@opencrvs/toolkit 2.1.0-rc.ecb508d → 2.1.0-rc.f29a266

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 (69) hide show
  1. package/README.md +1 -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 +254 -197
  6. package/dist/cli.js +195 -73
  7. package/dist/commons/api/router.d.ts +672 -57
  8. package/dist/commons/conditionals/conditionals.d.ts +6 -6
  9. package/dist/commons/conditionals/validate.d.ts +16 -5
  10. package/dist/commons/events/ActionDocument.d.ts +5 -11
  11. package/dist/commons/events/ActionInput.d.ts +4 -4
  12. package/dist/commons/events/ActionStatus.d.ts +14 -0
  13. package/dist/commons/events/AdvancedSearchConfig.d.ts +18 -0
  14. package/dist/commons/events/AuditLog.d.ts +147 -0
  15. package/dist/commons/events/EventConfig.d.ts +3 -0
  16. package/dist/commons/events/EventDocument.d.ts +2 -2
  17. package/dist/commons/events/EventIndex.d.ts +3 -26
  18. package/dist/commons/events/FieldConfig.d.ts +83 -53
  19. package/dist/commons/events/FieldTypeMapping.d.ts +19 -19
  20. package/dist/commons/events/FieldValue.d.ts +2 -2
  21. package/dist/commons/events/Flag.d.ts +42 -0
  22. package/dist/commons/events/PlainDate.d.ts +8 -0
  23. package/dist/commons/events/SummaryConfig.d.ts +249 -0
  24. package/dist/commons/events/WorkqueueConfig.d.ts +17 -14
  25. package/dist/commons/events/event.d.ts +12 -0
  26. package/dist/commons/events/index.d.ts +1 -0
  27. package/dist/commons/events/locationPayloads.d.ts +95 -0
  28. package/dist/commons/events/locations.d.ts +163 -24
  29. package/dist/commons/events/mocks.test.utils.d.ts +30 -0
  30. package/dist/commons/events/test.utils.d.ts +8 -4
  31. package/dist/commons/events/utils.d.ts +2 -2
  32. package/dist/commons/notification/UserNotifications.d.ts +28 -0
  33. package/dist/conditionals/index.js +308 -55
  34. package/dist/environment/index.d.ts +1 -0
  35. package/dist/environment/index.d.ts.map +1 -1
  36. package/dist/environment/index.js +10 -0
  37. package/dist/environment/logger.d.ts +12 -3
  38. package/dist/environment/logger.d.ts.map +1 -1
  39. package/dist/environment/paths.d.ts +7 -0
  40. package/dist/environment/paths.d.ts.map +1 -0
  41. package/dist/environment/paths.js +72 -0
  42. package/dist/environment/questions.d.ts.map +1 -1
  43. package/dist/environment/questions.js +20 -14
  44. package/dist/environment/setup-environment.js +3 -2
  45. package/dist/environment/templates.d.ts.map +1 -1
  46. package/dist/environment/templates.js +2 -1
  47. package/dist/environment/update-workflows.d.ts.map +1 -1
  48. package/dist/environment/update-workflows.js +17 -5
  49. package/dist/environment/upgrade.d.ts +2 -0
  50. package/dist/environment/upgrade.d.ts.map +1 -0
  51. package/dist/environment/upgrade.js +82 -0
  52. package/dist/environment/users.js +11 -13
  53. package/dist/events/index.js +3621 -3243
  54. package/dist/migrations/v2.0/checkout-upstream-files.d.ts +2 -2
  55. package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +1 -1
  56. package/dist/migrations/v2.0/checkout-upstream-files.js +2 -2
  57. package/dist/notification/index.js +1400 -1033
  58. package/dist/scopes/index.d.ts +253 -26
  59. package/dist/scopes/index.js +309 -55
  60. package/dist/templates/charts-values/opencrvs-services/values.yaml +4 -3
  61. package/dist/templates/charts-values/opentelemetry/values.yaml +95 -0
  62. package/dist/templates/charts-values/traefik/values.yaml +23 -9
  63. package/dist/templates/inventory/inventory.template.yml +1 -3
  64. package/opencrvs-toolkit-2.1.0-rc.f29a266.tgz +0 -0
  65. package/package.json +5 -5
  66. package/tsconfig.tsbuildinfo +1 -1
  67. package/dist/templates/inventory/production.example.yml +0 -77
  68. package/dist/templates/inventory/qa.example.yml +0 -48
  69. package/opencrvs-toolkit-2.1.0-rc.ecb508d.tgz +0 -0
