@opencrvs/toolkit 2.1.0-rc.edf2492 → 2.1.0-rc.f5f3da9

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 (70) hide show
  1. package/README.md +1 -0
  2. package/dist/application-config/index.js +2 -1
  3. package/dist/cli.js +217 -77
  4. package/dist/commons/api/router.d.ts +3293 -3310
  5. package/dist/commons/application-config/index.d.ts +6 -6
  6. package/dist/commons/conditionals/conditionals.d.ts +259 -2102
  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 +78 -895
  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 -119
  42. package/dist/environment/derived-variables.d.ts.map +1 -1
  43. package/dist/environment/index.d.ts +1 -0
  44. package/dist/environment/index.d.ts.map +1 -1
  45. package/dist/environment/index.js +10 -0
  46. package/dist/environment/logger.d.ts.map +1 -1
  47. package/dist/environment/paths.d.ts +13 -0
  48. package/dist/environment/paths.d.ts.map +1 -0
  49. package/dist/environment/paths.js +94 -0
  50. package/dist/environment/questions.d.ts +75 -74
  51. package/dist/environment/questions.d.ts.map +1 -1
  52. package/dist/environment/setup-environment.js +10 -15
  53. package/dist/environment/templates.d.ts.map +1 -1
  54. package/dist/environment/templates.js +2 -1
  55. package/dist/environment/update-workflows.d.ts.map +1 -1
  56. package/dist/environment/update-workflows.js +4 -3
  57. package/dist/environment/upgrade.d.ts +2 -0
  58. package/dist/environment/upgrade.d.ts.map +1 -0
  59. package/dist/environment/upgrade.js +100 -0
  60. package/dist/environment/users.js +11 -13
  61. package/dist/environment/utils.d.ts +1 -1
  62. package/dist/events/deduplication.d.ts +1 -1
  63. package/dist/events/index.js +62 -58
  64. package/dist/migrations/v2.0/migrate-application-config-url.js +4 -3
  65. package/dist/notification/index.js +48 -57
  66. package/dist/scopes/index.d.ts +146 -146
  67. package/opencrvs-toolkit-2.1.0-rc.f5f3da9.tgz +0 -0
  68. package/package.json +3 -4
  69. package/tsconfig.tsbuildinfo +1 -1
  70. package/opencrvs-toolkit-2.1.0-rc.edf2492.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,53 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
30
30
  mod
31
31
  ));
32
32
 
33
+ // src/environment/paths.ts
34
+ function getEnvironmentDir(environment) {
35
+ return (0, import_path2.join)("environments", environment);
36
+ }
37
+ function getEnvironmentInventoryPath(environment) {
38
+ return (0, import_path2.join)(getEnvironmentDir(environment), INVENTORY_FILE_NAME);
39
+ }
40
+ function getEnvironmentInventoryVarsPath(environment) {
41
+ return (0, import_path2.join)(getEnvironmentDir(environment), INVENTORY_VARS_FILE_NAME);
42
+ }
43
+ function findOldInventoryFiles() {
44
+ return glob.sync((0, import_path2.join)(OLD_INVENTORY_DIR, "*.yml")).sort();
45
+ }
46
+ function getEnvironmentNameFromOldInventoryPath(filePath) {
47
+ return (0, import_path2.basename)(filePath, ".yml");
48
+ }
49
+ function hasOldInventoryLayout() {
50
+ return findOldInventoryFiles().length > 0;
51
+ }
52
+ function assertNoOldInventoryLayout() {
53
+ if (!hasOldInventoryLayout()) {
54
+ return;
55
+ }
56
+ throw new Error(
57
+ [
58
+ `Old inventory layout detected at ${OLD_INVENTORY_DIR}.`,
59
+ "Please run `yarn environment:upgrade` before running `yarn environment:init`."
60
+ ].join(" ")
61
+ );
62
+ }
63
+ var import_fs, import_path2, glob, OLD_INVENTORY_DIR, INVENTORY_FILE_NAME, INVENTORY_VARS_FILE_NAME;
64
+ var init_paths = __esm({
65
+ "src/environment/paths.ts"() {
66
+ "use strict";
67
+ import_fs = require("fs");
68
+ import_path2 = require("path");
69
+ glob = __toESM(require("glob"));
70
+ OLD_INVENTORY_DIR = (0, import_path2.join)(
71
+ "infrastructure",
72
+ "server-setup",
73
+ "inventory"
74
+ );
75
+ INVENTORY_FILE_NAME = "inventory.yml";
76
+ INVENTORY_VARS_FILE_NAME = "inventory-vars.yml";
77
+ }
78
+ });
79
+
33
80
  // src/environment/logger.ts
