@opencrvs/toolkit 2.1.0-rc.28fe5a3 → 2.1.0-rc.3028b2e

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 (247) 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 +364 -285
  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 +3778 -1231
  11. package/dist/commons/api/router.d.ts +980 -420
  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 +41 -21
  17. package/dist/commons/events/ActionInput.d.ts +4 -10
  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 +474 -6
  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 +246 -13
  40. package/dist/commons/events/mocks.test.utils.d.ts +46 -2
  41. package/dist/commons/events/scopes.d.ts +21 -1
  42. package/dist/commons/events/test.utils.d.ts +82 -32
  43. package/dist/commons/events/utils.d.ts +41 -6
  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/derived-variables.d.ts +12 -0
  52. package/dist/environment/derived-variables.d.ts.map +1 -1
  53. package/dist/environment/derived-variables.js +14 -0
  54. package/dist/environment/index.d.ts +1 -0
  55. package/dist/environment/index.d.ts.map +1 -1
  56. package/dist/environment/index.js +12 -1
  57. package/dist/environment/logger.d.ts +15 -3
  58. package/dist/environment/logger.d.ts.map +1 -1
  59. package/dist/environment/manage-users.js +1 -1
  60. package/dist/environment/paths.d.ts +7 -0
  61. package/dist/environment/paths.d.ts.map +1 -0
  62. package/dist/environment/paths.js +72 -0
  63. package/dist/environment/questions.d.ts.map +1 -1
  64. package/dist/environment/questions.js +20 -14
  65. package/dist/environment/setup-environment.d.ts +1 -1
  66. package/dist/environment/setup-environment.d.ts.map +1 -1
  67. package/dist/environment/setup-environment.js +603 -562
  68. package/dist/environment/swarm-to-k8s.js +3 -4
  69. package/dist/environment/templates.d.ts +0 -1
  70. package/dist/environment/templates.d.ts.map +1 -1
  71. package/dist/environment/templates.js +5 -9
  72. package/dist/environment/update-workflows.d.ts.map +1 -1
  73. package/dist/environment/update-workflows.js +21 -5
  74. package/dist/environment/upgrade.d.ts +2 -0
  75. package/dist/environment/upgrade.d.ts.map +1 -0
  76. package/dist/environment/upgrade.js +82 -0
  77. package/dist/environment/users.js +11 -13
  78. package/dist/environment/utils.d.ts +0 -12
  79. package/dist/environment/utils.d.ts.map +1 -1
  80. package/dist/environment/utils.js +1 -28
  81. package/dist/events/index.js +7842 -7212
  82. package/dist/migrations/v2.1/add-recovery-link-notifications.d.ts +3 -0
  83. package/dist/migrations/v2.1/add-recovery-link-notifications.d.ts.map +1 -0
  84. package/dist/migrations/v2.1/add-recovery-link-notifications.js +511 -0
  85. package/dist/migrations/v2.1/add-translations.d.ts +9 -0
  86. package/dist/migrations/v2.1/add-translations.d.ts.map +1 -0
  87. package/dist/migrations/v2.1/add-translations.js +149 -0
  88. package/dist/migrations/{v2.0/rename-api-paths.d.ts → v2.1/enable-telemetry.d.ts} +1 -1
  89. package/dist/migrations/v2.1/enable-telemetry.d.ts.map +1 -0
  90. package/dist/migrations/v2.1/enable-telemetry.js +455 -0
  91. package/dist/migrations/v2.1/index.d.ts.map +1 -1
  92. package/dist/migrations/v2.1/index.js +1952 -0
  93. package/dist/migrations/v2.1/migrate-infrastructure-to-assets.d.ts +14 -0
  94. package/dist/migrations/v2.1/migrate-infrastructure-to-assets.d.ts.map +1 -0
  95. package/dist/migrations/v2.1/migrate-infrastructure-to-assets.js +348 -0
  96. package/dist/migrations/v2.1/remove-metabase-package-installs.d.ts +2 -0
  97. package/dist/migrations/v2.1/remove-metabase-package-installs.d.ts.map +1 -0
  98. package/dist/migrations/v2.1/remove-metabase-package-installs.js +161 -0
  99. package/dist/migrations/{v2.0/migrate-scopes.d.ts → v2.1/remove-sentry.d.ts} +1 -1
  100. package/dist/migrations/v2.1/remove-sentry.d.ts.map +1 -0
  101. package/dist/migrations/v2.1/remove-sentry.js +354 -0
  102. package/dist/migrations/{v2.0/create-events-index.d.ts → v2.1/rename-trigger-paths.d.ts} +1 -1
  103. package/dist/migrations/v2.1/rename-trigger-paths.d.ts.map +1 -0
  104. package/dist/migrations/{v2.0/rename-api-paths.js → v2.1/rename-trigger-paths.js} +69 -40
  105. package/dist/migrations/v2.1/template-files.d.ts +8 -0
  106. package/dist/migrations/v2.1/template-files.d.ts.map +1 -0
  107. package/dist/migrations/v2.1/template-files.js +49 -0
  108. package/dist/migrations/v2.1/upgrade-tilt.d.ts +8 -0
  109. package/dist/migrations/v2.1/upgrade-tilt.d.ts.map +1 -0
  110. package/dist/migrations/v2.1/upgrade-tilt.js +139 -0
  111. package/dist/notification/index.js +1925 -1485
  112. package/dist/scopes/index.d.ts +614 -36
  113. package/dist/scopes/index.js +351 -65
  114. package/dist/telemetry/index.d.ts +45 -0
  115. package/dist/telemetry/index.d.ts.map +1 -0
  116. package/dist/telemetry/index.js +43 -0
  117. package/dist/templates/charts-values/dependencies/values.yaml +8 -0
  118. package/dist/templates/charts-values/opencrvs-services/values.yaml +10 -3
  119. package/dist/templates/charts-values/opentelemetry/values.yaml +102 -0
  120. package/dist/templates/charts-values/traefik/values.yaml +23 -9
  121. package/dist/templates/countryconfig-template/.tiltignore +1 -0
  122. package/dist/templates/countryconfig-template/Dockerfile.assets +7 -0
  123. package/dist/templates/countryconfig-template/Tiltfile +112 -0
  124. package/dist/templates/countryconfig-template/assets/README.md +1 -0
  125. package/dist/templates/countryconfig-template/assets/clear-all-data-dev.sh +61 -0
  126. package/dist/templates/countryconfig-template/assets/deployment/deploy.sh +455 -0
  127. package/dist/templates/countryconfig-template/assets/deployment/reindex.sh +168 -0
  128. package/dist/templates/countryconfig-template/assets/deployment/validate-required-variables-in-compose-files.ts +67 -0
  129. package/dist/templates/countryconfig-template/assets/elasticsearch/reindex.sh +168 -0
  130. package/dist/templates/countryconfig-template/assets/metabase/README.md +34 -0
  131. package/dist/templates/countryconfig-template/assets/metabase/environment-configuration.sql +36 -0
  132. package/dist/templates/countryconfig-template/assets/metabase/initialize-database.sh +46 -0
  133. package/dist/templates/countryconfig-template/assets/metabase/metabase.init.db.sql +27737 -0
  134. package/dist/templates/countryconfig-template/assets/metabase/open-shell.sh +21 -0
  135. package/dist/templates/countryconfig-template/assets/metabase/package.json +13 -0
  136. package/dist/templates/countryconfig-template/assets/metabase/run-dev.sh +108 -0
  137. package/dist/templates/countryconfig-template/assets/metabase/run.sh +120 -0
  138. package/dist/templates/countryconfig-template/assets/metabase/update-database.sh +40 -0
  139. package/dist/templates/countryconfig-template/assets/postgres/setup-analytics.sh +135 -0
  140. package/dist/templates/countryconfig-template/assets/postgres/setup-reference-data.sh +108 -0
  141. package/dist/templates/countryconfig-template/tilt/clear-all-data.ps1 +50 -0
  142. package/dist/templates/countryconfig-template/tilt/clear-all-data.sh +35 -0
  143. package/dist/templates/countryconfig-template/tilt/common.tilt +145 -0
  144. package/dist/templates/countryconfig-template/tilt/examples/dependencies/values.yaml +15 -0
  145. package/dist/templates/countryconfig-template/tilt/examples/opencrvs-services/values.yaml +56 -0
  146. package/dist/templates/countryconfig-template/tilt/examples/traefik/values-minikube.yaml +21 -0
  147. package/dist/templates/countryconfig-template/tilt/examples/traefik/values.yaml +38 -0
  148. package/dist/templates/countryconfig-template/tilt/helm/dependencies/values.yaml +17 -0
  149. package/dist/templates/countryconfig-template/tilt/helm/opencrvs-services/values.yaml +16 -0
  150. package/dist/templates/countryconfig-template/tilt/lib.tilt +95 -0
  151. package/dist/templates/countryconfig-template/tilt/opencrvs.tilt +136 -0
  152. package/dist/templates/inventory/inventory.template.yml +1 -3
  153. package/dist/translations/template.d.ts +11 -0
  154. package/dist/translations/template.d.ts.map +1 -0
  155. package/dist/translations/template.js +100 -0
  156. package/dist/verify/endpoints.d.ts +2 -0
  157. package/dist/verify/endpoints.d.ts.map +1 -0
  158. package/dist/verify/endpoints.js +510 -0
  159. package/opencrvs-toolkit-2.1.0-rc.3028b2e.tgz +0 -0
  160. package/package.json +14 -7
  161. package/tsconfig.build.json +11 -0
  162. package/tsconfig.build.tsbuildinfo +1 -0
  163. package/tsconfig.json +3 -0
  164. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts +0 -3
  165. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts.map +0 -1
  166. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.js +0 -429
  167. package/dist/migrations/v2.0/add-resend-invite-notification.d.ts +0 -3
  168. package/dist/migrations/v2.0/add-resend-invite-notification.d.ts.map +0 -1
  169. package/dist/migrations/v2.0/add-resend-invite-notification.js +0 -373
  170. package/dist/migrations/v2.0/checkout-upstream-files.d.ts +0 -22
  171. package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +0 -1
  172. package/dist/migrations/v2.0/checkout-upstream-files.js +0 -146
  173. package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts +0 -2
  174. package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts.map +0 -1
  175. package/dist/migrations/v2.0/convert-config-files-to-ts.js +0 -838
  176. package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts +0 -3
  177. package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts.map +0 -1
  178. package/dist/migrations/v2.0/convert-paragraph-to-heading.js +0 -158
  179. package/dist/migrations/v2.0/create-events-index.d.ts.map +0 -1
  180. package/dist/migrations/v2.0/create-events-index.js +0 -325
  181. package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts +0 -11
  182. package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts.map +0 -1
  183. package/dist/migrations/v2.0/delete-infrastructure-directory.js +0 -123
  184. package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.d.ts +0 -3
  185. package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.d.ts.map +0 -1
  186. package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.js +0 -110
  187. package/dist/migrations/v2.0/index.d.ts +0 -13
  188. package/dist/migrations/v2.0/index.d.ts.map +0 -1
  189. package/dist/migrations/v2.0/index.js +0 -103
  190. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts +0 -3
  191. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts.map +0 -1
  192. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.js +0 -432
  193. package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts +0 -13
  194. package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts.map +0 -1
  195. package/dist/migrations/v2.0/merge-infrastructure-directory.js +0 -222
  196. package/dist/migrations/v2.0/migrate-application-config-url.d.ts +0 -3
  197. package/dist/migrations/v2.0/migrate-application-config-url.d.ts.map +0 -1
  198. package/dist/migrations/v2.0/migrate-application-config-url.js +0 -343
  199. package/dist/migrations/v2.0/migrate-scopes.d.ts.map +0 -1
  200. package/dist/migrations/v2.0/migrate-scopes.js +0 -305
  201. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts +0 -3
  202. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts.map +0 -1
  203. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.js +0 -267
  204. package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts +0 -3
  205. package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts.map +0 -1
  206. package/dist/migrations/v2.0/migrate-workqueue-configs.js +0 -317
  207. package/dist/migrations/v2.0/remove-delete-actions.d.ts +0 -3
  208. package/dist/migrations/v2.0/remove-delete-actions.d.ts.map +0 -1
  209. package/dist/migrations/v2.0/remove-delete-actions.js +0 -156
  210. package/dist/migrations/v2.0/remove-demo-scope.d.ts +0 -3
  211. package/dist/migrations/v2.0/remove-demo-scope.d.ts.map +0 -1
  212. package/dist/migrations/v2.0/remove-demo-scope.js +0 -74
  213. package/dist/migrations/v2.0/remove-deprecated-imports.d.ts +0 -3
  214. package/dist/migrations/v2.0/remove-deprecated-imports.d.ts.map +0 -1
  215. package/dist/migrations/v2.0/remove-deprecated-imports.js +0 -96
  216. package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts +0 -3
  217. package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts.map +0 -1
  218. package/dist/migrations/v2.0/remove-fhir-url-helpers.js +0 -163
  219. package/dist/migrations/v2.0/remove-hearth-migrations.d.ts +0 -3
  220. package/dist/migrations/v2.0/remove-hearth-migrations.d.ts.map +0 -1
  221. package/dist/migrations/v2.0/remove-hearth-migrations.js +0 -87
  222. package/dist/migrations/v2.0/remove-old-statistics-service.d.ts +0 -3
  223. package/dist/migrations/v2.0/remove-old-statistics-service.d.ts.map +0 -1
  224. package/dist/migrations/v2.0/remove-old-statistics-service.js +0 -356
  225. package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts +0 -3
  226. package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts.map +0 -1
  227. package/dist/migrations/v2.0/remove-pending-certification-flag.js +0 -109
  228. package/dist/migrations/v2.0/remove-review-from-register-action.d.ts +0 -3
  229. package/dist/migrations/v2.0/remove-review-from-register-action.d.ts.map +0 -1
  230. package/dist/migrations/v2.0/remove-review-from-register-action.js +0 -163
  231. package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts +0 -3
  232. package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts.map +0 -1
  233. package/dist/migrations/v2.0/remove-unused-environment-variables.js +0 -186
  234. package/dist/migrations/v2.0/rename-api-paths.d.ts.map +0 -1
  235. package/dist/migrations/v2.0/rename-location-parent-id.d.ts +0 -3
  236. package/dist/migrations/v2.0/rename-location-parent-id.d.ts.map +0 -1
  237. package/dist/migrations/v2.0/rename-location-parent-id.js +0 -180
  238. package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts +0 -3
  239. package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts.map +0 -1
  240. package/dist/migrations/v2.0/simplify-analytics-precalculations.js +0 -195
  241. package/dist/migrations/v2.0/update-package-json.d.ts +0 -3
  242. package/dist/migrations/v2.0/update-package-json.d.ts.map +0 -1
  243. package/dist/migrations/v2.0/update-package-json.js +0 -105
  244. package/dist/templates/inventory/production.example.yml +0 -77
  245. package/dist/templates/inventory/qa.example.yml +0 -48
  246. package/opencrvs-toolkit-2.1.0-rc.28fe5a3.tgz +0 -0
  247. package/tsconfig.tsbuildinfo +0 -1
