@opencrvs/toolkit 2.1.0-rc.d1b9774 → 2.1.0-rc.d235243

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 (223) hide show
  1. package/README.md +2 -12
  2. package/build.sh +15 -5
  3. package/create-countryconfig/index.js +164 -4
  4. package/dist/application-config/index.js +36 -25
  5. package/dist/authentication/index.d.ts +8 -9
  6. package/dist/authentication/index.js +23 -8
  7. package/dist/cli.js +1981 -2823
  8. package/dist/commons/api/router.d.ts +252 -290
  9. package/dist/commons/application-config/index.d.ts +0 -2
  10. package/dist/commons/conditionals/conditionals.d.ts +6 -6
  11. package/dist/commons/conditionals/validate.d.ts +19 -4
  12. package/dist/commons/events/ActionConfig.d.ts +5 -14
  13. package/dist/commons/events/ActionDocument.d.ts +30 -4
  14. package/dist/commons/events/AdvancedSearchConfig.d.ts +24 -12
  15. package/dist/commons/events/AuditLog.d.ts +1 -0
  16. package/dist/commons/events/Draft.d.ts +1 -21
  17. package/dist/commons/events/EventDocument.d.ts +4 -4
  18. package/dist/commons/events/FieldConfig.d.ts +26 -15
  19. package/dist/commons/events/FieldTypeMapping.d.ts +10 -10
  20. package/dist/commons/events/FieldValue.d.ts +1 -0
  21. package/dist/commons/events/FormConfig.d.ts +6 -0
  22. package/dist/commons/events/PageConfig.d.ts +4 -0
  23. package/dist/commons/events/locations.d.ts +4 -0
  24. package/dist/commons/events/scopes.d.ts +21 -1
  25. package/dist/commons/events/test.utils.d.ts +71 -22
  26. package/dist/commons/events/utils.d.ts +37 -2
  27. package/dist/conditionals/index.js +21 -7
  28. package/dist/environment/derived-variables.d.ts +18 -0
  29. package/dist/environment/derived-variables.d.ts.map +1 -1
  30. package/dist/environment/derived-variables.js +21 -0
  31. package/dist/environment/index.d.ts.map +1 -1
  32. package/dist/environment/index.js +2 -1
  33. package/dist/environment/manage-users.js +1 -1
  34. package/dist/environment/questions.d.ts +16 -0
  35. package/dist/environment/questions.d.ts.map +1 -1
  36. package/dist/environment/questions.js +27 -2
  37. package/dist/environment/setup-environment.d.ts +1 -1
  38. package/dist/environment/setup-environment.d.ts.map +1 -1
  39. package/dist/environment/setup-environment.js +633 -560
  40. package/dist/environment/swarm-to-k8s.js +3 -4
  41. package/dist/environment/templates.d.ts +0 -1
  42. package/dist/environment/templates.d.ts.map +1 -1
  43. package/dist/environment/templates.js +3 -8
  44. package/dist/environment/update-workflows.d.ts.map +1 -1
  45. package/dist/environment/update-workflows.js +6 -1
  46. package/dist/environment/utils.d.ts +0 -12
  47. package/dist/environment/utils.d.ts.map +1 -1
  48. package/dist/environment/utils.js +1 -28
  49. package/dist/events/index.js +2115 -1884
  50. package/dist/migrations/v2.1/add-recovery-link-notifications.js +4 -4
  51. package/dist/migrations/v2.1/add-translations.d.ts.map +1 -1
  52. package/dist/migrations/v2.1/add-translations.js +4 -68
  53. package/dist/migrations/v2.1/enable-telemetry.d.ts.map +1 -1
  54. package/dist/migrations/v2.1/enable-telemetry.js +30 -13
  55. package/dist/migrations/v2.1/index.d.ts.map +1 -1
  56. package/dist/migrations/v2.1/index.js +35 -1261
  57. package/dist/migrations/v2.1/migrate-infrastructure-to-assets.d.ts +14 -0
  58. package/dist/migrations/v2.1/migrate-infrastructure-to-assets.d.ts.map +1 -0
  59. package/dist/migrations/v2.1/migrate-infrastructure-to-assets.js +348 -0
  60. package/dist/migrations/v2.1/remove-metabase-package-installs.d.ts +2 -0
  61. package/dist/migrations/v2.1/remove-metabase-package-installs.d.ts.map +1 -0
  62. package/dist/migrations/v2.1/remove-metabase-package-installs.js +161 -0
  63. package/dist/migrations/{v2.0/migrate-scopes.d.ts → v2.1/remove-sentry.d.ts} +1 -1
  64. package/dist/migrations/v2.1/remove-sentry.d.ts.map +1 -0
  65. package/dist/migrations/v2.1/remove-sentry.js +354 -0
  66. package/dist/migrations/{v2.0/rename-api-paths.d.ts → v2.1/rename-trigger-paths.d.ts} +1 -1
  67. package/dist/migrations/v2.1/rename-trigger-paths.d.ts.map +1 -0
  68. package/dist/migrations/{v2.0/rename-api-paths.js → v2.1/rename-trigger-paths.js} +69 -40
  69. package/dist/migrations/v2.1/template-files.d.ts +8 -0
  70. package/dist/migrations/v2.1/template-files.d.ts.map +1 -0
  71. package/dist/migrations/v2.1/template-files.js +49 -0
  72. package/dist/migrations/v2.1/upgrade-tilt.d.ts +8 -0
  73. package/dist/migrations/v2.1/upgrade-tilt.d.ts.map +1 -0
  74. package/dist/migrations/v2.1/upgrade-tilt.js +139 -0
  75. package/dist/migrations/v2.2/add-e2e-tests.d.ts +19 -0
  76. package/dist/migrations/v2.2/add-e2e-tests.d.ts.map +1 -0
  77. package/dist/migrations/v2.2/add-e2e-tests.js +143 -0
  78. package/dist/migrations/v2.2/index.d.ts +6 -0
  79. package/dist/migrations/v2.2/index.d.ts.map +1 -0
  80. package/dist/migrations/v2.2/index.js +279 -0
  81. package/dist/migrations/v2.2/template-files.d.ts +8 -0
  82. package/dist/migrations/v2.2/template-files.d.ts.map +1 -0
  83. package/dist/migrations/v2.2/template-files.js +49 -0
  84. package/dist/migrations/v2.2/upgrade-tilt.d.ts +8 -0
  85. package/dist/migrations/v2.2/upgrade-tilt.d.ts.map +1 -0
  86. package/dist/migrations/v2.2/upgrade-tilt.js +139 -0
  87. package/dist/notification/index.js +249 -207
  88. package/dist/scopes/index.d.ts +288 -5
  89. package/dist/scopes/index.js +22 -7
  90. package/dist/telemetry/index.js +4 -0
  91. package/dist/templates/charts-values/dependencies/values.yaml +8 -0
  92. package/dist/templates/charts-values/opencrvs-services/values.yaml +6 -0
  93. package/dist/templates/charts-values/opentelemetry/values.yaml +7 -0
  94. package/dist/templates/charts-values/traefik/values.yaml +2 -3
  95. package/dist/templates/countryconfig-template/.tiltignore +1 -0
  96. package/dist/templates/countryconfig-template/Dockerfile.assets +7 -0
  97. package/dist/templates/countryconfig-template/Tiltfile +112 -0
  98. package/dist/templates/countryconfig-template/assets/README.md +1 -0
  99. package/dist/templates/countryconfig-template/assets/clear-all-data-dev.sh +61 -0
  100. package/dist/templates/countryconfig-template/assets/deployment/deploy.sh +455 -0
  101. package/dist/templates/countryconfig-template/assets/deployment/reindex.sh +168 -0
  102. package/dist/templates/countryconfig-template/assets/deployment/validate-required-variables-in-compose-files.ts +67 -0
  103. package/dist/templates/countryconfig-template/assets/elasticsearch/reindex.sh +168 -0
  104. package/dist/templates/countryconfig-template/assets/metabase/README.md +34 -0
  105. package/dist/templates/countryconfig-template/assets/metabase/environment-configuration.sql +36 -0
  106. package/dist/templates/countryconfig-template/assets/metabase/initialize-database.sh +46 -0
  107. package/dist/templates/countryconfig-template/assets/metabase/metabase.init.db.sql +27737 -0
  108. package/dist/templates/countryconfig-template/assets/metabase/open-shell.sh +21 -0
  109. package/dist/templates/countryconfig-template/assets/metabase/package.json +13 -0
  110. package/dist/templates/countryconfig-template/assets/metabase/run-dev.sh +108 -0
  111. package/dist/templates/countryconfig-template/assets/metabase/run.sh +120 -0
  112. package/dist/templates/countryconfig-template/assets/metabase/update-database.sh +40 -0
  113. package/dist/templates/countryconfig-template/assets/postgres/setup-analytics.sh +135 -0
  114. package/dist/templates/countryconfig-template/assets/postgres/setup-reference-data.sh +108 -0
  115. package/dist/templates/countryconfig-template/e2e/README.md +36 -0
  116. package/dist/templates/countryconfig-template/e2e/constants.ts +28 -0
  117. package/dist/templates/countryconfig-template/e2e/login.e2e.ts +59 -0
  118. package/dist/templates/countryconfig-template/package.json +153 -0
  119. package/dist/templates/countryconfig-template/playwright.config.ts +42 -0
  120. package/dist/templates/countryconfig-template/tilt/clear-all-data.ps1 +50 -0
  121. package/dist/templates/countryconfig-template/tilt/clear-all-data.sh +35 -0
  122. package/dist/templates/countryconfig-template/tilt/common.tilt +159 -0
  123. package/dist/templates/countryconfig-template/tilt/examples/dependencies/values.yaml +15 -0
  124. package/dist/templates/countryconfig-template/tilt/examples/opencrvs-services/values.yaml +56 -0
  125. package/dist/templates/countryconfig-template/tilt/examples/traefik/values-minikube.yaml +21 -0
  126. package/dist/templates/countryconfig-template/tilt/examples/traefik/values.yaml +38 -0
  127. package/dist/templates/countryconfig-template/tilt/helm/dependencies/values.yaml +17 -0
  128. package/dist/templates/countryconfig-template/tilt/helm/opencrvs-services/values.yaml +16 -0
  129. package/dist/templates/countryconfig-template/tilt/lib.tilt +95 -0
  130. package/dist/templates/countryconfig-template/tilt/opencrvs.tilt +136 -0
  131. package/dist/translations/template.d.ts +11 -0
  132. package/dist/translations/template.d.ts.map +1 -0
  133. package/dist/translations/template.js +100 -0
  134. package/dist/verify/endpoints.d.ts.map +1 -1
  135. package/dist/verify/endpoints.js +180 -15
  136. package/opencrvs-toolkit-2.1.0-rc.d235243.tgz +0 -0
  137. package/package.json +2 -1
  138. package/tsconfig.build.tsbuildinfo +1 -1
  139. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts +0 -3
  140. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts.map +0 -1
  141. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.js +0 -429
  142. package/dist/migrations/v2.0/add-resend-invite-notification.d.ts +0 -3
  143. package/dist/migrations/v2.0/add-resend-invite-notification.d.ts.map +0 -1
  144. package/dist/migrations/v2.0/add-resend-invite-notification.js +0 -373
  145. package/dist/migrations/v2.0/checkout-upstream-files.d.ts +0 -22
  146. package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +0 -1
  147. package/dist/migrations/v2.0/checkout-upstream-files.js +0 -146
  148. package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts +0 -2
  149. package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts.map +0 -1
  150. package/dist/migrations/v2.0/convert-config-files-to-ts.js +0 -838
  151. package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts +0 -3
  152. package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts.map +0 -1
  153. package/dist/migrations/v2.0/convert-paragraph-to-heading.js +0 -158
  154. package/dist/migrations/v2.0/create-events-index.d.ts +0 -3
  155. package/dist/migrations/v2.0/create-events-index.d.ts.map +0 -1
  156. package/dist/migrations/v2.0/create-events-index.js +0 -325
  157. package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts +0 -11
  158. package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts.map +0 -1
  159. package/dist/migrations/v2.0/delete-infrastructure-directory.js +0 -123
  160. package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.d.ts +0 -3
  161. package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.d.ts.map +0 -1
  162. package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.js +0 -110
  163. package/dist/migrations/v2.0/index.d.ts +0 -13
  164. package/dist/migrations/v2.0/index.d.ts.map +0 -1
  165. package/dist/migrations/v2.0/index.js +0 -103
  166. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts +0 -3
  167. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts.map +0 -1
  168. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.js +0 -432
  169. package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts +0 -13
  170. package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts.map +0 -1
  171. package/dist/migrations/v2.0/merge-infrastructure-directory.js +0 -222
  172. package/dist/migrations/v2.0/migrate-application-config-url.d.ts +0 -3
  173. package/dist/migrations/v2.0/migrate-application-config-url.d.ts.map +0 -1
  174. package/dist/migrations/v2.0/migrate-application-config-url.js +0 -343
  175. package/dist/migrations/v2.0/migrate-scopes.d.ts.map +0 -1
  176. package/dist/migrations/v2.0/migrate-scopes.js +0 -305
  177. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts +0 -3
  178. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts.map +0 -1
  179. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.js +0 -267
  180. package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts +0 -3
  181. package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts.map +0 -1
  182. package/dist/migrations/v2.0/migrate-workqueue-configs.js +0 -317
  183. package/dist/migrations/v2.0/remove-delete-actions.d.ts +0 -3
  184. package/dist/migrations/v2.0/remove-delete-actions.d.ts.map +0 -1
  185. package/dist/migrations/v2.0/remove-delete-actions.js +0 -156
  186. package/dist/migrations/v2.0/remove-demo-scope.d.ts +0 -3
  187. package/dist/migrations/v2.0/remove-demo-scope.d.ts.map +0 -1
  188. package/dist/migrations/v2.0/remove-demo-scope.js +0 -74
  189. package/dist/migrations/v2.0/remove-deprecated-imports.d.ts +0 -3
  190. package/dist/migrations/v2.0/remove-deprecated-imports.d.ts.map +0 -1
  191. package/dist/migrations/v2.0/remove-deprecated-imports.js +0 -96
  192. package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts +0 -3
  193. package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts.map +0 -1
  194. package/dist/migrations/v2.0/remove-fhir-url-helpers.js +0 -163
  195. package/dist/migrations/v2.0/remove-hearth-migrations.d.ts +0 -3
  196. package/dist/migrations/v2.0/remove-hearth-migrations.d.ts.map +0 -1
  197. package/dist/migrations/v2.0/remove-hearth-migrations.js +0 -87
  198. package/dist/migrations/v2.0/remove-old-statistics-service.d.ts +0 -3
  199. package/dist/migrations/v2.0/remove-old-statistics-service.d.ts.map +0 -1
  200. package/dist/migrations/v2.0/remove-old-statistics-service.js +0 -356
  201. package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts +0 -3
  202. package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts.map +0 -1
  203. package/dist/migrations/v2.0/remove-pending-certification-flag.js +0 -109
  204. package/dist/migrations/v2.0/remove-review-from-register-action.d.ts +0 -3
  205. package/dist/migrations/v2.0/remove-review-from-register-action.d.ts.map +0 -1
  206. package/dist/migrations/v2.0/remove-review-from-register-action.js +0 -163
  207. package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts +0 -3
  208. package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts.map +0 -1
  209. package/dist/migrations/v2.0/remove-unused-environment-variables.js +0 -186
  210. package/dist/migrations/v2.0/rename-api-paths.d.ts.map +0 -1
  211. package/dist/migrations/v2.0/rename-location-parent-id.d.ts +0 -3
  212. package/dist/migrations/v2.0/rename-location-parent-id.d.ts.map +0 -1
  213. package/dist/migrations/v2.0/rename-location-parent-id.js +0 -180
  214. package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts +0 -3
  215. package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts.map +0 -1
  216. package/dist/migrations/v2.0/simplify-analytics-precalculations.js +0 -195
  217. package/dist/migrations/v2.0/update-package-json.d.ts +0 -3
  218. package/dist/migrations/v2.0/update-package-json.d.ts.map +0 -1
  219. package/dist/migrations/v2.0/update-package-json.js +0 -105
  220. package/dist/translations/check.d.ts +0 -19
  221. package/dist/translations/check.d.ts.map +0 -1
  222. package/dist/translations/check.js +0 -127
  223. package/opencrvs-toolkit-2.1.0-rc.d1b9774.tgz +0 -0
