@opencrvs/toolkit 2.0.0-rc.bb52508 → 2.0.0-rc.bcb5fb2

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 (86) hide show
  1. package/build.sh +3 -0
  2. package/create-countryconfig/index.js +73 -0
  3. package/create-countryconfig/package.json +11 -0
  4. package/dist/application-config/index.js +37 -7
  5. package/dist/cli.js +1784 -349
  6. package/dist/commons/api/router.d.ts +54 -52
  7. package/dist/commons/conditionals/conditionals.d.ts +6 -6
  8. package/dist/commons/events/FieldConfig.d.ts +10 -0
  9. package/dist/commons/events/locations.d.ts +38 -1
  10. package/dist/commons/events/mocks.test.utils.d.ts +19 -0
  11. package/dist/commons/events/scopes.d.ts +24 -1
  12. package/dist/conditionals/index.js +37 -7
  13. package/dist/core-en.json +7238 -0
  14. package/dist/core-en.json.d.ts +2 -0
  15. package/dist/events/index.js +130 -7
  16. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts.map +1 -1
  17. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.js +63 -39
  18. package/dist/migrations/v2.0/add-resend-invite-notification.d.ts +3 -0
  19. package/dist/migrations/v2.0/add-resend-invite-notification.d.ts.map +1 -0
  20. package/dist/migrations/v2.0/add-resend-invite-notification.js +373 -0
  21. package/dist/migrations/v2.0/checkout-upstream-files.d.ts +19 -0
  22. package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +1 -1
  23. package/dist/migrations/v2.0/checkout-upstream-files.js +17 -14
  24. package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts.map +1 -1
  25. package/dist/migrations/v2.0/convert-config-files-to-ts.js +4 -5
  26. package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts.map +1 -1
  27. package/dist/migrations/v2.0/convert-paragraph-to-heading.js +4 -5
  28. package/dist/migrations/v2.0/create-events-index.d.ts.map +1 -1
  29. package/dist/migrations/v2.0/create-events-index.js +1 -2
  30. package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts +11 -0
  31. package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts.map +1 -0
  32. package/dist/migrations/v2.0/delete-infrastructure-directory.js +123 -0
  33. package/dist/migrations/v2.0/index.d.ts +10 -4
  34. package/dist/migrations/v2.0/index.d.ts.map +1 -1
  35. package/dist/migrations/v2.0/index.js +1752 -346
  36. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts.map +1 -1
  37. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.js +95 -7
  38. package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts +13 -0
  39. package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts.map +1 -0
  40. package/dist/migrations/v2.0/merge-infrastructure-directory.js +222 -0
  41. package/dist/migrations/v2.0/migrate-application-config-url.d.ts +3 -0
  42. package/dist/migrations/v2.0/migrate-application-config-url.d.ts.map +1 -0
  43. package/dist/migrations/v2.0/migrate-application-config-url.js +342 -0
  44. package/dist/migrations/v2.0/migrate-scopes.d.ts.map +1 -1
  45. package/dist/migrations/v2.0/migrate-scopes.js +6 -7
  46. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts.map +1 -1
  47. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.js +3 -4
  48. package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts.map +1 -1
  49. package/dist/migrations/v2.0/migrate-workqueue-configs.js +143 -63
  50. package/dist/migrations/v2.0/remove-delete-actions.d.ts.map +1 -1
  51. package/dist/migrations/v2.0/remove-delete-actions.js +3 -4
  52. package/dist/migrations/v2.0/remove-demo-scope.d.ts.map +1 -1
  53. package/dist/migrations/v2.0/remove-demo-scope.js +2 -3
  54. package/dist/migrations/v2.0/remove-deprecated-imports.d.ts.map +1 -1
  55. package/dist/migrations/v2.0/remove-deprecated-imports.js +3 -4
  56. package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts +3 -0
  57. package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts.map +1 -0
  58. package/dist/migrations/v2.0/remove-fhir-url-helpers.js +163 -0
  59. package/dist/migrations/v2.0/remove-hearth-migrations.d.ts.map +1 -1
  60. package/dist/migrations/v2.0/remove-hearth-migrations.js +1 -2
  61. package/dist/migrations/v2.0/remove-old-statistics-service.d.ts +3 -0
  62. package/dist/migrations/v2.0/remove-old-statistics-service.d.ts.map +1 -0
  63. package/dist/migrations/v2.0/remove-old-statistics-service.js +356 -0
  64. package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts.map +1 -1
  65. package/dist/migrations/v2.0/remove-pending-certification-flag.js +3 -4
  66. package/dist/migrations/v2.0/remove-review-from-register-action.d.ts.map +1 -1
  67. package/dist/migrations/v2.0/remove-review-from-register-action.js +3 -4
  68. package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts +3 -0
  69. package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts.map +1 -0
  70. package/dist/migrations/v2.0/remove-unused-environment-variables.js +186 -0
  71. package/dist/migrations/v2.0/rename-api-paths.d.ts.map +1 -1
  72. package/dist/migrations/v2.0/rename-api-paths.js +3 -4
  73. package/dist/migrations/v2.0/rename-location-parent-id.d.ts.map +1 -1
  74. package/dist/migrations/v2.0/rename-location-parent-id.js +3 -4
  75. package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts.map +1 -1
  76. package/dist/migrations/v2.0/simplify-analytics-precalculations.js +1 -2
  77. package/dist/migrations/v2.0/update-package-json.d.ts +3 -0
  78. package/dist/migrations/v2.0/update-package-json.d.ts.map +1 -0
  79. package/dist/migrations/v2.0/update-package-json.js +105 -0
  80. package/dist/notification/index.js +37 -7
  81. package/dist/scopes/index.d.ts +87 -10
  82. package/dist/scopes/index.js +43 -8
  83. package/opencrvs-toolkit-2.0.0-rc.bcb5fb2.tgz +0 -0
  84. package/package.json +6 -2
  85. package/tsconfig.tsbuildinfo +1 -1
  86. package/opencrvs-toolkit-2.0.0-rc.bb52508.tgz +0 -0
