@opencrvs/toolkit 1.9.13-rc.fc5374d → 2.0.0-rc.0146adf

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 (154) hide show
  1. package/build.sh +13 -0
  2. package/dist/api/index.d.ts.map +1 -1
  3. package/dist/application-config/index.d.ts +2 -0
  4. package/dist/application-config/index.d.ts.map +1 -0
  5. package/dist/application-config/index.js +2156 -0
  6. package/dist/cli.d.ts +2 -0
  7. package/dist/cli.d.ts.map +1 -0
  8. package/dist/cli.js +4972 -0
  9. package/dist/commons/api/router.d.ts +3497 -2348
  10. package/dist/commons/application-config/index.d.ts +96 -0
  11. package/dist/commons/conditionals/conditionals.d.ts +27 -3
  12. package/dist/commons/conditionals/validate.d.ts +13 -3
  13. package/dist/commons/events/ActionConfig.d.ts +415 -1555
  14. package/dist/commons/events/ActionDocument.d.ts +888 -1941
  15. package/dist/commons/events/ActionInput.d.ts +277 -1073
  16. package/dist/commons/events/ActionType.d.ts +91 -11
  17. package/dist/commons/events/AdvancedSearchConfig.d.ts +294 -1496
  18. package/dist/commons/events/AuditLog.d.ts +407 -0
  19. package/dist/commons/events/CompositeFieldValue.d.ts +30 -190
  20. package/dist/commons/events/Conditional.d.ts +26 -38
  21. package/dist/commons/events/Constants.d.ts +1 -1
  22. package/dist/commons/events/CountryConfigQueryInput.d.ts +1592 -4471
  23. package/dist/commons/events/DeduplicationConfig.d.ts +15 -171
  24. package/dist/commons/events/Draft.d.ts +72 -107
  25. package/dist/commons/events/DynamicFieldValue.d.ts +12 -78
  26. package/dist/commons/events/EventConfig.d.ts +37 -2420
  27. package/dist/commons/events/EventConfigInput.d.ts +0 -3
  28. package/dist/commons/events/EventDocument.d.ts +354 -1366
  29. package/dist/commons/events/EventIndex.d.ts +212 -1010
  30. package/dist/commons/events/EventInput.d.ts +3 -8
  31. package/dist/commons/events/EventMetadata.d.ts +130 -357
  32. package/dist/commons/events/FieldConfig.d.ts +2897 -12892
  33. package/dist/commons/events/FieldType.d.ts +26 -4
  34. package/dist/commons/events/FieldTypeMapping.d.ts +314 -906
  35. package/dist/commons/events/FieldValue.d.ts +149 -527
  36. package/dist/commons/events/FileUtils.d.ts +2 -2
  37. package/dist/commons/events/Flag.d.ts +67 -0
  38. package/dist/commons/events/FormConfig.d.ts +54 -721
  39. package/dist/commons/events/PageConfig.d.ts +58 -320
  40. package/dist/commons/events/PlainDate.d.ts +1 -1
  41. package/dist/commons/events/SummaryConfig.d.ts +14 -161
  42. package/dist/commons/events/TemplateConfig.d.ts +2 -3
  43. package/dist/commons/events/TranslationConfig.d.ts +2 -2
  44. package/dist/commons/events/WorkqueueColumnConfig.d.ts +74 -37
  45. package/dist/commons/events/WorkqueueConfig.d.ts +2208 -7553
  46. package/dist/commons/events/deduplication.d.ts +3 -3
  47. package/dist/commons/events/defineConfig.d.ts +2 -247
  48. package/dist/commons/events/eventConfigValidation.d.ts +8 -0
  49. package/dist/commons/events/index.d.ts +3 -0
  50. package/dist/commons/events/locations.d.ts +73 -20
  51. package/dist/commons/events/scopes.d.ts +36 -35
  52. package/dist/commons/events/state/availableActions.d.ts +7 -2
  53. package/dist/commons/events/state/flags.d.ts +21 -3
  54. package/dist/commons/events/state/index.d.ts +30 -27
  55. package/dist/commons/events/state/utils.d.ts +190 -172
  56. package/dist/commons/events/test.utils.d.ts +52 -11
  57. package/dist/commons/events/transactions.d.ts +1 -1
  58. package/dist/commons/events/utils.d.ts +373 -273
  59. package/dist/commons/notification/UserNotifications.d.ts +76 -637
  60. package/dist/conditionals/index.d.ts.map +1 -1
  61. package/dist/conditionals/index.js +330 -14
  62. package/dist/events/deduplication.d.ts +3 -3
  63. package/dist/events/index.js +2930 -2118
  64. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts +3 -0
  65. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts.map +1 -0
  66. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.js +429 -0
  67. package/dist/migrations/v2.0/add-resend-invite-notification.d.ts +3 -0
  68. package/dist/migrations/v2.0/add-resend-invite-notification.d.ts.map +1 -0
  69. package/dist/migrations/v2.0/add-resend-invite-notification.js +373 -0
  70. package/dist/migrations/v2.0/checkout-upstream-files.d.ts +22 -0
  71. package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +1 -0
  72. package/dist/migrations/v2.0/checkout-upstream-files.js +147 -0
  73. package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts +2 -0
  74. package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts.map +1 -0
  75. package/dist/migrations/v2.0/convert-config-files-to-ts.js +828 -0
  76. package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts +3 -0
  77. package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts.map +1 -0
  78. package/dist/migrations/v2.0/convert-paragraph-to-heading.js +158 -0
  79. package/dist/migrations/v2.0/create-events-index.d.ts +3 -0
  80. package/dist/migrations/v2.0/create-events-index.d.ts.map +1 -0
  81. package/dist/migrations/v2.0/create-events-index.js +325 -0
  82. package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts +3 -0
  83. package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts.map +1 -0
  84. package/dist/migrations/v2.0/delete-infrastructure-directory.js +77 -0
  85. package/dist/migrations/v2.0/index.d.ts +11 -0
  86. package/dist/migrations/v2.0/index.d.ts.map +1 -0
  87. package/dist/migrations/v2.0/index.js +4882 -0
  88. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts +3 -0
  89. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts.map +1 -0
  90. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.js +432 -0
  91. package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts +3 -0
  92. package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts.map +1 -0
  93. package/dist/migrations/v2.0/merge-infrastructure-directory.js +221 -0
  94. package/dist/migrations/v2.0/migrate-application-config-url.d.ts +3 -0
  95. package/dist/migrations/v2.0/migrate-application-config-url.d.ts.map +1 -0
  96. package/dist/migrations/v2.0/migrate-application-config-url.js +342 -0
  97. package/dist/migrations/v2.0/migrate-scopes.d.ts +3 -0
  98. package/dist/migrations/v2.0/migrate-scopes.d.ts.map +1 -0
  99. package/dist/migrations/v2.0/migrate-scopes.js +281 -0
  100. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts +3 -0
  101. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts.map +1 -0
  102. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.js +267 -0
  103. package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts +3 -0
  104. package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts.map +1 -0
  105. package/dist/migrations/v2.0/migrate-workqueue-configs.js +236 -0
  106. package/dist/migrations/v2.0/remove-delete-actions.d.ts +3 -0
  107. package/dist/migrations/v2.0/remove-delete-actions.d.ts.map +1 -0
  108. package/dist/migrations/v2.0/remove-delete-actions.js +156 -0
  109. package/dist/migrations/v2.0/remove-demo-scope.d.ts +3 -0
  110. package/dist/migrations/v2.0/remove-demo-scope.d.ts.map +1 -0
  111. package/dist/migrations/v2.0/remove-demo-scope.js +74 -0
  112. package/dist/migrations/v2.0/remove-deprecated-imports.d.ts +3 -0
  113. package/dist/migrations/v2.0/remove-deprecated-imports.d.ts.map +1 -0
  114. package/dist/migrations/v2.0/remove-deprecated-imports.js +96 -0
  115. package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts +3 -0
  116. package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts.map +1 -0
  117. package/dist/migrations/v2.0/remove-fhir-url-helpers.js +163 -0
  118. package/dist/migrations/v2.0/remove-hearth-migrations.d.ts +3 -0
  119. package/dist/migrations/v2.0/remove-hearth-migrations.d.ts.map +1 -0
  120. package/dist/migrations/v2.0/remove-hearth-migrations.js +77 -0
  121. package/dist/migrations/v2.0/remove-old-statistics-service.d.ts +3 -0
  122. package/dist/migrations/v2.0/remove-old-statistics-service.d.ts.map +1 -0
  123. package/dist/migrations/v2.0/remove-old-statistics-service.js +356 -0
  124. package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts +3 -0
  125. package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts.map +1 -0
  126. package/dist/migrations/v2.0/remove-pending-certification-flag.js +109 -0
  127. package/dist/migrations/v2.0/remove-review-from-register-action.d.ts +3 -0
  128. package/dist/migrations/v2.0/remove-review-from-register-action.d.ts.map +1 -0
  129. package/dist/migrations/v2.0/remove-review-from-register-action.js +163 -0
  130. package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts +3 -0
  131. package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts.map +1 -0
  132. package/dist/migrations/v2.0/remove-unused-environment-variables.js +186 -0
  133. package/dist/migrations/v2.0/rename-api-paths.d.ts +3 -0
  134. package/dist/migrations/v2.0/rename-api-paths.d.ts.map +1 -0
  135. package/dist/migrations/v2.0/rename-api-paths.js +187 -0
  136. package/dist/migrations/v2.0/rename-location-parent-id.d.ts +3 -0
  137. package/dist/migrations/v2.0/rename-location-parent-id.d.ts.map +1 -0
  138. package/dist/migrations/v2.0/rename-location-parent-id.js +180 -0
  139. package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts +3 -0
  140. package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts.map +1 -0
  141. package/dist/migrations/v2.0/simplify-analytics-precalculations.js +195 -0
  142. package/dist/migrations/v2.0/update-package-json.d.ts +3 -0
  143. package/dist/migrations/v2.0/update-package-json.d.ts.map +1 -0
  144. package/dist/migrations/v2.0/update-package-json.js +105 -0
  145. package/dist/notification/index.d.ts.map +1 -1
  146. package/dist/notification/index.js +2110 -1767
  147. package/dist/scopes/index.d.ts +711 -352
  148. package/dist/scopes/index.d.ts.map +1 -1
  149. package/dist/scopes/index.js +372 -299
  150. package/opencrvs-toolkit-2.0.0-rc.0146adf.tgz +0 -0
  151. package/package.json +18 -8
  152. package/tsconfig.json +12 -2
  153. package/tsconfig.tsbuildinfo +1 -1
  154. package/dist/commons/events/CreatedAtLocation.d.ts +0 -2
