@opencrvs/toolkit 2.1.0-rc.1b9e49f → 2.1.0-rc.1bd2a41

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 (79) hide show
  1. package/README.md +1 -0
  2. package/dist/application-config/index.js +2 -1
  3. package/dist/cli.js +164 -105
  4. package/dist/commons/api/router.d.ts +3342 -3359
  5. package/dist/commons/application-config/index.d.ts +6 -6
  6. package/dist/commons/conditionals/conditionals.d.ts +32 -323
  7. package/dist/commons/events/ActionConfig.d.ts +105 -105
  8. package/dist/commons/events/ActionDocument.d.ts +119 -119
  9. package/dist/commons/events/ActionInput.d.ts +0 -6
  10. package/dist/commons/events/ActionType.d.ts +62 -62
  11. package/dist/commons/events/AdvancedSearchConfig.d.ts +507 -507
  12. package/dist/commons/events/AuditLog.d.ts +43 -43
  13. package/dist/commons/events/CompositeFieldValue.d.ts +4 -4
  14. package/dist/commons/events/Conditional.d.ts +3 -3
  15. package/dist/commons/events/CountryConfigQueryInput.d.ts +590 -590
  16. package/dist/commons/events/Draft.d.ts +37 -37
  17. package/dist/commons/events/DynamicFieldValue.d.ts +9 -9
  18. package/dist/commons/events/EventConfig.d.ts +5 -5
  19. package/dist/commons/events/EventDocument.d.ts +48 -48
  20. package/dist/commons/events/EventIndex.d.ts +62 -62
  21. package/dist/commons/events/EventMetadata.d.ts +40 -40
  22. package/dist/commons/events/FieldConfig.d.ts +336 -336
  23. package/dist/commons/events/FieldType.d.ts +51 -51
  24. package/dist/commons/events/FieldTypeMapping.d.ts +100 -100
  25. package/dist/commons/events/FieldValue.d.ts +12 -12
  26. package/dist/commons/events/Flag.d.ts +15 -15
  27. package/dist/commons/events/TemplateConfig.d.ts +1 -1
  28. package/dist/commons/events/WorkqueueColumnConfig.d.ts +40 -40
  29. package/dist/commons/events/WorkqueueConfig.d.ts +826 -826
  30. package/dist/commons/events/deduplication.d.ts +1 -1
  31. package/dist/commons/events/event.d.ts +2 -2
  32. package/dist/commons/events/field.d.ts +69 -198
  33. package/dist/commons/events/locations.d.ts +96 -6
  34. package/dist/commons/events/mocks.test.utils.d.ts +18 -4
  35. package/dist/commons/events/scopes.d.ts +4 -4
  36. package/dist/commons/events/state/index.d.ts +17 -17
  37. package/dist/commons/events/state/utils.d.ts +7 -7
  38. package/dist/commons/events/test.utils.d.ts +40 -43
  39. package/dist/commons/events/utils.d.ts +114 -114
  40. package/dist/commons/notification/UserNotifications.d.ts +10 -10
  41. package/dist/environment/derived-variables.d.ts +119 -131
  42. package/dist/environment/derived-variables.d.ts.map +1 -1
  43. package/dist/environment/derived-variables.js +0 -14
  44. package/dist/environment/index.d.ts +1 -0
  45. package/dist/environment/index.d.ts.map +1 -1
  46. package/dist/environment/index.js +10 -0
  47. package/dist/environment/logger.d.ts +3 -12
  48. package/dist/environment/logger.d.ts.map +1 -1
  49. package/dist/environment/manage-users.js +17 -7
  50. package/dist/environment/paths.d.ts +7 -0
  51. package/dist/environment/paths.d.ts.map +1 -0
  52. package/dist/environment/paths.js +72 -0
  53. package/dist/environment/questions.d.ts +75 -74
  54. package/dist/environment/questions.d.ts.map +1 -1
  55. package/dist/environment/setup-environment.js +10 -29
  56. package/dist/environment/swarm-to-k8s.js +17 -7
  57. package/dist/environment/templates.d.ts.map +1 -1
  58. package/dist/environment/templates.js +2 -1
  59. package/dist/environment/update-workflows.d.ts.map +1 -1
  60. package/dist/environment/update-workflows.js +21 -10
  61. package/dist/environment/upgrade.d.ts +2 -0
  62. package/dist/environment/upgrade.d.ts.map +1 -0
  63. package/dist/environment/upgrade.js +80 -0
  64. package/dist/environment/users.js +28 -20
  65. package/dist/environment/utils.d.ts +1 -1
  66. package/dist/environment/utils.js +17 -7
  67. package/dist/events/deduplication.d.ts +1 -1
  68. package/dist/events/index.js +62 -58
  69. package/dist/migrations/v2.0/convert-config-files-to-ts.js +17 -7
  70. package/dist/migrations/v2.0/migrate-application-config-url.js +4 -3
  71. package/dist/migrations/v2.0/remove-hearth-migrations.js +17 -7
  72. package/dist/notification/index.js +48 -57
  73. package/dist/scopes/index.d.ts +146 -146
  74. package/dist/templates/charts-values/dependencies/values.yaml +0 -3
  75. package/dist/templates/charts-values/opencrvs-services/values.yaml +0 -4
  76. package/opencrvs-toolkit-2.1.0-rc.1bd2a41.tgz +0 -0
  77. package/package.json +3 -4
  78. package/tsconfig.tsbuildinfo +1 -1
  79. package/opencrvs-toolkit-2.1.0-rc.1b9e49f.tgz +0 -0
