@opencrvs/toolkit 2.1.0-rc.c498f10 → 2.1.0-rc.c8d2a48

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.
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
  ```
package/dist/cli.js CHANGED
@@ -30,6 +30,49 @@ 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 findOldInventoryFiles() {
41
+ return glob.sync((0, import_path2.join)(OLD_INVENTORY_DIR, "*.yml")).sort();
42
+ }
43
+ function getEnvironmentNameFromOldInventoryPath(filePath) {
44
+ return (0, import_path2.basename)(filePath, ".yml");
45
+ }
46
+ function hasOldInventoryLayout() {
47
+ return findOldInventoryFiles().length > 0;
48
+ }
49
+ function assertNoOldInventoryLayout() {
50
+ if (!hasOldInventoryLayout()) {
51
+ return;
52
+ }
53
+ throw new Error(
54
+ [
55
+ `Old inventory layout detected at ${OLD_INVENTORY_DIR}.`,
56
+ "Please run `yarn environment:upgrade` before running `yarn environment:init`."
57
+ ].join(" ")
58
+ );
59
+ }
60
+ var import_fs, import_path2, glob, OLD_INVENTORY_DIR, INVENTORY_FILE_NAME;
61
+ var init_paths = __esm({
62
+ "src/environment/paths.ts"() {
63
+ "use strict";
64
+ import_fs = require("fs");
65
+ import_path2 = require("path");
66
+ glob = __toESM(require("glob"));
67
+ OLD_INVENTORY_DIR = (0, import_path2.join)(
68
+ "infrastructure",
69
+ "server-setup",
70
+ "inventory"
71
+ );
72
+ INVENTORY_FILE_NAME = "inventory.yml";
73
+ }
74
+ });
75
+
33
76
  // src/environment/logger.ts
34
77
  var import_kleur, log, warn, success, info, error;
35
78
  var init_logger = __esm({
@@ -471,9 +514,9 @@ function storeSecrets(environment, answers) {
471
514
  let envConfig = {};
472
515
  try {
473
516
  envConfig = import_dotenv.default.parse(
474
- (0, import_fs.readFileSync)(`${process.cwd()}/.env.${environment}`)
517
+ (0, import_fs2.readFileSync)(`${process.cwd()}/.env.${environment}`)
475
518
  );
476
- } catch (error4) {
519
+ } catch (error3) {
477
520
  envConfig = {};
478
521
  }
479
522
  const linesFromAnswers = answers.map(
@@ -481,10 +524,10 @@ function storeSecrets(environment, answers) {
481
524
  );
482
525
  const linesFromEnvConfig = Object.entries(envConfig).filter(([name]) => !answers.find((update) => update.name === name)).map(([name, value]) => `${name}="${value}"`);
483
526
  const allLines = [...linesFromEnvConfig, ...linesFromAnswers].sort();
484
- (0, import_fs.writeFileSync)(`.env.${environment}`, allLines.join("\n"));
527
+ (0, import_fs2.writeFileSync)(`.env.${environment}`, allLines.join("\n"));
485
528
  }
486
529
  function readYamlFile(filePath) {
487
- const fileContent = import_fs.default.readFileSync(filePath, "utf8");
530
+ const fileContent = import_fs2.default.readFileSync(filePath, "utf8");
488
531
  return yaml.load(fileContent);
489
532
  }
490
533
  function writeYamlFile(filePath, data) {
@@ -497,16 +540,16 @@ function writeYamlFile(filePath, data) {
497
540
  noRefs: true,
498
541
  sortKeys: false
499
542
  });
500
- import_fs.default.writeFileSync(filePath, yamlContent, "utf8");
501
- } catch (error4) {
502
- throw new Error(`Failed to write inventory file: ${error4}`);
543
+ import_fs2.default.writeFileSync(filePath, yamlContent, "utf8");
544
+ } catch (error3) {
545
+ throw new Error(`Failed to write inventory file: ${error3}`);
503
546
  }
504
547
  }
505
- var import_fs, yaml, import_dotenv;
548
+ var import_fs2, yaml, import_dotenv;
506
549
  var init_utils = __esm({
507
550
  "src/environment/utils.ts"() {
508
551
  "use strict";
509
- import_fs = __toESM(require("fs"));
552
+ import_fs2 = __toESM(require("fs"));
510
553
  yaml = __toESM(require("js-yaml"));
511
554
  import_dotenv = __toESM(require("dotenv"));
512
555
  }
@@ -559,29 +602,29 @@ function extractWorkerNodes(data) {
559
602
  return worker_hosts;
560
603
  }
561
604
  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 });
605
+ const srcDir = import_path3.default.resolve(__dirname, "templates", "charts-values");
606
+ const destDir = import_path3.default.resolve(process.cwd(), "environments", env);
607
+ import_fs3.default.mkdirSync(destDir, { recursive: true });
565
608
  values["lets_encrypt"] = values["traefik_mode"] === "lets_encrypt";
566
609
  values["static_ssl"] = values["traefik_mode"] === "static_ssl";
567
610
  values["opencrvs_environment"] = env;
568
611
  function copyRecursive(src, dest) {
569
- const stat = import_fs2.default.statSync(src);
612
+ const stat = import_fs3.default.statSync(src);
570
613
  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));
614
+ import_fs3.default.mkdirSync(dest, { recursive: true });
615
+ for (const item of import_fs3.default.readdirSync(src)) {
616
+ copyRecursive(import_path3.default.join(src, item), import_path3.default.join(dest, item));
574
617
  }
575
618
  } else {
576
- const content = import_fs2.default.readFileSync(src, "utf8");
619
+ const content = import_fs3.default.readFileSync(src, "utf8");
577
620
  const template = import_handlebars.default.compile(content);
578
621
  const updated = template(values);
579
622
  const isOverridesFile = dest.endsWith("override.yaml");
580
- if (isOverridesFile && import_fs2.default.existsSync(dest)) {
623
+ if (isOverridesFile && import_fs3.default.existsSync(dest)) {
581
624
  log(` \u21B7 Skipped existing overrides file: ${dest}`);
582
625
  return;
583
626
  }
584
- import_fs2.default.writeFileSync(dest, updated, "utf8");
627
+ import_fs3.default.writeFileSync(dest, updated, "utf8");
585
628
  log(` \u2713 Created: ${dest}`);
586
629
  }
587
630
  }
@@ -592,36 +635,31 @@ function copyChartsValues(env, values) {
592
635
  `);
