@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.
Files changed (52) hide show
  1. package/build.sh +3 -0
  2. package/create-countryconfig/index.js +114 -66
  3. package/create-countryconfig/node_modules/.bin/degit +21 -0
  4. package/create-countryconfig/package.json +4 -1
  5. package/dist/application-config/index.js +242 -207
  6. package/dist/cli.js +556 -81
  7. package/dist/commons/api/router.d.ts +407 -50
  8. package/dist/commons/conditionals/conditionals.d.ts +6 -6
  9. package/dist/commons/conditionals/validate.d.ts +6 -2
  10. package/dist/commons/events/ActionDocument.d.ts +4 -4
  11. package/dist/commons/events/ActionInput.d.ts +4 -4
  12. package/dist/commons/events/AdvancedSearchConfig.d.ts +12 -0
  13. package/dist/commons/events/EventDocument.d.ts +470 -2
  14. package/dist/commons/events/EventMetadata.d.ts +1 -11
  15. package/dist/commons/events/EventStatus.d.ts +19 -0
  16. package/dist/commons/events/FieldConfig.d.ts +18 -0
  17. package/dist/commons/events/FieldTypeMapping.d.ts +15 -15
  18. package/dist/commons/events/locations.d.ts +59 -10
  19. package/dist/commons/events/test.utils.d.ts +8 -4
  20. package/dist/commons/events/utils.d.ts +2 -2
  21. package/dist/commons/notification/UserNotifications.d.ts +28 -13
  22. package/dist/commons/notification/dispatch.d.ts +15 -0
  23. package/dist/commons/notification/index.d.ts +1 -0
  24. package/dist/conditionals/index.js +77 -55
  25. package/dist/environment/questions.d.ts.map +1 -1
  26. package/dist/environment/questions.js +20 -14
  27. package/dist/environment/setup-environment.js +1 -1
  28. package/dist/events/index.js +839 -775
  29. package/dist/migrations/v2.0/checkout-upstream-files.d.ts +2 -2
  30. package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +1 -1
  31. package/dist/migrations/v2.0/checkout-upstream-files.js +2 -2
  32. package/dist/migrations/v2.1/add-recovery-link-notifications.d.ts +3 -0
  33. package/dist/migrations/v2.1/add-recovery-link-notifications.d.ts.map +1 -0
  34. package/dist/migrations/v2.1/add-recovery-link-notifications.js +530 -0
  35. package/dist/migrations/v2.1/index.d.ts.map +1 -1
  36. package/dist/migrations/v2.1/index.js +469 -0
  37. package/dist/notification/index.js +911 -1359
  38. package/dist/scopes/index.d.ts +71 -1
  39. package/dist/scopes/index.js +77 -55
  40. package/dist/telemetry/index.d.ts +48 -0
  41. package/dist/telemetry/index.d.ts.map +1 -0
  42. package/dist/telemetry/index.js +42 -0
  43. package/dist/templates/charts-values/opencrvs-services/values.yaml +1 -1
  44. package/dist/templates/charts-values/opentelemetry/values.yaml +22 -0
  45. package/dist/templates/charts-values/traefik/values.yaml +23 -9
  46. package/dist/templates/inventory/inventory.template.yml +1 -3
  47. package/opencrvs-toolkit-2.1.0-rc.517ffcd.tgz +0 -0
  48. package/package.json +2 -1
  49. package/tsconfig.tsbuildinfo +1 -1
  50. package/dist/templates/inventory/production.example.yml +0 -77
  51. package/dist/templates/inventory/qa.example.yml +0 -48
  52. package/opencrvs-toolkit-2.1.0-rc.5135dc7.tgz +0 -0
package/dist/cli.js CHANGED
@@ -32,13 +32,13 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
32
32
 
33
33
  // src/environment/paths.ts
34
34
  function getEnvironmentInventoryPath(environment) {
35
- return (0, import_path2.join)("environments", environment, INVENTORY_FILE_NAME);
35
+ return (0, import_path3.join)("environments", environment, INVENTORY_FILE_NAME);
36
36
  }
37
37
  function findOldInventoryFiles() {
38
- return glob.sync((0, import_path2.join)(OLD_INVENTORY_DIR, "*.yml")).sort();
38
+ return glob.sync((0, import_path3.join)(OLD_INVENTORY_DIR, "*.yml")).sort();
39
39
  }
40
40
  function getEnvironmentNameFromOldInventoryPath(filePath) {
41
- return (0, import_path2.basename)(filePath, ".yml");
41
+ return (0, import_path3.basename)(filePath, ".yml");
42
42
  }
43
43
  function assertNoOldInventoryLayout() {
44
44
  if (findOldInventoryFiles().length === 0) {
@@ -51,13 +51,13 @@ function assertNoOldInventoryLayout() {
51
51
  ].join(" ")
52
52
  );
53
53
  }