package/README.md CHANGED
@@ -25,6 +25,7 @@ Other environment operations are available as separate commands:
25
25
 
26
26
  ```sh
27
27
  opencrvs environment update-workflows
28
+ opencrvs environment upgrade
28
29
  opencrvs environment users
29
30
  opencrvs environment swarm-to-k8s
30
31
  ```
@@ -989,9 +989,10 @@ var NotifiedAction = ActionBase.extend(
989
989
  var EditAction = ActionBase.extend(
990
990
  z13.object({
991
991
  type: z13.literal(ActionType.EDIT),
992
+ /** @deprecated New Edit-actions should no longer contain content. This is kept for old 2.0 edits. */
992
993
  content: z13.object({
993
994
  comment: z13.string().describe("Comment for the edit action.").optional()
994
- })
995
+ }).optional()
995
996
  }).shape
996
997
  );
997
998
  var PrintContent = z13.object({
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({
@@ -380,20 +416,6 @@ var init_derived_variables = __esm({
380
416
  type: "disabled",
381
417
  scope: "ENVIRONMENT"
382
418
  },
383
- {
384
- name: "MONGODB_ADMIN_USER",
385
- valueLabel: "MONGODB_ADMIN_USER",
386
- valueType: "SECRET",
387
- type: "disabled",
388
- scope: "ENVIRONMENT"
389
- },
390
- {
391
- name: "MONGODB_ADMIN_PASSWORD",
392
- valueLabel: "MONGODB_ADMIN_PASSWORD",
393
- valueType: "SECRET",
394
- type: "disabled",
395
- scope: "ENVIRONMENT"
396
- },
397
419
  {
398
420
  name: "POSTGRES_USER",
399
421
  valueLabel: "POSTGRES_USER",
@@ -487,7 +509,7 @@ function storeSecrets(environment, answers) {
487
509
  envConfig = import_dotenv.default.parse(
488
510
  (0, import_fs.readFileSync)(`${process.cwd()}/.env.${environment}`)
489
511
  );
490
- } catch (error4) {
512
+ } catch (error3) {
491
513
  envConfig = {};
492
514
  }
493
515
  const linesFromAnswers = answers.map(
@@ -512,8 +534,8 @@ function writeYamlFile(filePath, data) {
512
534
  sortKeys: false
513
535
  });
514
536
  import_fs.default.writeFileSync(filePath, yamlContent, "utf8");
515
- } catch (error4) {
516
- throw new Error(`Failed to write inventory file: ${error4}`);
537
+ } catch (error3) {
538
+ throw new Error(`Failed to write inventory file: ${error3}`);
517
539
  }
518
540
  }
519
541
  var import_fs, yaml, import_dotenv;
@@ -573,8 +595,8 @@ function extractWorkerNodes(data) {
573
595
  return worker_hosts;
574
596
  }
575
597
  function copyChartsValues(env, values) {
576
- const srcDir = import_path2.default.resolve(__dirname, "templates", "charts-values");
577
- 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);
578
600
  import_fs2.default.mkdirSync(destDir, { recursive: true });
579
601
  values["lets_encrypt"] = values["traefik_mode"] === "lets_encrypt";
580
602
  values["static_ssl"] = values["traefik_mode"] === "static_ssl";
@@ -584,7 +606,7 @@ function copyChartsValues(env, values) {
584
606
  if (stat.isDirectory()) {
585
607
  import_fs2.default.mkdirSync(dest, { recursive: true });
586
608
  for (const item of import_fs2.default.readdirSync(src)) {
587
- 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));
588
610
  }
589
611
  } else {
590
612
  const content = import_fs2.default.readFileSync(src, "utf8");
@@ -606,36 +628,31 @@ function copyChartsValues(env, values) {
606
628
  `);
607
629
  }
608
630
  function generateInventory(env, values) {
609
- const templatePath = import_path2.default.join(
631
+ const templatePath = import_path3.default.join(
610
632
  __dirname,
611
633
  "templates",
612
634
  "inventory",
613
635
  "inventory.template.yml"
614
636
  );
615
- const outputPath = import_path2.default.join(
616
- process.cwd(),
617
- "infrastructure",
618
- "server-setup",
619
- "inventory",
620
- `${env}.yml`
621
- );
637
+ const outputPath = import_path3.default.resolve(process.cwd(), getEnvironmentInventoryPath(env));
622
638
  const templateFile = import_fs2.default.readFileSync(templatePath, "utf-8");
623
639
  const template = import_handlebars.default.compile(templateFile);
624
640
  values["single_node"] = values["kube_worker_nodes"].length > 0 || values["backup_host"] ? "false" : "true";
625
641
  const updated = template(values);
626
- import_fs2.default.mkdirSync(import_path2.default.dirname(outputPath), { recursive: true });
642
+ import_fs2.default.mkdirSync(import_path3.default.dirname(outputPath), { recursive: true });
627
643
  import_fs2.default.writeFileSync(outputPath, updated);
628
644
  log(`
629
645
  \u2705 Generated inventory file at ${outputPath}
630
646
  `);
631
647
  }
632
- var import_fs2, import_path2, import_handlebars;
648
+ var import_fs2, import_path3, import_handlebars;
633
649
  var init_templates = __esm({
634
650
  "src/environment/templates.ts"() {
635
651
  "use strict";
636
652
  import_fs2 = __toESM(require("fs"));
637
- import_path2 = __toESM(require("path"));
653
+ import_path3 = __toESM(require("path"));
638
654
  init_logger();
655
+ init_paths();
639
656
  import_handlebars = __toESM(require("handlebars"));
640
657
  import_handlebars.default.registerHelper("data_label_idx", function(value) {
641
658
  return parseInt(value) + 2;
@@ -1251,7 +1268,7 @@ function getCurrentUserSSHKeys() {
1251
1268
  keys.push(keyContent);
1252
1269
  }
1253
1270
  }
1254
- } catch (error4) {
1271
+ } catch (error3) {
1255
1272
  continue;
1256
1273
  }
1257
1274
  }
@@ -1787,6 +1804,7 @@ var init_setup_environment = __esm({
1787
1804
  init_editor_questions();
1788
1805
  init_questions_helper();
1789
1806
  init_manage_users();
1807
+ init_paths();
1790
1808
  ALL_QUESTIONS = [];
1791
1809
  ALL_ANSWERS = [];
1792
1810
  ALL_QUESTIONS.push(
@@ -1950,9 +1968,7 @@ var init_setup_environment = __esm({
1950
1968
  );
1951
1969
  const kubeWorkerNodes = infrastructure.kubeWorkerNodes ? infrastructure.kubeWorkerNodes.split(",").map((ip) => ip.trim()) : [];
1952
1970
  log("\n", import_kleur4.default.bold().underline("SSH Users"), "\n");
1953
- const users = await manageUsers(
1954
- `infrastructure/server-setup/inventory/${environment}.yml`
1955
- );
1971
+ const users = await manageUsers(getEnvironmentInventoryPath(environment));
1956
1972
  log("\n", import_kleur4.default.bold().underline("Traefik SSL Certificate"), "\n");
1957
1973
  const sslCertExists = findExistingValue(
1958
1974
  "SSL_CRT",
@@ -2290,40 +2306,6 @@ var init_setup_environment = __esm({
2290
2306
  ),
2291
2307
  scope: "ENVIRONMENT"
2292
2308
  },
2293
- {
2294
- name: "MONGODB_ADMIN_USER",
2295
- type: "SECRET",
2296
- didExist: findExistingValue(
2297
- "MONGODB_ADMIN_USER",
2298
- "SECRET",
2299
- "ENVIRONMENT",
2300
- existingValues
2301
- ),
2302
- value: findExistingOrDefine(
2303
- "MONGODB_ADMIN_USER",
2304
- "SECRET",
2305
- "ENVIRONMENT",
2306
- generateLongPassword()
2307
- ),
2308
- scope: "ENVIRONMENT"
2309
- },
2310
- {
2311
- name: "MONGODB_ADMIN_PASSWORD",
2312
- type: "SECRET",
2313
- didExist: findExistingValue(
2314
- "MONGODB_ADMIN_PASSWORD",
2315
- "SECRET",
2316
- "ENVIRONMENT",
2317
- existingValues
2318
- ),
2319
- value: findExistingOrDefine(
2320
- "MONGODB_ADMIN_PASSWORD",
2321
- "SECRET",
2322
- "ENVIRONMENT",
2323
- generateLongPassword()
2324
- ),
2325
- scope: "ENVIRONMENT"
2326
- },
2327
2309
  {
2328
2310
  name: "POSTGRES_USER",
2329
2311
  type: "SECRET",
@@ -2800,11 +2782,11 @@ __export(update_workflows_exports, {
2800
2782
  updateWorkflowEnvironments: () => updateWorkflowEnvironments
2801
2783
  });
2802
2784
  async function extractInfrastructureNames() {
2803
- const files = glob.sync("infrastructure/server-setup/inventory/*.yml");
2804
- const infraEnvironments = files.map((file) => (0, import_path3.basename)(file, ".yml"));
2785
+ const files = glob2.sync((0, import_path4.join)("environments", "*", INVENTORY_FILE_NAME));
2786
+ const infraEnvironments = files.map((file) => (0, import_path4.basename)((0, import_path4.dirname)(file)));
2805
2787
  if (infraEnvironments.length === 0) {
2806
2788
  console.log(
2807
- "\u26A0\uFE0F Warning: No environment directories found in infrastructure/server-setup/inventory/"
2789
+ `\u26A0\uFE0F Warning: No environment inventory files found at environments/*/${INVENTORY_FILE_NAME}`
2808
2790
  );
2809
2791
  return [];
2810
2792
  }
@@ -2814,7 +2796,7 @@ async function extractInfrastructureNames() {
2814
2796
  async function extractEnvironmentNames() {
2815
2797
  const entries = await (0, import_promises.readdir)("environments");
2816
2798
  const environments = entries.filter((entry) => {
2817
- const fullPath = (0, import_path3.join)("environments", entry);
2799
+ const fullPath = (0, import_path4.join)("environments", entry);
2818
2800
  return (0, import_fs3.statSync)(fullPath).isDirectory();
2819
2801
  });
2820
2802
  if (environments.length === 0) {
@@ -2851,13 +2833,13 @@ async function updateWorkflows(envList, config) {
2851
2833
  const updatedContent = updateOptionsInYaml(fileContents, envList);
2852
2834
  (0, import_fs3.writeFileSync)(workflowPath, updatedContent, "utf8");
2853
2835
  log(` \u2713 Successfully updated ${workflowPath}`);
2854
- } catch (error4) {
2836
+ } catch (error3) {
2855
2837
  console.error(
2856
2838
  `
2857
2839
  \u26A0\uFE0F Error updating ${workflowPath} with environments: [${envList.join(", ")}]`
2858
2840
  );
2859
- console.error(`\u2717 Failed to update ${workflowPath}:`, error4);
2860
- throw error4;
2841
+ console.error(`\u2717 Failed to update ${workflowPath}:`, error3);
2842
+ throw error3;
2861
2843
  }
2862
2844
  }
2863
2845
  }
@@ -2898,21 +2880,89 @@ async function updateWorkflowEnvironments() {
2898
2880
  } else {
2899
2881
  log("\u2139\uFE0F No workflows were updated.");
2900
2882
  }
2901
- } catch (error4) {
2902
- console.error("\n\u274C Error updating workflows:", error4);
2883
+ } catch (error3) {
2884
+ console.error("\n\u274C Error updating workflows:", error3);
2903
2885
  process.exit(1);
2904
2886
  }
2905
2887
  }
2906
- var import_promises, import_fs3, import_path3, glob, yaml2;
2888
+ var import_promises, import_fs3, import_path4, glob2, yaml2;
2907
2889
  var init_update_workflows = __esm({
2908
2890
  "src/environment/update-workflows.ts"() {
2909
2891
  "use strict";
2910
2892
  import_promises = require("fs/promises");
2911
2893
  import_fs3 = require("fs");
2912
- import_path3 = require("path");
2913
- glob = __toESM(require("glob"));
2894
+ import_path4 = require("path");
2895
+ glob2 = __toESM(require("glob"));
2914
2896
  yaml2 = __toESM(require("js-yaml"));
2915
2897
  init_logger();
2898
+ init_paths();
2899
+ }
2900
+ });
2901
+
2902
+ // src/environment/upgrade.ts
2903
+ var upgrade_exports = {};
2904
+ __export(upgrade_exports, {
2905
+ upgradeEnvironmentLayout: () => upgradeEnvironmentLayout
2906
+ });
2907
+ function moveFileIfDestinationMissing(sourcePath, destinationPath) {
2908
+ if (!(0, import_fs4.existsSync)(sourcePath)) {
2909
+ return false;
2910
+ }
2911
+ if ((0, import_fs4.existsSync)(destinationPath)) {
2912
+ warn(
2913
+ `\u26A0\uFE0F Skipped ${sourcePath}; destination already exists at ${destinationPath}`
2914
+ );
2915
+ return false;
2916
+ }
2917
+ (0, import_fs4.mkdirSync)((0, import_path5.dirname)(destinationPath), { recursive: true });
2918
+ (0, import_fs4.renameSync)(sourcePath, destinationPath);
2919
+ log(` \u2713 Moved ${sourcePath} -> ${destinationPath}`);
2920
+ return true;
2921
+ }
2922
+ function migrateInventoryFiles() {
2923
+ const oldInventoryFiles = findOldInventoryFiles();
2924
+ if (oldInventoryFiles.length === 0) {
2925
+ log(`\u2139\uFE0F No old inventory files found at ${OLD_INVENTORY_DIR}`);
2926
+ return false;
2927
+ }
2928
+ log(import_kleur5.default.bold("\nMigrating Ansible inventory files"));
2929
+ let didMoveInventory = false;
2930
+ for (const oldInventoryFile of oldInventoryFiles) {
2931
+ const environment = getEnvironmentNameFromOldInventoryPath(oldInventoryFile);
2932
+ didMoveInventory = moveFileIfDestinationMissing(
2933
+ oldInventoryFile,
2934
+ getEnvironmentInventoryPath(environment)
2935
+ ) || didMoveInventory;
2936
+ }
2937
+ try {
2938
+ if ((0, import_fs4.existsSync)(OLD_INVENTORY_DIR) && (0, import_fs4.readdirSync)(OLD_INVENTORY_DIR).length === 0) {
2939
+ (0, import_fs4.rmdirSync)(OLD_INVENTORY_DIR);
2940
+ log(` \u2713 Removed empty ${OLD_INVENTORY_DIR}`);
2941
+ }
2942
+ } catch {
2943
+ warn(`\u26A0\uFE0F Could not remove ${OLD_INVENTORY_DIR}; please review it manually`);
2944
+ }
2945
+ return didMoveInventory;
2946
+ }
2947
+ async function upgradeEnvironmentLayout() {
2948
+ const didMoveInventory = migrateInventoryFiles();
2949
+ await updateWorkflowEnvironments();
2950
+ if (didMoveInventory) {
2951
+ success("\n\u2705 Environment layout upgrade completed successfully.");
2952
+ return;
2953
+ }
2954
+ success("\n\u2705 Environment layout already uses the current structure.");
2955
+ }
2956
+ var import_fs4, import_path5, import_kleur5;
2957
+ var init_upgrade = __esm({
2958
+ "src/environment/upgrade.ts"() {
2959
+ "use strict";
2960
+ import_fs4 = require("fs");
2961
+ import_path5 = require("path");
2962
+ import_kleur5 = __toESM(require("kleur"));
2963
+ init_logger();
2964
+ init_paths();
2965
+ init_update_workflows();
2916
2966
  }
2917
2967
  });
2918
2968
 
@@ -2925,7 +2975,7 @@ async function select4(options) {
2925
2975
  const inquirer = await import("@inquirer/prompts");
2926
2976
  return inquirer.select(options);
2927
2977
  }
2928
- async function selectInventoryFile(dirPath = "./infrastructure/server-setup/inventory/") {
2978
+ async function selectInventoryFile(dirPath = "./environments") {
2929
2979
  if (!fs4.existsSync(dirPath)) {
2930
2980
  warn(`\u26A0\uFE0F No environment configuration directory found at ${dirPath}`);
2931
2981
  warn(
@@ -2933,22 +2983,20 @@ async function selectInventoryFile(dirPath = "./infrastructure/server-setup/inve
2933
2983
  );
2934
2984
  return null;
2935
2985
  }
2936
- const files = fs4.readdirSync(dirPath).filter((file) => {
2937
- const filePath = path4.join(dirPath, file);
2938
- const isFile = fs4.statSync(filePath).isFile();
2939
- const ext = path4.extname(file).slice(1).toLowerCase();
2940
- return isFile && (ext === "yml" || ext === "yaml");
2986
+ const environments = fs4.readdirSync(dirPath).filter((entry) => {
2987
+ const filePath = path4.join(dirPath, entry);
2988
+ return fs4.statSync(filePath).isDirectory() && fs4.existsSync(getEnvironmentInventoryPath(entry));
2941
2989
  }).sort();
2942
- if (files.length === 0) {
2990
+ if (environments.length === 0) {
2943
2991
  warn(`\u26A0\uFE0F No environment configuration files found at ${dirPath}`);
2944
2992
  warn(
2945
2993
  "Hint: If this is a new infrastructure repository, run `opencrvs environment init` first."
2946
2994
  );
2947
2995
  return null;
2948
2996
  }
2949
- const choices = files.map((file) => ({
2950
- name: path4.basename(file, path4.extname(file)),
2951
- value: path4.join(dirPath, file)
2997
+ const choices = environments.map((environment) => ({
2998
+ name: environment,
2999
+ value: getEnvironmentInventoryPath(environment)
2952
3000
  }));
2953
3001
  const selectedFile = await select4({
2954
3002
  message: "Select environment (inventory file) to load users:",
@@ -2957,33 +3005,34 @@ async function selectInventoryFile(dirPath = "./infrastructure/server-setup/inve
2957
3005
  return selectedFile;
2958
3006
  }
2959
3007
  async function manageEnvironmentUsers() {
2960
- console.log("\n", import_kleur5.default.bold().underline("Manage users"), "\n");
3008
+ console.log("\n", import_kleur6.default.bold().underline("Manage users"), "\n");
2961
3009
  const inventory_file = await selectInventoryFile();
2962
3010
  if (!inventory_file) {
2963
3011
  return;
2964
3012
  }
2965
3013
  await manageUsers(inventory_file);
2966
3014
  }
2967
- var fs4, path4, import_kleur5;
3015
+ var fs4, path4, import_kleur6;
2968
3016
  var init_users = __esm({
2969
3017
  "src/environment/users.ts"() {
2970
3018
  "use strict";
2971
3019
  fs4 = __toESM(require("fs"));
2972
3020
  path4 = __toESM(require("path"));
2973
- import_kleur5 = __toESM(require("kleur"));
3021
+ import_kleur6 = __toESM(require("kleur"));
2974
3022
  init_manage_users();
2975
3023
  init_logger();
3024
+ init_paths();
2976
3025
  }
2977
3026
  });
2978
3027
 
2979
3028
  // src/environment/swarm-to-k8s.ts
2980
3029
  var swarm_to_k8s_exports = {};
2981
- var path5, import_kleur6, import_core2;
3030
+ var path5, import_kleur7, import_core2;
2982
3031
  var init_swarm_to_k8s = __esm({
2983
3032
  "src/environment/swarm-to-k8s.ts"() {
2984
3033
  "use strict";
2985
3034
  path5 = __toESM(require("path"));
2986
- import_kleur6 = __toESM(require("kleur"));
3035
+ import_kleur7 = __toESM(require("kleur"));
2987
3036
  init_logger();
2988
3037
  init_utils();
2989
3038
  init_templates();
@@ -2992,7 +3041,7 @@ var init_swarm_to_k8s = __esm({
2992
3041
  init_github();
2993
3042
  (async () => {
2994
3043
  log(
2995
- import_kleur6.default.bold(
3044
+ import_kleur7.default.bold(
2996
3045
  "------------------------------------------------\nOpenCRVS Infrastructure migration script: \nMigrating Swarm configurations to Kubernetes\n------------------------------------------------\n"
2997
3046
  )
2998
3047
  );
@@ -3023,7 +3072,7 @@ var init_swarm_to_k8s = __esm({
3023
3072
  );
3024
3073
  process.exit(0);
3025
3074
  }
3026
- log(import_kleur6.default.bold().underline("Migration properties:"));
3075
+ log(import_kleur7.default.bold().underline("Migration properties:"));
3027
3076
  log(` \u2713 Environment: ${environment}`);
3028
3077
  const old_inventory_path = process.env.OLD_INVENTORY_PATH || "";
3029
3078
  if (!old_inventory_path) {
@@ -3341,8 +3390,9 @@ async function runUpgrade(dockerSwarm) {
3341
3390
  }
3342
3391
 
3343
3392
  // src/environment/index.ts
3344
- var import_fs4 = require("fs");
3345
- var import_path4 = require("path");
3393
+ var import_fs5 = require("fs");
3394
+ var import_path6 = require("path");
3395
+ init_paths();
3346
3396
  var REQUIRED_REPOSITORY_DIRECTORIES = [
3347
3397
  ".github/workflows",
3348
3398
  "environments",
@@ -3352,7 +3402,7 @@ function validateRepositoryStructure(repositoryRoot = process.cwd()) {
3352
3402
  const missingDirectories = REQUIRED_REPOSITORY_DIRECTORIES.filter(
3353
3403
  (directory) => {
3354
3404
  try {
3355
- return !(0, import_fs4.statSync)((0, import_path4.resolve)(repositoryRoot, directory)).isDirectory();
3405
+ return !(0, import_fs5.statSync)((0, import_path6.resolve)(repositoryRoot, directory)).isDirectory();
3356
3406
  } catch {
3357
3407
  return true;
3358
3408
  }
@@ -3366,8 +3416,14 @@ function validateRepositoryStructure(repositoryRoot = process.cwd()) {
3366
3416
  }
3367
3417
  async function runEnvironmentInit() {
3368
3418
  validateRepositoryStructure();
3419
+ assertNoOldInventoryLayout();
3369
3420
  await Promise.resolve().then(() => (init_setup_environment(), setup_environment_exports));
3370
3421
  }
3422
+ async function runEnvironmentUpgrade() {
3423
+ validateRepositoryStructure();
3424
+ const { upgradeEnvironmentLayout: upgradeEnvironmentLayout2 } = await Promise.resolve().then(() => (init_upgrade(), upgrade_exports));
3425
+ await upgradeEnvironmentLayout2();
3426
+ }
3371
3427
  async function runEnvironmentUpdateWorkflows() {
3372
3428
  validateRepositoryStructure();
3373
3429
  const { updateWorkflowEnvironments: updateWorkflowEnvironments2 } = await Promise.resolve().then(() => (init_update_workflows(), update_workflows_exports));
@@ -3437,6 +3493,7 @@ Usage: opencrvs environment <subcommand>
3437
3493
 
3438
3494
  Subcommands:
3439
3495
  init Initialise a new environment
3496
+ upgrade Upgrade existing environment configuration
3440
3497
  update-workflows Update workflow environment options
3441
3498
  users Manage environment users
3442
3499
  swarm-to-k8s Migrate Docker Swarm configuration to Kubernetes
@@ -3447,6 +3504,8 @@ Subcommands:
3447
3504
  switch (subcommand) {
3448
3505
  case "init":
3449
3506
  return runEnvironmentCommand("initialisation", runEnvironmentInit);
3507
+ case "upgrade":
3508
+ return runEnvironmentCommand("environment upgrade", runEnvironmentUpgrade);
3450
3509
  case "update-workflows":
3451
3510
  return runEnvironmentCommand(
3452
3511
  "workflow update",
@@ -3467,10 +3526,10 @@ Subcommands:
3467
3526
  async function runEnvironmentCommand(operation, command) {
3468
3527
  try {
3469
3528
  await command();
3470
- } catch (error4) {
3529
+ } catch (error3) {
3471
3530
  console.error(
3472
3531
  `Environment ${operation} failed:`,
3473
- error4 instanceof Error ? error4.message : error4
3532
+ error3 instanceof Error ? error3.message : error3
3474
3533
  );
3475
3534
  process.exit(1);
3476
3535
  }
@@ -3496,8 +3555,8 @@ async function handleUpgrade() {
3496
3555
  try {
3497
3556
  await runUpgrade(dockerSwarm);
3498
3557
  console.log("Upgrade completed successfully!");
3499
- } catch (error4) {
3500
- console.error("Upgrade failed:", error4);
3558
+ } catch (error3) {
3559
+ console.error("Upgrade failed:", error3);
3501
3560
  process.exit(1);
3502
3561
  }
3503
3562
  }