@@ -39,17 +39,24 @@ exports.main = main;
39
39
  * - `actions: [{...}, {...}, ...]` -> keeps first as `action`, warns about dropped extras
40
40
  * - If `action` already exists, removes deprecated `actions` and keeps `action`
41
41
  * - Removes unsupported `action.type` values (`DEFAULT`, `VALIDATE`, etc.)
42
+ * - Ensures every workqueue ends up with a valid `action`. When none is
43
+ * present (or the existing one is unsupported), falls back to
44
+ * `action: { type: ActionType.READ }` and ensures `ActionType` is imported
45
+ * from `@opencrvs/toolkit/events` in the file.
42
46
  * - Saves modified files in-place
43
47
  */
44
48
  const ts_morph_1 = require("ts-morph");
45
49
  const path_1 = __importDefault(require("path"));
46
- const _1 = require(".");
47
50
  const DEFINE_WORKQUEUES_NAME = 'defineWorkqueues';
48
51
  const ACTIONS_PROPERTY_NAME = 'actions';
49
52
  const ACTION_PROPERTY_NAME = 'action';
50
53
  const CONDITIONALS_PROPERTY_NAME = 'conditionals';
51
54
  const TYPE_PROPERTY_NAME = 'type';
52
55
  const SLUG_PROPERTY_NAME = 'slug';