@@ -1 +0,0 @@
1
- {"version":3,"file":"simplify-analytics-precalculations.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/simplify-analytics-precalculations.ts"],"names":[],"mappings":"AAqLA,iBAAe,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAyCnC;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
@@ -1,195 +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: Clean up `src/analytics/analytics.ts` by removing the Farajaland
28
- * sample precalculation wiring.
29
- *
30
- * Usage:
31
- * ts-node -r tsconfig-paths/register src/migrations/v2.0/simplify-analytics-precalculations.ts
32
- *
33
- * Runs LAST, after `checkout-upstream-files` has replaced
34
- * `src/analytics/analytics.ts` with the upstream v2.0 version. That upstream
35
- * version hardcodes a Farajaland-specific birth-event precalculation (it
36
- * imports `Event` and `precalculateBirthEvent`), which countries implementing
37
- * their own flows don't want. This codemod strips that out so each country
38
- * starts from a clean placeholder.
39
- *
40
- * What it does (only to `src/analytics/analytics.ts`, if present):
41
- * 1. Removes the named imports `Event` and `precalculateBirthEvent`.
42
- * If an import declaration becomes empty it is removed entirely.
43
- * 2. Rewrites the body of `precalculateAdditionalAnalytics` so it contains
44
- * nothing but `return declaration` — i.e. every statement that
45
- * references `Event` or `precalculateBirthEvent` is dropped, and a
46
- * `return declaration` is ensured at the end.
47
- *
48
- * The codemod is safe to re-run: if the imports are already gone and the
49
- * function body is already `return declaration`, it is a no-op.
50
- */
51
- const ts_morph_1 = require("ts-morph");
52
- const fs_1 = __importDefault(require("fs"));
53
- const path_1 = __importDefault(require("path"));
54
- const ANALYTICS_FILE_REL = 'src/analytics/analytics.ts';
55
- const FUNCTION_NAME = 'precalculateAdditionalAnalytics';
56
- const IMPORT_NAMES_TO_REMOVE = new Set(['Event', 'precalculateBirthEvent']);
57
- const RETURN_EXPRESSION_TEXT = 'declaration';
58
- // ─── Import cleanup ──────────────────────────────────────────────────────────
59
- /**
60
- * Removes every named import in `sourceFile` whose local binding name is in
61
- * `IMPORT_NAMES_TO_REMOVE`. If a given import declaration is left with no
62
- * named imports, default import or namespace import, the declaration itself
63
- * is removed.
64
- */
65
- function removeTargetedNamedImports(sourceFile) {
66
- const log = [];
67
- for (const importDecl of [...sourceFile.getImportDeclarations()]) {
68
- const namedImports = importDecl.getNamedImports();
69
- if (namedImports.length === 0)
70
- continue;
71
- const matched = namedImports.filter((ni) => IMPORT_NAMES_TO_REMOVE.has(ni.getName()));
72
- if (matched.length === 0)
73
- continue;
74
- const removedNames = matched.map((ni) => ni.getName());
75
- for (const ni of matched)
76
- ni.remove();
77
- log.push(`removed import(s) ${removedNames.join(', ')} from '${importDecl.getModuleSpecifierValue()}'`);
78
- const stillUsed = importDecl.getNamedImports().length > 0 ||
79
- importDecl.getDefaultImport() ||
80
- importDecl.getNamespaceImport();
81
- if (!stillUsed)
82
- importDecl.remove();
83
- }
84
- return log;
85
- }
86
- // ─── Function-body cleanup ───────────────────────────────────────────────────
87
- /**
88
- * Returns the `precalculateAdditionalAnalytics` declaration in `sourceFile`,
89
- * whether it was written as `function precalculateAdditionalAnalytics(...)` or
90
- * as `const precalculateAdditionalAnalytics = (...) => { ... }`.
91
- */
92
- function findPrecalculateFunction(sourceFile) {
93
- for (const fn of sourceFile.getFunctions()) {
94
- if (fn.getName() === FUNCTION_NAME)
95
- return fn;
96
- }
97
- for (const statement of sourceFile.getVariableStatements()) {
98
- for (const decl of statement.getDeclarations()) {
99
- if (decl.getName() === FUNCTION_NAME)
100
- return decl;
101
- }
102
- }
103
- return undefined;
104
- }
105
- /**
106
- * Returns the block body of a function declaration or variable-declared arrow
107
- * / function expression, or undefined if the function has an expression body
108
- * or doesn't exist.
109
- */
110
- function getFunctionBodyBlock(fn) {
111
- if (ts_morph_1.Node.isFunctionDeclaration(fn))
112
- return fn.getBody();
113
- const initializer = fn.getInitializer();
114
- if (!initializer)
115
- return undefined;
116
- if (!ts_morph_1.Node.isArrowFunction(initializer) &&
117
- !ts_morph_1.Node.isFunctionExpression(initializer)) {
118
- return undefined;
119
- }
120
- return initializer.getBody();
121
- }
122
- /**
123
- * Rewrites the body of `precalculateAdditionalAnalytics` so that the only
124
- * statement is `return declaration`. Any statement whose subtree references
125
- * the removed imports (`Event`, `precalculateBirthEvent`) is dropped; a
126
- * trailing `return declaration` is ensured.
127
- */
128
- function simplifyPrecalculateFunction(sourceFile) {
129
- var _a;
130
- const log = [];
131
- const fn = findPrecalculateFunction(sourceFile);
132
- if (!fn)
133
- return log;
134
- const body = getFunctionBodyBlock(fn);
135
- if (!body || !ts_morph_1.Node.isBlock(body))
136
- return log;
137
- // Drop every statement (not just `if`s) whose AST references an identifier
138
- // in IMPORT_NAMES_TO_REMOVE. This handles both the upstream shape
139
- // if (eventConfig.id === Event.Birth) return precalculateBirthEvent(...)
140
- // and any equivalent variant a country might have typed.
141
- for (const statement of [...body.getStatements()]) {
142
- const references = statement
143
- .getDescendantsOfKind(ts_morph_1.SyntaxKind.Identifier)
144
- .some((id) => IMPORT_NAMES_TO_REMOVE.has(id.getText()));
145
- if (references) {
146
- statement.remove();
147
- log.push(`removed statement in ${FUNCTION_NAME} referencing removed imports`);
148
- }
149
- }
150
- // Ensure the function ends with `return declaration`. If nothing changed
151
- // and the body already ends correctly, this is a no-op.
152
- const remaining = body.getStatements();
153
- const last = remaining[remaining.length - 1];
154
- const alreadyCorrect = last &&
155
- ts_morph_1.Node.isReturnStatement(last) &&
156
- ((_a = last.getExpression()) === null || _a === void 0 ? void 0 : _a.getText()) === RETURN_EXPRESSION_TEXT;
157
- if (!alreadyCorrect) {
158
- body.addStatements(`return ${RETURN_EXPRESSION_TEXT}`);
159
- log.push(`ensured '${FUNCTION_NAME}' ends with 'return ${RETURN_EXPRESSION_TEXT}'`);
160
- }
161
- return log;
162
- }
163
- // ─── Entry point ─────────────────────────────────────────────────────────────
164
- function main() {
165
- return __awaiter(this, void 0, void 0, function* () {
166
- const cwd = process.cwd();
167
- const absPath = path_1.default.join(cwd, ANALYTICS_FILE_REL);
168
- if (!fs_1.default.existsSync(absPath)) {
169
- console.log(`[${ANALYTICS_FILE_REL}] does not exist — nothing to clean up.`);
170
- return;
171
- }
172
- const project = new ts_morph_1.Project({
173
- tsConfigFilePath: path_1.default.resolve(cwd, 'tsconfig.json'),
174
- skipAddingFilesFromTsConfig: false
175
- });
176
- const sourceFile = project.getSourceFile(absPath);
177
- if (!sourceFile) {
178
- console.log(`[${ANALYTICS_FILE_REL}] is not part of the tsconfig project. Skipping.`);
179
- return;
180
- }
181
- console.log(`Cleaning up ${ANALYTICS_FILE_REL}...\n`);
182
- const importLogs = removeTargetedNamedImports(sourceFile);
183
- const fnLogs = simplifyPrecalculateFunction(sourceFile);
184
- const allLogs = [...importLogs, ...fnLogs];
185
- if (allLogs.length === 0) {
186
- console.log(`[${ANALYTICS_FILE_REL}] already clean — nothing to do.`);
187
- return;
188
- }
189
- for (const log of allLogs) {
190
- console.log(` [${ANALYTICS_FILE_REL}] ${log}`);
191
- }
192
- yield sourceFile.save();
193
- console.log(`\nSaved ${ANALYTICS_FILE_REL}.`);
194
- });
195
- }
@@ -1,3 +0,0 @@
1
- declare function main(): Promise<void>;
2
- export { main };
3
- //# sourceMappingURL=update-package-json.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"update-package-json.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/update-package-json.ts"],"names":[],"mappings":"AA2CA,iBAAe,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAyEnC;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
@@ -1,105 +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: Update root `package.json` for the v1.9 → v2.0 upgrade.
28
- *
29
- * Changes applied:
30
- * 1. Sets `version` to `2.0.0`.
31
- * 2. Sets `zod` to `^4.2.1` in `dependencies` (or `devDependencies` if it
32
- * already lives there). If `zod` is absent from both, it's added to
33
- * `dependencies`.
34
- *
35
- * Caveats:
36
- * - The codemod preserves the file's existing 2-space indentation and
37
- * trailing newline. Any non-standard formatting (e.g. tabs) will be
38
- * replaced with 2-space indentation.
39
- * - No-op when `package.json` is missing.
40
- * - No automatic `yarn install` is run; the developer should reinstall
41
- * dependencies after the codemods complete.
42
- */
43
- const fs_1 = require("fs");
44
- const path_1 = __importDefault(require("path"));
45
- const PACKAGE_JSON_RELATIVE = 'package.json';
46
- const TARGET_VERSION = '2.0.0';
47
- const TARGET_ZOD_RANGE = '^4.2.1';
48
- function main() {
49
- return __awaiter(this, void 0, void 0, function* () {
50
- const packageJsonPath = path_1.default.join(process.cwd(), PACKAGE_JSON_RELATIVE);
51
- if (!(0, fs_1.existsSync)(packageJsonPath)) {
52
- console.log(`'${PACKAGE_JSON_RELATIVE}' not found in ${process.cwd()} — skipping.`);
53
- return;
54
- }
55
- const raw = (0, fs_1.readFileSync)(packageJsonPath, 'utf8');
56
- let parsed;
57
- try {
58
- parsed = JSON.parse(raw);
59
- }
60
- catch (error) {
61
- console.warn(` [${PACKAGE_JSON_RELATIVE}] Failed to parse JSON — skipping update. ${error.message}`);
62
- return;
63
- }
64
- console.log(`Updating '${PACKAGE_JSON_RELATIVE}'...`);
65
- const previousVersion = parsed.version;
66
- const versionChanged = previousVersion !== TARGET_VERSION;
67
- parsed.version = TARGET_VERSION;
68
- if (versionChanged) {
69
- console.log(` Set version: ${previousVersion !== null && previousVersion !== void 0 ? previousVersion : '<unset>'} → ${TARGET_VERSION}`);
70
- }
71
- else {
72
- console.log(` Version already ${TARGET_VERSION} — no change.`);
73
- }
74
- // Resolve which dependency bucket already holds zod, defaulting to
75
- // `dependencies` when absent.
76
- let zodBucket = 'dependencies';
77
- if (parsed.devDependencies && 'zod' in parsed.devDependencies) {
78
- zodBucket = 'devDependencies';
79
- }
80
- if (!parsed[zodBucket]) {
81
- parsed[zodBucket] = {};
82
- }
83
- const bucket = parsed[zodBucket];
84
- const previousZod = bucket.zod;
85
- const zodChanged = previousZod !== TARGET_ZOD_RANGE;
86
- bucket.zod = TARGET_ZOD_RANGE;
87
- if (zodChanged) {
88
- console.log(` Set ${zodBucket}.zod: ${previousZod !== null && previousZod !== void 0 ? previousZod : '<absent>'} → ${TARGET_ZOD_RANGE}`);
89
- }
90
- else {
91
- console.log(` ${zodBucket}.zod already ${TARGET_ZOD_RANGE} — no change.`);
92
- }
93
- // Preserve trailing newline if the source had one (default to LF since
94
- // most repos commit JSON with a trailing newline).
95
- const trailingNewline = raw.endsWith('\n') ? '\n' : '';
96
- const next = JSON.stringify(parsed, null, 2) + trailingNewline;
97
- if (next === raw) {
98
- console.log('\n No changes to write.');
99
- return;
100
- }
101
- (0, fs_1.writeFileSync)(packageJsonPath, next, 'utf8');
102
- console.log(`\n Saved '${PACKAGE_JSON_RELATIVE}'.`);
103
- console.log(` NOTE: run \`yarn install\` (or your package manager equivalent) to install the updated dependency versions.`);
104
- });
105
- }
@@ -1,19 +0,0 @@
1
- export type Message = {
2
- id: string;
3
- defaultMessage: string;
4
- description: string;
5
- };
6
- export type CheckResult = {
7
- missing: Message[];
8
- /** Rows in countryconfig.csv that nothing in the source declares. */
9
- outdated: string[];
10
- /** Files declaring a message whose id is assembled at runtime. */
11
- dynamicIds: string[];
12
- };
13
- export declare function check(cwd: string): CheckResult;
14
- /**
15
- * Adds a row per missing message, filling in only English — the rest is copy
16
- * somebody has to write. Returns the ids added.
17
- */
18
- export declare function writeMissing(cwd: string, missing: Message[]): string[];
19
- //# sourceMappingURL=check.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../../src/translations/check.ts"],"names":[],"mappings":"AAwCA,MAAM,MAAM,OAAO,GAAG;IACpB,EAAE,EAAE,MAAM,CAAA;IACV,cAAc,EAAE,MAAM,CAAA;IACtB,WAAW,EAAE,MAAM,CAAA;CACpB,CAAA;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,OAAO,EAAE,OAAO,EAAE,CAAA;IAClB,qEAAqE;IACrE,QAAQ,EAAE,MAAM,EAAE,CAAA;IAClB,kEAAkE;IAClE,UAAU,EAAE,MAAM,EAAE,CAAA;CACrB,CAAA;AAgED,wBAAgB,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,CAyB9C;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,YAuB3D"}
@@ -1,127 +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 __importDefault = (this && this.__importDefault) || function (mod) {
13
- return (mod && mod.__esModule) ? mod : { "default": mod };
14
- };
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.check = check;
17
- exports.writeMissing = writeMissing;
18
- /**
19
- * Checks that every message a country config declares has a row in
20
- * `countryconfig.csv`.
21
- *
22
- * The mirror of the check core runs over its own packages: core validates
23
- * `client.csv` and `login.csv` against the client and login sources, and this
24
- * validates `countryconfig.csv` against the country config's own source.
25
- * Without it, a form or event label added to a country config renders as a raw
26
- * id.
27
- *
28
- * `client.csv` and `login.csv` are read but never written: core owns them, and
29
- * `opencrvs upgrade` keeps them in sync.
30
- */
31
- const ts_morph_1 = require("ts-morph");
32
- const path_1 = __importDefault(require("path"));
33
- const csv_1 = require("../csv");
34
- const TRANSLATIONS = 'src/translations';
35
- const OWN_FILE = `${TRANSLATIONS}/countryconfig.csv`;
36
- const CORE_FILES = [`${TRANSLATIONS}/client.csv`, `${TRANSLATIONS}/login.csv`];
37
- /**
38
- * The value of a property when the source says what it is outright. A template
39
- * literal with something interpolated into it does not count.
40
- */
41
- function staticStringOf(node, name) {
42
- const property = node.getProperty(name);
43
- if (!property || !ts_morph_1.Node.isPropertyAssignment(property)) {
44
- return undefined;
45
- }
46
- const initializer = property.getInitializer();
47
- return initializer &&
48
- (ts_morph_1.Node.isStringLiteral(initializer) ||
49
- ts_morph_1.Node.isNoSubstitutionTemplateLiteral(initializer))
50
- ? initializer.getLiteralValue()
51
- : undefined;
52
- }
53
- function messagesDeclaredIn(cwd) {
54
- const project = new ts_morph_1.Project({ skipAddingFilesFromTsConfig: true });
55
- project.addSourceFilesAtPaths([
56
- path_1.default.join(cwd, 'src/**/*.ts'),
57
- path_1.default.join(cwd, 'src/**/*.tsx'),
58
- `!${path_1.default.join(cwd, 'src/**/*.test.ts')}`,
59
- `!${path_1.default.join(cwd, 'src/**/*.test.tsx')}`,
60
- `!${path_1.default.join(cwd, 'src/**/*.stories.ts')}`,
61
- `!${path_1.default.join(cwd, 'src/**/*.stories.tsx')}`
62
- ]);
63
- const messages = [];
64
- const dynamicIds = [];
65
- for (const sourceFile of project.getSourceFiles()) {
66
- sourceFile.forEachDescendant((node) => {
67
- var _a, _b;
68
- if (!ts_morph_1.Node.isObjectLiteralExpression(node)) {
69
- return;
70
- }
71
- if (!(node.getProperty('id') && node.getProperty('defaultMessage'))) {
72
- return;
73
- }
74
- const id = staticStringOf(node, 'id');
75
- if (id === undefined) {
76
- dynamicIds.push(path_1.default.relative(cwd, sourceFile.getFilePath()));
77
- return;
78
- }
79
- messages.push({
80
- id,
81
- defaultMessage: (_a = staticStringOf(node, 'defaultMessage')) !== null && _a !== void 0 ? _a : '',
82
- description: (_b = staticStringOf(node, 'description')) !== null && _b !== void 0 ? _b : ''
83
- });
84
- });
85
- }
86
- return { messages, dynamicIds: [...new Set(dynamicIds)] };
87
- }
88
- function check(cwd) {
89
- var _a;
90
- const { messages, dynamicIds } = messagesDeclaredIn(cwd);
91
- const own = (0, csv_1.readCsvFile)(path_1.default.join(cwd, OWN_FILE));
92
- const covered = new Set([own, ...CORE_FILES.map((file) => (0, csv_1.readCsvFile)(path_1.default.join(cwd, file)))]
93
- .flatMap((csv) => { var _a; return (_a = csv === null || csv === void 0 ? void 0 : csv.body) !== null && _a !== void 0 ? _a : []; })
94
- .map(csv_1.idOf));
95
- // The same message is often declared in more than one place.
96
- const missing = [
97
- ...new Map(messages
98
- .filter(({ id }) => !covered.has(id))
99
- .map((message) => [message.id, message])).values()
100
- ].sort((a, b) => (a.id < b.id ? -1 : 1));
101
- const declared = new Set(messages.map(({ id }) => id));
102
- const outdated = ((_a = own === null || own === void 0 ? void 0 : own.body) !== null && _a !== void 0 ? _a : [])
103
- .map(csv_1.idOf)
104
- .filter((id) => !declared.has(id));
105
- return { missing, outdated, dynamicIds };
106
- }
107
- /**
108
- * Adds a row per missing message, filling in only English — the rest is copy
109
- * somebody has to write. Returns the ids added.
110
- */
111
- function writeMissing(cwd, missing) {
112
- const file = (0, csv_1.readCsvFile)(path_1.default.join(cwd, OWN_FILE));
113
- if (!file) {
114
- throw new Error(`${OWN_FILE} not found in ${cwd}`);
115
- }
116
- const columns = file.header.split(',');
117
- const rows = missing.map((message) => (0, csv_1.toCsvLine)(columns.map((column) => {
118
- if (column === 'id')
119
- return message.id;
120
- if (column === 'description')
121
- return message.description;
122
- return column === 'en' ? message.defaultMessage : '';
123
- })));
124
- const added = (0, csv_1.addRows)(file, rows);
125
- (0, csv_1.writeCsvFile)(path_1.default.join(cwd, OWN_FILE), file);
126
- return added;
127
- }