@opencrvs/toolkit 2.1.0-rc.ffe0b7f → 2.1.1-rc.52250d8

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 (243) hide show
  1. package/README.md +2 -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 +5 -2
  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 +3735 -1218
  11. package/dist/commons/api/router.d.ts +940 -363
  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 -26
  40. package/dist/commons/events/mocks.test.utils.d.ts +30 -0
  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/derived-variables.d.ts +18 -0
  52. package/dist/environment/derived-variables.d.ts.map +1 -1
  53. package/dist/environment/derived-variables.js +22 -1
  54. package/dist/environment/index.d.ts.map +1 -1
  55. package/dist/environment/index.js +2 -1
  56. package/dist/environment/logger.d.ts +15 -3
  57. package/dist/environment/logger.d.ts.map +1 -1
  58. package/dist/environment/manage-users.js +1 -1
  59. package/dist/environment/questions.d.ts +1 -1
  60. package/dist/environment/questions.d.ts.map +1 -1
  61. package/dist/environment/questions.js +27 -18
  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 +610 -560
  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 +3 -8
  69. package/dist/environment/update-workflows.d.ts.map +1 -1
  70. package/dist/environment/update-workflows.js +4 -0
  71. package/dist/environment/utils.d.ts +0 -12
  72. package/dist/environment/utils.d.ts.map +1 -1
  73. package/dist/environment/utils.js +1 -28
  74. package/dist/events/index.js +7689 -7063
  75. package/dist/migrations/v2.1/add-recovery-link-notifications.d.ts +3 -0
  76. package/dist/migrations/v2.1/add-recovery-link-notifications.d.ts.map +1 -0
  77. package/dist/migrations/v2.1/add-recovery-link-notifications.js +511 -0
  78. package/dist/migrations/v2.1/add-translations.d.ts +9 -0
  79. package/dist/migrations/v2.1/add-translations.d.ts.map +1 -0
  80. package/dist/migrations/v2.1/add-translations.js +149 -0
  81. package/dist/migrations/{v2.0/rename-api-paths.d.ts → v2.1/enable-telemetry.d.ts} +1 -1
  82. package/dist/migrations/v2.1/enable-telemetry.d.ts.map +1 -0
  83. package/dist/migrations/v2.1/enable-telemetry.js +455 -0
  84. package/dist/migrations/v2.1/index.d.ts.map +1 -1
  85. package/dist/migrations/v2.1/index.js +2015 -0
  86. package/dist/migrations/v2.1/migrate-infrastructure-to-assets.d.ts +14 -0
  87. package/dist/migrations/v2.1/migrate-infrastructure-to-assets.d.ts.map +1 -0
  88. package/dist/migrations/v2.1/migrate-infrastructure-to-assets.js +348 -0
  89. package/dist/migrations/v2.1/remove-metabase-package-installs.d.ts +2 -0
  90. package/dist/migrations/v2.1/remove-metabase-package-installs.d.ts.map +1 -0
  91. package/dist/migrations/v2.1/remove-metabase-package-installs.js +161 -0
  92. package/dist/migrations/{v2.0/migrate-scopes.d.ts → v2.1/remove-sentry.d.ts} +1 -1
  93. package/dist/migrations/v2.1/remove-sentry.d.ts.map +1 -0
  94. package/dist/migrations/v2.1/remove-sentry.js +354 -0
  95. package/dist/migrations/v2.1/remove-typings-from-dockerfile.d.ts +3 -0
  96. package/dist/migrations/v2.1/remove-typings-from-dockerfile.d.ts.map +1 -0
  97. package/dist/migrations/v2.1/remove-typings-from-dockerfile.js +121 -0
  98. package/dist/migrations/{v2.0/create-events-index.d.ts → v2.1/rename-trigger-paths.d.ts} +1 -1
  99. package/dist/migrations/v2.1/rename-trigger-paths.d.ts.map +1 -0
  100. package/dist/migrations/{v2.0/rename-api-paths.js → v2.1/rename-trigger-paths.js} +69 -40
  101. package/dist/migrations/v2.1/template-files.d.ts +8 -0
  102. package/dist/migrations/v2.1/template-files.d.ts.map +1 -0
  103. package/dist/migrations/v2.1/template-files.js +49 -0
  104. package/dist/migrations/v2.1/upgrade-tilt.d.ts +8 -0
  105. package/dist/migrations/v2.1/upgrade-tilt.d.ts.map +1 -0
  106. package/dist/migrations/v2.1/upgrade-tilt.js +139 -0
  107. package/dist/notification/index.js +1887 -1438
  108. package/dist/scopes/index.d.ts +614 -36
  109. package/dist/scopes/index.js +351 -65
  110. package/dist/telemetry/index.d.ts +45 -0
  111. package/dist/telemetry/index.d.ts.map +1 -0
  112. package/dist/telemetry/index.js +43 -0
  113. package/dist/templates/charts-values/dependencies/values.yaml +8 -0
  114. package/dist/templates/charts-values/opencrvs-services/values.yaml +10 -3
  115. package/dist/templates/charts-values/opentelemetry/values.yaml +102 -0
  116. package/dist/templates/charts-values/traefik/values.yaml +23 -9
  117. package/dist/templates/countryconfig-template/.tiltignore +1 -0
  118. package/dist/templates/countryconfig-template/Dockerfile.assets +7 -0
  119. package/dist/templates/countryconfig-template/Tiltfile +112 -0
  120. package/dist/templates/countryconfig-template/assets/README.md +1 -0
  121. package/dist/templates/countryconfig-template/assets/clear-all-data-dev.sh +61 -0
  122. package/dist/templates/countryconfig-template/assets/deployment/deploy.sh +455 -0
  123. package/dist/templates/countryconfig-template/assets/deployment/reindex.sh +168 -0
  124. package/dist/templates/countryconfig-template/assets/deployment/validate-required-variables-in-compose-files.ts +67 -0
  125. package/dist/templates/countryconfig-template/assets/elasticsearch/reindex.sh +168 -0
  126. package/dist/templates/countryconfig-template/assets/metabase/README.md +34 -0
  127. package/dist/templates/countryconfig-template/assets/metabase/environment-configuration.sql +36 -0
  128. package/dist/templates/countryconfig-template/assets/metabase/initialize-database.sh +46 -0
  129. package/dist/templates/countryconfig-template/assets/metabase/metabase.init.db.sql +27737 -0
  130. package/dist/templates/countryconfig-template/assets/metabase/open-shell.sh +21 -0
  131. package/dist/templates/countryconfig-template/assets/metabase/package.json +13 -0
  132. package/dist/templates/countryconfig-template/assets/metabase/run-dev.sh +108 -0
  133. package/dist/templates/countryconfig-template/assets/metabase/run.sh +120 -0
  134. package/dist/templates/countryconfig-template/assets/metabase/update-database.sh +40 -0
  135. package/dist/templates/countryconfig-template/assets/postgres/setup-analytics.sh +135 -0
  136. package/dist/templates/countryconfig-template/assets/postgres/setup-reference-data.sh +108 -0
  137. package/dist/templates/countryconfig-template/tilt/clear-all-data.ps1 +50 -0
  138. package/dist/templates/countryconfig-template/tilt/clear-all-data.sh +35 -0
  139. package/dist/templates/countryconfig-template/tilt/common.tilt +145 -0
  140. package/dist/templates/countryconfig-template/tilt/examples/dependencies/values.yaml +15 -0
  141. package/dist/templates/countryconfig-template/tilt/examples/opencrvs-services/values.yaml +56 -0
  142. package/dist/templates/countryconfig-template/tilt/examples/traefik/values-minikube.yaml +21 -0
  143. package/dist/templates/countryconfig-template/tilt/examples/traefik/values.yaml +38 -0
  144. package/dist/templates/countryconfig-template/tilt/helm/dependencies/values.yaml +17 -0
  145. package/dist/templates/countryconfig-template/tilt/helm/opencrvs-services/values.yaml +16 -0
  146. package/dist/templates/countryconfig-template/tilt/lib.tilt +95 -0
  147. package/dist/templates/countryconfig-template/tilt/opencrvs.tilt +136 -0
  148. package/dist/templates/inventory/inventory.template.yml +1 -3
  149. package/dist/translations/template.d.ts +11 -0
  150. package/dist/translations/template.d.ts.map +1 -0
  151. package/dist/translations/template.js +100 -0
  152. package/dist/verify/endpoints.d.ts +2 -0
  153. package/dist/verify/endpoints.d.ts.map +1 -0
  154. package/dist/verify/endpoints.js +510 -0
  155. package/opencrvs-toolkit-2.1.1-rc.52250d8.tgz +0 -0
  156. package/package.json +13 -7
  157. package/tsconfig.build.json +11 -0
  158. package/tsconfig.build.tsbuildinfo +1 -0
  159. package/tsconfig.json +3 -0
  160. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts +0 -3
  161. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts.map +0 -1
  162. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.js +0 -429
  163. package/dist/migrations/v2.0/add-resend-invite-notification.d.ts +0 -3
  164. package/dist/migrations/v2.0/add-resend-invite-notification.d.ts.map +0 -1
  165. package/dist/migrations/v2.0/add-resend-invite-notification.js +0 -373
  166. package/dist/migrations/v2.0/checkout-upstream-files.d.ts +0 -22
  167. package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +0 -1
  168. package/dist/migrations/v2.0/checkout-upstream-files.js +0 -146
  169. package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts +0 -2
  170. package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts.map +0 -1
  171. package/dist/migrations/v2.0/convert-config-files-to-ts.js +0 -838
  172. package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts +0 -3
  173. package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts.map +0 -1
  174. package/dist/migrations/v2.0/convert-paragraph-to-heading.js +0 -158
  175. package/dist/migrations/v2.0/create-events-index.d.ts.map +0 -1
  176. package/dist/migrations/v2.0/create-events-index.js +0 -325
  177. package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts +0 -11
  178. package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts.map +0 -1
  179. package/dist/migrations/v2.0/delete-infrastructure-directory.js +0 -123
  180. package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.d.ts +0 -3
  181. package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.d.ts.map +0 -1
  182. package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.js +0 -110
  183. package/dist/migrations/v2.0/index.d.ts +0 -13
  184. package/dist/migrations/v2.0/index.d.ts.map +0 -1
  185. package/dist/migrations/v2.0/index.js +0 -103
  186. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts +0 -3
  187. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts.map +0 -1
  188. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.js +0 -432
  189. package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts +0 -13
  190. package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts.map +0 -1
  191. package/dist/migrations/v2.0/merge-infrastructure-directory.js +0 -222
  192. package/dist/migrations/v2.0/migrate-application-config-url.d.ts +0 -3
  193. package/dist/migrations/v2.0/migrate-application-config-url.d.ts.map +0 -1
  194. package/dist/migrations/v2.0/migrate-application-config-url.js +0 -343
  195. package/dist/migrations/v2.0/migrate-scopes.d.ts.map +0 -1
  196. package/dist/migrations/v2.0/migrate-scopes.js +0 -305
  197. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts +0 -3
  198. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts.map +0 -1
  199. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.js +0 -267
  200. package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts +0 -3
  201. package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts.map +0 -1
  202. package/dist/migrations/v2.0/migrate-workqueue-configs.js +0 -317
  203. package/dist/migrations/v2.0/remove-delete-actions.d.ts +0 -3
  204. package/dist/migrations/v2.0/remove-delete-actions.d.ts.map +0 -1
  205. package/dist/migrations/v2.0/remove-delete-actions.js +0 -156
  206. package/dist/migrations/v2.0/remove-demo-scope.d.ts +0 -3
  207. package/dist/migrations/v2.0/remove-demo-scope.d.ts.map +0 -1
  208. package/dist/migrations/v2.0/remove-demo-scope.js +0 -74
  209. package/dist/migrations/v2.0/remove-deprecated-imports.d.ts +0 -3
  210. package/dist/migrations/v2.0/remove-deprecated-imports.d.ts.map +0 -1
  211. package/dist/migrations/v2.0/remove-deprecated-imports.js +0 -96
  212. package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts +0 -3
  213. package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts.map +0 -1
  214. package/dist/migrations/v2.0/remove-fhir-url-helpers.js +0 -163
  215. package/dist/migrations/v2.0/remove-hearth-migrations.d.ts +0 -3
  216. package/dist/migrations/v2.0/remove-hearth-migrations.d.ts.map +0 -1
  217. package/dist/migrations/v2.0/remove-hearth-migrations.js +0 -87
  218. package/dist/migrations/v2.0/remove-old-statistics-service.d.ts +0 -3
  219. package/dist/migrations/v2.0/remove-old-statistics-service.d.ts.map +0 -1
  220. package/dist/migrations/v2.0/remove-old-statistics-service.js +0 -356
  221. package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts +0 -3
  222. package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts.map +0 -1
  223. package/dist/migrations/v2.0/remove-pending-certification-flag.js +0 -109
  224. package/dist/migrations/v2.0/remove-review-from-register-action.d.ts +0 -3
  225. package/dist/migrations/v2.0/remove-review-from-register-action.d.ts.map +0 -1
  226. package/dist/migrations/v2.0/remove-review-from-register-action.js +0 -163
  227. package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts +0 -3
  228. package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts.map +0 -1
  229. package/dist/migrations/v2.0/remove-unused-environment-variables.js +0 -186
  230. package/dist/migrations/v2.0/rename-api-paths.d.ts.map +0 -1
  231. package/dist/migrations/v2.0/rename-location-parent-id.d.ts +0 -3
  232. package/dist/migrations/v2.0/rename-location-parent-id.d.ts.map +0 -1
  233. package/dist/migrations/v2.0/rename-location-parent-id.js +0 -180
  234. package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts +0 -3
  235. package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts.map +0 -1
  236. package/dist/migrations/v2.0/simplify-analytics-precalculations.js +0 -195
  237. package/dist/migrations/v2.0/update-package-json.d.ts +0 -3
  238. package/dist/migrations/v2.0/update-package-json.d.ts.map +0 -1
  239. package/dist/migrations/v2.0/update-package-json.js +0 -105
  240. package/dist/templates/inventory/production.example.yml +0 -77
  241. package/dist/templates/inventory/qa.example.yml +0 -48
  242. package/opencrvs-toolkit-2.1.0-rc.ffe0b7f.tgz +0 -0
  243. package/tsconfig.tsbuildinfo +0 -1
