@opencrvs/toolkit 1.9.12-rc.fdec004 → 1.9.12-rc.ff04697

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 (53) hide show
  1. package/dist/cli.js +246 -80
  2. package/dist/commons/api/router.d.ts +72 -67
  3. package/dist/events/index.js +1 -10
  4. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts.map +1 -1
  5. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.js +3 -4
  6. package/dist/migrations/v2.0/checkout-upstream-files.d.ts +19 -0
  7. package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +1 -1
  8. package/dist/migrations/v2.0/checkout-upstream-files.js +17 -13
  9. package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts.map +1 -1
  10. package/dist/migrations/v2.0/convert-config-files-to-ts.js +4 -5
  11. package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts.map +1 -1
  12. package/dist/migrations/v2.0/convert-paragraph-to-heading.js +4 -5
  13. package/dist/migrations/v2.0/create-events-index.d.ts.map +1 -1
  14. package/dist/migrations/v2.0/create-events-index.js +1 -2
  15. package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts +3 -0
  16. package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts.map +1 -0
  17. package/dist/migrations/v2.0/delete-infrastructure-directory.js +77 -0
  18. package/dist/migrations/v2.0/index.d.ts +8 -4
  19. package/dist/migrations/v2.0/index.d.ts.map +1 -1
  20. package/dist/migrations/v2.0/index.js +214 -77
  21. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts.map +1 -1
  22. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.js +5 -6
  23. package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts +3 -0
  24. package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts.map +1 -0
  25. package/dist/migrations/v2.0/merge-infrastructure-directory.js +221 -0
  26. package/dist/migrations/v2.0/migrate-scopes.d.ts.map +1 -1
  27. package/dist/migrations/v2.0/migrate-scopes.js +6 -7
  28. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts.map +1 -1
  29. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.js +3 -4
  30. package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts.map +1 -1
  31. package/dist/migrations/v2.0/migrate-workqueue-configs.js +3 -4
  32. package/dist/migrations/v2.0/remove-delete-actions.d.ts.map +1 -1
  33. package/dist/migrations/v2.0/remove-delete-actions.js +3 -4
  34. package/dist/migrations/v2.0/remove-demo-scope.d.ts.map +1 -1
  35. package/dist/migrations/v2.0/remove-demo-scope.js +2 -3
  36. package/dist/migrations/v2.0/remove-deprecated-imports.d.ts.map +1 -1
  37. package/dist/migrations/v2.0/remove-deprecated-imports.js +3 -4
  38. package/dist/migrations/v2.0/remove-hearth-migrations.d.ts.map +1 -1
  39. package/dist/migrations/v2.0/remove-hearth-migrations.js +1 -2
  40. package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts.map +1 -1
  41. package/dist/migrations/v2.0/remove-pending-certification-flag.js +3 -4
  42. package/dist/migrations/v2.0/remove-review-from-register-action.d.ts.map +1 -1
  43. package/dist/migrations/v2.0/remove-review-from-register-action.js +3 -4
  44. package/dist/migrations/v2.0/rename-api-paths.d.ts.map +1 -1
  45. package/dist/migrations/v2.0/rename-api-paths.js +3 -4
  46. package/dist/migrations/v2.0/rename-location-parent-id.d.ts.map +1 -1
  47. package/dist/migrations/v2.0/rename-location-parent-id.js +3 -4
  48. package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts.map +1 -1
  49. package/dist/migrations/v2.0/simplify-analytics-precalculations.js +1 -2
  50. package/opencrvs-toolkit-1.9.12-rc.ff04697.tgz +0 -0
  51. package/package.json +1 -1
  52. package/tsconfig.tsbuildinfo +1 -1
  53. package/opencrvs-toolkit-1.9.12-rc.fdec004.tgz +0 -0
package/dist/cli.js CHANGED
@@ -91,7 +91,7 @@ function processFile(filePath, project) {
91
91
  if (wasRemoved) {
92
92
  removedCount++;
93
93
  console.log(
94
- ` [${import_path.default.relative(getCwd(), filePath)}] Removed 'review' from REGISTER action`
94
+ ` [${import_path.default.relative(process.cwd(), filePath)}] Removed 'review' from REGISTER action`
95
95
  );
96
96
  }
97
97
  }
@@ -99,7 +99,7 @@ function processFile(filePath, project) {
99
99
  return removedCount;
100
100
  }
