@opencrvs/toolkit 2.0.0-rc.2625051 → 2.0.0-rc.2e68bac

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 (72) hide show
  1. package/dist/application-config/index.js +4 -4
  2. package/dist/cli.js +1417 -167
  3. package/dist/commons/api/router.d.ts +55 -54
  4. package/dist/commons/application-config/index.d.ts +16 -4
  5. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts.map +1 -1
  6. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.js +63 -39
  7. package/dist/migrations/v2.0/add-resend-invite-notification.d.ts +3 -0
  8. package/dist/migrations/v2.0/add-resend-invite-notification.d.ts.map +1 -0
  9. package/dist/migrations/v2.0/add-resend-invite-notification.js +373 -0
  10. package/dist/migrations/v2.0/checkout-upstream-files.d.ts +19 -0
  11. package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +1 -1
  12. package/dist/migrations/v2.0/checkout-upstream-files.js +17 -13
  13. package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts.map +1 -1
  14. package/dist/migrations/v2.0/convert-config-files-to-ts.js +4 -5
  15. package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts.map +1 -1
  16. package/dist/migrations/v2.0/convert-paragraph-to-heading.js +4 -5
  17. package/dist/migrations/v2.0/create-events-index.d.ts.map +1 -1
  18. package/dist/migrations/v2.0/create-events-index.js +1 -2
  19. package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts +3 -0
  20. package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts.map +1 -0
  21. package/dist/migrations/v2.0/delete-infrastructure-directory.js +77 -0
  22. package/dist/migrations/v2.0/index.d.ts +8 -4
  23. package/dist/migrations/v2.0/index.d.ts.map +1 -1
  24. package/dist/migrations/v2.0/index.js +1385 -164
  25. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts.map +1 -1
  26. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.js +5 -6
  27. package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts +3 -0
  28. package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts.map +1 -0
  29. package/dist/migrations/v2.0/merge-infrastructure-directory.js +221 -0
  30. package/dist/migrations/v2.0/migrate-application-config-url.d.ts +3 -0
  31. package/dist/migrations/v2.0/migrate-application-config-url.d.ts.map +1 -0
  32. package/dist/migrations/v2.0/migrate-application-config-url.js +342 -0
  33. package/dist/migrations/v2.0/migrate-scopes.d.ts.map +1 -1
  34. package/dist/migrations/v2.0/migrate-scopes.js +6 -7
  35. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts.map +1 -1
  36. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.js +3 -4
  37. package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts.map +1 -1
  38. package/dist/migrations/v2.0/migrate-workqueue-configs.js +3 -4
  39. package/dist/migrations/v2.0/remove-delete-actions.d.ts.map +1 -1
  40. package/dist/migrations/v2.0/remove-delete-actions.js +3 -4
  41. package/dist/migrations/v2.0/remove-demo-scope.d.ts.map +1 -1
  42. package/dist/migrations/v2.0/remove-demo-scope.js +2 -3
  43. package/dist/migrations/v2.0/remove-deprecated-imports.d.ts.map +1 -1
  44. package/dist/migrations/v2.0/remove-deprecated-imports.js +3 -4
  45. package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts +3 -0
  46. package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts.map +1 -0
  47. package/dist/migrations/v2.0/remove-fhir-url-helpers.js +163 -0
  48. package/dist/migrations/v2.0/remove-hearth-migrations.d.ts.map +1 -1
  49. package/dist/migrations/v2.0/remove-hearth-migrations.js +1 -2
  50. package/dist/migrations/v2.0/remove-old-statistics-service.d.ts +3 -0
  51. package/dist/migrations/v2.0/remove-old-statistics-service.d.ts.map +1 -0
  52. package/dist/migrations/v2.0/remove-old-statistics-service.js +356 -0
  53. package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts.map +1 -1
  54. package/dist/migrations/v2.0/remove-pending-certification-flag.js +3 -4
  55. package/dist/migrations/v2.0/remove-review-from-register-action.d.ts.map +1 -1
  56. package/dist/migrations/v2.0/remove-review-from-register-action.js +3 -4
  57. package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts +3 -0
  58. package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts.map +1 -0
  59. package/dist/migrations/v2.0/remove-unused-environment-variables.js +186 -0
  60. package/dist/migrations/v2.0/rename-api-paths.d.ts.map +1 -1
  61. package/dist/migrations/v2.0/rename-api-paths.js +3 -4
  62. package/dist/migrations/v2.0/rename-location-parent-id.d.ts.map +1 -1
  63. package/dist/migrations/v2.0/rename-location-parent-id.js +3 -4
  64. package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts.map +1 -1
  65. package/dist/migrations/v2.0/simplify-analytics-precalculations.js +1 -2
  66. package/dist/migrations/v2.0/update-package-json.d.ts +3 -0
  67. package/dist/migrations/v2.0/update-package-json.d.ts.map +1 -0
  68. package/dist/migrations/v2.0/update-package-json.js +105 -0
  69. package/opencrvs-toolkit-2.0.0-rc.2e68bac.tgz +0 -0
  70. package/package.json +1 -1
  71. package/tsconfig.tsbuildinfo +1 -1
  72. package/opencrvs-toolkit-2.0.0-rc.2625051.tgz +0 -0
@@ -31,7 +31,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
31
  // src/migrations/v2.0/index.ts
32
32
  var v2_exports = {};
33
33
  __export(v2_exports, {
34
- getCwd: () => getCwd,
35
34
  runUpgrade: () => runUpgrade
36
35
  });
37
36
  module.exports = __toCommonJS(v2_exports);
@@ -104,7 +103,7 @@ function processFile(filePath, project) {
104
103
  if (wasRemoved) {
105
104
  removedCount++;
106
105
  console.log(
107
- ` [${import_path.default.relative(getCwd(), filePath)}] Removed 'review' from REGISTER action`
106
+ ` [${import_path.default.relative(process.cwd(), filePath)}] Removed 'review' from REGISTER action`
108
107
  );
109
108
  }
110
109
  }
@@ -112,7 +111,7 @@ function processFile(filePath, project) {
112
111
  return removedCount;
113
112
  }