@@ -24,35 +24,44 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
25
  exports.main = main;
26
26
  /**
27
- * Codemod: Rename Hapi route `path` values inside route configuration objects.
27
+ * Codemod: Rename the `/triggers/...` country config routes to `/trigger/...`.
28
28
  *
29
29
  * Usage:
30
- * ts-node -r tsconfig-paths/register src/migrations/v2.0/rename-api-paths.ts
30
+ * ts-node -r tsconfig-paths/register src/migrations/v2.1/rename-trigger-paths.ts
31
+ *
32
+ * Why:
33
+ * The user-notification and system-ready triggers were served under
34
+ * `/triggers/`, while the event action and telemetry triggers use
35
+ * `/trigger/`. v2.1 settles on the singular prefix for all of them, so core
36
+ * now posts to `/trigger/user/*` and gets `/trigger/system/ready`. A route
37
+ * left on the old path answers 404, which core logs and moves on from — the
38
+ * notification is simply never sent and the country config's integrations
39
+ * are never registered. See CHANGELOG.md ("Country config triggers are all
40
+ * served under /trigger").
31
41
  *
32
42
  * What it does:
33
43
  * - Scans all TypeScript files under `src/`
34
- * - Finds every object literal that looks like a Hapi route config, i.e. one that
35
- * has both a `method` property whose value is a recognised HTTP verb (or an array
36
- * of them) and a `path` property whose value is a string literal
37
- * - Applies every rename listed in PATH_RENAMES to the `path` value
44
+ * - Finds every object literal that looks like a Hapi route config (a
45
+ * `method` property holding an HTTP verb, or an array of them, plus a
46
+ * string-literal `path`)
47
+ * - Rewrites a `path` starting with any prefix in PATH_PREFIX_RENAMES
38
48
  * - Saves the modified files in-place
39
- *
40
- * Adding new renames:
41
- * Add an entry to the PATH_RENAMES map below. Keys are the old path strings,
42
- * values are the new path strings. Exact string matching is used — no wildcards.
49
+ * - Warns about every remaining `/triggers/` occurrence under `src/`, which
50
+ * is anything this codemod cannot rewrite safely: a path built from a
51
+ * template literal or variable, a route config it did not recognise, or a
52
+ * test that requests the old path
43
53
  */
