@opencrvs/toolkit 2.1.0-rc.69ab488 → 2.1.0-rc.6bae709

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 (93) 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 +230 -197
  6. package/dist/cli.js +174 -106
  7. package/dist/commons/api/router.d.ts +3608 -3367
  8. package/dist/commons/application-config/index.d.ts +6 -6
  9. package/dist/commons/conditionals/conditionals.d.ts +32 -323
  10. package/dist/commons/conditionals/validate.d.ts +11 -4
  11. package/dist/commons/events/ActionConfig.d.ts +112 -105
  12. package/dist/commons/events/ActionDocument.d.ts +117 -123
  13. package/dist/commons/events/ActionInput.d.ts +0 -6
  14. package/dist/commons/events/ActionStatus.d.ts +14 -0
  15. package/dist/commons/events/ActionType.d.ts +62 -62
  16. package/dist/commons/events/AdvancedSearchConfig.d.ts +519 -507
  17. package/dist/commons/events/AuditLog.d.ts +189 -42
  18. package/dist/commons/events/CompositeFieldValue.d.ts +4 -4
  19. package/dist/commons/events/Conditional.d.ts +3 -3
  20. package/dist/commons/events/CountryConfigQueryInput.d.ts +590 -590
  21. package/dist/commons/events/Draft.d.ts +37 -37
  22. package/dist/commons/events/DynamicFieldValue.d.ts +9 -9
  23. package/dist/commons/events/EventConfig.d.ts +8 -5
  24. package/dist/commons/events/EventDocument.d.ts +48 -48
  25. package/dist/commons/events/EventIndex.d.ts +49 -72
  26. package/dist/commons/events/EventMetadata.d.ts +40 -40
  27. package/dist/commons/events/FieldConfig.d.ts +406 -389
  28. package/dist/commons/events/FieldType.d.ts +51 -51
  29. package/dist/commons/events/FieldTypeMapping.d.ts +90 -90
  30. package/dist/commons/events/FieldValue.d.ts +14 -14
  31. package/dist/commons/events/Flag.d.ts +57 -15
  32. package/dist/commons/events/PlainDate.d.ts +8 -0
  33. package/dist/commons/events/SummaryConfig.d.ts +249 -0
  34. package/dist/commons/events/TemplateConfig.d.ts +1 -1
  35. package/dist/commons/events/WorkqueueColumnConfig.d.ts +40 -40
  36. package/dist/commons/events/WorkqueueConfig.d.ts +817 -814
  37. package/dist/commons/events/deduplication.d.ts +1 -1
  38. package/dist/commons/events/event.d.ts +14 -2
  39. package/dist/commons/events/field.d.ts +69 -198
  40. package/dist/commons/events/index.d.ts +1 -0
  41. package/dist/commons/events/locationPayloads.d.ts +95 -0
  42. package/dist/commons/events/locations.d.ts +192 -12
  43. package/dist/commons/events/mocks.test.utils.d.ts +48 -4
  44. package/dist/commons/events/scopes.d.ts +4 -4
  45. package/dist/commons/events/state/index.d.ts +17 -17
  46. package/dist/commons/events/state/utils.d.ts +7 -7
  47. package/dist/commons/events/test.utils.d.ts +40 -43
  48. package/dist/commons/events/utils.d.ts +122 -114
  49. package/dist/commons/notification/UserNotifications.d.ts +10 -10
  50. package/dist/conditionals/index.js +303 -55
  51. package/dist/environment/derived-variables.d.ts +119 -131
  52. package/dist/environment/derived-variables.d.ts.map +1 -1
  53. package/dist/environment/derived-variables.js +0 -14
  54. package/dist/environment/index.d.ts +1 -0
  55. package/dist/environment/index.d.ts.map +1 -1
  56. package/dist/environment/index.js +10 -0
  57. package/dist/environment/logger.d.ts +3 -3
  58. package/dist/environment/manage-users.js +17 -7
  59. package/dist/environment/paths.d.ts +7 -0
  60. package/dist/environment/paths.d.ts.map +1 -0
  61. package/dist/environment/paths.js +72 -0
  62. package/dist/environment/questions.d.ts +75 -74
  63. package/dist/environment/questions.d.ts.map +1 -1
  64. package/dist/environment/setup-environment.js +10 -29
  65. package/dist/environment/swarm-to-k8s.js +17 -7
  66. package/dist/environment/templates.d.ts.map +1 -1
  67. package/dist/environment/templates.js +2 -1
  68. package/dist/environment/update-workflows.d.ts.map +1 -1
  69. package/dist/environment/update-workflows.js +34 -12
  70. package/dist/environment/upgrade.d.ts +2 -0
  71. package/dist/environment/upgrade.d.ts.map +1 -0
  72. package/dist/environment/upgrade.js +82 -0
  73. package/dist/environment/users.js +28 -20
  74. package/dist/environment/utils.d.ts +1 -1
  75. package/dist/environment/utils.js +17 -7
  76. package/dist/events/deduplication.d.ts +1 -1
  77. package/dist/events/index.js +3914 -3562
  78. package/dist/migrations/v2.0/checkout-upstream-files.d.ts +2 -2
  79. package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +1 -1
  80. package/dist/migrations/v2.0/checkout-upstream-files.js +2 -2
  81. package/dist/migrations/v2.0/convert-config-files-to-ts.js +17 -7
  82. package/dist/migrations/v2.0/migrate-application-config-url.js +4 -3
  83. package/dist/migrations/v2.0/remove-hearth-migrations.js +17 -7
  84. package/dist/notification/index.js +1937 -1112
  85. package/dist/scopes/index.d.ts +394 -169
  86. package/dist/scopes/index.js +304 -55
  87. package/dist/templates/charts-values/dependencies/values.yaml +0 -3
  88. package/dist/templates/charts-values/opencrvs-services/values.yaml +4 -7
  89. package/dist/templates/charts-values/opentelemetry/values.yaml +73 -0
  90. package/opencrvs-toolkit-2.1.0-rc.6bae709.tgz +0 -0
  91. package/package.json +7 -7
  92. package/tsconfig.tsbuildinfo +1 -1
  93. package/opencrvs-toolkit-2.1.0-rc.69ab488.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({
@@ -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",
@@ -2799,12 +2781,19 @@ var update_workflows_exports = {};
2799
2781
  __export(update_workflows_exports, {
2800
2782
  updateWorkflowEnvironments: () => updateWorkflowEnvironments
2801
2783
  });
2784
+ function isDirectory(path6) {
2785
+ try {
2786
+ return (0, import_fs3.statSync)(path6).isDirectory();
2787
+ } catch {
2788
+ return false;
2789
+ }
2790
+ }
2802
2791
  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"));
2792
+ const files = glob2.sync((0, import_path4.join)("environments", "*", INVENTORY_FILE_NAME));
2793
+ const infraEnvironments = files.map((file) => (0, import_path4.basename)((0, import_path4.dirname)(file)));
2805
2794
  if (infraEnvironments.length === 0) {
2806
2795
  console.log(
2807
- "\u26A0\uFE0F Warning: No environment directories found in infrastructure/server-setup/inventory/"
2796
+ `\u26A0\uFE0F Warning: No environment inventory files found at environments/*/${INVENTORY_FILE_NAME}`
2808
2797
  );
2809
2798
  return [];
2810
2799
  }
@@ -2814,8 +2803,9 @@ async function extractInfrastructureNames() {
2814
2803
  async function extractEnvironmentNames() {
2815
2804
  const entries = await (0, import_promises.readdir)("environments");
2816
2805
  const environments = entries.filter((entry) => {
2817
- const fullPath = (0, import_path3.join)("environments", entry);
2818
- return (0, import_fs3.statSync)(fullPath).isDirectory();
2806
+ const environmentPath = (0, import_path4.join)("environments", entry);
2807
+ const opencrvsServicesPath = (0, import_path4.join)(environmentPath, "opencrvs-services");
2808
+ return isDirectory(environmentPath) && (0, import_fs3.existsSync)(opencrvsServicesPath) && isDirectory(opencrvsServicesPath);
2819
2809
  });
2820
2810
  if (environments.length === 0) {
2821
2811
  console.log(
@@ -2851,13 +2841,13 @@ async function updateWorkflows(envList, config) {
2851
2841
  const updatedContent = updateOptionsInYaml(fileContents, envList);
2852
2842
  (0, import_fs3.writeFileSync)(workflowPath, updatedContent, "utf8");
2853
2843
  log(` \u2713 Successfully updated ${workflowPath}`);
2854
- } catch (error4) {
2844
+ } catch (error3) {
2855
2845
  console.error(
2856
2846
  `
2857
2847
  \u26A0\uFE0F Error updating ${workflowPath} with environments: [${envList.join(", ")}]`
2858
2848
  );
2859
- console.error(`\u2717 Failed to update ${workflowPath}:`, error4);
2860
- throw error4;
2849
+ console.error(`\u2717 Failed to update ${workflowPath}:`, error3);
2850
+ throw error3;
2861
2851
  }
2862
2852
  }
2863
2853
  }
@@ -2898,21 +2888,90 @@ async function updateWorkflowEnvironments() {
2898
2888
  } else {
2899
2889
  log("\u2139\uFE0F No workflows were updated.");
2900
2890
  }
2901
- } catch (error4) {
2902
- console.error("\n\u274C Error updating workflows:", error4);
2891
+ } catch (error3) {
2892
+ console.error("\n\u274C Error updating workflows:", error3);
2903
2893
  process.exit(1);
2904
2894
  }
2905
2895
  }
2906
- var import_promises, import_fs3, import_path3, glob, yaml2;
2896
+ var import_promises, import_fs3, import_path4, glob2, yaml2;
2907
2897
  var init_update_workflows = __esm({
2908
2898
  "src/environment/update-workflows.ts"() {
2909
2899
  "use strict";
2910
2900
  import_promises = require("fs/promises");
2911
2901
  import_fs3 = require("fs");
2912
- import_path3 = require("path");
2913
- glob = __toESM(require("glob"));
2902
+ import_path4 = require("path");
2903
+ glob2 = __toESM(require("glob"));
2914
2904
  yaml2 = __toESM(require("js-yaml"));
2915
2905
  init_logger();
2906
+ init_paths();
2907
+ }
2908
+ });
2909
+
2910
+ // src/environment/upgrade.ts
2911
+ var upgrade_exports = {};
2912
+ __export(upgrade_exports, {
2913
+ upgradeEnvironmentLayout: () => upgradeEnvironmentLayout
2914
+ });
2915
+ function moveFileIfDestinationMissing(sourcePath, destinationPath) {
2916
+ if (!(0, import_fs4.existsSync)(sourcePath)) {
2917
+ return false;
2918
+ }
2919
+ if ((0, import_fs4.existsSync)(destinationPath)) {
2920
+ warn(
2921
+ `\u26A0\uFE0F Skipped ${sourcePath}; destination already exists at ${destinationPath}`
2922
+ );
2923
+ return false;
2924
+ }
2925
+ (0, import_fs4.mkdirSync)((0, import_path5.dirname)(destinationPath), { recursive: true });
2926
+ (0, import_fs4.renameSync)(sourcePath, destinationPath);
2927
+ log(` \u2713 Moved ${sourcePath} -> ${destinationPath}`);
2928
+ return true;
2929
+ }
2930
+ function migrateInventoryFiles() {
2931
+ const oldInventoryFiles = findOldInventoryFiles();
2932
+ if (oldInventoryFiles.length === 0) {
2933
+ log(`\u2139\uFE0F No old inventory files found at ${OLD_INVENTORY_DIR}`);
2934
+ return false;
2935
+ }
2936
+ log(import_kleur5.default.bold("\nMigrating Ansible inventory files"));
2937
+ let didMoveInventory = false;
2938
+ for (const oldInventoryFile of oldInventoryFiles) {
2939
+ const environment = getEnvironmentNameFromOldInventoryPath(oldInventoryFile);
2940
+ didMoveInventory = moveFileIfDestinationMissing(
2941
+ oldInventoryFile,
2942
+ getEnvironmentInventoryPath(environment)
2943
+ ) || didMoveInventory;
2944
+ }
2945
+ try {
2946
+ if ((0, import_fs4.existsSync)(OLD_INVENTORY_DIR) && (0, import_fs4.readdirSync)(OLD_INVENTORY_DIR).length === 0) {
2947
+ (0, import_fs4.rmdirSync)(OLD_INVENTORY_DIR);
2948
+ log(` \u2713 Removed empty ${OLD_INVENTORY_DIR}`);
2949
+ }
2950
+ } catch {
2951
+ warn(`\u26A0\uFE0F Could not remove ${OLD_INVENTORY_DIR}; please review it manually`);
2952
+ }
2953
+ return didMoveInventory;
2954
+ }
2955
+ async function upgradeEnvironmentLayout() {
2956
+ const didMoveInventory = migrateInventoryFiles();
2957
+ await updateWorkflowEnvironments();
2958
+ if (didMoveInventory) {
2959
+ success("\n\u2705 Environment layout upgrade completed successfully.");
2960
+ } else {
2961
+ success("\n\u2705 Environment layout already uses the current structure.");
2962
+ }
2963
+ log("\nCommit changes into git after upgrade");
2964
+ }
2965
+ var import_fs4, import_path5, import_kleur5;
2966
+ var init_upgrade = __esm({
2967
+ "src/environment/upgrade.ts"() {
2968
+ "use strict";
2969
+ import_fs4 = require("fs");
2970
+ import_path5 = require("path");
2971
+ import_kleur5 = __toESM(require("kleur"));
2972
+ init_logger();
2973
+ init_paths();
2974
+ init_update_workflows();
2916
2975
  }
2917
2976
  });
2918
2977
 
@@ -2925,7 +2984,7 @@ async function select4(options) {
2925
2984
  const inquirer = await import("@inquirer/prompts");
2926
2985
  return inquirer.select(options);
2927
2986
  }
2928
- async function selectInventoryFile(dirPath = "./infrastructure/server-setup/inventory/") {
2987
+ async function selectInventoryFile(dirPath = "./environments") {
2929
2988
  if (!fs4.existsSync(dirPath)) {
2930
2989
  warn(`\u26A0\uFE0F No environment configuration directory found at ${dirPath}`);
2931
2990
  warn(
@@ -2933,22 +2992,20 @@ async function selectInventoryFile(dirPath = "./infrastructure/server-setup/inve
2933
2992
  );
2934
2993
  return null;
2935
2994
  }
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");
2995
+ const environments = fs4.readdirSync(dirPath).filter((entry) => {
2996
+ const filePath = path4.join(dirPath, entry);
2997
+ return fs4.statSync(filePath).isDirectory() && fs4.existsSync(getEnvironmentInventoryPath(entry));
2941
2998
  }).sort();
2942
- if (files.length === 0) {
2999
+ if (environments.length === 0) {
2943
3000
  warn(`\u26A0\uFE0F No environment configuration files found at ${dirPath}`);
2944
3001
  warn(
2945
3002
  "Hint: If this is a new infrastructure repository, run `opencrvs environment init` first."
2946
3003
  );
2947
3004
  return null;
2948
3005
  }
2949
- const choices = files.map((file) => ({
2950
- name: path4.basename(file, path4.extname(file)),
2951
- value: path4.join(dirPath, file)
3006
+ const choices = environments.map((environment) => ({
3007
+ name: environment,
3008
+ value: getEnvironmentInventoryPath(environment)
2952
3009
  }));
2953
3010
  const selectedFile = await select4({
2954
3011
  message: "Select environment (inventory file) to load users:",
@@ -2957,33 +3014,34 @@ async function selectInventoryFile(dirPath = "./infrastructure/server-setup/inve
2957
3014
  return selectedFile;
2958
3015
  }
2959
3016
  async function manageEnvironmentUsers() {
2960
- console.log("\n", import_kleur5.default.bold().underline("Manage users"), "\n");
3017
+ console.log("\n", import_kleur6.default.bold().underline("Manage users"), "\n");
2961
3018
  const inventory_file = await selectInventoryFile();
2962
3019
  if (!inventory_file) {
2963
3020
  return;
2964
3021
  }
2965
3022
  await manageUsers(inventory_file);
2966
3023
  }
2967
- var fs4, path4, import_kleur5;
3024
+ var fs4, path4, import_kleur6;
2968
3025
  var init_users = __esm({
2969
3026
  "src/environment/users.ts"() {
2970
3027
  "use strict";
2971
3028
  fs4 = __toESM(require("fs"));
2972
3029
  path4 = __toESM(require("path"));
2973
- import_kleur5 = __toESM(require("kleur"));
3030
+ import_kleur6 = __toESM(require("kleur"));
2974
3031
  init_manage_users();
2975
3032
  init_logger();
3033
+ init_paths();
2976
3034
  }
2977
3035
  });
2978
3036
 
2979
3037
  // src/environment/swarm-to-k8s.ts
2980
3038
  var swarm_to_k8s_exports = {};
2981
- var path5, import_kleur6, import_core2;
3039
+ var path5, import_kleur7, import_core2;
2982
3040
  var init_swarm_to_k8s = __esm({
2983
3041
  "src/environment/swarm-to-k8s.ts"() {
2984
3042
  "use strict";
2985
3043
  path5 = __toESM(require("path"));
2986
- import_kleur6 = __toESM(require("kleur"));
3044
+ import_kleur7 = __toESM(require("kleur"));
2987
3045
  init_logger();
2988
3046
  init_utils();
2989
3047
  init_templates();
@@ -2992,7 +3050,7 @@ var init_swarm_to_k8s = __esm({
2992
3050
  init_github();
2993
3051
  (async () => {
2994
3052
  log(
2995
- import_kleur6.default.bold(
3053
+ import_kleur7.default.bold(
2996
3054
  "------------------------------------------------\nOpenCRVS Infrastructure migration script: \nMigrating Swarm configurations to Kubernetes\n------------------------------------------------\n"
2997
3055
  )
2998
3056
  );
@@ -3023,7 +3081,7 @@ var init_swarm_to_k8s = __esm({
3023
3081
  );
3024
3082
  process.exit(0);
3025
3083
  }
3026
- log(import_kleur6.default.bold().underline("Migration properties:"));
3084
+ log(import_kleur7.default.bold().underline("Migration properties:"));
3027
3085
  log(` \u2713 Environment: ${environment}`);
3028
3086
  const old_inventory_path = process.env.OLD_INVENTORY_PATH || "";
3029
3087
  if (!old_inventory_path) {
@@ -3341,8 +3399,9 @@ async function runUpgrade(dockerSwarm) {
3341
3399
  }
3342
3400
 
3343
3401
  // src/environment/index.ts
3344
- var import_fs4 = require("fs");
3345
- var import_path4 = require("path");
3402
+ var import_fs5 = require("fs");
3403
+ var import_path6 = require("path");
3404
+ init_paths();
3346
3405
  var REQUIRED_REPOSITORY_DIRECTORIES = [
3347
3406
  ".github/workflows",
3348
3407
  "environments",
@@ -3352,7 +3411,7 @@ function validateRepositoryStructure(repositoryRoot = process.cwd()) {
3352
3411
  const missingDirectories = REQUIRED_REPOSITORY_DIRECTORIES.filter(
3353
3412
  (directory) => {
3354
3413
  try {
3355
- return !(0, import_fs4.statSync)((0, import_path4.resolve)(repositoryRoot, directory)).isDirectory();
3414
+ return !(0, import_fs5.statSync)((0, import_path6.resolve)(repositoryRoot, directory)).isDirectory();
3356
3415
  } catch {
3357
3416
  return true;
3358
3417
  }
@@ -3366,8 +3425,14 @@ function validateRepositoryStructure(repositoryRoot = process.cwd()) {
3366
3425
  }
3367
3426
  async function runEnvironmentInit() {
3368
3427
  validateRepositoryStructure();
3428
+ assertNoOldInventoryLayout();
3369
3429
  await Promise.resolve().then(() => (init_setup_environment(), setup_environment_exports));
3370
3430
  }
3431
+ async function runEnvironmentUpgrade() {
3432
+ validateRepositoryStructure();
3433
+ const { upgradeEnvironmentLayout: upgradeEnvironmentLayout2 } = await Promise.resolve().then(() => (init_upgrade(), upgrade_exports));
3434
+ await upgradeEnvironmentLayout2();
3435
+ }
3371
3436
  async function runEnvironmentUpdateWorkflows() {
3372
3437
  validateRepositoryStructure();
3373
3438
  const { updateWorkflowEnvironments: updateWorkflowEnvironments2 } = await Promise.resolve().then(() => (init_update_workflows(), update_workflows_exports));
@@ -3437,6 +3502,7 @@ Usage: opencrvs environment <subcommand>
3437
3502
 
3438
3503
  Subcommands:
3439
3504
  init Initialise a new environment
3505
+ upgrade Upgrade existing environment configuration
3440
3506
  update-workflows Update workflow environment options
3441
3507
  users Manage environment users
3442
3508
  swarm-to-k8s Migrate Docker Swarm configuration to Kubernetes
@@ -3447,6 +3513,8 @@ Subcommands:
3447
3513
  switch (subcommand) {
3448
3514
  case "init":
3449
3515
  return runEnvironmentCommand("initialisation", runEnvironmentInit);
3516
+ case "upgrade":
3517
+ return runEnvironmentCommand("environment upgrade", runEnvironmentUpgrade);
3450
3518
  case "update-workflows":
3451
3519
  return runEnvironmentCommand(
3452
3520
  "workflow update",
@@ -3467,10 +3535,10 @@ Subcommands:
3467
3535
  async function runEnvironmentCommand(operation, command) {
3468
3536
  try {
3469
3537
  await command();
3470
- } catch (error4) {
3538
+ } catch (error3) {
3471
3539
  console.error(
3472
3540
  `Environment ${operation} failed:`,
3473
- error4 instanceof Error ? error4.message : error4
3541
+ error3 instanceof Error ? error3.message : error3
3474
3542
  );
3475
3543
  process.exit(1);
3476
3544
  }
@@ -3496,8 +3564,8 @@ async function handleUpgrade() {
3496
3564
  try {
3497
3565
  await runUpgrade(dockerSwarm);
3498
3566
  console.log("Upgrade completed successfully!");
3499
- } catch (error4) {
3500
- console.error("Upgrade failed:", error4);
3567
+ } catch (error3) {
3568
+ console.error("Upgrade failed:", error3);
3501
3569
  process.exit(1);
3502
3570
  }
3503
3571
  }