@opencrvs/toolkit 2.1.2 → 2.2.0-rc.19ec10b
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 +9 -14
- package/create-countryconfig/package.json +1 -1
- package/dist/application-config/index.js +57 -14
- package/dist/authentication/index.d.ts +2 -1
- package/dist/authentication/index.js +34 -14
- package/dist/cli.js +1491 -2020
- package/dist/commons/api/router.d.ts +1564 -248
- package/dist/commons/application-config/index.d.ts +3 -3
- package/dist/commons/conditionals/conditionals.d.ts +58 -7
- package/dist/commons/conditionals/index.d.ts +1 -0
- package/dist/commons/conditionals/validate.d.ts +6 -1
- 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/ActionStatus.d.ts +2 -2
- package/dist/commons/events/ActionType.d.ts +13 -1
- package/dist/commons/events/AdvancedSearchConfig.d.ts +15 -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 +36 -1
- package/dist/commons/events/EventConfig.d.ts +473 -6
- package/dist/commons/events/EventDocument.d.ts +90 -0
- package/dist/commons/events/EventIndex.d.ts +44 -6
- package/dist/commons/events/EventInput.d.ts +1 -0
- package/dist/commons/events/EventMetadata.d.ts +24 -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 +17 -17
- package/dist/commons/events/Flag.d.ts +1 -7
- package/dist/commons/events/PlainDate.d.ts +6 -0
- package/dist/commons/events/WorkqueueConfig.d.ts +224 -33
- package/dist/commons/events/defineConfig.d.ts +7 -2
- package/dist/commons/events/event.d.ts +20 -1
- package/dist/commons/events/eventConfigValidation.d.ts +26 -1
- package/dist/commons/events/field.d.ts +37 -0
- package/dist/commons/events/index.d.ts +3 -0
- package/dist/commons/events/locations.d.ts +1 -1
- package/dist/commons/events/scopes.d.ts +4 -1
- package/dist/commons/events/state/flags.d.ts +1 -1
- package/dist/commons/events/state/index.d.ts +11 -2
- package/dist/commons/events/state/utils.d.ts +11 -1
- package/dist/commons/events/test.utils.d.ts +89 -7
- package/dist/commons/events/toNotificationForm.d.ts +17 -0
- package/dist/commons/events/utils.d.ts +90 -10
- package/dist/commons/users/Role.d.ts +23 -0
- package/dist/commons/users/User.d.ts +263 -0
- package/dist/commons/users/authentication.d.ts +67 -0
- package/dist/commons/users/index.d.ts +5 -0
- package/dist/commons/users/roleValidations.d.ts +15 -0
- package/dist/commons/users/scopes.d.ts +1402 -0
- package/dist/commons/users/userReferences.d.ts +176 -0
- package/dist/conditionals/index.js +29 -9
- package/dist/environment/custom-types.d.ts +1 -0
- package/dist/environment/custom-types.d.ts.map +1 -1
- package/dist/environment/derived-variables.d.ts +24 -4
- package/dist/environment/derived-variables.d.ts.map +1 -1
- package/dist/environment/derived-variables.js +27 -4
- package/dist/environment/questions.d.ts +42 -9
- package/dist/environment/questions.d.ts.map +1 -1
- package/dist/environment/questions.js +71 -48
- package/dist/environment/registry.d.ts +15 -0
- package/dist/environment/registry.d.ts.map +1 -0
- package/dist/environment/registry.js +112 -0
- package/dist/environment/setup-environment.d.ts.map +1 -1
- package/dist/environment/setup-environment.js +165 -35
- package/dist/environment/templates.d.ts.map +1 -1
- package/dist/events/index.js +2050 -1156
- package/dist/migrations/add-notify-config.d.ts +40 -0
- package/dist/migrations/add-notify-config.d.ts.map +1 -0
- package/dist/migrations/add-notify-config.js +249 -0
- package/dist/migrations/index.d.ts +9 -0
- package/dist/migrations/index.d.ts.map +1 -0
- package/dist/migrations/index.js +1306 -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 +260 -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 +199 -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/migrations/resolve-versioned-event-config.d.ts +56 -0
- package/dist/migrations/resolve-versioned-event-config.d.ts.map +1 -0
- package/dist/migrations/resolve-versioned-event-config.js +353 -0
- package/dist/migrations/utils.d.ts +61 -0
- package/dist/migrations/utils.d.ts.map +1 -0
- package/dist/migrations/utils.js +218 -0
- package/dist/notification/index.js +1081 -209
- package/dist/roles/index.d.ts +2 -0
- package/dist/roles/index.d.ts.map +1 -0
- package/dist/roles/index.js +730 -0
- package/dist/scopes/index.d.ts +83 -100
- package/dist/scopes/index.js +29 -13
- package/dist/templates/charts-values/dependencies/values.yaml +6 -3
- package/dist/templates/charts-values/opencrvs-services/values.yaml +5 -10
- package/dist/templates/charts-values/traefik/values.yaml +4 -3
- package/dist/verify/endpoints.d.ts +11 -0
- package/dist/verify/endpoints.d.ts.map +1 -1
- package/dist/verify/endpoints.js +21 -27
- package/opencrvs-toolkit-2.2.0-rc.19ec10b.tgz +0 -0
- package/package.json +5 -3
- package/tsconfig.build.tsbuildinfo +1 -1
- package/tsconfig.json +3 -5
- 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_path10.join)("environments", environment, INVENTORY_FILE_NAME);
|
|
36
36
|
}
|
|
37
37
|
function findOldInventoryFiles() {
|
|
38
|
-
return glob.sync((0,
|
|
38
|
+
return glob.sync((0, import_path10.join)(OLD_INVENTORY_DIR, "*.yml")).sort();
|
|
39
39
|
}
|
|
40
40
|
function getEnvironmentNameFromOldInventoryPath(filePath) {
|
|
41
|
-
return (0,
|
|
41
|
+
return (0, import_path10.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_path10, 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_path10 = require("path");
|
|
59
59
|
glob = __toESM(require("glob"));
|
|
60
|
-
OLD_INVENTORY_DIR = (0,
|
|
60
|
+
OLD_INVENTORY_DIR = (0, import_path10.join)(
|
|
61
61
|
"infrastructure",
|
|
62
62
|
"server-setup",
|
|
63
63
|
"inventory"
|
|
@@ -403,15 +403,17 @@ var init_derived_variables = __esm({
|
|
|
403
403
|
scope: "ENVIRONMENT"
|
|
404
404
|
},
|
|
405
405
|
{
|
|
406
|
-
name: "
|
|
407
|
-
valueLabel: "
|
|
406
|
+
name: "S3_ADMIN_ACCESS_KEY",
|
|
407
|
+
valueLabel: "S3_ADMIN_ACCESS_KEY",
|
|
408
|
+
legacyValueLabel: "MINIO_ROOT_USER",
|
|
408
409
|
valueType: "SECRET",
|
|
409
410
|
type: "disabled",
|
|
410
411
|
scope: "ENVIRONMENT"
|
|
411
412
|
},
|
|
412
413
|
{
|
|
413
|
-
name: "
|
|
414
|
-
valueLabel: "
|
|
414
|
+
name: "S3_ADMIN_SECRET_KEY",
|
|
415
|
+
valueLabel: "S3_ADMIN_SECRET_KEY",
|
|
416
|
+
legacyValueLabel: "MINIO_ROOT_PASSWORD",
|
|
415
417
|
valueType: "SECRET",
|
|
416
418
|
type: "disabled",
|
|
417
419
|
scope: "ENVIRONMENT"
|
|
@@ -499,6 +501,27 @@ var init_derived_variables = __esm({
|
|
|
499
501
|
valueType: "VARIABLE",
|
|
500
502
|
type: "disabled",
|
|
501
503
|
scope: "ENVIRONMENT"
|
|
504
|
+
},
|
|
505
|
+
{
|
|
506
|
+
name: "TWO_FA_ENABLED",
|
|
507
|
+
valueLabel: "TWO_FA_ENABLED",
|
|
508
|
+
valueType: "VARIABLE",
|
|
509
|
+
type: "disabled",
|
|
510
|
+
scope: "ENVIRONMENT"
|
|
511
|
+
},
|
|
512
|
+
{
|
|
513
|
+
name: "MONITORING_ENABLED",
|
|
514
|
+
valueLabel: "MONITORING_ENABLED",
|
|
515
|
+
valueType: "VARIABLE",
|
|
516
|
+
type: "disabled",
|
|
517
|
+
scope: "ENVIRONMENT"
|
|
518
|
+
},
|
|
519
|
+
{
|
|
520
|
+
name: "RUSTFS_HOST_DATA_PATH",
|
|
521
|
+
valueLabel: "RUSTFS_HOST_DATA_PATH",
|
|
522
|
+
valueType: "VARIABLE",
|
|
523
|
+
type: "disabled",
|
|
524
|
+
scope: "ENVIRONMENT"
|
|
502
525
|
}
|
|
503
526
|
];
|
|
504
527
|
}
|
|
@@ -518,7 +541,7 @@ function findExistingValue(name, type, scope, existingValues) {
|
|
|
518
541
|
);
|
|
519
542
|
}
|
|
520
543
|
function readYamlFile(filePath) {
|
|
521
|
-
const fileContent =
|
|
544
|
+
const fileContent = import_fs4.default.readFileSync(filePath, "utf8");
|
|
522
545
|
return yaml.load(fileContent);
|
|
523
546
|
}
|
|
524
547
|
function writeYamlFile(filePath, data) {
|
|
@@ -531,16 +554,16 @@ function writeYamlFile(filePath, data) {
|
|
|
531
554
|
noRefs: true,
|
|
532
555
|
sortKeys: false
|
|
533
556
|
});
|
|
534
|
-
|
|
535
|
-
} catch (
|
|
536
|
-
throw new Error(`Failed to write inventory file: ${
|
|
557
|
+
import_fs4.default.writeFileSync(filePath, yamlContent, "utf8");
|
|
558
|
+
} catch (error2) {
|
|
559
|
+
throw new Error(`Failed to write inventory file: ${error2}`);
|
|
537
560
|
}
|
|
538
561
|
}
|
|
539
|
-
var
|
|
562
|
+
var import_fs4, yaml;
|
|
540
563
|
var init_utils = __esm({
|
|
541
564
|
"src/environment/utils.ts"() {
|
|
542
565
|
"use strict";
|
|
543
|
-
|
|
566
|
+
import_fs4 = __toESM(require("fs"));
|
|
544
567
|
yaml = __toESM(require("js-yaml"));
|
|
545
568
|
}
|
|
546
569
|
});
|
|
@@ -589,29 +612,29 @@ function extractWorkerNodes(data) {
|
|
|
589
612
|
return worker_hosts;
|
|
590
613
|
}
|
|
591
614
|
function copyChartsValues(env, values) {
|
|
592
|
-
const srcDir =
|
|
593
|
-
const destDir =
|
|
594
|
-
|
|
615
|
+
const srcDir = import_path11.default.resolve(__dirname, "templates", "charts-values");
|
|
616
|
+
const destDir = import_path11.default.resolve(process.cwd(), "environments", env);
|
|
617
|
+
import_fs5.default.mkdirSync(destDir, { recursive: true });
|
|
595
618
|
values["lets_encrypt"] = values["traefik_mode"] === "lets_encrypt";
|
|
596
619
|
values["static_ssl"] = values["traefik_mode"] === "static_ssl";
|
|
597
620
|
values["opencrvs_environment"] = env;
|
|
598
621
|
function copyRecursive(src, dest) {
|
|
599
|
-
const stat =
|
|
622
|
+
const stat = import_fs5.default.statSync(src);
|
|
600
623
|
if (stat.isDirectory()) {
|
|
601
|
-
|
|
602
|
-
for (const item of
|
|
603
|
-
copyRecursive(
|
|
624
|
+
import_fs5.default.mkdirSync(dest, { recursive: true });
|
|
625
|
+
for (const item of import_fs5.default.readdirSync(src)) {
|
|
626
|
+
copyRecursive(import_path11.default.join(src, item), import_path11.default.join(dest, item));
|
|
604
627
|
}
|
|
605
628
|
} else {
|
|
606
|
-
const content =
|
|
629
|
+
const content = import_fs5.default.readFileSync(src, "utf8");
|
|
607
630
|
const template = import_handlebars.default.compile(content);
|
|
608
631
|
const updated = template(values);
|
|
609
632
|
const isOverridesFile = dest.endsWith("override.yaml");
|
|
610
|
-
if (isOverridesFile &&
|
|
633
|
+
if (isOverridesFile && import_fs5.default.existsSync(dest)) {
|
|
611
634
|
log(` \u21B7 Skipped existing overrides file: ${dest}`);
|
|
612
635
|
return;
|
|
613
636
|
}
|
|
614
|
-
|
|
637
|
+
import_fs5.default.writeFileSync(dest, updated, "utf8");
|
|
615
638
|
log(` \u2713 Created: ${dest}`);
|
|
616
639
|
}
|
|
617
640
|
}
|
|
@@ -622,29 +645,32 @@ function copyChartsValues(env, values) {
|
|
|
622
645
|
`);
|
|
623
646
|
}
|
|
624
647
|
function generateInventory(env, values) {
|
|
625
|
-
const templatePath =
|
|
648
|
+
const templatePath = import_path11.default.join(
|
|
626
649
|
__dirname,
|
|
627
650
|
"templates",
|
|
628
651
|
"inventory",
|
|
629
652
|
"inventory.template.yml"
|
|
630
653
|
);
|
|
631
|
-
const outputPath =
|
|
632
|
-
|
|
654
|
+
const outputPath = import_path11.default.resolve(
|
|
655
|
+
process.cwd(),
|
|
656
|
+
getEnvironmentInventoryPath(env)
|
|
657
|
+
);
|
|
658
|
+
const templateFile = import_fs5.default.readFileSync(templatePath, "utf-8");
|
|
633
659
|
const template = import_handlebars.default.compile(templateFile);
|
|
634
660
|
values["single_node"] = values["kube_worker_nodes"].length > 0 || values["backup_host"] ? "false" : "true";
|
|
635
661
|
const updated = template(values);
|
|
636
|
-
|
|
637
|
-
|
|
662
|
+
import_fs5.default.mkdirSync(import_path11.default.dirname(outputPath), { recursive: true });
|
|
663
|
+
import_fs5.default.writeFileSync(outputPath, updated);
|
|
638
664
|
log(`
|
|
639
665
|
\u2705 Generated inventory file at ${outputPath}
|
|
640
666
|
`);
|
|
641
667
|
}
|
|
642
|
-
var
|
|
668
|
+
var import_fs5, import_path11, import_handlebars;
|
|
643
669
|
var init_templates = __esm({
|
|
644
670
|
"src/environment/templates.ts"() {
|
|
645
671
|
"use strict";
|
|
646
|
-
|
|
647
|
-
|
|
672
|
+
import_fs5 = __toESM(require("fs"));
|
|
673
|
+
import_path11 = __toESM(require("path"));
|
|
648
674
|
init_logger();
|
|
649
675
|
init_paths();
|
|
650
676
|
import_handlebars = __toESM(require("handlebars"));
|
|
@@ -675,16 +701,16 @@ var update_workflows_exports = {};
|
|
|
675
701
|
__export(update_workflows_exports, {
|
|
676
702
|
updateWorkflowEnvironments: () => updateWorkflowEnvironments
|
|
677
703
|
});
|
|
678
|
-
function isDirectory(
|
|
704
|
+
function isDirectory(path15) {
|
|
679
705
|
try {
|
|
680
|
-
return (0,
|
|
706
|
+
return (0, import_fs6.statSync)(path15).isDirectory();
|
|
681
707
|
} catch {
|
|
682
708
|
return false;
|
|
683
709
|
}
|
|
684
710
|
}
|
|
685
711
|
async function extractInfrastructureNames() {
|
|
686
|
-
const files = glob2.sync((0,
|
|
687
|
-
const infraEnvironments = files.map((file) => (0,
|
|
712
|
+
const files = glob2.sync((0, import_path12.join)("environments", "*", INVENTORY_FILE_NAME));
|
|
713
|
+
const infraEnvironments = files.map((file) => (0, import_path12.basename)((0, import_path12.dirname)(file)));
|
|
688
714
|
if (infraEnvironments.length === 0) {
|
|
689
715
|
console.log(
|
|
690
716
|
`\u26A0\uFE0F Warning: No environment inventory files found at environments/*/${INVENTORY_FILE_NAME}`
|
|
@@ -697,9 +723,9 @@ async function extractInfrastructureNames() {
|
|
|
697
723
|
async function extractEnvironmentNames() {
|
|
698
724
|
const entries = await (0, import_promises.readdir)("environments");
|
|
699
725
|
const environments = entries.filter((entry) => {
|
|
700
|
-
const environmentPath = (0,
|
|
701
|
-
const opencrvsServicesPath = (0,
|
|
702
|
-
return isDirectory(environmentPath) && (0,
|
|
726
|
+
const environmentPath = (0, import_path12.join)("environments", entry);
|
|
727
|
+
const opencrvsServicesPath = (0, import_path12.join)(environmentPath, "opencrvs-services");
|
|
728
|
+
return isDirectory(environmentPath) && (0, import_fs6.existsSync)(opencrvsServicesPath) && isDirectory(opencrvsServicesPath);
|
|
703
729
|
});
|
|
704
730
|
if (environments.length === 0) {
|
|
705
731
|
console.log(
|
|
@@ -724,12 +750,12 @@ function updateOptionsInYaml(content, envList) {
|
|
|
724
750
|
async function updateWorkflows(envList, config) {
|
|
725
751
|
const { workflows } = config;
|
|
726
752
|
for (const workflowPath of workflows) {
|
|
727
|
-
if (!(0,
|
|
753
|
+
if (!(0, import_fs6.existsSync)(workflowPath)) {
|
|
728
754
|
log(` \u21B7 Skipped ${workflowPath} (not found in this repository)`);
|
|
729
755
|
continue;
|
|
730
756
|
}
|
|
731
757
|
try {
|
|
732
|
-
const fileContents = (0,
|
|
758
|
+
const fileContents = (0, import_fs6.readFileSync)(workflowPath, "utf8");
|
|
733
759
|
const workflowData = yaml2.load(fileContents);
|
|
734
760
|
if (!workflowData?.on?.workflow_dispatch?.inputs?.environment?.options) {
|
|
735
761
|
throw new Error(
|
|
@@ -737,15 +763,15 @@ async function updateWorkflows(envList, config) {
|
|
|
737
763
|
);
|
|
738
764
|
}
|
|
739
765
|
const updatedContent = updateOptionsInYaml(fileContents, envList);
|
|
740
|
-
(0,
|
|
766
|
+
(0, import_fs6.writeFileSync)(workflowPath, updatedContent, "utf8");
|
|
741
767
|
log(` \u2713 Successfully updated ${workflowPath}`);
|
|
742
|
-
} catch (
|
|
768
|
+
} catch (error2) {
|
|
743
769
|
console.error(
|
|
744
770
|
`
|
|
745
771
|
\u26A0\uFE0F Error updating ${workflowPath} with environments: [${envList.join(", ")}]`
|
|
746
772
|
);
|
|
747
|
-
console.error(`\u2717 Failed to update ${workflowPath}:`,
|
|
748
|
-
throw
|
|
773
|
+
console.error(`\u2717 Failed to update ${workflowPath}:`, error2);
|
|
774
|
+
throw error2;
|
|
749
775
|
}
|
|
750
776
|
}
|
|
751
777
|
}
|
|
@@ -786,18 +812,18 @@ async function updateWorkflowEnvironments() {
|
|
|
786
812
|
} else {
|
|
787
813
|
log("\u2139\uFE0F No workflows were updated.");
|
|
788
814
|
}
|
|
789
|
-
} catch (
|
|
790
|
-
console.error("\n\u274C Error updating workflows:",
|
|
815
|
+
} catch (error2) {
|
|
816
|
+
console.error("\n\u274C Error updating workflows:", error2);
|
|
791
817
|
process.exit(1);
|
|
792
818
|
}
|
|
793
819
|
}
|
|
794
|
-
var import_promises,
|
|
820
|
+
var import_promises, import_fs6, import_path12, glob2, yaml2;
|
|
795
821
|
var init_update_workflows = __esm({
|
|
796
822
|
"src/environment/update-workflows.ts"() {
|
|
797
823
|
"use strict";
|
|
798
824
|
import_promises = require("fs/promises");
|
|
799
|
-
|
|
800
|
-
|
|
825
|
+
import_fs6 = require("fs");
|
|
826
|
+
import_path12 = require("path");
|
|
801
827
|
glob2 = __toESM(require("glob"));
|
|
802
828
|
yaml2 = __toESM(require("js-yaml"));
|
|
803
829
|
init_logger();
|
|
@@ -808,7 +834,7 @@ var init_update_workflows = __esm({
|
|
|
808
834
|
// src/environment/git.ts
|
|
809
835
|
function getRepoInfo() {
|
|
810
836
|
try {
|
|
811
|
-
const remoteUrl = (0,
|
|
837
|
+
const remoteUrl = (0, import_child_process.execSync)("git config --get remote.origin.url", {
|
|
812
838
|
stdio: ["ignore", "pipe", "ignore"]
|
|
813
839
|
}).toString().trim();
|
|
814
840
|
const match = remoteUrl.match(/github\.com[:/](.+?)\/(.+?)(\.git)?$/);
|
|
@@ -826,11 +852,11 @@ function getRepoInfo() {
|
|
|
826
852
|
};
|
|
827
853
|
}
|
|
828
854
|
}
|
|
829
|
-
var
|
|
855
|
+
var import_child_process;
|
|
830
856
|
var init_git = __esm({
|
|
831
857
|
"src/environment/git.ts"() {
|
|
832
858
|
"use strict";
|
|
833
|
-
|
|
859
|
+
import_child_process = require("child_process");
|
|
834
860
|
}
|
|
835
861
|
});
|
|
836
862
|
|
|
@@ -855,7 +881,10 @@ function validateCIDRs(input4) {
|
|
|
855
881
|
}
|
|
856
882
|
return true;
|
|
857
883
|
}
|
|
858
|
-
|
|
884
|
+
function validateRegistryHost(input4) {
|
|
885
|
+
return /^[a-z0-9]([a-z0-9.-]*[a-z0-9])?(:[0-9]+)?$/i.test(input4) ? true : "Please enter a registry host without protocol or path (e.g. docker.io, ghcr.io)";
|
|
886
|
+
}
|
|
887
|
+
var import_kleur2, notEmpty, registryQuestions, githubQuestions, githubApprovalRequiredQuestion, githubApproversQuestion, githubOtherQuestions, githubTokenQuestion, countryQuestions, infrastructureQuestions, staticSSLCertQuestions, backupQuestions, diskQuestions, databaseAndMonitoringQuestions, emailQuestions, sentryQuestions, metabaseAdminQuestions;
|
|
859
888
|
var init_questions = __esm({
|
|
860
889
|
"src/environment/questions.ts"() {
|
|
861
890
|
"use strict";
|
|
@@ -863,45 +892,59 @@ var init_questions = __esm({
|
|
|
863
892
|
init_utils();
|
|
864
893
|
init_git();
|
|
865
894
|
notEmpty = (value) => value.toString().trim().length > 0 ? true : "Please enter a value";
|
|
866
|
-
|
|
895
|
+
registryQuestions = [
|
|
896
|
+
{
|
|
897
|
+
name: "registryHost",
|
|
898
|
+
type: "text",
|
|
899
|
+
message: "What is the host of your container registry? (e.g. docker.io, ghcr.io)",
|
|
900
|
+
valueType: "VARIABLE",
|
|
901
|
+
valueLabel: "REGISTRY_HOST",
|
|
902
|
+
validate: validateRegistryHost,
|
|
903
|
+
initial: process.env.REGISTRY_HOST || "docker.io",
|
|
904
|
+
scope: "REPOSITORY"
|
|
905
|
+
},
|
|
867
906
|
{
|
|
868
|
-
name: "
|
|
907
|
+
name: "registryOrganisation",
|
|
869
908
|
type: "text",
|
|
870
|
-
message: "What is the name of your
|
|
909
|
+
message: "What is the name of your organisation (or user) in the container registry?",
|
|
871
910
|
valueType: "SECRET",
|
|
872
|
-
valueLabel: "
|
|
911
|
+
valueLabel: "REGISTRY_ORGANISATION",
|
|
912
|
+
legacyValueLabel: "DOCKERHUB_ACCOUNT",
|
|
873
913
|
validate: notEmpty,
|
|
874
|
-
initial: process.env.
|
|
914
|
+
initial: process.env.REGISTRY_ORGANISATION,
|
|
875
915
|
scope: "REPOSITORY"
|
|
876
916
|
},
|
|
877
917
|
{
|
|
878
|
-
name: "
|
|
918
|
+
name: "registryRepository",
|
|
879
919
|
type: "text",
|
|
880
|
-
message: "What is the name of your private
|
|
920
|
+
message: "What is the name of your private container repository?",
|
|
881
921
|
valueType: "SECRET",
|
|
882
|
-
valueLabel: "
|
|
922
|
+
valueLabel: "REGISTRY_REPOSITORY",
|
|
923
|
+
legacyValueLabel: "DOCKERHUB_REPO",
|
|
883
924
|
validate: notEmpty,
|
|
884
|
-
initial: process.env.
|
|
925
|
+
initial: process.env.REGISTRY_REPOSITORY,
|
|
885
926
|
scope: "REPOSITORY"
|
|
886
927
|
},
|
|
887
928
|
{
|
|
888
|
-
name: "
|
|
929
|
+
name: "registryUsername",
|
|
889
930
|
type: "text",
|
|
890
|
-
message: "What is the
|
|
931
|
+
message: "What is the container registry username the target server should be using?",
|
|
891
932
|
valueType: "SECRET",
|
|
892
|
-
valueLabel: "
|
|
933
|
+
valueLabel: "REGISTRY_USERNAME",
|
|
934
|
+
legacyValueLabel: "DOCKER_USERNAME",
|
|
893
935
|
validate: notEmpty,
|
|
894
|
-
initial: process.env.
|
|
936
|
+
initial: process.env.REGISTRY_USERNAME,
|
|
895
937
|
scope: "REPOSITORY"
|
|
896
938
|
},
|
|
897
939
|
{
|
|
898
|
-
name: "
|
|
940
|
+
name: "registryToken",
|
|
899
941
|
type: "text",
|
|
900
|
-
message: "What is the token of this
|
|
942
|
+
message: "What is the token of this container registry account?",
|
|
901
943
|
valueType: "SECRET",
|
|
902
|
-
valueLabel: "
|
|
944
|
+
valueLabel: "REGISTRY_TOKEN",
|
|
945
|
+
legacyValueLabel: "DOCKER_TOKEN",
|
|
903
946
|
validate: notEmpty,
|
|
904
|
-
initial: process.env.
|
|
947
|
+
initial: process.env.REGISTRY_TOKEN,
|
|
905
948
|
scope: "REPOSITORY"
|
|
906
949
|
}
|
|
907
950
|
];
|
|
@@ -923,36 +966,38 @@ var init_questions = __esm({
|
|
|
923
966
|
scope: "REPOSITORY"
|
|
924
967
|
}
|
|
925
968
|
];
|
|
969
|
+
githubApprovalRequiredQuestion = {
|
|
970
|
+
name: "approvalRequired",
|
|
971
|
+
type: "select",
|
|
972
|
+
message: "Would you like to enable approvals process for GitHub action workflows?",
|
|
973
|
+
choices: [
|
|
974
|
+
{
|
|
975
|
+
title: "True",
|
|
976
|
+
value: "true"
|
|
977
|
+
},
|
|
978
|
+
{
|
|
979
|
+
title: "False",
|
|
980
|
+
value: "false"
|
|
981
|
+
}
|
|
982
|
+
],
|
|
983
|
+
valueType: "VARIABLE",
|
|
984
|
+
validate: notEmpty,
|
|
985
|
+
valueLabel: "APPROVAL_REQUIRED",
|
|
986
|
+
initial: process.env.APPROVAL_REQUIRED,
|
|
987
|
+
scope: "ENVIRONMENT"
|
|
988
|
+
};
|
|
989
|
+
githubApproversQuestion = {
|
|
990
|
+
name: "githubApprovers",
|
|
991
|
+
type: "text",
|
|
992
|
+
message: "Please provide/update list of approvers?",
|
|
993
|
+
initial: process.env.GH_APPROVERS,
|
|
994
|
+
valueType: "VARIABLE",
|
|
995
|
+
valueLabel: "GH_APPROVERS",
|
|
996
|
+
scope: "REPOSITORY"
|
|
997
|
+
};
|
|
926
998
|
githubOtherQuestions = [
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
type: "text",
|
|
930
|
-
message: "Please provide/update list of production approvers?",
|
|
931
|
-
initial: process.env.GH_APPROVERS,
|
|
932
|
-
valueType: "VARIABLE",
|
|
933
|
-
valueLabel: "GH_APPROVERS",
|
|
934
|
-
scope: "REPOSITORY"
|
|
935
|
-
},
|
|
936
|
-
{
|
|
937
|
-
name: "approvalRequired",
|
|
938
|
-
type: "select",
|
|
939
|
-
message: "Would you like to enable approvals process for GitHub action workflows?",
|
|
940
|
-
choices: [
|
|
941
|
-
{
|
|
942
|
-
title: "True",
|
|
943
|
-
value: "true"
|
|
944
|
-
},
|
|
945
|
-
{
|
|
946
|
-
title: "False",
|
|
947
|
-
value: "false"
|
|
948
|
-
}
|
|
949
|
-
],
|
|
950
|
-
valueType: "VARIABLE",
|
|
951
|
-
validate: notEmpty,
|
|
952
|
-
valueLabel: "APPROVAL_REQUIRED",
|
|
953
|
-
initial: process.env.APPROVAL_REQUIRED,
|
|
954
|
-
scope: "ENVIRONMENT"
|
|
955
|
-
}
|
|
999
|
+
githubApprovalRequiredQuestion,
|
|
1000
|
+
githubApproversQuestion
|
|
956
1001
|
];
|
|
957
1002
|
githubTokenQuestion = [
|
|
958
1003
|
{
|
|
@@ -1360,6 +1405,87 @@ var init_questions_helper = __esm({
|
|
|
1360
1405
|
}
|
|
1361
1406
|
});
|
|
1362
1407
|
|
|
1408
|
+
// src/environment/registry.ts
|
|
1409
|
+
function registryApiHost(registry) {
|
|
1410
|
+
const host = registry.trim().toLowerCase();
|
|
1411
|
+
return host === "docker.io" || host === "index.docker.io" ? "registry-1.docker.io" : host;
|
|
1412
|
+
}
|
|
1413
|
+
function request(url, authorization) {
|
|
1414
|
+
return fetch(url, {
|
|
1415
|
+
headers: authorization ? { Authorization: authorization } : {},
|
|
1416
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)
|
|
1417
|
+
});
|
|
1418
|
+
}
|
|
1419
|
+
function failure(registry, step, response) {
|
|
1420
|
+
const reason = `${registry} ${step} responded with HTTP ${response.status}`;
|
|
1421
|
+
switch (response.status) {
|
|
1422
|
+
case 401:
|
|
1423
|
+
case 403:
|
|
1424
|
+
return {
|
|
1425
|
+
status: "invalid-credentials",
|
|
1426
|
+
reason: `${reason}. Check REGISTRY_USERNAME, REGISTRY_TOKEN, REGISTRY_ORGANISATION and REGISTRY_REPOSITORY`
|
|
1427
|
+
};
|
|
1428
|
+
case 404:
|
|
1429
|
+
return {
|
|
1430
|
+
status: "repository-not-found",
|
|
1431
|
+
reason: `${reason}. This is also the answer for an empty repository. Check REGISTRY_ORGANISATION and REGISTRY_REPOSITORY`
|
|
1432
|
+
};
|
|
1433
|
+
default:
|
|
1434
|
+
return { status: "unreachable", reason };
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1437
|
+
async function validateRegistryCredentials(registry, organisation, repository, username, token) {
|
|
1438
|
+
if (!registry || !organisation || !repository || !username || !token) {
|
|
1439
|
+
return {
|
|
1440
|
+
status: "skipped",
|
|
1441
|
+
reason: "Some values are kept from existing GitHub secrets, which cannot be read back"
|
|
1442
|
+
};
|
|
1443
|
+
}
|
|
1444
|
+
const host = registryApiHost(registry);
|
|
1445
|
+
const name = `${organisation}/${repository}`;
|
|
1446
|
+
const basic = `Basic ${Buffer.from(`${username}:${token}`).toString("base64")}`;
|
|
1447
|
+
try {
|
|
1448
|
+
const challenge = (await request(`https://${host}/v2/`, void 0)).headers.get(
|
|
1449
|
+
"www-authenticate"
|
|
1450
|
+
) ?? "";
|
|
1451
|
+
const realm = challenge.match(/realm="([^"]*)"/i)?.[1];
|
|
1452
|
+
const service = challenge.match(/service="([^"]*)"/i)?.[1];
|
|
1453
|
+
let authorization = basic;
|
|
1454
|
+
if (/^\s*bearer/i.test(challenge) && realm) {
|
|
1455
|
+
const tokenUrl = new URL(realm);
|
|
1456
|
+
if (service) {
|
|
1457
|
+
tokenUrl.searchParams.set("service", service);
|
|
1458
|
+
}
|
|
1459
|
+
tokenUrl.searchParams.set("scope", `repository:${name}:pull`);
|
|
1460
|
+
const login = await request(tokenUrl, basic);
|
|
1461
|
+
if (!login.ok) {
|
|
1462
|
+
return failure(registry, "login", login);
|
|
1463
|
+
}
|
|
1464
|
+
const body = await login.json();
|
|
1465
|
+
authorization = `Bearer ${body.token ?? body.access_token}`;
|
|
1466
|
+
}
|
|
1467
|
+
const path15 = name.split("/").map(encodeURIComponent).join("/");
|
|
1468
|
+
const response = await request(
|
|
1469
|
+
`https://${host}/v2/${path15}/tags/list?n=1`,
|
|
1470
|
+
authorization
|
|
1471
|
+
);
|
|
1472
|
+
return response.ok ? { status: "valid" } : failure(registry, `lookup of repository ${name}`, response);
|
|
1473
|
+
} catch (err) {
|
|
1474
|
+
if (!(err instanceof Error)) {
|
|
1475
|
+
return { status: "unreachable", reason: String(err) };
|
|
1476
|
+
}
|
|
1477
|
+
const cause = err.cause instanceof Error ? `: ${err.cause.message}` : "";
|
|
1478
|
+
return { status: "unreachable", reason: `${err.message}${cause}` };
|
|
1479
|
+
}
|
|
1480
|
+
}
|
|
1481
|
+
var REQUEST_TIMEOUT_MS;
|
|
1482
|
+
var init_registry = __esm({
|
|
1483
|
+
"src/environment/registry.ts"() {
|
|
1484
|
+
"use strict";
|
|
1485
|
+
REQUEST_TIMEOUT_MS = 1e4;
|
|
1486
|
+
}
|
|
1487
|
+
});
|
|
1488
|
+
|
|
1363
1489
|
// src/environment/manage-users.ts
|
|
1364
1490
|
async function inquirerPrompt(name, options) {
|
|
1365
1491
|
const inquirer = await import("@inquirer/prompts");
|
|
@@ -1397,13 +1523,13 @@ function getCurrentUserSSHKeys() {
|
|
|
1397
1523
|
for (const keyFile of keyFiles) {
|
|
1398
1524
|
const keyPath = path11.join(sshDir, keyFile);
|
|
1399
1525
|
try {
|
|
1400
|
-
if (
|
|
1401
|
-
const keyContent =
|
|
1526
|
+
if (fs5.existsSync(keyPath)) {
|
|
1527
|
+
const keyContent = fs5.readFileSync(keyPath, "utf8").trim();
|
|
1402
1528
|
if (keyContent) {
|
|
1403
1529
|
keys.push(keyContent);
|
|
1404
1530
|
}
|
|
1405
1531
|
}
|
|
1406
|
-
} catch (
|
|
1532
|
+
} catch (error2) {
|
|
1407
1533
|
continue;
|
|
1408
1534
|
}
|
|
1409
1535
|
}
|
|
@@ -1617,7 +1743,7 @@ async function editUser(user) {
|
|
|
1617
1743
|
return updatedUser;
|
|
1618
1744
|
}
|
|
1619
1745
|
async function manageUsers(inventoryPath) {
|
|
1620
|
-
let users =
|
|
1746
|
+
let users = fs5.existsSync(inventoryPath) ? parseInventoryFile(inventoryPath) : [];
|
|
1621
1747
|
if (users.length > 0) {
|
|
1622
1748
|
displayUserSummary(users);
|
|
1623
1749
|
}
|
|
@@ -1709,7 +1835,7 @@ async function manageUsers(inventoryPath) {
|
|
|
1709
1835
|
message: "Save changes end exit?",
|
|
1710
1836
|
default: true
|
|
1711
1837
|
});
|
|
1712
|
-
if (confirmSave &&
|
|
1838
|
+
if (confirmSave && fs5.existsSync(inventoryPath)) {
|
|
1713
1839
|
updateInventoryFile(inventoryPath, users);
|
|
1714
1840
|
console.log(`
|
|
1715
1841
|
\u2705 Changes saved to ${inventoryPath}
|
|
@@ -1736,12 +1862,12 @@ async function manageUsers(inventoryPath) {
|
|
|
1736
1862
|
}
|
|
1737
1863
|
return users;
|
|
1738
1864
|
}
|
|
1739
|
-
var os,
|
|
1865
|
+
var os, fs5, path11, input2, select2, confirm, editor, checkbox;
|
|
1740
1866
|
var init_manage_users = __esm({
|
|
1741
1867
|
"src/environment/manage-users.ts"() {
|
|
1742
1868
|
"use strict";
|
|
1743
1869
|
os = __toESM(require("os"));
|
|
1744
|
-
|
|
1870
|
+
fs5 = __toESM(require("fs"));
|
|
1745
1871
|
path11 = __toESM(require("path"));
|
|
1746
1872
|
init_logger();
|
|
1747
1873
|
init_utils();
|
|
@@ -1774,6 +1900,7 @@ async function input3(options) {
|
|
|
1774
1900
|
function questionToPrompt({
|
|
1775
1901
|
valueType,
|
|
1776
1902
|
valueLabel,
|
|
1903
|
+
legacyValueLabel,
|
|
1777
1904
|
scope,
|
|
1778
1905
|
...promptOptions
|
|
1779
1906
|
}) {
|
|
@@ -1837,6 +1964,12 @@ function getAnswers(existingValues) {
|
|
|
1837
1964
|
});
|
|
1838
1965
|
});
|
|
1839
1966
|
}
|
|
1967
|
+
function getInitialValue(question, variable) {
|
|
1968
|
+
if (question.type === "select" && Array.isArray(question.choices)) {
|
|
1969
|
+
return getIndexFromChoices(question.choices, variable.value);
|
|
1970
|
+
}
|
|
1971
|
+
return variable.value;
|
|
1972
|
+
}
|
|
1840
1973
|
async function promptAndStoreAnswer(questions, existingValues) {
|
|
1841
1974
|
log("");
|
|
1842
1975
|
const processedQuestions = questions.flatMap((question) => {
|
|
@@ -1854,14 +1987,22 @@ async function promptAndStoreAnswer(questions, existingValues) {
|
|
|
1854
1987
|
questionWithVariableLabel.scope,
|
|
1855
1988
|
existingValues
|
|
1856
1989
|
);
|
|
1990
|
+
const legacyVariable = !existingVariable && questionWithVariableLabel.legacyValueLabel ? findExistingValue(
|
|
1991
|
+
questionWithVariableLabel.legacyValueLabel,
|
|
1992
|
+
"VARIABLE",
|
|
1993
|
+
questionWithVariableLabel.scope,
|
|
1994
|
+
existingValues
|
|
1995
|
+
) : void 0;
|
|
1996
|
+
if (legacyVariable) {
|
|
1997
|
+
return {
|
|
1998
|
+
...questionWithVariableLabel,
|
|
1999
|
+
message: `${questionWithVariableLabel.message} ${import_kleur4.default.gray(
|
|
2000
|
+
`(default taken from ${legacyVariable.name}, the previous name of this variable)`
|
|
2001
|
+
)}`,
|
|
2002
|
+
initial: getInitialValue(questionWithVariableLabel, legacyVariable)
|
|
2003
|
+
};
|
|
2004
|
+
}
|
|
1857
2005
|
if (existingVariable) {
|
|
1858
|
-
let initial_value = existingVariable.value;
|
|
1859
|
-
if (questionWithVariableLabel.type === "select" && Array.isArray(questionWithVariableLabel.choices)) {
|
|
1860
|
-
initial_value = getIndexFromChoices(
|
|
1861
|
-
questionWithVariableLabel.choices,
|
|
1862
|
-
existingVariable.value
|
|
1863
|
-
);
|
|
1864
|
-
}
|
|
1865
2006
|
return [
|
|
1866
2007
|
{
|
|
1867
2008
|
name: "overWrite" + questionWithVariableLabel.name,
|
|
@@ -1876,7 +2017,10 @@ async function promptAndStoreAnswer(questions, existingValues) {
|
|
|
1876
2017
|
{
|
|
1877
2018
|
...questionWithVariableLabel,
|
|
1878
2019
|
type: (prev) => prev ? questionWithVariableLabel.type : null,
|
|
1879
|
-
initial:
|
|
2020
|
+
initial: getInitialValue(
|
|
2021
|
+
questionWithVariableLabel,
|
|
2022
|
+
existingVariable
|
|
2023
|
+
)
|
|
1880
2024
|
}
|
|
1881
2025
|
];
|
|
1882
2026
|
}
|
|
@@ -1888,6 +2032,32 @@ async function promptAndStoreAnswer(questions, existingValues) {
|
|
|
1888
2032
|
questionWithVariableLabel.scope,
|
|
1889
2033
|
existingValues
|
|
1890
2034
|
);
|
|
2035
|
+
const legacySecret = !existingSecret && questionWithVariableLabel.legacyValueLabel ? findExistingValue(
|
|
2036
|
+
questionWithVariableLabel.legacyValueLabel,
|
|
2037
|
+
"SECRET",
|
|
2038
|
+
questionWithVariableLabel.scope,
|
|
2039
|
+
existingValues
|
|
2040
|
+
) : void 0;
|
|
2041
|
+
if (legacySecret) {
|
|
2042
|
+
return [
|
|
2043
|
+
{
|
|
2044
|
+
name: "overWrite" + questionWithVariableLabel.name,
|
|
2045
|
+
type: "confirm",
|
|
2046
|
+
scope: questionWithVariableLabel.scope,
|
|
2047
|
+
message: `${import_kleur4.default.yellow(
|
|
2048
|
+
`${legacySecret.scope === "REPOSITORY" ? "Repository secret" : "Secret"} ${import_kleur4.default.cyan(
|
|
2049
|
+
legacySecret.name
|
|
2050
|
+
)} already exists in Github under the previous name of ${import_kleur4.default.cyan(
|
|
2051
|
+
questionWithVariableLabel.valueLabel
|
|
2052
|
+
)}. The secrets migration workflow copies it. Do you want to enter a new value instead?`
|
|
2053
|
+
)}`
|
|
2054
|
+
},
|
|
2055
|
+
{
|
|
2056
|
+
...questionWithVariableLabel,
|
|
2057
|
+
type: (prev) => prev ? questionWithVariableLabel.type : null
|
|
2058
|
+
}
|
|
2059
|
+
];
|
|
2060
|
+
}
|
|
1891
2061
|
if (existingSecret) {
|
|
1892
2062
|
return [
|
|
1893
2063
|
{
|
|
@@ -1927,6 +2097,47 @@ async function promptAndStoreAnswer(questions, existingValues) {
|
|
|
1927
2097
|
]);
|
|
1928
2098
|
return { ...Object.fromEntries(existingValuesForQuestions), ...result };
|
|
1929
2099
|
}
|
|
2100
|
+
function defineIfMissing(existingValues, name, type, scope, newValue) {
|
|
2101
|
+
if (findExistingValue(name, type, scope, existingValues)) {
|
|
2102
|
+
return null;
|
|
2103
|
+
}
|
|
2104
|
+
const legacyName = ALL_QUESTIONS.find(
|
|
2105
|
+
(question) => question.valueLabel === name && question.valueType === type && question.scope === scope
|
|
2106
|
+
)?.legacyValueLabel;
|
|
2107
|
+
if (legacyName && findExistingValue(legacyName, type, scope, existingValues)) {
|
|
2108
|
+
log(
|
|
2109
|
+
import_kleur4.default.bold().green("\u2714"),
|
|
2110
|
+
import_kleur4.default.bold().yellow(
|
|
2111
|
+
`${legacyName} exists, the secrets migration workflow copies it to ${name}`
|
|
2112
|
+
)
|
|
2113
|
+
);
|
|
2114
|
+
return null;
|
|
2115
|
+
}
|
|
2116
|
+
return process.env[name] || newValue;
|
|
2117
|
+
}
|
|
2118
|
+
async function promptAndValidateRegistry(existingValues) {
|
|
2119
|
+
const answers = await promptAndStoreAnswer(registryQuestions, existingValues);
|
|
2120
|
+
const result = await validateRegistryCredentials(
|
|
2121
|
+
answers.registryHost,
|
|
2122
|
+
answers.registryOrganisation,
|
|
2123
|
+
answers.registryRepository,
|
|
2124
|
+
answers.registryUsername,
|
|
2125
|
+
answers.registryToken
|
|
2126
|
+
);
|
|
2127
|
+
if (result.status === "valid" || result.status === "skipped") {
|
|
2128
|
+
return;
|
|
2129
|
+
}
|
|
2130
|
+
error(`
|
|
2131
|
+
${result.status}: ${result.reason || "Generic error"}
|
|
2132
|
+
`);
|
|
2133
|
+
const continueNotValidated = await confirm2({
|
|
2134
|
+
message: "Container registry credentials are not validated. Continue anyway?",
|
|
2135
|
+
default: false
|
|
2136
|
+
});
|
|
2137
|
+
if (!continueNotValidated) {
|
|
2138
|
+
process.exit(1);
|
|
2139
|
+
}
|
|
2140
|
+
}
|
|
1930
2141
|
async function runSetupEnvironment() {
|
|
1931
2142
|
log("\n", import_kleur4.default.bold().underline("Github"), "\n");
|
|
1932
2143
|
const { githubOrganisation, githubRepository } = await (0, import_prompts2.default)(
|
|
@@ -1990,16 +2201,6 @@ async function runSetupEnvironment() {
|
|
|
1990
2201
|
]
|
|
1991
2202
|
});
|
|
1992
2203
|
}
|
|
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
2204
|
const environment_exists = existingEnvironments.map((e) => e.trim()).includes(environment);
|
|
2004
2205
|
if (!environment) {
|
|
2005
2206
|
process.exit(1);
|
|
@@ -2061,10 +2262,42 @@ async function runSetupEnvironment() {
|
|
|
2061
2262
|
"WARNING! You are setting up a production environment.\n Make sure you have read the deployment guide carefully before proceeding.\n"
|
|
2062
2263
|
)
|
|
2063
2264
|
);
|
|
2064
|
-
await promptAndStoreAnswer(githubOtherQuestions, existingValues);
|
|
2065
2265
|
}
|
|
2066
|
-
log("\n", import_kleur4.default.bold().underline("
|
|
2067
|
-
await promptAndStoreAnswer(
|
|
2266
|
+
log("\n", import_kleur4.default.bold().underline("Workflow approvals"));
|
|
2267
|
+
const { approvalRequired } = await promptAndStoreAnswer(
|
|
2268
|
+
[
|
|
2269
|
+
{
|
|
2270
|
+
...githubApprovalRequiredQuestion,
|
|
2271
|
+
initial: getIndexFromChoices(
|
|
2272
|
+
githubApprovalRequiredQuestion.choices,
|
|
2273
|
+
process.env.APPROVAL_REQUIRED || (environment_type === "production" ? "true" : "false")
|
|
2274
|
+
)
|
|
2275
|
+
}
|
|
2276
|
+
],
|
|
2277
|
+
existingValues
|
|
2278
|
+
);
|
|
2279
|
+
if (approvalRequired !== "false") {
|
|
2280
|
+
await promptAndStoreAnswer([githubApproversQuestion], existingValues);
|
|
2281
|
+
}
|
|
2282
|
+
log("\n", import_kleur4.default.bold().underline("Two-factor authentication (2FA)"));
|
|
2283
|
+
const existingTwoFaEnabled = findExistingValue(
|
|
2284
|
+
"TWO_FA_ENABLED",
|
|
2285
|
+
"VARIABLE",
|
|
2286
|
+
"ENVIRONMENT",
|
|
2287
|
+
existingValues
|
|
2288
|
+
);
|
|
2289
|
+
const twoFaDefault = process.env.TWO_FA_ENABLED || existingTwoFaEnabled?.value;
|
|
2290
|
+
const two_fa_enabled = await confirm2({
|
|
2291
|
+
message: "Enable two-factor authentication (2FA)? This should be enabled for any environment that hosts PII data.",
|
|
2292
|
+
default: twoFaDefault ? twoFaDefault === "true" : environment_type === "production"
|
|
2293
|
+
});
|
|
2294
|
+
if (!two_fa_enabled && ["production", "staging"].includes(environment_type)) {
|
|
2295
|
+
warn(
|
|
2296
|
+
"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."
|
|
2297
|
+
);
|
|
2298
|
+
}
|
|
2299
|
+
log("\n", import_kleur4.default.bold().underline("Container registry"));
|
|
2300
|
+
await promptAndValidateRegistry(existingValues);
|
|
2068
2301
|
log("\n", import_kleur4.default.bold().underline("Kubernetes & Runtime"));
|
|
2069
2302
|
const infrastructure = await promptAndStoreAnswer(
|
|
2070
2303
|
infrastructureQuestions,
|
|
@@ -2156,6 +2389,14 @@ async function runSetupEnvironment() {
|
|
|
2156
2389
|
);
|
|
2157
2390
|
}
|
|
2158
2391
|
}
|
|
2392
|
+
const existingRustfsHostDataPath = findExistingValue(
|
|
2393
|
+
"RUSTFS_HOST_DATA_PATH",
|
|
2394
|
+
"VARIABLE",
|
|
2395
|
+
"ENVIRONMENT",
|
|
2396
|
+
existingValues
|
|
2397
|
+
);
|
|
2398
|
+
const rustfs_host_data_path = existingRustfsHostDataPath?.value || (environment_exists ? "/data/minio" : "/data/rustfs");
|
|
2399
|
+
const rustfs_pvc_name = rustfs_host_data_path.endsWith("/minio") ? "minio" : "rustfs";
|
|
2159
2400
|
let backupHost = findExistingValue("BACKUP_HOST", "VARIABLE", "ENVIRONMENT", existingValues)?.value || "";
|
|
2160
2401
|
let backupType = "";
|
|
2161
2402
|
let restoreEnvironmentName = findExistingValue(
|
|
@@ -2248,7 +2489,22 @@ async function runSetupEnvironment() {
|
|
|
2248
2489
|
log(import_kleur4.default.bold().green("\u2714"), import_kleur4.default.bold().yellow("Restore is disabled"));
|
|
2249
2490
|
}
|
|
2250
2491
|
log("\n", import_kleur4.default.bold().underline("Monitoring"));
|
|
2251
|
-
|
|
2492
|
+
const existingMonitoringEnabled = findExistingValue(
|
|
2493
|
+
"MONITORING_ENABLED",
|
|
2494
|
+
"VARIABLE",
|
|
2495
|
+
"ENVIRONMENT",
|
|
2496
|
+
existingValues
|
|
2497
|
+
);
|
|
2498
|
+
const monitoringDefault = process.env.MONITORING_ENABLED || existingMonitoringEnabled?.value;
|
|
2499
|
+
const monitoring_enabled = await confirm2({
|
|
2500
|
+
message: "Enable monitoring (Kibana, APM, Filebeat, Metricbeat, Elastalert, OpenTelemetry Collector and tracing)? Disable it if this environment does not need its own monitoring stack.",
|
|
2501
|
+
default: monitoringDefault ? monitoringDefault === "true" : true
|
|
2502
|
+
});
|
|
2503
|
+
if (monitoring_enabled) {
|
|
2504
|
+
await promptAndStoreAnswer(databaseAndMonitoringQuestions, existingValues);
|
|
2505
|
+
} else {
|
|
2506
|
+
log(import_kleur4.default.bold().green("\u2714"), import_kleur4.default.bold().yellow("Monitoring is disabled"));
|
|
2507
|
+
}
|
|
2252
2508
|
const sentryDSNExists = findExistingValue(
|
|
2253
2509
|
"SENTRY_DSN",
|
|
2254
2510
|
"SECRET",
|
|
@@ -2279,9 +2535,7 @@ async function runSetupEnvironment() {
|
|
|
2279
2535
|
return { ...acc, ...answer };
|
|
2280
2536
|
});
|
|
2281
2537
|
const answerOrExisting = (variable, existingValue, fn) => fn(variable || existingValue?.value) || "";
|
|
2282
|
-
|
|
2283
|
-
return findExistingValue(name, type, scope, existingValues) ? null : process.env[name] || newValue;
|
|
2284
|
-
}
|
|
2538
|
+
const findExistingOrDefine = (name, type, scope, newValue) => defineIfMissing(existingValues, name, type, scope, newValue);
|
|
2285
2539
|
const derivedUpdates = [
|
|
2286
2540
|
{
|
|
2287
2541
|
name: "GH_ENCRYPTION_PASSWORD",
|
|
@@ -2318,6 +2572,28 @@ async function runSetupEnvironment() {
|
|
|
2318
2572
|
),
|
|
2319
2573
|
scope: "ENVIRONMENT"
|
|
2320
2574
|
});
|
|
2575
|
+
derivedUpdates.push({
|
|
2576
|
+
name: "TWO_FA_ENABLED",
|
|
2577
|
+
type: "VARIABLE",
|
|
2578
|
+
didExist: existingTwoFaEnabled,
|
|
2579
|
+
// Always stored, so the next run defaults to the current answer
|
|
2580
|
+
value: two_fa_enabled ? "true" : "false",
|
|
2581
|
+
scope: "ENVIRONMENT"
|
|
2582
|
+
});
|
|
2583
|
+
derivedUpdates.push({
|
|
2584
|
+
name: "MONITORING_ENABLED",
|
|
2585
|
+
type: "VARIABLE",
|
|
2586
|
+
didExist: existingMonitoringEnabled,
|
|
2587
|
+
value: monitoring_enabled ? "true" : "false",
|
|
2588
|
+
scope: "ENVIRONMENT"
|
|
2589
|
+
});
|
|
2590
|
+
derivedUpdates.push({
|
|
2591
|
+
name: "RUSTFS_HOST_DATA_PATH",
|
|
2592
|
+
type: "VARIABLE",
|
|
2593
|
+
didExist: existingRustfsHostDataPath,
|
|
2594
|
+
value: rustfs_host_data_path,
|
|
2595
|
+
scope: "ENVIRONMENT"
|
|
2596
|
+
});
|
|
2321
2597
|
derivedUpdates.push(...ssl_answers);
|
|
2322
2598
|
if (configureBackup) {
|
|
2323
2599
|
derivedUpdates.push({
|
|
@@ -2374,16 +2650,16 @@ async function runSetupEnvironment() {
|
|
|
2374
2650
|
scope: "ENVIRONMENT"
|
|
2375
2651
|
},
|
|
2376
2652
|
{
|
|
2377
|
-
name: "
|
|
2653
|
+
name: "S3_ADMIN_ACCESS_KEY",
|
|
2378
2654
|
type: "SECRET",
|
|
2379
2655
|
didExist: findExistingValue(
|
|
2380
|
-
"
|
|
2656
|
+
"S3_ADMIN_ACCESS_KEY",
|
|
2381
2657
|
"SECRET",
|
|
2382
2658
|
"ENVIRONMENT",
|
|
2383
2659
|
existingValues
|
|
2384
2660
|
),
|
|
2385
2661
|
value: findExistingOrDefine(
|
|
2386
|
-
"
|
|
2662
|
+
"S3_ADMIN_ACCESS_KEY",
|
|
2387
2663
|
"SECRET",
|
|
2388
2664
|
"ENVIRONMENT",
|
|
2389
2665
|
generateLongPassword()
|
|
@@ -2391,16 +2667,16 @@ async function runSetupEnvironment() {
|
|
|
2391
2667
|
scope: "ENVIRONMENT"
|
|
2392
2668
|
},
|
|
2393
2669
|
{
|
|
2394
|
-
name: "
|
|
2670
|
+
name: "S3_ADMIN_SECRET_KEY",
|
|
2395
2671
|
type: "SECRET",
|
|
2396
2672
|
didExist: findExistingValue(
|
|
2397
|
-
"
|
|
2673
|
+
"S3_ADMIN_SECRET_KEY",
|
|
2398
2674
|
"SECRET",
|
|
2399
2675
|
"ENVIRONMENT",
|
|
2400
2676
|
existingValues
|
|
2401
2677
|
),
|
|
2402
2678
|
value: findExistingOrDefine(
|
|
2403
|
-
"
|
|
2679
|
+
"S3_ADMIN_SECRET_KEY",
|
|
2404
2680
|
"SECRET",
|
|
2405
2681
|
"ENVIRONMENT",
|
|
2406
2682
|
generateLongPassword()
|
|
@@ -2664,7 +2940,7 @@ async function runSetupEnvironment() {
|
|
|
2664
2940
|
);
|
|
2665
2941
|
const unknownVariables = existingValues.filter((value) => {
|
|
2666
2942
|
return !ALL_QUESTIONS.find(
|
|
2667
|
-
(question) => question.valueLabel === value.name && question.valueType === value.type && question.scope === value.scope
|
|
2943
|
+
(question) => (question.valueLabel === value.name || question.legacyValueLabel === value.name) && question.valueType === value.type && question.scope === value.scope
|
|
2668
2944
|
);
|
|
2669
2945
|
});
|
|
2670
2946
|
log("");
|
|
@@ -2868,6 +3144,9 @@ async function runSetupEnvironment() {
|
|
|
2868
3144
|
env: environment,
|
|
2869
3145
|
environment_type,
|
|
2870
3146
|
two_fa_enabled,
|
|
3147
|
+
monitoring_enabled,
|
|
3148
|
+
rustfs_host_data_path,
|
|
3149
|
+
rustfs_pvc_name,
|
|
2871
3150
|
traefik_mode: traefikConfOption,
|
|
2872
3151
|
restore_enabled: restoreEnvironmentName ? true : false,
|
|
2873
3152
|
restore_environment_name: restoreEnvironmentName || "",
|
|
@@ -2933,6 +3212,7 @@ var init_setup_environment = __esm({
|
|
|
2933
3212
|
init_questions();
|
|
2934
3213
|
init_editor_questions();
|
|
2935
3214
|
init_questions_helper();
|
|
3215
|
+
init_registry();
|
|
2936
3216
|
init_manage_users();
|
|
2937
3217
|
init_paths();
|
|
2938
3218
|
ALL_QUESTIONS = [];
|
|
@@ -2940,7 +3220,7 @@ var init_setup_environment = __esm({
|
|
|
2940
3220
|
ALL_QUESTIONS.push(
|
|
2941
3221
|
...githubTokenQuestion,
|
|
2942
3222
|
...githubOtherQuestions,
|
|
2943
|
-
...
|
|
3223
|
+
...registryQuestions,
|
|
2944
3224
|
...diskQuestions,
|
|
2945
3225
|
...infrastructureQuestions,
|
|
2946
3226
|
...backupQuestions,
|
|
@@ -2960,17 +3240,17 @@ __export(upgrade_exports, {
|
|
|
2960
3240
|
upgradeEnvironmentLayout: () => upgradeEnvironmentLayout
|
|
2961
3241
|
});
|
|
2962
3242
|
function moveFileIfDestinationMissing(sourcePath, destinationPath) {
|
|
2963
|
-
if (!(0,
|
|
3243
|
+
if (!(0, import_fs7.existsSync)(sourcePath)) {
|
|
2964
3244
|
return false;
|
|
2965
3245
|
}
|
|
2966
|
-
if ((0,
|
|
3246
|
+
if ((0, import_fs7.existsSync)(destinationPath)) {
|
|
2967
3247
|
warn(
|
|
2968
3248
|
`\u26A0\uFE0F Skipped ${sourcePath}; destination already exists at ${destinationPath}`
|
|
2969
3249
|
);
|
|
2970
3250
|
return false;
|
|
2971
3251
|
}
|
|
2972
|
-
(0,
|
|
2973
|
-
(0,
|
|
3252
|
+
(0, import_fs7.mkdirSync)((0, import_path13.dirname)(destinationPath), { recursive: true });
|
|
3253
|
+
(0, import_fs7.renameSync)(sourcePath, destinationPath);
|
|
2974
3254
|
log(` \u2713 Moved ${sourcePath} -> ${destinationPath}`);
|
|
2975
3255
|
return true;
|
|
2976
3256
|
}
|
|
@@ -2990,8 +3270,8 @@ function migrateInventoryFiles() {
|
|
|
2990
3270
|
) || didMoveInventory;
|
|
2991
3271
|
}
|
|
2992
3272
|
try {
|
|
2993
|
-
if ((0,
|
|
2994
|
-
(0,
|
|
3273
|
+
if ((0, import_fs7.existsSync)(OLD_INVENTORY_DIR) && (0, import_fs7.readdirSync)(OLD_INVENTORY_DIR).length === 0) {
|
|
3274
|
+
(0, import_fs7.rmdirSync)(OLD_INVENTORY_DIR);
|
|
2995
3275
|
log(` \u2713 Removed empty ${OLD_INVENTORY_DIR}`);
|
|
2996
3276
|
}
|
|
2997
3277
|
} catch {
|
|
@@ -3009,12 +3289,12 @@ async function upgradeEnvironmentLayout() {
|
|
|
3009
3289
|
}
|
|
3010
3290
|
log("\nCommit changes into git after upgrade");
|
|
3011
3291
|
}
|
|
3012
|
-
var
|
|
3292
|
+
var import_fs7, import_path13, import_kleur5;
|
|
3013
3293
|
var init_upgrade = __esm({
|
|
3014
3294
|
"src/environment/upgrade.ts"() {
|
|
3015
3295
|
"use strict";
|
|
3016
|
-
|
|
3017
|
-
|
|
3296
|
+
import_fs7 = require("fs");
|
|
3297
|
+
import_path13 = require("path");
|
|
3018
3298
|
import_kleur5 = __toESM(require("kleur"));
|
|
3019
3299
|
init_logger();
|
|
3020
3300
|
init_paths();
|
|
@@ -3032,16 +3312,16 @@ async function select4(options) {
|
|
|
3032
3312
|
return inquirer.select(options);
|
|
3033
3313
|
}
|
|
3034
3314
|
async function selectInventoryFile(dirPath = "./environments") {
|
|
3035
|
-
if (!
|
|
3315
|
+
if (!fs6.existsSync(dirPath)) {
|
|
3036
3316
|
warn(`\u26A0\uFE0F No environment configuration directory found at ${dirPath}`);
|
|
3037
3317
|
warn(
|
|
3038
3318
|
"Hint: If this is a new infrastructure repository, run `opencrvs environment init` first."
|
|
3039
3319
|
);
|
|
3040
3320
|
return null;
|
|
3041
3321
|
}
|
|
3042
|
-
const environments =
|
|
3322
|
+
const environments = fs6.readdirSync(dirPath).filter((entry) => {
|
|
3043
3323
|
const filePath = path12.join(dirPath, entry);
|
|
3044
|
-
return
|
|
3324
|
+
return fs6.statSync(filePath).isDirectory() && fs6.existsSync(getEnvironmentInventoryPath(entry));
|
|
3045
3325
|
}).sort();
|
|
3046
3326
|
if (environments.length === 0) {
|
|
3047
3327
|
warn(`\u26A0\uFE0F No environment configuration files found at ${dirPath}`);
|
|
@@ -3068,11 +3348,11 @@ async function manageEnvironmentUsers() {
|
|
|
3068
3348
|
}
|
|
3069
3349
|
await manageUsers(inventory_file);
|
|
3070
3350
|
}
|
|
3071
|
-
var
|
|
3351
|
+
var fs6, path12, import_kleur6;
|
|
3072
3352
|
var init_users = __esm({
|
|
3073
3353
|
"src/environment/users.ts"() {
|
|
3074
3354
|
"use strict";
|
|
3075
|
-
|
|
3355
|
+
fs6 = __toESM(require("fs"));
|
|
3076
3356
|
path12 = __toESM(require("path"));
|
|
3077
3357
|
import_kleur6 = __toESM(require("kleur"));
|
|
3078
3358
|
init_manage_users();
|
|
@@ -3260,187 +3540,12 @@ var init_swarm_to_k8s = __esm({
|
|
|
3260
3540
|
}
|
|
3261
3541
|
});
|
|
3262
3542
|
|
|
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
|
-
}
|
|
3543
|
+
// src/cli.ts
|
|
3544
|
+
var import_fs9 = __toESM(require("fs"));
|
|
3545
|
+
var import_path15 = __toESM(require("path"));
|
|
3439
3546
|
|
|
3440
|
-
// src/migrations/
|
|
3441
|
-
var
|
|
3442
|
-
var import_fs2 = require("fs");
|
|
3443
|
-
var import_path2 = __toESM(require("path"));
|
|
3547
|
+
// src/migrations/persistent/add-translations.ts
|
|
3548
|
+
var import_path = __toESM(require("path"));
|
|
3444
3549
|
|
|
3445
3550
|
// src/csv.ts
|
|
3446
3551
|
var import_fs = require("fs");
|
|
@@ -3482,20 +3587,20 @@ function idOf(line2) {
|
|
|
3482
3587
|
const comma = line2.indexOf(",");
|
|
3483
3588
|
return comma === -1 ? line2 : line2.slice(0, comma);
|
|
3484
3589
|
}
|
|
3485
|
-
function readCsvFile(
|
|
3486
|
-
if (!(0, import_fs.existsSync)(
|
|
3590
|
+
function readCsvFile(path15) {
|
|
3591
|
+
if (!(0, import_fs.existsSync)(path15)) {
|
|
3487
3592
|
return void 0;
|
|
3488
3593
|
}
|
|
3489
|
-
const contents = (0, import_fs.readFileSync)(
|
|
3594
|
+
const contents = (0, import_fs.readFileSync)(path15, "utf8");
|
|
3490
3595
|
const newline = contents.includes("\r\n") ? "\r\n" : "\n";
|
|
3491
3596
|
const trailingNewline = /\r?\n$/.test(contents);
|
|
3492
3597
|
const lines = contents.replace(/\r?\n$/, "").split(/\r?\n/);
|
|
3493
3598
|
const body = lines.slice(1).filter((line2) => line2 !== "");
|
|
3494
3599
|
return { header: lines[0], body, newline, trailingNewline };
|
|
3495
3600
|
}
|
|
3496
|
-
function writeCsvFile(
|
|
3601
|
+
function writeCsvFile(path15, file) {
|
|
3497
3602
|
(0, import_fs.writeFileSync)(
|
|
3498
|
-
|
|
3603
|
+
path15,
|
|
3499
3604
|
[file.header, ...file.body].join(file.newline) + (file.trailingNewline ? file.newline : "")
|
|
3500
3605
|
);
|
|
3501
3606
|
}
|
|
@@ -3509,464 +3614,17 @@ function addRows(file, rows) {
|
|
|
3509
3614
|
if (file.body.some((line2) => idOf(line2) === id)) {
|
|
3510
3615
|
continue;
|
|
3511
3616
|
}
|
|
3512
|
-
const
|
|
3513
|
-
if (
|
|
3617
|
+
const insertAt2 = isSorted ? file.body.findIndex((line2) => idOf(line2) > id) : -1;
|
|
3618
|
+
if (insertAt2 === -1) {
|
|
3514
3619
|
file.body.push(row);
|
|
3515
3620
|
} else {
|
|
3516
|
-
file.body.splice(
|
|
3621
|
+
file.body.splice(insertAt2, 0, row);
|
|
3517
3622
|
}
|
|
3518
3623
|
added.push(id);
|
|
3519
3624
|
}
|
|
3520
3625
|
return added;
|
|
3521
3626
|
}
|
|
3522
3627
|
|
|
3523
|
-
// src/migrations/v2.1/add-recovery-link-notifications.ts
|
|
3524
|
-
var EMAIL_TEMPLATES_FILE = "src/api/notification/email-templates/index.ts";
|
|
3525
|
-
var SMS_SERVICE_FILE = "src/api/notification/sms-service.ts";
|
|
3526
|
-
var HANDLER_FILE = "src/api/notification/handler.ts";
|
|
3527
|
-
var ROUTES_FILE = "src/config/routes/userNotificationRoutes.ts";
|
|
3528
|
-
var EMAIL_TEMPLATE_DIR = "src/api/notification/email-templates/other";
|
|
3529
|
-
var NOTIFICATION_CSV = "src/translations/notification.csv";
|
|
3530
|
-
var LOGIN_CSV = "src/translations/login.csv";
|
|
3531
|
-
var TRIGGER_VARIABLE_OBJECT = "TriggerVariable";
|
|
3532
|
-
var TEMPLATES_OBJECT = "templates";
|
|
3533
|
-
var OTHER_TEMPLATES_OBJECT = "otherTemplates";
|
|
3534
|
-
var TRIGGER_TO_SMS_TEMPLATE_OBJECT = "TriggerToSMSTemplate";
|
|
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"
|
|
3557
|
-
}
|
|
3558
|
-
];
|
|
3559
|
-
var NOTIFICATION_CSV_ROWS = [
|
|
3560
|
-
`resetPasswordLinkNotification,The SMS message that is sent to a user containing a self-service password reset link,{{applicationName}}: reset your password using this link. It expires in 1 hour. {{{recoveryURL}}},{{applicationName}} : r\xE9initialisez votre mot de passe \xE0 l'aide de ce lien. Il expire dans 1 heure. {{{recoveryURL}}}`,
|
|
3561
|
-
`retrieveUsernameLinkNotification,The SMS message that is sent to a user containing a self-service username retrieval link,{{applicationName}}: retrieve your username using this link. It expires in 1 hour. {{{recoveryURL}}},{{applicationName}} : r\xE9cup\xE9rez votre nom d'utilisateur \xE0 l'aide de ce lien. Il expire dans 1 heure. {{{recoveryURL}}}`
|
|
3562
|
-
];
|
|
3563
|
-
var LOGIN_CSV_ROWS = [
|
|
3564
|
-
`buttons.backToLogin,"Label used to leave a screen that is waiting on an emailed link, where logging in is not yet possible",Back to login,Retour \xE0 la connexion`,
|
|
3565
|
-
`resetCredentials.recoveryInstructionsSent.body,"Body message for the recovery instructions sent page. Must not assert delivery, since the account may not exist.","If we found an account, you'll receive instructions for {forgottenItem, select, username {retrieving your username} other {resetting your password}}. The link expires in 1 hour.","Si nous trouvons un compte correspondant, vous recevrez les instructions pour {forgottenItem, select, username {r\xE9cup\xE9rer votre nom d'utilisateur} other {r\xE9initialiser votre mot de passe}}. Le lien expire dans 1 heure."`,
|
|
3566
|
-
`resetCredentials.recoveryInstructionsSent.title.email,Title for the recovery instructions sent page when notifications are delivered by email,Check your email,V\xE9rifiez votre e-mail`,
|
|
3567
|
-
`resetCredentials.recoveryInstructionsSent.title.phone,Title for the recovery instructions sent page when notifications are delivered by SMS,Check your phone,V\xE9rifiez votre t\xE9l\xE9phone`,
|
|
3568
|
-
`resetCredentials.recoveryLinkLanding.expired.body,"Body shown when a recovery link is invalid, expired, or already used. Must not reveal whether the underlying account exists.",This link is no longer valid. Request a new one to continue.,Ce lien n'est plus valide. Veuillez en demander un nouveau pour continuer.`,
|
|
3569
|
-
`resetCredentials.recoveryLinkLanding.expired.link,Link back to the forgotten item form shown on an expired/invalid recovery link,Start again,Recommencer`,
|
|
3570
|
-
`resetCredentials.recoveryLinkLanding.expired.title,"Title shown when a recovery link is invalid, expired, or already used",This link has expired,Ce lien a expir\xE9`
|
|
3571
|
-
];
|
|
3572
|
-
var skipped = [];
|
|
3573
|
-
function warnSkipped(message) {
|
|
3574
|
-
skipped.push(message);
|
|
3575
|
-
console.warn(` \u26A0\uFE0F ${message}`);
|
|
3576
|
-
}
|
|
3577
|
-
function findObjectLiteral(declaration) {
|
|
3578
|
-
let expression = declaration?.getInitializer();
|
|
3579
|
-
while (expression && (import_ts_morph2.Node.isAsExpression(expression) || import_ts_morph2.Node.isSatisfiesExpression(expression))) {
|
|
3580
|
-
expression = expression.getExpression();
|
|
3581
|
-
}
|
|
3582
|
-
return expression && import_ts_morph2.Node.isObjectLiteralExpression(expression) ? expression : void 0;
|
|
3583
|
-
}
|
|
3584
|
-
function hasKeyFor(obj, key, constant) {
|
|
3585
|
-
const accepted = /* @__PURE__ */ new Set([
|
|
3586
|
-
`[TriggerEvent.${constant}]`,
|
|
3587
|
-
`['${key}']`,
|
|
3588
|
-
`["${key}"]`,
|
|
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}'`;
|
|
3625
|
-
}
|
|
3626
|
-
function updateEmailTemplates(project, cwd) {
|
|
3627
|
-
const sourceFile = project.getSourceFile(import_path2.default.join(cwd, EMAIL_TEMPLATES_FILE));
|
|
3628
|
-
if (!sourceFile) {
|
|
3629
|
-
warnSkipped(`${EMAIL_TEMPLATES_FILE} not found; email templates not wired`);
|
|
3630
|
-
return;
|
|
3631
|
-
}
|
|
3632
|
-
const missingObject = [TRIGGER_VARIABLE_OBJECT, TEMPLATES_OBJECT].find(
|
|
3633
|
-
(objectName) => !findObjectLiteral(sourceFile.getVariableDeclaration(objectName))
|
|
3634
|
-
);
|
|
3635
|
-
if (missingObject) {
|
|
3636
|
-
warnSkipped(
|
|
3637
|
-
`Could not find '${missingObject}' in ${EMAIL_TEMPLATES_FILE}; email templates not wired`
|
|
3638
|
-
);
|
|
3639
|
-
return;
|
|
3640
|
-
}
|
|
3641
|
-
for (const event of RECOVERY_EVENTS) {
|
|
3642
|
-
if (!objectHasKeyFor(
|
|
3643
|
-
sourceFile,
|
|
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`);
|
|
3694
|
-
return;
|
|
3695
|
-
}
|
|
3696
|
-
const missingObject = [
|
|
3697
|
-
OTHER_TEMPLATES_OBJECT,
|
|
3698
|
-
TRIGGER_TO_SMS_TEMPLATE_OBJECT
|
|
3699
|
-
].find(
|
|
3700
|
-
(objectName) => !findObjectLiteral(sourceFile.getVariableDeclaration(objectName))
|
|
3701
|
-
);
|
|
3702
|
-
if (missingObject) {
|
|
3703
|
-
warnSkipped(
|
|
3704
|
-
`Could not find '${missingObject}' in ${SMS_SERVICE_FILE}; SMS templates not wired`
|
|
3705
|
-
);
|
|
3706
|
-
return;
|
|
3707
|
-
}
|
|
3708
|
-
for (const event of RECOVERY_EVENTS) {
|
|
3709
|
-
if (!objectHasKeyFor(
|
|
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
3628
|
// src/translations/template.ts
|
|
3971
3629
|
var REPOSITORY = "opencrvs/opencrvs-core";
|
|
3972
3630
|
var TEMPLATE_TRANSLATIONS = "packages/countryconfig-template/src/translations";
|
|
@@ -4007,12 +3665,11 @@ async function fetchTemplate(refs, application) {
|
|
|
4007
3665
|
return void 0;
|
|
4008
3666
|
}
|
|
4009
3667
|
|
|
4010
|
-
// src/migrations/
|
|
3668
|
+
// src/migrations/persistent/add-translations.ts
|
|
4011
3669
|
var APPLICATIONS = ["client", "login"];
|
|
4012
|
-
var
|
|
4013
|
-
|
|
4014
|
-
|
|
4015
|
-
skipped2.push(message);
|
|
3670
|
+
var skipped = [];
|
|
3671
|
+
function warnSkipped(message) {
|
|
3672
|
+
skipped.push(message);
|
|
4016
3673
|
console.warn(` \u26A0\uFE0F ${message}`);
|
|
4017
3674
|
}
|
|
4018
3675
|
function rowsToAdd(local, template) {
|
|
@@ -4028,17 +3685,17 @@ function rowsToAdd(local, template) {
|
|
|
4028
3685
|
);
|
|
4029
3686
|
});
|
|
4030
3687
|
}
|
|
4031
|
-
async function updateApplication(cwd, refs, application) {
|
|
3688
|
+
async function updateApplication(cwd, targetVersion, refs, application) {
|
|
4032
3689
|
const relativePath = `src/translations/${application}.csv`;
|
|
4033
|
-
const local = readCsvFile(
|
|
3690
|
+
const local = readCsvFile(import_path.default.join(cwd, relativePath));
|
|
4034
3691
|
if (!local) {
|
|
4035
|
-
|
|
3692
|
+
warnSkipped(`${relativePath} not found; translations not added`);
|
|
4036
3693
|
return;
|
|
4037
3694
|
}
|
|
4038
3695
|
const fetched = await fetchTemplate(refs, application);
|
|
4039
3696
|
if (!fetched) {
|
|
4040
|
-
|
|
4041
|
-
`No ${application}.csv found in the ${
|
|
3697
|
+
warnSkipped(
|
|
3698
|
+
`No ${application}.csv found in the ${targetVersion} country config template on GitHub; ${application}.csv not updated`
|
|
4042
3699
|
);
|
|
4043
3700
|
return;
|
|
4044
3701
|
}
|
|
@@ -4048,10 +3705,10 @@ async function updateApplication(cwd, refs, application) {
|
|
|
4048
3705
|
return;
|
|
4049
3706
|
}
|
|
4050
3707
|
try {
|
|
4051
|
-
writeCsvFile(
|
|
4052
|
-
} catch (
|
|
4053
|
-
|
|
4054
|
-
`Could not write ${relativePath} (${
|
|
3708
|
+
writeCsvFile(import_path.default.join(cwd, relativePath), local);
|
|
3709
|
+
} catch (error2) {
|
|
3710
|
+
warnSkipped(
|
|
3711
|
+
`Could not write ${relativePath} (${error2.message}); translations not added`
|
|
4055
3712
|
);
|
|
4056
3713
|
return;
|
|
4057
3714
|
}
|
|
@@ -4068,1331 +3725,1138 @@ function readTemplate(contents) {
|
|
|
4068
3725
|
trailingNewline: true
|
|
4069
3726
|
};
|
|
4070
3727
|
}
|
|
4071
|
-
async function listRefs() {
|
|
3728
|
+
async function listRefs(targetVersion) {
|
|
4072
3729
|
try {
|
|
4073
|
-
return await candidateRefs(
|
|
4074
|
-
} catch (
|
|
4075
|
-
|
|
4076
|
-
`Could not list the ${
|
|
3730
|
+
return await candidateRefs(targetVersion);
|
|
3731
|
+
} catch (error2) {
|
|
3732
|
+
warnSkipped(
|
|
3733
|
+
`Could not list the ${targetVersion} refs on GitHub (${error2.message}); translations not added`
|
|
4077
3734
|
);
|
|
4078
3735
|
return void 0;
|
|
4079
3736
|
}
|
|
4080
3737
|
}
|
|
4081
|
-
async function
|
|
3738
|
+
async function main(targetVersion) {
|
|
4082
3739
|
const cwd = process.cwd();
|
|
4083
3740
|
console.log("Adding the translation keys core gained this version...\n");
|
|
4084
|
-
const refs = await listRefs();
|
|
3741
|
+
const refs = await listRefs(targetVersion);
|
|
4085
3742
|
if (refs) {
|
|
4086
3743
|
for (const application of APPLICATIONS) {
|
|
4087
3744
|
try {
|
|
4088
|
-
await updateApplication(cwd, refs, application);
|
|
4089
|
-
} catch (
|
|
4090
|
-
|
|
4091
|
-
`Could not read ${application}.csv from the country config template on GitHub (${
|
|
3745
|
+
await updateApplication(cwd, targetVersion, refs, application);
|
|
3746
|
+
} catch (error2) {
|
|
3747
|
+
warnSkipped(
|
|
3748
|
+
`Could not read ${application}.csv from the country config template on GitHub (${error2.message}); ${application}.csv not updated`
|
|
4092
3749
|
);
|
|
4093
3750
|
}
|
|
4094
3751
|
}
|
|
4095
3752
|
}
|
|
4096
|
-
if (
|
|
3753
|
+
if (skipped.length > 0) {
|
|
4097
3754
|
console.warn(
|
|
4098
3755
|
`
|
|
4099
|
-
\u26A0\uFE0F ${
|
|
3756
|
+
\u26A0\uFE0F ${skipped.length} step(s) were skipped. Add the missing translations by hand before upgrading:`
|
|
4100
3757
|
);
|
|
4101
|
-
for (const message of
|
|
3758
|
+
for (const message of skipped) {
|
|
4102
3759
|
console.warn(` - ${message}`);
|
|
4103
3760
|
}
|
|
4104
3761
|
}
|
|
4105
3762
|
}
|
|
4106
3763
|
|
|
4107
|
-
// src/migrations/
|
|
4108
|
-
var
|
|
4109
|
-
var
|
|
4110
|
-
var import_path4 = __toESM(require("path"));
|
|
4111
|
-
var HANDLER_FILE2 = "src/api/telemetry/handler.ts";
|
|
4112
|
-
var ENVIRONMENT_FILE = "src/environment.ts";
|
|
4113
|
-
var INDEX_FILE = "src/index.ts";
|
|
4114
|
-
var HANDLER_MODULE = "./api/telemetry/handler";
|
|
4115
|
-
var skipped3 = [];
|
|
4116
|
-
function warnSkipped3(message) {
|
|
4117
|
-
skipped3.push(message);
|
|
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
|
-
})
|
|
3764
|
+
// src/migrations/move-declaration-to-declare-action.ts
|
|
3765
|
+
var import_ts_morph2 = require("ts-morph");
|
|
3766
|
+
var import_path3 = __toESM(require("path"));
|
|
4149
3767
|
|
|
4150
|
-
|
|
4151
|
-
|
|
4152
|
-
|
|
4153
|
-
|
|
3768
|
+
// src/migrations/utils.ts
|
|
3769
|
+
var import_ts_morph = require("ts-morph");
|
|
3770
|
+
var import_path2 = __toESM(require("path"));
|
|
3771
|
+
var DEFINE_CONFIG_NAME = "defineConfig";
|
|
3772
|
+
var TOOLKIT_EVENTS_MODULE = "@opencrvs/toolkit/events";
|
|
3773
|
+
function location(node) {
|
|
3774
|
+
const relPath = import_path2.default.relative(
|
|
3775
|
+
process.cwd(),
|
|
3776
|
+
node.getSourceFile().getFilePath()
|
|
3777
|
+
);
|
|
3778
|
+
return `${relPath}:${node.getStartLineNumber()}`;
|
|
4154
3779
|
}
|
|
4155
|
-
|
|
4156
|
-
|
|
4157
|
-
|
|
4158
|
-
|
|
4159
|
-
|
|
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)
|
|
3780
|
+
function isToolkitDefineConfigCall(call) {
|
|
3781
|
+
const symbol = call.getExpression().getSymbol();
|
|
3782
|
+
const resolved = symbol?.getAliasedSymbol() ?? symbol;
|
|
3783
|
+
if (resolved?.getName() !== DEFINE_CONFIG_NAME) {
|
|
3784
|
+
return false;
|
|
4188
3785
|
}
|
|
4189
|
-
|
|
4190
|
-
|
|
4191
|
-
|
|
4192
|
-
|
|
4193
|
-
|
|
4194
|
-
|
|
4195
|
-
|
|
4196
|
-
|
|
4197
|
-
|
|
4198
|
-
|
|
4199
|
-
return h.response({ status: 'skipped' }).code(200)
|
|
3786
|
+
return resolved.getDeclarations().some((declaration) => declaration.getSourceFile().isDeclarationFile());
|
|
3787
|
+
}
|
|
3788
|
+
function findProperty(literal, name) {
|
|
3789
|
+
const property = literal.getProperty(name);
|
|
3790
|
+
return import_ts_morph.Node.isPropertyAssignment(property) || import_ts_morph.Node.isShorthandPropertyAssignment(property) ? property : void 0;
|
|
3791
|
+
}
|
|
3792
|
+
function mayHaveActionType(actionType, node, expectedActionType) {
|
|
3793
|
+
const typeProperty = actionType.getProperty("type");
|
|
3794
|
+
if (!typeProperty) {
|
|
3795
|
+
return true;
|
|
4200
3796
|
}
|
|
4201
|
-
|
|
4202
|
-
const
|
|
4203
|
-
|
|
4204
|
-
|
|
4205
|
-
|
|
4206
|
-
|
|
4207
|
-
|
|
4208
|
-
|
|
4209
|
-
|
|
4210
|
-
application_name: applicationConfig.APPLICATION_NAME,
|
|
4211
|
-
environment: env.ENVIRONMENT_NAME,
|
|
4212
|
-
app_version: incoming.app_version
|
|
4213
|
-
},
|
|
4214
|
-
metrics: incoming.metrics
|
|
3797
|
+
const type = typeProperty.getTypeAtLocation(node);
|
|
3798
|
+
const values = type.isUnion() ? type.getUnionTypes() : [type];
|
|
3799
|
+
return !values.every(
|
|
3800
|
+
(value) => value.isStringLiteral() && value.getLiteralValue() !== expectedActionType
|
|
3801
|
+
);
|
|
3802
|
+
}
|
|
3803
|
+
function mayBeAction(node, actionType) {
|
|
3804
|
+
if (import_ts_morph.Node.isObjectLiteralExpression(node)) {
|
|
3805
|
+
return isAction(node, actionType);
|
|
4215
3806
|
}
|
|
4216
|
-
|
|
4217
|
-
|
|
4218
|
-
|
|
4219
|
-
|
|
4220
|
-
|
|
4221
|
-
|
|
4222
|
-
logger.error(\`Telemetry: forwarding to status service failed: \${message}\`)
|
|
4223
|
-
return h.response({ status: 'error' }).code(502)
|
|
3807
|
+
if (import_ts_morph.Node.isSpreadElement(node)) {
|
|
3808
|
+
const arrayType = node.getExpression().getType();
|
|
3809
|
+
const elementTypes = arrayType.isTuple() ? arrayType.getTupleElements() : [arrayType.getArrayElementType()];
|
|
3810
|
+
return elementTypes.some(
|
|
3811
|
+
(elementType) => !elementType || mayHaveActionType(elementType, node, actionType)
|
|
3812
|
+
);
|
|
4224
3813
|
}
|
|
4225
|
-
|
|
4226
|
-
|
|
4227
|
-
|
|
4228
|
-
|
|
4229
|
-
|
|
4230
|
-
|
|
3814
|
+
return mayHaveActionType(node.getType(), node, actionType);
|
|
3815
|
+
}
|
|
3816
|
+
function isAction(literal, actionType) {
|
|
3817
|
+
const type = findProperty(literal, "type");
|
|
3818
|
+
return import_ts_morph.Node.isPropertyAssignment(type) && type.getInitializerOrThrow().getType().getLiteralValue() === actionType;
|
|
3819
|
+
}
|
|
3820
|
+
function indentationOf(node) {
|
|
3821
|
+
const text = node.getSourceFile().getFullText();
|
|
3822
|
+
const lineStart = text.lastIndexOf("\n", node.getStart() - 1) + 1;
|
|
3823
|
+
return /^[ \t]*/.exec(text.slice(lineStart))?.[0] ?? "";
|
|
3824
|
+
}
|
|
3825
|
+
function restOfLine(text, position) {
|
|
3826
|
+
const lineEnd = text.indexOf("\n", position);
|
|
3827
|
+
return text.slice(position, lineEnd === -1 ? text.length : lineEnd);
|
|
3828
|
+
}
|
|
3829
|
+
function isOnlyComments(text) {
|
|
3830
|
+
return /^\s*(?:\/\/.*|\/\*.*?\*\/\s*)*$/.test(text);
|
|
3831
|
+
}
|
|
3832
|
+
function layoutOf(property) {
|
|
3833
|
+
const text = property.getSourceFile().getFullText();
|
|
3834
|
+
const next = property.getNextSibling();
|
|
3835
|
+
const hasComma = next?.getKind() === import_ts_morph.SyntaxKind.CommaToken;
|
|
3836
|
+
const end = next && hasComma ? next.getEnd() : property.getEnd();
|
|
3837
|
+
const trailing = restOfLine(text, end);
|
|
3838
|
+
const lineBreak = text.slice(property.getFullStart(), property.getStart()).indexOf("\n");
|
|
3839
|
+
if (lineBreak === -1 || !isOnlyComments(trailing)) {
|
|
3840
|
+
return {
|
|
3841
|
+
ownsLines: false,
|
|
3842
|
+
start: property.getStart(true),
|
|
3843
|
+
end,
|
|
3844
|
+
hasComma,
|
|
3845
|
+
trailingComment: ""
|
|
3846
|
+
};
|
|
4231
3847
|
}
|
|
4232
|
-
|
|
4233
|
-
|
|
4234
|
-
|
|
4235
|
-
|
|
4236
|
-
|
|
3848
|
+
const firstLine = property.getFullStart() + lineBreak + 1;
|
|
3849
|
+
return {
|
|
3850
|
+
ownsLines: true,
|
|
3851
|
+
start: firstLine + (/^\s*/.exec(text.slice(firstLine))?.[0].length ?? 0),
|
|
3852
|
+
end,
|
|
3853
|
+
hasComma,
|
|
3854
|
+
trailingComment: trailing.trimEnd()
|
|
3855
|
+
};
|
|
4237
3856
|
}
|
|
4238
|
-
|
|
4239
|
-
|
|
4240
|
-
|
|
4241
|
-
|
|
4242
|
-
|
|
4243
|
-
|
|
4244
|
-
|
|
4245
|
-
|
|
4246
|
-
|
|
3857
|
+
function insertAt(position, text) {
|
|
3858
|
+
return { start: position, end: position, text };
|
|
3859
|
+
}
|
|
3860
|
+
function applyTextEdits(sourceFile, edits) {
|
|
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
|
+
}
|
|
3867
|
+
function findToolkitImport(sourceFile) {
|
|
3868
|
+
return sourceFile.getImportDeclaration(
|
|
3869
|
+
(declaration) => declaration.getModuleSpecifierValue() === TOOLKIT_EVENTS_MODULE && !declaration.isTypeOnly() && !declaration.getNamespaceImport()
|
|
3870
|
+
);
|
|
3871
|
+
}
|
|
3872
|
+
function findToolkitImportName(sourceFile, name) {
|
|
3873
|
+
const imported = findToolkitImport(sourceFile)?.getNamedImports().find((namedImport) => namedImport.getName() === name);
|
|
3874
|
+
if (imported) {
|
|
3875
|
+
return imported.getAliasNode()?.getText() ?? name;
|
|
4247
3876
|
}
|
|
4248
|
-
|
|
4249
|
-
|
|
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;
|
|
3877
|
+
if (sourceFile.getLocal(name)) {
|
|
3878
|
+
return void 0;
|
|
4271
3879
|
}
|
|
4272
|
-
|
|
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;
|
|
3880
|
+
return name;
|
|
4285
3881
|
}
|
|
4286
|
-
function
|
|
4287
|
-
const
|
|
4288
|
-
if (!
|
|
4289
|
-
|
|
4290
|
-
|
|
3882
|
+
function addToolkitImport(sourceFile, name) {
|
|
3883
|
+
const toolkitImport = findToolkitImport(sourceFile);
|
|
3884
|
+
if (!toolkitImport) {
|
|
3885
|
+
const imports = sourceFile.getImportDeclarations();
|
|
3886
|
+
const lastImport = imports[imports.length - 1];
|
|
3887
|
+
sourceFile.insertStatements(
|
|
3888
|
+
lastImport ? lastImport.getChildIndex() + 1 : 0,
|
|
3889
|
+
`import { ${name} } from '${TOOLKIT_EVENTS_MODULE}'`
|
|
4291
3890
|
);
|
|
4292
3891
|
return;
|
|
4293
3892
|
}
|
|
4294
|
-
const
|
|
4295
|
-
|
|
3893
|
+
const alreadyImported = toolkitImport.getNamedImports().some((namedImport) => namedImport.getName() === name);
|
|
3894
|
+
if (alreadyImported) {
|
|
3895
|
+
return;
|
|
3896
|
+
}
|
|
3897
|
+
const namedImports = toolkitImport.getNamedImports();
|
|
3898
|
+
if (toolkitImport.getDefaultImport() || namedImports.length === 0) {
|
|
3899
|
+
toolkitImport.addNamedImport(name);
|
|
3900
|
+
return;
|
|
3901
|
+
}
|
|
3902
|
+
const names = [
|
|
3903
|
+
...namedImports.map((namedImport) => namedImport.getText()),
|
|
3904
|
+
name
|
|
3905
|
+
];
|
|
3906
|
+
const specifiers = toolkitImport.getText().includes("\n") ? `{
|
|
3907
|
+
${names.join(",\n ")}
|
|
3908
|
+
}` : `{ ${names.join(", ")} }`;
|
|
3909
|
+
toolkitImport.replaceWithText(
|
|
3910
|
+
`import ${specifiers} from '${TOOLKIT_EVENTS_MODULE}'`
|
|
4296
3911
|
);
|
|
4297
|
-
|
|
4298
|
-
|
|
4299
|
-
|
|
3912
|
+
}
|
|
3913
|
+
|
|
3914
|
+
// src/migrations/move-declaration-to-declare-action.ts
|
|
3915
|
+
var DEFINE_CONFIG_NAME2 = "defineConfig";
|
|
3916
|
+
var DECLARATION_PROPERTY_NAME = "declaration";
|
|
3917
|
+
var ACTIONS_PROPERTY_NAME = "actions";
|
|
3918
|
+
var DECLARE_ACTION_TYPE = "DECLARE";
|
|
3919
|
+
function findDeclareAction(config) {
|
|
3920
|
+
const actions = findProperty(config, ACTIONS_PROPERTY_NAME);
|
|
3921
|
+
const actionsValue = import_ts_morph2.Node.isPropertyAssignment(actions) ? actions.getInitializer() : void 0;
|
|
3922
|
+
if (!import_ts_morph2.Node.isArrayLiteralExpression(actionsValue)) {
|
|
3923
|
+
console.warn(
|
|
3924
|
+
` [${location(config)}] Skipped: \`${ACTIONS_PROPERTY_NAME}\` is not an array literal. Move \`${DECLARATION_PROPERTY_NAME}\` onto the ${DECLARE_ACTION_TYPE} action by hand.`
|
|
3925
|
+
);
|
|
3926
|
+
return void 0;
|
|
3927
|
+
}
|
|
3928
|
+
const candidates = actionsValue.getElements().filter((element) => mayBeAction(element, DECLARE_ACTION_TYPE));
|
|
3929
|
+
if (candidates.length !== 1 || !import_ts_morph2.Node.isObjectLiteralExpression(candidates[0])) {
|
|
3930
|
+
console.warn(
|
|
3931
|
+
` [${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.`
|
|
3932
|
+
);
|
|
3933
|
+
return void 0;
|
|
3934
|
+
}
|
|
3935
|
+
const declareAction = candidates[0];
|
|
3936
|
+
if (findProperty(declareAction, DECLARATION_PROPERTY_NAME)) {
|
|
3937
|
+
console.warn(
|
|
3938
|
+
` [${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.`
|
|
3939
|
+
);
|
|
3940
|
+
return void 0;
|
|
3941
|
+
}
|
|
3942
|
+
return declareAction;
|
|
3943
|
+
}
|
|
3944
|
+
function insertIntoDeclareAction(declareAction, property) {
|
|
3945
|
+
const anchor = declareAction.getProperty("label") ?? declareAction.getPropertyOrThrow("type");
|
|
3946
|
+
const text = property.getSourceFile().getFullText();
|
|
3947
|
+
const anchorLayout = layoutOf(anchor);
|
|
3948
|
+
const layout = layoutOf(property);
|
|
3949
|
+
const indent = indentationOf(anchor);
|
|
3950
|
+
const oldIndent = indentationOf(property);
|
|
3951
|
+
const reindent = (lines) => lines.split("\n").map(
|
|
3952
|
+
(line2, index) => index > 0 && line2.startsWith(oldIndent) ? indent + line2.slice(oldIndent.length) : line2
|
|
3953
|
+
).join("\n");
|
|
3954
|
+
if (anchorLayout.ownsLines) {
|
|
3955
|
+
const moved = reindent(text.slice(layout.start, property.getEnd()));
|
|
3956
|
+
const position = anchorLayout.end + restOfLine(text, anchorLayout.end).length;
|
|
3957
|
+
const insertion = `
|
|
3958
|
+
${indent}${moved}${anchorLayout.hasComma ? "," : ""}${layout.trailingComment}`;
|
|
3959
|
+
if (anchorLayout.hasComma) {
|
|
3960
|
+
return [insertAt(position, insertion)];
|
|
4300
3961
|
}
|
|
3962
|
+
return position === anchor.getEnd() ? [insertAt(position, `,${insertion}`)] : [insertAt(anchor.getEnd(), ","), insertAt(position, insertion)];
|
|
4301
3963
|
}
|
|
3964
|
+
const droppedComments = text.slice(layout.start, property.getStart(true)).trim() !== "" || layout.trailingComment !== "";
|
|
3965
|
+
if (droppedComments) {
|
|
3966
|
+
console.warn(
|
|
3967
|
+
` [${location(property)}] The comments next to \`${DECLARATION_PROPERTY_NAME}\` were not moved with it. Move them onto the ${DECLARE_ACTION_TYPE} action by hand.`
|
|
3968
|
+
);
|
|
3969
|
+
}
|
|
3970
|
+
const isMultiLine = declareAction.getText().includes("\n");
|
|
3971
|
+
const separator = isMultiLine ? `,
|
|
3972
|
+
${indent}` : ", ";
|
|
3973
|
+
return [
|
|
3974
|
+
insertAt(anchor.getEnd(), `${separator}${reindent(property.getText(true))}`)
|
|
3975
|
+
];
|
|
4302
3976
|
}
|
|
4303
|
-
function
|
|
4304
|
-
const
|
|
4305
|
-
|
|
4306
|
-
|
|
4307
|
-
|
|
4308
|
-
|
|
4309
|
-
|
|
4310
|
-
|
|
4311
|
-
|
|
4312
|
-
|
|
4313
|
-
|
|
4314
|
-
|
|
4315
|
-
|
|
4316
|
-
|
|
4317
|
-
|
|
4318
|
-
|
|
4319
|
-
options.insertPropertyAssignment(0, {
|
|
4320
|
-
name: "default",
|
|
4321
|
-
initializer: defaultExpr
|
|
4322
|
-
});
|
|
3977
|
+
function removeFromConfig(property) {
|
|
3978
|
+
const text = property.getSourceFile().getFullText();
|
|
3979
|
+
const layout = layoutOf(property);
|
|
3980
|
+
const previousComma = property.getPreviousSiblings().find((sibling) => !isOnlyComments(sibling.getText()))?.asKind(import_ts_morph2.SyntaxKind.CommaToken);
|
|
3981
|
+
if (layout.ownsLines) {
|
|
3982
|
+
const lines = {
|
|
3983
|
+
start: text.lastIndexOf("\n", layout.start - 1),
|
|
3984
|
+
end: layout.end + restOfLine(text, layout.end).length,
|
|
3985
|
+
text: ""
|
|
3986
|
+
};
|
|
3987
|
+
return !layout.hasComma && previousComma ? [
|
|
3988
|
+
lines,
|
|
3989
|
+
{
|
|
3990
|
+
start: previousComma.getStart(),
|
|
3991
|
+
end: previousComma.getEnd(),
|
|
3992
|
+
text: ""
|
|
4323
3993
|
}
|
|
4324
|
-
|
|
3994
|
+
] : [lines];
|
|
3995
|
+
}
|
|
3996
|
+
if (layout.hasComma) {
|
|
3997
|
+
return [{ start: property.getFullStart(), end: layout.end, text: "" }];
|
|
3998
|
+
}
|
|
3999
|
+
return [
|
|
4000
|
+
{
|
|
4001
|
+
start: (previousComma ?? property).getStart(),
|
|
4002
|
+
end: property.getEnd(),
|
|
4003
|
+
text: ""
|
|
4325
4004
|
}
|
|
4326
|
-
|
|
4005
|
+
];
|
|
4006
|
+
}
|
|
4007
|
+
function findConfigLiteral(call) {
|
|
4008
|
+
const config = call.getArguments()[0];
|
|
4009
|
+
if (!config || import_ts_morph2.Node.isObjectLiteralExpression(config)) {
|
|
4010
|
+
return config;
|
|
4327
4011
|
}
|
|
4328
|
-
if (
|
|
4329
|
-
|
|
4330
|
-
|
|
4331
|
-
|
|
4332
|
-
"})"
|
|
4333
|
-
])) {
|
|
4334
|
-
console.log(` \u2713 ${ENVIRONMENT_FILE}: ${name}`);
|
|
4012
|
+
if (config.getType().getProperty(DECLARATION_PROPERTY_NAME)) {
|
|
4013
|
+
console.warn(
|
|
4014
|
+
` [${location(config)}] Skipped: \`${DEFINE_CONFIG_NAME2}\` 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.`
|
|
4015
|
+
);
|
|
4335
4016
|
}
|
|
4017
|
+
return void 0;
|
|
4336
4018
|
}
|
|
4337
|
-
function
|
|
4338
|
-
const
|
|
4339
|
-
|
|
4340
|
-
|
|
4341
|
-
|
|
4342
|
-
|
|
4343
|
-
|
|
4019
|
+
function moveDeclarationToDeclareAction(sourceFile) {
|
|
4020
|
+
const configs = sourceFile.getDescendantsOfKind(import_ts_morph2.SyntaxKind.CallExpression).filter(isToolkitDefineConfigCall).map(findConfigLiteral).filter(import_ts_morph2.Node.isObjectLiteralExpression);
|
|
4021
|
+
const edits = [];
|
|
4022
|
+
let changes = 0;
|
|
4023
|
+
for (const config of configs) {
|
|
4024
|
+
const declaration = findProperty(config, DECLARATION_PROPERTY_NAME);
|
|
4025
|
+
if (!declaration) {
|
|
4026
|
+
continue;
|
|
4027
|
+
}
|
|
4028
|
+
const declareAction = findDeclareAction(config);
|
|
4029
|
+
if (!declareAction) {
|
|
4030
|
+
continue;
|
|
4031
|
+
}
|
|
4032
|
+
console.log(
|
|
4033
|
+
` [${location(declaration)}] Moved \`${declaration.getText()}\` onto the ${DECLARE_ACTION_TYPE} action`
|
|
4034
|
+
);
|
|
4035
|
+
edits.push(
|
|
4036
|
+
...insertIntoDeclareAction(declareAction, declaration),
|
|
4037
|
+
...removeFromConfig(declaration)
|
|
4344
4038
|
);
|
|
4039
|
+
changes++;
|
|
4040
|
+
}
|
|
4041
|
+
if (changes === 0) {
|
|
4042
|
+
return 0;
|
|
4043
|
+
}
|
|
4044
|
+
applyTextEdits(sourceFile, edits);
|
|
4045
|
+
return changes;
|
|
4046
|
+
}
|
|
4047
|
+
async function main2() {
|
|
4048
|
+
const srcDir = import_path3.default.join(process.cwd(), "src");
|
|
4049
|
+
console.log(`Scanning for top-level event declarations in: ${srcDir}
|
|
4050
|
+
`);
|
|
4051
|
+
const project = new import_ts_morph2.Project({
|
|
4052
|
+
tsConfigFilePath: import_path3.default.resolve(srcDir, "../tsconfig.json"),
|
|
4053
|
+
skipAddingFilesFromTsConfig: false
|
|
4054
|
+
});
|
|
4055
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
4056
|
+
const fp = sf.getFilePath();
|
|
4057
|
+
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
4058
|
+
});
|
|
4059
|
+
console.log(`Found ${sourceFiles.length} source file(s) to analyse.
|
|
4060
|
+
`);
|
|
4061
|
+
let totalChanges = 0;
|
|
4062
|
+
const modifiedFiles = [];
|
|
4063
|
+
for (const sourceFile of sourceFiles) {
|
|
4064
|
+
const changes = moveDeclarationToDeclareAction(sourceFile);
|
|
4065
|
+
if (changes > 0) {
|
|
4066
|
+
totalChanges += changes;
|
|
4067
|
+
modifiedFiles.push(sourceFile);
|
|
4068
|
+
}
|
|
4069
|
+
}
|
|
4070
|
+
if (modifiedFiles.length === 0) {
|
|
4071
|
+
console.log("No top-level event declarations found. Nothing to do.");
|
|
4345
4072
|
return;
|
|
4346
4073
|
}
|
|
4347
|
-
|
|
4348
|
-
|
|
4349
|
-
|
|
4074
|
+
console.log(`
|
|
4075
|
+
Saving ${modifiedFiles.length} modified file(s)...`);
|
|
4076
|
+
for (const sourceFile of modifiedFiles) {
|
|
4077
|
+
await sourceFile.save();
|
|
4078
|
+
console.log(
|
|
4079
|
+
` Saved: ${import_path3.default.relative(process.cwd(), sourceFile.getFilePath())}`
|
|
4350
4080
|
);
|
|
4351
|
-
return;
|
|
4352
4081
|
}
|
|
4353
|
-
|
|
4354
|
-
|
|
4355
|
-
|
|
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
|
|
4082
|
+
console.log(
|
|
4083
|
+
`
|
|
4084
|
+
Done. Moved ${totalChanges} declaration(s) across ${modifiedFiles.length} file(s).`
|
|
4385
4085
|
);
|
|
4386
4086
|
}
|
|
4387
|
-
|
|
4388
|
-
|
|
4389
|
-
|
|
4390
|
-
|
|
4391
|
-
|
|
4392
|
-
|
|
4393
|
-
|
|
4394
|
-
|
|
4395
|
-
|
|
4396
|
-
|
|
4397
|
-
|
|
4087
|
+
|
|
4088
|
+
// src/migrations/add-notify-config.ts
|
|
4089
|
+
var import_ts_morph3 = require("ts-morph");
|
|
4090
|
+
var import_path4 = __toESM(require("path"));
|
|
4091
|
+
var DEFINE_CONFIG_NAME3 = "defineConfig";
|
|
4092
|
+
var ACTIONS_PROPERTY_NAME2 = "actions";
|
|
4093
|
+
var DECLARATION_PROPERTY_NAME2 = "declaration";
|
|
4094
|
+
var NOTIFY_ACTION_TYPE = "NOTIFY";
|
|
4095
|
+
var DECLARE_ACTION_TYPE2 = "DECLARE";
|
|
4096
|
+
var NOTIFY_PROPERTIES = [
|
|
4097
|
+
{
|
|
4098
|
+
name: "notificationForm",
|
|
4099
|
+
helper: "toNotificationForm",
|
|
4100
|
+
declareProperty: DECLARATION_PROPERTY_NAME2
|
|
4101
|
+
},
|
|
4102
|
+
{
|
|
4103
|
+
name: "review",
|
|
4104
|
+
helper: "toNotificationReview",
|
|
4105
|
+
declareProperty: "review"
|
|
4398
4106
|
}
|
|
4399
|
-
|
|
4400
|
-
|
|
4401
|
-
)
|
|
4402
|
-
|
|
4403
|
-
for (const name of missing) {
|
|
4404
|
-
importDeclaration.addNamedImport(name);
|
|
4107
|
+
];
|
|
4108
|
+
function referenceOf(property) {
|
|
4109
|
+
if (import_ts_morph3.Node.isShorthandPropertyAssignment(property)) {
|
|
4110
|
+
return property.getName();
|
|
4405
4111
|
}
|
|
4406
|
-
|
|
4407
|
-
|
|
4408
|
-
|
|
4409
|
-
|
|
4112
|
+
const value = property?.getInitializer();
|
|
4113
|
+
return import_ts_morph3.Node.isIdentifier(value) || import_ts_morph3.Node.isPropertyAccessExpression(value) ? value.getText() : void 0;
|
|
4114
|
+
}
|
|
4115
|
+
function findConfigLiteral2(call) {
|
|
4116
|
+
const config = call.getArguments()[0];
|
|
4117
|
+
if (import_ts_morph3.Node.isObjectLiteralExpression(config)) {
|
|
4118
|
+
return config;
|
|
4410
4119
|
}
|
|
4120
|
+
console.warn(
|
|
4121
|
+
` [${location(call)}] Skipped: \`${DEFINE_CONFIG_NAME3}\` is not given an object literal. If the event has a NOTIFY action, give it a \`notificationForm\` and \`review\` by hand.`
|
|
4122
|
+
);
|
|
4123
|
+
return void 0;
|
|
4411
4124
|
}
|
|
4412
|
-
function
|
|
4413
|
-
const
|
|
4414
|
-
|
|
4125
|
+
function findNotifyAction(config, actions) {
|
|
4126
|
+
const candidates = actions.filter(
|
|
4127
|
+
(action) => mayBeAction(action, NOTIFY_ACTION_TYPE)
|
|
4415
4128
|
);
|
|
4416
|
-
if (
|
|
4417
|
-
|
|
4418
|
-
|
|
4129
|
+
if (candidates.length === 0) {
|
|
4130
|
+
console.warn(
|
|
4131
|
+
` [${location(config)}] No ${NOTIFY_ACTION_TYPE} action: the event cannot be notified. If a role has \`record.notify\` for it, add a ${NOTIFY_ACTION_TYPE} action with a \`notificationForm\` and \`review\`.`
|
|
4419
4132
|
);
|
|
4420
|
-
return;
|
|
4133
|
+
return void 0;
|
|
4421
4134
|
}
|
|
4422
|
-
|
|
4423
|
-
|
|
4424
|
-
|
|
4425
|
-
|
|
4426
|
-
|
|
4427
|
-
|
|
4428
|
-
|
|
4429
|
-
|
|
4430
|
-
|
|
4431
|
-
|
|
4432
|
-
|
|
4433
|
-
|
|
4434
|
-
|
|
4435
|
-
|
|
4436
|
-
|
|
4437
|
-
|
|
4438
|
-
|
|
4439
|
-
|
|
4440
|
-
|
|
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`);
|
|
4135
|
+
if (candidates.length !== 1 || !import_ts_morph3.Node.isObjectLiteralExpression(candidates[0])) {
|
|
4136
|
+
console.warn(
|
|
4137
|
+
` [${location(config)}] Skipped: could not find exactly one ${NOTIFY_ACTION_TYPE} action written as an object literal in \`${ACTIONS_PROPERTY_NAME2}\`. Give it a \`notificationForm\` and \`review\` by hand.`
|
|
4138
|
+
);
|
|
4139
|
+
return void 0;
|
|
4140
|
+
}
|
|
4141
|
+
return candidates[0];
|
|
4142
|
+
}
|
|
4143
|
+
function insertIntoAction(action, properties) {
|
|
4144
|
+
const anchor = action.getProperty("label") ?? action.getPropertyOrThrow("type");
|
|
4145
|
+
const text = action.getSourceFile().getFullText();
|
|
4146
|
+
const anchorLayout = layoutOf(anchor);
|
|
4147
|
+
const indent = indentationOf(anchor);
|
|
4148
|
+
if (anchorLayout.ownsLines) {
|
|
4149
|
+
const position = anchorLayout.end + restOfLine(text, anchorLayout.end).length;
|
|
4150
|
+
const lines = properties.map((property) => `
|
|
4151
|
+
${indent}${property}`);
|
|
4152
|
+
if (anchorLayout.hasComma) {
|
|
4153
|
+
return [insertAt(position, `${lines.join(",")},`)];
|
|
4458
4154
|
}
|
|
4155
|
+
return position === anchor.getEnd() ? [insertAt(position, `,${lines.join(",")}`)] : [insertAt(anchor.getEnd(), ","), insertAt(position, lines.join(","))];
|
|
4459
4156
|
}
|
|
4460
|
-
|
|
4461
|
-
|
|
4462
|
-
|
|
4157
|
+
const separator = action.getText().includes("\n") ? `,
|
|
4158
|
+
${indent}` : ", ";
|
|
4159
|
+
return [
|
|
4160
|
+
insertAt(
|
|
4161
|
+
anchor.getEnd(),
|
|
4162
|
+
properties.map((property) => `${separator}${property}`).join("")
|
|
4163
|
+
)
|
|
4164
|
+
];
|
|
4165
|
+
}
|
|
4166
|
+
function addNotifyConfig(sourceFile) {
|
|
4167
|
+
const configs = sourceFile.getDescendantsOfKind(import_ts_morph3.SyntaxKind.CallExpression).filter(isToolkitDefineConfigCall).map(findConfigLiteral2).filter(import_ts_morph3.Node.isObjectLiteralExpression);
|
|
4168
|
+
const helperNames = Object.fromEntries(
|
|
4169
|
+
NOTIFY_PROPERTIES.map(({ helper }) => [
|
|
4170
|
+
helper,
|
|
4171
|
+
findToolkitImportName(sourceFile, helper)
|
|
4172
|
+
])
|
|
4173
|
+
);
|
|
4174
|
+
const edits = [];
|
|
4175
|
+
const usedHelpers = /* @__PURE__ */ new Set();
|
|
4176
|
+
let changes = 0;
|
|
4177
|
+
for (const config of configs) {
|
|
4178
|
+
const actions = findProperty(config, ACTIONS_PROPERTY_NAME2);
|
|
4179
|
+
const actionsValue = import_ts_morph3.Node.isPropertyAssignment(actions) ? actions.getInitializer() : void 0;
|
|
4180
|
+
if (!import_ts_morph3.Node.isArrayLiteralExpression(actionsValue)) {
|
|
4181
|
+
console.warn(
|
|
4182
|
+
` [${location(config)}] Skipped: \`${ACTIONS_PROPERTY_NAME2}\` is not an array literal. If the event has a ${NOTIFY_ACTION_TYPE} action, give it a \`notificationForm\` and \`review\` by hand.`
|
|
4183
|
+
);
|
|
4184
|
+
continue;
|
|
4185
|
+
}
|
|
4186
|
+
const notifyAction = findNotifyAction(config, actionsValue.getElements());
|
|
4187
|
+
if (!notifyAction) {
|
|
4188
|
+
continue;
|
|
4189
|
+
}
|
|
4190
|
+
const declareAction = actionsValue.getElements().find(
|
|
4191
|
+
(action) => import_ts_morph3.Node.isObjectLiteralExpression(action) && isAction(action, DECLARE_ACTION_TYPE2)
|
|
4463
4192
|
);
|
|
4464
|
-
|
|
4465
|
-
|
|
4466
|
-
|
|
4193
|
+
const properties = NOTIFY_PROPERTIES.filter(
|
|
4194
|
+
({ name }) => !findProperty(notifyAction, name)
|
|
4195
|
+
).flatMap(({ name, helper, declareProperty }) => {
|
|
4196
|
+
const helperName = helperNames[helper];
|
|
4197
|
+
const reference = referenceOf(
|
|
4198
|
+
(declareAction && findProperty(declareAction, declareProperty)) ?? (declareProperty === DECLARATION_PROPERTY_NAME2 ? findProperty(config, declareProperty) : void 0)
|
|
4467
4199
|
);
|
|
4468
|
-
|
|
4469
|
-
|
|
4470
|
-
|
|
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`
|
|
4200
|
+
if (!helperName) {
|
|
4201
|
+
console.warn(
|
|
4202
|
+
` [${location(notifyAction)}] Skipped \`${name}\`: the file already declares its own \`${helper}\`. Add \`${name}\` to the ${NOTIFY_ACTION_TYPE} action by hand, using the toolkit's \`${helper}\`.`
|
|
4482
4203
|
);
|
|
4204
|
+
return [];
|
|
4483
4205
|
}
|
|
4206
|
+
if (!reference) {
|
|
4207
|
+
console.warn(
|
|
4208
|
+
` [${location(notifyAction)}] Skipped \`${name}\`: the ${DECLARE_ACTION_TYPE2} action's \`${declareProperty}\` is not given as a name. Add \`${name}: ${helper}(<${DECLARE_ACTION_TYPE2} ${declareProperty}>)\` to the ${NOTIFY_ACTION_TYPE} action by hand.`
|
|
4209
|
+
);
|
|
4210
|
+
return [];
|
|
4211
|
+
}
|
|
4212
|
+
if (helperName === helper) {
|
|
4213
|
+
usedHelpers.add(helper);
|
|
4214
|
+
}
|
|
4215
|
+
return [`${name}: ${helperName}(${reference})`];
|
|
4216
|
+
});
|
|
4217
|
+
if (properties.length === 0) {
|
|
4218
|
+
continue;
|
|
4484
4219
|
}
|
|
4220
|
+
console.log(
|
|
4221
|
+
` [${location(notifyAction)}] Added \`${properties.join("`, `")}\` to the ${NOTIFY_ACTION_TYPE} action`
|
|
4222
|
+
);
|
|
4223
|
+
edits.push(...insertIntoAction(notifyAction, properties));
|
|
4224
|
+
changes++;
|
|
4485
4225
|
}
|
|
4226
|
+
if (changes === 0) {
|
|
4227
|
+
return 0;
|
|
4228
|
+
}
|
|
4229
|
+
applyTextEdits(sourceFile, edits);
|
|
4230
|
+
for (const helper of usedHelpers) {
|
|
4231
|
+
addToolkitImport(sourceFile, helper);
|
|
4232
|
+
}
|
|
4233
|
+
return changes;
|
|
4486
4234
|
}
|
|
4487
|
-
async function
|
|
4488
|
-
const
|
|
4489
|
-
|
|
4490
|
-
|
|
4491
|
-
`
|
|
4492
|
-
Adding daily usage telemetry (${config.enabled ? `enabled for ${config.countryCode}` : "disabled"} by default)...
|
|
4493
|
-
`
|
|
4494
|
-
);
|
|
4495
|
-
writeTelemetryHandler(cwd);
|
|
4235
|
+
async function main3() {
|
|
4236
|
+
const srcDir = import_path4.default.join(process.cwd(), "src");
|
|
4237
|
+
console.log(`Scanning for NOTIFY actions in: ${srcDir}
|
|
4238
|
+
`);
|
|
4496
4239
|
const project = new import_ts_morph3.Project({
|
|
4497
|
-
|
|
4498
|
-
|
|
4499
|
-
manipulationSettings: {
|
|
4500
|
-
indentationText: import_ts_morph3.IndentationText.TwoSpaces,
|
|
4501
|
-
quoteKind: import_ts_morph3.QuoteKind.Single
|
|
4502
|
-
}
|
|
4240
|
+
tsConfigFilePath: import_path4.default.resolve(srcDir, "../tsconfig.json"),
|
|
4241
|
+
skipAddingFilesFromTsConfig: false
|
|
4503
4242
|
});
|
|
4504
|
-
|
|
4505
|
-
|
|
4506
|
-
|
|
4507
|
-
|
|
4508
|
-
|
|
4509
|
-
|
|
4510
|
-
|
|
4511
|
-
|
|
4512
|
-
|
|
4513
|
-
|
|
4243
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
4244
|
+
const fp = sf.getFilePath();
|
|
4245
|
+
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
4246
|
+
});
|
|
4247
|
+
console.log(`Found ${sourceFiles.length} source file(s) to analyse.
|
|
4248
|
+
`);
|
|
4249
|
+
let totalChanges = 0;
|
|
4250
|
+
const modifiedFiles = [];
|
|
4251
|
+
for (const sourceFile of sourceFiles) {
|
|
4252
|
+
const changes = addNotifyConfig(sourceFile);
|
|
4253
|
+
if (changes > 0) {
|
|
4254
|
+
totalChanges += changes;
|
|
4255
|
+
modifiedFiles.push(sourceFile);
|
|
4514
4256
|
}
|
|
4515
4257
|
}
|
|
4258
|
+
if (modifiedFiles.length === 0) {
|
|
4259
|
+
console.log("No NOTIFY actions to update. Nothing to do.");
|
|
4260
|
+
return;
|
|
4261
|
+
}
|
|
4262
|
+
console.log(`
|
|
4263
|
+
Saving ${modifiedFiles.length} modified file(s)...`);
|
|
4264
|
+
for (const sourceFile of modifiedFiles) {
|
|
4265
|
+
await sourceFile.save();
|
|
4266
|
+
console.log(
|
|
4267
|
+
` Saved: ${import_path4.default.relative(process.cwd(), sourceFile.getFilePath())}`
|
|
4268
|
+
);
|
|
4269
|
+
}
|
|
4270
|
+
console.log(
|
|
4271
|
+
`
|
|
4272
|
+
Done. Updated ${totalChanges} NOTIFY action(s) across ${modifiedFiles.length} file(s).`
|
|
4273
|
+
);
|
|
4516
4274
|
}
|
|
4517
4275
|
|
|
4518
|
-
// src/migrations/
|
|
4519
|
-
var
|
|
4520
|
-
var import_fs5 = require("fs");
|
|
4521
|
-
var import_os = require("os");
|
|
4522
|
-
var import_path6 = __toESM(require("path"));
|
|
4523
|
-
|
|
4524
|
-
// src/migrations/v2.1/template-files.ts
|
|
4525
|
-
var import_fs4 = require("fs");
|
|
4276
|
+
// src/migrations/read-declaration-through-helper.ts
|
|
4277
|
+
var import_ts_morph4 = require("ts-morph");
|
|
4526
4278
|
var import_path5 = __toESM(require("path"));
|
|
4527
|
-
|
|
4528
|
-
|
|
4529
|
-
|
|
4530
|
-
|
|
4531
|
-
|
|
4532
|
-
const
|
|
4533
|
-
|
|
4534
|
-
|
|
4535
|
-
if (!templateDir) {
|
|
4536
|
-
throw new Error(
|
|
4537
|
-
`Country config template files not found in any of: ${candidates.join(", ")}`
|
|
4538
|
-
);
|
|
4279
|
+
var EVENT_CONFIG_TYPE_NAME = "EventConfig";
|
|
4280
|
+
var DECLARATION_PROPERTY_NAME3 = "declaration";
|
|
4281
|
+
var GET_DECLARATION_NAME = "getDeclaration";
|
|
4282
|
+
function isToolkitEventConfig(type) {
|
|
4283
|
+
const nonNullableType = type.getNonNullableType();
|
|
4284
|
+
const symbol = nonNullableType.getAliasSymbol() ?? nonNullableType.getSymbol();
|
|
4285
|
+
if (symbol?.getName() !== EVENT_CONFIG_TYPE_NAME) {
|
|
4286
|
+
return false;
|
|
4539
4287
|
}
|
|
4540
|
-
return
|
|
4288
|
+
return symbol.getDeclarations().some((declaration) => declaration.getSourceFile().isDeclarationFile());
|
|
4541
4289
|
}
|
|
4542
|
-
function
|
|
4543
|
-
|
|
4544
|
-
if (!(0, import_fs4.existsSync)(absolute)) {
|
|
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
|
-
});
|
|
4290
|
+
function isDeclarationReadOnEventConfig(node) {
|
|
4291
|
+
return node.getName() === DECLARATION_PROPERTY_NAME3 && isToolkitEventConfig(node.getExpression().getType());
|
|
4551
4292
|
}
|
|
4552
|
-
|
|
4553
|
-
|
|
4554
|
-
|
|
4555
|
-
|
|
4556
|
-
|
|
4557
|
-
|
|
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" });
|
|
4293
|
+
function isAssignmentOperator(kind) {
|
|
4294
|
+
return kind >= import_ts_morph4.SyntaxKind.FirstAssignment && kind <= import_ts_morph4.SyntaxKind.LastAssignment;
|
|
4295
|
+
}
|
|
4296
|
+
function isWriteTarget(node) {
|
|
4297
|
+
const parent = node.getParent();
|
|
4298
|
+
if (import_ts_morph4.Node.isDeleteExpression(parent)) {
|
|
4566
4299
|
return true;
|
|
4567
|
-
} catch {
|
|
4568
|
-
return false;
|
|
4569
4300
|
}
|
|
4301
|
+
return import_ts_morph4.Node.isBinaryExpression(parent) && parent.getLeft() === node && isAssignmentOperator(parent.getOperatorToken().getKind());
|
|
4570
4302
|
}
|
|
4571
|
-
function
|
|
4572
|
-
|
|
4573
|
-
|
|
4574
|
-
|
|
4303
|
+
function location2(node) {
|
|
4304
|
+
const relPath = import_path5.default.relative(
|
|
4305
|
+
process.cwd(),
|
|
4306
|
+
node.getSourceFile().getFilePath()
|
|
4307
|
+
);
|
|
4308
|
+
return `${relPath}:${node.getStartLineNumber()}`;
|
|
4309
|
+
}
|
|
4310
|
+
function warnDestructuredDeclarations(sourceFile) {
|
|
4311
|
+
for (const pattern of sourceFile.getDescendantsOfKind(
|
|
4312
|
+
import_ts_morph4.SyntaxKind.ObjectBindingPattern
|
|
4313
|
+
)) {
|
|
4314
|
+
const destructuresDeclaration = pattern.getElements().some(
|
|
4315
|
+
(element) => (element.getPropertyNameNode()?.getText() ?? element.getName()) === DECLARATION_PROPERTY_NAME3
|
|
4575
4316
|
);
|
|
4317
|
+
if (destructuresDeclaration && isToolkitEventConfig(pattern.getType())) {
|
|
4318
|
+
console.warn(
|
|
4319
|
+
` [${location2(pattern)}] Destructures \`${DECLARATION_PROPERTY_NAME3}\` from an EventConfig. Rewrite it to use \`${GET_DECLARATION_NAME}(config)\` by hand.`
|
|
4320
|
+
);
|
|
4321
|
+
}
|
|
4576
4322
|
}
|
|
4577
4323
|
}
|
|
4578
|
-
|
|
4579
|
-
|
|
4580
|
-
|
|
4581
|
-
|
|
4582
|
-
|
|
4583
|
-
|
|
4584
|
-
|
|
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)
|
|
4324
|
+
function warnSpreadDeclarations(sourceFile) {
|
|
4325
|
+
for (const literal of sourceFile.getDescendantsOfKind(
|
|
4326
|
+
import_ts_morph4.SyntaxKind.ObjectLiteralExpression
|
|
4327
|
+
)) {
|
|
4328
|
+
const properties = literal.getProperties();
|
|
4329
|
+
const spreadsEventConfig = properties.some(
|
|
4330
|
+
(property) => import_ts_morph4.Node.isSpreadAssignment(property) && isToolkitEventConfig(property.getExpression().getType())
|
|
4589
4331
|
);
|
|
4590
|
-
|
|
4591
|
-
|
|
4592
|
-
|
|
4593
|
-
|
|
4594
|
-
|
|
4595
|
-
|
|
4596
|
-
|
|
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;
|
|
4332
|
+
const setsDeclaration = properties.some(
|
|
4333
|
+
(property) => (import_ts_morph4.Node.isPropertyAssignment(property) || import_ts_morph4.Node.isShorthandPropertyAssignment(property)) && property.getName() === DECLARATION_PROPERTY_NAME3
|
|
4334
|
+
);
|
|
4335
|
+
if (spreadsEventConfig && setsDeclaration) {
|
|
4336
|
+
console.warn(
|
|
4337
|
+
` [${location2(literal)}] Spreads an EventConfig and sets \`${DECLARATION_PROPERTY_NAME3}\` next to it. The spread config already has a \`${DECLARATION_PROPERTY_NAME3}\` on its DECLARE action, so replace that one by hand.`
|
|
4338
|
+
);
|
|
4613
4339
|
}
|
|
4614
|
-
return { contents: toBytes((0, import_fs5.readFileSync)(oursPath)), conflicts };
|
|
4615
|
-
} finally {
|
|
4616
|
-
(0, import_fs5.rmSync)(dir, { recursive: true, force: true });
|
|
4617
4340
|
}
|
|
4618
4341
|
}
|
|
4619
|
-
|
|
4620
|
-
|
|
4621
|
-
|
|
4622
|
-
|
|
4623
|
-
|
|
4624
|
-
|
|
4625
|
-
|
|
4626
|
-
} else if (response.status !== 404) {
|
|
4627
|
-
throw new Error(
|
|
4628
|
-
`GitHub answered ${response.status} ${response.statusText} for ${url}`
|
|
4342
|
+
function rewriteDeclarationReads(sourceFile) {
|
|
4343
|
+
warnDestructuredDeclarations(sourceFile);
|
|
4344
|
+
warnSpreadDeclarations(sourceFile);
|
|
4345
|
+
const reads = sourceFile.getDescendantsOfKind(import_ts_morph4.SyntaxKind.PropertyAccessExpression).filter(isDeclarationReadOnEventConfig).filter((node) => {
|
|
4346
|
+
if (node.hasQuestionDotToken()) {
|
|
4347
|
+
console.warn(
|
|
4348
|
+
` [${location2(node)}] Skipped optional chain \`${node.getText()}\`. Rewrite it to use \`${GET_DECLARATION_NAME}()\` by hand.`
|
|
4629
4349
|
);
|
|
4350
|
+
return false;
|
|
4630
4351
|
}
|
|
4352
|
+
if (isWriteTarget(node)) {
|
|
4353
|
+
console.warn(
|
|
4354
|
+
` [${location2(node)}] Skipped write to \`${node.getText()}\`. Set \`${DECLARATION_PROPERTY_NAME3}\` on the DECLARE action instead.`
|
|
4355
|
+
);
|
|
4356
|
+
return false;
|
|
4357
|
+
}
|
|
4358
|
+
return true;
|
|
4359
|
+
}).sort((a, b) => b.getStart() - a.getStart());
|
|
4360
|
+
if (reads.length === 0) {
|
|
4361
|
+
return 0;
|
|
4362
|
+
}
|
|
4363
|
+
const getDeclarationName = findToolkitImportName(
|
|
4364
|
+
sourceFile,
|
|
4365
|
+
GET_DECLARATION_NAME
|
|
4366
|
+
);
|
|
4367
|
+
if (!getDeclarationName) {
|
|
4368
|
+
console.warn(
|
|
4369
|
+
` [${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.`
|
|
4370
|
+
);
|
|
4371
|
+
return 0;
|
|
4372
|
+
}
|
|
4373
|
+
for (const read of reads) {
|
|
4374
|
+
console.log(
|
|
4375
|
+
` [${location2(read)}] ${read.getText()} -> ${getDeclarationName}(${read.getExpression().getText()})`
|
|
4376
|
+
);
|
|
4377
|
+
read.replaceWithText(
|
|
4378
|
+
`${getDeclarationName}(${read.getExpression().getText()})`
|
|
4379
|
+
);
|
|
4380
|
+
}
|
|
4381
|
+
addToolkitImport(sourceFile, GET_DECLARATION_NAME);
|
|
4382
|
+
return reads.length;
|
|
4383
|
+
}
|
|
4384
|
+
async function main4() {
|
|
4385
|
+
const srcDir = import_path5.default.join(process.cwd(), "src");
|
|
4386
|
+
console.log(`Scanning for EventConfig declaration reads in: ${srcDir}
|
|
4387
|
+
`);
|
|
4388
|
+
const project = new import_ts_morph4.Project({
|
|
4389
|
+
tsConfigFilePath: import_path5.default.resolve(srcDir, "../tsconfig.json"),
|
|
4390
|
+
skipAddingFilesFromTsConfig: false
|
|
4391
|
+
});
|
|
4392
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
4393
|
+
const fp = sf.getFilePath();
|
|
4394
|
+
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
4395
|
+
});
|
|
4396
|
+
console.log(`Found ${sourceFiles.length} source file(s) to analyse.
|
|
4397
|
+
`);
|
|
4398
|
+
let totalChanges = 0;
|
|
4399
|
+
const modifiedFiles = [];
|
|
4400
|
+
for (const sourceFile of sourceFiles) {
|
|
4401
|
+
const changes = rewriteDeclarationReads(sourceFile);
|
|
4402
|
+
if (changes > 0) {
|
|
4403
|
+
totalChanges += changes;
|
|
4404
|
+
modifiedFiles.push(sourceFile);
|
|
4405
|
+
}
|
|
4406
|
+
}
|
|
4407
|
+
if (modifiedFiles.length === 0) {
|
|
4408
|
+
console.log("No EventConfig declaration reads found. Nothing to do.");
|
|
4409
|
+
return;
|
|
4410
|
+
}
|
|
4411
|
+
console.log(`
|
|
4412
|
+
Saving ${modifiedFiles.length} modified file(s)...`);
|
|
4413
|
+
for (const sourceFile of modifiedFiles) {
|
|
4414
|
+
await sourceFile.save();
|
|
4415
|
+
console.log(
|
|
4416
|
+
` Saved: ${import_path5.default.relative(process.cwd(), sourceFile.getFilePath())}`
|
|
4417
|
+
);
|
|
4418
|
+
}
|
|
4419
|
+
console.log(
|
|
4420
|
+
`
|
|
4421
|
+
Done. Rewrote ${totalChanges} declaration read(s) across ${modifiedFiles.length} file(s).`
|
|
4422
|
+
);
|
|
4423
|
+
}
|
|
4424
|
+
|
|
4425
|
+
// src/migrations/resolve-versioned-event-config.ts
|
|
4426
|
+
var import_ts_morph5 = require("ts-morph");
|
|
4427
|
+
var import_path6 = __toESM(require("path"));
|
|
4428
|
+
var EVENT_CONFIG_TYPE_NAME2 = "EventConfig";
|
|
4429
|
+
var VERSIONED_EVENT_CONFIG_TYPE_NAME = "VersionedEventConfig";
|
|
4430
|
+
var RESOLVE_EVENT_CONFIG_NAME = "resolveEventConfig";
|
|
4431
|
+
var TOOLKIT_EVENTS_MODULE2 = "@opencrvs/toolkit/events";
|
|
4432
|
+
function isToolkitType(type, name) {
|
|
4433
|
+
const nonNullableType = type.getNonNullableType();
|
|
4434
|
+
const symbol = nonNullableType.getAliasSymbol() ?? nonNullableType.getSymbol();
|
|
4435
|
+
if (symbol?.getName() !== name) {
|
|
4436
|
+
return false;
|
|
4437
|
+
}
|
|
4438
|
+
return symbol.getDeclarations().some((declaration) => declaration.getSourceFile().isDeclarationFile());
|
|
4439
|
+
}
|
|
4440
|
+
function isVersionedEventConfig(type) {
|
|
4441
|
+
return isToolkitType(type, VERSIONED_EVENT_CONFIG_TYPE_NAME);
|
|
4442
|
+
}
|
|
4443
|
+
function isEventConfig(type) {
|
|
4444
|
+
return isToolkitType(type, EVENT_CONFIG_TYPE_NAME2);
|
|
4445
|
+
}
|
|
4446
|
+
function isArrayOf(type, isElement) {
|
|
4447
|
+
const elementType = type.getNonNullableType().getArrayElementType();
|
|
4448
|
+
return elementType !== void 0 && isElement(elementType);
|
|
4449
|
+
}
|
|
4450
|
+
function isVersionedField(type, name) {
|
|
4451
|
+
return type.getNonNullableType().getProperty(name) !== void 0;
|
|
4452
|
+
}
|
|
4453
|
+
function isAssignmentOperator2(kind) {
|
|
4454
|
+
return kind >= import_ts_morph5.SyntaxKind.FirstAssignment && kind <= import_ts_morph5.SyntaxKind.LastAssignment;
|
|
4455
|
+
}
|
|
4456
|
+
function isWriteTarget2(node) {
|
|
4457
|
+
const parent = node.getParent();
|
|
4458
|
+
if (import_ts_morph5.Node.isDeleteExpression(parent)) {
|
|
4459
|
+
return true;
|
|
4631
4460
|
}
|
|
4632
|
-
return
|
|
4461
|
+
return import_ts_morph5.Node.isBinaryExpression(parent) && parent.getLeft() === node && isAssignmentOperator2(parent.getOperatorToken().getKind());
|
|
4633
4462
|
}
|
|
4634
|
-
function
|
|
4635
|
-
const
|
|
4636
|
-
|
|
4637
|
-
|
|
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)
|
|
4463
|
+
function location3(node) {
|
|
4464
|
+
const relPath = import_path6.default.relative(
|
|
4465
|
+
process.cwd(),
|
|
4466
|
+
node.getSourceFile().getFilePath()
|
|
4641
4467
|
);
|
|
4642
|
-
|
|
4643
|
-
|
|
4644
|
-
|
|
4645
|
-
|
|
4646
|
-
|
|
4647
|
-
|
|
4648
|
-
const
|
|
4649
|
-
|
|
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) {
|
|
4468
|
+
return `${relPath}:${node.getStartLineNumber()}`;
|
|
4469
|
+
}
|
|
4470
|
+
function warnDestructuredVersionFields(sourceFile) {
|
|
4471
|
+
for (const pattern of sourceFile.getDescendantsOfKind(
|
|
4472
|
+
import_ts_morph5.SyntaxKind.ObjectBindingPattern
|
|
4473
|
+
)) {
|
|
4474
|
+
const type = pattern.getType();
|
|
4475
|
+
if (!isVersionedEventConfig(type)) {
|
|
4696
4476
|
continue;
|
|
4697
4477
|
}
|
|
4698
|
-
|
|
4699
|
-
|
|
4700
|
-
|
|
4701
|
-
|
|
4702
|
-
|
|
4478
|
+
const destructuresVersionField = pattern.getElements().some(
|
|
4479
|
+
(element) => !element.getDotDotDotToken() && !isVersionedField(
|
|
4480
|
+
type,
|
|
4481
|
+
element.getPropertyNameNode()?.getText() ?? element.getName()
|
|
4482
|
+
)
|
|
4483
|
+
);
|
|
4484
|
+
if (destructuresVersionField) {
|
|
4485
|
+
console.warn(
|
|
4486
|
+
` [${location3(pattern)}] Destructures a field of a version from a VersionedEventConfig. Destructure it from \`${RESOLVE_EVENT_CONFIG_NAME}(config)\` by hand.`
|
|
4487
|
+
);
|
|
4703
4488
|
}
|
|
4704
4489
|
}
|
|
4705
|
-
return { outcomes, migrated: [...migrated].sort() };
|
|
4706
4490
|
}
|
|
4707
|
-
function
|
|
4708
|
-
|
|
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) {
|
|
4491
|
+
function findVersionFieldReads(sourceFile) {
|
|
4492
|
+
return sourceFile.getDescendantsOfKind(import_ts_morph5.SyntaxKind.PropertyAccessExpression).filter((node) => {
|
|
4493
|
+
const type = node.getExpression().getType();
|
|
4494
|
+
return isVersionedEventConfig(type) && !isVersionedField(type, node.getName());
|
|
4495
|
+
}).filter((node) => {
|
|
4496
|
+
if (node.hasQuestionDotToken()) {
|
|
4747
4497
|
console.warn(
|
|
4748
|
-
`
|
|
4498
|
+
` [${location3(node)}] Skipped optional chain \`${node.getText()}\`. Rewrite it to use \`${RESOLVE_EVENT_CONFIG_NAME}()\` by hand.`
|
|
4749
4499
|
);
|
|
4750
|
-
return;
|
|
4500
|
+
return false;
|
|
4751
4501
|
}
|
|
4752
|
-
|
|
4753
|
-
|
|
4754
|
-
|
|
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
|
|
4502
|
+
if (isWriteTarget2(node)) {
|
|
4503
|
+
console.warn(
|
|
4504
|
+
` [${location3(node)}] Skipped write to \`${node.getText()}\`. Set it in the version passed to \`defineConfig\` instead.`
|
|
4760
4505
|
);
|
|
4761
|
-
|
|
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
|
-
}
|
|
4506
|
+
return false;
|
|
4768
4507
|
}
|
|
4769
|
-
|
|
4770
|
-
|
|
4771
|
-
|
|
4772
|
-
|
|
4773
|
-
|
|
4774
|
-
|
|
4508
|
+
return true;
|
|
4509
|
+
});
|
|
4510
|
+
}
|
|
4511
|
+
function isHandedOver(node) {
|
|
4512
|
+
const parent = node.getParent();
|
|
4513
|
+
if (import_ts_morph5.Node.isCallExpression(parent) || import_ts_morph5.Node.isNewExpression(parent)) {
|
|
4514
|
+
return parent.getArguments().includes(node);
|
|
4515
|
+
}
|
|
4516
|
+
return (import_ts_morph5.Node.isVariableDeclaration(parent) || import_ts_morph5.Node.isPropertyAssignment(parent)) && parent.getInitializer() === node || import_ts_morph5.Node.isReturnStatement(parent);
|
|
4517
|
+
}
|
|
4518
|
+
function findValuesExpectingEventConfig(sourceFile) {
|
|
4519
|
+
return sourceFile.getDescendants().filter((node) => import_ts_morph5.Node.isExpression(node)).filter(isHandedOver).map((node) => {
|
|
4520
|
+
const type = node.getType();
|
|
4521
|
+
const expectedType = node.getContextualType();
|
|
4522
|
+
if (!expectedType) {
|
|
4523
|
+
return void 0;
|
|
4775
4524
|
}
|
|
4776
|
-
|
|
4777
|
-
|
|
4778
|
-
(file) => outcomes[file] === "conflict"
|
|
4779
|
-
);
|
|
4780
|
-
for (const file of conflicts) {
|
|
4781
|
-
tryGit(["restore", "--staged", "--", `${ASSETS_DIR}/${file}`]);
|
|
4525
|
+
if (isVersionedEventConfig(type) && isEventConfig(expectedType)) {
|
|
4526
|
+
return { node, isArray: false };
|
|
4782
4527
|
}
|
|
4783
|
-
if (
|
|
4784
|
-
|
|
4785
|
-
`
|
|
4786
|
-
\u26A0\uFE0F ${conflicts.length} file(s) need their conflicts resolved: ${conflicts.map((file) => `assets/${file}`).join(", ")}`
|
|
4787
|
-
);
|
|
4528
|
+
if (isArrayOf(type, isVersionedEventConfig) && isArrayOf(expectedType, isEventConfig)) {
|
|
4529
|
+
return { node, isArray: true };
|
|
4788
4530
|
}
|
|
4789
|
-
|
|
4531
|
+
return void 0;
|
|
4532
|
+
}).filter((value) => value !== void 0).filter(({ node }) => {
|
|
4533
|
+
if (node.getType().isNullable()) {
|
|
4790
4534
|
console.warn(
|
|
4791
|
-
|
|
4535
|
+
` [${location3(node)}] Skipped \`${node.getText()}\`, which may be undefined where an EventConfig is expected. Narrow it and pass \`${RESOLVE_EVENT_CONFIG_NAME}(...)\` by hand.`
|
|
4792
4536
|
);
|
|
4537
|
+
return false;
|
|
4793
4538
|
}
|
|
4794
|
-
|
|
4795
|
-
|
|
4796
|
-
}
|
|
4797
|
-
const dockerfile = toBytes(
|
|
4798
|
-
(0, import_fs5.readFileSync)(import_path6.default.join(templateDir, "Dockerfile.assets"))
|
|
4799
|
-
);
|
|
4800
|
-
const current = readIfExists(import_path6.default.join(cwd, "Dockerfile.assets"));
|
|
4801
|
-
if (!current || !sameBytes(current, dockerfile)) {
|
|
4802
|
-
(0, import_fs5.writeFileSync)(import_path6.default.join(cwd, "Dockerfile.assets"), dockerfile);
|
|
4803
|
-
tryGit(["add", "--", "Dockerfile.assets"]);
|
|
4804
|
-
console.log(" \u2713 Dockerfile.assets replaced with the template version");
|
|
4805
|
-
}
|
|
4539
|
+
return true;
|
|
4540
|
+
});
|
|
4806
4541
|
}
|
|
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)) {
|
|
4847
|
-
return void 0;
|
|
4848
|
-
}
|
|
4849
|
-
return source.replace(APK_BLOCK, "").replace(SALT_LINE, FIXED_SALT_LINE);
|
|
4542
|
+
function findToolkitImport2(sourceFile) {
|
|
4543
|
+
return sourceFile.getImportDeclaration(
|
|
4544
|
+
(declaration) => declaration.getModuleSpecifierValue() === TOOLKIT_EVENTS_MODULE2 && !declaration.isTypeOnly() && !declaration.getNamespaceImport()
|
|
4545
|
+
);
|
|
4850
4546
|
}
|
|
4851
|
-
function
|
|
4852
|
-
|
|
4853
|
-
|
|
4547
|
+
function findResolveEventConfigName(sourceFile) {
|
|
4548
|
+
const imported = findToolkitImport2(sourceFile)?.getNamedImports().find((namedImport) => namedImport.getName() === RESOLVE_EVENT_CONFIG_NAME);
|
|
4549
|
+
if (imported) {
|
|
4550
|
+
return imported.getAliasNode()?.getText() ?? RESOLVE_EVENT_CONFIG_NAME;
|
|
4854
4551
|
}
|
|
4855
|
-
if (
|
|
4552
|
+
if (sourceFile.getLocal(RESOLVE_EVENT_CONFIG_NAME)) {
|
|
4856
4553
|
return void 0;
|
|
4857
4554
|
}
|
|
4858
|
-
return
|
|
4555
|
+
return RESOLVE_EVENT_CONFIG_NAME;
|
|
4859
4556
|
}
|
|
4860
|
-
function
|
|
4861
|
-
const
|
|
4862
|
-
if (!
|
|
4863
|
-
|
|
4864
|
-
|
|
4865
|
-
|
|
4866
|
-
|
|
4867
|
-
|
|
4868
|
-
console.warn(
|
|
4869
|
-
` \u26A0\uFE0F ${relativePath} does not match the upstream v2.0 version, so it was left alone. Apply https://github.com/opencrvs/opencrvs-core/pull/13778 by hand, or Metabase will fail to start behind the chart's private egress policy.`
|
|
4557
|
+
function addResolveEventConfigImport(sourceFile) {
|
|
4558
|
+
const toolkitImport = findToolkitImport2(sourceFile);
|
|
4559
|
+
if (!toolkitImport) {
|
|
4560
|
+
const imports = sourceFile.getImportDeclarations();
|
|
4561
|
+
const lastImport = imports[imports.length - 1];
|
|
4562
|
+
sourceFile.insertStatements(
|
|
4563
|
+
lastImport ? lastImport.getChildIndex() + 1 : 0,
|
|
4564
|
+
`import { ${RESOLVE_EVENT_CONFIG_NAME} } from '${TOOLKIT_EVENTS_MODULE2}'`
|
|
4870
4565
|
);
|
|
4871
4566
|
return;
|
|
4872
4567
|
}
|
|
4873
|
-
|
|
4568
|
+
const alreadyImported = toolkitImport.getNamedImports().some((namedImport) => namedImport.getName() === RESOLVE_EVENT_CONFIG_NAME);
|
|
4569
|
+
if (alreadyImported) {
|
|
4874
4570
|
return;
|
|
4875
4571
|
}
|
|
4876
|
-
|
|
4877
|
-
|
|
4878
|
-
|
|
4879
|
-
|
|
4880
|
-
console.log("\nRemoving the Metabase package installs...\n");
|
|
4881
|
-
for (const dir of METABASE_DIRS) {
|
|
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"
|
|
4887
|
-
);
|
|
4572
|
+
const namedImports = toolkitImport.getNamedImports();
|
|
4573
|
+
if (toolkitImport.getDefaultImport() || namedImports.length === 0) {
|
|
4574
|
+
toolkitImport.addNamedImport(RESOLVE_EVENT_CONFIG_NAME);
|
|
4575
|
+
return;
|
|
4888
4576
|
}
|
|
4889
|
-
|
|
4890
|
-
|
|
4891
|
-
|
|
4892
|
-
|
|
4893
|
-
|
|
4894
|
-
|
|
4895
|
-
|
|
4896
|
-
|
|
4897
|
-
|
|
4898
|
-
"src/login-config.ts",
|
|
4899
|
-
"src/login-config.prod.ts"
|
|
4900
|
-
];
|
|
4901
|
-
var ENVIRONMENT_FILE2 = "src/environment.ts";
|
|
4902
|
-
var CONSTANTS_FILE = "src/constants.ts";
|
|
4903
|
-
var INDEX_FILE2 = "src/index.ts";
|
|
4904
|
-
var UTILS_FILE = "src/utils/index.ts";
|
|
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}`);
|
|
4912
|
-
}
|
|
4913
|
-
function isReferenced(sourceFile, name) {
|
|
4914
|
-
return sourceFile.getDescendantsOfKind(import_ts_morph4.SyntaxKind.Identifier).some(
|
|
4915
|
-
(identifier) => identifier.getText() === name && !identifier.getFirstAncestorByKind(import_ts_morph4.SyntaxKind.ImportDeclaration)
|
|
4577
|
+
const names = [
|
|
4578
|
+
...namedImports.map((namedImport) => namedImport.getText()),
|
|
4579
|
+
RESOLVE_EVENT_CONFIG_NAME
|
|
4580
|
+
];
|
|
4581
|
+
const specifiers = toolkitImport.getText().includes("\n") ? `{
|
|
4582
|
+
${names.join(",\n ")}
|
|
4583
|
+
}` : `{ ${names.join(", ")} }`;
|
|
4584
|
+
toolkitImport.replaceWithText(
|
|
4585
|
+
`import ${specifiers} from '${TOOLKIT_EVENTS_MODULE2}'`
|
|
4916
4586
|
);
|
|
4917
4587
|
}
|
|
4918
|
-
function
|
|
4919
|
-
|
|
4920
|
-
|
|
4921
|
-
|
|
4922
|
-
|
|
4923
|
-
|
|
4924
|
-
|
|
4925
|
-
|
|
4926
|
-
return true;
|
|
4927
|
-
}
|
|
4928
|
-
return false;
|
|
4588
|
+
function withToolkitEventsAt(compilerOptions, toolkitEventsPath) {
|
|
4589
|
+
return {
|
|
4590
|
+
...compilerOptions,
|
|
4591
|
+
paths: {
|
|
4592
|
+
...compilerOptions.paths,
|
|
4593
|
+
[TOOLKIT_EVENTS_MODULE2]: [toolkitEventsPath]
|
|
4594
|
+
}
|
|
4595
|
+
};
|
|
4929
4596
|
}
|
|
4930
|
-
function
|
|
4931
|
-
|
|
4932
|
-
|
|
4597
|
+
function rewriteVersionedEventConfigUses(sourceFile) {
|
|
4598
|
+
warnDestructuredVersionFields(sourceFile);
|
|
4599
|
+
const uses = [
|
|
4600
|
+
...findVersionFieldReads(sourceFile).map((node) => ({
|
|
4601
|
+
node,
|
|
4602
|
+
rewrite: (name) => `${name}(${node.getExpression().getText()}).${node.getName()}`
|
|
4603
|
+
})),
|
|
4604
|
+
...findValuesExpectingEventConfig(sourceFile).map(({ node, isArray }) => ({
|
|
4605
|
+
node,
|
|
4606
|
+
rewrite: (name) => isArray ? `${node.getText()}.map(${name})` : `${name}(${node.getText()})`
|
|
4607
|
+
}))
|
|
4608
|
+
].sort(
|
|
4609
|
+
(a, b) => b.node.getStart() - a.node.getStart() || a.node.getEnd() - b.node.getEnd()
|
|
4933
4610
|
);
|
|
4934
|
-
if (
|
|
4935
|
-
|
|
4936
|
-
if (!named) return false;
|
|
4937
|
-
named.remove();
|
|
4938
|
-
if (importDeclaration.getNamedImports().length === 0 && !importDeclaration.getDefaultImport() && !importDeclaration.getNamespaceImport()) {
|
|
4939
|
-
importDeclaration.remove();
|
|
4611
|
+
if (uses.length === 0) {
|
|
4612
|
+
return 0;
|
|
4940
4613
|
}
|
|
4941
|
-
|
|
4942
|
-
|
|
4943
|
-
|
|
4944
|
-
|
|
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())
|
|
4614
|
+
const resolveEventConfigName = findResolveEventConfigName(sourceFile);
|
|
4615
|
+
if (!resolveEventConfigName) {
|
|
4616
|
+
console.warn(
|
|
4617
|
+
` [${location3(uses[uses.length - 1].node)}] Skipped ${uses.length} use(s): the file already declares its own \`${RESOLVE_EVENT_CONFIG_NAME}\`. Rewrite them to use the toolkit's \`${RESOLVE_EVENT_CONFIG_NAME}()\` by hand.`
|
|
4951
4618
|
);
|
|
4952
|
-
|
|
4953
|
-
for (const importDeclaration of [...sourceFile.getImportDeclarations()]) {
|
|
4954
|
-
const imported = [
|
|
4955
|
-
importDeclaration.getDefaultImport()?.getText(),
|
|
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
|
-
}
|
|
4962
|
-
}
|
|
4963
|
-
console.log(` \u2713 ${file}: SENTRY`);
|
|
4619
|
+
return 0;
|
|
4964
4620
|
}
|
|
4621
|
+
for (const { node, rewrite } of uses) {
|
|
4622
|
+
const before = node.getText();
|
|
4623
|
+
const after = rewrite(resolveEventConfigName);
|
|
4624
|
+
console.log(` [${location3(node)}] ${before} -> ${after}`);
|
|
4625
|
+
node.replaceWithText(after);
|
|
4626
|
+
}
|
|
4627
|
+
addResolveEventConfigImport(sourceFile);
|
|
4628
|
+
return uses.length;
|
|
4965
4629
|
}
|
|
4966
|
-
function
|
|
4967
|
-
const
|
|
4968
|
-
|
|
4630
|
+
async function main5() {
|
|
4631
|
+
const srcDir = import_path6.default.join(process.cwd(), "src");
|
|
4632
|
+
console.log(
|
|
4633
|
+
`Scanning for VersionedEventConfig used as an EventConfig in: ${srcDir}
|
|
4634
|
+
`
|
|
4969
4635
|
);
|
|
4970
|
-
|
|
4971
|
-
const
|
|
4972
|
-
|
|
4973
|
-
|
|
4974
|
-
|
|
4636
|
+
const tsConfigFilePath = import_path6.default.resolve(srcDir, "../tsconfig.json");
|
|
4637
|
+
const project = new import_ts_morph5.Project({
|
|
4638
|
+
tsConfigFilePath,
|
|
4639
|
+
skipAddingFilesFromTsConfig: false,
|
|
4640
|
+
// The events module of this toolkit, next to the migrations in `dist`
|
|
4641
|
+
compilerOptions: withToolkitEventsAt(
|
|
4642
|
+
(0, import_ts_morph5.getCompilerOptionsFromTsConfig)(tsConfigFilePath).options,
|
|
4643
|
+
import_path6.default.resolve(__dirname, "../events")
|
|
4644
|
+
)
|
|
4645
|
+
});
|
|
4646
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
4647
|
+
const fp = sf.getFilePath();
|
|
4648
|
+
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
4649
|
+
});
|
|
4650
|
+
console.log(`Found ${sourceFiles.length} source file(s) to analyse.
|
|
4651
|
+
`);
|
|
4652
|
+
let totalChanges = 0;
|
|
4653
|
+
const modifiedFiles = [];
|
|
4654
|
+
for (const sourceFile of sourceFiles) {
|
|
4655
|
+
const changes = rewriteVersionedEventConfigUses(sourceFile);
|
|
4656
|
+
if (changes > 0) {
|
|
4657
|
+
totalChanges += changes;
|
|
4658
|
+
modifiedFiles.push(sourceFile);
|
|
4659
|
+
}
|
|
4660
|
+
}
|
|
4661
|
+
if (modifiedFiles.length === 0) {
|
|
4662
|
+
console.log(
|
|
4663
|
+
"No VersionedEventConfig used as an EventConfig found. Nothing to do."
|
|
4975
4664
|
);
|
|
4976
4665
|
return;
|
|
4977
4666
|
}
|
|
4978
|
-
|
|
4979
|
-
|
|
4980
|
-
|
|
4981
|
-
|
|
4982
|
-
|
|
4983
|
-
|
|
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
|
-
)
|
|
4667
|
+
console.log(`
|
|
4668
|
+
Saving ${modifiedFiles.length} modified file(s)...`);
|
|
4669
|
+
for (const sourceFile of modifiedFiles) {
|
|
4670
|
+
await sourceFile.save();
|
|
4671
|
+
console.log(
|
|
4672
|
+
` Saved: ${import_path6.default.relative(process.cwd(), sourceFile.getFilePath())}`
|
|
4994
4673
|
);
|
|
4995
|
-
if (matching.length === 0) continue;
|
|
4996
|
-
const names = matching.map((declaration) => declaration.getName());
|
|
4997
|
-
if (matching.length === declarations.length) {
|
|
4998
|
-
statement.remove();
|
|
4999
|
-
} else {
|
|
5000
|
-
for (const declaration of matching) {
|
|
5001
|
-
declaration.remove();
|
|
5002
|
-
}
|
|
5003
|
-
}
|
|
5004
|
-
console.log(` \u2713 ${CONSTANTS_FILE}: ${names.join(", ")}`);
|
|
5005
4674
|
}
|
|
5006
|
-
|
|
5007
|
-
|
|
5008
|
-
|
|
5009
|
-
import_path8.default.join(cwd, INDEX_FILE2)
|
|
5010
|
-
);
|
|
5011
|
-
if (!sourceFile) return;
|
|
5012
|
-
const pluginImport = sourceFile.getImportDeclarations().find(
|
|
5013
|
-
(declaration) => declaration.getModuleSpecifierValue() === SENTRY_PLUGIN
|
|
5014
|
-
);
|
|
5015
|
-
const pluginName = pluginImport?.getNamespaceImport()?.getText() ?? pluginImport?.getDefaultImport()?.getText() ?? "Sentry";
|
|
5016
|
-
const registration = sourceFile.getDescendantsOfKind(import_ts_morph4.SyntaxKind.IfStatement).find(
|
|
5017
|
-
(statement) => /\bSENTRY_DSN\b/.test(statement.getExpression().getText()) && new RegExp(`\\bplugin:\\s*${pluginName}\\b`).test(statement.getText())
|
|
4675
|
+
console.log(
|
|
4676
|
+
`
|
|
4677
|
+
Done. Rewrote ${totalChanges} use(s) across ${modifiedFiles.length} file(s).`
|
|
5018
4678
|
);
|
|
5019
|
-
|
|
5020
|
-
|
|
5021
|
-
|
|
5022
|
-
|
|
5023
|
-
|
|
5024
|
-
|
|
4679
|
+
}
|
|
4680
|
+
|
|
4681
|
+
// src/migrations/persistent/update-toolkit-dependency.ts
|
|
4682
|
+
var import_fs3 = __toESM(require("fs"));
|
|
4683
|
+
var import_path8 = __toESM(require("path"));
|
|
4684
|
+
|
|
4685
|
+
// src/migrations/persistent/check-upgrade-path.ts
|
|
4686
|
+
var import_fs2 = __toESM(require("fs"));
|
|
4687
|
+
var import_path7 = __toESM(require("path"));
|
|
4688
|
+
var TOOLKIT_PACKAGE_NAME = "@opencrvs/toolkit";
|
|
4689
|
+
function findMajorMinor(version) {
|
|
4690
|
+
const match = /(\d+)\.(\d+)/.exec(version);
|
|
4691
|
+
return match ? { major: Number(match[1]), minor: Number(match[2]) } : void 0;
|
|
4692
|
+
}
|
|
4693
|
+
function format({ major, minor }) {
|
|
4694
|
+
return `${major}.${minor}`;
|
|
4695
|
+
}
|
|
4696
|
+
function findCountryConfigToolkitVersion(cwd) {
|
|
4697
|
+
try {
|
|
4698
|
+
const packageJson = JSON.parse(
|
|
4699
|
+
import_fs2.default.readFileSync(import_path7.default.join(cwd, "package.json"), "utf-8")
|
|
5025
4700
|
);
|
|
4701
|
+
return packageJson.dependencies?.[TOOLKIT_PACKAGE_NAME] ?? packageJson.devDependencies?.[TOOLKIT_PACKAGE_NAME];
|
|
4702
|
+
} catch {
|
|
4703
|
+
return void 0;
|
|
5026
4704
|
}
|
|
5027
|
-
|
|
5028
|
-
|
|
5029
|
-
);
|
|
5030
|
-
|
|
5031
|
-
|
|
5032
|
-
|
|
5033
|
-
|
|
5034
|
-
|
|
5035
|
-
|
|
5036
|
-
);
|
|
4705
|
+
}
|
|
4706
|
+
function checkUpgradePath(countryConfigToolkitVersion, toolkitVersion) {
|
|
4707
|
+
const target = findMajorMinor(toolkitVersion);
|
|
4708
|
+
const current = countryConfigToolkitVersion ? findMajorMinor(countryConfigToolkitVersion) : void 0;
|
|
4709
|
+
if (!target || !current) {
|
|
4710
|
+
return {
|
|
4711
|
+
status: "unknown",
|
|
4712
|
+
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.`
|
|
4713
|
+
};
|
|
5037
4714
|
}
|
|
5038
|
-
|
|
5039
|
-
|
|
4715
|
+
const isSameVersion = current.major === target.major && current.minor === target.minor;
|
|
4716
|
+
const isPreviousMinor = current.major === target.major && current.minor === target.minor - 1;
|
|
4717
|
+
const isPreviousMajor = target.minor === 0 && current.major === target.major - 1;
|
|
4718
|
+
if (isSameVersion || isPreviousMinor || isPreviousMajor) {
|
|
4719
|
+
return { status: "ok" };
|
|
5040
4720
|
}
|
|
5041
|
-
|
|
5042
|
-
|
|
5043
|
-
|
|
5044
|
-
|
|
5045
|
-
|
|
5046
|
-
|
|
5047
|
-
}
|
|
5048
|
-
}
|
|
4721
|
+
const isNewer = current.major > target.major || current.major === target.major && current.minor > target.minor;
|
|
4722
|
+
if (isNewer) {
|
|
4723
|
+
return {
|
|
4724
|
+
status: "blocked",
|
|
4725
|
+
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.`
|
|
4726
|
+
};
|
|
5049
4727
|
}
|
|
4728
|
+
const upgradesFrom = target.minor > 0 ? format({ major: target.major, minor: target.minor - 1 }) : `the last ${target.major - 1}.x`;
|
|
4729
|
+
const nextStep = current.major === target.major ? `: run \`npx ${TOOLKIT_PACKAGE_NAME}@${format({ major: current.major, minor: current.minor + 1 })} upgrade\` first` : "";
|
|
4730
|
+
return {
|
|
4731
|
+
status: "blocked",
|
|
4732
|
+
message: `The country config is on ${format(current)}, but toolkit ${toolkitVersion} only upgrades from ${upgradesFrom}. Upgrade one minor version at a time${nextStep}.`
|
|
4733
|
+
};
|
|
5050
4734
|
}
|
|
5051
|
-
|
|
5052
|
-
|
|
5053
|
-
|
|
5054
|
-
)
|
|
5055
|
-
|
|
5056
|
-
|
|
5057
|
-
|
|
5058
|
-
|
|
5059
|
-
|
|
5060
|
-
|
|
5061
|
-
|
|
5062
|
-
|
|
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`
|
|
5074
|
-
);
|
|
5075
|
-
return;
|
|
5076
|
-
}
|
|
5077
|
-
const removed = [];
|
|
5078
|
-
for (const bucket of ["dependencies", "devDependencies"]) {
|
|
5079
|
-
const dependencies = parsed[bucket];
|
|
5080
|
-
if (!dependencies) continue;
|
|
5081
|
-
for (const name of Object.keys(dependencies)) {
|
|
5082
|
-
if (isSentryPackage(name)) {
|
|
5083
|
-
delete dependencies[name];
|
|
5084
|
-
removed.push(name);
|
|
4735
|
+
|
|
4736
|
+
// src/migrations/persistent/update-toolkit-dependency.ts
|
|
4737
|
+
var DEPENDENCY_PATTERN = new RegExp(
|
|
4738
|
+
`("${TOOLKIT_PACKAGE_NAME}"\\s*:\\s*")([^"]*)(")`,
|
|
4739
|
+
"g"
|
|
4740
|
+
);
|
|
4741
|
+
function updateToolkitDependency(packageJson, toolkitVersion) {
|
|
4742
|
+
const updated = packageJson.replace(
|
|
4743
|
+
DEPENDENCY_PATTERN,
|
|
4744
|
+
(match, before, version, after) => {
|
|
4745
|
+
if (!findMajorMinor(version)) {
|
|
4746
|
+
return match;
|
|
5085
4747
|
}
|
|
4748
|
+
const range = /^[\^~]?/.exec(version)?.[0] ?? "";
|
|
4749
|
+
return `${before}${range}${toolkitVersion}${after}`;
|
|
5086
4750
|
}
|
|
5087
|
-
}
|
|
5088
|
-
if (removed.length === 0) return;
|
|
5089
|
-
const trailingNewline = raw.endsWith("\n") ? "\n" : "";
|
|
5090
|
-
(0, import_fs7.writeFileSync)(
|
|
5091
|
-
packageJsonPath,
|
|
5092
|
-
`${JSON.stringify(parsed, null, 2)}${trailingNewline}`
|
|
5093
4751
|
);
|
|
5094
|
-
|
|
5095
|
-
}
|
|
5096
|
-
function
|
|
5097
|
-
const
|
|
5098
|
-
if (!
|
|
5099
|
-
|
|
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
|
-
);
|
|
4752
|
+
return updated === packageJson ? void 0 : updated;
|
|
4753
|
+
}
|
|
4754
|
+
async function main6(toolkitVersion) {
|
|
4755
|
+
const packageJsonPath = import_path8.default.join(process.cwd(), "package.json");
|
|
4756
|
+
if (!import_fs3.default.existsSync(packageJsonPath)) {
|
|
4757
|
+
console.log(`No package.json found. Skipping ${TOOLKIT_PACKAGE_NAME}.`);
|
|
5104
4758
|
return;
|
|
5105
4759
|
}
|
|
5106
|
-
|
|
5107
|
-
|
|
5108
|
-
|
|
5109
|
-
|
|
5110
|
-
|
|
5111
|
-
|
|
5112
|
-
|
|
5113
|
-
// ts-morph indents with four spaces and double-quotes strings by default,
|
|
5114
|
-
// both of which the country config's prettier run would undo.
|
|
5115
|
-
manipulationSettings: {
|
|
5116
|
-
indentationText: import_ts_morph4.IndentationText.TwoSpaces,
|
|
5117
|
-
quoteKind: import_ts_morph4.QuoteKind.Single
|
|
5118
|
-
}
|
|
5119
|
-
});
|
|
5120
|
-
removeSentryFromConfigs(project, cwd);
|
|
5121
|
-
removeEnvironmentVariable(project, cwd);
|
|
5122
|
-
removeConstant(project, cwd);
|
|
5123
|
-
unwireIndex(project, cwd);
|
|
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:`
|
|
4760
|
+
const updated = updateToolkitDependency(
|
|
4761
|
+
import_fs3.default.readFileSync(packageJsonPath, "utf-8"),
|
|
4762
|
+
toolkitVersion
|
|
4763
|
+
);
|
|
4764
|
+
if (!updated) {
|
|
4765
|
+
console.log(
|
|
4766
|
+
`${TOOLKIT_PACKAGE_NAME} in package.json needs no update. Nothing to do.`
|
|
5132
4767
|
);
|
|
5133
|
-
|
|
5134
|
-
console.warn(` - ${message}`);
|
|
5135
|
-
}
|
|
4768
|
+
return;
|
|
5136
4769
|
}
|
|
4770
|
+
import_fs3.default.writeFileSync(packageJsonPath, updated);
|
|
4771
|
+
console.log(
|
|
4772
|
+
`Updated ${TOOLKIT_PACKAGE_NAME} to ${toolkitVersion} in package.json. Install the dependencies again to use it.`
|
|
4773
|
+
);
|
|
5137
4774
|
}
|
|
5138
4775
|
|
|
5139
|
-
// src/migrations/
|
|
5140
|
-
var
|
|
4776
|
+
// src/migrations/replace-incomplete-flag.ts
|
|
4777
|
+
var import_ts_morph6 = require("ts-morph");
|
|
5141
4778
|
var import_path9 = __toESM(require("path"));
|
|
5142
|
-
var
|
|
5143
|
-
|
|
5144
|
-
|
|
5145
|
-
|
|
5146
|
-
|
|
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())
|
|
5170
|
-
);
|
|
5171
|
-
if (!allVerbs) return false;
|
|
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
|
|
4779
|
+
var INCOMPLETE = "InherentFlags.INCOMPLETE";
|
|
4780
|
+
var NOTIFIED_STATUS = `{ type: 'exact', term: EventStatus.enum.NOTIFIED }`;
|
|
4781
|
+
function ensureEventStatusImport(sourceFile) {
|
|
4782
|
+
const importDeclaration = sourceFile.getImportDeclarations().find(
|
|
4783
|
+
(declaration) => declaration.getNamedImports().some((named) => named.getName() === "InherentFlags")
|
|
5202
4784
|
);
|
|
5203
|
-
|
|
5204
|
-
|
|
5205
|
-
|
|
5206
|
-
if (newPath) {
|
|
5207
|
-
renamedCount++;
|
|
5208
|
-
console.log(` [${relPath}] Renamed route path \u2192 '${newPath}'`);
|
|
5209
|
-
}
|
|
4785
|
+
const hasEventStatus = importDeclaration?.getNamedImports().some((named) => named.getName() === "EventStatus");
|
|
4786
|
+
if (importDeclaration && !hasEventStatus) {
|
|
4787
|
+
importDeclaration.addNamedImport("EventStatus");
|
|
5210
4788
|
}
|
|
5211
|
-
return renamedCount;
|
|
5212
4789
|
}
|
|
5213
|
-
function
|
|
5214
|
-
|
|
5215
|
-
|
|
5216
|
-
const
|
|
5217
|
-
const
|
|
5218
|
-
|
|
5219
|
-
|
|
5220
|
-
|
|
5221
|
-
|
|
5222
|
-
|
|
4790
|
+
function replaceIncompleteFlag(sourceFile) {
|
|
4791
|
+
let changed = false;
|
|
4792
|
+
const anyOfIncomplete = sourceFile.getDescendantsOfKind(import_ts_morph6.SyntaxKind.PropertyAccessExpression).filter((node) => node.getText() === INCOMPLETE).map((node) => node.getParent()).filter(import_ts_morph6.Node.isArrayLiteralExpression).filter((array2) => {
|
|
4793
|
+
const anyOf = array2.getParent();
|
|
4794
|
+
const flags = anyOf?.getParent()?.getParent();
|
|
4795
|
+
return import_ts_morph6.Node.isPropertyAssignment(anyOf) && anyOf.getName() === "anyOf" && import_ts_morph6.Node.isPropertyAssignment(flags) && flags.getName() === "flags";
|
|
4796
|
+
});
|
|
4797
|
+
for (const array2 of anyOfIncomplete) {
|
|
4798
|
+
const anyOf = array2.getParentIfKindOrThrow(import_ts_morph6.SyntaxKind.PropertyAssignment);
|
|
4799
|
+
const flagsObject = anyOf.getParentIfKindOrThrow(
|
|
4800
|
+
import_ts_morph6.SyntaxKind.ObjectLiteralExpression
|
|
4801
|
+
);
|
|
4802
|
+
const flags = flagsObject.getParentIfKindOrThrow(
|
|
4803
|
+
import_ts_morph6.SyntaxKind.PropertyAssignment
|
|
4804
|
+
);
|
|
4805
|
+
const query = flags.getParentIfKindOrThrow(
|
|
4806
|
+
import_ts_morph6.SyntaxKind.ObjectLiteralExpression
|
|
4807
|
+
);
|
|
4808
|
+
array2.getElements().filter((element) => element.getText() === INCOMPLETE).forEach((element) => array2.removeElement(element));
|
|
4809
|
+
if (array2.getElements().length === 0) anyOf.remove();
|
|
4810
|
+
if (flagsObject.getProperties().length === 0) flags.remove();
|
|
4811
|
+
if (!query.getProperty("status")) {
|
|
4812
|
+
query.addPropertyAssignment({
|
|
4813
|
+
name: "status",
|
|
4814
|
+
initializer: NOTIFIED_STATUS
|
|
4815
|
+
});
|
|
4816
|
+
}
|
|
4817
|
+
changed = true;
|
|
5223
4818
|
}
|
|
5224
|
-
if (
|
|
5225
|
-
|
|
5226
|
-
|
|
5227
|
-
WARNING: ${stale.length} remaining '${STALE_PREFIX}' reference(s) need to be renamed by hand:`
|
|
5228
|
-
);
|
|
5229
|
-
console.log(stale.join("\n"));
|
|
4819
|
+
if (changed) ensureEventStatusImport(sourceFile);
|
|
4820
|
+
const remaining = sourceFile.getDescendantsOfKind(import_ts_morph6.SyntaxKind.PropertyAccessExpression).filter((node) => node.getText() === INCOMPLETE).map((node) => node.getStartLineNumber());
|
|
4821
|
+
return { changed, remaining };
|
|
5230
4822
|
}
|
|
5231
|
-
async function
|
|
5232
|
-
const
|
|
5233
|
-
|
|
5234
|
-
`);
|
|
5235
|
-
console.log("Active path renames:");
|
|
5236
|
-
for (const [from, to] of Object.entries(PATH_PREFIX_RENAMES)) {
|
|
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"),
|
|
5242
|
-
skipAddingFilesFromTsConfig: false
|
|
5243
|
-
});
|
|
5244
|
-
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
5245
|
-
const fp = sf.getFilePath();
|
|
5246
|
-
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
4823
|
+
async function main7() {
|
|
4824
|
+
const project = new import_ts_morph6.Project({
|
|
4825
|
+
tsConfigFilePath: import_path9.default.join(process.cwd(), "tsconfig.json")
|
|
5247
4826
|
});
|
|
5248
|
-
|
|
5249
|
-
`);
|
|
5250
|
-
let totalRenamed = 0;
|
|
5251
|
-
const modifiedFiles = [];
|
|
4827
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => !sf.getFilePath().includes("/node_modules/"));
|
|
5252
4828
|
for (const sourceFile of sourceFiles) {
|
|
5253
|
-
const
|
|
5254
|
-
const
|
|
5255
|
-
if (
|
|
5256
|
-
totalRenamed += renamed;
|
|
5257
|
-
modifiedFiles.push(filePath);
|
|
5258
|
-
}
|
|
5259
|
-
}
|
|
5260
|
-
if (modifiedFiles.length === 0) {
|
|
5261
|
-
console.log("No trigger route paths to rename.");
|
|
5262
|
-
} else {
|
|
5263
|
-
console.log(`
|
|
5264
|
-
Saving ${modifiedFiles.length} modified file(s)...`);
|
|
5265
|
-
for (const filePath of modifiedFiles) {
|
|
5266
|
-
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
4829
|
+
const relPath = import_path9.default.relative(process.cwd(), sourceFile.getFilePath());
|
|
4830
|
+
const { changed, remaining } = replaceIncompleteFlag(sourceFile);
|
|
4831
|
+
if (changed) {
|
|
5267
4832
|
await sourceFile.save();
|
|
5268
|
-
console.log(
|
|
4833
|
+
console.log(
|
|
4834
|
+
` [${relPath}] Replaced the incomplete flag with the NOTIFIED status`
|
|
4835
|
+
);
|
|
5269
4836
|
}
|
|
5270
|
-
|
|
5271
|
-
|
|
5272
|
-
}
|
|
5273
|
-
|
|
5274
|
-
}
|
|
5275
|
-
|
|
5276
|
-
// src/migrations/v2.1/upgrade-tilt.ts
|
|
5277
|
-
var import_fs8 = require("fs");
|
|
5278
|
-
var import_path10 = __toESM(require("path"));
|
|
5279
|
-
var COUNTRY_OWNED_DIR = "tilt/helm/";
|
|
5280
|
-
var CHARTS_CHECKOUT_DIR = ".opencrvs-core-charts";
|
|
5281
|
-
var IMAGE_NAME_PATTERN = /^countryconfig_image_name\s*=\s*(["'])(.*?)\1/m;
|
|
5282
|
-
function writeIfChanged(cwd, relativePath, contents, mode) {
|
|
5283
|
-
const target = import_path10.default.join(cwd, relativePath);
|
|
5284
|
-
const existed = (0, import_fs8.existsSync)(target);
|
|
5285
|
-
if (existed && (0, import_fs8.readFileSync)(target, "utf8") === contents) {
|
|
5286
|
-
return "unchanged";
|
|
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
|
-
);
|
|
5309
|
-
}
|
|
5310
|
-
function withIgnoreEntry(contents, line2) {
|
|
5311
|
-
const normalise = (entry) => entry.trim().replace(/^\//, "").replace(/\/$/, "");
|
|
5312
|
-
const alreadyIgnored = contents.split(/\r?\n/).some((entry) => normalise(entry) === normalise(line2));
|
|
5313
|
-
if (alreadyIgnored) {
|
|
5314
|
-
return contents;
|
|
5315
|
-
}
|
|
5316
|
-
const separator = contents === "" || contents.endsWith("\n") ? "" : "\n";
|
|
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;
|
|
4837
|
+
for (const line2 of remaining) {
|
|
4838
|
+
console.warn(
|
|
4839
|
+
` [${relPath}:${line2}] ${INCOMPLETE} was removed, update this reference to use the NOTIFIED status`
|
|
4840
|
+
);
|
|
5345
4841
|
}
|
|
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
|
-
)
|
|
5354
|
-
);
|
|
5355
|
-
}
|
|
5356
|
-
const unknownFiles = listFiles(cwd, "tilt").filter(
|
|
5357
|
-
(file) => !file.startsWith(COUNTRY_OWNED_DIR) && !templateFiles.includes(file)
|
|
5358
|
-
);
|
|
5359
|
-
for (const file of unknownFiles) {
|
|
5360
|
-
console.warn(
|
|
5361
|
-
` \u26A0\uFE0F ${file} is not part of the template and was left in place.`
|
|
5362
|
-
);
|
|
5363
|
-
}
|
|
5364
|
-
ensureIgnored(cwd, ".tiltignore", `${CHARTS_CHECKOUT_DIR}/`);
|
|
5365
|
-
ensureIgnored(cwd, ".gitignore", CHARTS_CHECKOUT_DIR);
|
|
5366
|
-
if (existingTiltfile?.includes("opencrvs-helm-charts")) {
|
|
5367
|
-
console.log(
|
|
5368
|
-
` \u2139\uFE0F The Tiltfile no longer uses ../opencrvs-helm-charts; charts are cloned into ${CHARTS_CHECKOUT_DIR}/ instead. The old checkout can be deleted.`
|
|
5369
|
-
);
|
|
5370
4842
|
}
|
|
5371
4843
|
}
|
|
5372
|
-
async function main9() {
|
|
5373
|
-
console.log("Upgrading the local Tilt setup...\n");
|
|
5374
|
-
upgradeTilt(process.cwd(), findTemplateDir());
|
|
5375
|
-
console.log(
|
|
5376
|
-
"\n Review local customisations with: git diff -- Tiltfile tilt/ .tiltignore .gitignore\n"
|
|
5377
|
-
);
|
|
5378
|
-
}
|
|
5379
4844
|
|
|
5380
|
-
// src/migrations/
|
|
5381
|
-
async function runUpgrade(
|
|
5382
|
-
|
|
5383
|
-
await main8();
|
|
4845
|
+
// src/migrations/index.ts
|
|
4846
|
+
async function runUpgrade(toolkitVersion) {
|
|
4847
|
+
const [major, minor] = toolkitVersion.split(".");
|
|
5384
4848
|
await main2();
|
|
5385
4849
|
await main3();
|
|
5386
|
-
await
|
|
5387
|
-
await main6();
|
|
5388
|
-
await main5(dockerSwarm);
|
|
5389
|
-
await main9();
|
|
4850
|
+
await main5();
|
|
5390
4851
|
await main4();
|
|
4852
|
+
await main(`${major}.${minor}`);
|
|
4853
|
+
await main7();
|
|
4854
|
+
await main6(toolkitVersion);
|
|
5391
4855
|
}
|
|
5392
4856
|
|
|
5393
4857
|
// src/environment/index.ts
|
|
5394
|
-
var
|
|
5395
|
-
var
|
|
4858
|
+
var import_fs8 = require("fs");
|
|
4859
|
+
var import_path14 = require("path");
|
|
5396
4860
|
init_paths();
|
|
5397
4861
|
var REQUIRED_REPOSITORY_DIRECTORIES = [
|
|
5398
4862
|
".github/workflows",
|
|
@@ -5403,7 +4867,7 @@ function validateRepositoryStructure(repositoryRoot = process.cwd()) {
|
|
|
5403
4867
|
const missingDirectories = REQUIRED_REPOSITORY_DIRECTORIES.filter(
|
|
5404
4868
|
(directory) => {
|
|
5405
4869
|
try {
|
|
5406
|
-
return !(0,
|
|
4870
|
+
return !(0, import_fs8.statSync)((0, import_path14.resolve)(repositoryRoot, directory)).isDirectory();
|
|
5407
4871
|
} catch {
|
|
5408
4872
|
return true;
|
|
5409
4873
|
}
|
|
@@ -5444,7 +4908,7 @@ async function runEnvironmentSwarmToK8s() {
|
|
|
5444
4908
|
// src/verify/endpoints.ts
|
|
5445
4909
|
var import_colors = require("kleur/colors");
|
|
5446
4910
|
var z = __toESM(require("zod/v4"));
|
|
5447
|
-
var
|
|
4911
|
+
var REQUEST_TIMEOUT_MS2 = 15e3;
|
|
5448
4912
|
var DEFAULT_TARGET_URL = "http://localhost:3040";
|
|
5449
4913
|
var REQUIRED_PUBLIC_ENDPOINTS = [
|
|
5450
4914
|
{ method: "GET", path: "/client-config.js" },
|
|
@@ -5515,7 +4979,7 @@ async function requestStatus(url, method) {
|
|
|
5515
4979
|
try {
|
|
5516
4980
|
const response = await fetch(url, {
|
|
5517
4981
|
method,
|
|
5518
|
-
signal: AbortSignal.timeout(
|
|
4982
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS2),
|
|
5519
4983
|
// Sent without an Authorization header on purpose. A secured route
|
|
5520
4984
|
// rejects with 401/403 before ever reading the body.
|
|
5521
4985
|
headers: method === "POST" ? { "Content-Type": "application/json" } : void 0,
|
|
@@ -5526,40 +4990,30 @@ async function requestStatus(url, method) {
|
|
|
5526
4990
|
return "error";
|
|
5527
4991
|
}
|
|
5528
4992
|
}
|
|
5529
|
-
|
|
5530
|
-
|
|
5531
|
-
|
|
5532
|
-
|
|
5533
|
-
|
|
5534
|
-
|
|
5535
|
-
|
|
5536
|
-
|
|
5537
|
-
const
|
|
5538
|
-
|
|
5539
|
-
|
|
5540
|
-
|
|
5541
|
-
|
|
5542
|
-
}
|
|
5543
|
-
const type = action.type;
|
|
5544
|
-
return typeof type === "string" ? type : null;
|
|
5545
|
-
}).filter((type) => type !== null)
|
|
5546
|
-
)
|
|
5547
|
-
) : [];
|
|
5548
|
-
return { id: record2.id, actions };
|
|
4993
|
+
var ServedEventConfigVersion = z.object({
|
|
4994
|
+
actions: z.array(z.object({ type: z.string() }))
|
|
4995
|
+
});
|
|
4996
|
+
var ServedEventConfig = z.union([
|
|
4997
|
+
z.object({ id: z.string(), versions: z.array(ServedEventConfigVersion) }),
|
|
4998
|
+
ServedEventConfigVersion.extend({ id: z.string() })
|
|
4999
|
+
]);
|
|
5000
|
+
function toEventTriggerConfig(config) {
|
|
5001
|
+
const versions = "versions" in config ? config.versions : [config];
|
|
5002
|
+
const actions = versions.flatMap(
|
|
5003
|
+
(version) => version.actions.map(({ type }) => type)
|
|
5004
|
+
);
|
|
5005
|
+
return { id: config.id, actions: Array.from(new Set(actions)) };
|
|
5549
5006
|
}
|
|
5550
5007
|
async function fetchEventConfigs(baseUrl) {
|
|
5551
5008
|
try {
|
|
5552
5009
|
const response = await fetch(`${baseUrl}/config/events`, {
|
|
5553
|
-
signal: AbortSignal.timeout(
|
|
5010
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS2)
|
|
5554
5011
|
});
|
|
5555
5012
|
if (!response.ok) {
|
|
5556
5013
|
return null;
|
|
5557
5014
|
}
|
|
5558
|
-
const
|
|
5559
|
-
|
|
5560
|
-
return null;
|
|
5561
|
-
}
|
|
5562
|
-
return body.map(toEventTriggerConfig).filter((config) => config !== null);
|
|
5015
|
+
const parsed = z.array(ServedEventConfig).safeParse(await response.json());
|
|
5016
|
+
return parsed.success ? parsed.data.map(toEventTriggerConfig) : null;
|
|
5563
5017
|
} catch {
|
|
5564
5018
|
return null;
|
|
5565
5019
|
}
|
|
@@ -5614,7 +5068,7 @@ var ServedTranslations = z.object({
|
|
|
5614
5068
|
async function fetchServedTranslations(baseUrl, application) {
|
|
5615
5069
|
try {
|
|
5616
5070
|
const response = await fetch(`${baseUrl}/content/${application}`, {
|
|
5617
|
-
signal: AbortSignal.timeout(
|
|
5071
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS2)
|
|
5618
5072
|
});
|
|
5619
5073
|
if (!response.ok) {
|
|
5620
5074
|
return null;
|
|
@@ -5630,10 +5084,10 @@ async function verifyTranslations(baseUrl) {
|
|
|
5630
5084
|
let refs;
|
|
5631
5085
|
try {
|
|
5632
5086
|
refs = await candidateRefs(TEMPLATE_VERSION);
|
|
5633
|
-
} catch (
|
|
5087
|
+
} catch (error2) {
|
|
5634
5088
|
console.log(
|
|
5635
5089
|
" " + (0, import_colors.yellow)(
|
|
5636
|
-
`Could not list the ${TEMPLATE_VERSION} refs on GitHub (${
|
|
5090
|
+
`Could not list the ${TEMPLATE_VERSION} refs on GitHub (${error2.message}); translations not checked.`
|
|
5637
5091
|
)
|
|
5638
5092
|
);
|
|
5639
5093
|
return 0;
|
|
@@ -5644,10 +5098,10 @@ async function verifyTranslations(baseUrl) {
|
|
|
5644
5098
|
let fetched;
|
|
5645
5099
|
try {
|
|
5646
5100
|
fetched = await fetchTemplate(refs, application);
|
|
5647
|
-
} catch (
|
|
5101
|
+
} catch (error2) {
|
|
5648
5102
|
console.log(
|
|
5649
5103
|
" " + (0, import_colors.yellow)(
|
|
5650
|
-
`Could not read ${application}.csv from the country config template on GitHub (${
|
|
5104
|
+
`Could not read ${application}.csv from the country config template on GitHub (${error2.message}); ${endpoint} not checked.`
|
|
5651
5105
|
)
|
|
5652
5106
|
);
|
|
5653
5107
|
continue;
|
|
@@ -5730,8 +5184,8 @@ async function runVerifyEndpoints(target = DEFAULT_TARGET_URL) {
|
|
|
5730
5184
|
console.log(line(ok, endpointLabel(check), detail));
|
|
5731
5185
|
}
|
|
5732
5186
|
{
|
|
5733
|
-
const
|
|
5734
|
-
const status = await requestStatus(`${baseUrl}${
|
|
5187
|
+
const path15 = `/fonts/${PROBE_SEGMENT}.ttf`;
|
|
5188
|
+
const status = await requestStatus(`${baseUrl}${path15}`, "GET");
|
|
5735
5189
|
const ok = status === 200 || status === 404;
|
|
5736
5190
|
if (!ok) {
|
|
5737
5191
|
failures++;
|
|
@@ -5746,7 +5200,7 @@ async function runVerifyEndpoints(target = DEFAULT_TARGET_URL) {
|
|
|
5746
5200
|
} else {
|
|
5747
5201
|
detail = `${describeStatus(status)} \u2014 unexpected`;
|
|
5748
5202
|
}
|
|
5749
|
-
console.log(line(ok, `GET /fonts/{filename}${(0, import_colors.dim)(` \u2192 ${
|
|
5203
|
+
console.log(line(ok, `GET /fonts/{filename}${(0, import_colors.dim)(` \u2192 ${path15}`)}`, detail));
|
|
5750
5204
|
}
|
|
5751
5205
|
console.log();
|
|
5752
5206
|
console.log((0, import_colors.bold)("Secured endpoints (must be absent or require auth):"));
|
|
@@ -5799,13 +5253,13 @@ async function runVerifyEndpoints(target = DEFAULT_TARGET_URL) {
|
|
|
5799
5253
|
line(true, pattern, `${actions.length} action(s) \u2014 all require auth`)
|
|
5800
5254
|
);
|
|
5801
5255
|
} else {
|
|
5802
|
-
for (const
|
|
5256
|
+
for (const failure2 of failed) {
|
|
5803
5257
|
failures++;
|
|
5804
5258
|
console.log(
|
|
5805
5259
|
line(
|
|
5806
5260
|
false,
|
|
5807
|
-
`POST /trigger/events/${event.id}/actions/${
|
|
5808
|
-
securedDetail(
|
|
5261
|
+
`POST /trigger/events/${event.id}/actions/${failure2.action}`,
|
|
5262
|
+
securedDetail(failure2.status)
|
|
5809
5263
|
)
|
|
5810
5264
|
);
|
|
5811
5265
|
}
|
|
@@ -5873,18 +5327,20 @@ Exits with a non-zero status if any check fails.
|
|
|
5873
5327
|
var UPGRADE_USAGE = `
|
|
5874
5328
|
Usage: opencrvs upgrade [options]
|
|
5875
5329
|
|
|
5876
|
-
Upgrade the country config in the current working directory to
|
|
5877
|
-
|
|
5330
|
+
Upgrade the country config in the current working directory to this toolkit's
|
|
5331
|
+
version of OpenCRVS. Upgrade one minor version at a time: toolkit 2.2 upgrades
|
|
5332
|
+
a country config on 2.1.
|
|
5333
|
+
|
|
5334
|
+
The upgrade tells which version the country config is on by its
|
|
5335
|
+
@opencrvs/toolkit dependency, and updates that dependency itself once done.
|
|
5336
|
+
Run it without changing the dependency first, e.g.
|
|
5337
|
+
|
|
5338
|
+
npx @opencrvs/toolkit@2.2 upgrade
|
|
5878
5339
|
|
|
5879
5340
|
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
5341
|
-h, --help Show this message.
|
|
5886
5342
|
`.trim();
|
|
5887
|
-
function
|
|
5343
|
+
function main8() {
|
|
5888
5344
|
const command = args[0];
|
|
5889
5345
|
if (!command || command === "--help" || command === "-h") {
|
|
5890
5346
|
console.log(USAGE);
|
|
@@ -5946,37 +5402,52 @@ Subcommands:
|
|
|
5946
5402
|
async function runEnvironmentCommand(operation, command) {
|
|
5947
5403
|
try {
|
|
5948
5404
|
await command();
|
|
5949
|
-
} catch (
|
|
5405
|
+
} catch (error2) {
|
|
5950
5406
|
console.error(
|
|
5951
5407
|
`Environment ${operation} failed:`,
|
|
5952
|
-
|
|
5408
|
+
error2 instanceof Error ? error2.message : error2
|
|
5953
5409
|
);
|
|
5954
5410
|
process.exit(1);
|
|
5955
5411
|
}
|
|
5956
5412
|
}
|
|
5413
|
+
function readToolkitVersion() {
|
|
5414
|
+
const packageJson = JSON.parse(
|
|
5415
|
+
import_fs9.default.readFileSync(import_path15.default.join(__dirname, "..", "package.json"), "utf-8")
|
|
5416
|
+
);
|
|
5417
|
+
return packageJson.version;
|
|
5418
|
+
}
|
|
5957
5419
|
async function handleUpgrade() {
|
|
5958
5420
|
const upgradeArgs = args.slice(1);
|
|
5959
5421
|
if (upgradeArgs.includes("--help") || upgradeArgs.includes("-h")) {
|
|
5960
5422
|
console.log(UPGRADE_USAGE);
|
|
5961
5423
|
process.exit(0);
|
|
5962
5424
|
}
|
|
5963
|
-
const
|
|
5964
|
-
const unknownFlags = upgradeArgs.filter(
|
|
5965
|
-
(arg) => arg.startsWith("-") && !KNOWN_FLAGS.has(arg)
|
|
5966
|
-
);
|
|
5425
|
+
const unknownFlags = upgradeArgs.filter((arg) => arg.startsWith("-"));
|
|
5967
5426
|
if (unknownFlags.length > 0) {
|
|
5968
5427
|
console.error(`Unknown option(s): ${unknownFlags.join(", ")}
|
|
5969
5428
|
`);
|
|
5970
5429
|
console.log(UPGRADE_USAGE);
|
|
5971
5430
|
process.exit(1);
|
|
5972
5431
|
}
|
|
5973
|
-
const
|
|
5432
|
+
const toolkitVersion = readToolkitVersion();
|
|
5433
|
+
const upgradePath = checkUpgradePath(
|
|
5434
|
+
findCountryConfigToolkitVersion(process.cwd()),
|
|
5435
|
+
toolkitVersion
|
|
5436
|
+
);
|
|
5437
|
+
if (upgradePath.status === "unknown") {
|
|
5438
|
+
console.warn(`\u26A0\uFE0F ${upgradePath.message}
|
|
5439
|
+
`);
|
|
5440
|
+
}
|
|
5441
|
+
if (upgradePath.status === "blocked") {
|
|
5442
|
+
console.error(upgradePath.message);
|
|
5443
|
+
process.exit(1);
|
|
5444
|
+
}
|
|
5974
5445
|
console.log("Initiating upgrade...");
|
|
5975
5446
|
try {
|
|
5976
|
-
await runUpgrade(
|
|
5447
|
+
await runUpgrade(toolkitVersion);
|
|
5977
5448
|
console.log("Upgrade completed successfully!");
|
|
5978
|
-
} catch (
|
|
5979
|
-
console.error("Upgrade failed:",
|
|
5449
|
+
} catch (error2) {
|
|
5450
|
+
console.error("Upgrade failed:", error2);
|
|
5980
5451
|
process.exit(1);
|
|
5981
5452
|
}
|
|
5982
5453
|
}
|
|
@@ -5997,12 +5468,12 @@ async function handleVerifyEndpoints() {
|
|
|
5997
5468
|
}
|
|
5998
5469
|
try {
|
|
5999
5470
|
await runVerifyEndpoints(positional[0]);
|
|
6000
|
-
} catch (
|
|
5471
|
+
} catch (error2) {
|
|
6001
5472
|
console.error(
|
|
6002
5473
|
"Endpoint verification failed:",
|
|
6003
|
-
|
|
5474
|
+
error2 instanceof Error ? error2.message : error2
|
|
6004
5475
|
);
|
|
6005
5476
|
process.exit(1);
|
|
6006
5477
|
}
|
|
6007
5478
|
}
|
|
6008
|
-
|
|
5479
|
+
main8();
|