@opencrvs/toolkit 2.1.2 → 2.2.0-rc.045257f
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/create-countryconfig/package.json +1 -1
- package/dist/application-config/index.js +41 -9
- package/dist/authentication/index.d.ts +1 -0
- package/dist/authentication/index.js +30 -6
- package/dist/cli.js +944 -2044
- package/dist/commons/api/router.d.ts +1546 -243
- package/dist/commons/application-config/index.d.ts +2 -2
- package/dist/commons/conditionals/conditionals.d.ts +3 -3
- 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 +146 -20
- package/dist/commons/events/ActionDocument.d.ts +89 -0
- package/dist/commons/events/ActionInput.d.ts +56 -4
- package/dist/commons/events/ActionType.d.ts +11 -1
- package/dist/commons/events/AdvancedSearchConfig.d.ts +12 -0
- package/dist/commons/events/AuditLog.d.ts +4 -0
- package/dist/commons/events/CompositeFieldValue.d.ts +5 -1
- package/dist/commons/events/CountryConfigQueryInput.d.ts +192 -18
- package/dist/commons/events/Draft.d.ts +2 -0
- package/dist/commons/events/EventConfig.d.ts +27 -6
- package/dist/commons/events/EventDocument.d.ts +88 -0
- package/dist/commons/events/EventIndex.d.ts +43 -6
- package/dist/commons/events/EventMetadata.d.ts +23 -1
- package/dist/commons/events/EventStatus.d.ts +1 -0
- package/dist/commons/events/FieldConfig.d.ts +11 -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 +224 -33
- package/dist/commons/events/eventConfigValidation.d.ts +26 -1
- package/dist/commons/events/index.d.ts +3 -0
- package/dist/commons/events/scopes.d.ts +2 -0
- package/dist/commons/events/state/flags.d.ts +1 -1
- package/dist/commons/events/state/index.d.ts +10 -2
- package/dist/commons/events/state/utils.d.ts +11 -1
- package/dist/commons/events/test.utils.d.ts +30 -1
- package/dist/commons/events/toNotificationForm.d.ts +17 -0
- package/dist/commons/events/utils.d.ts +62 -8
- package/dist/conditionals/index.js +16 -4
- package/dist/environment/derived-variables.d.ts +16 -4
- package/dist/environment/derived-variables.d.ts.map +1 -1
- package/dist/environment/derived-variables.js +18 -4
- package/dist/environment/dockerhub.d.ts +15 -0
- package/dist/environment/dockerhub.d.ts.map +1 -0
- package/dist/environment/dockerhub.js +104 -0
- package/dist/environment/questions.js +1 -1
- package/dist/environment/setup-environment.d.ts.map +1 -1
- package/dist/environment/setup-environment.js +67 -18
- package/dist/environment/templates.d.ts.map +1 -1
- package/dist/events/index.js +496 -129
- 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/{v2.1 → persistent}/add-translations.d.ts +7 -1
- package/dist/migrations/persistent/add-translations.d.ts.map +1 -0
- package/dist/migrations/{v2.1 → persistent}/add-translations.js +14 -12
- 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/read-declaration-through-helper.d.ts +39 -0
- package/dist/migrations/read-declaration-through-helper.d.ts.map +1 -0
- package/dist/migrations/read-declaration-through-helper.js +257 -0
- 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 +390 -106
- package/dist/scopes/index.d.ts +83 -90
- package/dist/scopes/index.js +26 -6
- package/dist/templates/charts-values/dependencies/values.yaml +1 -1
- package/dist/templates/charts-values/opencrvs-services/values.yaml +3 -5
- package/dist/templates/charts-values/traefik/values.yaml +4 -3
- package/opencrvs-toolkit-2.2.0-rc.045257f.tgz +0 -0
- package/package.json +2 -2
- package/tsconfig.build.tsbuildinfo +1 -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/add-translations.d.ts.map +0 -1
- 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 -2170
- package/dist/migrations/v2.1/migrate-infrastructure-to-assets.d.ts +0 -14
- 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 -8
- package/dist/migrations/v2.1/upgrade-tilt.d.ts.map +0 -1
- package/dist/migrations/v2.1/upgrade-tilt.js +0 -139
- 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.1.2.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,15 @@ 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
408
|
valueType: "SECRET",
|
|
409
409
|
type: "disabled",
|
|
410
410
|
scope: "ENVIRONMENT"
|
|
411
411
|
},
|
|
412
412
|
{
|
|
413
|
-
name: "
|
|
414
|
-
valueLabel: "
|
|
413
|
+
name: "S3_ADMIN_SECRET_KEY",
|
|
414
|
+
valueLabel: "S3_ADMIN_SECRET_KEY",
|
|
415
415
|
valueType: "SECRET",
|
|
416
416
|
type: "disabled",
|
|
417
417
|
scope: "ENVIRONMENT"
|
|
@@ -499,6 +499,20 @@ var init_derived_variables = __esm({
|
|
|
499
499
|
valueType: "VARIABLE",
|
|
500
500
|
type: "disabled",
|
|
501
501
|
scope: "ENVIRONMENT"
|
|
502
|
+
},
|
|
503
|
+
{
|
|
504
|
+
name: "TWO_FA_ENABLED",
|
|
505
|
+
valueLabel: "TWO_FA_ENABLED",
|
|
506
|
+
valueType: "VARIABLE",
|
|
507
|
+
type: "disabled",
|
|
508
|
+
scope: "ENVIRONMENT"
|
|
509
|
+
},
|
|
510
|
+
{
|
|
511
|
+
name: "MONITORING_ENABLED",
|
|
512
|
+
valueLabel: "MONITORING_ENABLED",
|
|
513
|
+
valueType: "VARIABLE",
|
|
514
|
+
type: "disabled",
|
|
515
|
+
scope: "ENVIRONMENT"
|
|
502
516
|
}
|
|
503
517
|
];
|
|
504
518
|
}
|
|
@@ -518,7 +532,7 @@ function findExistingValue(name, type, scope, existingValues) {
|
|
|
518
532
|
);
|
|
519
533
|
}
|
|
520
534
|
function readYamlFile(filePath) {
|
|
521
|
-
const fileContent =
|
|
535
|
+
const fileContent = import_fs4.default.readFileSync(filePath, "utf8");
|
|
522
536
|
return yaml.load(fileContent);
|
|
523
537
|
}
|
|
524
538
|
function writeYamlFile(filePath, data) {
|
|
@@ -531,16 +545,16 @@ function writeYamlFile(filePath, data) {
|
|
|
531
545
|
noRefs: true,
|
|
532
546
|
sortKeys: false
|
|
533
547
|
});
|
|
534
|
-
|
|
535
|
-
} catch (
|
|
536
|
-
throw new Error(`Failed to write inventory file: ${
|
|
548
|
+
import_fs4.default.writeFileSync(filePath, yamlContent, "utf8");
|
|
549
|
+
} catch (error2) {
|
|
550
|
+
throw new Error(`Failed to write inventory file: ${error2}`);
|
|
537
551
|
}
|
|
538
552
|
}
|
|
539
|
-
var
|
|
553
|
+
var import_fs4, yaml;
|
|
540
554
|
var init_utils = __esm({
|
|
541
555
|
"src/environment/utils.ts"() {
|
|
542
556
|
"use strict";
|
|
543
|
-
|
|
557
|
+
import_fs4 = __toESM(require("fs"));
|
|
544
558
|
yaml = __toESM(require("js-yaml"));
|
|
545
559
|
}
|
|
546
560
|
});
|
|
@@ -589,29 +603,29 @@ function extractWorkerNodes(data) {
|
|
|
589
603
|
return worker_hosts;
|
|
590
604
|
}
|
|
591
605
|
function copyChartsValues(env, values) {
|
|
592
|
-
const srcDir =
|
|
593
|
-
const destDir =
|
|
594
|
-
|
|
606
|
+
const srcDir = import_path8.default.resolve(__dirname, "templates", "charts-values");
|
|
607
|
+
const destDir = import_path8.default.resolve(process.cwd(), "environments", env);
|
|
608
|
+
import_fs5.default.mkdirSync(destDir, { recursive: true });
|
|
595
609
|
values["lets_encrypt"] = values["traefik_mode"] === "lets_encrypt";
|
|
596
610
|
values["static_ssl"] = values["traefik_mode"] === "static_ssl";
|
|
597
611
|
values["opencrvs_environment"] = env;
|
|
598
612
|
function copyRecursive(src, dest) {
|
|
599
|
-
const stat =
|
|
613
|
+
const stat = import_fs5.default.statSync(src);
|
|
600
614
|
if (stat.isDirectory()) {
|
|
601
|
-
|
|
602
|
-
for (const item of
|
|
603
|
-
copyRecursive(
|
|
615
|
+
import_fs5.default.mkdirSync(dest, { recursive: true });
|
|
616
|
+
for (const item of import_fs5.default.readdirSync(src)) {
|
|
617
|
+
copyRecursive(import_path8.default.join(src, item), import_path8.default.join(dest, item));
|
|
604
618
|
}
|
|
605
619
|
} else {
|
|
606
|
-
const content =
|
|
620
|
+
const content = import_fs5.default.readFileSync(src, "utf8");
|
|
607
621
|
const template = import_handlebars.default.compile(content);
|
|
608
622
|
const updated = template(values);
|
|
609
623
|
const isOverridesFile = dest.endsWith("override.yaml");
|
|
610
|
-
if (isOverridesFile &&
|
|
624
|
+
if (isOverridesFile && import_fs5.default.existsSync(dest)) {
|
|
611
625
|
log(` \u21B7 Skipped existing overrides file: ${dest}`);
|
|
612
626
|
return;
|
|
613
627
|
}
|
|
614
|
-
|
|
628
|
+
import_fs5.default.writeFileSync(dest, updated, "utf8");
|
|
615
629
|
log(` \u2713 Created: ${dest}`);
|
|
616
630
|
}
|
|
617
631
|
}
|
|
@@ -622,29 +636,32 @@ function copyChartsValues(env, values) {
|
|
|
622
636
|
`);
|
|
623
637
|
}
|
|
624
638
|
function generateInventory(env, values) {
|
|
625
|
-
const templatePath =
|
|
639
|
+
const templatePath = import_path8.default.join(
|
|
626
640
|
__dirname,
|
|
627
641
|
"templates",
|
|
628
642
|
"inventory",
|
|
629
643
|
"inventory.template.yml"
|
|
630
644
|
);
|
|
631
|
-
const outputPath =
|
|
632
|
-
|
|
645
|
+
const outputPath = import_path8.default.resolve(
|
|
646
|
+
process.cwd(),
|
|
647
|
+
getEnvironmentInventoryPath(env)
|
|
648
|
+
);
|
|
649
|
+
const templateFile = import_fs5.default.readFileSync(templatePath, "utf-8");
|
|
633
650
|
const template = import_handlebars.default.compile(templateFile);
|
|
634
651
|
values["single_node"] = values["kube_worker_nodes"].length > 0 || values["backup_host"] ? "false" : "true";
|
|
635
652
|
const updated = template(values);
|
|
636
|
-
|
|
637
|
-
|
|
653
|
+
import_fs5.default.mkdirSync(import_path8.default.dirname(outputPath), { recursive: true });
|
|
654
|
+
import_fs5.default.writeFileSync(outputPath, updated);
|
|
638
655
|
log(`
|
|
639
656
|
\u2705 Generated inventory file at ${outputPath}
|
|
640
657
|
`);
|
|
641
658
|
}
|
|
642
|
-
var
|
|
659
|
+
var import_fs5, import_path8, import_handlebars;
|
|
643
660
|
var init_templates = __esm({
|
|
644
661
|
"src/environment/templates.ts"() {
|
|
645
662
|
"use strict";
|
|
646
|
-
|
|
647
|
-
|
|
663
|
+
import_fs5 = __toESM(require("fs"));
|
|
664
|
+
import_path8 = __toESM(require("path"));
|
|
648
665
|
init_logger();
|
|
649
666
|
init_paths();
|
|
650
667
|
import_handlebars = __toESM(require("handlebars"));
|
|
@@ -675,16 +692,16 @@ var update_workflows_exports = {};
|
|
|
675
692
|
__export(update_workflows_exports, {
|
|
676
693
|
updateWorkflowEnvironments: () => updateWorkflowEnvironments
|
|
677
694
|
});
|
|
678
|
-
function isDirectory(
|
|
695
|
+
function isDirectory(path12) {
|
|
679
696
|
try {
|
|
680
|
-
return (0,
|
|
697
|
+
return (0, import_fs6.statSync)(path12).isDirectory();
|
|
681
698
|
} catch {
|
|
682
699
|
return false;
|
|
683
700
|
}
|
|
684
701
|
}
|
|
685
702
|
async function extractInfrastructureNames() {
|
|
686
|
-
const files = glob2.sync((0,
|
|
687
|
-
const infraEnvironments = files.map((file) => (0,
|
|
703
|
+
const files = glob2.sync((0, import_path9.join)("environments", "*", INVENTORY_FILE_NAME));
|
|
704
|
+
const infraEnvironments = files.map((file) => (0, import_path9.basename)((0, import_path9.dirname)(file)));
|
|
688
705
|
if (infraEnvironments.length === 0) {
|
|
689
706
|
console.log(
|
|
690
707
|
`\u26A0\uFE0F Warning: No environment inventory files found at environments/*/${INVENTORY_FILE_NAME}`
|
|
@@ -697,9 +714,9 @@ async function extractInfrastructureNames() {
|
|
|
697
714
|
async function extractEnvironmentNames() {
|
|
698
715
|
const entries = await (0, import_promises.readdir)("environments");
|
|
699
716
|
const environments = entries.filter((entry) => {
|
|
700
|
-
const environmentPath = (0,
|
|
701
|
-
const opencrvsServicesPath = (0,
|
|
702
|
-
return isDirectory(environmentPath) && (0,
|
|
717
|
+
const environmentPath = (0, import_path9.join)("environments", entry);
|
|
718
|
+
const opencrvsServicesPath = (0, import_path9.join)(environmentPath, "opencrvs-services");
|
|
719
|
+
return isDirectory(environmentPath) && (0, import_fs6.existsSync)(opencrvsServicesPath) && isDirectory(opencrvsServicesPath);
|
|
703
720
|
});
|
|
704
721
|
if (environments.length === 0) {
|
|
705
722
|
console.log(
|
|
@@ -724,12 +741,12 @@ function updateOptionsInYaml(content, envList) {
|
|
|
724
741
|
async function updateWorkflows(envList, config) {
|
|
725
742
|
const { workflows } = config;
|
|
726
743
|
for (const workflowPath of workflows) {
|
|
727
|
-
if (!(0,
|
|
744
|
+
if (!(0, import_fs6.existsSync)(workflowPath)) {
|
|
728
745
|
log(` \u21B7 Skipped ${workflowPath} (not found in this repository)`);
|
|
729
746
|
continue;
|
|
730
747
|
}
|
|
731
748
|
try {
|
|
732
|
-
const fileContents = (0,
|
|
749
|
+
const fileContents = (0, import_fs6.readFileSync)(workflowPath, "utf8");
|
|
733
750
|
const workflowData = yaml2.load(fileContents);
|
|
734
751
|
if (!workflowData?.on?.workflow_dispatch?.inputs?.environment?.options) {
|
|
735
752
|
throw new Error(
|
|
@@ -737,15 +754,15 @@ async function updateWorkflows(envList, config) {
|
|
|
737
754
|
);
|
|
738
755
|
}
|
|
739
756
|
const updatedContent = updateOptionsInYaml(fileContents, envList);
|
|
740
|
-
(0,
|
|
757
|
+
(0, import_fs6.writeFileSync)(workflowPath, updatedContent, "utf8");
|
|
741
758
|
log(` \u2713 Successfully updated ${workflowPath}`);
|
|
742
|
-
} catch (
|
|
759
|
+
} catch (error2) {
|
|
743
760
|
console.error(
|
|
744
761
|
`
|
|
745
762
|
\u26A0\uFE0F Error updating ${workflowPath} with environments: [${envList.join(", ")}]`
|
|
746
763
|
);
|
|
747
|
-
console.error(`\u2717 Failed to update ${workflowPath}:`,
|
|
748
|
-
throw
|
|
764
|
+
console.error(`\u2717 Failed to update ${workflowPath}:`, error2);
|
|
765
|
+
throw error2;
|
|
749
766
|
}
|
|
750
767
|
}
|
|
751
768
|
}
|
|
@@ -786,18 +803,18 @@ async function updateWorkflowEnvironments() {
|
|
|
786
803
|
} else {
|
|
787
804
|
log("\u2139\uFE0F No workflows were updated.");
|
|
788
805
|
}
|
|
789
|
-
} catch (
|
|
790
|
-
console.error("\n\u274C Error updating workflows:",
|
|
806
|
+
} catch (error2) {
|
|
807
|
+
console.error("\n\u274C Error updating workflows:", error2);
|
|
791
808
|
process.exit(1);
|
|
792
809
|
}
|
|
793
810
|
}
|
|
794
|
-
var import_promises,
|
|
811
|
+
var import_promises, import_fs6, import_path9, glob2, yaml2;
|
|
795
812
|
var init_update_workflows = __esm({
|
|
796
813
|
"src/environment/update-workflows.ts"() {
|
|
797
814
|
"use strict";
|
|
798
815
|
import_promises = require("fs/promises");
|
|
799
|
-
|
|
800
|
-
|
|
816
|
+
import_fs6 = require("fs");
|
|
817
|
+
import_path9 = require("path");
|
|
801
818
|
glob2 = __toESM(require("glob"));
|
|
802
819
|
yaml2 = __toESM(require("js-yaml"));
|
|
803
820
|
init_logger();
|
|
@@ -808,7 +825,7 @@ var init_update_workflows = __esm({
|
|
|
808
825
|
// src/environment/git.ts
|
|
809
826
|
function getRepoInfo() {
|
|
810
827
|
try {
|
|
811
|
-
const remoteUrl = (0,
|
|
828
|
+
const remoteUrl = (0, import_child_process.execSync)("git config --get remote.origin.url", {
|
|
812
829
|
stdio: ["ignore", "pipe", "ignore"]
|
|
813
830
|
}).toString().trim();
|
|
814
831
|
const match = remoteUrl.match(/github\.com[:/](.+?)\/(.+?)(\.git)?$/);
|
|
@@ -826,11 +843,11 @@ function getRepoInfo() {
|
|
|
826
843
|
};
|
|
827
844
|
}
|
|
828
845
|
}
|
|
829
|
-
var
|
|
846
|
+
var import_child_process;
|
|
830
847
|
var init_git = __esm({
|
|
831
848
|
"src/environment/git.ts"() {
|
|
832
849
|
"use strict";
|
|
833
|
-
|
|
850
|
+
import_child_process = require("child_process");
|
|
834
851
|
}
|
|
835
852
|
});
|
|
836
853
|
|
|
@@ -1360,6 +1377,86 @@ var init_questions_helper = __esm({
|
|
|
1360
1377
|
}
|
|
1361
1378
|
});
|
|
1362
1379
|
|
|
1380
|
+
// src/environment/dockerhub.ts
|
|
1381
|
+
async function validateDockerHubCredentials(organisation, repository, username, token) {
|
|
1382
|
+
if (!organisation || !repository || !username || !token) {
|
|
1383
|
+
return {
|
|
1384
|
+
status: "skipped",
|
|
1385
|
+
reason: "Some values are kept from existing GitHub secrets, which cannot be read back"
|
|
1386
|
+
};
|
|
1387
|
+
}
|
|
1388
|
+
try {
|
|
1389
|
+
const login = await fetch(`${DOCKER_HUB_API}/auth/token`, {
|
|
1390
|
+
method: "POST",
|
|
1391
|
+
headers: { "Content-Type": "application/json" },
|
|
1392
|
+
body: JSON.stringify({ identifier: username, secret: token }),
|
|
1393
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)
|
|
1394
|
+
});
|
|
1395
|
+
if (login.status === 401 || login.status === 403) {
|
|
1396
|
+
return {
|
|
1397
|
+
status: "invalid-credentials",
|
|
1398
|
+
reason: "Docker Hub rejected the username or token. Check DOCKER_USERNAME and DOCKER_TOKEN"
|
|
1399
|
+
};
|
|
1400
|
+
}
|
|
1401
|
+
if (!login.ok) {
|
|
1402
|
+
return {
|
|
1403
|
+
status: "unreachable",
|
|
1404
|
+
reason: `Docker Hub login responded with HTTP ${login.status}`
|
|
1405
|
+
};
|
|
1406
|
+
}
|
|
1407
|
+
const body = await login.json();
|
|
1408
|
+
const accessToken = body.access_token ?? body.token;
|
|
1409
|
+
if (!accessToken) {
|
|
1410
|
+
return {
|
|
1411
|
+
status: "unreachable",
|
|
1412
|
+
reason: "Docker Hub login response did not contain an access token"
|
|
1413
|
+
};
|
|
1414
|
+
}
|
|
1415
|
+
const repositoryResponse = await fetch(
|
|
1416
|
+
`${DOCKER_HUB_API}/repositories/${encodeURIComponent(
|
|
1417
|
+
organisation
|
|
1418
|
+
)}/${encodeURIComponent(repository)}/`,
|
|
1419
|
+
{
|
|
1420
|
+
headers: { Authorization: `Bearer ${accessToken}` },
|
|
1421
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)
|
|
1422
|
+
}
|
|
1423
|
+
);
|
|
1424
|
+
if (repositoryResponse.ok) {
|
|
1425
|
+
return { status: "valid" };
|
|
1426
|
+
}
|
|
1427
|
+
if (repositoryResponse.status === 404) {
|
|
1428
|
+
return {
|
|
1429
|
+
status: "repository-not-found",
|
|
1430
|
+
reason: `Login succeeded, but repository ${organisation}/${repository} was not found or is not accessible with this token. Check DOCKERHUB_ACCOUNT and DOCKERHUB_REPO`
|
|
1431
|
+
};
|
|
1432
|
+
}
|
|
1433
|
+
if (repositoryResponse.status === 401 || repositoryResponse.status === 403) {
|
|
1434
|
+
return {
|
|
1435
|
+
status: "invalid-credentials",
|
|
1436
|
+
reason: `Login succeeded, but the token is not allowed to read repository ${organisation}/${repository}`
|
|
1437
|
+
};
|
|
1438
|
+
}
|
|
1439
|
+
return {
|
|
1440
|
+
status: "unreachable",
|
|
1441
|
+
reason: `Docker Hub repository lookup responded with HTTP ${repositoryResponse.status}`
|
|
1442
|
+
};
|
|
1443
|
+
} catch (err) {
|
|
1444
|
+
if (!(err instanceof Error)) {
|
|
1445
|
+
return { status: "unreachable", reason: String(err) };
|
|
1446
|
+
}
|
|
1447
|
+
const cause = err.cause instanceof Error ? `: ${err.cause.message}` : "";
|
|
1448
|
+
return { status: "unreachable", reason: `${err.message}${cause}` };
|
|
1449
|
+
}
|
|
1450
|
+
}
|
|
1451
|
+
var DOCKER_HUB_API, REQUEST_TIMEOUT_MS;
|
|
1452
|
+
var init_dockerhub = __esm({
|
|
1453
|
+
"src/environment/dockerhub.ts"() {
|
|
1454
|
+
"use strict";
|
|
1455
|
+
DOCKER_HUB_API = "https://hub.docker.com/v2";
|
|
1456
|
+
REQUEST_TIMEOUT_MS = 1e4;
|
|
1457
|
+
}
|
|
1458
|
+
});
|
|
1459
|
+
|
|
1363
1460
|
// src/environment/manage-users.ts
|
|
1364
1461
|
async function inquirerPrompt(name, options) {
|
|
1365
1462
|
const inquirer = await import("@inquirer/prompts");
|
|
@@ -1386,7 +1483,7 @@ function getCurrentUsername() {
|
|
|
1386
1483
|
}
|
|
1387
1484
|
function getCurrentUserSSHKeys() {
|
|
1388
1485
|
const homeDir = os.homedir();
|
|
1389
|
-
const sshDir =
|
|
1486
|
+
const sshDir = path8.join(homeDir, ".ssh");
|
|
1390
1487
|
const keys = [];
|
|
1391
1488
|
const keyFiles = [
|
|
1392
1489
|
"id_rsa.pub",
|
|
@@ -1395,15 +1492,15 @@ function getCurrentUserSSHKeys() {
|
|
|
1395
1492
|
"id_dsa.pub"
|
|
1396
1493
|
];
|
|
1397
1494
|
for (const keyFile of keyFiles) {
|
|
1398
|
-
const keyPath =
|
|
1495
|
+
const keyPath = path8.join(sshDir, keyFile);
|
|
1399
1496
|
try {
|
|
1400
|
-
if (
|
|
1401
|
-
const keyContent =
|
|
1497
|
+
if (fs5.existsSync(keyPath)) {
|
|
1498
|
+
const keyContent = fs5.readFileSync(keyPath, "utf8").trim();
|
|
1402
1499
|
if (keyContent) {
|
|
1403
1500
|
keys.push(keyContent);
|
|
1404
1501
|
}
|
|
1405
1502
|
}
|
|
1406
|
-
} catch (
|
|
1503
|
+
} catch (error2) {
|
|
1407
1504
|
continue;
|
|
1408
1505
|
}
|
|
1409
1506
|
}
|
|
@@ -1617,7 +1714,7 @@ async function editUser(user) {
|
|
|
1617
1714
|
return updatedUser;
|
|
1618
1715
|
}
|
|
1619
1716
|
async function manageUsers(inventoryPath) {
|
|
1620
|
-
let users =
|
|
1717
|
+
let users = fs5.existsSync(inventoryPath) ? parseInventoryFile(inventoryPath) : [];
|
|
1621
1718
|
if (users.length > 0) {
|
|
1622
1719
|
displayUserSummary(users);
|
|
1623
1720
|
}
|
|
@@ -1709,7 +1806,7 @@ async function manageUsers(inventoryPath) {
|
|
|
1709
1806
|
message: "Save changes end exit?",
|
|
1710
1807
|
default: true
|
|
1711
1808
|
});
|
|
1712
|
-
if (confirmSave &&
|
|
1809
|
+
if (confirmSave && fs5.existsSync(inventoryPath)) {
|
|
1713
1810
|
updateInventoryFile(inventoryPath, users);
|
|
1714
1811
|
console.log(`
|
|
1715
1812
|
\u2705 Changes saved to ${inventoryPath}
|
|
@@ -1736,13 +1833,13 @@ async function manageUsers(inventoryPath) {
|
|
|
1736
1833
|
}
|
|
1737
1834
|
return users;
|
|
1738
1835
|
}
|
|
1739
|
-
var os,
|
|
1836
|
+
var os, fs5, path8, input2, select2, confirm, editor, checkbox;
|
|
1740
1837
|
var init_manage_users = __esm({
|
|
1741
1838
|
"src/environment/manage-users.ts"() {
|
|
1742
1839
|
"use strict";
|
|
1743
1840
|
os = __toESM(require("os"));
|
|
1744
|
-
|
|
1745
|
-
|
|
1841
|
+
fs5 = __toESM(require("fs"));
|
|
1842
|
+
path8 = __toESM(require("path"));
|
|
1746
1843
|
init_logger();
|
|
1747
1844
|
init_utils();
|
|
1748
1845
|
init_templates();
|
|
@@ -1927,6 +2024,28 @@ async function promptAndStoreAnswer(questions, existingValues) {
|
|
|
1927
2024
|
]);
|
|
1928
2025
|
return { ...Object.fromEntries(existingValuesForQuestions), ...result };
|
|
1929
2026
|
}
|
|
2027
|
+
async function promptAndValidateDockerhub(existingValues) {
|
|
2028
|
+
const answers = await promptAndStoreAnswer(dockerhubQuestions, existingValues);
|
|
2029
|
+
const result = await validateDockerHubCredentials(
|
|
2030
|
+
answers.dockerhubOrganisation,
|
|
2031
|
+
answers.dockerhubRepository,
|
|
2032
|
+
answers.dockerhubUsername,
|
|
2033
|
+
answers.dockerhubToken
|
|
2034
|
+
);
|
|
2035
|
+
if (result.status === "valid" || result.status === "skipped") {
|
|
2036
|
+
return;
|
|
2037
|
+
}
|
|
2038
|
+
error(`
|
|
2039
|
+
${result.status}: ${result.reason || "Generic error"}
|
|
2040
|
+
`);
|
|
2041
|
+
const continueNotValidated = await confirm2({
|
|
2042
|
+
message: "Docker Hub credentials are not validated. Continue anyway?",
|
|
2043
|
+
default: false
|
|
2044
|
+
});
|
|
2045
|
+
if (!continueNotValidated) {
|
|
2046
|
+
process.exit(1);
|
|
2047
|
+
}
|
|
2048
|
+
}
|
|
1930
2049
|
async function runSetupEnvironment() {
|
|
1931
2050
|
log("\n", import_kleur4.default.bold().underline("Github"), "\n");
|
|
1932
2051
|
const { githubOrganisation, githubRepository } = await (0, import_prompts2.default)(
|
|
@@ -1990,16 +2109,6 @@ async function runSetupEnvironment() {
|
|
|
1990
2109
|
]
|
|
1991
2110
|
});
|
|
1992
2111
|
}
|
|
1993
|
-
log("\n", import_kleur4.default.bold().underline("Two-factor authentication (2FA)"));
|
|
1994
|
-
const two_fa_enabled = await confirm2({
|
|
1995
|
-
message: "Enable two-factor authentication (2FA)? This should be enabled for any environment that hosts PII data.",
|
|
1996
|
-
default: process.env.TWO_FA_ENABLED ? process.env.TWO_FA_ENABLED === "true" : environment_type === "production"
|
|
1997
|
-
});
|
|
1998
|
-
if (!two_fa_enabled && ["production", "staging"].includes(environment_type)) {
|
|
1999
|
-
warn(
|
|
2000
|
-
"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."
|
|
2001
|
-
);
|
|
2002
|
-
}
|
|
2003
2112
|
const environment_exists = existingEnvironments.map((e) => e.trim()).includes(environment);
|
|
2004
2113
|
if (!environment) {
|
|
2005
2114
|
process.exit(1);
|
|
@@ -2063,8 +2172,25 @@ async function runSetupEnvironment() {
|
|
|
2063
2172
|
);
|
|
2064
2173
|
await promptAndStoreAnswer(githubOtherQuestions, existingValues);
|
|
2065
2174
|
}
|
|
2175
|
+
log("\n", import_kleur4.default.bold().underline("Two-factor authentication (2FA)"));
|
|
2176
|
+
const existingTwoFaEnabled = findExistingValue(
|
|
2177
|
+
"TWO_FA_ENABLED",
|
|
2178
|
+
"VARIABLE",
|
|
2179
|
+
"ENVIRONMENT",
|
|
2180
|
+
existingValues
|
|
2181
|
+
);
|
|
2182
|
+
const twoFaDefault = process.env.TWO_FA_ENABLED || existingTwoFaEnabled?.value;
|
|
2183
|
+
const two_fa_enabled = await confirm2({
|
|
2184
|
+
message: "Enable two-factor authentication (2FA)? This should be enabled for any environment that hosts PII data.",
|
|
2185
|
+
default: twoFaDefault ? twoFaDefault === "true" : environment_type === "production"
|
|
2186
|
+
});
|
|
2187
|
+
if (!two_fa_enabled && ["production", "staging"].includes(environment_type)) {
|
|
2188
|
+
warn(
|
|
2189
|
+
"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."
|
|
2190
|
+
);
|
|
2191
|
+
}
|
|
2066
2192
|
log("\n", import_kleur4.default.bold().underline("Docker Hub"));
|
|
2067
|
-
await
|
|
2193
|
+
await promptAndValidateDockerhub(existingValues);
|
|
2068
2194
|
log("\n", import_kleur4.default.bold().underline("Kubernetes & Runtime"));
|
|
2069
2195
|
const infrastructure = await promptAndStoreAnswer(
|
|
2070
2196
|
infrastructureQuestions,
|
|
@@ -2248,7 +2374,22 @@ async function runSetupEnvironment() {
|
|
|
2248
2374
|
log(import_kleur4.default.bold().green("\u2714"), import_kleur4.default.bold().yellow("Restore is disabled"));
|
|
2249
2375
|
}
|
|
2250
2376
|
log("\n", import_kleur4.default.bold().underline("Monitoring"));
|
|
2251
|
-
|
|
2377
|
+
const existingMonitoringEnabled = findExistingValue(
|
|
2378
|
+
"MONITORING_ENABLED",
|
|
2379
|
+
"VARIABLE",
|
|
2380
|
+
"ENVIRONMENT",
|
|
2381
|
+
existingValues
|
|
2382
|
+
);
|
|
2383
|
+
const monitoringDefault = process.env.MONITORING_ENABLED || existingMonitoringEnabled?.value;
|
|
2384
|
+
const monitoring_enabled = await confirm2({
|
|
2385
|
+
message: "Enable monitoring (Kibana, APM, Filebeat, Metricbeat, Elastalert, OpenTelemetry Collector and tracing)? Disable it if this environment does not need its own monitoring stack.",
|
|
2386
|
+
default: monitoringDefault ? monitoringDefault === "true" : true
|
|
2387
|
+
});
|
|
2388
|
+
if (monitoring_enabled) {
|
|
2389
|
+
await promptAndStoreAnswer(databaseAndMonitoringQuestions, existingValues);
|
|
2390
|
+
} else {
|
|
2391
|
+
log(import_kleur4.default.bold().green("\u2714"), import_kleur4.default.bold().yellow("Monitoring is disabled"));
|
|
2392
|
+
}
|
|
2252
2393
|
const sentryDSNExists = findExistingValue(
|
|
2253
2394
|
"SENTRY_DSN",
|
|
2254
2395
|
"SECRET",
|
|
@@ -2318,6 +2459,21 @@ async function runSetupEnvironment() {
|
|
|
2318
2459
|
),
|
|
2319
2460
|
scope: "ENVIRONMENT"
|
|
2320
2461
|
});
|
|
2462
|
+
derivedUpdates.push({
|
|
2463
|
+
name: "TWO_FA_ENABLED",
|
|
2464
|
+
type: "VARIABLE",
|
|
2465
|
+
didExist: existingTwoFaEnabled,
|
|
2466
|
+
// Always stored, so the next run defaults to the current answer
|
|
2467
|
+
value: two_fa_enabled ? "true" : "false",
|
|
2468
|
+
scope: "ENVIRONMENT"
|
|
2469
|
+
});
|
|
2470
|
+
derivedUpdates.push({
|
|
2471
|
+
name: "MONITORING_ENABLED",
|
|
2472
|
+
type: "VARIABLE",
|
|
2473
|
+
didExist: existingMonitoringEnabled,
|
|
2474
|
+
value: monitoring_enabled ? "true" : "false",
|
|
2475
|
+
scope: "ENVIRONMENT"
|
|
2476
|
+
});
|
|
2321
2477
|
derivedUpdates.push(...ssl_answers);
|
|
2322
2478
|
if (configureBackup) {
|
|
2323
2479
|
derivedUpdates.push({
|
|
@@ -2374,16 +2530,16 @@ async function runSetupEnvironment() {
|
|
|
2374
2530
|
scope: "ENVIRONMENT"
|
|
2375
2531
|
},
|
|
2376
2532
|
{
|
|
2377
|
-
name: "
|
|
2533
|
+
name: "S3_ADMIN_ACCESS_KEY",
|
|
2378
2534
|
type: "SECRET",
|
|
2379
2535
|
didExist: findExistingValue(
|
|
2380
|
-
"
|
|
2536
|
+
"S3_ADMIN_ACCESS_KEY",
|
|
2381
2537
|
"SECRET",
|
|
2382
2538
|
"ENVIRONMENT",
|
|
2383
2539
|
existingValues
|
|
2384
2540
|
),
|
|
2385
2541
|
value: findExistingOrDefine(
|
|
2386
|
-
"
|
|
2542
|
+
"S3_ADMIN_ACCESS_KEY",
|
|
2387
2543
|
"SECRET",
|
|
2388
2544
|
"ENVIRONMENT",
|
|
2389
2545
|
generateLongPassword()
|
|
@@ -2391,16 +2547,16 @@ async function runSetupEnvironment() {
|
|
|
2391
2547
|
scope: "ENVIRONMENT"
|
|
2392
2548
|
},
|
|
2393
2549
|
{
|
|
2394
|
-
name: "
|
|
2550
|
+
name: "S3_ADMIN_SECRET_KEY",
|
|
2395
2551
|
type: "SECRET",
|
|
2396
2552
|
didExist: findExistingValue(
|
|
2397
|
-
"
|
|
2553
|
+
"S3_ADMIN_SECRET_KEY",
|
|
2398
2554
|
"SECRET",
|
|
2399
2555
|
"ENVIRONMENT",
|
|
2400
2556
|
existingValues
|
|
2401
2557
|
),
|
|
2402
2558
|
value: findExistingOrDefine(
|
|
2403
|
-
"
|
|
2559
|
+
"S3_ADMIN_SECRET_KEY",
|
|
2404
2560
|
"SECRET",
|
|
2405
2561
|
"ENVIRONMENT",
|
|
2406
2562
|
generateLongPassword()
|
|
@@ -2868,6 +3024,7 @@ async function runSetupEnvironment() {
|
|
|
2868
3024
|
env: environment,
|
|
2869
3025
|
environment_type,
|
|
2870
3026
|
two_fa_enabled,
|
|
3027
|
+
monitoring_enabled,
|
|
2871
3028
|
traefik_mode: traefikConfOption,
|
|
2872
3029
|
restore_enabled: restoreEnvironmentName ? true : false,
|
|
2873
3030
|
restore_environment_name: restoreEnvironmentName || "",
|
|
@@ -2933,6 +3090,7 @@ var init_setup_environment = __esm({
|
|
|
2933
3090
|
init_questions();
|
|
2934
3091
|
init_editor_questions();
|
|
2935
3092
|
init_questions_helper();
|
|
3093
|
+
init_dockerhub();
|
|
2936
3094
|
init_manage_users();
|
|
2937
3095
|
init_paths();
|
|
2938
3096
|
ALL_QUESTIONS = [];
|
|
@@ -2960,17 +3118,17 @@ __export(upgrade_exports, {
|
|
|
2960
3118
|
upgradeEnvironmentLayout: () => upgradeEnvironmentLayout
|
|
2961
3119
|
});
|
|
2962
3120
|
function moveFileIfDestinationMissing(sourcePath, destinationPath) {
|
|
2963
|
-
if (!(0,
|
|
3121
|
+
if (!(0, import_fs7.existsSync)(sourcePath)) {
|
|
2964
3122
|
return false;
|
|
2965
3123
|
}
|
|
2966
|
-
if ((0,
|
|
3124
|
+
if ((0, import_fs7.existsSync)(destinationPath)) {
|
|
2967
3125
|
warn(
|
|
2968
3126
|
`\u26A0\uFE0F Skipped ${sourcePath}; destination already exists at ${destinationPath}`
|
|
2969
3127
|
);
|
|
2970
3128
|
return false;
|
|
2971
3129
|
}
|
|
2972
|
-
(0,
|
|
2973
|
-
(0,
|
|
3130
|
+
(0, import_fs7.mkdirSync)((0, import_path10.dirname)(destinationPath), { recursive: true });
|
|
3131
|
+
(0, import_fs7.renameSync)(sourcePath, destinationPath);
|
|
2974
3132
|
log(` \u2713 Moved ${sourcePath} -> ${destinationPath}`);
|
|
2975
3133
|
return true;
|
|
2976
3134
|
}
|
|
@@ -2990,8 +3148,8 @@ function migrateInventoryFiles() {
|
|
|
2990
3148
|
) || didMoveInventory;
|
|
2991
3149
|
}
|
|
2992
3150
|
try {
|
|
2993
|
-
if ((0,
|
|
2994
|
-
(0,
|
|
3151
|
+
if ((0, import_fs7.existsSync)(OLD_INVENTORY_DIR) && (0, import_fs7.readdirSync)(OLD_INVENTORY_DIR).length === 0) {
|
|
3152
|
+
(0, import_fs7.rmdirSync)(OLD_INVENTORY_DIR);
|
|
2995
3153
|
log(` \u2713 Removed empty ${OLD_INVENTORY_DIR}`);
|
|
2996
3154
|
}
|
|
2997
3155
|
} catch {
|
|
@@ -3009,12 +3167,12 @@ async function upgradeEnvironmentLayout() {
|
|
|
3009
3167
|
}
|
|
3010
3168
|
log("\nCommit changes into git after upgrade");
|
|
3011
3169
|
}
|
|
3012
|
-
var
|
|
3170
|
+
var import_fs7, import_path10, import_kleur5;
|
|
3013
3171
|
var init_upgrade = __esm({
|
|
3014
3172
|
"src/environment/upgrade.ts"() {
|
|
3015
3173
|
"use strict";
|
|
3016
|
-
|
|
3017
|
-
|
|
3174
|
+
import_fs7 = require("fs");
|
|
3175
|
+
import_path10 = require("path");
|
|
3018
3176
|
import_kleur5 = __toESM(require("kleur"));
|
|
3019
3177
|
init_logger();
|
|
3020
3178
|
init_paths();
|
|
@@ -3032,16 +3190,16 @@ async function select4(options) {
|
|
|
3032
3190
|
return inquirer.select(options);
|
|
3033
3191
|
}
|
|
3034
3192
|
async function selectInventoryFile(dirPath = "./environments") {
|
|
3035
|
-
if (!
|
|
3193
|
+
if (!fs6.existsSync(dirPath)) {
|
|
3036
3194
|
warn(`\u26A0\uFE0F No environment configuration directory found at ${dirPath}`);
|
|
3037
3195
|
warn(
|
|
3038
3196
|
"Hint: If this is a new infrastructure repository, run `opencrvs environment init` first."
|
|
3039
3197
|
);
|
|
3040
3198
|
return null;
|
|
3041
3199
|
}
|
|
3042
|
-
const environments =
|
|
3043
|
-
const filePath =
|
|
3044
|
-
return
|
|
3200
|
+
const environments = fs6.readdirSync(dirPath).filter((entry) => {
|
|
3201
|
+
const filePath = path9.join(dirPath, entry);
|
|
3202
|
+
return fs6.statSync(filePath).isDirectory() && fs6.existsSync(getEnvironmentInventoryPath(entry));
|
|
3045
3203
|
}).sort();
|
|
3046
3204
|
if (environments.length === 0) {
|
|
3047
3205
|
warn(`\u26A0\uFE0F No environment configuration files found at ${dirPath}`);
|
|
@@ -3068,12 +3226,12 @@ async function manageEnvironmentUsers() {
|
|
|
3068
3226
|
}
|
|
3069
3227
|
await manageUsers(inventory_file);
|
|
3070
3228
|
}
|
|
3071
|
-
var
|
|
3229
|
+
var fs6, path9, import_kleur6;
|
|
3072
3230
|
var init_users = __esm({
|
|
3073
3231
|
"src/environment/users.ts"() {
|
|
3074
3232
|
"use strict";
|
|
3075
|
-
|
|
3076
|
-
|
|
3233
|
+
fs6 = __toESM(require("fs"));
|
|
3234
|
+
path9 = __toESM(require("path"));
|
|
3077
3235
|
import_kleur6 = __toESM(require("kleur"));
|
|
3078
3236
|
init_manage_users();
|
|
3079
3237
|
init_logger();
|
|
@@ -3083,11 +3241,11 @@ var init_users = __esm({
|
|
|
3083
3241
|
|
|
3084
3242
|
// src/environment/swarm-to-k8s.ts
|
|
3085
3243
|
var swarm_to_k8s_exports = {};
|
|
3086
|
-
var
|
|
3244
|
+
var path10, import_kleur7, import_core2;
|
|
3087
3245
|
var init_swarm_to_k8s = __esm({
|
|
3088
3246
|
"src/environment/swarm-to-k8s.ts"() {
|
|
3089
3247
|
"use strict";
|
|
3090
|
-
|
|
3248
|
+
path10 = __toESM(require("path"));
|
|
3091
3249
|
import_kleur7 = __toESM(require("kleur"));
|
|
3092
3250
|
init_logger();
|
|
3093
3251
|
init_utils();
|
|
@@ -3139,7 +3297,7 @@ var init_swarm_to_k8s = __esm({
|
|
|
3139
3297
|
);
|
|
3140
3298
|
process.exit(1);
|
|
3141
3299
|
}
|
|
3142
|
-
const ansible_inventory =
|
|
3300
|
+
const ansible_inventory = path10.join(old_inventory_path, environment + ".yml");
|
|
3143
3301
|
const data = readYamlFile(ansible_inventory);
|
|
3144
3302
|
log(` \u2713 Loaded old inventory file: ${ansible_inventory}`);
|
|
3145
3303
|
const master = dockerManagerFirst(data) || "";
|
|
@@ -3260,187 +3418,12 @@ var init_swarm_to_k8s = __esm({
|
|
|
3260
3418
|
}
|
|
3261
3419
|
});
|
|
3262
3420
|
|
|
3263
|
-
// src/
|
|
3264
|
-
var
|
|
3265
|
-
var
|
|
3266
|
-
var DEFINE_CONFIG_NAME = "defineConfig";
|
|
3267
|
-
var ACTIONS_PROPERTY_NAME = "actions";
|
|
3268
|
-
var TYPE_PROPERTY_NAME = "type";
|
|
3269
|
-
var FLAGS_PROPERTY_NAME = "flags";
|
|
3270
|
-
var CONDITIONALS_PROPERTY_NAME = "conditionals";
|
|
3271
|
-
var ACTION_TYPE_ENUM_NAME = "ActionType";
|
|
3272
|
-
var REQUEST_CORRECTION_TYPE = "REQUEST_CORRECTION";
|
|
3273
|
-
var CORRECTION_ACTIONS_TO_ADD = [
|
|
3274
|
-
{
|
|
3275
|
-
actionType: "APPROVE_CORRECTION",
|
|
3276
|
-
labelId: "v2.events.correction.approve.label",
|
|
3277
|
-
defaultMessage: "Approve correction",
|
|
3278
|
-
description: "Label for the approve correction action"
|
|
3279
|
-
},
|
|
3280
|
-
{
|
|
3281
|
-
actionType: "REJECT_CORRECTION",
|
|
3282
|
-
labelId: "v2.events.correction.reject.label",
|
|
3283
|
-
defaultMessage: "Reject correction",
|
|
3284
|
-
description: "Label for the reject correction action"
|
|
3285
|
-
}
|
|
3286
|
-
];
|
|
3287
|
-
function isActionOfType(obj, typeName) {
|
|
3288
|
-
const typeProperty = obj.getProperty(TYPE_PROPERTY_NAME);
|
|
3289
|
-
if (!typeProperty || !import_ts_morph.Node.isPropertyAssignment(typeProperty)) return false;
|
|
3290
|
-
const typeInit = typeProperty.getInitializer();
|
|
3291
|
-
if (!typeInit) return false;
|
|
3292
|
-
if (import_ts_morph.Node.isPropertyAccessExpression(typeInit)) {
|
|
3293
|
-
return typeInit.getExpression().getText() === ACTION_TYPE_ENUM_NAME && typeInit.getName() === typeName;
|
|
3294
|
-
}
|
|
3295
|
-
if (import_ts_morph.Node.isStringLiteral(typeInit)) {
|
|
3296
|
-
return typeInit.getLiteralValue() === typeName;
|
|
3297
|
-
}
|
|
3298
|
-
return false;
|
|
3299
|
-
}
|
|
3300
|
-
function getTypeInitializerStyle(obj) {
|
|
3301
|
-
const typeProperty = obj.getProperty(TYPE_PROPERTY_NAME);
|
|
3302
|
-
if (typeProperty && import_ts_morph.Node.isPropertyAssignment(typeProperty)) {
|
|
3303
|
-
const typeInit = typeProperty.getInitializer();
|
|
3304
|
-
if (typeInit && import_ts_morph.Node.isPropertyAccessExpression(typeInit)) return "enum";
|
|
3305
|
-
}
|
|
3306
|
-
return "string";
|
|
3307
|
-
}
|
|
3308
|
-
function getNonEmptyArrayPropertyText(obj, propName) {
|
|
3309
|
-
const prop = obj.getProperty(propName);
|
|
3310
|
-
if (!prop || !import_ts_morph.Node.isPropertyAssignment(prop)) return void 0;
|
|
3311
|
-
const init = prop.getInitializer();
|
|
3312
|
-
if (!init || !import_ts_morph.Node.isArrayLiteralExpression(init)) return void 0;
|
|
3313
|
-
if (init.getElements().length === 0) return void 0;
|
|
3314
|
-
return init.getText();
|
|
3315
|
-
}
|
|
3316
|
-
function buildCorrectionActionText(spec, typeStyle, flagsText, conditionalsText) {
|
|
3317
|
-
const typeText = typeStyle === "enum" ? `${ACTION_TYPE_ENUM_NAME}.${spec.actionType}` : `'${spec.actionType}'`;
|
|
3318
|
-
const lines = [
|
|
3319
|
-
`type: ${typeText}`,
|
|
3320
|
-
`label: {
|
|
3321
|
-
id: '${spec.labelId}',
|
|
3322
|
-
defaultMessage: '${spec.defaultMessage}',
|
|
3323
|
-
description: '${spec.description}'
|
|
3324
|
-
}`
|
|
3325
|
-
];
|
|
3326
|
-
if (flagsText) {
|
|
3327
|
-
lines.push(`${FLAGS_PROPERTY_NAME}: ${flagsText}`);
|
|
3328
|
-
}
|
|
3329
|
-
if (conditionalsText) {
|
|
3330
|
-
lines.push(`${CONDITIONALS_PROPERTY_NAME}: ${conditionalsText}`);
|
|
3331
|
-
}
|
|
3332
|
-
return `{
|
|
3333
|
-
${lines.join(",\n ")}
|
|
3334
|
-
}`;
|
|
3335
|
-
}
|
|
3336
|
-
function processFile(filePath, project) {
|
|
3337
|
-
const sourceFile = project.getSourceFile(filePath);
|
|
3338
|
-
if (!sourceFile) return 0;
|
|
3339
|
-
let changes = 0;
|
|
3340
|
-
const relPath = import_path.default.relative(process.cwd(), filePath);
|
|
3341
|
-
const callExpressions = sourceFile.getDescendantsOfKind(
|
|
3342
|
-
import_ts_morph.SyntaxKind.CallExpression
|
|
3343
|
-
);
|
|
3344
|
-
for (const call of callExpressions) {
|
|
3345
|
-
const expression = call.getExpression();
|
|
3346
|
-
if (!import_ts_morph.Node.isIdentifier(expression) || expression.getText() !== DEFINE_CONFIG_NAME) {
|
|
3347
|
-
continue;
|
|
3348
|
-
}
|
|
3349
|
-
const args2 = call.getArguments();
|
|
3350
|
-
if (args2.length === 0) continue;
|
|
3351
|
-
const configArg = args2[0];
|
|
3352
|
-
if (!import_ts_morph.Node.isObjectLiteralExpression(configArg)) continue;
|
|
3353
|
-
const actionsProperty = configArg.getProperty(ACTIONS_PROPERTY_NAME);
|
|
3354
|
-
if (!actionsProperty || !import_ts_morph.Node.isPropertyAssignment(actionsProperty))
|
|
3355
|
-
continue;
|
|
3356
|
-
const actionsInitializer = actionsProperty.getInitializer();
|
|
3357
|
-
if (!actionsInitializer || !import_ts_morph.Node.isArrayLiteralExpression(actionsInitializer))
|
|
3358
|
-
continue;
|
|
3359
|
-
const elements = actionsInitializer.getElements();
|
|
3360
|
-
const requestCorrectionIndex = elements.findIndex(
|
|
3361
|
-
(el) => import_ts_morph.Node.isObjectLiteralExpression(el) && isActionOfType(el, REQUEST_CORRECTION_TYPE)
|
|
3362
|
-
);
|
|
3363
|
-
if (requestCorrectionIndex === -1) continue;
|
|
3364
|
-
const requestCorrection = elements[requestCorrectionIndex];
|
|
3365
|
-
const flagsText = getNonEmptyArrayPropertyText(
|
|
3366
|
-
requestCorrection,
|
|
3367
|
-
FLAGS_PROPERTY_NAME
|
|
3368
|
-
);
|
|
3369
|
-
const conditionalsText = getNonEmptyArrayPropertyText(
|
|
3370
|
-
requestCorrection,
|
|
3371
|
-
CONDITIONALS_PROPERTY_NAME
|
|
3372
|
-
);
|
|
3373
|
-
if (!flagsText && !conditionalsText) continue;
|
|
3374
|
-
const typeStyle = getTypeInitializerStyle(requestCorrection);
|
|
3375
|
-
let insertAt = requestCorrectionIndex + 1;
|
|
3376
|
-
for (const spec of CORRECTION_ACTIONS_TO_ADD) {
|
|
3377
|
-
const alreadyPresent = actionsInitializer.getElements().some(
|
|
3378
|
-
(el) => import_ts_morph.Node.isObjectLiteralExpression(el) && isActionOfType(el, spec.actionType)
|
|
3379
|
-
);
|
|
3380
|
-
if (alreadyPresent) continue;
|
|
3381
|
-
const text = buildCorrectionActionText(
|
|
3382
|
-
spec,
|
|
3383
|
-
typeStyle,
|
|
3384
|
-
flagsText,
|
|
3385
|
-
conditionalsText
|
|
3386
|
-
);
|
|
3387
|
-
actionsInitializer.insertElement(insertAt, text);
|
|
3388
|
-
insertAt++;
|
|
3389
|
-
changes++;
|
|
3390
|
-
console.log(
|
|
3391
|
-
` [${relPath}] Added ${spec.actionType} action carrying over REQUEST_CORRECTION's flags/conditionals`
|
|
3392
|
-
);
|
|
3393
|
-
}
|
|
3394
|
-
}
|
|
3395
|
-
return changes;
|
|
3396
|
-
}
|
|
3397
|
-
async function main() {
|
|
3398
|
-
const srcDir = import_path.default.join(process.cwd(), "src");
|
|
3399
|
-
console.log(`Scanning for defineConfig calls in: ${srcDir}
|
|
3400
|
-
`);
|
|
3401
|
-
const project = new import_ts_morph.Project({
|
|
3402
|
-
tsConfigFilePath: import_path.default.resolve(srcDir, "../tsconfig.json"),
|
|
3403
|
-
skipAddingFilesFromTsConfig: false
|
|
3404
|
-
});
|
|
3405
|
-
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
3406
|
-
const fp = sf.getFilePath();
|
|
3407
|
-
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
3408
|
-
});
|
|
3409
|
-
console.log(`Found ${sourceFiles.length} source file(s) to analyse.
|
|
3410
|
-
`);
|
|
3411
|
-
let totalChanges = 0;
|
|
3412
|
-
const modifiedFiles = [];
|
|
3413
|
-
for (const sourceFile of sourceFiles) {
|
|
3414
|
-
const filePath = sourceFile.getFilePath();
|
|
3415
|
-
const changes = processFile(filePath, project);
|
|
3416
|
-
if (changes > 0) {
|
|
3417
|
-
totalChanges += changes;
|
|
3418
|
-
modifiedFiles.push(filePath);
|
|
3419
|
-
}
|
|
3420
|
-
}
|
|
3421
|
-
if (modifiedFiles.length === 0) {
|
|
3422
|
-
console.log(
|
|
3423
|
-
"No REQUEST_CORRECTION actions with flags/conditionals found. Nothing to do."
|
|
3424
|
-
);
|
|
3425
|
-
return;
|
|
3426
|
-
}
|
|
3427
|
-
console.log(`
|
|
3428
|
-
Saving ${modifiedFiles.length} modified file(s)...`);
|
|
3429
|
-
for (const filePath of modifiedFiles) {
|
|
3430
|
-
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
3431
|
-
await sourceFile.save();
|
|
3432
|
-
console.log(` Saved: ${import_path.default.relative(process.cwd(), filePath)}`);
|
|
3433
|
-
}
|
|
3434
|
-
console.log(
|
|
3435
|
-
`
|
|
3436
|
-
Done. Added ${totalChanges} correction action config(s) across ${modifiedFiles.length} file(s).`
|
|
3437
|
-
);
|
|
3438
|
-
}
|
|
3421
|
+
// src/cli.ts
|
|
3422
|
+
var import_fs9 = __toESM(require("fs"));
|
|
3423
|
+
var import_path12 = __toESM(require("path"));
|
|
3439
3424
|
|
|
3440
|
-
// src/migrations/
|
|
3441
|
-
var
|
|
3442
|
-
var import_fs2 = require("fs");
|
|
3443
|
-
var import_path2 = __toESM(require("path"));
|
|
3425
|
+
// src/migrations/persistent/add-translations.ts
|
|
3426
|
+
var import_path = __toESM(require("path"));
|
|
3444
3427
|
|
|
3445
3428
|
// src/csv.ts
|
|
3446
3429
|
var import_fs = require("fs");
|
|
@@ -3482,20 +3465,20 @@ function idOf(line2) {
|
|
|
3482
3465
|
const comma = line2.indexOf(",");
|
|
3483
3466
|
return comma === -1 ? line2 : line2.slice(0, comma);
|
|
3484
3467
|
}
|
|
3485
|
-
function readCsvFile(
|
|
3486
|
-
if (!(0, import_fs.existsSync)(
|
|
3468
|
+
function readCsvFile(path12) {
|
|
3469
|
+
if (!(0, import_fs.existsSync)(path12)) {
|
|
3487
3470
|
return void 0;
|
|
3488
3471
|
}
|
|
3489
|
-
const contents = (0, import_fs.readFileSync)(
|
|
3472
|
+
const contents = (0, import_fs.readFileSync)(path12, "utf8");
|
|
3490
3473
|
const newline = contents.includes("\r\n") ? "\r\n" : "\n";
|
|
3491
3474
|
const trailingNewline = /\r?\n$/.test(contents);
|
|
3492
3475
|
const lines = contents.replace(/\r?\n$/, "").split(/\r?\n/);
|
|
3493
3476
|
const body = lines.slice(1).filter((line2) => line2 !== "");
|
|
3494
3477
|
return { header: lines[0], body, newline, trailingNewline };
|
|
3495
3478
|
}
|
|
3496
|
-
function writeCsvFile(
|
|
3479
|
+
function writeCsvFile(path12, file) {
|
|
3497
3480
|
(0, import_fs.writeFileSync)(
|
|
3498
|
-
|
|
3481
|
+
path12,
|
|
3499
3482
|
[file.header, ...file.body].join(file.newline) + (file.trailingNewline ? file.newline : "")
|
|
3500
3483
|
);
|
|
3501
3484
|
}
|
|
@@ -3509,554 +3492,106 @@ function addRows(file, rows) {
|
|
|
3509
3492
|
if (file.body.some((line2) => idOf(line2) === id)) {
|
|
3510
3493
|
continue;
|
|
3511
3494
|
}
|
|
3512
|
-
const
|
|
3513
|
-
if (
|
|
3495
|
+
const insertAt2 = isSorted ? file.body.findIndex((line2) => idOf(line2) > id) : -1;
|
|
3496
|
+
if (insertAt2 === -1) {
|
|
3514
3497
|
file.body.push(row);
|
|
3515
3498
|
} else {
|
|
3516
|
-
file.body.splice(
|
|
3499
|
+
file.body.splice(insertAt2, 0, row);
|
|
3517
3500
|
}
|
|
3518
3501
|
added.push(id);
|
|
3519
3502
|
}
|
|
3520
3503
|
return added;
|
|
3521
3504
|
}
|
|
3522
3505
|
|
|
3523
|
-
// src/
|
|
3524
|
-
var
|
|
3525
|
-
var
|
|
3526
|
-
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
|
|
3530
|
-
|
|
3531
|
-
|
|
3532
|
-
|
|
3533
|
-
|
|
3534
|
-
|
|
3535
|
-
var CONVERT_PAYLOAD_FUNCTION = "convertPayloadToVariable";
|
|
3536
|
-
var ROUTES_FUNCTION = "getUserNotificationRoutes";
|
|
3537
|
-
var RECOVERY_EVENTS = [
|
|
3538
|
-
{
|
|
3539
|
-
id: "password-reset-link",
|
|
3540
|
-
constant: "PASSWORD_RESET_LINK",
|
|
3541
|
-
smsTemplate: "resetPasswordLinkNotification",
|
|
3542
|
-
emailSubject: "Reset your password",
|
|
3543
|
-
routeDescription: "Handles notification for password reset recovery link",
|
|
3544
|
-
heading: "Reset your password",
|
|
3545
|
-
reason: "Someone asked to reset the password for your {{applicationName}}\n account.",
|
|
3546
|
-
linkLabel: "Reset your password"
|
|
3547
|
-
},
|
|
3548
|
-
{
|
|
3549
|
-
id: "username-reminder-link",
|
|
3550
|
-
constant: "USERNAME_REMINDER_LINK",
|
|
3551
|
-
smsTemplate: "retrieveUsernameLinkNotification",
|
|
3552
|
-
emailSubject: "Retrieve your username",
|
|
3553
|
-
routeDescription: "Handles notification for username reminder recovery link",
|
|
3554
|
-
heading: "Retrieve your username",
|
|
3555
|
-
reason: "Someone asked for a reminder of the username for your\n {{applicationName}} account.",
|
|
3556
|
-
linkLabel: "Retrieve your username"
|
|
3506
|
+
// src/translations/template.ts
|
|
3507
|
+
var REPOSITORY = "opencrvs/opencrvs-core";
|
|
3508
|
+
var TEMPLATE_TRANSLATIONS = "packages/countryconfig-template/src/translations";
|
|
3509
|
+
async function matchingRefs(namespace, prefix) {
|
|
3510
|
+
const url = `https://api.github.com/repos/${REPOSITORY}/git/matching-refs/${namespace}/${prefix}`;
|
|
3511
|
+
const response = await fetch(url, {
|
|
3512
|
+
headers: { accept: "application/vnd.github+json" }
|
|
3513
|
+
});
|
|
3514
|
+
if (!response.ok) {
|
|
3515
|
+
throw new Error(
|
|
3516
|
+
`GitHub answered ${response.status} ${response.statusText} for ${url}`
|
|
3517
|
+
);
|
|
3557
3518
|
}
|
|
3558
|
-
|
|
3559
|
-
|
|
3560
|
-
|
|
3561
|
-
|
|
3562
|
-
|
|
3563
|
-
|
|
3564
|
-
|
|
3565
|
-
|
|
3566
|
-
|
|
3567
|
-
|
|
3568
|
-
|
|
3569
|
-
|
|
3570
|
-
|
|
3571
|
-
|
|
3519
|
+
const refs = await response.json();
|
|
3520
|
+
const patchOf = (ref) => Number(ref.split(".").pop()) || 0;
|
|
3521
|
+
return refs.map(({ ref }) => ref.replace(/^refs\/(heads|tags)\//, "")).sort((a, b) => patchOf(b) - patchOf(a));
|
|
3522
|
+
}
|
|
3523
|
+
async function candidateRefs(version) {
|
|
3524
|
+
return [
|
|
3525
|
+
...await matchingRefs("heads", `release/${version}.`),
|
|
3526
|
+
...await matchingRefs("tags", `v${version}.`),
|
|
3527
|
+
"develop"
|
|
3528
|
+
];
|
|
3529
|
+
}
|
|
3530
|
+
async function fetchTemplate(refs, application) {
|
|
3531
|
+
for (const ref of refs) {
|
|
3532
|
+
const url = `https://raw.githubusercontent.com/${REPOSITORY}/${ref}/${TEMPLATE_TRANSLATIONS}/${application}.csv`;
|
|
3533
|
+
const response = await fetch(url);
|
|
3534
|
+
if (response.ok) {
|
|
3535
|
+
return { ref, contents: await response.text() };
|
|
3536
|
+
}
|
|
3537
|
+
if (response.status !== 404) {
|
|
3538
|
+
throw new Error(
|
|
3539
|
+
`GitHub answered ${response.status} ${response.statusText} for ${url}`
|
|
3540
|
+
);
|
|
3541
|
+
}
|
|
3542
|
+
}
|
|
3543
|
+
return void 0;
|
|
3544
|
+
}
|
|
3545
|
+
|
|
3546
|
+
// src/migrations/persistent/add-translations.ts
|
|
3547
|
+
var APPLICATIONS = ["client", "login"];
|
|
3572
3548
|
var skipped = [];
|
|
3573
3549
|
function warnSkipped(message) {
|
|
3574
3550
|
skipped.push(message);
|
|
3575
3551
|
console.warn(` \u26A0\uFE0F ${message}`);
|
|
3576
3552
|
}
|
|
3577
|
-
function
|
|
3578
|
-
|
|
3579
|
-
|
|
3580
|
-
|
|
3581
|
-
|
|
3582
|
-
|
|
3583
|
-
|
|
3584
|
-
|
|
3585
|
-
|
|
3586
|
-
|
|
3587
|
-
|
|
3588
|
-
|
|
3589
|
-
`'${key}'`,
|
|
3590
|
-
`"${key}"`,
|
|
3591
|
-
key
|
|
3592
|
-
]);
|
|
3593
|
-
return obj.getProperties().some(
|
|
3594
|
-
(property) => import_ts_morph2.Node.isPropertyAssignment(property) && accepted.has(property.getName().trim())
|
|
3595
|
-
);
|
|
3596
|
-
}
|
|
3597
|
-
function renderKey(obj, key, constant) {
|
|
3598
|
-
const names = obj.getProperties().filter(import_ts_morph2.Node.isPropertyAssignment).map((property) => property.getName().trim());
|
|
3599
|
-
if (names.some((name) => name.startsWith("[TriggerEvent."))) {
|
|
3600
|
-
return `[TriggerEvent.${constant}]`;
|
|
3601
|
-
}
|
|
3602
|
-
if (names.some((name) => name.startsWith("["))) {
|
|
3603
|
-
return `['${key}']`;
|
|
3604
|
-
}
|
|
3605
|
-
return `'${key}'`;
|
|
3606
|
-
}
|
|
3607
|
-
function appendEntry(sourceFile, objectName, key, valueLines) {
|
|
3608
|
-
const obj = findObjectLiteral(sourceFile.getVariableDeclaration(objectName));
|
|
3609
|
-
const properties = obj?.getProperties() ?? [];
|
|
3610
|
-
const lastProperty = properties[properties.length - 1];
|
|
3611
|
-
if (!lastProperty) return false;
|
|
3612
|
-
const indent = lastProperty.getIndentationText();
|
|
3613
|
-
const entry = valueLines.map((line2, index) => `${indent}${index === 0 ? `${key}: ${line2}` : line2}`).join("\n");
|
|
3614
|
-
sourceFile.insertText(lastProperty.getEnd(), `,
|
|
3615
|
-
${entry}`);
|
|
3616
|
-
return true;
|
|
3617
|
-
}
|
|
3618
|
-
function objectHasKeyFor(sourceFile, objectName, key, constant) {
|
|
3619
|
-
const obj = findObjectLiteral(sourceFile.getVariableDeclaration(objectName));
|
|
3620
|
-
return obj ? hasKeyFor(obj, key, constant) : false;
|
|
3621
|
-
}
|
|
3622
|
-
function renderKeyFor(sourceFile, objectName, key, constant) {
|
|
3623
|
-
const obj = findObjectLiteral(sourceFile.getVariableDeclaration(objectName));
|
|
3624
|
-
return obj ? renderKey(obj, key, constant) : `'${key}'`;
|
|
3553
|
+
function rowsToAdd(local, template) {
|
|
3554
|
+
const localColumns = parseCsvLine(local.header);
|
|
3555
|
+
const templateColumns = parseCsvLine(template.header);
|
|
3556
|
+
return template.body.filter((line2) => line2 !== "").map((line2) => {
|
|
3557
|
+
const values = parseCsvLine(line2);
|
|
3558
|
+
return toCsvLine(
|
|
3559
|
+
localColumns.map((column) => {
|
|
3560
|
+
const index = templateColumns.indexOf(column);
|
|
3561
|
+
return index === -1 ? "" : values[index] ?? "";
|
|
3562
|
+
})
|
|
3563
|
+
);
|
|
3564
|
+
});
|
|
3625
3565
|
}
|
|
3626
|
-
function
|
|
3627
|
-
const
|
|
3628
|
-
|
|
3629
|
-
|
|
3566
|
+
async function updateApplication(cwd, targetVersion, refs, application) {
|
|
3567
|
+
const relativePath = `src/translations/${application}.csv`;
|
|
3568
|
+
const local = readCsvFile(import_path.default.join(cwd, relativePath));
|
|
3569
|
+
if (!local) {
|
|
3570
|
+
warnSkipped(`${relativePath} not found; translations not added`);
|
|
3630
3571
|
return;
|
|
3631
3572
|
}
|
|
3632
|
-
const
|
|
3633
|
-
|
|
3634
|
-
);
|
|
3635
|
-
if (missingObject) {
|
|
3573
|
+
const fetched = await fetchTemplate(refs, application);
|
|
3574
|
+
if (!fetched) {
|
|
3636
3575
|
warnSkipped(
|
|
3637
|
-
`
|
|
3576
|
+
`No ${application}.csv found in the ${targetVersion} country config template on GitHub; ${application}.csv not updated`
|
|
3638
3577
|
);
|
|
3639
3578
|
return;
|
|
3640
3579
|
}
|
|
3641
|
-
|
|
3642
|
-
|
|
3643
|
-
|
|
3644
|
-
TRIGGER_VARIABLE_OBJECT,
|
|
3645
|
-
event.id,
|
|
3646
|
-
event.constant
|
|
3647
|
-
) && appendEntry(
|
|
3648
|
-
sourceFile,
|
|
3649
|
-
TRIGGER_VARIABLE_OBJECT,
|
|
3650
|
-
renderKeyFor(
|
|
3651
|
-
sourceFile,
|
|
3652
|
-
TRIGGER_VARIABLE_OBJECT,
|
|
3653
|
-
event.id,
|
|
3654
|
-
event.constant
|
|
3655
|
-
),
|
|
3656
|
-
[
|
|
3657
|
-
"z.object({",
|
|
3658
|
-
" firstname: z.string(),",
|
|
3659
|
-
" applicationName: z.string(),",
|
|
3660
|
-
" countryLogo: z.string(),",
|
|
3661
|
-
" recoveryURL: z.string()",
|
|
3662
|
-
"})"
|
|
3663
|
-
]
|
|
3664
|
-
)) {
|
|
3665
|
-
console.log(` \u2713 ${EMAIL_TEMPLATES_FILE}: ${event.id} variables`);
|
|
3666
|
-
}
|
|
3667
|
-
if (!objectHasKeyFor(
|
|
3668
|
-
sourceFile,
|
|
3669
|
-
TEMPLATES_OBJECT,
|
|
3670
|
-
event.id,
|
|
3671
|
-
event.constant
|
|
3672
|
-
) && appendEntry(
|
|
3673
|
-
sourceFile,
|
|
3674
|
-
TEMPLATES_OBJECT,
|
|
3675
|
-
renderKeyFor(sourceFile, TEMPLATES_OBJECT, event.id, event.constant),
|
|
3676
|
-
[
|
|
3677
|
-
"{",
|
|
3678
|
-
` type: '${event.id}',`,
|
|
3679
|
-
` subject: '${event.emailSubject}',`,
|
|
3680
|
-
` template: readOtherTemplate<TriggerVariable['${event.id}']>(`,
|
|
3681
|
-
` '${event.id}'`,
|
|
3682
|
-
" )",
|
|
3683
|
-
"}"
|
|
3684
|
-
]
|
|
3685
|
-
)) {
|
|
3686
|
-
console.log(` \u2713 ${EMAIL_TEMPLATES_FILE}: ${event.id} template`);
|
|
3687
|
-
}
|
|
3688
|
-
}
|
|
3689
|
-
}
|
|
3690
|
-
function updateSmsService(project, cwd) {
|
|
3691
|
-
const sourceFile = project.getSourceFile(import_path2.default.join(cwd, SMS_SERVICE_FILE));
|
|
3692
|
-
if (!sourceFile) {
|
|
3693
|
-
warnSkipped(`${SMS_SERVICE_FILE} not found; SMS templates not wired`);
|
|
3580
|
+
const template = readTemplate(fetched.contents);
|
|
3581
|
+
const added = addRows(local, rowsToAdd(local, template));
|
|
3582
|
+
if (added.length === 0) {
|
|
3694
3583
|
return;
|
|
3695
3584
|
}
|
|
3696
|
-
|
|
3697
|
-
|
|
3698
|
-
|
|
3699
|
-
].find(
|
|
3700
|
-
(objectName) => !findObjectLiteral(sourceFile.getVariableDeclaration(objectName))
|
|
3701
|
-
);
|
|
3702
|
-
if (missingObject) {
|
|
3585
|
+
try {
|
|
3586
|
+
writeCsvFile(import_path.default.join(cwd, relativePath), local);
|
|
3587
|
+
} catch (error2) {
|
|
3703
3588
|
warnSkipped(
|
|
3704
|
-
`Could not
|
|
3589
|
+
`Could not write ${relativePath} (${error2.message}); translations not added`
|
|
3705
3590
|
);
|
|
3706
3591
|
return;
|
|
3707
3592
|
}
|
|
3708
|
-
for (const
|
|
3709
|
-
|
|
3710
|
-
sourceFile,
|
|
3711
|
-
OTHER_TEMPLATES_OBJECT,
|
|
3712
|
-
event.smsTemplate,
|
|
3713
|
-
event.smsTemplate
|
|
3714
|
-
) && appendEntry(sourceFile, OTHER_TEMPLATES_OBJECT, event.smsTemplate, [
|
|
3715
|
-
`'${event.smsTemplate}'`
|
|
3716
|
-
])) {
|
|
3717
|
-
console.log(` \u2713 ${SMS_SERVICE_FILE}: ${event.smsTemplate}`);
|
|
3718
|
-
}
|
|
3719
|
-
if (!objectHasKeyFor(
|
|
3720
|
-
sourceFile,
|
|
3721
|
-
TRIGGER_TO_SMS_TEMPLATE_OBJECT,
|
|
3722
|
-
event.id,
|
|
3723
|
-
event.constant
|
|
3724
|
-
) && appendEntry(
|
|
3725
|
-
sourceFile,
|
|
3726
|
-
TRIGGER_TO_SMS_TEMPLATE_OBJECT,
|
|
3727
|
-
renderKeyFor(
|
|
3728
|
-
sourceFile,
|
|
3729
|
-
TRIGGER_TO_SMS_TEMPLATE_OBJECT,
|
|
3730
|
-
event.id,
|
|
3731
|
-
event.constant
|
|
3732
|
-
),
|
|
3733
|
-
[`'${event.smsTemplate}'`]
|
|
3734
|
-
)) {
|
|
3735
|
-
console.log(
|
|
3736
|
-
` \u2713 ${SMS_SERVICE_FILE}: ${event.id} -> ${event.smsTemplate}`
|
|
3737
|
-
);
|
|
3738
|
-
}
|
|
3739
|
-
}
|
|
3740
|
-
}
|
|
3741
|
-
function updateHandler(project, cwd) {
|
|
3742
|
-
const sourceFile = project.getSourceFile(import_path2.default.join(cwd, HANDLER_FILE));
|
|
3743
|
-
if (!sourceFile) {
|
|
3744
|
-
warnSkipped(`${HANDLER_FILE} not found; payload conversion not wired`);
|
|
3745
|
-
return;
|
|
3746
|
-
}
|
|
3747
|
-
const convertPayload = sourceFile.getFunction(CONVERT_PAYLOAD_FUNCTION);
|
|
3748
|
-
const caseBlock = convertPayload?.getFirstDescendantByKind(import_ts_morph2.SyntaxKind.SwitchStatement)?.getCaseBlock();
|
|
3749
|
-
if (!caseBlock) {
|
|
3750
|
-
warnSkipped(
|
|
3751
|
-
`Could not find a switch inside '${CONVERT_PAYLOAD_FUNCTION}' in ${HANDLER_FILE}; payload conversion not wired`
|
|
3752
|
-
);
|
|
3753
|
-
return;
|
|
3754
|
-
}
|
|
3755
|
-
const missing = RECOVERY_EVENTS.filter(
|
|
3756
|
-
(event) => !caseBlock.getText().includes(`TriggerEvent.${event.constant}`) && !caseBlock.getText().includes(`'${event.id}'`)
|
|
3757
|
-
);
|
|
3758
|
-
if (missing.length === 0) return;
|
|
3759
|
-
const existingClauses = caseBlock.getClauses();
|
|
3760
|
-
if (existingClauses.length === 0) {
|
|
3761
|
-
warnSkipped(
|
|
3762
|
-
`The switch inside '${CONVERT_PAYLOAD_FUNCTION}' in ${HANDLER_FILE} has no cases; payload conversion not wired`
|
|
3763
|
-
);
|
|
3764
|
-
return;
|
|
3765
|
-
}
|
|
3766
|
-
const defaultClause = existingClauses.find(import_ts_morph2.Node.isDefaultClause);
|
|
3767
|
-
const anchor = defaultClause ?? existingClauses[existingClauses.length - 1];
|
|
3768
|
-
const indent = anchor.getIndentationText();
|
|
3769
|
-
const lines = [
|
|
3770
|
-
...missing.map((event) => `case TriggerEvent.${event.constant}:`),
|
|
3771
|
-
` return {`,
|
|
3772
|
-
` firstname,`,
|
|
3773
|
-
` applicationName: applicationConfig.APPLICATION_NAME,`,
|
|
3774
|
-
` countryLogo: COUNTRY_LOGO_URL,`,
|
|
3775
|
-
` recoveryURL: \`\${LOGIN_URL}recover?token=\${encodeURIComponent(payload.token)}\``,
|
|
3776
|
-
` }`
|
|
3777
|
-
];
|
|
3778
|
-
if (defaultClause) {
|
|
3779
|
-
caseBlock.insertText(
|
|
3780
|
-
anchor.getStart(),
|
|
3781
|
-
`${lines.map((line2, index) => index === 0 ? line2 : `${indent}${line2}`).join("\n")}
|
|
3782
|
-
${indent}`
|
|
3783
|
-
);
|
|
3784
|
-
} else {
|
|
3785
|
-
caseBlock.insertText(
|
|
3786
|
-
anchor.getEnd(),
|
|
3787
|
-
`
|
|
3788
|
-
${lines.map((line2) => `${indent}${line2}`).join("\n")}`
|
|
3789
|
-
);
|
|
3790
|
-
}
|
|
3791
|
-
for (const event of missing) {
|
|
3792
|
-
console.log(` \u2713 ${HANDLER_FILE}: ${event.id} case`);
|
|
3793
|
-
}
|
|
3794
|
-
}
|
|
3795
|
-
function updateRoutes(project, cwd) {
|
|
3796
|
-
const sourceFile = project.getSourceFile(import_path2.default.join(cwd, ROUTES_FILE));
|
|
3797
|
-
if (!sourceFile) {
|
|
3798
|
-
warnSkipped(`${ROUTES_FILE} not found; trigger routes not registered`);
|
|
3799
|
-
return;
|
|
3800
|
-
}
|
|
3801
|
-
const routesFunction = sourceFile.getFunction(ROUTES_FUNCTION) ?? sourceFile.getFunctions().find((fn) => fn.isDefaultExport());
|
|
3802
|
-
const routesArray = routesFunction?.getFirstDescendantByKind(import_ts_morph2.SyntaxKind.ReturnStatement)?.getExpressionIfKind(import_ts_morph2.SyntaxKind.ArrayLiteralExpression);
|
|
3803
|
-
if (!routesArray) {
|
|
3804
|
-
warnSkipped(
|
|
3805
|
-
`Could not find the route array returned by '${ROUTES_FUNCTION}' in ${ROUTES_FILE}; trigger routes not registered`
|
|
3806
|
-
);
|
|
3807
|
-
return;
|
|
3808
|
-
}
|
|
3809
|
-
for (const event of RECOVERY_EVENTS) {
|
|
3810
|
-
if (routesArray.getText().includes(`/trigger/user/${event.id}`)) continue;
|
|
3811
|
-
routesArray.addElement(`{
|
|
3812
|
-
method: 'POST',
|
|
3813
|
-
path: '/trigger/user/${event.id}',
|
|
3814
|
-
handler: makeNotificationHandler('${event.id}'),
|
|
3815
|
-
options: {
|
|
3816
|
-
auth: false,
|
|
3817
|
-
tags: ['api'],
|
|
3818
|
-
description: '${event.routeDescription}'
|
|
3819
|
-
}
|
|
3820
|
-
}`);
|
|
3821
|
-
console.log(` \u2713 ${ROUTES_FILE}: POST /trigger/user/${event.id}`);
|
|
3822
|
-
}
|
|
3823
|
-
}
|
|
3824
|
-
function renderEmailTemplate(event) {
|
|
3825
|
-
return `<!--
|
|
3826
|
-
This Source Code Form is subject to the terms of the Mozilla Public
|
|
3827
|
-
License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
3828
|
-
file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
3829
|
-
|
|
3830
|
-
OpenCRVS is also distributed under the terms of the Civil Registration
|
|
3831
|
-
& Healthcare Disclaimer located at http://opencrvs.org/license.
|
|
3832
|
-
|
|
3833
|
-
Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
|
|
3834
|
-
-->
|
|
3835
|
-
<!doctype html>
|
|
3836
|
-
<html>
|
|
3837
|
-
<head>
|
|
3838
|
-
<link
|
|
3839
|
-
href="https://fonts.googleapis.com/css2?family=Noto+Sans:wght@400;700&display=swap"
|
|
3840
|
-
rel="stylesheet"
|
|
3841
|
-
/>
|
|
3842
|
-
<style type="text/css">
|
|
3843
|
-
body {
|
|
3844
|
-
font-family: 'Noto Sans', sans-serif;
|
|
3845
|
-
color: #222;
|
|
3846
|
-
padding: 16px 24px;
|
|
3847
|
-
}
|
|
3848
|
-
|
|
3849
|
-
h1 {
|
|
3850
|
-
font-size: 21px;
|
|
3851
|
-
margin-top: 32px;
|
|
3852
|
-
margin-bottom: 36px;
|
|
3853
|
-
font-weight: 700;
|
|
3854
|
-
}
|
|
3855
|
-
|
|
3856
|
-
p {
|
|
3857
|
-
font-weight: 400;
|
|
3858
|
-
font-size: 16px;
|
|
3859
|
-
line-height: 1.8;
|
|
3860
|
-
margin-bottom: 24px;
|
|
3861
|
-
}
|
|
3862
|
-
|
|
3863
|
-
i {
|
|
3864
|
-
color: #666;
|
|
3865
|
-
font-weight: 400;
|
|
3866
|
-
font-size: 16px;
|
|
3867
|
-
}
|
|
3868
|
-
</style>
|
|
3869
|
-
</head>
|
|
3870
|
-
|
|
3871
|
-
<body>
|
|
3872
|
-
<img
|
|
3873
|
-
src="{{countryLogo}}"
|
|
3874
|
-
alt="country_logo"
|
|
3875
|
-
style="max-height: 88px; max-width: 100%"
|
|
3876
|
-
/>
|
|
3877
|
-
<h1>${event.heading}</h1>
|
|
3878
|
-
<p>Hello {{firstname}},</p>
|
|
3879
|
-
<p>
|
|
3880
|
-
${event.reason}
|
|
3881
|
-
</p>
|
|
3882
|
-
|
|
3883
|
-
<div style="margin-top: 32px; margin-bottom: 32px">
|
|
3884
|
-
<a href="{{{recoveryURL}}}">${event.linkLabel}</a>
|
|
3885
|
-
</div>
|
|
3886
|
-
<br />
|
|
3887
|
-
<p>
|
|
3888
|
-
This link expires in 1 hour and can only be used once. If you did not
|
|
3889
|
-
request this, you can ignore this email.
|
|
3890
|
-
</p>
|
|
3891
|
-
<br />
|
|
3892
|
-
<p>
|
|
3893
|
-
Best regards, <br />
|
|
3894
|
-
{{applicationName}} Team
|
|
3895
|
-
</p>
|
|
3896
|
-
</body>
|
|
3897
|
-
</html>
|
|
3898
|
-
`;
|
|
3899
|
-
}
|
|
3900
|
-
function writeEmailTemplates(cwd) {
|
|
3901
|
-
const templateDir = import_path2.default.join(cwd, EMAIL_TEMPLATE_DIR);
|
|
3902
|
-
if (!(0, import_fs2.existsSync)(templateDir)) {
|
|
3903
|
-
warnSkipped(
|
|
3904
|
-
`${EMAIL_TEMPLATE_DIR} not found; recovery email bodies not written`
|
|
3905
|
-
);
|
|
3906
|
-
return;
|
|
3907
|
-
}
|
|
3908
|
-
for (const event of RECOVERY_EVENTS) {
|
|
3909
|
-
const templatePath = import_path2.default.join(templateDir, `${event.id}.html`);
|
|
3910
|
-
if ((0, import_fs2.existsSync)(templatePath)) continue;
|
|
3911
|
-
(0, import_fs2.writeFileSync)(templatePath, renderEmailTemplate(event));
|
|
3912
|
-
console.log(` \u2713 ${EMAIL_TEMPLATE_DIR}/${event.id}.html`);
|
|
3913
|
-
}
|
|
3914
|
-
}
|
|
3915
|
-
function addCsvRows(cwd, relativePath, rows) {
|
|
3916
|
-
const csvPath = import_path2.default.join(cwd, relativePath);
|
|
3917
|
-
const file = readCsvFile(csvPath);
|
|
3918
|
-
if (!file) {
|
|
3919
|
-
warnSkipped(`${relativePath} not found; translations not added`);
|
|
3920
|
-
return;
|
|
3921
|
-
}
|
|
3922
|
-
const added = addRows(file, rows);
|
|
3923
|
-
if (added.length === 0) return;
|
|
3924
|
-
for (const id of added) {
|
|
3925
|
-
console.log(` \u2713 ${relativePath}: ${id}`);
|
|
3926
|
-
}
|
|
3927
|
-
writeCsvFile(csvPath, file);
|
|
3928
|
-
}
|
|
3929
|
-
async function main2() {
|
|
3930
|
-
const cwd = process.cwd();
|
|
3931
|
-
const tsConfigFilePath = import_path2.default.join(cwd, "tsconfig.json");
|
|
3932
|
-
console.log(
|
|
3933
|
-
"Registering the password-reset-link and username-reminder-link notifications...\n"
|
|
3934
|
-
);
|
|
3935
|
-
if (!(0, import_fs2.existsSync)(tsConfigFilePath)) {
|
|
3936
|
-
warnSkipped(
|
|
3937
|
-
`tsconfig.json not found in ${cwd}; notification wiring skipped entirely`
|
|
3938
|
-
);
|
|
3939
|
-
return;
|
|
3940
|
-
}
|
|
3941
|
-
const project = new import_ts_morph2.Project({
|
|
3942
|
-
tsConfigFilePath,
|
|
3943
|
-
skipAddingFilesFromTsConfig: false,
|
|
3944
|
-
// ts-morph indents inserted code with four spaces by default, which every
|
|
3945
|
-
// country config's prettier run would immediately undo.
|
|
3946
|
-
manipulationSettings: { indentationText: import_ts_morph2.IndentationText.TwoSpaces }
|
|
3947
|
-
});
|
|
3948
|
-
updateEmailTemplates(project, cwd);
|
|
3949
|
-
updateSmsService(project, cwd);
|
|
3950
|
-
updateHandler(project, cwd);
|
|
3951
|
-
updateRoutes(project, cwd);
|
|
3952
|
-
await project.save();
|
|
3953
|
-
writeEmailTemplates(cwd);
|
|
3954
|
-
addCsvRows(cwd, NOTIFICATION_CSV, NOTIFICATION_CSV_ROWS);
|
|
3955
|
-
addCsvRows(cwd, LOGIN_CSV, LOGIN_CSV_ROWS);
|
|
3956
|
-
if (skipped.length > 0) {
|
|
3957
|
-
console.warn(
|
|
3958
|
-
`
|
|
3959
|
-
\u26A0\uFE0F ${skipped.length} step(s) were skipped. Wire the following by hand before upgrading:`
|
|
3960
|
-
);
|
|
3961
|
-
for (const message of skipped) {
|
|
3962
|
-
console.warn(` - ${message}`);
|
|
3963
|
-
}
|
|
3964
|
-
}
|
|
3965
|
-
}
|
|
3966
|
-
|
|
3967
|
-
// src/migrations/v2.1/add-translations.ts
|
|
3968
|
-
var import_path3 = __toESM(require("path"));
|
|
3969
|
-
|
|
3970
|
-
// src/translations/template.ts
|
|
3971
|
-
var REPOSITORY = "opencrvs/opencrvs-core";
|
|
3972
|
-
var TEMPLATE_TRANSLATIONS = "packages/countryconfig-template/src/translations";
|
|
3973
|
-
async function matchingRefs(namespace, prefix) {
|
|
3974
|
-
const url = `https://api.github.com/repos/${REPOSITORY}/git/matching-refs/${namespace}/${prefix}`;
|
|
3975
|
-
const response = await fetch(url, {
|
|
3976
|
-
headers: { accept: "application/vnd.github+json" }
|
|
3977
|
-
});
|
|
3978
|
-
if (!response.ok) {
|
|
3979
|
-
throw new Error(
|
|
3980
|
-
`GitHub answered ${response.status} ${response.statusText} for ${url}`
|
|
3981
|
-
);
|
|
3982
|
-
}
|
|
3983
|
-
const refs = await response.json();
|
|
3984
|
-
const patchOf = (ref) => Number(ref.split(".").pop()) || 0;
|
|
3985
|
-
return refs.map(({ ref }) => ref.replace(/^refs\/(heads|tags)\//, "")).sort((a, b) => patchOf(b) - patchOf(a));
|
|
3986
|
-
}
|
|
3987
|
-
async function candidateRefs(version) {
|
|
3988
|
-
return [
|
|
3989
|
-
...await matchingRefs("heads", `release/${version}.`),
|
|
3990
|
-
...await matchingRefs("tags", `v${version}.`),
|
|
3991
|
-
"develop"
|
|
3992
|
-
];
|
|
3993
|
-
}
|
|
3994
|
-
async function fetchTemplate(refs, application) {
|
|
3995
|
-
for (const ref of refs) {
|
|
3996
|
-
const url = `https://raw.githubusercontent.com/${REPOSITORY}/${ref}/${TEMPLATE_TRANSLATIONS}/${application}.csv`;
|
|
3997
|
-
const response = await fetch(url);
|
|
3998
|
-
if (response.ok) {
|
|
3999
|
-
return { ref, contents: await response.text() };
|
|
4000
|
-
}
|
|
4001
|
-
if (response.status !== 404) {
|
|
4002
|
-
throw new Error(
|
|
4003
|
-
`GitHub answered ${response.status} ${response.statusText} for ${url}`
|
|
4004
|
-
);
|
|
4005
|
-
}
|
|
4006
|
-
}
|
|
4007
|
-
return void 0;
|
|
4008
|
-
}
|
|
4009
|
-
|
|
4010
|
-
// src/migrations/v2.1/add-translations.ts
|
|
4011
|
-
var APPLICATIONS = ["client", "login"];
|
|
4012
|
-
var TARGET_VERSION = "2.1";
|
|
4013
|
-
var skipped2 = [];
|
|
4014
|
-
function warnSkipped2(message) {
|
|
4015
|
-
skipped2.push(message);
|
|
4016
|
-
console.warn(` \u26A0\uFE0F ${message}`);
|
|
4017
|
-
}
|
|
4018
|
-
function rowsToAdd(local, template) {
|
|
4019
|
-
const localColumns = parseCsvLine(local.header);
|
|
4020
|
-
const templateColumns = parseCsvLine(template.header);
|
|
4021
|
-
return template.body.filter((line2) => line2 !== "").map((line2) => {
|
|
4022
|
-
const values = parseCsvLine(line2);
|
|
4023
|
-
return toCsvLine(
|
|
4024
|
-
localColumns.map((column) => {
|
|
4025
|
-
const index = templateColumns.indexOf(column);
|
|
4026
|
-
return index === -1 ? "" : values[index] ?? "";
|
|
4027
|
-
})
|
|
4028
|
-
);
|
|
4029
|
-
});
|
|
4030
|
-
}
|
|
4031
|
-
async function updateApplication(cwd, refs, application) {
|
|
4032
|
-
const relativePath = `src/translations/${application}.csv`;
|
|
4033
|
-
const local = readCsvFile(import_path3.default.join(cwd, relativePath));
|
|
4034
|
-
if (!local) {
|
|
4035
|
-
warnSkipped2(`${relativePath} not found; translations not added`);
|
|
4036
|
-
return;
|
|
4037
|
-
}
|
|
4038
|
-
const fetched = await fetchTemplate(refs, application);
|
|
4039
|
-
if (!fetched) {
|
|
4040
|
-
warnSkipped2(
|
|
4041
|
-
`No ${application}.csv found in the ${TARGET_VERSION} country config template on GitHub; ${application}.csv not updated`
|
|
4042
|
-
);
|
|
4043
|
-
return;
|
|
4044
|
-
}
|
|
4045
|
-
const template = readTemplate(fetched.contents);
|
|
4046
|
-
const added = addRows(local, rowsToAdd(local, template));
|
|
4047
|
-
if (added.length === 0) {
|
|
4048
|
-
return;
|
|
4049
|
-
}
|
|
4050
|
-
try {
|
|
4051
|
-
writeCsvFile(import_path3.default.join(cwd, relativePath), local);
|
|
4052
|
-
} catch (error3) {
|
|
4053
|
-
warnSkipped2(
|
|
4054
|
-
`Could not write ${relativePath} (${error3.message}); translations not added`
|
|
4055
|
-
);
|
|
4056
|
-
return;
|
|
4057
|
-
}
|
|
4058
|
-
for (const id of added) {
|
|
4059
|
-
console.log(` \u2713 ${relativePath}: ${id}`);
|
|
3593
|
+
for (const id of added) {
|
|
3594
|
+
console.log(` \u2713 ${relativePath}: ${id}`);
|
|
4060
3595
|
}
|
|
4061
3596
|
}
|
|
4062
3597
|
function readTemplate(contents) {
|
|
@@ -4068,1177 +3603,467 @@ function readTemplate(contents) {
|
|
|
4068
3603
|
trailingNewline: true
|
|
4069
3604
|
};
|
|
4070
3605
|
}
|
|
4071
|
-
async function listRefs() {
|
|
3606
|
+
async function listRefs(targetVersion) {
|
|
4072
3607
|
try {
|
|
4073
|
-
return await candidateRefs(
|
|
4074
|
-
} catch (
|
|
4075
|
-
|
|
4076
|
-
`Could not list the ${
|
|
3608
|
+
return await candidateRefs(targetVersion);
|
|
3609
|
+
} catch (error2) {
|
|
3610
|
+
warnSkipped(
|
|
3611
|
+
`Could not list the ${targetVersion} refs on GitHub (${error2.message}); translations not added`
|
|
4077
3612
|
);
|
|
4078
3613
|
return void 0;
|
|
4079
3614
|
}
|
|
4080
3615
|
}
|
|
4081
|
-
async function
|
|
3616
|
+
async function main(targetVersion) {
|
|
4082
3617
|
const cwd = process.cwd();
|
|
4083
3618
|
console.log("Adding the translation keys core gained this version...\n");
|
|
4084
|
-
const refs = await listRefs();
|
|
3619
|
+
const refs = await listRefs(targetVersion);
|
|
4085
3620
|
if (refs) {
|
|
4086
3621
|
for (const application of APPLICATIONS) {
|
|
4087
3622
|
try {
|
|
4088
|
-
await updateApplication(cwd, refs, application);
|
|
4089
|
-
} catch (
|
|
4090
|
-
|
|
4091
|
-
`Could not read ${application}.csv from the country config template on GitHub (${
|
|
3623
|
+
await updateApplication(cwd, targetVersion, refs, application);
|
|
3624
|
+
} catch (error2) {
|
|
3625
|
+
warnSkipped(
|
|
3626
|
+
`Could not read ${application}.csv from the country config template on GitHub (${error2.message}); ${application}.csv not updated`
|
|
4092
3627
|
);
|
|
4093
3628
|
}
|
|
4094
3629
|
}
|
|
4095
3630
|
}
|
|
4096
|
-
if (
|
|
3631
|
+
if (skipped.length > 0) {
|
|
4097
3632
|
console.warn(
|
|
4098
3633
|
`
|
|
4099
|
-
\u26A0\uFE0F ${
|
|
3634
|
+
\u26A0\uFE0F ${skipped.length} step(s) were skipped. Add the missing translations by hand before upgrading:`
|
|
4100
3635
|
);
|
|
4101
|
-
for (const message of
|
|
3636
|
+
for (const message of skipped) {
|
|
4102
3637
|
console.warn(` - ${message}`);
|
|
4103
3638
|
}
|
|
4104
3639
|
}
|
|
4105
3640
|
}
|
|
4106
3641
|
|
|
4107
|
-
// src/migrations/
|
|
4108
|
-
var
|
|
4109
|
-
var
|
|
4110
|
-
var
|
|
4111
|
-
var
|
|
4112
|
-
var
|
|
4113
|
-
var
|
|
4114
|
-
|
|
4115
|
-
|
|
4116
|
-
|
|
4117
|
-
|
|
4118
|
-
console.warn(` \u26A0\uFE0F ${message}`);
|
|
4119
|
-
}
|
|
4120
|
-
var TELEMETRY_HANDLER_SOURCE = `/*
|
|
4121
|
-
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
4122
|
-
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
4123
|
-
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
4124
|
-
*
|
|
4125
|
-
* OpenCRVS is also distributed under the terms of the Civil Registration
|
|
4126
|
-
* & Healthcare Disclaimer located at http://opencrvs.org/license.
|
|
4127
|
-
*
|
|
4128
|
-
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
|
|
4129
|
-
*/
|
|
4130
|
-
|
|
4131
|
-
import { Request, ResponseToolkit } from '@hapi/hapi'
|
|
4132
|
-
import * as Joi from 'joi'
|
|
4133
|
-
import { sendTelemetry, TelemetryReport } from '@opencrvs/toolkit/telemetry'
|
|
4134
|
-
import { env } from '@countryconfig/environment'
|
|
4135
|
-
import { logger } from '@countryconfig/logger'
|
|
4136
|
-
import { applicationConfig } from '@countryconfig/api/application/application-config'
|
|
4137
|
-
|
|
4138
|
-
/** Report the events service posts to \`/trigger/telemetry\`. */
|
|
4139
|
-
export const telemetrySchema = Joi.object({
|
|
4140
|
-
reported_at: Joi.string().isoDate().required(),
|
|
4141
|
-
app_version: Joi.string().optional(),
|
|
4142
|
-
metrics: Joi.object()
|
|
4143
|
-
.pattern(
|
|
4144
|
-
Joi.string(),
|
|
4145
|
-
Joi.alternatives(Joi.number(), Joi.string(), Joi.boolean())
|
|
4146
|
-
)
|
|
4147
|
-
.required()
|
|
4148
|
-
})
|
|
4149
|
-
|
|
4150
|
-
interface IncomingReport {
|
|
4151
|
-
reported_at: string
|
|
4152
|
-
app_version?: string
|
|
4153
|
-
metrics: Record<string, number | string | boolean>
|
|
4154
|
-
}
|
|
4155
|
-
|
|
4156
|
-
/** Logged once at countryconfig startup while telemetry is disabled. */
|
|
4157
|
-
export const TELEMETRY_DISABLED_NOTICE =
|
|
4158
|
-
'Telemetry is disabled. Help improve OpenCRVS by sharing anonymous, ' +
|
|
4159
|
-
'aggregate usage metrics (registration and certificate counts, active ' +
|
|
4160
|
-
'users, uptime) \u2014 no personal, health, or otherwise protected record data ' +
|
|
4161
|
-
'ever leaves your instance. Enable it by setting TELEMETRY_ENABLED=true on ' +
|
|
4162
|
-
'the countryconfig service.'
|
|
4163
|
-
|
|
4164
|
-
/**
|
|
4165
|
-
* Receives a usage report from the events service and, when telemetry is
|
|
4166
|
-
* enabled for this instance, stamps the instance identity onto it and forwards
|
|
4167
|
-
* it to the status service via the toolkit's \`sendTelemetry\` (which owns the
|
|
4168
|
-
* endpoint and payload schema). The events service is unaware of whether
|
|
4169
|
-
* telemetry is enabled or of the country code / domain / environment reported.
|
|
4170
|
-
*/
|
|
4171
|
-
export async function telemetryHandler(request: Request, h: ResponseToolkit) {
|
|
4172
|
-
// Only accept OpenCRVS *system* tokens (the events service's service
|
|
4173
|
-
// token has userType 'system'). A logged-in user's token is a 'user' token,
|
|
4174
|
-
// so a user cannot submit telemetry with their own credentials \u2014 and the
|
|
4175
|
-
// service-token endpoint is not reachable through the public gateway.
|
|
4176
|
-
const credentials = request.auth.credentials as
|
|
4177
|
-
| { userType?: string }
|
|
4178
|
-
| undefined
|
|
4179
|
-
if (credentials?.userType !== 'system') {
|
|
4180
|
-
logger.warn('Telemetry: rejected a request that is not from a system token')
|
|
4181
|
-
return h.response({ error: 'forbidden' }).code(403)
|
|
4182
|
-
}
|
|
4183
|
-
|
|
4184
|
-
if (!env.TELEMETRY_ENABLED) {
|
|
4185
|
-
// The encouraging notice is logged once at startup (see index.ts); keep the
|
|
4186
|
-
// per-report path quiet.
|
|
4187
|
-
return h.response({ status: 'skipped' }).code(200)
|
|
4188
|
-
}
|
|
4189
|
-
|
|
4190
|
-
const incoming = request.payload as IncomingReport
|
|
4191
|
-
|
|
4192
|
-
// Only production instances report; staging, QA and local build the report
|
|
4193
|
-
// but never reach the status service. (This gate used to live in the
|
|
4194
|
-
// toolkit's sendTelemetry; each country config now owns it.)
|
|
4195
|
-
if (!env.isProduction) {
|
|
4196
|
-
logger.info(
|
|
4197
|
-
\`Telemetry: report for \${incoming.reported_at} was not sent \u2014 only production instances report\`
|
|
4198
|
-
)
|
|
4199
|
-
return h.response({ status: 'skipped' }).code(200)
|
|
4200
|
-
}
|
|
4201
|
-
|
|
4202
|
-
const report: TelemetryReport = {
|
|
4203
|
-
reported_at: incoming.reported_at,
|
|
4204
|
-
country_code: env.COUNTRY_CODE,
|
|
4205
|
-
organisation: env.ORGANISATION,
|
|
4206
|
-
// env.DOMAIN defaults to a wildcard for CORS in some setups; treat that as
|
|
4207
|
-
// "no domain" rather than reporting a literal "*".
|
|
4208
|
-
domain: env.DOMAIN && env.DOMAIN !== '*' ? env.DOMAIN : null,
|
|
4209
|
-
instance: {
|
|
4210
|
-
application_name: applicationConfig.APPLICATION_NAME,
|
|
4211
|
-
environment: env.ENVIRONMENT_NAME,
|
|
4212
|
-
app_version: incoming.app_version
|
|
4213
|
-
},
|
|
4214
|
-
metrics: incoming.metrics
|
|
4215
|
-
}
|
|
4216
|
-
|
|
4217
|
-
let result
|
|
4218
|
-
try {
|
|
4219
|
-
result = await sendTelemetry(report)
|
|
4220
|
-
} catch (error) {
|
|
4221
|
-
const message = error instanceof Error ? error.message : String(error)
|
|
4222
|
-
logger.error(\`Telemetry: forwarding to status service failed: \${message}\`)
|
|
4223
|
-
return h.response({ status: 'error' }).code(502)
|
|
4224
|
-
}
|
|
4225
|
-
|
|
4226
|
-
if (result.outcome === 'rejected') {
|
|
4227
|
-
logger.error(
|
|
4228
|
-
\`Telemetry: status service rejected report (HTTP \${result.status}): \${result.detail ?? ''}\`
|
|
4229
|
-
)
|
|
4230
|
-
return h.response({ status: 'error' }).code(502)
|
|
4231
|
-
}
|
|
4232
|
-
|
|
4233
|
-
logger.info(
|
|
4234
|
-
\`Telemetry: forwarded report for \${report.reported_at} to the status service\`
|
|
4235
|
-
)
|
|
4236
|
-
return h.response({ status: 'forwarded' }).code(202)
|
|
4237
|
-
}
|
|
4238
|
-
`;
|
|
4239
|
-
var TELEMETRY_DISABLED = {
|
|
4240
|
-
enabled: false,
|
|
4241
|
-
countryCode: "",
|
|
4242
|
-
organisation: ""
|
|
4243
|
-
};
|
|
4244
|
-
async function promptTelemetryConfig() {
|
|
4245
|
-
if (!process.stdin.isTTY) {
|
|
4246
|
-
return TELEMETRY_DISABLED;
|
|
4247
|
-
}
|
|
4248
|
-
const { confirm: confirm3, input: input4 } = await import("@inquirer/prompts");
|
|
4249
|
-
const enabled = await confirm3({
|
|
4250
|
-
message: "Enable anonymous usage telemetry to help improve OpenCRVS? Only aggregate metrics are shared \u2014 no personal or protected data.",
|
|
4251
|
-
default: true
|
|
4252
|
-
});
|
|
4253
|
-
if (!enabled) {
|
|
4254
|
-
return TELEMETRY_DISABLED;
|
|
4255
|
-
}
|
|
4256
|
-
const countryCode = (await input4({
|
|
4257
|
-
message: "Country code (ISO alpha-3, e.g. FAR):",
|
|
4258
|
-
validate: (value) => /^[A-Za-z]{3}$/.test(value.trim()) || "Enter a 3-letter ISO alpha-3 code."
|
|
4259
|
-
})).trim().toUpperCase();
|
|
4260
|
-
const organisation = (await input4({
|
|
4261
|
-
message: "Organisation running this instance:",
|
|
4262
|
-
validate: (value) => value.trim() !== "" || "Enter an organisation name."
|
|
4263
|
-
})).trim();
|
|
4264
|
-
return { enabled: true, countryCode, organisation };
|
|
4265
|
-
}
|
|
4266
|
-
function writeTelemetryHandler(cwd) {
|
|
4267
|
-
const handlerPath = import_path4.default.join(cwd, HANDLER_FILE2);
|
|
4268
|
-
if ((0, import_fs3.existsSync)(handlerPath)) {
|
|
4269
|
-
console.log(` ${HANDLER_FILE2} already present; left unchanged`);
|
|
4270
|
-
return;
|
|
4271
|
-
}
|
|
4272
|
-
(0, import_fs3.mkdirSync)(import_path4.default.dirname(handlerPath), { recursive: true });
|
|
4273
|
-
(0, import_fs3.writeFileSync)(handlerPath, TELEMETRY_HANDLER_SOURCE);
|
|
4274
|
-
console.log(` \u2713 ${HANDLER_FILE2}`);
|
|
4275
|
-
}
|
|
4276
|
-
function appendProperty(sourceFile, object2, name, valueLines) {
|
|
4277
|
-
const properties = object2.getProperties();
|
|
4278
|
-
const lastProperty = properties[properties.length - 1];
|
|
4279
|
-
if (!lastProperty) return false;
|
|
4280
|
-
const indent = lastProperty.getIndentationText();
|
|
4281
|
-
const entry = valueLines.map((line2, index) => `${indent}${index === 0 ? `${name}: ${line2}` : line2}`).join("\n");
|
|
4282
|
-
sourceFile.insertText(lastProperty.getEnd(), `,
|
|
4283
|
-
${entry}`);
|
|
4284
|
-
return true;
|
|
4285
|
-
}
|
|
4286
|
-
function ensureEnvalidNamedImports(sourceFile, names) {
|
|
4287
|
-
const importDeclaration = sourceFile.getImportDeclarations().find((declaration) => declaration.getModuleSpecifierValue() === "envalid");
|
|
4288
|
-
if (!importDeclaration) {
|
|
4289
|
-
warnSkipped3(
|
|
4290
|
-
`Could not find the 'envalid' import in ${ENVIRONMENT_FILE}; import { ${names.join(", ")} } by hand`
|
|
4291
|
-
);
|
|
4292
|
-
return;
|
|
4293
|
-
}
|
|
4294
|
-
const existing = new Set(
|
|
4295
|
-
importDeclaration.getNamedImports().map((named) => named.getName())
|
|
4296
|
-
);
|
|
4297
|
-
for (const name of names) {
|
|
4298
|
-
if (!existing.has(name)) {
|
|
4299
|
-
importDeclaration.addNamedImport(name);
|
|
4300
|
-
}
|
|
4301
|
-
}
|
|
4302
|
-
}
|
|
4303
|
-
function getCleanEnvObject(sourceFile) {
|
|
4304
|
-
const options = sourceFile.getDescendantsOfKind(import_ts_morph3.SyntaxKind.CallExpression).find((call) => call.getExpression().getText() === "cleanEnv")?.getArguments()[1];
|
|
4305
|
-
return options && import_ts_morph3.Node.isObjectLiteralExpression(options) ? options : void 0;
|
|
4306
|
-
}
|
|
4307
|
-
function upsertEnvVar(sourceFile, name, kind, defaultExpr, desc, update) {
|
|
4308
|
-
const object2 = getCleanEnvObject(sourceFile);
|
|
4309
|
-
if (!object2) return;
|
|
4310
|
-
const existing = object2.getProperty(name);
|
|
4311
|
-
if (existing && import_ts_morph3.Node.isPropertyAssignment(existing)) {
|
|
4312
|
-
if (!update) return;
|
|
4313
|
-
const options = existing.getInitializerIfKind(import_ts_morph3.SyntaxKind.CallExpression)?.getArguments()[0];
|
|
4314
|
-
if (options && import_ts_morph3.Node.isObjectLiteralExpression(options)) {
|
|
4315
|
-
const defaultProperty = options.getProperty("default");
|
|
4316
|
-
if (defaultProperty && import_ts_morph3.Node.isPropertyAssignment(defaultProperty)) {
|
|
4317
|
-
defaultProperty.setInitializer(defaultExpr);
|
|
4318
|
-
} else {
|
|
4319
|
-
options.insertPropertyAssignment(0, {
|
|
4320
|
-
name: "default",
|
|
4321
|
-
initializer: defaultExpr
|
|
4322
|
-
});
|
|
4323
|
-
}
|
|
4324
|
-
console.log(` \u2713 ${ENVIRONMENT_FILE}: ${name} default set`);
|
|
4325
|
-
}
|
|
4326
|
-
return;
|
|
4327
|
-
}
|
|
4328
|
-
if (appendProperty(sourceFile, object2, name, [
|
|
4329
|
-
`${kind}({`,
|
|
4330
|
-
` default: ${defaultExpr},`,
|
|
4331
|
-
` desc: ${JSON.stringify(desc)}`,
|
|
4332
|
-
"})"
|
|
4333
|
-
])) {
|
|
4334
|
-
console.log(` \u2713 ${ENVIRONMENT_FILE}: ${name}`);
|
|
4335
|
-
}
|
|
4336
|
-
}
|
|
4337
|
-
function addEnvironmentVariables(project, cwd, config) {
|
|
4338
|
-
const sourceFile = project.addSourceFileAtPathIfExists(
|
|
4339
|
-
import_path4.default.join(cwd, ENVIRONMENT_FILE)
|
|
4340
|
-
);
|
|
4341
|
-
if (!sourceFile) {
|
|
4342
|
-
warnSkipped3(
|
|
4343
|
-
`${ENVIRONMENT_FILE} not found; add the telemetry env vars by hand`
|
|
4344
|
-
);
|
|
4345
|
-
return;
|
|
4346
|
-
}
|
|
4347
|
-
if (!getCleanEnvObject(sourceFile)) {
|
|
4348
|
-
warnSkipped3(
|
|
4349
|
-
`Could not find the cleanEnv(...) config object in ${ENVIRONMENT_FILE}; add the telemetry env vars by hand`
|
|
4350
|
-
);
|
|
4351
|
-
return;
|
|
4352
|
-
}
|
|
4353
|
-
ensureEnvalidNamedImports(sourceFile, ["bool", "str"]);
|
|
4354
|
-
upsertEnvVar(
|
|
4355
|
-
sourceFile,
|
|
4356
|
-
"TELEMETRY_ENABLED",
|
|
4357
|
-
"bool",
|
|
4358
|
-
config.enabled ? "true" : "false",
|
|
4359
|
-
"When true, usage telemetry received from the events service is forwarded to the OpenCRVS status service.",
|
|
4360
|
-
true
|
|
4361
|
-
);
|
|
4362
|
-
upsertEnvVar(
|
|
4363
|
-
sourceFile,
|
|
4364
|
-
"COUNTRY_CODE",
|
|
4365
|
-
"str",
|
|
4366
|
-
config.enabled ? JSON.stringify(config.countryCode) : `'FAR'`,
|
|
4367
|
-
"ISO-style country code of this instance, reported with telemetry.",
|
|
4368
|
-
config.enabled
|
|
4369
|
-
);
|
|
4370
|
-
upsertEnvVar(
|
|
4371
|
-
sourceFile,
|
|
4372
|
-
"ORGANISATION",
|
|
4373
|
-
"str",
|
|
4374
|
-
config.enabled ? JSON.stringify(config.organisation) : `''`,
|
|
4375
|
-
"Organisation running this instance, reported with telemetry. Empty by default.",
|
|
4376
|
-
config.enabled
|
|
4377
|
-
);
|
|
4378
|
-
upsertEnvVar(
|
|
4379
|
-
sourceFile,
|
|
4380
|
-
"ENVIRONMENT_NAME",
|
|
4381
|
-
"str",
|
|
4382
|
-
`'development'`,
|
|
4383
|
-
'Environment name (e.g. "production", "staging") reported as the telemetry environment.',
|
|
4384
|
-
false
|
|
4385
|
-
);
|
|
4386
|
-
}
|
|
4387
|
-
function ensureHandlerNamedImports(sourceFile, names) {
|
|
4388
|
-
const importDeclaration = sourceFile.getImportDeclarations().find(
|
|
4389
|
-
(declaration) => declaration.getModuleSpecifierValue() === HANDLER_MODULE
|
|
4390
|
-
);
|
|
4391
|
-
if (!importDeclaration) {
|
|
4392
|
-
sourceFile.addImportDeclaration({
|
|
4393
|
-
moduleSpecifier: HANDLER_MODULE,
|
|
4394
|
-
namedImports: names
|
|
4395
|
-
});
|
|
4396
|
-
console.log(` \u2713 ${INDEX_FILE}: import ${HANDLER_MODULE}`);
|
|
4397
|
-
return;
|
|
4398
|
-
}
|
|
4399
|
-
const existing = new Set(
|
|
4400
|
-
importDeclaration.getNamedImports().map((named) => named.getName())
|
|
4401
|
-
);
|
|
4402
|
-
const missing = names.filter((name) => !existing.has(name));
|
|
4403
|
-
for (const name of missing) {
|
|
4404
|
-
importDeclaration.addNamedImport(name);
|
|
4405
|
-
}
|
|
4406
|
-
if (missing.length > 0) {
|
|
4407
|
-
console.log(
|
|
4408
|
-
` \u2713 ${INDEX_FILE}: import ${missing.join(", ")} from ${HANDLER_MODULE}`
|
|
4409
|
-
);
|
|
4410
|
-
}
|
|
4411
|
-
}
|
|
4412
|
-
function wireIndex(project, cwd) {
|
|
4413
|
-
const sourceFile = project.addSourceFileAtPathIfExists(
|
|
4414
|
-
import_path4.default.join(cwd, INDEX_FILE)
|
|
4415
|
-
);
|
|
4416
|
-
if (!sourceFile) {
|
|
4417
|
-
warnSkipped3(
|
|
4418
|
-
`${INDEX_FILE} not found; register POST /trigger/telemetry and the startup notice by hand`
|
|
4419
|
-
);
|
|
4420
|
-
return;
|
|
4421
|
-
}
|
|
4422
|
-
ensureHandlerNamedImports(sourceFile, [
|
|
4423
|
-
"telemetryHandler",
|
|
4424
|
-
"telemetrySchema",
|
|
4425
|
-
"TELEMETRY_DISABLED_NOTICE"
|
|
4426
|
-
]);
|
|
4427
|
-
if (!sourceFile.getText().includes("path: '/trigger/telemetry'")) {
|
|
4428
|
-
const lastRouteStatement = sourceFile.getDescendantsOfKind(import_ts_morph3.SyntaxKind.CallExpression).filter((call) => call.getExpression().getText() === "server.route").map(
|
|
4429
|
-
(call) => call.getFirstAncestorByKind(import_ts_morph3.SyntaxKind.ExpressionStatement)
|
|
4430
|
-
).filter(
|
|
4431
|
-
(statement) => Boolean(statement)
|
|
4432
|
-
).pop();
|
|
4433
|
-
if (!lastRouteStatement) {
|
|
4434
|
-
warnSkipped3(
|
|
4435
|
-
`Could not find a server.route(...) call in ${INDEX_FILE}; register POST /trigger/telemetry by hand`
|
|
4436
|
-
);
|
|
4437
|
-
} else {
|
|
4438
|
-
const indent = lastRouteStatement.getIndentationText();
|
|
4439
|
-
const route = [
|
|
4440
|
-
`server.route({`,
|
|
4441
|
-
` method: 'POST',`,
|
|
4442
|
-
` path: '/trigger/telemetry',`,
|
|
4443
|
-
` handler: telemetryHandler,`,
|
|
4444
|
-
` options: {`,
|
|
4445
|
-
` tags: ['api', 'triggers'],`,
|
|
4446
|
-
` validate: {`,
|
|
4447
|
-
` payload: telemetrySchema`,
|
|
4448
|
-
` },`,
|
|
4449
|
-
` description:`,
|
|
4450
|
-
` 'Receives a usage report from the events service and forwards it to the status service when telemetry is enabled'`,
|
|
4451
|
-
` }`,
|
|
4452
|
-
`})`
|
|
4453
|
-
].map((line2) => line2 ? `${indent}${line2}` : line2).join("\n");
|
|
4454
|
-
sourceFile.insertText(lastRouteStatement.getEnd(), `
|
|
4455
|
-
|
|
4456
|
-
${route}`);
|
|
4457
|
-
console.log(` \u2713 ${INDEX_FILE}: POST /trigger/telemetry`);
|
|
4458
|
-
}
|
|
4459
|
-
}
|
|
4460
|
-
if (!sourceFile.getText().includes("logger.info(TELEMETRY_DISABLED_NOTICE)")) {
|
|
4461
|
-
const startedLog = sourceFile.getDescendantsOfKind(import_ts_morph3.SyntaxKind.ExpressionStatement).find(
|
|
4462
|
-
(statement) => statement.getText().includes("Server successfully started")
|
|
4463
|
-
);
|
|
4464
|
-
if (!startedLog) {
|
|
4465
|
-
warnSkipped3(
|
|
4466
|
-
`Could not find the startup log in ${INDEX_FILE}; log TELEMETRY_DISABLED_NOTICE when TELEMETRY_ENABLED is false by hand`
|
|
4467
|
-
);
|
|
4468
|
-
} else {
|
|
4469
|
-
const indent = startedLog.getIndentationText();
|
|
4470
|
-
const notice = [
|
|
4471
|
-
`if (!env.TELEMETRY_ENABLED) {`,
|
|
4472
|
-
` logger.info(TELEMETRY_DISABLED_NOTICE)`,
|
|
4473
|
-
`}`
|
|
4474
|
-
].map((line2) => line2 ? `${indent}${line2}` : line2).join("\n");
|
|
4475
|
-
sourceFile.insertText(startedLog.getEnd(), `
|
|
4476
|
-
|
|
4477
|
-
${notice}`);
|
|
4478
|
-
console.log(` \u2713 ${INDEX_FILE}: telemetry-disabled startup notice`);
|
|
4479
|
-
if (!sourceFile.getImportDeclarations().some((d) => d.getModuleSpecifierValue() === "./environment")) {
|
|
4480
|
-
warnSkipped3(
|
|
4481
|
-
`The startup notice reads env.TELEMETRY_ENABLED but ${INDEX_FILE} does not import env from './environment'; import it by hand`
|
|
4482
|
-
);
|
|
4483
|
-
}
|
|
4484
|
-
}
|
|
4485
|
-
}
|
|
4486
|
-
}
|
|
4487
|
-
async function main4() {
|
|
4488
|
-
const cwd = process.cwd();
|
|
4489
|
-
const config = await promptTelemetryConfig();
|
|
4490
|
-
console.log(
|
|
4491
|
-
`
|
|
4492
|
-
Adding daily usage telemetry (${config.enabled ? `enabled for ${config.countryCode}` : "disabled"} by default)...
|
|
4493
|
-
`
|
|
3642
|
+
// src/migrations/move-declaration-to-declare-action.ts
|
|
3643
|
+
var import_ts_morph = require("ts-morph");
|
|
3644
|
+
var import_path2 = __toESM(require("path"));
|
|
3645
|
+
var DEFINE_CONFIG_NAME = "defineConfig";
|
|
3646
|
+
var DECLARATION_PROPERTY_NAME = "declaration";
|
|
3647
|
+
var ACTIONS_PROPERTY_NAME = "actions";
|
|
3648
|
+
var DECLARE_ACTION_TYPE = "DECLARE";
|
|
3649
|
+
function location(node) {
|
|
3650
|
+
const relPath = import_path2.default.relative(
|
|
3651
|
+
process.cwd(),
|
|
3652
|
+
node.getSourceFile().getFilePath()
|
|
4494
3653
|
);
|
|
4495
|
-
|
|
4496
|
-
const project = new import_ts_morph3.Project({
|
|
4497
|
-
// ts-morph indents inserted code with four spaces and double-quotes strings
|
|
4498
|
-
// by default, both of which the country config's prettier run would undo.
|
|
4499
|
-
manipulationSettings: {
|
|
4500
|
-
indentationText: import_ts_morph3.IndentationText.TwoSpaces,
|
|
4501
|
-
quoteKind: import_ts_morph3.QuoteKind.Single
|
|
4502
|
-
}
|
|
4503
|
-
});
|
|
4504
|
-
addEnvironmentVariables(project, cwd, config);
|
|
4505
|
-
wireIndex(project, cwd);
|
|
4506
|
-
await project.save();
|
|
4507
|
-
if (skipped3.length > 0) {
|
|
4508
|
-
console.warn(
|
|
4509
|
-
`
|
|
4510
|
-
\u26A0\uFE0F ${skipped3.length} telemetry step(s) were skipped. Wire the following by hand:`
|
|
4511
|
-
);
|
|
4512
|
-
for (const message of skipped3) {
|
|
4513
|
-
console.warn(` - ${message}`);
|
|
4514
|
-
}
|
|
4515
|
-
}
|
|
3654
|
+
return `${relPath}:${node.getStartLineNumber()}`;
|
|
4516
3655
|
}
|
|
4517
|
-
|
|
4518
|
-
|
|
4519
|
-
|
|
4520
|
-
|
|
4521
|
-
|
|
4522
|
-
var import_path6 = __toESM(require("path"));
|
|
4523
|
-
|
|
4524
|
-
// src/migrations/v2.1/template-files.ts
|
|
4525
|
-
var import_fs4 = require("fs");
|
|
4526
|
-
var import_path5 = __toESM(require("path"));
|
|
4527
|
-
function findTemplateDir() {
|
|
4528
|
-
const candidates = [
|
|
4529
|
-
import_path5.default.resolve(__dirname, "templates", "countryconfig-template"),
|
|
4530
|
-
import_path5.default.resolve(__dirname, "../../../../countryconfig-template")
|
|
4531
|
-
];
|
|
4532
|
-
const templateDir = candidates.find(
|
|
4533
|
-
(candidate) => (0, import_fs4.existsSync)(import_path5.default.join(candidate, "Tiltfile"))
|
|
4534
|
-
);
|
|
4535
|
-
if (!templateDir) {
|
|
4536
|
-
throw new Error(
|
|
4537
|
-
`Country config template files not found in any of: ${candidates.join(", ")}`
|
|
4538
|
-
);
|
|
3656
|
+
function isToolkitDefineConfigCall(call) {
|
|
3657
|
+
const symbol = call.getExpression().getSymbol();
|
|
3658
|
+
const resolved = symbol?.getAliasedSymbol() ?? symbol;
|
|
3659
|
+
if (resolved?.getName() !== DEFINE_CONFIG_NAME) {
|
|
3660
|
+
return false;
|
|
4539
3661
|
}
|
|
4540
|
-
return
|
|
3662
|
+
return resolved.getDeclarations().some((declaration) => declaration.getSourceFile().isDeclarationFile());
|
|
4541
3663
|
}
|
|
4542
|
-
function
|
|
4543
|
-
const
|
|
4544
|
-
|
|
4545
|
-
return [];
|
|
4546
|
-
}
|
|
4547
|
-
return (0, import_fs4.readdirSync)(absolute, { withFileTypes: true }).flatMap((entry) => {
|
|
4548
|
-
const relative = import_path5.default.posix.join(dir, entry.name);
|
|
4549
|
-
return entry.isDirectory() ? listFiles(root, relative) : [relative];
|
|
4550
|
-
});
|
|
3664
|
+
function findProperty(literal, name) {
|
|
3665
|
+
const property = literal.getProperty(name);
|
|
3666
|
+
return import_ts_morph.Node.isPropertyAssignment(property) || import_ts_morph.Node.isShorthandPropertyAssignment(property) ? property : void 0;
|
|
4551
3667
|
}
|
|
4552
|
-
|
|
4553
|
-
|
|
4554
|
-
|
|
4555
|
-
var ASSETS_DIR = "assets";
|
|
4556
|
-
var BASE_URL = "https://raw.githubusercontent.com/opencrvs/opencrvs-farajaland/release/v2.0.0/infrastructure";
|
|
4557
|
-
var SOURCE_OF = {
|
|
4558
|
-
"elasticsearch/reindex.sh": "deployment/reindex.sh"
|
|
4559
|
-
};
|
|
4560
|
-
var MIGRATED_DIRS = ["metabase", "postgres", "deployment", "elasticsearch"];
|
|
4561
|
-
var NOT_MOVED = ["postgres/on-deploy.sh"];
|
|
4562
|
-
var isMigrated = (file) => MIGRATED_DIRS.some((dir) => file.startsWith(`${dir}/`));
|
|
4563
|
-
function tryGit(args2) {
|
|
4564
|
-
try {
|
|
4565
|
-
(0, import_child_process.execFileSync)("git", args2, { stdio: "ignore" });
|
|
3668
|
+
function mayHaveDeclareType(actionType, node) {
|
|
3669
|
+
const typeProperty = actionType.getProperty("type");
|
|
3670
|
+
if (!typeProperty) {
|
|
4566
3671
|
return true;
|
|
4567
|
-
} catch {
|
|
4568
|
-
return false;
|
|
4569
3672
|
}
|
|
3673
|
+
const type = typeProperty.getTypeAtLocation(node);
|
|
3674
|
+
const values = type.isUnion() ? type.getUnionTypes() : [type];
|
|
3675
|
+
return !values.every(
|
|
3676
|
+
(value) => value.isStringLiteral() && value.getLiteralValue() !== DECLARE_ACTION_TYPE
|
|
3677
|
+
);
|
|
4570
3678
|
}
|
|
4571
|
-
function
|
|
4572
|
-
if (
|
|
4573
|
-
|
|
4574
|
-
`${process.cwd()} is not a git repository. Initialise git (or run the upgrade inside a git checkout) before re-running.`
|
|
4575
|
-
);
|
|
3679
|
+
function mayBeDeclareAction(node) {
|
|
3680
|
+
if (import_ts_morph.Node.isObjectLiteralExpression(node)) {
|
|
3681
|
+
return isDeclareAction(node);
|
|
4576
3682
|
}
|
|
4577
|
-
|
|
4578
|
-
|
|
4579
|
-
|
|
4580
|
-
|
|
4581
|
-
|
|
4582
|
-
return (0, import_fs5.existsSync)(file) ? toBytes((0, import_fs5.readFileSync)(file)) : void 0;
|
|
4583
|
-
}
|
|
4584
|
-
function mergeFile(file, ours, base, theirs) {
|
|
4585
|
-
const dir = (0, import_fs5.mkdtempSync)(import_path6.default.join((0, import_os.tmpdir)(), "opencrvs-merge-assets-"));
|
|
4586
|
-
try {
|
|
4587
|
-
const [oursPath, basePath, theirsPath] = ["ours", "base", "theirs"].map(
|
|
4588
|
-
(name) => import_path6.default.join(dir, name)
|
|
3683
|
+
if (import_ts_morph.Node.isSpreadElement(node)) {
|
|
3684
|
+
const arrayType = node.getExpression().getType();
|
|
3685
|
+
const elementTypes = arrayType.isTuple() ? arrayType.getTupleElements() : [arrayType.getArrayElementType()];
|
|
3686
|
+
return elementTypes.some(
|
|
3687
|
+
(elementType) => !elementType || mayHaveDeclareType(elementType, node)
|
|
4589
3688
|
);
|
|
4590
|
-
(0, import_fs5.writeFileSync)(oursPath, ours);
|
|
4591
|
-
(0, import_fs5.writeFileSync)(basePath, base);
|
|
4592
|
-
(0, import_fs5.writeFileSync)(theirsPath, theirs);
|
|
4593
|
-
const args2 = [
|
|
4594
|
-
"merge-file",
|
|
4595
|
-
"-q",
|
|
4596
|
-
"-L",
|
|
4597
|
-
`infrastructure/${file}`,
|
|
4598
|
-
"-L",
|
|
4599
|
-
"v2.0",
|
|
4600
|
-
"-L",
|
|
4601
|
-
`v2.1 template`,
|
|
4602
|
-
oursPath,
|
|
4603
|
-
basePath,
|
|
4604
|
-
theirsPath
|
|
4605
|
-
];
|
|
4606
|
-
let conflicts = 0;
|
|
4607
|
-
try {
|
|
4608
|
-
(0, import_child_process.execFileSync)("git", args2, { stdio: "ignore" });
|
|
4609
|
-
} catch (error3) {
|
|
4610
|
-
const { status } = error3;
|
|
4611
|
-
if (!status || status >= 255) throw error3;
|
|
4612
|
-
conflicts = status;
|
|
4613
|
-
}
|
|
4614
|
-
return { contents: toBytes((0, import_fs5.readFileSync)(oursPath)), conflicts };
|
|
4615
|
-
} finally {
|
|
4616
|
-
(0, import_fs5.rmSync)(dir, { recursive: true, force: true });
|
|
4617
3689
|
}
|
|
3690
|
+
return mayHaveDeclareType(node.getType(), node);
|
|
4618
3691
|
}
|
|
4619
|
-
|
|
4620
|
-
const
|
|
4621
|
-
|
|
4622
|
-
const url = `${BASE_URL}/${file}`;
|
|
4623
|
-
const response = await fetch(url);
|
|
4624
|
-
if (response.ok) {
|
|
4625
|
-
bases.set(file, new Uint8Array(await response.arrayBuffer()));
|
|
4626
|
-
} else if (response.status !== 404) {
|
|
4627
|
-
throw new Error(
|
|
4628
|
-
`GitHub answered ${response.status} ${response.statusText} for ${url}`
|
|
4629
|
-
);
|
|
4630
|
-
}
|
|
4631
|
-
}
|
|
4632
|
-
return bases;
|
|
4633
|
-
}
|
|
4634
|
-
function migrateInfrastructureToAssets(cwd, templateDir, readBase) {
|
|
4635
|
-
const infrastructure = import_path6.default.join(cwd, INFRASTRUCTURE_DIR);
|
|
4636
|
-
const templateAssets = import_path6.default.join(templateDir, ASSETS_DIR);
|
|
4637
|
-
const relativeTo = (dir) => (file) => file.slice(dir.length + 1);
|
|
4638
|
-
const localFiles = listFiles(cwd, INFRASTRUCTURE_DIR).map(relativeTo(INFRASTRUCTURE_DIR)).filter(isMigrated);
|
|
4639
|
-
const templateFiles = listFiles(templateDir, ASSETS_DIR).map(
|
|
4640
|
-
relativeTo(ASSETS_DIR)
|
|
4641
|
-
);
|
|
4642
|
-
const outcomes = {};
|
|
4643
|
-
const migrated = /* @__PURE__ */ new Set();
|
|
4644
|
-
for (const file of [.../* @__PURE__ */ new Set([...templateFiles, ...localFiles])].sort()) {
|
|
4645
|
-
const sourceFile = !localFiles.includes(file) && localFiles.includes(SOURCE_OF[file]) ? SOURCE_OF[file] : file;
|
|
4646
|
-
const ours = readIfExists(import_path6.default.join(infrastructure, sourceFile));
|
|
4647
|
-
const theirsPath = import_path6.default.join(templateAssets, file);
|
|
4648
|
-
const theirs = readIfExists(theirsPath);
|
|
4649
|
-
const base = ours && readBase(sourceFile);
|
|
4650
|
-
const target = import_path6.default.join(cwd, ASSETS_DIR, file);
|
|
4651
|
-
if (NOT_MOVED.includes(file)) {
|
|
4652
|
-
if (ours && base && sameBytes(ours, base)) {
|
|
4653
|
-
migrated.add(file);
|
|
4654
|
-
outcomes[file] = "dropped";
|
|
4655
|
-
} else if (ours) {
|
|
4656
|
-
outcomes[file] = "not-moved";
|
|
4657
|
-
}
|
|
4658
|
-
continue;
|
|
4659
|
-
}
|
|
4660
|
-
const ownsSource = ours !== void 0 && sourceFile === file;
|
|
4661
|
-
if ((0, import_fs5.existsSync)(target)) {
|
|
4662
|
-
if (ownsSource) {
|
|
4663
|
-
const same = sameBytes(toBytes((0, import_fs5.readFileSync)(target)), ours);
|
|
4664
|
-
if (same) {
|
|
4665
|
-
migrated.add(file);
|
|
4666
|
-
}
|
|
4667
|
-
outcomes[file] = same ? "exists" : "exists-differs";
|
|
4668
|
-
}
|
|
4669
|
-
continue;
|
|
4670
|
-
}
|
|
4671
|
-
if (ownsSource) {
|
|
4672
|
-
migrated.add(file);
|
|
4673
|
-
}
|
|
4674
|
-
let contents;
|
|
4675
|
-
let outcome;
|
|
4676
|
-
if (!ours) {
|
|
4677
|
-
contents = theirs;
|
|
4678
|
-
outcome = "copied";
|
|
4679
|
-
} else if (!theirs) {
|
|
4680
|
-
const unchanged = base && sameBytes(ours, base);
|
|
4681
|
-
contents = unchanged ? void 0 : ours;
|
|
4682
|
-
outcome = unchanged ? "dropped" : "kept";
|
|
4683
|
-
} else if (sameBytes(ours, theirs) || base && sameBytes(ours, base)) {
|
|
4684
|
-
contents = theirs;
|
|
4685
|
-
outcome = "copied";
|
|
4686
|
-
} else if (!base || sameBytes(base, theirs) || isBinary(ours)) {
|
|
4687
|
-
contents = ours;
|
|
4688
|
-
outcome = "kept";
|
|
4689
|
-
} else {
|
|
4690
|
-
const result = mergeFile(sourceFile, ours, base, theirs);
|
|
4691
|
-
contents = result.contents;
|
|
4692
|
-
outcome = result.conflicts > 0 ? "conflict" : "merged";
|
|
4693
|
-
}
|
|
4694
|
-
outcomes[file] = outcome;
|
|
4695
|
-
if (contents === void 0) {
|
|
4696
|
-
continue;
|
|
4697
|
-
}
|
|
4698
|
-
(0, import_fs5.mkdirSync)(import_path6.default.dirname(target), { recursive: true });
|
|
4699
|
-
(0, import_fs5.writeFileSync)(target, contents);
|
|
4700
|
-
const modeSource = ours && outcome === "kept" ? import_path6.default.join(infrastructure, sourceFile) : theirsPath;
|
|
4701
|
-
if ((0, import_fs5.existsSync)(modeSource)) {
|
|
4702
|
-
(0, import_fs5.chmodSync)(target, (0, import_fs5.statSync)(modeSource).mode & 511);
|
|
4703
|
-
}
|
|
4704
|
-
}
|
|
4705
|
-
return { outcomes, migrated: [...migrated].sort() };
|
|
3692
|
+
function isDeclareAction(literal) {
|
|
3693
|
+
const type = findProperty(literal, "type");
|
|
3694
|
+
return import_ts_morph.Node.isPropertyAssignment(type) && type.getInitializerOrThrow().getType().getLiteralValue() === DECLARE_ACTION_TYPE;
|
|
4706
3695
|
}
|
|
4707
|
-
function
|
|
4708
|
-
const
|
|
4709
|
-
|
|
4710
|
-
|
|
4711
|
-
|
|
4712
|
-
|
|
4713
|
-
if (!(0, import_fs5.existsSync)(dir)) {
|
|
4714
|
-
return true;
|
|
4715
|
-
}
|
|
4716
|
-
const empty = (0, import_fs5.readdirSync)(dir, { withFileTypes: true }).map(
|
|
4717
|
-
(entry) => entry.isDirectory() ? pruneEmpty(import_path6.default.join(dir, entry.name)) : false
|
|
4718
|
-
).every(Boolean);
|
|
4719
|
-
if (empty) {
|
|
4720
|
-
(0, import_fs5.rmdirSync)(dir);
|
|
4721
|
-
}
|
|
4722
|
-
return empty;
|
|
4723
|
-
};
|
|
4724
|
-
pruneEmpty(infrastructure);
|
|
4725
|
-
}
|
|
4726
|
-
var DESCRIPTIONS = {
|
|
4727
|
-
copied: "from the template",
|
|
4728
|
-
kept: "country's version",
|
|
4729
|
-
merged: "merged",
|
|
4730
|
-
conflict: "CONFLICT, resolve the markers by hand",
|
|
4731
|
-
dropped: "dropped, no longer used",
|
|
4732
|
-
exists: "already migrated",
|
|
4733
|
-
"exists-differs": "already exists with different contents; infrastructure/ copy kept for review",
|
|
4734
|
-
"not-moved": "changed locally but not moved: the chart runs its own on-deploy script, port your changes there"
|
|
4735
|
-
};
|
|
4736
|
-
async function main5(dockerSwarm = false) {
|
|
4737
|
-
const cwd = process.cwd();
|
|
4738
|
-
console.log("Moving infrastructure/ into assets/...\n");
|
|
4739
|
-
const templateDir = findTemplateDir();
|
|
4740
|
-
if ((0, import_fs5.existsSync)(import_path6.default.join(cwd, INFRASTRUCTURE_DIR))) {
|
|
4741
|
-
assertIsGitRepo();
|
|
4742
|
-
const needed = listFiles(cwd, INFRASTRUCTURE_DIR).map((file) => file.slice(INFRASTRUCTURE_DIR.length + 1)).filter(isMigrated);
|
|
4743
|
-
let bases;
|
|
4744
|
-
try {
|
|
4745
|
-
bases = await fetchBases(needed);
|
|
4746
|
-
} catch (error3) {
|
|
4747
|
-
console.warn(
|
|
4748
|
-
` \u26A0\uFE0F Could not read the v2.0 files to merge against (${error3.message}); infrastructure/ was not migrated. Re-run 'opencrvs upgrade' with network access.`
|
|
4749
|
-
);
|
|
4750
|
-
return;
|
|
4751
|
-
}
|
|
4752
|
-
const { outcomes, migrated } = migrateInfrastructureToAssets(
|
|
4753
|
-
cwd,
|
|
4754
|
-
templateDir,
|
|
4755
|
-
(file) => bases.get(file)
|
|
4756
|
-
);
|
|
4757
|
-
for (const [file, outcome] of Object.entries(outcomes)) {
|
|
4758
|
-
const needsReview = ["conflict", "not-moved", "exists-differs"].includes(
|
|
4759
|
-
outcome
|
|
4760
|
-
);
|
|
4761
|
-
const shown = outcome === "not-moved" ? INFRASTRUCTURE_DIR : ASSETS_DIR;
|
|
4762
|
-
const line2 = ` ${needsReview ? "\u26A0\uFE0F " : "\u2713"} ${shown}/${file}: ${DESCRIPTIONS[outcome]}`;
|
|
4763
|
-
if (needsReview) {
|
|
4764
|
-
console.warn(line2);
|
|
4765
|
-
} else {
|
|
4766
|
-
console.log(line2);
|
|
4767
|
-
}
|
|
4768
|
-
}
|
|
4769
|
-
if (dockerSwarm) {
|
|
4770
|
-
console.log(
|
|
4771
|
-
"\n infrastructure/ kept in place (--docker-swarm); assets/ now holds a copy."
|
|
4772
|
-
);
|
|
4773
|
-
} else {
|
|
4774
|
-
removeMigrated(cwd, migrated);
|
|
4775
|
-
}
|
|
4776
|
-
tryGit(["add", "-A", "--", ASSETS_DIR, INFRASTRUCTURE_DIR]);
|
|
4777
|
-
const conflicts = Object.keys(outcomes).filter(
|
|
4778
|
-
(file) => outcomes[file] === "conflict"
|
|
3696
|
+
function findDeclareAction(config) {
|
|
3697
|
+
const actions = findProperty(config, ACTIONS_PROPERTY_NAME);
|
|
3698
|
+
const actionsValue = import_ts_morph.Node.isPropertyAssignment(actions) ? actions.getInitializer() : void 0;
|
|
3699
|
+
if (!import_ts_morph.Node.isArrayLiteralExpression(actionsValue)) {
|
|
3700
|
+
console.warn(
|
|
3701
|
+
` [${location(config)}] Skipped: \`${ACTIONS_PROPERTY_NAME}\` is not an array literal. Move \`${DECLARATION_PROPERTY_NAME}\` onto the ${DECLARE_ACTION_TYPE} action by hand.`
|
|
4779
3702
|
);
|
|
4780
|
-
|
|
4781
|
-
tryGit(["restore", "--staged", "--", `${ASSETS_DIR}/${file}`]);
|
|
4782
|
-
}
|
|
4783
|
-
if (conflicts.length > 0) {
|
|
4784
|
-
console.warn(
|
|
4785
|
-
`
|
|
4786
|
-
\u26A0\uFE0F ${conflicts.length} file(s) need their conflicts resolved: ${conflicts.map((file) => `assets/${file}`).join(", ")}`
|
|
4787
|
-
);
|
|
4788
|
-
}
|
|
4789
|
-
if ((0, import_fs5.existsSync)(import_path6.default.join(cwd, INFRASTRUCTURE_DIR)) && !dockerSwarm) {
|
|
4790
|
-
console.warn(
|
|
4791
|
-
" \u26A0\uFE0F infrastructure/ still has files the Kubernetes deployment does not use. Review and delete them if they are no longer needed."
|
|
4792
|
-
);
|
|
4793
|
-
}
|
|
4794
|
-
} else {
|
|
4795
|
-
console.log(" infrastructure/ not found, nothing to move.");
|
|
3703
|
+
return void 0;
|
|
4796
3704
|
}
|
|
4797
|
-
const
|
|
4798
|
-
|
|
4799
|
-
|
|
4800
|
-
|
|
4801
|
-
|
|
4802
|
-
|
|
4803
|
-
tryGit(["add", "--", "Dockerfile.assets"]);
|
|
4804
|
-
console.log(" \u2713 Dockerfile.assets replaced with the template version");
|
|
3705
|
+
const candidates = actionsValue.getElements().filter(mayBeDeclareAction);
|
|
3706
|
+
if (candidates.length !== 1 || !import_ts_morph.Node.isObjectLiteralExpression(candidates[0])) {
|
|
3707
|
+
console.warn(
|
|
3708
|
+
` [${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.`
|
|
3709
|
+
);
|
|
3710
|
+
return void 0;
|
|
4805
3711
|
}
|
|
4806
|
-
|
|
4807
|
-
|
|
4808
|
-
|
|
4809
|
-
|
|
4810
|
-
|
|
4811
|
-
var METABASE_DIRS = ["infrastructure/metabase", "assets/metabase"];
|
|
4812
|
-
var APK_BLOCK = [
|
|
4813
|
-
"apk update",
|
|
4814
|
-
"apk upgrade",
|
|
4815
|
-
"apk add --no-cache gettext",
|
|
4816
|
-
"apk add --no-cache util-linux",
|
|
4817
|
-
"",
|
|
4818
|
-
""
|
|
4819
|
-
].join("\n");
|
|
4820
|
-
var SALT_LINE = "export OPENCRVS_METABASE_ADMIN_PASSWORD_SALT=$(uuidgen)\n";
|
|
4821
|
-
var FIXED_SALT_LINE = "export OPENCRVS_METABASE_ADMIN_PASSWORD_SALT=$(cat /proc/sys/kernel/random/uuid 2>/dev/null || uuidgen)\n\n";
|
|
4822
|
-
var FIXED_SALT_MARKER = "/proc/sys/kernel/random/uuid";
|
|
4823
|
-
var ENVSUBST_GUARD = [
|
|
4824
|
-
"if ! which envsubst >/dev/null; then",
|
|
4825
|
-
' echo "envsubst could not be found. Please install envsubst before continuing."',
|
|
4826
|
-
' echo "MacOS: brew install gettext && brew link --force gettext"',
|
|
4827
|
-
" exit 1",
|
|
4828
|
-
"fi",
|
|
4829
|
-
""
|
|
4830
|
-
].join("\n");
|
|
4831
|
-
var ENVSUBST_CALL = "envsubst < $environment_configuration_sql_file > $environment_configuration_sql_file.tmp\n";
|
|
4832
|
-
var FIXED_EXPANSION = [
|
|
4833
|
-
"",
|
|
4834
|
-
"# Expand $VAR / ${VAR} using bash's own heredoc expansion instead of envsubst,",
|
|
4835
|
-
"# because envsubst is not installed in the Metabase image",
|
|
4836
|
-
'eval "cat <<OPENCRVS_ENV_EOF',
|
|
4837
|
-
'$(cat "$environment_configuration_sql_file")',
|
|
4838
|
-
'OPENCRVS_ENV_EOF" > "$environment_configuration_sql_file.tmp"',
|
|
4839
|
-
""
|
|
4840
|
-
].join("\n");
|
|
4841
|
-
var FIXED_EXPANSION_MARKER = "OPENCRVS_ENV_EOF";
|
|
4842
|
-
function patchRunScript(source) {
|
|
4843
|
-
if (source.includes(FIXED_SALT_MARKER) && !source.includes(APK_BLOCK)) {
|
|
4844
|
-
return source;
|
|
4845
|
-
}
|
|
4846
|
-
if (!source.includes(APK_BLOCK) || !source.includes(SALT_LINE)) {
|
|
3712
|
+
const declareAction = candidates[0];
|
|
3713
|
+
if (findProperty(declareAction, DECLARATION_PROPERTY_NAME)) {
|
|
3714
|
+
console.warn(
|
|
3715
|
+
` [${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.`
|
|
3716
|
+
);
|
|
4847
3717
|
return void 0;
|
|
4848
3718
|
}
|
|
4849
|
-
return
|
|
3719
|
+
return declareAction;
|
|
4850
3720
|
}
|
|
4851
|
-
function
|
|
4852
|
-
|
|
4853
|
-
|
|
3721
|
+
function indentationOf(node) {
|
|
3722
|
+
const text = node.getSourceFile().getFullText();
|
|
3723
|
+
const lineStart = text.lastIndexOf("\n", node.getStart() - 1) + 1;
|
|
3724
|
+
return /^[ \t]*/.exec(text.slice(lineStart))?.[0] ?? "";
|
|
3725
|
+
}
|
|
3726
|
+
function restOfLine(text, position) {
|
|
3727
|
+
const lineEnd = text.indexOf("\n", position);
|
|
3728
|
+
return text.slice(position, lineEnd === -1 ? text.length : lineEnd);
|
|
3729
|
+
}
|
|
3730
|
+
function isOnlyComments(text) {
|
|
3731
|
+
return /^\s*(?:\/\/.*|\/\*.*?\*\/\s*)*$/.test(text);
|
|
3732
|
+
}
|
|
3733
|
+
function layoutOf(property) {
|
|
3734
|
+
const text = property.getSourceFile().getFullText();
|
|
3735
|
+
const next = property.getNextSibling();
|
|
3736
|
+
const hasComma = next?.getKind() === import_ts_morph.SyntaxKind.CommaToken;
|
|
3737
|
+
const end = next && hasComma ? next.getEnd() : property.getEnd();
|
|
3738
|
+
const trailing = restOfLine(text, end);
|
|
3739
|
+
const lineBreak = text.slice(property.getFullStart(), property.getStart()).indexOf("\n");
|
|
3740
|
+
if (lineBreak === -1 || !isOnlyComments(trailing)) {
|
|
3741
|
+
return {
|
|
3742
|
+
ownsLines: false,
|
|
3743
|
+
start: property.getStart(true),
|
|
3744
|
+
end,
|
|
3745
|
+
hasComma,
|
|
3746
|
+
trailingComment: ""
|
|
3747
|
+
};
|
|
4854
3748
|
}
|
|
4855
|
-
|
|
4856
|
-
|
|
3749
|
+
const firstLine = property.getFullStart() + lineBreak + 1;
|
|
3750
|
+
return {
|
|
3751
|
+
ownsLines: true,
|
|
3752
|
+
start: firstLine + (/^\s*/.exec(text.slice(firstLine))?.[0].length ?? 0),
|
|
3753
|
+
end,
|
|
3754
|
+
hasComma,
|
|
3755
|
+
trailingComment: trailing.trimEnd()
|
|
3756
|
+
};
|
|
3757
|
+
}
|
|
3758
|
+
function insertAt(position, text) {
|
|
3759
|
+
return { start: position, end: position, text };
|
|
3760
|
+
}
|
|
3761
|
+
function insertIntoDeclareAction(declareAction, property) {
|
|
3762
|
+
const anchor = declareAction.getProperty("label") ?? declareAction.getPropertyOrThrow("type");
|
|
3763
|
+
const text = property.getSourceFile().getFullText();
|
|
3764
|
+
const anchorLayout = layoutOf(anchor);
|
|
3765
|
+
const layout = layoutOf(property);
|
|
3766
|
+
const indent = indentationOf(anchor);
|
|
3767
|
+
const oldIndent = indentationOf(property);
|
|
3768
|
+
const reindent = (lines) => lines.split("\n").map(
|
|
3769
|
+
(line2, index) => index > 0 && line2.startsWith(oldIndent) ? indent + line2.slice(oldIndent.length) : line2
|
|
3770
|
+
).join("\n");
|
|
3771
|
+
if (anchorLayout.ownsLines) {
|
|
3772
|
+
const moved = reindent(text.slice(layout.start, property.getEnd()));
|
|
3773
|
+
const position = anchorLayout.end + restOfLine(text, anchorLayout.end).length;
|
|
3774
|
+
const insertion = `
|
|
3775
|
+
${indent}${moved}${anchorLayout.hasComma ? "," : ""}${layout.trailingComment}`;
|
|
3776
|
+
if (anchorLayout.hasComma) {
|
|
3777
|
+
return [insertAt(position, insertion)];
|
|
3778
|
+
}
|
|
3779
|
+
return position === anchor.getEnd() ? [insertAt(position, `,${insertion}`)] : [insertAt(anchor.getEnd(), ","), insertAt(position, insertion)];
|
|
3780
|
+
}
|
|
3781
|
+
const droppedComments = text.slice(layout.start, property.getStart(true)).trim() !== "" || layout.trailingComment !== "";
|
|
3782
|
+
if (droppedComments) {
|
|
3783
|
+
console.warn(
|
|
3784
|
+
` [${location(property)}] The comments next to \`${DECLARATION_PROPERTY_NAME}\` were not moved with it. Move them onto the ${DECLARE_ACTION_TYPE} action by hand.`
|
|
3785
|
+
);
|
|
4857
3786
|
}
|
|
4858
|
-
|
|
3787
|
+
const isMultiLine = declareAction.getText().includes("\n");
|
|
3788
|
+
const separator = isMultiLine ? `,
|
|
3789
|
+
${indent}` : ", ";
|
|
3790
|
+
return [
|
|
3791
|
+
insertAt(anchor.getEnd(), `${separator}${reindent(property.getText(true))}`)
|
|
3792
|
+
];
|
|
4859
3793
|
}
|
|
4860
|
-
function
|
|
4861
|
-
const
|
|
4862
|
-
|
|
4863
|
-
|
|
3794
|
+
function removeFromConfig(property) {
|
|
3795
|
+
const text = property.getSourceFile().getFullText();
|
|
3796
|
+
const layout = layoutOf(property);
|
|
3797
|
+
const previousComma = property.getPreviousSiblings().find((sibling) => !isOnlyComments(sibling.getText()))?.asKind(import_ts_morph.SyntaxKind.CommaToken);
|
|
3798
|
+
if (layout.ownsLines) {
|
|
3799
|
+
const lines = {
|
|
3800
|
+
start: text.lastIndexOf("\n", layout.start - 1),
|
|
3801
|
+
end: layout.end + restOfLine(text, layout.end).length,
|
|
3802
|
+
text: ""
|
|
3803
|
+
};
|
|
3804
|
+
return !layout.hasComma && previousComma ? [
|
|
3805
|
+
lines,
|
|
3806
|
+
{
|
|
3807
|
+
start: previousComma.getStart(),
|
|
3808
|
+
end: previousComma.getEnd(),
|
|
3809
|
+
text: ""
|
|
3810
|
+
}
|
|
3811
|
+
] : [lines];
|
|
3812
|
+
}
|
|
3813
|
+
if (layout.hasComma) {
|
|
3814
|
+
return [{ start: property.getFullStart(), end: layout.end, text: "" }];
|
|
3815
|
+
}
|
|
3816
|
+
return [
|
|
3817
|
+
{
|
|
3818
|
+
start: (previousComma ?? property).getStart(),
|
|
3819
|
+
end: property.getEnd(),
|
|
3820
|
+
text: ""
|
|
3821
|
+
}
|
|
3822
|
+
];
|
|
3823
|
+
}
|
|
3824
|
+
function findConfigLiteral(call) {
|
|
3825
|
+
const config = call.getArguments()[0];
|
|
3826
|
+
if (!config || import_ts_morph.Node.isObjectLiteralExpression(config)) {
|
|
3827
|
+
return config;
|
|
4864
3828
|
}
|
|
4865
|
-
|
|
4866
|
-
const patched = patch(source);
|
|
4867
|
-
if (patched === void 0) {
|
|
3829
|
+
if (config.getType().getProperty(DECLARATION_PROPERTY_NAME)) {
|
|
4868
3830
|
console.warn(
|
|
4869
|
-
`
|
|
3831
|
+
` [${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.`
|
|
4870
3832
|
);
|
|
4871
|
-
return;
|
|
4872
3833
|
}
|
|
4873
|
-
|
|
3834
|
+
return void 0;
|
|
3835
|
+
}
|
|
3836
|
+
function moveDeclarationToDeclareAction(sourceFile) {
|
|
3837
|
+
const configs = sourceFile.getDescendantsOfKind(import_ts_morph.SyntaxKind.CallExpression).filter(isToolkitDefineConfigCall).map(findConfigLiteral).filter(import_ts_morph.Node.isObjectLiteralExpression);
|
|
3838
|
+
const edits = [];
|
|
3839
|
+
let changes = 0;
|
|
3840
|
+
for (const config of configs) {
|
|
3841
|
+
const declaration = findProperty(config, DECLARATION_PROPERTY_NAME);
|
|
3842
|
+
if (!declaration) {
|
|
3843
|
+
continue;
|
|
3844
|
+
}
|
|
3845
|
+
const declareAction = findDeclareAction(config);
|
|
3846
|
+
if (!declareAction) {
|
|
3847
|
+
continue;
|
|
3848
|
+
}
|
|
3849
|
+
console.log(
|
|
3850
|
+
` [${location(declaration)}] Moved \`${declaration.getText()}\` onto the ${DECLARE_ACTION_TYPE} action`
|
|
3851
|
+
);
|
|
3852
|
+
edits.push(
|
|
3853
|
+
...insertIntoDeclareAction(declareAction, declaration),
|
|
3854
|
+
...removeFromConfig(declaration)
|
|
3855
|
+
);
|
|
3856
|
+
changes++;
|
|
3857
|
+
}
|
|
3858
|
+
if (changes === 0) {
|
|
3859
|
+
return 0;
|
|
3860
|
+
}
|
|
3861
|
+
const text = edits.sort((a, b) => b.start - a.start).reduce(
|
|
3862
|
+
(result, edit) => result.slice(0, edit.start) + edit.text + result.slice(edit.end),
|
|
3863
|
+
sourceFile.getFullText()
|
|
3864
|
+
);
|
|
3865
|
+
sourceFile.replaceWithText(text);
|
|
3866
|
+
return changes;
|
|
3867
|
+
}
|
|
3868
|
+
async function main2() {
|
|
3869
|
+
const srcDir = import_path2.default.join(process.cwd(), "src");
|
|
3870
|
+
console.log(`Scanning for top-level event declarations in: ${srcDir}
|
|
3871
|
+
`);
|
|
3872
|
+
const project = new import_ts_morph.Project({
|
|
3873
|
+
tsConfigFilePath: import_path2.default.resolve(srcDir, "../tsconfig.json"),
|
|
3874
|
+
skipAddingFilesFromTsConfig: false
|
|
3875
|
+
});
|
|
3876
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
3877
|
+
const fp = sf.getFilePath();
|
|
3878
|
+
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
3879
|
+
});
|
|
3880
|
+
console.log(`Found ${sourceFiles.length} source file(s) to analyse.
|
|
3881
|
+
`);
|
|
3882
|
+
let totalChanges = 0;
|
|
3883
|
+
const modifiedFiles = [];
|
|
3884
|
+
for (const sourceFile of sourceFiles) {
|
|
3885
|
+
const changes = moveDeclarationToDeclareAction(sourceFile);
|
|
3886
|
+
if (changes > 0) {
|
|
3887
|
+
totalChanges += changes;
|
|
3888
|
+
modifiedFiles.push(sourceFile);
|
|
3889
|
+
}
|
|
3890
|
+
}
|
|
3891
|
+
if (modifiedFiles.length === 0) {
|
|
3892
|
+
console.log("No top-level event declarations found. Nothing to do.");
|
|
4874
3893
|
return;
|
|
4875
3894
|
}
|
|
4876
|
-
|
|
4877
|
-
|
|
4878
|
-
|
|
4879
|
-
|
|
4880
|
-
|
|
4881
|
-
|
|
4882
|
-
patchFile((0, import_path7.join)(dir, "run.sh"), patchRunScript, "apk add gettext util-linux");
|
|
4883
|
-
patchFile(
|
|
4884
|
-
(0, import_path7.join)(dir, "update-database.sh"),
|
|
4885
|
-
patchUpdateDatabaseScript,
|
|
4886
|
-
"envsubst"
|
|
3895
|
+
console.log(`
|
|
3896
|
+
Saving ${modifiedFiles.length} modified file(s)...`);
|
|
3897
|
+
for (const sourceFile of modifiedFiles) {
|
|
3898
|
+
await sourceFile.save();
|
|
3899
|
+
console.log(
|
|
3900
|
+
` Saved: ${import_path2.default.relative(process.cwd(), sourceFile.getFilePath())}`
|
|
4887
3901
|
);
|
|
4888
3902
|
}
|
|
3903
|
+
console.log(
|
|
3904
|
+
`
|
|
3905
|
+
Done. Moved ${totalChanges} declaration(s) across ${modifiedFiles.length} file(s).`
|
|
3906
|
+
);
|
|
4889
3907
|
}
|
|
4890
3908
|
|
|
4891
|
-
// src/migrations/
|
|
4892
|
-
var
|
|
4893
|
-
var
|
|
4894
|
-
var
|
|
4895
|
-
var
|
|
4896
|
-
|
|
4897
|
-
|
|
4898
|
-
|
|
4899
|
-
|
|
4900
|
-
|
|
4901
|
-
|
|
4902
|
-
|
|
4903
|
-
|
|
4904
|
-
|
|
4905
|
-
var PACKAGE_JSON_FILE = "package.json";
|
|
4906
|
-
var TYPINGS_FILE = "typings/hapi-sentry.d.ts";
|
|
4907
|
-
var SENTRY_PLUGIN = "hapi-sentry";
|
|
4908
|
-
var skipped4 = [];
|
|
4909
|
-
function warnSkipped4(message) {
|
|
4910
|
-
skipped4.push(message);
|
|
4911
|
-
console.warn(` \u26A0\uFE0F ${message}`);
|
|
3909
|
+
// src/migrations/read-declaration-through-helper.ts
|
|
3910
|
+
var import_ts_morph2 = require("ts-morph");
|
|
3911
|
+
var import_path3 = __toESM(require("path"));
|
|
3912
|
+
var EVENT_CONFIG_TYPE_NAME = "EventConfig";
|
|
3913
|
+
var DECLARATION_PROPERTY_NAME2 = "declaration";
|
|
3914
|
+
var GET_DECLARATION_NAME = "getDeclaration";
|
|
3915
|
+
var TOOLKIT_EVENTS_MODULE = "@opencrvs/toolkit/events";
|
|
3916
|
+
function isToolkitEventConfig(type) {
|
|
3917
|
+
const nonNullableType = type.getNonNullableType();
|
|
3918
|
+
const symbol = nonNullableType.getAliasSymbol() ?? nonNullableType.getSymbol();
|
|
3919
|
+
if (symbol?.getName() !== EVENT_CONFIG_TYPE_NAME) {
|
|
3920
|
+
return false;
|
|
3921
|
+
}
|
|
3922
|
+
return symbol.getDeclarations().some((declaration) => declaration.getSourceFile().isDeclarationFile());
|
|
4912
3923
|
}
|
|
4913
|
-
function
|
|
4914
|
-
return
|
|
4915
|
-
(identifier) => identifier.getText() === name && !identifier.getFirstAncestorByKind(import_ts_morph4.SyntaxKind.ImportDeclaration)
|
|
4916
|
-
);
|
|
3924
|
+
function isDeclarationReadOnEventConfig(node) {
|
|
3925
|
+
return node.getName() === DECLARATION_PROPERTY_NAME2 && isToolkitEventConfig(node.getExpression().getType());
|
|
4917
3926
|
}
|
|
4918
|
-
function
|
|
4919
|
-
|
|
4920
|
-
|
|
4921
|
-
|
|
4922
|
-
|
|
4923
|
-
|
|
4924
|
-
if (names.length > 0 && names.every((name) => !isReferenced(sourceFile, name))) {
|
|
4925
|
-
importDeclaration.remove();
|
|
3927
|
+
function isAssignmentOperator(kind) {
|
|
3928
|
+
return kind >= import_ts_morph2.SyntaxKind.FirstAssignment && kind <= import_ts_morph2.SyntaxKind.LastAssignment;
|
|
3929
|
+
}
|
|
3930
|
+
function isWriteTarget(node) {
|
|
3931
|
+
const parent = node.getParent();
|
|
3932
|
+
if (import_ts_morph2.Node.isDeleteExpression(parent)) {
|
|
4926
3933
|
return true;
|
|
4927
3934
|
}
|
|
4928
|
-
return
|
|
3935
|
+
return import_ts_morph2.Node.isBinaryExpression(parent) && parent.getLeft() === node && isAssignmentOperator(parent.getOperatorToken().getKind());
|
|
4929
3936
|
}
|
|
4930
|
-
function
|
|
4931
|
-
const
|
|
4932
|
-
|
|
3937
|
+
function location2(node) {
|
|
3938
|
+
const relPath = import_path3.default.relative(
|
|
3939
|
+
process.cwd(),
|
|
3940
|
+
node.getSourceFile().getFilePath()
|
|
4933
3941
|
);
|
|
4934
|
-
|
|
4935
|
-
|
|
4936
|
-
|
|
4937
|
-
|
|
4938
|
-
|
|
4939
|
-
|
|
4940
|
-
|
|
4941
|
-
|
|
4942
|
-
}
|
|
4943
|
-
function removeSentryFromConfigs(project, cwd) {
|
|
4944
|
-
for (const file of CONFIG_FILES) {
|
|
4945
|
-
const sourceFile = project.addSourceFileAtPathIfExists(import_path8.default.join(cwd, file));
|
|
4946
|
-
if (!sourceFile) continue;
|
|
4947
|
-
const property = sourceFile.getDescendantsOfKind(import_ts_morph4.SyntaxKind.PropertyAssignment).find((assignment) => assignment.getName() === "SENTRY");
|
|
4948
|
-
if (!property) continue;
|
|
4949
|
-
const usedNames = new Set(
|
|
4950
|
-
property.getDescendantsOfKind(import_ts_morph4.SyntaxKind.Identifier).map((identifier) => identifier.getText())
|
|
3942
|
+
return `${relPath}:${node.getStartLineNumber()}`;
|
|
3943
|
+
}
|
|
3944
|
+
function warnDestructuredDeclarations(sourceFile) {
|
|
3945
|
+
for (const pattern of sourceFile.getDescendantsOfKind(
|
|
3946
|
+
import_ts_morph2.SyntaxKind.ObjectBindingPattern
|
|
3947
|
+
)) {
|
|
3948
|
+
const destructuresDeclaration = pattern.getElements().some(
|
|
3949
|
+
(element) => (element.getPropertyNameNode()?.getText() ?? element.getName()) === DECLARATION_PROPERTY_NAME2
|
|
4951
3950
|
);
|
|
4952
|
-
|
|
4953
|
-
|
|
4954
|
-
|
|
4955
|
-
|
|
4956
|
-
importDeclaration.getNamespaceImport()?.getText(),
|
|
4957
|
-
...importDeclaration.getNamedImports().map((named) => named.getName())
|
|
4958
|
-
].filter((name) => Boolean(name));
|
|
4959
|
-
if (imported.some((name) => usedNames.has(name))) {
|
|
4960
|
-
removeIfUnused(sourceFile, importDeclaration);
|
|
4961
|
-
}
|
|
3951
|
+
if (destructuresDeclaration && isToolkitEventConfig(pattern.getType())) {
|
|
3952
|
+
console.warn(
|
|
3953
|
+
` [${location2(pattern)}] Destructures \`${DECLARATION_PROPERTY_NAME2}\` from an EventConfig. Rewrite it to use \`${GET_DECLARATION_NAME}(config)\` by hand.`
|
|
3954
|
+
);
|
|
4962
3955
|
}
|
|
4963
|
-
console.log(` \u2713 ${file}: SENTRY`);
|
|
4964
3956
|
}
|
|
4965
3957
|
}
|
|
4966
|
-
function
|
|
4967
|
-
const
|
|
4968
|
-
|
|
4969
|
-
)
|
|
4970
|
-
|
|
4971
|
-
|
|
4972
|
-
|
|
4973
|
-
warnSkipped4(
|
|
4974
|
-
`Could not find the cleanEnv(...) config object in ${ENVIRONMENT_FILE2}; remove SENTRY_DSN by hand`
|
|
3958
|
+
function warnSpreadDeclarations(sourceFile) {
|
|
3959
|
+
for (const literal of sourceFile.getDescendantsOfKind(
|
|
3960
|
+
import_ts_morph2.SyntaxKind.ObjectLiteralExpression
|
|
3961
|
+
)) {
|
|
3962
|
+
const properties = literal.getProperties();
|
|
3963
|
+
const spreadsEventConfig = properties.some(
|
|
3964
|
+
(property) => import_ts_morph2.Node.isSpreadAssignment(property) && isToolkitEventConfig(property.getExpression().getType())
|
|
4975
3965
|
);
|
|
4976
|
-
|
|
4977
|
-
|
|
4978
|
-
const property = options.getProperty("SENTRY_DSN");
|
|
4979
|
-
if (!property) return;
|
|
4980
|
-
property.remove();
|
|
4981
|
-
console.log(` \u2713 ${ENVIRONMENT_FILE2}: SENTRY_DSN`);
|
|
4982
|
-
}
|
|
4983
|
-
function removeConstant(project, cwd) {
|
|
4984
|
-
const sourceFile = project.addSourceFileAtPathIfExists(
|
|
4985
|
-
import_path8.default.join(cwd, CONSTANTS_FILE)
|
|
4986
|
-
);
|
|
4987
|
-
if (!sourceFile) return;
|
|
4988
|
-
for (const statement of [...sourceFile.getVariableStatements()]) {
|
|
4989
|
-
const declarations = statement.getDeclarations();
|
|
4990
|
-
const matching = declarations.filter(
|
|
4991
|
-
(declaration) => declaration.getName() === "SENTRY_DSN" || /\benv\.SENTRY_DSN\b/.test(
|
|
4992
|
-
declaration.getInitializer()?.getText() ?? ""
|
|
4993
|
-
)
|
|
3966
|
+
const setsDeclaration = properties.some(
|
|
3967
|
+
(property) => (import_ts_morph2.Node.isPropertyAssignment(property) || import_ts_morph2.Node.isShorthandPropertyAssignment(property)) && property.getName() === DECLARATION_PROPERTY_NAME2
|
|
4994
3968
|
);
|
|
4995
|
-
if (
|
|
4996
|
-
|
|
4997
|
-
|
|
4998
|
-
|
|
4999
|
-
} else {
|
|
5000
|
-
for (const declaration of matching) {
|
|
5001
|
-
declaration.remove();
|
|
5002
|
-
}
|
|
3969
|
+
if (spreadsEventConfig && setsDeclaration) {
|
|
3970
|
+
console.warn(
|
|
3971
|
+
` [${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.`
|
|
3972
|
+
);
|
|
5003
3973
|
}
|
|
5004
|
-
console.log(` \u2713 ${CONSTANTS_FILE}: ${names.join(", ")}`);
|
|
5005
3974
|
}
|
|
5006
3975
|
}
|
|
5007
|
-
function
|
|
5008
|
-
|
|
5009
|
-
|
|
5010
|
-
);
|
|
5011
|
-
if (!sourceFile) return;
|
|
5012
|
-
const pluginImport = sourceFile.getImportDeclarations().find(
|
|
5013
|
-
(declaration) => declaration.getModuleSpecifierValue() === SENTRY_PLUGIN
|
|
3976
|
+
function findToolkitImport(sourceFile) {
|
|
3977
|
+
return sourceFile.getImportDeclaration(
|
|
3978
|
+
(declaration) => declaration.getModuleSpecifierValue() === TOOLKIT_EVENTS_MODULE && !declaration.isTypeOnly() && !declaration.getNamespaceImport()
|
|
5014
3979
|
);
|
|
5015
|
-
|
|
5016
|
-
|
|
5017
|
-
|
|
5018
|
-
)
|
|
5019
|
-
|
|
5020
|
-
registration.remove();
|
|
5021
|
-
console.log(` \u2713 ${INDEX_FILE2}: hapi-sentry plugin registration`);
|
|
5022
|
-
} else if (sourceFile.getText().includes(SENTRY_PLUGIN)) {
|
|
5023
|
-
warnSkipped4(
|
|
5024
|
-
`Could not find the hapi-sentry plugin registration in ${INDEX_FILE2}; remove it by hand`
|
|
5025
|
-
);
|
|
5026
|
-
}
|
|
5027
|
-
const scopeExtension = sourceFile.getDescendantsOfKind(import_ts_morph4.SyntaxKind.ExpressionStatement).find(
|
|
5028
|
-
(statement) => statement.getText().includes("sentryScope") && statement.getText().startsWith("server.ext")
|
|
5029
|
-
);
|
|
5030
|
-
if (scopeExtension) {
|
|
5031
|
-
scopeExtension.remove();
|
|
5032
|
-
console.log(` \u2713 ${INDEX_FILE2}: onRequest Sentry scope extension`);
|
|
5033
|
-
} else if (sourceFile.getText().includes("sentryScope")) {
|
|
5034
|
-
warnSkipped4(
|
|
5035
|
-
`Found 'sentryScope' in ${INDEX_FILE2} outside a server.ext(...) call; remove it by hand`
|
|
5036
|
-
);
|
|
5037
|
-
}
|
|
5038
|
-
if (pluginImport && removeIfUnused(sourceFile, pluginImport)) {
|
|
5039
|
-
console.log(` \u2713 ${INDEX_FILE2}: import '${SENTRY_PLUGIN}'`);
|
|
3980
|
+
}
|
|
3981
|
+
function findGetDeclarationName(sourceFile) {
|
|
3982
|
+
const imported = findToolkitImport(sourceFile)?.getNamedImports().find((namedImport) => namedImport.getName() === GET_DECLARATION_NAME);
|
|
3983
|
+
if (imported) {
|
|
3984
|
+
return imported.getAliasNode()?.getText() ?? GET_DECLARATION_NAME;
|
|
5040
3985
|
}
|
|
5041
|
-
if (
|
|
5042
|
-
|
|
5043
|
-
const specifier = declaration.getModuleSpecifierValue();
|
|
5044
|
-
if (removeNamedImport(sourceFile, specifier, "SENTRY_DSN")) {
|
|
5045
|
-
console.log(` \u2713 ${INDEX_FILE2}: import SENTRY_DSN from '${specifier}'`);
|
|
5046
|
-
break;
|
|
5047
|
-
}
|
|
5048
|
-
}
|
|
3986
|
+
if (sourceFile.getLocal(GET_DECLARATION_NAME)) {
|
|
3987
|
+
return void 0;
|
|
5049
3988
|
}
|
|
3989
|
+
return GET_DECLARATION_NAME;
|
|
5050
3990
|
}
|
|
5051
|
-
function
|
|
5052
|
-
const
|
|
5053
|
-
|
|
5054
|
-
|
|
5055
|
-
|
|
5056
|
-
|
|
5057
|
-
|
|
5058
|
-
|
|
5059
|
-
console.log(` \u2713 ${UTILS_FILE}: IApplicationConfig.SENTRY`);
|
|
5060
|
-
}
|
|
5061
|
-
function isSentryPackage(name) {
|
|
5062
|
-
return name === SENTRY_PLUGIN || name.startsWith("@sentry/");
|
|
5063
|
-
}
|
|
5064
|
-
function removeDependencies(cwd) {
|
|
5065
|
-
const packageJsonPath = import_path8.default.join(cwd, PACKAGE_JSON_FILE);
|
|
5066
|
-
if (!(0, import_fs7.existsSync)(packageJsonPath)) return;
|
|
5067
|
-
const raw = (0, import_fs7.readFileSync)(packageJsonPath, "utf8");
|
|
5068
|
-
let parsed;
|
|
5069
|
-
try {
|
|
5070
|
-
parsed = JSON.parse(raw);
|
|
5071
|
-
} catch (error3) {
|
|
5072
|
-
warnSkipped4(
|
|
5073
|
-
`${PACKAGE_JSON_FILE} could not be parsed (${error3.message}); remove the Sentry dependencies by hand`
|
|
3991
|
+
function addGetDeclarationImport(sourceFile) {
|
|
3992
|
+
const toolkitImport = findToolkitImport(sourceFile);
|
|
3993
|
+
if (!toolkitImport) {
|
|
3994
|
+
const imports = sourceFile.getImportDeclarations();
|
|
3995
|
+
const lastImport = imports[imports.length - 1];
|
|
3996
|
+
sourceFile.insertStatements(
|
|
3997
|
+
lastImport ? lastImport.getChildIndex() + 1 : 0,
|
|
3998
|
+
`import { ${GET_DECLARATION_NAME} } from '${TOOLKIT_EVENTS_MODULE}'`
|
|
5074
3999
|
);
|
|
5075
4000
|
return;
|
|
5076
4001
|
}
|
|
5077
|
-
const
|
|
5078
|
-
|
|
5079
|
-
|
|
5080
|
-
if (!dependencies) continue;
|
|
5081
|
-
for (const name of Object.keys(dependencies)) {
|
|
5082
|
-
if (isSentryPackage(name)) {
|
|
5083
|
-
delete dependencies[name];
|
|
5084
|
-
removed.push(name);
|
|
5085
|
-
}
|
|
5086
|
-
}
|
|
4002
|
+
const alreadyImported = toolkitImport.getNamedImports().some((namedImport) => namedImport.getName() === GET_DECLARATION_NAME);
|
|
4003
|
+
if (alreadyImported) {
|
|
4004
|
+
return;
|
|
5087
4005
|
}
|
|
5088
|
-
|
|
5089
|
-
|
|
5090
|
-
|
|
5091
|
-
packageJsonPath,
|
|
5092
|
-
`${JSON.stringify(parsed, null, 2)}${trailingNewline}`
|
|
5093
|
-
);
|
|
5094
|
-
console.log(` \u2713 ${PACKAGE_JSON_FILE}: ${removed.join(", ")}`);
|
|
5095
|
-
}
|
|
5096
|
-
function removeTypings(cwd) {
|
|
5097
|
-
const typingsPath = import_path8.default.join(cwd, TYPINGS_FILE);
|
|
5098
|
-
if (!(0, import_fs7.existsSync)(typingsPath)) return;
|
|
5099
|
-
const declarations = (0, import_fs7.readFileSync)(typingsPath, "utf8").replace(/\/\*[\s\S]*?\*\//g, "").replace(/^\s*\/\/.*$/gm, "").trim();
|
|
5100
|
-
if (!/^declare module ['"]hapi-sentry['"];?$/.test(declarations)) {
|
|
5101
|
-
warnSkipped4(
|
|
5102
|
-
`${TYPINGS_FILE} declares more than the 'hapi-sentry' module; remove the declaration by hand`
|
|
5103
|
-
);
|
|
4006
|
+
const namedImports = toolkitImport.getNamedImports();
|
|
4007
|
+
if (toolkitImport.getDefaultImport() || namedImports.length === 0) {
|
|
4008
|
+
toolkitImport.addNamedImport(GET_DECLARATION_NAME);
|
|
5104
4009
|
return;
|
|
5105
4010
|
}
|
|
5106
|
-
|
|
5107
|
-
|
|
4011
|
+
const names = [
|
|
4012
|
+
...namedImports.map((namedImport) => namedImport.getText()),
|
|
4013
|
+
GET_DECLARATION_NAME
|
|
4014
|
+
];
|
|
4015
|
+
const specifiers = toolkitImport.getText().includes("\n") ? `{
|
|
4016
|
+
${names.join(",\n ")}
|
|
4017
|
+
}` : `{ ${names.join(", ")} }`;
|
|
4018
|
+
toolkitImport.replaceWithText(
|
|
4019
|
+
`import ${specifiers} from '${TOOLKIT_EVENTS_MODULE}'`
|
|
4020
|
+
);
|
|
5108
4021
|
}
|
|
5109
|
-
|
|
5110
|
-
|
|
5111
|
-
|
|
5112
|
-
const
|
|
5113
|
-
|
|
5114
|
-
|
|
5115
|
-
|
|
5116
|
-
|
|
5117
|
-
|
|
4022
|
+
function rewriteDeclarationReads(sourceFile) {
|
|
4023
|
+
warnDestructuredDeclarations(sourceFile);
|
|
4024
|
+
warnSpreadDeclarations(sourceFile);
|
|
4025
|
+
const reads = sourceFile.getDescendantsOfKind(import_ts_morph2.SyntaxKind.PropertyAccessExpression).filter(isDeclarationReadOnEventConfig).filter((node) => {
|
|
4026
|
+
if (node.hasQuestionDotToken()) {
|
|
4027
|
+
console.warn(
|
|
4028
|
+
` [${location2(node)}] Skipped optional chain \`${node.getText()}\`. Rewrite it to use \`${GET_DECLARATION_NAME}()\` by hand.`
|
|
4029
|
+
);
|
|
4030
|
+
return false;
|
|
5118
4031
|
}
|
|
5119
|
-
|
|
5120
|
-
|
|
5121
|
-
|
|
5122
|
-
|
|
5123
|
-
|
|
5124
|
-
removeApplicationConfigField(project, cwd);
|
|
5125
|
-
await project.save();
|
|
5126
|
-
removeDependencies(cwd);
|
|
5127
|
-
removeTypings(cwd);
|
|
5128
|
-
if (skipped4.length > 0) {
|
|
5129
|
-
console.warn(
|
|
5130
|
-
`
|
|
5131
|
-
\u26A0\uFE0F ${skipped4.length} Sentry removal step(s) were skipped. Handle the following by hand:`
|
|
5132
|
-
);
|
|
5133
|
-
for (const message of skipped4) {
|
|
5134
|
-
console.warn(` - ${message}`);
|
|
4032
|
+
if (isWriteTarget(node)) {
|
|
4033
|
+
console.warn(
|
|
4034
|
+
` [${location2(node)}] Skipped write to \`${node.getText()}\`. Set \`${DECLARATION_PROPERTY_NAME2}\` on the DECLARE action instead.`
|
|
4035
|
+
);
|
|
4036
|
+
return false;
|
|
5135
4037
|
}
|
|
4038
|
+
return true;
|
|
4039
|
+
}).sort((a, b) => b.getStart() - a.getStart());
|
|
4040
|
+
if (reads.length === 0) {
|
|
4041
|
+
return 0;
|
|
5136
4042
|
}
|
|
5137
|
-
|
|
5138
|
-
|
|
5139
|
-
|
|
5140
|
-
|
|
5141
|
-
var import_path9 = __toESM(require("path"));
|
|
5142
|
-
var PATH_PREFIX_RENAMES = {
|
|
5143
|
-
"/triggers/user/": "/trigger/user/",
|
|
5144
|
-
"/triggers/system/": "/trigger/system/"
|
|
5145
|
-
};
|
|
5146
|
-
var STALE_PREFIX = "/triggers/";
|
|
5147
|
-
var METHOD_PROPERTY_NAME = "method";
|
|
5148
|
-
var PATH_PROPERTY_NAME = "path";
|
|
5149
|
-
var HTTP_VERBS = /* @__PURE__ */ new Set([
|
|
5150
|
-
"GET",
|
|
5151
|
-
"POST",
|
|
5152
|
-
"PUT",
|
|
5153
|
-
"PATCH",
|
|
5154
|
-
"DELETE",
|
|
5155
|
-
"OPTIONS",
|
|
5156
|
-
"HEAD",
|
|
5157
|
-
"*"
|
|
5158
|
-
]);
|
|
5159
|
-
function isRouteConfig(obj) {
|
|
5160
|
-
const methodProp = obj.getProperty(METHOD_PROPERTY_NAME);
|
|
5161
|
-
if (!methodProp || !import_ts_morph5.Node.isPropertyAssignment(methodProp)) return false;
|
|
5162
|
-
const methodInit = methodProp.getInitializer();
|
|
5163
|
-
if (!methodInit) return false;
|
|
5164
|
-
if (import_ts_morph5.Node.isStringLiteral(methodInit)) {
|
|
5165
|
-
if (!HTTP_VERBS.has(methodInit.getLiteralValue().toUpperCase()))
|
|
5166
|
-
return false;
|
|
5167
|
-
} else if (import_ts_morph5.Node.isArrayLiteralExpression(methodInit)) {
|
|
5168
|
-
const allVerbs = methodInit.getElements().every(
|
|
5169
|
-
(el) => import_ts_morph5.Node.isStringLiteral(el) && HTTP_VERBS.has(el.getLiteralValue().toUpperCase())
|
|
4043
|
+
const getDeclarationName = findGetDeclarationName(sourceFile);
|
|
4044
|
+
if (!getDeclarationName) {
|
|
4045
|
+
console.warn(
|
|
4046
|
+
` [${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.`
|
|
5170
4047
|
);
|
|
5171
|
-
|
|
5172
|
-
} else {
|
|
5173
|
-
return false;
|
|
5174
|
-
}
|
|
5175
|
-
const pathProp = obj.getProperty(PATH_PROPERTY_NAME);
|
|
5176
|
-
if (!pathProp || !import_ts_morph5.Node.isPropertyAssignment(pathProp)) return false;
|
|
5177
|
-
const pathInit = pathProp.getInitializer();
|
|
5178
|
-
return !!pathInit && import_ts_morph5.Node.isStringLiteral(pathInit);
|
|
5179
|
-
}
|
|
5180
|
-
function renameRoutePath(obj) {
|
|
5181
|
-
const pathProp = obj.getProperty(PATH_PROPERTY_NAME);
|
|
5182
|
-
if (!pathProp || !import_ts_morph5.Node.isPropertyAssignment(pathProp)) return null;
|
|
5183
|
-
const pathInit = pathProp.getInitializer();
|
|
5184
|
-
if (!pathInit || !import_ts_morph5.Node.isStringLiteral(pathInit)) return null;
|
|
5185
|
-
const oldPath = pathInit.getLiteralValue();
|
|
5186
|
-
const match = Object.entries(PATH_PREFIX_RENAMES).find(
|
|
5187
|
-
([from2]) => oldPath.startsWith(from2)
|
|
5188
|
-
);
|
|
5189
|
-
if (!match) return null;
|
|
5190
|
-
const [from, to] = match;
|
|
5191
|
-
const newPath = to + oldPath.slice(from.length);
|
|
5192
|
-
pathInit.replaceWithText(`'${newPath}'`);
|
|
5193
|
-
return newPath;
|
|
5194
|
-
}
|
|
5195
|
-
function processFile2(filePath, project) {
|
|
5196
|
-
const sourceFile = project.getSourceFile(filePath);
|
|
5197
|
-
if (!sourceFile) return 0;
|
|
5198
|
-
let renamedCount = 0;
|
|
5199
|
-
const relPath = import_path9.default.relative(process.cwd(), filePath);
|
|
5200
|
-
const candidates = sourceFile.getDescendantsOfKind(
|
|
5201
|
-
import_ts_morph5.SyntaxKind.ObjectLiteralExpression
|
|
5202
|
-
);
|
|
5203
|
-
for (const obj of candidates) {
|
|
5204
|
-
if (!isRouteConfig(obj)) continue;
|
|
5205
|
-
const newPath = renameRoutePath(obj);
|
|
5206
|
-
if (newPath) {
|
|
5207
|
-
renamedCount++;
|
|
5208
|
-
console.log(` [${relPath}] Renamed route path \u2192 '${newPath}'`);
|
|
5209
|
-
}
|
|
4048
|
+
return 0;
|
|
5210
4049
|
}
|
|
5211
|
-
|
|
5212
|
-
|
|
5213
|
-
|
|
5214
|
-
|
|
5215
|
-
|
|
5216
|
-
|
|
5217
|
-
|
|
5218
|
-
lines.forEach((line2, index) => {
|
|
5219
|
-
if (line2.includes(STALE_PREFIX)) {
|
|
5220
|
-
stale.push(` ${relPath}:${index + 1}: ${line2.trim()}`);
|
|
5221
|
-
}
|
|
5222
|
-
});
|
|
4050
|
+
for (const read of reads) {
|
|
4051
|
+
console.log(
|
|
4052
|
+
` [${location2(read)}] ${read.getText()} -> ${getDeclarationName}(${read.getExpression().getText()})`
|
|
4053
|
+
);
|
|
4054
|
+
read.replaceWithText(
|
|
4055
|
+
`${getDeclarationName}(${read.getExpression().getText()})`
|
|
4056
|
+
);
|
|
5223
4057
|
}
|
|
5224
|
-
|
|
5225
|
-
|
|
5226
|
-
`
|
|
5227
|
-
WARNING: ${stale.length} remaining '${STALE_PREFIX}' reference(s) need to be renamed by hand:`
|
|
5228
|
-
);
|
|
5229
|
-
console.log(stale.join("\n"));
|
|
4058
|
+
addGetDeclarationImport(sourceFile);
|
|
4059
|
+
return reads.length;
|
|
5230
4060
|
}
|
|
5231
|
-
async function
|
|
5232
|
-
const srcDir =
|
|
5233
|
-
console.log(`Scanning for
|
|
4061
|
+
async function main3() {
|
|
4062
|
+
const srcDir = import_path3.default.join(process.cwd(), "src");
|
|
4063
|
+
console.log(`Scanning for EventConfig declaration reads in: ${srcDir}
|
|
5234
4064
|
`);
|
|
5235
|
-
|
|
5236
|
-
|
|
5237
|
-
console.log(` '${from}*' \u2192 '${to}*'`);
|
|
5238
|
-
}
|
|
5239
|
-
console.log();
|
|
5240
|
-
const project = new import_ts_morph5.Project({
|
|
5241
|
-
tsConfigFilePath: import_path9.default.resolve(srcDir, "../tsconfig.json"),
|
|
4065
|
+
const project = new import_ts_morph2.Project({
|
|
4066
|
+
tsConfigFilePath: import_path3.default.resolve(srcDir, "../tsconfig.json"),
|
|
5242
4067
|
skipAddingFilesFromTsConfig: false
|
|
5243
4068
|
});
|
|
5244
4069
|
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
@@ -5247,152 +4072,210 @@ async function main8() {
|
|
|
5247
4072
|
});
|
|
5248
4073
|
console.log(`Found ${sourceFiles.length} source file(s) to analyse.
|
|
5249
4074
|
`);
|
|
5250
|
-
let
|
|
4075
|
+
let totalChanges = 0;
|
|
5251
4076
|
const modifiedFiles = [];
|
|
5252
4077
|
for (const sourceFile of sourceFiles) {
|
|
5253
|
-
const
|
|
5254
|
-
|
|
5255
|
-
|
|
5256
|
-
|
|
5257
|
-
modifiedFiles.push(filePath);
|
|
4078
|
+
const changes = rewriteDeclarationReads(sourceFile);
|
|
4079
|
+
if (changes > 0) {
|
|
4080
|
+
totalChanges += changes;
|
|
4081
|
+
modifiedFiles.push(sourceFile);
|
|
5258
4082
|
}
|
|
5259
4083
|
}
|
|
5260
4084
|
if (modifiedFiles.length === 0) {
|
|
5261
|
-
console.log("No
|
|
5262
|
-
|
|
5263
|
-
|
|
4085
|
+
console.log("No EventConfig declaration reads found. Nothing to do.");
|
|
4086
|
+
return;
|
|
4087
|
+
}
|
|
4088
|
+
console.log(`
|
|
5264
4089
|
Saving ${modifiedFiles.length} modified file(s)...`);
|
|
5265
|
-
|
|
5266
|
-
|
|
5267
|
-
|
|
5268
|
-
|
|
5269
|
-
|
|
5270
|
-
console.log(`
|
|
5271
|
-
Done. Renamed ${totalRenamed} route path(s).`);
|
|
4090
|
+
for (const sourceFile of modifiedFiles) {
|
|
4091
|
+
await sourceFile.save();
|
|
4092
|
+
console.log(
|
|
4093
|
+
` Saved: ${import_path3.default.relative(process.cwd(), sourceFile.getFilePath())}`
|
|
4094
|
+
);
|
|
5272
4095
|
}
|
|
5273
|
-
|
|
4096
|
+
console.log(
|
|
4097
|
+
`
|
|
4098
|
+
Done. Rewrote ${totalChanges} declaration read(s) across ${modifiedFiles.length} file(s).`
|
|
4099
|
+
);
|
|
5274
4100
|
}
|
|
5275
4101
|
|
|
5276
|
-
// src/migrations/
|
|
5277
|
-
var
|
|
5278
|
-
var
|
|
5279
|
-
|
|
5280
|
-
|
|
5281
|
-
var
|
|
5282
|
-
|
|
5283
|
-
|
|
5284
|
-
|
|
5285
|
-
|
|
5286
|
-
|
|
5287
|
-
}
|
|
5288
|
-
(0, import_fs8.mkdirSync)(import_path10.default.dirname(target), { recursive: true });
|
|
5289
|
-
(0, import_fs8.writeFileSync)(target, contents);
|
|
5290
|
-
if (mode !== void 0) {
|
|
5291
|
-
(0, import_fs8.chmodSync)(target, mode & 511);
|
|
5292
|
-
}
|
|
5293
|
-
return existed ? "updated" : "created";
|
|
5294
|
-
}
|
|
5295
|
-
function report(relativePath, change) {
|
|
5296
|
-
if (change !== "unchanged") {
|
|
5297
|
-
console.log(` \u2713 ${change} ${relativePath}`);
|
|
5298
|
-
}
|
|
5299
|
-
}
|
|
5300
|
-
function renderTiltfile(template, existing) {
|
|
5301
|
-
const imageName = existing?.match(IMAGE_NAME_PATTERN)?.[2];
|
|
5302
|
-
if (!imageName) {
|
|
5303
|
-
return template;
|
|
5304
|
-
}
|
|
5305
|
-
return template.replace(
|
|
5306
|
-
IMAGE_NAME_PATTERN,
|
|
5307
|
-
(_line, quote) => `countryconfig_image_name=${quote}${imageName}${quote}`
|
|
5308
|
-
);
|
|
4102
|
+
// src/migrations/persistent/update-toolkit-dependency.ts
|
|
4103
|
+
var import_fs3 = __toESM(require("fs"));
|
|
4104
|
+
var import_path5 = __toESM(require("path"));
|
|
4105
|
+
|
|
4106
|
+
// src/migrations/persistent/check-upgrade-path.ts
|
|
4107
|
+
var import_fs2 = __toESM(require("fs"));
|
|
4108
|
+
var import_path4 = __toESM(require("path"));
|
|
4109
|
+
var TOOLKIT_PACKAGE_NAME = "@opencrvs/toolkit";
|
|
4110
|
+
function findMajorMinor(version) {
|
|
4111
|
+
const match = /(\d+)\.(\d+)/.exec(version);
|
|
4112
|
+
return match ? { major: Number(match[1]), minor: Number(match[2]) } : void 0;
|
|
5309
4113
|
}
|
|
5310
|
-
function
|
|
5311
|
-
|
|
5312
|
-
|
|
5313
|
-
|
|
5314
|
-
|
|
5315
|
-
|
|
5316
|
-
|
|
5317
|
-
return `${contents}${separator}${line2}
|
|
5318
|
-
`;
|
|
5319
|
-
}
|
|
5320
|
-
function ensureIgnored(cwd, file, line2) {
|
|
5321
|
-
const target = import_path10.default.join(cwd, file);
|
|
5322
|
-
const contents = (0, import_fs8.existsSync)(target) ? (0, import_fs8.readFileSync)(target, "utf8") : "";
|
|
5323
|
-
report(file, writeIfChanged(cwd, file, withIgnoreEntry(contents, line2)));
|
|
5324
|
-
}
|
|
5325
|
-
function upgradeTilt(cwd, templateDir) {
|
|
5326
|
-
const tiltfilePath = import_path10.default.join(cwd, "Tiltfile");
|
|
5327
|
-
const existingTiltfile = (0, import_fs8.existsSync)(tiltfilePath) ? (0, import_fs8.readFileSync)(tiltfilePath, "utf8") : void 0;
|
|
5328
|
-
report(
|
|
5329
|
-
"Tiltfile",
|
|
5330
|
-
writeIfChanged(
|
|
5331
|
-
cwd,
|
|
5332
|
-
"Tiltfile",
|
|
5333
|
-
renderTiltfile(
|
|
5334
|
-
(0, import_fs8.readFileSync)(import_path10.default.join(templateDir, "Tiltfile"), "utf8"),
|
|
5335
|
-
existingTiltfile
|
|
5336
|
-
)
|
|
5337
|
-
)
|
|
5338
|
-
);
|
|
5339
|
-
const templateFiles = listFiles(templateDir, "tilt");
|
|
5340
|
-
for (const file of templateFiles) {
|
|
5341
|
-
const source = import_path10.default.join(templateDir, file);
|
|
5342
|
-
const countryOwned = file.startsWith(COUNTRY_OWNED_DIR);
|
|
5343
|
-
if (countryOwned && (0, import_fs8.existsSync)(import_path10.default.join(cwd, file))) {
|
|
5344
|
-
continue;
|
|
5345
|
-
}
|
|
5346
|
-
report(
|
|
5347
|
-
file,
|
|
5348
|
-
writeIfChanged(
|
|
5349
|
-
cwd,
|
|
5350
|
-
file,
|
|
5351
|
-
(0, import_fs8.readFileSync)(source, "utf8"),
|
|
5352
|
-
(0, import_fs8.statSync)(source).mode
|
|
5353
|
-
)
|
|
4114
|
+
function format({ major, minor }) {
|
|
4115
|
+
return `${major}.${minor}`;
|
|
4116
|
+
}
|
|
4117
|
+
function findCountryConfigToolkitVersion(cwd) {
|
|
4118
|
+
try {
|
|
4119
|
+
const packageJson = JSON.parse(
|
|
4120
|
+
import_fs2.default.readFileSync(import_path4.default.join(cwd, "package.json"), "utf-8")
|
|
5354
4121
|
);
|
|
4122
|
+
return packageJson.dependencies?.[TOOLKIT_PACKAGE_NAME] ?? packageJson.devDependencies?.[TOOLKIT_PACKAGE_NAME];
|
|
4123
|
+
} catch {
|
|
4124
|
+
return void 0;
|
|
4125
|
+
}
|
|
4126
|
+
}
|
|
4127
|
+
function checkUpgradePath(countryConfigToolkitVersion, toolkitVersion) {
|
|
4128
|
+
const target = findMajorMinor(toolkitVersion);
|
|
4129
|
+
const current = countryConfigToolkitVersion ? findMajorMinor(countryConfigToolkitVersion) : void 0;
|
|
4130
|
+
if (!target || !current) {
|
|
4131
|
+
return {
|
|
4132
|
+
status: "unknown",
|
|
4133
|
+
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.`
|
|
4134
|
+
};
|
|
4135
|
+
}
|
|
4136
|
+
const isSameVersion = current.major === target.major && current.minor === target.minor;
|
|
4137
|
+
const isPreviousMinor = current.major === target.major && current.minor === target.minor - 1;
|
|
4138
|
+
const isPreviousMajor = target.minor === 0 && current.major === target.major - 1;
|
|
4139
|
+
if (isSameVersion || isPreviousMinor || isPreviousMajor) {
|
|
4140
|
+
return { status: "ok" };
|
|
5355
4141
|
}
|
|
5356
|
-
const
|
|
5357
|
-
|
|
4142
|
+
const isNewer = current.major > target.major || current.major === target.major && current.minor > target.minor;
|
|
4143
|
+
if (isNewer) {
|
|
4144
|
+
return {
|
|
4145
|
+
status: "blocked",
|
|
4146
|
+
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.`
|
|
4147
|
+
};
|
|
4148
|
+
}
|
|
4149
|
+
const upgradesFrom = target.minor > 0 ? format({ major: target.major, minor: target.minor - 1 }) : `the last ${target.major - 1}.x`;
|
|
4150
|
+
const nextStep = current.major === target.major ? `: run \`npx ${TOOLKIT_PACKAGE_NAME}@${format({ major: current.major, minor: current.minor + 1 })} upgrade\` first` : "";
|
|
4151
|
+
return {
|
|
4152
|
+
status: "blocked",
|
|
4153
|
+
message: `The country config is on ${format(current)}, but toolkit ${toolkitVersion} only upgrades from ${upgradesFrom}. Upgrade one minor version at a time${nextStep}.`
|
|
4154
|
+
};
|
|
4155
|
+
}
|
|
4156
|
+
|
|
4157
|
+
// src/migrations/persistent/update-toolkit-dependency.ts
|
|
4158
|
+
var DEPENDENCY_PATTERN = new RegExp(
|
|
4159
|
+
`("${TOOLKIT_PACKAGE_NAME}"\\s*:\\s*")([^"]*)(")`,
|
|
4160
|
+
"g"
|
|
4161
|
+
);
|
|
4162
|
+
function updateToolkitDependency(packageJson, toolkitVersion) {
|
|
4163
|
+
const updated = packageJson.replace(
|
|
4164
|
+
DEPENDENCY_PATTERN,
|
|
4165
|
+
(match, before, version, after) => {
|
|
4166
|
+
if (!findMajorMinor(version)) {
|
|
4167
|
+
return match;
|
|
4168
|
+
}
|
|
4169
|
+
const range = /^[\^~]?/.exec(version)?.[0] ?? "";
|
|
4170
|
+
return `${before}${range}${toolkitVersion}${after}`;
|
|
4171
|
+
}
|
|
5358
4172
|
);
|
|
5359
|
-
|
|
5360
|
-
|
|
5361
|
-
|
|
5362
|
-
|
|
4173
|
+
return updated === packageJson ? void 0 : updated;
|
|
4174
|
+
}
|
|
4175
|
+
async function main4(toolkitVersion) {
|
|
4176
|
+
const packageJsonPath = import_path5.default.join(process.cwd(), "package.json");
|
|
4177
|
+
if (!import_fs3.default.existsSync(packageJsonPath)) {
|
|
4178
|
+
console.log(`No package.json found. Skipping ${TOOLKIT_PACKAGE_NAME}.`);
|
|
4179
|
+
return;
|
|
5363
4180
|
}
|
|
5364
|
-
|
|
5365
|
-
|
|
5366
|
-
|
|
4181
|
+
const updated = updateToolkitDependency(
|
|
4182
|
+
import_fs3.default.readFileSync(packageJsonPath, "utf-8"),
|
|
4183
|
+
toolkitVersion
|
|
4184
|
+
);
|
|
4185
|
+
if (!updated) {
|
|
5367
4186
|
console.log(
|
|
5368
|
-
|
|
4187
|
+
`${TOOLKIT_PACKAGE_NAME} in package.json needs no update. Nothing to do.`
|
|
5369
4188
|
);
|
|
4189
|
+
return;
|
|
5370
4190
|
}
|
|
5371
|
-
|
|
5372
|
-
async function main9() {
|
|
5373
|
-
console.log("Upgrading the local Tilt setup...\n");
|
|
5374
|
-
upgradeTilt(process.cwd(), findTemplateDir());
|
|
4191
|
+
import_fs3.default.writeFileSync(packageJsonPath, updated);
|
|
5375
4192
|
console.log(
|
|
5376
|
-
|
|
4193
|
+
`Updated ${TOOLKIT_PACKAGE_NAME} to ${toolkitVersion} in package.json. Install the dependencies again to use it.`
|
|
5377
4194
|
);
|
|
5378
4195
|
}
|
|
5379
4196
|
|
|
5380
|
-
// src/migrations/
|
|
5381
|
-
|
|
5382
|
-
|
|
5383
|
-
|
|
4197
|
+
// src/migrations/replace-incomplete-flag.ts
|
|
4198
|
+
var import_ts_morph3 = require("ts-morph");
|
|
4199
|
+
var import_path6 = __toESM(require("path"));
|
|
4200
|
+
var INCOMPLETE = "InherentFlags.INCOMPLETE";
|
|
4201
|
+
var NOTIFIED_STATUS = `{ type: 'exact', term: EventStatus.enum.NOTIFIED }`;
|
|
4202
|
+
function ensureEventStatusImport(sourceFile) {
|
|
4203
|
+
const importDeclaration = sourceFile.getImportDeclarations().find(
|
|
4204
|
+
(declaration) => declaration.getNamedImports().some((named) => named.getName() === "InherentFlags")
|
|
4205
|
+
);
|
|
4206
|
+
const hasEventStatus = importDeclaration?.getNamedImports().some((named) => named.getName() === "EventStatus");
|
|
4207
|
+
if (importDeclaration && !hasEventStatus) {
|
|
4208
|
+
importDeclaration.addNamedImport("EventStatus");
|
|
4209
|
+
}
|
|
4210
|
+
}
|
|
4211
|
+
function replaceIncompleteFlag(sourceFile) {
|
|
4212
|
+
let changed = false;
|
|
4213
|
+
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) => {
|
|
4214
|
+
const anyOf = array2.getParent();
|
|
4215
|
+
const flags = anyOf?.getParent()?.getParent();
|
|
4216
|
+
return import_ts_morph3.Node.isPropertyAssignment(anyOf) && anyOf.getName() === "anyOf" && import_ts_morph3.Node.isPropertyAssignment(flags) && flags.getName() === "flags";
|
|
4217
|
+
});
|
|
4218
|
+
for (const array2 of anyOfIncomplete) {
|
|
4219
|
+
const anyOf = array2.getParentIfKindOrThrow(import_ts_morph3.SyntaxKind.PropertyAssignment);
|
|
4220
|
+
const flagsObject = anyOf.getParentIfKindOrThrow(
|
|
4221
|
+
import_ts_morph3.SyntaxKind.ObjectLiteralExpression
|
|
4222
|
+
);
|
|
4223
|
+
const flags = flagsObject.getParentIfKindOrThrow(
|
|
4224
|
+
import_ts_morph3.SyntaxKind.PropertyAssignment
|
|
4225
|
+
);
|
|
4226
|
+
const query = flags.getParentIfKindOrThrow(
|
|
4227
|
+
import_ts_morph3.SyntaxKind.ObjectLiteralExpression
|
|
4228
|
+
);
|
|
4229
|
+
array2.getElements().filter((element) => element.getText() === INCOMPLETE).forEach((element) => array2.removeElement(element));
|
|
4230
|
+
if (array2.getElements().length === 0) anyOf.remove();
|
|
4231
|
+
if (flagsObject.getProperties().length === 0) flags.remove();
|
|
4232
|
+
if (!query.getProperty("status")) {
|
|
4233
|
+
query.addPropertyAssignment({
|
|
4234
|
+
name: "status",
|
|
4235
|
+
initializer: NOTIFIED_STATUS
|
|
4236
|
+
});
|
|
4237
|
+
}
|
|
4238
|
+
changed = true;
|
|
4239
|
+
}
|
|
4240
|
+
if (changed) ensureEventStatusImport(sourceFile);
|
|
4241
|
+
const remaining = sourceFile.getDescendantsOfKind(import_ts_morph3.SyntaxKind.PropertyAccessExpression).filter((node) => node.getText() === INCOMPLETE).map((node) => node.getStartLineNumber());
|
|
4242
|
+
return { changed, remaining };
|
|
4243
|
+
}
|
|
4244
|
+
async function main5() {
|
|
4245
|
+
const project = new import_ts_morph3.Project({
|
|
4246
|
+
tsConfigFilePath: import_path6.default.join(process.cwd(), "tsconfig.json")
|
|
4247
|
+
});
|
|
4248
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => !sf.getFilePath().includes("/node_modules/"));
|
|
4249
|
+
for (const sourceFile of sourceFiles) {
|
|
4250
|
+
const relPath = import_path6.default.relative(process.cwd(), sourceFile.getFilePath());
|
|
4251
|
+
const { changed, remaining } = replaceIncompleteFlag(sourceFile);
|
|
4252
|
+
if (changed) {
|
|
4253
|
+
await sourceFile.save();
|
|
4254
|
+
console.log(
|
|
4255
|
+
` [${relPath}] Replaced the incomplete flag with the NOTIFIED status`
|
|
4256
|
+
);
|
|
4257
|
+
}
|
|
4258
|
+
for (const line2 of remaining) {
|
|
4259
|
+
console.warn(
|
|
4260
|
+
` [${relPath}:${line2}] ${INCOMPLETE} was removed, update this reference to use the NOTIFIED status`
|
|
4261
|
+
);
|
|
4262
|
+
}
|
|
4263
|
+
}
|
|
4264
|
+
}
|
|
4265
|
+
|
|
4266
|
+
// src/migrations/index.ts
|
|
4267
|
+
async function runUpgrade(toolkitVersion) {
|
|
4268
|
+
const [major, minor] = toolkitVersion.split(".");
|
|
5384
4269
|
await main2();
|
|
5385
4270
|
await main3();
|
|
5386
|
-
await
|
|
5387
|
-
await
|
|
5388
|
-
await
|
|
5389
|
-
await main9();
|
|
5390
|
-
await main4();
|
|
4271
|
+
await main(`${major}.${minor}`);
|
|
4272
|
+
await main5();
|
|
4273
|
+
await main4(toolkitVersion);
|
|
5391
4274
|
}
|
|
5392
4275
|
|
|
5393
4276
|
// src/environment/index.ts
|
|
5394
|
-
var
|
|
5395
|
-
var
|
|
4277
|
+
var import_fs8 = require("fs");
|
|
4278
|
+
var import_path11 = require("path");
|
|
5396
4279
|
init_paths();
|
|
5397
4280
|
var REQUIRED_REPOSITORY_DIRECTORIES = [
|
|
5398
4281
|
".github/workflows",
|
|
@@ -5403,7 +4286,7 @@ function validateRepositoryStructure(repositoryRoot = process.cwd()) {
|
|
|
5403
4286
|
const missingDirectories = REQUIRED_REPOSITORY_DIRECTORIES.filter(
|
|
5404
4287
|
(directory) => {
|
|
5405
4288
|
try {
|
|
5406
|
-
return !(0,
|
|
4289
|
+
return !(0, import_fs8.statSync)((0, import_path11.resolve)(repositoryRoot, directory)).isDirectory();
|
|
5407
4290
|
} catch {
|
|
5408
4291
|
return true;
|
|
5409
4292
|
}
|
|
@@ -5444,7 +4327,7 @@ async function runEnvironmentSwarmToK8s() {
|
|
|
5444
4327
|
// src/verify/endpoints.ts
|
|
5445
4328
|
var import_colors = require("kleur/colors");
|
|
5446
4329
|
var z = __toESM(require("zod/v4"));
|
|
5447
|
-
var
|
|
4330
|
+
var REQUEST_TIMEOUT_MS2 = 15e3;
|
|
5448
4331
|
var DEFAULT_TARGET_URL = "http://localhost:3040";
|
|
5449
4332
|
var REQUIRED_PUBLIC_ENDPOINTS = [
|
|
5450
4333
|
{ method: "GET", path: "/client-config.js" },
|
|
@@ -5515,7 +4398,7 @@ async function requestStatus(url, method) {
|
|
|
5515
4398
|
try {
|
|
5516
4399
|
const response = await fetch(url, {
|
|
5517
4400
|
method,
|
|
5518
|
-
signal: AbortSignal.timeout(
|
|
4401
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS2),
|
|
5519
4402
|
// Sent without an Authorization header on purpose. A secured route
|
|
5520
4403
|
// rejects with 401/403 before ever reading the body.
|
|
5521
4404
|
headers: method === "POST" ? { "Content-Type": "application/json" } : void 0,
|
|
@@ -5550,7 +4433,7 @@ function toEventTriggerConfig(value) {
|
|
|
5550
4433
|
async function fetchEventConfigs(baseUrl) {
|
|
5551
4434
|
try {
|
|
5552
4435
|
const response = await fetch(`${baseUrl}/config/events`, {
|
|
5553
|
-
signal: AbortSignal.timeout(
|
|
4436
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS2)
|
|
5554
4437
|
});
|
|
5555
4438
|
if (!response.ok) {
|
|
5556
4439
|
return null;
|
|
@@ -5614,7 +4497,7 @@ var ServedTranslations = z.object({
|
|
|
5614
4497
|
async function fetchServedTranslations(baseUrl, application) {
|
|
5615
4498
|
try {
|
|
5616
4499
|
const response = await fetch(`${baseUrl}/content/${application}`, {
|
|
5617
|
-
signal: AbortSignal.timeout(
|
|
4500
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS2)
|
|
5618
4501
|
});
|
|
5619
4502
|
if (!response.ok) {
|
|
5620
4503
|
return null;
|
|
@@ -5630,10 +4513,10 @@ async function verifyTranslations(baseUrl) {
|
|
|
5630
4513
|
let refs;
|
|
5631
4514
|
try {
|
|
5632
4515
|
refs = await candidateRefs(TEMPLATE_VERSION);
|
|
5633
|
-
} catch (
|
|
4516
|
+
} catch (error2) {
|
|
5634
4517
|
console.log(
|
|
5635
4518
|
" " + (0, import_colors.yellow)(
|
|
5636
|
-
`Could not list the ${TEMPLATE_VERSION} refs on GitHub (${
|
|
4519
|
+
`Could not list the ${TEMPLATE_VERSION} refs on GitHub (${error2.message}); translations not checked.`
|
|
5637
4520
|
)
|
|
5638
4521
|
);
|
|
5639
4522
|
return 0;
|
|
@@ -5644,10 +4527,10 @@ async function verifyTranslations(baseUrl) {
|
|
|
5644
4527
|
let fetched;
|
|
5645
4528
|
try {
|
|
5646
4529
|
fetched = await fetchTemplate(refs, application);
|
|
5647
|
-
} catch (
|
|
4530
|
+
} catch (error2) {
|
|
5648
4531
|
console.log(
|
|
5649
4532
|
" " + (0, import_colors.yellow)(
|
|
5650
|
-
`Could not read ${application}.csv from the country config template on GitHub (${
|
|
4533
|
+
`Could not read ${application}.csv from the country config template on GitHub (${error2.message}); ${endpoint} not checked.`
|
|
5651
4534
|
)
|
|
5652
4535
|
);
|
|
5653
4536
|
continue;
|
|
@@ -5730,8 +4613,8 @@ async function runVerifyEndpoints(target = DEFAULT_TARGET_URL) {
|
|
|
5730
4613
|
console.log(line(ok, endpointLabel(check), detail));
|
|
5731
4614
|
}
|
|
5732
4615
|
{
|
|
5733
|
-
const
|
|
5734
|
-
const status = await requestStatus(`${baseUrl}${
|
|
4616
|
+
const path12 = `/fonts/${PROBE_SEGMENT}.ttf`;
|
|
4617
|
+
const status = await requestStatus(`${baseUrl}${path12}`, "GET");
|
|
5735
4618
|
const ok = status === 200 || status === 404;
|
|
5736
4619
|
if (!ok) {
|
|
5737
4620
|
failures++;
|
|
@@ -5746,7 +4629,7 @@ async function runVerifyEndpoints(target = DEFAULT_TARGET_URL) {
|
|
|
5746
4629
|
} else {
|
|
5747
4630
|
detail = `${describeStatus(status)} \u2014 unexpected`;
|
|
5748
4631
|
}
|
|
5749
|
-
console.log(line(ok, `GET /fonts/{filename}${(0, import_colors.dim)(` \u2192 ${
|
|
4632
|
+
console.log(line(ok, `GET /fonts/{filename}${(0, import_colors.dim)(` \u2192 ${path12}`)}`, detail));
|
|
5750
4633
|
}
|
|
5751
4634
|
console.log();
|
|
5752
4635
|
console.log((0, import_colors.bold)("Secured endpoints (must be absent or require auth):"));
|
|
@@ -5873,18 +4756,20 @@ Exits with a non-zero status if any check fails.
|
|
|
5873
4756
|
var UPGRADE_USAGE = `
|
|
5874
4757
|
Usage: opencrvs upgrade [options]
|
|
5875
4758
|
|
|
5876
|
-
Upgrade the country config in the current working directory to
|
|
5877
|
-
|
|
4759
|
+
Upgrade the country config in the current working directory to this toolkit's
|
|
4760
|
+
version of OpenCRVS. Upgrade one minor version at a time: toolkit 2.2 upgrades
|
|
4761
|
+
a country config on 2.1.
|
|
4762
|
+
|
|
4763
|
+
The upgrade tells which version the country config is on by its
|
|
4764
|
+
@opencrvs/toolkit dependency, and updates that dependency itself once done.
|
|
4765
|
+
Run it without changing the dependency first, e.g.
|
|
4766
|
+
|
|
4767
|
+
npx @opencrvs/toolkit@2.2 upgrade
|
|
5878
4768
|
|
|
5879
4769
|
Options:
|
|
5880
|
-
--docker-swarm Keep the 'infrastructure/' directory where it is and
|
|
5881
|
-
only copy what the assets image needs into 'assets/'.
|
|
5882
|
-
Use this if your country deploys OpenCRVS via Docker
|
|
5883
|
-
Swarm. When omitted, 'infrastructure/' moves to
|
|
5884
|
-
'assets/' (default).
|
|
5885
4770
|
-h, --help Show this message.
|
|
5886
4771
|
`.trim();
|
|
5887
|
-
function
|
|
4772
|
+
function main6() {
|
|
5888
4773
|
const command = args[0];
|
|
5889
4774
|
if (!command || command === "--help" || command === "-h") {
|
|
5890
4775
|
console.log(USAGE);
|
|
@@ -5946,37 +4831,52 @@ Subcommands:
|
|
|
5946
4831
|
async function runEnvironmentCommand(operation, command) {
|
|
5947
4832
|
try {
|
|
5948
4833
|
await command();
|
|
5949
|
-
} catch (
|
|
4834
|
+
} catch (error2) {
|
|
5950
4835
|
console.error(
|
|
5951
4836
|
`Environment ${operation} failed:`,
|
|
5952
|
-
|
|
4837
|
+
error2 instanceof Error ? error2.message : error2
|
|
5953
4838
|
);
|
|
5954
4839
|
process.exit(1);
|
|
5955
4840
|
}
|
|
5956
4841
|
}
|
|
4842
|
+
function readToolkitVersion() {
|
|
4843
|
+
const packageJson = JSON.parse(
|
|
4844
|
+
import_fs9.default.readFileSync(import_path12.default.join(__dirname, "..", "package.json"), "utf-8")
|
|
4845
|
+
);
|
|
4846
|
+
return packageJson.version;
|
|
4847
|
+
}
|
|
5957
4848
|
async function handleUpgrade() {
|
|
5958
4849
|
const upgradeArgs = args.slice(1);
|
|
5959
4850
|
if (upgradeArgs.includes("--help") || upgradeArgs.includes("-h")) {
|
|
5960
4851
|
console.log(UPGRADE_USAGE);
|
|
5961
4852
|
process.exit(0);
|
|
5962
4853
|
}
|
|
5963
|
-
const
|
|
5964
|
-
const unknownFlags = upgradeArgs.filter(
|
|
5965
|
-
(arg) => arg.startsWith("-") && !KNOWN_FLAGS.has(arg)
|
|
5966
|
-
);
|
|
4854
|
+
const unknownFlags = upgradeArgs.filter((arg) => arg.startsWith("-"));
|
|
5967
4855
|
if (unknownFlags.length > 0) {
|
|
5968
4856
|
console.error(`Unknown option(s): ${unknownFlags.join(", ")}
|
|
5969
4857
|
`);
|
|
5970
4858
|
console.log(UPGRADE_USAGE);
|
|
5971
4859
|
process.exit(1);
|
|
5972
4860
|
}
|
|
5973
|
-
const
|
|
4861
|
+
const toolkitVersion = readToolkitVersion();
|
|
4862
|
+
const upgradePath = checkUpgradePath(
|
|
4863
|
+
findCountryConfigToolkitVersion(process.cwd()),
|
|
4864
|
+
toolkitVersion
|
|
4865
|
+
);
|
|
4866
|
+
if (upgradePath.status === "unknown") {
|
|
4867
|
+
console.warn(`\u26A0\uFE0F ${upgradePath.message}
|
|
4868
|
+
`);
|
|
4869
|
+
}
|
|
4870
|
+
if (upgradePath.status === "blocked") {
|
|
4871
|
+
console.error(upgradePath.message);
|
|
4872
|
+
process.exit(1);
|
|
4873
|
+
}
|
|
5974
4874
|
console.log("Initiating upgrade...");
|
|
5975
4875
|
try {
|
|
5976
|
-
await runUpgrade(
|
|
4876
|
+
await runUpgrade(toolkitVersion);
|
|
5977
4877
|
console.log("Upgrade completed successfully!");
|
|
5978
|
-
} catch (
|
|
5979
|
-
console.error("Upgrade failed:",
|
|
4878
|
+
} catch (error2) {
|
|
4879
|
+
console.error("Upgrade failed:", error2);
|
|
5980
4880
|
process.exit(1);
|
|
5981
4881
|
}
|
|
5982
4882
|
}
|
|
@@ -5997,12 +4897,12 @@ async function handleVerifyEndpoints() {
|
|
|
5997
4897
|
}
|
|
5998
4898
|
try {
|
|
5999
4899
|
await runVerifyEndpoints(positional[0]);
|
|
6000
|
-
} catch (
|
|
4900
|
+
} catch (error2) {
|
|
6001
4901
|
console.error(
|
|
6002
4902
|
"Endpoint verification failed:",
|
|
6003
|
-
|
|
4903
|
+
error2 instanceof Error ? error2.message : error2
|
|
6004
4904
|
);
|
|
6005
4905
|
process.exit(1);
|
|
6006
4906
|
}
|
|
6007
4907
|
}
|
|
6008
|
-
|
|
4908
|
+
main6();
|