101
101
  async function main() {
102
- const srcDir = import_path.default.join(getCwd(), "src");
102
+ const srcDir = import_path.default.join(process.cwd(), "src");
103
103
  console.log(`Scanning for defineConfig calls in: ${srcDir}
104
104
  `);
105
105
  const project = new import_ts_morph.Project({
@@ -135,7 +135,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
135
135
  for (const filePath of modifiedFiles) {
136
136
  const sourceFile = project.getSourceFileOrThrow(filePath);
137
137
  await sourceFile.save();
138
- console.log(` Saved: ${import_path.default.relative(getCwd(), filePath)}`);
138
+ console.log(` Saved: ${import_path.default.relative(process.cwd(), filePath)}`);
139
139
  }
140
140
  console.log(
141
141
  `
@@ -338,7 +338,7 @@ function processFile2(filePath, project) {
338
338
  const eventType = resolveEventType(configArg);
339
339
  if (!eventType) {
340
340
  console.warn(
341
- ` [${import_path2.default.relative(getCwd(), configArg.getSourceFile().getFilePath())}] Could not resolve root 'type' from defineConfig \u2014 skipping auditHistoryLabel id generation`
341
+ ` [${import_path2.default.relative(process.cwd(), configArg.getSourceFile().getFilePath())}] Could not resolve root 'type' from defineConfig \u2014 skipping auditHistoryLabel id generation`
342
342
  );
343
343
  }
344
344
  let fileNeedsImports = false;
@@ -354,7 +354,7 @@ function processFile2(filePath, project) {
354
354
  fileNeedsImports = true;
355
355
  configHadValidateAction = true;
356
356
  console.log(
357
- ` [${import_path2.default.relative(getCwd(), filePath)}] Transformed VALIDATE action to CUSTOM with customActionType: '${VALIDATE_DECLARATION_VALUE}'`
357
+ ` [${import_path2.default.relative(process.cwd(), filePath)}] Transformed VALIDATE action to CUSTOM with customActionType: '${VALIDATE_DECLARATION_VALUE}'`
358
358
  );
359
359
  }
360
360
  }
@@ -375,7 +375,7 @@ function processFile2(filePath, project) {
375
375
  ]`
376
376
  });
377
377
  console.log(
378
- ` [${import_path2.default.relative(getCwd(), filePath)}] Added top-level 'flags' array to defineConfig`
378
+ ` [${import_path2.default.relative(process.cwd(), filePath)}] Added top-level 'flags' array to defineConfig`
379
379
  );
380
380
  }
381
381
  if (fileNeedsImports) {
@@ -385,7 +385,7 @@ function processFile2(filePath, project) {
385
385
  return transformedCount;
386
386
  }
387
387
  async function main2() {
388
- const srcDir = import_path2.default.join(getCwd(), "src");
388
+ const srcDir = import_path2.default.join(process.cwd(), "src");
389
389
  console.log(`Scanning for defineConfig calls in: ${srcDir}
390
390
  `);
391
391
  const project = new import_ts_morph2.Project({
@@ -420,7 +420,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
420
420
  for (const filePath of modifiedFiles) {
421
421
  const sourceFile = project.getSourceFileOrThrow(filePath);
422
422
  await sourceFile.save();
423
- console.log(` Saved: ${import_path2.default.relative(getCwd(), filePath)}`);
423
+ console.log(` Saved: ${import_path2.default.relative(process.cwd(), filePath)}`);
424
424
  }
425
425
  console.log(
426
426
  `
@@ -491,14 +491,14 @@ function processFile3(filePath, project) {
491
491
  actionsInitializer.removeElement(index);
492
492
  removedCount++;
493
493
  console.log(
494
- ` [${import_path3.default.relative(getCwd(), filePath)}] Removed DELETE action at index ${index}`
494
+ ` [${import_path3.default.relative(process.cwd(), filePath)}] Removed DELETE action at index ${index}`
495
495
  );
496
496
  }
497
497
  }
498
498
  return removedCount;
499
499
  }
500
500
  async function main3() {
501
- const srcDir = import_path3.default.join(getCwd(), "src");
501
+ const srcDir = import_path3.default.join(process.cwd(), "src");
502
502
  console.log(`Scanning for defineConfig calls in: ${srcDir}
503
503
  `);
504
504
  const project = new import_ts_morph3.Project({
@@ -533,7 +533,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
533
533
  for (const filePath of modifiedFiles) {
534
534
  const sourceFile = project.getSourceFileOrThrow(filePath);
535
535
  await sourceFile.save();
536
- console.log(` Saved: ${import_path3.default.relative(getCwd(), filePath)}`);
536
+ console.log(` Saved: ${import_path3.default.relative(process.cwd(), filePath)}`);
537
537
  }
538
538
  console.log(
539
539
  `
@@ -607,19 +607,19 @@ function processFile4(filePath, project) {
607
607
  if (result === "converted-to-heading") {
608
608
  changedCount++;
609
609
  console.log(
610
- ` [${import_path4.default.relative(getCwd(), filePath)}] Converted PARAGRAPH with heading fontVariant to HEADING`
610
+ ` [${import_path4.default.relative(process.cwd(), filePath)}] Converted PARAGRAPH with heading fontVariant to HEADING`
611
611
  );
612
612
  } else if (result === "removed-font-variant") {
613
613
  changedCount++;
614
614
  console.log(
615
- ` [${import_path4.default.relative(getCwd(), filePath)}] Removed non-heading fontVariant from PARAGRAPH`
615
+ ` [${import_path4.default.relative(process.cwd(), filePath)}] Removed non-heading fontVariant from PARAGRAPH`
616
616
  );
617
617
  }
618
618
  }
619
619
  return changedCount;
620
620
  }
621
621
  async function main4() {
622
- const srcDir = import_path4.default.join(getCwd(), "src");
622
+ const srcDir = import_path4.default.join(process.cwd(), "src");
623
623
  console.log(`Scanning for FieldType.PARAGRAPH fields in: ${srcDir}
624
624
  `);
625
625
  const project = new import_ts_morph4.Project({
@@ -653,7 +653,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
653
653
  for (const filePath of modifiedFiles) {
654
654
  const sourceFile = project.getSourceFileOrThrow(filePath);
655
655
  await sourceFile.save();
656
- console.log(` Saved: ${import_path4.default.relative(getCwd(), filePath)}`);
656
+ console.log(` Saved: ${import_path4.default.relative(process.cwd(), filePath)}`);
657
657
  }
658
658
  console.log(`
659
659
  Done. Processed ${totalChanged} FieldType.PARAGRAPH field(s).`);
@@ -803,7 +803,7 @@ function processFile5(filePath, project) {
803
803
  if (changed > 0) {
804
804
  migratedCount += changed;
805
805
  console.log(
806
- ` [${import_path5.default.relative(getCwd(), filePath)}] Migrated ${changed} clause(s): VALIDATED status \u2192 flags.anyOf`
806
+ ` [${import_path5.default.relative(process.cwd(), filePath)}] Migrated ${changed} clause(s): VALIDATED status \u2192 flags.anyOf`
807
807
  );
808
808
  }
809
809
  }
@@ -811,7 +811,7 @@ function processFile5(filePath, project) {
811
811
  return migratedCount;
812
812
  }
813
813
  async function main5() {
814
- const srcDir = import_path5.default.join(getCwd(), "src");
814
+ const srcDir = import_path5.default.join(process.cwd(), "src");
815
815
  console.log(`Scanning for defineWorkqueues calls in: ${srcDir}
816
816
  `);
817
817
  const project = new import_ts_morph5.Project({
@@ -845,7 +845,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
845
845
  for (const filePath of modifiedFiles) {
846
846
  const sourceFile = project.getSourceFileOrThrow(filePath);
847
847
  await sourceFile.save();
848
- console.log(` Saved: ${import_path5.default.relative(getCwd(), filePath)}`);
848
+ console.log(` Saved: ${import_path5.default.relative(process.cwd(), filePath)}`);
849
849
  }
850
850
  console.log(
851
851
  `
@@ -1063,7 +1063,7 @@ function processFile6(filePath, project) {
1063
1063
  const sourceFile = project.getSourceFile(filePath);
1064
1064
  if (!sourceFile) return 0;
1065
1065
  let totalChanges = 0;
1066
- const relPath = import_path6.default.relative(getCwd(), filePath);
1066
+ const relPath = import_path6.default.relative(process.cwd(), filePath);
1067
1067
  const callExpressions = sourceFile.getDescendantsOfKind(
1068
1068
  import_ts_morph6.SyntaxKind.CallExpression
1069
1069
  );
@@ -1104,7 +1104,7 @@ function processFile6(filePath, project) {
1104
1104
  return totalChanges;
1105
1105
  }
1106
1106
  async function main6() {
1107
- const srcDir = import_path6.default.join(getCwd(), "src");
1107
+ const srcDir = import_path6.default.join(process.cwd(), "src");
1108
1108
  console.log(
1109
1109
  `Scanning for birth defineConfig and PRINT_CERTIFICATE workqueues in: ${srcDir}
1110
1110
  `
@@ -1140,7 +1140,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
1140
1140
  for (const filePath of modifiedFiles) {
1141
1141
  const sourceFile = project.getSourceFileOrThrow(filePath);
1142
1142
  await sourceFile.save();
1143
- console.log(` Saved: ${import_path6.default.relative(getCwd(), filePath)}`);
1143
+ console.log(` Saved: ${import_path6.default.relative(process.cwd(), filePath)}`);
1144
1144
  }
1145
1145
  console.log(
1146
1146
  `
@@ -1177,14 +1177,14 @@ function processFile7(filePath, project) {
1177
1177
  array3.removeElement(index);
1178
1178
  removedCount++;
1179
1179
  console.log(
1180
- ` [${import_path7.default.relative(getCwd(), filePath)}] Removed InherentFlags.PENDING_CERTIFICATION from array`
1180
+ ` [${import_path7.default.relative(process.cwd(), filePath)}] Removed InherentFlags.PENDING_CERTIFICATION from array`
1181
1181
  );
1182
1182
  }
1183
1183
  }
1184
1184
  return removedCount;
1185
1185
  }
1186
1186
  async function main7() {
1187
- const srcDir = import_path7.default.join(getCwd(), "src");
1187
+ const srcDir = import_path7.default.join(process.cwd(), "src");
1188
1188
  console.log(
1189
1189
  `Scanning for InherentFlags.PENDING_CERTIFICATION array elements in: ${srcDir}
1190
1190
  `
@@ -1220,7 +1220,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
1220
1220
  for (const filePath of modifiedFiles) {
1221
1221
  const sourceFile = project.getSourceFileOrThrow(filePath);
1222
1222
  await sourceFile.save();
1223
- console.log(` Saved: ${import_path7.default.relative(getCwd(), filePath)}`);
1223
+ console.log(` Saved: ${import_path7.default.relative(process.cwd(), filePath)}`);
1224
1224
  }
1225
1225
  console.log(
1226
1226
  `
@@ -1278,13 +1278,13 @@ function processFile8(filePath, project) {
1278
1278
  propAccess.getNameNode().replaceWithText(NEW_PROPERTY_NAME);
1279
1279
  renamedCount++;
1280
1280
  console.log(
1281
- ` [${import_path8.default.relative(getCwd(), filePath)}] Renamed Location.${OLD_PROPERTY_NAME} \u2192 Location.${NEW_PROPERTY_NAME}`
1281
+ ` [${import_path8.default.relative(process.cwd(), filePath)}] Renamed Location.${OLD_PROPERTY_NAME} \u2192 Location.${NEW_PROPERTY_NAME}`
1282
1282
  );
1283
1283
  }
1284
1284
  return renamedCount;
1285
1285
  }
1286
1286
  async function main8() {
1287
- const srcDir = import_path8.default.join(getCwd(), "src");
1287
+ const srcDir = import_path8.default.join(process.cwd(), "src");
1288
1288
  console.log(
1289
1289
  `Scanning for Location.${OLD_PROPERTY_NAME} references in: ${srcDir}
1290
1290
  `
@@ -1320,7 +1320,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
1320
1320
  for (const filePath of modifiedFiles) {
1321
1321
  const sourceFile = project.getSourceFileOrThrow(filePath);
1322
1322
  await sourceFile.save();
1323
- console.log(` Saved: ${import_path8.default.relative(getCwd(), filePath)}`);
1323
+ console.log(` Saved: ${import_path8.default.relative(process.cwd(), filePath)}`);
1324
1324
  }
1325
1325
  console.log(
1326
1326
  `
@@ -1387,7 +1387,7 @@ function processFile9(filePath, project) {
1387
1387
  const sourceFile = project.getSourceFile(filePath);
1388
1388
  if (!sourceFile) return 0;
1389
1389
  let renamedCount = 0;
1390
- const relPath = import_path9.default.relative(getCwd(), filePath);
1390
+ const relPath = import_path9.default.relative(process.cwd(), filePath);
1391
1391
  const candidates = sourceFile.getDescendantsOfKind(
1392
1392
  import_ts_morph9.SyntaxKind.ObjectLiteralExpression
1393
1393
  );
@@ -1402,7 +1402,7 @@ function processFile9(filePath, project) {
1402
1402
  return renamedCount;
1403
1403
  }
1404
1404
  async function main9() {
1405
- const srcDir = import_path9.default.join(getCwd(), "src");
1405
+ const srcDir = import_path9.default.join(process.cwd(), "src");
1406
1406
  console.log(`Scanning for Hapi route configs in: ${srcDir}
1407
1407
  `);
1408
1408
  console.log("Active path renames:");
@@ -1439,7 +1439,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
1439
1439
  for (const filePath of modifiedFiles) {
1440
1440
  const sourceFile = project.getSourceFileOrThrow(filePath);
1441
1441
  await sourceFile.save();
1442
- console.log(` Saved: ${import_path9.default.relative(getCwd(), filePath)}`);
1442
+ console.log(` Saved: ${import_path9.default.relative(process.cwd(), filePath)}`);
1443
1443
  }
1444
1444
  console.log(`
1445
1445
  Done. Renamed ${totalRenamed} route path(s).`);
@@ -1860,8 +1860,8 @@ function ensureJoinImport(sf) {
1860
1860
  });
1861
1861
  }
1862
1862
  async function main10() {
1863
- const srcDir = import_path10.default.join(getCwd(), "src");
1864
- const relCwd = (fp) => import_path10.default.relative(getCwd(), fp);
1863
+ const srcDir = import_path10.default.join(process.cwd(), "src");
1864
+ const relCwd = (fp) => import_path10.default.relative(process.cwd(), fp);
1865
1865
  console.log("Phase 1: Converting JS config files to TypeScript...\n");
1866
1866
  let convertedCount = 0;
1867
1867
  for (const group of CONFIG_GROUPS) {
@@ -1949,7 +1949,7 @@ async function main10() {
1949
1949
  ensureJoinImport(sf);
1950
1950
  }
1951
1951
  console.log(
1952
- ` Inlined applicationConfig.${accessPath.join(".")} \u2192 ${adjustedValue} in ${import_path10.default.relative(getCwd(), sf.getFilePath())}`
1952
+ ` Inlined applicationConfig.${accessPath.join(".")} \u2192 ${adjustedValue} in ${import_path10.default.relative(process.cwd(), sf.getFilePath())}`
1953
1953
  );
1954
1954
  filesToSaveAfterInlining.add(sf);
1955
1955
  madeReplacement = true;
@@ -1961,7 +1961,7 @@ async function main10() {
1961
1961
  for (const sf of Array.from(filesToSaveAfterInlining)) {
1962
1962
  await sf.save();
1963
1963
  console.log(
1964
- ` Saved (inlined): ${import_path10.default.relative(getCwd(), sf.getFilePath())}`
1964
+ ` Saved (inlined): ${import_path10.default.relative(process.cwd(), sf.getFilePath())}`
1965
1965
  );
1966
1966
  }
1967
1967
  for (const prop of [...propsToRemove].reverse()) {
@@ -2578,7 +2578,7 @@ function migrateScopesArrays(rolesFilePath, project) {
2578
2578
  const scopeKey = resolveScopeKeyFromElementAccess(element);
2579
2579
  if (scopeKey && !(scopeKey in SCOPES)) {
2580
2580
  console.warn(
2581
- ` [${import_path11.default.relative(getCwd(), rolesFilePath)}] Removing unknown scope reference: SCOPES.${scopeKey}`
2581
+ ` [${import_path11.default.relative(process.cwd(), rolesFilePath)}] Removing unknown scope reference: SCOPES.${scopeKey}`
2582
2582
  );
2583
2583
  initializer.removeElement(index);
2584
2584
  removedCount++;
@@ -2587,7 +2587,7 @@ function migrateScopesArrays(rolesFilePath, project) {
2587
2587
  const legacyScope = resolveLegacyScopeFromElement(element);
2588
2588
  if (!legacyScope) {
2589
2589
  console.warn(
2590
- ` [${import_path11.default.relative(getCwd(), rolesFilePath)}] Skipping non-literal scope expression: ${element.getText()}`
2590
+ ` [${import_path11.default.relative(process.cwd(), rolesFilePath)}] Skipping non-literal scope expression: ${element.getText()}`
2591
2591
  );
2592
2592
  continue;
2593
2593
  }
@@ -2596,7 +2596,7 @@ function migrateScopesArrays(rolesFilePath, project) {
2596
2596
  const scope = decodeScope(migratedScope);
2597
2597
  if (!scope) {
2598
2598
  console.warn(
2599
- ` [${import_path11.default.relative(getCwd(), rolesFilePath)}] Could not decode migrated scope '${migratedScope}'.`
2599
+ ` [${import_path11.default.relative(process.cwd(), rolesFilePath)}] Could not decode migrated scope '${migratedScope}'.`
2600
2600
  );
2601
2601
  continue;
2602
2602
  }
@@ -2604,14 +2604,14 @@ function migrateScopesArrays(rolesFilePath, project) {
2604
2604
  migratedCount++;
2605
2605
  } catch (error) {
2606
2606
  console.warn(
2607
- ` [${import_path11.default.relative(getCwd(), rolesFilePath)}] Could not migrate scope '${legacyScope}': ${error}`
2607
+ ` [${import_path11.default.relative(process.cwd(), rolesFilePath)}] Could not migrate scope '${legacyScope}': ${error}`
2608
2608
  );
2609
2609
  }
2610
2610
  }
2611
2611
  }
2612
2612
  if (removedCount > 0) {
2613
2613
  console.log(
2614
- ` Removed ${removedCount} unknown SCOPES reference(s) from '${import_path11.default.relative(getCwd(), rolesFilePath)}'.`
2614
+ ` Removed ${removedCount} unknown SCOPES reference(s) from '${import_path11.default.relative(process.cwd(), rolesFilePath)}'.`
2615
2615
  );
2616
2616
  }
2617
2617
  return { migratedCount, removedCount };
@@ -2733,9 +2733,9 @@ function removeRoleTypeDefinitionAndUnusedImports(rolesFilePath, project) {
2733
2733
  return removed;
2734
2734
  }
2735
2735
  async function main11() {
2736
- const cwd2 = getCwd();
2737
- const srcDir = import_path11.default.join(cwd2, "src");
2738
- const rolesFilePath = import_path11.default.join(cwd2, ROLES_FILE_RELATIVE_PATH);
2736
+ const cwd = process.cwd();
2737
+ const srcDir = import_path11.default.join(cwd, "src");
2738
+ const rolesFilePath = import_path11.default.join(cwd, ROLES_FILE_RELATIVE_PATH);
2739
2739
  console.log(`Scanning roles scopes in: ${rolesFilePath}`);
2740
2740
  const project = new import_ts_morph11.Project({
2741
2741
  tsConfigFilePath: import_path11.default.resolve(srcDir, "../tsconfig.json"),
@@ -2799,13 +2799,13 @@ function processFile10(filePath, project) {
2799
2799
  decl.remove();
2800
2800
  }
2801
2801
  console.log(
2802
- ` [${import_path12.default.relative(getCwd(), filePath)}] Removed ${matchingNamedImports.length} deprecated '${DEPRECATED_IMPORT}' import(s) from '${decl.getModuleSpecifierValue()}'`
2802
+ ` [${import_path12.default.relative(process.cwd(), filePath)}] Removed ${matchingNamedImports.length} deprecated '${DEPRECATED_IMPORT}' import(s) from '${decl.getModuleSpecifierValue()}'`
2803
2803
  );
2804
2804
  }
2805
2805
  return removedCount;
2806
2806
  }
2807
2807
  async function main12() {
2808
- const srcDir = import_path12.default.join(getCwd(), "src");
2808
+ const srcDir = import_path12.default.join(process.cwd(), "src");
2809
2809
  console.log(`Scanning for deprecated imports in: ${srcDir}
2810
2810
  `);
2811
2811
  const project = new import_ts_morph12.Project({
@@ -2836,7 +2836,7 @@ async function main12() {
2836
2836
  Saving ${modifiedFiles.length} modified file(s)...`);
2837
2837
  for (const filePath of modifiedFiles) {
2838
2838
  await project.getSourceFileOrThrow(filePath).save();
2839
- console.log(` Saved: ${import_path12.default.relative(getCwd(), filePath)}`);
2839
+ console.log(` Saved: ${import_path12.default.relative(process.cwd(), filePath)}`);
2840
2840
  }
2841
2841
  console.log(`
2842
2842
  Done. Removed ${totalRemoved} deprecated import(s).`);
@@ -2983,7 +2983,7 @@ function processFile11(filePath, project) {
2983
2983
  const sourceFile = project.getSourceFile(filePath);
2984
2984
  if (!sourceFile) return 0;
2985
2985
  let migratedWorkqueues = 0;
2986
- const relPath = import_path13.default.relative(getCwd(), filePath);
2986
+ const relPath = import_path13.default.relative(process.cwd(), filePath);
2987
2987
  const callExpressions = sourceFile.getDescendantsOfKind(
2988
2988
  import_ts_morph13.SyntaxKind.CallExpression
2989
2989
  );
@@ -3004,7 +3004,7 @@ function processFile11(filePath, project) {
3004
3004
  return migratedWorkqueues;
3005
3005
  }
3006
3006
  async function main13() {
3007
- const srcDir = import_path13.default.join(getCwd(), "src");
3007
+ const srcDir = import_path13.default.join(process.cwd(), "src");
3008
3008
  console.log(`Scanning for defineWorkqueues calls in: ${srcDir}
3009
3009
  `);
3010
3010
  const project = new import_ts_morph13.Project({
@@ -3038,7 +3038,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
3038
3038
  for (const filePath of modifiedFiles) {
3039
3039
  const sourceFile = project.getSourceFileOrThrow(filePath);
3040
3040
  await sourceFile.save();
3041
- console.log(` Saved: ${import_path13.default.relative(getCwd(), filePath)}`);
3041
+ console.log(` Saved: ${import_path13.default.relative(process.cwd(), filePath)}`);
3042
3042
  }
3043
3043
  console.log(
3044
3044
  `
@@ -3051,9 +3051,9 @@ var import_path14 = __toESM(require("path"));
3051
3051
  var import_ts_morph14 = require("ts-morph");
3052
3052
  var ROLES_HANDLER_RELATIVE_PATH = "src/data-seeding/roles/handler.ts";
3053
3053
  async function main14() {
3054
- const rolesHandlerPath = import_path14.default.join(getCwd(), ROLES_HANDLER_RELATIVE_PATH);
3054
+ const rolesHandlerPath = import_path14.default.join(process.cwd(), ROLES_HANDLER_RELATIVE_PATH);
3055
3055
  const project = new import_ts_morph14.Project({
3056
- tsConfigFilePath: import_path14.default.resolve(getCwd(), "tsconfig.json"),
3056
+ tsConfigFilePath: import_path14.default.resolve(process.cwd(), "tsconfig.json"),
3057
3057
  skipAddingFilesFromTsConfig: false
3058
3058
  });
3059
3059
  const sourceFile = project.getSourceFile(rolesHandlerPath);
@@ -3116,7 +3116,7 @@ var PATHS_TO_REMOVE = [
3116
3116
  ];
3117
3117
  async function main15() {
3118
3118
  for (const { relativePath, label } of PATHS_TO_REMOVE) {
3119
- const absolutePath = import_path15.default.join(getCwd(), relativePath);
3119
+ const absolutePath = import_path15.default.join(process.cwd(), relativePath);
3120
3120
  if (fs2.existsSync(absolutePath)) {
3121
3121
  fs2.rmSync(absolutePath, { recursive: true, force: true });
3122
3122
  console.log(`Removed ${label} '${relativePath}'.`);
@@ -3272,8 +3272,8 @@ function modifyHandler(sourceFile, exportNames) {
3272
3272
  return changes;
3273
3273
  }
3274
3274
  async function main16() {
3275
- const cwd2 = getCwd();
3276
- const srcDir = import_path16.default.join(cwd2, "src");
3275
+ const cwd = process.cwd();
3276
+ const srcDir = import_path16.default.join(cwd, "src");
3277
3277
  console.log(`Scanning for defineConfig event exports in: ${srcDir}
3278
3278
  `);
3279
3279
  const project = new import_ts_morph15.Project({
@@ -3289,10 +3289,10 @@ async function main16() {
3289
3289
  }
3290
3290
  console.log(`Found ${eventConfigExports.length} event config export(s):`);
3291
3291
  for (const e of eventConfigExports) {
3292
- console.log(` ${e.name} \u2190 ${import_path16.default.relative(cwd2, e.filePath)}`);
3292
+ console.log(` ${e.name} \u2190 ${import_path16.default.relative(cwd, e.filePath)}`);
3293
3293
  }
3294
3294
  const eventsIndexAbs = import_path16.default.join(srcDir, "events", "index.ts");
3295
- const eventsIndexRel = import_path16.default.relative(cwd2, eventsIndexAbs);
3295
+ const eventsIndexRel = import_path16.default.relative(cwd, eventsIndexAbs);
3296
3296
  if (import_fs.default.existsSync(eventsIndexAbs)) {
3297
3297
  console.log(`
3298
3298
  [${eventsIndexRel}] already exists \u2014 leaving untouched.`);
@@ -3318,7 +3318,7 @@ No event-config handler file found (looked for exported function(s): ${Array.fro
3318
3318
  );
3319
3319
  return;
3320
3320
  }
3321
- const handlerRelPath = import_path16.default.relative(cwd2, handler.getFilePath());
3321
+ const handlerRelPath = import_path16.default.relative(cwd, handler.getFilePath());
3322
3322
  const exportNameSet = new Set(eventConfigExports.map((e) => e.name));
3323
3323
  const changes = modifyHandler(handler, exportNameSet);
3324
3324
  if (changes.length === 0) {
@@ -3338,12 +3338,13 @@ var UPSTREAM_URL = "https://github.com/opencrvs/opencrvs-countryconfig.git";
3338
3338
  var UPSTREAM_BRANCH = "develop";
3339
3339
  var TEMP_REMOTE = "opencrvs-upgrade-v19-v20-codemod";
3340
3340
  var FILES_TO_CHECKOUT = [
3341
- "infrastructure/postgres/setup-analytics.sh",
3342
- "src/analytics/analytics.ts"
3341
+ "src/analytics/analytics.ts",
3342
+ "Dockerfile",
3343
+ "Dockerfile.assets"
3343
3344
  ];
3344
3345
  function runGit(args2, { silent = false } = {}) {
3345
3346
  return (0, import_child_process.execFileSync)("git", args2, {
3346
- cwd: getCwd(),
3347
+ cwd: process.cwd(),
3347
3348
  encoding: "utf8",
3348
3349
  stdio: silent ? ["ignore", "pipe", "pipe"] : ["ignore", "pipe", "inherit"]
3349
3350
  });
@@ -3359,7 +3360,7 @@ function tryGit(args2) {
3359
3360
  function assertIsGitRepo() {
3360
3361
  if (!tryGit(["rev-parse", "--is-inside-work-tree"])) {
3361
3362
  throw new Error(
3362
- `checkout-upstream-files: ${getCwd()} is not a git repository. Initialise git (or run the upgrade inside a git checkout) before re-running.`
3363
+ `${process.cwd()} is not a git repository. Initialise git (or run the upgrade inside a git checkout) before re-running.`
3363
3364
  );
3364
3365
  }
3365
3366
  }
@@ -3483,8 +3484,8 @@ function simplifyPrecalculateFunction(sourceFile) {
3483
3484
  return log;
3484
3485
  }
3485
3486
  async function main18() {
3486
- const cwd2 = getCwd();
3487
- const absPath = import_path17.default.join(cwd2, ANALYTICS_FILE_REL);
3487
+ const cwd = process.cwd();
3488
+ const absPath = import_path17.default.join(cwd, ANALYTICS_FILE_REL);
3488
3489
  if (!import_fs2.default.existsSync(absPath)) {
3489
3490
  console.log(
3490
3491
  `[${ANALYTICS_FILE_REL}] does not exist \u2014 nothing to clean up.`
@@ -3492,7 +3493,7 @@ async function main18() {
3492
3493
  return;
3493
3494
  }
3494
3495
  const project = new import_ts_morph16.Project({
3495
- tsConfigFilePath: import_path17.default.resolve(cwd2, "tsconfig.json"),
3496
+ tsConfigFilePath: import_path17.default.resolve(cwd, "tsconfig.json"),
3496
3497
  skipAddingFilesFromTsConfig: false
3497
3498
  });
3498
3499
  const sourceFile = project.getSourceFile(absPath);
@@ -3519,25 +3520,157 @@ async function main18() {
3519
3520
  Saved ${ANALYTICS_FILE_REL}.`);
3520
3521
  }
3521
3522
 
3522
- // src/migrations/v2.0/index.ts
3523
- var cwd;
3524
- function getCwd() {
3525
- if (!cwd) {
3526
- throw new Error("Country config working directory not set.");
3523
+ // src/migrations/v2.0/merge-infrastructure-directory.ts
3524
+ var import_child_process2 = require("child_process");
3525
+ var import_fs3 = require("fs");
3526
+ var import_os = require("os");
3527
+ var import_path18 = require("path");
3528
+ var TEMP_REMOTE2 = "opencrvs-upgrade-v19-v20-codemod-merge-infra";
3529
+ var INFRASTRUCTURE_DIR = "infrastructure";
3530
+ var BASE_BRANCH = "release-v1.9";
3531
+ function gitShowBytes(ref, path17) {
3532
+ try {
3533
+ const buf = (0, import_child_process2.execFileSync)("git", ["show", `${ref}:${path17}`], {
3534
+ cwd: process.cwd(),
3535
+ stdio: ["ignore", "pipe", "pipe"]
3536
+ });
3537
+ return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
3538
+ } catch {
3539
+ return null;
3527
3540
  }
3528
- return cwd;
3529
3541
  }
3530
- async function runUpgrade(ccwd) {
3531
- if (ccwd) {
3532
- console.log("Country config working directory:", ccwd);
3533
- cwd = ccwd;
3542
+ async function main19() {
3543
+ console.log(
3544
+ `Merging '${INFRASTRUCTURE_DIR}/' from ${UPSTREAM_URL}@${UPSTREAM_BRANCH} (base: ${BASE_BRANCH})...
3545
+ `
3546
+ );
3547
+ assertIsGitRepo();
3548
+ tryGit(["remote", "remove", TEMP_REMOTE2]);
3549
+ try {
3550
+ console.log(` Adding temporary remote '${TEMP_REMOTE2}' \u2192 ${UPSTREAM_URL}`);
3551
+ runGit(["remote", "add", TEMP_REMOTE2, UPSTREAM_URL], { silent: true });
3552
+ console.log(
3553
+ ` Fetching ${TEMP_REMOTE2}/{${UPSTREAM_BRANCH},${BASE_BRANCH}} (depth 1)...`
3554
+ );
3555
+ runGit(["fetch", "--depth=1", TEMP_REMOTE2, UPSTREAM_BRANCH, BASE_BRANCH]);
3556
+ const ref = `${TEMP_REMOTE2}/${UPSTREAM_BRANCH}`;
3557
+ const baseRef = `${TEMP_REMOTE2}/${BASE_BRANCH}`;
3558
+ const upstreamFiles = runGit(
3559
+ [
3560
+ "ls-tree",
3561
+ "-r",
3562
+ "--name-only",
3563
+ "-z",
3564
+ ref,
3565
+ "--",
3566
+ `${INFRASTRUCTURE_DIR}/`
3567
+ ],
3568
+ { silent: true }
3569
+ ).split("\0").filter(Boolean);
3570
+ if (upstreamFiles.length === 0) {
3571
+ console.log(
3572
+ ` No files found under '${INFRASTRUCTURE_DIR}/' on ${ref}. Nothing to merge.`
3573
+ );
3574
+ return;
3575
+ }
3576
+ const tmpDir = (0, import_fs3.mkdtempSync)((0, import_path18.join)((0, import_os.tmpdir)(), "opencrvs-merge-infra-"));
3577
+ const baseTmp = (0, import_path18.join)(tmpDir, "base");
3578
+ const theirsTmp = (0, import_path18.join)(tmpDir, "theirs");
3579
+ let added = 0;
3580
+ let merged = 0;
3581
+ const conflictedFiles = [];
3582
+ for (const file of upstreamFiles) {
3583
+ const fullPath = (0, import_path18.join)(process.cwd(), file);
3584
+ if (!(0, import_fs3.existsSync)(fullPath)) {
3585
+ if (tryGit(["checkout", ref, "--", file])) {
3586
+ console.log(` + ${file} (new from upstream)`);
3587
+ added++;
3588
+ } else {
3589
+ console.warn(` [warn] failed to add new file ${file}`);
3590
+ }
3591
+ continue;
3592
+ }
3593
+ const theirContents = gitShowBytes(ref, file);
3594
+ if (theirContents === null) {
3595
+ console.warn(` [warn] could not read ${file} from ${ref} \u2014 skipping.`);
3596
+ continue;
3597
+ }
3598
+ (0, import_fs3.writeFileSync)(theirsTmp, theirContents);
3599
+ const baseContents = gitShowBytes(baseRef, file);
3600
+ (0, import_fs3.writeFileSync)(baseTmp, baseContents ?? new Uint8Array(0));
3601
+ try {
3602
+ (0, import_child_process2.execFileSync)("git", ["merge-file", fullPath, baseTmp, theirsTmp], {
3603
+ cwd: process.cwd(),
3604
+ stdio: ["ignore", "pipe", "pipe"]
3605
+ });
3606
+ runGit(["add", "--", file], { silent: true });
3607
+ merged++;
3608
+ } catch (err) {
3609
+ const status = err.status;
3610
+ if (typeof status === "number" && status > 0) {
3611
+ conflictedFiles.push(file);
3612
+ console.warn(
3613
+ ` ! ${file} (${status} conflict${status > 1 ? "s" : ""})`
3614
+ );
3615
+ } else {
3616
+ conflictedFiles.push(file);
3617
+ console.warn(
3618
+ ` [warn] merge failed for ${file} (likely binary or unreadable) \u2014 left untouched.`
3619
+ );
3620
+ }
3621
+ }
3622
+ }
3623
+ console.log(
3624
+ `
3625
+ Done. ${added} added, ${merged} merged cleanly, ${conflictedFiles.length} with conflicts.`
3626
+ );
3627
+ if (conflictedFiles.length > 0) {
3628
+ console.warn(
3629
+ `
3630
+ NOTE: ${conflictedFiles.length} file(s) under '${INFRASTRUCTURE_DIR}/' have merge conflicts that you must resolve manually.
3631
+ Look for the standard conflict markers (<<<<<<<, =======, >>>>>>>) in:
3632
+ ` + conflictedFiles.map((f) => ` - ${f}`).join("\n") + `
3633
+ After resolving, stage the fixes with: git add ${INFRASTRUCTURE_DIR}/`
3634
+ );
3635
+ }
3636
+ } finally {
3637
+ if (tryGit(["remote", "remove", TEMP_REMOTE2])) {
3638
+ console.log(` Removed temporary remote '${TEMP_REMOTE2}'.`);
3639
+ }
3534
3640
  }
3535
- if (!ccwd) {
3641
+ }
3642
+
3643
+ // src/migrations/v2.0/delete-infrastructure-directory.ts
3644
+ var import_fs4 = require("fs");
3645
+ var import_path19 = require("path");
3646
+ var INFRASTRUCTURE_DIR2 = "infrastructure";
3647
+ async function main20() {
3648
+ const fullPath = (0, import_path19.join)(process.cwd(), INFRASTRUCTURE_DIR2);
3649
+ if (!(0, import_fs4.existsSync)(fullPath)) {
3536
3650
  console.log(
3537
- "Will use current working directory as country config working directory."
3651
+ `'${INFRASTRUCTURE_DIR2}/' not found in ${process.cwd()} \u2014 nothing to delete.`
3538
3652
  );
3539
- cwd = process.cwd();
3653
+ return;
3540
3654
  }
3655
+ console.log(`Deleting '${INFRASTRUCTURE_DIR2}/'...
3656
+ `);
3657
+ assertIsGitRepo();
3658
+ runGit(["rm", "-rf", "--ignore-unmatch", "--", `${INFRASTRUCTURE_DIR2}/`], {
3659
+ silent: true
3660
+ });
3661
+ console.log(` Staged deletion of tracked files under '${INFRASTRUCTURE_DIR2}/'.`);
3662
+ if ((0, import_fs4.existsSync)(fullPath)) {
3663
+ (0, import_fs4.rmSync)(fullPath, { recursive: true, force: true });
3664
+ console.log(` Removed remaining untracked files under '${INFRASTRUCTURE_DIR2}/'.`);
3665
+ }
3666
+ console.log(
3667
+ `
3668
+ Done. Review the staged deletion with: git diff --cached -- '${INFRASTRUCTURE_DIR2}/'`
3669
+ );
3670
+ }
3671
+
3672
+ // src/migrations/v2.0/index.ts
3673
+ async function runUpgrade(dockerSwarm) {
3541
3674
  await main13();
3542
3675
  await main();
3543
3676
  await main2();
@@ -3556,6 +3689,11 @@ async function runUpgrade(ccwd) {
3556
3689
  await main16();
3557
3690
  await main17();
3558
3691
  await main18();
3692
+ if (dockerSwarm) {
3693
+ await main19();
3694
+ } else {
3695
+ await main20();
3696
+ }
3559
3697
  }
3560
3698
 
3561
3699
  // src/cli.ts
@@ -3570,7 +3708,20 @@ Commands:
3570
3708
 
3571
3709
  Run 'opencrvs <command> --help' for more information on a command.
3572
3710
  `.trim();
3573
- function main19() {
3711
+ var UPGRADE_USAGE = `
3712
+ Usage: opencrvs upgrade [options]
3713
+
3714
+ Upgrade the country config in the current working directory to the next
3715
+ major version of OpenCRVS.
3716
+
3717
+ Options:
3718
+ --docker-swarm Keep and merge the 'infrastructure/' directory with
3719
+ upstream changes. Use this if your country deploys
3720
+ OpenCRVS via Docker Swarm. When omitted, the
3721
+ 'infrastructure/' directory is deleted (default).
3722
+ -h, --help Show this message.
3723
+ `.trim();
3724
+ function main21() {
3574
3725
  const command = args[0];
3575
3726
  if (!command || command === "--help" || command === "-h") {
3576
3727
  console.log(USAGE);
@@ -3615,10 +3766,25 @@ Subcommands:
3615
3766
  }
3616
3767
  }
3617
3768
  async function handleUpgrade() {
3769
+ const upgradeArgs = args.slice(1);
3770
+ if (upgradeArgs.includes("--help") || upgradeArgs.includes("-h")) {
3771
+ console.log(UPGRADE_USAGE);
3772
+ process.exit(0);
3773
+ }
3774
+ const KNOWN_FLAGS = /* @__PURE__ */ new Set(["--docker-swarm"]);
3775
+ const unknownFlags = upgradeArgs.filter(
3776
+ (arg) => arg.startsWith("-") && !KNOWN_FLAGS.has(arg)
3777
+ );
3778
+ if (unknownFlags.length > 0) {
3779
+ console.error(`Unknown option(s): ${unknownFlags.join(", ")}
3780
+ `);
3781
+ console.log(UPGRADE_USAGE);
3782
+ process.exit(1);
3783
+ }
3784
+ const dockerSwarm = upgradeArgs.includes("--docker-swarm");
3618
3785
  console.log("Initiating upgrade...");
3619
3786
  try {
3620
- const pathToCountryconfig = args[1];
3621
- await runUpgrade(pathToCountryconfig);
3787
+ await runUpgrade(dockerSwarm);
3622
3788
  console.log("Upgrade completed successfully!");
3623
3789
  } catch (error) {
3624
3790
  console.error("Upgrade failed:", error);
@@ -3630,4 +3796,4 @@ function handleCheckTranslations() {
3630
3796
  console.warn("This command is not implemented yet!");
3631
3797
  process.exit(1);
3632
3798
  }
3633
- main19();
3799
+ main21();