@opencrvs/toolkit 1.9.12-rc.ab1347b → 1.9.12-rc.ab196db
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 +1 -1
- package/dist/cli.js +1890 -278
- package/dist/commons/api/router.d.ts +175 -163
- package/dist/commons/events/AuditLog.d.ts +2 -0
- package/dist/commons/events/EventConfig.d.ts +3 -1
- package/dist/commons/events/FieldConfig.d.ts +2 -2
- package/dist/commons/events/scopes.d.ts +1 -1
- package/dist/commons/notification/UserNotifications.d.ts +15 -0
- package/dist/events/index.js +18 -4
- 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 +3 -4
- package/dist/migrations/v2.0/add-resend-invite-notification.d.ts +3 -0
- package/dist/migrations/v2.0/add-resend-invite-notification.d.ts.map +1 -0
- package/dist/migrations/v2.0/add-resend-invite-notification.js +356 -0
- package/dist/migrations/v2.0/checkout-upstream-files.d.ts +22 -0
- package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +1 -0
- package/dist/migrations/v2.0/checkout-upstream-files.js +147 -0
- 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 +4 -5
- package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts.map +1 -1
- package/dist/migrations/v2.0/convert-paragraph-to-heading.js +4 -5
- package/dist/migrations/v2.0/create-events-index.d.ts +3 -0
- package/dist/migrations/v2.0/create-events-index.d.ts.map +1 -0
- package/dist/migrations/v2.0/create-events-index.js +325 -0
- package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts +3 -0
- package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts.map +1 -0
- package/dist/migrations/v2.0/delete-infrastructure-directory.js +77 -0
- package/dist/migrations/v2.0/index.d.ts +8 -4
- package/dist/migrations/v2.0/index.d.ts.map +1 -1
- package/dist/migrations/v2.0/index.js +1860 -277
- 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 +5 -6
- package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts +3 -0
- package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts.map +1 -0
- package/dist/migrations/v2.0/merge-infrastructure-directory.js +221 -0
- package/dist/migrations/v2.0/migrate-application-config-url.d.ts +3 -0
- package/dist/migrations/v2.0/migrate-application-config-url.d.ts.map +1 -0
- package/dist/migrations/v2.0/migrate-application-config-url.js +342 -0
- package/dist/migrations/v2.0/migrate-scopes.d.ts.map +1 -1
- package/dist/migrations/v2.0/migrate-scopes.js +6 -7
- 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 +3 -4
- package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts.map +1 -1
- package/dist/migrations/v2.0/migrate-workqueue-configs.js +3 -4
- package/dist/migrations/v2.0/remove-delete-actions.d.ts.map +1 -1
- package/dist/migrations/v2.0/remove-delete-actions.js +3 -4
- package/dist/migrations/v2.0/remove-demo-scope.d.ts.map +1 -1
- package/dist/migrations/v2.0/remove-demo-scope.js +2 -3
- package/dist/migrations/v2.0/remove-deprecated-imports.d.ts.map +1 -1
- package/dist/migrations/v2.0/remove-deprecated-imports.js +3 -4
- package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts +3 -0
- package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts.map +1 -0
- package/dist/migrations/v2.0/remove-fhir-url-helpers.js +163 -0
- package/dist/migrations/v2.0/remove-hearth-migrations.d.ts.map +1 -1
- package/dist/migrations/v2.0/remove-hearth-migrations.js +1 -2
- package/dist/migrations/v2.0/remove-old-statistics-service.d.ts +3 -0
- package/dist/migrations/v2.0/remove-old-statistics-service.d.ts.map +1 -0
- package/dist/migrations/v2.0/remove-old-statistics-service.js +356 -0
- package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts.map +1 -1
- package/dist/migrations/v2.0/remove-pending-certification-flag.js +3 -4
- 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 +3 -4
- package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts +3 -0
- package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts.map +1 -0
- package/dist/migrations/v2.0/remove-unused-environment-variables.js +186 -0
- package/dist/migrations/v2.0/rename-api-paths.d.ts.map +1 -1
- package/dist/migrations/v2.0/rename-api-paths.js +3 -4
- package/dist/migrations/v2.0/rename-location-parent-id.d.ts.map +1 -1
- package/dist/migrations/v2.0/rename-location-parent-id.js +3 -4
- package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts +3 -0
- package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts.map +1 -0
- package/dist/migrations/v2.0/simplify-analytics-precalculations.js +195 -0
- package/dist/migrations/v2.0/update-package-json.d.ts +3 -0
- package/dist/migrations/v2.0/update-package-json.d.ts.map +1 -0
- package/dist/migrations/v2.0/update-package-json.js +105 -0
- package/dist/notification/index.js +11 -2
- package/opencrvs-toolkit-1.9.12-rc.ab196db.tgz +0 -0
- package/package.json +1 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/opencrvs-toolkit-1.9.12-rc.ab1347b.tgz +0 -0
|
@@ -31,7 +31,6 @@ 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,
|
|
35
34
|
runUpgrade: () => runUpgrade
|
|
36
35
|
});
|
|
37
36
|
module.exports = __toCommonJS(v2_exports);
|
|
@@ -104,7 +103,7 @@ function processFile(filePath, project) {
|
|
|
104
103
|
if (wasRemoved) {
|
|
105
104
|
removedCount++;
|
|
106
105
|
console.log(
|
|
107
|
-
` [${import_path.default.relative(
|
|
106
|
+
` [${import_path.default.relative(process.cwd(), filePath)}] Removed 'review' from REGISTER action`
|
|
108
107
|
);
|
|
109
108
|
}
|
|
110
109
|
}
|
|
@@ -112,7 +111,7 @@ function processFile(filePath, project) {
|
|
|
112
111
|
return removedCount;
|
|
113
112
|
}
|
|
114
113
|
async function main() {
|
|
115
|
-
const srcDir = import_path.default.join(
|
|
114
|
+
const srcDir = import_path.default.join(process.cwd(), "src");
|
|
116
115
|
console.log(`Scanning for defineConfig calls in: ${srcDir}
|
|
117
116
|
`);
|
|
118
117
|
const project = new import_ts_morph.Project({
|
|
@@ -148,7 +147,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
148
147
|
for (const filePath of modifiedFiles) {
|
|
149
148
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
150
149
|
await sourceFile.save();
|
|
151
|
-
console.log(` Saved: ${import_path.default.relative(
|
|
150
|
+
console.log(` Saved: ${import_path.default.relative(process.cwd(), filePath)}`);
|
|
152
151
|
}
|
|
153
152
|
console.log(
|
|
154
153
|
`
|
|
@@ -351,7 +350,7 @@ function processFile2(filePath, project) {
|
|
|
351
350
|
const eventType = resolveEventType(configArg);
|
|
352
351
|
if (!eventType) {
|
|
353
352
|
console.warn(
|
|
354
|
-
` [${import_path2.default.relative(
|
|
353
|
+
` [${import_path2.default.relative(process.cwd(), configArg.getSourceFile().getFilePath())}] Could not resolve root 'type' from defineConfig \u2014 skipping auditHistoryLabel id generation`
|
|
355
354
|
);
|
|
356
355
|
}
|
|
357
356
|
let fileNeedsImports = false;
|
|
@@ -367,7 +366,7 @@ function processFile2(filePath, project) {
|
|
|
367
366
|
fileNeedsImports = true;
|
|
368
367
|
configHadValidateAction = true;
|
|
369
368
|
console.log(
|
|
370
|
-
` [${import_path2.default.relative(
|
|
369
|
+
` [${import_path2.default.relative(process.cwd(), filePath)}] Transformed VALIDATE action to CUSTOM with customActionType: '${VALIDATE_DECLARATION_VALUE}'`
|
|
371
370
|
);
|
|
372
371
|
}
|
|
373
372
|
}
|
|
@@ -388,7 +387,7 @@ function processFile2(filePath, project) {
|
|
|
388
387
|
]`
|
|
389
388
|
});
|
|
390
389
|
console.log(
|
|
391
|
-
` [${import_path2.default.relative(
|
|
390
|
+
` [${import_path2.default.relative(process.cwd(), filePath)}] Added top-level 'flags' array to defineConfig`
|
|
392
391
|
);
|
|
393
392
|
}
|
|
394
393
|
if (fileNeedsImports) {
|
|
@@ -398,7 +397,7 @@ function processFile2(filePath, project) {
|
|
|
398
397
|
return transformedCount;
|
|
399
398
|
}
|
|
400
399
|
async function main2() {
|
|
401
|
-
const srcDir = import_path2.default.join(
|
|
400
|
+
const srcDir = import_path2.default.join(process.cwd(), "src");
|
|
402
401
|
console.log(`Scanning for defineConfig calls in: ${srcDir}
|
|
403
402
|
`);
|
|
404
403
|
const project = new import_ts_morph2.Project({
|
|
@@ -433,7 +432,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
433
432
|
for (const filePath of modifiedFiles) {
|
|
434
433
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
435
434
|
await sourceFile.save();
|
|
436
|
-
console.log(` Saved: ${import_path2.default.relative(
|
|
435
|
+
console.log(` Saved: ${import_path2.default.relative(process.cwd(), filePath)}`);
|
|
437
436
|
}
|
|
438
437
|
console.log(
|
|
439
438
|
`
|
|
@@ -504,14 +503,14 @@ function processFile3(filePath, project) {
|
|
|
504
503
|
actionsInitializer.removeElement(index);
|
|
505
504
|
removedCount++;
|
|
506
505
|
console.log(
|
|
507
|
-
` [${import_path3.default.relative(
|
|
506
|
+
` [${import_path3.default.relative(process.cwd(), filePath)}] Removed DELETE action at index ${index}`
|
|
508
507
|
);
|
|
509
508
|
}
|
|
510
509
|
}
|
|
511
510
|
return removedCount;
|
|
512
511
|
}
|
|
513
512
|
async function main3() {
|
|
514
|
-
const srcDir = import_path3.default.join(
|
|
513
|
+
const srcDir = import_path3.default.join(process.cwd(), "src");
|
|
515
514
|
console.log(`Scanning for defineConfig calls in: ${srcDir}
|
|
516
515
|
`);
|
|
517
516
|
const project = new import_ts_morph3.Project({
|
|
@@ -546,7 +545,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
546
545
|
for (const filePath of modifiedFiles) {
|
|
547
546
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
548
547
|
await sourceFile.save();
|
|
549
|
-
console.log(` Saved: ${import_path3.default.relative(
|
|
548
|
+
console.log(` Saved: ${import_path3.default.relative(process.cwd(), filePath)}`);
|
|
550
549
|
}
|
|
551
550
|
console.log(
|
|
552
551
|
`
|
|
@@ -620,19 +619,19 @@ function processFile4(filePath, project) {
|
|
|
620
619
|
if (result === "converted-to-heading") {
|
|
621
620
|
changedCount++;
|
|
622
621
|
console.log(
|
|
623
|
-
` [${import_path4.default.relative(
|
|
622
|
+
` [${import_path4.default.relative(process.cwd(), filePath)}] Converted PARAGRAPH with heading fontVariant to HEADING`
|
|
624
623
|
);
|
|
625
624
|
} else if (result === "removed-font-variant") {
|
|
626
625
|
changedCount++;
|
|
627
626
|
console.log(
|
|
628
|
-
` [${import_path4.default.relative(
|
|
627
|
+
` [${import_path4.default.relative(process.cwd(), filePath)}] Removed non-heading fontVariant from PARAGRAPH`
|
|
629
628
|
);
|
|
630
629
|
}
|
|
631
630
|
}
|
|
632
631
|
return changedCount;
|
|
633
632
|
}
|
|
634
633
|
async function main4() {
|
|
635
|
-
const srcDir = import_path4.default.join(
|
|
634
|
+
const srcDir = import_path4.default.join(process.cwd(), "src");
|
|
636
635
|
console.log(`Scanning for FieldType.PARAGRAPH fields in: ${srcDir}
|
|
637
636
|
`);
|
|
638
637
|
const project = new import_ts_morph4.Project({
|
|
@@ -666,7 +665,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
666
665
|
for (const filePath of modifiedFiles) {
|
|
667
666
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
668
667
|
await sourceFile.save();
|
|
669
|
-
console.log(` Saved: ${import_path4.default.relative(
|
|
668
|
+
console.log(` Saved: ${import_path4.default.relative(process.cwd(), filePath)}`);
|
|
670
669
|
}
|
|
671
670
|
console.log(`
|
|
672
671
|
Done. Processed ${totalChanged} FieldType.PARAGRAPH field(s).`);
|
|
@@ -816,7 +815,7 @@ function processFile5(filePath, project) {
|
|
|
816
815
|
if (changed > 0) {
|
|
817
816
|
migratedCount += changed;
|
|
818
817
|
console.log(
|
|
819
|
-
` [${import_path5.default.relative(
|
|
818
|
+
` [${import_path5.default.relative(process.cwd(), filePath)}] Migrated ${changed} clause(s): VALIDATED status \u2192 flags.anyOf`
|
|
820
819
|
);
|
|
821
820
|
}
|
|
822
821
|
}
|
|
@@ -824,7 +823,7 @@ function processFile5(filePath, project) {
|
|
|
824
823
|
return migratedCount;
|
|
825
824
|
}
|
|
826
825
|
async function main5() {
|
|
827
|
-
const srcDir = import_path5.default.join(
|
|
826
|
+
const srcDir = import_path5.default.join(process.cwd(), "src");
|
|
828
827
|
console.log(`Scanning for defineWorkqueues calls in: ${srcDir}
|
|
829
828
|
`);
|
|
830
829
|
const project = new import_ts_morph5.Project({
|
|
@@ -858,7 +857,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
858
857
|
for (const filePath of modifiedFiles) {
|
|
859
858
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
860
859
|
await sourceFile.save();
|
|
861
|
-
console.log(` Saved: ${import_path5.default.relative(
|
|
860
|
+
console.log(` Saved: ${import_path5.default.relative(process.cwd(), filePath)}`);
|
|
862
861
|
}
|
|
863
862
|
console.log(
|
|
864
863
|
`
|
|
@@ -1076,7 +1075,7 @@ function processFile6(filePath, project) {
|
|
|
1076
1075
|
const sourceFile = project.getSourceFile(filePath);
|
|
1077
1076
|
if (!sourceFile) return 0;
|
|
1078
1077
|
let totalChanges = 0;
|
|
1079
|
-
const relPath = import_path6.default.relative(
|
|
1078
|
+
const relPath = import_path6.default.relative(process.cwd(), filePath);
|
|
1080
1079
|
const callExpressions = sourceFile.getDescendantsOfKind(
|
|
1081
1080
|
import_ts_morph6.SyntaxKind.CallExpression
|
|
1082
1081
|
);
|
|
@@ -1117,7 +1116,7 @@ function processFile6(filePath, project) {
|
|
|
1117
1116
|
return totalChanges;
|
|
1118
1117
|
}
|
|
1119
1118
|
async function main6() {
|
|
1120
|
-
const srcDir = import_path6.default.join(
|
|
1119
|
+
const srcDir = import_path6.default.join(process.cwd(), "src");
|
|
1121
1120
|
console.log(
|
|
1122
1121
|
`Scanning for birth defineConfig and PRINT_CERTIFICATE workqueues in: ${srcDir}
|
|
1123
1122
|
`
|
|
@@ -1153,7 +1152,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
1153
1152
|
for (const filePath of modifiedFiles) {
|
|
1154
1153
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
1155
1154
|
await sourceFile.save();
|
|
1156
|
-
console.log(` Saved: ${import_path6.default.relative(
|
|
1155
|
+
console.log(` Saved: ${import_path6.default.relative(process.cwd(), filePath)}`);
|
|
1157
1156
|
}
|
|
1158
1157
|
console.log(
|
|
1159
1158
|
`
|
|
@@ -1190,14 +1189,14 @@ function processFile7(filePath, project) {
|
|
|
1190
1189
|
array3.removeElement(index);
|
|
1191
1190
|
removedCount++;
|
|
1192
1191
|
console.log(
|
|
1193
|
-
` [${import_path7.default.relative(
|
|
1192
|
+
` [${import_path7.default.relative(process.cwd(), filePath)}] Removed InherentFlags.PENDING_CERTIFICATION from array`
|
|
1194
1193
|
);
|
|
1195
1194
|
}
|
|
1196
1195
|
}
|
|
1197
1196
|
return removedCount;
|
|
1198
1197
|
}
|
|
1199
1198
|
async function main7() {
|
|
1200
|
-
const srcDir = import_path7.default.join(
|
|
1199
|
+
const srcDir = import_path7.default.join(process.cwd(), "src");
|
|
1201
1200
|
console.log(
|
|
1202
1201
|
`Scanning for InherentFlags.PENDING_CERTIFICATION array elements in: ${srcDir}
|
|
1203
1202
|
`
|
|
@@ -1233,7 +1232,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
1233
1232
|
for (const filePath of modifiedFiles) {
|
|
1234
1233
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
1235
1234
|
await sourceFile.save();
|
|
1236
|
-
console.log(` Saved: ${import_path7.default.relative(
|
|
1235
|
+
console.log(` Saved: ${import_path7.default.relative(process.cwd(), filePath)}`);
|
|
1237
1236
|
}
|
|
1238
1237
|
console.log(
|
|
1239
1238
|
`
|
|
@@ -1291,13 +1290,13 @@ function processFile8(filePath, project) {
|
|
|
1291
1290
|
propAccess.getNameNode().replaceWithText(NEW_PROPERTY_NAME);
|
|
1292
1291
|
renamedCount++;
|
|
1293
1292
|
console.log(
|
|
1294
|
-
` [${import_path8.default.relative(
|
|
1293
|
+
` [${import_path8.default.relative(process.cwd(), filePath)}] Renamed Location.${OLD_PROPERTY_NAME} \u2192 Location.${NEW_PROPERTY_NAME}`
|
|
1295
1294
|
);
|
|
1296
1295
|
}
|
|
1297
1296
|
return renamedCount;
|
|
1298
1297
|
}
|
|
1299
1298
|
async function main8() {
|
|
1300
|
-
const srcDir = import_path8.default.join(
|
|
1299
|
+
const srcDir = import_path8.default.join(process.cwd(), "src");
|
|
1301
1300
|
console.log(
|
|
1302
1301
|
`Scanning for Location.${OLD_PROPERTY_NAME} references in: ${srcDir}
|
|
1303
1302
|
`
|
|
@@ -1333,7 +1332,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
1333
1332
|
for (const filePath of modifiedFiles) {
|
|
1334
1333
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
1335
1334
|
await sourceFile.save();
|
|
1336
|
-
console.log(` Saved: ${import_path8.default.relative(
|
|
1335
|
+
console.log(` Saved: ${import_path8.default.relative(process.cwd(), filePath)}`);
|
|
1337
1336
|
}
|
|
1338
1337
|
console.log(
|
|
1339
1338
|
`
|
|
@@ -1400,7 +1399,7 @@ function processFile9(filePath, project) {
|
|
|
1400
1399
|
const sourceFile = project.getSourceFile(filePath);
|
|
1401
1400
|
if (!sourceFile) return 0;
|
|
1402
1401
|
let renamedCount = 0;
|
|
1403
|
-
const relPath = import_path9.default.relative(
|
|
1402
|
+
const relPath = import_path9.default.relative(process.cwd(), filePath);
|
|
1404
1403
|
const candidates = sourceFile.getDescendantsOfKind(
|
|
1405
1404
|
import_ts_morph9.SyntaxKind.ObjectLiteralExpression
|
|
1406
1405
|
);
|
|
@@ -1415,7 +1414,7 @@ function processFile9(filePath, project) {
|
|
|
1415
1414
|
return renamedCount;
|
|
1416
1415
|
}
|
|
1417
1416
|
async function main9() {
|
|
1418
|
-
const srcDir = import_path9.default.join(
|
|
1417
|
+
const srcDir = import_path9.default.join(process.cwd(), "src");
|
|
1419
1418
|
console.log(`Scanning for Hapi route configs in: ${srcDir}
|
|
1420
1419
|
`);
|
|
1421
1420
|
console.log("Active path renames:");
|
|
@@ -1452,7 +1451,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
1452
1451
|
for (const filePath of modifiedFiles) {
|
|
1453
1452
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
1454
1453
|
await sourceFile.save();
|
|
1455
|
-
console.log(` Saved: ${import_path9.default.relative(
|
|
1454
|
+
console.log(` Saved: ${import_path9.default.relative(process.cwd(), filePath)}`);
|
|
1456
1455
|
}
|
|
1457
1456
|
console.log(`
|
|
1458
1457
|
Done. Renamed ${totalRenamed} route path(s).`);
|
|
@@ -1826,9 +1825,9 @@ function updateRouteHandlers(sourceFiles, group, srcDir, relCwd) {
|
|
|
1826
1825
|
}
|
|
1827
1826
|
return replacedCount;
|
|
1828
1827
|
}
|
|
1829
|
-
function resolveConfigChain(configObj,
|
|
1828
|
+
function resolveConfigChain(configObj, path23) {
|
|
1830
1829
|
let current = configObj;
|
|
1831
|
-
for (const key of
|
|
1830
|
+
for (const key of path23) {
|
|
1832
1831
|
if (!import_ts_morph10.Node.isObjectLiteralExpression(current)) return null;
|
|
1833
1832
|
const prop = current.getProperty(key);
|
|
1834
1833
|
if (!prop || !import_ts_morph10.Node.isPropertyAssignment(prop)) return null;
|
|
@@ -1873,8 +1872,8 @@ function ensureJoinImport(sf) {
|
|
|
1873
1872
|
});
|
|
1874
1873
|
}
|
|
1875
1874
|
async function main10() {
|
|
1876
|
-
const srcDir = import_path10.default.join(
|
|
1877
|
-
const relCwd = (fp) => import_path10.default.relative(
|
|
1875
|
+
const srcDir = import_path10.default.join(process.cwd(), "src");
|
|
1876
|
+
const relCwd = (fp) => import_path10.default.relative(process.cwd(), fp);
|
|
1878
1877
|
console.log("Phase 1: Converting JS config files to TypeScript...\n");
|
|
1879
1878
|
let convertedCount = 0;
|
|
1880
1879
|
for (const group of CONFIG_GROUPS) {
|
|
@@ -1962,7 +1961,7 @@ async function main10() {
|
|
|
1962
1961
|
ensureJoinImport(sf);
|
|
1963
1962
|
}
|
|
1964
1963
|
console.log(
|
|
1965
|
-
` Inlined applicationConfig.${accessPath.join(".")} \u2192 ${adjustedValue} in ${import_path10.default.relative(
|
|
1964
|
+
` Inlined applicationConfig.${accessPath.join(".")} \u2192 ${adjustedValue} in ${import_path10.default.relative(process.cwd(), sf.getFilePath())}`
|
|
1966
1965
|
);
|
|
1967
1966
|
filesToSaveAfterInlining.add(sf);
|
|
1968
1967
|
madeReplacement = true;
|
|
@@ -1974,7 +1973,7 @@ async function main10() {
|
|
|
1974
1973
|
for (const sf of Array.from(filesToSaveAfterInlining)) {
|
|
1975
1974
|
await sf.save();
|
|
1976
1975
|
console.log(
|
|
1977
|
-
` Saved (inlined): ${import_path10.default.relative(
|
|
1976
|
+
` Saved (inlined): ${import_path10.default.relative(process.cwd(), sf.getFilePath())}`
|
|
1978
1977
|
);
|
|
1979
1978
|
}
|
|
1980
1979
|
for (const prop of [...propsToRemove].reverse()) {
|
|
@@ -2591,7 +2590,7 @@ function migrateScopesArrays(rolesFilePath, project) {
|
|
|
2591
2590
|
const scopeKey = resolveScopeKeyFromElementAccess(element);
|
|
2592
2591
|
if (scopeKey && !(scopeKey in SCOPES)) {
|
|
2593
2592
|
console.warn(
|
|
2594
|
-
` [${import_path11.default.relative(
|
|
2593
|
+
` [${import_path11.default.relative(process.cwd(), rolesFilePath)}] Removing unknown scope reference: SCOPES.${scopeKey}`
|
|
2595
2594
|
);
|
|
2596
2595
|
initializer.removeElement(index);
|
|
2597
2596
|
removedCount++;
|
|
@@ -2600,7 +2599,7 @@ function migrateScopesArrays(rolesFilePath, project) {
|
|
|
2600
2599
|
const legacyScope = resolveLegacyScopeFromElement(element);
|
|
2601
2600
|
if (!legacyScope) {
|
|
2602
2601
|
console.warn(
|
|
2603
|
-
` [${import_path11.default.relative(
|
|
2602
|
+
` [${import_path11.default.relative(process.cwd(), rolesFilePath)}] Skipping non-literal scope expression: ${element.getText()}`
|
|
2604
2603
|
);
|
|
2605
2604
|
continue;
|
|
2606
2605
|
}
|
|
@@ -2609,7 +2608,7 @@ function migrateScopesArrays(rolesFilePath, project) {
|
|
|
2609
2608
|
const scope = decodeScope(migratedScope);
|
|
2610
2609
|
if (!scope) {
|
|
2611
2610
|
console.warn(
|
|
2612
|
-
` [${import_path11.default.relative(
|
|
2611
|
+
` [${import_path11.default.relative(process.cwd(), rolesFilePath)}] Could not decode migrated scope '${migratedScope}'.`
|
|
2613
2612
|
);
|
|
2614
2613
|
continue;
|
|
2615
2614
|
}
|
|
@@ -2617,14 +2616,14 @@ function migrateScopesArrays(rolesFilePath, project) {
|
|
|
2617
2616
|
migratedCount++;
|
|
2618
2617
|
} catch (error) {
|
|
2619
2618
|
console.warn(
|
|
2620
|
-
` [${import_path11.default.relative(
|
|
2619
|
+
` [${import_path11.default.relative(process.cwd(), rolesFilePath)}] Could not migrate scope '${legacyScope}': ${error}`
|
|
2621
2620
|
);
|
|
2622
2621
|
}
|
|
2623
2622
|
}
|
|
2624
2623
|
}
|
|
2625
2624
|
if (removedCount > 0) {
|
|
2626
2625
|
console.log(
|
|
2627
|
-
` Removed ${removedCount} unknown SCOPES reference(s) from '${import_path11.default.relative(
|
|
2626
|
+
` Removed ${removedCount} unknown SCOPES reference(s) from '${import_path11.default.relative(process.cwd(), rolesFilePath)}'.`
|
|
2628
2627
|
);
|
|
2629
2628
|
}
|
|
2630
2629
|
return { migratedCount, removedCount };
|
|
@@ -2746,9 +2745,9 @@ function removeRoleTypeDefinitionAndUnusedImports(rolesFilePath, project) {
|
|
|
2746
2745
|
return removed;
|
|
2747
2746
|
}
|
|
2748
2747
|
async function main11() {
|
|
2749
|
-
const
|
|
2750
|
-
const srcDir = import_path11.default.join(
|
|
2751
|
-
const rolesFilePath = import_path11.default.join(
|
|
2748
|
+
const cwd = process.cwd();
|
|
2749
|
+
const srcDir = import_path11.default.join(cwd, "src");
|
|
2750
|
+
const rolesFilePath = import_path11.default.join(cwd, ROLES_FILE_RELATIVE_PATH);
|
|
2752
2751
|
console.log(`Scanning roles scopes in: ${rolesFilePath}`);
|
|
2753
2752
|
const project = new import_ts_morph11.Project({
|
|
2754
2753
|
tsConfigFilePath: import_path11.default.resolve(srcDir, "../tsconfig.json"),
|
|
@@ -2812,13 +2811,13 @@ function processFile10(filePath, project) {
|
|
|
2812
2811
|
decl.remove();
|
|
2813
2812
|
}
|
|
2814
2813
|
console.log(
|
|
2815
|
-
` [${import_path12.default.relative(
|
|
2814
|
+
` [${import_path12.default.relative(process.cwd(), filePath)}] Removed ${matchingNamedImports.length} deprecated '${DEPRECATED_IMPORT}' import(s) from '${decl.getModuleSpecifierValue()}'`
|
|
2816
2815
|
);
|
|
2817
2816
|
}
|
|
2818
2817
|
return removedCount;
|
|
2819
2818
|
}
|
|
2820
2819
|
async function main12() {
|
|
2821
|
-
const srcDir = import_path12.default.join(
|
|
2820
|
+
const srcDir = import_path12.default.join(process.cwd(), "src");
|
|
2822
2821
|
console.log(`Scanning for deprecated imports in: ${srcDir}
|
|
2823
2822
|
`);
|
|
2824
2823
|
const project = new import_ts_morph12.Project({
|
|
@@ -2849,15 +2848,738 @@ async function main12() {
|
|
|
2849
2848
|
Saving ${modifiedFiles.length} modified file(s)...`);
|
|
2850
2849
|
for (const filePath of modifiedFiles) {
|
|
2851
2850
|
await project.getSourceFileOrThrow(filePath).save();
|
|
2852
|
-
console.log(` Saved: ${import_path12.default.relative(
|
|
2851
|
+
console.log(` Saved: ${import_path12.default.relative(process.cwd(), filePath)}`);
|
|
2853
2852
|
}
|
|
2854
2853
|
console.log(`
|
|
2855
2854
|
Done. Removed ${totalRemoved} deprecated import(s).`);
|
|
2856
2855
|
}
|
|
2857
2856
|
|
|
2858
|
-
// src/migrations/v2.0/
|
|
2859
|
-
var import_ts_morph13 = require("ts-morph");
|
|
2857
|
+
// src/migrations/v2.0/remove-unused-environment-variables.ts
|
|
2860
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
|
+
// src/migrations/v2.0/migrate-workqueue-configs.ts
|
|
3581
|
+
var import_ts_morph17 = require("ts-morph");
|
|
3582
|
+
var import_path18 = __toESM(require("path"));
|
|
2861
3583
|
var DEFINE_WORKQUEUES_NAME3 = "defineWorkqueues";
|
|
2862
3584
|
var ACTIONS_PROPERTY_NAME5 = "actions";
|
|
2863
3585
|
var ACTION_PROPERTY_NAME2 = "action";
|
|
@@ -2876,289 +3598,1136 @@ var SUPPORTED_WORKQUEUE_ACTION_TYPES = /* @__PURE__ */ new Set([
|
|
|
2876
3598
|
"PRINT_CERTIFICATE",
|
|
2877
3599
|
"REQUEST_CORRECTION"
|
|
2878
3600
|
]);
|
|
2879
|
-
function getWorkqueueLabel(workqueue) {
|
|
2880
|
-
const slugProperty = workqueue.getProperty(SLUG_PROPERTY_NAME);
|
|
2881
|
-
if (!slugProperty || !
|
|
2882
|
-
return "(unknown slug)";
|
|
3601
|
+
function getWorkqueueLabel(workqueue) {
|
|
3602
|
+
const slugProperty = workqueue.getProperty(SLUG_PROPERTY_NAME);
|
|
3603
|
+
if (!slugProperty || !import_ts_morph17.Node.isPropertyAssignment(slugProperty)) {
|
|
3604
|
+
return "(unknown slug)";
|
|
3605
|
+
}
|
|
3606
|
+
const slugInitializer = slugProperty.getInitializer();
|
|
3607
|
+
if (!slugInitializer || !import_ts_morph17.Node.isStringLiteral(slugInitializer)) {
|
|
3608
|
+
return "(unknown slug)";
|
|
3609
|
+
}
|
|
3610
|
+
return slugInitializer.getLiteralValue();
|
|
3611
|
+
}
|
|
3612
|
+
function getActionTypeName(action) {
|
|
3613
|
+
const typeProperty = action.getProperty(TYPE_PROPERTY_NAME7);
|
|
3614
|
+
if (!typeProperty || !import_ts_morph17.Node.isPropertyAssignment(typeProperty)) {
|
|
3615
|
+
return null;
|
|
3616
|
+
}
|
|
3617
|
+
const typeInitializer = typeProperty.getInitializer();
|
|
3618
|
+
if (!typeInitializer) {
|
|
3619
|
+
return null;
|
|
3620
|
+
}
|
|
3621
|
+
if (import_ts_morph17.Node.isStringLiteral(typeInitializer)) {
|
|
3622
|
+
return typeInitializer.getLiteralValue();
|
|
3623
|
+
}
|
|
3624
|
+
if (import_ts_morph17.Node.isPropertyAccessExpression(typeInitializer)) {
|
|
3625
|
+
return typeInitializer.getName();
|
|
3626
|
+
}
|
|
3627
|
+
return null;
|
|
3628
|
+
}
|
|
3629
|
+
function isUnsupportedActionType(action) {
|
|
3630
|
+
const typeName = getActionTypeName(action);
|
|
3631
|
+
if (!typeName) {
|
|
3632
|
+
return false;
|
|
3633
|
+
}
|
|
3634
|
+
return !SUPPORTED_WORKQUEUE_ACTION_TYPES.has(typeName);
|
|
3635
|
+
}
|
|
3636
|
+
function migrateWorkqueueActions(workqueue, relPath) {
|
|
3637
|
+
const actionsProperty = workqueue.getProperty(ACTIONS_PROPERTY_NAME5);
|
|
3638
|
+
if (!actionsProperty || !import_ts_morph17.Node.isPropertyAssignment(actionsProperty)) {
|
|
3639
|
+
return 0;
|
|
3640
|
+
}
|
|
3641
|
+
const actionsInitializer = actionsProperty.getInitializer();
|
|
3642
|
+
if (!actionsInitializer || !import_ts_morph17.Node.isArrayLiteralExpression(actionsInitializer)) {
|
|
3643
|
+
return 0;
|
|
3644
|
+
}
|
|
3645
|
+
const workqueueLabel = getWorkqueueLabel(workqueue);
|
|
3646
|
+
const existingActionProperty = workqueue.getProperty(ACTION_PROPERTY_NAME2);
|
|
3647
|
+
if (existingActionProperty) {
|
|
3648
|
+
if (import_ts_morph17.Node.isPropertyAssignment(existingActionProperty)) {
|
|
3649
|
+
const existingActionInitializer = existingActionProperty.getInitializer();
|
|
3650
|
+
if (existingActionInitializer && import_ts_morph17.Node.isObjectLiteralExpression(existingActionInitializer)) {
|
|
3651
|
+
const conditionalsProperty2 = existingActionInitializer.getProperty(
|
|
3652
|
+
CONDITIONALS_PROPERTY_NAME
|
|
3653
|
+
);
|
|
3654
|
+
if (conditionalsProperty2) {
|
|
3655
|
+
conditionalsProperty2.remove();
|
|
3656
|
+
console.log(
|
|
3657
|
+
` [${relPath}] Removed deprecated 'conditionals' from 'action' on workqueue '${workqueueLabel}'`
|
|
3658
|
+
);
|
|
3659
|
+
}
|
|
3660
|
+
if (isUnsupportedActionType(existingActionInitializer)) {
|
|
3661
|
+
existingActionProperty.remove();
|
|
3662
|
+
console.log(
|
|
3663
|
+
` [${relPath}] Removed unsupported 'action' type on workqueue '${workqueueLabel}'`
|
|
3664
|
+
);
|
|
3665
|
+
}
|
|
3666
|
+
}
|
|
3667
|
+
}
|
|
3668
|
+
actionsProperty.remove();
|
|
3669
|
+
console.log(
|
|
3670
|
+
` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' (existing 'action' kept)`
|
|
3671
|
+
);
|
|
3672
|
+
return 1;
|
|
3673
|
+
}
|
|
3674
|
+
const actionCandidates = actionsInitializer.getElements().filter(
|
|
3675
|
+
(element) => import_ts_morph17.Node.isObjectLiteralExpression(element)
|
|
3676
|
+
);
|
|
3677
|
+
if (actionCandidates.length === 0) {
|
|
3678
|
+
actionsProperty.remove();
|
|
3679
|
+
console.log(
|
|
3680
|
+
` [${relPath}] Removed empty 'actions' from workqueue '${workqueueLabel}'`
|
|
3681
|
+
);
|
|
3682
|
+
return 1;
|
|
3683
|
+
}
|
|
3684
|
+
if (actionCandidates.length > 1) {
|
|
3685
|
+
const droppedCount = actionCandidates.length - 1;
|
|
3686
|
+
console.warn(
|
|
3687
|
+
` [${relPath}] Workqueue '${workqueueLabel}' has ${actionCandidates.length} actions; keeping first as 'action' and dropping ${droppedCount} extra action(s)`
|
|
3688
|
+
);
|
|
3689
|
+
}
|
|
3690
|
+
const conditionalsProperty = actionCandidates[0].getProperty(
|
|
3691
|
+
CONDITIONALS_PROPERTY_NAME
|
|
3692
|
+
);
|
|
3693
|
+
if (conditionalsProperty) {
|
|
3694
|
+
conditionalsProperty.remove();
|
|
3695
|
+
console.log(
|
|
3696
|
+
` [${relPath}] Removed deprecated 'conditionals' from migrated 'action' on workqueue '${workqueueLabel}'`
|
|
3697
|
+
);
|
|
3698
|
+
}
|
|
3699
|
+
if (isUnsupportedActionType(actionCandidates[0])) {
|
|
3700
|
+
actionsProperty.remove();
|
|
3701
|
+
console.log(
|
|
3702
|
+
` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' because action type is unsupported`
|
|
3703
|
+
);
|
|
3704
|
+
return 1;
|
|
3705
|
+
}
|
|
3706
|
+
const firstActionText = actionCandidates[0].getText();
|
|
3707
|
+
workqueue.addPropertyAssignment({
|
|
3708
|
+
name: ACTION_PROPERTY_NAME2,
|
|
3709
|
+
initializer: firstActionText
|
|
3710
|
+
});
|
|
3711
|
+
actionsProperty.remove();
|
|
3712
|
+
console.log(
|
|
3713
|
+
` [${relPath}] Replaced 'actions' with 'action' on workqueue '${workqueueLabel}'`
|
|
3714
|
+
);
|
|
3715
|
+
return 1;
|
|
3716
|
+
}
|
|
3717
|
+
function processFile13(filePath, project) {
|
|
3718
|
+
const sourceFile = project.getSourceFile(filePath);
|
|
3719
|
+
if (!sourceFile) return 0;
|
|
3720
|
+
let migratedWorkqueues = 0;
|
|
3721
|
+
const relPath = import_path18.default.relative(process.cwd(), filePath);
|
|
3722
|
+
const callExpressions = sourceFile.getDescendantsOfKind(
|
|
3723
|
+
import_ts_morph17.SyntaxKind.CallExpression
|
|
3724
|
+
);
|
|
3725
|
+
for (const call of callExpressions) {
|
|
3726
|
+
const expression = call.getExpression();
|
|
3727
|
+
if (!import_ts_morph17.Node.isIdentifier(expression) || expression.getText() !== DEFINE_WORKQUEUES_NAME3) {
|
|
3728
|
+
continue;
|
|
3729
|
+
}
|
|
3730
|
+
const args = call.getArguments();
|
|
3731
|
+
if (args.length === 0) continue;
|
|
3732
|
+
const workqueuesArg = args[0];
|
|
3733
|
+
if (!import_ts_morph17.Node.isArrayLiteralExpression(workqueuesArg)) continue;
|
|
3734
|
+
for (const element of workqueuesArg.getElements()) {
|
|
3735
|
+
if (!import_ts_morph17.Node.isObjectLiteralExpression(element)) continue;
|
|
3736
|
+
migratedWorkqueues += migrateWorkqueueActions(element, relPath);
|
|
3737
|
+
}
|
|
3738
|
+
}
|
|
3739
|
+
return migratedWorkqueues;
|
|
3740
|
+
}
|
|
3741
|
+
async function main18() {
|
|
3742
|
+
const srcDir = import_path18.default.join(process.cwd(), "src");
|
|
3743
|
+
console.log(`Scanning for defineWorkqueues calls in: ${srcDir}
|
|
3744
|
+
`);
|
|
3745
|
+
const project = new import_ts_morph17.Project({
|
|
3746
|
+
tsConfigFilePath: import_path18.default.resolve(srcDir, "../tsconfig.json"),
|
|
3747
|
+
skipAddingFilesFromTsConfig: false
|
|
3748
|
+
});
|
|
3749
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
3750
|
+
const fp = sf.getFilePath();
|
|
3751
|
+
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
3752
|
+
});
|
|
3753
|
+
console.log(`Found ${sourceFiles.length} source file(s) to analyse.
|
|
3754
|
+
`);
|
|
3755
|
+
let totalMigrated = 0;
|
|
3756
|
+
const modifiedFiles = [];
|
|
3757
|
+
for (const sourceFile of sourceFiles) {
|
|
3758
|
+
const filePath = sourceFile.getFilePath();
|
|
3759
|
+
const migrated = processFile13(filePath, project);
|
|
3760
|
+
if (migrated > 0) {
|
|
3761
|
+
totalMigrated += migrated;
|
|
3762
|
+
modifiedFiles.push(filePath);
|
|
3763
|
+
}
|
|
3764
|
+
}
|
|
3765
|
+
if (modifiedFiles.length === 0) {
|
|
3766
|
+
console.log(
|
|
3767
|
+
"No deprecated workqueue 'actions' arrays found inside defineWorkqueues calls. Nothing to do."
|
|
3768
|
+
);
|
|
3769
|
+
return;
|
|
3770
|
+
}
|
|
3771
|
+
console.log(`
|
|
3772
|
+
Saving ${modifiedFiles.length} modified file(s)...`);
|
|
3773
|
+
for (const filePath of modifiedFiles) {
|
|
3774
|
+
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
3775
|
+
await sourceFile.save();
|
|
3776
|
+
console.log(` Saved: ${import_path18.default.relative(process.cwd(), filePath)}`);
|
|
3777
|
+
}
|
|
3778
|
+
console.log(
|
|
3779
|
+
`
|
|
3780
|
+
Done. Migrated ${totalMigrated} deprecated workqueue 'actions' definition(s) to 'action'.`
|
|
3781
|
+
);
|
|
3782
|
+
}
|
|
3783
|
+
|
|
3784
|
+
// src/migrations/v2.0/remove-demo-scope.ts
|
|
3785
|
+
var import_path19 = __toESM(require("path"));
|
|
3786
|
+
var import_ts_morph18 = require("ts-morph");
|
|
3787
|
+
var ROLES_HANDLER_RELATIVE_PATH = "src/data-seeding/roles/handler.ts";
|
|
3788
|
+
async function main19() {
|
|
3789
|
+
const rolesHandlerPath = import_path19.default.join(process.cwd(), ROLES_HANDLER_RELATIVE_PATH);
|
|
3790
|
+
const project = new import_ts_morph18.Project({
|
|
3791
|
+
tsConfigFilePath: import_path19.default.resolve(process.cwd(), "tsconfig.json"),
|
|
3792
|
+
skipAddingFilesFromTsConfig: false
|
|
3793
|
+
});
|
|
3794
|
+
const sourceFile = project.getSourceFile(rolesHandlerPath);
|
|
3795
|
+
if (!sourceFile) {
|
|
3796
|
+
console.log(
|
|
3797
|
+
`No roles handler found at '${ROLES_HANDLER_RELATIVE_PATH}'. Nothing to do.`
|
|
3798
|
+
);
|
|
3799
|
+
return;
|
|
3800
|
+
}
|
|
3801
|
+
let changed = false;
|
|
3802
|
+
const constantsImport = sourceFile.getImportDeclaration(
|
|
3803
|
+
(decl) => decl.getModuleSpecifierValue() === "@countryconfig/constants"
|
|
3804
|
+
);
|
|
3805
|
+
if (constantsImport) {
|
|
3806
|
+
constantsImport.remove();
|
|
3807
|
+
changed = true;
|
|
3808
|
+
}
|
|
3809
|
+
const rolesHandler = sourceFile.getFunction("rolesHandler");
|
|
3810
|
+
if (!rolesHandler) {
|
|
3811
|
+
console.log(
|
|
3812
|
+
`No rolesHandler export found in '${ROLES_HANDLER_RELATIVE_PATH}'. Nothing to do.`
|
|
3813
|
+
);
|
|
3814
|
+
return;
|
|
3815
|
+
}
|
|
3816
|
+
const secondParam = rolesHandler.getParameters()[1];
|
|
3817
|
+
const secondParamName = secondParam?.getName();
|
|
3818
|
+
const responseToolkitIdentifier = secondParamName || "h";
|
|
3819
|
+
const currentBodyText = rolesHandler.getBodyText();
|
|
3820
|
+
const normalizedCurrent = currentBodyText?.replace(/\s+/g, " ").trim() ?? "";
|
|
3821
|
+
const normalizedDesired = `return ${responseToolkitIdentifier}.response(roles)`;
|
|
3822
|
+
if (normalizedCurrent !== normalizedDesired) {
|
|
3823
|
+
rolesHandler.setBodyText(`return ${responseToolkitIdentifier}.response(roles)`);
|
|
3824
|
+
changed = true;
|
|
3825
|
+
}
|
|
3826
|
+
if (!changed) {
|
|
3827
|
+
console.log(
|
|
3828
|
+
`No changes needed in '${ROLES_HANDLER_RELATIVE_PATH}'.`
|
|
3829
|
+
);
|
|
3830
|
+
return;
|
|
3831
|
+
}
|
|
3832
|
+
await sourceFile.save();
|
|
3833
|
+
console.log(
|
|
3834
|
+
`Updated '${ROLES_HANDLER_RELATIVE_PATH}' to remove demo scope behavior while preserving file structure.`
|
|
3835
|
+
);
|
|
3836
|
+
}
|
|
3837
|
+
|
|
3838
|
+
// src/migrations/v2.0/remove-hearth-migrations.ts
|
|
3839
|
+
var fs2 = __toESM(require("fs"));
|
|
3840
|
+
var import_path20 = __toESM(require("path"));
|
|
3841
|
+
var PATHS_TO_REMOVE = [
|
|
3842
|
+
{
|
|
3843
|
+
relativePath: "src/migrations/hearth",
|
|
3844
|
+
label: "Hearth migrations directory"
|
|
3845
|
+
},
|
|
3846
|
+
{
|
|
3847
|
+
relativePath: "src/migrations/user-mgnt",
|
|
3848
|
+
label: "user-mgnt migrations directory"
|
|
3849
|
+
},
|
|
3850
|
+
{ relativePath: "src/utils/hearth-helpers.ts", label: "Hearth helpers file" }
|
|
3851
|
+
];
|
|
3852
|
+
async function main20() {
|
|
3853
|
+
for (const { relativePath, label } of PATHS_TO_REMOVE) {
|
|
3854
|
+
const absolutePath = import_path20.default.join(process.cwd(), relativePath);
|
|
3855
|
+
if (fs2.existsSync(absolutePath)) {
|
|
3856
|
+
fs2.rmSync(absolutePath, { recursive: true, force: true });
|
|
3857
|
+
console.log(`Removed ${label} '${relativePath}'.`);
|
|
3858
|
+
} else {
|
|
3859
|
+
console.log(`No ${label} found at '${relativePath}'.`);
|
|
3860
|
+
}
|
|
3861
|
+
}
|
|
3862
|
+
}
|
|
3863
|
+
|
|
3864
|
+
// src/migrations/v2.0/create-events-index.ts
|
|
3865
|
+
var import_ts_morph19 = require("ts-morph");
|
|
3866
|
+
var import_fs2 = __toESM(require("fs"));
|
|
3867
|
+
var import_path21 = __toESM(require("path"));
|
|
3868
|
+
var DEFINE_CONFIG_NAME5 = "defineConfig";
|
|
3869
|
+
var HANDLER_FUNCTION_NAMES = /* @__PURE__ */ new Set([
|
|
3870
|
+
"getCustomEventsHandler",
|
|
3871
|
+
"getEventsHandler"
|
|
3872
|
+
]);
|
|
3873
|
+
var EVENT_CONFIGS_IDENTIFIER = "eventConfigs";
|
|
3874
|
+
var EVENTS_INDEX_IMPORT_PATH = "@countryconfig/events";
|
|
3875
|
+
var RESPONSE_METHOD_NAME = "response";
|
|
3876
|
+
var LICENSE_HEADER = `/*
|
|
3877
|
+
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
3878
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
3879
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
3880
|
+
*
|
|
3881
|
+
* OpenCRVS is also distributed under the terms of the Civil Registration
|
|
3882
|
+
* & Healthcare Disclaimer located at http://opencrvs.org/license.
|
|
3883
|
+
*
|
|
3884
|
+
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
|
|
3885
|
+
*/
|
|
3886
|
+
`;
|
|
3887
|
+
function findEventConfigExports(project, srcDir) {
|
|
3888
|
+
const found = [];
|
|
3889
|
+
const eventsIndexAbs = import_path21.default.join(srcDir, "events", "index.ts");
|
|
3890
|
+
for (const sourceFile of project.getSourceFiles()) {
|
|
3891
|
+
const filePath = sourceFile.getFilePath();
|
|
3892
|
+
if (!filePath.startsWith(srcDir) || filePath.includes("/node_modules/")) {
|
|
3893
|
+
continue;
|
|
3894
|
+
}
|
|
3895
|
+
if (filePath === eventsIndexAbs) continue;
|
|
3896
|
+
for (const statement of sourceFile.getVariableStatements()) {
|
|
3897
|
+
if (!statement.hasExportKeyword()) continue;
|
|
3898
|
+
for (const decl of statement.getDeclarations()) {
|
|
3899
|
+
const initializer = decl.getInitializer();
|
|
3900
|
+
if (!initializer) continue;
|
|
3901
|
+
const unwrapped = import_ts_morph19.Node.isAsExpression(initializer) ? initializer.getExpression() : initializer;
|
|
3902
|
+
if (!import_ts_morph19.Node.isCallExpression(unwrapped)) continue;
|
|
3903
|
+
const callee = unwrapped.getExpression();
|
|
3904
|
+
if (!import_ts_morph19.Node.isIdentifier(callee)) continue;
|
|
3905
|
+
if (callee.getText() !== DEFINE_CONFIG_NAME5) continue;
|
|
3906
|
+
found.push({ name: decl.getName(), filePath });
|
|
3907
|
+
}
|
|
3908
|
+
}
|
|
2883
3909
|
}
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
3910
|
+
return found;
|
|
3911
|
+
}
|
|
3912
|
+
function buildIndexImportSpecifier(eventConfigFilePath, srcDir) {
|
|
3913
|
+
const eventsIndexDir = import_path21.default.join(srcDir, "events");
|
|
3914
|
+
let rel = import_path21.default.relative(eventsIndexDir, eventConfigFilePath).split(import_path21.default.sep).join("/");
|
|
3915
|
+
if (rel.endsWith(".ts")) rel = rel.slice(0, -".ts".length);
|
|
3916
|
+
if (rel.endsWith("/index")) rel = rel.slice(0, -"/index".length);
|
|
3917
|
+
if (!rel.startsWith(".")) rel = "./" + rel;
|
|
3918
|
+
return rel;
|
|
3919
|
+
}
|
|
3920
|
+
function buildEventsIndexSource(exports, srcDir) {
|
|
3921
|
+
const imports = exports.map(
|
|
3922
|
+
(e) => `import { ${e.name} } from '${buildIndexImportSpecifier(
|
|
3923
|
+
e.filePath,
|
|
3924
|
+
srcDir
|
|
3925
|
+
)}'`
|
|
3926
|
+
).join("\n");
|
|
3927
|
+
const array3 = `export const ${EVENT_CONFIGS_IDENTIFIER} = [${exports.map((e) => e.name).join(", ")}]`;
|
|
3928
|
+
return `${LICENSE_HEADER}${imports}
|
|
3929
|
+
|
|
3930
|
+
${array3}
|
|
3931
|
+
`;
|
|
3932
|
+
}
|
|
3933
|
+
function findHandlerSourceFile(project, srcDir) {
|
|
3934
|
+
for (const sf of project.getSourceFiles()) {
|
|
3935
|
+
const fp = sf.getFilePath();
|
|
3936
|
+
if (!fp.startsWith(srcDir) || fp.includes("/node_modules/")) continue;
|
|
3937
|
+
for (const fn of sf.getFunctions()) {
|
|
3938
|
+
const name = fn.getName();
|
|
3939
|
+
if (name && HANDLER_FUNCTION_NAMES.has(name)) return sf;
|
|
3940
|
+
}
|
|
3941
|
+
for (const statement of sf.getVariableStatements()) {
|
|
3942
|
+
for (const decl of statement.getDeclarations()) {
|
|
3943
|
+
if (HANDLER_FUNCTION_NAMES.has(decl.getName())) return sf;
|
|
3944
|
+
}
|
|
3945
|
+
}
|
|
2887
3946
|
}
|
|
2888
|
-
return
|
|
3947
|
+
return void 0;
|
|
2889
3948
|
}
|
|
2890
|
-
function
|
|
2891
|
-
const
|
|
2892
|
-
|
|
2893
|
-
|
|
3949
|
+
function modifyHandler(sourceFile, exportNames) {
|
|
3950
|
+
const changes = [];
|
|
3951
|
+
for (const importDecl of [...sourceFile.getImportDeclarations()]) {
|
|
3952
|
+
const namedImports = importDecl.getNamedImports();
|
|
3953
|
+
if (namedImports.length === 0) continue;
|
|
3954
|
+
const matched = namedImports.filter((ni) => exportNames.has(ni.getName()));
|
|
3955
|
+
if (matched.length === 0) continue;
|
|
3956
|
+
const removedNames = matched.map((ni) => ni.getName());
|
|
3957
|
+
for (const ni of matched) ni.remove();
|
|
3958
|
+
changes.push(`removed direct imports: ${removedNames.join(", ")}`);
|
|
3959
|
+
const stillUsed = importDecl.getNamedImports().length > 0 || importDecl.getDefaultImport() || importDecl.getNamespaceImport();
|
|
3960
|
+
if (!stillUsed) importDecl.remove();
|
|
3961
|
+
}
|
|
3962
|
+
for (const statement of [...sourceFile.getVariableStatements()]) {
|
|
3963
|
+
if (!statement.hasExportKeyword()) continue;
|
|
3964
|
+
const hasEventConfigs = statement.getDeclarations().some((d) => d.getName() === EVENT_CONFIGS_IDENTIFIER);
|
|
3965
|
+
if (hasEventConfigs) {
|
|
3966
|
+
statement.remove();
|
|
3967
|
+
changes.push(`removed inline 'export const ${EVENT_CONFIGS_IDENTIFIER}'`);
|
|
3968
|
+
}
|
|
2894
3969
|
}
|
|
2895
|
-
const
|
|
2896
|
-
|
|
2897
|
-
|
|
3970
|
+
const existing = sourceFile.getImportDeclaration(
|
|
3971
|
+
(imp) => imp.getModuleSpecifierValue() === EVENTS_INDEX_IMPORT_PATH
|
|
3972
|
+
);
|
|
3973
|
+
if (existing) {
|
|
3974
|
+
const already = existing.getNamedImports().some((ni) => ni.getName() === EVENT_CONFIGS_IDENTIFIER);
|
|
3975
|
+
if (!already) {
|
|
3976
|
+
existing.addNamedImport(EVENT_CONFIGS_IDENTIFIER);
|
|
3977
|
+
changes.push(
|
|
3978
|
+
`added '${EVENT_CONFIGS_IDENTIFIER}' to existing import from '${EVENTS_INDEX_IMPORT_PATH}'`
|
|
3979
|
+
);
|
|
3980
|
+
}
|
|
3981
|
+
} else {
|
|
3982
|
+
sourceFile.addImportDeclaration({
|
|
3983
|
+
moduleSpecifier: EVENTS_INDEX_IMPORT_PATH,
|
|
3984
|
+
namedImports: [EVENT_CONFIGS_IDENTIFIER]
|
|
3985
|
+
});
|
|
3986
|
+
changes.push(
|
|
3987
|
+
`added import { ${EVENT_CONFIGS_IDENTIFIER} } from '${EVENTS_INDEX_IMPORT_PATH}'`
|
|
3988
|
+
);
|
|
2898
3989
|
}
|
|
2899
|
-
|
|
2900
|
-
|
|
3990
|
+
for (const call of sourceFile.getDescendantsOfKind(
|
|
3991
|
+
import_ts_morph19.SyntaxKind.CallExpression
|
|
3992
|
+
)) {
|
|
3993
|
+
const callee = call.getExpression();
|
|
3994
|
+
if (!import_ts_morph19.Node.isPropertyAccessExpression(callee)) continue;
|
|
3995
|
+
if (callee.getName() !== RESPONSE_METHOD_NAME) continue;
|
|
3996
|
+
const args = call.getArguments();
|
|
3997
|
+
if (args.length !== 1) continue;
|
|
3998
|
+
const [arg] = args;
|
|
3999
|
+
if (!import_ts_morph19.Node.isArrayLiteralExpression(arg)) continue;
|
|
4000
|
+
if (arg.getElements().length === 0) continue;
|
|
4001
|
+
if (!arg.getElements().every((el) => import_ts_morph19.Node.isIdentifier(el))) continue;
|
|
4002
|
+
arg.replaceWithText(EVENT_CONFIGS_IDENTIFIER);
|
|
4003
|
+
changes.push(
|
|
4004
|
+
`rewrote h.response([...]) \u2192 h.response(${EVENT_CONFIGS_IDENTIFIER})`
|
|
4005
|
+
);
|
|
2901
4006
|
}
|
|
2902
|
-
|
|
2903
|
-
|
|
4007
|
+
return changes;
|
|
4008
|
+
}
|
|
4009
|
+
async function main21() {
|
|
4010
|
+
const cwd = process.cwd();
|
|
4011
|
+
const srcDir = import_path21.default.join(cwd, "src");
|
|
4012
|
+
console.log(`Scanning for defineConfig event exports in: ${srcDir}
|
|
4013
|
+
`);
|
|
4014
|
+
const project = new import_ts_morph19.Project({
|
|
4015
|
+
tsConfigFilePath: import_path21.default.resolve(srcDir, "../tsconfig.json"),
|
|
4016
|
+
skipAddingFilesFromTsConfig: false
|
|
4017
|
+
});
|
|
4018
|
+
const eventConfigExports = findEventConfigExports(project, srcDir);
|
|
4019
|
+
if (eventConfigExports.length === 0) {
|
|
4020
|
+
console.log(
|
|
4021
|
+
"No top-level `export const X = defineConfig(...)` declarations found. Nothing to do."
|
|
4022
|
+
);
|
|
4023
|
+
return;
|
|
2904
4024
|
}
|
|
2905
|
-
|
|
4025
|
+
console.log(`Found ${eventConfigExports.length} event config export(s):`);
|
|
4026
|
+
for (const e of eventConfigExports) {
|
|
4027
|
+
console.log(` ${e.name} \u2190 ${import_path21.default.relative(cwd, e.filePath)}`);
|
|
4028
|
+
}
|
|
4029
|
+
const eventsIndexAbs = import_path21.default.join(srcDir, "events", "index.ts");
|
|
4030
|
+
const eventsIndexRel = import_path21.default.relative(cwd, eventsIndexAbs);
|
|
4031
|
+
if (import_fs2.default.existsSync(eventsIndexAbs)) {
|
|
4032
|
+
console.log(`
|
|
4033
|
+
[${eventsIndexRel}] already exists \u2014 leaving untouched.`);
|
|
4034
|
+
} else {
|
|
4035
|
+
import_fs2.default.mkdirSync(import_path21.default.dirname(eventsIndexAbs), { recursive: true });
|
|
4036
|
+
const source = buildEventsIndexSource(eventConfigExports, srcDir);
|
|
4037
|
+
const eventsIndexFile = project.createSourceFile(eventsIndexAbs, source, {
|
|
4038
|
+
overwrite: false
|
|
4039
|
+
});
|
|
4040
|
+
await eventsIndexFile.save();
|
|
4041
|
+
console.log(
|
|
4042
|
+
`
|
|
4043
|
+
[${eventsIndexRel}] created with ${EVENT_CONFIGS_IDENTIFIER} of ${eventConfigExports.length} event(s).`
|
|
4044
|
+
);
|
|
4045
|
+
}
|
|
4046
|
+
const handler = findHandlerSourceFile(project, srcDir);
|
|
4047
|
+
if (!handler) {
|
|
4048
|
+
console.log(
|
|
4049
|
+
`
|
|
4050
|
+
No event-config handler file found (looked for exported function(s): ${Array.from(
|
|
4051
|
+
HANDLER_FUNCTION_NAMES
|
|
4052
|
+
).join(", ")}). Skipping handler rewrite.`
|
|
4053
|
+
);
|
|
4054
|
+
return;
|
|
4055
|
+
}
|
|
4056
|
+
const handlerRelPath = import_path21.default.relative(cwd, handler.getFilePath());
|
|
4057
|
+
const exportNameSet = new Set(eventConfigExports.map((e) => e.name));
|
|
4058
|
+
const changes = modifyHandler(handler, exportNameSet);
|
|
4059
|
+
if (changes.length === 0) {
|
|
4060
|
+
console.log(`
|
|
4061
|
+
[${handlerRelPath}] already wired to ${EVENTS_INDEX_IMPORT_PATH} \u2014 no changes.`);
|
|
4062
|
+
return;
|
|
4063
|
+
}
|
|
4064
|
+
for (const c of changes) console.log(` [${handlerRelPath}] ${c}`);
|
|
4065
|
+
await handler.save();
|
|
4066
|
+
console.log(`
|
|
4067
|
+
Saved ${handlerRelPath}.`);
|
|
2906
4068
|
}
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
4069
|
+
|
|
4070
|
+
// src/migrations/v2.0/checkout-upstream-files.ts
|
|
4071
|
+
var import_child_process = require("child_process");
|
|
4072
|
+
var UPSTREAM_URL = "https://github.com/opencrvs/opencrvs-countryconfig.git";
|
|
4073
|
+
var UPSTREAM_BRANCH = "develop";
|
|
4074
|
+
var TEMP_REMOTE = "opencrvs-upgrade-v19-v20-codemod";
|
|
4075
|
+
var FILES_TO_CHECKOUT = [
|
|
4076
|
+
"src/analytics/analytics.ts",
|
|
4077
|
+
"Dockerfile",
|
|
4078
|
+
"Dockerfile.assets"
|
|
4079
|
+
];
|
|
4080
|
+
function runGit(args, { silent = false } = {}) {
|
|
4081
|
+
return (0, import_child_process.execFileSync)("git", args, {
|
|
4082
|
+
cwd: process.cwd(),
|
|
4083
|
+
encoding: "utf8",
|
|
4084
|
+
stdio: silent ? ["ignore", "pipe", "pipe"] : ["ignore", "pipe", "inherit"]
|
|
4085
|
+
});
|
|
4086
|
+
}
|
|
4087
|
+
function tryGit(args) {
|
|
4088
|
+
try {
|
|
4089
|
+
runGit(args, { silent: true });
|
|
4090
|
+
return true;
|
|
4091
|
+
} catch {
|
|
2910
4092
|
return false;
|
|
2911
4093
|
}
|
|
2912
|
-
return !SUPPORTED_WORKQUEUE_ACTION_TYPES.has(typeName);
|
|
2913
4094
|
}
|
|
2914
|
-
function
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
const actionsInitializer = actionsProperty.getInitializer();
|
|
2920
|
-
if (!actionsInitializer || !import_ts_morph13.Node.isArrayLiteralExpression(actionsInitializer)) {
|
|
2921
|
-
return 0;
|
|
4095
|
+
function assertIsGitRepo() {
|
|
4096
|
+
if (!tryGit(["rev-parse", "--is-inside-work-tree"])) {
|
|
4097
|
+
throw new Error(
|
|
4098
|
+
`${process.cwd()} is not a git repository. Initialise git (or run the upgrade inside a git checkout) before re-running.`
|
|
4099
|
+
);
|
|
2922
4100
|
}
|
|
2923
|
-
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
|
|
2928
|
-
|
|
2929
|
-
|
|
2930
|
-
|
|
4101
|
+
}
|
|
4102
|
+
async function main22() {
|
|
4103
|
+
console.log(
|
|
4104
|
+
`Checking out ${FILES_TO_CHECKOUT.length} file(s) from ${UPSTREAM_URL}@${UPSTREAM_BRANCH}...
|
|
4105
|
+
`
|
|
4106
|
+
);
|
|
4107
|
+
assertIsGitRepo();
|
|
4108
|
+
tryGit(["remote", "remove", TEMP_REMOTE]);
|
|
4109
|
+
try {
|
|
4110
|
+
console.log(` Adding temporary remote '${TEMP_REMOTE}' \u2192 ${UPSTREAM_URL}`);
|
|
4111
|
+
runGit(["remote", "add", TEMP_REMOTE, UPSTREAM_URL], { silent: true });
|
|
4112
|
+
console.log(` Fetching ${TEMP_REMOTE}/${UPSTREAM_BRANCH} (depth 1)...`);
|
|
4113
|
+
runGit(["fetch", "--depth=1", TEMP_REMOTE, UPSTREAM_BRANCH]);
|
|
4114
|
+
const ref = `${TEMP_REMOTE}/${UPSTREAM_BRANCH}`;
|
|
4115
|
+
const missing = [];
|
|
4116
|
+
let checkedOut = 0;
|
|
4117
|
+
for (const file of FILES_TO_CHECKOUT) {
|
|
4118
|
+
if (tryGit(["checkout", ref, "--", file])) {
|
|
4119
|
+
console.log(` Checked out ${file} from ${ref}`);
|
|
4120
|
+
checkedOut++;
|
|
4121
|
+
} else {
|
|
4122
|
+
console.warn(
|
|
4123
|
+
` [warn] ${file} not found on ${ref} \u2014 skipping. Verify the path exists on that branch.`
|
|
2931
4124
|
);
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
4125
|
+
missing.push(file);
|
|
4126
|
+
}
|
|
4127
|
+
}
|
|
4128
|
+
console.log(
|
|
4129
|
+
`
|
|
4130
|
+
Checked out ${checkedOut}/${FILES_TO_CHECKOUT.length} file(s) from ${ref}.`
|
|
4131
|
+
);
|
|
4132
|
+
if (missing.length > 0) {
|
|
4133
|
+
console.warn(` Missing on upstream branch: ${missing.join(", ")}`);
|
|
4134
|
+
}
|
|
4135
|
+
if (checkedOut > 0) {
|
|
4136
|
+
console.log(
|
|
4137
|
+
` Review the staged changes with: git diff --cached -- ${FILES_TO_CHECKOUT.map(
|
|
4138
|
+
(f) => `'${f}'`
|
|
4139
|
+
).join(" ")}
|
|
4140
|
+
`
|
|
4141
|
+
);
|
|
4142
|
+
}
|
|
4143
|
+
} finally {
|
|
4144
|
+
if (tryGit(["remote", "remove", TEMP_REMOTE])) {
|
|
4145
|
+
console.log(` Removed temporary remote '${TEMP_REMOTE}'.`);
|
|
4146
|
+
}
|
|
4147
|
+
}
|
|
4148
|
+
}
|
|
4149
|
+
|
|
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 EMAIL_TEMPLATES_INDEX = "src/api/notification/email-templates/index.ts";
|
|
4155
|
+
var NOTIFICATION_HANDLER = "src/api/notification/handler.ts";
|
|
4156
|
+
var USER_NOTIFICATION_ROUTES = "src/config/routes/userNotificationRoutes.ts";
|
|
4157
|
+
var SMS_SERVICE = "src/api/notification/sms-service.ts";
|
|
4158
|
+
var NOTIFICATION_CSV = "src/translations/notification.csv";
|
|
4159
|
+
var RESEND_INVITE_HTML = "src/api/notification/email-templates/other/resend-invite.html";
|
|
4160
|
+
var RESEND_INVITE_HTML_CONTENT = `<!doctype html>
|
|
4161
|
+
<html>
|
|
4162
|
+
<head>
|
|
4163
|
+
<link
|
|
4164
|
+
href="https://fonts.googleapis.com/css2?family=Noto+Sans:wght@400;700&display=swap"
|
|
4165
|
+
rel="stylesheet"
|
|
4166
|
+
/>
|
|
4167
|
+
<style type="text/css">
|
|
4168
|
+
body {
|
|
4169
|
+
font-family: 'Noto Sans', sans-serif;
|
|
4170
|
+
color: #222;
|
|
4171
|
+
padding: 16px 24px;
|
|
4172
|
+
}
|
|
4173
|
+
|
|
4174
|
+
h1 {
|
|
4175
|
+
font-size: 21px;
|
|
4176
|
+
margin-top: 32px;
|
|
4177
|
+
margin-bottom: 36px;
|
|
4178
|
+
font-weight: 700;
|
|
4179
|
+
}
|
|
4180
|
+
|
|
4181
|
+
p {
|
|
4182
|
+
font-weight: 400;
|
|
4183
|
+
font-size: 16px;
|
|
4184
|
+
line-height: 1.8;
|
|
4185
|
+
margin-bottom: 24px;
|
|
4186
|
+
}
|
|
4187
|
+
|
|
4188
|
+
i {
|
|
4189
|
+
color: #666;
|
|
4190
|
+
font-weight: 400;
|
|
4191
|
+
font-size: 16px;
|
|
4192
|
+
}
|
|
4193
|
+
</style>
|
|
4194
|
+
</head>
|
|
4195
|
+
|
|
4196
|
+
<body>
|
|
4197
|
+
<img
|
|
4198
|
+
src="{{countryLogo}}"
|
|
4199
|
+
alt="country_logo"
|
|
4200
|
+
style="max-height: 88px; max-width: 100%"
|
|
4201
|
+
/>
|
|
4202
|
+
<h1>Your {{applicationName}} account invitation</h1>
|
|
4203
|
+
<p>Hello {{firstname}},</p>
|
|
4204
|
+
<p>Your account invitation has been resent. Please use the following credentials to access your account:</p>
|
|
4205
|
+
<p>
|
|
4206
|
+
Username: <strong>{{username}}</strong><br />
|
|
4207
|
+
Password: <strong>{{temporaryPassword}}</strong>
|
|
4208
|
+
</p>
|
|
4209
|
+
<p>
|
|
4210
|
+
Please click the link below to complete your account setup and start using
|
|
4211
|
+
{{applicationName}}.
|
|
4212
|
+
</p>
|
|
4213
|
+
|
|
4214
|
+
<div style="margin-top: 32px; margin-bottom: 32px">
|
|
4215
|
+
<a href="{{loginURL}}">Complete setup</a>
|
|
4216
|
+
</div>
|
|
4217
|
+
<br />
|
|
4218
|
+
<p>
|
|
4219
|
+
Best regards, <br />
|
|
4220
|
+
{{applicationName}} Team
|
|
4221
|
+
</p>
|
|
4222
|
+
</body>
|
|
4223
|
+
</html>
|
|
4224
|
+
`;
|
|
4225
|
+
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";
|
|
4226
|
+
function getObjectLiteralFromConst(declaration) {
|
|
4227
|
+
if (!declaration) {
|
|
4228
|
+
return;
|
|
4229
|
+
}
|
|
4230
|
+
const initializer = declaration.getInitializer();
|
|
4231
|
+
if (!initializer) {
|
|
4232
|
+
return;
|
|
4233
|
+
}
|
|
4234
|
+
if (import_ts_morph20.Node.isObjectLiteralExpression(initializer)) {
|
|
4235
|
+
return initializer;
|
|
4236
|
+
}
|
|
4237
|
+
if (import_ts_morph20.Node.isAsExpression(initializer)) {
|
|
4238
|
+
const expression = initializer.getExpression();
|
|
4239
|
+
if (import_ts_morph20.Node.isObjectLiteralExpression(expression)) {
|
|
4240
|
+
return expression;
|
|
4241
|
+
}
|
|
4242
|
+
}
|
|
4243
|
+
}
|
|
4244
|
+
function patchEmailTemplatesIndex() {
|
|
4245
|
+
const full = import_path22.default.join(process.cwd(), EMAIL_TEMPLATES_INDEX);
|
|
4246
|
+
if (!(0, import_fs3.existsSync)(full)) {
|
|
4247
|
+
console.log(` '${EMAIL_TEMPLATES_INDEX}' missing \u2014 skipping.`);
|
|
4248
|
+
return false;
|
|
4249
|
+
}
|
|
4250
|
+
const project = new import_ts_morph20.Project({
|
|
4251
|
+
skipAddingFilesFromTsConfig: true
|
|
4252
|
+
});
|
|
4253
|
+
const sourceFile = project.addSourceFileAtPath(full);
|
|
4254
|
+
let changed = false;
|
|
4255
|
+
const triggerVariableObject = getObjectLiteralFromConst(
|
|
4256
|
+
sourceFile.getVariableDeclaration("TriggerVariable")
|
|
4257
|
+
);
|
|
4258
|
+
if (triggerVariableObject) {
|
|
4259
|
+
const hasResendInviteVariable = triggerVariableObject.getProperties().some((prop) => prop.getText().includes("[TriggerEvent.RESEND_INVITE]"));
|
|
4260
|
+
if (!hasResendInviteVariable) {
|
|
4261
|
+
triggerVariableObject.addPropertyAssignment({
|
|
4262
|
+
name: "[TriggerEvent.RESEND_INVITE]",
|
|
4263
|
+
initializer: `z.object({
|
|
4264
|
+
firstname: z.string(),
|
|
4265
|
+
username: z.string(),
|
|
4266
|
+
temporaryPassword: z.string(),
|
|
4267
|
+
completeSetupUrl: z.string(),
|
|
4268
|
+
loginURL: z.string()
|
|
4269
|
+
})`
|
|
4270
|
+
});
|
|
4271
|
+
changed = true;
|
|
4272
|
+
}
|
|
4273
|
+
}
|
|
4274
|
+
const templatesObject = getObjectLiteralFromConst(
|
|
4275
|
+
sourceFile.getVariableDeclaration("templates")
|
|
4276
|
+
);
|
|
4277
|
+
if (templatesObject) {
|
|
4278
|
+
const hasResendInviteTemplate = templatesObject.getProperties().some(
|
|
4279
|
+
(prop) => prop.getText().includes("readOtherTemplate<TriggerVariable['resend-invite']>")
|
|
4280
|
+
);
|
|
4281
|
+
if (!hasResendInviteTemplate) {
|
|
4282
|
+
const userCreatedIndex = templatesObject.getProperties().findIndex((prop) => prop.getText().includes("[TriggerEvent.USER_CREATED]"));
|
|
4283
|
+
templatesObject.insertPropertyAssignment(
|
|
4284
|
+
userCreatedIndex >= 0 ? userCreatedIndex + 1 : templatesObject.getProperties().length,
|
|
4285
|
+
{
|
|
4286
|
+
name: "[TriggerEvent.RESEND_INVITE]",
|
|
4287
|
+
initializer: `{
|
|
4288
|
+
type: 'resend-invite',
|
|
4289
|
+
subject: 'Your OpenCRVS account invitation',
|
|
4290
|
+
template:
|
|
4291
|
+
readOtherTemplate<TriggerVariable['resend-invite']>('resend-invite')
|
|
4292
|
+
}`
|
|
2943
4293
|
}
|
|
2944
|
-
|
|
4294
|
+
);
|
|
4295
|
+
changed = true;
|
|
2945
4296
|
}
|
|
2946
|
-
actionsProperty.remove();
|
|
2947
|
-
console.log(
|
|
2948
|
-
` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' (existing 'action' kept)`
|
|
2949
|
-
);
|
|
2950
|
-
return 1;
|
|
2951
4297
|
}
|
|
2952
|
-
|
|
2953
|
-
|
|
4298
|
+
if (changed) {
|
|
4299
|
+
sourceFile.saveSync();
|
|
4300
|
+
}
|
|
4301
|
+
return changed;
|
|
4302
|
+
}
|
|
4303
|
+
function patchNotificationHandler() {
|
|
4304
|
+
const full = import_path22.default.join(process.cwd(), NOTIFICATION_HANDLER);
|
|
4305
|
+
if (!(0, import_fs3.existsSync)(full)) {
|
|
4306
|
+
return false;
|
|
4307
|
+
}
|
|
4308
|
+
const project = new import_ts_morph20.Project({ skipAddingFilesFromTsConfig: true });
|
|
4309
|
+
const sourceFile = project.addSourceFileAtPath(full);
|
|
4310
|
+
const convertFn = sourceFile.getFunction("convertPayloadToVariable");
|
|
4311
|
+
if (!convertFn) {
|
|
4312
|
+
return false;
|
|
4313
|
+
}
|
|
4314
|
+
const switchStmt = convertFn.getFirstDescendantByKind(
|
|
4315
|
+
import_ts_morph20.SyntaxKind.SwitchStatement
|
|
2954
4316
|
);
|
|
2955
|
-
if (
|
|
2956
|
-
|
|
2957
|
-
console.log(
|
|
2958
|
-
` [${relPath}] Removed empty 'actions' from workqueue '${workqueueLabel}'`
|
|
2959
|
-
);
|
|
2960
|
-
return 1;
|
|
4317
|
+
if (!switchStmt) {
|
|
4318
|
+
return false;
|
|
2961
4319
|
}
|
|
2962
|
-
|
|
2963
|
-
|
|
2964
|
-
|
|
2965
|
-
|
|
2966
|
-
|
|
4320
|
+
const clauses = switchStmt.getCaseBlock().getClauses();
|
|
4321
|
+
const hasResendInvite = clauses.some(
|
|
4322
|
+
(clause) => import_ts_morph20.Node.isCaseClause(clause) && clause.getExpression().getText() === "TriggerEvent.RESEND_INVITE"
|
|
4323
|
+
);
|
|
4324
|
+
if (hasResendInvite) {
|
|
4325
|
+
return false;
|
|
2967
4326
|
}
|
|
2968
|
-
const
|
|
2969
|
-
|
|
4327
|
+
const userCreatedClauseIndex = clauses.findIndex(
|
|
4328
|
+
(clause) => import_ts_morph20.Node.isCaseClause(clause) && clause.getExpression().getText() === "TriggerEvent.USER_CREATED"
|
|
2970
4329
|
);
|
|
2971
|
-
if (
|
|
2972
|
-
|
|
2973
|
-
console.log(
|
|
2974
|
-
` [${relPath}] Removed deprecated 'conditionals' from migrated 'action' on workqueue '${workqueueLabel}'`
|
|
2975
|
-
);
|
|
4330
|
+
if (userCreatedClauseIndex < 0) {
|
|
4331
|
+
return false;
|
|
2976
4332
|
}
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
|
|
4333
|
+
const userCreatedClause = clauses[userCreatedClauseIndex];
|
|
4334
|
+
sourceFile.insertText(
|
|
4335
|
+
userCreatedClause.getEnd(),
|
|
4336
|
+
`
|
|
4337
|
+
|
|
4338
|
+
case TriggerEvent.RESEND_INVITE:
|
|
4339
|
+
return {
|
|
4340
|
+
firstname,
|
|
4341
|
+
username: payload.username,
|
|
4342
|
+
temporaryPassword: payload.temporaryPassword,
|
|
4343
|
+
completeSetupUrl: LOGIN_URL,
|
|
4344
|
+
loginURL: LOGIN_URL
|
|
4345
|
+
}`
|
|
4346
|
+
);
|
|
4347
|
+
sourceFile.saveSync();
|
|
4348
|
+
return true;
|
|
4349
|
+
}
|
|
4350
|
+
function getReturnedArrayLiteral(functionFilePath, fnName) {
|
|
4351
|
+
const project = new import_ts_morph20.Project({ skipAddingFilesFromTsConfig: true });
|
|
4352
|
+
const sourceFile = project.addSourceFileAtPath(functionFilePath);
|
|
4353
|
+
const fn = sourceFile.getFunction(fnName);
|
|
4354
|
+
const returnStmt = fn?.getFirstDescendantByKind(import_ts_morph20.SyntaxKind.ReturnStatement);
|
|
4355
|
+
const expr = returnStmt?.getExpression();
|
|
4356
|
+
if (!expr || !import_ts_morph20.Node.isArrayLiteralExpression(expr)) {
|
|
4357
|
+
return { sourceFile, arrayLiteral: void 0 };
|
|
4358
|
+
}
|
|
4359
|
+
return { sourceFile, arrayLiteral: expr };
|
|
4360
|
+
}
|
|
4361
|
+
function patchUserNotificationRoutes() {
|
|
4362
|
+
const full = import_path22.default.join(process.cwd(), USER_NOTIFICATION_ROUTES);
|
|
4363
|
+
if (!(0, import_fs3.existsSync)(full)) {
|
|
4364
|
+
return false;
|
|
2983
4365
|
}
|
|
2984
|
-
const
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
initializer: firstActionText
|
|
2988
|
-
});
|
|
2989
|
-
actionsProperty.remove();
|
|
2990
|
-
console.log(
|
|
2991
|
-
` [${relPath}] Replaced 'actions' with 'action' on workqueue '${workqueueLabel}'`
|
|
4366
|
+
const { sourceFile, arrayLiteral } = getReturnedArrayLiteral(
|
|
4367
|
+
full,
|
|
4368
|
+
"getUserNotificationRoutes"
|
|
2992
4369
|
);
|
|
2993
|
-
|
|
4370
|
+
if (!arrayLiteral) {
|
|
4371
|
+
return false;
|
|
4372
|
+
}
|
|
4373
|
+
const routeExists = arrayLiteral.getElements().some((element) => element.getText().includes(`path: '/triggers/user/resend-invite'`));
|
|
4374
|
+
if (routeExists) {
|
|
4375
|
+
return false;
|
|
4376
|
+
}
|
|
4377
|
+
const userCreatedIndex = arrayLiteral.getElements().findIndex((element) => element.getText().includes(`path: '/triggers/user/user-created'`));
|
|
4378
|
+
arrayLiteral.insertElement(
|
|
4379
|
+
userCreatedIndex >= 0 ? userCreatedIndex + 1 : arrayLiteral.getElements().length,
|
|
4380
|
+
`{
|
|
4381
|
+
method: 'POST',
|
|
4382
|
+
path: '/triggers/user/resend-invite',
|
|
4383
|
+
handler: makeNotificationHandler('resend-invite'),
|
|
4384
|
+
options: {
|
|
4385
|
+
auth: false,
|
|
4386
|
+
tags: ['api'],
|
|
4387
|
+
description: 'Handles notification for resent user invite'
|
|
4388
|
+
}
|
|
4389
|
+
}`
|
|
4390
|
+
);
|
|
4391
|
+
sourceFile.saveSync();
|
|
4392
|
+
return true;
|
|
2994
4393
|
}
|
|
2995
|
-
function
|
|
2996
|
-
const
|
|
2997
|
-
if (!
|
|
2998
|
-
|
|
2999
|
-
|
|
3000
|
-
const
|
|
3001
|
-
|
|
4394
|
+
function patchSmsService() {
|
|
4395
|
+
const full = import_path22.default.join(process.cwd(), SMS_SERVICE);
|
|
4396
|
+
if (!(0, import_fs3.existsSync)(full)) {
|
|
4397
|
+
return false;
|
|
4398
|
+
}
|
|
4399
|
+
const project = new import_ts_morph20.Project({ skipAddingFilesFromTsConfig: true });
|
|
4400
|
+
const sourceFile = project.addSourceFileAtPath(full);
|
|
4401
|
+
let changed = false;
|
|
4402
|
+
const otherTemplatesObject = getObjectLiteralFromConst(
|
|
4403
|
+
sourceFile.getVariableDeclaration("otherTemplates")
|
|
3002
4404
|
);
|
|
3003
|
-
|
|
3004
|
-
const
|
|
3005
|
-
if (!
|
|
3006
|
-
|
|
4405
|
+
if (otherTemplatesObject) {
|
|
4406
|
+
const hasResendTemplate = otherTemplatesObject.getProperties().some((prop) => prop.getText().includes("resendInviteNotification"));
|
|
4407
|
+
if (!hasResendTemplate) {
|
|
4408
|
+
const userCredentialsIndex = otherTemplatesObject.getProperties().findIndex((prop) => prop.getText().includes("userCredentialsNotification"));
|
|
4409
|
+
otherTemplatesObject.insertPropertyAssignment(
|
|
4410
|
+
userCredentialsIndex >= 0 ? userCredentialsIndex + 1 : otherTemplatesObject.getProperties().length,
|
|
4411
|
+
{
|
|
4412
|
+
name: "resendInviteNotification",
|
|
4413
|
+
initializer: `'resendInviteNotification'`
|
|
4414
|
+
}
|
|
4415
|
+
);
|
|
4416
|
+
changed = true;
|
|
3007
4417
|
}
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
|
|
3011
|
-
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
|
|
4418
|
+
}
|
|
4419
|
+
const triggerToSmsTemplateObject = getObjectLiteralFromConst(
|
|
4420
|
+
sourceFile.getVariableDeclaration("TriggerToSMSTemplate")
|
|
4421
|
+
);
|
|
4422
|
+
if (triggerToSmsTemplateObject) {
|
|
4423
|
+
const hasResendInviteMap = triggerToSmsTemplateObject.getProperties().some((prop) => prop.getText().includes(`['resend-invite']`));
|
|
4424
|
+
if (!hasResendInviteMap) {
|
|
4425
|
+
const userCreatedIndex = triggerToSmsTemplateObject.getProperties().findIndex((prop) => prop.getText().includes(`['user-created']`));
|
|
4426
|
+
triggerToSmsTemplateObject.insertPropertyAssignment(
|
|
4427
|
+
userCreatedIndex >= 0 ? userCreatedIndex + 1 : triggerToSmsTemplateObject.getProperties().length,
|
|
4428
|
+
{
|
|
4429
|
+
name: `['resend-invite']`,
|
|
4430
|
+
initializer: `'resendInviteNotification'`
|
|
4431
|
+
}
|
|
4432
|
+
);
|
|
4433
|
+
changed = true;
|
|
3015
4434
|
}
|
|
3016
4435
|
}
|
|
3017
|
-
|
|
4436
|
+
if (changed) {
|
|
4437
|
+
sourceFile.saveSync();
|
|
4438
|
+
}
|
|
4439
|
+
return changed;
|
|
3018
4440
|
}
|
|
3019
|
-
async function
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
|
|
3030
|
-
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
|
-
let totalMigrated = 0;
|
|
3034
|
-
const modifiedFiles = [];
|
|
3035
|
-
for (const sourceFile of sourceFiles) {
|
|
3036
|
-
const filePath = sourceFile.getFilePath();
|
|
3037
|
-
const migrated = processFile11(filePath, project);
|
|
3038
|
-
if (migrated > 0) {
|
|
3039
|
-
totalMigrated += migrated;
|
|
3040
|
-
modifiedFiles.push(filePath);
|
|
4441
|
+
async function main23() {
|
|
4442
|
+
console.log("Adding RESEND_INVITE notification wiring\u2026");
|
|
4443
|
+
const touched = [];
|
|
4444
|
+
if (patchEmailTemplatesIndex()) touched.push(EMAIL_TEMPLATES_INDEX);
|
|
4445
|
+
if (patchNotificationHandler()) touched.push(NOTIFICATION_HANDLER);
|
|
4446
|
+
if (patchUserNotificationRoutes()) touched.push(USER_NOTIFICATION_ROUTES);
|
|
4447
|
+
if (patchSmsService()) touched.push(SMS_SERVICE);
|
|
4448
|
+
const csvPath = import_path22.default.join(process.cwd(), NOTIFICATION_CSV);
|
|
4449
|
+
if ((0, import_fs3.existsSync)(csvPath)) {
|
|
4450
|
+
let t = (0, import_fs3.readFileSync)(csvPath, "utf8");
|
|
4451
|
+
if (!/^resendInviteNotification,/m.test(t)) {
|
|
4452
|
+
if (!t.endsWith("\n")) t += "\n";
|
|
4453
|
+
(0, import_fs3.writeFileSync)(csvPath, t + CSV_ROW);
|
|
4454
|
+
touched.push(NOTIFICATION_CSV);
|
|
3041
4455
|
}
|
|
3042
4456
|
}
|
|
3043
|
-
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
);
|
|
3047
|
-
|
|
4457
|
+
const htmlPath = import_path22.default.join(process.cwd(), RESEND_INVITE_HTML);
|
|
4458
|
+
(0, import_fs3.mkdirSync)(import_path22.default.dirname(htmlPath), { recursive: true });
|
|
4459
|
+
if (!(0, import_fs3.existsSync)(htmlPath)) {
|
|
4460
|
+
(0, import_fs3.writeFileSync)(htmlPath, RESEND_INVITE_HTML_CONTENT);
|
|
4461
|
+
touched.push(RESEND_INVITE_HTML);
|
|
3048
4462
|
}
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
3053
|
-
await sourceFile.save();
|
|
3054
|
-
console.log(` Saved: ${import_path13.default.relative(getCwd(), filePath)}`);
|
|
4463
|
+
if (touched.length === 0) {
|
|
4464
|
+
console.log(" Nothing to update (already present or anchors not found).");
|
|
4465
|
+
return;
|
|
3055
4466
|
}
|
|
3056
|
-
console.log(
|
|
3057
|
-
`
|
|
3058
|
-
Done. Migrated ${totalMigrated} deprecated workqueue 'actions' definition(s) to 'action'.`
|
|
3059
|
-
);
|
|
4467
|
+
console.log(` Updated:
|
|
4468
|
+
${touched.map((f) => ` - ${f}`).join("\n")}`);
|
|
3060
4469
|
}
|
|
3061
4470
|
|
|
3062
|
-
// src/migrations/v2.0/
|
|
3063
|
-
var
|
|
3064
|
-
var
|
|
3065
|
-
var
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
const
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
4471
|
+
// src/migrations/v2.0/simplify-analytics-precalculations.ts
|
|
4472
|
+
var import_ts_morph21 = require("ts-morph");
|
|
4473
|
+
var import_fs4 = __toESM(require("fs"));
|
|
4474
|
+
var import_path23 = __toESM(require("path"));
|
|
4475
|
+
var ANALYTICS_FILE_REL = "src/analytics/analytics.ts";
|
|
4476
|
+
var FUNCTION_NAME = "precalculateAdditionalAnalytics";
|
|
4477
|
+
var IMPORT_NAMES_TO_REMOVE = /* @__PURE__ */ new Set(["Event", "precalculateBirthEvent"]);
|
|
4478
|
+
var RETURN_EXPRESSION_TEXT = "declaration";
|
|
4479
|
+
function removeTargetedNamedImports(sourceFile) {
|
|
4480
|
+
const log = [];
|
|
4481
|
+
for (const importDecl of [...sourceFile.getImportDeclarations()]) {
|
|
4482
|
+
const namedImports = importDecl.getNamedImports();
|
|
4483
|
+
if (namedImports.length === 0) continue;
|
|
4484
|
+
const matched = namedImports.filter(
|
|
4485
|
+
(ni) => IMPORT_NAMES_TO_REMOVE.has(ni.getName())
|
|
3076
4486
|
);
|
|
3077
|
-
|
|
4487
|
+
if (matched.length === 0) continue;
|
|
4488
|
+
const removedNames = matched.map((ni) => ni.getName());
|
|
4489
|
+
for (const ni of matched) ni.remove();
|
|
4490
|
+
log.push(
|
|
4491
|
+
`removed import(s) ${removedNames.join(", ")} from '${importDecl.getModuleSpecifierValue()}'`
|
|
4492
|
+
);
|
|
4493
|
+
const stillUsed = importDecl.getNamedImports().length > 0 || importDecl.getDefaultImport() || importDecl.getNamespaceImport();
|
|
4494
|
+
if (!stillUsed) importDecl.remove();
|
|
3078
4495
|
}
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
)
|
|
3083
|
-
|
|
3084
|
-
constantsImport.remove();
|
|
3085
|
-
changed = true;
|
|
4496
|
+
return log;
|
|
4497
|
+
}
|
|
4498
|
+
function findPrecalculateFunction(sourceFile) {
|
|
4499
|
+
for (const fn of sourceFile.getFunctions()) {
|
|
4500
|
+
if (fn.getName() === FUNCTION_NAME) return fn;
|
|
3086
4501
|
}
|
|
3087
|
-
const
|
|
3088
|
-
|
|
4502
|
+
for (const statement of sourceFile.getVariableStatements()) {
|
|
4503
|
+
for (const decl of statement.getDeclarations()) {
|
|
4504
|
+
if (decl.getName() === FUNCTION_NAME) return decl;
|
|
4505
|
+
}
|
|
4506
|
+
}
|
|
4507
|
+
return void 0;
|
|
4508
|
+
}
|
|
4509
|
+
function getFunctionBodyBlock(fn) {
|
|
4510
|
+
if (import_ts_morph21.Node.isFunctionDeclaration(fn)) return fn.getBody();
|
|
4511
|
+
const initializer = fn.getInitializer();
|
|
4512
|
+
if (!initializer) return void 0;
|
|
4513
|
+
if (!import_ts_morph21.Node.isArrowFunction(initializer) && !import_ts_morph21.Node.isFunctionExpression(initializer)) {
|
|
4514
|
+
return void 0;
|
|
4515
|
+
}
|
|
4516
|
+
return initializer.getBody();
|
|
4517
|
+
}
|
|
4518
|
+
function simplifyPrecalculateFunction(sourceFile) {
|
|
4519
|
+
const log = [];
|
|
4520
|
+
const fn = findPrecalculateFunction(sourceFile);
|
|
4521
|
+
if (!fn) return log;
|
|
4522
|
+
const body = getFunctionBodyBlock(fn);
|
|
4523
|
+
if (!body || !import_ts_morph21.Node.isBlock(body)) return log;
|
|
4524
|
+
for (const statement of [...body.getStatements()]) {
|
|
4525
|
+
const references = statement.getDescendantsOfKind(import_ts_morph21.SyntaxKind.Identifier).some((id) => IMPORT_NAMES_TO_REMOVE.has(id.getText()));
|
|
4526
|
+
if (references) {
|
|
4527
|
+
statement.remove();
|
|
4528
|
+
log.push(`removed statement in ${FUNCTION_NAME} referencing removed imports`);
|
|
4529
|
+
}
|
|
4530
|
+
}
|
|
4531
|
+
const remaining = body.getStatements();
|
|
4532
|
+
const last = remaining[remaining.length - 1];
|
|
4533
|
+
const alreadyCorrect = last && import_ts_morph21.Node.isReturnStatement(last) && last.getExpression()?.getText() === RETURN_EXPRESSION_TEXT;
|
|
4534
|
+
if (!alreadyCorrect) {
|
|
4535
|
+
body.addStatements(`return ${RETURN_EXPRESSION_TEXT}`);
|
|
4536
|
+
log.push(
|
|
4537
|
+
`ensured '${FUNCTION_NAME}' ends with 'return ${RETURN_EXPRESSION_TEXT}'`
|
|
4538
|
+
);
|
|
4539
|
+
}
|
|
4540
|
+
return log;
|
|
4541
|
+
}
|
|
4542
|
+
async function main24() {
|
|
4543
|
+
const cwd = process.cwd();
|
|
4544
|
+
const absPath = import_path23.default.join(cwd, ANALYTICS_FILE_REL);
|
|
4545
|
+
if (!import_fs4.default.existsSync(absPath)) {
|
|
3089
4546
|
console.log(
|
|
3090
|
-
`
|
|
4547
|
+
`[${ANALYTICS_FILE_REL}] does not exist \u2014 nothing to clean up.`
|
|
3091
4548
|
);
|
|
3092
4549
|
return;
|
|
3093
4550
|
}
|
|
3094
|
-
const
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
const
|
|
3099
|
-
|
|
3100
|
-
if (normalizedCurrent !== normalizedDesired) {
|
|
3101
|
-
rolesHandler.setBodyText(`return ${responseToolkitIdentifier}.response(roles)`);
|
|
3102
|
-
changed = true;
|
|
3103
|
-
}
|
|
3104
|
-
if (!changed) {
|
|
4551
|
+
const project = new import_ts_morph21.Project({
|
|
4552
|
+
tsConfigFilePath: import_path23.default.resolve(cwd, "tsconfig.json"),
|
|
4553
|
+
skipAddingFilesFromTsConfig: false
|
|
4554
|
+
});
|
|
4555
|
+
const sourceFile = project.getSourceFile(absPath);
|
|
4556
|
+
if (!sourceFile) {
|
|
3105
4557
|
console.log(
|
|
3106
|
-
`
|
|
4558
|
+
`[${ANALYTICS_FILE_REL}] is not part of the tsconfig project. Skipping.`
|
|
3107
4559
|
);
|
|
3108
4560
|
return;
|
|
3109
4561
|
}
|
|
4562
|
+
console.log(`Cleaning up ${ANALYTICS_FILE_REL}...
|
|
4563
|
+
`);
|
|
4564
|
+
const importLogs = removeTargetedNamedImports(sourceFile);
|
|
4565
|
+
const fnLogs = simplifyPrecalculateFunction(sourceFile);
|
|
4566
|
+
const allLogs = [...importLogs, ...fnLogs];
|
|
4567
|
+
if (allLogs.length === 0) {
|
|
4568
|
+
console.log(`[${ANALYTICS_FILE_REL}] already clean \u2014 nothing to do.`);
|
|
4569
|
+
return;
|
|
4570
|
+
}
|
|
4571
|
+
for (const log of allLogs) {
|
|
4572
|
+
console.log(` [${ANALYTICS_FILE_REL}] ${log}`);
|
|
4573
|
+
}
|
|
3110
4574
|
await sourceFile.save();
|
|
3111
|
-
console.log(
|
|
3112
|
-
|
|
3113
|
-
);
|
|
4575
|
+
console.log(`
|
|
4576
|
+
Saved ${ANALYTICS_FILE_REL}.`);
|
|
3114
4577
|
}
|
|
3115
4578
|
|
|
3116
|
-
// src/migrations/v2.0/
|
|
3117
|
-
var
|
|
3118
|
-
var
|
|
3119
|
-
var
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
|
|
3127
|
-
|
|
3128
|
-
|
|
3129
|
-
|
|
3130
|
-
|
|
3131
|
-
|
|
3132
|
-
|
|
3133
|
-
if (fs2.existsSync(absolutePath)) {
|
|
3134
|
-
fs2.rmSync(absolutePath, { recursive: true, force: true });
|
|
3135
|
-
console.log(`Removed ${label} '${relativePath}'.`);
|
|
3136
|
-
} else {
|
|
3137
|
-
console.log(`No ${label} found at '${relativePath}'.`);
|
|
3138
|
-
}
|
|
4579
|
+
// src/migrations/v2.0/merge-infrastructure-directory.ts
|
|
4580
|
+
var import_child_process2 = require("child_process");
|
|
4581
|
+
var import_fs5 = require("fs");
|
|
4582
|
+
var import_os = require("os");
|
|
4583
|
+
var import_path24 = require("path");
|
|
4584
|
+
var TEMP_REMOTE2 = "opencrvs-upgrade-v19-v20-codemod-merge-infra";
|
|
4585
|
+
var INFRASTRUCTURE_DIR = "infrastructure";
|
|
4586
|
+
var BASE_BRANCH = "release-v1.9";
|
|
4587
|
+
function gitShowBytes(ref, path23) {
|
|
4588
|
+
try {
|
|
4589
|
+
const buf = (0, import_child_process2.execFileSync)("git", ["show", `${ref}:${path23}`], {
|
|
4590
|
+
cwd: process.cwd(),
|
|
4591
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
4592
|
+
});
|
|
4593
|
+
return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
4594
|
+
} catch {
|
|
4595
|
+
return null;
|
|
3139
4596
|
}
|
|
3140
4597
|
}
|
|
3141
|
-
|
|
3142
|
-
|
|
3143
|
-
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
|
|
4598
|
+
async function main25() {
|
|
4599
|
+
console.log(
|
|
4600
|
+
`Merging '${INFRASTRUCTURE_DIR}/' from ${UPSTREAM_URL}@${UPSTREAM_BRANCH} (base: ${BASE_BRANCH})...
|
|
4601
|
+
`
|
|
4602
|
+
);
|
|
4603
|
+
assertIsGitRepo();
|
|
4604
|
+
tryGit(["remote", "remove", TEMP_REMOTE2]);
|
|
4605
|
+
try {
|
|
4606
|
+
console.log(` Adding temporary remote '${TEMP_REMOTE2}' \u2192 ${UPSTREAM_URL}`);
|
|
4607
|
+
runGit(["remote", "add", TEMP_REMOTE2, UPSTREAM_URL], { silent: true });
|
|
4608
|
+
console.log(
|
|
4609
|
+
` Fetching ${TEMP_REMOTE2}/{${UPSTREAM_BRANCH},${BASE_BRANCH}} (depth 1)...`
|
|
4610
|
+
);
|
|
4611
|
+
runGit(["fetch", "--depth=1", TEMP_REMOTE2, UPSTREAM_BRANCH, BASE_BRANCH]);
|
|
4612
|
+
const ref = `${TEMP_REMOTE2}/${UPSTREAM_BRANCH}`;
|
|
4613
|
+
const baseRef = `${TEMP_REMOTE2}/${BASE_BRANCH}`;
|
|
4614
|
+
const upstreamFiles = runGit(
|
|
4615
|
+
[
|
|
4616
|
+
"ls-tree",
|
|
4617
|
+
"-r",
|
|
4618
|
+
"--name-only",
|
|
4619
|
+
"-z",
|
|
4620
|
+
ref,
|
|
4621
|
+
"--",
|
|
4622
|
+
`${INFRASTRUCTURE_DIR}/`
|
|
4623
|
+
],
|
|
4624
|
+
{ silent: true }
|
|
4625
|
+
).split("\0").filter(Boolean);
|
|
4626
|
+
if (upstreamFiles.length === 0) {
|
|
4627
|
+
console.log(
|
|
4628
|
+
` No files found under '${INFRASTRUCTURE_DIR}/' on ${ref}. Nothing to merge.`
|
|
4629
|
+
);
|
|
4630
|
+
return;
|
|
4631
|
+
}
|
|
4632
|
+
const tmpDir = (0, import_fs5.mkdtempSync)((0, import_path24.join)((0, import_os.tmpdir)(), "opencrvs-merge-infra-"));
|
|
4633
|
+
const baseTmp = (0, import_path24.join)(tmpDir, "base");
|
|
4634
|
+
const theirsTmp = (0, import_path24.join)(tmpDir, "theirs");
|
|
4635
|
+
let added = 0;
|
|
4636
|
+
let merged = 0;
|
|
4637
|
+
const conflictedFiles = [];
|
|
4638
|
+
for (const file of upstreamFiles) {
|
|
4639
|
+
const fullPath = (0, import_path24.join)(process.cwd(), file);
|
|
4640
|
+
if (!(0, import_fs5.existsSync)(fullPath)) {
|
|
4641
|
+
if (tryGit(["checkout", ref, "--", file])) {
|
|
4642
|
+
console.log(` + ${file} (new from upstream)`);
|
|
4643
|
+
added++;
|
|
4644
|
+
} else {
|
|
4645
|
+
console.warn(` [warn] failed to add new file ${file}`);
|
|
4646
|
+
}
|
|
4647
|
+
continue;
|
|
4648
|
+
}
|
|
4649
|
+
const theirContents = gitShowBytes(ref, file);
|
|
4650
|
+
if (theirContents === null) {
|
|
4651
|
+
console.warn(` [warn] could not read ${file} from ${ref} \u2014 skipping.`);
|
|
4652
|
+
continue;
|
|
4653
|
+
}
|
|
4654
|
+
(0, import_fs5.writeFileSync)(theirsTmp, theirContents);
|
|
4655
|
+
const baseContents = gitShowBytes(baseRef, file);
|
|
4656
|
+
(0, import_fs5.writeFileSync)(baseTmp, baseContents ?? new Uint8Array(0));
|
|
4657
|
+
try {
|
|
4658
|
+
(0, import_child_process2.execFileSync)("git", ["merge-file", fullPath, baseTmp, theirsTmp], {
|
|
4659
|
+
cwd: process.cwd(),
|
|
4660
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
4661
|
+
});
|
|
4662
|
+
runGit(["add", "--", file], { silent: true });
|
|
4663
|
+
merged++;
|
|
4664
|
+
} catch (err) {
|
|
4665
|
+
const status = err.status;
|
|
4666
|
+
if (typeof status === "number" && status > 0) {
|
|
4667
|
+
conflictedFiles.push(file);
|
|
4668
|
+
console.warn(
|
|
4669
|
+
` ! ${file} (${status} conflict${status > 1 ? "s" : ""})`
|
|
4670
|
+
);
|
|
4671
|
+
} else {
|
|
4672
|
+
conflictedFiles.push(file);
|
|
4673
|
+
console.warn(
|
|
4674
|
+
` [warn] merge failed for ${file} (likely binary or unreadable) \u2014 left untouched.`
|
|
4675
|
+
);
|
|
4676
|
+
}
|
|
4677
|
+
}
|
|
4678
|
+
}
|
|
4679
|
+
console.log(
|
|
4680
|
+
`
|
|
4681
|
+
Done. ${added} added, ${merged} merged cleanly, ${conflictedFiles.length} with conflicts.`
|
|
4682
|
+
);
|
|
4683
|
+
if (conflictedFiles.length > 0) {
|
|
4684
|
+
console.warn(
|
|
4685
|
+
`
|
|
4686
|
+
NOTE: ${conflictedFiles.length} file(s) under '${INFRASTRUCTURE_DIR}/' have merge conflicts that you must resolve manually.
|
|
4687
|
+
Look for the standard conflict markers (<<<<<<<, =======, >>>>>>>) in:
|
|
4688
|
+
` + conflictedFiles.map((f) => ` - ${f}`).join("\n") + `
|
|
4689
|
+
After resolving, stage the fixes with: git add ${INFRASTRUCTURE_DIR}/`
|
|
4690
|
+
);
|
|
4691
|
+
}
|
|
4692
|
+
} finally {
|
|
4693
|
+
if (tryGit(["remote", "remove", TEMP_REMOTE2])) {
|
|
4694
|
+
console.log(` Removed temporary remote '${TEMP_REMOTE2}'.`);
|
|
4695
|
+
}
|
|
3147
4696
|
}
|
|
3148
|
-
return cwd;
|
|
3149
4697
|
}
|
|
3150
|
-
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
4698
|
+
|
|
4699
|
+
// src/migrations/v2.0/delete-infrastructure-directory.ts
|
|
4700
|
+
var import_fs6 = require("fs");
|
|
4701
|
+
var import_path25 = require("path");
|
|
4702
|
+
var INFRASTRUCTURE_DIR2 = "infrastructure";
|
|
4703
|
+
async function main26() {
|
|
4704
|
+
const fullPath = (0, import_path25.join)(process.cwd(), INFRASTRUCTURE_DIR2);
|
|
4705
|
+
if (!(0, import_fs6.existsSync)(fullPath)) {
|
|
3156
4706
|
console.log(
|
|
3157
|
-
|
|
4707
|
+
`'${INFRASTRUCTURE_DIR2}/' not found in ${process.cwd()} \u2014 nothing to delete.`
|
|
3158
4708
|
);
|
|
3159
|
-
|
|
4709
|
+
return;
|
|
3160
4710
|
}
|
|
3161
|
-
|
|
4711
|
+
console.log(`Deleting '${INFRASTRUCTURE_DIR2}/'...
|
|
4712
|
+
`);
|
|
4713
|
+
assertIsGitRepo();
|
|
4714
|
+
runGit(["rm", "-rf", "--ignore-unmatch", "--", `${INFRASTRUCTURE_DIR2}/`], {
|
|
4715
|
+
silent: true
|
|
4716
|
+
});
|
|
4717
|
+
console.log(` Staged deletion of tracked files under '${INFRASTRUCTURE_DIR2}/'.`);
|
|
4718
|
+
if ((0, import_fs6.existsSync)(fullPath)) {
|
|
4719
|
+
(0, import_fs6.rmSync)(fullPath, { recursive: true, force: true });
|
|
4720
|
+
console.log(` Removed remaining untracked files under '${INFRASTRUCTURE_DIR2}/'.`);
|
|
4721
|
+
}
|
|
4722
|
+
console.log(
|
|
4723
|
+
`
|
|
4724
|
+
Done. Review the staged deletion with: git diff --cached -- '${INFRASTRUCTURE_DIR2}/'`
|
|
4725
|
+
);
|
|
4726
|
+
}
|
|
4727
|
+
|
|
4728
|
+
// src/migrations/v2.0/index.ts
|
|
4729
|
+
async function runUpgrade(dockerSwarm) {
|
|
4730
|
+
await main18();
|
|
3162
4731
|
await main();
|
|
3163
4732
|
await main2();
|
|
3164
4733
|
await main3();
|
|
@@ -3171,6 +4740,20 @@ async function runUpgrade(ccwd) {
|
|
|
3171
4740
|
await main10();
|
|
3172
4741
|
await main11();
|
|
3173
4742
|
await main12();
|
|
4743
|
+
await main13();
|
|
3174
4744
|
await main14();
|
|
3175
4745
|
await main15();
|
|
4746
|
+
await main16();
|
|
4747
|
+
await main19();
|
|
4748
|
+
await main20();
|
|
4749
|
+
await main21();
|
|
4750
|
+
await main22();
|
|
4751
|
+
await main23();
|
|
4752
|
+
await main24();
|
|
4753
|
+
await main17();
|
|
4754
|
+
if (dockerSwarm) {
|
|
4755
|
+
await main25();
|
|
4756
|
+
} else {
|
|
4757
|
+
await main26();
|
|
4758
|
+
}
|
|
3176
4759
|
}
|