@opencrvs/toolkit 2.0.0-rc.b63fd2e → 2.0.0-rc.bee2b7b
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/application-config/index.js +36 -7
- package/dist/cli.js +178 -1390
- package/dist/commons/events/locations.d.ts +17 -1
- package/dist/conditionals/index.js +36 -7
- package/dist/events/index.js +74 -7
- package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts.map +1 -1
- package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.js +4 -3
- package/dist/migrations/v2.0/checkout-upstream-files.d.ts +0 -19
- package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +1 -1
- package/dist/migrations/v2.0/checkout-upstream-files.js +13 -17
- package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts.map +1 -1
- package/dist/migrations/v2.0/convert-config-files-to-ts.js +5 -4
- package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts.map +1 -1
- package/dist/migrations/v2.0/convert-paragraph-to-heading.js +5 -4
- package/dist/migrations/v2.0/create-events-index.d.ts.map +1 -1
- package/dist/migrations/v2.0/create-events-index.js +2 -1
- package/dist/migrations/v2.0/index.d.ts +4 -8
- package/dist/migrations/v2.0/index.d.ts.map +1 -1
- package/dist/migrations/v2.0/index.js +175 -1358
- package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts.map +1 -1
- package/dist/migrations/v2.0/make-built-in-validate-actions-custom.js +6 -5
- package/dist/migrations/v2.0/migrate-scopes.d.ts.map +1 -1
- package/dist/migrations/v2.0/migrate-scopes.js +7 -6
- package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts.map +1 -1
- package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.js +4 -3
- package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts.map +1 -1
- package/dist/migrations/v2.0/migrate-workqueue-configs.js +4 -3
- package/dist/migrations/v2.0/remove-delete-actions.d.ts.map +1 -1
- package/dist/migrations/v2.0/remove-delete-actions.js +4 -3
- package/dist/migrations/v2.0/remove-demo-scope.d.ts.map +1 -1
- package/dist/migrations/v2.0/remove-demo-scope.js +3 -2
- package/dist/migrations/v2.0/remove-deprecated-imports.d.ts.map +1 -1
- package/dist/migrations/v2.0/remove-deprecated-imports.js +4 -3
- package/dist/migrations/v2.0/remove-hearth-migrations.d.ts.map +1 -1
- package/dist/migrations/v2.0/remove-hearth-migrations.js +2 -1
- package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts.map +1 -1
- package/dist/migrations/v2.0/remove-pending-certification-flag.js +4 -3
- package/dist/migrations/v2.0/remove-review-from-register-action.d.ts.map +1 -1
- package/dist/migrations/v2.0/remove-review-from-register-action.js +4 -3
- package/dist/migrations/v2.0/rename-api-paths.d.ts.map +1 -1
- package/dist/migrations/v2.0/rename-api-paths.js +4 -3
- package/dist/migrations/v2.0/rename-location-parent-id.d.ts.map +1 -1
- package/dist/migrations/v2.0/rename-location-parent-id.js +4 -3
- package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts.map +1 -1
- package/dist/migrations/v2.0/simplify-analytics-precalculations.js +2 -1
- package/dist/notification/index.js +36 -7
- package/dist/scopes/index.d.ts +80 -10
- package/dist/scopes/index.js +42 -8
- package/opencrvs-toolkit-2.0.0-rc.bee2b7b.tgz +0 -0
- package/package.json +1 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/migrations/v2.0/add-resend-invite-notification.d.ts +0 -3
- package/dist/migrations/v2.0/add-resend-invite-notification.d.ts.map +0 -1
- package/dist/migrations/v2.0/add-resend-invite-notification.js +0 -373
- package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts +0 -3
- package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts.map +0 -1
- package/dist/migrations/v2.0/delete-infrastructure-directory.js +0 -77
- package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts +0 -3
- package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts.map +0 -1
- package/dist/migrations/v2.0/merge-infrastructure-directory.js +0 -221
- package/dist/migrations/v2.0/migrate-application-config-url.d.ts +0 -3
- package/dist/migrations/v2.0/migrate-application-config-url.d.ts.map +0 -1
- package/dist/migrations/v2.0/migrate-application-config-url.js +0 -342
- package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts +0 -3
- package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts.map +0 -1
- package/dist/migrations/v2.0/remove-fhir-url-helpers.js +0 -163
- package/dist/migrations/v2.0/remove-old-statistics-service.d.ts +0 -3
- package/dist/migrations/v2.0/remove-old-statistics-service.d.ts.map +0 -1
- package/dist/migrations/v2.0/remove-old-statistics-service.js +0 -356
- package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts +0 -3
- package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts.map +0 -1
- package/dist/migrations/v2.0/remove-unused-environment-variables.js +0 -186
- package/dist/migrations/v2.0/update-package-json.d.ts +0 -3
- package/dist/migrations/v2.0/update-package-json.d.ts.map +0 -1
- package/dist/migrations/v2.0/update-package-json.js +0 -105
- package/opencrvs-toolkit-2.0.0-rc.b63fd2e.tgz +0 -0
|
@@ -31,6 +31,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
// src/migrations/v2.0/index.ts
|
|
32
32
|
var v2_exports = {};
|
|
33
33
|
__export(v2_exports, {
|
|
34
|
+
getCwd: () => getCwd,
|
|
34
35
|
runUpgrade: () => runUpgrade
|
|
35
36
|
});
|
|
36
37
|
module.exports = __toCommonJS(v2_exports);
|
|
@@ -103,7 +104,7 @@ function processFile(filePath, project) {
|
|
|
103
104
|
if (wasRemoved) {
|
|
104
105
|
removedCount++;
|
|
105
106
|
console.log(
|
|
106
|
-
` [${import_path.default.relative(
|
|
107
|
+
` [${import_path.default.relative(getCwd(), filePath)}] Removed 'review' from REGISTER action`
|
|
107
108
|
);
|
|
108
109
|
}
|
|
109
110
|
}
|
|
@@ -111,7 +112,7 @@ function processFile(filePath, project) {
|
|
|
111
112
|
return removedCount;
|
|
112
113
|
}
|
|
113
114
|
async function main() {
|
|
114
|
-
const srcDir = import_path.default.join(
|
|
115
|
+
const srcDir = import_path.default.join(getCwd(), "src");
|
|
115
116
|
console.log(`Scanning for defineConfig calls in: ${srcDir}
|
|
116
117
|
`);
|
|
117
118
|
const project = new import_ts_morph.Project({
|
|
@@ -147,7 +148,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
147
148
|
for (const filePath of modifiedFiles) {
|
|
148
149
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
149
150
|
await sourceFile.save();
|
|
150
|
-
console.log(` Saved: ${import_path.default.relative(
|
|
151
|
+
console.log(` Saved: ${import_path.default.relative(getCwd(), filePath)}`);
|
|
151
152
|
}
|
|
152
153
|
console.log(
|
|
153
154
|
`
|
|
@@ -350,7 +351,7 @@ function processFile2(filePath, project) {
|
|
|
350
351
|
const eventType = resolveEventType(configArg);
|
|
351
352
|
if (!eventType) {
|
|
352
353
|
console.warn(
|
|
353
|
-
` [${import_path2.default.relative(
|
|
354
|
+
` [${import_path2.default.relative(getCwd(), configArg.getSourceFile().getFilePath())}] Could not resolve root 'type' from defineConfig \u2014 skipping auditHistoryLabel id generation`
|
|
354
355
|
);
|
|
355
356
|
}
|
|
356
357
|
let fileNeedsImports = false;
|
|
@@ -366,7 +367,7 @@ function processFile2(filePath, project) {
|
|
|
366
367
|
fileNeedsImports = true;
|
|
367
368
|
configHadValidateAction = true;
|
|
368
369
|
console.log(
|
|
369
|
-
` [${import_path2.default.relative(
|
|
370
|
+
` [${import_path2.default.relative(getCwd(), filePath)}] Transformed VALIDATE action to CUSTOM with customActionType: '${VALIDATE_DECLARATION_VALUE}'`
|
|
370
371
|
);
|
|
371
372
|
}
|
|
372
373
|
}
|
|
@@ -387,7 +388,7 @@ function processFile2(filePath, project) {
|
|
|
387
388
|
]`
|
|
388
389
|
});
|
|
389
390
|
console.log(
|
|
390
|
-
` [${import_path2.default.relative(
|
|
391
|
+
` [${import_path2.default.relative(getCwd(), filePath)}] Added top-level 'flags' array to defineConfig`
|
|
391
392
|
);
|
|
392
393
|
}
|
|
393
394
|
if (fileNeedsImports) {
|
|
@@ -397,7 +398,7 @@ function processFile2(filePath, project) {
|
|
|
397
398
|
return transformedCount;
|
|
398
399
|
}
|
|
399
400
|
async function main2() {
|
|
400
|
-
const srcDir = import_path2.default.join(
|
|
401
|
+
const srcDir = import_path2.default.join(getCwd(), "src");
|
|
401
402
|
console.log(`Scanning for defineConfig calls in: ${srcDir}
|
|
402
403
|
`);
|
|
403
404
|
const project = new import_ts_morph2.Project({
|
|
@@ -432,7 +433,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
432
433
|
for (const filePath of modifiedFiles) {
|
|
433
434
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
434
435
|
await sourceFile.save();
|
|
435
|
-
console.log(` Saved: ${import_path2.default.relative(
|
|
436
|
+
console.log(` Saved: ${import_path2.default.relative(getCwd(), filePath)}`);
|
|
436
437
|
}
|
|
437
438
|
console.log(
|
|
438
439
|
`
|
|
@@ -503,14 +504,14 @@ function processFile3(filePath, project) {
|
|
|
503
504
|
actionsInitializer.removeElement(index);
|
|
504
505
|
removedCount++;
|
|
505
506
|
console.log(
|
|
506
|
-
` [${import_path3.default.relative(
|
|
507
|
+
` [${import_path3.default.relative(getCwd(), filePath)}] Removed DELETE action at index ${index}`
|
|
507
508
|
);
|
|
508
509
|
}
|
|
509
510
|
}
|
|
510
511
|
return removedCount;
|
|
511
512
|
}
|
|
512
513
|
async function main3() {
|
|
513
|
-
const srcDir = import_path3.default.join(
|
|
514
|
+
const srcDir = import_path3.default.join(getCwd(), "src");
|
|
514
515
|
console.log(`Scanning for defineConfig calls in: ${srcDir}
|
|
515
516
|
`);
|
|
516
517
|
const project = new import_ts_morph3.Project({
|
|
@@ -545,7 +546,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
545
546
|
for (const filePath of modifiedFiles) {
|
|
546
547
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
547
548
|
await sourceFile.save();
|
|
548
|
-
console.log(` Saved: ${import_path3.default.relative(
|
|
549
|
+
console.log(` Saved: ${import_path3.default.relative(getCwd(), filePath)}`);
|
|
549
550
|
}
|
|
550
551
|
console.log(
|
|
551
552
|
`
|
|
@@ -619,19 +620,19 @@ function processFile4(filePath, project) {
|
|
|
619
620
|
if (result === "converted-to-heading") {
|
|
620
621
|
changedCount++;
|
|
621
622
|
console.log(
|
|
622
|
-
` [${import_path4.default.relative(
|
|
623
|
+
` [${import_path4.default.relative(getCwd(), filePath)}] Converted PARAGRAPH with heading fontVariant to HEADING`
|
|
623
624
|
);
|
|
624
625
|
} else if (result === "removed-font-variant") {
|
|
625
626
|
changedCount++;
|
|
626
627
|
console.log(
|
|
627
|
-
` [${import_path4.default.relative(
|
|
628
|
+
` [${import_path4.default.relative(getCwd(), filePath)}] Removed non-heading fontVariant from PARAGRAPH`
|
|
628
629
|
);
|
|
629
630
|
}
|
|
630
631
|
}
|
|
631
632
|
return changedCount;
|
|
632
633
|
}
|
|
633
634
|
async function main4() {
|
|
634
|
-
const srcDir = import_path4.default.join(
|
|
635
|
+
const srcDir = import_path4.default.join(getCwd(), "src");
|
|
635
636
|
console.log(`Scanning for FieldType.PARAGRAPH fields in: ${srcDir}
|
|
636
637
|
`);
|
|
637
638
|
const project = new import_ts_morph4.Project({
|
|
@@ -665,7 +666,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
665
666
|
for (const filePath of modifiedFiles) {
|
|
666
667
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
667
668
|
await sourceFile.save();
|
|
668
|
-
console.log(` Saved: ${import_path4.default.relative(
|
|
669
|
+
console.log(` Saved: ${import_path4.default.relative(getCwd(), filePath)}`);
|
|
669
670
|
}
|
|
670
671
|
console.log(`
|
|
671
672
|
Done. Processed ${totalChanged} FieldType.PARAGRAPH field(s).`);
|
|
@@ -815,7 +816,7 @@ function processFile5(filePath, project) {
|
|
|
815
816
|
if (changed > 0) {
|
|
816
817
|
migratedCount += changed;
|
|
817
818
|
console.log(
|
|
818
|
-
` [${import_path5.default.relative(
|
|
819
|
+
` [${import_path5.default.relative(getCwd(), filePath)}] Migrated ${changed} clause(s): VALIDATED status \u2192 flags.anyOf`
|
|
819
820
|
);
|
|
820
821
|
}
|
|
821
822
|
}
|
|
@@ -823,7 +824,7 @@ function processFile5(filePath, project) {
|
|
|
823
824
|
return migratedCount;
|
|
824
825
|
}
|
|
825
826
|
async function main5() {
|
|
826
|
-
const srcDir = import_path5.default.join(
|
|
827
|
+
const srcDir = import_path5.default.join(getCwd(), "src");
|
|
827
828
|
console.log(`Scanning for defineWorkqueues calls in: ${srcDir}
|
|
828
829
|
`);
|
|
829
830
|
const project = new import_ts_morph5.Project({
|
|
@@ -857,7 +858,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
857
858
|
for (const filePath of modifiedFiles) {
|
|
858
859
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
859
860
|
await sourceFile.save();
|
|
860
|
-
console.log(` Saved: ${import_path5.default.relative(
|
|
861
|
+
console.log(` Saved: ${import_path5.default.relative(getCwd(), filePath)}`);
|
|
861
862
|
}
|
|
862
863
|
console.log(
|
|
863
864
|
`
|
|
@@ -1075,7 +1076,7 @@ function processFile6(filePath, project) {
|
|
|
1075
1076
|
const sourceFile = project.getSourceFile(filePath);
|
|
1076
1077
|
if (!sourceFile) return 0;
|
|
1077
1078
|
let totalChanges = 0;
|
|
1078
|
-
const relPath = import_path6.default.relative(
|
|
1079
|
+
const relPath = import_path6.default.relative(getCwd(), filePath);
|
|
1079
1080
|
const callExpressions = sourceFile.getDescendantsOfKind(
|
|
1080
1081
|
import_ts_morph6.SyntaxKind.CallExpression
|
|
1081
1082
|
);
|
|
@@ -1116,7 +1117,7 @@ function processFile6(filePath, project) {
|
|
|
1116
1117
|
return totalChanges;
|
|
1117
1118
|
}
|
|
1118
1119
|
async function main6() {
|
|
1119
|
-
const srcDir = import_path6.default.join(
|
|
1120
|
+
const srcDir = import_path6.default.join(getCwd(), "src");
|
|
1120
1121
|
console.log(
|
|
1121
1122
|
`Scanning for birth defineConfig and PRINT_CERTIFICATE workqueues in: ${srcDir}
|
|
1122
1123
|
`
|
|
@@ -1152,7 +1153,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
1152
1153
|
for (const filePath of modifiedFiles) {
|
|
1153
1154
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
1154
1155
|
await sourceFile.save();
|
|
1155
|
-
console.log(` Saved: ${import_path6.default.relative(
|
|
1156
|
+
console.log(` Saved: ${import_path6.default.relative(getCwd(), filePath)}`);
|
|
1156
1157
|
}
|
|
1157
1158
|
console.log(
|
|
1158
1159
|
`
|
|
@@ -1189,14 +1190,14 @@ function processFile7(filePath, project) {
|
|
|
1189
1190
|
array3.removeElement(index);
|
|
1190
1191
|
removedCount++;
|
|
1191
1192
|
console.log(
|
|
1192
|
-
` [${import_path7.default.relative(
|
|
1193
|
+
` [${import_path7.default.relative(getCwd(), filePath)}] Removed InherentFlags.PENDING_CERTIFICATION from array`
|
|
1193
1194
|
);
|
|
1194
1195
|
}
|
|
1195
1196
|
}
|
|
1196
1197
|
return removedCount;
|
|
1197
1198
|
}
|
|
1198
1199
|
async function main7() {
|
|
1199
|
-
const srcDir = import_path7.default.join(
|
|
1200
|
+
const srcDir = import_path7.default.join(getCwd(), "src");
|
|
1200
1201
|
console.log(
|
|
1201
1202
|
`Scanning for InherentFlags.PENDING_CERTIFICATION array elements in: ${srcDir}
|
|
1202
1203
|
`
|
|
@@ -1232,7 +1233,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
1232
1233
|
for (const filePath of modifiedFiles) {
|
|
1233
1234
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
1234
1235
|
await sourceFile.save();
|
|
1235
|
-
console.log(` Saved: ${import_path7.default.relative(
|
|
1236
|
+
console.log(` Saved: ${import_path7.default.relative(getCwd(), filePath)}`);
|
|
1236
1237
|
}
|
|
1237
1238
|
console.log(
|
|
1238
1239
|
`
|
|
@@ -1290,13 +1291,13 @@ function processFile8(filePath, project) {
|
|
|
1290
1291
|
propAccess.getNameNode().replaceWithText(NEW_PROPERTY_NAME);
|
|
1291
1292
|
renamedCount++;
|
|
1292
1293
|
console.log(
|
|
1293
|
-
` [${import_path8.default.relative(
|
|
1294
|
+
` [${import_path8.default.relative(getCwd(), filePath)}] Renamed Location.${OLD_PROPERTY_NAME} \u2192 Location.${NEW_PROPERTY_NAME}`
|
|
1294
1295
|
);
|
|
1295
1296
|
}
|
|
1296
1297
|
return renamedCount;
|
|
1297
1298
|
}
|
|
1298
1299
|
async function main8() {
|
|
1299
|
-
const srcDir = import_path8.default.join(
|
|
1300
|
+
const srcDir = import_path8.default.join(getCwd(), "src");
|
|
1300
1301
|
console.log(
|
|
1301
1302
|
`Scanning for Location.${OLD_PROPERTY_NAME} references in: ${srcDir}
|
|
1302
1303
|
`
|
|
@@ -1332,7 +1333,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
1332
1333
|
for (const filePath of modifiedFiles) {
|
|
1333
1334
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
1334
1335
|
await sourceFile.save();
|
|
1335
|
-
console.log(` Saved: ${import_path8.default.relative(
|
|
1336
|
+
console.log(` Saved: ${import_path8.default.relative(getCwd(), filePath)}`);
|
|
1336
1337
|
}
|
|
1337
1338
|
console.log(
|
|
1338
1339
|
`
|
|
@@ -1399,7 +1400,7 @@ function processFile9(filePath, project) {
|
|
|
1399
1400
|
const sourceFile = project.getSourceFile(filePath);
|
|
1400
1401
|
if (!sourceFile) return 0;
|
|
1401
1402
|
let renamedCount = 0;
|
|
1402
|
-
const relPath = import_path9.default.relative(
|
|
1403
|
+
const relPath = import_path9.default.relative(getCwd(), filePath);
|
|
1403
1404
|
const candidates = sourceFile.getDescendantsOfKind(
|
|
1404
1405
|
import_ts_morph9.SyntaxKind.ObjectLiteralExpression
|
|
1405
1406
|
);
|
|
@@ -1414,7 +1415,7 @@ function processFile9(filePath, project) {
|
|
|
1414
1415
|
return renamedCount;
|
|
1415
1416
|
}
|
|
1416
1417
|
async function main9() {
|
|
1417
|
-
const srcDir = import_path9.default.join(
|
|
1418
|
+
const srcDir = import_path9.default.join(getCwd(), "src");
|
|
1418
1419
|
console.log(`Scanning for Hapi route configs in: ${srcDir}
|
|
1419
1420
|
`);
|
|
1420
1421
|
console.log("Active path renames:");
|
|
@@ -1451,7 +1452,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
1451
1452
|
for (const filePath of modifiedFiles) {
|
|
1452
1453
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
1453
1454
|
await sourceFile.save();
|
|
1454
|
-
console.log(` Saved: ${import_path9.default.relative(
|
|
1455
|
+
console.log(` Saved: ${import_path9.default.relative(getCwd(), filePath)}`);
|
|
1455
1456
|
}
|
|
1456
1457
|
console.log(`
|
|
1457
1458
|
Done. Renamed ${totalRenamed} route path(s).`);
|
|
@@ -1825,9 +1826,9 @@ function updateRouteHandlers(sourceFiles, group, srcDir, relCwd) {
|
|
|
1825
1826
|
}
|
|
1826
1827
|
return replacedCount;
|
|
1827
1828
|
}
|
|
1828
|
-
function resolveConfigChain(configObj,
|
|
1829
|
+
function resolveConfigChain(configObj, path17) {
|
|
1829
1830
|
let current = configObj;
|
|
1830
|
-
for (const key of
|
|
1831
|
+
for (const key of path17) {
|
|
1831
1832
|
if (!import_ts_morph10.Node.isObjectLiteralExpression(current)) return null;
|
|
1832
1833
|
const prop = current.getProperty(key);
|
|
1833
1834
|
if (!prop || !import_ts_morph10.Node.isPropertyAssignment(prop)) return null;
|
|
@@ -1872,8 +1873,8 @@ function ensureJoinImport(sf) {
|
|
|
1872
1873
|
});
|
|
1873
1874
|
}
|
|
1874
1875
|
async function main10() {
|
|
1875
|
-
const srcDir = import_path10.default.join(
|
|
1876
|
-
const relCwd = (fp) => import_path10.default.relative(
|
|
1876
|
+
const srcDir = import_path10.default.join(getCwd(), "src");
|
|
1877
|
+
const relCwd = (fp) => import_path10.default.relative(getCwd(), fp);
|
|
1877
1878
|
console.log("Phase 1: Converting JS config files to TypeScript...\n");
|
|
1878
1879
|
let convertedCount = 0;
|
|
1879
1880
|
for (const group of CONFIG_GROUPS) {
|
|
@@ -1961,7 +1962,7 @@ async function main10() {
|
|
|
1961
1962
|
ensureJoinImport(sf);
|
|
1962
1963
|
}
|
|
1963
1964
|
console.log(
|
|
1964
|
-
` Inlined applicationConfig.${accessPath.join(".")} \u2192 ${adjustedValue} in ${import_path10.default.relative(
|
|
1965
|
+
` Inlined applicationConfig.${accessPath.join(".")} \u2192 ${adjustedValue} in ${import_path10.default.relative(getCwd(), sf.getFilePath())}`
|
|
1965
1966
|
);
|
|
1966
1967
|
filesToSaveAfterInlining.add(sf);
|
|
1967
1968
|
madeReplacement = true;
|
|
@@ -1973,7 +1974,7 @@ async function main10() {
|
|
|
1973
1974
|
for (const sf of Array.from(filesToSaveAfterInlining)) {
|
|
1974
1975
|
await sf.save();
|
|
1975
1976
|
console.log(
|
|
1976
|
-
` Saved (inlined): ${import_path10.default.relative(
|
|
1977
|
+
` Saved (inlined): ${import_path10.default.relative(getCwd(), sf.getFilePath())}`
|
|
1977
1978
|
);
|
|
1978
1979
|
}
|
|
1979
1980
|
for (const prop of [...propsToRemove].reverse()) {
|
|
@@ -2122,6 +2123,10 @@ var scopeByEvent = z3.preprocess(
|
|
|
2122
2123
|
(val) => val === void 0 ? void 0 : [val].flat(),
|
|
2123
2124
|
z3.array(z3.string()).optional()
|
|
2124
2125
|
).describe("Event type, e.g. birth, death");
|
|
2126
|
+
var userRole = z3.preprocess(
|
|
2127
|
+
(val) => val === void 0 ? void 0 : [val].flat(),
|
|
2128
|
+
z3.array(z3.string()).optional()
|
|
2129
|
+
).describe("User role, e.g. admin, field agent");
|
|
2125
2130
|
var scopeOptionsPlaceEvent = z3.object({
|
|
2126
2131
|
event: scopeByEvent,
|
|
2127
2132
|
placeOfEvent: JurisdictionFilter.optional()
|
|
@@ -2226,6 +2231,33 @@ var RecordScopeV2 = z3.discriminatedUnion("type", [
|
|
|
2226
2231
|
]).describe(
|
|
2227
2232
|
"Scopes used to check user's permission to perform actions on a record."
|
|
2228
2233
|
);
|
|
2234
|
+
var SystemScopeType = z3.enum([
|
|
2235
|
+
"organisation.read-locations",
|
|
2236
|
+
"user.read",
|
|
2237
|
+
"user.create",
|
|
2238
|
+
"user.edit"
|
|
2239
|
+
]);
|
|
2240
|
+
var UserScopeType = SystemScopeType.extract([
|
|
2241
|
+
"user.read",
|
|
2242
|
+
"user.create",
|
|
2243
|
+
"user.edit"
|
|
2244
|
+
]);
|
|
2245
|
+
var ScopesWithRoleOption = UserScopeType.extract(["user.edit", "user.create"]);
|
|
2246
|
+
var UserScopeV2 = z3.discriminatedUnion("type", [
|
|
2247
|
+
z3.object({
|
|
2248
|
+
type: ScopesWithRoleOption,
|
|
2249
|
+
options: z3.object({
|
|
2250
|
+
accessLevel: JurisdictionFilter.optional(),
|
|
2251
|
+
role: userRole.optional()
|
|
2252
|
+
}).optional()
|
|
2253
|
+
}),
|
|
2254
|
+
z3.object({
|
|
2255
|
+
type: UserScopeType.extract(["user.read"]),
|
|
2256
|
+
options: z3.object({
|
|
2257
|
+
accessLevel: JurisdictionFilter.optional()
|
|
2258
|
+
}).optional()
|
|
2259
|
+
})
|
|
2260
|
+
]);
|
|
2229
2261
|
var ResolvedRecordScopeV2 = z3.discriminatedUnion("type", [
|
|
2230
2262
|
z3.object({
|
|
2231
2263
|
type: ScopesWithPlaceEventOptions,
|
|
@@ -2246,16 +2278,14 @@ var ResolvedRecordScopeV2 = z3.discriminatedUnion("type", [
|
|
|
2246
2278
|
}).optional()
|
|
2247
2279
|
})
|
|
2248
2280
|
]).describe("Resolved scope with location/user IDs instead of filters.");
|
|
2249
|
-
var SystemScopeType = z3.enum([
|
|
2250
|
-
"organisation.read-locations",
|
|
2251
|
-
"user.read",
|
|
2252
|
-
"user.create",
|
|
2253
|
-
"user.edit"
|
|
2254
|
-
]);
|
|
2255
2281
|
var Scope2 = z3.discriminatedUnion("type", [
|
|
2256
2282
|
z3.object({ type: PlainScopeType }),
|
|
2257
2283
|
...RecordScopeV2.options,
|
|
2258
|
-
|
|
2284
|
+
...UserScopeV2.options,
|
|
2285
|
+
z3.object({
|
|
2286
|
+
type: z3.literal("organisation.read-locations"),
|
|
2287
|
+
options: AccessLevelOptions.optional()
|
|
2288
|
+
}),
|
|
2259
2289
|
z3.object({
|
|
2260
2290
|
type: z3.literal("workqueue"),
|
|
2261
2291
|
options: WorkqueueOrDashboardOptions
|
|
@@ -2590,7 +2620,7 @@ function migrateScopesArrays(rolesFilePath, project) {
|
|
|
2590
2620
|
const scopeKey = resolveScopeKeyFromElementAccess(element);
|
|
2591
2621
|
if (scopeKey && !(scopeKey in SCOPES)) {
|
|
2592
2622
|
console.warn(
|
|
2593
|
-
` [${import_path11.default.relative(
|
|
2623
|
+
` [${import_path11.default.relative(getCwd(), rolesFilePath)}] Removing unknown scope reference: SCOPES.${scopeKey}`
|
|
2594
2624
|
);
|
|
2595
2625
|
initializer.removeElement(index);
|
|
2596
2626
|
removedCount++;
|
|
@@ -2599,7 +2629,7 @@ function migrateScopesArrays(rolesFilePath, project) {
|
|
|
2599
2629
|
const legacyScope = resolveLegacyScopeFromElement(element);
|
|
2600
2630
|
if (!legacyScope) {
|
|
2601
2631
|
console.warn(
|
|
2602
|
-
` [${import_path11.default.relative(
|
|
2632
|
+
` [${import_path11.default.relative(getCwd(), rolesFilePath)}] Skipping non-literal scope expression: ${element.getText()}`
|
|
2603
2633
|
);
|
|
2604
2634
|
continue;
|
|
2605
2635
|
}
|
|
@@ -2608,7 +2638,7 @@ function migrateScopesArrays(rolesFilePath, project) {
|
|
|
2608
2638
|
const scope = decodeScope(migratedScope);
|
|
2609
2639
|
if (!scope) {
|
|
2610
2640
|
console.warn(
|
|
2611
|
-
` [${import_path11.default.relative(
|
|
2641
|
+
` [${import_path11.default.relative(getCwd(), rolesFilePath)}] Could not decode migrated scope '${migratedScope}'.`
|
|
2612
2642
|
);
|
|
2613
2643
|
continue;
|
|
2614
2644
|
}
|
|
@@ -2616,14 +2646,14 @@ function migrateScopesArrays(rolesFilePath, project) {
|
|
|
2616
2646
|
migratedCount++;
|
|
2617
2647
|
} catch (error) {
|
|
2618
2648
|
console.warn(
|
|
2619
|
-
` [${import_path11.default.relative(
|
|
2649
|
+
` [${import_path11.default.relative(getCwd(), rolesFilePath)}] Could not migrate scope '${legacyScope}': ${error}`
|
|
2620
2650
|
);
|
|
2621
2651
|
}
|
|
2622
2652
|
}
|
|
2623
2653
|
}
|
|
2624
2654
|
if (removedCount > 0) {
|
|
2625
2655
|
console.log(
|
|
2626
|
-
` Removed ${removedCount} unknown SCOPES reference(s) from '${import_path11.default.relative(
|
|
2656
|
+
` Removed ${removedCount} unknown SCOPES reference(s) from '${import_path11.default.relative(getCwd(), rolesFilePath)}'.`
|
|
2627
2657
|
);
|
|
2628
2658
|
}
|
|
2629
2659
|
return { migratedCount, removedCount };
|
|
@@ -2745,9 +2775,9 @@ function removeRoleTypeDefinitionAndUnusedImports(rolesFilePath, project) {
|
|
|
2745
2775
|
return removed;
|
|
2746
2776
|
}
|
|
2747
2777
|
async function main11() {
|
|
2748
|
-
const
|
|
2749
|
-
const srcDir = import_path11.default.join(
|
|
2750
|
-
const rolesFilePath = import_path11.default.join(
|
|
2778
|
+
const cwd2 = getCwd();
|
|
2779
|
+
const srcDir = import_path11.default.join(cwd2, "src");
|
|
2780
|
+
const rolesFilePath = import_path11.default.join(cwd2, ROLES_FILE_RELATIVE_PATH);
|
|
2751
2781
|
console.log(`Scanning roles scopes in: ${rolesFilePath}`);
|
|
2752
2782
|
const project = new import_ts_morph11.Project({
|
|
2753
2783
|
tsConfigFilePath: import_path11.default.resolve(srcDir, "../tsconfig.json"),
|
|
@@ -2811,13 +2841,13 @@ function processFile10(filePath, project) {
|
|
|
2811
2841
|
decl.remove();
|
|
2812
2842
|
}
|
|
2813
2843
|
console.log(
|
|
2814
|
-
` [${import_path12.default.relative(
|
|
2844
|
+
` [${import_path12.default.relative(getCwd(), filePath)}] Removed ${matchingNamedImports.length} deprecated '${DEPRECATED_IMPORT}' import(s) from '${decl.getModuleSpecifierValue()}'`
|
|
2815
2845
|
);
|
|
2816
2846
|
}
|
|
2817
2847
|
return removedCount;
|
|
2818
2848
|
}
|
|
2819
2849
|
async function main12() {
|
|
2820
|
-
const srcDir = import_path12.default.join(
|
|
2850
|
+
const srcDir = import_path12.default.join(getCwd(), "src");
|
|
2821
2851
|
console.log(`Scanning for deprecated imports in: ${srcDir}
|
|
2822
2852
|
`);
|
|
2823
2853
|
const project = new import_ts_morph12.Project({
|
|
@@ -2848,738 +2878,15 @@ async function main12() {
|
|
|
2848
2878
|
Saving ${modifiedFiles.length} modified file(s)...`);
|
|
2849
2879
|
for (const filePath of modifiedFiles) {
|
|
2850
2880
|
await project.getSourceFileOrThrow(filePath).save();
|
|
2851
|
-
console.log(` Saved: ${import_path12.default.relative(
|
|
2881
|
+
console.log(` Saved: ${import_path12.default.relative(getCwd(), filePath)}`);
|
|
2852
2882
|
}
|
|
2853
2883
|
console.log(`
|
|
2854
2884
|
Done. Removed ${totalRemoved} deprecated import(s).`);
|
|
2855
2885
|
}
|
|
2856
2886
|
|
|
2857
|
-
// src/migrations/v2.0/remove-unused-environment-variables.ts
|
|
2858
|
-
var import_path13 = __toESM(require("path"));
|
|
2859
|
-
var import_ts_morph13 = require("ts-morph");
|
|
2860
|
-
var UNUSED_ENV_VARS = /* @__PURE__ */ new Set([
|
|
2861
|
-
"APPLICATION_CONFIG_URL",
|
|
2862
|
-
"FHIR_URL",
|
|
2863
|
-
"CONFIRM_REGISTRATION_URL"
|
|
2864
|
-
]);
|
|
2865
|
-
var ENVIRONMENT_FILE_RELATIVE = "src/environment.ts";
|
|
2866
|
-
var CONSTANTS_FILE_RELATIVE = "src/constants.ts";
|
|
2867
|
-
function cleanEnvironmentFile(project, filePath) {
|
|
2868
|
-
const sourceFile = project.getSourceFile(filePath);
|
|
2869
|
-
if (!sourceFile) return [];
|
|
2870
|
-
const removed = [];
|
|
2871
|
-
const cleanEnvCall = sourceFile.getDescendantsOfKind(import_ts_morph13.SyntaxKind.CallExpression).find((call) => {
|
|
2872
|
-
const expr = call.getExpression();
|
|
2873
|
-
return import_ts_morph13.Node.isIdentifier(expr) && expr.getText() === "cleanEnv";
|
|
2874
|
-
});
|
|
2875
|
-
if (!cleanEnvCall) return removed;
|
|
2876
|
-
const schemaArg = cleanEnvCall.getArguments()[1]?.asKind(import_ts_morph13.SyntaxKind.ObjectLiteralExpression);
|
|
2877
|
-
if (!schemaArg) return removed;
|
|
2878
|
-
for (const name of UNUSED_ENV_VARS) {
|
|
2879
|
-
const prop = schemaArg.getProperty(name);
|
|
2880
|
-
if (!prop) continue;
|
|
2881
|
-
if (prop.isKind(import_ts_morph13.SyntaxKind.PropertyAssignment) || prop.isKind(import_ts_morph13.SyntaxKind.ShorthandPropertyAssignment)) {
|
|
2882
|
-
prop.remove();
|
|
2883
|
-
removed.push(name);
|
|
2884
|
-
}
|
|
2885
|
-
}
|
|
2886
|
-
return removed;
|
|
2887
|
-
}
|
|
2888
|
-
function extractEnvAccess(initText) {
|
|
2889
|
-
if (!initText) return null;
|
|
2890
|
-
const match = /\benv\.([A-Z][A-Z0-9_]*)\b/.exec(initText);
|
|
2891
|
-
return match ? match[1] : null;
|
|
2892
|
-
}
|
|
2893
|
-
function cleanConstantsFile(project, filePath) {
|
|
2894
|
-
const sourceFile = project.getSourceFile(filePath);
|
|
2895
|
-
if (!sourceFile) return [];
|
|
2896
|
-
const removed = [];
|
|
2897
|
-
for (const stmt of [...sourceFile.getVariableStatements()]) {
|
|
2898
|
-
const declarations = [...stmt.getDeclarations()];
|
|
2899
|
-
const declarationsToRemove = declarations.filter((decl) => {
|
|
2900
|
-
const name = decl.getName();
|
|
2901
|
-
const accessedEnvVar = extractEnvAccess(decl.getInitializer()?.getText());
|
|
2902
|
-
return UNUSED_ENV_VARS.has(name) || accessedEnvVar !== null && UNUSED_ENV_VARS.has(accessedEnvVar);
|
|
2903
|
-
});
|
|
2904
|
-
if (declarationsToRemove.length === 0) continue;
|
|
2905
|
-
const namesToRemove = declarationsToRemove.map((decl) => decl.getName());
|
|
2906
|
-
removed.push(...namesToRemove);
|
|
2907
|
-
if (declarationsToRemove.length === declarations.length) {
|
|
2908
|
-
stmt.remove();
|
|
2909
|
-
} else {
|
|
2910
|
-
for (const decl of declarationsToRemove) {
|
|
2911
|
-
decl.remove();
|
|
2912
|
-
}
|
|
2913
|
-
}
|
|
2914
|
-
}
|
|
2915
|
-
return removed;
|
|
2916
|
-
}
|
|
2917
|
-
async function main13() {
|
|
2918
|
-
const project = new import_ts_morph13.Project({
|
|
2919
|
-
tsConfigFilePath: import_path13.default.resolve(process.cwd(), "tsconfig.json"),
|
|
2920
|
-
skipAddingFilesFromTsConfig: false
|
|
2921
|
-
});
|
|
2922
|
-
console.log(
|
|
2923
|
-
`Removing unused environment variable(s) (${[...UNUSED_ENV_VARS].join(", ")})...
|
|
2924
|
-
`
|
|
2925
|
-
);
|
|
2926
|
-
const envFilePath = import_path13.default.join(process.cwd(), ENVIRONMENT_FILE_RELATIVE);
|
|
2927
|
-
const constsFilePath = import_path13.default.join(process.cwd(), CONSTANTS_FILE_RELATIVE);
|
|
2928
|
-
const envRemoved = cleanEnvironmentFile(project, envFilePath);
|
|
2929
|
-
if (envRemoved.length > 0) {
|
|
2930
|
-
await project.getSourceFileOrThrow(envFilePath).save();
|
|
2931
|
-
console.log(
|
|
2932
|
-
` [${ENVIRONMENT_FILE_RELATIVE}] Removed schema entr${envRemoved.length === 1 ? "y" : "ies"}: ${envRemoved.join(", ")}`
|
|
2933
|
-
);
|
|
2934
|
-
} else if (project.getSourceFile(envFilePath)) {
|
|
2935
|
-
console.log(
|
|
2936
|
-
` [${ENVIRONMENT_FILE_RELATIVE}] No matching schema entries \u2014 nothing to remove.`
|
|
2937
|
-
);
|
|
2938
|
-
} else {
|
|
2939
|
-
console.log(
|
|
2940
|
-
` [${ENVIRONMENT_FILE_RELATIVE}] File not found \u2014 skipping.`
|
|
2941
|
-
);
|
|
2942
|
-
}
|
|
2943
|
-
const constsRemoved = cleanConstantsFile(project, constsFilePath);
|
|
2944
|
-
if (constsRemoved.length > 0) {
|
|
2945
|
-
await project.getSourceFileOrThrow(constsFilePath).save();
|
|
2946
|
-
console.log(
|
|
2947
|
-
` [${CONSTANTS_FILE_RELATIVE}] Removed declaration(s): ${constsRemoved.join(", ")}`
|
|
2948
|
-
);
|
|
2949
|
-
} else if (project.getSourceFile(constsFilePath)) {
|
|
2950
|
-
console.log(
|
|
2951
|
-
` [${CONSTANTS_FILE_RELATIVE}] No matching declarations \u2014 nothing to remove.`
|
|
2952
|
-
);
|
|
2953
|
-
} else {
|
|
2954
|
-
console.log(` [${CONSTANTS_FILE_RELATIVE}] File not found \u2014 skipping.`);
|
|
2955
|
-
}
|
|
2956
|
-
if (envRemoved.length === 0 && constsRemoved.length === 0) {
|
|
2957
|
-
console.log("\nNothing to do.");
|
|
2958
|
-
return;
|
|
2959
|
-
}
|
|
2960
|
-
console.log(
|
|
2961
|
-
`
|
|
2962
|
-
Done. NOTE: usages of these constants elsewhere in 'src/' may now produce TypeScript errors and need manual review.`
|
|
2963
|
-
);
|
|
2964
|
-
}
|
|
2965
|
-
|
|
2966
|
-
// src/migrations/v2.0/remove-fhir-url-helpers.ts
|
|
2967
|
-
var import_path14 = __toESM(require("path"));
|
|
2968
|
-
var import_ts_morph14 = require("ts-morph");
|
|
2969
|
-
var FHIR_IMPORT = "FHIR_URL";
|
|
2970
|
-
var HELPER_NAMES = /* @__PURE__ */ new Set([
|
|
2971
|
-
"getFromFhir",
|
|
2972
|
-
"updateResourceFromHearth",
|
|
2973
|
-
"updateResourceInHearth"
|
|
2974
|
-
]);
|
|
2975
|
-
function removeHelpers(sourceFilePath, project) {
|
|
2976
|
-
const sourceFile = project.getSourceFile(sourceFilePath);
|
|
2977
|
-
if (!sourceFile) {
|
|
2978
|
-
return {
|
|
2979
|
-
removedHelpers: [],
|
|
2980
|
-
removedImportCount: 0,
|
|
2981
|
-
remainingFhirReferences: 0
|
|
2982
|
-
};
|
|
2983
|
-
}
|
|
2984
|
-
const removedHelpers = [];
|
|
2985
|
-
let removedImportCount = 0;
|
|
2986
|
-
for (const fn of sourceFile.getFunctions()) {
|
|
2987
|
-
const name = fn.getName();
|
|
2988
|
-
if (!name || !HELPER_NAMES.has(name)) continue;
|
|
2989
|
-
removedHelpers.push(name);
|
|
2990
|
-
fn.remove();
|
|
2991
|
-
}
|
|
2992
|
-
for (const stmt of [...sourceFile.getVariableStatements()]) {
|
|
2993
|
-
const declarations = [...stmt.getDeclarations()];
|
|
2994
|
-
const toRemove = declarations.filter((decl) => HELPER_NAMES.has(decl.getName()));
|
|
2995
|
-
if (toRemove.length === 0) continue;
|
|
2996
|
-
removedHelpers.push(...toRemove.map((decl) => decl.getName()));
|
|
2997
|
-
if (toRemove.length === declarations.length) {
|
|
2998
|
-
stmt.remove();
|
|
2999
|
-
} else {
|
|
3000
|
-
for (const decl of toRemove) decl.remove();
|
|
3001
|
-
}
|
|
3002
|
-
}
|
|
3003
|
-
for (const decl of sourceFile.getImportDeclarations()) {
|
|
3004
|
-
const matches = decl.getNamedImports().filter((ni) => ni.getName() === FHIR_IMPORT);
|
|
3005
|
-
if (matches.length === 0) continue;
|
|
3006
|
-
for (const named of matches) {
|
|
3007
|
-
named.remove();
|
|
3008
|
-
removedImportCount++;
|
|
3009
|
-
}
|
|
3010
|
-
const hasAnyNamedImportsLeft = decl.getNamedImports().length > 0;
|
|
3011
|
-
const hasDefaultImport = !!decl.getDefaultImport();
|
|
3012
|
-
const hasNamespaceImport = !!decl.getNamespaceImport();
|
|
3013
|
-
if (!hasAnyNamedImportsLeft && !hasDefaultImport && !hasNamespaceImport) {
|
|
3014
|
-
decl.remove();
|
|
3015
|
-
}
|
|
3016
|
-
}
|
|
3017
|
-
const remainingFhirReferences = sourceFile.getDescendantsOfKind(import_ts_morph14.SyntaxKind.Identifier).filter((id) => id.getText() === FHIR_IMPORT).filter((id) => !id.getFirstAncestorByKind(import_ts_morph14.SyntaxKind.ImportDeclaration)).length;
|
|
3018
|
-
return { removedHelpers, removedImportCount, remainingFhirReferences };
|
|
3019
|
-
}
|
|
3020
|
-
async function main14() {
|
|
3021
|
-
const project = new import_ts_morph14.Project({
|
|
3022
|
-
tsConfigFilePath: import_path14.default.resolve(process.cwd(), "tsconfig.json"),
|
|
3023
|
-
skipAddingFilesFromTsConfig: false
|
|
3024
|
-
});
|
|
3025
|
-
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
3026
|
-
const fp = sf.getFilePath();
|
|
3027
|
-
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
3028
|
-
});
|
|
3029
|
-
console.log(`Removing legacy FHIR_URL helpers in ${sourceFiles.length} source file(s)...
|
|
3030
|
-
`);
|
|
3031
|
-
let totalRemovedImports = 0;
|
|
3032
|
-
let totalRemovedHelpers = 0;
|
|
3033
|
-
const modifiedFiles = [];
|
|
3034
|
-
const warnings = [];
|
|
3035
|
-
for (const sourceFile of sourceFiles) {
|
|
3036
|
-
const filePath = sourceFile.getFilePath();
|
|
3037
|
-
const rel = import_path14.default.relative(process.cwd(), filePath);
|
|
3038
|
-
const result = removeHelpers(filePath, project);
|
|
3039
|
-
const changed = result.removedImportCount > 0 || result.removedHelpers.length > 0;
|
|
3040
|
-
if (changed) {
|
|
3041
|
-
modifiedFiles.push(filePath);
|
|
3042
|
-
totalRemovedImports += result.removedImportCount;
|
|
3043
|
-
totalRemovedHelpers += result.removedHelpers.length;
|
|
3044
|
-
if (result.removedHelpers.length > 0) {
|
|
3045
|
-
console.log(
|
|
3046
|
-
` [${rel}] Removed helper(s): ${result.removedHelpers.join(", ")}`
|
|
3047
|
-
);
|
|
3048
|
-
}
|
|
3049
|
-
if (result.removedImportCount > 0) {
|
|
3050
|
-
console.log(
|
|
3051
|
-
` [${rel}] Removed ${result.removedImportCount} '${FHIR_IMPORT}' import(s)`
|
|
3052
|
-
);
|
|
3053
|
-
}
|
|
3054
|
-
}
|
|
3055
|
-
if (result.remainingFhirReferences > 0) {
|
|
3056
|
-
warnings.push(
|
|
3057
|
-
`${rel}: ${result.remainingFhirReferences} remaining '${FHIR_IMPORT}' reference(s)`
|
|
3058
|
-
);
|
|
3059
|
-
}
|
|
3060
|
-
}
|
|
3061
|
-
if (modifiedFiles.length === 0 && warnings.length === 0) {
|
|
3062
|
-
console.log("No FHIR_URL imports/helpers found. Nothing to do.");
|
|
3063
|
-
return;
|
|
3064
|
-
}
|
|
3065
|
-
if (modifiedFiles.length > 0) {
|
|
3066
|
-
console.log(`
|
|
3067
|
-
Saving ${modifiedFiles.length} modified file(s)...`);
|
|
3068
|
-
for (const filePath of modifiedFiles) {
|
|
3069
|
-
await project.getSourceFileOrThrow(filePath).save();
|
|
3070
|
-
console.log(` Saved: ${import_path14.default.relative(process.cwd(), filePath)}`);
|
|
3071
|
-
}
|
|
3072
|
-
}
|
|
3073
|
-
if (warnings.length > 0) {
|
|
3074
|
-
console.warn(
|
|
3075
|
-
`
|
|
3076
|
-
WARNING: Some '${FHIR_IMPORT}' usages remain and need manual cleanup:
|
|
3077
|
-
` + warnings.map((line) => ` - ${line}`).join("\n")
|
|
3078
|
-
);
|
|
3079
|
-
}
|
|
3080
|
-
console.log(
|
|
3081
|
-
`
|
|
3082
|
-
Done. Removed ${totalRemovedHelpers} helper declaration(s) and ${totalRemovedImports} '${FHIR_IMPORT}' import(s).`
|
|
3083
|
-
);
|
|
3084
|
-
}
|
|
3085
|
-
|
|
3086
|
-
// src/migrations/v2.0/migrate-application-config-url.ts
|
|
3087
|
-
var import_path15 = __toESM(require("path"));
|
|
3088
|
-
var import_ts_morph15 = require("ts-morph");
|
|
3089
|
-
var TARGET_IDENTIFIER = "APPLICATION_CONFIG_URL";
|
|
3090
|
-
var REPLACEMENT_IDENTIFIER = "applicationConfig";
|
|
3091
|
-
var REPLACEMENT_MODULE = "@countryconfig/api/application/application-config";
|
|
3092
|
-
var FUNCTION_LIKE_KINDS = [
|
|
3093
|
-
import_ts_morph15.SyntaxKind.FunctionDeclaration,
|
|
3094
|
-
import_ts_morph15.SyntaxKind.FunctionExpression,
|
|
3095
|
-
import_ts_morph15.SyntaxKind.ArrowFunction,
|
|
3096
|
-
import_ts_morph15.SyntaxKind.MethodDeclaration
|
|
3097
|
-
];
|
|
3098
|
-
function describeFunction(node) {
|
|
3099
|
-
if (import_ts_morph15.Node.isFunctionDeclaration(node) || import_ts_morph15.Node.isMethodDeclaration(node)) {
|
|
3100
|
-
return node.getName() ?? "<anonymous>";
|
|
3101
|
-
}
|
|
3102
|
-
const parent = node.getParent();
|
|
3103
|
-
if (parent && import_ts_morph15.Node.isVariableDeclaration(parent)) {
|
|
3104
|
-
return parent.getName();
|
|
3105
|
-
}
|
|
3106
|
-
if (parent && import_ts_morph15.Node.isPropertyAssignment(parent)) {
|
|
3107
|
-
return parent.getName();
|
|
3108
|
-
}
|
|
3109
|
-
if (import_ts_morph15.Node.isFunctionExpression(node) && node.getNameNode() !== void 0) {
|
|
3110
|
-
return node.getNameNode()?.getText() ?? "<anonymous>";
|
|
3111
|
-
}
|
|
3112
|
-
return "<anonymous>";
|
|
3113
|
-
}
|
|
3114
|
-
function hasBlockBody(node) {
|
|
3115
|
-
if (import_ts_morph15.Node.isFunctionDeclaration(node) || import_ts_morph15.Node.isFunctionExpression(node) || import_ts_morph15.Node.isMethodDeclaration(node)) {
|
|
3116
|
-
return node.getBody() !== void 0;
|
|
3117
|
-
}
|
|
3118
|
-
if (import_ts_morph15.Node.isArrowFunction(node)) {
|
|
3119
|
-
return node.getBody().getKind() === import_ts_morph15.SyntaxKind.Block;
|
|
3120
|
-
}
|
|
3121
|
-
return false;
|
|
3122
|
-
}
|
|
3123
|
-
function isConfigFetcher(node) {
|
|
3124
|
-
let referencesTarget = false;
|
|
3125
|
-
let callsFetch = false;
|
|
3126
|
-
for (const id of node.getDescendantsOfKind(import_ts_morph15.SyntaxKind.Identifier)) {
|
|
3127
|
-
const text = id.getText();
|
|
3128
|
-
if (!referencesTarget && text === TARGET_IDENTIFIER) referencesTarget = true;
|
|
3129
|
-
if (!callsFetch && text === "fetch") {
|
|
3130
|
-
const parent = id.getParent();
|
|
3131
|
-
if (import_ts_morph15.Node.isCallExpression(parent) && parent.getExpression() === id) {
|
|
3132
|
-
callsFetch = true;
|
|
3133
|
-
}
|
|
3134
|
-
}
|
|
3135
|
-
if (referencesTarget && callsFetch) return true;
|
|
3136
|
-
}
|
|
3137
|
-
return false;
|
|
3138
|
-
}
|
|
3139
|
-
function processFile11(sourceFile) {
|
|
3140
|
-
const importsWithTarget = sourceFile.getImportDeclarations().filter(
|
|
3141
|
-
(decl) => decl.getNamedImports().some((ni) => ni.getName() === TARGET_IDENTIFIER)
|
|
3142
|
-
);
|
|
3143
|
-
if (importsWithTarget.length === 0) {
|
|
3144
|
-
return { changed: false, rewrittenFunctions: [], renamedReferences: 0 };
|
|
3145
|
-
}
|
|
3146
|
-
const collidingLocals = sourceFile.getDescendantsOfKind(import_ts_morph15.SyntaxKind.Identifier).filter((id) => id.getText() === REPLACEMENT_IDENTIFIER).filter((id) => {
|
|
3147
|
-
const parent = id.getParent();
|
|
3148
|
-
const kind = parent.getKind();
|
|
3149
|
-
return kind === import_ts_morph15.SyntaxKind.VariableDeclaration || kind === import_ts_morph15.SyntaxKind.FunctionDeclaration || kind === import_ts_morph15.SyntaxKind.ClassDeclaration || kind === import_ts_morph15.SyntaxKind.Parameter;
|
|
3150
|
-
});
|
|
3151
|
-
if (collidingLocals.length > 0) {
|
|
3152
|
-
return {
|
|
3153
|
-
changed: false,
|
|
3154
|
-
rewrittenFunctions: [],
|
|
3155
|
-
renamedReferences: 0,
|
|
3156
|
-
skippedReason: `local declaration named '${REPLACEMENT_IDENTIFIER}' would collide`
|
|
3157
|
-
};
|
|
3158
|
-
}
|
|
3159
|
-
const candidateFunctions = FUNCTION_LIKE_KINDS.flatMap(
|
|
3160
|
-
(kind) => sourceFile.getDescendantsOfKind(kind)
|
|
3161
|
-
);
|
|
3162
|
-
candidateFunctions.sort((a, b) => a.getStart() - b.getStart());
|
|
3163
|
-
const rewrittenFunctions = [];
|
|
3164
|
-
const rewrittenSet = /* @__PURE__ */ new Set();
|
|
3165
|
-
for (const fn of candidateFunctions) {
|
|
3166
|
-
if (!hasBlockBody(fn)) continue;
|
|
3167
|
-
if (!isConfigFetcher(fn)) continue;
|
|
3168
|
-
let inRewrittenAncestor = false;
|
|
3169
|
-
let cursor = fn.getParent();
|
|
3170
|
-
while (cursor) {
|
|
3171
|
-
if (rewrittenSet.has(cursor)) {
|
|
3172
|
-
inRewrittenAncestor = true;
|
|
3173
|
-
break;
|
|
3174
|
-
}
|
|
3175
|
-
cursor = cursor.getParent();
|
|
3176
|
-
}
|
|
3177
|
-
if (inRewrittenAncestor) continue;
|
|
3178
|
-
const start = fn.getStart();
|
|
3179
|
-
const line = sourceFile.getLineAndColumnAtPos(start).line;
|
|
3180
|
-
const name = describeFunction(fn);
|
|
3181
|
-
if (import_ts_morph15.Node.isFunctionDeclaration(fn) || import_ts_morph15.Node.isFunctionExpression(fn) || import_ts_morph15.Node.isMethodDeclaration(fn) || import_ts_morph15.Node.isArrowFunction(fn)) {
|
|
3182
|
-
fn.setBodyText(`return ${REPLACEMENT_IDENTIFIER}`);
|
|
3183
|
-
}
|
|
3184
|
-
rewrittenFunctions.push({ name, line });
|
|
3185
|
-
rewrittenSet.add(fn);
|
|
3186
|
-
}
|
|
3187
|
-
for (const decl of importsWithTarget) {
|
|
3188
|
-
const targetNamed = decl.getNamedImports().find((ni) => ni.getName() === TARGET_IDENTIFIER);
|
|
3189
|
-
targetNamed?.remove();
|
|
3190
|
-
const isNowEmpty = decl.getNamedImports().length === 0 && !decl.getDefaultImport() && !decl.getNamespaceImport();
|
|
3191
|
-
if (isNowEmpty) decl.remove();
|
|
3192
|
-
}
|
|
3193
|
-
const existing = sourceFile.getImportDeclaration(
|
|
3194
|
-
(decl) => decl.getModuleSpecifierValue() === REPLACEMENT_MODULE
|
|
3195
|
-
);
|
|
3196
|
-
if (existing) {
|
|
3197
|
-
const alreadyImported = existing.getNamedImports().some((ni) => ni.getName() === REPLACEMENT_IDENTIFIER);
|
|
3198
|
-
if (!alreadyImported) existing.addNamedImport(REPLACEMENT_IDENTIFIER);
|
|
3199
|
-
} else {
|
|
3200
|
-
sourceFile.addImportDeclaration({
|
|
3201
|
-
moduleSpecifier: REPLACEMENT_MODULE,
|
|
3202
|
-
namedImports: [REPLACEMENT_IDENTIFIER]
|
|
3203
|
-
});
|
|
3204
|
-
}
|
|
3205
|
-
const renameTargets = sourceFile.getDescendantsOfKind(import_ts_morph15.SyntaxKind.Identifier).filter((id) => id.getText() === TARGET_IDENTIFIER).filter((id) => !id.getFirstAncestorByKind(import_ts_morph15.SyntaxKind.ImportDeclaration)).filter((id) => {
|
|
3206
|
-
const parent = id.getParent();
|
|
3207
|
-
const parentKind = parent.getKind();
|
|
3208
|
-
if (parentKind === import_ts_morph15.SyntaxKind.PropertyAccessExpression) {
|
|
3209
|
-
const pae = parent.asKind(import_ts_morph15.SyntaxKind.PropertyAccessExpression);
|
|
3210
|
-
if (pae.getNameNode() === id) return false;
|
|
3211
|
-
}
|
|
3212
|
-
if (parentKind === import_ts_morph15.SyntaxKind.PropertyAssignment) {
|
|
3213
|
-
const pa = parent.asKind(import_ts_morph15.SyntaxKind.PropertyAssignment);
|
|
3214
|
-
if (pa.getNameNode() === id) return false;
|
|
3215
|
-
}
|
|
3216
|
-
if (parentKind === import_ts_morph15.SyntaxKind.ShorthandPropertyAssignment) {
|
|
3217
|
-
return false;
|
|
3218
|
-
}
|
|
3219
|
-
return true;
|
|
3220
|
-
}).sort((a, b) => b.getPos() - a.getPos());
|
|
3221
|
-
for (const id of renameTargets) {
|
|
3222
|
-
id.replaceWithText(REPLACEMENT_IDENTIFIER);
|
|
3223
|
-
}
|
|
3224
|
-
return {
|
|
3225
|
-
changed: true,
|
|
3226
|
-
rewrittenFunctions,
|
|
3227
|
-
renamedReferences: renameTargets.length
|
|
3228
|
-
};
|
|
3229
|
-
}
|
|
3230
|
-
async function main15() {
|
|
3231
|
-
const project = new import_ts_morph15.Project({
|
|
3232
|
-
tsConfigFilePath: import_path15.default.resolve(process.cwd(), "tsconfig.json"),
|
|
3233
|
-
skipAddingFilesFromTsConfig: false
|
|
3234
|
-
});
|
|
3235
|
-
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
3236
|
-
const fp = sf.getFilePath();
|
|
3237
|
-
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
3238
|
-
});
|
|
3239
|
-
console.log(
|
|
3240
|
-
`Migrating '${TARGET_IDENTIFIER}' \u2192 '${REPLACEMENT_IDENTIFIER}' across ${sourceFiles.length} source file(s)...
|
|
3241
|
-
`
|
|
3242
|
-
);
|
|
3243
|
-
let changedFiles = 0;
|
|
3244
|
-
let totalRewrittenFunctions = 0;
|
|
3245
|
-
let totalRenamedReferences = 0;
|
|
3246
|
-
const skipped = [];
|
|
3247
|
-
for (const sourceFile of sourceFiles) {
|
|
3248
|
-
const filePath = sourceFile.getFilePath();
|
|
3249
|
-
const rel = import_path15.default.relative(process.cwd(), filePath);
|
|
3250
|
-
const result = processFile11(sourceFile);
|
|
3251
|
-
if (result.skippedReason) {
|
|
3252
|
-
skipped.push(`${rel} (${result.skippedReason})`);
|
|
3253
|
-
continue;
|
|
3254
|
-
}
|
|
3255
|
-
if (!result.changed) continue;
|
|
3256
|
-
await sourceFile.save();
|
|
3257
|
-
changedFiles++;
|
|
3258
|
-
totalRewrittenFunctions += result.rewrittenFunctions.length;
|
|
3259
|
-
totalRenamedReferences += result.renamedReferences;
|
|
3260
|
-
for (const fn of result.rewrittenFunctions) {
|
|
3261
|
-
console.log(
|
|
3262
|
-
` [${rel}:${fn.line}] Rewrote '${fn.name}' body \u2192 'return ${REPLACEMENT_IDENTIFIER}' (config fetch eliminated)`
|
|
3263
|
-
);
|
|
3264
|
-
}
|
|
3265
|
-
if (result.renamedReferences > 0) {
|
|
3266
|
-
console.log(
|
|
3267
|
-
` [${rel}] Renamed ${result.renamedReferences} stray reference(s) ${TARGET_IDENTIFIER} \u2192 ${REPLACEMENT_IDENTIFIER}`
|
|
3268
|
-
);
|
|
3269
|
-
}
|
|
3270
|
-
}
|
|
3271
|
-
if (skipped.length > 0) {
|
|
3272
|
-
console.warn(
|
|
3273
|
-
`
|
|
3274
|
-
${skipped.length} file(s) skipped:
|
|
3275
|
-
` + skipped.map((s) => ` - ${s}`).join("\n")
|
|
3276
|
-
);
|
|
3277
|
-
}
|
|
3278
|
-
if (changedFiles === 0) {
|
|
3279
|
-
console.log(`
|
|
3280
|
-
No files reference '${TARGET_IDENTIFIER}'. Nothing to do.`);
|
|
3281
|
-
return;
|
|
3282
|
-
}
|
|
3283
|
-
console.log(
|
|
3284
|
-
`
|
|
3285
|
-
Done. Updated ${changedFiles} file(s): ${totalRewrittenFunctions} fetch function(s) rewritten, ${totalRenamedReferences} bare reference(s) renamed.`
|
|
3286
|
-
);
|
|
3287
|
-
if (totalRewrittenFunctions > 0) {
|
|
3288
|
-
console.log(
|
|
3289
|
-
`NOTE: rewriting fetch functions discards any custom logic that lived inside them. Review the diff and re-apply any country-specific adjustments on top of '${REPLACEMENT_IDENTIFIER}'.`
|
|
3290
|
-
);
|
|
3291
|
-
}
|
|
3292
|
-
}
|
|
3293
|
-
|
|
3294
|
-
// src/migrations/v2.0/remove-old-statistics-service.ts
|
|
3295
|
-
var import_path16 = __toESM(require("path"));
|
|
3296
|
-
var import_ts_morph16 = require("ts-morph");
|
|
3297
|
-
var ROUTE_PATH = "/statistics";
|
|
3298
|
-
var HANDLER_NAME = "statisticsHandler";
|
|
3299
|
-
function isStatisticsRouteObject(obj) {
|
|
3300
|
-
const pathProp = obj.getProperty("path");
|
|
3301
|
-
if (!pathProp || !import_ts_morph16.Node.isPropertyAssignment(pathProp)) return false;
|
|
3302
|
-
const init = pathProp.getInitializer();
|
|
3303
|
-
if (!init) return false;
|
|
3304
|
-
if (import_ts_morph16.Node.isStringLiteral(init) || import_ts_morph16.Node.isNoSubstitutionTemplateLiteral(init)) {
|
|
3305
|
-
return init.getLiteralValue() === ROUTE_PATH;
|
|
3306
|
-
}
|
|
3307
|
-
return false;
|
|
3308
|
-
}
|
|
3309
|
-
function removeStatisticsRoutes(sourceFile) {
|
|
3310
|
-
let removed = 0;
|
|
3311
|
-
const callExpressions = [
|
|
3312
|
-
...sourceFile.getDescendantsOfKind(import_ts_morph16.SyntaxKind.CallExpression)
|
|
3313
|
-
];
|
|
3314
|
-
for (const call of callExpressions) {
|
|
3315
|
-
if (call.wasForgotten()) continue;
|
|
3316
|
-
const expr = call.getExpression();
|
|
3317
|
-
if (!import_ts_morph16.Node.isPropertyAccessExpression(expr)) continue;
|
|
3318
|
-
if (expr.getName() !== "route") continue;
|
|
3319
|
-
const args = call.getArguments();
|
|
3320
|
-
if (args.length === 0) continue;
|
|
3321
|
-
const firstArg = args[0];
|
|
3322
|
-
if (import_ts_morph16.Node.isObjectLiteralExpression(firstArg)) {
|
|
3323
|
-
if (!isStatisticsRouteObject(firstArg)) continue;
|
|
3324
|
-
const stmt = call.getFirstAncestorByKind(import_ts_morph16.SyntaxKind.ExpressionStatement);
|
|
3325
|
-
if (stmt) {
|
|
3326
|
-
stmt.remove();
|
|
3327
|
-
removed++;
|
|
3328
|
-
} else {
|
|
3329
|
-
call.replaceWithText("");
|
|
3330
|
-
removed++;
|
|
3331
|
-
}
|
|
3332
|
-
continue;
|
|
3333
|
-
}
|
|
3334
|
-
if (import_ts_morph16.Node.isArrayLiteralExpression(firstArg)) {
|
|
3335
|
-
const matchingIndexes = firstArg.getElements().map((el, idx) => ({ el, idx })).filter(
|
|
3336
|
-
({ el }) => import_ts_morph16.Node.isObjectLiteralExpression(el) && isStatisticsRouteObject(el)
|
|
3337
|
-
).map(({ idx }) => idx);
|
|
3338
|
-
matchingIndexes.sort((a, b) => b - a).forEach((idx) => {
|
|
3339
|
-
firstArg.removeElement(idx);
|
|
3340
|
-
removed++;
|
|
3341
|
-
});
|
|
3342
|
-
}
|
|
3343
|
-
}
|
|
3344
|
-
return removed;
|
|
3345
|
-
}
|
|
3346
|
-
function removeStatisticsHandlerImports(sourceFile) {
|
|
3347
|
-
let changed = false;
|
|
3348
|
-
for (const decl of sourceFile.getImportDeclarations()) {
|
|
3349
|
-
const targetNamed = decl.getNamedImports().find((ni) => ni.getName() === HANDLER_NAME);
|
|
3350
|
-
if (!targetNamed) continue;
|
|
3351
|
-
targetNamed.remove();
|
|
3352
|
-
changed = true;
|
|
3353
|
-
const isNowEmpty = decl.getNamedImports().length === 0 && !decl.getDefaultImport() && !decl.getNamespaceImport();
|
|
3354
|
-
if (isNowEmpty) decl.remove();
|
|
3355
|
-
}
|
|
3356
|
-
return changed;
|
|
3357
|
-
}
|
|
3358
|
-
function processFile12(sourceFile) {
|
|
3359
|
-
const routesRemoved = removeStatisticsRoutes(sourceFile);
|
|
3360
|
-
const importsCleaned = removeStatisticsHandlerImports(sourceFile);
|
|
3361
|
-
return { routesRemoved, importsCleaned };
|
|
3362
|
-
}
|
|
3363
|
-
function collectLocalImportsInSubtree(sourceFile, subtreeRoot) {
|
|
3364
|
-
const result = [];
|
|
3365
|
-
for (const decl of sourceFile.getImportDeclarations()) {
|
|
3366
|
-
const moduleSf = decl.getModuleSpecifierSourceFile();
|
|
3367
|
-
if (!moduleSf) continue;
|
|
3368
|
-
const fp = moduleSf.getFilePath();
|
|
3369
|
-
if (!fp.startsWith(subtreeRoot)) continue;
|
|
3370
|
-
result.push(fp);
|
|
3371
|
-
}
|
|
3372
|
-
return result;
|
|
3373
|
-
}
|
|
3374
|
-
function deleteOrphanedDescendants(project, startingFile, subtreeRoot) {
|
|
3375
|
-
const initialCandidates = collectLocalImportsInSubtree(
|
|
3376
|
-
startingFile,
|
|
3377
|
-
subtreeRoot
|
|
3378
|
-
);
|
|
3379
|
-
const startingPath = startingFile.getFilePath();
|
|
3380
|
-
const deleted = /* @__PURE__ */ new Set([startingPath]);
|
|
3381
|
-
const seen = /* @__PURE__ */ new Set();
|
|
3382
|
-
const worklist = [...initialCandidates];
|
|
3383
|
-
const orphans = [];
|
|
3384
|
-
while (worklist.length > 0) {
|
|
3385
|
-
const candidate = worklist.shift();
|
|
3386
|
-
if (seen.has(candidate)) continue;
|
|
3387
|
-
seen.add(candidate);
|
|
3388
|
-
if (deleted.has(candidate)) continue;
|
|
3389
|
-
if (!candidate.startsWith(subtreeRoot)) continue;
|
|
3390
|
-
const candidateSf = project.getSourceFile(candidate);
|
|
3391
|
-
if (!candidateSf) continue;
|
|
3392
|
-
const stillImported = project.getSourceFiles().some((sf) => {
|
|
3393
|
-
const sfPath = sf.getFilePath();
|
|
3394
|
-
if (deleted.has(sfPath)) return false;
|
|
3395
|
-
if (sfPath === candidate) return false;
|
|
3396
|
-
return sf.getImportDeclarations().some(
|
|
3397
|
-
(decl) => decl.getModuleSpecifierSourceFile()?.getFilePath() === candidate
|
|
3398
|
-
);
|
|
3399
|
-
});
|
|
3400
|
-
if (stillImported) continue;
|
|
3401
|
-
const next = collectLocalImportsInSubtree(candidateSf, subtreeRoot);
|
|
3402
|
-
worklist.push(...next);
|
|
3403
|
-
candidateSf.delete();
|
|
3404
|
-
deleted.add(candidate);
|
|
3405
|
-
orphans.push(candidate);
|
|
3406
|
-
}
|
|
3407
|
-
return orphans;
|
|
3408
|
-
}
|
|
3409
|
-
function processHandlerFile(project) {
|
|
3410
|
-
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
3411
|
-
const fp = sf.getFilePath();
|
|
3412
|
-
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
3413
|
-
});
|
|
3414
|
-
for (const sf of sourceFiles) {
|
|
3415
|
-
const fn = sf.getFunction(HANDLER_NAME);
|
|
3416
|
-
if (!fn) continue;
|
|
3417
|
-
const filePath = sf.getFilePath();
|
|
3418
|
-
const exportsByName = [...sf.getExportedDeclarations().keys()];
|
|
3419
|
-
const otherExports = exportsByName.filter((name) => name !== HANDLER_NAME);
|
|
3420
|
-
if (otherExports.length === 0) {
|
|
3421
|
-
const subtreeRoot = import_path16.default.dirname(filePath) + import_path16.default.sep;
|
|
3422
|
-
const orphansDeleted = deleteOrphanedDescendants(
|
|
3423
|
-
project,
|
|
3424
|
-
sf,
|
|
3425
|
-
subtreeRoot
|
|
3426
|
-
);
|
|
3427
|
-
sf.delete();
|
|
3428
|
-
return { filePath, action: "deleted", orphansDeleted };
|
|
3429
|
-
}
|
|
3430
|
-
fn.remove();
|
|
3431
|
-
return {
|
|
3432
|
-
filePath,
|
|
3433
|
-
action: "function-removed",
|
|
3434
|
-
remainingExports: otherExports,
|
|
3435
|
-
orphansDeleted: []
|
|
3436
|
-
};
|
|
3437
|
-
}
|
|
3438
|
-
return { filePath: "", action: "not-found", orphansDeleted: [] };
|
|
3439
|
-
}
|
|
3440
|
-
async function main16() {
|
|
3441
|
-
const project = new import_ts_morph16.Project({
|
|
3442
|
-
tsConfigFilePath: import_path16.default.resolve(process.cwd(), "tsconfig.json"),
|
|
3443
|
-
skipAddingFilesFromTsConfig: false
|
|
3444
|
-
});
|
|
3445
|
-
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
3446
|
-
const fp = sf.getFilePath();
|
|
3447
|
-
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
3448
|
-
});
|
|
3449
|
-
console.log(
|
|
3450
|
-
`Removing legacy 'GET ${ROUTE_PATH}' route and '${HANDLER_NAME}' across ${sourceFiles.length} source file(s)...
|
|
3451
|
-
`
|
|
3452
|
-
);
|
|
3453
|
-
let totalRoutesRemoved = 0;
|
|
3454
|
-
let totalFilesWithImportsCleaned = 0;
|
|
3455
|
-
let totalFilesWithRoutesRemoved = 0;
|
|
3456
|
-
for (const sourceFile of sourceFiles) {
|
|
3457
|
-
const filePath = sourceFile.getFilePath();
|
|
3458
|
-
const rel = import_path16.default.relative(process.cwd(), filePath);
|
|
3459
|
-
const result = processFile12(sourceFile);
|
|
3460
|
-
if (result.routesRemoved > 0) {
|
|
3461
|
-
console.log(
|
|
3462
|
-
` [${rel}] Removed ${result.routesRemoved} '${ROUTE_PATH}' route(s)`
|
|
3463
|
-
);
|
|
3464
|
-
totalRoutesRemoved += result.routesRemoved;
|
|
3465
|
-
totalFilesWithRoutesRemoved++;
|
|
3466
|
-
}
|
|
3467
|
-
if (result.importsCleaned) {
|
|
3468
|
-
console.log(` [${rel}] Cleaned up '${HANDLER_NAME}' import`);
|
|
3469
|
-
totalFilesWithImportsCleaned++;
|
|
3470
|
-
}
|
|
3471
|
-
if (result.routesRemoved > 0 || result.importsCleaned) {
|
|
3472
|
-
await sourceFile.save();
|
|
3473
|
-
}
|
|
3474
|
-
}
|
|
3475
|
-
const handlerResult = processHandlerFile(project);
|
|
3476
|
-
switch (handlerResult.action) {
|
|
3477
|
-
case "deleted": {
|
|
3478
|
-
const rel = import_path16.default.relative(process.cwd(), handlerResult.filePath);
|
|
3479
|
-
console.log(
|
|
3480
|
-
` [${rel}] Deleted handler file ('${HANDLER_NAME}' was the sole export).`
|
|
3481
|
-
);
|
|
3482
|
-
for (const orphanPath of handlerResult.orphansDeleted) {
|
|
3483
|
-
const orphanRel = import_path16.default.relative(process.cwd(), orphanPath);
|
|
3484
|
-
console.log(
|
|
3485
|
-
` [${orphanRel}] Deleted (no remaining importers in the project after handler removal).`
|
|
3486
|
-
);
|
|
3487
|
-
}
|
|
3488
|
-
await project.save();
|
|
3489
|
-
break;
|
|
3490
|
-
}
|
|
3491
|
-
case "function-removed": {
|
|
3492
|
-
const rel = import_path16.default.relative(process.cwd(), handlerResult.filePath);
|
|
3493
|
-
console.warn(
|
|
3494
|
-
` [${rel}] Removed '${HANDLER_NAME}' function but kept the file (other exports remain: ${handlerResult.remainingExports?.join(", ")}). Review whether the file is still needed.`
|
|
3495
|
-
);
|
|
3496
|
-
const sf = project.getSourceFile(handlerResult.filePath);
|
|
3497
|
-
if (sf) await sf.save();
|
|
3498
|
-
break;
|
|
3499
|
-
}
|
|
3500
|
-
case "not-found":
|
|
3501
|
-
break;
|
|
3502
|
-
}
|
|
3503
|
-
if (totalRoutesRemoved === 0 && totalFilesWithImportsCleaned === 0 && handlerResult.action === "not-found") {
|
|
3504
|
-
console.log(`
|
|
3505
|
-
No legacy '${ROUTE_PATH}' route or handler found. Nothing to do.`);
|
|
3506
|
-
return;
|
|
3507
|
-
}
|
|
3508
|
-
const orphansSummary = handlerResult.orphansDeleted.length > 0 ? ` and ${handlerResult.orphansDeleted.length} orphaned helper file(s)` : "";
|
|
3509
|
-
console.log(
|
|
3510
|
-
`
|
|
3511
|
-
Done. Removed ${totalRoutesRemoved} route(s) across ${totalFilesWithRoutesRemoved} file(s); cleaned ${HANDLER_NAME} import in ${totalFilesWithImportsCleaned} file(s)${orphansSummary}.`
|
|
3512
|
-
);
|
|
3513
|
-
}
|
|
3514
|
-
|
|
3515
|
-
// src/migrations/v2.0/update-package-json.ts
|
|
3516
|
-
var import_fs = require("fs");
|
|
3517
|
-
var import_path17 = __toESM(require("path"));
|
|
3518
|
-
var PACKAGE_JSON_RELATIVE = "package.json";
|
|
3519
|
-
var TARGET_VERSION = "2.0.0";
|
|
3520
|
-
var TARGET_ZOD_RANGE = "^4.2.1";
|
|
3521
|
-
async function main17() {
|
|
3522
|
-
const packageJsonPath = import_path17.default.join(process.cwd(), PACKAGE_JSON_RELATIVE);
|
|
3523
|
-
if (!(0, import_fs.existsSync)(packageJsonPath)) {
|
|
3524
|
-
console.log(`'${PACKAGE_JSON_RELATIVE}' not found in ${process.cwd()} \u2014 skipping.`);
|
|
3525
|
-
return;
|
|
3526
|
-
}
|
|
3527
|
-
const raw = (0, import_fs.readFileSync)(packageJsonPath, "utf8");
|
|
3528
|
-
let parsed;
|
|
3529
|
-
try {
|
|
3530
|
-
parsed = JSON.parse(raw);
|
|
3531
|
-
} catch (error) {
|
|
3532
|
-
console.warn(
|
|
3533
|
-
` [${PACKAGE_JSON_RELATIVE}] Failed to parse JSON \u2014 skipping update. ${error.message}`
|
|
3534
|
-
);
|
|
3535
|
-
return;
|
|
3536
|
-
}
|
|
3537
|
-
console.log(`Updating '${PACKAGE_JSON_RELATIVE}'...`);
|
|
3538
|
-
const previousVersion = parsed.version;
|
|
3539
|
-
const versionChanged = previousVersion !== TARGET_VERSION;
|
|
3540
|
-
parsed.version = TARGET_VERSION;
|
|
3541
|
-
if (versionChanged) {
|
|
3542
|
-
console.log(
|
|
3543
|
-
` Set version: ${previousVersion ?? "<unset>"} \u2192 ${TARGET_VERSION}`
|
|
3544
|
-
);
|
|
3545
|
-
} else {
|
|
3546
|
-
console.log(` Version already ${TARGET_VERSION} \u2014 no change.`);
|
|
3547
|
-
}
|
|
3548
|
-
let zodBucket = "dependencies";
|
|
3549
|
-
if (parsed.devDependencies && "zod" in parsed.devDependencies) {
|
|
3550
|
-
zodBucket = "devDependencies";
|
|
3551
|
-
}
|
|
3552
|
-
if (!parsed[zodBucket]) {
|
|
3553
|
-
parsed[zodBucket] = {};
|
|
3554
|
-
}
|
|
3555
|
-
const bucket = parsed[zodBucket];
|
|
3556
|
-
const previousZod = bucket.zod;
|
|
3557
|
-
const zodChanged = previousZod !== TARGET_ZOD_RANGE;
|
|
3558
|
-
bucket.zod = TARGET_ZOD_RANGE;
|
|
3559
|
-
if (zodChanged) {
|
|
3560
|
-
console.log(
|
|
3561
|
-
` Set ${zodBucket}.zod: ${previousZod ?? "<absent>"} \u2192 ${TARGET_ZOD_RANGE}`
|
|
3562
|
-
);
|
|
3563
|
-
} else {
|
|
3564
|
-
console.log(` ${zodBucket}.zod already ${TARGET_ZOD_RANGE} \u2014 no change.`);
|
|
3565
|
-
}
|
|
3566
|
-
const trailingNewline = raw.endsWith("\n") ? "\n" : "";
|
|
3567
|
-
const next = JSON.stringify(parsed, null, 2) + trailingNewline;
|
|
3568
|
-
if (next === raw) {
|
|
3569
|
-
console.log("\n No changes to write.");
|
|
3570
|
-
return;
|
|
3571
|
-
}
|
|
3572
|
-
(0, import_fs.writeFileSync)(packageJsonPath, next, "utf8");
|
|
3573
|
-
console.log(`
|
|
3574
|
-
Saved '${PACKAGE_JSON_RELATIVE}'.`);
|
|
3575
|
-
console.log(
|
|
3576
|
-
` NOTE: run \`yarn install\` (or your package manager equivalent) to install the updated dependency versions.`
|
|
3577
|
-
);
|
|
3578
|
-
}
|
|
3579
|
-
|
|
3580
2887
|
// src/migrations/v2.0/migrate-workqueue-configs.ts
|
|
3581
|
-
var
|
|
3582
|
-
var
|
|
2888
|
+
var import_ts_morph13 = require("ts-morph");
|
|
2889
|
+
var import_path13 = __toESM(require("path"));
|
|
3583
2890
|
var DEFINE_WORKQUEUES_NAME3 = "defineWorkqueues";
|
|
3584
2891
|
var ACTIONS_PROPERTY_NAME5 = "actions";
|
|
3585
2892
|
var ACTION_PROPERTY_NAME2 = "action";
|
|
@@ -3600,28 +2907,28 @@ var SUPPORTED_WORKQUEUE_ACTION_TYPES = /* @__PURE__ */ new Set([
|
|
|
3600
2907
|
]);
|
|
3601
2908
|
function getWorkqueueLabel(workqueue) {
|
|
3602
2909
|
const slugProperty = workqueue.getProperty(SLUG_PROPERTY_NAME);
|
|
3603
|
-
if (!slugProperty || !
|
|
2910
|
+
if (!slugProperty || !import_ts_morph13.Node.isPropertyAssignment(slugProperty)) {
|
|
3604
2911
|
return "(unknown slug)";
|
|
3605
2912
|
}
|
|
3606
2913
|
const slugInitializer = slugProperty.getInitializer();
|
|
3607
|
-
if (!slugInitializer || !
|
|
2914
|
+
if (!slugInitializer || !import_ts_morph13.Node.isStringLiteral(slugInitializer)) {
|
|
3608
2915
|
return "(unknown slug)";
|
|
3609
2916
|
}
|
|
3610
2917
|
return slugInitializer.getLiteralValue();
|
|
3611
2918
|
}
|
|
3612
2919
|
function getActionTypeName(action) {
|
|
3613
2920
|
const typeProperty = action.getProperty(TYPE_PROPERTY_NAME7);
|
|
3614
|
-
if (!typeProperty || !
|
|
2921
|
+
if (!typeProperty || !import_ts_morph13.Node.isPropertyAssignment(typeProperty)) {
|
|
3615
2922
|
return null;
|
|
3616
2923
|
}
|
|
3617
2924
|
const typeInitializer = typeProperty.getInitializer();
|
|
3618
2925
|
if (!typeInitializer) {
|
|
3619
2926
|
return null;
|
|
3620
2927
|
}
|
|
3621
|
-
if (
|
|
2928
|
+
if (import_ts_morph13.Node.isStringLiteral(typeInitializer)) {
|
|
3622
2929
|
return typeInitializer.getLiteralValue();
|
|
3623
2930
|
}
|
|
3624
|
-
if (
|
|
2931
|
+
if (import_ts_morph13.Node.isPropertyAccessExpression(typeInitializer)) {
|
|
3625
2932
|
return typeInitializer.getName();
|
|
3626
2933
|
}
|
|
3627
2934
|
return null;
|
|
@@ -3635,19 +2942,19 @@ function isUnsupportedActionType(action) {
|
|
|
3635
2942
|
}
|
|
3636
2943
|
function migrateWorkqueueActions(workqueue, relPath) {
|
|
3637
2944
|
const actionsProperty = workqueue.getProperty(ACTIONS_PROPERTY_NAME5);
|
|
3638
|
-
if (!actionsProperty || !
|
|
2945
|
+
if (!actionsProperty || !import_ts_morph13.Node.isPropertyAssignment(actionsProperty)) {
|
|
3639
2946
|
return 0;
|
|
3640
2947
|
}
|
|
3641
2948
|
const actionsInitializer = actionsProperty.getInitializer();
|
|
3642
|
-
if (!actionsInitializer || !
|
|
2949
|
+
if (!actionsInitializer || !import_ts_morph13.Node.isArrayLiteralExpression(actionsInitializer)) {
|
|
3643
2950
|
return 0;
|
|
3644
2951
|
}
|
|
3645
2952
|
const workqueueLabel = getWorkqueueLabel(workqueue);
|
|
3646
2953
|
const existingActionProperty = workqueue.getProperty(ACTION_PROPERTY_NAME2);
|
|
3647
2954
|
if (existingActionProperty) {
|
|
3648
|
-
if (
|
|
2955
|
+
if (import_ts_morph13.Node.isPropertyAssignment(existingActionProperty)) {
|
|
3649
2956
|
const existingActionInitializer = existingActionProperty.getInitializer();
|
|
3650
|
-
if (existingActionInitializer &&
|
|
2957
|
+
if (existingActionInitializer && import_ts_morph13.Node.isObjectLiteralExpression(existingActionInitializer)) {
|
|
3651
2958
|
const conditionalsProperty2 = existingActionInitializer.getProperty(
|
|
3652
2959
|
CONDITIONALS_PROPERTY_NAME
|
|
3653
2960
|
);
|
|
@@ -3672,7 +2979,7 @@ function migrateWorkqueueActions(workqueue, relPath) {
|
|
|
3672
2979
|
return 1;
|
|
3673
2980
|
}
|
|
3674
2981
|
const actionCandidates = actionsInitializer.getElements().filter(
|
|
3675
|
-
(element) =>
|
|
2982
|
+
(element) => import_ts_morph13.Node.isObjectLiteralExpression(element)
|
|
3676
2983
|
);
|
|
3677
2984
|
if (actionCandidates.length === 0) {
|
|
3678
2985
|
actionsProperty.remove();
|
|
@@ -3714,36 +3021,36 @@ function migrateWorkqueueActions(workqueue, relPath) {
|
|
|
3714
3021
|
);
|
|
3715
3022
|
return 1;
|
|
3716
3023
|
}
|
|
3717
|
-
function
|
|
3024
|
+
function processFile11(filePath, project) {
|
|
3718
3025
|
const sourceFile = project.getSourceFile(filePath);
|
|
3719
3026
|
if (!sourceFile) return 0;
|
|
3720
3027
|
let migratedWorkqueues = 0;
|
|
3721
|
-
const relPath =
|
|
3028
|
+
const relPath = import_path13.default.relative(getCwd(), filePath);
|
|
3722
3029
|
const callExpressions = sourceFile.getDescendantsOfKind(
|
|
3723
|
-
|
|
3030
|
+
import_ts_morph13.SyntaxKind.CallExpression
|
|
3724
3031
|
);
|
|
3725
3032
|
for (const call of callExpressions) {
|
|
3726
3033
|
const expression = call.getExpression();
|
|
3727
|
-
if (!
|
|
3034
|
+
if (!import_ts_morph13.Node.isIdentifier(expression) || expression.getText() !== DEFINE_WORKQUEUES_NAME3) {
|
|
3728
3035
|
continue;
|
|
3729
3036
|
}
|
|
3730
3037
|
const args = call.getArguments();
|
|
3731
3038
|
if (args.length === 0) continue;
|
|
3732
3039
|
const workqueuesArg = args[0];
|
|
3733
|
-
if (!
|
|
3040
|
+
if (!import_ts_morph13.Node.isArrayLiteralExpression(workqueuesArg)) continue;
|
|
3734
3041
|
for (const element of workqueuesArg.getElements()) {
|
|
3735
|
-
if (!
|
|
3042
|
+
if (!import_ts_morph13.Node.isObjectLiteralExpression(element)) continue;
|
|
3736
3043
|
migratedWorkqueues += migrateWorkqueueActions(element, relPath);
|
|
3737
3044
|
}
|
|
3738
3045
|
}
|
|
3739
3046
|
return migratedWorkqueues;
|
|
3740
3047
|
}
|
|
3741
|
-
async function
|
|
3742
|
-
const srcDir =
|
|
3048
|
+
async function main13() {
|
|
3049
|
+
const srcDir = import_path13.default.join(getCwd(), "src");
|
|
3743
3050
|
console.log(`Scanning for defineWorkqueues calls in: ${srcDir}
|
|
3744
3051
|
`);
|
|
3745
|
-
const project = new
|
|
3746
|
-
tsConfigFilePath:
|
|
3052
|
+
const project = new import_ts_morph13.Project({
|
|
3053
|
+
tsConfigFilePath: import_path13.default.resolve(srcDir, "../tsconfig.json"),
|
|
3747
3054
|
skipAddingFilesFromTsConfig: false
|
|
3748
3055
|
});
|
|
3749
3056
|
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
@@ -3756,7 +3063,7 @@ async function main18() {
|
|
|
3756
3063
|
const modifiedFiles = [];
|
|
3757
3064
|
for (const sourceFile of sourceFiles) {
|
|
3758
3065
|
const filePath = sourceFile.getFilePath();
|
|
3759
|
-
const migrated =
|
|
3066
|
+
const migrated = processFile11(filePath, project);
|
|
3760
3067
|
if (migrated > 0) {
|
|
3761
3068
|
totalMigrated += migrated;
|
|
3762
3069
|
modifiedFiles.push(filePath);
|
|
@@ -3773,7 +3080,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
3773
3080
|
for (const filePath of modifiedFiles) {
|
|
3774
3081
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
3775
3082
|
await sourceFile.save();
|
|
3776
|
-
console.log(` Saved: ${
|
|
3083
|
+
console.log(` Saved: ${import_path13.default.relative(getCwd(), filePath)}`);
|
|
3777
3084
|
}
|
|
3778
3085
|
console.log(
|
|
3779
3086
|
`
|
|
@@ -3782,13 +3089,13 @@ Done. Migrated ${totalMigrated} deprecated workqueue 'actions' definition(s) to
|
|
|
3782
3089
|
}
|
|
3783
3090
|
|
|
3784
3091
|
// src/migrations/v2.0/remove-demo-scope.ts
|
|
3785
|
-
var
|
|
3786
|
-
var
|
|
3092
|
+
var import_path14 = __toESM(require("path"));
|
|
3093
|
+
var import_ts_morph14 = require("ts-morph");
|
|
3787
3094
|
var ROLES_HANDLER_RELATIVE_PATH = "src/data-seeding/roles/handler.ts";
|
|
3788
|
-
async function
|
|
3789
|
-
const rolesHandlerPath =
|
|
3790
|
-
const project = new
|
|
3791
|
-
tsConfigFilePath:
|
|
3095
|
+
async function main14() {
|
|
3096
|
+
const rolesHandlerPath = import_path14.default.join(getCwd(), ROLES_HANDLER_RELATIVE_PATH);
|
|
3097
|
+
const project = new import_ts_morph14.Project({
|
|
3098
|
+
tsConfigFilePath: import_path14.default.resolve(getCwd(), "tsconfig.json"),
|
|
3792
3099
|
skipAddingFilesFromTsConfig: false
|
|
3793
3100
|
});
|
|
3794
3101
|
const sourceFile = project.getSourceFile(rolesHandlerPath);
|
|
@@ -3837,7 +3144,7 @@ async function main19() {
|
|
|
3837
3144
|
|
|
3838
3145
|
// src/migrations/v2.0/remove-hearth-migrations.ts
|
|
3839
3146
|
var fs2 = __toESM(require("fs"));
|
|
3840
|
-
var
|
|
3147
|
+
var import_path15 = __toESM(require("path"));
|
|
3841
3148
|
var PATHS_TO_REMOVE = [
|
|
3842
3149
|
{
|
|
3843
3150
|
relativePath: "src/migrations/hearth",
|
|
@@ -3849,9 +3156,9 @@ var PATHS_TO_REMOVE = [
|
|
|
3849
3156
|
},
|
|
3850
3157
|
{ relativePath: "src/utils/hearth-helpers.ts", label: "Hearth helpers file" }
|
|
3851
3158
|
];
|
|
3852
|
-
async function
|
|
3159
|
+
async function main15() {
|
|
3853
3160
|
for (const { relativePath, label } of PATHS_TO_REMOVE) {
|
|
3854
|
-
const absolutePath =
|
|
3161
|
+
const absolutePath = import_path15.default.join(getCwd(), relativePath);
|
|
3855
3162
|
if (fs2.existsSync(absolutePath)) {
|
|
3856
3163
|
fs2.rmSync(absolutePath, { recursive: true, force: true });
|
|
3857
3164
|
console.log(`Removed ${label} '${relativePath}'.`);
|
|
@@ -3862,9 +3169,9 @@ async function main20() {
|
|
|
3862
3169
|
}
|
|
3863
3170
|
|
|
3864
3171
|
// src/migrations/v2.0/create-events-index.ts
|
|
3865
|
-
var
|
|
3866
|
-
var
|
|
3867
|
-
var
|
|
3172
|
+
var import_ts_morph15 = require("ts-morph");
|
|
3173
|
+
var import_fs = __toESM(require("fs"));
|
|
3174
|
+
var import_path16 = __toESM(require("path"));
|
|
3868
3175
|
var DEFINE_CONFIG_NAME5 = "defineConfig";
|
|
3869
3176
|
var HANDLER_FUNCTION_NAMES = /* @__PURE__ */ new Set([
|
|
3870
3177
|
"getCustomEventsHandler",
|
|
@@ -3886,7 +3193,7 @@ var LICENSE_HEADER = `/*
|
|
|
3886
3193
|
`;
|
|
3887
3194
|
function findEventConfigExports(project, srcDir) {
|
|
3888
3195
|
const found = [];
|
|
3889
|
-
const eventsIndexAbs =
|
|
3196
|
+
const eventsIndexAbs = import_path16.default.join(srcDir, "events", "index.ts");
|
|
3890
3197
|
for (const sourceFile of project.getSourceFiles()) {
|
|
3891
3198
|
const filePath = sourceFile.getFilePath();
|
|
3892
3199
|
if (!filePath.startsWith(srcDir) || filePath.includes("/node_modules/")) {
|
|
@@ -3898,10 +3205,10 @@ function findEventConfigExports(project, srcDir) {
|
|
|
3898
3205
|
for (const decl of statement.getDeclarations()) {
|
|
3899
3206
|
const initializer = decl.getInitializer();
|
|
3900
3207
|
if (!initializer) continue;
|
|
3901
|
-
const unwrapped =
|
|
3902
|
-
if (!
|
|
3208
|
+
const unwrapped = import_ts_morph15.Node.isAsExpression(initializer) ? initializer.getExpression() : initializer;
|
|
3209
|
+
if (!import_ts_morph15.Node.isCallExpression(unwrapped)) continue;
|
|
3903
3210
|
const callee = unwrapped.getExpression();
|
|
3904
|
-
if (!
|
|
3211
|
+
if (!import_ts_morph15.Node.isIdentifier(callee)) continue;
|
|
3905
3212
|
if (callee.getText() !== DEFINE_CONFIG_NAME5) continue;
|
|
3906
3213
|
found.push({ name: decl.getName(), filePath });
|
|
3907
3214
|
}
|
|
@@ -3910,8 +3217,8 @@ function findEventConfigExports(project, srcDir) {
|
|
|
3910
3217
|
return found;
|
|
3911
3218
|
}
|
|
3912
3219
|
function buildIndexImportSpecifier(eventConfigFilePath, srcDir) {
|
|
3913
|
-
const eventsIndexDir =
|
|
3914
|
-
let rel =
|
|
3220
|
+
const eventsIndexDir = import_path16.default.join(srcDir, "events");
|
|
3221
|
+
let rel = import_path16.default.relative(eventsIndexDir, eventConfigFilePath).split(import_path16.default.sep).join("/");
|
|
3915
3222
|
if (rel.endsWith(".ts")) rel = rel.slice(0, -".ts".length);
|
|
3916
3223
|
if (rel.endsWith("/index")) rel = rel.slice(0, -"/index".length);
|
|
3917
3224
|
if (!rel.startsWith(".")) rel = "./" + rel;
|
|
@@ -3988,17 +3295,17 @@ function modifyHandler(sourceFile, exportNames) {
|
|
|
3988
3295
|
);
|
|
3989
3296
|
}
|
|
3990
3297
|
for (const call of sourceFile.getDescendantsOfKind(
|
|
3991
|
-
|
|
3298
|
+
import_ts_morph15.SyntaxKind.CallExpression
|
|
3992
3299
|
)) {
|
|
3993
3300
|
const callee = call.getExpression();
|
|
3994
|
-
if (!
|
|
3301
|
+
if (!import_ts_morph15.Node.isPropertyAccessExpression(callee)) continue;
|
|
3995
3302
|
if (callee.getName() !== RESPONSE_METHOD_NAME) continue;
|
|
3996
3303
|
const args = call.getArguments();
|
|
3997
3304
|
if (args.length !== 1) continue;
|
|
3998
3305
|
const [arg] = args;
|
|
3999
|
-
if (!
|
|
3306
|
+
if (!import_ts_morph15.Node.isArrayLiteralExpression(arg)) continue;
|
|
4000
3307
|
if (arg.getElements().length === 0) continue;
|
|
4001
|
-
if (!arg.getElements().every((el) =>
|
|
3308
|
+
if (!arg.getElements().every((el) => import_ts_morph15.Node.isIdentifier(el))) continue;
|
|
4002
3309
|
arg.replaceWithText(EVENT_CONFIGS_IDENTIFIER);
|
|
4003
3310
|
changes.push(
|
|
4004
3311
|
`rewrote h.response([...]) \u2192 h.response(${EVENT_CONFIGS_IDENTIFIER})`
|
|
@@ -4006,13 +3313,13 @@ function modifyHandler(sourceFile, exportNames) {
|
|
|
4006
3313
|
}
|
|
4007
3314
|
return changes;
|
|
4008
3315
|
}
|
|
4009
|
-
async function
|
|
4010
|
-
const
|
|
4011
|
-
const srcDir =
|
|
3316
|
+
async function main16() {
|
|
3317
|
+
const cwd2 = getCwd();
|
|
3318
|
+
const srcDir = import_path16.default.join(cwd2, "src");
|
|
4012
3319
|
console.log(`Scanning for defineConfig event exports in: ${srcDir}
|
|
4013
3320
|
`);
|
|
4014
|
-
const project = new
|
|
4015
|
-
tsConfigFilePath:
|
|
3321
|
+
const project = new import_ts_morph15.Project({
|
|
3322
|
+
tsConfigFilePath: import_path16.default.resolve(srcDir, "../tsconfig.json"),
|
|
4016
3323
|
skipAddingFilesFromTsConfig: false
|
|
4017
3324
|
});
|
|
4018
3325
|
const eventConfigExports = findEventConfigExports(project, srcDir);
|
|
@@ -4024,15 +3331,15 @@ async function main21() {
|
|
|
4024
3331
|
}
|
|
4025
3332
|
console.log(`Found ${eventConfigExports.length} event config export(s):`);
|
|
4026
3333
|
for (const e of eventConfigExports) {
|
|
4027
|
-
console.log(` ${e.name} \u2190 ${
|
|
3334
|
+
console.log(` ${e.name} \u2190 ${import_path16.default.relative(cwd2, e.filePath)}`);
|
|
4028
3335
|
}
|
|
4029
|
-
const eventsIndexAbs =
|
|
4030
|
-
const eventsIndexRel =
|
|
4031
|
-
if (
|
|
3336
|
+
const eventsIndexAbs = import_path16.default.join(srcDir, "events", "index.ts");
|
|
3337
|
+
const eventsIndexRel = import_path16.default.relative(cwd2, eventsIndexAbs);
|
|
3338
|
+
if (import_fs.default.existsSync(eventsIndexAbs)) {
|
|
4032
3339
|
console.log(`
|
|
4033
3340
|
[${eventsIndexRel}] already exists \u2014 leaving untouched.`);
|
|
4034
3341
|
} else {
|
|
4035
|
-
|
|
3342
|
+
import_fs.default.mkdirSync(import_path16.default.dirname(eventsIndexAbs), { recursive: true });
|
|
4036
3343
|
const source = buildEventsIndexSource(eventConfigExports, srcDir);
|
|
4037
3344
|
const eventsIndexFile = project.createSourceFile(eventsIndexAbs, source, {
|
|
4038
3345
|
overwrite: false
|
|
@@ -4053,7 +3360,7 @@ No event-config handler file found (looked for exported function(s): ${Array.fro
|
|
|
4053
3360
|
);
|
|
4054
3361
|
return;
|
|
4055
3362
|
}
|
|
4056
|
-
const handlerRelPath =
|
|
3363
|
+
const handlerRelPath = import_path16.default.relative(cwd2, handler.getFilePath());
|
|
4057
3364
|
const exportNameSet = new Set(eventConfigExports.map((e) => e.name));
|
|
4058
3365
|
const changes = modifyHandler(handler, exportNameSet);
|
|
4059
3366
|
if (changes.length === 0) {
|
|
@@ -4073,13 +3380,12 @@ var UPSTREAM_URL = "https://github.com/opencrvs/opencrvs-countryconfig.git";
|
|
|
4073
3380
|
var UPSTREAM_BRANCH = "develop";
|
|
4074
3381
|
var TEMP_REMOTE = "opencrvs-upgrade-v19-v20-codemod";
|
|
4075
3382
|
var FILES_TO_CHECKOUT = [
|
|
4076
|
-
"
|
|
4077
|
-
"
|
|
4078
|
-
"Dockerfile.assets"
|
|
3383
|
+
"infrastructure/postgres/setup-analytics.sh",
|
|
3384
|
+
"src/analytics/analytics.ts"
|
|
4079
3385
|
];
|
|
4080
3386
|
function runGit(args, { silent = false } = {}) {
|
|
4081
3387
|
return (0, import_child_process.execFileSync)("git", args, {
|
|
4082
|
-
cwd:
|
|
3388
|
+
cwd: getCwd(),
|
|
4083
3389
|
encoding: "utf8",
|
|
4084
3390
|
stdio: silent ? ["ignore", "pipe", "pipe"] : ["ignore", "pipe", "inherit"]
|
|
4085
3391
|
});
|
|
@@ -4095,11 +3401,11 @@ function tryGit(args) {
|
|
|
4095
3401
|
function assertIsGitRepo() {
|
|
4096
3402
|
if (!tryGit(["rev-parse", "--is-inside-work-tree"])) {
|
|
4097
3403
|
throw new Error(
|
|
4098
|
-
|
|
3404
|
+
`checkout-upstream-files: ${getCwd()} is not a git repository. Initialise git (or run the upgrade inside a git checkout) before re-running.`
|
|
4099
3405
|
);
|
|
4100
3406
|
}
|
|
4101
3407
|
}
|
|
4102
|
-
async function
|
|
3408
|
+
async function main17() {
|
|
4103
3409
|
console.log(
|
|
4104
3410
|
`Checking out ${FILES_TO_CHECKOUT.length} file(s) from ${UPSTREAM_URL}@${UPSTREAM_BRANCH}...
|
|
4105
3411
|
`
|
|
@@ -4147,356 +3453,10 @@ async function main22() {
|
|
|
4147
3453
|
}
|
|
4148
3454
|
}
|
|
4149
3455
|
|
|
4150
|
-
// src/migrations/v2.0/add-resend-invite-notification.ts
|
|
4151
|
-
var import_fs3 = require("fs");
|
|
4152
|
-
var import_path22 = __toESM(require("path"));
|
|
4153
|
-
var import_ts_morph20 = require("ts-morph");
|
|
4154
|
-
var TS_MORPH_PROJECT_OPTIONS = {
|
|
4155
|
-
skipAddingFilesFromTsConfig: true,
|
|
4156
|
-
manipulationSettings: {
|
|
4157
|
-
indentationText: import_ts_morph20.IndentationText.TwoSpaces
|
|
4158
|
-
}
|
|
4159
|
-
};
|
|
4160
|
-
var EMAIL_TEMPLATES_INDEX = "src/api/notification/email-templates/index.ts";
|
|
4161
|
-
var NOTIFICATION_HANDLER = "src/api/notification/handler.ts";
|
|
4162
|
-
var USER_NOTIFICATION_ROUTES = "src/config/routes/userNotificationRoutes.ts";
|
|
4163
|
-
var SMS_SERVICE = "src/api/notification/sms-service.ts";
|
|
4164
|
-
var NOTIFICATION_CSV = "src/translations/notification.csv";
|
|
4165
|
-
var RESEND_INVITE_HTML = "src/api/notification/email-templates/other/resend-invite.html";
|
|
4166
|
-
var RESEND_INVITE_HTML_CONTENT = `<!doctype html>
|
|
4167
|
-
<html>
|
|
4168
|
-
<head>
|
|
4169
|
-
<link
|
|
4170
|
-
href="https://fonts.googleapis.com/css2?family=Noto+Sans:wght@400;700&display=swap"
|
|
4171
|
-
rel="stylesheet"
|
|
4172
|
-
/>
|
|
4173
|
-
<style type="text/css">
|
|
4174
|
-
body {
|
|
4175
|
-
font-family: 'Noto Sans', sans-serif;
|
|
4176
|
-
color: #222;
|
|
4177
|
-
padding: 16px 24px;
|
|
4178
|
-
}
|
|
4179
|
-
|
|
4180
|
-
h1 {
|
|
4181
|
-
font-size: 21px;
|
|
4182
|
-
margin-top: 32px;
|
|
4183
|
-
margin-bottom: 36px;
|
|
4184
|
-
font-weight: 700;
|
|
4185
|
-
}
|
|
4186
|
-
|
|
4187
|
-
p {
|
|
4188
|
-
font-weight: 400;
|
|
4189
|
-
font-size: 16px;
|
|
4190
|
-
line-height: 1.8;
|
|
4191
|
-
margin-bottom: 24px;
|
|
4192
|
-
}
|
|
4193
|
-
|
|
4194
|
-
i {
|
|
4195
|
-
color: #666;
|
|
4196
|
-
font-weight: 400;
|
|
4197
|
-
font-size: 16px;
|
|
4198
|
-
}
|
|
4199
|
-
</style>
|
|
4200
|
-
</head>
|
|
4201
|
-
|
|
4202
|
-
<body>
|
|
4203
|
-
<img
|
|
4204
|
-
src="{{countryLogo}}"
|
|
4205
|
-
alt="country_logo"
|
|
4206
|
-
style="max-height: 88px; max-width: 100%"
|
|
4207
|
-
/>
|
|
4208
|
-
<h1>Your {{applicationName}} account invitation</h1>
|
|
4209
|
-
<p>Hello {{firstname}},</p>
|
|
4210
|
-
<p>Your account invitation has been resent. Please use the following credentials to access your account:</p>
|
|
4211
|
-
<p>
|
|
4212
|
-
Username: <strong>{{username}}</strong><br />
|
|
4213
|
-
Password: <strong>{{temporaryPassword}}</strong>
|
|
4214
|
-
</p>
|
|
4215
|
-
<p>
|
|
4216
|
-
Please click the link below to complete your account setup and start using
|
|
4217
|
-
{{applicationName}}.
|
|
4218
|
-
</p>
|
|
4219
|
-
|
|
4220
|
-
<div style="margin-top: 32px; margin-bottom: 32px">
|
|
4221
|
-
<a href="{{loginURL}}">Complete setup</a>
|
|
4222
|
-
</div>
|
|
4223
|
-
<br />
|
|
4224
|
-
<p>
|
|
4225
|
-
Best regards, <br />
|
|
4226
|
-
{{applicationName}} Team
|
|
4227
|
-
</p>
|
|
4228
|
-
</body>
|
|
4229
|
-
</html>
|
|
4230
|
-
`;
|
|
4231
|
-
var CSV_ROW = "resendInviteNotification,The SMS message that is sent when a user invitation is resent,Your OpenCRVS account invitation was resent. Please login with your username: {{username}} and temporary password: {{temporaryPassword}},Votre invitation de compte OpenCRVS a \xE9t\xE9 renvoy\xE9e. Veuillez vous connecter avec votre nom d'utilisateur : {{username}} et votre mot de passe temporaire : {{temporaryPassword}}.\n";
|
|
4232
|
-
function getObjectLiteralFromConst(declaration) {
|
|
4233
|
-
if (!declaration) {
|
|
4234
|
-
return;
|
|
4235
|
-
}
|
|
4236
|
-
const initializer = declaration.getInitializer();
|
|
4237
|
-
if (!initializer) {
|
|
4238
|
-
return;
|
|
4239
|
-
}
|
|
4240
|
-
if (import_ts_morph20.Node.isObjectLiteralExpression(initializer)) {
|
|
4241
|
-
return initializer;
|
|
4242
|
-
}
|
|
4243
|
-
if (import_ts_morph20.Node.isAsExpression(initializer)) {
|
|
4244
|
-
const expression = initializer.getExpression();
|
|
4245
|
-
if (import_ts_morph20.Node.isObjectLiteralExpression(expression)) {
|
|
4246
|
-
return expression;
|
|
4247
|
-
}
|
|
4248
|
-
}
|
|
4249
|
-
if (import_ts_morph20.Node.isSatisfiesExpression(initializer)) {
|
|
4250
|
-
const expression = initializer.getExpression();
|
|
4251
|
-
if (import_ts_morph20.Node.isObjectLiteralExpression(expression)) {
|
|
4252
|
-
return expression;
|
|
4253
|
-
}
|
|
4254
|
-
}
|
|
4255
|
-
}
|
|
4256
|
-
function patchEmailTemplatesIndex() {
|
|
4257
|
-
const full = import_path22.default.join(process.cwd(), EMAIL_TEMPLATES_INDEX);
|
|
4258
|
-
if (!(0, import_fs3.existsSync)(full)) {
|
|
4259
|
-
console.log(` '${EMAIL_TEMPLATES_INDEX}' missing \u2014 skipping.`);
|
|
4260
|
-
return false;
|
|
4261
|
-
}
|
|
4262
|
-
const project = new import_ts_morph20.Project(TS_MORPH_PROJECT_OPTIONS);
|
|
4263
|
-
const sourceFile = project.addSourceFileAtPath(full);
|
|
4264
|
-
let changed = false;
|
|
4265
|
-
const triggerVariableObject = getObjectLiteralFromConst(
|
|
4266
|
-
sourceFile.getVariableDeclaration("TriggerVariable")
|
|
4267
|
-
);
|
|
4268
|
-
if (triggerVariableObject) {
|
|
4269
|
-
const hasResendInviteVariable = triggerVariableObject.getProperties().some((prop) => prop.getText().includes("[TriggerEvent.RESEND_INVITE]"));
|
|
4270
|
-
if (!hasResendInviteVariable) {
|
|
4271
|
-
const properties = triggerVariableObject.getProperties();
|
|
4272
|
-
const lastProperty = properties[properties.length - 1];
|
|
4273
|
-
if (lastProperty) {
|
|
4274
|
-
sourceFile.insertText(
|
|
4275
|
-
lastProperty.getEnd(),
|
|
4276
|
-
`,
|
|
4277
|
-
[TriggerEvent.RESEND_INVITE]: z.object({
|
|
4278
|
-
firstname: z.string(),
|
|
4279
|
-
username: z.string(),
|
|
4280
|
-
temporaryPassword: z.string(),
|
|
4281
|
-
completeSetupUrl: z.string(),
|
|
4282
|
-
loginURL: z.string()
|
|
4283
|
-
})`
|
|
4284
|
-
);
|
|
4285
|
-
changed = true;
|
|
4286
|
-
}
|
|
4287
|
-
}
|
|
4288
|
-
}
|
|
4289
|
-
const templatesObject = getObjectLiteralFromConst(
|
|
4290
|
-
sourceFile.getVariableDeclaration("templates")
|
|
4291
|
-
);
|
|
4292
|
-
if (templatesObject) {
|
|
4293
|
-
const hasResendInviteTemplate = templatesObject.getProperties().some(
|
|
4294
|
-
(prop) => prop.getText().includes("readOtherTemplate<TriggerVariable['resend-invite']>")
|
|
4295
|
-
);
|
|
4296
|
-
if (!hasResendInviteTemplate) {
|
|
4297
|
-
const userCreatedProp = templatesObject.getProperties().find((prop) => prop.getText().includes("[TriggerEvent.USER_CREATED]"));
|
|
4298
|
-
const anchor = userCreatedProp ?? templatesObject.getProperties()[templatesObject.getProperties().length - 1];
|
|
4299
|
-
if (anchor) {
|
|
4300
|
-
sourceFile.insertText(
|
|
4301
|
-
anchor.getEnd(),
|
|
4302
|
-
`,
|
|
4303
|
-
[TriggerEvent.RESEND_INVITE]: {
|
|
4304
|
-
type: 'resend-invite',
|
|
4305
|
-
subject: 'Your OpenCRVS account invitation',
|
|
4306
|
-
template:
|
|
4307
|
-
readOtherTemplate<TriggerVariable['resend-invite']>('resend-invite')
|
|
4308
|
-
}`
|
|
4309
|
-
);
|
|
4310
|
-
changed = true;
|
|
4311
|
-
}
|
|
4312
|
-
}
|
|
4313
|
-
}
|
|
4314
|
-
if (changed) {
|
|
4315
|
-
sourceFile.saveSync();
|
|
4316
|
-
}
|
|
4317
|
-
return changed;
|
|
4318
|
-
}
|
|
4319
|
-
function patchNotificationHandler() {
|
|
4320
|
-
const full = import_path22.default.join(process.cwd(), NOTIFICATION_HANDLER);
|
|
4321
|
-
if (!(0, import_fs3.existsSync)(full)) {
|
|
4322
|
-
return false;
|
|
4323
|
-
}
|
|
4324
|
-
const project = new import_ts_morph20.Project(TS_MORPH_PROJECT_OPTIONS);
|
|
4325
|
-
const sourceFile = project.addSourceFileAtPath(full);
|
|
4326
|
-
const convertFn = sourceFile.getFunction("convertPayloadToVariable");
|
|
4327
|
-
if (!convertFn) {
|
|
4328
|
-
return false;
|
|
4329
|
-
}
|
|
4330
|
-
const switchStmt = convertFn.getFirstDescendantByKind(
|
|
4331
|
-
import_ts_morph20.SyntaxKind.SwitchStatement
|
|
4332
|
-
);
|
|
4333
|
-
if (!switchStmt) {
|
|
4334
|
-
return false;
|
|
4335
|
-
}
|
|
4336
|
-
const clauses = switchStmt.getCaseBlock().getClauses();
|
|
4337
|
-
const hasResendInvite = clauses.some(
|
|
4338
|
-
(clause) => import_ts_morph20.Node.isCaseClause(clause) && clause.getExpression().getText() === "TriggerEvent.RESEND_INVITE"
|
|
4339
|
-
);
|
|
4340
|
-
if (hasResendInvite) {
|
|
4341
|
-
return false;
|
|
4342
|
-
}
|
|
4343
|
-
const userCreatedClauseIndex = clauses.findIndex(
|
|
4344
|
-
(clause) => import_ts_morph20.Node.isCaseClause(clause) && clause.getExpression().getText() === "TriggerEvent.USER_CREATED"
|
|
4345
|
-
);
|
|
4346
|
-
if (userCreatedClauseIndex < 0) {
|
|
4347
|
-
return false;
|
|
4348
|
-
}
|
|
4349
|
-
const userCreatedClause = clauses[userCreatedClauseIndex];
|
|
4350
|
-
sourceFile.insertText(
|
|
4351
|
-
userCreatedClause.getEnd(),
|
|
4352
|
-
`
|
|
4353
|
-
|
|
4354
|
-
case TriggerEvent.RESEND_INVITE:
|
|
4355
|
-
return {
|
|
4356
|
-
firstname,
|
|
4357
|
-
username: payload.username,
|
|
4358
|
-
temporaryPassword: payload.temporaryPassword,
|
|
4359
|
-
completeSetupUrl: LOGIN_URL,
|
|
4360
|
-
loginURL: LOGIN_URL
|
|
4361
|
-
}`
|
|
4362
|
-
);
|
|
4363
|
-
sourceFile.saveSync();
|
|
4364
|
-
return true;
|
|
4365
|
-
}
|
|
4366
|
-
function getReturnedArrayLiteral(functionFilePath, fnName) {
|
|
4367
|
-
const project = new import_ts_morph20.Project(TS_MORPH_PROJECT_OPTIONS);
|
|
4368
|
-
const sourceFile = project.addSourceFileAtPath(functionFilePath);
|
|
4369
|
-
const fn = sourceFile.getFunction(fnName);
|
|
4370
|
-
const returnStmt = fn?.getFirstDescendantByKind(import_ts_morph20.SyntaxKind.ReturnStatement);
|
|
4371
|
-
const expr = returnStmt?.getExpression();
|
|
4372
|
-
if (!expr || !import_ts_morph20.Node.isArrayLiteralExpression(expr)) {
|
|
4373
|
-
return { sourceFile, arrayLiteral: void 0 };
|
|
4374
|
-
}
|
|
4375
|
-
return { sourceFile, arrayLiteral: expr };
|
|
4376
|
-
}
|
|
4377
|
-
function patchUserNotificationRoutes() {
|
|
4378
|
-
const full = import_path22.default.join(process.cwd(), USER_NOTIFICATION_ROUTES);
|
|
4379
|
-
if (!(0, import_fs3.existsSync)(full)) {
|
|
4380
|
-
return false;
|
|
4381
|
-
}
|
|
4382
|
-
const { sourceFile, arrayLiteral } = getReturnedArrayLiteral(
|
|
4383
|
-
full,
|
|
4384
|
-
"getUserNotificationRoutes"
|
|
4385
|
-
);
|
|
4386
|
-
if (!arrayLiteral) {
|
|
4387
|
-
return false;
|
|
4388
|
-
}
|
|
4389
|
-
const elements = arrayLiteral.getElements();
|
|
4390
|
-
const routeExists = elements.some(
|
|
4391
|
-
(element) => element.getText().includes(`path: '/triggers/user/resend-invite'`)
|
|
4392
|
-
);
|
|
4393
|
-
if (routeExists) {
|
|
4394
|
-
return false;
|
|
4395
|
-
}
|
|
4396
|
-
const anchor = elements.find(
|
|
4397
|
-
(element) => element.getText().includes(`path: '/triggers/user/user-created'`)
|
|
4398
|
-
) ?? elements[elements.length - 1];
|
|
4399
|
-
if (!anchor) {
|
|
4400
|
-
return false;
|
|
4401
|
-
}
|
|
4402
|
-
sourceFile.insertText(
|
|
4403
|
-
anchor.getEnd(),
|
|
4404
|
-
`,
|
|
4405
|
-
{
|
|
4406
|
-
method: 'POST',
|
|
4407
|
-
path: '/triggers/user/resend-invite',
|
|
4408
|
-
handler: makeNotificationHandler('resend-invite'),
|
|
4409
|
-
options: {
|
|
4410
|
-
auth: false,
|
|
4411
|
-
tags: ['api'],
|
|
4412
|
-
description: 'Handles notification for resent user invite'
|
|
4413
|
-
}
|
|
4414
|
-
}`
|
|
4415
|
-
);
|
|
4416
|
-
sourceFile.saveSync();
|
|
4417
|
-
return true;
|
|
4418
|
-
}
|
|
4419
|
-
function patchSmsService() {
|
|
4420
|
-
const full = import_path22.default.join(process.cwd(), SMS_SERVICE);
|
|
4421
|
-
if (!(0, import_fs3.existsSync)(full)) {
|
|
4422
|
-
return false;
|
|
4423
|
-
}
|
|
4424
|
-
const project = new import_ts_morph20.Project(TS_MORPH_PROJECT_OPTIONS);
|
|
4425
|
-
const sourceFile = project.addSourceFileAtPath(full);
|
|
4426
|
-
let changed = false;
|
|
4427
|
-
const otherTemplatesObject = getObjectLiteralFromConst(
|
|
4428
|
-
sourceFile.getVariableDeclaration("otherTemplates")
|
|
4429
|
-
);
|
|
4430
|
-
if (otherTemplatesObject) {
|
|
4431
|
-
const hasResendTemplate = otherTemplatesObject.getProperties().some((prop) => prop.getText().includes("resendInviteNotification"));
|
|
4432
|
-
if (!hasResendTemplate) {
|
|
4433
|
-
const userCredentialsIndex = otherTemplatesObject.getProperties().findIndex((prop) => prop.getText().includes("userCredentialsNotification"));
|
|
4434
|
-
otherTemplatesObject.insertPropertyAssignment(
|
|
4435
|
-
userCredentialsIndex >= 0 ? userCredentialsIndex + 1 : otherTemplatesObject.getProperties().length,
|
|
4436
|
-
{
|
|
4437
|
-
name: "resendInviteNotification",
|
|
4438
|
-
initializer: `'resendInviteNotification'`
|
|
4439
|
-
}
|
|
4440
|
-
);
|
|
4441
|
-
changed = true;
|
|
4442
|
-
}
|
|
4443
|
-
}
|
|
4444
|
-
const triggerToSmsTemplateObject = getObjectLiteralFromConst(
|
|
4445
|
-
sourceFile.getVariableDeclaration("TriggerToSMSTemplate")
|
|
4446
|
-
);
|
|
4447
|
-
if (triggerToSmsTemplateObject) {
|
|
4448
|
-
const hasResendInviteMap = triggerToSmsTemplateObject.getProperties().some((prop) => prop.getText().includes(`['resend-invite']`));
|
|
4449
|
-
if (!hasResendInviteMap) {
|
|
4450
|
-
const userCreatedIndex = triggerToSmsTemplateObject.getProperties().findIndex((prop) => prop.getText().includes(`['user-created']`));
|
|
4451
|
-
triggerToSmsTemplateObject.insertPropertyAssignment(
|
|
4452
|
-
userCreatedIndex >= 0 ? userCreatedIndex + 1 : triggerToSmsTemplateObject.getProperties().length,
|
|
4453
|
-
{
|
|
4454
|
-
name: `['resend-invite']`,
|
|
4455
|
-
initializer: `'resendInviteNotification'`
|
|
4456
|
-
}
|
|
4457
|
-
);
|
|
4458
|
-
changed = true;
|
|
4459
|
-
}
|
|
4460
|
-
}
|
|
4461
|
-
if (changed) {
|
|
4462
|
-
sourceFile.saveSync();
|
|
4463
|
-
}
|
|
4464
|
-
return changed;
|
|
4465
|
-
}
|
|
4466
|
-
async function main23() {
|
|
4467
|
-
console.log("Adding RESEND_INVITE notification wiring\u2026");
|
|
4468
|
-
const touched = [];
|
|
4469
|
-
if (patchEmailTemplatesIndex()) touched.push(EMAIL_TEMPLATES_INDEX);
|
|
4470
|
-
if (patchNotificationHandler()) touched.push(NOTIFICATION_HANDLER);
|
|
4471
|
-
if (patchUserNotificationRoutes()) touched.push(USER_NOTIFICATION_ROUTES);
|
|
4472
|
-
if (patchSmsService()) touched.push(SMS_SERVICE);
|
|
4473
|
-
const csvPath = import_path22.default.join(process.cwd(), NOTIFICATION_CSV);
|
|
4474
|
-
if ((0, import_fs3.existsSync)(csvPath)) {
|
|
4475
|
-
let t = (0, import_fs3.readFileSync)(csvPath, "utf8");
|
|
4476
|
-
if (!/^resendInviteNotification,/m.test(t)) {
|
|
4477
|
-
if (!t.endsWith("\n")) t += "\n";
|
|
4478
|
-
(0, import_fs3.writeFileSync)(csvPath, t + CSV_ROW);
|
|
4479
|
-
touched.push(NOTIFICATION_CSV);
|
|
4480
|
-
}
|
|
4481
|
-
}
|
|
4482
|
-
const htmlPath = import_path22.default.join(process.cwd(), RESEND_INVITE_HTML);
|
|
4483
|
-
(0, import_fs3.mkdirSync)(import_path22.default.dirname(htmlPath), { recursive: true });
|
|
4484
|
-
if (!(0, import_fs3.existsSync)(htmlPath)) {
|
|
4485
|
-
(0, import_fs3.writeFileSync)(htmlPath, RESEND_INVITE_HTML_CONTENT);
|
|
4486
|
-
touched.push(RESEND_INVITE_HTML);
|
|
4487
|
-
}
|
|
4488
|
-
if (touched.length === 0) {
|
|
4489
|
-
console.log(" Nothing to update (already present or anchors not found).");
|
|
4490
|
-
return;
|
|
4491
|
-
}
|
|
4492
|
-
console.log(` Updated:
|
|
4493
|
-
${touched.map((f) => ` - ${f}`).join("\n")}`);
|
|
4494
|
-
}
|
|
4495
|
-
|
|
4496
3456
|
// src/migrations/v2.0/simplify-analytics-precalculations.ts
|
|
4497
|
-
var
|
|
4498
|
-
var
|
|
4499
|
-
var
|
|
3457
|
+
var import_ts_morph16 = require("ts-morph");
|
|
3458
|
+
var import_fs2 = __toESM(require("fs"));
|
|
3459
|
+
var import_path17 = __toESM(require("path"));
|
|
4500
3460
|
var ANALYTICS_FILE_REL = "src/analytics/analytics.ts";
|
|
4501
3461
|
var FUNCTION_NAME = "precalculateAdditionalAnalytics";
|
|
4502
3462
|
var IMPORT_NAMES_TO_REMOVE = /* @__PURE__ */ new Set(["Event", "precalculateBirthEvent"]);
|
|
@@ -4532,10 +3492,10 @@ function findPrecalculateFunction(sourceFile) {
|
|
|
4532
3492
|
return void 0;
|
|
4533
3493
|
}
|
|
4534
3494
|
function getFunctionBodyBlock(fn) {
|
|
4535
|
-
if (
|
|
3495
|
+
if (import_ts_morph16.Node.isFunctionDeclaration(fn)) return fn.getBody();
|
|
4536
3496
|
const initializer = fn.getInitializer();
|
|
4537
3497
|
if (!initializer) return void 0;
|
|
4538
|
-
if (!
|
|
3498
|
+
if (!import_ts_morph16.Node.isArrowFunction(initializer) && !import_ts_morph16.Node.isFunctionExpression(initializer)) {
|
|
4539
3499
|
return void 0;
|
|
4540
3500
|
}
|
|
4541
3501
|
return initializer.getBody();
|
|
@@ -4545,9 +3505,9 @@ function simplifyPrecalculateFunction(sourceFile) {
|
|
|
4545
3505
|
const fn = findPrecalculateFunction(sourceFile);
|
|
4546
3506
|
if (!fn) return log;
|
|
4547
3507
|
const body = getFunctionBodyBlock(fn);
|
|
4548
|
-
if (!body || !
|
|
3508
|
+
if (!body || !import_ts_morph16.Node.isBlock(body)) return log;
|
|
4549
3509
|
for (const statement of [...body.getStatements()]) {
|
|
4550
|
-
const references = statement.getDescendantsOfKind(
|
|
3510
|
+
const references = statement.getDescendantsOfKind(import_ts_morph16.SyntaxKind.Identifier).some((id) => IMPORT_NAMES_TO_REMOVE.has(id.getText()));
|
|
4551
3511
|
if (references) {
|
|
4552
3512
|
statement.remove();
|
|
4553
3513
|
log.push(`removed statement in ${FUNCTION_NAME} referencing removed imports`);
|
|
@@ -4555,7 +3515,7 @@ function simplifyPrecalculateFunction(sourceFile) {
|
|
|
4555
3515
|
}
|
|
4556
3516
|
const remaining = body.getStatements();
|
|
4557
3517
|
const last = remaining[remaining.length - 1];
|
|
4558
|
-
const alreadyCorrect = last &&
|
|
3518
|
+
const alreadyCorrect = last && import_ts_morph16.Node.isReturnStatement(last) && last.getExpression()?.getText() === RETURN_EXPRESSION_TEXT;
|
|
4559
3519
|
if (!alreadyCorrect) {
|
|
4560
3520
|
body.addStatements(`return ${RETURN_EXPRESSION_TEXT}`);
|
|
4561
3521
|
log.push(
|
|
@@ -4564,17 +3524,17 @@ function simplifyPrecalculateFunction(sourceFile) {
|
|
|
4564
3524
|
}
|
|
4565
3525
|
return log;
|
|
4566
3526
|
}
|
|
4567
|
-
async function
|
|
4568
|
-
const
|
|
4569
|
-
const absPath =
|
|
4570
|
-
if (!
|
|
3527
|
+
async function main18() {
|
|
3528
|
+
const cwd2 = getCwd();
|
|
3529
|
+
const absPath = import_path17.default.join(cwd2, ANALYTICS_FILE_REL);
|
|
3530
|
+
if (!import_fs2.default.existsSync(absPath)) {
|
|
4571
3531
|
console.log(
|
|
4572
3532
|
`[${ANALYTICS_FILE_REL}] does not exist \u2014 nothing to clean up.`
|
|
4573
3533
|
);
|
|
4574
3534
|
return;
|
|
4575
3535
|
}
|
|
4576
|
-
const project = new
|
|
4577
|
-
tsConfigFilePath:
|
|
3536
|
+
const project = new import_ts_morph16.Project({
|
|
3537
|
+
tsConfigFilePath: import_path17.default.resolve(cwd2, "tsconfig.json"),
|
|
4578
3538
|
skipAddingFilesFromTsConfig: false
|
|
4579
3539
|
});
|
|
4580
3540
|
const sourceFile = project.getSourceFile(absPath);
|
|
@@ -4601,158 +3561,26 @@ async function main24() {
|
|
|
4601
3561
|
Saved ${ANALYTICS_FILE_REL}.`);
|
|
4602
3562
|
}
|
|
4603
3563
|
|
|
4604
|
-
// src/migrations/v2.0/
|
|
4605
|
-
var
|
|
4606
|
-
|
|
4607
|
-
|
|
4608
|
-
|
|
4609
|
-
var TEMP_REMOTE2 = "opencrvs-upgrade-v19-v20-codemod-merge-infra";
|
|
4610
|
-
var INFRASTRUCTURE_DIR = "infrastructure";
|
|
4611
|
-
var BASE_BRANCH = "release-v1.9";
|
|
4612
|
-
function gitShowBytes(ref, path23) {
|
|
4613
|
-
try {
|
|
4614
|
-
const buf = (0, import_child_process2.execFileSync)("git", ["show", `${ref}:${path23}`], {
|
|
4615
|
-
cwd: process.cwd(),
|
|
4616
|
-
stdio: ["ignore", "pipe", "pipe"]
|
|
4617
|
-
});
|
|
4618
|
-
return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
4619
|
-
} catch {
|
|
4620
|
-
return null;
|
|
3564
|
+
// src/migrations/v2.0/index.ts
|
|
3565
|
+
var cwd;
|
|
3566
|
+
function getCwd() {
|
|
3567
|
+
if (!cwd) {
|
|
3568
|
+
throw new Error("Country config working directory not set.");
|
|
4621
3569
|
}
|
|
3570
|
+
return cwd;
|
|
4622
3571
|
}
|
|
4623
|
-
async function
|
|
4624
|
-
|
|
4625
|
-
|
|
4626
|
-
|
|
4627
|
-
);
|
|
4628
|
-
assertIsGitRepo();
|
|
4629
|
-
tryGit(["remote", "remove", TEMP_REMOTE2]);
|
|
4630
|
-
try {
|
|
4631
|
-
console.log(` Adding temporary remote '${TEMP_REMOTE2}' \u2192 ${UPSTREAM_URL}`);
|
|
4632
|
-
runGit(["remote", "add", TEMP_REMOTE2, UPSTREAM_URL], { silent: true });
|
|
4633
|
-
console.log(
|
|
4634
|
-
` Fetching ${TEMP_REMOTE2}/{${UPSTREAM_BRANCH},${BASE_BRANCH}} (depth 1)...`
|
|
4635
|
-
);
|
|
4636
|
-
runGit(["fetch", "--depth=1", TEMP_REMOTE2, UPSTREAM_BRANCH, BASE_BRANCH]);
|
|
4637
|
-
const ref = `${TEMP_REMOTE2}/${UPSTREAM_BRANCH}`;
|
|
4638
|
-
const baseRef = `${TEMP_REMOTE2}/${BASE_BRANCH}`;
|
|
4639
|
-
const upstreamFiles = runGit(
|
|
4640
|
-
[
|
|
4641
|
-
"ls-tree",
|
|
4642
|
-
"-r",
|
|
4643
|
-
"--name-only",
|
|
4644
|
-
"-z",
|
|
4645
|
-
ref,
|
|
4646
|
-
"--",
|
|
4647
|
-
`${INFRASTRUCTURE_DIR}/`
|
|
4648
|
-
],
|
|
4649
|
-
{ silent: true }
|
|
4650
|
-
).split("\0").filter(Boolean);
|
|
4651
|
-
if (upstreamFiles.length === 0) {
|
|
4652
|
-
console.log(
|
|
4653
|
-
` No files found under '${INFRASTRUCTURE_DIR}/' on ${ref}. Nothing to merge.`
|
|
4654
|
-
);
|
|
4655
|
-
return;
|
|
4656
|
-
}
|
|
4657
|
-
const tmpDir = (0, import_fs5.mkdtempSync)((0, import_path24.join)((0, import_os.tmpdir)(), "opencrvs-merge-infra-"));
|
|
4658
|
-
const baseTmp = (0, import_path24.join)(tmpDir, "base");
|
|
4659
|
-
const theirsTmp = (0, import_path24.join)(tmpDir, "theirs");
|
|
4660
|
-
let added = 0;
|
|
4661
|
-
let merged = 0;
|
|
4662
|
-
const conflictedFiles = [];
|
|
4663
|
-
for (const file of upstreamFiles) {
|
|
4664
|
-
const fullPath = (0, import_path24.join)(process.cwd(), file);
|
|
4665
|
-
if (!(0, import_fs5.existsSync)(fullPath)) {
|
|
4666
|
-
if (tryGit(["checkout", ref, "--", file])) {
|
|
4667
|
-
console.log(` + ${file} (new from upstream)`);
|
|
4668
|
-
added++;
|
|
4669
|
-
} else {
|
|
4670
|
-
console.warn(` [warn] failed to add new file ${file}`);
|
|
4671
|
-
}
|
|
4672
|
-
continue;
|
|
4673
|
-
}
|
|
4674
|
-
const theirContents = gitShowBytes(ref, file);
|
|
4675
|
-
if (theirContents === null) {
|
|
4676
|
-
console.warn(` [warn] could not read ${file} from ${ref} \u2014 skipping.`);
|
|
4677
|
-
continue;
|
|
4678
|
-
}
|
|
4679
|
-
(0, import_fs5.writeFileSync)(theirsTmp, theirContents);
|
|
4680
|
-
const baseContents = gitShowBytes(baseRef, file);
|
|
4681
|
-
(0, import_fs5.writeFileSync)(baseTmp, baseContents ?? new Uint8Array(0));
|
|
4682
|
-
try {
|
|
4683
|
-
(0, import_child_process2.execFileSync)("git", ["merge-file", fullPath, baseTmp, theirsTmp], {
|
|
4684
|
-
cwd: process.cwd(),
|
|
4685
|
-
stdio: ["ignore", "pipe", "pipe"]
|
|
4686
|
-
});
|
|
4687
|
-
runGit(["add", "--", file], { silent: true });
|
|
4688
|
-
merged++;
|
|
4689
|
-
} catch (err) {
|
|
4690
|
-
const status = err.status;
|
|
4691
|
-
if (typeof status === "number" && status > 0) {
|
|
4692
|
-
conflictedFiles.push(file);
|
|
4693
|
-
console.warn(
|
|
4694
|
-
` ! ${file} (${status} conflict${status > 1 ? "s" : ""})`
|
|
4695
|
-
);
|
|
4696
|
-
} else {
|
|
4697
|
-
conflictedFiles.push(file);
|
|
4698
|
-
console.warn(
|
|
4699
|
-
` [warn] merge failed for ${file} (likely binary or unreadable) \u2014 left untouched.`
|
|
4700
|
-
);
|
|
4701
|
-
}
|
|
4702
|
-
}
|
|
4703
|
-
}
|
|
4704
|
-
console.log(
|
|
4705
|
-
`
|
|
4706
|
-
Done. ${added} added, ${merged} merged cleanly, ${conflictedFiles.length} with conflicts.`
|
|
4707
|
-
);
|
|
4708
|
-
if (conflictedFiles.length > 0) {
|
|
4709
|
-
console.warn(
|
|
4710
|
-
`
|
|
4711
|
-
NOTE: ${conflictedFiles.length} file(s) under '${INFRASTRUCTURE_DIR}/' have merge conflicts that you must resolve manually.
|
|
4712
|
-
Look for the standard conflict markers (<<<<<<<, =======, >>>>>>>) in:
|
|
4713
|
-
` + conflictedFiles.map((f) => ` - ${f}`).join("\n") + `
|
|
4714
|
-
After resolving, stage the fixes with: git add ${INFRASTRUCTURE_DIR}/`
|
|
4715
|
-
);
|
|
4716
|
-
}
|
|
4717
|
-
} finally {
|
|
4718
|
-
if (tryGit(["remote", "remove", TEMP_REMOTE2])) {
|
|
4719
|
-
console.log(` Removed temporary remote '${TEMP_REMOTE2}'.`);
|
|
4720
|
-
}
|
|
3572
|
+
async function runUpgrade(ccwd) {
|
|
3573
|
+
if (ccwd) {
|
|
3574
|
+
console.log("Country config working directory:", ccwd);
|
|
3575
|
+
cwd = ccwd;
|
|
4721
3576
|
}
|
|
4722
|
-
|
|
4723
|
-
|
|
4724
|
-
// src/migrations/v2.0/delete-infrastructure-directory.ts
|
|
4725
|
-
var import_fs6 = require("fs");
|
|
4726
|
-
var import_path25 = require("path");
|
|
4727
|
-
var INFRASTRUCTURE_DIR2 = "infrastructure";
|
|
4728
|
-
async function main26() {
|
|
4729
|
-
const fullPath = (0, import_path25.join)(process.cwd(), INFRASTRUCTURE_DIR2);
|
|
4730
|
-
if (!(0, import_fs6.existsSync)(fullPath)) {
|
|
3577
|
+
if (!ccwd) {
|
|
4731
3578
|
console.log(
|
|
4732
|
-
|
|
3579
|
+
"Will use current working directory as country config working directory."
|
|
4733
3580
|
);
|
|
4734
|
-
|
|
4735
|
-
}
|
|
4736
|
-
console.log(`Deleting '${INFRASTRUCTURE_DIR2}/'...
|
|
4737
|
-
`);
|
|
4738
|
-
assertIsGitRepo();
|
|
4739
|
-
runGit(["rm", "-rf", "--ignore-unmatch", "--", `${INFRASTRUCTURE_DIR2}/`], {
|
|
4740
|
-
silent: true
|
|
4741
|
-
});
|
|
4742
|
-
console.log(` Staged deletion of tracked files under '${INFRASTRUCTURE_DIR2}/'.`);
|
|
4743
|
-
if ((0, import_fs6.existsSync)(fullPath)) {
|
|
4744
|
-
(0, import_fs6.rmSync)(fullPath, { recursive: true, force: true });
|
|
4745
|
-
console.log(` Removed remaining untracked files under '${INFRASTRUCTURE_DIR2}/'.`);
|
|
3581
|
+
cwd = process.cwd();
|
|
4746
3582
|
}
|
|
4747
|
-
|
|
4748
|
-
`
|
|
4749
|
-
Done. Review the staged deletion with: git diff --cached -- '${INFRASTRUCTURE_DIR2}/'`
|
|
4750
|
-
);
|
|
4751
|
-
}
|
|
4752
|
-
|
|
4753
|
-
// src/migrations/v2.0/index.ts
|
|
4754
|
-
async function runUpgrade(dockerSwarm) {
|
|
4755
|
-
await main18();
|
|
3583
|
+
await main13();
|
|
4756
3584
|
await main();
|
|
4757
3585
|
await main2();
|
|
4758
3586
|
await main3();
|
|
@@ -4765,20 +3593,9 @@ async function runUpgrade(dockerSwarm) {
|
|
|
4765
3593
|
await main10();
|
|
4766
3594
|
await main11();
|
|
4767
3595
|
await main12();
|
|
4768
|
-
await main13();
|
|
4769
3596
|
await main14();
|
|
4770
3597
|
await main15();
|
|
4771
3598
|
await main16();
|
|
4772
|
-
await main19();
|
|
4773
|
-
await main20();
|
|
4774
|
-
await main21();
|
|
4775
|
-
await main22();
|
|
4776
|
-
await main23();
|
|
4777
|
-
await main24();
|
|
4778
3599
|
await main17();
|
|
4779
|
-
|
|
4780
|
-
await main25();
|
|
4781
|
-
} else {
|
|
4782
|
-
await main26();
|
|
4783
|
-
}
|
|
3600
|
+
await main18();
|
|
4784
3601
|
}
|