@opencrvs/toolkit 1.9.12-rc.a9b25f0 → 1.9.12-rc.ab196db

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 (79) hide show
  1. package/dist/application-config/index.js +1 -1
  2. package/dist/cli.js +1890 -278
  3. package/dist/commons/api/router.d.ts +175 -163
  4. package/dist/commons/events/AuditLog.d.ts +2 -0
  5. package/dist/commons/events/EventConfig.d.ts +3 -1
  6. package/dist/commons/events/FieldConfig.d.ts +2 -2
  7. package/dist/commons/notification/UserNotifications.d.ts +15 -0
  8. package/dist/events/index.js +17 -3
  9. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts.map +1 -1
  10. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.js +3 -4
  11. package/dist/migrations/v2.0/add-resend-invite-notification.d.ts +3 -0
  12. package/dist/migrations/v2.0/add-resend-invite-notification.d.ts.map +1 -0
  13. package/dist/migrations/v2.0/add-resend-invite-notification.js +356 -0
  14. package/dist/migrations/v2.0/checkout-upstream-files.d.ts +22 -0
  15. package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +1 -0
  16. package/dist/migrations/v2.0/checkout-upstream-files.js +147 -0
  17. package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts.map +1 -1
  18. package/dist/migrations/v2.0/convert-config-files-to-ts.js +4 -5
  19. package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts.map +1 -1
  20. package/dist/migrations/v2.0/convert-paragraph-to-heading.js +4 -5
  21. package/dist/migrations/v2.0/create-events-index.d.ts +3 -0
  22. package/dist/migrations/v2.0/create-events-index.d.ts.map +1 -0
  23. package/dist/migrations/v2.0/create-events-index.js +325 -0
  24. package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts +3 -0
  25. package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts.map +1 -0
  26. package/dist/migrations/v2.0/delete-infrastructure-directory.js +77 -0
  27. package/dist/migrations/v2.0/index.d.ts +8 -4
  28. package/dist/migrations/v2.0/index.d.ts.map +1 -1
  29. package/dist/migrations/v2.0/index.js +1860 -277
  30. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts.map +1 -1
  31. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.js +5 -6
  32. package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts +3 -0
  33. package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts.map +1 -0
  34. package/dist/migrations/v2.0/merge-infrastructure-directory.js +221 -0
  35. package/dist/migrations/v2.0/migrate-application-config-url.d.ts +3 -0
  36. package/dist/migrations/v2.0/migrate-application-config-url.d.ts.map +1 -0
  37. package/dist/migrations/v2.0/migrate-application-config-url.js +342 -0
  38. package/dist/migrations/v2.0/migrate-scopes.d.ts.map +1 -1
  39. package/dist/migrations/v2.0/migrate-scopes.js +6 -7
  40. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts.map +1 -1
  41. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.js +3 -4
  42. package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts.map +1 -1
  43. package/dist/migrations/v2.0/migrate-workqueue-configs.js +3 -4
  44. package/dist/migrations/v2.0/remove-delete-actions.d.ts.map +1 -1
  45. package/dist/migrations/v2.0/remove-delete-actions.js +3 -4
  46. package/dist/migrations/v2.0/remove-demo-scope.d.ts.map +1 -1
  47. package/dist/migrations/v2.0/remove-demo-scope.js +2 -3
  48. package/dist/migrations/v2.0/remove-deprecated-imports.d.ts.map +1 -1
  49. package/dist/migrations/v2.0/remove-deprecated-imports.js +3 -4
  50. package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts +3 -0
  51. package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts.map +1 -0
  52. package/dist/migrations/v2.0/remove-fhir-url-helpers.js +163 -0
  53. package/dist/migrations/v2.0/remove-hearth-migrations.d.ts.map +1 -1
  54. package/dist/migrations/v2.0/remove-hearth-migrations.js +1 -2
  55. package/dist/migrations/v2.0/remove-old-statistics-service.d.ts +3 -0
  56. package/dist/migrations/v2.0/remove-old-statistics-service.d.ts.map +1 -0
  57. package/dist/migrations/v2.0/remove-old-statistics-service.js +356 -0
  58. package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts.map +1 -1
  59. package/dist/migrations/v2.0/remove-pending-certification-flag.js +3 -4
  60. package/dist/migrations/v2.0/remove-review-from-register-action.d.ts.map +1 -1
  61. package/dist/migrations/v2.0/remove-review-from-register-action.js +3 -4
  62. package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts +3 -0
  63. package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts.map +1 -0
  64. package/dist/migrations/v2.0/remove-unused-environment-variables.js +186 -0
  65. package/dist/migrations/v2.0/rename-api-paths.d.ts.map +1 -1
  66. package/dist/migrations/v2.0/rename-api-paths.js +3 -4
  67. package/dist/migrations/v2.0/rename-location-parent-id.d.ts.map +1 -1
  68. package/dist/migrations/v2.0/rename-location-parent-id.js +3 -4
  69. package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts +3 -0
  70. package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts.map +1 -0
  71. package/dist/migrations/v2.0/simplify-analytics-precalculations.js +195 -0
  72. package/dist/migrations/v2.0/update-package-json.d.ts +3 -0
  73. package/dist/migrations/v2.0/update-package-json.d.ts.map +1 -0
  74. package/dist/migrations/v2.0/update-package-json.js +105 -0
  75. package/dist/notification/index.js +10 -1
  76. package/opencrvs-toolkit-1.9.12-rc.ab196db.tgz +0 -0
  77. package/package.json +1 -1
  78. package/tsconfig.tsbuildinfo +1 -1
  79. package/opencrvs-toolkit-1.9.12-rc.a9b25f0.tgz +0 -0
