@opencrvs/toolkit 1.9.12-rc.a9b25f0 → 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/notification/UserNotifications.d.ts +15 -0
- package/dist/events/index.js +17 -3
- 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 +10 -1
- 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.a9b25f0.tgz +0 -0
package/dist/cli.js
CHANGED
|
@@ -91,7 +91,7 @@ function processFile(filePath, project) {
|
|
|
91
91
|
if (wasRemoved) {
|
|
92
92
|
removedCount++;
|
|
93
93
|
console.log(
|
|
94
|
-
` [${import_path.default.relative(
|
|
94
|
+
` [${import_path.default.relative(process.cwd(), filePath)}] Removed 'review' from REGISTER action`
|
|
95
95
|
);
|
|
96
96
|
}
|
|
97
97
|
}
|
|
@@ -99,7 +99,7 @@ function processFile(filePath, project) {
|
|
|
99
99
|
return removedCount;
|
|
100
100
|
}
|
|
101
101
|
async function main() {
|
|
102
|
-
const srcDir = import_path.default.join(
|
|
102
|
+
const srcDir = import_path.default.join(process.cwd(), "src");
|
|
103
103
|
console.log(`Scanning for defineConfig calls in: ${srcDir}
|
|
104
104
|
`);
|
|
105
105
|
const project = new import_ts_morph.Project({
|
|
@@ -135,7 +135,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
135
135
|
for (const filePath of modifiedFiles) {
|
|
136
136
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
137
137
|
await sourceFile.save();
|
|
138
|
-
console.log(` Saved: ${import_path.default.relative(
|
|
138
|
+
console.log(` Saved: ${import_path.default.relative(process.cwd(), filePath)}`);
|
|
139
139
|
}
|
|
140
140
|
console.log(
|
|
141
141
|
`
|
|
@@ -338,7 +338,7 @@ function processFile2(filePath, project) {
|
|
|
338
338
|
const eventType = resolveEventType(configArg);
|
|
339
339
|
if (!eventType) {
|
|
340
340
|
console.warn(
|
|
341
|
-
` [${import_path2.default.relative(
|
|
341
|
+
` [${import_path2.default.relative(process.cwd(), configArg.getSourceFile().getFilePath())}] Could not resolve root 'type' from defineConfig \u2014 skipping auditHistoryLabel id generation`
|
|
342
342
|
);
|
|
343
343
|
}
|
|
344
344
|
let fileNeedsImports = false;
|
|
@@ -354,7 +354,7 @@ function processFile2(filePath, project) {
|
|
|
354
354
|
fileNeedsImports = true;
|
|
355
355
|
configHadValidateAction = true;
|
|
356
356
|
console.log(
|
|
357
|
-
` [${import_path2.default.relative(
|
|
357
|
+
` [${import_path2.default.relative(process.cwd(), filePath)}] Transformed VALIDATE action to CUSTOM with customActionType: '${VALIDATE_DECLARATION_VALUE}'`
|
|
358
358
|
);
|
|
359
359
|
}
|
|
360
360
|
}
|
|
@@ -375,7 +375,7 @@ function processFile2(filePath, project) {
|
|
|
375
375
|
]`
|
|
376
376
|
});
|
|
377
377
|
console.log(
|
|
378
|
-
` [${import_path2.default.relative(
|
|
378
|
+
` [${import_path2.default.relative(process.cwd(), filePath)}] Added top-level 'flags' array to defineConfig`
|
|
379
379
|
);
|
|
380
380
|
}
|
|
381
381
|
if (fileNeedsImports) {
|
|
@@ -385,7 +385,7 @@ function processFile2(filePath, project) {
|
|
|
385
385
|
return transformedCount;
|
|
386
386
|
}
|
|
387
387
|
async function main2() {
|
|
388
|
-
const srcDir = import_path2.default.join(
|
|
388
|
+
const srcDir = import_path2.default.join(process.cwd(), "src");
|
|
389
389
|
console.log(`Scanning for defineConfig calls in: ${srcDir}
|
|
390
390
|
`);
|
|
391
391
|
const project = new import_ts_morph2.Project({
|
|
@@ -420,7 +420,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
420
420
|
for (const filePath of modifiedFiles) {
|
|
421
421
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
422
422
|
await sourceFile.save();
|
|
423
|
-
console.log(` Saved: ${import_path2.default.relative(
|
|
423
|
+
console.log(` Saved: ${import_path2.default.relative(process.cwd(), filePath)}`);
|
|
424
424
|
}
|
|
425
425
|
console.log(
|
|
426
426
|
`
|
|
@@ -491,14 +491,14 @@ function processFile3(filePath, project) {
|
|
|
491
491
|
actionsInitializer.removeElement(index);
|
|
492
492
|
removedCount++;
|
|
493
493
|
console.log(
|
|
494
|
-
` [${import_path3.default.relative(
|
|
494
|
+
` [${import_path3.default.relative(process.cwd(), filePath)}] Removed DELETE action at index ${index}`
|
|
495
495
|
);
|
|
496
496
|
}
|
|
497
497
|
}
|
|
498
498
|
return removedCount;
|
|
499
499
|
}
|
|
500
500
|
async function main3() {
|
|
501
|
-
const srcDir = import_path3.default.join(
|
|
501
|
+
const srcDir = import_path3.default.join(process.cwd(), "src");
|
|
502
502
|
console.log(`Scanning for defineConfig calls in: ${srcDir}
|
|
503
503
|
`);
|
|
504
504
|
const project = new import_ts_morph3.Project({
|
|
@@ -533,7 +533,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
533
533
|
for (const filePath of modifiedFiles) {
|
|
534
534
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
535
535
|
await sourceFile.save();
|
|
536
|
-
console.log(` Saved: ${import_path3.default.relative(
|
|
536
|
+
console.log(` Saved: ${import_path3.default.relative(process.cwd(), filePath)}`);
|
|
537
537
|
}
|
|
538
538
|
console.log(
|
|
539
539
|
`
|
|
@@ -607,19 +607,19 @@ function processFile4(filePath, project) {
|
|
|
607
607
|
if (result === "converted-to-heading") {
|
|
608
608
|
changedCount++;
|
|
609
609
|
console.log(
|
|
610
|
-
` [${import_path4.default.relative(
|
|
610
|
+
` [${import_path4.default.relative(process.cwd(), filePath)}] Converted PARAGRAPH with heading fontVariant to HEADING`
|
|
611
611
|
);
|
|
612
612
|
} else if (result === "removed-font-variant") {
|
|
613
613
|
changedCount++;
|
|
614
614
|
console.log(
|
|
615
|
-
` [${import_path4.default.relative(
|
|
615
|
+
` [${import_path4.default.relative(process.cwd(), filePath)}] Removed non-heading fontVariant from PARAGRAPH`
|
|
616
616
|
);
|
|
617
617
|
}
|
|
618
618
|
}
|
|
619
619
|
return changedCount;
|
|
620
620
|
}
|
|
621
621
|
async function main4() {
|
|
622
|
-
const srcDir = import_path4.default.join(
|
|
622
|
+
const srcDir = import_path4.default.join(process.cwd(), "src");
|
|
623
623
|
console.log(`Scanning for FieldType.PARAGRAPH fields in: ${srcDir}
|
|
624
624
|
`);
|
|
625
625
|
const project = new import_ts_morph4.Project({
|
|
@@ -653,7 +653,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
653
653
|
for (const filePath of modifiedFiles) {
|
|
654
654
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
655
655
|
await sourceFile.save();
|
|
656
|
-
console.log(` Saved: ${import_path4.default.relative(
|
|
656
|
+
console.log(` Saved: ${import_path4.default.relative(process.cwd(), filePath)}`);
|
|
657
657
|
}
|
|
658
658
|
console.log(`
|
|
659
659
|
Done. Processed ${totalChanged} FieldType.PARAGRAPH field(s).`);
|
|
@@ -803,7 +803,7 @@ function processFile5(filePath, project) {
|
|
|
803
803
|
if (changed > 0) {
|
|
804
804
|
migratedCount += changed;
|
|
805
805
|
console.log(
|
|
806
|
-
` [${import_path5.default.relative(
|
|
806
|
+
` [${import_path5.default.relative(process.cwd(), filePath)}] Migrated ${changed} clause(s): VALIDATED status \u2192 flags.anyOf`
|
|
807
807
|
);
|
|
808
808
|
}
|
|
809
809
|
}
|
|
@@ -811,7 +811,7 @@ function processFile5(filePath, project) {
|
|
|
811
811
|
return migratedCount;
|
|
812
812
|
}
|
|
813
813
|
async function main5() {
|
|
814
|
-
const srcDir = import_path5.default.join(
|
|
814
|
+
const srcDir = import_path5.default.join(process.cwd(), "src");
|
|
815
815
|
console.log(`Scanning for defineWorkqueues calls in: ${srcDir}
|
|
816
816
|
`);
|
|
817
817
|
const project = new import_ts_morph5.Project({
|
|
@@ -845,7 +845,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
845
845
|
for (const filePath of modifiedFiles) {
|
|
846
846
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
847
847
|
await sourceFile.save();
|
|
848
|
-
console.log(` Saved: ${import_path5.default.relative(
|
|
848
|
+
console.log(` Saved: ${import_path5.default.relative(process.cwd(), filePath)}`);
|
|
849
849
|
}
|
|
850
850
|
console.log(
|
|
851
851
|
`
|
|
@@ -1063,7 +1063,7 @@ function processFile6(filePath, project) {
|
|
|
1063
1063
|
const sourceFile = project.getSourceFile(filePath);
|
|
1064
1064
|
if (!sourceFile) return 0;
|
|
1065
1065
|
let totalChanges = 0;
|
|
1066
|
-
const relPath = import_path6.default.relative(
|
|
1066
|
+
const relPath = import_path6.default.relative(process.cwd(), filePath);
|
|
1067
1067
|
const callExpressions = sourceFile.getDescendantsOfKind(
|
|
1068
1068
|
import_ts_morph6.SyntaxKind.CallExpression
|
|
1069
1069
|
);
|
|
@@ -1104,7 +1104,7 @@ function processFile6(filePath, project) {
|
|
|
1104
1104
|
return totalChanges;
|
|
1105
1105
|
}
|
|
1106
1106
|
async function main6() {
|
|
1107
|
-
const srcDir = import_path6.default.join(
|
|
1107
|
+
const srcDir = import_path6.default.join(process.cwd(), "src");
|
|
1108
1108
|
console.log(
|
|
1109
1109
|
`Scanning for birth defineConfig and PRINT_CERTIFICATE workqueues in: ${srcDir}
|
|
1110
1110
|
`
|
|
@@ -1140,7 +1140,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
1140
1140
|
for (const filePath of modifiedFiles) {
|
|
1141
1141
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
1142
1142
|
await sourceFile.save();
|
|
1143
|
-
console.log(` Saved: ${import_path6.default.relative(
|
|
1143
|
+
console.log(` Saved: ${import_path6.default.relative(process.cwd(), filePath)}`);
|
|
1144
1144
|
}
|
|
1145
1145
|
console.log(
|
|
1146
1146
|
`
|
|
@@ -1177,14 +1177,14 @@ function processFile7(filePath, project) {
|
|
|
1177
1177
|
array3.removeElement(index);
|
|
1178
1178
|
removedCount++;
|
|
1179
1179
|
console.log(
|
|
1180
|
-
` [${import_path7.default.relative(
|
|
1180
|
+
` [${import_path7.default.relative(process.cwd(), filePath)}] Removed InherentFlags.PENDING_CERTIFICATION from array`
|
|
1181
1181
|
);
|
|
1182
1182
|
}
|
|
1183
1183
|
}
|
|
1184
1184
|
return removedCount;
|
|
1185
1185
|
}
|
|
1186
1186
|
async function main7() {
|
|
1187
|
-
const srcDir = import_path7.default.join(
|
|
1187
|
+
const srcDir = import_path7.default.join(process.cwd(), "src");
|
|
1188
1188
|
console.log(
|
|
1189
1189
|
`Scanning for InherentFlags.PENDING_CERTIFICATION array elements in: ${srcDir}
|
|
1190
1190
|
`
|
|
@@ -1220,7 +1220,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
1220
1220
|
for (const filePath of modifiedFiles) {
|
|
1221
1221
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
1222
1222
|
await sourceFile.save();
|
|
1223
|
-
console.log(` Saved: ${import_path7.default.relative(
|
|
1223
|
+
console.log(` Saved: ${import_path7.default.relative(process.cwd(), filePath)}`);
|
|
1224
1224
|
}
|
|
1225
1225
|
console.log(
|
|
1226
1226
|
`
|
|
@@ -1278,13 +1278,13 @@ function processFile8(filePath, project) {
|
|
|
1278
1278
|
propAccess.getNameNode().replaceWithText(NEW_PROPERTY_NAME);
|
|
1279
1279
|
renamedCount++;
|
|
1280
1280
|
console.log(
|
|
1281
|
-
` [${import_path8.default.relative(
|
|
1281
|
+
` [${import_path8.default.relative(process.cwd(), filePath)}] Renamed Location.${OLD_PROPERTY_NAME} \u2192 Location.${NEW_PROPERTY_NAME}`
|
|
1282
1282
|
);
|
|
1283
1283
|
}
|
|
1284
1284
|
return renamedCount;
|
|
1285
1285
|
}
|
|
1286
1286
|
async function main8() {
|
|
1287
|
-
const srcDir = import_path8.default.join(
|
|
1287
|
+
const srcDir = import_path8.default.join(process.cwd(), "src");
|
|
1288
1288
|
console.log(
|
|
1289
1289
|
`Scanning for Location.${OLD_PROPERTY_NAME} references in: ${srcDir}
|
|
1290
1290
|
`
|
|
@@ -1320,7 +1320,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
1320
1320
|
for (const filePath of modifiedFiles) {
|
|
1321
1321
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
1322
1322
|
await sourceFile.save();
|
|
1323
|
-
console.log(` Saved: ${import_path8.default.relative(
|
|
1323
|
+
console.log(` Saved: ${import_path8.default.relative(process.cwd(), filePath)}`);
|
|
1324
1324
|
}
|
|
1325
1325
|
console.log(
|
|
1326
1326
|
`
|
|
@@ -1387,7 +1387,7 @@ function processFile9(filePath, project) {
|
|
|
1387
1387
|
const sourceFile = project.getSourceFile(filePath);
|
|
1388
1388
|
if (!sourceFile) return 0;
|
|
1389
1389
|
let renamedCount = 0;
|
|
1390
|
-
const relPath = import_path9.default.relative(
|
|
1390
|
+
const relPath = import_path9.default.relative(process.cwd(), filePath);
|
|
1391
1391
|
const candidates = sourceFile.getDescendantsOfKind(
|
|
1392
1392
|
import_ts_morph9.SyntaxKind.ObjectLiteralExpression
|
|
1393
1393
|
);
|
|
@@ -1402,7 +1402,7 @@ function processFile9(filePath, project) {
|
|
|
1402
1402
|
return renamedCount;
|
|
1403
1403
|
}
|
|
1404
1404
|
async function main9() {
|
|
1405
|
-
const srcDir = import_path9.default.join(
|
|
1405
|
+
const srcDir = import_path9.default.join(process.cwd(), "src");
|
|
1406
1406
|
console.log(`Scanning for Hapi route configs in: ${srcDir}
|
|
1407
1407
|
`);
|
|
1408
1408
|
console.log("Active path renames:");
|
|
@@ -1439,7 +1439,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
1439
1439
|
for (const filePath of modifiedFiles) {
|
|
1440
1440
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
1441
1441
|
await sourceFile.save();
|
|
1442
|
-
console.log(` Saved: ${import_path9.default.relative(
|
|
1442
|
+
console.log(` Saved: ${import_path9.default.relative(process.cwd(), filePath)}`);
|
|
1443
1443
|
}
|
|
1444
1444
|
console.log(`
|
|
1445
1445
|
Done. Renamed ${totalRenamed} route path(s).`);
|
|
@@ -1813,9 +1813,9 @@ function updateRouteHandlers(sourceFiles, group, srcDir, relCwd) {
|
|
|
1813
1813
|
}
|
|
1814
1814
|
return replacedCount;
|
|
1815
1815
|
}
|
|
1816
|
-
function resolveConfigChain(configObj,
|
|
1816
|
+
function resolveConfigChain(configObj, path23) {
|
|
1817
1817
|
let current = configObj;
|
|
1818
|
-
for (const key of
|
|
1818
|
+
for (const key of path23) {
|
|
1819
1819
|
if (!import_ts_morph10.Node.isObjectLiteralExpression(current)) return null;
|
|
1820
1820
|
const prop = current.getProperty(key);
|
|
1821
1821
|
if (!prop || !import_ts_morph10.Node.isPropertyAssignment(prop)) return null;
|
|
@@ -1860,8 +1860,8 @@ function ensureJoinImport(sf) {
|
|
|
1860
1860
|
});
|
|
1861
1861
|
}
|
|
1862
1862
|
async function main10() {
|
|
1863
|
-
const srcDir = import_path10.default.join(
|
|
1864
|
-
const relCwd = (fp) => import_path10.default.relative(
|
|
1863
|
+
const srcDir = import_path10.default.join(process.cwd(), "src");
|
|
1864
|
+
const relCwd = (fp) => import_path10.default.relative(process.cwd(), fp);
|
|
1865
1865
|
console.log("Phase 1: Converting JS config files to TypeScript...\n");
|
|
1866
1866
|
let convertedCount = 0;
|
|
1867
1867
|
for (const group of CONFIG_GROUPS) {
|
|
@@ -1949,7 +1949,7 @@ async function main10() {
|
|
|
1949
1949
|
ensureJoinImport(sf);
|
|
1950
1950
|
}
|
|
1951
1951
|
console.log(
|
|
1952
|
-
` Inlined applicationConfig.${accessPath.join(".")} \u2192 ${adjustedValue} in ${import_path10.default.relative(
|
|
1952
|
+
` Inlined applicationConfig.${accessPath.join(".")} \u2192 ${adjustedValue} in ${import_path10.default.relative(process.cwd(), sf.getFilePath())}`
|
|
1953
1953
|
);
|
|
1954
1954
|
filesToSaveAfterInlining.add(sf);
|
|
1955
1955
|
madeReplacement = true;
|
|
@@ -1961,7 +1961,7 @@ async function main10() {
|
|
|
1961
1961
|
for (const sf of Array.from(filesToSaveAfterInlining)) {
|
|
1962
1962
|
await sf.save();
|
|
1963
1963
|
console.log(
|
|
1964
|
-
` Saved (inlined): ${import_path10.default.relative(
|
|
1964
|
+
` Saved (inlined): ${import_path10.default.relative(process.cwd(), sf.getFilePath())}`
|
|
1965
1965
|
);
|
|
1966
1966
|
}
|
|
1967
1967
|
for (const prop of [...propsToRemove].reverse()) {
|
|
@@ -2578,7 +2578,7 @@ function migrateScopesArrays(rolesFilePath, project) {
|
|
|
2578
2578
|
const scopeKey = resolveScopeKeyFromElementAccess(element);
|
|
2579
2579
|
if (scopeKey && !(scopeKey in SCOPES)) {
|
|
2580
2580
|
console.warn(
|
|
2581
|
-
` [${import_path11.default.relative(
|
|
2581
|
+
` [${import_path11.default.relative(process.cwd(), rolesFilePath)}] Removing unknown scope reference: SCOPES.${scopeKey}`
|
|
2582
2582
|
);
|
|
2583
2583
|
initializer.removeElement(index);
|
|
2584
2584
|
removedCount++;
|
|
@@ -2587,7 +2587,7 @@ function migrateScopesArrays(rolesFilePath, project) {
|
|
|
2587
2587
|
const legacyScope = resolveLegacyScopeFromElement(element);
|
|
2588
2588
|
if (!legacyScope) {
|
|
2589
2589
|
console.warn(
|
|
2590
|
-
` [${import_path11.default.relative(
|
|
2590
|
+
` [${import_path11.default.relative(process.cwd(), rolesFilePath)}] Skipping non-literal scope expression: ${element.getText()}`
|
|
2591
2591
|
);
|
|
2592
2592
|
continue;
|
|
2593
2593
|
}
|
|
@@ -2596,7 +2596,7 @@ function migrateScopesArrays(rolesFilePath, project) {
|
|
|
2596
2596
|
const scope = decodeScope(migratedScope);
|
|
2597
2597
|
if (!scope) {
|
|
2598
2598
|
console.warn(
|
|
2599
|
-
` [${import_path11.default.relative(
|
|
2599
|
+
` [${import_path11.default.relative(process.cwd(), rolesFilePath)}] Could not decode migrated scope '${migratedScope}'.`
|
|
2600
2600
|
);
|
|
2601
2601
|
continue;
|
|
2602
2602
|
}
|
|
@@ -2604,14 +2604,14 @@ function migrateScopesArrays(rolesFilePath, project) {
|
|
|
2604
2604
|
migratedCount++;
|
|
2605
2605
|
} catch (error) {
|
|
2606
2606
|
console.warn(
|
|
2607
|
-
` [${import_path11.default.relative(
|
|
2607
|
+
` [${import_path11.default.relative(process.cwd(), rolesFilePath)}] Could not migrate scope '${legacyScope}': ${error}`
|
|
2608
2608
|
);
|
|
2609
2609
|
}
|
|
2610
2610
|
}
|
|
2611
2611
|
}
|
|
2612
2612
|
if (removedCount > 0) {
|
|
2613
2613
|
console.log(
|
|
2614
|
-
` Removed ${removedCount} unknown SCOPES reference(s) from '${import_path11.default.relative(
|
|
2614
|
+
` Removed ${removedCount} unknown SCOPES reference(s) from '${import_path11.default.relative(process.cwd(), rolesFilePath)}'.`
|
|
2615
2615
|
);
|
|
2616
2616
|
}
|
|
2617
2617
|
return { migratedCount, removedCount };
|
|
@@ -2733,9 +2733,9 @@ function removeRoleTypeDefinitionAndUnusedImports(rolesFilePath, project) {
|
|
|
2733
2733
|
return removed;
|
|
2734
2734
|
}
|
|
2735
2735
|
async function main11() {
|
|
2736
|
-
const
|
|
2737
|
-
const srcDir = import_path11.default.join(
|
|
2738
|
-
const rolesFilePath = import_path11.default.join(
|
|
2736
|
+
const cwd = process.cwd();
|
|
2737
|
+
const srcDir = import_path11.default.join(cwd, "src");
|
|
2738
|
+
const rolesFilePath = import_path11.default.join(cwd, ROLES_FILE_RELATIVE_PATH);
|
|
2739
2739
|
console.log(`Scanning roles scopes in: ${rolesFilePath}`);
|
|
2740
2740
|
const project = new import_ts_morph11.Project({
|
|
2741
2741
|
tsConfigFilePath: import_path11.default.resolve(srcDir, "../tsconfig.json"),
|
|
@@ -2799,13 +2799,13 @@ function processFile10(filePath, project) {
|
|
|
2799
2799
|
decl.remove();
|
|
2800
2800
|
}
|
|
2801
2801
|
console.log(
|
|
2802
|
-
` [${import_path12.default.relative(
|
|
2802
|
+
` [${import_path12.default.relative(process.cwd(), filePath)}] Removed ${matchingNamedImports.length} deprecated '${DEPRECATED_IMPORT}' import(s) from '${decl.getModuleSpecifierValue()}'`
|
|
2803
2803
|
);
|
|
2804
2804
|
}
|
|
2805
2805
|
return removedCount;
|
|
2806
2806
|
}
|
|
2807
2807
|
async function main12() {
|
|
2808
|
-
const srcDir = import_path12.default.join(
|
|
2808
|
+
const srcDir = import_path12.default.join(process.cwd(), "src");
|
|
2809
2809
|
console.log(`Scanning for deprecated imports in: ${srcDir}
|
|
2810
2810
|
`);
|
|
2811
2811
|
const project = new import_ts_morph12.Project({
|
|
@@ -2836,15 +2836,738 @@ async function main12() {
|
|
|
2836
2836
|
Saving ${modifiedFiles.length} modified file(s)...`);
|
|
2837
2837
|
for (const filePath of modifiedFiles) {
|
|
2838
2838
|
await project.getSourceFileOrThrow(filePath).save();
|
|
2839
|
-
console.log(` Saved: ${import_path12.default.relative(
|
|
2839
|
+
console.log(` Saved: ${import_path12.default.relative(process.cwd(), filePath)}`);
|
|
2840
2840
|
}
|
|
2841
2841
|
console.log(`
|
|
2842
2842
|
Done. Removed ${totalRemoved} deprecated import(s).`);
|
|
2843
2843
|
}
|
|
2844
2844
|
|
|
2845
|
-
// src/migrations/v2.0/
|
|
2846
|
-
var import_ts_morph13 = require("ts-morph");
|
|
2845
|
+
// src/migrations/v2.0/remove-unused-environment-variables.ts
|
|
2847
2846
|
var import_path13 = __toESM(require("path"));
|
|
2847
|
+
var import_ts_morph13 = require("ts-morph");
|
|
2848
|
+
var UNUSED_ENV_VARS = /* @__PURE__ */ new Set([
|
|
2849
|
+
"APPLICATION_CONFIG_URL",
|
|
2850
|
+
"FHIR_URL",
|
|
2851
|
+
"CONFIRM_REGISTRATION_URL"
|
|
2852
|
+
]);
|
|
2853
|
+
var ENVIRONMENT_FILE_RELATIVE = "src/environment.ts";
|
|
2854
|
+
var CONSTANTS_FILE_RELATIVE = "src/constants.ts";
|
|
2855
|
+
function cleanEnvironmentFile(project, filePath) {
|
|
2856
|
+
const sourceFile = project.getSourceFile(filePath);
|
|
2857
|
+
if (!sourceFile) return [];
|
|
2858
|
+
const removed = [];
|
|
2859
|
+
const cleanEnvCall = sourceFile.getDescendantsOfKind(import_ts_morph13.SyntaxKind.CallExpression).find((call) => {
|
|
2860
|
+
const expr = call.getExpression();
|
|
2861
|
+
return import_ts_morph13.Node.isIdentifier(expr) && expr.getText() === "cleanEnv";
|
|
2862
|
+
});
|
|
2863
|
+
if (!cleanEnvCall) return removed;
|
|
2864
|
+
const schemaArg = cleanEnvCall.getArguments()[1]?.asKind(import_ts_morph13.SyntaxKind.ObjectLiteralExpression);
|
|
2865
|
+
if (!schemaArg) return removed;
|
|
2866
|
+
for (const name of UNUSED_ENV_VARS) {
|
|
2867
|
+
const prop = schemaArg.getProperty(name);
|
|
2868
|
+
if (!prop) continue;
|
|
2869
|
+
if (prop.isKind(import_ts_morph13.SyntaxKind.PropertyAssignment) || prop.isKind(import_ts_morph13.SyntaxKind.ShorthandPropertyAssignment)) {
|
|
2870
|
+
prop.remove();
|
|
2871
|
+
removed.push(name);
|
|
2872
|
+
}
|
|
2873
|
+
}
|
|
2874
|
+
return removed;
|
|
2875
|
+
}
|
|
2876
|
+
function extractEnvAccess(initText) {
|
|
2877
|
+
if (!initText) return null;
|
|
2878
|
+
const match = /\benv\.([A-Z][A-Z0-9_]*)\b/.exec(initText);
|
|
2879
|
+
return match ? match[1] : null;
|
|
2880
|
+
}
|
|
2881
|
+
function cleanConstantsFile(project, filePath) {
|
|
2882
|
+
const sourceFile = project.getSourceFile(filePath);
|
|
2883
|
+
if (!sourceFile) return [];
|
|
2884
|
+
const removed = [];
|
|
2885
|
+
for (const stmt of [...sourceFile.getVariableStatements()]) {
|
|
2886
|
+
const declarations = [...stmt.getDeclarations()];
|
|
2887
|
+
const declarationsToRemove = declarations.filter((decl) => {
|
|
2888
|
+
const name = decl.getName();
|
|
2889
|
+
const accessedEnvVar = extractEnvAccess(decl.getInitializer()?.getText());
|
|
2890
|
+
return UNUSED_ENV_VARS.has(name) || accessedEnvVar !== null && UNUSED_ENV_VARS.has(accessedEnvVar);
|
|
2891
|
+
});
|
|
2892
|
+
if (declarationsToRemove.length === 0) continue;
|
|
2893
|
+
const namesToRemove = declarationsToRemove.map((decl) => decl.getName());
|
|
2894
|
+
removed.push(...namesToRemove);
|
|
2895
|
+
if (declarationsToRemove.length === declarations.length) {
|
|
2896
|
+
stmt.remove();
|
|
2897
|
+
} else {
|
|
2898
|
+
for (const decl of declarationsToRemove) {
|
|
2899
|
+
decl.remove();
|
|
2900
|
+
}
|
|
2901
|
+
}
|
|
2902
|
+
}
|
|
2903
|
+
return removed;
|
|
2904
|
+
}
|
|
2905
|
+
async function main13() {
|
|
2906
|
+
const project = new import_ts_morph13.Project({
|
|
2907
|
+
tsConfigFilePath: import_path13.default.resolve(process.cwd(), "tsconfig.json"),
|
|
2908
|
+
skipAddingFilesFromTsConfig: false
|
|
2909
|
+
});
|
|
2910
|
+
console.log(
|
|
2911
|
+
`Removing unused environment variable(s) (${[...UNUSED_ENV_VARS].join(", ")})...
|
|
2912
|
+
`
|
|
2913
|
+
);
|
|
2914
|
+
const envFilePath = import_path13.default.join(process.cwd(), ENVIRONMENT_FILE_RELATIVE);
|
|
2915
|
+
const constsFilePath = import_path13.default.join(process.cwd(), CONSTANTS_FILE_RELATIVE);
|
|
2916
|
+
const envRemoved = cleanEnvironmentFile(project, envFilePath);
|
|
2917
|
+
if (envRemoved.length > 0) {
|
|
2918
|
+
await project.getSourceFileOrThrow(envFilePath).save();
|
|
2919
|
+
console.log(
|
|
2920
|
+
` [${ENVIRONMENT_FILE_RELATIVE}] Removed schema entr${envRemoved.length === 1 ? "y" : "ies"}: ${envRemoved.join(", ")}`
|
|
2921
|
+
);
|
|
2922
|
+
} else if (project.getSourceFile(envFilePath)) {
|
|
2923
|
+
console.log(
|
|
2924
|
+
` [${ENVIRONMENT_FILE_RELATIVE}] No matching schema entries \u2014 nothing to remove.`
|
|
2925
|
+
);
|
|
2926
|
+
} else {
|
|
2927
|
+
console.log(
|
|
2928
|
+
` [${ENVIRONMENT_FILE_RELATIVE}] File not found \u2014 skipping.`
|
|
2929
|
+
);
|
|
2930
|
+
}
|
|
2931
|
+
const constsRemoved = cleanConstantsFile(project, constsFilePath);
|
|
2932
|
+
if (constsRemoved.length > 0) {
|
|
2933
|
+
await project.getSourceFileOrThrow(constsFilePath).save();
|
|
2934
|
+
console.log(
|
|
2935
|
+
` [${CONSTANTS_FILE_RELATIVE}] Removed declaration(s): ${constsRemoved.join(", ")}`
|
|
2936
|
+
);
|
|
2937
|
+
} else if (project.getSourceFile(constsFilePath)) {
|
|
2938
|
+
console.log(
|
|
2939
|
+
` [${CONSTANTS_FILE_RELATIVE}] No matching declarations \u2014 nothing to remove.`
|
|
2940
|
+
);
|
|
2941
|
+
} else {
|
|
2942
|
+
console.log(` [${CONSTANTS_FILE_RELATIVE}] File not found \u2014 skipping.`);
|
|
2943
|
+
}
|
|
2944
|
+
if (envRemoved.length === 0 && constsRemoved.length === 0) {
|
|
2945
|
+
console.log("\nNothing to do.");
|
|
2946
|
+
return;
|
|
2947
|
+
}
|
|
2948
|
+
console.log(
|
|
2949
|
+
`
|
|
2950
|
+
Done. NOTE: usages of these constants elsewhere in 'src/' may now produce TypeScript errors and need manual review.`
|
|
2951
|
+
);
|
|
2952
|
+
}
|
|
2953
|
+
|
|
2954
|
+
// src/migrations/v2.0/remove-fhir-url-helpers.ts
|
|
2955
|
+
var import_path14 = __toESM(require("path"));
|
|
2956
|
+
var import_ts_morph14 = require("ts-morph");
|
|
2957
|
+
var FHIR_IMPORT = "FHIR_URL";
|
|
2958
|
+
var HELPER_NAMES = /* @__PURE__ */ new Set([
|
|
2959
|
+
"getFromFhir",
|
|
2960
|
+
"updateResourceFromHearth",
|
|
2961
|
+
"updateResourceInHearth"
|
|
2962
|
+
]);
|
|
2963
|
+
function removeHelpers(sourceFilePath, project) {
|
|
2964
|
+
const sourceFile = project.getSourceFile(sourceFilePath);
|
|
2965
|
+
if (!sourceFile) {
|
|
2966
|
+
return {
|
|
2967
|
+
removedHelpers: [],
|
|
2968
|
+
removedImportCount: 0,
|
|
2969
|
+
remainingFhirReferences: 0
|
|
2970
|
+
};
|
|
2971
|
+
}
|
|
2972
|
+
const removedHelpers = [];
|
|
2973
|
+
let removedImportCount = 0;
|
|
2974
|
+
for (const fn of sourceFile.getFunctions()) {
|
|
2975
|
+
const name = fn.getName();
|
|
2976
|
+
if (!name || !HELPER_NAMES.has(name)) continue;
|
|
2977
|
+
removedHelpers.push(name);
|
|
2978
|
+
fn.remove();
|
|
2979
|
+
}
|
|
2980
|
+
for (const stmt of [...sourceFile.getVariableStatements()]) {
|
|
2981
|
+
const declarations = [...stmt.getDeclarations()];
|
|
2982
|
+
const toRemove = declarations.filter((decl) => HELPER_NAMES.has(decl.getName()));
|
|
2983
|
+
if (toRemove.length === 0) continue;
|
|
2984
|
+
removedHelpers.push(...toRemove.map((decl) => decl.getName()));
|
|
2985
|
+
if (toRemove.length === declarations.length) {
|
|
2986
|
+
stmt.remove();
|
|
2987
|
+
} else {
|
|
2988
|
+
for (const decl of toRemove) decl.remove();
|
|
2989
|
+
}
|
|
2990
|
+
}
|
|
2991
|
+
for (const decl of sourceFile.getImportDeclarations()) {
|
|
2992
|
+
const matches = decl.getNamedImports().filter((ni) => ni.getName() === FHIR_IMPORT);
|
|
2993
|
+
if (matches.length === 0) continue;
|
|
2994
|
+
for (const named of matches) {
|
|
2995
|
+
named.remove();
|
|
2996
|
+
removedImportCount++;
|
|
2997
|
+
}
|
|
2998
|
+
const hasAnyNamedImportsLeft = decl.getNamedImports().length > 0;
|
|
2999
|
+
const hasDefaultImport = !!decl.getDefaultImport();
|
|
3000
|
+
const hasNamespaceImport = !!decl.getNamespaceImport();
|
|
3001
|
+
if (!hasAnyNamedImportsLeft && !hasDefaultImport && !hasNamespaceImport) {
|
|
3002
|
+
decl.remove();
|
|
3003
|
+
}
|
|
3004
|
+
}
|
|
3005
|
+
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;
|
|
3006
|
+
return { removedHelpers, removedImportCount, remainingFhirReferences };
|
|
3007
|
+
}
|
|
3008
|
+
async function main14() {
|
|
3009
|
+
const project = new import_ts_morph14.Project({
|
|
3010
|
+
tsConfigFilePath: import_path14.default.resolve(process.cwd(), "tsconfig.json"),
|
|
3011
|
+
skipAddingFilesFromTsConfig: false
|
|
3012
|
+
});
|
|
3013
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
3014
|
+
const fp = sf.getFilePath();
|
|
3015
|
+
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
3016
|
+
});
|
|
3017
|
+
console.log(`Removing legacy FHIR_URL helpers in ${sourceFiles.length} source file(s)...
|
|
3018
|
+
`);
|
|
3019
|
+
let totalRemovedImports = 0;
|
|
3020
|
+
let totalRemovedHelpers = 0;
|
|
3021
|
+
const modifiedFiles = [];
|
|
3022
|
+
const warnings = [];
|
|
3023
|
+
for (const sourceFile of sourceFiles) {
|
|
3024
|
+
const filePath = sourceFile.getFilePath();
|
|
3025
|
+
const rel = import_path14.default.relative(process.cwd(), filePath);
|
|
3026
|
+
const result = removeHelpers(filePath, project);
|
|
3027
|
+
const changed = result.removedImportCount > 0 || result.removedHelpers.length > 0;
|
|
3028
|
+
if (changed) {
|
|
3029
|
+
modifiedFiles.push(filePath);
|
|
3030
|
+
totalRemovedImports += result.removedImportCount;
|
|
3031
|
+
totalRemovedHelpers += result.removedHelpers.length;
|
|
3032
|
+
if (result.removedHelpers.length > 0) {
|
|
3033
|
+
console.log(
|
|
3034
|
+
` [${rel}] Removed helper(s): ${result.removedHelpers.join(", ")}`
|
|
3035
|
+
);
|
|
3036
|
+
}
|
|
3037
|
+
if (result.removedImportCount > 0) {
|
|
3038
|
+
console.log(
|
|
3039
|
+
` [${rel}] Removed ${result.removedImportCount} '${FHIR_IMPORT}' import(s)`
|
|
3040
|
+
);
|
|
3041
|
+
}
|
|
3042
|
+
}
|
|
3043
|
+
if (result.remainingFhirReferences > 0) {
|
|
3044
|
+
warnings.push(
|
|
3045
|
+
`${rel}: ${result.remainingFhirReferences} remaining '${FHIR_IMPORT}' reference(s)`
|
|
3046
|
+
);
|
|
3047
|
+
}
|
|
3048
|
+
}
|
|
3049
|
+
if (modifiedFiles.length === 0 && warnings.length === 0) {
|
|
3050
|
+
console.log("No FHIR_URL imports/helpers found. Nothing to do.");
|
|
3051
|
+
return;
|
|
3052
|
+
}
|
|
3053
|
+
if (modifiedFiles.length > 0) {
|
|
3054
|
+
console.log(`
|
|
3055
|
+
Saving ${modifiedFiles.length} modified file(s)...`);
|
|
3056
|
+
for (const filePath of modifiedFiles) {
|
|
3057
|
+
await project.getSourceFileOrThrow(filePath).save();
|
|
3058
|
+
console.log(` Saved: ${import_path14.default.relative(process.cwd(), filePath)}`);
|
|
3059
|
+
}
|
|
3060
|
+
}
|
|
3061
|
+
if (warnings.length > 0) {
|
|
3062
|
+
console.warn(
|
|
3063
|
+
`
|
|
3064
|
+
WARNING: Some '${FHIR_IMPORT}' usages remain and need manual cleanup:
|
|
3065
|
+
` + warnings.map((line) => ` - ${line}`).join("\n")
|
|
3066
|
+
);
|
|
3067
|
+
}
|
|
3068
|
+
console.log(
|
|
3069
|
+
`
|
|
3070
|
+
Done. Removed ${totalRemovedHelpers} helper declaration(s) and ${totalRemovedImports} '${FHIR_IMPORT}' import(s).`
|
|
3071
|
+
);
|
|
3072
|
+
}
|
|
3073
|
+
|
|
3074
|
+
// src/migrations/v2.0/migrate-application-config-url.ts
|
|
3075
|
+
var import_path15 = __toESM(require("path"));
|
|
3076
|
+
var import_ts_morph15 = require("ts-morph");
|
|
3077
|
+
var TARGET_IDENTIFIER = "APPLICATION_CONFIG_URL";
|
|
3078
|
+
var REPLACEMENT_IDENTIFIER = "applicationConfig";
|
|
3079
|
+
var REPLACEMENT_MODULE = "@countryconfig/api/application/application-config";
|
|
3080
|
+
var FUNCTION_LIKE_KINDS = [
|
|
3081
|
+
import_ts_morph15.SyntaxKind.FunctionDeclaration,
|
|
3082
|
+
import_ts_morph15.SyntaxKind.FunctionExpression,
|
|
3083
|
+
import_ts_morph15.SyntaxKind.ArrowFunction,
|
|
3084
|
+
import_ts_morph15.SyntaxKind.MethodDeclaration
|
|
3085
|
+
];
|
|
3086
|
+
function describeFunction(node) {
|
|
3087
|
+
if (import_ts_morph15.Node.isFunctionDeclaration(node) || import_ts_morph15.Node.isMethodDeclaration(node)) {
|
|
3088
|
+
return node.getName() ?? "<anonymous>";
|
|
3089
|
+
}
|
|
3090
|
+
const parent = node.getParent();
|
|
3091
|
+
if (parent && import_ts_morph15.Node.isVariableDeclaration(parent)) {
|
|
3092
|
+
return parent.getName();
|
|
3093
|
+
}
|
|
3094
|
+
if (parent && import_ts_morph15.Node.isPropertyAssignment(parent)) {
|
|
3095
|
+
return parent.getName();
|
|
3096
|
+
}
|
|
3097
|
+
if (import_ts_morph15.Node.isFunctionExpression(node) && node.getNameNode() !== void 0) {
|
|
3098
|
+
return node.getNameNode()?.getText() ?? "<anonymous>";
|
|
3099
|
+
}
|
|
3100
|
+
return "<anonymous>";
|
|
3101
|
+
}
|
|
3102
|
+
function hasBlockBody(node) {
|
|
3103
|
+
if (import_ts_morph15.Node.isFunctionDeclaration(node) || import_ts_morph15.Node.isFunctionExpression(node) || import_ts_morph15.Node.isMethodDeclaration(node)) {
|
|
3104
|
+
return node.getBody() !== void 0;
|
|
3105
|
+
}
|
|
3106
|
+
if (import_ts_morph15.Node.isArrowFunction(node)) {
|
|
3107
|
+
return node.getBody().getKind() === import_ts_morph15.SyntaxKind.Block;
|
|
3108
|
+
}
|
|
3109
|
+
return false;
|
|
3110
|
+
}
|
|
3111
|
+
function isConfigFetcher(node) {
|
|
3112
|
+
let referencesTarget = false;
|
|
3113
|
+
let callsFetch = false;
|
|
3114
|
+
for (const id of node.getDescendantsOfKind(import_ts_morph15.SyntaxKind.Identifier)) {
|
|
3115
|
+
const text = id.getText();
|
|
3116
|
+
if (!referencesTarget && text === TARGET_IDENTIFIER) referencesTarget = true;
|
|
3117
|
+
if (!callsFetch && text === "fetch") {
|
|
3118
|
+
const parent = id.getParent();
|
|
3119
|
+
if (import_ts_morph15.Node.isCallExpression(parent) && parent.getExpression() === id) {
|
|
3120
|
+
callsFetch = true;
|
|
3121
|
+
}
|
|
3122
|
+
}
|
|
3123
|
+
if (referencesTarget && callsFetch) return true;
|
|
3124
|
+
}
|
|
3125
|
+
return false;
|
|
3126
|
+
}
|
|
3127
|
+
function processFile11(sourceFile) {
|
|
3128
|
+
const importsWithTarget = sourceFile.getImportDeclarations().filter(
|
|
3129
|
+
(decl) => decl.getNamedImports().some((ni) => ni.getName() === TARGET_IDENTIFIER)
|
|
3130
|
+
);
|
|
3131
|
+
if (importsWithTarget.length === 0) {
|
|
3132
|
+
return { changed: false, rewrittenFunctions: [], renamedReferences: 0 };
|
|
3133
|
+
}
|
|
3134
|
+
const collidingLocals = sourceFile.getDescendantsOfKind(import_ts_morph15.SyntaxKind.Identifier).filter((id) => id.getText() === REPLACEMENT_IDENTIFIER).filter((id) => {
|
|
3135
|
+
const parent = id.getParent();
|
|
3136
|
+
const kind = parent.getKind();
|
|
3137
|
+
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;
|
|
3138
|
+
});
|
|
3139
|
+
if (collidingLocals.length > 0) {
|
|
3140
|
+
return {
|
|
3141
|
+
changed: false,
|
|
3142
|
+
rewrittenFunctions: [],
|
|
3143
|
+
renamedReferences: 0,
|
|
3144
|
+
skippedReason: `local declaration named '${REPLACEMENT_IDENTIFIER}' would collide`
|
|
3145
|
+
};
|
|
3146
|
+
}
|
|
3147
|
+
const candidateFunctions = FUNCTION_LIKE_KINDS.flatMap(
|
|
3148
|
+
(kind) => sourceFile.getDescendantsOfKind(kind)
|
|
3149
|
+
);
|
|
3150
|
+
candidateFunctions.sort((a, b) => a.getStart() - b.getStart());
|
|
3151
|
+
const rewrittenFunctions = [];
|
|
3152
|
+
const rewrittenSet = /* @__PURE__ */ new Set();
|
|
3153
|
+
for (const fn of candidateFunctions) {
|
|
3154
|
+
if (!hasBlockBody(fn)) continue;
|
|
3155
|
+
if (!isConfigFetcher(fn)) continue;
|
|
3156
|
+
let inRewrittenAncestor = false;
|
|
3157
|
+
let cursor = fn.getParent();
|
|
3158
|
+
while (cursor) {
|
|
3159
|
+
if (rewrittenSet.has(cursor)) {
|
|
3160
|
+
inRewrittenAncestor = true;
|
|
3161
|
+
break;
|
|
3162
|
+
}
|
|
3163
|
+
cursor = cursor.getParent();
|
|
3164
|
+
}
|
|
3165
|
+
if (inRewrittenAncestor) continue;
|
|
3166
|
+
const start = fn.getStart();
|
|
3167
|
+
const line = sourceFile.getLineAndColumnAtPos(start).line;
|
|
3168
|
+
const name = describeFunction(fn);
|
|
3169
|
+
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)) {
|
|
3170
|
+
fn.setBodyText(`return ${REPLACEMENT_IDENTIFIER}`);
|
|
3171
|
+
}
|
|
3172
|
+
rewrittenFunctions.push({ name, line });
|
|
3173
|
+
rewrittenSet.add(fn);
|
|
3174
|
+
}
|
|
3175
|
+
for (const decl of importsWithTarget) {
|
|
3176
|
+
const targetNamed = decl.getNamedImports().find((ni) => ni.getName() === TARGET_IDENTIFIER);
|
|
3177
|
+
targetNamed?.remove();
|
|
3178
|
+
const isNowEmpty = decl.getNamedImports().length === 0 && !decl.getDefaultImport() && !decl.getNamespaceImport();
|
|
3179
|
+
if (isNowEmpty) decl.remove();
|
|
3180
|
+
}
|
|
3181
|
+
const existing = sourceFile.getImportDeclaration(
|
|
3182
|
+
(decl) => decl.getModuleSpecifierValue() === REPLACEMENT_MODULE
|
|
3183
|
+
);
|
|
3184
|
+
if (existing) {
|
|
3185
|
+
const alreadyImported = existing.getNamedImports().some((ni) => ni.getName() === REPLACEMENT_IDENTIFIER);
|
|
3186
|
+
if (!alreadyImported) existing.addNamedImport(REPLACEMENT_IDENTIFIER);
|
|
3187
|
+
} else {
|
|
3188
|
+
sourceFile.addImportDeclaration({
|
|
3189
|
+
moduleSpecifier: REPLACEMENT_MODULE,
|
|
3190
|
+
namedImports: [REPLACEMENT_IDENTIFIER]
|
|
3191
|
+
});
|
|
3192
|
+
}
|
|
3193
|
+
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) => {
|
|
3194
|
+
const parent = id.getParent();
|
|
3195
|
+
const parentKind = parent.getKind();
|
|
3196
|
+
if (parentKind === import_ts_morph15.SyntaxKind.PropertyAccessExpression) {
|
|
3197
|
+
const pae = parent.asKind(import_ts_morph15.SyntaxKind.PropertyAccessExpression);
|
|
3198
|
+
if (pae.getNameNode() === id) return false;
|
|
3199
|
+
}
|
|
3200
|
+
if (parentKind === import_ts_morph15.SyntaxKind.PropertyAssignment) {
|
|
3201
|
+
const pa = parent.asKind(import_ts_morph15.SyntaxKind.PropertyAssignment);
|
|
3202
|
+
if (pa.getNameNode() === id) return false;
|
|
3203
|
+
}
|
|
3204
|
+
if (parentKind === import_ts_morph15.SyntaxKind.ShorthandPropertyAssignment) {
|
|
3205
|
+
return false;
|
|
3206
|
+
}
|
|
3207
|
+
return true;
|
|
3208
|
+
}).sort((a, b) => b.getPos() - a.getPos());
|
|
3209
|
+
for (const id of renameTargets) {
|
|
3210
|
+
id.replaceWithText(REPLACEMENT_IDENTIFIER);
|
|
3211
|
+
}
|
|
3212
|
+
return {
|
|
3213
|
+
changed: true,
|
|
3214
|
+
rewrittenFunctions,
|
|
3215
|
+
renamedReferences: renameTargets.length
|
|
3216
|
+
};
|
|
3217
|
+
}
|
|
3218
|
+
async function main15() {
|
|
3219
|
+
const project = new import_ts_morph15.Project({
|
|
3220
|
+
tsConfigFilePath: import_path15.default.resolve(process.cwd(), "tsconfig.json"),
|
|
3221
|
+
skipAddingFilesFromTsConfig: false
|
|
3222
|
+
});
|
|
3223
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
3224
|
+
const fp = sf.getFilePath();
|
|
3225
|
+
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
3226
|
+
});
|
|
3227
|
+
console.log(
|
|
3228
|
+
`Migrating '${TARGET_IDENTIFIER}' \u2192 '${REPLACEMENT_IDENTIFIER}' across ${sourceFiles.length} source file(s)...
|
|
3229
|
+
`
|
|
3230
|
+
);
|
|
3231
|
+
let changedFiles = 0;
|
|
3232
|
+
let totalRewrittenFunctions = 0;
|
|
3233
|
+
let totalRenamedReferences = 0;
|
|
3234
|
+
const skipped = [];
|
|
3235
|
+
for (const sourceFile of sourceFiles) {
|
|
3236
|
+
const filePath = sourceFile.getFilePath();
|
|
3237
|
+
const rel = import_path15.default.relative(process.cwd(), filePath);
|
|
3238
|
+
const result = processFile11(sourceFile);
|
|
3239
|
+
if (result.skippedReason) {
|
|
3240
|
+
skipped.push(`${rel} (${result.skippedReason})`);
|
|
3241
|
+
continue;
|
|
3242
|
+
}
|
|
3243
|
+
if (!result.changed) continue;
|
|
3244
|
+
await sourceFile.save();
|
|
3245
|
+
changedFiles++;
|
|
3246
|
+
totalRewrittenFunctions += result.rewrittenFunctions.length;
|
|
3247
|
+
totalRenamedReferences += result.renamedReferences;
|
|
3248
|
+
for (const fn of result.rewrittenFunctions) {
|
|
3249
|
+
console.log(
|
|
3250
|
+
` [${rel}:${fn.line}] Rewrote '${fn.name}' body \u2192 'return ${REPLACEMENT_IDENTIFIER}' (config fetch eliminated)`
|
|
3251
|
+
);
|
|
3252
|
+
}
|
|
3253
|
+
if (result.renamedReferences > 0) {
|
|
3254
|
+
console.log(
|
|
3255
|
+
` [${rel}] Renamed ${result.renamedReferences} stray reference(s) ${TARGET_IDENTIFIER} \u2192 ${REPLACEMENT_IDENTIFIER}`
|
|
3256
|
+
);
|
|
3257
|
+
}
|
|
3258
|
+
}
|
|
3259
|
+
if (skipped.length > 0) {
|
|
3260
|
+
console.warn(
|
|
3261
|
+
`
|
|
3262
|
+
${skipped.length} file(s) skipped:
|
|
3263
|
+
` + skipped.map((s) => ` - ${s}`).join("\n")
|
|
3264
|
+
);
|
|
3265
|
+
}
|
|
3266
|
+
if (changedFiles === 0) {
|
|
3267
|
+
console.log(`
|
|
3268
|
+
No files reference '${TARGET_IDENTIFIER}'. Nothing to do.`);
|
|
3269
|
+
return;
|
|
3270
|
+
}
|
|
3271
|
+
console.log(
|
|
3272
|
+
`
|
|
3273
|
+
Done. Updated ${changedFiles} file(s): ${totalRewrittenFunctions} fetch function(s) rewritten, ${totalRenamedReferences} bare reference(s) renamed.`
|
|
3274
|
+
);
|
|
3275
|
+
if (totalRewrittenFunctions > 0) {
|
|
3276
|
+
console.log(
|
|
3277
|
+
`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}'.`
|
|
3278
|
+
);
|
|
3279
|
+
}
|
|
3280
|
+
}
|
|
3281
|
+
|
|
3282
|
+
// src/migrations/v2.0/remove-old-statistics-service.ts
|
|
3283
|
+
var import_path16 = __toESM(require("path"));
|
|
3284
|
+
var import_ts_morph16 = require("ts-morph");
|
|
3285
|
+
var ROUTE_PATH = "/statistics";
|
|
3286
|
+
var HANDLER_NAME = "statisticsHandler";
|
|
3287
|
+
function isStatisticsRouteObject(obj) {
|
|
3288
|
+
const pathProp = obj.getProperty("path");
|
|
3289
|
+
if (!pathProp || !import_ts_morph16.Node.isPropertyAssignment(pathProp)) return false;
|
|
3290
|
+
const init = pathProp.getInitializer();
|
|
3291
|
+
if (!init) return false;
|
|
3292
|
+
if (import_ts_morph16.Node.isStringLiteral(init) || import_ts_morph16.Node.isNoSubstitutionTemplateLiteral(init)) {
|
|
3293
|
+
return init.getLiteralValue() === ROUTE_PATH;
|
|
3294
|
+
}
|
|
3295
|
+
return false;
|
|
3296
|
+
}
|
|
3297
|
+
function removeStatisticsRoutes(sourceFile) {
|
|
3298
|
+
let removed = 0;
|
|
3299
|
+
const callExpressions = [
|
|
3300
|
+
...sourceFile.getDescendantsOfKind(import_ts_morph16.SyntaxKind.CallExpression)
|
|
3301
|
+
];
|
|
3302
|
+
for (const call of callExpressions) {
|
|
3303
|
+
if (call.wasForgotten()) continue;
|
|
3304
|
+
const expr = call.getExpression();
|
|
3305
|
+
if (!import_ts_morph16.Node.isPropertyAccessExpression(expr)) continue;
|
|
3306
|
+
if (expr.getName() !== "route") continue;
|
|
3307
|
+
const args2 = call.getArguments();
|
|
3308
|
+
if (args2.length === 0) continue;
|
|
3309
|
+
const firstArg = args2[0];
|
|
3310
|
+
if (import_ts_morph16.Node.isObjectLiteralExpression(firstArg)) {
|
|
3311
|
+
if (!isStatisticsRouteObject(firstArg)) continue;
|
|
3312
|
+
const stmt = call.getFirstAncestorByKind(import_ts_morph16.SyntaxKind.ExpressionStatement);
|
|
3313
|
+
if (stmt) {
|
|
3314
|
+
stmt.remove();
|
|
3315
|
+
removed++;
|
|
3316
|
+
} else {
|
|
3317
|
+
call.replaceWithText("");
|
|
3318
|
+
removed++;
|
|
3319
|
+
}
|
|
3320
|
+
continue;
|
|
3321
|
+
}
|
|
3322
|
+
if (import_ts_morph16.Node.isArrayLiteralExpression(firstArg)) {
|
|
3323
|
+
const matchingIndexes = firstArg.getElements().map((el, idx) => ({ el, idx })).filter(
|
|
3324
|
+
({ el }) => import_ts_morph16.Node.isObjectLiteralExpression(el) && isStatisticsRouteObject(el)
|
|
3325
|
+
).map(({ idx }) => idx);
|
|
3326
|
+
matchingIndexes.sort((a, b) => b - a).forEach((idx) => {
|
|
3327
|
+
firstArg.removeElement(idx);
|
|
3328
|
+
removed++;
|
|
3329
|
+
});
|
|
3330
|
+
}
|
|
3331
|
+
}
|
|
3332
|
+
return removed;
|
|
3333
|
+
}
|
|
3334
|
+
function removeStatisticsHandlerImports(sourceFile) {
|
|
3335
|
+
let changed = false;
|
|
3336
|
+
for (const decl of sourceFile.getImportDeclarations()) {
|
|
3337
|
+
const targetNamed = decl.getNamedImports().find((ni) => ni.getName() === HANDLER_NAME);
|
|
3338
|
+
if (!targetNamed) continue;
|
|
3339
|
+
targetNamed.remove();
|
|
3340
|
+
changed = true;
|
|
3341
|
+
const isNowEmpty = decl.getNamedImports().length === 0 && !decl.getDefaultImport() && !decl.getNamespaceImport();
|
|
3342
|
+
if (isNowEmpty) decl.remove();
|
|
3343
|
+
}
|
|
3344
|
+
return changed;
|
|
3345
|
+
}
|
|
3346
|
+
function processFile12(sourceFile) {
|
|
3347
|
+
const routesRemoved = removeStatisticsRoutes(sourceFile);
|
|
3348
|
+
const importsCleaned = removeStatisticsHandlerImports(sourceFile);
|
|
3349
|
+
return { routesRemoved, importsCleaned };
|
|
3350
|
+
}
|
|
3351
|
+
function collectLocalImportsInSubtree(sourceFile, subtreeRoot) {
|
|
3352
|
+
const result = [];
|
|
3353
|
+
for (const decl of sourceFile.getImportDeclarations()) {
|
|
3354
|
+
const moduleSf = decl.getModuleSpecifierSourceFile();
|
|
3355
|
+
if (!moduleSf) continue;
|
|
3356
|
+
const fp = moduleSf.getFilePath();
|
|
3357
|
+
if (!fp.startsWith(subtreeRoot)) continue;
|
|
3358
|
+
result.push(fp);
|
|
3359
|
+
}
|
|
3360
|
+
return result;
|
|
3361
|
+
}
|
|
3362
|
+
function deleteOrphanedDescendants(project, startingFile, subtreeRoot) {
|
|
3363
|
+
const initialCandidates = collectLocalImportsInSubtree(
|
|
3364
|
+
startingFile,
|
|
3365
|
+
subtreeRoot
|
|
3366
|
+
);
|
|
3367
|
+
const startingPath = startingFile.getFilePath();
|
|
3368
|
+
const deleted = /* @__PURE__ */ new Set([startingPath]);
|
|
3369
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3370
|
+
const worklist = [...initialCandidates];
|
|
3371
|
+
const orphans = [];
|
|
3372
|
+
while (worklist.length > 0) {
|
|
3373
|
+
const candidate = worklist.shift();
|
|
3374
|
+
if (seen.has(candidate)) continue;
|
|
3375
|
+
seen.add(candidate);
|
|
3376
|
+
if (deleted.has(candidate)) continue;
|
|
3377
|
+
if (!candidate.startsWith(subtreeRoot)) continue;
|
|
3378
|
+
const candidateSf = project.getSourceFile(candidate);
|
|
3379
|
+
if (!candidateSf) continue;
|
|
3380
|
+
const stillImported = project.getSourceFiles().some((sf) => {
|
|
3381
|
+
const sfPath = sf.getFilePath();
|
|
3382
|
+
if (deleted.has(sfPath)) return false;
|
|
3383
|
+
if (sfPath === candidate) return false;
|
|
3384
|
+
return sf.getImportDeclarations().some(
|
|
3385
|
+
(decl) => decl.getModuleSpecifierSourceFile()?.getFilePath() === candidate
|
|
3386
|
+
);
|
|
3387
|
+
});
|
|
3388
|
+
if (stillImported) continue;
|
|
3389
|
+
const next = collectLocalImportsInSubtree(candidateSf, subtreeRoot);
|
|
3390
|
+
worklist.push(...next);
|
|
3391
|
+
candidateSf.delete();
|
|
3392
|
+
deleted.add(candidate);
|
|
3393
|
+
orphans.push(candidate);
|
|
3394
|
+
}
|
|
3395
|
+
return orphans;
|
|
3396
|
+
}
|
|
3397
|
+
function processHandlerFile(project) {
|
|
3398
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
3399
|
+
const fp = sf.getFilePath();
|
|
3400
|
+
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
3401
|
+
});
|
|
3402
|
+
for (const sf of sourceFiles) {
|
|
3403
|
+
const fn = sf.getFunction(HANDLER_NAME);
|
|
3404
|
+
if (!fn) continue;
|
|
3405
|
+
const filePath = sf.getFilePath();
|
|
3406
|
+
const exportsByName = [...sf.getExportedDeclarations().keys()];
|
|
3407
|
+
const otherExports = exportsByName.filter((name) => name !== HANDLER_NAME);
|
|
3408
|
+
if (otherExports.length === 0) {
|
|
3409
|
+
const subtreeRoot = import_path16.default.dirname(filePath) + import_path16.default.sep;
|
|
3410
|
+
const orphansDeleted = deleteOrphanedDescendants(
|
|
3411
|
+
project,
|
|
3412
|
+
sf,
|
|
3413
|
+
subtreeRoot
|
|
3414
|
+
);
|
|
3415
|
+
sf.delete();
|
|
3416
|
+
return { filePath, action: "deleted", orphansDeleted };
|
|
3417
|
+
}
|
|
3418
|
+
fn.remove();
|
|
3419
|
+
return {
|
|
3420
|
+
filePath,
|
|
3421
|
+
action: "function-removed",
|
|
3422
|
+
remainingExports: otherExports,
|
|
3423
|
+
orphansDeleted: []
|
|
3424
|
+
};
|
|
3425
|
+
}
|
|
3426
|
+
return { filePath: "", action: "not-found", orphansDeleted: [] };
|
|
3427
|
+
}
|
|
3428
|
+
async function main16() {
|
|
3429
|
+
const project = new import_ts_morph16.Project({
|
|
3430
|
+
tsConfigFilePath: import_path16.default.resolve(process.cwd(), "tsconfig.json"),
|
|
3431
|
+
skipAddingFilesFromTsConfig: false
|
|
3432
|
+
});
|
|
3433
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
3434
|
+
const fp = sf.getFilePath();
|
|
3435
|
+
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
3436
|
+
});
|
|
3437
|
+
console.log(
|
|
3438
|
+
`Removing legacy 'GET ${ROUTE_PATH}' route and '${HANDLER_NAME}' across ${sourceFiles.length} source file(s)...
|
|
3439
|
+
`
|
|
3440
|
+
);
|
|
3441
|
+
let totalRoutesRemoved = 0;
|
|
3442
|
+
let totalFilesWithImportsCleaned = 0;
|
|
3443
|
+
let totalFilesWithRoutesRemoved = 0;
|
|
3444
|
+
for (const sourceFile of sourceFiles) {
|
|
3445
|
+
const filePath = sourceFile.getFilePath();
|
|
3446
|
+
const rel = import_path16.default.relative(process.cwd(), filePath);
|
|
3447
|
+
const result = processFile12(sourceFile);
|
|
3448
|
+
if (result.routesRemoved > 0) {
|
|
3449
|
+
console.log(
|
|
3450
|
+
` [${rel}] Removed ${result.routesRemoved} '${ROUTE_PATH}' route(s)`
|
|
3451
|
+
);
|
|
3452
|
+
totalRoutesRemoved += result.routesRemoved;
|
|
3453
|
+
totalFilesWithRoutesRemoved++;
|
|
3454
|
+
}
|
|
3455
|
+
if (result.importsCleaned) {
|
|
3456
|
+
console.log(` [${rel}] Cleaned up '${HANDLER_NAME}' import`);
|
|
3457
|
+
totalFilesWithImportsCleaned++;
|
|
3458
|
+
}
|
|
3459
|
+
if (result.routesRemoved > 0 || result.importsCleaned) {
|
|
3460
|
+
await sourceFile.save();
|
|
3461
|
+
}
|
|
3462
|
+
}
|
|
3463
|
+
const handlerResult = processHandlerFile(project);
|
|
3464
|
+
switch (handlerResult.action) {
|
|
3465
|
+
case "deleted": {
|
|
3466
|
+
const rel = import_path16.default.relative(process.cwd(), handlerResult.filePath);
|
|
3467
|
+
console.log(
|
|
3468
|
+
` [${rel}] Deleted handler file ('${HANDLER_NAME}' was the sole export).`
|
|
3469
|
+
);
|
|
3470
|
+
for (const orphanPath of handlerResult.orphansDeleted) {
|
|
3471
|
+
const orphanRel = import_path16.default.relative(process.cwd(), orphanPath);
|
|
3472
|
+
console.log(
|
|
3473
|
+
` [${orphanRel}] Deleted (no remaining importers in the project after handler removal).`
|
|
3474
|
+
);
|
|
3475
|
+
}
|
|
3476
|
+
await project.save();
|
|
3477
|
+
break;
|
|
3478
|
+
}
|
|
3479
|
+
case "function-removed": {
|
|
3480
|
+
const rel = import_path16.default.relative(process.cwd(), handlerResult.filePath);
|
|
3481
|
+
console.warn(
|
|
3482
|
+
` [${rel}] Removed '${HANDLER_NAME}' function but kept the file (other exports remain: ${handlerResult.remainingExports?.join(", ")}). Review whether the file is still needed.`
|
|
3483
|
+
);
|
|
3484
|
+
const sf = project.getSourceFile(handlerResult.filePath);
|
|
3485
|
+
if (sf) await sf.save();
|
|
3486
|
+
break;
|
|
3487
|
+
}
|
|
3488
|
+
case "not-found":
|
|
3489
|
+
break;
|
|
3490
|
+
}
|
|
3491
|
+
if (totalRoutesRemoved === 0 && totalFilesWithImportsCleaned === 0 && handlerResult.action === "not-found") {
|
|
3492
|
+
console.log(`
|
|
3493
|
+
No legacy '${ROUTE_PATH}' route or handler found. Nothing to do.`);
|
|
3494
|
+
return;
|
|
3495
|
+
}
|
|
3496
|
+
const orphansSummary = handlerResult.orphansDeleted.length > 0 ? ` and ${handlerResult.orphansDeleted.length} orphaned helper file(s)` : "";
|
|
3497
|
+
console.log(
|
|
3498
|
+
`
|
|
3499
|
+
Done. Removed ${totalRoutesRemoved} route(s) across ${totalFilesWithRoutesRemoved} file(s); cleaned ${HANDLER_NAME} import in ${totalFilesWithImportsCleaned} file(s)${orphansSummary}.`
|
|
3500
|
+
);
|
|
3501
|
+
}
|
|
3502
|
+
|
|
3503
|
+
// src/migrations/v2.0/update-package-json.ts
|
|
3504
|
+
var import_fs = require("fs");
|
|
3505
|
+
var import_path17 = __toESM(require("path"));
|
|
3506
|
+
var PACKAGE_JSON_RELATIVE = "package.json";
|
|
3507
|
+
var TARGET_VERSION = "2.0.0";
|
|
3508
|
+
var TARGET_ZOD_RANGE = "^4.2.1";
|
|
3509
|
+
async function main17() {
|
|
3510
|
+
const packageJsonPath = import_path17.default.join(process.cwd(), PACKAGE_JSON_RELATIVE);
|
|
3511
|
+
if (!(0, import_fs.existsSync)(packageJsonPath)) {
|
|
3512
|
+
console.log(`'${PACKAGE_JSON_RELATIVE}' not found in ${process.cwd()} \u2014 skipping.`);
|
|
3513
|
+
return;
|
|
3514
|
+
}
|
|
3515
|
+
const raw = (0, import_fs.readFileSync)(packageJsonPath, "utf8");
|
|
3516
|
+
let parsed;
|
|
3517
|
+
try {
|
|
3518
|
+
parsed = JSON.parse(raw);
|
|
3519
|
+
} catch (error) {
|
|
3520
|
+
console.warn(
|
|
3521
|
+
` [${PACKAGE_JSON_RELATIVE}] Failed to parse JSON \u2014 skipping update. ${error.message}`
|
|
3522
|
+
);
|
|
3523
|
+
return;
|
|
3524
|
+
}
|
|
3525
|
+
console.log(`Updating '${PACKAGE_JSON_RELATIVE}'...`);
|
|
3526
|
+
const previousVersion = parsed.version;
|
|
3527
|
+
const versionChanged = previousVersion !== TARGET_VERSION;
|
|
3528
|
+
parsed.version = TARGET_VERSION;
|
|
3529
|
+
if (versionChanged) {
|
|
3530
|
+
console.log(
|
|
3531
|
+
` Set version: ${previousVersion ?? "<unset>"} \u2192 ${TARGET_VERSION}`
|
|
3532
|
+
);
|
|
3533
|
+
} else {
|
|
3534
|
+
console.log(` Version already ${TARGET_VERSION} \u2014 no change.`);
|
|
3535
|
+
}
|
|
3536
|
+
let zodBucket = "dependencies";
|
|
3537
|
+
if (parsed.devDependencies && "zod" in parsed.devDependencies) {
|
|
3538
|
+
zodBucket = "devDependencies";
|
|
3539
|
+
}
|
|
3540
|
+
if (!parsed[zodBucket]) {
|
|
3541
|
+
parsed[zodBucket] = {};
|
|
3542
|
+
}
|
|
3543
|
+
const bucket = parsed[zodBucket];
|
|
3544
|
+
const previousZod = bucket.zod;
|
|
3545
|
+
const zodChanged = previousZod !== TARGET_ZOD_RANGE;
|
|
3546
|
+
bucket.zod = TARGET_ZOD_RANGE;
|
|
3547
|
+
if (zodChanged) {
|
|
3548
|
+
console.log(
|
|
3549
|
+
` Set ${zodBucket}.zod: ${previousZod ?? "<absent>"} \u2192 ${TARGET_ZOD_RANGE}`
|
|
3550
|
+
);
|
|
3551
|
+
} else {
|
|
3552
|
+
console.log(` ${zodBucket}.zod already ${TARGET_ZOD_RANGE} \u2014 no change.`);
|
|
3553
|
+
}
|
|
3554
|
+
const trailingNewline = raw.endsWith("\n") ? "\n" : "";
|
|
3555
|
+
const next = JSON.stringify(parsed, null, 2) + trailingNewline;
|
|
3556
|
+
if (next === raw) {
|
|
3557
|
+
console.log("\n No changes to write.");
|
|
3558
|
+
return;
|
|
3559
|
+
}
|
|
3560
|
+
(0, import_fs.writeFileSync)(packageJsonPath, next, "utf8");
|
|
3561
|
+
console.log(`
|
|
3562
|
+
Saved '${PACKAGE_JSON_RELATIVE}'.`);
|
|
3563
|
+
console.log(
|
|
3564
|
+
` NOTE: run \`yarn install\` (or your package manager equivalent) to install the updated dependency versions.`
|
|
3565
|
+
);
|
|
3566
|
+
}
|
|
3567
|
+
|
|
3568
|
+
// src/migrations/v2.0/migrate-workqueue-configs.ts
|
|
3569
|
+
var import_ts_morph17 = require("ts-morph");
|
|
3570
|
+
var import_path18 = __toESM(require("path"));
|
|
2848
3571
|
var DEFINE_WORKQUEUES_NAME3 = "defineWorkqueues";
|
|
2849
3572
|
var ACTIONS_PROPERTY_NAME5 = "actions";
|
|
2850
3573
|
var ACTION_PROPERTY_NAME2 = "action";
|
|
@@ -2863,289 +3586,1136 @@ var SUPPORTED_WORKQUEUE_ACTION_TYPES = /* @__PURE__ */ new Set([
|
|
|
2863
3586
|
"PRINT_CERTIFICATE",
|
|
2864
3587
|
"REQUEST_CORRECTION"
|
|
2865
3588
|
]);
|
|
2866
|
-
function getWorkqueueLabel(workqueue) {
|
|
2867
|
-
const slugProperty = workqueue.getProperty(SLUG_PROPERTY_NAME);
|
|
2868
|
-
if (!slugProperty || !
|
|
2869
|
-
return "(unknown slug)";
|
|
3589
|
+
function getWorkqueueLabel(workqueue) {
|
|
3590
|
+
const slugProperty = workqueue.getProperty(SLUG_PROPERTY_NAME);
|
|
3591
|
+
if (!slugProperty || !import_ts_morph17.Node.isPropertyAssignment(slugProperty)) {
|
|
3592
|
+
return "(unknown slug)";
|
|
3593
|
+
}
|
|
3594
|
+
const slugInitializer = slugProperty.getInitializer();
|
|
3595
|
+
if (!slugInitializer || !import_ts_morph17.Node.isStringLiteral(slugInitializer)) {
|
|
3596
|
+
return "(unknown slug)";
|
|
3597
|
+
}
|
|
3598
|
+
return slugInitializer.getLiteralValue();
|
|
3599
|
+
}
|
|
3600
|
+
function getActionTypeName(action) {
|
|
3601
|
+
const typeProperty = action.getProperty(TYPE_PROPERTY_NAME7);
|
|
3602
|
+
if (!typeProperty || !import_ts_morph17.Node.isPropertyAssignment(typeProperty)) {
|
|
3603
|
+
return null;
|
|
3604
|
+
}
|
|
3605
|
+
const typeInitializer = typeProperty.getInitializer();
|
|
3606
|
+
if (!typeInitializer) {
|
|
3607
|
+
return null;
|
|
3608
|
+
}
|
|
3609
|
+
if (import_ts_morph17.Node.isStringLiteral(typeInitializer)) {
|
|
3610
|
+
return typeInitializer.getLiteralValue();
|
|
3611
|
+
}
|
|
3612
|
+
if (import_ts_morph17.Node.isPropertyAccessExpression(typeInitializer)) {
|
|
3613
|
+
return typeInitializer.getName();
|
|
3614
|
+
}
|
|
3615
|
+
return null;
|
|
3616
|
+
}
|
|
3617
|
+
function isUnsupportedActionType(action) {
|
|
3618
|
+
const typeName = getActionTypeName(action);
|
|
3619
|
+
if (!typeName) {
|
|
3620
|
+
return false;
|
|
3621
|
+
}
|
|
3622
|
+
return !SUPPORTED_WORKQUEUE_ACTION_TYPES.has(typeName);
|
|
3623
|
+
}
|
|
3624
|
+
function migrateWorkqueueActions(workqueue, relPath) {
|
|
3625
|
+
const actionsProperty = workqueue.getProperty(ACTIONS_PROPERTY_NAME5);
|
|
3626
|
+
if (!actionsProperty || !import_ts_morph17.Node.isPropertyAssignment(actionsProperty)) {
|
|
3627
|
+
return 0;
|
|
3628
|
+
}
|
|
3629
|
+
const actionsInitializer = actionsProperty.getInitializer();
|
|
3630
|
+
if (!actionsInitializer || !import_ts_morph17.Node.isArrayLiteralExpression(actionsInitializer)) {
|
|
3631
|
+
return 0;
|
|
3632
|
+
}
|
|
3633
|
+
const workqueueLabel = getWorkqueueLabel(workqueue);
|
|
3634
|
+
const existingActionProperty = workqueue.getProperty(ACTION_PROPERTY_NAME2);
|
|
3635
|
+
if (existingActionProperty) {
|
|
3636
|
+
if (import_ts_morph17.Node.isPropertyAssignment(existingActionProperty)) {
|
|
3637
|
+
const existingActionInitializer = existingActionProperty.getInitializer();
|
|
3638
|
+
if (existingActionInitializer && import_ts_morph17.Node.isObjectLiteralExpression(existingActionInitializer)) {
|
|
3639
|
+
const conditionalsProperty2 = existingActionInitializer.getProperty(
|
|
3640
|
+
CONDITIONALS_PROPERTY_NAME
|
|
3641
|
+
);
|
|
3642
|
+
if (conditionalsProperty2) {
|
|
3643
|
+
conditionalsProperty2.remove();
|
|
3644
|
+
console.log(
|
|
3645
|
+
` [${relPath}] Removed deprecated 'conditionals' from 'action' on workqueue '${workqueueLabel}'`
|
|
3646
|
+
);
|
|
3647
|
+
}
|
|
3648
|
+
if (isUnsupportedActionType(existingActionInitializer)) {
|
|
3649
|
+
existingActionProperty.remove();
|
|
3650
|
+
console.log(
|
|
3651
|
+
` [${relPath}] Removed unsupported 'action' type on workqueue '${workqueueLabel}'`
|
|
3652
|
+
);
|
|
3653
|
+
}
|
|
3654
|
+
}
|
|
3655
|
+
}
|
|
3656
|
+
actionsProperty.remove();
|
|
3657
|
+
console.log(
|
|
3658
|
+
` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' (existing 'action' kept)`
|
|
3659
|
+
);
|
|
3660
|
+
return 1;
|
|
3661
|
+
}
|
|
3662
|
+
const actionCandidates = actionsInitializer.getElements().filter(
|
|
3663
|
+
(element) => import_ts_morph17.Node.isObjectLiteralExpression(element)
|
|
3664
|
+
);
|
|
3665
|
+
if (actionCandidates.length === 0) {
|
|
3666
|
+
actionsProperty.remove();
|
|
3667
|
+
console.log(
|
|
3668
|
+
` [${relPath}] Removed empty 'actions' from workqueue '${workqueueLabel}'`
|
|
3669
|
+
);
|
|
3670
|
+
return 1;
|
|
3671
|
+
}
|
|
3672
|
+
if (actionCandidates.length > 1) {
|
|
3673
|
+
const droppedCount = actionCandidates.length - 1;
|
|
3674
|
+
console.warn(
|
|
3675
|
+
` [${relPath}] Workqueue '${workqueueLabel}' has ${actionCandidates.length} actions; keeping first as 'action' and dropping ${droppedCount} extra action(s)`
|
|
3676
|
+
);
|
|
3677
|
+
}
|
|
3678
|
+
const conditionalsProperty = actionCandidates[0].getProperty(
|
|
3679
|
+
CONDITIONALS_PROPERTY_NAME
|
|
3680
|
+
);
|
|
3681
|
+
if (conditionalsProperty) {
|
|
3682
|
+
conditionalsProperty.remove();
|
|
3683
|
+
console.log(
|
|
3684
|
+
` [${relPath}] Removed deprecated 'conditionals' from migrated 'action' on workqueue '${workqueueLabel}'`
|
|
3685
|
+
);
|
|
3686
|
+
}
|
|
3687
|
+
if (isUnsupportedActionType(actionCandidates[0])) {
|
|
3688
|
+
actionsProperty.remove();
|
|
3689
|
+
console.log(
|
|
3690
|
+
` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' because action type is unsupported`
|
|
3691
|
+
);
|
|
3692
|
+
return 1;
|
|
3693
|
+
}
|
|
3694
|
+
const firstActionText = actionCandidates[0].getText();
|
|
3695
|
+
workqueue.addPropertyAssignment({
|
|
3696
|
+
name: ACTION_PROPERTY_NAME2,
|
|
3697
|
+
initializer: firstActionText
|
|
3698
|
+
});
|
|
3699
|
+
actionsProperty.remove();
|
|
3700
|
+
console.log(
|
|
3701
|
+
` [${relPath}] Replaced 'actions' with 'action' on workqueue '${workqueueLabel}'`
|
|
3702
|
+
);
|
|
3703
|
+
return 1;
|
|
3704
|
+
}
|
|
3705
|
+
function processFile13(filePath, project) {
|
|
3706
|
+
const sourceFile = project.getSourceFile(filePath);
|
|
3707
|
+
if (!sourceFile) return 0;
|
|
3708
|
+
let migratedWorkqueues = 0;
|
|
3709
|
+
const relPath = import_path18.default.relative(process.cwd(), filePath);
|
|
3710
|
+
const callExpressions = sourceFile.getDescendantsOfKind(
|
|
3711
|
+
import_ts_morph17.SyntaxKind.CallExpression
|
|
3712
|
+
);
|
|
3713
|
+
for (const call of callExpressions) {
|
|
3714
|
+
const expression = call.getExpression();
|
|
3715
|
+
if (!import_ts_morph17.Node.isIdentifier(expression) || expression.getText() !== DEFINE_WORKQUEUES_NAME3) {
|
|
3716
|
+
continue;
|
|
3717
|
+
}
|
|
3718
|
+
const args2 = call.getArguments();
|
|
3719
|
+
if (args2.length === 0) continue;
|
|
3720
|
+
const workqueuesArg = args2[0];
|
|
3721
|
+
if (!import_ts_morph17.Node.isArrayLiteralExpression(workqueuesArg)) continue;
|
|
3722
|
+
for (const element of workqueuesArg.getElements()) {
|
|
3723
|
+
if (!import_ts_morph17.Node.isObjectLiteralExpression(element)) continue;
|
|
3724
|
+
migratedWorkqueues += migrateWorkqueueActions(element, relPath);
|
|
3725
|
+
}
|
|
3726
|
+
}
|
|
3727
|
+
return migratedWorkqueues;
|
|
3728
|
+
}
|
|
3729
|
+
async function main18() {
|
|
3730
|
+
const srcDir = import_path18.default.join(process.cwd(), "src");
|
|
3731
|
+
console.log(`Scanning for defineWorkqueues calls in: ${srcDir}
|
|
3732
|
+
`);
|
|
3733
|
+
const project = new import_ts_morph17.Project({
|
|
3734
|
+
tsConfigFilePath: import_path18.default.resolve(srcDir, "../tsconfig.json"),
|
|
3735
|
+
skipAddingFilesFromTsConfig: false
|
|
3736
|
+
});
|
|
3737
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
3738
|
+
const fp = sf.getFilePath();
|
|
3739
|
+
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
3740
|
+
});
|
|
3741
|
+
console.log(`Found ${sourceFiles.length} source file(s) to analyse.
|
|
3742
|
+
`);
|
|
3743
|
+
let totalMigrated = 0;
|
|
3744
|
+
const modifiedFiles = [];
|
|
3745
|
+
for (const sourceFile of sourceFiles) {
|
|
3746
|
+
const filePath = sourceFile.getFilePath();
|
|
3747
|
+
const migrated = processFile13(filePath, project);
|
|
3748
|
+
if (migrated > 0) {
|
|
3749
|
+
totalMigrated += migrated;
|
|
3750
|
+
modifiedFiles.push(filePath);
|
|
3751
|
+
}
|
|
3752
|
+
}
|
|
3753
|
+
if (modifiedFiles.length === 0) {
|
|
3754
|
+
console.log(
|
|
3755
|
+
"No deprecated workqueue 'actions' arrays found inside defineWorkqueues calls. Nothing to do."
|
|
3756
|
+
);
|
|
3757
|
+
return;
|
|
3758
|
+
}
|
|
3759
|
+
console.log(`
|
|
3760
|
+
Saving ${modifiedFiles.length} modified file(s)...`);
|
|
3761
|
+
for (const filePath of modifiedFiles) {
|
|
3762
|
+
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
3763
|
+
await sourceFile.save();
|
|
3764
|
+
console.log(` Saved: ${import_path18.default.relative(process.cwd(), filePath)}`);
|
|
3765
|
+
}
|
|
3766
|
+
console.log(
|
|
3767
|
+
`
|
|
3768
|
+
Done. Migrated ${totalMigrated} deprecated workqueue 'actions' definition(s) to 'action'.`
|
|
3769
|
+
);
|
|
3770
|
+
}
|
|
3771
|
+
|
|
3772
|
+
// src/migrations/v2.0/remove-demo-scope.ts
|
|
3773
|
+
var import_path19 = __toESM(require("path"));
|
|
3774
|
+
var import_ts_morph18 = require("ts-morph");
|
|
3775
|
+
var ROLES_HANDLER_RELATIVE_PATH = "src/data-seeding/roles/handler.ts";
|
|
3776
|
+
async function main19() {
|
|
3777
|
+
const rolesHandlerPath = import_path19.default.join(process.cwd(), ROLES_HANDLER_RELATIVE_PATH);
|
|
3778
|
+
const project = new import_ts_morph18.Project({
|
|
3779
|
+
tsConfigFilePath: import_path19.default.resolve(process.cwd(), "tsconfig.json"),
|
|
3780
|
+
skipAddingFilesFromTsConfig: false
|
|
3781
|
+
});
|
|
3782
|
+
const sourceFile = project.getSourceFile(rolesHandlerPath);
|
|
3783
|
+
if (!sourceFile) {
|
|
3784
|
+
console.log(
|
|
3785
|
+
`No roles handler found at '${ROLES_HANDLER_RELATIVE_PATH}'. Nothing to do.`
|
|
3786
|
+
);
|
|
3787
|
+
return;
|
|
3788
|
+
}
|
|
3789
|
+
let changed = false;
|
|
3790
|
+
const constantsImport = sourceFile.getImportDeclaration(
|
|
3791
|
+
(decl) => decl.getModuleSpecifierValue() === "@countryconfig/constants"
|
|
3792
|
+
);
|
|
3793
|
+
if (constantsImport) {
|
|
3794
|
+
constantsImport.remove();
|
|
3795
|
+
changed = true;
|
|
3796
|
+
}
|
|
3797
|
+
const rolesHandler = sourceFile.getFunction("rolesHandler");
|
|
3798
|
+
if (!rolesHandler) {
|
|
3799
|
+
console.log(
|
|
3800
|
+
`No rolesHandler export found in '${ROLES_HANDLER_RELATIVE_PATH}'. Nothing to do.`
|
|
3801
|
+
);
|
|
3802
|
+
return;
|
|
3803
|
+
}
|
|
3804
|
+
const secondParam = rolesHandler.getParameters()[1];
|
|
3805
|
+
const secondParamName = secondParam?.getName();
|
|
3806
|
+
const responseToolkitIdentifier = secondParamName || "h";
|
|
3807
|
+
const currentBodyText = rolesHandler.getBodyText();
|
|
3808
|
+
const normalizedCurrent = currentBodyText?.replace(/\s+/g, " ").trim() ?? "";
|
|
3809
|
+
const normalizedDesired = `return ${responseToolkitIdentifier}.response(roles)`;
|
|
3810
|
+
if (normalizedCurrent !== normalizedDesired) {
|
|
3811
|
+
rolesHandler.setBodyText(`return ${responseToolkitIdentifier}.response(roles)`);
|
|
3812
|
+
changed = true;
|
|
3813
|
+
}
|
|
3814
|
+
if (!changed) {
|
|
3815
|
+
console.log(
|
|
3816
|
+
`No changes needed in '${ROLES_HANDLER_RELATIVE_PATH}'.`
|
|
3817
|
+
);
|
|
3818
|
+
return;
|
|
3819
|
+
}
|
|
3820
|
+
await sourceFile.save();
|
|
3821
|
+
console.log(
|
|
3822
|
+
`Updated '${ROLES_HANDLER_RELATIVE_PATH}' to remove demo scope behavior while preserving file structure.`
|
|
3823
|
+
);
|
|
3824
|
+
}
|
|
3825
|
+
|
|
3826
|
+
// src/migrations/v2.0/remove-hearth-migrations.ts
|
|
3827
|
+
var fs2 = __toESM(require("fs"));
|
|
3828
|
+
var import_path20 = __toESM(require("path"));
|
|
3829
|
+
var PATHS_TO_REMOVE = [
|
|
3830
|
+
{
|
|
3831
|
+
relativePath: "src/migrations/hearth",
|
|
3832
|
+
label: "Hearth migrations directory"
|
|
3833
|
+
},
|
|
3834
|
+
{
|
|
3835
|
+
relativePath: "src/migrations/user-mgnt",
|
|
3836
|
+
label: "user-mgnt migrations directory"
|
|
3837
|
+
},
|
|
3838
|
+
{ relativePath: "src/utils/hearth-helpers.ts", label: "Hearth helpers file" }
|
|
3839
|
+
];
|
|
3840
|
+
async function main20() {
|
|
3841
|
+
for (const { relativePath, label } of PATHS_TO_REMOVE) {
|
|
3842
|
+
const absolutePath = import_path20.default.join(process.cwd(), relativePath);
|
|
3843
|
+
if (fs2.existsSync(absolutePath)) {
|
|
3844
|
+
fs2.rmSync(absolutePath, { recursive: true, force: true });
|
|
3845
|
+
console.log(`Removed ${label} '${relativePath}'.`);
|
|
3846
|
+
} else {
|
|
3847
|
+
console.log(`No ${label} found at '${relativePath}'.`);
|
|
3848
|
+
}
|
|
3849
|
+
}
|
|
3850
|
+
}
|
|
3851
|
+
|
|
3852
|
+
// src/migrations/v2.0/create-events-index.ts
|
|
3853
|
+
var import_ts_morph19 = require("ts-morph");
|
|
3854
|
+
var import_fs2 = __toESM(require("fs"));
|
|
3855
|
+
var import_path21 = __toESM(require("path"));
|
|
3856
|
+
var DEFINE_CONFIG_NAME5 = "defineConfig";
|
|
3857
|
+
var HANDLER_FUNCTION_NAMES = /* @__PURE__ */ new Set([
|
|
3858
|
+
"getCustomEventsHandler",
|
|
3859
|
+
"getEventsHandler"
|
|
3860
|
+
]);
|
|
3861
|
+
var EVENT_CONFIGS_IDENTIFIER = "eventConfigs";
|
|
3862
|
+
var EVENTS_INDEX_IMPORT_PATH = "@countryconfig/events";
|
|
3863
|
+
var RESPONSE_METHOD_NAME = "response";
|
|
3864
|
+
var LICENSE_HEADER = `/*
|
|
3865
|
+
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
3866
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
3867
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
3868
|
+
*
|
|
3869
|
+
* OpenCRVS is also distributed under the terms of the Civil Registration
|
|
3870
|
+
* & Healthcare Disclaimer located at http://opencrvs.org/license.
|
|
3871
|
+
*
|
|
3872
|
+
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
|
|
3873
|
+
*/
|
|
3874
|
+
`;
|
|
3875
|
+
function findEventConfigExports(project, srcDir) {
|
|
3876
|
+
const found = [];
|
|
3877
|
+
const eventsIndexAbs = import_path21.default.join(srcDir, "events", "index.ts");
|
|
3878
|
+
for (const sourceFile of project.getSourceFiles()) {
|
|
3879
|
+
const filePath = sourceFile.getFilePath();
|
|
3880
|
+
if (!filePath.startsWith(srcDir) || filePath.includes("/node_modules/")) {
|
|
3881
|
+
continue;
|
|
3882
|
+
}
|
|
3883
|
+
if (filePath === eventsIndexAbs) continue;
|
|
3884
|
+
for (const statement of sourceFile.getVariableStatements()) {
|
|
3885
|
+
if (!statement.hasExportKeyword()) continue;
|
|
3886
|
+
for (const decl of statement.getDeclarations()) {
|
|
3887
|
+
const initializer = decl.getInitializer();
|
|
3888
|
+
if (!initializer) continue;
|
|
3889
|
+
const unwrapped = import_ts_morph19.Node.isAsExpression(initializer) ? initializer.getExpression() : initializer;
|
|
3890
|
+
if (!import_ts_morph19.Node.isCallExpression(unwrapped)) continue;
|
|
3891
|
+
const callee = unwrapped.getExpression();
|
|
3892
|
+
if (!import_ts_morph19.Node.isIdentifier(callee)) continue;
|
|
3893
|
+
if (callee.getText() !== DEFINE_CONFIG_NAME5) continue;
|
|
3894
|
+
found.push({ name: decl.getName(), filePath });
|
|
3895
|
+
}
|
|
3896
|
+
}
|
|
2870
3897
|
}
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
3898
|
+
return found;
|
|
3899
|
+
}
|
|
3900
|
+
function buildIndexImportSpecifier(eventConfigFilePath, srcDir) {
|
|
3901
|
+
const eventsIndexDir = import_path21.default.join(srcDir, "events");
|
|
3902
|
+
let rel = import_path21.default.relative(eventsIndexDir, eventConfigFilePath).split(import_path21.default.sep).join("/");
|
|
3903
|
+
if (rel.endsWith(".ts")) rel = rel.slice(0, -".ts".length);
|
|
3904
|
+
if (rel.endsWith("/index")) rel = rel.slice(0, -"/index".length);
|
|
3905
|
+
if (!rel.startsWith(".")) rel = "./" + rel;
|
|
3906
|
+
return rel;
|
|
3907
|
+
}
|
|
3908
|
+
function buildEventsIndexSource(exports, srcDir) {
|
|
3909
|
+
const imports = exports.map(
|
|
3910
|
+
(e) => `import { ${e.name} } from '${buildIndexImportSpecifier(
|
|
3911
|
+
e.filePath,
|
|
3912
|
+
srcDir
|
|
3913
|
+
)}'`
|
|
3914
|
+
).join("\n");
|
|
3915
|
+
const array3 = `export const ${EVENT_CONFIGS_IDENTIFIER} = [${exports.map((e) => e.name).join(", ")}]`;
|
|
3916
|
+
return `${LICENSE_HEADER}${imports}
|
|
3917
|
+
|
|
3918
|
+
${array3}
|
|
3919
|
+
`;
|
|
3920
|
+
}
|
|
3921
|
+
function findHandlerSourceFile(project, srcDir) {
|
|
3922
|
+
for (const sf of project.getSourceFiles()) {
|
|
3923
|
+
const fp = sf.getFilePath();
|
|
3924
|
+
if (!fp.startsWith(srcDir) || fp.includes("/node_modules/")) continue;
|
|
3925
|
+
for (const fn of sf.getFunctions()) {
|
|
3926
|
+
const name = fn.getName();
|
|
3927
|
+
if (name && HANDLER_FUNCTION_NAMES.has(name)) return sf;
|
|
3928
|
+
}
|
|
3929
|
+
for (const statement of sf.getVariableStatements()) {
|
|
3930
|
+
for (const decl of statement.getDeclarations()) {
|
|
3931
|
+
if (HANDLER_FUNCTION_NAMES.has(decl.getName())) return sf;
|
|
3932
|
+
}
|
|
3933
|
+
}
|
|
2874
3934
|
}
|
|
2875
|
-
return
|
|
3935
|
+
return void 0;
|
|
2876
3936
|
}
|
|
2877
|
-
function
|
|
2878
|
-
const
|
|
2879
|
-
|
|
2880
|
-
|
|
3937
|
+
function modifyHandler(sourceFile, exportNames) {
|
|
3938
|
+
const changes = [];
|
|
3939
|
+
for (const importDecl of [...sourceFile.getImportDeclarations()]) {
|
|
3940
|
+
const namedImports = importDecl.getNamedImports();
|
|
3941
|
+
if (namedImports.length === 0) continue;
|
|
3942
|
+
const matched = namedImports.filter((ni) => exportNames.has(ni.getName()));
|
|
3943
|
+
if (matched.length === 0) continue;
|
|
3944
|
+
const removedNames = matched.map((ni) => ni.getName());
|
|
3945
|
+
for (const ni of matched) ni.remove();
|
|
3946
|
+
changes.push(`removed direct imports: ${removedNames.join(", ")}`);
|
|
3947
|
+
const stillUsed = importDecl.getNamedImports().length > 0 || importDecl.getDefaultImport() || importDecl.getNamespaceImport();
|
|
3948
|
+
if (!stillUsed) importDecl.remove();
|
|
3949
|
+
}
|
|
3950
|
+
for (const statement of [...sourceFile.getVariableStatements()]) {
|
|
3951
|
+
if (!statement.hasExportKeyword()) continue;
|
|
3952
|
+
const hasEventConfigs = statement.getDeclarations().some((d) => d.getName() === EVENT_CONFIGS_IDENTIFIER);
|
|
3953
|
+
if (hasEventConfigs) {
|
|
3954
|
+
statement.remove();
|
|
3955
|
+
changes.push(`removed inline 'export const ${EVENT_CONFIGS_IDENTIFIER}'`);
|
|
3956
|
+
}
|
|
2881
3957
|
}
|
|
2882
|
-
const
|
|
2883
|
-
|
|
2884
|
-
|
|
3958
|
+
const existing = sourceFile.getImportDeclaration(
|
|
3959
|
+
(imp) => imp.getModuleSpecifierValue() === EVENTS_INDEX_IMPORT_PATH
|
|
3960
|
+
);
|
|
3961
|
+
if (existing) {
|
|
3962
|
+
const already = existing.getNamedImports().some((ni) => ni.getName() === EVENT_CONFIGS_IDENTIFIER);
|
|
3963
|
+
if (!already) {
|
|
3964
|
+
existing.addNamedImport(EVENT_CONFIGS_IDENTIFIER);
|
|
3965
|
+
changes.push(
|
|
3966
|
+
`added '${EVENT_CONFIGS_IDENTIFIER}' to existing import from '${EVENTS_INDEX_IMPORT_PATH}'`
|
|
3967
|
+
);
|
|
3968
|
+
}
|
|
3969
|
+
} else {
|
|
3970
|
+
sourceFile.addImportDeclaration({
|
|
3971
|
+
moduleSpecifier: EVENTS_INDEX_IMPORT_PATH,
|
|
3972
|
+
namedImports: [EVENT_CONFIGS_IDENTIFIER]
|
|
3973
|
+
});
|
|
3974
|
+
changes.push(
|
|
3975
|
+
`added import { ${EVENT_CONFIGS_IDENTIFIER} } from '${EVENTS_INDEX_IMPORT_PATH}'`
|
|
3976
|
+
);
|
|
2885
3977
|
}
|
|
2886
|
-
|
|
2887
|
-
|
|
3978
|
+
for (const call of sourceFile.getDescendantsOfKind(
|
|
3979
|
+
import_ts_morph19.SyntaxKind.CallExpression
|
|
3980
|
+
)) {
|
|
3981
|
+
const callee = call.getExpression();
|
|
3982
|
+
if (!import_ts_morph19.Node.isPropertyAccessExpression(callee)) continue;
|
|
3983
|
+
if (callee.getName() !== RESPONSE_METHOD_NAME) continue;
|
|
3984
|
+
const args2 = call.getArguments();
|
|
3985
|
+
if (args2.length !== 1) continue;
|
|
3986
|
+
const [arg] = args2;
|
|
3987
|
+
if (!import_ts_morph19.Node.isArrayLiteralExpression(arg)) continue;
|
|
3988
|
+
if (arg.getElements().length === 0) continue;
|
|
3989
|
+
if (!arg.getElements().every((el) => import_ts_morph19.Node.isIdentifier(el))) continue;
|
|
3990
|
+
arg.replaceWithText(EVENT_CONFIGS_IDENTIFIER);
|
|
3991
|
+
changes.push(
|
|
3992
|
+
`rewrote h.response([...]) \u2192 h.response(${EVENT_CONFIGS_IDENTIFIER})`
|
|
3993
|
+
);
|
|
2888
3994
|
}
|
|
2889
|
-
|
|
2890
|
-
|
|
3995
|
+
return changes;
|
|
3996
|
+
}
|
|
3997
|
+
async function main21() {
|
|
3998
|
+
const cwd = process.cwd();
|
|
3999
|
+
const srcDir = import_path21.default.join(cwd, "src");
|
|
4000
|
+
console.log(`Scanning for defineConfig event exports in: ${srcDir}
|
|
4001
|
+
`);
|
|
4002
|
+
const project = new import_ts_morph19.Project({
|
|
4003
|
+
tsConfigFilePath: import_path21.default.resolve(srcDir, "../tsconfig.json"),
|
|
4004
|
+
skipAddingFilesFromTsConfig: false
|
|
4005
|
+
});
|
|
4006
|
+
const eventConfigExports = findEventConfigExports(project, srcDir);
|
|
4007
|
+
if (eventConfigExports.length === 0) {
|
|
4008
|
+
console.log(
|
|
4009
|
+
"No top-level `export const X = defineConfig(...)` declarations found. Nothing to do."
|
|
4010
|
+
);
|
|
4011
|
+
return;
|
|
2891
4012
|
}
|
|
2892
|
-
|
|
4013
|
+
console.log(`Found ${eventConfigExports.length} event config export(s):`);
|
|
4014
|
+
for (const e of eventConfigExports) {
|
|
4015
|
+
console.log(` ${e.name} \u2190 ${import_path21.default.relative(cwd, e.filePath)}`);
|
|
4016
|
+
}
|
|
4017
|
+
const eventsIndexAbs = import_path21.default.join(srcDir, "events", "index.ts");
|
|
4018
|
+
const eventsIndexRel = import_path21.default.relative(cwd, eventsIndexAbs);
|
|
4019
|
+
if (import_fs2.default.existsSync(eventsIndexAbs)) {
|
|
4020
|
+
console.log(`
|
|
4021
|
+
[${eventsIndexRel}] already exists \u2014 leaving untouched.`);
|
|
4022
|
+
} else {
|
|
4023
|
+
import_fs2.default.mkdirSync(import_path21.default.dirname(eventsIndexAbs), { recursive: true });
|
|
4024
|
+
const source = buildEventsIndexSource(eventConfigExports, srcDir);
|
|
4025
|
+
const eventsIndexFile = project.createSourceFile(eventsIndexAbs, source, {
|
|
4026
|
+
overwrite: false
|
|
4027
|
+
});
|
|
4028
|
+
await eventsIndexFile.save();
|
|
4029
|
+
console.log(
|
|
4030
|
+
`
|
|
4031
|
+
[${eventsIndexRel}] created with ${EVENT_CONFIGS_IDENTIFIER} of ${eventConfigExports.length} event(s).`
|
|
4032
|
+
);
|
|
4033
|
+
}
|
|
4034
|
+
const handler = findHandlerSourceFile(project, srcDir);
|
|
4035
|
+
if (!handler) {
|
|
4036
|
+
console.log(
|
|
4037
|
+
`
|
|
4038
|
+
No event-config handler file found (looked for exported function(s): ${Array.from(
|
|
4039
|
+
HANDLER_FUNCTION_NAMES
|
|
4040
|
+
).join(", ")}). Skipping handler rewrite.`
|
|
4041
|
+
);
|
|
4042
|
+
return;
|
|
4043
|
+
}
|
|
4044
|
+
const handlerRelPath = import_path21.default.relative(cwd, handler.getFilePath());
|
|
4045
|
+
const exportNameSet = new Set(eventConfigExports.map((e) => e.name));
|
|
4046
|
+
const changes = modifyHandler(handler, exportNameSet);
|
|
4047
|
+
if (changes.length === 0) {
|
|
4048
|
+
console.log(`
|
|
4049
|
+
[${handlerRelPath}] already wired to ${EVENTS_INDEX_IMPORT_PATH} \u2014 no changes.`);
|
|
4050
|
+
return;
|
|
4051
|
+
}
|
|
4052
|
+
for (const c of changes) console.log(` [${handlerRelPath}] ${c}`);
|
|
4053
|
+
await handler.save();
|
|
4054
|
+
console.log(`
|
|
4055
|
+
Saved ${handlerRelPath}.`);
|
|
2893
4056
|
}
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
4057
|
+
|
|
4058
|
+
// src/migrations/v2.0/checkout-upstream-files.ts
|
|
4059
|
+
var import_child_process = require("child_process");
|
|
4060
|
+
var UPSTREAM_URL = "https://github.com/opencrvs/opencrvs-countryconfig.git";
|
|
4061
|
+
var UPSTREAM_BRANCH = "develop";
|
|
4062
|
+
var TEMP_REMOTE = "opencrvs-upgrade-v19-v20-codemod";
|
|
4063
|
+
var FILES_TO_CHECKOUT = [
|
|
4064
|
+
"src/analytics/analytics.ts",
|
|
4065
|
+
"Dockerfile",
|
|
4066
|
+
"Dockerfile.assets"
|
|
4067
|
+
];
|
|
4068
|
+
function runGit(args2, { silent = false } = {}) {
|
|
4069
|
+
return (0, import_child_process.execFileSync)("git", args2, {
|
|
4070
|
+
cwd: process.cwd(),
|
|
4071
|
+
encoding: "utf8",
|
|
4072
|
+
stdio: silent ? ["ignore", "pipe", "pipe"] : ["ignore", "pipe", "inherit"]
|
|
4073
|
+
});
|
|
4074
|
+
}
|
|
4075
|
+
function tryGit(args2) {
|
|
4076
|
+
try {
|
|
4077
|
+
runGit(args2, { silent: true });
|
|
4078
|
+
return true;
|
|
4079
|
+
} catch {
|
|
2897
4080
|
return false;
|
|
2898
4081
|
}
|
|
2899
|
-
return !SUPPORTED_WORKQUEUE_ACTION_TYPES.has(typeName);
|
|
2900
4082
|
}
|
|
2901
|
-
function
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
const actionsInitializer = actionsProperty.getInitializer();
|
|
2907
|
-
if (!actionsInitializer || !import_ts_morph13.Node.isArrayLiteralExpression(actionsInitializer)) {
|
|
2908
|
-
return 0;
|
|
4083
|
+
function assertIsGitRepo() {
|
|
4084
|
+
if (!tryGit(["rev-parse", "--is-inside-work-tree"])) {
|
|
4085
|
+
throw new Error(
|
|
4086
|
+
`${process.cwd()} is not a git repository. Initialise git (or run the upgrade inside a git checkout) before re-running.`
|
|
4087
|
+
);
|
|
2909
4088
|
}
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
4089
|
+
}
|
|
4090
|
+
async function main22() {
|
|
4091
|
+
console.log(
|
|
4092
|
+
`Checking out ${FILES_TO_CHECKOUT.length} file(s) from ${UPSTREAM_URL}@${UPSTREAM_BRANCH}...
|
|
4093
|
+
`
|
|
4094
|
+
);
|
|
4095
|
+
assertIsGitRepo();
|
|
4096
|
+
tryGit(["remote", "remove", TEMP_REMOTE]);
|
|
4097
|
+
try {
|
|
4098
|
+
console.log(` Adding temporary remote '${TEMP_REMOTE}' \u2192 ${UPSTREAM_URL}`);
|
|
4099
|
+
runGit(["remote", "add", TEMP_REMOTE, UPSTREAM_URL], { silent: true });
|
|
4100
|
+
console.log(` Fetching ${TEMP_REMOTE}/${UPSTREAM_BRANCH} (depth 1)...`);
|
|
4101
|
+
runGit(["fetch", "--depth=1", TEMP_REMOTE, UPSTREAM_BRANCH]);
|
|
4102
|
+
const ref = `${TEMP_REMOTE}/${UPSTREAM_BRANCH}`;
|
|
4103
|
+
const missing = [];
|
|
4104
|
+
let checkedOut = 0;
|
|
4105
|
+
for (const file of FILES_TO_CHECKOUT) {
|
|
4106
|
+
if (tryGit(["checkout", ref, "--", file])) {
|
|
4107
|
+
console.log(` Checked out ${file} from ${ref}`);
|
|
4108
|
+
checkedOut++;
|
|
4109
|
+
} else {
|
|
4110
|
+
console.warn(
|
|
4111
|
+
` [warn] ${file} not found on ${ref} \u2014 skipping. Verify the path exists on that branch.`
|
|
2918
4112
|
);
|
|
2919
|
-
|
|
2920
|
-
conditionalsProperty2.remove();
|
|
2921
|
-
console.log(
|
|
2922
|
-
` [${relPath}] Removed deprecated 'conditionals' from 'action' on workqueue '${workqueueLabel}'`
|
|
2923
|
-
);
|
|
2924
|
-
}
|
|
2925
|
-
if (isUnsupportedActionType(existingActionInitializer)) {
|
|
2926
|
-
existingActionProperty.remove();
|
|
2927
|
-
console.log(
|
|
2928
|
-
` [${relPath}] Removed unsupported 'action' type on workqueue '${workqueueLabel}'`
|
|
2929
|
-
);
|
|
2930
|
-
}
|
|
4113
|
+
missing.push(file);
|
|
2931
4114
|
}
|
|
2932
4115
|
}
|
|
2933
|
-
actionsProperty.remove();
|
|
2934
4116
|
console.log(
|
|
2935
|
-
`
|
|
4117
|
+
`
|
|
4118
|
+
Checked out ${checkedOut}/${FILES_TO_CHECKOUT.length} file(s) from ${ref}.`
|
|
2936
4119
|
);
|
|
2937
|
-
|
|
4120
|
+
if (missing.length > 0) {
|
|
4121
|
+
console.warn(` Missing on upstream branch: ${missing.join(", ")}`);
|
|
4122
|
+
}
|
|
4123
|
+
if (checkedOut > 0) {
|
|
4124
|
+
console.log(
|
|
4125
|
+
` Review the staged changes with: git diff --cached -- ${FILES_TO_CHECKOUT.map(
|
|
4126
|
+
(f) => `'${f}'`
|
|
4127
|
+
).join(" ")}
|
|
4128
|
+
`
|
|
4129
|
+
);
|
|
4130
|
+
}
|
|
4131
|
+
} finally {
|
|
4132
|
+
if (tryGit(["remote", "remove", TEMP_REMOTE])) {
|
|
4133
|
+
console.log(` Removed temporary remote '${TEMP_REMOTE}'.`);
|
|
4134
|
+
}
|
|
4135
|
+
}
|
|
4136
|
+
}
|
|
4137
|
+
|
|
4138
|
+
// src/migrations/v2.0/add-resend-invite-notification.ts
|
|
4139
|
+
var import_fs3 = require("fs");
|
|
4140
|
+
var import_path22 = __toESM(require("path"));
|
|
4141
|
+
var import_ts_morph20 = require("ts-morph");
|
|
4142
|
+
var EMAIL_TEMPLATES_INDEX = "src/api/notification/email-templates/index.ts";
|
|
4143
|
+
var NOTIFICATION_HANDLER = "src/api/notification/handler.ts";
|
|
4144
|
+
var USER_NOTIFICATION_ROUTES = "src/config/routes/userNotificationRoutes.ts";
|
|
4145
|
+
var SMS_SERVICE = "src/api/notification/sms-service.ts";
|
|
4146
|
+
var NOTIFICATION_CSV = "src/translations/notification.csv";
|
|
4147
|
+
var RESEND_INVITE_HTML = "src/api/notification/email-templates/other/resend-invite.html";
|
|
4148
|
+
var RESEND_INVITE_HTML_CONTENT = `<!doctype html>
|
|
4149
|
+
<html>
|
|
4150
|
+
<head>
|
|
4151
|
+
<link
|
|
4152
|
+
href="https://fonts.googleapis.com/css2?family=Noto+Sans:wght@400;700&display=swap"
|
|
4153
|
+
rel="stylesheet"
|
|
4154
|
+
/>
|
|
4155
|
+
<style type="text/css">
|
|
4156
|
+
body {
|
|
4157
|
+
font-family: 'Noto Sans', sans-serif;
|
|
4158
|
+
color: #222;
|
|
4159
|
+
padding: 16px 24px;
|
|
4160
|
+
}
|
|
4161
|
+
|
|
4162
|
+
h1 {
|
|
4163
|
+
font-size: 21px;
|
|
4164
|
+
margin-top: 32px;
|
|
4165
|
+
margin-bottom: 36px;
|
|
4166
|
+
font-weight: 700;
|
|
4167
|
+
}
|
|
4168
|
+
|
|
4169
|
+
p {
|
|
4170
|
+
font-weight: 400;
|
|
4171
|
+
font-size: 16px;
|
|
4172
|
+
line-height: 1.8;
|
|
4173
|
+
margin-bottom: 24px;
|
|
4174
|
+
}
|
|
4175
|
+
|
|
4176
|
+
i {
|
|
4177
|
+
color: #666;
|
|
4178
|
+
font-weight: 400;
|
|
4179
|
+
font-size: 16px;
|
|
4180
|
+
}
|
|
4181
|
+
</style>
|
|
4182
|
+
</head>
|
|
4183
|
+
|
|
4184
|
+
<body>
|
|
4185
|
+
<img
|
|
4186
|
+
src="{{countryLogo}}"
|
|
4187
|
+
alt="country_logo"
|
|
4188
|
+
style="max-height: 88px; max-width: 100%"
|
|
4189
|
+
/>
|
|
4190
|
+
<h1>Your {{applicationName}} account invitation</h1>
|
|
4191
|
+
<p>Hello {{firstname}},</p>
|
|
4192
|
+
<p>Your account invitation has been resent. Please use the following credentials to access your account:</p>
|
|
4193
|
+
<p>
|
|
4194
|
+
Username: <strong>{{username}}</strong><br />
|
|
4195
|
+
Password: <strong>{{temporaryPassword}}</strong>
|
|
4196
|
+
</p>
|
|
4197
|
+
<p>
|
|
4198
|
+
Please click the link below to complete your account setup and start using
|
|
4199
|
+
{{applicationName}}.
|
|
4200
|
+
</p>
|
|
4201
|
+
|
|
4202
|
+
<div style="margin-top: 32px; margin-bottom: 32px">
|
|
4203
|
+
<a href="{{loginURL}}">Complete setup</a>
|
|
4204
|
+
</div>
|
|
4205
|
+
<br />
|
|
4206
|
+
<p>
|
|
4207
|
+
Best regards, <br />
|
|
4208
|
+
{{applicationName}} Team
|
|
4209
|
+
</p>
|
|
4210
|
+
</body>
|
|
4211
|
+
</html>
|
|
4212
|
+
`;
|
|
4213
|
+
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";
|
|
4214
|
+
function getObjectLiteralFromConst(declaration) {
|
|
4215
|
+
if (!declaration) {
|
|
4216
|
+
return;
|
|
4217
|
+
}
|
|
4218
|
+
const initializer = declaration.getInitializer();
|
|
4219
|
+
if (!initializer) {
|
|
4220
|
+
return;
|
|
4221
|
+
}
|
|
4222
|
+
if (import_ts_morph20.Node.isObjectLiteralExpression(initializer)) {
|
|
4223
|
+
return initializer;
|
|
4224
|
+
}
|
|
4225
|
+
if (import_ts_morph20.Node.isAsExpression(initializer)) {
|
|
4226
|
+
const expression = initializer.getExpression();
|
|
4227
|
+
if (import_ts_morph20.Node.isObjectLiteralExpression(expression)) {
|
|
4228
|
+
return expression;
|
|
4229
|
+
}
|
|
4230
|
+
}
|
|
4231
|
+
}
|
|
4232
|
+
function patchEmailTemplatesIndex() {
|
|
4233
|
+
const full = import_path22.default.join(process.cwd(), EMAIL_TEMPLATES_INDEX);
|
|
4234
|
+
if (!(0, import_fs3.existsSync)(full)) {
|
|
4235
|
+
console.log(` '${EMAIL_TEMPLATES_INDEX}' missing \u2014 skipping.`);
|
|
4236
|
+
return false;
|
|
4237
|
+
}
|
|
4238
|
+
const project = new import_ts_morph20.Project({
|
|
4239
|
+
skipAddingFilesFromTsConfig: true
|
|
4240
|
+
});
|
|
4241
|
+
const sourceFile = project.addSourceFileAtPath(full);
|
|
4242
|
+
let changed = false;
|
|
4243
|
+
const triggerVariableObject = getObjectLiteralFromConst(
|
|
4244
|
+
sourceFile.getVariableDeclaration("TriggerVariable")
|
|
4245
|
+
);
|
|
4246
|
+
if (triggerVariableObject) {
|
|
4247
|
+
const hasResendInviteVariable = triggerVariableObject.getProperties().some((prop) => prop.getText().includes("[TriggerEvent.RESEND_INVITE]"));
|
|
4248
|
+
if (!hasResendInviteVariable) {
|
|
4249
|
+
triggerVariableObject.addPropertyAssignment({
|
|
4250
|
+
name: "[TriggerEvent.RESEND_INVITE]",
|
|
4251
|
+
initializer: `z.object({
|
|
4252
|
+
firstname: z.string(),
|
|
4253
|
+
username: z.string(),
|
|
4254
|
+
temporaryPassword: z.string(),
|
|
4255
|
+
completeSetupUrl: z.string(),
|
|
4256
|
+
loginURL: z.string()
|
|
4257
|
+
})`
|
|
4258
|
+
});
|
|
4259
|
+
changed = true;
|
|
4260
|
+
}
|
|
4261
|
+
}
|
|
4262
|
+
const templatesObject = getObjectLiteralFromConst(
|
|
4263
|
+
sourceFile.getVariableDeclaration("templates")
|
|
4264
|
+
);
|
|
4265
|
+
if (templatesObject) {
|
|
4266
|
+
const hasResendInviteTemplate = templatesObject.getProperties().some(
|
|
4267
|
+
(prop) => prop.getText().includes("readOtherTemplate<TriggerVariable['resend-invite']>")
|
|
4268
|
+
);
|
|
4269
|
+
if (!hasResendInviteTemplate) {
|
|
4270
|
+
const userCreatedIndex = templatesObject.getProperties().findIndex((prop) => prop.getText().includes("[TriggerEvent.USER_CREATED]"));
|
|
4271
|
+
templatesObject.insertPropertyAssignment(
|
|
4272
|
+
userCreatedIndex >= 0 ? userCreatedIndex + 1 : templatesObject.getProperties().length,
|
|
4273
|
+
{
|
|
4274
|
+
name: "[TriggerEvent.RESEND_INVITE]",
|
|
4275
|
+
initializer: `{
|
|
4276
|
+
type: 'resend-invite',
|
|
4277
|
+
subject: 'Your OpenCRVS account invitation',
|
|
4278
|
+
template:
|
|
4279
|
+
readOtherTemplate<TriggerVariable['resend-invite']>('resend-invite')
|
|
4280
|
+
}`
|
|
4281
|
+
}
|
|
4282
|
+
);
|
|
4283
|
+
changed = true;
|
|
4284
|
+
}
|
|
4285
|
+
}
|
|
4286
|
+
if (changed) {
|
|
4287
|
+
sourceFile.saveSync();
|
|
4288
|
+
}
|
|
4289
|
+
return changed;
|
|
4290
|
+
}
|
|
4291
|
+
function patchNotificationHandler() {
|
|
4292
|
+
const full = import_path22.default.join(process.cwd(), NOTIFICATION_HANDLER);
|
|
4293
|
+
if (!(0, import_fs3.existsSync)(full)) {
|
|
4294
|
+
return false;
|
|
2938
4295
|
}
|
|
2939
|
-
const
|
|
2940
|
-
|
|
4296
|
+
const project = new import_ts_morph20.Project({ skipAddingFilesFromTsConfig: true });
|
|
4297
|
+
const sourceFile = project.addSourceFileAtPath(full);
|
|
4298
|
+
const convertFn = sourceFile.getFunction("convertPayloadToVariable");
|
|
4299
|
+
if (!convertFn) {
|
|
4300
|
+
return false;
|
|
4301
|
+
}
|
|
4302
|
+
const switchStmt = convertFn.getFirstDescendantByKind(
|
|
4303
|
+
import_ts_morph20.SyntaxKind.SwitchStatement
|
|
2941
4304
|
);
|
|
2942
|
-
if (
|
|
2943
|
-
|
|
2944
|
-
console.log(
|
|
2945
|
-
` [${relPath}] Removed empty 'actions' from workqueue '${workqueueLabel}'`
|
|
2946
|
-
);
|
|
2947
|
-
return 1;
|
|
4305
|
+
if (!switchStmt) {
|
|
4306
|
+
return false;
|
|
2948
4307
|
}
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
|
|
4308
|
+
const clauses = switchStmt.getCaseBlock().getClauses();
|
|
4309
|
+
const hasResendInvite = clauses.some(
|
|
4310
|
+
(clause) => import_ts_morph20.Node.isCaseClause(clause) && clause.getExpression().getText() === "TriggerEvent.RESEND_INVITE"
|
|
4311
|
+
);
|
|
4312
|
+
if (hasResendInvite) {
|
|
4313
|
+
return false;
|
|
2954
4314
|
}
|
|
2955
|
-
const
|
|
2956
|
-
|
|
4315
|
+
const userCreatedClauseIndex = clauses.findIndex(
|
|
4316
|
+
(clause) => import_ts_morph20.Node.isCaseClause(clause) && clause.getExpression().getText() === "TriggerEvent.USER_CREATED"
|
|
2957
4317
|
);
|
|
2958
|
-
if (
|
|
2959
|
-
|
|
2960
|
-
console.log(
|
|
2961
|
-
` [${relPath}] Removed deprecated 'conditionals' from migrated 'action' on workqueue '${workqueueLabel}'`
|
|
2962
|
-
);
|
|
4318
|
+
if (userCreatedClauseIndex < 0) {
|
|
4319
|
+
return false;
|
|
2963
4320
|
}
|
|
2964
|
-
|
|
2965
|
-
|
|
2966
|
-
|
|
2967
|
-
|
|
2968
|
-
|
|
2969
|
-
|
|
4321
|
+
const userCreatedClause = clauses[userCreatedClauseIndex];
|
|
4322
|
+
sourceFile.insertText(
|
|
4323
|
+
userCreatedClause.getEnd(),
|
|
4324
|
+
`
|
|
4325
|
+
|
|
4326
|
+
case TriggerEvent.RESEND_INVITE:
|
|
4327
|
+
return {
|
|
4328
|
+
firstname,
|
|
4329
|
+
username: payload.username,
|
|
4330
|
+
temporaryPassword: payload.temporaryPassword,
|
|
4331
|
+
completeSetupUrl: LOGIN_URL,
|
|
4332
|
+
loginURL: LOGIN_URL
|
|
4333
|
+
}`
|
|
4334
|
+
);
|
|
4335
|
+
sourceFile.saveSync();
|
|
4336
|
+
return true;
|
|
4337
|
+
}
|
|
4338
|
+
function getReturnedArrayLiteral(functionFilePath, fnName) {
|
|
4339
|
+
const project = new import_ts_morph20.Project({ skipAddingFilesFromTsConfig: true });
|
|
4340
|
+
const sourceFile = project.addSourceFileAtPath(functionFilePath);
|
|
4341
|
+
const fn = sourceFile.getFunction(fnName);
|
|
4342
|
+
const returnStmt = fn?.getFirstDescendantByKind(import_ts_morph20.SyntaxKind.ReturnStatement);
|
|
4343
|
+
const expr = returnStmt?.getExpression();
|
|
4344
|
+
if (!expr || !import_ts_morph20.Node.isArrayLiteralExpression(expr)) {
|
|
4345
|
+
return { sourceFile, arrayLiteral: void 0 };
|
|
4346
|
+
}
|
|
4347
|
+
return { sourceFile, arrayLiteral: expr };
|
|
4348
|
+
}
|
|
4349
|
+
function patchUserNotificationRoutes() {
|
|
4350
|
+
const full = import_path22.default.join(process.cwd(), USER_NOTIFICATION_ROUTES);
|
|
4351
|
+
if (!(0, import_fs3.existsSync)(full)) {
|
|
4352
|
+
return false;
|
|
2970
4353
|
}
|
|
2971
|
-
const
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
initializer: firstActionText
|
|
2975
|
-
});
|
|
2976
|
-
actionsProperty.remove();
|
|
2977
|
-
console.log(
|
|
2978
|
-
` [${relPath}] Replaced 'actions' with 'action' on workqueue '${workqueueLabel}'`
|
|
4354
|
+
const { sourceFile, arrayLiteral } = getReturnedArrayLiteral(
|
|
4355
|
+
full,
|
|
4356
|
+
"getUserNotificationRoutes"
|
|
2979
4357
|
);
|
|
2980
|
-
|
|
4358
|
+
if (!arrayLiteral) {
|
|
4359
|
+
return false;
|
|
4360
|
+
}
|
|
4361
|
+
const routeExists = arrayLiteral.getElements().some((element) => element.getText().includes(`path: '/triggers/user/resend-invite'`));
|
|
4362
|
+
if (routeExists) {
|
|
4363
|
+
return false;
|
|
4364
|
+
}
|
|
4365
|
+
const userCreatedIndex = arrayLiteral.getElements().findIndex((element) => element.getText().includes(`path: '/triggers/user/user-created'`));
|
|
4366
|
+
arrayLiteral.insertElement(
|
|
4367
|
+
userCreatedIndex >= 0 ? userCreatedIndex + 1 : arrayLiteral.getElements().length,
|
|
4368
|
+
`{
|
|
4369
|
+
method: 'POST',
|
|
4370
|
+
path: '/triggers/user/resend-invite',
|
|
4371
|
+
handler: makeNotificationHandler('resend-invite'),
|
|
4372
|
+
options: {
|
|
4373
|
+
auth: false,
|
|
4374
|
+
tags: ['api'],
|
|
4375
|
+
description: 'Handles notification for resent user invite'
|
|
4376
|
+
}
|
|
4377
|
+
}`
|
|
4378
|
+
);
|
|
4379
|
+
sourceFile.saveSync();
|
|
4380
|
+
return true;
|
|
2981
4381
|
}
|
|
2982
|
-
function
|
|
2983
|
-
const
|
|
2984
|
-
if (!
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
const
|
|
2988
|
-
|
|
4382
|
+
function patchSmsService() {
|
|
4383
|
+
const full = import_path22.default.join(process.cwd(), SMS_SERVICE);
|
|
4384
|
+
if (!(0, import_fs3.existsSync)(full)) {
|
|
4385
|
+
return false;
|
|
4386
|
+
}
|
|
4387
|
+
const project = new import_ts_morph20.Project({ skipAddingFilesFromTsConfig: true });
|
|
4388
|
+
const sourceFile = project.addSourceFileAtPath(full);
|
|
4389
|
+
let changed = false;
|
|
4390
|
+
const otherTemplatesObject = getObjectLiteralFromConst(
|
|
4391
|
+
sourceFile.getVariableDeclaration("otherTemplates")
|
|
2989
4392
|
);
|
|
2990
|
-
|
|
2991
|
-
const
|
|
2992
|
-
if (!
|
|
2993
|
-
|
|
4393
|
+
if (otherTemplatesObject) {
|
|
4394
|
+
const hasResendTemplate = otherTemplatesObject.getProperties().some((prop) => prop.getText().includes("resendInviteNotification"));
|
|
4395
|
+
if (!hasResendTemplate) {
|
|
4396
|
+
const userCredentialsIndex = otherTemplatesObject.getProperties().findIndex((prop) => prop.getText().includes("userCredentialsNotification"));
|
|
4397
|
+
otherTemplatesObject.insertPropertyAssignment(
|
|
4398
|
+
userCredentialsIndex >= 0 ? userCredentialsIndex + 1 : otherTemplatesObject.getProperties().length,
|
|
4399
|
+
{
|
|
4400
|
+
name: "resendInviteNotification",
|
|
4401
|
+
initializer: `'resendInviteNotification'`
|
|
4402
|
+
}
|
|
4403
|
+
);
|
|
4404
|
+
changed = true;
|
|
2994
4405
|
}
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
|
|
3000
|
-
|
|
3001
|
-
|
|
4406
|
+
}
|
|
4407
|
+
const triggerToSmsTemplateObject = getObjectLiteralFromConst(
|
|
4408
|
+
sourceFile.getVariableDeclaration("TriggerToSMSTemplate")
|
|
4409
|
+
);
|
|
4410
|
+
if (triggerToSmsTemplateObject) {
|
|
4411
|
+
const hasResendInviteMap = triggerToSmsTemplateObject.getProperties().some((prop) => prop.getText().includes(`['resend-invite']`));
|
|
4412
|
+
if (!hasResendInviteMap) {
|
|
4413
|
+
const userCreatedIndex = triggerToSmsTemplateObject.getProperties().findIndex((prop) => prop.getText().includes(`['user-created']`));
|
|
4414
|
+
triggerToSmsTemplateObject.insertPropertyAssignment(
|
|
4415
|
+
userCreatedIndex >= 0 ? userCreatedIndex + 1 : triggerToSmsTemplateObject.getProperties().length,
|
|
4416
|
+
{
|
|
4417
|
+
name: `['resend-invite']`,
|
|
4418
|
+
initializer: `'resendInviteNotification'`
|
|
4419
|
+
}
|
|
4420
|
+
);
|
|
4421
|
+
changed = true;
|
|
3002
4422
|
}
|
|
3003
4423
|
}
|
|
3004
|
-
|
|
4424
|
+
if (changed) {
|
|
4425
|
+
sourceFile.saveSync();
|
|
4426
|
+
}
|
|
4427
|
+
return changed;
|
|
3005
4428
|
}
|
|
3006
|
-
async function
|
|
3007
|
-
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
|
|
3011
|
-
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
let totalMigrated = 0;
|
|
3021
|
-
const modifiedFiles = [];
|
|
3022
|
-
for (const sourceFile of sourceFiles) {
|
|
3023
|
-
const filePath = sourceFile.getFilePath();
|
|
3024
|
-
const migrated = processFile11(filePath, project);
|
|
3025
|
-
if (migrated > 0) {
|
|
3026
|
-
totalMigrated += migrated;
|
|
3027
|
-
modifiedFiles.push(filePath);
|
|
4429
|
+
async function main23() {
|
|
4430
|
+
console.log("Adding RESEND_INVITE notification wiring\u2026");
|
|
4431
|
+
const touched = [];
|
|
4432
|
+
if (patchEmailTemplatesIndex()) touched.push(EMAIL_TEMPLATES_INDEX);
|
|
4433
|
+
if (patchNotificationHandler()) touched.push(NOTIFICATION_HANDLER);
|
|
4434
|
+
if (patchUserNotificationRoutes()) touched.push(USER_NOTIFICATION_ROUTES);
|
|
4435
|
+
if (patchSmsService()) touched.push(SMS_SERVICE);
|
|
4436
|
+
const csvPath = import_path22.default.join(process.cwd(), NOTIFICATION_CSV);
|
|
4437
|
+
if ((0, import_fs3.existsSync)(csvPath)) {
|
|
4438
|
+
let t = (0, import_fs3.readFileSync)(csvPath, "utf8");
|
|
4439
|
+
if (!/^resendInviteNotification,/m.test(t)) {
|
|
4440
|
+
if (!t.endsWith("\n")) t += "\n";
|
|
4441
|
+
(0, import_fs3.writeFileSync)(csvPath, t + CSV_ROW);
|
|
4442
|
+
touched.push(NOTIFICATION_CSV);
|
|
3028
4443
|
}
|
|
3029
4444
|
}
|
|
3030
|
-
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
|
-
);
|
|
3034
|
-
|
|
4445
|
+
const htmlPath = import_path22.default.join(process.cwd(), RESEND_INVITE_HTML);
|
|
4446
|
+
(0, import_fs3.mkdirSync)(import_path22.default.dirname(htmlPath), { recursive: true });
|
|
4447
|
+
if (!(0, import_fs3.existsSync)(htmlPath)) {
|
|
4448
|
+
(0, import_fs3.writeFileSync)(htmlPath, RESEND_INVITE_HTML_CONTENT);
|
|
4449
|
+
touched.push(RESEND_INVITE_HTML);
|
|
3035
4450
|
}
|
|
3036
|
-
|
|
3037
|
-
|
|
3038
|
-
|
|
3039
|
-
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
3040
|
-
await sourceFile.save();
|
|
3041
|
-
console.log(` Saved: ${import_path13.default.relative(getCwd(), filePath)}`);
|
|
4451
|
+
if (touched.length === 0) {
|
|
4452
|
+
console.log(" Nothing to update (already present or anchors not found).");
|
|
4453
|
+
return;
|
|
3042
4454
|
}
|
|
3043
|
-
console.log(
|
|
3044
|
-
`
|
|
3045
|
-
Done. Migrated ${totalMigrated} deprecated workqueue 'actions' definition(s) to 'action'.`
|
|
3046
|
-
);
|
|
4455
|
+
console.log(` Updated:
|
|
4456
|
+
${touched.map((f) => ` - ${f}`).join("\n")}`);
|
|
3047
4457
|
}
|
|
3048
4458
|
|
|
3049
|
-
// src/migrations/v2.0/
|
|
3050
|
-
var
|
|
3051
|
-
var
|
|
3052
|
-
var
|
|
3053
|
-
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
|
|
3057
|
-
|
|
3058
|
-
|
|
3059
|
-
const
|
|
3060
|
-
|
|
3061
|
-
|
|
3062
|
-
|
|
4459
|
+
// src/migrations/v2.0/simplify-analytics-precalculations.ts
|
|
4460
|
+
var import_ts_morph21 = require("ts-morph");
|
|
4461
|
+
var import_fs4 = __toESM(require("fs"));
|
|
4462
|
+
var import_path23 = __toESM(require("path"));
|
|
4463
|
+
var ANALYTICS_FILE_REL = "src/analytics/analytics.ts";
|
|
4464
|
+
var FUNCTION_NAME = "precalculateAdditionalAnalytics";
|
|
4465
|
+
var IMPORT_NAMES_TO_REMOVE = /* @__PURE__ */ new Set(["Event", "precalculateBirthEvent"]);
|
|
4466
|
+
var RETURN_EXPRESSION_TEXT = "declaration";
|
|
4467
|
+
function removeTargetedNamedImports(sourceFile) {
|
|
4468
|
+
const log = [];
|
|
4469
|
+
for (const importDecl of [...sourceFile.getImportDeclarations()]) {
|
|
4470
|
+
const namedImports = importDecl.getNamedImports();
|
|
4471
|
+
if (namedImports.length === 0) continue;
|
|
4472
|
+
const matched = namedImports.filter(
|
|
4473
|
+
(ni) => IMPORT_NAMES_TO_REMOVE.has(ni.getName())
|
|
3063
4474
|
);
|
|
3064
|
-
|
|
4475
|
+
if (matched.length === 0) continue;
|
|
4476
|
+
const removedNames = matched.map((ni) => ni.getName());
|
|
4477
|
+
for (const ni of matched) ni.remove();
|
|
4478
|
+
log.push(
|
|
4479
|
+
`removed import(s) ${removedNames.join(", ")} from '${importDecl.getModuleSpecifierValue()}'`
|
|
4480
|
+
);
|
|
4481
|
+
const stillUsed = importDecl.getNamedImports().length > 0 || importDecl.getDefaultImport() || importDecl.getNamespaceImport();
|
|
4482
|
+
if (!stillUsed) importDecl.remove();
|
|
3065
4483
|
}
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
)
|
|
3070
|
-
|
|
3071
|
-
constantsImport.remove();
|
|
3072
|
-
changed = true;
|
|
4484
|
+
return log;
|
|
4485
|
+
}
|
|
4486
|
+
function findPrecalculateFunction(sourceFile) {
|
|
4487
|
+
for (const fn of sourceFile.getFunctions()) {
|
|
4488
|
+
if (fn.getName() === FUNCTION_NAME) return fn;
|
|
3073
4489
|
}
|
|
3074
|
-
const
|
|
3075
|
-
|
|
4490
|
+
for (const statement of sourceFile.getVariableStatements()) {
|
|
4491
|
+
for (const decl of statement.getDeclarations()) {
|
|
4492
|
+
if (decl.getName() === FUNCTION_NAME) return decl;
|
|
4493
|
+
}
|
|
4494
|
+
}
|
|
4495
|
+
return void 0;
|
|
4496
|
+
}
|
|
4497
|
+
function getFunctionBodyBlock(fn) {
|
|
4498
|
+
if (import_ts_morph21.Node.isFunctionDeclaration(fn)) return fn.getBody();
|
|
4499
|
+
const initializer = fn.getInitializer();
|
|
4500
|
+
if (!initializer) return void 0;
|
|
4501
|
+
if (!import_ts_morph21.Node.isArrowFunction(initializer) && !import_ts_morph21.Node.isFunctionExpression(initializer)) {
|
|
4502
|
+
return void 0;
|
|
4503
|
+
}
|
|
4504
|
+
return initializer.getBody();
|
|
4505
|
+
}
|
|
4506
|
+
function simplifyPrecalculateFunction(sourceFile) {
|
|
4507
|
+
const log = [];
|
|
4508
|
+
const fn = findPrecalculateFunction(sourceFile);
|
|
4509
|
+
if (!fn) return log;
|
|
4510
|
+
const body = getFunctionBodyBlock(fn);
|
|
4511
|
+
if (!body || !import_ts_morph21.Node.isBlock(body)) return log;
|
|
4512
|
+
for (const statement of [...body.getStatements()]) {
|
|
4513
|
+
const references = statement.getDescendantsOfKind(import_ts_morph21.SyntaxKind.Identifier).some((id) => IMPORT_NAMES_TO_REMOVE.has(id.getText()));
|
|
4514
|
+
if (references) {
|
|
4515
|
+
statement.remove();
|
|
4516
|
+
log.push(`removed statement in ${FUNCTION_NAME} referencing removed imports`);
|
|
4517
|
+
}
|
|
4518
|
+
}
|
|
4519
|
+
const remaining = body.getStatements();
|
|
4520
|
+
const last = remaining[remaining.length - 1];
|
|
4521
|
+
const alreadyCorrect = last && import_ts_morph21.Node.isReturnStatement(last) && last.getExpression()?.getText() === RETURN_EXPRESSION_TEXT;
|
|
4522
|
+
if (!alreadyCorrect) {
|
|
4523
|
+
body.addStatements(`return ${RETURN_EXPRESSION_TEXT}`);
|
|
4524
|
+
log.push(
|
|
4525
|
+
`ensured '${FUNCTION_NAME}' ends with 'return ${RETURN_EXPRESSION_TEXT}'`
|
|
4526
|
+
);
|
|
4527
|
+
}
|
|
4528
|
+
return log;
|
|
4529
|
+
}
|
|
4530
|
+
async function main24() {
|
|
4531
|
+
const cwd = process.cwd();
|
|
4532
|
+
const absPath = import_path23.default.join(cwd, ANALYTICS_FILE_REL);
|
|
4533
|
+
if (!import_fs4.default.existsSync(absPath)) {
|
|
3076
4534
|
console.log(
|
|
3077
|
-
`
|
|
4535
|
+
`[${ANALYTICS_FILE_REL}] does not exist \u2014 nothing to clean up.`
|
|
3078
4536
|
);
|
|
3079
4537
|
return;
|
|
3080
4538
|
}
|
|
3081
|
-
const
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
const
|
|
3086
|
-
|
|
3087
|
-
if (normalizedCurrent !== normalizedDesired) {
|
|
3088
|
-
rolesHandler.setBodyText(`return ${responseToolkitIdentifier}.response(roles)`);
|
|
3089
|
-
changed = true;
|
|
3090
|
-
}
|
|
3091
|
-
if (!changed) {
|
|
4539
|
+
const project = new import_ts_morph21.Project({
|
|
4540
|
+
tsConfigFilePath: import_path23.default.resolve(cwd, "tsconfig.json"),
|
|
4541
|
+
skipAddingFilesFromTsConfig: false
|
|
4542
|
+
});
|
|
4543
|
+
const sourceFile = project.getSourceFile(absPath);
|
|
4544
|
+
if (!sourceFile) {
|
|
3092
4545
|
console.log(
|
|
3093
|
-
`
|
|
4546
|
+
`[${ANALYTICS_FILE_REL}] is not part of the tsconfig project. Skipping.`
|
|
3094
4547
|
);
|
|
3095
4548
|
return;
|
|
3096
4549
|
}
|
|
4550
|
+
console.log(`Cleaning up ${ANALYTICS_FILE_REL}...
|
|
4551
|
+
`);
|
|
4552
|
+
const importLogs = removeTargetedNamedImports(sourceFile);
|
|
4553
|
+
const fnLogs = simplifyPrecalculateFunction(sourceFile);
|
|
4554
|
+
const allLogs = [...importLogs, ...fnLogs];
|
|
4555
|
+
if (allLogs.length === 0) {
|
|
4556
|
+
console.log(`[${ANALYTICS_FILE_REL}] already clean \u2014 nothing to do.`);
|
|
4557
|
+
return;
|
|
4558
|
+
}
|
|
4559
|
+
for (const log of allLogs) {
|
|
4560
|
+
console.log(` [${ANALYTICS_FILE_REL}] ${log}`);
|
|
4561
|
+
}
|
|
3097
4562
|
await sourceFile.save();
|
|
3098
|
-
console.log(
|
|
3099
|
-
|
|
3100
|
-
);
|
|
4563
|
+
console.log(`
|
|
4564
|
+
Saved ${ANALYTICS_FILE_REL}.`);
|
|
3101
4565
|
}
|
|
3102
4566
|
|
|
3103
|
-
// src/migrations/v2.0/
|
|
3104
|
-
var
|
|
3105
|
-
var
|
|
3106
|
-
var
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
if (fs2.existsSync(absolutePath)) {
|
|
3121
|
-
fs2.rmSync(absolutePath, { recursive: true, force: true });
|
|
3122
|
-
console.log(`Removed ${label} '${relativePath}'.`);
|
|
3123
|
-
} else {
|
|
3124
|
-
console.log(`No ${label} found at '${relativePath}'.`);
|
|
3125
|
-
}
|
|
4567
|
+
// src/migrations/v2.0/merge-infrastructure-directory.ts
|
|
4568
|
+
var import_child_process2 = require("child_process");
|
|
4569
|
+
var import_fs5 = require("fs");
|
|
4570
|
+
var import_os = require("os");
|
|
4571
|
+
var import_path24 = require("path");
|
|
4572
|
+
var TEMP_REMOTE2 = "opencrvs-upgrade-v19-v20-codemod-merge-infra";
|
|
4573
|
+
var INFRASTRUCTURE_DIR = "infrastructure";
|
|
4574
|
+
var BASE_BRANCH = "release-v1.9";
|
|
4575
|
+
function gitShowBytes(ref, path23) {
|
|
4576
|
+
try {
|
|
4577
|
+
const buf = (0, import_child_process2.execFileSync)("git", ["show", `${ref}:${path23}`], {
|
|
4578
|
+
cwd: process.cwd(),
|
|
4579
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
4580
|
+
});
|
|
4581
|
+
return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
4582
|
+
} catch {
|
|
4583
|
+
return null;
|
|
3126
4584
|
}
|
|
3127
4585
|
}
|
|
3128
|
-
|
|
3129
|
-
|
|
3130
|
-
|
|
3131
|
-
|
|
3132
|
-
|
|
3133
|
-
|
|
4586
|
+
async function main25() {
|
|
4587
|
+
console.log(
|
|
4588
|
+
`Merging '${INFRASTRUCTURE_DIR}/' from ${UPSTREAM_URL}@${UPSTREAM_BRANCH} (base: ${BASE_BRANCH})...
|
|
4589
|
+
`
|
|
4590
|
+
);
|
|
4591
|
+
assertIsGitRepo();
|
|
4592
|
+
tryGit(["remote", "remove", TEMP_REMOTE2]);
|
|
4593
|
+
try {
|
|
4594
|
+
console.log(` Adding temporary remote '${TEMP_REMOTE2}' \u2192 ${UPSTREAM_URL}`);
|
|
4595
|
+
runGit(["remote", "add", TEMP_REMOTE2, UPSTREAM_URL], { silent: true });
|
|
4596
|
+
console.log(
|
|
4597
|
+
` Fetching ${TEMP_REMOTE2}/{${UPSTREAM_BRANCH},${BASE_BRANCH}} (depth 1)...`
|
|
4598
|
+
);
|
|
4599
|
+
runGit(["fetch", "--depth=1", TEMP_REMOTE2, UPSTREAM_BRANCH, BASE_BRANCH]);
|
|
4600
|
+
const ref = `${TEMP_REMOTE2}/${UPSTREAM_BRANCH}`;
|
|
4601
|
+
const baseRef = `${TEMP_REMOTE2}/${BASE_BRANCH}`;
|
|
4602
|
+
const upstreamFiles = runGit(
|
|
4603
|
+
[
|
|
4604
|
+
"ls-tree",
|
|
4605
|
+
"-r",
|
|
4606
|
+
"--name-only",
|
|
4607
|
+
"-z",
|
|
4608
|
+
ref,
|
|
4609
|
+
"--",
|
|
4610
|
+
`${INFRASTRUCTURE_DIR}/`
|
|
4611
|
+
],
|
|
4612
|
+
{ silent: true }
|
|
4613
|
+
).split("\0").filter(Boolean);
|
|
4614
|
+
if (upstreamFiles.length === 0) {
|
|
4615
|
+
console.log(
|
|
4616
|
+
` No files found under '${INFRASTRUCTURE_DIR}/' on ${ref}. Nothing to merge.`
|
|
4617
|
+
);
|
|
4618
|
+
return;
|
|
4619
|
+
}
|
|
4620
|
+
const tmpDir = (0, import_fs5.mkdtempSync)((0, import_path24.join)((0, import_os.tmpdir)(), "opencrvs-merge-infra-"));
|
|
4621
|
+
const baseTmp = (0, import_path24.join)(tmpDir, "base");
|
|
4622
|
+
const theirsTmp = (0, import_path24.join)(tmpDir, "theirs");
|
|
4623
|
+
let added = 0;
|
|
4624
|
+
let merged = 0;
|
|
4625
|
+
const conflictedFiles = [];
|
|
4626
|
+
for (const file of upstreamFiles) {
|
|
4627
|
+
const fullPath = (0, import_path24.join)(process.cwd(), file);
|
|
4628
|
+
if (!(0, import_fs5.existsSync)(fullPath)) {
|
|
4629
|
+
if (tryGit(["checkout", ref, "--", file])) {
|
|
4630
|
+
console.log(` + ${file} (new from upstream)`);
|
|
4631
|
+
added++;
|
|
4632
|
+
} else {
|
|
4633
|
+
console.warn(` [warn] failed to add new file ${file}`);
|
|
4634
|
+
}
|
|
4635
|
+
continue;
|
|
4636
|
+
}
|
|
4637
|
+
const theirContents = gitShowBytes(ref, file);
|
|
4638
|
+
if (theirContents === null) {
|
|
4639
|
+
console.warn(` [warn] could not read ${file} from ${ref} \u2014 skipping.`);
|
|
4640
|
+
continue;
|
|
4641
|
+
}
|
|
4642
|
+
(0, import_fs5.writeFileSync)(theirsTmp, theirContents);
|
|
4643
|
+
const baseContents = gitShowBytes(baseRef, file);
|
|
4644
|
+
(0, import_fs5.writeFileSync)(baseTmp, baseContents ?? new Uint8Array(0));
|
|
4645
|
+
try {
|
|
4646
|
+
(0, import_child_process2.execFileSync)("git", ["merge-file", fullPath, baseTmp, theirsTmp], {
|
|
4647
|
+
cwd: process.cwd(),
|
|
4648
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
4649
|
+
});
|
|
4650
|
+
runGit(["add", "--", file], { silent: true });
|
|
4651
|
+
merged++;
|
|
4652
|
+
} catch (err) {
|
|
4653
|
+
const status = err.status;
|
|
4654
|
+
if (typeof status === "number" && status > 0) {
|
|
4655
|
+
conflictedFiles.push(file);
|
|
4656
|
+
console.warn(
|
|
4657
|
+
` ! ${file} (${status} conflict${status > 1 ? "s" : ""})`
|
|
4658
|
+
);
|
|
4659
|
+
} else {
|
|
4660
|
+
conflictedFiles.push(file);
|
|
4661
|
+
console.warn(
|
|
4662
|
+
` [warn] merge failed for ${file} (likely binary or unreadable) \u2014 left untouched.`
|
|
4663
|
+
);
|
|
4664
|
+
}
|
|
4665
|
+
}
|
|
4666
|
+
}
|
|
4667
|
+
console.log(
|
|
4668
|
+
`
|
|
4669
|
+
Done. ${added} added, ${merged} merged cleanly, ${conflictedFiles.length} with conflicts.`
|
|
4670
|
+
);
|
|
4671
|
+
if (conflictedFiles.length > 0) {
|
|
4672
|
+
console.warn(
|
|
4673
|
+
`
|
|
4674
|
+
NOTE: ${conflictedFiles.length} file(s) under '${INFRASTRUCTURE_DIR}/' have merge conflicts that you must resolve manually.
|
|
4675
|
+
Look for the standard conflict markers (<<<<<<<, =======, >>>>>>>) in:
|
|
4676
|
+
` + conflictedFiles.map((f) => ` - ${f}`).join("\n") + `
|
|
4677
|
+
After resolving, stage the fixes with: git add ${INFRASTRUCTURE_DIR}/`
|
|
4678
|
+
);
|
|
4679
|
+
}
|
|
4680
|
+
} finally {
|
|
4681
|
+
if (tryGit(["remote", "remove", TEMP_REMOTE2])) {
|
|
4682
|
+
console.log(` Removed temporary remote '${TEMP_REMOTE2}'.`);
|
|
4683
|
+
}
|
|
3134
4684
|
}
|
|
3135
|
-
return cwd;
|
|
3136
4685
|
}
|
|
3137
|
-
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
|
|
4686
|
+
|
|
4687
|
+
// src/migrations/v2.0/delete-infrastructure-directory.ts
|
|
4688
|
+
var import_fs6 = require("fs");
|
|
4689
|
+
var import_path25 = require("path");
|
|
4690
|
+
var INFRASTRUCTURE_DIR2 = "infrastructure";
|
|
4691
|
+
async function main26() {
|
|
4692
|
+
const fullPath = (0, import_path25.join)(process.cwd(), INFRASTRUCTURE_DIR2);
|
|
4693
|
+
if (!(0, import_fs6.existsSync)(fullPath)) {
|
|
3143
4694
|
console.log(
|
|
3144
|
-
|
|
4695
|
+
`'${INFRASTRUCTURE_DIR2}/' not found in ${process.cwd()} \u2014 nothing to delete.`
|
|
3145
4696
|
);
|
|
3146
|
-
|
|
4697
|
+
return;
|
|
3147
4698
|
}
|
|
3148
|
-
|
|
4699
|
+
console.log(`Deleting '${INFRASTRUCTURE_DIR2}/'...
|
|
4700
|
+
`);
|
|
4701
|
+
assertIsGitRepo();
|
|
4702
|
+
runGit(["rm", "-rf", "--ignore-unmatch", "--", `${INFRASTRUCTURE_DIR2}/`], {
|
|
4703
|
+
silent: true
|
|
4704
|
+
});
|
|
4705
|
+
console.log(` Staged deletion of tracked files under '${INFRASTRUCTURE_DIR2}/'.`);
|
|
4706
|
+
if ((0, import_fs6.existsSync)(fullPath)) {
|
|
4707
|
+
(0, import_fs6.rmSync)(fullPath, { recursive: true, force: true });
|
|
4708
|
+
console.log(` Removed remaining untracked files under '${INFRASTRUCTURE_DIR2}/'.`);
|
|
4709
|
+
}
|
|
4710
|
+
console.log(
|
|
4711
|
+
`
|
|
4712
|
+
Done. Review the staged deletion with: git diff --cached -- '${INFRASTRUCTURE_DIR2}/'`
|
|
4713
|
+
);
|
|
4714
|
+
}
|
|
4715
|
+
|
|
4716
|
+
// src/migrations/v2.0/index.ts
|
|
4717
|
+
async function runUpgrade(dockerSwarm) {
|
|
4718
|
+
await main18();
|
|
3149
4719
|
await main();
|
|
3150
4720
|
await main2();
|
|
3151
4721
|
await main3();
|
|
@@ -3158,8 +4728,22 @@ async function runUpgrade(ccwd) {
|
|
|
3158
4728
|
await main10();
|
|
3159
4729
|
await main11();
|
|
3160
4730
|
await main12();
|
|
4731
|
+
await main13();
|
|
3161
4732
|
await main14();
|
|
3162
4733
|
await main15();
|
|
4734
|
+
await main16();
|
|
4735
|
+
await main19();
|
|
4736
|
+
await main20();
|
|
4737
|
+
await main21();
|
|
4738
|
+
await main22();
|
|
4739
|
+
await main23();
|
|
4740
|
+
await main24();
|
|
4741
|
+
await main17();
|
|
4742
|
+
if (dockerSwarm) {
|
|
4743
|
+
await main25();
|
|
4744
|
+
} else {
|
|
4745
|
+
await main26();
|
|
4746
|
+
}
|
|
3163
4747
|
}
|
|
3164
4748
|
|
|
3165
4749
|
// src/cli.ts
|
|
@@ -3174,7 +4758,20 @@ Commands:
|
|
|
3174
4758
|
|
|
3175
4759
|
Run 'opencrvs <command> --help' for more information on a command.
|
|
3176
4760
|
`.trim();
|
|
3177
|
-
|
|
4761
|
+
var UPGRADE_USAGE = `
|
|
4762
|
+
Usage: opencrvs upgrade [options]
|
|
4763
|
+
|
|
4764
|
+
Upgrade the country config in the current working directory to the next
|
|
4765
|
+
major version of OpenCRVS.
|
|
4766
|
+
|
|
4767
|
+
Options:
|
|
4768
|
+
--docker-swarm Keep and merge the 'infrastructure/' directory with
|
|
4769
|
+
upstream changes. Use this if your country deploys
|
|
4770
|
+
OpenCRVS via Docker Swarm. When omitted, the
|
|
4771
|
+
'infrastructure/' directory is deleted (default).
|
|
4772
|
+
-h, --help Show this message.
|
|
4773
|
+
`.trim();
|
|
4774
|
+
function main27() {
|
|
3178
4775
|
const command = args[0];
|
|
3179
4776
|
if (!command || command === "--help" || command === "-h") {
|
|
3180
4777
|
console.log(USAGE);
|
|
@@ -3219,10 +4816,25 @@ Subcommands:
|
|
|
3219
4816
|
}
|
|
3220
4817
|
}
|
|
3221
4818
|
async function handleUpgrade() {
|
|
4819
|
+
const upgradeArgs = args.slice(1);
|
|
4820
|
+
if (upgradeArgs.includes("--help") || upgradeArgs.includes("-h")) {
|
|
4821
|
+
console.log(UPGRADE_USAGE);
|
|
4822
|
+
process.exit(0);
|
|
4823
|
+
}
|
|
4824
|
+
const KNOWN_FLAGS = /* @__PURE__ */ new Set(["--docker-swarm"]);
|
|
4825
|
+
const unknownFlags = upgradeArgs.filter(
|
|
4826
|
+
(arg) => arg.startsWith("-") && !KNOWN_FLAGS.has(arg)
|
|
4827
|
+
);
|
|
4828
|
+
if (unknownFlags.length > 0) {
|
|
4829
|
+
console.error(`Unknown option(s): ${unknownFlags.join(", ")}
|
|
4830
|
+
`);
|
|
4831
|
+
console.log(UPGRADE_USAGE);
|
|
4832
|
+
process.exit(1);
|
|
4833
|
+
}
|
|
4834
|
+
const dockerSwarm = upgradeArgs.includes("--docker-swarm");
|
|
3222
4835
|
console.log("Initiating upgrade...");
|
|
3223
4836
|
try {
|
|
3224
|
-
|
|
3225
|
-
await runUpgrade(pathToCountryconfig);
|
|
4837
|
+
await runUpgrade(dockerSwarm);
|
|
3226
4838
|
console.log("Upgrade completed successfully!");
|
|
3227
4839
|
} catch (error) {
|
|
3228
4840
|
console.error("Upgrade failed:", error);
|
|
@@ -3234,4 +4846,4 @@ function handleCheckTranslations() {
|
|
|
3234
4846
|
console.warn("This command is not implemented yet!");
|
|
3235
4847
|
process.exit(1);
|
|
3236
4848
|
}
|
|
3237
|
-
|
|
4849
|
+
main27();
|