@@ -1,13 +0,0 @@
1
- interface MergeInfrastructureOptions {
2
- /**
3
- * Top-level subdirectories of `infrastructure/` to scope the merge to.
4
- * When omitted or empty, the entire `infrastructure/` tree is merged
5
- * (legacy behavior). Each name is relative to `infrastructure/` —
6
- * e.g. `['postgres', 'metabase']` merges only
7
- * `infrastructure/postgres/` and `infrastructure/metabase/`.
8
- */
9
- subdirs?: string[];
10
- }
11
- declare function main({ subdirs }?: MergeInfrastructureOptions): Promise<void>;
12
- export { main };
13
- //# sourceMappingURL=merge-infrastructure-directory.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"merge-infrastructure-directory.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/merge-infrastructure-directory.ts"],"names":[],"mappings":"AAsHA,UAAU,0BAA0B;IAClC;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;CACnB;AAID,iBAAe,IAAI,CAAC,EAClB,OAAY,EACb,GAAE,0BAA+B,GAAG,OAAO,CAAC,IAAI,CAAC,CAoIjD;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
@@ -1,222 +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
- Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.main = main;
23
- /**
24
- * Codemod: Merge upstream changes into the local `infrastructure/` directory
25
- * (or selected subdirectories of it) from opencrvs/opencrvs-countryconfig.
26
- *
27
- * Usage:
28
- * ts-node -r tsconfig-paths/register src/migrations/v2.0/merge-infrastructure-directory.ts
29
- *
30
- * What it does:
31
- * 1. Registers a temporary git remote that points at the canonical
32
- * opencrvs-countryconfig repository and fetches both:
33
- * - the upstream "theirs" branch (v2.0) → `UPSTREAM_BRANCH`
34
- * - the synthetic merge-base branch (latest 1.9 release line)
35
- * → `BASE_BRANCH`
36
- * 2. For every file under `infrastructure/` on upstream "theirs" (or, when
37
- * `subdirs` is provided, only files under
38
- * `infrastructure/<subdir>/` for each requested subdir), performs a
39
- * file-scoped 3-way merge:
40
- * - new file on upstream → checked out and staged
41
- * - existing file → 3-way merged in place via `git merge-file`,
42
- * using the BASE_BRANCH version of the file
43
- * as the ancestor (or an empty file if the
44
- * base doesn't have it)
45
- * Files local to the country config that don't exist on upstream are
46
- * left untouched.
47
- * 3. Cleanly merged files are staged. Files with conflicts are left in the
48
- * working tree with standard <<<<<<< / ======= / >>>>>>> markers and
49
- * MUST be resolved manually by the developer.
50
- * 4. Removes the temporary remote in all cases (success, failure, or
51
- * unexpected error) via a `finally` block.
52
- *
53
- * Why a content-based synthetic merge-base instead of `git merge-base`:
54
- * - Country config repos rarely share git history with
55
- * opencrvs-countryconfig (squashed forks, template-cloned repos, etc.),
56
- * so `git merge-base HEAD upstream/develop` typically returns nothing.
57
- * - With no merge-base, a 3-way merge degenerates to a 2-way diff against
58
- * an empty file — every line that differs becomes a conflict.
59
- * - `release-v1.9` is the latest 1.9.x release line on upstream and is a
60
- * near-perfect representation of "what `infrastructure/` looked like
61
- * before v2.0", regardless of whether the fork's git history reaches it.
62
- * - For files the country config never modified relative to that baseline,
63
- * `git merge-file` resolves cleanly to upstream's v2.0 version. Conflicts
64
- * are produced only where local edits genuinely overlap with v1.9 → v2.0
65
- * upstream edits — which is what the developer needs to review anyway.
66
- *
67
- * Why per-file merge instead of a real `git merge`:
68
- * - Limits the blast radius to `infrastructure/` only — no other paths
69
- * are touched.
70
- * - Doesn't put the repository into an in-progress merge state
71
- * (no MERGE_HEAD), so subsequent codemods/commands behave normally.
72
- * - Works regardless of whether the local repo shares history with
73
- * opencrvs-countryconfig.
74
- *
75
- * Caveats:
76
- * - Local edits to merged files may be overwritten where they overlap
77
- * with upstream changes. Run on a clean working tree.
78
- * - Requires git to be installed and network access to github.com.
79
- * - Requires the country config working directory to be a git repo.
80
- * - Binary files in `infrastructure/` are not merged textually; if both
81
- * sides changed a binary file, the result will be invalid and a warning
82
- * is printed.
83
- * - Forks that are on a much older 1.9.x and never merged later 1.9 patches
84
- * may see a few extra conflicts on files where 1.9.x → release-v1.9
85
- * patches and v1.9 → v2.0 changes textually overlap.
86
- */
87
- const child_process_1 = require("child_process");
88
- const fs_1 = require("fs");
89
- const os_1 = require("os");
90
- const path_1 = require("path");
91
- const checkout_upstream_files_1 = require("./checkout-upstream-files");
92
- // Distinct from the remote used by `checkout-upstream-files` so that a stale
93
- // remote left behind by an aborted run of one codemod doesn't trip up the
94
- // other.
95
- const TEMP_REMOTE = 'opencrvs-upgrade-v19-v20-codemod-merge-infra';
96
- const INFRASTRUCTURE_DIR = 'infrastructure';
97
- // Synthetic merge-base: the tip of upstream's latest 1.9.x release line.
98
- // We use this branch's content as the "common ancestor" for every file,
99
- // since most country forks don't share git history with upstream.
100
- const BASE_BRANCH = 'release-v1.9';
101
- /**
102
- * Reads `git show <ref>:<path>` as a Uint8Array (binary-safe).
103
- * Returns `null` if the path doesn't exist at that ref.
104
- */
105
- function gitShowBytes(ref, path) {
106
- try {
107
- const buf = (0, child_process_1.execFileSync)('git', ['show', `${ref}:${path}`], {
108
- cwd: process.cwd(),
109
- stdio: ['ignore', 'pipe', 'pipe']
110
- });
111
- // Return a plain Uint8Array view to satisfy strict typings of `fs`
112
- // (which want `ArrayBufferView`, not Node's `Buffer` subtype).
113
- return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
114
- }
115
- catch (_a) {
116
- return null;
117
- }
118
- }
119
- // ─── Entry point ─────────────────────────────────────────────────────────────
120
- function main() {
121
- return __awaiter(this, arguments, void 0, function* ({ subdirs = [] } = {}) {
122
- // Build the pathspec list passed to `git ls-tree`. Trailing slashes make
123
- // git treat them as tree paths (recurse into them).
124
- const pathspecs = subdirs.length > 0
125
- ? subdirs.map((s) => `${INFRASTRUCTURE_DIR}/${s}/`)
126
- : [`${INFRASTRUCTURE_DIR}/`];
127
- const scopeLabel = pathspecs.map((p) => `'${p}'`).join(', ');
128
- console.log(`Merging ${scopeLabel} from ${checkout_upstream_files_1.UPSTREAM_URL}@${checkout_upstream_files_1.UPSTREAM_BRANCH} (base: ${BASE_BRANCH})...\n`);
129
- (0, checkout_upstream_files_1.assertIsGitRepo)();
130
- // Best-effort cleanup of a stale temp remote from a previous aborted run.
131
- (0, checkout_upstream_files_1.tryGit)(['remote', 'remove', TEMP_REMOTE]);
132
- try {
133
- console.log(` Adding temporary remote '${TEMP_REMOTE}' → ${checkout_upstream_files_1.UPSTREAM_URL}`);
134
- (0, checkout_upstream_files_1.runGit)(['remote', 'add', TEMP_REMOTE, checkout_upstream_files_1.UPSTREAM_URL], { silent: true });
135
- // Fetch both branches at depth=1 — we only need their tip contents,
136
- // not their history (the merge is content-based, not history-based).
137
- console.log(` Fetching ${TEMP_REMOTE}/{${checkout_upstream_files_1.UPSTREAM_BRANCH},${BASE_BRANCH}} (depth 1)...`);
138
- (0, checkout_upstream_files_1.runGit)(['fetch', '--depth=1', TEMP_REMOTE, checkout_upstream_files_1.UPSTREAM_BRANCH, BASE_BRANCH]);
139
- const ref = `${TEMP_REMOTE}/${checkout_upstream_files_1.UPSTREAM_BRANCH}`;
140
- const baseRef = `${TEMP_REMOTE}/${BASE_BRANCH}`;
141
- // -z gives NUL-separated paths so filenames with spaces or newlines
142
- // survive the round-trip. Multiple pathspecs after `--` are unioned
143
- // by git, which scopes the listing to the requested subdirectories.
144
- const upstreamFiles = (0, checkout_upstream_files_1.runGit)(['ls-tree', '-r', '--name-only', '-z', ref, '--', ...pathspecs], { silent: true })
145
- .split('\0')
146
- .filter(Boolean);
147
- if (upstreamFiles.length === 0) {
148
- console.log(` No files found under ${scopeLabel} on ${ref}. Nothing to merge.`);
149
- return;
150
- }
151
- const tmpDir = (0, fs_1.mkdtempSync)((0, path_1.join)((0, os_1.tmpdir)(), 'opencrvs-merge-infra-'));
152
- const baseTmp = (0, path_1.join)(tmpDir, 'base');
153
- const theirsTmp = (0, path_1.join)(tmpDir, 'theirs');
154
- let added = 0;
155
- let merged = 0;
156
- const conflictedFiles = [];
157
- for (const file of upstreamFiles) {
158
- const fullPath = (0, path_1.join)(process.cwd(), file);
159
- if (!(0, fs_1.existsSync)(fullPath)) {
160
- // New upstream file — `git checkout` handles binary correctly and
161
- // stages the result, matching the UX of `checkout-upstream-files`.
162
- if ((0, checkout_upstream_files_1.tryGit)(['checkout', ref, '--', file])) {
163
- console.log(` + ${file} (new from upstream)`);
164
- added++;
165
- }
166
- else {
167
- console.warn(` [warn] failed to add new file ${file}`);
168
- }
169
- continue;
170
- }
171
- const theirContents = gitShowBytes(ref, file);
172
- if (theirContents === null) {
173
- // Shouldn't happen — `ls-tree` just told us the file is there.
174
- console.warn(` [warn] could not read ${file} from ${ref} — skipping.`);
175
- continue;
176
- }
177
- (0, fs_1.writeFileSync)(theirsTmp, theirContents);
178
- // Pull the base version from upstream's latest 1.9 release line. If
179
- // the file didn't exist there yet (added in v2.0), fall back to an
180
- // empty base — `git merge-file` will then treat any local content as
181
- // a local addition.
182
- const baseContents = gitShowBytes(baseRef, file);
183
- (0, fs_1.writeFileSync)(baseTmp, baseContents !== null && baseContents !== void 0 ? baseContents : new Uint8Array(0));
184
- // `git merge-file` does an in-place 3-way merge. Exit codes:
185
- // 0 → clean merge
186
- // 1..N → that many conflicts; markers written into the file
187
- // <0/127 → error (e.g. binary file rejected)
188
- try {
189
- (0, child_process_1.execFileSync)('git', ['merge-file', fullPath, baseTmp, theirsTmp], {
190
- cwd: process.cwd(),
191
- stdio: ['ignore', 'pipe', 'pipe']
192
- });
193
- (0, checkout_upstream_files_1.runGit)(['add', '--', file], { silent: true });
194
- merged++;
195
- }
196
- catch (err) {
197
- const status = err.status;
198
- if (typeof status === 'number' && status > 0) {
199
- conflictedFiles.push(file);
200
- console.warn(` ! ${file} (${status} conflict${status > 1 ? 's' : ''})`);
201
- }
202
- else {
203
- conflictedFiles.push(file);
204
- console.warn(` [warn] merge failed for ${file} (likely binary or unreadable) — left untouched.`);
205
- }
206
- }
207
- }
208
- console.log(`\n Done. ${added} added, ${merged} merged cleanly, ${conflictedFiles.length} with conflicts.`);
209
- if (conflictedFiles.length > 0) {
210
- console.warn(`\n NOTE: ${conflictedFiles.length} file(s) under '${INFRASTRUCTURE_DIR}/' have merge conflicts that you must resolve manually.\n` +
211
- ` Look for the standard conflict markers (<<<<<<<, =======, >>>>>>>) in:\n` +
212
- conflictedFiles.map((f) => ` - ${f}`).join('\n') +
213
- `\n After resolving, stage the fixes with: git add ${INFRASTRUCTURE_DIR}/`);
214
- }
215
- }
216
- finally {
217
- if ((0, checkout_upstream_files_1.tryGit)(['remote', 'remove', TEMP_REMOTE])) {
218
- console.log(` Removed temporary remote '${TEMP_REMOTE}'.`);
219
- }
220
- }
221
- });
222
- }
@@ -1,3 +0,0 @@
1
- declare function main(): Promise<void>;
2
- export { main };
3
- //# sourceMappingURL=migrate-application-config-url.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"migrate-application-config-url.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/migrate-application-config-url.ts"],"names":[],"mappings":"AAwUA,iBAAe,IAAI,kBAqElB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
@@ -1,343 +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: Replace usages of the legacy `APPLICATION_CONFIG_URL` env-derived
28
- * constant with direct usage of the v2.0 `applicationConfig` object.
29
- *
30
- * Background:
31
- * In v1.9 country configs read application configuration over HTTP from
32
- * the config service via `APPLICATION_CONFIG_URL`. In v2.0 the config is
33
- * defined statically in `src/api/application/application-config.ts` (as
34
- * `applicationConfig`) and consumed by import.
35
- *
36
- * What it does (per source file under `src/`):
37
- * 1. If the file imports `APPLICATION_CONFIG_URL` (from any module), the
38
- * named import is removed; if that leaves the import declaration empty,
39
- * the whole declaration is removed.
40
- * 2. An import of `applicationConfig` from
41
- * `@countryconfig/api/application/application-config` is added
42
- * (idempotent — re-uses an existing import declaration if one exists).
43
- * 3. Block-bodied functions whose body references *both*
44
- * `APPLICATION_CONFIG_URL` *and* a `fetch(...)` call are recognised
45
- * as "config-fetcher" functions. Their entire body is replaced with
46
- * `return applicationConfig` — eliminating the URL construction,
47
- * `fetch`, JSON parsing, and unwrapping of `.config`. Callers
48
- * (`await getApplicationConfig()` etc.) keep working because async
49
- * functions still wrap the return value in a `Promise`.
50
- * 4. Any remaining bare identifier references to `APPLICATION_CONFIG_URL`
51
- * are renamed to `applicationConfig`. Property names (e.g.
52
- * `obj.APPLICATION_CONFIG_URL` or `{ APPLICATION_CONFIG_URL: x }`)
53
- * are left alone.
54
- *
55
- * Caveats:
56
- * - Wholesale body replacement of config-fetcher functions destroys any
57
- * custom logic the country had inlined there (error handling, derived
58
- * fields, etc.). Each rewrite is logged so the developer can review
59
- * the diff and re-apply customisations on top of `applicationConfig`.
60
- * - The shape of v2.0 `applicationConfig` is not identical to the v1.9
61
- * `IApplicationConfigResponse.config` — callers that destructured
62
- * v1.9-only fields will produce TypeScript errors and need manual
63
- * review.
64
- * - Files that have a local declaration named `applicationConfig` are
65
- * skipped to avoid a name collision; a warning is logged so the
66
- * developer can resolve it manually.
67
- * - Files that reference `APPLICATION_CONFIG_URL` *without* importing it
68
- * (e.g. as a local variable) are skipped — we only rewrite imported
69
- * usages.
70
- * - Concise-body arrow functions (`() => fetch(...)`) are not
71
- * body-rewritten — only their identifier is renamed in step 4. If a
72
- * country happens to inline the fetch in concise form, the result
73
- * will need manual cleanup.
74
- */
75
- const path_1 = __importDefault(require("path"));
76
- const ts_morph_1 = require("ts-morph");
77
- const TARGET_IDENTIFIER = 'APPLICATION_CONFIG_URL';
78
- const REPLACEMENT_IDENTIFIER = 'applicationConfig';
79
- const REPLACEMENT_MODULE = '@countryconfig/api/application/application-config';
80
- /**
81
- * Function-like syntax kinds whose `body` we know how to replace via
82
- * `setBodyText` (i.e. block-bodied callables).
83
- */
84
- const FUNCTION_LIKE_KINDS = [
85
- ts_morph_1.SyntaxKind.FunctionDeclaration,
86
- ts_morph_1.SyntaxKind.FunctionExpression,
87
- ts_morph_1.SyntaxKind.ArrowFunction,
88
- ts_morph_1.SyntaxKind.MethodDeclaration
89
- ];
90
- /**
91
- * Returns the name of the function-like node for logging purposes.
92
- * Falls back to `<anonymous>` when nothing useful can be derived.
93
- */
94
- function describeFunction(node) {
95
- var _a;
96
- var _b, _c;
97
- if (ts_morph_1.Node.isFunctionDeclaration(node) || ts_morph_1.Node.isMethodDeclaration(node)) {
98
- return (_b = node.getName()) !== null && _b !== void 0 ? _b : '<anonymous>';
99
- }
100
- // FunctionExpression / ArrowFunction: try to pick up the assignment target.
101
- const parent = node.getParent();
102
- if (parent && ts_morph_1.Node.isVariableDeclaration(parent)) {
103
- return parent.getName();
104
- }
105
- if (parent && ts_morph_1.Node.isPropertyAssignment(parent)) {
106
- return parent.getName();
107
- }
108
- if (ts_morph_1.Node.isFunctionExpression(node) &&
109
- node.getNameNode() !== undefined) {
110
- return (_c = (_a = node.getNameNode()) === null || _a === void 0 ? void 0 : _a.getText()) !== null && _c !== void 0 ? _c : '<anonymous>';
111
- }
112
- return '<anonymous>';
113
- }
114
- /**
115
- * True when the node has a block body that we can safely replace via
116
- * `setBodyText` (excludes concise-body arrow functions like `() => 1`).
117
- */
118
- function hasBlockBody(node) {
119
- if (ts_morph_1.Node.isFunctionDeclaration(node) ||
120
- ts_morph_1.Node.isFunctionExpression(node) ||
121
- ts_morph_1.Node.isMethodDeclaration(node)) {
122
- return node.getBody() !== undefined;
123
- }
124
- if (ts_morph_1.Node.isArrowFunction(node)) {
125
- return node.getBody().getKind() === ts_morph_1.SyntaxKind.Block;
126
- }
127
- return false;
128
- }
129
- /**
130
- * True when the node's body references `APPLICATION_CONFIG_URL` AND
131
- * contains at least one `fetch(...)` call — the "config-fetcher" signature.
132
- */
133
- function isConfigFetcher(node) {
134
- let referencesTarget = false;
135
- let callsFetch = false;
136
- for (const id of node.getDescendantsOfKind(ts_morph_1.SyntaxKind.Identifier)) {
137
- const text = id.getText();
138
- if (!referencesTarget && text === TARGET_IDENTIFIER)
139
- referencesTarget = true;
140
- if (!callsFetch && text === 'fetch') {
141
- // Only count `fetch(` calls, not bare references like
142
- // `const f = fetch` (rare, but pedantic).
143
- const parent = id.getParent();
144
- if (ts_morph_1.Node.isCallExpression(parent) &&
145
- parent.getExpression() === id) {
146
- callsFetch = true;
147
- }
148
- }
149
- if (referencesTarget && callsFetch)
150
- return true;
151
- }
152
- return false;
153
- }
154
- function processFile(sourceFile) {
155
- const importsWithTarget = sourceFile
156
- .getImportDeclarations()
157
- .filter((decl) => decl.getNamedImports().some((ni) => ni.getName() === TARGET_IDENTIFIER));
158
- if (importsWithTarget.length === 0) {
159
- return { changed: false, rewrittenFunctions: [], renamedReferences: 0 };
160
- }
161
- // Bail out if a same-named local would collide with the new identifier.
162
- // Imported `applicationConfig` doesn't count as a local declaration.
163
- const collidingLocals = sourceFile
164
- .getDescendantsOfKind(ts_morph_1.SyntaxKind.Identifier)
165
- .filter((id) => id.getText() === REPLACEMENT_IDENTIFIER)
166
- .filter((id) => {
167
- const parent = id.getParent();
168
- const kind = parent.getKind();
169
- return (kind === ts_morph_1.SyntaxKind.VariableDeclaration ||
170
- kind === ts_morph_1.SyntaxKind.FunctionDeclaration ||
171
- kind === ts_morph_1.SyntaxKind.ClassDeclaration ||
172
- kind === ts_morph_1.SyntaxKind.Parameter);
173
- });
174
- if (collidingLocals.length > 0) {
175
- return {
176
- changed: false,
177
- rewrittenFunctions: [],
178
- renamedReferences: 0,
179
- skippedReason: `local declaration named '${REPLACEMENT_IDENTIFIER}' would collide`
180
- };
181
- }
182
- // ─── 1. Rewrite "config-fetcher" function bodies ───────────────────────
183
- // We only replace block-bodied functions that reference both
184
- // APPLICATION_CONFIG_URL and `fetch(...)`. The bodies are replaced with
185
- // `return applicationConfig`, which works for both sync and async
186
- // functions (the latter automatically wraps the value in a Promise).
187
- const candidateFunctions = FUNCTION_LIKE_KINDS.flatMap((kind) => sourceFile.getDescendantsOfKind(kind));
188
- // Outermost-first: when functions are nested, rewriting the outer one
189
- // also discards the inner one, so we shouldn't try to rewrite the inner
190
- // afterwards. Sorting by start position handles this; we additionally
191
- // filter out any candidate whose ancestor we already rewrote.
192
- candidateFunctions.sort((a, b) => a.getStart() - b.getStart());
193
- const rewrittenFunctions = [];
194
- const rewrittenSet = new Set();
195
- for (const fn of candidateFunctions) {
196
- if (!hasBlockBody(fn))
197
- continue;
198
- if (!isConfigFetcher(fn))
199
- continue;
200
- // Skip if any ancestor was already rewritten (its descendants are now
201
- // detached from the source file).
202
- let inRewrittenAncestor = false;
203
- let cursor = fn.getParent();
204
- while (cursor) {
205
- if (rewrittenSet.has(cursor)) {
206
- inRewrittenAncestor = true;
207
- break;
208
- }
209
- cursor = cursor.getParent();
210
- }
211
- if (inRewrittenAncestor)
212
- continue;
213
- const start = fn.getStart();
214
- const line = sourceFile.getLineAndColumnAtPos(start).line;
215
- const name = describeFunction(fn);
216
- if (ts_morph_1.Node.isFunctionDeclaration(fn) ||
217
- ts_morph_1.Node.isFunctionExpression(fn) ||
218
- ts_morph_1.Node.isMethodDeclaration(fn) ||
219
- ts_morph_1.Node.isArrowFunction(fn)) {
220
- fn.setBodyText(`return ${REPLACEMENT_IDENTIFIER}`);
221
- }
222
- rewrittenFunctions.push({ name, line });
223
- rewrittenSet.add(fn);
224
- }
225
- // ─── 2. Remove the `APPLICATION_CONFIG_URL` import ─────────────────────
226
- for (const decl of importsWithTarget) {
227
- const targetNamed = decl
228
- .getNamedImports()
229
- .find((ni) => ni.getName() === TARGET_IDENTIFIER);
230
- targetNamed === null || targetNamed === void 0 ? void 0 : targetNamed.remove();
231
- const isNowEmpty = decl.getNamedImports().length === 0 &&
232
- !decl.getDefaultImport() &&
233
- !decl.getNamespaceImport();
234
- if (isNowEmpty)
235
- decl.remove();
236
- }
237
- // ─── 3. Add the new `applicationConfig` import ─────────────────────────
238
- const existing = sourceFile.getImportDeclaration((decl) => decl.getModuleSpecifierValue() === REPLACEMENT_MODULE);
239
- if (existing) {
240
- const alreadyImported = existing
241
- .getNamedImports()
242
- .some((ni) => ni.getName() === REPLACEMENT_IDENTIFIER);
243
- if (!alreadyImported)
244
- existing.addNamedImport(REPLACEMENT_IDENTIFIER);
245
- }
246
- else {
247
- sourceFile.addImportDeclaration({
248
- moduleSpecifier: REPLACEMENT_MODULE,
249
- namedImports: [REPLACEMENT_IDENTIFIER]
250
- });
251
- }
252
- // ─── 4. Rename remaining identifier references ─────────────────────────
253
- // Anything still named APPLICATION_CONFIG_URL after the function-body
254
- // rewrites and import cleanup is a stray reference; rename it. Iterate
255
- // from highest position to lowest so `replaceWithText` doesn't shift
256
- // offsets for nodes we haven't visited yet.
257
- const renameTargets = sourceFile
258
- .getDescendantsOfKind(ts_morph_1.SyntaxKind.Identifier)
259
- .filter((id) => id.getText() === TARGET_IDENTIFIER)
260
- .filter((id) => !id.getFirstAncestorByKind(ts_morph_1.SyntaxKind.ImportDeclaration))
261
- .filter((id) => {
262
- const parent = id.getParent();
263
- const parentKind = parent.getKind();
264
- if (parentKind === ts_morph_1.SyntaxKind.PropertyAccessExpression) {
265
- const pae = parent.asKind(ts_morph_1.SyntaxKind.PropertyAccessExpression);
266
- // Right-hand side of `x.APPLICATION_CONFIG_URL` — leave alone.
267
- if (pae.getNameNode() === id)
268
- return false;
269
- }
270
- if (parentKind === ts_morph_1.SyntaxKind.PropertyAssignment) {
271
- const pa = parent.asKind(ts_morph_1.SyntaxKind.PropertyAssignment);
272
- // `{ APPLICATION_CONFIG_URL: ... }` — leave the key alone.
273
- if (pa.getNameNode() === id)
274
- return false;
275
- }
276
- if (parentKind === ts_morph_1.SyntaxKind.ShorthandPropertyAssignment) {
277
- // `{ APPLICATION_CONFIG_URL }` shorthand — both binding name AND
278
- // referenced symbol. Leave alone here; if the user wants to rename
279
- // the referenced value they should expand it manually first.
280
- return false;
281
- }
282
- return true;
283
- })
284
- .sort((a, b) => b.getPos() - a.getPos());
285
- for (const id of renameTargets) {
286
- id.replaceWithText(REPLACEMENT_IDENTIFIER);
287
- }
288
- return {
289
- changed: true,
290
- rewrittenFunctions,
291
- renamedReferences: renameTargets.length
292
- };
293
- }
294
- function main() {
295
- return __awaiter(this, void 0, void 0, function* () {
296
- const project = new ts_morph_1.Project({
297
- tsConfigFilePath: path_1.default.resolve(process.cwd(), 'tsconfig.json'),
298
- skipAddingFilesFromTsConfig: false
299
- });
300
- const sourceFiles = project.getSourceFiles().filter((sf) => {
301
- const fp = sf.getFilePath();
302
- return fp.includes('/src/') && !fp.includes('/node_modules/');
303
- });
304
- console.log(`Migrating '${TARGET_IDENTIFIER}' → '${REPLACEMENT_IDENTIFIER}' across ${sourceFiles.length} source file(s)...\n`);
305
- let changedFiles = 0;
306
- let totalRewrittenFunctions = 0;
307
- let totalRenamedReferences = 0;
308
- const skipped = [];
309
- for (const sourceFile of sourceFiles) {
310
- const filePath = sourceFile.getFilePath();
311
- const rel = path_1.default.relative(process.cwd(), filePath);
312
- const result = processFile(sourceFile);
313
- if (result.skippedReason) {
314
- skipped.push(`${rel} (${result.skippedReason})`);
315
- continue;
316
- }
317
- if (!result.changed)
318
- continue;
319
- yield sourceFile.save();
320
- changedFiles++;
321
- totalRewrittenFunctions += result.rewrittenFunctions.length;
322
- totalRenamedReferences += result.renamedReferences;
323
- for (const fn of result.rewrittenFunctions) {
324
- console.log(` [${rel}:${fn.line}] Rewrote '${fn.name}' body → 'return ${REPLACEMENT_IDENTIFIER}' (config fetch eliminated)`);
325
- }
326
- if (result.renamedReferences > 0) {
327
- console.log(` [${rel}] Renamed ${result.renamedReferences} stray reference(s) ${TARGET_IDENTIFIER} → ${REPLACEMENT_IDENTIFIER}`);
328
- }
329
- }
330
- if (skipped.length > 0) {
331
- console.warn(`\n ${skipped.length} file(s) skipped:\n` +
332
- skipped.map((s) => ` - ${s}`).join('\n'));
333
- }
334
- if (changedFiles === 0) {
335
- console.log(`\nNo files reference '${TARGET_IDENTIFIER}'. Nothing to do.`);
336
- return;
337
- }
338
- console.log(`\nDone. Updated ${changedFiles} file(s): ${totalRewrittenFunctions} fetch function(s) rewritten, ${totalRenamedReferences} bare reference(s) renamed.`);
339
- if (totalRewrittenFunctions > 0) {
340
- console.log(`NOTE: rewriting fetch functions discards any custom logic that lived inside them. Review the diff and re-apply any country-specific adjustments on top of '${REPLACEMENT_IDENTIFIER}'.`);
341
- }
342
- });
343
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"migrate-scopes.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/migrate-scopes.ts"],"names":[],"mappings":"AAoXA,iBAAe,IAAI,kBAmDlB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}