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