@opencrvs/toolkit 2.1.0 → 2.1.1-rc.52250d8

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/dist/cli.js CHANGED
@@ -32,13 +32,13 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
32
32
 
33
33
  // src/environment/paths.ts
34
34
  function getEnvironmentInventoryPath(environment) {
35
- return (0, import_path11.join)("environments", environment, INVENTORY_FILE_NAME);
35
+ return (0, import_path12.join)("environments", environment, INVENTORY_FILE_NAME);
36
36
  }
37
37
  function findOldInventoryFiles() {
38
- return glob.sync((0, import_path11.join)(OLD_INVENTORY_DIR, "*.yml")).sort();
38
+ return glob.sync((0, import_path12.join)(OLD_INVENTORY_DIR, "*.yml")).sort();
39
39
  }
40
40
  function getEnvironmentNameFromOldInventoryPath(filePath) {
41
- return (0, import_path11.basename)(filePath, ".yml");
41
+ return (0, import_path12.basename)(filePath, ".yml");
42
42
  }
43
43
  function assertNoOldInventoryLayout() {
44
44
  if (findOldInventoryFiles().length === 0) {
@@ -51,13 +51,13 @@ function assertNoOldInventoryLayout() {
51
51
  ].join(" ")
52
52
  );
53
53
  }
