@opencrvs/toolkit 2.1.0-rc.0ec4a9a → 2.1.0-rc.14fb6a5

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 (244) hide show
  1. package/README.md +3 -12
  2. package/build.sh +22 -4
  3. package/create-countryconfig/index.js +441 -59
  4. package/create-countryconfig/node_modules/.bin/degit +21 -0
  5. package/create-countryconfig/package.json +4 -1
  6. package/dist/application-config/index.js +362 -284
  7. package/dist/authentication/index.d.ts +66 -0
  8. package/dist/authentication/index.d.ts.map +1 -0
  9. package/dist/authentication/index.js +765 -0
  10. package/dist/cli.js +3751 -1232
  11. package/dist/commons/api/router.d.ts +940 -366
  12. package/dist/commons/application-config/index.d.ts +0 -2
  13. package/dist/commons/conditionals/conditionals.d.ts +6 -6
  14. package/dist/commons/conditionals/validate.d.ts +34 -8
  15. package/dist/commons/events/ActionConfig.d.ts +5 -14
  16. package/dist/commons/events/ActionDocument.d.ts +35 -15
  17. package/dist/commons/events/ActionInput.d.ts +4 -4
  18. package/dist/commons/events/ActionStatus.d.ts +14 -0
  19. package/dist/commons/events/AdvancedSearchConfig.d.ts +48 -12
  20. package/dist/commons/events/AuditLog.d.ts +148 -0
  21. package/dist/commons/events/Draft.d.ts +1 -21
  22. package/dist/commons/events/EventConfig.d.ts +3 -0
  23. package/dist/commons/events/EventDocument.d.ts +472 -4
  24. package/dist/commons/events/EventIndex.d.ts +3 -26
  25. package/dist/commons/events/EventMetadata.d.ts +1 -11
  26. package/dist/commons/events/EventStatus.d.ts +19 -0
  27. package/dist/commons/events/FieldConfig.d.ts +109 -63
  28. package/dist/commons/events/FieldTypeMapping.d.ts +17 -17
  29. package/dist/commons/events/FieldValue.d.ts +3 -2
  30. package/dist/commons/events/Flag.d.ts +42 -0
  31. package/dist/commons/events/FormConfig.d.ts +6 -0
  32. package/dist/commons/events/PageConfig.d.ts +4 -0
  33. package/dist/commons/events/PlainDate.d.ts +8 -0
  34. package/dist/commons/events/SummaryConfig.d.ts +249 -0
  35. package/dist/commons/events/WorkqueueConfig.d.ts +17 -14
  36. package/dist/commons/events/event.d.ts +12 -0
  37. package/dist/commons/events/index.d.ts +1 -0
  38. package/dist/commons/events/locationPayloads.d.ts +95 -0
  39. package/dist/commons/events/locations.d.ts +169 -29
  40. package/dist/commons/events/mocks.test.utils.d.ts +30 -2
  41. package/dist/commons/events/scopes.d.ts +21 -1
  42. package/dist/commons/events/test.utils.d.ts +78 -25
  43. package/dist/commons/events/utils.d.ts +39 -4
  44. package/dist/commons/notification/UserNotifications.d.ts +28 -13
  45. package/dist/commons/notification/dispatch.d.ts +10 -0
  46. package/dist/commons/notification/index.d.ts +1 -0
  47. package/dist/conditionals/index.js +349 -65
  48. package/dist/csv.d.ts +25 -0
  49. package/dist/csv.d.ts.map +1 -0
  50. package/dist/csv.js +120 -0
  51. package/dist/environment/index.d.ts +1 -0
  52. package/dist/environment/index.d.ts.map +1 -1
  53. package/dist/environment/index.js +12 -1
  54. package/dist/environment/logger.d.ts +15 -3
  55. package/dist/environment/logger.d.ts.map +1 -1
  56. package/dist/environment/manage-users.js +1 -1
  57. package/dist/environment/paths.d.ts +7 -0
  58. package/dist/environment/paths.d.ts.map +1 -0
  59. package/dist/environment/paths.js +72 -0
  60. package/dist/environment/questions.d.ts.map +1 -1
  61. package/dist/environment/questions.js +20 -14
  62. package/dist/environment/setup-environment.d.ts +1 -1
  63. package/dist/environment/setup-environment.d.ts.map +1 -1
  64. package/dist/environment/setup-environment.js +594 -562
  65. package/dist/environment/swarm-to-k8s.js +3 -4
  66. package/dist/environment/templates.d.ts +0 -1
  67. package/dist/environment/templates.d.ts.map +1 -1
  68. package/dist/environment/templates.js +5 -9
  69. package/dist/environment/update-workflows.d.ts.map +1 -1
  70. package/dist/environment/update-workflows.js +21 -5
  71. package/dist/environment/upgrade.d.ts +2 -0
  72. package/dist/environment/upgrade.d.ts.map +1 -0
  73. package/dist/environment/upgrade.js +82 -0
  74. package/dist/environment/users.js +11 -13
  75. package/dist/environment/utils.d.ts +0 -12
  76. package/dist/environment/utils.d.ts.map +1 -1
  77. package/dist/environment/utils.js +1 -28
  78. package/dist/events/index.js +7686 -7063
  79. package/dist/migrations/v2.1/add-recovery-link-notifications.d.ts +3 -0
  80. package/dist/migrations/v2.1/add-recovery-link-notifications.d.ts.map +1 -0
  81. package/dist/migrations/v2.1/add-recovery-link-notifications.js +511 -0
  82. package/dist/migrations/v2.1/add-translations.d.ts +9 -0
  83. package/dist/migrations/v2.1/add-translations.d.ts.map +1 -0
  84. package/dist/migrations/v2.1/add-translations.js +149 -0
  85. package/dist/migrations/{v2.0/rename-api-paths.d.ts → v2.1/enable-telemetry.d.ts} +1 -1
  86. package/dist/migrations/v2.1/enable-telemetry.d.ts.map +1 -0
  87. package/dist/migrations/v2.1/enable-telemetry.js +455 -0
  88. package/dist/migrations/v2.1/index.d.ts.map +1 -1
  89. package/dist/migrations/v2.1/index.js +1952 -0
  90. package/dist/migrations/v2.1/migrate-infrastructure-to-assets.d.ts +14 -0
  91. package/dist/migrations/v2.1/migrate-infrastructure-to-assets.d.ts.map +1 -0
  92. package/dist/migrations/v2.1/migrate-infrastructure-to-assets.js +348 -0
  93. package/dist/migrations/v2.1/remove-metabase-package-installs.d.ts +2 -0
  94. package/dist/migrations/v2.1/remove-metabase-package-installs.d.ts.map +1 -0
  95. package/dist/migrations/v2.1/remove-metabase-package-installs.js +161 -0
  96. package/dist/migrations/{v2.0/migrate-scopes.d.ts → v2.1/remove-sentry.d.ts} +1 -1
  97. package/dist/migrations/v2.1/remove-sentry.d.ts.map +1 -0
  98. package/dist/migrations/v2.1/remove-sentry.js +354 -0
  99. package/dist/migrations/{v2.0/create-events-index.d.ts → v2.1/rename-trigger-paths.d.ts} +1 -1
  100. package/dist/migrations/v2.1/rename-trigger-paths.d.ts.map +1 -0
  101. package/dist/migrations/{v2.0/rename-api-paths.js → v2.1/rename-trigger-paths.js} +69 -40
  102. package/dist/migrations/v2.1/template-files.d.ts +8 -0
  103. package/dist/migrations/v2.1/template-files.d.ts.map +1 -0
  104. package/dist/migrations/v2.1/template-files.js +49 -0
  105. package/dist/migrations/v2.1/upgrade-tilt.d.ts +8 -0
  106. package/dist/migrations/v2.1/upgrade-tilt.d.ts.map +1 -0
  107. package/dist/migrations/v2.1/upgrade-tilt.js +139 -0
  108. package/dist/notification/index.js +1886 -1440
  109. package/dist/scopes/index.d.ts +614 -36
  110. package/dist/scopes/index.js +351 -65
  111. package/dist/telemetry/index.d.ts +45 -0
  112. package/dist/telemetry/index.d.ts.map +1 -0
  113. package/dist/telemetry/index.js +43 -0
  114. package/dist/templates/charts-values/dependencies/values.yaml +8 -0
  115. package/dist/templates/charts-values/opencrvs-services/values.yaml +10 -3
  116. package/dist/templates/charts-values/opentelemetry/values.yaml +102 -0
  117. package/dist/templates/charts-values/traefik/values.yaml +23 -9
  118. package/dist/templates/countryconfig-template/.tiltignore +1 -0
  119. package/dist/templates/countryconfig-template/Dockerfile.assets +7 -0
  120. package/dist/templates/countryconfig-template/Tiltfile +112 -0
  121. package/dist/templates/countryconfig-template/assets/README.md +1 -0
  122. package/dist/templates/countryconfig-template/assets/clear-all-data-dev.sh +61 -0
  123. package/dist/templates/countryconfig-template/assets/deployment/deploy.sh +455 -0
  124. package/dist/templates/countryconfig-template/assets/deployment/reindex.sh +168 -0
  125. package/dist/templates/countryconfig-template/assets/deployment/validate-required-variables-in-compose-files.ts +67 -0
  126. package/dist/templates/countryconfig-template/assets/elasticsearch/reindex.sh +168 -0
  127. package/dist/templates/countryconfig-template/assets/metabase/README.md +34 -0
  128. package/dist/templates/countryconfig-template/assets/metabase/environment-configuration.sql +36 -0
  129. package/dist/templates/countryconfig-template/assets/metabase/initialize-database.sh +46 -0
  130. package/dist/templates/countryconfig-template/assets/metabase/metabase.init.db.sql +27737 -0
  131. package/dist/templates/countryconfig-template/assets/metabase/open-shell.sh +21 -0
  132. package/dist/templates/countryconfig-template/assets/metabase/package.json +13 -0
  133. package/dist/templates/countryconfig-template/assets/metabase/run-dev.sh +108 -0
  134. package/dist/templates/countryconfig-template/assets/metabase/run.sh +120 -0
  135. package/dist/templates/countryconfig-template/assets/metabase/update-database.sh +40 -0
  136. package/dist/templates/countryconfig-template/assets/postgres/setup-analytics.sh +135 -0
  137. package/dist/templates/countryconfig-template/assets/postgres/setup-reference-data.sh +108 -0
  138. package/dist/templates/countryconfig-template/tilt/clear-all-data.ps1 +50 -0
  139. package/dist/templates/countryconfig-template/tilt/clear-all-data.sh +35 -0
  140. package/dist/templates/countryconfig-template/tilt/common.tilt +145 -0
  141. package/dist/templates/countryconfig-template/tilt/examples/dependencies/values.yaml +15 -0
  142. package/dist/templates/countryconfig-template/tilt/examples/opencrvs-services/values.yaml +56 -0
  143. package/dist/templates/countryconfig-template/tilt/examples/traefik/values-minikube.yaml +21 -0
  144. package/dist/templates/countryconfig-template/tilt/examples/traefik/values.yaml +38 -0
  145. package/dist/templates/countryconfig-template/tilt/helm/dependencies/values.yaml +17 -0
  146. package/dist/templates/countryconfig-template/tilt/helm/opencrvs-services/values.yaml +16 -0
  147. package/dist/templates/countryconfig-template/tilt/lib.tilt +95 -0
  148. package/dist/templates/countryconfig-template/tilt/opencrvs.tilt +136 -0
  149. package/dist/templates/inventory/inventory.template.yml +1 -3
  150. package/dist/translations/template.d.ts +11 -0
  151. package/dist/translations/template.d.ts.map +1 -0
  152. package/dist/translations/template.js +100 -0
  153. package/dist/verify/endpoints.d.ts +2 -0
  154. package/dist/verify/endpoints.d.ts.map +1 -0
  155. package/dist/verify/endpoints.js +510 -0
  156. package/opencrvs-toolkit-2.1.0-rc.14fb6a5.tgz +0 -0
  157. package/package.json +13 -6
  158. package/tsconfig.build.json +11 -0
  159. package/tsconfig.build.tsbuildinfo +1 -0
  160. package/tsconfig.json +3 -0
  161. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts +0 -3
  162. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts.map +0 -1
  163. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.js +0 -429
  164. package/dist/migrations/v2.0/add-resend-invite-notification.d.ts +0 -3
  165. package/dist/migrations/v2.0/add-resend-invite-notification.d.ts.map +0 -1
  166. package/dist/migrations/v2.0/add-resend-invite-notification.js +0 -373
  167. package/dist/migrations/v2.0/checkout-upstream-files.d.ts +0 -22
  168. package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +0 -1
  169. package/dist/migrations/v2.0/checkout-upstream-files.js +0 -146
  170. package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts +0 -2
  171. package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts.map +0 -1
  172. package/dist/migrations/v2.0/convert-config-files-to-ts.js +0 -838
  173. package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts +0 -3
  174. package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts.map +0 -1
  175. package/dist/migrations/v2.0/convert-paragraph-to-heading.js +0 -158
  176. package/dist/migrations/v2.0/create-events-index.d.ts.map +0 -1
  177. package/dist/migrations/v2.0/create-events-index.js +0 -325
  178. package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts +0 -11
  179. package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts.map +0 -1
  180. package/dist/migrations/v2.0/delete-infrastructure-directory.js +0 -123
  181. package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.d.ts +0 -3
  182. package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.d.ts.map +0 -1
  183. package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.js +0 -110
  184. package/dist/migrations/v2.0/index.d.ts +0 -13
  185. package/dist/migrations/v2.0/index.d.ts.map +0 -1
  186. package/dist/migrations/v2.0/index.js +0 -103
  187. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts +0 -3
  188. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts.map +0 -1
  189. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.js +0 -432
  190. package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts +0 -13
  191. package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts.map +0 -1
  192. package/dist/migrations/v2.0/merge-infrastructure-directory.js +0 -222
  193. package/dist/migrations/v2.0/migrate-application-config-url.d.ts +0 -3
  194. package/dist/migrations/v2.0/migrate-application-config-url.d.ts.map +0 -1
  195. package/dist/migrations/v2.0/migrate-application-config-url.js +0 -343
  196. package/dist/migrations/v2.0/migrate-scopes.d.ts.map +0 -1
  197. package/dist/migrations/v2.0/migrate-scopes.js +0 -305
  198. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts +0 -3
  199. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts.map +0 -1
  200. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.js +0 -267
  201. package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts +0 -3
  202. package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts.map +0 -1
  203. package/dist/migrations/v2.0/migrate-workqueue-configs.js +0 -317
  204. package/dist/migrations/v2.0/remove-delete-actions.d.ts +0 -3
  205. package/dist/migrations/v2.0/remove-delete-actions.d.ts.map +0 -1
  206. package/dist/migrations/v2.0/remove-delete-actions.js +0 -156
  207. package/dist/migrations/v2.0/remove-demo-scope.d.ts +0 -3
  208. package/dist/migrations/v2.0/remove-demo-scope.d.ts.map +0 -1
  209. package/dist/migrations/v2.0/remove-demo-scope.js +0 -74
  210. package/dist/migrations/v2.0/remove-deprecated-imports.d.ts +0 -3
  211. package/dist/migrations/v2.0/remove-deprecated-imports.d.ts.map +0 -1
  212. package/dist/migrations/v2.0/remove-deprecated-imports.js +0 -96
  213. package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts +0 -3
  214. package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts.map +0 -1
  215. package/dist/migrations/v2.0/remove-fhir-url-helpers.js +0 -163
  216. package/dist/migrations/v2.0/remove-hearth-migrations.d.ts +0 -3
  217. package/dist/migrations/v2.0/remove-hearth-migrations.d.ts.map +0 -1
  218. package/dist/migrations/v2.0/remove-hearth-migrations.js +0 -87
  219. package/dist/migrations/v2.0/remove-old-statistics-service.d.ts +0 -3
  220. package/dist/migrations/v2.0/remove-old-statistics-service.d.ts.map +0 -1
  221. package/dist/migrations/v2.0/remove-old-statistics-service.js +0 -356
  222. package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts +0 -3
  223. package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts.map +0 -1
  224. package/dist/migrations/v2.0/remove-pending-certification-flag.js +0 -109
  225. package/dist/migrations/v2.0/remove-review-from-register-action.d.ts +0 -3
  226. package/dist/migrations/v2.0/remove-review-from-register-action.d.ts.map +0 -1
  227. package/dist/migrations/v2.0/remove-review-from-register-action.js +0 -163
  228. package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts +0 -3
  229. package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts.map +0 -1
  230. package/dist/migrations/v2.0/remove-unused-environment-variables.js +0 -186
  231. package/dist/migrations/v2.0/rename-api-paths.d.ts.map +0 -1
  232. package/dist/migrations/v2.0/rename-location-parent-id.d.ts +0 -3
  233. package/dist/migrations/v2.0/rename-location-parent-id.d.ts.map +0 -1
  234. package/dist/migrations/v2.0/rename-location-parent-id.js +0 -180
  235. package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts +0 -3
  236. package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts.map +0 -1
  237. package/dist/migrations/v2.0/simplify-analytics-precalculations.js +0 -195
  238. package/dist/migrations/v2.0/update-package-json.d.ts +0 -3
  239. package/dist/migrations/v2.0/update-package-json.d.ts.map +0 -1
  240. package/dist/migrations/v2.0/update-package-json.js +0 -105
  241. package/dist/templates/inventory/production.example.yml +0 -77
  242. package/dist/templates/inventory/qa.example.yml +0 -48
  243. package/opencrvs-toolkit-2.1.0-rc.0ec4a9a.tgz +0 -0
  244. package/tsconfig.tsbuildinfo +0 -1