34
81
  var import_kleur, log, warn, success, info, error;
35
82
  var init_logger = __esm({
@@ -471,9 +518,9 @@ function storeSecrets(environment, answers) {
471
518
  let envConfig = {};
472
519
  try {
473
520
  envConfig = import_dotenv.default.parse(
474
- (0, import_fs.readFileSync)(`${process.cwd()}/.env.${environment}`)
521
+ (0, import_fs2.readFileSync)(`${process.cwd()}/.env.${environment}`)
475
522
  );
476
- } catch (error4) {
523
+ } catch (error3) {
477
524
  envConfig = {};
478
525
  }
479
526
  const linesFromAnswers = answers.map(
@@ -481,10 +528,10 @@ function storeSecrets(environment, answers) {
481
528
  );
482
529
  const linesFromEnvConfig = Object.entries(envConfig).filter(([name]) => !answers.find((update) => update.name === name)).map(([name, value]) => `${name}="${value}"`);
483
530
  const allLines = [...linesFromEnvConfig, ...linesFromAnswers].sort();
484
- (0, import_fs.writeFileSync)(`.env.${environment}`, allLines.join("\n"));
531
+ (0, import_fs2.writeFileSync)(`.env.${environment}`, allLines.join("\n"));
485
532
  }
486
533
  function readYamlFile(filePath) {
487
- const fileContent = import_fs.default.readFileSync(filePath, "utf8");
534
+ const fileContent = import_fs2.default.readFileSync(filePath, "utf8");
488
535
  return yaml.load(fileContent);
489
536
  }
490
537
  function writeYamlFile(filePath, data) {
@@ -497,16 +544,16 @@ function writeYamlFile(filePath, data) {
497
544
  noRefs: true,
498
545
  sortKeys: false
499
546
  });
500
- import_fs.default.writeFileSync(filePath, yamlContent, "utf8");
501
- } catch (error4) {
502
- throw new Error(`Failed to write inventory file: ${error4}`);
547
+ import_fs2.default.writeFileSync(filePath, yamlContent, "utf8");
548
+ } catch (error3) {
549
+ throw new Error(`Failed to write inventory file: ${error3}`);
503
550
  }
504
551
  }
505
- var import_fs, yaml, import_dotenv;
552
+ var import_fs2, yaml, import_dotenv;
506
553
  var init_utils = __esm({
507
554
  "src/environment/utils.ts"() {
508
555
  "use strict";
509
- import_fs = __toESM(require("fs"));
556
+ import_fs2 = __toESM(require("fs"));
510
557
  yaml = __toESM(require("js-yaml"));
511
558
  import_dotenv = __toESM(require("dotenv"));
512
559
  }
@@ -559,29 +606,29 @@ function extractWorkerNodes(data) {
559
606
  return worker_hosts;
560
607
  }
561
608
  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);
564
- import_fs2.default.mkdirSync(destDir, { recursive: true });
609
+ const srcDir = import_path3.default.resolve(__dirname, "templates", "charts-values");
610
+ const destDir = import_path3.default.resolve(process.cwd(), "environments", env);
611
+ import_fs3.default.mkdirSync(destDir, { recursive: true });
565
612
  values["lets_encrypt"] = values["traefik_mode"] === "lets_encrypt";
566
613
  values["static_ssl"] = values["traefik_mode"] === "static_ssl";
567
614
  values["opencrvs_environment"] = env;
568
615
  function copyRecursive(src, dest) {
569
- const stat = import_fs2.default.statSync(src);
616
+ const stat = import_fs3.default.statSync(src);
570
617
  if (stat.isDirectory()) {
571
- import_fs2.default.mkdirSync(dest, { recursive: true });
572
- for (const item of import_fs2.default.readdirSync(src)) {
573
- copyRecursive(import_path2.default.join(src, item), import_path2.default.join(dest, item));
618
+ import_fs3.default.mkdirSync(dest, { recursive: true });
619
+ for (const item of import_fs3.default.readdirSync(src)) {
620
+ copyRecursive(import_path3.default.join(src, item), import_path3.default.join(dest, item));
574
621
  }
575
622
  } else {
576
- const content = import_fs2.default.readFileSync(src, "utf8");
623
+ const content = import_fs3.default.readFileSync(src, "utf8");
577
624
  const template = import_handlebars.default.compile(content);
578
625
  const updated = template(values);
579
626
  const isOverridesFile = dest.endsWith("override.yaml");
580
- if (isOverridesFile && import_fs2.default.existsSync(dest)) {
627
+ if (isOverridesFile && import_fs3.default.existsSync(dest)) {
581
628
  log(` \u21B7 Skipped existing overrides file: ${dest}`);
582
629
  return;
583
630
  }
584
- import_fs2.default.writeFileSync(dest, updated, "utf8");
631
+ import_fs3.default.writeFileSync(dest, updated, "utf8");
585
632
  log(` \u2713 Created: ${dest}`);
586
633
  }
587
634
  }
@@ -592,36 +639,31 @@ function copyChartsValues(env, values) {
592
639
  `);
593
640
  }
594
641
  function generateInventory(env, values) {
595
- const templatePath = import_path2.default.join(
642
+ const templatePath = import_path3.default.join(
596
643
  __dirname,
597
644
  "templates",
598
645
  "inventory",
599
646
  "inventory.template.yml"
600
647
  );
601
- const outputPath = import_path2.default.join(
602
- process.cwd(),
603
- "infrastructure",
604
- "server-setup",
605
- "inventory",
606
- `${env}.yml`
607
- );
608
- const templateFile = import_fs2.default.readFileSync(templatePath, "utf-8");
648
+ const outputPath = import_path3.default.resolve(process.cwd(), getEnvironmentInventoryPath(env));
649
+ const templateFile = import_fs3.default.readFileSync(templatePath, "utf-8");
609
650
  const template = import_handlebars.default.compile(templateFile);
610
651
  values["single_node"] = values["kube_worker_nodes"].length > 0 || values["backup_host"] ? "false" : "true";
611
652
  const updated = template(values);
612
- import_fs2.default.mkdirSync(import_path2.default.dirname(outputPath), { recursive: true });
613
- import_fs2.default.writeFileSync(outputPath, updated);
653
+ import_fs3.default.mkdirSync(import_path3.default.dirname(outputPath), { recursive: true });
654
+ import_fs3.default.writeFileSync(outputPath, updated);
614
655
  log(`
615
656
  \u2705 Generated inventory file at ${outputPath}
616
657
  `);
617
658
  }
618
- var import_fs2, import_path2, import_handlebars;
659
+ var import_fs3, import_path3, import_handlebars;
619
660
  var init_templates = __esm({
620
661
  "src/environment/templates.ts"() {
621
662
  "use strict";
622
- import_fs2 = __toESM(require("fs"));
623
- import_path2 = __toESM(require("path"));
663
+ import_fs3 = __toESM(require("fs"));
664
+ import_path3 = __toESM(require("path"));
624
665
  init_logger();
666
+ init_paths();
625
667
  import_handlebars = __toESM(require("handlebars"));
626
668
  import_handlebars.default.registerHelper("data_label_idx", function(value) {
627
669
  return parseInt(value) + 2;
@@ -1237,7 +1279,7 @@ function getCurrentUserSSHKeys() {
1237
1279
  keys.push(keyContent);
1238
1280
  }
1239
1281
  }
1240
- } catch (error4) {
1282
+ } catch (error3) {
1241
1283
  continue;
1242
1284
  }
1243
1285
  }
@@ -1773,6 +1815,7 @@ var init_setup_environment = __esm({
1773
1815
  init_editor_questions();
1774
1816
  init_questions_helper();
1775
1817
  init_manage_users();
1818
+ init_paths();
1776
1819
  ALL_QUESTIONS = [];
1777
1820
  ALL_ANSWERS = [];
1778
1821
  ALL_QUESTIONS.push(
@@ -1936,9 +1979,7 @@ var init_setup_environment = __esm({
1936
1979
  );
1937
1980
  const kubeWorkerNodes = infrastructure.kubeWorkerNodes ? infrastructure.kubeWorkerNodes.split(",").map((ip) => ip.trim()) : [];
1938
1981
  log("\n", import_kleur4.default.bold().underline("SSH Users"), "\n");
1939
- const users = await manageUsers(
1940
- `infrastructure/server-setup/inventory/${environment}.yml`
1941
- );
1982
+ const users = await manageUsers(getEnvironmentInventoryPath(environment));
1942
1983
  log("\n", import_kleur4.default.bold().underline("Traefik SSL Certificate"), "\n");
1943
1984
  const sslCertExists = findExistingValue(
1944
1985
  "SSL_CRT",
@@ -2752,11 +2793,11 @@ __export(update_workflows_exports, {
2752
2793
  updateWorkflowEnvironments: () => updateWorkflowEnvironments
2753
2794
  });
2754
2795
  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"));
2796
+ const files = glob2.sync((0, import_path4.join)("environments", "*", INVENTORY_FILE_NAME));
2797
+ const infraEnvironments = files.map((file) => (0, import_path4.basename)((0, import_path4.dirname)(file)));
2757
2798
  if (infraEnvironments.length === 0) {
2758
2799
  console.log(
2759
- "\u26A0\uFE0F Warning: No environment directories found in infrastructure/server-setup/inventory/"
2800
+ `\u26A0\uFE0F Warning: No environment inventory files found at environments/*/${INVENTORY_FILE_NAME}`
2760
2801
  );
2761
2802
  return [];
2762
2803
  }
@@ -2766,8 +2807,8 @@ async function extractInfrastructureNames() {
2766
2807
  async function extractEnvironmentNames() {
2767
2808
  const entries = await (0, import_promises.readdir)("environments");
2768
2809
  const environments = entries.filter((entry) => {
2769
- const fullPath = (0, import_path3.join)("environments", entry);
2770
- return (0, import_fs3.statSync)(fullPath).isDirectory();
2810
+ const fullPath = (0, import_path4.join)("environments", entry);
2811
+ return (0, import_fs4.statSync)(fullPath).isDirectory();
2771
2812
  });
2772
2813
  if (environments.length === 0) {
2773
2814
  console.log(
@@ -2793,7 +2834,7 @@ async function updateWorkflows(envList, config) {
2793
2834
  const { workflows } = config;
2794
2835
  for (const workflowPath of workflows) {
2795
2836
  try {
2796
- const fileContents = (0, import_fs3.readFileSync)(workflowPath, "utf8");
2837
+ const fileContents = (0, import_fs4.readFileSync)(workflowPath, "utf8");
2797
2838
  const workflowData = yaml2.load(fileContents);
2798
2839
  if (!workflowData?.on?.workflow_dispatch?.inputs?.environment?.options) {
2799
2840
  throw new Error(
@@ -2801,15 +2842,15 @@ async function updateWorkflows(envList, config) {
2801
2842
  );
2802
2843
  }
2803
2844
  const updatedContent = updateOptionsInYaml(fileContents, envList);
2804
- (0, import_fs3.writeFileSync)(workflowPath, updatedContent, "utf8");
2845
+ (0, import_fs4.writeFileSync)(workflowPath, updatedContent, "utf8");
2805
2846
  log(` \u2713 Successfully updated ${workflowPath}`);
2806
- } catch (error4) {
2847
+ } catch (error3) {
2807
2848
  console.error(
2808
2849
  `
2809
2850
  \u26A0\uFE0F Error updating ${workflowPath} with environments: [${envList.join(", ")}]`
2810
2851
  );
2811
- console.error(`\u2717 Failed to update ${workflowPath}:`, error4);
2812
- throw error4;
2852
+ console.error(`\u2717 Failed to update ${workflowPath}:`, error3);
2853
+ throw error3;
2813
2854
  }
2814
2855
  }
2815
2856
  }
@@ -2850,21 +2891,111 @@ async function updateWorkflowEnvironments() {
2850
2891
  } else {
2851
2892
  log("\u2139\uFE0F No workflows were updated.");
2852
2893
  }
2853
- } catch (error4) {
2854
- console.error("\n\u274C Error updating workflows:", error4);
2894
+ } catch (error3) {
2895
+ console.error("\n\u274C Error updating workflows:", error3);
2855
2896
  process.exit(1);
2856
2897
  }
2857
2898
  }
2858
- var import_promises, import_fs3, import_path3, glob, yaml2;
2899
+ var import_promises, import_fs4, import_path4, glob2, yaml2;
2859
2900
  var init_update_workflows = __esm({
2860
2901
  "src/environment/update-workflows.ts"() {
2861
2902
  "use strict";
2862
2903
  import_promises = require("fs/promises");
2863
- import_fs3 = require("fs");
2864
- import_path3 = require("path");
2865
- glob = __toESM(require("glob"));
2904
+ import_fs4 = require("fs");
2905
+ import_path4 = require("path");
2906
+ glob2 = __toESM(require("glob"));
2866
2907
  yaml2 = __toESM(require("js-yaml"));
2867
2908
  init_logger();
2909
+ init_paths();
2910
+ }
2911
+ });
2912
+
2913
+ // src/environment/upgrade.ts
2914
+ var upgrade_exports = {};
2915
+ __export(upgrade_exports, {
2916
+ upgradeEnvironmentLayout: () => upgradeEnvironmentLayout
2917
+ });
2918
+ function moveFileIfDestinationMissing(sourcePath, destinationPath) {
2919
+ if (!(0, import_fs5.existsSync)(sourcePath)) {
2920
+ return false;
2921
+ }
2922
+ if ((0, import_fs5.existsSync)(destinationPath)) {
2923
+ warn(
2924
+ `\u26A0\uFE0F Skipped ${sourcePath}; destination already exists at ${destinationPath}`
2925
+ );
2926
+ return false;
2927
+ }
2928
+ (0, import_fs5.mkdirSync)((0, import_path5.dirname)(destinationPath), { recursive: true });
2929
+ (0, import_fs5.renameSync)(sourcePath, destinationPath);
2930
+ log(` \u2713 Moved ${sourcePath} -> ${destinationPath}`);
2931
+ return true;
2932
+ }
2933
+ function migrateInventoryFiles() {
2934
+ const oldInventoryFiles = findOldInventoryFiles();
2935
+ if (oldInventoryFiles.length === 0) {
2936
+ log(`\u2139\uFE0F No old inventory files found at ${OLD_INVENTORY_DIR}`);
2937
+ return false;
2938
+ }
2939
+ log(import_kleur5.default.bold("\nMigrating Ansible inventory files"));
2940
+ let didMoveInventory = false;
2941
+ for (const oldInventoryFile of oldInventoryFiles) {
2942
+ const environment = getEnvironmentNameFromOldInventoryPath(oldInventoryFile);
2943
+ didMoveInventory = moveFileIfDestinationMissing(
2944
+ oldInventoryFile,
2945
+ getEnvironmentInventoryPath(environment)
2946
+ ) || didMoveInventory;
2947
+ }
2948
+ try {
2949
+ if ((0, import_fs5.existsSync)(OLD_INVENTORY_DIR) && (0, import_fs5.readdirSync)(OLD_INVENTORY_DIR).length === 0) {
2950
+ (0, import_fs5.rmdirSync)(OLD_INVENTORY_DIR);
2951
+ log(` \u2713 Removed empty ${OLD_INVENTORY_DIR}`);
2952
+ }
2953
+ } catch {
2954
+ warn(`\u26A0\uFE0F Could not remove ${OLD_INVENTORY_DIR}; please review it manually`);
2955
+ }
2956
+ return didMoveInventory;
2957
+ }
2958
+ function migrateInventoryVarsFiles() {
2959
+ if (!(0, import_fs5.existsSync)("environments")) {
2960
+ return false;
2961
+ }
2962
+ log(import_kleur5.default.bold("\nMigrating optional inventory variable files"));
2963
+ let didMoveVars = false;
2964
+ for (const entry of (0, import_fs5.readdirSync)("environments")) {
2965
+ const environmentDir = (0, import_path5.join)("environments", entry);
2966
+ if (!(0, import_fs5.statSync)(environmentDir).isDirectory()) {
2967
+ continue;
2968
+ }
2969
+ didMoveVars = moveFileIfDestinationMissing(
2970
+ (0, import_path5.join)(environmentDir, "inventory.override.yml"),
2971
+ getEnvironmentInventoryVarsPath(entry)
2972
+ ) || didMoveVars;
2973
+ }
2974
+ if (!didMoveVars) {
2975
+ log(`\u2139\uFE0F No inventory override files found to rename to ${INVENTORY_VARS_FILE_NAME}`);
2976
+ }
2977
+ return didMoveVars;
2978
+ }
2979
+ async function upgradeEnvironmentLayout() {
2980
+ const didMoveInventory = migrateInventoryFiles();
2981
+ const didMoveVars = migrateInventoryVarsFiles();
2982
+ await updateWorkflowEnvironments();
2983
+ if (didMoveInventory || didMoveVars) {
2984
+ success("\n\u2705 Environment layout upgrade completed successfully.");
2985
+ return;
2986
+ }
2987
+ success("\n\u2705 Environment layout already uses the current structure.");
2988
+ }
2989
+ var import_fs5, import_path5, import_kleur5;
2990
+ var init_upgrade = __esm({
2991
+ "src/environment/upgrade.ts"() {
2992
+ "use strict";
2993
+ import_fs5 = require("fs");
2994
+ import_path5 = require("path");
2995
+ import_kleur5 = __toESM(require("kleur"));
2996
+ init_logger();
2997
+ init_paths();
2998
+ init_update_workflows();
2868
2999
  }
2869
3000
  });
2870
3001
 
@@ -2877,7 +3008,7 @@ async function select4(options) {
2877
3008
  const inquirer = await import("@inquirer/prompts");
2878
3009
  return inquirer.select(options);
2879
3010
  }
2880
- async function selectInventoryFile(dirPath = "./infrastructure/server-setup/inventory/") {
3011
+ async function selectInventoryFile(dirPath = "./environments") {
2881
3012
  if (!fs4.existsSync(dirPath)) {
2882
3013
  warn(`\u26A0\uFE0F No environment configuration directory found at ${dirPath}`);
2883
3014
  warn(
@@ -2885,22 +3016,20 @@ async function selectInventoryFile(dirPath = "./infrastructure/server-setup/inve
2885
3016
  );
2886
3017
  return null;
2887
3018
  }
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");
3019
+ const environments = fs4.readdirSync(dirPath).filter((entry) => {
3020
+ const filePath = path4.join(dirPath, entry);
3021
+ return fs4.statSync(filePath).isDirectory() && fs4.existsSync(getEnvironmentInventoryPath(entry));
2893
3022
  }).sort();
2894
- if (files.length === 0) {
3023
+ if (environments.length === 0) {
2895
3024
  warn(`\u26A0\uFE0F No environment configuration files found at ${dirPath}`);
2896
3025
  warn(
2897
3026
  "Hint: If this is a new infrastructure repository, run `opencrvs environment init` first."
2898
3027
  );
2899
3028
  return null;
2900
3029
  }
2901
- const choices = files.map((file) => ({
2902
- name: path4.basename(file, path4.extname(file)),
2903
- value: path4.join(dirPath, file)
3030
+ const choices = environments.map((environment) => ({
3031
+ name: environment,
3032
+ value: getEnvironmentInventoryPath(environment)
2904
3033
  }));
2905
3034
  const selectedFile = await select4({
2906
3035
  message: "Select environment (inventory file) to load users:",
@@ -2909,33 +3038,34 @@ async function selectInventoryFile(dirPath = "./infrastructure/server-setup/inve
2909
3038
  return selectedFile;
2910
3039
  }
2911
3040
  async function manageEnvironmentUsers() {
2912
- console.log("\n", import_kleur5.default.bold().underline("Manage users"), "\n");
3041
+ console.log("\n", import_kleur6.default.bold().underline("Manage users"), "\n");
2913
3042
  const inventory_file = await selectInventoryFile();
2914
3043
  if (!inventory_file) {
2915
3044
  return;
2916
3045
  }
2917
3046
  await manageUsers(inventory_file);
2918
3047
  }
2919
- var fs4, path4, import_kleur5;
3048
+ var fs4, path4, import_kleur6;
2920
3049
  var init_users = __esm({
2921
3050
  "src/environment/users.ts"() {
2922
3051
  "use strict";
2923
3052
  fs4 = __toESM(require("fs"));
2924
3053
  path4 = __toESM(require("path"));
2925
- import_kleur5 = __toESM(require("kleur"));
3054
+ import_kleur6 = __toESM(require("kleur"));
2926
3055
  init_manage_users();
2927
3056
  init_logger();
3057
+ init_paths();
2928
3058
  }
2929
3059
  });
2930
3060
 
2931
3061
  // src/environment/swarm-to-k8s.ts
2932
3062
  var swarm_to_k8s_exports = {};
2933
- var path5, import_kleur6, import_core2;
3063
+ var path5, import_kleur7, import_core2;
2934
3064
  var init_swarm_to_k8s = __esm({
2935
3065
  "src/environment/swarm-to-k8s.ts"() {
2936
3066
  "use strict";
2937
3067
  path5 = __toESM(require("path"));
2938
- import_kleur6 = __toESM(require("kleur"));
3068
+ import_kleur7 = __toESM(require("kleur"));
2939
3069
  init_logger();
2940
3070
  init_utils();
2941
3071
  init_templates();
@@ -2944,7 +3074,7 @@ var init_swarm_to_k8s = __esm({
2944
3074
  init_github();
2945
3075
  (async () => {
2946
3076
  log(
2947
- import_kleur6.default.bold(
3077
+ import_kleur7.default.bold(
2948
3078
  "------------------------------------------------\nOpenCRVS Infrastructure migration script: \nMigrating Swarm configurations to Kubernetes\n------------------------------------------------\n"
2949
3079
  )
2950
3080
  );
@@ -2975,7 +3105,7 @@ var init_swarm_to_k8s = __esm({
2975
3105
  );
2976
3106
  process.exit(0);
2977
3107
  }
2978
- log(import_kleur6.default.bold().underline("Migration properties:"));
3108
+ log(import_kleur7.default.bold().underline("Migration properties:"));
2979
3109
  log(` \u2713 Environment: ${environment}`);
2980
3110
  const old_inventory_path = process.env.OLD_INVENTORY_PATH || "";
2981
3111
  if (!old_inventory_path) {
@@ -3293,8 +3423,9 @@ async function runUpgrade(dockerSwarm) {
3293
3423
  }
3294
3424
 
3295
3425
  // src/environment/index.ts
3296
- var import_fs4 = require("fs");
3297
- var import_path4 = require("path");
3426
+ var import_fs6 = require("fs");
3427
+ var import_path6 = require("path");
3428
+ init_paths();
3298
3429
  var REQUIRED_REPOSITORY_DIRECTORIES = [
3299
3430
  ".github/workflows",
3300
3431
  "environments",
@@ -3304,7 +3435,7 @@ function validateRepositoryStructure(repositoryRoot = process.cwd()) {
3304
3435
  const missingDirectories = REQUIRED_REPOSITORY_DIRECTORIES.filter(
3305
3436
  (directory) => {
3306
3437
  try {
3307
- return !(0, import_fs4.statSync)((0, import_path4.resolve)(repositoryRoot, directory)).isDirectory();
3438
+ return !(0, import_fs6.statSync)((0, import_path6.resolve)(repositoryRoot, directory)).isDirectory();
3308
3439
  } catch {
3309
3440
  return true;
3310
3441
  }
@@ -3318,8 +3449,14 @@ function validateRepositoryStructure(repositoryRoot = process.cwd()) {
3318
3449
  }
3319
3450
  async function runEnvironmentInit() {
3320
3451
  validateRepositoryStructure();
3452
+ assertNoOldInventoryLayout();
3321
3453
  await Promise.resolve().then(() => (init_setup_environment(), setup_environment_exports));
3322
3454
  }
3455
+ async function runEnvironmentUpgrade() {
3456
+ validateRepositoryStructure();
3457
+ const { upgradeEnvironmentLayout: upgradeEnvironmentLayout2 } = await Promise.resolve().then(() => (init_upgrade(), upgrade_exports));
3458
+ await upgradeEnvironmentLayout2();
3459
+ }
3323
3460
  async function runEnvironmentUpdateWorkflows() {
3324
3461
  validateRepositoryStructure();
3325
3462
  const { updateWorkflowEnvironments: updateWorkflowEnvironments2 } = await Promise.resolve().then(() => (init_update_workflows(), update_workflows_exports));
@@ -3389,6 +3526,7 @@ Usage: opencrvs environment <subcommand>
3389
3526
 
3390
3527
  Subcommands:
3391
3528
  init Initialise a new environment
3529
+ upgrade Upgrade existing environment configuration layout
3392
3530
  update-workflows Update workflow environment options
3393
3531
  users Manage environment users
3394
3532
  swarm-to-k8s Migrate Docker Swarm configuration to Kubernetes
@@ -3399,6 +3537,8 @@ Subcommands:
3399
3537
  switch (subcommand) {
3400
3538
  case "init":
3401
3539
  return runEnvironmentCommand("initialisation", runEnvironmentInit);
3540
+ case "upgrade":
3541
+ return runEnvironmentCommand("environment upgrade", runEnvironmentUpgrade);
3402
3542
  case "update-workflows":
3403
3543
  return runEnvironmentCommand(
3404
3544
  "workflow update",
@@ -3419,10 +3559,10 @@ Subcommands:
3419
3559
  async function runEnvironmentCommand(operation, command) {
3420
3560
  try {
3421
3561
  await command();
3422
- } catch (error4) {
3562
+ } catch (error3) {
3423
3563
  console.error(
3424
3564
  `Environment ${operation} failed:`,
3425
- error4 instanceof Error ? error4.message : error4
3565
+ error3 instanceof Error ? error3.message : error3
3426
3566
  );
3427
3567
  process.exit(1);
3428
3568
  }
@@ -3448,8 +3588,8 @@ async function handleUpgrade() {
3448
3588
  try {
3449
3589
  await runUpgrade(dockerSwarm);
3450
3590
  console.log("Upgrade completed successfully!");
3451
- } catch (error4) {
3452
- console.error("Upgrade failed:", error4);
3591
+ } catch (error3) {
3592
+ console.error("Upgrade failed:", error3);
3453
3593
  process.exit(1);
3454
3594
  }
3455
3595
  }