54
- var import_path11, glob, OLD_INVENTORY_DIR, INVENTORY_FILE_NAME;
54
+ var import_path12, glob, OLD_INVENTORY_DIR, INVENTORY_FILE_NAME;
55
55
  var init_paths = __esm({
56
56
  "src/environment/paths.ts"() {
57
57
  "use strict";
58
- import_path11 = require("path");
58
+ import_path12 = require("path");
59
59
  glob = __toESM(require("glob"));
60
- OLD_INVENTORY_DIR = (0, import_path11.join)(
60
+ OLD_INVENTORY_DIR = (0, import_path12.join)(
61
61
  "infrastructure",
62
62
  "server-setup",
63
63
  "inventory"
@@ -479,12 +479,33 @@ var init_derived_variables = __esm({
479
479
  type: "disabled",
480
480
  scope: "ENVIRONMENT"
481
481
  },
482
+ {
483
+ name: "RESTORE_ENVIRONMENT_MODE",
484
+ valueLabel: "RESTORE_ENVIRONMENT_MODE",
485
+ valueType: "VARIABLE",
486
+ type: "disabled",
487
+ scope: "ENVIRONMENT"
488
+ },
489
+ {
490
+ name: "RESTORE_HOST",
491
+ valueLabel: "RESTORE_HOST",
492
+ valueType: "VARIABLE",
493
+ type: "disabled",
494
+ scope: "ENVIRONMENT"
495
+ },
482
496
  {
483
497
  name: "NOTIFICATION_TRANSPORT",
484
498
  valueLabel: "NOTIFICATION_TRANSPORT",
485
499
  valueType: "VARIABLE",
486
500
  type: "disabled",
487
501
  scope: "ENVIRONMENT"
502
+ },
503
+ {
504
+ name: "TWO_FA_ENABLED",
505
+ valueLabel: "TWO_FA_ENABLED",
506
+ valueType: "VARIABLE",
507
+ type: "disabled",
508
+ scope: "ENVIRONMENT"
488
509
  }
489
510
  ];
490
511
  }
@@ -504,7 +525,7 @@ function findExistingValue(name, type, scope, existingValues) {
504
525
  );
505
526
  }
506
527
  function readYamlFile(filePath) {
507
- const fileContent = import_fs9.default.readFileSync(filePath, "utf8");
528
+ const fileContent = import_fs10.default.readFileSync(filePath, "utf8");
508
529
  return yaml.load(fileContent);
509
530
  }
510
531
  function writeYamlFile(filePath, data) {
@@ -517,16 +538,16 @@ function writeYamlFile(filePath, data) {
517
538
  noRefs: true,
518
539
  sortKeys: false
519
540
  });
520
- import_fs9.default.writeFileSync(filePath, yamlContent, "utf8");
541
+ import_fs10.default.writeFileSync(filePath, yamlContent, "utf8");
521
542
  } catch (error3) {
522
543
  throw new Error(`Failed to write inventory file: ${error3}`);
523
544
  }
524
545
  }
525
- var import_fs9, yaml;
546
+ var import_fs10, yaml;
526
547
  var init_utils = __esm({
527
548
  "src/environment/utils.ts"() {
528
549
  "use strict";
529
- import_fs9 = __toESM(require("fs"));
550
+ import_fs10 = __toESM(require("fs"));
530
551
  yaml = __toESM(require("js-yaml"));
531
552
  }
532
553
  });
@@ -575,29 +596,29 @@ function extractWorkerNodes(data) {
575
596
  return worker_hosts;
576
597
  }
577
598
  function copyChartsValues(env, values) {
578
- const srcDir = import_path12.default.resolve(__dirname, "templates", "charts-values");
579
- const destDir = import_path12.default.resolve(process.cwd(), "environments", env);
580
- import_fs10.default.mkdirSync(destDir, { recursive: true });
599
+ const srcDir = import_path13.default.resolve(__dirname, "templates", "charts-values");
600
+ const destDir = import_path13.default.resolve(process.cwd(), "environments", env);
601
+ import_fs11.default.mkdirSync(destDir, { recursive: true });
581
602
  values["lets_encrypt"] = values["traefik_mode"] === "lets_encrypt";
582
603
  values["static_ssl"] = values["traefik_mode"] === "static_ssl";
583
604
  values["opencrvs_environment"] = env;
584
605
  function copyRecursive(src, dest) {
585
- const stat = import_fs10.default.statSync(src);
606
+ const stat = import_fs11.default.statSync(src);
586
607
  if (stat.isDirectory()) {
587
- import_fs10.default.mkdirSync(dest, { recursive: true });
588
- for (const item of import_fs10.default.readdirSync(src)) {
589
- copyRecursive(import_path12.default.join(src, item), import_path12.default.join(dest, item));
608
+ import_fs11.default.mkdirSync(dest, { recursive: true });
609
+ for (const item of import_fs11.default.readdirSync(src)) {
610
+ copyRecursive(import_path13.default.join(src, item), import_path13.default.join(dest, item));
590
611
  }
591
612
  } else {
592
- const content = import_fs10.default.readFileSync(src, "utf8");
613
+ const content = import_fs11.default.readFileSync(src, "utf8");
593
614
  const template = import_handlebars.default.compile(content);
594
615
  const updated = template(values);
595
616
  const isOverridesFile = dest.endsWith("override.yaml");
596
- if (isOverridesFile && import_fs10.default.existsSync(dest)) {
617
+ if (isOverridesFile && import_fs11.default.existsSync(dest)) {
597
618
  log(` \u21B7 Skipped existing overrides file: ${dest}`);
598
619
  return;
599
620
  }
600
- import_fs10.default.writeFileSync(dest, updated, "utf8");
621
+ import_fs11.default.writeFileSync(dest, updated, "utf8");
601
622
  log(` \u2713 Created: ${dest}`);
602
623
  }
603
624
  }
@@ -608,29 +629,29 @@ function copyChartsValues(env, values) {
608
629
  `);
609
630
  }
610
631
  function generateInventory(env, values) {
611
- const templatePath = import_path12.default.join(
632
+ const templatePath = import_path13.default.join(
612
633
  __dirname,
613
634
  "templates",
614
635
  "inventory",
615
636
  "inventory.template.yml"
616
637
  );
617
- const outputPath = import_path12.default.resolve(process.cwd(), getEnvironmentInventoryPath(env));
618
- const templateFile = import_fs10.default.readFileSync(templatePath, "utf-8");
638
+ const outputPath = import_path13.default.resolve(process.cwd(), getEnvironmentInventoryPath(env));
639
+ const templateFile = import_fs11.default.readFileSync(templatePath, "utf-8");
619
640
  const template = import_handlebars.default.compile(templateFile);
620
641
  values["single_node"] = values["kube_worker_nodes"].length > 0 || values["backup_host"] ? "false" : "true";
621
642
  const updated = template(values);
622
- import_fs10.default.mkdirSync(import_path12.default.dirname(outputPath), { recursive: true });
623
- import_fs10.default.writeFileSync(outputPath, updated);
643
+ import_fs11.default.mkdirSync(import_path13.default.dirname(outputPath), { recursive: true });
644
+ import_fs11.default.writeFileSync(outputPath, updated);
624
645
  log(`
625
646
  \u2705 Generated inventory file at ${outputPath}
626
647
  `);
627
648
  }
628
- var import_fs10, import_path12, import_handlebars;
649
+ var import_fs11, import_path13, import_handlebars;
629
650
  var init_templates = __esm({
630
651
  "src/environment/templates.ts"() {
631
652
  "use strict";
632
- import_fs10 = __toESM(require("fs"));
633
- import_path12 = __toESM(require("path"));
653
+ import_fs11 = __toESM(require("fs"));
654
+ import_path13 = __toESM(require("path"));
634
655
  init_logger();
635
656
  init_paths();
636
657
  import_handlebars = __toESM(require("handlebars"));
@@ -661,16 +682,16 @@ var update_workflows_exports = {};
661
682
  __export(update_workflows_exports, {
662
683
  updateWorkflowEnvironments: () => updateWorkflowEnvironments
663
684
  });
664
- function isDirectory(path14) {
685
+ function isDirectory(path15) {
665
686
  try {
666
- return (0, import_fs11.statSync)(path14).isDirectory();
687
+ return (0, import_fs12.statSync)(path15).isDirectory();
667
688
  } catch {
668
689
  return false;
669
690
  }
670
691
  }
671
692
  async function extractInfrastructureNames() {
672
- const files = glob2.sync((0, import_path13.join)("environments", "*", INVENTORY_FILE_NAME));
673
- const infraEnvironments = files.map((file) => (0, import_path13.basename)((0, import_path13.dirname)(file)));
693
+ const files = glob2.sync((0, import_path14.join)("environments", "*", INVENTORY_FILE_NAME));
694
+ const infraEnvironments = files.map((file) => (0, import_path14.basename)((0, import_path14.dirname)(file)));
674
695
  if (infraEnvironments.length === 0) {
675
696
  console.log(
676
697
  `\u26A0\uFE0F Warning: No environment inventory files found at environments/*/${INVENTORY_FILE_NAME}`
@@ -683,9 +704,9 @@ async function extractInfrastructureNames() {
683
704
  async function extractEnvironmentNames() {
684
705
  const entries = await (0, import_promises.readdir)("environments");
685
706
  const environments = entries.filter((entry) => {
686
- const environmentPath = (0, import_path13.join)("environments", entry);
687
- const opencrvsServicesPath = (0, import_path13.join)(environmentPath, "opencrvs-services");
688
- return isDirectory(environmentPath) && (0, import_fs11.existsSync)(opencrvsServicesPath) && isDirectory(opencrvsServicesPath);
707
+ const environmentPath = (0, import_path14.join)("environments", entry);
708
+ const opencrvsServicesPath = (0, import_path14.join)(environmentPath, "opencrvs-services");
709
+ return isDirectory(environmentPath) && (0, import_fs12.existsSync)(opencrvsServicesPath) && isDirectory(opencrvsServicesPath);
689
710
  });
690
711
  if (environments.length === 0) {
691
712
  console.log(
@@ -710,12 +731,12 @@ function updateOptionsInYaml(content, envList) {
710
731
  async function updateWorkflows(envList, config) {
711
732
  const { workflows } = config;
712
733
  for (const workflowPath of workflows) {
713
- if (!(0, import_fs11.existsSync)(workflowPath)) {
734
+ if (!(0, import_fs12.existsSync)(workflowPath)) {
714
735
  log(` \u21B7 Skipped ${workflowPath} (not found in this repository)`);
715
736
  continue;
716
737
  }
717
738
  try {
718
- const fileContents = (0, import_fs11.readFileSync)(workflowPath, "utf8");
739
+ const fileContents = (0, import_fs12.readFileSync)(workflowPath, "utf8");
719
740
  const workflowData = yaml2.load(fileContents);
720
741
  if (!workflowData?.on?.workflow_dispatch?.inputs?.environment?.options) {
721
742
  throw new Error(
@@ -723,7 +744,7 @@ async function updateWorkflows(envList, config) {
723
744
  );
724
745
  }
725
746
  const updatedContent = updateOptionsInYaml(fileContents, envList);
726
- (0, import_fs11.writeFileSync)(workflowPath, updatedContent, "utf8");
747
+ (0, import_fs12.writeFileSync)(workflowPath, updatedContent, "utf8");
727
748
  log(` \u2713 Successfully updated ${workflowPath}`);
728
749
  } catch (error3) {
729
750
  console.error(
@@ -777,13 +798,13 @@ async function updateWorkflowEnvironments() {
777
798
  process.exit(1);
778
799
  }
779
800
  }
780
- var import_promises, import_fs11, import_path13, glob2, yaml2;
801
+ var import_promises, import_fs12, import_path14, glob2, yaml2;
781
802
  var init_update_workflows = __esm({
782
803
  "src/environment/update-workflows.ts"() {
783
804
  "use strict";
784
805
  import_promises = require("fs/promises");
785
- import_fs11 = require("fs");
786
- import_path13 = require("path");
806
+ import_fs12 = require("fs");
807
+ import_path14 = require("path");
787
808
  glob2 = __toESM(require("glob"));
788
809
  yaml2 = __toESM(require("js-yaml"));
789
810
  init_logger();
@@ -1079,13 +1100,14 @@ var init_questions = __esm({
1079
1100
  {
1080
1101
  name: "diskSpace",
1081
1102
  type: "text",
1082
- message: `What is the amount of diskspace that should be dedicated to OpenCRVS data and will become the size of an encrypted cryptfs data directory.
1083
-
1084
- ${import_kleur2.default.red("DO NOT USE ALL DISKSPACE FOR OPENCRVS!")}
1085
-
1086
- Leave at least 50g available for OS use.`,
1103
+ message: [
1104
+ "How much disk space should be reserved for OpenCRVS data on each node? (e.g. 200g)",
1105
+ "A fixed-size encrypted volume of this size is created on every node and cannot be resized later.",
1106
+ import_kleur2.default.red("DO NOT USE ALL DISK SPACE FOR OPENCRVS!"),
1107
+ "Each node needs this much free space on its root partition, plus 50g or 10% of this size, whichever is larger."
1108
+ ].join("\n"),
1087
1109
  valueType: "VARIABLE",
1088
- validate: notEmpty,
1110
+ validate: (value) => /^\d+g$/i.test(value.trim()) || "Enter a size in gigabytes, e.g. 200g",
1089
1111
  valueLabel: "DISK_SPACE",
1090
1112
  initial: process.env.DISK_SPACE || "200g",
1091
1113
  scope: "ENVIRONMENT"
@@ -1372,7 +1394,7 @@ function getCurrentUsername() {
1372
1394
  }
1373
1395
  function getCurrentUserSSHKeys() {
1374
1396
  const homeDir = os.homedir();
1375
- const sshDir = path11.join(homeDir, ".ssh");
1397
+ const sshDir = path12.join(homeDir, ".ssh");
1376
1398
  const keys = [];
1377
1399
  const keyFiles = [
1378
1400
  "id_rsa.pub",
@@ -1381,7 +1403,7 @@ function getCurrentUserSSHKeys() {
1381
1403
  "id_dsa.pub"
1382
1404
  ];
1383
1405
  for (const keyFile of keyFiles) {
1384
- const keyPath = path11.join(sshDir, keyFile);
1406
+ const keyPath = path12.join(sshDir, keyFile);
1385
1407
  try {
1386
1408
  if (fs3.existsSync(keyPath)) {
1387
1409
  const keyContent = fs3.readFileSync(keyPath, "utf8").trim();
@@ -1722,13 +1744,13 @@ async function manageUsers(inventoryPath) {
1722
1744
  }
1723
1745
  return users;
1724
1746
  }
1725
- var os, fs3, path11, input2, select2, confirm, editor, checkbox;
1747
+ var os, fs3, path12, input2, select2, confirm, editor, checkbox;
1726
1748
  var init_manage_users = __esm({
1727
1749
  "src/environment/manage-users.ts"() {
1728
1750
  "use strict";
1729
1751
  os = __toESM(require("os"));
1730
1752
  fs3 = __toESM(require("fs"));
1731
- path11 = __toESM(require("path"));
1753
+ path12 = __toESM(require("path"));
1732
1754
  init_logger();
1733
1755
  init_utils();
1734
1756
  init_templates();
@@ -1976,16 +1998,6 @@ async function runSetupEnvironment() {
1976
1998
  ]
1977
1999
  });
1978
2000
  }
1979
- log("\n", import_kleur4.default.bold().underline("Two-factor authentication (2FA)"));
1980
- const two_fa_enabled = await confirm2({
1981
- message: "Enable two-factor authentication (2FA)? This should be enabled for any environment that hosts PII data.",
1982
- default: process.env.TWO_FA_ENABLED ? process.env.TWO_FA_ENABLED === "true" : environment_type === "production"
1983
- });
1984
- if (!two_fa_enabled && ["production", "staging"].includes(environment_type)) {
1985
- warn(
1986
- "2FA is disabled on a production-like environment. Logins will accept the fixed test code 000000, exposing real citizen data. Only do this if you know what you are doing."
1987
- );
1988
- }
1989
2001
  const environment_exists = existingEnvironments.map((e) => e.trim()).includes(environment);
1990
2002
  if (!environment) {
1991
2003
  process.exit(1);
@@ -2049,6 +2061,23 @@ async function runSetupEnvironment() {
2049
2061
  );
2050
2062
  await promptAndStoreAnswer(githubOtherQuestions, existingValues);
2051
2063
  }
2064
+ log("\n", import_kleur4.default.bold().underline("Two-factor authentication (2FA)"));
2065
+ const existingTwoFaEnabled = findExistingValue(
2066
+ "TWO_FA_ENABLED",
2067
+ "VARIABLE",
2068
+ "ENVIRONMENT",
2069
+ existingValues
2070
+ );
2071
+ const twoFaDefault = process.env.TWO_FA_ENABLED || existingTwoFaEnabled?.value;
2072
+ const two_fa_enabled = await confirm2({
2073
+ message: "Enable two-factor authentication (2FA)? This should be enabled for any environment that hosts PII data.",
2074
+ default: twoFaDefault ? twoFaDefault === "true" : environment_type === "production"
2075
+ });
2076
+ if (!two_fa_enabled && ["production", "staging"].includes(environment_type)) {
2077
+ warn(
2078
+ "2FA is disabled on a production-like environment. Logins will accept the fixed test code 000000, exposing real citizen data. Only do this if you know what you are doing."
2079
+ );
2080
+ }
2052
2081
  log("\n", import_kleur4.default.bold().underline("Docker Hub"));
2053
2082
  await promptAndStoreAnswer(dockerhubQuestions, existingValues);
2054
2083
  log("\n", import_kleur4.default.bold().underline("Kubernetes & Runtime"));
@@ -2214,6 +2243,7 @@ async function runSetupEnvironment() {
2214
2243
  });
2215
2244
  restoreType = await select3({
2216
2245
  message: `Select ${import_kleur4.default.yellow().bold(restoreEnvironmentName)} environment backup mode`,
2246
+ default: restoreType,
2217
2247
  choices: [
2218
2248
  {
2219
2249
  name: "Full dump (daily full database backup)",
@@ -2303,6 +2333,14 @@ async function runSetupEnvironment() {
2303
2333
  ),
2304
2334
  scope: "ENVIRONMENT"
2305
2335
  });
2336
+ derivedUpdates.push({
2337
+ name: "TWO_FA_ENABLED",
2338
+ type: "VARIABLE",
2339
+ didExist: existingTwoFaEnabled,
2340
+ // Always stored, so the next run defaults to the current answer
2341
+ value: two_fa_enabled ? "true" : "false",
2342
+ scope: "ENVIRONMENT"
2343
+ });
2306
2344
  derivedUpdates.push(...ssl_answers);
2307
2345
  if (configureBackup) {
2308
2346
  derivedUpdates.push({
@@ -2576,6 +2614,19 @@ async function runSetupEnvironment() {
2576
2614
  existingValues
2577
2615
  ),
2578
2616
  scope: "ENVIRONMENT"
2617
+ },
2618
+ {
2619
+ type: "VARIABLE",
2620
+ name: "RESTORE_ENVIRONMENT_MODE",
2621
+ // Only persist the mode when restore is configured
2622
+ value: restoreEnvironmentName ? restoreType : "",
2623
+ didExist: findExistingValue(
2624
+ "RESTORE_ENVIRONMENT_MODE",
2625
+ "VARIABLE",
2626
+ "ENVIRONMENT",
2627
+ existingValues
2628
+ ),
2629
+ scope: "ENVIRONMENT"
2579
2630
  }
2580
2631
  ];
2581
2632
  if (enableEncryption) {
@@ -2932,17 +2983,17 @@ __export(upgrade_exports, {
2932
2983
  upgradeEnvironmentLayout: () => upgradeEnvironmentLayout
2933
2984
  });
2934
2985
  function moveFileIfDestinationMissing(sourcePath, destinationPath) {
2935
- if (!(0, import_fs12.existsSync)(sourcePath)) {
2986
+ if (!(0, import_fs13.existsSync)(sourcePath)) {
2936
2987
  return false;
2937
2988
  }
2938
- if ((0, import_fs12.existsSync)(destinationPath)) {
2989
+ if ((0, import_fs13.existsSync)(destinationPath)) {
2939
2990
  warn(
2940
2991
  `\u26A0\uFE0F Skipped ${sourcePath}; destination already exists at ${destinationPath}`
2941
2992
  );
2942
2993
  return false;
2943
2994
  }
2944
- (0, import_fs12.mkdirSync)((0, import_path14.dirname)(destinationPath), { recursive: true });
2945
- (0, import_fs12.renameSync)(sourcePath, destinationPath);
2995
+ (0, import_fs13.mkdirSync)((0, import_path15.dirname)(destinationPath), { recursive: true });
2996
+ (0, import_fs13.renameSync)(sourcePath, destinationPath);
2946
2997
  log(` \u2713 Moved ${sourcePath} -> ${destinationPath}`);
2947
2998
  return true;
2948
2999
  }
@@ -2962,8 +3013,8 @@ function migrateInventoryFiles() {
2962
3013
  ) || didMoveInventory;
2963
3014
  }
2964
3015
  try {
2965
- if ((0, import_fs12.existsSync)(OLD_INVENTORY_DIR) && (0, import_fs12.readdirSync)(OLD_INVENTORY_DIR).length === 0) {
2966
- (0, import_fs12.rmdirSync)(OLD_INVENTORY_DIR);
3016
+ if ((0, import_fs13.existsSync)(OLD_INVENTORY_DIR) && (0, import_fs13.readdirSync)(OLD_INVENTORY_DIR).length === 0) {
3017
+ (0, import_fs13.rmdirSync)(OLD_INVENTORY_DIR);
2967
3018
  log(` \u2713 Removed empty ${OLD_INVENTORY_DIR}`);
2968
3019
  }
2969
3020
  } catch {
@@ -2981,12 +3032,12 @@ async function upgradeEnvironmentLayout() {
2981
3032
  }
2982
3033
  log("\nCommit changes into git after upgrade");
2983
3034
  }
2984
- var import_fs12, import_path14, import_kleur5;
3035
+ var import_fs13, import_path15, import_kleur5;
2985
3036
  var init_upgrade = __esm({
2986
3037
  "src/environment/upgrade.ts"() {
2987
3038
  "use strict";
2988
- import_fs12 = require("fs");
2989
- import_path14 = require("path");
3039
+ import_fs13 = require("fs");
3040
+ import_path15 = require("path");
2990
3041
  import_kleur5 = __toESM(require("kleur"));
2991
3042
  init_logger();
2992
3043
  init_paths();
@@ -3012,7 +3063,7 @@ async function selectInventoryFile(dirPath = "./environments") {
3012
3063
  return null;
3013
3064
  }
3014
3065
  const environments = fs4.readdirSync(dirPath).filter((entry) => {
3015
- const filePath = path12.join(dirPath, entry);
3066
+ const filePath = path13.join(dirPath, entry);
3016
3067
  return fs4.statSync(filePath).isDirectory() && fs4.existsSync(getEnvironmentInventoryPath(entry));
3017
3068
  }).sort();
3018
3069
  if (environments.length === 0) {
@@ -3040,12 +3091,12 @@ async function manageEnvironmentUsers() {
3040
3091
  }
3041
3092
  await manageUsers(inventory_file);
3042
3093
  }
3043
- var fs4, path12, import_kleur6;
3094
+ var fs4, path13, import_kleur6;
3044
3095
  var init_users = __esm({
3045
3096
  "src/environment/users.ts"() {
3046
3097
  "use strict";
3047
3098
  fs4 = __toESM(require("fs"));
3048
- path12 = __toESM(require("path"));
3099
+ path13 = __toESM(require("path"));
3049
3100
  import_kleur6 = __toESM(require("kleur"));
3050
3101
  init_manage_users();
3051
3102
  init_logger();
@@ -3055,11 +3106,11 @@ var init_users = __esm({
3055
3106
 
3056
3107
  // src/environment/swarm-to-k8s.ts
3057
3108
  var swarm_to_k8s_exports = {};
3058
- var path13, import_kleur7, import_core2;
3109
+ var path14, import_kleur7, import_core2;
3059
3110
  var init_swarm_to_k8s = __esm({
3060
3111
  "src/environment/swarm-to-k8s.ts"() {
3061
3112
  "use strict";
3062
- path13 = __toESM(require("path"));
3113
+ path14 = __toESM(require("path"));
3063
3114
  import_kleur7 = __toESM(require("kleur"));
3064
3115
  init_logger();
3065
3116
  init_utils();
@@ -3111,7 +3162,7 @@ var init_swarm_to_k8s = __esm({
3111
3162
  );
3112
3163
  process.exit(1);
3113
3164
  }
3114
- const ansible_inventory = path13.join(old_inventory_path, environment + ".yml");
3165
+ const ansible_inventory = path14.join(old_inventory_path, environment + ".yml");
3115
3166
  const data = readYamlFile(ansible_inventory);
3116
3167
  log(` \u2713 Loaded old inventory file: ${ansible_inventory}`);
3117
3168
  const master = dockerManagerFirst(data) || "";
@@ -3454,20 +3505,20 @@ function idOf(line2) {
3454
3505
  const comma = line2.indexOf(",");
3455
3506
  return comma === -1 ? line2 : line2.slice(0, comma);
3456
3507
  }
3457
- function readCsvFile(path14) {
3458
- if (!(0, import_fs.existsSync)(path14)) {
3508
+ function readCsvFile(path15) {
3509
+ if (!(0, import_fs.existsSync)(path15)) {
3459
3510
  return void 0;
3460
3511
  }
3461
- const contents = (0, import_fs.readFileSync)(path14, "utf8");
3512
+ const contents = (0, import_fs.readFileSync)(path15, "utf8");
3462
3513
  const newline = contents.includes("\r\n") ? "\r\n" : "\n";
3463
3514
  const trailingNewline = /\r?\n$/.test(contents);
3464
3515
  const lines = contents.replace(/\r?\n$/, "").split(/\r?\n/);
3465
3516
  const body = lines.slice(1).filter((line2) => line2 !== "");
3466
3517
  return { header: lines[0], body, newline, trailingNewline };
3467
3518
  }
3468
- function writeCsvFile(path14, file) {
3519
+ function writeCsvFile(path15, file) {
3469
3520
  (0, import_fs.writeFileSync)(
3470
- path14,
3521
+ path15,
3471
3522
  [file.header, ...file.body].join(file.newline) + (file.trailingNewline ? file.newline : "")
3472
3523
  );
3473
3524
  }
@@ -5108,9 +5159,71 @@ async function main7() {
5108
5159
  }
5109
5160
  }
5110
5161
 
5162
+ // src/migrations/v2.1/remove-typings-from-dockerfile.ts
5163
+ var import_fs8 = require("fs");
5164
+ var import_path9 = __toESM(require("path"));
5165
+ var DOCKERFILE = "Dockerfile";
5166
+ var TYPINGS_PATH = /^(?:\.\/)?typings(?:\/.*)?$/;
5167
+ var continues = (line2) => !/^\s*#/.test(line2) && /\\[ \t]*\r?\n?$/.test(line2);
5168
+ function contextSources(line2, continued) {
5169
+ const [instruction, ...args2] = line2.split(/[\s"',[\]]+/).filter(Boolean);
5170
+ if (!/^(?:COPY|ADD)$/i.test(instruction) || args2.some((arg) => arg.startsWith("--from"))) {
5171
+ return [];
5172
+ }
5173
+ const paths = args2.filter((arg) => arg !== "\\" && !arg.startsWith("--"));
5174
+ return continued ? paths : paths.slice(0, -1);
5175
+ }
5176
+ function removeTypingsCopy(dockerfile) {
5177
+ const kept = [];
5178
+ const removed = [];
5179
+ const unresolved = [];
5180
+ let previousCarriesOn = false;
5181
+ const lines = dockerfile.match(/[^\n]*\n|[^\n]+$/g) ?? [];
5182
+ for (const line2 of lines) {
5183
+ const startsInstruction = !previousCarriesOn;
5184
+ const carriesOn = continues(line2);
5185
+ previousCarriesOn = carriesOn;
5186
+ const sources = startsInstruction ? contextSources(line2, carriesOn) : [];
5187
+ if (!sources.some((source) => TYPINGS_PATH.test(source))) {
5188
+ kept.push(line2);
5189
+ } else if (sources.length === 1 && !carriesOn) {
5190
+ removed.push(line2.trim());
5191
+ } else {
5192
+ kept.push(line2);
5193
+ unresolved.push(line2.trim());
5194
+ }
5195
+ }
5196
+ return { contents: kept.join(""), removed, unresolved };
5197
+ }
5198
+ function removeTypingsFromDockerfile(cwd) {
5199
+ const dockerfilePath = import_path9.default.join(cwd, DOCKERFILE);
5200
+ if (!(0, import_fs8.existsSync)(dockerfilePath)) return;
5201
+ const { contents, removed, unresolved } = removeTypingsCopy(
5202
+ (0, import_fs8.readFileSync)(dockerfilePath, "utf8")
5203
+ );
5204
+ if (removed.length === 0 && unresolved.length === 0) return;
5205
+ console.log("\nUpdating the Dockerfile...\n");
5206
+ if (removed.length > 0) {
5207
+ (0, import_fs8.writeFileSync)(dockerfilePath, contents);
5208
+ }
5209
+ for (const instruction of removed) {
5210
+ console.log(
5211
+ ` \u2713 ${DOCKERFILE}: removed '${instruction}', the Tiltfile no longer sends typings/ to the image build`
5212
+ );
5213
+ }
5214
+ for (const instruction of unresolved) {
5215
+ console.warn(
5216
+ ` \u26A0\uFE0F ${DOCKERFILE} still copies from typings/ ('${instruction}'), which the Tiltfile no longer sends to the image build; remove it by hand`
5217
+ );
5218
+ }
5219
+ }
5220
+ async function main8() {
5221
+ removeTypingsFromDockerfile(process.cwd());
5222
+ }
5223
+
5111
5224
  // src/migrations/v2.1/rename-trigger-paths.ts
5112
5225
  var import_ts_morph5 = require("ts-morph");
5113
- var import_path9 = __toESM(require("path"));
5226
+ var import_path10 = __toESM(require("path"));
5114
5227
  var PATH_PREFIX_RENAMES = {
5115
5228
  "/triggers/user/": "/trigger/user/",
5116
5229
  "/triggers/system/": "/trigger/system/"
@@ -5168,7 +5281,7 @@ function processFile2(filePath, project) {
5168
5281
  const sourceFile = project.getSourceFile(filePath);
5169
5282
  if (!sourceFile) return 0;
5170
5283
  let renamedCount = 0;
5171
- const relPath = import_path9.default.relative(process.cwd(), filePath);
5284
+ const relPath = import_path10.default.relative(process.cwd(), filePath);
5172
5285
  const candidates = sourceFile.getDescendantsOfKind(
5173
5286
  import_ts_morph5.SyntaxKind.ObjectLiteralExpression
5174
5287
  );
@@ -5185,7 +5298,7 @@ function processFile2(filePath, project) {
5185
5298
  function warnAboutStalePaths(sourceFiles) {
5186
5299
  const stale = [];
5187
5300
  for (const sourceFile of sourceFiles) {
5188
- const relPath = import_path9.default.relative(process.cwd(), sourceFile.getFilePath());
5301
+ const relPath = import_path10.default.relative(process.cwd(), sourceFile.getFilePath());
5189
5302
  const lines = sourceFile.getFullText().split("\n");
5190
5303
  lines.forEach((line2, index) => {
5191
5304
  if (line2.includes(STALE_PREFIX)) {
@@ -5200,8 +5313,8 @@ WARNING: ${stale.length} remaining '${STALE_PREFIX}' reference(s) need to be ren
5200
5313
  );
5201
5314
  console.log(stale.join("\n"));
5202
5315
  }
5203
- async function main8() {
5204
- const srcDir = import_path9.default.join(process.cwd(), "src");
5316
+ async function main9() {
5317
+ const srcDir = import_path10.default.join(process.cwd(), "src");
5205
5318
  console.log(`Scanning for Hapi route configs in: ${srcDir}
5206
5319
  `);
5207
5320
  console.log("Active path renames:");
@@ -5210,7 +5323,7 @@ async function main8() {
5210
5323
  }
5211
5324
  console.log();
5212
5325
  const project = new import_ts_morph5.Project({
5213
- tsConfigFilePath: import_path9.default.resolve(srcDir, "../tsconfig.json"),
5326
+ tsConfigFilePath: import_path10.default.resolve(srcDir, "../tsconfig.json"),
5214
5327
  skipAddingFilesFromTsConfig: false
5215
5328
  });
5216
5329
  const sourceFiles = project.getSourceFiles().filter((sf) => {
@@ -5237,7 +5350,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
5237
5350
  for (const filePath of modifiedFiles) {
5238
5351
  const sourceFile = project.getSourceFileOrThrow(filePath);
5239
5352
  await sourceFile.save();
5240
- console.log(` Saved: ${import_path9.default.relative(process.cwd(), filePath)}`);
5353
+ console.log(` Saved: ${import_path10.default.relative(process.cwd(), filePath)}`);
5241
5354
  }
5242
5355
  console.log(`
5243
5356
  Done. Renamed ${totalRenamed} route path(s).`);
@@ -5246,21 +5359,21 @@ Done. Renamed ${totalRenamed} route path(s).`);
5246
5359
  }
5247
5360
 
5248
5361
  // src/migrations/v2.1/upgrade-tilt.ts
5249
- var import_fs8 = require("fs");
5250
- var import_path10 = __toESM(require("path"));
5362
+ var import_fs9 = require("fs");
5363
+ var import_path11 = __toESM(require("path"));
5251
5364
  var COUNTRY_OWNED_DIR = "tilt/helm/";
5252
5365
  var CHARTS_CHECKOUT_DIR = ".opencrvs-core-charts";
5253
5366
  var IMAGE_NAME_PATTERN = /^countryconfig_image_name\s*=\s*(["'])(.*?)\1/m;
5254
5367
  function writeIfChanged(cwd, relativePath, contents, mode) {
5255
- const target = import_path10.default.join(cwd, relativePath);
5256
- const existed = (0, import_fs8.existsSync)(target);
5257
- if (existed && (0, import_fs8.readFileSync)(target, "utf8") === contents) {
5368
+ const target = import_path11.default.join(cwd, relativePath);
5369
+ const existed = (0, import_fs9.existsSync)(target);
5370
+ if (existed && (0, import_fs9.readFileSync)(target, "utf8") === contents) {
5258
5371
  return "unchanged";
5259
5372
  }
5260
- (0, import_fs8.mkdirSync)(import_path10.default.dirname(target), { recursive: true });
5261
- (0, import_fs8.writeFileSync)(target, contents);
5373
+ (0, import_fs9.mkdirSync)(import_path11.default.dirname(target), { recursive: true });
5374
+ (0, import_fs9.writeFileSync)(target, contents);
5262
5375
  if (mode !== void 0) {
5263
- (0, import_fs8.chmodSync)(target, mode & 511);
5376
+ (0, import_fs9.chmodSync)(target, mode & 511);
5264
5377
  }
5265
5378
  return existed ? "updated" : "created";
5266
5379
  }
@@ -5290,29 +5403,29 @@ function withIgnoreEntry(contents, line2) {
5290
5403
  `;
5291
5404
  }
5292
5405
  function ensureIgnored(cwd, file, line2) {
5293
- const target = import_path10.default.join(cwd, file);
5294
- const contents = (0, import_fs8.existsSync)(target) ? (0, import_fs8.readFileSync)(target, "utf8") : "";
5406
+ const target = import_path11.default.join(cwd, file);
5407
+ const contents = (0, import_fs9.existsSync)(target) ? (0, import_fs9.readFileSync)(target, "utf8") : "";
5295
5408
  report(file, writeIfChanged(cwd, file, withIgnoreEntry(contents, line2)));
5296
5409
  }
5297
5410
  function upgradeTilt(cwd, templateDir) {
5298
- const tiltfilePath = import_path10.default.join(cwd, "Tiltfile");
5299
- const existingTiltfile = (0, import_fs8.existsSync)(tiltfilePath) ? (0, import_fs8.readFileSync)(tiltfilePath, "utf8") : void 0;
5411
+ const tiltfilePath = import_path11.default.join(cwd, "Tiltfile");
5412
+ const existingTiltfile = (0, import_fs9.existsSync)(tiltfilePath) ? (0, import_fs9.readFileSync)(tiltfilePath, "utf8") : void 0;
5300
5413
  report(
5301
5414
  "Tiltfile",
5302
5415
  writeIfChanged(
5303
5416
  cwd,
5304
5417
  "Tiltfile",
5305
5418
  renderTiltfile(
5306
- (0, import_fs8.readFileSync)(import_path10.default.join(templateDir, "Tiltfile"), "utf8"),
5419
+ (0, import_fs9.readFileSync)(import_path11.default.join(templateDir, "Tiltfile"), "utf8"),
5307
5420
  existingTiltfile
5308
5421
  )
5309
5422
  )
5310
5423
  );
5311
5424
  const templateFiles = listFiles(templateDir, "tilt");
5312
5425
  for (const file of templateFiles) {
5313
- const source = import_path10.default.join(templateDir, file);
5426
+ const source = import_path11.default.join(templateDir, file);
5314
5427
  const countryOwned = file.startsWith(COUNTRY_OWNED_DIR);
5315
- if (countryOwned && (0, import_fs8.existsSync)(import_path10.default.join(cwd, file))) {
5428
+ if (countryOwned && (0, import_fs9.existsSync)(import_path11.default.join(cwd, file))) {
5316
5429
  continue;
5317
5430
  }
5318
5431
  report(
@@ -5320,8 +5433,8 @@ function upgradeTilt(cwd, templateDir) {
5320
5433
  writeIfChanged(
5321
5434
  cwd,
5322
5435
  file,
5323
- (0, import_fs8.readFileSync)(source, "utf8"),
5324
- (0, import_fs8.statSync)(source).mode
5436
+ (0, import_fs9.readFileSync)(source, "utf8"),
5437
+ (0, import_fs9.statSync)(source).mode
5325
5438
  )
5326
5439
  );
5327
5440
  }
@@ -5341,7 +5454,7 @@ function upgradeTilt(cwd, templateDir) {
5341
5454
  );
5342
5455
  }
5343
5456
  }
5344
- async function main9() {
5457
+ async function main10() {
5345
5458
  console.log("Upgrading the local Tilt setup...\n");
5346
5459
  upgradeTilt(process.cwd(), findTemplateDir());
5347
5460
  console.log(
@@ -5352,19 +5465,20 @@ async function main9() {
5352
5465
  // src/migrations/v2.1/index.ts
5353
5466
  async function runUpgrade(dockerSwarm) {
5354
5467
  await main();
5355
- await main8();
5468
+ await main9();
5356
5469
  await main2();
5357
5470
  await main3();
5358
5471
  await main7();
5359
5472
  await main6();
5360
5473
  await main5(dockerSwarm);
5361
- await main9();
5474
+ await main10();
5475
+ await main8();
5362
5476
  await main4();
5363
5477
  }
5364
5478
 
5365
5479
  // src/environment/index.ts
5366
- var import_fs13 = require("fs");
5367
- var import_path15 = require("path");
5480
+ var import_fs14 = require("fs");
5481
+ var import_path16 = require("path");
5368
5482
  init_paths();
5369
5483
  var REQUIRED_REPOSITORY_DIRECTORIES = [
5370
5484
  ".github/workflows",
@@ -5375,7 +5489,7 @@ function validateRepositoryStructure(repositoryRoot = process.cwd()) {
5375
5489
  const missingDirectories = REQUIRED_REPOSITORY_DIRECTORIES.filter(
5376
5490
  (directory) => {
5377
5491
  try {
5378
- return !(0, import_fs13.statSync)((0, import_path15.resolve)(repositoryRoot, directory)).isDirectory();
5492
+ return !(0, import_fs14.statSync)((0, import_path16.resolve)(repositoryRoot, directory)).isDirectory();
5379
5493
  } catch {
5380
5494
  return true;
5381
5495
  }
@@ -5702,8 +5816,8 @@ async function runVerifyEndpoints(target = DEFAULT_TARGET_URL) {
5702
5816
  console.log(line(ok, endpointLabel(check), detail));
5703
5817
  }
5704
5818
  {
5705
- const path14 = `/fonts/${PROBE_SEGMENT}.ttf`;
5706
- const status = await requestStatus(`${baseUrl}${path14}`, "GET");
5819
+ const path15 = `/fonts/${PROBE_SEGMENT}.ttf`;
5820
+ const status = await requestStatus(`${baseUrl}${path15}`, "GET");
5707
5821
  const ok = status === 200 || status === 404;
5708
5822
  if (!ok) {
5709
5823
  failures++;
@@ -5718,7 +5832,7 @@ async function runVerifyEndpoints(target = DEFAULT_TARGET_URL) {
5718
5832
  } else {
5719
5833
  detail = `${describeStatus(status)} \u2014 unexpected`;
5720
5834
  }
5721
- console.log(line(ok, `GET /fonts/{filename}${(0, import_colors.dim)(` \u2192 ${path14}`)}`, detail));
5835
+ console.log(line(ok, `GET /fonts/{filename}${(0, import_colors.dim)(` \u2192 ${path15}`)}`, detail));
5722
5836
  }
5723
5837
  console.log();
5724
5838
  console.log((0, import_colors.bold)("Secured endpoints (must be absent or require auth):"));
@@ -5856,7 +5970,7 @@ Options:
5856
5970
  'assets/' (default).
5857
5971
  -h, --help Show this message.
5858
5972
  `.trim();
5859
- function main10() {
5973
+ function main11() {
5860
5974
  const command = args[0];
5861
5975
  if (!command || command === "--help" || command === "-h") {
5862
5976
  console.log(USAGE);
@@ -5977,4 +6091,4 @@ async function handleVerifyEndpoints() {
5977
6091
  process.exit(1);
5978
6092
  }
5979
6093
  }
5980
- main10();
6094
+ main11();