@opencrvs/toolkit 2.2.0-rc.045257f → 2.2.0-rc.1a111f2
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/dist/cli.js +925 -356
- package/dist/commons/api/router.d.ts +4 -4
- package/dist/commons/events/ActionType.d.ts +2 -0
- package/dist/commons/events/AdvancedSearchConfig.d.ts +3 -0
- package/dist/commons/events/Draft.d.ts +34 -1
- package/dist/commons/events/EventConfig.d.ts +385 -0
- package/dist/commons/events/defineConfig.d.ts +7 -2
- package/dist/commons/events/event.d.ts +4 -1
- package/dist/commons/events/field.d.ts +5 -0
- package/dist/commons/events/scopes.d.ts +1 -0
- package/dist/commons/events/test.utils.d.ts +57 -5
- package/dist/commons/events/utils.d.ts +13 -0
- package/dist/environment/custom-types.d.ts +1 -0
- package/dist/environment/custom-types.d.ts.map +1 -1
- package/dist/environment/derived-variables.d.ts +8 -0
- package/dist/environment/derived-variables.d.ts.map +1 -1
- package/dist/environment/derived-variables.js +9 -0
- package/dist/environment/questions.d.ts +42 -9
- package/dist/environment/questions.d.ts.map +1 -1
- package/dist/environment/questions.js +70 -47
- package/dist/environment/registry.d.ts +15 -0
- package/dist/environment/registry.d.ts.map +1 -0
- package/dist/environment/registry.js +112 -0
- package/dist/environment/setup-environment.d.ts.map +1 -1
- package/dist/environment/setup-environment.js +98 -23
- package/dist/events/index.js +462 -99
- package/dist/migrations/add-notify-config.d.ts +40 -0
- package/dist/migrations/add-notify-config.d.ts.map +1 -0
- package/dist/migrations/add-notify-config.js +249 -0
- package/dist/migrations/index.d.ts.map +1 -1
- package/dist/migrations/index.js +602 -143
- package/dist/migrations/move-declaration-to-declare-action.d.ts.map +1 -1
- package/dist/migrations/move-declaration-to-declare-action.js +27 -144
- package/dist/migrations/read-declaration-through-helper.d.ts.map +1 -1
- package/dist/migrations/read-declaration-through-helper.js +3 -61
- package/dist/migrations/resolve-versioned-event-config.d.ts +56 -0
- package/dist/migrations/resolve-versioned-event-config.d.ts.map +1 -0
- package/dist/migrations/resolve-versioned-event-config.js +353 -0
- package/dist/migrations/utils.d.ts +61 -0
- package/dist/migrations/utils.d.ts.map +1 -0
- package/dist/migrations/utils.js +218 -0
- package/dist/notification/index.js +510 -36
- package/dist/templates/charts-values/dependencies/values.yaml +2 -1
- package/dist/templates/charts-values/opencrvs-services/values.yaml +2 -2
- package/dist/verify/endpoints.d.ts +11 -0
- package/dist/verify/endpoints.d.ts.map +1 -1
- package/dist/verify/endpoints.js +21 -27
- package/opencrvs-toolkit-2.2.0-rc.1a111f2.tgz +0 -0
- package/package.json +2 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/dist/environment/dockerhub.d.ts +0 -15
- package/dist/environment/dockerhub.d.ts.map +0 -1
- package/dist/environment/dockerhub.js +0 -104
- package/opencrvs-toolkit-2.2.0-rc.045257f.tgz +0 -0
package/dist/cli.js
CHANGED
|
@@ -32,13 +32,13 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
32
32
|
|
|
33
33
|
// src/environment/paths.ts
|
|
34
34
|
function getEnvironmentInventoryPath(environment) {
|
|
35
|
-
return (0,
|
|
35
|
+
return (0, import_path10.join)("environments", environment, INVENTORY_FILE_NAME);
|
|
36
36
|
}
|
|
37
37
|
function findOldInventoryFiles() {
|
|
38
|
-
return glob.sync((0,
|
|
38
|
+
return glob.sync((0, import_path10.join)(OLD_INVENTORY_DIR, "*.yml")).sort();
|
|
39
39
|
}
|
|
40
40
|
function getEnvironmentNameFromOldInventoryPath(filePath) {
|
|
41
|
-
return (0,
|
|
41
|
+
return (0, import_path10.basename)(filePath, ".yml");
|
|
42
42
|
}
|
|
43
43
|
function assertNoOldInventoryLayout() {
|
|
44
44
|
if (findOldInventoryFiles().length === 0) {
|
|
@@ -51,13 +51,13 @@ function assertNoOldInventoryLayout() {
|
|
|
51
51
|
].join(" ")
|
|
52
52
|
);
|
|
53
53
|
}
|
|
54
|
-
var
|
|
54
|
+
var import_path10, glob, OLD_INVENTORY_DIR, INVENTORY_FILE_NAME;
|
|
55
55
|
var init_paths = __esm({
|
|
56
56
|
"src/environment/paths.ts"() {
|
|
57
57
|
"use strict";
|
|
58
|
-
|
|
58
|
+
import_path10 = require("path");
|
|
59
59
|
glob = __toESM(require("glob"));
|
|
60
|
-
OLD_INVENTORY_DIR = (0,
|
|
60
|
+
OLD_INVENTORY_DIR = (0, import_path10.join)(
|
|
61
61
|
"infrastructure",
|
|
62
62
|
"server-setup",
|
|
63
63
|
"inventory"
|
|
@@ -405,6 +405,7 @@ var init_derived_variables = __esm({
|
|
|
405
405
|
{
|
|
406
406
|
name: "S3_ADMIN_ACCESS_KEY",
|
|
407
407
|
valueLabel: "S3_ADMIN_ACCESS_KEY",
|
|
408
|
+
legacyValueLabel: "MINIO_ROOT_USER",
|
|
408
409
|
valueType: "SECRET",
|
|
409
410
|
type: "disabled",
|
|
410
411
|
scope: "ENVIRONMENT"
|
|
@@ -412,6 +413,7 @@ var init_derived_variables = __esm({
|
|
|
412
413
|
{
|
|
413
414
|
name: "S3_ADMIN_SECRET_KEY",
|
|
414
415
|
valueLabel: "S3_ADMIN_SECRET_KEY",
|
|
416
|
+
legacyValueLabel: "MINIO_ROOT_PASSWORD",
|
|
415
417
|
valueType: "SECRET",
|
|
416
418
|
type: "disabled",
|
|
417
419
|
scope: "ENVIRONMENT"
|
|
@@ -513,6 +515,13 @@ var init_derived_variables = __esm({
|
|
|
513
515
|
valueType: "VARIABLE",
|
|
514
516
|
type: "disabled",
|
|
515
517
|
scope: "ENVIRONMENT"
|
|
518
|
+
},
|
|
519
|
+
{
|
|
520
|
+
name: "RUSTFS_HOST_DATA_PATH",
|
|
521
|
+
valueLabel: "RUSTFS_HOST_DATA_PATH",
|
|
522
|
+
valueType: "VARIABLE",
|
|
523
|
+
type: "disabled",
|
|
524
|
+
scope: "ENVIRONMENT"
|
|
516
525
|
}
|
|
517
526
|
];
|
|
518
527
|
}
|
|
@@ -603,8 +612,8 @@ function extractWorkerNodes(data) {
|
|
|
603
612
|
return worker_hosts;
|
|
604
613
|
}
|
|
605
614
|
function copyChartsValues(env, values) {
|
|
606
|
-
const srcDir =
|
|
607
|
-
const destDir =
|
|
615
|
+
const srcDir = import_path11.default.resolve(__dirname, "templates", "charts-values");
|
|
616
|
+
const destDir = import_path11.default.resolve(process.cwd(), "environments", env);
|
|
608
617
|
import_fs5.default.mkdirSync(destDir, { recursive: true });
|
|
609
618
|
values["lets_encrypt"] = values["traefik_mode"] === "lets_encrypt";
|
|
610
619
|
values["static_ssl"] = values["traefik_mode"] === "static_ssl";
|
|
@@ -614,7 +623,7 @@ function copyChartsValues(env, values) {
|
|
|
614
623
|
if (stat.isDirectory()) {
|
|
615
624
|
import_fs5.default.mkdirSync(dest, { recursive: true });
|
|
616
625
|
for (const item of import_fs5.default.readdirSync(src)) {
|
|
617
|
-
copyRecursive(
|
|
626
|
+
copyRecursive(import_path11.default.join(src, item), import_path11.default.join(dest, item));
|
|
618
627
|
}
|
|
619
628
|
} else {
|
|
620
629
|
const content = import_fs5.default.readFileSync(src, "utf8");
|
|
@@ -636,13 +645,13 @@ function copyChartsValues(env, values) {
|
|
|
636
645
|
`);
|
|
637
646
|
}
|
|
638
647
|
function generateInventory(env, values) {
|
|
639
|
-
const templatePath =
|
|
648
|
+
const templatePath = import_path11.default.join(
|
|
640
649
|
__dirname,
|
|
641
650
|
"templates",
|
|
642
651
|
"inventory",
|
|
643
652
|
"inventory.template.yml"
|
|
644
653
|
);
|
|
645
|
-
const outputPath =
|
|
654
|
+
const outputPath = import_path11.default.resolve(
|
|
646
655
|
process.cwd(),
|
|
647
656
|
getEnvironmentInventoryPath(env)
|
|
648
657
|
);
|
|
@@ -650,18 +659,18 @@ function generateInventory(env, values) {
|
|
|
650
659
|
const template = import_handlebars.default.compile(templateFile);
|
|
651
660
|
values["single_node"] = values["kube_worker_nodes"].length > 0 || values["backup_host"] ? "false" : "true";
|
|
652
661
|
const updated = template(values);
|
|
653
|
-
import_fs5.default.mkdirSync(
|
|
662
|
+
import_fs5.default.mkdirSync(import_path11.default.dirname(outputPath), { recursive: true });
|
|
654
663
|
import_fs5.default.writeFileSync(outputPath, updated);
|
|
655
664
|
log(`
|
|
656
665
|
\u2705 Generated inventory file at ${outputPath}
|
|
657
666
|
`);
|
|
658
667
|
}
|
|
659
|
-
var import_fs5,
|
|
668
|
+
var import_fs5, import_path11, import_handlebars;
|
|
660
669
|
var init_templates = __esm({
|
|
661
670
|
"src/environment/templates.ts"() {
|
|
662
671
|
"use strict";
|
|
663
672
|
import_fs5 = __toESM(require("fs"));
|
|
664
|
-
|
|
673
|
+
import_path11 = __toESM(require("path"));
|
|
665
674
|
init_logger();
|
|
666
675
|
init_paths();
|
|
667
676
|
import_handlebars = __toESM(require("handlebars"));
|
|
@@ -692,16 +701,16 @@ var update_workflows_exports = {};
|
|
|
692
701
|
__export(update_workflows_exports, {
|
|
693
702
|
updateWorkflowEnvironments: () => updateWorkflowEnvironments
|
|
694
703
|
});
|
|
695
|
-
function isDirectory(
|
|
704
|
+
function isDirectory(path15) {
|
|
696
705
|
try {
|
|
697
|
-
return (0, import_fs6.statSync)(
|
|
706
|
+
return (0, import_fs6.statSync)(path15).isDirectory();
|
|
698
707
|
} catch {
|
|
699
708
|
return false;
|
|
700
709
|
}
|
|
701
710
|
}
|
|
702
711
|
async function extractInfrastructureNames() {
|
|
703
|
-
const files = glob2.sync((0,
|
|
704
|
-
const infraEnvironments = files.map((file) => (0,
|
|
712
|
+
const files = glob2.sync((0, import_path12.join)("environments", "*", INVENTORY_FILE_NAME));
|
|
713
|
+
const infraEnvironments = files.map((file) => (0, import_path12.basename)((0, import_path12.dirname)(file)));
|
|
705
714
|
if (infraEnvironments.length === 0) {
|
|
706
715
|
console.log(
|
|
707
716
|
`\u26A0\uFE0F Warning: No environment inventory files found at environments/*/${INVENTORY_FILE_NAME}`
|
|
@@ -714,8 +723,8 @@ async function extractInfrastructureNames() {
|
|
|
714
723
|
async function extractEnvironmentNames() {
|
|
715
724
|
const entries = await (0, import_promises.readdir)("environments");
|
|
716
725
|
const environments = entries.filter((entry) => {
|
|
717
|
-
const environmentPath = (0,
|
|
718
|
-
const opencrvsServicesPath = (0,
|
|
726
|
+
const environmentPath = (0, import_path12.join)("environments", entry);
|
|
727
|
+
const opencrvsServicesPath = (0, import_path12.join)(environmentPath, "opencrvs-services");
|
|
719
728
|
return isDirectory(environmentPath) && (0, import_fs6.existsSync)(opencrvsServicesPath) && isDirectory(opencrvsServicesPath);
|
|
720
729
|
});
|
|
721
730
|
if (environments.length === 0) {
|
|
@@ -808,13 +817,13 @@ async function updateWorkflowEnvironments() {
|
|
|
808
817
|
process.exit(1);
|
|
809
818
|
}
|
|
810
819
|
}
|
|
811
|
-
var import_promises, import_fs6,
|
|
820
|
+
var import_promises, import_fs6, import_path12, glob2, yaml2;
|
|
812
821
|
var init_update_workflows = __esm({
|
|
813
822
|
"src/environment/update-workflows.ts"() {
|
|
814
823
|
"use strict";
|
|
815
824
|
import_promises = require("fs/promises");
|
|
816
825
|
import_fs6 = require("fs");
|
|
817
|
-
|
|
826
|
+
import_path12 = require("path");
|
|
818
827
|
glob2 = __toESM(require("glob"));
|
|
819
828
|
yaml2 = __toESM(require("js-yaml"));
|
|
820
829
|
init_logger();
|
|
@@ -872,7 +881,10 @@ function validateCIDRs(input4) {
|
|
|
872
881
|
}
|
|
873
882
|
return true;
|
|
874
883
|
}
|
|
875
|
-
|
|
884
|
+
function validateRegistryHost(input4) {
|
|
885
|
+
return /^[a-z0-9]([a-z0-9.-]*[a-z0-9])?(:[0-9]+)?$/i.test(input4) ? true : "Please enter a registry host without protocol or path (e.g. docker.io, ghcr.io)";
|
|
886
|
+
}
|
|
887
|
+
var import_kleur2, notEmpty, registryQuestions, githubQuestions, githubApprovalRequiredQuestion, githubApproversQuestion, githubOtherQuestions, githubTokenQuestion, countryQuestions, infrastructureQuestions, staticSSLCertQuestions, backupQuestions, diskQuestions, databaseAndMonitoringQuestions, emailQuestions, sentryQuestions, metabaseAdminQuestions;
|
|
876
888
|
var init_questions = __esm({
|
|
877
889
|
"src/environment/questions.ts"() {
|
|
878
890
|
"use strict";
|
|
@@ -880,45 +892,59 @@ var init_questions = __esm({
|
|
|
880
892
|
init_utils();
|
|
881
893
|
init_git();
|
|
882
894
|
notEmpty = (value) => value.toString().trim().length > 0 ? true : "Please enter a value";
|
|
883
|
-
|
|
895
|
+
registryQuestions = [
|
|
896
|
+
{
|
|
897
|
+
name: "registryHost",
|
|
898
|
+
type: "text",
|
|
899
|
+
message: "What is the host of your container registry? (e.g. docker.io, ghcr.io)",
|
|
900
|
+
valueType: "VARIABLE",
|
|
901
|
+
valueLabel: "REGISTRY_HOST",
|
|
902
|
+
validate: validateRegistryHost,
|
|
903
|
+
initial: process.env.REGISTRY_HOST || "docker.io",
|
|
904
|
+
scope: "REPOSITORY"
|
|
905
|
+
},
|
|
884
906
|
{
|
|
885
|
-
name: "
|
|
907
|
+
name: "registryOrganisation",
|
|
886
908
|
type: "text",
|
|
887
|
-
message: "What is the name of your
|
|
909
|
+
message: "What is the name of your organisation (or user) in the container registry?",
|
|
888
910
|
valueType: "SECRET",
|
|
889
|
-
valueLabel: "
|
|
911
|
+
valueLabel: "REGISTRY_ORGANISATION",
|
|
912
|
+
legacyValueLabel: "DOCKERHUB_ACCOUNT",
|
|
890
913
|
validate: notEmpty,
|
|
891
|
-
initial: process.env.
|
|
914
|
+
initial: process.env.REGISTRY_ORGANISATION,
|
|
892
915
|
scope: "REPOSITORY"
|
|
893
916
|
},
|
|
894
917
|
{
|
|
895
|
-
name: "
|
|
918
|
+
name: "registryRepository",
|
|
896
919
|
type: "text",
|
|
897
|
-
message: "What is the name of your private
|
|
920
|
+
message: "What is the name of your private container repository?",
|
|
898
921
|
valueType: "SECRET",
|
|
899
|
-
valueLabel: "
|
|
922
|
+
valueLabel: "REGISTRY_REPOSITORY",
|
|
923
|
+
legacyValueLabel: "DOCKERHUB_REPO",
|
|
900
924
|
validate: notEmpty,
|
|
901
|
-
initial: process.env.
|
|
925
|
+
initial: process.env.REGISTRY_REPOSITORY,
|
|
902
926
|
scope: "REPOSITORY"
|
|
903
927
|
},
|
|
904
928
|
{
|
|
905
|
-
name: "
|
|
929
|
+
name: "registryUsername",
|
|
906
930
|
type: "text",
|
|
907
|
-
message: "What is the
|
|
931
|
+
message: "What is the container registry username the target server should be using?",
|
|
908
932
|
valueType: "SECRET",
|
|
909
|
-
valueLabel: "
|
|
933
|
+
valueLabel: "REGISTRY_USERNAME",
|
|
934
|
+
legacyValueLabel: "DOCKER_USERNAME",
|
|
910
935
|
validate: notEmpty,
|
|
911
|
-
initial: process.env.
|
|
936
|
+
initial: process.env.REGISTRY_USERNAME,
|
|
912
937
|
scope: "REPOSITORY"
|
|
913
938
|
},
|
|
914
939
|
{
|
|
915
|
-
name: "
|
|
940
|
+
name: "registryToken",
|
|
916
941
|
type: "text",
|
|
917
|
-
message: "What is the token of this
|
|
942
|
+
message: "What is the token of this container registry account?",
|
|
918
943
|
valueType: "SECRET",
|
|
919
|
-
valueLabel: "
|
|
944
|
+
valueLabel: "REGISTRY_TOKEN",
|
|
945
|
+
legacyValueLabel: "DOCKER_TOKEN",
|
|
920
946
|
validate: notEmpty,
|
|
921
|
-
initial: process.env.
|
|
947
|
+
initial: process.env.REGISTRY_TOKEN,
|
|
922
948
|
scope: "REPOSITORY"
|
|
923
949
|
}
|
|
924
950
|
];
|
|
@@ -940,36 +966,38 @@ var init_questions = __esm({
|
|
|
940
966
|
scope: "REPOSITORY"
|
|
941
967
|
}
|
|
942
968
|
];
|
|
969
|
+
githubApprovalRequiredQuestion = {
|
|
970
|
+
name: "approvalRequired",
|
|
971
|
+
type: "select",
|
|
972
|
+
message: "Would you like to enable approvals process for GitHub action workflows?",
|
|
973
|
+
choices: [
|
|
974
|
+
{
|
|
975
|
+
title: "True",
|
|
976
|
+
value: "true"
|
|
977
|
+
},
|
|
978
|
+
{
|
|
979
|
+
title: "False",
|
|
980
|
+
value: "false"
|
|
981
|
+
}
|
|
982
|
+
],
|
|
983
|
+
valueType: "VARIABLE",
|
|
984
|
+
validate: notEmpty,
|
|
985
|
+
valueLabel: "APPROVAL_REQUIRED",
|
|
986
|
+
initial: process.env.APPROVAL_REQUIRED,
|
|
987
|
+
scope: "ENVIRONMENT"
|
|
988
|
+
};
|
|
989
|
+
githubApproversQuestion = {
|
|
990
|
+
name: "githubApprovers",
|
|
991
|
+
type: "text",
|
|
992
|
+
message: "Please provide/update list of approvers?",
|
|
993
|
+
initial: process.env.GH_APPROVERS,
|
|
994
|
+
valueType: "VARIABLE",
|
|
995
|
+
valueLabel: "GH_APPROVERS",
|
|
996
|
+
scope: "REPOSITORY"
|
|
997
|
+
};
|
|
943
998
|
githubOtherQuestions = [
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
type: "text",
|
|
947
|
-
message: "Please provide/update list of production approvers?",
|
|
948
|
-
initial: process.env.GH_APPROVERS,
|
|
949
|
-
valueType: "VARIABLE",
|
|
950
|
-
valueLabel: "GH_APPROVERS",
|
|
951
|
-
scope: "REPOSITORY"
|
|
952
|
-
},
|
|
953
|
-
{
|
|
954
|
-
name: "approvalRequired",
|
|
955
|
-
type: "select",
|
|
956
|
-
message: "Would you like to enable approvals process for GitHub action workflows?",
|
|
957
|
-
choices: [
|
|
958
|
-
{
|
|
959
|
-
title: "True",
|
|
960
|
-
value: "true"
|
|
961
|
-
},
|
|
962
|
-
{
|
|
963
|
-
title: "False",
|
|
964
|
-
value: "false"
|
|
965
|
-
}
|
|
966
|
-
],
|
|
967
|
-
valueType: "VARIABLE",
|
|
968
|
-
validate: notEmpty,
|
|
969
|
-
valueLabel: "APPROVAL_REQUIRED",
|
|
970
|
-
initial: process.env.APPROVAL_REQUIRED,
|
|
971
|
-
scope: "ENVIRONMENT"
|
|
972
|
-
}
|
|
999
|
+
githubApprovalRequiredQuestion,
|
|
1000
|
+
githubApproversQuestion
|
|
973
1001
|
];
|
|
974
1002
|
githubTokenQuestion = [
|
|
975
1003
|
{
|
|
@@ -1377,69 +1405,71 @@ var init_questions_helper = __esm({
|
|
|
1377
1405
|
}
|
|
1378
1406
|
});
|
|
1379
1407
|
|
|
1380
|
-
// src/environment/
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1408
|
+
// src/environment/registry.ts
|
|
1409
|
+
function registryApiHost(registry) {
|
|
1410
|
+
const host = registry.trim().toLowerCase();
|
|
1411
|
+
return host === "docker.io" || host === "index.docker.io" ? "registry-1.docker.io" : host;
|
|
1412
|
+
}
|
|
1413
|
+
function request(url, authorization) {
|
|
1414
|
+
return fetch(url, {
|
|
1415
|
+
headers: authorization ? { Authorization: authorization } : {},
|
|
1416
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)
|
|
1417
|
+
});
|
|
1418
|
+
}
|
|
1419
|
+
function failure(registry, step, response) {
|
|
1420
|
+
const reason = `${registry} ${step} responded with HTTP ${response.status}`;
|
|
1421
|
+
switch (response.status) {
|
|
1422
|
+
case 401:
|
|
1423
|
+
case 403:
|
|
1396
1424
|
return {
|
|
1397
1425
|
status: "invalid-credentials",
|
|
1398
|
-
reason:
|
|
1399
|
-
};
|
|
1400
|
-
}
|
|
1401
|
-
if (!login.ok) {
|
|
1402
|
-
return {
|
|
1403
|
-
status: "unreachable",
|
|
1404
|
-
reason: `Docker Hub login responded with HTTP ${login.status}`
|
|
1405
|
-
};
|
|
1406
|
-
}
|
|
1407
|
-
const body = await login.json();
|
|
1408
|
-
const accessToken = body.access_token ?? body.token;
|
|
1409
|
-
if (!accessToken) {
|
|
1410
|
-
return {
|
|
1411
|
-
status: "unreachable",
|
|
1412
|
-
reason: "Docker Hub login response did not contain an access token"
|
|
1426
|
+
reason: `${reason}. Check REGISTRY_USERNAME, REGISTRY_TOKEN, REGISTRY_ORGANISATION and REGISTRY_REPOSITORY`
|
|
1413
1427
|
};
|
|
1414
|
-
|
|
1415
|
-
const repositoryResponse = await fetch(
|
|
1416
|
-
`${DOCKER_HUB_API}/repositories/${encodeURIComponent(
|
|
1417
|
-
organisation
|
|
1418
|
-
)}/${encodeURIComponent(repository)}/`,
|
|
1419
|
-
{
|
|
1420
|
-
headers: { Authorization: `Bearer ${accessToken}` },
|
|
1421
|
-
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)
|
|
1422
|
-
}
|
|
1423
|
-
);
|
|
1424
|
-
if (repositoryResponse.ok) {
|
|
1425
|
-
return { status: "valid" };
|
|
1426
|
-
}
|
|
1427
|
-
if (repositoryResponse.status === 404) {
|
|
1428
|
+
case 404:
|
|
1428
1429
|
return {
|
|
1429
1430
|
status: "repository-not-found",
|
|
1430
|
-
reason:
|
|
1431
|
-
};
|
|
1432
|
-
}
|
|
1433
|
-
if (repositoryResponse.status === 401 || repositoryResponse.status === 403) {
|
|
1434
|
-
return {
|
|
1435
|
-
status: "invalid-credentials",
|
|
1436
|
-
reason: `Login succeeded, but the token is not allowed to read repository ${organisation}/${repository}`
|
|
1431
|
+
reason: `${reason}. This is also the answer for an empty repository. Check REGISTRY_ORGANISATION and REGISTRY_REPOSITORY`
|
|
1437
1432
|
};
|
|
1438
|
-
|
|
1433
|
+
default:
|
|
1434
|
+
return { status: "unreachable", reason };
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1437
|
+
async function validateRegistryCredentials(registry, organisation, repository, username, token) {
|
|
1438
|
+
if (!registry || !organisation || !repository || !username || !token) {
|
|
1439
1439
|
return {
|
|
1440
|
-
status: "
|
|
1441
|
-
reason:
|
|
1440
|
+
status: "skipped",
|
|
1441
|
+
reason: "Some values are kept from existing GitHub secrets, which cannot be read back"
|
|
1442
1442
|
};
|
|
1443
|
+
}
|
|
1444
|
+
const host = registryApiHost(registry);
|
|
1445
|
+
const name = `${organisation}/${repository}`;
|
|
1446
|
+
const basic = `Basic ${Buffer.from(`${username}:${token}`).toString("base64")}`;
|
|
1447
|
+
try {
|
|
1448
|
+
const challenge = (await request(`https://${host}/v2/`, void 0)).headers.get(
|
|
1449
|
+
"www-authenticate"
|
|
1450
|
+
) ?? "";
|
|
1451
|
+
const realm = challenge.match(/realm="([^"]*)"/i)?.[1];
|
|
1452
|
+
const service = challenge.match(/service="([^"]*)"/i)?.[1];
|
|
1453
|
+
let authorization = basic;
|
|
1454
|
+
if (/^\s*bearer/i.test(challenge) && realm) {
|
|
1455
|
+
const tokenUrl = new URL(realm);
|
|
1456
|
+
if (service) {
|
|
1457
|
+
tokenUrl.searchParams.set("service", service);
|
|
1458
|
+
}
|
|
1459
|
+
tokenUrl.searchParams.set("scope", `repository:${name}:pull`);
|
|
1460
|
+
const login = await request(tokenUrl, basic);
|
|
1461
|
+
if (!login.ok) {
|
|
1462
|
+
return failure(registry, "login", login);
|
|
1463
|
+
}
|
|
1464
|
+
const body = await login.json();
|
|
1465
|
+
authorization = `Bearer ${body.token ?? body.access_token}`;
|
|
1466
|
+
}
|
|
1467
|
+
const path15 = name.split("/").map(encodeURIComponent).join("/");
|
|
1468
|
+
const response = await request(
|
|
1469
|
+
`https://${host}/v2/${path15}/tags/list?n=1`,
|
|
1470
|
+
authorization
|
|
1471
|
+
);
|
|
1472
|
+
return response.ok ? { status: "valid" } : failure(registry, `lookup of repository ${name}`, response);
|
|
1443
1473
|
} catch (err) {
|
|
1444
1474
|
if (!(err instanceof Error)) {
|
|
1445
1475
|
return { status: "unreachable", reason: String(err) };
|
|
@@ -1448,11 +1478,10 @@ async function validateDockerHubCredentials(organisation, repository, username,
|
|
|
1448
1478
|
return { status: "unreachable", reason: `${err.message}${cause}` };
|
|
1449
1479
|
}
|
|
1450
1480
|
}
|
|
1451
|
-
var
|
|
1452
|
-
var
|
|
1453
|
-
"src/environment/
|
|
1481
|
+
var REQUEST_TIMEOUT_MS;
|
|
1482
|
+
var init_registry = __esm({
|
|
1483
|
+
"src/environment/registry.ts"() {
|
|
1454
1484
|
"use strict";
|
|
1455
|
-
DOCKER_HUB_API = "https://hub.docker.com/v2";
|
|
1456
1485
|
REQUEST_TIMEOUT_MS = 1e4;
|
|
1457
1486
|
}
|
|
1458
1487
|
});
|
|
@@ -1483,7 +1512,7 @@ function getCurrentUsername() {
|
|
|
1483
1512
|
}
|
|
1484
1513
|
function getCurrentUserSSHKeys() {
|
|
1485
1514
|
const homeDir = os.homedir();
|
|
1486
|
-
const sshDir =
|
|
1515
|
+
const sshDir = path11.join(homeDir, ".ssh");
|
|
1487
1516
|
const keys = [];
|
|
1488
1517
|
const keyFiles = [
|
|
1489
1518
|
"id_rsa.pub",
|
|
@@ -1492,7 +1521,7 @@ function getCurrentUserSSHKeys() {
|
|
|
1492
1521
|
"id_dsa.pub"
|
|
1493
1522
|
];
|
|
1494
1523
|
for (const keyFile of keyFiles) {
|
|
1495
|
-
const keyPath =
|
|
1524
|
+
const keyPath = path11.join(sshDir, keyFile);
|
|
1496
1525
|
try {
|
|
1497
1526
|
if (fs5.existsSync(keyPath)) {
|
|
1498
1527
|
const keyContent = fs5.readFileSync(keyPath, "utf8").trim();
|
|
@@ -1833,13 +1862,13 @@ async function manageUsers(inventoryPath) {
|
|
|
1833
1862
|
}
|
|
1834
1863
|
return users;
|
|
1835
1864
|
}
|
|
1836
|
-
var os, fs5,
|
|
1865
|
+
var os, fs5, path11, input2, select2, confirm, editor, checkbox;
|
|
1837
1866
|
var init_manage_users = __esm({
|
|
1838
1867
|
"src/environment/manage-users.ts"() {
|
|
1839
1868
|
"use strict";
|
|
1840
1869
|
os = __toESM(require("os"));
|
|
1841
1870
|
fs5 = __toESM(require("fs"));
|
|
1842
|
-
|
|
1871
|
+
path11 = __toESM(require("path"));
|
|
1843
1872
|
init_logger();
|
|
1844
1873
|
init_utils();
|
|
1845
1874
|
init_templates();
|
|
@@ -1871,6 +1900,7 @@ async function input3(options) {
|
|
|
1871
1900
|
function questionToPrompt({
|
|
1872
1901
|
valueType,
|
|
1873
1902
|
valueLabel,
|
|
1903
|
+
legacyValueLabel,
|
|
1874
1904
|
scope,
|
|
1875
1905
|
...promptOptions
|
|
1876
1906
|
}) {
|
|
@@ -1934,6 +1964,12 @@ function getAnswers(existingValues) {
|
|
|
1934
1964
|
});
|
|
1935
1965
|
});
|
|
1936
1966
|
}
|
|
1967
|
+
function getInitialValue(question, variable) {
|
|
1968
|
+
if (question.type === "select" && Array.isArray(question.choices)) {
|
|
1969
|
+
return getIndexFromChoices(question.choices, variable.value);
|
|
1970
|
+
}
|
|
1971
|
+
return variable.value;
|
|
1972
|
+
}
|
|
1937
1973
|
async function promptAndStoreAnswer(questions, existingValues) {
|
|
1938
1974
|
log("");
|
|
1939
1975
|
const processedQuestions = questions.flatMap((question) => {
|
|
@@ -1951,14 +1987,22 @@ async function promptAndStoreAnswer(questions, existingValues) {
|
|
|
1951
1987
|
questionWithVariableLabel.scope,
|
|
1952
1988
|
existingValues
|
|
1953
1989
|
);
|
|
1990
|
+
const legacyVariable = !existingVariable && questionWithVariableLabel.legacyValueLabel ? findExistingValue(
|
|
1991
|
+
questionWithVariableLabel.legacyValueLabel,
|
|
1992
|
+
"VARIABLE",
|
|
1993
|
+
questionWithVariableLabel.scope,
|
|
1994
|
+
existingValues
|
|
1995
|
+
) : void 0;
|
|
1996
|
+
if (legacyVariable) {
|
|
1997
|
+
return {
|
|
1998
|
+
...questionWithVariableLabel,
|
|
1999
|
+
message: `${questionWithVariableLabel.message} ${import_kleur4.default.gray(
|
|
2000
|
+
`(default taken from ${legacyVariable.name}, the previous name of this variable)`
|
|
2001
|
+
)}`,
|
|
2002
|
+
initial: getInitialValue(questionWithVariableLabel, legacyVariable)
|
|
2003
|
+
};
|
|
2004
|
+
}
|
|
1954
2005
|
if (existingVariable) {
|
|
1955
|
-
let initial_value = existingVariable.value;
|
|
1956
|
-
if (questionWithVariableLabel.type === "select" && Array.isArray(questionWithVariableLabel.choices)) {
|
|
1957
|
-
initial_value = getIndexFromChoices(
|
|
1958
|
-
questionWithVariableLabel.choices,
|
|
1959
|
-
existingVariable.value
|
|
1960
|
-
);
|
|
1961
|
-
}
|
|
1962
2006
|
return [
|
|
1963
2007
|
{
|
|
1964
2008
|
name: "overWrite" + questionWithVariableLabel.name,
|
|
@@ -1973,7 +2017,10 @@ async function promptAndStoreAnswer(questions, existingValues) {
|
|
|
1973
2017
|
{
|
|
1974
2018
|
...questionWithVariableLabel,
|
|
1975
2019
|
type: (prev) => prev ? questionWithVariableLabel.type : null,
|
|
1976
|
-
initial:
|
|
2020
|
+
initial: getInitialValue(
|
|
2021
|
+
questionWithVariableLabel,
|
|
2022
|
+
existingVariable
|
|
2023
|
+
)
|
|
1977
2024
|
}
|
|
1978
2025
|
];
|
|
1979
2026
|
}
|
|
@@ -1985,6 +2032,32 @@ async function promptAndStoreAnswer(questions, existingValues) {
|
|
|
1985
2032
|
questionWithVariableLabel.scope,
|
|
1986
2033
|
existingValues
|
|
1987
2034
|
);
|
|
2035
|
+
const legacySecret = !existingSecret && questionWithVariableLabel.legacyValueLabel ? findExistingValue(
|
|
2036
|
+
questionWithVariableLabel.legacyValueLabel,
|
|
2037
|
+
"SECRET",
|
|
2038
|
+
questionWithVariableLabel.scope,
|
|
2039
|
+
existingValues
|
|
2040
|
+
) : void 0;
|
|
2041
|
+
if (legacySecret) {
|
|
2042
|
+
return [
|
|
2043
|
+
{
|
|
2044
|
+
name: "overWrite" + questionWithVariableLabel.name,
|
|
2045
|
+
type: "confirm",
|
|
2046
|
+
scope: questionWithVariableLabel.scope,
|
|
2047
|
+
message: `${import_kleur4.default.yellow(
|
|
2048
|
+
`${legacySecret.scope === "REPOSITORY" ? "Repository secret" : "Secret"} ${import_kleur4.default.cyan(
|
|
2049
|
+
legacySecret.name
|
|
2050
|
+
)} already exists in Github under the previous name of ${import_kleur4.default.cyan(
|
|
2051
|
+
questionWithVariableLabel.valueLabel
|
|
2052
|
+
)}. The secrets migration workflow copies it. Do you want to enter a new value instead?`
|
|
2053
|
+
)}`
|
|
2054
|
+
},
|
|
2055
|
+
{
|
|
2056
|
+
...questionWithVariableLabel,
|
|
2057
|
+
type: (prev) => prev ? questionWithVariableLabel.type : null
|
|
2058
|
+
}
|
|
2059
|
+
];
|
|
2060
|
+
}
|
|
1988
2061
|
if (existingSecret) {
|
|
1989
2062
|
return [
|
|
1990
2063
|
{
|
|
@@ -2024,13 +2097,32 @@ async function promptAndStoreAnswer(questions, existingValues) {
|
|
|
2024
2097
|
]);
|
|
2025
2098
|
return { ...Object.fromEntries(existingValuesForQuestions), ...result };
|
|
2026
2099
|
}
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2100
|
+
function defineIfMissing(existingValues, name, type, scope, newValue) {
|
|
2101
|
+
if (findExistingValue(name, type, scope, existingValues)) {
|
|
2102
|
+
return null;
|
|
2103
|
+
}
|
|
2104
|
+
const legacyName = ALL_QUESTIONS.find(
|
|
2105
|
+
(question) => question.valueLabel === name && question.valueType === type && question.scope === scope
|
|
2106
|
+
)?.legacyValueLabel;
|
|
2107
|
+
if (legacyName && findExistingValue(legacyName, type, scope, existingValues)) {
|
|
2108
|
+
log(
|
|
2109
|
+
import_kleur4.default.bold().green("\u2714"),
|
|
2110
|
+
import_kleur4.default.bold().yellow(
|
|
2111
|
+
`${legacyName} exists, the secrets migration workflow copies it to ${name}`
|
|
2112
|
+
)
|
|
2113
|
+
);
|
|
2114
|
+
return null;
|
|
2115
|
+
}
|
|
2116
|
+
return process.env[name] || newValue;
|
|
2117
|
+
}
|
|
2118
|
+
async function promptAndValidateRegistry(existingValues) {
|
|
2119
|
+
const answers = await promptAndStoreAnswer(registryQuestions, existingValues);
|
|
2120
|
+
const result = await validateRegistryCredentials(
|
|
2121
|
+
answers.registryHost,
|
|
2122
|
+
answers.registryOrganisation,
|
|
2123
|
+
answers.registryRepository,
|
|
2124
|
+
answers.registryUsername,
|
|
2125
|
+
answers.registryToken
|
|
2034
2126
|
);
|
|
2035
2127
|
if (result.status === "valid" || result.status === "skipped") {
|
|
2036
2128
|
return;
|
|
@@ -2039,7 +2131,7 @@ async function promptAndValidateDockerhub(existingValues) {
|
|
|
2039
2131
|
${result.status}: ${result.reason || "Generic error"}
|
|
2040
2132
|
`);
|
|
2041
2133
|
const continueNotValidated = await confirm2({
|
|
2042
|
-
message: "
|
|
2134
|
+
message: "Container registry credentials are not validated. Continue anyway?",
|
|
2043
2135
|
default: false
|
|
2044
2136
|
});
|
|
2045
2137
|
if (!continueNotValidated) {
|
|
@@ -2170,7 +2262,22 @@ async function runSetupEnvironment() {
|
|
|
2170
2262
|
"WARNING! You are setting up a production environment.\n Make sure you have read the deployment guide carefully before proceeding.\n"
|
|
2171
2263
|
)
|
|
2172
2264
|
);
|
|
2173
|
-
|
|
2265
|
+
}
|
|
2266
|
+
log("\n", import_kleur4.default.bold().underline("Workflow approvals"));
|
|
2267
|
+
const { approvalRequired } = await promptAndStoreAnswer(
|
|
2268
|
+
[
|
|
2269
|
+
{
|
|
2270
|
+
...githubApprovalRequiredQuestion,
|
|
2271
|
+
initial: getIndexFromChoices(
|
|
2272
|
+
githubApprovalRequiredQuestion.choices,
|
|
2273
|
+
process.env.APPROVAL_REQUIRED || (environment_type === "production" ? "true" : "false")
|
|
2274
|
+
)
|
|
2275
|
+
}
|
|
2276
|
+
],
|
|
2277
|
+
existingValues
|
|
2278
|
+
);
|
|
2279
|
+
if (approvalRequired !== "false") {
|
|
2280
|
+
await promptAndStoreAnswer([githubApproversQuestion], existingValues);
|
|
2174
2281
|
}
|
|
2175
2282
|
log("\n", import_kleur4.default.bold().underline("Two-factor authentication (2FA)"));
|
|
2176
2283
|
const existingTwoFaEnabled = findExistingValue(
|
|
@@ -2189,8 +2296,8 @@ async function runSetupEnvironment() {
|
|
|
2189
2296
|
"2FA is disabled on a production-like environment. Logins will accept the fixed test code 000000, exposing real citizen data. Only do this if you know what you are doing."
|
|
2190
2297
|
);
|
|
2191
2298
|
}
|
|
2192
|
-
log("\n", import_kleur4.default.bold().underline("
|
|
2193
|
-
await
|
|
2299
|
+
log("\n", import_kleur4.default.bold().underline("Container registry"));
|
|
2300
|
+
await promptAndValidateRegistry(existingValues);
|
|
2194
2301
|
log("\n", import_kleur4.default.bold().underline("Kubernetes & Runtime"));
|
|
2195
2302
|
const infrastructure = await promptAndStoreAnswer(
|
|
2196
2303
|
infrastructureQuestions,
|
|
@@ -2282,6 +2389,13 @@ async function runSetupEnvironment() {
|
|
|
2282
2389
|
);
|
|
2283
2390
|
}
|
|
2284
2391
|
}
|
|
2392
|
+
const existingRustfsHostDataPath = findExistingValue(
|
|
2393
|
+
"RUSTFS_HOST_DATA_PATH",
|
|
2394
|
+
"VARIABLE",
|
|
2395
|
+
"ENVIRONMENT",
|
|
2396
|
+
existingValues
|
|
2397
|
+
);
|
|
2398
|
+
const rustfs_host_data_path = existingRustfsHostDataPath?.value || (environment_exists ? "/data/minio" : "/data/rustfs");
|
|
2285
2399
|
let backupHost = findExistingValue("BACKUP_HOST", "VARIABLE", "ENVIRONMENT", existingValues)?.value || "";
|
|
2286
2400
|
let backupType = "";
|
|
2287
2401
|
let restoreEnvironmentName = findExistingValue(
|
|
@@ -2420,9 +2534,7 @@ async function runSetupEnvironment() {
|
|
|
2420
2534
|
return { ...acc, ...answer };
|
|
2421
2535
|
});
|
|
2422
2536
|
const answerOrExisting = (variable, existingValue, fn) => fn(variable || existingValue?.value) || "";
|
|
2423
|
-
|
|
2424
|
-
return findExistingValue(name, type, scope, existingValues) ? null : process.env[name] || newValue;
|
|
2425
|
-
}
|
|
2537
|
+
const findExistingOrDefine = (name, type, scope, newValue) => defineIfMissing(existingValues, name, type, scope, newValue);
|
|
2426
2538
|
const derivedUpdates = [
|
|
2427
2539
|
{
|
|
2428
2540
|
name: "GH_ENCRYPTION_PASSWORD",
|
|
@@ -2474,6 +2586,13 @@ async function runSetupEnvironment() {
|
|
|
2474
2586
|
value: monitoring_enabled ? "true" : "false",
|
|
2475
2587
|
scope: "ENVIRONMENT"
|
|
2476
2588
|
});
|
|
2589
|
+
derivedUpdates.push({
|
|
2590
|
+
name: "RUSTFS_HOST_DATA_PATH",
|
|
2591
|
+
type: "VARIABLE",
|
|
2592
|
+
didExist: existingRustfsHostDataPath,
|
|
2593
|
+
value: rustfs_host_data_path,
|
|
2594
|
+
scope: "ENVIRONMENT"
|
|
2595
|
+
});
|
|
2477
2596
|
derivedUpdates.push(...ssl_answers);
|
|
2478
2597
|
if (configureBackup) {
|
|
2479
2598
|
derivedUpdates.push({
|
|
@@ -2820,7 +2939,7 @@ async function runSetupEnvironment() {
|
|
|
2820
2939
|
);
|
|
2821
2940
|
const unknownVariables = existingValues.filter((value) => {
|
|
2822
2941
|
return !ALL_QUESTIONS.find(
|
|
2823
|
-
(question) => question.valueLabel === value.name && question.valueType === value.type && question.scope === value.scope
|
|
2942
|
+
(question) => (question.valueLabel === value.name || question.legacyValueLabel === value.name) && question.valueType === value.type && question.scope === value.scope
|
|
2824
2943
|
);
|
|
2825
2944
|
});
|
|
2826
2945
|
log("");
|
|
@@ -3025,6 +3144,7 @@ async function runSetupEnvironment() {
|
|
|
3025
3144
|
environment_type,
|
|
3026
3145
|
two_fa_enabled,
|
|
3027
3146
|
monitoring_enabled,
|
|
3147
|
+
rustfs_host_data_path,
|
|
3028
3148
|
traefik_mode: traefikConfOption,
|
|
3029
3149
|
restore_enabled: restoreEnvironmentName ? true : false,
|
|
3030
3150
|
restore_environment_name: restoreEnvironmentName || "",
|
|
@@ -3090,7 +3210,7 @@ var init_setup_environment = __esm({
|
|
|
3090
3210
|
init_questions();
|
|
3091
3211
|
init_editor_questions();
|
|
3092
3212
|
init_questions_helper();
|
|
3093
|
-
|
|
3213
|
+
init_registry();
|
|
3094
3214
|
init_manage_users();
|
|
3095
3215
|
init_paths();
|
|
3096
3216
|
ALL_QUESTIONS = [];
|
|
@@ -3098,7 +3218,7 @@ var init_setup_environment = __esm({
|
|
|
3098
3218
|
ALL_QUESTIONS.push(
|
|
3099
3219
|
...githubTokenQuestion,
|
|
3100
3220
|
...githubOtherQuestions,
|
|
3101
|
-
...
|
|
3221
|
+
...registryQuestions,
|
|
3102
3222
|
...diskQuestions,
|
|
3103
3223
|
...infrastructureQuestions,
|
|
3104
3224
|
...backupQuestions,
|
|
@@ -3127,7 +3247,7 @@ function moveFileIfDestinationMissing(sourcePath, destinationPath) {
|
|
|
3127
3247
|
);
|
|
3128
3248
|
return false;
|
|
3129
3249
|
}
|
|
3130
|
-
(0, import_fs7.mkdirSync)((0,
|
|
3250
|
+
(0, import_fs7.mkdirSync)((0, import_path13.dirname)(destinationPath), { recursive: true });
|
|
3131
3251
|
(0, import_fs7.renameSync)(sourcePath, destinationPath);
|
|
3132
3252
|
log(` \u2713 Moved ${sourcePath} -> ${destinationPath}`);
|
|
3133
3253
|
return true;
|
|
@@ -3167,12 +3287,12 @@ async function upgradeEnvironmentLayout() {
|
|
|
3167
3287
|
}
|
|
3168
3288
|
log("\nCommit changes into git after upgrade");
|
|
3169
3289
|
}
|
|
3170
|
-
var import_fs7,
|
|
3290
|
+
var import_fs7, import_path13, import_kleur5;
|
|
3171
3291
|
var init_upgrade = __esm({
|
|
3172
3292
|
"src/environment/upgrade.ts"() {
|
|
3173
3293
|
"use strict";
|
|
3174
3294
|
import_fs7 = require("fs");
|
|
3175
|
-
|
|
3295
|
+
import_path13 = require("path");
|
|
3176
3296
|
import_kleur5 = __toESM(require("kleur"));
|
|
3177
3297
|
init_logger();
|
|
3178
3298
|
init_paths();
|
|
@@ -3198,7 +3318,7 @@ async function selectInventoryFile(dirPath = "./environments") {
|
|
|
3198
3318
|
return null;
|
|
3199
3319
|
}
|
|
3200
3320
|
const environments = fs6.readdirSync(dirPath).filter((entry) => {
|
|
3201
|
-
const filePath =
|
|
3321
|
+
const filePath = path12.join(dirPath, entry);
|
|
3202
3322
|
return fs6.statSync(filePath).isDirectory() && fs6.existsSync(getEnvironmentInventoryPath(entry));
|
|
3203
3323
|
}).sort();
|
|
3204
3324
|
if (environments.length === 0) {
|
|
@@ -3226,12 +3346,12 @@ async function manageEnvironmentUsers() {
|
|
|
3226
3346
|
}
|
|
3227
3347
|
await manageUsers(inventory_file);
|
|
3228
3348
|
}
|
|
3229
|
-
var fs6,
|
|
3349
|
+
var fs6, path12, import_kleur6;
|
|
3230
3350
|
var init_users = __esm({
|
|
3231
3351
|
"src/environment/users.ts"() {
|
|
3232
3352
|
"use strict";
|
|
3233
3353
|
fs6 = __toESM(require("fs"));
|
|
3234
|
-
|
|
3354
|
+
path12 = __toESM(require("path"));
|
|
3235
3355
|
import_kleur6 = __toESM(require("kleur"));
|
|
3236
3356
|
init_manage_users();
|
|
3237
3357
|
init_logger();
|
|
@@ -3241,11 +3361,11 @@ var init_users = __esm({
|
|
|
3241
3361
|
|
|
3242
3362
|
// src/environment/swarm-to-k8s.ts
|
|
3243
3363
|
var swarm_to_k8s_exports = {};
|
|
3244
|
-
var
|
|
3364
|
+
var path13, import_kleur7, import_core2;
|
|
3245
3365
|
var init_swarm_to_k8s = __esm({
|
|
3246
3366
|
"src/environment/swarm-to-k8s.ts"() {
|
|
3247
3367
|
"use strict";
|
|
3248
|
-
|
|
3368
|
+
path13 = __toESM(require("path"));
|
|
3249
3369
|
import_kleur7 = __toESM(require("kleur"));
|
|
3250
3370
|
init_logger();
|
|
3251
3371
|
init_utils();
|
|
@@ -3297,7 +3417,7 @@ var init_swarm_to_k8s = __esm({
|
|
|
3297
3417
|
);
|
|
3298
3418
|
process.exit(1);
|
|
3299
3419
|
}
|
|
3300
|
-
const ansible_inventory =
|
|
3420
|
+
const ansible_inventory = path13.join(old_inventory_path, environment + ".yml");
|
|
3301
3421
|
const data = readYamlFile(ansible_inventory);
|
|
3302
3422
|
log(` \u2713 Loaded old inventory file: ${ansible_inventory}`);
|
|
3303
3423
|
const master = dockerManagerFirst(data) || "";
|
|
@@ -3420,7 +3540,7 @@ var init_swarm_to_k8s = __esm({
|
|
|
3420
3540
|
|
|
3421
3541
|
// src/cli.ts
|
|
3422
3542
|
var import_fs9 = __toESM(require("fs"));
|
|
3423
|
-
var
|
|
3543
|
+
var import_path15 = __toESM(require("path"));
|
|
3424
3544
|
|
|
3425
3545
|
// src/migrations/persistent/add-translations.ts
|
|
3426
3546
|
var import_path = __toESM(require("path"));
|
|
@@ -3465,20 +3585,20 @@ function idOf(line2) {
|
|
|
3465
3585
|
const comma = line2.indexOf(",");
|
|
3466
3586
|
return comma === -1 ? line2 : line2.slice(0, comma);
|
|
3467
3587
|
}
|
|
3468
|
-
function readCsvFile(
|
|
3469
|
-
if (!(0, import_fs.existsSync)(
|
|
3588
|
+
function readCsvFile(path15) {
|
|
3589
|
+
if (!(0, import_fs.existsSync)(path15)) {
|
|
3470
3590
|
return void 0;
|
|
3471
3591
|
}
|
|
3472
|
-
const contents = (0, import_fs.readFileSync)(
|
|
3592
|
+
const contents = (0, import_fs.readFileSync)(path15, "utf8");
|
|
3473
3593
|
const newline = contents.includes("\r\n") ? "\r\n" : "\n";
|
|
3474
3594
|
const trailingNewline = /\r?\n$/.test(contents);
|
|
3475
3595
|
const lines = contents.replace(/\r?\n$/, "").split(/\r?\n/);
|
|
3476
3596
|
const body = lines.slice(1).filter((line2) => line2 !== "");
|
|
3477
3597
|
return { header: lines[0], body, newline, trailingNewline };
|
|
3478
3598
|
}
|
|
3479
|
-
function writeCsvFile(
|
|
3599
|
+
function writeCsvFile(path15, file) {
|
|
3480
3600
|
(0, import_fs.writeFileSync)(
|
|
3481
|
-
|
|
3601
|
+
path15,
|
|
3482
3602
|
[file.header, ...file.body].join(file.newline) + (file.trailingNewline ? file.newline : "")
|
|
3483
3603
|
);
|
|
3484
3604
|
}
|
|
@@ -3640,12 +3760,14 @@ async function main(targetVersion) {
|
|
|
3640
3760
|
}
|
|
3641
3761
|
|
|
3642
3762
|
// src/migrations/move-declaration-to-declare-action.ts
|
|
3763
|
+
var import_ts_morph2 = require("ts-morph");
|
|
3764
|
+
var import_path3 = __toESM(require("path"));
|
|
3765
|
+
|
|
3766
|
+
// src/migrations/utils.ts
|
|
3643
3767
|
var import_ts_morph = require("ts-morph");
|
|
3644
3768
|
var import_path2 = __toESM(require("path"));
|
|
3645
3769
|
var DEFINE_CONFIG_NAME = "defineConfig";
|
|
3646
|
-
var
|
|
3647
|
-
var ACTIONS_PROPERTY_NAME = "actions";
|
|
3648
|
-
var DECLARE_ACTION_TYPE = "DECLARE";
|
|
3770
|
+
var TOOLKIT_EVENTS_MODULE = "@opencrvs/toolkit/events";
|
|
3649
3771
|
function location(node) {
|
|
3650
3772
|
const relPath = import_path2.default.relative(
|
|
3651
3773
|
process.cwd(),
|
|
@@ -3665,7 +3787,7 @@ function findProperty(literal, name) {
|
|
|
3665
3787
|
const property = literal.getProperty(name);
|
|
3666
3788
|
return import_ts_morph.Node.isPropertyAssignment(property) || import_ts_morph.Node.isShorthandPropertyAssignment(property) ? property : void 0;
|
|
3667
3789
|
}
|
|
3668
|
-
function
|
|
3790
|
+
function mayHaveActionType(actionType, node, expectedActionType) {
|
|
3669
3791
|
const typeProperty = actionType.getProperty("type");
|
|
3670
3792
|
if (!typeProperty) {
|
|
3671
3793
|
return true;
|
|
@@ -3673,50 +3795,25 @@ function mayHaveDeclareType(actionType, node) {
|
|
|
3673
3795
|
const type = typeProperty.getTypeAtLocation(node);
|
|
3674
3796
|
const values = type.isUnion() ? type.getUnionTypes() : [type];
|
|
3675
3797
|
return !values.every(
|
|
3676
|
-
(value) => value.isStringLiteral() && value.getLiteralValue() !==
|
|
3798
|
+
(value) => value.isStringLiteral() && value.getLiteralValue() !== expectedActionType
|
|
3677
3799
|
);
|
|
3678
3800
|
}
|
|
3679
|
-
function
|
|
3801
|
+
function mayBeAction(node, actionType) {
|
|
3680
3802
|
if (import_ts_morph.Node.isObjectLiteralExpression(node)) {
|
|
3681
|
-
return
|
|
3803
|
+
return isAction(node, actionType);
|
|
3682
3804
|
}
|
|
3683
3805
|
if (import_ts_morph.Node.isSpreadElement(node)) {
|
|
3684
3806
|
const arrayType = node.getExpression().getType();
|
|
3685
3807
|
const elementTypes = arrayType.isTuple() ? arrayType.getTupleElements() : [arrayType.getArrayElementType()];
|
|
3686
3808
|
return elementTypes.some(
|
|
3687
|
-
(elementType) => !elementType ||
|
|
3809
|
+
(elementType) => !elementType || mayHaveActionType(elementType, node, actionType)
|
|
3688
3810
|
);
|
|
3689
3811
|
}
|
|
3690
|
-
return
|
|
3812
|
+
return mayHaveActionType(node.getType(), node, actionType);
|
|
3691
3813
|
}
|
|
3692
|
-
function
|
|
3814
|
+
function isAction(literal, actionType) {
|
|
3693
3815
|
const type = findProperty(literal, "type");
|
|
3694
|
-
return import_ts_morph.Node.isPropertyAssignment(type) && type.getInitializerOrThrow().getType().getLiteralValue() ===
|
|
3695
|
-
}
|
|
3696
|
-
function findDeclareAction(config) {
|
|
3697
|
-
const actions = findProperty(config, ACTIONS_PROPERTY_NAME);
|
|
3698
|
-
const actionsValue = import_ts_morph.Node.isPropertyAssignment(actions) ? actions.getInitializer() : void 0;
|
|
3699
|
-
if (!import_ts_morph.Node.isArrayLiteralExpression(actionsValue)) {
|
|
3700
|
-
console.warn(
|
|
3701
|
-
` [${location(config)}] Skipped: \`${ACTIONS_PROPERTY_NAME}\` is not an array literal. Move \`${DECLARATION_PROPERTY_NAME}\` onto the ${DECLARE_ACTION_TYPE} action by hand.`
|
|
3702
|
-
);
|
|
3703
|
-
return void 0;
|
|
3704
|
-
}
|
|
3705
|
-
const candidates = actionsValue.getElements().filter(mayBeDeclareAction);
|
|
3706
|
-
if (candidates.length !== 1 || !import_ts_morph.Node.isObjectLiteralExpression(candidates[0])) {
|
|
3707
|
-
console.warn(
|
|
3708
|
-
` [${location(config)}] Skipped: could not find exactly one ${DECLARE_ACTION_TYPE} action written as an object literal in \`${ACTIONS_PROPERTY_NAME}\`. Move \`${DECLARATION_PROPERTY_NAME}\` onto it by hand.`
|
|
3709
|
-
);
|
|
3710
|
-
return void 0;
|
|
3711
|
-
}
|
|
3712
|
-
const declareAction = candidates[0];
|
|
3713
|
-
if (findProperty(declareAction, DECLARATION_PROPERTY_NAME)) {
|
|
3714
|
-
console.warn(
|
|
3715
|
-
` [${location(config)}] Skipped: \`${DECLARATION_PROPERTY_NAME}\` is set both at the top level and on the ${DECLARE_ACTION_TYPE} action. Keep only the one on the action.`
|
|
3716
|
-
);
|
|
3717
|
-
return void 0;
|
|
3718
|
-
}
|
|
3719
|
-
return declareAction;
|
|
3816
|
+
return import_ts_morph.Node.isPropertyAssignment(type) && type.getInitializerOrThrow().getType().getLiteralValue() === actionType;
|
|
3720
3817
|
}
|
|
3721
3818
|
function indentationOf(node) {
|
|
3722
3819
|
const text = node.getSourceFile().getFullText();
|
|
@@ -3758,6 +3855,90 @@ function layoutOf(property) {
|
|
|
3758
3855
|
function insertAt(position, text) {
|
|
3759
3856
|
return { start: position, end: position, text };
|
|
3760
3857
|
}
|
|
3858
|
+
function applyTextEdits(sourceFile, edits) {
|
|
3859
|
+
const text = [...edits].sort((a, b) => b.start - a.start).reduce(
|
|
3860
|
+
(result, edit) => result.slice(0, edit.start) + edit.text + result.slice(edit.end),
|
|
3861
|
+
sourceFile.getFullText()
|
|
3862
|
+
);
|
|
3863
|
+
sourceFile.replaceWithText(text);
|
|
3864
|
+
}
|
|
3865
|
+
function findToolkitImport(sourceFile) {
|
|
3866
|
+
return sourceFile.getImportDeclaration(
|
|
3867
|
+
(declaration) => declaration.getModuleSpecifierValue() === TOOLKIT_EVENTS_MODULE && !declaration.isTypeOnly() && !declaration.getNamespaceImport()
|
|
3868
|
+
);
|
|
3869
|
+
}
|
|
3870
|
+
function findToolkitImportName(sourceFile, name) {
|
|
3871
|
+
const imported = findToolkitImport(sourceFile)?.getNamedImports().find((namedImport) => namedImport.getName() === name);
|
|
3872
|
+
if (imported) {
|
|
3873
|
+
return imported.getAliasNode()?.getText() ?? name;
|
|
3874
|
+
}
|
|
3875
|
+
if (sourceFile.getLocal(name)) {
|
|
3876
|
+
return void 0;
|
|
3877
|
+
}
|
|
3878
|
+
return name;
|
|
3879
|
+
}
|
|
3880
|
+
function addToolkitImport(sourceFile, name) {
|
|
3881
|
+
const toolkitImport = findToolkitImport(sourceFile);
|
|
3882
|
+
if (!toolkitImport) {
|
|
3883
|
+
const imports = sourceFile.getImportDeclarations();
|
|
3884
|
+
const lastImport = imports[imports.length - 1];
|
|
3885
|
+
sourceFile.insertStatements(
|
|
3886
|
+
lastImport ? lastImport.getChildIndex() + 1 : 0,
|
|
3887
|
+
`import { ${name} } from '${TOOLKIT_EVENTS_MODULE}'`
|
|
3888
|
+
);
|
|
3889
|
+
return;
|
|
3890
|
+
}
|
|
3891
|
+
const alreadyImported = toolkitImport.getNamedImports().some((namedImport) => namedImport.getName() === name);
|
|
3892
|
+
if (alreadyImported) {
|
|
3893
|
+
return;
|
|
3894
|
+
}
|
|
3895
|
+
const namedImports = toolkitImport.getNamedImports();
|
|
3896
|
+
if (toolkitImport.getDefaultImport() || namedImports.length === 0) {
|
|
3897
|
+
toolkitImport.addNamedImport(name);
|
|
3898
|
+
return;
|
|
3899
|
+
}
|
|
3900
|
+
const names = [
|
|
3901
|
+
...namedImports.map((namedImport) => namedImport.getText()),
|
|
3902
|
+
name
|
|
3903
|
+
];
|
|
3904
|
+
const specifiers = toolkitImport.getText().includes("\n") ? `{
|
|
3905
|
+
${names.join(",\n ")}
|
|
3906
|
+
}` : `{ ${names.join(", ")} }`;
|
|
3907
|
+
toolkitImport.replaceWithText(
|
|
3908
|
+
`import ${specifiers} from '${TOOLKIT_EVENTS_MODULE}'`
|
|
3909
|
+
);
|
|
3910
|
+
}
|
|
3911
|
+
|
|
3912
|
+
// src/migrations/move-declaration-to-declare-action.ts
|
|
3913
|
+
var DEFINE_CONFIG_NAME2 = "defineConfig";
|
|
3914
|
+
var DECLARATION_PROPERTY_NAME = "declaration";
|
|
3915
|
+
var ACTIONS_PROPERTY_NAME = "actions";
|
|
3916
|
+
var DECLARE_ACTION_TYPE = "DECLARE";
|
|
3917
|
+
function findDeclareAction(config) {
|
|
3918
|
+
const actions = findProperty(config, ACTIONS_PROPERTY_NAME);
|
|
3919
|
+
const actionsValue = import_ts_morph2.Node.isPropertyAssignment(actions) ? actions.getInitializer() : void 0;
|
|
3920
|
+
if (!import_ts_morph2.Node.isArrayLiteralExpression(actionsValue)) {
|
|
3921
|
+
console.warn(
|
|
3922
|
+
` [${location(config)}] Skipped: \`${ACTIONS_PROPERTY_NAME}\` is not an array literal. Move \`${DECLARATION_PROPERTY_NAME}\` onto the ${DECLARE_ACTION_TYPE} action by hand.`
|
|
3923
|
+
);
|
|
3924
|
+
return void 0;
|
|
3925
|
+
}
|
|
3926
|
+
const candidates = actionsValue.getElements().filter((element) => mayBeAction(element, DECLARE_ACTION_TYPE));
|
|
3927
|
+
if (candidates.length !== 1 || !import_ts_morph2.Node.isObjectLiteralExpression(candidates[0])) {
|
|
3928
|
+
console.warn(
|
|
3929
|
+
` [${location(config)}] Skipped: could not find exactly one ${DECLARE_ACTION_TYPE} action written as an object literal in \`${ACTIONS_PROPERTY_NAME}\`. Move \`${DECLARATION_PROPERTY_NAME}\` onto it by hand.`
|
|
3930
|
+
);
|
|
3931
|
+
return void 0;
|
|
3932
|
+
}
|
|
3933
|
+
const declareAction = candidates[0];
|
|
3934
|
+
if (findProperty(declareAction, DECLARATION_PROPERTY_NAME)) {
|
|
3935
|
+
console.warn(
|
|
3936
|
+
` [${location(config)}] Skipped: \`${DECLARATION_PROPERTY_NAME}\` is set both at the top level and on the ${DECLARE_ACTION_TYPE} action. Keep only the one on the action.`
|
|
3937
|
+
);
|
|
3938
|
+
return void 0;
|
|
3939
|
+
}
|
|
3940
|
+
return declareAction;
|
|
3941
|
+
}
|
|
3761
3942
|
function insertIntoDeclareAction(declareAction, property) {
|
|
3762
3943
|
const anchor = declareAction.getProperty("label") ?? declareAction.getPropertyOrThrow("type");
|
|
3763
3944
|
const text = property.getSourceFile().getFullText();
|
|
@@ -3794,7 +3975,7 @@ ${indent}` : ", ";
|
|
|
3794
3975
|
function removeFromConfig(property) {
|
|
3795
3976
|
const text = property.getSourceFile().getFullText();
|
|
3796
3977
|
const layout = layoutOf(property);
|
|
3797
|
-
const previousComma = property.getPreviousSiblings().find((sibling) => !isOnlyComments(sibling.getText()))?.asKind(
|
|
3978
|
+
const previousComma = property.getPreviousSiblings().find((sibling) => !isOnlyComments(sibling.getText()))?.asKind(import_ts_morph2.SyntaxKind.CommaToken);
|
|
3798
3979
|
if (layout.ownsLines) {
|
|
3799
3980
|
const lines = {
|
|
3800
3981
|
start: text.lastIndexOf("\n", layout.start - 1),
|
|
@@ -3823,18 +4004,18 @@ function removeFromConfig(property) {
|
|
|
3823
4004
|
}
|
|
3824
4005
|
function findConfigLiteral(call) {
|
|
3825
4006
|
const config = call.getArguments()[0];
|
|
3826
|
-
if (!config ||
|
|
4007
|
+
if (!config || import_ts_morph2.Node.isObjectLiteralExpression(config)) {
|
|
3827
4008
|
return config;
|
|
3828
4009
|
}
|
|
3829
4010
|
if (config.getType().getProperty(DECLARATION_PROPERTY_NAME)) {
|
|
3830
4011
|
console.warn(
|
|
3831
|
-
` [${location(config)}] Skipped: \`${
|
|
4012
|
+
` [${location(config)}] Skipped: \`${DEFINE_CONFIG_NAME2}\` is not given an object literal. If its config has a top-level \`${DECLARATION_PROPERTY_NAME}\`, move it onto the ${DECLARE_ACTION_TYPE} action by hand.`
|
|
3832
4013
|
);
|
|
3833
4014
|
}
|
|
3834
4015
|
return void 0;
|
|
3835
4016
|
}
|
|
3836
4017
|
function moveDeclarationToDeclareAction(sourceFile) {
|
|
3837
|
-
const configs = sourceFile.getDescendantsOfKind(
|
|
4018
|
+
const configs = sourceFile.getDescendantsOfKind(import_ts_morph2.SyntaxKind.CallExpression).filter(isToolkitDefineConfigCall).map(findConfigLiteral).filter(import_ts_morph2.Node.isObjectLiteralExpression);
|
|
3838
4019
|
const edits = [];
|
|
3839
4020
|
let changes = 0;
|
|
3840
4021
|
for (const config of configs) {
|
|
@@ -3858,19 +4039,15 @@ function moveDeclarationToDeclareAction(sourceFile) {
|
|
|
3858
4039
|
if (changes === 0) {
|
|
3859
4040
|
return 0;
|
|
3860
4041
|
}
|
|
3861
|
-
|
|
3862
|
-
(result, edit) => result.slice(0, edit.start) + edit.text + result.slice(edit.end),
|
|
3863
|
-
sourceFile.getFullText()
|
|
3864
|
-
);
|
|
3865
|
-
sourceFile.replaceWithText(text);
|
|
4042
|
+
applyTextEdits(sourceFile, edits);
|
|
3866
4043
|
return changes;
|
|
3867
4044
|
}
|
|
3868
4045
|
async function main2() {
|
|
3869
|
-
const srcDir =
|
|
4046
|
+
const srcDir = import_path3.default.join(process.cwd(), "src");
|
|
3870
4047
|
console.log(`Scanning for top-level event declarations in: ${srcDir}
|
|
3871
4048
|
`);
|
|
3872
|
-
const project = new
|
|
3873
|
-
tsConfigFilePath:
|
|
4049
|
+
const project = new import_ts_morph2.Project({
|
|
4050
|
+
tsConfigFilePath: import_path3.default.resolve(srcDir, "../tsconfig.json"),
|
|
3874
4051
|
skipAddingFilesFromTsConfig: false
|
|
3875
4052
|
});
|
|
3876
4053
|
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
@@ -3897,7 +4074,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
3897
4074
|
for (const sourceFile of modifiedFiles) {
|
|
3898
4075
|
await sourceFile.save();
|
|
3899
4076
|
console.log(
|
|
3900
|
-
` Saved: ${
|
|
4077
|
+
` Saved: ${import_path3.default.relative(process.cwd(), sourceFile.getFilePath())}`
|
|
3901
4078
|
);
|
|
3902
4079
|
}
|
|
3903
4080
|
console.log(
|
|
@@ -3906,36 +4083,223 @@ Done. Moved ${totalChanges} declaration(s) across ${modifiedFiles.length} file(s
|
|
|
3906
4083
|
);
|
|
3907
4084
|
}
|
|
3908
4085
|
|
|
3909
|
-
// src/migrations/
|
|
3910
|
-
var
|
|
3911
|
-
var
|
|
3912
|
-
var
|
|
4086
|
+
// src/migrations/add-notify-config.ts
|
|
4087
|
+
var import_ts_morph3 = require("ts-morph");
|
|
4088
|
+
var import_path4 = __toESM(require("path"));
|
|
4089
|
+
var DEFINE_CONFIG_NAME3 = "defineConfig";
|
|
4090
|
+
var ACTIONS_PROPERTY_NAME2 = "actions";
|
|
3913
4091
|
var DECLARATION_PROPERTY_NAME2 = "declaration";
|
|
3914
|
-
var
|
|
3915
|
-
var
|
|
3916
|
-
|
|
3917
|
-
|
|
3918
|
-
|
|
3919
|
-
|
|
3920
|
-
|
|
4092
|
+
var NOTIFY_ACTION_TYPE = "NOTIFY";
|
|
4093
|
+
var DECLARE_ACTION_TYPE2 = "DECLARE";
|
|
4094
|
+
var NOTIFY_PROPERTIES = [
|
|
4095
|
+
{
|
|
4096
|
+
name: "notificationForm",
|
|
4097
|
+
helper: "toNotificationForm",
|
|
4098
|
+
declareProperty: DECLARATION_PROPERTY_NAME2
|
|
4099
|
+
},
|
|
4100
|
+
{
|
|
4101
|
+
name: "review",
|
|
4102
|
+
helper: "toNotificationReview",
|
|
4103
|
+
declareProperty: "review"
|
|
3921
4104
|
}
|
|
3922
|
-
|
|
4105
|
+
];
|
|
4106
|
+
function referenceOf(property) {
|
|
4107
|
+
if (import_ts_morph3.Node.isShorthandPropertyAssignment(property)) {
|
|
4108
|
+
return property.getName();
|
|
4109
|
+
}
|
|
4110
|
+
const value = property?.getInitializer();
|
|
4111
|
+
return import_ts_morph3.Node.isIdentifier(value) || import_ts_morph3.Node.isPropertyAccessExpression(value) ? value.getText() : void 0;
|
|
4112
|
+
}
|
|
4113
|
+
function findConfigLiteral2(call) {
|
|
4114
|
+
const config = call.getArguments()[0];
|
|
4115
|
+
if (import_ts_morph3.Node.isObjectLiteralExpression(config)) {
|
|
4116
|
+
return config;
|
|
4117
|
+
}
|
|
4118
|
+
console.warn(
|
|
4119
|
+
` [${location(call)}] Skipped: \`${DEFINE_CONFIG_NAME3}\` is not given an object literal. If the event has a NOTIFY action, give it a \`notificationForm\` and \`review\` by hand.`
|
|
4120
|
+
);
|
|
4121
|
+
return void 0;
|
|
4122
|
+
}
|
|
4123
|
+
function findNotifyAction(config, actions) {
|
|
4124
|
+
const candidates = actions.filter(
|
|
4125
|
+
(action) => mayBeAction(action, NOTIFY_ACTION_TYPE)
|
|
4126
|
+
);
|
|
4127
|
+
if (candidates.length === 0) {
|
|
4128
|
+
console.warn(
|
|
4129
|
+
` [${location(config)}] No ${NOTIFY_ACTION_TYPE} action: the event cannot be notified. If a role has \`record.notify\` for it, add a ${NOTIFY_ACTION_TYPE} action with a \`notificationForm\` and \`review\`.`
|
|
4130
|
+
);
|
|
4131
|
+
return void 0;
|
|
4132
|
+
}
|
|
4133
|
+
if (candidates.length !== 1 || !import_ts_morph3.Node.isObjectLiteralExpression(candidates[0])) {
|
|
4134
|
+
console.warn(
|
|
4135
|
+
` [${location(config)}] Skipped: could not find exactly one ${NOTIFY_ACTION_TYPE} action written as an object literal in \`${ACTIONS_PROPERTY_NAME2}\`. Give it a \`notificationForm\` and \`review\` by hand.`
|
|
4136
|
+
);
|
|
4137
|
+
return void 0;
|
|
4138
|
+
}
|
|
4139
|
+
return candidates[0];
|
|
4140
|
+
}
|
|
4141
|
+
function insertIntoAction(action, properties) {
|
|
4142
|
+
const anchor = action.getProperty("label") ?? action.getPropertyOrThrow("type");
|
|
4143
|
+
const text = action.getSourceFile().getFullText();
|
|
4144
|
+
const anchorLayout = layoutOf(anchor);
|
|
4145
|
+
const indent = indentationOf(anchor);
|
|
4146
|
+
if (anchorLayout.ownsLines) {
|
|
4147
|
+
const position = anchorLayout.end + restOfLine(text, anchorLayout.end).length;
|
|
4148
|
+
const lines = properties.map((property) => `
|
|
4149
|
+
${indent}${property}`);
|
|
4150
|
+
if (anchorLayout.hasComma) {
|
|
4151
|
+
return [insertAt(position, `${lines.join(",")},`)];
|
|
4152
|
+
}
|
|
4153
|
+
return position === anchor.getEnd() ? [insertAt(position, `,${lines.join(",")}`)] : [insertAt(anchor.getEnd(), ","), insertAt(position, lines.join(","))];
|
|
4154
|
+
}
|
|
4155
|
+
const separator = action.getText().includes("\n") ? `,
|
|
4156
|
+
${indent}` : ", ";
|
|
4157
|
+
return [
|
|
4158
|
+
insertAt(
|
|
4159
|
+
anchor.getEnd(),
|
|
4160
|
+
properties.map((property) => `${separator}${property}`).join("")
|
|
4161
|
+
)
|
|
4162
|
+
];
|
|
4163
|
+
}
|
|
4164
|
+
function addNotifyConfig(sourceFile) {
|
|
4165
|
+
const configs = sourceFile.getDescendantsOfKind(import_ts_morph3.SyntaxKind.CallExpression).filter(isToolkitDefineConfigCall).map(findConfigLiteral2).filter(import_ts_morph3.Node.isObjectLiteralExpression);
|
|
4166
|
+
const helperNames = Object.fromEntries(
|
|
4167
|
+
NOTIFY_PROPERTIES.map(({ helper }) => [
|
|
4168
|
+
helper,
|
|
4169
|
+
findToolkitImportName(sourceFile, helper)
|
|
4170
|
+
])
|
|
4171
|
+
);
|
|
4172
|
+
const edits = [];
|
|
4173
|
+
const usedHelpers = /* @__PURE__ */ new Set();
|
|
4174
|
+
let changes = 0;
|
|
4175
|
+
for (const config of configs) {
|
|
4176
|
+
const actions = findProperty(config, ACTIONS_PROPERTY_NAME2);
|
|
4177
|
+
const actionsValue = import_ts_morph3.Node.isPropertyAssignment(actions) ? actions.getInitializer() : void 0;
|
|
4178
|
+
if (!import_ts_morph3.Node.isArrayLiteralExpression(actionsValue)) {
|
|
4179
|
+
console.warn(
|
|
4180
|
+
` [${location(config)}] Skipped: \`${ACTIONS_PROPERTY_NAME2}\` is not an array literal. If the event has a ${NOTIFY_ACTION_TYPE} action, give it a \`notificationForm\` and \`review\` by hand.`
|
|
4181
|
+
);
|
|
4182
|
+
continue;
|
|
4183
|
+
}
|
|
4184
|
+
const notifyAction = findNotifyAction(config, actionsValue.getElements());
|
|
4185
|
+
if (!notifyAction) {
|
|
4186
|
+
continue;
|
|
4187
|
+
}
|
|
4188
|
+
const declareAction = actionsValue.getElements().find(
|
|
4189
|
+
(action) => import_ts_morph3.Node.isObjectLiteralExpression(action) && isAction(action, DECLARE_ACTION_TYPE2)
|
|
4190
|
+
);
|
|
4191
|
+
const properties = NOTIFY_PROPERTIES.filter(
|
|
4192
|
+
({ name }) => !findProperty(notifyAction, name)
|
|
4193
|
+
).flatMap(({ name, helper, declareProperty }) => {
|
|
4194
|
+
const helperName = helperNames[helper];
|
|
4195
|
+
const reference = referenceOf(
|
|
4196
|
+
(declareAction && findProperty(declareAction, declareProperty)) ?? (declareProperty === DECLARATION_PROPERTY_NAME2 ? findProperty(config, declareProperty) : void 0)
|
|
4197
|
+
);
|
|
4198
|
+
if (!helperName) {
|
|
4199
|
+
console.warn(
|
|
4200
|
+
` [${location(notifyAction)}] Skipped \`${name}\`: the file already declares its own \`${helper}\`. Add \`${name}\` to the ${NOTIFY_ACTION_TYPE} action by hand, using the toolkit's \`${helper}\`.`
|
|
4201
|
+
);
|
|
4202
|
+
return [];
|
|
4203
|
+
}
|
|
4204
|
+
if (!reference) {
|
|
4205
|
+
console.warn(
|
|
4206
|
+
` [${location(notifyAction)}] Skipped \`${name}\`: the ${DECLARE_ACTION_TYPE2} action's \`${declareProperty}\` is not given as a name. Add \`${name}: ${helper}(<${DECLARE_ACTION_TYPE2} ${declareProperty}>)\` to the ${NOTIFY_ACTION_TYPE} action by hand.`
|
|
4207
|
+
);
|
|
4208
|
+
return [];
|
|
4209
|
+
}
|
|
4210
|
+
if (helperName === helper) {
|
|
4211
|
+
usedHelpers.add(helper);
|
|
4212
|
+
}
|
|
4213
|
+
return [`${name}: ${helperName}(${reference})`];
|
|
4214
|
+
});
|
|
4215
|
+
if (properties.length === 0) {
|
|
4216
|
+
continue;
|
|
4217
|
+
}
|
|
4218
|
+
console.log(
|
|
4219
|
+
` [${location(notifyAction)}] Added \`${properties.join("`, `")}\` to the ${NOTIFY_ACTION_TYPE} action`
|
|
4220
|
+
);
|
|
4221
|
+
edits.push(...insertIntoAction(notifyAction, properties));
|
|
4222
|
+
changes++;
|
|
4223
|
+
}
|
|
4224
|
+
if (changes === 0) {
|
|
4225
|
+
return 0;
|
|
4226
|
+
}
|
|
4227
|
+
applyTextEdits(sourceFile, edits);
|
|
4228
|
+
for (const helper of usedHelpers) {
|
|
4229
|
+
addToolkitImport(sourceFile, helper);
|
|
4230
|
+
}
|
|
4231
|
+
return changes;
|
|
4232
|
+
}
|
|
4233
|
+
async function main3() {
|
|
4234
|
+
const srcDir = import_path4.default.join(process.cwd(), "src");
|
|
4235
|
+
console.log(`Scanning for NOTIFY actions in: ${srcDir}
|
|
4236
|
+
`);
|
|
4237
|
+
const project = new import_ts_morph3.Project({
|
|
4238
|
+
tsConfigFilePath: import_path4.default.resolve(srcDir, "../tsconfig.json"),
|
|
4239
|
+
skipAddingFilesFromTsConfig: false
|
|
4240
|
+
});
|
|
4241
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
4242
|
+
const fp = sf.getFilePath();
|
|
4243
|
+
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
4244
|
+
});
|
|
4245
|
+
console.log(`Found ${sourceFiles.length} source file(s) to analyse.
|
|
4246
|
+
`);
|
|
4247
|
+
let totalChanges = 0;
|
|
4248
|
+
const modifiedFiles = [];
|
|
4249
|
+
for (const sourceFile of sourceFiles) {
|
|
4250
|
+
const changes = addNotifyConfig(sourceFile);
|
|
4251
|
+
if (changes > 0) {
|
|
4252
|
+
totalChanges += changes;
|
|
4253
|
+
modifiedFiles.push(sourceFile);
|
|
4254
|
+
}
|
|
4255
|
+
}
|
|
4256
|
+
if (modifiedFiles.length === 0) {
|
|
4257
|
+
console.log("No NOTIFY actions to update. Nothing to do.");
|
|
4258
|
+
return;
|
|
4259
|
+
}
|
|
4260
|
+
console.log(`
|
|
4261
|
+
Saving ${modifiedFiles.length} modified file(s)...`);
|
|
4262
|
+
for (const sourceFile of modifiedFiles) {
|
|
4263
|
+
await sourceFile.save();
|
|
4264
|
+
console.log(
|
|
4265
|
+
` Saved: ${import_path4.default.relative(process.cwd(), sourceFile.getFilePath())}`
|
|
4266
|
+
);
|
|
4267
|
+
}
|
|
4268
|
+
console.log(
|
|
4269
|
+
`
|
|
4270
|
+
Done. Updated ${totalChanges} NOTIFY action(s) across ${modifiedFiles.length} file(s).`
|
|
4271
|
+
);
|
|
4272
|
+
}
|
|
4273
|
+
|
|
4274
|
+
// src/migrations/read-declaration-through-helper.ts
|
|
4275
|
+
var import_ts_morph4 = require("ts-morph");
|
|
4276
|
+
var import_path5 = __toESM(require("path"));
|
|
4277
|
+
var EVENT_CONFIG_TYPE_NAME = "EventConfig";
|
|
4278
|
+
var DECLARATION_PROPERTY_NAME3 = "declaration";
|
|
4279
|
+
var GET_DECLARATION_NAME = "getDeclaration";
|
|
4280
|
+
function isToolkitEventConfig(type) {
|
|
4281
|
+
const nonNullableType = type.getNonNullableType();
|
|
4282
|
+
const symbol = nonNullableType.getAliasSymbol() ?? nonNullableType.getSymbol();
|
|
4283
|
+
if (symbol?.getName() !== EVENT_CONFIG_TYPE_NAME) {
|
|
4284
|
+
return false;
|
|
4285
|
+
}
|
|
4286
|
+
return symbol.getDeclarations().some((declaration) => declaration.getSourceFile().isDeclarationFile());
|
|
3923
4287
|
}
|
|
3924
4288
|
function isDeclarationReadOnEventConfig(node) {
|
|
3925
|
-
return node.getName() ===
|
|
4289
|
+
return node.getName() === DECLARATION_PROPERTY_NAME3 && isToolkitEventConfig(node.getExpression().getType());
|
|
3926
4290
|
}
|
|
3927
4291
|
function isAssignmentOperator(kind) {
|
|
3928
|
-
return kind >=
|
|
4292
|
+
return kind >= import_ts_morph4.SyntaxKind.FirstAssignment && kind <= import_ts_morph4.SyntaxKind.LastAssignment;
|
|
3929
4293
|
}
|
|
3930
4294
|
function isWriteTarget(node) {
|
|
3931
4295
|
const parent = node.getParent();
|
|
3932
|
-
if (
|
|
4296
|
+
if (import_ts_morph4.Node.isDeleteExpression(parent)) {
|
|
3933
4297
|
return true;
|
|
3934
4298
|
}
|
|
3935
|
-
return
|
|
4299
|
+
return import_ts_morph4.Node.isBinaryExpression(parent) && parent.getLeft() === node && isAssignmentOperator(parent.getOperatorToken().getKind());
|
|
3936
4300
|
}
|
|
3937
4301
|
function location2(node) {
|
|
3938
|
-
const relPath =
|
|
4302
|
+
const relPath = import_path5.default.relative(
|
|
3939
4303
|
process.cwd(),
|
|
3940
4304
|
node.getSourceFile().getFilePath()
|
|
3941
4305
|
);
|
|
@@ -3943,86 +4307,40 @@ function location2(node) {
|
|
|
3943
4307
|
}
|
|
3944
4308
|
function warnDestructuredDeclarations(sourceFile) {
|
|
3945
4309
|
for (const pattern of sourceFile.getDescendantsOfKind(
|
|
3946
|
-
|
|
4310
|
+
import_ts_morph4.SyntaxKind.ObjectBindingPattern
|
|
3947
4311
|
)) {
|
|
3948
4312
|
const destructuresDeclaration = pattern.getElements().some(
|
|
3949
|
-
(element) => (element.getPropertyNameNode()?.getText() ?? element.getName()) ===
|
|
4313
|
+
(element) => (element.getPropertyNameNode()?.getText() ?? element.getName()) === DECLARATION_PROPERTY_NAME3
|
|
3950
4314
|
);
|
|
3951
4315
|
if (destructuresDeclaration && isToolkitEventConfig(pattern.getType())) {
|
|
3952
4316
|
console.warn(
|
|
3953
|
-
` [${location2(pattern)}] Destructures \`${
|
|
4317
|
+
` [${location2(pattern)}] Destructures \`${DECLARATION_PROPERTY_NAME3}\` from an EventConfig. Rewrite it to use \`${GET_DECLARATION_NAME}(config)\` by hand.`
|
|
3954
4318
|
);
|
|
3955
4319
|
}
|
|
3956
4320
|
}
|
|
3957
4321
|
}
|
|
3958
4322
|
function warnSpreadDeclarations(sourceFile) {
|
|
3959
4323
|
for (const literal of sourceFile.getDescendantsOfKind(
|
|
3960
|
-
|
|
4324
|
+
import_ts_morph4.SyntaxKind.ObjectLiteralExpression
|
|
3961
4325
|
)) {
|
|
3962
4326
|
const properties = literal.getProperties();
|
|
3963
4327
|
const spreadsEventConfig = properties.some(
|
|
3964
|
-
(property) =>
|
|
4328
|
+
(property) => import_ts_morph4.Node.isSpreadAssignment(property) && isToolkitEventConfig(property.getExpression().getType())
|
|
3965
4329
|
);
|
|
3966
4330
|
const setsDeclaration = properties.some(
|
|
3967
|
-
(property) => (
|
|
4331
|
+
(property) => (import_ts_morph4.Node.isPropertyAssignment(property) || import_ts_morph4.Node.isShorthandPropertyAssignment(property)) && property.getName() === DECLARATION_PROPERTY_NAME3
|
|
3968
4332
|
);
|
|
3969
4333
|
if (spreadsEventConfig && setsDeclaration) {
|
|
3970
4334
|
console.warn(
|
|
3971
|
-
` [${location2(literal)}] Spreads an EventConfig and sets \`${
|
|
4335
|
+
` [${location2(literal)}] Spreads an EventConfig and sets \`${DECLARATION_PROPERTY_NAME3}\` next to it. The spread config already has a \`${DECLARATION_PROPERTY_NAME3}\` on its DECLARE action, so replace that one by hand.`
|
|
3972
4336
|
);
|
|
3973
4337
|
}
|
|
3974
4338
|
}
|
|
3975
4339
|
}
|
|
3976
|
-
function findToolkitImport(sourceFile) {
|
|
3977
|
-
return sourceFile.getImportDeclaration(
|
|
3978
|
-
(declaration) => declaration.getModuleSpecifierValue() === TOOLKIT_EVENTS_MODULE && !declaration.isTypeOnly() && !declaration.getNamespaceImport()
|
|
3979
|
-
);
|
|
3980
|
-
}
|
|
3981
|
-
function findGetDeclarationName(sourceFile) {
|
|
3982
|
-
const imported = findToolkitImport(sourceFile)?.getNamedImports().find((namedImport) => namedImport.getName() === GET_DECLARATION_NAME);
|
|
3983
|
-
if (imported) {
|
|
3984
|
-
return imported.getAliasNode()?.getText() ?? GET_DECLARATION_NAME;
|
|
3985
|
-
}
|
|
3986
|
-
if (sourceFile.getLocal(GET_DECLARATION_NAME)) {
|
|
3987
|
-
return void 0;
|
|
3988
|
-
}
|
|
3989
|
-
return GET_DECLARATION_NAME;
|
|
3990
|
-
}
|
|
3991
|
-
function addGetDeclarationImport(sourceFile) {
|
|
3992
|
-
const toolkitImport = findToolkitImport(sourceFile);
|
|
3993
|
-
if (!toolkitImport) {
|
|
3994
|
-
const imports = sourceFile.getImportDeclarations();
|
|
3995
|
-
const lastImport = imports[imports.length - 1];
|
|
3996
|
-
sourceFile.insertStatements(
|
|
3997
|
-
lastImport ? lastImport.getChildIndex() + 1 : 0,
|
|
3998
|
-
`import { ${GET_DECLARATION_NAME} } from '${TOOLKIT_EVENTS_MODULE}'`
|
|
3999
|
-
);
|
|
4000
|
-
return;
|
|
4001
|
-
}
|
|
4002
|
-
const alreadyImported = toolkitImport.getNamedImports().some((namedImport) => namedImport.getName() === GET_DECLARATION_NAME);
|
|
4003
|
-
if (alreadyImported) {
|
|
4004
|
-
return;
|
|
4005
|
-
}
|
|
4006
|
-
const namedImports = toolkitImport.getNamedImports();
|
|
4007
|
-
if (toolkitImport.getDefaultImport() || namedImports.length === 0) {
|
|
4008
|
-
toolkitImport.addNamedImport(GET_DECLARATION_NAME);
|
|
4009
|
-
return;
|
|
4010
|
-
}
|
|
4011
|
-
const names = [
|
|
4012
|
-
...namedImports.map((namedImport) => namedImport.getText()),
|
|
4013
|
-
GET_DECLARATION_NAME
|
|
4014
|
-
];
|
|
4015
|
-
const specifiers = toolkitImport.getText().includes("\n") ? `{
|
|
4016
|
-
${names.join(",\n ")}
|
|
4017
|
-
}` : `{ ${names.join(", ")} }`;
|
|
4018
|
-
toolkitImport.replaceWithText(
|
|
4019
|
-
`import ${specifiers} from '${TOOLKIT_EVENTS_MODULE}'`
|
|
4020
|
-
);
|
|
4021
|
-
}
|
|
4022
4340
|
function rewriteDeclarationReads(sourceFile) {
|
|
4023
4341
|
warnDestructuredDeclarations(sourceFile);
|
|
4024
4342
|
warnSpreadDeclarations(sourceFile);
|
|
4025
|
-
const reads = sourceFile.getDescendantsOfKind(
|
|
4343
|
+
const reads = sourceFile.getDescendantsOfKind(import_ts_morph4.SyntaxKind.PropertyAccessExpression).filter(isDeclarationReadOnEventConfig).filter((node) => {
|
|
4026
4344
|
if (node.hasQuestionDotToken()) {
|
|
4027
4345
|
console.warn(
|
|
4028
4346
|
` [${location2(node)}] Skipped optional chain \`${node.getText()}\`. Rewrite it to use \`${GET_DECLARATION_NAME}()\` by hand.`
|
|
@@ -4031,7 +4349,7 @@ function rewriteDeclarationReads(sourceFile) {
|
|
|
4031
4349
|
}
|
|
4032
4350
|
if (isWriteTarget(node)) {
|
|
4033
4351
|
console.warn(
|
|
4034
|
-
` [${location2(node)}] Skipped write to \`${node.getText()}\`. Set \`${
|
|
4352
|
+
` [${location2(node)}] Skipped write to \`${node.getText()}\`. Set \`${DECLARATION_PROPERTY_NAME3}\` on the DECLARE action instead.`
|
|
4035
4353
|
);
|
|
4036
4354
|
return false;
|
|
4037
4355
|
}
|
|
@@ -4040,7 +4358,10 @@ function rewriteDeclarationReads(sourceFile) {
|
|
|
4040
4358
|
if (reads.length === 0) {
|
|
4041
4359
|
return 0;
|
|
4042
4360
|
}
|
|
4043
|
-
const getDeclarationName =
|
|
4361
|
+
const getDeclarationName = findToolkitImportName(
|
|
4362
|
+
sourceFile,
|
|
4363
|
+
GET_DECLARATION_NAME
|
|
4364
|
+
);
|
|
4044
4365
|
if (!getDeclarationName) {
|
|
4045
4366
|
console.warn(
|
|
4046
4367
|
` [${location2(reads[reads.length - 1])}] Skipped ${reads.length} read(s): the file already declares its own \`${GET_DECLARATION_NAME}\`. Rewrite them to use the toolkit's \`${GET_DECLARATION_NAME}()\` by hand.`
|
|
@@ -4055,15 +4376,15 @@ function rewriteDeclarationReads(sourceFile) {
|
|
|
4055
4376
|
`${getDeclarationName}(${read.getExpression().getText()})`
|
|
4056
4377
|
);
|
|
4057
4378
|
}
|
|
4058
|
-
|
|
4379
|
+
addToolkitImport(sourceFile, GET_DECLARATION_NAME);
|
|
4059
4380
|
return reads.length;
|
|
4060
4381
|
}
|
|
4061
|
-
async function
|
|
4062
|
-
const srcDir =
|
|
4382
|
+
async function main4() {
|
|
4383
|
+
const srcDir = import_path5.default.join(process.cwd(), "src");
|
|
4063
4384
|
console.log(`Scanning for EventConfig declaration reads in: ${srcDir}
|
|
4064
4385
|
`);
|
|
4065
|
-
const project = new
|
|
4066
|
-
tsConfigFilePath:
|
|
4386
|
+
const project = new import_ts_morph4.Project({
|
|
4387
|
+
tsConfigFilePath: import_path5.default.resolve(srcDir, "../tsconfig.json"),
|
|
4067
4388
|
skipAddingFilesFromTsConfig: false
|
|
4068
4389
|
});
|
|
4069
4390
|
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
@@ -4090,7 +4411,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
4090
4411
|
for (const sourceFile of modifiedFiles) {
|
|
4091
4412
|
await sourceFile.save();
|
|
4092
4413
|
console.log(
|
|
4093
|
-
` Saved: ${
|
|
4414
|
+
` Saved: ${import_path5.default.relative(process.cwd(), sourceFile.getFilePath())}`
|
|
4094
4415
|
);
|
|
4095
4416
|
}
|
|
4096
4417
|
console.log(
|
|
@@ -4099,13 +4420,269 @@ Done. Rewrote ${totalChanges} declaration read(s) across ${modifiedFiles.length}
|
|
|
4099
4420
|
);
|
|
4100
4421
|
}
|
|
4101
4422
|
|
|
4423
|
+
// src/migrations/resolve-versioned-event-config.ts
|
|
4424
|
+
var import_ts_morph5 = require("ts-morph");
|
|
4425
|
+
var import_path6 = __toESM(require("path"));
|
|
4426
|
+
var EVENT_CONFIG_TYPE_NAME2 = "EventConfig";
|
|
4427
|
+
var VERSIONED_EVENT_CONFIG_TYPE_NAME = "VersionedEventConfig";
|
|
4428
|
+
var RESOLVE_EVENT_CONFIG_NAME = "resolveEventConfig";
|
|
4429
|
+
var TOOLKIT_EVENTS_MODULE2 = "@opencrvs/toolkit/events";
|
|
4430
|
+
function isToolkitType(type, name) {
|
|
4431
|
+
const nonNullableType = type.getNonNullableType();
|
|
4432
|
+
const symbol = nonNullableType.getAliasSymbol() ?? nonNullableType.getSymbol();
|
|
4433
|
+
if (symbol?.getName() !== name) {
|
|
4434
|
+
return false;
|
|
4435
|
+
}
|
|
4436
|
+
return symbol.getDeclarations().some((declaration) => declaration.getSourceFile().isDeclarationFile());
|
|
4437
|
+
}
|
|
4438
|
+
function isVersionedEventConfig(type) {
|
|
4439
|
+
return isToolkitType(type, VERSIONED_EVENT_CONFIG_TYPE_NAME);
|
|
4440
|
+
}
|
|
4441
|
+
function isEventConfig(type) {
|
|
4442
|
+
return isToolkitType(type, EVENT_CONFIG_TYPE_NAME2);
|
|
4443
|
+
}
|
|
4444
|
+
function isArrayOf(type, isElement) {
|
|
4445
|
+
const elementType = type.getNonNullableType().getArrayElementType();
|
|
4446
|
+
return elementType !== void 0 && isElement(elementType);
|
|
4447
|
+
}
|
|
4448
|
+
function isVersionedField(type, name) {
|
|
4449
|
+
return type.getNonNullableType().getProperty(name) !== void 0;
|
|
4450
|
+
}
|
|
4451
|
+
function isAssignmentOperator2(kind) {
|
|
4452
|
+
return kind >= import_ts_morph5.SyntaxKind.FirstAssignment && kind <= import_ts_morph5.SyntaxKind.LastAssignment;
|
|
4453
|
+
}
|
|
4454
|
+
function isWriteTarget2(node) {
|
|
4455
|
+
const parent = node.getParent();
|
|
4456
|
+
if (import_ts_morph5.Node.isDeleteExpression(parent)) {
|
|
4457
|
+
return true;
|
|
4458
|
+
}
|
|
4459
|
+
return import_ts_morph5.Node.isBinaryExpression(parent) && parent.getLeft() === node && isAssignmentOperator2(parent.getOperatorToken().getKind());
|
|
4460
|
+
}
|
|
4461
|
+
function location3(node) {
|
|
4462
|
+
const relPath = import_path6.default.relative(
|
|
4463
|
+
process.cwd(),
|
|
4464
|
+
node.getSourceFile().getFilePath()
|
|
4465
|
+
);
|
|
4466
|
+
return `${relPath}:${node.getStartLineNumber()}`;
|
|
4467
|
+
}
|
|
4468
|
+
function warnDestructuredVersionFields(sourceFile) {
|
|
4469
|
+
for (const pattern of sourceFile.getDescendantsOfKind(
|
|
4470
|
+
import_ts_morph5.SyntaxKind.ObjectBindingPattern
|
|
4471
|
+
)) {
|
|
4472
|
+
const type = pattern.getType();
|
|
4473
|
+
if (!isVersionedEventConfig(type)) {
|
|
4474
|
+
continue;
|
|
4475
|
+
}
|
|
4476
|
+
const destructuresVersionField = pattern.getElements().some(
|
|
4477
|
+
(element) => !element.getDotDotDotToken() && !isVersionedField(
|
|
4478
|
+
type,
|
|
4479
|
+
element.getPropertyNameNode()?.getText() ?? element.getName()
|
|
4480
|
+
)
|
|
4481
|
+
);
|
|
4482
|
+
if (destructuresVersionField) {
|
|
4483
|
+
console.warn(
|
|
4484
|
+
` [${location3(pattern)}] Destructures a field of a version from a VersionedEventConfig. Destructure it from \`${RESOLVE_EVENT_CONFIG_NAME}(config)\` by hand.`
|
|
4485
|
+
);
|
|
4486
|
+
}
|
|
4487
|
+
}
|
|
4488
|
+
}
|
|
4489
|
+
function findVersionFieldReads(sourceFile) {
|
|
4490
|
+
return sourceFile.getDescendantsOfKind(import_ts_morph5.SyntaxKind.PropertyAccessExpression).filter((node) => {
|
|
4491
|
+
const type = node.getExpression().getType();
|
|
4492
|
+
return isVersionedEventConfig(type) && !isVersionedField(type, node.getName());
|
|
4493
|
+
}).filter((node) => {
|
|
4494
|
+
if (node.hasQuestionDotToken()) {
|
|
4495
|
+
console.warn(
|
|
4496
|
+
` [${location3(node)}] Skipped optional chain \`${node.getText()}\`. Rewrite it to use \`${RESOLVE_EVENT_CONFIG_NAME}()\` by hand.`
|
|
4497
|
+
);
|
|
4498
|
+
return false;
|
|
4499
|
+
}
|
|
4500
|
+
if (isWriteTarget2(node)) {
|
|
4501
|
+
console.warn(
|
|
4502
|
+
` [${location3(node)}] Skipped write to \`${node.getText()}\`. Set it in the version passed to \`defineConfig\` instead.`
|
|
4503
|
+
);
|
|
4504
|
+
return false;
|
|
4505
|
+
}
|
|
4506
|
+
return true;
|
|
4507
|
+
});
|
|
4508
|
+
}
|
|
4509
|
+
function isHandedOver(node) {
|
|
4510
|
+
const parent = node.getParent();
|
|
4511
|
+
if (import_ts_morph5.Node.isCallExpression(parent) || import_ts_morph5.Node.isNewExpression(parent)) {
|
|
4512
|
+
return parent.getArguments().includes(node);
|
|
4513
|
+
}
|
|
4514
|
+
return (import_ts_morph5.Node.isVariableDeclaration(parent) || import_ts_morph5.Node.isPropertyAssignment(parent)) && parent.getInitializer() === node || import_ts_morph5.Node.isReturnStatement(parent);
|
|
4515
|
+
}
|
|
4516
|
+
function findValuesExpectingEventConfig(sourceFile) {
|
|
4517
|
+
return sourceFile.getDescendants().filter((node) => import_ts_morph5.Node.isExpression(node)).filter(isHandedOver).map((node) => {
|
|
4518
|
+
const type = node.getType();
|
|
4519
|
+
const expectedType = node.getContextualType();
|
|
4520
|
+
if (!expectedType) {
|
|
4521
|
+
return void 0;
|
|
4522
|
+
}
|
|
4523
|
+
if (isVersionedEventConfig(type) && isEventConfig(expectedType)) {
|
|
4524
|
+
return { node, isArray: false };
|
|
4525
|
+
}
|
|
4526
|
+
if (isArrayOf(type, isVersionedEventConfig) && isArrayOf(expectedType, isEventConfig)) {
|
|
4527
|
+
return { node, isArray: true };
|
|
4528
|
+
}
|
|
4529
|
+
return void 0;
|
|
4530
|
+
}).filter((value) => value !== void 0).filter(({ node }) => {
|
|
4531
|
+
if (node.getType().isNullable()) {
|
|
4532
|
+
console.warn(
|
|
4533
|
+
` [${location3(node)}] Skipped \`${node.getText()}\`, which may be undefined where an EventConfig is expected. Narrow it and pass \`${RESOLVE_EVENT_CONFIG_NAME}(...)\` by hand.`
|
|
4534
|
+
);
|
|
4535
|
+
return false;
|
|
4536
|
+
}
|
|
4537
|
+
return true;
|
|
4538
|
+
});
|
|
4539
|
+
}
|
|
4540
|
+
function findToolkitImport2(sourceFile) {
|
|
4541
|
+
return sourceFile.getImportDeclaration(
|
|
4542
|
+
(declaration) => declaration.getModuleSpecifierValue() === TOOLKIT_EVENTS_MODULE2 && !declaration.isTypeOnly() && !declaration.getNamespaceImport()
|
|
4543
|
+
);
|
|
4544
|
+
}
|
|
4545
|
+
function findResolveEventConfigName(sourceFile) {
|
|
4546
|
+
const imported = findToolkitImport2(sourceFile)?.getNamedImports().find((namedImport) => namedImport.getName() === RESOLVE_EVENT_CONFIG_NAME);
|
|
4547
|
+
if (imported) {
|
|
4548
|
+
return imported.getAliasNode()?.getText() ?? RESOLVE_EVENT_CONFIG_NAME;
|
|
4549
|
+
}
|
|
4550
|
+
if (sourceFile.getLocal(RESOLVE_EVENT_CONFIG_NAME)) {
|
|
4551
|
+
return void 0;
|
|
4552
|
+
}
|
|
4553
|
+
return RESOLVE_EVENT_CONFIG_NAME;
|
|
4554
|
+
}
|
|
4555
|
+
function addResolveEventConfigImport(sourceFile) {
|
|
4556
|
+
const toolkitImport = findToolkitImport2(sourceFile);
|
|
4557
|
+
if (!toolkitImport) {
|
|
4558
|
+
const imports = sourceFile.getImportDeclarations();
|
|
4559
|
+
const lastImport = imports[imports.length - 1];
|
|
4560
|
+
sourceFile.insertStatements(
|
|
4561
|
+
lastImport ? lastImport.getChildIndex() + 1 : 0,
|
|
4562
|
+
`import { ${RESOLVE_EVENT_CONFIG_NAME} } from '${TOOLKIT_EVENTS_MODULE2}'`
|
|
4563
|
+
);
|
|
4564
|
+
return;
|
|
4565
|
+
}
|
|
4566
|
+
const alreadyImported = toolkitImport.getNamedImports().some((namedImport) => namedImport.getName() === RESOLVE_EVENT_CONFIG_NAME);
|
|
4567
|
+
if (alreadyImported) {
|
|
4568
|
+
return;
|
|
4569
|
+
}
|
|
4570
|
+
const namedImports = toolkitImport.getNamedImports();
|
|
4571
|
+
if (toolkitImport.getDefaultImport() || namedImports.length === 0) {
|
|
4572
|
+
toolkitImport.addNamedImport(RESOLVE_EVENT_CONFIG_NAME);
|
|
4573
|
+
return;
|
|
4574
|
+
}
|
|
4575
|
+
const names = [
|
|
4576
|
+
...namedImports.map((namedImport) => namedImport.getText()),
|
|
4577
|
+
RESOLVE_EVENT_CONFIG_NAME
|
|
4578
|
+
];
|
|
4579
|
+
const specifiers = toolkitImport.getText().includes("\n") ? `{
|
|
4580
|
+
${names.join(",\n ")}
|
|
4581
|
+
}` : `{ ${names.join(", ")} }`;
|
|
4582
|
+
toolkitImport.replaceWithText(
|
|
4583
|
+
`import ${specifiers} from '${TOOLKIT_EVENTS_MODULE2}'`
|
|
4584
|
+
);
|
|
4585
|
+
}
|
|
4586
|
+
function withToolkitEventsAt(compilerOptions, toolkitEventsPath) {
|
|
4587
|
+
return {
|
|
4588
|
+
...compilerOptions,
|
|
4589
|
+
paths: {
|
|
4590
|
+
...compilerOptions.paths,
|
|
4591
|
+
[TOOLKIT_EVENTS_MODULE2]: [toolkitEventsPath]
|
|
4592
|
+
}
|
|
4593
|
+
};
|
|
4594
|
+
}
|
|
4595
|
+
function rewriteVersionedEventConfigUses(sourceFile) {
|
|
4596
|
+
warnDestructuredVersionFields(sourceFile);
|
|
4597
|
+
const uses = [
|
|
4598
|
+
...findVersionFieldReads(sourceFile).map((node) => ({
|
|
4599
|
+
node,
|
|
4600
|
+
rewrite: (name) => `${name}(${node.getExpression().getText()}).${node.getName()}`
|
|
4601
|
+
})),
|
|
4602
|
+
...findValuesExpectingEventConfig(sourceFile).map(({ node, isArray }) => ({
|
|
4603
|
+
node,
|
|
4604
|
+
rewrite: (name) => isArray ? `${node.getText()}.map(${name})` : `${name}(${node.getText()})`
|
|
4605
|
+
}))
|
|
4606
|
+
].sort(
|
|
4607
|
+
(a, b) => b.node.getStart() - a.node.getStart() || a.node.getEnd() - b.node.getEnd()
|
|
4608
|
+
);
|
|
4609
|
+
if (uses.length === 0) {
|
|
4610
|
+
return 0;
|
|
4611
|
+
}
|
|
4612
|
+
const resolveEventConfigName = findResolveEventConfigName(sourceFile);
|
|
4613
|
+
if (!resolveEventConfigName) {
|
|
4614
|
+
console.warn(
|
|
4615
|
+
` [${location3(uses[uses.length - 1].node)}] Skipped ${uses.length} use(s): the file already declares its own \`${RESOLVE_EVENT_CONFIG_NAME}\`. Rewrite them to use the toolkit's \`${RESOLVE_EVENT_CONFIG_NAME}()\` by hand.`
|
|
4616
|
+
);
|
|
4617
|
+
return 0;
|
|
4618
|
+
}
|
|
4619
|
+
for (const { node, rewrite } of uses) {
|
|
4620
|
+
const before = node.getText();
|
|
4621
|
+
const after = rewrite(resolveEventConfigName);
|
|
4622
|
+
console.log(` [${location3(node)}] ${before} -> ${after}`);
|
|
4623
|
+
node.replaceWithText(after);
|
|
4624
|
+
}
|
|
4625
|
+
addResolveEventConfigImport(sourceFile);
|
|
4626
|
+
return uses.length;
|
|
4627
|
+
}
|
|
4628
|
+
async function main5() {
|
|
4629
|
+
const srcDir = import_path6.default.join(process.cwd(), "src");
|
|
4630
|
+
console.log(
|
|
4631
|
+
`Scanning for VersionedEventConfig used as an EventConfig in: ${srcDir}
|
|
4632
|
+
`
|
|
4633
|
+
);
|
|
4634
|
+
const tsConfigFilePath = import_path6.default.resolve(srcDir, "../tsconfig.json");
|
|
4635
|
+
const project = new import_ts_morph5.Project({
|
|
4636
|
+
tsConfigFilePath,
|
|
4637
|
+
skipAddingFilesFromTsConfig: false,
|
|
4638
|
+
// The events module of this toolkit, next to the migrations in `dist`
|
|
4639
|
+
compilerOptions: withToolkitEventsAt(
|
|
4640
|
+
(0, import_ts_morph5.getCompilerOptionsFromTsConfig)(tsConfigFilePath).options,
|
|
4641
|
+
import_path6.default.resolve(__dirname, "../events")
|
|
4642
|
+
)
|
|
4643
|
+
});
|
|
4644
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
4645
|
+
const fp = sf.getFilePath();
|
|
4646
|
+
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
4647
|
+
});
|
|
4648
|
+
console.log(`Found ${sourceFiles.length} source file(s) to analyse.
|
|
4649
|
+
`);
|
|
4650
|
+
let totalChanges = 0;
|
|
4651
|
+
const modifiedFiles = [];
|
|
4652
|
+
for (const sourceFile of sourceFiles) {
|
|
4653
|
+
const changes = rewriteVersionedEventConfigUses(sourceFile);
|
|
4654
|
+
if (changes > 0) {
|
|
4655
|
+
totalChanges += changes;
|
|
4656
|
+
modifiedFiles.push(sourceFile);
|
|
4657
|
+
}
|
|
4658
|
+
}
|
|
4659
|
+
if (modifiedFiles.length === 0) {
|
|
4660
|
+
console.log(
|
|
4661
|
+
"No VersionedEventConfig used as an EventConfig found. Nothing to do."
|
|
4662
|
+
);
|
|
4663
|
+
return;
|
|
4664
|
+
}
|
|
4665
|
+
console.log(`
|
|
4666
|
+
Saving ${modifiedFiles.length} modified file(s)...`);
|
|
4667
|
+
for (const sourceFile of modifiedFiles) {
|
|
4668
|
+
await sourceFile.save();
|
|
4669
|
+
console.log(
|
|
4670
|
+
` Saved: ${import_path6.default.relative(process.cwd(), sourceFile.getFilePath())}`
|
|
4671
|
+
);
|
|
4672
|
+
}
|
|
4673
|
+
console.log(
|
|
4674
|
+
`
|
|
4675
|
+
Done. Rewrote ${totalChanges} use(s) across ${modifiedFiles.length} file(s).`
|
|
4676
|
+
);
|
|
4677
|
+
}
|
|
4678
|
+
|
|
4102
4679
|
// src/migrations/persistent/update-toolkit-dependency.ts
|
|
4103
4680
|
var import_fs3 = __toESM(require("fs"));
|
|
4104
|
-
var
|
|
4681
|
+
var import_path8 = __toESM(require("path"));
|
|
4105
4682
|
|
|
4106
4683
|
// src/migrations/persistent/check-upgrade-path.ts
|
|
4107
4684
|
var import_fs2 = __toESM(require("fs"));
|
|
4108
|
-
var
|
|
4685
|
+
var import_path7 = __toESM(require("path"));
|
|
4109
4686
|
var TOOLKIT_PACKAGE_NAME = "@opencrvs/toolkit";
|
|
4110
4687
|
function findMajorMinor(version) {
|
|
4111
4688
|
const match = /(\d+)\.(\d+)/.exec(version);
|
|
@@ -4117,7 +4694,7 @@ function format({ major, minor }) {
|
|
|
4117
4694
|
function findCountryConfigToolkitVersion(cwd) {
|
|
4118
4695
|
try {
|
|
4119
4696
|
const packageJson = JSON.parse(
|
|
4120
|
-
import_fs2.default.readFileSync(
|
|
4697
|
+
import_fs2.default.readFileSync(import_path7.default.join(cwd, "package.json"), "utf-8")
|
|
4121
4698
|
);
|
|
4122
4699
|
return packageJson.dependencies?.[TOOLKIT_PACKAGE_NAME] ?? packageJson.devDependencies?.[TOOLKIT_PACKAGE_NAME];
|
|
4123
4700
|
} catch {
|
|
@@ -4172,8 +4749,8 @@ function updateToolkitDependency(packageJson, toolkitVersion) {
|
|
|
4172
4749
|
);
|
|
4173
4750
|
return updated === packageJson ? void 0 : updated;
|
|
4174
4751
|
}
|
|
4175
|
-
async function
|
|
4176
|
-
const packageJsonPath =
|
|
4752
|
+
async function main6(toolkitVersion) {
|
|
4753
|
+
const packageJsonPath = import_path8.default.join(process.cwd(), "package.json");
|
|
4177
4754
|
if (!import_fs3.default.existsSync(packageJsonPath)) {
|
|
4178
4755
|
console.log(`No package.json found. Skipping ${TOOLKIT_PACKAGE_NAME}.`);
|
|
4179
4756
|
return;
|
|
@@ -4195,8 +4772,8 @@ async function main4(toolkitVersion) {
|
|
|
4195
4772
|
}
|
|
4196
4773
|
|
|
4197
4774
|
// src/migrations/replace-incomplete-flag.ts
|
|
4198
|
-
var
|
|
4199
|
-
var
|
|
4775
|
+
var import_ts_morph6 = require("ts-morph");
|
|
4776
|
+
var import_path9 = __toESM(require("path"));
|
|
4200
4777
|
var INCOMPLETE = "InherentFlags.INCOMPLETE";
|
|
4201
4778
|
var NOTIFIED_STATUS = `{ type: 'exact', term: EventStatus.enum.NOTIFIED }`;
|
|
4202
4779
|
function ensureEventStatusImport(sourceFile) {
|
|
@@ -4210,21 +4787,21 @@ function ensureEventStatusImport(sourceFile) {
|
|
|
4210
4787
|
}
|
|
4211
4788
|
function replaceIncompleteFlag(sourceFile) {
|
|
4212
4789
|
let changed = false;
|
|
4213
|
-
const anyOfIncomplete = sourceFile.getDescendantsOfKind(
|
|
4790
|
+
const anyOfIncomplete = sourceFile.getDescendantsOfKind(import_ts_morph6.SyntaxKind.PropertyAccessExpression).filter((node) => node.getText() === INCOMPLETE).map((node) => node.getParent()).filter(import_ts_morph6.Node.isArrayLiteralExpression).filter((array2) => {
|
|
4214
4791
|
const anyOf = array2.getParent();
|
|
4215
4792
|
const flags = anyOf?.getParent()?.getParent();
|
|
4216
|
-
return
|
|
4793
|
+
return import_ts_morph6.Node.isPropertyAssignment(anyOf) && anyOf.getName() === "anyOf" && import_ts_morph6.Node.isPropertyAssignment(flags) && flags.getName() === "flags";
|
|
4217
4794
|
});
|
|
4218
4795
|
for (const array2 of anyOfIncomplete) {
|
|
4219
|
-
const anyOf = array2.getParentIfKindOrThrow(
|
|
4796
|
+
const anyOf = array2.getParentIfKindOrThrow(import_ts_morph6.SyntaxKind.PropertyAssignment);
|
|
4220
4797
|
const flagsObject = anyOf.getParentIfKindOrThrow(
|
|
4221
|
-
|
|
4798
|
+
import_ts_morph6.SyntaxKind.ObjectLiteralExpression
|
|
4222
4799
|
);
|
|
4223
4800
|
const flags = flagsObject.getParentIfKindOrThrow(
|
|
4224
|
-
|
|
4801
|
+
import_ts_morph6.SyntaxKind.PropertyAssignment
|
|
4225
4802
|
);
|
|
4226
4803
|
const query = flags.getParentIfKindOrThrow(
|
|
4227
|
-
|
|
4804
|
+
import_ts_morph6.SyntaxKind.ObjectLiteralExpression
|
|
4228
4805
|
);
|
|
4229
4806
|
array2.getElements().filter((element) => element.getText() === INCOMPLETE).forEach((element) => array2.removeElement(element));
|
|
4230
4807
|
if (array2.getElements().length === 0) anyOf.remove();
|
|
@@ -4238,16 +4815,16 @@ function replaceIncompleteFlag(sourceFile) {
|
|
|
4238
4815
|
changed = true;
|
|
4239
4816
|
}
|
|
4240
4817
|
if (changed) ensureEventStatusImport(sourceFile);
|
|
4241
|
-
const remaining = sourceFile.getDescendantsOfKind(
|
|
4818
|
+
const remaining = sourceFile.getDescendantsOfKind(import_ts_morph6.SyntaxKind.PropertyAccessExpression).filter((node) => node.getText() === INCOMPLETE).map((node) => node.getStartLineNumber());
|
|
4242
4819
|
return { changed, remaining };
|
|
4243
4820
|
}
|
|
4244
|
-
async function
|
|
4245
|
-
const project = new
|
|
4246
|
-
tsConfigFilePath:
|
|
4821
|
+
async function main7() {
|
|
4822
|
+
const project = new import_ts_morph6.Project({
|
|
4823
|
+
tsConfigFilePath: import_path9.default.join(process.cwd(), "tsconfig.json")
|
|
4247
4824
|
});
|
|
4248
4825
|
const sourceFiles = project.getSourceFiles().filter((sf) => !sf.getFilePath().includes("/node_modules/"));
|
|
4249
4826
|
for (const sourceFile of sourceFiles) {
|
|
4250
|
-
const relPath =
|
|
4827
|
+
const relPath = import_path9.default.relative(process.cwd(), sourceFile.getFilePath());
|
|
4251
4828
|
const { changed, remaining } = replaceIncompleteFlag(sourceFile);
|
|
4252
4829
|
if (changed) {
|
|
4253
4830
|
await sourceFile.save();
|
|
@@ -4268,14 +4845,16 @@ async function runUpgrade(toolkitVersion) {
|
|
|
4268
4845
|
const [major, minor] = toolkitVersion.split(".");
|
|
4269
4846
|
await main2();
|
|
4270
4847
|
await main3();
|
|
4271
|
-
await main(`${major}.${minor}`);
|
|
4272
4848
|
await main5();
|
|
4273
|
-
await main4(
|
|
4849
|
+
await main4();
|
|
4850
|
+
await main(`${major}.${minor}`);
|
|
4851
|
+
await main7();
|
|
4852
|
+
await main6(toolkitVersion);
|
|
4274
4853
|
}
|
|
4275
4854
|
|
|
4276
4855
|
// src/environment/index.ts
|
|
4277
4856
|
var import_fs8 = require("fs");
|
|
4278
|
-
var
|
|
4857
|
+
var import_path14 = require("path");
|
|
4279
4858
|
init_paths();
|
|
4280
4859
|
var REQUIRED_REPOSITORY_DIRECTORIES = [
|
|
4281
4860
|
".github/workflows",
|
|
@@ -4286,7 +4865,7 @@ function validateRepositoryStructure(repositoryRoot = process.cwd()) {
|
|
|
4286
4865
|
const missingDirectories = REQUIRED_REPOSITORY_DIRECTORIES.filter(
|
|
4287
4866
|
(directory) => {
|
|
4288
4867
|
try {
|
|
4289
|
-
return !(0, import_fs8.statSync)((0,
|
|
4868
|
+
return !(0, import_fs8.statSync)((0, import_path14.resolve)(repositoryRoot, directory)).isDirectory();
|
|
4290
4869
|
} catch {
|
|
4291
4870
|
return true;
|
|
4292
4871
|
}
|
|
@@ -4409,26 +4988,19 @@ async function requestStatus(url, method) {
|
|
|
4409
4988
|
return "error";
|
|
4410
4989
|
}
|
|
4411
4990
|
}
|
|
4412
|
-
|
|
4413
|
-
|
|
4414
|
-
|
|
4415
|
-
|
|
4416
|
-
|
|
4417
|
-
|
|
4418
|
-
|
|
4419
|
-
|
|
4420
|
-
const
|
|
4421
|
-
|
|
4422
|
-
|
|
4423
|
-
|
|
4424
|
-
|
|
4425
|
-
}
|
|
4426
|
-
const type = action.type;
|
|
4427
|
-
return typeof type === "string" ? type : null;
|
|
4428
|
-
}).filter((type) => type !== null)
|
|
4429
|
-
)
|
|
4430
|
-
) : [];
|
|
4431
|
-
return { id: record2.id, actions };
|
|
4991
|
+
var ServedEventConfigVersion = z.object({
|
|
4992
|
+
actions: z.array(z.object({ type: z.string() }))
|
|
4993
|
+
});
|
|
4994
|
+
var ServedEventConfig = z.union([
|
|
4995
|
+
z.object({ id: z.string(), versions: z.array(ServedEventConfigVersion) }),
|
|
4996
|
+
ServedEventConfigVersion.extend({ id: z.string() })
|
|
4997
|
+
]);
|
|
4998
|
+
function toEventTriggerConfig(config) {
|
|
4999
|
+
const versions = "versions" in config ? config.versions : [config];
|
|
5000
|
+
const actions = versions.flatMap(
|
|
5001
|
+
(version) => version.actions.map(({ type }) => type)
|
|
5002
|
+
);
|
|
5003
|
+
return { id: config.id, actions: Array.from(new Set(actions)) };
|
|
4432
5004
|
}
|
|
4433
5005
|
async function fetchEventConfigs(baseUrl) {
|
|
4434
5006
|
try {
|
|
@@ -4438,11 +5010,8 @@ async function fetchEventConfigs(baseUrl) {
|
|
|
4438
5010
|
if (!response.ok) {
|
|
4439
5011
|
return null;
|
|
4440
5012
|
}
|
|
4441
|
-
const
|
|
4442
|
-
|
|
4443
|
-
return null;
|
|
4444
|
-
}
|
|
4445
|
-
return body.map(toEventTriggerConfig).filter((config) => config !== null);
|
|
5013
|
+
const parsed = z.array(ServedEventConfig).safeParse(await response.json());
|
|
5014
|
+
return parsed.success ? parsed.data.map(toEventTriggerConfig) : null;
|
|
4446
5015
|
} catch {
|
|
4447
5016
|
return null;
|
|
4448
5017
|
}
|
|
@@ -4613,8 +5182,8 @@ async function runVerifyEndpoints(target = DEFAULT_TARGET_URL) {
|
|
|
4613
5182
|
console.log(line(ok, endpointLabel(check), detail));
|
|
4614
5183
|
}
|
|
4615
5184
|
{
|
|
4616
|
-
const
|
|
4617
|
-
const status = await requestStatus(`${baseUrl}${
|
|
5185
|
+
const path15 = `/fonts/${PROBE_SEGMENT}.ttf`;
|
|
5186
|
+
const status = await requestStatus(`${baseUrl}${path15}`, "GET");
|
|
4618
5187
|
const ok = status === 200 || status === 404;
|
|
4619
5188
|
if (!ok) {
|
|
4620
5189
|
failures++;
|
|
@@ -4629,7 +5198,7 @@ async function runVerifyEndpoints(target = DEFAULT_TARGET_URL) {
|
|
|
4629
5198
|
} else {
|
|
4630
5199
|
detail = `${describeStatus(status)} \u2014 unexpected`;
|
|
4631
5200
|
}
|
|
4632
|
-
console.log(line(ok, `GET /fonts/{filename}${(0, import_colors.dim)(` \u2192 ${
|
|
5201
|
+
console.log(line(ok, `GET /fonts/{filename}${(0, import_colors.dim)(` \u2192 ${path15}`)}`, detail));
|
|
4633
5202
|
}
|
|
4634
5203
|
console.log();
|
|
4635
5204
|
console.log((0, import_colors.bold)("Secured endpoints (must be absent or require auth):"));
|
|
@@ -4682,13 +5251,13 @@ async function runVerifyEndpoints(target = DEFAULT_TARGET_URL) {
|
|
|
4682
5251
|
line(true, pattern, `${actions.length} action(s) \u2014 all require auth`)
|
|
4683
5252
|
);
|
|
4684
5253
|
} else {
|
|
4685
|
-
for (const
|
|
5254
|
+
for (const failure2 of failed) {
|
|
4686
5255
|
failures++;
|
|
4687
5256
|
console.log(
|
|
4688
5257
|
line(
|
|
4689
5258
|
false,
|
|
4690
|
-
`POST /trigger/events/${event.id}/actions/${
|
|
4691
|
-
securedDetail(
|
|
5259
|
+
`POST /trigger/events/${event.id}/actions/${failure2.action}`,
|
|
5260
|
+
securedDetail(failure2.status)
|
|
4692
5261
|
)
|
|
4693
5262
|
);
|
|
4694
5263
|
}
|
|
@@ -4769,7 +5338,7 @@ Run it without changing the dependency first, e.g.
|
|
|
4769
5338
|
Options:
|
|
4770
5339
|
-h, --help Show this message.
|
|
4771
5340
|
`.trim();
|
|
4772
|
-
function
|
|
5341
|
+
function main8() {
|
|
4773
5342
|
const command = args[0];
|
|
4774
5343
|
if (!command || command === "--help" || command === "-h") {
|
|
4775
5344
|
console.log(USAGE);
|
|
@@ -4841,7 +5410,7 @@ async function runEnvironmentCommand(operation, command) {
|
|
|
4841
5410
|
}
|
|
4842
5411
|
function readToolkitVersion() {
|
|
4843
5412
|
const packageJson = JSON.parse(
|
|
4844
|
-
import_fs9.default.readFileSync(
|
|
5413
|
+
import_fs9.default.readFileSync(import_path15.default.join(__dirname, "..", "package.json"), "utf-8")
|
|
4845
5414
|
);
|
|
4846
5415
|
return packageJson.version;
|
|
4847
5416
|
}
|
|
@@ -4905,4 +5474,4 @@ async function handleVerifyEndpoints() {
|
|
|
4905
5474
|
process.exit(1);
|
|
4906
5475
|
}
|
|
4907
5476
|
}
|
|
4908
|
-
|
|
5477
|
+
main8();
|