@opencrvs/toolkit 2.0.0-rc.3855fe8 → 2.0.0-rc.3c7efd6

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.
Files changed (78) hide show
  1. package/dist/application-config/index.js +11 -10
  2. package/dist/cli.js +1394 -152
  3. package/dist/commons/api/router.d.ts +45 -68
  4. package/dist/commons/conditionals/conditionals.d.ts +6 -6
  5. package/dist/commons/events/FieldConfig.d.ts +10 -0
  6. package/dist/conditionals/index.js +11 -10
  7. package/dist/events/index.js +11 -10
  8. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts.map +1 -1
  9. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.js +3 -4
  10. package/dist/migrations/v2.0/add-resend-invite-notification.d.ts +3 -0
  11. package/dist/migrations/v2.0/add-resend-invite-notification.d.ts.map +1 -0
  12. package/dist/migrations/v2.0/add-resend-invite-notification.js +373 -0
  13. package/dist/migrations/v2.0/checkout-upstream-files.d.ts +19 -0
  14. package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +1 -1
  15. package/dist/migrations/v2.0/checkout-upstream-files.js +17 -13
  16. package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts.map +1 -1
  17. package/dist/migrations/v2.0/convert-config-files-to-ts.js +4 -5
  18. package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts.map +1 -1
  19. package/dist/migrations/v2.0/convert-paragraph-to-heading.js +4 -5
  20. package/dist/migrations/v2.0/create-events-index.d.ts.map +1 -1
  21. package/dist/migrations/v2.0/create-events-index.js +1 -2
  22. package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts +3 -0
  23. package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts.map +1 -0
  24. package/dist/migrations/v2.0/delete-infrastructure-directory.js +77 -0
  25. package/dist/migrations/v2.0/index.d.ts +8 -4
  26. package/dist/migrations/v2.0/index.d.ts.map +1 -1
  27. package/dist/migrations/v2.0/index.js +1362 -149
  28. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts.map +1 -1
  29. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.js +5 -6
  30. package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts +3 -0
  31. package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts.map +1 -0
  32. package/dist/migrations/v2.0/merge-infrastructure-directory.js +221 -0
  33. package/dist/migrations/v2.0/migrate-application-config-url.d.ts +3 -0
  34. package/dist/migrations/v2.0/migrate-application-config-url.d.ts.map +1 -0
  35. package/dist/migrations/v2.0/migrate-application-config-url.js +342 -0
  36. package/dist/migrations/v2.0/migrate-scopes.d.ts.map +1 -1
  37. package/dist/migrations/v2.0/migrate-scopes.js +6 -7
  38. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts.map +1 -1
  39. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.js +3 -4
  40. package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts.map +1 -1
  41. package/dist/migrations/v2.0/migrate-workqueue-configs.js +3 -4
  42. package/dist/migrations/v2.0/remove-delete-actions.d.ts.map +1 -1
  43. package/dist/migrations/v2.0/remove-delete-actions.js +3 -4
  44. package/dist/migrations/v2.0/remove-demo-scope.d.ts.map +1 -1
  45. package/dist/migrations/v2.0/remove-demo-scope.js +2 -3
  46. package/dist/migrations/v2.0/remove-deprecated-imports.d.ts.map +1 -1
  47. package/dist/migrations/v2.0/remove-deprecated-imports.js +3 -4
  48. package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts +3 -0
  49. package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts.map +1 -0
  50. package/dist/migrations/v2.0/remove-fhir-url-helpers.js +163 -0
  51. package/dist/migrations/v2.0/remove-hearth-migrations.d.ts.map +1 -1
  52. package/dist/migrations/v2.0/remove-hearth-migrations.js +1 -2
  53. package/dist/migrations/v2.0/remove-old-statistics-service.d.ts +3 -0
  54. package/dist/migrations/v2.0/remove-old-statistics-service.d.ts.map +1 -0
  55. package/dist/migrations/v2.0/remove-old-statistics-service.js +356 -0
  56. package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts.map +1 -1
  57. package/dist/migrations/v2.0/remove-pending-certification-flag.js +3 -4
  58. package/dist/migrations/v2.0/remove-review-from-register-action.d.ts.map +1 -1
  59. package/dist/migrations/v2.0/remove-review-from-register-action.js +3 -4
  60. package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts +3 -0
  61. package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts.map +1 -0
  62. package/dist/migrations/v2.0/remove-unused-environment-variables.js +186 -0
  63. package/dist/migrations/v2.0/rename-api-paths.d.ts.map +1 -1
  64. package/dist/migrations/v2.0/rename-api-paths.js +3 -4
  65. package/dist/migrations/v2.0/rename-location-parent-id.d.ts.map +1 -1
  66. package/dist/migrations/v2.0/rename-location-parent-id.js +3 -4
  67. package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts.map +1 -1
  68. package/dist/migrations/v2.0/simplify-analytics-precalculations.js +1 -2
  69. package/dist/migrations/v2.0/update-package-json.d.ts +3 -0
  70. package/dist/migrations/v2.0/update-package-json.d.ts.map +1 -0
  71. package/dist/migrations/v2.0/update-package-json.js +105 -0
  72. package/dist/notification/index.js +11 -10
  73. package/dist/scopes/index.d.ts +8 -1
  74. package/dist/scopes/index.js +11 -10
  75. package/opencrvs-toolkit-2.0.0-rc.3c7efd6.tgz +0 -0
  76. package/package.json +1 -1
  77. package/tsconfig.tsbuildinfo +1 -1
  78. package/opencrvs-toolkit-2.0.0-rc.3855fe8.tgz +0 -0
package/dist/cli.js CHANGED
@@ -91,7 +91,7 @@ function processFile(filePath, project) {
91
91
  if (wasRemoved) {
92
92
  removedCount++;
93
93
  console.log(
94
- ` [${import_path.default.relative(getCwd(), filePath)}] Removed 'review' from REGISTER action`
94
+ ` [${import_path.default.relative(process.cwd(), filePath)}] Removed 'review' from REGISTER action`
95
95
  );
96
96
  }
97
97
  }
@@ -99,7 +99,7 @@ function processFile(filePath, project) {
99
99
  return removedCount;
100
100
  }
