@opencrvs/toolkit 1.9.13-rc.f1fdcea → 2.0.0-rc.02ff545

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 (154) hide show
  1. package/build.sh +13 -0
  2. package/dist/api/index.d.ts.map +1 -1
  3. package/dist/application-config/index.d.ts +2 -0
  4. package/dist/application-config/index.d.ts.map +1 -0
  5. package/dist/application-config/index.js +2156 -0
  6. package/dist/cli.d.ts +2 -0
  7. package/dist/cli.d.ts.map +1 -0
  8. package/dist/cli.js +4972 -0
  9. package/dist/commons/api/router.d.ts +3497 -2348
  10. package/dist/commons/application-config/index.d.ts +96 -0
  11. package/dist/commons/conditionals/conditionals.d.ts +27 -3
  12. package/dist/commons/conditionals/validate.d.ts +13 -2
  13. package/dist/commons/events/ActionConfig.d.ts +415 -1555
  14. package/dist/commons/events/ActionDocument.d.ts +888 -1941
  15. package/dist/commons/events/ActionInput.d.ts +277 -1073
  16. package/dist/commons/events/ActionType.d.ts +91 -11
  17. package/dist/commons/events/AdvancedSearchConfig.d.ts +294 -1496
  18. package/dist/commons/events/AuditLog.d.ts +407 -0
  19. package/dist/commons/events/CompositeFieldValue.d.ts +30 -190
  20. package/dist/commons/events/Conditional.d.ts +26 -38
  21. package/dist/commons/events/Constants.d.ts +1 -1
  22. package/dist/commons/events/CountryConfigQueryInput.d.ts +1592 -4471
  23. package/dist/commons/events/DeduplicationConfig.d.ts +15 -171
  24. package/dist/commons/events/Draft.d.ts +72 -107
  25. package/dist/commons/events/DynamicFieldValue.d.ts +12 -78
  26. package/dist/commons/events/EventConfig.d.ts +37 -2420
  27. package/dist/commons/events/EventConfigInput.d.ts +0 -3
  28. package/dist/commons/events/EventDocument.d.ts +354 -1366
  29. package/dist/commons/events/EventIndex.d.ts +212 -1010
  30. package/dist/commons/events/EventInput.d.ts +3 -8
  31. package/dist/commons/events/EventMetadata.d.ts +130 -357
  32. package/dist/commons/events/FieldConfig.d.ts +2897 -12901
  33. package/dist/commons/events/FieldType.d.ts +26 -4
  34. package/dist/commons/events/FieldTypeMapping.d.ts +314 -906
  35. package/dist/commons/events/FieldValue.d.ts +149 -527
  36. package/dist/commons/events/FileUtils.d.ts +2 -2
  37. package/dist/commons/events/Flag.d.ts +67 -0
  38. package/dist/commons/events/FormConfig.d.ts +54 -721
  39. package/dist/commons/events/PageConfig.d.ts +58 -320
  40. package/dist/commons/events/PlainDate.d.ts +1 -1
  41. package/dist/commons/events/SummaryConfig.d.ts +14 -161
  42. package/dist/commons/events/TemplateConfig.d.ts +2 -3
  43. package/dist/commons/events/TranslationConfig.d.ts +2 -2
  44. package/dist/commons/events/WorkqueueColumnConfig.d.ts +74 -37
  45. package/dist/commons/events/WorkqueueConfig.d.ts +2208 -7553
  46. package/dist/commons/events/deduplication.d.ts +3 -3
  47. package/dist/commons/events/defineConfig.d.ts +2 -247
  48. package/dist/commons/events/eventConfigValidation.d.ts +8 -0
  49. package/dist/commons/events/index.d.ts +3 -0
  50. package/dist/commons/events/locations.d.ts +73 -20
  51. package/dist/commons/events/scopes.d.ts +36 -35
  52. package/dist/commons/events/state/availableActions.d.ts +7 -2
  53. package/dist/commons/events/state/flags.d.ts +21 -3
  54. package/dist/commons/events/state/index.d.ts +30 -27
  55. package/dist/commons/events/state/utils.d.ts +190 -172
  56. package/dist/commons/events/test.utils.d.ts +52 -11
  57. package/dist/commons/events/transactions.d.ts +1 -1
  58. package/dist/commons/events/utils.d.ts +374 -443
  59. package/dist/commons/notification/UserNotifications.d.ts +76 -637
  60. package/dist/conditionals/index.d.ts.map +1 -1
  61. package/dist/conditionals/index.js +330 -14
  62. package/dist/events/deduplication.d.ts +3 -3
  63. package/dist/events/index.js +2923 -2112
  64. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts +3 -0
  65. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts.map +1 -0
  66. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.js +429 -0
  67. package/dist/migrations/v2.0/add-resend-invite-notification.d.ts +3 -0
  68. package/dist/migrations/v2.0/add-resend-invite-notification.d.ts.map +1 -0
  69. package/dist/migrations/v2.0/add-resend-invite-notification.js +373 -0
  70. package/dist/migrations/v2.0/checkout-upstream-files.d.ts +22 -0
  71. package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +1 -0
  72. package/dist/migrations/v2.0/checkout-upstream-files.js +147 -0
  73. package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts +2 -0
  74. package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts.map +1 -0
  75. package/dist/migrations/v2.0/convert-config-files-to-ts.js +828 -0
  76. package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts +3 -0
  77. package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts.map +1 -0
  78. package/dist/migrations/v2.0/convert-paragraph-to-heading.js +158 -0
  79. package/dist/migrations/v2.0/create-events-index.d.ts +3 -0
  80. package/dist/migrations/v2.0/create-events-index.d.ts.map +1 -0
  81. package/dist/migrations/v2.0/create-events-index.js +325 -0
  82. package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts +3 -0
  83. package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts.map +1 -0
  84. package/dist/migrations/v2.0/delete-infrastructure-directory.js +77 -0
  85. package/dist/migrations/v2.0/index.d.ts +11 -0
  86. package/dist/migrations/v2.0/index.d.ts.map +1 -0
  87. package/dist/migrations/v2.0/index.js +4882 -0
  88. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts +3 -0
  89. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts.map +1 -0
  90. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.js +432 -0
  91. package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts +3 -0
  92. package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts.map +1 -0
  93. package/dist/migrations/v2.0/merge-infrastructure-directory.js +221 -0
  94. package/dist/migrations/v2.0/migrate-application-config-url.d.ts +3 -0
  95. package/dist/migrations/v2.0/migrate-application-config-url.d.ts.map +1 -0
  96. package/dist/migrations/v2.0/migrate-application-config-url.js +342 -0
  97. package/dist/migrations/v2.0/migrate-scopes.d.ts +3 -0
  98. package/dist/migrations/v2.0/migrate-scopes.d.ts.map +1 -0
  99. package/dist/migrations/v2.0/migrate-scopes.js +281 -0
  100. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts +3 -0
  101. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts.map +1 -0
  102. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.js +267 -0
  103. package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts +3 -0
  104. package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts.map +1 -0
  105. package/dist/migrations/v2.0/migrate-workqueue-configs.js +236 -0
  106. package/dist/migrations/v2.0/remove-delete-actions.d.ts +3 -0
  107. package/dist/migrations/v2.0/remove-delete-actions.d.ts.map +1 -0
  108. package/dist/migrations/v2.0/remove-delete-actions.js +156 -0
  109. package/dist/migrations/v2.0/remove-demo-scope.d.ts +3 -0
  110. package/dist/migrations/v2.0/remove-demo-scope.d.ts.map +1 -0
  111. package/dist/migrations/v2.0/remove-demo-scope.js +74 -0
  112. package/dist/migrations/v2.0/remove-deprecated-imports.d.ts +3 -0
  113. package/dist/migrations/v2.0/remove-deprecated-imports.d.ts.map +1 -0
  114. package/dist/migrations/v2.0/remove-deprecated-imports.js +96 -0
  115. package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts +3 -0
  116. package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts.map +1 -0
  117. package/dist/migrations/v2.0/remove-fhir-url-helpers.js +163 -0
  118. package/dist/migrations/v2.0/remove-hearth-migrations.d.ts +3 -0
  119. package/dist/migrations/v2.0/remove-hearth-migrations.d.ts.map +1 -0
  120. package/dist/migrations/v2.0/remove-hearth-migrations.js +77 -0
  121. package/dist/migrations/v2.0/remove-old-statistics-service.d.ts +3 -0
  122. package/dist/migrations/v2.0/remove-old-statistics-service.d.ts.map +1 -0
  123. package/dist/migrations/v2.0/remove-old-statistics-service.js +356 -0
  124. package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts +3 -0
  125. package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts.map +1 -0
  126. package/dist/migrations/v2.0/remove-pending-certification-flag.js +109 -0
  127. package/dist/migrations/v2.0/remove-review-from-register-action.d.ts +3 -0
  128. package/dist/migrations/v2.0/remove-review-from-register-action.d.ts.map +1 -0
  129. package/dist/migrations/v2.0/remove-review-from-register-action.js +163 -0
  130. package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts +3 -0
  131. package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts.map +1 -0
  132. package/dist/migrations/v2.0/remove-unused-environment-variables.js +186 -0
  133. package/dist/migrations/v2.0/rename-api-paths.d.ts +3 -0
  134. package/dist/migrations/v2.0/rename-api-paths.d.ts.map +1 -0
  135. package/dist/migrations/v2.0/rename-api-paths.js +187 -0
  136. package/dist/migrations/v2.0/rename-location-parent-id.d.ts +3 -0
  137. package/dist/migrations/v2.0/rename-location-parent-id.d.ts.map +1 -0
  138. package/dist/migrations/v2.0/rename-location-parent-id.js +180 -0
  139. package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts +3 -0
  140. package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts.map +1 -0
  141. package/dist/migrations/v2.0/simplify-analytics-precalculations.js +195 -0
  142. package/dist/migrations/v2.0/update-package-json.d.ts +3 -0
  143. package/dist/migrations/v2.0/update-package-json.d.ts.map +1 -0
  144. package/dist/migrations/v2.0/update-package-json.js +105 -0
  145. package/dist/notification/index.d.ts.map +1 -1
  146. package/dist/notification/index.js +2110 -1770
  147. package/dist/scopes/index.d.ts +711 -352
  148. package/dist/scopes/index.d.ts.map +1 -1
  149. package/dist/scopes/index.js +372 -299
  150. package/opencrvs-toolkit-2.0.0-rc.02ff545.tgz +0 -0
  151. package/package.json +18 -8
  152. package/tsconfig.json +12 -2
  153. package/tsconfig.tsbuildinfo +1 -1
  154. package/dist/commons/events/CreatedAtLocation.d.ts +0 -2
