@opencrvs/toolkit 1.9.13-rc.fc5374d → 2.0.0-rc.e0918cb

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 (130) 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 +2128 -0
  6. package/dist/cli.d.ts +2 -0
  7. package/dist/cli.d.ts.map +1 -0
  8. package/dist/cli.js +3633 -0
  9. package/dist/commons/api/router.d.ts +3438 -2300
  10. package/dist/commons/application-config/index.d.ts +84 -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 +405 -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 +2892 -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 +57 -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 +61 -637
  60. package/dist/conditionals/index.d.ts.map +1 -1
  61. package/dist/conditionals/index.js +302 -14
  62. package/dist/events/deduplication.d.ts +3 -3
  63. package/dist/events/index.js +2860 -2115
  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 +405 -0
  67. package/dist/migrations/v2.0/checkout-upstream-files.d.ts +3 -0
  68. package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +1 -0
  69. package/dist/migrations/v2.0/checkout-upstream-files.js +143 -0
  70. package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts +2 -0
  71. package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts.map +1 -0
  72. package/dist/migrations/v2.0/convert-config-files-to-ts.js +829 -0
  73. package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts +3 -0
  74. package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts.map +1 -0
  75. package/dist/migrations/v2.0/convert-paragraph-to-heading.js +159 -0
  76. package/dist/migrations/v2.0/create-events-index.d.ts +3 -0
  77. package/dist/migrations/v2.0/create-events-index.d.ts.map +1 -0
  78. package/dist/migrations/v2.0/create-events-index.js +326 -0
  79. package/dist/migrations/v2.0/index.d.ts +7 -0
  80. package/dist/migrations/v2.0/index.d.ts.map +1 -0
  81. package/dist/migrations/v2.0/index.js +3572 -0
  82. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts +3 -0
  83. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts.map +1 -0
  84. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.js +344 -0
  85. package/dist/migrations/v2.0/migrate-scopes.d.ts +3 -0
  86. package/dist/migrations/v2.0/migrate-scopes.d.ts.map +1 -0
  87. package/dist/migrations/v2.0/migrate-scopes.js +282 -0
  88. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts +3 -0
  89. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts.map +1 -0
  90. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.js +268 -0
  91. package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts +3 -0
  92. package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts.map +1 -0
  93. package/dist/migrations/v2.0/migrate-workqueue-configs.js +237 -0
  94. package/dist/migrations/v2.0/remove-delete-actions.d.ts +3 -0
  95. package/dist/migrations/v2.0/remove-delete-actions.d.ts.map +1 -0
  96. package/dist/migrations/v2.0/remove-delete-actions.js +157 -0
  97. package/dist/migrations/v2.0/remove-demo-scope.d.ts +3 -0
  98. package/dist/migrations/v2.0/remove-demo-scope.d.ts.map +1 -0
  99. package/dist/migrations/v2.0/remove-demo-scope.js +75 -0
  100. package/dist/migrations/v2.0/remove-deprecated-imports.d.ts +3 -0
  101. package/dist/migrations/v2.0/remove-deprecated-imports.d.ts.map +1 -0
  102. package/dist/migrations/v2.0/remove-deprecated-imports.js +97 -0
  103. package/dist/migrations/v2.0/remove-hearth-migrations.d.ts +3 -0
  104. package/dist/migrations/v2.0/remove-hearth-migrations.d.ts.map +1 -0
  105. package/dist/migrations/v2.0/remove-hearth-migrations.js +78 -0
  106. package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts +3 -0
  107. package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts.map +1 -0
  108. package/dist/migrations/v2.0/remove-pending-certification-flag.js +110 -0
  109. package/dist/migrations/v2.0/remove-review-from-register-action.d.ts +3 -0
  110. package/dist/migrations/v2.0/remove-review-from-register-action.d.ts.map +1 -0
  111. package/dist/migrations/v2.0/remove-review-from-register-action.js +164 -0
  112. package/dist/migrations/v2.0/rename-api-paths.d.ts +3 -0
  113. package/dist/migrations/v2.0/rename-api-paths.d.ts.map +1 -0
  114. package/dist/migrations/v2.0/rename-api-paths.js +188 -0
  115. package/dist/migrations/v2.0/rename-location-parent-id.d.ts +3 -0
  116. package/dist/migrations/v2.0/rename-location-parent-id.d.ts.map +1 -0
  117. package/dist/migrations/v2.0/rename-location-parent-id.js +181 -0
  118. package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts +3 -0
  119. package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts.map +1 -0
  120. package/dist/migrations/v2.0/simplify-analytics-precalculations.js +196 -0
  121. package/dist/notification/index.d.ts.map +1 -1
  122. package/dist/notification/index.js +2076 -1767
  123. package/dist/scopes/index.d.ts +640 -353
  124. package/dist/scopes/index.d.ts.map +1 -1
  125. package/dist/scopes/index.js +340 -300
  126. package/opencrvs-toolkit-2.0.0-rc.e0918cb.tgz +0 -0
  127. package/package.json +18 -8
  128. package/tsconfig.json +12 -2
  129. package/tsconfig.tsbuildinfo +1 -1
  130. 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":"AA6WA,iBAAe,IAAI,kBAiDlB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
