@opencrvs/toolkit 2.0.0-rc.d7cb6e7 → 2.0.0-rc.da37d4e
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 +5 -3
- package/dist/cli.js +1388 -145
- package/dist/commons/api/router.d.ts +58 -72
- package/dist/commons/conditionals/conditionals.d.ts +3 -3
- package/dist/commons/events/FieldConfig.d.ts +5 -0
- package/dist/conditionals/index.js +5 -3
- package/dist/events/index.js +5 -3
- package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts.map +1 -1
- package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.js +3 -4
- package/dist/migrations/v2.0/add-resend-invite-notification.d.ts +3 -0
- package/dist/migrations/v2.0/add-resend-invite-notification.d.ts.map +1 -0
- package/dist/migrations/v2.0/add-resend-invite-notification.js +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 +1356 -142
- 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 +5 -3
- package/dist/scopes/index.d.ts +6 -1
- package/dist/scopes/index.js +5 -3
- package/opencrvs-toolkit-2.0.0-rc.da37d4e.tgz +0 -0
- package/package.json +1 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/opencrvs-toolkit-2.0.0-rc.d7cb6e7.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()) {
|
|
@@ -2239,12 +2238,14 @@ var SystemScopeType = z3.enum([
|
|
|
2239
2238
|
"organisation.read-locations",
|
|
2240
2239
|
"user.read",
|
|
2241
2240
|
"user.create",
|
|
2242
|
-
"user.edit"
|
|
2241
|
+
"user.edit",
|
|
2242
|
+
"user.search"
|
|
2243
2243
|
]);
|
|
2244
2244
|
var UserScopeType = SystemScopeType.extract([
|
|
2245
2245
|
"user.read",
|
|
2246
2246
|
"user.create",
|
|
2247
|
-
"user.edit"
|
|
2247
|
+
"user.edit",
|
|
2248
|
+
"user.search"
|
|
2248
2249
|
]);
|
|
2249
2250
|
var ScopesWithRoleOption = UserScopeType.extract(["user.edit", "user.create"]);
|
|
2250
2251
|
var UserScopeV2 = z3.discriminatedUnion("type", [
|
|
@@ -2253,7 +2254,7 @@ var UserScopeV2 = z3.discriminatedUnion("type", [
|
|
|
2253
2254
|
options: AllUserScopeOptions.optional()
|
|
2254
2255
|
}),
|
|
2255
2256
|
z3.object({
|
|
2256
|
-
type: UserScopeType.extract(["user.read"]),
|
|
2257
|
+
type: UserScopeType.extract(["user.read", "user.search"]),
|
|
2257
2258
|
options: AccessLevelOptions.optional()
|
|
2258
2259
|
})
|
|
2259
2260
|
]);
|
|
@@ -2619,7 +2620,7 @@ function migrateScopesArrays(rolesFilePath, project) {
|
|
|
2619
2620
|
const scopeKey = resolveScopeKeyFromElementAccess(element);
|
|
2620
2621
|
if (scopeKey && !(scopeKey in SCOPES)) {
|
|
2621
2622
|
console.warn(
|
|
2622
|
-
` [${import_path11.default.relative(
|
|
2623
|
+
` [${import_path11.default.relative(process.cwd(), rolesFilePath)}] Removing unknown scope reference: SCOPES.${scopeKey}`
|
|
2623
2624
|
);
|
|
2624
2625
|
initializer.removeElement(index);
|
|
2625
2626
|
removedCount++;
|
|
@@ -2628,7 +2629,7 @@ function migrateScopesArrays(rolesFilePath, project) {
|
|
|
2628
2629
|
const legacyScope = resolveLegacyScopeFromElement(element);
|
|
2629
2630
|
if (!legacyScope) {
|
|
2630
2631
|
console.warn(
|
|
2631
|
-
` [${import_path11.default.relative(
|
|
2632
|
+
` [${import_path11.default.relative(process.cwd(), rolesFilePath)}] Skipping non-literal scope expression: ${element.getText()}`
|
|
2632
2633
|
);
|
|
2633
2634
|
continue;
|
|
2634
2635
|
}
|
|
@@ -2637,7 +2638,7 @@ function migrateScopesArrays(rolesFilePath, project) {
|
|
|
2637
2638
|
const scope = decodeScope(migratedScope);
|
|
2638
2639
|
if (!scope) {
|
|
2639
2640
|
console.warn(
|
|
2640
|
-
` [${import_path11.default.relative(
|
|
2641
|
+
` [${import_path11.default.relative(process.cwd(), rolesFilePath)}] Could not decode migrated scope '${migratedScope}'.`
|
|
2641
2642
|
);
|
|
2642
2643
|
continue;
|
|
2643
2644
|
}
|
|
@@ -2645,14 +2646,14 @@ function migrateScopesArrays(rolesFilePath, project) {
|
|
|
2645
2646
|
migratedCount++;
|
|
2646
2647
|
} catch (error) {
|
|
2647
2648
|
console.warn(
|
|
2648
|
-
` [${import_path11.default.relative(
|
|
2649
|
+
` [${import_path11.default.relative(process.cwd(), rolesFilePath)}] Could not migrate scope '${legacyScope}': ${error}`
|
|
2649
2650
|
);
|
|
2650
2651
|
}
|
|
2651
2652
|
}
|
|
2652
2653
|
}
|
|
2653
2654
|
if (removedCount > 0) {
|
|
2654
2655
|
console.log(
|
|
2655
|
-
` Removed ${removedCount} unknown SCOPES reference(s) from '${import_path11.default.relative(
|
|
2656
|
+
` Removed ${removedCount} unknown SCOPES reference(s) from '${import_path11.default.relative(process.cwd(), rolesFilePath)}'.`
|
|
2656
2657
|
);
|
|
2657
2658
|
}
|
|
2658
2659
|
return { migratedCount, removedCount };
|
|
@@ -2774,9 +2775,9 @@ function removeRoleTypeDefinitionAndUnusedImports(rolesFilePath, project) {
|
|
|
2774
2775
|
return removed;
|
|
2775
2776
|
}
|
|
2776
2777
|
async function main11() {
|
|
2777
|
-
const
|
|
2778
|
-
const srcDir = import_path11.default.join(
|
|
2779
|
-
const rolesFilePath = import_path11.default.join(
|
|
2778
|
+
const cwd = process.cwd();
|
|
2779
|
+
const srcDir = import_path11.default.join(cwd, "src");
|
|
2780
|
+
const rolesFilePath = import_path11.default.join(cwd, ROLES_FILE_RELATIVE_PATH);
|
|
2780
2781
|
console.log(`Scanning roles scopes in: ${rolesFilePath}`);
|
|
2781
2782
|
const project = new import_ts_morph11.Project({
|
|
2782
2783
|
tsConfigFilePath: import_path11.default.resolve(srcDir, "../tsconfig.json"),
|
|
@@ -2840,13 +2841,13 @@ function processFile10(filePath, project) {
|
|
|
2840
2841
|
decl.remove();
|
|
2841
2842
|
}
|
|
2842
2843
|
console.log(
|
|
2843
|
-
` [${import_path12.default.relative(
|
|
2844
|
+
` [${import_path12.default.relative(process.cwd(), filePath)}] Removed ${matchingNamedImports.length} deprecated '${DEPRECATED_IMPORT}' import(s) from '${decl.getModuleSpecifierValue()}'`
|
|
2844
2845
|
);
|
|
2845
2846
|
}
|
|
2846
2847
|
return removedCount;
|
|
2847
2848
|
}
|
|
2848
2849
|
async function main12() {
|
|
2849
|
-
const srcDir = import_path12.default.join(
|
|
2850
|
+
const srcDir = import_path12.default.join(process.cwd(), "src");
|
|
2850
2851
|
console.log(`Scanning for deprecated imports in: ${srcDir}
|
|
2851
2852
|
`);
|
|
2852
2853
|
const project = new import_ts_morph12.Project({
|
|
@@ -2877,15 +2878,738 @@ async function main12() {
|
|
|
2877
2878
|
Saving ${modifiedFiles.length} modified file(s)...`);
|
|
2878
2879
|
for (const filePath of modifiedFiles) {
|
|
2879
2880
|
await project.getSourceFileOrThrow(filePath).save();
|
|
2880
|
-
console.log(` Saved: ${import_path12.default.relative(
|
|
2881
|
+
console.log(` Saved: ${import_path12.default.relative(process.cwd(), filePath)}`);
|
|
2881
2882
|
}
|
|
2882
2883
|
console.log(`
|
|
2883
2884
|
Done. Removed ${totalRemoved} deprecated import(s).`);
|
|
2884
2885
|
}
|
|
2885
2886
|
|
|
2886
|
-
// src/migrations/v2.0/
|
|
2887
|
-
var import_ts_morph13 = require("ts-morph");
|
|
2887
|
+
// src/migrations/v2.0/remove-unused-environment-variables.ts
|
|
2888
2888
|
var import_path13 = __toESM(require("path"));
|
|
2889
|
+
var import_ts_morph13 = require("ts-morph");
|
|
2890
|
+
var UNUSED_ENV_VARS = /* @__PURE__ */ new Set([
|
|
2891
|
+
"APPLICATION_CONFIG_URL",
|
|
2892
|
+
"FHIR_URL",
|
|
2893
|
+
"CONFIRM_REGISTRATION_URL"
|
|
2894
|
+
]);
|
|
2895
|
+
var ENVIRONMENT_FILE_RELATIVE = "src/environment.ts";
|
|
2896
|
+
var CONSTANTS_FILE_RELATIVE = "src/constants.ts";
|
|
2897
|
+
function cleanEnvironmentFile(project, filePath) {
|
|
2898
|
+
const sourceFile = project.getSourceFile(filePath);
|
|
2899
|
+
if (!sourceFile) return [];
|
|
2900
|
+
const removed = [];
|
|
2901
|
+
const cleanEnvCall = sourceFile.getDescendantsOfKind(import_ts_morph13.SyntaxKind.CallExpression).find((call) => {
|
|
2902
|
+
const expr = call.getExpression();
|
|
2903
|
+
return import_ts_morph13.Node.isIdentifier(expr) && expr.getText() === "cleanEnv";
|
|
2904
|
+
});
|
|
2905
|
+
if (!cleanEnvCall) return removed;
|
|
2906
|
+
const schemaArg = cleanEnvCall.getArguments()[1]?.asKind(import_ts_morph13.SyntaxKind.ObjectLiteralExpression);
|
|
2907
|
+
if (!schemaArg) return removed;
|
|
2908
|
+
for (const name of UNUSED_ENV_VARS) {
|
|
2909
|
+
const prop = schemaArg.getProperty(name);
|
|
2910
|
+
if (!prop) continue;
|
|
2911
|
+
if (prop.isKind(import_ts_morph13.SyntaxKind.PropertyAssignment) || prop.isKind(import_ts_morph13.SyntaxKind.ShorthandPropertyAssignment)) {
|
|
2912
|
+
prop.remove();
|
|
2913
|
+
removed.push(name);
|
|
2914
|
+
}
|
|
2915
|
+
}
|
|
2916
|
+
return removed;
|
|
2917
|
+
}
|
|
2918
|
+
function extractEnvAccess(initText) {
|
|
2919
|
+
if (!initText) return null;
|
|
2920
|
+
const match = /\benv\.([A-Z][A-Z0-9_]*)\b/.exec(initText);
|
|
2921
|
+
return match ? match[1] : null;
|
|
2922
|
+
}
|
|
2923
|
+
function cleanConstantsFile(project, filePath) {
|
|
2924
|
+
const sourceFile = project.getSourceFile(filePath);
|
|
2925
|
+
if (!sourceFile) return [];
|
|
2926
|
+
const removed = [];
|
|
2927
|
+
for (const stmt of [...sourceFile.getVariableStatements()]) {
|
|
2928
|
+
const declarations = [...stmt.getDeclarations()];
|
|
2929
|
+
const declarationsToRemove = declarations.filter((decl) => {
|
|
2930
|
+
const name = decl.getName();
|
|
2931
|
+
const accessedEnvVar = extractEnvAccess(decl.getInitializer()?.getText());
|
|
2932
|
+
return UNUSED_ENV_VARS.has(name) || accessedEnvVar !== null && UNUSED_ENV_VARS.has(accessedEnvVar);
|
|
2933
|
+
});
|
|
2934
|
+
if (declarationsToRemove.length === 0) continue;
|
|
2935
|
+
const namesToRemove = declarationsToRemove.map((decl) => decl.getName());
|
|
2936
|
+
removed.push(...namesToRemove);
|
|
2937
|
+
if (declarationsToRemove.length === declarations.length) {
|
|
2938
|
+
stmt.remove();
|
|
2939
|
+
} else {
|
|
2940
|
+
for (const decl of declarationsToRemove) {
|
|
2941
|
+
decl.remove();
|
|
2942
|
+
}
|
|
2943
|
+
}
|
|
2944
|
+
}
|
|
2945
|
+
return removed;
|
|
2946
|
+
}
|
|
2947
|
+
async function main13() {
|
|
2948
|
+
const project = new import_ts_morph13.Project({
|
|
2949
|
+
tsConfigFilePath: import_path13.default.resolve(process.cwd(), "tsconfig.json"),
|
|
2950
|
+
skipAddingFilesFromTsConfig: false
|
|
2951
|
+
});
|
|
2952
|
+
console.log(
|
|
2953
|
+
`Removing unused environment variable(s) (${[...UNUSED_ENV_VARS].join(", ")})...
|
|
2954
|
+
`
|
|
2955
|
+
);
|
|
2956
|
+
const envFilePath = import_path13.default.join(process.cwd(), ENVIRONMENT_FILE_RELATIVE);
|
|
2957
|
+
const constsFilePath = import_path13.default.join(process.cwd(), CONSTANTS_FILE_RELATIVE);
|
|
2958
|
+
const envRemoved = cleanEnvironmentFile(project, envFilePath);
|
|
2959
|
+
if (envRemoved.length > 0) {
|
|
2960
|
+
await project.getSourceFileOrThrow(envFilePath).save();
|
|
2961
|
+
console.log(
|
|
2962
|
+
` [${ENVIRONMENT_FILE_RELATIVE}] Removed schema entr${envRemoved.length === 1 ? "y" : "ies"}: ${envRemoved.join(", ")}`
|
|
2963
|
+
);
|
|
2964
|
+
} else if (project.getSourceFile(envFilePath)) {
|
|
2965
|
+
console.log(
|
|
2966
|
+
` [${ENVIRONMENT_FILE_RELATIVE}] No matching schema entries \u2014 nothing to remove.`
|
|
2967
|
+
);
|
|
2968
|
+
} else {
|
|
2969
|
+
console.log(
|
|
2970
|
+
` [${ENVIRONMENT_FILE_RELATIVE}] File not found \u2014 skipping.`
|
|
2971
|
+
);
|
|
2972
|
+
}
|
|
2973
|
+
const constsRemoved = cleanConstantsFile(project, constsFilePath);
|
|
2974
|
+
if (constsRemoved.length > 0) {
|
|
2975
|
+
await project.getSourceFileOrThrow(constsFilePath).save();
|
|
2976
|
+
console.log(
|
|
2977
|
+
` [${CONSTANTS_FILE_RELATIVE}] Removed declaration(s): ${constsRemoved.join(", ")}`
|
|
2978
|
+
);
|
|
2979
|
+
} else if (project.getSourceFile(constsFilePath)) {
|
|
2980
|
+
console.log(
|
|
2981
|
+
` [${CONSTANTS_FILE_RELATIVE}] No matching declarations \u2014 nothing to remove.`
|
|
2982
|
+
);
|
|
2983
|
+
} else {
|
|
2984
|
+
console.log(` [${CONSTANTS_FILE_RELATIVE}] File not found \u2014 skipping.`);
|
|
2985
|
+
}
|
|
2986
|
+
if (envRemoved.length === 0 && constsRemoved.length === 0) {
|
|
2987
|
+
console.log("\nNothing to do.");
|
|
2988
|
+
return;
|
|
2989
|
+
}
|
|
2990
|
+
console.log(
|
|
2991
|
+
`
|
|
2992
|
+
Done. NOTE: usages of these constants elsewhere in 'src/' may now produce TypeScript errors and need manual review.`
|
|
2993
|
+
);
|
|
2994
|
+
}
|
|
2995
|
+
|
|
2996
|
+
// src/migrations/v2.0/remove-fhir-url-helpers.ts
|
|
2997
|
+
var import_path14 = __toESM(require("path"));
|
|
2998
|
+
var import_ts_morph14 = require("ts-morph");
|
|
2999
|
+
var FHIR_IMPORT = "FHIR_URL";
|
|
3000
|
+
var HELPER_NAMES = /* @__PURE__ */ new Set([
|
|
3001
|
+
"getFromFhir",
|
|
3002
|
+
"updateResourceFromHearth",
|
|
3003
|
+
"updateResourceInHearth"
|
|
3004
|
+
]);
|
|
3005
|
+
function removeHelpers(sourceFilePath, project) {
|
|
3006
|
+
const sourceFile = project.getSourceFile(sourceFilePath);
|
|
3007
|
+
if (!sourceFile) {
|
|
3008
|
+
return {
|
|
3009
|
+
removedHelpers: [],
|
|
3010
|
+
removedImportCount: 0,
|
|
3011
|
+
remainingFhirReferences: 0
|
|
3012
|
+
};
|
|
3013
|
+
}
|
|
3014
|
+
const removedHelpers = [];
|
|
3015
|
+
let removedImportCount = 0;
|
|
3016
|
+
for (const fn of sourceFile.getFunctions()) {
|
|
3017
|
+
const name = fn.getName();
|
|
3018
|
+
if (!name || !HELPER_NAMES.has(name)) continue;
|
|
3019
|
+
removedHelpers.push(name);
|
|
3020
|
+
fn.remove();
|
|
3021
|
+
}
|
|
3022
|
+
for (const stmt of [...sourceFile.getVariableStatements()]) {
|
|
3023
|
+
const declarations = [...stmt.getDeclarations()];
|
|
3024
|
+
const toRemove = declarations.filter((decl) => HELPER_NAMES.has(decl.getName()));
|
|
3025
|
+
if (toRemove.length === 0) continue;
|
|
3026
|
+
removedHelpers.push(...toRemove.map((decl) => decl.getName()));
|
|
3027
|
+
if (toRemove.length === declarations.length) {
|
|
3028
|
+
stmt.remove();
|
|
3029
|
+
} else {
|
|
3030
|
+
for (const decl of toRemove) decl.remove();
|
|
3031
|
+
}
|
|
3032
|
+
}
|
|
3033
|
+
for (const decl of sourceFile.getImportDeclarations()) {
|
|
3034
|
+
const matches = decl.getNamedImports().filter((ni) => ni.getName() === FHIR_IMPORT);
|
|
3035
|
+
if (matches.length === 0) continue;
|
|
3036
|
+
for (const named of matches) {
|
|
3037
|
+
named.remove();
|
|
3038
|
+
removedImportCount++;
|
|
3039
|
+
}
|
|
3040
|
+
const hasAnyNamedImportsLeft = decl.getNamedImports().length > 0;
|
|
3041
|
+
const hasDefaultImport = !!decl.getDefaultImport();
|
|
3042
|
+
const hasNamespaceImport = !!decl.getNamespaceImport();
|
|
3043
|
+
if (!hasAnyNamedImportsLeft && !hasDefaultImport && !hasNamespaceImport) {
|
|
3044
|
+
decl.remove();
|
|
3045
|
+
}
|
|
3046
|
+
}
|
|
3047
|
+
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;
|
|
3048
|
+
return { removedHelpers, removedImportCount, remainingFhirReferences };
|
|
3049
|
+
}
|
|
3050
|
+
async function main14() {
|
|
3051
|
+
const project = new import_ts_morph14.Project({
|
|
3052
|
+
tsConfigFilePath: import_path14.default.resolve(process.cwd(), "tsconfig.json"),
|
|
3053
|
+
skipAddingFilesFromTsConfig: false
|
|
3054
|
+
});
|
|
3055
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
3056
|
+
const fp = sf.getFilePath();
|
|
3057
|
+
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
3058
|
+
});
|
|
3059
|
+
console.log(`Removing legacy FHIR_URL helpers in ${sourceFiles.length} source file(s)...
|
|
3060
|
+
`);
|
|
3061
|
+
let totalRemovedImports = 0;
|
|
3062
|
+
let totalRemovedHelpers = 0;
|
|
3063
|
+
const modifiedFiles = [];
|
|
3064
|
+
const warnings = [];
|
|
3065
|
+
for (const sourceFile of sourceFiles) {
|
|
3066
|
+
const filePath = sourceFile.getFilePath();
|
|
3067
|
+
const rel = import_path14.default.relative(process.cwd(), filePath);
|
|
3068
|
+
const result = removeHelpers(filePath, project);
|
|
3069
|
+
const changed = result.removedImportCount > 0 || result.removedHelpers.length > 0;
|
|
3070
|
+
if (changed) {
|
|
3071
|
+
modifiedFiles.push(filePath);
|
|
3072
|
+
totalRemovedImports += result.removedImportCount;
|
|
3073
|
+
totalRemovedHelpers += result.removedHelpers.length;
|
|
3074
|
+
if (result.removedHelpers.length > 0) {
|
|
3075
|
+
console.log(
|
|
3076
|
+
` [${rel}] Removed helper(s): ${result.removedHelpers.join(", ")}`
|
|
3077
|
+
);
|
|
3078
|
+
}
|
|
3079
|
+
if (result.removedImportCount > 0) {
|
|
3080
|
+
console.log(
|
|
3081
|
+
` [${rel}] Removed ${result.removedImportCount} '${FHIR_IMPORT}' import(s)`
|
|
3082
|
+
);
|
|
3083
|
+
}
|
|
3084
|
+
}
|
|
3085
|
+
if (result.remainingFhirReferences > 0) {
|
|
3086
|
+
warnings.push(
|
|
3087
|
+
`${rel}: ${result.remainingFhirReferences} remaining '${FHIR_IMPORT}' reference(s)`
|
|
3088
|
+
);
|
|
3089
|
+
}
|
|
3090
|
+
}
|
|
3091
|
+
if (modifiedFiles.length === 0 && warnings.length === 0) {
|
|
3092
|
+
console.log("No FHIR_URL imports/helpers found. Nothing to do.");
|
|
3093
|
+
return;
|
|
3094
|
+
}
|
|
3095
|
+
if (modifiedFiles.length > 0) {
|
|
3096
|
+
console.log(`
|
|
3097
|
+
Saving ${modifiedFiles.length} modified file(s)...`);
|
|
3098
|
+
for (const filePath of modifiedFiles) {
|
|
3099
|
+
await project.getSourceFileOrThrow(filePath).save();
|
|
3100
|
+
console.log(` Saved: ${import_path14.default.relative(process.cwd(), filePath)}`);
|
|
3101
|
+
}
|
|
3102
|
+
}
|
|
3103
|
+
if (warnings.length > 0) {
|
|
3104
|
+
console.warn(
|
|
3105
|
+
`
|
|
3106
|
+
WARNING: Some '${FHIR_IMPORT}' usages remain and need manual cleanup:
|
|
3107
|
+
` + warnings.map((line) => ` - ${line}`).join("\n")
|
|
3108
|
+
);
|
|
3109
|
+
}
|
|
3110
|
+
console.log(
|
|
3111
|
+
`
|
|
3112
|
+
Done. Removed ${totalRemovedHelpers} helper declaration(s) and ${totalRemovedImports} '${FHIR_IMPORT}' import(s).`
|
|
3113
|
+
);
|
|
3114
|
+
}
|
|
3115
|
+
|
|
3116
|
+
// src/migrations/v2.0/migrate-application-config-url.ts
|
|
3117
|
+
var import_path15 = __toESM(require("path"));
|
|
3118
|
+
var import_ts_morph15 = require("ts-morph");
|
|
3119
|
+
var TARGET_IDENTIFIER = "APPLICATION_CONFIG_URL";
|
|
3120
|
+
var REPLACEMENT_IDENTIFIER = "applicationConfig";
|
|
3121
|
+
var REPLACEMENT_MODULE = "@countryconfig/api/application/application-config";
|
|
3122
|
+
var FUNCTION_LIKE_KINDS = [
|
|
3123
|
+
import_ts_morph15.SyntaxKind.FunctionDeclaration,
|
|
3124
|
+
import_ts_morph15.SyntaxKind.FunctionExpression,
|
|
3125
|
+
import_ts_morph15.SyntaxKind.ArrowFunction,
|
|
3126
|
+
import_ts_morph15.SyntaxKind.MethodDeclaration
|
|
3127
|
+
];
|
|
3128
|
+
function describeFunction(node) {
|
|
3129
|
+
if (import_ts_morph15.Node.isFunctionDeclaration(node) || import_ts_morph15.Node.isMethodDeclaration(node)) {
|
|
3130
|
+
return node.getName() ?? "<anonymous>";
|
|
3131
|
+
}
|
|
3132
|
+
const parent = node.getParent();
|
|
3133
|
+
if (parent && import_ts_morph15.Node.isVariableDeclaration(parent)) {
|
|
3134
|
+
return parent.getName();
|
|
3135
|
+
}
|
|
3136
|
+
if (parent && import_ts_morph15.Node.isPropertyAssignment(parent)) {
|
|
3137
|
+
return parent.getName();
|
|
3138
|
+
}
|
|
3139
|
+
if (import_ts_morph15.Node.isFunctionExpression(node) && node.getNameNode() !== void 0) {
|
|
3140
|
+
return node.getNameNode()?.getText() ?? "<anonymous>";
|
|
3141
|
+
}
|
|
3142
|
+
return "<anonymous>";
|
|
3143
|
+
}
|
|
3144
|
+
function hasBlockBody(node) {
|
|
3145
|
+
if (import_ts_morph15.Node.isFunctionDeclaration(node) || import_ts_morph15.Node.isFunctionExpression(node) || import_ts_morph15.Node.isMethodDeclaration(node)) {
|
|
3146
|
+
return node.getBody() !== void 0;
|
|
3147
|
+
}
|
|
3148
|
+
if (import_ts_morph15.Node.isArrowFunction(node)) {
|
|
3149
|
+
return node.getBody().getKind() === import_ts_morph15.SyntaxKind.Block;
|
|
3150
|
+
}
|
|
3151
|
+
return false;
|
|
3152
|
+
}
|
|
3153
|
+
function isConfigFetcher(node) {
|
|
3154
|
+
let referencesTarget = false;
|
|
3155
|
+
let callsFetch = false;
|
|
3156
|
+
for (const id of node.getDescendantsOfKind(import_ts_morph15.SyntaxKind.Identifier)) {
|
|
3157
|
+
const text = id.getText();
|
|
3158
|
+
if (!referencesTarget && text === TARGET_IDENTIFIER) referencesTarget = true;
|
|
3159
|
+
if (!callsFetch && text === "fetch") {
|
|
3160
|
+
const parent = id.getParent();
|
|
3161
|
+
if (import_ts_morph15.Node.isCallExpression(parent) && parent.getExpression() === id) {
|
|
3162
|
+
callsFetch = true;
|
|
3163
|
+
}
|
|
3164
|
+
}
|
|
3165
|
+
if (referencesTarget && callsFetch) return true;
|
|
3166
|
+
}
|
|
3167
|
+
return false;
|
|
3168
|
+
}
|
|
3169
|
+
function processFile11(sourceFile) {
|
|
3170
|
+
const importsWithTarget = sourceFile.getImportDeclarations().filter(
|
|
3171
|
+
(decl) => decl.getNamedImports().some((ni) => ni.getName() === TARGET_IDENTIFIER)
|
|
3172
|
+
);
|
|
3173
|
+
if (importsWithTarget.length === 0) {
|
|
3174
|
+
return { changed: false, rewrittenFunctions: [], renamedReferences: 0 };
|
|
3175
|
+
}
|
|
3176
|
+
const collidingLocals = sourceFile.getDescendantsOfKind(import_ts_morph15.SyntaxKind.Identifier).filter((id) => id.getText() === REPLACEMENT_IDENTIFIER).filter((id) => {
|
|
3177
|
+
const parent = id.getParent();
|
|
3178
|
+
const kind = parent.getKind();
|
|
3179
|
+
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;
|
|
3180
|
+
});
|
|
3181
|
+
if (collidingLocals.length > 0) {
|
|
3182
|
+
return {
|
|
3183
|
+
changed: false,
|
|
3184
|
+
rewrittenFunctions: [],
|
|
3185
|
+
renamedReferences: 0,
|
|
3186
|
+
skippedReason: `local declaration named '${REPLACEMENT_IDENTIFIER}' would collide`
|
|
3187
|
+
};
|
|
3188
|
+
}
|
|
3189
|
+
const candidateFunctions = FUNCTION_LIKE_KINDS.flatMap(
|
|
3190
|
+
(kind) => sourceFile.getDescendantsOfKind(kind)
|
|
3191
|
+
);
|
|
3192
|
+
candidateFunctions.sort((a, b) => a.getStart() - b.getStart());
|
|
3193
|
+
const rewrittenFunctions = [];
|
|
3194
|
+
const rewrittenSet = /* @__PURE__ */ new Set();
|
|
3195
|
+
for (const fn of candidateFunctions) {
|
|
3196
|
+
if (!hasBlockBody(fn)) continue;
|
|
3197
|
+
if (!isConfigFetcher(fn)) continue;
|
|
3198
|
+
let inRewrittenAncestor = false;
|
|
3199
|
+
let cursor = fn.getParent();
|
|
3200
|
+
while (cursor) {
|
|
3201
|
+
if (rewrittenSet.has(cursor)) {
|
|
3202
|
+
inRewrittenAncestor = true;
|
|
3203
|
+
break;
|
|
3204
|
+
}
|
|
3205
|
+
cursor = cursor.getParent();
|
|
3206
|
+
}
|
|
3207
|
+
if (inRewrittenAncestor) continue;
|
|
3208
|
+
const start = fn.getStart();
|
|
3209
|
+
const line = sourceFile.getLineAndColumnAtPos(start).line;
|
|
3210
|
+
const name = describeFunction(fn);
|
|
3211
|
+
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)) {
|
|
3212
|
+
fn.setBodyText(`return ${REPLACEMENT_IDENTIFIER}`);
|
|
3213
|
+
}
|
|
3214
|
+
rewrittenFunctions.push({ name, line });
|
|
3215
|
+
rewrittenSet.add(fn);
|
|
3216
|
+
}
|
|
3217
|
+
for (const decl of importsWithTarget) {
|
|
3218
|
+
const targetNamed = decl.getNamedImports().find((ni) => ni.getName() === TARGET_IDENTIFIER);
|
|
3219
|
+
targetNamed?.remove();
|
|
3220
|
+
const isNowEmpty = decl.getNamedImports().length === 0 && !decl.getDefaultImport() && !decl.getNamespaceImport();
|
|
3221
|
+
if (isNowEmpty) decl.remove();
|
|
3222
|
+
}
|
|
3223
|
+
const existing = sourceFile.getImportDeclaration(
|
|
3224
|
+
(decl) => decl.getModuleSpecifierValue() === REPLACEMENT_MODULE
|
|
3225
|
+
);
|
|
3226
|
+
if (existing) {
|
|
3227
|
+
const alreadyImported = existing.getNamedImports().some((ni) => ni.getName() === REPLACEMENT_IDENTIFIER);
|
|
3228
|
+
if (!alreadyImported) existing.addNamedImport(REPLACEMENT_IDENTIFIER);
|
|
3229
|
+
} else {
|
|
3230
|
+
sourceFile.addImportDeclaration({
|
|
3231
|
+
moduleSpecifier: REPLACEMENT_MODULE,
|
|
3232
|
+
namedImports: [REPLACEMENT_IDENTIFIER]
|
|
3233
|
+
});
|
|
3234
|
+
}
|
|
3235
|
+
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) => {
|
|
3236
|
+
const parent = id.getParent();
|
|
3237
|
+
const parentKind = parent.getKind();
|
|
3238
|
+
if (parentKind === import_ts_morph15.SyntaxKind.PropertyAccessExpression) {
|
|
3239
|
+
const pae = parent.asKind(import_ts_morph15.SyntaxKind.PropertyAccessExpression);
|
|
3240
|
+
if (pae.getNameNode() === id) return false;
|
|
3241
|
+
}
|
|
3242
|
+
if (parentKind === import_ts_morph15.SyntaxKind.PropertyAssignment) {
|
|
3243
|
+
const pa = parent.asKind(import_ts_morph15.SyntaxKind.PropertyAssignment);
|
|
3244
|
+
if (pa.getNameNode() === id) return false;
|
|
3245
|
+
}
|
|
3246
|
+
if (parentKind === import_ts_morph15.SyntaxKind.ShorthandPropertyAssignment) {
|
|
3247
|
+
return false;
|
|
3248
|
+
}
|
|
3249
|
+
return true;
|
|
3250
|
+
}).sort((a, b) => b.getPos() - a.getPos());
|
|
3251
|
+
for (const id of renameTargets) {
|
|
3252
|
+
id.replaceWithText(REPLACEMENT_IDENTIFIER);
|
|
3253
|
+
}
|
|
3254
|
+
return {
|
|
3255
|
+
changed: true,
|
|
3256
|
+
rewrittenFunctions,
|
|
3257
|
+
renamedReferences: renameTargets.length
|
|
3258
|
+
};
|
|
3259
|
+
}
|
|
3260
|
+
async function main15() {
|
|
3261
|
+
const project = new import_ts_morph15.Project({
|
|
3262
|
+
tsConfigFilePath: import_path15.default.resolve(process.cwd(), "tsconfig.json"),
|
|
3263
|
+
skipAddingFilesFromTsConfig: false
|
|
3264
|
+
});
|
|
3265
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
3266
|
+
const fp = sf.getFilePath();
|
|
3267
|
+
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
3268
|
+
});
|
|
3269
|
+
console.log(
|
|
3270
|
+
`Migrating '${TARGET_IDENTIFIER}' \u2192 '${REPLACEMENT_IDENTIFIER}' across ${sourceFiles.length} source file(s)...
|
|
3271
|
+
`
|
|
3272
|
+
);
|
|
3273
|
+
let changedFiles = 0;
|
|
3274
|
+
let totalRewrittenFunctions = 0;
|
|
3275
|
+
let totalRenamedReferences = 0;
|
|
3276
|
+
const skipped = [];
|
|
3277
|
+
for (const sourceFile of sourceFiles) {
|
|
3278
|
+
const filePath = sourceFile.getFilePath();
|
|
3279
|
+
const rel = import_path15.default.relative(process.cwd(), filePath);
|
|
3280
|
+
const result = processFile11(sourceFile);
|
|
3281
|
+
if (result.skippedReason) {
|
|
3282
|
+
skipped.push(`${rel} (${result.skippedReason})`);
|
|
3283
|
+
continue;
|
|
3284
|
+
}
|
|
3285
|
+
if (!result.changed) continue;
|
|
3286
|
+
await sourceFile.save();
|
|
3287
|
+
changedFiles++;
|
|
3288
|
+
totalRewrittenFunctions += result.rewrittenFunctions.length;
|
|
3289
|
+
totalRenamedReferences += result.renamedReferences;
|
|
3290
|
+
for (const fn of result.rewrittenFunctions) {
|
|
3291
|
+
console.log(
|
|
3292
|
+
` [${rel}:${fn.line}] Rewrote '${fn.name}' body \u2192 'return ${REPLACEMENT_IDENTIFIER}' (config fetch eliminated)`
|
|
3293
|
+
);
|
|
3294
|
+
}
|
|
3295
|
+
if (result.renamedReferences > 0) {
|
|
3296
|
+
console.log(
|
|
3297
|
+
` [${rel}] Renamed ${result.renamedReferences} stray reference(s) ${TARGET_IDENTIFIER} \u2192 ${REPLACEMENT_IDENTIFIER}`
|
|
3298
|
+
);
|
|
3299
|
+
}
|
|
3300
|
+
}
|
|
3301
|
+
if (skipped.length > 0) {
|
|
3302
|
+
console.warn(
|
|
3303
|
+
`
|
|
3304
|
+
${skipped.length} file(s) skipped:
|
|
3305
|
+
` + skipped.map((s) => ` - ${s}`).join("\n")
|
|
3306
|
+
);
|
|
3307
|
+
}
|
|
3308
|
+
if (changedFiles === 0) {
|
|
3309
|
+
console.log(`
|
|
3310
|
+
No files reference '${TARGET_IDENTIFIER}'. Nothing to do.`);
|
|
3311
|
+
return;
|
|
3312
|
+
}
|
|
3313
|
+
console.log(
|
|
3314
|
+
`
|
|
3315
|
+
Done. Updated ${changedFiles} file(s): ${totalRewrittenFunctions} fetch function(s) rewritten, ${totalRenamedReferences} bare reference(s) renamed.`
|
|
3316
|
+
);
|
|
3317
|
+
if (totalRewrittenFunctions > 0) {
|
|
3318
|
+
console.log(
|
|
3319
|
+
`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}'.`
|
|
3320
|
+
);
|
|
3321
|
+
}
|
|
3322
|
+
}
|
|
3323
|
+
|
|
3324
|
+
// src/migrations/v2.0/remove-old-statistics-service.ts
|
|
3325
|
+
var import_path16 = __toESM(require("path"));
|
|
3326
|
+
var import_ts_morph16 = require("ts-morph");
|
|
3327
|
+
var ROUTE_PATH = "/statistics";
|
|
3328
|
+
var HANDLER_NAME = "statisticsHandler";
|
|
3329
|
+
function isStatisticsRouteObject(obj) {
|
|
3330
|
+
const pathProp = obj.getProperty("path");
|
|
3331
|
+
if (!pathProp || !import_ts_morph16.Node.isPropertyAssignment(pathProp)) return false;
|
|
3332
|
+
const init = pathProp.getInitializer();
|
|
3333
|
+
if (!init) return false;
|
|
3334
|
+
if (import_ts_morph16.Node.isStringLiteral(init) || import_ts_morph16.Node.isNoSubstitutionTemplateLiteral(init)) {
|
|
3335
|
+
return init.getLiteralValue() === ROUTE_PATH;
|
|
3336
|
+
}
|
|
3337
|
+
return false;
|
|
3338
|
+
}
|
|
3339
|
+
function removeStatisticsRoutes(sourceFile) {
|
|
3340
|
+
let removed = 0;
|
|
3341
|
+
const callExpressions = [
|
|
3342
|
+
...sourceFile.getDescendantsOfKind(import_ts_morph16.SyntaxKind.CallExpression)
|
|
3343
|
+
];
|
|
3344
|
+
for (const call of callExpressions) {
|
|
3345
|
+
if (call.wasForgotten()) continue;
|
|
3346
|
+
const expr = call.getExpression();
|
|
3347
|
+
if (!import_ts_morph16.Node.isPropertyAccessExpression(expr)) continue;
|
|
3348
|
+
if (expr.getName() !== "route") continue;
|
|
3349
|
+
const args = call.getArguments();
|
|
3350
|
+
if (args.length === 0) continue;
|
|
3351
|
+
const firstArg = args[0];
|
|
3352
|
+
if (import_ts_morph16.Node.isObjectLiteralExpression(firstArg)) {
|
|
3353
|
+
if (!isStatisticsRouteObject(firstArg)) continue;
|
|
3354
|
+
const stmt = call.getFirstAncestorByKind(import_ts_morph16.SyntaxKind.ExpressionStatement);
|
|
3355
|
+
if (stmt) {
|
|
3356
|
+
stmt.remove();
|
|
3357
|
+
removed++;
|
|
3358
|
+
} else {
|
|
3359
|
+
call.replaceWithText("");
|
|
3360
|
+
removed++;
|
|
3361
|
+
}
|
|
3362
|
+
continue;
|
|
3363
|
+
}
|
|
3364
|
+
if (import_ts_morph16.Node.isArrayLiteralExpression(firstArg)) {
|
|
3365
|
+
const matchingIndexes = firstArg.getElements().map((el, idx) => ({ el, idx })).filter(
|
|
3366
|
+
({ el }) => import_ts_morph16.Node.isObjectLiteralExpression(el) && isStatisticsRouteObject(el)
|
|
3367
|
+
).map(({ idx }) => idx);
|
|
3368
|
+
matchingIndexes.sort((a, b) => b - a).forEach((idx) => {
|
|
3369
|
+
firstArg.removeElement(idx);
|
|
3370
|
+
removed++;
|
|
3371
|
+
});
|
|
3372
|
+
}
|
|
3373
|
+
}
|
|
3374
|
+
return removed;
|
|
3375
|
+
}
|
|
3376
|
+
function removeStatisticsHandlerImports(sourceFile) {
|
|
3377
|
+
let changed = false;
|
|
3378
|
+
for (const decl of sourceFile.getImportDeclarations()) {
|
|
3379
|
+
const targetNamed = decl.getNamedImports().find((ni) => ni.getName() === HANDLER_NAME);
|
|
3380
|
+
if (!targetNamed) continue;
|
|
3381
|
+
targetNamed.remove();
|
|
3382
|
+
changed = true;
|
|
3383
|
+
const isNowEmpty = decl.getNamedImports().length === 0 && !decl.getDefaultImport() && !decl.getNamespaceImport();
|
|
3384
|
+
if (isNowEmpty) decl.remove();
|
|
3385
|
+
}
|
|
3386
|
+
return changed;
|
|
3387
|
+
}
|
|
3388
|
+
function processFile12(sourceFile) {
|
|
3389
|
+
const routesRemoved = removeStatisticsRoutes(sourceFile);
|
|
3390
|
+
const importsCleaned = removeStatisticsHandlerImports(sourceFile);
|
|
3391
|
+
return { routesRemoved, importsCleaned };
|
|
3392
|
+
}
|
|
3393
|
+
function collectLocalImportsInSubtree(sourceFile, subtreeRoot) {
|
|
3394
|
+
const result = [];
|
|
3395
|
+
for (const decl of sourceFile.getImportDeclarations()) {
|
|
3396
|
+
const moduleSf = decl.getModuleSpecifierSourceFile();
|
|
3397
|
+
if (!moduleSf) continue;
|
|
3398
|
+
const fp = moduleSf.getFilePath();
|
|
3399
|
+
if (!fp.startsWith(subtreeRoot)) continue;
|
|
3400
|
+
result.push(fp);
|
|
3401
|
+
}
|
|
3402
|
+
return result;
|
|
3403
|
+
}
|
|
3404
|
+
function deleteOrphanedDescendants(project, startingFile, subtreeRoot) {
|
|
3405
|
+
const initialCandidates = collectLocalImportsInSubtree(
|
|
3406
|
+
startingFile,
|
|
3407
|
+
subtreeRoot
|
|
3408
|
+
);
|
|
3409
|
+
const startingPath = startingFile.getFilePath();
|
|
3410
|
+
const deleted = /* @__PURE__ */ new Set([startingPath]);
|
|
3411
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3412
|
+
const worklist = [...initialCandidates];
|
|
3413
|
+
const orphans = [];
|
|
3414
|
+
while (worklist.length > 0) {
|
|
3415
|
+
const candidate = worklist.shift();
|
|
3416
|
+
if (seen.has(candidate)) continue;
|
|
3417
|
+
seen.add(candidate);
|
|
3418
|
+
if (deleted.has(candidate)) continue;
|
|
3419
|
+
if (!candidate.startsWith(subtreeRoot)) continue;
|
|
3420
|
+
const candidateSf = project.getSourceFile(candidate);
|
|
3421
|
+
if (!candidateSf) continue;
|
|
3422
|
+
const stillImported = project.getSourceFiles().some((sf) => {
|
|
3423
|
+
const sfPath = sf.getFilePath();
|
|
3424
|
+
if (deleted.has(sfPath)) return false;
|
|
3425
|
+
if (sfPath === candidate) return false;
|
|
3426
|
+
return sf.getImportDeclarations().some(
|
|
3427
|
+
(decl) => decl.getModuleSpecifierSourceFile()?.getFilePath() === candidate
|
|
3428
|
+
);
|
|
3429
|
+
});
|
|
3430
|
+
if (stillImported) continue;
|
|
3431
|
+
const next = collectLocalImportsInSubtree(candidateSf, subtreeRoot);
|
|
3432
|
+
worklist.push(...next);
|
|
3433
|
+
candidateSf.delete();
|
|
3434
|
+
deleted.add(candidate);
|
|
3435
|
+
orphans.push(candidate);
|
|
3436
|
+
}
|
|
3437
|
+
return orphans;
|
|
3438
|
+
}
|
|
3439
|
+
function processHandlerFile(project) {
|
|
3440
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
3441
|
+
const fp = sf.getFilePath();
|
|
3442
|
+
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
3443
|
+
});
|
|
3444
|
+
for (const sf of sourceFiles) {
|
|
3445
|
+
const fn = sf.getFunction(HANDLER_NAME);
|
|
3446
|
+
if (!fn) continue;
|
|
3447
|
+
const filePath = sf.getFilePath();
|
|
3448
|
+
const exportsByName = [...sf.getExportedDeclarations().keys()];
|
|
3449
|
+
const otherExports = exportsByName.filter((name) => name !== HANDLER_NAME);
|
|
3450
|
+
if (otherExports.length === 0) {
|
|
3451
|
+
const subtreeRoot = import_path16.default.dirname(filePath) + import_path16.default.sep;
|
|
3452
|
+
const orphansDeleted = deleteOrphanedDescendants(
|
|
3453
|
+
project,
|
|
3454
|
+
sf,
|
|
3455
|
+
subtreeRoot
|
|
3456
|
+
);
|
|
3457
|
+
sf.delete();
|
|
3458
|
+
return { filePath, action: "deleted", orphansDeleted };
|
|
3459
|
+
}
|
|
3460
|
+
fn.remove();
|
|
3461
|
+
return {
|
|
3462
|
+
filePath,
|
|
3463
|
+
action: "function-removed",
|
|
3464
|
+
remainingExports: otherExports,
|
|
3465
|
+
orphansDeleted: []
|
|
3466
|
+
};
|
|
3467
|
+
}
|
|
3468
|
+
return { filePath: "", action: "not-found", orphansDeleted: [] };
|
|
3469
|
+
}
|
|
3470
|
+
async function main16() {
|
|
3471
|
+
const project = new import_ts_morph16.Project({
|
|
3472
|
+
tsConfigFilePath: import_path16.default.resolve(process.cwd(), "tsconfig.json"),
|
|
3473
|
+
skipAddingFilesFromTsConfig: false
|
|
3474
|
+
});
|
|
3475
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
3476
|
+
const fp = sf.getFilePath();
|
|
3477
|
+
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
3478
|
+
});
|
|
3479
|
+
console.log(
|
|
3480
|
+
`Removing legacy 'GET ${ROUTE_PATH}' route and '${HANDLER_NAME}' across ${sourceFiles.length} source file(s)...
|
|
3481
|
+
`
|
|
3482
|
+
);
|
|
3483
|
+
let totalRoutesRemoved = 0;
|
|
3484
|
+
let totalFilesWithImportsCleaned = 0;
|
|
3485
|
+
let totalFilesWithRoutesRemoved = 0;
|
|
3486
|
+
for (const sourceFile of sourceFiles) {
|
|
3487
|
+
const filePath = sourceFile.getFilePath();
|
|
3488
|
+
const rel = import_path16.default.relative(process.cwd(), filePath);
|
|
3489
|
+
const result = processFile12(sourceFile);
|
|
3490
|
+
if (result.routesRemoved > 0) {
|
|
3491
|
+
console.log(
|
|
3492
|
+
` [${rel}] Removed ${result.routesRemoved} '${ROUTE_PATH}' route(s)`
|
|
3493
|
+
);
|
|
3494
|
+
totalRoutesRemoved += result.routesRemoved;
|
|
3495
|
+
totalFilesWithRoutesRemoved++;
|
|
3496
|
+
}
|
|
3497
|
+
if (result.importsCleaned) {
|
|
3498
|
+
console.log(` [${rel}] Cleaned up '${HANDLER_NAME}' import`);
|
|
3499
|
+
totalFilesWithImportsCleaned++;
|
|
3500
|
+
}
|
|
3501
|
+
if (result.routesRemoved > 0 || result.importsCleaned) {
|
|
3502
|
+
await sourceFile.save();
|
|
3503
|
+
}
|
|
3504
|
+
}
|
|
3505
|
+
const handlerResult = processHandlerFile(project);
|
|
3506
|
+
switch (handlerResult.action) {
|
|
3507
|
+
case "deleted": {
|
|
3508
|
+
const rel = import_path16.default.relative(process.cwd(), handlerResult.filePath);
|
|
3509
|
+
console.log(
|
|
3510
|
+
` [${rel}] Deleted handler file ('${HANDLER_NAME}' was the sole export).`
|
|
3511
|
+
);
|
|
3512
|
+
for (const orphanPath of handlerResult.orphansDeleted) {
|
|
3513
|
+
const orphanRel = import_path16.default.relative(process.cwd(), orphanPath);
|
|
3514
|
+
console.log(
|
|
3515
|
+
` [${orphanRel}] Deleted (no remaining importers in the project after handler removal).`
|
|
3516
|
+
);
|
|
3517
|
+
}
|
|
3518
|
+
await project.save();
|
|
3519
|
+
break;
|
|
3520
|
+
}
|
|
3521
|
+
case "function-removed": {
|
|
3522
|
+
const rel = import_path16.default.relative(process.cwd(), handlerResult.filePath);
|
|
3523
|
+
console.warn(
|
|
3524
|
+
` [${rel}] Removed '${HANDLER_NAME}' function but kept the file (other exports remain: ${handlerResult.remainingExports?.join(", ")}). Review whether the file is still needed.`
|
|
3525
|
+
);
|
|
3526
|
+
const sf = project.getSourceFile(handlerResult.filePath);
|
|
3527
|
+
if (sf) await sf.save();
|
|
3528
|
+
break;
|
|
3529
|
+
}
|
|
3530
|
+
case "not-found":
|
|
3531
|
+
break;
|
|
3532
|
+
}
|
|
3533
|
+
if (totalRoutesRemoved === 0 && totalFilesWithImportsCleaned === 0 && handlerResult.action === "not-found") {
|
|
3534
|
+
console.log(`
|
|
3535
|
+
No legacy '${ROUTE_PATH}' route or handler found. Nothing to do.`);
|
|
3536
|
+
return;
|
|
3537
|
+
}
|
|
3538
|
+
const orphansSummary = handlerResult.orphansDeleted.length > 0 ? ` and ${handlerResult.orphansDeleted.length} orphaned helper file(s)` : "";
|
|
3539
|
+
console.log(
|
|
3540
|
+
`
|
|
3541
|
+
Done. Removed ${totalRoutesRemoved} route(s) across ${totalFilesWithRoutesRemoved} file(s); cleaned ${HANDLER_NAME} import in ${totalFilesWithImportsCleaned} file(s)${orphansSummary}.`
|
|
3542
|
+
);
|
|
3543
|
+
}
|
|
3544
|
+
|
|
3545
|
+
// src/migrations/v2.0/update-package-json.ts
|
|
3546
|
+
var import_fs = require("fs");
|
|
3547
|
+
var import_path17 = __toESM(require("path"));
|
|
3548
|
+
var PACKAGE_JSON_RELATIVE = "package.json";
|
|
3549
|
+
var TARGET_VERSION = "2.0.0";
|
|
3550
|
+
var TARGET_ZOD_RANGE = "^4.2.1";
|
|
3551
|
+
async function main17() {
|
|
3552
|
+
const packageJsonPath = import_path17.default.join(process.cwd(), PACKAGE_JSON_RELATIVE);
|
|
3553
|
+
if (!(0, import_fs.existsSync)(packageJsonPath)) {
|
|
3554
|
+
console.log(`'${PACKAGE_JSON_RELATIVE}' not found in ${process.cwd()} \u2014 skipping.`);
|
|
3555
|
+
return;
|
|
3556
|
+
}
|
|
3557
|
+
const raw = (0, import_fs.readFileSync)(packageJsonPath, "utf8");
|
|
3558
|
+
let parsed;
|
|
3559
|
+
try {
|
|
3560
|
+
parsed = JSON.parse(raw);
|
|
3561
|
+
} catch (error) {
|
|
3562
|
+
console.warn(
|
|
3563
|
+
` [${PACKAGE_JSON_RELATIVE}] Failed to parse JSON \u2014 skipping update. ${error.message}`
|
|
3564
|
+
);
|
|
3565
|
+
return;
|
|
3566
|
+
}
|
|
3567
|
+
console.log(`Updating '${PACKAGE_JSON_RELATIVE}'...`);
|
|
3568
|
+
const previousVersion = parsed.version;
|
|
3569
|
+
const versionChanged = previousVersion !== TARGET_VERSION;
|
|
3570
|
+
parsed.version = TARGET_VERSION;
|
|
3571
|
+
if (versionChanged) {
|
|
3572
|
+
console.log(
|
|
3573
|
+
` Set version: ${previousVersion ?? "<unset>"} \u2192 ${TARGET_VERSION}`
|
|
3574
|
+
);
|
|
3575
|
+
} else {
|
|
3576
|
+
console.log(` Version already ${TARGET_VERSION} \u2014 no change.`);
|
|
3577
|
+
}
|
|
3578
|
+
let zodBucket = "dependencies";
|
|
3579
|
+
if (parsed.devDependencies && "zod" in parsed.devDependencies) {
|
|
3580
|
+
zodBucket = "devDependencies";
|
|
3581
|
+
}
|
|
3582
|
+
if (!parsed[zodBucket]) {
|
|
3583
|
+
parsed[zodBucket] = {};
|
|
3584
|
+
}
|
|
3585
|
+
const bucket = parsed[zodBucket];
|
|
3586
|
+
const previousZod = bucket.zod;
|
|
3587
|
+
const zodChanged = previousZod !== TARGET_ZOD_RANGE;
|
|
3588
|
+
bucket.zod = TARGET_ZOD_RANGE;
|
|
3589
|
+
if (zodChanged) {
|
|
3590
|
+
console.log(
|
|
3591
|
+
` Set ${zodBucket}.zod: ${previousZod ?? "<absent>"} \u2192 ${TARGET_ZOD_RANGE}`
|
|
3592
|
+
);
|
|
3593
|
+
} else {
|
|
3594
|
+
console.log(` ${zodBucket}.zod already ${TARGET_ZOD_RANGE} \u2014 no change.`);
|
|
3595
|
+
}
|
|
3596
|
+
const trailingNewline = raw.endsWith("\n") ? "\n" : "";
|
|
3597
|
+
const next = JSON.stringify(parsed, null, 2) + trailingNewline;
|
|
3598
|
+
if (next === raw) {
|
|
3599
|
+
console.log("\n No changes to write.");
|
|
3600
|
+
return;
|
|
3601
|
+
}
|
|
3602
|
+
(0, import_fs.writeFileSync)(packageJsonPath, next, "utf8");
|
|
3603
|
+
console.log(`
|
|
3604
|
+
Saved '${PACKAGE_JSON_RELATIVE}'.`);
|
|
3605
|
+
console.log(
|
|
3606
|
+
` NOTE: run \`yarn install\` (or your package manager equivalent) to install the updated dependency versions.`
|
|
3607
|
+
);
|
|
3608
|
+
}
|
|
3609
|
+
|
|
3610
|
+
// src/migrations/v2.0/migrate-workqueue-configs.ts
|
|
3611
|
+
var import_ts_morph17 = require("ts-morph");
|
|
3612
|
+
var import_path18 = __toESM(require("path"));
|
|
2889
3613
|
var DEFINE_WORKQUEUES_NAME3 = "defineWorkqueues";
|
|
2890
3614
|
var ACTIONS_PROPERTY_NAME5 = "actions";
|
|
2891
3615
|
var ACTION_PROPERTY_NAME2 = "action";
|
|
@@ -2906,28 +3630,28 @@ var SUPPORTED_WORKQUEUE_ACTION_TYPES = /* @__PURE__ */ new Set([
|
|
|
2906
3630
|
]);
|
|
2907
3631
|
function getWorkqueueLabel(workqueue) {
|
|
2908
3632
|
const slugProperty = workqueue.getProperty(SLUG_PROPERTY_NAME);
|
|
2909
|
-
if (!slugProperty || !
|
|
3633
|
+
if (!slugProperty || !import_ts_morph17.Node.isPropertyAssignment(slugProperty)) {
|
|
2910
3634
|
return "(unknown slug)";
|
|
2911
3635
|
}
|
|
2912
3636
|
const slugInitializer = slugProperty.getInitializer();
|
|
2913
|
-
if (!slugInitializer || !
|
|
3637
|
+
if (!slugInitializer || !import_ts_morph17.Node.isStringLiteral(slugInitializer)) {
|
|
2914
3638
|
return "(unknown slug)";
|
|
2915
3639
|
}
|
|
2916
3640
|
return slugInitializer.getLiteralValue();
|
|
2917
3641
|
}
|
|
2918
3642
|
function getActionTypeName(action) {
|
|
2919
3643
|
const typeProperty = action.getProperty(TYPE_PROPERTY_NAME7);
|
|
2920
|
-
if (!typeProperty || !
|
|
3644
|
+
if (!typeProperty || !import_ts_morph17.Node.isPropertyAssignment(typeProperty)) {
|
|
2921
3645
|
return null;
|
|
2922
3646
|
}
|
|
2923
3647
|
const typeInitializer = typeProperty.getInitializer();
|
|
2924
3648
|
if (!typeInitializer) {
|
|
2925
3649
|
return null;
|
|
2926
3650
|
}
|
|
2927
|
-
if (
|
|
3651
|
+
if (import_ts_morph17.Node.isStringLiteral(typeInitializer)) {
|
|
2928
3652
|
return typeInitializer.getLiteralValue();
|
|
2929
3653
|
}
|
|
2930
|
-
if (
|
|
3654
|
+
if (import_ts_morph17.Node.isPropertyAccessExpression(typeInitializer)) {
|
|
2931
3655
|
return typeInitializer.getName();
|
|
2932
3656
|
}
|
|
2933
3657
|
return null;
|
|
@@ -2941,19 +3665,19 @@ function isUnsupportedActionType(action) {
|
|
|
2941
3665
|
}
|
|
2942
3666
|
function migrateWorkqueueActions(workqueue, relPath) {
|
|
2943
3667
|
const actionsProperty = workqueue.getProperty(ACTIONS_PROPERTY_NAME5);
|
|
2944
|
-
if (!actionsProperty || !
|
|
3668
|
+
if (!actionsProperty || !import_ts_morph17.Node.isPropertyAssignment(actionsProperty)) {
|
|
2945
3669
|
return 0;
|
|
2946
3670
|
}
|
|
2947
3671
|
const actionsInitializer = actionsProperty.getInitializer();
|
|
2948
|
-
if (!actionsInitializer || !
|
|
3672
|
+
if (!actionsInitializer || !import_ts_morph17.Node.isArrayLiteralExpression(actionsInitializer)) {
|
|
2949
3673
|
return 0;
|
|
2950
3674
|
}
|
|
2951
3675
|
const workqueueLabel = getWorkqueueLabel(workqueue);
|
|
2952
3676
|
const existingActionProperty = workqueue.getProperty(ACTION_PROPERTY_NAME2);
|
|
2953
3677
|
if (existingActionProperty) {
|
|
2954
|
-
if (
|
|
3678
|
+
if (import_ts_morph17.Node.isPropertyAssignment(existingActionProperty)) {
|
|
2955
3679
|
const existingActionInitializer = existingActionProperty.getInitializer();
|
|
2956
|
-
if (existingActionInitializer &&
|
|
3680
|
+
if (existingActionInitializer && import_ts_morph17.Node.isObjectLiteralExpression(existingActionInitializer)) {
|
|
2957
3681
|
const conditionalsProperty2 = existingActionInitializer.getProperty(
|
|
2958
3682
|
CONDITIONALS_PROPERTY_NAME
|
|
2959
3683
|
);
|
|
@@ -2978,7 +3702,7 @@ function migrateWorkqueueActions(workqueue, relPath) {
|
|
|
2978
3702
|
return 1;
|
|
2979
3703
|
}
|
|
2980
3704
|
const actionCandidates = actionsInitializer.getElements().filter(
|
|
2981
|
-
(element) =>
|
|
3705
|
+
(element) => import_ts_morph17.Node.isObjectLiteralExpression(element)
|
|
2982
3706
|
);
|
|
2983
3707
|
if (actionCandidates.length === 0) {
|
|
2984
3708
|
actionsProperty.remove();
|
|
@@ -3020,36 +3744,36 @@ function migrateWorkqueueActions(workqueue, relPath) {
|
|
|
3020
3744
|
);
|
|
3021
3745
|
return 1;
|
|
3022
3746
|
}
|
|
3023
|
-
function
|
|
3747
|
+
function processFile13(filePath, project) {
|
|
3024
3748
|
const sourceFile = project.getSourceFile(filePath);
|
|
3025
3749
|
if (!sourceFile) return 0;
|
|
3026
3750
|
let migratedWorkqueues = 0;
|
|
3027
|
-
const relPath =
|
|
3751
|
+
const relPath = import_path18.default.relative(process.cwd(), filePath);
|
|
3028
3752
|
const callExpressions = sourceFile.getDescendantsOfKind(
|
|
3029
|
-
|
|
3753
|
+
import_ts_morph17.SyntaxKind.CallExpression
|
|
3030
3754
|
);
|
|
3031
3755
|
for (const call of callExpressions) {
|
|
3032
3756
|
const expression = call.getExpression();
|
|
3033
|
-
if (!
|
|
3757
|
+
if (!import_ts_morph17.Node.isIdentifier(expression) || expression.getText() !== DEFINE_WORKQUEUES_NAME3) {
|
|
3034
3758
|
continue;
|
|
3035
3759
|
}
|
|
3036
3760
|
const args = call.getArguments();
|
|
3037
3761
|
if (args.length === 0) continue;
|
|
3038
3762
|
const workqueuesArg = args[0];
|
|
3039
|
-
if (!
|
|
3763
|
+
if (!import_ts_morph17.Node.isArrayLiteralExpression(workqueuesArg)) continue;
|
|
3040
3764
|
for (const element of workqueuesArg.getElements()) {
|
|
3041
|
-
if (!
|
|
3765
|
+
if (!import_ts_morph17.Node.isObjectLiteralExpression(element)) continue;
|
|
3042
3766
|
migratedWorkqueues += migrateWorkqueueActions(element, relPath);
|
|
3043
3767
|
}
|
|
3044
3768
|
}
|
|
3045
3769
|
return migratedWorkqueues;
|
|
3046
3770
|
}
|
|
3047
|
-
async function
|
|
3048
|
-
const srcDir =
|
|
3771
|
+
async function main18() {
|
|
3772
|
+
const srcDir = import_path18.default.join(process.cwd(), "src");
|
|
3049
3773
|
console.log(`Scanning for defineWorkqueues calls in: ${srcDir}
|
|
3050
3774
|
`);
|
|
3051
|
-
const project = new
|
|
3052
|
-
tsConfigFilePath:
|
|
3775
|
+
const project = new import_ts_morph17.Project({
|
|
3776
|
+
tsConfigFilePath: import_path18.default.resolve(srcDir, "../tsconfig.json"),
|
|
3053
3777
|
skipAddingFilesFromTsConfig: false
|
|
3054
3778
|
});
|
|
3055
3779
|
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
@@ -3062,7 +3786,7 @@ async function main13() {
|
|
|
3062
3786
|
const modifiedFiles = [];
|
|
3063
3787
|
for (const sourceFile of sourceFiles) {
|
|
3064
3788
|
const filePath = sourceFile.getFilePath();
|
|
3065
|
-
const migrated =
|
|
3789
|
+
const migrated = processFile13(filePath, project);
|
|
3066
3790
|
if (migrated > 0) {
|
|
3067
3791
|
totalMigrated += migrated;
|
|
3068
3792
|
modifiedFiles.push(filePath);
|
|
@@ -3079,7 +3803,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
3079
3803
|
for (const filePath of modifiedFiles) {
|
|
3080
3804
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
3081
3805
|
await sourceFile.save();
|
|
3082
|
-
console.log(` Saved: ${
|
|
3806
|
+
console.log(` Saved: ${import_path18.default.relative(process.cwd(), filePath)}`);
|
|
3083
3807
|
}
|
|
3084
3808
|
console.log(
|
|
3085
3809
|
`
|
|
@@ -3088,13 +3812,13 @@ Done. Migrated ${totalMigrated} deprecated workqueue 'actions' definition(s) to
|
|
|
3088
3812
|
}
|
|
3089
3813
|
|
|
3090
3814
|
// src/migrations/v2.0/remove-demo-scope.ts
|
|
3091
|
-
var
|
|
3092
|
-
var
|
|
3815
|
+
var import_path19 = __toESM(require("path"));
|
|
3816
|
+
var import_ts_morph18 = require("ts-morph");
|
|
3093
3817
|
var ROLES_HANDLER_RELATIVE_PATH = "src/data-seeding/roles/handler.ts";
|
|
3094
|
-
async function
|
|
3095
|
-
const rolesHandlerPath =
|
|
3096
|
-
const project = new
|
|
3097
|
-
tsConfigFilePath:
|
|
3818
|
+
async function main19() {
|
|
3819
|
+
const rolesHandlerPath = import_path19.default.join(process.cwd(), ROLES_HANDLER_RELATIVE_PATH);
|
|
3820
|
+
const project = new import_ts_morph18.Project({
|
|
3821
|
+
tsConfigFilePath: import_path19.default.resolve(process.cwd(), "tsconfig.json"),
|
|
3098
3822
|
skipAddingFilesFromTsConfig: false
|
|
3099
3823
|
});
|
|
3100
3824
|
const sourceFile = project.getSourceFile(rolesHandlerPath);
|
|
@@ -3143,7 +3867,7 @@ async function main14() {
|
|
|
3143
3867
|
|
|
3144
3868
|
// src/migrations/v2.0/remove-hearth-migrations.ts
|
|
3145
3869
|
var fs2 = __toESM(require("fs"));
|
|
3146
|
-
var
|
|
3870
|
+
var import_path20 = __toESM(require("path"));
|
|
3147
3871
|
var PATHS_TO_REMOVE = [
|
|
3148
3872
|
{
|
|
3149
3873
|
relativePath: "src/migrations/hearth",
|
|
@@ -3155,9 +3879,9 @@ var PATHS_TO_REMOVE = [
|
|
|
3155
3879
|
},
|
|
3156
3880
|
{ relativePath: "src/utils/hearth-helpers.ts", label: "Hearth helpers file" }
|
|
3157
3881
|
];
|
|
3158
|
-
async function
|
|
3882
|
+
async function main20() {
|
|
3159
3883
|
for (const { relativePath, label } of PATHS_TO_REMOVE) {
|
|
3160
|
-
const absolutePath =
|
|
3884
|
+
const absolutePath = import_path20.default.join(process.cwd(), relativePath);
|
|
3161
3885
|
if (fs2.existsSync(absolutePath)) {
|
|
3162
3886
|
fs2.rmSync(absolutePath, { recursive: true, force: true });
|
|
3163
3887
|
console.log(`Removed ${label} '${relativePath}'.`);
|
|
@@ -3168,9 +3892,9 @@ async function main15() {
|
|
|
3168
3892
|
}
|
|
3169
3893
|
|
|
3170
3894
|
// src/migrations/v2.0/create-events-index.ts
|
|
3171
|
-
var
|
|
3172
|
-
var
|
|
3173
|
-
var
|
|
3895
|
+
var import_ts_morph19 = require("ts-morph");
|
|
3896
|
+
var import_fs2 = __toESM(require("fs"));
|
|
3897
|
+
var import_path21 = __toESM(require("path"));
|
|
3174
3898
|
var DEFINE_CONFIG_NAME5 = "defineConfig";
|
|
3175
3899
|
var HANDLER_FUNCTION_NAMES = /* @__PURE__ */ new Set([
|
|
3176
3900
|
"getCustomEventsHandler",
|
|
@@ -3192,7 +3916,7 @@ var LICENSE_HEADER = `/*
|
|
|
3192
3916
|
`;
|
|
3193
3917
|
function findEventConfigExports(project, srcDir) {
|
|
3194
3918
|
const found = [];
|
|
3195
|
-
const eventsIndexAbs =
|
|
3919
|
+
const eventsIndexAbs = import_path21.default.join(srcDir, "events", "index.ts");
|
|
3196
3920
|
for (const sourceFile of project.getSourceFiles()) {
|
|
3197
3921
|
const filePath = sourceFile.getFilePath();
|
|
3198
3922
|
if (!filePath.startsWith(srcDir) || filePath.includes("/node_modules/")) {
|
|
@@ -3204,10 +3928,10 @@ function findEventConfigExports(project, srcDir) {
|
|
|
3204
3928
|
for (const decl of statement.getDeclarations()) {
|
|
3205
3929
|
const initializer = decl.getInitializer();
|
|
3206
3930
|
if (!initializer) continue;
|
|
3207
|
-
const unwrapped =
|
|
3208
|
-
if (!
|
|
3931
|
+
const unwrapped = import_ts_morph19.Node.isAsExpression(initializer) ? initializer.getExpression() : initializer;
|
|
3932
|
+
if (!import_ts_morph19.Node.isCallExpression(unwrapped)) continue;
|
|
3209
3933
|
const callee = unwrapped.getExpression();
|
|
3210
|
-
if (!
|
|
3934
|
+
if (!import_ts_morph19.Node.isIdentifier(callee)) continue;
|
|
3211
3935
|
if (callee.getText() !== DEFINE_CONFIG_NAME5) continue;
|
|
3212
3936
|
found.push({ name: decl.getName(), filePath });
|
|
3213
3937
|
}
|
|
@@ -3216,8 +3940,8 @@ function findEventConfigExports(project, srcDir) {
|
|
|
3216
3940
|
return found;
|
|
3217
3941
|
}
|
|
3218
3942
|
function buildIndexImportSpecifier(eventConfigFilePath, srcDir) {
|
|
3219
|
-
const eventsIndexDir =
|
|
3220
|
-
let rel =
|
|
3943
|
+
const eventsIndexDir = import_path21.default.join(srcDir, "events");
|
|
3944
|
+
let rel = import_path21.default.relative(eventsIndexDir, eventConfigFilePath).split(import_path21.default.sep).join("/");
|
|
3221
3945
|
if (rel.endsWith(".ts")) rel = rel.slice(0, -".ts".length);
|
|
3222
3946
|
if (rel.endsWith("/index")) rel = rel.slice(0, -"/index".length);
|
|
3223
3947
|
if (!rel.startsWith(".")) rel = "./" + rel;
|
|
@@ -3294,17 +4018,17 @@ function modifyHandler(sourceFile, exportNames) {
|
|
|
3294
4018
|
);
|
|
3295
4019
|
}
|
|
3296
4020
|
for (const call of sourceFile.getDescendantsOfKind(
|
|
3297
|
-
|
|
4021
|
+
import_ts_morph19.SyntaxKind.CallExpression
|
|
3298
4022
|
)) {
|
|
3299
4023
|
const callee = call.getExpression();
|
|
3300
|
-
if (!
|
|
4024
|
+
if (!import_ts_morph19.Node.isPropertyAccessExpression(callee)) continue;
|
|
3301
4025
|
if (callee.getName() !== RESPONSE_METHOD_NAME) continue;
|
|
3302
4026
|
const args = call.getArguments();
|
|
3303
4027
|
if (args.length !== 1) continue;
|
|
3304
4028
|
const [arg] = args;
|
|
3305
|
-
if (!
|
|
4029
|
+
if (!import_ts_morph19.Node.isArrayLiteralExpression(arg)) continue;
|
|
3306
4030
|
if (arg.getElements().length === 0) continue;
|
|
3307
|
-
if (!arg.getElements().every((el) =>
|
|
4031
|
+
if (!arg.getElements().every((el) => import_ts_morph19.Node.isIdentifier(el))) continue;
|
|
3308
4032
|
arg.replaceWithText(EVENT_CONFIGS_IDENTIFIER);
|
|
3309
4033
|
changes.push(
|
|
3310
4034
|
`rewrote h.response([...]) \u2192 h.response(${EVENT_CONFIGS_IDENTIFIER})`
|
|
@@ -3312,13 +4036,13 @@ function modifyHandler(sourceFile, exportNames) {
|
|
|
3312
4036
|
}
|
|
3313
4037
|
return changes;
|
|
3314
4038
|
}
|
|
3315
|
-
async function
|
|
3316
|
-
const
|
|
3317
|
-
const srcDir =
|
|
4039
|
+
async function main21() {
|
|
4040
|
+
const cwd = process.cwd();
|
|
4041
|
+
const srcDir = import_path21.default.join(cwd, "src");
|
|
3318
4042
|
console.log(`Scanning for defineConfig event exports in: ${srcDir}
|
|
3319
4043
|
`);
|
|
3320
|
-
const project = new
|
|
3321
|
-
tsConfigFilePath:
|
|
4044
|
+
const project = new import_ts_morph19.Project({
|
|
4045
|
+
tsConfigFilePath: import_path21.default.resolve(srcDir, "../tsconfig.json"),
|
|
3322
4046
|
skipAddingFilesFromTsConfig: false
|
|
3323
4047
|
});
|
|
3324
4048
|
const eventConfigExports = findEventConfigExports(project, srcDir);
|
|
@@ -3330,15 +4054,15 @@ async function main16() {
|
|
|
3330
4054
|
}
|
|
3331
4055
|
console.log(`Found ${eventConfigExports.length} event config export(s):`);
|
|
3332
4056
|
for (const e of eventConfigExports) {
|
|
3333
|
-
console.log(` ${e.name} \u2190 ${
|
|
4057
|
+
console.log(` ${e.name} \u2190 ${import_path21.default.relative(cwd, e.filePath)}`);
|
|
3334
4058
|
}
|
|
3335
|
-
const eventsIndexAbs =
|
|
3336
|
-
const eventsIndexRel =
|
|
3337
|
-
if (
|
|
4059
|
+
const eventsIndexAbs = import_path21.default.join(srcDir, "events", "index.ts");
|
|
4060
|
+
const eventsIndexRel = import_path21.default.relative(cwd, eventsIndexAbs);
|
|
4061
|
+
if (import_fs2.default.existsSync(eventsIndexAbs)) {
|
|
3338
4062
|
console.log(`
|
|
3339
4063
|
[${eventsIndexRel}] already exists \u2014 leaving untouched.`);
|
|
3340
4064
|
} else {
|
|
3341
|
-
|
|
4065
|
+
import_fs2.default.mkdirSync(import_path21.default.dirname(eventsIndexAbs), { recursive: true });
|
|
3342
4066
|
const source = buildEventsIndexSource(eventConfigExports, srcDir);
|
|
3343
4067
|
const eventsIndexFile = project.createSourceFile(eventsIndexAbs, source, {
|
|
3344
4068
|
overwrite: false
|
|
@@ -3359,7 +4083,7 @@ No event-config handler file found (looked for exported function(s): ${Array.fro
|
|
|
3359
4083
|
);
|
|
3360
4084
|
return;
|
|
3361
4085
|
}
|
|
3362
|
-
const handlerRelPath =
|
|
4086
|
+
const handlerRelPath = import_path21.default.relative(cwd, handler.getFilePath());
|
|
3363
4087
|
const exportNameSet = new Set(eventConfigExports.map((e) => e.name));
|
|
3364
4088
|
const changes = modifyHandler(handler, exportNameSet);
|
|
3365
4089
|
if (changes.length === 0) {
|
|
@@ -3379,12 +4103,13 @@ var UPSTREAM_URL = "https://github.com/opencrvs/opencrvs-countryconfig.git";
|
|
|
3379
4103
|
var UPSTREAM_BRANCH = "develop";
|
|
3380
4104
|
var TEMP_REMOTE = "opencrvs-upgrade-v19-v20-codemod";
|
|
3381
4105
|
var FILES_TO_CHECKOUT = [
|
|
3382
|
-
"
|
|
3383
|
-
"
|
|
4106
|
+
"src/analytics/analytics.ts",
|
|
4107
|
+
"Dockerfile",
|
|
4108
|
+
"Dockerfile.assets"
|
|
3384
4109
|
];
|
|
3385
4110
|
function runGit(args, { silent = false } = {}) {
|
|
3386
4111
|
return (0, import_child_process.execFileSync)("git", args, {
|
|
3387
|
-
cwd:
|
|
4112
|
+
cwd: process.cwd(),
|
|
3388
4113
|
encoding: "utf8",
|
|
3389
4114
|
stdio: silent ? ["ignore", "pipe", "pipe"] : ["ignore", "pipe", "inherit"]
|
|
3390
4115
|
});
|
|
@@ -3400,11 +4125,11 @@ function tryGit(args) {
|
|
|
3400
4125
|
function assertIsGitRepo() {
|
|
3401
4126
|
if (!tryGit(["rev-parse", "--is-inside-work-tree"])) {
|
|
3402
4127
|
throw new Error(
|
|
3403
|
-
|
|
4128
|
+
`${process.cwd()} is not a git repository. Initialise git (or run the upgrade inside a git checkout) before re-running.`
|
|
3404
4129
|
);
|
|
3405
4130
|
}
|
|
3406
4131
|
}
|
|
3407
|
-
async function
|
|
4132
|
+
async function main22() {
|
|
3408
4133
|
console.log(
|
|
3409
4134
|
`Checking out ${FILES_TO_CHECKOUT.length} file(s) from ${UPSTREAM_URL}@${UPSTREAM_BRANCH}...
|
|
3410
4135
|
`
|
|
@@ -3452,10 +4177,356 @@ async function main17() {
|
|
|
3452
4177
|
}
|
|
3453
4178
|
}
|
|
3454
4179
|
|
|
4180
|
+
// src/migrations/v2.0/add-resend-invite-notification.ts
|
|
4181
|
+
var import_fs3 = require("fs");
|
|
4182
|
+
var import_path22 = __toESM(require("path"));
|
|
4183
|
+
var import_ts_morph20 = require("ts-morph");
|
|
4184
|
+
var TS_MORPH_PROJECT_OPTIONS = {
|
|
4185
|
+
skipAddingFilesFromTsConfig: true,
|
|
4186
|
+
manipulationSettings: {
|
|
4187
|
+
indentationText: import_ts_morph20.IndentationText.TwoSpaces
|
|
4188
|
+
}
|
|
4189
|
+
};
|
|
4190
|
+
var EMAIL_TEMPLATES_INDEX = "src/api/notification/email-templates/index.ts";
|
|
4191
|
+
var NOTIFICATION_HANDLER = "src/api/notification/handler.ts";
|
|
4192
|
+
var USER_NOTIFICATION_ROUTES = "src/config/routes/userNotificationRoutes.ts";
|
|
4193
|
+
var SMS_SERVICE = "src/api/notification/sms-service.ts";
|
|
4194
|
+
var NOTIFICATION_CSV = "src/translations/notification.csv";
|
|
4195
|
+
var RESEND_INVITE_HTML = "src/api/notification/email-templates/other/resend-invite.html";
|
|
4196
|
+
var RESEND_INVITE_HTML_CONTENT = `<!doctype html>
|
|
4197
|
+
<html>
|
|
4198
|
+
<head>
|
|
4199
|
+
<link
|
|
4200
|
+
href="https://fonts.googleapis.com/css2?family=Noto+Sans:wght@400;700&display=swap"
|
|
4201
|
+
rel="stylesheet"
|
|
4202
|
+
/>
|
|
4203
|
+
<style type="text/css">
|
|
4204
|
+
body {
|
|
4205
|
+
font-family: 'Noto Sans', sans-serif;
|
|
4206
|
+
color: #222;
|
|
4207
|
+
padding: 16px 24px;
|
|
4208
|
+
}
|
|
4209
|
+
|
|
4210
|
+
h1 {
|
|
4211
|
+
font-size: 21px;
|
|
4212
|
+
margin-top: 32px;
|
|
4213
|
+
margin-bottom: 36px;
|
|
4214
|
+
font-weight: 700;
|
|
4215
|
+
}
|
|
4216
|
+
|
|
4217
|
+
p {
|
|
4218
|
+
font-weight: 400;
|
|
4219
|
+
font-size: 16px;
|
|
4220
|
+
line-height: 1.8;
|
|
4221
|
+
margin-bottom: 24px;
|
|
4222
|
+
}
|
|
4223
|
+
|
|
4224
|
+
i {
|
|
4225
|
+
color: #666;
|
|
4226
|
+
font-weight: 400;
|
|
4227
|
+
font-size: 16px;
|
|
4228
|
+
}
|
|
4229
|
+
</style>
|
|
4230
|
+
</head>
|
|
4231
|
+
|
|
4232
|
+
<body>
|
|
4233
|
+
<img
|
|
4234
|
+
src="{{countryLogo}}"
|
|
4235
|
+
alt="country_logo"
|
|
4236
|
+
style="max-height: 88px; max-width: 100%"
|
|
4237
|
+
/>
|
|
4238
|
+
<h1>Your {{applicationName}} account invitation</h1>
|
|
4239
|
+
<p>Hello {{firstname}},</p>
|
|
4240
|
+
<p>Your account invitation has been resent. Please use the following credentials to access your account:</p>
|
|
4241
|
+
<p>
|
|
4242
|
+
Username: <strong>{{username}}</strong><br />
|
|
4243
|
+
Password: <strong>{{temporaryPassword}}</strong>
|
|
4244
|
+
</p>
|
|
4245
|
+
<p>
|
|
4246
|
+
Please click the link below to complete your account setup and start using
|
|
4247
|
+
{{applicationName}}.
|
|
4248
|
+
</p>
|
|
4249
|
+
|
|
4250
|
+
<div style="margin-top: 32px; margin-bottom: 32px">
|
|
4251
|
+
<a href="{{loginURL}}">Complete setup</a>
|
|
4252
|
+
</div>
|
|
4253
|
+
<br />
|
|
4254
|
+
<p>
|
|
4255
|
+
Best regards, <br />
|
|
4256
|
+
{{applicationName}} Team
|
|
4257
|
+
</p>
|
|
4258
|
+
</body>
|
|
4259
|
+
</html>
|
|
4260
|
+
`;
|
|
4261
|
+
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";
|
|
4262
|
+
function getObjectLiteralFromConst(declaration) {
|
|
4263
|
+
if (!declaration) {
|
|
4264
|
+
return;
|
|
4265
|
+
}
|
|
4266
|
+
const initializer = declaration.getInitializer();
|
|
4267
|
+
if (!initializer) {
|
|
4268
|
+
return;
|
|
4269
|
+
}
|
|
4270
|
+
if (import_ts_morph20.Node.isObjectLiteralExpression(initializer)) {
|
|
4271
|
+
return initializer;
|
|
4272
|
+
}
|
|
4273
|
+
if (import_ts_morph20.Node.isAsExpression(initializer)) {
|
|
4274
|
+
const expression = initializer.getExpression();
|
|
4275
|
+
if (import_ts_morph20.Node.isObjectLiteralExpression(expression)) {
|
|
4276
|
+
return expression;
|
|
4277
|
+
}
|
|
4278
|
+
}
|
|
4279
|
+
if (import_ts_morph20.Node.isSatisfiesExpression(initializer)) {
|
|
4280
|
+
const expression = initializer.getExpression();
|
|
4281
|
+
if (import_ts_morph20.Node.isObjectLiteralExpression(expression)) {
|
|
4282
|
+
return expression;
|
|
4283
|
+
}
|
|
4284
|
+
}
|
|
4285
|
+
}
|
|
4286
|
+
function patchEmailTemplatesIndex() {
|
|
4287
|
+
const full = import_path22.default.join(process.cwd(), EMAIL_TEMPLATES_INDEX);
|
|
4288
|
+
if (!(0, import_fs3.existsSync)(full)) {
|
|
4289
|
+
console.log(` '${EMAIL_TEMPLATES_INDEX}' missing \u2014 skipping.`);
|
|
4290
|
+
return false;
|
|
4291
|
+
}
|
|
4292
|
+
const project = new import_ts_morph20.Project(TS_MORPH_PROJECT_OPTIONS);
|
|
4293
|
+
const sourceFile = project.addSourceFileAtPath(full);
|
|
4294
|
+
let changed = false;
|
|
4295
|
+
const triggerVariableObject = getObjectLiteralFromConst(
|
|
4296
|
+
sourceFile.getVariableDeclaration("TriggerVariable")
|
|
4297
|
+
);
|
|
4298
|
+
if (triggerVariableObject) {
|
|
4299
|
+
const hasResendInviteVariable = triggerVariableObject.getProperties().some((prop) => prop.getText().includes("[TriggerEvent.RESEND_INVITE]"));
|
|
4300
|
+
if (!hasResendInviteVariable) {
|
|
4301
|
+
const properties = triggerVariableObject.getProperties();
|
|
4302
|
+
const lastProperty = properties[properties.length - 1];
|
|
4303
|
+
if (lastProperty) {
|
|
4304
|
+
sourceFile.insertText(
|
|
4305
|
+
lastProperty.getEnd(),
|
|
4306
|
+
`,
|
|
4307
|
+
[TriggerEvent.RESEND_INVITE]: z.object({
|
|
4308
|
+
firstname: z.string(),
|
|
4309
|
+
username: z.string(),
|
|
4310
|
+
temporaryPassword: z.string(),
|
|
4311
|
+
completeSetupUrl: z.string(),
|
|
4312
|
+
loginURL: z.string()
|
|
4313
|
+
})`
|
|
4314
|
+
);
|
|
4315
|
+
changed = true;
|
|
4316
|
+
}
|
|
4317
|
+
}
|
|
4318
|
+
}
|
|
4319
|
+
const templatesObject = getObjectLiteralFromConst(
|
|
4320
|
+
sourceFile.getVariableDeclaration("templates")
|
|
4321
|
+
);
|
|
4322
|
+
if (templatesObject) {
|
|
4323
|
+
const hasResendInviteTemplate = templatesObject.getProperties().some(
|
|
4324
|
+
(prop) => prop.getText().includes("readOtherTemplate<TriggerVariable['resend-invite']>")
|
|
4325
|
+
);
|
|
4326
|
+
if (!hasResendInviteTemplate) {
|
|
4327
|
+
const userCreatedProp = templatesObject.getProperties().find((prop) => prop.getText().includes("[TriggerEvent.USER_CREATED]"));
|
|
4328
|
+
const anchor = userCreatedProp ?? templatesObject.getProperties()[templatesObject.getProperties().length - 1];
|
|
4329
|
+
if (anchor) {
|
|
4330
|
+
sourceFile.insertText(
|
|
4331
|
+
anchor.getEnd(),
|
|
4332
|
+
`,
|
|
4333
|
+
[TriggerEvent.RESEND_INVITE]: {
|
|
4334
|
+
type: 'resend-invite',
|
|
4335
|
+
subject: 'Your OpenCRVS account invitation',
|
|
4336
|
+
template:
|
|
4337
|
+
readOtherTemplate<TriggerVariable['resend-invite']>('resend-invite')
|
|
4338
|
+
}`
|
|
4339
|
+
);
|
|
4340
|
+
changed = true;
|
|
4341
|
+
}
|
|
4342
|
+
}
|
|
4343
|
+
}
|
|
4344
|
+
if (changed) {
|
|
4345
|
+
sourceFile.saveSync();
|
|
4346
|
+
}
|
|
4347
|
+
return changed;
|
|
4348
|
+
}
|
|
4349
|
+
function patchNotificationHandler() {
|
|
4350
|
+
const full = import_path22.default.join(process.cwd(), NOTIFICATION_HANDLER);
|
|
4351
|
+
if (!(0, import_fs3.existsSync)(full)) {
|
|
4352
|
+
return false;
|
|
4353
|
+
}
|
|
4354
|
+
const project = new import_ts_morph20.Project(TS_MORPH_PROJECT_OPTIONS);
|
|
4355
|
+
const sourceFile = project.addSourceFileAtPath(full);
|
|
4356
|
+
const convertFn = sourceFile.getFunction("convertPayloadToVariable");
|
|
4357
|
+
if (!convertFn) {
|
|
4358
|
+
return false;
|
|
4359
|
+
}
|
|
4360
|
+
const switchStmt = convertFn.getFirstDescendantByKind(
|
|
4361
|
+
import_ts_morph20.SyntaxKind.SwitchStatement
|
|
4362
|
+
);
|
|
4363
|
+
if (!switchStmt) {
|
|
4364
|
+
return false;
|
|
4365
|
+
}
|
|
4366
|
+
const clauses = switchStmt.getCaseBlock().getClauses();
|
|
4367
|
+
const hasResendInvite = clauses.some(
|
|
4368
|
+
(clause) => import_ts_morph20.Node.isCaseClause(clause) && clause.getExpression().getText() === "TriggerEvent.RESEND_INVITE"
|
|
4369
|
+
);
|
|
4370
|
+
if (hasResendInvite) {
|
|
4371
|
+
return false;
|
|
4372
|
+
}
|
|
4373
|
+
const userCreatedClauseIndex = clauses.findIndex(
|
|
4374
|
+
(clause) => import_ts_morph20.Node.isCaseClause(clause) && clause.getExpression().getText() === "TriggerEvent.USER_CREATED"
|
|
4375
|
+
);
|
|
4376
|
+
if (userCreatedClauseIndex < 0) {
|
|
4377
|
+
return false;
|
|
4378
|
+
}
|
|
4379
|
+
const userCreatedClause = clauses[userCreatedClauseIndex];
|
|
4380
|
+
sourceFile.insertText(
|
|
4381
|
+
userCreatedClause.getEnd(),
|
|
4382
|
+
`
|
|
4383
|
+
|
|
4384
|
+
case TriggerEvent.RESEND_INVITE:
|
|
4385
|
+
return {
|
|
4386
|
+
firstname,
|
|
4387
|
+
username: payload.username,
|
|
4388
|
+
temporaryPassword: payload.temporaryPassword,
|
|
4389
|
+
completeSetupUrl: LOGIN_URL,
|
|
4390
|
+
loginURL: LOGIN_URL
|
|
4391
|
+
}`
|
|
4392
|
+
);
|
|
4393
|
+
sourceFile.saveSync();
|
|
4394
|
+
return true;
|
|
4395
|
+
}
|
|
4396
|
+
function getReturnedArrayLiteral(functionFilePath, fnName) {
|
|
4397
|
+
const project = new import_ts_morph20.Project(TS_MORPH_PROJECT_OPTIONS);
|
|
4398
|
+
const sourceFile = project.addSourceFileAtPath(functionFilePath);
|
|
4399
|
+
const fn = sourceFile.getFunction(fnName);
|
|
4400
|
+
const returnStmt = fn?.getFirstDescendantByKind(import_ts_morph20.SyntaxKind.ReturnStatement);
|
|
4401
|
+
const expr = returnStmt?.getExpression();
|
|
4402
|
+
if (!expr || !import_ts_morph20.Node.isArrayLiteralExpression(expr)) {
|
|
4403
|
+
return { sourceFile, arrayLiteral: void 0 };
|
|
4404
|
+
}
|
|
4405
|
+
return { sourceFile, arrayLiteral: expr };
|
|
4406
|
+
}
|
|
4407
|
+
function patchUserNotificationRoutes() {
|
|
4408
|
+
const full = import_path22.default.join(process.cwd(), USER_NOTIFICATION_ROUTES);
|
|
4409
|
+
if (!(0, import_fs3.existsSync)(full)) {
|
|
4410
|
+
return false;
|
|
4411
|
+
}
|
|
4412
|
+
const { sourceFile, arrayLiteral } = getReturnedArrayLiteral(
|
|
4413
|
+
full,
|
|
4414
|
+
"getUserNotificationRoutes"
|
|
4415
|
+
);
|
|
4416
|
+
if (!arrayLiteral) {
|
|
4417
|
+
return false;
|
|
4418
|
+
}
|
|
4419
|
+
const elements = arrayLiteral.getElements();
|
|
4420
|
+
const routeExists = elements.some(
|
|
4421
|
+
(element) => element.getText().includes(`path: '/triggers/user/resend-invite'`)
|
|
4422
|
+
);
|
|
4423
|
+
if (routeExists) {
|
|
4424
|
+
return false;
|
|
4425
|
+
}
|
|
4426
|
+
const anchor = elements.find(
|
|
4427
|
+
(element) => element.getText().includes(`path: '/triggers/user/user-created'`)
|
|
4428
|
+
) ?? elements[elements.length - 1];
|
|
4429
|
+
if (!anchor) {
|
|
4430
|
+
return false;
|
|
4431
|
+
}
|
|
4432
|
+
sourceFile.insertText(
|
|
4433
|
+
anchor.getEnd(),
|
|
4434
|
+
`,
|
|
4435
|
+
{
|
|
4436
|
+
method: 'POST',
|
|
4437
|
+
path: '/triggers/user/resend-invite',
|
|
4438
|
+
handler: makeNotificationHandler('resend-invite'),
|
|
4439
|
+
options: {
|
|
4440
|
+
auth: false,
|
|
4441
|
+
tags: ['api'],
|
|
4442
|
+
description: 'Handles notification for resent user invite'
|
|
4443
|
+
}
|
|
4444
|
+
}`
|
|
4445
|
+
);
|
|
4446
|
+
sourceFile.saveSync();
|
|
4447
|
+
return true;
|
|
4448
|
+
}
|
|
4449
|
+
function patchSmsService() {
|
|
4450
|
+
const full = import_path22.default.join(process.cwd(), SMS_SERVICE);
|
|
4451
|
+
if (!(0, import_fs3.existsSync)(full)) {
|
|
4452
|
+
return false;
|
|
4453
|
+
}
|
|
4454
|
+
const project = new import_ts_morph20.Project(TS_MORPH_PROJECT_OPTIONS);
|
|
4455
|
+
const sourceFile = project.addSourceFileAtPath(full);
|
|
4456
|
+
let changed = false;
|
|
4457
|
+
const otherTemplatesObject = getObjectLiteralFromConst(
|
|
4458
|
+
sourceFile.getVariableDeclaration("otherTemplates")
|
|
4459
|
+
);
|
|
4460
|
+
if (otherTemplatesObject) {
|
|
4461
|
+
const hasResendTemplate = otherTemplatesObject.getProperties().some((prop) => prop.getText().includes("resendInviteNotification"));
|
|
4462
|
+
if (!hasResendTemplate) {
|
|
4463
|
+
const userCredentialsIndex = otherTemplatesObject.getProperties().findIndex((prop) => prop.getText().includes("userCredentialsNotification"));
|
|
4464
|
+
otherTemplatesObject.insertPropertyAssignment(
|
|
4465
|
+
userCredentialsIndex >= 0 ? userCredentialsIndex + 1 : otherTemplatesObject.getProperties().length,
|
|
4466
|
+
{
|
|
4467
|
+
name: "resendInviteNotification",
|
|
4468
|
+
initializer: `'resendInviteNotification'`
|
|
4469
|
+
}
|
|
4470
|
+
);
|
|
4471
|
+
changed = true;
|
|
4472
|
+
}
|
|
4473
|
+
}
|
|
4474
|
+
const triggerToSmsTemplateObject = getObjectLiteralFromConst(
|
|
4475
|
+
sourceFile.getVariableDeclaration("TriggerToSMSTemplate")
|
|
4476
|
+
);
|
|
4477
|
+
if (triggerToSmsTemplateObject) {
|
|
4478
|
+
const hasResendInviteMap = triggerToSmsTemplateObject.getProperties().some((prop) => prop.getText().includes(`['resend-invite']`));
|
|
4479
|
+
if (!hasResendInviteMap) {
|
|
4480
|
+
const userCreatedIndex = triggerToSmsTemplateObject.getProperties().findIndex((prop) => prop.getText().includes(`['user-created']`));
|
|
4481
|
+
triggerToSmsTemplateObject.insertPropertyAssignment(
|
|
4482
|
+
userCreatedIndex >= 0 ? userCreatedIndex + 1 : triggerToSmsTemplateObject.getProperties().length,
|
|
4483
|
+
{
|
|
4484
|
+
name: `['resend-invite']`,
|
|
4485
|
+
initializer: `'resendInviteNotification'`
|
|
4486
|
+
}
|
|
4487
|
+
);
|
|
4488
|
+
changed = true;
|
|
4489
|
+
}
|
|
4490
|
+
}
|
|
4491
|
+
if (changed) {
|
|
4492
|
+
sourceFile.saveSync();
|
|
4493
|
+
}
|
|
4494
|
+
return changed;
|
|
4495
|
+
}
|
|
4496
|
+
async function main23() {
|
|
4497
|
+
console.log("Adding RESEND_INVITE notification wiring\u2026");
|
|
4498
|
+
const touched = [];
|
|
4499
|
+
if (patchEmailTemplatesIndex()) touched.push(EMAIL_TEMPLATES_INDEX);
|
|
4500
|
+
if (patchNotificationHandler()) touched.push(NOTIFICATION_HANDLER);
|
|
4501
|
+
if (patchUserNotificationRoutes()) touched.push(USER_NOTIFICATION_ROUTES);
|
|
4502
|
+
if (patchSmsService()) touched.push(SMS_SERVICE);
|
|
4503
|
+
const csvPath = import_path22.default.join(process.cwd(), NOTIFICATION_CSV);
|
|
4504
|
+
if ((0, import_fs3.existsSync)(csvPath)) {
|
|
4505
|
+
let t = (0, import_fs3.readFileSync)(csvPath, "utf8");
|
|
4506
|
+
if (!/^resendInviteNotification,/m.test(t)) {
|
|
4507
|
+
if (!t.endsWith("\n")) t += "\n";
|
|
4508
|
+
(0, import_fs3.writeFileSync)(csvPath, t + CSV_ROW);
|
|
4509
|
+
touched.push(NOTIFICATION_CSV);
|
|
4510
|
+
}
|
|
4511
|
+
}
|
|
4512
|
+
const htmlPath = import_path22.default.join(process.cwd(), RESEND_INVITE_HTML);
|
|
4513
|
+
(0, import_fs3.mkdirSync)(import_path22.default.dirname(htmlPath), { recursive: true });
|
|
4514
|
+
if (!(0, import_fs3.existsSync)(htmlPath)) {
|
|
4515
|
+
(0, import_fs3.writeFileSync)(htmlPath, RESEND_INVITE_HTML_CONTENT);
|
|
4516
|
+
touched.push(RESEND_INVITE_HTML);
|
|
4517
|
+
}
|
|
4518
|
+
if (touched.length === 0) {
|
|
4519
|
+
console.log(" Nothing to update (already present or anchors not found).");
|
|
4520
|
+
return;
|
|
4521
|
+
}
|
|
4522
|
+
console.log(` Updated:
|
|
4523
|
+
${touched.map((f) => ` - ${f}`).join("\n")}`);
|
|
4524
|
+
}
|
|
4525
|
+
|
|
3455
4526
|
// src/migrations/v2.0/simplify-analytics-precalculations.ts
|
|
3456
|
-
var
|
|
3457
|
-
var
|
|
3458
|
-
var
|
|
4527
|
+
var import_ts_morph21 = require("ts-morph");
|
|
4528
|
+
var import_fs4 = __toESM(require("fs"));
|
|
4529
|
+
var import_path23 = __toESM(require("path"));
|
|
3459
4530
|
var ANALYTICS_FILE_REL = "src/analytics/analytics.ts";
|
|
3460
4531
|
var FUNCTION_NAME = "precalculateAdditionalAnalytics";
|
|
3461
4532
|
var IMPORT_NAMES_TO_REMOVE = /* @__PURE__ */ new Set(["Event", "precalculateBirthEvent"]);
|
|
@@ -3491,10 +4562,10 @@ function findPrecalculateFunction(sourceFile) {
|
|
|
3491
4562
|
return void 0;
|
|
3492
4563
|
}
|
|
3493
4564
|
function getFunctionBodyBlock(fn) {
|
|
3494
|
-
if (
|
|
4565
|
+
if (import_ts_morph21.Node.isFunctionDeclaration(fn)) return fn.getBody();
|
|
3495
4566
|
const initializer = fn.getInitializer();
|
|
3496
4567
|
if (!initializer) return void 0;
|
|
3497
|
-
if (!
|
|
4568
|
+
if (!import_ts_morph21.Node.isArrowFunction(initializer) && !import_ts_morph21.Node.isFunctionExpression(initializer)) {
|
|
3498
4569
|
return void 0;
|
|
3499
4570
|
}
|
|
3500
4571
|
return initializer.getBody();
|
|
@@ -3504,9 +4575,9 @@ function simplifyPrecalculateFunction(sourceFile) {
|
|
|
3504
4575
|
const fn = findPrecalculateFunction(sourceFile);
|
|
3505
4576
|
if (!fn) return log;
|
|
3506
4577
|
const body = getFunctionBodyBlock(fn);
|
|
3507
|
-
if (!body || !
|
|
4578
|
+
if (!body || !import_ts_morph21.Node.isBlock(body)) return log;
|
|
3508
4579
|
for (const statement of [...body.getStatements()]) {
|
|
3509
|
-
const references = statement.getDescendantsOfKind(
|
|
4580
|
+
const references = statement.getDescendantsOfKind(import_ts_morph21.SyntaxKind.Identifier).some((id) => IMPORT_NAMES_TO_REMOVE.has(id.getText()));
|
|
3510
4581
|
if (references) {
|
|
3511
4582
|
statement.remove();
|
|
3512
4583
|
log.push(`removed statement in ${FUNCTION_NAME} referencing removed imports`);
|
|
@@ -3514,7 +4585,7 @@ function simplifyPrecalculateFunction(sourceFile) {
|
|
|
3514
4585
|
}
|
|
3515
4586
|
const remaining = body.getStatements();
|
|
3516
4587
|
const last = remaining[remaining.length - 1];
|
|
3517
|
-
const alreadyCorrect = last &&
|
|
4588
|
+
const alreadyCorrect = last && import_ts_morph21.Node.isReturnStatement(last) && last.getExpression()?.getText() === RETURN_EXPRESSION_TEXT;
|
|
3518
4589
|
if (!alreadyCorrect) {
|
|
3519
4590
|
body.addStatements(`return ${RETURN_EXPRESSION_TEXT}`);
|
|
3520
4591
|
log.push(
|
|
@@ -3523,17 +4594,17 @@ function simplifyPrecalculateFunction(sourceFile) {
|
|
|
3523
4594
|
}
|
|
3524
4595
|
return log;
|
|
3525
4596
|
}
|
|
3526
|
-
async function
|
|
3527
|
-
const
|
|
3528
|
-
const absPath =
|
|
3529
|
-
if (!
|
|
4597
|
+
async function main24() {
|
|
4598
|
+
const cwd = process.cwd();
|
|
4599
|
+
const absPath = import_path23.default.join(cwd, ANALYTICS_FILE_REL);
|
|
4600
|
+
if (!import_fs4.default.existsSync(absPath)) {
|
|
3530
4601
|
console.log(
|
|
3531
4602
|
`[${ANALYTICS_FILE_REL}] does not exist \u2014 nothing to clean up.`
|
|
3532
4603
|
);
|
|
3533
4604
|
return;
|
|
3534
4605
|
}
|
|
3535
|
-
const project = new
|
|
3536
|
-
tsConfigFilePath:
|
|
4606
|
+
const project = new import_ts_morph21.Project({
|
|
4607
|
+
tsConfigFilePath: import_path23.default.resolve(cwd, "tsconfig.json"),
|
|
3537
4608
|
skipAddingFilesFromTsConfig: false
|
|
3538
4609
|
});
|
|
3539
4610
|
const sourceFile = project.getSourceFile(absPath);
|
|
@@ -3560,26 +4631,158 @@ async function main18() {
|
|
|
3560
4631
|
Saved ${ANALYTICS_FILE_REL}.`);
|
|
3561
4632
|
}
|
|
3562
4633
|
|
|
3563
|
-
// src/migrations/v2.0/
|
|
3564
|
-
var
|
|
3565
|
-
|
|
3566
|
-
|
|
3567
|
-
|
|
4634
|
+
// src/migrations/v2.0/merge-infrastructure-directory.ts
|
|
4635
|
+
var import_child_process2 = require("child_process");
|
|
4636
|
+
var import_fs5 = require("fs");
|
|
4637
|
+
var import_os = require("os");
|
|
4638
|
+
var import_path24 = require("path");
|
|
4639
|
+
var TEMP_REMOTE2 = "opencrvs-upgrade-v19-v20-codemod-merge-infra";
|
|
4640
|
+
var INFRASTRUCTURE_DIR = "infrastructure";
|
|
4641
|
+
var BASE_BRANCH = "release-v1.9";
|
|
4642
|
+
function gitShowBytes(ref, path23) {
|
|
4643
|
+
try {
|
|
4644
|
+
const buf = (0, import_child_process2.execFileSync)("git", ["show", `${ref}:${path23}`], {
|
|
4645
|
+
cwd: process.cwd(),
|
|
4646
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
4647
|
+
});
|
|
4648
|
+
return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
4649
|
+
} catch {
|
|
4650
|
+
return null;
|
|
3568
4651
|
}
|
|
3569
|
-
return cwd;
|
|
3570
4652
|
}
|
|
3571
|
-
async function
|
|
3572
|
-
|
|
3573
|
-
|
|
3574
|
-
|
|
4653
|
+
async function main25() {
|
|
4654
|
+
console.log(
|
|
4655
|
+
`Merging '${INFRASTRUCTURE_DIR}/' from ${UPSTREAM_URL}@${UPSTREAM_BRANCH} (base: ${BASE_BRANCH})...
|
|
4656
|
+
`
|
|
4657
|
+
);
|
|
4658
|
+
assertIsGitRepo();
|
|
4659
|
+
tryGit(["remote", "remove", TEMP_REMOTE2]);
|
|
4660
|
+
try {
|
|
4661
|
+
console.log(` Adding temporary remote '${TEMP_REMOTE2}' \u2192 ${UPSTREAM_URL}`);
|
|
4662
|
+
runGit(["remote", "add", TEMP_REMOTE2, UPSTREAM_URL], { silent: true });
|
|
4663
|
+
console.log(
|
|
4664
|
+
` Fetching ${TEMP_REMOTE2}/{${UPSTREAM_BRANCH},${BASE_BRANCH}} (depth 1)...`
|
|
4665
|
+
);
|
|
4666
|
+
runGit(["fetch", "--depth=1", TEMP_REMOTE2, UPSTREAM_BRANCH, BASE_BRANCH]);
|
|
4667
|
+
const ref = `${TEMP_REMOTE2}/${UPSTREAM_BRANCH}`;
|
|
4668
|
+
const baseRef = `${TEMP_REMOTE2}/${BASE_BRANCH}`;
|
|
4669
|
+
const upstreamFiles = runGit(
|
|
4670
|
+
[
|
|
4671
|
+
"ls-tree",
|
|
4672
|
+
"-r",
|
|
4673
|
+
"--name-only",
|
|
4674
|
+
"-z",
|
|
4675
|
+
ref,
|
|
4676
|
+
"--",
|
|
4677
|
+
`${INFRASTRUCTURE_DIR}/`
|
|
4678
|
+
],
|
|
4679
|
+
{ silent: true }
|
|
4680
|
+
).split("\0").filter(Boolean);
|
|
4681
|
+
if (upstreamFiles.length === 0) {
|
|
4682
|
+
console.log(
|
|
4683
|
+
` No files found under '${INFRASTRUCTURE_DIR}/' on ${ref}. Nothing to merge.`
|
|
4684
|
+
);
|
|
4685
|
+
return;
|
|
4686
|
+
}
|
|
4687
|
+
const tmpDir = (0, import_fs5.mkdtempSync)((0, import_path24.join)((0, import_os.tmpdir)(), "opencrvs-merge-infra-"));
|
|
4688
|
+
const baseTmp = (0, import_path24.join)(tmpDir, "base");
|
|
4689
|
+
const theirsTmp = (0, import_path24.join)(tmpDir, "theirs");
|
|
4690
|
+
let added = 0;
|
|
4691
|
+
let merged = 0;
|
|
4692
|
+
const conflictedFiles = [];
|
|
4693
|
+
for (const file of upstreamFiles) {
|
|
4694
|
+
const fullPath = (0, import_path24.join)(process.cwd(), file);
|
|
4695
|
+
if (!(0, import_fs5.existsSync)(fullPath)) {
|
|
4696
|
+
if (tryGit(["checkout", ref, "--", file])) {
|
|
4697
|
+
console.log(` + ${file} (new from upstream)`);
|
|
4698
|
+
added++;
|
|
4699
|
+
} else {
|
|
4700
|
+
console.warn(` [warn] failed to add new file ${file}`);
|
|
4701
|
+
}
|
|
4702
|
+
continue;
|
|
4703
|
+
}
|
|
4704
|
+
const theirContents = gitShowBytes(ref, file);
|
|
4705
|
+
if (theirContents === null) {
|
|
4706
|
+
console.warn(` [warn] could not read ${file} from ${ref} \u2014 skipping.`);
|
|
4707
|
+
continue;
|
|
4708
|
+
}
|
|
4709
|
+
(0, import_fs5.writeFileSync)(theirsTmp, theirContents);
|
|
4710
|
+
const baseContents = gitShowBytes(baseRef, file);
|
|
4711
|
+
(0, import_fs5.writeFileSync)(baseTmp, baseContents ?? new Uint8Array(0));
|
|
4712
|
+
try {
|
|
4713
|
+
(0, import_child_process2.execFileSync)("git", ["merge-file", fullPath, baseTmp, theirsTmp], {
|
|
4714
|
+
cwd: process.cwd(),
|
|
4715
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
4716
|
+
});
|
|
4717
|
+
runGit(["add", "--", file], { silent: true });
|
|
4718
|
+
merged++;
|
|
4719
|
+
} catch (err) {
|
|
4720
|
+
const status = err.status;
|
|
4721
|
+
if (typeof status === "number" && status > 0) {
|
|
4722
|
+
conflictedFiles.push(file);
|
|
4723
|
+
console.warn(
|
|
4724
|
+
` ! ${file} (${status} conflict${status > 1 ? "s" : ""})`
|
|
4725
|
+
);
|
|
4726
|
+
} else {
|
|
4727
|
+
conflictedFiles.push(file);
|
|
4728
|
+
console.warn(
|
|
4729
|
+
` [warn] merge failed for ${file} (likely binary or unreadable) \u2014 left untouched.`
|
|
4730
|
+
);
|
|
4731
|
+
}
|
|
4732
|
+
}
|
|
4733
|
+
}
|
|
4734
|
+
console.log(
|
|
4735
|
+
`
|
|
4736
|
+
Done. ${added} added, ${merged} merged cleanly, ${conflictedFiles.length} with conflicts.`
|
|
4737
|
+
);
|
|
4738
|
+
if (conflictedFiles.length > 0) {
|
|
4739
|
+
console.warn(
|
|
4740
|
+
`
|
|
4741
|
+
NOTE: ${conflictedFiles.length} file(s) under '${INFRASTRUCTURE_DIR}/' have merge conflicts that you must resolve manually.
|
|
4742
|
+
Look for the standard conflict markers (<<<<<<<, =======, >>>>>>>) in:
|
|
4743
|
+
` + conflictedFiles.map((f) => ` - ${f}`).join("\n") + `
|
|
4744
|
+
After resolving, stage the fixes with: git add ${INFRASTRUCTURE_DIR}/`
|
|
4745
|
+
);
|
|
4746
|
+
}
|
|
4747
|
+
} finally {
|
|
4748
|
+
if (tryGit(["remote", "remove", TEMP_REMOTE2])) {
|
|
4749
|
+
console.log(` Removed temporary remote '${TEMP_REMOTE2}'.`);
|
|
4750
|
+
}
|
|
3575
4751
|
}
|
|
3576
|
-
|
|
4752
|
+
}
|
|
4753
|
+
|
|
4754
|
+
// src/migrations/v2.0/delete-infrastructure-directory.ts
|
|
4755
|
+
var import_fs6 = require("fs");
|
|
4756
|
+
var import_path25 = require("path");
|
|
4757
|
+
var INFRASTRUCTURE_DIR2 = "infrastructure";
|
|
4758
|
+
async function main26() {
|
|
4759
|
+
const fullPath = (0, import_path25.join)(process.cwd(), INFRASTRUCTURE_DIR2);
|
|
4760
|
+
if (!(0, import_fs6.existsSync)(fullPath)) {
|
|
3577
4761
|
console.log(
|
|
3578
|
-
|
|
4762
|
+
`'${INFRASTRUCTURE_DIR2}/' not found in ${process.cwd()} \u2014 nothing to delete.`
|
|
3579
4763
|
);
|
|
3580
|
-
|
|
4764
|
+
return;
|
|
3581
4765
|
}
|
|
3582
|
-
|
|
4766
|
+
console.log(`Deleting '${INFRASTRUCTURE_DIR2}/'...
|
|
4767
|
+
`);
|
|
4768
|
+
assertIsGitRepo();
|
|
4769
|
+
runGit(["rm", "-rf", "--ignore-unmatch", "--", `${INFRASTRUCTURE_DIR2}/`], {
|
|
4770
|
+
silent: true
|
|
4771
|
+
});
|
|
4772
|
+
console.log(` Staged deletion of tracked files under '${INFRASTRUCTURE_DIR2}/'.`);
|
|
4773
|
+
if ((0, import_fs6.existsSync)(fullPath)) {
|
|
4774
|
+
(0, import_fs6.rmSync)(fullPath, { recursive: true, force: true });
|
|
4775
|
+
console.log(` Removed remaining untracked files under '${INFRASTRUCTURE_DIR2}/'.`);
|
|
4776
|
+
}
|
|
4777
|
+
console.log(
|
|
4778
|
+
`
|
|
4779
|
+
Done. Review the staged deletion with: git diff --cached -- '${INFRASTRUCTURE_DIR2}/'`
|
|
4780
|
+
);
|
|
4781
|
+
}
|
|
4782
|
+
|
|
4783
|
+
// src/migrations/v2.0/index.ts
|
|
4784
|
+
async function runUpgrade(dockerSwarm) {
|
|
4785
|
+
await main18();
|
|
3583
4786
|
await main();
|
|
3584
4787
|
await main2();
|
|
3585
4788
|
await main3();
|
|
@@ -3592,9 +4795,20 @@ async function runUpgrade(ccwd) {
|
|
|
3592
4795
|
await main10();
|
|
3593
4796
|
await main11();
|
|
3594
4797
|
await main12();
|
|
4798
|
+
await main13();
|
|
3595
4799
|
await main14();
|
|
3596
4800
|
await main15();
|
|
3597
4801
|
await main16();
|
|
4802
|
+
await main19();
|
|
4803
|
+
await main20();
|
|
4804
|
+
await main21();
|
|
4805
|
+
await main22();
|
|
4806
|
+
await main23();
|
|
4807
|
+
await main24();
|
|
3598
4808
|
await main17();
|
|
3599
|
-
|
|
4809
|
+
if (dockerSwarm) {
|
|
4810
|
+
await main25();
|
|
4811
|
+
} else {
|
|
4812
|
+
await main26();
|
|
4813
|
+
}
|
|
3600
4814
|
}
|