@opencrvs/toolkit 2.2.0-rc.9042a13 → 2.2.0-rc.9dfc125
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/build.sh +2 -12
- package/dist/application-config/index.js +12 -7
- package/dist/authentication/index.d.ts +1 -0
- package/dist/authentication/index.js +16 -5
- package/dist/cli.js +875 -193
- package/dist/commons/api/router.d.ts +252 -246
- package/dist/commons/application-config/index.d.ts +2 -2
- package/dist/commons/conditionals/index.d.ts +1 -0
- package/dist/commons/conditionals/validate.d.ts +5 -0
- package/dist/commons/events/ActionConfig.d.ts +16 -23
- package/dist/commons/events/ActionDocument.d.ts +1 -0
- package/dist/commons/events/ActionInput.d.ts +4 -4
- package/dist/commons/events/CompositeFieldValue.d.ts +5 -1
- package/dist/commons/events/CountryConfigQueryInput.d.ts +60 -18
- package/dist/commons/events/EventConfig.d.ts +12 -2
- package/dist/commons/events/EventIndex.d.ts +23 -6
- package/dist/commons/events/EventMetadata.d.ts +0 -1
- package/dist/commons/events/FieldConfig.d.ts +1 -1
- package/dist/commons/events/FieldTypeMapping.d.ts +6 -6
- package/dist/commons/events/Flag.d.ts +1 -7
- package/dist/commons/events/PlainDate.d.ts +1 -0
- package/dist/commons/events/WorkqueueConfig.d.ts +74 -27
- package/dist/commons/events/eventConfigValidation.d.ts +9 -0
- package/dist/commons/events/index.d.ts +2 -0
- package/dist/commons/events/notificationFormFallback.d.ts +10 -0
- package/dist/commons/events/state/flags.d.ts +1 -1
- package/dist/commons/events/test.utils.d.ts +3 -0
- package/dist/commons/events/utils.d.ts +85 -56
- package/dist/conditionals/index.js +2 -3
- package/dist/environment/custom-types.d.ts +1 -0
- package/dist/environment/custom-types.d.ts.map +1 -1
- package/dist/environment/derived-variables.d.ts +12 -4
- package/dist/environment/derived-variables.d.ts.map +1 -1
- package/dist/environment/derived-variables.js +13 -4
- package/dist/environment/questions.d.ts +14 -2
- package/dist/environment/questions.d.ts.map +1 -1
- package/dist/environment/questions.js +40 -19
- package/dist/environment/registry.d.ts +15 -0
- package/dist/environment/registry.d.ts.map +1 -0
- package/dist/environment/registry.js +112 -0
- package/dist/environment/setup-environment.d.ts.map +1 -1
- package/dist/environment/setup-environment.js +111 -24
- package/dist/environment/templates.d.ts.map +1 -1
- package/dist/events/index.js +251 -67
- package/dist/migrations/index.d.ts +9 -0
- package/dist/migrations/index.d.ts.map +1 -0
- package/dist/migrations/index.js +847 -0
- package/dist/migrations/move-declaration-to-declare-action.d.ts +38 -0
- package/dist/migrations/move-declaration-to-declare-action.d.ts.map +1 -0
- package/dist/migrations/move-declaration-to-declare-action.js +377 -0
- package/dist/migrations/{add-translations.d.ts → persistent/add-translations.d.ts} +1 -1
- package/dist/migrations/persistent/add-translations.d.ts.map +1 -0
- package/dist/migrations/{add-translations.js → persistent/add-translations.js} +2 -2
- package/dist/migrations/persistent/check-upgrade-path.d.ts +36 -0
- package/dist/migrations/persistent/check-upgrade-path.d.ts.map +1 -0
- package/dist/migrations/persistent/check-upgrade-path.js +105 -0
- package/dist/migrations/persistent/update-toolkit-dependency.d.ts +7 -0
- package/dist/migrations/persistent/update-toolkit-dependency.d.ts.map +1 -0
- package/dist/migrations/persistent/update-toolkit-dependency.js +77 -0
- package/dist/migrations/{v2.2/read-declaration-through-helper.d.ts → read-declaration-through-helper.d.ts} +1 -1
- package/dist/migrations/read-declaration-through-helper.d.ts.map +1 -0
- package/dist/migrations/{v2.2/read-declaration-through-helper.js → read-declaration-through-helper.js} +1 -1
- package/dist/migrations/replace-incomplete-flag.d.ts +26 -0
- package/dist/migrations/replace-incomplete-flag.d.ts.map +1 -0
- package/dist/migrations/replace-incomplete-flag.js +126 -0
- package/dist/notification/index.js +151 -21
- package/dist/scopes/index.d.ts +54 -84
- package/dist/scopes/index.js +12 -5
- package/dist/templates/charts-values/dependencies/values.yaml +1 -1
- package/dist/templates/charts-values/opencrvs-services/values.yaml +4 -6
- package/dist/templates/charts-values/traefik/values.yaml +2 -0
- package/opencrvs-toolkit-2.2.0-rc.9dfc125.tgz +0 -0
- package/package.json +2 -2
- package/tsconfig.build.tsbuildinfo +1 -1
- package/dist/migrations/add-translations.d.ts.map +0 -1
- package/dist/migrations/v2.1/add-explicit-correction-flags.d.ts +0 -3
- package/dist/migrations/v2.1/add-explicit-correction-flags.d.ts.map +0 -1
- package/dist/migrations/v2.1/add-explicit-correction-flags.js +0 -234
- package/dist/migrations/v2.1/add-recovery-link-notifications.d.ts +0 -3
- package/dist/migrations/v2.1/add-recovery-link-notifications.d.ts.map +0 -1
- package/dist/migrations/v2.1/add-recovery-link-notifications.js +0 -511
- package/dist/migrations/v2.1/enable-telemetry.d.ts +0 -3
- package/dist/migrations/v2.1/enable-telemetry.d.ts.map +0 -1
- package/dist/migrations/v2.1/enable-telemetry.js +0 -455
- package/dist/migrations/v2.1/index.d.ts +0 -6
- package/dist/migrations/v2.1/index.d.ts.map +0 -1
- package/dist/migrations/v2.1/index.js +0 -50
- package/dist/migrations/v2.1/migrate-infrastructure-to-assets.d.ts +0 -17
- package/dist/migrations/v2.1/migrate-infrastructure-to-assets.d.ts.map +0 -1
- package/dist/migrations/v2.1/migrate-infrastructure-to-assets.js +0 -348
- package/dist/migrations/v2.1/remove-metabase-package-installs.d.ts +0 -2
- package/dist/migrations/v2.1/remove-metabase-package-installs.d.ts.map +0 -1
- package/dist/migrations/v2.1/remove-metabase-package-installs.js +0 -161
- package/dist/migrations/v2.1/remove-sentry.d.ts +0 -3
- package/dist/migrations/v2.1/remove-sentry.d.ts.map +0 -1
- package/dist/migrations/v2.1/remove-sentry.js +0 -354
- package/dist/migrations/v2.1/rename-trigger-paths.d.ts +0 -3
- package/dist/migrations/v2.1/rename-trigger-paths.d.ts.map +0 -1
- package/dist/migrations/v2.1/rename-trigger-paths.js +0 -216
- package/dist/migrations/v2.1/template-files.d.ts +0 -8
- package/dist/migrations/v2.1/template-files.d.ts.map +0 -1
- package/dist/migrations/v2.1/template-files.js +0 -49
- package/dist/migrations/v2.1/upgrade-tilt.d.ts +0 -11
- package/dist/migrations/v2.1/upgrade-tilt.d.ts.map +0 -1
- package/dist/migrations/v2.1/upgrade-tilt.js +0 -139
- package/dist/migrations/v2.2/index.d.ts +0 -6
- package/dist/migrations/v2.2/index.d.ts.map +0 -1
- package/dist/migrations/v2.2/index.js +0 -456
- package/dist/migrations/v2.2/read-declaration-through-helper.d.ts.map +0 -1
- package/dist/templates/countryconfig-template/.tiltignore +0 -1
- package/dist/templates/countryconfig-template/Dockerfile.assets +0 -7
- package/dist/templates/countryconfig-template/Tiltfile +0 -112
- package/dist/templates/countryconfig-template/assets/README.md +0 -1
- package/dist/templates/countryconfig-template/assets/clear-all-data-dev.sh +0 -61
- package/dist/templates/countryconfig-template/assets/deployment/deploy.sh +0 -455
- package/dist/templates/countryconfig-template/assets/deployment/reindex.sh +0 -168
- package/dist/templates/countryconfig-template/assets/deployment/validate-required-variables-in-compose-files.ts +0 -67
- package/dist/templates/countryconfig-template/assets/elasticsearch/reindex.sh +0 -168
- package/dist/templates/countryconfig-template/assets/metabase/README.md +0 -34
- package/dist/templates/countryconfig-template/assets/metabase/environment-configuration.sql +0 -36
- package/dist/templates/countryconfig-template/assets/metabase/initialize-database.sh +0 -46
- package/dist/templates/countryconfig-template/assets/metabase/metabase.init.db.sql +0 -27737
- package/dist/templates/countryconfig-template/assets/metabase/open-shell.sh +0 -21
- package/dist/templates/countryconfig-template/assets/metabase/package.json +0 -13
- package/dist/templates/countryconfig-template/assets/metabase/run-dev.sh +0 -108
- package/dist/templates/countryconfig-template/assets/metabase/run.sh +0 -120
- package/dist/templates/countryconfig-template/assets/metabase/update-database.sh +0 -40
- package/dist/templates/countryconfig-template/assets/postgres/setup-analytics.sh +0 -135
- package/dist/templates/countryconfig-template/assets/postgres/setup-reference-data.sh +0 -108
- package/dist/templates/countryconfig-template/tilt/clear-all-data.ps1 +0 -50
- package/dist/templates/countryconfig-template/tilt/clear-all-data.sh +0 -35
- package/dist/templates/countryconfig-template/tilt/common.tilt +0 -145
- package/dist/templates/countryconfig-template/tilt/examples/dependencies/values.yaml +0 -15
- package/dist/templates/countryconfig-template/tilt/examples/opencrvs-services/values.yaml +0 -56
- package/dist/templates/countryconfig-template/tilt/examples/traefik/values-minikube.yaml +0 -21
- package/dist/templates/countryconfig-template/tilt/examples/traefik/values.yaml +0 -38
- package/dist/templates/countryconfig-template/tilt/helm/dependencies/values.yaml +0 -17
- package/dist/templates/countryconfig-template/tilt/helm/opencrvs-services/values.yaml +0 -16
- package/dist/templates/countryconfig-template/tilt/lib.tilt +0 -95
- package/dist/templates/countryconfig-template/tilt/opencrvs.tilt +0 -136
- package/opencrvs-toolkit-2.2.0-rc.9042a13.tgz +0 -0
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,
|
|
35
|
+
return (0, import_path7.join)("environments", environment, INVENTORY_FILE_NAME);
|
|
36
36
|
}
|
|
37
37
|
function findOldInventoryFiles() {
|
|
38
|
-
return glob.sync((0,
|
|
38
|
+
return glob.sync((0, import_path7.join)(OLD_INVENTORY_DIR, "*.yml")).sort();
|
|
39
39
|
}
|
|
40
40
|
function getEnvironmentNameFromOldInventoryPath(filePath) {
|
|
41
|
-
return (0,
|
|
41
|
+
return (0, import_path7.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
|
|
54
|
+
var import_path7, glob, OLD_INVENTORY_DIR, INVENTORY_FILE_NAME;
|
|
55
55
|
var init_paths = __esm({
|
|
56
56
|
"src/environment/paths.ts"() {
|
|
57
57
|
"use strict";
|
|
58
|
-
|
|
58
|
+
import_path7 = require("path");
|
|
59
59
|
glob = __toESM(require("glob"));
|
|
60
|
-
OLD_INVENTORY_DIR = (0,
|
|
60
|
+
OLD_INVENTORY_DIR = (0, import_path7.join)(
|
|
61
61
|
"infrastructure",
|
|
62
62
|
"server-setup",
|
|
63
63
|
"inventory"
|
|
@@ -403,15 +403,17 @@ var init_derived_variables = __esm({
|
|
|
403
403
|
scope: "ENVIRONMENT"
|
|
404
404
|
},
|
|
405
405
|
{
|
|
406
|
-
name: "
|
|
407
|
-
valueLabel: "
|
|
406
|
+
name: "S3_ADMIN_ACCESS_KEY",
|
|
407
|
+
valueLabel: "S3_ADMIN_ACCESS_KEY",
|
|
408
|
+
legacyValueLabel: "MINIO_ROOT_USER",
|
|
408
409
|
valueType: "SECRET",
|
|
409
410
|
type: "disabled",
|
|
410
411
|
scope: "ENVIRONMENT"
|
|
411
412
|
},
|
|
412
413
|
{
|
|
413
|
-
name: "
|
|
414
|
-
valueLabel: "
|
|
414
|
+
name: "S3_ADMIN_SECRET_KEY",
|
|
415
|
+
valueLabel: "S3_ADMIN_SECRET_KEY",
|
|
416
|
+
legacyValueLabel: "MINIO_ROOT_PASSWORD",
|
|
415
417
|
valueType: "SECRET",
|
|
416
418
|
type: "disabled",
|
|
417
419
|
scope: "ENVIRONMENT"
|
|
@@ -506,6 +508,13 @@ var init_derived_variables = __esm({
|
|
|
506
508
|
valueType: "VARIABLE",
|
|
507
509
|
type: "disabled",
|
|
508
510
|
scope: "ENVIRONMENT"
|
|
511
|
+
},
|
|
512
|
+
{
|
|
513
|
+
name: "MONITORING_ENABLED",
|
|
514
|
+
valueLabel: "MONITORING_ENABLED",
|
|
515
|
+
valueType: "VARIABLE",
|
|
516
|
+
type: "disabled",
|
|
517
|
+
scope: "ENVIRONMENT"
|
|
509
518
|
}
|
|
510
519
|
];
|
|
511
520
|
}
|
|
@@ -525,7 +534,7 @@ function findExistingValue(name, type, scope, existingValues) {
|
|
|
525
534
|
);
|
|
526
535
|
}
|
|
527
536
|
function readYamlFile(filePath) {
|
|
528
|
-
const fileContent =
|
|
537
|
+
const fileContent = import_fs4.default.readFileSync(filePath, "utf8");
|
|
529
538
|
return yaml.load(fileContent);
|
|
530
539
|
}
|
|
531
540
|
function writeYamlFile(filePath, data) {
|
|
@@ -538,16 +547,16 @@ function writeYamlFile(filePath, data) {
|
|
|
538
547
|
noRefs: true,
|
|
539
548
|
sortKeys: false
|
|
540
549
|
});
|
|
541
|
-
|
|
542
|
-
} catch (
|
|
543
|
-
throw new Error(`Failed to write inventory file: ${
|
|
550
|
+
import_fs4.default.writeFileSync(filePath, yamlContent, "utf8");
|
|
551
|
+
} catch (error2) {
|
|
552
|
+
throw new Error(`Failed to write inventory file: ${error2}`);
|
|
544
553
|
}
|
|
545
554
|
}
|
|
546
|
-
var
|
|
555
|
+
var import_fs4, yaml;
|
|
547
556
|
var init_utils = __esm({
|
|
548
557
|
"src/environment/utils.ts"() {
|
|
549
558
|
"use strict";
|
|
550
|
-
|
|
559
|
+
import_fs4 = __toESM(require("fs"));
|
|
551
560
|
yaml = __toESM(require("js-yaml"));
|
|
552
561
|
}
|
|
553
562
|
});
|
|
@@ -596,29 +605,29 @@ function extractWorkerNodes(data) {
|
|
|
596
605
|
return worker_hosts;
|
|
597
606
|
}
|
|
598
607
|
function copyChartsValues(env, values) {
|
|
599
|
-
const srcDir =
|
|
600
|
-
const destDir =
|
|
601
|
-
|
|
608
|
+
const srcDir = import_path8.default.resolve(__dirname, "templates", "charts-values");
|
|
609
|
+
const destDir = import_path8.default.resolve(process.cwd(), "environments", env);
|
|
610
|
+
import_fs5.default.mkdirSync(destDir, { recursive: true });
|
|
602
611
|
values["lets_encrypt"] = values["traefik_mode"] === "lets_encrypt";
|
|
603
612
|
values["static_ssl"] = values["traefik_mode"] === "static_ssl";
|
|
604
613
|
values["opencrvs_environment"] = env;
|
|
605
614
|
function copyRecursive(src, dest) {
|
|
606
|
-
const stat =
|
|
615
|
+
const stat = import_fs5.default.statSync(src);
|
|
607
616
|
if (stat.isDirectory()) {
|
|
608
|
-
|
|
609
|
-
for (const item of
|
|
610
|
-
copyRecursive(
|
|
617
|
+
import_fs5.default.mkdirSync(dest, { recursive: true });
|
|
618
|
+
for (const item of import_fs5.default.readdirSync(src)) {
|
|
619
|
+
copyRecursive(import_path8.default.join(src, item), import_path8.default.join(dest, item));
|
|
611
620
|
}
|
|
612
621
|
} else {
|
|
613
|
-
const content =
|
|
622
|
+
const content = import_fs5.default.readFileSync(src, "utf8");
|
|
614
623
|
const template = import_handlebars.default.compile(content);
|
|
615
624
|
const updated = template(values);
|
|
616
625
|
const isOverridesFile = dest.endsWith("override.yaml");
|
|
617
|
-
if (isOverridesFile &&
|
|
626
|
+
if (isOverridesFile && import_fs5.default.existsSync(dest)) {
|
|
618
627
|
log(` \u21B7 Skipped existing overrides file: ${dest}`);
|
|
619
628
|
return;
|
|
620
629
|
}
|
|
621
|
-
|
|
630
|
+
import_fs5.default.writeFileSync(dest, updated, "utf8");
|
|
622
631
|
log(` \u2713 Created: ${dest}`);
|
|
623
632
|
}
|
|
624
633
|
}
|
|
@@ -629,29 +638,32 @@ function copyChartsValues(env, values) {
|
|
|
629
638
|
`);
|
|
630
639
|
}
|
|
631
640
|
function generateInventory(env, values) {
|
|
632
|
-
const templatePath =
|
|
641
|
+
const templatePath = import_path8.default.join(
|
|
633
642
|
__dirname,
|
|
634
643
|
"templates",
|
|
635
644
|
"inventory",
|
|
636
645
|
"inventory.template.yml"
|
|
637
646
|
);
|
|
638
|
-
const outputPath =
|
|
639
|
-
|
|
647
|
+
const outputPath = import_path8.default.resolve(
|
|
648
|
+
process.cwd(),
|
|
649
|
+
getEnvironmentInventoryPath(env)
|
|
650
|
+
);
|
|
651
|
+
const templateFile = import_fs5.default.readFileSync(templatePath, "utf-8");
|
|
640
652
|
const template = import_handlebars.default.compile(templateFile);
|
|
641
653
|
values["single_node"] = values["kube_worker_nodes"].length > 0 || values["backup_host"] ? "false" : "true";
|
|
642
654
|
const updated = template(values);
|
|
643
|
-
|
|
644
|
-
|
|
655
|
+
import_fs5.default.mkdirSync(import_path8.default.dirname(outputPath), { recursive: true });
|
|
656
|
+
import_fs5.default.writeFileSync(outputPath, updated);
|
|
645
657
|
log(`
|
|
646
658
|
\u2705 Generated inventory file at ${outputPath}
|
|
647
659
|
`);
|
|
648
660
|
}
|
|
649
|
-
var
|
|
661
|
+
var import_fs5, import_path8, import_handlebars;
|
|
650
662
|
var init_templates = __esm({
|
|
651
663
|
"src/environment/templates.ts"() {
|
|
652
664
|
"use strict";
|
|
653
|
-
|
|
654
|
-
|
|
665
|
+
import_fs5 = __toESM(require("fs"));
|
|
666
|
+
import_path8 = __toESM(require("path"));
|
|
655
667
|
init_logger();
|
|
656
668
|
init_paths();
|
|
657
669
|
import_handlebars = __toESM(require("handlebars"));
|
|
@@ -682,16 +694,16 @@ var update_workflows_exports = {};
|
|
|
682
694
|
__export(update_workflows_exports, {
|
|
683
695
|
updateWorkflowEnvironments: () => updateWorkflowEnvironments
|
|
684
696
|
});
|
|
685
|
-
function isDirectory(
|
|
697
|
+
function isDirectory(path12) {
|
|
686
698
|
try {
|
|
687
|
-
return (0,
|
|
699
|
+
return (0, import_fs6.statSync)(path12).isDirectory();
|
|
688
700
|
} catch {
|
|
689
701
|
return false;
|
|
690
702
|
}
|
|
691
703
|
}
|
|
692
704
|
async function extractInfrastructureNames() {
|
|
693
|
-
const files = glob2.sync((0,
|
|
694
|
-
const infraEnvironments = files.map((file) => (0,
|
|
705
|
+
const files = glob2.sync((0, import_path9.join)("environments", "*", INVENTORY_FILE_NAME));
|
|
706
|
+
const infraEnvironments = files.map((file) => (0, import_path9.basename)((0, import_path9.dirname)(file)));
|
|
695
707
|
if (infraEnvironments.length === 0) {
|
|
696
708
|
console.log(
|
|
697
709
|
`\u26A0\uFE0F Warning: No environment inventory files found at environments/*/${INVENTORY_FILE_NAME}`
|
|
@@ -704,9 +716,9 @@ async function extractInfrastructureNames() {
|
|
|
704
716
|
async function extractEnvironmentNames() {
|
|
705
717
|
const entries = await (0, import_promises.readdir)("environments");
|
|
706
718
|
const environments = entries.filter((entry) => {
|
|
707
|
-
const environmentPath = (0,
|
|
708
|
-
const opencrvsServicesPath = (0,
|
|
709
|
-
return isDirectory(environmentPath) && (0,
|
|
719
|
+
const environmentPath = (0, import_path9.join)("environments", entry);
|
|
720
|
+
const opencrvsServicesPath = (0, import_path9.join)(environmentPath, "opencrvs-services");
|
|
721
|
+
return isDirectory(environmentPath) && (0, import_fs6.existsSync)(opencrvsServicesPath) && isDirectory(opencrvsServicesPath);
|
|
710
722
|
});
|
|
711
723
|
if (environments.length === 0) {
|
|
712
724
|
console.log(
|
|
@@ -731,12 +743,12 @@ function updateOptionsInYaml(content, envList) {
|
|
|
731
743
|
async function updateWorkflows(envList, config) {
|
|
732
744
|
const { workflows } = config;
|
|
733
745
|
for (const workflowPath of workflows) {
|
|
734
|
-
if (!(0,
|
|
746
|
+
if (!(0, import_fs6.existsSync)(workflowPath)) {
|
|
735
747
|
log(` \u21B7 Skipped ${workflowPath} (not found in this repository)`);
|
|
736
748
|
continue;
|
|
737
749
|
}
|
|
738
750
|
try {
|
|
739
|
-
const fileContents = (0,
|
|
751
|
+
const fileContents = (0, import_fs6.readFileSync)(workflowPath, "utf8");
|
|
740
752
|
const workflowData = yaml2.load(fileContents);
|
|
741
753
|
if (!workflowData?.on?.workflow_dispatch?.inputs?.environment?.options) {
|
|
742
754
|
throw new Error(
|
|
@@ -744,15 +756,15 @@ async function updateWorkflows(envList, config) {
|
|
|
744
756
|
);
|
|
745
757
|
}
|
|
746
758
|
const updatedContent = updateOptionsInYaml(fileContents, envList);
|
|
747
|
-
(0,
|
|
759
|
+
(0, import_fs6.writeFileSync)(workflowPath, updatedContent, "utf8");
|
|
748
760
|
log(` \u2713 Successfully updated ${workflowPath}`);
|
|
749
|
-
} catch (
|
|
761
|
+
} catch (error2) {
|
|
750
762
|
console.error(
|
|
751
763
|
`
|
|
752
764
|
\u26A0\uFE0F Error updating ${workflowPath} with environments: [${envList.join(", ")}]`
|
|
753
765
|
);
|
|
754
|
-
console.error(`\u2717 Failed to update ${workflowPath}:`,
|
|
755
|
-
throw
|
|
766
|
+
console.error(`\u2717 Failed to update ${workflowPath}:`, error2);
|
|
767
|
+
throw error2;
|
|
756
768
|
}
|
|
757
769
|
}
|
|
758
770
|
}
|
|
@@ -793,18 +805,18 @@ async function updateWorkflowEnvironments() {
|
|
|
793
805
|
} else {
|
|
794
806
|
log("\u2139\uFE0F No workflows were updated.");
|
|
795
807
|
}
|
|
796
|
-
} catch (
|
|
797
|
-
console.error("\n\u274C Error updating workflows:",
|
|
808
|
+
} catch (error2) {
|
|
809
|
+
console.error("\n\u274C Error updating workflows:", error2);
|
|
798
810
|
process.exit(1);
|
|
799
811
|
}
|
|
800
812
|
}
|
|
801
|
-
var import_promises,
|
|
813
|
+
var import_promises, import_fs6, import_path9, glob2, yaml2;
|
|
802
814
|
var init_update_workflows = __esm({
|
|
803
815
|
"src/environment/update-workflows.ts"() {
|
|
804
816
|
"use strict";
|
|
805
817
|
import_promises = require("fs/promises");
|
|
806
|
-
|
|
807
|
-
|
|
818
|
+
import_fs6 = require("fs");
|
|
819
|
+
import_path9 = require("path");
|
|
808
820
|
glob2 = __toESM(require("glob"));
|
|
809
821
|
yaml2 = __toESM(require("js-yaml"));
|
|
810
822
|
init_logger();
|
|
@@ -862,7 +874,10 @@ function validateCIDRs(input4) {
|
|
|
862
874
|
}
|
|
863
875
|
return true;
|
|
864
876
|
}
|
|
865
|
-
|
|
877
|
+
function validateRegistryHost(input4) {
|
|
878
|
+
return /^[a-z0-9]([a-z0-9.-]*[a-z0-9])?(:[0-9]+)?$/i.test(input4) ? true : "Please enter a registry host without protocol or path (e.g. docker.io, ghcr.io)";
|
|
879
|
+
}
|
|
880
|
+
var import_kleur2, notEmpty, registryQuestions, githubQuestions, githubOtherQuestions, githubTokenQuestion, countryQuestions, infrastructureQuestions, staticSSLCertQuestions, backupQuestions, diskQuestions, databaseAndMonitoringQuestions, emailQuestions, sentryQuestions, metabaseAdminQuestions;
|
|
866
881
|
var init_questions = __esm({
|
|
867
882
|
"src/environment/questions.ts"() {
|
|
868
883
|
"use strict";
|
|
@@ -870,45 +885,59 @@ var init_questions = __esm({
|
|
|
870
885
|
init_utils();
|
|
871
886
|
init_git();
|
|
872
887
|
notEmpty = (value) => value.toString().trim().length > 0 ? true : "Please enter a value";
|
|
873
|
-
|
|
888
|
+
registryQuestions = [
|
|
889
|
+
{
|
|
890
|
+
name: "registryHost",
|
|
891
|
+
type: "text",
|
|
892
|
+
message: "What is the host of your container registry? (e.g. docker.io, ghcr.io)",
|
|
893
|
+
valueType: "VARIABLE",
|
|
894
|
+
valueLabel: "REGISTRY_HOST",
|
|
895
|
+
validate: validateRegistryHost,
|
|
896
|
+
initial: process.env.REGISTRY_HOST || "docker.io",
|
|
897
|
+
scope: "REPOSITORY"
|
|
898
|
+
},
|
|
874
899
|
{
|
|
875
|
-
name: "
|
|
900
|
+
name: "registryOrganisation",
|
|
876
901
|
type: "text",
|
|
877
|
-
message: "What is the name of your
|
|
902
|
+
message: "What is the name of your organisation (or user) in the container registry?",
|
|
878
903
|
valueType: "SECRET",
|
|
879
|
-
valueLabel: "
|
|
904
|
+
valueLabel: "REGISTRY_ORGANISATION",
|
|
905
|
+
legacyValueLabel: "DOCKERHUB_ACCOUNT",
|
|
880
906
|
validate: notEmpty,
|
|
881
|
-
initial: process.env.
|
|
907
|
+
initial: process.env.REGISTRY_ORGANISATION,
|
|
882
908
|
scope: "REPOSITORY"
|
|
883
909
|
},
|
|
884
910
|
{
|
|
885
|
-
name: "
|
|
911
|
+
name: "registryRepository",
|
|
886
912
|
type: "text",
|
|
887
|
-
message: "What is the name of your private
|
|
913
|
+
message: "What is the name of your private container repository?",
|
|
888
914
|
valueType: "SECRET",
|
|
889
|
-
valueLabel: "
|
|
915
|
+
valueLabel: "REGISTRY_REPOSITORY",
|
|
916
|
+
legacyValueLabel: "DOCKERHUB_REPO",
|
|
890
917
|
validate: notEmpty,
|
|
891
|
-
initial: process.env.
|
|
918
|
+
initial: process.env.REGISTRY_REPOSITORY,
|
|
892
919
|
scope: "REPOSITORY"
|
|
893
920
|
},
|
|
894
921
|
{
|
|
895
|
-
name: "
|
|
922
|
+
name: "registryUsername",
|
|
896
923
|
type: "text",
|
|
897
|
-
message: "What is the
|
|
924
|
+
message: "What is the container registry username the target server should be using?",
|
|
898
925
|
valueType: "SECRET",
|
|
899
|
-
valueLabel: "
|
|
926
|
+
valueLabel: "REGISTRY_USERNAME",
|
|
927
|
+
legacyValueLabel: "DOCKER_USERNAME",
|
|
900
928
|
validate: notEmpty,
|
|
901
|
-
initial: process.env.
|
|
929
|
+
initial: process.env.REGISTRY_USERNAME,
|
|
902
930
|
scope: "REPOSITORY"
|
|
903
931
|
},
|
|
904
932
|
{
|
|
905
|
-
name: "
|
|
933
|
+
name: "registryToken",
|
|
906
934
|
type: "text",
|
|
907
|
-
message: "What is the token of this
|
|
935
|
+
message: "What is the token of this container registry account?",
|
|
908
936
|
valueType: "SECRET",
|
|
909
|
-
valueLabel: "
|
|
937
|
+
valueLabel: "REGISTRY_TOKEN",
|
|
938
|
+
legacyValueLabel: "DOCKER_TOKEN",
|
|
910
939
|
validate: notEmpty,
|
|
911
|
-
initial: process.env.
|
|
940
|
+
initial: process.env.REGISTRY_TOKEN,
|
|
912
941
|
scope: "REPOSITORY"
|
|
913
942
|
}
|
|
914
943
|
];
|
|
@@ -1367,6 +1396,87 @@ var init_questions_helper = __esm({
|
|
|
1367
1396
|
}
|
|
1368
1397
|
});
|
|
1369
1398
|
|
|
1399
|
+
// src/environment/registry.ts
|
|
1400
|
+
function registryApiHost(registry) {
|
|
1401
|
+
const host = registry.trim().toLowerCase();
|
|
1402
|
+
return host === "docker.io" || host === "index.docker.io" ? "registry-1.docker.io" : host;
|
|
1403
|
+
}
|
|
1404
|
+
function request(url, authorization) {
|
|
1405
|
+
return fetch(url, {
|
|
1406
|
+
headers: authorization ? { Authorization: authorization } : {},
|
|
1407
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)
|
|
1408
|
+
});
|
|
1409
|
+
}
|
|
1410
|
+
function failure(registry, step, response) {
|
|
1411
|
+
const reason = `${registry} ${step} responded with HTTP ${response.status}`;
|
|
1412
|
+
switch (response.status) {
|
|
1413
|
+
case 401:
|
|
1414
|
+
case 403:
|
|
1415
|
+
return {
|
|
1416
|
+
status: "invalid-credentials",
|
|
1417
|
+
reason: `${reason}. Check REGISTRY_USERNAME, REGISTRY_TOKEN, REGISTRY_ORGANISATION and REGISTRY_REPOSITORY`
|
|
1418
|
+
};
|
|
1419
|
+
case 404:
|
|
1420
|
+
return {
|
|
1421
|
+
status: "repository-not-found",
|
|
1422
|
+
reason: `${reason}. This is also the answer for an empty repository. Check REGISTRY_ORGANISATION and REGISTRY_REPOSITORY`
|
|
1423
|
+
};
|
|
1424
|
+
default:
|
|
1425
|
+
return { status: "unreachable", reason };
|
|
1426
|
+
}
|
|
1427
|
+
}
|
|
1428
|
+
async function validateRegistryCredentials(registry, organisation, repository, username, token) {
|
|
1429
|
+
if (!registry || !organisation || !repository || !username || !token) {
|
|
1430
|
+
return {
|
|
1431
|
+
status: "skipped",
|
|
1432
|
+
reason: "Some values are kept from existing GitHub secrets, which cannot be read back"
|
|
1433
|
+
};
|
|
1434
|
+
}
|
|
1435
|
+
const host = registryApiHost(registry);
|
|
1436
|
+
const name = `${organisation}/${repository}`;
|
|
1437
|
+
const basic = `Basic ${Buffer.from(`${username}:${token}`).toString("base64")}`;
|
|
1438
|
+
try {
|
|
1439
|
+
const challenge = (await request(`https://${host}/v2/`, void 0)).headers.get(
|
|
1440
|
+
"www-authenticate"
|
|
1441
|
+
) ?? "";
|
|
1442
|
+
const realm = challenge.match(/realm="([^"]*)"/i)?.[1];
|
|
1443
|
+
const service = challenge.match(/service="([^"]*)"/i)?.[1];
|
|
1444
|
+
let authorization = basic;
|
|
1445
|
+
if (/^\s*bearer/i.test(challenge) && realm) {
|
|
1446
|
+
const tokenUrl = new URL(realm);
|
|
1447
|
+
if (service) {
|
|
1448
|
+
tokenUrl.searchParams.set("service", service);
|
|
1449
|
+
}
|
|
1450
|
+
tokenUrl.searchParams.set("scope", `repository:${name}:pull`);
|
|
1451
|
+
const login = await request(tokenUrl, basic);
|
|
1452
|
+
if (!login.ok) {
|
|
1453
|
+
return failure(registry, "login", login);
|
|
1454
|
+
}
|
|
1455
|
+
const body = await login.json();
|
|
1456
|
+
authorization = `Bearer ${body.token ?? body.access_token}`;
|
|
1457
|
+
}
|
|
1458
|
+
const path12 = name.split("/").map(encodeURIComponent).join("/");
|
|
1459
|
+
const response = await request(
|
|
1460
|
+
`https://${host}/v2/${path12}/tags/list?n=1`,
|
|
1461
|
+
authorization
|
|
1462
|
+
);
|
|
1463
|
+
return response.ok ? { status: "valid" } : failure(registry, `lookup of repository ${name}`, response);
|
|
1464
|
+
} catch (err) {
|
|
1465
|
+
if (!(err instanceof Error)) {
|
|
1466
|
+
return { status: "unreachable", reason: String(err) };
|
|
1467
|
+
}
|
|
1468
|
+
const cause = err.cause instanceof Error ? `: ${err.cause.message}` : "";
|
|
1469
|
+
return { status: "unreachable", reason: `${err.message}${cause}` };
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1472
|
+
var REQUEST_TIMEOUT_MS;
|
|
1473
|
+
var init_registry = __esm({
|
|
1474
|
+
"src/environment/registry.ts"() {
|
|
1475
|
+
"use strict";
|
|
1476
|
+
REQUEST_TIMEOUT_MS = 1e4;
|
|
1477
|
+
}
|
|
1478
|
+
});
|
|
1479
|
+
|
|
1370
1480
|
// src/environment/manage-users.ts
|
|
1371
1481
|
async function inquirerPrompt(name, options) {
|
|
1372
1482
|
const inquirer = await import("@inquirer/prompts");
|
|
@@ -1393,7 +1503,7 @@ function getCurrentUsername() {
|
|
|
1393
1503
|
}
|
|
1394
1504
|
function getCurrentUserSSHKeys() {
|
|
1395
1505
|
const homeDir = os.homedir();
|
|
1396
|
-
const sshDir =
|
|
1506
|
+
const sshDir = path8.join(homeDir, ".ssh");
|
|
1397
1507
|
const keys = [];
|
|
1398
1508
|
const keyFiles = [
|
|
1399
1509
|
"id_rsa.pub",
|
|
@@ -1402,15 +1512,15 @@ function getCurrentUserSSHKeys() {
|
|
|
1402
1512
|
"id_dsa.pub"
|
|
1403
1513
|
];
|
|
1404
1514
|
for (const keyFile of keyFiles) {
|
|
1405
|
-
const keyPath =
|
|
1515
|
+
const keyPath = path8.join(sshDir, keyFile);
|
|
1406
1516
|
try {
|
|
1407
|
-
if (
|
|
1408
|
-
const keyContent =
|
|
1517
|
+
if (fs5.existsSync(keyPath)) {
|
|
1518
|
+
const keyContent = fs5.readFileSync(keyPath, "utf8").trim();
|
|
1409
1519
|
if (keyContent) {
|
|
1410
1520
|
keys.push(keyContent);
|
|
1411
1521
|
}
|
|
1412
1522
|
}
|
|
1413
|
-
} catch (
|
|
1523
|
+
} catch (error2) {
|
|
1414
1524
|
continue;
|
|
1415
1525
|
}
|
|
1416
1526
|
}
|
|
@@ -1624,7 +1734,7 @@ async function editUser(user) {
|
|
|
1624
1734
|
return updatedUser;
|
|
1625
1735
|
}
|
|
1626
1736
|
async function manageUsers(inventoryPath) {
|
|
1627
|
-
let users =
|
|
1737
|
+
let users = fs5.existsSync(inventoryPath) ? parseInventoryFile(inventoryPath) : [];
|
|
1628
1738
|
if (users.length > 0) {
|
|
1629
1739
|
displayUserSummary(users);
|
|
1630
1740
|
}
|
|
@@ -1716,7 +1826,7 @@ async function manageUsers(inventoryPath) {
|
|
|
1716
1826
|
message: "Save changes end exit?",
|
|
1717
1827
|
default: true
|
|
1718
1828
|
});
|
|
1719
|
-
if (confirmSave &&
|
|
1829
|
+
if (confirmSave && fs5.existsSync(inventoryPath)) {
|
|
1720
1830
|
updateInventoryFile(inventoryPath, users);
|
|
1721
1831
|
console.log(`
|
|
1722
1832
|
\u2705 Changes saved to ${inventoryPath}
|
|
@@ -1743,13 +1853,13 @@ async function manageUsers(inventoryPath) {
|
|
|
1743
1853
|
}
|
|
1744
1854
|
return users;
|
|
1745
1855
|
}
|
|
1746
|
-
var os,
|
|
1856
|
+
var os, fs5, path8, input2, select2, confirm, editor, checkbox;
|
|
1747
1857
|
var init_manage_users = __esm({
|
|
1748
1858
|
"src/environment/manage-users.ts"() {
|
|
1749
1859
|
"use strict";
|
|
1750
1860
|
os = __toESM(require("os"));
|
|
1751
|
-
|
|
1752
|
-
|
|
1861
|
+
fs5 = __toESM(require("fs"));
|
|
1862
|
+
path8 = __toESM(require("path"));
|
|
1753
1863
|
init_logger();
|
|
1754
1864
|
init_utils();
|
|
1755
1865
|
init_templates();
|
|
@@ -1781,6 +1891,7 @@ async function input3(options) {
|
|
|
1781
1891
|
function questionToPrompt({
|
|
1782
1892
|
valueType,
|
|
1783
1893
|
valueLabel,
|
|
1894
|
+
legacyValueLabel,
|
|
1784
1895
|
scope,
|
|
1785
1896
|
...promptOptions
|
|
1786
1897
|
}) {
|
|
@@ -1844,6 +1955,12 @@ function getAnswers(existingValues) {
|
|
|
1844
1955
|
});
|
|
1845
1956
|
});
|
|
1846
1957
|
}
|
|
1958
|
+
function getInitialValue(question, variable) {
|
|
1959
|
+
if (question.type === "select" && Array.isArray(question.choices)) {
|
|
1960
|
+
return getIndexFromChoices(question.choices, variable.value);
|
|
1961
|
+
}
|
|
1962
|
+
return variable.value;
|
|
1963
|
+
}
|
|
1847
1964
|
async function promptAndStoreAnswer(questions, existingValues) {
|
|
1848
1965
|
log("");
|
|
1849
1966
|
const processedQuestions = questions.flatMap((question) => {
|
|
@@ -1861,14 +1978,22 @@ async function promptAndStoreAnswer(questions, existingValues) {
|
|
|
1861
1978
|
questionWithVariableLabel.scope,
|
|
1862
1979
|
existingValues
|
|
1863
1980
|
);
|
|
1981
|
+
const legacyVariable = !existingVariable && questionWithVariableLabel.legacyValueLabel ? findExistingValue(
|
|
1982
|
+
questionWithVariableLabel.legacyValueLabel,
|
|
1983
|
+
"VARIABLE",
|
|
1984
|
+
questionWithVariableLabel.scope,
|
|
1985
|
+
existingValues
|
|
1986
|
+
) : void 0;
|
|
1987
|
+
if (legacyVariable) {
|
|
1988
|
+
return {
|
|
1989
|
+
...questionWithVariableLabel,
|
|
1990
|
+
message: `${questionWithVariableLabel.message} ${import_kleur4.default.gray(
|
|
1991
|
+
`(default taken from ${legacyVariable.name}, the previous name of this variable)`
|
|
1992
|
+
)}`,
|
|
1993
|
+
initial: getInitialValue(questionWithVariableLabel, legacyVariable)
|
|
1994
|
+
};
|
|
1995
|
+
}
|
|
1864
1996
|
if (existingVariable) {
|
|
1865
|
-
let initial_value = existingVariable.value;
|
|
1866
|
-
if (questionWithVariableLabel.type === "select" && Array.isArray(questionWithVariableLabel.choices)) {
|
|
1867
|
-
initial_value = getIndexFromChoices(
|
|
1868
|
-
questionWithVariableLabel.choices,
|
|
1869
|
-
existingVariable.value
|
|
1870
|
-
);
|
|
1871
|
-
}
|
|
1872
1997
|
return [
|
|
1873
1998
|
{
|
|
1874
1999
|
name: "overWrite" + questionWithVariableLabel.name,
|
|
@@ -1883,7 +2008,10 @@ async function promptAndStoreAnswer(questions, existingValues) {
|
|
|
1883
2008
|
{
|
|
1884
2009
|
...questionWithVariableLabel,
|
|
1885
2010
|
type: (prev) => prev ? questionWithVariableLabel.type : null,
|
|
1886
|
-
initial:
|
|
2011
|
+
initial: getInitialValue(
|
|
2012
|
+
questionWithVariableLabel,
|
|
2013
|
+
existingVariable
|
|
2014
|
+
)
|
|
1887
2015
|
}
|
|
1888
2016
|
];
|
|
1889
2017
|
}
|
|
@@ -1895,6 +2023,32 @@ async function promptAndStoreAnswer(questions, existingValues) {
|
|
|
1895
2023
|
questionWithVariableLabel.scope,
|
|
1896
2024
|
existingValues
|
|
1897
2025
|
);
|
|
2026
|
+
const legacySecret = !existingSecret && questionWithVariableLabel.legacyValueLabel ? findExistingValue(
|
|
2027
|
+
questionWithVariableLabel.legacyValueLabel,
|
|
2028
|
+
"SECRET",
|
|
2029
|
+
questionWithVariableLabel.scope,
|
|
2030
|
+
existingValues
|
|
2031
|
+
) : void 0;
|
|
2032
|
+
if (legacySecret) {
|
|
2033
|
+
return [
|
|
2034
|
+
{
|
|
2035
|
+
name: "overWrite" + questionWithVariableLabel.name,
|
|
2036
|
+
type: "confirm",
|
|
2037
|
+
scope: questionWithVariableLabel.scope,
|
|
2038
|
+
message: `${import_kleur4.default.yellow(
|
|
2039
|
+
`${legacySecret.scope === "REPOSITORY" ? "Repository secret" : "Secret"} ${import_kleur4.default.cyan(
|
|
2040
|
+
legacySecret.name
|
|
2041
|
+
)} already exists in Github under the previous name of ${import_kleur4.default.cyan(
|
|
2042
|
+
questionWithVariableLabel.valueLabel
|
|
2043
|
+
)}. The secrets migration workflow copies it. Do you want to enter a new value instead?`
|
|
2044
|
+
)}`
|
|
2045
|
+
},
|
|
2046
|
+
{
|
|
2047
|
+
...questionWithVariableLabel,
|
|
2048
|
+
type: (prev) => prev ? questionWithVariableLabel.type : null
|
|
2049
|
+
}
|
|
2050
|
+
];
|
|
2051
|
+
}
|
|
1898
2052
|
if (existingSecret) {
|
|
1899
2053
|
return [
|
|
1900
2054
|
{
|
|
@@ -1934,6 +2088,47 @@ async function promptAndStoreAnswer(questions, existingValues) {
|
|
|
1934
2088
|
]);
|
|
1935
2089
|
return { ...Object.fromEntries(existingValuesForQuestions), ...result };
|
|
1936
2090
|
}
|
|
2091
|
+
function defineIfMissing(existingValues, name, type, scope, newValue) {
|
|
2092
|
+
if (findExistingValue(name, type, scope, existingValues)) {
|
|
2093
|
+
return null;
|
|
2094
|
+
}
|
|
2095
|
+
const legacyName = ALL_QUESTIONS.find(
|
|
2096
|
+
(question) => question.valueLabel === name && question.valueType === type && question.scope === scope
|
|
2097
|
+
)?.legacyValueLabel;
|
|
2098
|
+
if (legacyName && findExistingValue(legacyName, type, scope, existingValues)) {
|
|
2099
|
+
log(
|
|
2100
|
+
import_kleur4.default.bold().green("\u2714"),
|
|
2101
|
+
import_kleur4.default.bold().yellow(
|
|
2102
|
+
`${legacyName} exists, the secrets migration workflow copies it to ${name}`
|
|
2103
|
+
)
|
|
2104
|
+
);
|
|
2105
|
+
return null;
|
|
2106
|
+
}
|
|
2107
|
+
return process.env[name] || newValue;
|
|
2108
|
+
}
|
|
2109
|
+
async function promptAndValidateRegistry(existingValues) {
|
|
2110
|
+
const answers = await promptAndStoreAnswer(registryQuestions, existingValues);
|
|
2111
|
+
const result = await validateRegistryCredentials(
|
|
2112
|
+
answers.registryHost,
|
|
2113
|
+
answers.registryOrganisation,
|
|
2114
|
+
answers.registryRepository,
|
|
2115
|
+
answers.registryUsername,
|
|
2116
|
+
answers.registryToken
|
|
2117
|
+
);
|
|
2118
|
+
if (result.status === "valid" || result.status === "skipped") {
|
|
2119
|
+
return;
|
|
2120
|
+
}
|
|
2121
|
+
error(`
|
|
2122
|
+
${result.status}: ${result.reason || "Generic error"}
|
|
2123
|
+
`);
|
|
2124
|
+
const continueNotValidated = await confirm2({
|
|
2125
|
+
message: "Container registry credentials are not validated. Continue anyway?",
|
|
2126
|
+
default: false
|
|
2127
|
+
});
|
|
2128
|
+
if (!continueNotValidated) {
|
|
2129
|
+
process.exit(1);
|
|
2130
|
+
}
|
|
2131
|
+
}
|
|
1937
2132
|
async function runSetupEnvironment() {
|
|
1938
2133
|
log("\n", import_kleur4.default.bold().underline("Github"), "\n");
|
|
1939
2134
|
const { githubOrganisation, githubRepository } = await (0, import_prompts2.default)(
|
|
@@ -2077,8 +2272,8 @@ async function runSetupEnvironment() {
|
|
|
2077
2272
|
"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."
|
|
2078
2273
|
);
|
|
2079
2274
|
}
|
|
2080
|
-
log("\n", import_kleur4.default.bold().underline("
|
|
2081
|
-
await
|
|
2275
|
+
log("\n", import_kleur4.default.bold().underline("Container registry"));
|
|
2276
|
+
await promptAndValidateRegistry(existingValues);
|
|
2082
2277
|
log("\n", import_kleur4.default.bold().underline("Kubernetes & Runtime"));
|
|
2083
2278
|
const infrastructure = await promptAndStoreAnswer(
|
|
2084
2279
|
infrastructureQuestions,
|
|
@@ -2262,7 +2457,22 @@ async function runSetupEnvironment() {
|
|
|
2262
2457
|
log(import_kleur4.default.bold().green("\u2714"), import_kleur4.default.bold().yellow("Restore is disabled"));
|
|
2263
2458
|
}
|
|
2264
2459
|
log("\n", import_kleur4.default.bold().underline("Monitoring"));
|
|
2265
|
-
|
|
2460
|
+
const existingMonitoringEnabled = findExistingValue(
|
|
2461
|
+
"MONITORING_ENABLED",
|
|
2462
|
+
"VARIABLE",
|
|
2463
|
+
"ENVIRONMENT",
|
|
2464
|
+
existingValues
|
|
2465
|
+
);
|
|
2466
|
+
const monitoringDefault = process.env.MONITORING_ENABLED || existingMonitoringEnabled?.value;
|
|
2467
|
+
const monitoring_enabled = await confirm2({
|
|
2468
|
+
message: "Enable monitoring (Kibana, APM, Filebeat, Metricbeat, Elastalert, OpenTelemetry Collector and tracing)? Disable it if this environment does not need its own monitoring stack.",
|
|
2469
|
+
default: monitoringDefault ? monitoringDefault === "true" : true
|
|
2470
|
+
});
|
|
2471
|
+
if (monitoring_enabled) {
|
|
2472
|
+
await promptAndStoreAnswer(databaseAndMonitoringQuestions, existingValues);
|
|
2473
|
+
} else {
|
|
2474
|
+
log(import_kleur4.default.bold().green("\u2714"), import_kleur4.default.bold().yellow("Monitoring is disabled"));
|
|
2475
|
+
}
|
|
2266
2476
|
const sentryDSNExists = findExistingValue(
|
|
2267
2477
|
"SENTRY_DSN",
|
|
2268
2478
|
"SECRET",
|
|
@@ -2293,9 +2503,7 @@ async function runSetupEnvironment() {
|
|
|
2293
2503
|
return { ...acc, ...answer };
|
|
2294
2504
|
});
|
|
2295
2505
|
const answerOrExisting = (variable, existingValue, fn) => fn(variable || existingValue?.value) || "";
|
|
2296
|
-
|
|
2297
|
-
return findExistingValue(name, type, scope, existingValues) ? null : process.env[name] || newValue;
|
|
2298
|
-
}
|
|
2506
|
+
const findExistingOrDefine = (name, type, scope, newValue) => defineIfMissing(existingValues, name, type, scope, newValue);
|
|
2299
2507
|
const derivedUpdates = [
|
|
2300
2508
|
{
|
|
2301
2509
|
name: "GH_ENCRYPTION_PASSWORD",
|
|
@@ -2340,6 +2548,13 @@ async function runSetupEnvironment() {
|
|
|
2340
2548
|
value: two_fa_enabled ? "true" : "false",
|
|
2341
2549
|
scope: "ENVIRONMENT"
|
|
2342
2550
|
});
|
|
2551
|
+
derivedUpdates.push({
|
|
2552
|
+
name: "MONITORING_ENABLED",
|
|
2553
|
+
type: "VARIABLE",
|
|
2554
|
+
didExist: existingMonitoringEnabled,
|
|
2555
|
+
value: monitoring_enabled ? "true" : "false",
|
|
2556
|
+
scope: "ENVIRONMENT"
|
|
2557
|
+
});
|
|
2343
2558
|
derivedUpdates.push(...ssl_answers);
|
|
2344
2559
|
if (configureBackup) {
|
|
2345
2560
|
derivedUpdates.push({
|
|
@@ -2396,16 +2611,16 @@ async function runSetupEnvironment() {
|
|
|
2396
2611
|
scope: "ENVIRONMENT"
|
|
2397
2612
|
},
|
|
2398
2613
|
{
|
|
2399
|
-
name: "
|
|
2614
|
+
name: "S3_ADMIN_ACCESS_KEY",
|
|
2400
2615
|
type: "SECRET",
|
|
2401
2616
|
didExist: findExistingValue(
|
|
2402
|
-
"
|
|
2617
|
+
"S3_ADMIN_ACCESS_KEY",
|
|
2403
2618
|
"SECRET",
|
|
2404
2619
|
"ENVIRONMENT",
|
|
2405
2620
|
existingValues
|
|
2406
2621
|
),
|
|
2407
2622
|
value: findExistingOrDefine(
|
|
2408
|
-
"
|
|
2623
|
+
"S3_ADMIN_ACCESS_KEY",
|
|
2409
2624
|
"SECRET",
|
|
2410
2625
|
"ENVIRONMENT",
|
|
2411
2626
|
generateLongPassword()
|
|
@@ -2413,16 +2628,16 @@ async function runSetupEnvironment() {
|
|
|
2413
2628
|
scope: "ENVIRONMENT"
|
|
2414
2629
|
},
|
|
2415
2630
|
{
|
|
2416
|
-
name: "
|
|
2631
|
+
name: "S3_ADMIN_SECRET_KEY",
|
|
2417
2632
|
type: "SECRET",
|
|
2418
2633
|
didExist: findExistingValue(
|
|
2419
|
-
"
|
|
2634
|
+
"S3_ADMIN_SECRET_KEY",
|
|
2420
2635
|
"SECRET",
|
|
2421
2636
|
"ENVIRONMENT",
|
|
2422
2637
|
existingValues
|
|
2423
2638
|
),
|
|
2424
2639
|
value: findExistingOrDefine(
|
|
2425
|
-
"
|
|
2640
|
+
"S3_ADMIN_SECRET_KEY",
|
|
2426
2641
|
"SECRET",
|
|
2427
2642
|
"ENVIRONMENT",
|
|
2428
2643
|
generateLongPassword()
|
|
@@ -2686,7 +2901,7 @@ async function runSetupEnvironment() {
|
|
|
2686
2901
|
);
|
|
2687
2902
|
const unknownVariables = existingValues.filter((value) => {
|
|
2688
2903
|
return !ALL_QUESTIONS.find(
|
|
2689
|
-
(question) => question.valueLabel === value.name && question.valueType === value.type && question.scope === value.scope
|
|
2904
|
+
(question) => (question.valueLabel === value.name || question.legacyValueLabel === value.name) && question.valueType === value.type && question.scope === value.scope
|
|
2690
2905
|
);
|
|
2691
2906
|
});
|
|
2692
2907
|
log("");
|
|
@@ -2890,6 +3105,7 @@ async function runSetupEnvironment() {
|
|
|
2890
3105
|
env: environment,
|
|
2891
3106
|
environment_type,
|
|
2892
3107
|
two_fa_enabled,
|
|
3108
|
+
monitoring_enabled,
|
|
2893
3109
|
traefik_mode: traefikConfOption,
|
|
2894
3110
|
restore_enabled: restoreEnvironmentName ? true : false,
|
|
2895
3111
|
restore_environment_name: restoreEnvironmentName || "",
|
|
@@ -2955,6 +3171,7 @@ var init_setup_environment = __esm({
|
|
|
2955
3171
|
init_questions();
|
|
2956
3172
|
init_editor_questions();
|
|
2957
3173
|
init_questions_helper();
|
|
3174
|
+
init_registry();
|
|
2958
3175
|
init_manage_users();
|
|
2959
3176
|
init_paths();
|
|
2960
3177
|
ALL_QUESTIONS = [];
|
|
@@ -2962,7 +3179,7 @@ var init_setup_environment = __esm({
|
|
|
2962
3179
|
ALL_QUESTIONS.push(
|
|
2963
3180
|
...githubTokenQuestion,
|
|
2964
3181
|
...githubOtherQuestions,
|
|
2965
|
-
...
|
|
3182
|
+
...registryQuestions,
|
|
2966
3183
|
...diskQuestions,
|
|
2967
3184
|
...infrastructureQuestions,
|
|
2968
3185
|
...backupQuestions,
|
|
@@ -2982,17 +3199,17 @@ __export(upgrade_exports, {
|
|
|
2982
3199
|
upgradeEnvironmentLayout: () => upgradeEnvironmentLayout
|
|
2983
3200
|
});
|
|
2984
3201
|
function moveFileIfDestinationMissing(sourcePath, destinationPath) {
|
|
2985
|
-
if (!(0,
|
|
3202
|
+
if (!(0, import_fs7.existsSync)(sourcePath)) {
|
|
2986
3203
|
return false;
|
|
2987
3204
|
}
|
|
2988
|
-
if ((0,
|
|
3205
|
+
if ((0, import_fs7.existsSync)(destinationPath)) {
|
|
2989
3206
|
warn(
|
|
2990
3207
|
`\u26A0\uFE0F Skipped ${sourcePath}; destination already exists at ${destinationPath}`
|
|
2991
3208
|
);
|
|
2992
3209
|
return false;
|
|
2993
3210
|
}
|
|
2994
|
-
(0,
|
|
2995
|
-
(0,
|
|
3211
|
+
(0, import_fs7.mkdirSync)((0, import_path10.dirname)(destinationPath), { recursive: true });
|
|
3212
|
+
(0, import_fs7.renameSync)(sourcePath, destinationPath);
|
|
2996
3213
|
log(` \u2713 Moved ${sourcePath} -> ${destinationPath}`);
|
|
2997
3214
|
return true;
|
|
2998
3215
|
}
|
|
@@ -3012,8 +3229,8 @@ function migrateInventoryFiles() {
|
|
|
3012
3229
|
) || didMoveInventory;
|
|
3013
3230
|
}
|
|
3014
3231
|
try {
|
|
3015
|
-
if ((0,
|
|
3016
|
-
(0,
|
|
3232
|
+
if ((0, import_fs7.existsSync)(OLD_INVENTORY_DIR) && (0, import_fs7.readdirSync)(OLD_INVENTORY_DIR).length === 0) {
|
|
3233
|
+
(0, import_fs7.rmdirSync)(OLD_INVENTORY_DIR);
|
|
3017
3234
|
log(` \u2713 Removed empty ${OLD_INVENTORY_DIR}`);
|
|
3018
3235
|
}
|
|
3019
3236
|
} catch {
|
|
@@ -3031,12 +3248,12 @@ async function upgradeEnvironmentLayout() {
|
|
|
3031
3248
|
}
|
|
3032
3249
|
log("\nCommit changes into git after upgrade");
|
|
3033
3250
|
}
|
|
3034
|
-
var
|
|
3251
|
+
var import_fs7, import_path10, import_kleur5;
|
|
3035
3252
|
var init_upgrade = __esm({
|
|
3036
3253
|
"src/environment/upgrade.ts"() {
|
|
3037
3254
|
"use strict";
|
|
3038
|
-
|
|
3039
|
-
|
|
3255
|
+
import_fs7 = require("fs");
|
|
3256
|
+
import_path10 = require("path");
|
|
3040
3257
|
import_kleur5 = __toESM(require("kleur"));
|
|
3041
3258
|
init_logger();
|
|
3042
3259
|
init_paths();
|
|
@@ -3054,16 +3271,16 @@ async function select4(options) {
|
|
|
3054
3271
|
return inquirer.select(options);
|
|
3055
3272
|
}
|
|
3056
3273
|
async function selectInventoryFile(dirPath = "./environments") {
|
|
3057
|
-
if (!
|
|
3274
|
+
if (!fs6.existsSync(dirPath)) {
|
|
3058
3275
|
warn(`\u26A0\uFE0F No environment configuration directory found at ${dirPath}`);
|
|
3059
3276
|
warn(
|
|
3060
3277
|
"Hint: If this is a new infrastructure repository, run `opencrvs environment init` first."
|
|
3061
3278
|
);
|
|
3062
3279
|
return null;
|
|
3063
3280
|
}
|
|
3064
|
-
const environments =
|
|
3065
|
-
const filePath =
|
|
3066
|
-
return
|
|
3281
|
+
const environments = fs6.readdirSync(dirPath).filter((entry) => {
|
|
3282
|
+
const filePath = path9.join(dirPath, entry);
|
|
3283
|
+
return fs6.statSync(filePath).isDirectory() && fs6.existsSync(getEnvironmentInventoryPath(entry));
|
|
3067
3284
|
}).sort();
|
|
3068
3285
|
if (environments.length === 0) {
|
|
3069
3286
|
warn(`\u26A0\uFE0F No environment configuration files found at ${dirPath}`);
|
|
@@ -3090,12 +3307,12 @@ async function manageEnvironmentUsers() {
|
|
|
3090
3307
|
}
|
|
3091
3308
|
await manageUsers(inventory_file);
|
|
3092
3309
|
}
|
|
3093
|
-
var
|
|
3310
|
+
var fs6, path9, import_kleur6;
|
|
3094
3311
|
var init_users = __esm({
|
|
3095
3312
|
"src/environment/users.ts"() {
|
|
3096
3313
|
"use strict";
|
|
3097
|
-
|
|
3098
|
-
|
|
3314
|
+
fs6 = __toESM(require("fs"));
|
|
3315
|
+
path9 = __toESM(require("path"));
|
|
3099
3316
|
import_kleur6 = __toESM(require("kleur"));
|
|
3100
3317
|
init_manage_users();
|
|
3101
3318
|
init_logger();
|
|
@@ -3105,11 +3322,11 @@ var init_users = __esm({
|
|
|
3105
3322
|
|
|
3106
3323
|
// src/environment/swarm-to-k8s.ts
|
|
3107
3324
|
var swarm_to_k8s_exports = {};
|
|
3108
|
-
var
|
|
3325
|
+
var path10, import_kleur7, import_core2;
|
|
3109
3326
|
var init_swarm_to_k8s = __esm({
|
|
3110
3327
|
"src/environment/swarm-to-k8s.ts"() {
|
|
3111
3328
|
"use strict";
|
|
3112
|
-
|
|
3329
|
+
path10 = __toESM(require("path"));
|
|
3113
3330
|
import_kleur7 = __toESM(require("kleur"));
|
|
3114
3331
|
init_logger();
|
|
3115
3332
|
init_utils();
|
|
@@ -3161,7 +3378,7 @@ var init_swarm_to_k8s = __esm({
|
|
|
3161
3378
|
);
|
|
3162
3379
|
process.exit(1);
|
|
3163
3380
|
}
|
|
3164
|
-
const ansible_inventory =
|
|
3381
|
+
const ansible_inventory = path10.join(old_inventory_path, environment + ".yml");
|
|
3165
3382
|
const data = readYamlFile(ansible_inventory);
|
|
3166
3383
|
log(` \u2713 Loaded old inventory file: ${ansible_inventory}`);
|
|
3167
3384
|
const master = dockerManagerFirst(data) || "";
|
|
@@ -3282,7 +3499,11 @@ var init_swarm_to_k8s = __esm({
|
|
|
3282
3499
|
}
|
|
3283
3500
|
});
|
|
3284
3501
|
|
|
3285
|
-
// src/
|
|
3502
|
+
// src/cli.ts
|
|
3503
|
+
var import_fs9 = __toESM(require("fs"));
|
|
3504
|
+
var import_path12 = __toESM(require("path"));
|
|
3505
|
+
|
|
3506
|
+
// src/migrations/persistent/add-translations.ts
|
|
3286
3507
|
var import_path = __toESM(require("path"));
|
|
3287
3508
|
|
|
3288
3509
|
// src/csv.ts
|
|
@@ -3325,20 +3546,20 @@ function idOf(line2) {
|
|
|
3325
3546
|
const comma = line2.indexOf(",");
|
|
3326
3547
|
return comma === -1 ? line2 : line2.slice(0, comma);
|
|
3327
3548
|
}
|
|
3328
|
-
function readCsvFile(
|
|
3329
|
-
if (!(0, import_fs.existsSync)(
|
|
3549
|
+
function readCsvFile(path12) {
|
|
3550
|
+
if (!(0, import_fs.existsSync)(path12)) {
|
|
3330
3551
|
return void 0;
|
|
3331
3552
|
}
|
|
3332
|
-
const contents = (0, import_fs.readFileSync)(
|
|
3553
|
+
const contents = (0, import_fs.readFileSync)(path12, "utf8");
|
|
3333
3554
|
const newline = contents.includes("\r\n") ? "\r\n" : "\n";
|
|
3334
3555
|
const trailingNewline = /\r?\n$/.test(contents);
|
|
3335
3556
|
const lines = contents.replace(/\r?\n$/, "").split(/\r?\n/);
|
|
3336
3557
|
const body = lines.slice(1).filter((line2) => line2 !== "");
|
|
3337
3558
|
return { header: lines[0], body, newline, trailingNewline };
|
|
3338
3559
|
}
|
|
3339
|
-
function writeCsvFile(
|
|
3560
|
+
function writeCsvFile(path12, file) {
|
|
3340
3561
|
(0, import_fs.writeFileSync)(
|
|
3341
|
-
|
|
3562
|
+
path12,
|
|
3342
3563
|
[file.header, ...file.body].join(file.newline) + (file.trailingNewline ? file.newline : "")
|
|
3343
3564
|
);
|
|
3344
3565
|
}
|
|
@@ -3352,11 +3573,11 @@ function addRows(file, rows) {
|
|
|
3352
3573
|
if (file.body.some((line2) => idOf(line2) === id)) {
|
|
3353
3574
|
continue;
|
|
3354
3575
|
}
|
|
3355
|
-
const
|
|
3356
|
-
if (
|
|
3576
|
+
const insertAt2 = isSorted ? file.body.findIndex((line2) => idOf(line2) > id) : -1;
|
|
3577
|
+
if (insertAt2 === -1) {
|
|
3357
3578
|
file.body.push(row);
|
|
3358
3579
|
} else {
|
|
3359
|
-
file.body.splice(
|
|
3580
|
+
file.body.splice(insertAt2, 0, row);
|
|
3360
3581
|
}
|
|
3361
3582
|
added.push(id);
|
|
3362
3583
|
}
|
|
@@ -3403,7 +3624,7 @@ async function fetchTemplate(refs, application) {
|
|
|
3403
3624
|
return void 0;
|
|
3404
3625
|
}
|
|
3405
3626
|
|
|
3406
|
-
// src/migrations/add-translations.ts
|
|
3627
|
+
// src/migrations/persistent/add-translations.ts
|
|
3407
3628
|
var APPLICATIONS = ["client", "login"];
|
|
3408
3629
|
var skipped = [];
|
|
3409
3630
|
function warnSkipped(message) {
|
|
@@ -3444,9 +3665,9 @@ async function updateApplication(cwd, targetVersion, refs, application) {
|
|
|
3444
3665
|
}
|
|
3445
3666
|
try {
|
|
3446
3667
|
writeCsvFile(import_path.default.join(cwd, relativePath), local);
|
|
3447
|
-
} catch (
|
|
3668
|
+
} catch (error2) {
|
|
3448
3669
|
warnSkipped(
|
|
3449
|
-
`Could not write ${relativePath} (${
|
|
3670
|
+
`Could not write ${relativePath} (${error2.message}); translations not added`
|
|
3450
3671
|
);
|
|
3451
3672
|
return;
|
|
3452
3673
|
}
|
|
@@ -3466,9 +3687,9 @@ function readTemplate(contents) {
|
|
|
3466
3687
|
async function listRefs(targetVersion) {
|
|
3467
3688
|
try {
|
|
3468
3689
|
return await candidateRefs(targetVersion);
|
|
3469
|
-
} catch (
|
|
3690
|
+
} catch (error2) {
|
|
3470
3691
|
warnSkipped(
|
|
3471
|
-
`Could not list the ${targetVersion} refs on GitHub (${
|
|
3692
|
+
`Could not list the ${targetVersion} refs on GitHub (${error2.message}); translations not added`
|
|
3472
3693
|
);
|
|
3473
3694
|
return void 0;
|
|
3474
3695
|
}
|
|
@@ -3481,9 +3702,9 @@ async function main(targetVersion) {
|
|
|
3481
3702
|
for (const application of APPLICATIONS) {
|
|
3482
3703
|
try {
|
|
3483
3704
|
await updateApplication(cwd, targetVersion, refs, application);
|
|
3484
|
-
} catch (
|
|
3705
|
+
} catch (error2) {
|
|
3485
3706
|
warnSkipped(
|
|
3486
|
-
`Could not read ${application}.csv from the country config template on GitHub (${
|
|
3707
|
+
`Could not read ${application}.csv from the country config template on GitHub (${error2.message}); ${application}.csv not updated`
|
|
3487
3708
|
);
|
|
3488
3709
|
}
|
|
3489
3710
|
}
|
|
@@ -3499,11 +3720,278 @@ async function main(targetVersion) {
|
|
|
3499
3720
|
}
|
|
3500
3721
|
}
|
|
3501
3722
|
|
|
3502
|
-
// src/migrations/
|
|
3723
|
+
// src/migrations/move-declaration-to-declare-action.ts
|
|
3503
3724
|
var import_ts_morph = require("ts-morph");
|
|
3504
3725
|
var import_path2 = __toESM(require("path"));
|
|
3505
|
-
var
|
|
3726
|
+
var DEFINE_CONFIG_NAME = "defineConfig";
|
|
3506
3727
|
var DECLARATION_PROPERTY_NAME = "declaration";
|
|
3728
|
+
var ACTIONS_PROPERTY_NAME = "actions";
|
|
3729
|
+
var DECLARE_ACTION_TYPE = "DECLARE";
|
|
3730
|
+
function location(node) {
|
|
3731
|
+
const relPath = import_path2.default.relative(
|
|
3732
|
+
process.cwd(),
|
|
3733
|
+
node.getSourceFile().getFilePath()
|
|
3734
|
+
);
|
|
3735
|
+
return `${relPath}:${node.getStartLineNumber()}`;
|
|
3736
|
+
}
|
|
3737
|
+
function isToolkitDefineConfigCall(call) {
|
|
3738
|
+
const symbol = call.getExpression().getSymbol();
|
|
3739
|
+
const resolved = symbol?.getAliasedSymbol() ?? symbol;
|
|
3740
|
+
if (resolved?.getName() !== DEFINE_CONFIG_NAME) {
|
|
3741
|
+
return false;
|
|
3742
|
+
}
|
|
3743
|
+
return resolved.getDeclarations().some((declaration) => declaration.getSourceFile().isDeclarationFile());
|
|
3744
|
+
}
|
|
3745
|
+
function findProperty(literal, name) {
|
|
3746
|
+
const property = literal.getProperty(name);
|
|
3747
|
+
return import_ts_morph.Node.isPropertyAssignment(property) || import_ts_morph.Node.isShorthandPropertyAssignment(property) ? property : void 0;
|
|
3748
|
+
}
|
|
3749
|
+
function mayHaveDeclareType(actionType, node) {
|
|
3750
|
+
const typeProperty = actionType.getProperty("type");
|
|
3751
|
+
if (!typeProperty) {
|
|
3752
|
+
return true;
|
|
3753
|
+
}
|
|
3754
|
+
const type = typeProperty.getTypeAtLocation(node);
|
|
3755
|
+
const values = type.isUnion() ? type.getUnionTypes() : [type];
|
|
3756
|
+
return !values.every(
|
|
3757
|
+
(value) => value.isStringLiteral() && value.getLiteralValue() !== DECLARE_ACTION_TYPE
|
|
3758
|
+
);
|
|
3759
|
+
}
|
|
3760
|
+
function mayBeDeclareAction(node) {
|
|
3761
|
+
if (import_ts_morph.Node.isObjectLiteralExpression(node)) {
|
|
3762
|
+
return isDeclareAction(node);
|
|
3763
|
+
}
|
|
3764
|
+
if (import_ts_morph.Node.isSpreadElement(node)) {
|
|
3765
|
+
const arrayType = node.getExpression().getType();
|
|
3766
|
+
const elementTypes = arrayType.isTuple() ? arrayType.getTupleElements() : [arrayType.getArrayElementType()];
|
|
3767
|
+
return elementTypes.some(
|
|
3768
|
+
(elementType) => !elementType || mayHaveDeclareType(elementType, node)
|
|
3769
|
+
);
|
|
3770
|
+
}
|
|
3771
|
+
return mayHaveDeclareType(node.getType(), node);
|
|
3772
|
+
}
|
|
3773
|
+
function isDeclareAction(literal) {
|
|
3774
|
+
const type = findProperty(literal, "type");
|
|
3775
|
+
return import_ts_morph.Node.isPropertyAssignment(type) && type.getInitializerOrThrow().getType().getLiteralValue() === DECLARE_ACTION_TYPE;
|
|
3776
|
+
}
|
|
3777
|
+
function findDeclareAction(config) {
|
|
3778
|
+
const actions = findProperty(config, ACTIONS_PROPERTY_NAME);
|
|
3779
|
+
const actionsValue = import_ts_morph.Node.isPropertyAssignment(actions) ? actions.getInitializer() : void 0;
|
|
3780
|
+
if (!import_ts_morph.Node.isArrayLiteralExpression(actionsValue)) {
|
|
3781
|
+
console.warn(
|
|
3782
|
+
` [${location(config)}] Skipped: \`${ACTIONS_PROPERTY_NAME}\` is not an array literal. Move \`${DECLARATION_PROPERTY_NAME}\` onto the ${DECLARE_ACTION_TYPE} action by hand.`
|
|
3783
|
+
);
|
|
3784
|
+
return void 0;
|
|
3785
|
+
}
|
|
3786
|
+
const candidates = actionsValue.getElements().filter(mayBeDeclareAction);
|
|
3787
|
+
if (candidates.length !== 1 || !import_ts_morph.Node.isObjectLiteralExpression(candidates[0])) {
|
|
3788
|
+
console.warn(
|
|
3789
|
+
` [${location(config)}] Skipped: could not find exactly one ${DECLARE_ACTION_TYPE} action written as an object literal in \`${ACTIONS_PROPERTY_NAME}\`. Move \`${DECLARATION_PROPERTY_NAME}\` onto it by hand.`
|
|
3790
|
+
);
|
|
3791
|
+
return void 0;
|
|
3792
|
+
}
|
|
3793
|
+
const declareAction = candidates[0];
|
|
3794
|
+
if (findProperty(declareAction, DECLARATION_PROPERTY_NAME)) {
|
|
3795
|
+
console.warn(
|
|
3796
|
+
` [${location(config)}] Skipped: \`${DECLARATION_PROPERTY_NAME}\` is set both at the top level and on the ${DECLARE_ACTION_TYPE} action. Keep only the one on the action.`
|
|
3797
|
+
);
|
|
3798
|
+
return void 0;
|
|
3799
|
+
}
|
|
3800
|
+
return declareAction;
|
|
3801
|
+
}
|
|
3802
|
+
function indentationOf(node) {
|
|
3803
|
+
const text = node.getSourceFile().getFullText();
|
|
3804
|
+
const lineStart = text.lastIndexOf("\n", node.getStart() - 1) + 1;
|
|
3805
|
+
return /^[ \t]*/.exec(text.slice(lineStart))?.[0] ?? "";
|
|
3806
|
+
}
|
|
3807
|
+
function restOfLine(text, position) {
|
|
3808
|
+
const lineEnd = text.indexOf("\n", position);
|
|
3809
|
+
return text.slice(position, lineEnd === -1 ? text.length : lineEnd);
|
|
3810
|
+
}
|
|
3811
|
+
function isOnlyComments(text) {
|
|
3812
|
+
return /^\s*(?:\/\/.*|\/\*.*?\*\/\s*)*$/.test(text);
|
|
3813
|
+
}
|
|
3814
|
+
function layoutOf(property) {
|
|
3815
|
+
const text = property.getSourceFile().getFullText();
|
|
3816
|
+
const next = property.getNextSibling();
|
|
3817
|
+
const hasComma = next?.getKind() === import_ts_morph.SyntaxKind.CommaToken;
|
|
3818
|
+
const end = next && hasComma ? next.getEnd() : property.getEnd();
|
|
3819
|
+
const trailing = restOfLine(text, end);
|
|
3820
|
+
const lineBreak = text.slice(property.getFullStart(), property.getStart()).indexOf("\n");
|
|
3821
|
+
if (lineBreak === -1 || !isOnlyComments(trailing)) {
|
|
3822
|
+
return {
|
|
3823
|
+
ownsLines: false,
|
|
3824
|
+
start: property.getStart(true),
|
|
3825
|
+
end,
|
|
3826
|
+
hasComma,
|
|
3827
|
+
trailingComment: ""
|
|
3828
|
+
};
|
|
3829
|
+
}
|
|
3830
|
+
const firstLine = property.getFullStart() + lineBreak + 1;
|
|
3831
|
+
return {
|
|
3832
|
+
ownsLines: true,
|
|
3833
|
+
start: firstLine + (/^\s*/.exec(text.slice(firstLine))?.[0].length ?? 0),
|
|
3834
|
+
end,
|
|
3835
|
+
hasComma,
|
|
3836
|
+
trailingComment: trailing.trimEnd()
|
|
3837
|
+
};
|
|
3838
|
+
}
|
|
3839
|
+
function insertAt(position, text) {
|
|
3840
|
+
return { start: position, end: position, text };
|
|
3841
|
+
}
|
|
3842
|
+
function insertIntoDeclareAction(declareAction, property) {
|
|
3843
|
+
const anchor = declareAction.getProperty("label") ?? declareAction.getPropertyOrThrow("type");
|
|
3844
|
+
const text = property.getSourceFile().getFullText();
|
|
3845
|
+
const anchorLayout = layoutOf(anchor);
|
|
3846
|
+
const layout = layoutOf(property);
|
|
3847
|
+
const indent = indentationOf(anchor);
|
|
3848
|
+
const oldIndent = indentationOf(property);
|
|
3849
|
+
const reindent = (lines) => lines.split("\n").map(
|
|
3850
|
+
(line2, index) => index > 0 && line2.startsWith(oldIndent) ? indent + line2.slice(oldIndent.length) : line2
|
|
3851
|
+
).join("\n");
|
|
3852
|
+
if (anchorLayout.ownsLines) {
|
|
3853
|
+
const moved = reindent(text.slice(layout.start, property.getEnd()));
|
|
3854
|
+
const position = anchorLayout.end + restOfLine(text, anchorLayout.end).length;
|
|
3855
|
+
const insertion = `
|
|
3856
|
+
${indent}${moved}${anchorLayout.hasComma ? "," : ""}${layout.trailingComment}`;
|
|
3857
|
+
if (anchorLayout.hasComma) {
|
|
3858
|
+
return [insertAt(position, insertion)];
|
|
3859
|
+
}
|
|
3860
|
+
return position === anchor.getEnd() ? [insertAt(position, `,${insertion}`)] : [insertAt(anchor.getEnd(), ","), insertAt(position, insertion)];
|
|
3861
|
+
}
|
|
3862
|
+
const droppedComments = text.slice(layout.start, property.getStart(true)).trim() !== "" || layout.trailingComment !== "";
|
|
3863
|
+
if (droppedComments) {
|
|
3864
|
+
console.warn(
|
|
3865
|
+
` [${location(property)}] The comments next to \`${DECLARATION_PROPERTY_NAME}\` were not moved with it. Move them onto the ${DECLARE_ACTION_TYPE} action by hand.`
|
|
3866
|
+
);
|
|
3867
|
+
}
|
|
3868
|
+
const isMultiLine = declareAction.getText().includes("\n");
|
|
3869
|
+
const separator = isMultiLine ? `,
|
|
3870
|
+
${indent}` : ", ";
|
|
3871
|
+
return [
|
|
3872
|
+
insertAt(anchor.getEnd(), `${separator}${reindent(property.getText(true))}`)
|
|
3873
|
+
];
|
|
3874
|
+
}
|
|
3875
|
+
function removeFromConfig(property) {
|
|
3876
|
+
const text = property.getSourceFile().getFullText();
|
|
3877
|
+
const layout = layoutOf(property);
|
|
3878
|
+
const previousComma = property.getPreviousSiblings().find((sibling) => !isOnlyComments(sibling.getText()))?.asKind(import_ts_morph.SyntaxKind.CommaToken);
|
|
3879
|
+
if (layout.ownsLines) {
|
|
3880
|
+
const lines = {
|
|
3881
|
+
start: text.lastIndexOf("\n", layout.start - 1),
|
|
3882
|
+
end: layout.end + restOfLine(text, layout.end).length,
|
|
3883
|
+
text: ""
|
|
3884
|
+
};
|
|
3885
|
+
return !layout.hasComma && previousComma ? [
|
|
3886
|
+
lines,
|
|
3887
|
+
{
|
|
3888
|
+
start: previousComma.getStart(),
|
|
3889
|
+
end: previousComma.getEnd(),
|
|
3890
|
+
text: ""
|
|
3891
|
+
}
|
|
3892
|
+
] : [lines];
|
|
3893
|
+
}
|
|
3894
|
+
if (layout.hasComma) {
|
|
3895
|
+
return [{ start: property.getFullStart(), end: layout.end, text: "" }];
|
|
3896
|
+
}
|
|
3897
|
+
return [
|
|
3898
|
+
{
|
|
3899
|
+
start: (previousComma ?? property).getStart(),
|
|
3900
|
+
end: property.getEnd(),
|
|
3901
|
+
text: ""
|
|
3902
|
+
}
|
|
3903
|
+
];
|
|
3904
|
+
}
|
|
3905
|
+
function findConfigLiteral(call) {
|
|
3906
|
+
const config = call.getArguments()[0];
|
|
3907
|
+
if (!config || import_ts_morph.Node.isObjectLiteralExpression(config)) {
|
|
3908
|
+
return config;
|
|
3909
|
+
}
|
|
3910
|
+
if (config.getType().getProperty(DECLARATION_PROPERTY_NAME)) {
|
|
3911
|
+
console.warn(
|
|
3912
|
+
` [${location(config)}] Skipped: \`${DEFINE_CONFIG_NAME}\` is not given an object literal. If its config has a top-level \`${DECLARATION_PROPERTY_NAME}\`, move it onto the ${DECLARE_ACTION_TYPE} action by hand.`
|
|
3913
|
+
);
|
|
3914
|
+
}
|
|
3915
|
+
return void 0;
|
|
3916
|
+
}
|
|
3917
|
+
function moveDeclarationToDeclareAction(sourceFile) {
|
|
3918
|
+
const configs = sourceFile.getDescendantsOfKind(import_ts_morph.SyntaxKind.CallExpression).filter(isToolkitDefineConfigCall).map(findConfigLiteral).filter(import_ts_morph.Node.isObjectLiteralExpression);
|
|
3919
|
+
const edits = [];
|
|
3920
|
+
let changes = 0;
|
|
3921
|
+
for (const config of configs) {
|
|
3922
|
+
const declaration = findProperty(config, DECLARATION_PROPERTY_NAME);
|
|
3923
|
+
if (!declaration) {
|
|
3924
|
+
continue;
|
|
3925
|
+
}
|
|
3926
|
+
const declareAction = findDeclareAction(config);
|
|
3927
|
+
if (!declareAction) {
|
|
3928
|
+
continue;
|
|
3929
|
+
}
|
|
3930
|
+
console.log(
|
|
3931
|
+
` [${location(declaration)}] Moved \`${declaration.getText()}\` onto the ${DECLARE_ACTION_TYPE} action`
|
|
3932
|
+
);
|
|
3933
|
+
edits.push(
|
|
3934
|
+
...insertIntoDeclareAction(declareAction, declaration),
|
|
3935
|
+
...removeFromConfig(declaration)
|
|
3936
|
+
);
|
|
3937
|
+
changes++;
|
|
3938
|
+
}
|
|
3939
|
+
if (changes === 0) {
|
|
3940
|
+
return 0;
|
|
3941
|
+
}
|
|
3942
|
+
const text = edits.sort((a, b) => b.start - a.start).reduce(
|
|
3943
|
+
(result, edit) => result.slice(0, edit.start) + edit.text + result.slice(edit.end),
|
|
3944
|
+
sourceFile.getFullText()
|
|
3945
|
+
);
|
|
3946
|
+
sourceFile.replaceWithText(text);
|
|
3947
|
+
return changes;
|
|
3948
|
+
}
|
|
3949
|
+
async function main2() {
|
|
3950
|
+
const srcDir = import_path2.default.join(process.cwd(), "src");
|
|
3951
|
+
console.log(`Scanning for top-level event declarations in: ${srcDir}
|
|
3952
|
+
`);
|
|
3953
|
+
const project = new import_ts_morph.Project({
|
|
3954
|
+
tsConfigFilePath: import_path2.default.resolve(srcDir, "../tsconfig.json"),
|
|
3955
|
+
skipAddingFilesFromTsConfig: false
|
|
3956
|
+
});
|
|
3957
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
3958
|
+
const fp = sf.getFilePath();
|
|
3959
|
+
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
3960
|
+
});
|
|
3961
|
+
console.log(`Found ${sourceFiles.length} source file(s) to analyse.
|
|
3962
|
+
`);
|
|
3963
|
+
let totalChanges = 0;
|
|
3964
|
+
const modifiedFiles = [];
|
|
3965
|
+
for (const sourceFile of sourceFiles) {
|
|
3966
|
+
const changes = moveDeclarationToDeclareAction(sourceFile);
|
|
3967
|
+
if (changes > 0) {
|
|
3968
|
+
totalChanges += changes;
|
|
3969
|
+
modifiedFiles.push(sourceFile);
|
|
3970
|
+
}
|
|
3971
|
+
}
|
|
3972
|
+
if (modifiedFiles.length === 0) {
|
|
3973
|
+
console.log("No top-level event declarations found. Nothing to do.");
|
|
3974
|
+
return;
|
|
3975
|
+
}
|
|
3976
|
+
console.log(`
|
|
3977
|
+
Saving ${modifiedFiles.length} modified file(s)...`);
|
|
3978
|
+
for (const sourceFile of modifiedFiles) {
|
|
3979
|
+
await sourceFile.save();
|
|
3980
|
+
console.log(
|
|
3981
|
+
` Saved: ${import_path2.default.relative(process.cwd(), sourceFile.getFilePath())}`
|
|
3982
|
+
);
|
|
3983
|
+
}
|
|
3984
|
+
console.log(
|
|
3985
|
+
`
|
|
3986
|
+
Done. Moved ${totalChanges} declaration(s) across ${modifiedFiles.length} file(s).`
|
|
3987
|
+
);
|
|
3988
|
+
}
|
|
3989
|
+
|
|
3990
|
+
// src/migrations/read-declaration-through-helper.ts
|
|
3991
|
+
var import_ts_morph2 = require("ts-morph");
|
|
3992
|
+
var import_path3 = __toESM(require("path"));
|
|
3993
|
+
var EVENT_CONFIG_TYPE_NAME = "EventConfig";
|
|
3994
|
+
var DECLARATION_PROPERTY_NAME2 = "declaration";
|
|
3507
3995
|
var GET_DECLARATION_NAME = "getDeclaration";
|
|
3508
3996
|
var TOOLKIT_EVENTS_MODULE = "@opencrvs/toolkit/events";
|
|
3509
3997
|
function isToolkitEventConfig(type) {
|
|
@@ -3515,20 +4003,20 @@ function isToolkitEventConfig(type) {
|
|
|
3515
4003
|
return symbol.getDeclarations().some((declaration) => declaration.getSourceFile().isDeclarationFile());
|
|
3516
4004
|
}
|
|
3517
4005
|
function isDeclarationReadOnEventConfig(node) {
|
|
3518
|
-
return node.getName() ===
|
|
4006
|
+
return node.getName() === DECLARATION_PROPERTY_NAME2 && isToolkitEventConfig(node.getExpression().getType());
|
|
3519
4007
|
}
|
|
3520
4008
|
function isAssignmentOperator(kind) {
|
|
3521
|
-
return kind >=
|
|
4009
|
+
return kind >= import_ts_morph2.SyntaxKind.FirstAssignment && kind <= import_ts_morph2.SyntaxKind.LastAssignment;
|
|
3522
4010
|
}
|
|
3523
4011
|
function isWriteTarget(node) {
|
|
3524
4012
|
const parent = node.getParent();
|
|
3525
|
-
if (
|
|
4013
|
+
if (import_ts_morph2.Node.isDeleteExpression(parent)) {
|
|
3526
4014
|
return true;
|
|
3527
4015
|
}
|
|
3528
|
-
return
|
|
4016
|
+
return import_ts_morph2.Node.isBinaryExpression(parent) && parent.getLeft() === node && isAssignmentOperator(parent.getOperatorToken().getKind());
|
|
3529
4017
|
}
|
|
3530
|
-
function
|
|
3531
|
-
const relPath =
|
|
4018
|
+
function location2(node) {
|
|
4019
|
+
const relPath = import_path3.default.relative(
|
|
3532
4020
|
process.cwd(),
|
|
3533
4021
|
node.getSourceFile().getFilePath()
|
|
3534
4022
|
);
|
|
@@ -3536,32 +4024,32 @@ function location(node) {
|
|
|
3536
4024
|
}
|
|
3537
4025
|
function warnDestructuredDeclarations(sourceFile) {
|
|
3538
4026
|
for (const pattern of sourceFile.getDescendantsOfKind(
|
|
3539
|
-
|
|
4027
|
+
import_ts_morph2.SyntaxKind.ObjectBindingPattern
|
|
3540
4028
|
)) {
|
|
3541
4029
|
const destructuresDeclaration = pattern.getElements().some(
|
|
3542
|
-
(element) => (element.getPropertyNameNode()?.getText() ?? element.getName()) ===
|
|
4030
|
+
(element) => (element.getPropertyNameNode()?.getText() ?? element.getName()) === DECLARATION_PROPERTY_NAME2
|
|
3543
4031
|
);
|
|
3544
4032
|
if (destructuresDeclaration && isToolkitEventConfig(pattern.getType())) {
|
|
3545
4033
|
console.warn(
|
|
3546
|
-
` [${
|
|
4034
|
+
` [${location2(pattern)}] Destructures \`${DECLARATION_PROPERTY_NAME2}\` from an EventConfig. Rewrite it to use \`${GET_DECLARATION_NAME}(config)\` by hand.`
|
|
3547
4035
|
);
|
|
3548
4036
|
}
|
|
3549
4037
|
}
|
|
3550
4038
|
}
|
|
3551
4039
|
function warnSpreadDeclarations(sourceFile) {
|
|
3552
4040
|
for (const literal of sourceFile.getDescendantsOfKind(
|
|
3553
|
-
|
|
4041
|
+
import_ts_morph2.SyntaxKind.ObjectLiteralExpression
|
|
3554
4042
|
)) {
|
|
3555
4043
|
const properties = literal.getProperties();
|
|
3556
4044
|
const spreadsEventConfig = properties.some(
|
|
3557
|
-
(property) =>
|
|
4045
|
+
(property) => import_ts_morph2.Node.isSpreadAssignment(property) && isToolkitEventConfig(property.getExpression().getType())
|
|
3558
4046
|
);
|
|
3559
4047
|
const setsDeclaration = properties.some(
|
|
3560
|
-
(property) => (
|
|
4048
|
+
(property) => (import_ts_morph2.Node.isPropertyAssignment(property) || import_ts_morph2.Node.isShorthandPropertyAssignment(property)) && property.getName() === DECLARATION_PROPERTY_NAME2
|
|
3561
4049
|
);
|
|
3562
4050
|
if (spreadsEventConfig && setsDeclaration) {
|
|
3563
4051
|
console.warn(
|
|
3564
|
-
` [${
|
|
4052
|
+
` [${location2(literal)}] Spreads an EventConfig and sets \`${DECLARATION_PROPERTY_NAME2}\` next to it. The spread config already has a \`${DECLARATION_PROPERTY_NAME2}\` on its DECLARE action, so replace that one by hand.`
|
|
3565
4053
|
);
|
|
3566
4054
|
}
|
|
3567
4055
|
}
|
|
@@ -3615,16 +4103,16 @@ function addGetDeclarationImport(sourceFile) {
|
|
|
3615
4103
|
function rewriteDeclarationReads(sourceFile) {
|
|
3616
4104
|
warnDestructuredDeclarations(sourceFile);
|
|
3617
4105
|
warnSpreadDeclarations(sourceFile);
|
|
3618
|
-
const reads = sourceFile.getDescendantsOfKind(
|
|
4106
|
+
const reads = sourceFile.getDescendantsOfKind(import_ts_morph2.SyntaxKind.PropertyAccessExpression).filter(isDeclarationReadOnEventConfig).filter((node) => {
|
|
3619
4107
|
if (node.hasQuestionDotToken()) {
|
|
3620
4108
|
console.warn(
|
|
3621
|
-
` [${
|
|
4109
|
+
` [${location2(node)}] Skipped optional chain \`${node.getText()}\`. Rewrite it to use \`${GET_DECLARATION_NAME}()\` by hand.`
|
|
3622
4110
|
);
|
|
3623
4111
|
return false;
|
|
3624
4112
|
}
|
|
3625
4113
|
if (isWriteTarget(node)) {
|
|
3626
4114
|
console.warn(
|
|
3627
|
-
` [${
|
|
4115
|
+
` [${location2(node)}] Skipped write to \`${node.getText()}\`. Set \`${DECLARATION_PROPERTY_NAME2}\` on the DECLARE action instead.`
|
|
3628
4116
|
);
|
|
3629
4117
|
return false;
|
|
3630
4118
|
}
|
|
@@ -3636,13 +4124,13 @@ function rewriteDeclarationReads(sourceFile) {
|
|
|
3636
4124
|
const getDeclarationName = findGetDeclarationName(sourceFile);
|
|
3637
4125
|
if (!getDeclarationName) {
|
|
3638
4126
|
console.warn(
|
|
3639
|
-
` [${
|
|
4127
|
+
` [${location2(reads[reads.length - 1])}] Skipped ${reads.length} read(s): the file already declares its own \`${GET_DECLARATION_NAME}\`. Rewrite them to use the toolkit's \`${GET_DECLARATION_NAME}()\` by hand.`
|
|
3640
4128
|
);
|
|
3641
4129
|
return 0;
|
|
3642
4130
|
}
|
|
3643
4131
|
for (const read of reads) {
|
|
3644
4132
|
console.log(
|
|
3645
|
-
` [${
|
|
4133
|
+
` [${location2(read)}] ${read.getText()} -> ${getDeclarationName}(${read.getExpression().getText()})`
|
|
3646
4134
|
);
|
|
3647
4135
|
read.replaceWithText(
|
|
3648
4136
|
`${getDeclarationName}(${read.getExpression().getText()})`
|
|
@@ -3651,12 +4139,12 @@ function rewriteDeclarationReads(sourceFile) {
|
|
|
3651
4139
|
addGetDeclarationImport(sourceFile);
|
|
3652
4140
|
return reads.length;
|
|
3653
4141
|
}
|
|
3654
|
-
async function
|
|
3655
|
-
const srcDir =
|
|
4142
|
+
async function main3() {
|
|
4143
|
+
const srcDir = import_path3.default.join(process.cwd(), "src");
|
|
3656
4144
|
console.log(`Scanning for EventConfig declaration reads in: ${srcDir}
|
|
3657
4145
|
`);
|
|
3658
|
-
const project = new
|
|
3659
|
-
tsConfigFilePath:
|
|
4146
|
+
const project = new import_ts_morph2.Project({
|
|
4147
|
+
tsConfigFilePath: import_path3.default.resolve(srcDir, "../tsconfig.json"),
|
|
3660
4148
|
skipAddingFilesFromTsConfig: false
|
|
3661
4149
|
});
|
|
3662
4150
|
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
@@ -3683,7 +4171,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
3683
4171
|
for (const sourceFile of modifiedFiles) {
|
|
3684
4172
|
await sourceFile.save();
|
|
3685
4173
|
console.log(
|
|
3686
|
-
` Saved: ${
|
|
4174
|
+
` Saved: ${import_path3.default.relative(process.cwd(), sourceFile.getFilePath())}`
|
|
3687
4175
|
);
|
|
3688
4176
|
}
|
|
3689
4177
|
console.log(
|
|
@@ -3692,15 +4180,183 @@ Done. Rewrote ${totalChanges} declaration read(s) across ${modifiedFiles.length}
|
|
|
3692
4180
|
);
|
|
3693
4181
|
}
|
|
3694
4182
|
|
|
3695
|
-
// src/migrations/
|
|
3696
|
-
|
|
4183
|
+
// src/migrations/persistent/update-toolkit-dependency.ts
|
|
4184
|
+
var import_fs3 = __toESM(require("fs"));
|
|
4185
|
+
var import_path5 = __toESM(require("path"));
|
|
4186
|
+
|
|
4187
|
+
// src/migrations/persistent/check-upgrade-path.ts
|
|
4188
|
+
var import_fs2 = __toESM(require("fs"));
|
|
4189
|
+
var import_path4 = __toESM(require("path"));
|
|
4190
|
+
var TOOLKIT_PACKAGE_NAME = "@opencrvs/toolkit";
|
|
4191
|
+
function findMajorMinor(version) {
|
|
4192
|
+
const match = /(\d+)\.(\d+)/.exec(version);
|
|
4193
|
+
return match ? { major: Number(match[1]), minor: Number(match[2]) } : void 0;
|
|
4194
|
+
}
|
|
4195
|
+
function format({ major, minor }) {
|
|
4196
|
+
return `${major}.${minor}`;
|
|
4197
|
+
}
|
|
4198
|
+
function findCountryConfigToolkitVersion(cwd) {
|
|
4199
|
+
try {
|
|
4200
|
+
const packageJson = JSON.parse(
|
|
4201
|
+
import_fs2.default.readFileSync(import_path4.default.join(cwd, "package.json"), "utf-8")
|
|
4202
|
+
);
|
|
4203
|
+
return packageJson.dependencies?.[TOOLKIT_PACKAGE_NAME] ?? packageJson.devDependencies?.[TOOLKIT_PACKAGE_NAME];
|
|
4204
|
+
} catch {
|
|
4205
|
+
return void 0;
|
|
4206
|
+
}
|
|
4207
|
+
}
|
|
4208
|
+
function checkUpgradePath(countryConfigToolkitVersion, toolkitVersion) {
|
|
4209
|
+
const target = findMajorMinor(toolkitVersion);
|
|
4210
|
+
const current = countryConfigToolkitVersion ? findMajorMinor(countryConfigToolkitVersion) : void 0;
|
|
4211
|
+
if (!target || !current) {
|
|
4212
|
+
return {
|
|
4213
|
+
status: "unknown",
|
|
4214
|
+
message: `Could not tell which version the country config is on from its ${TOOLKIT_PACKAGE_NAME} dependency (${countryConfigToolkitVersion ?? "not found"}). Make sure it is on the version before ${toolkitVersion}: upgrade one minor version at a time.`
|
|
4215
|
+
};
|
|
4216
|
+
}
|
|
4217
|
+
const isSameVersion = current.major === target.major && current.minor === target.minor;
|
|
4218
|
+
const isPreviousMinor = current.major === target.major && current.minor === target.minor - 1;
|
|
4219
|
+
const isPreviousMajor = target.minor === 0 && current.major === target.major - 1;
|
|
4220
|
+
if (isSameVersion || isPreviousMinor || isPreviousMajor) {
|
|
4221
|
+
return { status: "ok" };
|
|
4222
|
+
}
|
|
4223
|
+
const isNewer = current.major > target.major || current.major === target.major && current.minor > target.minor;
|
|
4224
|
+
if (isNewer) {
|
|
4225
|
+
return {
|
|
4226
|
+
status: "blocked",
|
|
4227
|
+
message: `The country config is already on ${format(current)}, newer than toolkit ${toolkitVersion}. Run the upgrade with the toolkit of the version you are upgrading to.`
|
|
4228
|
+
};
|
|
4229
|
+
}
|
|
4230
|
+
const upgradesFrom = target.minor > 0 ? format({ major: target.major, minor: target.minor - 1 }) : `the last ${target.major - 1}.x`;
|
|
4231
|
+
const nextStep = current.major === target.major ? `: run \`npx ${TOOLKIT_PACKAGE_NAME}@${format({ major: current.major, minor: current.minor + 1 })} upgrade\` first` : "";
|
|
4232
|
+
return {
|
|
4233
|
+
status: "blocked",
|
|
4234
|
+
message: `The country config is on ${format(current)}, but toolkit ${toolkitVersion} only upgrades from ${upgradesFrom}. Upgrade one minor version at a time${nextStep}.`
|
|
4235
|
+
};
|
|
4236
|
+
}
|
|
4237
|
+
|
|
4238
|
+
// src/migrations/persistent/update-toolkit-dependency.ts
|
|
4239
|
+
var DEPENDENCY_PATTERN = new RegExp(
|
|
4240
|
+
`("${TOOLKIT_PACKAGE_NAME}"\\s*:\\s*")([^"]*)(")`,
|
|
4241
|
+
"g"
|
|
4242
|
+
);
|
|
4243
|
+
function updateToolkitDependency(packageJson, toolkitVersion) {
|
|
4244
|
+
const updated = packageJson.replace(
|
|
4245
|
+
DEPENDENCY_PATTERN,
|
|
4246
|
+
(match, before, version, after) => {
|
|
4247
|
+
if (!findMajorMinor(version)) {
|
|
4248
|
+
return match;
|
|
4249
|
+
}
|
|
4250
|
+
const range = /^[\^~]?/.exec(version)?.[0] ?? "";
|
|
4251
|
+
return `${before}${range}${toolkitVersion}${after}`;
|
|
4252
|
+
}
|
|
4253
|
+
);
|
|
4254
|
+
return updated === packageJson ? void 0 : updated;
|
|
4255
|
+
}
|
|
4256
|
+
async function main4(toolkitVersion) {
|
|
4257
|
+
const packageJsonPath = import_path5.default.join(process.cwd(), "package.json");
|
|
4258
|
+
if (!import_fs3.default.existsSync(packageJsonPath)) {
|
|
4259
|
+
console.log(`No package.json found. Skipping ${TOOLKIT_PACKAGE_NAME}.`);
|
|
4260
|
+
return;
|
|
4261
|
+
}
|
|
4262
|
+
const updated = updateToolkitDependency(
|
|
4263
|
+
import_fs3.default.readFileSync(packageJsonPath, "utf-8"),
|
|
4264
|
+
toolkitVersion
|
|
4265
|
+
);
|
|
4266
|
+
if (!updated) {
|
|
4267
|
+
console.log(
|
|
4268
|
+
`${TOOLKIT_PACKAGE_NAME} in package.json needs no update. Nothing to do.`
|
|
4269
|
+
);
|
|
4270
|
+
return;
|
|
4271
|
+
}
|
|
4272
|
+
import_fs3.default.writeFileSync(packageJsonPath, updated);
|
|
4273
|
+
console.log(
|
|
4274
|
+
`Updated ${TOOLKIT_PACKAGE_NAME} to ${toolkitVersion} in package.json. Install the dependencies again to use it.`
|
|
4275
|
+
);
|
|
4276
|
+
}
|
|
4277
|
+
|
|
4278
|
+
// src/migrations/replace-incomplete-flag.ts
|
|
4279
|
+
var import_ts_morph3 = require("ts-morph");
|
|
4280
|
+
var import_path6 = __toESM(require("path"));
|
|
4281
|
+
var INCOMPLETE = "InherentFlags.INCOMPLETE";
|
|
4282
|
+
var NOTIFIED_STATUS = `{ type: 'exact', term: EventStatus.enum.NOTIFIED }`;
|
|
4283
|
+
function ensureEventStatusImport(sourceFile) {
|
|
4284
|
+
const importDeclaration = sourceFile.getImportDeclarations().find(
|
|
4285
|
+
(declaration) => declaration.getNamedImports().some((named) => named.getName() === "InherentFlags")
|
|
4286
|
+
);
|
|
4287
|
+
const hasEventStatus = importDeclaration?.getNamedImports().some((named) => named.getName() === "EventStatus");
|
|
4288
|
+
if (importDeclaration && !hasEventStatus) {
|
|
4289
|
+
importDeclaration.addNamedImport("EventStatus");
|
|
4290
|
+
}
|
|
4291
|
+
}
|
|
4292
|
+
function replaceIncompleteFlag(sourceFile) {
|
|
4293
|
+
let changed = false;
|
|
4294
|
+
const anyOfIncomplete = sourceFile.getDescendantsOfKind(import_ts_morph3.SyntaxKind.PropertyAccessExpression).filter((node) => node.getText() === INCOMPLETE).map((node) => node.getParent()).filter(import_ts_morph3.Node.isArrayLiteralExpression).filter((array2) => {
|
|
4295
|
+
const anyOf = array2.getParent();
|
|
4296
|
+
const flags = anyOf?.getParent()?.getParent();
|
|
4297
|
+
return import_ts_morph3.Node.isPropertyAssignment(anyOf) && anyOf.getName() === "anyOf" && import_ts_morph3.Node.isPropertyAssignment(flags) && flags.getName() === "flags";
|
|
4298
|
+
});
|
|
4299
|
+
for (const array2 of anyOfIncomplete) {
|
|
4300
|
+
const anyOf = array2.getParentIfKindOrThrow(import_ts_morph3.SyntaxKind.PropertyAssignment);
|
|
4301
|
+
const flagsObject = anyOf.getParentIfKindOrThrow(
|
|
4302
|
+
import_ts_morph3.SyntaxKind.ObjectLiteralExpression
|
|
4303
|
+
);
|
|
4304
|
+
const flags = flagsObject.getParentIfKindOrThrow(
|
|
4305
|
+
import_ts_morph3.SyntaxKind.PropertyAssignment
|
|
4306
|
+
);
|
|
4307
|
+
const query = flags.getParentIfKindOrThrow(
|
|
4308
|
+
import_ts_morph3.SyntaxKind.ObjectLiteralExpression
|
|
4309
|
+
);
|
|
4310
|
+
array2.getElements().filter((element) => element.getText() === INCOMPLETE).forEach((element) => array2.removeElement(element));
|
|
4311
|
+
if (array2.getElements().length === 0) anyOf.remove();
|
|
4312
|
+
if (flagsObject.getProperties().length === 0) flags.remove();
|
|
4313
|
+
if (!query.getProperty("status")) {
|
|
4314
|
+
query.addPropertyAssignment({
|
|
4315
|
+
name: "status",
|
|
4316
|
+
initializer: NOTIFIED_STATUS
|
|
4317
|
+
});
|
|
4318
|
+
}
|
|
4319
|
+
changed = true;
|
|
4320
|
+
}
|
|
4321
|
+
if (changed) ensureEventStatusImport(sourceFile);
|
|
4322
|
+
const remaining = sourceFile.getDescendantsOfKind(import_ts_morph3.SyntaxKind.PropertyAccessExpression).filter((node) => node.getText() === INCOMPLETE).map((node) => node.getStartLineNumber());
|
|
4323
|
+
return { changed, remaining };
|
|
4324
|
+
}
|
|
4325
|
+
async function main5() {
|
|
4326
|
+
const project = new import_ts_morph3.Project({
|
|
4327
|
+
tsConfigFilePath: import_path6.default.join(process.cwd(), "tsconfig.json")
|
|
4328
|
+
});
|
|
4329
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => !sf.getFilePath().includes("/node_modules/"));
|
|
4330
|
+
for (const sourceFile of sourceFiles) {
|
|
4331
|
+
const relPath = import_path6.default.relative(process.cwd(), sourceFile.getFilePath());
|
|
4332
|
+
const { changed, remaining } = replaceIncompleteFlag(sourceFile);
|
|
4333
|
+
if (changed) {
|
|
4334
|
+
await sourceFile.save();
|
|
4335
|
+
console.log(
|
|
4336
|
+
` [${relPath}] Replaced the incomplete flag with the NOTIFIED status`
|
|
4337
|
+
);
|
|
4338
|
+
}
|
|
4339
|
+
for (const line2 of remaining) {
|
|
4340
|
+
console.warn(
|
|
4341
|
+
` [${relPath}:${line2}] ${INCOMPLETE} was removed, update this reference to use the NOTIFIED status`
|
|
4342
|
+
);
|
|
4343
|
+
}
|
|
4344
|
+
}
|
|
4345
|
+
}
|
|
4346
|
+
|
|
4347
|
+
// src/migrations/index.ts
|
|
4348
|
+
async function runUpgrade(toolkitVersion) {
|
|
4349
|
+
const [major, minor] = toolkitVersion.split(".");
|
|
3697
4350
|
await main2();
|
|
3698
|
-
await
|
|
4351
|
+
await main3();
|
|
4352
|
+
await main(`${major}.${minor}`);
|
|
4353
|
+
await main5();
|
|
4354
|
+
await main4(toolkitVersion);
|
|
3699
4355
|
}
|
|
3700
4356
|
|
|
3701
4357
|
// src/environment/index.ts
|
|
3702
|
-
var
|
|
3703
|
-
var
|
|
4358
|
+
var import_fs8 = require("fs");
|
|
4359
|
+
var import_path11 = require("path");
|
|
3704
4360
|
init_paths();
|
|
3705
4361
|
var REQUIRED_REPOSITORY_DIRECTORIES = [
|
|
3706
4362
|
".github/workflows",
|
|
@@ -3711,7 +4367,7 @@ function validateRepositoryStructure(repositoryRoot = process.cwd()) {
|
|
|
3711
4367
|
const missingDirectories = REQUIRED_REPOSITORY_DIRECTORIES.filter(
|
|
3712
4368
|
(directory) => {
|
|
3713
4369
|
try {
|
|
3714
|
-
return !(0,
|
|
4370
|
+
return !(0, import_fs8.statSync)((0, import_path11.resolve)(repositoryRoot, directory)).isDirectory();
|
|
3715
4371
|
} catch {
|
|
3716
4372
|
return true;
|
|
3717
4373
|
}
|
|
@@ -3752,7 +4408,7 @@ async function runEnvironmentSwarmToK8s() {
|
|
|
3752
4408
|
// src/verify/endpoints.ts
|
|
3753
4409
|
var import_colors = require("kleur/colors");
|
|
3754
4410
|
var z = __toESM(require("zod/v4"));
|
|
3755
|
-
var
|
|
4411
|
+
var REQUEST_TIMEOUT_MS2 = 15e3;
|
|
3756
4412
|
var DEFAULT_TARGET_URL = "http://localhost:3040";
|
|
3757
4413
|
var REQUIRED_PUBLIC_ENDPOINTS = [
|
|
3758
4414
|
{ method: "GET", path: "/client-config.js" },
|
|
@@ -3823,7 +4479,7 @@ async function requestStatus(url, method) {
|
|
|
3823
4479
|
try {
|
|
3824
4480
|
const response = await fetch(url, {
|
|
3825
4481
|
method,
|
|
3826
|
-
signal: AbortSignal.timeout(
|
|
4482
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS2),
|
|
3827
4483
|
// Sent without an Authorization header on purpose. A secured route
|
|
3828
4484
|
// rejects with 401/403 before ever reading the body.
|
|
3829
4485
|
headers: method === "POST" ? { "Content-Type": "application/json" } : void 0,
|
|
@@ -3858,7 +4514,7 @@ function toEventTriggerConfig(value) {
|
|
|
3858
4514
|
async function fetchEventConfigs(baseUrl) {
|
|
3859
4515
|
try {
|
|
3860
4516
|
const response = await fetch(`${baseUrl}/config/events`, {
|
|
3861
|
-
signal: AbortSignal.timeout(
|
|
4517
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS2)
|
|
3862
4518
|
});
|
|
3863
4519
|
if (!response.ok) {
|
|
3864
4520
|
return null;
|
|
@@ -3922,7 +4578,7 @@ var ServedTranslations = z.object({
|
|
|
3922
4578
|
async function fetchServedTranslations(baseUrl, application) {
|
|
3923
4579
|
try {
|
|
3924
4580
|
const response = await fetch(`${baseUrl}/content/${application}`, {
|
|
3925
|
-
signal: AbortSignal.timeout(
|
|
4581
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS2)
|
|
3926
4582
|
});
|
|
3927
4583
|
if (!response.ok) {
|
|
3928
4584
|
return null;
|
|
@@ -3938,10 +4594,10 @@ async function verifyTranslations(baseUrl) {
|
|
|
3938
4594
|
let refs;
|
|
3939
4595
|
try {
|
|
3940
4596
|
refs = await candidateRefs(TEMPLATE_VERSION);
|
|
3941
|
-
} catch (
|
|
4597
|
+
} catch (error2) {
|
|
3942
4598
|
console.log(
|
|
3943
4599
|
" " + (0, import_colors.yellow)(
|
|
3944
|
-
`Could not list the ${TEMPLATE_VERSION} refs on GitHub (${
|
|
4600
|
+
`Could not list the ${TEMPLATE_VERSION} refs on GitHub (${error2.message}); translations not checked.`
|
|
3945
4601
|
)
|
|
3946
4602
|
);
|
|
3947
4603
|
return 0;
|
|
@@ -3952,10 +4608,10 @@ async function verifyTranslations(baseUrl) {
|
|
|
3952
4608
|
let fetched;
|
|
3953
4609
|
try {
|
|
3954
4610
|
fetched = await fetchTemplate(refs, application);
|
|
3955
|
-
} catch (
|
|
4611
|
+
} catch (error2) {
|
|
3956
4612
|
console.log(
|
|
3957
4613
|
" " + (0, import_colors.yellow)(
|
|
3958
|
-
`Could not read ${application}.csv from the country config template on GitHub (${
|
|
4614
|
+
`Could not read ${application}.csv from the country config template on GitHub (${error2.message}); ${endpoint} not checked.`
|
|
3959
4615
|
)
|
|
3960
4616
|
);
|
|
3961
4617
|
continue;
|
|
@@ -4038,8 +4694,8 @@ async function runVerifyEndpoints(target = DEFAULT_TARGET_URL) {
|
|
|
4038
4694
|
console.log(line(ok, endpointLabel(check), detail));
|
|
4039
4695
|
}
|
|
4040
4696
|
{
|
|
4041
|
-
const
|
|
4042
|
-
const status = await requestStatus(`${baseUrl}${
|
|
4697
|
+
const path12 = `/fonts/${PROBE_SEGMENT}.ttf`;
|
|
4698
|
+
const status = await requestStatus(`${baseUrl}${path12}`, "GET");
|
|
4043
4699
|
const ok = status === 200 || status === 404;
|
|
4044
4700
|
if (!ok) {
|
|
4045
4701
|
failures++;
|
|
@@ -4054,7 +4710,7 @@ async function runVerifyEndpoints(target = DEFAULT_TARGET_URL) {
|
|
|
4054
4710
|
} else {
|
|
4055
4711
|
detail = `${describeStatus(status)} \u2014 unexpected`;
|
|
4056
4712
|
}
|
|
4057
|
-
console.log(line(ok, `GET /fonts/{filename}${(0, import_colors.dim)(` \u2192 ${
|
|
4713
|
+
console.log(line(ok, `GET /fonts/{filename}${(0, import_colors.dim)(` \u2192 ${path12}`)}`, detail));
|
|
4058
4714
|
}
|
|
4059
4715
|
console.log();
|
|
4060
4716
|
console.log((0, import_colors.bold)("Secured endpoints (must be absent or require auth):"));
|
|
@@ -4107,13 +4763,13 @@ async function runVerifyEndpoints(target = DEFAULT_TARGET_URL) {
|
|
|
4107
4763
|
line(true, pattern, `${actions.length} action(s) \u2014 all require auth`)
|
|
4108
4764
|
);
|
|
4109
4765
|
} else {
|
|
4110
|
-
for (const
|
|
4766
|
+
for (const failure2 of failed) {
|
|
4111
4767
|
failures++;
|
|
4112
4768
|
console.log(
|
|
4113
4769
|
line(
|
|
4114
4770
|
false,
|
|
4115
|
-
`POST /trigger/events/${event.id}/actions/${
|
|
4116
|
-
securedDetail(
|
|
4771
|
+
`POST /trigger/events/${event.id}/actions/${failure2.action}`,
|
|
4772
|
+
securedDetail(failure2.status)
|
|
4117
4773
|
)
|
|
4118
4774
|
);
|
|
4119
4775
|
}
|
|
@@ -4181,13 +4837,20 @@ Exits with a non-zero status if any check fails.
|
|
|
4181
4837
|
var UPGRADE_USAGE = `
|
|
4182
4838
|
Usage: opencrvs upgrade [options]
|
|
4183
4839
|
|
|
4184
|
-
Upgrade the country config in the current working directory to
|
|
4185
|
-
|
|
4840
|
+
Upgrade the country config in the current working directory to this toolkit's
|
|
4841
|
+
version of OpenCRVS. Upgrade one minor version at a time: toolkit 2.2 upgrades
|
|
4842
|
+
a country config on 2.1.
|
|
4843
|
+
|
|
4844
|
+
The upgrade tells which version the country config is on by its
|
|
4845
|
+
@opencrvs/toolkit dependency, and updates that dependency itself once done.
|
|
4846
|
+
Run it without changing the dependency first, e.g.
|
|
4847
|
+
|
|
4848
|
+
npx @opencrvs/toolkit@2.2 upgrade
|
|
4186
4849
|
|
|
4187
4850
|
Options:
|
|
4188
4851
|
-h, --help Show this message.
|
|
4189
4852
|
`.trim();
|
|
4190
|
-
function
|
|
4853
|
+
function main6() {
|
|
4191
4854
|
const command = args[0];
|
|
4192
4855
|
if (!command || command === "--help" || command === "-h") {
|
|
4193
4856
|
console.log(USAGE);
|
|
@@ -4249,14 +4912,20 @@ Subcommands:
|
|
|
4249
4912
|
async function runEnvironmentCommand(operation, command) {
|
|
4250
4913
|
try {
|
|
4251
4914
|
await command();
|
|
4252
|
-
} catch (
|
|
4915
|
+
} catch (error2) {
|
|
4253
4916
|
console.error(
|
|
4254
4917
|
`Environment ${operation} failed:`,
|
|
4255
|
-
|
|
4918
|
+
error2 instanceof Error ? error2.message : error2
|
|
4256
4919
|
);
|
|
4257
4920
|
process.exit(1);
|
|
4258
4921
|
}
|
|
4259
4922
|
}
|
|
4923
|
+
function readToolkitVersion() {
|
|
4924
|
+
const packageJson = JSON.parse(
|
|
4925
|
+
import_fs9.default.readFileSync(import_path12.default.join(__dirname, "..", "package.json"), "utf-8")
|
|
4926
|
+
);
|
|
4927
|
+
return packageJson.version;
|
|
4928
|
+
}
|
|
4260
4929
|
async function handleUpgrade() {
|
|
4261
4930
|
const upgradeArgs = args.slice(1);
|
|
4262
4931
|
if (upgradeArgs.includes("--help") || upgradeArgs.includes("-h")) {
|
|
@@ -4270,12 +4939,25 @@ async function handleUpgrade() {
|
|
|
4270
4939
|
console.log(UPGRADE_USAGE);
|
|
4271
4940
|
process.exit(1);
|
|
4272
4941
|
}
|
|
4942
|
+
const toolkitVersion = readToolkitVersion();
|
|
4943
|
+
const upgradePath = checkUpgradePath(
|
|
4944
|
+
findCountryConfigToolkitVersion(process.cwd()),
|
|
4945
|
+
toolkitVersion
|
|
4946
|
+
);
|
|
4947
|
+
if (upgradePath.status === "unknown") {
|
|
4948
|
+
console.warn(`\u26A0\uFE0F ${upgradePath.message}
|
|
4949
|
+
`);
|
|
4950
|
+
}
|
|
4951
|
+
if (upgradePath.status === "blocked") {
|
|
4952
|
+
console.error(upgradePath.message);
|
|
4953
|
+
process.exit(1);
|
|
4954
|
+
}
|
|
4273
4955
|
console.log("Initiating upgrade...");
|
|
4274
4956
|
try {
|
|
4275
|
-
await runUpgrade();
|
|
4957
|
+
await runUpgrade(toolkitVersion);
|
|
4276
4958
|
console.log("Upgrade completed successfully!");
|
|
4277
|
-
} catch (
|
|
4278
|
-
console.error("Upgrade failed:",
|
|
4959
|
+
} catch (error2) {
|
|
4960
|
+
console.error("Upgrade failed:", error2);
|
|
4279
4961
|
process.exit(1);
|
|
4280
4962
|
}
|
|
4281
4963
|
}
|
|
@@ -4296,12 +4978,12 @@ async function handleVerifyEndpoints() {
|
|
|
4296
4978
|
}
|
|
4297
4979
|
try {
|
|
4298
4980
|
await runVerifyEndpoints(positional[0]);
|
|
4299
|
-
} catch (
|
|
4981
|
+
} catch (error2) {
|
|
4300
4982
|
console.error(
|
|
4301
4983
|
"Endpoint verification failed:",
|
|
4302
|
-
|
|
4984
|
+
error2 instanceof Error ? error2.message : error2
|
|
4303
4985
|
);
|
|
4304
4986
|
process.exit(1);
|
|
4305
4987
|
}
|
|
4306
4988
|
}
|
|
4307
|
-
|
|
4989
|
+
main6();
|