@opencrvs/toolkit 2.1.0-rc.976ee09 → 2.1.0-rc.982e0ae
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 +1 -0
- package/build.sh +9 -1
- package/create-countryconfig/index.js +284 -62
- package/create-countryconfig/node_modules/.bin/degit +21 -0
- package/create-countryconfig/package.json +4 -1
- package/dist/application-config/index.js +341 -274
- package/dist/authentication/index.d.ts +67 -0
- package/dist/authentication/index.d.ts.map +1 -0
- package/dist/authentication/index.js +750 -0
- package/dist/cli.js +1744 -104
- package/dist/commons/api/router.d.ts +691 -76
- package/dist/commons/conditionals/conditionals.d.ts +6 -6
- package/dist/commons/conditionals/validate.d.ts +16 -5
- 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 +24 -0
- 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 +88 -53
- 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/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 +165 -26
- package/dist/commons/events/mocks.test.utils.d.ts +30 -0
- package/dist/commons/events/test.utils.d.ts +8 -4
- package/dist/commons/events/utils.d.ts +2 -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 +328 -58
- package/dist/csv.d.ts +25 -0
- package/dist/csv.d.ts.map +1 -0
- package/dist/csv.js +120 -0
- package/dist/environment/index.d.ts +1 -0
- package/dist/environment/index.d.ts.map +1 -1
- package/dist/environment/index.js +10 -0
- package/dist/environment/logger.d.ts +15 -3
- package/dist/environment/logger.d.ts.map +1 -1
- package/dist/environment/paths.d.ts +7 -0
- package/dist/environment/paths.d.ts.map +1 -0
- package/dist/environment/paths.js +72 -0
- package/dist/environment/questions.d.ts.map +1 -1
- package/dist/environment/questions.js +20 -14
- package/dist/environment/setup-environment.js +3 -2
- package/dist/environment/templates.d.ts.map +1 -1
- package/dist/environment/templates.js +2 -1
- package/dist/environment/update-workflows.d.ts.map +1 -1
- package/dist/environment/update-workflows.js +17 -5
- package/dist/environment/upgrade.d.ts +2 -0
- package/dist/environment/upgrade.d.ts.map +1 -0
- package/dist/environment/upgrade.js +82 -0
- package/dist/environment/users.js +11 -13
- package/dist/events/index.js +3688 -3293
- 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.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 +511 -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 +213 -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 +438 -0
- package/dist/migrations/v2.1/index.d.ts.map +1 -1
- package/dist/migrations/v2.1/index.js +1058 -0
- package/dist/notification/index.js +1833 -1426
- package/dist/scopes/index.d.ts +327 -32
- package/dist/scopes/index.js +329 -58
- 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/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 +19 -0
- package/dist/translations/check.d.ts.map +1 -0
- package/dist/translations/check.js +127 -0
- package/dist/verify/endpoints.d.ts +2 -0
- package/dist/verify/endpoints.d.ts.map +1 -0
- package/dist/verify/endpoints.js +345 -0
- package/opencrvs-toolkit-2.1.0-rc.982e0ae.tgz +0 -0
- package/package.json +11 -5
- 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.976ee09.tgz +0 -0
- package/tsconfig.tsbuildinfo +0 -1
package/dist/cli.js
CHANGED
|
@@ -30,6 +30,42 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
30
30
|
mod
|
|
31
31
|
));
|
|
32
32
|
|
|
33
|
+
// src/environment/paths.ts
|
|
34
|
+
function getEnvironmentInventoryPath(environment) {
|
|
35
|
+
return (0, import_path6.join)("environments", environment, INVENTORY_FILE_NAME);
|
|
36
|
+
}
|
|
37
|
+
function findOldInventoryFiles() {
|
|
38
|
+
return glob.sync((0, import_path6.join)(OLD_INVENTORY_DIR, "*.yml")).sort();
|
|
39
|
+
}
|
|
40
|
+
function getEnvironmentNameFromOldInventoryPath(filePath) {
|
|
41
|
+
return (0, import_path6.basename)(filePath, ".yml");
|
|
42
|
+
}
|
|
43
|
+
function assertNoOldInventoryLayout() {
|
|
44
|
+
if (findOldInventoryFiles().length === 0) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
throw new Error(
|
|
48
|
+
[
|
|
49
|
+
`Old inventory layout detected at ${OLD_INVENTORY_DIR}.`,
|
|
50
|
+
"Please run `yarn environment:upgrade` before running `yarn environment:init`."
|
|
51
|
+
].join(" ")
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
var import_path6, glob, OLD_INVENTORY_DIR, INVENTORY_FILE_NAME;
|
|
55
|
+
var init_paths = __esm({
|
|
56
|
+
"src/environment/paths.ts"() {
|
|
57
|
+
"use strict";
|
|
58
|
+
import_path6 = require("path");
|
|
59
|
+
glob = __toESM(require("glob"));
|
|
60
|
+
OLD_INVENTORY_DIR = (0, import_path6.join)(
|
|
61
|
+
"infrastructure",
|
|
62
|
+
"server-setup",
|
|
63
|
+
"inventory"
|
|
64
|
+
);
|
|
65
|
+
INVENTORY_FILE_NAME = "inventory.yml";
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
|
|
33
69
|
// src/environment/logger.ts
|
|
34
70
|
var import_kleur, log, warn, success, info, error;
|
|
35
71
|
var init_logger = __esm({
|
|
@@ -471,9 +507,9 @@ function storeSecrets(environment, answers) {
|
|
|
471
507
|
let envConfig = {};
|
|
472
508
|
try {
|
|
473
509
|
envConfig = import_dotenv.default.parse(
|
|
474
|
-
(0,
|
|
510
|
+
(0, import_fs4.readFileSync)(`${process.cwd()}/.env.${environment}`)
|
|
475
511
|
);
|
|
476
|
-
} catch (
|
|
512
|
+
} catch (error3) {
|
|
477
513
|
envConfig = {};
|
|
478
514
|
}
|
|
479
515
|
const linesFromAnswers = answers.map(
|
|
@@ -481,10 +517,10 @@ function storeSecrets(environment, answers) {
|
|
|
481
517
|
);
|
|
482
518
|
const linesFromEnvConfig = Object.entries(envConfig).filter(([name]) => !answers.find((update) => update.name === name)).map(([name, value]) => `${name}="${value}"`);
|
|
483
519
|
const allLines = [...linesFromEnvConfig, ...linesFromAnswers].sort();
|
|
484
|
-
(0,
|
|
520
|
+
(0, import_fs4.writeFileSync)(`.env.${environment}`, allLines.join("\n"));
|
|
485
521
|
}
|
|
486
522
|
function readYamlFile(filePath) {
|
|
487
|
-
const fileContent =
|
|
523
|
+
const fileContent = import_fs4.default.readFileSync(filePath, "utf8");
|
|
488
524
|
return yaml.load(fileContent);
|
|
489
525
|
}
|
|
490
526
|
function writeYamlFile(filePath, data) {
|
|
@@ -497,16 +533,16 @@ function writeYamlFile(filePath, data) {
|
|
|
497
533
|
noRefs: true,
|
|
498
534
|
sortKeys: false
|
|
499
535
|
});
|
|
500
|
-
|
|
501
|
-
} catch (
|
|
502
|
-
throw new Error(`Failed to write inventory file: ${
|
|
536
|
+
import_fs4.default.writeFileSync(filePath, yamlContent, "utf8");
|
|
537
|
+
} catch (error3) {
|
|
538
|
+
throw new Error(`Failed to write inventory file: ${error3}`);
|
|
503
539
|
}
|
|
504
540
|
}
|
|
505
|
-
var
|
|
541
|
+
var import_fs4, yaml, import_dotenv;
|
|
506
542
|
var init_utils = __esm({
|
|
507
543
|
"src/environment/utils.ts"() {
|
|
508
544
|
"use strict";
|
|
509
|
-
|
|
545
|
+
import_fs4 = __toESM(require("fs"));
|
|
510
546
|
yaml = __toESM(require("js-yaml"));
|
|
511
547
|
import_dotenv = __toESM(require("dotenv"));
|
|
512
548
|
}
|
|
@@ -559,29 +595,29 @@ function extractWorkerNodes(data) {
|
|
|
559
595
|
return worker_hosts;
|
|
560
596
|
}
|
|
561
597
|
function copyChartsValues(env, values) {
|
|
562
|
-
const srcDir =
|
|
563
|
-
const destDir =
|
|
564
|
-
|
|
598
|
+
const srcDir = import_path7.default.resolve(__dirname, "templates", "charts-values");
|
|
599
|
+
const destDir = import_path7.default.resolve(process.cwd(), "environments", env);
|
|
600
|
+
import_fs5.default.mkdirSync(destDir, { recursive: true });
|
|
565
601
|
values["lets_encrypt"] = values["traefik_mode"] === "lets_encrypt";
|
|
566
602
|
values["static_ssl"] = values["traefik_mode"] === "static_ssl";
|
|
567
603
|
values["opencrvs_environment"] = env;
|
|
568
604
|
function copyRecursive(src, dest) {
|
|
569
|
-
const stat =
|
|
605
|
+
const stat = import_fs5.default.statSync(src);
|
|
570
606
|
if (stat.isDirectory()) {
|
|
571
|
-
|
|
572
|
-
for (const item of
|
|
573
|
-
copyRecursive(
|
|
607
|
+
import_fs5.default.mkdirSync(dest, { recursive: true });
|
|
608
|
+
for (const item of import_fs5.default.readdirSync(src)) {
|
|
609
|
+
copyRecursive(import_path7.default.join(src, item), import_path7.default.join(dest, item));
|
|
574
610
|
}
|
|
575
611
|
} else {
|
|
576
|
-
const content =
|
|
612
|
+
const content = import_fs5.default.readFileSync(src, "utf8");
|
|
577
613
|
const template = import_handlebars.default.compile(content);
|
|
578
614
|
const updated = template(values);
|
|
579
615
|
const isOverridesFile = dest.endsWith("override.yaml");
|
|
580
|
-
if (isOverridesFile &&
|
|
616
|
+
if (isOverridesFile && import_fs5.default.existsSync(dest)) {
|
|
581
617
|
log(` \u21B7 Skipped existing overrides file: ${dest}`);
|
|
582
618
|
return;
|
|
583
619
|
}
|
|
584
|
-
|
|
620
|
+
import_fs5.default.writeFileSync(dest, updated, "utf8");
|
|
585
621
|
log(` \u2713 Created: ${dest}`);
|
|
586
622
|
}
|
|
587
623
|
}
|
|
@@ -592,36 +628,31 @@ function copyChartsValues(env, values) {
|
|
|
592
628
|
`);
|
|
593
629
|
}
|
|
594
630
|
function generateInventory(env, values) {
|
|
595
|
-
const templatePath =
|
|
631
|
+
const templatePath = import_path7.default.join(
|
|
596
632
|
__dirname,
|
|
597
633
|
"templates",
|
|
598
634
|
"inventory",
|
|
599
635
|
"inventory.template.yml"
|
|
600
636
|
);
|
|
601
|
-
const outputPath =
|
|
602
|
-
|
|
603
|
-
"infrastructure",
|
|
604
|
-
"server-setup",
|
|
605
|
-
"inventory",
|
|
606
|
-
`${env}.yml`
|
|
607
|
-
);
|
|
608
|
-
const templateFile = import_fs2.default.readFileSync(templatePath, "utf-8");
|
|
637
|
+
const outputPath = import_path7.default.resolve(process.cwd(), getEnvironmentInventoryPath(env));
|
|
638
|
+
const templateFile = import_fs5.default.readFileSync(templatePath, "utf-8");
|
|
609
639
|
const template = import_handlebars.default.compile(templateFile);
|
|
610
640
|
values["single_node"] = values["kube_worker_nodes"].length > 0 || values["backup_host"] ? "false" : "true";
|
|
611
641
|
const updated = template(values);
|
|
612
|
-
|
|
613
|
-
|
|
642
|
+
import_fs5.default.mkdirSync(import_path7.default.dirname(outputPath), { recursive: true });
|
|
643
|
+
import_fs5.default.writeFileSync(outputPath, updated);
|
|
614
644
|
log(`
|
|
615
645
|
\u2705 Generated inventory file at ${outputPath}
|
|
616
646
|
`);
|
|
617
647
|
}
|
|
618
|
-
var
|
|
648
|
+
var import_fs5, import_path7, import_handlebars;
|
|
619
649
|
var init_templates = __esm({
|
|
620
650
|
"src/environment/templates.ts"() {
|
|
621
651
|
"use strict";
|
|
622
|
-
|
|
623
|
-
|
|
652
|
+
import_fs5 = __toESM(require("fs"));
|
|
653
|
+
import_path7 = __toESM(require("path"));
|
|
624
654
|
init_logger();
|
|
655
|
+
init_paths();
|
|
625
656
|
import_handlebars = __toESM(require("handlebars"));
|
|
626
657
|
import_handlebars.default.registerHelper("data_label_idx", function(value) {
|
|
627
658
|
return parseInt(value) + 2;
|
|
@@ -829,11 +860,28 @@ var init_questions = __esm({
|
|
|
829
860
|
scope: "ENVIRONMENT"
|
|
830
861
|
},
|
|
831
862
|
{
|
|
832
|
-
name: "
|
|
863
|
+
name: "kubeMasterNode",
|
|
833
864
|
type: "text",
|
|
834
|
-
message: `Kubernetes
|
|
865
|
+
message: `Kubernetes master node hostnames or IP (default: auto-detect)`,
|
|
866
|
+
valueType: "VARIABLE",
|
|
867
|
+
valueLabel: "KUBE_MASTER_NODE",
|
|
868
|
+
initial: process.env.KUBE_MASTER_NODE,
|
|
869
|
+
scope: "ENVIRONMENT"
|
|
870
|
+
},
|
|
871
|
+
{
|
|
872
|
+
name: "kubeWorkerNodes",
|
|
873
|
+
type: "text",
|
|
874
|
+
message: `Kubernetes worker node hostnames or IPs (comma-separated, default: no worker nodes)`,
|
|
875
|
+
valueType: "VARIABLE",
|
|
876
|
+
valueLabel: "KUBE_WORKER_NODES",
|
|
877
|
+
initial: process.env.KUBE_WORKER_NODES || "",
|
|
878
|
+
scope: "ENVIRONMENT"
|
|
879
|
+
},
|
|
880
|
+
{
|
|
881
|
+
name: "kubeApiHost",
|
|
882
|
+
type: "text",
|
|
883
|
+
message: `Kubernetes API endpoint IP (default: KUBE_MASTER_NODE)`,
|
|
835
884
|
valueType: "VARIABLE",
|
|
836
|
-
// validate: notEmpty,
|
|
837
885
|
valueLabel: "KUBE_API_HOST",
|
|
838
886
|
initial: process.env.KUBE_API_HOST,
|
|
839
887
|
scope: "ENVIRONMENT"
|
|
@@ -847,16 +895,6 @@ var init_questions = __esm({
|
|
|
847
895
|
valueLabel: "KUBE_API_ALLOWED_CIDRS",
|
|
848
896
|
initial: process.env.KUBE_API_ALLOWED_CIDRS || "",
|
|
849
897
|
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
|
-
// validate: notEmpty,
|
|
857
|
-
valueLabel: "KUBE_WORKER_NODES",
|
|
858
|
-
initial: process.env.KUBE_WORKER_NODES || "",
|
|
859
|
-
scope: "ENVIRONMENT"
|
|
860
898
|
}
|
|
861
899
|
];
|
|
862
900
|
staticSSLCertQuestions = [
|
|
@@ -887,7 +925,6 @@ var init_questions = __esm({
|
|
|
887
925
|
type: "text",
|
|
888
926
|
message: `Please enter backup server host/IP address, (default: no backup):`,
|
|
889
927
|
valueType: "VARIABLE",
|
|
890
|
-
// validate: notEmpty,
|
|
891
928
|
valueLabel: "BACKUP_HOST",
|
|
892
929
|
initial: process.env.BACKUP_HOST || "",
|
|
893
930
|
scope: "ENVIRONMENT"
|
|
@@ -1220,7 +1257,7 @@ function getCurrentUsername() {
|
|
|
1220
1257
|
}
|
|
1221
1258
|
function getCurrentUserSSHKeys() {
|
|
1222
1259
|
const homeDir = os.homedir();
|
|
1223
|
-
const sshDir =
|
|
1260
|
+
const sshDir = path7.join(homeDir, ".ssh");
|
|
1224
1261
|
const keys = [];
|
|
1225
1262
|
const keyFiles = [
|
|
1226
1263
|
"id_rsa.pub",
|
|
@@ -1229,7 +1266,7 @@ function getCurrentUserSSHKeys() {
|
|
|
1229
1266
|
"id_dsa.pub"
|
|
1230
1267
|
];
|
|
1231
1268
|
for (const keyFile of keyFiles) {
|
|
1232
|
-
const keyPath =
|
|
1269
|
+
const keyPath = path7.join(sshDir, keyFile);
|
|
1233
1270
|
try {
|
|
1234
1271
|
if (fs3.existsSync(keyPath)) {
|
|
1235
1272
|
const keyContent = fs3.readFileSync(keyPath, "utf8").trim();
|
|
@@ -1237,7 +1274,7 @@ function getCurrentUserSSHKeys() {
|
|
|
1237
1274
|
keys.push(keyContent);
|
|
1238
1275
|
}
|
|
1239
1276
|
}
|
|
1240
|
-
} catch (
|
|
1277
|
+
} catch (error3) {
|
|
1241
1278
|
continue;
|
|
1242
1279
|
}
|
|
1243
1280
|
}
|
|
@@ -1570,13 +1607,13 @@ async function manageUsers(inventoryPath) {
|
|
|
1570
1607
|
}
|
|
1571
1608
|
return users;
|
|
1572
1609
|
}
|
|
1573
|
-
var os, fs3,
|
|
1610
|
+
var os, fs3, path7, input2, select2, confirm, editor, checkbox;
|
|
1574
1611
|
var init_manage_users = __esm({
|
|
1575
1612
|
"src/environment/manage-users.ts"() {
|
|
1576
1613
|
"use strict";
|
|
1577
1614
|
os = __toESM(require("os"));
|
|
1578
1615
|
fs3 = __toESM(require("fs"));
|
|
1579
|
-
|
|
1616
|
+
path7 = __toESM(require("path"));
|
|
1580
1617
|
init_logger();
|
|
1581
1618
|
init_utils();
|
|
1582
1619
|
init_templates();
|
|
@@ -1773,6 +1810,7 @@ var init_setup_environment = __esm({
|
|
|
1773
1810
|
init_editor_questions();
|
|
1774
1811
|
init_questions_helper();
|
|
1775
1812
|
init_manage_users();
|
|
1813
|
+
init_paths();
|
|
1776
1814
|
ALL_QUESTIONS = [];
|
|
1777
1815
|
ALL_ANSWERS = [];
|
|
1778
1816
|
ALL_QUESTIONS.push(
|
|
@@ -1936,9 +1974,7 @@ var init_setup_environment = __esm({
|
|
|
1936
1974
|
);
|
|
1937
1975
|
const kubeWorkerNodes = infrastructure.kubeWorkerNodes ? infrastructure.kubeWorkerNodes.split(",").map((ip) => ip.trim()) : [];
|
|
1938
1976
|
log("\n", import_kleur4.default.bold().underline("SSH Users"), "\n");
|
|
1939
|
-
const users = await manageUsers(
|
|
1940
|
-
`infrastructure/server-setup/inventory/${environment}.yml`
|
|
1941
|
-
);
|
|
1977
|
+
const users = await manageUsers(getEnvironmentInventoryPath(environment));
|
|
1942
1978
|
log("\n", import_kleur4.default.bold().underline("Traefik SSL Certificate"), "\n");
|
|
1943
1979
|
const sslCertExists = findExistingValue(
|
|
1944
1980
|
"SSL_CRT",
|
|
@@ -2690,7 +2726,7 @@ var init_setup_environment = __esm({
|
|
|
2690
2726
|
log("\n", import_kleur4.default.bold().underline("Running configuration files updates"));
|
|
2691
2727
|
generateInventory(environment, {
|
|
2692
2728
|
kube_worker_nodes: kubeWorkerNodes,
|
|
2693
|
-
kube_api_host: infrastructure.
|
|
2729
|
+
kube_api_host: infrastructure.kubeApiHost || "",
|
|
2694
2730
|
backup_host: backupHost || "",
|
|
2695
2731
|
users
|
|
2696
2732
|
});
|
|
@@ -2751,12 +2787,19 @@ var update_workflows_exports = {};
|
|
|
2751
2787
|
__export(update_workflows_exports, {
|
|
2752
2788
|
updateWorkflowEnvironments: () => updateWorkflowEnvironments
|
|
2753
2789
|
});
|
|
2790
|
+
function isDirectory(path10) {
|
|
2791
|
+
try {
|
|
2792
|
+
return (0, import_fs6.statSync)(path10).isDirectory();
|
|
2793
|
+
} catch {
|
|
2794
|
+
return false;
|
|
2795
|
+
}
|
|
2796
|
+
}
|
|
2754
2797
|
async function extractInfrastructureNames() {
|
|
2755
|
-
const files =
|
|
2756
|
-
const infraEnvironments = files.map((file) => (0,
|
|
2798
|
+
const files = glob2.sync((0, import_path8.join)("environments", "*", INVENTORY_FILE_NAME));
|
|
2799
|
+
const infraEnvironments = files.map((file) => (0, import_path8.basename)((0, import_path8.dirname)(file)));
|
|
2757
2800
|
if (infraEnvironments.length === 0) {
|
|
2758
2801
|
console.log(
|
|
2759
|
-
|
|
2802
|
+
`\u26A0\uFE0F Warning: No environment inventory files found at environments/*/${INVENTORY_FILE_NAME}`
|
|
2760
2803
|
);
|
|
2761
2804
|
return [];
|
|
2762
2805
|
}
|
|
@@ -2766,8 +2809,9 @@ async function extractInfrastructureNames() {
|
|
|
2766
2809
|
async function extractEnvironmentNames() {
|
|
2767
2810
|
const entries = await (0, import_promises.readdir)("environments");
|
|
2768
2811
|
const environments = entries.filter((entry) => {
|
|
2769
|
-
const
|
|
2770
|
-
|
|
2812
|
+
const environmentPath = (0, import_path8.join)("environments", entry);
|
|
2813
|
+
const opencrvsServicesPath = (0, import_path8.join)(environmentPath, "opencrvs-services");
|
|
2814
|
+
return isDirectory(environmentPath) && (0, import_fs6.existsSync)(opencrvsServicesPath) && isDirectory(opencrvsServicesPath);
|
|
2771
2815
|
});
|
|
2772
2816
|
if (environments.length === 0) {
|
|
2773
2817
|
console.log(
|
|
@@ -2793,7 +2837,7 @@ async function updateWorkflows(envList, config) {
|
|
|
2793
2837
|
const { workflows } = config;
|
|
2794
2838
|
for (const workflowPath of workflows) {
|
|
2795
2839
|
try {
|
|
2796
|
-
const fileContents = (0,
|
|
2840
|
+
const fileContents = (0, import_fs6.readFileSync)(workflowPath, "utf8");
|
|
2797
2841
|
const workflowData = yaml2.load(fileContents);
|
|
2798
2842
|
if (!workflowData?.on?.workflow_dispatch?.inputs?.environment?.options) {
|
|
2799
2843
|
throw new Error(
|
|
@@ -2801,15 +2845,15 @@ async function updateWorkflows(envList, config) {
|
|
|
2801
2845
|
);
|
|
2802
2846
|
}
|
|
2803
2847
|
const updatedContent = updateOptionsInYaml(fileContents, envList);
|
|
2804
|
-
(0,
|
|
2848
|
+
(0, import_fs6.writeFileSync)(workflowPath, updatedContent, "utf8");
|
|
2805
2849
|
log(` \u2713 Successfully updated ${workflowPath}`);
|
|
2806
|
-
} catch (
|
|
2850
|
+
} catch (error3) {
|
|
2807
2851
|
console.error(
|
|
2808
2852
|
`
|
|
2809
2853
|
\u26A0\uFE0F Error updating ${workflowPath} with environments: [${envList.join(", ")}]`
|
|
2810
2854
|
);
|
|
2811
|
-
console.error(`\u2717 Failed to update ${workflowPath}:`,
|
|
2812
|
-
throw
|
|
2855
|
+
console.error(`\u2717 Failed to update ${workflowPath}:`, error3);
|
|
2856
|
+
throw error3;
|
|
2813
2857
|
}
|
|
2814
2858
|
}
|
|
2815
2859
|
}
|
|
@@ -2850,21 +2894,90 @@ async function updateWorkflowEnvironments() {
|
|
|
2850
2894
|
} else {
|
|
2851
2895
|
log("\u2139\uFE0F No workflows were updated.");
|
|
2852
2896
|
}
|
|
2853
|
-
} catch (
|
|
2854
|
-
console.error("\n\u274C Error updating workflows:",
|
|
2897
|
+
} catch (error3) {
|
|
2898
|
+
console.error("\n\u274C Error updating workflows:", error3);
|
|
2855
2899
|
process.exit(1);
|
|
2856
2900
|
}
|
|
2857
2901
|
}
|
|
2858
|
-
var import_promises,
|
|
2902
|
+
var import_promises, import_fs6, import_path8, glob2, yaml2;
|
|
2859
2903
|
var init_update_workflows = __esm({
|
|
2860
2904
|
"src/environment/update-workflows.ts"() {
|
|
2861
2905
|
"use strict";
|
|
2862
2906
|
import_promises = require("fs/promises");
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2907
|
+
import_fs6 = require("fs");
|
|
2908
|
+
import_path8 = require("path");
|
|
2909
|
+
glob2 = __toESM(require("glob"));
|
|
2866
2910
|
yaml2 = __toESM(require("js-yaml"));
|
|
2867
2911
|
init_logger();
|
|
2912
|
+
init_paths();
|
|
2913
|
+
}
|
|
2914
|
+
});
|
|
2915
|
+
|
|
2916
|
+
// src/environment/upgrade.ts
|
|
2917
|
+
var upgrade_exports = {};
|
|
2918
|
+
__export(upgrade_exports, {
|
|
2919
|
+
upgradeEnvironmentLayout: () => upgradeEnvironmentLayout
|
|
2920
|
+
});
|
|
2921
|
+
function moveFileIfDestinationMissing(sourcePath, destinationPath) {
|
|
2922
|
+
if (!(0, import_fs7.existsSync)(sourcePath)) {
|
|
2923
|
+
return false;
|
|
2924
|
+
}
|
|
2925
|
+
if ((0, import_fs7.existsSync)(destinationPath)) {
|
|
2926
|
+
warn(
|
|
2927
|
+
`\u26A0\uFE0F Skipped ${sourcePath}; destination already exists at ${destinationPath}`
|
|
2928
|
+
);
|
|
2929
|
+
return false;
|
|
2930
|
+
}
|
|
2931
|
+
(0, import_fs7.mkdirSync)((0, import_path9.dirname)(destinationPath), { recursive: true });
|
|
2932
|
+
(0, import_fs7.renameSync)(sourcePath, destinationPath);
|
|
2933
|
+
log(` \u2713 Moved ${sourcePath} -> ${destinationPath}`);
|
|
2934
|
+
return true;
|
|
2935
|
+
}
|
|
2936
|
+
function migrateInventoryFiles() {
|
|
2937
|
+
const oldInventoryFiles = findOldInventoryFiles();
|
|
2938
|
+
if (oldInventoryFiles.length === 0) {
|
|
2939
|
+
log(`\u2139\uFE0F No old inventory files found at ${OLD_INVENTORY_DIR}`);
|
|
2940
|
+
return false;
|
|
2941
|
+
}
|
|
2942
|
+
log(import_kleur5.default.bold("\nMigrating Ansible inventory files"));
|
|
2943
|
+
let didMoveInventory = false;
|
|
2944
|
+
for (const oldInventoryFile of oldInventoryFiles) {
|
|
2945
|
+
const environment = getEnvironmentNameFromOldInventoryPath(oldInventoryFile);
|
|
2946
|
+
didMoveInventory = moveFileIfDestinationMissing(
|
|
2947
|
+
oldInventoryFile,
|
|
2948
|
+
getEnvironmentInventoryPath(environment)
|
|
2949
|
+
) || didMoveInventory;
|
|
2950
|
+
}
|
|
2951
|
+
try {
|
|
2952
|
+
if ((0, import_fs7.existsSync)(OLD_INVENTORY_DIR) && (0, import_fs7.readdirSync)(OLD_INVENTORY_DIR).length === 0) {
|
|
2953
|
+
(0, import_fs7.rmdirSync)(OLD_INVENTORY_DIR);
|
|
2954
|
+
log(` \u2713 Removed empty ${OLD_INVENTORY_DIR}`);
|
|
2955
|
+
}
|
|
2956
|
+
} catch {
|
|
2957
|
+
warn(`\u26A0\uFE0F Could not remove ${OLD_INVENTORY_DIR}; please review it manually`);
|
|
2958
|
+
}
|
|
2959
|
+
return didMoveInventory;
|
|
2960
|
+
}
|
|
2961
|
+
async function upgradeEnvironmentLayout() {
|
|
2962
|
+
const didMoveInventory = migrateInventoryFiles();
|
|
2963
|
+
await updateWorkflowEnvironments();
|
|
2964
|
+
if (didMoveInventory) {
|
|
2965
|
+
success("\n\u2705 Environment layout upgrade completed successfully.");
|
|
2966
|
+
} else {
|
|
2967
|
+
success("\n\u2705 Environment layout already uses the current structure.");
|
|
2968
|
+
}
|
|
2969
|
+
log("\nCommit changes into git after upgrade");
|
|
2970
|
+
}
|
|
2971
|
+
var import_fs7, import_path9, import_kleur5;
|
|
2972
|
+
var init_upgrade = __esm({
|
|
2973
|
+
"src/environment/upgrade.ts"() {
|
|
2974
|
+
"use strict";
|
|
2975
|
+
import_fs7 = require("fs");
|
|
2976
|
+
import_path9 = require("path");
|
|
2977
|
+
import_kleur5 = __toESM(require("kleur"));
|
|
2978
|
+
init_logger();
|
|
2979
|
+
init_paths();
|
|
2980
|
+
init_update_workflows();
|
|
2868
2981
|
}
|
|
2869
2982
|
});
|
|
2870
2983
|
|
|
@@ -2877,7 +2990,7 @@ async function select4(options) {
|
|
|
2877
2990
|
const inquirer = await import("@inquirer/prompts");
|
|
2878
2991
|
return inquirer.select(options);
|
|
2879
2992
|
}
|
|
2880
|
-
async function selectInventoryFile(dirPath = "./
|
|
2993
|
+
async function selectInventoryFile(dirPath = "./environments") {
|
|
2881
2994
|
if (!fs4.existsSync(dirPath)) {
|
|
2882
2995
|
warn(`\u26A0\uFE0F No environment configuration directory found at ${dirPath}`);
|
|
2883
2996
|
warn(
|
|
@@ -2885,22 +2998,20 @@ async function selectInventoryFile(dirPath = "./infrastructure/server-setup/inve
|
|
|
2885
2998
|
);
|
|
2886
2999
|
return null;
|
|
2887
3000
|
}
|
|
2888
|
-
const
|
|
2889
|
-
const filePath =
|
|
2890
|
-
|
|
2891
|
-
const ext = path4.extname(file).slice(1).toLowerCase();
|
|
2892
|
-
return isFile && (ext === "yml" || ext === "yaml");
|
|
3001
|
+
const environments = fs4.readdirSync(dirPath).filter((entry) => {
|
|
3002
|
+
const filePath = path8.join(dirPath, entry);
|
|
3003
|
+
return fs4.statSync(filePath).isDirectory() && fs4.existsSync(getEnvironmentInventoryPath(entry));
|
|
2893
3004
|
}).sort();
|
|
2894
|
-
if (
|
|
3005
|
+
if (environments.length === 0) {
|
|
2895
3006
|
warn(`\u26A0\uFE0F No environment configuration files found at ${dirPath}`);
|
|
2896
3007
|
warn(
|
|
2897
3008
|
"Hint: If this is a new infrastructure repository, run `opencrvs environment init` first."
|
|
2898
3009
|
);
|
|
2899
3010
|
return null;
|
|
2900
3011
|
}
|
|
2901
|
-
const choices =
|
|
2902
|
-
name:
|
|
2903
|
-
value:
|
|
3012
|
+
const choices = environments.map((environment) => ({
|
|
3013
|
+
name: environment,
|
|
3014
|
+
value: getEnvironmentInventoryPath(environment)
|
|
2904
3015
|
}));
|
|
2905
3016
|
const selectedFile = await select4({
|
|
2906
3017
|
message: "Select environment (inventory file) to load users:",
|
|
@@ -2909,33 +3020,34 @@ async function selectInventoryFile(dirPath = "./infrastructure/server-setup/inve
|
|
|
2909
3020
|
return selectedFile;
|
|
2910
3021
|
}
|
|
2911
3022
|
async function manageEnvironmentUsers() {
|
|
2912
|
-
console.log("\n",
|
|
3023
|
+
console.log("\n", import_kleur6.default.bold().underline("Manage users"), "\n");
|
|
2913
3024
|
const inventory_file = await selectInventoryFile();
|
|
2914
3025
|
if (!inventory_file) {
|
|
2915
3026
|
return;
|
|
2916
3027
|
}
|
|
2917
3028
|
await manageUsers(inventory_file);
|
|
2918
3029
|
}
|
|
2919
|
-
var fs4,
|
|
3030
|
+
var fs4, path8, import_kleur6;
|
|
2920
3031
|
var init_users = __esm({
|
|
2921
3032
|
"src/environment/users.ts"() {
|
|
2922
3033
|
"use strict";
|
|
2923
3034
|
fs4 = __toESM(require("fs"));
|
|
2924
|
-
|
|
2925
|
-
|
|
3035
|
+
path8 = __toESM(require("path"));
|
|
3036
|
+
import_kleur6 = __toESM(require("kleur"));
|
|
2926
3037
|
init_manage_users();
|
|
2927
3038
|
init_logger();
|
|
3039
|
+
init_paths();
|
|
2928
3040
|
}
|
|
2929
3041
|
});
|
|
2930
3042
|
|
|
2931
3043
|
// src/environment/swarm-to-k8s.ts
|
|
2932
3044
|
var swarm_to_k8s_exports = {};
|
|
2933
|
-
var
|
|
3045
|
+
var path9, import_kleur7, import_core2;
|
|
2934
3046
|
var init_swarm_to_k8s = __esm({
|
|
2935
3047
|
"src/environment/swarm-to-k8s.ts"() {
|
|
2936
3048
|
"use strict";
|
|
2937
|
-
|
|
2938
|
-
|
|
3049
|
+
path9 = __toESM(require("path"));
|
|
3050
|
+
import_kleur7 = __toESM(require("kleur"));
|
|
2939
3051
|
init_logger();
|
|
2940
3052
|
init_utils();
|
|
2941
3053
|
init_templates();
|
|
@@ -2944,7 +3056,7 @@ var init_swarm_to_k8s = __esm({
|
|
|
2944
3056
|
init_github();
|
|
2945
3057
|
(async () => {
|
|
2946
3058
|
log(
|
|
2947
|
-
|
|
3059
|
+
import_kleur7.default.bold(
|
|
2948
3060
|
"------------------------------------------------\nOpenCRVS Infrastructure migration script: \nMigrating Swarm configurations to Kubernetes\n------------------------------------------------\n"
|
|
2949
3061
|
)
|
|
2950
3062
|
);
|
|
@@ -2975,7 +3087,7 @@ var init_swarm_to_k8s = __esm({
|
|
|
2975
3087
|
);
|
|
2976
3088
|
process.exit(0);
|
|
2977
3089
|
}
|
|
2978
|
-
log(
|
|
3090
|
+
log(import_kleur7.default.bold().underline("Migration properties:"));
|
|
2979
3091
|
log(` \u2713 Environment: ${environment}`);
|
|
2980
3092
|
const old_inventory_path = process.env.OLD_INVENTORY_PATH || "";
|
|
2981
3093
|
if (!old_inventory_path) {
|
|
@@ -2986,7 +3098,7 @@ var init_swarm_to_k8s = __esm({
|
|
|
2986
3098
|
);
|
|
2987
3099
|
process.exit(1);
|
|
2988
3100
|
}
|
|
2989
|
-
const ansible_inventory =
|
|
3101
|
+
const ansible_inventory = path9.join(old_inventory_path, environment + ".yml");
|
|
2990
3102
|
const data = readYamlFile(ansible_inventory);
|
|
2991
3103
|
log(` \u2713 Loaded old inventory file: ${ansible_inventory}`);
|
|
2992
3104
|
const master = dockerManagerFirst(data) || "";
|
|
@@ -3287,14 +3399,1156 @@ Done. Added ${totalChanges} correction action config(s) across ${modifiedFiles.l
|
|
|
3287
3399
|
);
|
|
3288
3400
|
}
|
|
3289
3401
|
|
|
3402
|
+
// src/migrations/v2.1/add-recovery-link-notifications.ts
|
|
3403
|
+
var import_ts_morph2 = require("ts-morph");
|
|
3404
|
+
var import_fs2 = require("fs");
|
|
3405
|
+
var import_path2 = __toESM(require("path"));
|
|
3406
|
+
|
|
3407
|
+
// src/csv.ts
|
|
3408
|
+
var import_fs = require("fs");
|
|
3409
|
+
function parseCsvLine(line2) {
|
|
3410
|
+
const values = [];
|
|
3411
|
+
let value = "";
|
|
3412
|
+
let quoted = false;
|
|
3413
|
+
for (let index = 0; index < line2.length; index++) {
|
|
3414
|
+
const character = line2[index];
|
|
3415
|
+
if (quoted) {
|
|
3416
|
+
if (character !== '"') {
|
|
3417
|
+
value += character;
|
|
3418
|
+
} else if (line2[index + 1] === '"') {
|
|
3419
|
+
value += '"';
|
|
3420
|
+
index++;
|
|
3421
|
+
} else {
|
|
3422
|
+
quoted = false;
|
|
3423
|
+
}
|
|
3424
|
+
continue;
|
|
3425
|
+
}
|
|
3426
|
+
if (character === '"') {
|
|
3427
|
+
quoted = true;
|
|
3428
|
+
} else if (character === ",") {
|
|
3429
|
+
values.push(value);
|
|
3430
|
+
value = "";
|
|
3431
|
+
} else {
|
|
3432
|
+
value += character;
|
|
3433
|
+
}
|
|
3434
|
+
}
|
|
3435
|
+
values.push(value);
|
|
3436
|
+
return values;
|
|
3437
|
+
}
|
|
3438
|
+
function toCsvLine(values) {
|
|
3439
|
+
return values.map(
|
|
3440
|
+
(value) => /["\n,]/.test(value) ? `"${value.replace(/"/g, '""')}"` : value
|
|
3441
|
+
).join(",");
|
|
3442
|
+
}
|
|
3443
|
+
function idOf(line2) {
|
|
3444
|
+
const comma = line2.indexOf(",");
|
|
3445
|
+
return comma === -1 ? line2 : line2.slice(0, comma);
|
|
3446
|
+
}
|
|
3447
|
+
function readCsvFile(path10) {
|
|
3448
|
+
if (!(0, import_fs.existsSync)(path10)) {
|
|
3449
|
+
return void 0;
|
|
3450
|
+
}
|
|
3451
|
+
const contents = (0, import_fs.readFileSync)(path10, "utf8");
|
|
3452
|
+
const newline = contents.includes("\r\n") ? "\r\n" : "\n";
|
|
3453
|
+
const trailingNewline = /\r?\n$/.test(contents);
|
|
3454
|
+
const lines = contents.replace(/\r?\n$/, "").split(/\r?\n/);
|
|
3455
|
+
const body = lines.slice(1).filter((line2) => line2 !== "");
|
|
3456
|
+
return { header: lines[0], body, newline, trailingNewline };
|
|
3457
|
+
}
|
|
3458
|
+
function writeCsvFile(path10, file) {
|
|
3459
|
+
(0, import_fs.writeFileSync)(
|
|
3460
|
+
path10,
|
|
3461
|
+
[file.header, ...file.body].join(file.newline) + (file.trailingNewline ? file.newline : "")
|
|
3462
|
+
);
|
|
3463
|
+
}
|
|
3464
|
+
function addRows(file, rows) {
|
|
3465
|
+
const isSorted = file.body.every(
|
|
3466
|
+
(line2, index) => index === 0 || idOf(file.body[index - 1]) <= idOf(line2)
|
|
3467
|
+
);
|
|
3468
|
+
const added = [];
|
|
3469
|
+
for (const row of rows) {
|
|
3470
|
+
const id = idOf(row);
|
|
3471
|
+
if (file.body.some((line2) => idOf(line2) === id)) {
|
|
3472
|
+
continue;
|
|
3473
|
+
}
|
|
3474
|
+
const insertAt = isSorted ? file.body.findIndex((line2) => idOf(line2) > id) : -1;
|
|
3475
|
+
if (insertAt === -1) {
|
|
3476
|
+
file.body.push(row);
|
|
3477
|
+
} else {
|
|
3478
|
+
file.body.splice(insertAt, 0, row);
|
|
3479
|
+
}
|
|
3480
|
+
added.push(id);
|
|
3481
|
+
}
|
|
3482
|
+
return added;
|
|
3483
|
+
}
|
|
3484
|
+
|
|
3485
|
+
// src/migrations/v2.1/add-recovery-link-notifications.ts
|
|
3486
|
+
var EMAIL_TEMPLATES_FILE = "src/api/notification/email-templates/index.ts";
|
|
3487
|
+
var SMS_SERVICE_FILE = "src/api/notification/sms-service.ts";
|
|
3488
|
+
var HANDLER_FILE = "src/api/notification/handler.ts";
|
|
3489
|
+
var ROUTES_FILE = "src/config/routes/userNotificationRoutes.ts";
|
|
3490
|
+
var EMAIL_TEMPLATE_DIR = "src/api/notification/email-templates/other";
|
|
3491
|
+
var NOTIFICATION_CSV = "src/translations/notification.csv";
|
|
3492
|
+
var LOGIN_CSV = "src/translations/login.csv";
|
|
3493
|
+
var TRIGGER_VARIABLE_OBJECT = "TriggerVariable";
|
|
3494
|
+
var TEMPLATES_OBJECT = "templates";
|
|
3495
|
+
var OTHER_TEMPLATES_OBJECT = "otherTemplates";
|
|
3496
|
+
var TRIGGER_TO_SMS_TEMPLATE_OBJECT = "TriggerToSMSTemplate";
|
|
3497
|
+
var CONVERT_PAYLOAD_FUNCTION = "convertPayloadToVariable";
|
|
3498
|
+
var ROUTES_FUNCTION = "getUserNotificationRoutes";
|
|
3499
|
+
var RECOVERY_EVENTS = [
|
|
3500
|
+
{
|
|
3501
|
+
id: "password-reset-link",
|
|
3502
|
+
constant: "PASSWORD_RESET_LINK",
|
|
3503
|
+
smsTemplate: "resetPasswordLinkNotification",
|
|
3504
|
+
emailSubject: "Reset your password",
|
|
3505
|
+
routeDescription: "Handles notification for password reset recovery link",
|
|
3506
|
+
heading: "Reset your password",
|
|
3507
|
+
reason: "Someone asked to reset the password for your {{applicationName}}\n account.",
|
|
3508
|
+
linkLabel: "Reset your password"
|
|
3509
|
+
},
|
|
3510
|
+
{
|
|
3511
|
+
id: "username-reminder-link",
|
|
3512
|
+
constant: "USERNAME_REMINDER_LINK",
|
|
3513
|
+
smsTemplate: "retrieveUsernameLinkNotification",
|
|
3514
|
+
emailSubject: "Retrieve your username",
|
|
3515
|
+
routeDescription: "Handles notification for username reminder recovery link",
|
|
3516
|
+
heading: "Retrieve your username",
|
|
3517
|
+
reason: "Someone asked for a reminder of the username for your\n {{applicationName}} account.",
|
|
3518
|
+
linkLabel: "Retrieve your username"
|
|
3519
|
+
}
|
|
3520
|
+
];
|
|
3521
|
+
var NOTIFICATION_CSV_ROWS = [
|
|
3522
|
+
`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}}}`,
|
|
3523
|
+
`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}}}`
|
|
3524
|
+
];
|
|
3525
|
+
var LOGIN_CSV_ROWS = [
|
|
3526
|
+
`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`,
|
|
3527
|
+
`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."`,
|
|
3528
|
+
`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`,
|
|
3529
|
+
`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`,
|
|
3530
|
+
`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.`,
|
|
3531
|
+
`resetCredentials.recoveryLinkLanding.expired.link,Link back to the forgotten item form shown on an expired/invalid recovery link,Start again,Recommencer`,
|
|
3532
|
+
`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`
|
|
3533
|
+
];
|
|
3534
|
+
var skipped = [];
|
|
3535
|
+
function warnSkipped(message) {
|
|
3536
|
+
skipped.push(message);
|
|
3537
|
+
console.warn(` \u26A0\uFE0F ${message}`);
|
|
3538
|
+
}
|
|
3539
|
+
function findObjectLiteral(declaration) {
|
|
3540
|
+
let expression = declaration?.getInitializer();
|
|
3541
|
+
while (expression && (import_ts_morph2.Node.isAsExpression(expression) || import_ts_morph2.Node.isSatisfiesExpression(expression))) {
|
|
3542
|
+
expression = expression.getExpression();
|
|
3543
|
+
}
|
|
3544
|
+
return expression && import_ts_morph2.Node.isObjectLiteralExpression(expression) ? expression : void 0;
|
|
3545
|
+
}
|
|
3546
|
+
function hasKeyFor(obj, key, constant) {
|
|
3547
|
+
const accepted = /* @__PURE__ */ new Set([
|
|
3548
|
+
`[TriggerEvent.${constant}]`,
|
|
3549
|
+
`['${key}']`,
|
|
3550
|
+
`["${key}"]`,
|
|
3551
|
+
`'${key}'`,
|
|
3552
|
+
`"${key}"`,
|
|
3553
|
+
key
|
|
3554
|
+
]);
|
|
3555
|
+
return obj.getProperties().some(
|
|
3556
|
+
(property) => import_ts_morph2.Node.isPropertyAssignment(property) && accepted.has(property.getName().trim())
|
|
3557
|
+
);
|
|
3558
|
+
}
|
|
3559
|
+
function renderKey(obj, key, constant) {
|
|
3560
|
+
const names = obj.getProperties().filter(import_ts_morph2.Node.isPropertyAssignment).map((property) => property.getName().trim());
|
|
3561
|
+
if (names.some((name) => name.startsWith("[TriggerEvent."))) {
|
|
3562
|
+
return `[TriggerEvent.${constant}]`;
|
|
3563
|
+
}
|
|
3564
|
+
if (names.some((name) => name.startsWith("["))) {
|
|
3565
|
+
return `['${key}']`;
|
|
3566
|
+
}
|
|
3567
|
+
return `'${key}'`;
|
|
3568
|
+
}
|
|
3569
|
+
function appendEntry(sourceFile, objectName, key, valueLines) {
|
|
3570
|
+
const obj = findObjectLiteral(sourceFile.getVariableDeclaration(objectName));
|
|
3571
|
+
const properties = obj?.getProperties() ?? [];
|
|
3572
|
+
const lastProperty = properties[properties.length - 1];
|
|
3573
|
+
if (!lastProperty) return false;
|
|
3574
|
+
const indent = lastProperty.getIndentationText();
|
|
3575
|
+
const entry = valueLines.map((line2, index) => `${indent}${index === 0 ? `${key}: ${line2}` : line2}`).join("\n");
|
|
3576
|
+
sourceFile.insertText(lastProperty.getEnd(), `,
|
|
3577
|
+
${entry}`);
|
|
3578
|
+
return true;
|
|
3579
|
+
}
|
|
3580
|
+
function objectHasKeyFor(sourceFile, objectName, key, constant) {
|
|
3581
|
+
const obj = findObjectLiteral(sourceFile.getVariableDeclaration(objectName));
|
|
3582
|
+
return obj ? hasKeyFor(obj, key, constant) : false;
|
|
3583
|
+
}
|
|
3584
|
+
function renderKeyFor(sourceFile, objectName, key, constant) {
|
|
3585
|
+
const obj = findObjectLiteral(sourceFile.getVariableDeclaration(objectName));
|
|
3586
|
+
return obj ? renderKey(obj, key, constant) : `'${key}'`;
|
|
3587
|
+
}
|
|
3588
|
+
function updateEmailTemplates(project, cwd) {
|
|
3589
|
+
const sourceFile = project.getSourceFile(import_path2.default.join(cwd, EMAIL_TEMPLATES_FILE));
|
|
3590
|
+
if (!sourceFile) {
|
|
3591
|
+
warnSkipped(`${EMAIL_TEMPLATES_FILE} not found; email templates not wired`);
|
|
3592
|
+
return;
|
|
3593
|
+
}
|
|
3594
|
+
const missingObject = [TRIGGER_VARIABLE_OBJECT, TEMPLATES_OBJECT].find(
|
|
3595
|
+
(objectName) => !findObjectLiteral(sourceFile.getVariableDeclaration(objectName))
|
|
3596
|
+
);
|
|
3597
|
+
if (missingObject) {
|
|
3598
|
+
warnSkipped(
|
|
3599
|
+
`Could not find '${missingObject}' in ${EMAIL_TEMPLATES_FILE}; email templates not wired`
|
|
3600
|
+
);
|
|
3601
|
+
return;
|
|
3602
|
+
}
|
|
3603
|
+
for (const event of RECOVERY_EVENTS) {
|
|
3604
|
+
if (!objectHasKeyFor(
|
|
3605
|
+
sourceFile,
|
|
3606
|
+
TRIGGER_VARIABLE_OBJECT,
|
|
3607
|
+
event.id,
|
|
3608
|
+
event.constant
|
|
3609
|
+
) && appendEntry(
|
|
3610
|
+
sourceFile,
|
|
3611
|
+
TRIGGER_VARIABLE_OBJECT,
|
|
3612
|
+
renderKeyFor(
|
|
3613
|
+
sourceFile,
|
|
3614
|
+
TRIGGER_VARIABLE_OBJECT,
|
|
3615
|
+
event.id,
|
|
3616
|
+
event.constant
|
|
3617
|
+
),
|
|
3618
|
+
[
|
|
3619
|
+
"z.object({",
|
|
3620
|
+
" firstname: z.string(),",
|
|
3621
|
+
" applicationName: z.string(),",
|
|
3622
|
+
" countryLogo: z.string(),",
|
|
3623
|
+
" recoveryURL: z.string()",
|
|
3624
|
+
"})"
|
|
3625
|
+
]
|
|
3626
|
+
)) {
|
|
3627
|
+
console.log(` \u2713 ${EMAIL_TEMPLATES_FILE}: ${event.id} variables`);
|
|
3628
|
+
}
|
|
3629
|
+
if (!objectHasKeyFor(
|
|
3630
|
+
sourceFile,
|
|
3631
|
+
TEMPLATES_OBJECT,
|
|
3632
|
+
event.id,
|
|
3633
|
+
event.constant
|
|
3634
|
+
) && appendEntry(
|
|
3635
|
+
sourceFile,
|
|
3636
|
+
TEMPLATES_OBJECT,
|
|
3637
|
+
renderKeyFor(sourceFile, TEMPLATES_OBJECT, event.id, event.constant),
|
|
3638
|
+
[
|
|
3639
|
+
"{",
|
|
3640
|
+
` type: '${event.id}',`,
|
|
3641
|
+
` subject: '${event.emailSubject}',`,
|
|
3642
|
+
` template: readOtherTemplate<TriggerVariable['${event.id}']>(`,
|
|
3643
|
+
` '${event.id}'`,
|
|
3644
|
+
" )",
|
|
3645
|
+
"}"
|
|
3646
|
+
]
|
|
3647
|
+
)) {
|
|
3648
|
+
console.log(` \u2713 ${EMAIL_TEMPLATES_FILE}: ${event.id} template`);
|
|
3649
|
+
}
|
|
3650
|
+
}
|
|
3651
|
+
}
|
|
3652
|
+
function updateSmsService(project, cwd) {
|
|
3653
|
+
const sourceFile = project.getSourceFile(import_path2.default.join(cwd, SMS_SERVICE_FILE));
|
|
3654
|
+
if (!sourceFile) {
|
|
3655
|
+
warnSkipped(`${SMS_SERVICE_FILE} not found; SMS templates not wired`);
|
|
3656
|
+
return;
|
|
3657
|
+
}
|
|
3658
|
+
const missingObject = [
|
|
3659
|
+
OTHER_TEMPLATES_OBJECT,
|
|
3660
|
+
TRIGGER_TO_SMS_TEMPLATE_OBJECT
|
|
3661
|
+
].find(
|
|
3662
|
+
(objectName) => !findObjectLiteral(sourceFile.getVariableDeclaration(objectName))
|
|
3663
|
+
);
|
|
3664
|
+
if (missingObject) {
|
|
3665
|
+
warnSkipped(
|
|
3666
|
+
`Could not find '${missingObject}' in ${SMS_SERVICE_FILE}; SMS templates not wired`
|
|
3667
|
+
);
|
|
3668
|
+
return;
|
|
3669
|
+
}
|
|
3670
|
+
for (const event of RECOVERY_EVENTS) {
|
|
3671
|
+
if (!objectHasKeyFor(
|
|
3672
|
+
sourceFile,
|
|
3673
|
+
OTHER_TEMPLATES_OBJECT,
|
|
3674
|
+
event.smsTemplate,
|
|
3675
|
+
event.smsTemplate
|
|
3676
|
+
) && appendEntry(sourceFile, OTHER_TEMPLATES_OBJECT, event.smsTemplate, [
|
|
3677
|
+
`'${event.smsTemplate}'`
|
|
3678
|
+
])) {
|
|
3679
|
+
console.log(` \u2713 ${SMS_SERVICE_FILE}: ${event.smsTemplate}`);
|
|
3680
|
+
}
|
|
3681
|
+
if (!objectHasKeyFor(
|
|
3682
|
+
sourceFile,
|
|
3683
|
+
TRIGGER_TO_SMS_TEMPLATE_OBJECT,
|
|
3684
|
+
event.id,
|
|
3685
|
+
event.constant
|
|
3686
|
+
) && appendEntry(
|
|
3687
|
+
sourceFile,
|
|
3688
|
+
TRIGGER_TO_SMS_TEMPLATE_OBJECT,
|
|
3689
|
+
renderKeyFor(
|
|
3690
|
+
sourceFile,
|
|
3691
|
+
TRIGGER_TO_SMS_TEMPLATE_OBJECT,
|
|
3692
|
+
event.id,
|
|
3693
|
+
event.constant
|
|
3694
|
+
),
|
|
3695
|
+
[`'${event.smsTemplate}'`]
|
|
3696
|
+
)) {
|
|
3697
|
+
console.log(
|
|
3698
|
+
` \u2713 ${SMS_SERVICE_FILE}: ${event.id} -> ${event.smsTemplate}`
|
|
3699
|
+
);
|
|
3700
|
+
}
|
|
3701
|
+
}
|
|
3702
|
+
}
|
|
3703
|
+
function updateHandler(project, cwd) {
|
|
3704
|
+
const sourceFile = project.getSourceFile(import_path2.default.join(cwd, HANDLER_FILE));
|
|
3705
|
+
if (!sourceFile) {
|
|
3706
|
+
warnSkipped(`${HANDLER_FILE} not found; payload conversion not wired`);
|
|
3707
|
+
return;
|
|
3708
|
+
}
|
|
3709
|
+
const convertPayload = sourceFile.getFunction(CONVERT_PAYLOAD_FUNCTION);
|
|
3710
|
+
const caseBlock = convertPayload?.getFirstDescendantByKind(import_ts_morph2.SyntaxKind.SwitchStatement)?.getCaseBlock();
|
|
3711
|
+
if (!caseBlock) {
|
|
3712
|
+
warnSkipped(
|
|
3713
|
+
`Could not find a switch inside '${CONVERT_PAYLOAD_FUNCTION}' in ${HANDLER_FILE}; payload conversion not wired`
|
|
3714
|
+
);
|
|
3715
|
+
return;
|
|
3716
|
+
}
|
|
3717
|
+
const missing = RECOVERY_EVENTS.filter(
|
|
3718
|
+
(event) => !caseBlock.getText().includes(`TriggerEvent.${event.constant}`) && !caseBlock.getText().includes(`'${event.id}'`)
|
|
3719
|
+
);
|
|
3720
|
+
if (missing.length === 0) return;
|
|
3721
|
+
const existingClauses = caseBlock.getClauses();
|
|
3722
|
+
if (existingClauses.length === 0) {
|
|
3723
|
+
warnSkipped(
|
|
3724
|
+
`The switch inside '${CONVERT_PAYLOAD_FUNCTION}' in ${HANDLER_FILE} has no cases; payload conversion not wired`
|
|
3725
|
+
);
|
|
3726
|
+
return;
|
|
3727
|
+
}
|
|
3728
|
+
const defaultClause = existingClauses.find(import_ts_morph2.Node.isDefaultClause);
|
|
3729
|
+
const anchor = defaultClause ?? existingClauses[existingClauses.length - 1];
|
|
3730
|
+
const indent = anchor.getIndentationText();
|
|
3731
|
+
const lines = [
|
|
3732
|
+
...missing.map((event) => `case TriggerEvent.${event.constant}:`),
|
|
3733
|
+
` return {`,
|
|
3734
|
+
` firstname,`,
|
|
3735
|
+
` applicationName: applicationConfig.APPLICATION_NAME,`,
|
|
3736
|
+
` countryLogo: COUNTRY_LOGO_URL,`,
|
|
3737
|
+
` recoveryURL: \`\${LOGIN_URL}recover?token=\${encodeURIComponent(payload.token)}\``,
|
|
3738
|
+
` }`
|
|
3739
|
+
];
|
|
3740
|
+
if (defaultClause) {
|
|
3741
|
+
caseBlock.insertText(
|
|
3742
|
+
anchor.getStart(),
|
|
3743
|
+
`${lines.map((line2, index) => index === 0 ? line2 : `${indent}${line2}`).join("\n")}
|
|
3744
|
+
${indent}`
|
|
3745
|
+
);
|
|
3746
|
+
} else {
|
|
3747
|
+
caseBlock.insertText(
|
|
3748
|
+
anchor.getEnd(),
|
|
3749
|
+
`
|
|
3750
|
+
${lines.map((line2) => `${indent}${line2}`).join("\n")}`
|
|
3751
|
+
);
|
|
3752
|
+
}
|
|
3753
|
+
for (const event of missing) {
|
|
3754
|
+
console.log(` \u2713 ${HANDLER_FILE}: ${event.id} case`);
|
|
3755
|
+
}
|
|
3756
|
+
}
|
|
3757
|
+
function updateRoutes(project, cwd) {
|
|
3758
|
+
const sourceFile = project.getSourceFile(import_path2.default.join(cwd, ROUTES_FILE));
|
|
3759
|
+
if (!sourceFile) {
|
|
3760
|
+
warnSkipped(`${ROUTES_FILE} not found; trigger routes not registered`);
|
|
3761
|
+
return;
|
|
3762
|
+
}
|
|
3763
|
+
const routesFunction = sourceFile.getFunction(ROUTES_FUNCTION) ?? sourceFile.getFunctions().find((fn) => fn.isDefaultExport());
|
|
3764
|
+
const routesArray = routesFunction?.getFirstDescendantByKind(import_ts_morph2.SyntaxKind.ReturnStatement)?.getExpressionIfKind(import_ts_morph2.SyntaxKind.ArrayLiteralExpression);
|
|
3765
|
+
if (!routesArray) {
|
|
3766
|
+
warnSkipped(
|
|
3767
|
+
`Could not find the route array returned by '${ROUTES_FUNCTION}' in ${ROUTES_FILE}; trigger routes not registered`
|
|
3768
|
+
);
|
|
3769
|
+
return;
|
|
3770
|
+
}
|
|
3771
|
+
for (const event of RECOVERY_EVENTS) {
|
|
3772
|
+
if (routesArray.getText().includes(`/triggers/user/${event.id}`)) continue;
|
|
3773
|
+
routesArray.addElement(`{
|
|
3774
|
+
method: 'POST',
|
|
3775
|
+
path: '/triggers/user/${event.id}',
|
|
3776
|
+
handler: makeNotificationHandler('${event.id}'),
|
|
3777
|
+
options: {
|
|
3778
|
+
auth: false,
|
|
3779
|
+
tags: ['api'],
|
|
3780
|
+
description: '${event.routeDescription}'
|
|
3781
|
+
}
|
|
3782
|
+
}`);
|
|
3783
|
+
console.log(` \u2713 ${ROUTES_FILE}: POST /triggers/user/${event.id}`);
|
|
3784
|
+
}
|
|
3785
|
+
}
|
|
3786
|
+
function renderEmailTemplate(event) {
|
|
3787
|
+
return `<!--
|
|
3788
|
+
This Source Code Form is subject to the terms of the Mozilla Public
|
|
3789
|
+
License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
3790
|
+
file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
3791
|
+
|
|
3792
|
+
OpenCRVS is also distributed under the terms of the Civil Registration
|
|
3793
|
+
& Healthcare Disclaimer located at http://opencrvs.org/license.
|
|
3794
|
+
|
|
3795
|
+
Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
|
|
3796
|
+
-->
|
|
3797
|
+
<!doctype html>
|
|
3798
|
+
<html>
|
|
3799
|
+
<head>
|
|
3800
|
+
<link
|
|
3801
|
+
href="https://fonts.googleapis.com/css2?family=Noto+Sans:wght@400;700&display=swap"
|
|
3802
|
+
rel="stylesheet"
|
|
3803
|
+
/>
|
|
3804
|
+
<style type="text/css">
|
|
3805
|
+
body {
|
|
3806
|
+
font-family: 'Noto Sans', sans-serif;
|
|
3807
|
+
color: #222;
|
|
3808
|
+
padding: 16px 24px;
|
|
3809
|
+
}
|
|
3810
|
+
|
|
3811
|
+
h1 {
|
|
3812
|
+
font-size: 21px;
|
|
3813
|
+
margin-top: 32px;
|
|
3814
|
+
margin-bottom: 36px;
|
|
3815
|
+
font-weight: 700;
|
|
3816
|
+
}
|
|
3817
|
+
|
|
3818
|
+
p {
|
|
3819
|
+
font-weight: 400;
|
|
3820
|
+
font-size: 16px;
|
|
3821
|
+
line-height: 1.8;
|
|
3822
|
+
margin-bottom: 24px;
|
|
3823
|
+
}
|
|
3824
|
+
|
|
3825
|
+
i {
|
|
3826
|
+
color: #666;
|
|
3827
|
+
font-weight: 400;
|
|
3828
|
+
font-size: 16px;
|
|
3829
|
+
}
|
|
3830
|
+
</style>
|
|
3831
|
+
</head>
|
|
3832
|
+
|
|
3833
|
+
<body>
|
|
3834
|
+
<img
|
|
3835
|
+
src="{{countryLogo}}"
|
|
3836
|
+
alt="country_logo"
|
|
3837
|
+
style="max-height: 88px; max-width: 100%"
|
|
3838
|
+
/>
|
|
3839
|
+
<h1>${event.heading}</h1>
|
|
3840
|
+
<p>Hello {{firstname}},</p>
|
|
3841
|
+
<p>
|
|
3842
|
+
${event.reason}
|
|
3843
|
+
</p>
|
|
3844
|
+
|
|
3845
|
+
<div style="margin-top: 32px; margin-bottom: 32px">
|
|
3846
|
+
<a href="{{{recoveryURL}}}">${event.linkLabel}</a>
|
|
3847
|
+
</div>
|
|
3848
|
+
<br />
|
|
3849
|
+
<p>
|
|
3850
|
+
This link expires in 1 hour and can only be used once. If you did not
|
|
3851
|
+
request this, you can ignore this email.
|
|
3852
|
+
</p>
|
|
3853
|
+
<br />
|
|
3854
|
+
<p>
|
|
3855
|
+
Best regards, <br />
|
|
3856
|
+
{{applicationName}} Team
|
|
3857
|
+
</p>
|
|
3858
|
+
</body>
|
|
3859
|
+
</html>
|
|
3860
|
+
`;
|
|
3861
|
+
}
|
|
3862
|
+
function writeEmailTemplates(cwd) {
|
|
3863
|
+
const templateDir = import_path2.default.join(cwd, EMAIL_TEMPLATE_DIR);
|
|
3864
|
+
if (!(0, import_fs2.existsSync)(templateDir)) {
|
|
3865
|
+
warnSkipped(
|
|
3866
|
+
`${EMAIL_TEMPLATE_DIR} not found; recovery email bodies not written`
|
|
3867
|
+
);
|
|
3868
|
+
return;
|
|
3869
|
+
}
|
|
3870
|
+
for (const event of RECOVERY_EVENTS) {
|
|
3871
|
+
const templatePath = import_path2.default.join(templateDir, `${event.id}.html`);
|
|
3872
|
+
if ((0, import_fs2.existsSync)(templatePath)) continue;
|
|
3873
|
+
(0, import_fs2.writeFileSync)(templatePath, renderEmailTemplate(event));
|
|
3874
|
+
console.log(` \u2713 ${EMAIL_TEMPLATE_DIR}/${event.id}.html`);
|
|
3875
|
+
}
|
|
3876
|
+
}
|
|
3877
|
+
function addCsvRows(cwd, relativePath, rows) {
|
|
3878
|
+
const csvPath = import_path2.default.join(cwd, relativePath);
|
|
3879
|
+
const file = readCsvFile(csvPath);
|
|
3880
|
+
if (!file) {
|
|
3881
|
+
warnSkipped(`${relativePath} not found; translations not added`);
|
|
3882
|
+
return;
|
|
3883
|
+
}
|
|
3884
|
+
const added = addRows(file, rows);
|
|
3885
|
+
if (added.length === 0) return;
|
|
3886
|
+
for (const id of added) {
|
|
3887
|
+
console.log(` \u2713 ${relativePath}: ${id}`);
|
|
3888
|
+
}
|
|
3889
|
+
writeCsvFile(csvPath, file);
|
|
3890
|
+
}
|
|
3891
|
+
async function main2() {
|
|
3892
|
+
const cwd = process.cwd();
|
|
3893
|
+
const tsConfigFilePath = import_path2.default.join(cwd, "tsconfig.json");
|
|
3894
|
+
console.log(
|
|
3895
|
+
"Registering the password-reset-link and username-reminder-link notifications...\n"
|
|
3896
|
+
);
|
|
3897
|
+
if (!(0, import_fs2.existsSync)(tsConfigFilePath)) {
|
|
3898
|
+
warnSkipped(
|
|
3899
|
+
`tsconfig.json not found in ${cwd}; notification wiring skipped entirely`
|
|
3900
|
+
);
|
|
3901
|
+
return;
|
|
3902
|
+
}
|
|
3903
|
+
const project = new import_ts_morph2.Project({
|
|
3904
|
+
tsConfigFilePath,
|
|
3905
|
+
skipAddingFilesFromTsConfig: false,
|
|
3906
|
+
// ts-morph indents inserted code with four spaces by default, which every
|
|
3907
|
+
// country config's prettier run would immediately undo.
|
|
3908
|
+
manipulationSettings: { indentationText: import_ts_morph2.IndentationText.TwoSpaces }
|
|
3909
|
+
});
|
|
3910
|
+
updateEmailTemplates(project, cwd);
|
|
3911
|
+
updateSmsService(project, cwd);
|
|
3912
|
+
updateHandler(project, cwd);
|
|
3913
|
+
updateRoutes(project, cwd);
|
|
3914
|
+
await project.save();
|
|
3915
|
+
writeEmailTemplates(cwd);
|
|
3916
|
+
addCsvRows(cwd, NOTIFICATION_CSV, NOTIFICATION_CSV_ROWS);
|
|
3917
|
+
addCsvRows(cwd, LOGIN_CSV, LOGIN_CSV_ROWS);
|
|
3918
|
+
if (skipped.length > 0) {
|
|
3919
|
+
console.warn(
|
|
3920
|
+
`
|
|
3921
|
+
\u26A0\uFE0F ${skipped.length} step(s) were skipped. Wire the following by hand before upgrading:`
|
|
3922
|
+
);
|
|
3923
|
+
for (const message of skipped) {
|
|
3924
|
+
console.warn(` - ${message}`);
|
|
3925
|
+
}
|
|
3926
|
+
}
|
|
3927
|
+
}
|
|
3928
|
+
|
|
3929
|
+
// src/migrations/v2.1/add-translations.ts
|
|
3930
|
+
var import_path3 = __toESM(require("path"));
|
|
3931
|
+
var REPOSITORY = "opencrvs/opencrvs-core";
|
|
3932
|
+
var TEMPLATE_TRANSLATIONS = "packages/countryconfig-template/src/translations";
|
|
3933
|
+
var APPLICATIONS = ["client", "login"];
|
|
3934
|
+
var TARGET_VERSION = "2.1";
|
|
3935
|
+
var skipped2 = [];
|
|
3936
|
+
function warnSkipped2(message) {
|
|
3937
|
+
skipped2.push(message);
|
|
3938
|
+
console.warn(` \u26A0\uFE0F ${message}`);
|
|
3939
|
+
}
|
|
3940
|
+
async function matchingRefs(namespace, prefix) {
|
|
3941
|
+
const url = `https://api.github.com/repos/${REPOSITORY}/git/matching-refs/${namespace}/${prefix}`;
|
|
3942
|
+
const response = await fetch(url, {
|
|
3943
|
+
headers: { accept: "application/vnd.github+json" }
|
|
3944
|
+
});
|
|
3945
|
+
if (!response.ok) {
|
|
3946
|
+
throw new Error(
|
|
3947
|
+
`GitHub answered ${response.status} ${response.statusText} for ${url}`
|
|
3948
|
+
);
|
|
3949
|
+
}
|
|
3950
|
+
const refs = await response.json();
|
|
3951
|
+
const patchOf = (ref) => Number(ref.split(".").pop()) || 0;
|
|
3952
|
+
return refs.map(({ ref }) => ref.replace(/^refs\/(heads|tags)\//, "")).sort((a, b) => patchOf(b) - patchOf(a));
|
|
3953
|
+
}
|
|
3954
|
+
async function candidateRefs() {
|
|
3955
|
+
return [
|
|
3956
|
+
...await matchingRefs("heads", `release/${TARGET_VERSION}.`),
|
|
3957
|
+
...await matchingRefs("tags", `v${TARGET_VERSION}.`),
|
|
3958
|
+
"develop"
|
|
3959
|
+
];
|
|
3960
|
+
}
|
|
3961
|
+
async function fetchTemplate(refs, application) {
|
|
3962
|
+
for (const ref of refs) {
|
|
3963
|
+
const url = `https://raw.githubusercontent.com/${REPOSITORY}/${ref}/${TEMPLATE_TRANSLATIONS}/${application}.csv`;
|
|
3964
|
+
const response = await fetch(url);
|
|
3965
|
+
if (response.ok) {
|
|
3966
|
+
return { ref, contents: await response.text() };
|
|
3967
|
+
}
|
|
3968
|
+
if (response.status !== 404) {
|
|
3969
|
+
throw new Error(
|
|
3970
|
+
`GitHub answered ${response.status} ${response.statusText} for ${url}`
|
|
3971
|
+
);
|
|
3972
|
+
}
|
|
3973
|
+
}
|
|
3974
|
+
warnSkipped2(
|
|
3975
|
+
`No ${application}.csv found in the ${TARGET_VERSION} country config template on GitHub; ${application}.csv not updated`
|
|
3976
|
+
);
|
|
3977
|
+
return void 0;
|
|
3978
|
+
}
|
|
3979
|
+
function rowsToAdd(local, template) {
|
|
3980
|
+
const localColumns = parseCsvLine(local.header);
|
|
3981
|
+
const templateColumns = parseCsvLine(template.header);
|
|
3982
|
+
return template.body.filter((line2) => line2 !== "").map((line2) => {
|
|
3983
|
+
const values = parseCsvLine(line2);
|
|
3984
|
+
return toCsvLine(
|
|
3985
|
+
localColumns.map((column) => {
|
|
3986
|
+
const index = templateColumns.indexOf(column);
|
|
3987
|
+
return index === -1 ? "" : values[index] ?? "";
|
|
3988
|
+
})
|
|
3989
|
+
);
|
|
3990
|
+
});
|
|
3991
|
+
}
|
|
3992
|
+
async function updateApplication(cwd, refs, application) {
|
|
3993
|
+
const relativePath = `src/translations/${application}.csv`;
|
|
3994
|
+
const local = readCsvFile(import_path3.default.join(cwd, relativePath));
|
|
3995
|
+
if (!local) {
|
|
3996
|
+
warnSkipped2(`${relativePath} not found; translations not added`);
|
|
3997
|
+
return;
|
|
3998
|
+
}
|
|
3999
|
+
const fetched = await fetchTemplate(refs, application);
|
|
4000
|
+
if (!fetched) {
|
|
4001
|
+
return;
|
|
4002
|
+
}
|
|
4003
|
+
const template = readTemplate(fetched.contents);
|
|
4004
|
+
const added = addRows(local, rowsToAdd(local, template));
|
|
4005
|
+
if (added.length === 0) {
|
|
4006
|
+
return;
|
|
4007
|
+
}
|
|
4008
|
+
try {
|
|
4009
|
+
writeCsvFile(import_path3.default.join(cwd, relativePath), local);
|
|
4010
|
+
} catch (error3) {
|
|
4011
|
+
warnSkipped2(
|
|
4012
|
+
`Could not write ${relativePath} (${error3.message}); translations not added`
|
|
4013
|
+
);
|
|
4014
|
+
return;
|
|
4015
|
+
}
|
|
4016
|
+
for (const id of added) {
|
|
4017
|
+
console.log(` \u2713 ${relativePath}: ${id}`);
|
|
4018
|
+
}
|
|
4019
|
+
}
|
|
4020
|
+
function readTemplate(contents) {
|
|
4021
|
+
const lines = contents.replace(/\r?\n$/, "").split(/\r?\n/);
|
|
4022
|
+
return {
|
|
4023
|
+
header: lines[0],
|
|
4024
|
+
body: lines.slice(1),
|
|
4025
|
+
newline: "\n",
|
|
4026
|
+
trailingNewline: true
|
|
4027
|
+
};
|
|
4028
|
+
}
|
|
4029
|
+
async function listRefs() {
|
|
4030
|
+
try {
|
|
4031
|
+
return await candidateRefs();
|
|
4032
|
+
} catch (error3) {
|
|
4033
|
+
warnSkipped2(
|
|
4034
|
+
`Could not list the ${TARGET_VERSION} refs on GitHub (${error3.message}); translations not added`
|
|
4035
|
+
);
|
|
4036
|
+
return void 0;
|
|
4037
|
+
}
|
|
4038
|
+
}
|
|
4039
|
+
async function main3() {
|
|
4040
|
+
const cwd = process.cwd();
|
|
4041
|
+
console.log("Adding the translation keys core gained this version...\n");
|
|
4042
|
+
const refs = await listRefs();
|
|
4043
|
+
if (refs) {
|
|
4044
|
+
for (const application of APPLICATIONS) {
|
|
4045
|
+
try {
|
|
4046
|
+
await updateApplication(cwd, refs, application);
|
|
4047
|
+
} catch (error3) {
|
|
4048
|
+
warnSkipped2(
|
|
4049
|
+
`Could not read ${application}.csv from the country config template on GitHub (${error3.message}); ${application}.csv not updated`
|
|
4050
|
+
);
|
|
4051
|
+
}
|
|
4052
|
+
}
|
|
4053
|
+
}
|
|
4054
|
+
if (skipped2.length > 0) {
|
|
4055
|
+
console.warn(
|
|
4056
|
+
`
|
|
4057
|
+
\u26A0\uFE0F ${skipped2.length} step(s) were skipped. Add the missing translations by hand before upgrading:`
|
|
4058
|
+
);
|
|
4059
|
+
for (const message of skipped2) {
|
|
4060
|
+
console.warn(` - ${message}`);
|
|
4061
|
+
}
|
|
4062
|
+
}
|
|
4063
|
+
}
|
|
4064
|
+
|
|
4065
|
+
// src/migrations/v2.1/enable-telemetry.ts
|
|
4066
|
+
var import_ts_morph3 = require("ts-morph");
|
|
4067
|
+
var import_fs3 = require("fs");
|
|
4068
|
+
var import_path4 = __toESM(require("path"));
|
|
4069
|
+
var HANDLER_FILE2 = "src/api/telemetry/handler.ts";
|
|
4070
|
+
var ENVIRONMENT_FILE = "src/environment.ts";
|
|
4071
|
+
var INDEX_FILE = "src/index.ts";
|
|
4072
|
+
var HANDLER_MODULE = "./api/telemetry/handler";
|
|
4073
|
+
var skipped3 = [];
|
|
4074
|
+
function warnSkipped3(message) {
|
|
4075
|
+
skipped3.push(message);
|
|
4076
|
+
console.warn(` \u26A0\uFE0F ${message}`);
|
|
4077
|
+
}
|
|
4078
|
+
var TELEMETRY_HANDLER_SOURCE = `/*
|
|
4079
|
+
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
4080
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
4081
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
4082
|
+
*
|
|
4083
|
+
* OpenCRVS is also distributed under the terms of the Civil Registration
|
|
4084
|
+
* & Healthcare Disclaimer located at http://opencrvs.org/license.
|
|
4085
|
+
*
|
|
4086
|
+
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
|
|
4087
|
+
*/
|
|
4088
|
+
|
|
4089
|
+
import { Request, ResponseToolkit } from '@hapi/hapi'
|
|
4090
|
+
import * as Joi from 'joi'
|
|
4091
|
+
import { sendTelemetry, TelemetryReport } from '@opencrvs/toolkit/telemetry'
|
|
4092
|
+
import { env } from '@countryconfig/environment'
|
|
4093
|
+
import { logger } from '@countryconfig/logger'
|
|
4094
|
+
import { applicationConfig } from '@countryconfig/api/application/application-config'
|
|
4095
|
+
|
|
4096
|
+
/** Report the events service posts to \`/trigger/telemetry\`. */
|
|
4097
|
+
export const telemetrySchema = Joi.object({
|
|
4098
|
+
reported_at: Joi.string().isoDate().required(),
|
|
4099
|
+
app_version: Joi.string().optional(),
|
|
4100
|
+
metrics: Joi.object()
|
|
4101
|
+
.pattern(
|
|
4102
|
+
Joi.string(),
|
|
4103
|
+
Joi.alternatives(Joi.number(), Joi.string(), Joi.boolean())
|
|
4104
|
+
)
|
|
4105
|
+
.required()
|
|
4106
|
+
})
|
|
4107
|
+
|
|
4108
|
+
interface IncomingReport {
|
|
4109
|
+
reported_at: string
|
|
4110
|
+
app_version?: string
|
|
4111
|
+
metrics: Record<string, number | string | boolean>
|
|
4112
|
+
}
|
|
4113
|
+
|
|
4114
|
+
/** Logged once at countryconfig startup while telemetry is disabled. */
|
|
4115
|
+
export const TELEMETRY_DISABLED_NOTICE =
|
|
4116
|
+
'Telemetry is disabled. Help improve OpenCRVS by sharing anonymous, ' +
|
|
4117
|
+
'aggregate usage metrics (registration and certificate counts, active ' +
|
|
4118
|
+
'users, uptime) \u2014 no personal, health, or otherwise protected record data ' +
|
|
4119
|
+
'ever leaves your instance. Enable it by setting TELEMETRY_ENABLED=true on ' +
|
|
4120
|
+
'the countryconfig service.'
|
|
4121
|
+
|
|
4122
|
+
/**
|
|
4123
|
+
* Receives a usage report from the events service and, when telemetry is
|
|
4124
|
+
* enabled for this instance, stamps the instance identity onto it and forwards
|
|
4125
|
+
* it to the status service via the toolkit's \`sendTelemetry\` (which owns the
|
|
4126
|
+
* endpoint and payload schema). The events service is unaware of whether
|
|
4127
|
+
* telemetry is enabled or of the country code / domain / environment reported.
|
|
4128
|
+
*/
|
|
4129
|
+
export async function telemetryHandler(request: Request, h: ResponseToolkit) {
|
|
4130
|
+
// Only accept OpenCRVS *system* tokens (the events service's service
|
|
4131
|
+
// token has userType 'system'). A logged-in user's token is a 'user' token,
|
|
4132
|
+
// so a user cannot submit telemetry with their own credentials \u2014 and the
|
|
4133
|
+
// service-token endpoint is not reachable through the public gateway.
|
|
4134
|
+
const credentials = request.auth.credentials as
|
|
4135
|
+
| { userType?: string }
|
|
4136
|
+
| undefined
|
|
4137
|
+
if (credentials?.userType !== 'system') {
|
|
4138
|
+
logger.warn('Telemetry: rejected a request that is not from a system token')
|
|
4139
|
+
return h.response({ error: 'forbidden' }).code(403)
|
|
4140
|
+
}
|
|
4141
|
+
|
|
4142
|
+
if (!env.TELEMETRY_ENABLED) {
|
|
4143
|
+
// The encouraging notice is logged once at startup (see index.ts); keep the
|
|
4144
|
+
// per-report path quiet.
|
|
4145
|
+
return h.response({ status: 'skipped' }).code(200)
|
|
4146
|
+
}
|
|
4147
|
+
|
|
4148
|
+
const incoming = request.payload as IncomingReport
|
|
4149
|
+
|
|
4150
|
+
// Only production instances report; staging, QA and local build the report
|
|
4151
|
+
// but never reach the status service. (This gate used to live in the
|
|
4152
|
+
// toolkit's sendTelemetry; each country config now owns it.)
|
|
4153
|
+
if (!env.isProduction) {
|
|
4154
|
+
logger.info(
|
|
4155
|
+
\`Telemetry: report for \${incoming.reported_at} was not sent \u2014 only production instances report\`
|
|
4156
|
+
)
|
|
4157
|
+
return h.response({ status: 'skipped' }).code(200)
|
|
4158
|
+
}
|
|
4159
|
+
|
|
4160
|
+
const report: TelemetryReport = {
|
|
4161
|
+
reported_at: incoming.reported_at,
|
|
4162
|
+
country_code: env.COUNTRY_CODE,
|
|
4163
|
+
organisation: env.ORGANISATION,
|
|
4164
|
+
// env.DOMAIN defaults to a wildcard for CORS in some setups; treat that as
|
|
4165
|
+
// "no domain" rather than reporting a literal "*".
|
|
4166
|
+
domain: env.DOMAIN && env.DOMAIN !== '*' ? env.DOMAIN : null,
|
|
4167
|
+
instance: {
|
|
4168
|
+
application_name: applicationConfig.APPLICATION_NAME,
|
|
4169
|
+
environment: env.ENVIRONMENT_NAME,
|
|
4170
|
+
app_version: incoming.app_version
|
|
4171
|
+
},
|
|
4172
|
+
metrics: incoming.metrics
|
|
4173
|
+
}
|
|
4174
|
+
|
|
4175
|
+
let result
|
|
4176
|
+
try {
|
|
4177
|
+
result = await sendTelemetry(report)
|
|
4178
|
+
} catch (error) {
|
|
4179
|
+
const message = error instanceof Error ? error.message : String(error)
|
|
4180
|
+
logger.error(\`Telemetry: forwarding to status service failed: \${message}\`)
|
|
4181
|
+
return h.response({ status: 'error' }).code(502)
|
|
4182
|
+
}
|
|
4183
|
+
|
|
4184
|
+
if (result.outcome === 'rejected') {
|
|
4185
|
+
logger.error(
|
|
4186
|
+
\`Telemetry: status service rejected report (HTTP \${result.status}): \${result.detail ?? ''}\`
|
|
4187
|
+
)
|
|
4188
|
+
return h.response({ status: 'error' }).code(502)
|
|
4189
|
+
}
|
|
4190
|
+
|
|
4191
|
+
logger.info(
|
|
4192
|
+
\`Telemetry: forwarded report for \${report.reported_at} to the status service\`
|
|
4193
|
+
)
|
|
4194
|
+
return h.response({ status: 'forwarded' }).code(202)
|
|
4195
|
+
}
|
|
4196
|
+
`;
|
|
4197
|
+
var TELEMETRY_DISABLED = {
|
|
4198
|
+
enabled: false,
|
|
4199
|
+
countryCode: "",
|
|
4200
|
+
organisation: ""
|
|
4201
|
+
};
|
|
4202
|
+
async function promptTelemetryConfig() {
|
|
4203
|
+
if (!process.stdin.isTTY) {
|
|
4204
|
+
return TELEMETRY_DISABLED;
|
|
4205
|
+
}
|
|
4206
|
+
const { confirm: confirm3, input: input3 } = await import("@inquirer/prompts");
|
|
4207
|
+
const enabled = await confirm3({
|
|
4208
|
+
message: "Enable anonymous usage telemetry to help improve OpenCRVS? Only aggregate metrics are shared \u2014 no personal or protected data.",
|
|
4209
|
+
default: true
|
|
4210
|
+
});
|
|
4211
|
+
if (!enabled) {
|
|
4212
|
+
return TELEMETRY_DISABLED;
|
|
4213
|
+
}
|
|
4214
|
+
const countryCode = (await input3({
|
|
4215
|
+
message: "Country code (ISO alpha-3, e.g. FAR):",
|
|
4216
|
+
validate: (value) => /^[A-Za-z]{3}$/.test(value.trim()) || "Enter a 3-letter ISO alpha-3 code."
|
|
4217
|
+
})).trim().toUpperCase();
|
|
4218
|
+
const organisation = (await input3({
|
|
4219
|
+
message: "Organisation running this instance:",
|
|
4220
|
+
validate: (value) => value.trim() !== "" || "Enter an organisation name."
|
|
4221
|
+
})).trim();
|
|
4222
|
+
return { enabled: true, countryCode, organisation };
|
|
4223
|
+
}
|
|
4224
|
+
function writeTelemetryHandler(cwd) {
|
|
4225
|
+
const handlerPath = import_path4.default.join(cwd, HANDLER_FILE2);
|
|
4226
|
+
if ((0, import_fs3.existsSync)(handlerPath)) {
|
|
4227
|
+
console.log(` ${HANDLER_FILE2} already present; left unchanged`);
|
|
4228
|
+
return;
|
|
4229
|
+
}
|
|
4230
|
+
(0, import_fs3.mkdirSync)(import_path4.default.dirname(handlerPath), { recursive: true });
|
|
4231
|
+
(0, import_fs3.writeFileSync)(handlerPath, TELEMETRY_HANDLER_SOURCE);
|
|
4232
|
+
console.log(` \u2713 ${HANDLER_FILE2}`);
|
|
4233
|
+
}
|
|
4234
|
+
function appendProperty(sourceFile, object, name, valueLines) {
|
|
4235
|
+
const properties = object.getProperties();
|
|
4236
|
+
const lastProperty = properties[properties.length - 1];
|
|
4237
|
+
if (!lastProperty) return false;
|
|
4238
|
+
const indent = lastProperty.getIndentationText();
|
|
4239
|
+
const entry = valueLines.map((line2, index) => `${indent}${index === 0 ? `${name}: ${line2}` : line2}`).join("\n");
|
|
4240
|
+
sourceFile.insertText(lastProperty.getEnd(), `,
|
|
4241
|
+
${entry}`);
|
|
4242
|
+
return true;
|
|
4243
|
+
}
|
|
4244
|
+
function ensureEnvalidNamedImports(sourceFile, names) {
|
|
4245
|
+
const importDeclaration = sourceFile.getImportDeclarations().find((declaration) => declaration.getModuleSpecifierValue() === "envalid");
|
|
4246
|
+
if (!importDeclaration) {
|
|
4247
|
+
warnSkipped3(
|
|
4248
|
+
`Could not find the 'envalid' import in ${ENVIRONMENT_FILE}; import { ${names.join(", ")} } by hand`
|
|
4249
|
+
);
|
|
4250
|
+
return;
|
|
4251
|
+
}
|
|
4252
|
+
const existing = new Set(
|
|
4253
|
+
importDeclaration.getNamedImports().map((named) => named.getName())
|
|
4254
|
+
);
|
|
4255
|
+
for (const name of names) {
|
|
4256
|
+
if (!existing.has(name)) {
|
|
4257
|
+
importDeclaration.addNamedImport(name);
|
|
4258
|
+
}
|
|
4259
|
+
}
|
|
4260
|
+
}
|
|
4261
|
+
function getCleanEnvObject(sourceFile) {
|
|
4262
|
+
const options = sourceFile.getDescendantsOfKind(import_ts_morph3.SyntaxKind.CallExpression).find((call) => call.getExpression().getText() === "cleanEnv")?.getArguments()[1];
|
|
4263
|
+
return options && import_ts_morph3.Node.isObjectLiteralExpression(options) ? options : void 0;
|
|
4264
|
+
}
|
|
4265
|
+
function upsertEnvVar(sourceFile, name, kind, defaultExpr, desc, update) {
|
|
4266
|
+
const object = getCleanEnvObject(sourceFile);
|
|
4267
|
+
if (!object) return;
|
|
4268
|
+
const existing = object.getProperty(name);
|
|
4269
|
+
if (existing && import_ts_morph3.Node.isPropertyAssignment(existing)) {
|
|
4270
|
+
if (!update) return;
|
|
4271
|
+
const options = existing.getInitializerIfKind(import_ts_morph3.SyntaxKind.CallExpression)?.getArguments()[0];
|
|
4272
|
+
if (options && import_ts_morph3.Node.isObjectLiteralExpression(options)) {
|
|
4273
|
+
const defaultProperty = options.getProperty("default");
|
|
4274
|
+
if (defaultProperty && import_ts_morph3.Node.isPropertyAssignment(defaultProperty)) {
|
|
4275
|
+
defaultProperty.setInitializer(defaultExpr);
|
|
4276
|
+
} else {
|
|
4277
|
+
options.insertPropertyAssignment(0, {
|
|
4278
|
+
name: "default",
|
|
4279
|
+
initializer: defaultExpr
|
|
4280
|
+
});
|
|
4281
|
+
}
|
|
4282
|
+
console.log(` \u2713 ${ENVIRONMENT_FILE}: ${name} default set`);
|
|
4283
|
+
}
|
|
4284
|
+
return;
|
|
4285
|
+
}
|
|
4286
|
+
if (appendProperty(sourceFile, object, name, [
|
|
4287
|
+
`${kind}({`,
|
|
4288
|
+
` default: ${defaultExpr},`,
|
|
4289
|
+
` desc: ${JSON.stringify(desc)}`,
|
|
4290
|
+
"})"
|
|
4291
|
+
])) {
|
|
4292
|
+
console.log(` \u2713 ${ENVIRONMENT_FILE}: ${name}`);
|
|
4293
|
+
}
|
|
4294
|
+
}
|
|
4295
|
+
function addEnvironmentVariables(project, cwd, config) {
|
|
4296
|
+
const sourceFile = project.addSourceFileAtPathIfExists(
|
|
4297
|
+
import_path4.default.join(cwd, ENVIRONMENT_FILE)
|
|
4298
|
+
);
|
|
4299
|
+
if (!sourceFile) {
|
|
4300
|
+
warnSkipped3(
|
|
4301
|
+
`${ENVIRONMENT_FILE} not found; add the telemetry env vars by hand`
|
|
4302
|
+
);
|
|
4303
|
+
return;
|
|
4304
|
+
}
|
|
4305
|
+
if (!getCleanEnvObject(sourceFile)) {
|
|
4306
|
+
warnSkipped3(
|
|
4307
|
+
`Could not find the cleanEnv(...) config object in ${ENVIRONMENT_FILE}; add the telemetry env vars by hand`
|
|
4308
|
+
);
|
|
4309
|
+
return;
|
|
4310
|
+
}
|
|
4311
|
+
ensureEnvalidNamedImports(sourceFile, ["bool", "str"]);
|
|
4312
|
+
upsertEnvVar(
|
|
4313
|
+
sourceFile,
|
|
4314
|
+
"TELEMETRY_ENABLED",
|
|
4315
|
+
"bool",
|
|
4316
|
+
config.enabled ? "true" : "false",
|
|
4317
|
+
"When true, usage telemetry received from the events service is forwarded to the OpenCRVS status service.",
|
|
4318
|
+
true
|
|
4319
|
+
);
|
|
4320
|
+
upsertEnvVar(
|
|
4321
|
+
sourceFile,
|
|
4322
|
+
"COUNTRY_CODE",
|
|
4323
|
+
"str",
|
|
4324
|
+
config.enabled ? JSON.stringify(config.countryCode) : `'FAR'`,
|
|
4325
|
+
"ISO-style country code of this instance, reported with telemetry.",
|
|
4326
|
+
config.enabled
|
|
4327
|
+
);
|
|
4328
|
+
upsertEnvVar(
|
|
4329
|
+
sourceFile,
|
|
4330
|
+
"ORGANISATION",
|
|
4331
|
+
"str",
|
|
4332
|
+
config.enabled ? JSON.stringify(config.organisation) : `''`,
|
|
4333
|
+
"Organisation running this instance, reported with telemetry. Empty by default.",
|
|
4334
|
+
config.enabled
|
|
4335
|
+
);
|
|
4336
|
+
upsertEnvVar(
|
|
4337
|
+
sourceFile,
|
|
4338
|
+
"ENVIRONMENT_NAME",
|
|
4339
|
+
"str",
|
|
4340
|
+
`'development'`,
|
|
4341
|
+
'Environment name (e.g. "production", "staging") reported as the telemetry environment.',
|
|
4342
|
+
false
|
|
4343
|
+
);
|
|
4344
|
+
}
|
|
4345
|
+
function wireIndex(project, cwd) {
|
|
4346
|
+
const sourceFile = project.addSourceFileAtPathIfExists(
|
|
4347
|
+
import_path4.default.join(cwd, INDEX_FILE)
|
|
4348
|
+
);
|
|
4349
|
+
if (!sourceFile) {
|
|
4350
|
+
warnSkipped3(
|
|
4351
|
+
`${INDEX_FILE} not found; register POST /trigger/telemetry and the startup notice by hand`
|
|
4352
|
+
);
|
|
4353
|
+
return;
|
|
4354
|
+
}
|
|
4355
|
+
if (!sourceFile.getImportDeclarations().some((d) => d.getModuleSpecifierValue() === HANDLER_MODULE)) {
|
|
4356
|
+
sourceFile.addImportDeclaration({
|
|
4357
|
+
moduleSpecifier: HANDLER_MODULE,
|
|
4358
|
+
namedImports: [
|
|
4359
|
+
"telemetryHandler",
|
|
4360
|
+
"telemetrySchema",
|
|
4361
|
+
"TELEMETRY_DISABLED_NOTICE"
|
|
4362
|
+
]
|
|
4363
|
+
});
|
|
4364
|
+
console.log(` \u2713 ${INDEX_FILE}: import ${HANDLER_MODULE}`);
|
|
4365
|
+
}
|
|
4366
|
+
if (!sourceFile.getText().includes("path: '/trigger/telemetry'")) {
|
|
4367
|
+
const lastRouteStatement = sourceFile.getDescendantsOfKind(import_ts_morph3.SyntaxKind.CallExpression).filter((call) => call.getExpression().getText() === "server.route").map(
|
|
4368
|
+
(call) => call.getFirstAncestorByKind(import_ts_morph3.SyntaxKind.ExpressionStatement)
|
|
4369
|
+
).filter(
|
|
4370
|
+
(statement) => Boolean(statement)
|
|
4371
|
+
).pop();
|
|
4372
|
+
if (!lastRouteStatement) {
|
|
4373
|
+
warnSkipped3(
|
|
4374
|
+
`Could not find a server.route(...) call in ${INDEX_FILE}; register POST /trigger/telemetry by hand`
|
|
4375
|
+
);
|
|
4376
|
+
} else {
|
|
4377
|
+
const indent = lastRouteStatement.getIndentationText();
|
|
4378
|
+
const route = [
|
|
4379
|
+
`server.route({`,
|
|
4380
|
+
` method: 'POST',`,
|
|
4381
|
+
` path: '/trigger/telemetry',`,
|
|
4382
|
+
` handler: telemetryHandler,`,
|
|
4383
|
+
` options: {`,
|
|
4384
|
+
` tags: ['api', 'triggers'],`,
|
|
4385
|
+
` validate: {`,
|
|
4386
|
+
` payload: telemetrySchema`,
|
|
4387
|
+
` },`,
|
|
4388
|
+
` description:`,
|
|
4389
|
+
` 'Receives a usage report from the events service and forwards it to the status service when telemetry is enabled'`,
|
|
4390
|
+
` }`,
|
|
4391
|
+
`})`
|
|
4392
|
+
].map((line2) => line2 ? `${indent}${line2}` : line2).join("\n");
|
|
4393
|
+
sourceFile.insertText(lastRouteStatement.getEnd(), `
|
|
4394
|
+
|
|
4395
|
+
${route}`);
|
|
4396
|
+
console.log(` \u2713 ${INDEX_FILE}: POST /trigger/telemetry`);
|
|
4397
|
+
}
|
|
4398
|
+
}
|
|
4399
|
+
if (!sourceFile.getText().includes("logger.info(TELEMETRY_DISABLED_NOTICE)")) {
|
|
4400
|
+
const startedLog = sourceFile.getDescendantsOfKind(import_ts_morph3.SyntaxKind.ExpressionStatement).find(
|
|
4401
|
+
(statement) => statement.getText().includes("Server successfully started")
|
|
4402
|
+
);
|
|
4403
|
+
if (!startedLog) {
|
|
4404
|
+
warnSkipped3(
|
|
4405
|
+
`Could not find the startup log in ${INDEX_FILE}; log TELEMETRY_DISABLED_NOTICE when TELEMETRY_ENABLED is false by hand`
|
|
4406
|
+
);
|
|
4407
|
+
} else {
|
|
4408
|
+
const indent = startedLog.getIndentationText();
|
|
4409
|
+
const notice = [
|
|
4410
|
+
`if (!env.TELEMETRY_ENABLED) {`,
|
|
4411
|
+
` logger.info(TELEMETRY_DISABLED_NOTICE)`,
|
|
4412
|
+
`}`
|
|
4413
|
+
].map((line2) => line2 ? `${indent}${line2}` : line2).join("\n");
|
|
4414
|
+
sourceFile.insertText(startedLog.getEnd(), `
|
|
4415
|
+
|
|
4416
|
+
${notice}`);
|
|
4417
|
+
console.log(` \u2713 ${INDEX_FILE}: telemetry-disabled startup notice`);
|
|
4418
|
+
if (!sourceFile.getImportDeclarations().some((d) => d.getModuleSpecifierValue() === "./environment")) {
|
|
4419
|
+
warnSkipped3(
|
|
4420
|
+
`The startup notice reads env.TELEMETRY_ENABLED but ${INDEX_FILE} does not import env from './environment'; import it by hand`
|
|
4421
|
+
);
|
|
4422
|
+
}
|
|
4423
|
+
}
|
|
4424
|
+
}
|
|
4425
|
+
}
|
|
4426
|
+
async function main4() {
|
|
4427
|
+
const cwd = process.cwd();
|
|
4428
|
+
const config = await promptTelemetryConfig();
|
|
4429
|
+
console.log(
|
|
4430
|
+
`
|
|
4431
|
+
Adding daily usage telemetry (${config.enabled ? `enabled for ${config.countryCode}` : "disabled"} by default)...
|
|
4432
|
+
`
|
|
4433
|
+
);
|
|
4434
|
+
writeTelemetryHandler(cwd);
|
|
4435
|
+
const project = new import_ts_morph3.Project({
|
|
4436
|
+
// ts-morph indents inserted code with four spaces and double-quotes strings
|
|
4437
|
+
// by default, both of which the country config's prettier run would undo.
|
|
4438
|
+
manipulationSettings: {
|
|
4439
|
+
indentationText: import_ts_morph3.IndentationText.TwoSpaces,
|
|
4440
|
+
quoteKind: import_ts_morph3.QuoteKind.Single
|
|
4441
|
+
}
|
|
4442
|
+
});
|
|
4443
|
+
addEnvironmentVariables(project, cwd, config);
|
|
4444
|
+
wireIndex(project, cwd);
|
|
4445
|
+
await project.save();
|
|
4446
|
+
if (skipped3.length > 0) {
|
|
4447
|
+
console.warn(
|
|
4448
|
+
`
|
|
4449
|
+
\u26A0\uFE0F ${skipped3.length} telemetry step(s) were skipped. Wire the following by hand:`
|
|
4450
|
+
);
|
|
4451
|
+
for (const message of skipped3) {
|
|
4452
|
+
console.warn(` - ${message}`);
|
|
4453
|
+
}
|
|
4454
|
+
}
|
|
4455
|
+
}
|
|
4456
|
+
|
|
3290
4457
|
// src/migrations/v2.1/index.ts
|
|
3291
4458
|
async function runUpgrade(dockerSwarm) {
|
|
3292
4459
|
await main();
|
|
4460
|
+
await main2();
|
|
4461
|
+
await main3();
|
|
4462
|
+
await main4();
|
|
4463
|
+
}
|
|
4464
|
+
|
|
4465
|
+
// src/translations/check.ts
|
|
4466
|
+
var import_ts_morph4 = require("ts-morph");
|
|
4467
|
+
var import_path5 = __toESM(require("path"));
|
|
4468
|
+
var TRANSLATIONS = "src/translations";
|
|
4469
|
+
var OWN_FILE = `${TRANSLATIONS}/countryconfig.csv`;
|
|
4470
|
+
var CORE_FILES = [`${TRANSLATIONS}/client.csv`, `${TRANSLATIONS}/login.csv`];
|
|
4471
|
+
function staticStringOf(node, name) {
|
|
4472
|
+
const property = node.getProperty(name);
|
|
4473
|
+
if (!property || !import_ts_morph4.Node.isPropertyAssignment(property)) {
|
|
4474
|
+
return void 0;
|
|
4475
|
+
}
|
|
4476
|
+
const initializer = property.getInitializer();
|
|
4477
|
+
return initializer && (import_ts_morph4.Node.isStringLiteral(initializer) || import_ts_morph4.Node.isNoSubstitutionTemplateLiteral(initializer)) ? initializer.getLiteralValue() : void 0;
|
|
4478
|
+
}
|
|
4479
|
+
function messagesDeclaredIn(cwd) {
|
|
4480
|
+
const project = new import_ts_morph4.Project({ skipAddingFilesFromTsConfig: true });
|
|
4481
|
+
project.addSourceFilesAtPaths([
|
|
4482
|
+
import_path5.default.join(cwd, "src/**/*.ts"),
|
|
4483
|
+
import_path5.default.join(cwd, "src/**/*.tsx"),
|
|
4484
|
+
`!${import_path5.default.join(cwd, "src/**/*.test.ts")}`,
|
|
4485
|
+
`!${import_path5.default.join(cwd, "src/**/*.test.tsx")}`,
|
|
4486
|
+
`!${import_path5.default.join(cwd, "src/**/*.stories.ts")}`,
|
|
4487
|
+
`!${import_path5.default.join(cwd, "src/**/*.stories.tsx")}`
|
|
4488
|
+
]);
|
|
4489
|
+
const messages = [];
|
|
4490
|
+
const dynamicIds = [];
|
|
4491
|
+
for (const sourceFile of project.getSourceFiles()) {
|
|
4492
|
+
sourceFile.forEachDescendant((node) => {
|
|
4493
|
+
if (!import_ts_morph4.Node.isObjectLiteralExpression(node)) {
|
|
4494
|
+
return;
|
|
4495
|
+
}
|
|
4496
|
+
if (!(node.getProperty("id") && node.getProperty("defaultMessage"))) {
|
|
4497
|
+
return;
|
|
4498
|
+
}
|
|
4499
|
+
const id = staticStringOf(node, "id");
|
|
4500
|
+
if (id === void 0) {
|
|
4501
|
+
dynamicIds.push(import_path5.default.relative(cwd, sourceFile.getFilePath()));
|
|
4502
|
+
return;
|
|
4503
|
+
}
|
|
4504
|
+
messages.push({
|
|
4505
|
+
id,
|
|
4506
|
+
defaultMessage: staticStringOf(node, "defaultMessage") ?? "",
|
|
4507
|
+
description: staticStringOf(node, "description") ?? ""
|
|
4508
|
+
});
|
|
4509
|
+
});
|
|
4510
|
+
}
|
|
4511
|
+
return { messages, dynamicIds: [...new Set(dynamicIds)] };
|
|
4512
|
+
}
|
|
4513
|
+
function check(cwd) {
|
|
4514
|
+
const { messages, dynamicIds } = messagesDeclaredIn(cwd);
|
|
4515
|
+
const own = readCsvFile(import_path5.default.join(cwd, OWN_FILE));
|
|
4516
|
+
const covered = new Set(
|
|
4517
|
+
[own, ...CORE_FILES.map((file) => readCsvFile(import_path5.default.join(cwd, file)))].flatMap((csv) => csv?.body ?? []).map(idOf)
|
|
4518
|
+
);
|
|
4519
|
+
const missing = [
|
|
4520
|
+
...new Map(
|
|
4521
|
+
messages.filter(({ id }) => !covered.has(id)).map((message) => [message.id, message])
|
|
4522
|
+
).values()
|
|
4523
|
+
].sort((a, b) => a.id < b.id ? -1 : 1);
|
|
4524
|
+
const declared = new Set(messages.map(({ id }) => id));
|
|
4525
|
+
const outdated = (own?.body ?? []).map(idOf).filter((id) => !declared.has(id));
|
|
4526
|
+
return { missing, outdated, dynamicIds };
|
|
4527
|
+
}
|
|
4528
|
+
function writeMissing(cwd, missing) {
|
|
4529
|
+
const file = readCsvFile(import_path5.default.join(cwd, OWN_FILE));
|
|
4530
|
+
if (!file) {
|
|
4531
|
+
throw new Error(`${OWN_FILE} not found in ${cwd}`);
|
|
4532
|
+
}
|
|
4533
|
+
const columns = file.header.split(",");
|
|
4534
|
+
const rows = missing.map(
|
|
4535
|
+
(message) => toCsvLine(
|
|
4536
|
+
columns.map((column) => {
|
|
4537
|
+
if (column === "id") return message.id;
|
|
4538
|
+
if (column === "description") return message.description;
|
|
4539
|
+
return column === "en" ? message.defaultMessage : "";
|
|
4540
|
+
})
|
|
4541
|
+
)
|
|
4542
|
+
);
|
|
4543
|
+
const added = addRows(file, rows);
|
|
4544
|
+
writeCsvFile(import_path5.default.join(cwd, OWN_FILE), file);
|
|
4545
|
+
return added;
|
|
3293
4546
|
}
|
|
3294
4547
|
|
|
3295
4548
|
// src/environment/index.ts
|
|
3296
|
-
var
|
|
3297
|
-
var
|
|
4549
|
+
var import_fs8 = require("fs");
|
|
4550
|
+
var import_path10 = require("path");
|
|
4551
|
+
init_paths();
|
|
3298
4552
|
var REQUIRED_REPOSITORY_DIRECTORIES = [
|
|
3299
4553
|
".github/workflows",
|
|
3300
4554
|
"environments",
|
|
@@ -3304,7 +4558,7 @@ function validateRepositoryStructure(repositoryRoot = process.cwd()) {
|
|
|
3304
4558
|
const missingDirectories = REQUIRED_REPOSITORY_DIRECTORIES.filter(
|
|
3305
4559
|
(directory) => {
|
|
3306
4560
|
try {
|
|
3307
|
-
return !(0,
|
|
4561
|
+
return !(0, import_fs8.statSync)((0, import_path10.resolve)(repositoryRoot, directory)).isDirectory();
|
|
3308
4562
|
} catch {
|
|
3309
4563
|
return true;
|
|
3310
4564
|
}
|
|
@@ -3318,8 +4572,14 @@ function validateRepositoryStructure(repositoryRoot = process.cwd()) {
|
|
|
3318
4572
|
}
|
|
3319
4573
|
async function runEnvironmentInit() {
|
|
3320
4574
|
validateRepositoryStructure();
|
|
4575
|
+
assertNoOldInventoryLayout();
|
|
3321
4576
|
await Promise.resolve().then(() => (init_setup_environment(), setup_environment_exports));
|
|
3322
4577
|
}
|
|
4578
|
+
async function runEnvironmentUpgrade() {
|
|
4579
|
+
validateRepositoryStructure();
|
|
4580
|
+
const { upgradeEnvironmentLayout: upgradeEnvironmentLayout2 } = await Promise.resolve().then(() => (init_upgrade(), upgrade_exports));
|
|
4581
|
+
await upgradeEnvironmentLayout2();
|
|
4582
|
+
}
|
|
3323
4583
|
async function runEnvironmentUpdateWorkflows() {
|
|
3324
4584
|
validateRepositoryStructure();
|
|
3325
4585
|
const { updateWorkflowEnvironments: updateWorkflowEnvironments2 } = await Promise.resolve().then(() => (init_update_workflows(), update_workflows_exports));
|
|
@@ -3335,6 +4595,278 @@ async function runEnvironmentSwarmToK8s() {
|
|
|
3335
4595
|
await Promise.resolve().then(() => (init_swarm_to_k8s(), swarm_to_k8s_exports));
|
|
3336
4596
|
}
|
|
3337
4597
|
|
|
4598
|
+
// src/verify/endpoints.ts
|
|
4599
|
+
var import_colors = require("kleur/colors");
|
|
4600
|
+
var REQUEST_TIMEOUT_MS = 15e3;
|
|
4601
|
+
var DEFAULT_TARGET_URL = "http://localhost:3040";
|
|
4602
|
+
var REQUIRED_PUBLIC_ENDPOINTS = [
|
|
4603
|
+
{ method: "GET", path: "/client-config.js" },
|
|
4604
|
+
{ method: "GET", path: "/login-config.js" },
|
|
4605
|
+
{ method: "GET", path: "/handlebars.js" },
|
|
4606
|
+
{ method: "GET", path: "/content/client" },
|
|
4607
|
+
{ method: "GET", path: "/content/login" },
|
|
4608
|
+
{ method: "GET", path: "/content/map.geojson" },
|
|
4609
|
+
{ method: "GET", path: "/content/country-logo" },
|
|
4610
|
+
{ method: "GET", path: "/config/application" },
|
|
4611
|
+
{ method: "GET", path: "/config/workqueues" },
|
|
4612
|
+
{ method: "GET", path: "/config/locations" },
|
|
4613
|
+
{ method: "GET", path: "/config/roles" },
|
|
4614
|
+
{ method: "GET", path: "/config/events" }
|
|
4615
|
+
];
|
|
4616
|
+
var PROBE_SEGMENT = "verify-endpoints-probe";
|
|
4617
|
+
var SECURED_TRIGGER_USER_EVENTS = [
|
|
4618
|
+
"user-created",
|
|
4619
|
+
"user-updated",
|
|
4620
|
+
"username-reminder",
|
|
4621
|
+
"reset-password",
|
|
4622
|
+
"reset-password-by-admin",
|
|
4623
|
+
"password-reset-link",
|
|
4624
|
+
"username-reminder-link",
|
|
4625
|
+
"resend-invite",
|
|
4626
|
+
"2fa",
|
|
4627
|
+
"all-user-notification",
|
|
4628
|
+
"change-phone-number",
|
|
4629
|
+
"change-email-address"
|
|
4630
|
+
];
|
|
4631
|
+
var SECURED_ENDPOINTS = [
|
|
4632
|
+
...SECURED_TRIGGER_USER_EVENTS.map(
|
|
4633
|
+
(event) => ({
|
|
4634
|
+
method: "POST",
|
|
4635
|
+
path: `/triggers/user/${event}`
|
|
4636
|
+
})
|
|
4637
|
+
),
|
|
4638
|
+
{ method: "POST", path: "/trigger/telemetry" },
|
|
4639
|
+
{ method: "GET", path: "/triggers/system/ready" },
|
|
4640
|
+
{
|
|
4641
|
+
method: "GET",
|
|
4642
|
+
path: `/certificates/${PROBE_SEGMENT}`,
|
|
4643
|
+
label: "/certificates/{id}"
|
|
4644
|
+
},
|
|
4645
|
+
{ method: "GET", path: "/certificates" },
|
|
4646
|
+
{ method: "GET", path: "/config/users" }
|
|
4647
|
+
];
|
|
4648
|
+
var FALLBACK_EVENT_TRIGGERS = [
|
|
4649
|
+
{
|
|
4650
|
+
method: "POST",
|
|
4651
|
+
path: `/trigger/events/${PROBE_SEGMENT}/actions/${PROBE_SEGMENT}`,
|
|
4652
|
+
label: "/trigger/events/{event}/actions/{action}"
|
|
4653
|
+
},
|
|
4654
|
+
{
|
|
4655
|
+
method: "POST",
|
|
4656
|
+
path: `/trigger/events/birth/actions/${PROBE_SEGMENT}`,
|
|
4657
|
+
label: "/trigger/events/birth/actions/{action}"
|
|
4658
|
+
},
|
|
4659
|
+
{
|
|
4660
|
+
method: "POST",
|
|
4661
|
+
path: `/trigger/events/death/actions/${PROBE_SEGMENT}`,
|
|
4662
|
+
label: "/trigger/events/death/actions/{action}"
|
|
4663
|
+
}
|
|
4664
|
+
];
|
|
4665
|
+
var isSuccess = (status) => status !== "error" && status >= 200 && status < 300;
|
|
4666
|
+
var requiresAuthOrAbsent = (status) => status === 401 || status === 403 || status === 404;
|
|
4667
|
+
async function requestStatus(url, method) {
|
|
4668
|
+
const controller = new AbortController();
|
|
4669
|
+
const timer = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
|
|
4670
|
+
try {
|
|
4671
|
+
const response = await fetch(url, {
|
|
4672
|
+
method,
|
|
4673
|
+
signal: controller.signal,
|
|
4674
|
+
// Sent without an Authorization header on purpose. A secured route
|
|
4675
|
+
// rejects with 401/403 before ever reading the body.
|
|
4676
|
+
headers: method === "POST" ? { "Content-Type": "application/json" } : void 0,
|
|
4677
|
+
body: method === "POST" ? "{}" : void 0
|
|
4678
|
+
});
|
|
4679
|
+
return response.status;
|
|
4680
|
+
} catch {
|
|
4681
|
+
return "error";
|
|
4682
|
+
} finally {
|
|
4683
|
+
clearTimeout(timer);
|
|
4684
|
+
}
|
|
4685
|
+
}
|
|
4686
|
+
function toEventTriggerConfig(value) {
|
|
4687
|
+
if (typeof value !== "object" || value === null) {
|
|
4688
|
+
return null;
|
|
4689
|
+
}
|
|
4690
|
+
const record = value;
|
|
4691
|
+
if (typeof record.id !== "string") {
|
|
4692
|
+
return null;
|
|
4693
|
+
}
|
|
4694
|
+
const actions = Array.isArray(record.actions) ? Array.from(
|
|
4695
|
+
new Set(
|
|
4696
|
+
record.actions.map((action) => {
|
|
4697
|
+
if (typeof action !== "object" || action === null) {
|
|
4698
|
+
return null;
|
|
4699
|
+
}
|
|
4700
|
+
const type = action.type;
|
|
4701
|
+
return typeof type === "string" ? type : null;
|
|
4702
|
+
}).filter((type) => type !== null)
|
|
4703
|
+
)
|
|
4704
|
+
) : [];
|
|
4705
|
+
return { id: record.id, actions };
|
|
4706
|
+
}
|
|
4707
|
+
async function fetchEventConfigs(baseUrl) {
|
|
4708
|
+
const controller = new AbortController();
|
|
4709
|
+
const timer = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
|
|
4710
|
+
try {
|
|
4711
|
+
const response = await fetch(`${baseUrl}/config/events`, {
|
|
4712
|
+
signal: controller.signal
|
|
4713
|
+
});
|
|
4714
|
+
if (!response.ok) {
|
|
4715
|
+
return null;
|
|
4716
|
+
}
|
|
4717
|
+
const body = await response.json();
|
|
4718
|
+
if (!Array.isArray(body)) {
|
|
4719
|
+
return null;
|
|
4720
|
+
}
|
|
4721
|
+
return body.map(toEventTriggerConfig).filter((config) => config !== null);
|
|
4722
|
+
} catch {
|
|
4723
|
+
return null;
|
|
4724
|
+
} finally {
|
|
4725
|
+
clearTimeout(timer);
|
|
4726
|
+
}
|
|
4727
|
+
}
|
|
4728
|
+
function resolveBaseUrl(input3) {
|
|
4729
|
+
const withProtocol = /^https?:\/\//i.test(input3) ? input3 : `https://${input3}`;
|
|
4730
|
+
return withProtocol.replace(/\/+$/, "");
|
|
4731
|
+
}
|
|
4732
|
+
function describeStatus(status) {
|
|
4733
|
+
return status === "error" ? "no response" : `HTTP ${status}`;
|
|
4734
|
+
}
|
|
4735
|
+
function endpointLabel(check2) {
|
|
4736
|
+
const shown = check2.label ?? check2.path;
|
|
4737
|
+
const suffix = check2.label ? (0, import_colors.dim)(` \u2192 ${check2.path}`) : "";
|
|
4738
|
+
return `${check2.method} ${shown}${suffix}`;
|
|
4739
|
+
}
|
|
4740
|
+
function line(ok, label, detail) {
|
|
4741
|
+
const mark = ok ? (0, import_colors.green)("\u2713") : (0, import_colors.red)("\u2717");
|
|
4742
|
+
return ` ${mark} ${label} ${(0, import_colors.dim)(`(${detail})`)}`;
|
|
4743
|
+
}
|
|
4744
|
+
function securedDetail(status) {
|
|
4745
|
+
if (status === 401 || status === 403) {
|
|
4746
|
+
return `${describeStatus(status)} \u2014 auth required`;
|
|
4747
|
+
}
|
|
4748
|
+
if (status === 404) {
|
|
4749
|
+
return `${describeStatus(status)} \u2014 not implemented`;
|
|
4750
|
+
}
|
|
4751
|
+
if (status === "error") {
|
|
4752
|
+
return `${describeStatus(status)} \u2014 request failed`;
|
|
4753
|
+
}
|
|
4754
|
+
return `${describeStatus(status)} \u2014 INSECURE: processed without a token`;
|
|
4755
|
+
}
|
|
4756
|
+
async function runVerifyEndpoints(target = DEFAULT_TARGET_URL) {
|
|
4757
|
+
const baseUrl = resolveBaseUrl(target);
|
|
4758
|
+
console.log((0, import_colors.bold)(`Verifying country config endpoints at ${baseUrl}
|
|
4759
|
+
`));
|
|
4760
|
+
let failures = 0;
|
|
4761
|
+
console.log((0, import_colors.bold)("Required public endpoints (must respond 2xx):"));
|
|
4762
|
+
for (const check2 of REQUIRED_PUBLIC_ENDPOINTS) {
|
|
4763
|
+
const status = await requestStatus(`${baseUrl}${check2.path}`, check2.method);
|
|
4764
|
+
const ok = isSuccess(status);
|
|
4765
|
+
if (!ok) {
|
|
4766
|
+
failures++;
|
|
4767
|
+
}
|
|
4768
|
+
const detail = status === 404 ? `${describeStatus(status)} \u2014 missing` : ok ? describeStatus(status) : `${describeStatus(status)} \u2014 unexpected`;
|
|
4769
|
+
console.log(line(ok, endpointLabel(check2), detail));
|
|
4770
|
+
}
|
|
4771
|
+
{
|
|
4772
|
+
const path10 = `/fonts/${PROBE_SEGMENT}.ttf`;
|
|
4773
|
+
const status = await requestStatus(`${baseUrl}${path10}`, "GET");
|
|
4774
|
+
const ok = status === 200 || status === 404;
|
|
4775
|
+
if (!ok) {
|
|
4776
|
+
failures++;
|
|
4777
|
+
}
|
|
4778
|
+
let detail;
|
|
4779
|
+
if (status === 404) {
|
|
4780
|
+
detail = `${describeStatus(status)} \u2014 reachable (made-up filename)`;
|
|
4781
|
+
} else if (status === 200) {
|
|
4782
|
+
detail = describeStatus(status);
|
|
4783
|
+
} else if (status === 401 || status === 403) {
|
|
4784
|
+
detail = `${describeStatus(status)} \u2014 must be public`;
|
|
4785
|
+
} else {
|
|
4786
|
+
detail = `${describeStatus(status)} \u2014 unexpected`;
|
|
4787
|
+
}
|
|
4788
|
+
console.log(line(ok, `GET /fonts/{filename}${(0, import_colors.dim)(` \u2192 ${path10}`)}`, detail));
|
|
4789
|
+
}
|
|
4790
|
+
console.log();
|
|
4791
|
+
console.log((0, import_colors.bold)("Secured endpoints (must be absent or require auth):"));
|
|
4792
|
+
for (const check2 of SECURED_ENDPOINTS) {
|
|
4793
|
+
const status = await requestStatus(`${baseUrl}${check2.path}`, check2.method);
|
|
4794
|
+
const ok = requiresAuthOrAbsent(status);
|
|
4795
|
+
if (!ok) {
|
|
4796
|
+
failures++;
|
|
4797
|
+
}
|
|
4798
|
+
console.log(line(ok, endpointLabel(check2), securedDetail(status)));
|
|
4799
|
+
}
|
|
4800
|
+
console.log();
|
|
4801
|
+
console.log((0, import_colors.bold)("Event action triggers (must be absent or require auth):"));
|
|
4802
|
+
const events = await fetchEventConfigs(baseUrl);
|
|
4803
|
+
if (!events) {
|
|
4804
|
+
console.log(
|
|
4805
|
+
" " + (0, import_colors.yellow)(
|
|
4806
|
+
"Could not read /config/events; falling back to route-pattern checks."
|
|
4807
|
+
)
|
|
4808
|
+
);
|
|
4809
|
+
for (const check2 of FALLBACK_EVENT_TRIGGERS) {
|
|
4810
|
+
const status = await requestStatus(
|
|
4811
|
+
`${baseUrl}${check2.path}`,
|
|
4812
|
+
check2.method
|
|
4813
|
+
);
|
|
4814
|
+
const ok = requiresAuthOrAbsent(status);
|
|
4815
|
+
if (!ok) {
|
|
4816
|
+
failures++;
|
|
4817
|
+
}
|
|
4818
|
+
console.log(line(ok, endpointLabel(check2), securedDetail(status)));
|
|
4819
|
+
}
|
|
4820
|
+
} else if (events.length === 0) {
|
|
4821
|
+
console.log(" " + (0, import_colors.yellow)("No events configured."));
|
|
4822
|
+
} else {
|
|
4823
|
+
for (const event of events) {
|
|
4824
|
+
const actions = event.actions.length ? event.actions : [PROBE_SEGMENT];
|
|
4825
|
+
const failed = [];
|
|
4826
|
+
for (const action of actions) {
|
|
4827
|
+
const status = await requestStatus(
|
|
4828
|
+
`${baseUrl}/trigger/events/${event.id}/actions/${action}`,
|
|
4829
|
+
"POST"
|
|
4830
|
+
);
|
|
4831
|
+
if (!requiresAuthOrAbsent(status)) {
|
|
4832
|
+
failed.push({ action, status });
|
|
4833
|
+
}
|
|
4834
|
+
}
|
|
4835
|
+
const pattern = `POST /trigger/events/${event.id}/actions/{action}`;
|
|
4836
|
+
if (failed.length === 0) {
|
|
4837
|
+
console.log(
|
|
4838
|
+
line(true, pattern, `${actions.length} action(s) \u2014 all require auth`)
|
|
4839
|
+
);
|
|
4840
|
+
} else {
|
|
4841
|
+
for (const failure of failed) {
|
|
4842
|
+
failures++;
|
|
4843
|
+
console.log(
|
|
4844
|
+
line(
|
|
4845
|
+
false,
|
|
4846
|
+
`POST /trigger/events/${event.id}/actions/${failure.action}`,
|
|
4847
|
+
securedDetail(failure.status)
|
|
4848
|
+
)
|
|
4849
|
+
);
|
|
4850
|
+
}
|
|
4851
|
+
const okCount = actions.length - failed.length;
|
|
4852
|
+
if (okCount > 0) {
|
|
4853
|
+
console.log(
|
|
4854
|
+
line(true, pattern, `${okCount} other action(s) require auth`)
|
|
4855
|
+
);
|
|
4856
|
+
}
|
|
4857
|
+
}
|
|
4858
|
+
}
|
|
4859
|
+
}
|
|
4860
|
+
console.log();
|
|
4861
|
+
if (failures > 0) {
|
|
4862
|
+
console.log(
|
|
4863
|
+
(0, import_colors.red)((0, import_colors.bold)(`\u2717 ${failures} check(s) failed.`)) + (0, import_colors.yellow)(" See the lines marked \u2717 above.")
|
|
4864
|
+
);
|
|
4865
|
+
process.exit(1);
|
|
4866
|
+
}
|
|
4867
|
+
console.log((0, import_colors.green)((0, import_colors.bold)("\u2713 All endpoint checks passed.")));
|
|
4868
|
+
}
|
|
4869
|
+
|
|
3338
4870
|
// src/cli.ts
|
|
3339
4871
|
var args = process.argv.slice(2);
|
|
3340
4872
|
var USAGE = `
|
|
@@ -3344,9 +4876,31 @@ Commands:
|
|
|
3344
4876
|
environment Manage deployment environments
|
|
3345
4877
|
upgrade Upgrade an existing environment
|
|
3346
4878
|
check-translations Check translation files for completeness
|
|
4879
|
+
verify-endpoints Verify the locally-running country config exposes the
|
|
4880
|
+
expected endpoints and keeps secured ones locked down
|
|
3347
4881
|
|
|
3348
4882
|
Run 'opencrvs <command> --help' for more information on a command.
|
|
3349
4883
|
`.trim();
|
|
4884
|
+
var VERIFY_ENDPOINTS_USAGE = `
|
|
4885
|
+
Usage: opencrvs verify-endpoints [country-config-url]
|
|
4886
|
+
|
|
4887
|
+
Run this after 'opencrvs upgrade', with the upgraded country config running
|
|
4888
|
+
locally, to confirm it still behaves correctly. It checks over HTTP that:
|
|
4889
|
+
- required public endpoints exist (respond 2xx), and
|
|
4890
|
+
- user-notification trigger endpoints are either absent or reject
|
|
4891
|
+
unauthenticated requests (never processed without a token).
|
|
4892
|
+
|
|
4893
|
+
Arguments:
|
|
4894
|
+
[country-config-url] Optional. Domain or URL of the country config
|
|
4895
|
+
service. Defaults to 'http://localhost:3040', the
|
|
4896
|
+
port country config listens on locally. A bare
|
|
4897
|
+
domain is assumed to use https.
|
|
4898
|
+
|
|
4899
|
+
Options:
|
|
4900
|
+
-h, --help Show this message.
|
|
4901
|
+
|
|
4902
|
+
Exits with a non-zero status if any check fails.
|
|
4903
|
+
`.trim();
|
|
3350
4904
|
var UPGRADE_USAGE = `
|
|
3351
4905
|
Usage: opencrvs upgrade [options]
|
|
3352
4906
|
|
|
@@ -3360,7 +4914,7 @@ Options:
|
|
|
3360
4914
|
'infrastructure/' directory is deleted (default).
|
|
3361
4915
|
-h, --help Show this message.
|
|
3362
4916
|
`.trim();
|
|
3363
|
-
function
|
|
4917
|
+
function main5() {
|
|
3364
4918
|
const command = args[0];
|
|
3365
4919
|
if (!command || command === "--help" || command === "-h") {
|
|
3366
4920
|
console.log(USAGE);
|
|
@@ -3373,6 +4927,8 @@ function main2() {
|
|
|
3373
4927
|
return handleUpgrade();
|
|
3374
4928
|
case "check-translations":
|
|
3375
4929
|
return handleCheckTranslations();
|
|
4930
|
+
case "verify-endpoints":
|
|
4931
|
+
return handleVerifyEndpoints();
|
|
3376
4932
|
default:
|
|
3377
4933
|
console.error(`Unknown command: ${command}
|
|
3378
4934
|
`);
|
|
@@ -3389,6 +4945,7 @@ Usage: opencrvs environment <subcommand>
|
|
|
3389
4945
|
|
|
3390
4946
|
Subcommands:
|
|
3391
4947
|
init Initialise a new environment
|
|
4948
|
+
upgrade Upgrade existing environment configuration
|
|
3392
4949
|
update-workflows Update workflow environment options
|
|
3393
4950
|
users Manage environment users
|
|
3394
4951
|
swarm-to-k8s Migrate Docker Swarm configuration to Kubernetes
|
|
@@ -3399,6 +4956,8 @@ Subcommands:
|
|
|
3399
4956
|
switch (subcommand) {
|
|
3400
4957
|
case "init":
|
|
3401
4958
|
return runEnvironmentCommand("initialisation", runEnvironmentInit);
|
|
4959
|
+
case "upgrade":
|
|
4960
|
+
return runEnvironmentCommand("environment upgrade", runEnvironmentUpgrade);
|
|
3402
4961
|
case "update-workflows":
|
|
3403
4962
|
return runEnvironmentCommand(
|
|
3404
4963
|
"workflow update",
|
|
@@ -3419,10 +4978,10 @@ Subcommands:
|
|
|
3419
4978
|
async function runEnvironmentCommand(operation, command) {
|
|
3420
4979
|
try {
|
|
3421
4980
|
await command();
|
|
3422
|
-
} catch (
|
|
4981
|
+
} catch (error3) {
|
|
3423
4982
|
console.error(
|
|
3424
4983
|
`Environment ${operation} failed:`,
|
|
3425
|
-
|
|
4984
|
+
error3 instanceof Error ? error3.message : error3
|
|
3426
4985
|
);
|
|
3427
4986
|
process.exit(1);
|
|
3428
4987
|
}
|
|
@@ -3448,14 +5007,95 @@ async function handleUpgrade() {
|
|
|
3448
5007
|
try {
|
|
3449
5008
|
await runUpgrade(dockerSwarm);
|
|
3450
5009
|
console.log("Upgrade completed successfully!");
|
|
3451
|
-
} catch (
|
|
3452
|
-
console.error("Upgrade failed:",
|
|
5010
|
+
} catch (error3) {
|
|
5011
|
+
console.error("Upgrade failed:", error3);
|
|
3453
5012
|
process.exit(1);
|
|
3454
5013
|
}
|
|
3455
5014
|
}
|
|
5015
|
+
var CHECK_TRANSLATIONS_USAGE = `
|
|
5016
|
+
Usage: opencrvs check-translations [options]
|
|
5017
|
+
|
|
5018
|
+
Check that every message this country config declares has a row in
|
|
5019
|
+
src/translations/countryconfig.csv.
|
|
5020
|
+
|
|
5021
|
+
Options:
|
|
5022
|
+
--write Add the missing rows, filling in English only
|
|
5023
|
+
--outdated List rows nothing in the source declares any more
|
|
5024
|
+
-h, --help Show this help
|
|
5025
|
+
`;
|
|
3456
5026
|
function handleCheckTranslations() {
|
|
3457
|
-
|
|
3458
|
-
|
|
3459
|
-
|
|
5027
|
+
const checkArgs = args.slice(1);
|
|
5028
|
+
if (checkArgs.includes("--help") || checkArgs.includes("-h")) {
|
|
5029
|
+
console.log(CHECK_TRANSLATIONS_USAGE);
|
|
5030
|
+
return;
|
|
5031
|
+
}
|
|
5032
|
+
const unknownFlags = checkArgs.filter(
|
|
5033
|
+
(arg) => arg.startsWith("-") && !["--write", "--outdated"].includes(arg)
|
|
5034
|
+
);
|
|
5035
|
+
if (unknownFlags.length > 0) {
|
|
5036
|
+
console.error(`Unknown option: ${unknownFlags.join(", ")}
|
|
5037
|
+
`);
|
|
5038
|
+
console.log(CHECK_TRANSLATIONS_USAGE);
|
|
5039
|
+
process.exit(1);
|
|
5040
|
+
}
|
|
5041
|
+
const cwd = process.cwd();
|
|
5042
|
+
const { missing, outdated, dynamicIds } = check(cwd);
|
|
5043
|
+
for (const file of dynamicIds) {
|
|
5044
|
+
console.warn(
|
|
5045
|
+
`Warning: ${file} declares a message whose id is built at runtime. Ids have to be hardcoded to be checked.`
|
|
5046
|
+
);
|
|
5047
|
+
}
|
|
5048
|
+
if (checkArgs.includes("--outdated")) {
|
|
5049
|
+
console.log(
|
|
5050
|
+
`${outdated.length} row(s) in countryconfig.csv are not declared in src:
|
|
5051
|
+
`
|
|
5052
|
+
);
|
|
5053
|
+
console.log(outdated.join("\n"));
|
|
5054
|
+
return;
|
|
5055
|
+
}
|
|
5056
|
+
if (missing.length === 0) {
|
|
5057
|
+
console.log("Every message declared in src has a translation row.");
|
|
5058
|
+
return;
|
|
5059
|
+
}
|
|
5060
|
+
console.error(
|
|
5061
|
+
`${missing.length} message(s) declared in src have no row in src/translations/countryconfig.csv:
|
|
5062
|
+
`
|
|
5063
|
+
);
|
|
5064
|
+
console.error(missing.map(({ id }) => ` ${id}`).join("\n"));
|
|
5065
|
+
if (!checkArgs.includes("--write")) {
|
|
5066
|
+
console.error(
|
|
5067
|
+
"\nRun `pnpm extract:translations --write` to add them with their English copy."
|
|
5068
|
+
);
|
|
5069
|
+
process.exit(1);
|
|
5070
|
+
}
|
|
5071
|
+
const added = writeMissing(cwd, missing);
|
|
5072
|
+
console.log(`
|
|
5073
|
+
Added ${added.length} row(s) to countryconfig.csv.`);
|
|
5074
|
+
console.log("The languages other than English are still yours to write.");
|
|
5075
|
+
}
|
|
5076
|
+
async function handleVerifyEndpoints() {
|
|
5077
|
+
const verifyArgs = args.slice(1);
|
|
5078
|
+
if (verifyArgs.includes("--help") || verifyArgs.includes("-h")) {
|
|
5079
|
+
console.log(VERIFY_ENDPOINTS_USAGE);
|
|
5080
|
+
process.exit(0);
|
|
5081
|
+
}
|
|
5082
|
+
const positional = verifyArgs.filter((arg) => !arg.startsWith("-"));
|
|
5083
|
+
if (positional.length > 1) {
|
|
5084
|
+
console.error(
|
|
5085
|
+
`Unexpected extra argument(s): ${positional.slice(1).join(", ")}
|
|
5086
|
+
`
|
|
5087
|
+
);
|
|
5088
|
+
console.log(VERIFY_ENDPOINTS_USAGE);
|
|
5089
|
+
process.exit(1);
|
|
5090
|
+
}
|
|
5091
|
+
try {
|
|
5092
|
+
await runVerifyEndpoints(positional[0]);
|
|
5093
|
+
} catch (error3) {
|
|
5094
|
+
console.error(
|
|
5095
|
+
"Endpoint verification failed:",
|
|
5096
|
+
error3 instanceof Error ? error3.message : error3
|
|
5097
|
+
);
|
|
5098
|
+
process.exit(1);
|
|
5099
|
+
}
|
|
3460
5100
|
}
|
|
3461
|
-
|
|
5101
|
+
main5();
|