44
54
  const ts_morph_1 = require("ts-morph");
45
55
  const path_1 = __importDefault(require("path"));
46
56
  // ─── Path rename table ────────────────────────────────────────────────────────
47
- // Add new renames here as further API paths are changed between versions.
48
- const PATH_RENAMES = {
49
- '/events': '/config/events',
50
- '/application-config': '/config/application',
51
- '/workqueue': '/config/workqueues',
52
- '/locations': '/config/locations',
53
- '/users': '/config/users',
54
- '/roles': '/config/roles'
57
+ // Prefixes rather than whole paths: `/triggers/user/` covers one route per
58
+ // `TriggerEvent`, and a country config may have added its own.
59
+ const PATH_PREFIX_RENAMES = {
60
+ '/triggers/user/': '/trigger/user/',
61
+ '/triggers/system/': '/trigger/system/'
55
62
  };
63
+ /** Matched against the remaining source text once the renames are applied. */
64
+ const STALE_PREFIX = '/triggers/';
56
65
  // ─── Constants ────────────────────────────────────────────────────────────────
57
66
  const METHOD_PROPERTY_NAME = 'method';
58
67
  const PATH_PROPERTY_NAME = 'path';
@@ -68,15 +77,11 @@ const HTTP_VERBS = new Set([
68
77
  ]);
69
78
  // ─── Helpers ──────────────────────────────────────────────────────────────────
70
79
  /**
71
- * Returns true when the given object literal looks like a Hapi route config.
72
- *
73
- * A route config must have:
74
- * - a `method` property whose value is either a recognised HTTP verb string
75
- * literal, or an array literal whose elements are all recognised verb strings
76
- * - a `path` property whose value is a string literal
80
+ * Returns true when the given object literal looks like a Hapi route config,
81
+ * i.e. it has a `method` property holding a recognised HTTP verb string (or an
82
+ * array of them) and a string-literal `path` property.
77
83
  */
78
84
  function isRouteConfig(obj) {
79
- // ── method check ────────────────────────────────────────────────────────────
80
85
  const methodProp = obj.getProperty(METHOD_PROPERTY_NAME);
81
86
  if (!methodProp || !ts_morph_1.Node.isPropertyAssignment(methodProp))
82
87
  return false;
@@ -98,7 +103,6 @@ function isRouteConfig(obj) {
98
103
  else {
99
104
  return false;
100
105
  }
101
- // ── path check ──────────────────────────────────────────────────────────────
102
106
  const pathProp = obj.getProperty(PATH_PROPERTY_NAME);
103
107
  if (!pathProp || !ts_morph_1.Node.isPropertyAssignment(pathProp))
104
108
  return false;
@@ -106,8 +110,8 @@ function isRouteConfig(obj) {
106
110
  return !!pathInit && ts_morph_1.Node.isStringLiteral(pathInit);
107
111
  }
108
112
  /**
109
- * Applies PATH_RENAMES to the `path` property of a confirmed route config object.
110
- * Returns the new path string if a rename was applied, or null if no change was made.
113
+ * Applies PATH_PREFIX_RENAMES to the `path` of a confirmed route config.
114
+ * Returns the new path, or null when no prefix matched.
111
115
  */
112
116
  function renameRoutePath(obj) {
113
117
  const pathProp = obj.getProperty(PATH_PROPERTY_NAME);
@@ -117,9 +121,11 @@ function renameRoutePath(obj) {
117
121
  if (!pathInit || !ts_morph_1.Node.isStringLiteral(pathInit))
118
122
  return null;
119
123
  const oldPath = pathInit.getLiteralValue();
120
- const newPath = PATH_RENAMES[oldPath];
121
- if (!newPath)
124
+ const match = Object.entries(PATH_PREFIX_RENAMES).find(([from]) => oldPath.startsWith(from));
125
+ if (!match)
122
126
  return null;
127
+ const [from, to] = match;
128
+ const newPath = to + oldPath.slice(from.length);
123
129
  pathInit.replaceWithText(`'${newPath}'`);
124
130
  return newPath;
125
131
  }
@@ -143,14 +149,35 @@ function processFile(filePath, project) {
143
149
  }
144
150
  return renamedCount;
145
151
  }
152
+ /**
153
+ * Reports leftover `/triggers/` occurrences. Rewriting these is guesswork —
154
+ * the path may be assembled at runtime — but leaving them unmentioned would
155
+ * hide a route that still answers on the old path.
156
+ */
157
+ function warnAboutStalePaths(sourceFiles) {
158
+ const stale = [];
159
+ for (const sourceFile of sourceFiles) {
160
+ const relPath = path_1.default.relative(process.cwd(), sourceFile.getFilePath());
161
+ const lines = sourceFile.getFullText().split('\n');
162
+ lines.forEach((line, index) => {
163
+ if (line.includes(STALE_PREFIX)) {
164
+ stale.push(` ${relPath}:${index + 1}: ${line.trim()}`);
165
+ }
166
+ });
167
+ }
168
+ if (stale.length === 0)
169
+ return;
170
+ console.log(`\nWARNING: ${stale.length} remaining '${STALE_PREFIX}' reference(s) need to be renamed by hand:`);
171
+ console.log(stale.join('\n'));
172
+ }
146
173
  // ─── Entry point ─────────────────────────────────────────────────────────────
147
174
  function main() {
148
175
  return __awaiter(this, void 0, void 0, function* () {
149
176
  const srcDir = path_1.default.join(process.cwd(), 'src');
150
177
  console.log(`Scanning for Hapi route configs in: ${srcDir}\n`);
151
178
  console.log('Active path renames:');
152
- for (const [from, to] of Object.entries(PATH_RENAMES)) {
153
- console.log(` '${from}' → '${to}'`);
179
+ for (const [from, to] of Object.entries(PATH_PREFIX_RENAMES)) {
180
+ console.log(` '${from}*' → '${to}*'`);
154
181
  }
155
182
  console.log();
156
183
  const project = new ts_morph_1.Project({
@@ -173,15 +200,17 @@ function main() {
173
200
  }
174
201
  }
175
202
  if (modifiedFiles.length === 0) {
176
- console.log('No matching route paths found. Nothing to do.');
177
- return;
203
+ console.log('No trigger route paths to rename.');
178
204
  }
179
- console.log(`\nSaving ${modifiedFiles.length} modified file(s)...`);
180
- for (const filePath of modifiedFiles) {
181
- const sourceFile = project.getSourceFileOrThrow(filePath);
182
- yield sourceFile.save();
183
- console.log(` Saved: ${path_1.default.relative(process.cwd(), filePath)}`);
205
+ else {
206
+ console.log(`\nSaving ${modifiedFiles.length} modified file(s)...`);
207
+ for (const filePath of modifiedFiles) {
208
+ const sourceFile = project.getSourceFileOrThrow(filePath);
209
+ yield sourceFile.save();
210
+ console.log(` Saved: ${path_1.default.relative(process.cwd(), filePath)}`);
211
+ }
212
+ console.log(`\nDone. Renamed ${totalRenamed} route path(s).`);
184
213
  }
185
- console.log(`\nDone. Renamed ${totalRenamed} route path(s).`);
214
+ warnAboutStalePaths(sourceFiles);
186
215
  });
187
216
  }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Where the bundled template files are: next to the built CLI in `dist/`, or
3
+ * the template package itself when running from source (tests, ts-node).
4
+ */
5
+ export declare function findTemplateDir(): string;
6
+ /** Every file under `dir`, relative to `root`, with forward slashes. */
7
+ export declare function listFiles(root: string, dir: string): string[];
8
+ //# sourceMappingURL=template-files.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"template-files.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.1/template-files.ts"],"names":[],"mappings":"AAmBA;;;GAGG;AACH,wBAAgB,eAAe,WAiB9B;AAED,wEAAwE;AACxE,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAW7D"}
@@ -0,0 +1,49 @@
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.findTemplateDir = findTemplateDir;
17
+ exports.listFiles = listFiles;
18
+ /**
19
+ * Country config template files bundled into the toolkit by `build.sh`, shared
20
+ * by the codemods that copy them into a country config.
21
+ */
22
+ const fs_1 = require("fs");
23
+ const path_1 = __importDefault(require("path"));
24
+ /**
25
+ * Where the bundled template files are: next to the built CLI in `dist/`, or
26
+ * the template package itself when running from source (tests, ts-node).
27
+ */
28
+ function findTemplateDir() {
29
+ const candidates = [
30
+ path_1.default.resolve(__dirname, 'templates', 'countryconfig-template'),
31
+ path_1.default.resolve(__dirname, '../../../../countryconfig-template')
32
+ ];
33
+ const templateDir = candidates.find((candidate) => (0, fs_1.existsSync)(path_1.default.join(candidate, 'Tiltfile')));
34
+ if (!templateDir) {
35
+ throw new Error(`Country config template files not found in any of: ${candidates.join(', ')}`);
36
+ }
37
+ return templateDir;
38
+ }
39
+ /** Every file under `dir`, relative to `root`, with forward slashes. */
40
+ function listFiles(root, dir) {
41
+ const absolute = path_1.default.join(root, dir);
42
+ if (!(0, fs_1.existsSync)(absolute)) {
43
+ return [];
44
+ }
45
+ return (0, fs_1.readdirSync)(absolute, { withFileTypes: true }).flatMap((entry) => {
46
+ const relative = path_1.default.posix.join(dir, entry.name);
47
+ return entry.isDirectory() ? listFiles(root, relative) : [relative];
48
+ });
49
+ }
@@ -0,0 +1,8 @@
1
+ /** TODO: ????? The template Tiltfile, keeping the image name the country already uses. */
2
+ export declare function renderTiltfile(template: string, existing?: string): string;
3
+ /** `contents` with `line` appended, unless an equivalent entry is there already. */
4
+ export declare function withIgnoreEntry(contents: string, line: string): string;
5
+ export declare function upgradeTilt(cwd: string, templateDir: string): void;
6
+ declare function main(): Promise<void>;
7
+ export { main };
8
+ //# sourceMappingURL=upgrade-tilt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upgrade-tilt.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.1/upgrade-tilt.ts"],"names":[],"mappings":"AAyFA,0FAA0F;AAC1F,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,UAYjE;AAED,oFAAoF;AACpF,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAc7D;AAQD,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,QA0D3D;AAED,iBAAe,IAAI,kBAQlB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
@@ -0,0 +1,139 @@
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.renderTiltfile = renderTiltfile;
26
+ exports.withIgnoreEntry = withIgnoreEntry;
27
+ exports.upgradeTilt = upgradeTilt;
28
+ exports.main = main;
29
+ /**
30
+ * Codemod: bring the local Tilt setup in line with the country config template.
31
+ *
32
+ * Up to v2.0 the Tiltfile cloned opencrvs/opencrvs-helm-charts into a sibling
33
+ * `../opencrvs-helm-charts` directory and loaded its `tilt/opencrvs.tilt`. The
34
+ * charts now live in opencrvs-core, and the Tilt helpers ship with the country
35
+ * config itself under `tilt/`.
36
+ *
37
+ * What it does:
38
+ * 1. Replaces `Tiltfile` with the template's, carrying over the country's
39
+ * `countryconfig_image_name`.
40
+ * 2. Replaces every file under `tilt/` that core owns (the helpers and
41
+ * `tilt/examples/`) with the template's.
42
+ * 3. Creates `tilt/helm/<chart>/values.yaml` when missing. These hold the
43
+ * country's own overrides and are never overwritten.
44
+ * 4. Adds `.opencrvs-core-charts/` (the Tiltfile's charts checkout) to
45
+ * `.tiltignore` and `.gitignore`.
46
+ *
47
+ * The template files are bundled into the toolkit at build time, so they always
48
+ * match the toolkit version being run.
49
+ *
50
+ * Caveats:
51
+ * - Local changes to the Tiltfile or to core owned files under `tilt/` are
52
+ * overwritten. Review them with `git diff -- Tiltfile tilt/` and move
53
+ * chart overrides into `tilt/helm/`.
54
+ * - Files under `tilt/` that the template does not have are left in place.
55
+ */
56
+ const fs_1 = require("fs");
57
+ const path_1 = __importDefault(require("path"));
58
+ const template_files_1 = require("./template-files");
59
+ /** Paths under `tilt/` the country owns: created when missing, never replaced. */
60
+ const COUNTRY_OWNED_DIR = 'tilt/helm/';
61
+ const CHARTS_CHECKOUT_DIR = '.opencrvs-core-charts';
62
+ const IMAGE_NAME_PATTERN = /^countryconfig_image_name\s*=\s*(["'])(.*?)\1/m;
63
+ function writeIfChanged(cwd, relativePath, contents, mode) {
64
+ const target = path_1.default.join(cwd, relativePath);
65
+ const existed = (0, fs_1.existsSync)(target);
66
+ if (existed && (0, fs_1.readFileSync)(target, 'utf8') === contents) {
67
+ return 'unchanged';
68
+ }
69
+ (0, fs_1.mkdirSync)(path_1.default.dirname(target), { recursive: true });
70
+ (0, fs_1.writeFileSync)(target, contents);
71
+ // Keeps shell scripts such as clear-all-data.sh executable
72
+ if (mode !== undefined) {
73
+ (0, fs_1.chmodSync)(target, mode & 0o777);
74
+ }
75
+ return existed ? 'updated' : 'created';
76
+ }
77
+ function report(relativePath, change) {
78
+ if (change !== 'unchanged') {
79
+ console.log(` ✓ ${change} ${relativePath}`);
80
+ }
81
+ }
82
+ /** TODO: ????? The template Tiltfile, keeping the image name the country already uses. */
83
+ function renderTiltfile(template, existing) {
84
+ var _a;
85
+ const imageName = (_a = existing === null || existing === void 0 ? void 0 : existing.match(IMAGE_NAME_PATTERN)) === null || _a === void 0 ? void 0 : _a[2];
86
+ if (!imageName) {
87
+ return template;
88
+ }
89
+ return template.replace(IMAGE_NAME_PATTERN, (_line, quote) => `countryconfig_image_name=${quote}${imageName}${quote}`);
90
+ }
91
+ /** `contents` with `line` appended, unless an equivalent entry is there already. */
92
+ function withIgnoreEntry(contents, line) {
93
+ const normalise = (entry) => entry.trim().replace(/^\//, '').replace(/\/$/, '');
94
+ const alreadyIgnored = contents
95
+ .split(/\r?\n/)
96
+ .some((entry) => normalise(entry) === normalise(line));
97
+ if (alreadyIgnored) {
98
+ return contents;
99
+ }
100
+ const separator = contents === '' || contents.endsWith('\n') ? '' : '\n';
101
+ return `${contents}${separator}${line}\n`;
102
+ }
103
+ function ensureIgnored(cwd, file, line) {
104
+ const target = path_1.default.join(cwd, file);
105
+ const contents = (0, fs_1.existsSync)(target) ? (0, fs_1.readFileSync)(target, 'utf8') : '';
106
+ report(file, writeIfChanged(cwd, file, withIgnoreEntry(contents, line)));
107
+ }
108
+ function upgradeTilt(cwd, templateDir) {
109
+ const tiltfilePath = path_1.default.join(cwd, 'Tiltfile');
110
+ const existingTiltfile = (0, fs_1.existsSync)(tiltfilePath)
111
+ ? (0, fs_1.readFileSync)(tiltfilePath, 'utf8')
112
+ : undefined;
113
+ report('Tiltfile', writeIfChanged(cwd, 'Tiltfile', renderTiltfile((0, fs_1.readFileSync)(path_1.default.join(templateDir, 'Tiltfile'), 'utf8'), existingTiltfile)));
114
+ const templateFiles = (0, template_files_1.listFiles)(templateDir, 'tilt');
115
+ for (const file of templateFiles) {
116
+ const source = path_1.default.join(templateDir, file);
117
+ const countryOwned = file.startsWith(COUNTRY_OWNED_DIR);
118
+ if (countryOwned && (0, fs_1.existsSync)(path_1.default.join(cwd, file))) {
119
+ continue;
120
+ }
121
+ report(file, writeIfChanged(cwd, file, (0, fs_1.readFileSync)(source, 'utf8'), (0, fs_1.statSync)(source).mode));
122
+ }
123
+ const unknownFiles = (0, template_files_1.listFiles)(cwd, 'tilt').filter((file) => !file.startsWith(COUNTRY_OWNED_DIR) && !templateFiles.includes(file));
124
+ for (const file of unknownFiles) {
125
+ console.warn(` ⚠️ ${file} is not part of the template and was left in place.`);
126
+ }
127
+ ensureIgnored(cwd, '.tiltignore', `${CHARTS_CHECKOUT_DIR}/`);
128
+ ensureIgnored(cwd, '.gitignore', CHARTS_CHECKOUT_DIR);
129
+ if (existingTiltfile === null || existingTiltfile === void 0 ? void 0 : existingTiltfile.includes('opencrvs-helm-charts')) {
130
+ console.log(` ℹ️ The Tiltfile no longer uses ../opencrvs-helm-charts; charts are cloned into ${CHARTS_CHECKOUT_DIR}/ instead. The old checkout can be deleted.`);
131
+ }
132
+ }
133
+ function main() {
134
+ return __awaiter(this, void 0, void 0, function* () {
135
+ console.log('Upgrading the local Tilt setup...\n');
136
+ upgradeTilt(process.cwd(), (0, template_files_1.findTemplateDir)());
137
+ console.log('\n Review local customisations with: git diff -- Tiltfile tilt/ .tiltignore .gitignore\n');
138
+ });
139
+ }