@opencrvs/toolkit 2.1.0-rc.05a1257 → 2.1.0-rc.05b7761

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 (66) hide show
  1. package/README.md +2 -12
  2. package/build.sh +10 -3
  3. package/create-countryconfig/index.js +338 -4
  4. package/dist/application-config/index.js +17 -18
  5. package/dist/authentication/index.d.ts +67 -0
  6. package/dist/authentication/index.d.ts.map +1 -0
  7. package/dist/authentication/index.js +751 -0
  8. package/dist/cli.js +1090 -187
  9. package/dist/commons/api/router.d.ts +6 -42
  10. package/dist/commons/conditionals/conditionals.d.ts +6 -6
  11. package/dist/commons/conditionals/validate.d.ts +1 -1
  12. package/dist/commons/events/ActionConfig.d.ts +4 -0
  13. package/dist/commons/events/AdvancedSearchConfig.d.ts +12 -12
  14. package/dist/commons/events/FieldConfig.d.ts +16 -15
  15. package/dist/commons/events/FormConfig.d.ts +6 -0
  16. package/dist/commons/events/PageConfig.d.ts +4 -0
  17. package/dist/commons/events/locations.d.ts +4 -0
  18. package/dist/commons/events/test.utils.d.ts +18 -1
  19. package/dist/commons/events/utils.d.ts +15 -0
  20. package/dist/commons/notification/dispatch.d.ts +1 -6
  21. package/dist/conditionals/index.js +7 -6
  22. package/dist/csv.d.ts.map +1 -1
  23. package/dist/csv.js +7 -2
  24. package/dist/environment/logger.d.ts +3 -0
  25. package/dist/environment/logger.d.ts.map +1 -1
  26. package/dist/environment/manage-users.js +1 -1
  27. package/dist/environment/setup-environment.js +44 -26
  28. package/dist/environment/templates.d.ts +0 -1
  29. package/dist/environment/templates.d.ts.map +1 -1
  30. package/dist/environment/templates.js +3 -8
  31. package/dist/environment/update-workflows.d.ts.map +1 -1
  32. package/dist/environment/update-workflows.js +4 -0
  33. package/dist/environment/utils.d.ts +0 -12
  34. package/dist/environment/utils.d.ts.map +1 -1
  35. package/dist/environment/utils.js +1 -28
  36. package/dist/events/index.js +1901 -1792
  37. package/dist/migrations/v2.0/merge-infrastructure-directory.js +3 -3
  38. package/dist/migrations/v2.1/add-recovery-link-notifications.js +4 -4
  39. package/dist/migrations/v2.1/add-translations.d.ts.map +1 -1
  40. package/dist/migrations/v2.1/add-translations.js +42 -11
  41. package/dist/migrations/v2.1/enable-telemetry.d.ts +3 -0
  42. package/dist/migrations/v2.1/enable-telemetry.d.ts.map +1 -0
  43. package/dist/migrations/v2.1/enable-telemetry.js +455 -0
  44. package/dist/migrations/v2.1/index.d.ts.map +1 -1
  45. package/dist/migrations/v2.1/index.js +601 -19
  46. package/dist/migrations/v2.1/rename-trigger-paths.d.ts +3 -0
  47. package/dist/migrations/v2.1/rename-trigger-paths.d.ts.map +1 -0
  48. package/dist/migrations/v2.1/rename-trigger-paths.js +216 -0
  49. package/dist/notification/index.js +167 -155
  50. package/dist/scopes/index.d.ts +109 -5
  51. package/dist/scopes/index.js +7 -6
  52. package/dist/telemetry/index.d.ts +45 -0
  53. package/dist/telemetry/index.d.ts.map +1 -0
  54. package/dist/telemetry/index.js +43 -0
  55. package/dist/templates/charts-values/dependencies/values.yaml +2 -0
  56. package/dist/translations/check.d.ts +2 -4
  57. package/dist/translations/check.d.ts.map +1 -1
  58. package/dist/translations/check.js +14 -8
  59. package/dist/verify/endpoints.d.ts +2 -0
  60. package/dist/verify/endpoints.d.ts.map +1 -0
  61. package/dist/verify/endpoints.js +345 -0
  62. package/opencrvs-toolkit-2.1.0-rc.05b7761.tgz +0 -0
  63. package/package.json +5 -2
  64. package/tsconfig.build.tsbuildinfo +1 -1
  65. package/tsconfig.json +3 -0
  66. package/opencrvs-toolkit-2.1.0-rc.05a1257.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_path5.join)("environments", environment, INVENTORY_FILE_NAME);
35
+ return (0, import_path7.join)("environments", environment, INVENTORY_FILE_NAME);
36
36
  }
37
37
  function findOldInventoryFiles() {
38
- return glob.sync((0, import_path5.join)(OLD_INVENTORY_DIR, "*.yml")).sort();
38
+ return glob.sync((0, import_path7.join)(OLD_INVENTORY_DIR, "*.yml")).sort();
39
39
  }