@@ -0,0 +1,147 @@
1
+ "use strict";
2
+ /*
3
+ * This Source Code Form is subject to the terms of the Mozilla Public
4
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/.
6
+ *
7
+ * OpenCRVS is also distributed under the terms of the Civil Registration
8
+ * & Healthcare Disclaimer located at http://opencrvs.org/license.
9
+ *
10
+ * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
11
+ */
12
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
+ return new (P || (P = Promise))(function (resolve, reject) {
15
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
19
+ });
20
+ };
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.UPSTREAM_BRANCH = exports.UPSTREAM_URL = void 0;
23
+ exports.runGit = runGit;
24
+ exports.tryGit = tryGit;
25
+ exports.assertIsGitRepo = assertIsGitRepo;
26
+ exports.main = main;
27
+ /**
28
+ * Codemod: Replace selected files with their upstream v2.0 versions from
29
+ * opencrvs/opencrvs-countryconfig.
30
+ *
31
+ * Usage:
32
+ * ts-node -r tsconfig-paths/register src/migrations/v2.0/checkout-upstream-files.ts
33
+ *
34
+ * What it does:
35
+ * 1. Registers a temporary git remote that points at the canonical
36
+ * opencrvs-countryconfig repository.
37
+ * 2. Fetches the chosen upstream branch at --depth=1 to keep it fast.
38
+ * 3. Path-scoped checkouts each listed file from that branch. The upstream
39
+ * version is written to the working tree AND staged in the index, so
40
+ * the dev can review the diff afterwards with:
41
+ * git diff --cached -- <file>
42
+ * 4. Removes the temporary remote in all cases (success, failure, or
43
+ * unexpected error) via a `finally` block.
44
+ *
45
+ * Why a git-based approach (as opposed to a raw HTTPS download):
46
+ * - Git handles text, binary, and line endings correctly.
47
+ * - The checked-out files end up staged, giving an obvious review UX.
48
+ * - `git checkout <ref> -- <paths>` is a blob-level copy, so it works
49
+ * whether or not the target repo shares history with
50
+ * opencrvs-countryconfig (e.g. country implementations started from
51
+ * scratch rather than forked).
52
+ *
53
+ * Caveats:
54
+ * - Overwrites any local modifications to the listed files. Run the
55
+ * upgrade on a clean working tree, or accept that the upstream version
56
+ * replaces yours.
57
+ * - Requires git to be installed and network access to github.com.
58
+ * - Requires the country config working directory to be a git repo.
59
+ */
60
+ const child_process_1 = require("child_process");
61
+ exports.UPSTREAM_URL = 'https://github.com/opencrvs/opencrvs-countryconfig.git';
62
+ // @TODO: This needs to be changed to 'release-v2.0.0' once the branch is created
63
+ exports.UPSTREAM_BRANCH = 'develop';
64
+ // Remote name used only for the duration of this codemod. Prefixed to avoid
65
+ // clashing with remotes the user may have (origin, upstream, etc.).
66
+ const TEMP_REMOTE = 'opencrvs-upgrade-v19-v20-codemod';
67
+ const FILES_TO_CHECKOUT = [
68
+ 'src/analytics/analytics.ts',
69
+ 'Dockerfile',
70
+ 'Dockerfile.assets'
71
+ ];
72
+ // ─── Git helpers ─────────────────────────────────────────────────────────────
73
+ /**
74
+ * Runs a git command in the country config working directory.
75
+ *
76
+ * By default stderr is inherited so the user sees progress output from
77
+ * long-running commands (e.g. `git fetch`). Pass `silent: true` to suppress
78
+ * both stdout and stderr when you only care about the exit code.
79
+ */
80
+ function runGit(args, { silent = false } = {}) {
81
+ return (0, child_process_1.execFileSync)('git', args, {
82
+ cwd: process.cwd(),
83
+ encoding: 'utf8',
84
+ stdio: silent ? ['ignore', 'pipe', 'pipe'] : ['ignore', 'pipe', 'inherit']
85
+ });
86
+ }
87
+ /**
88
+ * Runs a git command and returns true on success, false on failure.
89
+ * Stderr/stdout are suppressed — use only when the exit code is the only
90
+ * signal you care about.
91
+ */
92
+ function tryGit(args) {
93
+ try {
94
+ runGit(args, { silent: true });
95
+ return true;
96
+ }
97
+ catch (_a) {
98
+ return false;
99
+ }
100
+ }
101
+ function assertIsGitRepo() {
102
+ if (!tryGit(['rev-parse', '--is-inside-work-tree'])) {
103
+ throw new Error(`${process.cwd()} is not a git repository. Initialise git (or run the upgrade inside a git checkout) before re-running.`);
104
+ }
105
+ }
106
+ // ─── Entry point ─────────────────────────────────────────────────────────────
107
+ function main() {
108
+ return __awaiter(this, void 0, void 0, function* () {
109
+ console.log(`Checking out ${FILES_TO_CHECKOUT.length} file(s) from ${exports.UPSTREAM_URL}@${exports.UPSTREAM_BRANCH}...\n`);
110
+ assertIsGitRepo();
111
+ // Best-effort cleanup of a stale temp remote from a previous aborted run.
112
+ tryGit(['remote', 'remove', TEMP_REMOTE]);
113
+ try {
114
+ console.log(` Adding temporary remote '${TEMP_REMOTE}' → ${exports.UPSTREAM_URL}`);
115
+ runGit(['remote', 'add', TEMP_REMOTE, exports.UPSTREAM_URL], { silent: true });
116
+ console.log(` Fetching ${TEMP_REMOTE}/${exports.UPSTREAM_BRANCH} (depth 1)...`);
117
+ runGit(['fetch', '--depth=1', TEMP_REMOTE, exports.UPSTREAM_BRANCH]);
118
+ const ref = `${TEMP_REMOTE}/${exports.UPSTREAM_BRANCH}`;
119
+ const missing = [];
120
+ let checkedOut = 0;
121
+ for (const file of FILES_TO_CHECKOUT) {
122
+ // `--` separates paths from refs and avoids ambiguity when a path
123
+ // happens to match a branch/tag name.
124
+ if (tryGit(['checkout', ref, '--', file])) {
125
+ console.log(` Checked out ${file} from ${ref}`);
126
+ checkedOut++;
127
+ }
128
+ else {
129
+ console.warn(` [warn] ${file} not found on ${ref} — skipping. Verify the path exists on that branch.`);
130
+ missing.push(file);
131
+ }
132
+ }
133
+ console.log(`\n Checked out ${checkedOut}/${FILES_TO_CHECKOUT.length} file(s) from ${ref}.`);
134
+ if (missing.length > 0) {
135
+ console.warn(` Missing on upstream branch: ${missing.join(', ')}`);
136
+ }
137
+ if (checkedOut > 0) {
138
+ console.log(` Review the staged changes with: git diff --cached -- ${FILES_TO_CHECKOUT.map((f) => `'${f}'`).join(' ')}\n`);
139
+ }
140
+ }
141
+ finally {
142
+ if (tryGit(['remote', 'remove', TEMP_REMOTE])) {
143
+ console.log(` Removed temporary remote '${TEMP_REMOTE}'.`);
144
+ }
145
+ }
146
+ });
147
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"convert-config-files-to-ts.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/convert-config-files-to-ts.ts"],"names":[],"mappings":"AAyuBA,wBAAsB,IAAI,kBAyPzB"}
1
+ {"version":3,"file":"convert-config-files-to-ts.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/convert-config-files-to-ts.ts"],"names":[],"mappings":"AAuuBA,wBAAsB,IAAI,kBAyPzB"}
@@ -87,7 +87,6 @@ exports.main = main;
87
87
  const fs = __importStar(require("fs"));