@@ -1,317 +0,0 @@
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: migrate deprecated workqueue `actions` array to singular `action`.
28
- *
29
- * Usage:
30
- * ts-node -r tsconfig-paths/register src/migrations/v2.0/migrate-workqueue-configs.ts
31
- *
32
- * What it does:
33
- * - Scans TypeScript files under `src/`
34
- * - Finds `defineWorkqueues([...])` calls
35
- * - For each workqueue object:
36
- * - `actions: []` -> removes `actions`
37
- * - `actions: [{ ... }]` -> replaces with `action: { ... }` if type is supported
38
- * - `actions: [{ type: 'DEFAULT' }]` -> removes `actions` and does not create `action`
39
- * - `actions: [{...}, {...}, ...]` -> keeps first as `action`, warns about dropped extras
40
- * - If `action` already exists, removes deprecated `actions` and keeps `action`
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.
46
- * - Saves modified files in-place
47
- */
48
- const ts_morph_1 = require("ts-morph");
49
- const path_1 = __importDefault(require("path"));
50
- const DEFINE_WORKQUEUES_NAME = 'defineWorkqueues';
51
- const ACTIONS_PROPERTY_NAME = 'actions';
52
- const ACTION_PROPERTY_NAME = 'action';
53
- const CONDITIONALS_PROPERTY_NAME = 'conditionals';
54
- const TYPE_PROPERTY_NAME = 'type';
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} }`;
60
- const SUPPORTED_WORKQUEUE_ACTION_TYPES = new Set([
61
- 'READ',
62
- 'DELETE',
63
- 'DECLARE',
64
- 'REGISTER',
65
- 'EDIT',
66
- 'REJECT',
67
- 'MARK_AS_DUPLICATE',
68
- 'ARCHIVE',
69
- 'PRINT_CERTIFICATE',
70
- 'REQUEST_CORRECTION'
71
- ]);
72
- function getWorkqueueLabel(workqueue) {
73
- const slugProperty = workqueue.getProperty(SLUG_PROPERTY_NAME);
74
- if (!slugProperty || !ts_morph_1.Node.isPropertyAssignment(slugProperty)) {
75
- return '(unknown slug)';
76
- }
77
- const slugInitializer = slugProperty.getInitializer();
78
- if (!slugInitializer || !ts_morph_1.Node.isStringLiteral(slugInitializer)) {
79
- return '(unknown slug)';
80
- }
81
- return slugInitializer.getLiteralValue();
82
- }
83
- function getActionTypeName(action) {
84
- const typeProperty = action.getProperty(TYPE_PROPERTY_NAME);
85
- if (!typeProperty || !ts_morph_1.Node.isPropertyAssignment(typeProperty)) {
86
- return null;
87
- }
88
- const typeInitializer = typeProperty.getInitializer();
89
- if (!typeInitializer) {
90
- return null;
91
- }
92
- if (ts_morph_1.Node.isStringLiteral(typeInitializer)) {
93
- return typeInitializer.getLiteralValue();
94
- }
95
- if (ts_morph_1.Node.isPropertyAccessExpression(typeInitializer)) {
96
- return typeInitializer.getName();
97
- }
98
- return null;
99
- }
100
- function isUnsupportedActionType(action) {
101
- const typeName = getActionTypeName(action);
102
- if (!typeName) {
103
- return false;
104
- }
105
- return !SUPPORTED_WORKQUEUE_ACTION_TYPES.has(typeName);
106
- }
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
- }
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) {
142
- const workqueueLabel = getWorkqueueLabel(workqueue);
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
- }
162
- }
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();
174
- // eslint-disable-next-line no-console
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
- }
207
- }
208
- }
209
- }
210
- }
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;
235
- }
236
- sourceFile.addImportDeclaration({
237
- moduleSpecifier: TOOLKIT_EVENTS_MODULE,
238
- namedImports: [ACTION_TYPE_IMPORT_NAME]
239
- });
240
- }
241
- function processFile(filePath, project) {
242
- const sourceFile = project.getSourceFile(filePath);
243
- if (!sourceFile)
244
- return 0;
245
- let migratedWorkqueues = 0;
246
- let needsActionTypeImport = false;
247
- const relPath = path_1.default.relative(process.cwd(), filePath);
248
- const callExpressions = sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.CallExpression);
249
- for (const call of callExpressions) {
250
- const expression = call.getExpression();
251
- if (!ts_morph_1.Node.isIdentifier(expression) ||
252
- expression.getText() !== DEFINE_WORKQUEUES_NAME) {
253
- continue;
254
- }
255
- const args = call.getArguments();
256
- if (args.length === 0)
257
- continue;
258
- const workqueuesArg = args[0];
259
- if (!ts_morph_1.Node.isArrayLiteralExpression(workqueuesArg))
260
- continue;
261
- for (const element of workqueuesArg.getElements()) {
262
- if (!ts_morph_1.Node.isObjectLiteralExpression(element))
263
- continue;
264
- const result = migrateWorkqueueActions(element, relPath);
265
- if (result.changed)
266
- migratedWorkqueues++;
267
- if (result.usedReadFallback)
268
- needsActionTypeImport = true;
269
- }
270
- }
271
- if (needsActionTypeImport) {
272
- ensureActionTypeImport(sourceFile);
273
- }
274
- return migratedWorkqueues;
275
- }
276
- function main() {
277
- return __awaiter(this, void 0, void 0, function* () {
278
- const srcDir = path_1.default.join(process.cwd(), 'src');
279
- // eslint-disable-next-line no-console
280
- console.log(`Scanning for defineWorkqueues calls in: ${srcDir}\n`);
281
- const project = new ts_morph_1.Project({
282
- tsConfigFilePath: path_1.default.resolve(srcDir, '../tsconfig.json'),
283
- skipAddingFilesFromTsConfig: false
284
- });
285
- const sourceFiles = project.getSourceFiles().filter((sf) => {
286
- const fp = sf.getFilePath();
287
- return fp.includes('/src/') && !fp.includes('/node_modules/');
288
- });
289
- // eslint-disable-next-line no-console
290
- console.log(`Found ${sourceFiles.length} source file(s) to analyse.\n`);
291
- let totalMigrated = 0;
292
- const modifiedFiles = [];
293
- for (const sourceFile of sourceFiles) {
294
- const filePath = sourceFile.getFilePath();
295
- const migrated = processFile(filePath, project);
296
- if (migrated > 0) {
297
- totalMigrated += migrated;
298
- modifiedFiles.push(filePath);
299
- }
300
- }
301
- if (modifiedFiles.length === 0) {
302
- // eslint-disable-next-line no-console
303
- console.log("No deprecated workqueue 'actions' arrays found inside defineWorkqueues calls. Nothing to do.");
304
- return;
305
- }
306
- // eslint-disable-next-line no-console
307
- console.log(`\nSaving ${modifiedFiles.length} modified file(s)...`);
308
- for (const filePath of modifiedFiles) {
309
- const sourceFile = project.getSourceFileOrThrow(filePath);
310
- yield sourceFile.save();
311
- // eslint-disable-next-line no-console
312
- console.log(` Saved: ${path_1.default.relative(process.cwd(), filePath)}`);
313
- }
314
- // eslint-disable-next-line no-console
315
- console.log(`\nDone. Migrated ${totalMigrated} deprecated workqueue 'actions' definition(s) to 'action'.`);
316
- });
317
- }
@@ -1,3 +0,0 @@
1
- declare function main(): Promise<void>;
2
- export { main };
3
- //# sourceMappingURL=remove-delete-actions.d.ts.map
@@ -1 +0,0 @@
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"}
@@ -1,156 +0,0 @@
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 `DELETE` type actions from the `actions` array inside `defineConfig` calls.
28
- *
29
- * Usage:
30
- * ts-node -r tsconfig-paths/register src/migrations/v2.0/remove-delete-actions.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.DELETE` or the string literal `"DELETE"`
37
- * - Removes those action objects entirely from the array
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 ACTION_TYPE_ENUM_NAME = 'ActionType';
46
- const DELETE_MEMBER_NAME = 'DELETE';
47
- const DELETE_STRING_LITERAL = 'DELETE';
48
- function isDeleteType(typeInitializer) {
49
- // Matches: ActionType.DELETE
50
- if (typeInitializer.getKind() === ts_morph_1.SyntaxKind.PropertyAccessExpression) {
51
- const propAccess = typeInitializer.asKindOrThrow(ts_morph_1.SyntaxKind.PropertyAccessExpression);
52
- const obj = propAccess.getExpression();
53
- const member = propAccess.getName();
54
- return (ts_morph_1.Node.isIdentifier(obj) &&
55
- obj.getText() === ACTION_TYPE_ENUM_NAME &&
56
- member === DELETE_MEMBER_NAME);
57
- }
58
- // Matches: "DELETE"
59
- if (typeInitializer.getKind() === ts_morph_1.SyntaxKind.StringLiteral) {
60
- return (typeInitializer
61
- .asKindOrThrow(ts_morph_1.SyntaxKind.StringLiteral)
62
- .getLiteralValue() === DELETE_STRING_LITERAL);
63
- }
64
- return false;
65
- }
66
- function isDeleteAction(obj) {
67
- const typeProperty = obj.getProperty(TYPE_PROPERTY_NAME);
68
- if (!typeProperty || !ts_morph_1.Node.isPropertyAssignment(typeProperty)) {
69
- return false;
70
- }
71
- const typeInitializer = typeProperty.getInitializer();
72
- return !!typeInitializer && isDeleteType(typeInitializer);
73
- }
74
- function processFile(filePath, project) {
75
- const sourceFile = project.getSourceFile(filePath);
76
- if (!sourceFile)
77
- return 0;
78
- let removedCount = 0;
79
- // Find all call expressions named `defineConfig`
80
- const callExpressions = sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.CallExpression);
81
- for (const call of callExpressions) {
82
- const expression = call.getExpression();
83
- // Only interested in bare `defineConfig(...)` calls
84
- if (!ts_morph_1.Node.isIdentifier(expression) ||
85
- expression.getText() !== DEFINE_CONFIG_NAME) {
86
- continue;
87
- }
88
- const args = call.getArguments();
89
- if (args.length === 0)
90
- continue;
91
- // The first argument should be the config object literal
92
- const configArg = args[0];
93
- if (!ts_morph_1.Node.isObjectLiteralExpression(configArg))
94
- continue;
95
- // Find the `actions` property inside the config object
96
- const actionsProperty = configArg.getProperty(ACTIONS_PROPERTY_NAME);
97
- if (!actionsProperty || !ts_morph_1.Node.isPropertyAssignment(actionsProperty))
98
- continue;
99
- const actionsInitializer = actionsProperty.getInitializer();
100
- if (!actionsInitializer ||
101
- !ts_morph_1.Node.isArrayLiteralExpression(actionsInitializer))
102
- continue;
103
- // Collect indices of DELETE actions in reverse order so removal doesn't
104
- // shift the indices of elements yet to be processed
105
- const indicesToRemove = [];
106
- actionsInitializer.getElements().forEach((element, index) => {
107
- if (ts_morph_1.Node.isObjectLiteralExpression(element) && isDeleteAction(element)) {
108
- indicesToRemove.push(index);
109
- }
110
- });
111
- for (const index of indicesToRemove.reverse()) {
112
- actionsInitializer.removeElement(index);
113
- removedCount++;
114
- console.log(` [${path_1.default.relative(process.cwd(), filePath)}] Removed DELETE action at index ${index}`);
115
- }
116
- }
117
- return removedCount;
118
- }
119
- function main() {
120
- return __awaiter(this, void 0, void 0, function* () {
121
- const srcDir = path_1.default.join(process.cwd(), 'src');
122
- console.log(`Scanning for defineConfig calls in: ${srcDir}\n`);
123
- const project = new ts_morph_1.Project({
124
- tsConfigFilePath: path_1.default.resolve(srcDir, '../tsconfig.json'),
125
- // Do not emit — we only manipulate source files
126
- skipAddingFilesFromTsConfig: false
127
- });
128
- // Restrict to source files only (exclude node_modules, build artefacts, etc.)
129
- const sourceFiles = project.getSourceFiles().filter((sf) => {
130
- const fp = sf.getFilePath();
131
- return fp.includes('/src/') && !fp.includes('/node_modules/');
132
- });
133
- console.log(`Found ${sourceFiles.length} source file(s) to analyse.\n`);
134
- let totalRemoved = 0;
135
- const modifiedFiles = [];
136
- for (const sourceFile of sourceFiles) {
137
- const filePath = sourceFile.getFilePath();
138
- const removed = processFile(filePath, project);
139
- if (removed > 0) {
140
- totalRemoved += removed;
141
- modifiedFiles.push(filePath);
142
- }
143
- }
144
- if (modifiedFiles.length === 0) {
145
- console.log('No DELETE actions found inside defineConfig calls. Nothing to do.');
146
- return;
147
- }
148
- console.log(`\nSaving ${modifiedFiles.length} modified file(s)...`);
149
- for (const filePath of modifiedFiles) {
150
- const sourceFile = project.getSourceFileOrThrow(filePath);
151
- yield sourceFile.save();
152
- console.log(` Saved: ${path_1.default.relative(process.cwd(), filePath)}`);
153
- }
154
- console.log(`\nDone. Removed ${totalRemoved} DELETE action(s) from defineConfig call(s).`);
155
- });
156
- }
@@ -1,3 +0,0 @@
1
- declare function main(): Promise<void>;
2
- export { main };
3
- //# sourceMappingURL=remove-demo-scope.d.ts.map
@@ -1 +0,0 @@
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"}
@@ -1,74 +0,0 @@
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
- const path_1 = __importDefault(require("path"));
27
- const ts_morph_1 = require("ts-morph");
28
- const ROLES_HANDLER_RELATIVE_PATH = 'src/data-seeding/roles/handler.ts';
29
- function main() {
30
- return __awaiter(this, void 0, void 0, function* () {
31
- var _a;
32
- const rolesHandlerPath = path_1.default.join(process.cwd(), ROLES_HANDLER_RELATIVE_PATH);
33
- const project = new ts_morph_1.Project({
34
- tsConfigFilePath: path_1.default.resolve(process.cwd(), 'tsconfig.json'),
35
- skipAddingFilesFromTsConfig: false
36
- });
37
- const sourceFile = project.getSourceFile(rolesHandlerPath);
38
- if (!sourceFile) {
39
- // eslint-disable-next-line no-console
40
- console.log(`No roles handler found at '${ROLES_HANDLER_RELATIVE_PATH}'. Nothing to do.`);
41
- return;
42
- }
43
- let changed = false;
44
- const constantsImport = sourceFile.getImportDeclaration((decl) => decl.getModuleSpecifierValue() === '@countryconfig/constants');
45
- if (constantsImport) {
46
- constantsImport.remove();
47
- changed = true;
48
- }
49
- const rolesHandler = sourceFile.getFunction('rolesHandler');
50
- if (!rolesHandler) {
51
- // eslint-disable-next-line no-console
52
- console.log(`No rolesHandler export found in '${ROLES_HANDLER_RELATIVE_PATH}'. Nothing to do.`);
53
- return;
54
- }
55
- const secondParam = rolesHandler.getParameters()[1];
56
- const secondParamName = secondParam === null || secondParam === void 0 ? void 0 : secondParam.getName();
57
- const responseToolkitIdentifier = secondParamName || 'h';
58
- const currentBodyText = rolesHandler.getBodyText();
59
- const normalizedCurrent = (_a = currentBodyText === null || currentBodyText === void 0 ? void 0 : currentBodyText.replace(/\s+/g, ' ').trim()) !== null && _a !== void 0 ? _a : '';
60
- const normalizedDesired = `return ${responseToolkitIdentifier}.response(roles)`;
61
- if (normalizedCurrent !== normalizedDesired) {
62
- rolesHandler.setBodyText(`return ${responseToolkitIdentifier}.response(roles)`);
63
- changed = true;
64
- }
65
- if (!changed) {
66
- // eslint-disable-next-line no-console
67
- console.log(`No changes needed in '${ROLES_HANDLER_RELATIVE_PATH}'.`);
68
- return;
69
- }
70
- yield sourceFile.save();
71
- // eslint-disable-next-line no-console
72
- console.log(`Updated '${ROLES_HANDLER_RELATIVE_PATH}' to remove demo scope behavior while preserving file structure.`);
73
- });
74
- }
@@ -1,3 +0,0 @@
1
- declare function main(): Promise<void>;
2
- export { main };
3
- //# sourceMappingURL=remove-deprecated-imports.d.ts.map
@@ -1 +0,0 @@
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"}
@@ -1,96 +0,0 @@
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
- const ts_morph_1 = require("ts-morph");
27
- const path_1 = __importDefault(require("path"));
28
- const DEPRECATED_IMPORT = 'SCOPES';
29
- const TARGET_MODULES = new Set([
30
- '@opencrvs/toolkit/scopes',
31
- '@opencrvs/toolkit'
32
- ]);
33
- function processFile(filePath, project) {
34
- const sourceFile = project.getSourceFile(filePath);
35
- if (!sourceFile)
36
- return 0;
37
- let removedCount = 0;
38
- const importDecls = sourceFile
39
- .getImportDeclarations()
40
- .filter((decl) => TARGET_MODULES.has(decl.getModuleSpecifierValue()));
41
- for (const decl of importDecls) {
42
- const matchingNamedImports = decl
43
- .getNamedImports()
44
- .filter((ni) => ni.getName() === DEPRECATED_IMPORT);
45
- if (matchingNamedImports.length === 0)
46
- continue;
47
- for (const namedImport of matchingNamedImports) {
48
- namedImport.remove();
49
- removedCount++;
50
- }
51
- const hasAnyNamedImportsLeft = decl.getNamedImports().length > 0;
52
- const hasDefaultImport = !!decl.getDefaultImport();
53
- const hasNamespaceImport = !!decl.getNamespaceImport();
54
- // If the declaration only contained SCOPE, remove the now-empty import line.
55
- if (!hasAnyNamedImportsLeft && !hasDefaultImport && !hasNamespaceImport) {
56
- decl.remove();
57
- }
58
- console.log(` [${path_1.default.relative(process.cwd(), filePath)}] Removed ${matchingNamedImports.length} deprecated '${DEPRECATED_IMPORT}' import(s) from '${decl.getModuleSpecifierValue()}'`);
59
- }
60
- return removedCount;
61
- }
62
- function main() {
63
- return __awaiter(this, void 0, void 0, function* () {
64
- const srcDir = path_1.default.join(process.cwd(), 'src');
65
- console.log(`Scanning for deprecated imports in: ${srcDir}\n`);
66
- const project = new ts_morph_1.Project({
67
- tsConfigFilePath: path_1.default.resolve(srcDir, '../tsconfig.json'),
68
- skipAddingFilesFromTsConfig: false
69
- });
70
- const sourceFiles = project.getSourceFiles().filter((sf) => {
71
- const fp = sf.getFilePath();
72
- return fp.includes('/src/') && !fp.includes('/node_modules/');
73
- });
74
- console.log(`Found ${sourceFiles.length} source file(s) to analyse.\n`);
75
- let totalRemoved = 0;
76
- const modifiedFiles = [];
77
- for (const sourceFile of sourceFiles) {
78
- const filePath = sourceFile.getFilePath();
79
- const removed = processFile(filePath, project);
80
- if (removed > 0) {
81
- totalRemoved += removed;
82
- modifiedFiles.push(filePath);
83
- }
84
- }
85
- if (modifiedFiles.length === 0) {
86
- console.log('No deprecated imports found. Nothing to do.');
87
- return;
88
- }
89
- console.log(`\nSaving ${modifiedFiles.length} modified file(s)...`);
90
- for (const filePath of modifiedFiles) {
91
- yield project.getSourceFileOrThrow(filePath).save();
92
- console.log(` Saved: ${path_1.default.relative(process.cwd(), filePath)}`);
93
- }
94
- console.log(`\nDone. Removed ${totalRemoved} deprecated import(s).`);
95
- });
96
- }