@opencrvs/toolkit 1.9.12-rc.f1e116d → 1.9.12-rc.f82cfcf

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 (112) 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 +135 -0
  6. package/dist/cli.d.ts +2 -0
  7. package/dist/cli.d.ts.map +1 -0
  8. package/dist/cli.js +2422 -0
  9. package/dist/commons/api/router.d.ts +3386 -2262
  10. package/dist/commons/application-config/index.d.ts +82 -0
  11. package/dist/commons/conditionals/conditionals.d.ts +27 -3
  12. package/dist/commons/conditionals/validate.d.ts +13 -2
  13. package/dist/commons/events/ActionConfig.d.ts +415 -1555
  14. package/dist/commons/events/ActionDocument.d.ts +889 -1942
  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 +73 -108
  25. package/dist/commons/events/DynamicFieldValue.d.ts +12 -78
  26. package/dist/commons/events/EventConfig.d.ts +35 -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 +2894 -12697
  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 +35 -34
  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 +191 -173
  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 +374 -443
  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 +2853 -2110
  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/convert-config-files-to-ts.d.ts +2 -0
  68. package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts.map +1 -0
  69. package/dist/migrations/v2.0/convert-config-files-to-ts.js +753 -0
  70. package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts +3 -0
  71. package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts.map +1 -0
  72. package/dist/migrations/v2.0/convert-paragraph-to-heading.js +159 -0
  73. package/dist/migrations/v2.0/index.d.ts +7 -0
  74. package/dist/migrations/v2.0/index.d.ts.map +1 -0
  75. package/dist/migrations/v2.0/index.js +2361 -0
  76. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts +3 -0
  77. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts.map +1 -0
  78. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.js +344 -0
  79. package/dist/migrations/v2.0/migrate-scopes.d.ts +3 -0
  80. package/dist/migrations/v2.0/migrate-scopes.d.ts.map +1 -0
  81. package/dist/migrations/v2.0/migrate-scopes.js +281 -0
  82. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts +3 -0
  83. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts.map +1 -0
  84. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.js +268 -0
  85. package/dist/migrations/v2.0/remove-delete-actions.d.ts +3 -0
  86. package/dist/migrations/v2.0/remove-delete-actions.d.ts.map +1 -0
  87. package/dist/migrations/v2.0/remove-delete-actions.js +157 -0
  88. package/dist/migrations/v2.0/remove-deprecated-imports.d.ts +3 -0
  89. package/dist/migrations/v2.0/remove-deprecated-imports.d.ts.map +1 -0
  90. package/dist/migrations/v2.0/remove-deprecated-imports.js +97 -0
  91. package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts +3 -0
  92. package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts.map +1 -0
  93. package/dist/migrations/v2.0/remove-pending-certification-flag.js +110 -0
  94. package/dist/migrations/v2.0/remove-review-from-register-action.d.ts +3 -0
  95. package/dist/migrations/v2.0/remove-review-from-register-action.d.ts.map +1 -0
  96. package/dist/migrations/v2.0/remove-review-from-register-action.js +164 -0
  97. package/dist/migrations/v2.0/rename-api-paths.d.ts +3 -0
  98. package/dist/migrations/v2.0/rename-api-paths.d.ts.map +1 -0
  99. package/dist/migrations/v2.0/rename-api-paths.js +188 -0
  100. package/dist/migrations/v2.0/rename-location-parent-id.d.ts +3 -0
  101. package/dist/migrations/v2.0/rename-location-parent-id.d.ts.map +1 -0
  102. package/dist/migrations/v2.0/rename-location-parent-id.js +181 -0
  103. package/dist/notification/index.d.ts.map +1 -1
  104. package/dist/notification/index.js +2088 -1773
  105. package/dist/scopes/index.d.ts +640 -353
  106. package/dist/scopes/index.d.ts.map +1 -1
  107. package/dist/scopes/index.js +340 -300
  108. package/opencrvs-toolkit-1.9.12-rc.f82cfcf.tgz +0 -0
  109. package/package.json +18 -8
  110. package/tsconfig.json +9 -2
  111. package/tsconfig.tsbuildinfo +1 -1
  112. package/dist/commons/events/CreatedAtLocation.d.ts +0 -2