101
101
  async function main() {
102
- const srcDir = import_path.default.join(getCwd(), "src");
102
+ const srcDir = import_path.default.join(process.cwd(), "src");
103
103
  console.log(`Scanning for defineConfig calls in: ${srcDir}
104
104
  `);
105
105
  const project = new import_ts_morph.Project({
@@ -135,7 +135,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
135
135
  for (const filePath of modifiedFiles) {
136
136
  const sourceFile = project.getSourceFileOrThrow(filePath);
137
137
  await sourceFile.save();
138
- console.log(` Saved: ${import_path.default.relative(getCwd(), filePath)}`);
138
+ console.log(` Saved: ${import_path.default.relative(process.cwd(), filePath)}`);
139
139
  }
140
140
  console.log(
141
141
  `
@@ -338,7 +338,7 @@ function processFile2(filePath, project) {
338
338
  const eventType = resolveEventType(configArg);
339
339
  if (!eventType) {
340
340
  console.warn(
341
- ` [${import_path2.default.relative(getCwd(), configArg.getSourceFile().getFilePath())}] Could not resolve root 'type' from defineConfig \u2014 skipping auditHistoryLabel id generation`
341
+ ` [${import_path2.default.relative(process.cwd(), configArg.getSourceFile().getFilePath())}] Could not resolve root 'type' from defineConfig \u2014 skipping auditHistoryLabel id generation`
342
342
  );
343
343
  }
344
344
  let fileNeedsImports = false;
@@ -354,7 +354,7 @@ function processFile2(filePath, project) {
354
354
  fileNeedsImports = true;
355
355
  configHadValidateAction = true;
356
356
  console.log(
357
- ` [${import_path2.default.relative(getCwd(), filePath)}] Transformed VALIDATE action to CUSTOM with customActionType: '${VALIDATE_DECLARATION_VALUE}'`
357
+ ` [${import_path2.default.relative(process.cwd(), filePath)}] Transformed VALIDATE action to CUSTOM with customActionType: '${VALIDATE_DECLARATION_VALUE}'`
358
358
  );
359
359
  }
360
360
  }
@@ -375,7 +375,7 @@ function processFile2(filePath, project) {
375
375
  ]`
376
376
  });
377
377
  console.log(
378
- ` [${import_path2.default.relative(getCwd(), filePath)}] Added top-level 'flags' array to defineConfig`
378
+ ` [${import_path2.default.relative(process.cwd(), filePath)}] Added top-level 'flags' array to defineConfig`
379
379
  );
380
380
  }
381
381
  if (fileNeedsImports) {
@@ -385,7 +385,7 @@ function processFile2(filePath, project) {
385
385
  return transformedCount;
386
386
  }
387
387
  async function main2() {
388
- const srcDir = import_path2.default.join(getCwd(), "src");
388
+ const srcDir = import_path2.default.join(process.cwd(), "src");
389
389
  console.log(`Scanning for defineConfig calls in: ${srcDir}
390
390
  `);
391
391
  const project = new import_ts_morph2.Project({
@@ -420,7 +420,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
420
420
  for (const filePath of modifiedFiles) {
421
421
  const sourceFile = project.getSourceFileOrThrow(filePath);
422
422
  await sourceFile.save();
423
- console.log(` Saved: ${import_path2.default.relative(getCwd(), filePath)}`);
423
+ console.log(` Saved: ${import_path2.default.relative(process.cwd(), filePath)}`);
424
424
  }
425
425
  console.log(
426
426
  `
@@ -491,14 +491,14 @@ function processFile3(filePath, project) {
491
491
  actionsInitializer.removeElement(index);
492
492
  removedCount++;
493
493
  console.log(
494
- ` [${import_path3.default.relative(getCwd(), filePath)}] Removed DELETE action at index ${index}`
494
+ ` [${import_path3.default.relative(process.cwd(), filePath)}] Removed DELETE action at index ${index}`
495
495
  );
496
496
  }
497
497
  }
498
498
  return removedCount;
499
499
  }
500
500
  async function main3() {
501
- const srcDir = import_path3.default.join(getCwd(), "src");
501
+ const srcDir = import_path3.default.join(process.cwd(), "src");
502
502
  console.log(`Scanning for defineConfig calls in: ${srcDir}
503
503
  `);
504
504
  const project = new import_ts_morph3.Project({
@@ -533,7 +533,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
533
533
  for (const filePath of modifiedFiles) {
534
534
  const sourceFile = project.getSourceFileOrThrow(filePath);
535
535
  await sourceFile.save();
536
- console.log(` Saved: ${import_path3.default.relative(getCwd(), filePath)}`);
536
+ console.log(` Saved: ${import_path3.default.relative(process.cwd(), filePath)}`);
537
537
  }
538
538
  console.log(
539
539
  `
@@ -607,19 +607,19 @@ function processFile4(filePath, project) {
607
607
  if (result === "converted-to-heading") {
608
608
  changedCount++;
609
609
  console.log(
610
- ` [${import_path4.default.relative(getCwd(), filePath)}] Converted PARAGRAPH with heading fontVariant to HEADING`
610
+ ` [${import_path4.default.relative(process.cwd(), filePath)}] Converted PARAGRAPH with heading fontVariant to HEADING`
611
611
  );
612
612
  } else if (result === "removed-font-variant") {
613
613
  changedCount++;
614
614
  console.log(
615
- ` [${import_path4.default.relative(getCwd(), filePath)}] Removed non-heading fontVariant from PARAGRAPH`
615
+ ` [${import_path4.default.relative(process.cwd(), filePath)}] Removed non-heading fontVariant from PARAGRAPH`
616
616
  );
617
617
  }
618
618
  }
619
619
  return changedCount;
620
620
  }
621
621
  async function main4() {
622
- const srcDir = import_path4.default.join(getCwd(), "src");
622
+ const srcDir = import_path4.default.join(process.cwd(), "src");
623
623
  console.log(`Scanning for FieldType.PARAGRAPH fields in: ${srcDir}
624
624
  `);
625
625
  const project = new import_ts_morph4.Project({
@@ -653,7 +653,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
653
653
  for (const filePath of modifiedFiles) {
654
654
  const sourceFile = project.getSourceFileOrThrow(filePath);
655
655
  await sourceFile.save();
656
- console.log(` Saved: ${import_path4.default.relative(getCwd(), filePath)}`);
656
+ console.log(` Saved: ${import_path4.default.relative(process.cwd(), filePath)}`);
657
657
  }
658
658
  console.log(`
659
659
  Done. Processed ${totalChanged} FieldType.PARAGRAPH field(s).`);
@@ -803,7 +803,7 @@ function processFile5(filePath, project) {
803
803
  if (changed > 0) {
804
804
  migratedCount += changed;
805
805
  console.log(
806
- ` [${import_path5.default.relative(getCwd(), filePath)}] Migrated ${changed} clause(s): VALIDATED status \u2192 flags.anyOf`
806
+ ` [${import_path5.default.relative(process.cwd(), filePath)}] Migrated ${changed} clause(s): VALIDATED status \u2192 flags.anyOf`
807
807
  );
808
808
  }
809
809
  }
@@ -811,7 +811,7 @@ function processFile5(filePath, project) {
811
811
  return migratedCount;
812
812
  }
813
813
  async function main5() {
814
- const srcDir = import_path5.default.join(getCwd(), "src");
814
+ const srcDir = import_path5.default.join(process.cwd(), "src");
815
815
  console.log(`Scanning for defineWorkqueues calls in: ${srcDir}
816
816
  `);
817
817
  const project = new import_ts_morph5.Project({
@@ -845,7 +845,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
845
845
  for (const filePath of modifiedFiles) {
846
846
  const sourceFile = project.getSourceFileOrThrow(filePath);
847
847
  await sourceFile.save();
848
- console.log(` Saved: ${import_path5.default.relative(getCwd(), filePath)}`);
848
+ console.log(` Saved: ${import_path5.default.relative(process.cwd(), filePath)}`);
849
849
  }
850
850
  console.log(
851
851
  `
@@ -1063,7 +1063,7 @@ function processFile6(filePath, project) {
1063
1063
  const sourceFile = project.getSourceFile(filePath);
1064
1064
  if (!sourceFile) return 0;
1065
1065
  let totalChanges = 0;
1066
- const relPath = import_path6.default.relative(getCwd(), filePath);
1066
+ const relPath = import_path6.default.relative(process.cwd(), filePath);
1067
1067
  const callExpressions = sourceFile.getDescendantsOfKind(
1068
1068
  import_ts_morph6.SyntaxKind.CallExpression
1069
1069
  );
@@ -1104,7 +1104,7 @@ function processFile6(filePath, project) {
1104
1104
  return totalChanges;
1105
1105
  }
1106
1106
  async function main6() {
1107
- const srcDir = import_path6.default.join(getCwd(), "src");
1107
+ const srcDir = import_path6.default.join(process.cwd(), "src");
1108
1108
  console.log(
1109
1109
  `Scanning for birth defineConfig and PRINT_CERTIFICATE workqueues in: ${srcDir}
1110
1110
  `
@@ -1140,7 +1140,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
1140
1140
  for (const filePath of modifiedFiles) {
1141
1141
  const sourceFile = project.getSourceFileOrThrow(filePath);
1142
1142
  await sourceFile.save();
1143
- console.log(` Saved: ${import_path6.default.relative(getCwd(), filePath)}`);
1143
+ console.log(` Saved: ${import_path6.default.relative(process.cwd(), filePath)}`);
1144
1144
  }
1145
1145
  console.log(
1146
1146
  `
@@ -1177,14 +1177,14 @@ function processFile7(filePath, project) {
1177
1177
  array3.removeElement(index);
1178
1178
  removedCount++;
1179
1179
  console.log(
1180
- ` [${import_path7.default.relative(getCwd(), filePath)}] Removed InherentFlags.PENDING_CERTIFICATION from array`
1180
+ ` [${import_path7.default.relative(process.cwd(), filePath)}] Removed InherentFlags.PENDING_CERTIFICATION from array`
1181
1181
  );
1182
1182
  }
1183
1183
  }
1184
1184
  return removedCount;
1185
1185
  }
1186
1186
  async function main7() {
1187
- const srcDir = import_path7.default.join(getCwd(), "src");
1187
+ const srcDir = import_path7.default.join(process.cwd(), "src");
1188
1188
  console.log(
1189
1189
  `Scanning for InherentFlags.PENDING_CERTIFICATION array elements in: ${srcDir}
1190
1190
  `
@@ -1220,7 +1220,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
1220
1220
  for (const filePath of modifiedFiles) {
1221
1221
  const sourceFile = project.getSourceFileOrThrow(filePath);
1222
1222
  await sourceFile.save();
1223
- console.log(` Saved: ${import_path7.default.relative(getCwd(), filePath)}`);
1223
+ console.log(` Saved: ${import_path7.default.relative(process.cwd(), filePath)}`);
1224
1224
  }
1225
1225
  console.log(
1226
1226
  `
@@ -1278,13 +1278,13 @@ function processFile8(filePath, project) {
1278
1278
  propAccess.getNameNode().replaceWithText(NEW_PROPERTY_NAME);
1279
1279
  renamedCount++;
1280
1280
  console.log(
1281
- ` [${import_path8.default.relative(getCwd(), filePath)}] Renamed Location.${OLD_PROPERTY_NAME} \u2192 Location.${NEW_PROPERTY_NAME}`
1281
+ ` [${import_path8.default.relative(process.cwd(), filePath)}] Renamed Location.${OLD_PROPERTY_NAME} \u2192 Location.${NEW_PROPERTY_NAME}`
1282
1282
  );
1283
1283
  }
1284
1284
  return renamedCount;
1285
1285
  }
1286
1286
  async function main8() {
1287
- const srcDir = import_path8.default.join(getCwd(), "src");
1287
+ const srcDir = import_path8.default.join(process.cwd(), "src");
1288
1288
  console.log(
1289
1289
  `Scanning for Location.${OLD_PROPERTY_NAME} references in: ${srcDir}
1290
1290
  `
@@ -1320,7 +1320,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
1320
1320
  for (const filePath of modifiedFiles) {
1321
1321
  const sourceFile = project.getSourceFileOrThrow(filePath);
1322
1322
  await sourceFile.save();
1323
- console.log(` Saved: ${import_path8.default.relative(getCwd(), filePath)}`);
1323
+ console.log(` Saved: ${import_path8.default.relative(process.cwd(), filePath)}`);
1324
1324
  }
1325
1325
  console.log(
1326
1326
  `
@@ -1387,7 +1387,7 @@ function processFile9(filePath, project) {
1387
1387
  const sourceFile = project.getSourceFile(filePath);
1388
1388
  if (!sourceFile) return 0;
1389
1389
  let renamedCount = 0;
1390
- const relPath = import_path9.default.relative(getCwd(), filePath);
1390
+ const relPath = import_path9.default.relative(process.cwd(), filePath);
1391
1391
  const candidates = sourceFile.getDescendantsOfKind(
1392
1392
  import_ts_morph9.SyntaxKind.ObjectLiteralExpression
1393
1393
  );
@@ -1402,7 +1402,7 @@ function processFile9(filePath, project) {
1402
1402
  return renamedCount;
1403
1403
  }
1404
1404
  async function main9() {
1405
- const srcDir = import_path9.default.join(getCwd(), "src");
1405
+ const srcDir = import_path9.default.join(process.cwd(), "src");
1406
1406
  console.log(`Scanning for Hapi route configs in: ${srcDir}
1407
1407
  `);
1408
1408
  console.log("Active path renames:");
@@ -1439,7 +1439,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
1439
1439
  for (const filePath of modifiedFiles) {
1440
1440
  const sourceFile = project.getSourceFileOrThrow(filePath);
1441
1441
  await sourceFile.save();
1442
- console.log(` Saved: ${import_path9.default.relative(getCwd(), filePath)}`);
1442
+ console.log(` Saved: ${import_path9.default.relative(process.cwd(), filePath)}`);
1443
1443
  }
1444
1444
  console.log(`
1445
1445
  Done. Renamed ${totalRenamed} route path(s).`);
@@ -1813,9 +1813,9 @@ function updateRouteHandlers(sourceFiles, group, srcDir, relCwd) {
1813
1813
  }
1814
1814
  return replacedCount;
1815
1815
  }
1816
- function resolveConfigChain(configObj, path17) {
1816
+ function resolveConfigChain(configObj, path23) {
1817
1817
  let current = configObj;
1818
- for (const key of path17) {
1818
+ for (const key of path23) {
1819
1819
  if (!import_ts_morph10.Node.isObjectLiteralExpression(current)) return null;
1820
1820
  const prop = current.getProperty(key);
1821
1821
  if (!prop || !import_ts_morph10.Node.isPropertyAssignment(prop)) return null;
@@ -1860,8 +1860,8 @@ function ensureJoinImport(sf) {
1860
1860
  });
1861
1861
  }
1862
1862
  async function main10() {
1863
- const srcDir = import_path10.default.join(getCwd(), "src");
1864
- const relCwd = (fp) => import_path10.default.relative(getCwd(), fp);
1863
+ const srcDir = import_path10.default.join(process.cwd(), "src");
1864
+ const relCwd = (fp) => import_path10.default.relative(process.cwd(), fp);
1865
1865
  console.log("Phase 1: Converting JS config files to TypeScript...\n");
1866
1866
  let convertedCount = 0;
1867
1867
  for (const group of CONFIG_GROUPS) {
@@ -1949,7 +1949,7 @@ async function main10() {
1949
1949
  ensureJoinImport(sf);
1950
1950
  }
1951
1951
  console.log(
1952
- ` Inlined applicationConfig.${accessPath.join(".")} \u2192 ${adjustedValue} in ${import_path10.default.relative(getCwd(), sf.getFilePath())}`
1952
+ ` Inlined applicationConfig.${accessPath.join(".")} \u2192 ${adjustedValue} in ${import_path10.default.relative(process.cwd(), sf.getFilePath())}`
1953
1953
  );
1954
1954
  filesToSaveAfterInlining.add(sf);
1955
1955
  madeReplacement = true;
@@ -1961,7 +1961,7 @@ async function main10() {
1961
1961
  for (const sf of Array.from(filesToSaveAfterInlining)) {
1962
1962
  await sf.save();
1963
1963
  console.log(
1964
- ` Saved (inlined): ${import_path10.default.relative(getCwd(), sf.getFilePath())}`
1964
+ ` Saved (inlined): ${import_path10.default.relative(process.cwd(), sf.getFilePath())}`
1965
1965
  );
1966
1966
  }
1967
1967
  for (const prop of [...propsToRemove].reverse()) {
@@ -2137,6 +2137,9 @@ var CustomActionScopeOptions = AllRecordScopeOptions.extend({
2137
2137
  var AccessLevelOptions = z3.object({
2138
2138
  accessLevel: JurisdictionFilter.optional()
2139
2139
  });
2140
+ var AllUserScopeOptions = AccessLevelOptions.extend({
2141
+ role: userRole.optional()
2142
+ });
2140
2143
  var WorkqueueOrDashboardOptions = z3.object({
2141
2144
  ids: z3.preprocess(
2142
2145
  (val) => val === void 0 ? void 0 : [val].flat(),
@@ -2146,6 +2149,7 @@ var WorkqueueOrDashboardOptions = z3.object({
2146
2149
  var AllScopeOptions = z3.object({
2147
2150
  ...AllRecordScopeOptions.shape,
2148
2151
  ...AccessLevelOptions.shape,
2152
+ ...AllUserScopeOptions.shape,
2149
2153
  ...WorkqueueOrDashboardOptions.shape
2150
2154
  });
2151
2155
  var ScopeOptionKey = AllScopeOptions.keyof();
@@ -2222,27 +2226,24 @@ var SystemScopeType = z3.enum([
2222
2226
  "organisation.read-locations",
2223
2227
  "user.read",
2224
2228
  "user.create",
2225
- "user.edit"
2229
+ "user.edit",
2230
+ "user.search"
2226
2231
  ]);
2227
2232
  var UserScopeType = SystemScopeType.extract([
2228
2233
  "user.read",
2229
2234
  "user.create",
2230
- "user.edit"
2235
+ "user.edit",
2236
+ "user.search"
2231
2237
  ]);
2232
2238
  var ScopesWithRoleOption = UserScopeType.extract(["user.edit", "user.create"]);
2233
2239
  var UserScopeV2 = z3.discriminatedUnion("type", [
2234
2240
  z3.object({
2235
2241
  type: ScopesWithRoleOption,
2236
- options: z3.object({
2237
- accessLevel: JurisdictionFilter.optional(),
2238
- role: userRole.optional()
2239
- }).optional()
2242
+ options: AllUserScopeOptions.optional()
2240
2243
  }),
2241
2244
  z3.object({
2242
- type: UserScopeType.extract(["user.read"]),
2243
- options: z3.object({
2244
- accessLevel: JurisdictionFilter.optional()
2245
- }).optional()
2245
+ type: UserScopeType.extract(["user.read", "user.search"]),
2246
+ options: AccessLevelOptions.optional()
2246
2247
  })
2247
2248
  ]);
2248
2249
  var ResolvedRecordScopeV2 = z3.discriminatedUnion("type", [
@@ -2607,7 +2608,7 @@ function migrateScopesArrays(rolesFilePath, project) {
2607
2608
  const scopeKey = resolveScopeKeyFromElementAccess(element);
2608
2609
  if (scopeKey && !(scopeKey in SCOPES)) {
2609
2610
  console.warn(
2610
- ` [${import_path11.default.relative(getCwd(), rolesFilePath)}] Removing unknown scope reference: SCOPES.${scopeKey}`
2611
+ ` [${import_path11.default.relative(process.cwd(), rolesFilePath)}] Removing unknown scope reference: SCOPES.${scopeKey}`
2611
2612
  );
2612
2613
  initializer.removeElement(index);
2613
2614
  removedCount++;
@@ -2616,7 +2617,7 @@ function migrateScopesArrays(rolesFilePath, project) {
2616
2617
  const legacyScope = resolveLegacyScopeFromElement(element);
2617
2618
  if (!legacyScope) {
2618
2619
  console.warn(
2619
- ` [${import_path11.default.relative(getCwd(), rolesFilePath)}] Skipping non-literal scope expression: ${element.getText()}`
2620
+ ` [${import_path11.default.relative(process.cwd(), rolesFilePath)}] Skipping non-literal scope expression: ${element.getText()}`
2620
2621
  );
2621
2622
  continue;
2622
2623
  }
@@ -2625,7 +2626,7 @@ function migrateScopesArrays(rolesFilePath, project) {
2625
2626
  const scope = decodeScope(migratedScope);
2626
2627
  if (!scope) {
2627
2628
  console.warn(
2628
- ` [${import_path11.default.relative(getCwd(), rolesFilePath)}] Could not decode migrated scope '${migratedScope}'.`
2629
+ ` [${import_path11.default.relative(process.cwd(), rolesFilePath)}] Could not decode migrated scope '${migratedScope}'.`
2629
2630
  );
2630
2631
  continue;
2631
2632
  }
@@ -2633,14 +2634,14 @@ function migrateScopesArrays(rolesFilePath, project) {
2633
2634
  migratedCount++;
2634
2635
  } catch (error) {
2635
2636
  console.warn(
2636
- ` [${import_path11.default.relative(getCwd(), rolesFilePath)}] Could not migrate scope '${legacyScope}': ${error}`
2637
+ ` [${import_path11.default.relative(process.cwd(), rolesFilePath)}] Could not migrate scope '${legacyScope}': ${error}`
2637
2638
  );
2638
2639
  }
2639
2640
  }
2640
2641
  }
2641
2642
  if (removedCount > 0) {
2642
2643
  console.log(
2643
- ` Removed ${removedCount} unknown SCOPES reference(s) from '${import_path11.default.relative(getCwd(), rolesFilePath)}'.`
2644
+ ` Removed ${removedCount} unknown SCOPES reference(s) from '${import_path11.default.relative(process.cwd(), rolesFilePath)}'.`
2644
2645
  );
2645
2646
  }
2646
2647
  return { migratedCount, removedCount };
@@ -2762,9 +2763,9 @@ function removeRoleTypeDefinitionAndUnusedImports(rolesFilePath, project) {
2762
2763
  return removed;
2763
2764
  }
2764
2765
  async function main11() {
2765
- const cwd2 = getCwd();
2766
- const srcDir = import_path11.default.join(cwd2, "src");
2767
- const rolesFilePath = import_path11.default.join(cwd2, ROLES_FILE_RELATIVE_PATH);
2766
+ const cwd = process.cwd();
2767
+ const srcDir = import_path11.default.join(cwd, "src");
2768
+ const rolesFilePath = import_path11.default.join(cwd, ROLES_FILE_RELATIVE_PATH);
2768
2769
  console.log(`Scanning roles scopes in: ${rolesFilePath}`);
2769
2770
  const project = new import_ts_morph11.Project({
2770
2771
  tsConfigFilePath: import_path11.default.resolve(srcDir, "../tsconfig.json"),
@@ -2828,13 +2829,13 @@ function processFile10(filePath, project) {
2828
2829
  decl.remove();
2829
2830
  }
2830
2831
  console.log(
2831
- ` [${import_path12.default.relative(getCwd(), filePath)}] Removed ${matchingNamedImports.length} deprecated '${DEPRECATED_IMPORT}' import(s) from '${decl.getModuleSpecifierValue()}'`
2832
+ ` [${import_path12.default.relative(process.cwd(), filePath)}] Removed ${matchingNamedImports.length} deprecated '${DEPRECATED_IMPORT}' import(s) from '${decl.getModuleSpecifierValue()}'`
2832
2833
  );
2833
2834
  }
2834
2835
  return removedCount;
2835
2836
  }
2836
2837
  async function main12() {
2837
- const srcDir = import_path12.default.join(getCwd(), "src");
2838
+ const srcDir = import_path12.default.join(process.cwd(), "src");
2838
2839
  console.log(`Scanning for deprecated imports in: ${srcDir}
2839
2840
  `);
2840
2841
  const project = new import_ts_morph12.Project({
@@ -2865,15 +2866,738 @@ async function main12() {
2865
2866
  Saving ${modifiedFiles.length} modified file(s)...`);
2866
2867
  for (const filePath of modifiedFiles) {
2867
2868
  await project.getSourceFileOrThrow(filePath).save();
2868
- console.log(` Saved: ${import_path12.default.relative(getCwd(), filePath)}`);
2869
+ console.log(` Saved: ${import_path12.default.relative(process.cwd(), filePath)}`);
2869
2870
  }
2870
2871
  console.log(`
2871
2872
  Done. Removed ${totalRemoved} deprecated import(s).`);
2872
2873
  }
2873
2874
 
2874
- // src/migrations/v2.0/migrate-workqueue-configs.ts
2875
- var import_ts_morph13 = require("ts-morph");
2875
+ // src/migrations/v2.0/remove-unused-environment-variables.ts
2876
2876
  var import_path13 = __toESM(require("path"));
2877
+ var import_ts_morph13 = require("ts-morph");
2878
+ var UNUSED_ENV_VARS = /* @__PURE__ */ new Set([
2879
+ "APPLICATION_CONFIG_URL",
2880
+ "FHIR_URL",
2881
+ "CONFIRM_REGISTRATION_URL"
2882
+ ]);
2883
+ var ENVIRONMENT_FILE_RELATIVE = "src/environment.ts";
2884
+ var CONSTANTS_FILE_RELATIVE = "src/constants.ts";
2885
+ function cleanEnvironmentFile(project, filePath) {
2886
+ const sourceFile = project.getSourceFile(filePath);
2887
+ if (!sourceFile) return [];
2888
+ const removed = [];
2889
+ const cleanEnvCall = sourceFile.getDescendantsOfKind(import_ts_morph13.SyntaxKind.CallExpression).find((call) => {
2890
+ const expr = call.getExpression();
2891
+ return import_ts_morph13.Node.isIdentifier(expr) && expr.getText() === "cleanEnv";
2892
+ });
2893
+ if (!cleanEnvCall) return removed;
2894
+ const schemaArg = cleanEnvCall.getArguments()[1]?.asKind(import_ts_morph13.SyntaxKind.ObjectLiteralExpression);
2895
+ if (!schemaArg) return removed;
2896
+ for (const name of UNUSED_ENV_VARS) {
2897
+ const prop = schemaArg.getProperty(name);
2898
+ if (!prop) continue;
2899
+ if (prop.isKind(import_ts_morph13.SyntaxKind.PropertyAssignment) || prop.isKind(import_ts_morph13.SyntaxKind.ShorthandPropertyAssignment)) {
2900
+ prop.remove();
2901
+ removed.push(name);
2902
+ }
2903
+ }
2904
+ return removed;
2905
+ }
2906
+ function extractEnvAccess(initText) {
2907
+ if (!initText) return null;
2908
+ const match = /\benv\.([A-Z][A-Z0-9_]*)\b/.exec(initText);
2909
+ return match ? match[1] : null;
2910
+ }
2911
+ function cleanConstantsFile(project, filePath) {
2912
+ const sourceFile = project.getSourceFile(filePath);
2913
+ if (!sourceFile) return [];
2914
+ const removed = [];
2915
+ for (const stmt of [...sourceFile.getVariableStatements()]) {
2916
+ const declarations = [...stmt.getDeclarations()];
2917
+ const declarationsToRemove = declarations.filter((decl) => {
2918
+ const name = decl.getName();
2919
+ const accessedEnvVar = extractEnvAccess(decl.getInitializer()?.getText());
2920
+ return UNUSED_ENV_VARS.has(name) || accessedEnvVar !== null && UNUSED_ENV_VARS.has(accessedEnvVar);
2921
+ });
2922
+ if (declarationsToRemove.length === 0) continue;
2923
+ const namesToRemove = declarationsToRemove.map((decl) => decl.getName());
2924
+ removed.push(...namesToRemove);
2925
+ if (declarationsToRemove.length === declarations.length) {
2926
+ stmt.remove();
2927
+ } else {
2928
+ for (const decl of declarationsToRemove) {
2929
+ decl.remove();
2930
+ }
2931
+ }
2932
+ }
2933
+ return removed;
2934
+ }
2935
+ async function main13() {
2936
+ const project = new import_ts_morph13.Project({
2937
+ tsConfigFilePath: import_path13.default.resolve(process.cwd(), "tsconfig.json"),
2938
+ skipAddingFilesFromTsConfig: false
2939
+ });
2940
+ console.log(
2941
+ `Removing unused environment variable(s) (${[...UNUSED_ENV_VARS].join(", ")})...
2942
+ `
2943
+ );
2944
+ const envFilePath = import_path13.default.join(process.cwd(), ENVIRONMENT_FILE_RELATIVE);
2945
+ const constsFilePath = import_path13.default.join(process.cwd(), CONSTANTS_FILE_RELATIVE);
2946
+ const envRemoved = cleanEnvironmentFile(project, envFilePath);
2947
+ if (envRemoved.length > 0) {
2948
+ await project.getSourceFileOrThrow(envFilePath).save();
2949
+ console.log(
2950
+ ` [${ENVIRONMENT_FILE_RELATIVE}] Removed schema entr${envRemoved.length === 1 ? "y" : "ies"}: ${envRemoved.join(", ")}`
2951
+ );
2952
+ } else if (project.getSourceFile(envFilePath)) {
2953
+ console.log(
2954
+ ` [${ENVIRONMENT_FILE_RELATIVE}] No matching schema entries \u2014 nothing to remove.`
2955
+ );
2956
+ } else {
2957
+ console.log(
2958
+ ` [${ENVIRONMENT_FILE_RELATIVE}] File not found \u2014 skipping.`
2959
+ );
2960
+ }
2961
+ const constsRemoved = cleanConstantsFile(project, constsFilePath);
2962
+ if (constsRemoved.length > 0) {
2963
+ await project.getSourceFileOrThrow(constsFilePath).save();
2964
+ console.log(
2965
+ ` [${CONSTANTS_FILE_RELATIVE}] Removed declaration(s): ${constsRemoved.join(", ")}`
2966
+ );
2967
+ } else if (project.getSourceFile(constsFilePath)) {
2968
+ console.log(
2969
+ ` [${CONSTANTS_FILE_RELATIVE}] No matching declarations \u2014 nothing to remove.`
2970
+ );
2971
+ } else {
2972
+ console.log(` [${CONSTANTS_FILE_RELATIVE}] File not found \u2014 skipping.`);
2973
+ }
2974
+ if (envRemoved.length === 0 && constsRemoved.length === 0) {
2975
+ console.log("\nNothing to do.");
2976
+ return;
2977
+ }
2978
+ console.log(
2979
+ `
2980
+ Done. NOTE: usages of these constants elsewhere in 'src/' may now produce TypeScript errors and need manual review.`
2981
+ );
2982
+ }
2983
+
2984
+ // src/migrations/v2.0/remove-fhir-url-helpers.ts
2985
+ var import_path14 = __toESM(require("path"));
2986
+ var import_ts_morph14 = require("ts-morph");
2987
+ var FHIR_IMPORT = "FHIR_URL";
2988
+ var HELPER_NAMES = /* @__PURE__ */ new Set([
2989
+ "getFromFhir",
2990
+ "updateResourceFromHearth",
2991
+ "updateResourceInHearth"
2992
+ ]);
2993
+ function removeHelpers(sourceFilePath, project) {
2994
+ const sourceFile = project.getSourceFile(sourceFilePath);
2995
+ if (!sourceFile) {
2996
+ return {
2997
+ removedHelpers: [],
2998
+ removedImportCount: 0,
2999
+ remainingFhirReferences: 0
3000
+ };
3001
+ }
3002
+ const removedHelpers = [];
3003
+ let removedImportCount = 0;
3004
+ for (const fn of sourceFile.getFunctions()) {
3005
+ const name = fn.getName();
3006
+ if (!name || !HELPER_NAMES.has(name)) continue;
3007
+ removedHelpers.push(name);
3008
+ fn.remove();
3009
+ }
3010
+ for (const stmt of [...sourceFile.getVariableStatements()]) {
3011
+ const declarations = [...stmt.getDeclarations()];
3012
+ const toRemove = declarations.filter((decl) => HELPER_NAMES.has(decl.getName()));
3013
+ if (toRemove.length === 0) continue;
3014
+ removedHelpers.push(...toRemove.map((decl) => decl.getName()));
3015
+ if (toRemove.length === declarations.length) {
3016
+ stmt.remove();
3017
+ } else {
3018
+ for (const decl of toRemove) decl.remove();
3019
+ }
3020
+ }
3021
+ for (const decl of sourceFile.getImportDeclarations()) {
3022
+ const matches = decl.getNamedImports().filter((ni) => ni.getName() === FHIR_IMPORT);
3023
+ if (matches.length === 0) continue;
3024
+ for (const named of matches) {
3025
+ named.remove();
3026
+ removedImportCount++;
3027
+ }
3028
+ const hasAnyNamedImportsLeft = decl.getNamedImports().length > 0;
3029
+ const hasDefaultImport = !!decl.getDefaultImport();
3030
+ const hasNamespaceImport = !!decl.getNamespaceImport();
3031
+ if (!hasAnyNamedImportsLeft && !hasDefaultImport && !hasNamespaceImport) {
3032
+ decl.remove();
3033
+ }
3034
+ }
3035
+ 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;
3036
+ return { removedHelpers, removedImportCount, remainingFhirReferences };
3037
+ }
3038
+ async function main14() {
3039
+ const project = new import_ts_morph14.Project({
3040
+ tsConfigFilePath: import_path14.default.resolve(process.cwd(), "tsconfig.json"),
3041
+ skipAddingFilesFromTsConfig: false
3042
+ });
3043
+ const sourceFiles = project.getSourceFiles().filter((sf) => {
3044
+ const fp = sf.getFilePath();
3045
+ return fp.includes("/src/") && !fp.includes("/node_modules/");
3046
+ });
3047
+ console.log(`Removing legacy FHIR_URL helpers in ${sourceFiles.length} source file(s)...
3048
+ `);
3049
+ let totalRemovedImports = 0;
3050
+ let totalRemovedHelpers = 0;
3051
+ const modifiedFiles = [];
3052
+ const warnings = [];
3053
+ for (const sourceFile of sourceFiles) {
3054
+ const filePath = sourceFile.getFilePath();
3055
+ const rel = import_path14.default.relative(process.cwd(), filePath);
3056
+ const result = removeHelpers(filePath, project);
3057
+ const changed = result.removedImportCount > 0 || result.removedHelpers.length > 0;
3058
+ if (changed) {
3059
+ modifiedFiles.push(filePath);
3060
+ totalRemovedImports += result.removedImportCount;
3061
+ totalRemovedHelpers += result.removedHelpers.length;
3062
+ if (result.removedHelpers.length > 0) {
3063
+ console.log(
3064
+ ` [${rel}] Removed helper(s): ${result.removedHelpers.join(", ")}`
3065
+ );
3066
+ }
3067
+ if (result.removedImportCount > 0) {
3068
+ console.log(
3069
+ ` [${rel}] Removed ${result.removedImportCount} '${FHIR_IMPORT}' import(s)`
3070
+ );
3071
+ }
3072
+ }
3073
+ if (result.remainingFhirReferences > 0) {
3074
+ warnings.push(
3075
+ `${rel}: ${result.remainingFhirReferences} remaining '${FHIR_IMPORT}' reference(s)`
3076
+ );
3077
+ }
3078
+ }
3079
+ if (modifiedFiles.length === 0 && warnings.length === 0) {
3080
+ console.log("No FHIR_URL imports/helpers found. Nothing to do.");
3081
+ return;
3082
+ }
3083
+ if (modifiedFiles.length > 0) {
3084
+ console.log(`
3085
+ Saving ${modifiedFiles.length} modified file(s)...`);
3086
+ for (const filePath of modifiedFiles) {
3087
+ await project.getSourceFileOrThrow(filePath).save();
3088
+ console.log(` Saved: ${import_path14.default.relative(process.cwd(), filePath)}`);
3089
+ }
3090
+ }
3091
+ if (warnings.length > 0) {
3092
+ console.warn(
3093
+ `
3094
+ WARNING: Some '${FHIR_IMPORT}' usages remain and need manual cleanup:
3095
+ ` + warnings.map((line) => ` - ${line}`).join("\n")
3096
+ );
3097
+ }
3098
+ console.log(
3099
+ `
3100
+ Done. Removed ${totalRemovedHelpers} helper declaration(s) and ${totalRemovedImports} '${FHIR_IMPORT}' import(s).`
3101
+ );
3102
+ }
3103
+
3104
+ // src/migrations/v2.0/migrate-application-config-url.ts
3105
+ var import_path15 = __toESM(require("path"));
3106
+ var import_ts_morph15 = require("ts-morph");
3107
+ var TARGET_IDENTIFIER = "APPLICATION_CONFIG_URL";
3108
+ var REPLACEMENT_IDENTIFIER = "applicationConfig";
3109
+ var REPLACEMENT_MODULE = "@countryconfig/api/application/application-config";
3110
+ var FUNCTION_LIKE_KINDS = [
3111
+ import_ts_morph15.SyntaxKind.FunctionDeclaration,
3112
+ import_ts_morph15.SyntaxKind.FunctionExpression,
3113
+ import_ts_morph15.SyntaxKind.ArrowFunction,
3114
+ import_ts_morph15.SyntaxKind.MethodDeclaration
3115
+ ];
3116
+ function describeFunction(node) {
3117
+ if (import_ts_morph15.Node.isFunctionDeclaration(node) || import_ts_morph15.Node.isMethodDeclaration(node)) {
3118
+ return node.getName() ?? "<anonymous>";
3119
+ }
3120
+ const parent = node.getParent();
3121
+ if (parent && import_ts_morph15.Node.isVariableDeclaration(parent)) {
3122
+ return parent.getName();
3123
+ }
3124
+ if (parent && import_ts_morph15.Node.isPropertyAssignment(parent)) {
3125
+ return parent.getName();
3126
+ }
3127
+ if (import_ts_morph15.Node.isFunctionExpression(node) && node.getNameNode() !== void 0) {
3128
+ return node.getNameNode()?.getText() ?? "<anonymous>";
3129
+ }
3130
+ return "<anonymous>";
3131
+ }
3132
+ function hasBlockBody(node) {
3133
+ if (import_ts_morph15.Node.isFunctionDeclaration(node) || import_ts_morph15.Node.isFunctionExpression(node) || import_ts_morph15.Node.isMethodDeclaration(node)) {
3134
+ return node.getBody() !== void 0;
3135
+ }
3136
+ if (import_ts_morph15.Node.isArrowFunction(node)) {
3137
+ return node.getBody().getKind() === import_ts_morph15.SyntaxKind.Block;
3138
+ }
3139
+ return false;
3140
+ }
3141
+ function isConfigFetcher(node) {
3142
+ let referencesTarget = false;
3143
+ let callsFetch = false;
3144
+ for (const id of node.getDescendantsOfKind(import_ts_morph15.SyntaxKind.Identifier)) {
3145
+ const text = id.getText();
3146
+ if (!referencesTarget && text === TARGET_IDENTIFIER) referencesTarget = true;
3147
+ if (!callsFetch && text === "fetch") {
3148
+ const parent = id.getParent();
3149
+ if (import_ts_morph15.Node.isCallExpression(parent) && parent.getExpression() === id) {
3150
+ callsFetch = true;
3151
+ }
3152
+ }
3153
+ if (referencesTarget && callsFetch) return true;
3154
+ }
3155
+ return false;
3156
+ }
3157
+ function processFile11(sourceFile) {
3158
+ const importsWithTarget = sourceFile.getImportDeclarations().filter(
3159
+ (decl) => decl.getNamedImports().some((ni) => ni.getName() === TARGET_IDENTIFIER)
3160
+ );
3161
+ if (importsWithTarget.length === 0) {
3162
+ return { changed: false, rewrittenFunctions: [], renamedReferences: 0 };
3163
+ }
3164
+ const collidingLocals = sourceFile.getDescendantsOfKind(import_ts_morph15.SyntaxKind.Identifier).filter((id) => id.getText() === REPLACEMENT_IDENTIFIER).filter((id) => {
3165
+ const parent = id.getParent();
3166
+ const kind = parent.getKind();
3167
+ 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;
3168
+ });
3169
+ if (collidingLocals.length > 0) {
3170
+ return {
3171
+ changed: false,
3172
+ rewrittenFunctions: [],
3173
+ renamedReferences: 0,
3174
+ skippedReason: `local declaration named '${REPLACEMENT_IDENTIFIER}' would collide`
3175
+ };
3176
+ }
3177
+ const candidateFunctions = FUNCTION_LIKE_KINDS.flatMap(
3178
+ (kind) => sourceFile.getDescendantsOfKind(kind)
3179
+ );
3180
+ candidateFunctions.sort((a, b) => a.getStart() - b.getStart());
3181
+ const rewrittenFunctions = [];
3182
+ const rewrittenSet = /* @__PURE__ */ new Set();
3183
+ for (const fn of candidateFunctions) {
3184
+ if (!hasBlockBody(fn)) continue;
3185
+ if (!isConfigFetcher(fn)) continue;
3186
+ let inRewrittenAncestor = false;
3187
+ let cursor = fn.getParent();
3188
+ while (cursor) {
3189
+ if (rewrittenSet.has(cursor)) {
3190
+ inRewrittenAncestor = true;
3191
+ break;
3192
+ }
3193
+ cursor = cursor.getParent();
3194
+ }
3195
+ if (inRewrittenAncestor) continue;
3196
+ const start = fn.getStart();
3197
+ const line = sourceFile.getLineAndColumnAtPos(start).line;
3198
+ const name = describeFunction(fn);
3199
+ 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)) {
3200
+ fn.setBodyText(`return ${REPLACEMENT_IDENTIFIER}`);
3201
+ }
3202
+ rewrittenFunctions.push({ name, line });
3203
+ rewrittenSet.add(fn);
3204
+ }
3205
+ for (const decl of importsWithTarget) {
3206
+ const targetNamed = decl.getNamedImports().find((ni) => ni.getName() === TARGET_IDENTIFIER);
3207
+ targetNamed?.remove();
3208
+ const isNowEmpty = decl.getNamedImports().length === 0 && !decl.getDefaultImport() && !decl.getNamespaceImport();
3209
+ if (isNowEmpty) decl.remove();
3210
+ }
3211
+ const existing = sourceFile.getImportDeclaration(
3212
+ (decl) => decl.getModuleSpecifierValue() === REPLACEMENT_MODULE
3213
+ );
3214
+ if (existing) {
3215
+ const alreadyImported = existing.getNamedImports().some((ni) => ni.getName() === REPLACEMENT_IDENTIFIER);
3216
+ if (!alreadyImported) existing.addNamedImport(REPLACEMENT_IDENTIFIER);
3217
+ } else {
3218
+ sourceFile.addImportDeclaration({
3219
+ moduleSpecifier: REPLACEMENT_MODULE,
3220
+ namedImports: [REPLACEMENT_IDENTIFIER]
3221
+ });
3222
+ }
3223
+ 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) => {
3224
+ const parent = id.getParent();
3225
+ const parentKind = parent.getKind();
3226
+ if (parentKind === import_ts_morph15.SyntaxKind.PropertyAccessExpression) {
3227
+ const pae = parent.asKind(import_ts_morph15.SyntaxKind.PropertyAccessExpression);
3228
+ if (pae.getNameNode() === id) return false;
3229
+ }
3230
+ if (parentKind === import_ts_morph15.SyntaxKind.PropertyAssignment) {
3231
+ const pa = parent.asKind(import_ts_morph15.SyntaxKind.PropertyAssignment);
3232
+ if (pa.getNameNode() === id) return false;
3233
+ }
3234
+ if (parentKind === import_ts_morph15.SyntaxKind.ShorthandPropertyAssignment) {
3235
+ return false;
3236
+ }
3237
+ return true;
3238
+ }).sort((a, b) => b.getPos() - a.getPos());
3239
+ for (const id of renameTargets) {
3240
+ id.replaceWithText(REPLACEMENT_IDENTIFIER);
3241
+ }
3242
+ return {
3243
+ changed: true,
3244
+ rewrittenFunctions,
3245
+ renamedReferences: renameTargets.length
3246
+ };
3247
+ }
3248
+ async function main15() {
3249
+ const project = new import_ts_morph15.Project({
3250
+ tsConfigFilePath: import_path15.default.resolve(process.cwd(), "tsconfig.json"),
3251
+ skipAddingFilesFromTsConfig: false
3252
+ });
3253
+ const sourceFiles = project.getSourceFiles().filter((sf) => {
3254
+ const fp = sf.getFilePath();
3255
+ return fp.includes("/src/") && !fp.includes("/node_modules/");
3256
+ });
3257
+ console.log(
3258
+ `Migrating '${TARGET_IDENTIFIER}' \u2192 '${REPLACEMENT_IDENTIFIER}' across ${sourceFiles.length} source file(s)...
3259
+ `
3260
+ );
3261
+ let changedFiles = 0;
3262
+ let totalRewrittenFunctions = 0;
3263
+ let totalRenamedReferences = 0;
3264
+ const skipped = [];
3265
+ for (const sourceFile of sourceFiles) {
3266
+ const filePath = sourceFile.getFilePath();
3267
+ const rel = import_path15.default.relative(process.cwd(), filePath);
3268
+ const result = processFile11(sourceFile);
3269
+ if (result.skippedReason) {
3270
+ skipped.push(`${rel} (${result.skippedReason})`);
3271
+ continue;
3272
+ }
3273
+ if (!result.changed) continue;
3274
+ await sourceFile.save();
3275
+ changedFiles++;
3276
+ totalRewrittenFunctions += result.rewrittenFunctions.length;
3277
+ totalRenamedReferences += result.renamedReferences;
3278
+ for (const fn of result.rewrittenFunctions) {
3279
+ console.log(
3280
+ ` [${rel}:${fn.line}] Rewrote '${fn.name}' body \u2192 'return ${REPLACEMENT_IDENTIFIER}' (config fetch eliminated)`
3281
+ );
3282
+ }
3283
+ if (result.renamedReferences > 0) {
3284
+ console.log(
3285
+ ` [${rel}] Renamed ${result.renamedReferences} stray reference(s) ${TARGET_IDENTIFIER} \u2192 ${REPLACEMENT_IDENTIFIER}`
3286
+ );
3287
+ }
3288
+ }
3289
+ if (skipped.length > 0) {
3290
+ console.warn(
3291
+ `
3292
+ ${skipped.length} file(s) skipped:
3293
+ ` + skipped.map((s) => ` - ${s}`).join("\n")
3294
+ );
3295
+ }
3296
+ if (changedFiles === 0) {
3297
+ console.log(`
3298
+ No files reference '${TARGET_IDENTIFIER}'. Nothing to do.`);
3299
+ return;
3300
+ }
3301
+ console.log(
3302
+ `
3303
+ Done. Updated ${changedFiles} file(s): ${totalRewrittenFunctions} fetch function(s) rewritten, ${totalRenamedReferences} bare reference(s) renamed.`
3304
+ );
3305
+ if (totalRewrittenFunctions > 0) {
3306
+ console.log(
3307
+ `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}'.`
3308
+ );
3309
+ }
3310
+ }
3311
+
3312
+ // src/migrations/v2.0/remove-old-statistics-service.ts
3313
+ var import_path16 = __toESM(require("path"));
3314
+ var import_ts_morph16 = require("ts-morph");
3315
+ var ROUTE_PATH = "/statistics";
3316
+ var HANDLER_NAME = "statisticsHandler";
3317
+ function isStatisticsRouteObject(obj) {
3318
+ const pathProp = obj.getProperty("path");
3319
+ if (!pathProp || !import_ts_morph16.Node.isPropertyAssignment(pathProp)) return false;
3320
+ const init = pathProp.getInitializer();
3321
+ if (!init) return false;
3322
+ if (import_ts_morph16.Node.isStringLiteral(init) || import_ts_morph16.Node.isNoSubstitutionTemplateLiteral(init)) {
3323
+ return init.getLiteralValue() === ROUTE_PATH;
3324
+ }
3325
+ return false;
3326
+ }
3327
+ function removeStatisticsRoutes(sourceFile) {
3328
+ let removed = 0;
3329
+ const callExpressions = [
3330
+ ...sourceFile.getDescendantsOfKind(import_ts_morph16.SyntaxKind.CallExpression)
3331
+ ];
3332
+ for (const call of callExpressions) {
3333
+ if (call.wasForgotten()) continue;
3334
+ const expr = call.getExpression();
3335
+ if (!import_ts_morph16.Node.isPropertyAccessExpression(expr)) continue;
3336
+ if (expr.getName() !== "route") continue;
3337
+ const args2 = call.getArguments();
3338
+ if (args2.length === 0) continue;
3339
+ const firstArg = args2[0];
3340
+ if (import_ts_morph16.Node.isObjectLiteralExpression(firstArg)) {
3341
+ if (!isStatisticsRouteObject(firstArg)) continue;
3342
+ const stmt = call.getFirstAncestorByKind(import_ts_morph16.SyntaxKind.ExpressionStatement);
3343
+ if (stmt) {
3344
+ stmt.remove();
3345
+ removed++;
3346
+ } else {
3347
+ call.replaceWithText("");
3348
+ removed++;
3349
+ }
3350
+ continue;
3351
+ }
3352
+ if (import_ts_morph16.Node.isArrayLiteralExpression(firstArg)) {
3353
+ const matchingIndexes = firstArg.getElements().map((el, idx) => ({ el, idx })).filter(
3354
+ ({ el }) => import_ts_morph16.Node.isObjectLiteralExpression(el) && isStatisticsRouteObject(el)
3355
+ ).map(({ idx }) => idx);
3356
+ matchingIndexes.sort((a, b) => b - a).forEach((idx) => {
3357
+ firstArg.removeElement(idx);
3358
+ removed++;
3359
+ });
3360
+ }
3361
+ }
3362
+ return removed;
3363
+ }
3364
+ function removeStatisticsHandlerImports(sourceFile) {
3365
+ let changed = false;
3366
+ for (const decl of sourceFile.getImportDeclarations()) {
3367
+ const targetNamed = decl.getNamedImports().find((ni) => ni.getName() === HANDLER_NAME);
3368
+ if (!targetNamed) continue;
3369
+ targetNamed.remove();
3370
+ changed = true;
3371
+ const isNowEmpty = decl.getNamedImports().length === 0 && !decl.getDefaultImport() && !decl.getNamespaceImport();
3372
+ if (isNowEmpty) decl.remove();
3373
+ }
3374
+ return changed;
3375
+ }
3376
+ function processFile12(sourceFile) {
3377
+ const routesRemoved = removeStatisticsRoutes(sourceFile);
3378
+ const importsCleaned = removeStatisticsHandlerImports(sourceFile);
3379
+ return { routesRemoved, importsCleaned };
3380
+ }
3381
+ function collectLocalImportsInSubtree(sourceFile, subtreeRoot) {
3382
+ const result = [];
3383
+ for (const decl of sourceFile.getImportDeclarations()) {
3384
+ const moduleSf = decl.getModuleSpecifierSourceFile();
3385
+ if (!moduleSf) continue;
3386
+ const fp = moduleSf.getFilePath();
3387
+ if (!fp.startsWith(subtreeRoot)) continue;
3388
+ result.push(fp);
3389
+ }
3390
+ return result;
3391
+ }
3392
+ function deleteOrphanedDescendants(project, startingFile, subtreeRoot) {
3393
+ const initialCandidates = collectLocalImportsInSubtree(
3394
+ startingFile,
3395
+ subtreeRoot
3396
+ );
3397
+ const startingPath = startingFile.getFilePath();
3398
+ const deleted = /* @__PURE__ */ new Set([startingPath]);
3399
+ const seen = /* @__PURE__ */ new Set();
3400
+ const worklist = [...initialCandidates];
3401
+ const orphans = [];
3402
+ while (worklist.length > 0) {
3403
+ const candidate = worklist.shift();
3404
+ if (seen.has(candidate)) continue;
3405
+ seen.add(candidate);
3406
+ if (deleted.has(candidate)) continue;
3407
+ if (!candidate.startsWith(subtreeRoot)) continue;
3408
+ const candidateSf = project.getSourceFile(candidate);
3409
+ if (!candidateSf) continue;
3410
+ const stillImported = project.getSourceFiles().some((sf) => {
3411
+ const sfPath = sf.getFilePath();
3412
+ if (deleted.has(sfPath)) return false;
3413
+ if (sfPath === candidate) return false;
3414
+ return sf.getImportDeclarations().some(
3415
+ (decl) => decl.getModuleSpecifierSourceFile()?.getFilePath() === candidate
3416
+ );
3417
+ });
3418
+ if (stillImported) continue;
3419
+ const next = collectLocalImportsInSubtree(candidateSf, subtreeRoot);
3420
+ worklist.push(...next);
3421
+ candidateSf.delete();
3422
+ deleted.add(candidate);
3423
+ orphans.push(candidate);
3424
+ }
3425
+ return orphans;
3426
+ }
3427
+ function processHandlerFile(project) {
3428
+ const sourceFiles = project.getSourceFiles().filter((sf) => {
3429
+ const fp = sf.getFilePath();
3430
+ return fp.includes("/src/") && !fp.includes("/node_modules/");
3431
+ });
3432
+ for (const sf of sourceFiles) {
3433
+ const fn = sf.getFunction(HANDLER_NAME);
3434
+ if (!fn) continue;
3435
+ const filePath = sf.getFilePath();
3436
+ const exportsByName = [...sf.getExportedDeclarations().keys()];
3437
+ const otherExports = exportsByName.filter((name) => name !== HANDLER_NAME);
3438
+ if (otherExports.length === 0) {
3439
+ const subtreeRoot = import_path16.default.dirname(filePath) + import_path16.default.sep;
3440
+ const orphansDeleted = deleteOrphanedDescendants(
3441
+ project,
3442
+ sf,
3443
+ subtreeRoot
3444
+ );
3445
+ sf.delete();
3446
+ return { filePath, action: "deleted", orphansDeleted };
3447
+ }
3448
+ fn.remove();
3449
+ return {
3450
+ filePath,
3451
+ action: "function-removed",
3452
+ remainingExports: otherExports,
3453
+ orphansDeleted: []
3454
+ };
3455
+ }
3456
+ return { filePath: "", action: "not-found", orphansDeleted: [] };
3457
+ }
3458
+ async function main16() {
3459
+ const project = new import_ts_morph16.Project({
3460
+ tsConfigFilePath: import_path16.default.resolve(process.cwd(), "tsconfig.json"),
3461
+ skipAddingFilesFromTsConfig: false
3462
+ });
3463
+ const sourceFiles = project.getSourceFiles().filter((sf) => {
3464
+ const fp = sf.getFilePath();
3465
+ return fp.includes("/src/") && !fp.includes("/node_modules/");
3466
+ });
3467
+ console.log(
3468
+ `Removing legacy 'GET ${ROUTE_PATH}' route and '${HANDLER_NAME}' across ${sourceFiles.length} source file(s)...
3469
+ `
3470
+ );
3471
+ let totalRoutesRemoved = 0;
3472
+ let totalFilesWithImportsCleaned = 0;
3473
+ let totalFilesWithRoutesRemoved = 0;
3474
+ for (const sourceFile of sourceFiles) {
3475
+ const filePath = sourceFile.getFilePath();
3476
+ const rel = import_path16.default.relative(process.cwd(), filePath);
3477
+ const result = processFile12(sourceFile);
3478
+ if (result.routesRemoved > 0) {
3479
+ console.log(
3480
+ ` [${rel}] Removed ${result.routesRemoved} '${ROUTE_PATH}' route(s)`
3481
+ );
3482
+ totalRoutesRemoved += result.routesRemoved;
3483
+ totalFilesWithRoutesRemoved++;
3484
+ }
3485
+ if (result.importsCleaned) {
3486
+ console.log(` [${rel}] Cleaned up '${HANDLER_NAME}' import`);
3487
+ totalFilesWithImportsCleaned++;
3488
+ }
3489
+ if (result.routesRemoved > 0 || result.importsCleaned) {
3490
+ await sourceFile.save();
3491
+ }
3492
+ }
3493
+ const handlerResult = processHandlerFile(project);
3494
+ switch (handlerResult.action) {
3495
+ case "deleted": {
3496
+ const rel = import_path16.default.relative(process.cwd(), handlerResult.filePath);
3497
+ console.log(
3498
+ ` [${rel}] Deleted handler file ('${HANDLER_NAME}' was the sole export).`
3499
+ );
3500
+ for (const orphanPath of handlerResult.orphansDeleted) {
3501
+ const orphanRel = import_path16.default.relative(process.cwd(), orphanPath);
3502
+ console.log(
3503
+ ` [${orphanRel}] Deleted (no remaining importers in the project after handler removal).`
3504
+ );
3505
+ }
3506
+ await project.save();
3507
+ break;
3508
+ }
3509
+ case "function-removed": {
3510
+ const rel = import_path16.default.relative(process.cwd(), handlerResult.filePath);
3511
+ console.warn(
3512
+ ` [${rel}] Removed '${HANDLER_NAME}' function but kept the file (other exports remain: ${handlerResult.remainingExports?.join(", ")}). Review whether the file is still needed.`
3513
+ );
3514
+ const sf = project.getSourceFile(handlerResult.filePath);
3515
+ if (sf) await sf.save();
3516
+ break;
3517
+ }
3518
+ case "not-found":
3519
+ break;
3520
+ }
3521
+ if (totalRoutesRemoved === 0 && totalFilesWithImportsCleaned === 0 && handlerResult.action === "not-found") {
3522
+ console.log(`
3523
+ No legacy '${ROUTE_PATH}' route or handler found. Nothing to do.`);
3524
+ return;
3525
+ }
3526
+ const orphansSummary = handlerResult.orphansDeleted.length > 0 ? ` and ${handlerResult.orphansDeleted.length} orphaned helper file(s)` : "";
3527
+ console.log(
3528
+ `
3529
+ Done. Removed ${totalRoutesRemoved} route(s) across ${totalFilesWithRoutesRemoved} file(s); cleaned ${HANDLER_NAME} import in ${totalFilesWithImportsCleaned} file(s)${orphansSummary}.`
3530
+ );
3531
+ }
3532
+
3533
+ // src/migrations/v2.0/update-package-json.ts
3534
+ var import_fs = require("fs");
3535
+ var import_path17 = __toESM(require("path"));
3536
+ var PACKAGE_JSON_RELATIVE = "package.json";
3537
+ var TARGET_VERSION = "2.0.0";
3538
+ var TARGET_ZOD_RANGE = "^4.2.1";
3539
+ async function main17() {
3540
+ const packageJsonPath = import_path17.default.join(process.cwd(), PACKAGE_JSON_RELATIVE);
3541
+ if (!(0, import_fs.existsSync)(packageJsonPath)) {
3542
+ console.log(`'${PACKAGE_JSON_RELATIVE}' not found in ${process.cwd()} \u2014 skipping.`);
3543
+ return;
3544
+ }
3545
+ const raw = (0, import_fs.readFileSync)(packageJsonPath, "utf8");
3546
+ let parsed;
3547
+ try {
3548
+ parsed = JSON.parse(raw);
3549
+ } catch (error) {
3550
+ console.warn(
3551
+ ` [${PACKAGE_JSON_RELATIVE}] Failed to parse JSON \u2014 skipping update. ${error.message}`
3552
+ );
3553
+ return;
3554
+ }
3555
+ console.log(`Updating '${PACKAGE_JSON_RELATIVE}'...`);
3556
+ const previousVersion = parsed.version;
3557
+ const versionChanged = previousVersion !== TARGET_VERSION;
3558
+ parsed.version = TARGET_VERSION;
3559
+ if (versionChanged) {
3560
+ console.log(
3561
+ ` Set version: ${previousVersion ?? "<unset>"} \u2192 ${TARGET_VERSION}`
3562
+ );
3563
+ } else {
3564
+ console.log(` Version already ${TARGET_VERSION} \u2014 no change.`);
3565
+ }
3566
+ let zodBucket = "dependencies";
3567
+ if (parsed.devDependencies && "zod" in parsed.devDependencies) {
3568
+ zodBucket = "devDependencies";
3569
+ }
3570
+ if (!parsed[zodBucket]) {
3571
+ parsed[zodBucket] = {};
3572
+ }
3573
+ const bucket = parsed[zodBucket];
3574
+ const previousZod = bucket.zod;
3575
+ const zodChanged = previousZod !== TARGET_ZOD_RANGE;
3576
+ bucket.zod = TARGET_ZOD_RANGE;
3577
+ if (zodChanged) {
3578
+ console.log(
3579
+ ` Set ${zodBucket}.zod: ${previousZod ?? "<absent>"} \u2192 ${TARGET_ZOD_RANGE}`
3580
+ );
3581
+ } else {
3582
+ console.log(` ${zodBucket}.zod already ${TARGET_ZOD_RANGE} \u2014 no change.`);
3583
+ }
3584
+ const trailingNewline = raw.endsWith("\n") ? "\n" : "";
3585
+ const next = JSON.stringify(parsed, null, 2) + trailingNewline;
3586
+ if (next === raw) {
3587
+ console.log("\n No changes to write.");
3588
+ return;
3589
+ }
3590
+ (0, import_fs.writeFileSync)(packageJsonPath, next, "utf8");
3591
+ console.log(`
3592
+ Saved '${PACKAGE_JSON_RELATIVE}'.`);
3593
+ console.log(
3594
+ ` NOTE: run \`yarn install\` (or your package manager equivalent) to install the updated dependency versions.`
3595
+ );
3596
+ }
3597
+
3598
+ // src/migrations/v2.0/migrate-workqueue-configs.ts
3599
+ var import_ts_morph17 = require("ts-morph");
3600
+ var import_path18 = __toESM(require("path"));
2877
3601
  var DEFINE_WORKQUEUES_NAME3 = "defineWorkqueues";
2878
3602
  var ACTIONS_PROPERTY_NAME5 = "actions";
2879
3603
  var ACTION_PROPERTY_NAME2 = "action";
@@ -2894,28 +3618,28 @@ var SUPPORTED_WORKQUEUE_ACTION_TYPES = /* @__PURE__ */ new Set([
2894
3618
  ]);
2895
3619
  function getWorkqueueLabel(workqueue) {
2896
3620
  const slugProperty = workqueue.getProperty(SLUG_PROPERTY_NAME);
2897
- if (!slugProperty || !import_ts_morph13.Node.isPropertyAssignment(slugProperty)) {
3621
+ if (!slugProperty || !import_ts_morph17.Node.isPropertyAssignment(slugProperty)) {
2898
3622
  return "(unknown slug)";
2899
3623
  }
2900
3624
  const slugInitializer = slugProperty.getInitializer();
2901
- if (!slugInitializer || !import_ts_morph13.Node.isStringLiteral(slugInitializer)) {
3625
+ if (!slugInitializer || !import_ts_morph17.Node.isStringLiteral(slugInitializer)) {
2902
3626
  return "(unknown slug)";
2903
3627
  }
2904
3628
  return slugInitializer.getLiteralValue();
2905
3629
  }
2906
3630
  function getActionTypeName(action) {
2907
3631
  const typeProperty = action.getProperty(TYPE_PROPERTY_NAME7);
2908
- if (!typeProperty || !import_ts_morph13.Node.isPropertyAssignment(typeProperty)) {
3632
+ if (!typeProperty || !import_ts_morph17.Node.isPropertyAssignment(typeProperty)) {
2909
3633
  return null;
2910
3634
  }
2911
3635
  const typeInitializer = typeProperty.getInitializer();
2912
3636
  if (!typeInitializer) {
2913
3637
  return null;
2914
3638
  }
2915
- if (import_ts_morph13.Node.isStringLiteral(typeInitializer)) {
3639
+ if (import_ts_morph17.Node.isStringLiteral(typeInitializer)) {
2916
3640
  return typeInitializer.getLiteralValue();
2917
3641
  }
2918
- if (import_ts_morph13.Node.isPropertyAccessExpression(typeInitializer)) {
3642
+ if (import_ts_morph17.Node.isPropertyAccessExpression(typeInitializer)) {
2919
3643
  return typeInitializer.getName();
2920
3644
  }
2921
3645
  return null;
@@ -2929,19 +3653,19 @@ function isUnsupportedActionType(action) {
2929
3653
  }
2930
3654
  function migrateWorkqueueActions(workqueue, relPath) {
2931
3655
  const actionsProperty = workqueue.getProperty(ACTIONS_PROPERTY_NAME5);
2932
- if (!actionsProperty || !import_ts_morph13.Node.isPropertyAssignment(actionsProperty)) {
3656
+ if (!actionsProperty || !import_ts_morph17.Node.isPropertyAssignment(actionsProperty)) {
2933
3657
  return 0;
2934
3658
  }
2935
3659
  const actionsInitializer = actionsProperty.getInitializer();
2936
- if (!actionsInitializer || !import_ts_morph13.Node.isArrayLiteralExpression(actionsInitializer)) {
3660
+ if (!actionsInitializer || !import_ts_morph17.Node.isArrayLiteralExpression(actionsInitializer)) {
2937
3661
  return 0;
2938
3662
  }
2939
3663
  const workqueueLabel = getWorkqueueLabel(workqueue);
2940
3664
  const existingActionProperty = workqueue.getProperty(ACTION_PROPERTY_NAME2);
2941
3665
  if (existingActionProperty) {
2942
- if (import_ts_morph13.Node.isPropertyAssignment(existingActionProperty)) {
3666
+ if (import_ts_morph17.Node.isPropertyAssignment(existingActionProperty)) {
2943
3667
  const existingActionInitializer = existingActionProperty.getInitializer();
2944
- if (existingActionInitializer && import_ts_morph13.Node.isObjectLiteralExpression(existingActionInitializer)) {
3668
+ if (existingActionInitializer && import_ts_morph17.Node.isObjectLiteralExpression(existingActionInitializer)) {
2945
3669
  const conditionalsProperty2 = existingActionInitializer.getProperty(
2946
3670
  CONDITIONALS_PROPERTY_NAME
2947
3671
  );
@@ -2966,7 +3690,7 @@ function migrateWorkqueueActions(workqueue, relPath) {
2966
3690
  return 1;
2967
3691
  }
2968
3692
  const actionCandidates = actionsInitializer.getElements().filter(
2969
- (element) => import_ts_morph13.Node.isObjectLiteralExpression(element)
3693
+ (element) => import_ts_morph17.Node.isObjectLiteralExpression(element)
2970
3694
  );
2971
3695
  if (actionCandidates.length === 0) {
2972
3696
  actionsProperty.remove();
@@ -3008,36 +3732,36 @@ function migrateWorkqueueActions(workqueue, relPath) {
3008
3732
  );
3009
3733
  return 1;
3010
3734
  }
3011
- function processFile11(filePath, project) {
3735
+ function processFile13(filePath, project) {
3012
3736
  const sourceFile = project.getSourceFile(filePath);
3013
3737
  if (!sourceFile) return 0;
3014
3738
  let migratedWorkqueues = 0;
3015
- const relPath = import_path13.default.relative(getCwd(), filePath);
3739
+ const relPath = import_path18.default.relative(process.cwd(), filePath);
3016
3740
  const callExpressions = sourceFile.getDescendantsOfKind(
3017
- import_ts_morph13.SyntaxKind.CallExpression
3741
+ import_ts_morph17.SyntaxKind.CallExpression
3018
3742
  );
3019
3743
  for (const call of callExpressions) {
3020
3744
  const expression = call.getExpression();
3021
- if (!import_ts_morph13.Node.isIdentifier(expression) || expression.getText() !== DEFINE_WORKQUEUES_NAME3) {
3745
+ if (!import_ts_morph17.Node.isIdentifier(expression) || expression.getText() !== DEFINE_WORKQUEUES_NAME3) {
3022
3746
  continue;
3023
3747
  }
3024
3748
  const args2 = call.getArguments();
3025
3749
  if (args2.length === 0) continue;
3026
3750
  const workqueuesArg = args2[0];
3027
- if (!import_ts_morph13.Node.isArrayLiteralExpression(workqueuesArg)) continue;
3751
+ if (!import_ts_morph17.Node.isArrayLiteralExpression(workqueuesArg)) continue;
3028
3752
  for (const element of workqueuesArg.getElements()) {
3029
- if (!import_ts_morph13.Node.isObjectLiteralExpression(element)) continue;
3753
+ if (!import_ts_morph17.Node.isObjectLiteralExpression(element)) continue;
3030
3754
  migratedWorkqueues += migrateWorkqueueActions(element, relPath);
3031
3755
  }
3032
3756
  }
3033
3757
  return migratedWorkqueues;
3034
3758
  }
3035
- async function main13() {
3036
- const srcDir = import_path13.default.join(getCwd(), "src");
3759
+ async function main18() {
3760
+ const srcDir = import_path18.default.join(process.cwd(), "src");
3037
3761
  console.log(`Scanning for defineWorkqueues calls in: ${srcDir}
3038
3762
  `);
3039
- const project = new import_ts_morph13.Project({
3040
- tsConfigFilePath: import_path13.default.resolve(srcDir, "../tsconfig.json"),
3763
+ const project = new import_ts_morph17.Project({
3764
+ tsConfigFilePath: import_path18.default.resolve(srcDir, "../tsconfig.json"),
3041
3765
  skipAddingFilesFromTsConfig: false
3042
3766
  });
3043
3767
  const sourceFiles = project.getSourceFiles().filter((sf) => {
@@ -3050,7 +3774,7 @@ async function main13() {
3050
3774
  const modifiedFiles = [];
3051
3775
  for (const sourceFile of sourceFiles) {
3052
3776
  const filePath = sourceFile.getFilePath();
3053
- const migrated = processFile11(filePath, project);
3777
+ const migrated = processFile13(filePath, project);
3054
3778
  if (migrated > 0) {
3055
3779
  totalMigrated += migrated;
3056
3780
  modifiedFiles.push(filePath);
@@ -3067,7 +3791,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
3067
3791
  for (const filePath of modifiedFiles) {
3068
3792
  const sourceFile = project.getSourceFileOrThrow(filePath);
3069
3793
  await sourceFile.save();
3070
- console.log(` Saved: ${import_path13.default.relative(getCwd(), filePath)}`);
3794
+ console.log(` Saved: ${import_path18.default.relative(process.cwd(), filePath)}`);
3071
3795
  }
3072
3796
  console.log(
3073
3797
  `
@@ -3076,13 +3800,13 @@ Done. Migrated ${totalMigrated} deprecated workqueue 'actions' definition(s) to
3076
3800
  }
3077
3801
 
3078
3802
  // src/migrations/v2.0/remove-demo-scope.ts
3079
- var import_path14 = __toESM(require("path"));
3080
- var import_ts_morph14 = require("ts-morph");
3803
+ var import_path19 = __toESM(require("path"));
3804
+ var import_ts_morph18 = require("ts-morph");
3081
3805
  var ROLES_HANDLER_RELATIVE_PATH = "src/data-seeding/roles/handler.ts";
3082
- async function main14() {
3083
- const rolesHandlerPath = import_path14.default.join(getCwd(), ROLES_HANDLER_RELATIVE_PATH);
3084
- const project = new import_ts_morph14.Project({
3085
- tsConfigFilePath: import_path14.default.resolve(getCwd(), "tsconfig.json"),
3806
+ async function main19() {
3807
+ const rolesHandlerPath = import_path19.default.join(process.cwd(), ROLES_HANDLER_RELATIVE_PATH);
3808
+ const project = new import_ts_morph18.Project({
3809
+ tsConfigFilePath: import_path19.default.resolve(process.cwd(), "tsconfig.json"),
3086
3810
  skipAddingFilesFromTsConfig: false
3087
3811
  });
3088
3812
  const sourceFile = project.getSourceFile(rolesHandlerPath);
@@ -3131,7 +3855,7 @@ async function main14() {
3131
3855
 
3132
3856
  // src/migrations/v2.0/remove-hearth-migrations.ts
3133
3857
  var fs2 = __toESM(require("fs"));
3134
- var import_path15 = __toESM(require("path"));
3858
+ var import_path20 = __toESM(require("path"));
3135
3859
  var PATHS_TO_REMOVE = [
3136
3860
  {
3137
3861
  relativePath: "src/migrations/hearth",
@@ -3143,9 +3867,9 @@ var PATHS_TO_REMOVE = [
3143
3867
  },
3144
3868
  { relativePath: "src/utils/hearth-helpers.ts", label: "Hearth helpers file" }
3145
3869
  ];
3146
- async function main15() {
3870
+ async function main20() {
3147
3871
  for (const { relativePath, label } of PATHS_TO_REMOVE) {
3148
- const absolutePath = import_path15.default.join(getCwd(), relativePath);
3872
+ const absolutePath = import_path20.default.join(process.cwd(), relativePath);
3149
3873
  if (fs2.existsSync(absolutePath)) {
3150
3874
  fs2.rmSync(absolutePath, { recursive: true, force: true });
3151
3875
  console.log(`Removed ${label} '${relativePath}'.`);
@@ -3156,9 +3880,9 @@ async function main15() {
3156
3880
  }
3157
3881
 
3158
3882
  // src/migrations/v2.0/create-events-index.ts
3159
- var import_ts_morph15 = require("ts-morph");
3160
- var import_fs = __toESM(require("fs"));
3161
- var import_path16 = __toESM(require("path"));
3883
+ var import_ts_morph19 = require("ts-morph");
3884
+ var import_fs2 = __toESM(require("fs"));
3885
+ var import_path21 = __toESM(require("path"));
3162
3886
  var DEFINE_CONFIG_NAME5 = "defineConfig";
3163
3887
  var HANDLER_FUNCTION_NAMES = /* @__PURE__ */ new Set([
3164
3888
  "getCustomEventsHandler",
@@ -3180,7 +3904,7 @@ var LICENSE_HEADER = `/*
3180
3904
  `;
3181
3905
  function findEventConfigExports(project, srcDir) {
3182
3906
  const found = [];
3183
- const eventsIndexAbs = import_path16.default.join(srcDir, "events", "index.ts");
3907
+ const eventsIndexAbs = import_path21.default.join(srcDir, "events", "index.ts");
3184
3908
  for (const sourceFile of project.getSourceFiles()) {
3185
3909
  const filePath = sourceFile.getFilePath();
3186
3910
  if (!filePath.startsWith(srcDir) || filePath.includes("/node_modules/")) {
@@ -3192,10 +3916,10 @@ function findEventConfigExports(project, srcDir) {
3192
3916
  for (const decl of statement.getDeclarations()) {
3193
3917
  const initializer = decl.getInitializer();
3194
3918
  if (!initializer) continue;
3195
- const unwrapped = import_ts_morph15.Node.isAsExpression(initializer) ? initializer.getExpression() : initializer;
3196
- if (!import_ts_morph15.Node.isCallExpression(unwrapped)) continue;
3919
+ const unwrapped = import_ts_morph19.Node.isAsExpression(initializer) ? initializer.getExpression() : initializer;
3920
+ if (!import_ts_morph19.Node.isCallExpression(unwrapped)) continue;
3197
3921
  const callee = unwrapped.getExpression();
3198
- if (!import_ts_morph15.Node.isIdentifier(callee)) continue;
3922
+ if (!import_ts_morph19.Node.isIdentifier(callee)) continue;
3199
3923
  if (callee.getText() !== DEFINE_CONFIG_NAME5) continue;
3200
3924
  found.push({ name: decl.getName(), filePath });
3201
3925
  }
@@ -3204,8 +3928,8 @@ function findEventConfigExports(project, srcDir) {
3204
3928
  return found;
3205
3929
  }
3206
3930
  function buildIndexImportSpecifier(eventConfigFilePath, srcDir) {
3207
- const eventsIndexDir = import_path16.default.join(srcDir, "events");
3208
- let rel = import_path16.default.relative(eventsIndexDir, eventConfigFilePath).split(import_path16.default.sep).join("/");
3931
+ const eventsIndexDir = import_path21.default.join(srcDir, "events");
3932
+ let rel = import_path21.default.relative(eventsIndexDir, eventConfigFilePath).split(import_path21.default.sep).join("/");
3209
3933
  if (rel.endsWith(".ts")) rel = rel.slice(0, -".ts".length);
3210
3934
  if (rel.endsWith("/index")) rel = rel.slice(0, -"/index".length);
3211
3935
  if (!rel.startsWith(".")) rel = "./" + rel;
@@ -3282,17 +4006,17 @@ function modifyHandler(sourceFile, exportNames) {
3282
4006
  );
3283
4007
  }
3284
4008
  for (const call of sourceFile.getDescendantsOfKind(
3285
- import_ts_morph15.SyntaxKind.CallExpression
4009
+ import_ts_morph19.SyntaxKind.CallExpression
3286
4010
  )) {
3287
4011
  const callee = call.getExpression();
3288
- if (!import_ts_morph15.Node.isPropertyAccessExpression(callee)) continue;
4012
+ if (!import_ts_morph19.Node.isPropertyAccessExpression(callee)) continue;
3289
4013
  if (callee.getName() !== RESPONSE_METHOD_NAME) continue;
3290
4014
  const args2 = call.getArguments();
3291
4015
  if (args2.length !== 1) continue;
3292
4016
  const [arg] = args2;
3293
- if (!import_ts_morph15.Node.isArrayLiteralExpression(arg)) continue;
4017
+ if (!import_ts_morph19.Node.isArrayLiteralExpression(arg)) continue;
3294
4018
  if (arg.getElements().length === 0) continue;
3295
- if (!arg.getElements().every((el) => import_ts_morph15.Node.isIdentifier(el))) continue;
4019
+ if (!arg.getElements().every((el) => import_ts_morph19.Node.isIdentifier(el))) continue;
3296
4020
  arg.replaceWithText(EVENT_CONFIGS_IDENTIFIER);
3297
4021
  changes.push(
3298
4022
  `rewrote h.response([...]) \u2192 h.response(${EVENT_CONFIGS_IDENTIFIER})`
@@ -3300,13 +4024,13 @@ function modifyHandler(sourceFile, exportNames) {
3300
4024
  }
3301
4025
  return changes;
3302
4026
  }
3303
- async function main16() {
3304
- const cwd2 = getCwd();
3305
- const srcDir = import_path16.default.join(cwd2, "src");
4027
+ async function main21() {
4028
+ const cwd = process.cwd();
4029
+ const srcDir = import_path21.default.join(cwd, "src");
3306
4030
  console.log(`Scanning for defineConfig event exports in: ${srcDir}
3307
4031
  `);
3308
- const project = new import_ts_morph15.Project({
3309
- tsConfigFilePath: import_path16.default.resolve(srcDir, "../tsconfig.json"),
4032
+ const project = new import_ts_morph19.Project({
4033
+ tsConfigFilePath: import_path21.default.resolve(srcDir, "../tsconfig.json"),
3310
4034
  skipAddingFilesFromTsConfig: false
3311
4035
  });
3312
4036
  const eventConfigExports = findEventConfigExports(project, srcDir);
@@ -3318,15 +4042,15 @@ async function main16() {
3318
4042
  }
3319
4043
  console.log(`Found ${eventConfigExports.length} event config export(s):`);
3320
4044
  for (const e of eventConfigExports) {
3321
- console.log(` ${e.name} \u2190 ${import_path16.default.relative(cwd2, e.filePath)}`);
4045
+ console.log(` ${e.name} \u2190 ${import_path21.default.relative(cwd, e.filePath)}`);
3322
4046
  }
3323
- const eventsIndexAbs = import_path16.default.join(srcDir, "events", "index.ts");
3324
- const eventsIndexRel = import_path16.default.relative(cwd2, eventsIndexAbs);
3325
- if (import_fs.default.existsSync(eventsIndexAbs)) {
4047
+ const eventsIndexAbs = import_path21.default.join(srcDir, "events", "index.ts");
4048
+ const eventsIndexRel = import_path21.default.relative(cwd, eventsIndexAbs);
4049
+ if (import_fs2.default.existsSync(eventsIndexAbs)) {
3326
4050
  console.log(`
3327
4051
  [${eventsIndexRel}] already exists \u2014 leaving untouched.`);
3328
4052
  } else {
3329
- import_fs.default.mkdirSync(import_path16.default.dirname(eventsIndexAbs), { recursive: true });
4053
+ import_fs2.default.mkdirSync(import_path21.default.dirname(eventsIndexAbs), { recursive: true });
3330
4054
  const source = buildEventsIndexSource(eventConfigExports, srcDir);
3331
4055
  const eventsIndexFile = project.createSourceFile(eventsIndexAbs, source, {
3332
4056
  overwrite: false
@@ -3347,7 +4071,7 @@ No event-config handler file found (looked for exported function(s): ${Array.fro
3347
4071
  );
3348
4072
  return;
3349
4073
  }
3350
- const handlerRelPath = import_path16.default.relative(cwd2, handler.getFilePath());
4074
+ const handlerRelPath = import_path21.default.relative(cwd, handler.getFilePath());
3351
4075
  const exportNameSet = new Set(eventConfigExports.map((e) => e.name));
3352
4076
  const changes = modifyHandler(handler, exportNameSet);
3353
4077
  if (changes.length === 0) {
@@ -3367,12 +4091,13 @@ var UPSTREAM_URL = "https://github.com/opencrvs/opencrvs-countryconfig.git";
3367
4091
  var UPSTREAM_BRANCH = "develop";
3368
4092
  var TEMP_REMOTE = "opencrvs-upgrade-v19-v20-codemod";
3369
4093
  var FILES_TO_CHECKOUT = [
3370
- "infrastructure/postgres/setup-analytics.sh",
3371
- "src/analytics/analytics.ts"
4094
+ "src/analytics/analytics.ts",
4095
+ "Dockerfile",
4096
+ "Dockerfile.assets"
3372
4097
  ];
3373
4098
  function runGit(args2, { silent = false } = {}) {
3374
4099
  return (0, import_child_process.execFileSync)("git", args2, {
3375
- cwd: getCwd(),
4100
+ cwd: process.cwd(),
3376
4101
  encoding: "utf8",
3377
4102
  stdio: silent ? ["ignore", "pipe", "pipe"] : ["ignore", "pipe", "inherit"]
3378
4103
  });
@@ -3388,11 +4113,11 @@ function tryGit(args2) {
3388
4113
  function assertIsGitRepo() {
3389
4114
  if (!tryGit(["rev-parse", "--is-inside-work-tree"])) {
3390
4115
  throw new Error(
3391
- `checkout-upstream-files: ${getCwd()} is not a git repository. Initialise git (or run the upgrade inside a git checkout) before re-running.`
4116
+ `${process.cwd()} is not a git repository. Initialise git (or run the upgrade inside a git checkout) before re-running.`
3392
4117
  );
3393
4118
  }
3394
4119
  }
3395
- async function main17() {
4120
+ async function main22() {
3396
4121
  console.log(
3397
4122
  `Checking out ${FILES_TO_CHECKOUT.length} file(s) from ${UPSTREAM_URL}@${UPSTREAM_BRANCH}...
3398
4123
  `
@@ -3440,10 +4165,356 @@ async function main17() {
3440
4165
  }
3441
4166
  }
3442
4167
 
4168
+ // src/migrations/v2.0/add-resend-invite-notification.ts
4169
+ var import_fs3 = require("fs");
4170
+ var import_path22 = __toESM(require("path"));
4171
+ var import_ts_morph20 = require("ts-morph");
4172
+ var TS_MORPH_PROJECT_OPTIONS = {
4173
+ skipAddingFilesFromTsConfig: true,
4174
+ manipulationSettings: {
4175
+ indentationText: import_ts_morph20.IndentationText.TwoSpaces
4176
+ }
4177
+ };
4178
+ var EMAIL_TEMPLATES_INDEX = "src/api/notification/email-templates/index.ts";
4179
+ var NOTIFICATION_HANDLER = "src/api/notification/handler.ts";
4180
+ var USER_NOTIFICATION_ROUTES = "src/config/routes/userNotificationRoutes.ts";
4181
+ var SMS_SERVICE = "src/api/notification/sms-service.ts";
4182
+ var NOTIFICATION_CSV = "src/translations/notification.csv";
4183
+ var RESEND_INVITE_HTML = "src/api/notification/email-templates/other/resend-invite.html";
4184
+ var RESEND_INVITE_HTML_CONTENT = `<!doctype html>
4185
+ <html>
4186
+ <head>
4187
+ <link
4188
+ href="https://fonts.googleapis.com/css2?family=Noto+Sans:wght@400;700&display=swap"
4189
+ rel="stylesheet"
4190
+ />
4191
+ <style type="text/css">
4192
+ body {
4193
+ font-family: 'Noto Sans', sans-serif;
4194
+ color: #222;
4195
+ padding: 16px 24px;
4196
+ }
4197
+
4198
+ h1 {
4199
+ font-size: 21px;
4200
+ margin-top: 32px;
4201
+ margin-bottom: 36px;
4202
+ font-weight: 700;
4203
+ }
4204
+
4205
+ p {
4206
+ font-weight: 400;
4207
+ font-size: 16px;
4208
+ line-height: 1.8;
4209
+ margin-bottom: 24px;
4210
+ }
4211
+
4212
+ i {
4213
+ color: #666;
4214
+ font-weight: 400;
4215
+ font-size: 16px;
4216
+ }
4217
+ </style>
4218
+ </head>
4219
+
4220
+ <body>
4221
+ <img
4222
+ src="{{countryLogo}}"
4223
+ alt="country_logo"
4224
+ style="max-height: 88px; max-width: 100%"
4225
+ />
4226
+ <h1>Your {{applicationName}} account invitation</h1>
4227
+ <p>Hello {{firstname}},</p>
4228
+ <p>Your account invitation has been resent. Please use the following credentials to access your account:</p>
4229
+ <p>
4230
+ Username: <strong>{{username}}</strong><br />
4231
+ Password: <strong>{{temporaryPassword}}</strong>
4232
+ </p>
4233
+ <p>
4234
+ Please click the link below to complete your account setup and start using
4235
+ {{applicationName}}.
4236
+ </p>
4237
+
4238
+ <div style="margin-top: 32px; margin-bottom: 32px">
4239
+ <a href="{{loginURL}}">Complete setup</a>
4240
+ </div>
4241
+ <br />
4242
+ <p>
4243
+ Best regards, <br />
4244
+ {{applicationName}} Team
4245
+ </p>
4246
+ </body>
4247
+ </html>
4248
+ `;
4249
+ 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";
4250
+ function getObjectLiteralFromConst(declaration) {
4251
+ if (!declaration) {
4252
+ return;
4253
+ }
4254
+ const initializer = declaration.getInitializer();
4255
+ if (!initializer) {
4256
+ return;
4257
+ }
4258
+ if (import_ts_morph20.Node.isObjectLiteralExpression(initializer)) {
4259
+ return initializer;
4260
+ }
4261
+ if (import_ts_morph20.Node.isAsExpression(initializer)) {
4262
+ const expression = initializer.getExpression();
4263
+ if (import_ts_morph20.Node.isObjectLiteralExpression(expression)) {
4264
+ return expression;
4265
+ }
4266
+ }
4267
+ if (import_ts_morph20.Node.isSatisfiesExpression(initializer)) {
4268
+ const expression = initializer.getExpression();
4269
+ if (import_ts_morph20.Node.isObjectLiteralExpression(expression)) {
4270
+ return expression;
4271
+ }
4272
+ }
4273
+ }
4274
+ function patchEmailTemplatesIndex() {
4275
+ const full = import_path22.default.join(process.cwd(), EMAIL_TEMPLATES_INDEX);
4276
+ if (!(0, import_fs3.existsSync)(full)) {
4277
+ console.log(` '${EMAIL_TEMPLATES_INDEX}' missing \u2014 skipping.`);
4278
+ return false;
4279
+ }
4280
+ const project = new import_ts_morph20.Project(TS_MORPH_PROJECT_OPTIONS);
4281
+ const sourceFile = project.addSourceFileAtPath(full);
4282
+ let changed = false;
4283
+ const triggerVariableObject = getObjectLiteralFromConst(
4284
+ sourceFile.getVariableDeclaration("TriggerVariable")
4285
+ );
4286
+ if (triggerVariableObject) {
4287
+ const hasResendInviteVariable = triggerVariableObject.getProperties().some((prop) => prop.getText().includes("[TriggerEvent.RESEND_INVITE]"));
4288
+ if (!hasResendInviteVariable) {
4289
+ const properties = triggerVariableObject.getProperties();
4290
+ const lastProperty = properties[properties.length - 1];
4291
+ if (lastProperty) {
4292
+ sourceFile.insertText(
4293
+ lastProperty.getEnd(),
4294
+ `,
4295
+ [TriggerEvent.RESEND_INVITE]: z.object({
4296
+ firstname: z.string(),
4297
+ username: z.string(),
4298
+ temporaryPassword: z.string(),
4299
+ completeSetupUrl: z.string(),
4300
+ loginURL: z.string()
4301
+ })`
4302
+ );
4303
+ changed = true;
4304
+ }
4305
+ }
4306
+ }
4307
+ const templatesObject = getObjectLiteralFromConst(
4308
+ sourceFile.getVariableDeclaration("templates")
4309
+ );
4310
+ if (templatesObject) {
4311
+ const hasResendInviteTemplate = templatesObject.getProperties().some(
4312
+ (prop) => prop.getText().includes("readOtherTemplate<TriggerVariable['resend-invite']>")
4313
+ );
4314
+ if (!hasResendInviteTemplate) {
4315
+ const userCreatedProp = templatesObject.getProperties().find((prop) => prop.getText().includes("[TriggerEvent.USER_CREATED]"));
4316
+ const anchor = userCreatedProp ?? templatesObject.getProperties()[templatesObject.getProperties().length - 1];
4317
+ if (anchor) {
4318
+ sourceFile.insertText(
4319
+ anchor.getEnd(),
4320
+ `,
4321
+ [TriggerEvent.RESEND_INVITE]: {
4322
+ type: 'resend-invite',
4323
+ subject: 'Your OpenCRVS account invitation',
4324
+ template:
4325
+ readOtherTemplate<TriggerVariable['resend-invite']>('resend-invite')
4326
+ }`
4327
+ );
4328
+ changed = true;
4329
+ }
4330
+ }
4331
+ }
4332
+ if (changed) {
4333
+ sourceFile.saveSync();
4334
+ }
4335
+ return changed;
4336
+ }
4337
+ function patchNotificationHandler() {
4338
+ const full = import_path22.default.join(process.cwd(), NOTIFICATION_HANDLER);
4339
+ if (!(0, import_fs3.existsSync)(full)) {
4340
+ return false;
4341
+ }
4342
+ const project = new import_ts_morph20.Project(TS_MORPH_PROJECT_OPTIONS);
4343
+ const sourceFile = project.addSourceFileAtPath(full);
4344
+ const convertFn = sourceFile.getFunction("convertPayloadToVariable");
4345
+ if (!convertFn) {
4346
+ return false;
4347
+ }
4348
+ const switchStmt = convertFn.getFirstDescendantByKind(
4349
+ import_ts_morph20.SyntaxKind.SwitchStatement
4350
+ );
4351
+ if (!switchStmt) {
4352
+ return false;
4353
+ }
4354
+ const clauses = switchStmt.getCaseBlock().getClauses();
4355
+ const hasResendInvite = clauses.some(
4356
+ (clause) => import_ts_morph20.Node.isCaseClause(clause) && clause.getExpression().getText() === "TriggerEvent.RESEND_INVITE"
4357
+ );
4358
+ if (hasResendInvite) {
4359
+ return false;
4360
+ }
4361
+ const userCreatedClauseIndex = clauses.findIndex(
4362
+ (clause) => import_ts_morph20.Node.isCaseClause(clause) && clause.getExpression().getText() === "TriggerEvent.USER_CREATED"
4363
+ );
4364
+ if (userCreatedClauseIndex < 0) {
4365
+ return false;
4366
+ }
4367
+ const userCreatedClause = clauses[userCreatedClauseIndex];
4368
+ sourceFile.insertText(
4369
+ userCreatedClause.getEnd(),
4370
+ `
4371
+
4372
+ case TriggerEvent.RESEND_INVITE:
4373
+ return {
4374
+ firstname,
4375
+ username: payload.username,
4376
+ temporaryPassword: payload.temporaryPassword,
4377
+ completeSetupUrl: LOGIN_URL,
4378
+ loginURL: LOGIN_URL
4379
+ }`
4380
+ );
4381
+ sourceFile.saveSync();
4382
+ return true;
4383
+ }
4384
+ function getReturnedArrayLiteral(functionFilePath, fnName) {
4385
+ const project = new import_ts_morph20.Project(TS_MORPH_PROJECT_OPTIONS);
4386
+ const sourceFile = project.addSourceFileAtPath(functionFilePath);
4387
+ const fn = sourceFile.getFunction(fnName);
4388
+ const returnStmt = fn?.getFirstDescendantByKind(import_ts_morph20.SyntaxKind.ReturnStatement);
4389
+ const expr = returnStmt?.getExpression();
4390
+ if (!expr || !import_ts_morph20.Node.isArrayLiteralExpression(expr)) {
4391
+ return { sourceFile, arrayLiteral: void 0 };
4392
+ }
4393
+ return { sourceFile, arrayLiteral: expr };
4394
+ }
4395
+ function patchUserNotificationRoutes() {
4396
+ const full = import_path22.default.join(process.cwd(), USER_NOTIFICATION_ROUTES);
4397
+ if (!(0, import_fs3.existsSync)(full)) {
4398
+ return false;
4399
+ }
4400
+ const { sourceFile, arrayLiteral } = getReturnedArrayLiteral(
4401
+ full,
4402
+ "getUserNotificationRoutes"
4403
+ );
4404
+ if (!arrayLiteral) {
4405
+ return false;
4406
+ }
4407
+ const elements = arrayLiteral.getElements();
4408
+ const routeExists = elements.some(
4409
+ (element) => element.getText().includes(`path: '/triggers/user/resend-invite'`)
4410
+ );
4411
+ if (routeExists) {
4412
+ return false;
4413
+ }
4414
+ const anchor = elements.find(
4415
+ (element) => element.getText().includes(`path: '/triggers/user/user-created'`)
4416
+ ) ?? elements[elements.length - 1];
4417
+ if (!anchor) {
4418
+ return false;
4419
+ }
4420
+ sourceFile.insertText(
4421
+ anchor.getEnd(),
4422
+ `,
4423
+ {
4424
+ method: 'POST',
4425
+ path: '/triggers/user/resend-invite',
4426
+ handler: makeNotificationHandler('resend-invite'),
4427
+ options: {
4428
+ auth: false,
4429
+ tags: ['api'],
4430
+ description: 'Handles notification for resent user invite'
4431
+ }
4432
+ }`
4433
+ );
4434
+ sourceFile.saveSync();
4435
+ return true;
4436
+ }
4437
+ function patchSmsService() {
4438
+ const full = import_path22.default.join(process.cwd(), SMS_SERVICE);
4439
+ if (!(0, import_fs3.existsSync)(full)) {
4440
+ return false;
4441
+ }
4442
+ const project = new import_ts_morph20.Project(TS_MORPH_PROJECT_OPTIONS);
4443
+ const sourceFile = project.addSourceFileAtPath(full);
4444
+ let changed = false;
4445
+ const otherTemplatesObject = getObjectLiteralFromConst(
4446
+ sourceFile.getVariableDeclaration("otherTemplates")
4447
+ );
4448
+ if (otherTemplatesObject) {
4449
+ const hasResendTemplate = otherTemplatesObject.getProperties().some((prop) => prop.getText().includes("resendInviteNotification"));
4450
+ if (!hasResendTemplate) {
4451
+ const userCredentialsIndex = otherTemplatesObject.getProperties().findIndex((prop) => prop.getText().includes("userCredentialsNotification"));
4452
+ otherTemplatesObject.insertPropertyAssignment(
4453
+ userCredentialsIndex >= 0 ? userCredentialsIndex + 1 : otherTemplatesObject.getProperties().length,
4454
+ {
4455
+ name: "resendInviteNotification",
4456
+ initializer: `'resendInviteNotification'`
4457
+ }
4458
+ );
4459
+ changed = true;
4460
+ }
4461
+ }
4462
+ const triggerToSmsTemplateObject = getObjectLiteralFromConst(
4463
+ sourceFile.getVariableDeclaration("TriggerToSMSTemplate")
4464
+ );
4465
+ if (triggerToSmsTemplateObject) {
4466
+ const hasResendInviteMap = triggerToSmsTemplateObject.getProperties().some((prop) => prop.getText().includes(`['resend-invite']`));
4467
+ if (!hasResendInviteMap) {
4468
+ const userCreatedIndex = triggerToSmsTemplateObject.getProperties().findIndex((prop) => prop.getText().includes(`['user-created']`));
4469
+ triggerToSmsTemplateObject.insertPropertyAssignment(
4470
+ userCreatedIndex >= 0 ? userCreatedIndex + 1 : triggerToSmsTemplateObject.getProperties().length,
4471
+ {
4472
+ name: `['resend-invite']`,
4473
+ initializer: `'resendInviteNotification'`
4474
+ }
4475
+ );
4476
+ changed = true;
4477
+ }
4478
+ }
4479
+ if (changed) {
4480
+ sourceFile.saveSync();
4481
+ }
4482
+ return changed;
4483
+ }
4484
+ async function main23() {
4485
+ console.log("Adding RESEND_INVITE notification wiring\u2026");
4486
+ const touched = [];
4487
+ if (patchEmailTemplatesIndex()) touched.push(EMAIL_TEMPLATES_INDEX);
4488
+ if (patchNotificationHandler()) touched.push(NOTIFICATION_HANDLER);
4489
+ if (patchUserNotificationRoutes()) touched.push(USER_NOTIFICATION_ROUTES);
4490
+ if (patchSmsService()) touched.push(SMS_SERVICE);
4491
+ const csvPath = import_path22.default.join(process.cwd(), NOTIFICATION_CSV);
4492
+ if ((0, import_fs3.existsSync)(csvPath)) {
4493
+ let t = (0, import_fs3.readFileSync)(csvPath, "utf8");
4494
+ if (!/^resendInviteNotification,/m.test(t)) {
4495
+ if (!t.endsWith("\n")) t += "\n";
4496
+ (0, import_fs3.writeFileSync)(csvPath, t + CSV_ROW);
4497
+ touched.push(NOTIFICATION_CSV);
4498
+ }
4499
+ }
4500
+ const htmlPath = import_path22.default.join(process.cwd(), RESEND_INVITE_HTML);
4501
+ (0, import_fs3.mkdirSync)(import_path22.default.dirname(htmlPath), { recursive: true });
4502
+ if (!(0, import_fs3.existsSync)(htmlPath)) {
4503
+ (0, import_fs3.writeFileSync)(htmlPath, RESEND_INVITE_HTML_CONTENT);
4504
+ touched.push(RESEND_INVITE_HTML);
4505
+ }
4506
+ if (touched.length === 0) {
4507
+ console.log(" Nothing to update (already present or anchors not found).");
4508
+ return;
4509
+ }
4510
+ console.log(` Updated:
4511
+ ${touched.map((f) => ` - ${f}`).join("\n")}`);
4512
+ }
4513
+
3443
4514
  // src/migrations/v2.0/simplify-analytics-precalculations.ts
3444
- var import_ts_morph16 = require("ts-morph");
3445
- var import_fs2 = __toESM(require("fs"));
3446
- var import_path17 = __toESM(require("path"));
4515
+ var import_ts_morph21 = require("ts-morph");
4516
+ var import_fs4 = __toESM(require("fs"));
4517
+ var import_path23 = __toESM(require("path"));
3447
4518
  var ANALYTICS_FILE_REL = "src/analytics/analytics.ts";
3448
4519
  var FUNCTION_NAME = "precalculateAdditionalAnalytics";
3449
4520
  var IMPORT_NAMES_TO_REMOVE = /* @__PURE__ */ new Set(["Event", "precalculateBirthEvent"]);
@@ -3479,10 +4550,10 @@ function findPrecalculateFunction(sourceFile) {
3479
4550
  return void 0;
3480
4551
  }
3481
4552
  function getFunctionBodyBlock(fn) {
3482
- if (import_ts_morph16.Node.isFunctionDeclaration(fn)) return fn.getBody();
4553
+ if (import_ts_morph21.Node.isFunctionDeclaration(fn)) return fn.getBody();
3483
4554
  const initializer = fn.getInitializer();
3484
4555
  if (!initializer) return void 0;
3485
- if (!import_ts_morph16.Node.isArrowFunction(initializer) && !import_ts_morph16.Node.isFunctionExpression(initializer)) {
4556
+ if (!import_ts_morph21.Node.isArrowFunction(initializer) && !import_ts_morph21.Node.isFunctionExpression(initializer)) {
3486
4557
  return void 0;
3487
4558
  }
3488
4559
  return initializer.getBody();
@@ -3492,9 +4563,9 @@ function simplifyPrecalculateFunction(sourceFile) {
3492
4563
  const fn = findPrecalculateFunction(sourceFile);
3493
4564
  if (!fn) return log;
3494
4565
  const body = getFunctionBodyBlock(fn);
3495
- if (!body || !import_ts_morph16.Node.isBlock(body)) return log;
4566
+ if (!body || !import_ts_morph21.Node.isBlock(body)) return log;
3496
4567
  for (const statement of [...body.getStatements()]) {
3497
- const references = statement.getDescendantsOfKind(import_ts_morph16.SyntaxKind.Identifier).some((id) => IMPORT_NAMES_TO_REMOVE.has(id.getText()));
4568
+ const references = statement.getDescendantsOfKind(import_ts_morph21.SyntaxKind.Identifier).some((id) => IMPORT_NAMES_TO_REMOVE.has(id.getText()));
3498
4569
  if (references) {
3499
4570
  statement.remove();
3500
4571
  log.push(`removed statement in ${FUNCTION_NAME} referencing removed imports`);
@@ -3502,7 +4573,7 @@ function simplifyPrecalculateFunction(sourceFile) {
3502
4573
  }
3503
4574
  const remaining = body.getStatements();
3504
4575
  const last = remaining[remaining.length - 1];
3505
- const alreadyCorrect = last && import_ts_morph16.Node.isReturnStatement(last) && last.getExpression()?.getText() === RETURN_EXPRESSION_TEXT;
4576
+ const alreadyCorrect = last && import_ts_morph21.Node.isReturnStatement(last) && last.getExpression()?.getText() === RETURN_EXPRESSION_TEXT;
3506
4577
  if (!alreadyCorrect) {
3507
4578
  body.addStatements(`return ${RETURN_EXPRESSION_TEXT}`);
3508
4579
  log.push(
@@ -3511,17 +4582,17 @@ function simplifyPrecalculateFunction(sourceFile) {
3511
4582
  }
3512
4583
  return log;
3513
4584
  }
3514
- async function main18() {
3515
- const cwd2 = getCwd();
3516
- const absPath = import_path17.default.join(cwd2, ANALYTICS_FILE_REL);
3517
- if (!import_fs2.default.existsSync(absPath)) {
4585
+ async function main24() {
4586
+ const cwd = process.cwd();
4587
+ const absPath = import_path23.default.join(cwd, ANALYTICS_FILE_REL);
4588
+ if (!import_fs4.default.existsSync(absPath)) {
3518
4589
  console.log(
3519
4590
  `[${ANALYTICS_FILE_REL}] does not exist \u2014 nothing to clean up.`
3520
4591
  );
3521
4592
  return;
3522
4593
  }
3523
- const project = new import_ts_morph16.Project({
3524
- tsConfigFilePath: import_path17.default.resolve(cwd2, "tsconfig.json"),
4594
+ const project = new import_ts_morph21.Project({
4595
+ tsConfigFilePath: import_path23.default.resolve(cwd, "tsconfig.json"),
3525
4596
  skipAddingFilesFromTsConfig: false
3526
4597
  });
3527
4598
  const sourceFile = project.getSourceFile(absPath);
@@ -3548,26 +4619,158 @@ async function main18() {
3548
4619
  Saved ${ANALYTICS_FILE_REL}.`);
3549
4620
  }
3550
4621
 
3551
- // src/migrations/v2.0/index.ts
3552
- var cwd;
3553
- function getCwd() {
3554
- if (!cwd) {
3555
- throw new Error("Country config working directory not set.");
4622
+ // src/migrations/v2.0/merge-infrastructure-directory.ts
4623
+ var import_child_process2 = require("child_process");
4624
+ var import_fs5 = require("fs");
4625
+ var import_os = require("os");
4626
+ var import_path24 = require("path");
4627
+ var TEMP_REMOTE2 = "opencrvs-upgrade-v19-v20-codemod-merge-infra";
4628
+ var INFRASTRUCTURE_DIR = "infrastructure";
4629
+ var BASE_BRANCH = "release-v1.9";
4630
+ function gitShowBytes(ref, path23) {
4631
+ try {
4632
+ const buf = (0, import_child_process2.execFileSync)("git", ["show", `${ref}:${path23}`], {
4633
+ cwd: process.cwd(),
4634
+ stdio: ["ignore", "pipe", "pipe"]
4635
+ });
4636
+ return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
4637
+ } catch {
4638
+ return null;
3556
4639
  }
3557
- return cwd;
3558
4640
  }
3559
- async function runUpgrade(ccwd) {
3560
- if (ccwd) {
3561
- console.log("Country config working directory:", ccwd);
3562
- cwd = ccwd;
4641
+ async function main25() {
4642
+ console.log(
4643
+ `Merging '${INFRASTRUCTURE_DIR}/' from ${UPSTREAM_URL}@${UPSTREAM_BRANCH} (base: ${BASE_BRANCH})...
4644
+ `
4645
+ );
4646
+ assertIsGitRepo();
4647
+ tryGit(["remote", "remove", TEMP_REMOTE2]);
4648
+ try {
4649
+ console.log(` Adding temporary remote '${TEMP_REMOTE2}' \u2192 ${UPSTREAM_URL}`);
4650
+ runGit(["remote", "add", TEMP_REMOTE2, UPSTREAM_URL], { silent: true });
4651
+ console.log(
4652
+ ` Fetching ${TEMP_REMOTE2}/{${UPSTREAM_BRANCH},${BASE_BRANCH}} (depth 1)...`
4653
+ );
4654
+ runGit(["fetch", "--depth=1", TEMP_REMOTE2, UPSTREAM_BRANCH, BASE_BRANCH]);
4655
+ const ref = `${TEMP_REMOTE2}/${UPSTREAM_BRANCH}`;
4656
+ const baseRef = `${TEMP_REMOTE2}/${BASE_BRANCH}`;
4657
+ const upstreamFiles = runGit(
4658
+ [
4659
+ "ls-tree",
4660
+ "-r",
4661
+ "--name-only",
4662
+ "-z",
4663
+ ref,
4664
+ "--",
4665
+ `${INFRASTRUCTURE_DIR}/`
4666
+ ],
4667
+ { silent: true }
4668
+ ).split("\0").filter(Boolean);
4669
+ if (upstreamFiles.length === 0) {
4670
+ console.log(
4671
+ ` No files found under '${INFRASTRUCTURE_DIR}/' on ${ref}. Nothing to merge.`
4672
+ );
4673
+ return;
4674
+ }
4675
+ const tmpDir = (0, import_fs5.mkdtempSync)((0, import_path24.join)((0, import_os.tmpdir)(), "opencrvs-merge-infra-"));
4676
+ const baseTmp = (0, import_path24.join)(tmpDir, "base");
4677
+ const theirsTmp = (0, import_path24.join)(tmpDir, "theirs");
4678
+ let added = 0;
4679
+ let merged = 0;
4680
+ const conflictedFiles = [];
4681
+ for (const file of upstreamFiles) {
4682
+ const fullPath = (0, import_path24.join)(process.cwd(), file);
4683
+ if (!(0, import_fs5.existsSync)(fullPath)) {
4684
+ if (tryGit(["checkout", ref, "--", file])) {
4685
+ console.log(` + ${file} (new from upstream)`);
4686
+ added++;
4687
+ } else {
4688
+ console.warn(` [warn] failed to add new file ${file}`);
4689
+ }
4690
+ continue;
4691
+ }
4692
+ const theirContents = gitShowBytes(ref, file);
4693
+ if (theirContents === null) {
4694
+ console.warn(` [warn] could not read ${file} from ${ref} \u2014 skipping.`);
4695
+ continue;
4696
+ }
4697
+ (0, import_fs5.writeFileSync)(theirsTmp, theirContents);
4698
+ const baseContents = gitShowBytes(baseRef, file);
4699
+ (0, import_fs5.writeFileSync)(baseTmp, baseContents ?? new Uint8Array(0));
4700
+ try {
4701
+ (0, import_child_process2.execFileSync)("git", ["merge-file", fullPath, baseTmp, theirsTmp], {
4702
+ cwd: process.cwd(),
4703
+ stdio: ["ignore", "pipe", "pipe"]
4704
+ });
4705
+ runGit(["add", "--", file], { silent: true });
4706
+ merged++;
4707
+ } catch (err) {
4708
+ const status = err.status;
4709
+ if (typeof status === "number" && status > 0) {
4710
+ conflictedFiles.push(file);
4711
+ console.warn(
4712
+ ` ! ${file} (${status} conflict${status > 1 ? "s" : ""})`
4713
+ );
4714
+ } else {
4715
+ conflictedFiles.push(file);
4716
+ console.warn(
4717
+ ` [warn] merge failed for ${file} (likely binary or unreadable) \u2014 left untouched.`
4718
+ );
4719
+ }
4720
+ }
4721
+ }
4722
+ console.log(
4723
+ `
4724
+ Done. ${added} added, ${merged} merged cleanly, ${conflictedFiles.length} with conflicts.`
4725
+ );
4726
+ if (conflictedFiles.length > 0) {
4727
+ console.warn(
4728
+ `
4729
+ NOTE: ${conflictedFiles.length} file(s) under '${INFRASTRUCTURE_DIR}/' have merge conflicts that you must resolve manually.
4730
+ Look for the standard conflict markers (<<<<<<<, =======, >>>>>>>) in:
4731
+ ` + conflictedFiles.map((f) => ` - ${f}`).join("\n") + `
4732
+ After resolving, stage the fixes with: git add ${INFRASTRUCTURE_DIR}/`
4733
+ );
4734
+ }
4735
+ } finally {
4736
+ if (tryGit(["remote", "remove", TEMP_REMOTE2])) {
4737
+ console.log(` Removed temporary remote '${TEMP_REMOTE2}'.`);
4738
+ }
3563
4739
  }
3564
- if (!ccwd) {
4740
+ }
4741
+
4742
+ // src/migrations/v2.0/delete-infrastructure-directory.ts
4743
+ var import_fs6 = require("fs");
4744
+ var import_path25 = require("path");
4745
+ var INFRASTRUCTURE_DIR2 = "infrastructure";
4746
+ async function main26() {
4747
+ const fullPath = (0, import_path25.join)(process.cwd(), INFRASTRUCTURE_DIR2);
4748
+ if (!(0, import_fs6.existsSync)(fullPath)) {
3565
4749
  console.log(
3566
- "Will use current working directory as country config working directory."
4750
+ `'${INFRASTRUCTURE_DIR2}/' not found in ${process.cwd()} \u2014 nothing to delete.`
3567
4751
  );
3568
- cwd = process.cwd();
4752
+ return;
3569
4753
  }
3570
- await main13();
4754
+ console.log(`Deleting '${INFRASTRUCTURE_DIR2}/'...
4755
+ `);
4756
+ assertIsGitRepo();
4757
+ runGit(["rm", "-rf", "--ignore-unmatch", "--", `${INFRASTRUCTURE_DIR2}/`], {
4758
+ silent: true
4759
+ });
4760
+ console.log(` Staged deletion of tracked files under '${INFRASTRUCTURE_DIR2}/'.`);
4761
+ if ((0, import_fs6.existsSync)(fullPath)) {
4762
+ (0, import_fs6.rmSync)(fullPath, { recursive: true, force: true });
4763
+ console.log(` Removed remaining untracked files under '${INFRASTRUCTURE_DIR2}/'.`);
4764
+ }
4765
+ console.log(
4766
+ `
4767
+ Done. Review the staged deletion with: git diff --cached -- '${INFRASTRUCTURE_DIR2}/'`
4768
+ );
4769
+ }
4770
+
4771
+ // src/migrations/v2.0/index.ts
4772
+ async function runUpgrade(dockerSwarm) {
4773
+ await main18();
3571
4774
  await main();
3572
4775
  await main2();
3573
4776
  await main3();
@@ -3580,11 +4783,22 @@ async function runUpgrade(ccwd) {
3580
4783
  await main10();
3581
4784
  await main11();
3582
4785
  await main12();
4786
+ await main13();
3583
4787
  await main14();
3584
4788
  await main15();
3585
4789
  await main16();
4790
+ await main19();
4791
+ await main20();
4792
+ await main21();
4793
+ await main22();
4794
+ await main23();
4795
+ await main24();
3586
4796
  await main17();
3587
- await main18();
4797
+ if (dockerSwarm) {
4798
+ await main25();
4799
+ } else {
4800
+ await main26();
4801
+ }
3588
4802
  }
3589
4803
 
3590
4804
  // src/cli.ts
@@ -3599,7 +4813,20 @@ Commands:
3599
4813
 
3600
4814
  Run 'opencrvs <command> --help' for more information on a command.
3601
4815
  `.trim();
3602
- function main19() {
4816
+ var UPGRADE_USAGE = `
4817
+ Usage: opencrvs upgrade [options]
4818
+
4819
+ Upgrade the country config in the current working directory to the next
4820
+ major version of OpenCRVS.
4821
+
4822
+ Options:
4823
+ --docker-swarm Keep and merge the 'infrastructure/' directory with
4824
+ upstream changes. Use this if your country deploys
4825
+ OpenCRVS via Docker Swarm. When omitted, the
4826
+ 'infrastructure/' directory is deleted (default).
4827
+ -h, --help Show this message.
4828
+ `.trim();
4829
+ function main27() {
3603
4830
  const command = args[0];
3604
4831
  if (!command || command === "--help" || command === "-h") {
3605
4832
  console.log(USAGE);
@@ -3644,10 +4871,25 @@ Subcommands:
3644
4871
  }
3645
4872
  }
3646
4873
  async function handleUpgrade() {
4874
+ const upgradeArgs = args.slice(1);
4875
+ if (upgradeArgs.includes("--help") || upgradeArgs.includes("-h")) {
4876
+ console.log(UPGRADE_USAGE);
4877
+ process.exit(0);
4878
+ }
4879
+ const KNOWN_FLAGS = /* @__PURE__ */ new Set(["--docker-swarm"]);
4880
+ const unknownFlags = upgradeArgs.filter(
4881
+ (arg) => arg.startsWith("-") && !KNOWN_FLAGS.has(arg)
4882
+ );
4883
+ if (unknownFlags.length > 0) {
4884
+ console.error(`Unknown option(s): ${unknownFlags.join(", ")}
4885
+ `);
4886
+ console.log(UPGRADE_USAGE);
4887
+ process.exit(1);
4888
+ }
4889
+ const dockerSwarm = upgradeArgs.includes("--docker-swarm");
3647
4890
  console.log("Initiating upgrade...");
3648
4891
  try {
3649
- const pathToCountryconfig = args[1];
3650
- await runUpgrade(pathToCountryconfig);
4892
+ await runUpgrade(dockerSwarm);
3651
4893
  console.log("Upgrade completed successfully!");
3652
4894
  } catch (error) {
3653
4895
  console.error("Upgrade failed:", error);
@@ -3659,4 +4901,4 @@ function handleCheckTranslations() {
3659
4901
  console.warn("This command is not implemented yet!");
3660
4902
  process.exit(1);
3661
4903
  }
3662
- main19();
4904
+ main27();