54
- var import_path2, glob, OLD_INVENTORY_DIR, INVENTORY_FILE_NAME;
54
+ var import_path3, glob, OLD_INVENTORY_DIR, INVENTORY_FILE_NAME;
55
55
  var init_paths = __esm({
56
56
  "src/environment/paths.ts"() {
57
57
  "use strict";
58
- import_path2 = require("path");
58
+ import_path3 = require("path");
59
59
  glob = __toESM(require("glob"));
60
- OLD_INVENTORY_DIR = (0, import_path2.join)(
60
+ OLD_INVENTORY_DIR = (0, import_path3.join)(
61
61
  "infrastructure",
62
62
  "server-setup",
63
63
  "inventory"
@@ -507,7 +507,7 @@ function storeSecrets(environment, answers) {
507
507
  let envConfig = {};
508
508
  try {
509
509
  envConfig = import_dotenv.default.parse(
510
- (0, import_fs.readFileSync)(`${process.cwd()}/.env.${environment}`)
510
+ (0, import_fs2.readFileSync)(`${process.cwd()}/.env.${environment}`)
511
511
  );
512
512
  } catch (error3) {
513
513
  envConfig = {};
@@ -517,10 +517,10 @@ function storeSecrets(environment, answers) {
517
517
  );
518
518
  const linesFromEnvConfig = Object.entries(envConfig).filter(([name]) => !answers.find((update) => update.name === name)).map(([name, value]) => `${name}="${value}"`);
519
519
  const allLines = [...linesFromEnvConfig, ...linesFromAnswers].sort();
520
- (0, import_fs.writeFileSync)(`.env.${environment}`, allLines.join("\n"));
520
+ (0, import_fs2.writeFileSync)(`.env.${environment}`, allLines.join("\n"));
521
521
  }
522
522
  function readYamlFile(filePath) {
523
- const fileContent = import_fs.default.readFileSync(filePath, "utf8");
523
+ const fileContent = import_fs2.default.readFileSync(filePath, "utf8");
524
524
  return yaml.load(fileContent);
525
525
  }
526
526
  function writeYamlFile(filePath, data) {
@@ -533,16 +533,16 @@ function writeYamlFile(filePath, data) {
533
533
  noRefs: true,
534
534
  sortKeys: false
535
535
  });
536
- import_fs.default.writeFileSync(filePath, yamlContent, "utf8");
536
+ import_fs2.default.writeFileSync(filePath, yamlContent, "utf8");
537
537
  } catch (error3) {
538
538
  throw new Error(`Failed to write inventory file: ${error3}`);
539
539
  }
540
540
  }
541
- var import_fs, yaml, import_dotenv;
541
+ var import_fs2, yaml, import_dotenv;
542
542
  var init_utils = __esm({
543
543
  "src/environment/utils.ts"() {
544
544
  "use strict";
545
- import_fs = __toESM(require("fs"));
545
+ import_fs2 = __toESM(require("fs"));
546
546
  yaml = __toESM(require("js-yaml"));
547
547
  import_dotenv = __toESM(require("dotenv"));
548
548
  }
@@ -595,29 +595,29 @@ function extractWorkerNodes(data) {
595
595
  return worker_hosts;
596
596
  }
597
597
  function copyChartsValues(env, values) {
598
- const srcDir = import_path3.default.resolve(__dirname, "templates", "charts-values");
599
- const destDir = import_path3.default.resolve(process.cwd(), "environments", env);
600
- import_fs2.default.mkdirSync(destDir, { recursive: true });
598
+ const srcDir = import_path4.default.resolve(__dirname, "templates", "charts-values");
599
+ const destDir = import_path4.default.resolve(process.cwd(), "environments", env);
600
+ import_fs3.default.mkdirSync(destDir, { recursive: true });
601
601
  values["lets_encrypt"] = values["traefik_mode"] === "lets_encrypt";
602
602
  values["static_ssl"] = values["traefik_mode"] === "static_ssl";
603
603
  values["opencrvs_environment"] = env;
604
604
  function copyRecursive(src, dest) {
605
- const stat = import_fs2.default.statSync(src);
605
+ const stat = import_fs3.default.statSync(src);
606
606
  if (stat.isDirectory()) {
607
- import_fs2.default.mkdirSync(dest, { recursive: true });
608
- for (const item of import_fs2.default.readdirSync(src)) {
609
- copyRecursive(import_path3.default.join(src, item), import_path3.default.join(dest, item));
607
+ import_fs3.default.mkdirSync(dest, { recursive: true });
608
+ for (const item of import_fs3.default.readdirSync(src)) {
609
+ copyRecursive(import_path4.default.join(src, item), import_path4.default.join(dest, item));
610
610
  }
611
611
  } else {
612
- const content = import_fs2.default.readFileSync(src, "utf8");
612
+ const content = import_fs3.default.readFileSync(src, "utf8");
613
613
  const template = import_handlebars.default.compile(content);
614
614
  const updated = template(values);
615
615
  const isOverridesFile = dest.endsWith("override.yaml");
616
- if (isOverridesFile && import_fs2.default.existsSync(dest)) {
616
+ if (isOverridesFile && import_fs3.default.existsSync(dest)) {
617
617
  log(` \u21B7 Skipped existing overrides file: ${dest}`);
618
618
  return;
619
619
  }
620
- import_fs2.default.writeFileSync(dest, updated, "utf8");
620
+ import_fs3.default.writeFileSync(dest, updated, "utf8");
621
621
  log(` \u2713 Created: ${dest}`);
622
622
  }
623
623
  }
@@ -628,29 +628,29 @@ function copyChartsValues(env, values) {
628
628
  `);
629
629
  }
630
630
  function generateInventory(env, values) {
631
- const templatePath = import_path3.default.join(
631
+ const templatePath = import_path4.default.join(
632
632
  __dirname,
633
633
  "templates",
634
634
  "inventory",
635
635
  "inventory.template.yml"
636
636
  );
637
- const outputPath = import_path3.default.resolve(process.cwd(), getEnvironmentInventoryPath(env));
638
- const templateFile = import_fs2.default.readFileSync(templatePath, "utf-8");
637
+ const outputPath = import_path4.default.resolve(process.cwd(), getEnvironmentInventoryPath(env));
638
+ const templateFile = import_fs3.default.readFileSync(templatePath, "utf-8");
639
639
  const template = import_handlebars.default.compile(templateFile);
640
640
  values["single_node"] = values["kube_worker_nodes"].length > 0 || values["backup_host"] ? "false" : "true";
641
641
  const updated = template(values);
642
- import_fs2.default.mkdirSync(import_path3.default.dirname(outputPath), { recursive: true });
643
- import_fs2.default.writeFileSync(outputPath, updated);
642
+ import_fs3.default.mkdirSync(import_path4.default.dirname(outputPath), { recursive: true });
643
+ import_fs3.default.writeFileSync(outputPath, updated);
644
644
  log(`
645
645
  \u2705 Generated inventory file at ${outputPath}
646
646
  `);
647
647
  }
648
- var import_fs2, import_path3, import_handlebars;
648
+ var import_fs3, import_path4, import_handlebars;
649
649
  var init_templates = __esm({
650
650
  "src/environment/templates.ts"() {
651
651
  "use strict";
652
- import_fs2 = __toESM(require("fs"));
653
- import_path3 = __toESM(require("path"));
652
+ import_fs3 = __toESM(require("fs"));
653
+ import_path4 = __toESM(require("path"));
654
654
  init_logger();
655
655
  init_paths();
656
656
  import_handlebars = __toESM(require("handlebars"));
@@ -860,11 +860,28 @@ var init_questions = __esm({
860
860
  scope: "ENVIRONMENT"
861
861
  },
862
862
  {
863
- name: "kubeAPIHost",
863
+ name: "kubeMasterNode",
864
864
  type: "text",
865
- message: `Kubernetes API endpoint (default: auto-detect)`,
865
+ message: `Kubernetes master node hostnames or IP (default: auto-detect)`,
866
+ valueType: "VARIABLE",
867
+ valueLabel: "KUBE_MASTER_NODE",
868
+ initial: process.env.KUBE_MASTER_NODE,
869
+ scope: "ENVIRONMENT"
870
+ },
871
+ {
872
+ name: "kubeWorkerNodes",
873
+ type: "text",
874
+ message: `Kubernetes worker node hostnames or IPs (comma-separated, default: no worker nodes)`,
875
+ valueType: "VARIABLE",
876
+ valueLabel: "KUBE_WORKER_NODES",
877
+ initial: process.env.KUBE_WORKER_NODES || "",
878
+ scope: "ENVIRONMENT"
879
+ },
880
+ {
881
+ name: "kubeApiHost",
882
+ type: "text",
883
+ message: `Kubernetes API endpoint IP (default: KUBE_MASTER_NODE)`,
866
884
  valueType: "VARIABLE",
867
- // validate: notEmpty,
868
885
  valueLabel: "KUBE_API_HOST",
869
886
  initial: process.env.KUBE_API_HOST,
870
887
  scope: "ENVIRONMENT"
@@ -878,16 +895,6 @@ var init_questions = __esm({
878
895
  valueLabel: "KUBE_API_ALLOWED_CIDRS",
879
896
  initial: process.env.KUBE_API_ALLOWED_CIDRS || "",
880
897
  scope: "ENVIRONMENT"
881
- },
882
- {
883
- name: "kubeWorkerNodes",
884
- type: "text",
885
- message: `Kubernetes worker node hostnames or IPs (comma-separated, default: no worker nodes)`,
886
- valueType: "VARIABLE",
887
- // validate: notEmpty,
888
- valueLabel: "KUBE_WORKER_NODES",
889
- initial: process.env.KUBE_WORKER_NODES || "",
890
- scope: "ENVIRONMENT"
891
898
  }
892
899
  ];
893
900
  staticSSLCertQuestions = [
@@ -918,7 +925,6 @@ var init_questions = __esm({
918
925
  type: "text",
919
926
  message: `Please enter backup server host/IP address, (default: no backup):`,
920
927
  valueType: "VARIABLE",
921
- // validate: notEmpty,
922
928
  valueLabel: "BACKUP_HOST",
923
929
  initial: process.env.BACKUP_HOST || "",
924
930
  scope: "ENVIRONMENT"
@@ -1251,7 +1257,7 @@ function getCurrentUsername() {
1251
1257
  }
1252
1258
  function getCurrentUserSSHKeys() {
1253
1259
  const homeDir = os.homedir();
1254
- const sshDir = path3.join(homeDir, ".ssh");
1260
+ const sshDir = path4.join(homeDir, ".ssh");
1255
1261
  const keys = [];
1256
1262
  const keyFiles = [
1257
1263
  "id_rsa.pub",
@@ -1260,7 +1266,7 @@ function getCurrentUserSSHKeys() {
1260
1266
  "id_dsa.pub"
1261
1267
  ];
1262
1268
  for (const keyFile of keyFiles) {
1263
- const keyPath = path3.join(sshDir, keyFile);
1269
+ const keyPath = path4.join(sshDir, keyFile);
1264
1270
  try {
1265
1271
  if (fs3.existsSync(keyPath)) {
1266
1272
  const keyContent = fs3.readFileSync(keyPath, "utf8").trim();
@@ -1601,13 +1607,13 @@ async function manageUsers(inventoryPath) {
1601
1607
  }
1602
1608
  return users;
1603
1609
  }
1604
- var os, fs3, path3, input2, select2, confirm, editor, checkbox;
1610
+ var os, fs3, path4, input2, select2, confirm, editor, checkbox;
1605
1611
  var init_manage_users = __esm({
1606
1612
  "src/environment/manage-users.ts"() {
1607
1613
  "use strict";
1608
1614
  os = __toESM(require("os"));
1609
1615
  fs3 = __toESM(require("fs"));
1610
- path3 = __toESM(require("path"));
1616
+ path4 = __toESM(require("path"));
1611
1617
  init_logger();
1612
1618
  init_utils();
1613
1619
  init_templates();
@@ -2720,7 +2726,7 @@ var init_setup_environment = __esm({
2720
2726
  log("\n", import_kleur4.default.bold().underline("Running configuration files updates"));
2721
2727
  generateInventory(environment, {
2722
2728
  kube_worker_nodes: kubeWorkerNodes,
2723
- kube_api_host: infrastructure.kubeAPIHost || "",
2729
+ kube_api_host: infrastructure.kubeApiHost || "",
2724
2730
  backup_host: backupHost || "",
2725
2731
  users
2726
2732
  });
@@ -2781,16 +2787,16 @@ var update_workflows_exports = {};
2781
2787
  __export(update_workflows_exports, {
2782
2788
  updateWorkflowEnvironments: () => updateWorkflowEnvironments
2783
2789
  });
2784
- function isDirectory(path6) {
2790
+ function isDirectory(path7) {
2785
2791
  try {
2786
- return (0, import_fs3.statSync)(path6).isDirectory();
2792
+ return (0, import_fs4.statSync)(path7).isDirectory();
2787
2793
  } catch {
2788
2794
  return false;
2789
2795
  }
2790
2796
  }
2791
2797
  async function extractInfrastructureNames() {
2792
- const files = glob2.sync((0, import_path4.join)("environments", "*", INVENTORY_FILE_NAME));
2793
- const infraEnvironments = files.map((file) => (0, import_path4.basename)((0, import_path4.dirname)(file)));
2798
+ const files = glob2.sync((0, import_path5.join)("environments", "*", INVENTORY_FILE_NAME));
2799
+ const infraEnvironments = files.map((file) => (0, import_path5.basename)((0, import_path5.dirname)(file)));
2794
2800
  if (infraEnvironments.length === 0) {
2795
2801
  console.log(
2796
2802
  `\u26A0\uFE0F Warning: No environment inventory files found at environments/*/${INVENTORY_FILE_NAME}`
@@ -2803,9 +2809,9 @@ async function extractInfrastructureNames() {
2803
2809
  async function extractEnvironmentNames() {
2804
2810
  const entries = await (0, import_promises.readdir)("environments");
2805
2811
  const environments = entries.filter((entry) => {
2806
- const environmentPath = (0, import_path4.join)("environments", entry);
2807
- const opencrvsServicesPath = (0, import_path4.join)(environmentPath, "opencrvs-services");
2808
- return isDirectory(environmentPath) && (0, import_fs3.existsSync)(opencrvsServicesPath) && isDirectory(opencrvsServicesPath);
2812
+ const environmentPath = (0, import_path5.join)("environments", entry);
2813
+ const opencrvsServicesPath = (0, import_path5.join)(environmentPath, "opencrvs-services");
2814
+ return isDirectory(environmentPath) && (0, import_fs4.existsSync)(opencrvsServicesPath) && isDirectory(opencrvsServicesPath);
2809
2815
  });
2810
2816
  if (environments.length === 0) {
2811
2817
  console.log(
@@ -2831,7 +2837,7 @@ async function updateWorkflows(envList, config) {
2831
2837
  const { workflows } = config;
2832
2838
  for (const workflowPath of workflows) {
2833
2839
  try {
2834
- const fileContents = (0, import_fs3.readFileSync)(workflowPath, "utf8");
2840
+ const fileContents = (0, import_fs4.readFileSync)(workflowPath, "utf8");
2835
2841
  const workflowData = yaml2.load(fileContents);
2836
2842
  if (!workflowData?.on?.workflow_dispatch?.inputs?.environment?.options) {
2837
2843
  throw new Error(
@@ -2839,7 +2845,7 @@ async function updateWorkflows(envList, config) {
2839
2845
  );
2840
2846
  }
2841
2847
  const updatedContent = updateOptionsInYaml(fileContents, envList);
2842
- (0, import_fs3.writeFileSync)(workflowPath, updatedContent, "utf8");
2848
+ (0, import_fs4.writeFileSync)(workflowPath, updatedContent, "utf8");
2843
2849
  log(` \u2713 Successfully updated ${workflowPath}`);
2844
2850
  } catch (error3) {
2845
2851
  console.error(
@@ -2893,13 +2899,13 @@ async function updateWorkflowEnvironments() {
2893
2899
  process.exit(1);
2894
2900
  }
2895
2901
  }
2896
- var import_promises, import_fs3, import_path4, glob2, yaml2;
2902
+ var import_promises, import_fs4, import_path5, glob2, yaml2;
2897
2903
  var init_update_workflows = __esm({
2898
2904
  "src/environment/update-workflows.ts"() {
2899
2905
  "use strict";
2900
2906
  import_promises = require("fs/promises");
2901
- import_fs3 = require("fs");
2902
- import_path4 = require("path");
2907
+ import_fs4 = require("fs");
2908
+ import_path5 = require("path");
2903
2909
  glob2 = __toESM(require("glob"));
2904
2910
  yaml2 = __toESM(require("js-yaml"));
2905
2911
  init_logger();
@@ -2913,17 +2919,17 @@ __export(upgrade_exports, {
2913
2919
  upgradeEnvironmentLayout: () => upgradeEnvironmentLayout
2914
2920
  });
2915
2921
  function moveFileIfDestinationMissing(sourcePath, destinationPath) {
2916
- if (!(0, import_fs4.existsSync)(sourcePath)) {
2922
+ if (!(0, import_fs5.existsSync)(sourcePath)) {
2917
2923
  return false;
2918
2924
  }
2919
- if ((0, import_fs4.existsSync)(destinationPath)) {
2925
+ if ((0, import_fs5.existsSync)(destinationPath)) {
2920
2926
  warn(
2921
2927
  `\u26A0\uFE0F Skipped ${sourcePath}; destination already exists at ${destinationPath}`
2922
2928
  );
2923
2929
  return false;
2924
2930
  }
2925
- (0, import_fs4.mkdirSync)((0, import_path5.dirname)(destinationPath), { recursive: true });
2926
- (0, import_fs4.renameSync)(sourcePath, destinationPath);
2931
+ (0, import_fs5.mkdirSync)((0, import_path6.dirname)(destinationPath), { recursive: true });
2932
+ (0, import_fs5.renameSync)(sourcePath, destinationPath);
2927
2933
  log(` \u2713 Moved ${sourcePath} -> ${destinationPath}`);
2928
2934
  return true;
2929
2935
  }
@@ -2943,8 +2949,8 @@ function migrateInventoryFiles() {
2943
2949
  ) || didMoveInventory;
2944
2950
  }
2945
2951
  try {
2946
- if ((0, import_fs4.existsSync)(OLD_INVENTORY_DIR) && (0, import_fs4.readdirSync)(OLD_INVENTORY_DIR).length === 0) {
2947
- (0, import_fs4.rmdirSync)(OLD_INVENTORY_DIR);
2952
+ if ((0, import_fs5.existsSync)(OLD_INVENTORY_DIR) && (0, import_fs5.readdirSync)(OLD_INVENTORY_DIR).length === 0) {
2953
+ (0, import_fs5.rmdirSync)(OLD_INVENTORY_DIR);
2948
2954
  log(` \u2713 Removed empty ${OLD_INVENTORY_DIR}`);
2949
2955
  }
2950
2956
  } catch {
@@ -2962,12 +2968,12 @@ async function upgradeEnvironmentLayout() {
2962
2968
  }
2963
2969
  log("\nCommit changes into git after upgrade");
2964
2970
  }
2965
- var import_fs4, import_path5, import_kleur5;
2971
+ var import_fs5, import_path6, import_kleur5;
2966
2972
  var init_upgrade = __esm({
2967
2973
  "src/environment/upgrade.ts"() {
2968
2974
  "use strict";
2969
- import_fs4 = require("fs");
2970
- import_path5 = require("path");
2975
+ import_fs5 = require("fs");
2976
+ import_path6 = require("path");
2971
2977
  import_kleur5 = __toESM(require("kleur"));
2972
2978
  init_logger();
2973
2979
  init_paths();
@@ -2993,7 +2999,7 @@ async function selectInventoryFile(dirPath = "./environments") {
2993
2999
  return null;
2994
3000
  }
2995
3001
  const environments = fs4.readdirSync(dirPath).filter((entry) => {
2996
- const filePath = path4.join(dirPath, entry);
3002
+ const filePath = path5.join(dirPath, entry);
2997
3003
  return fs4.statSync(filePath).isDirectory() && fs4.existsSync(getEnvironmentInventoryPath(entry));
2998
3004
  }).sort();
2999
3005
  if (environments.length === 0) {
@@ -3021,12 +3027,12 @@ async function manageEnvironmentUsers() {
3021
3027
  }
3022
3028
  await manageUsers(inventory_file);
3023
3029
  }
3024
- var fs4, path4, import_kleur6;
3030
+ var fs4, path5, import_kleur6;
3025
3031
  var init_users = __esm({
3026
3032
  "src/environment/users.ts"() {
3027
3033
  "use strict";
3028
3034
  fs4 = __toESM(require("fs"));
3029
- path4 = __toESM(require("path"));
3035
+ path5 = __toESM(require("path"));
3030
3036
  import_kleur6 = __toESM(require("kleur"));
3031
3037
  init_manage_users();
3032
3038
  init_logger();
@@ -3036,11 +3042,11 @@ var init_users = __esm({
3036
3042
 
3037
3043
  // src/environment/swarm-to-k8s.ts
3038
3044
  var swarm_to_k8s_exports = {};
3039
- var path5, import_kleur7, import_core2;
3045
+ var path6, import_kleur7, import_core2;
3040
3046
  var init_swarm_to_k8s = __esm({
3041
3047
  "src/environment/swarm-to-k8s.ts"() {
3042
3048
  "use strict";
3043
- path5 = __toESM(require("path"));
3049
+ path6 = __toESM(require("path"));
3044
3050
  import_kleur7 = __toESM(require("kleur"));
3045
3051
  init_logger();
3046
3052
  init_utils();
@@ -3092,7 +3098,7 @@ var init_swarm_to_k8s = __esm({
3092
3098
  );
3093
3099
  process.exit(1);
3094
3100
  }
3095
- const ansible_inventory = path5.join(old_inventory_path, environment + ".yml");
3101
+ const ansible_inventory = path6.join(old_inventory_path, environment + ".yml");
3096
3102
  const data = readYamlFile(ansible_inventory);
3097
3103
  log(` \u2713 Loaded old inventory file: ${ansible_inventory}`);
3098
3104
  const master = dockerManagerFirst(data) || "";
@@ -3393,14 +3399,483 @@ Done. Added ${totalChanges} correction action config(s) across ${modifiedFiles.l
3393
3399
  );
3394
3400
  }
3395
3401
 
3402
+ // src/migrations/v2.1/add-recovery-link-notifications.ts
3403
+ var import_ts_morph2 = require("ts-morph");
3404
+ var import_fs = require("fs");
3405
+ var import_path2 = __toESM(require("path"));
3406
+ var EMAIL_TEMPLATES_FILE = "src/api/notification/email-templates/index.ts";
3407
+ var SMS_SERVICE_FILE = "src/api/notification/sms-service.ts";
3408
+ var HANDLER_FILE = "src/api/notification/handler.ts";
3409
+ var ROUTES_FILE = "src/config/routes/userNotificationRoutes.ts";
3410
+ var EMAIL_TEMPLATE_DIR = "src/api/notification/email-templates/other";
3411
+ var NOTIFICATION_CSV = "src/translations/notification.csv";
3412
+ var LOGIN_CSV = "src/translations/login.csv";
3413
+ var TRIGGER_VARIABLE_OBJECT = "TriggerVariable";
3414
+ var TEMPLATES_OBJECT = "templates";
3415
+ var OTHER_TEMPLATES_OBJECT = "otherTemplates";
3416
+ var TRIGGER_TO_SMS_TEMPLATE_OBJECT = "TriggerToSMSTemplate";
3417
+ var CONVERT_PAYLOAD_FUNCTION = "convertPayloadToVariable";
3418
+ var ROUTES_FUNCTION = "getUserNotificationRoutes";
3419
+ var RECOVERY_EVENTS = [
3420
+ {
3421
+ id: "password-reset-link",
3422
+ constant: "PASSWORD_RESET_LINK",
3423
+ smsTemplate: "resetPasswordLinkNotification",
3424
+ emailSubject: "Reset your password",
3425
+ routeDescription: "Handles notification for password reset recovery link",
3426
+ heading: "Reset your password",
3427
+ reason: "Someone asked to reset the password for your {{applicationName}}\n account.",
3428
+ linkLabel: "Reset your password"
3429
+ },
3430
+ {
3431
+ id: "username-reminder-link",
3432
+ constant: "USERNAME_REMINDER_LINK",
3433
+ smsTemplate: "retrieveUsernameLinkNotification",
3434
+ emailSubject: "Retrieve your username",
3435
+ routeDescription: "Handles notification for username reminder recovery link",
3436
+ heading: "Retrieve your username",
3437
+ reason: "Someone asked for a reminder of the username for your\n {{applicationName}} account.",
3438
+ linkLabel: "Retrieve your username"
3439
+ }
3440
+ ];
3441
+ var NOTIFICATION_CSV_ROWS = [
3442
+ `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}}}`,
3443
+ `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}}}`
3444
+ ];
3445
+ var LOGIN_CSV_ROWS = [
3446
+ `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`,
3447
+ `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."`,
3448
+ `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`,
3449
+ `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`,
3450
+ `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.`,
3451
+ `resetCredentials.recoveryLinkLanding.expired.link,Link back to the forgotten item form shown on an expired/invalid recovery link,Start again,Recommencer`,
3452
+ `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`
3453
+ ];
3454
+ var skipped = [];
3455
+ function warnSkipped(message) {
3456
+ skipped.push(message);
3457
+ console.warn(` \u26A0\uFE0F ${message}`);
3458
+ }
3459
+ function findObjectLiteral(declaration) {
3460
+ let expression = declaration?.getInitializer();
3461
+ while (expression && (import_ts_morph2.Node.isAsExpression(expression) || import_ts_morph2.Node.isSatisfiesExpression(expression))) {
3462
+ expression = expression.getExpression();
3463
+ }
3464
+ return expression && import_ts_morph2.Node.isObjectLiteralExpression(expression) ? expression : void 0;
3465
+ }
3466
+ function hasKeyFor(obj, key, constant) {
3467
+ const accepted = /* @__PURE__ */ new Set([
3468
+ `[TriggerEvent.${constant}]`,
3469
+ `['${key}']`,
3470
+ `["${key}"]`,
3471
+ `'${key}'`,
3472
+ `"${key}"`,
3473
+ key
3474
+ ]);
3475
+ return obj.getProperties().some(
3476
+ (property) => import_ts_morph2.Node.isPropertyAssignment(property) && accepted.has(property.getName().trim())
3477
+ );
3478
+ }
3479
+ function renderKey(obj, key, constant) {
3480
+ const names = obj.getProperties().filter(import_ts_morph2.Node.isPropertyAssignment).map((property) => property.getName().trim());
3481
+ if (names.some((name) => name.startsWith("[TriggerEvent."))) {
3482
+ return `[TriggerEvent.${constant}]`;
3483
+ }
3484
+ if (names.some((name) => name.startsWith("["))) {
3485
+ return `['${key}']`;
3486
+ }
3487
+ return `'${key}'`;
3488
+ }
3489
+ function appendEntry(sourceFile, objectName, key, valueLines) {
3490
+ const obj = findObjectLiteral(sourceFile.getVariableDeclaration(objectName));
3491
+ const properties = obj?.getProperties() ?? [];
3492
+ const lastProperty = properties[properties.length - 1];
3493
+ if (!lastProperty) return false;
3494
+ const indent = lastProperty.getIndentationText();
3495
+ const entry = valueLines.map((line, index) => `${indent}${index === 0 ? `${key}: ${line}` : line}`).join("\n");
3496
+ sourceFile.insertText(lastProperty.getEnd(), `,
3497
+ ${entry}`);
3498
+ return true;
3499
+ }
3500
+ function objectHasKeyFor(sourceFile, objectName, key, constant) {
3501
+ const obj = findObjectLiteral(sourceFile.getVariableDeclaration(objectName));
3502
+ return obj ? hasKeyFor(obj, key, constant) : false;
3503
+ }
3504
+ function renderKeyFor(sourceFile, objectName, key, constant) {
3505
+ const obj = findObjectLiteral(sourceFile.getVariableDeclaration(objectName));
3506
+ return obj ? renderKey(obj, key, constant) : `'${key}'`;
3507
+ }
3508
+ function updateEmailTemplates(project, cwd) {
3509
+ const sourceFile = project.getSourceFile(import_path2.default.join(cwd, EMAIL_TEMPLATES_FILE));
3510
+ if (!sourceFile) {
3511
+ warnSkipped(`${EMAIL_TEMPLATES_FILE} not found; email templates not wired`);
3512
+ return;
3513
+ }
3514
+ const missingObject = [TRIGGER_VARIABLE_OBJECT, TEMPLATES_OBJECT].find(
3515
+ (objectName) => !findObjectLiteral(sourceFile.getVariableDeclaration(objectName))
3516
+ );
3517
+ if (missingObject) {
3518
+ warnSkipped(
3519
+ `Could not find '${missingObject}' in ${EMAIL_TEMPLATES_FILE}; email templates not wired`
3520
+ );
3521
+ return;
3522
+ }
3523
+ for (const event of RECOVERY_EVENTS) {
3524
+ if (!objectHasKeyFor(
3525
+ sourceFile,
3526
+ TRIGGER_VARIABLE_OBJECT,
3527
+ event.id,
3528
+ event.constant
3529
+ ) && appendEntry(
3530
+ sourceFile,
3531
+ TRIGGER_VARIABLE_OBJECT,
3532
+ renderKeyFor(
3533
+ sourceFile,
3534
+ TRIGGER_VARIABLE_OBJECT,
3535
+ event.id,
3536
+ event.constant
3537
+ ),
3538
+ [
3539
+ "z.object({",
3540
+ " firstname: z.string(),",
3541
+ " applicationName: z.string(),",
3542
+ " countryLogo: z.string(),",
3543
+ " recoveryURL: z.string()",
3544
+ "})"
3545
+ ]
3546
+ )) {
3547
+ console.log(` \u2713 ${EMAIL_TEMPLATES_FILE}: ${event.id} variables`);
3548
+ }
3549
+ if (!objectHasKeyFor(
3550
+ sourceFile,
3551
+ TEMPLATES_OBJECT,
3552
+ event.id,
3553
+ event.constant
3554
+ ) && appendEntry(
3555
+ sourceFile,
3556
+ TEMPLATES_OBJECT,
3557
+ renderKeyFor(sourceFile, TEMPLATES_OBJECT, event.id, event.constant),
3558
+ [
3559
+ "{",
3560
+ ` type: '${event.id}',`,
3561
+ ` subject: '${event.emailSubject}',`,
3562
+ ` template: readOtherTemplate<TriggerVariable['${event.id}']>(`,
3563
+ ` '${event.id}'`,
3564
+ " )",
3565
+ "}"
3566
+ ]
3567
+ )) {
3568
+ console.log(` \u2713 ${EMAIL_TEMPLATES_FILE}: ${event.id} template`);
3569
+ }
3570
+ }
3571
+ }
3572
+ function updateSmsService(project, cwd) {
3573
+ const sourceFile = project.getSourceFile(import_path2.default.join(cwd, SMS_SERVICE_FILE));
3574
+ if (!sourceFile) {
3575
+ warnSkipped(`${SMS_SERVICE_FILE} not found; SMS templates not wired`);
3576
+ return;
3577
+ }
3578
+ const missingObject = [
3579
+ OTHER_TEMPLATES_OBJECT,
3580
+ TRIGGER_TO_SMS_TEMPLATE_OBJECT
3581
+ ].find(
3582
+ (objectName) => !findObjectLiteral(sourceFile.getVariableDeclaration(objectName))
3583
+ );
3584
+ if (missingObject) {
3585
+ warnSkipped(
3586
+ `Could not find '${missingObject}' in ${SMS_SERVICE_FILE}; SMS templates not wired`
3587
+ );
3588
+ return;
3589
+ }
3590
+ for (const event of RECOVERY_EVENTS) {
3591
+ if (!objectHasKeyFor(
3592
+ sourceFile,
3593
+ OTHER_TEMPLATES_OBJECT,
3594
+ event.smsTemplate,
3595
+ event.smsTemplate
3596
+ ) && appendEntry(sourceFile, OTHER_TEMPLATES_OBJECT, event.smsTemplate, [
3597
+ `'${event.smsTemplate}'`
3598
+ ])) {
3599
+ console.log(` \u2713 ${SMS_SERVICE_FILE}: ${event.smsTemplate}`);
3600
+ }
3601
+ if (!objectHasKeyFor(
3602
+ sourceFile,
3603
+ TRIGGER_TO_SMS_TEMPLATE_OBJECT,
3604
+ event.id,
3605
+ event.constant
3606
+ ) && appendEntry(
3607
+ sourceFile,
3608
+ TRIGGER_TO_SMS_TEMPLATE_OBJECT,
3609
+ renderKeyFor(
3610
+ sourceFile,
3611
+ TRIGGER_TO_SMS_TEMPLATE_OBJECT,
3612
+ event.id,
3613
+ event.constant
3614
+ ),
3615
+ [`'${event.smsTemplate}'`]
3616
+ )) {
3617
+ console.log(
3618
+ ` \u2713 ${SMS_SERVICE_FILE}: ${event.id} -> ${event.smsTemplate}`
3619
+ );
3620
+ }
3621
+ }
3622
+ }
3623
+ function updateHandler(project, cwd) {
3624
+ const sourceFile = project.getSourceFile(import_path2.default.join(cwd, HANDLER_FILE));
3625
+ if (!sourceFile) {
3626
+ warnSkipped(`${HANDLER_FILE} not found; payload conversion not wired`);
3627
+ return;
3628
+ }
3629
+ const convertPayload = sourceFile.getFunction(CONVERT_PAYLOAD_FUNCTION);
3630
+ const caseBlock = convertPayload?.getFirstDescendantByKind(import_ts_morph2.SyntaxKind.SwitchStatement)?.getCaseBlock();
3631
+ if (!caseBlock) {
3632
+ warnSkipped(
3633
+ `Could not find a switch inside '${CONVERT_PAYLOAD_FUNCTION}' in ${HANDLER_FILE}; payload conversion not wired`
3634
+ );
3635
+ return;
3636
+ }
3637
+ const missing = RECOVERY_EVENTS.filter(
3638
+ (event) => !caseBlock.getText().includes(`TriggerEvent.${event.constant}`) && !caseBlock.getText().includes(`'${event.id}'`)
3639
+ );
3640
+ if (missing.length === 0) return;
3641
+ const existingClauses = caseBlock.getClauses();
3642
+ if (existingClauses.length === 0) {
3643
+ warnSkipped(
3644
+ `The switch inside '${CONVERT_PAYLOAD_FUNCTION}' in ${HANDLER_FILE} has no cases; payload conversion not wired`
3645
+ );
3646
+ return;
3647
+ }
3648
+ const defaultClause = existingClauses.find(import_ts_morph2.Node.isDefaultClause);
3649
+ const anchor = defaultClause ?? existingClauses[existingClauses.length - 1];
3650
+ const indent = anchor.getIndentationText();
3651
+ const lines = [
3652
+ ...missing.map((event) => `case TriggerEvent.${event.constant}:`),
3653
+ ` return {`,
3654
+ ` firstname,`,
3655
+ ` applicationName: applicationConfig.APPLICATION_NAME,`,
3656
+ ` countryLogo: COUNTRY_LOGO_URL,`,
3657
+ ` recoveryURL: \`\${LOGIN_URL}recover?token=\${encodeURIComponent(payload.token)}\``,
3658
+ ` }`
3659
+ ];
3660
+ if (defaultClause) {
3661
+ caseBlock.insertText(
3662
+ anchor.getStart(),
3663
+ `${lines.map((line, index) => index === 0 ? line : `${indent}${line}`).join("\n")}
3664
+ ${indent}`
3665
+ );
3666
+ } else {
3667
+ caseBlock.insertText(
3668
+ anchor.getEnd(),
3669
+ `
3670
+ ${lines.map((line) => `${indent}${line}`).join("\n")}`
3671
+ );
3672
+ }
3673
+ for (const event of missing) {
3674
+ console.log(` \u2713 ${HANDLER_FILE}: ${event.id} case`);
3675
+ }
3676
+ }
3677
+ function updateRoutes(project, cwd) {
3678
+ const sourceFile = project.getSourceFile(import_path2.default.join(cwd, ROUTES_FILE));
3679
+ if (!sourceFile) {
3680
+ warnSkipped(`${ROUTES_FILE} not found; trigger routes not registered`);
3681
+ return;
3682
+ }
3683
+ const routesFunction = sourceFile.getFunction(ROUTES_FUNCTION) ?? sourceFile.getFunctions().find((fn) => fn.isDefaultExport());
3684
+ const routesArray = routesFunction?.getFirstDescendantByKind(import_ts_morph2.SyntaxKind.ReturnStatement)?.getExpressionIfKind(import_ts_morph2.SyntaxKind.ArrayLiteralExpression);
3685
+ if (!routesArray) {
3686
+ warnSkipped(
3687
+ `Could not find the route array returned by '${ROUTES_FUNCTION}' in ${ROUTES_FILE}; trigger routes not registered`
3688
+ );
3689
+ return;
3690
+ }
3691
+ for (const event of RECOVERY_EVENTS) {
3692
+ if (routesArray.getText().includes(`/triggers/user/${event.id}`)) continue;
3693
+ routesArray.addElement(`{
3694
+ method: 'POST',
3695
+ path: '/triggers/user/${event.id}',
3696
+ handler: makeNotificationHandler('${event.id}'),
3697
+ options: {
3698
+ auth: false,
3699
+ tags: ['api'],
3700
+ description: '${event.routeDescription}'
3701
+ }
3702
+ }`);
3703
+ console.log(` \u2713 ${ROUTES_FILE}: POST /triggers/user/${event.id}`);
3704
+ }
3705
+ }
3706
+ function renderEmailTemplate(event) {
3707
+ return `<!--
3708
+ This Source Code Form is subject to the terms of the Mozilla Public
3709
+ License, v. 2.0. If a copy of the MPL was not distributed with this
3710
+ file, You can obtain one at https://mozilla.org/MPL/2.0/.
3711
+
3712
+ OpenCRVS is also distributed under the terms of the Civil Registration
3713
+ & Healthcare Disclaimer located at http://opencrvs.org/license.
3714
+
3715
+ Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
3716
+ -->
3717
+ <!doctype html>
3718
+ <html>
3719
+ <head>
3720
+ <link
3721
+ href="https://fonts.googleapis.com/css2?family=Noto+Sans:wght@400;700&display=swap"
3722
+ rel="stylesheet"
3723
+ />
3724
+ <style type="text/css">
3725
+ body {
3726
+ font-family: 'Noto Sans', sans-serif;
3727
+ color: #222;
3728
+ padding: 16px 24px;
3729
+ }
3730
+
3731
+ h1 {
3732
+ font-size: 21px;
3733
+ margin-top: 32px;
3734
+ margin-bottom: 36px;
3735
+ font-weight: 700;
3736
+ }
3737
+
3738
+ p {
3739
+ font-weight: 400;
3740
+ font-size: 16px;
3741
+ line-height: 1.8;
3742
+ margin-bottom: 24px;
3743
+ }
3744
+
3745
+ i {
3746
+ color: #666;
3747
+ font-weight: 400;
3748
+ font-size: 16px;
3749
+ }
3750
+ </style>
3751
+ </head>
3752
+
3753
+ <body>
3754
+ <img
3755
+ src="{{countryLogo}}"
3756
+ alt="country_logo"
3757
+ style="max-height: 88px; max-width: 100%"
3758
+ />
3759
+ <h1>${event.heading}</h1>
3760
+ <p>Hello {{firstname}},</p>
3761
+ <p>
3762
+ ${event.reason}
3763
+ </p>
3764
+
3765
+ <div style="margin-top: 32px; margin-bottom: 32px">
3766
+ <a href="{{{recoveryURL}}}">${event.linkLabel}</a>
3767
+ </div>
3768
+ <br />
3769
+ <p>
3770
+ This link expires in 1 hour and can only be used once. If you did not
3771
+ request this, you can ignore this email.
3772
+ </p>
3773
+ <br />
3774
+ <p>
3775
+ Best regards, <br />
3776
+ {{applicationName}} Team
3777
+ </p>
3778
+ </body>
3779
+ </html>
3780
+ `;
3781
+ }
3782
+ function writeEmailTemplates(cwd) {
3783
+ const templateDir = import_path2.default.join(cwd, EMAIL_TEMPLATE_DIR);
3784
+ if (!(0, import_fs.existsSync)(templateDir)) {
3785
+ warnSkipped(
3786
+ `${EMAIL_TEMPLATE_DIR} not found; recovery email bodies not written`
3787
+ );
3788
+ return;
3789
+ }
3790
+ for (const event of RECOVERY_EVENTS) {
3791
+ const templatePath = import_path2.default.join(templateDir, `${event.id}.html`);
3792
+ if ((0, import_fs.existsSync)(templatePath)) continue;
3793
+ (0, import_fs.writeFileSync)(templatePath, renderEmailTemplate(event));
3794
+ console.log(` \u2713 ${EMAIL_TEMPLATE_DIR}/${event.id}.html`);
3795
+ }
3796
+ }
3797
+ function addCsvRows(cwd, relativePath, rows) {
3798
+ const csvPath = import_path2.default.join(cwd, relativePath);
3799
+ if (!(0, import_fs.existsSync)(csvPath)) {
3800
+ warnSkipped(`${relativePath} not found; translations not added`);
3801
+ return;
3802
+ }
3803
+ const original = (0, import_fs.readFileSync)(csvPath, "utf8");
3804
+ const newline = original.includes("\r\n") ? "\r\n" : "\n";
3805
+ const hadTrailingNewline = /\r?\n$/.test(original);
3806
+ const lines = original.replace(/\r?\n$/, "").split(/\r?\n/);
3807
+ const idOf = (line) => line.slice(0, line.indexOf(","));
3808
+ const header = lines[0];
3809
+ const body = lines.slice(1);
3810
+ const isSorted = body.every(
3811
+ (line, index) => index === 0 || idOf(body[index - 1]) <= idOf(line)
3812
+ );
3813
+ let added = 0;
3814
+ for (const row of rows) {
3815
+ const id = idOf(row);
3816
+ if (body.some((line) => idOf(line) === id)) continue;
3817
+ const insertAt = isSorted ? body.findIndex((line) => idOf(line) > id) : -1;
3818
+ if (insertAt === -1) {
3819
+ body.push(row);
3820
+ } else {
3821
+ body.splice(insertAt, 0, row);
3822
+ }
3823
+ added++;
3824
+ console.log(` \u2713 ${relativePath}: ${id}`);
3825
+ }
3826
+ if (added === 0) return;
3827
+ (0, import_fs.writeFileSync)(
3828
+ csvPath,
3829
+ [header, ...body].join(newline) + (hadTrailingNewline ? newline : "")
3830
+ );
3831
+ }
3832
+ async function main2() {
3833
+ const cwd = process.cwd();
3834
+ const tsConfigFilePath = import_path2.default.join(cwd, "tsconfig.json");
3835
+ console.log(
3836
+ "Registering the password-reset-link and username-reminder-link notifications...\n"
3837
+ );
3838
+ if (!(0, import_fs.existsSync)(tsConfigFilePath)) {
3839
+ warnSkipped(
3840
+ `tsconfig.json not found in ${cwd}; notification wiring skipped entirely`
3841
+ );
3842
+ return;
3843
+ }
3844
+ const project = new import_ts_morph2.Project({
3845
+ tsConfigFilePath,
3846
+ skipAddingFilesFromTsConfig: false,
3847
+ // ts-morph indents inserted code with four spaces by default, which every
3848
+ // country config's prettier run would immediately undo.
3849
+ manipulationSettings: { indentationText: import_ts_morph2.IndentationText.TwoSpaces }
3850
+ });
3851
+ updateEmailTemplates(project, cwd);
3852
+ updateSmsService(project, cwd);
3853
+ updateHandler(project, cwd);
3854
+ updateRoutes(project, cwd);
3855
+ await project.save();
3856
+ writeEmailTemplates(cwd);
3857
+ addCsvRows(cwd, NOTIFICATION_CSV, NOTIFICATION_CSV_ROWS);
3858
+ addCsvRows(cwd, LOGIN_CSV, LOGIN_CSV_ROWS);
3859
+ if (skipped.length > 0) {
3860
+ console.warn(
3861
+ `
3862
+ \u26A0\uFE0F ${skipped.length} step(s) were skipped. Wire the following by hand before upgrading:`
3863
+ );
3864
+ for (const message of skipped) {
3865
+ console.warn(` - ${message}`);
3866
+ }
3867
+ }
3868
+ }
3869
+
3396
3870
  // src/migrations/v2.1/index.ts
3397
3871
  async function runUpgrade(dockerSwarm) {
3398
3872
  await main();
3873
+ await main2();
3399
3874
  }
3400
3875
 
3401
3876
  // src/environment/index.ts
3402
- var import_fs5 = require("fs");
3403
- var import_path6 = require("path");
3877
+ var import_fs6 = require("fs");
3878
+ var import_path7 = require("path");
3404
3879
  init_paths();
3405
3880
  var REQUIRED_REPOSITORY_DIRECTORIES = [
3406
3881
  ".github/workflows",
@@ -3411,7 +3886,7 @@ function validateRepositoryStructure(repositoryRoot = process.cwd()) {
3411
3886
  const missingDirectories = REQUIRED_REPOSITORY_DIRECTORIES.filter(
3412
3887
  (directory) => {
3413
3888
  try {
3414
- return !(0, import_fs5.statSync)((0, import_path6.resolve)(repositoryRoot, directory)).isDirectory();
3889
+ return !(0, import_fs6.statSync)((0, import_path7.resolve)(repositoryRoot, directory)).isDirectory();
3415
3890
  } catch {
3416
3891
  return true;
3417
3892
  }
@@ -3473,7 +3948,7 @@ Options:
3473
3948
  'infrastructure/' directory is deleted (default).
3474
3949
  -h, --help Show this message.
3475
3950
  `.trim();
3476
- function main2() {
3951
+ function main3() {
3477
3952
  const command = args[0];
3478
3953
  if (!command || command === "--help" || command === "-h") {
3479
3954
  console.log(USAGE);
@@ -3574,4 +4049,4 @@ function handleCheckTranslations() {
3574
4049
  console.warn("This command is not implemented yet!");
3575
4050
  process.exit(1);
3576
4051
  }
3577
- main2();
4052
+ main3();