@@ -0,0 +1,2361 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+
31
+ // src/migrations/v2.0/index.ts
32
+ var v2_exports = {};
33
+ __export(v2_exports, {
34
+ getCwd: () => getCwd,
35
+ runUpgrade: () => runUpgrade
36
+ });
37
+ module.exports = __toCommonJS(v2_exports);
38
+
39
+ // src/migrations/v2.0/remove-review-from-register-action.ts
40
+ var import_ts_morph = require("ts-morph");
41
+ var import_path = __toESM(require("path"));
42
+ var DEFINE_CONFIG_NAME = "defineConfig";
43
+ var ACTIONS_PROPERTY_NAME = "actions";
44
+ var TYPE_PROPERTY_NAME = "type";
45
+ var REVIEW_PROPERTY_NAME = "review";
46
+ var REGISTER_ENUM_NAME = "ActionType";
47
+ var REGISTER_MEMBER_NAME = "REGISTER";
48
+ var REGISTER_STRING_LITERAL = "REGISTER";
49
+ function isRegisterType(typeInitializer) {
50
+ if (typeInitializer.getKind() === import_ts_morph.SyntaxKind.PropertyAccessExpression) {
51
+ const propAccess = typeInitializer.asKindOrThrow(
52
+ import_ts_morph.SyntaxKind.PropertyAccessExpression
53
+ );
54
+ const obj = propAccess.getExpression();
55
+ const member = propAccess.getName();
56
+ return import_ts_morph.Node.isIdentifier(obj) && obj.getText() === REGISTER_ENUM_NAME && member === REGISTER_MEMBER_NAME;
57
+ }
58
+ if (typeInitializer.getKind() === import_ts_morph.SyntaxKind.StringLiteral) {
59
+ return typeInitializer.asKindOrThrow(import_ts_morph.SyntaxKind.StringLiteral).getLiteralValue() === REGISTER_STRING_LITERAL;
60
+ }
61
+ return false;
62
+ }
63
+ function removeReviewFromRegisterActions(obj) {
64
+ const typeProperty = obj.getProperty(TYPE_PROPERTY_NAME);
65
+ if (!typeProperty || !import_ts_morph.Node.isPropertyAssignment(typeProperty)) {
66
+ return false;
67
+ }
68
+ const typeInitializer = typeProperty.getInitializer();
69
+ if (!typeInitializer || !isRegisterType(typeInitializer)) {
70
+ return false;
71
+ }
72
+ const reviewProperty = obj.getProperty(REVIEW_PROPERTY_NAME);
73
+ if (!reviewProperty) {
74
+ return false;
75
+ }
76
+ reviewProperty.remove();
77
+ return true;
78
+ }
79
+ function processFile(filePath, project) {
80
+ const sourceFile = project.getSourceFile(filePath);
81
+ if (!sourceFile) return 0;
82
+ let removedCount = 0;
83
+ const callExpressions = sourceFile.getDescendantsOfKind(
84
+ import_ts_morph.SyntaxKind.CallExpression
85
+ );
86
+ for (const call of callExpressions) {
87
+ const expression = call.getExpression();
88
+ if (!import_ts_morph.Node.isIdentifier(expression) || expression.getText() !== DEFINE_CONFIG_NAME) {
89
+ continue;
90
+ }
91
+ const args = call.getArguments();
92
+ if (args.length === 0) continue;
93
+ const configArg = args[0];
94
+ if (!import_ts_morph.Node.isObjectLiteralExpression(configArg)) continue;
95
+ const actionsProperty = configArg.getProperty(ACTIONS_PROPERTY_NAME);
96
+ if (!actionsProperty || !import_ts_morph.Node.isPropertyAssignment(actionsProperty))
97
+ continue;
98
+ const actionsInitializer = actionsProperty.getInitializer();
99
+ if (!actionsInitializer || !import_ts_morph.Node.isArrayLiteralExpression(actionsInitializer))
100
+ continue;
101
+ for (const element of actionsInitializer.getElements()) {
102
+ if (!import_ts_morph.Node.isObjectLiteralExpression(element)) continue;
103
+ const wasRemoved = removeReviewFromRegisterActions(element);
104
+ if (wasRemoved) {
105
+ removedCount++;
106
+ console.log(
107
+ ` [${import_path.default.relative(getCwd(), filePath)}] Removed 'review' from REGISTER action`
108
+ );
109
+ }
110
+ }
111
+ }
112
+ return removedCount;
113
+ }
114
+ async function main() {
115
+ const srcDir = import_path.default.join(getCwd(), "src");
116
+ console.log(`Scanning for defineConfig calls in: ${srcDir}
117
+ `);
118
+ const project = new import_ts_morph.Project({
119
+ tsConfigFilePath: import_path.default.resolve(srcDir, "../tsconfig.json"),
120
+ // Do not emit — we only manipulate source files
121
+ skipAddingFilesFromTsConfig: false
122
+ // addFilesFromTsConfig: true
123
+ });
124
+ const sourceFiles = project.getSourceFiles().filter((sf) => {
125
+ const fp = sf.getFilePath();
126
+ return fp.includes("/src/") && !fp.includes("/node_modules/");
127
+ });
128
+ console.log(`Found ${sourceFiles.length} source file(s) to analyse.
129
+ `);
130
+ let totalRemoved = 0;
131
+ const modifiedFiles = [];
132
+ for (const sourceFile of sourceFiles) {
133
+ const filePath = sourceFile.getFilePath();
134
+ const removed = processFile(filePath, project);
135
+ if (removed > 0) {
136
+ totalRemoved += removed;
137
+ modifiedFiles.push(filePath);
138
+ }
139
+ }
140
+ if (modifiedFiles.length === 0) {
141
+ console.log(
142
+ "No 'review' properties found on REGISTER actions. Nothing to do."
143
+ );
144
+ return;
145
+ }
146
+ console.log(`
147
+ Saving ${modifiedFiles.length} modified file(s)...`);
148
+ for (const filePath of modifiedFiles) {
149
+ const sourceFile = project.getSourceFileOrThrow(filePath);
150
+ await sourceFile.save();
151
+ console.log(` Saved: ${import_path.default.relative(getCwd(), filePath)}`);
152
+ }
153
+ console.log(
154
+ `
155
+ Done. Removed ${totalRemoved} 'review' property assignment(s) from REGISTER action(s).`
156
+ );
157
+ }
158
+
159
+ // src/migrations/v2.0/make-built-in-validate-actions-custom.ts
160
+ var import_ts_morph2 = require("ts-morph");
161
+ var import_path2 = __toESM(require("path"));
162
+ var TOOLKIT_EVENTS_MODULE = "@opencrvs/toolkit/events";
163
+ var REQUIRED_SYMBOLS = [
164
+ "ConditionalType",
165
+ "and",
166
+ "status",
167
+ "not",
168
+ "flag",
169
+ "InherentFlags"
170
+ ];
171
+ function ensureImports(sourceFile) {
172
+ const existingImport = sourceFile.getImportDeclaration(
173
+ (decl) => decl.getModuleSpecifierValue() === TOOLKIT_EVENTS_MODULE
174
+ );
175
+ if (existingImport) {
176
+ const existingNames = new Set(
177
+ existingImport.getNamedImports().map((ni) => ni.getName())
178
+ );
179
+ for (const name of REQUIRED_SYMBOLS) {
180
+ if (!existingNames.has(name)) {
181
+ existingImport.addNamedImport(name);
182
+ }
183
+ }
184
+ } else {
185
+ sourceFile.addImportDeclaration({
186
+ moduleSpecifier: TOOLKIT_EVENTS_MODULE,
187
+ namedImports: REQUIRED_SYMBOLS
188
+ });
189
+ }
190
+ }
191
+ var DEFINE_CONFIG_NAME2 = "defineConfig";
192
+ var ACTIONS_PROPERTY_NAME2 = "actions";
193
+ var TYPE_PROPERTY_NAME2 = "type";
194
+ var CUSTOM_ACTION_TYPE_PROPERTY_NAME = "customActionType";
195
+ var AUDIT_HISTORY_LABEL_PROPERTY_NAME = "auditHistoryLabel";
196
+ var DEDUPLICATION_PROPERTY_NAME = "deduplication";
197
+ var REVIEW_PROPERTY_NAME2 = "review";
198
+ var FIELDS_PROPERTY_NAME = "fields";
199
+ var FORM_PROPERTY_NAME = "form";
200
+ var ACTION_TYPE_ENUM_NAME = "ActionType";
201
+ var VALIDATE_MEMBER_NAME = "VALIDATE";
202
+ var CUSTOM_MEMBER_NAME = "CUSTOM";
203
+ var VALIDATE_STRING_LITERAL = "VALIDATE";
204
+ var CUSTOM_STRING_LITERAL = "CUSTOM";
205
+ var VALIDATE_DECLARATION_VALUE = "VALIDATE_DECLARATION";
206
+ function isValidateType(typeInitializer) {
207
+ if (typeInitializer.getKind() === import_ts_morph2.SyntaxKind.PropertyAccessExpression) {
208
+ const propAccess = typeInitializer.asKindOrThrow(
209
+ import_ts_morph2.SyntaxKind.PropertyAccessExpression
210
+ );
211
+ const obj = propAccess.getExpression();
212
+ const member = propAccess.getName();
213
+ return import_ts_morph2.Node.isIdentifier(obj) && obj.getText() === ACTION_TYPE_ENUM_NAME && member === VALIDATE_MEMBER_NAME;
214
+ }
215
+ if (typeInitializer.getKind() === import_ts_morph2.SyntaxKind.StringLiteral) {
216
+ return typeInitializer.asKindOrThrow(import_ts_morph2.SyntaxKind.StringLiteral).getLiteralValue() === VALIDATE_STRING_LITERAL;
217
+ }
218
+ return false;
219
+ }
220
+ function resolveEventType(configArg) {
221
+ const typeProperty = configArg.getProperty(TYPE_PROPERTY_NAME2);
222
+ if (!typeProperty || !import_ts_morph2.Node.isPropertyAssignment(typeProperty)) return null;
223
+ const initializer = typeProperty.getInitializer();
224
+ if (!initializer) return null;
225
+ if (import_ts_morph2.Node.isStringLiteral(initializer)) {
226
+ return initializer.getLiteralValue().toLowerCase();
227
+ }
228
+ if (initializer.getKind() === import_ts_morph2.SyntaxKind.PropertyAccessExpression && import_ts_morph2.Node.isPropertyAccessExpression(initializer)) {
229
+ return initializer.getName().toLowerCase();
230
+ }
231
+ return null;
232
+ }
233
+ function transformValidateActionToCustom(obj, eventType) {
234
+ const typeProperty = obj.getProperty(TYPE_PROPERTY_NAME2);
235
+ if (!typeProperty || !import_ts_morph2.Node.isPropertyAssignment(typeProperty)) {
236
+ return false;
237
+ }
238
+ const typeInitializer = typeProperty.getInitializer();
239
+ if (!typeInitializer || !isValidateType(typeInitializer)) {
240
+ return false;
241
+ }
242
+ if (typeInitializer.getKind() === import_ts_morph2.SyntaxKind.PropertyAccessExpression) {
243
+ typeInitializer.replaceWithText(
244
+ `${ACTION_TYPE_ENUM_NAME}.${CUSTOM_MEMBER_NAME}`
245
+ );
246
+ } else {
247
+ typeInitializer.replaceWithText(`'${CUSTOM_STRING_LITERAL}'`);
248
+ }
249
+ if (!obj.getProperty(CUSTOM_ACTION_TYPE_PROPERTY_NAME)) {
250
+ obj.addPropertyAssignment({
251
+ name: CUSTOM_ACTION_TYPE_PROPERTY_NAME,
252
+ initializer: `'${VALIDATE_DECLARATION_VALUE}'`
253
+ });
254
+ }
255
+ if (!obj.getProperty(AUDIT_HISTORY_LABEL_PROPERTY_NAME)) {
256
+ const messageId = `event.${eventType}.custom.action.validate-declaration.audit-history-label`;
257
+ obj.addPropertyAssignment({
258
+ name: AUDIT_HISTORY_LABEL_PROPERTY_NAME,
259
+ initializer: `{
260
+ defaultMessage: 'Validated',
261
+ description: 'The label to show in audit history for the validate action',
262
+ id: '${messageId}'
263
+ }`
264
+ });
265
+ }
266
+ if (!obj.getProperty("supportingCopy")) {
267
+ const supportingCopyId = `event.${eventType}.custom.action.validate-declaration.supportingCopy`;
268
+ obj.addPropertyAssignment({
269
+ name: "supportingCopy",
270
+ initializer: `{
271
+ defaultMessage:
272
+ 'Approving this declaration confirms it as legally accepted and eligible for registration.',
273
+ description:
274
+ 'This is the supporting copy for the Validate declaration -action',
275
+ id: '${supportingCopyId}'
276
+ }`
277
+ });
278
+ }
279
+ if (!obj.getProperty("conditionals")) {
280
+ obj.addPropertyAssignment({
281
+ name: "conditionals",
282
+ initializer: `[
283
+ {
284
+ type: ConditionalType.SHOW,
285
+ conditional: and(status('DECLARED'), not(flag('validated')))
286
+ },
287
+ {
288
+ type: ConditionalType.ENABLE,
289
+ conditional: not(flag(InherentFlags.POTENTIAL_DUPLICATE))
290
+ }
291
+ ]`
292
+ });
293
+ }
294
+ if (!obj.getProperty("flags")) {
295
+ obj.addPropertyAssignment({
296
+ name: "flags",
297
+ initializer: `[{ id: 'validated', operation: 'add' }]`
298
+ });
299
+ }
300
+ const deduplicationProperty = obj.getProperty(DEDUPLICATION_PROPERTY_NAME);
301
+ if (deduplicationProperty) {
302
+ deduplicationProperty.remove();
303
+ }
304
+ const reviewProperty = obj.getProperty(REVIEW_PROPERTY_NAME2);
305
+ if (reviewProperty && import_ts_morph2.Node.isPropertyAssignment(reviewProperty)) {
306
+ const reviewInitializer = reviewProperty.getInitializer();
307
+ if (reviewInitializer) {
308
+ if (import_ts_morph2.Node.isObjectLiteralExpression(reviewInitializer)) {
309
+ const fieldsProperty = reviewInitializer.getProperty(FIELDS_PROPERTY_NAME);
310
+ if (fieldsProperty && import_ts_morph2.Node.isPropertyAssignment(fieldsProperty)) {
311
+ const fieldsInitializer = fieldsProperty.getInitializer();
312
+ if (fieldsInitializer) {
313
+ reviewProperty.set({
314
+ name: FORM_PROPERTY_NAME,
315
+ initializer: fieldsInitializer.getText()
316
+ });
317
+ }
318
+ }
319
+ } else {
320
+ reviewProperty.set({
321
+ name: FORM_PROPERTY_NAME,
322
+ initializer: `${reviewInitializer.getText()}.fields`
323
+ });
324
+ }
325
+ }
326
+ }
327
+ return true;
328
+ }
329
+ function processFile2(filePath, project) {
330
+ const sourceFile = project.getSourceFile(filePath);
331
+ if (!sourceFile) return 0;
332
+ let transformedCount = 0;
333
+ const callExpressions = sourceFile.getDescendantsOfKind(
334
+ import_ts_morph2.SyntaxKind.CallExpression
335
+ );
336
+ for (const call of callExpressions) {
337
+ const expression = call.getExpression();
338
+ if (!import_ts_morph2.Node.isIdentifier(expression) || expression.getText() !== DEFINE_CONFIG_NAME2) {
339
+ continue;
340
+ }
341
+ const args = call.getArguments();
342
+ if (args.length === 0) continue;
343
+ const configArg = args[0];
344
+ if (!import_ts_morph2.Node.isObjectLiteralExpression(configArg)) continue;
345
+ const actionsProperty = configArg.getProperty(ACTIONS_PROPERTY_NAME2);
346
+ if (!actionsProperty || !import_ts_morph2.Node.isPropertyAssignment(actionsProperty))
347
+ continue;
348
+ const actionsInitializer = actionsProperty.getInitializer();
349
+ if (!actionsInitializer || !import_ts_morph2.Node.isArrayLiteralExpression(actionsInitializer))
350
+ continue;
351
+ const eventType = resolveEventType(configArg);
352
+ if (!eventType) {
353
+ console.warn(
354
+ ` [${import_path2.default.relative(getCwd(), configArg.getSourceFile().getFilePath())}] Could not resolve root 'type' from defineConfig \u2014 skipping auditHistoryLabel id generation`
355
+ );
356
+ }
357
+ let fileNeedsImports = false;
358
+ let configHadValidateAction = false;
359
+ for (const element of actionsInitializer.getElements()) {
360
+ if (!import_ts_morph2.Node.isObjectLiteralExpression(element)) continue;
361
+ const wasTransformed = transformValidateActionToCustom(
362
+ element,
363
+ eventType ?? "unknown"
364
+ );
365
+ if (wasTransformed) {
366
+ transformedCount++;
367
+ fileNeedsImports = true;
368
+ configHadValidateAction = true;
369
+ console.log(
370
+ ` [${import_path2.default.relative(getCwd(), filePath)}] Transformed VALIDATE action to CUSTOM with customActionType: '${VALIDATE_DECLARATION_VALUE}'`
371
+ );
372
+ }
373
+ }
374
+ if (configHadValidateAction && !configArg.getProperty("flags")) {
375
+ const resolvedEventType = eventType ?? "unknown";
376
+ configArg.addPropertyAssignment({
377
+ name: "flags",
378
+ initializer: `[
379
+ {
380
+ id: 'validated',
381
+ label: {
382
+ id: 'event.${resolvedEventType}.flag.validated',
383
+ defaultMessage: 'Validated',
384
+ description: 'Flag label for validated'
385
+ },
386
+ requiresAction: true
387
+ }
388
+ ]`
389
+ });
390
+ console.log(
391
+ ` [${import_path2.default.relative(getCwd(), filePath)}] Added top-level 'flags' array to defineConfig`
392
+ );
393
+ }
394
+ if (fileNeedsImports) {
395
+ ensureImports(sourceFile);
396
+ }
397
+ }
398
+ return transformedCount;
399
+ }
400
+ async function main2() {
401
+ const srcDir = import_path2.default.join(getCwd(), "src");
402
+ console.log(`Scanning for defineConfig calls in: ${srcDir}
403
+ `);
404
+ const project = new import_ts_morph2.Project({
405
+ tsConfigFilePath: import_path2.default.resolve(srcDir, "../tsconfig.json"),
406
+ // Do not emit — we only manipulate source files
407
+ skipAddingFilesFromTsConfig: false
408
+ });
409
+ const sourceFiles = project.getSourceFiles().filter((sf) => {
410
+ const fp = sf.getFilePath();
411
+ return fp.includes("/src/") && !fp.includes("/node_modules/");
412
+ });
413
+ console.log(`Found ${sourceFiles.length} source file(s) to analyse.
414
+ `);
415
+ let totalTransformed = 0;
416
+ const modifiedFiles = [];
417
+ for (const sourceFile of sourceFiles) {
418
+ const filePath = sourceFile.getFilePath();
419
+ const transformed = processFile2(filePath, project);
420
+ if (transformed > 0) {
421
+ totalTransformed += transformed;
422
+ modifiedFiles.push(filePath);
423
+ }
424
+ }
425
+ if (modifiedFiles.length === 0) {
426
+ console.log(
427
+ "No VALIDATE actions found inside defineConfig calls. Nothing to do."
428
+ );
429
+ return;
430
+ }
431
+ console.log(`
432
+ Saving ${modifiedFiles.length} modified file(s)...`);
433
+ for (const filePath of modifiedFiles) {
434
+ const sourceFile = project.getSourceFileOrThrow(filePath);
435
+ await sourceFile.save();
436
+ console.log(` Saved: ${import_path2.default.relative(getCwd(), filePath)}`);
437
+ }
438
+ console.log(
439
+ `
440
+ Done. Transformed ${totalTransformed} VALIDATE action(s) to CUSTOM with customActionType: '${VALIDATE_DECLARATION_VALUE}'.`
441
+ );
442
+ }
443
+
444
+ // src/migrations/v2.0/remove-delete-actions.ts
445
+ var import_ts_morph3 = require("ts-morph");
446
+ var import_path3 = __toESM(require("path"));
447
+ var DEFINE_CONFIG_NAME3 = "defineConfig";
448
+ var ACTIONS_PROPERTY_NAME3 = "actions";
449
+ var TYPE_PROPERTY_NAME3 = "type";
450
+ var ACTION_TYPE_ENUM_NAME2 = "ActionType";
451
+ var DELETE_MEMBER_NAME = "DELETE";
452
+ var DELETE_STRING_LITERAL = "DELETE";
453
+ function isDeleteType(typeInitializer) {
454
+ if (typeInitializer.getKind() === import_ts_morph3.SyntaxKind.PropertyAccessExpression) {
455
+ const propAccess = typeInitializer.asKindOrThrow(
456
+ import_ts_morph3.SyntaxKind.PropertyAccessExpression
457
+ );
458
+ const obj = propAccess.getExpression();
459
+ const member = propAccess.getName();
460
+ return import_ts_morph3.Node.isIdentifier(obj) && obj.getText() === ACTION_TYPE_ENUM_NAME2 && member === DELETE_MEMBER_NAME;
461
+ }
462
+ if (typeInitializer.getKind() === import_ts_morph3.SyntaxKind.StringLiteral) {
463
+ return typeInitializer.asKindOrThrow(import_ts_morph3.SyntaxKind.StringLiteral).getLiteralValue() === DELETE_STRING_LITERAL;
464
+ }
465
+ return false;
466
+ }
467
+ function isDeleteAction(obj) {
468
+ const typeProperty = obj.getProperty(TYPE_PROPERTY_NAME3);
469
+ if (!typeProperty || !import_ts_morph3.Node.isPropertyAssignment(typeProperty)) {
470
+ return false;
471
+ }
472
+ const typeInitializer = typeProperty.getInitializer();
473
+ return !!typeInitializer && isDeleteType(typeInitializer);
474
+ }
475
+ function processFile3(filePath, project) {
476
+ const sourceFile = project.getSourceFile(filePath);
477
+ if (!sourceFile) return 0;
478
+ let removedCount = 0;
479
+ const callExpressions = sourceFile.getDescendantsOfKind(
480
+ import_ts_morph3.SyntaxKind.CallExpression
481
+ );
482
+ for (const call of callExpressions) {
483
+ const expression = call.getExpression();
484
+ if (!import_ts_morph3.Node.isIdentifier(expression) || expression.getText() !== DEFINE_CONFIG_NAME3) {
485
+ continue;
486
+ }
487
+ const args = call.getArguments();
488
+ if (args.length === 0) continue;
489
+ const configArg = args[0];
490
+ if (!import_ts_morph3.Node.isObjectLiteralExpression(configArg)) continue;
491
+ const actionsProperty = configArg.getProperty(ACTIONS_PROPERTY_NAME3);
492
+ if (!actionsProperty || !import_ts_morph3.Node.isPropertyAssignment(actionsProperty))
493
+ continue;
494
+ const actionsInitializer = actionsProperty.getInitializer();
495
+ if (!actionsInitializer || !import_ts_morph3.Node.isArrayLiteralExpression(actionsInitializer))
496
+ continue;
497
+ const indicesToRemove = [];
498
+ actionsInitializer.getElements().forEach((element, index) => {
499
+ if (import_ts_morph3.Node.isObjectLiteralExpression(element) && isDeleteAction(element)) {
500
+ indicesToRemove.push(index);
501
+ }
502
+ });
503
+ for (const index of indicesToRemove.reverse()) {
504
+ actionsInitializer.removeElement(index);
505
+ removedCount++;
506
+ console.log(
507
+ ` [${import_path3.default.relative(getCwd(), filePath)}] Removed DELETE action at index ${index}`
508
+ );
509
+ }
510
+ }
511
+ return removedCount;
512
+ }
513
+ async function main3() {
514
+ const srcDir = import_path3.default.join(getCwd(), "src");
515
+ console.log(`Scanning for defineConfig calls in: ${srcDir}
516
+ `);
517
+ const project = new import_ts_morph3.Project({
518
+ tsConfigFilePath: import_path3.default.resolve(srcDir, "../tsconfig.json"),
519
+ // Do not emit — we only manipulate source files
520
+ skipAddingFilesFromTsConfig: false
521
+ });
522
+ const sourceFiles = project.getSourceFiles().filter((sf) => {
523
+ const fp = sf.getFilePath();
524
+ return fp.includes("/src/") && !fp.includes("/node_modules/");
525
+ });
526
+ console.log(`Found ${sourceFiles.length} source file(s) to analyse.
527
+ `);
528
+ let totalRemoved = 0;
529
+ const modifiedFiles = [];
530
+ for (const sourceFile of sourceFiles) {
531
+ const filePath = sourceFile.getFilePath();
532
+ const removed = processFile3(filePath, project);
533
+ if (removed > 0) {
534
+ totalRemoved += removed;
535
+ modifiedFiles.push(filePath);
536
+ }
537
+ }
538
+ if (modifiedFiles.length === 0) {
539
+ console.log(
540
+ "No DELETE actions found inside defineConfig calls. Nothing to do."
541
+ );
542
+ return;
543
+ }
544
+ console.log(`
545
+ Saving ${modifiedFiles.length} modified file(s)...`);
546
+ for (const filePath of modifiedFiles) {
547
+ const sourceFile = project.getSourceFileOrThrow(filePath);
548
+ await sourceFile.save();
549
+ console.log(` Saved: ${import_path3.default.relative(getCwd(), filePath)}`);
550
+ }
551
+ console.log(
552
+ `
553
+ Done. Removed ${totalRemoved} DELETE action(s) from defineConfig call(s).`
554
+ );
555
+ }
556
+
557
+ // src/migrations/v2.0/convert-paragraph-to-heading.ts
558
+ var import_ts_morph4 = require("ts-morph");
559
+ var import_path4 = __toESM(require("path"));
560
+ var FIELD_TYPE_ENUM_NAME = "FieldType";
561
+ var PARAGRAPH_MEMBER_NAME = "PARAGRAPH";
562
+ var HEADING_MEMBER_NAME = "HEADING";
563
+ var TYPE_PROPERTY_NAME4 = "type";
564
+ var CONFIGURATION_PROPERTY_NAME = "configuration";
565
+ var STYLES_PROPERTY_NAME = "styles";
566
+ var FONT_VARIANT_PROPERTY_NAME = "fontVariant";
567
+ var HEADING_FONT_VARIANTS = /* @__PURE__ */ new Set(["h1", "h2", "h3", "h4"]);
568
+ function isParagraphType(typeInitializer) {
569
+ if (!import_ts_morph4.Node.isPropertyAccessExpression(typeInitializer)) return false;
570
+ const obj = typeInitializer.getExpression();
571
+ const member = typeInitializer.getName();
572
+ return import_ts_morph4.Node.isIdentifier(obj) && obj.getText() === FIELD_TYPE_ENUM_NAME && member === PARAGRAPH_MEMBER_NAME;
573
+ }
574
+ function getFontVariantProperty(obj) {
575
+ const configProperty = obj.getProperty(CONFIGURATION_PROPERTY_NAME);
576
+ if (!configProperty || !import_ts_morph4.Node.isPropertyAssignment(configProperty)) return null;
577
+ const configInitializer = configProperty.getInitializer();
578
+ if (!configInitializer || !import_ts_morph4.Node.isObjectLiteralExpression(configInitializer))
579
+ return null;
580
+ const stylesProperty = configInitializer.getProperty(STYLES_PROPERTY_NAME);
581
+ if (!stylesProperty || !import_ts_morph4.Node.isPropertyAssignment(stylesProperty)) return null;
582
+ const stylesInitializer = stylesProperty.getInitializer();
583
+ if (!stylesInitializer || !import_ts_morph4.Node.isObjectLiteralExpression(stylesInitializer))
584
+ return null;
585
+ const fontVariantProperty = stylesInitializer.getProperty(
586
+ FONT_VARIANT_PROPERTY_NAME
587
+ );
588
+ if (!fontVariantProperty || !import_ts_morph4.Node.isPropertyAssignment(fontVariantProperty))
589
+ return null;
590
+ return fontVariantProperty;
591
+ }
592
+ function transformParagraphField(obj) {
593
+ const typeProperty = obj.getProperty(TYPE_PROPERTY_NAME4);
594
+ if (!typeProperty || !import_ts_morph4.Node.isPropertyAssignment(typeProperty)) return null;
595
+ const typeInitializer = typeProperty.getInitializer();
596
+ if (!typeInitializer || !isParagraphType(typeInitializer)) return null;
597
+ const fontVariantProperty = getFontVariantProperty(obj);
598
+ if (fontVariantProperty) {
599
+ const fontVariantInitializer = fontVariantProperty.getInitializer();
600
+ if (fontVariantInitializer && import_ts_morph4.Node.isStringLiteral(fontVariantInitializer) && HEADING_FONT_VARIANTS.has(fontVariantInitializer.getLiteralValue())) {
601
+ typeInitializer.replaceWithText(
602
+ `${FIELD_TYPE_ENUM_NAME}.${HEADING_MEMBER_NAME}`
603
+ );
604
+ return "converted-to-heading";
605
+ }
606
+ fontVariantProperty.remove();
607
+ return "removed-font-variant";
608
+ }
609
+ return null;
610
+ }
611
+ function processFile4(filePath, project) {
612
+ const sourceFile = project.getSourceFile(filePath);
613
+ if (!sourceFile) return 0;
614
+ let changedCount = 0;
615
+ const objectLiterals = sourceFile.getDescendantsOfKind(
616
+ import_ts_morph4.SyntaxKind.ObjectLiteralExpression
617
+ );
618
+ for (const obj of objectLiterals) {
619
+ const result = transformParagraphField(obj);
620
+ if (result === "converted-to-heading") {
621
+ changedCount++;
622
+ console.log(
623
+ ` [${import_path4.default.relative(getCwd(), filePath)}] Converted PARAGRAPH with heading fontVariant to HEADING`
624
+ );
625
+ } else if (result === "removed-font-variant") {
626
+ changedCount++;
627
+ console.log(
628
+ ` [${import_path4.default.relative(getCwd(), filePath)}] Removed non-heading fontVariant from PARAGRAPH`
629
+ );
630
+ }
631
+ }
632
+ return changedCount;
633
+ }
634
+ async function main4() {
635
+ const srcDir = import_path4.default.join(getCwd(), "src");
636
+ console.log(`Scanning for FieldType.PARAGRAPH fields in: ${srcDir}
637
+ `);
638
+ const project = new import_ts_morph4.Project({
639
+ tsConfigFilePath: import_path4.default.resolve(srcDir, "../tsconfig.json"),
640
+ skipAddingFilesFromTsConfig: false
641
+ });
642
+ const sourceFiles = project.getSourceFiles().filter((sf) => {
643
+ const fp = sf.getFilePath();
644
+ return fp.includes("/src/") && !fp.includes("/node_modules/");
645
+ });
646
+ console.log(`Found ${sourceFiles.length} source file(s) to analyse.
647
+ `);
648
+ let totalChanged = 0;
649
+ const modifiedFiles = [];
650
+ for (const sourceFile of sourceFiles) {
651
+ const filePath = sourceFile.getFilePath();
652
+ const changed = processFile4(filePath, project);
653
+ if (changed > 0) {
654
+ totalChanged += changed;
655
+ modifiedFiles.push(filePath);
656
+ }
657
+ }
658
+ if (modifiedFiles.length === 0) {
659
+ console.log(
660
+ "No FieldType.PARAGRAPH fields with fontVariant found. Nothing to do."
661
+ );
662
+ return;
663
+ }
664
+ console.log(`
665
+ Saving ${modifiedFiles.length} modified file(s)...`);
666
+ for (const filePath of modifiedFiles) {
667
+ const sourceFile = project.getSourceFileOrThrow(filePath);
668
+ await sourceFile.save();
669
+ console.log(` Saved: ${import_path4.default.relative(getCwd(), filePath)}`);
670
+ }
671
+ console.log(`
672
+ Done. Processed ${totalChanged} FieldType.PARAGRAPH field(s).`);
673
+ }
674
+
675
+ // src/migrations/v2.0/migrate-validated-workqueue-status-to-flag.ts
676
+ var import_ts_morph5 = require("ts-morph");
677
+ var import_path5 = __toESM(require("path"));
678
+ var DEFINE_WORKQUEUES_NAME = "defineWorkqueues";
679
+ var QUERY_PROPERTY_NAME = "query";
680
+ var TYPE_PROPERTY_NAME5 = "type";
681
+ var CLAUSES_PROPERTY_NAME = "clauses";
682
+ var STATUS_PROPERTY_NAME = "status";
683
+ var FLAGS_PROPERTY_NAME = "flags";
684
+ var TERMS_PROPERTY_NAME = "terms";
685
+ var TERM_PROPERTY_NAME = "term";
686
+ var ANY_OF_PROPERTY_NAME = "anyOf";
687
+ var VALIDATED_STATUS_VALUE = "VALIDATED";
688
+ var VALIDATED_FLAG_VALUE = "validated";
689
+ function addValidatedFlag(clause) {
690
+ const flagsProperty = clause.getProperty(FLAGS_PROPERTY_NAME);
691
+ if (flagsProperty && import_ts_morph5.Node.isPropertyAssignment(flagsProperty)) {
692
+ const flagsInit = flagsProperty.getInitializer();
693
+ if (flagsInit && import_ts_morph5.Node.isObjectLiteralExpression(flagsInit)) {
694
+ const anyOfProperty = flagsInit.getProperty(ANY_OF_PROPERTY_NAME);
695
+ if (anyOfProperty && import_ts_morph5.Node.isPropertyAssignment(anyOfProperty)) {
696
+ const anyOfInit = anyOfProperty.getInitializer();
697
+ if (anyOfInit && import_ts_morph5.Node.isArrayLiteralExpression(anyOfInit)) {
698
+ anyOfInit.addElement(`'${VALIDATED_FLAG_VALUE}'`);
699
+ }
700
+ } else {
701
+ flagsInit.addPropertyAssignment({
702
+ name: ANY_OF_PROPERTY_NAME,
703
+ initializer: `['${VALIDATED_FLAG_VALUE}']`
704
+ });
705
+ }
706
+ }
707
+ } else {
708
+ clause.addPropertyAssignment({
709
+ name: FLAGS_PROPERTY_NAME,
710
+ initializer: `{ ${ANY_OF_PROPERTY_NAME}: ['${VALIDATED_FLAG_VALUE}'] }`
711
+ });
712
+ }
713
+ }
714
+ function migrateClause(clause) {
715
+ const statusProperty = clause.getProperty(STATUS_PROPERTY_NAME);
716
+ if (!statusProperty || !import_ts_morph5.Node.isPropertyAssignment(statusProperty)) {
717
+ return false;
718
+ }
719
+ const statusInit = statusProperty.getInitializer();
720
+ if (!statusInit || !import_ts_morph5.Node.isObjectLiteralExpression(statusInit)) {
721
+ return false;
722
+ }
723
+ const statusTypeProperty = statusInit.getProperty(TYPE_PROPERTY_NAME5);
724
+ if (!statusTypeProperty || !import_ts_morph5.Node.isPropertyAssignment(statusTypeProperty)) {
725
+ return false;
726
+ }
727
+ const statusTypeInit = statusTypeProperty.getInitializer();
728
+ if (!statusTypeInit || !import_ts_morph5.Node.isStringLiteral(statusTypeInit)) {
729
+ return false;
730
+ }
731
+ const statusType = statusTypeInit.getLiteralValue();
732
+ if (statusType === "anyOf") {
733
+ const termsProperty = statusInit.getProperty(TERMS_PROPERTY_NAME);
734
+ if (!termsProperty || !import_ts_morph5.Node.isPropertyAssignment(termsProperty)) {
735
+ return false;
736
+ }
737
+ const termsInit = termsProperty.getInitializer();
738
+ if (!termsInit || !import_ts_morph5.Node.isArrayLiteralExpression(termsInit)) {
739
+ return false;
740
+ }
741
+ const elements = termsInit.getElements();
742
+ const validatedIndex = elements.findIndex(
743
+ (el) => import_ts_morph5.Node.isStringLiteral(el) && el.getLiteralValue() === VALIDATED_STATUS_VALUE
744
+ );
745
+ if (validatedIndex === -1) return false;
746
+ termsInit.removeElement(validatedIndex);
747
+ if (termsInit.getElements().length === 0) {
748
+ statusProperty.remove();
749
+ }
750
+ addValidatedFlag(clause);
751
+ return true;
752
+ }
753
+ if (statusType === "exact") {
754
+ const termProperty = statusInit.getProperty(TERM_PROPERTY_NAME);
755
+ if (!termProperty || !import_ts_morph5.Node.isPropertyAssignment(termProperty)) {
756
+ return false;
757
+ }
758
+ const termInit = termProperty.getInitializer();
759
+ if (!termInit || !import_ts_morph5.Node.isStringLiteral(termInit)) {
760
+ return false;
761
+ }
762
+ if (termInit.getLiteralValue() !== VALIDATED_STATUS_VALUE) return false;
763
+ statusProperty.remove();
764
+ addValidatedFlag(clause);
765
+ return true;
766
+ }
767
+ return false;
768
+ }
769
+ function walkQuery(queryObj) {
770
+ const typeProperty = queryObj.getProperty(TYPE_PROPERTY_NAME5);
771
+ if (typeProperty && import_ts_morph5.Node.isPropertyAssignment(typeProperty)) {
772
+ const typeInit = typeProperty.getInitializer();
773
+ if (typeInit && import_ts_morph5.Node.isStringLiteral(typeInit) && (typeInit.getLiteralValue() === "or" || typeInit.getLiteralValue() === "and")) {
774
+ const clausesProperty = queryObj.getProperty(CLAUSES_PROPERTY_NAME);
775
+ if (!clausesProperty || !import_ts_morph5.Node.isPropertyAssignment(clausesProperty)) {
776
+ return 0;
777
+ }
778
+ const clausesInit = clausesProperty.getInitializer();
779
+ if (!clausesInit || !import_ts_morph5.Node.isArrayLiteralExpression(clausesInit)) {
780
+ return 0;
781
+ }
782
+ let changed = 0;
783
+ for (const clause of clausesInit.getElements()) {
784
+ if (import_ts_morph5.Node.isObjectLiteralExpression(clause)) {
785
+ changed += walkQuery(clause);
786
+ }
787
+ }
788
+ return changed;
789
+ }
790
+ }
791
+ return migrateClause(queryObj) ? 1 : 0;
792
+ }
793
+ function processFile5(filePath, project) {
794
+ const sourceFile = project.getSourceFile(filePath);
795
+ if (!sourceFile) return 0;
796
+ let migratedCount = 0;
797
+ const callExpressions = sourceFile.getDescendantsOfKind(
798
+ import_ts_morph5.SyntaxKind.CallExpression
799
+ );
800
+ for (const call of callExpressions) {
801
+ const expression = call.getExpression();
802
+ if (!import_ts_morph5.Node.isIdentifier(expression) || expression.getText() !== DEFINE_WORKQUEUES_NAME) {
803
+ continue;
804
+ }
805
+ const args = call.getArguments();
806
+ if (args.length === 0) continue;
807
+ const workqueuesArg = args[0];
808
+ if (!import_ts_morph5.Node.isArrayLiteralExpression(workqueuesArg)) continue;
809
+ for (const workqueueElement of workqueuesArg.getElements()) {
810
+ if (!import_ts_morph5.Node.isObjectLiteralExpression(workqueueElement)) continue;
811
+ const queryProperty = workqueueElement.getProperty(QUERY_PROPERTY_NAME);
812
+ if (!queryProperty || !import_ts_morph5.Node.isPropertyAssignment(queryProperty)) continue;
813
+ const queryInit = queryProperty.getInitializer();
814
+ if (!queryInit || !import_ts_morph5.Node.isObjectLiteralExpression(queryInit)) continue;
815
+ const changed = walkQuery(queryInit);
816
+ if (changed > 0) {
817
+ migratedCount += changed;
818
+ console.log(
819
+ ` [${import_path5.default.relative(getCwd(), filePath)}] Migrated ${changed} clause(s): VALIDATED status \u2192 flags.anyOf`
820
+ );
821
+ }
822
+ }
823
+ }
824
+ return migratedCount;
825
+ }
826
+ async function main5() {
827
+ const srcDir = import_path5.default.join(getCwd(), "src");
828
+ console.log(`Scanning for defineWorkqueues calls in: ${srcDir}
829
+ `);
830
+ const project = new import_ts_morph5.Project({
831
+ tsConfigFilePath: import_path5.default.resolve(srcDir, "../tsconfig.json"),
832
+ skipAddingFilesFromTsConfig: false
833
+ });
834
+ const sourceFiles = project.getSourceFiles().filter((sf) => {
835
+ const fp = sf.getFilePath();
836
+ return fp.includes("/src/") && !fp.includes("/node_modules/");
837
+ });
838
+ console.log(`Found ${sourceFiles.length} source file(s) to analyse.
839
+ `);
840
+ let totalMigrated = 0;
841
+ const modifiedFiles = [];
842
+ for (const sourceFile of sourceFiles) {
843
+ const filePath = sourceFile.getFilePath();
844
+ const migrated = processFile5(filePath, project);
845
+ if (migrated > 0) {
846
+ totalMigrated += migrated;
847
+ modifiedFiles.push(filePath);
848
+ }
849
+ }
850
+ if (modifiedFiles.length === 0) {
851
+ console.log(
852
+ "No VALIDATED status references found in defineWorkqueues calls. Nothing to do."
853
+ );
854
+ return;
855
+ }
856
+ console.log(`
857
+ Saving ${modifiedFiles.length} modified file(s)...`);
858
+ for (const filePath of modifiedFiles) {
859
+ const sourceFile = project.getSourceFileOrThrow(filePath);
860
+ await sourceFile.save();
861
+ console.log(` Saved: ${import_path5.default.relative(getCwd(), filePath)}`);
862
+ }
863
+ console.log(
864
+ `
865
+ Done. Migrated ${totalMigrated} clause(s) from VALIDATED status to flags.anyOf['validated'].`
866
+ );
867
+ }
868
+
869
+ // src/migrations/v2.0/add-birth-certificate-issuance-flag.ts
870
+ var import_ts_morph6 = require("ts-morph");
871
+ var import_path6 = __toESM(require("path"));
872
+ var DEFINE_CONFIG_NAME4 = "defineConfig";
873
+ var DEFINE_WORKQUEUES_NAME2 = "defineWorkqueues";
874
+ var ACTIONS_PROPERTY_NAME4 = "actions";
875
+ var ACTION_PROPERTY_NAME = "action";
876
+ var FLAGS_PROPERTY_NAME2 = "flags";
877
+ var QUERY_PROPERTY_NAME2 = "query";
878
+ var TYPE_PROPERTY_NAME6 = "type";
879
+ var CLAUSES_PROPERTY_NAME2 = "clauses";
880
+ var ANY_OF_PROPERTY_NAME2 = "anyOf";
881
+ var FLAG_ID = "pending-first-certificate-issuance";
882
+ var REGISTER_TYPE = "REGISTER";
883
+ var PRINT_CERTIFICATE_TYPE = "PRINT_CERTIFICATE";
884
+ var FLAG_DEFINITION_INITIALIZER = `{
885
+ id: '${FLAG_ID}',
886
+ label: {
887
+ id: 'event.birth.flag.${FLAG_ID}',
888
+ defaultMessage: 'Pending first certificate issuance',
889
+ description: 'Flag label for first certificate issuance'
890
+ },
891
+ requiresAction: true
892
+ }`;
893
+ function isActionOfType(obj, typeName) {
894
+ const typeProperty = obj.getProperty(TYPE_PROPERTY_NAME6);
895
+ if (!typeProperty || !import_ts_morph6.Node.isPropertyAssignment(typeProperty)) return false;
896
+ const typeInit = typeProperty.getInitializer();
897
+ if (!typeInit) return false;
898
+ if (import_ts_morph6.Node.isPropertyAccessExpression(typeInit)) {
899
+ return typeInit.getName() === typeName;
900
+ }
901
+ if (import_ts_morph6.Node.isStringLiteral(typeInit)) {
902
+ return typeInit.getLiteralValue() === typeName;
903
+ }
904
+ return false;
905
+ }
906
+ function isBirthConfig(configArg) {
907
+ const typeProperty = configArg.getProperty(TYPE_PROPERTY_NAME6);
908
+ if (!typeProperty || !import_ts_morph6.Node.isPropertyAssignment(typeProperty)) return false;
909
+ const initializer = typeProperty.getInitializer();
910
+ if (!initializer) return false;
911
+ if (import_ts_morph6.Node.isStringLiteral(initializer)) {
912
+ return initializer.getLiteralValue().toLowerCase() === "birth";
913
+ }
914
+ if (import_ts_morph6.Node.isPropertyAccessExpression(initializer)) {
915
+ return initializer.getName().toLowerCase() === "birth";
916
+ }
917
+ return false;
918
+ }
919
+ function hasElementWithId(array, id) {
920
+ for (const el of array.getElements()) {
921
+ if (!import_ts_morph6.Node.isObjectLiteralExpression(el)) continue;
922
+ const idProp = el.getProperty("id");
923
+ if (!idProp || !import_ts_morph6.Node.isPropertyAssignment(idProp)) continue;
924
+ const idInit = idProp.getInitializer();
925
+ if (idInit && import_ts_morph6.Node.isStringLiteral(idInit) && idInit.getLiteralValue() === id) {
926
+ return true;
927
+ }
928
+ }
929
+ return false;
930
+ }
931
+ function ensureTopLevelFlagDefinition(configArg) {
932
+ const flagsProp = configArg.getProperty(FLAGS_PROPERTY_NAME2);
933
+ if (flagsProp && import_ts_morph6.Node.isPropertyAssignment(flagsProp)) {
934
+ const flagsInit = flagsProp.getInitializer();
935
+ if (flagsInit && import_ts_morph6.Node.isArrayLiteralExpression(flagsInit)) {
936
+ if (hasElementWithId(flagsInit, FLAG_ID)) return false;
937
+ flagsInit.addElement(FLAG_DEFINITION_INITIALIZER);
938
+ return true;
939
+ }
940
+ return false;
941
+ }
942
+ configArg.addPropertyAssignment({
943
+ name: FLAGS_PROPERTY_NAME2,
944
+ initializer: `[
945
+ ${FLAG_DEFINITION_INITIALIZER}
946
+ ]`
947
+ });
948
+ return true;
949
+ }
950
+ function ensureActionOperationFlag(action, operation) {
951
+ const flagsProp = action.getProperty(FLAGS_PROPERTY_NAME2);
952
+ const entry = `{ id: '${FLAG_ID}', operation: '${operation}' }`;
953
+ if (flagsProp && import_ts_morph6.Node.isPropertyAssignment(flagsProp)) {
954
+ const flagsInit = flagsProp.getInitializer();
955
+ if (flagsInit && import_ts_morph6.Node.isArrayLiteralExpression(flagsInit)) {
956
+ if (hasElementWithId(flagsInit, FLAG_ID)) return false;
957
+ flagsInit.addElement(entry);
958
+ return true;
959
+ }
960
+ return false;
961
+ }
962
+ action.addPropertyAssignment({
963
+ name: FLAGS_PROPERTY_NAME2,
964
+ initializer: `[${entry}]`
965
+ });
966
+ return true;
967
+ }
968
+ function processBirthConfig(configArg, relPath) {
969
+ let changes = 0;
970
+ if (ensureTopLevelFlagDefinition(configArg)) {
971
+ changes++;
972
+ console.log(` [${relPath}] Added '${FLAG_ID}' to top-level flags`);
973
+ }
974
+ const actionsProp = configArg.getProperty(ACTIONS_PROPERTY_NAME4);
975
+ if (!actionsProp || !import_ts_morph6.Node.isPropertyAssignment(actionsProp)) return changes;
976
+ const actionsInit = actionsProp.getInitializer();
977
+ if (!actionsInit || !import_ts_morph6.Node.isArrayLiteralExpression(actionsInit)) {
978
+ return changes;
979
+ }
980
+ for (const element of actionsInit.getElements()) {
981
+ if (!import_ts_morph6.Node.isObjectLiteralExpression(element)) continue;
982
+ if (isActionOfType(element, REGISTER_TYPE)) {
983
+ if (ensureActionOperationFlag(element, "add")) {
984
+ changes++;
985
+ console.log(
986
+ ` [${relPath}] Added '${FLAG_ID}' add-flag to REGISTER action`
987
+ );
988
+ }
989
+ }
990
+ if (isActionOfType(element, PRINT_CERTIFICATE_TYPE)) {
991
+ if (ensureActionOperationFlag(element, "remove")) {
992
+ changes++;
993
+ console.log(
994
+ ` [${relPath}] Added '${FLAG_ID}' remove-flag to PRINT_CERTIFICATE action`
995
+ );
996
+ }
997
+ }
998
+ }
999
+ return changes;
1000
+ }
1001
+ function hasPrintCertificateAction(workqueue) {
1002
+ const actionsProp = workqueue.getProperty(ACTIONS_PROPERTY_NAME4);
1003
+ if (actionsProp && import_ts_morph6.Node.isPropertyAssignment(actionsProp)) {
1004
+ const actionsInit = actionsProp.getInitializer();
1005
+ if (actionsInit && import_ts_morph6.Node.isArrayLiteralExpression(actionsInit)) {
1006
+ for (const el of actionsInit.getElements()) {
1007
+ if (import_ts_morph6.Node.isObjectLiteralExpression(el) && isActionOfType(el, PRINT_CERTIFICATE_TYPE)) {
1008
+ return true;
1009
+ }
1010
+ }
1011
+ }
1012
+ }
1013
+ const actionProp = workqueue.getProperty(ACTION_PROPERTY_NAME);
1014
+ if (actionProp && import_ts_morph6.Node.isPropertyAssignment(actionProp)) {
1015
+ const actionInit = actionProp.getInitializer();
1016
+ if (actionInit && import_ts_morph6.Node.isObjectLiteralExpression(actionInit) && isActionOfType(actionInit, PRINT_CERTIFICATE_TYPE)) {
1017
+ return true;
1018
+ }
1019
+ }
1020
+ return false;
1021
+ }
1022
+ function addFlagToQueryClause(clause) {
1023
+ const flagsProp = clause.getProperty(FLAGS_PROPERTY_NAME2);
1024
+ if (flagsProp && import_ts_morph6.Node.isPropertyAssignment(flagsProp)) {
1025
+ const flagsInit = flagsProp.getInitializer();
1026
+ if (flagsInit && import_ts_morph6.Node.isObjectLiteralExpression(flagsInit)) {
1027
+ const anyOfProp = flagsInit.getProperty(ANY_OF_PROPERTY_NAME2);
1028
+ if (anyOfProp && import_ts_morph6.Node.isPropertyAssignment(anyOfProp)) {
1029
+ const anyOfInit = anyOfProp.getInitializer();
1030
+ if (anyOfInit && import_ts_morph6.Node.isArrayLiteralExpression(anyOfInit)) {
1031
+ const alreadyPresent = anyOfInit.getElements().some(
1032
+ (el) => import_ts_morph6.Node.isStringLiteral(el) && el.getLiteralValue() === FLAG_ID
1033
+ );
1034
+ if (alreadyPresent) return false;
1035
+ anyOfInit.addElement(`'${FLAG_ID}'`);
1036
+ return true;
1037
+ }
1038
+ } else {
1039
+ flagsInit.addPropertyAssignment({
1040
+ name: ANY_OF_PROPERTY_NAME2,
1041
+ initializer: `['${FLAG_ID}']`
1042
+ });
1043
+ return true;
1044
+ }
1045
+ }
1046
+ } else {
1047
+ clause.addPropertyAssignment({
1048
+ name: FLAGS_PROPERTY_NAME2,
1049
+ initializer: `{ ${ANY_OF_PROPERTY_NAME2}: ['${FLAG_ID}'] }`
1050
+ });
1051
+ return true;
1052
+ }
1053
+ return false;
1054
+ }
1055
+ function walkQueryForFlagAddition(queryObj) {
1056
+ const typeProp = queryObj.getProperty(TYPE_PROPERTY_NAME6);
1057
+ if (typeProp && import_ts_morph6.Node.isPropertyAssignment(typeProp)) {
1058
+ const typeInit = typeProp.getInitializer();
1059
+ if (typeInit && import_ts_morph6.Node.isStringLiteral(typeInit) && (typeInit.getLiteralValue() === "or" || typeInit.getLiteralValue() === "and")) {
1060
+ const clausesProp = queryObj.getProperty(CLAUSES_PROPERTY_NAME2);
1061
+ if (!clausesProp || !import_ts_morph6.Node.isPropertyAssignment(clausesProp)) return 0;
1062
+ const clausesInit = clausesProp.getInitializer();
1063
+ if (!clausesInit || !import_ts_morph6.Node.isArrayLiteralExpression(clausesInit)) return 0;
1064
+ let changed = 0;
1065
+ for (const clause of clausesInit.getElements()) {
1066
+ if (import_ts_morph6.Node.isObjectLiteralExpression(clause)) {
1067
+ changed += walkQueryForFlagAddition(clause);
1068
+ }
1069
+ }
1070
+ return changed;
1071
+ }
1072
+ }
1073
+ return addFlagToQueryClause(queryObj) ? 1 : 0;
1074
+ }
1075
+ function processFile6(filePath, project) {
1076
+ const sourceFile = project.getSourceFile(filePath);
1077
+ if (!sourceFile) return 0;
1078
+ let totalChanges = 0;
1079
+ const relPath = import_path6.default.relative(getCwd(), filePath);
1080
+ const callExpressions = sourceFile.getDescendantsOfKind(
1081
+ import_ts_morph6.SyntaxKind.CallExpression
1082
+ );
1083
+ for (const call of callExpressions) {
1084
+ const expression = call.getExpression();
1085
+ if (!import_ts_morph6.Node.isIdentifier(expression)) continue;
1086
+ const calleeName = expression.getText();
1087
+ if (calleeName === DEFINE_CONFIG_NAME4) {
1088
+ const args = call.getArguments();
1089
+ if (args.length === 0) continue;
1090
+ const configArg = args[0];
1091
+ if (!import_ts_morph6.Node.isObjectLiteralExpression(configArg)) continue;
1092
+ if (!isBirthConfig(configArg)) continue;
1093
+ totalChanges += processBirthConfig(configArg, relPath);
1094
+ }
1095
+ if (calleeName === DEFINE_WORKQUEUES_NAME2) {
1096
+ const args = call.getArguments();
1097
+ if (args.length === 0) continue;
1098
+ const workqueuesArg = args[0];
1099
+ if (!import_ts_morph6.Node.isArrayLiteralExpression(workqueuesArg)) continue;
1100
+ for (const workqueueEl of workqueuesArg.getElements()) {
1101
+ if (!import_ts_morph6.Node.isObjectLiteralExpression(workqueueEl)) continue;
1102
+ if (!hasPrintCertificateAction(workqueueEl)) continue;
1103
+ const queryProp = workqueueEl.getProperty(QUERY_PROPERTY_NAME2);
1104
+ if (!queryProp || !import_ts_morph6.Node.isPropertyAssignment(queryProp)) continue;
1105
+ const queryInit = queryProp.getInitializer();
1106
+ if (!queryInit || !import_ts_morph6.Node.isObjectLiteralExpression(queryInit)) continue;
1107
+ const changed = walkQueryForFlagAddition(queryInit);
1108
+ if (changed > 0) {
1109
+ totalChanges += changed;
1110
+ console.log(
1111
+ ` [${relPath}] Added '${FLAG_ID}' to flags.anyOf in ${changed} PRINT_CERTIFICATE workqueue clause(s)`
1112
+ );
1113
+ }
1114
+ }
1115
+ }
1116
+ }
1117
+ return totalChanges;
1118
+ }
1119
+ async function main6() {
1120
+ const srcDir = import_path6.default.join(getCwd(), "src");
1121
+ console.log(
1122
+ `Scanning for birth defineConfig and PRINT_CERTIFICATE workqueues in: ${srcDir}
1123
+ `
1124
+ );
1125
+ const project = new import_ts_morph6.Project({
1126
+ tsConfigFilePath: import_path6.default.resolve(srcDir, "../tsconfig.json"),
1127
+ skipAddingFilesFromTsConfig: false
1128
+ });
1129
+ const sourceFiles = project.getSourceFiles().filter((sf) => {
1130
+ const fp = sf.getFilePath();
1131
+ return fp.includes("/src/") && !fp.includes("/node_modules/");
1132
+ });
1133
+ console.log(`Found ${sourceFiles.length} source file(s) to analyse.
1134
+ `);
1135
+ let totalChanges = 0;
1136
+ const modifiedFiles = [];
1137
+ for (const sourceFile of sourceFiles) {
1138
+ const filePath = sourceFile.getFilePath();
1139
+ const changes = processFile6(filePath, project);
1140
+ if (changes > 0) {
1141
+ totalChanges += changes;
1142
+ modifiedFiles.push(filePath);
1143
+ }
1144
+ }
1145
+ if (modifiedFiles.length === 0) {
1146
+ console.log(
1147
+ "No birth configs or PRINT_CERTIFICATE workqueues found. Nothing to do."
1148
+ );
1149
+ return;
1150
+ }
1151
+ console.log(`
1152
+ Saving ${modifiedFiles.length} modified file(s)...`);
1153
+ for (const filePath of modifiedFiles) {
1154
+ const sourceFile = project.getSourceFileOrThrow(filePath);
1155
+ await sourceFile.save();
1156
+ console.log(` Saved: ${import_path6.default.relative(getCwd(), filePath)}`);
1157
+ }
1158
+ console.log(
1159
+ `
1160
+ Done. Applied ${totalChanges} change(s) across ${modifiedFiles.length} file(s).`
1161
+ );
1162
+ }
1163
+
1164
+ // src/migrations/v2.0/remove-pending-certification-flag.ts
1165
+ var import_ts_morph7 = require("ts-morph");
1166
+ var import_path7 = __toESM(require("path"));
1167
+ var INHERENT_FLAGS_ENUM_NAME = "InherentFlags";
1168
+ var PENDING_CERTIFICATION_MEMBER = "PENDING_CERTIFICATION";
1169
+ function isPendingCertificationFlag(node) {
1170
+ if (!import_ts_morph7.Node.isPropertyAccessExpression(node)) return false;
1171
+ const obj = node.getExpression();
1172
+ const member = node.getName();
1173
+ return import_ts_morph7.Node.isIdentifier(obj) && obj.getText() === INHERENT_FLAGS_ENUM_NAME && member === PENDING_CERTIFICATION_MEMBER;
1174
+ }
1175
+ function processFile7(filePath, project) {
1176
+ const sourceFile = project.getSourceFile(filePath);
1177
+ if (!sourceFile) return 0;
1178
+ let removedCount = 0;
1179
+ const arrayLiterals = sourceFile.getDescendantsOfKind(
1180
+ import_ts_morph7.SyntaxKind.ArrayLiteralExpression
1181
+ );
1182
+ for (const array of arrayLiterals) {
1183
+ const indicesToRemove = [];
1184
+ array.getElements().forEach((element, index) => {
1185
+ if (isPendingCertificationFlag(element)) {
1186
+ indicesToRemove.push(index);
1187
+ }
1188
+ });
1189
+ for (const index of indicesToRemove.reverse()) {
1190
+ array.removeElement(index);
1191
+ removedCount++;
1192
+ console.log(
1193
+ ` [${import_path7.default.relative(getCwd(), filePath)}] Removed InherentFlags.PENDING_CERTIFICATION from array`
1194
+ );
1195
+ }
1196
+ }
1197
+ return removedCount;
1198
+ }
1199
+ async function main7() {
1200
+ const srcDir = import_path7.default.join(getCwd(), "src");
1201
+ console.log(
1202
+ `Scanning for InherentFlags.PENDING_CERTIFICATION array elements in: ${srcDir}
1203
+ `
1204
+ );
1205
+ const project = new import_ts_morph7.Project({
1206
+ tsConfigFilePath: import_path7.default.resolve(srcDir, "../tsconfig.json"),
1207
+ skipAddingFilesFromTsConfig: false
1208
+ });
1209
+ const sourceFiles = project.getSourceFiles().filter((sf) => {
1210
+ const fp = sf.getFilePath();
1211
+ return fp.includes("/src/") && !fp.includes("/node_modules/");
1212
+ });
1213
+ console.log(`Found ${sourceFiles.length} source file(s) to analyse.
1214
+ `);
1215
+ let totalRemoved = 0;
1216
+ const modifiedFiles = [];
1217
+ for (const sourceFile of sourceFiles) {
1218
+ const filePath = sourceFile.getFilePath();
1219
+ const removed = processFile7(filePath, project);
1220
+ if (removed > 0) {
1221
+ totalRemoved += removed;
1222
+ modifiedFiles.push(filePath);
1223
+ }
1224
+ }
1225
+ if (modifiedFiles.length === 0) {
1226
+ console.log(
1227
+ "No InherentFlags.PENDING_CERTIFICATION elements found in any array. Nothing to do."
1228
+ );
1229
+ return;
1230
+ }
1231
+ console.log(`
1232
+ Saving ${modifiedFiles.length} modified file(s)...`);
1233
+ for (const filePath of modifiedFiles) {
1234
+ const sourceFile = project.getSourceFileOrThrow(filePath);
1235
+ await sourceFile.save();
1236
+ console.log(` Saved: ${import_path7.default.relative(getCwd(), filePath)}`);
1237
+ }
1238
+ console.log(
1239
+ `
1240
+ Done. Removed ${totalRemoved} InherentFlags.PENDING_CERTIFICATION element(s) from array(s).`
1241
+ );
1242
+ }
1243
+
1244
+ // src/migrations/v2.0/rename-location-parent-id.ts
1245
+ var import_ts_morph8 = require("ts-morph");
1246
+ var import_path8 = __toESM(require("path"));
1247
+ var OLD_PROPERTY_NAME = "parentId";
1248
+ var NEW_PROPERTY_NAME = "administrativeAreaId";
1249
+ var LOCATION_TYPE_NAME = "Location";
1250
+ var LOCATION_STRUCTURAL_PROPS = [
1251
+ "id",
1252
+ "name",
1253
+ "externalId",
1254
+ "locationType"
1255
+ ];
1256
+ var LOCATION_AREA_ID_PROPS = ["administrativeAreaId", "parentId"];
1257
+ function isSingleLocationType(t) {
1258
+ if (t.getAliasSymbol()?.getName() === LOCATION_TYPE_NAME) return true;
1259
+ if (t.getSymbol()?.getName() === LOCATION_TYPE_NAME) return true;
1260
+ if (t.isObject()) {
1261
+ const propNames = new Set(t.getProperties().map((p) => p.getName()));
1262
+ const hasCorePropNames = LOCATION_STRUCTURAL_PROPS.every(
1263
+ (p) => propNames.has(p)
1264
+ );
1265
+ const hasAreaIdProp = LOCATION_AREA_ID_PROPS.some((p) => propNames.has(p));
1266
+ if (hasCorePropNames && hasAreaIdProp) return true;
1267
+ }
1268
+ return false;
1269
+ }
1270
+ function isLocationType(node) {
1271
+ let type;
1272
+ try {
1273
+ type = node.getType();
1274
+ } catch {
1275
+ return false;
1276
+ }
1277
+ if (isSingleLocationType(type)) return true;
1278
+ for (const constituent of type.getUnionTypes()) {
1279
+ if (isSingleLocationType(constituent)) return true;
1280
+ }
1281
+ return false;
1282
+ }
1283
+ function processFile8(filePath, project) {
1284
+ const sourceFile = project.getSourceFile(filePath);
1285
+ if (!sourceFile) return 0;
1286
+ let renamedCount = 0;
1287
+ const candidates = sourceFile.getDescendantsOfKind(import_ts_morph8.SyntaxKind.PropertyAccessExpression).filter((propAccess) => propAccess.getName() === OLD_PROPERTY_NAME);
1288
+ for (const propAccess of candidates) {
1289
+ const obj = propAccess.getExpression();
1290
+ if (!isLocationType(obj)) continue;
1291
+ propAccess.getNameNode().replaceWithText(NEW_PROPERTY_NAME);
1292
+ renamedCount++;
1293
+ console.log(
1294
+ ` [${import_path8.default.relative(getCwd(), filePath)}] Renamed Location.${OLD_PROPERTY_NAME} \u2192 Location.${NEW_PROPERTY_NAME}`
1295
+ );
1296
+ }
1297
+ return renamedCount;
1298
+ }
1299
+ async function main8() {
1300
+ const srcDir = import_path8.default.join(getCwd(), "src");
1301
+ console.log(
1302
+ `Scanning for Location.${OLD_PROPERTY_NAME} references in: ${srcDir}
1303
+ `
1304
+ );
1305
+ const project = new import_ts_morph8.Project({
1306
+ tsConfigFilePath: import_path8.default.resolve(srcDir, "../tsconfig.json"),
1307
+ skipAddingFilesFromTsConfig: false
1308
+ });
1309
+ const sourceFiles = project.getSourceFiles().filter((sf) => {
1310
+ const fp = sf.getFilePath();
1311
+ return fp.includes("/src/") && !fp.includes("/node_modules/");
1312
+ });
1313
+ console.log(`Found ${sourceFiles.length} source file(s) to analyse.
1314
+ `);
1315
+ let totalRenamed = 0;
1316
+ const modifiedFiles = [];
1317
+ for (const sourceFile of sourceFiles) {
1318
+ const filePath = sourceFile.getFilePath();
1319
+ const renamed = processFile8(filePath, project);
1320
+ if (renamed > 0) {
1321
+ totalRenamed += renamed;
1322
+ modifiedFiles.push(filePath);
1323
+ }
1324
+ }
1325
+ if (modifiedFiles.length === 0) {
1326
+ console.log(
1327
+ `No Location.${OLD_PROPERTY_NAME} references found. Nothing to do.`
1328
+ );
1329
+ return;
1330
+ }
1331
+ console.log(`
1332
+ Saving ${modifiedFiles.length} modified file(s)...`);
1333
+ for (const filePath of modifiedFiles) {
1334
+ const sourceFile = project.getSourceFileOrThrow(filePath);
1335
+ await sourceFile.save();
1336
+ console.log(` Saved: ${import_path8.default.relative(getCwd(), filePath)}`);
1337
+ }
1338
+ console.log(
1339
+ `
1340
+ Done. Renamed ${totalRenamed} Location.${OLD_PROPERTY_NAME} reference(s) to Location.${NEW_PROPERTY_NAME}.`
1341
+ );
1342
+ }
1343
+
1344
+ // src/migrations/v2.0/rename-api-paths.ts
1345
+ var import_ts_morph9 = require("ts-morph");
1346
+ var import_path9 = __toESM(require("path"));
1347
+ var PATH_RENAMES = {
1348
+ "/events": "/config/events",
1349
+ "/application-config": "/config/application",
1350
+ "/workqueue": "/config/workqueues",
1351
+ "/locations": "/config/locations",
1352
+ "/users": "/config/users",
1353
+ "/roles": "/config/roles"
1354
+ };
1355
+ var METHOD_PROPERTY_NAME = "method";
1356
+ var PATH_PROPERTY_NAME = "path";
1357
+ var HTTP_VERBS = /* @__PURE__ */ new Set([
1358
+ "GET",
1359
+ "POST",
1360
+ "PUT",
1361
+ "PATCH",
1362
+ "DELETE",
1363
+ "OPTIONS",
1364
+ "HEAD",
1365
+ "*"
1366
+ ]);
1367
+ function isRouteConfig(obj) {
1368
+ const methodProp = obj.getProperty(METHOD_PROPERTY_NAME);
1369
+ if (!methodProp || !import_ts_morph9.Node.isPropertyAssignment(methodProp)) return false;
1370
+ const methodInit = methodProp.getInitializer();
1371
+ if (!methodInit) return false;
1372
+ if (import_ts_morph9.Node.isStringLiteral(methodInit)) {
1373
+ if (!HTTP_VERBS.has(methodInit.getLiteralValue().toUpperCase()))
1374
+ return false;
1375
+ } else if (import_ts_morph9.Node.isArrayLiteralExpression(methodInit)) {
1376
+ const allVerbs = methodInit.getElements().every(
1377
+ (el) => import_ts_morph9.Node.isStringLiteral(el) && HTTP_VERBS.has(el.getLiteralValue().toUpperCase())
1378
+ );
1379
+ if (!allVerbs) return false;
1380
+ } else {
1381
+ return false;
1382
+ }
1383
+ const pathProp = obj.getProperty(PATH_PROPERTY_NAME);
1384
+ if (!pathProp || !import_ts_morph9.Node.isPropertyAssignment(pathProp)) return false;
1385
+ const pathInit = pathProp.getInitializer();
1386
+ return !!pathInit && import_ts_morph9.Node.isStringLiteral(pathInit);
1387
+ }
1388
+ function renameRoutePath(obj) {
1389
+ const pathProp = obj.getProperty(PATH_PROPERTY_NAME);
1390
+ if (!pathProp || !import_ts_morph9.Node.isPropertyAssignment(pathProp)) return null;
1391
+ const pathInit = pathProp.getInitializer();
1392
+ if (!pathInit || !import_ts_morph9.Node.isStringLiteral(pathInit)) return null;
1393
+ const oldPath = pathInit.getLiteralValue();
1394
+ const newPath = PATH_RENAMES[oldPath];
1395
+ if (!newPath) return null;
1396
+ pathInit.replaceWithText(`'${newPath}'`);
1397
+ return newPath;
1398
+ }
1399
+ function processFile9(filePath, project) {
1400
+ const sourceFile = project.getSourceFile(filePath);
1401
+ if (!sourceFile) return 0;
1402
+ let renamedCount = 0;
1403
+ const relPath = import_path9.default.relative(getCwd(), filePath);
1404
+ const candidates = sourceFile.getDescendantsOfKind(
1405
+ import_ts_morph9.SyntaxKind.ObjectLiteralExpression
1406
+ );
1407
+ for (const obj of candidates) {
1408
+ if (!isRouteConfig(obj)) continue;
1409
+ const newPath = renameRoutePath(obj);
1410
+ if (newPath) {
1411
+ renamedCount++;
1412
+ console.log(` [${relPath}] Renamed route path \u2192 '${newPath}'`);
1413
+ }
1414
+ }
1415
+ return renamedCount;
1416
+ }
1417
+ async function main9() {
1418
+ const srcDir = import_path9.default.join(getCwd(), "src");
1419
+ console.log(`Scanning for Hapi route configs in: ${srcDir}
1420
+ `);
1421
+ console.log("Active path renames:");
1422
+ for (const [from, to] of Object.entries(PATH_RENAMES)) {
1423
+ console.log(` '${from}' \u2192 '${to}'`);
1424
+ }
1425
+ console.log();
1426
+ const project = new import_ts_morph9.Project({
1427
+ tsConfigFilePath: import_path9.default.resolve(srcDir, "../tsconfig.json"),
1428
+ skipAddingFilesFromTsConfig: false
1429
+ });
1430
+ const sourceFiles = project.getSourceFiles().filter((sf) => {
1431
+ const fp = sf.getFilePath();
1432
+ return fp.includes("/src/") && !fp.includes("/node_modules/");
1433
+ });
1434
+ console.log(`Found ${sourceFiles.length} source file(s) to analyse.
1435
+ `);
1436
+ let totalRenamed = 0;
1437
+ const modifiedFiles = [];
1438
+ for (const sourceFile of sourceFiles) {
1439
+ const filePath = sourceFile.getFilePath();
1440
+ const renamed = processFile9(filePath, project);
1441
+ if (renamed > 0) {
1442
+ totalRenamed += renamed;
1443
+ modifiedFiles.push(filePath);
1444
+ }
1445
+ }
1446
+ if (modifiedFiles.length === 0) {
1447
+ console.log("No matching route paths found. Nothing to do.");
1448
+ return;
1449
+ }
1450
+ console.log(`
1451
+ Saving ${modifiedFiles.length} modified file(s)...`);
1452
+ for (const filePath of modifiedFiles) {
1453
+ const sourceFile = project.getSourceFileOrThrow(filePath);
1454
+ await sourceFile.save();
1455
+ console.log(` Saved: ${import_path9.default.relative(getCwd(), filePath)}`);
1456
+ }
1457
+ console.log(`
1458
+ Done. Renamed ${totalRenamed} route path(s).`);
1459
+ }
1460
+
1461
+ // src/migrations/v2.0/convert-config-files-to-ts.ts
1462
+ var fs = __toESM(require("fs"));
1463
+ var import_ts_morph10 = require("ts-morph");
1464
+ var import_path10 = __toESM(require("path"));
1465
+ var CLIENT_VALID_KEYS = /* @__PURE__ */ new Set([
1466
+ "COUNTRY",
1467
+ "LANGUAGES",
1468
+ "SENTRY",
1469
+ "REGISTER_BACKGROUND",
1470
+ "DASHBOARDS",
1471
+ "FEATURES"
1472
+ ]);
1473
+ var LOGIN_VALID_KEYS = /* @__PURE__ */ new Set([
1474
+ "COUNTRY",
1475
+ "LANGUAGES",
1476
+ "USER_NOTIFICATION_DELIVERY_METHOD",
1477
+ "INFORMANT_NOTIFICATION_DELIVERY_METHOD",
1478
+ "PHONE_NUMBER_PATTERN",
1479
+ "LOGIN_BACKGROUND",
1480
+ "SENTRY"
1481
+ ]);
1482
+ var APPLICATION_CONFIG_VALID_KEYS = /* @__PURE__ */ new Set([
1483
+ "APPLICATION_NAME",
1484
+ "COUNTRY_LOGO",
1485
+ "SYSTEM_IANA_TIMEZONE",
1486
+ "CURRENCY",
1487
+ "ADMIN_STRUCTURE",
1488
+ "PHONE_NUMBER_PATTERN",
1489
+ "USER_NOTIFICATION_DELIVERY_METHOD",
1490
+ "INFORMANT_NOTIFICATION_DELIVERY_METHOD",
1491
+ "SEARCH_DEFAULT_CRITERIA"
1492
+ ]);
1493
+ var CONFIG_GROUPS = [
1494
+ {
1495
+ baseName: "client-config",
1496
+ prodName: "client-config.prod",
1497
+ defineFn: "defineClientConfig",
1498
+ importFrom: "@opencrvs/toolkit/application-config",
1499
+ validKeys: CLIENT_VALID_KEYS,
1500
+ requiredPlaceholders: {
1501
+ // BackgroundConfig requires backgroundColor or backgroundImage
1502
+ REGISTER_BACKGROUND: "{ backgroundColor: '#F4F4F7' }"
1503
+ },
1504
+ exportNames: {
1505
+ "client-config": "clientConfig",
1506
+ "client-config.prod": "clientConfigProd"
1507
+ },
1508
+ routePath: "/client-config.js"
1509
+ },
1510
+ {
1511
+ baseName: "login-config",
1512
+ prodName: "login-config.prod",
1513
+ defineFn: "defineLoginConfig",
1514
+ importFrom: "@opencrvs/toolkit/application-config",
1515
+ validKeys: LOGIN_VALID_KEYS,
1516
+ requiredPlaceholders: {},
1517
+ // These keys are always sourced from applicationConfig rather than
1518
+ // copied from the old JS file or filled with a placeholder value.
1519
+ // LOGIN_BACKGROUND lives in applicationConfig and is not part of the
1520
+ // ApplicationConfig schema, so Phase 3 will inline its value and remove
1521
+ // it from applicationConfig automatically.
1522
+ applicationConfigKeys: [
1523
+ "LOGIN_BACKGROUND",
1524
+ "USER_NOTIFICATION_DELIVERY_METHOD",
1525
+ "INFORMANT_NOTIFICATION_DELIVERY_METHOD",
1526
+ "PHONE_NUMBER_PATTERN"
1527
+ ],
1528
+ applicationConfigImportPath: "./api/application/application-config",
1529
+ exportNames: {
1530
+ "login-config": "loginConfig",
1531
+ "login-config.prod": "loginConfigProd"
1532
+ },
1533
+ routePath: "/login-config.js"
1534
+ }
1535
+ ];
1536
+ var HTTP_VERBS2 = /* @__PURE__ */ new Set([
1537
+ "GET",
1538
+ "POST",
1539
+ "PUT",
1540
+ "PATCH",
1541
+ "DELETE",
1542
+ "OPTIONS",
1543
+ "HEAD",
1544
+ "*"
1545
+ ]);
1546
+ function extractWindowConfig(jsFilePath) {
1547
+ const jsProject = new import_ts_morph10.Project({
1548
+ compilerOptions: { allowJs: true, checkJs: false }
1549
+ // addFilesFromTsConfig: false
1550
+ });
1551
+ let sourceFile;
1552
+ try {
1553
+ sourceFile = jsProject.addSourceFileAtPath(jsFilePath);
1554
+ } catch {
1555
+ console.warn(` Could not parse ${jsFilePath}`);
1556
+ return null;
1557
+ }
1558
+ for (const binary of sourceFile.getDescendantsOfKind(
1559
+ import_ts_morph10.SyntaxKind.BinaryExpression
1560
+ )) {
1561
+ if (binary.getOperatorToken().getKind() !== import_ts_morph10.SyntaxKind.EqualsToken) continue;
1562
+ const left = binary.getLeft();
1563
+ if (!import_ts_morph10.Node.isPropertyAccessExpression(left)) continue;
1564
+ if (left.getExpression().getText() !== "window") continue;
1565
+ if (left.getName() !== "config") continue;
1566
+ const right = binary.getRight();
1567
+ if (import_ts_morph10.Node.isObjectLiteralExpression(right)) return right;
1568
+ }
1569
+ return null;
1570
+ }
1571
+ function convertLanguages(init) {
1572
+ if (import_ts_morph10.Node.isStringLiteral(init)) {
1573
+ const langs = init.getLiteralValue().split(",").map((l) => `'${l.trim()}'`).join(", ");
1574
+ return `[${langs}]`;
1575
+ }
1576
+ return init.getText();
1577
+ }
1578
+ function extractStaticUrlString(init) {
1579
+ if (import_ts_morph10.Node.isStringLiteral(init)) {
1580
+ return init.getLiteralValue();
1581
+ }
1582
+ if (init.getKind() === import_ts_morph10.SyntaxKind.NoSubstitutionTemplateLiteral) {
1583
+ const raw = init.getText();
1584
+ return raw.slice(1, -1);
1585
+ }
1586
+ return null;
1587
+ }
1588
+ function transformDashboardUrl(init, isProd) {
1589
+ if (!isProd) return init.getText();
1590
+ const urlString = extractStaticUrlString(init);
1591
+ if (!urlString) return init.getText();
1592
+ try {
1593
+ const parsed = new URL(urlString);
1594
+ const rest = parsed.pathname + parsed.search + parsed.hash;
1595
+ return `\`\${scheme}//metabase.\${hostname}${rest}\``;
1596
+ } catch {
1597
+ return init.getText();
1598
+ }
1599
+ }
1600
+ function transformDashboardsValue(init, isProd) {
1601
+ if (!isProd || !import_ts_morph10.Node.isArrayLiteralExpression(init)) {
1602
+ return init.getText();
1603
+ }
1604
+ const elementParts = [];
1605
+ for (const el of init.getElements()) {
1606
+ if (!import_ts_morph10.Node.isObjectLiteralExpression(el)) {
1607
+ elementParts.push(el.getText());
1608
+ continue;
1609
+ }
1610
+ const propParts = [];
1611
+ for (const prop of el.getProperties()) {
1612
+ if (!import_ts_morph10.Node.isPropertyAssignment(prop)) {
1613
+ propParts.push(prop.getText());
1614
+ continue;
1615
+ }
1616
+ const propName = prop.getName();
1617
+ const propInit = prop.getInitializer();
1618
+ if (!propInit) {
1619
+ propParts.push(prop.getText());
1620
+ continue;
1621
+ }
1622
+ if (propName === "url") {
1623
+ propParts.push(`url: ${transformDashboardUrl(propInit, isProd)}`);
1624
+ } else {
1625
+ propParts.push(`${propName}: ${propInit.getText()}`);
1626
+ }
1627
+ }
1628
+ elementParts.push(
1629
+ ` {
1630
+ ${propParts.map((p) => ` ${p}`).join(",\n")}
1631
+ }`
1632
+ );
1633
+ }
1634
+ return `[
1635
+ ${elementParts.join(",\n")}
1636
+ ]`;
1637
+ }
1638
+ function generateTsContent(configObj, exportName, group, isProd) {
1639
+ const headerLines = [];
1640
+ if (isProd) {
1641
+ headerLines.push(`import { env } from './environment'`);
1642
+ }
1643
+ headerLines.push(`import { ${group.defineFn} } from '${group.importFrom}'`);
1644
+ if (group.applicationConfigImportPath) {
1645
+ headerLines.push(
1646
+ `import { applicationConfig } from '${group.applicationConfigImportPath}'`
1647
+ );
1648
+ }
1649
+ headerLines.push("");
1650
+ if (isProd) {
1651
+ headerLines.push(`const scheme = 'https'`);
1652
+ headerLines.push(`const hostname = env.DOMAIN`);
1653
+ headerLines.push(`const sentry = env.SENTRY_DSN`);
1654
+ } else {
1655
+ headerLines.push(`const scheme = 'http'`);
1656
+ headerLines.push(`const hostname = 'localhost'`);
1657
+ }
1658
+ const propertyLines = [];
1659
+ const seenKeys = /* @__PURE__ */ new Set();
1660
+ const appConfigKeySet = new Set(group.applicationConfigKeys ?? []);
1661
+ for (const prop of configObj.getProperties()) {
1662
+ if (!import_ts_morph10.Node.isPropertyAssignment(prop)) continue;
1663
+ const name = prop.getName();
1664
+ if (!group.validKeys.has(name)) continue;
1665
+ if (appConfigKeySet.has(name)) continue;
1666
+ seenKeys.add(name);
1667
+ const init = prop.getInitializer();
1668
+ if (!init) continue;
1669
+ if (name === "LANGUAGES") {
1670
+ propertyLines.push(` LANGUAGES: ${convertLanguages(init)}`);
1671
+ } else if (name === "SENTRY" && isProd) {
1672
+ propertyLines.push(` SENTRY: sentry`);
1673
+ } else if (name === "DASHBOARDS") {
1674
+ propertyLines.push(
1675
+ ` DASHBOARDS: ${transformDashboardsValue(init, isProd)}`
1676
+ );
1677
+ } else {
1678
+ propertyLines.push(` ${name}: ${init.getText()}`);
1679
+ }
1680
+ }
1681
+ for (const [key, placeholder] of Object.entries(group.requiredPlaceholders)) {
1682
+ if (!seenKeys.has(key)) {
1683
+ propertyLines.push(
1684
+ ` // TODO: configure ${key} \u2014 replace this placeholder`,
1685
+ ` ${key}: ${placeholder}`
1686
+ );
1687
+ }
1688
+ }
1689
+ for (const key of appConfigKeySet) {
1690
+ propertyLines.push(` ${key}: applicationConfig.${key}`);
1691
+ }
1692
+ const body = propertyLines.join(",\n");
1693
+ return [
1694
+ ...headerLines,
1695
+ "",
1696
+ `export const ${exportName} = ${group.defineFn}({`,
1697
+ body,
1698
+ "})",
1699
+ ""
1700
+ ].join("\n");
1701
+ }
1702
+ function convertFile(name, group, srcDir) {
1703
+ const jsFilePath = import_path10.default.join(srcDir, `${name}.js`);
1704
+ const tsFilePath = import_path10.default.join(srcDir, `${name}.ts`);
1705
+ if (!fs.existsSync(jsFilePath)) {
1706
+ console.log(` Skipping ${name}.js \u2014 file not found`);
1707
+ return false;
1708
+ }
1709
+ if (fs.existsSync(tsFilePath)) {
1710
+ console.log(` Skipping ${name}.js \u2014 ${name}.ts already exists`);
1711
+ return false;
1712
+ }
1713
+ const configObj = extractWindowConfig(jsFilePath);
1714
+ if (!configObj) {
1715
+ console.warn(
1716
+ ` [${name}.js] Could not locate window.config assignment \u2014 skipping`
1717
+ );
1718
+ return false;
1719
+ }
1720
+ const isProd = name.endsWith(".prod");
1721
+ const exportName = group.exportNames[name];
1722
+ const content = generateTsContent(configObj, exportName, group, isProd);
1723
+ fs.writeFileSync(tsFilePath, content, "utf8");
1724
+ fs.unlinkSync(jsFilePath);
1725
+ console.log(` Converted ${name}.js \u2192 ${name}.ts (export: ${exportName})`);
1726
+ return true;
1727
+ }
1728
+ function isRouteConfig2(obj) {
1729
+ const methodProp = obj.getProperty("method");
1730
+ if (!methodProp || !import_ts_morph10.Node.isPropertyAssignment(methodProp)) return false;
1731
+ const methodInit = methodProp.getInitializer();
1732
+ if (!methodInit) return false;
1733
+ if (import_ts_morph10.Node.isStringLiteral(methodInit)) {
1734
+ if (!HTTP_VERBS2.has(methodInit.getLiteralValue().toUpperCase()))
1735
+ return false;
1736
+ } else if (import_ts_morph10.Node.isArrayLiteralExpression(methodInit)) {
1737
+ const allVerbs = methodInit.getElements().every(
1738
+ (el) => import_ts_morph10.Node.isStringLiteral(el) && HTTP_VERBS2.has(el.getLiteralValue().toUpperCase())
1739
+ );
1740
+ if (!allVerbs) return false;
1741
+ } else {
1742
+ return false;
1743
+ }
1744
+ const pathProp = obj.getProperty("path");
1745
+ if (!pathProp || !import_ts_morph10.Node.isPropertyAssignment(pathProp)) return false;
1746
+ const pathInit = pathProp.getInitializer();
1747
+ return !!pathInit && import_ts_morph10.Node.isStringLiteral(pathInit);
1748
+ }
1749
+ function getRoutePath(obj) {
1750
+ const pathProp = obj.getProperty("path");
1751
+ if (!pathProp || !import_ts_morph10.Node.isPropertyAssignment(pathProp)) return null;
1752
+ const pathInit = pathProp.getInitializer();
1753
+ if (!pathInit || !import_ts_morph10.Node.isStringLiteral(pathInit)) return null;
1754
+ return pathInit.getLiteralValue();
1755
+ }
1756
+ function findHandlerProperty(routeObj) {
1757
+ const directHandler = routeObj.getProperty("handler");
1758
+ if (directHandler && import_ts_morph10.Node.isPropertyAssignment(directHandler)) {
1759
+ return directHandler;
1760
+ }
1761
+ const optionsProp = routeObj.getProperty("options");
1762
+ if (optionsProp && import_ts_morph10.Node.isPropertyAssignment(optionsProp)) {
1763
+ const optionsInit = optionsProp.getInitializer();
1764
+ if (optionsInit && import_ts_morph10.Node.isObjectLiteralExpression(optionsInit)) {
1765
+ const nestedHandler = optionsInit.getProperty("handler");
1766
+ if (nestedHandler && import_ts_morph10.Node.isPropertyAssignment(nestedHandler)) {
1767
+ return nestedHandler;
1768
+ }
1769
+ }
1770
+ }
1771
+ return null;
1772
+ }
1773
+ function ensureConfigImports(sourceFile, group, srcDir) {
1774
+ const routeFileDir = import_path10.default.dirname(sourceFile.getFilePath());
1775
+ for (const name of [group.baseName, group.prodName]) {
1776
+ const exportName = group.exportNames[name];
1777
+ const absoluteConfigPath = import_path10.default.join(srcDir, name);
1778
+ const rel = import_path10.default.relative(routeFileDir, absoluteConfigPath).replace(/\\/g, "/");
1779
+ const moduleSpecifier = rel.startsWith(".") ? rel : `./${rel}`;
1780
+ const alreadyImported = sourceFile.getImportDeclarations().some(
1781
+ (d) => d.getModuleSpecifierValue() === moduleSpecifier || d.getNamedImports().some((ni) => ni.getName() === exportName)
1782
+ );
1783
+ if (!alreadyImported) {
1784
+ sourceFile.addImportDeclaration({
1785
+ moduleSpecifier,
1786
+ namedImports: [exportName]
1787
+ });
1788
+ }
1789
+ }
1790
+ }
1791
+ function updateRouteHandlers(sourceFiles, group, srcDir, relCwd) {
1792
+ const baseExport = group.exportNames[group.baseName];
1793
+ const prodExport = group.exportNames[group.prodName];
1794
+ const newHandlerText = `async (request, h) => {
1795
+ const config =
1796
+ process.env.NODE_ENV === 'production' ? ${prodExport} : ${baseExport}
1797
+ return h
1798
+ .response(\`window.config = \${JSON.stringify(config)}\`)
1799
+ .type('application/javascript')
1800
+ }`;
1801
+ let replacedCount = 0;
1802
+ for (const sourceFile of sourceFiles) {
1803
+ const filePath = sourceFile.getFilePath();
1804
+ const candidates = sourceFile.getDescendantsOfKind(
1805
+ import_ts_morph10.SyntaxKind.ObjectLiteralExpression
1806
+ );
1807
+ for (const obj of candidates) {
1808
+ if (!isRouteConfig2(obj)) continue;
1809
+ if (getRoutePath(obj) !== group.routePath) continue;
1810
+ const handlerProp = findHandlerProperty(obj);
1811
+ if (!handlerProp) {
1812
+ console.warn(
1813
+ ` [${relCwd(filePath)}] Found route '${group.routePath}' but could not locate handler property \u2014 skipping`
1814
+ );
1815
+ continue;
1816
+ }
1817
+ handlerProp.setInitializer(newHandlerText);
1818
+ ensureConfigImports(sourceFile, group, srcDir);
1819
+ replacedCount++;
1820
+ console.log(
1821
+ ` [${relCwd(filePath)}] Replaced handler for route '${group.routePath}'`
1822
+ );
1823
+ }
1824
+ }
1825
+ return replacedCount;
1826
+ }
1827
+ function resolveConfigChain(configObj, path12) {
1828
+ let current = configObj;
1829
+ for (const key of path12) {
1830
+ if (!import_ts_morph10.Node.isObjectLiteralExpression(current)) return null;
1831
+ const prop = current.getProperty(key);
1832
+ if (!prop || !import_ts_morph10.Node.isPropertyAssignment(prop)) return null;
1833
+ const initNode = prop.getInitializer();
1834
+ if (!initNode) return null;
1835
+ current = initNode;
1836
+ }
1837
+ return current.getText();
1838
+ }
1839
+ async function main10() {
1840
+ const srcDir = import_path10.default.join(getCwd(), "src");
1841
+ const relCwd = (fp) => import_path10.default.relative(getCwd(), fp);
1842
+ console.log("Phase 1: Converting JS config files to TypeScript...\n");
1843
+ let convertedCount = 0;
1844
+ for (const group of CONFIG_GROUPS) {
1845
+ for (const name of [group.baseName, group.prodName]) {
1846
+ if (convertFile(name, group, srcDir)) {
1847
+ convertedCount++;
1848
+ }
1849
+ }
1850
+ }
1851
+ if (convertedCount === 0) {
1852
+ console.log(" No JS config files needed conversion.\n");
1853
+ } else {
1854
+ console.log(`
1855
+ Converted ${convertedCount} file(s).
1856
+ `);
1857
+ }
1858
+ console.log(
1859
+ "Phase 3: Wrapping applicationConfig with defineApplicationConfig...\n"
1860
+ );
1861
+ const appConfigRelPath = "api/application/application-config.ts";
1862
+ const appConfigAbsPath = import_path10.default.join(srcDir, appConfigRelPath);
1863
+ if (!fs.existsSync(appConfigAbsPath)) {
1864
+ console.log(` Skipping Phase 3 \u2014 ${appConfigRelPath} not found in src/
1865
+ `);
1866
+ } else {
1867
+ const appConfigProject = new import_ts_morph10.Project({
1868
+ tsConfigFilePath: import_path10.default.resolve(srcDir, "../tsconfig.json"),
1869
+ skipAddingFilesFromTsConfig: false
1870
+ });
1871
+ const appConfigFile = appConfigProject.getSourceFile(appConfigAbsPath) ?? appConfigProject.addSourceFileAtPath(appConfigAbsPath);
1872
+ let wrapped = false;
1873
+ for (const varDecl of appConfigFile.getVariableDeclarations()) {
1874
+ if (varDecl.getName() !== "applicationConfig") continue;
1875
+ const init = varDecl.getInitializer();
1876
+ if (!init || !import_ts_morph10.Node.isObjectLiteralExpression(init)) continue;
1877
+ const propsToRemove = init.getProperties().filter((prop) => {
1878
+ if (!import_ts_morph10.Node.isPropertyAssignment(prop)) return false;
1879
+ const name = prop.getNameNode().getText().replace(/^['"]|['"]$/g, "");
1880
+ return !APPLICATION_CONFIG_VALID_KEYS.has(name);
1881
+ });
1882
+ if (propsToRemove.length > 0) {
1883
+ const filesToSaveAfterInlining = /* @__PURE__ */ new Set();
1884
+ for (const removedProp of propsToRemove) {
1885
+ const key = removedProp.getName();
1886
+ for (const sf of appConfigProject.getSourceFiles()) {
1887
+ if (sf.getFilePath() === appConfigAbsPath) continue;
1888
+ if (!sf.getFilePath().includes("/src/")) continue;
1889
+ if (sf.getFilePath().includes("/node_modules/")) continue;
1890
+ let madeReplacement = true;
1891
+ while (madeReplacement) {
1892
+ madeReplacement = false;
1893
+ for (const identNode of sf.getDescendantsOfKind(
1894
+ import_ts_morph10.SyntaxKind.Identifier
1895
+ )) {
1896
+ if (identNode.getText() !== "applicationConfig") continue;
1897
+ let node = identNode;
1898
+ const accessPath = [];
1899
+ while (true) {
1900
+ const parent = node.getParent();
1901
+ if (!import_ts_morph10.Node.isPropertyAccessExpression(parent)) break;
1902
+ if (parent.getExpression() !== node) break;
1903
+ accessPath.push(parent.getName());
1904
+ node = parent;
1905
+ }
1906
+ if (accessPath.length === 0 || accessPath[0] !== key) continue;
1907
+ const resolvedValue = resolveConfigChain(init, accessPath);
1908
+ if (resolvedValue === null) {
1909
+ console.log(
1910
+ ` Cannot resolve applicationConfig.${accessPath.join(".")} \u2014 skipping inline replacement`
1911
+ );
1912
+ continue;
1913
+ }
1914
+ node.replaceWithText(resolvedValue);
1915
+ console.log(
1916
+ ` Inlined applicationConfig.${accessPath.join(".")} \u2192 ${resolvedValue} in ${import_path10.default.relative(getCwd(), sf.getFilePath())}`
1917
+ );
1918
+ filesToSaveAfterInlining.add(sf);
1919
+ madeReplacement = true;
1920
+ break;
1921
+ }
1922
+ }
1923
+ }
1924
+ }
1925
+ for (const sf of Array.from(filesToSaveAfterInlining)) {
1926
+ await sf.save();
1927
+ console.log(
1928
+ ` Saved (inlined): ${import_path10.default.relative(getCwd(), sf.getFilePath())}`
1929
+ );
1930
+ }
1931
+ for (const prop of [...propsToRemove].reverse()) {
1932
+ const propName = prop.getName();
1933
+ console.log(
1934
+ ` Removing unknown key '${propName}' from applicationConfig (not in ApplicationConfig schema)`
1935
+ );
1936
+ prop.remove();
1937
+ }
1938
+ }
1939
+ varDecl.setInitializer(`defineApplicationConfig(${init.getText()})`);
1940
+ const TOOLKIT_MODULE = "@opencrvs/toolkit/application-config";
1941
+ const existing = appConfigFile.getImportDeclaration(
1942
+ (d) => d.getModuleSpecifierValue() === TOOLKIT_MODULE
1943
+ );
1944
+ if (existing) {
1945
+ const names = new Set(
1946
+ existing.getNamedImports().map((ni) => ni.getName())
1947
+ );
1948
+ if (!names.has("defineApplicationConfig")) {
1949
+ existing.addNamedImport("defineApplicationConfig");
1950
+ }
1951
+ } else {
1952
+ appConfigFile.addImportDeclaration({
1953
+ moduleSpecifier: TOOLKIT_MODULE,
1954
+ namedImports: ["defineApplicationConfig"]
1955
+ });
1956
+ }
1957
+ wrapped = true;
1958
+ console.log(
1959
+ ` Wrapped applicationConfig with defineApplicationConfig in ${appConfigRelPath}`
1960
+ );
1961
+ break;
1962
+ }
1963
+ if (!wrapped) {
1964
+ console.log(
1965
+ ` Skipping Phase 3 \u2014 applicationConfig plain object not found (already wrapped?)
1966
+ `
1967
+ );
1968
+ } else {
1969
+ await appConfigFile.save();
1970
+ console.log(` Saved: ${appConfigRelPath}
1971
+ `);
1972
+ }
1973
+ }
1974
+ console.log("Phase 2: Updating Hapi route handlers...\n");
1975
+ const project = new import_ts_morph10.Project({
1976
+ tsConfigFilePath: import_path10.default.resolve(srcDir, "../tsconfig.json"),
1977
+ skipAddingFilesFromTsConfig: false
1978
+ });
1979
+ const sourceFiles = project.getSourceFiles().filter((sf) => {
1980
+ const fp = sf.getFilePath();
1981
+ return fp.includes("/src/") && !fp.includes("/node_modules/");
1982
+ });
1983
+ console.log(` Analysing ${sourceFiles.length} source file(s).
1984
+ `);
1985
+ let totalReplaced = 0;
1986
+ for (const group of CONFIG_GROUPS) {
1987
+ totalReplaced += updateRouteHandlers(sourceFiles, group, srcDir, relCwd);
1988
+ }
1989
+ if (totalReplaced === 0) {
1990
+ console.log(" No route handlers matched \u2014 nothing to update in Phase 2.\n");
1991
+ }
1992
+ const modified = sourceFiles.filter((sf) => sf.wasForgotten() === false);
1993
+ const toSave = modified.filter(
1994
+ (sf) => sf.getDescendantsOfKind(import_ts_morph10.SyntaxKind.ObjectLiteralExpression).length > 0
1995
+ );
1996
+ let savedCount = 0;
1997
+ for (const sf of project.getSourceFiles()) {
1998
+ if (sf.isSaved()) continue;
1999
+ await sf.save();
2000
+ console.log(` Saved: ${relCwd(sf.getFilePath())}`);
2001
+ savedCount++;
2002
+ }
2003
+ if (savedCount === 0 && totalReplaced === 0) {
2004
+ console.log("Nothing was changed.");
2005
+ return;
2006
+ }
2007
+ console.log(
2008
+ `
2009
+ Done. Converted ${convertedCount} config file(s), replaced ${totalReplaced} route handler(s).`
2010
+ );
2011
+ }
2012
+
2013
+ // src/migrations/v2.0/migrate-scopes.ts
2014
+ var import_ts_morph11 = require("ts-morph");
2015
+ var import_path11 = __toESM(require("path"));
2016
+ var import_commons = require("../commons");
2017
+ var ROLES_FILE_RELATIVE_PATH = "src/data-seeding/roles/roles.ts";
2018
+ var SCOPES_PROPERTY_NAME = "scopes";
2019
+ var TOOLKIT_SCOPES_MODULE = "@opencrvs/toolkit/scopes";
2020
+ var DEFINE_SCOPES_IMPORT_NAME = "defineScopes";
2021
+ var DEFINE_ROLES_IMPORT_NAME = "defineRoles";
2022
+ function resolveScopeKeyFromElementAccess(element) {
2023
+ if (import_ts_morph11.Node.isPropertyAccessExpression(element) && element.getExpression().getText() === "SCOPES") {
2024
+ return element.getName();
2025
+ }
2026
+ if (import_ts_morph11.Node.isElementAccessExpression(element) && element.getExpression().getText() === "SCOPES") {
2027
+ const argumentExpression = element.getArgumentExpression();
2028
+ if (argumentExpression && (import_ts_morph11.Node.isStringLiteral(argumentExpression) || import_ts_morph11.Node.isNoSubstitutionTemplateLiteral(argumentExpression))) {
2029
+ return argumentExpression.getLiteralValue();
2030
+ }
2031
+ }
2032
+ return null;
2033
+ }
2034
+ function resolveLegacyScopeFromElement(element) {
2035
+ if (import_ts_morph11.Node.isStringLiteral(element) || import_ts_morph11.Node.isNoSubstitutionTemplateLiteral(element)) {
2036
+ return element.getLiteralValue();
2037
+ }
2038
+ const scopeKey = resolveScopeKeyFromElementAccess(element);
2039
+ if (scopeKey) {
2040
+ const scopeValue = import_commons.SCOPES[scopeKey];
2041
+ return typeof scopeValue === "string" ? scopeValue : null;
2042
+ }
2043
+ const expressionType = element.getType();
2044
+ if (expressionType.isStringLiteral()) {
2045
+ const literalValue = expressionType.getLiteralValue();
2046
+ return typeof literalValue === "string" ? literalValue : null;
2047
+ }
2048
+ return null;
2049
+ }
2050
+ function migrateScopesArrays(rolesFilePath, project) {
2051
+ const sourceFile = project.getSourceFile(rolesFilePath);
2052
+ if (!sourceFile) return { migratedCount: 0, removedCount: 0 };
2053
+ let migratedCount = 0;
2054
+ let removedCount = 0;
2055
+ const scopesProperties = sourceFile.getDescendantsOfKind(import_ts_morph11.SyntaxKind.PropertyAssignment).filter((prop) => prop.getName() === SCOPES_PROPERTY_NAME);
2056
+ for (const scopesProp of scopesProperties) {
2057
+ const initializer = scopesProp.getInitializer();
2058
+ if (!initializer || !import_ts_morph11.Node.isArrayLiteralExpression(initializer)) continue;
2059
+ const elements = initializer.getElements();
2060
+ for (let index = elements.length - 1; index >= 0; index--) {
2061
+ const element = elements[index];
2062
+ if (!import_ts_morph11.Node.isExpression(element)) continue;
2063
+ const scopeKey = resolveScopeKeyFromElementAccess(element);
2064
+ if (scopeKey && !(scopeKey in import_commons.SCOPES)) {
2065
+ console.warn(
2066
+ ` [${import_path11.default.relative(getCwd(), rolesFilePath)}] Removing unknown scope reference: SCOPES.${scopeKey}`
2067
+ );
2068
+ initializer.removeElement(index);
2069
+ removedCount++;
2070
+ continue;
2071
+ }
2072
+ const legacyScope = resolveLegacyScopeFromElement(element);
2073
+ if (!legacyScope) {
2074
+ console.warn(
2075
+ ` [${import_path11.default.relative(getCwd(), rolesFilePath)}] Skipping non-literal scope expression: ${element.getText()}`
2076
+ );
2077
+ continue;
2078
+ }
2079
+ try {
2080
+ const migratedScope = (0, import_commons.legacyScopeToV2Scope)(legacyScope);
2081
+ const scope = (0, import_commons.decodeScope)(migratedScope);
2082
+ if (!scope) {
2083
+ console.warn(
2084
+ ` [${import_path11.default.relative(getCwd(), rolesFilePath)}] Could not decode migrated scope '${migratedScope}'.`
2085
+ );
2086
+ continue;
2087
+ }
2088
+ element.replaceWithText(JSON.stringify(scope));
2089
+ migratedCount++;
2090
+ } catch (error) {
2091
+ console.warn(
2092
+ ` [${import_path11.default.relative(getCwd(), rolesFilePath)}] Could not migrate scope '${legacyScope}': ${error}`
2093
+ );
2094
+ }
2095
+ }
2096
+ }
2097
+ if (removedCount > 0) {
2098
+ console.log(
2099
+ ` Removed ${removedCount} unknown SCOPES reference(s) from '${import_path11.default.relative(getCwd(), rolesFilePath)}'.`
2100
+ );
2101
+ }
2102
+ return { migratedCount, removedCount };
2103
+ }
2104
+ function ensureScopesHelpersImport(rolesFilePath, project) {
2105
+ const sourceFile = project.getSourceFile(rolesFilePath);
2106
+ if (!sourceFile) return false;
2107
+ const existingImport = sourceFile.getImportDeclaration(
2108
+ (decl) => decl.getModuleSpecifierValue() === TOOLKIT_SCOPES_MODULE
2109
+ );
2110
+ let changed = false;
2111
+ if (existingImport) {
2112
+ const hasDefineScopesImport = existingImport.getNamedImports().some((ni) => ni.getName() === DEFINE_SCOPES_IMPORT_NAME);
2113
+ const hasDefineRolesImport = existingImport.getNamedImports().some((ni) => ni.getName() === DEFINE_ROLES_IMPORT_NAME);
2114
+ if (!hasDefineScopesImport) {
2115
+ existingImport.addNamedImport(DEFINE_SCOPES_IMPORT_NAME);
2116
+ changed = true;
2117
+ }
2118
+ if (!hasDefineRolesImport) {
2119
+ existingImport.addNamedImport(DEFINE_ROLES_IMPORT_NAME);
2120
+ changed = true;
2121
+ }
2122
+ const encodeScopeImport = existingImport.getNamedImports().find((ni) => ni.getName() === "encodeScope");
2123
+ if (encodeScopeImport) {
2124
+ encodeScopeImport.remove();
2125
+ changed = true;
2126
+ }
2127
+ return changed;
2128
+ }
2129
+ sourceFile.addImportDeclaration({
2130
+ moduleSpecifier: TOOLKIT_SCOPES_MODULE,
2131
+ namedImports: [DEFINE_SCOPES_IMPORT_NAME, DEFINE_ROLES_IMPORT_NAME]
2132
+ });
2133
+ return true;
2134
+ }
2135
+ function wrapScopesArraysWithDefineScopes(rolesFilePath, project) {
2136
+ const sourceFile = project.getSourceFile(rolesFilePath);
2137
+ if (!sourceFile) return 0;
2138
+ let wrappedCount = 0;
2139
+ const scopesProperties = sourceFile.getDescendantsOfKind(import_ts_morph11.SyntaxKind.PropertyAssignment).filter((prop) => prop.getName() === SCOPES_PROPERTY_NAME);
2140
+ for (const scopesProp of scopesProperties) {
2141
+ const initializer = scopesProp.getInitializer();
2142
+ if (!initializer) continue;
2143
+ if (import_ts_morph11.Node.isCallExpression(initializer) && initializer.getExpression().getText() === DEFINE_SCOPES_IMPORT_NAME) {
2144
+ continue;
2145
+ }
2146
+ if (!import_ts_morph11.Node.isArrayLiteralExpression(initializer)) continue;
2147
+ scopesProp.setInitializer(
2148
+ `${DEFINE_SCOPES_IMPORT_NAME}(${initializer.getText()})`
2149
+ );
2150
+ wrappedCount++;
2151
+ }
2152
+ return wrappedCount;
2153
+ }
2154
+ function wrapRolesWithDefineRoles(rolesFilePath, project) {
2155
+ const sourceFile = project.getSourceFile(rolesFilePath);
2156
+ if (!sourceFile) return false;
2157
+ const rolesDeclaration = sourceFile.getVariableDeclaration("roles");
2158
+ if (!rolesDeclaration) return false;
2159
+ const initializer = rolesDeclaration.getInitializer();
2160
+ if (!initializer) return false;
2161
+ if (import_ts_morph11.Node.isCallExpression(initializer) && initializer.getExpression().getText() === DEFINE_ROLES_IMPORT_NAME) {
2162
+ return false;
2163
+ }
2164
+ if (!import_ts_morph11.Node.isArrayLiteralExpression(initializer)) return false;
2165
+ const typeNode = rolesDeclaration.getTypeNode();
2166
+ if (typeNode?.getText().includes("Role")) {
2167
+ rolesDeclaration.removeType();
2168
+ }
2169
+ rolesDeclaration.setInitializer(
2170
+ `${DEFINE_ROLES_IMPORT_NAME}(${initializer.getText()})`
2171
+ );
2172
+ return true;
2173
+ }
2174
+ function pruneNamedImportIfUnused(sourceFile, moduleSpecifier, importName) {
2175
+ const importDeclaration = sourceFile.getImportDeclaration(
2176
+ (decl) => decl.getModuleSpecifierValue() === moduleSpecifier
2177
+ );
2178
+ if (!importDeclaration) return false;
2179
+ const namedImport = importDeclaration.getNamedImports().find((ni) => ni.getName() === importName);
2180
+ if (!namedImport) return false;
2181
+ const references = sourceFile.getDescendantsOfKind(import_ts_morph11.SyntaxKind.Identifier).filter(
2182
+ (identifier) => identifier.getText() === importName && !import_ts_morph11.Node.isImportSpecifier(identifier.getParent())
2183
+ );
2184
+ if (references.length > 0) {
2185
+ return false;
2186
+ }
2187
+ namedImport.remove();
2188
+ if (importDeclaration.getNamedImports().length === 0 && !importDeclaration.getDefaultImport() && !importDeclaration.getNamespaceImport()) {
2189
+ importDeclaration.remove();
2190
+ }
2191
+ return true;
2192
+ }
2193
+ function removeRoleTypeDefinitionAndUnusedImports(rolesFilePath, project) {
2194
+ const sourceFile = project.getSourceFile(rolesFilePath);
2195
+ if (!sourceFile) return false;
2196
+ let removed = false;
2197
+ const roleTypeAlias = sourceFile.getTypeAlias("Role");
2198
+ if (roleTypeAlias) {
2199
+ roleTypeAlias.remove();
2200
+ removed = true;
2201
+ }
2202
+ const roleInterface = sourceFile.getInterface("Role");
2203
+ if (roleInterface) {
2204
+ roleInterface.remove();
2205
+ removed = true;
2206
+ }
2207
+ const removedScopeImport = pruneNamedImportIfUnused(
2208
+ sourceFile,
2209
+ TOOLKIT_SCOPES_MODULE,
2210
+ "Scope"
2211
+ );
2212
+ const removedMessageDescriptorImport = pruneNamedImportIfUnused(
2213
+ sourceFile,
2214
+ "react-intl",
2215
+ "MessageDescriptor"
2216
+ );
2217
+ removed = removed || removedScopeImport || removedMessageDescriptorImport;
2218
+ return removed;
2219
+ }
2220
+ async function main11() {
2221
+ const cwd2 = getCwd();
2222
+ const srcDir = import_path11.default.join(cwd2, "src");
2223
+ const rolesFilePath = import_path11.default.join(cwd2, ROLES_FILE_RELATIVE_PATH);
2224
+ console.log(`Scanning roles scopes in: ${rolesFilePath}`);
2225
+ const project = new import_ts_morph11.Project({
2226
+ tsConfigFilePath: import_path11.default.resolve(srcDir, "../tsconfig.json"),
2227
+ skipAddingFilesFromTsConfig: false
2228
+ });
2229
+ const sourceFile = project.getSourceFile(rolesFilePath);
2230
+ if (!sourceFile) {
2231
+ console.log(
2232
+ `No roles file found at '${ROLES_FILE_RELATIVE_PATH}'. Nothing to do.`
2233
+ );
2234
+ return;
2235
+ }
2236
+ const importChanged = ensureScopesHelpersImport(rolesFilePath, project);
2237
+ const { migratedCount, removedCount } = migrateScopesArrays(
2238
+ rolesFilePath,
2239
+ project
2240
+ );
2241
+ const wrappedScopesCount = wrapScopesArraysWithDefineScopes(
2242
+ rolesFilePath,
2243
+ project
2244
+ );
2245
+ const wrappedRoles = wrapRolesWithDefineRoles(rolesFilePath, project);
2246
+ const removedRoleType = removeRoleTypeDefinitionAndUnusedImports(
2247
+ rolesFilePath,
2248
+ project
2249
+ );
2250
+ if (migratedCount === 0 && removedCount === 0 && wrappedScopesCount === 0 && !wrappedRoles && !removedRoleType && !importChanged) {
2251
+ console.log("No migratable literal scopes found. Nothing to do.");
2252
+ return;
2253
+ }
2254
+ await sourceFile.save();
2255
+ console.log(
2256
+ `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." : "."}`
2257
+ );
2258
+ }
2259
+
2260
+ // src/migrations/v2.0/remove-deprecated-imports.ts
2261
+ var import_ts_morph12 = require("ts-morph");
2262
+ var import_path12 = __toESM(require("path"));
2263
+ var DEPRECATED_IMPORT = "SCOPES";
2264
+ var TARGET_MODULES = /* @__PURE__ */ new Set([
2265
+ "@opencrvs/toolkit/scopes",
2266
+ "@opencrvs/toolkit"
2267
+ ]);
2268
+ function processFile10(filePath, project) {
2269
+ const sourceFile = project.getSourceFile(filePath);
2270
+ if (!sourceFile) return 0;
2271
+ let removedCount = 0;
2272
+ const importDecls = sourceFile.getImportDeclarations().filter((decl) => TARGET_MODULES.has(decl.getModuleSpecifierValue()));
2273
+ for (const decl of importDecls) {
2274
+ const matchingNamedImports = decl.getNamedImports().filter((ni) => ni.getName() === DEPRECATED_IMPORT);
2275
+ if (matchingNamedImports.length === 0) continue;
2276
+ for (const namedImport of matchingNamedImports) {
2277
+ namedImport.remove();
2278
+ removedCount++;
2279
+ }
2280
+ const hasAnyNamedImportsLeft = decl.getNamedImports().length > 0;
2281
+ const hasDefaultImport = !!decl.getDefaultImport();
2282
+ const hasNamespaceImport = !!decl.getNamespaceImport();
2283
+ if (!hasAnyNamedImportsLeft && !hasDefaultImport && !hasNamespaceImport) {
2284
+ decl.remove();
2285
+ }
2286
+ console.log(
2287
+ ` [${import_path12.default.relative(getCwd(), filePath)}] Removed ${matchingNamedImports.length} deprecated '${DEPRECATED_IMPORT}' import(s) from '${decl.getModuleSpecifierValue()}'`
2288
+ );
2289
+ }
2290
+ return removedCount;
2291
+ }
2292
+ async function main12() {
2293
+ const srcDir = import_path12.default.join(getCwd(), "src");
2294
+ console.log(`Scanning for deprecated imports in: ${srcDir}
2295
+ `);
2296
+ const project = new import_ts_morph12.Project({
2297
+ tsConfigFilePath: import_path12.default.resolve(srcDir, "../tsconfig.json"),
2298
+ skipAddingFilesFromTsConfig: false
2299
+ });
2300
+ const sourceFiles = project.getSourceFiles().filter((sf) => {
2301
+ const fp = sf.getFilePath();
2302
+ return fp.includes("/src/") && !fp.includes("/node_modules/");
2303
+ });
2304
+ console.log(`Found ${sourceFiles.length} source file(s) to analyse.
2305
+ `);
2306
+ let totalRemoved = 0;
2307
+ const modifiedFiles = [];
2308
+ for (const sourceFile of sourceFiles) {
2309
+ const filePath = sourceFile.getFilePath();
2310
+ const removed = processFile10(filePath, project);
2311
+ if (removed > 0) {
2312
+ totalRemoved += removed;
2313
+ modifiedFiles.push(filePath);
2314
+ }
2315
+ }
2316
+ if (modifiedFiles.length === 0) {
2317
+ console.log("No deprecated imports found. Nothing to do.");
2318
+ return;
2319
+ }
2320
+ console.log(`
2321
+ Saving ${modifiedFiles.length} modified file(s)...`);
2322
+ for (const filePath of modifiedFiles) {
2323
+ await project.getSourceFileOrThrow(filePath).save();
2324
+ console.log(` Saved: ${import_path12.default.relative(getCwd(), filePath)}`);
2325
+ }
2326
+ console.log(`
2327
+ Done. Removed ${totalRemoved} deprecated import(s).`);
2328
+ }
2329
+
2330
+ // src/migrations/v2.0/index.ts
2331
+ var cwd;
2332
+ function getCwd() {
2333
+ if (!cwd) {
2334
+ throw new Error("Country config working directory not set.");
2335
+ }
2336
+ return cwd;
2337
+ }
2338
+ async function runUpgrade(ccwd) {
2339
+ if (ccwd) {
2340
+ console.log("Country config working directory:", ccwd);
2341
+ cwd = ccwd;
2342
+ }
2343
+ if (!ccwd) {
2344
+ console.log(
2345
+ "Will use current working directory as country config working directory."
2346
+ );
2347
+ cwd = process.cwd();
2348
+ }
2349
+ await main();
2350
+ await main2();
2351
+ await main3();
2352
+ await main4();
2353
+ await main5();
2354
+ await main6();
2355
+ await main7();
2356
+ await main8();
2357
+ await main9();
2358
+ await main10();
2359
+ await main11();
2360
+ await main12();
2361
+ }