40
40
  function getEnvironmentNameFromOldInventoryPath(filePath) {
41
- return (0, import_path5.basename)(filePath, ".yml");
41
+ return (0, import_path7.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_path5, glob, OLD_INVENTORY_DIR, INVENTORY_FILE_NAME;
54
+ var import_path7, 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_path5 = require("path");
58
+ import_path7 = require("path");
59
59
  glob = __toESM(require("glob"));
60
- OLD_INVENTORY_DIR = (0, import_path5.join)(
60
+ OLD_INVENTORY_DIR = (0, import_path7.join)(
61
61
  "infrastructure",
62
62
  "server-setup",
63
63
  "inventory"
@@ -503,24 +503,8 @@ function findExistingValue(name, type, scope, existingValues) {
503
503
  (value) => value.name === name && value.type === type && value.scope === scope
504
504
  );
505
505
  }
506
- function storeSecrets(environment, answers) {
507
- let envConfig = {};
508
- try {
509
- envConfig = import_dotenv.default.parse(
510
- (0, import_fs3.readFileSync)(`${process.cwd()}/.env.${environment}`)
511
- );
512
- } catch (error3) {
513
- envConfig = {};
514
- }
515
- const linesFromAnswers = answers.map(
516
- (update) => `${update.name}="${update.value}"`
517
- );
518
- const linesFromEnvConfig = Object.entries(envConfig).filter(([name]) => !answers.find((update) => update.name === name)).map(([name, value]) => `${name}="${value}"`);
519
- const allLines = [...linesFromEnvConfig, ...linesFromAnswers].sort();
520
- (0, import_fs3.writeFileSync)(`.env.${environment}`, allLines.join("\n"));
521
- }
522
506
  function readYamlFile(filePath) {
523
- const fileContent = import_fs3.default.readFileSync(filePath, "utf8");
507
+ const fileContent = import_fs4.default.readFileSync(filePath, "utf8");
524
508
  return yaml.load(fileContent);
525
509
  }
526
510
  function writeYamlFile(filePath, data) {
@@ -533,33 +517,29 @@ function writeYamlFile(filePath, data) {
533
517
  noRefs: true,
534
518
  sortKeys: false
535
519
  });
536
- import_fs3.default.writeFileSync(filePath, yamlContent, "utf8");
520
+ import_fs4.default.writeFileSync(filePath, yamlContent, "utf8");
537
521
  } catch (error3) {
538
522
  throw new Error(`Failed to write inventory file: ${error3}`);
539
523
  }
540
524
  }
541
- var import_fs3, yaml, import_dotenv;
525
+ var import_fs4, yaml;
542
526
  var init_utils = __esm({
543
527
  "src/environment/utils.ts"() {
544
528
  "use strict";
545
- import_fs3 = __toESM(require("fs"));
529
+ import_fs4 = __toESM(require("fs"));
546
530
  yaml = __toESM(require("js-yaml"));
547
- import_dotenv = __toESM(require("dotenv"));
548
531
  }
549
532
  });
550
533
 
551
534
  // src/environment/templates.ts
552
- function getUsers(data) {
553
- if (!data?.all?.vars?.users) {
554
- return { users: [] };
555
- }
556
- return data.all.vars.users;
557
- }
558
535
  function extractAndModifyUsers(data) {
559
536
  if (!data?.all?.vars?.users) {
560
537
  return { users: [] };
561
538
  }
562
539
  const users = data.all.vars.users.map((user) => {
540
+ if (user.role) {
541
+ return user;
542
+ }
563
543
  const { sudoer, ...rest } = user;
564
544
  return {
565
545
  ...rest,
@@ -595,29 +575,29 @@ function extractWorkerNodes(data) {
595
575
  return worker_hosts;
596
576
  }
597
577
  function copyChartsValues(env, values) {
598
- const srcDir = import_path6.default.resolve(__dirname, "templates", "charts-values");
599
- const destDir = import_path6.default.resolve(process.cwd(), "environments", env);
600
- import_fs4.default.mkdirSync(destDir, { recursive: true });
578
+ const srcDir = import_path8.default.resolve(__dirname, "templates", "charts-values");
579
+ const destDir = import_path8.default.resolve(process.cwd(), "environments", env);
580
+ import_fs5.default.mkdirSync(destDir, { recursive: true });
601
581
  values["lets_encrypt"] = values["traefik_mode"] === "lets_encrypt";
602
582
  values["static_ssl"] = values["traefik_mode"] === "static_ssl";
603
583
  values["opencrvs_environment"] = env;
604
584
  function copyRecursive(src, dest) {
605
- const stat = import_fs4.default.statSync(src);
585
+ const stat = import_fs5.default.statSync(src);
606
586
  if (stat.isDirectory()) {
607
- import_fs4.default.mkdirSync(dest, { recursive: true });
608
- for (const item of import_fs4.default.readdirSync(src)) {
609
- copyRecursive(import_path6.default.join(src, item), import_path6.default.join(dest, item));
587
+ import_fs5.default.mkdirSync(dest, { recursive: true });
588
+ for (const item of import_fs5.default.readdirSync(src)) {
589
+ copyRecursive(import_path8.default.join(src, item), import_path8.default.join(dest, item));
610
590
  }
611
591
  } else {
612
- const content = import_fs4.default.readFileSync(src, "utf8");
592
+ const content = import_fs5.default.readFileSync(src, "utf8");
613
593
  const template = import_handlebars.default.compile(content);
614
594
  const updated = template(values);
615
595
  const isOverridesFile = dest.endsWith("override.yaml");
616
- if (isOverridesFile && import_fs4.default.existsSync(dest)) {
596
+ if (isOverridesFile && import_fs5.default.existsSync(dest)) {
617
597
  log(` \u21B7 Skipped existing overrides file: ${dest}`);
618
598
  return;
619
599
  }
620
- import_fs4.default.writeFileSync(dest, updated, "utf8");
600
+ import_fs5.default.writeFileSync(dest, updated, "utf8");
621
601
  log(` \u2713 Created: ${dest}`);
622
602
  }
623
603
  }
@@ -628,29 +608,29 @@ function copyChartsValues(env, values) {
628
608
  `);
629
609
  }
630
610
  function generateInventory(env, values) {
631
- const templatePath = import_path6.default.join(
611
+ const templatePath = import_path8.default.join(
632
612
  __dirname,
633
613
  "templates",
634
614
  "inventory",
635
615
  "inventory.template.yml"
636
616
  );
637
- const outputPath = import_path6.default.resolve(process.cwd(), getEnvironmentInventoryPath(env));
638
- const templateFile = import_fs4.default.readFileSync(templatePath, "utf-8");
617
+ const outputPath = import_path8.default.resolve(process.cwd(), getEnvironmentInventoryPath(env));
618
+ const templateFile = import_fs5.default.readFileSync(templatePath, "utf-8");
639
619
  const template = import_handlebars.default.compile(templateFile);
640
620
  values["single_node"] = values["kube_worker_nodes"].length > 0 || values["backup_host"] ? "false" : "true";
641
621
  const updated = template(values);
642
- import_fs4.default.mkdirSync(import_path6.default.dirname(outputPath), { recursive: true });
643
- import_fs4.default.writeFileSync(outputPath, updated);
622
+ import_fs5.default.mkdirSync(import_path8.default.dirname(outputPath), { recursive: true });
623
+ import_fs5.default.writeFileSync(outputPath, updated);
644
624
  log(`
645
625
  \u2705 Generated inventory file at ${outputPath}
646
626
  `);
647
627
  }
648
- var import_fs4, import_path6, import_handlebars;
628
+ var import_fs5, import_path8, import_handlebars;
649
629
  var init_templates = __esm({
650
630
  "src/environment/templates.ts"() {
651
631
  "use strict";
652
- import_fs4 = __toESM(require("fs"));
653
- import_path6 = __toESM(require("path"));
632
+ import_fs5 = __toESM(require("fs"));
633
+ import_path8 = __toESM(require("path"));
654
634
  init_logger();
655
635
  init_paths();
656
636
  import_handlebars = __toESM(require("handlebars"));
@@ -706,18 +686,18 @@ var init_git = __esm({
706
686
  });
707
687
 
708
688
  // src/environment/questions.ts
709
- function validateCIDR(input3) {
710
- if (!input3.trim()) {
689
+ function validateCIDR(input4) {
690
+ if (!input4.trim()) {
711
691
  return true;
712
692
  }
713
693
  const cidrRegex = /^((25[0-5]|(2[0-4]|1\d|[1-9]?\d)\d?)\.){3}(25[0-5]|(2[0-4]|1\d|[1-9]?\d)\d?)\/([0-9]|[12][0-9]|3[0-2])$/;
714
- return cidrRegex.test(input3.trim()) ? true : "Please enter a valid CIDR (e.g. 10.0.0.0/24)";
694
+ return cidrRegex.test(input4.trim()) ? true : "Please enter a valid CIDR (e.g. 10.0.0.0/24)";
715
695
  }
716
- function validateCIDRs(input3) {
717
- if (!input3.trim()) {
696
+ function validateCIDRs(input4) {
697
+ if (!input4.trim()) {
718
698
  return true;
719
699
  }
720
- const cidrs = input3.split(",").map((v) => v.trim());
700
+ const cidrs = input4.split(",").map((v) => v.trim());
721
701
  for (const cidr of cidrs) {
722
702
  const result = validateCIDR(cidr);
723
703
  if (result !== true) {
@@ -1247,7 +1227,7 @@ function updateInventoryFile(filePath, users) {
1247
1227
  function parseInventoryFile(filePath) {
1248
1228
  try {
1249
1229
  const data = readYamlFile(filePath);
1250
- return getUsers(data);
1230
+ return extractAndModifyUsers(data);
1251
1231
  } catch {
1252
1232
  return [];
1253
1233
  }
@@ -1257,7 +1237,7 @@ function getCurrentUsername() {
1257
1237
  }
1258
1238
  function getCurrentUserSSHKeys() {
1259
1239
  const homeDir = os.homedir();
1260
- const sshDir = path6.join(homeDir, ".ssh");
1240
+ const sshDir = path8.join(homeDir, ".ssh");
1261
1241
  const keys = [];
1262
1242
  const keyFiles = [
1263
1243
  "id_rsa.pub",
@@ -1266,7 +1246,7 @@ function getCurrentUserSSHKeys() {
1266
1246
  "id_dsa.pub"
1267
1247
  ];
1268
1248
  for (const keyFile of keyFiles) {
1269
- const keyPath = path6.join(sshDir, keyFile);
1249
+ const keyPath = path8.join(sshDir, keyFile);
1270
1250
  try {
1271
1251
  if (fs3.existsSync(keyPath)) {
1272
1252
  const keyContent = fs3.readFileSync(keyPath, "utf8").trim();
@@ -1607,13 +1587,13 @@ async function manageUsers(inventoryPath) {
1607
1587
  }
1608
1588
  return users;
1609
1589
  }
1610
- var os, fs3, path6, input2, select2, confirm, editor, checkbox;
1590
+ var os, fs3, path8, input2, select2, confirm, editor, checkbox;
1611
1591
  var init_manage_users = __esm({
1612
1592
  "src/environment/manage-users.ts"() {
1613
1593
  "use strict";
1614
1594
  os = __toESM(require("os"));
1615
1595
  fs3 = __toESM(require("fs"));
1616
- path6 = __toESM(require("path"));
1596
+ path8 = __toESM(require("path"));
1617
1597
  init_logger();
1618
1598
  init_utils();
1619
1599
  init_templates();
@@ -1635,6 +1615,10 @@ async function select3(options) {
1635
1615
  const inquirer = await import("@inquirer/prompts");
1636
1616
  return inquirer.select(options);
1637
1617
  }
1618
+ async function input3(options) {
1619
+ const inquirer = await import("@inquirer/prompts");
1620
+ return inquirer.input(options);
1621
+ }
1638
1622
  function questionToPrompt({
1639
1623
  valueType,
1640
1624
  valueLabel,
@@ -1701,7 +1685,7 @@ function getAnswers(existingValues) {
1701
1685
  });
1702
1686
  });
1703
1687
  }
1704
- async function promptAndStoreAnswer(environment, questions, existingValues) {
1688
+ async function promptAndStoreAnswer(questions, existingValues) {
1705
1689
  log("");
1706
1690
  const processedQuestions = questions.flatMap((question) => {
1707
1691
  const questionWithVariableLabel = {
@@ -1780,7 +1764,6 @@ async function promptAndStoreAnswer(environment, questions, existingValues) {
1780
1764
  }
1781
1765
  });
1782
1766
  ALL_ANSWERS.push(result);
1783
- storeSecrets(environment, getAnswers(existingValues));
1784
1767
  const existingValuesForQuestions = questions.filter((question) => question.valueType === "VARIABLE").map((question) => [
1785
1768
  question.name,
1786
1769
  findExistingValue(
@@ -1792,12 +1775,11 @@ async function promptAndStoreAnswer(environment, questions, existingValues) {
1792
1775
  ]);
1793
1776
  return { ...Object.fromEntries(existingValuesForQuestions), ...result };
1794
1777
  }
1795
- var import_core, import_dotenv2, import_kleur4, import_prompts2, ALL_QUESTIONS, ALL_ANSWERS;
1778
+ var import_core, import_kleur4, import_prompts2, ALL_QUESTIONS, ALL_ANSWERS;
1796
1779
  var init_setup_environment = __esm({
1797
1780
  "src/environment/setup-environment.ts"() {
1798
1781
  "use strict";
1799
1782
  import_core = require("@octokit/core");
1800
- import_dotenv2 = __toESM(require("dotenv"));
1801
1783
  import_kleur4 = __toESM(require("kleur"));
1802
1784
  import_prompts2 = __toESM(require("prompts"));
1803
1785
  init_github();
@@ -1837,11 +1819,7 @@ var init_setup_environment = __esm({
1837
1819
  }
1838
1820
  }
1839
1821
  );
1840
- const { githubToken } = await promptAndStoreAnswer(
1841
- "",
1842
- githubTokenQuestion,
1843
- []
1844
- );
1822
+ const { githubToken } = await promptAndStoreAnswer(githubTokenQuestion, []);
1845
1823
  const octokit = new import_core.Octokit({
1846
1824
  auth: githubToken
1847
1825
  });
@@ -1898,9 +1876,6 @@ var init_setup_environment = __esm({
1898
1876
  if (!environment) {
1899
1877
  process.exit(1);
1900
1878
  }
1901
- import_dotenv2.default.config({
1902
- path: `${process.cwd()}/.env.${environment}`
1903
- });
1904
1879
  await createEnvironment(
1905
1880
  octokit,
1906
1881
  environment,
@@ -1958,17 +1933,12 @@ var init_setup_environment = __esm({
1958
1933
  "WARNING! You are setting up a production environment.\n Make sure you have read the deployment guide carefully before proceeding.\n"
1959
1934
  )
1960
1935
  );
1961
- await promptAndStoreAnswer(
1962
- environment,
1963
- githubOtherQuestions,
1964
- existingValues
1965
- );
1936
+ await promptAndStoreAnswer(githubOtherQuestions, existingValues);
1966
1937
  }
1967
1938
  log("\n", import_kleur4.default.bold().underline("Docker Hub"));
1968
- await promptAndStoreAnswer(environment, dockerhubQuestions, existingValues);
1939
+ await promptAndStoreAnswer(dockerhubQuestions, existingValues);
1969
1940
  log("\n", import_kleur4.default.bold().underline("Kubernetes & Runtime"));
1970
1941
  const infrastructure = await promptAndStoreAnswer(
1971
- environment,
1972
1942
  infrastructureQuestions,
1973
1943
  existingValues
1974
1944
  );
@@ -2029,7 +1999,7 @@ var init_setup_environment = __esm({
2029
1999
  import_kleur4.default.bold().green("\u2714"),
2030
2000
  import_kleur4.default.bold().yellow(" Disk encryption is enabled")
2031
2001
  );
2032
- await promptAndStoreAnswer(environment, diskQuestions, existingValues);
2002
+ await promptAndStoreAnswer(diskQuestions, existingValues);
2033
2003
  } else {
2034
2004
  if (!enableEncryption && !encryption_key_defined && environment_exists) {
2035
2005
  log(
@@ -2066,6 +2036,7 @@ var init_setup_environment = __esm({
2066
2036
  "ENVIRONMENT",
2067
2037
  existingValues
2068
2038
  )?.value;
2039
+ let restoreHost = findExistingValue("RESTORE_HOST", "VARIABLE", "ENVIRONMENT", existingValues)?.value || "";
2069
2040
  let restoreType = findExistingValue(
2070
2041
  "RESTORE_ENVIRONMENT_MODE",
2071
2042
  "VARIABLE",
@@ -2084,7 +2055,6 @@ var init_setup_environment = __esm({
2084
2055
  let backupHostPublicKey = "";
2085
2056
  if (configureBackup) {
2086
2057
  const backupAnswers = await promptAndStoreAnswer(
2087
- environment,
2088
2058
  backupQuestions,
2089
2059
  existingValues
2090
2060
  );
@@ -2141,15 +2111,15 @@ var init_setup_environment = __esm({
2141
2111
  }
2142
2112
  ]
2143
2113
  });
2114
+ restoreHost = await input3({
2115
+ message: "What is the host/IP address of the restore backup server?",
2116
+ default: restoreHost
2117
+ });
2144
2118
  } else {
2145
2119
  log(import_kleur4.default.bold().green("\u2714"), import_kleur4.default.bold().yellow("Restore is disabled"));
2146
2120
  }
2147
2121
  log("\n", import_kleur4.default.bold().underline("Monitoring"));
2148
- await promptAndStoreAnswer(
2149
- environment,
2150
- databaseAndMonitoringQuestions,
2151
- existingValues
2152
- );
2122
+ await promptAndStoreAnswer(databaseAndMonitoringQuestions, existingValues);
2153
2123
  const sentryDSNExists = findExistingValue(
2154
2124
  "SENTRY_DSN",
2155
2125
  "SECRET",
@@ -2158,7 +2128,7 @@ var init_setup_environment = __esm({
2158
2128
  );
2159
2129
  log("\n", import_kleur4.default.bold().underline("Sentry"));
2160
2130
  if (sentryDSNExists) {
2161
- await promptAndStoreAnswer(environment, sentryQuestions, existingValues);
2131
+ await promptAndStoreAnswer(sentryQuestions, existingValues);
2162
2132
  } else {
2163
2133
  const { useSentry } = await (0, import_prompts2.default)([
2164
2134
  {
@@ -2169,17 +2139,13 @@ var init_setup_environment = __esm({
2169
2139
  }
2170
2140
  ]);
2171
2141
  if (useSentry) {
2172
- await promptAndStoreAnswer(environment, sentryQuestions, existingValues);
2142
+ await promptAndStoreAnswer(sentryQuestions, existingValues);
2173
2143
  }
2174
2144
  }
2175
2145
  log("\n", import_kleur4.default.bold().underline("METABASE ADMIN"));
2176
- await promptAndStoreAnswer(
2177
- environment,
2178
- metabaseAdminQuestions,
2179
- existingValues
2180
- );
2146
+ await promptAndStoreAnswer(metabaseAdminQuestions, existingValues);
2181
2147
  log("\n", import_kleur4.default.bold().underline("SMTP"));
2182
- await promptAndStoreAnswer(environment, emailQuestions, existingValues);
2148
+ await promptAndStoreAnswer(emailQuestions, existingValues);
2183
2149
  const allAnswers = ALL_ANSWERS.reduce((acc, answer) => {
2184
2150
  return { ...acc, ...answer };
2185
2151
  });
@@ -2475,6 +2441,27 @@ var init_setup_environment = __esm({
2475
2441
  existingValues
2476
2442
  ),
2477
2443
  scope: "ENVIRONMENT"
2444
+ },
2445
+ {
2446
+ type: "VARIABLE",
2447
+ name: "RESTORE_HOST",
2448
+ value: answerOrExisting(
2449
+ restoreHost,
2450
+ findExistingValue(
2451
+ "RESTORE_HOST",
2452
+ "VARIABLE",
2453
+ "ENVIRONMENT",
2454
+ existingValues
2455
+ ),
2456
+ (val) => val || ""
2457
+ ),
2458
+ didExist: findExistingValue(
2459
+ "RESTORE_HOST",
2460
+ "VARIABLE",
2461
+ "ENVIRONMENT",
2462
+ existingValues
2463
+ ),
2464
+ scope: "ENVIRONMENT"
2478
2465
  }
2479
2466
  ];
2480
2467
  if (enableEncryption) {
@@ -2521,7 +2508,6 @@ var init_setup_environment = __esm({
2521
2508
  (variable) => Boolean(variable.value) && // Only update values that changed
2522
2509
  (variable.type !== "VARIABLE" || variable.value !== variable.didExist?.value)
2523
2510
  );
2524
- storeSecrets(environment, updates);
2525
2511
  const newSecrets = updates.filter(
2526
2512
  (update) => update.type === "SECRET" && !update.didExist
2527
2513
  );
@@ -2623,6 +2609,12 @@ var init_setup_environment = __esm({
2623
2609
  if ([].concat(newSecrets).concat(updatedSecrets).concat(newVariables).concat(updatedVariables).length === 0) {
2624
2610
  process.exit(0);
2625
2611
  }
2612
+ log(
2613
+ import_kleur4.default.bold().red(
2614
+ "\u26A0\uFE0F COPY THESE NOW INTO A PASSWORD MANAGER \u2014 YOU WON'T SEE THEM AGAIN"
2615
+ )
2616
+ );
2617
+ log("");
2626
2618
  const saveChanges = await confirm2({
2627
2619
  message: "Do you want to continue?",
2628
2620
  default: true
@@ -2737,12 +2729,14 @@ var init_setup_environment = __esm({
2737
2729
  // Hardcode like this blocks us from being generic:
2738
2730
  // https://github.com/opencrvs/opencrvs-core/issues/11171
2739
2731
  two_fa_enabled: environment !== "production" ? false : true,
2740
- backup_enabled: configureBackup ? true : false,
2732
+ traefik_mode: traefikConfOption,
2741
2733
  restore_enabled: restoreEnvironmentName ? true : false,
2742
2734
  restore_environment_name: restoreEnvironmentName || "",
2743
2735
  restore_type: restoreType,
2744
- traefik_mode: traefikConfOption,
2745
- backup_type: backupType
2736
+ restore_host: restoreHost || "",
2737
+ backup_enabled: configureBackup ? true : false,
2738
+ backup_type: backupType,
2739
+ backup_host: backupHost || ""
2746
2740
  });
2747
2741
  let addon_message = kubeWorkerNodes.length > 0 || configureBackup ? `--------------------------------------------------------------------------------------------
2748
2742
 
@@ -2776,8 +2770,10 @@ ${addon_message}
2776
2770
  ${import_kleur4.default.yellow("\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501")}
2777
2771
  ${import_kleur4.default.yellow("Please KINDLY read hints above")}
2778
2772
  `);
2779
- log("\nAll variables stored in", import_kleur4.default.cyan(`.env.${environment}`));
2780
- log(import_kleur4.default.bold().yellow("DO NOT COMMIT THIS FILE TO GIT!"));
2773
+ log(
2774
+ "\nAll secrets and variables were printed above.",
2775
+ import_kleur4.default.bold().yellow("Store them in a password manager \u2014 they are not saved to disk.")
2776
+ );
2781
2777
  })();
2782
2778
  }
2783
2779
  });
@@ -2787,16 +2783,16 @@ var update_workflows_exports = {};
2787
2783
  __export(update_workflows_exports, {
2788
2784
  updateWorkflowEnvironments: () => updateWorkflowEnvironments
2789
2785
  });
2790
- function isDirectory(path9) {
2786
+ function isDirectory(path11) {
2791
2787
  try {
2792
- return (0, import_fs5.statSync)(path9).isDirectory();
2788
+ return (0, import_fs6.statSync)(path11).isDirectory();
2793
2789
  } catch {
2794
2790
  return false;
2795
2791
  }
2796
2792
  }
2797
2793
  async function extractInfrastructureNames() {
2798
- const files = glob2.sync((0, import_path7.join)("environments", "*", INVENTORY_FILE_NAME));
2799
- const infraEnvironments = files.map((file) => (0, import_path7.basename)((0, import_path7.dirname)(file)));
2794
+ const files = glob2.sync((0, import_path9.join)("environments", "*", INVENTORY_FILE_NAME));
2795
+ const infraEnvironments = files.map((file) => (0, import_path9.basename)((0, import_path9.dirname)(file)));
2800
2796
  if (infraEnvironments.length === 0) {
2801
2797
  console.log(
2802
2798
  `\u26A0\uFE0F Warning: No environment inventory files found at environments/*/${INVENTORY_FILE_NAME}`
@@ -2809,9 +2805,9 @@ async function extractInfrastructureNames() {
2809
2805
  async function extractEnvironmentNames() {
2810
2806
  const entries = await (0, import_promises.readdir)("environments");
2811
2807
  const environments = entries.filter((entry) => {
2812
- const environmentPath = (0, import_path7.join)("environments", entry);
2813
- const opencrvsServicesPath = (0, import_path7.join)(environmentPath, "opencrvs-services");
2814
- return isDirectory(environmentPath) && (0, import_fs5.existsSync)(opencrvsServicesPath) && isDirectory(opencrvsServicesPath);
2808
+ const environmentPath = (0, import_path9.join)("environments", entry);
2809
+ const opencrvsServicesPath = (0, import_path9.join)(environmentPath, "opencrvs-services");
2810
+ return isDirectory(environmentPath) && (0, import_fs6.existsSync)(opencrvsServicesPath) && isDirectory(opencrvsServicesPath);
2815
2811
  });
2816
2812
  if (environments.length === 0) {
2817
2813
  console.log(
@@ -2836,8 +2832,12 @@ function updateOptionsInYaml(content, envList) {
2836
2832
  async function updateWorkflows(envList, config) {
2837
2833
  const { workflows } = config;
2838
2834
  for (const workflowPath of workflows) {
2835
+ if (!(0, import_fs6.existsSync)(workflowPath)) {
2836
+ log(` \u21B7 Skipped ${workflowPath} (not found in this repository)`);
2837
+ continue;
2838
+ }
2839
2839
  try {
2840
- const fileContents = (0, import_fs5.readFileSync)(workflowPath, "utf8");
2840
+ const fileContents = (0, import_fs6.readFileSync)(workflowPath, "utf8");
2841
2841
  const workflowData = yaml2.load(fileContents);
2842
2842
  if (!workflowData?.on?.workflow_dispatch?.inputs?.environment?.options) {
2843
2843
  throw new Error(
@@ -2845,7 +2845,7 @@ async function updateWorkflows(envList, config) {
2845
2845
  );
2846
2846
  }
2847
2847
  const updatedContent = updateOptionsInYaml(fileContents, envList);
2848
- (0, import_fs5.writeFileSync)(workflowPath, updatedContent, "utf8");
2848
+ (0, import_fs6.writeFileSync)(workflowPath, updatedContent, "utf8");
2849
2849
  log(` \u2713 Successfully updated ${workflowPath}`);
2850
2850
  } catch (error3) {
2851
2851
  console.error(
@@ -2899,13 +2899,13 @@ async function updateWorkflowEnvironments() {
2899
2899
  process.exit(1);
2900
2900
  }
2901
2901
  }
2902
- var import_promises, import_fs5, import_path7, glob2, yaml2;
2902
+ var import_promises, import_fs6, import_path9, glob2, yaml2;
2903
2903
  var init_update_workflows = __esm({
2904
2904
  "src/environment/update-workflows.ts"() {
2905
2905
  "use strict";
2906
2906
  import_promises = require("fs/promises");
2907
- import_fs5 = require("fs");
2908
- import_path7 = require("path");
2907
+ import_fs6 = require("fs");
2908
+ import_path9 = require("path");
2909
2909
  glob2 = __toESM(require("glob"));
2910
2910
  yaml2 = __toESM(require("js-yaml"));
2911
2911
  init_logger();
@@ -2919,17 +2919,17 @@ __export(upgrade_exports, {
2919
2919
  upgradeEnvironmentLayout: () => upgradeEnvironmentLayout
2920
2920
  });
2921
2921
  function moveFileIfDestinationMissing(sourcePath, destinationPath) {
2922
- if (!(0, import_fs6.existsSync)(sourcePath)) {
2922
+ if (!(0, import_fs7.existsSync)(sourcePath)) {
2923
2923
  return false;
2924
2924
  }
2925
- if ((0, import_fs6.existsSync)(destinationPath)) {
2925
+ if ((0, import_fs7.existsSync)(destinationPath)) {
2926
2926
  warn(
2927
2927
  `\u26A0\uFE0F Skipped ${sourcePath}; destination already exists at ${destinationPath}`
2928
2928
  );
2929
2929
  return false;
2930
2930
  }
2931
- (0, import_fs6.mkdirSync)((0, import_path8.dirname)(destinationPath), { recursive: true });
2932
- (0, import_fs6.renameSync)(sourcePath, destinationPath);
2931
+ (0, import_fs7.mkdirSync)((0, import_path10.dirname)(destinationPath), { recursive: true });
2932
+ (0, import_fs7.renameSync)(sourcePath, destinationPath);
2933
2933
  log(` \u2713 Moved ${sourcePath} -> ${destinationPath}`);
2934
2934
  return true;
2935
2935
  }
@@ -2949,8 +2949,8 @@ function migrateInventoryFiles() {
2949
2949
  ) || didMoveInventory;
2950
2950
  }
2951
2951
  try {
2952
- if ((0, import_fs6.existsSync)(OLD_INVENTORY_DIR) && (0, import_fs6.readdirSync)(OLD_INVENTORY_DIR).length === 0) {
2953
- (0, import_fs6.rmdirSync)(OLD_INVENTORY_DIR);
2952
+ if ((0, import_fs7.existsSync)(OLD_INVENTORY_DIR) && (0, import_fs7.readdirSync)(OLD_INVENTORY_DIR).length === 0) {
2953
+ (0, import_fs7.rmdirSync)(OLD_INVENTORY_DIR);
2954
2954
  log(` \u2713 Removed empty ${OLD_INVENTORY_DIR}`);
2955
2955
  }
2956
2956
  } catch {
@@ -2968,12 +2968,12 @@ async function upgradeEnvironmentLayout() {
2968
2968
  }
2969
2969
  log("\nCommit changes into git after upgrade");
2970
2970
  }
2971
- var import_fs6, import_path8, import_kleur5;
2971
+ var import_fs7, import_path10, import_kleur5;
2972
2972
  var init_upgrade = __esm({
2973
2973
  "src/environment/upgrade.ts"() {
2974
2974
  "use strict";
2975
- import_fs6 = require("fs");
2976
- import_path8 = require("path");
2975
+ import_fs7 = require("fs");
2976
+ import_path10 = require("path");
2977
2977
  import_kleur5 = __toESM(require("kleur"));
2978
2978
  init_logger();
2979
2979
  init_paths();
@@ -2999,7 +2999,7 @@ async function selectInventoryFile(dirPath = "./environments") {
2999
2999
  return null;
3000
3000
  }
3001
3001
  const environments = fs4.readdirSync(dirPath).filter((entry) => {
3002
- const filePath = path7.join(dirPath, entry);
3002
+ const filePath = path9.join(dirPath, entry);
3003
3003
  return fs4.statSync(filePath).isDirectory() && fs4.existsSync(getEnvironmentInventoryPath(entry));
3004
3004
  }).sort();
3005
3005
  if (environments.length === 0) {
@@ -3027,12 +3027,12 @@ async function manageEnvironmentUsers() {
3027
3027
  }
3028
3028
  await manageUsers(inventory_file);
3029
3029
  }
3030
- var fs4, path7, import_kleur6;
3030
+ var fs4, path9, import_kleur6;
3031
3031
  var init_users = __esm({
3032
3032
  "src/environment/users.ts"() {
3033
3033
  "use strict";
3034
3034
  fs4 = __toESM(require("fs"));
3035
- path7 = __toESM(require("path"));
3035
+ path9 = __toESM(require("path"));
3036
3036
  import_kleur6 = __toESM(require("kleur"));
3037
3037
  init_manage_users();
3038
3038
  init_logger();
@@ -3042,11 +3042,11 @@ var init_users = __esm({
3042
3042
 
3043
3043
  // src/environment/swarm-to-k8s.ts
3044
3044
  var swarm_to_k8s_exports = {};
3045
- var path8, import_kleur7, import_core2;
3045
+ var path10, import_kleur7, import_core2;
3046
3046
  var init_swarm_to_k8s = __esm({
3047
3047
  "src/environment/swarm-to-k8s.ts"() {
3048
3048
  "use strict";
3049
- path8 = __toESM(require("path"));
3049
+ path10 = __toESM(require("path"));
3050
3050
  import_kleur7 = __toESM(require("kleur"));
3051
3051
  init_logger();
3052
3052
  init_utils();
@@ -3098,7 +3098,7 @@ var init_swarm_to_k8s = __esm({
3098
3098
  );
3099
3099
  process.exit(1);
3100
3100
  }
3101
- const ansible_inventory = path8.join(old_inventory_path, environment + ".yml");
3101
+ const ansible_inventory = path10.join(old_inventory_path, environment + ".yml");
3102
3102
  const data = readYamlFile(ansible_inventory);
3103
3103
  log(` \u2713 Loaded old inventory file: ${ansible_inventory}`);
3104
3104
  const master = dockerManagerFirst(data) || "";
@@ -3406,16 +3406,16 @@ var import_path2 = __toESM(require("path"));
3406
3406
 
3407
3407
  // src/csv.ts
3408
3408
  var import_fs = require("fs");
3409
- function parseCsvLine(line) {
3409
+ function parseCsvLine(line2) {
3410
3410
  const values = [];
3411
3411
  let value = "";
3412
3412
  let quoted = false;
3413
- for (let index = 0; index < line.length; index++) {
3414
- const character = line[index];
3413
+ for (let index = 0; index < line2.length; index++) {
3414
+ const character = line2[index];
3415
3415
  if (quoted) {
3416
3416
  if (character !== '"') {
3417
3417
  value += character;
3418
- } else if (line[index + 1] === '"') {
3418
+ } else if (line2[index + 1] === '"') {
3419
3419
  value += '"';
3420
3420
  index++;
3421
3421
  } else {
@@ -3440,36 +3440,38 @@ function toCsvLine(values) {
3440
3440
  (value) => /["\n,]/.test(value) ? `"${value.replace(/"/g, '""')}"` : value
3441
3441
  ).join(",");
3442
3442
  }
3443
- function idOf(line) {
3444
- return line.slice(0, line.indexOf(","));
3443
+ function idOf(line2) {
3444
+ const comma = line2.indexOf(",");
3445
+ return comma === -1 ? line2 : line2.slice(0, comma);
3445
3446
  }
3446
- function readCsvFile(path9) {
3447
- if (!(0, import_fs.existsSync)(path9)) {
3447
+ function readCsvFile(path11) {
3448
+ if (!(0, import_fs.existsSync)(path11)) {
3448
3449
  return void 0;
3449
3450
  }
3450
- const contents = (0, import_fs.readFileSync)(path9, "utf8");
3451
+ const contents = (0, import_fs.readFileSync)(path11, "utf8");
3451
3452
  const newline = contents.includes("\r\n") ? "\r\n" : "\n";
3452
3453
  const trailingNewline = /\r?\n$/.test(contents);
3453
3454
  const lines = contents.replace(/\r?\n$/, "").split(/\r?\n/);
3454
- return { header: lines[0], body: lines.slice(1), newline, trailingNewline };
3455
+ const body = lines.slice(1).filter((line2) => line2 !== "");
3456
+ return { header: lines[0], body, newline, trailingNewline };
3455
3457
  }
3456
- function writeCsvFile(path9, file) {
3458
+ function writeCsvFile(path11, file) {
3457
3459
  (0, import_fs.writeFileSync)(
3458
- path9,
3460
+ path11,
3459
3461
  [file.header, ...file.body].join(file.newline) + (file.trailingNewline ? file.newline : "")
3460
3462
  );
3461
3463
  }
3462
3464
  function addRows(file, rows) {
3463
3465
  const isSorted = file.body.every(
3464
- (line, index) => index === 0 || idOf(file.body[index - 1]) <= idOf(line)
3466
+ (line2, index) => index === 0 || idOf(file.body[index - 1]) <= idOf(line2)
3465
3467
  );
3466
3468
  const added = [];
3467
3469
  for (const row of rows) {
3468
3470
  const id = idOf(row);
3469
- if (file.body.some((line) => idOf(line) === id)) {
3471
+ if (file.body.some((line2) => idOf(line2) === id)) {
3470
3472
  continue;
3471
3473
  }
3472
- const insertAt = isSorted ? file.body.findIndex((line) => idOf(line) > id) : -1;
3474
+ const insertAt = isSorted ? file.body.findIndex((line2) => idOf(line2) > id) : -1;
3473
3475
  if (insertAt === -1) {
3474
3476
  file.body.push(row);
3475
3477
  } else {
@@ -3570,7 +3572,7 @@ function appendEntry(sourceFile, objectName, key, valueLines) {
3570
3572
  const lastProperty = properties[properties.length - 1];
3571
3573
  if (!lastProperty) return false;
3572
3574
  const indent = lastProperty.getIndentationText();
3573
- const entry = valueLines.map((line, index) => `${indent}${index === 0 ? `${key}: ${line}` : line}`).join("\n");
3575
+ const entry = valueLines.map((line2, index) => `${indent}${index === 0 ? `${key}: ${line2}` : line2}`).join("\n");
3574
3576
  sourceFile.insertText(lastProperty.getEnd(), `,
3575
3577
  ${entry}`);
3576
3578
  return true;
@@ -3738,14 +3740,14 @@ function updateHandler(project, cwd) {
3738
3740
  if (defaultClause) {
3739
3741
  caseBlock.insertText(
3740
3742
  anchor.getStart(),
3741
- `${lines.map((line, index) => index === 0 ? line : `${indent}${line}`).join("\n")}
3743
+ `${lines.map((line2, index) => index === 0 ? line2 : `${indent}${line2}`).join("\n")}
3742
3744
  ${indent}`
3743
3745
  );
3744
3746
  } else {
3745
3747
  caseBlock.insertText(
3746
3748
  anchor.getEnd(),
3747
3749
  `
3748
- ${lines.map((line) => `${indent}${line}`).join("\n")}`
3750
+ ${lines.map((line2) => `${indent}${line2}`).join("\n")}`
3749
3751
  );
3750
3752
  }
3751
3753
  for (const event of missing) {
@@ -3767,10 +3769,10 @@ function updateRoutes(project, cwd) {
3767
3769
  return;
3768
3770
  }
3769
3771
  for (const event of RECOVERY_EVENTS) {
3770
- if (routesArray.getText().includes(`/triggers/user/${event.id}`)) continue;
3772
+ if (routesArray.getText().includes(`/trigger/user/${event.id}`)) continue;
3771
3773
  routesArray.addElement(`{
3772
3774
  method: 'POST',
3773
- path: '/triggers/user/${event.id}',
3775
+ path: '/trigger/user/${event.id}',
3774
3776
  handler: makeNotificationHandler('${event.id}'),
3775
3777
  options: {
3776
3778
  auth: false,
@@ -3778,7 +3780,7 @@ function updateRoutes(project, cwd) {
3778
3780
  description: '${event.routeDescription}'
3779
3781
  }
3780
3782
  }`);
3781
- console.log(` \u2713 ${ROUTES_FILE}: POST /triggers/user/${event.id}`);
3783
+ console.log(` \u2713 ${ROUTES_FILE}: POST /trigger/user/${event.id}`);
3782
3784
  }
3783
3785
  }
3784
3786
  function renderEmailTemplate(event) {
@@ -3941,7 +3943,9 @@ async function matchingRefs(namespace, prefix) {
3941
3943
  headers: { accept: "application/vnd.github+json" }
3942
3944
  });
3943
3945
  if (!response.ok) {
3944
- return [];
3946
+ throw new Error(
3947
+ `GitHub answered ${response.status} ${response.statusText} for ${url}`
3948
+ );
3945
3949
  }
3946
3950
  const refs = await response.json();
3947
3951
  const patchOf = (ref) => Number(ref.split(".").pop()) || 0;
@@ -3961,6 +3965,11 @@ async function fetchTemplate(refs, application) {
3961
3965
  if (response.ok) {
3962
3966
  return { ref, contents: await response.text() };
3963
3967
  }
3968
+ if (response.status !== 404) {
3969
+ throw new Error(
3970
+ `GitHub answered ${response.status} ${response.statusText} for ${url}`
3971
+ );
3972
+ }
3964
3973
  }
3965
3974
  warnSkipped2(
3966
3975
  `No ${application}.csv found in the ${TARGET_VERSION} country config template on GitHub; ${application}.csv not updated`
@@ -3970,8 +3979,8 @@ async function fetchTemplate(refs, application) {
3970
3979
  function rowsToAdd(local, template) {
3971
3980
  const localColumns = parseCsvLine(local.header);
3972
3981
  const templateColumns = parseCsvLine(template.header);
3973
- return template.body.filter((line) => line !== "").map((line) => {
3974
- const values = parseCsvLine(line);
3982
+ return template.body.filter((line2) => line2 !== "").map((line2) => {
3983
+ const values = parseCsvLine(line2);
3975
3984
  return toCsvLine(
3976
3985
  localColumns.map((column) => {
3977
3986
  const index = templateColumns.indexOf(column);
@@ -3996,7 +4005,14 @@ async function updateApplication(cwd, refs, application) {
3996
4005
  if (added.length === 0) {
3997
4006
  return;
3998
4007
  }
3999
- writeCsvFile(import_path3.default.join(cwd, relativePath), local);
4008
+ try {
4009
+ writeCsvFile(import_path3.default.join(cwd, relativePath), local);
4010
+ } catch (error3) {
4011
+ warnSkipped2(
4012
+ `Could not write ${relativePath} (${error3.message}); translations not added`
4013
+ );
4014
+ return;
4015
+ }
4000
4016
  for (const id of added) {
4001
4017
  console.log(` \u2713 ${relativePath}: ${id}`);
4002
4018
  }
@@ -4010,18 +4026,30 @@ function readTemplate(contents) {
4010
4026
  trailingNewline: true
4011
4027
  };
4012
4028
  }
4029
+ async function listRefs() {
4030
+ try {
4031
+ return await candidateRefs();
4032
+ } catch (error3) {
4033
+ warnSkipped2(
4034
+ `Could not list the ${TARGET_VERSION} refs on GitHub (${error3.message}); translations not added`
4035
+ );
4036
+ return void 0;
4037
+ }
4038
+ }
4013
4039
  async function main3() {
4014
4040
  const cwd = process.cwd();
4015
4041
  console.log("Adding the translation keys core gained this version...\n");
4016
- try {
4017
- const refs = await candidateRefs();
4042
+ const refs = await listRefs();
4043
+ if (refs) {
4018
4044
  for (const application of APPLICATIONS) {
4019
- await updateApplication(cwd, refs, application);
4045
+ try {
4046
+ await updateApplication(cwd, refs, application);
4047
+ } catch (error3) {
4048
+ warnSkipped2(
4049
+ `Could not read ${application}.csv from the country config template on GitHub (${error3.message}); ${application}.csv not updated`
4050
+ );
4051
+ }
4020
4052
  }
4021
- } catch (error3) {
4022
- warnSkipped2(
4023
- `Could not read the country config template from GitHub (${error3.message}); translations not added`
4024
- );
4025
4053
  }
4026
4054
  if (skipped2.length > 0) {
4027
4055
  console.warn(
@@ -4034,40 +4062,592 @@ async function main3() {
4034
4062
  }
4035
4063
  }
4036
4064
 
4065
+ // src/migrations/v2.1/enable-telemetry.ts
4066
+ var import_ts_morph3 = require("ts-morph");
4067
+ var import_fs3 = require("fs");
4068
+ var import_path4 = __toESM(require("path"));
4069
+ var HANDLER_FILE2 = "src/api/telemetry/handler.ts";
4070
+ var ENVIRONMENT_FILE = "src/environment.ts";
4071
+ var INDEX_FILE = "src/index.ts";
4072
+ var HANDLER_MODULE = "./api/telemetry/handler";
4073
+ var skipped3 = [];
4074
+ function warnSkipped3(message) {
4075
+ skipped3.push(message);
4076
+ console.warn(` \u26A0\uFE0F ${message}`);
4077
+ }
4078
+ var TELEMETRY_HANDLER_SOURCE = `/*
4079
+ * This Source Code Form is subject to the terms of the Mozilla Public
4080
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
4081
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/.
4082
+ *
4083
+ * OpenCRVS is also distributed under the terms of the Civil Registration
4084
+ * & Healthcare Disclaimer located at http://opencrvs.org/license.
4085
+ *
4086
+ * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
4087
+ */
4088
+
4089
+ import { Request, ResponseToolkit } from '@hapi/hapi'
4090
+ import * as Joi from 'joi'
4091
+ import { sendTelemetry, TelemetryReport } from '@opencrvs/toolkit/telemetry'
4092
+ import { env } from '@countryconfig/environment'
4093
+ import { logger } from '@countryconfig/logger'
4094
+ import { applicationConfig } from '@countryconfig/api/application/application-config'
4095
+
4096
+ /** Report the events service posts to \`/trigger/telemetry\`. */
4097
+ export const telemetrySchema = Joi.object({
4098
+ reported_at: Joi.string().isoDate().required(),
4099
+ app_version: Joi.string().optional(),
4100
+ metrics: Joi.object()
4101
+ .pattern(
4102
+ Joi.string(),
4103
+ Joi.alternatives(Joi.number(), Joi.string(), Joi.boolean())
4104
+ )
4105
+ .required()
4106
+ })
4107
+
4108
+ interface IncomingReport {
4109
+ reported_at: string
4110
+ app_version?: string
4111
+ metrics: Record<string, number | string | boolean>
4112
+ }
4113
+
4114
+ /** Logged once at countryconfig startup while telemetry is disabled. */
4115
+ export const TELEMETRY_DISABLED_NOTICE =
4116
+ 'Telemetry is disabled. Help improve OpenCRVS by sharing anonymous, ' +
4117
+ 'aggregate usage metrics (registration and certificate counts, active ' +
4118
+ 'users, uptime) \u2014 no personal, health, or otherwise protected record data ' +
4119
+ 'ever leaves your instance. Enable it by setting TELEMETRY_ENABLED=true on ' +
4120
+ 'the countryconfig service.'
4121
+
4122
+ /**
4123
+ * Receives a usage report from the events service and, when telemetry is
4124
+ * enabled for this instance, stamps the instance identity onto it and forwards
4125
+ * it to the status service via the toolkit's \`sendTelemetry\` (which owns the
4126
+ * endpoint and payload schema). The events service is unaware of whether
4127
+ * telemetry is enabled or of the country code / domain / environment reported.
4128
+ */
4129
+ export async function telemetryHandler(request: Request, h: ResponseToolkit) {
4130
+ // Only accept OpenCRVS *system* tokens (the events service's service
4131
+ // token has userType 'system'). A logged-in user's token is a 'user' token,
4132
+ // so a user cannot submit telemetry with their own credentials \u2014 and the
4133
+ // service-token endpoint is not reachable through the public gateway.
4134
+ const credentials = request.auth.credentials as
4135
+ | { userType?: string }
4136
+ | undefined
4137
+ if (credentials?.userType !== 'system') {
4138
+ logger.warn('Telemetry: rejected a request that is not from a system token')
4139
+ return h.response({ error: 'forbidden' }).code(403)
4140
+ }
4141
+
4142
+ if (!env.TELEMETRY_ENABLED) {
4143
+ // The encouraging notice is logged once at startup (see index.ts); keep the
4144
+ // per-report path quiet.
4145
+ return h.response({ status: 'skipped' }).code(200)
4146
+ }
4147
+
4148
+ const incoming = request.payload as IncomingReport
4149
+
4150
+ // Only production instances report; staging, QA and local build the report
4151
+ // but never reach the status service. (This gate used to live in the
4152
+ // toolkit's sendTelemetry; each country config now owns it.)
4153
+ if (!env.isProduction) {
4154
+ logger.info(
4155
+ \`Telemetry: report for \${incoming.reported_at} was not sent \u2014 only production instances report\`
4156
+ )
4157
+ return h.response({ status: 'skipped' }).code(200)
4158
+ }
4159
+
4160
+ const report: TelemetryReport = {
4161
+ reported_at: incoming.reported_at,
4162
+ country_code: env.COUNTRY_CODE,
4163
+ organisation: env.ORGANISATION,
4164
+ // env.DOMAIN defaults to a wildcard for CORS in some setups; treat that as
4165
+ // "no domain" rather than reporting a literal "*".
4166
+ domain: env.DOMAIN && env.DOMAIN !== '*' ? env.DOMAIN : null,
4167
+ instance: {
4168
+ application_name: applicationConfig.APPLICATION_NAME,
4169
+ environment: env.ENVIRONMENT_NAME,
4170
+ app_version: incoming.app_version
4171
+ },
4172
+ metrics: incoming.metrics
4173
+ }
4174
+
4175
+ let result
4176
+ try {
4177
+ result = await sendTelemetry(report)
4178
+ } catch (error) {
4179
+ const message = error instanceof Error ? error.message : String(error)
4180
+ logger.error(\`Telemetry: forwarding to status service failed: \${message}\`)
4181
+ return h.response({ status: 'error' }).code(502)
4182
+ }
4183
+
4184
+ if (result.outcome === 'rejected') {
4185
+ logger.error(
4186
+ \`Telemetry: status service rejected report (HTTP \${result.status}): \${result.detail ?? ''}\`
4187
+ )
4188
+ return h.response({ status: 'error' }).code(502)
4189
+ }
4190
+
4191
+ logger.info(
4192
+ \`Telemetry: forwarded report for \${report.reported_at} to the status service\`
4193
+ )
4194
+ return h.response({ status: 'forwarded' }).code(202)
4195
+ }
4196
+ `;
4197
+ var TELEMETRY_DISABLED = {
4198
+ enabled: false,
4199
+ countryCode: "",
4200
+ organisation: ""
4201
+ };
4202
+ async function promptTelemetryConfig() {
4203
+ if (!process.stdin.isTTY) {
4204
+ return TELEMETRY_DISABLED;
4205
+ }
4206
+ const { confirm: confirm3, input: input4 } = await import("@inquirer/prompts");
4207
+ const enabled = await confirm3({
4208
+ message: "Enable anonymous usage telemetry to help improve OpenCRVS? Only aggregate metrics are shared \u2014 no personal or protected data.",
4209
+ default: true
4210
+ });
4211
+ if (!enabled) {
4212
+ return TELEMETRY_DISABLED;
4213
+ }
4214
+ const countryCode = (await input4({
4215
+ message: "Country code (ISO alpha-3, e.g. FAR):",
4216
+ validate: (value) => /^[A-Za-z]{3}$/.test(value.trim()) || "Enter a 3-letter ISO alpha-3 code."
4217
+ })).trim().toUpperCase();
4218
+ const organisation = (await input4({
4219
+ message: "Organisation running this instance:",
4220
+ validate: (value) => value.trim() !== "" || "Enter an organisation name."
4221
+ })).trim();
4222
+ return { enabled: true, countryCode, organisation };
4223
+ }
4224
+ function writeTelemetryHandler(cwd) {
4225
+ const handlerPath = import_path4.default.join(cwd, HANDLER_FILE2);
4226
+ if ((0, import_fs3.existsSync)(handlerPath)) {
4227
+ console.log(` ${HANDLER_FILE2} already present; left unchanged`);
4228
+ return;
4229
+ }
4230
+ (0, import_fs3.mkdirSync)(import_path4.default.dirname(handlerPath), { recursive: true });
4231
+ (0, import_fs3.writeFileSync)(handlerPath, TELEMETRY_HANDLER_SOURCE);
4232
+ console.log(` \u2713 ${HANDLER_FILE2}`);
4233
+ }
4234
+ function appendProperty(sourceFile, object, name, valueLines) {
4235
+ const properties = object.getProperties();
4236
+ const lastProperty = properties[properties.length - 1];
4237
+ if (!lastProperty) return false;
4238
+ const indent = lastProperty.getIndentationText();
4239
+ const entry = valueLines.map((line2, index) => `${indent}${index === 0 ? `${name}: ${line2}` : line2}`).join("\n");
4240
+ sourceFile.insertText(lastProperty.getEnd(), `,
4241
+ ${entry}`);
4242
+ return true;
4243
+ }
4244
+ function ensureEnvalidNamedImports(sourceFile, names) {
4245
+ const importDeclaration = sourceFile.getImportDeclarations().find((declaration) => declaration.getModuleSpecifierValue() === "envalid");
4246
+ if (!importDeclaration) {
4247
+ warnSkipped3(
4248
+ `Could not find the 'envalid' import in ${ENVIRONMENT_FILE}; import { ${names.join(", ")} } by hand`
4249
+ );
4250
+ return;
4251
+ }
4252
+ const existing = new Set(
4253
+ importDeclaration.getNamedImports().map((named) => named.getName())
4254
+ );
4255
+ for (const name of names) {
4256
+ if (!existing.has(name)) {
4257
+ importDeclaration.addNamedImport(name);
4258
+ }
4259
+ }
4260
+ }
4261
+ function getCleanEnvObject(sourceFile) {
4262
+ const options = sourceFile.getDescendantsOfKind(import_ts_morph3.SyntaxKind.CallExpression).find((call) => call.getExpression().getText() === "cleanEnv")?.getArguments()[1];
4263
+ return options && import_ts_morph3.Node.isObjectLiteralExpression(options) ? options : void 0;
4264
+ }
4265
+ function upsertEnvVar(sourceFile, name, kind, defaultExpr, desc, update) {
4266
+ const object = getCleanEnvObject(sourceFile);
4267
+ if (!object) return;
4268
+ const existing = object.getProperty(name);
4269
+ if (existing && import_ts_morph3.Node.isPropertyAssignment(existing)) {
4270
+ if (!update) return;
4271
+ const options = existing.getInitializerIfKind(import_ts_morph3.SyntaxKind.CallExpression)?.getArguments()[0];
4272
+ if (options && import_ts_morph3.Node.isObjectLiteralExpression(options)) {
4273
+ const defaultProperty = options.getProperty("default");
4274
+ if (defaultProperty && import_ts_morph3.Node.isPropertyAssignment(defaultProperty)) {
4275
+ defaultProperty.setInitializer(defaultExpr);
4276
+ } else {
4277
+ options.insertPropertyAssignment(0, {
4278
+ name: "default",
4279
+ initializer: defaultExpr
4280
+ });
4281
+ }
4282
+ console.log(` \u2713 ${ENVIRONMENT_FILE}: ${name} default set`);
4283
+ }
4284
+ return;
4285
+ }
4286
+ if (appendProperty(sourceFile, object, name, [
4287
+ `${kind}({`,
4288
+ ` default: ${defaultExpr},`,
4289
+ ` desc: ${JSON.stringify(desc)}`,
4290
+ "})"
4291
+ ])) {
4292
+ console.log(` \u2713 ${ENVIRONMENT_FILE}: ${name}`);
4293
+ }
4294
+ }
4295
+ function addEnvironmentVariables(project, cwd, config) {
4296
+ const sourceFile = project.addSourceFileAtPathIfExists(
4297
+ import_path4.default.join(cwd, ENVIRONMENT_FILE)
4298
+ );
4299
+ if (!sourceFile) {
4300
+ warnSkipped3(
4301
+ `${ENVIRONMENT_FILE} not found; add the telemetry env vars by hand`
4302
+ );
4303
+ return;
4304
+ }
4305
+ if (!getCleanEnvObject(sourceFile)) {
4306
+ warnSkipped3(
4307
+ `Could not find the cleanEnv(...) config object in ${ENVIRONMENT_FILE}; add the telemetry env vars by hand`
4308
+ );
4309
+ return;
4310
+ }
4311
+ ensureEnvalidNamedImports(sourceFile, ["bool", "str"]);
4312
+ upsertEnvVar(
4313
+ sourceFile,
4314
+ "TELEMETRY_ENABLED",
4315
+ "bool",
4316
+ config.enabled ? "true" : "false",
4317
+ "When true, usage telemetry received from the events service is forwarded to the OpenCRVS status service.",
4318
+ true
4319
+ );
4320
+ upsertEnvVar(
4321
+ sourceFile,
4322
+ "COUNTRY_CODE",
4323
+ "str",
4324
+ config.enabled ? JSON.stringify(config.countryCode) : `'FAR'`,
4325
+ "ISO-style country code of this instance, reported with telemetry.",
4326
+ config.enabled
4327
+ );
4328
+ upsertEnvVar(
4329
+ sourceFile,
4330
+ "ORGANISATION",
4331
+ "str",
4332
+ config.enabled ? JSON.stringify(config.organisation) : `''`,
4333
+ "Organisation running this instance, reported with telemetry. Empty by default.",
4334
+ config.enabled
4335
+ );
4336
+ upsertEnvVar(
4337
+ sourceFile,
4338
+ "ENVIRONMENT_NAME",
4339
+ "str",
4340
+ `'development'`,
4341
+ 'Environment name (e.g. "production", "staging") reported as the telemetry environment.',
4342
+ false
4343
+ );
4344
+ }
4345
+ function ensureHandlerNamedImports(sourceFile, names) {
4346
+ const importDeclaration = sourceFile.getImportDeclarations().find(
4347
+ (declaration) => declaration.getModuleSpecifierValue() === HANDLER_MODULE
4348
+ );
4349
+ if (!importDeclaration) {
4350
+ sourceFile.addImportDeclaration({
4351
+ moduleSpecifier: HANDLER_MODULE,
4352
+ namedImports: names
4353
+ });
4354
+ console.log(` \u2713 ${INDEX_FILE}: import ${HANDLER_MODULE}`);
4355
+ return;
4356
+ }
4357
+ const existing = new Set(
4358
+ importDeclaration.getNamedImports().map((named) => named.getName())
4359
+ );
4360
+ const missing = names.filter((name) => !existing.has(name));
4361
+ for (const name of missing) {
4362
+ importDeclaration.addNamedImport(name);
4363
+ }
4364
+ if (missing.length > 0) {
4365
+ console.log(
4366
+ ` \u2713 ${INDEX_FILE}: import ${missing.join(", ")} from ${HANDLER_MODULE}`
4367
+ );
4368
+ }
4369
+ }
4370
+ function wireIndex(project, cwd) {
4371
+ const sourceFile = project.addSourceFileAtPathIfExists(
4372
+ import_path4.default.join(cwd, INDEX_FILE)
4373
+ );
4374
+ if (!sourceFile) {
4375
+ warnSkipped3(
4376
+ `${INDEX_FILE} not found; register POST /trigger/telemetry and the startup notice by hand`
4377
+ );
4378
+ return;
4379
+ }
4380
+ ensureHandlerNamedImports(sourceFile, [
4381
+ "telemetryHandler",
4382
+ "telemetrySchema",
4383
+ "TELEMETRY_DISABLED_NOTICE"
4384
+ ]);
4385
+ if (!sourceFile.getText().includes("path: '/trigger/telemetry'")) {
4386
+ const lastRouteStatement = sourceFile.getDescendantsOfKind(import_ts_morph3.SyntaxKind.CallExpression).filter((call) => call.getExpression().getText() === "server.route").map(
4387
+ (call) => call.getFirstAncestorByKind(import_ts_morph3.SyntaxKind.ExpressionStatement)
4388
+ ).filter(
4389
+ (statement) => Boolean(statement)
4390
+ ).pop();
4391
+ if (!lastRouteStatement) {
4392
+ warnSkipped3(
4393
+ `Could not find a server.route(...) call in ${INDEX_FILE}; register POST /trigger/telemetry by hand`
4394
+ );
4395
+ } else {
4396
+ const indent = lastRouteStatement.getIndentationText();
4397
+ const route = [
4398
+ `server.route({`,
4399
+ ` method: 'POST',`,
4400
+ ` path: '/trigger/telemetry',`,
4401
+ ` handler: telemetryHandler,`,
4402
+ ` options: {`,
4403
+ ` tags: ['api', 'triggers'],`,
4404
+ ` validate: {`,
4405
+ ` payload: telemetrySchema`,
4406
+ ` },`,
4407
+ ` description:`,
4408
+ ` 'Receives a usage report from the events service and forwards it to the status service when telemetry is enabled'`,
4409
+ ` }`,
4410
+ `})`
4411
+ ].map((line2) => line2 ? `${indent}${line2}` : line2).join("\n");
4412
+ sourceFile.insertText(lastRouteStatement.getEnd(), `
4413
+
4414
+ ${route}`);
4415
+ console.log(` \u2713 ${INDEX_FILE}: POST /trigger/telemetry`);
4416
+ }
4417
+ }
4418
+ if (!sourceFile.getText().includes("logger.info(TELEMETRY_DISABLED_NOTICE)")) {
4419
+ const startedLog = sourceFile.getDescendantsOfKind(import_ts_morph3.SyntaxKind.ExpressionStatement).find(
4420
+ (statement) => statement.getText().includes("Server successfully started")
4421
+ );
4422
+ if (!startedLog) {
4423
+ warnSkipped3(
4424
+ `Could not find the startup log in ${INDEX_FILE}; log TELEMETRY_DISABLED_NOTICE when TELEMETRY_ENABLED is false by hand`
4425
+ );
4426
+ } else {
4427
+ const indent = startedLog.getIndentationText();
4428
+ const notice = [
4429
+ `if (!env.TELEMETRY_ENABLED) {`,
4430
+ ` logger.info(TELEMETRY_DISABLED_NOTICE)`,
4431
+ `}`
4432
+ ].map((line2) => line2 ? `${indent}${line2}` : line2).join("\n");
4433
+ sourceFile.insertText(startedLog.getEnd(), `
4434
+
4435
+ ${notice}`);
4436
+ console.log(` \u2713 ${INDEX_FILE}: telemetry-disabled startup notice`);
4437
+ if (!sourceFile.getImportDeclarations().some((d) => d.getModuleSpecifierValue() === "./environment")) {
4438
+ warnSkipped3(
4439
+ `The startup notice reads env.TELEMETRY_ENABLED but ${INDEX_FILE} does not import env from './environment'; import it by hand`
4440
+ );
4441
+ }
4442
+ }
4443
+ }
4444
+ }
4445
+ async function main4() {
4446
+ const cwd = process.cwd();
4447
+ const config = await promptTelemetryConfig();
4448
+ console.log(
4449
+ `
4450
+ Adding daily usage telemetry (${config.enabled ? `enabled for ${config.countryCode}` : "disabled"} by default)...
4451
+ `
4452
+ );
4453
+ writeTelemetryHandler(cwd);
4454
+ const project = new import_ts_morph3.Project({
4455
+ // ts-morph indents inserted code with four spaces and double-quotes strings
4456
+ // by default, both of which the country config's prettier run would undo.
4457
+ manipulationSettings: {
4458
+ indentationText: import_ts_morph3.IndentationText.TwoSpaces,
4459
+ quoteKind: import_ts_morph3.QuoteKind.Single
4460
+ }
4461
+ });
4462
+ addEnvironmentVariables(project, cwd, config);
4463
+ wireIndex(project, cwd);
4464
+ await project.save();
4465
+ if (skipped3.length > 0) {
4466
+ console.warn(
4467
+ `
4468
+ \u26A0\uFE0F ${skipped3.length} telemetry step(s) were skipped. Wire the following by hand:`
4469
+ );
4470
+ for (const message of skipped3) {
4471
+ console.warn(` - ${message}`);
4472
+ }
4473
+ }
4474
+ }
4475
+
4476
+ // src/migrations/v2.1/rename-trigger-paths.ts
4477
+ var import_ts_morph4 = require("ts-morph");
4478
+ var import_path5 = __toESM(require("path"));
4479
+ var PATH_PREFIX_RENAMES = {
4480
+ "/triggers/user/": "/trigger/user/",
4481
+ "/triggers/system/": "/trigger/system/"
4482
+ };
4483
+ var STALE_PREFIX = "/triggers/";
4484
+ var METHOD_PROPERTY_NAME = "method";
4485
+ var PATH_PROPERTY_NAME = "path";
4486
+ var HTTP_VERBS = /* @__PURE__ */ new Set([
4487
+ "GET",
4488
+ "POST",
4489
+ "PUT",
4490
+ "PATCH",
4491
+ "DELETE",
4492
+ "OPTIONS",
4493
+ "HEAD",
4494
+ "*"
4495
+ ]);
4496
+ function isRouteConfig(obj) {
4497
+ const methodProp = obj.getProperty(METHOD_PROPERTY_NAME);
4498
+ if (!methodProp || !import_ts_morph4.Node.isPropertyAssignment(methodProp)) return false;
4499
+ const methodInit = methodProp.getInitializer();
4500
+ if (!methodInit) return false;
4501
+ if (import_ts_morph4.Node.isStringLiteral(methodInit)) {
4502
+ if (!HTTP_VERBS.has(methodInit.getLiteralValue().toUpperCase()))
4503
+ return false;
4504
+ } else if (import_ts_morph4.Node.isArrayLiteralExpression(methodInit)) {
4505
+ const allVerbs = methodInit.getElements().every(
4506
+ (el) => import_ts_morph4.Node.isStringLiteral(el) && HTTP_VERBS.has(el.getLiteralValue().toUpperCase())
4507
+ );
4508
+ if (!allVerbs) return false;
4509
+ } else {
4510
+ return false;
4511
+ }
4512
+ const pathProp = obj.getProperty(PATH_PROPERTY_NAME);
4513
+ if (!pathProp || !import_ts_morph4.Node.isPropertyAssignment(pathProp)) return false;
4514
+ const pathInit = pathProp.getInitializer();
4515
+ return !!pathInit && import_ts_morph4.Node.isStringLiteral(pathInit);
4516
+ }
4517
+ function renameRoutePath(obj) {
4518
+ const pathProp = obj.getProperty(PATH_PROPERTY_NAME);
4519
+ if (!pathProp || !import_ts_morph4.Node.isPropertyAssignment(pathProp)) return null;
4520
+ const pathInit = pathProp.getInitializer();
4521
+ if (!pathInit || !import_ts_morph4.Node.isStringLiteral(pathInit)) return null;
4522
+ const oldPath = pathInit.getLiteralValue();
4523
+ const match = Object.entries(PATH_PREFIX_RENAMES).find(
4524
+ ([from2]) => oldPath.startsWith(from2)
4525
+ );
4526
+ if (!match) return null;
4527
+ const [from, to] = match;
4528
+ const newPath = to + oldPath.slice(from.length);
4529
+ pathInit.replaceWithText(`'${newPath}'`);
4530
+ return newPath;
4531
+ }
4532
+ function processFile2(filePath, project) {
4533
+ const sourceFile = project.getSourceFile(filePath);
4534
+ if (!sourceFile) return 0;
4535
+ let renamedCount = 0;
4536
+ const relPath = import_path5.default.relative(process.cwd(), filePath);
4537
+ const candidates = sourceFile.getDescendantsOfKind(
4538
+ import_ts_morph4.SyntaxKind.ObjectLiteralExpression
4539
+ );
4540
+ for (const obj of candidates) {
4541
+ if (!isRouteConfig(obj)) continue;
4542
+ const newPath = renameRoutePath(obj);
4543
+ if (newPath) {
4544
+ renamedCount++;
4545
+ console.log(` [${relPath}] Renamed route path \u2192 '${newPath}'`);
4546
+ }
4547
+ }
4548
+ return renamedCount;
4549
+ }
4550
+ function warnAboutStalePaths(sourceFiles) {
4551
+ const stale = [];
4552
+ for (const sourceFile of sourceFiles) {
4553
+ const relPath = import_path5.default.relative(process.cwd(), sourceFile.getFilePath());
4554
+ const lines = sourceFile.getFullText().split("\n");
4555
+ lines.forEach((line2, index) => {
4556
+ if (line2.includes(STALE_PREFIX)) {
4557
+ stale.push(` ${relPath}:${index + 1}: ${line2.trim()}`);
4558
+ }
4559
+ });
4560
+ }
4561
+ if (stale.length === 0) return;
4562
+ console.log(
4563
+ `
4564
+ WARNING: ${stale.length} remaining '${STALE_PREFIX}' reference(s) need to be renamed by hand:`
4565
+ );
4566
+ console.log(stale.join("\n"));
4567
+ }
4568
+ async function main5() {
4569
+ const srcDir = import_path5.default.join(process.cwd(), "src");
4570
+ console.log(`Scanning for Hapi route configs in: ${srcDir}
4571
+ `);
4572
+ console.log("Active path renames:");
4573
+ for (const [from, to] of Object.entries(PATH_PREFIX_RENAMES)) {
4574
+ console.log(` '${from}*' \u2192 '${to}*'`);
4575
+ }
4576
+ console.log();
4577
+ const project = new import_ts_morph4.Project({
4578
+ tsConfigFilePath: import_path5.default.resolve(srcDir, "../tsconfig.json"),
4579
+ skipAddingFilesFromTsConfig: false
4580
+ });
4581
+ const sourceFiles = project.getSourceFiles().filter((sf) => {
4582
+ const fp = sf.getFilePath();
4583
+ return fp.includes("/src/") && !fp.includes("/node_modules/");
4584
+ });
4585
+ console.log(`Found ${sourceFiles.length} source file(s) to analyse.
4586
+ `);
4587
+ let totalRenamed = 0;
4588
+ const modifiedFiles = [];
4589
+ for (const sourceFile of sourceFiles) {
4590
+ const filePath = sourceFile.getFilePath();
4591
+ const renamed = processFile2(filePath, project);
4592
+ if (renamed > 0) {
4593
+ totalRenamed += renamed;
4594
+ modifiedFiles.push(filePath);
4595
+ }
4596
+ }
4597
+ if (modifiedFiles.length === 0) {
4598
+ console.log("No trigger route paths to rename.");
4599
+ } else {
4600
+ console.log(`
4601
+ Saving ${modifiedFiles.length} modified file(s)...`);
4602
+ for (const filePath of modifiedFiles) {
4603
+ const sourceFile = project.getSourceFileOrThrow(filePath);
4604
+ await sourceFile.save();
4605
+ console.log(` Saved: ${import_path5.default.relative(process.cwd(), filePath)}`);
4606
+ }
4607
+ console.log(`
4608
+ Done. Renamed ${totalRenamed} route path(s).`);
4609
+ }
4610
+ warnAboutStalePaths(sourceFiles);
4611
+ }
4612
+
4037
4613
  // src/migrations/v2.1/index.ts
4038
4614
  async function runUpgrade(dockerSwarm) {
4039
4615
  await main();
4616
+ await main5();
4040
4617
  await main2();
4041
4618
  await main3();
4619
+ await main4();
4042
4620
  }
4043
4621
 
4044
4622
  // src/translations/check.ts
4045
- var import_ts_morph3 = require("ts-morph");
4046
- var import_path4 = __toESM(require("path"));
4623
+ var import_ts_morph5 = require("ts-morph");
4624
+ var import_path6 = __toESM(require("path"));
4047
4625
  var TRANSLATIONS = "src/translations";
4048
4626
  var OWN_FILE = `${TRANSLATIONS}/countryconfig.csv`;
4049
4627
  var CORE_FILES = [`${TRANSLATIONS}/client.csv`, `${TRANSLATIONS}/login.csv`];
4050
4628
  function staticStringOf(node, name) {
4051
4629
  const property = node.getProperty(name);
4052
- if (!property || !import_ts_morph3.Node.isPropertyAssignment(property)) {
4630
+ if (!property || !import_ts_morph5.Node.isPropertyAssignment(property)) {
4053
4631
  return void 0;
4054
4632
  }
4055
4633
  const initializer = property.getInitializer();
4056
- return initializer && (import_ts_morph3.Node.isStringLiteral(initializer) || import_ts_morph3.Node.isNoSubstitutionTemplateLiteral(initializer)) ? initializer.getLiteralValue() : void 0;
4634
+ return initializer && (import_ts_morph5.Node.isStringLiteral(initializer) || import_ts_morph5.Node.isNoSubstitutionTemplateLiteral(initializer)) ? initializer.getLiteralValue() : void 0;
4057
4635
  }
4058
4636
  function messagesDeclaredIn(cwd) {
4059
- const project = new import_ts_morph3.Project({ skipAddingFilesFromTsConfig: true });
4637
+ const project = new import_ts_morph5.Project({ skipAddingFilesFromTsConfig: true });
4060
4638
  project.addSourceFilesAtPaths([
4061
- import_path4.default.join(cwd, "src/**/*.ts"),
4062
- import_path4.default.join(cwd, "src/**/*.tsx"),
4063
- `!${import_path4.default.join(cwd, "src/**/*.test.ts")}`,
4064
- `!${import_path4.default.join(cwd, "src/**/*.test.tsx")}`
4639
+ import_path6.default.join(cwd, "src/**/*.ts"),
4640
+ import_path6.default.join(cwd, "src/**/*.tsx"),
4641
+ `!${import_path6.default.join(cwd, "src/**/*.test.ts")}`,
4642
+ `!${import_path6.default.join(cwd, "src/**/*.test.tsx")}`,
4643
+ `!${import_path6.default.join(cwd, "src/**/*.stories.ts")}`,
4644
+ `!${import_path6.default.join(cwd, "src/**/*.stories.tsx")}`
4065
4645
  ]);
4066
4646
  const messages = [];
4067
4647
  const dynamicIds = [];
4068
4648
  for (const sourceFile of project.getSourceFiles()) {
4069
4649
  sourceFile.forEachDescendant((node) => {
4070
- if (!import_ts_morph3.Node.isObjectLiteralExpression(node)) {
4650
+ if (!import_ts_morph5.Node.isObjectLiteralExpression(node)) {
4071
4651
  return;
4072
4652
  }
4073
4653
  if (!(node.getProperty("id") && node.getProperty("defaultMessage"))) {
@@ -4075,7 +4655,7 @@ function messagesDeclaredIn(cwd) {
4075
4655
  }
4076
4656
  const id = staticStringOf(node, "id");
4077
4657
  if (id === void 0) {
4078
- dynamicIds.push(import_path4.default.relative(cwd, sourceFile.getFilePath()));
4658
+ dynamicIds.push(import_path6.default.relative(cwd, sourceFile.getFilePath()));
4079
4659
  return;
4080
4660
  }
4081
4661
  messages.push({
@@ -4089,9 +4669,9 @@ function messagesDeclaredIn(cwd) {
4089
4669
  }
4090
4670
  function check(cwd) {
4091
4671
  const { messages, dynamicIds } = messagesDeclaredIn(cwd);
4092
- const own = readCsvFile(import_path4.default.join(cwd, OWN_FILE));
4672
+ const own = readCsvFile(import_path6.default.join(cwd, OWN_FILE));
4093
4673
  const covered = new Set(
4094
- [own, ...CORE_FILES.map((file) => readCsvFile(import_path4.default.join(cwd, file)))].flatMap((csv) => csv?.body ?? []).map((line) => line.slice(0, line.indexOf(",")))
4674
+ [own, ...CORE_FILES.map((file) => readCsvFile(import_path6.default.join(cwd, file)))].flatMap((csv) => csv?.body ?? []).map(idOf)
4095
4675
  );
4096
4676
  const missing = [
4097
4677
  ...new Map(
@@ -4099,14 +4679,16 @@ function check(cwd) {
4099
4679
  ).values()
4100
4680
  ].sort((a, b) => a.id < b.id ? -1 : 1);
4101
4681
  const declared = new Set(messages.map(({ id }) => id));
4102
- const outdated = (own?.body ?? []).map((line) => line.slice(0, line.indexOf(","))).filter((id) => !declared.has(id));
4682
+ const outdated = (own?.body ?? []).map(idOf).filter((id) => !declared.has(id));
4103
4683
  return { missing, outdated, dynamicIds };
4104
4684
  }
4105
4685
  function writeMissing(cwd, missing) {
4106
- const file = readCsvFile(import_path4.default.join(cwd, OWN_FILE));
4107
- if (!file) {
4108
- throw new Error(`${OWN_FILE} not found in ${cwd}`);
4109
- }
4686
+ const file = readCsvFile(import_path6.default.join(cwd, OWN_FILE)) ?? {
4687
+ header: "id,description,en",
4688
+ body: [],
4689
+ newline: "\n",
4690
+ trailingNewline: true
4691
+ };
4110
4692
  const columns = file.header.split(",");
4111
4693
  const rows = missing.map(
4112
4694
  (message) => toCsvLine(
@@ -4118,13 +4700,13 @@ function writeMissing(cwd, missing) {
4118
4700
  )
4119
4701
  );
4120
4702
  const added = addRows(file, rows);
4121
- writeCsvFile(import_path4.default.join(cwd, OWN_FILE), file);
4703
+ writeCsvFile(import_path6.default.join(cwd, OWN_FILE), file);
4122
4704
  return added;
4123
4705
  }
4124
4706
 
4125
4707
  // src/environment/index.ts
4126
- var import_fs7 = require("fs");
4127
- var import_path9 = require("path");
4708
+ var import_fs8 = require("fs");
4709
+ var import_path11 = require("path");
4128
4710
  init_paths();
4129
4711
  var REQUIRED_REPOSITORY_DIRECTORIES = [
4130
4712
  ".github/workflows",
@@ -4135,7 +4717,7 @@ function validateRepositoryStructure(repositoryRoot = process.cwd()) {
4135
4717
  const missingDirectories = REQUIRED_REPOSITORY_DIRECTORIES.filter(
4136
4718
  (directory) => {
4137
4719
  try {
4138
- return !(0, import_fs7.statSync)((0, import_path9.resolve)(repositoryRoot, directory)).isDirectory();
4720
+ return !(0, import_fs8.statSync)((0, import_path11.resolve)(repositoryRoot, directory)).isDirectory();
4139
4721
  } catch {
4140
4722
  return true;
4141
4723
  }
@@ -4172,6 +4754,278 @@ async function runEnvironmentSwarmToK8s() {
4172
4754
  await Promise.resolve().then(() => (init_swarm_to_k8s(), swarm_to_k8s_exports));
4173
4755
  }
4174
4756
 
4757
+ // src/verify/endpoints.ts
4758
+ var import_colors = require("kleur/colors");
4759
+ var REQUEST_TIMEOUT_MS = 15e3;
4760
+ var DEFAULT_TARGET_URL = "http://localhost:3040";
4761
+ var REQUIRED_PUBLIC_ENDPOINTS = [
4762
+ { method: "GET", path: "/client-config.js" },
4763
+ { method: "GET", path: "/login-config.js" },
4764
+ { method: "GET", path: "/handlebars.js" },
4765
+ { method: "GET", path: "/content/client" },
4766
+ { method: "GET", path: "/content/login" },
4767
+ { method: "GET", path: "/content/map.geojson" },
4768
+ { method: "GET", path: "/content/country-logo" },
4769
+ { method: "GET", path: "/config/application" },
4770
+ { method: "GET", path: "/config/workqueues" },
4771
+ { method: "GET", path: "/config/locations" },
4772
+ { method: "GET", path: "/config/roles" },
4773
+ { method: "GET", path: "/config/events" }
4774
+ ];
4775
+ var PROBE_SEGMENT = "verify-endpoints-probe";
4776
+ var SECURED_TRIGGER_USER_EVENTS = [
4777
+ "user-created",
4778
+ "user-updated",
4779
+ "username-reminder",
4780
+ "reset-password",
4781
+ "reset-password-by-admin",
4782
+ "password-reset-link",
4783
+ "username-reminder-link",
4784
+ "resend-invite",
4785
+ "2fa",
4786
+ "all-user-notification",
4787
+ "change-phone-number",
4788
+ "change-email-address"
4789
+ ];
4790
+ var SECURED_ENDPOINTS = [
4791
+ ...SECURED_TRIGGER_USER_EVENTS.map(
4792
+ (event) => ({
4793
+ method: "POST",
4794
+ path: `/trigger/user/${event}`
4795
+ })
4796
+ ),
4797
+ { method: "POST", path: "/trigger/telemetry" },
4798
+ { method: "GET", path: "/trigger/system/ready" },
4799
+ {
4800
+ method: "GET",
4801
+ path: `/certificates/${PROBE_SEGMENT}`,
4802
+ label: "/certificates/{id}"
4803
+ },
4804
+ { method: "GET", path: "/certificates" },
4805
+ { method: "GET", path: "/config/users" }
4806
+ ];
4807
+ var FALLBACK_EVENT_TRIGGERS = [
4808
+ {
4809
+ method: "POST",
4810
+ path: `/trigger/events/${PROBE_SEGMENT}/actions/${PROBE_SEGMENT}`,
4811
+ label: "/trigger/events/{event}/actions/{action}"
4812
+ },
4813
+ {
4814
+ method: "POST",
4815
+ path: `/trigger/events/birth/actions/${PROBE_SEGMENT}`,
4816
+ label: "/trigger/events/birth/actions/{action}"
4817
+ },
4818
+ {
4819
+ method: "POST",
4820
+ path: `/trigger/events/death/actions/${PROBE_SEGMENT}`,
4821
+ label: "/trigger/events/death/actions/{action}"
4822
+ }
4823
+ ];
4824
+ var isSuccess = (status) => status !== "error" && status >= 200 && status < 300;
4825
+ var requiresAuthOrAbsent = (status) => status === 401 || status === 403 || status === 404;
4826
+ async function requestStatus(url, method) {
4827
+ const controller = new AbortController();
4828
+ const timer = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
4829
+ try {
4830
+ const response = await fetch(url, {
4831
+ method,
4832
+ signal: controller.signal,
4833
+ // Sent without an Authorization header on purpose. A secured route
4834
+ // rejects with 401/403 before ever reading the body.
4835
+ headers: method === "POST" ? { "Content-Type": "application/json" } : void 0,
4836
+ body: method === "POST" ? "{}" : void 0
4837
+ });
4838
+ return response.status;
4839
+ } catch {
4840
+ return "error";
4841
+ } finally {
4842
+ clearTimeout(timer);
4843
+ }
4844
+ }
4845
+ function toEventTriggerConfig(value) {
4846
+ if (typeof value !== "object" || value === null) {
4847
+ return null;
4848
+ }
4849
+ const record = value;
4850
+ if (typeof record.id !== "string") {
4851
+ return null;
4852
+ }
4853
+ const actions = Array.isArray(record.actions) ? Array.from(
4854
+ new Set(
4855
+ record.actions.map((action) => {
4856
+ if (typeof action !== "object" || action === null) {
4857
+ return null;
4858
+ }
4859
+ const type = action.type;
4860
+ return typeof type === "string" ? type : null;
4861
+ }).filter((type) => type !== null)
4862
+ )
4863
+ ) : [];
4864
+ return { id: record.id, actions };
4865
+ }
4866
+ async function fetchEventConfigs(baseUrl) {
4867
+ const controller = new AbortController();
4868
+ const timer = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
4869
+ try {
4870
+ const response = await fetch(`${baseUrl}/config/events`, {
4871
+ signal: controller.signal
4872
+ });
4873
+ if (!response.ok) {
4874
+ return null;
4875
+ }
4876
+ const body = await response.json();
4877
+ if (!Array.isArray(body)) {
4878
+ return null;
4879
+ }
4880
+ return body.map(toEventTriggerConfig).filter((config) => config !== null);
4881
+ } catch {
4882
+ return null;
4883
+ } finally {
4884
+ clearTimeout(timer);
4885
+ }
4886
+ }
4887
+ function resolveBaseUrl(input4) {
4888
+ const withProtocol = /^https?:\/\//i.test(input4) ? input4 : `https://${input4}`;
4889
+ return withProtocol.replace(/\/+$/, "");
4890
+ }
4891
+ function describeStatus(status) {
4892
+ return status === "error" ? "no response" : `HTTP ${status}`;
4893
+ }
4894
+ function endpointLabel(check2) {
4895
+ const shown = check2.label ?? check2.path;
4896
+ const suffix = check2.label ? (0, import_colors.dim)(` \u2192 ${check2.path}`) : "";
4897
+ return `${check2.method} ${shown}${suffix}`;
4898
+ }
4899
+ function line(ok, label, detail) {
4900
+ const mark = ok ? (0, import_colors.green)("\u2713") : (0, import_colors.red)("\u2717");
4901
+ return ` ${mark} ${label} ${(0, import_colors.dim)(`(${detail})`)}`;
4902
+ }
4903
+ function securedDetail(status) {
4904
+ if (status === 401 || status === 403) {
4905
+ return `${describeStatus(status)} \u2014 auth required`;
4906
+ }
4907
+ if (status === 404) {
4908
+ return `${describeStatus(status)} \u2014 not implemented`;
4909
+ }
4910
+ if (status === "error") {
4911
+ return `${describeStatus(status)} \u2014 request failed`;
4912
+ }
4913
+ return `${describeStatus(status)} \u2014 INSECURE: ensure this endpoint requires authentication!`;
4914
+ }
4915
+ async function runVerifyEndpoints(target = DEFAULT_TARGET_URL) {
4916
+ const baseUrl = resolveBaseUrl(target);
4917
+ console.log((0, import_colors.bold)(`Verifying country config endpoints at ${baseUrl}
4918
+ `));
4919
+ let failures = 0;
4920
+ console.log((0, import_colors.bold)("Required public endpoints (must respond 2xx):"));
4921
+ for (const check2 of REQUIRED_PUBLIC_ENDPOINTS) {
4922
+ const status = await requestStatus(`${baseUrl}${check2.path}`, check2.method);
4923
+ const ok = isSuccess(status);
4924
+ if (!ok) {
4925
+ failures++;
4926
+ }
4927
+ const detail = status === 404 ? `${describeStatus(status)} \u2014 missing` : ok ? describeStatus(status) : `${describeStatus(status)} \u2014 unexpected`;
4928
+ console.log(line(ok, endpointLabel(check2), detail));
4929
+ }
4930
+ {
4931
+ const path11 = `/fonts/${PROBE_SEGMENT}.ttf`;
4932
+ const status = await requestStatus(`${baseUrl}${path11}`, "GET");
4933
+ const ok = status === 200 || status === 404;
4934
+ if (!ok) {
4935
+ failures++;
4936
+ }
4937
+ let detail;
4938
+ if (status === 404) {
4939
+ detail = `${describeStatus(status)} \u2014 reachable (made-up filename)`;
4940
+ } else if (status === 200) {
4941
+ detail = describeStatus(status);
4942
+ } else if (status === 401 || status === 403) {
4943
+ detail = `${describeStatus(status)} \u2014 must be public`;
4944
+ } else {
4945
+ detail = `${describeStatus(status)} \u2014 unexpected`;
4946
+ }
4947
+ console.log(line(ok, `GET /fonts/{filename}${(0, import_colors.dim)(` \u2192 ${path11}`)}`, detail));
4948
+ }
4949
+ console.log();
4950
+ console.log((0, import_colors.bold)("Secured endpoints (must be absent or require auth):"));
4951
+ for (const check2 of SECURED_ENDPOINTS) {
4952
+ const status = await requestStatus(`${baseUrl}${check2.path}`, check2.method);
4953
+ const ok = requiresAuthOrAbsent(status);
4954
+ if (!ok) {
4955
+ failures++;
4956
+ }
4957
+ console.log(line(ok, endpointLabel(check2), securedDetail(status)));
4958
+ }
4959
+ console.log();
4960
+ console.log((0, import_colors.bold)("Event action triggers (must be absent or require auth):"));
4961
+ const events = await fetchEventConfigs(baseUrl);
4962
+ if (!events) {
4963
+ console.log(
4964
+ " " + (0, import_colors.yellow)(
4965
+ "Could not read /config/events; falling back to route-pattern checks."
4966
+ )
4967
+ );
4968
+ for (const check2 of FALLBACK_EVENT_TRIGGERS) {
4969
+ const status = await requestStatus(
4970
+ `${baseUrl}${check2.path}`,
4971
+ check2.method
4972
+ );
4973
+ const ok = requiresAuthOrAbsent(status);
4974
+ if (!ok) {
4975
+ failures++;
4976
+ }
4977
+ console.log(line(ok, endpointLabel(check2), securedDetail(status)));
4978
+ }
4979
+ } else if (events.length === 0) {
4980
+ console.log(" " + (0, import_colors.yellow)("No events configured."));
4981
+ } else {
4982
+ for (const event of events) {
4983
+ const actions = event.actions.length ? event.actions : [PROBE_SEGMENT];
4984
+ const failed = [];
4985
+ for (const action of actions) {
4986
+ const status = await requestStatus(
4987
+ `${baseUrl}/trigger/events/${event.id}/actions/${action}`,
4988
+ "POST"
4989
+ );
4990
+ if (!requiresAuthOrAbsent(status)) {
4991
+ failed.push({ action, status });
4992
+ }
4993
+ }
4994
+ const pattern = `POST /trigger/events/${event.id}/actions/{action}`;
4995
+ if (failed.length === 0) {
4996
+ console.log(
4997
+ line(true, pattern, `${actions.length} action(s) \u2014 all require auth`)
4998
+ );
4999
+ } else {
5000
+ for (const failure of failed) {
5001
+ failures++;
5002
+ console.log(
5003
+ line(
5004
+ false,
5005
+ `POST /trigger/events/${event.id}/actions/${failure.action}`,
5006
+ securedDetail(failure.status)
5007
+ )
5008
+ );
5009
+ }
5010
+ const okCount = actions.length - failed.length;
5011
+ if (okCount > 0) {
5012
+ console.log(
5013
+ line(true, pattern, `${okCount} other action(s) require auth`)
5014
+ );
5015
+ }
5016
+ }
5017
+ }
5018
+ }
5019
+ console.log();
5020
+ if (failures > 0) {
5021
+ console.log(
5022
+ (0, import_colors.red)((0, import_colors.bold)(`\u2717 ${failures} check(s) failed.`)) + (0, import_colors.yellow)(" See the lines marked \u2717 above.")
5023
+ );
5024
+ process.exit(1);
5025
+ }
5026
+ console.log((0, import_colors.green)((0, import_colors.bold)("\u2713 All endpoint checks passed.")));
5027
+ }
5028
+
4175
5029
  // src/cli.ts
4176
5030
  var args = process.argv.slice(2);
4177
5031
  var USAGE = `
@@ -4181,9 +5035,31 @@ Commands:
4181
5035
  environment Manage deployment environments
4182
5036
  upgrade Upgrade an existing environment
4183
5037
  check-translations Check translation files for completeness
5038
+ verify-endpoints Verify the locally-running country config exposes the
5039
+ expected endpoints and keeps secured ones locked down
4184
5040
 
4185
5041
  Run 'opencrvs <command> --help' for more information on a command.
4186
5042
  `.trim();
5043
+ var VERIFY_ENDPOINTS_USAGE = `
5044
+ Usage: opencrvs verify-endpoints [country-config-url]
5045
+
5046
+ Run this after 'opencrvs upgrade', with the upgraded country config running
5047
+ locally, to confirm it still behaves correctly. It checks over HTTP that:
5048
+ - required public endpoints exist (respond 2xx), and
5049
+ - user-notification trigger endpoints are either absent or reject
5050
+ unauthenticated requests (never processed without a token).
5051
+
5052
+ Arguments:
5053
+ [country-config-url] Optional. Domain or URL of the country config
5054
+ service. Defaults to 'http://localhost:3040', the
5055
+ port country config listens on locally. A bare
5056
+ domain is assumed to use https.
5057
+
5058
+ Options:
5059
+ -h, --help Show this message.
5060
+
5061
+ Exits with a non-zero status if any check fails.
5062
+ `.trim();
4187
5063
  var UPGRADE_USAGE = `
4188
5064
  Usage: opencrvs upgrade [options]
4189
5065
 
@@ -4197,7 +5073,7 @@ Options:
4197
5073
  'infrastructure/' directory is deleted (default).
4198
5074
  -h, --help Show this message.
4199
5075
  `.trim();
4200
- function main4() {
5076
+ function main6() {
4201
5077
  const command = args[0];
4202
5078
  if (!command || command === "--help" || command === "-h") {
4203
5079
  console.log(USAGE);
@@ -4210,6 +5086,8 @@ function main4() {
4210
5086
  return handleUpgrade();
4211
5087
  case "check-translations":
4212
5088
  return handleCheckTranslations();
5089
+ case "verify-endpoints":
5090
+ return handleVerifyEndpoints();
4213
5091
  default:
4214
5092
  console.error(`Unknown command: ${command}
4215
5093
  `);
@@ -4311,7 +5189,7 @@ function handleCheckTranslations() {
4311
5189
  return;
4312
5190
  }
4313
5191
  const unknownFlags = checkArgs.filter(
4314
- (arg) => !["--write", "--outdated"].includes(arg)
5192
+ (arg) => arg.startsWith("-") && !["--write", "--outdated"].includes(arg)
4315
5193
  );
4316
5194
  if (unknownFlags.length > 0) {
4317
5195
  console.error(`Unknown option: ${unknownFlags.join(", ")}
@@ -4345,7 +5223,7 @@ function handleCheckTranslations() {
4345
5223
  console.error(missing.map(({ id }) => ` ${id}`).join("\n"));
4346
5224
  if (!checkArgs.includes("--write")) {
4347
5225
  console.error(
4348
- "\nRun `opencrvs check-translations --write` to add them with their English copy."
5226
+ "\nRun `pnpm extract:translations --write` to add them with their English copy."
4349
5227
  );
4350
5228
  process.exit(1);
4351
5229
  }
@@ -4354,4 +5232,29 @@ function handleCheckTranslations() {
4354
5232
  Added ${added.length} row(s) to countryconfig.csv.`);
4355
5233
  console.log("The languages other than English are still yours to write.");
4356
5234
  }
4357
- main4();
5235
+ async function handleVerifyEndpoints() {
5236
+ const verifyArgs = args.slice(1);
5237
+ if (verifyArgs.includes("--help") || verifyArgs.includes("-h")) {
5238
+ console.log(VERIFY_ENDPOINTS_USAGE);
5239
+ process.exit(0);
5240
+ }
5241
+ const positional = verifyArgs.filter((arg) => !arg.startsWith("-"));
5242
+ if (positional.length > 1) {
5243
+ console.error(
5244
+ `Unexpected extra argument(s): ${positional.slice(1).join(", ")}
5245
+ `
5246
+ );
5247
+ console.log(VERIFY_ENDPOINTS_USAGE);
5248
+ process.exit(1);
5249
+ }
5250
+ try {
5251
+ await runVerifyEndpoints(positional[0]);
5252
+ } catch (error3) {
5253
+ console.error(
5254
+ "Endpoint verification failed:",
5255
+ error3 instanceof Error ? error3.message : error3
5256
+ );
5257
+ process.exit(1);
5258
+ }
5259
+ }
5260
+ main6();