@@ -0,0 +1,3 @@
1
+ declare function main(): Promise<void>;
2
+ export { main };
3
+ //# sourceMappingURL=make-built-in-validate-actions-custom.d.ts.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,432 @@
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
+ }
@@ -0,0 +1,3 @@
1
+ declare function main(): Promise<void>;
2
+ export { main };
3
+ //# sourceMappingURL=merge-infrastructure-directory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"merge-infrastructure-directory.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/merge-infrastructure-directory.ts"],"names":[],"mappings":"AAsHA,iBAAe,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAkInC;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
@@ -0,0 +1,221 @@
1
+ "use strict";
2
+ /*
3
+ * This Source Code Form is subject to the terms of the Mozilla Public
4
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/.
6
+ *
7
+ * OpenCRVS is also distributed under the terms of the Civil Registration
8
+ * & Healthcare Disclaimer located at http://opencrvs.org/license.
9
+ *
10
+ * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
11
+ */
12
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
+ return new (P || (P = Promise))(function (resolve, reject) {
15
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
19
+ });
20
+ };
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.main = main;
23
+ /**
24
+ * Codemod: Merge upstream changes into the local `infrastructure/` directory
25
+ * from opencrvs/opencrvs-countryconfig.
26
+ *
27
+ * Usage:
28
+ * ts-node -r tsconfig-paths/register src/migrations/v2.0/merge-infrastructure-directory.ts
29
+ *
30
+ * What it does:
31
+ * 1. Registers a temporary git remote that points at the canonical
32
+ * opencrvs-countryconfig repository and fetches both:
33
+ * - the upstream "theirs" branch (v2.0) → `UPSTREAM_BRANCH`
34
+ * - the synthetic merge-base branch (latest 1.9 release line)
35
+ * → `BASE_BRANCH`
36
+ * 2. For every file under `infrastructure/` on upstream "theirs", performs
37
+ * a file-scoped 3-way merge:
38
+ * - new file on upstream → checked out and staged
39
+ * - existing file → 3-way merged in place via `git merge-file`,
40
+ * using the BASE_BRANCH version of the file
41
+ * as the ancestor (or an empty file if the
42
+ * base doesn't have it)
43
+ * Files local to the country config that don't exist on upstream are
44
+ * left untouched.
45
+ * 3. Cleanly merged files are staged. Files with conflicts are left in the
46
+ * working tree with standard <<<<<<< / ======= / >>>>>>> markers and
47
+ * MUST be resolved manually by the developer.
48
+ * 4. Removes the temporary remote in all cases (success, failure, or
49
+ * unexpected error) via a `finally` block.
50
+ *
51
+ * Why a content-based synthetic merge-base instead of `git merge-base`:
52
+ * - Country config repos rarely share git history with
53
+ * opencrvs-countryconfig (squashed forks, template-cloned repos, etc.),
54
+ * so `git merge-base HEAD upstream/develop` typically returns nothing.
55
+ * - With no merge-base, a 3-way merge degenerates to a 2-way diff against
56
+ * an empty file — every line that differs becomes a conflict.
57
+ * - `release-v1.9` is the latest 1.9.x release line on upstream and is a
58
+ * near-perfect representation of "what `infrastructure/` looked like
59
+ * before v2.0", regardless of whether the fork's git history reaches it.
60
+ * - For files the country config never modified relative to that baseline,
61
+ * `git merge-file` resolves cleanly to upstream's v2.0 version. Conflicts
62
+ * are produced only where local edits genuinely overlap with v1.9 → v2.0
63
+ * upstream edits — which is what the developer needs to review anyway.
64
+ *
65
+ * Why per-file merge instead of a real `git merge`:
66
+ * - Limits the blast radius to `infrastructure/` only — no other paths
67
+ * are touched.
68
+ * - Doesn't put the repository into an in-progress merge state
69
+ * (no MERGE_HEAD), so subsequent codemods/commands behave normally.
70
+ * - Works regardless of whether the local repo shares history with
71
+ * opencrvs-countryconfig.
72
+ *
73
+ * Caveats:
74
+ * - Local edits to merged files may be overwritten where they overlap
75
+ * with upstream changes. Run on a clean working tree.
76
+ * - Requires git to be installed and network access to github.com.
77
+ * - Requires the country config working directory to be a git repo.
78
+ * - Binary files in `infrastructure/` are not merged textually; if both
79
+ * sides changed a binary file, the result will be invalid and a warning
80
+ * is printed.
81
+ * - Forks that are on a much older 1.9.x and never merged later 1.9 patches
82
+ * may see a few extra conflicts on files where 1.9.x → release-v1.9
83
+ * patches and v1.9 → v2.0 changes textually overlap.
84
+ */
85
+ const child_process_1 = require("child_process");
86
+ const fs_1 = require("fs");
87
+ const os_1 = require("os");
88
+ const path_1 = require("path");
89
+ const checkout_upstream_files_1 = require("./checkout-upstream-files");
90
+ // Distinct from the remote used by `checkout-upstream-files` so that a stale
91
+ // remote left behind by an aborted run of one codemod doesn't trip up the
92
+ // other.
93
+ const TEMP_REMOTE = 'opencrvs-upgrade-v19-v20-codemod-merge-infra';
94
+ const INFRASTRUCTURE_DIR = 'infrastructure';
95
+ // Synthetic merge-base: the tip of upstream's latest 1.9.x release line.
96
+ // We use this branch's content as the "common ancestor" for every file,
97
+ // since most country forks don't share git history with upstream.
98
+ const BASE_BRANCH = 'release-v1.9';
99
+ /**
100
+ * Reads `git show <ref>:<path>` as a Uint8Array (binary-safe).
101
+ * Returns `null` if the path doesn't exist at that ref.
102
+ */
103
+ function gitShowBytes(ref, path) {
104
+ try {
105
+ const buf = (0, child_process_1.execFileSync)('git', ['show', `${ref}:${path}`], {
106
+ cwd: process.cwd(),
107
+ stdio: ['ignore', 'pipe', 'pipe']
108
+ });
109
+ // Return a plain Uint8Array view to satisfy strict typings of `fs`
110
+ // (which want `ArrayBufferView`, not Node's `Buffer` subtype).
111
+ return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
112
+ }
113
+ catch (_a) {
114
+ return null;
115
+ }
116
+ }
117
+ // ─── Entry point ─────────────────────────────────────────────────────────────
118
+ function main() {
119
+ return __awaiter(this, void 0, void 0, function* () {
120
+ console.log(`Merging '${INFRASTRUCTURE_DIR}/' from ${checkout_upstream_files_1.UPSTREAM_URL}@${checkout_upstream_files_1.UPSTREAM_BRANCH} (base: ${BASE_BRANCH})...\n`);
121
+ (0, checkout_upstream_files_1.assertIsGitRepo)();
122
+ // Best-effort cleanup of a stale temp remote from a previous aborted run.
123
+ (0, checkout_upstream_files_1.tryGit)(['remote', 'remove', TEMP_REMOTE]);
124
+ try {
125
+ console.log(` Adding temporary remote '${TEMP_REMOTE}' → ${checkout_upstream_files_1.UPSTREAM_URL}`);
126
+ (0, checkout_upstream_files_1.runGit)(['remote', 'add', TEMP_REMOTE, checkout_upstream_files_1.UPSTREAM_URL], { silent: true });
127
+ // Fetch both branches at depth=1 — we only need their tip contents,
128
+ // not their history (the merge is content-based, not history-based).
129
+ console.log(` Fetching ${TEMP_REMOTE}/{${checkout_upstream_files_1.UPSTREAM_BRANCH},${BASE_BRANCH}} (depth 1)...`);
130
+ (0, checkout_upstream_files_1.runGit)(['fetch', '--depth=1', TEMP_REMOTE, checkout_upstream_files_1.UPSTREAM_BRANCH, BASE_BRANCH]);
131
+ const ref = `${TEMP_REMOTE}/${checkout_upstream_files_1.UPSTREAM_BRANCH}`;
132
+ const baseRef = `${TEMP_REMOTE}/${BASE_BRANCH}`;
133
+ // -z gives NUL-separated paths so filenames with spaces or newlines
134
+ // survive the round-trip.
135
+ const upstreamFiles = (0, checkout_upstream_files_1.runGit)([
136
+ 'ls-tree',
137
+ '-r',
138
+ '--name-only',
139
+ '-z',
140
+ ref,
141
+ '--',
142
+ `${INFRASTRUCTURE_DIR}/`
143
+ ], { silent: true })
144
+ .split('\0')
145
+ .filter(Boolean);
146
+ if (upstreamFiles.length === 0) {
147
+ console.log(` No files found under '${INFRASTRUCTURE_DIR}/' on ${ref}. Nothing to merge.`);
148
+ return;
149
+ }
150
+ const tmpDir = (0, fs_1.mkdtempSync)((0, path_1.join)((0, os_1.tmpdir)(), 'opencrvs-merge-infra-'));
151
+ const baseTmp = (0, path_1.join)(tmpDir, 'base');
152
+ const theirsTmp = (0, path_1.join)(tmpDir, 'theirs');
153
+ let added = 0;
154
+ let merged = 0;
155
+ const conflictedFiles = [];
156
+ for (const file of upstreamFiles) {
157
+ const fullPath = (0, path_1.join)(process.cwd(), file);
158
+ if (!(0, fs_1.existsSync)(fullPath)) {
159
+ // New upstream file — `git checkout` handles binary correctly and
160
+ // stages the result, matching the UX of `checkout-upstream-files`.
161
+ if ((0, checkout_upstream_files_1.tryGit)(['checkout', ref, '--', file])) {
162
+ console.log(` + ${file} (new from upstream)`);
163
+ added++;
164
+ }
165
+ else {
166
+ console.warn(` [warn] failed to add new file ${file}`);
167
+ }
168
+ continue;
169
+ }
170
+ const theirContents = gitShowBytes(ref, file);
171
+ if (theirContents === null) {
172
+ // Shouldn't happen — `ls-tree` just told us the file is there.
173
+ console.warn(` [warn] could not read ${file} from ${ref} — skipping.`);
174
+ continue;
175
+ }
176
+ (0, fs_1.writeFileSync)(theirsTmp, theirContents);
177
+ // Pull the base version from upstream's latest 1.9 release line. If
178
+ // the file didn't exist there yet (added in v2.0), fall back to an
179
+ // empty base — `git merge-file` will then treat any local content as
180
+ // a local addition.
181
+ const baseContents = gitShowBytes(baseRef, file);
182
+ (0, fs_1.writeFileSync)(baseTmp, baseContents !== null && baseContents !== void 0 ? baseContents : new Uint8Array(0));
183
+ // `git merge-file` does an in-place 3-way merge. Exit codes:
184
+ // 0 → clean merge
185
+ // 1..N → that many conflicts; markers written into the file
186
+ // <0/127 → error (e.g. binary file rejected)
187
+ try {
188
+ (0, child_process_1.execFileSync)('git', ['merge-file', fullPath, baseTmp, theirsTmp], {
189
+ cwd: process.cwd(),
190
+ stdio: ['ignore', 'pipe', 'pipe']
191
+ });
192
+ (0, checkout_upstream_files_1.runGit)(['add', '--', file], { silent: true });
193
+ merged++;
194
+ }
195
+ catch (err) {
196
+ const status = err.status;
197
+ if (typeof status === 'number' && status > 0) {
198
+ conflictedFiles.push(file);
199
+ console.warn(` ! ${file} (${status} conflict${status > 1 ? 's' : ''})`);
200
+ }
201
+ else {
202
+ conflictedFiles.push(file);
203
+ console.warn(` [warn] merge failed for ${file} (likely binary or unreadable) — left untouched.`);
204
+ }
205
+ }
206
+ }
207
+ console.log(`\n Done. ${added} added, ${merged} merged cleanly, ${conflictedFiles.length} with conflicts.`);
208
+ if (conflictedFiles.length > 0) {
209
+ console.warn(`\n NOTE: ${conflictedFiles.length} file(s) under '${INFRASTRUCTURE_DIR}/' have merge conflicts that you must resolve manually.\n` +
210
+ ` Look for the standard conflict markers (<<<<<<<, =======, >>>>>>>) in:\n` +
211
+ conflictedFiles.map((f) => ` - ${f}`).join('\n') +
212
+ `\n After resolving, stage the fixes with: git add ${INFRASTRUCTURE_DIR}/`);
213
+ }
214
+ }
215
+ finally {
216
+ if ((0, checkout_upstream_files_1.tryGit)(['remote', 'remove', TEMP_REMOTE])) {
217
+ console.log(` Removed temporary remote '${TEMP_REMOTE}'.`);
218
+ }
219
+ }
220
+ });
221
+ }
@@ -0,0 +1,3 @@
1
+ declare function main(): Promise<void>;
2
+ export { main };
3
+ //# sourceMappingURL=migrate-application-config-url.d.ts.map