@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
@@ -1,110 +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: In `acceptRequestedRegistration`, update the `action` parameter type from:
28
- * action: ActionInput
29
- * to:
30
- * action: Extract<ActionInput, { type?: 'REGISTER' }>
31
- *
32
- * What it does:
33
- * - Scans all TypeScript files under `src/`
34
- * - Finds `acceptRequestedRegistration` (function declaration or const assignment)
35
- * - Rewrites only the `action` parameter when its type is exactly `ActionInput`
36
- * - Saves modified files in-place
37
- */
38
- /* eslint-disable no-console */
39
- const ts_morph_1 = require("ts-morph");
40
- const path_1 = __importDefault(require("path"));
41
- const TARGET_FUNCTION_NAME = 'acceptRequestedRegistration';
42
- const ACTION_PARAMETER_NAME = 'action';
43
- const OLD_TYPE = 'ActionInput';
44
- const NEW_TYPE = "Extract<ActionInput, { type?: 'REGISTER' }>";
45
- function isAcceptRequestedRegistrationParameter(parameter) {
46
- const functionDeclaration = parameter.getFirstAncestorByKind(ts_morph_1.SyntaxKind.FunctionDeclaration);
47
- if ((functionDeclaration === null || functionDeclaration === void 0 ? void 0 : functionDeclaration.getName()) === TARGET_FUNCTION_NAME) {
48
- return true;
49
- }
50
- const arrowFunction = parameter.getFirstAncestorByKind(ts_morph_1.SyntaxKind.ArrowFunction);
51
- const variableDeclaration = arrowFunction === null || arrowFunction === void 0 ? void 0 : arrowFunction.getFirstAncestorByKind(ts_morph_1.SyntaxKind.VariableDeclaration);
52
- return (variableDeclaration === null || variableDeclaration === void 0 ? void 0 : variableDeclaration.getName()) === TARGET_FUNCTION_NAME;
53
- }
54
- function processFile(filePath, project) {
55
- const sourceFile = project.getSourceFile(filePath);
56
- if (!sourceFile)
57
- return 0;
58
- let updatedCount = 0;
59
- for (const parameter of sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.Parameter)) {
60
- if (parameter.getName() !== ACTION_PARAMETER_NAME) {
61
- continue;
62
- }
63
- if (!isAcceptRequestedRegistrationParameter(parameter)) {
64
- continue;
65
- }
66
- const typeNode = parameter.getTypeNode();
67
- if (!typeNode || typeNode.getText() !== OLD_TYPE) {
68
- continue;
69
- }
70
- parameter.setType(NEW_TYPE);
71
- updatedCount++;
72
- console.log(` [${path_1.default.relative(process.cwd(), filePath)}] Updated '${ACTION_PARAMETER_NAME}' in ${TARGET_FUNCTION_NAME} to ${NEW_TYPE}`);
73
- }
74
- return updatedCount;
75
- }
76
- function main() {
77
- return __awaiter(this, void 0, void 0, function* () {
78
- const srcDir = path_1.default.join(process.cwd(), 'src');
79
- console.log(`Scanning for ${TARGET_FUNCTION_NAME} in: ${srcDir}\n`);
80
- const project = new ts_morph_1.Project({
81
- tsConfigFilePath: path_1.default.resolve(srcDir, '../tsconfig.json'),
82
- skipAddingFilesFromTsConfig: false
83
- });
84
- const sourceFiles = project.getSourceFiles().filter((sf) => {
85
- const filePath = sf.getFilePath();
86
- return filePath.includes('/src/') && !filePath.includes('/node_modules/');
87
- });
88
- let totalUpdated = 0;
89
- const modifiedFiles = [];
90
- for (const sourceFile of sourceFiles) {
91
- const filePath = sourceFile.getFilePath();
92
- const updated = processFile(filePath, project);
93
- if (updated > 0) {
94
- totalUpdated += updated;
95
- modifiedFiles.push(filePath);
96
- }
97
- }
98
- if (modifiedFiles.length === 0) {
99
- console.log(`No '${ACTION_PARAMETER_NAME}: ${OLD_TYPE}' parameter in ${TARGET_FUNCTION_NAME} found. Nothing to do.`);
100
- return;
101
- }
102
- console.log(`\nSaving ${modifiedFiles.length} modified file(s)...`);
103
- for (const filePath of modifiedFiles) {
104
- const sourceFile = project.getSourceFileOrThrow(filePath);
105
- yield sourceFile.save();
106
- console.log(` Saved: ${path_1.default.relative(process.cwd(), filePath)}`);
107
- }
108
- console.log(`\nDone. Updated ${totalUpdated} parameter type annotation(s) in ${TARGET_FUNCTION_NAME}.`);
109
- });
110
- }
@@ -1,13 +0,0 @@
1
- /**
2
- * Run the upgrade process for the country config in the current working
3
- * directory.
4
- *
5
- * @param dockerSwarm - When true, the local `infrastructure/` directory is
6
- * merged with upstream changes in its entirety (Docker Swarm deployments
7
- * still need it all). When false (the default), everything under
8
- * `infrastructure/` is deleted EXCEPT the subdirectories listed in
9
- * `NON_SWARM_INFRA_SUBDIRS`, and those preserved subdirectories are then
10
- * merged with upstream.
11
- */
12
- export declare function runUpgrade(dockerSwarm: boolean): Promise<void>;
13
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/index.ts"],"names":[],"mappings":"AA8CA;;;;;;;;;;GAUG;AACH,wBAAsB,UAAU,CAAC,WAAW,EAAE,OAAO,iBAiCpD"}
@@ -1,103 +0,0 @@
1
- "use strict";
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
- });
10
- };
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 remove_review_from_register_action_1 = require("./remove-review-from-register-action");
24
- const make_built_in_validate_actions_custom_1 = require("./make-built-in-validate-actions-custom");
25
- const remove_delete_actions_1 = require("./remove-delete-actions");
26
- const convert_paragraph_to_heading_1 = require("./convert-paragraph-to-heading");
27
- const migrate_validated_workqueue_status_to_flag_1 = require("./migrate-validated-workqueue-status-to-flag");
28
- const add_birth_certificate_issuance_flag_1 = require("./add-birth-certificate-issuance-flag");
29
- const remove_pending_certification_flag_1 = require("./remove-pending-certification-flag");
30
- const rename_location_parent_id_1 = require("./rename-location-parent-id");
31
- const rename_api_paths_1 = require("./rename-api-paths");
32
- const convert_config_files_to_ts_1 = require("./convert-config-files-to-ts");
33
- const migrate_scopes_1 = require("./migrate-scopes");
34
- const remove_deprecated_imports_1 = require("./remove-deprecated-imports");
35
- const remove_unused_environment_variables_1 = require("./remove-unused-environment-variables");
36
- const remove_fhir_url_helpers_1 = require("./remove-fhir-url-helpers");
37
- const migrate_application_config_url_1 = require("./migrate-application-config-url");
38
- const remove_old_statistics_service_1 = require("./remove-old-statistics-service");
39
- const update_package_json_1 = require("./update-package-json");
40
- const migrate_workqueue_configs_1 = require("./migrate-workqueue-configs");
41
- const remove_demo_scope_1 = require("./remove-demo-scope");
42
- const remove_hearth_migrations_1 = require("./remove-hearth-migrations");
43
- const create_events_index_1 = require("./create-events-index");
44
- const checkout_upstream_files_1 = require("./checkout-upstream-files");
45
- const add_resend_invite_notification_1 = require("./add-resend-invite-notification");
46
- const simplify_analytics_precalculations_1 = require("./simplify-analytics-precalculations");
47
- const merge_infrastructure_directory_1 = require("./merge-infrastructure-directory");
48
- const delete_infrastructure_directory_1 = require("./delete-infrastructure-directory");
49
- const fix_accept_requested_registration_function_type_1 = require("./fix-accept-requested-registration-function-type");
50
- /**
51
- * Top-level subdirectories of `infrastructure/` that non-Swarm deployments
52
- * still need (e.g. Postgres init scripts, Metabase config). Everything else
53
- * under `infrastructure/` is deleted, and these subdirectories are then
54
- * merged with upstream so the country config picks up the v2.0 changes.
55
- */
56
- const NON_SWARM_INFRA_SUBDIRS = ['postgres', 'metabase'];
57
- /**
58
- * Run the upgrade process for the country config in the current working
59
- * directory.
60
- *
61
- * @param dockerSwarm - When true, the local `infrastructure/` directory is
62
- * merged with upstream changes in its entirety (Docker Swarm deployments
63
- * still need it all). When false (the default), everything under
64
- * `infrastructure/` is deleted EXCEPT the subdirectories listed in
65
- * `NON_SWARM_INFRA_SUBDIRS`, and those preserved subdirectories are then
66
- * merged with upstream.
67
- */
68
- function runUpgrade(dockerSwarm) {
69
- return __awaiter(this, void 0, void 0, function* () {
70
- yield (0, migrate_workqueue_configs_1.main)();
71
- yield (0, remove_review_from_register_action_1.main)();
72
- yield (0, make_built_in_validate_actions_custom_1.main)();
73
- yield (0, remove_delete_actions_1.main)();
74
- yield (0, convert_paragraph_to_heading_1.main)();
75
- yield (0, migrate_validated_workqueue_status_to_flag_1.main)();
76
- yield (0, add_birth_certificate_issuance_flag_1.main)();
77
- yield (0, remove_pending_certification_flag_1.main)();
78
- yield (0, rename_location_parent_id_1.main)();
79
- yield (0, rename_api_paths_1.main)();
80
- yield (0, convert_config_files_to_ts_1.main)();
81
- yield (0, migrate_scopes_1.main)();
82
- yield (0, remove_deprecated_imports_1.main)();
83
- yield (0, remove_unused_environment_variables_1.main)();
84
- yield (0, remove_fhir_url_helpers_1.main)();
85
- yield (0, migrate_application_config_url_1.main)();
86
- yield (0, remove_old_statistics_service_1.main)();
87
- yield (0, remove_demo_scope_1.main)();
88
- yield (0, remove_hearth_migrations_1.main)();
89
- yield (0, create_events_index_1.main)();
90
- yield (0, checkout_upstream_files_1.main)();
91
- yield (0, add_resend_invite_notification_1.main)();
92
- yield (0, simplify_analytics_precalculations_1.main)();
93
- yield (0, fix_accept_requested_registration_function_type_1.main)();
94
- yield (0, update_package_json_1.main)();
95
- if (dockerSwarm) {
96
- yield (0, merge_infrastructure_directory_1.main)();
97
- }
98
- else {
99
- yield (0, delete_infrastructure_directory_1.main)({ keep: NON_SWARM_INFRA_SUBDIRS });
100
- yield (0, merge_infrastructure_directory_1.main)({ subdirs: NON_SWARM_INFRA_SUBDIRS });
101
- }
102
- });
103
- }
@@ -1,3 +0,0 @@
1
- declare function main(): Promise<void>;
2
- export { main };
3
- //# sourceMappingURL=make-built-in-validate-actions-custom.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"make-built-in-validate-actions-custom.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/make-built-in-validate-actions-custom.ts"],"names":[],"mappings":"AAodA,iBAAe,IAAI,kBAiDlB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
@@ -1,432 +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: Transform `VALIDATE` type actions into `CUSTOM` actions inside `defineConfig` calls.
28
- *
29
- * Usage:
30
- * ts-node -r tsconfig-paths/register src/migrations/v2.0/make-built-in-validate-actions-custom.ts
31
- *
32
- * What it does:
33
- * - Scans all TypeScript files under `src/`
34
- * - Finds every `defineConfig({ ... })` call expression
35
- * - Inside the `actions` array of that config, locates object literals
36
- * whose `type` property resolves to `ActionType.VALIDATE` or the string literal `"VALIDATE"`
37
- * - Changes the `type` value to `ActionType.CUSTOM` (or `"CUSTOM"` for string literals)
38
- * - Adds a `customActionType: 'VALIDATE_DECLARATION'` property to those objects
39
- * - Adds an `auditHistoryLabel` intl descriptor whose `id` is derived from the
40
- * root `type` value of the `defineConfig` config object
41
- * - Removes the `deduplication` property from those objects
42
- * - Replaces `review: { fields: <value> }` with `form: <value>`, or
43
- * `review: <expr>` with `form: <expr>.fields` when the value is not an inline object
44
- * - Adds the top-level `validated` flag definition and `{ id: 'validated',
45
- * operation: 'add' }` to the (now custom) validate action
46
- * - Adds `{ id: 'validated', operation: 'remove' }` to every `REGISTER` action
47
- * in the same config, closing the flag's lifecycle when registration happens
48
- * - Saves the modified files in-place
49
- */
50
- const ts_morph_1 = require("ts-morph");
51
- const path_1 = __importDefault(require("path"));
52
- const TOOLKIT_EVENTS_MODULE = '@opencrvs/toolkit/events';
53
- const REQUIRED_SYMBOLS = [
54
- 'ConditionalType',
55
- 'and',
56
- 'status',
57
- 'not',
58
- 'flag',
59
- 'InherentFlags'
60
- ];
61
- function ensureImports(sourceFile) {
62
- const existingImport = sourceFile.getImportDeclaration((decl) => decl.getModuleSpecifierValue() === TOOLKIT_EVENTS_MODULE);
63
- if (existingImport) {
64
- const existingNames = new Set(existingImport.getNamedImports().map((ni) => ni.getName()));
65
- for (const name of REQUIRED_SYMBOLS) {
66
- if (!existingNames.has(name)) {
67
- existingImport.addNamedImport(name);
68
- }
69
- }
70
- }
71
- else {
72
- sourceFile.addImportDeclaration({
73
- moduleSpecifier: TOOLKIT_EVENTS_MODULE,
74
- namedImports: REQUIRED_SYMBOLS
75
- });
76
- }
77
- }
78
- const DEFINE_CONFIG_NAME = 'defineConfig';
79
- const ACTIONS_PROPERTY_NAME = 'actions';
80
- const TYPE_PROPERTY_NAME = 'type';
81
- const ID_PROPERTY_NAME = 'id';
82
- const FLAGS_PROPERTY_NAME = 'flags';
83
- const CUSTOM_ACTION_TYPE_PROPERTY_NAME = 'customActionType';
84
- const AUDIT_HISTORY_LABEL_PROPERTY_NAME = 'auditHistoryLabel';
85
- const DEDUPLICATION_PROPERTY_NAME = 'deduplication';
86
- const REVIEW_PROPERTY_NAME = 'review';
87
- const FIELDS_PROPERTY_NAME = 'fields';
88
- const FORM_PROPERTY_NAME = 'form';
89
- const ACTION_TYPE_ENUM_NAME = 'ActionType';
90
- const VALIDATE_MEMBER_NAME = 'VALIDATE';
91
- const CUSTOM_MEMBER_NAME = 'CUSTOM';
92
- const REGISTER_MEMBER_NAME = 'REGISTER';
93
- const VALIDATE_STRING_LITERAL = 'VALIDATE';
94
- const CUSTOM_STRING_LITERAL = 'CUSTOM';
95
- const REGISTER_STRING_LITERAL = 'REGISTER';
96
- const VALIDATE_DECLARATION_VALUE = 'VALIDATE_DECLARATION';
97
- const VALIDATED_FLAG_VALUE = 'validated';
98
- function isValidateType(typeInitializer) {
99
- // Matches: ActionType.VALIDATE
100
- if (typeInitializer.getKind() === ts_morph_1.SyntaxKind.PropertyAccessExpression) {
101
- const propAccess = typeInitializer.asKindOrThrow(ts_morph_1.SyntaxKind.PropertyAccessExpression);
102
- const obj = propAccess.getExpression();
103
- const member = propAccess.getName();
104
- return (ts_morph_1.Node.isIdentifier(obj) &&
105
- obj.getText() === ACTION_TYPE_ENUM_NAME &&
106
- member === VALIDATE_MEMBER_NAME);
107
- }
108
- // Matches: "VALIDATE"
109
- if (typeInitializer.getKind() === ts_morph_1.SyntaxKind.StringLiteral) {
110
- return (typeInitializer
111
- .asKindOrThrow(ts_morph_1.SyntaxKind.StringLiteral)
112
- .getLiteralValue() === VALIDATE_STRING_LITERAL);
113
- }
114
- return false;
115
- }
116
- function resolveEventType(configArg) {
117
- const typeProperty = configArg.getProperty(TYPE_PROPERTY_NAME);
118
- if (!typeProperty || !ts_morph_1.Node.isPropertyAssignment(typeProperty))
119
- return null;
120
- const initializer = typeProperty.getInitializer();
121
- if (!initializer)
122
- return null;
123
- // 'birth' / 'death' etc. — use the literal value directly
124
- if (ts_morph_1.Node.isStringLiteral(initializer)) {
125
- return initializer.getLiteralValue().toLowerCase();
126
- }
127
- // EventType.BIRTH — extract and lowercase the member name
128
- if (initializer.getKind() === ts_morph_1.SyntaxKind.PropertyAccessExpression &&
129
- ts_morph_1.Node.isPropertyAccessExpression(initializer)) {
130
- return initializer.getName().toLowerCase();
131
- }
132
- return null;
133
- }
134
- function transformValidateActionToCustom(obj, eventType) {
135
- const typeProperty = obj.getProperty(TYPE_PROPERTY_NAME);
136
- if (!typeProperty || !ts_morph_1.Node.isPropertyAssignment(typeProperty)) {
137
- return false;
138
- }
139
- const typeInitializer = typeProperty.getInitializer();
140
- if (!typeInitializer || !isValidateType(typeInitializer)) {
141
- return false;
142
- }
143
- // Replace the type value: ActionType.VALIDATE -> ActionType.CUSTOM, "VALIDATE" -> "CUSTOM"
144
- if (typeInitializer.getKind() === ts_morph_1.SyntaxKind.PropertyAccessExpression) {
145
- typeInitializer.replaceWithText(`${ACTION_TYPE_ENUM_NAME}.${CUSTOM_MEMBER_NAME}`);
146
- }
147
- else {
148
- typeInitializer.replaceWithText(`'${CUSTOM_STRING_LITERAL}'`);
149
- }
150
- // Add customActionType: 'VALIDATE_DECLARATION' if not already present
151
- if (!obj.getProperty(CUSTOM_ACTION_TYPE_PROPERTY_NAME)) {
152
- obj.addPropertyAssignment({
153
- name: CUSTOM_ACTION_TYPE_PROPERTY_NAME,
154
- initializer: `'${VALIDATE_DECLARATION_VALUE}'`
155
- });
156
- }
157
- // Add auditHistoryLabel intl descriptor if not already present
158
- if (!obj.getProperty(AUDIT_HISTORY_LABEL_PROPERTY_NAME)) {
159
- const messageId = `event.${eventType}.custom.action.validate-declaration.audit-history-label`;
160
- obj.addPropertyAssignment({
161
- name: AUDIT_HISTORY_LABEL_PROPERTY_NAME,
162
- initializer: `{
163
- defaultMessage: 'Validated',
164
- description: 'The label to show in audit history for the validate action',
165
- id: '${messageId}'
166
- }`
167
- });
168
- }
169
- // Add supportingCopy intl descriptor if not already present
170
- if (!obj.getProperty('supportingCopy')) {
171
- const supportingCopyId = `event.${eventType}.custom.action.validate-declaration.supportingCopy`;
172
- obj.addPropertyAssignment({
173
- name: 'supportingCopy',
174
- initializer: `{
175
- defaultMessage:
176
- 'Approving this declaration confirms it as legally accepted and eligible for registration.',
177
- description:
178
- 'This is the supporting copy for the Validate declaration -action',
179
- id: '${supportingCopyId}'
180
- }`
181
- });
182
- }
183
- // Add conditionals if not already present
184
- if (!obj.getProperty('conditionals')) {
185
- obj.addPropertyAssignment({
186
- name: 'conditionals',
187
- initializer: `[
188
- {
189
- type: ConditionalType.SHOW,
190
- conditional: and(status('DECLARED'), not(flag('validated')))
191
- },
192
- {
193
- type: ConditionalType.ENABLE,
194
- conditional: not(flag(InherentFlags.POTENTIAL_DUPLICATE))
195
- }
196
- ]`
197
- });
198
- }
199
- // Add flags if not already present
200
- if (!obj.getProperty('flags')) {
201
- obj.addPropertyAssignment({
202
- name: 'flags',
203
- initializer: `[{ id: 'validated', operation: 'add' }]`
204
- });
205
- }
206
- // Remove the `deduplication` property if present
207
- const deduplicationProperty = obj.getProperty(DEDUPLICATION_PROPERTY_NAME);
208
- if (deduplicationProperty) {
209
- deduplicationProperty.remove();
210
- }
211
- // Replace `review` with `form`:
212
- // - `review: { fields: <value> }` → `form: <value>`
213
- // - `review: <expr>` → `form: <expr>.fields`
214
- const reviewProperty = obj.getProperty(REVIEW_PROPERTY_NAME);
215
- if (reviewProperty && ts_morph_1.Node.isPropertyAssignment(reviewProperty)) {
216
- const reviewInitializer = reviewProperty.getInitializer();
217
- if (reviewInitializer) {
218
- if (ts_morph_1.Node.isObjectLiteralExpression(reviewInitializer)) {
219
- // Inline object: extract the `fields` value directly
220
- const fieldsProperty = reviewInitializer.getProperty(FIELDS_PROPERTY_NAME);
221
- if (fieldsProperty && ts_morph_1.Node.isPropertyAssignment(fieldsProperty)) {
222
- const fieldsInitializer = fieldsProperty.getInitializer();
223
- if (fieldsInitializer) {
224
- reviewProperty.set({
225
- name: FORM_PROPERTY_NAME,
226
- initializer: fieldsInitializer.getText()
227
- });
228
- }
229
- }
230
- }
231
- else {
232
- // Reference or other expression: append `.fields`
233
- reviewProperty.set({
234
- name: FORM_PROPERTY_NAME,
235
- initializer: `${reviewInitializer.getText()}.fields`
236
- });
237
- }
238
- }
239
- }
240
- return true;
241
- }
242
- function isRegisterAction(action) {
243
- const typeProperty = action.getProperty(TYPE_PROPERTY_NAME);
244
- if (!typeProperty || !ts_morph_1.Node.isPropertyAssignment(typeProperty))
245
- return false;
246
- const typeInit = typeProperty.getInitializer();
247
- if (!typeInit)
248
- return false;
249
- // Matches: ActionType.REGISTER
250
- if (ts_morph_1.Node.isPropertyAccessExpression(typeInit)) {
251
- const enumExpr = typeInit.getExpression();
252
- return (ts_morph_1.Node.isIdentifier(enumExpr) &&
253
- enumExpr.getText() === ACTION_TYPE_ENUM_NAME &&
254
- typeInit.getName() === REGISTER_MEMBER_NAME);
255
- }
256
- // Matches: "REGISTER"
257
- if (ts_morph_1.Node.isStringLiteral(typeInit)) {
258
- return typeInit.getLiteralValue() === REGISTER_STRING_LITERAL;
259
- }
260
- return false;
261
- }
262
- /**
263
- * Returns true if an array literal contains an object literal with `id: <id>`.
264
- */
265
- function arrayHasElementWithId(array, id) {
266
- for (const el of array.getElements()) {
267
- if (!ts_morph_1.Node.isObjectLiteralExpression(el))
268
- continue;
269
- const idProp = el.getProperty(ID_PROPERTY_NAME);
270
- if (!idProp || !ts_morph_1.Node.isPropertyAssignment(idProp))
271
- continue;
272
- const idInit = idProp.getInitializer();
273
- if (idInit &&
274
- ts_morph_1.Node.isStringLiteral(idInit) &&
275
- idInit.getLiteralValue() === id) {
276
- return true;
277
- }
278
- }
279
- return false;
280
- }
281
- /**
282
- * Adds `{ id: 'validated', operation: 'remove' }` to a REGISTER action's
283
- * `flags` array. Skips if any `validated` flag entry is already present —
284
- * this keeps the codemod idempotent and avoids stomping on an intentional
285
- * `add` op a maintainer may have authored manually.
286
- *
287
- * Returns true if a change was made.
288
- */
289
- function ensureRegisterRemovesValidatedFlag(action) {
290
- const entry = `{ id: '${VALIDATED_FLAG_VALUE}', operation: 'remove' }`;
291
- const flagsProp = action.getProperty(FLAGS_PROPERTY_NAME);
292
- if (flagsProp && ts_morph_1.Node.isPropertyAssignment(flagsProp)) {
293
- const flagsInit = flagsProp.getInitializer();
294
- if (flagsInit && ts_morph_1.Node.isArrayLiteralExpression(flagsInit)) {
295
- if (arrayHasElementWithId(flagsInit, VALIDATED_FLAG_VALUE))
296
- return false;
297
- flagsInit.addElement(entry);
298
- return true;
299
- }
300
- return false;
301
- }
302
- action.addPropertyAssignment({
303
- name: FLAGS_PROPERTY_NAME,
304
- initializer: `[${entry}]`
305
- });
306
- return true;
307
- }
308
- function processFile(filePath, project) {
309
- const sourceFile = project.getSourceFile(filePath);
310
- if (!sourceFile)
311
- return 0;
312
- let transformedCount = 0;
313
- // Find all call expressions named `defineConfig`
314
- const callExpressions = sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.CallExpression);
315
- for (const call of callExpressions) {
316
- const expression = call.getExpression();
317
- // Only interested in bare `defineConfig(...)` calls
318
- if (!ts_morph_1.Node.isIdentifier(expression) ||
319
- expression.getText() !== DEFINE_CONFIG_NAME) {
320
- continue;
321
- }
322
- const args = call.getArguments();
323
- if (args.length === 0)
324
- continue;
325
- // The first argument should be the config object literal
326
- const configArg = args[0];
327
- if (!ts_morph_1.Node.isObjectLiteralExpression(configArg))
328
- continue;
329
- // Find the `actions` property inside the config object
330
- const actionsProperty = configArg.getProperty(ACTIONS_PROPERTY_NAME);
331
- if (!actionsProperty || !ts_morph_1.Node.isPropertyAssignment(actionsProperty))
332
- continue;
333
- const actionsInitializer = actionsProperty.getInitializer();
334
- if (!actionsInitializer ||
335
- !ts_morph_1.Node.isArrayLiteralExpression(actionsInitializer))
336
- continue;
337
- // Resolve the root event type for use in the auditHistoryLabel id
338
- const eventType = resolveEventType(configArg);
339
- if (!eventType) {
340
- console.warn(` [${path_1.default.relative(process.cwd(), configArg.getSourceFile().getFilePath())}] Could not resolve root 'type' from defineConfig — skipping auditHistoryLabel id generation`);
341
- }
342
- // Iterate over every element in the `actions` array
343
- let fileNeedsImports = false;
344
- let configHadValidateAction = false;
345
- for (const element of actionsInitializer.getElements()) {
346
- if (!ts_morph_1.Node.isObjectLiteralExpression(element))
347
- continue;
348
- const wasTransformed = transformValidateActionToCustom(element, eventType !== null && eventType !== void 0 ? eventType : 'unknown');
349
- if (wasTransformed) {
350
- transformedCount++;
351
- fileNeedsImports = true;
352
- configHadValidateAction = true;
353
- console.log(` [${path_1.default.relative(process.cwd(), filePath)}] Transformed VALIDATE action to CUSTOM with customActionType: '${VALIDATE_DECLARATION_VALUE}'`);
354
- }
355
- }
356
- // Add top-level flags array to the config object if a VALIDATE action was found
357
- if (configHadValidateAction && !configArg.getProperty('flags')) {
358
- const resolvedEventType = eventType !== null && eventType !== void 0 ? eventType : 'unknown';
359
- configArg.addPropertyAssignment({
360
- name: 'flags',
361
- initializer: `[
362
- {
363
- id: 'validated',
364
- label: {
365
- id: 'event.${resolvedEventType}.flag.validated',
366
- defaultMessage: 'Validated',
367
- description: 'Flag label for validated'
368
- },
369
- requiresAction: true
370
- }
371
- ]`
372
- });
373
- console.log(` [${path_1.default.relative(process.cwd(), filePath)}] Added top-level 'flags' array to defineConfig`);
374
- }
375
- // Close the `validated` flag's lifecycle: when the validate action adds the
376
- // flag, the matching REGISTER action(s) must remove it on registration.
377
- if (configHadValidateAction) {
378
- for (const element of actionsInitializer.getElements()) {
379
- if (!ts_morph_1.Node.isObjectLiteralExpression(element))
380
- continue;
381
- if (!isRegisterAction(element))
382
- continue;
383
- if (ensureRegisterRemovesValidatedFlag(element)) {
384
- transformedCount++;
385
- console.log(` [${path_1.default.relative(process.cwd(), filePath)}] Added '${VALIDATED_FLAG_VALUE}' remove-flag to REGISTER action`);
386
- }
387
- }
388
- }
389
- if (fileNeedsImports) {
390
- ensureImports(sourceFile);
391
- }
392
- }
393
- return transformedCount;
394
- }
395
- function main() {
396
- return __awaiter(this, void 0, void 0, function* () {
397
- const srcDir = path_1.default.join(process.cwd(), 'src');
398
- console.log(`Scanning for defineConfig calls in: ${srcDir}\n`);
399
- const project = new ts_morph_1.Project({
400
- tsConfigFilePath: path_1.default.resolve(srcDir, '../tsconfig.json'),
401
- // Do not emit — we only manipulate source files
402
- skipAddingFilesFromTsConfig: false
403
- });
404
- // Restrict to source files only (exclude node_modules, build artefacts, etc.)
405
- const sourceFiles = project.getSourceFiles().filter((sf) => {
406
- const fp = sf.getFilePath();
407
- return fp.includes('/src/') && !fp.includes('/node_modules/');
408
- });
409
- console.log(`Found ${sourceFiles.length} source file(s) to analyse.\n`);
410
- let totalTransformed = 0;
411
- const modifiedFiles = [];
412
- for (const sourceFile of sourceFiles) {
413
- const filePath = sourceFile.getFilePath();
414
- const transformed = processFile(filePath, project);
415
- if (transformed > 0) {
416
- totalTransformed += transformed;
417
- modifiedFiles.push(filePath);
418
- }
419
- }
420
- if (modifiedFiles.length === 0) {
421
- console.log('No VALIDATE actions found inside defineConfig calls. Nothing to do.');
422
- return;
423
- }
424
- console.log(`\nSaving ${modifiedFiles.length} modified file(s)...`);
425
- for (const filePath of modifiedFiles) {
426
- const sourceFile = project.getSourceFileOrThrow(filePath);
427
- yield sourceFile.save();
428
- console.log(` Saved: ${path_1.default.relative(process.cwd(), filePath)}`);
429
- }
430
- console.log(`\nDone. Applied ${totalTransformed} change(s): VALIDATE → CUSTOM (${VALIDATE_DECLARATION_VALUE}) and '${VALIDATED_FLAG_VALUE}' remove-flag on matching REGISTER actions.`);
431
- });
432
- }