@opencrvs/toolkit 2.1.0-rc.ffe0b7f → 2.2.0-rc.ab91cce

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 (246) hide show
  1. package/README.md +2 -12
  2. package/build.sh +23 -5
  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 +2041 -1311
  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 +77 -7
  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 +29 -6
  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/eventConfigValidation.d.ts +17 -1
  38. package/dist/commons/events/index.d.ts +1 -0
  39. package/dist/commons/events/locationPayloads.d.ts +95 -0
  40. package/dist/commons/events/locations.d.ts +169 -26
  41. package/dist/commons/events/mocks.test.utils.d.ts +30 -0
  42. package/dist/commons/events/scopes.d.ts +21 -1
  43. package/dist/commons/events/test.utils.d.ts +83 -25
  44. package/dist/commons/events/utils.d.ts +52 -17
  45. package/dist/commons/notification/UserNotifications.d.ts +28 -13
  46. package/dist/commons/notification/dispatch.d.ts +10 -0
  47. package/dist/commons/notification/index.d.ts +1 -0
  48. package/dist/conditionals/index.js +349 -65
  49. package/dist/csv.d.ts +25 -0
  50. package/dist/csv.d.ts.map +1 -0
  51. package/dist/csv.js +120 -0
  52. package/dist/environment/derived-variables.d.ts +18 -0
  53. package/dist/environment/derived-variables.d.ts.map +1 -1
  54. package/dist/environment/derived-variables.js +22 -1
  55. package/dist/environment/index.d.ts.map +1 -1
  56. package/dist/environment/index.js +2 -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/questions.d.ts.map +1 -1
  61. package/dist/environment/questions.js +20 -14
  62. package/dist/environment/setup-environment.d.ts +1 -1
  63. package/dist/environment/setup-environment.d.ts.map +1 -1
  64. package/dist/environment/setup-environment.js +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 +6115 -5378
  75. package/dist/migrations/add-translations.d.ts +15 -0
  76. package/dist/migrations/add-translations.d.ts.map +1 -0
  77. package/dist/migrations/add-translations.js +151 -0
  78. package/dist/migrations/v2.1/add-recovery-link-notifications.d.ts +3 -0
  79. package/dist/migrations/v2.1/add-recovery-link-notifications.d.ts.map +1 -0
  80. package/dist/migrations/v2.1/add-recovery-link-notifications.js +511 -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 +47 -215
  86. package/dist/migrations/v2.1/migrate-infrastructure-to-assets.d.ts +17 -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.0/create-events-index.d.ts → v2.1/rename-trigger-paths.d.ts} +1 -1
  96. package/dist/migrations/v2.1/rename-trigger-paths.d.ts.map +1 -0
  97. package/dist/migrations/{v2.0/rename-api-paths.js → v2.1/rename-trigger-paths.js} +69 -40
  98. package/dist/migrations/v2.1/template-files.d.ts +8 -0
  99. package/dist/migrations/v2.1/template-files.d.ts.map +1 -0
  100. package/dist/migrations/v2.1/template-files.js +49 -0
  101. package/dist/migrations/v2.1/upgrade-tilt.d.ts +11 -0
  102. package/dist/migrations/v2.1/upgrade-tilt.d.ts.map +1 -0
  103. package/dist/migrations/v2.1/upgrade-tilt.js +139 -0
  104. package/dist/migrations/v2.2/index.d.ts +6 -0
  105. package/dist/migrations/v2.2/index.d.ts.map +1 -0
  106. package/dist/migrations/v2.2/index.js +456 -0
  107. package/dist/migrations/v2.2/read-declaration-through-helper.d.ts +39 -0
  108. package/dist/migrations/v2.2/read-declaration-through-helper.d.ts.map +1 -0
  109. package/dist/migrations/v2.2/read-declaration-through-helper.js +257 -0
  110. package/dist/notification/index.js +2012 -1455
  111. package/dist/scopes/index.d.ts +614 -36
  112. package/dist/scopes/index.js +351 -65
  113. package/dist/telemetry/index.d.ts +45 -0
  114. package/dist/telemetry/index.d.ts.map +1 -0
  115. package/dist/telemetry/index.js +43 -0
  116. package/dist/templates/charts-values/dependencies/values.yaml +8 -0
  117. package/dist/templates/charts-values/opencrvs-services/values.yaml +10 -3
  118. package/dist/templates/charts-values/opentelemetry/values.yaml +102 -0
  119. package/dist/templates/charts-values/traefik/values.yaml +25 -12
  120. package/dist/templates/countryconfig-template/.tiltignore +1 -0
  121. package/dist/templates/countryconfig-template/Dockerfile.assets +7 -0
  122. package/dist/templates/countryconfig-template/Tiltfile +112 -0
  123. package/dist/templates/countryconfig-template/assets/README.md +1 -0
  124. package/dist/templates/countryconfig-template/assets/clear-all-data-dev.sh +61 -0
  125. package/dist/templates/countryconfig-template/assets/deployment/deploy.sh +455 -0
  126. package/dist/templates/countryconfig-template/assets/deployment/reindex.sh +168 -0
  127. package/dist/templates/countryconfig-template/assets/deployment/validate-required-variables-in-compose-files.ts +67 -0
  128. package/dist/templates/countryconfig-template/assets/elasticsearch/reindex.sh +168 -0
  129. package/dist/templates/countryconfig-template/assets/metabase/README.md +34 -0
  130. package/dist/templates/countryconfig-template/assets/metabase/environment-configuration.sql +36 -0
  131. package/dist/templates/countryconfig-template/assets/metabase/initialize-database.sh +46 -0
  132. package/dist/templates/countryconfig-template/assets/metabase/metabase.init.db.sql +27737 -0
  133. package/dist/templates/countryconfig-template/assets/metabase/open-shell.sh +21 -0
  134. package/dist/templates/countryconfig-template/assets/metabase/package.json +13 -0
  135. package/dist/templates/countryconfig-template/assets/metabase/run-dev.sh +108 -0
  136. package/dist/templates/countryconfig-template/assets/metabase/run.sh +120 -0
  137. package/dist/templates/countryconfig-template/assets/metabase/update-database.sh +40 -0
  138. package/dist/templates/countryconfig-template/assets/postgres/setup-analytics.sh +135 -0
  139. package/dist/templates/countryconfig-template/assets/postgres/setup-reference-data.sh +108 -0
  140. package/dist/templates/countryconfig-template/tilt/clear-all-data.ps1 +50 -0
  141. package/dist/templates/countryconfig-template/tilt/clear-all-data.sh +35 -0
  142. package/dist/templates/countryconfig-template/tilt/common.tilt +145 -0
  143. package/dist/templates/countryconfig-template/tilt/examples/dependencies/values.yaml +15 -0
  144. package/dist/templates/countryconfig-template/tilt/examples/opencrvs-services/values.yaml +56 -0
  145. package/dist/templates/countryconfig-template/tilt/examples/traefik/values-minikube.yaml +21 -0
  146. package/dist/templates/countryconfig-template/tilt/examples/traefik/values.yaml +38 -0
  147. package/dist/templates/countryconfig-template/tilt/helm/dependencies/values.yaml +17 -0
  148. package/dist/templates/countryconfig-template/tilt/helm/opencrvs-services/values.yaml +16 -0
  149. package/dist/templates/countryconfig-template/tilt/lib.tilt +95 -0
  150. package/dist/templates/countryconfig-template/tilt/opencrvs.tilt +136 -0
  151. package/dist/templates/inventory/inventory.template.yml +1 -3
  152. package/dist/translations/template.d.ts +11 -0
  153. package/dist/translations/template.d.ts.map +1 -0
  154. package/dist/translations/template.js +100 -0
  155. package/dist/verify/endpoints.d.ts +2 -0
  156. package/dist/verify/endpoints.d.ts.map +1 -0
  157. package/dist/verify/endpoints.js +510 -0
  158. package/opencrvs-toolkit-2.2.0-rc.ab91cce.tgz +0 -0
  159. package/package.json +13 -7
  160. package/tsconfig.build.json +11 -0
  161. package/tsconfig.build.tsbuildinfo +1 -0
  162. package/tsconfig.json +3 -0
  163. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts +0 -3
  164. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts.map +0 -1
  165. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.js +0 -429
  166. package/dist/migrations/v2.0/add-resend-invite-notification.d.ts +0 -3
  167. package/dist/migrations/v2.0/add-resend-invite-notification.d.ts.map +0 -1
  168. package/dist/migrations/v2.0/add-resend-invite-notification.js +0 -373
  169. package/dist/migrations/v2.0/checkout-upstream-files.d.ts +0 -22
  170. package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +0 -1
  171. package/dist/migrations/v2.0/checkout-upstream-files.js +0 -146
  172. package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts +0 -2
  173. package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts.map +0 -1
  174. package/dist/migrations/v2.0/convert-config-files-to-ts.js +0 -838
  175. package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts +0 -3
  176. package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts.map +0 -1
  177. package/dist/migrations/v2.0/convert-paragraph-to-heading.js +0 -158
  178. package/dist/migrations/v2.0/create-events-index.d.ts.map +0 -1
  179. package/dist/migrations/v2.0/create-events-index.js +0 -325
  180. package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts +0 -11
  181. package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts.map +0 -1
  182. package/dist/migrations/v2.0/delete-infrastructure-directory.js +0 -123
  183. package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.d.ts +0 -3
  184. package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.d.ts.map +0 -1
  185. package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.js +0 -110
  186. package/dist/migrations/v2.0/index.d.ts +0 -13
  187. package/dist/migrations/v2.0/index.d.ts.map +0 -1
  188. package/dist/migrations/v2.0/index.js +0 -103
  189. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts +0 -3
  190. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts.map +0 -1
  191. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.js +0 -432
  192. package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts +0 -13
  193. package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts.map +0 -1
  194. package/dist/migrations/v2.0/merge-infrastructure-directory.js +0 -222
  195. package/dist/migrations/v2.0/migrate-application-config-url.d.ts +0 -3
  196. package/dist/migrations/v2.0/migrate-application-config-url.d.ts.map +0 -1
  197. package/dist/migrations/v2.0/migrate-application-config-url.js +0 -343
  198. package/dist/migrations/v2.0/migrate-scopes.d.ts.map +0 -1
  199. package/dist/migrations/v2.0/migrate-scopes.js +0 -305
  200. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts +0 -3
  201. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts.map +0 -1
  202. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.js +0 -267
  203. package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts +0 -3
  204. package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts.map +0 -1
  205. package/dist/migrations/v2.0/migrate-workqueue-configs.js +0 -317
  206. package/dist/migrations/v2.0/remove-delete-actions.d.ts +0 -3
  207. package/dist/migrations/v2.0/remove-delete-actions.d.ts.map +0 -1
  208. package/dist/migrations/v2.0/remove-delete-actions.js +0 -156
  209. package/dist/migrations/v2.0/remove-demo-scope.d.ts +0 -3
  210. package/dist/migrations/v2.0/remove-demo-scope.d.ts.map +0 -1
  211. package/dist/migrations/v2.0/remove-demo-scope.js +0 -74
  212. package/dist/migrations/v2.0/remove-deprecated-imports.d.ts +0 -3
  213. package/dist/migrations/v2.0/remove-deprecated-imports.d.ts.map +0 -1
  214. package/dist/migrations/v2.0/remove-deprecated-imports.js +0 -96
  215. package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts +0 -3
  216. package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts.map +0 -1
  217. package/dist/migrations/v2.0/remove-fhir-url-helpers.js +0 -163
  218. package/dist/migrations/v2.0/remove-hearth-migrations.d.ts +0 -3
  219. package/dist/migrations/v2.0/remove-hearth-migrations.d.ts.map +0 -1
  220. package/dist/migrations/v2.0/remove-hearth-migrations.js +0 -87
  221. package/dist/migrations/v2.0/remove-old-statistics-service.d.ts +0 -3
  222. package/dist/migrations/v2.0/remove-old-statistics-service.d.ts.map +0 -1
  223. package/dist/migrations/v2.0/remove-old-statistics-service.js +0 -356
  224. package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts +0 -3
  225. package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts.map +0 -1
  226. package/dist/migrations/v2.0/remove-pending-certification-flag.js +0 -109
  227. package/dist/migrations/v2.0/remove-review-from-register-action.d.ts +0 -3
  228. package/dist/migrations/v2.0/remove-review-from-register-action.d.ts.map +0 -1
  229. package/dist/migrations/v2.0/remove-review-from-register-action.js +0 -163
  230. package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts +0 -3
  231. package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts.map +0 -1
  232. package/dist/migrations/v2.0/remove-unused-environment-variables.js +0 -186
  233. package/dist/migrations/v2.0/rename-api-paths.d.ts.map +0 -1
  234. package/dist/migrations/v2.0/rename-location-parent-id.d.ts +0 -3
  235. package/dist/migrations/v2.0/rename-location-parent-id.d.ts.map +0 -1
  236. package/dist/migrations/v2.0/rename-location-parent-id.js +0 -180
  237. package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts +0 -3
  238. package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts.map +0 -1
  239. package/dist/migrations/v2.0/simplify-analytics-precalculations.js +0 -195
  240. package/dist/migrations/v2.0/update-package-json.d.ts +0 -3
  241. package/dist/migrations/v2.0/update-package-json.d.ts.map +0 -1
  242. package/dist/migrations/v2.0/update-package-json.js +0 -105
  243. package/dist/templates/inventory/production.example.yml +0 -77
  244. package/dist/templates/inventory/qa.example.yml +0 -48
  245. package/opencrvs-toolkit-2.1.0-rc.ffe0b7f.tgz +0 -0
  246. package/tsconfig.tsbuildinfo +0 -1