56
+ const READ_ACTION_TYPE = 'READ';
57
+ const ACTION_TYPE_IMPORT_NAME = 'ActionType';
58
+ const TOOLKIT_EVENTS_MODULE = '@opencrvs/toolkit/events';
59
+ const READ_ACTION_FALLBACK_INITIALIZER = `{ type: ${ACTION_TYPE_IMPORT_NAME}.${READ_ACTION_TYPE} }`;
53
60
  const SUPPORTED_WORKQUEUE_ACTION_TYPES = new Set([
54
61
  'READ',
55
62
  'DELETE',
@@ -97,81 +104,147 @@ function isUnsupportedActionType(action) {
97
104
  }
98
105
  return !SUPPORTED_WORKQUEUE_ACTION_TYPES.has(typeName);
99
106
  }
100
- function migrateWorkqueueActions(workqueue, relPath) {
101
- const actionsProperty = workqueue.getProperty(ACTIONS_PROPERTY_NAME);
102
- if (!actionsProperty || !ts_morph_1.Node.isPropertyAssignment(actionsProperty)) {
103
- return 0;
104
- }
105
- const actionsInitializer = actionsProperty.getInitializer();
106
- if (!actionsInitializer || !ts_morph_1.Node.isArrayLiteralExpression(actionsInitializer)) {
107
- return 0;
107
+ /**
108
+ * Ensures the workqueue has a valid singular `action` property. When the
109
+ * existing `action` is missing or has an unsupported type, replaces it with
110
+ * `action: { type: ActionType.READ }`.
111
+ *
112
+ * Returns whether anything was changed and whether the READ fallback was
113
+ * applied (so the caller can ensure `ActionType` is imported in the file).
114
+ */
115
+ function ensureValidAction(workqueue, relPath) {
116
+ const workqueueLabel = getWorkqueueLabel(workqueue);
117
+ const actionProperty = workqueue.getProperty(ACTION_PROPERTY_NAME);
118
+ if (actionProperty && ts_morph_1.Node.isPropertyAssignment(actionProperty)) {
119
+ const initializer = actionProperty.getInitializer();
120
+ if (initializer && ts_morph_1.Node.isObjectLiteralExpression(initializer)) {
121
+ if (!isUnsupportedActionType(initializer)) {
122
+ return { changed: false, usedReadFallback: false };
123
+ }
124
+ actionProperty.set({
125
+ name: ACTION_PROPERTY_NAME,
126
+ initializer: READ_ACTION_FALLBACK_INITIALIZER
127
+ });
128
+ // eslint-disable-next-line no-console
129
+ console.log(` [${relPath}] Replaced unsupported 'action' type with '${ACTION_TYPE_IMPORT_NAME}.${READ_ACTION_TYPE}' on workqueue '${workqueueLabel}'`);
130
+ return { changed: true, usedReadFallback: true };
131
+ }
108
132
  }
133
+ workqueue.addPropertyAssignment({
134
+ name: ACTION_PROPERTY_NAME,
135
+ initializer: READ_ACTION_FALLBACK_INITIALIZER
136
+ });
137
+ // eslint-disable-next-line no-console
138
+ console.log(` [${relPath}] Added default 'action: ${READ_ACTION_FALLBACK_INITIALIZER}' to workqueue '${workqueueLabel}'`);
139
+ return { changed: true, usedReadFallback: true };
140
+ }
141
+ function migrateWorkqueueActions(workqueue, relPath) {
109
142
  const workqueueLabel = getWorkqueueLabel(workqueue);
110
- const existingActionProperty = workqueue.getProperty(ACTION_PROPERTY_NAME);
111
- if (existingActionProperty) {
112
- if (ts_morph_1.Node.isPropertyAssignment(existingActionProperty)) {
113
- const existingActionInitializer = existingActionProperty.getInitializer();
114
- if (existingActionInitializer && ts_morph_1.Node.isObjectLiteralExpression(existingActionInitializer)) {
115
- const conditionalsProperty = existingActionInitializer.getProperty(CONDITIONALS_PROPERTY_NAME);
116
- if (conditionalsProperty) {
117
- conditionalsProperty.remove();
118
- // eslint-disable-next-line no-console
119
- console.log(` [${relPath}] Removed deprecated 'conditionals' from 'action' on workqueue '${workqueueLabel}'`);
143
+ const actionsProperty = workqueue.getProperty(ACTIONS_PROPERTY_NAME);
144
+ let actionsArrayMigrated = false;
145
+ if (actionsProperty && ts_morph_1.Node.isPropertyAssignment(actionsProperty)) {
146
+ const actionsInitializer = actionsProperty.getInitializer();
147
+ if (actionsInitializer &&
148
+ ts_morph_1.Node.isArrayLiteralExpression(actionsInitializer)) {
149
+ const existingActionProperty = workqueue.getProperty(ACTION_PROPERTY_NAME);
150
+ if (existingActionProperty) {
151
+ if (ts_morph_1.Node.isPropertyAssignment(existingActionProperty)) {
152
+ const existingActionInitializer = existingActionProperty.getInitializer();
153
+ if (existingActionInitializer &&
154
+ ts_morph_1.Node.isObjectLiteralExpression(existingActionInitializer)) {
155
+ const conditionalsProperty = existingActionInitializer.getProperty(CONDITIONALS_PROPERTY_NAME);
156
+ if (conditionalsProperty) {
157
+ conditionalsProperty.remove();
158
+ // eslint-disable-next-line no-console
159
+ console.log(` [${relPath}] Removed deprecated 'conditionals' from 'action' on workqueue '${workqueueLabel}'`);
160
+ }
161
+ }
120
162
  }
121
- if (isUnsupportedActionType(existingActionInitializer)) {
122
- existingActionProperty.remove();
163
+ actionsProperty.remove();
164
+ // eslint-disable-next-line no-console
165
+ console.log(` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' (existing 'action' kept)`);
166
+ actionsArrayMigrated = true;
167
+ }
168
+ else {
169
+ const actionCandidates = actionsInitializer
170
+ .getElements()
171
+ .filter((element) => ts_morph_1.Node.isObjectLiteralExpression(element));
172
+ if (actionCandidates.length === 0) {
173
+ actionsProperty.remove();
123
174
  // eslint-disable-next-line no-console
124
- console.log(` [${relPath}] Removed unsupported 'action' type on workqueue '${workqueueLabel}'`);
175
+ console.log(` [${relPath}] Removed empty 'actions' from workqueue '${workqueueLabel}'`);
176
+ actionsArrayMigrated = true;
177
+ }
178
+ else {
179
+ if (actionCandidates.length > 1) {
180
+ const droppedCount = actionCandidates.length - 1;
181
+ // eslint-disable-next-line no-console
182
+ console.warn(` [${relPath}] Workqueue '${workqueueLabel}' has ${actionCandidates.length} actions; keeping first as 'action' and dropping ${droppedCount} extra action(s)`);
183
+ }
184
+ const conditionalsProperty = actionCandidates[0].getProperty(CONDITIONALS_PROPERTY_NAME);
185
+ if (conditionalsProperty) {
186
+ conditionalsProperty.remove();
187
+ // eslint-disable-next-line no-console
188
+ console.log(` [${relPath}] Removed deprecated 'conditionals' from migrated 'action' on workqueue '${workqueueLabel}'`);
189
+ }
190
+ if (isUnsupportedActionType(actionCandidates[0])) {
191
+ actionsProperty.remove();
192
+ // eslint-disable-next-line no-console
193
+ console.log(` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' because action type is unsupported`);
194
+ actionsArrayMigrated = true;
195
+ }
196
+ else {
197
+ const firstActionText = actionCandidates[0].getText();
198
+ workqueue.addPropertyAssignment({
199
+ name: ACTION_PROPERTY_NAME,
200
+ initializer: firstActionText
201
+ });
202
+ actionsProperty.remove();
203
+ // eslint-disable-next-line no-console
204
+ console.log(` [${relPath}] Replaced 'actions' with 'action' on workqueue '${workqueueLabel}'`);
205
+ actionsArrayMigrated = true;
206
+ }
125
207
  }
126
208
  }
127
209
  }
128
- actionsProperty.remove();
129
- // eslint-disable-next-line no-console
130
- console.log(` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' (existing 'action' kept)`);
131
- return 1;
132
- }
133
- const actionCandidates = actionsInitializer
134
- .getElements()
135
- .filter((element) => ts_morph_1.Node.isObjectLiteralExpression(element));
136
- if (actionCandidates.length === 0) {
137
- actionsProperty.remove();
138
- // eslint-disable-next-line no-console
139
- console.log(` [${relPath}] Removed empty 'actions' from workqueue '${workqueueLabel}'`);
140
- return 1;
141
- }
142
- if (actionCandidates.length > 1) {
143
- const droppedCount = actionCandidates.length - 1;
144
- // eslint-disable-next-line no-console
145
- console.warn(` [${relPath}] Workqueue '${workqueueLabel}' has ${actionCandidates.length} actions; keeping first as 'action' and dropping ${droppedCount} extra action(s)`);
146
- }
147
- const conditionalsProperty = actionCandidates[0].getProperty(CONDITIONALS_PROPERTY_NAME);
148
- if (conditionalsProperty) {
149
- conditionalsProperty.remove();
150
- // eslint-disable-next-line no-console
151
- console.log(` [${relPath}] Removed deprecated 'conditionals' from migrated 'action' on workqueue '${workqueueLabel}'`);
152
210
  }
153
- if (isUnsupportedActionType(actionCandidates[0])) {
154
- actionsProperty.remove();
155
- // eslint-disable-next-line no-console
156
- console.log(` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' because action type is unsupported`);
157
- return 1;
211
+ // Always ensure the workqueue ends up with a valid `action`. This both
212
+ // covers workqueues that never had an `actions` array, and patches up
213
+ // workqueues whose existing/migrated action type is unsupported.
214
+ const fallback = ensureValidAction(workqueue, relPath);
215
+ return {
216
+ changed: actionsArrayMigrated || fallback.changed,
217
+ usedReadFallback: fallback.usedReadFallback
218
+ };
219
+ }
220
+ /**
221
+ * Ensures `import { ActionType } from '@opencrvs/toolkit/events'` exists in
222
+ * the source file, merging into any existing import declaration from the
223
+ * same module specifier.
224
+ */
225
+ function ensureActionTypeImport(sourceFile) {
226
+ const existingImport = sourceFile.getImportDeclaration((decl) => decl.getModuleSpecifierValue() === TOOLKIT_EVENTS_MODULE);
227
+ if (existingImport) {
228
+ const alreadyImported = existingImport
229
+ .getNamedImports()
230
+ .some((ni) => ni.getName() === ACTION_TYPE_IMPORT_NAME);
231
+ if (!alreadyImported) {
232
+ existingImport.addNamedImport(ACTION_TYPE_IMPORT_NAME);
233
+ }
234
+ return;
158
235
  }
159
- const firstActionText = actionCandidates[0].getText();
160
- workqueue.addPropertyAssignment({
161
- name: ACTION_PROPERTY_NAME,
162
- initializer: firstActionText
236
+ sourceFile.addImportDeclaration({
237
+ moduleSpecifier: TOOLKIT_EVENTS_MODULE,
238
+ namedImports: [ACTION_TYPE_IMPORT_NAME]
163
239
  });
164
- actionsProperty.remove();
165
- // eslint-disable-next-line no-console
166
- console.log(` [${relPath}] Replaced 'actions' with 'action' on workqueue '${workqueueLabel}'`);
167
- return 1;
168
240
  }
169
241
  function processFile(filePath, project) {
170
242
  const sourceFile = project.getSourceFile(filePath);
171
243
  if (!sourceFile)
172
244
  return 0;
173
245
  let migratedWorkqueues = 0;
174
- const relPath = path_1.default.relative((0, _1.getCwd)(), filePath);
246
+ let needsActionTypeImport = false;
247
+ const relPath = path_1.default.relative(process.cwd(), filePath);
175
248
  const callExpressions = sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.CallExpression);
176
249
  for (const call of callExpressions) {
177
250
  const expression = call.getExpression();
@@ -188,14 +261,21 @@ function processFile(filePath, project) {
188
261
  for (const element of workqueuesArg.getElements()) {
189
262
  if (!ts_morph_1.Node.isObjectLiteralExpression(element))
190
263
  continue;
191
- migratedWorkqueues += migrateWorkqueueActions(element, relPath);
264
+ const result = migrateWorkqueueActions(element, relPath);
265
+ if (result.changed)
266
+ migratedWorkqueues++;
267
+ if (result.usedReadFallback)
268
+ needsActionTypeImport = true;
192
269
  }
193
270
  }
271
+ if (needsActionTypeImport) {
272
+ ensureActionTypeImport(sourceFile);
273
+ }
194
274
  return migratedWorkqueues;
195
275
  }
196
276
  function main() {
197
277
  return __awaiter(this, void 0, void 0, function* () {
198
- const srcDir = path_1.default.join((0, _1.getCwd)(), 'src');
278
+ const srcDir = path_1.default.join(process.cwd(), 'src');
199
279
  // eslint-disable-next-line no-console
200
280
  console.log(`Scanning for defineWorkqueues calls in: ${srcDir}\n`);
201
281
  const project = new ts_morph_1.Project({
@@ -229,7 +309,7 @@ function main() {
229
309
  const sourceFile = project.getSourceFileOrThrow(filePath);
230
310
  yield sourceFile.save();
231
311
  // eslint-disable-next-line no-console
232
- console.log(` Saved: ${path_1.default.relative((0, _1.getCwd)(), filePath)}`);
312
+ console.log(` Saved: ${path_1.default.relative(process.cwd(), filePath)}`);
233
313
  }
234
314
  // eslint-disable-next-line no-console
235
315
  console.log(`\nDone. Migrated ${totalMigrated} deprecated workqueue 'actions' definition(s) to 'action'.`);
@@ -1 +1 @@
1
- {"version":3,"file":"remove-delete-actions.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/remove-delete-actions.ts"],"names":[],"mappings":"AA2IA,iBAAe,IAAI,kBAiDlB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
1
+ {"version":3,"file":"remove-delete-actions.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/remove-delete-actions.ts"],"names":[],"mappings":"AAyIA,iBAAe,IAAI,kBAiDlB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
@@ -39,7 +39,6 @@ exports.main = main;
39
39
  */
40
40
  const ts_morph_1 = require("ts-morph");
41
41
  const path_1 = __importDefault(require("path"));
42
- const _1 = require(".");
43
42
  const DEFINE_CONFIG_NAME = 'defineConfig';
44
43
  const ACTIONS_PROPERTY_NAME = 'actions';
45
44
  const TYPE_PROPERTY_NAME = 'type';
@@ -112,14 +111,14 @@ function processFile(filePath, project) {
112
111
  for (const index of indicesToRemove.reverse()) {
113
112
  actionsInitializer.removeElement(index);
114
113
  removedCount++;
115
- console.log(` [${path_1.default.relative((0, _1.getCwd)(), filePath)}] Removed DELETE action at index ${index}`);
114
+ console.log(` [${path_1.default.relative(process.cwd(), filePath)}] Removed DELETE action at index ${index}`);
116
115
  }
117
116
  }
118
117
  return removedCount;
119
118
  }
120
119
  function main() {
121
120
  return __awaiter(this, void 0, void 0, function* () {
122
- const srcDir = path_1.default.join((0, _1.getCwd)(), 'src');
121
+ const srcDir = path_1.default.join(process.cwd(), 'src');
123
122
  console.log(`Scanning for defineConfig calls in: ${srcDir}\n`);
124
123
  const project = new ts_morph_1.Project({
125
124
  tsConfigFilePath: path_1.default.resolve(srcDir, '../tsconfig.json'),
@@ -150,7 +149,7 @@ function main() {
150
149
  for (const filePath of modifiedFiles) {
151
150
  const sourceFile = project.getSourceFileOrThrow(filePath);
152
151
  yield sourceFile.save();
153
- console.log(` Saved: ${path_1.default.relative((0, _1.getCwd)(), filePath)}`);
152
+ console.log(` Saved: ${path_1.default.relative(process.cwd(), filePath)}`);
154
153
  }
155
154
  console.log(`\nDone. Removed ${totalRemoved} DELETE action(s) from defineConfig call(s).`);
156
155
  });
@@ -1 +1 @@
1
- {"version":3,"file":"remove-demo-scope.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/remove-demo-scope.ts"],"names":[],"mappings":"AAiBA,iBAAe,IAAI,kBA8DlB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
1
+ {"version":3,"file":"remove-demo-scope.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/remove-demo-scope.ts"],"names":[],"mappings":"AAeA,iBAAe,IAAI,kBA8DlB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
@@ -25,14 +25,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
25
25
  exports.main = main;
26
26
  const path_1 = __importDefault(require("path"));
27
27
  const ts_morph_1 = require("ts-morph");
28
- const _1 = require(".");
29
28
  const ROLES_HANDLER_RELATIVE_PATH = 'src/data-seeding/roles/handler.ts';
30
29
  function main() {
31
30
  return __awaiter(this, void 0, void 0, function* () {
32
31
  var _a;
33
- const rolesHandlerPath = path_1.default.join((0, _1.getCwd)(), ROLES_HANDLER_RELATIVE_PATH);
32
+ const rolesHandlerPath = path_1.default.join(process.cwd(), ROLES_HANDLER_RELATIVE_PATH);
34
33
  const project = new ts_morph_1.Project({
35
- tsConfigFilePath: path_1.default.resolve((0, _1.getCwd)(), 'tsconfig.json'),
34
+ tsConfigFilePath: path_1.default.resolve(process.cwd(), 'tsconfig.json'),
36
35
  skipAddingFilesFromTsConfig: false
37
36
  });
38
37
  const sourceFile = project.getSourceFile(rolesHandlerPath);
@@ -1 +1 @@
1
- {"version":3,"file":"remove-deprecated-imports.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/remove-deprecated-imports.ts"],"names":[],"mappings":"AA2DA,iBAAe,IAAI,kBAyClB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
1
+ {"version":3,"file":"remove-deprecated-imports.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/remove-deprecated-imports.ts"],"names":[],"mappings":"AAyDA,iBAAe,IAAI,kBAyClB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
@@ -25,7 +25,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
25
25
  exports.main = main;
26
26
  const ts_morph_1 = require("ts-morph");
27
27
  const path_1 = __importDefault(require("path"));
28
- const _1 = require(".");
29
28
  const DEPRECATED_IMPORT = 'SCOPES';
30
29
  const TARGET_MODULES = new Set([
31
30
  '@opencrvs/toolkit/scopes',
@@ -56,13 +55,13 @@ function processFile(filePath, project) {
56
55
  if (!hasAnyNamedImportsLeft && !hasDefaultImport && !hasNamespaceImport) {
57
56
  decl.remove();
58
57
  }
59
- console.log(` [${path_1.default.relative((0, _1.getCwd)(), filePath)}] Removed ${matchingNamedImports.length} deprecated '${DEPRECATED_IMPORT}' import(s) from '${decl.getModuleSpecifierValue()}'`);
58
+ console.log(` [${path_1.default.relative(process.cwd(), filePath)}] Removed ${matchingNamedImports.length} deprecated '${DEPRECATED_IMPORT}' import(s) from '${decl.getModuleSpecifierValue()}'`);
60
59
  }
61
60
  return removedCount;
62
61
  }
63
62
  function main() {
64
63
  return __awaiter(this, void 0, void 0, function* () {
65
- const srcDir = path_1.default.join((0, _1.getCwd)(), 'src');
64
+ const srcDir = path_1.default.join(process.cwd(), 'src');
66
65
  console.log(`Scanning for deprecated imports in: ${srcDir}\n`);
67
66
  const project = new ts_morph_1.Project({
68
67
  tsConfigFilePath: path_1.default.resolve(srcDir, '../tsconfig.json'),
@@ -90,7 +89,7 @@ function main() {
90
89
  console.log(`\nSaving ${modifiedFiles.length} modified file(s)...`);
91
90
  for (const filePath of modifiedFiles) {
92
91
  yield project.getSourceFileOrThrow(filePath).save();
93
- console.log(` Saved: ${path_1.default.relative((0, _1.getCwd)(), filePath)}`);
92
+ console.log(` Saved: ${path_1.default.relative(process.cwd(), filePath)}`);
94
93
  }
95
94
  console.log(`\nDone. Removed ${totalRemoved} deprecated import(s).`);
96
95
  });
@@ -0,0 +1,3 @@
1
+ declare function main(): Promise<void>;
2
+ export { main };
3
+ //# sourceMappingURL=remove-fhir-url-helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remove-fhir-url-helpers.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/remove-fhir-url-helpers.ts"],"names":[],"mappings":"AAiHA,iBAAe,IAAI,kBAyElB;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 legacy FHIR URL helpers after `FHIR_URL` env cleanup.
28
+ *
29
+ * Targets:
30
+ * - `FHIR_URL` named imports
31
+ * - functions: `getFromFhir`, `updateResourceFromHearth`, `updateResourceInHearth`
32
+ *
33
+ * What it does:
34
+ * 1. Removes top-level declarations with one of the helper names.
35
+ * Supported declaration forms:
36
+ * - `function getFromFhir(...) {}`
37
+ * - `const getFromFhir = (...) => {}`
38
+ * - `export const getFromFhir = (...) => {}`
39
+ * 2. Removes `FHIR_URL` named imports from any import declaration.
40
+ * Empty import declarations are dropped.
41
+ * 3. Reports any remaining `FHIR_URL` identifier references so developers
42
+ * can manually clean up unusual patterns.
43
+ */
44
+ const path_1 = __importDefault(require("path"));
45
+ const ts_morph_1 = require("ts-morph");
46
+ const FHIR_IMPORT = 'FHIR_URL';
47
+ const HELPER_NAMES = new Set([
48
+ 'getFromFhir',
49
+ 'updateResourceFromHearth',
50
+ 'updateResourceInHearth'
51
+ ]);
52
+ function removeHelpers(sourceFilePath, project) {
53
+ const sourceFile = project.getSourceFile(sourceFilePath);
54
+ if (!sourceFile) {
55
+ return {
56
+ removedHelpers: [],
57
+ removedImportCount: 0,
58
+ remainingFhirReferences: 0
59
+ };
60
+ }
61
+ const removedHelpers = [];
62
+ let removedImportCount = 0;
63
+ // Function declarations: `function getFromFhir(...) { ... }`
64
+ for (const fn of sourceFile.getFunctions()) {
65
+ const name = fn.getName();
66
+ if (!name || !HELPER_NAMES.has(name))
67
+ continue;
68
+ removedHelpers.push(name);
69
+ fn.remove();
70
+ }
71
+ // Variable declarations: `const getFromFhir = ...`
72
+ for (const stmt of [...sourceFile.getVariableStatements()]) {
73
+ const declarations = [...stmt.getDeclarations()];
74
+ const toRemove = declarations.filter((decl) => HELPER_NAMES.has(decl.getName()));
75
+ if (toRemove.length === 0)
76
+ continue;
77
+ removedHelpers.push(...toRemove.map((decl) => decl.getName()));
78
+ if (toRemove.length === declarations.length) {
79
+ stmt.remove();
80
+ }
81
+ else {
82
+ for (const decl of toRemove)
83
+ decl.remove();
84
+ }
85
+ }
86
+ // Remove FHIR_URL named imports.
87
+ for (const decl of sourceFile.getImportDeclarations()) {
88
+ const matches = decl
89
+ .getNamedImports()
90
+ .filter((ni) => ni.getName() === FHIR_IMPORT);
91
+ if (matches.length === 0)
92
+ continue;
93
+ for (const named of matches) {
94
+ named.remove();
95
+ removedImportCount++;
96
+ }
97
+ const hasAnyNamedImportsLeft = decl.getNamedImports().length > 0;
98
+ const hasDefaultImport = !!decl.getDefaultImport();
99
+ const hasNamespaceImport = !!decl.getNamespaceImport();
100
+ if (!hasAnyNamedImportsLeft && !hasDefaultImport && !hasNamespaceImport) {
101
+ decl.remove();
102
+ }
103
+ }
104
+ const remainingFhirReferences = sourceFile
105
+ .getDescendantsOfKind(ts_morph_1.SyntaxKind.Identifier)
106
+ .filter((id) => id.getText() === FHIR_IMPORT)
107
+ .filter((id) => !id.getFirstAncestorByKind(ts_morph_1.SyntaxKind.ImportDeclaration))
108
+ .length;
109
+ return { removedHelpers, removedImportCount, remainingFhirReferences };
110
+ }
111
+ function main() {
112
+ return __awaiter(this, void 0, void 0, function* () {
113
+ const project = new ts_morph_1.Project({
114
+ tsConfigFilePath: path_1.default.resolve(process.cwd(), 'tsconfig.json'),
115
+ skipAddingFilesFromTsConfig: false
116
+ });
117
+ const sourceFiles = project.getSourceFiles().filter((sf) => {
118
+ const fp = sf.getFilePath();
119
+ return fp.includes('/src/') && !fp.includes('/node_modules/');
120
+ });
121
+ console.log(`Removing legacy FHIR_URL helpers in ${sourceFiles.length} source file(s)...\n`);
122
+ let totalRemovedImports = 0;
123
+ let totalRemovedHelpers = 0;
124
+ const modifiedFiles = [];
125
+ const warnings = [];
126
+ for (const sourceFile of sourceFiles) {
127
+ const filePath = sourceFile.getFilePath();
128
+ const rel = path_1.default.relative(process.cwd(), filePath);
129
+ const result = removeHelpers(filePath, project);
130
+ const changed = result.removedImportCount > 0 || result.removedHelpers.length > 0;
131
+ if (changed) {
132
+ modifiedFiles.push(filePath);
133
+ totalRemovedImports += result.removedImportCount;
134
+ totalRemovedHelpers += result.removedHelpers.length;
135
+ if (result.removedHelpers.length > 0) {
136
+ console.log(` [${rel}] Removed helper(s): ${result.removedHelpers.join(', ')}`);
137
+ }
138
+ if (result.removedImportCount > 0) {
139
+ console.log(` [${rel}] Removed ${result.removedImportCount} '${FHIR_IMPORT}' import(s)`);
140
+ }
141
+ }
142
+ if (result.remainingFhirReferences > 0) {
143
+ warnings.push(`${rel}: ${result.remainingFhirReferences} remaining '${FHIR_IMPORT}' reference(s)`);
144
+ }
145
+ }
146
+ if (modifiedFiles.length === 0 && warnings.length === 0) {
147
+ console.log('No FHIR_URL imports/helpers found. Nothing to do.');
148
+ return;
149
+ }
150
+ if (modifiedFiles.length > 0) {
151
+ console.log(`\nSaving ${modifiedFiles.length} modified file(s)...`);
152
+ for (const filePath of modifiedFiles) {
153
+ yield project.getSourceFileOrThrow(filePath).save();
154
+ console.log(` Saved: ${path_1.default.relative(process.cwd(), filePath)}`);
155
+ }
156
+ }
157
+ if (warnings.length > 0) {
158
+ console.warn(`\n WARNING: Some '${FHIR_IMPORT}' usages remain and need manual cleanup:\n` +
159
+ warnings.map((line) => ` - ${line}`).join('\n'));
160
+ }
161
+ console.log(`\nDone. Removed ${totalRemovedHelpers} helper declaration(s) and ${totalRemovedImports} '${FHIR_IMPORT}' import(s).`);
162
+ });
163
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"remove-hearth-migrations.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/remove-hearth-migrations.ts"],"names":[],"mappings":"AA2BA,iBAAe,IAAI,kBAalB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
1
+ {"version":3,"file":"remove-hearth-migrations.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/remove-hearth-migrations.ts"],"names":[],"mappings":"AAyBA,iBAAe,IAAI,kBAalB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
@@ -48,7 +48,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
48
48
  exports.main = main;
49
49
  const fs = __importStar(require("fs"));
50
50
  const path_1 = __importDefault(require("path"));
51
- const _1 = require(".");
52
51
  const PATHS_TO_REMOVE = [
53
52
  {
54
53
  relativePath: 'src/migrations/hearth',
@@ -63,7 +62,7 @@ const PATHS_TO_REMOVE = [
63
62
  function main() {
64
63
  return __awaiter(this, void 0, void 0, function* () {
65
64
  for (const { relativePath, label } of PATHS_TO_REMOVE) {
66
- const absolutePath = path_1.default.join((0, _1.getCwd)(), relativePath);
65
+ const absolutePath = path_1.default.join(process.cwd(), relativePath);
67
66
  if (fs.existsSync(absolutePath)) {
68
67
  fs.rmSync(absolutePath, { recursive: true, force: true });
69
68
  // eslint-disable-next-line no-console
@@ -0,0 +1,3 @@
1
+ declare function main(): Promise<void>;
2
+ export { main };
3
+ //# sourceMappingURL=remove-old-statistics-service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remove-old-statistics-service.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/remove-old-statistics-service.ts"],"names":[],"mappings":"AAuUA,iBAAe,IAAI,kBA4FlB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}