88
88
  const ts_morph_1 = require("ts-morph");
89
89
  const path_1 = __importDefault(require("path"));
90
- const _1 = require(".");
91
90
  // ─── Schema-valid keys per config type ───────────────────────────────────────
92
91
  const CLIENT_VALID_KEYS = new Set([
93
92
  'COUNTRY',
@@ -634,8 +633,8 @@ function ensureJoinImport(sf) {
634
633
  function main() {
635
634
  return __awaiter(this, void 0, void 0, function* () {
636
635
  var _a;
637
- const srcDir = path_1.default.join((0, _1.getCwd)(), 'src');
638
- const relCwd = (fp) => path_1.default.relative((0, _1.getCwd)(), fp);
636
+ const srcDir = path_1.default.join(process.cwd(), 'src');
637
+ const relCwd = (fp) => path_1.default.relative(process.cwd(), fp);
639
638
  // ── Phase 1: Convert JS config files to TypeScript ────────────────────────
640
639
  console.log('Phase 1: Converting JS config files to TypeScript...\n');
641
640
  let convertedCount = 0;
@@ -741,7 +740,7 @@ function main() {
741
740
  if (/\bjoin\s*\(/.test(adjustedValue)) {
742
741
  ensureJoinImport(sf);
743
742
  }
744
- console.log(` Inlined applicationConfig.${accessPath.join('.')} → ${adjustedValue} in ${path_1.default.relative((0, _1.getCwd)(), sf.getFilePath())}`);
743
+ console.log(` Inlined applicationConfig.${accessPath.join('.')} → ${adjustedValue} in ${path_1.default.relative(process.cwd(), sf.getFilePath())}`);
745
744
  filesToSaveAfterInlining.add(sf);
746
745
  madeReplacement = true;
747
746
  break; // restart — tree has changed
@@ -752,7 +751,7 @@ function main() {
752
751
  // Persist files that received inline replacements
753
752
  for (const sf of Array.from(filesToSaveAfterInlining)) {
754
753
  yield sf.save();
755
- console.log(` Saved (inlined): ${path_1.default.relative((0, _1.getCwd)(), sf.getFilePath())}`);
754
+ console.log(` Saved (inlined): ${path_1.default.relative(process.cwd(), sf.getFilePath())}`);
756
755
  }
757
756
  // Remove in reverse order to avoid index shifting
758
757
  for (const prop of [...propsToRemove].reverse()) {
@@ -1 +1 @@
1
- {"version":3,"file":"convert-paragraph-to-heading.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/convert-paragraph-to-heading.ts"],"names":[],"mappings":"AAwJA,iBAAe,IAAI,kBA6ClB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
1
+ {"version":3,"file":"convert-paragraph-to-heading.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/convert-paragraph-to-heading.ts"],"names":[],"mappings":"AAsJA,iBAAe,IAAI,kBA6ClB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
@@ -42,7 +42,6 @@ exports.main = main;
42
42
  */
43
43
  const ts_morph_1 = require("ts-morph");
44
44
  const path_1 = __importDefault(require("path"));
45
- const _1 = require(".");
46
45
  const FIELD_TYPE_ENUM_NAME = 'FieldType';
47
46
  const PARAGRAPH_MEMBER_NAME = 'PARAGRAPH';
48
47
  const HEADING_MEMBER_NAME = 'HEADING';
@@ -112,18 +111,18 @@ function processFile(filePath, project) {
112
111
  const result = transformParagraphField(obj);
113
112
  if (result === 'converted-to-heading') {
114
113
  changedCount++;
115
- console.log(` [${path_1.default.relative((0, _1.getCwd)(), filePath)}] Converted PARAGRAPH with heading fontVariant to HEADING`);
114
+ console.log(` [${path_1.default.relative(process.cwd(), filePath)}] Converted PARAGRAPH with heading fontVariant to HEADING`);
116
115
  }
117
116
  else if (result === 'removed-font-variant') {
118
117
  changedCount++;
119
- console.log(` [${path_1.default.relative((0, _1.getCwd)(), filePath)}] Removed non-heading fontVariant from PARAGRAPH`);
118
+ console.log(` [${path_1.default.relative(process.cwd(), filePath)}] Removed non-heading fontVariant from PARAGRAPH`);
120
119
  }
121
120
  }
122
121
  return changedCount;
123
122
  }
124
123
  function main() {
125
124
  return __awaiter(this, void 0, void 0, function* () {
126
- const srcDir = path_1.default.join((0, _1.getCwd)(), 'src');
125
+ const srcDir = path_1.default.join(process.cwd(), 'src');
127
126
  console.log(`Scanning for FieldType.PARAGRAPH fields in: ${srcDir}\n`);
128
127
  const project = new ts_morph_1.Project({
129
128
  tsConfigFilePath: path_1.default.resolve(srcDir, '../tsconfig.json'),
@@ -152,7 +151,7 @@ function main() {
152
151
  for (const filePath of modifiedFiles) {
153
152
  const sourceFile = project.getSourceFileOrThrow(filePath);
154
153
  yield sourceFile.save();
155
- console.log(` Saved: ${path_1.default.relative((0, _1.getCwd)(), filePath)}`);
154
+ console.log(` Saved: ${path_1.default.relative(process.cwd(), filePath)}`);
156
155
  }
157
156
  console.log(`\nDone. Processed ${totalChanged} FieldType.PARAGRAPH field(s).`);
158
157
  });
@@ -0,0 +1,3 @@
1
+ declare function main(): Promise<void>;
2
+ export { main };
3
+ //# sourceMappingURL=create-events-index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-events-index.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/create-events-index.ts"],"names":[],"mappings":"AAmTA,iBAAe,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAmEnC;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
@@ -0,0 +1,325 @@
1
+ "use strict";
2
+ /*
3
+ * This Source Code Form is subject to the terms of the Mozilla Public
4
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/.
6
+ *
7
+ * OpenCRVS is also distributed under the terms of the Civil Registration
8
+ * & Healthcare Disclaimer located at http://opencrvs.org/license.
9
+ *
10
+ * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
11
+ */
12
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
+ return new (P || (P = Promise))(function (resolve, reject) {
15
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
19
+ });
20
+ };
21
+ var __importDefault = (this && this.__importDefault) || function (mod) {
22
+ return (mod && mod.__esModule) ? mod : { "default": mod };
23
+ };
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.main = main;
26
+ /**
27
+ * Codemod: Create `src/events/index.ts` that collects every `defineConfig`
28
+ * event export, and rewire the event-config handler to import from it.
29
+ *
30
+ * Usage:
31
+ * ts-node -r tsconfig-paths/register src/migrations/v2.0/create-events-index.ts
32
+ *
33
+ * Context:
34
+ * No codemod currently *moves* event-config source files into `src/events/`.
35
+ * Event configs therefore still live wherever the country defined them
36
+ * (typically `src/form/...`). This codemod works regardless of their
37
+ * location by discovering every `export const X = defineConfig(...)`
38
+ * declaration in `src/`.
39
+ *
40
+ * What it does:
41
+ * 1. Scans `src/` for every top-level `export const X = defineConfig(...)`
42
+ * declaration and records `{ name, filePath }` pairs.
43
+ * 2. Creates `src/events/index.ts` (if it does not already exist) that
44
+ * imports each event config from its actual file location using a
45
+ * relative path from `src/events/`, and exports:
46
+ * export const eventConfigs = [<name1>, <name2>, ...]
47
+ * 3. Locates the event-config Hapi handler file (a file whose top level
48
+ * declares a function named `getCustomEventsHandler` or
49
+ * `getEventsHandler`) and:
50
+ * - Removes direct named imports of the event configs it no longer
51
+ * needs, cleaning up the import declaration if it becomes empty.
52
+ * - Removes any previously-inlined `export const eventConfigs = [...]`
53
+ * at the top level (in case an earlier codemod version hoisted one).
54
+ * - Adds `import { eventConfigs } from '@countryconfig/events'`
55
+ * (merging into an existing import of the same module if present).
56
+ * - Rewrites `h.response([<identifiers>]).code(...)` inside the
57
+ * handler to `h.response(eventConfigs).code(...)`.
58
+ * 4. Saves the modified files.
59
+ *
60
+ * The codemod is safe to re-run: if `src/events/index.ts` already exists it
61
+ * is left untouched, and handler modifications are idempotent.
62
+ */
63
+ const ts_morph_1 = require("ts-morph");
64
+ const fs_1 = __importDefault(require("fs"));
65
+ const path_1 = __importDefault(require("path"));
66
+ const DEFINE_CONFIG_NAME = 'defineConfig';
67
+ const HANDLER_FUNCTION_NAMES = new Set([
68
+ 'getCustomEventsHandler',
69
+ 'getEventsHandler'
70
+ ]);
71
+ const EVENT_CONFIGS_IDENTIFIER = 'eventConfigs';
72
+ const EVENTS_INDEX_IMPORT_PATH = '@countryconfig/events';
73
+ const RESPONSE_METHOD_NAME = 'response';
74
+ const LICENSE_HEADER = `/*
75
+ * This Source Code Form is subject to the terms of the Mozilla Public
76
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
77
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/.
78
+ *
79
+ * OpenCRVS is also distributed under the terms of the Civil Registration
80
+ * & Healthcare Disclaimer located at http://opencrvs.org/license.
81
+ *
82
+ * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
83
+ */
84
+ `;
85
+ // ─── Discovery ───────────────────────────────────────────────────────────────
86
+ /**
87
+ * Returns every top-level `export const X = defineConfig(...)` declaration in
88
+ * files under `srcDir`. A declaration may wrap the call in a type assertion
89
+ * (`... as EventConfig`) — this is unwrapped before matching.
90
+ *
91
+ * An existing `src/events/index.ts` is excluded so re-runs don't pick up its
92
+ * re-exports as source definitions.
93
+ */
94
+ function findEventConfigExports(project, srcDir) {
95
+ const found = [];
96
+ const eventsIndexAbs = path_1.default.join(srcDir, 'events', 'index.ts');
97
+ for (const sourceFile of project.getSourceFiles()) {
98
+ const filePath = sourceFile.getFilePath();
99
+ if (!filePath.startsWith(srcDir) || filePath.includes('/node_modules/')) {
100
+ continue;
101
+ }
102
+ if (filePath === eventsIndexAbs)
103
+ continue;
104
+ for (const statement of sourceFile.getVariableStatements()) {
105
+ if (!statement.hasExportKeyword())
106
+ continue;
107
+ for (const decl of statement.getDeclarations()) {
108
+ const initializer = decl.getInitializer();
109
+ if (!initializer)
110
+ continue;
111
+ const unwrapped = ts_morph_1.Node.isAsExpression(initializer)
112
+ ? initializer.getExpression()
113
+ : initializer;
114
+ if (!ts_morph_1.Node.isCallExpression(unwrapped))
115
+ continue;
116
+ const callee = unwrapped.getExpression();
117
+ if (!ts_morph_1.Node.isIdentifier(callee))
118
+ continue;
119
+ if (callee.getText() !== DEFINE_CONFIG_NAME)
120
+ continue;
121
+ found.push({ name: decl.getName(), filePath });
122
+ }
123
+ }
124
+ }
125
+ return found;
126
+ }
127
+ // ─── Path helpers ────────────────────────────────────────────────────────────
128
+ /**
129
+ * Builds the POSIX module-specifier string used by `src/events/index.ts` to
130
+ * import from `eventConfigFilePath`.
131
+ *
132
+ * - Strips the trailing `.ts` extension.
133
+ * - Collapses `/index` so `src/form/v2/birth/index.ts` → `../form/v2/birth`.
134
+ * - Ensures the result starts with `./` or `../` (relative paths are required
135
+ * for sibling files that would otherwise be parsed as bare module names).
136
+ */
137
+ function buildIndexImportSpecifier(eventConfigFilePath, srcDir) {
138
+ const eventsIndexDir = path_1.default.join(srcDir, 'events');
139
+ let rel = path_1.default
140
+ .relative(eventsIndexDir, eventConfigFilePath)
141
+ .split(path_1.default.sep)
142
+ .join('/');
143
+ if (rel.endsWith('.ts'))
144
+ rel = rel.slice(0, -'.ts'.length);
145
+ if (rel.endsWith('/index'))
146
+ rel = rel.slice(0, -'/index'.length);
147
+ if (!rel.startsWith('.'))
148
+ rel = './' + rel;
149
+ return rel;
150
+ }
151
+ // ─── events/index.ts generation ──────────────────────────────────────────────
152
+ function buildEventsIndexSource(exports, srcDir) {
153
+ const imports = exports
154
+ .map((e) => `import { ${e.name} } from '${buildIndexImportSpecifier(e.filePath, srcDir)}'`)
155
+ .join('\n');
156
+ const array = `export const ${EVENT_CONFIGS_IDENTIFIER} = [${exports
157
+ .map((e) => e.name)
158
+ .join(', ')}]`;
159
+ return `${LICENSE_HEADER}${imports}\n\n${array}\n`;
160
+ }
161
+ // ─── Handler discovery & rewrite ─────────────────────────────────────────────
162
+ /**
163
+ * Returns the first source file under `srcDir` whose top-level declarations
164
+ * include a function (either `function foo()` or `const foo = () => {}`) whose
165
+ * name is in `HANDLER_FUNCTION_NAMES`.
166
+ */
167
+ function findHandlerSourceFile(project, srcDir) {
168
+ for (const sf of project.getSourceFiles()) {
169
+ const fp = sf.getFilePath();
170
+ if (!fp.startsWith(srcDir) || fp.includes('/node_modules/'))
171
+ continue;
172
+ for (const fn of sf.getFunctions()) {
173
+ const name = fn.getName();
174
+ if (name && HANDLER_FUNCTION_NAMES.has(name))
175
+ return sf;
176
+ }
177
+ for (const statement of sf.getVariableStatements()) {
178
+ for (const decl of statement.getDeclarations()) {
179
+ if (HANDLER_FUNCTION_NAMES.has(decl.getName()))
180
+ return sf;
181
+ }
182
+ }
183
+ }
184
+ return undefined;
185
+ }
186
+ /**
187
+ * Mutates the handler source file:
188
+ * 1. Removes named imports matching `exportNames` from existing imports
189
+ * and drops any import declaration that's left empty.
190
+ * 2. Removes a stale top-level `export const eventConfigs = ...` if present.
191
+ * 3. Ensures `import { eventConfigs } from '@countryconfig/events'` exists
192
+ * (merging into an existing import of the same module when possible).
193
+ * 4. Replaces every `h.response([<identifiers>])` argument with
194
+ * `eventConfigs`.
195
+ *
196
+ * Returns a log of the changes that were actually applied.
197
+ */
198
+ function modifyHandler(sourceFile, exportNames) {
199
+ const changes = [];
200
+ // 1. Drop direct imports of event configs. Iterate over a snapshot because
201
+ // `importDecl.remove()` may mutate the declaration list.
202
+ for (const importDecl of [...sourceFile.getImportDeclarations()]) {
203
+ const namedImports = importDecl.getNamedImports();
204
+ if (namedImports.length === 0)
205
+ continue;
206
+ const matched = namedImports.filter((ni) => exportNames.has(ni.getName()));
207
+ if (matched.length === 0)
208
+ continue;
209
+ const removedNames = matched.map((ni) => ni.getName());
210
+ for (const ni of matched)
211
+ ni.remove();
212
+ changes.push(`removed direct imports: ${removedNames.join(', ')}`);
213
+ const stillUsed = importDecl.getNamedImports().length > 0 ||
214
+ importDecl.getDefaultImport() ||
215
+ importDecl.getNamespaceImport();
216
+ if (!stillUsed)
217
+ importDecl.remove();
218
+ }
219
+ // 2. Remove an inline top-level `export const eventConfigs = ...` if present.
220
+ // This cleans up after any earlier in-place hoisting done by a previous
221
+ // version of this migration.
222
+ for (const statement of [...sourceFile.getVariableStatements()]) {
223
+ if (!statement.hasExportKeyword())
224
+ continue;
225
+ const hasEventConfigs = statement
226
+ .getDeclarations()
227
+ .some((d) => d.getName() === EVENT_CONFIGS_IDENTIFIER);
228
+ if (hasEventConfigs) {
229
+ statement.remove();
230
+ changes.push(`removed inline 'export const ${EVENT_CONFIGS_IDENTIFIER}'`);
231
+ }
232
+ }
233
+ // 3. Ensure `import { eventConfigs } from '@countryconfig/events'`.
234
+ const existing = sourceFile.getImportDeclaration((imp) => imp.getModuleSpecifierValue() === EVENTS_INDEX_IMPORT_PATH);
235
+ if (existing) {
236
+ const already = existing
237
+ .getNamedImports()
238
+ .some((ni) => ni.getName() === EVENT_CONFIGS_IDENTIFIER);
239
+ if (!already) {
240
+ existing.addNamedImport(EVENT_CONFIGS_IDENTIFIER);
241
+ changes.push(`added '${EVENT_CONFIGS_IDENTIFIER}' to existing import from '${EVENTS_INDEX_IMPORT_PATH}'`);
242
+ }
243
+ }
244
+ else {
245
+ sourceFile.addImportDeclaration({
246
+ moduleSpecifier: EVENTS_INDEX_IMPORT_PATH,
247
+ namedImports: [EVENT_CONFIGS_IDENTIFIER]
248
+ });
249
+ changes.push(`added import { ${EVENT_CONFIGS_IDENTIFIER} } from '${EVENTS_INDEX_IMPORT_PATH}'`);
250
+ }
251
+ // 4. Replace inline `h.response([<identifiers>])` with `h.response(eventConfigs)`.
252
+ for (const call of sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.CallExpression)) {
253
+ const callee = call.getExpression();
254
+ if (!ts_morph_1.Node.isPropertyAccessExpression(callee))
255
+ continue;
256
+ if (callee.getName() !== RESPONSE_METHOD_NAME)
257
+ continue;
258
+ const args = call.getArguments();
259
+ if (args.length !== 1)
260
+ continue;
261
+ const [arg] = args;
262
+ if (!ts_morph_1.Node.isArrayLiteralExpression(arg))
263
+ continue;
264
+ if (arg.getElements().length === 0)
265
+ continue;
266
+ if (!arg.getElements().every((el) => ts_morph_1.Node.isIdentifier(el)))
267
+ continue;
268
+ arg.replaceWithText(EVENT_CONFIGS_IDENTIFIER);
269
+ changes.push(`rewrote h.response([...]) → h.response(${EVENT_CONFIGS_IDENTIFIER})`);
270
+ }
271
+ return changes;
272
+ }
273
+ // ─── Entry point ─────────────────────────────────────────────────────────────
274
+ function main() {
275
+ return __awaiter(this, void 0, void 0, function* () {
276
+ const cwd = process.cwd();
277
+ const srcDir = path_1.default.join(cwd, 'src');
278
+ console.log(`Scanning for defineConfig event exports in: ${srcDir}\n`);
279
+ const project = new ts_morph_1.Project({
280
+ tsConfigFilePath: path_1.default.resolve(srcDir, '../tsconfig.json'),
281
+ skipAddingFilesFromTsConfig: false
282
+ });
283
+ const eventConfigExports = findEventConfigExports(project, srcDir);
284
+ if (eventConfigExports.length === 0) {
285
+ console.log('No top-level `export const X = defineConfig(...)` declarations found. Nothing to do.');
286
+ return;
287
+ }
288
+ console.log(`Found ${eventConfigExports.length} event config export(s):`);
289
+ for (const e of eventConfigExports) {
290
+ console.log(` ${e.name} ← ${path_1.default.relative(cwd, e.filePath)}`);
291
+ }
292
+ // ── Create (or skip) src/events/index.ts ───────────────────────────────────
293
+ const eventsIndexAbs = path_1.default.join(srcDir, 'events', 'index.ts');
294
+ const eventsIndexRel = path_1.default.relative(cwd, eventsIndexAbs);
295
+ if (fs_1.default.existsSync(eventsIndexAbs)) {
296
+ console.log(`\n[${eventsIndexRel}] already exists — leaving untouched.`);
297
+ }
298
+ else {
299
+ fs_1.default.mkdirSync(path_1.default.dirname(eventsIndexAbs), { recursive: true });
300
+ const source = buildEventsIndexSource(eventConfigExports, srcDir);
301
+ const eventsIndexFile = project.createSourceFile(eventsIndexAbs, source, {
302
+ overwrite: false
303
+ });
304
+ yield eventsIndexFile.save();
305
+ console.log(`\n[${eventsIndexRel}] created with ${EVENT_CONFIGS_IDENTIFIER} of ${eventConfigExports.length} event(s).`);
306
+ }
307
+ // ── Rewire handler file ────────────────────────────────────────────────────
308
+ const handler = findHandlerSourceFile(project, srcDir);
309
+ if (!handler) {
310
+ console.log(`\nNo event-config handler file found (looked for exported function(s): ${Array.from(HANDLER_FUNCTION_NAMES).join(', ')}). Skipping handler rewrite.`);
311
+ return;
312
+ }
313
+ const handlerRelPath = path_1.default.relative(cwd, handler.getFilePath());
314
+ const exportNameSet = new Set(eventConfigExports.map((e) => e.name));
315
+ const changes = modifyHandler(handler, exportNameSet);
316
+ if (changes.length === 0) {
317
+ console.log(`\n[${handlerRelPath}] already wired to ${EVENTS_INDEX_IMPORT_PATH} — no changes.`);
318
+ return;
319
+ }
320
+ for (const c of changes)
321
+ console.log(` [${handlerRelPath}] ${c}`);
322
+ yield handler.save();
323
+ console.log(`\nSaved ${handlerRelPath}.`);
324
+ });
325
+ }
@@ -0,0 +1,3 @@
1
+ declare function main(): Promise<void>;
2
+ export { main };
3
+ //# sourceMappingURL=delete-infrastructure-directory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"delete-infrastructure-directory.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/delete-infrastructure-directory.ts"],"names":[],"mappings":"AA4CA,iBAAe,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAgCnC;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ /*
3
+ * This Source Code Form is subject to the terms of the Mozilla Public
4
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/.
6
+ *
7
+ * OpenCRVS is also distributed under the terms of the Civil Registration
8
+ * & Healthcare Disclaimer located at http://opencrvs.org/license.
9
+ *
10
+ * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
11
+ */
12
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
+ return new (P || (P = Promise))(function (resolve, reject) {
15
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
19
+ });
20
+ };
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.main = main;
23
+ /**
24
+ * Codemod: Remove the local `infrastructure/` directory.
25
+ *
26
+ * Used by the v1.9 → v2.0 upgrade when the country config does NOT deploy
27
+ * via Docker Swarm. In that case the `infrastructure/` directory shipped
28
+ * with opencrvs-countryconfig is no longer needed and can be removed.
29
+ *
30
+ * Usage:
31
+ * ts-node -r tsconfig-paths/register src/migrations/v2.0/delete-infrastructure-directory.ts
32
+ *
33
+ * What it does:
34
+ * 1. Stages deletion of all tracked files under `infrastructure/` via
35
+ * `git rm -rf --ignore-unmatch -- infrastructure/`. This both removes
36
+ * the files from the working tree and records the deletion in the
37
+ * index, so it shows up in the upgrade commit alongside the other
38
+ * codemod changes.
39
+ * 2. Cleans up any untracked files / empty directory that `git rm` left
40
+ * behind, so the path is fully gone from the working tree.
41
+ *
42
+ * Caveats:
43
+ * - Destructive: any local edits to `infrastructure/` are lost. Run on a
44
+ * clean working tree (or after committing your local changes).
45
+ * - If `infrastructure/` doesn't exist, this codemod is a no-op.
46
+ * - Requires git to be installed and the country config working directory
47
+ * to be a git repo.
48
+ */
49
+ const fs_1 = require("fs");
50
+ const path_1 = require("path");
51
+ const checkout_upstream_files_1 = require("./checkout-upstream-files");
52
+ const INFRASTRUCTURE_DIR = 'infrastructure';
53
+ function main() {
54
+ return __awaiter(this, void 0, void 0, function* () {
55
+ const fullPath = (0, path_1.join)(process.cwd(), INFRASTRUCTURE_DIR);
56
+ if (!(0, fs_1.existsSync)(fullPath)) {
57
+ console.log(`'${INFRASTRUCTURE_DIR}/' not found in ${process.cwd()} — nothing to delete.`);
58
+ return;
59
+ }
60
+ console.log(`Deleting '${INFRASTRUCTURE_DIR}/'...\n`);
61
+ (0, checkout_upstream_files_1.assertIsGitRepo)();
62
+ // `git rm -rf --ignore-unmatch` removes tracked files (working tree + index)
63
+ // and is a no-op for paths with no tracked entries, so it's safe to run
64
+ // even when `infrastructure/` exists only as untracked files.
65
+ (0, checkout_upstream_files_1.runGit)(['rm', '-rf', '--ignore-unmatch', '--', `${INFRASTRUCTURE_DIR}/`], {
66
+ silent: true
67
+ });
68
+ console.log(` Staged deletion of tracked files under '${INFRASTRUCTURE_DIR}/'.`);
69
+ // `git rm` leaves untracked files (and any now-empty directory) on disk;
70
+ // remove whatever's left so the path is fully gone.
71
+ if ((0, fs_1.existsSync)(fullPath)) {
72
+ (0, fs_1.rmSync)(fullPath, { recursive: true, force: true });
73
+ console.log(` Removed remaining untracked files under '${INFRASTRUCTURE_DIR}/'.`);
74
+ }
75
+ console.log(`\n Done. Review the staged deletion with: git diff --cached -- '${INFRASTRUCTURE_DIR}/'`);
76
+ });
77
+ }