114
113
  async function main() {
115
- const srcDir = import_path.default.join(getCwd(), "src");
114
+ const srcDir = import_path.default.join(process.cwd(), "src");
116
115
  console.log(`Scanning for defineConfig calls in: ${srcDir}
117
116
  `);
118
117
  const project = new import_ts_morph.Project({
@@ -148,7 +147,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
148
147
  for (const filePath of modifiedFiles) {
149
148
  const sourceFile = project.getSourceFileOrThrow(filePath);
150
149
  await sourceFile.save();
151
- console.log(` Saved: ${import_path.default.relative(getCwd(), filePath)}`);
150
+ console.log(` Saved: ${import_path.default.relative(process.cwd(), filePath)}`);
152
151
  }
153
152
  console.log(
154
153
  `
@@ -351,7 +350,7 @@ function processFile2(filePath, project) {
351
350
  const eventType = resolveEventType(configArg);
352
351
  if (!eventType) {
353
352
  console.warn(
354
- ` [${import_path2.default.relative(getCwd(), configArg.getSourceFile().getFilePath())}] Could not resolve root 'type' from defineConfig \u2014 skipping auditHistoryLabel id generation`
353
+ ` [${import_path2.default.relative(process.cwd(), configArg.getSourceFile().getFilePath())}] Could not resolve root 'type' from defineConfig \u2014 skipping auditHistoryLabel id generation`
355
354
  );
356
355
  }
357
356
  let fileNeedsImports = false;
@@ -367,7 +366,7 @@ function processFile2(filePath, project) {
367
366
  fileNeedsImports = true;
368
367
  configHadValidateAction = true;
369
368
  console.log(
370
- ` [${import_path2.default.relative(getCwd(), filePath)}] Transformed VALIDATE action to CUSTOM with customActionType: '${VALIDATE_DECLARATION_VALUE}'`
369
+ ` [${import_path2.default.relative(process.cwd(), filePath)}] Transformed VALIDATE action to CUSTOM with customActionType: '${VALIDATE_DECLARATION_VALUE}'`
371
370
  );
372
371
  }
373
372
  }
@@ -388,7 +387,7 @@ function processFile2(filePath, project) {
388
387
  ]`
389
388
  });
390
389
  console.log(
391
- ` [${import_path2.default.relative(getCwd(), filePath)}] Added top-level 'flags' array to defineConfig`
390
+ ` [${import_path2.default.relative(process.cwd(), filePath)}] Added top-level 'flags' array to defineConfig`
392
391
  );
393
392
  }
394
393
  if (fileNeedsImports) {
@@ -398,7 +397,7 @@ function processFile2(filePath, project) {
398
397
  return transformedCount;
399
398
  }
400
399
  async function main2() {
401
- const srcDir = import_path2.default.join(getCwd(), "src");
400
+ const srcDir = import_path2.default.join(process.cwd(), "src");
402
401
  console.log(`Scanning for defineConfig calls in: ${srcDir}
403
402
  `);
404
403
  const project = new import_ts_morph2.Project({
@@ -433,7 +432,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
433
432
  for (const filePath of modifiedFiles) {
434
433
  const sourceFile = project.getSourceFileOrThrow(filePath);
435
434
  await sourceFile.save();
436
- console.log(` Saved: ${import_path2.default.relative(getCwd(), filePath)}`);
435
+ console.log(` Saved: ${import_path2.default.relative(process.cwd(), filePath)}`);
437
436
  }
438
437
  console.log(
439
438
  `
@@ -504,14 +503,14 @@ function processFile3(filePath, project) {
504
503
  actionsInitializer.removeElement(index);
505
504
  removedCount++;
506
505
  console.log(
507
- ` [${import_path3.default.relative(getCwd(), filePath)}] Removed DELETE action at index ${index}`
506
+ ` [${import_path3.default.relative(process.cwd(), filePath)}] Removed DELETE action at index ${index}`
508
507
  );
509
508
  }
510
509
  }
511
510
  return removedCount;
512
511
  }
513
512
  async function main3() {
514
- const srcDir = import_path3.default.join(getCwd(), "src");
513
+ const srcDir = import_path3.default.join(process.cwd(), "src");
515
514
  console.log(`Scanning for defineConfig calls in: ${srcDir}
516
515
  `);
517
516
  const project = new import_ts_morph3.Project({
@@ -546,7 +545,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
546
545
  for (const filePath of modifiedFiles) {
547
546
  const sourceFile = project.getSourceFileOrThrow(filePath);
548
547
  await sourceFile.save();
549
- console.log(` Saved: ${import_path3.default.relative(getCwd(), filePath)}`);
548
+ console.log(` Saved: ${import_path3.default.relative(process.cwd(), filePath)}`);
550
549
  }
551
550
  console.log(
552
551
  `
@@ -620,19 +619,19 @@ function processFile4(filePath, project) {
620
619
  if (result === "converted-to-heading") {
621
620
  changedCount++;
622
621
  console.log(
623
- ` [${import_path4.default.relative(getCwd(), filePath)}] Converted PARAGRAPH with heading fontVariant to HEADING`
622
+ ` [${import_path4.default.relative(process.cwd(), filePath)}] Converted PARAGRAPH with heading fontVariant to HEADING`
624
623
  );
625
624
  } else if (result === "removed-font-variant") {
626
625
  changedCount++;
627
626
  console.log(
628
- ` [${import_path4.default.relative(getCwd(), filePath)}] Removed non-heading fontVariant from PARAGRAPH`
627
+ ` [${import_path4.default.relative(process.cwd(), filePath)}] Removed non-heading fontVariant from PARAGRAPH`
629
628
  );
630
629
  }
631
630
  }
632
631
  return changedCount;
633
632
  }
634
633
  async function main4() {
635
- const srcDir = import_path4.default.join(getCwd(), "src");
634
+ const srcDir = import_path4.default.join(process.cwd(), "src");
636
635
  console.log(`Scanning for FieldType.PARAGRAPH fields in: ${srcDir}
637
636
  `);
638
637
  const project = new import_ts_morph4.Project({
@@ -666,7 +665,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
666
665
  for (const filePath of modifiedFiles) {
667
666
  const sourceFile = project.getSourceFileOrThrow(filePath);
668
667
  await sourceFile.save();
669
- console.log(` Saved: ${import_path4.default.relative(getCwd(), filePath)}`);
668
+ console.log(` Saved: ${import_path4.default.relative(process.cwd(), filePath)}`);
670
669
  }
671
670
  console.log(`
672
671
  Done. Processed ${totalChanged} FieldType.PARAGRAPH field(s).`);
@@ -816,7 +815,7 @@ function processFile5(filePath, project) {
816
815
  if (changed > 0) {
817
816
  migratedCount += changed;
818
817
  console.log(
819
- ` [${import_path5.default.relative(getCwd(), filePath)}] Migrated ${changed} clause(s): VALIDATED status \u2192 flags.anyOf`
818
+ ` [${import_path5.default.relative(process.cwd(), filePath)}] Migrated ${changed} clause(s): VALIDATED status \u2192 flags.anyOf`
820
819
  );
821
820
  }
822
821
  }
@@ -824,7 +823,7 @@ function processFile5(filePath, project) {
824
823
  return migratedCount;
825
824
  }
826
825
  async function main5() {
827
- const srcDir = import_path5.default.join(getCwd(), "src");
826
+ const srcDir = import_path5.default.join(process.cwd(), "src");
828
827
  console.log(`Scanning for defineWorkqueues calls in: ${srcDir}
829
828
  `);
830
829
  const project = new import_ts_morph5.Project({
@@ -858,7 +857,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
858
857
  for (const filePath of modifiedFiles) {
859
858
  const sourceFile = project.getSourceFileOrThrow(filePath);
860
859
  await sourceFile.save();
861
- console.log(` Saved: ${import_path5.default.relative(getCwd(), filePath)}`);
860
+ console.log(` Saved: ${import_path5.default.relative(process.cwd(), filePath)}`);
862
861
  }
863
862
  console.log(
864
863
  `
@@ -876,20 +875,23 @@ var ACTION_PROPERTY_NAME = "action";
876
875
  var FLAGS_PROPERTY_NAME2 = "flags";
877
876
  var QUERY_PROPERTY_NAME2 = "query";
878
877
  var TYPE_PROPERTY_NAME6 = "type";
878
+ var ID_PROPERTY_NAME = "id";
879
879
  var CLAUSES_PROPERTY_NAME2 = "clauses";
880
880
  var ANY_OF_PROPERTY_NAME2 = "anyOf";
881
881
  var FLAG_ID = "pending-first-certificate-issuance";
882
882
  var REGISTER_TYPE = "REGISTER";
883
883
  var PRINT_CERTIFICATE_TYPE = "PRINT_CERTIFICATE";
884
- var FLAG_DEFINITION_INITIALIZER = `{
884
+ function flagDefinitionInitializer(eventType) {
885
+ return `{
885
886
  id: '${FLAG_ID}',
886
887
  label: {
887
- id: 'event.birth.flag.${FLAG_ID}',
888
+ id: 'event.${eventType}.flag.${FLAG_ID}',
888
889
  defaultMessage: 'Pending first certificate issuance',
889
890
  description: 'Flag label for first certificate issuance'
890
891
  },
891
892
  requiresAction: true
892
893
  }`;
894
+ }
893
895
  function isActionOfType(obj, typeName) {
894
896
  const typeProperty = obj.getProperty(TYPE_PROPERTY_NAME6);
895
897
  if (!typeProperty || !import_ts_morph6.Node.isPropertyAssignment(typeProperty)) return false;
@@ -903,18 +905,20 @@ function isActionOfType(obj, typeName) {
903
905
  }
904
906
  return false;
905
907
  }
906
- function isBirthConfig(configArg) {
907
- const typeProperty = configArg.getProperty(TYPE_PROPERTY_NAME6);
908
- if (!typeProperty || !import_ts_morph6.Node.isPropertyAssignment(typeProperty)) return false;
909
- const initializer = typeProperty.getInitializer();
910
- if (!initializer) return false;
911
- if (import_ts_morph6.Node.isStringLiteral(initializer)) {
912
- return initializer.getLiteralValue().toLowerCase() === "birth";
913
- }
914
- if (import_ts_morph6.Node.isPropertyAccessExpression(initializer)) {
915
- return initializer.getName().toLowerCase() === "birth";
908
+ function getEventType(configArg) {
909
+ for (const propName of [TYPE_PROPERTY_NAME6, ID_PROPERTY_NAME]) {
910
+ const prop = configArg.getProperty(propName);
911
+ if (!prop || !import_ts_morph6.Node.isPropertyAssignment(prop)) continue;
912
+ const initializer = prop.getInitializer();
913
+ if (!initializer) continue;
914
+ if (import_ts_morph6.Node.isStringLiteral(initializer)) {
915
+ return initializer.getLiteralValue().toLowerCase();
916
+ }
917
+ if (import_ts_morph6.Node.isPropertyAccessExpression(initializer)) {
918
+ return initializer.getName().toLowerCase();
919
+ }
916
920
  }
917
- return false;
921
+ return null;
918
922
  }
919
923
  function hasElementWithId(array3, id) {
920
924
  for (const el of array3.getElements()) {
@@ -928,13 +932,14 @@ function hasElementWithId(array3, id) {
928
932
  }
929
933
  return false;
930
934
  }
931
- function ensureTopLevelFlagDefinition(configArg) {
935
+ function ensureTopLevelFlagDefinition(configArg, eventType) {
936
+ const initializer = flagDefinitionInitializer(eventType);
932
937
  const flagsProp = configArg.getProperty(FLAGS_PROPERTY_NAME2);
933
938
  if (flagsProp && import_ts_morph6.Node.isPropertyAssignment(flagsProp)) {
934
939
  const flagsInit = flagsProp.getInitializer();
935
940
  if (flagsInit && import_ts_morph6.Node.isArrayLiteralExpression(flagsInit)) {
936
941
  if (hasElementWithId(flagsInit, FLAG_ID)) return false;
937
- flagsInit.addElement(FLAG_DEFINITION_INITIALIZER);
942
+ flagsInit.addElement(initializer);
938
943
  return true;
939
944
  }
940
945
  return false;
@@ -942,7 +947,7 @@ function ensureTopLevelFlagDefinition(configArg) {
942
947
  configArg.addPropertyAssignment({
943
948
  name: FLAGS_PROPERTY_NAME2,
944
949
  initializer: `[
945
- ${FLAG_DEFINITION_INITIALIZER}
950
+ ${initializer}
946
951
  ]`
947
952
  });
948
953
  return true;
@@ -965,11 +970,13 @@ function ensureActionOperationFlag(action, operation) {
965
970
  });
966
971
  return true;
967
972
  }
968
- function processBirthConfig(configArg, relPath) {
973
+ function processConfig(configArg, eventType, relPath) {
969
974
  let changes = 0;
970
- if (ensureTopLevelFlagDefinition(configArg)) {
975
+ if (ensureTopLevelFlagDefinition(configArg, eventType)) {
971
976
  changes++;
972
- console.log(` [${relPath}] Added '${FLAG_ID}' to top-level flags`);
977
+ console.log(
978
+ ` [${relPath}] (${eventType}) Added '${FLAG_ID}' to top-level flags`
979
+ );
973
980
  }
974
981
  const actionsProp = configArg.getProperty(ACTIONS_PROPERTY_NAME4);
975
982
  if (!actionsProp || !import_ts_morph6.Node.isPropertyAssignment(actionsProp)) return changes;
@@ -983,7 +990,7 @@ function processBirthConfig(configArg, relPath) {
983
990
  if (ensureActionOperationFlag(element, "add")) {
984
991
  changes++;
985
992
  console.log(
986
- ` [${relPath}] Added '${FLAG_ID}' add-flag to REGISTER action`
993
+ ` [${relPath}] (${eventType}) Added '${FLAG_ID}' add-flag to REGISTER action`
987
994
  );
988
995
  }
989
996
  }
@@ -991,7 +998,7 @@ function processBirthConfig(configArg, relPath) {
991
998
  if (ensureActionOperationFlag(element, "remove")) {
992
999
  changes++;
993
1000
  console.log(
994
- ` [${relPath}] Added '${FLAG_ID}' remove-flag to PRINT_CERTIFICATE action`
1001
+ ` [${relPath}] (${eventType}) Added '${FLAG_ID}' remove-flag to PRINT_CERTIFICATE action`
995
1002
  );
996
1003
  }
997
1004
  }
@@ -1076,7 +1083,7 @@ function processFile6(filePath, project) {
1076
1083
  const sourceFile = project.getSourceFile(filePath);
1077
1084
  if (!sourceFile) return 0;
1078
1085
  let totalChanges = 0;
1079
- const relPath = import_path6.default.relative(getCwd(), filePath);
1086
+ const relPath = import_path6.default.relative(process.cwd(), filePath);
1080
1087
  const callExpressions = sourceFile.getDescendantsOfKind(
1081
1088
  import_ts_morph6.SyntaxKind.CallExpression
1082
1089
  );
@@ -1089,8 +1096,9 @@ function processFile6(filePath, project) {
1089
1096
  if (args.length === 0) continue;
1090
1097
  const configArg = args[0];
1091
1098
  if (!import_ts_morph6.Node.isObjectLiteralExpression(configArg)) continue;
1092
- if (!isBirthConfig(configArg)) continue;
1093
- totalChanges += processBirthConfig(configArg, relPath);
1099
+ const eventType = getEventType(configArg);
1100
+ if (!eventType) continue;
1101
+ totalChanges += processConfig(configArg, eventType, relPath);
1094
1102
  }
1095
1103
  if (calleeName === DEFINE_WORKQUEUES_NAME2) {
1096
1104
  const args = call.getArguments();
@@ -1117,9 +1125,9 @@ function processFile6(filePath, project) {
1117
1125
  return totalChanges;
1118
1126
  }
1119
1127
  async function main6() {
1120
- const srcDir = import_path6.default.join(getCwd(), "src");
1128
+ const srcDir = import_path6.default.join(process.cwd(), "src");
1121
1129
  console.log(
1122
- `Scanning for birth defineConfig and PRINT_CERTIFICATE workqueues in: ${srcDir}
1130
+ `Scanning for defineConfig and PRINT_CERTIFICATE workqueues in: ${srcDir}
1123
1131
  `
1124
1132
  );
1125
1133
  const project = new import_ts_morph6.Project({
@@ -1144,7 +1152,7 @@ async function main6() {
1144
1152
  }
1145
1153
  if (modifiedFiles.length === 0) {
1146
1154
  console.log(
1147
- "No birth configs or PRINT_CERTIFICATE workqueues found. Nothing to do."
1155
+ "No event configs or PRINT_CERTIFICATE workqueues found. Nothing to do."
1148
1156
  );
1149
1157
  return;
1150
1158
  }
@@ -1153,7 +1161,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
1153
1161
  for (const filePath of modifiedFiles) {
1154
1162
  const sourceFile = project.getSourceFileOrThrow(filePath);
1155
1163
  await sourceFile.save();
1156
- console.log(` Saved: ${import_path6.default.relative(getCwd(), filePath)}`);
1164
+ console.log(` Saved: ${import_path6.default.relative(process.cwd(), filePath)}`);
1157
1165
  }
1158
1166
  console.log(
1159
1167
  `
@@ -1190,14 +1198,14 @@ function processFile7(filePath, project) {
1190
1198
  array3.removeElement(index);
1191
1199
  removedCount++;
1192
1200
  console.log(
1193
- ` [${import_path7.default.relative(getCwd(), filePath)}] Removed InherentFlags.PENDING_CERTIFICATION from array`
1201
+ ` [${import_path7.default.relative(process.cwd(), filePath)}] Removed InherentFlags.PENDING_CERTIFICATION from array`
1194
1202
  );
1195
1203
  }
1196
1204
  }
1197
1205
  return removedCount;
1198
1206
  }
1199
1207
  async function main7() {
1200
- const srcDir = import_path7.default.join(getCwd(), "src");
1208
+ const srcDir = import_path7.default.join(process.cwd(), "src");
1201
1209
  console.log(
1202
1210
  `Scanning for InherentFlags.PENDING_CERTIFICATION array elements in: ${srcDir}
1203
1211
  `
@@ -1233,7 +1241,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
1233
1241
  for (const filePath of modifiedFiles) {
1234
1242
  const sourceFile = project.getSourceFileOrThrow(filePath);
1235
1243
  await sourceFile.save();
1236
- console.log(` Saved: ${import_path7.default.relative(getCwd(), filePath)}`);
1244
+ console.log(` Saved: ${import_path7.default.relative(process.cwd(), filePath)}`);
1237
1245
  }
1238
1246
  console.log(
1239
1247
  `
@@ -1291,13 +1299,13 @@ function processFile8(filePath, project) {
1291
1299
  propAccess.getNameNode().replaceWithText(NEW_PROPERTY_NAME);
1292
1300
  renamedCount++;
1293
1301
  console.log(
1294
- ` [${import_path8.default.relative(getCwd(), filePath)}] Renamed Location.${OLD_PROPERTY_NAME} \u2192 Location.${NEW_PROPERTY_NAME}`
1302
+ ` [${import_path8.default.relative(process.cwd(), filePath)}] Renamed Location.${OLD_PROPERTY_NAME} \u2192 Location.${NEW_PROPERTY_NAME}`
1295
1303
  );
1296
1304
  }
1297
1305
  return renamedCount;
1298
1306
  }
1299
1307
  async function main8() {
1300
- const srcDir = import_path8.default.join(getCwd(), "src");
1308
+ const srcDir = import_path8.default.join(process.cwd(), "src");
1301
1309
  console.log(
1302
1310
  `Scanning for Location.${OLD_PROPERTY_NAME} references in: ${srcDir}
1303
1311
  `
@@ -1333,7 +1341,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
1333
1341
  for (const filePath of modifiedFiles) {
1334
1342
  const sourceFile = project.getSourceFileOrThrow(filePath);
1335
1343
  await sourceFile.save();
1336
- console.log(` Saved: ${import_path8.default.relative(getCwd(), filePath)}`);
1344
+ console.log(` Saved: ${import_path8.default.relative(process.cwd(), filePath)}`);
1337
1345
  }
1338
1346
  console.log(
1339
1347
  `
@@ -1400,7 +1408,7 @@ function processFile9(filePath, project) {
1400
1408
  const sourceFile = project.getSourceFile(filePath);
1401
1409
  if (!sourceFile) return 0;
1402
1410
  let renamedCount = 0;
1403
- const relPath = import_path9.default.relative(getCwd(), filePath);
1411
+ const relPath = import_path9.default.relative(process.cwd(), filePath);
1404
1412
  const candidates = sourceFile.getDescendantsOfKind(
1405
1413
  import_ts_morph9.SyntaxKind.ObjectLiteralExpression
1406
1414
  );
@@ -1415,7 +1423,7 @@ function processFile9(filePath, project) {
1415
1423
  return renamedCount;
1416
1424
  }
1417
1425
  async function main9() {
1418
- const srcDir = import_path9.default.join(getCwd(), "src");
1426
+ const srcDir = import_path9.default.join(process.cwd(), "src");
1419
1427
  console.log(`Scanning for Hapi route configs in: ${srcDir}
1420
1428
  `);
1421
1429
  console.log("Active path renames:");
@@ -1452,7 +1460,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
1452
1460
  for (const filePath of modifiedFiles) {
1453
1461
  const sourceFile = project.getSourceFileOrThrow(filePath);
1454
1462
  await sourceFile.save();
1455
- console.log(` Saved: ${import_path9.default.relative(getCwd(), filePath)}`);
1463
+ console.log(` Saved: ${import_path9.default.relative(process.cwd(), filePath)}`);
1456
1464
  }
1457
1465
  console.log(`
1458
1466
  Done. Renamed ${totalRenamed} route path(s).`);
@@ -1826,9 +1834,9 @@ function updateRouteHandlers(sourceFiles, group, srcDir, relCwd) {
1826
1834
  }
1827
1835
  return replacedCount;
1828
1836
  }
1829
- function resolveConfigChain(configObj, path17) {
1837
+ function resolveConfigChain(configObj, path23) {
1830
1838
  let current = configObj;
1831
- for (const key of path17) {
1839
+ for (const key of path23) {
1832
1840
  if (!import_ts_morph10.Node.isObjectLiteralExpression(current)) return null;
1833
1841
  const prop = current.getProperty(key);
1834
1842
  if (!prop || !import_ts_morph10.Node.isPropertyAssignment(prop)) return null;
@@ -1873,8 +1881,8 @@ function ensureJoinImport(sf) {
1873
1881
  });
1874
1882
  }
1875
1883
  async function main10() {
1876
- const srcDir = import_path10.default.join(getCwd(), "src");
1877
- const relCwd = (fp) => import_path10.default.relative(getCwd(), fp);
1884
+ const srcDir = import_path10.default.join(process.cwd(), "src");
1885
+ const relCwd = (fp) => import_path10.default.relative(process.cwd(), fp);
1878
1886
  console.log("Phase 1: Converting JS config files to TypeScript...\n");
1879
1887
  let convertedCount = 0;
1880
1888
  for (const group of CONFIG_GROUPS) {
@@ -1962,7 +1970,7 @@ async function main10() {
1962
1970
  ensureJoinImport(sf);
1963
1971
  }
1964
1972
  console.log(
1965
- ` Inlined applicationConfig.${accessPath.join(".")} \u2192 ${adjustedValue} in ${import_path10.default.relative(getCwd(), sf.getFilePath())}`
1973
+ ` Inlined applicationConfig.${accessPath.join(".")} \u2192 ${adjustedValue} in ${import_path10.default.relative(process.cwd(), sf.getFilePath())}`
1966
1974
  );
1967
1975
  filesToSaveAfterInlining.add(sf);
1968
1976
  madeReplacement = true;
@@ -1974,7 +1982,7 @@ async function main10() {
1974
1982
  for (const sf of Array.from(filesToSaveAfterInlining)) {
1975
1983
  await sf.save();
1976
1984
  console.log(
1977
- ` Saved (inlined): ${import_path10.default.relative(getCwd(), sf.getFilePath())}`
1985
+ ` Saved (inlined): ${import_path10.default.relative(process.cwd(), sf.getFilePath())}`
1978
1986
  );
1979
1987
  }
1980
1988
  for (const prop of [...propsToRemove].reverse()) {
@@ -2619,7 +2627,7 @@ function migrateScopesArrays(rolesFilePath, project) {
2619
2627
  const scopeKey = resolveScopeKeyFromElementAccess(element);
2620
2628
  if (scopeKey && !(scopeKey in SCOPES)) {
2621
2629
  console.warn(
2622
- ` [${import_path11.default.relative(getCwd(), rolesFilePath)}] Removing unknown scope reference: SCOPES.${scopeKey}`
2630
+ ` [${import_path11.default.relative(process.cwd(), rolesFilePath)}] Removing unknown scope reference: SCOPES.${scopeKey}`
2623
2631
  );
2624
2632
  initializer.removeElement(index);
2625
2633
  removedCount++;
@@ -2628,7 +2636,7 @@ function migrateScopesArrays(rolesFilePath, project) {
2628
2636
  const legacyScope = resolveLegacyScopeFromElement(element);
2629
2637
  if (!legacyScope) {
2630
2638
  console.warn(
2631
- ` [${import_path11.default.relative(getCwd(), rolesFilePath)}] Skipping non-literal scope expression: ${element.getText()}`
2639
+ ` [${import_path11.default.relative(process.cwd(), rolesFilePath)}] Skipping non-literal scope expression: ${element.getText()}`
2632
2640
  );
2633
2641
  continue;
2634
2642
  }
@@ -2637,7 +2645,7 @@ function migrateScopesArrays(rolesFilePath, project) {
2637
2645
  const scope = decodeScope(migratedScope);
2638
2646
  if (!scope) {
2639
2647
  console.warn(
2640
- ` [${import_path11.default.relative(getCwd(), rolesFilePath)}] Could not decode migrated scope '${migratedScope}'.`
2648
+ ` [${import_path11.default.relative(process.cwd(), rolesFilePath)}] Could not decode migrated scope '${migratedScope}'.`
2641
2649
  );
2642
2650
  continue;
2643
2651
  }
@@ -2645,14 +2653,14 @@ function migrateScopesArrays(rolesFilePath, project) {
2645
2653
  migratedCount++;
2646
2654
  } catch (error) {
2647
2655
  console.warn(
2648
- ` [${import_path11.default.relative(getCwd(), rolesFilePath)}] Could not migrate scope '${legacyScope}': ${error}`
2656
+ ` [${import_path11.default.relative(process.cwd(), rolesFilePath)}] Could not migrate scope '${legacyScope}': ${error}`
2649
2657
  );
2650
2658
  }
2651
2659
  }
2652
2660
  }
2653
2661
  if (removedCount > 0) {
2654
2662
  console.log(
2655
- ` Removed ${removedCount} unknown SCOPES reference(s) from '${import_path11.default.relative(getCwd(), rolesFilePath)}'.`
2663
+ ` Removed ${removedCount} unknown SCOPES reference(s) from '${import_path11.default.relative(process.cwd(), rolesFilePath)}'.`
2656
2664
  );
2657
2665
  }
2658
2666
  return { migratedCount, removedCount };
@@ -2774,9 +2782,9 @@ function removeRoleTypeDefinitionAndUnusedImports(rolesFilePath, project) {
2774
2782
  return removed;
2775
2783
  }
2776
2784
  async function main11() {
2777
- const cwd2 = getCwd();
2778
- const srcDir = import_path11.default.join(cwd2, "src");
2779
- const rolesFilePath = import_path11.default.join(cwd2, ROLES_FILE_RELATIVE_PATH);
2785
+ const cwd = process.cwd();
2786
+ const srcDir = import_path11.default.join(cwd, "src");
2787
+ const rolesFilePath = import_path11.default.join(cwd, ROLES_FILE_RELATIVE_PATH);
2780
2788
  console.log(`Scanning roles scopes in: ${rolesFilePath}`);
2781
2789
  const project = new import_ts_morph11.Project({
2782
2790
  tsConfigFilePath: import_path11.default.resolve(srcDir, "../tsconfig.json"),
@@ -2840,13 +2848,13 @@ function processFile10(filePath, project) {
2840
2848
  decl.remove();
2841
2849
  }
2842
2850
  console.log(
2843
- ` [${import_path12.default.relative(getCwd(), filePath)}] Removed ${matchingNamedImports.length} deprecated '${DEPRECATED_IMPORT}' import(s) from '${decl.getModuleSpecifierValue()}'`
2851
+ ` [${import_path12.default.relative(process.cwd(), filePath)}] Removed ${matchingNamedImports.length} deprecated '${DEPRECATED_IMPORT}' import(s) from '${decl.getModuleSpecifierValue()}'`
2844
2852
  );
2845
2853
  }
2846
2854
  return removedCount;
2847
2855
  }
2848
2856
  async function main12() {
2849
- const srcDir = import_path12.default.join(getCwd(), "src");
2857
+ const srcDir = import_path12.default.join(process.cwd(), "src");
2850
2858
  console.log(`Scanning for deprecated imports in: ${srcDir}
2851
2859
  `);
2852
2860
  const project = new import_ts_morph12.Project({
@@ -2877,15 +2885,738 @@ async function main12() {
2877
2885
  Saving ${modifiedFiles.length} modified file(s)...`);
2878
2886
  for (const filePath of modifiedFiles) {
2879
2887
  await project.getSourceFileOrThrow(filePath).save();
2880
- console.log(` Saved: ${import_path12.default.relative(getCwd(), filePath)}`);
2888
+ console.log(` Saved: ${import_path12.default.relative(process.cwd(), filePath)}`);
2881
2889
  }
2882
2890
  console.log(`
2883
2891
  Done. Removed ${totalRemoved} deprecated import(s).`);
2884
2892
  }
2885
2893
 
2886
- // src/migrations/v2.0/migrate-workqueue-configs.ts
2887
- var import_ts_morph13 = require("ts-morph");
2894
+ // src/migrations/v2.0/remove-unused-environment-variables.ts
2888
2895
  var import_path13 = __toESM(require("path"));
2896
+ var import_ts_morph13 = require("ts-morph");
2897
+ var UNUSED_ENV_VARS = /* @__PURE__ */ new Set([
2898
+ "APPLICATION_CONFIG_URL",
2899
+ "FHIR_URL",
2900
+ "CONFIRM_REGISTRATION_URL"
2901
+ ]);
2902
+ var ENVIRONMENT_FILE_RELATIVE = "src/environment.ts";
2903
+ var CONSTANTS_FILE_RELATIVE = "src/constants.ts";
2904
+ function cleanEnvironmentFile(project, filePath) {
2905
+ const sourceFile = project.getSourceFile(filePath);
2906
+ if (!sourceFile) return [];
2907
+ const removed = [];
2908
+ const cleanEnvCall = sourceFile.getDescendantsOfKind(import_ts_morph13.SyntaxKind.CallExpression).find((call) => {
2909
+ const expr = call.getExpression();
2910
+ return import_ts_morph13.Node.isIdentifier(expr) && expr.getText() === "cleanEnv";
2911
+ });
2912
+ if (!cleanEnvCall) return removed;
2913
+ const schemaArg = cleanEnvCall.getArguments()[1]?.asKind(import_ts_morph13.SyntaxKind.ObjectLiteralExpression);
2914
+ if (!schemaArg) return removed;
2915
+ for (const name of UNUSED_ENV_VARS) {
2916
+ const prop = schemaArg.getProperty(name);
2917
+ if (!prop) continue;
2918
+ if (prop.isKind(import_ts_morph13.SyntaxKind.PropertyAssignment) || prop.isKind(import_ts_morph13.SyntaxKind.ShorthandPropertyAssignment)) {
2919
+ prop.remove();
2920
+ removed.push(name);
2921
+ }
2922
+ }
2923
+ return removed;
2924
+ }
2925
+ function extractEnvAccess(initText) {
2926
+ if (!initText) return null;
2927
+ const match = /\benv\.([A-Z][A-Z0-9_]*)\b/.exec(initText);
2928
+ return match ? match[1] : null;
2929
+ }
2930
+ function cleanConstantsFile(project, filePath) {
2931
+ const sourceFile = project.getSourceFile(filePath);
2932
+ if (!sourceFile) return [];
2933
+ const removed = [];
2934
+ for (const stmt of [...sourceFile.getVariableStatements()]) {
2935
+ const declarations = [...stmt.getDeclarations()];
2936
+ const declarationsToRemove = declarations.filter((decl) => {
2937
+ const name = decl.getName();
2938
+ const accessedEnvVar = extractEnvAccess(decl.getInitializer()?.getText());
2939
+ return UNUSED_ENV_VARS.has(name) || accessedEnvVar !== null && UNUSED_ENV_VARS.has(accessedEnvVar);
2940
+ });
2941
+ if (declarationsToRemove.length === 0) continue;
2942
+ const namesToRemove = declarationsToRemove.map((decl) => decl.getName());
2943
+ removed.push(...namesToRemove);
2944
+ if (declarationsToRemove.length === declarations.length) {
2945
+ stmt.remove();
2946
+ } else {
2947
+ for (const decl of declarationsToRemove) {
2948
+ decl.remove();
2949
+ }
2950
+ }
2951
+ }
2952
+ return removed;
2953
+ }
2954
+ async function main13() {
2955
+ const project = new import_ts_morph13.Project({
2956
+ tsConfigFilePath: import_path13.default.resolve(process.cwd(), "tsconfig.json"),
2957
+ skipAddingFilesFromTsConfig: false
2958
+ });
2959
+ console.log(
2960
+ `Removing unused environment variable(s) (${[...UNUSED_ENV_VARS].join(", ")})...
2961
+ `
2962
+ );
2963
+ const envFilePath = import_path13.default.join(process.cwd(), ENVIRONMENT_FILE_RELATIVE);
2964
+ const constsFilePath = import_path13.default.join(process.cwd(), CONSTANTS_FILE_RELATIVE);
2965
+ const envRemoved = cleanEnvironmentFile(project, envFilePath);
2966
+ if (envRemoved.length > 0) {
2967
+ await project.getSourceFileOrThrow(envFilePath).save();
2968
+ console.log(
2969
+ ` [${ENVIRONMENT_FILE_RELATIVE}] Removed schema entr${envRemoved.length === 1 ? "y" : "ies"}: ${envRemoved.join(", ")}`
2970
+ );
2971
+ } else if (project.getSourceFile(envFilePath)) {
2972
+ console.log(
2973
+ ` [${ENVIRONMENT_FILE_RELATIVE}] No matching schema entries \u2014 nothing to remove.`
2974
+ );
2975
+ } else {
2976
+ console.log(
2977
+ ` [${ENVIRONMENT_FILE_RELATIVE}] File not found \u2014 skipping.`
2978
+ );
2979
+ }
2980
+ const constsRemoved = cleanConstantsFile(project, constsFilePath);
2981
+ if (constsRemoved.length > 0) {
2982
+ await project.getSourceFileOrThrow(constsFilePath).save();
2983
+ console.log(
2984
+ ` [${CONSTANTS_FILE_RELATIVE}] Removed declaration(s): ${constsRemoved.join(", ")}`
2985
+ );
2986
+ } else if (project.getSourceFile(constsFilePath)) {
2987
+ console.log(
2988
+ ` [${CONSTANTS_FILE_RELATIVE}] No matching declarations \u2014 nothing to remove.`
2989
+ );
2990
+ } else {
2991
+ console.log(` [${CONSTANTS_FILE_RELATIVE}] File not found \u2014 skipping.`);
2992
+ }
2993
+ if (envRemoved.length === 0 && constsRemoved.length === 0) {
2994
+ console.log("\nNothing to do.");
2995
+ return;
2996
+ }
2997
+ console.log(
2998
+ `
2999
+ Done. NOTE: usages of these constants elsewhere in 'src/' may now produce TypeScript errors and need manual review.`
3000
+ );
3001
+ }
3002
+
3003
+ // src/migrations/v2.0/remove-fhir-url-helpers.ts
3004
+ var import_path14 = __toESM(require("path"));
3005
+ var import_ts_morph14 = require("ts-morph");
3006
+ var FHIR_IMPORT = "FHIR_URL";
3007
+ var HELPER_NAMES = /* @__PURE__ */ new Set([
3008
+ "getFromFhir",
3009
+ "updateResourceFromHearth",
3010
+ "updateResourceInHearth"
3011
+ ]);
3012
+ function removeHelpers(sourceFilePath, project) {
3013
+ const sourceFile = project.getSourceFile(sourceFilePath);
3014
+ if (!sourceFile) {
3015
+ return {
3016
+ removedHelpers: [],
3017
+ removedImportCount: 0,
3018
+ remainingFhirReferences: 0
3019
+ };
3020
+ }
3021
+ const removedHelpers = [];
3022
+ let removedImportCount = 0;
3023
+ for (const fn of sourceFile.getFunctions()) {
3024
+ const name = fn.getName();
3025
+ if (!name || !HELPER_NAMES.has(name)) continue;
3026
+ removedHelpers.push(name);
3027
+ fn.remove();
3028
+ }
3029
+ for (const stmt of [...sourceFile.getVariableStatements()]) {
3030
+ const declarations = [...stmt.getDeclarations()];
3031
+ const toRemove = declarations.filter((decl) => HELPER_NAMES.has(decl.getName()));
3032
+ if (toRemove.length === 0) continue;
3033
+ removedHelpers.push(...toRemove.map((decl) => decl.getName()));
3034
+ if (toRemove.length === declarations.length) {
3035
+ stmt.remove();
3036
+ } else {
3037
+ for (const decl of toRemove) decl.remove();
3038
+ }
3039
+ }
3040
+ for (const decl of sourceFile.getImportDeclarations()) {
3041
+ const matches = decl.getNamedImports().filter((ni) => ni.getName() === FHIR_IMPORT);
3042
+ if (matches.length === 0) continue;
3043
+ for (const named of matches) {
3044
+ named.remove();
3045
+ removedImportCount++;
3046
+ }
3047
+ const hasAnyNamedImportsLeft = decl.getNamedImports().length > 0;
3048
+ const hasDefaultImport = !!decl.getDefaultImport();
3049
+ const hasNamespaceImport = !!decl.getNamespaceImport();
3050
+ if (!hasAnyNamedImportsLeft && !hasDefaultImport && !hasNamespaceImport) {
3051
+ decl.remove();
3052
+ }
3053
+ }
3054
+ 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;
3055
+ return { removedHelpers, removedImportCount, remainingFhirReferences };
3056
+ }
3057
+ async function main14() {
3058
+ const project = new import_ts_morph14.Project({
3059
+ tsConfigFilePath: import_path14.default.resolve(process.cwd(), "tsconfig.json"),
3060
+ skipAddingFilesFromTsConfig: false
3061
+ });
3062
+ const sourceFiles = project.getSourceFiles().filter((sf) => {
3063
+ const fp = sf.getFilePath();
3064
+ return fp.includes("/src/") && !fp.includes("/node_modules/");
3065
+ });
3066
+ console.log(`Removing legacy FHIR_URL helpers in ${sourceFiles.length} source file(s)...
3067
+ `);
3068
+ let totalRemovedImports = 0;
3069
+ let totalRemovedHelpers = 0;
3070
+ const modifiedFiles = [];
3071
+ const warnings = [];
3072
+ for (const sourceFile of sourceFiles) {
3073
+ const filePath = sourceFile.getFilePath();
3074
+ const rel = import_path14.default.relative(process.cwd(), filePath);
3075
+ const result = removeHelpers(filePath, project);
3076
+ const changed = result.removedImportCount > 0 || result.removedHelpers.length > 0;
3077
+ if (changed) {
3078
+ modifiedFiles.push(filePath);
3079
+ totalRemovedImports += result.removedImportCount;
3080
+ totalRemovedHelpers += result.removedHelpers.length;
3081
+ if (result.removedHelpers.length > 0) {
3082
+ console.log(
3083
+ ` [${rel}] Removed helper(s): ${result.removedHelpers.join(", ")}`
3084
+ );
3085
+ }
3086
+ if (result.removedImportCount > 0) {
3087
+ console.log(
3088
+ ` [${rel}] Removed ${result.removedImportCount} '${FHIR_IMPORT}' import(s)`
3089
+ );
3090
+ }
3091
+ }
3092
+ if (result.remainingFhirReferences > 0) {
3093
+ warnings.push(
3094
+ `${rel}: ${result.remainingFhirReferences} remaining '${FHIR_IMPORT}' reference(s)`
3095
+ );
3096
+ }
3097
+ }
3098
+ if (modifiedFiles.length === 0 && warnings.length === 0) {
3099
+ console.log("No FHIR_URL imports/helpers found. Nothing to do.");
3100
+ return;
3101
+ }
3102
+ if (modifiedFiles.length > 0) {
3103
+ console.log(`
3104
+ Saving ${modifiedFiles.length} modified file(s)...`);
3105
+ for (const filePath of modifiedFiles) {
3106
+ await project.getSourceFileOrThrow(filePath).save();
3107
+ console.log(` Saved: ${import_path14.default.relative(process.cwd(), filePath)}`);
3108
+ }
3109
+ }
3110
+ if (warnings.length > 0) {
3111
+ console.warn(
3112
+ `
3113
+ WARNING: Some '${FHIR_IMPORT}' usages remain and need manual cleanup:
3114
+ ` + warnings.map((line) => ` - ${line}`).join("\n")
3115
+ );
3116
+ }
3117
+ console.log(
3118
+ `
3119
+ Done. Removed ${totalRemovedHelpers} helper declaration(s) and ${totalRemovedImports} '${FHIR_IMPORT}' import(s).`
3120
+ );
3121
+ }
3122
+
3123
+ // src/migrations/v2.0/migrate-application-config-url.ts
3124
+ var import_path15 = __toESM(require("path"));
3125
+ var import_ts_morph15 = require("ts-morph");
3126
+ var TARGET_IDENTIFIER = "APPLICATION_CONFIG_URL";
3127
+ var REPLACEMENT_IDENTIFIER = "applicationConfig";
3128
+ var REPLACEMENT_MODULE = "@countryconfig/api/application/application-config";
3129
+ var FUNCTION_LIKE_KINDS = [
3130
+ import_ts_morph15.SyntaxKind.FunctionDeclaration,
3131
+ import_ts_morph15.SyntaxKind.FunctionExpression,
3132
+ import_ts_morph15.SyntaxKind.ArrowFunction,
3133
+ import_ts_morph15.SyntaxKind.MethodDeclaration
3134
+ ];
3135
+ function describeFunction(node) {
3136
+ if (import_ts_morph15.Node.isFunctionDeclaration(node) || import_ts_morph15.Node.isMethodDeclaration(node)) {
3137
+ return node.getName() ?? "<anonymous>";
3138
+ }
3139
+ const parent = node.getParent();
3140
+ if (parent && import_ts_morph15.Node.isVariableDeclaration(parent)) {
3141
+ return parent.getName();
3142
+ }
3143
+ if (parent && import_ts_morph15.Node.isPropertyAssignment(parent)) {
3144
+ return parent.getName();
3145
+ }
3146
+ if (import_ts_morph15.Node.isFunctionExpression(node) && node.getNameNode() !== void 0) {
3147
+ return node.getNameNode()?.getText() ?? "<anonymous>";
3148
+ }
3149
+ return "<anonymous>";
3150
+ }
3151
+ function hasBlockBody(node) {
3152
+ if (import_ts_morph15.Node.isFunctionDeclaration(node) || import_ts_morph15.Node.isFunctionExpression(node) || import_ts_morph15.Node.isMethodDeclaration(node)) {
3153
+ return node.getBody() !== void 0;
3154
+ }
3155
+ if (import_ts_morph15.Node.isArrowFunction(node)) {
3156
+ return node.getBody().getKind() === import_ts_morph15.SyntaxKind.Block;
3157
+ }
3158
+ return false;
3159
+ }
3160
+ function isConfigFetcher(node) {
3161
+ let referencesTarget = false;
3162
+ let callsFetch = false;
3163
+ for (const id of node.getDescendantsOfKind(import_ts_morph15.SyntaxKind.Identifier)) {
3164
+ const text = id.getText();
3165
+ if (!referencesTarget && text === TARGET_IDENTIFIER) referencesTarget = true;
3166
+ if (!callsFetch && text === "fetch") {
3167
+ const parent = id.getParent();
3168
+ if (import_ts_morph15.Node.isCallExpression(parent) && parent.getExpression() === id) {
3169
+ callsFetch = true;
3170
+ }
3171
+ }
3172
+ if (referencesTarget && callsFetch) return true;
3173
+ }
3174
+ return false;
3175
+ }
3176
+ function processFile11(sourceFile) {
3177
+ const importsWithTarget = sourceFile.getImportDeclarations().filter(
3178
+ (decl) => decl.getNamedImports().some((ni) => ni.getName() === TARGET_IDENTIFIER)
3179
+ );
3180
+ if (importsWithTarget.length === 0) {
3181
+ return { changed: false, rewrittenFunctions: [], renamedReferences: 0 };
3182
+ }
3183
+ const collidingLocals = sourceFile.getDescendantsOfKind(import_ts_morph15.SyntaxKind.Identifier).filter((id) => id.getText() === REPLACEMENT_IDENTIFIER).filter((id) => {
3184
+ const parent = id.getParent();
3185
+ const kind = parent.getKind();
3186
+ 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;
3187
+ });
3188
+ if (collidingLocals.length > 0) {
3189
+ return {
3190
+ changed: false,
3191
+ rewrittenFunctions: [],
3192
+ renamedReferences: 0,
3193
+ skippedReason: `local declaration named '${REPLACEMENT_IDENTIFIER}' would collide`
3194
+ };
3195
+ }
3196
+ const candidateFunctions = FUNCTION_LIKE_KINDS.flatMap(
3197
+ (kind) => sourceFile.getDescendantsOfKind(kind)
3198
+ );
3199
+ candidateFunctions.sort((a, b) => a.getStart() - b.getStart());
3200
+ const rewrittenFunctions = [];
3201
+ const rewrittenSet = /* @__PURE__ */ new Set();
3202
+ for (const fn of candidateFunctions) {
3203
+ if (!hasBlockBody(fn)) continue;
3204
+ if (!isConfigFetcher(fn)) continue;
3205
+ let inRewrittenAncestor = false;
3206
+ let cursor = fn.getParent();
3207
+ while (cursor) {
3208
+ if (rewrittenSet.has(cursor)) {
3209
+ inRewrittenAncestor = true;
3210
+ break;
3211
+ }
3212
+ cursor = cursor.getParent();
3213
+ }
3214
+ if (inRewrittenAncestor) continue;
3215
+ const start = fn.getStart();
3216
+ const line = sourceFile.getLineAndColumnAtPos(start).line;
3217
+ const name = describeFunction(fn);
3218
+ 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)) {
3219
+ fn.setBodyText(`return ${REPLACEMENT_IDENTIFIER}`);
3220
+ }
3221
+ rewrittenFunctions.push({ name, line });
3222
+ rewrittenSet.add(fn);
3223
+ }
3224
+ for (const decl of importsWithTarget) {
3225
+ const targetNamed = decl.getNamedImports().find((ni) => ni.getName() === TARGET_IDENTIFIER);
3226
+ targetNamed?.remove();
3227
+ const isNowEmpty = decl.getNamedImports().length === 0 && !decl.getDefaultImport() && !decl.getNamespaceImport();
3228
+ if (isNowEmpty) decl.remove();
3229
+ }
3230
+ const existing = sourceFile.getImportDeclaration(
3231
+ (decl) => decl.getModuleSpecifierValue() === REPLACEMENT_MODULE
3232
+ );
3233
+ if (existing) {
3234
+ const alreadyImported = existing.getNamedImports().some((ni) => ni.getName() === REPLACEMENT_IDENTIFIER);
3235
+ if (!alreadyImported) existing.addNamedImport(REPLACEMENT_IDENTIFIER);
3236
+ } else {
3237
+ sourceFile.addImportDeclaration({
3238
+ moduleSpecifier: REPLACEMENT_MODULE,
3239
+ namedImports: [REPLACEMENT_IDENTIFIER]
3240
+ });
3241
+ }
3242
+ 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) => {
3243
+ const parent = id.getParent();
3244
+ const parentKind = parent.getKind();
3245
+ if (parentKind === import_ts_morph15.SyntaxKind.PropertyAccessExpression) {
3246
+ const pae = parent.asKind(import_ts_morph15.SyntaxKind.PropertyAccessExpression);
3247
+ if (pae.getNameNode() === id) return false;
3248
+ }
3249
+ if (parentKind === import_ts_morph15.SyntaxKind.PropertyAssignment) {
3250
+ const pa = parent.asKind(import_ts_morph15.SyntaxKind.PropertyAssignment);
3251
+ if (pa.getNameNode() === id) return false;
3252
+ }
3253
+ if (parentKind === import_ts_morph15.SyntaxKind.ShorthandPropertyAssignment) {
3254
+ return false;
3255
+ }
3256
+ return true;
3257
+ }).sort((a, b) => b.getPos() - a.getPos());
3258
+ for (const id of renameTargets) {
3259
+ id.replaceWithText(REPLACEMENT_IDENTIFIER);
3260
+ }
3261
+ return {
3262
+ changed: true,
3263
+ rewrittenFunctions,
3264
+ renamedReferences: renameTargets.length
3265
+ };
3266
+ }
3267
+ async function main15() {
3268
+ const project = new import_ts_morph15.Project({
3269
+ tsConfigFilePath: import_path15.default.resolve(process.cwd(), "tsconfig.json"),
3270
+ skipAddingFilesFromTsConfig: false
3271
+ });
3272
+ const sourceFiles = project.getSourceFiles().filter((sf) => {
3273
+ const fp = sf.getFilePath();
3274
+ return fp.includes("/src/") && !fp.includes("/node_modules/");
3275
+ });
3276
+ console.log(
3277
+ `Migrating '${TARGET_IDENTIFIER}' \u2192 '${REPLACEMENT_IDENTIFIER}' across ${sourceFiles.length} source file(s)...
3278
+ `
3279
+ );
3280
+ let changedFiles = 0;
3281
+ let totalRewrittenFunctions = 0;
3282
+ let totalRenamedReferences = 0;
3283
+ const skipped = [];
3284
+ for (const sourceFile of sourceFiles) {
3285
+ const filePath = sourceFile.getFilePath();
3286
+ const rel = import_path15.default.relative(process.cwd(), filePath);
3287
+ const result = processFile11(sourceFile);
3288
+ if (result.skippedReason) {
3289
+ skipped.push(`${rel} (${result.skippedReason})`);
3290
+ continue;
3291
+ }
3292
+ if (!result.changed) continue;
3293
+ await sourceFile.save();
3294
+ changedFiles++;
3295
+ totalRewrittenFunctions += result.rewrittenFunctions.length;
3296
+ totalRenamedReferences += result.renamedReferences;
3297
+ for (const fn of result.rewrittenFunctions) {
3298
+ console.log(
3299
+ ` [${rel}:${fn.line}] Rewrote '${fn.name}' body \u2192 'return ${REPLACEMENT_IDENTIFIER}' (config fetch eliminated)`
3300
+ );
3301
+ }
3302
+ if (result.renamedReferences > 0) {
3303
+ console.log(
3304
+ ` [${rel}] Renamed ${result.renamedReferences} stray reference(s) ${TARGET_IDENTIFIER} \u2192 ${REPLACEMENT_IDENTIFIER}`
3305
+ );
3306
+ }
3307
+ }
3308
+ if (skipped.length > 0) {
3309
+ console.warn(
3310
+ `
3311
+ ${skipped.length} file(s) skipped:
3312
+ ` + skipped.map((s) => ` - ${s}`).join("\n")
3313
+ );
3314
+ }
3315
+ if (changedFiles === 0) {
3316
+ console.log(`
3317
+ No files reference '${TARGET_IDENTIFIER}'. Nothing to do.`);
3318
+ return;
3319
+ }
3320
+ console.log(
3321
+ `
3322
+ Done. Updated ${changedFiles} file(s): ${totalRewrittenFunctions} fetch function(s) rewritten, ${totalRenamedReferences} bare reference(s) renamed.`
3323
+ );
3324
+ if (totalRewrittenFunctions > 0) {
3325
+ console.log(
3326
+ `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}'.`
3327
+ );
3328
+ }
3329
+ }
3330
+
3331
+ // src/migrations/v2.0/remove-old-statistics-service.ts
3332
+ var import_path16 = __toESM(require("path"));
3333
+ var import_ts_morph16 = require("ts-morph");
3334
+ var ROUTE_PATH = "/statistics";
3335
+ var HANDLER_NAME = "statisticsHandler";
3336
+ function isStatisticsRouteObject(obj) {
3337
+ const pathProp = obj.getProperty("path");
3338
+ if (!pathProp || !import_ts_morph16.Node.isPropertyAssignment(pathProp)) return false;
3339
+ const init = pathProp.getInitializer();
3340
+ if (!init) return false;
3341
+ if (import_ts_morph16.Node.isStringLiteral(init) || import_ts_morph16.Node.isNoSubstitutionTemplateLiteral(init)) {
3342
+ return init.getLiteralValue() === ROUTE_PATH;
3343
+ }
3344
+ return false;
3345
+ }
3346
+ function removeStatisticsRoutes(sourceFile) {
3347
+ let removed = 0;
3348
+ const callExpressions = [
3349
+ ...sourceFile.getDescendantsOfKind(import_ts_morph16.SyntaxKind.CallExpression)
3350
+ ];
3351
+ for (const call of callExpressions) {
3352
+ if (call.wasForgotten()) continue;
3353
+ const expr = call.getExpression();
3354
+ if (!import_ts_morph16.Node.isPropertyAccessExpression(expr)) continue;
3355
+ if (expr.getName() !== "route") continue;
3356
+ const args = call.getArguments();
3357
+ if (args.length === 0) continue;
3358
+ const firstArg = args[0];
3359
+ if (import_ts_morph16.Node.isObjectLiteralExpression(firstArg)) {
3360
+ if (!isStatisticsRouteObject(firstArg)) continue;
3361
+ const stmt = call.getFirstAncestorByKind(import_ts_morph16.SyntaxKind.ExpressionStatement);
3362
+ if (stmt) {
3363
+ stmt.remove();
3364
+ removed++;
3365
+ } else {
3366
+ call.replaceWithText("");
3367
+ removed++;
3368
+ }
3369
+ continue;
3370
+ }
3371
+ if (import_ts_morph16.Node.isArrayLiteralExpression(firstArg)) {
3372
+ const matchingIndexes = firstArg.getElements().map((el, idx) => ({ el, idx })).filter(
3373
+ ({ el }) => import_ts_morph16.Node.isObjectLiteralExpression(el) && isStatisticsRouteObject(el)
3374
+ ).map(({ idx }) => idx);
3375
+ matchingIndexes.sort((a, b) => b - a).forEach((idx) => {
3376
+ firstArg.removeElement(idx);
3377
+ removed++;
3378
+ });
3379
+ }
3380
+ }
3381
+ return removed;
3382
+ }
3383
+ function removeStatisticsHandlerImports(sourceFile) {
3384
+ let changed = false;
3385
+ for (const decl of sourceFile.getImportDeclarations()) {
3386
+ const targetNamed = decl.getNamedImports().find((ni) => ni.getName() === HANDLER_NAME);
3387
+ if (!targetNamed) continue;
3388
+ targetNamed.remove();
3389
+ changed = true;
3390
+ const isNowEmpty = decl.getNamedImports().length === 0 && !decl.getDefaultImport() && !decl.getNamespaceImport();
3391
+ if (isNowEmpty) decl.remove();
3392
+ }
3393
+ return changed;
3394
+ }
3395
+ function processFile12(sourceFile) {
3396
+ const routesRemoved = removeStatisticsRoutes(sourceFile);
3397
+ const importsCleaned = removeStatisticsHandlerImports(sourceFile);
3398
+ return { routesRemoved, importsCleaned };
3399
+ }
3400
+ function collectLocalImportsInSubtree(sourceFile, subtreeRoot) {
3401
+ const result = [];
3402
+ for (const decl of sourceFile.getImportDeclarations()) {
3403
+ const moduleSf = decl.getModuleSpecifierSourceFile();
3404
+ if (!moduleSf) continue;
3405
+ const fp = moduleSf.getFilePath();
3406
+ if (!fp.startsWith(subtreeRoot)) continue;
3407
+ result.push(fp);
3408
+ }
3409
+ return result;
3410
+ }
3411
+ function deleteOrphanedDescendants(project, startingFile, subtreeRoot) {
3412
+ const initialCandidates = collectLocalImportsInSubtree(
3413
+ startingFile,
3414
+ subtreeRoot
3415
+ );
3416
+ const startingPath = startingFile.getFilePath();
3417
+ const deleted = /* @__PURE__ */ new Set([startingPath]);
3418
+ const seen = /* @__PURE__ */ new Set();
3419
+ const worklist = [...initialCandidates];
3420
+ const orphans = [];
3421
+ while (worklist.length > 0) {
3422
+ const candidate = worklist.shift();
3423
+ if (seen.has(candidate)) continue;
3424
+ seen.add(candidate);
3425
+ if (deleted.has(candidate)) continue;
3426
+ if (!candidate.startsWith(subtreeRoot)) continue;
3427
+ const candidateSf = project.getSourceFile(candidate);
3428
+ if (!candidateSf) continue;
3429
+ const stillImported = project.getSourceFiles().some((sf) => {
3430
+ const sfPath = sf.getFilePath();
3431
+ if (deleted.has(sfPath)) return false;
3432
+ if (sfPath === candidate) return false;
3433
+ return sf.getImportDeclarations().some(
3434
+ (decl) => decl.getModuleSpecifierSourceFile()?.getFilePath() === candidate
3435
+ );
3436
+ });
3437
+ if (stillImported) continue;
3438
+ const next = collectLocalImportsInSubtree(candidateSf, subtreeRoot);
3439
+ worklist.push(...next);
3440
+ candidateSf.delete();
3441
+ deleted.add(candidate);
3442
+ orphans.push(candidate);
3443
+ }
3444
+ return orphans;
3445
+ }
3446
+ function processHandlerFile(project) {
3447
+ const sourceFiles = project.getSourceFiles().filter((sf) => {
3448
+ const fp = sf.getFilePath();
3449
+ return fp.includes("/src/") && !fp.includes("/node_modules/");
3450
+ });
3451
+ for (const sf of sourceFiles) {
3452
+ const fn = sf.getFunction(HANDLER_NAME);
3453
+ if (!fn) continue;
3454
+ const filePath = sf.getFilePath();
3455
+ const exportsByName = [...sf.getExportedDeclarations().keys()];
3456
+ const otherExports = exportsByName.filter((name) => name !== HANDLER_NAME);
3457
+ if (otherExports.length === 0) {
3458
+ const subtreeRoot = import_path16.default.dirname(filePath) + import_path16.default.sep;
3459
+ const orphansDeleted = deleteOrphanedDescendants(
3460
+ project,
3461
+ sf,
3462
+ subtreeRoot
3463
+ );
3464
+ sf.delete();
3465
+ return { filePath, action: "deleted", orphansDeleted };
3466
+ }
3467
+ fn.remove();
3468
+ return {
3469
+ filePath,
3470
+ action: "function-removed",
3471
+ remainingExports: otherExports,
3472
+ orphansDeleted: []
3473
+ };
3474
+ }
3475
+ return { filePath: "", action: "not-found", orphansDeleted: [] };
3476
+ }
3477
+ async function main16() {
3478
+ const project = new import_ts_morph16.Project({
3479
+ tsConfigFilePath: import_path16.default.resolve(process.cwd(), "tsconfig.json"),
3480
+ skipAddingFilesFromTsConfig: false
3481
+ });
3482
+ const sourceFiles = project.getSourceFiles().filter((sf) => {
3483
+ const fp = sf.getFilePath();
3484
+ return fp.includes("/src/") && !fp.includes("/node_modules/");
3485
+ });
3486
+ console.log(
3487
+ `Removing legacy 'GET ${ROUTE_PATH}' route and '${HANDLER_NAME}' across ${sourceFiles.length} source file(s)...
3488
+ `
3489
+ );
3490
+ let totalRoutesRemoved = 0;
3491
+ let totalFilesWithImportsCleaned = 0;
3492
+ let totalFilesWithRoutesRemoved = 0;
3493
+ for (const sourceFile of sourceFiles) {
3494
+ const filePath = sourceFile.getFilePath();
3495
+ const rel = import_path16.default.relative(process.cwd(), filePath);
3496
+ const result = processFile12(sourceFile);
3497
+ if (result.routesRemoved > 0) {
3498
+ console.log(
3499
+ ` [${rel}] Removed ${result.routesRemoved} '${ROUTE_PATH}' route(s)`
3500
+ );
3501
+ totalRoutesRemoved += result.routesRemoved;
3502
+ totalFilesWithRoutesRemoved++;
3503
+ }
3504
+ if (result.importsCleaned) {
3505
+ console.log(` [${rel}] Cleaned up '${HANDLER_NAME}' import`);
3506
+ totalFilesWithImportsCleaned++;
3507
+ }
3508
+ if (result.routesRemoved > 0 || result.importsCleaned) {
3509
+ await sourceFile.save();
3510
+ }
3511
+ }
3512
+ const handlerResult = processHandlerFile(project);
3513
+ switch (handlerResult.action) {
3514
+ case "deleted": {
3515
+ const rel = import_path16.default.relative(process.cwd(), handlerResult.filePath);
3516
+ console.log(
3517
+ ` [${rel}] Deleted handler file ('${HANDLER_NAME}' was the sole export).`
3518
+ );
3519
+ for (const orphanPath of handlerResult.orphansDeleted) {
3520
+ const orphanRel = import_path16.default.relative(process.cwd(), orphanPath);
3521
+ console.log(
3522
+ ` [${orphanRel}] Deleted (no remaining importers in the project after handler removal).`
3523
+ );
3524
+ }
3525
+ await project.save();
3526
+ break;
3527
+ }
3528
+ case "function-removed": {
3529
+ const rel = import_path16.default.relative(process.cwd(), handlerResult.filePath);
3530
+ console.warn(
3531
+ ` [${rel}] Removed '${HANDLER_NAME}' function but kept the file (other exports remain: ${handlerResult.remainingExports?.join(", ")}). Review whether the file is still needed.`
3532
+ );
3533
+ const sf = project.getSourceFile(handlerResult.filePath);
3534
+ if (sf) await sf.save();
3535
+ break;
3536
+ }
3537
+ case "not-found":
3538
+ break;
3539
+ }
3540
+ if (totalRoutesRemoved === 0 && totalFilesWithImportsCleaned === 0 && handlerResult.action === "not-found") {
3541
+ console.log(`
3542
+ No legacy '${ROUTE_PATH}' route or handler found. Nothing to do.`);
3543
+ return;
3544
+ }
3545
+ const orphansSummary = handlerResult.orphansDeleted.length > 0 ? ` and ${handlerResult.orphansDeleted.length} orphaned helper file(s)` : "";
3546
+ console.log(
3547
+ `
3548
+ Done. Removed ${totalRoutesRemoved} route(s) across ${totalFilesWithRoutesRemoved} file(s); cleaned ${HANDLER_NAME} import in ${totalFilesWithImportsCleaned} file(s)${orphansSummary}.`
3549
+ );
3550
+ }
3551
+
3552
+ // src/migrations/v2.0/update-package-json.ts
3553
+ var import_fs = require("fs");
3554
+ var import_path17 = __toESM(require("path"));
3555
+ var PACKAGE_JSON_RELATIVE = "package.json";
3556
+ var TARGET_VERSION = "2.0.0";
3557
+ var TARGET_ZOD_RANGE = "^4.2.1";
3558
+ async function main17() {
3559
+ const packageJsonPath = import_path17.default.join(process.cwd(), PACKAGE_JSON_RELATIVE);
3560
+ if (!(0, import_fs.existsSync)(packageJsonPath)) {
3561
+ console.log(`'${PACKAGE_JSON_RELATIVE}' not found in ${process.cwd()} \u2014 skipping.`);
3562
+ return;
3563
+ }
3564
+ const raw = (0, import_fs.readFileSync)(packageJsonPath, "utf8");
3565
+ let parsed;
3566
+ try {
3567
+ parsed = JSON.parse(raw);
3568
+ } catch (error) {
3569
+ console.warn(
3570
+ ` [${PACKAGE_JSON_RELATIVE}] Failed to parse JSON \u2014 skipping update. ${error.message}`
3571
+ );
3572
+ return;
3573
+ }
3574
+ console.log(`Updating '${PACKAGE_JSON_RELATIVE}'...`);
3575
+ const previousVersion = parsed.version;
3576
+ const versionChanged = previousVersion !== TARGET_VERSION;
3577
+ parsed.version = TARGET_VERSION;
3578
+ if (versionChanged) {
3579
+ console.log(
3580
+ ` Set version: ${previousVersion ?? "<unset>"} \u2192 ${TARGET_VERSION}`
3581
+ );
3582
+ } else {
3583
+ console.log(` Version already ${TARGET_VERSION} \u2014 no change.`);
3584
+ }
3585
+ let zodBucket = "dependencies";
3586
+ if (parsed.devDependencies && "zod" in parsed.devDependencies) {
3587
+ zodBucket = "devDependencies";
3588
+ }
3589
+ if (!parsed[zodBucket]) {
3590
+ parsed[zodBucket] = {};
3591
+ }
3592
+ const bucket = parsed[zodBucket];
3593
+ const previousZod = bucket.zod;
3594
+ const zodChanged = previousZod !== TARGET_ZOD_RANGE;
3595
+ bucket.zod = TARGET_ZOD_RANGE;
3596
+ if (zodChanged) {
3597
+ console.log(
3598
+ ` Set ${zodBucket}.zod: ${previousZod ?? "<absent>"} \u2192 ${TARGET_ZOD_RANGE}`
3599
+ );
3600
+ } else {
3601
+ console.log(` ${zodBucket}.zod already ${TARGET_ZOD_RANGE} \u2014 no change.`);
3602
+ }
3603
+ const trailingNewline = raw.endsWith("\n") ? "\n" : "";
3604
+ const next = JSON.stringify(parsed, null, 2) + trailingNewline;
3605
+ if (next === raw) {
3606
+ console.log("\n No changes to write.");
3607
+ return;
3608
+ }
3609
+ (0, import_fs.writeFileSync)(packageJsonPath, next, "utf8");
3610
+ console.log(`
3611
+ Saved '${PACKAGE_JSON_RELATIVE}'.`);
3612
+ console.log(
3613
+ ` NOTE: run \`yarn install\` (or your package manager equivalent) to install the updated dependency versions.`
3614
+ );
3615
+ }
3616
+
3617
+ // src/migrations/v2.0/migrate-workqueue-configs.ts
3618
+ var import_ts_morph17 = require("ts-morph");
3619
+ var import_path18 = __toESM(require("path"));
2889
3620
  var DEFINE_WORKQUEUES_NAME3 = "defineWorkqueues";
2890
3621
  var ACTIONS_PROPERTY_NAME5 = "actions";
2891
3622
  var ACTION_PROPERTY_NAME2 = "action";
@@ -2906,28 +3637,28 @@ var SUPPORTED_WORKQUEUE_ACTION_TYPES = /* @__PURE__ */ new Set([
2906
3637
  ]);
2907
3638
  function getWorkqueueLabel(workqueue) {
2908
3639
  const slugProperty = workqueue.getProperty(SLUG_PROPERTY_NAME);
2909
- if (!slugProperty || !import_ts_morph13.Node.isPropertyAssignment(slugProperty)) {
3640
+ if (!slugProperty || !import_ts_morph17.Node.isPropertyAssignment(slugProperty)) {
2910
3641
  return "(unknown slug)";
2911
3642
  }
2912
3643
  const slugInitializer = slugProperty.getInitializer();
2913
- if (!slugInitializer || !import_ts_morph13.Node.isStringLiteral(slugInitializer)) {
3644
+ if (!slugInitializer || !import_ts_morph17.Node.isStringLiteral(slugInitializer)) {
2914
3645
  return "(unknown slug)";
2915
3646
  }
2916
3647
  return slugInitializer.getLiteralValue();
2917
3648
  }
2918
3649
  function getActionTypeName(action) {
2919
3650
  const typeProperty = action.getProperty(TYPE_PROPERTY_NAME7);
2920
- if (!typeProperty || !import_ts_morph13.Node.isPropertyAssignment(typeProperty)) {
3651
+ if (!typeProperty || !import_ts_morph17.Node.isPropertyAssignment(typeProperty)) {
2921
3652
  return null;
2922
3653
  }
2923
3654
  const typeInitializer = typeProperty.getInitializer();
2924
3655
  if (!typeInitializer) {
2925
3656
  return null;
2926
3657
  }
2927
- if (import_ts_morph13.Node.isStringLiteral(typeInitializer)) {
3658
+ if (import_ts_morph17.Node.isStringLiteral(typeInitializer)) {
2928
3659
  return typeInitializer.getLiteralValue();
2929
3660
  }
2930
- if (import_ts_morph13.Node.isPropertyAccessExpression(typeInitializer)) {
3661
+ if (import_ts_morph17.Node.isPropertyAccessExpression(typeInitializer)) {
2931
3662
  return typeInitializer.getName();
2932
3663
  }
2933
3664
  return null;
@@ -2941,19 +3672,19 @@ function isUnsupportedActionType(action) {
2941
3672
  }
2942
3673
  function migrateWorkqueueActions(workqueue, relPath) {
2943
3674
  const actionsProperty = workqueue.getProperty(ACTIONS_PROPERTY_NAME5);
2944
- if (!actionsProperty || !import_ts_morph13.Node.isPropertyAssignment(actionsProperty)) {
3675
+ if (!actionsProperty || !import_ts_morph17.Node.isPropertyAssignment(actionsProperty)) {
2945
3676
  return 0;
2946
3677
  }
2947
3678
  const actionsInitializer = actionsProperty.getInitializer();
2948
- if (!actionsInitializer || !import_ts_morph13.Node.isArrayLiteralExpression(actionsInitializer)) {
3679
+ if (!actionsInitializer || !import_ts_morph17.Node.isArrayLiteralExpression(actionsInitializer)) {
2949
3680
  return 0;
2950
3681
  }
2951
3682
  const workqueueLabel = getWorkqueueLabel(workqueue);
2952
3683
  const existingActionProperty = workqueue.getProperty(ACTION_PROPERTY_NAME2);
2953
3684
  if (existingActionProperty) {
2954
- if (import_ts_morph13.Node.isPropertyAssignment(existingActionProperty)) {
3685
+ if (import_ts_morph17.Node.isPropertyAssignment(existingActionProperty)) {
2955
3686
  const existingActionInitializer = existingActionProperty.getInitializer();
2956
- if (existingActionInitializer && import_ts_morph13.Node.isObjectLiteralExpression(existingActionInitializer)) {
3687
+ if (existingActionInitializer && import_ts_morph17.Node.isObjectLiteralExpression(existingActionInitializer)) {
2957
3688
  const conditionalsProperty2 = existingActionInitializer.getProperty(
2958
3689
  CONDITIONALS_PROPERTY_NAME
2959
3690
  );
@@ -2978,7 +3709,7 @@ function migrateWorkqueueActions(workqueue, relPath) {
2978
3709
  return 1;
2979
3710
  }
2980
3711
  const actionCandidates = actionsInitializer.getElements().filter(
2981
- (element) => import_ts_morph13.Node.isObjectLiteralExpression(element)
3712
+ (element) => import_ts_morph17.Node.isObjectLiteralExpression(element)
2982
3713
  );
2983
3714
  if (actionCandidates.length === 0) {
2984
3715
  actionsProperty.remove();
@@ -3020,36 +3751,36 @@ function migrateWorkqueueActions(workqueue, relPath) {
3020
3751
  );
3021
3752
  return 1;
3022
3753
  }
3023
- function processFile11(filePath, project) {
3754
+ function processFile13(filePath, project) {
3024
3755
  const sourceFile = project.getSourceFile(filePath);
3025
3756
  if (!sourceFile) return 0;
3026
3757
  let migratedWorkqueues = 0;
3027
- const relPath = import_path13.default.relative(getCwd(), filePath);
3758
+ const relPath = import_path18.default.relative(process.cwd(), filePath);
3028
3759
  const callExpressions = sourceFile.getDescendantsOfKind(
3029
- import_ts_morph13.SyntaxKind.CallExpression
3760
+ import_ts_morph17.SyntaxKind.CallExpression
3030
3761
  );
3031
3762
  for (const call of callExpressions) {
3032
3763
  const expression = call.getExpression();
3033
- if (!import_ts_morph13.Node.isIdentifier(expression) || expression.getText() !== DEFINE_WORKQUEUES_NAME3) {
3764
+ if (!import_ts_morph17.Node.isIdentifier(expression) || expression.getText() !== DEFINE_WORKQUEUES_NAME3) {
3034
3765
  continue;
3035
3766
  }
3036
3767
  const args = call.getArguments();
3037
3768
  if (args.length === 0) continue;
3038
3769
  const workqueuesArg = args[0];
3039
- if (!import_ts_morph13.Node.isArrayLiteralExpression(workqueuesArg)) continue;
3770
+ if (!import_ts_morph17.Node.isArrayLiteralExpression(workqueuesArg)) continue;
3040
3771
  for (const element of workqueuesArg.getElements()) {
3041
- if (!import_ts_morph13.Node.isObjectLiteralExpression(element)) continue;
3772
+ if (!import_ts_morph17.Node.isObjectLiteralExpression(element)) continue;
3042
3773
  migratedWorkqueues += migrateWorkqueueActions(element, relPath);
3043
3774
  }
3044
3775
  }
3045
3776
  return migratedWorkqueues;
3046
3777
  }
3047
- async function main13() {
3048
- const srcDir = import_path13.default.join(getCwd(), "src");
3778
+ async function main18() {
3779
+ const srcDir = import_path18.default.join(process.cwd(), "src");
3049
3780
  console.log(`Scanning for defineWorkqueues calls in: ${srcDir}
3050
3781
  `);
3051
- const project = new import_ts_morph13.Project({
3052
- tsConfigFilePath: import_path13.default.resolve(srcDir, "../tsconfig.json"),
3782
+ const project = new import_ts_morph17.Project({
3783
+ tsConfigFilePath: import_path18.default.resolve(srcDir, "../tsconfig.json"),
3053
3784
  skipAddingFilesFromTsConfig: false
3054
3785
  });
3055
3786
  const sourceFiles = project.getSourceFiles().filter((sf) => {
@@ -3062,7 +3793,7 @@ async function main13() {
3062
3793
  const modifiedFiles = [];
3063
3794
  for (const sourceFile of sourceFiles) {
3064
3795
  const filePath = sourceFile.getFilePath();
3065
- const migrated = processFile11(filePath, project);
3796
+ const migrated = processFile13(filePath, project);
3066
3797
  if (migrated > 0) {
3067
3798
  totalMigrated += migrated;
3068
3799
  modifiedFiles.push(filePath);
@@ -3079,7 +3810,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
3079
3810
  for (const filePath of modifiedFiles) {
3080
3811
  const sourceFile = project.getSourceFileOrThrow(filePath);
3081
3812
  await sourceFile.save();
3082
- console.log(` Saved: ${import_path13.default.relative(getCwd(), filePath)}`);
3813
+ console.log(` Saved: ${import_path18.default.relative(process.cwd(), filePath)}`);
3083
3814
  }
3084
3815
  console.log(
3085
3816
  `
@@ -3088,13 +3819,13 @@ Done. Migrated ${totalMigrated} deprecated workqueue 'actions' definition(s) to
3088
3819
  }
3089
3820
 
3090
3821
  // src/migrations/v2.0/remove-demo-scope.ts
3091
- var import_path14 = __toESM(require("path"));
3092
- var import_ts_morph14 = require("ts-morph");
3822
+ var import_path19 = __toESM(require("path"));
3823
+ var import_ts_morph18 = require("ts-morph");
3093
3824
  var ROLES_HANDLER_RELATIVE_PATH = "src/data-seeding/roles/handler.ts";
3094
- async function main14() {
3095
- const rolesHandlerPath = import_path14.default.join(getCwd(), ROLES_HANDLER_RELATIVE_PATH);
3096
- const project = new import_ts_morph14.Project({
3097
- tsConfigFilePath: import_path14.default.resolve(getCwd(), "tsconfig.json"),
3825
+ async function main19() {
3826
+ const rolesHandlerPath = import_path19.default.join(process.cwd(), ROLES_HANDLER_RELATIVE_PATH);
3827
+ const project = new import_ts_morph18.Project({
3828
+ tsConfigFilePath: import_path19.default.resolve(process.cwd(), "tsconfig.json"),
3098
3829
  skipAddingFilesFromTsConfig: false
3099
3830
  });
3100
3831
  const sourceFile = project.getSourceFile(rolesHandlerPath);
@@ -3143,7 +3874,7 @@ async function main14() {
3143
3874
 
3144
3875
  // src/migrations/v2.0/remove-hearth-migrations.ts
3145
3876
  var fs2 = __toESM(require("fs"));
3146
- var import_path15 = __toESM(require("path"));
3877
+ var import_path20 = __toESM(require("path"));
3147
3878
  var PATHS_TO_REMOVE = [
3148
3879
  {
3149
3880
  relativePath: "src/migrations/hearth",
@@ -3155,9 +3886,9 @@ var PATHS_TO_REMOVE = [
3155
3886
  },
3156
3887
  { relativePath: "src/utils/hearth-helpers.ts", label: "Hearth helpers file" }
3157
3888
  ];
3158
- async function main15() {
3889
+ async function main20() {
3159
3890
  for (const { relativePath, label } of PATHS_TO_REMOVE) {
3160
- const absolutePath = import_path15.default.join(getCwd(), relativePath);
3891
+ const absolutePath = import_path20.default.join(process.cwd(), relativePath);
3161
3892
  if (fs2.existsSync(absolutePath)) {
3162
3893
  fs2.rmSync(absolutePath, { recursive: true, force: true });
3163
3894
  console.log(`Removed ${label} '${relativePath}'.`);
@@ -3168,9 +3899,9 @@ async function main15() {
3168
3899
  }
3169
3900
 
3170
3901
  // src/migrations/v2.0/create-events-index.ts
3171
- var import_ts_morph15 = require("ts-morph");
3172
- var import_fs = __toESM(require("fs"));
3173
- var import_path16 = __toESM(require("path"));
3902
+ var import_ts_morph19 = require("ts-morph");
3903
+ var import_fs2 = __toESM(require("fs"));
3904
+ var import_path21 = __toESM(require("path"));
3174
3905
  var DEFINE_CONFIG_NAME5 = "defineConfig";
3175
3906
  var HANDLER_FUNCTION_NAMES = /* @__PURE__ */ new Set([
3176
3907
  "getCustomEventsHandler",
@@ -3192,7 +3923,7 @@ var LICENSE_HEADER = `/*
3192
3923
  `;
3193
3924
  function findEventConfigExports(project, srcDir) {
3194
3925
  const found = [];
3195
- const eventsIndexAbs = import_path16.default.join(srcDir, "events", "index.ts");
3926
+ const eventsIndexAbs = import_path21.default.join(srcDir, "events", "index.ts");
3196
3927
  for (const sourceFile of project.getSourceFiles()) {
3197
3928
  const filePath = sourceFile.getFilePath();
3198
3929
  if (!filePath.startsWith(srcDir) || filePath.includes("/node_modules/")) {
@@ -3204,10 +3935,10 @@ function findEventConfigExports(project, srcDir) {
3204
3935
  for (const decl of statement.getDeclarations()) {
3205
3936
  const initializer = decl.getInitializer();
3206
3937
  if (!initializer) continue;
3207
- const unwrapped = import_ts_morph15.Node.isAsExpression(initializer) ? initializer.getExpression() : initializer;
3208
- if (!import_ts_morph15.Node.isCallExpression(unwrapped)) continue;
3938
+ const unwrapped = import_ts_morph19.Node.isAsExpression(initializer) ? initializer.getExpression() : initializer;
3939
+ if (!import_ts_morph19.Node.isCallExpression(unwrapped)) continue;
3209
3940
  const callee = unwrapped.getExpression();
3210
- if (!import_ts_morph15.Node.isIdentifier(callee)) continue;
3941
+ if (!import_ts_morph19.Node.isIdentifier(callee)) continue;
3211
3942
  if (callee.getText() !== DEFINE_CONFIG_NAME5) continue;
3212
3943
  found.push({ name: decl.getName(), filePath });
3213
3944
  }
@@ -3216,8 +3947,8 @@ function findEventConfigExports(project, srcDir) {
3216
3947
  return found;
3217
3948
  }
3218
3949
  function buildIndexImportSpecifier(eventConfigFilePath, srcDir) {
3219
- const eventsIndexDir = import_path16.default.join(srcDir, "events");
3220
- let rel = import_path16.default.relative(eventsIndexDir, eventConfigFilePath).split(import_path16.default.sep).join("/");
3950
+ const eventsIndexDir = import_path21.default.join(srcDir, "events");
3951
+ let rel = import_path21.default.relative(eventsIndexDir, eventConfigFilePath).split(import_path21.default.sep).join("/");
3221
3952
  if (rel.endsWith(".ts")) rel = rel.slice(0, -".ts".length);
3222
3953
  if (rel.endsWith("/index")) rel = rel.slice(0, -"/index".length);
3223
3954
  if (!rel.startsWith(".")) rel = "./" + rel;
@@ -3294,17 +4025,17 @@ function modifyHandler(sourceFile, exportNames) {
3294
4025
  );
3295
4026
  }
3296
4027
  for (const call of sourceFile.getDescendantsOfKind(
3297
- import_ts_morph15.SyntaxKind.CallExpression
4028
+ import_ts_morph19.SyntaxKind.CallExpression
3298
4029
  )) {
3299
4030
  const callee = call.getExpression();
3300
- if (!import_ts_morph15.Node.isPropertyAccessExpression(callee)) continue;
4031
+ if (!import_ts_morph19.Node.isPropertyAccessExpression(callee)) continue;
3301
4032
  if (callee.getName() !== RESPONSE_METHOD_NAME) continue;
3302
4033
  const args = call.getArguments();
3303
4034
  if (args.length !== 1) continue;
3304
4035
  const [arg] = args;
3305
- if (!import_ts_morph15.Node.isArrayLiteralExpression(arg)) continue;
4036
+ if (!import_ts_morph19.Node.isArrayLiteralExpression(arg)) continue;
3306
4037
  if (arg.getElements().length === 0) continue;
3307
- if (!arg.getElements().every((el) => import_ts_morph15.Node.isIdentifier(el))) continue;
4038
+ if (!arg.getElements().every((el) => import_ts_morph19.Node.isIdentifier(el))) continue;
3308
4039
  arg.replaceWithText(EVENT_CONFIGS_IDENTIFIER);
3309
4040
  changes.push(
3310
4041
  `rewrote h.response([...]) \u2192 h.response(${EVENT_CONFIGS_IDENTIFIER})`
@@ -3312,13 +4043,13 @@ function modifyHandler(sourceFile, exportNames) {
3312
4043
  }
3313
4044
  return changes;
3314
4045
  }
3315
- async function main16() {
3316
- const cwd2 = getCwd();
3317
- const srcDir = import_path16.default.join(cwd2, "src");
4046
+ async function main21() {
4047
+ const cwd = process.cwd();
4048
+ const srcDir = import_path21.default.join(cwd, "src");
3318
4049
  console.log(`Scanning for defineConfig event exports in: ${srcDir}
3319
4050
  `);
3320
- const project = new import_ts_morph15.Project({
3321
- tsConfigFilePath: import_path16.default.resolve(srcDir, "../tsconfig.json"),
4051
+ const project = new import_ts_morph19.Project({
4052
+ tsConfigFilePath: import_path21.default.resolve(srcDir, "../tsconfig.json"),
3322
4053
  skipAddingFilesFromTsConfig: false
3323
4054
  });
3324
4055
  const eventConfigExports = findEventConfigExports(project, srcDir);
@@ -3330,15 +4061,15 @@ async function main16() {
3330
4061
  }
3331
4062
  console.log(`Found ${eventConfigExports.length} event config export(s):`);
3332
4063
  for (const e of eventConfigExports) {
3333
- console.log(` ${e.name} \u2190 ${import_path16.default.relative(cwd2, e.filePath)}`);
4064
+ console.log(` ${e.name} \u2190 ${import_path21.default.relative(cwd, e.filePath)}`);
3334
4065
  }
3335
- const eventsIndexAbs = import_path16.default.join(srcDir, "events", "index.ts");
3336
- const eventsIndexRel = import_path16.default.relative(cwd2, eventsIndexAbs);
3337
- if (import_fs.default.existsSync(eventsIndexAbs)) {
4066
+ const eventsIndexAbs = import_path21.default.join(srcDir, "events", "index.ts");
4067
+ const eventsIndexRel = import_path21.default.relative(cwd, eventsIndexAbs);
4068
+ if (import_fs2.default.existsSync(eventsIndexAbs)) {
3338
4069
  console.log(`
3339
4070
  [${eventsIndexRel}] already exists \u2014 leaving untouched.`);
3340
4071
  } else {
3341
- import_fs.default.mkdirSync(import_path16.default.dirname(eventsIndexAbs), { recursive: true });
4072
+ import_fs2.default.mkdirSync(import_path21.default.dirname(eventsIndexAbs), { recursive: true });
3342
4073
  const source = buildEventsIndexSource(eventConfigExports, srcDir);
3343
4074
  const eventsIndexFile = project.createSourceFile(eventsIndexAbs, source, {
3344
4075
  overwrite: false
@@ -3359,7 +4090,7 @@ No event-config handler file found (looked for exported function(s): ${Array.fro
3359
4090
  );
3360
4091
  return;
3361
4092
  }
3362
- const handlerRelPath = import_path16.default.relative(cwd2, handler.getFilePath());
4093
+ const handlerRelPath = import_path21.default.relative(cwd, handler.getFilePath());
3363
4094
  const exportNameSet = new Set(eventConfigExports.map((e) => e.name));
3364
4095
  const changes = modifyHandler(handler, exportNameSet);
3365
4096
  if (changes.length === 0) {
@@ -3379,12 +4110,13 @@ var UPSTREAM_URL = "https://github.com/opencrvs/opencrvs-countryconfig.git";
3379
4110
  var UPSTREAM_BRANCH = "develop";
3380
4111
  var TEMP_REMOTE = "opencrvs-upgrade-v19-v20-codemod";
3381
4112
  var FILES_TO_CHECKOUT = [
3382
- "infrastructure/postgres/setup-analytics.sh",
3383
- "src/analytics/analytics.ts"
4113
+ "src/analytics/analytics.ts",
4114
+ "Dockerfile",
4115
+ "Dockerfile.assets"
3384
4116
  ];
3385
4117
  function runGit(args, { silent = false } = {}) {
3386
4118
  return (0, import_child_process.execFileSync)("git", args, {
3387
- cwd: getCwd(),
4119
+ cwd: process.cwd(),
3388
4120
  encoding: "utf8",
3389
4121
  stdio: silent ? ["ignore", "pipe", "pipe"] : ["ignore", "pipe", "inherit"]
3390
4122
  });
@@ -3400,11 +4132,11 @@ function tryGit(args) {
3400
4132
  function assertIsGitRepo() {
3401
4133
  if (!tryGit(["rev-parse", "--is-inside-work-tree"])) {
3402
4134
  throw new Error(
3403
- `checkout-upstream-files: ${getCwd()} is not a git repository. Initialise git (or run the upgrade inside a git checkout) before re-running.`
4135
+ `${process.cwd()} is not a git repository. Initialise git (or run the upgrade inside a git checkout) before re-running.`
3404
4136
  );
3405
4137
  }
3406
4138
  }
3407
- async function main17() {
4139
+ async function main22() {
3408
4140
  console.log(
3409
4141
  `Checking out ${FILES_TO_CHECKOUT.length} file(s) from ${UPSTREAM_URL}@${UPSTREAM_BRANCH}...
3410
4142
  `
@@ -3452,10 +4184,356 @@ async function main17() {
3452
4184
  }
3453
4185
  }
3454
4186
 
4187
+ // src/migrations/v2.0/add-resend-invite-notification.ts
4188
+ var import_fs3 = require("fs");
4189
+ var import_path22 = __toESM(require("path"));
4190
+ var import_ts_morph20 = require("ts-morph");
4191
+ var TS_MORPH_PROJECT_OPTIONS = {
4192
+ skipAddingFilesFromTsConfig: true,
4193
+ manipulationSettings: {
4194
+ indentationText: import_ts_morph20.IndentationText.TwoSpaces
4195
+ }
4196
+ };
4197
+ var EMAIL_TEMPLATES_INDEX = "src/api/notification/email-templates/index.ts";
4198
+ var NOTIFICATION_HANDLER = "src/api/notification/handler.ts";
4199
+ var USER_NOTIFICATION_ROUTES = "src/config/routes/userNotificationRoutes.ts";
4200
+ var SMS_SERVICE = "src/api/notification/sms-service.ts";
4201
+ var NOTIFICATION_CSV = "src/translations/notification.csv";
4202
+ var RESEND_INVITE_HTML = "src/api/notification/email-templates/other/resend-invite.html";
4203
+ var RESEND_INVITE_HTML_CONTENT = `<!doctype html>
4204
+ <html>
4205
+ <head>
4206
+ <link
4207
+ href="https://fonts.googleapis.com/css2?family=Noto+Sans:wght@400;700&display=swap"
4208
+ rel="stylesheet"
4209
+ />
4210
+ <style type="text/css">
4211
+ body {
4212
+ font-family: 'Noto Sans', sans-serif;
4213
+ color: #222;
4214
+ padding: 16px 24px;
4215
+ }
4216
+
4217
+ h1 {
4218
+ font-size: 21px;
4219
+ margin-top: 32px;
4220
+ margin-bottom: 36px;
4221
+ font-weight: 700;
4222
+ }
4223
+
4224
+ p {
4225
+ font-weight: 400;
4226
+ font-size: 16px;
4227
+ line-height: 1.8;
4228
+ margin-bottom: 24px;
4229
+ }
4230
+
4231
+ i {
4232
+ color: #666;
4233
+ font-weight: 400;
4234
+ font-size: 16px;
4235
+ }
4236
+ </style>
4237
+ </head>
4238
+
4239
+ <body>
4240
+ <img
4241
+ src="{{countryLogo}}"
4242
+ alt="country_logo"
4243
+ style="max-height: 88px; max-width: 100%"
4244
+ />
4245
+ <h1>Your {{applicationName}} account invitation</h1>
4246
+ <p>Hello {{firstname}},</p>
4247
+ <p>Your account invitation has been resent. Please use the following credentials to access your account:</p>
4248
+ <p>
4249
+ Username: <strong>{{username}}</strong><br />
4250
+ Password: <strong>{{temporaryPassword}}</strong>
4251
+ </p>
4252
+ <p>
4253
+ Please click the link below to complete your account setup and start using
4254
+ {{applicationName}}.
4255
+ </p>
4256
+
4257
+ <div style="margin-top: 32px; margin-bottom: 32px">
4258
+ <a href="{{loginURL}}">Complete setup</a>
4259
+ </div>
4260
+ <br />
4261
+ <p>
4262
+ Best regards, <br />
4263
+ {{applicationName}} Team
4264
+ </p>
4265
+ </body>
4266
+ </html>
4267
+ `;
4268
+ 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";
4269
+ function getObjectLiteralFromConst(declaration) {
4270
+ if (!declaration) {
4271
+ return;
4272
+ }
4273
+ const initializer = declaration.getInitializer();
4274
+ if (!initializer) {
4275
+ return;
4276
+ }
4277
+ if (import_ts_morph20.Node.isObjectLiteralExpression(initializer)) {
4278
+ return initializer;
4279
+ }
4280
+ if (import_ts_morph20.Node.isAsExpression(initializer)) {
4281
+ const expression = initializer.getExpression();
4282
+ if (import_ts_morph20.Node.isObjectLiteralExpression(expression)) {
4283
+ return expression;
4284
+ }
4285
+ }
4286
+ if (import_ts_morph20.Node.isSatisfiesExpression(initializer)) {
4287
+ const expression = initializer.getExpression();
4288
+ if (import_ts_morph20.Node.isObjectLiteralExpression(expression)) {
4289
+ return expression;
4290
+ }
4291
+ }
4292
+ }
4293
+ function patchEmailTemplatesIndex() {
4294
+ const full = import_path22.default.join(process.cwd(), EMAIL_TEMPLATES_INDEX);
4295
+ if (!(0, import_fs3.existsSync)(full)) {
4296
+ console.log(` '${EMAIL_TEMPLATES_INDEX}' missing \u2014 skipping.`);
4297
+ return false;
4298
+ }
4299
+ const project = new import_ts_morph20.Project(TS_MORPH_PROJECT_OPTIONS);
4300
+ const sourceFile = project.addSourceFileAtPath(full);
4301
+ let changed = false;
4302
+ const triggerVariableObject = getObjectLiteralFromConst(
4303
+ sourceFile.getVariableDeclaration("TriggerVariable")
4304
+ );
4305
+ if (triggerVariableObject) {
4306
+ const hasResendInviteVariable = triggerVariableObject.getProperties().some((prop) => prop.getText().includes("[TriggerEvent.RESEND_INVITE]"));
4307
+ if (!hasResendInviteVariable) {
4308
+ const properties = triggerVariableObject.getProperties();
4309
+ const lastProperty = properties[properties.length - 1];
4310
+ if (lastProperty) {
4311
+ sourceFile.insertText(
4312
+ lastProperty.getEnd(),
4313
+ `,
4314
+ [TriggerEvent.RESEND_INVITE]: z.object({
4315
+ firstname: z.string(),
4316
+ username: z.string(),
4317
+ temporaryPassword: z.string(),
4318
+ completeSetupUrl: z.string(),
4319
+ loginURL: z.string()
4320
+ })`
4321
+ );
4322
+ changed = true;
4323
+ }
4324
+ }
4325
+ }
4326
+ const templatesObject = getObjectLiteralFromConst(
4327
+ sourceFile.getVariableDeclaration("templates")
4328
+ );
4329
+ if (templatesObject) {
4330
+ const hasResendInviteTemplate = templatesObject.getProperties().some(
4331
+ (prop) => prop.getText().includes("readOtherTemplate<TriggerVariable['resend-invite']>")
4332
+ );
4333
+ if (!hasResendInviteTemplate) {
4334
+ const userCreatedProp = templatesObject.getProperties().find((prop) => prop.getText().includes("[TriggerEvent.USER_CREATED]"));
4335
+ const anchor = userCreatedProp ?? templatesObject.getProperties()[templatesObject.getProperties().length - 1];
4336
+ if (anchor) {
4337
+ sourceFile.insertText(
4338
+ anchor.getEnd(),
4339
+ `,
4340
+ [TriggerEvent.RESEND_INVITE]: {
4341
+ type: 'resend-invite',
4342
+ subject: 'Your OpenCRVS account invitation',
4343
+ template:
4344
+ readOtherTemplate<TriggerVariable['resend-invite']>('resend-invite')
4345
+ }`
4346
+ );
4347
+ changed = true;
4348
+ }
4349
+ }
4350
+ }
4351
+ if (changed) {
4352
+ sourceFile.saveSync();
4353
+ }
4354
+ return changed;
4355
+ }
4356
+ function patchNotificationHandler() {
4357
+ const full = import_path22.default.join(process.cwd(), NOTIFICATION_HANDLER);
4358
+ if (!(0, import_fs3.existsSync)(full)) {
4359
+ return false;
4360
+ }
4361
+ const project = new import_ts_morph20.Project(TS_MORPH_PROJECT_OPTIONS);
4362
+ const sourceFile = project.addSourceFileAtPath(full);
4363
+ const convertFn = sourceFile.getFunction("convertPayloadToVariable");
4364
+ if (!convertFn) {
4365
+ return false;
4366
+ }
4367
+ const switchStmt = convertFn.getFirstDescendantByKind(
4368
+ import_ts_morph20.SyntaxKind.SwitchStatement
4369
+ );
4370
+ if (!switchStmt) {
4371
+ return false;
4372
+ }
4373
+ const clauses = switchStmt.getCaseBlock().getClauses();
4374
+ const hasResendInvite = clauses.some(
4375
+ (clause) => import_ts_morph20.Node.isCaseClause(clause) && clause.getExpression().getText() === "TriggerEvent.RESEND_INVITE"
4376
+ );
4377
+ if (hasResendInvite) {
4378
+ return false;
4379
+ }
4380
+ const userCreatedClauseIndex = clauses.findIndex(
4381
+ (clause) => import_ts_morph20.Node.isCaseClause(clause) && clause.getExpression().getText() === "TriggerEvent.USER_CREATED"
4382
+ );
4383
+ if (userCreatedClauseIndex < 0) {
4384
+ return false;
4385
+ }
4386
+ const userCreatedClause = clauses[userCreatedClauseIndex];
4387
+ sourceFile.insertText(
4388
+ userCreatedClause.getEnd(),
4389
+ `
4390
+
4391
+ case TriggerEvent.RESEND_INVITE:
4392
+ return {
4393
+ firstname,
4394
+ username: payload.username,
4395
+ temporaryPassword: payload.temporaryPassword,
4396
+ completeSetupUrl: LOGIN_URL,
4397
+ loginURL: LOGIN_URL
4398
+ }`
4399
+ );
4400
+ sourceFile.saveSync();
4401
+ return true;
4402
+ }
4403
+ function getReturnedArrayLiteral(functionFilePath, fnName) {
4404
+ const project = new import_ts_morph20.Project(TS_MORPH_PROJECT_OPTIONS);
4405
+ const sourceFile = project.addSourceFileAtPath(functionFilePath);
4406
+ const fn = sourceFile.getFunction(fnName);
4407
+ const returnStmt = fn?.getFirstDescendantByKind(import_ts_morph20.SyntaxKind.ReturnStatement);
4408
+ const expr = returnStmt?.getExpression();
4409
+ if (!expr || !import_ts_morph20.Node.isArrayLiteralExpression(expr)) {
4410
+ return { sourceFile, arrayLiteral: void 0 };
4411
+ }
4412
+ return { sourceFile, arrayLiteral: expr };
4413
+ }
4414
+ function patchUserNotificationRoutes() {
4415
+ const full = import_path22.default.join(process.cwd(), USER_NOTIFICATION_ROUTES);
4416
+ if (!(0, import_fs3.existsSync)(full)) {
4417
+ return false;
4418
+ }
4419
+ const { sourceFile, arrayLiteral } = getReturnedArrayLiteral(
4420
+ full,
4421
+ "getUserNotificationRoutes"
4422
+ );
4423
+ if (!arrayLiteral) {
4424
+ return false;
4425
+ }
4426
+ const elements = arrayLiteral.getElements();
4427
+ const routeExists = elements.some(
4428
+ (element) => element.getText().includes(`path: '/triggers/user/resend-invite'`)
4429
+ );
4430
+ if (routeExists) {
4431
+ return false;
4432
+ }
4433
+ const anchor = elements.find(
4434
+ (element) => element.getText().includes(`path: '/triggers/user/user-created'`)
4435
+ ) ?? elements[elements.length - 1];
4436
+ if (!anchor) {
4437
+ return false;
4438
+ }
4439
+ sourceFile.insertText(
4440
+ anchor.getEnd(),
4441
+ `,
4442
+ {
4443
+ method: 'POST',
4444
+ path: '/triggers/user/resend-invite',
4445
+ handler: makeNotificationHandler('resend-invite'),
4446
+ options: {
4447
+ auth: false,
4448
+ tags: ['api'],
4449
+ description: 'Handles notification for resent user invite'
4450
+ }
4451
+ }`
4452
+ );
4453
+ sourceFile.saveSync();
4454
+ return true;
4455
+ }
4456
+ function patchSmsService() {
4457
+ const full = import_path22.default.join(process.cwd(), SMS_SERVICE);
4458
+ if (!(0, import_fs3.existsSync)(full)) {
4459
+ return false;
4460
+ }
4461
+ const project = new import_ts_morph20.Project(TS_MORPH_PROJECT_OPTIONS);
4462
+ const sourceFile = project.addSourceFileAtPath(full);
4463
+ let changed = false;
4464
+ const otherTemplatesObject = getObjectLiteralFromConst(
4465
+ sourceFile.getVariableDeclaration("otherTemplates")
4466
+ );
4467
+ if (otherTemplatesObject) {
4468
+ const hasResendTemplate = otherTemplatesObject.getProperties().some((prop) => prop.getText().includes("resendInviteNotification"));
4469
+ if (!hasResendTemplate) {
4470
+ const userCredentialsIndex = otherTemplatesObject.getProperties().findIndex((prop) => prop.getText().includes("userCredentialsNotification"));
4471
+ otherTemplatesObject.insertPropertyAssignment(
4472
+ userCredentialsIndex >= 0 ? userCredentialsIndex + 1 : otherTemplatesObject.getProperties().length,
4473
+ {
4474
+ name: "resendInviteNotification",
4475
+ initializer: `'resendInviteNotification'`
4476
+ }
4477
+ );
4478
+ changed = true;
4479
+ }
4480
+ }
4481
+ const triggerToSmsTemplateObject = getObjectLiteralFromConst(
4482
+ sourceFile.getVariableDeclaration("TriggerToSMSTemplate")
4483
+ );
4484
+ if (triggerToSmsTemplateObject) {
4485
+ const hasResendInviteMap = triggerToSmsTemplateObject.getProperties().some((prop) => prop.getText().includes(`['resend-invite']`));
4486
+ if (!hasResendInviteMap) {
4487
+ const userCreatedIndex = triggerToSmsTemplateObject.getProperties().findIndex((prop) => prop.getText().includes(`['user-created']`));
4488
+ triggerToSmsTemplateObject.insertPropertyAssignment(
4489
+ userCreatedIndex >= 0 ? userCreatedIndex + 1 : triggerToSmsTemplateObject.getProperties().length,
4490
+ {
4491
+ name: `['resend-invite']`,
4492
+ initializer: `'resendInviteNotification'`
4493
+ }
4494
+ );
4495
+ changed = true;
4496
+ }
4497
+ }
4498
+ if (changed) {
4499
+ sourceFile.saveSync();
4500
+ }
4501
+ return changed;
4502
+ }
4503
+ async function main23() {
4504
+ console.log("Adding RESEND_INVITE notification wiring\u2026");
4505
+ const touched = [];
4506
+ if (patchEmailTemplatesIndex()) touched.push(EMAIL_TEMPLATES_INDEX);
4507
+ if (patchNotificationHandler()) touched.push(NOTIFICATION_HANDLER);
4508
+ if (patchUserNotificationRoutes()) touched.push(USER_NOTIFICATION_ROUTES);
4509
+ if (patchSmsService()) touched.push(SMS_SERVICE);
4510
+ const csvPath = import_path22.default.join(process.cwd(), NOTIFICATION_CSV);
4511
+ if ((0, import_fs3.existsSync)(csvPath)) {
4512
+ let t = (0, import_fs3.readFileSync)(csvPath, "utf8");
4513
+ if (!/^resendInviteNotification,/m.test(t)) {
4514
+ if (!t.endsWith("\n")) t += "\n";
4515
+ (0, import_fs3.writeFileSync)(csvPath, t + CSV_ROW);
4516
+ touched.push(NOTIFICATION_CSV);
4517
+ }
4518
+ }
4519
+ const htmlPath = import_path22.default.join(process.cwd(), RESEND_INVITE_HTML);
4520
+ (0, import_fs3.mkdirSync)(import_path22.default.dirname(htmlPath), { recursive: true });
4521
+ if (!(0, import_fs3.existsSync)(htmlPath)) {
4522
+ (0, import_fs3.writeFileSync)(htmlPath, RESEND_INVITE_HTML_CONTENT);
4523
+ touched.push(RESEND_INVITE_HTML);
4524
+ }
4525
+ if (touched.length === 0) {
4526
+ console.log(" Nothing to update (already present or anchors not found).");
4527
+ return;
4528
+ }
4529
+ console.log(` Updated:
4530
+ ${touched.map((f) => ` - ${f}`).join("\n")}`);
4531
+ }
4532
+
3455
4533
  // src/migrations/v2.0/simplify-analytics-precalculations.ts
3456
- var import_ts_morph16 = require("ts-morph");
3457
- var import_fs2 = __toESM(require("fs"));
3458
- var import_path17 = __toESM(require("path"));
4534
+ var import_ts_morph21 = require("ts-morph");
4535
+ var import_fs4 = __toESM(require("fs"));
4536
+ var import_path23 = __toESM(require("path"));
3459
4537
  var ANALYTICS_FILE_REL = "src/analytics/analytics.ts";
3460
4538
  var FUNCTION_NAME = "precalculateAdditionalAnalytics";
3461
4539
  var IMPORT_NAMES_TO_REMOVE = /* @__PURE__ */ new Set(["Event", "precalculateBirthEvent"]);
@@ -3491,10 +4569,10 @@ function findPrecalculateFunction(sourceFile) {
3491
4569
  return void 0;
3492
4570
  }
3493
4571
  function getFunctionBodyBlock(fn) {
3494
- if (import_ts_morph16.Node.isFunctionDeclaration(fn)) return fn.getBody();
4572
+ if (import_ts_morph21.Node.isFunctionDeclaration(fn)) return fn.getBody();
3495
4573
  const initializer = fn.getInitializer();
3496
4574
  if (!initializer) return void 0;
3497
- if (!import_ts_morph16.Node.isArrowFunction(initializer) && !import_ts_morph16.Node.isFunctionExpression(initializer)) {
4575
+ if (!import_ts_morph21.Node.isArrowFunction(initializer) && !import_ts_morph21.Node.isFunctionExpression(initializer)) {
3498
4576
  return void 0;
3499
4577
  }
3500
4578
  return initializer.getBody();
@@ -3504,9 +4582,9 @@ function simplifyPrecalculateFunction(sourceFile) {
3504
4582
  const fn = findPrecalculateFunction(sourceFile);
3505
4583
  if (!fn) return log;
3506
4584
  const body = getFunctionBodyBlock(fn);
3507
- if (!body || !import_ts_morph16.Node.isBlock(body)) return log;
4585
+ if (!body || !import_ts_morph21.Node.isBlock(body)) return log;
3508
4586
  for (const statement of [...body.getStatements()]) {
3509
- const references = statement.getDescendantsOfKind(import_ts_morph16.SyntaxKind.Identifier).some((id) => IMPORT_NAMES_TO_REMOVE.has(id.getText()));
4587
+ const references = statement.getDescendantsOfKind(import_ts_morph21.SyntaxKind.Identifier).some((id) => IMPORT_NAMES_TO_REMOVE.has(id.getText()));
3510
4588
  if (references) {
3511
4589
  statement.remove();
3512
4590
  log.push(`removed statement in ${FUNCTION_NAME} referencing removed imports`);
@@ -3514,7 +4592,7 @@ function simplifyPrecalculateFunction(sourceFile) {
3514
4592
  }
3515
4593
  const remaining = body.getStatements();
3516
4594
  const last = remaining[remaining.length - 1];
3517
- const alreadyCorrect = last && import_ts_morph16.Node.isReturnStatement(last) && last.getExpression()?.getText() === RETURN_EXPRESSION_TEXT;
4595
+ const alreadyCorrect = last && import_ts_morph21.Node.isReturnStatement(last) && last.getExpression()?.getText() === RETURN_EXPRESSION_TEXT;
3518
4596
  if (!alreadyCorrect) {
3519
4597
  body.addStatements(`return ${RETURN_EXPRESSION_TEXT}`);
3520
4598
  log.push(
@@ -3523,17 +4601,17 @@ function simplifyPrecalculateFunction(sourceFile) {
3523
4601
  }
3524
4602
  return log;
3525
4603
  }
3526
- async function main18() {
3527
- const cwd2 = getCwd();
3528
- const absPath = import_path17.default.join(cwd2, ANALYTICS_FILE_REL);
3529
- if (!import_fs2.default.existsSync(absPath)) {
4604
+ async function main24() {
4605
+ const cwd = process.cwd();
4606
+ const absPath = import_path23.default.join(cwd, ANALYTICS_FILE_REL);
4607
+ if (!import_fs4.default.existsSync(absPath)) {
3530
4608
  console.log(
3531
4609
  `[${ANALYTICS_FILE_REL}] does not exist \u2014 nothing to clean up.`
3532
4610
  );
3533
4611
  return;
3534
4612
  }
3535
- const project = new import_ts_morph16.Project({
3536
- tsConfigFilePath: import_path17.default.resolve(cwd2, "tsconfig.json"),
4613
+ const project = new import_ts_morph21.Project({
4614
+ tsConfigFilePath: import_path23.default.resolve(cwd, "tsconfig.json"),
3537
4615
  skipAddingFilesFromTsConfig: false
3538
4616
  });
3539
4617
  const sourceFile = project.getSourceFile(absPath);
@@ -3560,26 +4638,158 @@ async function main18() {
3560
4638
  Saved ${ANALYTICS_FILE_REL}.`);
3561
4639
  }
3562
4640
 
3563
- // src/migrations/v2.0/index.ts
3564
- var cwd;
3565
- function getCwd() {
3566
- if (!cwd) {
3567
- throw new Error("Country config working directory not set.");
4641
+ // src/migrations/v2.0/merge-infrastructure-directory.ts
4642
+ var import_child_process2 = require("child_process");
4643
+ var import_fs5 = require("fs");
4644
+ var import_os = require("os");
4645
+ var import_path24 = require("path");
4646
+ var TEMP_REMOTE2 = "opencrvs-upgrade-v19-v20-codemod-merge-infra";
4647
+ var INFRASTRUCTURE_DIR = "infrastructure";
4648
+ var BASE_BRANCH = "release-v1.9";
4649
+ function gitShowBytes(ref, path23) {
4650
+ try {
4651
+ const buf = (0, import_child_process2.execFileSync)("git", ["show", `${ref}:${path23}`], {
4652
+ cwd: process.cwd(),
4653
+ stdio: ["ignore", "pipe", "pipe"]
4654
+ });
4655
+ return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
4656
+ } catch {
4657
+ return null;
3568
4658
  }
3569
- return cwd;
3570
4659
  }
3571
- async function runUpgrade(ccwd) {
3572
- if (ccwd) {
3573
- console.log("Country config working directory:", ccwd);
3574
- cwd = ccwd;
4660
+ async function main25() {
4661
+ console.log(
4662
+ `Merging '${INFRASTRUCTURE_DIR}/' from ${UPSTREAM_URL}@${UPSTREAM_BRANCH} (base: ${BASE_BRANCH})...
4663
+ `
4664
+ );
4665
+ assertIsGitRepo();
4666
+ tryGit(["remote", "remove", TEMP_REMOTE2]);
4667
+ try {
4668
+ console.log(` Adding temporary remote '${TEMP_REMOTE2}' \u2192 ${UPSTREAM_URL}`);
4669
+ runGit(["remote", "add", TEMP_REMOTE2, UPSTREAM_URL], { silent: true });
4670
+ console.log(
4671
+ ` Fetching ${TEMP_REMOTE2}/{${UPSTREAM_BRANCH},${BASE_BRANCH}} (depth 1)...`
4672
+ );
4673
+ runGit(["fetch", "--depth=1", TEMP_REMOTE2, UPSTREAM_BRANCH, BASE_BRANCH]);
4674
+ const ref = `${TEMP_REMOTE2}/${UPSTREAM_BRANCH}`;
4675
+ const baseRef = `${TEMP_REMOTE2}/${BASE_BRANCH}`;
4676
+ const upstreamFiles = runGit(
4677
+ [
4678
+ "ls-tree",
4679
+ "-r",
4680
+ "--name-only",
4681
+ "-z",
4682
+ ref,
4683
+ "--",
4684
+ `${INFRASTRUCTURE_DIR}/`
4685
+ ],
4686
+ { silent: true }
4687
+ ).split("\0").filter(Boolean);
4688
+ if (upstreamFiles.length === 0) {
4689
+ console.log(
4690
+ ` No files found under '${INFRASTRUCTURE_DIR}/' on ${ref}. Nothing to merge.`
4691
+ );
4692
+ return;
4693
+ }
4694
+ const tmpDir = (0, import_fs5.mkdtempSync)((0, import_path24.join)((0, import_os.tmpdir)(), "opencrvs-merge-infra-"));
4695
+ const baseTmp = (0, import_path24.join)(tmpDir, "base");
4696
+ const theirsTmp = (0, import_path24.join)(tmpDir, "theirs");
4697
+ let added = 0;
4698
+ let merged = 0;
4699
+ const conflictedFiles = [];
4700
+ for (const file of upstreamFiles) {
4701
+ const fullPath = (0, import_path24.join)(process.cwd(), file);
4702
+ if (!(0, import_fs5.existsSync)(fullPath)) {
4703
+ if (tryGit(["checkout", ref, "--", file])) {
4704
+ console.log(` + ${file} (new from upstream)`);
4705
+ added++;
4706
+ } else {
4707
+ console.warn(` [warn] failed to add new file ${file}`);
4708
+ }
4709
+ continue;
4710
+ }
4711
+ const theirContents = gitShowBytes(ref, file);
4712
+ if (theirContents === null) {
4713
+ console.warn(` [warn] could not read ${file} from ${ref} \u2014 skipping.`);
4714
+ continue;
4715
+ }
4716
+ (0, import_fs5.writeFileSync)(theirsTmp, theirContents);
4717
+ const baseContents = gitShowBytes(baseRef, file);
4718
+ (0, import_fs5.writeFileSync)(baseTmp, baseContents ?? new Uint8Array(0));
4719
+ try {
4720
+ (0, import_child_process2.execFileSync)("git", ["merge-file", fullPath, baseTmp, theirsTmp], {
4721
+ cwd: process.cwd(),
4722
+ stdio: ["ignore", "pipe", "pipe"]
4723
+ });
4724
+ runGit(["add", "--", file], { silent: true });
4725
+ merged++;
4726
+ } catch (err) {
4727
+ const status = err.status;
4728
+ if (typeof status === "number" && status > 0) {
4729
+ conflictedFiles.push(file);
4730
+ console.warn(
4731
+ ` ! ${file} (${status} conflict${status > 1 ? "s" : ""})`
4732
+ );
4733
+ } else {
4734
+ conflictedFiles.push(file);
4735
+ console.warn(
4736
+ ` [warn] merge failed for ${file} (likely binary or unreadable) \u2014 left untouched.`
4737
+ );
4738
+ }
4739
+ }
4740
+ }
4741
+ console.log(
4742
+ `
4743
+ Done. ${added} added, ${merged} merged cleanly, ${conflictedFiles.length} with conflicts.`
4744
+ );
4745
+ if (conflictedFiles.length > 0) {
4746
+ console.warn(
4747
+ `
4748
+ NOTE: ${conflictedFiles.length} file(s) under '${INFRASTRUCTURE_DIR}/' have merge conflicts that you must resolve manually.
4749
+ Look for the standard conflict markers (<<<<<<<, =======, >>>>>>>) in:
4750
+ ` + conflictedFiles.map((f) => ` - ${f}`).join("\n") + `
4751
+ After resolving, stage the fixes with: git add ${INFRASTRUCTURE_DIR}/`
4752
+ );
4753
+ }
4754
+ } finally {
4755
+ if (tryGit(["remote", "remove", TEMP_REMOTE2])) {
4756
+ console.log(` Removed temporary remote '${TEMP_REMOTE2}'.`);
4757
+ }
3575
4758
  }
3576
- if (!ccwd) {
4759
+ }
4760
+
4761
+ // src/migrations/v2.0/delete-infrastructure-directory.ts
4762
+ var import_fs6 = require("fs");
4763
+ var import_path25 = require("path");
4764
+ var INFRASTRUCTURE_DIR2 = "infrastructure";
4765
+ async function main26() {
4766
+ const fullPath = (0, import_path25.join)(process.cwd(), INFRASTRUCTURE_DIR2);
4767
+ if (!(0, import_fs6.existsSync)(fullPath)) {
3577
4768
  console.log(
3578
- "Will use current working directory as country config working directory."
4769
+ `'${INFRASTRUCTURE_DIR2}/' not found in ${process.cwd()} \u2014 nothing to delete.`
3579
4770
  );
3580
- cwd = process.cwd();
4771
+ return;
3581
4772
  }
3582
- await main13();
4773
+ console.log(`Deleting '${INFRASTRUCTURE_DIR2}/'...
4774
+ `);
4775
+ assertIsGitRepo();
4776
+ runGit(["rm", "-rf", "--ignore-unmatch", "--", `${INFRASTRUCTURE_DIR2}/`], {
4777
+ silent: true
4778
+ });
4779
+ console.log(` Staged deletion of tracked files under '${INFRASTRUCTURE_DIR2}/'.`);
4780
+ if ((0, import_fs6.existsSync)(fullPath)) {
4781
+ (0, import_fs6.rmSync)(fullPath, { recursive: true, force: true });
4782
+ console.log(` Removed remaining untracked files under '${INFRASTRUCTURE_DIR2}/'.`);
4783
+ }
4784
+ console.log(
4785
+ `
4786
+ Done. Review the staged deletion with: git diff --cached -- '${INFRASTRUCTURE_DIR2}/'`
4787
+ );
4788
+ }
4789
+
4790
+ // src/migrations/v2.0/index.ts
4791
+ async function runUpgrade(dockerSwarm) {
4792
+ await main18();
3583
4793
  await main();
3584
4794
  await main2();
3585
4795
  await main3();
@@ -3592,9 +4802,20 @@ async function runUpgrade(ccwd) {
3592
4802
  await main10();
3593
4803
  await main11();
3594
4804
  await main12();
4805
+ await main13();
3595
4806
  await main14();
3596
4807
  await main15();
3597
4808
  await main16();
4809
+ await main19();
4810
+ await main20();
4811
+ await main21();
4812
+ await main22();
4813
+ await main23();
4814
+ await main24();
3598
4815
  await main17();
3599
- await main18();
4816
+ if (dockerSwarm) {
4817
+ await main25();
4818
+ } else {
4819
+ await main26();
4820
+ }
3600
4821
  }