@@ -0,0 +1,344 @@
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
+ * - Saves the modified files in-place
45
+ */
46
+ const ts_morph_1 = require("ts-morph");
47
+ const path_1 = __importDefault(require("path"));
48
+ const _1 = require(".");
49
+ const TOOLKIT_EVENTS_MODULE = '@opencrvs/toolkit/events';
50
+ const REQUIRED_SYMBOLS = [
51
+ 'ConditionalType',
52
+ 'and',
53
+ 'status',
54
+ 'not',
55
+ 'flag',
56
+ 'InherentFlags'
57
+ ];
58
+ function ensureImports(sourceFile) {
59
+ const existingImport = sourceFile.getImportDeclaration((decl) => decl.getModuleSpecifierValue() === TOOLKIT_EVENTS_MODULE);
60
+ if (existingImport) {
61
+ const existingNames = new Set(existingImport.getNamedImports().map((ni) => ni.getName()));
62
+ for (const name of REQUIRED_SYMBOLS) {
63
+ if (!existingNames.has(name)) {
64
+ existingImport.addNamedImport(name);
65
+ }
66
+ }
67
+ }
68
+ else {
69
+ sourceFile.addImportDeclaration({
70
+ moduleSpecifier: TOOLKIT_EVENTS_MODULE,
71
+ namedImports: REQUIRED_SYMBOLS
72
+ });
73
+ }
74
+ }
75
+ const DEFINE_CONFIG_NAME = 'defineConfig';
76
+ const ACTIONS_PROPERTY_NAME = 'actions';
77
+ const TYPE_PROPERTY_NAME = 'type';
78
+ const CUSTOM_ACTION_TYPE_PROPERTY_NAME = 'customActionType';
79
+ const AUDIT_HISTORY_LABEL_PROPERTY_NAME = 'auditHistoryLabel';
80
+ const DEDUPLICATION_PROPERTY_NAME = 'deduplication';
81
+ const REVIEW_PROPERTY_NAME = 'review';
82
+ const FIELDS_PROPERTY_NAME = 'fields';
83
+ const FORM_PROPERTY_NAME = 'form';
84
+ const ACTION_TYPE_ENUM_NAME = 'ActionType';
85
+ const VALIDATE_MEMBER_NAME = 'VALIDATE';
86
+ const CUSTOM_MEMBER_NAME = 'CUSTOM';
87
+ const VALIDATE_STRING_LITERAL = 'VALIDATE';
88
+ const CUSTOM_STRING_LITERAL = 'CUSTOM';
89
+ const VALIDATE_DECLARATION_VALUE = 'VALIDATE_DECLARATION';
90
+ function isValidateType(typeInitializer) {
91
+ // Matches: ActionType.VALIDATE
92
+ if (typeInitializer.getKind() === ts_morph_1.SyntaxKind.PropertyAccessExpression) {
93
+ const propAccess = typeInitializer.asKindOrThrow(ts_morph_1.SyntaxKind.PropertyAccessExpression);
94
+ const obj = propAccess.getExpression();
95
+ const member = propAccess.getName();
96
+ return (ts_morph_1.Node.isIdentifier(obj) &&
97
+ obj.getText() === ACTION_TYPE_ENUM_NAME &&
98
+ member === VALIDATE_MEMBER_NAME);
99
+ }
100
+ // Matches: "VALIDATE"
101
+ if (typeInitializer.getKind() === ts_morph_1.SyntaxKind.StringLiteral) {
102
+ return (typeInitializer
103
+ .asKindOrThrow(ts_morph_1.SyntaxKind.StringLiteral)
104
+ .getLiteralValue() === VALIDATE_STRING_LITERAL);
105
+ }
106
+ return false;
107
+ }
108
+ function resolveEventType(configArg) {
109
+ const typeProperty = configArg.getProperty(TYPE_PROPERTY_NAME);
110
+ if (!typeProperty || !ts_morph_1.Node.isPropertyAssignment(typeProperty))
111
+ return null;
112
+ const initializer = typeProperty.getInitializer();
113
+ if (!initializer)
114
+ return null;
115
+ // 'birth' / 'death' etc. — use the literal value directly
116
+ if (ts_morph_1.Node.isStringLiteral(initializer)) {
117
+ return initializer.getLiteralValue().toLowerCase();
118
+ }
119
+ // EventType.BIRTH — extract and lowercase the member name
120
+ if (initializer.getKind() === ts_morph_1.SyntaxKind.PropertyAccessExpression &&
121
+ ts_morph_1.Node.isPropertyAccessExpression(initializer)) {
122
+ return initializer.getName().toLowerCase();
123
+ }
124
+ return null;
125
+ }
126
+ function transformValidateActionToCustom(obj, eventType) {
127
+ const typeProperty = obj.getProperty(TYPE_PROPERTY_NAME);
128
+ if (!typeProperty || !ts_morph_1.Node.isPropertyAssignment(typeProperty)) {
129
+ return false;
130
+ }
131
+ const typeInitializer = typeProperty.getInitializer();
132
+ if (!typeInitializer || !isValidateType(typeInitializer)) {
133
+ return false;
134
+ }
135
+ // Replace the type value: ActionType.VALIDATE -> ActionType.CUSTOM, "VALIDATE" -> "CUSTOM"
136
+ if (typeInitializer.getKind() === ts_morph_1.SyntaxKind.PropertyAccessExpression) {
137
+ typeInitializer.replaceWithText(`${ACTION_TYPE_ENUM_NAME}.${CUSTOM_MEMBER_NAME}`);
138
+ }
139
+ else {
140
+ typeInitializer.replaceWithText(`'${CUSTOM_STRING_LITERAL}'`);
141
+ }
142
+ // Add customActionType: 'VALIDATE_DECLARATION' if not already present
143
+ if (!obj.getProperty(CUSTOM_ACTION_TYPE_PROPERTY_NAME)) {
144
+ obj.addPropertyAssignment({
145
+ name: CUSTOM_ACTION_TYPE_PROPERTY_NAME,
146
+ initializer: `'${VALIDATE_DECLARATION_VALUE}'`
147
+ });
148
+ }
149
+ // Add auditHistoryLabel intl descriptor if not already present
150
+ if (!obj.getProperty(AUDIT_HISTORY_LABEL_PROPERTY_NAME)) {
151
+ const messageId = `event.${eventType}.custom.action.validate-declaration.audit-history-label`;
152
+ obj.addPropertyAssignment({
153
+ name: AUDIT_HISTORY_LABEL_PROPERTY_NAME,
154
+ initializer: `{
155
+ defaultMessage: 'Validated',
156
+ description: 'The label to show in audit history for the validate action',
157
+ id: '${messageId}'
158
+ }`
159
+ });
160
+ }
161
+ // Add supportingCopy intl descriptor if not already present
162
+ if (!obj.getProperty('supportingCopy')) {
163
+ const supportingCopyId = `event.${eventType}.custom.action.validate-declaration.supportingCopy`;
164
+ obj.addPropertyAssignment({
165
+ name: 'supportingCopy',
166
+ initializer: `{
167
+ defaultMessage:
168
+ 'Approving this declaration confirms it as legally accepted and eligible for registration.',
169
+ description:
170
+ 'This is the supporting copy for the Validate declaration -action',
171
+ id: '${supportingCopyId}'
172
+ }`
173
+ });
174
+ }
175
+ // Add conditionals if not already present
176
+ if (!obj.getProperty('conditionals')) {
177
+ obj.addPropertyAssignment({
178
+ name: 'conditionals',
179
+ initializer: `[
180
+ {
181
+ type: ConditionalType.SHOW,
182
+ conditional: and(status('DECLARED'), not(flag('validated')))
183
+ },
184
+ {
185
+ type: ConditionalType.ENABLE,
186
+ conditional: not(flag(InherentFlags.POTENTIAL_DUPLICATE))
187
+ }
188
+ ]`
189
+ });
190
+ }
191
+ // Add flags if not already present
192
+ if (!obj.getProperty('flags')) {
193
+ obj.addPropertyAssignment({
194
+ name: 'flags',
195
+ initializer: `[{ id: 'validated', operation: 'add' }]`
196
+ });
197
+ }
198
+ // Remove the `deduplication` property if present
199
+ const deduplicationProperty = obj.getProperty(DEDUPLICATION_PROPERTY_NAME);
200
+ if (deduplicationProperty) {
201
+ deduplicationProperty.remove();
202
+ }
203
+ // Replace `review` with `form`:
204
+ // - `review: { fields: <value> }` → `form: <value>`
205
+ // - `review: <expr>` → `form: <expr>.fields`
206
+ const reviewProperty = obj.getProperty(REVIEW_PROPERTY_NAME);
207
+ if (reviewProperty && ts_morph_1.Node.isPropertyAssignment(reviewProperty)) {
208
+ const reviewInitializer = reviewProperty.getInitializer();
209
+ if (reviewInitializer) {
210
+ if (ts_morph_1.Node.isObjectLiteralExpression(reviewInitializer)) {
211
+ // Inline object: extract the `fields` value directly
212
+ const fieldsProperty = reviewInitializer.getProperty(FIELDS_PROPERTY_NAME);
213
+ if (fieldsProperty && ts_morph_1.Node.isPropertyAssignment(fieldsProperty)) {
214
+ const fieldsInitializer = fieldsProperty.getInitializer();
215
+ if (fieldsInitializer) {
216
+ reviewProperty.set({
217
+ name: FORM_PROPERTY_NAME,
218
+ initializer: fieldsInitializer.getText()
219
+ });
220
+ }
221
+ }
222
+ }
223
+ else {
224
+ // Reference or other expression: append `.fields`
225
+ reviewProperty.set({
226
+ name: FORM_PROPERTY_NAME,
227
+ initializer: `${reviewInitializer.getText()}.fields`
228
+ });
229
+ }
230
+ }
231
+ }
232
+ return true;
233
+ }
234
+ function processFile(filePath, project) {
235
+ const sourceFile = project.getSourceFile(filePath);
236
+ if (!sourceFile)
237
+ return 0;
238
+ let transformedCount = 0;
239
+ // Find all call expressions named `defineConfig`
240
+ const callExpressions = sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.CallExpression);
241
+ for (const call of callExpressions) {
242
+ const expression = call.getExpression();
243
+ // Only interested in bare `defineConfig(...)` calls
244
+ if (!ts_morph_1.Node.isIdentifier(expression) ||
245
+ expression.getText() !== DEFINE_CONFIG_NAME) {
246
+ continue;
247
+ }
248
+ const args = call.getArguments();
249
+ if (args.length === 0)
250
+ continue;
251
+ // The first argument should be the config object literal
252
+ const configArg = args[0];
253
+ if (!ts_morph_1.Node.isObjectLiteralExpression(configArg))
254
+ continue;
255
+ // Find the `actions` property inside the config object
256
+ const actionsProperty = configArg.getProperty(ACTIONS_PROPERTY_NAME);
257
+ if (!actionsProperty || !ts_morph_1.Node.isPropertyAssignment(actionsProperty))
258
+ continue;
259
+ const actionsInitializer = actionsProperty.getInitializer();
260
+ if (!actionsInitializer ||
261
+ !ts_morph_1.Node.isArrayLiteralExpression(actionsInitializer))
262
+ continue;
263
+ // Resolve the root event type for use in the auditHistoryLabel id
264
+ const eventType = resolveEventType(configArg);
265
+ if (!eventType) {
266
+ console.warn(` [${path_1.default.relative((0, _1.getCwd)(), configArg.getSourceFile().getFilePath())}] Could not resolve root 'type' from defineConfig — skipping auditHistoryLabel id generation`);
267
+ }
268
+ // Iterate over every element in the `actions` array
269
+ let fileNeedsImports = false;
270
+ let configHadValidateAction = false;
271
+ for (const element of actionsInitializer.getElements()) {
272
+ if (!ts_morph_1.Node.isObjectLiteralExpression(element))
273
+ continue;
274
+ const wasTransformed = transformValidateActionToCustom(element, eventType !== null && eventType !== void 0 ? eventType : 'unknown');
275
+ if (wasTransformed) {
276
+ transformedCount++;
277
+ fileNeedsImports = true;
278
+ configHadValidateAction = true;
279
+ console.log(` [${path_1.default.relative((0, _1.getCwd)(), filePath)}] Transformed VALIDATE action to CUSTOM with customActionType: '${VALIDATE_DECLARATION_VALUE}'`);
280
+ }
281
+ }
282
+ // Add top-level flags array to the config object if a VALIDATE action was found
283
+ if (configHadValidateAction && !configArg.getProperty('flags')) {
284
+ const resolvedEventType = eventType !== null && eventType !== void 0 ? eventType : 'unknown';
285
+ configArg.addPropertyAssignment({
286
+ name: 'flags',
287
+ initializer: `[
288
+ {
289
+ id: 'validated',
290
+ label: {
291
+ id: 'event.${resolvedEventType}.flag.validated',
292
+ defaultMessage: 'Validated',
293
+ description: 'Flag label for validated'
294
+ },
295
+ requiresAction: true
296
+ }
297
+ ]`
298
+ });
299
+ console.log(` [${path_1.default.relative((0, _1.getCwd)(), filePath)}] Added top-level 'flags' array to defineConfig`);
300
+ }
301
+ if (fileNeedsImports) {
302
+ ensureImports(sourceFile);
303
+ }
304
+ }
305
+ return transformedCount;
306
+ }
307
+ function main() {
308
+ return __awaiter(this, void 0, void 0, function* () {
309
+ const srcDir = path_1.default.join((0, _1.getCwd)(), 'src');
310
+ console.log(`Scanning for defineConfig calls in: ${srcDir}\n`);
311
+ const project = new ts_morph_1.Project({
312
+ tsConfigFilePath: path_1.default.resolve(srcDir, '../tsconfig.json'),
313
+ // Do not emit — we only manipulate source files
314
+ skipAddingFilesFromTsConfig: false
315
+ });
316
+ // Restrict to source files only (exclude node_modules, build artefacts, etc.)
317
+ const sourceFiles = project.getSourceFiles().filter((sf) => {
318
+ const fp = sf.getFilePath();
319
+ return fp.includes('/src/') && !fp.includes('/node_modules/');
320
+ });
321
+ console.log(`Found ${sourceFiles.length} source file(s) to analyse.\n`);
322
+ let totalTransformed = 0;
323
+ const modifiedFiles = [];
324
+ for (const sourceFile of sourceFiles) {
325
+ const filePath = sourceFile.getFilePath();
326
+ const transformed = processFile(filePath, project);
327
+ if (transformed > 0) {
328
+ totalTransformed += transformed;
329
+ modifiedFiles.push(filePath);
330
+ }
331
+ }
332
+ if (modifiedFiles.length === 0) {
333
+ console.log('No VALIDATE actions found inside defineConfig calls. Nothing to do.');
334
+ return;
335
+ }
336
+ console.log(`\nSaving ${modifiedFiles.length} modified file(s)...`);
337
+ for (const filePath of modifiedFiles) {
338
+ const sourceFile = project.getSourceFileOrThrow(filePath);
339
+ yield sourceFile.save();
340
+ console.log(` Saved: ${path_1.default.relative((0, _1.getCwd)(), filePath)}`);
341
+ }
342
+ console.log(`\nDone. Transformed ${totalTransformed} VALIDATE action(s) to CUSTOM with customActionType: '${VALIDATE_DECLARATION_VALUE}'.`);
343
+ });
344
+ }
@@ -0,0 +1,3 @@
1
+ declare function main(): Promise<void>;
2
+ export { main };
3
+ //# sourceMappingURL=migrate-scopes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrate-scopes.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/migrate-scopes.ts"],"names":[],"mappings":"AA2VA,iBAAe,IAAI,kBAmDlB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
@@ -0,0 +1,282 @@
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
+ const ts_morph_1 = require("ts-morph");
27
+ const path_1 = __importDefault(require("path"));
28
+ const scopes_1 = require("../commons/scopes");
29
+ const scopes_deprecated_do_not_use_1 = require("../commons/scopes.deprecated.do-not-use");
30
+ const _1 = require(".");
31
+ const ROLES_FILE_RELATIVE_PATH = 'src/data-seeding/roles/roles.ts';
32
+ const SCOPES_PROPERTY_NAME = 'scopes';
33
+ const TOOLKIT_SCOPES_MODULE = '@opencrvs/toolkit/scopes';
34
+ const DEFINE_SCOPES_IMPORT_NAME = 'defineScopes';
35
+ const DEFINE_ROLES_IMPORT_NAME = 'defineRoles';
36
+ function resolveScopeKeyFromElementAccess(element) {
37
+ if (ts_morph_1.Node.isPropertyAccessExpression(element) &&
38
+ element.getExpression().getText() === 'SCOPES') {
39
+ return element.getName();
40
+ }
41
+ if (ts_morph_1.Node.isElementAccessExpression(element) &&
42
+ element.getExpression().getText() === 'SCOPES') {
43
+ const argumentExpression = element.getArgumentExpression();
44
+ if (argumentExpression &&
45
+ (ts_morph_1.Node.isStringLiteral(argumentExpression) ||
46
+ ts_morph_1.Node.isNoSubstitutionTemplateLiteral(argumentExpression))) {
47
+ return argumentExpression.getLiteralValue();
48
+ }
49
+ }
50
+ return null;
51
+ }
52
+ function resolveLegacyScopeFromElement(element) {
53
+ if (ts_morph_1.Node.isStringLiteral(element) ||
54
+ ts_morph_1.Node.isNoSubstitutionTemplateLiteral(element)) {
55
+ return element.getLiteralValue();
56
+ }
57
+ const scopeKey = resolveScopeKeyFromElementAccess(element);
58
+ if (scopeKey) {
59
+ const scopeValue = scopes_deprecated_do_not_use_1.SCOPES[scopeKey];
60
+ return typeof scopeValue === 'string' ? scopeValue : null;
61
+ }
62
+ const expressionType = element.getType();
63
+ if (expressionType.isStringLiteral()) {
64
+ const literalValue = expressionType.getLiteralValue();
65
+ return typeof literalValue === 'string' ? literalValue : null;
66
+ }
67
+ return null;
68
+ }
69
+ function migrateScopesArrays(rolesFilePath, project) {
70
+ const sourceFile = project.getSourceFile(rolesFilePath);
71
+ if (!sourceFile)
72
+ return { migratedCount: 0, removedCount: 0 };
73
+ let migratedCount = 0;
74
+ let removedCount = 0;
75
+ const scopesProperties = sourceFile
76
+ .getDescendantsOfKind(ts_morph_1.SyntaxKind.PropertyAssignment)
77
+ .filter((prop) => prop.getName() === SCOPES_PROPERTY_NAME);
78
+ for (const scopesProp of scopesProperties) {
79
+ const initializer = scopesProp.getInitializer();
80
+ if (!initializer || !ts_morph_1.Node.isArrayLiteralExpression(initializer))
81
+ continue;
82
+ const elements = initializer.getElements();
83
+ for (let index = elements.length - 1; index >= 0; index--) {
84
+ const element = elements[index];
85
+ if (!ts_morph_1.Node.isExpression(element))
86
+ continue;
87
+ const scopeKey = resolveScopeKeyFromElementAccess(element);
88
+ if (scopeKey && !(scopeKey in scopes_deprecated_do_not_use_1.SCOPES)) {
89
+ // eslint-disable-next-line no-console
90
+ console.warn(` [${path_1.default.relative((0, _1.getCwd)(), rolesFilePath)}] Removing unknown scope reference: SCOPES.${scopeKey}`);
91
+ initializer.removeElement(index);
92
+ removedCount++;
93
+ continue;
94
+ }
95
+ const legacyScope = resolveLegacyScopeFromElement(element);
96
+ if (!legacyScope) {
97
+ // eslint-disable-next-line no-console
98
+ console.warn(` [${path_1.default.relative((0, _1.getCwd)(), rolesFilePath)}] Skipping non-literal scope expression: ${element.getText()}`);
99
+ continue;
100
+ }
101
+ try {
102
+ const migratedScope = (0, scopes_deprecated_do_not_use_1.legacyScopeToV2Scope)(legacyScope);
103
+ const scope = (0, scopes_1.decodeScope)(migratedScope);
104
+ if (!scope) {
105
+ // eslint-disable-next-line no-console
106
+ console.warn(` [${path_1.default.relative((0, _1.getCwd)(), rolesFilePath)}] Could not decode migrated scope '${migratedScope}'.`);
107
+ continue;
108
+ }
109
+ element.replaceWithText(JSON.stringify(scope));
110
+ migratedCount++;
111
+ }
112
+ catch (error) {
113
+ // eslint-disable-next-line no-console
114
+ console.warn(` [${path_1.default.relative((0, _1.getCwd)(), rolesFilePath)}] Could not migrate scope '${legacyScope}': ${error}`);
115
+ }
116
+ }
117
+ }
118
+ if (removedCount > 0) {
119
+ // eslint-disable-next-line no-console
120
+ console.log(` Removed ${removedCount} unknown SCOPES reference(s) from '${path_1.default.relative((0, _1.getCwd)(), rolesFilePath)}'.`);
121
+ }
122
+ return { migratedCount, removedCount };
123
+ }
124
+ function ensureScopesHelpersImport(rolesFilePath, project) {
125
+ const sourceFile = project.getSourceFile(rolesFilePath);
126
+ if (!sourceFile)
127
+ return false;
128
+ const existingImport = sourceFile.getImportDeclaration((decl) => decl.getModuleSpecifierValue() === TOOLKIT_SCOPES_MODULE);
129
+ let changed = false;
130
+ if (existingImport) {
131
+ const hasDefineScopesImport = existingImport
132
+ .getNamedImports()
133
+ .some((ni) => ni.getName() === DEFINE_SCOPES_IMPORT_NAME);
134
+ const hasDefineRolesImport = existingImport
135
+ .getNamedImports()
136
+ .some((ni) => ni.getName() === DEFINE_ROLES_IMPORT_NAME);
137
+ if (!hasDefineScopesImport) {
138
+ existingImport.addNamedImport(DEFINE_SCOPES_IMPORT_NAME);
139
+ changed = true;
140
+ }
141
+ if (!hasDefineRolesImport) {
142
+ existingImport.addNamedImport(DEFINE_ROLES_IMPORT_NAME);
143
+ changed = true;
144
+ }
145
+ const encodeScopeImport = existingImport
146
+ .getNamedImports()
147
+ .find((ni) => ni.getName() === 'encodeScope');
148
+ if (encodeScopeImport) {
149
+ encodeScopeImport.remove();
150
+ changed = true;
151
+ }
152
+ return changed;
153
+ }
154
+ sourceFile.addImportDeclaration({
155
+ moduleSpecifier: TOOLKIT_SCOPES_MODULE,
156
+ namedImports: [DEFINE_SCOPES_IMPORT_NAME, DEFINE_ROLES_IMPORT_NAME]
157
+ });
158
+ return true;
159
+ }
160
+ function wrapScopesArraysWithDefineScopes(rolesFilePath, project) {
161
+ const sourceFile = project.getSourceFile(rolesFilePath);
162
+ if (!sourceFile)
163
+ return 0;
164
+ let wrappedCount = 0;
165
+ const scopesProperties = sourceFile
166
+ .getDescendantsOfKind(ts_morph_1.SyntaxKind.PropertyAssignment)
167
+ .filter((prop) => prop.getName() === SCOPES_PROPERTY_NAME);
168
+ for (const scopesProp of scopesProperties) {
169
+ const initializer = scopesProp.getInitializer();
170
+ if (!initializer)
171
+ continue;
172
+ if (ts_morph_1.Node.isCallExpression(initializer) &&
173
+ initializer.getExpression().getText() === DEFINE_SCOPES_IMPORT_NAME) {
174
+ continue;
175
+ }
176
+ if (!ts_morph_1.Node.isArrayLiteralExpression(initializer))
177
+ continue;
178
+ scopesProp.setInitializer(`${DEFINE_SCOPES_IMPORT_NAME}(${initializer.getText()})`);
179
+ wrappedCount++;
180
+ }
181
+ return wrappedCount;
182
+ }
183
+ function wrapRolesWithDefineRoles(rolesFilePath, project) {
184
+ const sourceFile = project.getSourceFile(rolesFilePath);
185
+ if (!sourceFile)
186
+ return false;
187
+ const rolesDeclaration = sourceFile.getVariableDeclaration('roles');
188
+ if (!rolesDeclaration)
189
+ return false;
190
+ const initializer = rolesDeclaration.getInitializer();
191
+ if (!initializer)
192
+ return false;
193
+ if (ts_morph_1.Node.isCallExpression(initializer) &&
194
+ initializer.getExpression().getText() === DEFINE_ROLES_IMPORT_NAME) {
195
+ return false;
196
+ }
197
+ if (!ts_morph_1.Node.isArrayLiteralExpression(initializer))
198
+ return false;
199
+ const typeNode = rolesDeclaration.getTypeNode();
200
+ if (typeNode === null || typeNode === void 0 ? void 0 : typeNode.getText().includes('Role')) {
201
+ rolesDeclaration.removeType();
202
+ }
203
+ rolesDeclaration.setInitializer(`${DEFINE_ROLES_IMPORT_NAME}(${initializer.getText()})`);
204
+ return true;
205
+ }
206
+ function pruneNamedImportIfUnused(sourceFile, moduleSpecifier, importName) {
207
+ const importDeclaration = sourceFile.getImportDeclaration((decl) => decl.getModuleSpecifierValue() === moduleSpecifier);
208
+ if (!importDeclaration)
209
+ return false;
210
+ const namedImport = importDeclaration
211
+ .getNamedImports()
212
+ .find((ni) => ni.getName() === importName);
213
+ if (!namedImport)
214
+ return false;
215
+ const references = sourceFile
216
+ .getDescendantsOfKind(ts_morph_1.SyntaxKind.Identifier)
217
+ .filter((identifier) => identifier.getText() === importName &&
218
+ !ts_morph_1.Node.isImportSpecifier(identifier.getParent()));
219
+ if (references.length > 0) {
220
+ return false;
221
+ }
222
+ namedImport.remove();
223
+ if (importDeclaration.getNamedImports().length === 0 &&
224
+ !importDeclaration.getDefaultImport() &&
225
+ !importDeclaration.getNamespaceImport()) {
226
+ importDeclaration.remove();
227
+ }
228
+ return true;
229
+ }
230
+ function removeRoleTypeDefinitionAndUnusedImports(rolesFilePath, project) {
231
+ const sourceFile = project.getSourceFile(rolesFilePath);
232
+ if (!sourceFile)
233
+ return false;
234
+ let removed = false;
235
+ const roleTypeAlias = sourceFile.getTypeAlias('Role');
236
+ if (roleTypeAlias) {
237
+ roleTypeAlias.remove();
238
+ removed = true;
239
+ }
240
+ const roleInterface = sourceFile.getInterface('Role');
241
+ if (roleInterface) {
242
+ roleInterface.remove();
243
+ removed = true;
244
+ }
245
+ const removedScopeImport = pruneNamedImportIfUnused(sourceFile, TOOLKIT_SCOPES_MODULE, 'Scope');
246
+ const removedMessageDescriptorImport = pruneNamedImportIfUnused(sourceFile, 'react-intl', 'MessageDescriptor');
247
+ removed = removed || removedScopeImport || removedMessageDescriptorImport;
248
+ return removed;
249
+ }
250
+ function main() {
251
+ return __awaiter(this, void 0, void 0, function* () {
252
+ const cwd = (0, _1.getCwd)();
253
+ const srcDir = path_1.default.join(cwd, 'src');
254
+ const rolesFilePath = path_1.default.join(cwd, ROLES_FILE_RELATIVE_PATH);
255
+ console.log(`Scanning roles scopes in: ${rolesFilePath}`);
256
+ const project = new ts_morph_1.Project({
257
+ tsConfigFilePath: path_1.default.resolve(srcDir, '../tsconfig.json'),
258
+ skipAddingFilesFromTsConfig: false
259
+ });
260
+ const sourceFile = project.getSourceFile(rolesFilePath);
261
+ if (!sourceFile) {
262
+ console.log(`No roles file found at '${ROLES_FILE_RELATIVE_PATH}'. Nothing to do.`);
263
+ return;
264
+ }
265
+ const importChanged = ensureScopesHelpersImport(rolesFilePath, project);
266
+ const { migratedCount, removedCount } = migrateScopesArrays(rolesFilePath, project);
267
+ const wrappedScopesCount = wrapScopesArraysWithDefineScopes(rolesFilePath, project);
268
+ const wrappedRoles = wrapRolesWithDefineRoles(rolesFilePath, project);
269
+ const removedRoleType = removeRoleTypeDefinitionAndUnusedImports(rolesFilePath, project);
270
+ if (migratedCount === 0 &&
271
+ removedCount === 0 &&
272
+ wrappedScopesCount === 0 &&
273
+ !wrappedRoles &&
274
+ !removedRoleType &&
275
+ !importChanged) {
276
+ console.log('No migratable literal scopes found. Nothing to do.');
277
+ return;
278
+ }
279
+ yield sourceFile.save();
280
+ console.log(`Done. Migrated ${migratedCount} legacy scope(s), removed ${removedCount} unknown SCOPES reference(s), wrapped ${wrappedScopesCount} scope array(s) with defineScopes()${wrappedRoles ? ', wrapped roles with defineRoles()' : ''}${removedRoleType ? ', and removed Role type definition' : ''}${importChanged ? '. Updated toolkit/scopes imports.' : '.'}`);
281
+ });
282
+ }
@@ -0,0 +1,3 @@
1
+ declare function main(): Promise<void>;
2
+ export { main };
3
+ //# sourceMappingURL=migrate-validated-workqueue-status-to-flag.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrate-validated-workqueue-status-to-flag.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/migrate-validated-workqueue-status-to-flag.ts"],"names":[],"mappings":"AA2QA,iBAAe,IAAI,kBA+ClB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}