@@ -0,0 +1,356 @@
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: Remove the legacy `GET /statistics` Hapi route and its handler.
28
+ *
29
+ * Background:
30
+ * In v1.x country configs exposed a `GET /statistics` route used by the
31
+ * demo data-generator script to seed location statistics. In v2.0 this is
32
+ * no longer part of the country config surface — the data-generator (where
33
+ * it remains) talks to the Core FHIR APIs directly.
34
+ *
35
+ * What it does (per source file under `src/`):
36
+ * 1. Removes any `<receiver>.route({ method: 'GET', path: '/statistics', ... })`
37
+ * call. Both single-route (`server.route({...})`) and array-route
38
+ * (`server.route([{...}, {...}])`) forms are handled — for the array
39
+ * form only the matching object is removed, the other routes stay.
40
+ * 2. Removes any `statisticsHandler` named import. If that empties an
41
+ * import declaration, the whole declaration is dropped.
42
+ * 3. Finds the file that defines `export async function statisticsHandler`
43
+ * (typically `src/api/data-generator/handler.ts`):
44
+ * - If `statisticsHandler` is the file's *only* export → the whole
45
+ * file is deleted.
46
+ * - Otherwise → just the function declaration is removed and a
47
+ * warning is logged so the developer can decide what to do with
48
+ * the rest of the file.
49
+ * 4. After deleting the handler file, performs a transitive orphan sweep
50
+ * bounded to the handler's directory subtree (e.g.
51
+ * `src/api/data-generator/`):
52
+ * - Each project-local import the handler had is checked. If no
53
+ * remaining file in the project imports that module, the module
54
+ * file is deleted too.
55
+ * - Recursive: a deleted file's own local imports are then checked
56
+ * the same way. The directory boundary prevents this from ever
57
+ * touching shared utilities outside the handler's subtree.
58
+ * This is what reaches `service.ts` (and friends) once nothing else
59
+ * uses it.
60
+ *
61
+ * Caveats:
62
+ * - Only project-local imports inside the handler's directory are
63
+ * considered for orphan deletion. Helpers in shared locations (e.g.
64
+ * `src/utils/`, `src/constants.ts`) are never auto-deleted.
65
+ * - Files that are still referenced by *anything* in the project (other
66
+ * handlers, scripts, demo/data-generators) are kept untouched.
67
+ * - The codemod is a no-op when the route doesn't exist (already
68
+ * migrated country configs).
69
+ */
70
+ const path_1 = __importDefault(require("path"));
71
+ const ts_morph_1 = require("ts-morph");
72
+ const ROUTE_PATH = '/statistics';
73
+ const HANDLER_NAME = 'statisticsHandler';
74
+ /**
75
+ * Returns true if the given object literal has a property `path` whose
76
+ * value (string literal or no-substitution template literal) equals
77
+ * `ROUTE_PATH`.
78
+ */
79
+ function isStatisticsRouteObject(obj) {
80
+ const pathProp = obj.getProperty('path');
81
+ if (!pathProp || !ts_morph_1.Node.isPropertyAssignment(pathProp))
82
+ return false;
83
+ const init = pathProp.getInitializer();
84
+ if (!init)
85
+ return false;
86
+ if (ts_morph_1.Node.isStringLiteral(init) || ts_morph_1.Node.isNoSubstitutionTemplateLiteral(init)) {
87
+ return init.getLiteralValue() === ROUTE_PATH;
88
+ }
89
+ return false;
90
+ }
91
+ /**
92
+ * Removes `<receiver>.route({...})` and `<receiver>.route([{...}, ...])`
93
+ * calls whose route object has `path: '/statistics'`. For the array form
94
+ * only the matching element is removed; siblings are preserved.
95
+ *
96
+ * Returns the number of routes removed in this file.
97
+ */
98
+ function removeStatisticsRoutes(sourceFile) {
99
+ let removed = 0;
100
+ // Snapshot first — we'll be mutating the AST during iteration.
101
+ const callExpressions = [
102
+ ...sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.CallExpression)
103
+ ];
104
+ for (const call of callExpressions) {
105
+ if (call.wasForgotten())
106
+ continue;
107
+ const expr = call.getExpression();
108
+ if (!ts_morph_1.Node.isPropertyAccessExpression(expr))
109
+ continue;
110
+ if (expr.getName() !== 'route')
111
+ continue;
112
+ const args = call.getArguments();
113
+ if (args.length === 0)
114
+ continue;
115
+ const firstArg = args[0];
116
+ // Single-route form: `server.route({ method, path, handler, ... })`
117
+ if (ts_morph_1.Node.isObjectLiteralExpression(firstArg)) {
118
+ if (!isStatisticsRouteObject(firstArg))
119
+ continue;
120
+ // Drop the whole `server.route({...})` statement, not just the call,
121
+ // so we don't leave a dangling `;` behind.
122
+ const stmt = call.getFirstAncestorByKind(ts_morph_1.SyntaxKind.ExpressionStatement);
123
+ if (stmt) {
124
+ stmt.remove();
125
+ removed++;
126
+ }
127
+ else {
128
+ // Fallback (shouldn't happen at top level): replace the call.
129
+ call.replaceWithText('');
130
+ removed++;
131
+ }
132
+ continue;
133
+ }
134
+ // Array-route form: `server.route([{...}, {...}])`
135
+ if (ts_morph_1.Node.isArrayLiteralExpression(firstArg)) {
136
+ const matchingIndexes = firstArg
137
+ .getElements()
138
+ .map((el, idx) => ({ el, idx }))
139
+ .filter(({ el }) => ts_morph_1.Node.isObjectLiteralExpression(el) && isStatisticsRouteObject(el))
140
+ .map(({ idx }) => idx);
141
+ // Highest index first so each removal doesn't shift the index of
142
+ // matches we haven't dropped yet.
143
+ matchingIndexes
144
+ .sort((a, b) => b - a)
145
+ .forEach((idx) => {
146
+ firstArg.removeElement(idx);
147
+ removed++;
148
+ });
149
+ }
150
+ }
151
+ return removed;
152
+ }
153
+ /**
154
+ * Removes any `statisticsHandler` named import. Returns true if the file
155
+ * was modified.
156
+ */
157
+ function removeStatisticsHandlerImports(sourceFile) {
158
+ let changed = false;
159
+ for (const decl of sourceFile.getImportDeclarations()) {
160
+ const targetNamed = decl
161
+ .getNamedImports()
162
+ .find((ni) => ni.getName() === HANDLER_NAME);
163
+ if (!targetNamed)
164
+ continue;
165
+ targetNamed.remove();
166
+ changed = true;
167
+ const isNowEmpty = decl.getNamedImports().length === 0 &&
168
+ !decl.getDefaultImport() &&
169
+ !decl.getNamespaceImport();
170
+ if (isNowEmpty)
171
+ decl.remove();
172
+ }
173
+ return changed;
174
+ }
175
+ function processFile(sourceFile) {
176
+ const routesRemoved = removeStatisticsRoutes(sourceFile);
177
+ const importsCleaned = removeStatisticsHandlerImports(sourceFile);
178
+ return { routesRemoved, importsCleaned };
179
+ }
180
+ /**
181
+ * Returns local-project import paths from the given source file that
182
+ * resolve to a file inside `subtreeRoot`. External (npm) imports and
183
+ * imports outside the subtree are excluded.
184
+ */
185
+ function collectLocalImportsInSubtree(sourceFile, subtreeRoot) {
186
+ const result = [];
187
+ for (const decl of sourceFile.getImportDeclarations()) {
188
+ const moduleSf = decl.getModuleSpecifierSourceFile();
189
+ if (!moduleSf)
190
+ continue;
191
+ const fp = moduleSf.getFilePath();
192
+ if (!fp.startsWith(subtreeRoot))
193
+ continue;
194
+ result.push(fp);
195
+ }
196
+ return result;
197
+ }
198
+ /**
199
+ * Walks files reachable from a deleted starting file via local imports
200
+ * within `subtreeRoot`, deleting any that nobody else imports. Recursive
201
+ * via worklist — when a file is deleted, its own local imports become
202
+ * candidates for the next round.
203
+ */
204
+ function deleteOrphanedDescendants(project, startingFile, subtreeRoot) {
205
+ const initialCandidates = collectLocalImportsInSubtree(startingFile, subtreeRoot);
206
+ const startingPath = startingFile.getFilePath();
207
+ const deleted = new Set([startingPath]);
208
+ const seen = new Set();
209
+ const worklist = [...initialCandidates];
210
+ const orphans = [];
211
+ while (worklist.length > 0) {
212
+ const candidate = worklist.shift();
213
+ if (seen.has(candidate))
214
+ continue;
215
+ seen.add(candidate);
216
+ if (deleted.has(candidate))
217
+ continue;
218
+ if (!candidate.startsWith(subtreeRoot))
219
+ continue;
220
+ const candidateSf = project.getSourceFile(candidate);
221
+ if (!candidateSf)
222
+ continue;
223
+ // Anyone left in the project still importing this file (including
224
+ // files outside the subtree)? If so, it's not actually orphaned.
225
+ const stillImported = project.getSourceFiles().some((sf) => {
226
+ const sfPath = sf.getFilePath();
227
+ if (deleted.has(sfPath))
228
+ return false;
229
+ if (sfPath === candidate)
230
+ return false;
231
+ return sf
232
+ .getImportDeclarations()
233
+ .some((decl) => { var _a; return ((_a = decl.getModuleSpecifierSourceFile()) === null || _a === void 0 ? void 0 : _a.getFilePath()) === candidate; });
234
+ });
235
+ if (stillImported)
236
+ continue;
237
+ // Capture local imports BEFORE deletion — `delete()` invalidates the
238
+ // node, so we wouldn't be able to read them afterwards.
239
+ const next = collectLocalImportsInSubtree(candidateSf, subtreeRoot);
240
+ worklist.push(...next);
241
+ candidateSf.delete();
242
+ deleted.add(candidate);
243
+ orphans.push(candidate);
244
+ }
245
+ return orphans;
246
+ }
247
+ /**
248
+ * Finds the file that exports `statisticsHandler` and either deletes the
249
+ * whole file (when it's the sole export) or just removes the function
250
+ * declaration. When the file is deleted, also performs a transitive
251
+ * orphan sweep bounded to the file's directory.
252
+ */
253
+ function processHandlerFile(project) {
254
+ const sourceFiles = project.getSourceFiles().filter((sf) => {
255
+ const fp = sf.getFilePath();
256
+ return fp.includes('/src/') && !fp.includes('/node_modules/');
257
+ });
258
+ for (const sf of sourceFiles) {
259
+ const fn = sf.getFunction(HANDLER_NAME);
260
+ if (!fn)
261
+ continue;
262
+ const filePath = sf.getFilePath();
263
+ const exportsByName = [...sf.getExportedDeclarations().keys()];
264
+ const otherExports = exportsByName.filter((name) => name !== HANDLER_NAME);
265
+ if (otherExports.length === 0) {
266
+ // Sole export — delete the file, then sweep orphans inside its
267
+ // directory subtree.
268
+ const subtreeRoot = path_1.default.dirname(filePath) + path_1.default.sep;
269
+ const orphansDeleted = deleteOrphanedDescendants(project, sf, subtreeRoot);
270
+ sf.delete();
271
+ return { filePath, action: 'deleted', orphansDeleted };
272
+ }
273
+ // Other exports exist; surgically remove just this function.
274
+ // We don't run the orphan sweep here — the file isn't gone, so
275
+ // anything it imports is presumably still in use.
276
+ fn.remove();
277
+ return {
278
+ filePath,
279
+ action: 'function-removed',
280
+ remainingExports: otherExports,
281
+ orphansDeleted: []
282
+ };
283
+ }
284
+ return { filePath: '', action: 'not-found', orphansDeleted: [] };
285
+ }
286
+ function main() {
287
+ return __awaiter(this, void 0, void 0, function* () {
288
+ var _a;
289
+ const project = new ts_morph_1.Project({
290
+ tsConfigFilePath: path_1.default.resolve(process.cwd(), 'tsconfig.json'),
291
+ skipAddingFilesFromTsConfig: false
292
+ });
293
+ const sourceFiles = project.getSourceFiles().filter((sf) => {
294
+ const fp = sf.getFilePath();
295
+ return fp.includes('/src/') && !fp.includes('/node_modules/');
296
+ });
297
+ console.log(`Removing legacy 'GET ${ROUTE_PATH}' route and '${HANDLER_NAME}' across ${sourceFiles.length} source file(s)...\n`);
298
+ let totalRoutesRemoved = 0;
299
+ let totalFilesWithImportsCleaned = 0;
300
+ let totalFilesWithRoutesRemoved = 0;
301
+ for (const sourceFile of sourceFiles) {
302
+ const filePath = sourceFile.getFilePath();
303
+ const rel = path_1.default.relative(process.cwd(), filePath);
304
+ const result = processFile(sourceFile);
305
+ if (result.routesRemoved > 0) {
306
+ console.log(` [${rel}] Removed ${result.routesRemoved} '${ROUTE_PATH}' route(s)`);
307
+ totalRoutesRemoved += result.routesRemoved;
308
+ totalFilesWithRoutesRemoved++;
309
+ }
310
+ if (result.importsCleaned) {
311
+ console.log(` [${rel}] Cleaned up '${HANDLER_NAME}' import`);
312
+ totalFilesWithImportsCleaned++;
313
+ }
314
+ if (result.routesRemoved > 0 || result.importsCleaned) {
315
+ yield sourceFile.save();
316
+ }
317
+ }
318
+ const handlerResult = processHandlerFile(project);
319
+ switch (handlerResult.action) {
320
+ case 'deleted': {
321
+ const rel = path_1.default.relative(process.cwd(), handlerResult.filePath);
322
+ console.log(` [${rel}] Deleted handler file ('${HANDLER_NAME}' was the sole export).`);
323
+ for (const orphanPath of handlerResult.orphansDeleted) {
324
+ const orphanRel = path_1.default.relative(process.cwd(), orphanPath);
325
+ console.log(` [${orphanRel}] Deleted (no remaining importers in the project after handler removal).`);
326
+ }
327
+ // `delete()` schedules deletion; `save()` writes it to disk.
328
+ yield project.save();
329
+ break;
330
+ }
331
+ case 'function-removed': {
332
+ const rel = path_1.default.relative(process.cwd(), handlerResult.filePath);
333
+ console.warn(` [${rel}] Removed '${HANDLER_NAME}' function but kept the file (other exports remain: ${(_a = handlerResult.remainingExports) === null || _a === void 0 ? void 0 : _a.join(', ')}). Review whether the file is still needed.`);
334
+ // Save the source file with the function removed.
335
+ const sf = project.getSourceFile(handlerResult.filePath);
336
+ if (sf)
337
+ yield sf.save();
338
+ break;
339
+ }
340
+ case 'not-found':
341
+ // Either already migrated or the handler lives somewhere unexpected.
342
+ // Not an error — continue silently.
343
+ break;
344
+ }
345
+ if (totalRoutesRemoved === 0 &&
346
+ totalFilesWithImportsCleaned === 0 &&
347
+ handlerResult.action === 'not-found') {
348
+ console.log(`\nNo legacy '${ROUTE_PATH}' route or handler found. Nothing to do.`);
349
+ return;
350
+ }
351
+ const orphansSummary = handlerResult.orphansDeleted.length > 0
352
+ ? ` and ${handlerResult.orphansDeleted.length} orphaned helper file(s)`
353
+ : '';
354
+ console.log(`\nDone. Removed ${totalRoutesRemoved} route(s) across ${totalFilesWithRoutesRemoved} file(s); cleaned ${HANDLER_NAME} import in ${totalFilesWithImportsCleaned} file(s)${orphansSummary}.`);
355
+ });
356
+ }
@@ -0,0 +1,3 @@
1
+ declare function main(): Promise<void>;
2
+ export { main };
3
+ //# sourceMappingURL=remove-pending-certification-flag.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remove-pending-certification-flag.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/remove-pending-certification-flag.ts"],"names":[],"mappings":"AAyEA,iBAAe,IAAI,kBAiDlB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
@@ -0,0 +1,109 @@
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: Remove `InherentFlags.PENDING_CERTIFICATION` from any array literal.
28
+ *
29
+ * Usage:
30
+ * ts-node -r tsconfig-paths/register src/migrations/v2.0/remove-pending-certification-flag.ts
31
+ *
32
+ * What it does:
33
+ * - Scans all TypeScript files under `src/`
34
+ * - Finds every array literal in every file
35
+ * - Removes any element that is the property access expression
36
+ * `InherentFlags.PENDING_CERTIFICATION`
37
+ * - Saves the modified files in-place
38
+ */
39
+ const ts_morph_1 = require("ts-morph");
40
+ const path_1 = __importDefault(require("path"));
41
+ const INHERENT_FLAGS_ENUM_NAME = 'InherentFlags';
42
+ const PENDING_CERTIFICATION_MEMBER = 'PENDING_CERTIFICATION';
43
+ function isPendingCertificationFlag(node) {
44
+ if (!ts_morph_1.Node.isPropertyAccessExpression(node))
45
+ return false;
46
+ const obj = node.getExpression();
47
+ const member = node.getName();
48
+ return (ts_morph_1.Node.isIdentifier(obj) &&
49
+ obj.getText() === INHERENT_FLAGS_ENUM_NAME &&
50
+ member === PENDING_CERTIFICATION_MEMBER);
51
+ }
52
+ function processFile(filePath, project) {
53
+ const sourceFile = project.getSourceFile(filePath);
54
+ if (!sourceFile)
55
+ return 0;
56
+ let removedCount = 0;
57
+ const arrayLiterals = sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.ArrayLiteralExpression);
58
+ for (const array of arrayLiterals) {
59
+ // Collect indices in reverse order so removal doesn't shift remaining indices
60
+ const indicesToRemove = [];
61
+ array.getElements().forEach((element, index) => {
62
+ if (isPendingCertificationFlag(element)) {
63
+ indicesToRemove.push(index);
64
+ }
65
+ });
66
+ for (const index of indicesToRemove.reverse()) {
67
+ array.removeElement(index);
68
+ removedCount++;
69
+ console.log(` [${path_1.default.relative(process.cwd(), filePath)}] Removed InherentFlags.PENDING_CERTIFICATION from array`);
70
+ }
71
+ }
72
+ return removedCount;
73
+ }
74
+ function main() {
75
+ return __awaiter(this, void 0, void 0, function* () {
76
+ const srcDir = path_1.default.join(process.cwd(), 'src');
77
+ console.log(`Scanning for InherentFlags.PENDING_CERTIFICATION array elements in: ${srcDir}\n`);
78
+ const project = new ts_morph_1.Project({
79
+ tsConfigFilePath: path_1.default.resolve(srcDir, '../tsconfig.json'),
80
+ skipAddingFilesFromTsConfig: false
81
+ });
82
+ const sourceFiles = project.getSourceFiles().filter((sf) => {
83
+ const fp = sf.getFilePath();
84
+ return fp.includes('/src/') && !fp.includes('/node_modules/');
85
+ });
86
+ console.log(`Found ${sourceFiles.length} source file(s) to analyse.\n`);
87
+ let totalRemoved = 0;
88
+ const modifiedFiles = [];
89
+ for (const sourceFile of sourceFiles) {
90
+ const filePath = sourceFile.getFilePath();
91
+ const removed = processFile(filePath, project);
92
+ if (removed > 0) {
93
+ totalRemoved += removed;
94
+ modifiedFiles.push(filePath);
95
+ }
96
+ }
97
+ if (modifiedFiles.length === 0) {
98
+ console.log('No InherentFlags.PENDING_CERTIFICATION elements found in any array. Nothing to do.');
99
+ return;
100
+ }
101
+ console.log(`\nSaving ${modifiedFiles.length} modified file(s)...`);
102
+ for (const filePath of modifiedFiles) {
103
+ const sourceFile = project.getSourceFileOrThrow(filePath);
104
+ yield sourceFile.save();
105
+ console.log(` Saved: ${path_1.default.relative(process.cwd(), filePath)}`);
106
+ }
107
+ console.log(`\nDone. Removed ${totalRemoved} InherentFlags.PENDING_CERTIFICATION element(s) from array(s).`);
108
+ });
109
+ }
@@ -0,0 +1,3 @@
1
+ declare function main(): Promise<void>;
2
+ export { main };
3
+ //# sourceMappingURL=remove-review-from-register-action.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remove-review-from-register-action.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/remove-review-from-register-action.ts"],"names":[],"mappings":"AAkJA,iBAAe,IAAI,kBAkDlB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
@@ -0,0 +1,163 @@
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: Remove `review` property from `REGISTER` type actions inside `defineConfig` calls.
28
+ *
29
+ * Usage:
30
+ * ts-node -r tsconfig-paths/register src/remove-review-from-register-action.ts
31
+ *
32
+ * What it does:
33
+ * - Scans all TypeScript files under `src/`
34
+ * - Finds every `defineConfig({ ... })` call expression
35
+ * - Inside the `actions` array of that config, locates object literals
36
+ * whose `type` property resolves to `ActionType.REGISTER` or the string literal `"REGISTER"`
37
+ * - Removes the `review` property assignment from those objects
38
+ * - Saves the modified files in-place
39
+ */
40
+ const ts_morph_1 = require("ts-morph");
41
+ const path_1 = __importDefault(require("path"));
42
+ const DEFINE_CONFIG_NAME = 'defineConfig';
43
+ const ACTIONS_PROPERTY_NAME = 'actions';
44
+ const TYPE_PROPERTY_NAME = 'type';
45
+ const REVIEW_PROPERTY_NAME = 'review';
46
+ const REGISTER_ENUM_NAME = 'ActionType';
47
+ const REGISTER_MEMBER_NAME = 'REGISTER';
48
+ const REGISTER_STRING_LITERAL = 'REGISTER';
49
+ function isRegisterType(typeInitializer) {
50
+ // Matches: ActionType.REGISTER
51
+ if (typeInitializer.getKind() === ts_morph_1.SyntaxKind.PropertyAccessExpression) {
52
+ const propAccess = typeInitializer.asKindOrThrow(ts_morph_1.SyntaxKind.PropertyAccessExpression);
53
+ const obj = propAccess.getExpression();
54
+ const member = propAccess.getName();
55
+ return (ts_morph_1.Node.isIdentifier(obj) &&
56
+ obj.getText() === REGISTER_ENUM_NAME &&
57
+ member === REGISTER_MEMBER_NAME);
58
+ }
59
+ // Matches: "REGISTER"
60
+ if (typeInitializer.getKind() === ts_morph_1.SyntaxKind.StringLiteral) {
61
+ return (typeInitializer
62
+ .asKindOrThrow(ts_morph_1.SyntaxKind.StringLiteral)
63
+ .getLiteralValue() === REGISTER_STRING_LITERAL);
64
+ }
65
+ return false;
66
+ }
67
+ function removeReviewFromRegisterActions(obj) {
68
+ const typeProperty = obj.getProperty(TYPE_PROPERTY_NAME);
69
+ if (!typeProperty || !ts_morph_1.Node.isPropertyAssignment(typeProperty)) {
70
+ return false;
71
+ }
72
+ const typeInitializer = typeProperty.getInitializer();
73
+ if (!typeInitializer || !isRegisterType(typeInitializer)) {
74
+ return false;
75
+ }
76
+ const reviewProperty = obj.getProperty(REVIEW_PROPERTY_NAME);
77
+ if (!reviewProperty) {
78
+ return false;
79
+ }
80
+ reviewProperty.remove();
81
+ return true;
82
+ }
83
+ function processFile(filePath, project) {
84
+ const sourceFile = project.getSourceFile(filePath);
85
+ if (!sourceFile)
86
+ return 0;
87
+ let removedCount = 0;
88
+ // Find all call expressions named `defineConfig`
89
+ const callExpressions = sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.CallExpression);
90
+ for (const call of callExpressions) {
91
+ const expression = call.getExpression();
92
+ // Only interested in bare `defineConfig(...)` calls
93
+ if (!ts_morph_1.Node.isIdentifier(expression) ||
94
+ expression.getText() !== DEFINE_CONFIG_NAME) {
95
+ continue;
96
+ }
97
+ const args = call.getArguments();
98
+ if (args.length === 0)
99
+ continue;
100
+ // The first argument should be the config object literal
101
+ const configArg = args[0];
102
+ if (!ts_morph_1.Node.isObjectLiteralExpression(configArg))
103
+ continue;
104
+ // Find the `actions` property inside the config object
105
+ const actionsProperty = configArg.getProperty(ACTIONS_PROPERTY_NAME);
106
+ if (!actionsProperty || !ts_morph_1.Node.isPropertyAssignment(actionsProperty))
107
+ continue;
108
+ const actionsInitializer = actionsProperty.getInitializer();
109
+ if (!actionsInitializer ||
110
+ !ts_morph_1.Node.isArrayLiteralExpression(actionsInitializer))
111
+ continue;
112
+ // Iterate over every element in the `actions` array
113
+ for (const element of actionsInitializer.getElements()) {
114
+ if (!ts_morph_1.Node.isObjectLiteralExpression(element))
115
+ continue;
116
+ const wasRemoved = removeReviewFromRegisterActions(element);
117
+ if (wasRemoved) {
118
+ removedCount++;
119
+ console.log(` [${path_1.default.relative(process.cwd(), filePath)}] Removed 'review' from REGISTER action`);
120
+ }
121
+ }
122
+ }
123
+ return removedCount;
124
+ }
125
+ function main() {
126
+ return __awaiter(this, void 0, void 0, function* () {
127
+ const srcDir = path_1.default.join(process.cwd(), 'src');
128
+ console.log(`Scanning for defineConfig calls in: ${srcDir}\n`);
129
+ const project = new ts_morph_1.Project({
130
+ tsConfigFilePath: path_1.default.resolve(srcDir, '../tsconfig.json'),
131
+ // Do not emit — we only manipulate source files
132
+ skipAddingFilesFromTsConfig: false
133
+ // addFilesFromTsConfig: true
134
+ });
135
+ // Restrict to source files only (exclude node_modules, build artefacts, etc.)
136
+ const sourceFiles = project.getSourceFiles().filter((sf) => {
137
+ const fp = sf.getFilePath();
138
+ return fp.includes('/src/') && !fp.includes('/node_modules/');
139
+ });
140
+ console.log(`Found ${sourceFiles.length} source file(s) to analyse.\n`);
141
+ let totalRemoved = 0;
142
+ const modifiedFiles = [];
143
+ for (const sourceFile of sourceFiles) {
144
+ const filePath = sourceFile.getFilePath();
145
+ const removed = processFile(filePath, project);
146
+ if (removed > 0) {
147
+ totalRemoved += removed;
148
+ modifiedFiles.push(filePath);
149
+ }
150
+ }
151
+ if (modifiedFiles.length === 0) {
152
+ console.log("No 'review' properties found on REGISTER actions. Nothing to do.");
153
+ return;
154
+ }
155
+ console.log(`\nSaving ${modifiedFiles.length} modified file(s)...`);
156
+ for (const filePath of modifiedFiles) {
157
+ const sourceFile = project.getSourceFileOrThrow(filePath);
158
+ yield sourceFile.save();
159
+ console.log(` Saved: ${path_1.default.relative(process.cwd(), filePath)}`);
160
+ }
161
+ console.log(`\nDone. Removed ${totalRemoved} 'review' property assignment(s) from REGISTER action(s).`);
162
+ });
163
+ }
@@ -0,0 +1,3 @@
1
+ declare function main(): Promise<void>;
2
+ export { main };
3
+ //# sourceMappingURL=remove-unused-environment-variables.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remove-unused-environment-variables.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/remove-unused-environment-variables.ts"],"names":[],"mappings":"AAsJA,iBAAe,IAAI,kBAmDlB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}