593
636
  }
594
637
  function generateInventory(env, values) {
595
- const templatePath = import_path2.default.join(
638
+ const templatePath = import_path3.default.join(
596
639
  __dirname,
597
640
  "templates",
598
641
  "inventory",
599
642
  "inventory.template.yml"
600
643
  );
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");
644
+ const outputPath = import_path3.default.resolve(process.cwd(), getEnvironmentInventoryPath(env));
645
+ const templateFile = import_fs3.default.readFileSync(templatePath, "utf-8");
609
646
  const template = import_handlebars.default.compile(templateFile);
610
647
  values["single_node"] = values["kube_worker_nodes"].length > 0 || values["backup_host"] ? "false" : "true";
611
648
  const updated = template(values);
612
- import_fs2.default.mkdirSync(import_path2.default.dirname(outputPath), { recursive: true });
613
- import_fs2.default.writeFileSync(outputPath, updated);
649
+ import_fs3.default.mkdirSync(import_path3.default.dirname(outputPath), { recursive: true });
650
+ import_fs3.default.writeFileSync(outputPath, updated);
614
651
  log(`
615
652
  \u2705 Generated inventory file at ${outputPath}
616
653
  `);
617
654
  }
618
- var import_fs2, import_path2, import_handlebars;
655
+ var import_fs3, import_path3, import_handlebars;
619
656
  var init_templates = __esm({
620
657
  "src/environment/templates.ts"() {
621
658
  "use strict";
622
- import_fs2 = __toESM(require("fs"));
623
- import_path2 = __toESM(require("path"));
659
+ import_fs3 = __toESM(require("fs"));
660
+ import_path3 = __toESM(require("path"));
624
661
  init_logger();
662
+ init_paths();
625
663
  import_handlebars = __toESM(require("handlebars"));
626
664
  import_handlebars.default.registerHelper("data_label_idx", function(value) {
627
665
  return parseInt(value) + 2;
@@ -1237,7 +1275,7 @@ function getCurrentUserSSHKeys() {
1237
1275
  keys.push(keyContent);
1238
1276
  }
1239
1277
  }
1240
- } catch (error4) {
1278
+ } catch (error3) {
1241
1279
  continue;
1242
1280
  }
1243
1281
  }
@@ -1773,6 +1811,7 @@ var init_setup_environment = __esm({
1773
1811
  init_editor_questions();
1774
1812
  init_questions_helper();
1775
1813
  init_manage_users();
1814
+ init_paths();
1776
1815
  ALL_QUESTIONS = [];
1777
1816
  ALL_ANSWERS = [];
1778
1817
  ALL_QUESTIONS.push(
@@ -1936,9 +1975,7 @@ var init_setup_environment = __esm({
1936
1975
  );
1937
1976
  const kubeWorkerNodes = infrastructure.kubeWorkerNodes ? infrastructure.kubeWorkerNodes.split(",").map((ip) => ip.trim()) : [];
1938
1977
  log("\n", import_kleur4.default.bold().underline("SSH Users"), "\n");
1939
- const users = await manageUsers(
1940
- `infrastructure/server-setup/inventory/${environment}.yml`
1941
- );
1978
+ const users = await manageUsers(getEnvironmentInventoryPath(environment));
1942
1979
  log("\n", import_kleur4.default.bold().underline("Traefik SSL Certificate"), "\n");
1943
1980
  const sslCertExists = findExistingValue(
1944
1981
  "SSL_CRT",
@@ -2752,11 +2789,11 @@ __export(update_workflows_exports, {
2752
2789
  updateWorkflowEnvironments: () => updateWorkflowEnvironments
2753
2790
  });
2754
2791
  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"));
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)));
2757
2794
  if (infraEnvironments.length === 0) {
2758
2795
  console.log(
2759
- "\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}`
2760
2797
  );
2761
2798
  return [];
2762
2799
  }
@@ -2766,8 +2803,8 @@ async function extractInfrastructureNames() {
2766
2803
  async function extractEnvironmentNames() {
2767
2804
  const entries = await (0, import_promises.readdir)("environments");
2768
2805
  const environments = entries.filter((entry) => {
2769
- const fullPath = (0, import_path3.join)("environments", entry);
2770
- return (0, import_fs3.statSync)(fullPath).isDirectory();
2806
+ const fullPath = (0, import_path4.join)("environments", entry);
2807
+ return (0, import_fs4.statSync)(fullPath).isDirectory();
2771
2808
  });
2772
2809
  if (environments.length === 0) {
2773
2810
  console.log(
@@ -2793,7 +2830,7 @@ async function updateWorkflows(envList, config) {
2793
2830
  const { workflows } = config;
2794
2831
  for (const workflowPath of workflows) {
2795
2832
  try {
2796
- const fileContents = (0, import_fs3.readFileSync)(workflowPath, "utf8");
2833
+ const fileContents = (0, import_fs4.readFileSync)(workflowPath, "utf8");
2797
2834
  const workflowData = yaml2.load(fileContents);
2798
2835
  if (!workflowData?.on?.workflow_dispatch?.inputs?.environment?.options) {
2799
2836
  throw new Error(
@@ -2801,15 +2838,15 @@ async function updateWorkflows(envList, config) {
2801
2838
  );
2802
2839
  }
2803
2840
  const updatedContent = updateOptionsInYaml(fileContents, envList);
2804
- (0, import_fs3.writeFileSync)(workflowPath, updatedContent, "utf8");
2841
+ (0, import_fs4.writeFileSync)(workflowPath, updatedContent, "utf8");
2805
2842
  log(` \u2713 Successfully updated ${workflowPath}`);
2806
- } catch (error4) {
2843
+ } catch (error3) {
2807
2844
  console.error(
2808
2845
  `
2809
2846
  \u26A0\uFE0F Error updating ${workflowPath} with environments: [${envList.join(", ")}]`
2810
2847
  );
2811
- console.error(`\u2717 Failed to update ${workflowPath}:`, error4);
2812
- throw error4;
2848
+ console.error(`\u2717 Failed to update ${workflowPath}:`, error3);
2849
+ throw error3;
2813
2850
  }
2814
2851
  }
2815
2852
  }
@@ -2850,21 +2887,89 @@ async function updateWorkflowEnvironments() {
2850
2887
  } else {
2851
2888
  log("\u2139\uFE0F No workflows were updated.");
2852
2889
  }
2853
- } catch (error4) {
2854
- console.error("\n\u274C Error updating workflows:", error4);
2890
+ } catch (error3) {
2891
+ console.error("\n\u274C Error updating workflows:", error3);
2855
2892
  process.exit(1);
2856
2893
  }
2857
2894
  }
2858
- var import_promises, import_fs3, import_path3, glob, yaml2;
2895
+ var import_promises, import_fs4, import_path4, glob2, yaml2;
2859
2896
  var init_update_workflows = __esm({
2860
2897
  "src/environment/update-workflows.ts"() {
2861
2898
  "use strict";
2862
2899
  import_promises = require("fs/promises");
2863
- import_fs3 = require("fs");
2864
- import_path3 = require("path");
2865
- glob = __toESM(require("glob"));
2900
+ import_fs4 = require("fs");
2901
+ import_path4 = require("path");
2902
+ glob2 = __toESM(require("glob"));
2866
2903
  yaml2 = __toESM(require("js-yaml"));
2867
2904
  init_logger();
2905
+ init_paths();
2906
+ }
2907
+ });
2908
+
2909
+ // src/environment/upgrade.ts
2910
+ var upgrade_exports = {};
2911
+ __export(upgrade_exports, {
2912
+ upgradeEnvironmentLayout: () => upgradeEnvironmentLayout
2913
+ });
2914
+ function moveFileIfDestinationMissing(sourcePath, destinationPath) {
2915
+ if (!(0, import_fs5.existsSync)(sourcePath)) {
2916
+ return false;
2917
+ }
2918
+ if ((0, import_fs5.existsSync)(destinationPath)) {
2919
+ warn(
2920
+ `\u26A0\uFE0F Skipped ${sourcePath}; destination already exists at ${destinationPath}`
2921
+ );
2922
+ return false;
2923
+ }
2924
+ (0, import_fs5.mkdirSync)((0, import_path5.dirname)(destinationPath), { recursive: true });
2925
+ (0, import_fs5.renameSync)(sourcePath, destinationPath);
2926
+ log(` \u2713 Moved ${sourcePath} -> ${destinationPath}`);
2927
+ return true;
2928
+ }
2929
+ function migrateInventoryFiles() {
2930
+ const oldInventoryFiles = findOldInventoryFiles();
2931
+ if (oldInventoryFiles.length === 0) {
2932
+ log(`\u2139\uFE0F No old inventory files found at ${OLD_INVENTORY_DIR}`);
2933
+ return false;
2934
+ }
2935
+ log(import_kleur5.default.bold("\nMigrating Ansible inventory files"));
2936
+ let didMoveInventory = false;
2937
+ for (const oldInventoryFile of oldInventoryFiles) {
2938
+ const environment = getEnvironmentNameFromOldInventoryPath(oldInventoryFile);
2939
+ didMoveInventory = moveFileIfDestinationMissing(
2940
+ oldInventoryFile,
2941
+ getEnvironmentInventoryPath(environment)
2942
+ ) || didMoveInventory;
2943
+ }
2944
+ try {
2945
+ if ((0, import_fs5.existsSync)(OLD_INVENTORY_DIR) && (0, import_fs5.readdirSync)(OLD_INVENTORY_DIR).length === 0) {
2946
+ (0, import_fs5.rmdirSync)(OLD_INVENTORY_DIR);
2947
+ log(` \u2713 Removed empty ${OLD_INVENTORY_DIR}`);
2948
+ }
2949
+ } catch {
2950
+ warn(`\u26A0\uFE0F Could not remove ${OLD_INVENTORY_DIR}; please review it manually`);
2951
+ }
2952
+ return didMoveInventory;
2953
+ }
2954
+ async function upgradeEnvironmentLayout() {
2955
+ const didMoveInventory = migrateInventoryFiles();
2956
+ await updateWorkflowEnvironments();
2957
+ if (didMoveInventory) {
2958
+ success("\n\u2705 Environment layout upgrade completed successfully.");
2959
+ return;
2960
+ }
2961
+ success("\n\u2705 Environment layout already uses the current structure.");
2962
+ }
2963
+ var import_fs5, import_path5, import_kleur5;
2964
+ var init_upgrade = __esm({
2965
+ "src/environment/upgrade.ts"() {
2966
+ "use strict";
2967
+ import_fs5 = require("fs");
2968
+ import_path5 = require("path");
2969
+ import_kleur5 = __toESM(require("kleur"));
2970
+ init_logger();
2971
+ init_paths();
2972
+ init_update_workflows();
2868
2973
  }
2869
2974
  });
2870
2975
 
@@ -2877,7 +2982,7 @@ async function select4(options) {
2877
2982
  const inquirer = await import("@inquirer/prompts");
2878
2983
  return inquirer.select(options);
2879
2984
  }
2880
- async function selectInventoryFile(dirPath = "./infrastructure/server-setup/inventory/") {
2985
+ async function selectInventoryFile(dirPath = "./environments") {
2881
2986
  if (!fs4.existsSync(dirPath)) {
2882
2987
  warn(`\u26A0\uFE0F No environment configuration directory found at ${dirPath}`);
2883
2988
  warn(
@@ -2885,22 +2990,20 @@ async function selectInventoryFile(dirPath = "./infrastructure/server-setup/inve
2885
2990
  );
2886
2991
  return null;
2887
2992
  }
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");
2993
+ const environments = fs4.readdirSync(dirPath).filter((entry) => {
2994
+ const filePath = path4.join(dirPath, entry);
2995
+ return fs4.statSync(filePath).isDirectory() && fs4.existsSync(getEnvironmentInventoryPath(entry));
2893
2996
  }).sort();
2894
- if (files.length === 0) {
2997
+ if (environments.length === 0) {
2895
2998
  warn(`\u26A0\uFE0F No environment configuration files found at ${dirPath}`);
2896
2999
  warn(
2897
3000
  "Hint: If this is a new infrastructure repository, run `opencrvs environment init` first."
2898
3001
  );
2899
3002
  return null;
2900
3003
  }
2901
- const choices = files.map((file) => ({
2902
- name: path4.basename(file, path4.extname(file)),
2903
- value: path4.join(dirPath, file)
3004
+ const choices = environments.map((environment) => ({
3005
+ name: environment,
3006
+ value: getEnvironmentInventoryPath(environment)
2904
3007
  }));
2905
3008
  const selectedFile = await select4({
2906
3009
  message: "Select environment (inventory file) to load users:",
@@ -2909,33 +3012,34 @@ async function selectInventoryFile(dirPath = "./infrastructure/server-setup/inve
2909
3012
  return selectedFile;
2910
3013
  }
2911
3014
  async function manageEnvironmentUsers() {
2912
- console.log("\n", import_kleur5.default.bold().underline("Manage users"), "\n");
3015
+ console.log("\n", import_kleur6.default.bold().underline("Manage users"), "\n");
2913
3016
  const inventory_file = await selectInventoryFile();
2914
3017
  if (!inventory_file) {
2915
3018
  return;
2916
3019
  }
2917
3020
  await manageUsers(inventory_file);
2918
3021
  }
2919
- var fs4, path4, import_kleur5;
3022
+ var fs4, path4, import_kleur6;
2920
3023
  var init_users = __esm({
2921
3024
  "src/environment/users.ts"() {
2922
3025
  "use strict";
2923
3026
  fs4 = __toESM(require("fs"));
2924
3027
  path4 = __toESM(require("path"));
2925
- import_kleur5 = __toESM(require("kleur"));
3028
+ import_kleur6 = __toESM(require("kleur"));
2926
3029
  init_manage_users();
2927
3030
  init_logger();
3031
+ init_paths();
2928
3032
  }
2929
3033
  });
2930
3034
 
2931
3035
  // src/environment/swarm-to-k8s.ts
2932
3036
  var swarm_to_k8s_exports = {};
2933
- var path5, import_kleur6, import_core2;
3037
+ var path5, import_kleur7, import_core2;
2934
3038
  var init_swarm_to_k8s = __esm({
2935
3039
  "src/environment/swarm-to-k8s.ts"() {
2936
3040
  "use strict";
2937
3041
  path5 = __toESM(require("path"));
2938
- import_kleur6 = __toESM(require("kleur"));
3042
+ import_kleur7 = __toESM(require("kleur"));
2939
3043
  init_logger();
2940
3044
  init_utils();
2941
3045
  init_templates();
@@ -2944,7 +3048,7 @@ var init_swarm_to_k8s = __esm({
2944
3048
  init_github();
2945
3049
  (async () => {
2946
3050
  log(
2947
- import_kleur6.default.bold(
3051
+ import_kleur7.default.bold(
2948
3052
  "------------------------------------------------\nOpenCRVS Infrastructure migration script: \nMigrating Swarm configurations to Kubernetes\n------------------------------------------------\n"
2949
3053
  )
2950
3054
  );
@@ -2975,7 +3079,7 @@ var init_swarm_to_k8s = __esm({
2975
3079
  );
2976
3080
  process.exit(0);
2977
3081
  }
2978
- log(import_kleur6.default.bold().underline("Migration properties:"));
3082
+ log(import_kleur7.default.bold().underline("Migration properties:"));
2979
3083
  log(` \u2713 Environment: ${environment}`);
2980
3084
  const old_inventory_path = process.env.OLD_INVENTORY_PATH || "";
2981
3085
  if (!old_inventory_path) {
@@ -3293,8 +3397,9 @@ async function runUpgrade(dockerSwarm) {
3293
3397
  }
3294
3398
 
3295
3399
  // src/environment/index.ts
3296
- var import_fs4 = require("fs");
3297
- var import_path4 = require("path");
3400
+ var import_fs6 = require("fs");
3401
+ var import_path6 = require("path");
3402
+ init_paths();
3298
3403
  var REQUIRED_REPOSITORY_DIRECTORIES = [
3299
3404
  ".github/workflows",
3300
3405
  "environments",
@@ -3304,7 +3409,7 @@ function validateRepositoryStructure(repositoryRoot = process.cwd()) {
3304
3409
  const missingDirectories = REQUIRED_REPOSITORY_DIRECTORIES.filter(
3305
3410
  (directory) => {
3306
3411
  try {
3307
- return !(0, import_fs4.statSync)((0, import_path4.resolve)(repositoryRoot, directory)).isDirectory();
3412
+ return !(0, import_fs6.statSync)((0, import_path6.resolve)(repositoryRoot, directory)).isDirectory();
3308
3413
  } catch {
3309
3414
  return true;
3310
3415
  }
@@ -3318,8 +3423,14 @@ function validateRepositoryStructure(repositoryRoot = process.cwd()) {
3318
3423
  }
3319
3424
  async function runEnvironmentInit() {
3320
3425
  validateRepositoryStructure();
3426
+ assertNoOldInventoryLayout();
3321
3427
  await Promise.resolve().then(() => (init_setup_environment(), setup_environment_exports));
3322
3428
  }
3429
+ async function runEnvironmentUpgrade() {
3430
+ validateRepositoryStructure();
3431
+ const { upgradeEnvironmentLayout: upgradeEnvironmentLayout2 } = await Promise.resolve().then(() => (init_upgrade(), upgrade_exports));
3432
+ await upgradeEnvironmentLayout2();
3433
+ }
3323
3434
  async function runEnvironmentUpdateWorkflows() {
3324
3435
  validateRepositoryStructure();
3325
3436
  const { updateWorkflowEnvironments: updateWorkflowEnvironments2 } = await Promise.resolve().then(() => (init_update_workflows(), update_workflows_exports));
@@ -3389,6 +3500,7 @@ Usage: opencrvs environment <subcommand>
3389
3500
 
3390
3501
  Subcommands:
3391
3502
  init Initialise a new environment
3503
+ upgrade Upgrade existing environment configuration layout
3392
3504
  update-workflows Update workflow environment options
3393
3505
  users Manage environment users
3394
3506
  swarm-to-k8s Migrate Docker Swarm configuration to Kubernetes
@@ -3399,6 +3511,8 @@ Subcommands:
3399
3511
  switch (subcommand) {
3400
3512
  case "init":
3401
3513
  return runEnvironmentCommand("initialisation", runEnvironmentInit);
3514
+ case "upgrade":
3515
+ return runEnvironmentCommand("environment upgrade", runEnvironmentUpgrade);
3402
3516
  case "update-workflows":
3403
3517
  return runEnvironmentCommand(
3404
3518
  "workflow update",
@@ -3419,10 +3533,10 @@ Subcommands:
3419
3533
  async function runEnvironmentCommand(operation, command) {
3420
3534
  try {
3421
3535
  await command();
3422
- } catch (error4) {
3536
+ } catch (error3) {
3423
3537
  console.error(
3424
3538
  `Environment ${operation} failed:`,
3425
- error4 instanceof Error ? error4.message : error4
3539
+ error3 instanceof Error ? error3.message : error3
3426
3540
  );
3427
3541
  process.exit(1);
3428
3542
  }
@@ -3448,8 +3562,8 @@ async function handleUpgrade() {
3448
3562
  try {
3449
3563
  await runUpgrade(dockerSwarm);
3450
3564
  console.log("Upgrade completed successfully!");
3451
- } catch (error4) {
3452
- console.error("Upgrade failed:", error4);
3565
+ } catch (error3) {
3566
+ console.error("Upgrade failed:", error3);
3453
3567
  process.exit(1);
3454
3568
  }
3455
3569
  }
@@ -8351,8 +8351,15 @@ export declare const appRouter: import("@trpc/server").TRPCBuiltRouter<{
8351
8351
  name: string;
8352
8352
  externalId?: string | null | undefined;
8353
8353
  administrativeAreaId: (string & import("zod").$brand<"UUID">) | null;
8354
- validUntil: string | null;
8355
8354
  locationType: string | null;
8355
+ status: "active" | "inactive";
8356
+ versions: {
8357
+ versionId: string & import("zod").$brand<"UUID">;
8358
+ effectiveFrom: string;
8359
+ name: string;
8360
+ externalId?: string | null | undefined;
8361
+ status: "active" | "inactive";
8362
+ }[];
8356
8363
  }[];
8357
8364
  meta: object;
8358
8365
  }>;
@@ -8362,7 +8369,6 @@ export declare const appRouter: import("@trpc/server").TRPCBuiltRouter<{
8362
8369
  name: string;
8363
8370
  externalId?: string | null | undefined;
8364
8371
  administrativeAreaId: string | null;
8365
- validUntil: string | null;
8366
8372
  locationType: string | null;
8367
8373
  }[];
8368
8374
  output: void;
@@ -8377,8 +8383,15 @@ export declare const appRouter: import("@trpc/server").TRPCBuiltRouter<{
8377
8383
  name: string;
8378
8384
  externalId?: string | null | undefined;
8379
8385
  administrativeAreaId: (string & import("zod").$brand<"UUID">) | null;
8380
- validUntil: string | null;
8381
8386
  locationType: string | null;
8387
+ status: "active" | "inactive";
8388
+ versions: {
8389
+ versionId: string & import("zod").$brand<"UUID">;
8390
+ effectiveFrom: string;
8391
+ name: string;
8392
+ externalId?: string | null | undefined;
8393
+ status: "active" | "inactive";
8394
+ }[];
8382
8395
  };
8383
8396
  meta: import("trpc-to-openapi").OpenApiMeta;
8384
8397
  }>;
@@ -8786,7 +8799,14 @@ export declare const appRouter: import("@trpc/server").TRPCBuiltRouter<{
8786
8799
  name: string;
8787
8800
  externalId?: string | null | undefined;
8788
8801
  parentId: (string & import("zod").$brand<"UUID">) | null;
8789
- validUntil: string | null;
8802
+ status: "active" | "inactive";
8803
+ versions: {
8804
+ versionId: string & import("zod").$brand<"UUID">;
8805
+ effectiveFrom: string;
8806
+ name: string;
8807
+ externalId?: string | null | undefined;
8808
+ status: "active" | "inactive";
8809
+ }[];
8790
8810
  }[];
8791
8811
  meta: import("trpc-to-openapi").OpenApiMeta;
8792
8812
  }>;
@@ -8796,7 +8816,6 @@ export declare const appRouter: import("@trpc/server").TRPCBuiltRouter<{
8796
8816
  name: string;
8797
8817
  externalId?: string | null | undefined;
8798
8818
  parentId: string | null;
8799
- validUntil: string | null;
8800
8819
  }[];
8801
8820
  output: void;
8802
8821
  meta: object;