@opencrvs/toolkit 2.1.0-rc.982e0ae → 2.1.0-rc.9a83eed
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -12
- package/create-countryconfig/index.js +133 -2
- package/dist/application-config/index.js +17 -18
- package/dist/authentication/index.js +7 -6
- package/dist/cli.js +458 -204
- package/dist/commons/api/router.d.ts +6 -42
- package/dist/commons/conditionals/conditionals.d.ts +6 -6
- package/dist/commons/conditionals/validate.d.ts +1 -1
- package/dist/commons/events/ActionConfig.d.ts +4 -0
- package/dist/commons/events/AdvancedSearchConfig.d.ts +12 -12
- package/dist/commons/events/FieldConfig.d.ts +16 -15
- package/dist/commons/events/FormConfig.d.ts +6 -0
- package/dist/commons/events/PageConfig.d.ts +4 -0
- package/dist/commons/events/locations.d.ts +4 -0
- package/dist/commons/events/test.utils.d.ts +18 -1
- package/dist/commons/events/utils.d.ts +15 -0
- package/dist/conditionals/index.js +7 -6
- package/dist/environment/manage-users.js +1 -1
- package/dist/environment/setup-environment.js +44 -26
- package/dist/environment/templates.d.ts +0 -1
- package/dist/environment/templates.d.ts.map +1 -1
- package/dist/environment/templates.js +3 -8
- package/dist/environment/update-workflows.d.ts.map +1 -1
- package/dist/environment/update-workflows.js +4 -0
- package/dist/environment/utils.d.ts +0 -12
- package/dist/environment/utils.d.ts.map +1 -1
- package/dist/environment/utils.js +1 -28
- package/dist/events/index.js +1901 -1792
- package/dist/migrations/v2.0/merge-infrastructure-directory.js +3 -3
- package/dist/migrations/v2.1/add-explicit-correction-flags.d.ts +1 -1
- package/dist/migrations/v2.1/add-explicit-correction-flags.d.ts.map +1 -1
- package/dist/migrations/v2.1/add-explicit-correction-flags.js +34 -6
- package/dist/migrations/v2.1/add-recovery-link-notifications.d.ts +1 -1
- package/dist/migrations/v2.1/add-recovery-link-notifications.d.ts.map +1 -1
- package/dist/migrations/v2.1/add-recovery-link-notifications.js +2 -7
- package/dist/migrations/v2.1/add-translations.d.ts +1 -1
- package/dist/migrations/v2.1/add-translations.d.ts.map +1 -1
- package/dist/migrations/v2.1/add-translations.js +1 -6
- package/dist/migrations/v2.1/enable-telemetry.d.ts +1 -1
- package/dist/migrations/v2.1/enable-telemetry.d.ts.map +1 -1
- package/dist/migrations/v2.1/enable-telemetry.js +1 -6
- package/dist/migrations/v2.1/index.d.ts +14 -1
- package/dist/migrations/v2.1/index.d.ts.map +1 -1
- package/dist/migrations/v2.1/index.js +96 -84
- package/dist/notification/index.js +155 -152
- package/dist/scopes/index.d.ts +109 -5
- package/dist/scopes/index.js +7 -6
- package/dist/templates/charts-values/dependencies/values.yaml +2 -0
- package/dist/translations/check.d.ts +2 -0
- package/dist/translations/check.d.ts.map +1 -1
- package/dist/translations/check.js +9 -4
- package/dist/verify/endpoints.d.ts +18 -1
- package/dist/verify/endpoints.d.ts.map +1 -1
- package/dist/verify/endpoints.js +12 -4
- package/dist/verify/scopes.d.ts +13 -0
- package/dist/verify/scopes.d.ts.map +1 -0
- package/dist/verify/scopes.js +131 -0
- package/dist/verify/upgrade.d.ts +14 -0
- package/dist/verify/upgrade.d.ts.map +1 -0
- package/dist/verify/upgrade.js +111 -0
- package/opencrvs-toolkit-2.1.0-rc.9a83eed.tgz +0 -0
- package/package.json +2 -2
- package/tsconfig.build.tsbuildinfo +1 -1
- package/opencrvs-toolkit-2.1.0-rc.982e0ae.tgz +0 -0
package/dist/cli.js
CHANGED
|
@@ -503,24 +503,8 @@ function findExistingValue(name, type, scope, existingValues) {
|
|
|
503
503
|
(value) => value.name === name && value.type === type && value.scope === scope
|
|
504
504
|
);
|
|
505
505
|
}
|
|
506
|
-
function storeSecrets(environment, answers) {
|
|
507
|
-
let envConfig = {};
|
|
508
|
-
try {
|
|
509
|
-
envConfig = import_dotenv.default.parse(
|
|
510
|
-
(0, import_fs4.readFileSync)(`${process.cwd()}/.env.${environment}`)
|
|
511
|
-
);
|
|
512
|
-
} catch (error3) {
|
|
513
|
-
envConfig = {};
|
|
514
|
-
}
|
|
515
|
-
const linesFromAnswers = answers.map(
|
|
516
|
-
(update) => `${update.name}="${update.value}"`
|
|
517
|
-
);
|
|
518
|
-
const linesFromEnvConfig = Object.entries(envConfig).filter(([name]) => !answers.find((update) => update.name === name)).map(([name, value]) => `${name}="${value}"`);
|
|
519
|
-
const allLines = [...linesFromEnvConfig, ...linesFromAnswers].sort();
|
|
520
|
-
(0, import_fs4.writeFileSync)(`.env.${environment}`, allLines.join("\n"));
|
|
521
|
-
}
|
|
522
506
|
function readYamlFile(filePath) {
|
|
523
|
-
const fileContent =
|
|
507
|
+
const fileContent = import_fs5.default.readFileSync(filePath, "utf8");
|
|
524
508
|
return yaml.load(fileContent);
|
|
525
509
|
}
|
|
526
510
|
function writeYamlFile(filePath, data) {
|
|
@@ -533,33 +517,29 @@ function writeYamlFile(filePath, data) {
|
|
|
533
517
|
noRefs: true,
|
|
534
518
|
sortKeys: false
|
|
535
519
|
});
|
|
536
|
-
|
|
520
|
+
import_fs5.default.writeFileSync(filePath, yamlContent, "utf8");
|
|
537
521
|
} catch (error3) {
|
|
538
522
|
throw new Error(`Failed to write inventory file: ${error3}`);
|
|
539
523
|
}
|
|
540
524
|
}
|
|
541
|
-
var
|
|
525
|
+
var import_fs5, yaml;
|
|
542
526
|
var init_utils = __esm({
|
|
543
527
|
"src/environment/utils.ts"() {
|
|
544
528
|
"use strict";
|
|
545
|
-
|
|
529
|
+
import_fs5 = __toESM(require("fs"));
|
|
546
530
|
yaml = __toESM(require("js-yaml"));
|
|
547
|
-
import_dotenv = __toESM(require("dotenv"));
|
|
548
531
|
}
|
|
549
532
|
});
|
|
550
533
|
|
|
551
534
|
// src/environment/templates.ts
|
|
552
|
-
function getUsers(data) {
|
|
553
|
-
if (!data?.all?.vars?.users) {
|
|
554
|
-
return { users: [] };
|
|
555
|
-
}
|
|
556
|
-
return data.all.vars.users;
|
|
557
|
-
}
|
|
558
535
|
function extractAndModifyUsers(data) {
|
|
559
536
|
if (!data?.all?.vars?.users) {
|
|
560
537
|
return { users: [] };
|
|
561
538
|
}
|
|
562
539
|
const users = data.all.vars.users.map((user) => {
|
|
540
|
+
if (user.role) {
|
|
541
|
+
return user;
|
|
542
|
+
}
|
|
563
543
|
const { sudoer, ...rest } = user;
|
|
564
544
|
return {
|
|
565
545
|
...rest,
|
|
@@ -597,27 +577,27 @@ function extractWorkerNodes(data) {
|
|
|
597
577
|
function copyChartsValues(env, values) {
|
|
598
578
|
const srcDir = import_path7.default.resolve(__dirname, "templates", "charts-values");
|
|
599
579
|
const destDir = import_path7.default.resolve(process.cwd(), "environments", env);
|
|
600
|
-
|
|
580
|
+
import_fs6.default.mkdirSync(destDir, { recursive: true });
|
|
601
581
|
values["lets_encrypt"] = values["traefik_mode"] === "lets_encrypt";
|
|
602
582
|
values["static_ssl"] = values["traefik_mode"] === "static_ssl";
|
|
603
583
|
values["opencrvs_environment"] = env;
|
|
604
584
|
function copyRecursive(src, dest) {
|
|
605
|
-
const stat =
|
|
585
|
+
const stat = import_fs6.default.statSync(src);
|
|
606
586
|
if (stat.isDirectory()) {
|
|
607
|
-
|
|
608
|
-
for (const item of
|
|
587
|
+
import_fs6.default.mkdirSync(dest, { recursive: true });
|
|
588
|
+
for (const item of import_fs6.default.readdirSync(src)) {
|
|
609
589
|
copyRecursive(import_path7.default.join(src, item), import_path7.default.join(dest, item));
|
|
610
590
|
}
|
|
611
591
|
} else {
|
|
612
|
-
const content =
|
|
592
|
+
const content = import_fs6.default.readFileSync(src, "utf8");
|
|
613
593
|
const template = import_handlebars.default.compile(content);
|
|
614
594
|
const updated = template(values);
|
|
615
595
|
const isOverridesFile = dest.endsWith("override.yaml");
|
|
616
|
-
if (isOverridesFile &&
|
|
596
|
+
if (isOverridesFile && import_fs6.default.existsSync(dest)) {
|
|
617
597
|
log(` \u21B7 Skipped existing overrides file: ${dest}`);
|
|
618
598
|
return;
|
|
619
599
|
}
|
|
620
|
-
|
|
600
|
+
import_fs6.default.writeFileSync(dest, updated, "utf8");
|
|
621
601
|
log(` \u2713 Created: ${dest}`);
|
|
622
602
|
}
|
|
623
603
|
}
|
|
@@ -635,21 +615,21 @@ function generateInventory(env, values) {
|
|
|
635
615
|
"inventory.template.yml"
|
|
636
616
|
);
|
|
637
617
|
const outputPath = import_path7.default.resolve(process.cwd(), getEnvironmentInventoryPath(env));
|
|
638
|
-
const templateFile =
|
|
618
|
+
const templateFile = import_fs6.default.readFileSync(templatePath, "utf-8");
|
|
639
619
|
const template = import_handlebars.default.compile(templateFile);
|
|
640
620
|
values["single_node"] = values["kube_worker_nodes"].length > 0 || values["backup_host"] ? "false" : "true";
|
|
641
621
|
const updated = template(values);
|
|
642
|
-
|
|
643
|
-
|
|
622
|
+
import_fs6.default.mkdirSync(import_path7.default.dirname(outputPath), { recursive: true });
|
|
623
|
+
import_fs6.default.writeFileSync(outputPath, updated);
|
|
644
624
|
log(`
|
|
645
625
|
\u2705 Generated inventory file at ${outputPath}
|
|
646
626
|
`);
|
|
647
627
|
}
|
|
648
|
-
var
|
|
628
|
+
var import_fs6, import_path7, import_handlebars;
|
|
649
629
|
var init_templates = __esm({
|
|
650
630
|
"src/environment/templates.ts"() {
|
|
651
631
|
"use strict";
|
|
652
|
-
|
|
632
|
+
import_fs6 = __toESM(require("fs"));
|
|
653
633
|
import_path7 = __toESM(require("path"));
|
|
654
634
|
init_logger();
|
|
655
635
|
init_paths();
|
|
@@ -706,18 +686,18 @@ var init_git = __esm({
|
|
|
706
686
|
});
|
|
707
687
|
|
|
708
688
|
// src/environment/questions.ts
|
|
709
|
-
function validateCIDR(
|
|
710
|
-
if (!
|
|
689
|
+
function validateCIDR(input4) {
|
|
690
|
+
if (!input4.trim()) {
|
|
711
691
|
return true;
|
|
712
692
|
}
|
|
713
693
|
const cidrRegex = /^((25[0-5]|(2[0-4]|1\d|[1-9]?\d)\d?)\.){3}(25[0-5]|(2[0-4]|1\d|[1-9]?\d)\d?)\/([0-9]|[12][0-9]|3[0-2])$/;
|
|
714
|
-
return cidrRegex.test(
|
|
694
|
+
return cidrRegex.test(input4.trim()) ? true : "Please enter a valid CIDR (e.g. 10.0.0.0/24)";
|
|
715
695
|
}
|
|
716
|
-
function validateCIDRs(
|
|
717
|
-
if (!
|
|
696
|
+
function validateCIDRs(input4) {
|
|
697
|
+
if (!input4.trim()) {
|
|
718
698
|
return true;
|
|
719
699
|
}
|
|
720
|
-
const cidrs =
|
|
700
|
+
const cidrs = input4.split(",").map((v) => v.trim());
|
|
721
701
|
for (const cidr of cidrs) {
|
|
722
702
|
const result = validateCIDR(cidr);
|
|
723
703
|
if (result !== true) {
|
|
@@ -1247,7 +1227,7 @@ function updateInventoryFile(filePath, users) {
|
|
|
1247
1227
|
function parseInventoryFile(filePath) {
|
|
1248
1228
|
try {
|
|
1249
1229
|
const data = readYamlFile(filePath);
|
|
1250
|
-
return
|
|
1230
|
+
return extractAndModifyUsers(data);
|
|
1251
1231
|
} catch {
|
|
1252
1232
|
return [];
|
|
1253
1233
|
}
|
|
@@ -1635,6 +1615,10 @@ async function select3(options) {
|
|
|
1635
1615
|
const inquirer = await import("@inquirer/prompts");
|
|
1636
1616
|
return inquirer.select(options);
|
|
1637
1617
|
}
|
|
1618
|
+
async function input3(options) {
|
|
1619
|
+
const inquirer = await import("@inquirer/prompts");
|
|
1620
|
+
return inquirer.input(options);
|
|
1621
|
+
}
|
|
1638
1622
|
function questionToPrompt({
|
|
1639
1623
|
valueType,
|
|
1640
1624
|
valueLabel,
|
|
@@ -1701,7 +1685,7 @@ function getAnswers(existingValues) {
|
|
|
1701
1685
|
});
|
|
1702
1686
|
});
|
|
1703
1687
|
}
|
|
1704
|
-
async function promptAndStoreAnswer(
|
|
1688
|
+
async function promptAndStoreAnswer(questions, existingValues) {
|
|
1705
1689
|
log("");
|
|
1706
1690
|
const processedQuestions = questions.flatMap((question) => {
|
|
1707
1691
|
const questionWithVariableLabel = {
|
|
@@ -1780,7 +1764,6 @@ async function promptAndStoreAnswer(environment, questions, existingValues) {
|
|
|
1780
1764
|
}
|
|
1781
1765
|
});
|
|
1782
1766
|
ALL_ANSWERS.push(result);
|
|
1783
|
-
storeSecrets(environment, getAnswers(existingValues));
|
|
1784
1767
|
const existingValuesForQuestions = questions.filter((question) => question.valueType === "VARIABLE").map((question) => [
|
|
1785
1768
|
question.name,
|
|
1786
1769
|
findExistingValue(
|
|
@@ -1792,12 +1775,11 @@ async function promptAndStoreAnswer(environment, questions, existingValues) {
|
|
|
1792
1775
|
]);
|
|
1793
1776
|
return { ...Object.fromEntries(existingValuesForQuestions), ...result };
|
|
1794
1777
|
}
|
|
1795
|
-
var import_core,
|
|
1778
|
+
var import_core, import_kleur4, import_prompts2, ALL_QUESTIONS, ALL_ANSWERS;
|
|
1796
1779
|
var init_setup_environment = __esm({
|
|
1797
1780
|
"src/environment/setup-environment.ts"() {
|
|
1798
1781
|
"use strict";
|
|
1799
1782
|
import_core = require("@octokit/core");
|
|
1800
|
-
import_dotenv2 = __toESM(require("dotenv"));
|
|
1801
1783
|
import_kleur4 = __toESM(require("kleur"));
|
|
1802
1784
|
import_prompts2 = __toESM(require("prompts"));
|
|
1803
1785
|
init_github();
|
|
@@ -1837,11 +1819,7 @@ var init_setup_environment = __esm({
|
|
|
1837
1819
|
}
|
|
1838
1820
|
}
|
|
1839
1821
|
);
|
|
1840
|
-
const { githubToken } = await promptAndStoreAnswer(
|
|
1841
|
-
"",
|
|
1842
|
-
githubTokenQuestion,
|
|
1843
|
-
[]
|
|
1844
|
-
);
|
|
1822
|
+
const { githubToken } = await promptAndStoreAnswer(githubTokenQuestion, []);
|
|
1845
1823
|
const octokit = new import_core.Octokit({
|
|
1846
1824
|
auth: githubToken
|
|
1847
1825
|
});
|
|
@@ -1898,9 +1876,6 @@ var init_setup_environment = __esm({
|
|
|
1898
1876
|
if (!environment) {
|
|
1899
1877
|
process.exit(1);
|
|
1900
1878
|
}
|
|
1901
|
-
import_dotenv2.default.config({
|
|
1902
|
-
path: `${process.cwd()}/.env.${environment}`
|
|
1903
|
-
});
|
|
1904
1879
|
await createEnvironment(
|
|
1905
1880
|
octokit,
|
|
1906
1881
|
environment,
|
|
@@ -1958,17 +1933,12 @@ var init_setup_environment = __esm({
|
|
|
1958
1933
|
"WARNING! You are setting up a production environment.\n Make sure you have read the deployment guide carefully before proceeding.\n"
|
|
1959
1934
|
)
|
|
1960
1935
|
);
|
|
1961
|
-
await promptAndStoreAnswer(
|
|
1962
|
-
environment,
|
|
1963
|
-
githubOtherQuestions,
|
|
1964
|
-
existingValues
|
|
1965
|
-
);
|
|
1936
|
+
await promptAndStoreAnswer(githubOtherQuestions, existingValues);
|
|
1966
1937
|
}
|
|
1967
1938
|
log("\n", import_kleur4.default.bold().underline("Docker Hub"));
|
|
1968
|
-
await promptAndStoreAnswer(
|
|
1939
|
+
await promptAndStoreAnswer(dockerhubQuestions, existingValues);
|
|
1969
1940
|
log("\n", import_kleur4.default.bold().underline("Kubernetes & Runtime"));
|
|
1970
1941
|
const infrastructure = await promptAndStoreAnswer(
|
|
1971
|
-
environment,
|
|
1972
1942
|
infrastructureQuestions,
|
|
1973
1943
|
existingValues
|
|
1974
1944
|
);
|
|
@@ -2029,7 +1999,7 @@ var init_setup_environment = __esm({
|
|
|
2029
1999
|
import_kleur4.default.bold().green("\u2714"),
|
|
2030
2000
|
import_kleur4.default.bold().yellow(" Disk encryption is enabled")
|
|
2031
2001
|
);
|
|
2032
|
-
await promptAndStoreAnswer(
|
|
2002
|
+
await promptAndStoreAnswer(diskQuestions, existingValues);
|
|
2033
2003
|
} else {
|
|
2034
2004
|
if (!enableEncryption && !encryption_key_defined && environment_exists) {
|
|
2035
2005
|
log(
|
|
@@ -2066,6 +2036,7 @@ var init_setup_environment = __esm({
|
|
|
2066
2036
|
"ENVIRONMENT",
|
|
2067
2037
|
existingValues
|
|
2068
2038
|
)?.value;
|
|
2039
|
+
let restoreHost = findExistingValue("RESTORE_HOST", "VARIABLE", "ENVIRONMENT", existingValues)?.value || "";
|
|
2069
2040
|
let restoreType = findExistingValue(
|
|
2070
2041
|
"RESTORE_ENVIRONMENT_MODE",
|
|
2071
2042
|
"VARIABLE",
|
|
@@ -2084,7 +2055,6 @@ var init_setup_environment = __esm({
|
|
|
2084
2055
|
let backupHostPublicKey = "";
|
|
2085
2056
|
if (configureBackup) {
|
|
2086
2057
|
const backupAnswers = await promptAndStoreAnswer(
|
|
2087
|
-
environment,
|
|
2088
2058
|
backupQuestions,
|
|
2089
2059
|
existingValues
|
|
2090
2060
|
);
|
|
@@ -2141,15 +2111,15 @@ var init_setup_environment = __esm({
|
|
|
2141
2111
|
}
|
|
2142
2112
|
]
|
|
2143
2113
|
});
|
|
2114
|
+
restoreHost = await input3({
|
|
2115
|
+
message: "What is the host/IP address of the restore backup server?",
|
|
2116
|
+
default: restoreHost
|
|
2117
|
+
});
|
|
2144
2118
|
} else {
|
|
2145
2119
|
log(import_kleur4.default.bold().green("\u2714"), import_kleur4.default.bold().yellow("Restore is disabled"));
|
|
2146
2120
|
}
|
|
2147
2121
|
log("\n", import_kleur4.default.bold().underline("Monitoring"));
|
|
2148
|
-
await promptAndStoreAnswer(
|
|
2149
|
-
environment,
|
|
2150
|
-
databaseAndMonitoringQuestions,
|
|
2151
|
-
existingValues
|
|
2152
|
-
);
|
|
2122
|
+
await promptAndStoreAnswer(databaseAndMonitoringQuestions, existingValues);
|
|
2153
2123
|
const sentryDSNExists = findExistingValue(
|
|
2154
2124
|
"SENTRY_DSN",
|
|
2155
2125
|
"SECRET",
|
|
@@ -2158,7 +2128,7 @@ var init_setup_environment = __esm({
|
|
|
2158
2128
|
);
|
|
2159
2129
|
log("\n", import_kleur4.default.bold().underline("Sentry"));
|
|
2160
2130
|
if (sentryDSNExists) {
|
|
2161
|
-
await promptAndStoreAnswer(
|
|
2131
|
+
await promptAndStoreAnswer(sentryQuestions, existingValues);
|
|
2162
2132
|
} else {
|
|
2163
2133
|
const { useSentry } = await (0, import_prompts2.default)([
|
|
2164
2134
|
{
|
|
@@ -2169,17 +2139,13 @@ var init_setup_environment = __esm({
|
|
|
2169
2139
|
}
|
|
2170
2140
|
]);
|
|
2171
2141
|
if (useSentry) {
|
|
2172
|
-
await promptAndStoreAnswer(
|
|
2142
|
+
await promptAndStoreAnswer(sentryQuestions, existingValues);
|
|
2173
2143
|
}
|
|
2174
2144
|
}
|
|
2175
2145
|
log("\n", import_kleur4.default.bold().underline("METABASE ADMIN"));
|
|
2176
|
-
await promptAndStoreAnswer(
|
|
2177
|
-
environment,
|
|
2178
|
-
metabaseAdminQuestions,
|
|
2179
|
-
existingValues
|
|
2180
|
-
);
|
|
2146
|
+
await promptAndStoreAnswer(metabaseAdminQuestions, existingValues);
|
|
2181
2147
|
log("\n", import_kleur4.default.bold().underline("SMTP"));
|
|
2182
|
-
await promptAndStoreAnswer(
|
|
2148
|
+
await promptAndStoreAnswer(emailQuestions, existingValues);
|
|
2183
2149
|
const allAnswers = ALL_ANSWERS.reduce((acc, answer) => {
|
|
2184
2150
|
return { ...acc, ...answer };
|
|
2185
2151
|
});
|
|
@@ -2475,6 +2441,27 @@ var init_setup_environment = __esm({
|
|
|
2475
2441
|
existingValues
|
|
2476
2442
|
),
|
|
2477
2443
|
scope: "ENVIRONMENT"
|
|
2444
|
+
},
|
|
2445
|
+
{
|
|
2446
|
+
type: "VARIABLE",
|
|
2447
|
+
name: "RESTORE_HOST",
|
|
2448
|
+
value: answerOrExisting(
|
|
2449
|
+
restoreHost,
|
|
2450
|
+
findExistingValue(
|
|
2451
|
+
"RESTORE_HOST",
|
|
2452
|
+
"VARIABLE",
|
|
2453
|
+
"ENVIRONMENT",
|
|
2454
|
+
existingValues
|
|
2455
|
+
),
|
|
2456
|
+
(val) => val || ""
|
|
2457
|
+
),
|
|
2458
|
+
didExist: findExistingValue(
|
|
2459
|
+
"RESTORE_HOST",
|
|
2460
|
+
"VARIABLE",
|
|
2461
|
+
"ENVIRONMENT",
|
|
2462
|
+
existingValues
|
|
2463
|
+
),
|
|
2464
|
+
scope: "ENVIRONMENT"
|
|
2478
2465
|
}
|
|
2479
2466
|
];
|
|
2480
2467
|
if (enableEncryption) {
|
|
@@ -2521,7 +2508,6 @@ var init_setup_environment = __esm({
|
|
|
2521
2508
|
(variable) => Boolean(variable.value) && // Only update values that changed
|
|
2522
2509
|
(variable.type !== "VARIABLE" || variable.value !== variable.didExist?.value)
|
|
2523
2510
|
);
|
|
2524
|
-
storeSecrets(environment, updates);
|
|
2525
2511
|
const newSecrets = updates.filter(
|
|
2526
2512
|
(update) => update.type === "SECRET" && !update.didExist
|
|
2527
2513
|
);
|
|
@@ -2623,6 +2609,12 @@ var init_setup_environment = __esm({
|
|
|
2623
2609
|
if ([].concat(newSecrets).concat(updatedSecrets).concat(newVariables).concat(updatedVariables).length === 0) {
|
|
2624
2610
|
process.exit(0);
|
|
2625
2611
|
}
|
|
2612
|
+
log(
|
|
2613
|
+
import_kleur4.default.bold().red(
|
|
2614
|
+
"\u26A0\uFE0F COPY THESE NOW INTO A PASSWORD MANAGER \u2014 YOU WON'T SEE THEM AGAIN"
|
|
2615
|
+
)
|
|
2616
|
+
);
|
|
2617
|
+
log("");
|
|
2626
2618
|
const saveChanges = await confirm2({
|
|
2627
2619
|
message: "Do you want to continue?",
|
|
2628
2620
|
default: true
|
|
@@ -2737,12 +2729,14 @@ var init_setup_environment = __esm({
|
|
|
2737
2729
|
// Hardcode like this blocks us from being generic:
|
|
2738
2730
|
// https://github.com/opencrvs/opencrvs-core/issues/11171
|
|
2739
2731
|
two_fa_enabled: environment !== "production" ? false : true,
|
|
2740
|
-
|
|
2732
|
+
traefik_mode: traefikConfOption,
|
|
2741
2733
|
restore_enabled: restoreEnvironmentName ? true : false,
|
|
2742
2734
|
restore_environment_name: restoreEnvironmentName || "",
|
|
2743
2735
|
restore_type: restoreType,
|
|
2744
|
-
|
|
2745
|
-
|
|
2736
|
+
restore_host: restoreHost || "",
|
|
2737
|
+
backup_enabled: configureBackup ? true : false,
|
|
2738
|
+
backup_type: backupType,
|
|
2739
|
+
backup_host: backupHost || ""
|
|
2746
2740
|
});
|
|
2747
2741
|
let addon_message = kubeWorkerNodes.length > 0 || configureBackup ? `--------------------------------------------------------------------------------------------
|
|
2748
2742
|
|
|
@@ -2776,8 +2770,10 @@ ${addon_message}
|
|
|
2776
2770
|
${import_kleur4.default.yellow("\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501")}
|
|
2777
2771
|
${import_kleur4.default.yellow("Please KINDLY read hints above")}
|
|
2778
2772
|
`);
|
|
2779
|
-
log(
|
|
2780
|
-
|
|
2773
|
+
log(
|
|
2774
|
+
"\nAll secrets and variables were printed above.",
|
|
2775
|
+
import_kleur4.default.bold().yellow("Store them in a password manager \u2014 they are not saved to disk.")
|
|
2776
|
+
);
|
|
2781
2777
|
})();
|
|
2782
2778
|
}
|
|
2783
2779
|
});
|
|
@@ -2789,7 +2785,7 @@ __export(update_workflows_exports, {
|
|
|
2789
2785
|
});
|
|
2790
2786
|
function isDirectory(path10) {
|
|
2791
2787
|
try {
|
|
2792
|
-
return (0,
|
|
2788
|
+
return (0, import_fs7.statSync)(path10).isDirectory();
|
|
2793
2789
|
} catch {
|
|
2794
2790
|
return false;
|
|
2795
2791
|
}
|
|
@@ -2811,7 +2807,7 @@ async function extractEnvironmentNames() {
|
|
|
2811
2807
|
const environments = entries.filter((entry) => {
|
|
2812
2808
|
const environmentPath = (0, import_path8.join)("environments", entry);
|
|
2813
2809
|
const opencrvsServicesPath = (0, import_path8.join)(environmentPath, "opencrvs-services");
|
|
2814
|
-
return isDirectory(environmentPath) && (0,
|
|
2810
|
+
return isDirectory(environmentPath) && (0, import_fs7.existsSync)(opencrvsServicesPath) && isDirectory(opencrvsServicesPath);
|
|
2815
2811
|
});
|
|
2816
2812
|
if (environments.length === 0) {
|
|
2817
2813
|
console.log(
|
|
@@ -2836,8 +2832,12 @@ function updateOptionsInYaml(content, envList) {
|
|
|
2836
2832
|
async function updateWorkflows(envList, config) {
|
|
2837
2833
|
const { workflows } = config;
|
|
2838
2834
|
for (const workflowPath of workflows) {
|
|
2835
|
+
if (!(0, import_fs7.existsSync)(workflowPath)) {
|
|
2836
|
+
log(` \u21B7 Skipped ${workflowPath} (not found in this repository)`);
|
|
2837
|
+
continue;
|
|
2838
|
+
}
|
|
2839
2839
|
try {
|
|
2840
|
-
const fileContents = (0,
|
|
2840
|
+
const fileContents = (0, import_fs7.readFileSync)(workflowPath, "utf8");
|
|
2841
2841
|
const workflowData = yaml2.load(fileContents);
|
|
2842
2842
|
if (!workflowData?.on?.workflow_dispatch?.inputs?.environment?.options) {
|
|
2843
2843
|
throw new Error(
|
|
@@ -2845,7 +2845,7 @@ async function updateWorkflows(envList, config) {
|
|
|
2845
2845
|
);
|
|
2846
2846
|
}
|
|
2847
2847
|
const updatedContent = updateOptionsInYaml(fileContents, envList);
|
|
2848
|
-
(0,
|
|
2848
|
+
(0, import_fs7.writeFileSync)(workflowPath, updatedContent, "utf8");
|
|
2849
2849
|
log(` \u2713 Successfully updated ${workflowPath}`);
|
|
2850
2850
|
} catch (error3) {
|
|
2851
2851
|
console.error(
|
|
@@ -2899,12 +2899,12 @@ async function updateWorkflowEnvironments() {
|
|
|
2899
2899
|
process.exit(1);
|
|
2900
2900
|
}
|
|
2901
2901
|
}
|
|
2902
|
-
var import_promises,
|
|
2902
|
+
var import_promises, import_fs7, import_path8, glob2, yaml2;
|
|
2903
2903
|
var init_update_workflows = __esm({
|
|
2904
2904
|
"src/environment/update-workflows.ts"() {
|
|
2905
2905
|
"use strict";
|
|
2906
2906
|
import_promises = require("fs/promises");
|
|
2907
|
-
|
|
2907
|
+
import_fs7 = require("fs");
|
|
2908
2908
|
import_path8 = require("path");
|
|
2909
2909
|
glob2 = __toESM(require("glob"));
|
|
2910
2910
|
yaml2 = __toESM(require("js-yaml"));
|
|
@@ -2919,17 +2919,17 @@ __export(upgrade_exports, {
|
|
|
2919
2919
|
upgradeEnvironmentLayout: () => upgradeEnvironmentLayout
|
|
2920
2920
|
});
|
|
2921
2921
|
function moveFileIfDestinationMissing(sourcePath, destinationPath) {
|
|
2922
|
-
if (!(0,
|
|
2922
|
+
if (!(0, import_fs8.existsSync)(sourcePath)) {
|
|
2923
2923
|
return false;
|
|
2924
2924
|
}
|
|
2925
|
-
if ((0,
|
|
2925
|
+
if ((0, import_fs8.existsSync)(destinationPath)) {
|
|
2926
2926
|
warn(
|
|
2927
2927
|
`\u26A0\uFE0F Skipped ${sourcePath}; destination already exists at ${destinationPath}`
|
|
2928
2928
|
);
|
|
2929
2929
|
return false;
|
|
2930
2930
|
}
|
|
2931
|
-
(0,
|
|
2932
|
-
(0,
|
|
2931
|
+
(0, import_fs8.mkdirSync)((0, import_path9.dirname)(destinationPath), { recursive: true });
|
|
2932
|
+
(0, import_fs8.renameSync)(sourcePath, destinationPath);
|
|
2933
2933
|
log(` \u2713 Moved ${sourcePath} -> ${destinationPath}`);
|
|
2934
2934
|
return true;
|
|
2935
2935
|
}
|
|
@@ -2949,8 +2949,8 @@ function migrateInventoryFiles() {
|
|
|
2949
2949
|
) || didMoveInventory;
|
|
2950
2950
|
}
|
|
2951
2951
|
try {
|
|
2952
|
-
if ((0,
|
|
2953
|
-
(0,
|
|
2952
|
+
if ((0, import_fs8.existsSync)(OLD_INVENTORY_DIR) && (0, import_fs8.readdirSync)(OLD_INVENTORY_DIR).length === 0) {
|
|
2953
|
+
(0, import_fs8.rmdirSync)(OLD_INVENTORY_DIR);
|
|
2954
2954
|
log(` \u2713 Removed empty ${OLD_INVENTORY_DIR}`);
|
|
2955
2955
|
}
|
|
2956
2956
|
} catch {
|
|
@@ -2968,11 +2968,11 @@ async function upgradeEnvironmentLayout() {
|
|
|
2968
2968
|
}
|
|
2969
2969
|
log("\nCommit changes into git after upgrade");
|
|
2970
2970
|
}
|
|
2971
|
-
var
|
|
2971
|
+
var import_fs8, import_path9, import_kleur5;
|
|
2972
2972
|
var init_upgrade = __esm({
|
|
2973
2973
|
"src/environment/upgrade.ts"() {
|
|
2974
2974
|
"use strict";
|
|
2975
|
-
|
|
2975
|
+
import_fs8 = require("fs");
|
|
2976
2976
|
import_path9 = require("path");
|
|
2977
2977
|
import_kleur5 = __toESM(require("kleur"));
|
|
2978
2978
|
init_logger();
|
|
@@ -3225,6 +3225,7 @@ var init_swarm_to_k8s = __esm({
|
|
|
3225
3225
|
// src/migrations/v2.1/add-explicit-correction-flags.ts
|
|
3226
3226
|
var import_ts_morph = require("ts-morph");
|
|
3227
3227
|
var import_path = __toESM(require("path"));
|
|
3228
|
+
var import_fs = require("fs");
|
|
3228
3229
|
var DEFINE_CONFIG_NAME = "defineConfig";
|
|
3229
3230
|
var ACTIONS_PROPERTY_NAME = "actions";
|
|
3230
3231
|
var TYPE_PROPERTY_NAME = "type";
|
|
@@ -3232,6 +3233,11 @@ var FLAGS_PROPERTY_NAME = "flags";
|
|
|
3232
3233
|
var CONDITIONALS_PROPERTY_NAME = "conditionals";
|
|
3233
3234
|
var ACTION_TYPE_ENUM_NAME = "ActionType";
|
|
3234
3235
|
var REQUEST_CORRECTION_TYPE = "REQUEST_CORRECTION";
|
|
3236
|
+
var skipped = [];
|
|
3237
|
+
function warnSkipped(message) {
|
|
3238
|
+
skipped.push(message);
|
|
3239
|
+
console.warn(` \u26A0\uFE0F ${message}`);
|
|
3240
|
+
}
|
|
3235
3241
|
var CORRECTION_ACTIONS_TO_ADD = [
|
|
3236
3242
|
{
|
|
3237
3243
|
actionType: "APPROVE_CORRECTION",
|
|
@@ -3297,8 +3303,9 @@ function buildCorrectionActionText(spec, typeStyle, flagsText, conditionalsText)
|
|
|
3297
3303
|
}
|
|
3298
3304
|
function processFile(filePath, project) {
|
|
3299
3305
|
const sourceFile = project.getSourceFile(filePath);
|
|
3300
|
-
if (!sourceFile) return 0;
|
|
3306
|
+
if (!sourceFile) return { changes: 0, defineConfigs: 0 };
|
|
3301
3307
|
let changes = 0;
|
|
3308
|
+
let defineConfigs = 0;
|
|
3302
3309
|
const relPath = import_path.default.relative(process.cwd(), filePath);
|
|
3303
3310
|
const callExpressions = sourceFile.getDescendantsOfKind(
|
|
3304
3311
|
import_ts_morph.SyntaxKind.CallExpression
|
|
@@ -3308,6 +3315,7 @@ function processFile(filePath, project) {
|
|
|
3308
3315
|
if (!import_ts_morph.Node.isIdentifier(expression) || expression.getText() !== DEFINE_CONFIG_NAME) {
|
|
3309
3316
|
continue;
|
|
3310
3317
|
}
|
|
3318
|
+
defineConfigs++;
|
|
3311
3319
|
const args2 = call.getArguments();
|
|
3312
3320
|
if (args2.length === 0) continue;
|
|
3313
3321
|
const configArg = args2[0];
|
|
@@ -3354,14 +3362,21 @@ function processFile(filePath, project) {
|
|
|
3354
3362
|
);
|
|
3355
3363
|
}
|
|
3356
3364
|
}
|
|
3357
|
-
return changes;
|
|
3365
|
+
return { changes, defineConfigs };
|
|
3358
3366
|
}
|
|
3359
3367
|
async function main() {
|
|
3360
3368
|
const srcDir = import_path.default.join(process.cwd(), "src");
|
|
3369
|
+
const tsConfigFilePath = import_path.default.resolve(srcDir, "../tsconfig.json");
|
|
3361
3370
|
console.log(`Scanning for defineConfig calls in: ${srcDir}
|
|
3362
3371
|
`);
|
|
3372
|
+
if (!(0, import_fs.existsSync)(tsConfigFilePath)) {
|
|
3373
|
+
warnSkipped(
|
|
3374
|
+
`tsconfig.json not found next to ${srcDir}, so no source could be read; add APPROVE_CORRECTION/REJECT_CORRECTION action configs by hand wherever REQUEST_CORRECTION sets flags or conditionals`
|
|
3375
|
+
);
|
|
3376
|
+
return skipped;
|
|
3377
|
+
}
|
|
3363
3378
|
const project = new import_ts_morph.Project({
|
|
3364
|
-
tsConfigFilePath
|
|
3379
|
+
tsConfigFilePath,
|
|
3365
3380
|
skipAddingFilesFromTsConfig: false
|
|
3366
3381
|
});
|
|
3367
3382
|
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
@@ -3371,20 +3386,28 @@ async function main() {
|
|
|
3371
3386
|
console.log(`Found ${sourceFiles.length} source file(s) to analyse.
|
|
3372
3387
|
`);
|
|
3373
3388
|
let totalChanges = 0;
|
|
3389
|
+
let totalDefineConfigs = 0;
|
|
3374
3390
|
const modifiedFiles = [];
|
|
3375
3391
|
for (const sourceFile of sourceFiles) {
|
|
3376
3392
|
const filePath = sourceFile.getFilePath();
|
|
3377
|
-
const changes = processFile(filePath, project);
|
|
3393
|
+
const { changes, defineConfigs } = processFile(filePath, project);
|
|
3394
|
+
totalDefineConfigs += defineConfigs;
|
|
3378
3395
|
if (changes > 0) {
|
|
3379
3396
|
totalChanges += changes;
|
|
3380
3397
|
modifiedFiles.push(filePath);
|
|
3381
3398
|
}
|
|
3382
3399
|
}
|
|
3400
|
+
if (totalDefineConfigs === 0) {
|
|
3401
|
+
warnSkipped(
|
|
3402
|
+
"No defineConfig call was found under src/, so no event configuration could be inspected; check by hand that any flags or conditionals on REQUEST_CORRECTION are repeated on APPROVE_CORRECTION and REJECT_CORRECTION"
|
|
3403
|
+
);
|
|
3404
|
+
return skipped;
|
|
3405
|
+
}
|
|
3383
3406
|
if (modifiedFiles.length === 0) {
|
|
3384
3407
|
console.log(
|
|
3385
|
-
|
|
3408
|
+
`No REQUEST_CORRECTION actions with flags/conditionals found across ${totalDefineConfigs} defineConfig call(s). Nothing to do.`
|
|
3386
3409
|
);
|
|
3387
|
-
return;
|
|
3410
|
+
return skipped;
|
|
3388
3411
|
}
|
|
3389
3412
|
console.log(`
|
|
3390
3413
|
Saving ${modifiedFiles.length} modified file(s)...`);
|
|
@@ -3397,15 +3420,16 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
3397
3420
|
`
|
|
3398
3421
|
Done. Added ${totalChanges} correction action config(s) across ${modifiedFiles.length} file(s).`
|
|
3399
3422
|
);
|
|
3423
|
+
return skipped;
|
|
3400
3424
|
}
|
|
3401
3425
|
|
|
3402
3426
|
// src/migrations/v2.1/add-recovery-link-notifications.ts
|
|
3403
3427
|
var import_ts_morph2 = require("ts-morph");
|
|
3404
|
-
var
|
|
3428
|
+
var import_fs3 = require("fs");
|
|
3405
3429
|
var import_path2 = __toESM(require("path"));
|
|
3406
3430
|
|
|
3407
3431
|
// src/csv.ts
|
|
3408
|
-
var
|
|
3432
|
+
var import_fs2 = require("fs");
|
|
3409
3433
|
function parseCsvLine(line2) {
|
|
3410
3434
|
const values = [];
|
|
3411
3435
|
let value = "";
|
|
@@ -3445,10 +3469,10 @@ function idOf(line2) {
|
|
|
3445
3469
|
return comma === -1 ? line2 : line2.slice(0, comma);
|
|
3446
3470
|
}
|
|
3447
3471
|
function readCsvFile(path10) {
|
|
3448
|
-
if (!(0,
|
|
3472
|
+
if (!(0, import_fs2.existsSync)(path10)) {
|
|
3449
3473
|
return void 0;
|
|
3450
3474
|
}
|
|
3451
|
-
const contents = (0,
|
|
3475
|
+
const contents = (0, import_fs2.readFileSync)(path10, "utf8");
|
|
3452
3476
|
const newline = contents.includes("\r\n") ? "\r\n" : "\n";
|
|
3453
3477
|
const trailingNewline = /\r?\n$/.test(contents);
|
|
3454
3478
|
const lines = contents.replace(/\r?\n$/, "").split(/\r?\n/);
|
|
@@ -3456,7 +3480,7 @@ function readCsvFile(path10) {
|
|
|
3456
3480
|
return { header: lines[0], body, newline, trailingNewline };
|
|
3457
3481
|
}
|
|
3458
3482
|
function writeCsvFile(path10, file) {
|
|
3459
|
-
(0,
|
|
3483
|
+
(0, import_fs2.writeFileSync)(
|
|
3460
3484
|
path10,
|
|
3461
3485
|
[file.header, ...file.body].join(file.newline) + (file.trailingNewline ? file.newline : "")
|
|
3462
3486
|
);
|
|
@@ -3531,9 +3555,9 @@ var LOGIN_CSV_ROWS = [
|
|
|
3531
3555
|
`resetCredentials.recoveryLinkLanding.expired.link,Link back to the forgotten item form shown on an expired/invalid recovery link,Start again,Recommencer`,
|
|
3532
3556
|
`resetCredentials.recoveryLinkLanding.expired.title,"Title shown when a recovery link is invalid, expired, or already used",This link has expired,Ce lien a expir\xE9`
|
|
3533
3557
|
];
|
|
3534
|
-
var
|
|
3535
|
-
function
|
|
3536
|
-
|
|
3558
|
+
var skipped2 = [];
|
|
3559
|
+
function warnSkipped2(message) {
|
|
3560
|
+
skipped2.push(message);
|
|
3537
3561
|
console.warn(` \u26A0\uFE0F ${message}`);
|
|
3538
3562
|
}
|
|
3539
3563
|
function findObjectLiteral(declaration) {
|
|
@@ -3588,14 +3612,14 @@ function renderKeyFor(sourceFile, objectName, key, constant) {
|
|
|
3588
3612
|
function updateEmailTemplates(project, cwd) {
|
|
3589
3613
|
const sourceFile = project.getSourceFile(import_path2.default.join(cwd, EMAIL_TEMPLATES_FILE));
|
|
3590
3614
|
if (!sourceFile) {
|
|
3591
|
-
|
|
3615
|
+
warnSkipped2(`${EMAIL_TEMPLATES_FILE} not found; email templates not wired`);
|
|
3592
3616
|
return;
|
|
3593
3617
|
}
|
|
3594
3618
|
const missingObject = [TRIGGER_VARIABLE_OBJECT, TEMPLATES_OBJECT].find(
|
|
3595
3619
|
(objectName) => !findObjectLiteral(sourceFile.getVariableDeclaration(objectName))
|
|
3596
3620
|
);
|
|
3597
3621
|
if (missingObject) {
|
|
3598
|
-
|
|
3622
|
+
warnSkipped2(
|
|
3599
3623
|
`Could not find '${missingObject}' in ${EMAIL_TEMPLATES_FILE}; email templates not wired`
|
|
3600
3624
|
);
|
|
3601
3625
|
return;
|
|
@@ -3652,7 +3676,7 @@ function updateEmailTemplates(project, cwd) {
|
|
|
3652
3676
|
function updateSmsService(project, cwd) {
|
|
3653
3677
|
const sourceFile = project.getSourceFile(import_path2.default.join(cwd, SMS_SERVICE_FILE));
|
|
3654
3678
|
if (!sourceFile) {
|
|
3655
|
-
|
|
3679
|
+
warnSkipped2(`${SMS_SERVICE_FILE} not found; SMS templates not wired`);
|
|
3656
3680
|
return;
|
|
3657
3681
|
}
|
|
3658
3682
|
const missingObject = [
|
|
@@ -3662,7 +3686,7 @@ function updateSmsService(project, cwd) {
|
|
|
3662
3686
|
(objectName) => !findObjectLiteral(sourceFile.getVariableDeclaration(objectName))
|
|
3663
3687
|
);
|
|
3664
3688
|
if (missingObject) {
|
|
3665
|
-
|
|
3689
|
+
warnSkipped2(
|
|
3666
3690
|
`Could not find '${missingObject}' in ${SMS_SERVICE_FILE}; SMS templates not wired`
|
|
3667
3691
|
);
|
|
3668
3692
|
return;
|
|
@@ -3703,13 +3727,13 @@ function updateSmsService(project, cwd) {
|
|
|
3703
3727
|
function updateHandler(project, cwd) {
|
|
3704
3728
|
const sourceFile = project.getSourceFile(import_path2.default.join(cwd, HANDLER_FILE));
|
|
3705
3729
|
if (!sourceFile) {
|
|
3706
|
-
|
|
3730
|
+
warnSkipped2(`${HANDLER_FILE} not found; payload conversion not wired`);
|
|
3707
3731
|
return;
|
|
3708
3732
|
}
|
|
3709
3733
|
const convertPayload = sourceFile.getFunction(CONVERT_PAYLOAD_FUNCTION);
|
|
3710
3734
|
const caseBlock = convertPayload?.getFirstDescendantByKind(import_ts_morph2.SyntaxKind.SwitchStatement)?.getCaseBlock();
|
|
3711
3735
|
if (!caseBlock) {
|
|
3712
|
-
|
|
3736
|
+
warnSkipped2(
|
|
3713
3737
|
`Could not find a switch inside '${CONVERT_PAYLOAD_FUNCTION}' in ${HANDLER_FILE}; payload conversion not wired`
|
|
3714
3738
|
);
|
|
3715
3739
|
return;
|
|
@@ -3720,7 +3744,7 @@ function updateHandler(project, cwd) {
|
|
|
3720
3744
|
if (missing.length === 0) return;
|
|
3721
3745
|
const existingClauses = caseBlock.getClauses();
|
|
3722
3746
|
if (existingClauses.length === 0) {
|
|
3723
|
-
|
|
3747
|
+
warnSkipped2(
|
|
3724
3748
|
`The switch inside '${CONVERT_PAYLOAD_FUNCTION}' in ${HANDLER_FILE} has no cases; payload conversion not wired`
|
|
3725
3749
|
);
|
|
3726
3750
|
return;
|
|
@@ -3757,13 +3781,13 @@ ${lines.map((line2) => `${indent}${line2}`).join("\n")}`
|
|
|
3757
3781
|
function updateRoutes(project, cwd) {
|
|
3758
3782
|
const sourceFile = project.getSourceFile(import_path2.default.join(cwd, ROUTES_FILE));
|
|
3759
3783
|
if (!sourceFile) {
|
|
3760
|
-
|
|
3784
|
+
warnSkipped2(`${ROUTES_FILE} not found; trigger routes not registered`);
|
|
3761
3785
|
return;
|
|
3762
3786
|
}
|
|
3763
3787
|
const routesFunction = sourceFile.getFunction(ROUTES_FUNCTION) ?? sourceFile.getFunctions().find((fn) => fn.isDefaultExport());
|
|
3764
3788
|
const routesArray = routesFunction?.getFirstDescendantByKind(import_ts_morph2.SyntaxKind.ReturnStatement)?.getExpressionIfKind(import_ts_morph2.SyntaxKind.ArrayLiteralExpression);
|
|
3765
3789
|
if (!routesArray) {
|
|
3766
|
-
|
|
3790
|
+
warnSkipped2(
|
|
3767
3791
|
`Could not find the route array returned by '${ROUTES_FUNCTION}' in ${ROUTES_FILE}; trigger routes not registered`
|
|
3768
3792
|
);
|
|
3769
3793
|
return;
|
|
@@ -3861,16 +3885,16 @@ Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencr
|
|
|
3861
3885
|
}
|
|
3862
3886
|
function writeEmailTemplates(cwd) {
|
|
3863
3887
|
const templateDir = import_path2.default.join(cwd, EMAIL_TEMPLATE_DIR);
|
|
3864
|
-
if (!(0,
|
|
3865
|
-
|
|
3888
|
+
if (!(0, import_fs3.existsSync)(templateDir)) {
|
|
3889
|
+
warnSkipped2(
|
|
3866
3890
|
`${EMAIL_TEMPLATE_DIR} not found; recovery email bodies not written`
|
|
3867
3891
|
);
|
|
3868
3892
|
return;
|
|
3869
3893
|
}
|
|
3870
3894
|
for (const event of RECOVERY_EVENTS) {
|
|
3871
3895
|
const templatePath = import_path2.default.join(templateDir, `${event.id}.html`);
|
|
3872
|
-
if ((0,
|
|
3873
|
-
(0,
|
|
3896
|
+
if ((0, import_fs3.existsSync)(templatePath)) continue;
|
|
3897
|
+
(0, import_fs3.writeFileSync)(templatePath, renderEmailTemplate(event));
|
|
3874
3898
|
console.log(` \u2713 ${EMAIL_TEMPLATE_DIR}/${event.id}.html`);
|
|
3875
3899
|
}
|
|
3876
3900
|
}
|
|
@@ -3878,7 +3902,7 @@ function addCsvRows(cwd, relativePath, rows) {
|
|
|
3878
3902
|
const csvPath = import_path2.default.join(cwd, relativePath);
|
|
3879
3903
|
const file = readCsvFile(csvPath);
|
|
3880
3904
|
if (!file) {
|
|
3881
|
-
|
|
3905
|
+
warnSkipped2(`${relativePath} not found; translations not added`);
|
|
3882
3906
|
return;
|
|
3883
3907
|
}
|
|
3884
3908
|
const added = addRows(file, rows);
|
|
@@ -3894,11 +3918,11 @@ async function main2() {
|
|
|
3894
3918
|
console.log(
|
|
3895
3919
|
"Registering the password-reset-link and username-reminder-link notifications...\n"
|
|
3896
3920
|
);
|
|
3897
|
-
if (!(0,
|
|
3898
|
-
|
|
3921
|
+
if (!(0, import_fs3.existsSync)(tsConfigFilePath)) {
|
|
3922
|
+
warnSkipped2(
|
|
3899
3923
|
`tsconfig.json not found in ${cwd}; notification wiring skipped entirely`
|
|
3900
3924
|
);
|
|
3901
|
-
return;
|
|
3925
|
+
return skipped2;
|
|
3902
3926
|
}
|
|
3903
3927
|
const project = new import_ts_morph2.Project({
|
|
3904
3928
|
tsConfigFilePath,
|
|
@@ -3915,15 +3939,7 @@ async function main2() {
|
|
|
3915
3939
|
writeEmailTemplates(cwd);
|
|
3916
3940
|
addCsvRows(cwd, NOTIFICATION_CSV, NOTIFICATION_CSV_ROWS);
|
|
3917
3941
|
addCsvRows(cwd, LOGIN_CSV, LOGIN_CSV_ROWS);
|
|
3918
|
-
|
|
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
|
-
}
|
|
3942
|
+
return skipped2;
|
|
3927
3943
|
}
|
|
3928
3944
|
|
|
3929
3945
|
// src/migrations/v2.1/add-translations.ts
|
|
@@ -3932,9 +3948,9 @@ var REPOSITORY = "opencrvs/opencrvs-core";
|
|
|
3932
3948
|
var TEMPLATE_TRANSLATIONS = "packages/countryconfig-template/src/translations";
|
|
3933
3949
|
var APPLICATIONS = ["client", "login"];
|
|
3934
3950
|
var TARGET_VERSION = "2.1";
|
|
3935
|
-
var
|
|
3936
|
-
function
|
|
3937
|
-
|
|
3951
|
+
var skipped3 = [];
|
|
3952
|
+
function warnSkipped3(message) {
|
|
3953
|
+
skipped3.push(message);
|
|
3938
3954
|
console.warn(` \u26A0\uFE0F ${message}`);
|
|
3939
3955
|
}
|
|
3940
3956
|
async function matchingRefs(namespace, prefix) {
|
|
@@ -3971,7 +3987,7 @@ async function fetchTemplate(refs, application) {
|
|
|
3971
3987
|
);
|
|
3972
3988
|
}
|
|
3973
3989
|
}
|
|
3974
|
-
|
|
3990
|
+
warnSkipped3(
|
|
3975
3991
|
`No ${application}.csv found in the ${TARGET_VERSION} country config template on GitHub; ${application}.csv not updated`
|
|
3976
3992
|
);
|
|
3977
3993
|
return void 0;
|
|
@@ -3993,7 +4009,7 @@ async function updateApplication(cwd, refs, application) {
|
|
|
3993
4009
|
const relativePath = `src/translations/${application}.csv`;
|
|
3994
4010
|
const local = readCsvFile(import_path3.default.join(cwd, relativePath));
|
|
3995
4011
|
if (!local) {
|
|
3996
|
-
|
|
4012
|
+
warnSkipped3(`${relativePath} not found; translations not added`);
|
|
3997
4013
|
return;
|
|
3998
4014
|
}
|
|
3999
4015
|
const fetched = await fetchTemplate(refs, application);
|
|
@@ -4008,7 +4024,7 @@ async function updateApplication(cwd, refs, application) {
|
|
|
4008
4024
|
try {
|
|
4009
4025
|
writeCsvFile(import_path3.default.join(cwd, relativePath), local);
|
|
4010
4026
|
} catch (error3) {
|
|
4011
|
-
|
|
4027
|
+
warnSkipped3(
|
|
4012
4028
|
`Could not write ${relativePath} (${error3.message}); translations not added`
|
|
4013
4029
|
);
|
|
4014
4030
|
return;
|
|
@@ -4030,7 +4046,7 @@ async function listRefs() {
|
|
|
4030
4046
|
try {
|
|
4031
4047
|
return await candidateRefs();
|
|
4032
4048
|
} catch (error3) {
|
|
4033
|
-
|
|
4049
|
+
warnSkipped3(
|
|
4034
4050
|
`Could not list the ${TARGET_VERSION} refs on GitHub (${error3.message}); translations not added`
|
|
4035
4051
|
);
|
|
4036
4052
|
return void 0;
|
|
@@ -4045,34 +4061,26 @@ async function main3() {
|
|
|
4045
4061
|
try {
|
|
4046
4062
|
await updateApplication(cwd, refs, application);
|
|
4047
4063
|
} catch (error3) {
|
|
4048
|
-
|
|
4064
|
+
warnSkipped3(
|
|
4049
4065
|
`Could not read ${application}.csv from the country config template on GitHub (${error3.message}); ${application}.csv not updated`
|
|
4050
4066
|
);
|
|
4051
4067
|
}
|
|
4052
4068
|
}
|
|
4053
4069
|
}
|
|
4054
|
-
|
|
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
|
-
}
|
|
4070
|
+
return skipped3;
|
|
4063
4071
|
}
|
|
4064
4072
|
|
|
4065
4073
|
// src/migrations/v2.1/enable-telemetry.ts
|
|
4066
4074
|
var import_ts_morph3 = require("ts-morph");
|
|
4067
|
-
var
|
|
4075
|
+
var import_fs4 = require("fs");
|
|
4068
4076
|
var import_path4 = __toESM(require("path"));
|
|
4069
4077
|
var HANDLER_FILE2 = "src/api/telemetry/handler.ts";
|
|
4070
4078
|
var ENVIRONMENT_FILE = "src/environment.ts";
|
|
4071
4079
|
var INDEX_FILE = "src/index.ts";
|
|
4072
4080
|
var HANDLER_MODULE = "./api/telemetry/handler";
|
|
4073
|
-
var
|
|
4074
|
-
function
|
|
4075
|
-
|
|
4081
|
+
var skipped4 = [];
|
|
4082
|
+
function warnSkipped4(message) {
|
|
4083
|
+
skipped4.push(message);
|
|
4076
4084
|
console.warn(` \u26A0\uFE0F ${message}`);
|
|
4077
4085
|
}
|
|
4078
4086
|
var TELEMETRY_HANDLER_SOURCE = `/*
|
|
@@ -4203,7 +4211,7 @@ async function promptTelemetryConfig() {
|
|
|
4203
4211
|
if (!process.stdin.isTTY) {
|
|
4204
4212
|
return TELEMETRY_DISABLED;
|
|
4205
4213
|
}
|
|
4206
|
-
const { confirm: confirm3, input:
|
|
4214
|
+
const { confirm: confirm3, input: input4 } = await import("@inquirer/prompts");
|
|
4207
4215
|
const enabled = await confirm3({
|
|
4208
4216
|
message: "Enable anonymous usage telemetry to help improve OpenCRVS? Only aggregate metrics are shared \u2014 no personal or protected data.",
|
|
4209
4217
|
default: true
|
|
@@ -4211,11 +4219,11 @@ async function promptTelemetryConfig() {
|
|
|
4211
4219
|
if (!enabled) {
|
|
4212
4220
|
return TELEMETRY_DISABLED;
|
|
4213
4221
|
}
|
|
4214
|
-
const countryCode = (await
|
|
4222
|
+
const countryCode = (await input4({
|
|
4215
4223
|
message: "Country code (ISO alpha-3, e.g. FAR):",
|
|
4216
4224
|
validate: (value) => /^[A-Za-z]{3}$/.test(value.trim()) || "Enter a 3-letter ISO alpha-3 code."
|
|
4217
4225
|
})).trim().toUpperCase();
|
|
4218
|
-
const organisation = (await
|
|
4226
|
+
const organisation = (await input4({
|
|
4219
4227
|
message: "Organisation running this instance:",
|
|
4220
4228
|
validate: (value) => value.trim() !== "" || "Enter an organisation name."
|
|
4221
4229
|
})).trim();
|
|
@@ -4223,12 +4231,12 @@ async function promptTelemetryConfig() {
|
|
|
4223
4231
|
}
|
|
4224
4232
|
function writeTelemetryHandler(cwd) {
|
|
4225
4233
|
const handlerPath = import_path4.default.join(cwd, HANDLER_FILE2);
|
|
4226
|
-
if ((0,
|
|
4234
|
+
if ((0, import_fs4.existsSync)(handlerPath)) {
|
|
4227
4235
|
console.log(` ${HANDLER_FILE2} already present; left unchanged`);
|
|
4228
4236
|
return;
|
|
4229
4237
|
}
|
|
4230
|
-
(0,
|
|
4231
|
-
(0,
|
|
4238
|
+
(0, import_fs4.mkdirSync)(import_path4.default.dirname(handlerPath), { recursive: true });
|
|
4239
|
+
(0, import_fs4.writeFileSync)(handlerPath, TELEMETRY_HANDLER_SOURCE);
|
|
4232
4240
|
console.log(` \u2713 ${HANDLER_FILE2}`);
|
|
4233
4241
|
}
|
|
4234
4242
|
function appendProperty(sourceFile, object, name, valueLines) {
|
|
@@ -4244,7 +4252,7 @@ ${entry}`);
|
|
|
4244
4252
|
function ensureEnvalidNamedImports(sourceFile, names) {
|
|
4245
4253
|
const importDeclaration = sourceFile.getImportDeclarations().find((declaration) => declaration.getModuleSpecifierValue() === "envalid");
|
|
4246
4254
|
if (!importDeclaration) {
|
|
4247
|
-
|
|
4255
|
+
warnSkipped4(
|
|
4248
4256
|
`Could not find the 'envalid' import in ${ENVIRONMENT_FILE}; import { ${names.join(", ")} } by hand`
|
|
4249
4257
|
);
|
|
4250
4258
|
return;
|
|
@@ -4297,13 +4305,13 @@ function addEnvironmentVariables(project, cwd, config) {
|
|
|
4297
4305
|
import_path4.default.join(cwd, ENVIRONMENT_FILE)
|
|
4298
4306
|
);
|
|
4299
4307
|
if (!sourceFile) {
|
|
4300
|
-
|
|
4308
|
+
warnSkipped4(
|
|
4301
4309
|
`${ENVIRONMENT_FILE} not found; add the telemetry env vars by hand`
|
|
4302
4310
|
);
|
|
4303
4311
|
return;
|
|
4304
4312
|
}
|
|
4305
4313
|
if (!getCleanEnvObject(sourceFile)) {
|
|
4306
|
-
|
|
4314
|
+
warnSkipped4(
|
|
4307
4315
|
`Could not find the cleanEnv(...) config object in ${ENVIRONMENT_FILE}; add the telemetry env vars by hand`
|
|
4308
4316
|
);
|
|
4309
4317
|
return;
|
|
@@ -4347,7 +4355,7 @@ function wireIndex(project, cwd) {
|
|
|
4347
4355
|
import_path4.default.join(cwd, INDEX_FILE)
|
|
4348
4356
|
);
|
|
4349
4357
|
if (!sourceFile) {
|
|
4350
|
-
|
|
4358
|
+
warnSkipped4(
|
|
4351
4359
|
`${INDEX_FILE} not found; register POST /trigger/telemetry and the startup notice by hand`
|
|
4352
4360
|
);
|
|
4353
4361
|
return;
|
|
@@ -4370,7 +4378,7 @@ function wireIndex(project, cwd) {
|
|
|
4370
4378
|
(statement) => Boolean(statement)
|
|
4371
4379
|
).pop();
|
|
4372
4380
|
if (!lastRouteStatement) {
|
|
4373
|
-
|
|
4381
|
+
warnSkipped4(
|
|
4374
4382
|
`Could not find a server.route(...) call in ${INDEX_FILE}; register POST /trigger/telemetry by hand`
|
|
4375
4383
|
);
|
|
4376
4384
|
} else {
|
|
@@ -4401,7 +4409,7 @@ ${route}`);
|
|
|
4401
4409
|
(statement) => statement.getText().includes("Server successfully started")
|
|
4402
4410
|
);
|
|
4403
4411
|
if (!startedLog) {
|
|
4404
|
-
|
|
4412
|
+
warnSkipped4(
|
|
4405
4413
|
`Could not find the startup log in ${INDEX_FILE}; log TELEMETRY_DISABLED_NOTICE when TELEMETRY_ENABLED is false by hand`
|
|
4406
4414
|
);
|
|
4407
4415
|
} else {
|
|
@@ -4416,7 +4424,7 @@ ${route}`);
|
|
|
4416
4424
|
${notice}`);
|
|
4417
4425
|
console.log(` \u2713 ${INDEX_FILE}: telemetry-disabled startup notice`);
|
|
4418
4426
|
if (!sourceFile.getImportDeclarations().some((d) => d.getModuleSpecifierValue() === "./environment")) {
|
|
4419
|
-
|
|
4427
|
+
warnSkipped4(
|
|
4420
4428
|
`The startup notice reads env.TELEMETRY_ENABLED but ${INDEX_FILE} does not import env from './environment'; import it by hand`
|
|
4421
4429
|
);
|
|
4422
4430
|
}
|
|
@@ -4443,23 +4451,27 @@ Adding daily usage telemetry (${config.enabled ? `enabled for ${config.countryCo
|
|
|
4443
4451
|
addEnvironmentVariables(project, cwd, config);
|
|
4444
4452
|
wireIndex(project, cwd);
|
|
4445
4453
|
await project.save();
|
|
4446
|
-
|
|
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
|
-
}
|
|
4454
|
+
return skipped4;
|
|
4455
4455
|
}
|
|
4456
4456
|
|
|
4457
4457
|
// src/migrations/v2.1/index.ts
|
|
4458
|
+
var DOCKER_SWARM_MANUAL_STEPS = [
|
|
4459
|
+
"Remove the `mongo1` and `influxdb` services from your compose files \u2014 MongoDB and InfluxDB are gone in this release.",
|
|
4460
|
+
"Remove the `legacy-data-migration` service from your compose files. It only ever migrated MongoDB data during the v2.0 upgrade, and the migration it ran no longer exists.",
|
|
4461
|
+
"Change the postgres image from `docker.io/chumaky/postgres_mongo_fdw:17.6_fdw5.5.2` back to `postgres:17.6`. The `mongo_fdw` build was only needed for the v2.0 legacy-data migration.",
|
|
4462
|
+
"Run `DROP EXTENSION mongo_fdw CASCADE;` against the events database as a Postgres superuser, if this deployment came through v2.0. It has to be a superuser: the extension is owned by the one that ran the v2.0 legacy migration, not by the role the migrations run as. Until it is dropped, a pg_dump/pg_restore of the database into a v2.1 cluster fails.",
|
|
4463
|
+
"Run `assets/deployment/reindex.sh` after deploying. `deploy.sh` does not call it, and this release adds `legalStatuses.NOTIFIED` to the Elasticsearch mapping, so records indexed before the upgrade carry none of it until a reindex."
|
|
4464
|
+
];
|
|
4458
4465
|
async function runUpgrade(dockerSwarm) {
|
|
4459
|
-
|
|
4460
|
-
await
|
|
4461
|
-
await
|
|
4462
|
-
await
|
|
4466
|
+
const outstanding = [];
|
|
4467
|
+
outstanding.push(...await main());
|
|
4468
|
+
outstanding.push(...await main2());
|
|
4469
|
+
outstanding.push(...await main3());
|
|
4470
|
+
outstanding.push(...await main4());
|
|
4471
|
+
if (dockerSwarm) {
|
|
4472
|
+
outstanding.push(...DOCKER_SWARM_MANUAL_STEPS);
|
|
4473
|
+
}
|
|
4474
|
+
return { outstanding };
|
|
4463
4475
|
}
|
|
4464
4476
|
|
|
4465
4477
|
// src/translations/check.ts
|
|
@@ -4526,10 +4538,12 @@ function check(cwd) {
|
|
|
4526
4538
|
return { missing, outdated, dynamicIds };
|
|
4527
4539
|
}
|
|
4528
4540
|
function writeMissing(cwd, missing) {
|
|
4529
|
-
const file = readCsvFile(import_path5.default.join(cwd, OWN_FILE))
|
|
4530
|
-
|
|
4531
|
-
|
|
4532
|
-
|
|
4541
|
+
const file = readCsvFile(import_path5.default.join(cwd, OWN_FILE)) ?? {
|
|
4542
|
+
header: "id,description,en",
|
|
4543
|
+
body: [],
|
|
4544
|
+
newline: "\n",
|
|
4545
|
+
trailingNewline: true
|
|
4546
|
+
};
|
|
4533
4547
|
const columns = file.header.split(",");
|
|
4534
4548
|
const rows = missing.map(
|
|
4535
4549
|
(message) => toCsvLine(
|
|
@@ -4546,7 +4560,7 @@ function writeMissing(cwd, missing) {
|
|
|
4546
4560
|
}
|
|
4547
4561
|
|
|
4548
4562
|
// src/environment/index.ts
|
|
4549
|
-
var
|
|
4563
|
+
var import_fs9 = require("fs");
|
|
4550
4564
|
var import_path10 = require("path");
|
|
4551
4565
|
init_paths();
|
|
4552
4566
|
var REQUIRED_REPOSITORY_DIRECTORIES = [
|
|
@@ -4558,7 +4572,7 @@ function validateRepositoryStructure(repositoryRoot = process.cwd()) {
|
|
|
4558
4572
|
const missingDirectories = REQUIRED_REPOSITORY_DIRECTORIES.filter(
|
|
4559
4573
|
(directory) => {
|
|
4560
4574
|
try {
|
|
4561
|
-
return !(0,
|
|
4575
|
+
return !(0, import_fs9.statSync)((0, import_path10.resolve)(repositoryRoot, directory)).isDirectory();
|
|
4562
4576
|
} catch {
|
|
4563
4577
|
return true;
|
|
4564
4578
|
}
|
|
@@ -4725,8 +4739,8 @@ async function fetchEventConfigs(baseUrl) {
|
|
|
4725
4739
|
clearTimeout(timer);
|
|
4726
4740
|
}
|
|
4727
4741
|
}
|
|
4728
|
-
function resolveBaseUrl(
|
|
4729
|
-
const withProtocol = /^https?:\/\//i.test(
|
|
4742
|
+
function resolveBaseUrl(input4) {
|
|
4743
|
+
const withProtocol = /^https?:\/\//i.test(input4) ? input4 : `https://${input4}`;
|
|
4730
4744
|
return withProtocol.replace(/\/+$/, "");
|
|
4731
4745
|
}
|
|
4732
4746
|
function describeStatus(status) {
|
|
@@ -4751,7 +4765,7 @@ function securedDetail(status) {
|
|
|
4751
4765
|
if (status === "error") {
|
|
4752
4766
|
return `${describeStatus(status)} \u2014 request failed`;
|
|
4753
4767
|
}
|
|
4754
|
-
return `${describeStatus(status)} \u2014 INSECURE:
|
|
4768
|
+
return `${describeStatus(status)} \u2014 INSECURE: ensure this endpoint requires authentication!`;
|
|
4755
4769
|
}
|
|
4756
4770
|
async function runVerifyEndpoints(target = DEFAULT_TARGET_URL) {
|
|
4757
4771
|
const baseUrl = resolveBaseUrl(target);
|
|
@@ -4862,9 +4876,163 @@ async function runVerifyEndpoints(target = DEFAULT_TARGET_URL) {
|
|
|
4862
4876
|
console.log(
|
|
4863
4877
|
(0, import_colors.red)((0, import_colors.bold)(`\u2717 ${failures} check(s) failed.`)) + (0, import_colors.yellow)(" See the lines marked \u2717 above.")
|
|
4864
4878
|
);
|
|
4865
|
-
|
|
4879
|
+
return failures;
|
|
4866
4880
|
}
|
|
4867
4881
|
console.log((0, import_colors.green)((0, import_colors.bold)("\u2713 All endpoint checks passed.")));
|
|
4882
|
+
return 0;
|
|
4883
|
+
}
|
|
4884
|
+
|
|
4885
|
+
// src/verify/upgrade.ts
|
|
4886
|
+
var import_colors3 = require("kleur/colors");
|
|
4887
|
+
|
|
4888
|
+
// src/verify/scopes.ts
|
|
4889
|
+
var import_colors2 = require("kleur/colors");
|
|
4890
|
+
var REQUEST_TIMEOUT_MS2 = 15e3;
|
|
4891
|
+
var SCOPES_ADDED_THIS_RELEASE = [
|
|
4892
|
+
{
|
|
4893
|
+
scope: "record.unarchive",
|
|
4894
|
+
guards: "the new UNARCHIVE action. Without it no role can restore an archived record, including roles that hold record.archive."
|
|
4895
|
+
},
|
|
4896
|
+
{
|
|
4897
|
+
scope: "location.edit",
|
|
4898
|
+
guards: "the location and administrative area write API (create, update, withdrawVersion)."
|
|
4899
|
+
},
|
|
4900
|
+
{
|
|
4901
|
+
scope: "integration.audit.read",
|
|
4902
|
+
guards: "reading a system client's audit log via the integrations.audit endpoint."
|
|
4903
|
+
}
|
|
4904
|
+
];
|
|
4905
|
+
function scopeType(encoded) {
|
|
4906
|
+
for (const pair of encoded.split("&")) {
|
|
4907
|
+
const [key, value] = pair.split("=");
|
|
4908
|
+
if (key === "type") {
|
|
4909
|
+
return value;
|
|
4910
|
+
}
|
|
4911
|
+
}
|
|
4912
|
+
return void 0;
|
|
4913
|
+
}
|
|
4914
|
+
async function fetchRoles(baseUrl) {
|
|
4915
|
+
try {
|
|
4916
|
+
const response = await fetch(`${baseUrl}/config/roles`, {
|
|
4917
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS2)
|
|
4918
|
+
});
|
|
4919
|
+
if (!response.ok) {
|
|
4920
|
+
return void 0;
|
|
4921
|
+
}
|
|
4922
|
+
const body = await response.json();
|
|
4923
|
+
if (!Array.isArray(body)) {
|
|
4924
|
+
return void 0;
|
|
4925
|
+
}
|
|
4926
|
+
return body.filter(
|
|
4927
|
+
(role) => typeof role === "object" && role !== null && Array.isArray(role.scopes)
|
|
4928
|
+
);
|
|
4929
|
+
} catch {
|
|
4930
|
+
return void 0;
|
|
4931
|
+
}
|
|
4932
|
+
}
|
|
4933
|
+
async function runVerifyScopes(target = DEFAULT_TARGET_URL) {
|
|
4934
|
+
const baseUrl = resolveBaseUrl(target);
|
|
4935
|
+
console.log((0, import_colors2.bold)(`Scopes added in this release, at ${baseUrl}
|
|
4936
|
+
`));
|
|
4937
|
+
const roles = await fetchRoles(baseUrl);
|
|
4938
|
+
if (!roles) {
|
|
4939
|
+
console.log(
|
|
4940
|
+
" " + (0, import_colors2.yellow)(
|
|
4941
|
+
"Could not read /config/roles, so the new scopes could not be checked."
|
|
4942
|
+
)
|
|
4943
|
+
);
|
|
4944
|
+
return 1;
|
|
4945
|
+
}
|
|
4946
|
+
let failures = 0;
|
|
4947
|
+
for (const { scope, guards } of SCOPES_ADDED_THIS_RELEASE) {
|
|
4948
|
+
const holders = roles.filter(
|
|
4949
|
+
(role) => role.scopes.some((encoded) => scopeType(encoded) === scope)
|
|
4950
|
+
);
|
|
4951
|
+
if (holders.length === 0) {
|
|
4952
|
+
failures++;
|
|
4953
|
+
console.log(line(false, scope, `held by no role \u2014 guards ${guards}`));
|
|
4954
|
+
continue;
|
|
4955
|
+
}
|
|
4956
|
+
const named = holders.map((role) => role.id).slice(0, 3).join(", ");
|
|
4957
|
+
const more = holders.length > 3 ? `, +${holders.length - 3} more` : "";
|
|
4958
|
+
console.log(
|
|
4959
|
+
line(true, scope, `${holders.length} role(s)${(0, import_colors2.dim)(`: ${named}${more}`)}`)
|
|
4960
|
+
);
|
|
4961
|
+
}
|
|
4962
|
+
console.log();
|
|
4963
|
+
if (failures === 0) {
|
|
4964
|
+
console.log((0, import_colors2.green)((0, import_colors2.bold)("\u2713 Every scope added this release is assigned.")));
|
|
4965
|
+
}
|
|
4966
|
+
return failures;
|
|
4967
|
+
}
|
|
4968
|
+
|
|
4969
|
+
// src/verify/upgrade.ts
|
|
4970
|
+
function verifyTranslations(cwd) {
|
|
4971
|
+
console.log((0, import_colors3.bold)("Translations\n"));
|
|
4972
|
+
const { missing, dynamicIds } = check(cwd);
|
|
4973
|
+
for (const file of dynamicIds) {
|
|
4974
|
+
console.log(
|
|
4975
|
+
" " + (0, import_colors3.yellow)(
|
|
4976
|
+
`${file} declares a message whose id is built at runtime; ids have to be hardcoded to be checked.`
|
|
4977
|
+
)
|
|
4978
|
+
);
|
|
4979
|
+
}
|
|
4980
|
+
if (missing.length === 0) {
|
|
4981
|
+
console.log(
|
|
4982
|
+
" " + (0, import_colors3.green)("\u2713") + " Every message declared in src has a translation row."
|
|
4983
|
+
);
|
|
4984
|
+
} else {
|
|
4985
|
+
console.log(
|
|
4986
|
+
" " + (0, import_colors3.red)("\u2717") + ` ${missing.length} message(s) declared in src have no row in src/translations/countryconfig.csv.`
|
|
4987
|
+
);
|
|
4988
|
+
for (const { id } of missing.slice(0, 10)) {
|
|
4989
|
+
console.log(` ${id}`);
|
|
4990
|
+
}
|
|
4991
|
+
if (missing.length > 10) {
|
|
4992
|
+
console.log(` +${missing.length - 10} more`);
|
|
4993
|
+
}
|
|
4994
|
+
}
|
|
4995
|
+
console.log();
|
|
4996
|
+
return {
|
|
4997
|
+
name: "Translations",
|
|
4998
|
+
failures: missing.length === 0 ? 0 : 1,
|
|
4999
|
+
remedy: "Run `opencrvs check-translations --write` to add the missing rows."
|
|
5000
|
+
};
|
|
5001
|
+
}
|
|
5002
|
+
async function runVerifyUpgrade(target = DEFAULT_TARGET_URL, cwd = process.cwd()) {
|
|
5003
|
+
const sections = [];
|
|
5004
|
+
sections.push(verifyTranslations(cwd));
|
|
5005
|
+
sections.push({
|
|
5006
|
+
name: "Scopes added this release",
|
|
5007
|
+
failures: await runVerifyScopes(target),
|
|
5008
|
+
remedy: "Assign each unheld scope to the role(s) that should have it in src/data-seeding/roles/roles.ts."
|
|
5009
|
+
});
|
|
5010
|
+
console.log();
|
|
5011
|
+
sections.push({
|
|
5012
|
+
name: "Endpoints",
|
|
5013
|
+
failures: await runVerifyEndpoints(target),
|
|
5014
|
+
remedy: "See the lines marked \u2717 above. A missing public endpoint or a secured one that answers without a token both need fixing before deploying."
|
|
5015
|
+
});
|
|
5016
|
+
const total = sections.reduce((sum, section) => sum + section.failures, 0);
|
|
5017
|
+
console.log();
|
|
5018
|
+
console.log((0, import_colors3.bold)("Upgrade verification summary"));
|
|
5019
|
+
console.log();
|
|
5020
|
+
for (const section of sections) {
|
|
5021
|
+
const mark = section.failures === 0 ? (0, import_colors3.green)("\u2713") : (0, import_colors3.red)("\u2717");
|
|
5022
|
+
const detail = section.failures === 0 ? "passed" : `${section.failures} problem(s)`;
|
|
5023
|
+
console.log(` ${mark} ${section.name}: ${detail}`);
|
|
5024
|
+
}
|
|
5025
|
+
console.log();
|
|
5026
|
+
if (total === 0) {
|
|
5027
|
+
console.log((0, import_colors3.green)((0, import_colors3.bold)("\u2713 This country config looks ready to deploy.")));
|
|
5028
|
+
return 0;
|
|
5029
|
+
}
|
|
5030
|
+
console.log((0, import_colors3.red)((0, import_colors3.bold)(`\u2717 ${total} problem(s) to fix before deploying:`)));
|
|
5031
|
+
console.log();
|
|
5032
|
+
for (const section of sections.filter((s) => s.failures > 0)) {
|
|
5033
|
+
console.log(` ${(0, import_colors3.bold)(section.name)}: ${section.remedy}`);
|
|
5034
|
+
}
|
|
5035
|
+
return total;
|
|
4868
5036
|
}
|
|
4869
5037
|
|
|
4870
5038
|
// src/cli.ts
|
|
@@ -4876,11 +5044,32 @@ Commands:
|
|
|
4876
5044
|
environment Manage deployment environments
|
|
4877
5045
|
upgrade Upgrade an existing environment
|
|
4878
5046
|
check-translations Check translation files for completeness
|
|
5047
|
+
verify-upgrade Run every post-upgrade check and report them together
|
|
4879
5048
|
verify-endpoints Verify the locally-running country config exposes the
|
|
4880
5049
|
expected endpoints and keeps secured ones locked down
|
|
4881
5050
|
|
|
4882
5051
|
Run 'opencrvs <command> --help' for more information on a command.
|
|
4883
5052
|
`.trim();
|
|
5053
|
+
var VERIFY_UPGRADE_USAGE = `
|
|
5054
|
+
Usage: opencrvs verify-upgrade [country-config-url]
|
|
5055
|
+
|
|
5056
|
+
Run this after 'opencrvs upgrade', from the country config directory, with the
|
|
5057
|
+
upgraded country config running. It runs every post-upgrade check there is and
|
|
5058
|
+
reports them together:
|
|
5059
|
+
- every message declared in src has a translation row,
|
|
5060
|
+
- every scope this release added is assigned to at least one role, and
|
|
5061
|
+
- the endpoint checks of 'verify-endpoints'.
|
|
5062
|
+
|
|
5063
|
+
Arguments:
|
|
5064
|
+
[country-config-url] Optional. Domain or URL of the country config
|
|
5065
|
+
service. Defaults to 'http://localhost:3040'. A bare
|
|
5066
|
+
domain is assumed to use https.
|
|
5067
|
+
|
|
5068
|
+
Options:
|
|
5069
|
+
-h, --help Show this message.
|
|
5070
|
+
|
|
5071
|
+
Exits with a non-zero status if any check fails.
|
|
5072
|
+
`.trim();
|
|
4884
5073
|
var VERIFY_ENDPOINTS_USAGE = `
|
|
4885
5074
|
Usage: opencrvs verify-endpoints [country-config-url]
|
|
4886
5075
|
|
|
@@ -4907,11 +5096,16 @@ Usage: opencrvs upgrade [options]
|
|
|
4907
5096
|
Upgrade the country config in the current working directory to the next
|
|
4908
5097
|
major version of OpenCRVS.
|
|
4909
5098
|
|
|
5099
|
+
Codemods are best-effort: a country config that renamed or restructured the
|
|
5100
|
+
files a codemod targets keeps its own structure, and the step is reported as
|
|
5101
|
+
outstanding rather than guessed at. Anything left over is listed at the end,
|
|
5102
|
+
and the command exits non-zero while that list is not empty.
|
|
5103
|
+
|
|
4910
5104
|
Options:
|
|
4911
|
-
--docker-swarm
|
|
4912
|
-
|
|
4913
|
-
|
|
4914
|
-
|
|
5105
|
+
--docker-swarm Also list the manual steps that only apply to a Docker
|
|
5106
|
+
Swarm deployment, which lives in compose files no codemod
|
|
5107
|
+
here touches. Omit it for Kubernetes, where the charts and
|
|
5108
|
+
the postgres-on-deploy job cover the same ground.
|
|
4915
5109
|
-h, --help Show this message.
|
|
4916
5110
|
`.trim();
|
|
4917
5111
|
function main5() {
|
|
@@ -4927,6 +5121,8 @@ function main5() {
|
|
|
4927
5121
|
return handleUpgrade();
|
|
4928
5122
|
case "check-translations":
|
|
4929
5123
|
return handleCheckTranslations();
|
|
5124
|
+
case "verify-upgrade":
|
|
5125
|
+
return handleVerifyUpgrade();
|
|
4930
5126
|
case "verify-endpoints":
|
|
4931
5127
|
return handleVerifyEndpoints();
|
|
4932
5128
|
default:
|
|
@@ -5004,13 +5200,33 @@ async function handleUpgrade() {
|
|
|
5004
5200
|
}
|
|
5005
5201
|
const dockerSwarm = upgradeArgs.includes("--docker-swarm");
|
|
5006
5202
|
console.log("Initiating upgrade...");
|
|
5203
|
+
let outstanding;
|
|
5007
5204
|
try {
|
|
5008
|
-
|
|
5009
|
-
|
|
5205
|
+
;
|
|
5206
|
+
({ outstanding } = await runUpgrade(dockerSwarm));
|
|
5010
5207
|
} catch (error3) {
|
|
5011
5208
|
console.error("Upgrade failed:", error3);
|
|
5012
5209
|
process.exit(1);
|
|
5013
5210
|
}
|
|
5211
|
+
if (outstanding.length === 0) {
|
|
5212
|
+
console.log("\nUpgrade completed successfully!");
|
|
5213
|
+
console.log(
|
|
5214
|
+
"Next, start the country config and run 'opencrvs verify-upgrade'."
|
|
5215
|
+
);
|
|
5216
|
+
return;
|
|
5217
|
+
}
|
|
5218
|
+
console.error(
|
|
5219
|
+
`
|
|
5220
|
+
Upgrade ran, but ${outstanding.length} step(s) could not be done for you.`
|
|
5221
|
+
);
|
|
5222
|
+
console.error("Do these by hand before deploying:\n");
|
|
5223
|
+
outstanding.forEach((step, index) => {
|
|
5224
|
+
console.error(` ${index + 1}. ${step}`);
|
|
5225
|
+
});
|
|
5226
|
+
console.error(
|
|
5227
|
+
"\nThen start the country config and run 'opencrvs verify-upgrade' to check what is left."
|
|
5228
|
+
);
|
|
5229
|
+
process.exit(1);
|
|
5014
5230
|
}
|
|
5015
5231
|
var CHECK_TRANSLATIONS_USAGE = `
|
|
5016
5232
|
Usage: opencrvs check-translations [options]
|
|
@@ -5089,7 +5305,10 @@ async function handleVerifyEndpoints() {
|
|
|
5089
5305
|
process.exit(1);
|
|
5090
5306
|
}
|
|
5091
5307
|
try {
|
|
5092
|
-
await runVerifyEndpoints(positional[0]);
|
|
5308
|
+
const failures = await runVerifyEndpoints(positional[0]);
|
|
5309
|
+
if (failures > 0) {
|
|
5310
|
+
process.exit(1);
|
|
5311
|
+
}
|
|
5093
5312
|
} catch (error3) {
|
|
5094
5313
|
console.error(
|
|
5095
5314
|
"Endpoint verification failed:",
|
|
@@ -5098,4 +5317,39 @@ async function handleVerifyEndpoints() {
|
|
|
5098
5317
|
process.exit(1);
|
|
5099
5318
|
}
|
|
5100
5319
|
}
|
|
5320
|
+
async function handleVerifyUpgrade() {
|
|
5321
|
+
const verifyArgs = args.slice(1);
|
|
5322
|
+
if (verifyArgs.includes("--help") || verifyArgs.includes("-h")) {
|
|
5323
|
+
console.log(VERIFY_UPGRADE_USAGE);
|
|
5324
|
+
process.exit(0);
|
|
5325
|
+
}
|
|
5326
|
+
const unknownFlags = verifyArgs.filter((arg) => arg.startsWith("-"));
|
|
5327
|
+
if (unknownFlags.length > 0) {
|
|
5328
|
+
console.error(`Unknown option(s): ${unknownFlags.join(", ")}
|
|
5329
|
+
`);
|
|
5330
|
+
console.log(VERIFY_UPGRADE_USAGE);
|
|
5331
|
+
process.exit(1);
|
|
5332
|
+
}
|
|
5333
|
+
const positional = verifyArgs.filter((arg) => !arg.startsWith("-"));
|
|
5334
|
+
if (positional.length > 1) {
|
|
5335
|
+
console.error(
|
|
5336
|
+
`Unexpected extra argument(s): ${positional.slice(1).join(", ")}
|
|
5337
|
+
`
|
|
5338
|
+
);
|
|
5339
|
+
console.log(VERIFY_UPGRADE_USAGE);
|
|
5340
|
+
process.exit(1);
|
|
5341
|
+
}
|
|
5342
|
+
try {
|
|
5343
|
+
const failures = await runVerifyUpgrade(positional[0]);
|
|
5344
|
+
if (failures > 0) {
|
|
5345
|
+
process.exit(1);
|
|
5346
|
+
}
|
|
5347
|
+
} catch (error3) {
|
|
5348
|
+
console.error(
|
|
5349
|
+
"Upgrade verification failed:",
|
|
5350
|
+
error3 instanceof Error ? error3.message : error3
|
|
5351
|
+
);
|
|
5352
|
+
process.exit(1);
|
|
5353
|
+
}
|
|
5354
|
+
}
|
|
5101
5355
|
main5();
|