@opencrvs/toolkit 2.1.0-rc.99061f0 → 2.1.0-rc.9a83eed
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -12
- package/build.sh +9 -1
- package/create-countryconfig/index.js +412 -59
- package/create-countryconfig/node_modules/.bin/degit +21 -0
- package/create-countryconfig/package.json +4 -1
- package/dist/application-config/index.js +347 -281
- package/dist/authentication/index.d.ts +67 -0
- package/dist/authentication/index.d.ts.map +1 -0
- package/dist/authentication/index.js +751 -0
- package/dist/cli.js +2077 -299
- package/dist/commons/api/router.d.ts +689 -110
- package/dist/commons/conditionals/conditionals.d.ts +6 -6
- package/dist/commons/conditionals/validate.d.ts +16 -5
- package/dist/commons/events/ActionConfig.d.ts +4 -0
- package/dist/commons/events/ActionDocument.d.ts +5 -11
- package/dist/commons/events/ActionInput.d.ts +4 -4
- package/dist/commons/events/ActionStatus.d.ts +14 -0
- package/dist/commons/events/AdvancedSearchConfig.d.ts +36 -12
- package/dist/commons/events/AuditLog.d.ts +147 -0
- package/dist/commons/events/EventConfig.d.ts +3 -0
- package/dist/commons/events/EventDocument.d.ts +470 -2
- package/dist/commons/events/EventIndex.d.ts +3 -26
- package/dist/commons/events/EventMetadata.d.ts +1 -11
- package/dist/commons/events/EventStatus.d.ts +19 -0
- package/dist/commons/events/FieldConfig.d.ts +99 -63
- package/dist/commons/events/FieldTypeMapping.d.ts +27 -27
- package/dist/commons/events/FieldValue.d.ts +2 -2
- package/dist/commons/events/Flag.d.ts +42 -0
- package/dist/commons/events/FormConfig.d.ts +6 -0
- package/dist/commons/events/PageConfig.d.ts +4 -0
- package/dist/commons/events/PlainDate.d.ts +8 -0
- package/dist/commons/events/SummaryConfig.d.ts +249 -0
- package/dist/commons/events/WorkqueueConfig.d.ts +17 -14
- package/dist/commons/events/event.d.ts +12 -0
- package/dist/commons/events/index.d.ts +1 -0
- package/dist/commons/events/locationPayloads.d.ts +95 -0
- package/dist/commons/events/locations.d.ts +169 -26
- package/dist/commons/events/mocks.test.utils.d.ts +30 -0
- package/dist/commons/events/test.utils.d.ts +25 -4
- package/dist/commons/events/utils.d.ts +17 -2
- package/dist/commons/notification/UserNotifications.d.ts +28 -13
- package/dist/commons/notification/dispatch.d.ts +10 -0
- package/dist/commons/notification/index.d.ts +1 -0
- package/dist/conditionals/index.js +335 -64
- package/dist/csv.d.ts +25 -0
- package/dist/csv.d.ts.map +1 -0
- package/dist/csv.js +120 -0
- package/dist/environment/logger.d.ts +15 -3
- package/dist/environment/logger.d.ts.map +1 -1
- package/dist/environment/manage-users.js +1 -1
- package/dist/environment/questions.d.ts.map +1 -1
- package/dist/environment/questions.js +20 -14
- package/dist/environment/setup-environment.js +45 -27
- package/dist/environment/templates.d.ts +0 -1
- package/dist/environment/templates.d.ts.map +1 -1
- package/dist/environment/templates.js +3 -8
- package/dist/environment/update-workflows.d.ts.map +1 -1
- package/dist/environment/update-workflows.js +4 -0
- package/dist/environment/utils.d.ts +0 -12
- package/dist/environment/utils.d.ts.map +1 -1
- package/dist/environment/utils.js +1 -28
- package/dist/events/index.js +7660 -7156
- package/dist/migrations/v2.0/checkout-upstream-files.d.ts +2 -2
- package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +1 -1
- package/dist/migrations/v2.0/checkout-upstream-files.js +2 -2
- package/dist/migrations/v2.0/merge-infrastructure-directory.js +3 -3
- package/dist/migrations/v2.1/add-explicit-correction-flags.d.ts +1 -1
- package/dist/migrations/v2.1/add-explicit-correction-flags.d.ts.map +1 -1
- package/dist/migrations/v2.1/add-explicit-correction-flags.js +34 -6
- package/dist/migrations/v2.1/add-recovery-link-notifications.d.ts +3 -0
- package/dist/migrations/v2.1/add-recovery-link-notifications.d.ts.map +1 -0
- package/dist/migrations/v2.1/add-recovery-link-notifications.js +506 -0
- package/dist/migrations/v2.1/add-translations.d.ts +9 -0
- package/dist/migrations/v2.1/add-translations.d.ts.map +1 -0
- package/dist/migrations/v2.1/add-translations.js +208 -0
- package/dist/migrations/v2.1/enable-telemetry.d.ts +3 -0
- package/dist/migrations/v2.1/enable-telemetry.d.ts.map +1 -0
- package/dist/migrations/v2.1/enable-telemetry.js +433 -0
- package/dist/migrations/v2.1/index.d.ts +14 -1
- package/dist/migrations/v2.1/index.d.ts.map +1 -1
- package/dist/migrations/v2.1/index.js +1077 -7
- package/dist/notification/index.js +1835 -1425
- package/dist/scopes/index.d.ts +435 -36
- package/dist/scopes/index.js +336 -64
- package/dist/telemetry/index.d.ts +45 -0
- package/dist/telemetry/index.d.ts.map +1 -0
- package/dist/telemetry/index.js +39 -0
- package/dist/templates/charts-values/dependencies/values.yaml +2 -0
- package/dist/templates/charts-values/opencrvs-services/values.yaml +4 -3
- package/dist/templates/charts-values/opentelemetry/values.yaml +95 -0
- package/dist/templates/charts-values/traefik/values.yaml +23 -9
- package/dist/templates/inventory/inventory.template.yml +1 -3
- package/dist/translations/check.d.ts +21 -0
- package/dist/translations/check.d.ts.map +1 -0
- package/dist/translations/check.js +132 -0
- package/dist/verify/endpoints.d.ts +19 -0
- package/dist/verify/endpoints.d.ts.map +1 -0
- package/dist/verify/endpoints.js +353 -0
- package/dist/verify/scopes.d.ts +13 -0
- package/dist/verify/scopes.d.ts.map +1 -0
- package/dist/verify/scopes.js +131 -0
- package/dist/verify/upgrade.d.ts +14 -0
- package/dist/verify/upgrade.d.ts.map +1 -0
- package/dist/verify/upgrade.js +111 -0
- package/opencrvs-toolkit-2.1.0-rc.9a83eed.tgz +0 -0
- package/package.json +12 -6
- package/tsconfig.build.json +11 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/tsconfig.json +3 -0
- package/dist/templates/inventory/production.example.yml +0 -77
- package/dist/templates/inventory/qa.example.yml +0 -48
- package/opencrvs-toolkit-2.1.0-rc.99061f0.tgz +0 -0
- package/tsconfig.tsbuildinfo +0 -1
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_path6.join)("environments", environment, INVENTORY_FILE_NAME);
|
|
36
36
|
}
|
|
37
37
|
function findOldInventoryFiles() {
|
|
38
|
-
return glob.sync((0,
|
|
38
|
+
return glob.sync((0, import_path6.join)(OLD_INVENTORY_DIR, "*.yml")).sort();
|
|
39
39
|
}
|
|
40
40
|
function getEnvironmentNameFromOldInventoryPath(filePath) {
|
|
41
|
-
return (0,
|
|
41
|
+
return (0, import_path6.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_path6, 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_path6 = require("path");
|
|
59
59
|
glob = __toESM(require("glob"));
|
|
60
|
-
OLD_INVENTORY_DIR = (0,
|
|
60
|
+
OLD_INVENTORY_DIR = (0, import_path6.join)(
|
|
61
61
|
"infrastructure",
|
|
62
62
|
"server-setup",
|
|
63
63
|
"inventory"
|
|
@@ -503,24 +503,8 @@ function findExistingValue(name, type, scope, existingValues) {
|
|
|
503
503
|
(value) => value.name === name && value.type === type && value.scope === scope
|
|
504
504
|
);
|
|
505
505
|
}
|
|
506
|
-
function storeSecrets(environment, answers) {
|
|
507
|
-
let envConfig = {};
|
|
508
|
-
try {
|
|
509
|
-
envConfig = import_dotenv.default.parse(
|
|
510
|
-
(0, import_fs.readFileSync)(`${process.cwd()}/.env.${environment}`)
|
|
511
|
-
);
|
|
512
|
-
} catch (error3) {
|
|
513
|
-
envConfig = {};
|
|
514
|
-
}
|
|
515
|
-
const linesFromAnswers = answers.map(
|
|
516
|
-
(update) => `${update.name}="${update.value}"`
|
|
517
|
-
);
|
|
518
|
-
const linesFromEnvConfig = Object.entries(envConfig).filter(([name]) => !answers.find((update) => update.name === name)).map(([name, value]) => `${name}="${value}"`);
|
|
519
|
-
const allLines = [...linesFromEnvConfig, ...linesFromAnswers].sort();
|
|
520
|
-
(0, import_fs.writeFileSync)(`.env.${environment}`, allLines.join("\n"));
|
|
521
|
-
}
|
|
522
506
|
function readYamlFile(filePath) {
|
|
523
|
-
const fileContent =
|
|
507
|
+
const fileContent = import_fs5.default.readFileSync(filePath, "utf8");
|
|
524
508
|
return yaml.load(fileContent);
|
|
525
509
|
}
|
|
526
510
|
function writeYamlFile(filePath, data) {
|
|
@@ -533,33 +517,29 @@ function writeYamlFile(filePath, data) {
|
|
|
533
517
|
noRefs: true,
|
|
534
518
|
sortKeys: false
|
|
535
519
|
});
|
|
536
|
-
|
|
520
|
+
import_fs5.default.writeFileSync(filePath, yamlContent, "utf8");
|
|
537
521
|
} catch (error3) {
|
|
538
522
|
throw new Error(`Failed to write inventory file: ${error3}`);
|
|
539
523
|
}
|
|
540
524
|
}
|
|
541
|
-
var
|
|
525
|
+
var import_fs5, yaml;
|
|
542
526
|
var init_utils = __esm({
|
|
543
527
|
"src/environment/utils.ts"() {
|
|
544
528
|
"use strict";
|
|
545
|
-
|
|
529
|
+
import_fs5 = __toESM(require("fs"));
|
|
546
530
|
yaml = __toESM(require("js-yaml"));
|
|
547
|
-
import_dotenv = __toESM(require("dotenv"));
|
|
548
531
|
}
|
|
549
532
|
});
|
|
550
533
|
|
|
551
534
|
// src/environment/templates.ts
|
|
552
|
-
function getUsers(data) {
|
|
553
|
-
if (!data?.all?.vars?.users) {
|
|
554
|
-
return { users: [] };
|
|
555
|
-
}
|
|
556
|
-
return data.all.vars.users;
|
|
557
|
-
}
|
|
558
535
|
function extractAndModifyUsers(data) {
|
|
559
536
|
if (!data?.all?.vars?.users) {
|
|
560
537
|
return { users: [] };
|
|
561
538
|
}
|
|
562
539
|
const users = data.all.vars.users.map((user) => {
|
|
540
|
+
if (user.role) {
|
|
541
|
+
return user;
|
|
542
|
+
}
|
|
563
543
|
const { sudoer, ...rest } = user;
|
|
564
544
|
return {
|
|
565
545
|
...rest,
|
|
@@ -595,29 +575,29 @@ function extractWorkerNodes(data) {
|
|
|
595
575
|
return worker_hosts;
|
|
596
576
|
}
|
|
597
577
|
function copyChartsValues(env, values) {
|
|
598
|
-
const srcDir =
|
|
599
|
-
const destDir =
|
|
600
|
-
|
|
578
|
+
const srcDir = import_path7.default.resolve(__dirname, "templates", "charts-values");
|
|
579
|
+
const destDir = import_path7.default.resolve(process.cwd(), "environments", env);
|
|
580
|
+
import_fs6.default.mkdirSync(destDir, { recursive: true });
|
|
601
581
|
values["lets_encrypt"] = values["traefik_mode"] === "lets_encrypt";
|
|
602
582
|
values["static_ssl"] = values["traefik_mode"] === "static_ssl";
|
|
603
583
|
values["opencrvs_environment"] = env;
|
|
604
584
|
function copyRecursive(src, dest) {
|
|
605
|
-
const stat =
|
|
585
|
+
const stat = import_fs6.default.statSync(src);
|
|
606
586
|
if (stat.isDirectory()) {
|
|
607
|
-
|
|
608
|
-
for (const item of
|
|
609
|
-
copyRecursive(
|
|
587
|
+
import_fs6.default.mkdirSync(dest, { recursive: true });
|
|
588
|
+
for (const item of import_fs6.default.readdirSync(src)) {
|
|
589
|
+
copyRecursive(import_path7.default.join(src, item), import_path7.default.join(dest, item));
|
|
610
590
|
}
|
|
611
591
|
} else {
|
|
612
|
-
const content =
|
|
592
|
+
const content = import_fs6.default.readFileSync(src, "utf8");
|
|
613
593
|
const template = import_handlebars.default.compile(content);
|
|
614
594
|
const updated = template(values);
|
|
615
595
|
const isOverridesFile = dest.endsWith("override.yaml");
|
|
616
|
-
if (isOverridesFile &&
|
|
596
|
+
if (isOverridesFile && import_fs6.default.existsSync(dest)) {
|
|
617
597
|
log(` \u21B7 Skipped existing overrides file: ${dest}`);
|
|
618
598
|
return;
|
|
619
599
|
}
|
|
620
|
-
|
|
600
|
+
import_fs6.default.writeFileSync(dest, updated, "utf8");
|
|
621
601
|
log(` \u2713 Created: ${dest}`);
|
|
622
602
|
}
|
|
623
603
|
}
|
|
@@ -628,29 +608,29 @@ function copyChartsValues(env, values) {
|
|
|
628
608
|
`);
|
|
629
609
|
}
|
|
630
610
|
function generateInventory(env, values) {
|
|
631
|
-
const templatePath =
|
|
611
|
+
const templatePath = import_path7.default.join(
|
|
632
612
|
__dirname,
|
|
633
613
|
"templates",
|
|
634
614
|
"inventory",
|
|
635
615
|
"inventory.template.yml"
|
|
636
616
|
);
|
|
637
|
-
const outputPath =
|
|
638
|
-
const templateFile =
|
|
617
|
+
const outputPath = import_path7.default.resolve(process.cwd(), getEnvironmentInventoryPath(env));
|
|
618
|
+
const templateFile = import_fs6.default.readFileSync(templatePath, "utf-8");
|
|
639
619
|
const template = import_handlebars.default.compile(templateFile);
|
|
640
620
|
values["single_node"] = values["kube_worker_nodes"].length > 0 || values["backup_host"] ? "false" : "true";
|
|
641
621
|
const updated = template(values);
|
|
642
|
-
|
|
643
|
-
|
|
622
|
+
import_fs6.default.mkdirSync(import_path7.default.dirname(outputPath), { recursive: true });
|
|
623
|
+
import_fs6.default.writeFileSync(outputPath, updated);
|
|
644
624
|
log(`
|
|
645
625
|
\u2705 Generated inventory file at ${outputPath}
|
|
646
626
|
`);
|
|
647
627
|
}
|
|
648
|
-
var
|
|
628
|
+
var import_fs6, import_path7, import_handlebars;
|
|
649
629
|
var init_templates = __esm({
|
|
650
630
|
"src/environment/templates.ts"() {
|
|
651
631
|
"use strict";
|
|
652
|
-
|
|
653
|
-
|
|
632
|
+
import_fs6 = __toESM(require("fs"));
|
|
633
|
+
import_path7 = __toESM(require("path"));
|
|
654
634
|
init_logger();
|
|
655
635
|
init_paths();
|
|
656
636
|
import_handlebars = __toESM(require("handlebars"));
|
|
@@ -706,18 +686,18 @@ var init_git = __esm({
|
|
|
706
686
|
});
|
|
707
687
|
|
|
708
688
|
// src/environment/questions.ts
|
|
709
|
-
function validateCIDR(
|
|
710
|
-
if (!
|
|
689
|
+
function validateCIDR(input4) {
|
|
690
|
+
if (!input4.trim()) {
|
|
711
691
|
return true;
|
|
712
692
|
}
|
|
713
693
|
const cidrRegex = /^((25[0-5]|(2[0-4]|1\d|[1-9]?\d)\d?)\.){3}(25[0-5]|(2[0-4]|1\d|[1-9]?\d)\d?)\/([0-9]|[12][0-9]|3[0-2])$/;
|
|
714
|
-
return cidrRegex.test(
|
|
694
|
+
return cidrRegex.test(input4.trim()) ? true : "Please enter a valid CIDR (e.g. 10.0.0.0/24)";
|
|
715
695
|
}
|
|
716
|
-
function validateCIDRs(
|
|
717
|
-
if (!
|
|
696
|
+
function validateCIDRs(input4) {
|
|
697
|
+
if (!input4.trim()) {
|
|
718
698
|
return true;
|
|
719
699
|
}
|
|
720
|
-
const cidrs =
|
|
700
|
+
const cidrs = input4.split(",").map((v) => v.trim());
|
|
721
701
|
for (const cidr of cidrs) {
|
|
722
702
|
const result = validateCIDR(cidr);
|
|
723
703
|
if (result !== true) {
|
|
@@ -860,11 +840,28 @@ var init_questions = __esm({
|
|
|
860
840
|
scope: "ENVIRONMENT"
|
|
861
841
|
},
|
|
862
842
|
{
|
|
863
|
-
name: "
|
|
843
|
+
name: "kubeMasterNode",
|
|
844
|
+
type: "text",
|
|
845
|
+
message: `Kubernetes master node hostnames or IP (default: auto-detect)`,
|
|
846
|
+
valueType: "VARIABLE",
|
|
847
|
+
valueLabel: "KUBE_MASTER_NODE",
|
|
848
|
+
initial: process.env.KUBE_MASTER_NODE,
|
|
849
|
+
scope: "ENVIRONMENT"
|
|
850
|
+
},
|
|
851
|
+
{
|
|
852
|
+
name: "kubeWorkerNodes",
|
|
853
|
+
type: "text",
|
|
854
|
+
message: `Kubernetes worker node hostnames or IPs (comma-separated, default: no worker nodes)`,
|
|
855
|
+
valueType: "VARIABLE",
|
|
856
|
+
valueLabel: "KUBE_WORKER_NODES",
|
|
857
|
+
initial: process.env.KUBE_WORKER_NODES || "",
|
|
858
|
+
scope: "ENVIRONMENT"
|
|
859
|
+
},
|
|
860
|
+
{
|
|
861
|
+
name: "kubeApiHost",
|
|
864
862
|
type: "text",
|
|
865
|
-
message: `Kubernetes API endpoint (default:
|
|
863
|
+
message: `Kubernetes API endpoint IP (default: KUBE_MASTER_NODE)`,
|
|
866
864
|
valueType: "VARIABLE",
|
|
867
|
-
// validate: notEmpty,
|
|
868
865
|
valueLabel: "KUBE_API_HOST",
|
|
869
866
|
initial: process.env.KUBE_API_HOST,
|
|
870
867
|
scope: "ENVIRONMENT"
|
|
@@ -878,16 +875,6 @@ var init_questions = __esm({
|
|
|
878
875
|
valueLabel: "KUBE_API_ALLOWED_CIDRS",
|
|
879
876
|
initial: process.env.KUBE_API_ALLOWED_CIDRS || "",
|
|
880
877
|
scope: "ENVIRONMENT"
|
|
881
|
-
},
|
|
882
|
-
{
|
|
883
|
-
name: "kubeWorkerNodes",
|
|
884
|
-
type: "text",
|
|
885
|
-
message: `Kubernetes worker node hostnames or IPs (comma-separated, default: no worker nodes)`,
|
|
886
|
-
valueType: "VARIABLE",
|
|
887
|
-
// validate: notEmpty,
|
|
888
|
-
valueLabel: "KUBE_WORKER_NODES",
|
|
889
|
-
initial: process.env.KUBE_WORKER_NODES || "",
|
|
890
|
-
scope: "ENVIRONMENT"
|
|
891
878
|
}
|
|
892
879
|
];
|
|
893
880
|
staticSSLCertQuestions = [
|
|
@@ -918,7 +905,6 @@ var init_questions = __esm({
|
|
|
918
905
|
type: "text",
|
|
919
906
|
message: `Please enter backup server host/IP address, (default: no backup):`,
|
|
920
907
|
valueType: "VARIABLE",
|
|
921
|
-
// validate: notEmpty,
|
|
922
908
|
valueLabel: "BACKUP_HOST",
|
|
923
909
|
initial: process.env.BACKUP_HOST || "",
|
|
924
910
|
scope: "ENVIRONMENT"
|
|
@@ -1241,7 +1227,7 @@ function updateInventoryFile(filePath, users) {
|
|
|
1241
1227
|
function parseInventoryFile(filePath) {
|
|
1242
1228
|
try {
|
|
1243
1229
|
const data = readYamlFile(filePath);
|
|
1244
|
-
return
|
|
1230
|
+
return extractAndModifyUsers(data);
|
|
1245
1231
|
} catch {
|
|
1246
1232
|
return [];
|
|
1247
1233
|
}
|
|
@@ -1251,7 +1237,7 @@ function getCurrentUsername() {
|
|
|
1251
1237
|
}
|
|
1252
1238
|
function getCurrentUserSSHKeys() {
|
|
1253
1239
|
const homeDir = os.homedir();
|
|
1254
|
-
const sshDir =
|
|
1240
|
+
const sshDir = path7.join(homeDir, ".ssh");
|
|
1255
1241
|
const keys = [];
|
|
1256
1242
|
const keyFiles = [
|
|
1257
1243
|
"id_rsa.pub",
|
|
@@ -1260,7 +1246,7 @@ function getCurrentUserSSHKeys() {
|
|
|
1260
1246
|
"id_dsa.pub"
|
|
1261
1247
|
];
|
|
1262
1248
|
for (const keyFile of keyFiles) {
|
|
1263
|
-
const keyPath =
|
|
1249
|
+
const keyPath = path7.join(sshDir, keyFile);
|
|
1264
1250
|
try {
|
|
1265
1251
|
if (fs3.existsSync(keyPath)) {
|
|
1266
1252
|
const keyContent = fs3.readFileSync(keyPath, "utf8").trim();
|
|
@@ -1601,13 +1587,13 @@ async function manageUsers(inventoryPath) {
|
|
|
1601
1587
|
}
|
|
1602
1588
|
return users;
|
|
1603
1589
|
}
|
|
1604
|
-
var os, fs3,
|
|
1590
|
+
var os, fs3, path7, input2, select2, confirm, editor, checkbox;
|
|
1605
1591
|
var init_manage_users = __esm({
|
|
1606
1592
|
"src/environment/manage-users.ts"() {
|
|
1607
1593
|
"use strict";
|
|
1608
1594
|
os = __toESM(require("os"));
|
|
1609
1595
|
fs3 = __toESM(require("fs"));
|
|
1610
|
-
|
|
1596
|
+
path7 = __toESM(require("path"));
|
|
1611
1597
|
init_logger();
|
|
1612
1598
|
init_utils();
|
|
1613
1599
|
init_templates();
|
|
@@ -1629,6 +1615,10 @@ async function select3(options) {
|
|
|
1629
1615
|
const inquirer = await import("@inquirer/prompts");
|
|
1630
1616
|
return inquirer.select(options);
|
|
1631
1617
|
}
|
|
1618
|
+
async function input3(options) {
|
|
1619
|
+
const inquirer = await import("@inquirer/prompts");
|
|
1620
|
+
return inquirer.input(options);
|
|
1621
|
+
}
|
|
1632
1622
|
function questionToPrompt({
|
|
1633
1623
|
valueType,
|
|
1634
1624
|
valueLabel,
|
|
@@ -1695,7 +1685,7 @@ function getAnswers(existingValues) {
|
|
|
1695
1685
|
});
|
|
1696
1686
|
});
|
|
1697
1687
|
}
|
|
1698
|
-
async function promptAndStoreAnswer(
|
|
1688
|
+
async function promptAndStoreAnswer(questions, existingValues) {
|
|
1699
1689
|
log("");
|
|
1700
1690
|
const processedQuestions = questions.flatMap((question) => {
|
|
1701
1691
|
const questionWithVariableLabel = {
|
|
@@ -1774,7 +1764,6 @@ async function promptAndStoreAnswer(environment, questions, existingValues) {
|
|
|
1774
1764
|
}
|
|
1775
1765
|
});
|
|
1776
1766
|
ALL_ANSWERS.push(result);
|
|
1777
|
-
storeSecrets(environment, getAnswers(existingValues));
|
|
1778
1767
|
const existingValuesForQuestions = questions.filter((question) => question.valueType === "VARIABLE").map((question) => [
|
|
1779
1768
|
question.name,
|
|
1780
1769
|
findExistingValue(
|
|
@@ -1786,12 +1775,11 @@ async function promptAndStoreAnswer(environment, questions, existingValues) {
|
|
|
1786
1775
|
]);
|
|
1787
1776
|
return { ...Object.fromEntries(existingValuesForQuestions), ...result };
|
|
1788
1777
|
}
|
|
1789
|
-
var import_core,
|
|
1778
|
+
var import_core, import_kleur4, import_prompts2, ALL_QUESTIONS, ALL_ANSWERS;
|
|
1790
1779
|
var init_setup_environment = __esm({
|
|
1791
1780
|
"src/environment/setup-environment.ts"() {
|
|
1792
1781
|
"use strict";
|
|
1793
1782
|
import_core = require("@octokit/core");
|
|
1794
|
-
import_dotenv2 = __toESM(require("dotenv"));
|
|
1795
1783
|
import_kleur4 = __toESM(require("kleur"));
|
|
1796
1784
|
import_prompts2 = __toESM(require("prompts"));
|
|
1797
1785
|
init_github();
|
|
@@ -1831,11 +1819,7 @@ var init_setup_environment = __esm({
|
|
|
1831
1819
|
}
|
|
1832
1820
|
}
|
|
1833
1821
|
);
|
|
1834
|
-
const { githubToken } = await promptAndStoreAnswer(
|
|
1835
|
-
"",
|
|
1836
|
-
githubTokenQuestion,
|
|
1837
|
-
[]
|
|
1838
|
-
);
|
|
1822
|
+
const { githubToken } = await promptAndStoreAnswer(githubTokenQuestion, []);
|
|
1839
1823
|
const octokit = new import_core.Octokit({
|
|
1840
1824
|
auth: githubToken
|
|
1841
1825
|
});
|
|
@@ -1892,9 +1876,6 @@ var init_setup_environment = __esm({
|
|
|
1892
1876
|
if (!environment) {
|
|
1893
1877
|
process.exit(1);
|
|
1894
1878
|
}
|
|
1895
|
-
import_dotenv2.default.config({
|
|
1896
|
-
path: `${process.cwd()}/.env.${environment}`
|
|
1897
|
-
});
|
|
1898
1879
|
await createEnvironment(
|
|
1899
1880
|
octokit,
|
|
1900
1881
|
environment,
|
|
@@ -1952,17 +1933,12 @@ var init_setup_environment = __esm({
|
|
|
1952
1933
|
"WARNING! You are setting up a production environment.\n Make sure you have read the deployment guide carefully before proceeding.\n"
|
|
1953
1934
|
)
|
|
1954
1935
|
);
|
|
1955
|
-
await promptAndStoreAnswer(
|
|
1956
|
-
environment,
|
|
1957
|
-
githubOtherQuestions,
|
|
1958
|
-
existingValues
|
|
1959
|
-
);
|
|
1936
|
+
await promptAndStoreAnswer(githubOtherQuestions, existingValues);
|
|
1960
1937
|
}
|
|
1961
1938
|
log("\n", import_kleur4.default.bold().underline("Docker Hub"));
|
|
1962
|
-
await promptAndStoreAnswer(
|
|
1939
|
+
await promptAndStoreAnswer(dockerhubQuestions, existingValues);
|
|
1963
1940
|
log("\n", import_kleur4.default.bold().underline("Kubernetes & Runtime"));
|
|
1964
1941
|
const infrastructure = await promptAndStoreAnswer(
|
|
1965
|
-
environment,
|
|
1966
1942
|
infrastructureQuestions,
|
|
1967
1943
|
existingValues
|
|
1968
1944
|
);
|
|
@@ -2023,7 +1999,7 @@ var init_setup_environment = __esm({
|
|
|
2023
1999
|
import_kleur4.default.bold().green("\u2714"),
|
|
2024
2000
|
import_kleur4.default.bold().yellow(" Disk encryption is enabled")
|
|
2025
2001
|
);
|
|
2026
|
-
await promptAndStoreAnswer(
|
|
2002
|
+
await promptAndStoreAnswer(diskQuestions, existingValues);
|
|
2027
2003
|
} else {
|
|
2028
2004
|
if (!enableEncryption && !encryption_key_defined && environment_exists) {
|
|
2029
2005
|
log(
|
|
@@ -2060,6 +2036,7 @@ var init_setup_environment = __esm({
|
|
|
2060
2036
|
"ENVIRONMENT",
|
|
2061
2037
|
existingValues
|
|
2062
2038
|
)?.value;
|
|
2039
|
+
let restoreHost = findExistingValue("RESTORE_HOST", "VARIABLE", "ENVIRONMENT", existingValues)?.value || "";
|
|
2063
2040
|
let restoreType = findExistingValue(
|
|
2064
2041
|
"RESTORE_ENVIRONMENT_MODE",
|
|
2065
2042
|
"VARIABLE",
|
|
@@ -2078,7 +2055,6 @@ var init_setup_environment = __esm({
|
|
|
2078
2055
|
let backupHostPublicKey = "";
|
|
2079
2056
|
if (configureBackup) {
|
|
2080
2057
|
const backupAnswers = await promptAndStoreAnswer(
|
|
2081
|
-
environment,
|
|
2082
2058
|
backupQuestions,
|
|
2083
2059
|
existingValues
|
|
2084
2060
|
);
|
|
@@ -2135,15 +2111,15 @@ var init_setup_environment = __esm({
|
|
|
2135
2111
|
}
|
|
2136
2112
|
]
|
|
2137
2113
|
});
|
|
2114
|
+
restoreHost = await input3({
|
|
2115
|
+
message: "What is the host/IP address of the restore backup server?",
|
|
2116
|
+
default: restoreHost
|
|
2117
|
+
});
|
|
2138
2118
|
} else {
|
|
2139
2119
|
log(import_kleur4.default.bold().green("\u2714"), import_kleur4.default.bold().yellow("Restore is disabled"));
|
|
2140
2120
|
}
|
|
2141
2121
|
log("\n", import_kleur4.default.bold().underline("Monitoring"));
|
|
2142
|
-
await promptAndStoreAnswer(
|
|
2143
|
-
environment,
|
|
2144
|
-
databaseAndMonitoringQuestions,
|
|
2145
|
-
existingValues
|
|
2146
|
-
);
|
|
2122
|
+
await promptAndStoreAnswer(databaseAndMonitoringQuestions, existingValues);
|
|
2147
2123
|
const sentryDSNExists = findExistingValue(
|
|
2148
2124
|
"SENTRY_DSN",
|
|
2149
2125
|
"SECRET",
|
|
@@ -2152,7 +2128,7 @@ var init_setup_environment = __esm({
|
|
|
2152
2128
|
);
|
|
2153
2129
|
log("\n", import_kleur4.default.bold().underline("Sentry"));
|
|
2154
2130
|
if (sentryDSNExists) {
|
|
2155
|
-
await promptAndStoreAnswer(
|
|
2131
|
+
await promptAndStoreAnswer(sentryQuestions, existingValues);
|
|
2156
2132
|
} else {
|
|
2157
2133
|
const { useSentry } = await (0, import_prompts2.default)([
|
|
2158
2134
|
{
|
|
@@ -2163,17 +2139,13 @@ var init_setup_environment = __esm({
|
|
|
2163
2139
|
}
|
|
2164
2140
|
]);
|
|
2165
2141
|
if (useSentry) {
|
|
2166
|
-
await promptAndStoreAnswer(
|
|
2142
|
+
await promptAndStoreAnswer(sentryQuestions, existingValues);
|
|
2167
2143
|
}
|
|
2168
2144
|
}
|
|
2169
2145
|
log("\n", import_kleur4.default.bold().underline("METABASE ADMIN"));
|
|
2170
|
-
await promptAndStoreAnswer(
|
|
2171
|
-
environment,
|
|
2172
|
-
metabaseAdminQuestions,
|
|
2173
|
-
existingValues
|
|
2174
|
-
);
|
|
2146
|
+
await promptAndStoreAnswer(metabaseAdminQuestions, existingValues);
|
|
2175
2147
|
log("\n", import_kleur4.default.bold().underline("SMTP"));
|
|
2176
|
-
await promptAndStoreAnswer(
|
|
2148
|
+
await promptAndStoreAnswer(emailQuestions, existingValues);
|
|
2177
2149
|
const allAnswers = ALL_ANSWERS.reduce((acc, answer) => {
|
|
2178
2150
|
return { ...acc, ...answer };
|
|
2179
2151
|
});
|
|
@@ -2469,6 +2441,27 @@ var init_setup_environment = __esm({
|
|
|
2469
2441
|
existingValues
|
|
2470
2442
|
),
|
|
2471
2443
|
scope: "ENVIRONMENT"
|
|
2444
|
+
},
|
|
2445
|
+
{
|
|
2446
|
+
type: "VARIABLE",
|
|
2447
|
+
name: "RESTORE_HOST",
|
|
2448
|
+
value: answerOrExisting(
|
|
2449
|
+
restoreHost,
|
|
2450
|
+
findExistingValue(
|
|
2451
|
+
"RESTORE_HOST",
|
|
2452
|
+
"VARIABLE",
|
|
2453
|
+
"ENVIRONMENT",
|
|
2454
|
+
existingValues
|
|
2455
|
+
),
|
|
2456
|
+
(val) => val || ""
|
|
2457
|
+
),
|
|
2458
|
+
didExist: findExistingValue(
|
|
2459
|
+
"RESTORE_HOST",
|
|
2460
|
+
"VARIABLE",
|
|
2461
|
+
"ENVIRONMENT",
|
|
2462
|
+
existingValues
|
|
2463
|
+
),
|
|
2464
|
+
scope: "ENVIRONMENT"
|
|
2472
2465
|
}
|
|
2473
2466
|
];
|
|
2474
2467
|
if (enableEncryption) {
|
|
@@ -2515,7 +2508,6 @@ var init_setup_environment = __esm({
|
|
|
2515
2508
|
(variable) => Boolean(variable.value) && // Only update values that changed
|
|
2516
2509
|
(variable.type !== "VARIABLE" || variable.value !== variable.didExist?.value)
|
|
2517
2510
|
);
|
|
2518
|
-
storeSecrets(environment, updates);
|
|
2519
2511
|
const newSecrets = updates.filter(
|
|
2520
2512
|
(update) => update.type === "SECRET" && !update.didExist
|
|
2521
2513
|
);
|
|
@@ -2617,6 +2609,12 @@ var init_setup_environment = __esm({
|
|
|
2617
2609
|
if ([].concat(newSecrets).concat(updatedSecrets).concat(newVariables).concat(updatedVariables).length === 0) {
|
|
2618
2610
|
process.exit(0);
|
|
2619
2611
|
}
|
|
2612
|
+
log(
|
|
2613
|
+
import_kleur4.default.bold().red(
|
|
2614
|
+
"\u26A0\uFE0F COPY THESE NOW INTO A PASSWORD MANAGER \u2014 YOU WON'T SEE THEM AGAIN"
|
|
2615
|
+
)
|
|
2616
|
+
);
|
|
2617
|
+
log("");
|
|
2620
2618
|
const saveChanges = await confirm2({
|
|
2621
2619
|
message: "Do you want to continue?",
|
|
2622
2620
|
default: true
|
|
@@ -2720,7 +2718,7 @@ var init_setup_environment = __esm({
|
|
|
2720
2718
|
log("\n", import_kleur4.default.bold().underline("Running configuration files updates"));
|
|
2721
2719
|
generateInventory(environment, {
|
|
2722
2720
|
kube_worker_nodes: kubeWorkerNodes,
|
|
2723
|
-
kube_api_host: infrastructure.
|
|
2721
|
+
kube_api_host: infrastructure.kubeApiHost || "",
|
|
2724
2722
|
backup_host: backupHost || "",
|
|
2725
2723
|
users
|
|
2726
2724
|
});
|
|
@@ -2731,12 +2729,14 @@ var init_setup_environment = __esm({
|
|
|
2731
2729
|
// Hardcode like this blocks us from being generic:
|
|
2732
2730
|
// https://github.com/opencrvs/opencrvs-core/issues/11171
|
|
2733
2731
|
two_fa_enabled: environment !== "production" ? false : true,
|
|
2734
|
-
|
|
2732
|
+
traefik_mode: traefikConfOption,
|
|
2735
2733
|
restore_enabled: restoreEnvironmentName ? true : false,
|
|
2736
2734
|
restore_environment_name: restoreEnvironmentName || "",
|
|
2737
2735
|
restore_type: restoreType,
|
|
2738
|
-
|
|
2739
|
-
|
|
2736
|
+
restore_host: restoreHost || "",
|
|
2737
|
+
backup_enabled: configureBackup ? true : false,
|
|
2738
|
+
backup_type: backupType,
|
|
2739
|
+
backup_host: backupHost || ""
|
|
2740
2740
|
});
|
|
2741
2741
|
let addon_message = kubeWorkerNodes.length > 0 || configureBackup ? `--------------------------------------------------------------------------------------------
|
|
2742
2742
|
|
|
@@ -2770,8 +2770,10 @@ ${addon_message}
|
|
|
2770
2770
|
${import_kleur4.default.yellow("\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501")}
|
|
2771
2771
|
${import_kleur4.default.yellow("Please KINDLY read hints above")}
|
|
2772
2772
|
`);
|
|
2773
|
-
log(
|
|
2774
|
-
|
|
2773
|
+
log(
|
|
2774
|
+
"\nAll secrets and variables were printed above.",
|
|
2775
|
+
import_kleur4.default.bold().yellow("Store them in a password manager \u2014 they are not saved to disk.")
|
|
2776
|
+
);
|
|
2775
2777
|
})();
|
|
2776
2778
|
}
|
|
2777
2779
|
});
|
|
@@ -2781,16 +2783,16 @@ var update_workflows_exports = {};
|
|
|
2781
2783
|
__export(update_workflows_exports, {
|
|
2782
2784
|
updateWorkflowEnvironments: () => updateWorkflowEnvironments
|
|
2783
2785
|
});
|
|
2784
|
-
function isDirectory(
|
|
2786
|
+
function isDirectory(path10) {
|
|
2785
2787
|
try {
|
|
2786
|
-
return (0,
|
|
2788
|
+
return (0, import_fs7.statSync)(path10).isDirectory();
|
|
2787
2789
|
} catch {
|
|
2788
2790
|
return false;
|
|
2789
2791
|
}
|
|
2790
2792
|
}
|
|
2791
2793
|
async function extractInfrastructureNames() {
|
|
2792
|
-
const files = glob2.sync((0,
|
|
2793
|
-
const infraEnvironments = files.map((file) => (0,
|
|
2794
|
+
const files = glob2.sync((0, import_path8.join)("environments", "*", INVENTORY_FILE_NAME));
|
|
2795
|
+
const infraEnvironments = files.map((file) => (0, import_path8.basename)((0, import_path8.dirname)(file)));
|
|
2794
2796
|
if (infraEnvironments.length === 0) {
|
|
2795
2797
|
console.log(
|
|
2796
2798
|
`\u26A0\uFE0F Warning: No environment inventory files found at environments/*/${INVENTORY_FILE_NAME}`
|
|
@@ -2803,9 +2805,9 @@ async function extractInfrastructureNames() {
|
|
|
2803
2805
|
async function extractEnvironmentNames() {
|
|
2804
2806
|
const entries = await (0, import_promises.readdir)("environments");
|
|
2805
2807
|
const environments = entries.filter((entry) => {
|
|
2806
|
-
const environmentPath = (0,
|
|
2807
|
-
const opencrvsServicesPath = (0,
|
|
2808
|
-
return isDirectory(environmentPath) && (0,
|
|
2808
|
+
const environmentPath = (0, import_path8.join)("environments", entry);
|
|
2809
|
+
const opencrvsServicesPath = (0, import_path8.join)(environmentPath, "opencrvs-services");
|
|
2810
|
+
return isDirectory(environmentPath) && (0, import_fs7.existsSync)(opencrvsServicesPath) && isDirectory(opencrvsServicesPath);
|
|
2809
2811
|
});
|
|
2810
2812
|
if (environments.length === 0) {
|
|
2811
2813
|
console.log(
|
|
@@ -2830,8 +2832,12 @@ function updateOptionsInYaml(content, envList) {
|
|
|
2830
2832
|
async function updateWorkflows(envList, config) {
|
|
2831
2833
|
const { workflows } = config;
|
|
2832
2834
|
for (const workflowPath of workflows) {
|
|
2835
|
+
if (!(0, import_fs7.existsSync)(workflowPath)) {
|
|
2836
|
+
log(` \u21B7 Skipped ${workflowPath} (not found in this repository)`);
|
|
2837
|
+
continue;
|
|
2838
|
+
}
|
|
2833
2839
|
try {
|
|
2834
|
-
const fileContents = (0,
|
|
2840
|
+
const fileContents = (0, import_fs7.readFileSync)(workflowPath, "utf8");
|
|
2835
2841
|
const workflowData = yaml2.load(fileContents);
|
|
2836
2842
|
if (!workflowData?.on?.workflow_dispatch?.inputs?.environment?.options) {
|
|
2837
2843
|
throw new Error(
|
|
@@ -2839,7 +2845,7 @@ async function updateWorkflows(envList, config) {
|
|
|
2839
2845
|
);
|
|
2840
2846
|
}
|
|
2841
2847
|
const updatedContent = updateOptionsInYaml(fileContents, envList);
|
|
2842
|
-
(0,
|
|
2848
|
+
(0, import_fs7.writeFileSync)(workflowPath, updatedContent, "utf8");
|
|
2843
2849
|
log(` \u2713 Successfully updated ${workflowPath}`);
|
|
2844
2850
|
} catch (error3) {
|
|
2845
2851
|
console.error(
|
|
@@ -2893,13 +2899,13 @@ async function updateWorkflowEnvironments() {
|
|
|
2893
2899
|
process.exit(1);
|
|
2894
2900
|
}
|
|
2895
2901
|
}
|
|
2896
|
-
var import_promises,
|
|
2902
|
+
var import_promises, import_fs7, import_path8, glob2, yaml2;
|
|
2897
2903
|
var init_update_workflows = __esm({
|
|
2898
2904
|
"src/environment/update-workflows.ts"() {
|
|
2899
2905
|
"use strict";
|
|
2900
2906
|
import_promises = require("fs/promises");
|
|
2901
|
-
|
|
2902
|
-
|
|
2907
|
+
import_fs7 = require("fs");
|
|
2908
|
+
import_path8 = require("path");
|
|
2903
2909
|
glob2 = __toESM(require("glob"));
|
|
2904
2910
|
yaml2 = __toESM(require("js-yaml"));
|
|
2905
2911
|
init_logger();
|
|
@@ -2913,17 +2919,17 @@ __export(upgrade_exports, {
|
|
|
2913
2919
|
upgradeEnvironmentLayout: () => upgradeEnvironmentLayout
|
|
2914
2920
|
});
|
|
2915
2921
|
function moveFileIfDestinationMissing(sourcePath, destinationPath) {
|
|
2916
|
-
if (!(0,
|
|
2922
|
+
if (!(0, import_fs8.existsSync)(sourcePath)) {
|
|
2917
2923
|
return false;
|
|
2918
2924
|
}
|
|
2919
|
-
if ((0,
|
|
2925
|
+
if ((0, import_fs8.existsSync)(destinationPath)) {
|
|
2920
2926
|
warn(
|
|
2921
2927
|
`\u26A0\uFE0F Skipped ${sourcePath}; destination already exists at ${destinationPath}`
|
|
2922
2928
|
);
|
|
2923
2929
|
return false;
|
|
2924
2930
|
}
|
|
2925
|
-
(0,
|
|
2926
|
-
(0,
|
|
2931
|
+
(0, import_fs8.mkdirSync)((0, import_path9.dirname)(destinationPath), { recursive: true });
|
|
2932
|
+
(0, import_fs8.renameSync)(sourcePath, destinationPath);
|
|
2927
2933
|
log(` \u2713 Moved ${sourcePath} -> ${destinationPath}`);
|
|
2928
2934
|
return true;
|
|
2929
2935
|
}
|
|
@@ -2943,8 +2949,8 @@ function migrateInventoryFiles() {
|
|
|
2943
2949
|
) || didMoveInventory;
|
|
2944
2950
|
}
|
|
2945
2951
|
try {
|
|
2946
|
-
if ((0,
|
|
2947
|
-
(0,
|
|
2952
|
+
if ((0, import_fs8.existsSync)(OLD_INVENTORY_DIR) && (0, import_fs8.readdirSync)(OLD_INVENTORY_DIR).length === 0) {
|
|
2953
|
+
(0, import_fs8.rmdirSync)(OLD_INVENTORY_DIR);
|
|
2948
2954
|
log(` \u2713 Removed empty ${OLD_INVENTORY_DIR}`);
|
|
2949
2955
|
}
|
|
2950
2956
|
} catch {
|
|
@@ -2962,12 +2968,12 @@ async function upgradeEnvironmentLayout() {
|
|
|
2962
2968
|
}
|
|
2963
2969
|
log("\nCommit changes into git after upgrade");
|
|
2964
2970
|
}
|
|
2965
|
-
var
|
|
2971
|
+
var import_fs8, import_path9, import_kleur5;
|
|
2966
2972
|
var init_upgrade = __esm({
|
|
2967
2973
|
"src/environment/upgrade.ts"() {
|
|
2968
2974
|
"use strict";
|
|
2969
|
-
|
|
2970
|
-
|
|
2975
|
+
import_fs8 = require("fs");
|
|
2976
|
+
import_path9 = require("path");
|
|
2971
2977
|
import_kleur5 = __toESM(require("kleur"));
|
|
2972
2978
|
init_logger();
|
|
2973
2979
|
init_paths();
|
|
@@ -2993,7 +2999,7 @@ async function selectInventoryFile(dirPath = "./environments") {
|
|
|
2993
2999
|
return null;
|
|
2994
3000
|
}
|
|
2995
3001
|
const environments = fs4.readdirSync(dirPath).filter((entry) => {
|
|
2996
|
-
const filePath =
|
|
3002
|
+
const filePath = path8.join(dirPath, entry);
|
|
2997
3003
|
return fs4.statSync(filePath).isDirectory() && fs4.existsSync(getEnvironmentInventoryPath(entry));
|
|
2998
3004
|
}).sort();
|
|
2999
3005
|
if (environments.length === 0) {
|
|
@@ -3021,12 +3027,12 @@ async function manageEnvironmentUsers() {
|
|
|
3021
3027
|
}
|
|
3022
3028
|
await manageUsers(inventory_file);
|
|
3023
3029
|
}
|
|
3024
|
-
var fs4,
|
|
3030
|
+
var fs4, path8, import_kleur6;
|
|
3025
3031
|
var init_users = __esm({
|
|
3026
3032
|
"src/environment/users.ts"() {
|
|
3027
3033
|
"use strict";
|
|
3028
3034
|
fs4 = __toESM(require("fs"));
|
|
3029
|
-
|
|
3035
|
+
path8 = __toESM(require("path"));
|
|
3030
3036
|
import_kleur6 = __toESM(require("kleur"));
|
|
3031
3037
|
init_manage_users();
|
|
3032
3038
|
init_logger();
|
|
@@ -3036,11 +3042,11 @@ var init_users = __esm({
|
|
|
3036
3042
|
|
|
3037
3043
|
// src/environment/swarm-to-k8s.ts
|
|
3038
3044
|
var swarm_to_k8s_exports = {};
|
|
3039
|
-
var
|
|
3045
|
+
var path9, import_kleur7, import_core2;
|
|
3040
3046
|
var init_swarm_to_k8s = __esm({
|
|
3041
3047
|
"src/environment/swarm-to-k8s.ts"() {
|
|
3042
3048
|
"use strict";
|
|
3043
|
-
|
|
3049
|
+
path9 = __toESM(require("path"));
|
|
3044
3050
|
import_kleur7 = __toESM(require("kleur"));
|
|
3045
3051
|
init_logger();
|
|
3046
3052
|
init_utils();
|
|
@@ -3092,7 +3098,7 @@ var init_swarm_to_k8s = __esm({
|
|
|
3092
3098
|
);
|
|
3093
3099
|
process.exit(1);
|
|
3094
3100
|
}
|
|
3095
|
-
const ansible_inventory =
|
|
3101
|
+
const ansible_inventory = path9.join(old_inventory_path, environment + ".yml");
|
|
3096
3102
|
const data = readYamlFile(ansible_inventory);
|
|
3097
3103
|
log(` \u2713 Loaded old inventory file: ${ansible_inventory}`);
|
|
3098
3104
|
const master = dockerManagerFirst(data) || "";
|
|
@@ -3219,6 +3225,7 @@ var init_swarm_to_k8s = __esm({
|
|
|
3219
3225
|
// src/migrations/v2.1/add-explicit-correction-flags.ts
|
|
3220
3226
|
var import_ts_morph = require("ts-morph");
|
|
3221
3227
|
var import_path = __toESM(require("path"));
|
|
3228
|
+
var import_fs = require("fs");
|
|
3222
3229
|
var DEFINE_CONFIG_NAME = "defineConfig";
|
|
3223
3230
|
var ACTIONS_PROPERTY_NAME = "actions";
|
|
3224
3231
|
var TYPE_PROPERTY_NAME = "type";
|
|
@@ -3226,6 +3233,11 @@ var FLAGS_PROPERTY_NAME = "flags";
|
|
|
3226
3233
|
var CONDITIONALS_PROPERTY_NAME = "conditionals";
|
|
3227
3234
|
var ACTION_TYPE_ENUM_NAME = "ActionType";
|
|
3228
3235
|
var REQUEST_CORRECTION_TYPE = "REQUEST_CORRECTION";
|
|
3236
|
+
var skipped = [];
|
|
3237
|
+
function warnSkipped(message) {
|
|
3238
|
+
skipped.push(message);
|
|
3239
|
+
console.warn(` \u26A0\uFE0F ${message}`);
|
|
3240
|
+
}
|
|
3229
3241
|
var CORRECTION_ACTIONS_TO_ADD = [
|
|
3230
3242
|
{
|
|
3231
3243
|
actionType: "APPROVE_CORRECTION",
|
|
@@ -3291,8 +3303,9 @@ function buildCorrectionActionText(spec, typeStyle, flagsText, conditionalsText)
|
|
|
3291
3303
|
}
|
|
3292
3304
|
function processFile(filePath, project) {
|
|
3293
3305
|
const sourceFile = project.getSourceFile(filePath);
|
|
3294
|
-
if (!sourceFile) return 0;
|
|
3306
|
+
if (!sourceFile) return { changes: 0, defineConfigs: 0 };
|
|
3295
3307
|
let changes = 0;
|
|
3308
|
+
let defineConfigs = 0;
|
|
3296
3309
|
const relPath = import_path.default.relative(process.cwd(), filePath);
|
|
3297
3310
|
const callExpressions = sourceFile.getDescendantsOfKind(
|
|
3298
3311
|
import_ts_morph.SyntaxKind.CallExpression
|
|
@@ -3302,6 +3315,7 @@ function processFile(filePath, project) {
|
|
|
3302
3315
|
if (!import_ts_morph.Node.isIdentifier(expression) || expression.getText() !== DEFINE_CONFIG_NAME) {
|
|
3303
3316
|
continue;
|
|
3304
3317
|
}
|
|
3318
|
+
defineConfigs++;
|
|
3305
3319
|
const args2 = call.getArguments();
|
|
3306
3320
|
if (args2.length === 0) continue;
|
|
3307
3321
|
const configArg = args2[0];
|
|
@@ -3348,14 +3362,21 @@ function processFile(filePath, project) {
|
|
|
3348
3362
|
);
|
|
3349
3363
|
}
|
|
3350
3364
|
}
|
|
3351
|
-
return changes;
|
|
3365
|
+
return { changes, defineConfigs };
|
|
3352
3366
|
}
|
|
3353
3367
|
async function main() {
|
|
3354
3368
|
const srcDir = import_path.default.join(process.cwd(), "src");
|
|
3369
|
+
const tsConfigFilePath = import_path.default.resolve(srcDir, "../tsconfig.json");
|
|
3355
3370
|
console.log(`Scanning for defineConfig calls in: ${srcDir}
|
|
3356
3371
|
`);
|
|
3372
|
+
if (!(0, import_fs.existsSync)(tsConfigFilePath)) {
|
|
3373
|
+
warnSkipped(
|
|
3374
|
+
`tsconfig.json not found next to ${srcDir}, so no source could be read; add APPROVE_CORRECTION/REJECT_CORRECTION action configs by hand wherever REQUEST_CORRECTION sets flags or conditionals`
|
|
3375
|
+
);
|
|
3376
|
+
return skipped;
|
|
3377
|
+
}
|
|
3357
3378
|
const project = new import_ts_morph.Project({
|
|
3358
|
-
tsConfigFilePath
|
|
3379
|
+
tsConfigFilePath,
|
|
3359
3380
|
skipAddingFilesFromTsConfig: false
|
|
3360
3381
|
});
|
|
3361
3382
|
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
@@ -3365,20 +3386,28 @@ async function main() {
|
|
|
3365
3386
|
console.log(`Found ${sourceFiles.length} source file(s) to analyse.
|
|
3366
3387
|
`);
|
|
3367
3388
|
let totalChanges = 0;
|
|
3389
|
+
let totalDefineConfigs = 0;
|
|
3368
3390
|
const modifiedFiles = [];
|
|
3369
3391
|
for (const sourceFile of sourceFiles) {
|
|
3370
3392
|
const filePath = sourceFile.getFilePath();
|
|
3371
|
-
const changes = processFile(filePath, project);
|
|
3393
|
+
const { changes, defineConfigs } = processFile(filePath, project);
|
|
3394
|
+
totalDefineConfigs += defineConfigs;
|
|
3372
3395
|
if (changes > 0) {
|
|
3373
3396
|
totalChanges += changes;
|
|
3374
3397
|
modifiedFiles.push(filePath);
|
|
3375
3398
|
}
|
|
3376
3399
|
}
|
|
3400
|
+
if (totalDefineConfigs === 0) {
|
|
3401
|
+
warnSkipped(
|
|
3402
|
+
"No defineConfig call was found under src/, so no event configuration could be inspected; check by hand that any flags or conditionals on REQUEST_CORRECTION are repeated on APPROVE_CORRECTION and REJECT_CORRECTION"
|
|
3403
|
+
);
|
|
3404
|
+
return skipped;
|
|
3405
|
+
}
|
|
3377
3406
|
if (modifiedFiles.length === 0) {
|
|
3378
3407
|
console.log(
|
|
3379
|
-
|
|
3408
|
+
`No REQUEST_CORRECTION actions with flags/conditionals found across ${totalDefineConfigs} defineConfig call(s). Nothing to do.`
|
|
3380
3409
|
);
|
|
3381
|
-
return;
|
|
3410
|
+
return skipped;
|
|
3382
3411
|
}
|
|
3383
3412
|
console.log(`
|
|
3384
3413
|
Saving ${modifiedFiles.length} modified file(s)...`);
|
|
@@ -3391,187 +3420,1936 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
3391
3420
|
`
|
|
3392
3421
|
Done. Added ${totalChanges} correction action config(s) across ${modifiedFiles.length} file(s).`
|
|
3393
3422
|
);
|
|
3423
|
+
return skipped;
|
|
3394
3424
|
}
|
|
3395
3425
|
|
|
3396
|
-
// src/migrations/v2.1/
|
|
3397
|
-
|
|
3398
|
-
|
|
3399
|
-
|
|
3426
|
+
// src/migrations/v2.1/add-recovery-link-notifications.ts
|
|
3427
|
+
var import_ts_morph2 = require("ts-morph");
|
|
3428
|
+
var import_fs3 = require("fs");
|
|
3429
|
+
var import_path2 = __toESM(require("path"));
|
|
3400
3430
|
|
|
3401
|
-
// src/
|
|
3402
|
-
var
|
|
3403
|
-
|
|
3404
|
-
|
|
3405
|
-
|
|
3406
|
-
|
|
3407
|
-
|
|
3408
|
-
|
|
3409
|
-
|
|
3410
|
-
|
|
3411
|
-
|
|
3412
|
-
|
|
3413
|
-
|
|
3414
|
-
|
|
3415
|
-
}
|
|
3416
|
-
|
|
3431
|
+
// src/csv.ts
|
|
3432
|
+
var import_fs2 = require("fs");
|
|
3433
|
+
function parseCsvLine(line2) {
|
|
3434
|
+
const values = [];
|
|
3435
|
+
let value = "";
|
|
3436
|
+
let quoted = false;
|
|
3437
|
+
for (let index = 0; index < line2.length; index++) {
|
|
3438
|
+
const character = line2[index];
|
|
3439
|
+
if (quoted) {
|
|
3440
|
+
if (character !== '"') {
|
|
3441
|
+
value += character;
|
|
3442
|
+
} else if (line2[index + 1] === '"') {
|
|
3443
|
+
value += '"';
|
|
3444
|
+
index++;
|
|
3445
|
+
} else {
|
|
3446
|
+
quoted = false;
|
|
3417
3447
|
}
|
|
3448
|
+
continue;
|
|
3449
|
+
}
|
|
3450
|
+
if (character === '"') {
|
|
3451
|
+
quoted = true;
|
|
3452
|
+
} else if (character === ",") {
|
|
3453
|
+
values.push(value);
|
|
3454
|
+
value = "";
|
|
3455
|
+
} else {
|
|
3456
|
+
value += character;
|
|
3418
3457
|
}
|
|
3419
|
-
);
|
|
3420
|
-
if (missingDirectories.length > 0) {
|
|
3421
|
-
throw new Error(
|
|
3422
|
-
`The current directory is not a valid OpenCRVS country configuration repository. Missing required director${missingDirectories.length === 1 ? "y" : "ies"}: ${missingDirectories.join(", ")}`
|
|
3423
|
-
);
|
|
3424
3458
|
}
|
|
3459
|
+
values.push(value);
|
|
3460
|
+
return values;
|
|
3425
3461
|
}
|
|
3426
|
-
|
|
3427
|
-
|
|
3428
|
-
|
|
3429
|
-
|
|
3462
|
+
function toCsvLine(values) {
|
|
3463
|
+
return values.map(
|
|
3464
|
+
(value) => /["\n,]/.test(value) ? `"${value.replace(/"/g, '""')}"` : value
|
|
3465
|
+
).join(",");
|
|
3430
3466
|
}
|
|
3431
|
-
|
|
3432
|
-
|
|
3433
|
-
|
|
3434
|
-
await upgradeEnvironmentLayout2();
|
|
3467
|
+
function idOf(line2) {
|
|
3468
|
+
const comma = line2.indexOf(",");
|
|
3469
|
+
return comma === -1 ? line2 : line2.slice(0, comma);
|
|
3435
3470
|
}
|
|
3436
|
-
|
|
3437
|
-
|
|
3438
|
-
|
|
3439
|
-
|
|
3471
|
+
function readCsvFile(path10) {
|
|
3472
|
+
if (!(0, import_fs2.existsSync)(path10)) {
|
|
3473
|
+
return void 0;
|
|
3474
|
+
}
|
|
3475
|
+
const contents = (0, import_fs2.readFileSync)(path10, "utf8");
|
|
3476
|
+
const newline = contents.includes("\r\n") ? "\r\n" : "\n";
|
|
3477
|
+
const trailingNewline = /\r?\n$/.test(contents);
|
|
3478
|
+
const lines = contents.replace(/\r?\n$/, "").split(/\r?\n/);
|
|
3479
|
+
const body = lines.slice(1).filter((line2) => line2 !== "");
|
|
3480
|
+
return { header: lines[0], body, newline, trailingNewline };
|
|
3440
3481
|
}
|
|
3441
|
-
|
|
3442
|
-
|
|
3443
|
-
|
|
3444
|
-
|
|
3482
|
+
function writeCsvFile(path10, file) {
|
|
3483
|
+
(0, import_fs2.writeFileSync)(
|
|
3484
|
+
path10,
|
|
3485
|
+
[file.header, ...file.body].join(file.newline) + (file.trailingNewline ? file.newline : "")
|
|
3486
|
+
);
|
|
3445
3487
|
}
|
|
3446
|
-
|
|
3447
|
-
|
|
3448
|
-
|
|
3488
|
+
function addRows(file, rows) {
|
|
3489
|
+
const isSorted = file.body.every(
|
|
3490
|
+
(line2, index) => index === 0 || idOf(file.body[index - 1]) <= idOf(line2)
|
|
3491
|
+
);
|
|
3492
|
+
const added = [];
|
|
3493
|
+
for (const row of rows) {
|
|
3494
|
+
const id = idOf(row);
|
|
3495
|
+
if (file.body.some((line2) => idOf(line2) === id)) {
|
|
3496
|
+
continue;
|
|
3497
|
+
}
|
|
3498
|
+
const insertAt = isSorted ? file.body.findIndex((line2) => idOf(line2) > id) : -1;
|
|
3499
|
+
if (insertAt === -1) {
|
|
3500
|
+
file.body.push(row);
|
|
3501
|
+
} else {
|
|
3502
|
+
file.body.splice(insertAt, 0, row);
|
|
3503
|
+
}
|
|
3504
|
+
added.push(id);
|
|
3505
|
+
}
|
|
3506
|
+
return added;
|
|
3449
3507
|
}
|
|
3450
3508
|
|
|
3451
|
-
// src/
|
|
3452
|
-
var
|
|
3453
|
-
var
|
|
3454
|
-
|
|
3455
|
-
|
|
3456
|
-
|
|
3457
|
-
|
|
3458
|
-
|
|
3459
|
-
|
|
3460
|
-
|
|
3461
|
-
|
|
3462
|
-
|
|
3463
|
-
var
|
|
3464
|
-
|
|
3465
|
-
|
|
3466
|
-
|
|
3467
|
-
|
|
3468
|
-
|
|
3469
|
-
|
|
3470
|
-
|
|
3471
|
-
|
|
3472
|
-
|
|
3473
|
-
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
|
|
3477
|
-
|
|
3478
|
-
|
|
3479
|
-
|
|
3480
|
-
|
|
3509
|
+
// src/migrations/v2.1/add-recovery-link-notifications.ts
|
|
3510
|
+
var EMAIL_TEMPLATES_FILE = "src/api/notification/email-templates/index.ts";
|
|
3511
|
+
var SMS_SERVICE_FILE = "src/api/notification/sms-service.ts";
|
|
3512
|
+
var HANDLER_FILE = "src/api/notification/handler.ts";
|
|
3513
|
+
var ROUTES_FILE = "src/config/routes/userNotificationRoutes.ts";
|
|
3514
|
+
var EMAIL_TEMPLATE_DIR = "src/api/notification/email-templates/other";
|
|
3515
|
+
var NOTIFICATION_CSV = "src/translations/notification.csv";
|
|
3516
|
+
var LOGIN_CSV = "src/translations/login.csv";
|
|
3517
|
+
var TRIGGER_VARIABLE_OBJECT = "TriggerVariable";
|
|
3518
|
+
var TEMPLATES_OBJECT = "templates";
|
|
3519
|
+
var OTHER_TEMPLATES_OBJECT = "otherTemplates";
|
|
3520
|
+
var TRIGGER_TO_SMS_TEMPLATE_OBJECT = "TriggerToSMSTemplate";
|
|
3521
|
+
var CONVERT_PAYLOAD_FUNCTION = "convertPayloadToVariable";
|
|
3522
|
+
var ROUTES_FUNCTION = "getUserNotificationRoutes";
|
|
3523
|
+
var RECOVERY_EVENTS = [
|
|
3524
|
+
{
|
|
3525
|
+
id: "password-reset-link",
|
|
3526
|
+
constant: "PASSWORD_RESET_LINK",
|
|
3527
|
+
smsTemplate: "resetPasswordLinkNotification",
|
|
3528
|
+
emailSubject: "Reset your password",
|
|
3529
|
+
routeDescription: "Handles notification for password reset recovery link",
|
|
3530
|
+
heading: "Reset your password",
|
|
3531
|
+
reason: "Someone asked to reset the password for your {{applicationName}}\n account.",
|
|
3532
|
+
linkLabel: "Reset your password"
|
|
3533
|
+
},
|
|
3534
|
+
{
|
|
3535
|
+
id: "username-reminder-link",
|
|
3536
|
+
constant: "USERNAME_REMINDER_LINK",
|
|
3537
|
+
smsTemplate: "retrieveUsernameLinkNotification",
|
|
3538
|
+
emailSubject: "Retrieve your username",
|
|
3539
|
+
routeDescription: "Handles notification for username reminder recovery link",
|
|
3540
|
+
heading: "Retrieve your username",
|
|
3541
|
+
reason: "Someone asked for a reminder of the username for your\n {{applicationName}} account.",
|
|
3542
|
+
linkLabel: "Retrieve your username"
|
|
3481
3543
|
}
|
|
3482
|
-
|
|
3483
|
-
|
|
3484
|
-
|
|
3485
|
-
|
|
3486
|
-
|
|
3487
|
-
|
|
3488
|
-
|
|
3489
|
-
|
|
3490
|
-
|
|
3491
|
-
`
|
|
3492
|
-
|
|
3493
|
-
|
|
3544
|
+
];
|
|
3545
|
+
var NOTIFICATION_CSV_ROWS = [
|
|
3546
|
+
`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}}}`,
|
|
3547
|
+
`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}}}`
|
|
3548
|
+
];
|
|
3549
|
+
var LOGIN_CSV_ROWS = [
|
|
3550
|
+
`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`,
|
|
3551
|
+
`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."`,
|
|
3552
|
+
`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`,
|
|
3553
|
+
`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`,
|
|
3554
|
+
`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.`,
|
|
3555
|
+
`resetCredentials.recoveryLinkLanding.expired.link,Link back to the forgotten item form shown on an expired/invalid recovery link,Start again,Recommencer`,
|
|
3556
|
+
`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`
|
|
3557
|
+
];
|
|
3558
|
+
var skipped2 = [];
|
|
3559
|
+
function warnSkipped2(message) {
|
|
3560
|
+
skipped2.push(message);
|
|
3561
|
+
console.warn(` \u26A0\uFE0F ${message}`);
|
|
3562
|
+
}
|
|
3563
|
+
function findObjectLiteral(declaration) {
|
|
3564
|
+
let expression = declaration?.getInitializer();
|
|
3565
|
+
while (expression && (import_ts_morph2.Node.isAsExpression(expression) || import_ts_morph2.Node.isSatisfiesExpression(expression))) {
|
|
3566
|
+
expression = expression.getExpression();
|
|
3494
3567
|
}
|
|
3568
|
+
return expression && import_ts_morph2.Node.isObjectLiteralExpression(expression) ? expression : void 0;
|
|
3495
3569
|
}
|
|
3496
|
-
|
|
3497
|
-
const
|
|
3498
|
-
|
|
3499
|
-
|
|
3500
|
-
|
|
3501
|
-
|
|
3502
|
-
|
|
3503
|
-
|
|
3504
|
-
|
|
3505
|
-
|
|
3506
|
-
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
|
|
3570
|
+
function hasKeyFor(obj, key, constant) {
|
|
3571
|
+
const accepted = /* @__PURE__ */ new Set([
|
|
3572
|
+
`[TriggerEvent.${constant}]`,
|
|
3573
|
+
`['${key}']`,
|
|
3574
|
+
`["${key}"]`,
|
|
3575
|
+
`'${key}'`,
|
|
3576
|
+
`"${key}"`,
|
|
3577
|
+
key
|
|
3578
|
+
]);
|
|
3579
|
+
return obj.getProperties().some(
|
|
3580
|
+
(property) => import_ts_morph2.Node.isPropertyAssignment(property) && accepted.has(property.getName().trim())
|
|
3581
|
+
);
|
|
3582
|
+
}
|
|
3583
|
+
function renderKey(obj, key, constant) {
|
|
3584
|
+
const names = obj.getProperties().filter(import_ts_morph2.Node.isPropertyAssignment).map((property) => property.getName().trim());
|
|
3585
|
+
if (names.some((name) => name.startsWith("[TriggerEvent."))) {
|
|
3586
|
+
return `[TriggerEvent.${constant}]`;
|
|
3512
3587
|
}
|
|
3513
|
-
|
|
3514
|
-
|
|
3515
|
-
return runEnvironmentCommand("initialisation", runEnvironmentInit);
|
|
3516
|
-
case "upgrade":
|
|
3517
|
-
return runEnvironmentCommand("environment upgrade", runEnvironmentUpgrade);
|
|
3518
|
-
case "update-workflows":
|
|
3519
|
-
return runEnvironmentCommand(
|
|
3520
|
-
"workflow update",
|
|
3521
|
-
runEnvironmentUpdateWorkflows
|
|
3522
|
-
);
|
|
3523
|
-
case "users":
|
|
3524
|
-
return runEnvironmentCommand("user management", runEnvironmentUsers);
|
|
3525
|
-
case "swarm-to-k8s":
|
|
3526
|
-
return runEnvironmentCommand(
|
|
3527
|
-
"Swarm to Kubernetes migration",
|
|
3528
|
-
runEnvironmentSwarmToK8s
|
|
3529
|
-
);
|
|
3530
|
-
default:
|
|
3531
|
-
console.error(`Unknown subcommand: environment ${subcommand}`);
|
|
3532
|
-
process.exit(1);
|
|
3588
|
+
if (names.some((name) => name.startsWith("["))) {
|
|
3589
|
+
return `['${key}']`;
|
|
3533
3590
|
}
|
|
3591
|
+
return `'${key}'`;
|
|
3534
3592
|
}
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
|
|
3538
|
-
|
|
3539
|
-
|
|
3540
|
-
|
|
3541
|
-
|
|
3593
|
+
function appendEntry(sourceFile, objectName, key, valueLines) {
|
|
3594
|
+
const obj = findObjectLiteral(sourceFile.getVariableDeclaration(objectName));
|
|
3595
|
+
const properties = obj?.getProperties() ?? [];
|
|
3596
|
+
const lastProperty = properties[properties.length - 1];
|
|
3597
|
+
if (!lastProperty) return false;
|
|
3598
|
+
const indent = lastProperty.getIndentationText();
|
|
3599
|
+
const entry = valueLines.map((line2, index) => `${indent}${index === 0 ? `${key}: ${line2}` : line2}`).join("\n");
|
|
3600
|
+
sourceFile.insertText(lastProperty.getEnd(), `,
|
|
3601
|
+
${entry}`);
|
|
3602
|
+
return true;
|
|
3603
|
+
}
|
|
3604
|
+
function objectHasKeyFor(sourceFile, objectName, key, constant) {
|
|
3605
|
+
const obj = findObjectLiteral(sourceFile.getVariableDeclaration(objectName));
|
|
3606
|
+
return obj ? hasKeyFor(obj, key, constant) : false;
|
|
3607
|
+
}
|
|
3608
|
+
function renderKeyFor(sourceFile, objectName, key, constant) {
|
|
3609
|
+
const obj = findObjectLiteral(sourceFile.getVariableDeclaration(objectName));
|
|
3610
|
+
return obj ? renderKey(obj, key, constant) : `'${key}'`;
|
|
3611
|
+
}
|
|
3612
|
+
function updateEmailTemplates(project, cwd) {
|
|
3613
|
+
const sourceFile = project.getSourceFile(import_path2.default.join(cwd, EMAIL_TEMPLATES_FILE));
|
|
3614
|
+
if (!sourceFile) {
|
|
3615
|
+
warnSkipped2(`${EMAIL_TEMPLATES_FILE} not found; email templates not wired`);
|
|
3616
|
+
return;
|
|
3617
|
+
}
|
|
3618
|
+
const missingObject = [TRIGGER_VARIABLE_OBJECT, TEMPLATES_OBJECT].find(
|
|
3619
|
+
(objectName) => !findObjectLiteral(sourceFile.getVariableDeclaration(objectName))
|
|
3620
|
+
);
|
|
3621
|
+
if (missingObject) {
|
|
3622
|
+
warnSkipped2(
|
|
3623
|
+
`Could not find '${missingObject}' in ${EMAIL_TEMPLATES_FILE}; email templates not wired`
|
|
3542
3624
|
);
|
|
3543
|
-
|
|
3625
|
+
return;
|
|
3626
|
+
}
|
|
3627
|
+
for (const event of RECOVERY_EVENTS) {
|
|
3628
|
+
if (!objectHasKeyFor(
|
|
3629
|
+
sourceFile,
|
|
3630
|
+
TRIGGER_VARIABLE_OBJECT,
|
|
3631
|
+
event.id,
|
|
3632
|
+
event.constant
|
|
3633
|
+
) && appendEntry(
|
|
3634
|
+
sourceFile,
|
|
3635
|
+
TRIGGER_VARIABLE_OBJECT,
|
|
3636
|
+
renderKeyFor(
|
|
3637
|
+
sourceFile,
|
|
3638
|
+
TRIGGER_VARIABLE_OBJECT,
|
|
3639
|
+
event.id,
|
|
3640
|
+
event.constant
|
|
3641
|
+
),
|
|
3642
|
+
[
|
|
3643
|
+
"z.object({",
|
|
3644
|
+
" firstname: z.string(),",
|
|
3645
|
+
" applicationName: z.string(),",
|
|
3646
|
+
" countryLogo: z.string(),",
|
|
3647
|
+
" recoveryURL: z.string()",
|
|
3648
|
+
"})"
|
|
3649
|
+
]
|
|
3650
|
+
)) {
|
|
3651
|
+
console.log(` \u2713 ${EMAIL_TEMPLATES_FILE}: ${event.id} variables`);
|
|
3652
|
+
}
|
|
3653
|
+
if (!objectHasKeyFor(
|
|
3654
|
+
sourceFile,
|
|
3655
|
+
TEMPLATES_OBJECT,
|
|
3656
|
+
event.id,
|
|
3657
|
+
event.constant
|
|
3658
|
+
) && appendEntry(
|
|
3659
|
+
sourceFile,
|
|
3660
|
+
TEMPLATES_OBJECT,
|
|
3661
|
+
renderKeyFor(sourceFile, TEMPLATES_OBJECT, event.id, event.constant),
|
|
3662
|
+
[
|
|
3663
|
+
"{",
|
|
3664
|
+
` type: '${event.id}',`,
|
|
3665
|
+
` subject: '${event.emailSubject}',`,
|
|
3666
|
+
` template: readOtherTemplate<TriggerVariable['${event.id}']>(`,
|
|
3667
|
+
` '${event.id}'`,
|
|
3668
|
+
" )",
|
|
3669
|
+
"}"
|
|
3670
|
+
]
|
|
3671
|
+
)) {
|
|
3672
|
+
console.log(` \u2713 ${EMAIL_TEMPLATES_FILE}: ${event.id} template`);
|
|
3673
|
+
}
|
|
3544
3674
|
}
|
|
3545
3675
|
}
|
|
3546
|
-
|
|
3547
|
-
const
|
|
3548
|
-
if (
|
|
3549
|
-
|
|
3550
|
-
|
|
3676
|
+
function updateSmsService(project, cwd) {
|
|
3677
|
+
const sourceFile = project.getSourceFile(import_path2.default.join(cwd, SMS_SERVICE_FILE));
|
|
3678
|
+
if (!sourceFile) {
|
|
3679
|
+
warnSkipped2(`${SMS_SERVICE_FILE} not found; SMS templates not wired`);
|
|
3680
|
+
return;
|
|
3551
3681
|
}
|
|
3552
|
-
const
|
|
3553
|
-
|
|
3554
|
-
|
|
3682
|
+
const missingObject = [
|
|
3683
|
+
OTHER_TEMPLATES_OBJECT,
|
|
3684
|
+
TRIGGER_TO_SMS_TEMPLATE_OBJECT
|
|
3685
|
+
].find(
|
|
3686
|
+
(objectName) => !findObjectLiteral(sourceFile.getVariableDeclaration(objectName))
|
|
3555
3687
|
);
|
|
3556
|
-
if (
|
|
3557
|
-
|
|
3558
|
-
`
|
|
3559
|
-
|
|
3560
|
-
|
|
3688
|
+
if (missingObject) {
|
|
3689
|
+
warnSkipped2(
|
|
3690
|
+
`Could not find '${missingObject}' in ${SMS_SERVICE_FILE}; SMS templates not wired`
|
|
3691
|
+
);
|
|
3692
|
+
return;
|
|
3693
|
+
}
|
|
3694
|
+
for (const event of RECOVERY_EVENTS) {
|
|
3695
|
+
if (!objectHasKeyFor(
|
|
3696
|
+
sourceFile,
|
|
3697
|
+
OTHER_TEMPLATES_OBJECT,
|
|
3698
|
+
event.smsTemplate,
|
|
3699
|
+
event.smsTemplate
|
|
3700
|
+
) && appendEntry(sourceFile, OTHER_TEMPLATES_OBJECT, event.smsTemplate, [
|
|
3701
|
+
`'${event.smsTemplate}'`
|
|
3702
|
+
])) {
|
|
3703
|
+
console.log(` \u2713 ${SMS_SERVICE_FILE}: ${event.smsTemplate}`);
|
|
3704
|
+
}
|
|
3705
|
+
if (!objectHasKeyFor(
|
|
3706
|
+
sourceFile,
|
|
3707
|
+
TRIGGER_TO_SMS_TEMPLATE_OBJECT,
|
|
3708
|
+
event.id,
|
|
3709
|
+
event.constant
|
|
3710
|
+
) && appendEntry(
|
|
3711
|
+
sourceFile,
|
|
3712
|
+
TRIGGER_TO_SMS_TEMPLATE_OBJECT,
|
|
3713
|
+
renderKeyFor(
|
|
3714
|
+
sourceFile,
|
|
3715
|
+
TRIGGER_TO_SMS_TEMPLATE_OBJECT,
|
|
3716
|
+
event.id,
|
|
3717
|
+
event.constant
|
|
3718
|
+
),
|
|
3719
|
+
[`'${event.smsTemplate}'`]
|
|
3720
|
+
)) {
|
|
3721
|
+
console.log(
|
|
3722
|
+
` \u2713 ${SMS_SERVICE_FILE}: ${event.id} -> ${event.smsTemplate}`
|
|
3723
|
+
);
|
|
3724
|
+
}
|
|
3725
|
+
}
|
|
3726
|
+
}
|
|
3727
|
+
function updateHandler(project, cwd) {
|
|
3728
|
+
const sourceFile = project.getSourceFile(import_path2.default.join(cwd, HANDLER_FILE));
|
|
3729
|
+
if (!sourceFile) {
|
|
3730
|
+
warnSkipped2(`${HANDLER_FILE} not found; payload conversion not wired`);
|
|
3731
|
+
return;
|
|
3732
|
+
}
|
|
3733
|
+
const convertPayload = sourceFile.getFunction(CONVERT_PAYLOAD_FUNCTION);
|
|
3734
|
+
const caseBlock = convertPayload?.getFirstDescendantByKind(import_ts_morph2.SyntaxKind.SwitchStatement)?.getCaseBlock();
|
|
3735
|
+
if (!caseBlock) {
|
|
3736
|
+
warnSkipped2(
|
|
3737
|
+
`Could not find a switch inside '${CONVERT_PAYLOAD_FUNCTION}' in ${HANDLER_FILE}; payload conversion not wired`
|
|
3738
|
+
);
|
|
3739
|
+
return;
|
|
3740
|
+
}
|
|
3741
|
+
const missing = RECOVERY_EVENTS.filter(
|
|
3742
|
+
(event) => !caseBlock.getText().includes(`TriggerEvent.${event.constant}`) && !caseBlock.getText().includes(`'${event.id}'`)
|
|
3743
|
+
);
|
|
3744
|
+
if (missing.length === 0) return;
|
|
3745
|
+
const existingClauses = caseBlock.getClauses();
|
|
3746
|
+
if (existingClauses.length === 0) {
|
|
3747
|
+
warnSkipped2(
|
|
3748
|
+
`The switch inside '${CONVERT_PAYLOAD_FUNCTION}' in ${HANDLER_FILE} has no cases; payload conversion not wired`
|
|
3749
|
+
);
|
|
3750
|
+
return;
|
|
3751
|
+
}
|
|
3752
|
+
const defaultClause = existingClauses.find(import_ts_morph2.Node.isDefaultClause);
|
|
3753
|
+
const anchor = defaultClause ?? existingClauses[existingClauses.length - 1];
|
|
3754
|
+
const indent = anchor.getIndentationText();
|
|
3755
|
+
const lines = [
|
|
3756
|
+
...missing.map((event) => `case TriggerEvent.${event.constant}:`),
|
|
3757
|
+
` return {`,
|
|
3758
|
+
` firstname,`,
|
|
3759
|
+
` applicationName: applicationConfig.APPLICATION_NAME,`,
|
|
3760
|
+
` countryLogo: COUNTRY_LOGO_URL,`,
|
|
3761
|
+
` recoveryURL: \`\${LOGIN_URL}recover?token=\${encodeURIComponent(payload.token)}\``,
|
|
3762
|
+
` }`
|
|
3763
|
+
];
|
|
3764
|
+
if (defaultClause) {
|
|
3765
|
+
caseBlock.insertText(
|
|
3766
|
+
anchor.getStart(),
|
|
3767
|
+
`${lines.map((line2, index) => index === 0 ? line2 : `${indent}${line2}`).join("\n")}
|
|
3768
|
+
${indent}`
|
|
3769
|
+
);
|
|
3770
|
+
} else {
|
|
3771
|
+
caseBlock.insertText(
|
|
3772
|
+
anchor.getEnd(),
|
|
3773
|
+
`
|
|
3774
|
+
${lines.map((line2) => `${indent}${line2}`).join("\n")}`
|
|
3775
|
+
);
|
|
3776
|
+
}
|
|
3777
|
+
for (const event of missing) {
|
|
3778
|
+
console.log(` \u2713 ${HANDLER_FILE}: ${event.id} case`);
|
|
3779
|
+
}
|
|
3780
|
+
}
|
|
3781
|
+
function updateRoutes(project, cwd) {
|
|
3782
|
+
const sourceFile = project.getSourceFile(import_path2.default.join(cwd, ROUTES_FILE));
|
|
3783
|
+
if (!sourceFile) {
|
|
3784
|
+
warnSkipped2(`${ROUTES_FILE} not found; trigger routes not registered`);
|
|
3785
|
+
return;
|
|
3786
|
+
}
|
|
3787
|
+
const routesFunction = sourceFile.getFunction(ROUTES_FUNCTION) ?? sourceFile.getFunctions().find((fn) => fn.isDefaultExport());
|
|
3788
|
+
const routesArray = routesFunction?.getFirstDescendantByKind(import_ts_morph2.SyntaxKind.ReturnStatement)?.getExpressionIfKind(import_ts_morph2.SyntaxKind.ArrayLiteralExpression);
|
|
3789
|
+
if (!routesArray) {
|
|
3790
|
+
warnSkipped2(
|
|
3791
|
+
`Could not find the route array returned by '${ROUTES_FUNCTION}' in ${ROUTES_FILE}; trigger routes not registered`
|
|
3792
|
+
);
|
|
3793
|
+
return;
|
|
3794
|
+
}
|
|
3795
|
+
for (const event of RECOVERY_EVENTS) {
|
|
3796
|
+
if (routesArray.getText().includes(`/triggers/user/${event.id}`)) continue;
|
|
3797
|
+
routesArray.addElement(`{
|
|
3798
|
+
method: 'POST',
|
|
3799
|
+
path: '/triggers/user/${event.id}',
|
|
3800
|
+
handler: makeNotificationHandler('${event.id}'),
|
|
3801
|
+
options: {
|
|
3802
|
+
auth: false,
|
|
3803
|
+
tags: ['api'],
|
|
3804
|
+
description: '${event.routeDescription}'
|
|
3805
|
+
}
|
|
3806
|
+
}`);
|
|
3807
|
+
console.log(` \u2713 ${ROUTES_FILE}: POST /triggers/user/${event.id}`);
|
|
3808
|
+
}
|
|
3809
|
+
}
|
|
3810
|
+
function renderEmailTemplate(event) {
|
|
3811
|
+
return `<!--
|
|
3812
|
+
This Source Code Form is subject to the terms of the Mozilla Public
|
|
3813
|
+
License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
3814
|
+
file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
3815
|
+
|
|
3816
|
+
OpenCRVS is also distributed under the terms of the Civil Registration
|
|
3817
|
+
& Healthcare Disclaimer located at http://opencrvs.org/license.
|
|
3818
|
+
|
|
3819
|
+
Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
|
|
3820
|
+
-->
|
|
3821
|
+
<!doctype html>
|
|
3822
|
+
<html>
|
|
3823
|
+
<head>
|
|
3824
|
+
<link
|
|
3825
|
+
href="https://fonts.googleapis.com/css2?family=Noto+Sans:wght@400;700&display=swap"
|
|
3826
|
+
rel="stylesheet"
|
|
3827
|
+
/>
|
|
3828
|
+
<style type="text/css">
|
|
3829
|
+
body {
|
|
3830
|
+
font-family: 'Noto Sans', sans-serif;
|
|
3831
|
+
color: #222;
|
|
3832
|
+
padding: 16px 24px;
|
|
3833
|
+
}
|
|
3834
|
+
|
|
3835
|
+
h1 {
|
|
3836
|
+
font-size: 21px;
|
|
3837
|
+
margin-top: 32px;
|
|
3838
|
+
margin-bottom: 36px;
|
|
3839
|
+
font-weight: 700;
|
|
3840
|
+
}
|
|
3841
|
+
|
|
3842
|
+
p {
|
|
3843
|
+
font-weight: 400;
|
|
3844
|
+
font-size: 16px;
|
|
3845
|
+
line-height: 1.8;
|
|
3846
|
+
margin-bottom: 24px;
|
|
3847
|
+
}
|
|
3848
|
+
|
|
3849
|
+
i {
|
|
3850
|
+
color: #666;
|
|
3851
|
+
font-weight: 400;
|
|
3852
|
+
font-size: 16px;
|
|
3853
|
+
}
|
|
3854
|
+
</style>
|
|
3855
|
+
</head>
|
|
3856
|
+
|
|
3857
|
+
<body>
|
|
3858
|
+
<img
|
|
3859
|
+
src="{{countryLogo}}"
|
|
3860
|
+
alt="country_logo"
|
|
3861
|
+
style="max-height: 88px; max-width: 100%"
|
|
3862
|
+
/>
|
|
3863
|
+
<h1>${event.heading}</h1>
|
|
3864
|
+
<p>Hello {{firstname}},</p>
|
|
3865
|
+
<p>
|
|
3866
|
+
${event.reason}
|
|
3867
|
+
</p>
|
|
3868
|
+
|
|
3869
|
+
<div style="margin-top: 32px; margin-bottom: 32px">
|
|
3870
|
+
<a href="{{{recoveryURL}}}">${event.linkLabel}</a>
|
|
3871
|
+
</div>
|
|
3872
|
+
<br />
|
|
3873
|
+
<p>
|
|
3874
|
+
This link expires in 1 hour and can only be used once. If you did not
|
|
3875
|
+
request this, you can ignore this email.
|
|
3876
|
+
</p>
|
|
3877
|
+
<br />
|
|
3878
|
+
<p>
|
|
3879
|
+
Best regards, <br />
|
|
3880
|
+
{{applicationName}} Team
|
|
3881
|
+
</p>
|
|
3882
|
+
</body>
|
|
3883
|
+
</html>
|
|
3884
|
+
`;
|
|
3885
|
+
}
|
|
3886
|
+
function writeEmailTemplates(cwd) {
|
|
3887
|
+
const templateDir = import_path2.default.join(cwd, EMAIL_TEMPLATE_DIR);
|
|
3888
|
+
if (!(0, import_fs3.existsSync)(templateDir)) {
|
|
3889
|
+
warnSkipped2(
|
|
3890
|
+
`${EMAIL_TEMPLATE_DIR} not found; recovery email bodies not written`
|
|
3891
|
+
);
|
|
3892
|
+
return;
|
|
3893
|
+
}
|
|
3894
|
+
for (const event of RECOVERY_EVENTS) {
|
|
3895
|
+
const templatePath = import_path2.default.join(templateDir, `${event.id}.html`);
|
|
3896
|
+
if ((0, import_fs3.existsSync)(templatePath)) continue;
|
|
3897
|
+
(0, import_fs3.writeFileSync)(templatePath, renderEmailTemplate(event));
|
|
3898
|
+
console.log(` \u2713 ${EMAIL_TEMPLATE_DIR}/${event.id}.html`);
|
|
3899
|
+
}
|
|
3900
|
+
}
|
|
3901
|
+
function addCsvRows(cwd, relativePath, rows) {
|
|
3902
|
+
const csvPath = import_path2.default.join(cwd, relativePath);
|
|
3903
|
+
const file = readCsvFile(csvPath);
|
|
3904
|
+
if (!file) {
|
|
3905
|
+
warnSkipped2(`${relativePath} not found; translations not added`);
|
|
3906
|
+
return;
|
|
3907
|
+
}
|
|
3908
|
+
const added = addRows(file, rows);
|
|
3909
|
+
if (added.length === 0) return;
|
|
3910
|
+
for (const id of added) {
|
|
3911
|
+
console.log(` \u2713 ${relativePath}: ${id}`);
|
|
3912
|
+
}
|
|
3913
|
+
writeCsvFile(csvPath, file);
|
|
3914
|
+
}
|
|
3915
|
+
async function main2() {
|
|
3916
|
+
const cwd = process.cwd();
|
|
3917
|
+
const tsConfigFilePath = import_path2.default.join(cwd, "tsconfig.json");
|
|
3918
|
+
console.log(
|
|
3919
|
+
"Registering the password-reset-link and username-reminder-link notifications...\n"
|
|
3920
|
+
);
|
|
3921
|
+
if (!(0, import_fs3.existsSync)(tsConfigFilePath)) {
|
|
3922
|
+
warnSkipped2(
|
|
3923
|
+
`tsconfig.json not found in ${cwd}; notification wiring skipped entirely`
|
|
3924
|
+
);
|
|
3925
|
+
return skipped2;
|
|
3926
|
+
}
|
|
3927
|
+
const project = new import_ts_morph2.Project({
|
|
3928
|
+
tsConfigFilePath,
|
|
3929
|
+
skipAddingFilesFromTsConfig: false,
|
|
3930
|
+
// ts-morph indents inserted code with four spaces by default, which every
|
|
3931
|
+
// country config's prettier run would immediately undo.
|
|
3932
|
+
manipulationSettings: { indentationText: import_ts_morph2.IndentationText.TwoSpaces }
|
|
3933
|
+
});
|
|
3934
|
+
updateEmailTemplates(project, cwd);
|
|
3935
|
+
updateSmsService(project, cwd);
|
|
3936
|
+
updateHandler(project, cwd);
|
|
3937
|
+
updateRoutes(project, cwd);
|
|
3938
|
+
await project.save();
|
|
3939
|
+
writeEmailTemplates(cwd);
|
|
3940
|
+
addCsvRows(cwd, NOTIFICATION_CSV, NOTIFICATION_CSV_ROWS);
|
|
3941
|
+
addCsvRows(cwd, LOGIN_CSV, LOGIN_CSV_ROWS);
|
|
3942
|
+
return skipped2;
|
|
3943
|
+
}
|
|
3944
|
+
|
|
3945
|
+
// src/migrations/v2.1/add-translations.ts
|
|
3946
|
+
var import_path3 = __toESM(require("path"));
|
|
3947
|
+
var REPOSITORY = "opencrvs/opencrvs-core";
|
|
3948
|
+
var TEMPLATE_TRANSLATIONS = "packages/countryconfig-template/src/translations";
|
|
3949
|
+
var APPLICATIONS = ["client", "login"];
|
|
3950
|
+
var TARGET_VERSION = "2.1";
|
|
3951
|
+
var skipped3 = [];
|
|
3952
|
+
function warnSkipped3(message) {
|
|
3953
|
+
skipped3.push(message);
|
|
3954
|
+
console.warn(` \u26A0\uFE0F ${message}`);
|
|
3955
|
+
}
|
|
3956
|
+
async function matchingRefs(namespace, prefix) {
|
|
3957
|
+
const url = `https://api.github.com/repos/${REPOSITORY}/git/matching-refs/${namespace}/${prefix}`;
|
|
3958
|
+
const response = await fetch(url, {
|
|
3959
|
+
headers: { accept: "application/vnd.github+json" }
|
|
3960
|
+
});
|
|
3961
|
+
if (!response.ok) {
|
|
3962
|
+
throw new Error(
|
|
3963
|
+
`GitHub answered ${response.status} ${response.statusText} for ${url}`
|
|
3964
|
+
);
|
|
3965
|
+
}
|
|
3966
|
+
const refs = await response.json();
|
|
3967
|
+
const patchOf = (ref) => Number(ref.split(".").pop()) || 0;
|
|
3968
|
+
return refs.map(({ ref }) => ref.replace(/^refs\/(heads|tags)\//, "")).sort((a, b) => patchOf(b) - patchOf(a));
|
|
3969
|
+
}
|
|
3970
|
+
async function candidateRefs() {
|
|
3971
|
+
return [
|
|
3972
|
+
...await matchingRefs("heads", `release/${TARGET_VERSION}.`),
|
|
3973
|
+
...await matchingRefs("tags", `v${TARGET_VERSION}.`),
|
|
3974
|
+
"develop"
|
|
3975
|
+
];
|
|
3976
|
+
}
|
|
3977
|
+
async function fetchTemplate(refs, application) {
|
|
3978
|
+
for (const ref of refs) {
|
|
3979
|
+
const url = `https://raw.githubusercontent.com/${REPOSITORY}/${ref}/${TEMPLATE_TRANSLATIONS}/${application}.csv`;
|
|
3980
|
+
const response = await fetch(url);
|
|
3981
|
+
if (response.ok) {
|
|
3982
|
+
return { ref, contents: await response.text() };
|
|
3983
|
+
}
|
|
3984
|
+
if (response.status !== 404) {
|
|
3985
|
+
throw new Error(
|
|
3986
|
+
`GitHub answered ${response.status} ${response.statusText} for ${url}`
|
|
3987
|
+
);
|
|
3988
|
+
}
|
|
3989
|
+
}
|
|
3990
|
+
warnSkipped3(
|
|
3991
|
+
`No ${application}.csv found in the ${TARGET_VERSION} country config template on GitHub; ${application}.csv not updated`
|
|
3992
|
+
);
|
|
3993
|
+
return void 0;
|
|
3994
|
+
}
|
|
3995
|
+
function rowsToAdd(local, template) {
|
|
3996
|
+
const localColumns = parseCsvLine(local.header);
|
|
3997
|
+
const templateColumns = parseCsvLine(template.header);
|
|
3998
|
+
return template.body.filter((line2) => line2 !== "").map((line2) => {
|
|
3999
|
+
const values = parseCsvLine(line2);
|
|
4000
|
+
return toCsvLine(
|
|
4001
|
+
localColumns.map((column) => {
|
|
4002
|
+
const index = templateColumns.indexOf(column);
|
|
4003
|
+
return index === -1 ? "" : values[index] ?? "";
|
|
4004
|
+
})
|
|
4005
|
+
);
|
|
4006
|
+
});
|
|
4007
|
+
}
|
|
4008
|
+
async function updateApplication(cwd, refs, application) {
|
|
4009
|
+
const relativePath = `src/translations/${application}.csv`;
|
|
4010
|
+
const local = readCsvFile(import_path3.default.join(cwd, relativePath));
|
|
4011
|
+
if (!local) {
|
|
4012
|
+
warnSkipped3(`${relativePath} not found; translations not added`);
|
|
4013
|
+
return;
|
|
4014
|
+
}
|
|
4015
|
+
const fetched = await fetchTemplate(refs, application);
|
|
4016
|
+
if (!fetched) {
|
|
4017
|
+
return;
|
|
4018
|
+
}
|
|
4019
|
+
const template = readTemplate(fetched.contents);
|
|
4020
|
+
const added = addRows(local, rowsToAdd(local, template));
|
|
4021
|
+
if (added.length === 0) {
|
|
4022
|
+
return;
|
|
4023
|
+
}
|
|
4024
|
+
try {
|
|
4025
|
+
writeCsvFile(import_path3.default.join(cwd, relativePath), local);
|
|
4026
|
+
} catch (error3) {
|
|
4027
|
+
warnSkipped3(
|
|
4028
|
+
`Could not write ${relativePath} (${error3.message}); translations not added`
|
|
4029
|
+
);
|
|
4030
|
+
return;
|
|
4031
|
+
}
|
|
4032
|
+
for (const id of added) {
|
|
4033
|
+
console.log(` \u2713 ${relativePath}: ${id}`);
|
|
4034
|
+
}
|
|
4035
|
+
}
|
|
4036
|
+
function readTemplate(contents) {
|
|
4037
|
+
const lines = contents.replace(/\r?\n$/, "").split(/\r?\n/);
|
|
4038
|
+
return {
|
|
4039
|
+
header: lines[0],
|
|
4040
|
+
body: lines.slice(1),
|
|
4041
|
+
newline: "\n",
|
|
4042
|
+
trailingNewline: true
|
|
4043
|
+
};
|
|
4044
|
+
}
|
|
4045
|
+
async function listRefs() {
|
|
4046
|
+
try {
|
|
4047
|
+
return await candidateRefs();
|
|
4048
|
+
} catch (error3) {
|
|
4049
|
+
warnSkipped3(
|
|
4050
|
+
`Could not list the ${TARGET_VERSION} refs on GitHub (${error3.message}); translations not added`
|
|
4051
|
+
);
|
|
4052
|
+
return void 0;
|
|
4053
|
+
}
|
|
4054
|
+
}
|
|
4055
|
+
async function main3() {
|
|
4056
|
+
const cwd = process.cwd();
|
|
4057
|
+
console.log("Adding the translation keys core gained this version...\n");
|
|
4058
|
+
const refs = await listRefs();
|
|
4059
|
+
if (refs) {
|
|
4060
|
+
for (const application of APPLICATIONS) {
|
|
4061
|
+
try {
|
|
4062
|
+
await updateApplication(cwd, refs, application);
|
|
4063
|
+
} catch (error3) {
|
|
4064
|
+
warnSkipped3(
|
|
4065
|
+
`Could not read ${application}.csv from the country config template on GitHub (${error3.message}); ${application}.csv not updated`
|
|
4066
|
+
);
|
|
4067
|
+
}
|
|
4068
|
+
}
|
|
4069
|
+
}
|
|
4070
|
+
return skipped3;
|
|
4071
|
+
}
|
|
4072
|
+
|
|
4073
|
+
// src/migrations/v2.1/enable-telemetry.ts
|
|
4074
|
+
var import_ts_morph3 = require("ts-morph");
|
|
4075
|
+
var import_fs4 = require("fs");
|
|
4076
|
+
var import_path4 = __toESM(require("path"));
|
|
4077
|
+
var HANDLER_FILE2 = "src/api/telemetry/handler.ts";
|
|
4078
|
+
var ENVIRONMENT_FILE = "src/environment.ts";
|
|
4079
|
+
var INDEX_FILE = "src/index.ts";
|
|
4080
|
+
var HANDLER_MODULE = "./api/telemetry/handler";
|
|
4081
|
+
var skipped4 = [];
|
|
4082
|
+
function warnSkipped4(message) {
|
|
4083
|
+
skipped4.push(message);
|
|
4084
|
+
console.warn(` \u26A0\uFE0F ${message}`);
|
|
4085
|
+
}
|
|
4086
|
+
var TELEMETRY_HANDLER_SOURCE = `/*
|
|
4087
|
+
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
4088
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
4089
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
4090
|
+
*
|
|
4091
|
+
* OpenCRVS is also distributed under the terms of the Civil Registration
|
|
4092
|
+
* & Healthcare Disclaimer located at http://opencrvs.org/license.
|
|
4093
|
+
*
|
|
4094
|
+
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
|
|
4095
|
+
*/
|
|
4096
|
+
|
|
4097
|
+
import { Request, ResponseToolkit } from '@hapi/hapi'
|
|
4098
|
+
import * as Joi from 'joi'
|
|
4099
|
+
import { sendTelemetry, TelemetryReport } from '@opencrvs/toolkit/telemetry'
|
|
4100
|
+
import { env } from '@countryconfig/environment'
|
|
4101
|
+
import { logger } from '@countryconfig/logger'
|
|
4102
|
+
import { applicationConfig } from '@countryconfig/api/application/application-config'
|
|
4103
|
+
|
|
4104
|
+
/** Report the events service posts to \`/trigger/telemetry\`. */
|
|
4105
|
+
export const telemetrySchema = Joi.object({
|
|
4106
|
+
reported_at: Joi.string().isoDate().required(),
|
|
4107
|
+
app_version: Joi.string().optional(),
|
|
4108
|
+
metrics: Joi.object()
|
|
4109
|
+
.pattern(
|
|
4110
|
+
Joi.string(),
|
|
4111
|
+
Joi.alternatives(Joi.number(), Joi.string(), Joi.boolean())
|
|
4112
|
+
)
|
|
4113
|
+
.required()
|
|
4114
|
+
})
|
|
4115
|
+
|
|
4116
|
+
interface IncomingReport {
|
|
4117
|
+
reported_at: string
|
|
4118
|
+
app_version?: string
|
|
4119
|
+
metrics: Record<string, number | string | boolean>
|
|
4120
|
+
}
|
|
4121
|
+
|
|
4122
|
+
/** Logged once at countryconfig startup while telemetry is disabled. */
|
|
4123
|
+
export const TELEMETRY_DISABLED_NOTICE =
|
|
4124
|
+
'Telemetry is disabled. Help improve OpenCRVS by sharing anonymous, ' +
|
|
4125
|
+
'aggregate usage metrics (registration and certificate counts, active ' +
|
|
4126
|
+
'users, uptime) \u2014 no personal, health, or otherwise protected record data ' +
|
|
4127
|
+
'ever leaves your instance. Enable it by setting TELEMETRY_ENABLED=true on ' +
|
|
4128
|
+
'the countryconfig service.'
|
|
4129
|
+
|
|
4130
|
+
/**
|
|
4131
|
+
* Receives a usage report from the events service and, when telemetry is
|
|
4132
|
+
* enabled for this instance, stamps the instance identity onto it and forwards
|
|
4133
|
+
* it to the status service via the toolkit's \`sendTelemetry\` (which owns the
|
|
4134
|
+
* endpoint and payload schema). The events service is unaware of whether
|
|
4135
|
+
* telemetry is enabled or of the country code / domain / environment reported.
|
|
4136
|
+
*/
|
|
4137
|
+
export async function telemetryHandler(request: Request, h: ResponseToolkit) {
|
|
4138
|
+
// Only accept OpenCRVS *system* tokens (the events service's service
|
|
4139
|
+
// token has userType 'system'). A logged-in user's token is a 'user' token,
|
|
4140
|
+
// so a user cannot submit telemetry with their own credentials \u2014 and the
|
|
4141
|
+
// service-token endpoint is not reachable through the public gateway.
|
|
4142
|
+
const credentials = request.auth.credentials as
|
|
4143
|
+
| { userType?: string }
|
|
4144
|
+
| undefined
|
|
4145
|
+
if (credentials?.userType !== 'system') {
|
|
4146
|
+
logger.warn('Telemetry: rejected a request that is not from a system token')
|
|
4147
|
+
return h.response({ error: 'forbidden' }).code(403)
|
|
4148
|
+
}
|
|
4149
|
+
|
|
4150
|
+
if (!env.TELEMETRY_ENABLED) {
|
|
4151
|
+
// The encouraging notice is logged once at startup (see index.ts); keep the
|
|
4152
|
+
// per-report path quiet.
|
|
4153
|
+
return h.response({ status: 'skipped' }).code(200)
|
|
4154
|
+
}
|
|
4155
|
+
|
|
4156
|
+
const incoming = request.payload as IncomingReport
|
|
4157
|
+
|
|
4158
|
+
// Only production instances report; staging, QA and local build the report
|
|
4159
|
+
// but never reach the status service. (This gate used to live in the
|
|
4160
|
+
// toolkit's sendTelemetry; each country config now owns it.)
|
|
4161
|
+
if (!env.isProduction) {
|
|
4162
|
+
logger.info(
|
|
4163
|
+
\`Telemetry: report for \${incoming.reported_at} was not sent \u2014 only production instances report\`
|
|
4164
|
+
)
|
|
4165
|
+
return h.response({ status: 'skipped' }).code(200)
|
|
4166
|
+
}
|
|
4167
|
+
|
|
4168
|
+
const report: TelemetryReport = {
|
|
4169
|
+
reported_at: incoming.reported_at,
|
|
4170
|
+
country_code: env.COUNTRY_CODE,
|
|
4171
|
+
organisation: env.ORGANISATION,
|
|
4172
|
+
// env.DOMAIN defaults to a wildcard for CORS in some setups; treat that as
|
|
4173
|
+
// "no domain" rather than reporting a literal "*".
|
|
4174
|
+
domain: env.DOMAIN && env.DOMAIN !== '*' ? env.DOMAIN : null,
|
|
4175
|
+
instance: {
|
|
4176
|
+
application_name: applicationConfig.APPLICATION_NAME,
|
|
4177
|
+
environment: env.ENVIRONMENT_NAME,
|
|
4178
|
+
app_version: incoming.app_version
|
|
4179
|
+
},
|
|
4180
|
+
metrics: incoming.metrics
|
|
4181
|
+
}
|
|
4182
|
+
|
|
4183
|
+
let result
|
|
4184
|
+
try {
|
|
4185
|
+
result = await sendTelemetry(report)
|
|
4186
|
+
} catch (error) {
|
|
4187
|
+
const message = error instanceof Error ? error.message : String(error)
|
|
4188
|
+
logger.error(\`Telemetry: forwarding to status service failed: \${message}\`)
|
|
4189
|
+
return h.response({ status: 'error' }).code(502)
|
|
4190
|
+
}
|
|
4191
|
+
|
|
4192
|
+
if (result.outcome === 'rejected') {
|
|
4193
|
+
logger.error(
|
|
4194
|
+
\`Telemetry: status service rejected report (HTTP \${result.status}): \${result.detail ?? ''}\`
|
|
4195
|
+
)
|
|
4196
|
+
return h.response({ status: 'error' }).code(502)
|
|
4197
|
+
}
|
|
4198
|
+
|
|
4199
|
+
logger.info(
|
|
4200
|
+
\`Telemetry: forwarded report for \${report.reported_at} to the status service\`
|
|
4201
|
+
)
|
|
4202
|
+
return h.response({ status: 'forwarded' }).code(202)
|
|
4203
|
+
}
|
|
4204
|
+
`;
|
|
4205
|
+
var TELEMETRY_DISABLED = {
|
|
4206
|
+
enabled: false,
|
|
4207
|
+
countryCode: "",
|
|
4208
|
+
organisation: ""
|
|
4209
|
+
};
|
|
4210
|
+
async function promptTelemetryConfig() {
|
|
4211
|
+
if (!process.stdin.isTTY) {
|
|
4212
|
+
return TELEMETRY_DISABLED;
|
|
4213
|
+
}
|
|
4214
|
+
const { confirm: confirm3, input: input4 } = await import("@inquirer/prompts");
|
|
4215
|
+
const enabled = await confirm3({
|
|
4216
|
+
message: "Enable anonymous usage telemetry to help improve OpenCRVS? Only aggregate metrics are shared \u2014 no personal or protected data.",
|
|
4217
|
+
default: true
|
|
4218
|
+
});
|
|
4219
|
+
if (!enabled) {
|
|
4220
|
+
return TELEMETRY_DISABLED;
|
|
4221
|
+
}
|
|
4222
|
+
const countryCode = (await input4({
|
|
4223
|
+
message: "Country code (ISO alpha-3, e.g. FAR):",
|
|
4224
|
+
validate: (value) => /^[A-Za-z]{3}$/.test(value.trim()) || "Enter a 3-letter ISO alpha-3 code."
|
|
4225
|
+
})).trim().toUpperCase();
|
|
4226
|
+
const organisation = (await input4({
|
|
4227
|
+
message: "Organisation running this instance:",
|
|
4228
|
+
validate: (value) => value.trim() !== "" || "Enter an organisation name."
|
|
4229
|
+
})).trim();
|
|
4230
|
+
return { enabled: true, countryCode, organisation };
|
|
4231
|
+
}
|
|
4232
|
+
function writeTelemetryHandler(cwd) {
|
|
4233
|
+
const handlerPath = import_path4.default.join(cwd, HANDLER_FILE2);
|
|
4234
|
+
if ((0, import_fs4.existsSync)(handlerPath)) {
|
|
4235
|
+
console.log(` ${HANDLER_FILE2} already present; left unchanged`);
|
|
4236
|
+
return;
|
|
4237
|
+
}
|
|
4238
|
+
(0, import_fs4.mkdirSync)(import_path4.default.dirname(handlerPath), { recursive: true });
|
|
4239
|
+
(0, import_fs4.writeFileSync)(handlerPath, TELEMETRY_HANDLER_SOURCE);
|
|
4240
|
+
console.log(` \u2713 ${HANDLER_FILE2}`);
|
|
4241
|
+
}
|
|
4242
|
+
function appendProperty(sourceFile, object, name, valueLines) {
|
|
4243
|
+
const properties = object.getProperties();
|
|
4244
|
+
const lastProperty = properties[properties.length - 1];
|
|
4245
|
+
if (!lastProperty) return false;
|
|
4246
|
+
const indent = lastProperty.getIndentationText();
|
|
4247
|
+
const entry = valueLines.map((line2, index) => `${indent}${index === 0 ? `${name}: ${line2}` : line2}`).join("\n");
|
|
4248
|
+
sourceFile.insertText(lastProperty.getEnd(), `,
|
|
4249
|
+
${entry}`);
|
|
4250
|
+
return true;
|
|
4251
|
+
}
|
|
4252
|
+
function ensureEnvalidNamedImports(sourceFile, names) {
|
|
4253
|
+
const importDeclaration = sourceFile.getImportDeclarations().find((declaration) => declaration.getModuleSpecifierValue() === "envalid");
|
|
4254
|
+
if (!importDeclaration) {
|
|
4255
|
+
warnSkipped4(
|
|
4256
|
+
`Could not find the 'envalid' import in ${ENVIRONMENT_FILE}; import { ${names.join(", ")} } by hand`
|
|
4257
|
+
);
|
|
4258
|
+
return;
|
|
4259
|
+
}
|
|
4260
|
+
const existing = new Set(
|
|
4261
|
+
importDeclaration.getNamedImports().map((named) => named.getName())
|
|
4262
|
+
);
|
|
4263
|
+
for (const name of names) {
|
|
4264
|
+
if (!existing.has(name)) {
|
|
4265
|
+
importDeclaration.addNamedImport(name);
|
|
4266
|
+
}
|
|
4267
|
+
}
|
|
4268
|
+
}
|
|
4269
|
+
function getCleanEnvObject(sourceFile) {
|
|
4270
|
+
const options = sourceFile.getDescendantsOfKind(import_ts_morph3.SyntaxKind.CallExpression).find((call) => call.getExpression().getText() === "cleanEnv")?.getArguments()[1];
|
|
4271
|
+
return options && import_ts_morph3.Node.isObjectLiteralExpression(options) ? options : void 0;
|
|
4272
|
+
}
|
|
4273
|
+
function upsertEnvVar(sourceFile, name, kind, defaultExpr, desc, update) {
|
|
4274
|
+
const object = getCleanEnvObject(sourceFile);
|
|
4275
|
+
if (!object) return;
|
|
4276
|
+
const existing = object.getProperty(name);
|
|
4277
|
+
if (existing && import_ts_morph3.Node.isPropertyAssignment(existing)) {
|
|
4278
|
+
if (!update) return;
|
|
4279
|
+
const options = existing.getInitializerIfKind(import_ts_morph3.SyntaxKind.CallExpression)?.getArguments()[0];
|
|
4280
|
+
if (options && import_ts_morph3.Node.isObjectLiteralExpression(options)) {
|
|
4281
|
+
const defaultProperty = options.getProperty("default");
|
|
4282
|
+
if (defaultProperty && import_ts_morph3.Node.isPropertyAssignment(defaultProperty)) {
|
|
4283
|
+
defaultProperty.setInitializer(defaultExpr);
|
|
4284
|
+
} else {
|
|
4285
|
+
options.insertPropertyAssignment(0, {
|
|
4286
|
+
name: "default",
|
|
4287
|
+
initializer: defaultExpr
|
|
4288
|
+
});
|
|
4289
|
+
}
|
|
4290
|
+
console.log(` \u2713 ${ENVIRONMENT_FILE}: ${name} default set`);
|
|
4291
|
+
}
|
|
4292
|
+
return;
|
|
4293
|
+
}
|
|
4294
|
+
if (appendProperty(sourceFile, object, name, [
|
|
4295
|
+
`${kind}({`,
|
|
4296
|
+
` default: ${defaultExpr},`,
|
|
4297
|
+
` desc: ${JSON.stringify(desc)}`,
|
|
4298
|
+
"})"
|
|
4299
|
+
])) {
|
|
4300
|
+
console.log(` \u2713 ${ENVIRONMENT_FILE}: ${name}`);
|
|
4301
|
+
}
|
|
4302
|
+
}
|
|
4303
|
+
function addEnvironmentVariables(project, cwd, config) {
|
|
4304
|
+
const sourceFile = project.addSourceFileAtPathIfExists(
|
|
4305
|
+
import_path4.default.join(cwd, ENVIRONMENT_FILE)
|
|
4306
|
+
);
|
|
4307
|
+
if (!sourceFile) {
|
|
4308
|
+
warnSkipped4(
|
|
4309
|
+
`${ENVIRONMENT_FILE} not found; add the telemetry env vars by hand`
|
|
4310
|
+
);
|
|
4311
|
+
return;
|
|
4312
|
+
}
|
|
4313
|
+
if (!getCleanEnvObject(sourceFile)) {
|
|
4314
|
+
warnSkipped4(
|
|
4315
|
+
`Could not find the cleanEnv(...) config object in ${ENVIRONMENT_FILE}; add the telemetry env vars by hand`
|
|
4316
|
+
);
|
|
4317
|
+
return;
|
|
4318
|
+
}
|
|
4319
|
+
ensureEnvalidNamedImports(sourceFile, ["bool", "str"]);
|
|
4320
|
+
upsertEnvVar(
|
|
4321
|
+
sourceFile,
|
|
4322
|
+
"TELEMETRY_ENABLED",
|
|
4323
|
+
"bool",
|
|
4324
|
+
config.enabled ? "true" : "false",
|
|
4325
|
+
"When true, usage telemetry received from the events service is forwarded to the OpenCRVS status service.",
|
|
4326
|
+
true
|
|
4327
|
+
);
|
|
4328
|
+
upsertEnvVar(
|
|
4329
|
+
sourceFile,
|
|
4330
|
+
"COUNTRY_CODE",
|
|
4331
|
+
"str",
|
|
4332
|
+
config.enabled ? JSON.stringify(config.countryCode) : `'FAR'`,
|
|
4333
|
+
"ISO-style country code of this instance, reported with telemetry.",
|
|
4334
|
+
config.enabled
|
|
4335
|
+
);
|
|
4336
|
+
upsertEnvVar(
|
|
4337
|
+
sourceFile,
|
|
4338
|
+
"ORGANISATION",
|
|
4339
|
+
"str",
|
|
4340
|
+
config.enabled ? JSON.stringify(config.organisation) : `''`,
|
|
4341
|
+
"Organisation running this instance, reported with telemetry. Empty by default.",
|
|
4342
|
+
config.enabled
|
|
4343
|
+
);
|
|
4344
|
+
upsertEnvVar(
|
|
4345
|
+
sourceFile,
|
|
4346
|
+
"ENVIRONMENT_NAME",
|
|
4347
|
+
"str",
|
|
4348
|
+
`'development'`,
|
|
4349
|
+
'Environment name (e.g. "production", "staging") reported as the telemetry environment.',
|
|
4350
|
+
false
|
|
4351
|
+
);
|
|
4352
|
+
}
|
|
4353
|
+
function wireIndex(project, cwd) {
|
|
4354
|
+
const sourceFile = project.addSourceFileAtPathIfExists(
|
|
4355
|
+
import_path4.default.join(cwd, INDEX_FILE)
|
|
4356
|
+
);
|
|
4357
|
+
if (!sourceFile) {
|
|
4358
|
+
warnSkipped4(
|
|
4359
|
+
`${INDEX_FILE} not found; register POST /trigger/telemetry and the startup notice by hand`
|
|
4360
|
+
);
|
|
4361
|
+
return;
|
|
4362
|
+
}
|
|
4363
|
+
if (!sourceFile.getImportDeclarations().some((d) => d.getModuleSpecifierValue() === HANDLER_MODULE)) {
|
|
4364
|
+
sourceFile.addImportDeclaration({
|
|
4365
|
+
moduleSpecifier: HANDLER_MODULE,
|
|
4366
|
+
namedImports: [
|
|
4367
|
+
"telemetryHandler",
|
|
4368
|
+
"telemetrySchema",
|
|
4369
|
+
"TELEMETRY_DISABLED_NOTICE"
|
|
4370
|
+
]
|
|
4371
|
+
});
|
|
4372
|
+
console.log(` \u2713 ${INDEX_FILE}: import ${HANDLER_MODULE}`);
|
|
4373
|
+
}
|
|
4374
|
+
if (!sourceFile.getText().includes("path: '/trigger/telemetry'")) {
|
|
4375
|
+
const lastRouteStatement = sourceFile.getDescendantsOfKind(import_ts_morph3.SyntaxKind.CallExpression).filter((call) => call.getExpression().getText() === "server.route").map(
|
|
4376
|
+
(call) => call.getFirstAncestorByKind(import_ts_morph3.SyntaxKind.ExpressionStatement)
|
|
4377
|
+
).filter(
|
|
4378
|
+
(statement) => Boolean(statement)
|
|
4379
|
+
).pop();
|
|
4380
|
+
if (!lastRouteStatement) {
|
|
4381
|
+
warnSkipped4(
|
|
4382
|
+
`Could not find a server.route(...) call in ${INDEX_FILE}; register POST /trigger/telemetry by hand`
|
|
4383
|
+
);
|
|
4384
|
+
} else {
|
|
4385
|
+
const indent = lastRouteStatement.getIndentationText();
|
|
4386
|
+
const route = [
|
|
4387
|
+
`server.route({`,
|
|
4388
|
+
` method: 'POST',`,
|
|
4389
|
+
` path: '/trigger/telemetry',`,
|
|
4390
|
+
` handler: telemetryHandler,`,
|
|
4391
|
+
` options: {`,
|
|
4392
|
+
` tags: ['api', 'triggers'],`,
|
|
4393
|
+
` validate: {`,
|
|
4394
|
+
` payload: telemetrySchema`,
|
|
4395
|
+
` },`,
|
|
4396
|
+
` description:`,
|
|
4397
|
+
` 'Receives a usage report from the events service and forwards it to the status service when telemetry is enabled'`,
|
|
4398
|
+
` }`,
|
|
4399
|
+
`})`
|
|
4400
|
+
].map((line2) => line2 ? `${indent}${line2}` : line2).join("\n");
|
|
4401
|
+
sourceFile.insertText(lastRouteStatement.getEnd(), `
|
|
4402
|
+
|
|
4403
|
+
${route}`);
|
|
4404
|
+
console.log(` \u2713 ${INDEX_FILE}: POST /trigger/telemetry`);
|
|
4405
|
+
}
|
|
4406
|
+
}
|
|
4407
|
+
if (!sourceFile.getText().includes("logger.info(TELEMETRY_DISABLED_NOTICE)")) {
|
|
4408
|
+
const startedLog = sourceFile.getDescendantsOfKind(import_ts_morph3.SyntaxKind.ExpressionStatement).find(
|
|
4409
|
+
(statement) => statement.getText().includes("Server successfully started")
|
|
4410
|
+
);
|
|
4411
|
+
if (!startedLog) {
|
|
4412
|
+
warnSkipped4(
|
|
4413
|
+
`Could not find the startup log in ${INDEX_FILE}; log TELEMETRY_DISABLED_NOTICE when TELEMETRY_ENABLED is false by hand`
|
|
4414
|
+
);
|
|
4415
|
+
} else {
|
|
4416
|
+
const indent = startedLog.getIndentationText();
|
|
4417
|
+
const notice = [
|
|
4418
|
+
`if (!env.TELEMETRY_ENABLED) {`,
|
|
4419
|
+
` logger.info(TELEMETRY_DISABLED_NOTICE)`,
|
|
4420
|
+
`}`
|
|
4421
|
+
].map((line2) => line2 ? `${indent}${line2}` : line2).join("\n");
|
|
4422
|
+
sourceFile.insertText(startedLog.getEnd(), `
|
|
4423
|
+
|
|
4424
|
+
${notice}`);
|
|
4425
|
+
console.log(` \u2713 ${INDEX_FILE}: telemetry-disabled startup notice`);
|
|
4426
|
+
if (!sourceFile.getImportDeclarations().some((d) => d.getModuleSpecifierValue() === "./environment")) {
|
|
4427
|
+
warnSkipped4(
|
|
4428
|
+
`The startup notice reads env.TELEMETRY_ENABLED but ${INDEX_FILE} does not import env from './environment'; import it by hand`
|
|
4429
|
+
);
|
|
4430
|
+
}
|
|
4431
|
+
}
|
|
4432
|
+
}
|
|
4433
|
+
}
|
|
4434
|
+
async function main4() {
|
|
4435
|
+
const cwd = process.cwd();
|
|
4436
|
+
const config = await promptTelemetryConfig();
|
|
4437
|
+
console.log(
|
|
4438
|
+
`
|
|
4439
|
+
Adding daily usage telemetry (${config.enabled ? `enabled for ${config.countryCode}` : "disabled"} by default)...
|
|
4440
|
+
`
|
|
4441
|
+
);
|
|
4442
|
+
writeTelemetryHandler(cwd);
|
|
4443
|
+
const project = new import_ts_morph3.Project({
|
|
4444
|
+
// ts-morph indents inserted code with four spaces and double-quotes strings
|
|
4445
|
+
// by default, both of which the country config's prettier run would undo.
|
|
4446
|
+
manipulationSettings: {
|
|
4447
|
+
indentationText: import_ts_morph3.IndentationText.TwoSpaces,
|
|
4448
|
+
quoteKind: import_ts_morph3.QuoteKind.Single
|
|
4449
|
+
}
|
|
4450
|
+
});
|
|
4451
|
+
addEnvironmentVariables(project, cwd, config);
|
|
4452
|
+
wireIndex(project, cwd);
|
|
4453
|
+
await project.save();
|
|
4454
|
+
return skipped4;
|
|
4455
|
+
}
|
|
4456
|
+
|
|
4457
|
+
// src/migrations/v2.1/index.ts
|
|
4458
|
+
var DOCKER_SWARM_MANUAL_STEPS = [
|
|
4459
|
+
"Remove the `mongo1` and `influxdb` services from your compose files \u2014 MongoDB and InfluxDB are gone in this release.",
|
|
4460
|
+
"Remove the `legacy-data-migration` service from your compose files. It only ever migrated MongoDB data during the v2.0 upgrade, and the migration it ran no longer exists.",
|
|
4461
|
+
"Change the postgres image from `docker.io/chumaky/postgres_mongo_fdw:17.6_fdw5.5.2` back to `postgres:17.6`. The `mongo_fdw` build was only needed for the v2.0 legacy-data migration.",
|
|
4462
|
+
"Run `DROP EXTENSION mongo_fdw CASCADE;` against the events database as a Postgres superuser, if this deployment came through v2.0. It has to be a superuser: the extension is owned by the one that ran the v2.0 legacy migration, not by the role the migrations run as. Until it is dropped, a pg_dump/pg_restore of the database into a v2.1 cluster fails.",
|
|
4463
|
+
"Run `assets/deployment/reindex.sh` after deploying. `deploy.sh` does not call it, and this release adds `legalStatuses.NOTIFIED` to the Elasticsearch mapping, so records indexed before the upgrade carry none of it until a reindex."
|
|
4464
|
+
];
|
|
4465
|
+
async function runUpgrade(dockerSwarm) {
|
|
4466
|
+
const outstanding = [];
|
|
4467
|
+
outstanding.push(...await main());
|
|
4468
|
+
outstanding.push(...await main2());
|
|
4469
|
+
outstanding.push(...await main3());
|
|
4470
|
+
outstanding.push(...await main4());
|
|
4471
|
+
if (dockerSwarm) {
|
|
4472
|
+
outstanding.push(...DOCKER_SWARM_MANUAL_STEPS);
|
|
4473
|
+
}
|
|
4474
|
+
return { outstanding };
|
|
4475
|
+
}
|
|
4476
|
+
|
|
4477
|
+
// src/translations/check.ts
|
|
4478
|
+
var import_ts_morph4 = require("ts-morph");
|
|
4479
|
+
var import_path5 = __toESM(require("path"));
|
|
4480
|
+
var TRANSLATIONS = "src/translations";
|
|
4481
|
+
var OWN_FILE = `${TRANSLATIONS}/countryconfig.csv`;
|
|
4482
|
+
var CORE_FILES = [`${TRANSLATIONS}/client.csv`, `${TRANSLATIONS}/login.csv`];
|
|
4483
|
+
function staticStringOf(node, name) {
|
|
4484
|
+
const property = node.getProperty(name);
|
|
4485
|
+
if (!property || !import_ts_morph4.Node.isPropertyAssignment(property)) {
|
|
4486
|
+
return void 0;
|
|
4487
|
+
}
|
|
4488
|
+
const initializer = property.getInitializer();
|
|
4489
|
+
return initializer && (import_ts_morph4.Node.isStringLiteral(initializer) || import_ts_morph4.Node.isNoSubstitutionTemplateLiteral(initializer)) ? initializer.getLiteralValue() : void 0;
|
|
4490
|
+
}
|
|
4491
|
+
function messagesDeclaredIn(cwd) {
|
|
4492
|
+
const project = new import_ts_morph4.Project({ skipAddingFilesFromTsConfig: true });
|
|
4493
|
+
project.addSourceFilesAtPaths([
|
|
4494
|
+
import_path5.default.join(cwd, "src/**/*.ts"),
|
|
4495
|
+
import_path5.default.join(cwd, "src/**/*.tsx"),
|
|
4496
|
+
`!${import_path5.default.join(cwd, "src/**/*.test.ts")}`,
|
|
4497
|
+
`!${import_path5.default.join(cwd, "src/**/*.test.tsx")}`,
|
|
4498
|
+
`!${import_path5.default.join(cwd, "src/**/*.stories.ts")}`,
|
|
4499
|
+
`!${import_path5.default.join(cwd, "src/**/*.stories.tsx")}`
|
|
4500
|
+
]);
|
|
4501
|
+
const messages = [];
|
|
4502
|
+
const dynamicIds = [];
|
|
4503
|
+
for (const sourceFile of project.getSourceFiles()) {
|
|
4504
|
+
sourceFile.forEachDescendant((node) => {
|
|
4505
|
+
if (!import_ts_morph4.Node.isObjectLiteralExpression(node)) {
|
|
4506
|
+
return;
|
|
4507
|
+
}
|
|
4508
|
+
if (!(node.getProperty("id") && node.getProperty("defaultMessage"))) {
|
|
4509
|
+
return;
|
|
4510
|
+
}
|
|
4511
|
+
const id = staticStringOf(node, "id");
|
|
4512
|
+
if (id === void 0) {
|
|
4513
|
+
dynamicIds.push(import_path5.default.relative(cwd, sourceFile.getFilePath()));
|
|
4514
|
+
return;
|
|
4515
|
+
}
|
|
4516
|
+
messages.push({
|
|
4517
|
+
id,
|
|
4518
|
+
defaultMessage: staticStringOf(node, "defaultMessage") ?? "",
|
|
4519
|
+
description: staticStringOf(node, "description") ?? ""
|
|
4520
|
+
});
|
|
4521
|
+
});
|
|
4522
|
+
}
|
|
4523
|
+
return { messages, dynamicIds: [...new Set(dynamicIds)] };
|
|
4524
|
+
}
|
|
4525
|
+
function check(cwd) {
|
|
4526
|
+
const { messages, dynamicIds } = messagesDeclaredIn(cwd);
|
|
4527
|
+
const own = readCsvFile(import_path5.default.join(cwd, OWN_FILE));
|
|
4528
|
+
const covered = new Set(
|
|
4529
|
+
[own, ...CORE_FILES.map((file) => readCsvFile(import_path5.default.join(cwd, file)))].flatMap((csv) => csv?.body ?? []).map(idOf)
|
|
4530
|
+
);
|
|
4531
|
+
const missing = [
|
|
4532
|
+
...new Map(
|
|
4533
|
+
messages.filter(({ id }) => !covered.has(id)).map((message) => [message.id, message])
|
|
4534
|
+
).values()
|
|
4535
|
+
].sort((a, b) => a.id < b.id ? -1 : 1);
|
|
4536
|
+
const declared = new Set(messages.map(({ id }) => id));
|
|
4537
|
+
const outdated = (own?.body ?? []).map(idOf).filter((id) => !declared.has(id));
|
|
4538
|
+
return { missing, outdated, dynamicIds };
|
|
4539
|
+
}
|
|
4540
|
+
function writeMissing(cwd, missing) {
|
|
4541
|
+
const file = readCsvFile(import_path5.default.join(cwd, OWN_FILE)) ?? {
|
|
4542
|
+
header: "id,description,en",
|
|
4543
|
+
body: [],
|
|
4544
|
+
newline: "\n",
|
|
4545
|
+
trailingNewline: true
|
|
4546
|
+
};
|
|
4547
|
+
const columns = file.header.split(",");
|
|
4548
|
+
const rows = missing.map(
|
|
4549
|
+
(message) => toCsvLine(
|
|
4550
|
+
columns.map((column) => {
|
|
4551
|
+
if (column === "id") return message.id;
|
|
4552
|
+
if (column === "description") return message.description;
|
|
4553
|
+
return column === "en" ? message.defaultMessage : "";
|
|
4554
|
+
})
|
|
4555
|
+
)
|
|
4556
|
+
);
|
|
4557
|
+
const added = addRows(file, rows);
|
|
4558
|
+
writeCsvFile(import_path5.default.join(cwd, OWN_FILE), file);
|
|
4559
|
+
return added;
|
|
4560
|
+
}
|
|
4561
|
+
|
|
4562
|
+
// src/environment/index.ts
|
|
4563
|
+
var import_fs9 = require("fs");
|
|
4564
|
+
var import_path10 = require("path");
|
|
4565
|
+
init_paths();
|
|
4566
|
+
var REQUIRED_REPOSITORY_DIRECTORIES = [
|
|
4567
|
+
".github/workflows",
|
|
4568
|
+
"environments",
|
|
4569
|
+
"infrastructure"
|
|
4570
|
+
];
|
|
4571
|
+
function validateRepositoryStructure(repositoryRoot = process.cwd()) {
|
|
4572
|
+
const missingDirectories = REQUIRED_REPOSITORY_DIRECTORIES.filter(
|
|
4573
|
+
(directory) => {
|
|
4574
|
+
try {
|
|
4575
|
+
return !(0, import_fs9.statSync)((0, import_path10.resolve)(repositoryRoot, directory)).isDirectory();
|
|
4576
|
+
} catch {
|
|
4577
|
+
return true;
|
|
4578
|
+
}
|
|
4579
|
+
}
|
|
4580
|
+
);
|
|
4581
|
+
if (missingDirectories.length > 0) {
|
|
4582
|
+
throw new Error(
|
|
4583
|
+
`The current directory is not a valid OpenCRVS country configuration repository. Missing required director${missingDirectories.length === 1 ? "y" : "ies"}: ${missingDirectories.join(", ")}`
|
|
4584
|
+
);
|
|
4585
|
+
}
|
|
4586
|
+
}
|
|
4587
|
+
async function runEnvironmentInit() {
|
|
4588
|
+
validateRepositoryStructure();
|
|
4589
|
+
assertNoOldInventoryLayout();
|
|
4590
|
+
await Promise.resolve().then(() => (init_setup_environment(), setup_environment_exports));
|
|
4591
|
+
}
|
|
4592
|
+
async function runEnvironmentUpgrade() {
|
|
4593
|
+
validateRepositoryStructure();
|
|
4594
|
+
const { upgradeEnvironmentLayout: upgradeEnvironmentLayout2 } = await Promise.resolve().then(() => (init_upgrade(), upgrade_exports));
|
|
4595
|
+
await upgradeEnvironmentLayout2();
|
|
4596
|
+
}
|
|
4597
|
+
async function runEnvironmentUpdateWorkflows() {
|
|
4598
|
+
validateRepositoryStructure();
|
|
4599
|
+
const { updateWorkflowEnvironments: updateWorkflowEnvironments2 } = await Promise.resolve().then(() => (init_update_workflows(), update_workflows_exports));
|
|
4600
|
+
await updateWorkflowEnvironments2();
|
|
4601
|
+
}
|
|
4602
|
+
async function runEnvironmentUsers() {
|
|
4603
|
+
validateRepositoryStructure();
|
|
4604
|
+
const { manageEnvironmentUsers: manageEnvironmentUsers2 } = await Promise.resolve().then(() => (init_users(), users_exports));
|
|
4605
|
+
await manageEnvironmentUsers2();
|
|
4606
|
+
}
|
|
4607
|
+
async function runEnvironmentSwarmToK8s() {
|
|
4608
|
+
validateRepositoryStructure();
|
|
4609
|
+
await Promise.resolve().then(() => (init_swarm_to_k8s(), swarm_to_k8s_exports));
|
|
4610
|
+
}
|
|
4611
|
+
|
|
4612
|
+
// src/verify/endpoints.ts
|
|
4613
|
+
var import_colors = require("kleur/colors");
|
|
4614
|
+
var REQUEST_TIMEOUT_MS = 15e3;
|
|
4615
|
+
var DEFAULT_TARGET_URL = "http://localhost:3040";
|
|
4616
|
+
var REQUIRED_PUBLIC_ENDPOINTS = [
|
|
4617
|
+
{ method: "GET", path: "/client-config.js" },
|
|
4618
|
+
{ method: "GET", path: "/login-config.js" },
|
|
4619
|
+
{ method: "GET", path: "/handlebars.js" },
|
|
4620
|
+
{ method: "GET", path: "/content/client" },
|
|
4621
|
+
{ method: "GET", path: "/content/login" },
|
|
4622
|
+
{ method: "GET", path: "/content/map.geojson" },
|
|
4623
|
+
{ method: "GET", path: "/content/country-logo" },
|
|
4624
|
+
{ method: "GET", path: "/config/application" },
|
|
4625
|
+
{ method: "GET", path: "/config/workqueues" },
|
|
4626
|
+
{ method: "GET", path: "/config/locations" },
|
|
4627
|
+
{ method: "GET", path: "/config/roles" },
|
|
4628
|
+
{ method: "GET", path: "/config/events" }
|
|
4629
|
+
];
|
|
4630
|
+
var PROBE_SEGMENT = "verify-endpoints-probe";
|
|
4631
|
+
var SECURED_TRIGGER_USER_EVENTS = [
|
|
4632
|
+
"user-created",
|
|
4633
|
+
"user-updated",
|
|
4634
|
+
"username-reminder",
|
|
4635
|
+
"reset-password",
|
|
4636
|
+
"reset-password-by-admin",
|
|
4637
|
+
"password-reset-link",
|
|
4638
|
+
"username-reminder-link",
|
|
4639
|
+
"resend-invite",
|
|
4640
|
+
"2fa",
|
|
4641
|
+
"all-user-notification",
|
|
4642
|
+
"change-phone-number",
|
|
4643
|
+
"change-email-address"
|
|
4644
|
+
];
|
|
4645
|
+
var SECURED_ENDPOINTS = [
|
|
4646
|
+
...SECURED_TRIGGER_USER_EVENTS.map(
|
|
4647
|
+
(event) => ({
|
|
4648
|
+
method: "POST",
|
|
4649
|
+
path: `/triggers/user/${event}`
|
|
4650
|
+
})
|
|
4651
|
+
),
|
|
4652
|
+
{ method: "POST", path: "/trigger/telemetry" },
|
|
4653
|
+
{ method: "GET", path: "/triggers/system/ready" },
|
|
4654
|
+
{
|
|
4655
|
+
method: "GET",
|
|
4656
|
+
path: `/certificates/${PROBE_SEGMENT}`,
|
|
4657
|
+
label: "/certificates/{id}"
|
|
4658
|
+
},
|
|
4659
|
+
{ method: "GET", path: "/certificates" },
|
|
4660
|
+
{ method: "GET", path: "/config/users" }
|
|
4661
|
+
];
|
|
4662
|
+
var FALLBACK_EVENT_TRIGGERS = [
|
|
4663
|
+
{
|
|
4664
|
+
method: "POST",
|
|
4665
|
+
path: `/trigger/events/${PROBE_SEGMENT}/actions/${PROBE_SEGMENT}`,
|
|
4666
|
+
label: "/trigger/events/{event}/actions/{action}"
|
|
4667
|
+
},
|
|
4668
|
+
{
|
|
4669
|
+
method: "POST",
|
|
4670
|
+
path: `/trigger/events/birth/actions/${PROBE_SEGMENT}`,
|
|
4671
|
+
label: "/trigger/events/birth/actions/{action}"
|
|
4672
|
+
},
|
|
4673
|
+
{
|
|
4674
|
+
method: "POST",
|
|
4675
|
+
path: `/trigger/events/death/actions/${PROBE_SEGMENT}`,
|
|
4676
|
+
label: "/trigger/events/death/actions/{action}"
|
|
4677
|
+
}
|
|
4678
|
+
];
|
|
4679
|
+
var isSuccess = (status) => status !== "error" && status >= 200 && status < 300;
|
|
4680
|
+
var requiresAuthOrAbsent = (status) => status === 401 || status === 403 || status === 404;
|
|
4681
|
+
async function requestStatus(url, method) {
|
|
4682
|
+
const controller = new AbortController();
|
|
4683
|
+
const timer = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
|
|
4684
|
+
try {
|
|
4685
|
+
const response = await fetch(url, {
|
|
4686
|
+
method,
|
|
4687
|
+
signal: controller.signal,
|
|
4688
|
+
// Sent without an Authorization header on purpose. A secured route
|
|
4689
|
+
// rejects with 401/403 before ever reading the body.
|
|
4690
|
+
headers: method === "POST" ? { "Content-Type": "application/json" } : void 0,
|
|
4691
|
+
body: method === "POST" ? "{}" : void 0
|
|
4692
|
+
});
|
|
4693
|
+
return response.status;
|
|
4694
|
+
} catch {
|
|
4695
|
+
return "error";
|
|
4696
|
+
} finally {
|
|
4697
|
+
clearTimeout(timer);
|
|
4698
|
+
}
|
|
4699
|
+
}
|
|
4700
|
+
function toEventTriggerConfig(value) {
|
|
4701
|
+
if (typeof value !== "object" || value === null) {
|
|
4702
|
+
return null;
|
|
4703
|
+
}
|
|
4704
|
+
const record = value;
|
|
4705
|
+
if (typeof record.id !== "string") {
|
|
4706
|
+
return null;
|
|
4707
|
+
}
|
|
4708
|
+
const actions = Array.isArray(record.actions) ? Array.from(
|
|
4709
|
+
new Set(
|
|
4710
|
+
record.actions.map((action) => {
|
|
4711
|
+
if (typeof action !== "object" || action === null) {
|
|
4712
|
+
return null;
|
|
4713
|
+
}
|
|
4714
|
+
const type = action.type;
|
|
4715
|
+
return typeof type === "string" ? type : null;
|
|
4716
|
+
}).filter((type) => type !== null)
|
|
4717
|
+
)
|
|
4718
|
+
) : [];
|
|
4719
|
+
return { id: record.id, actions };
|
|
4720
|
+
}
|
|
4721
|
+
async function fetchEventConfigs(baseUrl) {
|
|
4722
|
+
const controller = new AbortController();
|
|
4723
|
+
const timer = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
|
|
4724
|
+
try {
|
|
4725
|
+
const response = await fetch(`${baseUrl}/config/events`, {
|
|
4726
|
+
signal: controller.signal
|
|
4727
|
+
});
|
|
4728
|
+
if (!response.ok) {
|
|
4729
|
+
return null;
|
|
4730
|
+
}
|
|
4731
|
+
const body = await response.json();
|
|
4732
|
+
if (!Array.isArray(body)) {
|
|
4733
|
+
return null;
|
|
4734
|
+
}
|
|
4735
|
+
return body.map(toEventTriggerConfig).filter((config) => config !== null);
|
|
4736
|
+
} catch {
|
|
4737
|
+
return null;
|
|
4738
|
+
} finally {
|
|
4739
|
+
clearTimeout(timer);
|
|
4740
|
+
}
|
|
4741
|
+
}
|
|
4742
|
+
function resolveBaseUrl(input4) {
|
|
4743
|
+
const withProtocol = /^https?:\/\//i.test(input4) ? input4 : `https://${input4}`;
|
|
4744
|
+
return withProtocol.replace(/\/+$/, "");
|
|
4745
|
+
}
|
|
4746
|
+
function describeStatus(status) {
|
|
4747
|
+
return status === "error" ? "no response" : `HTTP ${status}`;
|
|
4748
|
+
}
|
|
4749
|
+
function endpointLabel(check2) {
|
|
4750
|
+
const shown = check2.label ?? check2.path;
|
|
4751
|
+
const suffix = check2.label ? (0, import_colors.dim)(` \u2192 ${check2.path}`) : "";
|
|
4752
|
+
return `${check2.method} ${shown}${suffix}`;
|
|
4753
|
+
}
|
|
4754
|
+
function line(ok, label, detail) {
|
|
4755
|
+
const mark = ok ? (0, import_colors.green)("\u2713") : (0, import_colors.red)("\u2717");
|
|
4756
|
+
return ` ${mark} ${label} ${(0, import_colors.dim)(`(${detail})`)}`;
|
|
4757
|
+
}
|
|
4758
|
+
function securedDetail(status) {
|
|
4759
|
+
if (status === 401 || status === 403) {
|
|
4760
|
+
return `${describeStatus(status)} \u2014 auth required`;
|
|
4761
|
+
}
|
|
4762
|
+
if (status === 404) {
|
|
4763
|
+
return `${describeStatus(status)} \u2014 not implemented`;
|
|
4764
|
+
}
|
|
4765
|
+
if (status === "error") {
|
|
4766
|
+
return `${describeStatus(status)} \u2014 request failed`;
|
|
4767
|
+
}
|
|
4768
|
+
return `${describeStatus(status)} \u2014 INSECURE: ensure this endpoint requires authentication!`;
|
|
4769
|
+
}
|
|
4770
|
+
async function runVerifyEndpoints(target = DEFAULT_TARGET_URL) {
|
|
4771
|
+
const baseUrl = resolveBaseUrl(target);
|
|
4772
|
+
console.log((0, import_colors.bold)(`Verifying country config endpoints at ${baseUrl}
|
|
4773
|
+
`));
|
|
4774
|
+
let failures = 0;
|
|
4775
|
+
console.log((0, import_colors.bold)("Required public endpoints (must respond 2xx):"));
|
|
4776
|
+
for (const check2 of REQUIRED_PUBLIC_ENDPOINTS) {
|
|
4777
|
+
const status = await requestStatus(`${baseUrl}${check2.path}`, check2.method);
|
|
4778
|
+
const ok = isSuccess(status);
|
|
4779
|
+
if (!ok) {
|
|
4780
|
+
failures++;
|
|
4781
|
+
}
|
|
4782
|
+
const detail = status === 404 ? `${describeStatus(status)} \u2014 missing` : ok ? describeStatus(status) : `${describeStatus(status)} \u2014 unexpected`;
|
|
4783
|
+
console.log(line(ok, endpointLabel(check2), detail));
|
|
4784
|
+
}
|
|
4785
|
+
{
|
|
4786
|
+
const path10 = `/fonts/${PROBE_SEGMENT}.ttf`;
|
|
4787
|
+
const status = await requestStatus(`${baseUrl}${path10}`, "GET");
|
|
4788
|
+
const ok = status === 200 || status === 404;
|
|
4789
|
+
if (!ok) {
|
|
4790
|
+
failures++;
|
|
4791
|
+
}
|
|
4792
|
+
let detail;
|
|
4793
|
+
if (status === 404) {
|
|
4794
|
+
detail = `${describeStatus(status)} \u2014 reachable (made-up filename)`;
|
|
4795
|
+
} else if (status === 200) {
|
|
4796
|
+
detail = describeStatus(status);
|
|
4797
|
+
} else if (status === 401 || status === 403) {
|
|
4798
|
+
detail = `${describeStatus(status)} \u2014 must be public`;
|
|
4799
|
+
} else {
|
|
4800
|
+
detail = `${describeStatus(status)} \u2014 unexpected`;
|
|
4801
|
+
}
|
|
4802
|
+
console.log(line(ok, `GET /fonts/{filename}${(0, import_colors.dim)(` \u2192 ${path10}`)}`, detail));
|
|
4803
|
+
}
|
|
4804
|
+
console.log();
|
|
4805
|
+
console.log((0, import_colors.bold)("Secured endpoints (must be absent or require auth):"));
|
|
4806
|
+
for (const check2 of SECURED_ENDPOINTS) {
|
|
4807
|
+
const status = await requestStatus(`${baseUrl}${check2.path}`, check2.method);
|
|
4808
|
+
const ok = requiresAuthOrAbsent(status);
|
|
4809
|
+
if (!ok) {
|
|
4810
|
+
failures++;
|
|
4811
|
+
}
|
|
4812
|
+
console.log(line(ok, endpointLabel(check2), securedDetail(status)));
|
|
4813
|
+
}
|
|
4814
|
+
console.log();
|
|
4815
|
+
console.log((0, import_colors.bold)("Event action triggers (must be absent or require auth):"));
|
|
4816
|
+
const events = await fetchEventConfigs(baseUrl);
|
|
4817
|
+
if (!events) {
|
|
4818
|
+
console.log(
|
|
4819
|
+
" " + (0, import_colors.yellow)(
|
|
4820
|
+
"Could not read /config/events; falling back to route-pattern checks."
|
|
4821
|
+
)
|
|
4822
|
+
);
|
|
4823
|
+
for (const check2 of FALLBACK_EVENT_TRIGGERS) {
|
|
4824
|
+
const status = await requestStatus(
|
|
4825
|
+
`${baseUrl}${check2.path}`,
|
|
4826
|
+
check2.method
|
|
4827
|
+
);
|
|
4828
|
+
const ok = requiresAuthOrAbsent(status);
|
|
4829
|
+
if (!ok) {
|
|
4830
|
+
failures++;
|
|
4831
|
+
}
|
|
4832
|
+
console.log(line(ok, endpointLabel(check2), securedDetail(status)));
|
|
4833
|
+
}
|
|
4834
|
+
} else if (events.length === 0) {
|
|
4835
|
+
console.log(" " + (0, import_colors.yellow)("No events configured."));
|
|
4836
|
+
} else {
|
|
4837
|
+
for (const event of events) {
|
|
4838
|
+
const actions = event.actions.length ? event.actions : [PROBE_SEGMENT];
|
|
4839
|
+
const failed = [];
|
|
4840
|
+
for (const action of actions) {
|
|
4841
|
+
const status = await requestStatus(
|
|
4842
|
+
`${baseUrl}/trigger/events/${event.id}/actions/${action}`,
|
|
4843
|
+
"POST"
|
|
4844
|
+
);
|
|
4845
|
+
if (!requiresAuthOrAbsent(status)) {
|
|
4846
|
+
failed.push({ action, status });
|
|
4847
|
+
}
|
|
4848
|
+
}
|
|
4849
|
+
const pattern = `POST /trigger/events/${event.id}/actions/{action}`;
|
|
4850
|
+
if (failed.length === 0) {
|
|
4851
|
+
console.log(
|
|
4852
|
+
line(true, pattern, `${actions.length} action(s) \u2014 all require auth`)
|
|
4853
|
+
);
|
|
4854
|
+
} else {
|
|
4855
|
+
for (const failure of failed) {
|
|
4856
|
+
failures++;
|
|
4857
|
+
console.log(
|
|
4858
|
+
line(
|
|
4859
|
+
false,
|
|
4860
|
+
`POST /trigger/events/${event.id}/actions/${failure.action}`,
|
|
4861
|
+
securedDetail(failure.status)
|
|
4862
|
+
)
|
|
4863
|
+
);
|
|
4864
|
+
}
|
|
4865
|
+
const okCount = actions.length - failed.length;
|
|
4866
|
+
if (okCount > 0) {
|
|
4867
|
+
console.log(
|
|
4868
|
+
line(true, pattern, `${okCount} other action(s) require auth`)
|
|
4869
|
+
);
|
|
4870
|
+
}
|
|
4871
|
+
}
|
|
4872
|
+
}
|
|
4873
|
+
}
|
|
4874
|
+
console.log();
|
|
4875
|
+
if (failures > 0) {
|
|
4876
|
+
console.log(
|
|
4877
|
+
(0, import_colors.red)((0, import_colors.bold)(`\u2717 ${failures} check(s) failed.`)) + (0, import_colors.yellow)(" See the lines marked \u2717 above.")
|
|
4878
|
+
);
|
|
4879
|
+
return failures;
|
|
4880
|
+
}
|
|
4881
|
+
console.log((0, import_colors.green)((0, import_colors.bold)("\u2713 All endpoint checks passed.")));
|
|
4882
|
+
return 0;
|
|
4883
|
+
}
|
|
4884
|
+
|
|
4885
|
+
// src/verify/upgrade.ts
|
|
4886
|
+
var import_colors3 = require("kleur/colors");
|
|
4887
|
+
|
|
4888
|
+
// src/verify/scopes.ts
|
|
4889
|
+
var import_colors2 = require("kleur/colors");
|
|
4890
|
+
var REQUEST_TIMEOUT_MS2 = 15e3;
|
|
4891
|
+
var SCOPES_ADDED_THIS_RELEASE = [
|
|
4892
|
+
{
|
|
4893
|
+
scope: "record.unarchive",
|
|
4894
|
+
guards: "the new UNARCHIVE action. Without it no role can restore an archived record, including roles that hold record.archive."
|
|
4895
|
+
},
|
|
4896
|
+
{
|
|
4897
|
+
scope: "location.edit",
|
|
4898
|
+
guards: "the location and administrative area write API (create, update, withdrawVersion)."
|
|
4899
|
+
},
|
|
4900
|
+
{
|
|
4901
|
+
scope: "integration.audit.read",
|
|
4902
|
+
guards: "reading a system client's audit log via the integrations.audit endpoint."
|
|
4903
|
+
}
|
|
4904
|
+
];
|
|
4905
|
+
function scopeType(encoded) {
|
|
4906
|
+
for (const pair of encoded.split("&")) {
|
|
4907
|
+
const [key, value] = pair.split("=");
|
|
4908
|
+
if (key === "type") {
|
|
4909
|
+
return value;
|
|
4910
|
+
}
|
|
4911
|
+
}
|
|
4912
|
+
return void 0;
|
|
4913
|
+
}
|
|
4914
|
+
async function fetchRoles(baseUrl) {
|
|
4915
|
+
try {
|
|
4916
|
+
const response = await fetch(`${baseUrl}/config/roles`, {
|
|
4917
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS2)
|
|
4918
|
+
});
|
|
4919
|
+
if (!response.ok) {
|
|
4920
|
+
return void 0;
|
|
4921
|
+
}
|
|
4922
|
+
const body = await response.json();
|
|
4923
|
+
if (!Array.isArray(body)) {
|
|
4924
|
+
return void 0;
|
|
4925
|
+
}
|
|
4926
|
+
return body.filter(
|
|
4927
|
+
(role) => typeof role === "object" && role !== null && Array.isArray(role.scopes)
|
|
4928
|
+
);
|
|
4929
|
+
} catch {
|
|
4930
|
+
return void 0;
|
|
4931
|
+
}
|
|
4932
|
+
}
|
|
4933
|
+
async function runVerifyScopes(target = DEFAULT_TARGET_URL) {
|
|
4934
|
+
const baseUrl = resolveBaseUrl(target);
|
|
4935
|
+
console.log((0, import_colors2.bold)(`Scopes added in this release, at ${baseUrl}
|
|
4936
|
+
`));
|
|
4937
|
+
const roles = await fetchRoles(baseUrl);
|
|
4938
|
+
if (!roles) {
|
|
4939
|
+
console.log(
|
|
4940
|
+
" " + (0, import_colors2.yellow)(
|
|
4941
|
+
"Could not read /config/roles, so the new scopes could not be checked."
|
|
4942
|
+
)
|
|
4943
|
+
);
|
|
4944
|
+
return 1;
|
|
4945
|
+
}
|
|
4946
|
+
let failures = 0;
|
|
4947
|
+
for (const { scope, guards } of SCOPES_ADDED_THIS_RELEASE) {
|
|
4948
|
+
const holders = roles.filter(
|
|
4949
|
+
(role) => role.scopes.some((encoded) => scopeType(encoded) === scope)
|
|
4950
|
+
);
|
|
4951
|
+
if (holders.length === 0) {
|
|
4952
|
+
failures++;
|
|
4953
|
+
console.log(line(false, scope, `held by no role \u2014 guards ${guards}`));
|
|
4954
|
+
continue;
|
|
4955
|
+
}
|
|
4956
|
+
const named = holders.map((role) => role.id).slice(0, 3).join(", ");
|
|
4957
|
+
const more = holders.length > 3 ? `, +${holders.length - 3} more` : "";
|
|
4958
|
+
console.log(
|
|
4959
|
+
line(true, scope, `${holders.length} role(s)${(0, import_colors2.dim)(`: ${named}${more}`)}`)
|
|
4960
|
+
);
|
|
4961
|
+
}
|
|
4962
|
+
console.log();
|
|
4963
|
+
if (failures === 0) {
|
|
4964
|
+
console.log((0, import_colors2.green)((0, import_colors2.bold)("\u2713 Every scope added this release is assigned.")));
|
|
4965
|
+
}
|
|
4966
|
+
return failures;
|
|
4967
|
+
}
|
|
4968
|
+
|
|
4969
|
+
// src/verify/upgrade.ts
|
|
4970
|
+
function verifyTranslations(cwd) {
|
|
4971
|
+
console.log((0, import_colors3.bold)("Translations\n"));
|
|
4972
|
+
const { missing, dynamicIds } = check(cwd);
|
|
4973
|
+
for (const file of dynamicIds) {
|
|
4974
|
+
console.log(
|
|
4975
|
+
" " + (0, import_colors3.yellow)(
|
|
4976
|
+
`${file} declares a message whose id is built at runtime; ids have to be hardcoded to be checked.`
|
|
4977
|
+
)
|
|
4978
|
+
);
|
|
4979
|
+
}
|
|
4980
|
+
if (missing.length === 0) {
|
|
4981
|
+
console.log(
|
|
4982
|
+
" " + (0, import_colors3.green)("\u2713") + " Every message declared in src has a translation row."
|
|
4983
|
+
);
|
|
4984
|
+
} else {
|
|
4985
|
+
console.log(
|
|
4986
|
+
" " + (0, import_colors3.red)("\u2717") + ` ${missing.length} message(s) declared in src have no row in src/translations/countryconfig.csv.`
|
|
4987
|
+
);
|
|
4988
|
+
for (const { id } of missing.slice(0, 10)) {
|
|
4989
|
+
console.log(` ${id}`);
|
|
4990
|
+
}
|
|
4991
|
+
if (missing.length > 10) {
|
|
4992
|
+
console.log(` +${missing.length - 10} more`);
|
|
4993
|
+
}
|
|
4994
|
+
}
|
|
4995
|
+
console.log();
|
|
4996
|
+
return {
|
|
4997
|
+
name: "Translations",
|
|
4998
|
+
failures: missing.length === 0 ? 0 : 1,
|
|
4999
|
+
remedy: "Run `opencrvs check-translations --write` to add the missing rows."
|
|
5000
|
+
};
|
|
5001
|
+
}
|
|
5002
|
+
async function runVerifyUpgrade(target = DEFAULT_TARGET_URL, cwd = process.cwd()) {
|
|
5003
|
+
const sections = [];
|
|
5004
|
+
sections.push(verifyTranslations(cwd));
|
|
5005
|
+
sections.push({
|
|
5006
|
+
name: "Scopes added this release",
|
|
5007
|
+
failures: await runVerifyScopes(target),
|
|
5008
|
+
remedy: "Assign each unheld scope to the role(s) that should have it in src/data-seeding/roles/roles.ts."
|
|
5009
|
+
});
|
|
5010
|
+
console.log();
|
|
5011
|
+
sections.push({
|
|
5012
|
+
name: "Endpoints",
|
|
5013
|
+
failures: await runVerifyEndpoints(target),
|
|
5014
|
+
remedy: "See the lines marked \u2717 above. A missing public endpoint or a secured one that answers without a token both need fixing before deploying."
|
|
5015
|
+
});
|
|
5016
|
+
const total = sections.reduce((sum, section) => sum + section.failures, 0);
|
|
5017
|
+
console.log();
|
|
5018
|
+
console.log((0, import_colors3.bold)("Upgrade verification summary"));
|
|
5019
|
+
console.log();
|
|
5020
|
+
for (const section of sections) {
|
|
5021
|
+
const mark = section.failures === 0 ? (0, import_colors3.green)("\u2713") : (0, import_colors3.red)("\u2717");
|
|
5022
|
+
const detail = section.failures === 0 ? "passed" : `${section.failures} problem(s)`;
|
|
5023
|
+
console.log(` ${mark} ${section.name}: ${detail}`);
|
|
5024
|
+
}
|
|
5025
|
+
console.log();
|
|
5026
|
+
if (total === 0) {
|
|
5027
|
+
console.log((0, import_colors3.green)((0, import_colors3.bold)("\u2713 This country config looks ready to deploy.")));
|
|
5028
|
+
return 0;
|
|
5029
|
+
}
|
|
5030
|
+
console.log((0, import_colors3.red)((0, import_colors3.bold)(`\u2717 ${total} problem(s) to fix before deploying:`)));
|
|
5031
|
+
console.log();
|
|
5032
|
+
for (const section of sections.filter((s) => s.failures > 0)) {
|
|
5033
|
+
console.log(` ${(0, import_colors3.bold)(section.name)}: ${section.remedy}`);
|
|
5034
|
+
}
|
|
5035
|
+
return total;
|
|
5036
|
+
}
|
|
5037
|
+
|
|
5038
|
+
// src/cli.ts
|
|
5039
|
+
var args = process.argv.slice(2);
|
|
5040
|
+
var USAGE = `
|
|
5041
|
+
Usage: opencrvs <command>
|
|
5042
|
+
|
|
5043
|
+
Commands:
|
|
5044
|
+
environment Manage deployment environments
|
|
5045
|
+
upgrade Upgrade an existing environment
|
|
5046
|
+
check-translations Check translation files for completeness
|
|
5047
|
+
verify-upgrade Run every post-upgrade check and report them together
|
|
5048
|
+
verify-endpoints Verify the locally-running country config exposes the
|
|
5049
|
+
expected endpoints and keeps secured ones locked down
|
|
5050
|
+
|
|
5051
|
+
Run 'opencrvs <command> --help' for more information on a command.
|
|
5052
|
+
`.trim();
|
|
5053
|
+
var VERIFY_UPGRADE_USAGE = `
|
|
5054
|
+
Usage: opencrvs verify-upgrade [country-config-url]
|
|
5055
|
+
|
|
5056
|
+
Run this after 'opencrvs upgrade', from the country config directory, with the
|
|
5057
|
+
upgraded country config running. It runs every post-upgrade check there is and
|
|
5058
|
+
reports them together:
|
|
5059
|
+
- every message declared in src has a translation row,
|
|
5060
|
+
- every scope this release added is assigned to at least one role, and
|
|
5061
|
+
- the endpoint checks of 'verify-endpoints'.
|
|
5062
|
+
|
|
5063
|
+
Arguments:
|
|
5064
|
+
[country-config-url] Optional. Domain or URL of the country config
|
|
5065
|
+
service. Defaults to 'http://localhost:3040'. A bare
|
|
5066
|
+
domain is assumed to use https.
|
|
5067
|
+
|
|
5068
|
+
Options:
|
|
5069
|
+
-h, --help Show this message.
|
|
5070
|
+
|
|
5071
|
+
Exits with a non-zero status if any check fails.
|
|
5072
|
+
`.trim();
|
|
5073
|
+
var VERIFY_ENDPOINTS_USAGE = `
|
|
5074
|
+
Usage: opencrvs verify-endpoints [country-config-url]
|
|
5075
|
+
|
|
5076
|
+
Run this after 'opencrvs upgrade', with the upgraded country config running
|
|
5077
|
+
locally, to confirm it still behaves correctly. It checks over HTTP that:
|
|
5078
|
+
- required public endpoints exist (respond 2xx), and
|
|
5079
|
+
- user-notification trigger endpoints are either absent or reject
|
|
5080
|
+
unauthenticated requests (never processed without a token).
|
|
5081
|
+
|
|
5082
|
+
Arguments:
|
|
5083
|
+
[country-config-url] Optional. Domain or URL of the country config
|
|
5084
|
+
service. Defaults to 'http://localhost:3040', the
|
|
5085
|
+
port country config listens on locally. A bare
|
|
5086
|
+
domain is assumed to use https.
|
|
5087
|
+
|
|
5088
|
+
Options:
|
|
5089
|
+
-h, --help Show this message.
|
|
5090
|
+
|
|
5091
|
+
Exits with a non-zero status if any check fails.
|
|
5092
|
+
`.trim();
|
|
5093
|
+
var UPGRADE_USAGE = `
|
|
5094
|
+
Usage: opencrvs upgrade [options]
|
|
5095
|
+
|
|
5096
|
+
Upgrade the country config in the current working directory to the next
|
|
5097
|
+
major version of OpenCRVS.
|
|
5098
|
+
|
|
5099
|
+
Codemods are best-effort: a country config that renamed or restructured the
|
|
5100
|
+
files a codemod targets keeps its own structure, and the step is reported as
|
|
5101
|
+
outstanding rather than guessed at. Anything left over is listed at the end,
|
|
5102
|
+
and the command exits non-zero while that list is not empty.
|
|
5103
|
+
|
|
5104
|
+
Options:
|
|
5105
|
+
--docker-swarm Also list the manual steps that only apply to a Docker
|
|
5106
|
+
Swarm deployment, which lives in compose files no codemod
|
|
5107
|
+
here touches. Omit it for Kubernetes, where the charts and
|
|
5108
|
+
the postgres-on-deploy job cover the same ground.
|
|
5109
|
+
-h, --help Show this message.
|
|
5110
|
+
`.trim();
|
|
5111
|
+
function main5() {
|
|
5112
|
+
const command = args[0];
|
|
5113
|
+
if (!command || command === "--help" || command === "-h") {
|
|
5114
|
+
console.log(USAGE);
|
|
5115
|
+
process.exit(0);
|
|
5116
|
+
}
|
|
5117
|
+
switch (command) {
|
|
5118
|
+
case "environment":
|
|
5119
|
+
return handleEnvironment();
|
|
5120
|
+
case "upgrade":
|
|
5121
|
+
return handleUpgrade();
|
|
5122
|
+
case "check-translations":
|
|
5123
|
+
return handleCheckTranslations();
|
|
5124
|
+
case "verify-upgrade":
|
|
5125
|
+
return handleVerifyUpgrade();
|
|
5126
|
+
case "verify-endpoints":
|
|
5127
|
+
return handleVerifyEndpoints();
|
|
5128
|
+
default:
|
|
5129
|
+
console.error(`Unknown command: ${command}
|
|
5130
|
+
`);
|
|
5131
|
+
console.log(USAGE);
|
|
5132
|
+
process.exit(1);
|
|
5133
|
+
}
|
|
5134
|
+
}
|
|
5135
|
+
async function handleEnvironment() {
|
|
5136
|
+
const subcommand = args[1];
|
|
5137
|
+
if (!subcommand || subcommand === "--help" || subcommand === "-h") {
|
|
5138
|
+
console.log(
|
|
5139
|
+
`
|
|
5140
|
+
Usage: opencrvs environment <subcommand>
|
|
5141
|
+
|
|
5142
|
+
Subcommands:
|
|
5143
|
+
init Initialise a new environment
|
|
5144
|
+
upgrade Upgrade existing environment configuration
|
|
5145
|
+
update-workflows Update workflow environment options
|
|
5146
|
+
users Manage environment users
|
|
5147
|
+
swarm-to-k8s Migrate Docker Swarm configuration to Kubernetes
|
|
5148
|
+
`.trim()
|
|
5149
|
+
);
|
|
5150
|
+
process.exit(0);
|
|
5151
|
+
}
|
|
5152
|
+
switch (subcommand) {
|
|
5153
|
+
case "init":
|
|
5154
|
+
return runEnvironmentCommand("initialisation", runEnvironmentInit);
|
|
5155
|
+
case "upgrade":
|
|
5156
|
+
return runEnvironmentCommand("environment upgrade", runEnvironmentUpgrade);
|
|
5157
|
+
case "update-workflows":
|
|
5158
|
+
return runEnvironmentCommand(
|
|
5159
|
+
"workflow update",
|
|
5160
|
+
runEnvironmentUpdateWorkflows
|
|
5161
|
+
);
|
|
5162
|
+
case "users":
|
|
5163
|
+
return runEnvironmentCommand("user management", runEnvironmentUsers);
|
|
5164
|
+
case "swarm-to-k8s":
|
|
5165
|
+
return runEnvironmentCommand(
|
|
5166
|
+
"Swarm to Kubernetes migration",
|
|
5167
|
+
runEnvironmentSwarmToK8s
|
|
5168
|
+
);
|
|
5169
|
+
default:
|
|
5170
|
+
console.error(`Unknown subcommand: environment ${subcommand}`);
|
|
5171
|
+
process.exit(1);
|
|
5172
|
+
}
|
|
5173
|
+
}
|
|
5174
|
+
async function runEnvironmentCommand(operation, command) {
|
|
5175
|
+
try {
|
|
5176
|
+
await command();
|
|
5177
|
+
} catch (error3) {
|
|
5178
|
+
console.error(
|
|
5179
|
+
`Environment ${operation} failed:`,
|
|
5180
|
+
error3 instanceof Error ? error3.message : error3
|
|
5181
|
+
);
|
|
5182
|
+
process.exit(1);
|
|
5183
|
+
}
|
|
5184
|
+
}
|
|
5185
|
+
async function handleUpgrade() {
|
|
5186
|
+
const upgradeArgs = args.slice(1);
|
|
5187
|
+
if (upgradeArgs.includes("--help") || upgradeArgs.includes("-h")) {
|
|
5188
|
+
console.log(UPGRADE_USAGE);
|
|
5189
|
+
process.exit(0);
|
|
5190
|
+
}
|
|
5191
|
+
const KNOWN_FLAGS = /* @__PURE__ */ new Set(["--docker-swarm"]);
|
|
5192
|
+
const unknownFlags = upgradeArgs.filter(
|
|
5193
|
+
(arg) => arg.startsWith("-") && !KNOWN_FLAGS.has(arg)
|
|
5194
|
+
);
|
|
5195
|
+
if (unknownFlags.length > 0) {
|
|
5196
|
+
console.error(`Unknown option(s): ${unknownFlags.join(", ")}
|
|
5197
|
+
`);
|
|
5198
|
+
console.log(UPGRADE_USAGE);
|
|
5199
|
+
process.exit(1);
|
|
3561
5200
|
}
|
|
3562
5201
|
const dockerSwarm = upgradeArgs.includes("--docker-swarm");
|
|
3563
5202
|
console.log("Initiating upgrade...");
|
|
5203
|
+
let outstanding;
|
|
3564
5204
|
try {
|
|
3565
|
-
|
|
3566
|
-
|
|
5205
|
+
;
|
|
5206
|
+
({ outstanding } = await runUpgrade(dockerSwarm));
|
|
3567
5207
|
} catch (error3) {
|
|
3568
5208
|
console.error("Upgrade failed:", error3);
|
|
3569
5209
|
process.exit(1);
|
|
3570
5210
|
}
|
|
5211
|
+
if (outstanding.length === 0) {
|
|
5212
|
+
console.log("\nUpgrade completed successfully!");
|
|
5213
|
+
console.log(
|
|
5214
|
+
"Next, start the country config and run 'opencrvs verify-upgrade'."
|
|
5215
|
+
);
|
|
5216
|
+
return;
|
|
5217
|
+
}
|
|
5218
|
+
console.error(
|
|
5219
|
+
`
|
|
5220
|
+
Upgrade ran, but ${outstanding.length} step(s) could not be done for you.`
|
|
5221
|
+
);
|
|
5222
|
+
console.error("Do these by hand before deploying:\n");
|
|
5223
|
+
outstanding.forEach((step, index) => {
|
|
5224
|
+
console.error(` ${index + 1}. ${step}`);
|
|
5225
|
+
});
|
|
5226
|
+
console.error(
|
|
5227
|
+
"\nThen start the country config and run 'opencrvs verify-upgrade' to check what is left."
|
|
5228
|
+
);
|
|
5229
|
+
process.exit(1);
|
|
3571
5230
|
}
|
|
5231
|
+
var CHECK_TRANSLATIONS_USAGE = `
|
|
5232
|
+
Usage: opencrvs check-translations [options]
|
|
5233
|
+
|
|
5234
|
+
Check that every message this country config declares has a row in
|
|
5235
|
+
src/translations/countryconfig.csv.
|
|
5236
|
+
|
|
5237
|
+
Options:
|
|
5238
|
+
--write Add the missing rows, filling in English only
|
|
5239
|
+
--outdated List rows nothing in the source declares any more
|
|
5240
|
+
-h, --help Show this help
|
|
5241
|
+
`;
|
|
3572
5242
|
function handleCheckTranslations() {
|
|
3573
|
-
|
|
3574
|
-
|
|
3575
|
-
|
|
5243
|
+
const checkArgs = args.slice(1);
|
|
5244
|
+
if (checkArgs.includes("--help") || checkArgs.includes("-h")) {
|
|
5245
|
+
console.log(CHECK_TRANSLATIONS_USAGE);
|
|
5246
|
+
return;
|
|
5247
|
+
}
|
|
5248
|
+
const unknownFlags = checkArgs.filter(
|
|
5249
|
+
(arg) => arg.startsWith("-") && !["--write", "--outdated"].includes(arg)
|
|
5250
|
+
);
|
|
5251
|
+
if (unknownFlags.length > 0) {
|
|
5252
|
+
console.error(`Unknown option: ${unknownFlags.join(", ")}
|
|
5253
|
+
`);
|
|
5254
|
+
console.log(CHECK_TRANSLATIONS_USAGE);
|
|
5255
|
+
process.exit(1);
|
|
5256
|
+
}
|
|
5257
|
+
const cwd = process.cwd();
|
|
5258
|
+
const { missing, outdated, dynamicIds } = check(cwd);
|
|
5259
|
+
for (const file of dynamicIds) {
|
|
5260
|
+
console.warn(
|
|
5261
|
+
`Warning: ${file} declares a message whose id is built at runtime. Ids have to be hardcoded to be checked.`
|
|
5262
|
+
);
|
|
5263
|
+
}
|
|
5264
|
+
if (checkArgs.includes("--outdated")) {
|
|
5265
|
+
console.log(
|
|
5266
|
+
`${outdated.length} row(s) in countryconfig.csv are not declared in src:
|
|
5267
|
+
`
|
|
5268
|
+
);
|
|
5269
|
+
console.log(outdated.join("\n"));
|
|
5270
|
+
return;
|
|
5271
|
+
}
|
|
5272
|
+
if (missing.length === 0) {
|
|
5273
|
+
console.log("Every message declared in src has a translation row.");
|
|
5274
|
+
return;
|
|
5275
|
+
}
|
|
5276
|
+
console.error(
|
|
5277
|
+
`${missing.length} message(s) declared in src have no row in src/translations/countryconfig.csv:
|
|
5278
|
+
`
|
|
5279
|
+
);
|
|
5280
|
+
console.error(missing.map(({ id }) => ` ${id}`).join("\n"));
|
|
5281
|
+
if (!checkArgs.includes("--write")) {
|
|
5282
|
+
console.error(
|
|
5283
|
+
"\nRun `pnpm extract:translations --write` to add them with their English copy."
|
|
5284
|
+
);
|
|
5285
|
+
process.exit(1);
|
|
5286
|
+
}
|
|
5287
|
+
const added = writeMissing(cwd, missing);
|
|
5288
|
+
console.log(`
|
|
5289
|
+
Added ${added.length} row(s) to countryconfig.csv.`);
|
|
5290
|
+
console.log("The languages other than English are still yours to write.");
|
|
5291
|
+
}
|
|
5292
|
+
async function handleVerifyEndpoints() {
|
|
5293
|
+
const verifyArgs = args.slice(1);
|
|
5294
|
+
if (verifyArgs.includes("--help") || verifyArgs.includes("-h")) {
|
|
5295
|
+
console.log(VERIFY_ENDPOINTS_USAGE);
|
|
5296
|
+
process.exit(0);
|
|
5297
|
+
}
|
|
5298
|
+
const positional = verifyArgs.filter((arg) => !arg.startsWith("-"));
|
|
5299
|
+
if (positional.length > 1) {
|
|
5300
|
+
console.error(
|
|
5301
|
+
`Unexpected extra argument(s): ${positional.slice(1).join(", ")}
|
|
5302
|
+
`
|
|
5303
|
+
);
|
|
5304
|
+
console.log(VERIFY_ENDPOINTS_USAGE);
|
|
5305
|
+
process.exit(1);
|
|
5306
|
+
}
|
|
5307
|
+
try {
|
|
5308
|
+
const failures = await runVerifyEndpoints(positional[0]);
|
|
5309
|
+
if (failures > 0) {
|
|
5310
|
+
process.exit(1);
|
|
5311
|
+
}
|
|
5312
|
+
} catch (error3) {
|
|
5313
|
+
console.error(
|
|
5314
|
+
"Endpoint verification failed:",
|
|
5315
|
+
error3 instanceof Error ? error3.message : error3
|
|
5316
|
+
);
|
|
5317
|
+
process.exit(1);
|
|
5318
|
+
}
|
|
5319
|
+
}
|
|
5320
|
+
async function handleVerifyUpgrade() {
|
|
5321
|
+
const verifyArgs = args.slice(1);
|
|
5322
|
+
if (verifyArgs.includes("--help") || verifyArgs.includes("-h")) {
|
|
5323
|
+
console.log(VERIFY_UPGRADE_USAGE);
|
|
5324
|
+
process.exit(0);
|
|
5325
|
+
}
|
|
5326
|
+
const unknownFlags = verifyArgs.filter((arg) => arg.startsWith("-"));
|
|
5327
|
+
if (unknownFlags.length > 0) {
|
|
5328
|
+
console.error(`Unknown option(s): ${unknownFlags.join(", ")}
|
|
5329
|
+
`);
|
|
5330
|
+
console.log(VERIFY_UPGRADE_USAGE);
|
|
5331
|
+
process.exit(1);
|
|
5332
|
+
}
|
|
5333
|
+
const positional = verifyArgs.filter((arg) => !arg.startsWith("-"));
|
|
5334
|
+
if (positional.length > 1) {
|
|
5335
|
+
console.error(
|
|
5336
|
+
`Unexpected extra argument(s): ${positional.slice(1).join(", ")}
|
|
5337
|
+
`
|
|
5338
|
+
);
|
|
5339
|
+
console.log(VERIFY_UPGRADE_USAGE);
|
|
5340
|
+
process.exit(1);
|
|
5341
|
+
}
|
|
5342
|
+
try {
|
|
5343
|
+
const failures = await runVerifyUpgrade(positional[0]);
|
|
5344
|
+
if (failures > 0) {
|
|
5345
|
+
process.exit(1);
|
|
5346
|
+
}
|
|
5347
|
+
} catch (error3) {
|
|
5348
|
+
console.error(
|
|
5349
|
+
"Upgrade verification failed:",
|
|
5350
|
+
error3 instanceof Error ? error3.message : error3
|
|
5351
|
+
);
|
|
5352
|
+
process.exit(1);
|
|
5353
|
+
}
|
|
3576
5354
|
}
|
|
3577
|
-
|
|
5355
|
+
main5();
|