@opencrvs/toolkit 2.0.0-rc.d7cb6e7 → 2.0.0-rc.d8342f1
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.
- package/create-countryconfig/index.js +73 -0
- package/create-countryconfig/package.json +11 -0
- package/dist/application-config/index.js +9 -7
- package/dist/cli.js +1771 -364
- package/dist/commons/api/router.d.ts +55 -54
- package/dist/commons/application-config/index.d.ts +16 -4
- package/dist/commons/conditionals/conditionals.d.ts +3 -3
- package/dist/commons/events/FieldConfig.d.ts +5 -0
- package/dist/commons/events/locations.d.ts +21 -0
- package/dist/commons/events/mocks.test.utils.d.ts +19 -0
- package/dist/commons/events/scopes.d.ts +24 -1
- package/dist/conditionals/index.js +5 -3
- package/dist/events/index.js +60 -3
- package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts.map +1 -1
- package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.js +63 -39
- package/dist/migrations/v2.0/add-resend-invite-notification.d.ts +3 -0
- package/dist/migrations/v2.0/add-resend-invite-notification.d.ts.map +1 -0
- package/dist/migrations/v2.0/add-resend-invite-notification.js +373 -0
- package/dist/migrations/v2.0/checkout-upstream-files.d.ts +19 -0
- package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +1 -1
- package/dist/migrations/v2.0/checkout-upstream-files.js +17 -14
- package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts.map +1 -1
- package/dist/migrations/v2.0/convert-config-files-to-ts.js +4 -5
- package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts.map +1 -1
- package/dist/migrations/v2.0/convert-paragraph-to-heading.js +4 -5
- package/dist/migrations/v2.0/create-events-index.d.ts.map +1 -1
- package/dist/migrations/v2.0/create-events-index.js +1 -2
- package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts +11 -0
- package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts.map +1 -0
- package/dist/migrations/v2.0/delete-infrastructure-directory.js +123 -0
- package/dist/migrations/v2.0/index.d.ts +10 -4
- package/dist/migrations/v2.0/index.d.ts.map +1 -1
- package/dist/migrations/v2.0/index.js +1739 -361
- package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts.map +1 -1
- package/dist/migrations/v2.0/make-built-in-validate-actions-custom.js +95 -7
- package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts +13 -0
- package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts.map +1 -0
- package/dist/migrations/v2.0/merge-infrastructure-directory.js +222 -0
- package/dist/migrations/v2.0/migrate-application-config-url.d.ts +3 -0
- package/dist/migrations/v2.0/migrate-application-config-url.d.ts.map +1 -0
- package/dist/migrations/v2.0/migrate-application-config-url.js +342 -0
- package/dist/migrations/v2.0/migrate-scopes.d.ts.map +1 -1
- package/dist/migrations/v2.0/migrate-scopes.js +6 -7
- package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts.map +1 -1
- package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.js +3 -4
- package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts.map +1 -1
- package/dist/migrations/v2.0/migrate-workqueue-configs.js +143 -63
- package/dist/migrations/v2.0/remove-delete-actions.d.ts.map +1 -1
- package/dist/migrations/v2.0/remove-delete-actions.js +3 -4
- package/dist/migrations/v2.0/remove-demo-scope.d.ts.map +1 -1
- package/dist/migrations/v2.0/remove-demo-scope.js +2 -3
- package/dist/migrations/v2.0/remove-deprecated-imports.d.ts.map +1 -1
- package/dist/migrations/v2.0/remove-deprecated-imports.js +3 -4
- package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts +3 -0
- package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts.map +1 -0
- package/dist/migrations/v2.0/remove-fhir-url-helpers.js +163 -0
- package/dist/migrations/v2.0/remove-hearth-migrations.d.ts.map +1 -1
- package/dist/migrations/v2.0/remove-hearth-migrations.js +1 -2
- package/dist/migrations/v2.0/remove-old-statistics-service.d.ts +3 -0
- package/dist/migrations/v2.0/remove-old-statistics-service.d.ts.map +1 -0
- package/dist/migrations/v2.0/remove-old-statistics-service.js +356 -0
- package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts.map +1 -1
- package/dist/migrations/v2.0/remove-pending-certification-flag.js +3 -4
- package/dist/migrations/v2.0/remove-review-from-register-action.d.ts.map +1 -1
- package/dist/migrations/v2.0/remove-review-from-register-action.js +3 -4
- package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts +3 -0
- package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts.map +1 -0
- package/dist/migrations/v2.0/remove-unused-environment-variables.js +186 -0
- package/dist/migrations/v2.0/rename-api-paths.d.ts.map +1 -1
- package/dist/migrations/v2.0/rename-api-paths.js +3 -4
- package/dist/migrations/v2.0/rename-location-parent-id.d.ts.map +1 -1
- package/dist/migrations/v2.0/rename-location-parent-id.js +3 -4
- package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts.map +1 -1
- package/dist/migrations/v2.0/simplify-analytics-precalculations.js +1 -2
- package/dist/migrations/v2.0/update-package-json.d.ts +3 -0
- package/dist/migrations/v2.0/update-package-json.d.ts.map +1 -0
- package/dist/migrations/v2.0/update-package-json.js +105 -0
- package/dist/notification/index.js +5 -3
- package/dist/scopes/index.d.ts +6 -1
- package/dist/scopes/index.js +5 -3
- package/opencrvs-toolkit-2.0.0-rc.d8342f1.tgz +0 -0
- package/package.json +1 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/opencrvs-toolkit-2.0.0-rc.d7cb6e7.tgz +0 -0
package/dist/cli.js
CHANGED
|
@@ -91,7 +91,7 @@ function processFile(filePath, project) {
|
|
|
91
91
|
if (wasRemoved) {
|
|
92
92
|
removedCount++;
|
|
93
93
|
console.log(
|
|
94
|
-
` [${import_path.default.relative(
|
|
94
|
+
` [${import_path.default.relative(process.cwd(), filePath)}] Removed 'review' from REGISTER action`
|
|
95
95
|
);
|
|
96
96
|
}
|
|
97
97
|
}
|
|
@@ -99,7 +99,7 @@ function processFile(filePath, project) {
|
|
|
99
99
|
return removedCount;
|
|
100
100
|
}
|
|
101
101
|
async function main() {
|
|
102
|
-
const srcDir = import_path.default.join(
|
|
102
|
+
const srcDir = import_path.default.join(process.cwd(), "src");
|
|
103
103
|
console.log(`Scanning for defineConfig calls in: ${srcDir}
|
|
104
104
|
`);
|
|
105
105
|
const project = new import_ts_morph.Project({
|
|
@@ -135,7 +135,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
135
135
|
for (const filePath of modifiedFiles) {
|
|
136
136
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
137
137
|
await sourceFile.save();
|
|
138
|
-
console.log(` Saved: ${import_path.default.relative(
|
|
138
|
+
console.log(` Saved: ${import_path.default.relative(process.cwd(), filePath)}`);
|
|
139
139
|
}
|
|
140
140
|
console.log(
|
|
141
141
|
`
|
|
@@ -178,6 +178,8 @@ function ensureImports(sourceFile) {
|
|
|
178
178
|
var DEFINE_CONFIG_NAME2 = "defineConfig";
|
|
179
179
|
var ACTIONS_PROPERTY_NAME2 = "actions";
|
|
180
180
|
var TYPE_PROPERTY_NAME2 = "type";
|
|
181
|
+
var ID_PROPERTY_NAME = "id";
|
|
182
|
+
var FLAGS_PROPERTY_NAME = "flags";
|
|
181
183
|
var CUSTOM_ACTION_TYPE_PROPERTY_NAME = "customActionType";
|
|
182
184
|
var AUDIT_HISTORY_LABEL_PROPERTY_NAME = "auditHistoryLabel";
|
|
183
185
|
var DEDUPLICATION_PROPERTY_NAME = "deduplication";
|
|
@@ -187,9 +189,12 @@ var FORM_PROPERTY_NAME = "form";
|
|
|
187
189
|
var ACTION_TYPE_ENUM_NAME = "ActionType";
|
|
188
190
|
var VALIDATE_MEMBER_NAME = "VALIDATE";
|
|
189
191
|
var CUSTOM_MEMBER_NAME = "CUSTOM";
|
|
192
|
+
var REGISTER_MEMBER_NAME2 = "REGISTER";
|
|
190
193
|
var VALIDATE_STRING_LITERAL = "VALIDATE";
|
|
191
194
|
var CUSTOM_STRING_LITERAL = "CUSTOM";
|
|
195
|
+
var REGISTER_STRING_LITERAL2 = "REGISTER";
|
|
192
196
|
var VALIDATE_DECLARATION_VALUE = "VALIDATE_DECLARATION";
|
|
197
|
+
var VALIDATED_FLAG_VALUE = "validated";
|
|
193
198
|
function isValidateType(typeInitializer) {
|
|
194
199
|
if (typeInitializer.getKind() === import_ts_morph2.SyntaxKind.PropertyAccessExpression) {
|
|
195
200
|
const propAccess = typeInitializer.asKindOrThrow(
|
|
@@ -313,6 +318,50 @@ function transformValidateActionToCustom(obj, eventType) {
|
|
|
313
318
|
}
|
|
314
319
|
return true;
|
|
315
320
|
}
|
|
321
|
+
function isRegisterAction(action) {
|
|
322
|
+
const typeProperty = action.getProperty(TYPE_PROPERTY_NAME2);
|
|
323
|
+
if (!typeProperty || !import_ts_morph2.Node.isPropertyAssignment(typeProperty)) return false;
|
|
324
|
+
const typeInit = typeProperty.getInitializer();
|
|
325
|
+
if (!typeInit) return false;
|
|
326
|
+
if (import_ts_morph2.Node.isPropertyAccessExpression(typeInit)) {
|
|
327
|
+
const enumExpr = typeInit.getExpression();
|
|
328
|
+
return import_ts_morph2.Node.isIdentifier(enumExpr) && enumExpr.getText() === ACTION_TYPE_ENUM_NAME && typeInit.getName() === REGISTER_MEMBER_NAME2;
|
|
329
|
+
}
|
|
330
|
+
if (import_ts_morph2.Node.isStringLiteral(typeInit)) {
|
|
331
|
+
return typeInit.getLiteralValue() === REGISTER_STRING_LITERAL2;
|
|
332
|
+
}
|
|
333
|
+
return false;
|
|
334
|
+
}
|
|
335
|
+
function arrayHasElementWithId(array3, id) {
|
|
336
|
+
for (const el of array3.getElements()) {
|
|
337
|
+
if (!import_ts_morph2.Node.isObjectLiteralExpression(el)) continue;
|
|
338
|
+
const idProp = el.getProperty(ID_PROPERTY_NAME);
|
|
339
|
+
if (!idProp || !import_ts_morph2.Node.isPropertyAssignment(idProp)) continue;
|
|
340
|
+
const idInit = idProp.getInitializer();
|
|
341
|
+
if (idInit && import_ts_morph2.Node.isStringLiteral(idInit) && idInit.getLiteralValue() === id) {
|
|
342
|
+
return true;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
return false;
|
|
346
|
+
}
|
|
347
|
+
function ensureRegisterRemovesValidatedFlag(action) {
|
|
348
|
+
const entry = `{ id: '${VALIDATED_FLAG_VALUE}', operation: 'remove' }`;
|
|
349
|
+
const flagsProp = action.getProperty(FLAGS_PROPERTY_NAME);
|
|
350
|
+
if (flagsProp && import_ts_morph2.Node.isPropertyAssignment(flagsProp)) {
|
|
351
|
+
const flagsInit = flagsProp.getInitializer();
|
|
352
|
+
if (flagsInit && import_ts_morph2.Node.isArrayLiteralExpression(flagsInit)) {
|
|
353
|
+
if (arrayHasElementWithId(flagsInit, VALIDATED_FLAG_VALUE)) return false;
|
|
354
|
+
flagsInit.addElement(entry);
|
|
355
|
+
return true;
|
|
356
|
+
}
|
|
357
|
+
return false;
|
|
358
|
+
}
|
|
359
|
+
action.addPropertyAssignment({
|
|
360
|
+
name: FLAGS_PROPERTY_NAME,
|
|
361
|
+
initializer: `[${entry}]`
|
|
362
|
+
});
|
|
363
|
+
return true;
|
|
364
|
+
}
|
|
316
365
|
function processFile2(filePath, project) {
|
|
317
366
|
const sourceFile = project.getSourceFile(filePath);
|
|
318
367
|
if (!sourceFile) return 0;
|
|
@@ -338,7 +387,7 @@ function processFile2(filePath, project) {
|
|
|
338
387
|
const eventType = resolveEventType(configArg);
|
|
339
388
|
if (!eventType) {
|
|
340
389
|
console.warn(
|
|
341
|
-
` [${import_path2.default.relative(
|
|
390
|
+
` [${import_path2.default.relative(process.cwd(), configArg.getSourceFile().getFilePath())}] Could not resolve root 'type' from defineConfig \u2014 skipping auditHistoryLabel id generation`
|
|
342
391
|
);
|
|
343
392
|
}
|
|
344
393
|
let fileNeedsImports = false;
|
|
@@ -354,7 +403,7 @@ function processFile2(filePath, project) {
|
|
|
354
403
|
fileNeedsImports = true;
|
|
355
404
|
configHadValidateAction = true;
|
|
356
405
|
console.log(
|
|
357
|
-
` [${import_path2.default.relative(
|
|
406
|
+
` [${import_path2.default.relative(process.cwd(), filePath)}] Transformed VALIDATE action to CUSTOM with customActionType: '${VALIDATE_DECLARATION_VALUE}'`
|
|
358
407
|
);
|
|
359
408
|
}
|
|
360
409
|
}
|
|
@@ -375,9 +424,21 @@ function processFile2(filePath, project) {
|
|
|
375
424
|
]`
|
|
376
425
|
});
|
|
377
426
|
console.log(
|
|
378
|
-
` [${import_path2.default.relative(
|
|
427
|
+
` [${import_path2.default.relative(process.cwd(), filePath)}] Added top-level 'flags' array to defineConfig`
|
|
379
428
|
);
|
|
380
429
|
}
|
|
430
|
+
if (configHadValidateAction) {
|
|
431
|
+
for (const element of actionsInitializer.getElements()) {
|
|
432
|
+
if (!import_ts_morph2.Node.isObjectLiteralExpression(element)) continue;
|
|
433
|
+
if (!isRegisterAction(element)) continue;
|
|
434
|
+
if (ensureRegisterRemovesValidatedFlag(element)) {
|
|
435
|
+
transformedCount++;
|
|
436
|
+
console.log(
|
|
437
|
+
` [${import_path2.default.relative(process.cwd(), filePath)}] Added '${VALIDATED_FLAG_VALUE}' remove-flag to REGISTER action`
|
|
438
|
+
);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
}
|
|
381
442
|
if (fileNeedsImports) {
|
|
382
443
|
ensureImports(sourceFile);
|
|
383
444
|
}
|
|
@@ -385,7 +446,7 @@ function processFile2(filePath, project) {
|
|
|
385
446
|
return transformedCount;
|
|
386
447
|
}
|
|
387
448
|
async function main2() {
|
|
388
|
-
const srcDir = import_path2.default.join(
|
|
449
|
+
const srcDir = import_path2.default.join(process.cwd(), "src");
|
|
389
450
|
console.log(`Scanning for defineConfig calls in: ${srcDir}
|
|
390
451
|
`);
|
|
391
452
|
const project = new import_ts_morph2.Project({
|
|
@@ -420,11 +481,11 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
420
481
|
for (const filePath of modifiedFiles) {
|
|
421
482
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
422
483
|
await sourceFile.save();
|
|
423
|
-
console.log(` Saved: ${import_path2.default.relative(
|
|
484
|
+
console.log(` Saved: ${import_path2.default.relative(process.cwd(), filePath)}`);
|
|
424
485
|
}
|
|
425
486
|
console.log(
|
|
426
487
|
`
|
|
427
|
-
Done.
|
|
488
|
+
Done. Applied ${totalTransformed} change(s): VALIDATE \u2192 CUSTOM (${VALIDATE_DECLARATION_VALUE}) and '${VALIDATED_FLAG_VALUE}' remove-flag on matching REGISTER actions.`
|
|
428
489
|
);
|
|
429
490
|
}
|
|
430
491
|
|
|
@@ -491,14 +552,14 @@ function processFile3(filePath, project) {
|
|
|
491
552
|
actionsInitializer.removeElement(index);
|
|
492
553
|
removedCount++;
|
|
493
554
|
console.log(
|
|
494
|
-
` [${import_path3.default.relative(
|
|
555
|
+
` [${import_path3.default.relative(process.cwd(), filePath)}] Removed DELETE action at index ${index}`
|
|
495
556
|
);
|
|
496
557
|
}
|
|
497
558
|
}
|
|
498
559
|
return removedCount;
|
|
499
560
|
}
|
|
500
561
|
async function main3() {
|
|
501
|
-
const srcDir = import_path3.default.join(
|
|
562
|
+
const srcDir = import_path3.default.join(process.cwd(), "src");
|
|
502
563
|
console.log(`Scanning for defineConfig calls in: ${srcDir}
|
|
503
564
|
`);
|
|
504
565
|
const project = new import_ts_morph3.Project({
|
|
@@ -533,7 +594,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
533
594
|
for (const filePath of modifiedFiles) {
|
|
534
595
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
535
596
|
await sourceFile.save();
|
|
536
|
-
console.log(` Saved: ${import_path3.default.relative(
|
|
597
|
+
console.log(` Saved: ${import_path3.default.relative(process.cwd(), filePath)}`);
|
|
537
598
|
}
|
|
538
599
|
console.log(
|
|
539
600
|
`
|
|
@@ -607,19 +668,19 @@ function processFile4(filePath, project) {
|
|
|
607
668
|
if (result === "converted-to-heading") {
|
|
608
669
|
changedCount++;
|
|
609
670
|
console.log(
|
|
610
|
-
` [${import_path4.default.relative(
|
|
671
|
+
` [${import_path4.default.relative(process.cwd(), filePath)}] Converted PARAGRAPH with heading fontVariant to HEADING`
|
|
611
672
|
);
|
|
612
673
|
} else if (result === "removed-font-variant") {
|
|
613
674
|
changedCount++;
|
|
614
675
|
console.log(
|
|
615
|
-
` [${import_path4.default.relative(
|
|
676
|
+
` [${import_path4.default.relative(process.cwd(), filePath)}] Removed non-heading fontVariant from PARAGRAPH`
|
|
616
677
|
);
|
|
617
678
|
}
|
|
618
679
|
}
|
|
619
680
|
return changedCount;
|
|
620
681
|
}
|
|
621
682
|
async function main4() {
|
|
622
|
-
const srcDir = import_path4.default.join(
|
|
683
|
+
const srcDir = import_path4.default.join(process.cwd(), "src");
|
|
623
684
|
console.log(`Scanning for FieldType.PARAGRAPH fields in: ${srcDir}
|
|
624
685
|
`);
|
|
625
686
|
const project = new import_ts_morph4.Project({
|
|
@@ -653,7 +714,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
653
714
|
for (const filePath of modifiedFiles) {
|
|
654
715
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
655
716
|
await sourceFile.save();
|
|
656
|
-
console.log(` Saved: ${import_path4.default.relative(
|
|
717
|
+
console.log(` Saved: ${import_path4.default.relative(process.cwd(), filePath)}`);
|
|
657
718
|
}
|
|
658
719
|
console.log(`
|
|
659
720
|
Done. Processed ${totalChanged} FieldType.PARAGRAPH field(s).`);
|
|
@@ -667,14 +728,14 @@ var QUERY_PROPERTY_NAME = "query";
|
|
|
667
728
|
var TYPE_PROPERTY_NAME5 = "type";
|
|
668
729
|
var CLAUSES_PROPERTY_NAME = "clauses";
|
|
669
730
|
var STATUS_PROPERTY_NAME = "status";
|
|
670
|
-
var
|
|
731
|
+
var FLAGS_PROPERTY_NAME2 = "flags";
|
|
671
732
|
var TERMS_PROPERTY_NAME = "terms";
|
|
672
733
|
var TERM_PROPERTY_NAME = "term";
|
|
673
734
|
var ANY_OF_PROPERTY_NAME = "anyOf";
|
|
674
735
|
var VALIDATED_STATUS_VALUE = "VALIDATED";
|
|
675
|
-
var
|
|
736
|
+
var VALIDATED_FLAG_VALUE2 = "validated";
|
|
676
737
|
function addValidatedFlag(clause) {
|
|
677
|
-
const flagsProperty = clause.getProperty(
|
|
738
|
+
const flagsProperty = clause.getProperty(FLAGS_PROPERTY_NAME2);
|
|
678
739
|
if (flagsProperty && import_ts_morph5.Node.isPropertyAssignment(flagsProperty)) {
|
|
679
740
|
const flagsInit = flagsProperty.getInitializer();
|
|
680
741
|
if (flagsInit && import_ts_morph5.Node.isObjectLiteralExpression(flagsInit)) {
|
|
@@ -682,19 +743,19 @@ function addValidatedFlag(clause) {
|
|
|
682
743
|
if (anyOfProperty && import_ts_morph5.Node.isPropertyAssignment(anyOfProperty)) {
|
|
683
744
|
const anyOfInit = anyOfProperty.getInitializer();
|
|
684
745
|
if (anyOfInit && import_ts_morph5.Node.isArrayLiteralExpression(anyOfInit)) {
|
|
685
|
-
anyOfInit.addElement(`'${
|
|
746
|
+
anyOfInit.addElement(`'${VALIDATED_FLAG_VALUE2}'`);
|
|
686
747
|
}
|
|
687
748
|
} else {
|
|
688
749
|
flagsInit.addPropertyAssignment({
|
|
689
750
|
name: ANY_OF_PROPERTY_NAME,
|
|
690
|
-
initializer: `['${
|
|
751
|
+
initializer: `['${VALIDATED_FLAG_VALUE2}']`
|
|
691
752
|
});
|
|
692
753
|
}
|
|
693
754
|
}
|
|
694
755
|
} else {
|
|
695
756
|
clause.addPropertyAssignment({
|
|
696
|
-
name:
|
|
697
|
-
initializer: `{ ${ANY_OF_PROPERTY_NAME}: ['${
|
|
757
|
+
name: FLAGS_PROPERTY_NAME2,
|
|
758
|
+
initializer: `{ ${ANY_OF_PROPERTY_NAME}: ['${VALIDATED_FLAG_VALUE2}'] }`
|
|
698
759
|
});
|
|
699
760
|
}
|
|
700
761
|
}
|
|
@@ -803,7 +864,7 @@ function processFile5(filePath, project) {
|
|
|
803
864
|
if (changed > 0) {
|
|
804
865
|
migratedCount += changed;
|
|
805
866
|
console.log(
|
|
806
|
-
` [${import_path5.default.relative(
|
|
867
|
+
` [${import_path5.default.relative(process.cwd(), filePath)}] Migrated ${changed} clause(s): VALIDATED status \u2192 flags.anyOf`
|
|
807
868
|
);
|
|
808
869
|
}
|
|
809
870
|
}
|
|
@@ -811,7 +872,7 @@ function processFile5(filePath, project) {
|
|
|
811
872
|
return migratedCount;
|
|
812
873
|
}
|
|
813
874
|
async function main5() {
|
|
814
|
-
const srcDir = import_path5.default.join(
|
|
875
|
+
const srcDir = import_path5.default.join(process.cwd(), "src");
|
|
815
876
|
console.log(`Scanning for defineWorkqueues calls in: ${srcDir}
|
|
816
877
|
`);
|
|
817
878
|
const project = new import_ts_morph5.Project({
|
|
@@ -845,7 +906,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
845
906
|
for (const filePath of modifiedFiles) {
|
|
846
907
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
847
908
|
await sourceFile.save();
|
|
848
|
-
console.log(` Saved: ${import_path5.default.relative(
|
|
909
|
+
console.log(` Saved: ${import_path5.default.relative(process.cwd(), filePath)}`);
|
|
849
910
|
}
|
|
850
911
|
console.log(
|
|
851
912
|
`
|
|
@@ -860,23 +921,26 @@ var DEFINE_CONFIG_NAME4 = "defineConfig";
|
|
|
860
921
|
var DEFINE_WORKQUEUES_NAME2 = "defineWorkqueues";
|
|
861
922
|
var ACTIONS_PROPERTY_NAME4 = "actions";
|
|
862
923
|
var ACTION_PROPERTY_NAME = "action";
|
|
863
|
-
var
|
|
924
|
+
var FLAGS_PROPERTY_NAME3 = "flags";
|
|
864
925
|
var QUERY_PROPERTY_NAME2 = "query";
|
|
865
926
|
var TYPE_PROPERTY_NAME6 = "type";
|
|
927
|
+
var ID_PROPERTY_NAME2 = "id";
|
|
866
928
|
var CLAUSES_PROPERTY_NAME2 = "clauses";
|
|
867
929
|
var ANY_OF_PROPERTY_NAME2 = "anyOf";
|
|
868
930
|
var FLAG_ID = "pending-first-certificate-issuance";
|
|
869
931
|
var REGISTER_TYPE = "REGISTER";
|
|
870
932
|
var PRINT_CERTIFICATE_TYPE = "PRINT_CERTIFICATE";
|
|
871
|
-
|
|
933
|
+
function flagDefinitionInitializer(eventType) {
|
|
934
|
+
return `{
|
|
872
935
|
id: '${FLAG_ID}',
|
|
873
936
|
label: {
|
|
874
|
-
id: 'event.
|
|
937
|
+
id: 'event.${eventType}.flag.${FLAG_ID}',
|
|
875
938
|
defaultMessage: 'Pending first certificate issuance',
|
|
876
939
|
description: 'Flag label for first certificate issuance'
|
|
877
940
|
},
|
|
878
941
|
requiresAction: true
|
|
879
942
|
}`;
|
|
943
|
+
}
|
|
880
944
|
function isActionOfType(obj, typeName) {
|
|
881
945
|
const typeProperty = obj.getProperty(TYPE_PROPERTY_NAME6);
|
|
882
946
|
if (!typeProperty || !import_ts_morph6.Node.isPropertyAssignment(typeProperty)) return false;
|
|
@@ -890,18 +954,20 @@ function isActionOfType(obj, typeName) {
|
|
|
890
954
|
}
|
|
891
955
|
return false;
|
|
892
956
|
}
|
|
893
|
-
function
|
|
894
|
-
const
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
957
|
+
function getEventType(configArg) {
|
|
958
|
+
for (const propName of [TYPE_PROPERTY_NAME6, ID_PROPERTY_NAME2]) {
|
|
959
|
+
const prop = configArg.getProperty(propName);
|
|
960
|
+
if (!prop || !import_ts_morph6.Node.isPropertyAssignment(prop)) continue;
|
|
961
|
+
const initializer = prop.getInitializer();
|
|
962
|
+
if (!initializer) continue;
|
|
963
|
+
if (import_ts_morph6.Node.isStringLiteral(initializer)) {
|
|
964
|
+
return initializer.getLiteralValue().toLowerCase();
|
|
965
|
+
}
|
|
966
|
+
if (import_ts_morph6.Node.isPropertyAccessExpression(initializer)) {
|
|
967
|
+
return initializer.getName().toLowerCase();
|
|
968
|
+
}
|
|
903
969
|
}
|
|
904
|
-
return
|
|
970
|
+
return null;
|
|
905
971
|
}
|
|
906
972
|
function hasElementWithId(array3, id) {
|
|
907
973
|
for (const el of array3.getElements()) {
|
|
@@ -915,27 +981,28 @@ function hasElementWithId(array3, id) {
|
|
|
915
981
|
}
|
|
916
982
|
return false;
|
|
917
983
|
}
|
|
918
|
-
function ensureTopLevelFlagDefinition(configArg) {
|
|
919
|
-
const
|
|
984
|
+
function ensureTopLevelFlagDefinition(configArg, eventType) {
|
|
985
|
+
const initializer = flagDefinitionInitializer(eventType);
|
|
986
|
+
const flagsProp = configArg.getProperty(FLAGS_PROPERTY_NAME3);
|
|
920
987
|
if (flagsProp && import_ts_morph6.Node.isPropertyAssignment(flagsProp)) {
|
|
921
988
|
const flagsInit = flagsProp.getInitializer();
|
|
922
989
|
if (flagsInit && import_ts_morph6.Node.isArrayLiteralExpression(flagsInit)) {
|
|
923
990
|
if (hasElementWithId(flagsInit, FLAG_ID)) return false;
|
|
924
|
-
flagsInit.addElement(
|
|
991
|
+
flagsInit.addElement(initializer);
|
|
925
992
|
return true;
|
|
926
993
|
}
|
|
927
994
|
return false;
|
|
928
995
|
}
|
|
929
996
|
configArg.addPropertyAssignment({
|
|
930
|
-
name:
|
|
997
|
+
name: FLAGS_PROPERTY_NAME3,
|
|
931
998
|
initializer: `[
|
|
932
|
-
${
|
|
999
|
+
${initializer}
|
|
933
1000
|
]`
|
|
934
1001
|
});
|
|
935
1002
|
return true;
|
|
936
1003
|
}
|
|
937
1004
|
function ensureActionOperationFlag(action, operation) {
|
|
938
|
-
const flagsProp = action.getProperty(
|
|
1005
|
+
const flagsProp = action.getProperty(FLAGS_PROPERTY_NAME3);
|
|
939
1006
|
const entry = `{ id: '${FLAG_ID}', operation: '${operation}' }`;
|
|
940
1007
|
if (flagsProp && import_ts_morph6.Node.isPropertyAssignment(flagsProp)) {
|
|
941
1008
|
const flagsInit = flagsProp.getInitializer();
|
|
@@ -947,16 +1014,18 @@ function ensureActionOperationFlag(action, operation) {
|
|
|
947
1014
|
return false;
|
|
948
1015
|
}
|
|
949
1016
|
action.addPropertyAssignment({
|
|
950
|
-
name:
|
|
1017
|
+
name: FLAGS_PROPERTY_NAME3,
|
|
951
1018
|
initializer: `[${entry}]`
|
|
952
1019
|
});
|
|
953
1020
|
return true;
|
|
954
1021
|
}
|
|
955
|
-
function
|
|
1022
|
+
function processConfig(configArg, eventType, relPath) {
|
|
956
1023
|
let changes = 0;
|
|
957
|
-
if (ensureTopLevelFlagDefinition(configArg)) {
|
|
1024
|
+
if (ensureTopLevelFlagDefinition(configArg, eventType)) {
|
|
958
1025
|
changes++;
|
|
959
|
-
console.log(
|
|
1026
|
+
console.log(
|
|
1027
|
+
` [${relPath}] (${eventType}) Added '${FLAG_ID}' to top-level flags`
|
|
1028
|
+
);
|
|
960
1029
|
}
|
|
961
1030
|
const actionsProp = configArg.getProperty(ACTIONS_PROPERTY_NAME4);
|
|
962
1031
|
if (!actionsProp || !import_ts_morph6.Node.isPropertyAssignment(actionsProp)) return changes;
|
|
@@ -970,7 +1039,7 @@ function processBirthConfig(configArg, relPath) {
|
|
|
970
1039
|
if (ensureActionOperationFlag(element, "add")) {
|
|
971
1040
|
changes++;
|
|
972
1041
|
console.log(
|
|
973
|
-
` [${relPath}] Added '${FLAG_ID}' add-flag to REGISTER action`
|
|
1042
|
+
` [${relPath}] (${eventType}) Added '${FLAG_ID}' add-flag to REGISTER action`
|
|
974
1043
|
);
|
|
975
1044
|
}
|
|
976
1045
|
}
|
|
@@ -978,7 +1047,7 @@ function processBirthConfig(configArg, relPath) {
|
|
|
978
1047
|
if (ensureActionOperationFlag(element, "remove")) {
|
|
979
1048
|
changes++;
|
|
980
1049
|
console.log(
|
|
981
|
-
` [${relPath}] Added '${FLAG_ID}' remove-flag to PRINT_CERTIFICATE action`
|
|
1050
|
+
` [${relPath}] (${eventType}) Added '${FLAG_ID}' remove-flag to PRINT_CERTIFICATE action`
|
|
982
1051
|
);
|
|
983
1052
|
}
|
|
984
1053
|
}
|
|
@@ -1007,7 +1076,7 @@ function hasPrintCertificateAction(workqueue) {
|
|
|
1007
1076
|
return false;
|
|
1008
1077
|
}
|
|
1009
1078
|
function addFlagToQueryClause(clause) {
|
|
1010
|
-
const flagsProp = clause.getProperty(
|
|
1079
|
+
const flagsProp = clause.getProperty(FLAGS_PROPERTY_NAME3);
|
|
1011
1080
|
if (flagsProp && import_ts_morph6.Node.isPropertyAssignment(flagsProp)) {
|
|
1012
1081
|
const flagsInit = flagsProp.getInitializer();
|
|
1013
1082
|
if (flagsInit && import_ts_morph6.Node.isObjectLiteralExpression(flagsInit)) {
|
|
@@ -1032,7 +1101,7 @@ function addFlagToQueryClause(clause) {
|
|
|
1032
1101
|
}
|
|
1033
1102
|
} else {
|
|
1034
1103
|
clause.addPropertyAssignment({
|
|
1035
|
-
name:
|
|
1104
|
+
name: FLAGS_PROPERTY_NAME3,
|
|
1036
1105
|
initializer: `{ ${ANY_OF_PROPERTY_NAME2}: ['${FLAG_ID}'] }`
|
|
1037
1106
|
});
|
|
1038
1107
|
return true;
|
|
@@ -1063,7 +1132,7 @@ function processFile6(filePath, project) {
|
|
|
1063
1132
|
const sourceFile = project.getSourceFile(filePath);
|
|
1064
1133
|
if (!sourceFile) return 0;
|
|
1065
1134
|
let totalChanges = 0;
|
|
1066
|
-
const relPath = import_path6.default.relative(
|
|
1135
|
+
const relPath = import_path6.default.relative(process.cwd(), filePath);
|
|
1067
1136
|
const callExpressions = sourceFile.getDescendantsOfKind(
|
|
1068
1137
|
import_ts_morph6.SyntaxKind.CallExpression
|
|
1069
1138
|
);
|
|
@@ -1076,8 +1145,9 @@ function processFile6(filePath, project) {
|
|
|
1076
1145
|
if (args2.length === 0) continue;
|
|
1077
1146
|
const configArg = args2[0];
|
|
1078
1147
|
if (!import_ts_morph6.Node.isObjectLiteralExpression(configArg)) continue;
|
|
1079
|
-
|
|
1080
|
-
|
|
1148
|
+
const eventType = getEventType(configArg);
|
|
1149
|
+
if (!eventType) continue;
|
|
1150
|
+
totalChanges += processConfig(configArg, eventType, relPath);
|
|
1081
1151
|
}
|
|
1082
1152
|
if (calleeName === DEFINE_WORKQUEUES_NAME2) {
|
|
1083
1153
|
const args2 = call.getArguments();
|
|
@@ -1104,9 +1174,9 @@ function processFile6(filePath, project) {
|
|
|
1104
1174
|
return totalChanges;
|
|
1105
1175
|
}
|
|
1106
1176
|
async function main6() {
|
|
1107
|
-
const srcDir = import_path6.default.join(
|
|
1177
|
+
const srcDir = import_path6.default.join(process.cwd(), "src");
|
|
1108
1178
|
console.log(
|
|
1109
|
-
`Scanning for
|
|
1179
|
+
`Scanning for defineConfig and PRINT_CERTIFICATE workqueues in: ${srcDir}
|
|
1110
1180
|
`
|
|
1111
1181
|
);
|
|
1112
1182
|
const project = new import_ts_morph6.Project({
|
|
@@ -1131,7 +1201,7 @@ async function main6() {
|
|
|
1131
1201
|
}
|
|
1132
1202
|
if (modifiedFiles.length === 0) {
|
|
1133
1203
|
console.log(
|
|
1134
|
-
"No
|
|
1204
|
+
"No event configs or PRINT_CERTIFICATE workqueues found. Nothing to do."
|
|
1135
1205
|
);
|
|
1136
1206
|
return;
|
|
1137
1207
|
}
|
|
@@ -1140,7 +1210,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
1140
1210
|
for (const filePath of modifiedFiles) {
|
|
1141
1211
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
1142
1212
|
await sourceFile.save();
|
|
1143
|
-
console.log(` Saved: ${import_path6.default.relative(
|
|
1213
|
+
console.log(` Saved: ${import_path6.default.relative(process.cwd(), filePath)}`);
|
|
1144
1214
|
}
|
|
1145
1215
|
console.log(
|
|
1146
1216
|
`
|
|
@@ -1177,14 +1247,14 @@ function processFile7(filePath, project) {
|
|
|
1177
1247
|
array3.removeElement(index);
|
|
1178
1248
|
removedCount++;
|
|
1179
1249
|
console.log(
|
|
1180
|
-
` [${import_path7.default.relative(
|
|
1250
|
+
` [${import_path7.default.relative(process.cwd(), filePath)}] Removed InherentFlags.PENDING_CERTIFICATION from array`
|
|
1181
1251
|
);
|
|
1182
1252
|
}
|
|
1183
1253
|
}
|
|
1184
1254
|
return removedCount;
|
|
1185
1255
|
}
|
|
1186
1256
|
async function main7() {
|
|
1187
|
-
const srcDir = import_path7.default.join(
|
|
1257
|
+
const srcDir = import_path7.default.join(process.cwd(), "src");
|
|
1188
1258
|
console.log(
|
|
1189
1259
|
`Scanning for InherentFlags.PENDING_CERTIFICATION array elements in: ${srcDir}
|
|
1190
1260
|
`
|
|
@@ -1220,7 +1290,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
1220
1290
|
for (const filePath of modifiedFiles) {
|
|
1221
1291
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
1222
1292
|
await sourceFile.save();
|
|
1223
|
-
console.log(` Saved: ${import_path7.default.relative(
|
|
1293
|
+
console.log(` Saved: ${import_path7.default.relative(process.cwd(), filePath)}`);
|
|
1224
1294
|
}
|
|
1225
1295
|
console.log(
|
|
1226
1296
|
`
|
|
@@ -1278,13 +1348,13 @@ function processFile8(filePath, project) {
|
|
|
1278
1348
|
propAccess.getNameNode().replaceWithText(NEW_PROPERTY_NAME);
|
|
1279
1349
|
renamedCount++;
|
|
1280
1350
|
console.log(
|
|
1281
|
-
` [${import_path8.default.relative(
|
|
1351
|
+
` [${import_path8.default.relative(process.cwd(), filePath)}] Renamed Location.${OLD_PROPERTY_NAME} \u2192 Location.${NEW_PROPERTY_NAME}`
|
|
1282
1352
|
);
|
|
1283
1353
|
}
|
|
1284
1354
|
return renamedCount;
|
|
1285
1355
|
}
|
|
1286
1356
|
async function main8() {
|
|
1287
|
-
const srcDir = import_path8.default.join(
|
|
1357
|
+
const srcDir = import_path8.default.join(process.cwd(), "src");
|
|
1288
1358
|
console.log(
|
|
1289
1359
|
`Scanning for Location.${OLD_PROPERTY_NAME} references in: ${srcDir}
|
|
1290
1360
|
`
|
|
@@ -1320,7 +1390,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
1320
1390
|
for (const filePath of modifiedFiles) {
|
|
1321
1391
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
1322
1392
|
await sourceFile.save();
|
|
1323
|
-
console.log(` Saved: ${import_path8.default.relative(
|
|
1393
|
+
console.log(` Saved: ${import_path8.default.relative(process.cwd(), filePath)}`);
|
|
1324
1394
|
}
|
|
1325
1395
|
console.log(
|
|
1326
1396
|
`
|
|
@@ -1387,7 +1457,7 @@ function processFile9(filePath, project) {
|
|
|
1387
1457
|
const sourceFile = project.getSourceFile(filePath);
|
|
1388
1458
|
if (!sourceFile) return 0;
|
|
1389
1459
|
let renamedCount = 0;
|
|
1390
|
-
const relPath = import_path9.default.relative(
|
|
1460
|
+
const relPath = import_path9.default.relative(process.cwd(), filePath);
|
|
1391
1461
|
const candidates = sourceFile.getDescendantsOfKind(
|
|
1392
1462
|
import_ts_morph9.SyntaxKind.ObjectLiteralExpression
|
|
1393
1463
|
);
|
|
@@ -1402,7 +1472,7 @@ function processFile9(filePath, project) {
|
|
|
1402
1472
|
return renamedCount;
|
|
1403
1473
|
}
|
|
1404
1474
|
async function main9() {
|
|
1405
|
-
const srcDir = import_path9.default.join(
|
|
1475
|
+
const srcDir = import_path9.default.join(process.cwd(), "src");
|
|
1406
1476
|
console.log(`Scanning for Hapi route configs in: ${srcDir}
|
|
1407
1477
|
`);
|
|
1408
1478
|
console.log("Active path renames:");
|
|
@@ -1439,7 +1509,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
1439
1509
|
for (const filePath of modifiedFiles) {
|
|
1440
1510
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
1441
1511
|
await sourceFile.save();
|
|
1442
|
-
console.log(` Saved: ${import_path9.default.relative(
|
|
1512
|
+
console.log(` Saved: ${import_path9.default.relative(process.cwd(), filePath)}`);
|
|
1443
1513
|
}
|
|
1444
1514
|
console.log(`
|
|
1445
1515
|
Done. Renamed ${totalRenamed} route path(s).`);
|
|
@@ -1813,9 +1883,9 @@ function updateRouteHandlers(sourceFiles, group, srcDir, relCwd) {
|
|
|
1813
1883
|
}
|
|
1814
1884
|
return replacedCount;
|
|
1815
1885
|
}
|
|
1816
|
-
function resolveConfigChain(configObj,
|
|
1886
|
+
function resolveConfigChain(configObj, path23) {
|
|
1817
1887
|
let current = configObj;
|
|
1818
|
-
for (const key of
|
|
1888
|
+
for (const key of path23) {
|
|
1819
1889
|
if (!import_ts_morph10.Node.isObjectLiteralExpression(current)) return null;
|
|
1820
1890
|
const prop = current.getProperty(key);
|
|
1821
1891
|
if (!prop || !import_ts_morph10.Node.isPropertyAssignment(prop)) return null;
|
|
@@ -1860,8 +1930,8 @@ function ensureJoinImport(sf) {
|
|
|
1860
1930
|
});
|
|
1861
1931
|
}
|
|
1862
1932
|
async function main10() {
|
|
1863
|
-
const srcDir = import_path10.default.join(
|
|
1864
|
-
const relCwd = (fp) => import_path10.default.relative(
|
|
1933
|
+
const srcDir = import_path10.default.join(process.cwd(), "src");
|
|
1934
|
+
const relCwd = (fp) => import_path10.default.relative(process.cwd(), fp);
|
|
1865
1935
|
console.log("Phase 1: Converting JS config files to TypeScript...\n");
|
|
1866
1936
|
let convertedCount = 0;
|
|
1867
1937
|
for (const group of CONFIG_GROUPS) {
|
|
@@ -1949,7 +2019,7 @@ async function main10() {
|
|
|
1949
2019
|
ensureJoinImport(sf);
|
|
1950
2020
|
}
|
|
1951
2021
|
console.log(
|
|
1952
|
-
` Inlined applicationConfig.${accessPath.join(".")} \u2192 ${adjustedValue} in ${import_path10.default.relative(
|
|
2022
|
+
` Inlined applicationConfig.${accessPath.join(".")} \u2192 ${adjustedValue} in ${import_path10.default.relative(process.cwd(), sf.getFilePath())}`
|
|
1953
2023
|
);
|
|
1954
2024
|
filesToSaveAfterInlining.add(sf);
|
|
1955
2025
|
madeReplacement = true;
|
|
@@ -1961,7 +2031,7 @@ async function main10() {
|
|
|
1961
2031
|
for (const sf of Array.from(filesToSaveAfterInlining)) {
|
|
1962
2032
|
await sf.save();
|
|
1963
2033
|
console.log(
|
|
1964
|
-
` Saved (inlined): ${import_path10.default.relative(
|
|
2034
|
+
` Saved (inlined): ${import_path10.default.relative(process.cwd(), sf.getFilePath())}`
|
|
1965
2035
|
);
|
|
1966
2036
|
}
|
|
1967
2037
|
for (const prop of [...propsToRemove].reverse()) {
|
|
@@ -2226,12 +2296,14 @@ var SystemScopeType = z3.enum([
|
|
|
2226
2296
|
"organisation.read-locations",
|
|
2227
2297
|
"user.read",
|
|
2228
2298
|
"user.create",
|
|
2229
|
-
"user.edit"
|
|
2299
|
+
"user.edit",
|
|
2300
|
+
"user.search"
|
|
2230
2301
|
]);
|
|
2231
2302
|
var UserScopeType = SystemScopeType.extract([
|
|
2232
2303
|
"user.read",
|
|
2233
2304
|
"user.create",
|
|
2234
|
-
"user.edit"
|
|
2305
|
+
"user.edit",
|
|
2306
|
+
"user.search"
|
|
2235
2307
|
]);
|
|
2236
2308
|
var ScopesWithRoleOption = UserScopeType.extract(["user.edit", "user.create"]);
|
|
2237
2309
|
var UserScopeV2 = z3.discriminatedUnion("type", [
|
|
@@ -2240,7 +2312,7 @@ var UserScopeV2 = z3.discriminatedUnion("type", [
|
|
|
2240
2312
|
options: AllUserScopeOptions.optional()
|
|
2241
2313
|
}),
|
|
2242
2314
|
z3.object({
|
|
2243
|
-
type: UserScopeType.extract(["user.read"]),
|
|
2315
|
+
type: UserScopeType.extract(["user.read", "user.search"]),
|
|
2244
2316
|
options: AccessLevelOptions.optional()
|
|
2245
2317
|
})
|
|
2246
2318
|
]);
|
|
@@ -2606,7 +2678,7 @@ function migrateScopesArrays(rolesFilePath, project) {
|
|
|
2606
2678
|
const scopeKey = resolveScopeKeyFromElementAccess(element);
|
|
2607
2679
|
if (scopeKey && !(scopeKey in SCOPES)) {
|
|
2608
2680
|
console.warn(
|
|
2609
|
-
` [${import_path11.default.relative(
|
|
2681
|
+
` [${import_path11.default.relative(process.cwd(), rolesFilePath)}] Removing unknown scope reference: SCOPES.${scopeKey}`
|
|
2610
2682
|
);
|
|
2611
2683
|
initializer.removeElement(index);
|
|
2612
2684
|
removedCount++;
|
|
@@ -2615,7 +2687,7 @@ function migrateScopesArrays(rolesFilePath, project) {
|
|
|
2615
2687
|
const legacyScope = resolveLegacyScopeFromElement(element);
|
|
2616
2688
|
if (!legacyScope) {
|
|
2617
2689
|
console.warn(
|
|
2618
|
-
` [${import_path11.default.relative(
|
|
2690
|
+
` [${import_path11.default.relative(process.cwd(), rolesFilePath)}] Skipping non-literal scope expression: ${element.getText()}`
|
|
2619
2691
|
);
|
|
2620
2692
|
continue;
|
|
2621
2693
|
}
|
|
@@ -2624,7 +2696,7 @@ function migrateScopesArrays(rolesFilePath, project) {
|
|
|
2624
2696
|
const scope = decodeScope(migratedScope);
|
|
2625
2697
|
if (!scope) {
|
|
2626
2698
|
console.warn(
|
|
2627
|
-
` [${import_path11.default.relative(
|
|
2699
|
+
` [${import_path11.default.relative(process.cwd(), rolesFilePath)}] Could not decode migrated scope '${migratedScope}'.`
|
|
2628
2700
|
);
|
|
2629
2701
|
continue;
|
|
2630
2702
|
}
|
|
@@ -2632,14 +2704,14 @@ function migrateScopesArrays(rolesFilePath, project) {
|
|
|
2632
2704
|
migratedCount++;
|
|
2633
2705
|
} catch (error) {
|
|
2634
2706
|
console.warn(
|
|
2635
|
-
` [${import_path11.default.relative(
|
|
2707
|
+
` [${import_path11.default.relative(process.cwd(), rolesFilePath)}] Could not migrate scope '${legacyScope}': ${error}`
|
|
2636
2708
|
);
|
|
2637
2709
|
}
|
|
2638
2710
|
}
|
|
2639
2711
|
}
|
|
2640
2712
|
if (removedCount > 0) {
|
|
2641
2713
|
console.log(
|
|
2642
|
-
` Removed ${removedCount} unknown SCOPES reference(s) from '${import_path11.default.relative(
|
|
2714
|
+
` Removed ${removedCount} unknown SCOPES reference(s) from '${import_path11.default.relative(process.cwd(), rolesFilePath)}'.`
|
|
2643
2715
|
);
|
|
2644
2716
|
}
|
|
2645
2717
|
return { migratedCount, removedCount };
|
|
@@ -2761,9 +2833,9 @@ function removeRoleTypeDefinitionAndUnusedImports(rolesFilePath, project) {
|
|
|
2761
2833
|
return removed;
|
|
2762
2834
|
}
|
|
2763
2835
|
async function main11() {
|
|
2764
|
-
const
|
|
2765
|
-
const srcDir = import_path11.default.join(
|
|
2766
|
-
const rolesFilePath = import_path11.default.join(
|
|
2836
|
+
const cwd = process.cwd();
|
|
2837
|
+
const srcDir = import_path11.default.join(cwd, "src");
|
|
2838
|
+
const rolesFilePath = import_path11.default.join(cwd, ROLES_FILE_RELATIVE_PATH);
|
|
2767
2839
|
console.log(`Scanning roles scopes in: ${rolesFilePath}`);
|
|
2768
2840
|
const project = new import_ts_morph11.Project({
|
|
2769
2841
|
tsConfigFilePath: import_path11.default.resolve(srcDir, "../tsconfig.json"),
|
|
@@ -2827,13 +2899,13 @@ function processFile10(filePath, project) {
|
|
|
2827
2899
|
decl.remove();
|
|
2828
2900
|
}
|
|
2829
2901
|
console.log(
|
|
2830
|
-
` [${import_path12.default.relative(
|
|
2902
|
+
` [${import_path12.default.relative(process.cwd(), filePath)}] Removed ${matchingNamedImports.length} deprecated '${DEPRECATED_IMPORT}' import(s) from '${decl.getModuleSpecifierValue()}'`
|
|
2831
2903
|
);
|
|
2832
2904
|
}
|
|
2833
2905
|
return removedCount;
|
|
2834
2906
|
}
|
|
2835
2907
|
async function main12() {
|
|
2836
|
-
const srcDir = import_path12.default.join(
|
|
2908
|
+
const srcDir = import_path12.default.join(process.cwd(), "src");
|
|
2837
2909
|
console.log(`Scanning for deprecated imports in: ${srcDir}
|
|
2838
2910
|
`);
|
|
2839
2911
|
const project = new import_ts_morph12.Project({
|
|
@@ -2864,274 +2936,1052 @@ async function main12() {
|
|
|
2864
2936
|
Saving ${modifiedFiles.length} modified file(s)...`);
|
|
2865
2937
|
for (const filePath of modifiedFiles) {
|
|
2866
2938
|
await project.getSourceFileOrThrow(filePath).save();
|
|
2867
|
-
console.log(` Saved: ${import_path12.default.relative(
|
|
2939
|
+
console.log(` Saved: ${import_path12.default.relative(process.cwd(), filePath)}`);
|
|
2868
2940
|
}
|
|
2869
2941
|
console.log(`
|
|
2870
2942
|
Done. Removed ${totalRemoved} deprecated import(s).`);
|
|
2871
2943
|
}
|
|
2872
2944
|
|
|
2873
|
-
// src/migrations/v2.0/
|
|
2874
|
-
var import_ts_morph13 = require("ts-morph");
|
|
2945
|
+
// src/migrations/v2.0/remove-unused-environment-variables.ts
|
|
2875
2946
|
var import_path13 = __toESM(require("path"));
|
|
2876
|
-
var
|
|
2877
|
-
var
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
var SLUG_PROPERTY_NAME = "slug";
|
|
2882
|
-
var SUPPORTED_WORKQUEUE_ACTION_TYPES = /* @__PURE__ */ new Set([
|
|
2883
|
-
"READ",
|
|
2884
|
-
"DELETE",
|
|
2885
|
-
"DECLARE",
|
|
2886
|
-
"REGISTER",
|
|
2887
|
-
"EDIT",
|
|
2888
|
-
"REJECT",
|
|
2889
|
-
"MARK_AS_DUPLICATE",
|
|
2890
|
-
"ARCHIVE",
|
|
2891
|
-
"PRINT_CERTIFICATE",
|
|
2892
|
-
"REQUEST_CORRECTION"
|
|
2947
|
+
var import_ts_morph13 = require("ts-morph");
|
|
2948
|
+
var UNUSED_ENV_VARS = /* @__PURE__ */ new Set([
|
|
2949
|
+
"APPLICATION_CONFIG_URL",
|
|
2950
|
+
"FHIR_URL",
|
|
2951
|
+
"CONFIRM_REGISTRATION_URL"
|
|
2893
2952
|
]);
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
const
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
if (import_ts_morph13.Node.isStringLiteral(typeInitializer)) {
|
|
2915
|
-
return typeInitializer.getLiteralValue();
|
|
2916
|
-
}
|
|
2917
|
-
if (import_ts_morph13.Node.isPropertyAccessExpression(typeInitializer)) {
|
|
2918
|
-
return typeInitializer.getName();
|
|
2953
|
+
var ENVIRONMENT_FILE_RELATIVE = "src/environment.ts";
|
|
2954
|
+
var CONSTANTS_FILE_RELATIVE = "src/constants.ts";
|
|
2955
|
+
function cleanEnvironmentFile(project, filePath) {
|
|
2956
|
+
const sourceFile = project.getSourceFile(filePath);
|
|
2957
|
+
if (!sourceFile) return [];
|
|
2958
|
+
const removed = [];
|
|
2959
|
+
const cleanEnvCall = sourceFile.getDescendantsOfKind(import_ts_morph13.SyntaxKind.CallExpression).find((call) => {
|
|
2960
|
+
const expr = call.getExpression();
|
|
2961
|
+
return import_ts_morph13.Node.isIdentifier(expr) && expr.getText() === "cleanEnv";
|
|
2962
|
+
});
|
|
2963
|
+
if (!cleanEnvCall) return removed;
|
|
2964
|
+
const schemaArg = cleanEnvCall.getArguments()[1]?.asKind(import_ts_morph13.SyntaxKind.ObjectLiteralExpression);
|
|
2965
|
+
if (!schemaArg) return removed;
|
|
2966
|
+
for (const name of UNUSED_ENV_VARS) {
|
|
2967
|
+
const prop = schemaArg.getProperty(name);
|
|
2968
|
+
if (!prop) continue;
|
|
2969
|
+
if (prop.isKind(import_ts_morph13.SyntaxKind.PropertyAssignment) || prop.isKind(import_ts_morph13.SyntaxKind.ShorthandPropertyAssignment)) {
|
|
2970
|
+
prop.remove();
|
|
2971
|
+
removed.push(name);
|
|
2972
|
+
}
|
|
2919
2973
|
}
|
|
2920
|
-
return
|
|
2974
|
+
return removed;
|
|
2921
2975
|
}
|
|
2922
|
-
function
|
|
2923
|
-
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
}
|
|
2927
|
-
return !SUPPORTED_WORKQUEUE_ACTION_TYPES.has(typeName);
|
|
2976
|
+
function extractEnvAccess(initText) {
|
|
2977
|
+
if (!initText) return null;
|
|
2978
|
+
const match = /\benv\.([A-Z][A-Z0-9_]*)\b/.exec(initText);
|
|
2979
|
+
return match ? match[1] : null;
|
|
2928
2980
|
}
|
|
2929
|
-
function
|
|
2930
|
-
const
|
|
2931
|
-
if (!
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
conditionalsProperty2.remove();
|
|
2949
|
-
console.log(
|
|
2950
|
-
` [${relPath}] Removed deprecated 'conditionals' from 'action' on workqueue '${workqueueLabel}'`
|
|
2951
|
-
);
|
|
2952
|
-
}
|
|
2953
|
-
if (isUnsupportedActionType(existingActionInitializer)) {
|
|
2954
|
-
existingActionProperty.remove();
|
|
2955
|
-
console.log(
|
|
2956
|
-
` [${relPath}] Removed unsupported 'action' type on workqueue '${workqueueLabel}'`
|
|
2957
|
-
);
|
|
2958
|
-
}
|
|
2981
|
+
function cleanConstantsFile(project, filePath) {
|
|
2982
|
+
const sourceFile = project.getSourceFile(filePath);
|
|
2983
|
+
if (!sourceFile) return [];
|
|
2984
|
+
const removed = [];
|
|
2985
|
+
for (const stmt of [...sourceFile.getVariableStatements()]) {
|
|
2986
|
+
const declarations = [...stmt.getDeclarations()];
|
|
2987
|
+
const declarationsToRemove = declarations.filter((decl) => {
|
|
2988
|
+
const name = decl.getName();
|
|
2989
|
+
const accessedEnvVar = extractEnvAccess(decl.getInitializer()?.getText());
|
|
2990
|
+
return UNUSED_ENV_VARS.has(name) || accessedEnvVar !== null && UNUSED_ENV_VARS.has(accessedEnvVar);
|
|
2991
|
+
});
|
|
2992
|
+
if (declarationsToRemove.length === 0) continue;
|
|
2993
|
+
const namesToRemove = declarationsToRemove.map((decl) => decl.getName());
|
|
2994
|
+
removed.push(...namesToRemove);
|
|
2995
|
+
if (declarationsToRemove.length === declarations.length) {
|
|
2996
|
+
stmt.remove();
|
|
2997
|
+
} else {
|
|
2998
|
+
for (const decl of declarationsToRemove) {
|
|
2999
|
+
decl.remove();
|
|
2959
3000
|
}
|
|
2960
3001
|
}
|
|
2961
|
-
actionsProperty.remove();
|
|
2962
|
-
console.log(
|
|
2963
|
-
` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' (existing 'action' kept)`
|
|
2964
|
-
);
|
|
2965
|
-
return 1;
|
|
2966
3002
|
}
|
|
2967
|
-
|
|
2968
|
-
|
|
3003
|
+
return removed;
|
|
3004
|
+
}
|
|
3005
|
+
async function main13() {
|
|
3006
|
+
const project = new import_ts_morph13.Project({
|
|
3007
|
+
tsConfigFilePath: import_path13.default.resolve(process.cwd(), "tsconfig.json"),
|
|
3008
|
+
skipAddingFilesFromTsConfig: false
|
|
3009
|
+
});
|
|
3010
|
+
console.log(
|
|
3011
|
+
`Removing unused environment variable(s) (${[...UNUSED_ENV_VARS].join(", ")})...
|
|
3012
|
+
`
|
|
2969
3013
|
);
|
|
2970
|
-
|
|
2971
|
-
|
|
3014
|
+
const envFilePath = import_path13.default.join(process.cwd(), ENVIRONMENT_FILE_RELATIVE);
|
|
3015
|
+
const constsFilePath = import_path13.default.join(process.cwd(), CONSTANTS_FILE_RELATIVE);
|
|
3016
|
+
const envRemoved = cleanEnvironmentFile(project, envFilePath);
|
|
3017
|
+
if (envRemoved.length > 0) {
|
|
3018
|
+
await project.getSourceFileOrThrow(envFilePath).save();
|
|
2972
3019
|
console.log(
|
|
2973
|
-
` [${
|
|
3020
|
+
` [${ENVIRONMENT_FILE_RELATIVE}] Removed schema entr${envRemoved.length === 1 ? "y" : "ies"}: ${envRemoved.join(", ")}`
|
|
2974
3021
|
);
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
const droppedCount = actionCandidates.length - 1;
|
|
2979
|
-
console.warn(
|
|
2980
|
-
` [${relPath}] Workqueue '${workqueueLabel}' has ${actionCandidates.length} actions; keeping first as 'action' and dropping ${droppedCount} extra action(s)`
|
|
3022
|
+
} else if (project.getSourceFile(envFilePath)) {
|
|
3023
|
+
console.log(
|
|
3024
|
+
` [${ENVIRONMENT_FILE_RELATIVE}] No matching schema entries \u2014 nothing to remove.`
|
|
2981
3025
|
);
|
|
2982
|
-
}
|
|
2983
|
-
const conditionalsProperty = actionCandidates[0].getProperty(
|
|
2984
|
-
CONDITIONALS_PROPERTY_NAME
|
|
2985
|
-
);
|
|
2986
|
-
if (conditionalsProperty) {
|
|
2987
|
-
conditionalsProperty.remove();
|
|
3026
|
+
} else {
|
|
2988
3027
|
console.log(
|
|
2989
|
-
` [${
|
|
3028
|
+
` [${ENVIRONMENT_FILE_RELATIVE}] File not found \u2014 skipping.`
|
|
2990
3029
|
);
|
|
2991
3030
|
}
|
|
2992
|
-
|
|
2993
|
-
|
|
3031
|
+
const constsRemoved = cleanConstantsFile(project, constsFilePath);
|
|
3032
|
+
if (constsRemoved.length > 0) {
|
|
3033
|
+
await project.getSourceFileOrThrow(constsFilePath).save();
|
|
3034
|
+
console.log(
|
|
3035
|
+
` [${CONSTANTS_FILE_RELATIVE}] Removed declaration(s): ${constsRemoved.join(", ")}`
|
|
3036
|
+
);
|
|
3037
|
+
} else if (project.getSourceFile(constsFilePath)) {
|
|
2994
3038
|
console.log(
|
|
2995
|
-
` [${
|
|
3039
|
+
` [${CONSTANTS_FILE_RELATIVE}] No matching declarations \u2014 nothing to remove.`
|
|
2996
3040
|
);
|
|
2997
|
-
|
|
3041
|
+
} else {
|
|
3042
|
+
console.log(` [${CONSTANTS_FILE_RELATIVE}] File not found \u2014 skipping.`);
|
|
3043
|
+
}
|
|
3044
|
+
if (envRemoved.length === 0 && constsRemoved.length === 0) {
|
|
3045
|
+
console.log("\nNothing to do.");
|
|
3046
|
+
return;
|
|
2998
3047
|
}
|
|
2999
|
-
const firstActionText = actionCandidates[0].getText();
|
|
3000
|
-
workqueue.addPropertyAssignment({
|
|
3001
|
-
name: ACTION_PROPERTY_NAME2,
|
|
3002
|
-
initializer: firstActionText
|
|
3003
|
-
});
|
|
3004
|
-
actionsProperty.remove();
|
|
3005
3048
|
console.log(
|
|
3006
|
-
`
|
|
3049
|
+
`
|
|
3050
|
+
Done. NOTE: usages of these constants elsewhere in 'src/' may now produce TypeScript errors and need manual review.`
|
|
3007
3051
|
);
|
|
3008
|
-
return 1;
|
|
3009
3052
|
}
|
|
3010
|
-
|
|
3011
|
-
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
|
|
3053
|
+
|
|
3054
|
+
// src/migrations/v2.0/remove-fhir-url-helpers.ts
|
|
3055
|
+
var import_path14 = __toESM(require("path"));
|
|
3056
|
+
var import_ts_morph14 = require("ts-morph");
|
|
3057
|
+
var FHIR_IMPORT = "FHIR_URL";
|
|
3058
|
+
var HELPER_NAMES = /* @__PURE__ */ new Set([
|
|
3059
|
+
"getFromFhir",
|
|
3060
|
+
"updateResourceFromHearth",
|
|
3061
|
+
"updateResourceInHearth"
|
|
3062
|
+
]);
|
|
3063
|
+
function removeHelpers(sourceFilePath, project) {
|
|
3064
|
+
const sourceFile = project.getSourceFile(sourceFilePath);
|
|
3065
|
+
if (!sourceFile) {
|
|
3066
|
+
return {
|
|
3067
|
+
removedHelpers: [],
|
|
3068
|
+
removedImportCount: 0,
|
|
3069
|
+
remainingFhirReferences: 0
|
|
3070
|
+
};
|
|
3071
|
+
}
|
|
3072
|
+
const removedHelpers = [];
|
|
3073
|
+
let removedImportCount = 0;
|
|
3074
|
+
for (const fn of sourceFile.getFunctions()) {
|
|
3075
|
+
const name = fn.getName();
|
|
3076
|
+
if (!name || !HELPER_NAMES.has(name)) continue;
|
|
3077
|
+
removedHelpers.push(name);
|
|
3078
|
+
fn.remove();
|
|
3079
|
+
}
|
|
3080
|
+
for (const stmt of [...sourceFile.getVariableStatements()]) {
|
|
3081
|
+
const declarations = [...stmt.getDeclarations()];
|
|
3082
|
+
const toRemove = declarations.filter((decl) => HELPER_NAMES.has(decl.getName()));
|
|
3083
|
+
if (toRemove.length === 0) continue;
|
|
3084
|
+
removedHelpers.push(...toRemove.map((decl) => decl.getName()));
|
|
3085
|
+
if (toRemove.length === declarations.length) {
|
|
3086
|
+
stmt.remove();
|
|
3087
|
+
} else {
|
|
3088
|
+
for (const decl of toRemove) decl.remove();
|
|
3022
3089
|
}
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
const
|
|
3026
|
-
if (
|
|
3027
|
-
for (const
|
|
3028
|
-
|
|
3029
|
-
|
|
3090
|
+
}
|
|
3091
|
+
for (const decl of sourceFile.getImportDeclarations()) {
|
|
3092
|
+
const matches = decl.getNamedImports().filter((ni) => ni.getName() === FHIR_IMPORT);
|
|
3093
|
+
if (matches.length === 0) continue;
|
|
3094
|
+
for (const named of matches) {
|
|
3095
|
+
named.remove();
|
|
3096
|
+
removedImportCount++;
|
|
3097
|
+
}
|
|
3098
|
+
const hasAnyNamedImportsLeft = decl.getNamedImports().length > 0;
|
|
3099
|
+
const hasDefaultImport = !!decl.getDefaultImport();
|
|
3100
|
+
const hasNamespaceImport = !!decl.getNamespaceImport();
|
|
3101
|
+
if (!hasAnyNamedImportsLeft && !hasDefaultImport && !hasNamespaceImport) {
|
|
3102
|
+
decl.remove();
|
|
3030
3103
|
}
|
|
3031
3104
|
}
|
|
3032
|
-
|
|
3105
|
+
const remainingFhirReferences = sourceFile.getDescendantsOfKind(import_ts_morph14.SyntaxKind.Identifier).filter((id) => id.getText() === FHIR_IMPORT).filter((id) => !id.getFirstAncestorByKind(import_ts_morph14.SyntaxKind.ImportDeclaration)).length;
|
|
3106
|
+
return { removedHelpers, removedImportCount, remainingFhirReferences };
|
|
3033
3107
|
}
|
|
3034
|
-
async function
|
|
3035
|
-
const
|
|
3036
|
-
|
|
3037
|
-
`);
|
|
3038
|
-
const project = new import_ts_morph13.Project({
|
|
3039
|
-
tsConfigFilePath: import_path13.default.resolve(srcDir, "../tsconfig.json"),
|
|
3108
|
+
async function main14() {
|
|
3109
|
+
const project = new import_ts_morph14.Project({
|
|
3110
|
+
tsConfigFilePath: import_path14.default.resolve(process.cwd(), "tsconfig.json"),
|
|
3040
3111
|
skipAddingFilesFromTsConfig: false
|
|
3041
3112
|
});
|
|
3042
3113
|
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
3043
3114
|
const fp = sf.getFilePath();
|
|
3044
3115
|
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
3045
3116
|
});
|
|
3046
|
-
console.log(`
|
|
3117
|
+
console.log(`Removing legacy FHIR_URL helpers in ${sourceFiles.length} source file(s)...
|
|
3047
3118
|
`);
|
|
3048
|
-
let
|
|
3119
|
+
let totalRemovedImports = 0;
|
|
3120
|
+
let totalRemovedHelpers = 0;
|
|
3049
3121
|
const modifiedFiles = [];
|
|
3122
|
+
const warnings = [];
|
|
3050
3123
|
for (const sourceFile of sourceFiles) {
|
|
3051
3124
|
const filePath = sourceFile.getFilePath();
|
|
3052
|
-
const
|
|
3053
|
-
|
|
3054
|
-
|
|
3125
|
+
const rel = import_path14.default.relative(process.cwd(), filePath);
|
|
3126
|
+
const result = removeHelpers(filePath, project);
|
|
3127
|
+
const changed = result.removedImportCount > 0 || result.removedHelpers.length > 0;
|
|
3128
|
+
if (changed) {
|
|
3055
3129
|
modifiedFiles.push(filePath);
|
|
3130
|
+
totalRemovedImports += result.removedImportCount;
|
|
3131
|
+
totalRemovedHelpers += result.removedHelpers.length;
|
|
3132
|
+
if (result.removedHelpers.length > 0) {
|
|
3133
|
+
console.log(
|
|
3134
|
+
` [${rel}] Removed helper(s): ${result.removedHelpers.join(", ")}`
|
|
3135
|
+
);
|
|
3136
|
+
}
|
|
3137
|
+
if (result.removedImportCount > 0) {
|
|
3138
|
+
console.log(
|
|
3139
|
+
` [${rel}] Removed ${result.removedImportCount} '${FHIR_IMPORT}' import(s)`
|
|
3140
|
+
);
|
|
3141
|
+
}
|
|
3142
|
+
}
|
|
3143
|
+
if (result.remainingFhirReferences > 0) {
|
|
3144
|
+
warnings.push(
|
|
3145
|
+
`${rel}: ${result.remainingFhirReferences} remaining '${FHIR_IMPORT}' reference(s)`
|
|
3146
|
+
);
|
|
3056
3147
|
}
|
|
3057
3148
|
}
|
|
3058
|
-
if (modifiedFiles.length === 0) {
|
|
3059
|
-
console.log(
|
|
3060
|
-
"No deprecated workqueue 'actions' arrays found inside defineWorkqueues calls. Nothing to do."
|
|
3061
|
-
);
|
|
3149
|
+
if (modifiedFiles.length === 0 && warnings.length === 0) {
|
|
3150
|
+
console.log("No FHIR_URL imports/helpers found. Nothing to do.");
|
|
3062
3151
|
return;
|
|
3063
3152
|
}
|
|
3064
|
-
|
|
3153
|
+
if (modifiedFiles.length > 0) {
|
|
3154
|
+
console.log(`
|
|
3065
3155
|
Saving ${modifiedFiles.length} modified file(s)...`);
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
|
|
3156
|
+
for (const filePath of modifiedFiles) {
|
|
3157
|
+
await project.getSourceFileOrThrow(filePath).save();
|
|
3158
|
+
console.log(` Saved: ${import_path14.default.relative(process.cwd(), filePath)}`);
|
|
3159
|
+
}
|
|
3160
|
+
}
|
|
3161
|
+
if (warnings.length > 0) {
|
|
3162
|
+
console.warn(
|
|
3163
|
+
`
|
|
3164
|
+
WARNING: Some '${FHIR_IMPORT}' usages remain and need manual cleanup:
|
|
3165
|
+
` + warnings.map((line) => ` - ${line}`).join("\n")
|
|
3166
|
+
);
|
|
3070
3167
|
}
|
|
3071
3168
|
console.log(
|
|
3072
3169
|
`
|
|
3073
|
-
Done.
|
|
3170
|
+
Done. Removed ${totalRemovedHelpers} helper declaration(s) and ${totalRemovedImports} '${FHIR_IMPORT}' import(s).`
|
|
3074
3171
|
);
|
|
3075
3172
|
}
|
|
3076
3173
|
|
|
3077
|
-
// src/migrations/v2.0/
|
|
3078
|
-
var
|
|
3079
|
-
var
|
|
3080
|
-
var
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
);
|
|
3092
|
-
return;
|
|
3174
|
+
// src/migrations/v2.0/migrate-application-config-url.ts
|
|
3175
|
+
var import_path15 = __toESM(require("path"));
|
|
3176
|
+
var import_ts_morph15 = require("ts-morph");
|
|
3177
|
+
var TARGET_IDENTIFIER = "APPLICATION_CONFIG_URL";
|
|
3178
|
+
var REPLACEMENT_IDENTIFIER = "applicationConfig";
|
|
3179
|
+
var REPLACEMENT_MODULE = "@countryconfig/api/application/application-config";
|
|
3180
|
+
var FUNCTION_LIKE_KINDS = [
|
|
3181
|
+
import_ts_morph15.SyntaxKind.FunctionDeclaration,
|
|
3182
|
+
import_ts_morph15.SyntaxKind.FunctionExpression,
|
|
3183
|
+
import_ts_morph15.SyntaxKind.ArrowFunction,
|
|
3184
|
+
import_ts_morph15.SyntaxKind.MethodDeclaration
|
|
3185
|
+
];
|
|
3186
|
+
function describeFunction(node) {
|
|
3187
|
+
if (import_ts_morph15.Node.isFunctionDeclaration(node) || import_ts_morph15.Node.isMethodDeclaration(node)) {
|
|
3188
|
+
return node.getName() ?? "<anonymous>";
|
|
3093
3189
|
}
|
|
3094
|
-
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
);
|
|
3098
|
-
if (constantsImport) {
|
|
3099
|
-
constantsImport.remove();
|
|
3100
|
-
changed = true;
|
|
3190
|
+
const parent = node.getParent();
|
|
3191
|
+
if (parent && import_ts_morph15.Node.isVariableDeclaration(parent)) {
|
|
3192
|
+
return parent.getName();
|
|
3101
3193
|
}
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
console.log(
|
|
3105
|
-
`No rolesHandler export found in '${ROLES_HANDLER_RELATIVE_PATH}'. Nothing to do.`
|
|
3106
|
-
);
|
|
3107
|
-
return;
|
|
3194
|
+
if (parent && import_ts_morph15.Node.isPropertyAssignment(parent)) {
|
|
3195
|
+
return parent.getName();
|
|
3108
3196
|
}
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
const responseToolkitIdentifier = secondParamName || "h";
|
|
3112
|
-
const currentBodyText = rolesHandler.getBodyText();
|
|
3113
|
-
const normalizedCurrent = currentBodyText?.replace(/\s+/g, " ").trim() ?? "";
|
|
3114
|
-
const normalizedDesired = `return ${responseToolkitIdentifier}.response(roles)`;
|
|
3115
|
-
if (normalizedCurrent !== normalizedDesired) {
|
|
3116
|
-
rolesHandler.setBodyText(`return ${responseToolkitIdentifier}.response(roles)`);
|
|
3117
|
-
changed = true;
|
|
3197
|
+
if (import_ts_morph15.Node.isFunctionExpression(node) && node.getNameNode() !== void 0) {
|
|
3198
|
+
return node.getNameNode()?.getText() ?? "<anonymous>";
|
|
3118
3199
|
}
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
return;
|
|
3200
|
+
return "<anonymous>";
|
|
3201
|
+
}
|
|
3202
|
+
function hasBlockBody(node) {
|
|
3203
|
+
if (import_ts_morph15.Node.isFunctionDeclaration(node) || import_ts_morph15.Node.isFunctionExpression(node) || import_ts_morph15.Node.isMethodDeclaration(node)) {
|
|
3204
|
+
return node.getBody() !== void 0;
|
|
3124
3205
|
}
|
|
3125
|
-
|
|
3126
|
-
|
|
3127
|
-
|
|
3128
|
-
|
|
3206
|
+
if (import_ts_morph15.Node.isArrowFunction(node)) {
|
|
3207
|
+
return node.getBody().getKind() === import_ts_morph15.SyntaxKind.Block;
|
|
3208
|
+
}
|
|
3209
|
+
return false;
|
|
3129
3210
|
}
|
|
3130
|
-
|
|
3131
|
-
|
|
3132
|
-
|
|
3133
|
-
|
|
3134
|
-
|
|
3211
|
+
function isConfigFetcher(node) {
|
|
3212
|
+
let referencesTarget = false;
|
|
3213
|
+
let callsFetch = false;
|
|
3214
|
+
for (const id of node.getDescendantsOfKind(import_ts_morph15.SyntaxKind.Identifier)) {
|
|
3215
|
+
const text = id.getText();
|
|
3216
|
+
if (!referencesTarget && text === TARGET_IDENTIFIER) referencesTarget = true;
|
|
3217
|
+
if (!callsFetch && text === "fetch") {
|
|
3218
|
+
const parent = id.getParent();
|
|
3219
|
+
if (import_ts_morph15.Node.isCallExpression(parent) && parent.getExpression() === id) {
|
|
3220
|
+
callsFetch = true;
|
|
3221
|
+
}
|
|
3222
|
+
}
|
|
3223
|
+
if (referencesTarget && callsFetch) return true;
|
|
3224
|
+
}
|
|
3225
|
+
return false;
|
|
3226
|
+
}
|
|
3227
|
+
function processFile11(sourceFile) {
|
|
3228
|
+
const importsWithTarget = sourceFile.getImportDeclarations().filter(
|
|
3229
|
+
(decl) => decl.getNamedImports().some((ni) => ni.getName() === TARGET_IDENTIFIER)
|
|
3230
|
+
);
|
|
3231
|
+
if (importsWithTarget.length === 0) {
|
|
3232
|
+
return { changed: false, rewrittenFunctions: [], renamedReferences: 0 };
|
|
3233
|
+
}
|
|
3234
|
+
const collidingLocals = sourceFile.getDescendantsOfKind(import_ts_morph15.SyntaxKind.Identifier).filter((id) => id.getText() === REPLACEMENT_IDENTIFIER).filter((id) => {
|
|
3235
|
+
const parent = id.getParent();
|
|
3236
|
+
const kind = parent.getKind();
|
|
3237
|
+
return kind === import_ts_morph15.SyntaxKind.VariableDeclaration || kind === import_ts_morph15.SyntaxKind.FunctionDeclaration || kind === import_ts_morph15.SyntaxKind.ClassDeclaration || kind === import_ts_morph15.SyntaxKind.Parameter;
|
|
3238
|
+
});
|
|
3239
|
+
if (collidingLocals.length > 0) {
|
|
3240
|
+
return {
|
|
3241
|
+
changed: false,
|
|
3242
|
+
rewrittenFunctions: [],
|
|
3243
|
+
renamedReferences: 0,
|
|
3244
|
+
skippedReason: `local declaration named '${REPLACEMENT_IDENTIFIER}' would collide`
|
|
3245
|
+
};
|
|
3246
|
+
}
|
|
3247
|
+
const candidateFunctions = FUNCTION_LIKE_KINDS.flatMap(
|
|
3248
|
+
(kind) => sourceFile.getDescendantsOfKind(kind)
|
|
3249
|
+
);
|
|
3250
|
+
candidateFunctions.sort((a, b) => a.getStart() - b.getStart());
|
|
3251
|
+
const rewrittenFunctions = [];
|
|
3252
|
+
const rewrittenSet = /* @__PURE__ */ new Set();
|
|
3253
|
+
for (const fn of candidateFunctions) {
|
|
3254
|
+
if (!hasBlockBody(fn)) continue;
|
|
3255
|
+
if (!isConfigFetcher(fn)) continue;
|
|
3256
|
+
let inRewrittenAncestor = false;
|
|
3257
|
+
let cursor = fn.getParent();
|
|
3258
|
+
while (cursor) {
|
|
3259
|
+
if (rewrittenSet.has(cursor)) {
|
|
3260
|
+
inRewrittenAncestor = true;
|
|
3261
|
+
break;
|
|
3262
|
+
}
|
|
3263
|
+
cursor = cursor.getParent();
|
|
3264
|
+
}
|
|
3265
|
+
if (inRewrittenAncestor) continue;
|
|
3266
|
+
const start = fn.getStart();
|
|
3267
|
+
const line = sourceFile.getLineAndColumnAtPos(start).line;
|
|
3268
|
+
const name = describeFunction(fn);
|
|
3269
|
+
if (import_ts_morph15.Node.isFunctionDeclaration(fn) || import_ts_morph15.Node.isFunctionExpression(fn) || import_ts_morph15.Node.isMethodDeclaration(fn) || import_ts_morph15.Node.isArrowFunction(fn)) {
|
|
3270
|
+
fn.setBodyText(`return ${REPLACEMENT_IDENTIFIER}`);
|
|
3271
|
+
}
|
|
3272
|
+
rewrittenFunctions.push({ name, line });
|
|
3273
|
+
rewrittenSet.add(fn);
|
|
3274
|
+
}
|
|
3275
|
+
for (const decl of importsWithTarget) {
|
|
3276
|
+
const targetNamed = decl.getNamedImports().find((ni) => ni.getName() === TARGET_IDENTIFIER);
|
|
3277
|
+
targetNamed?.remove();
|
|
3278
|
+
const isNowEmpty = decl.getNamedImports().length === 0 && !decl.getDefaultImport() && !decl.getNamespaceImport();
|
|
3279
|
+
if (isNowEmpty) decl.remove();
|
|
3280
|
+
}
|
|
3281
|
+
const existing = sourceFile.getImportDeclaration(
|
|
3282
|
+
(decl) => decl.getModuleSpecifierValue() === REPLACEMENT_MODULE
|
|
3283
|
+
);
|
|
3284
|
+
if (existing) {
|
|
3285
|
+
const alreadyImported = existing.getNamedImports().some((ni) => ni.getName() === REPLACEMENT_IDENTIFIER);
|
|
3286
|
+
if (!alreadyImported) existing.addNamedImport(REPLACEMENT_IDENTIFIER);
|
|
3287
|
+
} else {
|
|
3288
|
+
sourceFile.addImportDeclaration({
|
|
3289
|
+
moduleSpecifier: REPLACEMENT_MODULE,
|
|
3290
|
+
namedImports: [REPLACEMENT_IDENTIFIER]
|
|
3291
|
+
});
|
|
3292
|
+
}
|
|
3293
|
+
const renameTargets = sourceFile.getDescendantsOfKind(import_ts_morph15.SyntaxKind.Identifier).filter((id) => id.getText() === TARGET_IDENTIFIER).filter((id) => !id.getFirstAncestorByKind(import_ts_morph15.SyntaxKind.ImportDeclaration)).filter((id) => {
|
|
3294
|
+
const parent = id.getParent();
|
|
3295
|
+
const parentKind = parent.getKind();
|
|
3296
|
+
if (parentKind === import_ts_morph15.SyntaxKind.PropertyAccessExpression) {
|
|
3297
|
+
const pae = parent.asKind(import_ts_morph15.SyntaxKind.PropertyAccessExpression);
|
|
3298
|
+
if (pae.getNameNode() === id) return false;
|
|
3299
|
+
}
|
|
3300
|
+
if (parentKind === import_ts_morph15.SyntaxKind.PropertyAssignment) {
|
|
3301
|
+
const pa = parent.asKind(import_ts_morph15.SyntaxKind.PropertyAssignment);
|
|
3302
|
+
if (pa.getNameNode() === id) return false;
|
|
3303
|
+
}
|
|
3304
|
+
if (parentKind === import_ts_morph15.SyntaxKind.ShorthandPropertyAssignment) {
|
|
3305
|
+
return false;
|
|
3306
|
+
}
|
|
3307
|
+
return true;
|
|
3308
|
+
}).sort((a, b) => b.getPos() - a.getPos());
|
|
3309
|
+
for (const id of renameTargets) {
|
|
3310
|
+
id.replaceWithText(REPLACEMENT_IDENTIFIER);
|
|
3311
|
+
}
|
|
3312
|
+
return {
|
|
3313
|
+
changed: true,
|
|
3314
|
+
rewrittenFunctions,
|
|
3315
|
+
renamedReferences: renameTargets.length
|
|
3316
|
+
};
|
|
3317
|
+
}
|
|
3318
|
+
async function main15() {
|
|
3319
|
+
const project = new import_ts_morph15.Project({
|
|
3320
|
+
tsConfigFilePath: import_path15.default.resolve(process.cwd(), "tsconfig.json"),
|
|
3321
|
+
skipAddingFilesFromTsConfig: false
|
|
3322
|
+
});
|
|
3323
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
3324
|
+
const fp = sf.getFilePath();
|
|
3325
|
+
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
3326
|
+
});
|
|
3327
|
+
console.log(
|
|
3328
|
+
`Migrating '${TARGET_IDENTIFIER}' \u2192 '${REPLACEMENT_IDENTIFIER}' across ${sourceFiles.length} source file(s)...
|
|
3329
|
+
`
|
|
3330
|
+
);
|
|
3331
|
+
let changedFiles = 0;
|
|
3332
|
+
let totalRewrittenFunctions = 0;
|
|
3333
|
+
let totalRenamedReferences = 0;
|
|
3334
|
+
const skipped = [];
|
|
3335
|
+
for (const sourceFile of sourceFiles) {
|
|
3336
|
+
const filePath = sourceFile.getFilePath();
|
|
3337
|
+
const rel = import_path15.default.relative(process.cwd(), filePath);
|
|
3338
|
+
const result = processFile11(sourceFile);
|
|
3339
|
+
if (result.skippedReason) {
|
|
3340
|
+
skipped.push(`${rel} (${result.skippedReason})`);
|
|
3341
|
+
continue;
|
|
3342
|
+
}
|
|
3343
|
+
if (!result.changed) continue;
|
|
3344
|
+
await sourceFile.save();
|
|
3345
|
+
changedFiles++;
|
|
3346
|
+
totalRewrittenFunctions += result.rewrittenFunctions.length;
|
|
3347
|
+
totalRenamedReferences += result.renamedReferences;
|
|
3348
|
+
for (const fn of result.rewrittenFunctions) {
|
|
3349
|
+
console.log(
|
|
3350
|
+
` [${rel}:${fn.line}] Rewrote '${fn.name}' body \u2192 'return ${REPLACEMENT_IDENTIFIER}' (config fetch eliminated)`
|
|
3351
|
+
);
|
|
3352
|
+
}
|
|
3353
|
+
if (result.renamedReferences > 0) {
|
|
3354
|
+
console.log(
|
|
3355
|
+
` [${rel}] Renamed ${result.renamedReferences} stray reference(s) ${TARGET_IDENTIFIER} \u2192 ${REPLACEMENT_IDENTIFIER}`
|
|
3356
|
+
);
|
|
3357
|
+
}
|
|
3358
|
+
}
|
|
3359
|
+
if (skipped.length > 0) {
|
|
3360
|
+
console.warn(
|
|
3361
|
+
`
|
|
3362
|
+
${skipped.length} file(s) skipped:
|
|
3363
|
+
` + skipped.map((s) => ` - ${s}`).join("\n")
|
|
3364
|
+
);
|
|
3365
|
+
}
|
|
3366
|
+
if (changedFiles === 0) {
|
|
3367
|
+
console.log(`
|
|
3368
|
+
No files reference '${TARGET_IDENTIFIER}'. Nothing to do.`);
|
|
3369
|
+
return;
|
|
3370
|
+
}
|
|
3371
|
+
console.log(
|
|
3372
|
+
`
|
|
3373
|
+
Done. Updated ${changedFiles} file(s): ${totalRewrittenFunctions} fetch function(s) rewritten, ${totalRenamedReferences} bare reference(s) renamed.`
|
|
3374
|
+
);
|
|
3375
|
+
if (totalRewrittenFunctions > 0) {
|
|
3376
|
+
console.log(
|
|
3377
|
+
`NOTE: rewriting fetch functions discards any custom logic that lived inside them. Review the diff and re-apply any country-specific adjustments on top of '${REPLACEMENT_IDENTIFIER}'.`
|
|
3378
|
+
);
|
|
3379
|
+
}
|
|
3380
|
+
}
|
|
3381
|
+
|
|
3382
|
+
// src/migrations/v2.0/remove-old-statistics-service.ts
|
|
3383
|
+
var import_path16 = __toESM(require("path"));
|
|
3384
|
+
var import_ts_morph16 = require("ts-morph");
|
|
3385
|
+
var ROUTE_PATH = "/statistics";
|
|
3386
|
+
var HANDLER_NAME = "statisticsHandler";
|
|
3387
|
+
function isStatisticsRouteObject(obj) {
|
|
3388
|
+
const pathProp = obj.getProperty("path");
|
|
3389
|
+
if (!pathProp || !import_ts_morph16.Node.isPropertyAssignment(pathProp)) return false;
|
|
3390
|
+
const init = pathProp.getInitializer();
|
|
3391
|
+
if (!init) return false;
|
|
3392
|
+
if (import_ts_morph16.Node.isStringLiteral(init) || import_ts_morph16.Node.isNoSubstitutionTemplateLiteral(init)) {
|
|
3393
|
+
return init.getLiteralValue() === ROUTE_PATH;
|
|
3394
|
+
}
|
|
3395
|
+
return false;
|
|
3396
|
+
}
|
|
3397
|
+
function removeStatisticsRoutes(sourceFile) {
|
|
3398
|
+
let removed = 0;
|
|
3399
|
+
const callExpressions = [
|
|
3400
|
+
...sourceFile.getDescendantsOfKind(import_ts_morph16.SyntaxKind.CallExpression)
|
|
3401
|
+
];
|
|
3402
|
+
for (const call of callExpressions) {
|
|
3403
|
+
if (call.wasForgotten()) continue;
|
|
3404
|
+
const expr = call.getExpression();
|
|
3405
|
+
if (!import_ts_morph16.Node.isPropertyAccessExpression(expr)) continue;
|
|
3406
|
+
if (expr.getName() !== "route") continue;
|
|
3407
|
+
const args2 = call.getArguments();
|
|
3408
|
+
if (args2.length === 0) continue;
|
|
3409
|
+
const firstArg = args2[0];
|
|
3410
|
+
if (import_ts_morph16.Node.isObjectLiteralExpression(firstArg)) {
|
|
3411
|
+
if (!isStatisticsRouteObject(firstArg)) continue;
|
|
3412
|
+
const stmt = call.getFirstAncestorByKind(import_ts_morph16.SyntaxKind.ExpressionStatement);
|
|
3413
|
+
if (stmt) {
|
|
3414
|
+
stmt.remove();
|
|
3415
|
+
removed++;
|
|
3416
|
+
} else {
|
|
3417
|
+
call.replaceWithText("");
|
|
3418
|
+
removed++;
|
|
3419
|
+
}
|
|
3420
|
+
continue;
|
|
3421
|
+
}
|
|
3422
|
+
if (import_ts_morph16.Node.isArrayLiteralExpression(firstArg)) {
|
|
3423
|
+
const matchingIndexes = firstArg.getElements().map((el, idx) => ({ el, idx })).filter(
|
|
3424
|
+
({ el }) => import_ts_morph16.Node.isObjectLiteralExpression(el) && isStatisticsRouteObject(el)
|
|
3425
|
+
).map(({ idx }) => idx);
|
|
3426
|
+
matchingIndexes.sort((a, b) => b - a).forEach((idx) => {
|
|
3427
|
+
firstArg.removeElement(idx);
|
|
3428
|
+
removed++;
|
|
3429
|
+
});
|
|
3430
|
+
}
|
|
3431
|
+
}
|
|
3432
|
+
return removed;
|
|
3433
|
+
}
|
|
3434
|
+
function removeStatisticsHandlerImports(sourceFile) {
|
|
3435
|
+
let changed = false;
|
|
3436
|
+
for (const decl of sourceFile.getImportDeclarations()) {
|
|
3437
|
+
const targetNamed = decl.getNamedImports().find((ni) => ni.getName() === HANDLER_NAME);
|
|
3438
|
+
if (!targetNamed) continue;
|
|
3439
|
+
targetNamed.remove();
|
|
3440
|
+
changed = true;
|
|
3441
|
+
const isNowEmpty = decl.getNamedImports().length === 0 && !decl.getDefaultImport() && !decl.getNamespaceImport();
|
|
3442
|
+
if (isNowEmpty) decl.remove();
|
|
3443
|
+
}
|
|
3444
|
+
return changed;
|
|
3445
|
+
}
|
|
3446
|
+
function processFile12(sourceFile) {
|
|
3447
|
+
const routesRemoved = removeStatisticsRoutes(sourceFile);
|
|
3448
|
+
const importsCleaned = removeStatisticsHandlerImports(sourceFile);
|
|
3449
|
+
return { routesRemoved, importsCleaned };
|
|
3450
|
+
}
|
|
3451
|
+
function collectLocalImportsInSubtree(sourceFile, subtreeRoot) {
|
|
3452
|
+
const result = [];
|
|
3453
|
+
for (const decl of sourceFile.getImportDeclarations()) {
|
|
3454
|
+
const moduleSf = decl.getModuleSpecifierSourceFile();
|
|
3455
|
+
if (!moduleSf) continue;
|
|
3456
|
+
const fp = moduleSf.getFilePath();
|
|
3457
|
+
if (!fp.startsWith(subtreeRoot)) continue;
|
|
3458
|
+
result.push(fp);
|
|
3459
|
+
}
|
|
3460
|
+
return result;
|
|
3461
|
+
}
|
|
3462
|
+
function deleteOrphanedDescendants(project, startingFile, subtreeRoot) {
|
|
3463
|
+
const initialCandidates = collectLocalImportsInSubtree(
|
|
3464
|
+
startingFile,
|
|
3465
|
+
subtreeRoot
|
|
3466
|
+
);
|
|
3467
|
+
const startingPath = startingFile.getFilePath();
|
|
3468
|
+
const deleted = /* @__PURE__ */ new Set([startingPath]);
|
|
3469
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3470
|
+
const worklist = [...initialCandidates];
|
|
3471
|
+
const orphans = [];
|
|
3472
|
+
while (worklist.length > 0) {
|
|
3473
|
+
const candidate = worklist.shift();
|
|
3474
|
+
if (seen.has(candidate)) continue;
|
|
3475
|
+
seen.add(candidate);
|
|
3476
|
+
if (deleted.has(candidate)) continue;
|
|
3477
|
+
if (!candidate.startsWith(subtreeRoot)) continue;
|
|
3478
|
+
const candidateSf = project.getSourceFile(candidate);
|
|
3479
|
+
if (!candidateSf) continue;
|
|
3480
|
+
const stillImported = project.getSourceFiles().some((sf) => {
|
|
3481
|
+
const sfPath = sf.getFilePath();
|
|
3482
|
+
if (deleted.has(sfPath)) return false;
|
|
3483
|
+
if (sfPath === candidate) return false;
|
|
3484
|
+
return sf.getImportDeclarations().some(
|
|
3485
|
+
(decl) => decl.getModuleSpecifierSourceFile()?.getFilePath() === candidate
|
|
3486
|
+
);
|
|
3487
|
+
});
|
|
3488
|
+
if (stillImported) continue;
|
|
3489
|
+
const next = collectLocalImportsInSubtree(candidateSf, subtreeRoot);
|
|
3490
|
+
worklist.push(...next);
|
|
3491
|
+
candidateSf.delete();
|
|
3492
|
+
deleted.add(candidate);
|
|
3493
|
+
orphans.push(candidate);
|
|
3494
|
+
}
|
|
3495
|
+
return orphans;
|
|
3496
|
+
}
|
|
3497
|
+
function processHandlerFile(project) {
|
|
3498
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
3499
|
+
const fp = sf.getFilePath();
|
|
3500
|
+
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
3501
|
+
});
|
|
3502
|
+
for (const sf of sourceFiles) {
|
|
3503
|
+
const fn = sf.getFunction(HANDLER_NAME);
|
|
3504
|
+
if (!fn) continue;
|
|
3505
|
+
const filePath = sf.getFilePath();
|
|
3506
|
+
const exportsByName = [...sf.getExportedDeclarations().keys()];
|
|
3507
|
+
const otherExports = exportsByName.filter((name) => name !== HANDLER_NAME);
|
|
3508
|
+
if (otherExports.length === 0) {
|
|
3509
|
+
const subtreeRoot = import_path16.default.dirname(filePath) + import_path16.default.sep;
|
|
3510
|
+
const orphansDeleted = deleteOrphanedDescendants(
|
|
3511
|
+
project,
|
|
3512
|
+
sf,
|
|
3513
|
+
subtreeRoot
|
|
3514
|
+
);
|
|
3515
|
+
sf.delete();
|
|
3516
|
+
return { filePath, action: "deleted", orphansDeleted };
|
|
3517
|
+
}
|
|
3518
|
+
fn.remove();
|
|
3519
|
+
return {
|
|
3520
|
+
filePath,
|
|
3521
|
+
action: "function-removed",
|
|
3522
|
+
remainingExports: otherExports,
|
|
3523
|
+
orphansDeleted: []
|
|
3524
|
+
};
|
|
3525
|
+
}
|
|
3526
|
+
return { filePath: "", action: "not-found", orphansDeleted: [] };
|
|
3527
|
+
}
|
|
3528
|
+
async function main16() {
|
|
3529
|
+
const project = new import_ts_morph16.Project({
|
|
3530
|
+
tsConfigFilePath: import_path16.default.resolve(process.cwd(), "tsconfig.json"),
|
|
3531
|
+
skipAddingFilesFromTsConfig: false
|
|
3532
|
+
});
|
|
3533
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
3534
|
+
const fp = sf.getFilePath();
|
|
3535
|
+
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
3536
|
+
});
|
|
3537
|
+
console.log(
|
|
3538
|
+
`Removing legacy 'GET ${ROUTE_PATH}' route and '${HANDLER_NAME}' across ${sourceFiles.length} source file(s)...
|
|
3539
|
+
`
|
|
3540
|
+
);
|
|
3541
|
+
let totalRoutesRemoved = 0;
|
|
3542
|
+
let totalFilesWithImportsCleaned = 0;
|
|
3543
|
+
let totalFilesWithRoutesRemoved = 0;
|
|
3544
|
+
for (const sourceFile of sourceFiles) {
|
|
3545
|
+
const filePath = sourceFile.getFilePath();
|
|
3546
|
+
const rel = import_path16.default.relative(process.cwd(), filePath);
|
|
3547
|
+
const result = processFile12(sourceFile);
|
|
3548
|
+
if (result.routesRemoved > 0) {
|
|
3549
|
+
console.log(
|
|
3550
|
+
` [${rel}] Removed ${result.routesRemoved} '${ROUTE_PATH}' route(s)`
|
|
3551
|
+
);
|
|
3552
|
+
totalRoutesRemoved += result.routesRemoved;
|
|
3553
|
+
totalFilesWithRoutesRemoved++;
|
|
3554
|
+
}
|
|
3555
|
+
if (result.importsCleaned) {
|
|
3556
|
+
console.log(` [${rel}] Cleaned up '${HANDLER_NAME}' import`);
|
|
3557
|
+
totalFilesWithImportsCleaned++;
|
|
3558
|
+
}
|
|
3559
|
+
if (result.routesRemoved > 0 || result.importsCleaned) {
|
|
3560
|
+
await sourceFile.save();
|
|
3561
|
+
}
|
|
3562
|
+
}
|
|
3563
|
+
const handlerResult = processHandlerFile(project);
|
|
3564
|
+
switch (handlerResult.action) {
|
|
3565
|
+
case "deleted": {
|
|
3566
|
+
const rel = import_path16.default.relative(process.cwd(), handlerResult.filePath);
|
|
3567
|
+
console.log(
|
|
3568
|
+
` [${rel}] Deleted handler file ('${HANDLER_NAME}' was the sole export).`
|
|
3569
|
+
);
|
|
3570
|
+
for (const orphanPath of handlerResult.orphansDeleted) {
|
|
3571
|
+
const orphanRel = import_path16.default.relative(process.cwd(), orphanPath);
|
|
3572
|
+
console.log(
|
|
3573
|
+
` [${orphanRel}] Deleted (no remaining importers in the project after handler removal).`
|
|
3574
|
+
);
|
|
3575
|
+
}
|
|
3576
|
+
await project.save();
|
|
3577
|
+
break;
|
|
3578
|
+
}
|
|
3579
|
+
case "function-removed": {
|
|
3580
|
+
const rel = import_path16.default.relative(process.cwd(), handlerResult.filePath);
|
|
3581
|
+
console.warn(
|
|
3582
|
+
` [${rel}] Removed '${HANDLER_NAME}' function but kept the file (other exports remain: ${handlerResult.remainingExports?.join(", ")}). Review whether the file is still needed.`
|
|
3583
|
+
);
|
|
3584
|
+
const sf = project.getSourceFile(handlerResult.filePath);
|
|
3585
|
+
if (sf) await sf.save();
|
|
3586
|
+
break;
|
|
3587
|
+
}
|
|
3588
|
+
case "not-found":
|
|
3589
|
+
break;
|
|
3590
|
+
}
|
|
3591
|
+
if (totalRoutesRemoved === 0 && totalFilesWithImportsCleaned === 0 && handlerResult.action === "not-found") {
|
|
3592
|
+
console.log(`
|
|
3593
|
+
No legacy '${ROUTE_PATH}' route or handler found. Nothing to do.`);
|
|
3594
|
+
return;
|
|
3595
|
+
}
|
|
3596
|
+
const orphansSummary = handlerResult.orphansDeleted.length > 0 ? ` and ${handlerResult.orphansDeleted.length} orphaned helper file(s)` : "";
|
|
3597
|
+
console.log(
|
|
3598
|
+
`
|
|
3599
|
+
Done. Removed ${totalRoutesRemoved} route(s) across ${totalFilesWithRoutesRemoved} file(s); cleaned ${HANDLER_NAME} import in ${totalFilesWithImportsCleaned} file(s)${orphansSummary}.`
|
|
3600
|
+
);
|
|
3601
|
+
}
|
|
3602
|
+
|
|
3603
|
+
// src/migrations/v2.0/update-package-json.ts
|
|
3604
|
+
var import_fs = require("fs");
|
|
3605
|
+
var import_path17 = __toESM(require("path"));
|
|
3606
|
+
var PACKAGE_JSON_RELATIVE = "package.json";
|
|
3607
|
+
var TARGET_VERSION = "2.0.0";
|
|
3608
|
+
var TARGET_ZOD_RANGE = "^4.2.1";
|
|
3609
|
+
async function main17() {
|
|
3610
|
+
const packageJsonPath = import_path17.default.join(process.cwd(), PACKAGE_JSON_RELATIVE);
|
|
3611
|
+
if (!(0, import_fs.existsSync)(packageJsonPath)) {
|
|
3612
|
+
console.log(`'${PACKAGE_JSON_RELATIVE}' not found in ${process.cwd()} \u2014 skipping.`);
|
|
3613
|
+
return;
|
|
3614
|
+
}
|
|
3615
|
+
const raw = (0, import_fs.readFileSync)(packageJsonPath, "utf8");
|
|
3616
|
+
let parsed;
|
|
3617
|
+
try {
|
|
3618
|
+
parsed = JSON.parse(raw);
|
|
3619
|
+
} catch (error) {
|
|
3620
|
+
console.warn(
|
|
3621
|
+
` [${PACKAGE_JSON_RELATIVE}] Failed to parse JSON \u2014 skipping update. ${error.message}`
|
|
3622
|
+
);
|
|
3623
|
+
return;
|
|
3624
|
+
}
|
|
3625
|
+
console.log(`Updating '${PACKAGE_JSON_RELATIVE}'...`);
|
|
3626
|
+
const previousVersion = parsed.version;
|
|
3627
|
+
const versionChanged = previousVersion !== TARGET_VERSION;
|
|
3628
|
+
parsed.version = TARGET_VERSION;
|
|
3629
|
+
if (versionChanged) {
|
|
3630
|
+
console.log(
|
|
3631
|
+
` Set version: ${previousVersion ?? "<unset>"} \u2192 ${TARGET_VERSION}`
|
|
3632
|
+
);
|
|
3633
|
+
} else {
|
|
3634
|
+
console.log(` Version already ${TARGET_VERSION} \u2014 no change.`);
|
|
3635
|
+
}
|
|
3636
|
+
let zodBucket = "dependencies";
|
|
3637
|
+
if (parsed.devDependencies && "zod" in parsed.devDependencies) {
|
|
3638
|
+
zodBucket = "devDependencies";
|
|
3639
|
+
}
|
|
3640
|
+
if (!parsed[zodBucket]) {
|
|
3641
|
+
parsed[zodBucket] = {};
|
|
3642
|
+
}
|
|
3643
|
+
const bucket = parsed[zodBucket];
|
|
3644
|
+
const previousZod = bucket.zod;
|
|
3645
|
+
const zodChanged = previousZod !== TARGET_ZOD_RANGE;
|
|
3646
|
+
bucket.zod = TARGET_ZOD_RANGE;
|
|
3647
|
+
if (zodChanged) {
|
|
3648
|
+
console.log(
|
|
3649
|
+
` Set ${zodBucket}.zod: ${previousZod ?? "<absent>"} \u2192 ${TARGET_ZOD_RANGE}`
|
|
3650
|
+
);
|
|
3651
|
+
} else {
|
|
3652
|
+
console.log(` ${zodBucket}.zod already ${TARGET_ZOD_RANGE} \u2014 no change.`);
|
|
3653
|
+
}
|
|
3654
|
+
const trailingNewline = raw.endsWith("\n") ? "\n" : "";
|
|
3655
|
+
const next = JSON.stringify(parsed, null, 2) + trailingNewline;
|
|
3656
|
+
if (next === raw) {
|
|
3657
|
+
console.log("\n No changes to write.");
|
|
3658
|
+
return;
|
|
3659
|
+
}
|
|
3660
|
+
(0, import_fs.writeFileSync)(packageJsonPath, next, "utf8");
|
|
3661
|
+
console.log(`
|
|
3662
|
+
Saved '${PACKAGE_JSON_RELATIVE}'.`);
|
|
3663
|
+
console.log(
|
|
3664
|
+
` NOTE: run \`yarn install\` (or your package manager equivalent) to install the updated dependency versions.`
|
|
3665
|
+
);
|
|
3666
|
+
}
|
|
3667
|
+
|
|
3668
|
+
// src/migrations/v2.0/migrate-workqueue-configs.ts
|
|
3669
|
+
var import_ts_morph17 = require("ts-morph");
|
|
3670
|
+
var import_path18 = __toESM(require("path"));
|
|
3671
|
+
var DEFINE_WORKQUEUES_NAME3 = "defineWorkqueues";
|
|
3672
|
+
var ACTIONS_PROPERTY_NAME5 = "actions";
|
|
3673
|
+
var ACTION_PROPERTY_NAME2 = "action";
|
|
3674
|
+
var CONDITIONALS_PROPERTY_NAME = "conditionals";
|
|
3675
|
+
var TYPE_PROPERTY_NAME7 = "type";
|
|
3676
|
+
var SLUG_PROPERTY_NAME = "slug";
|
|
3677
|
+
var READ_ACTION_TYPE = "READ";
|
|
3678
|
+
var ACTION_TYPE_IMPORT_NAME = "ActionType";
|
|
3679
|
+
var TOOLKIT_EVENTS_MODULE2 = "@opencrvs/toolkit/events";
|
|
3680
|
+
var READ_ACTION_FALLBACK_INITIALIZER = `{ type: ${ACTION_TYPE_IMPORT_NAME}.${READ_ACTION_TYPE} }`;
|
|
3681
|
+
var SUPPORTED_WORKQUEUE_ACTION_TYPES = /* @__PURE__ */ new Set([
|
|
3682
|
+
"READ",
|
|
3683
|
+
"DELETE",
|
|
3684
|
+
"DECLARE",
|
|
3685
|
+
"REGISTER",
|
|
3686
|
+
"EDIT",
|
|
3687
|
+
"REJECT",
|
|
3688
|
+
"MARK_AS_DUPLICATE",
|
|
3689
|
+
"ARCHIVE",
|
|
3690
|
+
"PRINT_CERTIFICATE",
|
|
3691
|
+
"REQUEST_CORRECTION"
|
|
3692
|
+
]);
|
|
3693
|
+
function getWorkqueueLabel(workqueue) {
|
|
3694
|
+
const slugProperty = workqueue.getProperty(SLUG_PROPERTY_NAME);
|
|
3695
|
+
if (!slugProperty || !import_ts_morph17.Node.isPropertyAssignment(slugProperty)) {
|
|
3696
|
+
return "(unknown slug)";
|
|
3697
|
+
}
|
|
3698
|
+
const slugInitializer = slugProperty.getInitializer();
|
|
3699
|
+
if (!slugInitializer || !import_ts_morph17.Node.isStringLiteral(slugInitializer)) {
|
|
3700
|
+
return "(unknown slug)";
|
|
3701
|
+
}
|
|
3702
|
+
return slugInitializer.getLiteralValue();
|
|
3703
|
+
}
|
|
3704
|
+
function getActionTypeName(action) {
|
|
3705
|
+
const typeProperty = action.getProperty(TYPE_PROPERTY_NAME7);
|
|
3706
|
+
if (!typeProperty || !import_ts_morph17.Node.isPropertyAssignment(typeProperty)) {
|
|
3707
|
+
return null;
|
|
3708
|
+
}
|
|
3709
|
+
const typeInitializer = typeProperty.getInitializer();
|
|
3710
|
+
if (!typeInitializer) {
|
|
3711
|
+
return null;
|
|
3712
|
+
}
|
|
3713
|
+
if (import_ts_morph17.Node.isStringLiteral(typeInitializer)) {
|
|
3714
|
+
return typeInitializer.getLiteralValue();
|
|
3715
|
+
}
|
|
3716
|
+
if (import_ts_morph17.Node.isPropertyAccessExpression(typeInitializer)) {
|
|
3717
|
+
return typeInitializer.getName();
|
|
3718
|
+
}
|
|
3719
|
+
return null;
|
|
3720
|
+
}
|
|
3721
|
+
function isUnsupportedActionType(action) {
|
|
3722
|
+
const typeName = getActionTypeName(action);
|
|
3723
|
+
if (!typeName) {
|
|
3724
|
+
return false;
|
|
3725
|
+
}
|
|
3726
|
+
return !SUPPORTED_WORKQUEUE_ACTION_TYPES.has(typeName);
|
|
3727
|
+
}
|
|
3728
|
+
function ensureValidAction(workqueue, relPath) {
|
|
3729
|
+
const workqueueLabel = getWorkqueueLabel(workqueue);
|
|
3730
|
+
const actionProperty = workqueue.getProperty(ACTION_PROPERTY_NAME2);
|
|
3731
|
+
if (actionProperty && import_ts_morph17.Node.isPropertyAssignment(actionProperty)) {
|
|
3732
|
+
const initializer = actionProperty.getInitializer();
|
|
3733
|
+
if (initializer && import_ts_morph17.Node.isObjectLiteralExpression(initializer)) {
|
|
3734
|
+
if (!isUnsupportedActionType(initializer)) {
|
|
3735
|
+
return { changed: false, usedReadFallback: false };
|
|
3736
|
+
}
|
|
3737
|
+
actionProperty.set({
|
|
3738
|
+
name: ACTION_PROPERTY_NAME2,
|
|
3739
|
+
initializer: READ_ACTION_FALLBACK_INITIALIZER
|
|
3740
|
+
});
|
|
3741
|
+
console.log(
|
|
3742
|
+
` [${relPath}] Replaced unsupported 'action' type with '${ACTION_TYPE_IMPORT_NAME}.${READ_ACTION_TYPE}' on workqueue '${workqueueLabel}'`
|
|
3743
|
+
);
|
|
3744
|
+
return { changed: true, usedReadFallback: true };
|
|
3745
|
+
}
|
|
3746
|
+
}
|
|
3747
|
+
workqueue.addPropertyAssignment({
|
|
3748
|
+
name: ACTION_PROPERTY_NAME2,
|
|
3749
|
+
initializer: READ_ACTION_FALLBACK_INITIALIZER
|
|
3750
|
+
});
|
|
3751
|
+
console.log(
|
|
3752
|
+
` [${relPath}] Added default 'action: ${READ_ACTION_FALLBACK_INITIALIZER}' to workqueue '${workqueueLabel}'`
|
|
3753
|
+
);
|
|
3754
|
+
return { changed: true, usedReadFallback: true };
|
|
3755
|
+
}
|
|
3756
|
+
function migrateWorkqueueActions(workqueue, relPath) {
|
|
3757
|
+
const workqueueLabel = getWorkqueueLabel(workqueue);
|
|
3758
|
+
const actionsProperty = workqueue.getProperty(ACTIONS_PROPERTY_NAME5);
|
|
3759
|
+
let actionsArrayMigrated = false;
|
|
3760
|
+
if (actionsProperty && import_ts_morph17.Node.isPropertyAssignment(actionsProperty)) {
|
|
3761
|
+
const actionsInitializer = actionsProperty.getInitializer();
|
|
3762
|
+
if (actionsInitializer && import_ts_morph17.Node.isArrayLiteralExpression(actionsInitializer)) {
|
|
3763
|
+
const existingActionProperty = workqueue.getProperty(ACTION_PROPERTY_NAME2);
|
|
3764
|
+
if (existingActionProperty) {
|
|
3765
|
+
if (import_ts_morph17.Node.isPropertyAssignment(existingActionProperty)) {
|
|
3766
|
+
const existingActionInitializer = existingActionProperty.getInitializer();
|
|
3767
|
+
if (existingActionInitializer && import_ts_morph17.Node.isObjectLiteralExpression(existingActionInitializer)) {
|
|
3768
|
+
const conditionalsProperty = existingActionInitializer.getProperty(
|
|
3769
|
+
CONDITIONALS_PROPERTY_NAME
|
|
3770
|
+
);
|
|
3771
|
+
if (conditionalsProperty) {
|
|
3772
|
+
conditionalsProperty.remove();
|
|
3773
|
+
console.log(
|
|
3774
|
+
` [${relPath}] Removed deprecated 'conditionals' from 'action' on workqueue '${workqueueLabel}'`
|
|
3775
|
+
);
|
|
3776
|
+
}
|
|
3777
|
+
}
|
|
3778
|
+
}
|
|
3779
|
+
actionsProperty.remove();
|
|
3780
|
+
console.log(
|
|
3781
|
+
` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' (existing 'action' kept)`
|
|
3782
|
+
);
|
|
3783
|
+
actionsArrayMigrated = true;
|
|
3784
|
+
} else {
|
|
3785
|
+
const actionCandidates = actionsInitializer.getElements().filter(
|
|
3786
|
+
(element) => import_ts_morph17.Node.isObjectLiteralExpression(element)
|
|
3787
|
+
);
|
|
3788
|
+
if (actionCandidates.length === 0) {
|
|
3789
|
+
actionsProperty.remove();
|
|
3790
|
+
console.log(
|
|
3791
|
+
` [${relPath}] Removed empty 'actions' from workqueue '${workqueueLabel}'`
|
|
3792
|
+
);
|
|
3793
|
+
actionsArrayMigrated = true;
|
|
3794
|
+
} else {
|
|
3795
|
+
if (actionCandidates.length > 1) {
|
|
3796
|
+
const droppedCount = actionCandidates.length - 1;
|
|
3797
|
+
console.warn(
|
|
3798
|
+
` [${relPath}] Workqueue '${workqueueLabel}' has ${actionCandidates.length} actions; keeping first as 'action' and dropping ${droppedCount} extra action(s)`
|
|
3799
|
+
);
|
|
3800
|
+
}
|
|
3801
|
+
const conditionalsProperty = actionCandidates[0].getProperty(
|
|
3802
|
+
CONDITIONALS_PROPERTY_NAME
|
|
3803
|
+
);
|
|
3804
|
+
if (conditionalsProperty) {
|
|
3805
|
+
conditionalsProperty.remove();
|
|
3806
|
+
console.log(
|
|
3807
|
+
` [${relPath}] Removed deprecated 'conditionals' from migrated 'action' on workqueue '${workqueueLabel}'`
|
|
3808
|
+
);
|
|
3809
|
+
}
|
|
3810
|
+
if (isUnsupportedActionType(actionCandidates[0])) {
|
|
3811
|
+
actionsProperty.remove();
|
|
3812
|
+
console.log(
|
|
3813
|
+
` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' because action type is unsupported`
|
|
3814
|
+
);
|
|
3815
|
+
actionsArrayMigrated = true;
|
|
3816
|
+
} else {
|
|
3817
|
+
const firstActionText = actionCandidates[0].getText();
|
|
3818
|
+
workqueue.addPropertyAssignment({
|
|
3819
|
+
name: ACTION_PROPERTY_NAME2,
|
|
3820
|
+
initializer: firstActionText
|
|
3821
|
+
});
|
|
3822
|
+
actionsProperty.remove();
|
|
3823
|
+
console.log(
|
|
3824
|
+
` [${relPath}] Replaced 'actions' with 'action' on workqueue '${workqueueLabel}'`
|
|
3825
|
+
);
|
|
3826
|
+
actionsArrayMigrated = true;
|
|
3827
|
+
}
|
|
3828
|
+
}
|
|
3829
|
+
}
|
|
3830
|
+
}
|
|
3831
|
+
}
|
|
3832
|
+
const fallback = ensureValidAction(workqueue, relPath);
|
|
3833
|
+
return {
|
|
3834
|
+
changed: actionsArrayMigrated || fallback.changed,
|
|
3835
|
+
usedReadFallback: fallback.usedReadFallback
|
|
3836
|
+
};
|
|
3837
|
+
}
|
|
3838
|
+
function ensureActionTypeImport(sourceFile) {
|
|
3839
|
+
const existingImport = sourceFile.getImportDeclaration(
|
|
3840
|
+
(decl) => decl.getModuleSpecifierValue() === TOOLKIT_EVENTS_MODULE2
|
|
3841
|
+
);
|
|
3842
|
+
if (existingImport) {
|
|
3843
|
+
const alreadyImported = existingImport.getNamedImports().some((ni) => ni.getName() === ACTION_TYPE_IMPORT_NAME);
|
|
3844
|
+
if (!alreadyImported) {
|
|
3845
|
+
existingImport.addNamedImport(ACTION_TYPE_IMPORT_NAME);
|
|
3846
|
+
}
|
|
3847
|
+
return;
|
|
3848
|
+
}
|
|
3849
|
+
sourceFile.addImportDeclaration({
|
|
3850
|
+
moduleSpecifier: TOOLKIT_EVENTS_MODULE2,
|
|
3851
|
+
namedImports: [ACTION_TYPE_IMPORT_NAME]
|
|
3852
|
+
});
|
|
3853
|
+
}
|
|
3854
|
+
function processFile13(filePath, project) {
|
|
3855
|
+
const sourceFile = project.getSourceFile(filePath);
|
|
3856
|
+
if (!sourceFile) return 0;
|
|
3857
|
+
let migratedWorkqueues = 0;
|
|
3858
|
+
let needsActionTypeImport = false;
|
|
3859
|
+
const relPath = import_path18.default.relative(process.cwd(), filePath);
|
|
3860
|
+
const callExpressions = sourceFile.getDescendantsOfKind(
|
|
3861
|
+
import_ts_morph17.SyntaxKind.CallExpression
|
|
3862
|
+
);
|
|
3863
|
+
for (const call of callExpressions) {
|
|
3864
|
+
const expression = call.getExpression();
|
|
3865
|
+
if (!import_ts_morph17.Node.isIdentifier(expression) || expression.getText() !== DEFINE_WORKQUEUES_NAME3) {
|
|
3866
|
+
continue;
|
|
3867
|
+
}
|
|
3868
|
+
const args2 = call.getArguments();
|
|
3869
|
+
if (args2.length === 0) continue;
|
|
3870
|
+
const workqueuesArg = args2[0];
|
|
3871
|
+
if (!import_ts_morph17.Node.isArrayLiteralExpression(workqueuesArg)) continue;
|
|
3872
|
+
for (const element of workqueuesArg.getElements()) {
|
|
3873
|
+
if (!import_ts_morph17.Node.isObjectLiteralExpression(element)) continue;
|
|
3874
|
+
const result = migrateWorkqueueActions(element, relPath);
|
|
3875
|
+
if (result.changed) migratedWorkqueues++;
|
|
3876
|
+
if (result.usedReadFallback) needsActionTypeImport = true;
|
|
3877
|
+
}
|
|
3878
|
+
}
|
|
3879
|
+
if (needsActionTypeImport) {
|
|
3880
|
+
ensureActionTypeImport(sourceFile);
|
|
3881
|
+
}
|
|
3882
|
+
return migratedWorkqueues;
|
|
3883
|
+
}
|
|
3884
|
+
async function main18() {
|
|
3885
|
+
const srcDir = import_path18.default.join(process.cwd(), "src");
|
|
3886
|
+
console.log(`Scanning for defineWorkqueues calls in: ${srcDir}
|
|
3887
|
+
`);
|
|
3888
|
+
const project = new import_ts_morph17.Project({
|
|
3889
|
+
tsConfigFilePath: import_path18.default.resolve(srcDir, "../tsconfig.json"),
|
|
3890
|
+
skipAddingFilesFromTsConfig: false
|
|
3891
|
+
});
|
|
3892
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
3893
|
+
const fp = sf.getFilePath();
|
|
3894
|
+
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
3895
|
+
});
|
|
3896
|
+
console.log(`Found ${sourceFiles.length} source file(s) to analyse.
|
|
3897
|
+
`);
|
|
3898
|
+
let totalMigrated = 0;
|
|
3899
|
+
const modifiedFiles = [];
|
|
3900
|
+
for (const sourceFile of sourceFiles) {
|
|
3901
|
+
const filePath = sourceFile.getFilePath();
|
|
3902
|
+
const migrated = processFile13(filePath, project);
|
|
3903
|
+
if (migrated > 0) {
|
|
3904
|
+
totalMigrated += migrated;
|
|
3905
|
+
modifiedFiles.push(filePath);
|
|
3906
|
+
}
|
|
3907
|
+
}
|
|
3908
|
+
if (modifiedFiles.length === 0) {
|
|
3909
|
+
console.log(
|
|
3910
|
+
"No deprecated workqueue 'actions' arrays found inside defineWorkqueues calls. Nothing to do."
|
|
3911
|
+
);
|
|
3912
|
+
return;
|
|
3913
|
+
}
|
|
3914
|
+
console.log(`
|
|
3915
|
+
Saving ${modifiedFiles.length} modified file(s)...`);
|
|
3916
|
+
for (const filePath of modifiedFiles) {
|
|
3917
|
+
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
3918
|
+
await sourceFile.save();
|
|
3919
|
+
console.log(` Saved: ${import_path18.default.relative(process.cwd(), filePath)}`);
|
|
3920
|
+
}
|
|
3921
|
+
console.log(
|
|
3922
|
+
`
|
|
3923
|
+
Done. Migrated ${totalMigrated} deprecated workqueue 'actions' definition(s) to 'action'.`
|
|
3924
|
+
);
|
|
3925
|
+
}
|
|
3926
|
+
|
|
3927
|
+
// src/migrations/v2.0/remove-demo-scope.ts
|
|
3928
|
+
var import_path19 = __toESM(require("path"));
|
|
3929
|
+
var import_ts_morph18 = require("ts-morph");
|
|
3930
|
+
var ROLES_HANDLER_RELATIVE_PATH = "src/data-seeding/roles/handler.ts";
|
|
3931
|
+
async function main19() {
|
|
3932
|
+
const rolesHandlerPath = import_path19.default.join(process.cwd(), ROLES_HANDLER_RELATIVE_PATH);
|
|
3933
|
+
const project = new import_ts_morph18.Project({
|
|
3934
|
+
tsConfigFilePath: import_path19.default.resolve(process.cwd(), "tsconfig.json"),
|
|
3935
|
+
skipAddingFilesFromTsConfig: false
|
|
3936
|
+
});
|
|
3937
|
+
const sourceFile = project.getSourceFile(rolesHandlerPath);
|
|
3938
|
+
if (!sourceFile) {
|
|
3939
|
+
console.log(
|
|
3940
|
+
`No roles handler found at '${ROLES_HANDLER_RELATIVE_PATH}'. Nothing to do.`
|
|
3941
|
+
);
|
|
3942
|
+
return;
|
|
3943
|
+
}
|
|
3944
|
+
let changed = false;
|
|
3945
|
+
const constantsImport = sourceFile.getImportDeclaration(
|
|
3946
|
+
(decl) => decl.getModuleSpecifierValue() === "@countryconfig/constants"
|
|
3947
|
+
);
|
|
3948
|
+
if (constantsImport) {
|
|
3949
|
+
constantsImport.remove();
|
|
3950
|
+
changed = true;
|
|
3951
|
+
}
|
|
3952
|
+
const rolesHandler = sourceFile.getFunction("rolesHandler");
|
|
3953
|
+
if (!rolesHandler) {
|
|
3954
|
+
console.log(
|
|
3955
|
+
`No rolesHandler export found in '${ROLES_HANDLER_RELATIVE_PATH}'. Nothing to do.`
|
|
3956
|
+
);
|
|
3957
|
+
return;
|
|
3958
|
+
}
|
|
3959
|
+
const secondParam = rolesHandler.getParameters()[1];
|
|
3960
|
+
const secondParamName = secondParam?.getName();
|
|
3961
|
+
const responseToolkitIdentifier = secondParamName || "h";
|
|
3962
|
+
const currentBodyText = rolesHandler.getBodyText();
|
|
3963
|
+
const normalizedCurrent = currentBodyText?.replace(/\s+/g, " ").trim() ?? "";
|
|
3964
|
+
const normalizedDesired = `return ${responseToolkitIdentifier}.response(roles)`;
|
|
3965
|
+
if (normalizedCurrent !== normalizedDesired) {
|
|
3966
|
+
rolesHandler.setBodyText(`return ${responseToolkitIdentifier}.response(roles)`);
|
|
3967
|
+
changed = true;
|
|
3968
|
+
}
|
|
3969
|
+
if (!changed) {
|
|
3970
|
+
console.log(
|
|
3971
|
+
`No changes needed in '${ROLES_HANDLER_RELATIVE_PATH}'.`
|
|
3972
|
+
);
|
|
3973
|
+
return;
|
|
3974
|
+
}
|
|
3975
|
+
await sourceFile.save();
|
|
3976
|
+
console.log(
|
|
3977
|
+
`Updated '${ROLES_HANDLER_RELATIVE_PATH}' to remove demo scope behavior while preserving file structure.`
|
|
3978
|
+
);
|
|
3979
|
+
}
|
|
3980
|
+
|
|
3981
|
+
// src/migrations/v2.0/remove-hearth-migrations.ts
|
|
3982
|
+
var fs2 = __toESM(require("fs"));
|
|
3983
|
+
var import_path20 = __toESM(require("path"));
|
|
3984
|
+
var PATHS_TO_REMOVE = [
|
|
3135
3985
|
{
|
|
3136
3986
|
relativePath: "src/migrations/hearth",
|
|
3137
3987
|
label: "Hearth migrations directory"
|
|
@@ -3142,9 +3992,9 @@ var PATHS_TO_REMOVE = [
|
|
|
3142
3992
|
},
|
|
3143
3993
|
{ relativePath: "src/utils/hearth-helpers.ts", label: "Hearth helpers file" }
|
|
3144
3994
|
];
|
|
3145
|
-
async function
|
|
3995
|
+
async function main20() {
|
|
3146
3996
|
for (const { relativePath, label } of PATHS_TO_REMOVE) {
|
|
3147
|
-
const absolutePath =
|
|
3997
|
+
const absolutePath = import_path20.default.join(process.cwd(), relativePath);
|
|
3148
3998
|
if (fs2.existsSync(absolutePath)) {
|
|
3149
3999
|
fs2.rmSync(absolutePath, { recursive: true, force: true });
|
|
3150
4000
|
console.log(`Removed ${label} '${relativePath}'.`);
|
|
@@ -3155,9 +4005,9 @@ async function main15() {
|
|
|
3155
4005
|
}
|
|
3156
4006
|
|
|
3157
4007
|
// src/migrations/v2.0/create-events-index.ts
|
|
3158
|
-
var
|
|
3159
|
-
var
|
|
3160
|
-
var
|
|
4008
|
+
var import_ts_morph19 = require("ts-morph");
|
|
4009
|
+
var import_fs2 = __toESM(require("fs"));
|
|
4010
|
+
var import_path21 = __toESM(require("path"));
|
|
3161
4011
|
var DEFINE_CONFIG_NAME5 = "defineConfig";
|
|
3162
4012
|
var HANDLER_FUNCTION_NAMES = /* @__PURE__ */ new Set([
|
|
3163
4013
|
"getCustomEventsHandler",
|
|
@@ -3179,7 +4029,7 @@ var LICENSE_HEADER = `/*
|
|
|
3179
4029
|
`;
|
|
3180
4030
|
function findEventConfigExports(project, srcDir) {
|
|
3181
4031
|
const found = [];
|
|
3182
|
-
const eventsIndexAbs =
|
|
4032
|
+
const eventsIndexAbs = import_path21.default.join(srcDir, "events", "index.ts");
|
|
3183
4033
|
for (const sourceFile of project.getSourceFiles()) {
|
|
3184
4034
|
const filePath = sourceFile.getFilePath();
|
|
3185
4035
|
if (!filePath.startsWith(srcDir) || filePath.includes("/node_modules/")) {
|
|
@@ -3191,10 +4041,10 @@ function findEventConfigExports(project, srcDir) {
|
|
|
3191
4041
|
for (const decl of statement.getDeclarations()) {
|
|
3192
4042
|
const initializer = decl.getInitializer();
|
|
3193
4043
|
if (!initializer) continue;
|
|
3194
|
-
const unwrapped =
|
|
3195
|
-
if (!
|
|
4044
|
+
const unwrapped = import_ts_morph19.Node.isAsExpression(initializer) ? initializer.getExpression() : initializer;
|
|
4045
|
+
if (!import_ts_morph19.Node.isCallExpression(unwrapped)) continue;
|
|
3196
4046
|
const callee = unwrapped.getExpression();
|
|
3197
|
-
if (!
|
|
4047
|
+
if (!import_ts_morph19.Node.isIdentifier(callee)) continue;
|
|
3198
4048
|
if (callee.getText() !== DEFINE_CONFIG_NAME5) continue;
|
|
3199
4049
|
found.push({ name: decl.getName(), filePath });
|
|
3200
4050
|
}
|
|
@@ -3203,8 +4053,8 @@ function findEventConfigExports(project, srcDir) {
|
|
|
3203
4053
|
return found;
|
|
3204
4054
|
}
|
|
3205
4055
|
function buildIndexImportSpecifier(eventConfigFilePath, srcDir) {
|
|
3206
|
-
const eventsIndexDir =
|
|
3207
|
-
let rel =
|
|
4056
|
+
const eventsIndexDir = import_path21.default.join(srcDir, "events");
|
|
4057
|
+
let rel = import_path21.default.relative(eventsIndexDir, eventConfigFilePath).split(import_path21.default.sep).join("/");
|
|
3208
4058
|
if (rel.endsWith(".ts")) rel = rel.slice(0, -".ts".length);
|
|
3209
4059
|
if (rel.endsWith("/index")) rel = rel.slice(0, -"/index".length);
|
|
3210
4060
|
if (!rel.startsWith(".")) rel = "./" + rel;
|
|
@@ -3281,17 +4131,17 @@ function modifyHandler(sourceFile, exportNames) {
|
|
|
3281
4131
|
);
|
|
3282
4132
|
}
|
|
3283
4133
|
for (const call of sourceFile.getDescendantsOfKind(
|
|
3284
|
-
|
|
4134
|
+
import_ts_morph19.SyntaxKind.CallExpression
|
|
3285
4135
|
)) {
|
|
3286
4136
|
const callee = call.getExpression();
|
|
3287
|
-
if (!
|
|
4137
|
+
if (!import_ts_morph19.Node.isPropertyAccessExpression(callee)) continue;
|
|
3288
4138
|
if (callee.getName() !== RESPONSE_METHOD_NAME) continue;
|
|
3289
4139
|
const args2 = call.getArguments();
|
|
3290
4140
|
if (args2.length !== 1) continue;
|
|
3291
4141
|
const [arg] = args2;
|
|
3292
|
-
if (!
|
|
4142
|
+
if (!import_ts_morph19.Node.isArrayLiteralExpression(arg)) continue;
|
|
3293
4143
|
if (arg.getElements().length === 0) continue;
|
|
3294
|
-
if (!arg.getElements().every((el) =>
|
|
4144
|
+
if (!arg.getElements().every((el) => import_ts_morph19.Node.isIdentifier(el))) continue;
|
|
3295
4145
|
arg.replaceWithText(EVENT_CONFIGS_IDENTIFIER);
|
|
3296
4146
|
changes.push(
|
|
3297
4147
|
`rewrote h.response([...]) \u2192 h.response(${EVENT_CONFIGS_IDENTIFIER})`
|
|
@@ -3299,13 +4149,13 @@ function modifyHandler(sourceFile, exportNames) {
|
|
|
3299
4149
|
}
|
|
3300
4150
|
return changes;
|
|
3301
4151
|
}
|
|
3302
|
-
async function
|
|
3303
|
-
const
|
|
3304
|
-
const srcDir =
|
|
4152
|
+
async function main21() {
|
|
4153
|
+
const cwd = process.cwd();
|
|
4154
|
+
const srcDir = import_path21.default.join(cwd, "src");
|
|
3305
4155
|
console.log(`Scanning for defineConfig event exports in: ${srcDir}
|
|
3306
4156
|
`);
|
|
3307
|
-
const project = new
|
|
3308
|
-
tsConfigFilePath:
|
|
4157
|
+
const project = new import_ts_morph19.Project({
|
|
4158
|
+
tsConfigFilePath: import_path21.default.resolve(srcDir, "../tsconfig.json"),
|
|
3309
4159
|
skipAddingFilesFromTsConfig: false
|
|
3310
4160
|
});
|
|
3311
4161
|
const eventConfigExports = findEventConfigExports(project, srcDir);
|
|
@@ -3317,15 +4167,15 @@ async function main16() {
|
|
|
3317
4167
|
}
|
|
3318
4168
|
console.log(`Found ${eventConfigExports.length} event config export(s):`);
|
|
3319
4169
|
for (const e of eventConfigExports) {
|
|
3320
|
-
console.log(` ${e.name} \u2190 ${
|
|
4170
|
+
console.log(` ${e.name} \u2190 ${import_path21.default.relative(cwd, e.filePath)}`);
|
|
3321
4171
|
}
|
|
3322
|
-
const eventsIndexAbs =
|
|
3323
|
-
const eventsIndexRel =
|
|
3324
|
-
if (
|
|
4172
|
+
const eventsIndexAbs = import_path21.default.join(srcDir, "events", "index.ts");
|
|
4173
|
+
const eventsIndexRel = import_path21.default.relative(cwd, eventsIndexAbs);
|
|
4174
|
+
if (import_fs2.default.existsSync(eventsIndexAbs)) {
|
|
3325
4175
|
console.log(`
|
|
3326
4176
|
[${eventsIndexRel}] already exists \u2014 leaving untouched.`);
|
|
3327
4177
|
} else {
|
|
3328
|
-
|
|
4178
|
+
import_fs2.default.mkdirSync(import_path21.default.dirname(eventsIndexAbs), { recursive: true });
|
|
3329
4179
|
const source = buildEventsIndexSource(eventConfigExports, srcDir);
|
|
3330
4180
|
const eventsIndexFile = project.createSourceFile(eventsIndexAbs, source, {
|
|
3331
4181
|
overwrite: false
|
|
@@ -3346,7 +4196,7 @@ No event-config handler file found (looked for exported function(s): ${Array.fro
|
|
|
3346
4196
|
);
|
|
3347
4197
|
return;
|
|
3348
4198
|
}
|
|
3349
|
-
const handlerRelPath =
|
|
4199
|
+
const handlerRelPath = import_path21.default.relative(cwd, handler.getFilePath());
|
|
3350
4200
|
const exportNameSet = new Set(eventConfigExports.map((e) => e.name));
|
|
3351
4201
|
const changes = modifyHandler(handler, exportNameSet);
|
|
3352
4202
|
if (changes.length === 0) {
|
|
@@ -3363,15 +4213,16 @@ Saved ${handlerRelPath}.`);
|
|
|
3363
4213
|
// src/migrations/v2.0/checkout-upstream-files.ts
|
|
3364
4214
|
var import_child_process = require("child_process");
|
|
3365
4215
|
var UPSTREAM_URL = "https://github.com/opencrvs/opencrvs-countryconfig.git";
|
|
3366
|
-
var UPSTREAM_BRANCH = "
|
|
4216
|
+
var UPSTREAM_BRANCH = "release-v2.0.0";
|
|
3367
4217
|
var TEMP_REMOTE = "opencrvs-upgrade-v19-v20-codemod";
|
|
3368
4218
|
var FILES_TO_CHECKOUT = [
|
|
3369
|
-
"
|
|
3370
|
-
"
|
|
4219
|
+
"src/analytics/analytics.ts",
|
|
4220
|
+
"Dockerfile",
|
|
4221
|
+
"Dockerfile.assets"
|
|
3371
4222
|
];
|
|
3372
4223
|
function runGit(args2, { silent = false } = {}) {
|
|
3373
4224
|
return (0, import_child_process.execFileSync)("git", args2, {
|
|
3374
|
-
cwd:
|
|
4225
|
+
cwd: process.cwd(),
|
|
3375
4226
|
encoding: "utf8",
|
|
3376
4227
|
stdio: silent ? ["ignore", "pipe", "pipe"] : ["ignore", "pipe", "inherit"]
|
|
3377
4228
|
});
|
|
@@ -3387,11 +4238,11 @@ function tryGit(args2) {
|
|
|
3387
4238
|
function assertIsGitRepo() {
|
|
3388
4239
|
if (!tryGit(["rev-parse", "--is-inside-work-tree"])) {
|
|
3389
4240
|
throw new Error(
|
|
3390
|
-
|
|
4241
|
+
`${process.cwd()} is not a git repository. Initialise git (or run the upgrade inside a git checkout) before re-running.`
|
|
3391
4242
|
);
|
|
3392
4243
|
}
|
|
3393
4244
|
}
|
|
3394
|
-
async function
|
|
4245
|
+
async function main22() {
|
|
3395
4246
|
console.log(
|
|
3396
4247
|
`Checking out ${FILES_TO_CHECKOUT.length} file(s) from ${UPSTREAM_URL}@${UPSTREAM_BRANCH}...
|
|
3397
4248
|
`
|
|
@@ -3439,10 +4290,356 @@ async function main17() {
|
|
|
3439
4290
|
}
|
|
3440
4291
|
}
|
|
3441
4292
|
|
|
4293
|
+
// src/migrations/v2.0/add-resend-invite-notification.ts
|
|
4294
|
+
var import_fs3 = require("fs");
|
|
4295
|
+
var import_path22 = __toESM(require("path"));
|
|
4296
|
+
var import_ts_morph20 = require("ts-morph");
|
|
4297
|
+
var TS_MORPH_PROJECT_OPTIONS = {
|
|
4298
|
+
skipAddingFilesFromTsConfig: true,
|
|
4299
|
+
manipulationSettings: {
|
|
4300
|
+
indentationText: import_ts_morph20.IndentationText.TwoSpaces
|
|
4301
|
+
}
|
|
4302
|
+
};
|
|
4303
|
+
var EMAIL_TEMPLATES_INDEX = "src/api/notification/email-templates/index.ts";
|
|
4304
|
+
var NOTIFICATION_HANDLER = "src/api/notification/handler.ts";
|
|
4305
|
+
var USER_NOTIFICATION_ROUTES = "src/config/routes/userNotificationRoutes.ts";
|
|
4306
|
+
var SMS_SERVICE = "src/api/notification/sms-service.ts";
|
|
4307
|
+
var NOTIFICATION_CSV = "src/translations/notification.csv";
|
|
4308
|
+
var RESEND_INVITE_HTML = "src/api/notification/email-templates/other/resend-invite.html";
|
|
4309
|
+
var RESEND_INVITE_HTML_CONTENT = `<!doctype html>
|
|
4310
|
+
<html>
|
|
4311
|
+
<head>
|
|
4312
|
+
<link
|
|
4313
|
+
href="https://fonts.googleapis.com/css2?family=Noto+Sans:wght@400;700&display=swap"
|
|
4314
|
+
rel="stylesheet"
|
|
4315
|
+
/>
|
|
4316
|
+
<style type="text/css">
|
|
4317
|
+
body {
|
|
4318
|
+
font-family: 'Noto Sans', sans-serif;
|
|
4319
|
+
color: #222;
|
|
4320
|
+
padding: 16px 24px;
|
|
4321
|
+
}
|
|
4322
|
+
|
|
4323
|
+
h1 {
|
|
4324
|
+
font-size: 21px;
|
|
4325
|
+
margin-top: 32px;
|
|
4326
|
+
margin-bottom: 36px;
|
|
4327
|
+
font-weight: 700;
|
|
4328
|
+
}
|
|
4329
|
+
|
|
4330
|
+
p {
|
|
4331
|
+
font-weight: 400;
|
|
4332
|
+
font-size: 16px;
|
|
4333
|
+
line-height: 1.8;
|
|
4334
|
+
margin-bottom: 24px;
|
|
4335
|
+
}
|
|
4336
|
+
|
|
4337
|
+
i {
|
|
4338
|
+
color: #666;
|
|
4339
|
+
font-weight: 400;
|
|
4340
|
+
font-size: 16px;
|
|
4341
|
+
}
|
|
4342
|
+
</style>
|
|
4343
|
+
</head>
|
|
4344
|
+
|
|
4345
|
+
<body>
|
|
4346
|
+
<img
|
|
4347
|
+
src="{{countryLogo}}"
|
|
4348
|
+
alt="country_logo"
|
|
4349
|
+
style="max-height: 88px; max-width: 100%"
|
|
4350
|
+
/>
|
|
4351
|
+
<h1>Your {{applicationName}} account invitation</h1>
|
|
4352
|
+
<p>Hello {{firstname}},</p>
|
|
4353
|
+
<p>Your account invitation has been resent. Please use the following credentials to access your account:</p>
|
|
4354
|
+
<p>
|
|
4355
|
+
Username: <strong>{{username}}</strong><br />
|
|
4356
|
+
Password: <strong>{{temporaryPassword}}</strong>
|
|
4357
|
+
</p>
|
|
4358
|
+
<p>
|
|
4359
|
+
Please click the link below to complete your account setup and start using
|
|
4360
|
+
{{applicationName}}.
|
|
4361
|
+
</p>
|
|
4362
|
+
|
|
4363
|
+
<div style="margin-top: 32px; margin-bottom: 32px">
|
|
4364
|
+
<a href="{{loginURL}}">Complete setup</a>
|
|
4365
|
+
</div>
|
|
4366
|
+
<br />
|
|
4367
|
+
<p>
|
|
4368
|
+
Best regards, <br />
|
|
4369
|
+
{{applicationName}} Team
|
|
4370
|
+
</p>
|
|
4371
|
+
</body>
|
|
4372
|
+
</html>
|
|
4373
|
+
`;
|
|
4374
|
+
var CSV_ROW = "resendInviteNotification,The SMS message that is sent when a user invitation is resent,Your OpenCRVS account invitation was resent. Please login with your username: {{username}} and temporary password: {{temporaryPassword}},Votre invitation de compte OpenCRVS a \xE9t\xE9 renvoy\xE9e. Veuillez vous connecter avec votre nom d'utilisateur : {{username}} et votre mot de passe temporaire : {{temporaryPassword}}.\n";
|
|
4375
|
+
function getObjectLiteralFromConst(declaration) {
|
|
4376
|
+
if (!declaration) {
|
|
4377
|
+
return;
|
|
4378
|
+
}
|
|
4379
|
+
const initializer = declaration.getInitializer();
|
|
4380
|
+
if (!initializer) {
|
|
4381
|
+
return;
|
|
4382
|
+
}
|
|
4383
|
+
if (import_ts_morph20.Node.isObjectLiteralExpression(initializer)) {
|
|
4384
|
+
return initializer;
|
|
4385
|
+
}
|
|
4386
|
+
if (import_ts_morph20.Node.isAsExpression(initializer)) {
|
|
4387
|
+
const expression = initializer.getExpression();
|
|
4388
|
+
if (import_ts_morph20.Node.isObjectLiteralExpression(expression)) {
|
|
4389
|
+
return expression;
|
|
4390
|
+
}
|
|
4391
|
+
}
|
|
4392
|
+
if (import_ts_morph20.Node.isSatisfiesExpression(initializer)) {
|
|
4393
|
+
const expression = initializer.getExpression();
|
|
4394
|
+
if (import_ts_morph20.Node.isObjectLiteralExpression(expression)) {
|
|
4395
|
+
return expression;
|
|
4396
|
+
}
|
|
4397
|
+
}
|
|
4398
|
+
}
|
|
4399
|
+
function patchEmailTemplatesIndex() {
|
|
4400
|
+
const full = import_path22.default.join(process.cwd(), EMAIL_TEMPLATES_INDEX);
|
|
4401
|
+
if (!(0, import_fs3.existsSync)(full)) {
|
|
4402
|
+
console.log(` '${EMAIL_TEMPLATES_INDEX}' missing \u2014 skipping.`);
|
|
4403
|
+
return false;
|
|
4404
|
+
}
|
|
4405
|
+
const project = new import_ts_morph20.Project(TS_MORPH_PROJECT_OPTIONS);
|
|
4406
|
+
const sourceFile = project.addSourceFileAtPath(full);
|
|
4407
|
+
let changed = false;
|
|
4408
|
+
const triggerVariableObject = getObjectLiteralFromConst(
|
|
4409
|
+
sourceFile.getVariableDeclaration("TriggerVariable")
|
|
4410
|
+
);
|
|
4411
|
+
if (triggerVariableObject) {
|
|
4412
|
+
const hasResendInviteVariable = triggerVariableObject.getProperties().some((prop) => prop.getText().includes("[TriggerEvent.RESEND_INVITE]"));
|
|
4413
|
+
if (!hasResendInviteVariable) {
|
|
4414
|
+
const properties = triggerVariableObject.getProperties();
|
|
4415
|
+
const lastProperty = properties[properties.length - 1];
|
|
4416
|
+
if (lastProperty) {
|
|
4417
|
+
sourceFile.insertText(
|
|
4418
|
+
lastProperty.getEnd(),
|
|
4419
|
+
`,
|
|
4420
|
+
[TriggerEvent.RESEND_INVITE]: z.object({
|
|
4421
|
+
firstname: z.string(),
|
|
4422
|
+
username: z.string(),
|
|
4423
|
+
temporaryPassword: z.string(),
|
|
4424
|
+
completeSetupUrl: z.string(),
|
|
4425
|
+
loginURL: z.string()
|
|
4426
|
+
})`
|
|
4427
|
+
);
|
|
4428
|
+
changed = true;
|
|
4429
|
+
}
|
|
4430
|
+
}
|
|
4431
|
+
}
|
|
4432
|
+
const templatesObject = getObjectLiteralFromConst(
|
|
4433
|
+
sourceFile.getVariableDeclaration("templates")
|
|
4434
|
+
);
|
|
4435
|
+
if (templatesObject) {
|
|
4436
|
+
const hasResendInviteTemplate = templatesObject.getProperties().some(
|
|
4437
|
+
(prop) => prop.getText().includes("readOtherTemplate<TriggerVariable['resend-invite']>")
|
|
4438
|
+
);
|
|
4439
|
+
if (!hasResendInviteTemplate) {
|
|
4440
|
+
const userCreatedProp = templatesObject.getProperties().find((prop) => prop.getText().includes("[TriggerEvent.USER_CREATED]"));
|
|
4441
|
+
const anchor = userCreatedProp ?? templatesObject.getProperties()[templatesObject.getProperties().length - 1];
|
|
4442
|
+
if (anchor) {
|
|
4443
|
+
sourceFile.insertText(
|
|
4444
|
+
anchor.getEnd(),
|
|
4445
|
+
`,
|
|
4446
|
+
[TriggerEvent.RESEND_INVITE]: {
|
|
4447
|
+
type: 'resend-invite',
|
|
4448
|
+
subject: 'Your OpenCRVS account invitation',
|
|
4449
|
+
template:
|
|
4450
|
+
readOtherTemplate<TriggerVariable['resend-invite']>('resend-invite')
|
|
4451
|
+
}`
|
|
4452
|
+
);
|
|
4453
|
+
changed = true;
|
|
4454
|
+
}
|
|
4455
|
+
}
|
|
4456
|
+
}
|
|
4457
|
+
if (changed) {
|
|
4458
|
+
sourceFile.saveSync();
|
|
4459
|
+
}
|
|
4460
|
+
return changed;
|
|
4461
|
+
}
|
|
4462
|
+
function patchNotificationHandler() {
|
|
4463
|
+
const full = import_path22.default.join(process.cwd(), NOTIFICATION_HANDLER);
|
|
4464
|
+
if (!(0, import_fs3.existsSync)(full)) {
|
|
4465
|
+
return false;
|
|
4466
|
+
}
|
|
4467
|
+
const project = new import_ts_morph20.Project(TS_MORPH_PROJECT_OPTIONS);
|
|
4468
|
+
const sourceFile = project.addSourceFileAtPath(full);
|
|
4469
|
+
const convertFn = sourceFile.getFunction("convertPayloadToVariable");
|
|
4470
|
+
if (!convertFn) {
|
|
4471
|
+
return false;
|
|
4472
|
+
}
|
|
4473
|
+
const switchStmt = convertFn.getFirstDescendantByKind(
|
|
4474
|
+
import_ts_morph20.SyntaxKind.SwitchStatement
|
|
4475
|
+
);
|
|
4476
|
+
if (!switchStmt) {
|
|
4477
|
+
return false;
|
|
4478
|
+
}
|
|
4479
|
+
const clauses = switchStmt.getCaseBlock().getClauses();
|
|
4480
|
+
const hasResendInvite = clauses.some(
|
|
4481
|
+
(clause) => import_ts_morph20.Node.isCaseClause(clause) && clause.getExpression().getText() === "TriggerEvent.RESEND_INVITE"
|
|
4482
|
+
);
|
|
4483
|
+
if (hasResendInvite) {
|
|
4484
|
+
return false;
|
|
4485
|
+
}
|
|
4486
|
+
const userCreatedClauseIndex = clauses.findIndex(
|
|
4487
|
+
(clause) => import_ts_morph20.Node.isCaseClause(clause) && clause.getExpression().getText() === "TriggerEvent.USER_CREATED"
|
|
4488
|
+
);
|
|
4489
|
+
if (userCreatedClauseIndex < 0) {
|
|
4490
|
+
return false;
|
|
4491
|
+
}
|
|
4492
|
+
const userCreatedClause = clauses[userCreatedClauseIndex];
|
|
4493
|
+
sourceFile.insertText(
|
|
4494
|
+
userCreatedClause.getEnd(),
|
|
4495
|
+
`
|
|
4496
|
+
|
|
4497
|
+
case TriggerEvent.RESEND_INVITE:
|
|
4498
|
+
return {
|
|
4499
|
+
firstname,
|
|
4500
|
+
username: payload.username,
|
|
4501
|
+
temporaryPassword: payload.temporaryPassword,
|
|
4502
|
+
completeSetupUrl: LOGIN_URL,
|
|
4503
|
+
loginURL: LOGIN_URL
|
|
4504
|
+
}`
|
|
4505
|
+
);
|
|
4506
|
+
sourceFile.saveSync();
|
|
4507
|
+
return true;
|
|
4508
|
+
}
|
|
4509
|
+
function getReturnedArrayLiteral(functionFilePath, fnName) {
|
|
4510
|
+
const project = new import_ts_morph20.Project(TS_MORPH_PROJECT_OPTIONS);
|
|
4511
|
+
const sourceFile = project.addSourceFileAtPath(functionFilePath);
|
|
4512
|
+
const fn = sourceFile.getFunction(fnName);
|
|
4513
|
+
const returnStmt = fn?.getFirstDescendantByKind(import_ts_morph20.SyntaxKind.ReturnStatement);
|
|
4514
|
+
const expr = returnStmt?.getExpression();
|
|
4515
|
+
if (!expr || !import_ts_morph20.Node.isArrayLiteralExpression(expr)) {
|
|
4516
|
+
return { sourceFile, arrayLiteral: void 0 };
|
|
4517
|
+
}
|
|
4518
|
+
return { sourceFile, arrayLiteral: expr };
|
|
4519
|
+
}
|
|
4520
|
+
function patchUserNotificationRoutes() {
|
|
4521
|
+
const full = import_path22.default.join(process.cwd(), USER_NOTIFICATION_ROUTES);
|
|
4522
|
+
if (!(0, import_fs3.existsSync)(full)) {
|
|
4523
|
+
return false;
|
|
4524
|
+
}
|
|
4525
|
+
const { sourceFile, arrayLiteral } = getReturnedArrayLiteral(
|
|
4526
|
+
full,
|
|
4527
|
+
"getUserNotificationRoutes"
|
|
4528
|
+
);
|
|
4529
|
+
if (!arrayLiteral) {
|
|
4530
|
+
return false;
|
|
4531
|
+
}
|
|
4532
|
+
const elements = arrayLiteral.getElements();
|
|
4533
|
+
const routeExists = elements.some(
|
|
4534
|
+
(element) => element.getText().includes(`path: '/triggers/user/resend-invite'`)
|
|
4535
|
+
);
|
|
4536
|
+
if (routeExists) {
|
|
4537
|
+
return false;
|
|
4538
|
+
}
|
|
4539
|
+
const anchor = elements.find(
|
|
4540
|
+
(element) => element.getText().includes(`path: '/triggers/user/user-created'`)
|
|
4541
|
+
) ?? elements[elements.length - 1];
|
|
4542
|
+
if (!anchor) {
|
|
4543
|
+
return false;
|
|
4544
|
+
}
|
|
4545
|
+
sourceFile.insertText(
|
|
4546
|
+
anchor.getEnd(),
|
|
4547
|
+
`,
|
|
4548
|
+
{
|
|
4549
|
+
method: 'POST',
|
|
4550
|
+
path: '/triggers/user/resend-invite',
|
|
4551
|
+
handler: makeNotificationHandler('resend-invite'),
|
|
4552
|
+
options: {
|
|
4553
|
+
auth: false,
|
|
4554
|
+
tags: ['api'],
|
|
4555
|
+
description: 'Handles notification for resent user invite'
|
|
4556
|
+
}
|
|
4557
|
+
}`
|
|
4558
|
+
);
|
|
4559
|
+
sourceFile.saveSync();
|
|
4560
|
+
return true;
|
|
4561
|
+
}
|
|
4562
|
+
function patchSmsService() {
|
|
4563
|
+
const full = import_path22.default.join(process.cwd(), SMS_SERVICE);
|
|
4564
|
+
if (!(0, import_fs3.existsSync)(full)) {
|
|
4565
|
+
return false;
|
|
4566
|
+
}
|
|
4567
|
+
const project = new import_ts_morph20.Project(TS_MORPH_PROJECT_OPTIONS);
|
|
4568
|
+
const sourceFile = project.addSourceFileAtPath(full);
|
|
4569
|
+
let changed = false;
|
|
4570
|
+
const otherTemplatesObject = getObjectLiteralFromConst(
|
|
4571
|
+
sourceFile.getVariableDeclaration("otherTemplates")
|
|
4572
|
+
);
|
|
4573
|
+
if (otherTemplatesObject) {
|
|
4574
|
+
const hasResendTemplate = otherTemplatesObject.getProperties().some((prop) => prop.getText().includes("resendInviteNotification"));
|
|
4575
|
+
if (!hasResendTemplate) {
|
|
4576
|
+
const userCredentialsIndex = otherTemplatesObject.getProperties().findIndex((prop) => prop.getText().includes("userCredentialsNotification"));
|
|
4577
|
+
otherTemplatesObject.insertPropertyAssignment(
|
|
4578
|
+
userCredentialsIndex >= 0 ? userCredentialsIndex + 1 : otherTemplatesObject.getProperties().length,
|
|
4579
|
+
{
|
|
4580
|
+
name: "resendInviteNotification",
|
|
4581
|
+
initializer: `'resendInviteNotification'`
|
|
4582
|
+
}
|
|
4583
|
+
);
|
|
4584
|
+
changed = true;
|
|
4585
|
+
}
|
|
4586
|
+
}
|
|
4587
|
+
const triggerToSmsTemplateObject = getObjectLiteralFromConst(
|
|
4588
|
+
sourceFile.getVariableDeclaration("TriggerToSMSTemplate")
|
|
4589
|
+
);
|
|
4590
|
+
if (triggerToSmsTemplateObject) {
|
|
4591
|
+
const hasResendInviteMap = triggerToSmsTemplateObject.getProperties().some((prop) => prop.getText().includes(`['resend-invite']`));
|
|
4592
|
+
if (!hasResendInviteMap) {
|
|
4593
|
+
const userCreatedIndex = triggerToSmsTemplateObject.getProperties().findIndex((prop) => prop.getText().includes(`['user-created']`));
|
|
4594
|
+
triggerToSmsTemplateObject.insertPropertyAssignment(
|
|
4595
|
+
userCreatedIndex >= 0 ? userCreatedIndex + 1 : triggerToSmsTemplateObject.getProperties().length,
|
|
4596
|
+
{
|
|
4597
|
+
name: `['resend-invite']`,
|
|
4598
|
+
initializer: `'resendInviteNotification'`
|
|
4599
|
+
}
|
|
4600
|
+
);
|
|
4601
|
+
changed = true;
|
|
4602
|
+
}
|
|
4603
|
+
}
|
|
4604
|
+
if (changed) {
|
|
4605
|
+
sourceFile.saveSync();
|
|
4606
|
+
}
|
|
4607
|
+
return changed;
|
|
4608
|
+
}
|
|
4609
|
+
async function main23() {
|
|
4610
|
+
console.log("Adding RESEND_INVITE notification wiring\u2026");
|
|
4611
|
+
const touched = [];
|
|
4612
|
+
if (patchEmailTemplatesIndex()) touched.push(EMAIL_TEMPLATES_INDEX);
|
|
4613
|
+
if (patchNotificationHandler()) touched.push(NOTIFICATION_HANDLER);
|
|
4614
|
+
if (patchUserNotificationRoutes()) touched.push(USER_NOTIFICATION_ROUTES);
|
|
4615
|
+
if (patchSmsService()) touched.push(SMS_SERVICE);
|
|
4616
|
+
const csvPath = import_path22.default.join(process.cwd(), NOTIFICATION_CSV);
|
|
4617
|
+
if ((0, import_fs3.existsSync)(csvPath)) {
|
|
4618
|
+
let t = (0, import_fs3.readFileSync)(csvPath, "utf8");
|
|
4619
|
+
if (!/^resendInviteNotification,/m.test(t)) {
|
|
4620
|
+
if (!t.endsWith("\n")) t += "\n";
|
|
4621
|
+
(0, import_fs3.writeFileSync)(csvPath, t + CSV_ROW);
|
|
4622
|
+
touched.push(NOTIFICATION_CSV);
|
|
4623
|
+
}
|
|
4624
|
+
}
|
|
4625
|
+
const htmlPath = import_path22.default.join(process.cwd(), RESEND_INVITE_HTML);
|
|
4626
|
+
(0, import_fs3.mkdirSync)(import_path22.default.dirname(htmlPath), { recursive: true });
|
|
4627
|
+
if (!(0, import_fs3.existsSync)(htmlPath)) {
|
|
4628
|
+
(0, import_fs3.writeFileSync)(htmlPath, RESEND_INVITE_HTML_CONTENT);
|
|
4629
|
+
touched.push(RESEND_INVITE_HTML);
|
|
4630
|
+
}
|
|
4631
|
+
if (touched.length === 0) {
|
|
4632
|
+
console.log(" Nothing to update (already present or anchors not found).");
|
|
4633
|
+
return;
|
|
4634
|
+
}
|
|
4635
|
+
console.log(` Updated:
|
|
4636
|
+
${touched.map((f) => ` - ${f}`).join("\n")}`);
|
|
4637
|
+
}
|
|
4638
|
+
|
|
3442
4639
|
// src/migrations/v2.0/simplify-analytics-precalculations.ts
|
|
3443
|
-
var
|
|
3444
|
-
var
|
|
3445
|
-
var
|
|
4640
|
+
var import_ts_morph21 = require("ts-morph");
|
|
4641
|
+
var import_fs4 = __toESM(require("fs"));
|
|
4642
|
+
var import_path23 = __toESM(require("path"));
|
|
3446
4643
|
var ANALYTICS_FILE_REL = "src/analytics/analytics.ts";
|
|
3447
4644
|
var FUNCTION_NAME = "precalculateAdditionalAnalytics";
|
|
3448
4645
|
var IMPORT_NAMES_TO_REMOVE = /* @__PURE__ */ new Set(["Event", "precalculateBirthEvent"]);
|
|
@@ -3478,10 +4675,10 @@ function findPrecalculateFunction(sourceFile) {
|
|
|
3478
4675
|
return void 0;
|
|
3479
4676
|
}
|
|
3480
4677
|
function getFunctionBodyBlock(fn) {
|
|
3481
|
-
if (
|
|
4678
|
+
if (import_ts_morph21.Node.isFunctionDeclaration(fn)) return fn.getBody();
|
|
3482
4679
|
const initializer = fn.getInitializer();
|
|
3483
4680
|
if (!initializer) return void 0;
|
|
3484
|
-
if (!
|
|
4681
|
+
if (!import_ts_morph21.Node.isArrowFunction(initializer) && !import_ts_morph21.Node.isFunctionExpression(initializer)) {
|
|
3485
4682
|
return void 0;
|
|
3486
4683
|
}
|
|
3487
4684
|
return initializer.getBody();
|
|
@@ -3491,9 +4688,9 @@ function simplifyPrecalculateFunction(sourceFile) {
|
|
|
3491
4688
|
const fn = findPrecalculateFunction(sourceFile);
|
|
3492
4689
|
if (!fn) return log;
|
|
3493
4690
|
const body = getFunctionBodyBlock(fn);
|
|
3494
|
-
if (!body || !
|
|
4691
|
+
if (!body || !import_ts_morph21.Node.isBlock(body)) return log;
|
|
3495
4692
|
for (const statement of [...body.getStatements()]) {
|
|
3496
|
-
const references = statement.getDescendantsOfKind(
|
|
4693
|
+
const references = statement.getDescendantsOfKind(import_ts_morph21.SyntaxKind.Identifier).some((id) => IMPORT_NAMES_TO_REMOVE.has(id.getText()));
|
|
3497
4694
|
if (references) {
|
|
3498
4695
|
statement.remove();
|
|
3499
4696
|
log.push(`removed statement in ${FUNCTION_NAME} referencing removed imports`);
|
|
@@ -3501,7 +4698,7 @@ function simplifyPrecalculateFunction(sourceFile) {
|
|
|
3501
4698
|
}
|
|
3502
4699
|
const remaining = body.getStatements();
|
|
3503
4700
|
const last = remaining[remaining.length - 1];
|
|
3504
|
-
const alreadyCorrect = last &&
|
|
4701
|
+
const alreadyCorrect = last && import_ts_morph21.Node.isReturnStatement(last) && last.getExpression()?.getText() === RETURN_EXPRESSION_TEXT;
|
|
3505
4702
|
if (!alreadyCorrect) {
|
|
3506
4703
|
body.addStatements(`return ${RETURN_EXPRESSION_TEXT}`);
|
|
3507
4704
|
log.push(
|
|
@@ -3510,17 +4707,17 @@ function simplifyPrecalculateFunction(sourceFile) {
|
|
|
3510
4707
|
}
|
|
3511
4708
|
return log;
|
|
3512
4709
|
}
|
|
3513
|
-
async function
|
|
3514
|
-
const
|
|
3515
|
-
const absPath =
|
|
3516
|
-
if (!
|
|
4710
|
+
async function main24() {
|
|
4711
|
+
const cwd = process.cwd();
|
|
4712
|
+
const absPath = import_path23.default.join(cwd, ANALYTICS_FILE_REL);
|
|
4713
|
+
if (!import_fs4.default.existsSync(absPath)) {
|
|
3517
4714
|
console.log(
|
|
3518
4715
|
`[${ANALYTICS_FILE_REL}] does not exist \u2014 nothing to clean up.`
|
|
3519
4716
|
);
|
|
3520
4717
|
return;
|
|
3521
4718
|
}
|
|
3522
|
-
const project = new
|
|
3523
|
-
tsConfigFilePath:
|
|
4719
|
+
const project = new import_ts_morph21.Project({
|
|
4720
|
+
tsConfigFilePath: import_path23.default.resolve(cwd, "tsconfig.json"),
|
|
3524
4721
|
skipAddingFilesFromTsConfig: false
|
|
3525
4722
|
});
|
|
3526
4723
|
const sourceFile = project.getSourceFile(absPath);
|
|
@@ -3547,26 +4744,196 @@ async function main18() {
|
|
|
3547
4744
|
Saved ${ANALYTICS_FILE_REL}.`);
|
|
3548
4745
|
}
|
|
3549
4746
|
|
|
3550
|
-
// src/migrations/v2.0/
|
|
3551
|
-
var
|
|
3552
|
-
|
|
3553
|
-
|
|
3554
|
-
|
|
4747
|
+
// src/migrations/v2.0/merge-infrastructure-directory.ts
|
|
4748
|
+
var import_child_process2 = require("child_process");
|
|
4749
|
+
var import_fs5 = require("fs");
|
|
4750
|
+
var import_os = require("os");
|
|
4751
|
+
var import_path24 = require("path");
|
|
4752
|
+
var TEMP_REMOTE2 = "opencrvs-upgrade-v19-v20-codemod-merge-infra";
|
|
4753
|
+
var INFRASTRUCTURE_DIR = "infrastructure";
|
|
4754
|
+
var BASE_BRANCH = "release-v1.9";
|
|
4755
|
+
function gitShowBytes(ref, path23) {
|
|
4756
|
+
try {
|
|
4757
|
+
const buf = (0, import_child_process2.execFileSync)("git", ["show", `${ref}:${path23}`], {
|
|
4758
|
+
cwd: process.cwd(),
|
|
4759
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
4760
|
+
});
|
|
4761
|
+
return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
4762
|
+
} catch {
|
|
4763
|
+
return null;
|
|
4764
|
+
}
|
|
4765
|
+
}
|
|
4766
|
+
async function main25({
|
|
4767
|
+
subdirs = []
|
|
4768
|
+
} = {}) {
|
|
4769
|
+
const pathspecs = subdirs.length > 0 ? subdirs.map((s) => `${INFRASTRUCTURE_DIR}/${s}/`) : [`${INFRASTRUCTURE_DIR}/`];
|
|
4770
|
+
const scopeLabel = pathspecs.map((p) => `'${p}'`).join(", ");
|
|
4771
|
+
console.log(
|
|
4772
|
+
`Merging ${scopeLabel} from ${UPSTREAM_URL}@${UPSTREAM_BRANCH} (base: ${BASE_BRANCH})...
|
|
4773
|
+
`
|
|
4774
|
+
);
|
|
4775
|
+
assertIsGitRepo();
|
|
4776
|
+
tryGit(["remote", "remove", TEMP_REMOTE2]);
|
|
4777
|
+
try {
|
|
4778
|
+
console.log(` Adding temporary remote '${TEMP_REMOTE2}' \u2192 ${UPSTREAM_URL}`);
|
|
4779
|
+
runGit(["remote", "add", TEMP_REMOTE2, UPSTREAM_URL], { silent: true });
|
|
4780
|
+
console.log(
|
|
4781
|
+
` Fetching ${TEMP_REMOTE2}/{${UPSTREAM_BRANCH},${BASE_BRANCH}} (depth 1)...`
|
|
4782
|
+
);
|
|
4783
|
+
runGit(["fetch", "--depth=1", TEMP_REMOTE2, UPSTREAM_BRANCH, BASE_BRANCH]);
|
|
4784
|
+
const ref = `${TEMP_REMOTE2}/${UPSTREAM_BRANCH}`;
|
|
4785
|
+
const baseRef = `${TEMP_REMOTE2}/${BASE_BRANCH}`;
|
|
4786
|
+
const upstreamFiles = runGit(
|
|
4787
|
+
["ls-tree", "-r", "--name-only", "-z", ref, "--", ...pathspecs],
|
|
4788
|
+
{ silent: true }
|
|
4789
|
+
).split("\0").filter(Boolean);
|
|
4790
|
+
if (upstreamFiles.length === 0) {
|
|
4791
|
+
console.log(
|
|
4792
|
+
` No files found under ${scopeLabel} on ${ref}. Nothing to merge.`
|
|
4793
|
+
);
|
|
4794
|
+
return;
|
|
4795
|
+
}
|
|
4796
|
+
const tmpDir = (0, import_fs5.mkdtempSync)((0, import_path24.join)((0, import_os.tmpdir)(), "opencrvs-merge-infra-"));
|
|
4797
|
+
const baseTmp = (0, import_path24.join)(tmpDir, "base");
|
|
4798
|
+
const theirsTmp = (0, import_path24.join)(tmpDir, "theirs");
|
|
4799
|
+
let added = 0;
|
|
4800
|
+
let merged = 0;
|
|
4801
|
+
const conflictedFiles = [];
|
|
4802
|
+
for (const file of upstreamFiles) {
|
|
4803
|
+
const fullPath = (0, import_path24.join)(process.cwd(), file);
|
|
4804
|
+
if (!(0, import_fs5.existsSync)(fullPath)) {
|
|
4805
|
+
if (tryGit(["checkout", ref, "--", file])) {
|
|
4806
|
+
console.log(` + ${file} (new from upstream)`);
|
|
4807
|
+
added++;
|
|
4808
|
+
} else {
|
|
4809
|
+
console.warn(` [warn] failed to add new file ${file}`);
|
|
4810
|
+
}
|
|
4811
|
+
continue;
|
|
4812
|
+
}
|
|
4813
|
+
const theirContents = gitShowBytes(ref, file);
|
|
4814
|
+
if (theirContents === null) {
|
|
4815
|
+
console.warn(` [warn] could not read ${file} from ${ref} \u2014 skipping.`);
|
|
4816
|
+
continue;
|
|
4817
|
+
}
|
|
4818
|
+
(0, import_fs5.writeFileSync)(theirsTmp, theirContents);
|
|
4819
|
+
const baseContents = gitShowBytes(baseRef, file);
|
|
4820
|
+
(0, import_fs5.writeFileSync)(baseTmp, baseContents ?? new Uint8Array(0));
|
|
4821
|
+
try {
|
|
4822
|
+
(0, import_child_process2.execFileSync)("git", ["merge-file", fullPath, baseTmp, theirsTmp], {
|
|
4823
|
+
cwd: process.cwd(),
|
|
4824
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
4825
|
+
});
|
|
4826
|
+
runGit(["add", "--", file], { silent: true });
|
|
4827
|
+
merged++;
|
|
4828
|
+
} catch (err) {
|
|
4829
|
+
const status = err.status;
|
|
4830
|
+
if (typeof status === "number" && status > 0) {
|
|
4831
|
+
conflictedFiles.push(file);
|
|
4832
|
+
console.warn(
|
|
4833
|
+
` ! ${file} (${status} conflict${status > 1 ? "s" : ""})`
|
|
4834
|
+
);
|
|
4835
|
+
} else {
|
|
4836
|
+
conflictedFiles.push(file);
|
|
4837
|
+
console.warn(
|
|
4838
|
+
` [warn] merge failed for ${file} (likely binary or unreadable) \u2014 left untouched.`
|
|
4839
|
+
);
|
|
4840
|
+
}
|
|
4841
|
+
}
|
|
4842
|
+
}
|
|
4843
|
+
console.log(
|
|
4844
|
+
`
|
|
4845
|
+
Done. ${added} added, ${merged} merged cleanly, ${conflictedFiles.length} with conflicts.`
|
|
4846
|
+
);
|
|
4847
|
+
if (conflictedFiles.length > 0) {
|
|
4848
|
+
console.warn(
|
|
4849
|
+
`
|
|
4850
|
+
NOTE: ${conflictedFiles.length} file(s) under '${INFRASTRUCTURE_DIR}/' have merge conflicts that you must resolve manually.
|
|
4851
|
+
Look for the standard conflict markers (<<<<<<<, =======, >>>>>>>) in:
|
|
4852
|
+
` + conflictedFiles.map((f) => ` - ${f}`).join("\n") + `
|
|
4853
|
+
After resolving, stage the fixes with: git add ${INFRASTRUCTURE_DIR}/`
|
|
4854
|
+
);
|
|
4855
|
+
}
|
|
4856
|
+
} finally {
|
|
4857
|
+
if (tryGit(["remote", "remove", TEMP_REMOTE2])) {
|
|
4858
|
+
console.log(` Removed temporary remote '${TEMP_REMOTE2}'.`);
|
|
4859
|
+
}
|
|
3555
4860
|
}
|
|
3556
|
-
return cwd;
|
|
3557
4861
|
}
|
|
3558
|
-
|
|
3559
|
-
|
|
3560
|
-
|
|
3561
|
-
|
|
4862
|
+
|
|
4863
|
+
// src/migrations/v2.0/delete-infrastructure-directory.ts
|
|
4864
|
+
var import_fs6 = require("fs");
|
|
4865
|
+
var import_path25 = require("path");
|
|
4866
|
+
var INFRASTRUCTURE_DIR2 = "infrastructure";
|
|
4867
|
+
async function main26({
|
|
4868
|
+
keep = []
|
|
4869
|
+
} = {}) {
|
|
4870
|
+
const fullPath = (0, import_path25.join)(process.cwd(), INFRASTRUCTURE_DIR2);
|
|
4871
|
+
if (!(0, import_fs6.existsSync)(fullPath)) {
|
|
4872
|
+
console.log(
|
|
4873
|
+
`'${INFRASTRUCTURE_DIR2}/' not found in ${process.cwd()} \u2014 nothing to delete.`
|
|
4874
|
+
);
|
|
4875
|
+
return;
|
|
3562
4876
|
}
|
|
3563
|
-
|
|
4877
|
+
assertIsGitRepo();
|
|
4878
|
+
if (keep.length === 0) {
|
|
4879
|
+
console.log(`Deleting '${INFRASTRUCTURE_DIR2}/'...
|
|
4880
|
+
`);
|
|
4881
|
+
runGit(["rm", "-rf", "--ignore-unmatch", "--", `${INFRASTRUCTURE_DIR2}/`], {
|
|
4882
|
+
silent: true
|
|
4883
|
+
});
|
|
4884
|
+
console.log(
|
|
4885
|
+
` Staged deletion of tracked files under '${INFRASTRUCTURE_DIR2}/'.`
|
|
4886
|
+
);
|
|
4887
|
+
if ((0, import_fs6.existsSync)(fullPath)) {
|
|
4888
|
+
(0, import_fs6.rmSync)(fullPath, { recursive: true, force: true });
|
|
4889
|
+
console.log(
|
|
4890
|
+
` Removed remaining untracked files under '${INFRASTRUCTURE_DIR2}/'.`
|
|
4891
|
+
);
|
|
4892
|
+
}
|
|
3564
4893
|
console.log(
|
|
3565
|
-
|
|
4894
|
+
`
|
|
4895
|
+
Done. Review the staged deletion with: git diff --cached -- '${INFRASTRUCTURE_DIR2}/'`
|
|
3566
4896
|
);
|
|
3567
|
-
|
|
4897
|
+
return;
|
|
3568
4898
|
}
|
|
3569
|
-
|
|
4899
|
+
const keepSet = new Set(keep);
|
|
4900
|
+
console.log(
|
|
4901
|
+
`Deleting contents of '${INFRASTRUCTURE_DIR2}/' except: ${[...keepSet].map((name) => `'${name}'`).join(", ")}
|
|
4902
|
+
`
|
|
4903
|
+
);
|
|
4904
|
+
const topLevelEntries = (0, import_fs6.readdirSync)(fullPath, { withFileTypes: true });
|
|
4905
|
+
let deleted = 0;
|
|
4906
|
+
for (const entry of topLevelEntries) {
|
|
4907
|
+
if (keepSet.has(entry.name)) {
|
|
4908
|
+
console.log(` Keeping '${INFRASTRUCTURE_DIR2}/${entry.name}'.`);
|
|
4909
|
+
continue;
|
|
4910
|
+
}
|
|
4911
|
+
const relPath = `${INFRASTRUCTURE_DIR2}/${entry.name}${entry.isDirectory() ? "/" : ""}`;
|
|
4912
|
+
runGit(["rm", "-rf", "--ignore-unmatch", "--", relPath], { silent: true });
|
|
4913
|
+
const fullEntryPath = (0, import_path25.join)(fullPath, entry.name);
|
|
4914
|
+
if ((0, import_fs6.existsSync)(fullEntryPath)) {
|
|
4915
|
+
(0, import_fs6.rmSync)(fullEntryPath, { recursive: true, force: true });
|
|
4916
|
+
}
|
|
4917
|
+
console.log(` Deleted '${relPath}'.`);
|
|
4918
|
+
deleted++;
|
|
4919
|
+
}
|
|
4920
|
+
const presentNames = new Set(topLevelEntries.map((e) => e.name));
|
|
4921
|
+
const missingKeeps = [...keepSet].filter((name) => !presentNames.has(name));
|
|
4922
|
+
if (missingKeeps.length > 0) {
|
|
4923
|
+
console.warn(
|
|
4924
|
+
` [warn] Requested to keep ${missingKeeps.map((n) => `'${n}'`).join(", ")} but they don't exist under '${INFRASTRUCTURE_DIR2}/'.`
|
|
4925
|
+
);
|
|
4926
|
+
}
|
|
4927
|
+
console.log(
|
|
4928
|
+
`
|
|
4929
|
+
Done. Deleted ${deleted} top-level entr${deleted === 1 ? "y" : "ies"}. Review the staged deletions with: git diff --cached -- '${INFRASTRUCTURE_DIR2}/'`
|
|
4930
|
+
);
|
|
4931
|
+
}
|
|
4932
|
+
|
|
4933
|
+
// src/migrations/v2.0/index.ts
|
|
4934
|
+
var NON_SWARM_INFRA_SUBDIRS = ["postgres", "metabase"];
|
|
4935
|
+
async function runUpgrade(dockerSwarm) {
|
|
4936
|
+
await main18();
|
|
3570
4937
|
await main();
|
|
3571
4938
|
await main2();
|
|
3572
4939
|
await main3();
|
|
@@ -3579,11 +4946,23 @@ async function runUpgrade(ccwd) {
|
|
|
3579
4946
|
await main10();
|
|
3580
4947
|
await main11();
|
|
3581
4948
|
await main12();
|
|
4949
|
+
await main13();
|
|
3582
4950
|
await main14();
|
|
3583
4951
|
await main15();
|
|
3584
4952
|
await main16();
|
|
4953
|
+
await main19();
|
|
4954
|
+
await main20();
|
|
4955
|
+
await main21();
|
|
4956
|
+
await main22();
|
|
4957
|
+
await main23();
|
|
4958
|
+
await main24();
|
|
3585
4959
|
await main17();
|
|
3586
|
-
|
|
4960
|
+
if (dockerSwarm) {
|
|
4961
|
+
await main25();
|
|
4962
|
+
} else {
|
|
4963
|
+
await main26({ keep: NON_SWARM_INFRA_SUBDIRS });
|
|
4964
|
+
await main25({ subdirs: NON_SWARM_INFRA_SUBDIRS });
|
|
4965
|
+
}
|
|
3587
4966
|
}
|
|
3588
4967
|
|
|
3589
4968
|
// src/cli.ts
|
|
@@ -3598,7 +4977,20 @@ Commands:
|
|
|
3598
4977
|
|
|
3599
4978
|
Run 'opencrvs <command> --help' for more information on a command.
|
|
3600
4979
|
`.trim();
|
|
3601
|
-
|
|
4980
|
+
var UPGRADE_USAGE = `
|
|
4981
|
+
Usage: opencrvs upgrade [options]
|
|
4982
|
+
|
|
4983
|
+
Upgrade the country config in the current working directory to the next
|
|
4984
|
+
major version of OpenCRVS.
|
|
4985
|
+
|
|
4986
|
+
Options:
|
|
4987
|
+
--docker-swarm Keep and merge the 'infrastructure/' directory with
|
|
4988
|
+
upstream changes. Use this if your country deploys
|
|
4989
|
+
OpenCRVS via Docker Swarm. When omitted, the
|
|
4990
|
+
'infrastructure/' directory is deleted (default).
|
|
4991
|
+
-h, --help Show this message.
|
|
4992
|
+
`.trim();
|
|
4993
|
+
function main27() {
|
|
3602
4994
|
const command = args[0];
|
|
3603
4995
|
if (!command || command === "--help" || command === "-h") {
|
|
3604
4996
|
console.log(USAGE);
|
|
@@ -3643,10 +5035,25 @@ Subcommands:
|
|
|
3643
5035
|
}
|
|
3644
5036
|
}
|
|
3645
5037
|
async function handleUpgrade() {
|
|
5038
|
+
const upgradeArgs = args.slice(1);
|
|
5039
|
+
if (upgradeArgs.includes("--help") || upgradeArgs.includes("-h")) {
|
|
5040
|
+
console.log(UPGRADE_USAGE);
|
|
5041
|
+
process.exit(0);
|
|
5042
|
+
}
|
|
5043
|
+
const KNOWN_FLAGS = /* @__PURE__ */ new Set(["--docker-swarm"]);
|
|
5044
|
+
const unknownFlags = upgradeArgs.filter(
|
|
5045
|
+
(arg) => arg.startsWith("-") && !KNOWN_FLAGS.has(arg)
|
|
5046
|
+
);
|
|
5047
|
+
if (unknownFlags.length > 0) {
|
|
5048
|
+
console.error(`Unknown option(s): ${unknownFlags.join(", ")}
|
|
5049
|
+
`);
|
|
5050
|
+
console.log(UPGRADE_USAGE);
|
|
5051
|
+
process.exit(1);
|
|
5052
|
+
}
|
|
5053
|
+
const dockerSwarm = upgradeArgs.includes("--docker-swarm");
|
|
3646
5054
|
console.log("Initiating upgrade...");
|
|
3647
5055
|
try {
|
|
3648
|
-
|
|
3649
|
-
await runUpgrade(pathToCountryconfig);
|
|
5056
|
+
await runUpgrade(dockerSwarm);
|
|
3650
5057
|
console.log("Upgrade completed successfully!");
|
|
3651
5058
|
} catch (error) {
|
|
3652
5059
|
console.error("Upgrade failed:", error);
|
|
@@ -3658,4 +5065,4 @@ function handleCheckTranslations() {
|
|
|
3658
5065
|
console.warn("This command is not implemented yet!");
|
|
3659
5066
|
process.exit(1);
|
|
3660
5067
|
}
|
|
3661
|
-
|
|
5068
|
+
main27();
|