@@ -1,218 +1,50 @@
1
- #!/usr/bin/env node
2
1
  "use strict";
3
- var __create = Object.create;
4
- var __defProp = Object.defineProperty;
5
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
- var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getProtoOf = Object.getPrototypeOf;
8
- var __hasOwnProp = Object.prototype.hasOwnProperty;
9
- var __export = (target, all) => {
10
- for (var name in all)
11
- __defProp(target, name, { get: all[name], enumerable: true });
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
12
10
  };
13
- var __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from === "object" || typeof from === "function") {
15
- for (let key of __getOwnPropNames(from))
16
- if (!__hasOwnProp.call(to, key) && key !== except)
17
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
- }
19
- return to;
20
- };
21
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
- // If the importer is in node compatibility mode or this is not an ESM
23
- // file that has been converted to a CommonJS file using a Babel-
24
- // compatible transform (i.e. "__esModule" has not been set), then set
25
- // "default" to the CommonJS "module.exports" for node compatibility.
26
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
- mod
28
- ));
29
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
-
31
- // src/migrations/v2.1/index.ts
32
- var v2_exports = {};
33
- __export(v2_exports, {
34
- runUpgrade: () => runUpgrade
35
- });
36
- module.exports = __toCommonJS(v2_exports);
37
-
38
- // src/migrations/v2.1/add-explicit-correction-flags.ts
39
- var import_ts_morph = require("ts-morph");
40
- var import_path = __toESM(require("path"));
41
- var DEFINE_CONFIG_NAME = "defineConfig";
42
- var ACTIONS_PROPERTY_NAME = "actions";
43
- var TYPE_PROPERTY_NAME = "type";
44
- var FLAGS_PROPERTY_NAME = "flags";
45
- var CONDITIONALS_PROPERTY_NAME = "conditionals";
46
- var ACTION_TYPE_ENUM_NAME = "ActionType";
47
- var REQUEST_CORRECTION_TYPE = "REQUEST_CORRECTION";
48
- var CORRECTION_ACTIONS_TO_ADD = [
49
- {
50
- actionType: "APPROVE_CORRECTION",
51
- labelId: "v2.events.correction.approve.label",
52
- defaultMessage: "Approve correction",
53
- description: "Label for the approve correction action"
54
- },
55
- {
56
- actionType: "REJECT_CORRECTION",
57
- labelId: "v2.events.correction.reject.label",
58
- defaultMessage: "Reject correction",
59
- description: "Label for the reject correction action"
60
- }
61
- ];
62
- function isActionOfType(obj, typeName) {
63
- const typeProperty = obj.getProperty(TYPE_PROPERTY_NAME);
64
- if (!typeProperty || !import_ts_morph.Node.isPropertyAssignment(typeProperty)) return false;
65
- const typeInit = typeProperty.getInitializer();
66
- if (!typeInit) return false;
67
- if (import_ts_morph.Node.isPropertyAccessExpression(typeInit)) {
68
- return typeInit.getExpression().getText() === ACTION_TYPE_ENUM_NAME && typeInit.getName() === typeName;
69
- }
70
- if (import_ts_morph.Node.isStringLiteral(typeInit)) {
71
- return typeInit.getLiteralValue() === typeName;
72
- }
73
- return false;
74
- }
75
- function getTypeInitializerStyle(obj) {
76
- const typeProperty = obj.getProperty(TYPE_PROPERTY_NAME);
77
- if (typeProperty && import_ts_morph.Node.isPropertyAssignment(typeProperty)) {
78
- const typeInit = typeProperty.getInitializer();
79
- if (typeInit && import_ts_morph.Node.isPropertyAccessExpression(typeInit)) return "enum";
80
- }
81
- return "string";
82
- }
83
- function getNonEmptyArrayPropertyText(obj, propName) {
84
- const prop = obj.getProperty(propName);
85
- if (!prop || !import_ts_morph.Node.isPropertyAssignment(prop)) return void 0;
86
- const init = prop.getInitializer();
87
- if (!init || !import_ts_morph.Node.isArrayLiteralExpression(init)) return void 0;
88
- if (init.getElements().length === 0) return void 0;
89
- return init.getText();
90
- }
91
- function buildCorrectionActionText(spec, typeStyle, flagsText, conditionalsText) {
92
- const typeText = typeStyle === "enum" ? `${ACTION_TYPE_ENUM_NAME}.${spec.actionType}` : `'${spec.actionType}'`;
93
- const lines = [
94
- `type: ${typeText}`,
95
- `label: {
96
- id: '${spec.labelId}',
97
- defaultMessage: '${spec.defaultMessage}',
98
- description: '${spec.description}'
99
- }`
100
- ];
101
- if (flagsText) {
102
- lines.push(`${FLAGS_PROPERTY_NAME}: ${flagsText}`);
103
- }
104
- if (conditionalsText) {
105
- lines.push(`${CONDITIONALS_PROPERTY_NAME}: ${conditionalsText}`);
106
- }
107
- return `{
108
- ${lines.join(",\n ")}
109
- }`;
110
- }
111
- function processFile(filePath, project) {
112
- const sourceFile = project.getSourceFile(filePath);
113
- if (!sourceFile) return 0;
114
- let changes = 0;
115
- const relPath = import_path.default.relative(process.cwd(), filePath);
116
- const callExpressions = sourceFile.getDescendantsOfKind(
117
- import_ts_morph.SyntaxKind.CallExpression
118
- );
119
- for (const call of callExpressions) {
120
- const expression = call.getExpression();
121
- if (!import_ts_morph.Node.isIdentifier(expression) || expression.getText() !== DEFINE_CONFIG_NAME) {
122
- continue;
123
- }
124
- const args = call.getArguments();
125
- if (args.length === 0) continue;
126
- const configArg = args[0];
127
- if (!import_ts_morph.Node.isObjectLiteralExpression(configArg)) continue;
128
- const actionsProperty = configArg.getProperty(ACTIONS_PROPERTY_NAME);
129
- if (!actionsProperty || !import_ts_morph.Node.isPropertyAssignment(actionsProperty))
130
- continue;
131
- const actionsInitializer = actionsProperty.getInitializer();
132
- if (!actionsInitializer || !import_ts_morph.Node.isArrayLiteralExpression(actionsInitializer))
133
- continue;
134
- const elements = actionsInitializer.getElements();
135
- const requestCorrectionIndex = elements.findIndex(
136
- (el) => import_ts_morph.Node.isObjectLiteralExpression(el) && isActionOfType(el, REQUEST_CORRECTION_TYPE)
137
- );
138
- if (requestCorrectionIndex === -1) continue;
139
- const requestCorrection = elements[requestCorrectionIndex];
140
- const flagsText = getNonEmptyArrayPropertyText(
141
- requestCorrection,
142
- FLAGS_PROPERTY_NAME
143
- );
144
- const conditionalsText = getNonEmptyArrayPropertyText(
145
- requestCorrection,
146
- CONDITIONALS_PROPERTY_NAME
147
- );
148
- if (!flagsText && !conditionalsText) continue;
149
- const typeStyle = getTypeInitializerStyle(requestCorrection);
150
- let insertAt = requestCorrectionIndex + 1;
151
- for (const spec of CORRECTION_ACTIONS_TO_ADD) {
152
- const alreadyPresent = actionsInitializer.getElements().some(
153
- (el) => import_ts_morph.Node.isObjectLiteralExpression(el) && isActionOfType(el, spec.actionType)
154
- );
155
- if (alreadyPresent) continue;
156
- const text = buildCorrectionActionText(
157
- spec,
158
- typeStyle,
159
- flagsText,
160
- conditionalsText
161
- );
162
- actionsInitializer.insertElement(insertAt, text);
163
- insertAt++;
164
- changes++;
165
- console.log(
166
- ` [${relPath}] Added ${spec.actionType} action carrying over REQUEST_CORRECTION's flags/conditionals`
167
- );
168
- }
169
- }
170
- return changes;
171
- }
172
- async function main() {
173
- const srcDir = import_path.default.join(process.cwd(), "src");
174
- console.log(`Scanning for defineConfig calls in: ${srcDir}
175
- `);
176
- const project = new import_ts_morph.Project({
177
- tsConfigFilePath: import_path.default.resolve(srcDir, "../tsconfig.json"),
178
- skipAddingFilesFromTsConfig: false
179
- });
180
- const sourceFiles = project.getSourceFiles().filter((sf) => {
181
- const fp = sf.getFilePath();
182
- return fp.includes("/src/") && !fp.includes("/node_modules/");
183
- });
184
- console.log(`Found ${sourceFiles.length} source file(s) to analyse.
185
- `);
186
- let totalChanges = 0;
187
- const modifiedFiles = [];
188
- for (const sourceFile of sourceFiles) {
189
- const filePath = sourceFile.getFilePath();
190
- const changes = processFile(filePath, project);
191
- if (changes > 0) {
192
- totalChanges += changes;
193
- modifiedFiles.push(filePath);
194
- }
195
- }
196
- if (modifiedFiles.length === 0) {
197
- console.log(
198
- "No REQUEST_CORRECTION actions with flags/conditionals found. Nothing to do."
199
- );
200
- return;
201
- }
202
- console.log(`
203
- Saving ${modifiedFiles.length} modified file(s)...`);
204
- for (const filePath of modifiedFiles) {
205
- const sourceFile = project.getSourceFileOrThrow(filePath);
206
- await sourceFile.save();
207
- console.log(` Saved: ${import_path.default.relative(process.cwd(), filePath)}`);
208
- }
209
- console.log(
210
- `
211
- Done. Added ${totalChanges} correction action config(s) across ${modifiedFiles.length} file(s).`
212
- );
213
- }
214
-
215
- // src/migrations/v2.1/index.ts
216
- async function runUpgrade(dockerSwarm) {
217
- await main();
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.runUpgrade = runUpgrade;
13
+ /*
14
+ * This Source Code Form is subject to the terms of the Mozilla Public
15
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
16
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/.
17
+ *
18
+ * OpenCRVS is also distributed under the terms of the Civil Registration
19
+ * & Healthcare Disclaimer located at http://opencrvs.org/license.
20
+ *
21
+ * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
22
+ */
23
+ const add_explicit_correction_flags_1 = require("./add-explicit-correction-flags");
24
+ const add_recovery_link_notifications_1 = require("./add-recovery-link-notifications");
25
+ const add_translations_1 = require("../add-translations");
26
+ const enable_telemetry_1 = require("./enable-telemetry");
27
+ const migrate_infrastructure_to_assets_1 = require("./migrate-infrastructure-to-assets");
28
+ const remove_metabase_package_installs_1 = require("./remove-metabase-package-installs");
29
+ const remove_sentry_1 = require("./remove-sentry");
30
+ const rename_trigger_paths_1 = require("./rename-trigger-paths");
31
+ const upgrade_tilt_1 = require("./upgrade-tilt");
32
+ /**
33
+ * Run the upgrade process for the country config in the current working
34
+ * directory.
35
+ */
36
+ function runUpgrade(dockerSwarm) {
37
+ return __awaiter(this, void 0, void 0, function* () {
38
+ yield (0, add_explicit_correction_flags_1.main)();
39
+ yield (0, rename_trigger_paths_1.main)();
40
+ yield (0, add_recovery_link_notifications_1.main)();
41
+ yield (0, add_translations_1.main)('2.1');
42
+ yield (0, remove_sentry_1.main)();
43
+ yield (0, remove_metabase_package_installs_1.main)();
44
+ // After the Metabase fix, so the merge starts from the patched scripts
45
+ yield (0, migrate_infrastructure_to_assets_1.main)(dockerSwarm);
46
+ yield (0, upgrade_tilt_1.main)();
47
+ // Last, so the prompt comes after all file changes
48
+ yield (0, enable_telemetry_1.main)();
49
+ });
218
50
  }
@@ -0,0 +1,17 @@
1
+ type Outcome = 'copied' | 'kept' | 'merged' | 'conflict' | 'dropped' | 'exists' | 'exists-differs' | 'not-moved';
2
+ export interface AssetsMigrationResult {
3
+ /** Paths relative to `assets/`, by what happened to them. */
4
+ outcomes: Record<string, Outcome>;
5
+ /** Paths relative to `infrastructure/` that can be removed. */
6
+ migrated: string[];
7
+ }
8
+ export type ReadBase = (file: string) => Uint8Array | undefined;
9
+ export declare function migrateInfrastructureToAssets(cwd: string, templateDir: string, readBase: ReadBase): AssetsMigrationResult;
10
+ /** Removes migrated files and any directories they leave empty. */
11
+ export declare function removeMigrated(cwd: string, migrated: string[]): void;
12
+ declare function main(dockerSwarm?: boolean): Promise<void>;
13
+ /**
14
+ * @knipignore
15
+ */
16
+ export { main };
17
+ //# sourceMappingURL=migrate-infrastructure-to-assets.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrate-infrastructure-to-assets.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.1/migrate-infrastructure-to-assets.ts"],"names":[],"mappings":"AAiHA,KAAK,OAAO,GACR,QAAQ,GACR,MAAM,GACN,QAAQ,GACR,UAAU,GACV,SAAS,GACT,QAAQ,GACR,gBAAgB,GAChB,WAAW,CAAA;AAEf,MAAM,WAAW,qBAAqB;IACpC,6DAA6D;IAC7D,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACjC,+DAA+D;IAC/D,QAAQ,EAAE,MAAM,EAAE,CAAA;CACnB;AAED,MAAM,MAAM,QAAQ,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,UAAU,GAAG,SAAS,CAAA;AAyF/D,wBAAgB,6BAA6B,CAC3C,GAAG,EAAE,MAAM,EACX,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,QAAQ,GACjB,qBAAqB,CAmGvB;AAED,mEAAmE;AACnE,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,QAwB7D;AAeD,iBAAe,IAAI,CAAC,WAAW,UAAQ,iBAiFtC;AAED;;GAEG;AACH,OAAO,EAAE,IAAI,EAAE,CAAA"}
@@ -0,0 +1,348 @@
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.migrateInfrastructureToAssets = migrateInfrastructureToAssets;
26
+ exports.removeMigrated = removeMigrated;
27
+ exports.main = main;
28
+ /**
29
+ * Codemod: move `infrastructure/` into the v2.1 `assets/` directory, merging
30
+ * the country's changes with the template's.
31
+ *
32
+ * The assets image (Dockerfile.assets) is now built from `assets/` with a
33
+ * single `COPY assets /assets`, and the charts copy `/assets/metabase`,
34
+ * `/assets/postgres` and `/assets/elasticsearch` out of it.
35
+ *
36
+ * What it does, for every file under `infrastructure/{metabase,postgres,
37
+ * deployment,elasticsearch}/` and the template's `assets/`, going to the same
38
+ * path under `assets/`:
39
+ * - template only → copied from the template
40
+ * - unchanged since v2.0 → the template's version (or dropped,
41
+ * when the template no longer has it)
42
+ * - changed by the country only → the country's version
43
+ * - changed on both sides → 3-way merged (`git merge-file`), with
44
+ * conflict markers left for review
45
+ * - country only → moved across as is
46
+ * The v2.0 version of each file, used as the merge base, is read from
47
+ * opencrvs-farajaland's release/v2.0.0 on GitHub.
48
+ *
49
+ * `assets/elasticsearch/reindex.sh`, which the reindex job runs, is built from
50
+ * `infrastructure/deployment/reindex.sh` so a customised reindex script
51
+ * carries over.
52
+ *
53
+ * `postgres/on-deploy.sh` is never moved: the data-migration-analytics job
54
+ * runs every `*.sh` in `/assets/postgres`, and the chart ships its own
55
+ * on-deploy script. The v2.0 Dockerfile.assets deleted it from the image for
56
+ * the same reason.
57
+ *
58
+ * Then `Dockerfile.assets` is replaced with the template's, the migrated files
59
+ * are removed from `infrastructure/` (kept with `--docker-swarm`), and the
60
+ * result is staged. Files with conflicts are left unstaged. Anything else in
61
+ * `infrastructure/`, such as Docker Swarm configuration, is left in place.
62
+ *
63
+ * Caveats:
64
+ * - Existing files under `assets/` are never overwritten, so running it
65
+ * again, or after migrating by hand, leaves them alone. The
66
+ * `infrastructure/` original is then only removed when identical.
67
+ * - Binary files changed by the country keep the country's version.
68
+ * - Requires network access to raw.githubusercontent.com. Without it
69
+ * nothing is changed and the step is reported as skipped.
70
+ */
71
+ const child_process_1 = require("child_process");
72
+ const fs_1 = require("fs");
73
+ const os_1 = require("os");
74
+ const path_1 = __importDefault(require("path"));
75
+ const template_files_1 = require("./template-files");
76
+ const INFRASTRUCTURE_DIR = 'infrastructure';
77
+ const ASSETS_DIR = 'assets';
78
+ const BASE_URL = 'https://raw.githubusercontent.com/opencrvs/opencrvs-farajaland/release/v2.0.0/infrastructure';
79
+ /** Assets built from a differently named v2.0 file, when not present themselves. */
80
+ const SOURCE_OF = {
81
+ 'elasticsearch/reindex.sh': 'deployment/reindex.sh'
82
+ };
83
+ /**
84
+ * What the assets image needs. The rest of `infrastructure/` (Docker Swarm
85
+ * compose files, server setup and so on) is left where it is.
86
+ */
87
+ const MIGRATED_DIRS = ['metabase', 'postgres', 'deployment', 'elasticsearch'];
88
+ /** Never moved into `assets/`. */
89
+ const NOT_MOVED = ['postgres/on-deploy.sh'];
90
+ const isMigrated = (file) => MIGRATED_DIRS.some((dir) => file.startsWith(`${dir}/`));
91
+ /** Runs git silently in the working directory, returning true on success. */
92
+ function tryGit(args) {
93
+ try {
94
+ (0, child_process_1.execFileSync)('git', args, { stdio: 'ignore' });
95
+ return true;
96
+ }
97
+ catch (_a) {
98
+ return false;
99
+ }
100
+ }
101
+ function assertIsGitRepo() {
102
+ if (!tryGit(['rev-parse', '--is-inside-work-tree'])) {
103
+ throw new Error(`${process.cwd()} is not a git repository. Initialise git (or run the upgrade inside a git checkout) before re-running.`);
104
+ }
105
+ }
106
+ /*
107
+ * Plain Uint8Array rather than Buffer: the repository's Node typings reject a
108
+ * Buffer where fs expects an ArrayBufferView.
109
+ */
110
+ const toBytes = (buffer) => new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
111
+ const sameBytes = (a, b) => a.length === b.length && a.every((byte, index) => byte === b[index]);
112
+ const isBinary = (contents) => contents.includes(0);
113
+ function readIfExists(file) {
114
+ return (0, fs_1.existsSync)(file) ? toBytes((0, fs_1.readFileSync)(file)) : undefined;
115
+ }
116
+ /** 3-way merge of text contents. `conflicts` is 0 for a clean merge. */
117
+ function mergeFile(file, ours, base, theirs) {
118
+ const dir = (0, fs_1.mkdtempSync)(path_1.default.join((0, os_1.tmpdir)(), 'opencrvs-merge-assets-'));
119
+ try {
120
+ const [oursPath, basePath, theirsPath] = ['ours', 'base', 'theirs'].map((name) => path_1.default.join(dir, name));
121
+ (0, fs_1.writeFileSync)(oursPath, ours);
122
+ (0, fs_1.writeFileSync)(basePath, base);
123
+ (0, fs_1.writeFileSync)(theirsPath, theirs);
124
+ // Without -p git writes the result into `oursPath`, so large files
125
+ // (e.g. the Metabase init dump) don't overflow the stdout buffer
126
+ const args = [
127
+ 'merge-file',
128
+ '-q',
129
+ '-L',
130
+ `infrastructure/${file}`,
131
+ '-L',
132
+ 'v2.0',
133
+ '-L',
134
+ `v2.1 template`,
135
+ oursPath,
136
+ basePath,
137
+ theirsPath
138
+ ];
139
+ let conflicts = 0;
140
+ try {
141
+ (0, child_process_1.execFileSync)('git', args, { stdio: 'ignore' });
142
+ }
143
+ catch (error) {
144
+ const { status } = error;
145
+ // git merge-file exits with the number of conflicts, or 255 on error
146
+ if (!status || status >= 255)
147
+ throw error;
148
+ conflicts = status;
149
+ }
150
+ return { contents: toBytes((0, fs_1.readFileSync)(oursPath)), conflicts };
151
+ }
152
+ finally {
153
+ (0, fs_1.rmSync)(dir, { recursive: true, force: true });
154
+ }
155
+ }
156
+ /** Every v2.0 file the migration needs as a merge base, fetched up front. */
157
+ function fetchBases(files) {
158
+ return __awaiter(this, void 0, void 0, function* () {
159
+ const bases = new Map();
160
+ for (const file of files) {
161
+ const url = `${BASE_URL}/${file}`;
162
+ const response = yield fetch(url);
163
+ if (response.ok) {
164
+ bases.set(file, new Uint8Array(yield response.arrayBuffer()));
165
+ }
166
+ else if (response.status !== 404) {
167
+ // 404 means the file is the country's own; anything else would merge
168
+ // against a missing base, so give up before touching anything
169
+ throw new Error(`GitHub answered ${response.status} ${response.statusText} for ${url}`);
170
+ }
171
+ }
172
+ return bases;
173
+ });
174
+ }
175
+ function migrateInfrastructureToAssets(cwd, templateDir, readBase) {
176
+ const infrastructure = path_1.default.join(cwd, INFRASTRUCTURE_DIR);
177
+ const templateAssets = path_1.default.join(templateDir, ASSETS_DIR);
178
+ const relativeTo = (dir) => (file) => file.slice(dir.length + 1);
179
+ const localFiles = (0, template_files_1.listFiles)(cwd, INFRASTRUCTURE_DIR)
180
+ .map(relativeTo(INFRASTRUCTURE_DIR))
181
+ .filter(isMigrated);
182
+ const templateFiles = (0, template_files_1.listFiles)(templateDir, ASSETS_DIR).map(relativeTo(ASSETS_DIR));
183
+ const outcomes = {};
184
+ const migrated = new Set();
185
+ for (const file of [...new Set([...templateFiles, ...localFiles])].sort()) {
186
+ const sourceFile = !localFiles.includes(file) && localFiles.includes(SOURCE_OF[file])
187
+ ? SOURCE_OF[file]
188
+ : file;
189
+ const ours = readIfExists(path_1.default.join(infrastructure, sourceFile));
190
+ const theirsPath = path_1.default.join(templateAssets, file);
191
+ const theirs = readIfExists(theirsPath);
192
+ const base = ours && readBase(sourceFile);
193
+ const target = path_1.default.join(cwd, ASSETS_DIR, file);
194
+ if (NOT_MOVED.includes(file)) {
195
+ if (ours && base && sameBytes(ours, base)) {
196
+ migrated.add(file);
197
+ outcomes[file] = 'dropped';
198
+ }
199
+ else if (ours) {
200
+ outcomes[file] = 'not-moved';
201
+ }
202
+ continue;
203
+ }
204
+ const ownsSource = ours !== undefined && sourceFile === file;
205
+ if ((0, fs_1.existsSync)(target)) {
206
+ // Migrated before (a re-run, or by hand): only remove the original
207
+ // when nothing in it would be lost
208
+ if (ownsSource) {
209
+ const same = sameBytes(toBytes((0, fs_1.readFileSync)(target)), ours);
210
+ if (same) {
211
+ migrated.add(file);
212
+ }
213
+ outcomes[file] = same ? 'exists' : 'exists-differs';
214
+ }
215
+ continue;
216
+ }
217
+ if (ownsSource) {
218
+ migrated.add(file);
219
+ }
220
+ let contents;
221
+ let outcome;
222
+ if (!ours) {
223
+ contents = theirs;
224
+ outcome = 'copied';
225
+ }
226
+ else if (!theirs) {
227
+ const unchanged = base && sameBytes(ours, base);
228
+ contents = unchanged ? undefined : ours;
229
+ outcome = unchanged ? 'dropped' : 'kept';
230
+ }
231
+ else if (sameBytes(ours, theirs) || (base && sameBytes(ours, base))) {
232
+ contents = theirs;
233
+ outcome = 'copied';
234
+ }
235
+ else if (!base || sameBytes(base, theirs) || isBinary(ours)) {
236
+ contents = ours;
237
+ outcome = 'kept';
238
+ }
239
+ else {
240
+ const result = mergeFile(sourceFile, ours, base, theirs);
241
+ contents = result.contents;
242
+ outcome = result.conflicts > 0 ? 'conflict' : 'merged';
243
+ }
244
+ outcomes[file] = outcome;
245
+ if (contents === undefined) {
246
+ continue;
247
+ }
248
+ (0, fs_1.mkdirSync)(path_1.default.dirname(target), { recursive: true });
249
+ (0, fs_1.writeFileSync)(target, contents);
250
+ const modeSource = ours && outcome === 'kept'
251
+ ? path_1.default.join(infrastructure, sourceFile)
252
+ : theirsPath;
253
+ if ((0, fs_1.existsSync)(modeSource)) {
254
+ (0, fs_1.chmodSync)(target, (0, fs_1.statSync)(modeSource).mode & 0o777);
255
+ }
256
+ }
257
+ return { outcomes, migrated: [...migrated].sort() };
258
+ }
259
+ /** Removes migrated files and any directories they leave empty. */
260
+ function removeMigrated(cwd, migrated) {
261
+ const infrastructure = path_1.default.join(cwd, INFRASTRUCTURE_DIR);
262
+ for (const file of migrated) {
263
+ (0, fs_1.rmSync)(path_1.default.join(infrastructure, file), { force: true });
264
+ }
265
+ const pruneEmpty = (dir) => {
266
+ if (!(0, fs_1.existsSync)(dir)) {
267
+ return true;
268
+ }
269
+ const empty = (0, fs_1.readdirSync)(dir, { withFileTypes: true })
270
+ .map((entry) => entry.isDirectory() ? pruneEmpty(path_1.default.join(dir, entry.name)) : false)
271
+ .every(Boolean);
272
+ if (empty) {
273
+ (0, fs_1.rmdirSync)(dir);
274
+ }
275
+ return empty;
276
+ };
277
+ pruneEmpty(infrastructure);
278
+ }
279
+ const DESCRIPTIONS = {
280
+ copied: 'from the template',
281
+ kept: "country's version",
282
+ merged: 'merged',
283
+ conflict: 'CONFLICT, resolve the markers by hand',
284
+ dropped: 'dropped, no longer used',
285
+ exists: 'already migrated',
286
+ 'exists-differs': 'already exists with different contents; infrastructure/ copy kept for review',
287
+ 'not-moved': 'changed locally but not moved: the chart runs its own on-deploy script, port your changes there'
288
+ };
289
+ function main() {
290
+ return __awaiter(this, arguments, void 0, function* (dockerSwarm = false) {
291
+ const cwd = process.cwd();
292
+ console.log('Moving infrastructure/ into assets/...\n');
293
+ const templateDir = (0, template_files_1.findTemplateDir)();
294
+ if ((0, fs_1.existsSync)(path_1.default.join(cwd, INFRASTRUCTURE_DIR))) {
295
+ assertIsGitRepo();
296
+ const needed = (0, template_files_1.listFiles)(cwd, INFRASTRUCTURE_DIR)
297
+ .map((file) => file.slice(INFRASTRUCTURE_DIR.length + 1))
298
+ .filter(isMigrated);
299
+ let bases;
300
+ try {
301
+ bases = yield fetchBases(needed);
302
+ }
303
+ catch (error) {
304
+ console.warn(` ⚠️ Could not read the v2.0 files to merge against (${error.message}); infrastructure/ was not migrated. Re-run 'opencrvs upgrade' with network access.`);
305
+ return;
306
+ }
307
+ const { outcomes, migrated } = migrateInfrastructureToAssets(cwd, templateDir, (file) => bases.get(file));
308
+ for (const [file, outcome] of Object.entries(outcomes)) {
309
+ const needsReview = ['conflict', 'not-moved', 'exists-differs'].includes(outcome);
310
+ const shown = outcome === 'not-moved' ? INFRASTRUCTURE_DIR : ASSETS_DIR;
311
+ const line = ` ${needsReview ? '⚠️ ' : '✓'} ${shown}/${file}: ${DESCRIPTIONS[outcome]}`;
312
+ if (needsReview) {
313
+ console.warn(line);
314
+ }
315
+ else {
316
+ console.log(line);
317
+ }
318
+ }
319
+ if (dockerSwarm) {
320
+ console.log('\n infrastructure/ kept in place (--docker-swarm); assets/ now holds a copy.');
321
+ }
322
+ else {
323
+ removeMigrated(cwd, migrated);
324
+ }
325
+ tryGit(['add', '-A', '--', ASSETS_DIR, INFRASTRUCTURE_DIR]);
326
+ const conflicts = Object.keys(outcomes).filter((file) => outcomes[file] === 'conflict');
327
+ for (const file of conflicts) {
328
+ tryGit(['restore', '--staged', '--', `${ASSETS_DIR}/${file}`]);
329
+ }
330
+ if (conflicts.length > 0) {
331
+ console.warn(`\n ⚠️ ${conflicts.length} file(s) need their conflicts resolved: ${conflicts.map((file) => `assets/${file}`).join(', ')}`);
332
+ }
333
+ if ((0, fs_1.existsSync)(path_1.default.join(cwd, INFRASTRUCTURE_DIR)) && !dockerSwarm) {
334
+ console.warn(' ⚠️ infrastructure/ still has files the Kubernetes deployment does not use. Review and delete them if they are no longer needed.');
335
+ }
336
+ }
337
+ else {
338
+ console.log(' infrastructure/ not found, nothing to move.');
339
+ }
340
+ const dockerfile = toBytes((0, fs_1.readFileSync)(path_1.default.join(templateDir, 'Dockerfile.assets')));
341
+ const current = readIfExists(path_1.default.join(cwd, 'Dockerfile.assets'));
342
+ if (!current || !sameBytes(current, dockerfile)) {
343
+ (0, fs_1.writeFileSync)(path_1.default.join(cwd, 'Dockerfile.assets'), dockerfile);
344
+ tryGit(['add', '--', 'Dockerfile.assets']);
345
+ console.log(' ✓ Dockerfile.assets replaced with the template version');
346
+ }
347
+ });
348
+ }
@@ -0,0 +1,2 @@
1
+ export declare function main(): Promise<void>;
2
+ //# sourceMappingURL=remove-metabase-package-installs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remove-metabase-package-installs.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.1/remove-metabase-package-installs.ts"],"names":[],"mappings":"AA+KA,wBAAsB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAY1C"}