package/dist/cli.js CHANGED
@@ -30,6 +30,42 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
30
30
  mod
31
31
  ));
32
32
 
33
+ // src/environment/paths.ts
34
+ function getEnvironmentInventoryPath(environment) {
35
+ return (0, import_path2.join)("environments", environment, INVENTORY_FILE_NAME);
36
+ }
37
+ function findOldInventoryFiles() {
38
+ return glob.sync((0, import_path2.join)(OLD_INVENTORY_DIR, "*.yml")).sort();
39
+ }
40
+ function getEnvironmentNameFromOldInventoryPath(filePath) {
41
+ return (0, import_path2.basename)(filePath, ".yml");
42
+ }
43
+ function assertNoOldInventoryLayout() {
44
+ if (findOldInventoryFiles().length === 0) {
45
+ return;
46
+ }
47
+ throw new Error(
48
+ [
49
+ `Old inventory layout detected at ${OLD_INVENTORY_DIR}.`,
50
+ "Please run `yarn environment:upgrade` before running `yarn environment:init`."
51
+ ].join(" ")
52
+ );
53
+ }
54
+ var import_path2, glob, OLD_INVENTORY_DIR, INVENTORY_FILE_NAME;
55
+ var init_paths = __esm({
56
+ "src/environment/paths.ts"() {
57
+ "use strict";
58
+ import_path2 = require("path");
59
+ glob = __toESM(require("glob"));
60
+ OLD_INVENTORY_DIR = (0, import_path2.join)(
61
+ "infrastructure",
62
+ "server-setup",
63
+ "inventory"
64
+ );
65
+ INVENTORY_FILE_NAME = "inventory.yml";
66
+ }
67
+ });
68
+
33
69
  // src/environment/logger.ts
34
70
  var import_kleur, log, warn, success, info, error;
35
71
  var init_logger = __esm({
@@ -473,7 +509,7 @@ function storeSecrets(environment, answers) {
473
509
  envConfig = import_dotenv.default.parse(
474
510
  (0, import_fs.readFileSync)(`${process.cwd()}/.env.${environment}`)
475
511
  );
476
- } catch (error4) {
512
+ } catch (error3) {
477
513
  envConfig = {};
478
514
  }
479
515
  const linesFromAnswers = answers.map(
@@ -498,8 +534,8 @@ function writeYamlFile(filePath, data) {
498
534
  sortKeys: false
499
535
  });
500
536
  import_fs.default.writeFileSync(filePath, yamlContent, "utf8");
501
- } catch (error4) {
502
- throw new Error(`Failed to write inventory file: ${error4}`);
537
+ } catch (error3) {
538
+ throw new Error(`Failed to write inventory file: ${error3}`);
503
539
  }
504
540
  }
505
541
  var import_fs, yaml, import_dotenv;
@@ -559,8 +595,8 @@ function extractWorkerNodes(data) {
559
595
  return worker_hosts;
560
596
  }
561
597
  function copyChartsValues(env, values) {
562
- const srcDir = import_path2.default.resolve(__dirname, "templates", "charts-values");
563
- const destDir = import_path2.default.resolve(process.cwd(), "environments", env);
598
+ const srcDir = import_path3.default.resolve(__dirname, "templates", "charts-values");
599
+ const destDir = import_path3.default.resolve(process.cwd(), "environments", env);
564
600
  import_fs2.default.mkdirSync(destDir, { recursive: true });
565
601
  values["lets_encrypt"] = values["traefik_mode"] === "lets_encrypt";
566
602
  values["static_ssl"] = values["traefik_mode"] === "static_ssl";
@@ -570,7 +606,7 @@ function copyChartsValues(env, values) {
570
606
  if (stat.isDirectory()) {
571
607
  import_fs2.default.mkdirSync(dest, { recursive: true });
572
608
  for (const item of import_fs2.default.readdirSync(src)) {
573
- copyRecursive(import_path2.default.join(src, item), import_path2.default.join(dest, item));
609
+ copyRecursive(import_path3.default.join(src, item), import_path3.default.join(dest, item));
574
610
  }
575
611
  } else {
576
612
  const content = import_fs2.default.readFileSync(src, "utf8");
@@ -592,36 +628,31 @@ function copyChartsValues(env, values) {
592
628
  `);
593
629
  }
594
630
  function generateInventory(env, values) {
595
- const templatePath = import_path2.default.join(
631
+ const templatePath = import_path3.default.join(
596
632
  __dirname,
597
633
  "templates",
598
634
  "inventory",
599
635
  "inventory.template.yml"
600
636
  );
601
- const outputPath = import_path2.default.join(
602
- process.cwd(),
603
- "infrastructure",
604
- "server-setup",
605
- "inventory",
606
- `${env}.yml`
607
- );
637
+ const outputPath = import_path3.default.resolve(process.cwd(), getEnvironmentInventoryPath(env));
608
638
  const templateFile = import_fs2.default.readFileSync(templatePath, "utf-8");
609
639
  const template = import_handlebars.default.compile(templateFile);
610
640
  values["single_node"] = values["kube_worker_nodes"].length > 0 || values["backup_host"] ? "false" : "true";
611
641
  const updated = template(values);
612
- import_fs2.default.mkdirSync(import_path2.default.dirname(outputPath), { recursive: true });
642
+ import_fs2.default.mkdirSync(import_path3.default.dirname(outputPath), { recursive: true });
613
643
  import_fs2.default.writeFileSync(outputPath, updated);
614
644
  log(`
615
645
  \u2705 Generated inventory file at ${outputPath}
616
646
  `);
617
647
  }
618
- var import_fs2, import_path2, import_handlebars;
648
+ var import_fs2, import_path3, import_handlebars;
619
649
  var init_templates = __esm({
620
650
  "src/environment/templates.ts"() {
621
651
  "use strict";
622
652
  import_fs2 = __toESM(require("fs"));
623
- import_path2 = __toESM(require("path"));
653
+ import_path3 = __toESM(require("path"));
624
654
  init_logger();
655
+ init_paths();
625
656
  import_handlebars = __toESM(require("handlebars"));
626
657
  import_handlebars.default.registerHelper("data_label_idx", function(value) {
627
658
  return parseInt(value) + 2;
@@ -829,11 +860,28 @@ var init_questions = __esm({
829
860
  scope: "ENVIRONMENT"
830
861
  },
831
862
  {
832
- name: "kubeAPIHost",
863
+ name: "kubeMasterNode",
864
+ type: "text",
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",
833
882
  type: "text",
834
- message: `Kubernetes API endpoint (default: auto-detect)`,
883
+ message: `Kubernetes API endpoint IP (default: KUBE_MASTER_NODE)`,
835
884
  valueType: "VARIABLE",
836
- // validate: notEmpty,
837
885
  valueLabel: "KUBE_API_HOST",
838
886
  initial: process.env.KUBE_API_HOST,
839
887
  scope: "ENVIRONMENT"
@@ -847,16 +895,6 @@ var init_questions = __esm({
847
895
  valueLabel: "KUBE_API_ALLOWED_CIDRS",
848
896
  initial: process.env.KUBE_API_ALLOWED_CIDRS || "",
849
897
  scope: "ENVIRONMENT"
850
- },
851
- {
852
- name: "kubeWorkerNodes",
853
- type: "text",
854
- message: `Kubernetes worker node hostnames or IPs (comma-separated, default: no worker nodes)`,
855
- valueType: "VARIABLE",
856
- // validate: notEmpty,
857
- valueLabel: "KUBE_WORKER_NODES",
858
- initial: process.env.KUBE_WORKER_NODES || "",
859
- scope: "ENVIRONMENT"
860
898
  }
861
899
  ];
862
900
  staticSSLCertQuestions = [
@@ -887,7 +925,6 @@ var init_questions = __esm({
887
925
  type: "text",
888
926
  message: `Please enter backup server host/IP address, (default: no backup):`,
889
927
  valueType: "VARIABLE",
890
- // validate: notEmpty,
891
928
  valueLabel: "BACKUP_HOST",
892
929
  initial: process.env.BACKUP_HOST || "",
893
930
  scope: "ENVIRONMENT"
@@ -1237,7 +1274,7 @@ function getCurrentUserSSHKeys() {
1237
1274
  keys.push(keyContent);
1238
1275
  }
1239
1276
  }
1240
- } catch (error4) {
1277
+ } catch (error3) {
1241
1278
  continue;
1242
1279
  }
1243
1280
  }
@@ -1773,6 +1810,7 @@ var init_setup_environment = __esm({
1773
1810
  init_editor_questions();
1774
1811
  init_questions_helper();
1775
1812
  init_manage_users();
1813
+ init_paths();
1776
1814
  ALL_QUESTIONS = [];
1777
1815
  ALL_ANSWERS = [];
1778
1816
  ALL_QUESTIONS.push(
@@ -1936,9 +1974,7 @@ var init_setup_environment = __esm({
1936
1974
  );
1937
1975
  const kubeWorkerNodes = infrastructure.kubeWorkerNodes ? infrastructure.kubeWorkerNodes.split(",").map((ip) => ip.trim()) : [];
1938
1976
  log("\n", import_kleur4.default.bold().underline("SSH Users"), "\n");
1939
- const users = await manageUsers(
1940
- `infrastructure/server-setup/inventory/${environment}.yml`
1941
- );
1977
+ const users = await manageUsers(getEnvironmentInventoryPath(environment));
1942
1978
  log("\n", import_kleur4.default.bold().underline("Traefik SSL Certificate"), "\n");
1943
1979
  const sslCertExists = findExistingValue(
1944
1980
  "SSL_CRT",
@@ -2690,7 +2726,7 @@ var init_setup_environment = __esm({
2690
2726
  log("\n", import_kleur4.default.bold().underline("Running configuration files updates"));
2691
2727
  generateInventory(environment, {
2692
2728
  kube_worker_nodes: kubeWorkerNodes,
2693
- kube_api_host: infrastructure.kubeAPIHost || "",
2729
+ kube_api_host: infrastructure.kubeApiHost || "",
2694
2730
  backup_host: backupHost || "",
2695
2731
  users
2696
2732
  });
@@ -2751,12 +2787,19 @@ var update_workflows_exports = {};
2751
2787
  __export(update_workflows_exports, {
2752
2788
  updateWorkflowEnvironments: () => updateWorkflowEnvironments
2753
2789
  });
2790
+ function isDirectory(path6) {
2791
+ try {
2792
+ return (0, import_fs3.statSync)(path6).isDirectory();
2793
+ } catch {
2794
+ return false;
2795
+ }
2796
+ }
2754
2797
  async function extractInfrastructureNames() {
2755
- const files = glob.sync("infrastructure/server-setup/inventory/*.yml");
2756
- const infraEnvironments = files.map((file) => (0, import_path3.basename)(file, ".yml"));
2798
+ const files = glob2.sync((0, import_path4.join)("environments", "*", INVENTORY_FILE_NAME));
2799
+ const infraEnvironments = files.map((file) => (0, import_path4.basename)((0, import_path4.dirname)(file)));
2757
2800
  if (infraEnvironments.length === 0) {
2758
2801
  console.log(
2759
- "\u26A0\uFE0F Warning: No environment directories found in infrastructure/server-setup/inventory/"
2802
+ `\u26A0\uFE0F Warning: No environment inventory files found at environments/*/${INVENTORY_FILE_NAME}`
2760
2803
  );
2761
2804
  return [];
2762
2805
  }
@@ -2766,8 +2809,9 @@ async function extractInfrastructureNames() {
2766
2809
  async function extractEnvironmentNames() {
2767
2810
  const entries = await (0, import_promises.readdir)("environments");
2768
2811
  const environments = entries.filter((entry) => {
2769
- const fullPath = (0, import_path3.join)("environments", entry);
2770
- return (0, import_fs3.statSync)(fullPath).isDirectory();
2812
+ const environmentPath = (0, import_path4.join)("environments", entry);
2813
+ const opencrvsServicesPath = (0, import_path4.join)(environmentPath, "opencrvs-services");
2814
+ return isDirectory(environmentPath) && (0, import_fs3.existsSync)(opencrvsServicesPath) && isDirectory(opencrvsServicesPath);
2771
2815
  });
2772
2816
  if (environments.length === 0) {
2773
2817
  console.log(
@@ -2803,13 +2847,13 @@ async function updateWorkflows(envList, config) {
2803
2847
  const updatedContent = updateOptionsInYaml(fileContents, envList);
2804
2848
  (0, import_fs3.writeFileSync)(workflowPath, updatedContent, "utf8");
2805
2849
  log(` \u2713 Successfully updated ${workflowPath}`);
2806
- } catch (error4) {
2850
+ } catch (error3) {
2807
2851
  console.error(
2808
2852
  `
2809
2853
  \u26A0\uFE0F Error updating ${workflowPath} with environments: [${envList.join(", ")}]`
2810
2854
  );
2811
- console.error(`\u2717 Failed to update ${workflowPath}:`, error4);
2812
- throw error4;
2855
+ console.error(`\u2717 Failed to update ${workflowPath}:`, error3);
2856
+ throw error3;
2813
2857
  }
2814
2858
  }
2815
2859
  }
@@ -2850,21 +2894,90 @@ async function updateWorkflowEnvironments() {
2850
2894
  } else {
2851
2895
  log("\u2139\uFE0F No workflows were updated.");
2852
2896
  }
2853
- } catch (error4) {
2854
- console.error("\n\u274C Error updating workflows:", error4);
2897
+ } catch (error3) {
2898
+ console.error("\n\u274C Error updating workflows:", error3);
2855
2899
  process.exit(1);
2856
2900
  }
2857
2901
  }
2858
- var import_promises, import_fs3, import_path3, glob, yaml2;
2902
+ var import_promises, import_fs3, import_path4, glob2, yaml2;
2859
2903
  var init_update_workflows = __esm({
2860
2904
  "src/environment/update-workflows.ts"() {
2861
2905
  "use strict";
2862
2906
  import_promises = require("fs/promises");
2863
2907
  import_fs3 = require("fs");
2864
- import_path3 = require("path");
2865
- glob = __toESM(require("glob"));
2908
+ import_path4 = require("path");
2909
+ glob2 = __toESM(require("glob"));
2866
2910
  yaml2 = __toESM(require("js-yaml"));
2867
2911
  init_logger();
2912
+ init_paths();
2913
+ }
2914
+ });
2915
+
2916
+ // src/environment/upgrade.ts
2917
+ var upgrade_exports = {};
2918
+ __export(upgrade_exports, {
2919
+ upgradeEnvironmentLayout: () => upgradeEnvironmentLayout
2920
+ });
2921
+ function moveFileIfDestinationMissing(sourcePath, destinationPath) {
2922
+ if (!(0, import_fs4.existsSync)(sourcePath)) {
2923
+ return false;
2924
+ }
2925
+ if ((0, import_fs4.existsSync)(destinationPath)) {
2926
+ warn(
2927
+ `\u26A0\uFE0F Skipped ${sourcePath}; destination already exists at ${destinationPath}`
2928
+ );
2929
+ return false;
2930
+ }
2931
+ (0, import_fs4.mkdirSync)((0, import_path5.dirname)(destinationPath), { recursive: true });
2932
+ (0, import_fs4.renameSync)(sourcePath, destinationPath);
2933
+ log(` \u2713 Moved ${sourcePath} -> ${destinationPath}`);
2934
+ return true;
2935
+ }
2936
+ function migrateInventoryFiles() {
2937
+ const oldInventoryFiles = findOldInventoryFiles();
2938
+ if (oldInventoryFiles.length === 0) {
2939
+ log(`\u2139\uFE0F No old inventory files found at ${OLD_INVENTORY_DIR}`);
2940
+ return false;
2941
+ }
2942
+ log(import_kleur5.default.bold("\nMigrating Ansible inventory files"));
2943
+ let didMoveInventory = false;
2944
+ for (const oldInventoryFile of oldInventoryFiles) {
2945
+ const environment = getEnvironmentNameFromOldInventoryPath(oldInventoryFile);
2946
+ didMoveInventory = moveFileIfDestinationMissing(
2947
+ oldInventoryFile,
2948
+ getEnvironmentInventoryPath(environment)
2949
+ ) || didMoveInventory;
2950
+ }
2951
+ try {
2952
+ if ((0, import_fs4.existsSync)(OLD_INVENTORY_DIR) && (0, import_fs4.readdirSync)(OLD_INVENTORY_DIR).length === 0) {
2953
+ (0, import_fs4.rmdirSync)(OLD_INVENTORY_DIR);
2954
+ log(` \u2713 Removed empty ${OLD_INVENTORY_DIR}`);
2955
+ }
2956
+ } catch {
2957
+ warn(`\u26A0\uFE0F Could not remove ${OLD_INVENTORY_DIR}; please review it manually`);
2958
+ }
2959
+ return didMoveInventory;
2960
+ }
2961
+ async function upgradeEnvironmentLayout() {
2962
+ const didMoveInventory = migrateInventoryFiles();
2963
+ await updateWorkflowEnvironments();
2964
+ if (didMoveInventory) {
2965
+ success("\n\u2705 Environment layout upgrade completed successfully.");
2966
+ } else {
2967
+ success("\n\u2705 Environment layout already uses the current structure.");
2968
+ }
2969
+ log("\nCommit changes into git after upgrade");
2970
+ }
2971
+ var import_fs4, import_path5, import_kleur5;
2972
+ var init_upgrade = __esm({
2973
+ "src/environment/upgrade.ts"() {
2974
+ "use strict";
2975
+ import_fs4 = require("fs");
2976
+ import_path5 = require("path");
2977
+ import_kleur5 = __toESM(require("kleur"));
2978
+ init_logger();
2979
+ init_paths();
2980
+ init_update_workflows();
2868
2981
  }
2869
2982
  });
2870
2983
 
@@ -2877,7 +2990,7 @@ async function select4(options) {
2877
2990
  const inquirer = await import("@inquirer/prompts");
2878
2991
  return inquirer.select(options);
2879
2992
  }
2880
- async function selectInventoryFile(dirPath = "./infrastructure/server-setup/inventory/") {
2993
+ async function selectInventoryFile(dirPath = "./environments") {
2881
2994
  if (!fs4.existsSync(dirPath)) {
2882
2995
  warn(`\u26A0\uFE0F No environment configuration directory found at ${dirPath}`);
2883
2996
  warn(
@@ -2885,22 +2998,20 @@ async function selectInventoryFile(dirPath = "./infrastructure/server-setup/inve
2885
2998
  );
2886
2999
  return null;
2887
3000
  }
2888
- const files = fs4.readdirSync(dirPath).filter((file) => {
2889
- const filePath = path4.join(dirPath, file);
2890
- const isFile = fs4.statSync(filePath).isFile();
2891
- const ext = path4.extname(file).slice(1).toLowerCase();
2892
- return isFile && (ext === "yml" || ext === "yaml");
3001
+ const environments = fs4.readdirSync(dirPath).filter((entry) => {
3002
+ const filePath = path4.join(dirPath, entry);
3003
+ return fs4.statSync(filePath).isDirectory() && fs4.existsSync(getEnvironmentInventoryPath(entry));
2893
3004
  }).sort();
2894
- if (files.length === 0) {
3005
+ if (environments.length === 0) {
2895
3006
  warn(`\u26A0\uFE0F No environment configuration files found at ${dirPath}`);
2896
3007
  warn(
2897
3008
  "Hint: If this is a new infrastructure repository, run `opencrvs environment init` first."
2898
3009
  );
2899
3010
  return null;
2900
3011
  }
2901
- const choices = files.map((file) => ({
2902
- name: path4.basename(file, path4.extname(file)),
2903
- value: path4.join(dirPath, file)
3012
+ const choices = environments.map((environment) => ({
3013
+ name: environment,
3014
+ value: getEnvironmentInventoryPath(environment)
2904
3015
  }));
2905
3016
  const selectedFile = await select4({
2906
3017
  message: "Select environment (inventory file) to load users:",
@@ -2909,33 +3020,34 @@ async function selectInventoryFile(dirPath = "./infrastructure/server-setup/inve
2909
3020
  return selectedFile;
2910
3021
  }
2911
3022
  async function manageEnvironmentUsers() {
2912
- console.log("\n", import_kleur5.default.bold().underline("Manage users"), "\n");
3023
+ console.log("\n", import_kleur6.default.bold().underline("Manage users"), "\n");
2913
3024
  const inventory_file = await selectInventoryFile();
2914
3025
  if (!inventory_file) {
2915
3026
  return;
2916
3027
  }
2917
3028
  await manageUsers(inventory_file);
2918
3029
  }
2919
- var fs4, path4, import_kleur5;
3030
+ var fs4, path4, import_kleur6;
2920
3031
  var init_users = __esm({
2921
3032
  "src/environment/users.ts"() {
2922
3033
  "use strict";
2923
3034
  fs4 = __toESM(require("fs"));
2924
3035
  path4 = __toESM(require("path"));
2925
- import_kleur5 = __toESM(require("kleur"));
3036
+ import_kleur6 = __toESM(require("kleur"));
2926
3037
  init_manage_users();
2927
3038
  init_logger();
3039
+ init_paths();
2928
3040
  }
2929
3041
  });
2930
3042
 
2931
3043
  // src/environment/swarm-to-k8s.ts
2932
3044
  var swarm_to_k8s_exports = {};
2933
- var path5, import_kleur6, import_core2;
3045
+ var path5, import_kleur7, import_core2;
2934
3046
  var init_swarm_to_k8s = __esm({
2935
3047
  "src/environment/swarm-to-k8s.ts"() {
2936
3048
  "use strict";
2937
3049
  path5 = __toESM(require("path"));
2938
- import_kleur6 = __toESM(require("kleur"));
3050
+ import_kleur7 = __toESM(require("kleur"));
2939
3051
  init_logger();
2940
3052
  init_utils();
2941
3053
  init_templates();
@@ -2944,7 +3056,7 @@ var init_swarm_to_k8s = __esm({
2944
3056
  init_github();
2945
3057
  (async () => {
2946
3058
  log(
2947
- import_kleur6.default.bold(
3059
+ import_kleur7.default.bold(
2948
3060
  "------------------------------------------------\nOpenCRVS Infrastructure migration script: \nMigrating Swarm configurations to Kubernetes\n------------------------------------------------\n"
2949
3061
  )
2950
3062
  );
@@ -2975,7 +3087,7 @@ var init_swarm_to_k8s = __esm({
2975
3087
  );
2976
3088
  process.exit(0);
2977
3089
  }
2978
- log(import_kleur6.default.bold().underline("Migration properties:"));
3090
+ log(import_kleur7.default.bold().underline("Migration properties:"));
2979
3091
  log(` \u2713 Environment: ${environment}`);
2980
3092
  const old_inventory_path = process.env.OLD_INVENTORY_PATH || "";
2981
3093
  if (!old_inventory_path) {
@@ -3293,8 +3405,9 @@ async function runUpgrade(dockerSwarm) {
3293
3405
  }
3294
3406
 
3295
3407
  // src/environment/index.ts
3296
- var import_fs4 = require("fs");
3297
- var import_path4 = require("path");
3408
+ var import_fs5 = require("fs");
3409
+ var import_path6 = require("path");
3410
+ init_paths();
3298
3411
  var REQUIRED_REPOSITORY_DIRECTORIES = [
3299
3412
  ".github/workflows",
3300
3413
  "environments",
@@ -3304,7 +3417,7 @@ function validateRepositoryStructure(repositoryRoot = process.cwd()) {
3304
3417
  const missingDirectories = REQUIRED_REPOSITORY_DIRECTORIES.filter(
3305
3418
  (directory) => {
3306
3419
  try {
3307
- return !(0, import_fs4.statSync)((0, import_path4.resolve)(repositoryRoot, directory)).isDirectory();
3420
+ return !(0, import_fs5.statSync)((0, import_path6.resolve)(repositoryRoot, directory)).isDirectory();
3308
3421
  } catch {
3309
3422
  return true;
3310
3423
  }
@@ -3318,8 +3431,14 @@ function validateRepositoryStructure(repositoryRoot = process.cwd()) {
3318
3431
  }
3319
3432
  async function runEnvironmentInit() {
3320
3433
  validateRepositoryStructure();
3434
+ assertNoOldInventoryLayout();
3321
3435
  await Promise.resolve().then(() => (init_setup_environment(), setup_environment_exports));
3322
3436
  }
3437
+ async function runEnvironmentUpgrade() {
3438
+ validateRepositoryStructure();
3439
+ const { upgradeEnvironmentLayout: upgradeEnvironmentLayout2 } = await Promise.resolve().then(() => (init_upgrade(), upgrade_exports));
3440
+ await upgradeEnvironmentLayout2();
3441
+ }
3323
3442
  async function runEnvironmentUpdateWorkflows() {
3324
3443
  validateRepositoryStructure();
3325
3444
  const { updateWorkflowEnvironments: updateWorkflowEnvironments2 } = await Promise.resolve().then(() => (init_update_workflows(), update_workflows_exports));
@@ -3389,6 +3508,7 @@ Usage: opencrvs environment <subcommand>
3389
3508
 
3390
3509
  Subcommands:
3391
3510
  init Initialise a new environment
3511
+ upgrade Upgrade existing environment configuration
3392
3512
  update-workflows Update workflow environment options
3393
3513
  users Manage environment users
3394
3514
  swarm-to-k8s Migrate Docker Swarm configuration to Kubernetes
@@ -3399,6 +3519,8 @@ Subcommands:
3399
3519
  switch (subcommand) {
3400
3520
  case "init":
3401
3521
  return runEnvironmentCommand("initialisation", runEnvironmentInit);
3522
+ case "upgrade":
3523
+ return runEnvironmentCommand("environment upgrade", runEnvironmentUpgrade);
3402
3524
  case "update-workflows":
3403
3525
  return runEnvironmentCommand(
3404
3526
  "workflow update",
@@ -3419,10 +3541,10 @@ Subcommands:
3419
3541
  async function runEnvironmentCommand(operation, command) {
3420
3542
  try {
3421
3543
  await command();
3422
- } catch (error4) {
3544
+ } catch (error3) {
3423
3545
  console.error(
3424
3546
  `Environment ${operation} failed:`,
3425
- error4 instanceof Error ? error4.message : error4
3547
+ error3 instanceof Error ? error3.message : error3
3426
3548
  );
3427
3549
  process.exit(1);
3428
3550
  }
@@ -3448,8 +3570,8 @@ async function handleUpgrade() {
3448
3570
  try {
3449
3571
  await runUpgrade(dockerSwarm);
3450
3572
  console.log("Upgrade completed successfully!");
3451
- } catch (error4) {
3452
- console.error("Upgrade failed:", error4);
3573
+ } catch (error3) {
3574
+ console.error("Upgrade failed:", error3);
3453
3575
  process.exit(1);
3454
3576
  }
3455
3577
  }