@opencrvs/toolkit 2.0.0-rc.bee2b7b → 2.0.0-rc.bfc4add
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 +28 -39
- package/dist/cli.js +1845 -360
- package/dist/commons/api/router.d.ts +3016 -300
- package/dist/commons/application-config/index.d.ts +16 -4
- package/dist/commons/conditionals/conditionals.d.ts +6 -6
- package/dist/commons/conditionals/validate.d.ts +1 -0
- package/dist/commons/events/ActionInput.d.ts +108 -0
- package/dist/commons/events/Draft.d.ts +3 -0
- package/dist/commons/events/EventIndex.d.ts +0 -3
- package/dist/commons/events/EventMetadata.d.ts +0 -7
- package/dist/commons/events/FieldConfig.d.ts +10 -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/commons/events/state/index.d.ts +0 -4
- package/dist/commons/events/state/utils.d.ts +0 -2
- package/dist/commons/events/utils.d.ts +1 -1
- package/dist/conditionals/index.js +11 -10
- package/dist/events/index.js +95 -65
- 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 +1813 -357
- 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 +55 -32
- 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 +27 -35
- package/dist/scopes/index.d.ts +8 -1
- package/dist/scopes/index.js +11 -10
- package/opencrvs-toolkit-2.0.0-rc.bfc4add.tgz +0 -0
- package/package.json +1 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/opencrvs-toolkit-2.0.0-rc.bee2b7b.tgz +0 -0
|
@@ -31,7 +31,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
// src/migrations/v2.0/index.ts
|
|
32
32
|
var v2_exports = {};
|
|
33
33
|
__export(v2_exports, {
|
|
34
|
-
getCwd: () => getCwd,
|
|
35
34
|
runUpgrade: () => runUpgrade
|
|
36
35
|
});
|
|
37
36
|
module.exports = __toCommonJS(v2_exports);
|
|
@@ -104,7 +103,7 @@ function processFile(filePath, project) {
|
|
|
104
103
|
if (wasRemoved) {
|
|
105
104
|
removedCount++;
|
|
106
105
|
console.log(
|
|
107
|
-
` [${import_path.default.relative(
|
|
106
|
+
` [${import_path.default.relative(process.cwd(), filePath)}] Removed 'review' from REGISTER action`
|
|
108
107
|
);
|
|
109
108
|
}
|
|
110
109
|
}
|
|
@@ -112,7 +111,7 @@ function processFile(filePath, project) {
|
|
|
112
111
|
return removedCount;
|
|
113
112
|
}
|
|
114
113
|
async function main() {
|
|
115
|
-
const srcDir = import_path.default.join(
|
|
114
|
+
const srcDir = import_path.default.join(process.cwd(), "src");
|
|
116
115
|
console.log(`Scanning for defineConfig calls in: ${srcDir}
|
|
117
116
|
`);
|
|
118
117
|
const project = new import_ts_morph.Project({
|
|
@@ -148,7 +147,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
148
147
|
for (const filePath of modifiedFiles) {
|
|
149
148
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
150
149
|
await sourceFile.save();
|
|
151
|
-
console.log(` Saved: ${import_path.default.relative(
|
|
150
|
+
console.log(` Saved: ${import_path.default.relative(process.cwd(), filePath)}`);
|
|
152
151
|
}
|
|
153
152
|
console.log(
|
|
154
153
|
`
|
|
@@ -191,6 +190,8 @@ function ensureImports(sourceFile) {
|
|
|
191
190
|
var DEFINE_CONFIG_NAME2 = "defineConfig";
|
|
192
191
|
var ACTIONS_PROPERTY_NAME2 = "actions";
|
|
193
192
|
var TYPE_PROPERTY_NAME2 = "type";
|
|
193
|
+
var ID_PROPERTY_NAME = "id";
|
|
194
|
+
var FLAGS_PROPERTY_NAME = "flags";
|
|
194
195
|
var CUSTOM_ACTION_TYPE_PROPERTY_NAME = "customActionType";
|
|
195
196
|
var AUDIT_HISTORY_LABEL_PROPERTY_NAME = "auditHistoryLabel";
|
|
196
197
|
var DEDUPLICATION_PROPERTY_NAME = "deduplication";
|
|
@@ -200,9 +201,12 @@ var FORM_PROPERTY_NAME = "form";
|
|
|
200
201
|
var ACTION_TYPE_ENUM_NAME = "ActionType";
|
|
201
202
|
var VALIDATE_MEMBER_NAME = "VALIDATE";
|
|
202
203
|
var CUSTOM_MEMBER_NAME = "CUSTOM";
|
|
204
|
+
var REGISTER_MEMBER_NAME2 = "REGISTER";
|
|
203
205
|
var VALIDATE_STRING_LITERAL = "VALIDATE";
|
|
204
206
|
var CUSTOM_STRING_LITERAL = "CUSTOM";
|
|
207
|
+
var REGISTER_STRING_LITERAL2 = "REGISTER";
|
|
205
208
|
var VALIDATE_DECLARATION_VALUE = "VALIDATE_DECLARATION";
|
|
209
|
+
var VALIDATED_FLAG_VALUE = "validated";
|
|
206
210
|
function isValidateType(typeInitializer) {
|
|
207
211
|
if (typeInitializer.getKind() === import_ts_morph2.SyntaxKind.PropertyAccessExpression) {
|
|
208
212
|
const propAccess = typeInitializer.asKindOrThrow(
|
|
@@ -326,6 +330,50 @@ function transformValidateActionToCustom(obj, eventType) {
|
|
|
326
330
|
}
|
|
327
331
|
return true;
|
|
328
332
|
}
|
|
333
|
+
function isRegisterAction(action) {
|
|
334
|
+
const typeProperty = action.getProperty(TYPE_PROPERTY_NAME2);
|
|
335
|
+
if (!typeProperty || !import_ts_morph2.Node.isPropertyAssignment(typeProperty)) return false;
|
|
336
|
+
const typeInit = typeProperty.getInitializer();
|
|
337
|
+
if (!typeInit) return false;
|
|
338
|
+
if (import_ts_morph2.Node.isPropertyAccessExpression(typeInit)) {
|
|
339
|
+
const enumExpr = typeInit.getExpression();
|
|
340
|
+
return import_ts_morph2.Node.isIdentifier(enumExpr) && enumExpr.getText() === ACTION_TYPE_ENUM_NAME && typeInit.getName() === REGISTER_MEMBER_NAME2;
|
|
341
|
+
}
|
|
342
|
+
if (import_ts_morph2.Node.isStringLiteral(typeInit)) {
|
|
343
|
+
return typeInit.getLiteralValue() === REGISTER_STRING_LITERAL2;
|
|
344
|
+
}
|
|
345
|
+
return false;
|
|
346
|
+
}
|
|
347
|
+
function arrayHasElementWithId(array3, id) {
|
|
348
|
+
for (const el of array3.getElements()) {
|
|
349
|
+
if (!import_ts_morph2.Node.isObjectLiteralExpression(el)) continue;
|
|
350
|
+
const idProp = el.getProperty(ID_PROPERTY_NAME);
|
|
351
|
+
if (!idProp || !import_ts_morph2.Node.isPropertyAssignment(idProp)) continue;
|
|
352
|
+
const idInit = idProp.getInitializer();
|
|
353
|
+
if (idInit && import_ts_morph2.Node.isStringLiteral(idInit) && idInit.getLiteralValue() === id) {
|
|
354
|
+
return true;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
return false;
|
|
358
|
+
}
|
|
359
|
+
function ensureRegisterRemovesValidatedFlag(action) {
|
|
360
|
+
const entry = `{ id: '${VALIDATED_FLAG_VALUE}', operation: 'remove' }`;
|
|
361
|
+
const flagsProp = action.getProperty(FLAGS_PROPERTY_NAME);
|
|
362
|
+
if (flagsProp && import_ts_morph2.Node.isPropertyAssignment(flagsProp)) {
|
|
363
|
+
const flagsInit = flagsProp.getInitializer();
|
|
364
|
+
if (flagsInit && import_ts_morph2.Node.isArrayLiteralExpression(flagsInit)) {
|
|
365
|
+
if (arrayHasElementWithId(flagsInit, VALIDATED_FLAG_VALUE)) return false;
|
|
366
|
+
flagsInit.addElement(entry);
|
|
367
|
+
return true;
|
|
368
|
+
}
|
|
369
|
+
return false;
|
|
370
|
+
}
|
|
371
|
+
action.addPropertyAssignment({
|
|
372
|
+
name: FLAGS_PROPERTY_NAME,
|
|
373
|
+
initializer: `[${entry}]`
|
|
374
|
+
});
|
|
375
|
+
return true;
|
|
376
|
+
}
|
|
329
377
|
function processFile2(filePath, project) {
|
|
330
378
|
const sourceFile = project.getSourceFile(filePath);
|
|
331
379
|
if (!sourceFile) return 0;
|
|
@@ -351,7 +399,7 @@ function processFile2(filePath, project) {
|
|
|
351
399
|
const eventType = resolveEventType(configArg);
|
|
352
400
|
if (!eventType) {
|
|
353
401
|
console.warn(
|
|
354
|
-
` [${import_path2.default.relative(
|
|
402
|
+
` [${import_path2.default.relative(process.cwd(), configArg.getSourceFile().getFilePath())}] Could not resolve root 'type' from defineConfig \u2014 skipping auditHistoryLabel id generation`
|
|
355
403
|
);
|
|
356
404
|
}
|
|
357
405
|
let fileNeedsImports = false;
|
|
@@ -367,7 +415,7 @@ function processFile2(filePath, project) {
|
|
|
367
415
|
fileNeedsImports = true;
|
|
368
416
|
configHadValidateAction = true;
|
|
369
417
|
console.log(
|
|
370
|
-
` [${import_path2.default.relative(
|
|
418
|
+
` [${import_path2.default.relative(process.cwd(), filePath)}] Transformed VALIDATE action to CUSTOM with customActionType: '${VALIDATE_DECLARATION_VALUE}'`
|
|
371
419
|
);
|
|
372
420
|
}
|
|
373
421
|
}
|
|
@@ -388,9 +436,21 @@ function processFile2(filePath, project) {
|
|
|
388
436
|
]`
|
|
389
437
|
});
|
|
390
438
|
console.log(
|
|
391
|
-
` [${import_path2.default.relative(
|
|
439
|
+
` [${import_path2.default.relative(process.cwd(), filePath)}] Added top-level 'flags' array to defineConfig`
|
|
392
440
|
);
|
|
393
441
|
}
|
|
442
|
+
if (configHadValidateAction) {
|
|
443
|
+
for (const element of actionsInitializer.getElements()) {
|
|
444
|
+
if (!import_ts_morph2.Node.isObjectLiteralExpression(element)) continue;
|
|
445
|
+
if (!isRegisterAction(element)) continue;
|
|
446
|
+
if (ensureRegisterRemovesValidatedFlag(element)) {
|
|
447
|
+
transformedCount++;
|
|
448
|
+
console.log(
|
|
449
|
+
` [${import_path2.default.relative(process.cwd(), filePath)}] Added '${VALIDATED_FLAG_VALUE}' remove-flag to REGISTER action`
|
|
450
|
+
);
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
}
|
|
394
454
|
if (fileNeedsImports) {
|
|
395
455
|
ensureImports(sourceFile);
|
|
396
456
|
}
|
|
@@ -398,7 +458,7 @@ function processFile2(filePath, project) {
|
|
|
398
458
|
return transformedCount;
|
|
399
459
|
}
|
|
400
460
|
async function main2() {
|
|
401
|
-
const srcDir = import_path2.default.join(
|
|
461
|
+
const srcDir = import_path2.default.join(process.cwd(), "src");
|
|
402
462
|
console.log(`Scanning for defineConfig calls in: ${srcDir}
|
|
403
463
|
`);
|
|
404
464
|
const project = new import_ts_morph2.Project({
|
|
@@ -433,11 +493,11 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
433
493
|
for (const filePath of modifiedFiles) {
|
|
434
494
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
435
495
|
await sourceFile.save();
|
|
436
|
-
console.log(` Saved: ${import_path2.default.relative(
|
|
496
|
+
console.log(` Saved: ${import_path2.default.relative(process.cwd(), filePath)}`);
|
|
437
497
|
}
|
|
438
498
|
console.log(
|
|
439
499
|
`
|
|
440
|
-
Done.
|
|
500
|
+
Done. Applied ${totalTransformed} change(s): VALIDATE \u2192 CUSTOM (${VALIDATE_DECLARATION_VALUE}) and '${VALIDATED_FLAG_VALUE}' remove-flag on matching REGISTER actions.`
|
|
441
501
|
);
|
|
442
502
|
}
|
|
443
503
|
|
|
@@ -504,14 +564,14 @@ function processFile3(filePath, project) {
|
|
|
504
564
|
actionsInitializer.removeElement(index);
|
|
505
565
|
removedCount++;
|
|
506
566
|
console.log(
|
|
507
|
-
` [${import_path3.default.relative(
|
|
567
|
+
` [${import_path3.default.relative(process.cwd(), filePath)}] Removed DELETE action at index ${index}`
|
|
508
568
|
);
|
|
509
569
|
}
|
|
510
570
|
}
|
|
511
571
|
return removedCount;
|
|
512
572
|
}
|
|
513
573
|
async function main3() {
|
|
514
|
-
const srcDir = import_path3.default.join(
|
|
574
|
+
const srcDir = import_path3.default.join(process.cwd(), "src");
|
|
515
575
|
console.log(`Scanning for defineConfig calls in: ${srcDir}
|
|
516
576
|
`);
|
|
517
577
|
const project = new import_ts_morph3.Project({
|
|
@@ -546,7 +606,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
546
606
|
for (const filePath of modifiedFiles) {
|
|
547
607
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
548
608
|
await sourceFile.save();
|
|
549
|
-
console.log(` Saved: ${import_path3.default.relative(
|
|
609
|
+
console.log(` Saved: ${import_path3.default.relative(process.cwd(), filePath)}`);
|
|
550
610
|
}
|
|
551
611
|
console.log(
|
|
552
612
|
`
|
|
@@ -620,19 +680,19 @@ function processFile4(filePath, project) {
|
|
|
620
680
|
if (result === "converted-to-heading") {
|
|
621
681
|
changedCount++;
|
|
622
682
|
console.log(
|
|
623
|
-
` [${import_path4.default.relative(
|
|
683
|
+
` [${import_path4.default.relative(process.cwd(), filePath)}] Converted PARAGRAPH with heading fontVariant to HEADING`
|
|
624
684
|
);
|
|
625
685
|
} else if (result === "removed-font-variant") {
|
|
626
686
|
changedCount++;
|
|
627
687
|
console.log(
|
|
628
|
-
` [${import_path4.default.relative(
|
|
688
|
+
` [${import_path4.default.relative(process.cwd(), filePath)}] Removed non-heading fontVariant from PARAGRAPH`
|
|
629
689
|
);
|
|
630
690
|
}
|
|
631
691
|
}
|
|
632
692
|
return changedCount;
|
|
633
693
|
}
|
|
634
694
|
async function main4() {
|
|
635
|
-
const srcDir = import_path4.default.join(
|
|
695
|
+
const srcDir = import_path4.default.join(process.cwd(), "src");
|
|
636
696
|
console.log(`Scanning for FieldType.PARAGRAPH fields in: ${srcDir}
|
|
637
697
|
`);
|
|
638
698
|
const project = new import_ts_morph4.Project({
|
|
@@ -666,7 +726,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
666
726
|
for (const filePath of modifiedFiles) {
|
|
667
727
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
668
728
|
await sourceFile.save();
|
|
669
|
-
console.log(` Saved: ${import_path4.default.relative(
|
|
729
|
+
console.log(` Saved: ${import_path4.default.relative(process.cwd(), filePath)}`);
|
|
670
730
|
}
|
|
671
731
|
console.log(`
|
|
672
732
|
Done. Processed ${totalChanged} FieldType.PARAGRAPH field(s).`);
|
|
@@ -680,14 +740,14 @@ var QUERY_PROPERTY_NAME = "query";
|
|
|
680
740
|
var TYPE_PROPERTY_NAME5 = "type";
|
|
681
741
|
var CLAUSES_PROPERTY_NAME = "clauses";
|
|
682
742
|
var STATUS_PROPERTY_NAME = "status";
|
|
683
|
-
var
|
|
743
|
+
var FLAGS_PROPERTY_NAME2 = "flags";
|
|
684
744
|
var TERMS_PROPERTY_NAME = "terms";
|
|
685
745
|
var TERM_PROPERTY_NAME = "term";
|
|
686
746
|
var ANY_OF_PROPERTY_NAME = "anyOf";
|
|
687
747
|
var VALIDATED_STATUS_VALUE = "VALIDATED";
|
|
688
|
-
var
|
|
748
|
+
var VALIDATED_FLAG_VALUE2 = "validated";
|
|
689
749
|
function addValidatedFlag(clause) {
|
|
690
|
-
const flagsProperty = clause.getProperty(
|
|
750
|
+
const flagsProperty = clause.getProperty(FLAGS_PROPERTY_NAME2);
|
|
691
751
|
if (flagsProperty && import_ts_morph5.Node.isPropertyAssignment(flagsProperty)) {
|
|
692
752
|
const flagsInit = flagsProperty.getInitializer();
|
|
693
753
|
if (flagsInit && import_ts_morph5.Node.isObjectLiteralExpression(flagsInit)) {
|
|
@@ -695,19 +755,19 @@ function addValidatedFlag(clause) {
|
|
|
695
755
|
if (anyOfProperty && import_ts_morph5.Node.isPropertyAssignment(anyOfProperty)) {
|
|
696
756
|
const anyOfInit = anyOfProperty.getInitializer();
|
|
697
757
|
if (anyOfInit && import_ts_morph5.Node.isArrayLiteralExpression(anyOfInit)) {
|
|
698
|
-
anyOfInit.addElement(`'${
|
|
758
|
+
anyOfInit.addElement(`'${VALIDATED_FLAG_VALUE2}'`);
|
|
699
759
|
}
|
|
700
760
|
} else {
|
|
701
761
|
flagsInit.addPropertyAssignment({
|
|
702
762
|
name: ANY_OF_PROPERTY_NAME,
|
|
703
|
-
initializer: `['${
|
|
763
|
+
initializer: `['${VALIDATED_FLAG_VALUE2}']`
|
|
704
764
|
});
|
|
705
765
|
}
|
|
706
766
|
}
|
|
707
767
|
} else {
|
|
708
768
|
clause.addPropertyAssignment({
|
|
709
|
-
name:
|
|
710
|
-
initializer: `{ ${ANY_OF_PROPERTY_NAME}: ['${
|
|
769
|
+
name: FLAGS_PROPERTY_NAME2,
|
|
770
|
+
initializer: `{ ${ANY_OF_PROPERTY_NAME}: ['${VALIDATED_FLAG_VALUE2}'] }`
|
|
711
771
|
});
|
|
712
772
|
}
|
|
713
773
|
}
|
|
@@ -816,7 +876,7 @@ function processFile5(filePath, project) {
|
|
|
816
876
|
if (changed > 0) {
|
|
817
877
|
migratedCount += changed;
|
|
818
878
|
console.log(
|
|
819
|
-
` [${import_path5.default.relative(
|
|
879
|
+
` [${import_path5.default.relative(process.cwd(), filePath)}] Migrated ${changed} clause(s): VALIDATED status \u2192 flags.anyOf`
|
|
820
880
|
);
|
|
821
881
|
}
|
|
822
882
|
}
|
|
@@ -824,7 +884,7 @@ function processFile5(filePath, project) {
|
|
|
824
884
|
return migratedCount;
|
|
825
885
|
}
|
|
826
886
|
async function main5() {
|
|
827
|
-
const srcDir = import_path5.default.join(
|
|
887
|
+
const srcDir = import_path5.default.join(process.cwd(), "src");
|
|
828
888
|
console.log(`Scanning for defineWorkqueues calls in: ${srcDir}
|
|
829
889
|
`);
|
|
830
890
|
const project = new import_ts_morph5.Project({
|
|
@@ -858,7 +918,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
858
918
|
for (const filePath of modifiedFiles) {
|
|
859
919
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
860
920
|
await sourceFile.save();
|
|
861
|
-
console.log(` Saved: ${import_path5.default.relative(
|
|
921
|
+
console.log(` Saved: ${import_path5.default.relative(process.cwd(), filePath)}`);
|
|
862
922
|
}
|
|
863
923
|
console.log(
|
|
864
924
|
`
|
|
@@ -873,23 +933,26 @@ var DEFINE_CONFIG_NAME4 = "defineConfig";
|
|
|
873
933
|
var DEFINE_WORKQUEUES_NAME2 = "defineWorkqueues";
|
|
874
934
|
var ACTIONS_PROPERTY_NAME4 = "actions";
|
|
875
935
|
var ACTION_PROPERTY_NAME = "action";
|
|
876
|
-
var
|
|
936
|
+
var FLAGS_PROPERTY_NAME3 = "flags";
|
|
877
937
|
var QUERY_PROPERTY_NAME2 = "query";
|
|
878
938
|
var TYPE_PROPERTY_NAME6 = "type";
|
|
939
|
+
var ID_PROPERTY_NAME2 = "id";
|
|
879
940
|
var CLAUSES_PROPERTY_NAME2 = "clauses";
|
|
880
941
|
var ANY_OF_PROPERTY_NAME2 = "anyOf";
|
|
881
942
|
var FLAG_ID = "pending-first-certificate-issuance";
|
|
882
943
|
var REGISTER_TYPE = "REGISTER";
|
|
883
944
|
var PRINT_CERTIFICATE_TYPE = "PRINT_CERTIFICATE";
|
|
884
|
-
|
|
945
|
+
function flagDefinitionInitializer(eventType) {
|
|
946
|
+
return `{
|
|
885
947
|
id: '${FLAG_ID}',
|
|
886
948
|
label: {
|
|
887
|
-
id: 'event.
|
|
949
|
+
id: 'event.${eventType}.flag.${FLAG_ID}',
|
|
888
950
|
defaultMessage: 'Pending first certificate issuance',
|
|
889
951
|
description: 'Flag label for first certificate issuance'
|
|
890
952
|
},
|
|
891
953
|
requiresAction: true
|
|
892
954
|
}`;
|
|
955
|
+
}
|
|
893
956
|
function isActionOfType(obj, typeName) {
|
|
894
957
|
const typeProperty = obj.getProperty(TYPE_PROPERTY_NAME6);
|
|
895
958
|
if (!typeProperty || !import_ts_morph6.Node.isPropertyAssignment(typeProperty)) return false;
|
|
@@ -903,18 +966,20 @@ function isActionOfType(obj, typeName) {
|
|
|
903
966
|
}
|
|
904
967
|
return false;
|
|
905
968
|
}
|
|
906
|
-
function
|
|
907
|
-
const
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
969
|
+
function getEventType(configArg) {
|
|
970
|
+
for (const propName of [TYPE_PROPERTY_NAME6, ID_PROPERTY_NAME2]) {
|
|
971
|
+
const prop = configArg.getProperty(propName);
|
|
972
|
+
if (!prop || !import_ts_morph6.Node.isPropertyAssignment(prop)) continue;
|
|
973
|
+
const initializer = prop.getInitializer();
|
|
974
|
+
if (!initializer) continue;
|
|
975
|
+
if (import_ts_morph6.Node.isStringLiteral(initializer)) {
|
|
976
|
+
return initializer.getLiteralValue().toLowerCase();
|
|
977
|
+
}
|
|
978
|
+
if (import_ts_morph6.Node.isPropertyAccessExpression(initializer)) {
|
|
979
|
+
return initializer.getName().toLowerCase();
|
|
980
|
+
}
|
|
916
981
|
}
|
|
917
|
-
return
|
|
982
|
+
return null;
|
|
918
983
|
}
|
|
919
984
|
function hasElementWithId(array3, id) {
|
|
920
985
|
for (const el of array3.getElements()) {
|
|
@@ -928,27 +993,28 @@ function hasElementWithId(array3, id) {
|
|
|
928
993
|
}
|
|
929
994
|
return false;
|
|
930
995
|
}
|
|
931
|
-
function ensureTopLevelFlagDefinition(configArg) {
|
|
932
|
-
const
|
|
996
|
+
function ensureTopLevelFlagDefinition(configArg, eventType) {
|
|
997
|
+
const initializer = flagDefinitionInitializer(eventType);
|
|
998
|
+
const flagsProp = configArg.getProperty(FLAGS_PROPERTY_NAME3);
|
|
933
999
|
if (flagsProp && import_ts_morph6.Node.isPropertyAssignment(flagsProp)) {
|
|
934
1000
|
const flagsInit = flagsProp.getInitializer();
|
|
935
1001
|
if (flagsInit && import_ts_morph6.Node.isArrayLiteralExpression(flagsInit)) {
|
|
936
1002
|
if (hasElementWithId(flagsInit, FLAG_ID)) return false;
|
|
937
|
-
flagsInit.addElement(
|
|
1003
|
+
flagsInit.addElement(initializer);
|
|
938
1004
|
return true;
|
|
939
1005
|
}
|
|
940
1006
|
return false;
|
|
941
1007
|
}
|
|
942
1008
|
configArg.addPropertyAssignment({
|
|
943
|
-
name:
|
|
1009
|
+
name: FLAGS_PROPERTY_NAME3,
|
|
944
1010
|
initializer: `[
|
|
945
|
-
${
|
|
1011
|
+
${initializer}
|
|
946
1012
|
]`
|
|
947
1013
|
});
|
|
948
1014
|
return true;
|
|
949
1015
|
}
|
|
950
1016
|
function ensureActionOperationFlag(action, operation) {
|
|
951
|
-
const flagsProp = action.getProperty(
|
|
1017
|
+
const flagsProp = action.getProperty(FLAGS_PROPERTY_NAME3);
|
|
952
1018
|
const entry = `{ id: '${FLAG_ID}', operation: '${operation}' }`;
|
|
953
1019
|
if (flagsProp && import_ts_morph6.Node.isPropertyAssignment(flagsProp)) {
|
|
954
1020
|
const flagsInit = flagsProp.getInitializer();
|
|
@@ -960,16 +1026,18 @@ function ensureActionOperationFlag(action, operation) {
|
|
|
960
1026
|
return false;
|
|
961
1027
|
}
|
|
962
1028
|
action.addPropertyAssignment({
|
|
963
|
-
name:
|
|
1029
|
+
name: FLAGS_PROPERTY_NAME3,
|
|
964
1030
|
initializer: `[${entry}]`
|
|
965
1031
|
});
|
|
966
1032
|
return true;
|
|
967
1033
|
}
|
|
968
|
-
function
|
|
1034
|
+
function processConfig(configArg, eventType, relPath) {
|
|
969
1035
|
let changes = 0;
|
|
970
|
-
if (ensureTopLevelFlagDefinition(configArg)) {
|
|
1036
|
+
if (ensureTopLevelFlagDefinition(configArg, eventType)) {
|
|
971
1037
|
changes++;
|
|
972
|
-
console.log(
|
|
1038
|
+
console.log(
|
|
1039
|
+
` [${relPath}] (${eventType}) Added '${FLAG_ID}' to top-level flags`
|
|
1040
|
+
);
|
|
973
1041
|
}
|
|
974
1042
|
const actionsProp = configArg.getProperty(ACTIONS_PROPERTY_NAME4);
|
|
975
1043
|
if (!actionsProp || !import_ts_morph6.Node.isPropertyAssignment(actionsProp)) return changes;
|
|
@@ -983,7 +1051,7 @@ function processBirthConfig(configArg, relPath) {
|
|
|
983
1051
|
if (ensureActionOperationFlag(element, "add")) {
|
|
984
1052
|
changes++;
|
|
985
1053
|
console.log(
|
|
986
|
-
` [${relPath}] Added '${FLAG_ID}' add-flag to REGISTER action`
|
|
1054
|
+
` [${relPath}] (${eventType}) Added '${FLAG_ID}' add-flag to REGISTER action`
|
|
987
1055
|
);
|
|
988
1056
|
}
|
|
989
1057
|
}
|
|
@@ -991,7 +1059,7 @@ function processBirthConfig(configArg, relPath) {
|
|
|
991
1059
|
if (ensureActionOperationFlag(element, "remove")) {
|
|
992
1060
|
changes++;
|
|
993
1061
|
console.log(
|
|
994
|
-
` [${relPath}] Added '${FLAG_ID}' remove-flag to PRINT_CERTIFICATE action`
|
|
1062
|
+
` [${relPath}] (${eventType}) Added '${FLAG_ID}' remove-flag to PRINT_CERTIFICATE action`
|
|
995
1063
|
);
|
|
996
1064
|
}
|
|
997
1065
|
}
|
|
@@ -1020,7 +1088,7 @@ function hasPrintCertificateAction(workqueue) {
|
|
|
1020
1088
|
return false;
|
|
1021
1089
|
}
|
|
1022
1090
|
function addFlagToQueryClause(clause) {
|
|
1023
|
-
const flagsProp = clause.getProperty(
|
|
1091
|
+
const flagsProp = clause.getProperty(FLAGS_PROPERTY_NAME3);
|
|
1024
1092
|
if (flagsProp && import_ts_morph6.Node.isPropertyAssignment(flagsProp)) {
|
|
1025
1093
|
const flagsInit = flagsProp.getInitializer();
|
|
1026
1094
|
if (flagsInit && import_ts_morph6.Node.isObjectLiteralExpression(flagsInit)) {
|
|
@@ -1045,7 +1113,7 @@ function addFlagToQueryClause(clause) {
|
|
|
1045
1113
|
}
|
|
1046
1114
|
} else {
|
|
1047
1115
|
clause.addPropertyAssignment({
|
|
1048
|
-
name:
|
|
1116
|
+
name: FLAGS_PROPERTY_NAME3,
|
|
1049
1117
|
initializer: `{ ${ANY_OF_PROPERTY_NAME2}: ['${FLAG_ID}'] }`
|
|
1050
1118
|
});
|
|
1051
1119
|
return true;
|
|
@@ -1076,7 +1144,7 @@ function processFile6(filePath, project) {
|
|
|
1076
1144
|
const sourceFile = project.getSourceFile(filePath);
|
|
1077
1145
|
if (!sourceFile) return 0;
|
|
1078
1146
|
let totalChanges = 0;
|
|
1079
|
-
const relPath = import_path6.default.relative(
|
|
1147
|
+
const relPath = import_path6.default.relative(process.cwd(), filePath);
|
|
1080
1148
|
const callExpressions = sourceFile.getDescendantsOfKind(
|
|
1081
1149
|
import_ts_morph6.SyntaxKind.CallExpression
|
|
1082
1150
|
);
|
|
@@ -1089,8 +1157,9 @@ function processFile6(filePath, project) {
|
|
|
1089
1157
|
if (args.length === 0) continue;
|
|
1090
1158
|
const configArg = args[0];
|
|
1091
1159
|
if (!import_ts_morph6.Node.isObjectLiteralExpression(configArg)) continue;
|
|
1092
|
-
|
|
1093
|
-
|
|
1160
|
+
const eventType = getEventType(configArg);
|
|
1161
|
+
if (!eventType) continue;
|
|
1162
|
+
totalChanges += processConfig(configArg, eventType, relPath);
|
|
1094
1163
|
}
|
|
1095
1164
|
if (calleeName === DEFINE_WORKQUEUES_NAME2) {
|
|
1096
1165
|
const args = call.getArguments();
|
|
@@ -1117,9 +1186,9 @@ function processFile6(filePath, project) {
|
|
|
1117
1186
|
return totalChanges;
|
|
1118
1187
|
}
|
|
1119
1188
|
async function main6() {
|
|
1120
|
-
const srcDir = import_path6.default.join(
|
|
1189
|
+
const srcDir = import_path6.default.join(process.cwd(), "src");
|
|
1121
1190
|
console.log(
|
|
1122
|
-
`Scanning for
|
|
1191
|
+
`Scanning for defineConfig and PRINT_CERTIFICATE workqueues in: ${srcDir}
|
|
1123
1192
|
`
|
|
1124
1193
|
);
|
|
1125
1194
|
const project = new import_ts_morph6.Project({
|
|
@@ -1144,7 +1213,7 @@ async function main6() {
|
|
|
1144
1213
|
}
|
|
1145
1214
|
if (modifiedFiles.length === 0) {
|
|
1146
1215
|
console.log(
|
|
1147
|
-
"No
|
|
1216
|
+
"No event configs or PRINT_CERTIFICATE workqueues found. Nothing to do."
|
|
1148
1217
|
);
|
|
1149
1218
|
return;
|
|
1150
1219
|
}
|
|
@@ -1153,7 +1222,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
1153
1222
|
for (const filePath of modifiedFiles) {
|
|
1154
1223
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
1155
1224
|
await sourceFile.save();
|
|
1156
|
-
console.log(` Saved: ${import_path6.default.relative(
|
|
1225
|
+
console.log(` Saved: ${import_path6.default.relative(process.cwd(), filePath)}`);
|
|
1157
1226
|
}
|
|
1158
1227
|
console.log(
|
|
1159
1228
|
`
|
|
@@ -1190,14 +1259,14 @@ function processFile7(filePath, project) {
|
|
|
1190
1259
|
array3.removeElement(index);
|
|
1191
1260
|
removedCount++;
|
|
1192
1261
|
console.log(
|
|
1193
|
-
` [${import_path7.default.relative(
|
|
1262
|
+
` [${import_path7.default.relative(process.cwd(), filePath)}] Removed InherentFlags.PENDING_CERTIFICATION from array`
|
|
1194
1263
|
);
|
|
1195
1264
|
}
|
|
1196
1265
|
}
|
|
1197
1266
|
return removedCount;
|
|
1198
1267
|
}
|
|
1199
1268
|
async function main7() {
|
|
1200
|
-
const srcDir = import_path7.default.join(
|
|
1269
|
+
const srcDir = import_path7.default.join(process.cwd(), "src");
|
|
1201
1270
|
console.log(
|
|
1202
1271
|
`Scanning for InherentFlags.PENDING_CERTIFICATION array elements in: ${srcDir}
|
|
1203
1272
|
`
|
|
@@ -1233,7 +1302,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
1233
1302
|
for (const filePath of modifiedFiles) {
|
|
1234
1303
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
1235
1304
|
await sourceFile.save();
|
|
1236
|
-
console.log(` Saved: ${import_path7.default.relative(
|
|
1305
|
+
console.log(` Saved: ${import_path7.default.relative(process.cwd(), filePath)}`);
|
|
1237
1306
|
}
|
|
1238
1307
|
console.log(
|
|
1239
1308
|
`
|
|
@@ -1291,13 +1360,13 @@ function processFile8(filePath, project) {
|
|
|
1291
1360
|
propAccess.getNameNode().replaceWithText(NEW_PROPERTY_NAME);
|
|
1292
1361
|
renamedCount++;
|
|
1293
1362
|
console.log(
|
|
1294
|
-
` [${import_path8.default.relative(
|
|
1363
|
+
` [${import_path8.default.relative(process.cwd(), filePath)}] Renamed Location.${OLD_PROPERTY_NAME} \u2192 Location.${NEW_PROPERTY_NAME}`
|
|
1295
1364
|
);
|
|
1296
1365
|
}
|
|
1297
1366
|
return renamedCount;
|
|
1298
1367
|
}
|
|
1299
1368
|
async function main8() {
|
|
1300
|
-
const srcDir = import_path8.default.join(
|
|
1369
|
+
const srcDir = import_path8.default.join(process.cwd(), "src");
|
|
1301
1370
|
console.log(
|
|
1302
1371
|
`Scanning for Location.${OLD_PROPERTY_NAME} references in: ${srcDir}
|
|
1303
1372
|
`
|
|
@@ -1333,7 +1402,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
1333
1402
|
for (const filePath of modifiedFiles) {
|
|
1334
1403
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
1335
1404
|
await sourceFile.save();
|
|
1336
|
-
console.log(` Saved: ${import_path8.default.relative(
|
|
1405
|
+
console.log(` Saved: ${import_path8.default.relative(process.cwd(), filePath)}`);
|
|
1337
1406
|
}
|
|
1338
1407
|
console.log(
|
|
1339
1408
|
`
|
|
@@ -1400,7 +1469,7 @@ function processFile9(filePath, project) {
|
|
|
1400
1469
|
const sourceFile = project.getSourceFile(filePath);
|
|
1401
1470
|
if (!sourceFile) return 0;
|
|
1402
1471
|
let renamedCount = 0;
|
|
1403
|
-
const relPath = import_path9.default.relative(
|
|
1472
|
+
const relPath = import_path9.default.relative(process.cwd(), filePath);
|
|
1404
1473
|
const candidates = sourceFile.getDescendantsOfKind(
|
|
1405
1474
|
import_ts_morph9.SyntaxKind.ObjectLiteralExpression
|
|
1406
1475
|
);
|
|
@@ -1415,7 +1484,7 @@ function processFile9(filePath, project) {
|
|
|
1415
1484
|
return renamedCount;
|
|
1416
1485
|
}
|
|
1417
1486
|
async function main9() {
|
|
1418
|
-
const srcDir = import_path9.default.join(
|
|
1487
|
+
const srcDir = import_path9.default.join(process.cwd(), "src");
|
|
1419
1488
|
console.log(`Scanning for Hapi route configs in: ${srcDir}
|
|
1420
1489
|
`);
|
|
1421
1490
|
console.log("Active path renames:");
|
|
@@ -1452,7 +1521,7 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
1452
1521
|
for (const filePath of modifiedFiles) {
|
|
1453
1522
|
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
1454
1523
|
await sourceFile.save();
|
|
1455
|
-
console.log(` Saved: ${import_path9.default.relative(
|
|
1524
|
+
console.log(` Saved: ${import_path9.default.relative(process.cwd(), filePath)}`);
|
|
1456
1525
|
}
|
|
1457
1526
|
console.log(`
|
|
1458
1527
|
Done. Renamed ${totalRenamed} route path(s).`);
|
|
@@ -1826,9 +1895,9 @@ function updateRouteHandlers(sourceFiles, group, srcDir, relCwd) {
|
|
|
1826
1895
|
}
|
|
1827
1896
|
return replacedCount;
|
|
1828
1897
|
}
|
|
1829
|
-
function resolveConfigChain(configObj,
|
|
1898
|
+
function resolveConfigChain(configObj, path23) {
|
|
1830
1899
|
let current = configObj;
|
|
1831
|
-
for (const key of
|
|
1900
|
+
for (const key of path23) {
|
|
1832
1901
|
if (!import_ts_morph10.Node.isObjectLiteralExpression(current)) return null;
|
|
1833
1902
|
const prop = current.getProperty(key);
|
|
1834
1903
|
if (!prop || !import_ts_morph10.Node.isPropertyAssignment(prop)) return null;
|
|
@@ -1873,8 +1942,8 @@ function ensureJoinImport(sf) {
|
|
|
1873
1942
|
});
|
|
1874
1943
|
}
|
|
1875
1944
|
async function main10() {
|
|
1876
|
-
const srcDir = import_path10.default.join(
|
|
1877
|
-
const relCwd = (fp) => import_path10.default.relative(
|
|
1945
|
+
const srcDir = import_path10.default.join(process.cwd(), "src");
|
|
1946
|
+
const relCwd = (fp) => import_path10.default.relative(process.cwd(), fp);
|
|
1878
1947
|
console.log("Phase 1: Converting JS config files to TypeScript...\n");
|
|
1879
1948
|
let convertedCount = 0;
|
|
1880
1949
|
for (const group of CONFIG_GROUPS) {
|
|
@@ -1962,7 +2031,7 @@ async function main10() {
|
|
|
1962
2031
|
ensureJoinImport(sf);
|
|
1963
2032
|
}
|
|
1964
2033
|
console.log(
|
|
1965
|
-
` Inlined applicationConfig.${accessPath.join(".")} \u2192 ${adjustedValue} in ${import_path10.default.relative(
|
|
2034
|
+
` Inlined applicationConfig.${accessPath.join(".")} \u2192 ${adjustedValue} in ${import_path10.default.relative(process.cwd(), sf.getFilePath())}`
|
|
1966
2035
|
);
|
|
1967
2036
|
filesToSaveAfterInlining.add(sf);
|
|
1968
2037
|
madeReplacement = true;
|
|
@@ -1974,7 +2043,7 @@ async function main10() {
|
|
|
1974
2043
|
for (const sf of Array.from(filesToSaveAfterInlining)) {
|
|
1975
2044
|
await sf.save();
|
|
1976
2045
|
console.log(
|
|
1977
|
-
` Saved (inlined): ${import_path10.default.relative(
|
|
2046
|
+
` Saved (inlined): ${import_path10.default.relative(process.cwd(), sf.getFilePath())}`
|
|
1978
2047
|
);
|
|
1979
2048
|
}
|
|
1980
2049
|
for (const prop of [...propsToRemove].reverse()) {
|
|
@@ -2063,6 +2132,10 @@ Done. Converted ${convertedCount} config file(s), replaced ${totalReplaced} rout
|
|
|
2063
2132
|
var import_ts_morph11 = require("ts-morph");
|
|
2064
2133
|
var import_path11 = __toESM(require("path"));
|
|
2065
2134
|
|
|
2135
|
+
// ../commons/src/scopes.deprecated.do-not-use.ts
|
|
2136
|
+
var z4 = __toESM(require("zod/v4"));
|
|
2137
|
+
var import_lodash = require("lodash");
|
|
2138
|
+
|
|
2066
2139
|
// ../commons/src/scopes.ts
|
|
2067
2140
|
var z3 = __toESM(require("zod/v4"));
|
|
2068
2141
|
var qs = __toESM(require("qs"));
|
|
@@ -2150,6 +2223,9 @@ var CustomActionScopeOptions = AllRecordScopeOptions.extend({
|
|
|
2150
2223
|
var AccessLevelOptions = z3.object({
|
|
2151
2224
|
accessLevel: JurisdictionFilter.optional()
|
|
2152
2225
|
});
|
|
2226
|
+
var AllUserScopeOptions = AccessLevelOptions.extend({
|
|
2227
|
+
role: userRole.optional()
|
|
2228
|
+
});
|
|
2153
2229
|
var WorkqueueOrDashboardOptions = z3.object({
|
|
2154
2230
|
ids: z3.preprocess(
|
|
2155
2231
|
(val) => val === void 0 ? void 0 : [val].flat(),
|
|
@@ -2159,6 +2235,7 @@ var WorkqueueOrDashboardOptions = z3.object({
|
|
|
2159
2235
|
var AllScopeOptions = z3.object({
|
|
2160
2236
|
...AllRecordScopeOptions.shape,
|
|
2161
2237
|
...AccessLevelOptions.shape,
|
|
2238
|
+
...AllUserScopeOptions.shape,
|
|
2162
2239
|
...WorkqueueOrDashboardOptions.shape
|
|
2163
2240
|
});
|
|
2164
2241
|
var ScopeOptionKey = AllScopeOptions.keyof();
|
|
@@ -2235,27 +2312,24 @@ var SystemScopeType = z3.enum([
|
|
|
2235
2312
|
"organisation.read-locations",
|
|
2236
2313
|
"user.read",
|
|
2237
2314
|
"user.create",
|
|
2238
|
-
"user.edit"
|
|
2315
|
+
"user.edit",
|
|
2316
|
+
"user.search"
|
|
2239
2317
|
]);
|
|
2240
2318
|
var UserScopeType = SystemScopeType.extract([
|
|
2241
2319
|
"user.read",
|
|
2242
2320
|
"user.create",
|
|
2243
|
-
"user.edit"
|
|
2321
|
+
"user.edit",
|
|
2322
|
+
"user.search"
|
|
2244
2323
|
]);
|
|
2245
2324
|
var ScopesWithRoleOption = UserScopeType.extract(["user.edit", "user.create"]);
|
|
2246
2325
|
var UserScopeV2 = z3.discriminatedUnion("type", [
|
|
2247
2326
|
z3.object({
|
|
2248
2327
|
type: ScopesWithRoleOption,
|
|
2249
|
-
options:
|
|
2250
|
-
accessLevel: JurisdictionFilter.optional(),
|
|
2251
|
-
role: userRole.optional()
|
|
2252
|
-
}).optional()
|
|
2328
|
+
options: AllUserScopeOptions.optional()
|
|
2253
2329
|
}),
|
|
2254
2330
|
z3.object({
|
|
2255
|
-
type: UserScopeType.extract(["user.read"]),
|
|
2256
|
-
options:
|
|
2257
|
-
accessLevel: JurisdictionFilter.optional()
|
|
2258
|
-
}).optional()
|
|
2331
|
+
type: UserScopeType.extract(["user.read", "user.search"]),
|
|
2332
|
+
options: AccessLevelOptions.optional()
|
|
2259
2333
|
})
|
|
2260
2334
|
]);
|
|
2261
2335
|
var ResolvedRecordScopeV2 = z3.discriminatedUnion("type", [
|
|
@@ -2335,7 +2409,6 @@ var DEFAULT_SCOPE_OPTIONS = {
|
|
|
2335
2409
|
};
|
|
2336
2410
|
|
|
2337
2411
|
// ../commons/src/scopes.deprecated.do-not-use.ts
|
|
2338
|
-
var z4 = __toESM(require("zod/v4"));
|
|
2339
2412
|
var rawConfigurableScopeRegex = /^([a-zA-Z][a-zA-Z0-9.-]*(?:\.[a-zA-Z0-9.-]+)*)\[((?:\w+=[\w.-]+(?:\|[\w.-]+)*)(?:,[\w]+=[\w.-]+(?:\|[\w.-]+)*)*)\]$/;
|
|
2340
2413
|
var rawConfigurableScope = z4.string().regex(rawConfigurableScopeRegex);
|
|
2341
2414
|
var SearchScope = z4.object({
|
|
@@ -2569,6 +2642,74 @@ var legacyScopeToV2Scope = (v1Scope) => {
|
|
|
2569
2642
|
}
|
|
2570
2643
|
throw new Error(`Unsupported V1 scope type: ${v1Scope}`);
|
|
2571
2644
|
};
|
|
2645
|
+
var MERGEABLE_USER_SCOPE_TYPES = ["user.create", "user.edit"];
|
|
2646
|
+
function isMergeableUserScopeType(type) {
|
|
2647
|
+
return MERGEABLE_USER_SCOPE_TYPES.includes(type);
|
|
2648
|
+
}
|
|
2649
|
+
function decodeLegacyScope(legacy) {
|
|
2650
|
+
const encoded = legacyScopeToV2Scope(legacy);
|
|
2651
|
+
const scope = decodeScope(encoded);
|
|
2652
|
+
if (!scope) {
|
|
2653
|
+
throw new Error(
|
|
2654
|
+
`Could not decode migrated scope from legacy '${legacy}' (encoded: '${encoded}').`
|
|
2655
|
+
);
|
|
2656
|
+
}
|
|
2657
|
+
return { legacy, scope };
|
|
2658
|
+
}
|
|
2659
|
+
function groupByType(entries) {
|
|
2660
|
+
return entries.reduce(
|
|
2661
|
+
(groups, entry) => ({
|
|
2662
|
+
...groups,
|
|
2663
|
+
[entry.scope.type]: [...groups[entry.scope.type] ?? [], entry]
|
|
2664
|
+
}),
|
|
2665
|
+
{}
|
|
2666
|
+
);
|
|
2667
|
+
}
|
|
2668
|
+
function deduplicateEntries(entries) {
|
|
2669
|
+
return entries.filter(
|
|
2670
|
+
(entry, index) => entries.findIndex((e) => (0, import_lodash.isEqual)(e.scope, entry.scope)) === index
|
|
2671
|
+
);
|
|
2672
|
+
}
|
|
2673
|
+
function mergeEntries(type, entries) {
|
|
2674
|
+
const optionsList = entries.map(
|
|
2675
|
+
(e) => "options" in e.scope && e.scope.options ? e.scope.options : {}
|
|
2676
|
+
);
|
|
2677
|
+
const allKeys = optionsList.flatMap(
|
|
2678
|
+
(opts) => Object.keys(opts).filter((k) => opts[k] !== void 0)
|
|
2679
|
+
);
|
|
2680
|
+
const conflictKey = allKeys.find((key, i) => allKeys.indexOf(key) !== i);
|
|
2681
|
+
if (conflictKey) {
|
|
2682
|
+
const conflicting = entries.filter(
|
|
2683
|
+
(e) => conflictKey in ("options" in e.scope && e.scope.options || {})
|
|
2684
|
+
).map((e) => JSON.stringify(e.legacy));
|
|
2685
|
+
throw new Error(
|
|
2686
|
+
`Cannot auto-merge two '${type}' scopes that both define '${conflictKey}'. Conflicting legacy scopes: [${conflicting.join(", ")}]. Resolve manually in roles.ts and re-run.`
|
|
2687
|
+
);
|
|
2688
|
+
}
|
|
2689
|
+
const mergedOptions = Object.assign({}, ...optionsList);
|
|
2690
|
+
const merged = Object.keys(mergedOptions).length > 0 ? { type, options: mergedOptions } : { type };
|
|
2691
|
+
const parsed = Scope2.safeParse(merged);
|
|
2692
|
+
if (!parsed.success) {
|
|
2693
|
+
throw new Error(
|
|
2694
|
+
`Merged '${type}' scope failed schema validation: ${parsed.error.message}. Legacy scopes: [${entries.map((e) => JSON.stringify(e.legacy)).join(", ")}].`
|
|
2695
|
+
);
|
|
2696
|
+
}
|
|
2697
|
+
return parsed.data;
|
|
2698
|
+
}
|
|
2699
|
+
function migrateLegacyScopesArrayToV2Scopes(legacyScopes) {
|
|
2700
|
+
const groups = groupByType(legacyScopes.map(decodeLegacyScope));
|
|
2701
|
+
return Object.entries(groups).flatMap(([type, entries]) => {
|
|
2702
|
+
const deduped = deduplicateEntries(entries);
|
|
2703
|
+
if (deduped.length <= 1) return deduped.map((e) => e.scope);
|
|
2704
|
+
if (!isMergeableUserScopeType(type)) {
|
|
2705
|
+
console.warn(
|
|
2706
|
+
`Multiple non-mergeable '${type}' scopes detected after dedup \u2014 kept all as-is. Legacy scopes: [${deduped.map((e) => JSON.stringify(e.legacy)).join(", ")}]. Review whether the duplication is intentional.`
|
|
2707
|
+
);
|
|
2708
|
+
return deduped.map((e) => e.scope);
|
|
2709
|
+
}
|
|
2710
|
+
return [mergeEntries(type, deduped)];
|
|
2711
|
+
});
|
|
2712
|
+
}
|
|
2572
2713
|
|
|
2573
2714
|
// src/migrations/v2.0/migrate-scopes.ts
|
|
2574
2715
|
var ROLES_FILE_RELATIVE_PATH = "src/data-seeding/roles/roles.ts";
|
|
@@ -2606,57 +2747,65 @@ function resolveLegacyScopeFromElement(element) {
|
|
|
2606
2747
|
}
|
|
2607
2748
|
function migrateScopesArrays(rolesFilePath, project) {
|
|
2608
2749
|
const sourceFile = project.getSourceFile(rolesFilePath);
|
|
2609
|
-
if (!sourceFile)
|
|
2750
|
+
if (!sourceFile) {
|
|
2751
|
+
return { migratedCount: 0, removedCount: 0, mergedCount: 0 };
|
|
2752
|
+
}
|
|
2610
2753
|
let migratedCount = 0;
|
|
2611
2754
|
let removedCount = 0;
|
|
2755
|
+
let mergedCount = 0;
|
|
2612
2756
|
const scopesProperties = sourceFile.getDescendantsOfKind(import_ts_morph11.SyntaxKind.PropertyAssignment).filter((prop) => prop.getName() === SCOPES_PROPERTY_NAME);
|
|
2757
|
+
const relPath = import_path11.default.relative(process.cwd(), rolesFilePath);
|
|
2613
2758
|
for (const scopesProp of scopesProperties) {
|
|
2614
2759
|
const initializer = scopesProp.getInitializer();
|
|
2615
2760
|
if (!initializer || !import_ts_morph11.Node.isArrayLiteralExpression(initializer)) continue;
|
|
2616
|
-
const
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2761
|
+
const rawTexts = [];
|
|
2762
|
+
const legacyStrings = [];
|
|
2763
|
+
let anyChange = false;
|
|
2764
|
+
for (const element of initializer.getElements()) {
|
|
2620
2765
|
const scopeKey = resolveScopeKeyFromElementAccess(element);
|
|
2621
2766
|
if (scopeKey && !(scopeKey in SCOPES)) {
|
|
2622
2767
|
console.warn(
|
|
2623
|
-
` [${
|
|
2768
|
+
` [${relPath}] Removing unknown scope reference: SCOPES.${scopeKey}`
|
|
2624
2769
|
);
|
|
2625
|
-
initializer.removeElement(index);
|
|
2626
2770
|
removedCount++;
|
|
2771
|
+
anyChange = true;
|
|
2627
2772
|
continue;
|
|
2628
2773
|
}
|
|
2629
2774
|
const legacyScope = resolveLegacyScopeFromElement(element);
|
|
2630
2775
|
if (!legacyScope) {
|
|
2631
2776
|
console.warn(
|
|
2632
|
-
` [${
|
|
2777
|
+
` [${relPath}] Preserving non-literal scope expression verbatim: ${element.getText()}`
|
|
2633
2778
|
);
|
|
2779
|
+
rawTexts.push(element.getText());
|
|
2634
2780
|
continue;
|
|
2635
2781
|
}
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
console.warn(
|
|
2649
|
-
` [${import_path11.default.relative(getCwd(), rolesFilePath)}] Could not migrate scope '${legacyScope}': ${error}`
|
|
2650
|
-
);
|
|
2651
|
-
}
|
|
2782
|
+
legacyStrings.push(legacyScope);
|
|
2783
|
+
anyChange = true;
|
|
2784
|
+
}
|
|
2785
|
+
if (!anyChange) continue;
|
|
2786
|
+
let mergedScopes;
|
|
2787
|
+
try {
|
|
2788
|
+
mergedScopes = migrateLegacyScopesArrayToV2Scopes(legacyStrings);
|
|
2789
|
+
} catch (error) {
|
|
2790
|
+
throw new Error(
|
|
2791
|
+
`[${relPath}] Failed to migrate scopes for role: ${error instanceof Error ? error.message : String(error)}`,
|
|
2792
|
+
{ cause: error }
|
|
2793
|
+
);
|
|
2652
2794
|
}
|
|
2795
|
+
migratedCount += legacyStrings.length;
|
|
2796
|
+
mergedCount += legacyStrings.length - mergedScopes.length;
|
|
2797
|
+
const outputElements = [
|
|
2798
|
+
...rawTexts,
|
|
2799
|
+
...mergedScopes.map((s) => JSON.stringify(s))
|
|
2800
|
+
];
|
|
2801
|
+
scopesProp.setInitializer(`[${outputElements.join(", ")}]`);
|
|
2653
2802
|
}
|
|
2654
2803
|
if (removedCount > 0) {
|
|
2655
2804
|
console.log(
|
|
2656
|
-
` Removed ${removedCount} unknown SCOPES reference(s) from '${
|
|
2805
|
+
` Removed ${removedCount} unknown SCOPES reference(s) from '${relPath}'.`
|
|
2657
2806
|
);
|
|
2658
2807
|
}
|
|
2659
|
-
return { migratedCount, removedCount };
|
|
2808
|
+
return { migratedCount, removedCount, mergedCount };
|
|
2660
2809
|
}
|
|
2661
2810
|
function ensureScopesHelpersImport(rolesFilePath, project) {
|
|
2662
2811
|
const sourceFile = project.getSourceFile(rolesFilePath);
|
|
@@ -2775,9 +2924,9 @@ function removeRoleTypeDefinitionAndUnusedImports(rolesFilePath, project) {
|
|
|
2775
2924
|
return removed;
|
|
2776
2925
|
}
|
|
2777
2926
|
async function main11() {
|
|
2778
|
-
const
|
|
2779
|
-
const srcDir = import_path11.default.join(
|
|
2780
|
-
const rolesFilePath = import_path11.default.join(
|
|
2927
|
+
const cwd = process.cwd();
|
|
2928
|
+
const srcDir = import_path11.default.join(cwd, "src");
|
|
2929
|
+
const rolesFilePath = import_path11.default.join(cwd, ROLES_FILE_RELATIVE_PATH);
|
|
2781
2930
|
console.log(`Scanning roles scopes in: ${rolesFilePath}`);
|
|
2782
2931
|
const project = new import_ts_morph11.Project({
|
|
2783
2932
|
tsConfigFilePath: import_path11.default.resolve(srcDir, "../tsconfig.json"),
|
|
@@ -2791,7 +2940,7 @@ async function main11() {
|
|
|
2791
2940
|
return;
|
|
2792
2941
|
}
|
|
2793
2942
|
const importChanged = ensureScopesHelpersImport(rolesFilePath, project);
|
|
2794
|
-
const { migratedCount, removedCount } = migrateScopesArrays(
|
|
2943
|
+
const { migratedCount, removedCount, mergedCount } = migrateScopesArrays(
|
|
2795
2944
|
rolesFilePath,
|
|
2796
2945
|
project
|
|
2797
2946
|
);
|
|
@@ -2810,7 +2959,7 @@ async function main11() {
|
|
|
2810
2959
|
}
|
|
2811
2960
|
await sourceFile.save();
|
|
2812
2961
|
console.log(
|
|
2813
|
-
`Done. Migrated ${migratedCount} legacy scope(s), removed ${removedCount} unknown SCOPES reference(s), wrapped ${wrappedScopesCount} scope array(s) with defineScopes()${wrappedRoles ? ", wrapped roles with defineRoles()" : ""}${removedRoleType ? ", and removed Role type definition" : ""}${importChanged ? ". Updated toolkit/scopes imports." : "."}`
|
|
2962
|
+
`Done. Migrated ${migratedCount} legacy scope(s), merged ${mergedCount} AND-paired scope(s) into single v2 objects (privilege-escalation fix, see issue #12489), removed ${removedCount} unknown SCOPES reference(s), wrapped ${wrappedScopesCount} scope array(s) with defineScopes()${wrappedRoles ? ", wrapped roles with defineRoles()" : ""}${removedRoleType ? ", and removed Role type definition" : ""}${importChanged ? ". Updated toolkit/scopes imports." : "."}`
|
|
2814
2963
|
);
|
|
2815
2964
|
}
|
|
2816
2965
|
|
|
@@ -2841,13 +2990,13 @@ function processFile10(filePath, project) {
|
|
|
2841
2990
|
decl.remove();
|
|
2842
2991
|
}
|
|
2843
2992
|
console.log(
|
|
2844
|
-
` [${import_path12.default.relative(
|
|
2993
|
+
` [${import_path12.default.relative(process.cwd(), filePath)}] Removed ${matchingNamedImports.length} deprecated '${DEPRECATED_IMPORT}' import(s) from '${decl.getModuleSpecifierValue()}'`
|
|
2845
2994
|
);
|
|
2846
2995
|
}
|
|
2847
2996
|
return removedCount;
|
|
2848
2997
|
}
|
|
2849
2998
|
async function main12() {
|
|
2850
|
-
const srcDir = import_path12.default.join(
|
|
2999
|
+
const srcDir = import_path12.default.join(process.cwd(), "src");
|
|
2851
3000
|
console.log(`Scanning for deprecated imports in: ${srcDir}
|
|
2852
3001
|
`);
|
|
2853
3002
|
const project = new import_ts_morph12.Project({
|
|
@@ -2878,232 +3027,1010 @@ async function main12() {
|
|
|
2878
3027
|
Saving ${modifiedFiles.length} modified file(s)...`);
|
|
2879
3028
|
for (const filePath of modifiedFiles) {
|
|
2880
3029
|
await project.getSourceFileOrThrow(filePath).save();
|
|
2881
|
-
console.log(` Saved: ${import_path12.default.relative(
|
|
3030
|
+
console.log(` Saved: ${import_path12.default.relative(process.cwd(), filePath)}`);
|
|
2882
3031
|
}
|
|
2883
3032
|
console.log(`
|
|
2884
3033
|
Done. Removed ${totalRemoved} deprecated import(s).`);
|
|
2885
3034
|
}
|
|
2886
3035
|
|
|
2887
|
-
// src/migrations/v2.0/
|
|
2888
|
-
var import_ts_morph13 = require("ts-morph");
|
|
3036
|
+
// src/migrations/v2.0/remove-unused-environment-variables.ts
|
|
2889
3037
|
var import_path13 = __toESM(require("path"));
|
|
2890
|
-
var
|
|
2891
|
-
var
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
var SLUG_PROPERTY_NAME = "slug";
|
|
2896
|
-
var SUPPORTED_WORKQUEUE_ACTION_TYPES = /* @__PURE__ */ new Set([
|
|
2897
|
-
"READ",
|
|
2898
|
-
"DELETE",
|
|
2899
|
-
"DECLARE",
|
|
2900
|
-
"REGISTER",
|
|
2901
|
-
"EDIT",
|
|
2902
|
-
"REJECT",
|
|
2903
|
-
"MARK_AS_DUPLICATE",
|
|
2904
|
-
"ARCHIVE",
|
|
2905
|
-
"PRINT_CERTIFICATE",
|
|
2906
|
-
"REQUEST_CORRECTION"
|
|
3038
|
+
var import_ts_morph13 = require("ts-morph");
|
|
3039
|
+
var UNUSED_ENV_VARS = /* @__PURE__ */ new Set([
|
|
3040
|
+
"APPLICATION_CONFIG_URL",
|
|
3041
|
+
"FHIR_URL",
|
|
3042
|
+
"CONFIRM_REGISTRATION_URL"
|
|
2907
3043
|
]);
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
const
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
|
|
2921
|
-
|
|
2922
|
-
|
|
2923
|
-
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
|
|
2928
|
-
if (import_ts_morph13.Node.isStringLiteral(typeInitializer)) {
|
|
2929
|
-
return typeInitializer.getLiteralValue();
|
|
2930
|
-
}
|
|
2931
|
-
if (import_ts_morph13.Node.isPropertyAccessExpression(typeInitializer)) {
|
|
2932
|
-
return typeInitializer.getName();
|
|
3044
|
+
var ENVIRONMENT_FILE_RELATIVE = "src/environment.ts";
|
|
3045
|
+
var CONSTANTS_FILE_RELATIVE = "src/constants.ts";
|
|
3046
|
+
function cleanEnvironmentFile(project, filePath) {
|
|
3047
|
+
const sourceFile = project.getSourceFile(filePath);
|
|
3048
|
+
if (!sourceFile) return [];
|
|
3049
|
+
const removed = [];
|
|
3050
|
+
const cleanEnvCall = sourceFile.getDescendantsOfKind(import_ts_morph13.SyntaxKind.CallExpression).find((call) => {
|
|
3051
|
+
const expr = call.getExpression();
|
|
3052
|
+
return import_ts_morph13.Node.isIdentifier(expr) && expr.getText() === "cleanEnv";
|
|
3053
|
+
});
|
|
3054
|
+
if (!cleanEnvCall) return removed;
|
|
3055
|
+
const schemaArg = cleanEnvCall.getArguments()[1]?.asKind(import_ts_morph13.SyntaxKind.ObjectLiteralExpression);
|
|
3056
|
+
if (!schemaArg) return removed;
|
|
3057
|
+
for (const name of UNUSED_ENV_VARS) {
|
|
3058
|
+
const prop = schemaArg.getProperty(name);
|
|
3059
|
+
if (!prop) continue;
|
|
3060
|
+
if (prop.isKind(import_ts_morph13.SyntaxKind.PropertyAssignment) || prop.isKind(import_ts_morph13.SyntaxKind.ShorthandPropertyAssignment)) {
|
|
3061
|
+
prop.remove();
|
|
3062
|
+
removed.push(name);
|
|
3063
|
+
}
|
|
2933
3064
|
}
|
|
2934
|
-
return
|
|
3065
|
+
return removed;
|
|
2935
3066
|
}
|
|
2936
|
-
function
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
}
|
|
2941
|
-
return !SUPPORTED_WORKQUEUE_ACTION_TYPES.has(typeName);
|
|
3067
|
+
function extractEnvAccess(initText) {
|
|
3068
|
+
if (!initText) return null;
|
|
3069
|
+
const match = /\benv\.([A-Z][A-Z0-9_]*)\b/.exec(initText);
|
|
3070
|
+
return match ? match[1] : null;
|
|
2942
3071
|
}
|
|
2943
|
-
function
|
|
2944
|
-
const
|
|
2945
|
-
if (!
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
|
|
2961
|
-
|
|
2962
|
-
conditionalsProperty2.remove();
|
|
2963
|
-
console.log(
|
|
2964
|
-
` [${relPath}] Removed deprecated 'conditionals' from 'action' on workqueue '${workqueueLabel}'`
|
|
2965
|
-
);
|
|
2966
|
-
}
|
|
2967
|
-
if (isUnsupportedActionType(existingActionInitializer)) {
|
|
2968
|
-
existingActionProperty.remove();
|
|
2969
|
-
console.log(
|
|
2970
|
-
` [${relPath}] Removed unsupported 'action' type on workqueue '${workqueueLabel}'`
|
|
2971
|
-
);
|
|
2972
|
-
}
|
|
3072
|
+
function cleanConstantsFile(project, filePath) {
|
|
3073
|
+
const sourceFile = project.getSourceFile(filePath);
|
|
3074
|
+
if (!sourceFile) return [];
|
|
3075
|
+
const removed = [];
|
|
3076
|
+
for (const stmt of [...sourceFile.getVariableStatements()]) {
|
|
3077
|
+
const declarations = [...stmt.getDeclarations()];
|
|
3078
|
+
const declarationsToRemove = declarations.filter((decl) => {
|
|
3079
|
+
const name = decl.getName();
|
|
3080
|
+
const accessedEnvVar = extractEnvAccess(decl.getInitializer()?.getText());
|
|
3081
|
+
return UNUSED_ENV_VARS.has(name) || accessedEnvVar !== null && UNUSED_ENV_VARS.has(accessedEnvVar);
|
|
3082
|
+
});
|
|
3083
|
+
if (declarationsToRemove.length === 0) continue;
|
|
3084
|
+
const namesToRemove = declarationsToRemove.map((decl) => decl.getName());
|
|
3085
|
+
removed.push(...namesToRemove);
|
|
3086
|
+
if (declarationsToRemove.length === declarations.length) {
|
|
3087
|
+
stmt.remove();
|
|
3088
|
+
} else {
|
|
3089
|
+
for (const decl of declarationsToRemove) {
|
|
3090
|
+
decl.remove();
|
|
2973
3091
|
}
|
|
2974
3092
|
}
|
|
2975
|
-
actionsProperty.remove();
|
|
2976
|
-
console.log(
|
|
2977
|
-
` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' (existing 'action' kept)`
|
|
2978
|
-
);
|
|
2979
|
-
return 1;
|
|
2980
3093
|
}
|
|
2981
|
-
|
|
2982
|
-
|
|
3094
|
+
return removed;
|
|
3095
|
+
}
|
|
3096
|
+
async function main13() {
|
|
3097
|
+
const project = new import_ts_morph13.Project({
|
|
3098
|
+
tsConfigFilePath: import_path13.default.resolve(process.cwd(), "tsconfig.json"),
|
|
3099
|
+
skipAddingFilesFromTsConfig: false
|
|
3100
|
+
});
|
|
3101
|
+
console.log(
|
|
3102
|
+
`Removing unused environment variable(s) (${[...UNUSED_ENV_VARS].join(", ")})...
|
|
3103
|
+
`
|
|
2983
3104
|
);
|
|
2984
|
-
|
|
2985
|
-
|
|
3105
|
+
const envFilePath = import_path13.default.join(process.cwd(), ENVIRONMENT_FILE_RELATIVE);
|
|
3106
|
+
const constsFilePath = import_path13.default.join(process.cwd(), CONSTANTS_FILE_RELATIVE);
|
|
3107
|
+
const envRemoved = cleanEnvironmentFile(project, envFilePath);
|
|
3108
|
+
if (envRemoved.length > 0) {
|
|
3109
|
+
await project.getSourceFileOrThrow(envFilePath).save();
|
|
2986
3110
|
console.log(
|
|
2987
|
-
` [${
|
|
3111
|
+
` [${ENVIRONMENT_FILE_RELATIVE}] Removed schema entr${envRemoved.length === 1 ? "y" : "ies"}: ${envRemoved.join(", ")}`
|
|
2988
3112
|
);
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
const droppedCount = actionCandidates.length - 1;
|
|
2993
|
-
console.warn(
|
|
2994
|
-
` [${relPath}] Workqueue '${workqueueLabel}' has ${actionCandidates.length} actions; keeping first as 'action' and dropping ${droppedCount} extra action(s)`
|
|
3113
|
+
} else if (project.getSourceFile(envFilePath)) {
|
|
3114
|
+
console.log(
|
|
3115
|
+
` [${ENVIRONMENT_FILE_RELATIVE}] No matching schema entries \u2014 nothing to remove.`
|
|
2995
3116
|
);
|
|
2996
|
-
}
|
|
2997
|
-
const conditionalsProperty = actionCandidates[0].getProperty(
|
|
2998
|
-
CONDITIONALS_PROPERTY_NAME
|
|
2999
|
-
);
|
|
3000
|
-
if (conditionalsProperty) {
|
|
3001
|
-
conditionalsProperty.remove();
|
|
3117
|
+
} else {
|
|
3002
3118
|
console.log(
|
|
3003
|
-
` [${
|
|
3119
|
+
` [${ENVIRONMENT_FILE_RELATIVE}] File not found \u2014 skipping.`
|
|
3004
3120
|
);
|
|
3005
3121
|
}
|
|
3006
|
-
|
|
3007
|
-
|
|
3122
|
+
const constsRemoved = cleanConstantsFile(project, constsFilePath);
|
|
3123
|
+
if (constsRemoved.length > 0) {
|
|
3124
|
+
await project.getSourceFileOrThrow(constsFilePath).save();
|
|
3125
|
+
console.log(
|
|
3126
|
+
` [${CONSTANTS_FILE_RELATIVE}] Removed declaration(s): ${constsRemoved.join(", ")}`
|
|
3127
|
+
);
|
|
3128
|
+
} else if (project.getSourceFile(constsFilePath)) {
|
|
3008
3129
|
console.log(
|
|
3009
|
-
` [${
|
|
3130
|
+
` [${CONSTANTS_FILE_RELATIVE}] No matching declarations \u2014 nothing to remove.`
|
|
3010
3131
|
);
|
|
3011
|
-
|
|
3132
|
+
} else {
|
|
3133
|
+
console.log(` [${CONSTANTS_FILE_RELATIVE}] File not found \u2014 skipping.`);
|
|
3134
|
+
}
|
|
3135
|
+
if (envRemoved.length === 0 && constsRemoved.length === 0) {
|
|
3136
|
+
console.log("\nNothing to do.");
|
|
3137
|
+
return;
|
|
3012
3138
|
}
|
|
3013
|
-
const firstActionText = actionCandidates[0].getText();
|
|
3014
|
-
workqueue.addPropertyAssignment({
|
|
3015
|
-
name: ACTION_PROPERTY_NAME2,
|
|
3016
|
-
initializer: firstActionText
|
|
3017
|
-
});
|
|
3018
|
-
actionsProperty.remove();
|
|
3019
3139
|
console.log(
|
|
3020
|
-
`
|
|
3140
|
+
`
|
|
3141
|
+
Done. NOTE: usages of these constants elsewhere in 'src/' may now produce TypeScript errors and need manual review.`
|
|
3021
3142
|
);
|
|
3022
|
-
return 1;
|
|
3023
3143
|
}
|
|
3024
|
-
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
|
|
3030
|
-
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
|
|
3035
|
-
|
|
3144
|
+
|
|
3145
|
+
// src/migrations/v2.0/remove-fhir-url-helpers.ts
|
|
3146
|
+
var import_path14 = __toESM(require("path"));
|
|
3147
|
+
var import_ts_morph14 = require("ts-morph");
|
|
3148
|
+
var FHIR_IMPORT = "FHIR_URL";
|
|
3149
|
+
var HELPER_NAMES = /* @__PURE__ */ new Set([
|
|
3150
|
+
"getFromFhir",
|
|
3151
|
+
"updateResourceFromHearth",
|
|
3152
|
+
"updateResourceInHearth"
|
|
3153
|
+
]);
|
|
3154
|
+
function removeHelpers(sourceFilePath, project) {
|
|
3155
|
+
const sourceFile = project.getSourceFile(sourceFilePath);
|
|
3156
|
+
if (!sourceFile) {
|
|
3157
|
+
return {
|
|
3158
|
+
removedHelpers: [],
|
|
3159
|
+
removedImportCount: 0,
|
|
3160
|
+
remainingFhirReferences: 0
|
|
3161
|
+
};
|
|
3162
|
+
}
|
|
3163
|
+
const removedHelpers = [];
|
|
3164
|
+
let removedImportCount = 0;
|
|
3165
|
+
for (const fn of sourceFile.getFunctions()) {
|
|
3166
|
+
const name = fn.getName();
|
|
3167
|
+
if (!name || !HELPER_NAMES.has(name)) continue;
|
|
3168
|
+
removedHelpers.push(name);
|
|
3169
|
+
fn.remove();
|
|
3170
|
+
}
|
|
3171
|
+
for (const stmt of [...sourceFile.getVariableStatements()]) {
|
|
3172
|
+
const declarations = [...stmt.getDeclarations()];
|
|
3173
|
+
const toRemove = declarations.filter((decl) => HELPER_NAMES.has(decl.getName()));
|
|
3174
|
+
if (toRemove.length === 0) continue;
|
|
3175
|
+
removedHelpers.push(...toRemove.map((decl) => decl.getName()));
|
|
3176
|
+
if (toRemove.length === declarations.length) {
|
|
3177
|
+
stmt.remove();
|
|
3178
|
+
} else {
|
|
3179
|
+
for (const decl of toRemove) decl.remove();
|
|
3036
3180
|
}
|
|
3037
|
-
|
|
3038
|
-
|
|
3039
|
-
const
|
|
3040
|
-
if (
|
|
3041
|
-
for (const
|
|
3042
|
-
|
|
3043
|
-
|
|
3181
|
+
}
|
|
3182
|
+
for (const decl of sourceFile.getImportDeclarations()) {
|
|
3183
|
+
const matches = decl.getNamedImports().filter((ni) => ni.getName() === FHIR_IMPORT);
|
|
3184
|
+
if (matches.length === 0) continue;
|
|
3185
|
+
for (const named of matches) {
|
|
3186
|
+
named.remove();
|
|
3187
|
+
removedImportCount++;
|
|
3188
|
+
}
|
|
3189
|
+
const hasAnyNamedImportsLeft = decl.getNamedImports().length > 0;
|
|
3190
|
+
const hasDefaultImport = !!decl.getDefaultImport();
|
|
3191
|
+
const hasNamespaceImport = !!decl.getNamespaceImport();
|
|
3192
|
+
if (!hasAnyNamedImportsLeft && !hasDefaultImport && !hasNamespaceImport) {
|
|
3193
|
+
decl.remove();
|
|
3044
3194
|
}
|
|
3045
3195
|
}
|
|
3046
|
-
|
|
3196
|
+
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;
|
|
3197
|
+
return { removedHelpers, removedImportCount, remainingFhirReferences };
|
|
3047
3198
|
}
|
|
3048
|
-
async function
|
|
3049
|
-
const
|
|
3050
|
-
|
|
3051
|
-
`);
|
|
3052
|
-
const project = new import_ts_morph13.Project({
|
|
3053
|
-
tsConfigFilePath: import_path13.default.resolve(srcDir, "../tsconfig.json"),
|
|
3199
|
+
async function main14() {
|
|
3200
|
+
const project = new import_ts_morph14.Project({
|
|
3201
|
+
tsConfigFilePath: import_path14.default.resolve(process.cwd(), "tsconfig.json"),
|
|
3054
3202
|
skipAddingFilesFromTsConfig: false
|
|
3055
3203
|
});
|
|
3056
3204
|
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
3057
3205
|
const fp = sf.getFilePath();
|
|
3058
3206
|
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
3059
3207
|
});
|
|
3060
|
-
console.log(`
|
|
3208
|
+
console.log(`Removing legacy FHIR_URL helpers in ${sourceFiles.length} source file(s)...
|
|
3061
3209
|
`);
|
|
3062
|
-
let
|
|
3210
|
+
let totalRemovedImports = 0;
|
|
3211
|
+
let totalRemovedHelpers = 0;
|
|
3063
3212
|
const modifiedFiles = [];
|
|
3213
|
+
const warnings = [];
|
|
3064
3214
|
for (const sourceFile of sourceFiles) {
|
|
3065
3215
|
const filePath = sourceFile.getFilePath();
|
|
3066
|
-
const
|
|
3067
|
-
|
|
3068
|
-
|
|
3216
|
+
const rel = import_path14.default.relative(process.cwd(), filePath);
|
|
3217
|
+
const result = removeHelpers(filePath, project);
|
|
3218
|
+
const changed = result.removedImportCount > 0 || result.removedHelpers.length > 0;
|
|
3219
|
+
if (changed) {
|
|
3069
3220
|
modifiedFiles.push(filePath);
|
|
3221
|
+
totalRemovedImports += result.removedImportCount;
|
|
3222
|
+
totalRemovedHelpers += result.removedHelpers.length;
|
|
3223
|
+
if (result.removedHelpers.length > 0) {
|
|
3224
|
+
console.log(
|
|
3225
|
+
` [${rel}] Removed helper(s): ${result.removedHelpers.join(", ")}`
|
|
3226
|
+
);
|
|
3227
|
+
}
|
|
3228
|
+
if (result.removedImportCount > 0) {
|
|
3229
|
+
console.log(
|
|
3230
|
+
` [${rel}] Removed ${result.removedImportCount} '${FHIR_IMPORT}' import(s)`
|
|
3231
|
+
);
|
|
3232
|
+
}
|
|
3233
|
+
}
|
|
3234
|
+
if (result.remainingFhirReferences > 0) {
|
|
3235
|
+
warnings.push(
|
|
3236
|
+
`${rel}: ${result.remainingFhirReferences} remaining '${FHIR_IMPORT}' reference(s)`
|
|
3237
|
+
);
|
|
3070
3238
|
}
|
|
3071
3239
|
}
|
|
3072
|
-
if (modifiedFiles.length === 0) {
|
|
3073
|
-
console.log(
|
|
3074
|
-
"No deprecated workqueue 'actions' arrays found inside defineWorkqueues calls. Nothing to do."
|
|
3075
|
-
);
|
|
3240
|
+
if (modifiedFiles.length === 0 && warnings.length === 0) {
|
|
3241
|
+
console.log("No FHIR_URL imports/helpers found. Nothing to do.");
|
|
3076
3242
|
return;
|
|
3077
3243
|
}
|
|
3078
|
-
|
|
3244
|
+
if (modifiedFiles.length > 0) {
|
|
3245
|
+
console.log(`
|
|
3079
3246
|
Saving ${modifiedFiles.length} modified file(s)...`);
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
|
|
3247
|
+
for (const filePath of modifiedFiles) {
|
|
3248
|
+
await project.getSourceFileOrThrow(filePath).save();
|
|
3249
|
+
console.log(` Saved: ${import_path14.default.relative(process.cwd(), filePath)}`);
|
|
3250
|
+
}
|
|
3251
|
+
}
|
|
3252
|
+
if (warnings.length > 0) {
|
|
3253
|
+
console.warn(
|
|
3254
|
+
`
|
|
3255
|
+
WARNING: Some '${FHIR_IMPORT}' usages remain and need manual cleanup:
|
|
3256
|
+
` + warnings.map((line) => ` - ${line}`).join("\n")
|
|
3257
|
+
);
|
|
3084
3258
|
}
|
|
3085
3259
|
console.log(
|
|
3086
3260
|
`
|
|
3087
|
-
Done.
|
|
3261
|
+
Done. Removed ${totalRemovedHelpers} helper declaration(s) and ${totalRemovedImports} '${FHIR_IMPORT}' import(s).`
|
|
3088
3262
|
);
|
|
3089
3263
|
}
|
|
3090
3264
|
|
|
3091
|
-
// src/migrations/v2.0/
|
|
3092
|
-
var
|
|
3093
|
-
var
|
|
3094
|
-
var
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
);
|
|
3106
|
-
|
|
3265
|
+
// src/migrations/v2.0/migrate-application-config-url.ts
|
|
3266
|
+
var import_path15 = __toESM(require("path"));
|
|
3267
|
+
var import_ts_morph15 = require("ts-morph");
|
|
3268
|
+
var TARGET_IDENTIFIER = "APPLICATION_CONFIG_URL";
|
|
3269
|
+
var REPLACEMENT_IDENTIFIER = "applicationConfig";
|
|
3270
|
+
var REPLACEMENT_MODULE = "@countryconfig/api/application/application-config";
|
|
3271
|
+
var FUNCTION_LIKE_KINDS = [
|
|
3272
|
+
import_ts_morph15.SyntaxKind.FunctionDeclaration,
|
|
3273
|
+
import_ts_morph15.SyntaxKind.FunctionExpression,
|
|
3274
|
+
import_ts_morph15.SyntaxKind.ArrowFunction,
|
|
3275
|
+
import_ts_morph15.SyntaxKind.MethodDeclaration
|
|
3276
|
+
];
|
|
3277
|
+
function describeFunction(node) {
|
|
3278
|
+
if (import_ts_morph15.Node.isFunctionDeclaration(node) || import_ts_morph15.Node.isMethodDeclaration(node)) {
|
|
3279
|
+
return node.getName() ?? "<anonymous>";
|
|
3280
|
+
}
|
|
3281
|
+
const parent = node.getParent();
|
|
3282
|
+
if (parent && import_ts_morph15.Node.isVariableDeclaration(parent)) {
|
|
3283
|
+
return parent.getName();
|
|
3284
|
+
}
|
|
3285
|
+
if (parent && import_ts_morph15.Node.isPropertyAssignment(parent)) {
|
|
3286
|
+
return parent.getName();
|
|
3287
|
+
}
|
|
3288
|
+
if (import_ts_morph15.Node.isFunctionExpression(node) && node.getNameNode() !== void 0) {
|
|
3289
|
+
return node.getNameNode()?.getText() ?? "<anonymous>";
|
|
3290
|
+
}
|
|
3291
|
+
return "<anonymous>";
|
|
3292
|
+
}
|
|
3293
|
+
function hasBlockBody(node) {
|
|
3294
|
+
if (import_ts_morph15.Node.isFunctionDeclaration(node) || import_ts_morph15.Node.isFunctionExpression(node) || import_ts_morph15.Node.isMethodDeclaration(node)) {
|
|
3295
|
+
return node.getBody() !== void 0;
|
|
3296
|
+
}
|
|
3297
|
+
if (import_ts_morph15.Node.isArrowFunction(node)) {
|
|
3298
|
+
return node.getBody().getKind() === import_ts_morph15.SyntaxKind.Block;
|
|
3299
|
+
}
|
|
3300
|
+
return false;
|
|
3301
|
+
}
|
|
3302
|
+
function isConfigFetcher(node) {
|
|
3303
|
+
let referencesTarget = false;
|
|
3304
|
+
let callsFetch = false;
|
|
3305
|
+
for (const id of node.getDescendantsOfKind(import_ts_morph15.SyntaxKind.Identifier)) {
|
|
3306
|
+
const text = id.getText();
|
|
3307
|
+
if (!referencesTarget && text === TARGET_IDENTIFIER) referencesTarget = true;
|
|
3308
|
+
if (!callsFetch && text === "fetch") {
|
|
3309
|
+
const parent = id.getParent();
|
|
3310
|
+
if (import_ts_morph15.Node.isCallExpression(parent) && parent.getExpression() === id) {
|
|
3311
|
+
callsFetch = true;
|
|
3312
|
+
}
|
|
3313
|
+
}
|
|
3314
|
+
if (referencesTarget && callsFetch) return true;
|
|
3315
|
+
}
|
|
3316
|
+
return false;
|
|
3317
|
+
}
|
|
3318
|
+
function processFile11(sourceFile) {
|
|
3319
|
+
const importsWithTarget = sourceFile.getImportDeclarations().filter(
|
|
3320
|
+
(decl) => decl.getNamedImports().some((ni) => ni.getName() === TARGET_IDENTIFIER)
|
|
3321
|
+
);
|
|
3322
|
+
if (importsWithTarget.length === 0) {
|
|
3323
|
+
return { changed: false, rewrittenFunctions: [], renamedReferences: 0 };
|
|
3324
|
+
}
|
|
3325
|
+
const collidingLocals = sourceFile.getDescendantsOfKind(import_ts_morph15.SyntaxKind.Identifier).filter((id) => id.getText() === REPLACEMENT_IDENTIFIER).filter((id) => {
|
|
3326
|
+
const parent = id.getParent();
|
|
3327
|
+
const kind = parent.getKind();
|
|
3328
|
+
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;
|
|
3329
|
+
});
|
|
3330
|
+
if (collidingLocals.length > 0) {
|
|
3331
|
+
return {
|
|
3332
|
+
changed: false,
|
|
3333
|
+
rewrittenFunctions: [],
|
|
3334
|
+
renamedReferences: 0,
|
|
3335
|
+
skippedReason: `local declaration named '${REPLACEMENT_IDENTIFIER}' would collide`
|
|
3336
|
+
};
|
|
3337
|
+
}
|
|
3338
|
+
const candidateFunctions = FUNCTION_LIKE_KINDS.flatMap(
|
|
3339
|
+
(kind) => sourceFile.getDescendantsOfKind(kind)
|
|
3340
|
+
);
|
|
3341
|
+
candidateFunctions.sort((a, b) => a.getStart() - b.getStart());
|
|
3342
|
+
const rewrittenFunctions = [];
|
|
3343
|
+
const rewrittenSet = /* @__PURE__ */ new Set();
|
|
3344
|
+
for (const fn of candidateFunctions) {
|
|
3345
|
+
if (!hasBlockBody(fn)) continue;
|
|
3346
|
+
if (!isConfigFetcher(fn)) continue;
|
|
3347
|
+
let inRewrittenAncestor = false;
|
|
3348
|
+
let cursor = fn.getParent();
|
|
3349
|
+
while (cursor) {
|
|
3350
|
+
if (rewrittenSet.has(cursor)) {
|
|
3351
|
+
inRewrittenAncestor = true;
|
|
3352
|
+
break;
|
|
3353
|
+
}
|
|
3354
|
+
cursor = cursor.getParent();
|
|
3355
|
+
}
|
|
3356
|
+
if (inRewrittenAncestor) continue;
|
|
3357
|
+
const start = fn.getStart();
|
|
3358
|
+
const line = sourceFile.getLineAndColumnAtPos(start).line;
|
|
3359
|
+
const name = describeFunction(fn);
|
|
3360
|
+
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)) {
|
|
3361
|
+
fn.setBodyText(`return ${REPLACEMENT_IDENTIFIER}`);
|
|
3362
|
+
}
|
|
3363
|
+
rewrittenFunctions.push({ name, line });
|
|
3364
|
+
rewrittenSet.add(fn);
|
|
3365
|
+
}
|
|
3366
|
+
for (const decl of importsWithTarget) {
|
|
3367
|
+
const targetNamed = decl.getNamedImports().find((ni) => ni.getName() === TARGET_IDENTIFIER);
|
|
3368
|
+
targetNamed?.remove();
|
|
3369
|
+
const isNowEmpty = decl.getNamedImports().length === 0 && !decl.getDefaultImport() && !decl.getNamespaceImport();
|
|
3370
|
+
if (isNowEmpty) decl.remove();
|
|
3371
|
+
}
|
|
3372
|
+
const existing = sourceFile.getImportDeclaration(
|
|
3373
|
+
(decl) => decl.getModuleSpecifierValue() === REPLACEMENT_MODULE
|
|
3374
|
+
);
|
|
3375
|
+
if (existing) {
|
|
3376
|
+
const alreadyImported = existing.getNamedImports().some((ni) => ni.getName() === REPLACEMENT_IDENTIFIER);
|
|
3377
|
+
if (!alreadyImported) existing.addNamedImport(REPLACEMENT_IDENTIFIER);
|
|
3378
|
+
} else {
|
|
3379
|
+
sourceFile.addImportDeclaration({
|
|
3380
|
+
moduleSpecifier: REPLACEMENT_MODULE,
|
|
3381
|
+
namedImports: [REPLACEMENT_IDENTIFIER]
|
|
3382
|
+
});
|
|
3383
|
+
}
|
|
3384
|
+
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) => {
|
|
3385
|
+
const parent = id.getParent();
|
|
3386
|
+
const parentKind = parent.getKind();
|
|
3387
|
+
if (parentKind === import_ts_morph15.SyntaxKind.PropertyAccessExpression) {
|
|
3388
|
+
const pae = parent.asKind(import_ts_morph15.SyntaxKind.PropertyAccessExpression);
|
|
3389
|
+
if (pae.getNameNode() === id) return false;
|
|
3390
|
+
}
|
|
3391
|
+
if (parentKind === import_ts_morph15.SyntaxKind.PropertyAssignment) {
|
|
3392
|
+
const pa = parent.asKind(import_ts_morph15.SyntaxKind.PropertyAssignment);
|
|
3393
|
+
if (pa.getNameNode() === id) return false;
|
|
3394
|
+
}
|
|
3395
|
+
if (parentKind === import_ts_morph15.SyntaxKind.ShorthandPropertyAssignment) {
|
|
3396
|
+
return false;
|
|
3397
|
+
}
|
|
3398
|
+
return true;
|
|
3399
|
+
}).sort((a, b) => b.getPos() - a.getPos());
|
|
3400
|
+
for (const id of renameTargets) {
|
|
3401
|
+
id.replaceWithText(REPLACEMENT_IDENTIFIER);
|
|
3402
|
+
}
|
|
3403
|
+
return {
|
|
3404
|
+
changed: true,
|
|
3405
|
+
rewrittenFunctions,
|
|
3406
|
+
renamedReferences: renameTargets.length
|
|
3407
|
+
};
|
|
3408
|
+
}
|
|
3409
|
+
async function main15() {
|
|
3410
|
+
const project = new import_ts_morph15.Project({
|
|
3411
|
+
tsConfigFilePath: import_path15.default.resolve(process.cwd(), "tsconfig.json"),
|
|
3412
|
+
skipAddingFilesFromTsConfig: false
|
|
3413
|
+
});
|
|
3414
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
3415
|
+
const fp = sf.getFilePath();
|
|
3416
|
+
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
3417
|
+
});
|
|
3418
|
+
console.log(
|
|
3419
|
+
`Migrating '${TARGET_IDENTIFIER}' \u2192 '${REPLACEMENT_IDENTIFIER}' across ${sourceFiles.length} source file(s)...
|
|
3420
|
+
`
|
|
3421
|
+
);
|
|
3422
|
+
let changedFiles = 0;
|
|
3423
|
+
let totalRewrittenFunctions = 0;
|
|
3424
|
+
let totalRenamedReferences = 0;
|
|
3425
|
+
const skipped = [];
|
|
3426
|
+
for (const sourceFile of sourceFiles) {
|
|
3427
|
+
const filePath = sourceFile.getFilePath();
|
|
3428
|
+
const rel = import_path15.default.relative(process.cwd(), filePath);
|
|
3429
|
+
const result = processFile11(sourceFile);
|
|
3430
|
+
if (result.skippedReason) {
|
|
3431
|
+
skipped.push(`${rel} (${result.skippedReason})`);
|
|
3432
|
+
continue;
|
|
3433
|
+
}
|
|
3434
|
+
if (!result.changed) continue;
|
|
3435
|
+
await sourceFile.save();
|
|
3436
|
+
changedFiles++;
|
|
3437
|
+
totalRewrittenFunctions += result.rewrittenFunctions.length;
|
|
3438
|
+
totalRenamedReferences += result.renamedReferences;
|
|
3439
|
+
for (const fn of result.rewrittenFunctions) {
|
|
3440
|
+
console.log(
|
|
3441
|
+
` [${rel}:${fn.line}] Rewrote '${fn.name}' body \u2192 'return ${REPLACEMENT_IDENTIFIER}' (config fetch eliminated)`
|
|
3442
|
+
);
|
|
3443
|
+
}
|
|
3444
|
+
if (result.renamedReferences > 0) {
|
|
3445
|
+
console.log(
|
|
3446
|
+
` [${rel}] Renamed ${result.renamedReferences} stray reference(s) ${TARGET_IDENTIFIER} \u2192 ${REPLACEMENT_IDENTIFIER}`
|
|
3447
|
+
);
|
|
3448
|
+
}
|
|
3449
|
+
}
|
|
3450
|
+
if (skipped.length > 0) {
|
|
3451
|
+
console.warn(
|
|
3452
|
+
`
|
|
3453
|
+
${skipped.length} file(s) skipped:
|
|
3454
|
+
` + skipped.map((s) => ` - ${s}`).join("\n")
|
|
3455
|
+
);
|
|
3456
|
+
}
|
|
3457
|
+
if (changedFiles === 0) {
|
|
3458
|
+
console.log(`
|
|
3459
|
+
No files reference '${TARGET_IDENTIFIER}'. Nothing to do.`);
|
|
3460
|
+
return;
|
|
3461
|
+
}
|
|
3462
|
+
console.log(
|
|
3463
|
+
`
|
|
3464
|
+
Done. Updated ${changedFiles} file(s): ${totalRewrittenFunctions} fetch function(s) rewritten, ${totalRenamedReferences} bare reference(s) renamed.`
|
|
3465
|
+
);
|
|
3466
|
+
if (totalRewrittenFunctions > 0) {
|
|
3467
|
+
console.log(
|
|
3468
|
+
`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}'.`
|
|
3469
|
+
);
|
|
3470
|
+
}
|
|
3471
|
+
}
|
|
3472
|
+
|
|
3473
|
+
// src/migrations/v2.0/remove-old-statistics-service.ts
|
|
3474
|
+
var import_path16 = __toESM(require("path"));
|
|
3475
|
+
var import_ts_morph16 = require("ts-morph");
|
|
3476
|
+
var ROUTE_PATH = "/statistics";
|
|
3477
|
+
var HANDLER_NAME = "statisticsHandler";
|
|
3478
|
+
function isStatisticsRouteObject(obj) {
|
|
3479
|
+
const pathProp = obj.getProperty("path");
|
|
3480
|
+
if (!pathProp || !import_ts_morph16.Node.isPropertyAssignment(pathProp)) return false;
|
|
3481
|
+
const init = pathProp.getInitializer();
|
|
3482
|
+
if (!init) return false;
|
|
3483
|
+
if (import_ts_morph16.Node.isStringLiteral(init) || import_ts_morph16.Node.isNoSubstitutionTemplateLiteral(init)) {
|
|
3484
|
+
return init.getLiteralValue() === ROUTE_PATH;
|
|
3485
|
+
}
|
|
3486
|
+
return false;
|
|
3487
|
+
}
|
|
3488
|
+
function removeStatisticsRoutes(sourceFile) {
|
|
3489
|
+
let removed = 0;
|
|
3490
|
+
const callExpressions = [
|
|
3491
|
+
...sourceFile.getDescendantsOfKind(import_ts_morph16.SyntaxKind.CallExpression)
|
|
3492
|
+
];
|
|
3493
|
+
for (const call of callExpressions) {
|
|
3494
|
+
if (call.wasForgotten()) continue;
|
|
3495
|
+
const expr = call.getExpression();
|
|
3496
|
+
if (!import_ts_morph16.Node.isPropertyAccessExpression(expr)) continue;
|
|
3497
|
+
if (expr.getName() !== "route") continue;
|
|
3498
|
+
const args = call.getArguments();
|
|
3499
|
+
if (args.length === 0) continue;
|
|
3500
|
+
const firstArg = args[0];
|
|
3501
|
+
if (import_ts_morph16.Node.isObjectLiteralExpression(firstArg)) {
|
|
3502
|
+
if (!isStatisticsRouteObject(firstArg)) continue;
|
|
3503
|
+
const stmt = call.getFirstAncestorByKind(import_ts_morph16.SyntaxKind.ExpressionStatement);
|
|
3504
|
+
if (stmt) {
|
|
3505
|
+
stmt.remove();
|
|
3506
|
+
removed++;
|
|
3507
|
+
} else {
|
|
3508
|
+
call.replaceWithText("");
|
|
3509
|
+
removed++;
|
|
3510
|
+
}
|
|
3511
|
+
continue;
|
|
3512
|
+
}
|
|
3513
|
+
if (import_ts_morph16.Node.isArrayLiteralExpression(firstArg)) {
|
|
3514
|
+
const matchingIndexes = firstArg.getElements().map((el, idx) => ({ el, idx })).filter(
|
|
3515
|
+
({ el }) => import_ts_morph16.Node.isObjectLiteralExpression(el) && isStatisticsRouteObject(el)
|
|
3516
|
+
).map(({ idx }) => idx);
|
|
3517
|
+
matchingIndexes.sort((a, b) => b - a).forEach((idx) => {
|
|
3518
|
+
firstArg.removeElement(idx);
|
|
3519
|
+
removed++;
|
|
3520
|
+
});
|
|
3521
|
+
}
|
|
3522
|
+
}
|
|
3523
|
+
return removed;
|
|
3524
|
+
}
|
|
3525
|
+
function removeStatisticsHandlerImports(sourceFile) {
|
|
3526
|
+
let changed = false;
|
|
3527
|
+
for (const decl of sourceFile.getImportDeclarations()) {
|
|
3528
|
+
const targetNamed = decl.getNamedImports().find((ni) => ni.getName() === HANDLER_NAME);
|
|
3529
|
+
if (!targetNamed) continue;
|
|
3530
|
+
targetNamed.remove();
|
|
3531
|
+
changed = true;
|
|
3532
|
+
const isNowEmpty = decl.getNamedImports().length === 0 && !decl.getDefaultImport() && !decl.getNamespaceImport();
|
|
3533
|
+
if (isNowEmpty) decl.remove();
|
|
3534
|
+
}
|
|
3535
|
+
return changed;
|
|
3536
|
+
}
|
|
3537
|
+
function processFile12(sourceFile) {
|
|
3538
|
+
const routesRemoved = removeStatisticsRoutes(sourceFile);
|
|
3539
|
+
const importsCleaned = removeStatisticsHandlerImports(sourceFile);
|
|
3540
|
+
return { routesRemoved, importsCleaned };
|
|
3541
|
+
}
|
|
3542
|
+
function collectLocalImportsInSubtree(sourceFile, subtreeRoot) {
|
|
3543
|
+
const result = [];
|
|
3544
|
+
for (const decl of sourceFile.getImportDeclarations()) {
|
|
3545
|
+
const moduleSf = decl.getModuleSpecifierSourceFile();
|
|
3546
|
+
if (!moduleSf) continue;
|
|
3547
|
+
const fp = moduleSf.getFilePath();
|
|
3548
|
+
if (!fp.startsWith(subtreeRoot)) continue;
|
|
3549
|
+
result.push(fp);
|
|
3550
|
+
}
|
|
3551
|
+
return result;
|
|
3552
|
+
}
|
|
3553
|
+
function deleteOrphanedDescendants(project, startingFile, subtreeRoot) {
|
|
3554
|
+
const initialCandidates = collectLocalImportsInSubtree(
|
|
3555
|
+
startingFile,
|
|
3556
|
+
subtreeRoot
|
|
3557
|
+
);
|
|
3558
|
+
const startingPath = startingFile.getFilePath();
|
|
3559
|
+
const deleted = /* @__PURE__ */ new Set([startingPath]);
|
|
3560
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3561
|
+
const worklist = [...initialCandidates];
|
|
3562
|
+
const orphans = [];
|
|
3563
|
+
while (worklist.length > 0) {
|
|
3564
|
+
const candidate = worklist.shift();
|
|
3565
|
+
if (seen.has(candidate)) continue;
|
|
3566
|
+
seen.add(candidate);
|
|
3567
|
+
if (deleted.has(candidate)) continue;
|
|
3568
|
+
if (!candidate.startsWith(subtreeRoot)) continue;
|
|
3569
|
+
const candidateSf = project.getSourceFile(candidate);
|
|
3570
|
+
if (!candidateSf) continue;
|
|
3571
|
+
const stillImported = project.getSourceFiles().some((sf) => {
|
|
3572
|
+
const sfPath = sf.getFilePath();
|
|
3573
|
+
if (deleted.has(sfPath)) return false;
|
|
3574
|
+
if (sfPath === candidate) return false;
|
|
3575
|
+
return sf.getImportDeclarations().some(
|
|
3576
|
+
(decl) => decl.getModuleSpecifierSourceFile()?.getFilePath() === candidate
|
|
3577
|
+
);
|
|
3578
|
+
});
|
|
3579
|
+
if (stillImported) continue;
|
|
3580
|
+
const next = collectLocalImportsInSubtree(candidateSf, subtreeRoot);
|
|
3581
|
+
worklist.push(...next);
|
|
3582
|
+
candidateSf.delete();
|
|
3583
|
+
deleted.add(candidate);
|
|
3584
|
+
orphans.push(candidate);
|
|
3585
|
+
}
|
|
3586
|
+
return orphans;
|
|
3587
|
+
}
|
|
3588
|
+
function processHandlerFile(project) {
|
|
3589
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
3590
|
+
const fp = sf.getFilePath();
|
|
3591
|
+
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
3592
|
+
});
|
|
3593
|
+
for (const sf of sourceFiles) {
|
|
3594
|
+
const fn = sf.getFunction(HANDLER_NAME);
|
|
3595
|
+
if (!fn) continue;
|
|
3596
|
+
const filePath = sf.getFilePath();
|
|
3597
|
+
const exportsByName = [...sf.getExportedDeclarations().keys()];
|
|
3598
|
+
const otherExports = exportsByName.filter((name) => name !== HANDLER_NAME);
|
|
3599
|
+
if (otherExports.length === 0) {
|
|
3600
|
+
const subtreeRoot = import_path16.default.dirname(filePath) + import_path16.default.sep;
|
|
3601
|
+
const orphansDeleted = deleteOrphanedDescendants(
|
|
3602
|
+
project,
|
|
3603
|
+
sf,
|
|
3604
|
+
subtreeRoot
|
|
3605
|
+
);
|
|
3606
|
+
sf.delete();
|
|
3607
|
+
return { filePath, action: "deleted", orphansDeleted };
|
|
3608
|
+
}
|
|
3609
|
+
fn.remove();
|
|
3610
|
+
return {
|
|
3611
|
+
filePath,
|
|
3612
|
+
action: "function-removed",
|
|
3613
|
+
remainingExports: otherExports,
|
|
3614
|
+
orphansDeleted: []
|
|
3615
|
+
};
|
|
3616
|
+
}
|
|
3617
|
+
return { filePath: "", action: "not-found", orphansDeleted: [] };
|
|
3618
|
+
}
|
|
3619
|
+
async function main16() {
|
|
3620
|
+
const project = new import_ts_morph16.Project({
|
|
3621
|
+
tsConfigFilePath: import_path16.default.resolve(process.cwd(), "tsconfig.json"),
|
|
3622
|
+
skipAddingFilesFromTsConfig: false
|
|
3623
|
+
});
|
|
3624
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
3625
|
+
const fp = sf.getFilePath();
|
|
3626
|
+
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
3627
|
+
});
|
|
3628
|
+
console.log(
|
|
3629
|
+
`Removing legacy 'GET ${ROUTE_PATH}' route and '${HANDLER_NAME}' across ${sourceFiles.length} source file(s)...
|
|
3630
|
+
`
|
|
3631
|
+
);
|
|
3632
|
+
let totalRoutesRemoved = 0;
|
|
3633
|
+
let totalFilesWithImportsCleaned = 0;
|
|
3634
|
+
let totalFilesWithRoutesRemoved = 0;
|
|
3635
|
+
for (const sourceFile of sourceFiles) {
|
|
3636
|
+
const filePath = sourceFile.getFilePath();
|
|
3637
|
+
const rel = import_path16.default.relative(process.cwd(), filePath);
|
|
3638
|
+
const result = processFile12(sourceFile);
|
|
3639
|
+
if (result.routesRemoved > 0) {
|
|
3640
|
+
console.log(
|
|
3641
|
+
` [${rel}] Removed ${result.routesRemoved} '${ROUTE_PATH}' route(s)`
|
|
3642
|
+
);
|
|
3643
|
+
totalRoutesRemoved += result.routesRemoved;
|
|
3644
|
+
totalFilesWithRoutesRemoved++;
|
|
3645
|
+
}
|
|
3646
|
+
if (result.importsCleaned) {
|
|
3647
|
+
console.log(` [${rel}] Cleaned up '${HANDLER_NAME}' import`);
|
|
3648
|
+
totalFilesWithImportsCleaned++;
|
|
3649
|
+
}
|
|
3650
|
+
if (result.routesRemoved > 0 || result.importsCleaned) {
|
|
3651
|
+
await sourceFile.save();
|
|
3652
|
+
}
|
|
3653
|
+
}
|
|
3654
|
+
const handlerResult = processHandlerFile(project);
|
|
3655
|
+
switch (handlerResult.action) {
|
|
3656
|
+
case "deleted": {
|
|
3657
|
+
const rel = import_path16.default.relative(process.cwd(), handlerResult.filePath);
|
|
3658
|
+
console.log(
|
|
3659
|
+
` [${rel}] Deleted handler file ('${HANDLER_NAME}' was the sole export).`
|
|
3660
|
+
);
|
|
3661
|
+
for (const orphanPath of handlerResult.orphansDeleted) {
|
|
3662
|
+
const orphanRel = import_path16.default.relative(process.cwd(), orphanPath);
|
|
3663
|
+
console.log(
|
|
3664
|
+
` [${orphanRel}] Deleted (no remaining importers in the project after handler removal).`
|
|
3665
|
+
);
|
|
3666
|
+
}
|
|
3667
|
+
await project.save();
|
|
3668
|
+
break;
|
|
3669
|
+
}
|
|
3670
|
+
case "function-removed": {
|
|
3671
|
+
const rel = import_path16.default.relative(process.cwd(), handlerResult.filePath);
|
|
3672
|
+
console.warn(
|
|
3673
|
+
` [${rel}] Removed '${HANDLER_NAME}' function but kept the file (other exports remain: ${handlerResult.remainingExports?.join(", ")}). Review whether the file is still needed.`
|
|
3674
|
+
);
|
|
3675
|
+
const sf = project.getSourceFile(handlerResult.filePath);
|
|
3676
|
+
if (sf) await sf.save();
|
|
3677
|
+
break;
|
|
3678
|
+
}
|
|
3679
|
+
case "not-found":
|
|
3680
|
+
break;
|
|
3681
|
+
}
|
|
3682
|
+
if (totalRoutesRemoved === 0 && totalFilesWithImportsCleaned === 0 && handlerResult.action === "not-found") {
|
|
3683
|
+
console.log(`
|
|
3684
|
+
No legacy '${ROUTE_PATH}' route or handler found. Nothing to do.`);
|
|
3685
|
+
return;
|
|
3686
|
+
}
|
|
3687
|
+
const orphansSummary = handlerResult.orphansDeleted.length > 0 ? ` and ${handlerResult.orphansDeleted.length} orphaned helper file(s)` : "";
|
|
3688
|
+
console.log(
|
|
3689
|
+
`
|
|
3690
|
+
Done. Removed ${totalRoutesRemoved} route(s) across ${totalFilesWithRoutesRemoved} file(s); cleaned ${HANDLER_NAME} import in ${totalFilesWithImportsCleaned} file(s)${orphansSummary}.`
|
|
3691
|
+
);
|
|
3692
|
+
}
|
|
3693
|
+
|
|
3694
|
+
// src/migrations/v2.0/update-package-json.ts
|
|
3695
|
+
var import_fs = require("fs");
|
|
3696
|
+
var import_path17 = __toESM(require("path"));
|
|
3697
|
+
var PACKAGE_JSON_RELATIVE = "package.json";
|
|
3698
|
+
var TARGET_VERSION = "2.0.0";
|
|
3699
|
+
var TARGET_ZOD_RANGE = "^4.2.1";
|
|
3700
|
+
async function main17() {
|
|
3701
|
+
const packageJsonPath = import_path17.default.join(process.cwd(), PACKAGE_JSON_RELATIVE);
|
|
3702
|
+
if (!(0, import_fs.existsSync)(packageJsonPath)) {
|
|
3703
|
+
console.log(`'${PACKAGE_JSON_RELATIVE}' not found in ${process.cwd()} \u2014 skipping.`);
|
|
3704
|
+
return;
|
|
3705
|
+
}
|
|
3706
|
+
const raw = (0, import_fs.readFileSync)(packageJsonPath, "utf8");
|
|
3707
|
+
let parsed;
|
|
3708
|
+
try {
|
|
3709
|
+
parsed = JSON.parse(raw);
|
|
3710
|
+
} catch (error) {
|
|
3711
|
+
console.warn(
|
|
3712
|
+
` [${PACKAGE_JSON_RELATIVE}] Failed to parse JSON \u2014 skipping update. ${error.message}`
|
|
3713
|
+
);
|
|
3714
|
+
return;
|
|
3715
|
+
}
|
|
3716
|
+
console.log(`Updating '${PACKAGE_JSON_RELATIVE}'...`);
|
|
3717
|
+
const previousVersion = parsed.version;
|
|
3718
|
+
const versionChanged = previousVersion !== TARGET_VERSION;
|
|
3719
|
+
parsed.version = TARGET_VERSION;
|
|
3720
|
+
if (versionChanged) {
|
|
3721
|
+
console.log(
|
|
3722
|
+
` Set version: ${previousVersion ?? "<unset>"} \u2192 ${TARGET_VERSION}`
|
|
3723
|
+
);
|
|
3724
|
+
} else {
|
|
3725
|
+
console.log(` Version already ${TARGET_VERSION} \u2014 no change.`);
|
|
3726
|
+
}
|
|
3727
|
+
let zodBucket = "dependencies";
|
|
3728
|
+
if (parsed.devDependencies && "zod" in parsed.devDependencies) {
|
|
3729
|
+
zodBucket = "devDependencies";
|
|
3730
|
+
}
|
|
3731
|
+
if (!parsed[zodBucket]) {
|
|
3732
|
+
parsed[zodBucket] = {};
|
|
3733
|
+
}
|
|
3734
|
+
const bucket = parsed[zodBucket];
|
|
3735
|
+
const previousZod = bucket.zod;
|
|
3736
|
+
const zodChanged = previousZod !== TARGET_ZOD_RANGE;
|
|
3737
|
+
bucket.zod = TARGET_ZOD_RANGE;
|
|
3738
|
+
if (zodChanged) {
|
|
3739
|
+
console.log(
|
|
3740
|
+
` Set ${zodBucket}.zod: ${previousZod ?? "<absent>"} \u2192 ${TARGET_ZOD_RANGE}`
|
|
3741
|
+
);
|
|
3742
|
+
} else {
|
|
3743
|
+
console.log(` ${zodBucket}.zod already ${TARGET_ZOD_RANGE} \u2014 no change.`);
|
|
3744
|
+
}
|
|
3745
|
+
const trailingNewline = raw.endsWith("\n") ? "\n" : "";
|
|
3746
|
+
const next = JSON.stringify(parsed, null, 2) + trailingNewline;
|
|
3747
|
+
if (next === raw) {
|
|
3748
|
+
console.log("\n No changes to write.");
|
|
3749
|
+
return;
|
|
3750
|
+
}
|
|
3751
|
+
(0, import_fs.writeFileSync)(packageJsonPath, next, "utf8");
|
|
3752
|
+
console.log(`
|
|
3753
|
+
Saved '${PACKAGE_JSON_RELATIVE}'.`);
|
|
3754
|
+
console.log(
|
|
3755
|
+
` NOTE: run \`yarn install\` (or your package manager equivalent) to install the updated dependency versions.`
|
|
3756
|
+
);
|
|
3757
|
+
}
|
|
3758
|
+
|
|
3759
|
+
// src/migrations/v2.0/migrate-workqueue-configs.ts
|
|
3760
|
+
var import_ts_morph17 = require("ts-morph");
|
|
3761
|
+
var import_path18 = __toESM(require("path"));
|
|
3762
|
+
var DEFINE_WORKQUEUES_NAME3 = "defineWorkqueues";
|
|
3763
|
+
var ACTIONS_PROPERTY_NAME5 = "actions";
|
|
3764
|
+
var ACTION_PROPERTY_NAME2 = "action";
|
|
3765
|
+
var CONDITIONALS_PROPERTY_NAME = "conditionals";
|
|
3766
|
+
var TYPE_PROPERTY_NAME7 = "type";
|
|
3767
|
+
var SLUG_PROPERTY_NAME = "slug";
|
|
3768
|
+
var READ_ACTION_TYPE = "READ";
|
|
3769
|
+
var ACTION_TYPE_IMPORT_NAME = "ActionType";
|
|
3770
|
+
var TOOLKIT_EVENTS_MODULE2 = "@opencrvs/toolkit/events";
|
|
3771
|
+
var READ_ACTION_FALLBACK_INITIALIZER = `{ type: ${ACTION_TYPE_IMPORT_NAME}.${READ_ACTION_TYPE} }`;
|
|
3772
|
+
var SUPPORTED_WORKQUEUE_ACTION_TYPES = /* @__PURE__ */ new Set([
|
|
3773
|
+
"READ",
|
|
3774
|
+
"DELETE",
|
|
3775
|
+
"DECLARE",
|
|
3776
|
+
"REGISTER",
|
|
3777
|
+
"EDIT",
|
|
3778
|
+
"REJECT",
|
|
3779
|
+
"MARK_AS_DUPLICATE",
|
|
3780
|
+
"ARCHIVE",
|
|
3781
|
+
"PRINT_CERTIFICATE",
|
|
3782
|
+
"REQUEST_CORRECTION"
|
|
3783
|
+
]);
|
|
3784
|
+
function getWorkqueueLabel(workqueue) {
|
|
3785
|
+
const slugProperty = workqueue.getProperty(SLUG_PROPERTY_NAME);
|
|
3786
|
+
if (!slugProperty || !import_ts_morph17.Node.isPropertyAssignment(slugProperty)) {
|
|
3787
|
+
return "(unknown slug)";
|
|
3788
|
+
}
|
|
3789
|
+
const slugInitializer = slugProperty.getInitializer();
|
|
3790
|
+
if (!slugInitializer || !import_ts_morph17.Node.isStringLiteral(slugInitializer)) {
|
|
3791
|
+
return "(unknown slug)";
|
|
3792
|
+
}
|
|
3793
|
+
return slugInitializer.getLiteralValue();
|
|
3794
|
+
}
|
|
3795
|
+
function getActionTypeName(action) {
|
|
3796
|
+
const typeProperty = action.getProperty(TYPE_PROPERTY_NAME7);
|
|
3797
|
+
if (!typeProperty || !import_ts_morph17.Node.isPropertyAssignment(typeProperty)) {
|
|
3798
|
+
return null;
|
|
3799
|
+
}
|
|
3800
|
+
const typeInitializer = typeProperty.getInitializer();
|
|
3801
|
+
if (!typeInitializer) {
|
|
3802
|
+
return null;
|
|
3803
|
+
}
|
|
3804
|
+
if (import_ts_morph17.Node.isStringLiteral(typeInitializer)) {
|
|
3805
|
+
return typeInitializer.getLiteralValue();
|
|
3806
|
+
}
|
|
3807
|
+
if (import_ts_morph17.Node.isPropertyAccessExpression(typeInitializer)) {
|
|
3808
|
+
return typeInitializer.getName();
|
|
3809
|
+
}
|
|
3810
|
+
return null;
|
|
3811
|
+
}
|
|
3812
|
+
function isUnsupportedActionType(action) {
|
|
3813
|
+
const typeName = getActionTypeName(action);
|
|
3814
|
+
if (!typeName) {
|
|
3815
|
+
return false;
|
|
3816
|
+
}
|
|
3817
|
+
return !SUPPORTED_WORKQUEUE_ACTION_TYPES.has(typeName);
|
|
3818
|
+
}
|
|
3819
|
+
function ensureValidAction(workqueue, relPath) {
|
|
3820
|
+
const workqueueLabel = getWorkqueueLabel(workqueue);
|
|
3821
|
+
const actionProperty = workqueue.getProperty(ACTION_PROPERTY_NAME2);
|
|
3822
|
+
if (actionProperty && import_ts_morph17.Node.isPropertyAssignment(actionProperty)) {
|
|
3823
|
+
const initializer = actionProperty.getInitializer();
|
|
3824
|
+
if (initializer && import_ts_morph17.Node.isObjectLiteralExpression(initializer)) {
|
|
3825
|
+
if (!isUnsupportedActionType(initializer)) {
|
|
3826
|
+
return { changed: false, usedReadFallback: false };
|
|
3827
|
+
}
|
|
3828
|
+
actionProperty.set({
|
|
3829
|
+
name: ACTION_PROPERTY_NAME2,
|
|
3830
|
+
initializer: READ_ACTION_FALLBACK_INITIALIZER
|
|
3831
|
+
});
|
|
3832
|
+
console.log(
|
|
3833
|
+
` [${relPath}] Replaced unsupported 'action' type with '${ACTION_TYPE_IMPORT_NAME}.${READ_ACTION_TYPE}' on workqueue '${workqueueLabel}'`
|
|
3834
|
+
);
|
|
3835
|
+
return { changed: true, usedReadFallback: true };
|
|
3836
|
+
}
|
|
3837
|
+
}
|
|
3838
|
+
workqueue.addPropertyAssignment({
|
|
3839
|
+
name: ACTION_PROPERTY_NAME2,
|
|
3840
|
+
initializer: READ_ACTION_FALLBACK_INITIALIZER
|
|
3841
|
+
});
|
|
3842
|
+
console.log(
|
|
3843
|
+
` [${relPath}] Added default 'action: ${READ_ACTION_FALLBACK_INITIALIZER}' to workqueue '${workqueueLabel}'`
|
|
3844
|
+
);
|
|
3845
|
+
return { changed: true, usedReadFallback: true };
|
|
3846
|
+
}
|
|
3847
|
+
function migrateWorkqueueActions(workqueue, relPath) {
|
|
3848
|
+
const workqueueLabel = getWorkqueueLabel(workqueue);
|
|
3849
|
+
const actionsProperty = workqueue.getProperty(ACTIONS_PROPERTY_NAME5);
|
|
3850
|
+
let actionsArrayMigrated = false;
|
|
3851
|
+
if (actionsProperty && import_ts_morph17.Node.isPropertyAssignment(actionsProperty)) {
|
|
3852
|
+
const actionsInitializer = actionsProperty.getInitializer();
|
|
3853
|
+
if (actionsInitializer && import_ts_morph17.Node.isArrayLiteralExpression(actionsInitializer)) {
|
|
3854
|
+
const existingActionProperty = workqueue.getProperty(ACTION_PROPERTY_NAME2);
|
|
3855
|
+
if (existingActionProperty) {
|
|
3856
|
+
if (import_ts_morph17.Node.isPropertyAssignment(existingActionProperty)) {
|
|
3857
|
+
const existingActionInitializer = existingActionProperty.getInitializer();
|
|
3858
|
+
if (existingActionInitializer && import_ts_morph17.Node.isObjectLiteralExpression(existingActionInitializer)) {
|
|
3859
|
+
const conditionalsProperty = existingActionInitializer.getProperty(
|
|
3860
|
+
CONDITIONALS_PROPERTY_NAME
|
|
3861
|
+
);
|
|
3862
|
+
if (conditionalsProperty) {
|
|
3863
|
+
conditionalsProperty.remove();
|
|
3864
|
+
console.log(
|
|
3865
|
+
` [${relPath}] Removed deprecated 'conditionals' from 'action' on workqueue '${workqueueLabel}'`
|
|
3866
|
+
);
|
|
3867
|
+
}
|
|
3868
|
+
}
|
|
3869
|
+
}
|
|
3870
|
+
actionsProperty.remove();
|
|
3871
|
+
console.log(
|
|
3872
|
+
` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' (existing 'action' kept)`
|
|
3873
|
+
);
|
|
3874
|
+
actionsArrayMigrated = true;
|
|
3875
|
+
} else {
|
|
3876
|
+
const actionCandidates = actionsInitializer.getElements().filter(
|
|
3877
|
+
(element) => import_ts_morph17.Node.isObjectLiteralExpression(element)
|
|
3878
|
+
);
|
|
3879
|
+
if (actionCandidates.length === 0) {
|
|
3880
|
+
actionsProperty.remove();
|
|
3881
|
+
console.log(
|
|
3882
|
+
` [${relPath}] Removed empty 'actions' from workqueue '${workqueueLabel}'`
|
|
3883
|
+
);
|
|
3884
|
+
actionsArrayMigrated = true;
|
|
3885
|
+
} else {
|
|
3886
|
+
if (actionCandidates.length > 1) {
|
|
3887
|
+
const droppedCount = actionCandidates.length - 1;
|
|
3888
|
+
console.warn(
|
|
3889
|
+
` [${relPath}] Workqueue '${workqueueLabel}' has ${actionCandidates.length} actions; keeping first as 'action' and dropping ${droppedCount} extra action(s)`
|
|
3890
|
+
);
|
|
3891
|
+
}
|
|
3892
|
+
const conditionalsProperty = actionCandidates[0].getProperty(
|
|
3893
|
+
CONDITIONALS_PROPERTY_NAME
|
|
3894
|
+
);
|
|
3895
|
+
if (conditionalsProperty) {
|
|
3896
|
+
conditionalsProperty.remove();
|
|
3897
|
+
console.log(
|
|
3898
|
+
` [${relPath}] Removed deprecated 'conditionals' from migrated 'action' on workqueue '${workqueueLabel}'`
|
|
3899
|
+
);
|
|
3900
|
+
}
|
|
3901
|
+
if (isUnsupportedActionType(actionCandidates[0])) {
|
|
3902
|
+
actionsProperty.remove();
|
|
3903
|
+
console.log(
|
|
3904
|
+
` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' because action type is unsupported`
|
|
3905
|
+
);
|
|
3906
|
+
actionsArrayMigrated = true;
|
|
3907
|
+
} else {
|
|
3908
|
+
const firstActionText = actionCandidates[0].getText();
|
|
3909
|
+
workqueue.addPropertyAssignment({
|
|
3910
|
+
name: ACTION_PROPERTY_NAME2,
|
|
3911
|
+
initializer: firstActionText
|
|
3912
|
+
});
|
|
3913
|
+
actionsProperty.remove();
|
|
3914
|
+
console.log(
|
|
3915
|
+
` [${relPath}] Replaced 'actions' with 'action' on workqueue '${workqueueLabel}'`
|
|
3916
|
+
);
|
|
3917
|
+
actionsArrayMigrated = true;
|
|
3918
|
+
}
|
|
3919
|
+
}
|
|
3920
|
+
}
|
|
3921
|
+
}
|
|
3922
|
+
}
|
|
3923
|
+
const fallback = ensureValidAction(workqueue, relPath);
|
|
3924
|
+
return {
|
|
3925
|
+
changed: actionsArrayMigrated || fallback.changed,
|
|
3926
|
+
usedReadFallback: fallback.usedReadFallback
|
|
3927
|
+
};
|
|
3928
|
+
}
|
|
3929
|
+
function ensureActionTypeImport(sourceFile) {
|
|
3930
|
+
const existingImport = sourceFile.getImportDeclaration(
|
|
3931
|
+
(decl) => decl.getModuleSpecifierValue() === TOOLKIT_EVENTS_MODULE2
|
|
3932
|
+
);
|
|
3933
|
+
if (existingImport) {
|
|
3934
|
+
const alreadyImported = existingImport.getNamedImports().some((ni) => ni.getName() === ACTION_TYPE_IMPORT_NAME);
|
|
3935
|
+
if (!alreadyImported) {
|
|
3936
|
+
existingImport.addNamedImport(ACTION_TYPE_IMPORT_NAME);
|
|
3937
|
+
}
|
|
3938
|
+
return;
|
|
3939
|
+
}
|
|
3940
|
+
sourceFile.addImportDeclaration({
|
|
3941
|
+
moduleSpecifier: TOOLKIT_EVENTS_MODULE2,
|
|
3942
|
+
namedImports: [ACTION_TYPE_IMPORT_NAME]
|
|
3943
|
+
});
|
|
3944
|
+
}
|
|
3945
|
+
function processFile13(filePath, project) {
|
|
3946
|
+
const sourceFile = project.getSourceFile(filePath);
|
|
3947
|
+
if (!sourceFile) return 0;
|
|
3948
|
+
let migratedWorkqueues = 0;
|
|
3949
|
+
let needsActionTypeImport = false;
|
|
3950
|
+
const relPath = import_path18.default.relative(process.cwd(), filePath);
|
|
3951
|
+
const callExpressions = sourceFile.getDescendantsOfKind(
|
|
3952
|
+
import_ts_morph17.SyntaxKind.CallExpression
|
|
3953
|
+
);
|
|
3954
|
+
for (const call of callExpressions) {
|
|
3955
|
+
const expression = call.getExpression();
|
|
3956
|
+
if (!import_ts_morph17.Node.isIdentifier(expression) || expression.getText() !== DEFINE_WORKQUEUES_NAME3) {
|
|
3957
|
+
continue;
|
|
3958
|
+
}
|
|
3959
|
+
const args = call.getArguments();
|
|
3960
|
+
if (args.length === 0) continue;
|
|
3961
|
+
const workqueuesArg = args[0];
|
|
3962
|
+
if (!import_ts_morph17.Node.isArrayLiteralExpression(workqueuesArg)) continue;
|
|
3963
|
+
for (const element of workqueuesArg.getElements()) {
|
|
3964
|
+
if (!import_ts_morph17.Node.isObjectLiteralExpression(element)) continue;
|
|
3965
|
+
const result = migrateWorkqueueActions(element, relPath);
|
|
3966
|
+
if (result.changed) migratedWorkqueues++;
|
|
3967
|
+
if (result.usedReadFallback) needsActionTypeImport = true;
|
|
3968
|
+
}
|
|
3969
|
+
}
|
|
3970
|
+
if (needsActionTypeImport) {
|
|
3971
|
+
ensureActionTypeImport(sourceFile);
|
|
3972
|
+
}
|
|
3973
|
+
return migratedWorkqueues;
|
|
3974
|
+
}
|
|
3975
|
+
async function main18() {
|
|
3976
|
+
const srcDir = import_path18.default.join(process.cwd(), "src");
|
|
3977
|
+
console.log(`Scanning for defineWorkqueues calls in: ${srcDir}
|
|
3978
|
+
`);
|
|
3979
|
+
const project = new import_ts_morph17.Project({
|
|
3980
|
+
tsConfigFilePath: import_path18.default.resolve(srcDir, "../tsconfig.json"),
|
|
3981
|
+
skipAddingFilesFromTsConfig: false
|
|
3982
|
+
});
|
|
3983
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
3984
|
+
const fp = sf.getFilePath();
|
|
3985
|
+
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
3986
|
+
});
|
|
3987
|
+
console.log(`Found ${sourceFiles.length} source file(s) to analyse.
|
|
3988
|
+
`);
|
|
3989
|
+
let totalMigrated = 0;
|
|
3990
|
+
const modifiedFiles = [];
|
|
3991
|
+
for (const sourceFile of sourceFiles) {
|
|
3992
|
+
const filePath = sourceFile.getFilePath();
|
|
3993
|
+
const migrated = processFile13(filePath, project);
|
|
3994
|
+
if (migrated > 0) {
|
|
3995
|
+
totalMigrated += migrated;
|
|
3996
|
+
modifiedFiles.push(filePath);
|
|
3997
|
+
}
|
|
3998
|
+
}
|
|
3999
|
+
if (modifiedFiles.length === 0) {
|
|
4000
|
+
console.log(
|
|
4001
|
+
"No deprecated workqueue 'actions' arrays found inside defineWorkqueues calls. Nothing to do."
|
|
4002
|
+
);
|
|
4003
|
+
return;
|
|
4004
|
+
}
|
|
4005
|
+
console.log(`
|
|
4006
|
+
Saving ${modifiedFiles.length} modified file(s)...`);
|
|
4007
|
+
for (const filePath of modifiedFiles) {
|
|
4008
|
+
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
4009
|
+
await sourceFile.save();
|
|
4010
|
+
console.log(` Saved: ${import_path18.default.relative(process.cwd(), filePath)}`);
|
|
4011
|
+
}
|
|
4012
|
+
console.log(
|
|
4013
|
+
`
|
|
4014
|
+
Done. Migrated ${totalMigrated} deprecated workqueue 'actions' definition(s) to 'action'.`
|
|
4015
|
+
);
|
|
4016
|
+
}
|
|
4017
|
+
|
|
4018
|
+
// src/migrations/v2.0/remove-demo-scope.ts
|
|
4019
|
+
var import_path19 = __toESM(require("path"));
|
|
4020
|
+
var import_ts_morph18 = require("ts-morph");
|
|
4021
|
+
var ROLES_HANDLER_RELATIVE_PATH = "src/data-seeding/roles/handler.ts";
|
|
4022
|
+
async function main19() {
|
|
4023
|
+
const rolesHandlerPath = import_path19.default.join(process.cwd(), ROLES_HANDLER_RELATIVE_PATH);
|
|
4024
|
+
const project = new import_ts_morph18.Project({
|
|
4025
|
+
tsConfigFilePath: import_path19.default.resolve(process.cwd(), "tsconfig.json"),
|
|
4026
|
+
skipAddingFilesFromTsConfig: false
|
|
4027
|
+
});
|
|
4028
|
+
const sourceFile = project.getSourceFile(rolesHandlerPath);
|
|
4029
|
+
if (!sourceFile) {
|
|
4030
|
+
console.log(
|
|
4031
|
+
`No roles handler found at '${ROLES_HANDLER_RELATIVE_PATH}'. Nothing to do.`
|
|
4032
|
+
);
|
|
4033
|
+
return;
|
|
3107
4034
|
}
|
|
3108
4035
|
let changed = false;
|
|
3109
4036
|
const constantsImport = sourceFile.getImportDeclaration(
|
|
@@ -3144,7 +4071,7 @@ async function main14() {
|
|
|
3144
4071
|
|
|
3145
4072
|
// src/migrations/v2.0/remove-hearth-migrations.ts
|
|
3146
4073
|
var fs2 = __toESM(require("fs"));
|
|
3147
|
-
var
|
|
4074
|
+
var import_path20 = __toESM(require("path"));
|
|
3148
4075
|
var PATHS_TO_REMOVE = [
|
|
3149
4076
|
{
|
|
3150
4077
|
relativePath: "src/migrations/hearth",
|
|
@@ -3156,9 +4083,9 @@ var PATHS_TO_REMOVE = [
|
|
|
3156
4083
|
},
|
|
3157
4084
|
{ relativePath: "src/utils/hearth-helpers.ts", label: "Hearth helpers file" }
|
|
3158
4085
|
];
|
|
3159
|
-
async function
|
|
4086
|
+
async function main20() {
|
|
3160
4087
|
for (const { relativePath, label } of PATHS_TO_REMOVE) {
|
|
3161
|
-
const absolutePath =
|
|
4088
|
+
const absolutePath = import_path20.default.join(process.cwd(), relativePath);
|
|
3162
4089
|
if (fs2.existsSync(absolutePath)) {
|
|
3163
4090
|
fs2.rmSync(absolutePath, { recursive: true, force: true });
|
|
3164
4091
|
console.log(`Removed ${label} '${relativePath}'.`);
|
|
@@ -3169,9 +4096,9 @@ async function main15() {
|
|
|
3169
4096
|
}
|
|
3170
4097
|
|
|
3171
4098
|
// src/migrations/v2.0/create-events-index.ts
|
|
3172
|
-
var
|
|
3173
|
-
var
|
|
3174
|
-
var
|
|
4099
|
+
var import_ts_morph19 = require("ts-morph");
|
|
4100
|
+
var import_fs2 = __toESM(require("fs"));
|
|
4101
|
+
var import_path21 = __toESM(require("path"));
|
|
3175
4102
|
var DEFINE_CONFIG_NAME5 = "defineConfig";
|
|
3176
4103
|
var HANDLER_FUNCTION_NAMES = /* @__PURE__ */ new Set([
|
|
3177
4104
|
"getCustomEventsHandler",
|
|
@@ -3193,7 +4120,7 @@ var LICENSE_HEADER = `/*
|
|
|
3193
4120
|
`;
|
|
3194
4121
|
function findEventConfigExports(project, srcDir) {
|
|
3195
4122
|
const found = [];
|
|
3196
|
-
const eventsIndexAbs =
|
|
4123
|
+
const eventsIndexAbs = import_path21.default.join(srcDir, "events", "index.ts");
|
|
3197
4124
|
for (const sourceFile of project.getSourceFiles()) {
|
|
3198
4125
|
const filePath = sourceFile.getFilePath();
|
|
3199
4126
|
if (!filePath.startsWith(srcDir) || filePath.includes("/node_modules/")) {
|
|
@@ -3205,10 +4132,10 @@ function findEventConfigExports(project, srcDir) {
|
|
|
3205
4132
|
for (const decl of statement.getDeclarations()) {
|
|
3206
4133
|
const initializer = decl.getInitializer();
|
|
3207
4134
|
if (!initializer) continue;
|
|
3208
|
-
const unwrapped =
|
|
3209
|
-
if (!
|
|
4135
|
+
const unwrapped = import_ts_morph19.Node.isAsExpression(initializer) ? initializer.getExpression() : initializer;
|
|
4136
|
+
if (!import_ts_morph19.Node.isCallExpression(unwrapped)) continue;
|
|
3210
4137
|
const callee = unwrapped.getExpression();
|
|
3211
|
-
if (!
|
|
4138
|
+
if (!import_ts_morph19.Node.isIdentifier(callee)) continue;
|
|
3212
4139
|
if (callee.getText() !== DEFINE_CONFIG_NAME5) continue;
|
|
3213
4140
|
found.push({ name: decl.getName(), filePath });
|
|
3214
4141
|
}
|
|
@@ -3217,8 +4144,8 @@ function findEventConfigExports(project, srcDir) {
|
|
|
3217
4144
|
return found;
|
|
3218
4145
|
}
|
|
3219
4146
|
function buildIndexImportSpecifier(eventConfigFilePath, srcDir) {
|
|
3220
|
-
const eventsIndexDir =
|
|
3221
|
-
let rel =
|
|
4147
|
+
const eventsIndexDir = import_path21.default.join(srcDir, "events");
|
|
4148
|
+
let rel = import_path21.default.relative(eventsIndexDir, eventConfigFilePath).split(import_path21.default.sep).join("/");
|
|
3222
4149
|
if (rel.endsWith(".ts")) rel = rel.slice(0, -".ts".length);
|
|
3223
4150
|
if (rel.endsWith("/index")) rel = rel.slice(0, -"/index".length);
|
|
3224
4151
|
if (!rel.startsWith(".")) rel = "./" + rel;
|
|
@@ -3295,17 +4222,17 @@ function modifyHandler(sourceFile, exportNames) {
|
|
|
3295
4222
|
);
|
|
3296
4223
|
}
|
|
3297
4224
|
for (const call of sourceFile.getDescendantsOfKind(
|
|
3298
|
-
|
|
4225
|
+
import_ts_morph19.SyntaxKind.CallExpression
|
|
3299
4226
|
)) {
|
|
3300
4227
|
const callee = call.getExpression();
|
|
3301
|
-
if (!
|
|
4228
|
+
if (!import_ts_morph19.Node.isPropertyAccessExpression(callee)) continue;
|
|
3302
4229
|
if (callee.getName() !== RESPONSE_METHOD_NAME) continue;
|
|
3303
4230
|
const args = call.getArguments();
|
|
3304
4231
|
if (args.length !== 1) continue;
|
|
3305
4232
|
const [arg] = args;
|
|
3306
|
-
if (!
|
|
4233
|
+
if (!import_ts_morph19.Node.isArrayLiteralExpression(arg)) continue;
|
|
3307
4234
|
if (arg.getElements().length === 0) continue;
|
|
3308
|
-
if (!arg.getElements().every((el) =>
|
|
4235
|
+
if (!arg.getElements().every((el) => import_ts_morph19.Node.isIdentifier(el))) continue;
|
|
3309
4236
|
arg.replaceWithText(EVENT_CONFIGS_IDENTIFIER);
|
|
3310
4237
|
changes.push(
|
|
3311
4238
|
`rewrote h.response([...]) \u2192 h.response(${EVENT_CONFIGS_IDENTIFIER})`
|
|
@@ -3313,13 +4240,13 @@ function modifyHandler(sourceFile, exportNames) {
|
|
|
3313
4240
|
}
|
|
3314
4241
|
return changes;
|
|
3315
4242
|
}
|
|
3316
|
-
async function
|
|
3317
|
-
const
|
|
3318
|
-
const srcDir =
|
|
4243
|
+
async function main21() {
|
|
4244
|
+
const cwd = process.cwd();
|
|
4245
|
+
const srcDir = import_path21.default.join(cwd, "src");
|
|
3319
4246
|
console.log(`Scanning for defineConfig event exports in: ${srcDir}
|
|
3320
4247
|
`);
|
|
3321
|
-
const project = new
|
|
3322
|
-
tsConfigFilePath:
|
|
4248
|
+
const project = new import_ts_morph19.Project({
|
|
4249
|
+
tsConfigFilePath: import_path21.default.resolve(srcDir, "../tsconfig.json"),
|
|
3323
4250
|
skipAddingFilesFromTsConfig: false
|
|
3324
4251
|
});
|
|
3325
4252
|
const eventConfigExports = findEventConfigExports(project, srcDir);
|
|
@@ -3331,15 +4258,15 @@ async function main16() {
|
|
|
3331
4258
|
}
|
|
3332
4259
|
console.log(`Found ${eventConfigExports.length} event config export(s):`);
|
|
3333
4260
|
for (const e of eventConfigExports) {
|
|
3334
|
-
console.log(` ${e.name} \u2190 ${
|
|
4261
|
+
console.log(` ${e.name} \u2190 ${import_path21.default.relative(cwd, e.filePath)}`);
|
|
3335
4262
|
}
|
|
3336
|
-
const eventsIndexAbs =
|
|
3337
|
-
const eventsIndexRel =
|
|
3338
|
-
if (
|
|
4263
|
+
const eventsIndexAbs = import_path21.default.join(srcDir, "events", "index.ts");
|
|
4264
|
+
const eventsIndexRel = import_path21.default.relative(cwd, eventsIndexAbs);
|
|
4265
|
+
if (import_fs2.default.existsSync(eventsIndexAbs)) {
|
|
3339
4266
|
console.log(`
|
|
3340
4267
|
[${eventsIndexRel}] already exists \u2014 leaving untouched.`);
|
|
3341
4268
|
} else {
|
|
3342
|
-
|
|
4269
|
+
import_fs2.default.mkdirSync(import_path21.default.dirname(eventsIndexAbs), { recursive: true });
|
|
3343
4270
|
const source = buildEventsIndexSource(eventConfigExports, srcDir);
|
|
3344
4271
|
const eventsIndexFile = project.createSourceFile(eventsIndexAbs, source, {
|
|
3345
4272
|
overwrite: false
|
|
@@ -3360,7 +4287,7 @@ No event-config handler file found (looked for exported function(s): ${Array.fro
|
|
|
3360
4287
|
);
|
|
3361
4288
|
return;
|
|
3362
4289
|
}
|
|
3363
|
-
const handlerRelPath =
|
|
4290
|
+
const handlerRelPath = import_path21.default.relative(cwd, handler.getFilePath());
|
|
3364
4291
|
const exportNameSet = new Set(eventConfigExports.map((e) => e.name));
|
|
3365
4292
|
const changes = modifyHandler(handler, exportNameSet);
|
|
3366
4293
|
if (changes.length === 0) {
|
|
@@ -3377,15 +4304,16 @@ Saved ${handlerRelPath}.`);
|
|
|
3377
4304
|
// src/migrations/v2.0/checkout-upstream-files.ts
|
|
3378
4305
|
var import_child_process = require("child_process");
|
|
3379
4306
|
var UPSTREAM_URL = "https://github.com/opencrvs/opencrvs-countryconfig.git";
|
|
3380
|
-
var UPSTREAM_BRANCH = "
|
|
4307
|
+
var UPSTREAM_BRANCH = "release-v2.0.0";
|
|
3381
4308
|
var TEMP_REMOTE = "opencrvs-upgrade-v19-v20-codemod";
|
|
3382
4309
|
var FILES_TO_CHECKOUT = [
|
|
3383
|
-
"
|
|
3384
|
-
"
|
|
4310
|
+
"src/analytics/analytics.ts",
|
|
4311
|
+
"Dockerfile",
|
|
4312
|
+
"Dockerfile.assets"
|
|
3385
4313
|
];
|
|
3386
4314
|
function runGit(args, { silent = false } = {}) {
|
|
3387
4315
|
return (0, import_child_process.execFileSync)("git", args, {
|
|
3388
|
-
cwd:
|
|
4316
|
+
cwd: process.cwd(),
|
|
3389
4317
|
encoding: "utf8",
|
|
3390
4318
|
stdio: silent ? ["ignore", "pipe", "pipe"] : ["ignore", "pipe", "inherit"]
|
|
3391
4319
|
});
|
|
@@ -3401,11 +4329,11 @@ function tryGit(args) {
|
|
|
3401
4329
|
function assertIsGitRepo() {
|
|
3402
4330
|
if (!tryGit(["rev-parse", "--is-inside-work-tree"])) {
|
|
3403
4331
|
throw new Error(
|
|
3404
|
-
|
|
4332
|
+
`${process.cwd()} is not a git repository. Initialise git (or run the upgrade inside a git checkout) before re-running.`
|
|
3405
4333
|
);
|
|
3406
4334
|
}
|
|
3407
4335
|
}
|
|
3408
|
-
async function
|
|
4336
|
+
async function main22() {
|
|
3409
4337
|
console.log(
|
|
3410
4338
|
`Checking out ${FILES_TO_CHECKOUT.length} file(s) from ${UPSTREAM_URL}@${UPSTREAM_BRANCH}...
|
|
3411
4339
|
`
|
|
@@ -3453,10 +4381,356 @@ async function main17() {
|
|
|
3453
4381
|
}
|
|
3454
4382
|
}
|
|
3455
4383
|
|
|
4384
|
+
// src/migrations/v2.0/add-resend-invite-notification.ts
|
|
4385
|
+
var import_fs3 = require("fs");
|
|
4386
|
+
var import_path22 = __toESM(require("path"));
|
|
4387
|
+
var import_ts_morph20 = require("ts-morph");
|
|
4388
|
+
var TS_MORPH_PROJECT_OPTIONS = {
|
|
4389
|
+
skipAddingFilesFromTsConfig: true,
|
|
4390
|
+
manipulationSettings: {
|
|
4391
|
+
indentationText: import_ts_morph20.IndentationText.TwoSpaces
|
|
4392
|
+
}
|
|
4393
|
+
};
|
|
4394
|
+
var EMAIL_TEMPLATES_INDEX = "src/api/notification/email-templates/index.ts";
|
|
4395
|
+
var NOTIFICATION_HANDLER = "src/api/notification/handler.ts";
|
|
4396
|
+
var USER_NOTIFICATION_ROUTES = "src/config/routes/userNotificationRoutes.ts";
|
|
4397
|
+
var SMS_SERVICE = "src/api/notification/sms-service.ts";
|
|
4398
|
+
var NOTIFICATION_CSV = "src/translations/notification.csv";
|
|
4399
|
+
var RESEND_INVITE_HTML = "src/api/notification/email-templates/other/resend-invite.html";
|
|
4400
|
+
var RESEND_INVITE_HTML_CONTENT = `<!doctype html>
|
|
4401
|
+
<html>
|
|
4402
|
+
<head>
|
|
4403
|
+
<link
|
|
4404
|
+
href="https://fonts.googleapis.com/css2?family=Noto+Sans:wght@400;700&display=swap"
|
|
4405
|
+
rel="stylesheet"
|
|
4406
|
+
/>
|
|
4407
|
+
<style type="text/css">
|
|
4408
|
+
body {
|
|
4409
|
+
font-family: 'Noto Sans', sans-serif;
|
|
4410
|
+
color: #222;
|
|
4411
|
+
padding: 16px 24px;
|
|
4412
|
+
}
|
|
4413
|
+
|
|
4414
|
+
h1 {
|
|
4415
|
+
font-size: 21px;
|
|
4416
|
+
margin-top: 32px;
|
|
4417
|
+
margin-bottom: 36px;
|
|
4418
|
+
font-weight: 700;
|
|
4419
|
+
}
|
|
4420
|
+
|
|
4421
|
+
p {
|
|
4422
|
+
font-weight: 400;
|
|
4423
|
+
font-size: 16px;
|
|
4424
|
+
line-height: 1.8;
|
|
4425
|
+
margin-bottom: 24px;
|
|
4426
|
+
}
|
|
4427
|
+
|
|
4428
|
+
i {
|
|
4429
|
+
color: #666;
|
|
4430
|
+
font-weight: 400;
|
|
4431
|
+
font-size: 16px;
|
|
4432
|
+
}
|
|
4433
|
+
</style>
|
|
4434
|
+
</head>
|
|
4435
|
+
|
|
4436
|
+
<body>
|
|
4437
|
+
<img
|
|
4438
|
+
src="{{countryLogo}}"
|
|
4439
|
+
alt="country_logo"
|
|
4440
|
+
style="max-height: 88px; max-width: 100%"
|
|
4441
|
+
/>
|
|
4442
|
+
<h1>Your {{applicationName}} account invitation</h1>
|
|
4443
|
+
<p>Hello {{firstname}},</p>
|
|
4444
|
+
<p>Your account invitation has been resent. Please use the following credentials to access your account:</p>
|
|
4445
|
+
<p>
|
|
4446
|
+
Username: <strong>{{username}}</strong><br />
|
|
4447
|
+
Password: <strong>{{temporaryPassword}}</strong>
|
|
4448
|
+
</p>
|
|
4449
|
+
<p>
|
|
4450
|
+
Please click the link below to complete your account setup and start using
|
|
4451
|
+
{{applicationName}}.
|
|
4452
|
+
</p>
|
|
4453
|
+
|
|
4454
|
+
<div style="margin-top: 32px; margin-bottom: 32px">
|
|
4455
|
+
<a href="{{loginURL}}">Complete setup</a>
|
|
4456
|
+
</div>
|
|
4457
|
+
<br />
|
|
4458
|
+
<p>
|
|
4459
|
+
Best regards, <br />
|
|
4460
|
+
{{applicationName}} Team
|
|
4461
|
+
</p>
|
|
4462
|
+
</body>
|
|
4463
|
+
</html>
|
|
4464
|
+
`;
|
|
4465
|
+
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";
|
|
4466
|
+
function getObjectLiteralFromConst(declaration) {
|
|
4467
|
+
if (!declaration) {
|
|
4468
|
+
return;
|
|
4469
|
+
}
|
|
4470
|
+
const initializer = declaration.getInitializer();
|
|
4471
|
+
if (!initializer) {
|
|
4472
|
+
return;
|
|
4473
|
+
}
|
|
4474
|
+
if (import_ts_morph20.Node.isObjectLiteralExpression(initializer)) {
|
|
4475
|
+
return initializer;
|
|
4476
|
+
}
|
|
4477
|
+
if (import_ts_morph20.Node.isAsExpression(initializer)) {
|
|
4478
|
+
const expression = initializer.getExpression();
|
|
4479
|
+
if (import_ts_morph20.Node.isObjectLiteralExpression(expression)) {
|
|
4480
|
+
return expression;
|
|
4481
|
+
}
|
|
4482
|
+
}
|
|
4483
|
+
if (import_ts_morph20.Node.isSatisfiesExpression(initializer)) {
|
|
4484
|
+
const expression = initializer.getExpression();
|
|
4485
|
+
if (import_ts_morph20.Node.isObjectLiteralExpression(expression)) {
|
|
4486
|
+
return expression;
|
|
4487
|
+
}
|
|
4488
|
+
}
|
|
4489
|
+
}
|
|
4490
|
+
function patchEmailTemplatesIndex() {
|
|
4491
|
+
const full = import_path22.default.join(process.cwd(), EMAIL_TEMPLATES_INDEX);
|
|
4492
|
+
if (!(0, import_fs3.existsSync)(full)) {
|
|
4493
|
+
console.log(` '${EMAIL_TEMPLATES_INDEX}' missing \u2014 skipping.`);
|
|
4494
|
+
return false;
|
|
4495
|
+
}
|
|
4496
|
+
const project = new import_ts_morph20.Project(TS_MORPH_PROJECT_OPTIONS);
|
|
4497
|
+
const sourceFile = project.addSourceFileAtPath(full);
|
|
4498
|
+
let changed = false;
|
|
4499
|
+
const triggerVariableObject = getObjectLiteralFromConst(
|
|
4500
|
+
sourceFile.getVariableDeclaration("TriggerVariable")
|
|
4501
|
+
);
|
|
4502
|
+
if (triggerVariableObject) {
|
|
4503
|
+
const hasResendInviteVariable = triggerVariableObject.getProperties().some((prop) => prop.getText().includes("[TriggerEvent.RESEND_INVITE]"));
|
|
4504
|
+
if (!hasResendInviteVariable) {
|
|
4505
|
+
const properties = triggerVariableObject.getProperties();
|
|
4506
|
+
const lastProperty = properties[properties.length - 1];
|
|
4507
|
+
if (lastProperty) {
|
|
4508
|
+
sourceFile.insertText(
|
|
4509
|
+
lastProperty.getEnd(),
|
|
4510
|
+
`,
|
|
4511
|
+
[TriggerEvent.RESEND_INVITE]: z.object({
|
|
4512
|
+
firstname: z.string(),
|
|
4513
|
+
username: z.string(),
|
|
4514
|
+
temporaryPassword: z.string(),
|
|
4515
|
+
completeSetupUrl: z.string(),
|
|
4516
|
+
loginURL: z.string()
|
|
4517
|
+
})`
|
|
4518
|
+
);
|
|
4519
|
+
changed = true;
|
|
4520
|
+
}
|
|
4521
|
+
}
|
|
4522
|
+
}
|
|
4523
|
+
const templatesObject = getObjectLiteralFromConst(
|
|
4524
|
+
sourceFile.getVariableDeclaration("templates")
|
|
4525
|
+
);
|
|
4526
|
+
if (templatesObject) {
|
|
4527
|
+
const hasResendInviteTemplate = templatesObject.getProperties().some(
|
|
4528
|
+
(prop) => prop.getText().includes("readOtherTemplate<TriggerVariable['resend-invite']>")
|
|
4529
|
+
);
|
|
4530
|
+
if (!hasResendInviteTemplate) {
|
|
4531
|
+
const userCreatedProp = templatesObject.getProperties().find((prop) => prop.getText().includes("[TriggerEvent.USER_CREATED]"));
|
|
4532
|
+
const anchor = userCreatedProp ?? templatesObject.getProperties()[templatesObject.getProperties().length - 1];
|
|
4533
|
+
if (anchor) {
|
|
4534
|
+
sourceFile.insertText(
|
|
4535
|
+
anchor.getEnd(),
|
|
4536
|
+
`,
|
|
4537
|
+
[TriggerEvent.RESEND_INVITE]: {
|
|
4538
|
+
type: 'resend-invite',
|
|
4539
|
+
subject: 'Your OpenCRVS account invitation',
|
|
4540
|
+
template:
|
|
4541
|
+
readOtherTemplate<TriggerVariable['resend-invite']>('resend-invite')
|
|
4542
|
+
}`
|
|
4543
|
+
);
|
|
4544
|
+
changed = true;
|
|
4545
|
+
}
|
|
4546
|
+
}
|
|
4547
|
+
}
|
|
4548
|
+
if (changed) {
|
|
4549
|
+
sourceFile.saveSync();
|
|
4550
|
+
}
|
|
4551
|
+
return changed;
|
|
4552
|
+
}
|
|
4553
|
+
function patchNotificationHandler() {
|
|
4554
|
+
const full = import_path22.default.join(process.cwd(), NOTIFICATION_HANDLER);
|
|
4555
|
+
if (!(0, import_fs3.existsSync)(full)) {
|
|
4556
|
+
return false;
|
|
4557
|
+
}
|
|
4558
|
+
const project = new import_ts_morph20.Project(TS_MORPH_PROJECT_OPTIONS);
|
|
4559
|
+
const sourceFile = project.addSourceFileAtPath(full);
|
|
4560
|
+
const convertFn = sourceFile.getFunction("convertPayloadToVariable");
|
|
4561
|
+
if (!convertFn) {
|
|
4562
|
+
return false;
|
|
4563
|
+
}
|
|
4564
|
+
const switchStmt = convertFn.getFirstDescendantByKind(
|
|
4565
|
+
import_ts_morph20.SyntaxKind.SwitchStatement
|
|
4566
|
+
);
|
|
4567
|
+
if (!switchStmt) {
|
|
4568
|
+
return false;
|
|
4569
|
+
}
|
|
4570
|
+
const clauses = switchStmt.getCaseBlock().getClauses();
|
|
4571
|
+
const hasResendInvite = clauses.some(
|
|
4572
|
+
(clause) => import_ts_morph20.Node.isCaseClause(clause) && clause.getExpression().getText() === "TriggerEvent.RESEND_INVITE"
|
|
4573
|
+
);
|
|
4574
|
+
if (hasResendInvite) {
|
|
4575
|
+
return false;
|
|
4576
|
+
}
|
|
4577
|
+
const userCreatedClauseIndex = clauses.findIndex(
|
|
4578
|
+
(clause) => import_ts_morph20.Node.isCaseClause(clause) && clause.getExpression().getText() === "TriggerEvent.USER_CREATED"
|
|
4579
|
+
);
|
|
4580
|
+
if (userCreatedClauseIndex < 0) {
|
|
4581
|
+
return false;
|
|
4582
|
+
}
|
|
4583
|
+
const userCreatedClause = clauses[userCreatedClauseIndex];
|
|
4584
|
+
sourceFile.insertText(
|
|
4585
|
+
userCreatedClause.getEnd(),
|
|
4586
|
+
`
|
|
4587
|
+
|
|
4588
|
+
case TriggerEvent.RESEND_INVITE:
|
|
4589
|
+
return {
|
|
4590
|
+
firstname,
|
|
4591
|
+
username: payload.username,
|
|
4592
|
+
temporaryPassword: payload.temporaryPassword,
|
|
4593
|
+
completeSetupUrl: LOGIN_URL,
|
|
4594
|
+
loginURL: LOGIN_URL
|
|
4595
|
+
}`
|
|
4596
|
+
);
|
|
4597
|
+
sourceFile.saveSync();
|
|
4598
|
+
return true;
|
|
4599
|
+
}
|
|
4600
|
+
function getReturnedArrayLiteral(functionFilePath, fnName) {
|
|
4601
|
+
const project = new import_ts_morph20.Project(TS_MORPH_PROJECT_OPTIONS);
|
|
4602
|
+
const sourceFile = project.addSourceFileAtPath(functionFilePath);
|
|
4603
|
+
const fn = sourceFile.getFunction(fnName);
|
|
4604
|
+
const returnStmt = fn?.getFirstDescendantByKind(import_ts_morph20.SyntaxKind.ReturnStatement);
|
|
4605
|
+
const expr = returnStmt?.getExpression();
|
|
4606
|
+
if (!expr || !import_ts_morph20.Node.isArrayLiteralExpression(expr)) {
|
|
4607
|
+
return { sourceFile, arrayLiteral: void 0 };
|
|
4608
|
+
}
|
|
4609
|
+
return { sourceFile, arrayLiteral: expr };
|
|
4610
|
+
}
|
|
4611
|
+
function patchUserNotificationRoutes() {
|
|
4612
|
+
const full = import_path22.default.join(process.cwd(), USER_NOTIFICATION_ROUTES);
|
|
4613
|
+
if (!(0, import_fs3.existsSync)(full)) {
|
|
4614
|
+
return false;
|
|
4615
|
+
}
|
|
4616
|
+
const { sourceFile, arrayLiteral } = getReturnedArrayLiteral(
|
|
4617
|
+
full,
|
|
4618
|
+
"getUserNotificationRoutes"
|
|
4619
|
+
);
|
|
4620
|
+
if (!arrayLiteral) {
|
|
4621
|
+
return false;
|
|
4622
|
+
}
|
|
4623
|
+
const elements = arrayLiteral.getElements();
|
|
4624
|
+
const routeExists = elements.some(
|
|
4625
|
+
(element) => element.getText().includes(`path: '/triggers/user/resend-invite'`)
|
|
4626
|
+
);
|
|
4627
|
+
if (routeExists) {
|
|
4628
|
+
return false;
|
|
4629
|
+
}
|
|
4630
|
+
const anchor = elements.find(
|
|
4631
|
+
(element) => element.getText().includes(`path: '/triggers/user/user-created'`)
|
|
4632
|
+
) ?? elements[elements.length - 1];
|
|
4633
|
+
if (!anchor) {
|
|
4634
|
+
return false;
|
|
4635
|
+
}
|
|
4636
|
+
sourceFile.insertText(
|
|
4637
|
+
anchor.getEnd(),
|
|
4638
|
+
`,
|
|
4639
|
+
{
|
|
4640
|
+
method: 'POST',
|
|
4641
|
+
path: '/triggers/user/resend-invite',
|
|
4642
|
+
handler: makeNotificationHandler('resend-invite'),
|
|
4643
|
+
options: {
|
|
4644
|
+
auth: false,
|
|
4645
|
+
tags: ['api'],
|
|
4646
|
+
description: 'Handles notification for resent user invite'
|
|
4647
|
+
}
|
|
4648
|
+
}`
|
|
4649
|
+
);
|
|
4650
|
+
sourceFile.saveSync();
|
|
4651
|
+
return true;
|
|
4652
|
+
}
|
|
4653
|
+
function patchSmsService() {
|
|
4654
|
+
const full = import_path22.default.join(process.cwd(), SMS_SERVICE);
|
|
4655
|
+
if (!(0, import_fs3.existsSync)(full)) {
|
|
4656
|
+
return false;
|
|
4657
|
+
}
|
|
4658
|
+
const project = new import_ts_morph20.Project(TS_MORPH_PROJECT_OPTIONS);
|
|
4659
|
+
const sourceFile = project.addSourceFileAtPath(full);
|
|
4660
|
+
let changed = false;
|
|
4661
|
+
const otherTemplatesObject = getObjectLiteralFromConst(
|
|
4662
|
+
sourceFile.getVariableDeclaration("otherTemplates")
|
|
4663
|
+
);
|
|
4664
|
+
if (otherTemplatesObject) {
|
|
4665
|
+
const hasResendTemplate = otherTemplatesObject.getProperties().some((prop) => prop.getText().includes("resendInviteNotification"));
|
|
4666
|
+
if (!hasResendTemplate) {
|
|
4667
|
+
const userCredentialsIndex = otherTemplatesObject.getProperties().findIndex((prop) => prop.getText().includes("userCredentialsNotification"));
|
|
4668
|
+
otherTemplatesObject.insertPropertyAssignment(
|
|
4669
|
+
userCredentialsIndex >= 0 ? userCredentialsIndex + 1 : otherTemplatesObject.getProperties().length,
|
|
4670
|
+
{
|
|
4671
|
+
name: "resendInviteNotification",
|
|
4672
|
+
initializer: `'resendInviteNotification'`
|
|
4673
|
+
}
|
|
4674
|
+
);
|
|
4675
|
+
changed = true;
|
|
4676
|
+
}
|
|
4677
|
+
}
|
|
4678
|
+
const triggerToSmsTemplateObject = getObjectLiteralFromConst(
|
|
4679
|
+
sourceFile.getVariableDeclaration("TriggerToSMSTemplate")
|
|
4680
|
+
);
|
|
4681
|
+
if (triggerToSmsTemplateObject) {
|
|
4682
|
+
const hasResendInviteMap = triggerToSmsTemplateObject.getProperties().some((prop) => prop.getText().includes(`['resend-invite']`));
|
|
4683
|
+
if (!hasResendInviteMap) {
|
|
4684
|
+
const userCreatedIndex = triggerToSmsTemplateObject.getProperties().findIndex((prop) => prop.getText().includes(`['user-created']`));
|
|
4685
|
+
triggerToSmsTemplateObject.insertPropertyAssignment(
|
|
4686
|
+
userCreatedIndex >= 0 ? userCreatedIndex + 1 : triggerToSmsTemplateObject.getProperties().length,
|
|
4687
|
+
{
|
|
4688
|
+
name: `['resend-invite']`,
|
|
4689
|
+
initializer: `'resendInviteNotification'`
|
|
4690
|
+
}
|
|
4691
|
+
);
|
|
4692
|
+
changed = true;
|
|
4693
|
+
}
|
|
4694
|
+
}
|
|
4695
|
+
if (changed) {
|
|
4696
|
+
sourceFile.saveSync();
|
|
4697
|
+
}
|
|
4698
|
+
return changed;
|
|
4699
|
+
}
|
|
4700
|
+
async function main23() {
|
|
4701
|
+
console.log("Adding RESEND_INVITE notification wiring\u2026");
|
|
4702
|
+
const touched = [];
|
|
4703
|
+
if (patchEmailTemplatesIndex()) touched.push(EMAIL_TEMPLATES_INDEX);
|
|
4704
|
+
if (patchNotificationHandler()) touched.push(NOTIFICATION_HANDLER);
|
|
4705
|
+
if (patchUserNotificationRoutes()) touched.push(USER_NOTIFICATION_ROUTES);
|
|
4706
|
+
if (patchSmsService()) touched.push(SMS_SERVICE);
|
|
4707
|
+
const csvPath = import_path22.default.join(process.cwd(), NOTIFICATION_CSV);
|
|
4708
|
+
if ((0, import_fs3.existsSync)(csvPath)) {
|
|
4709
|
+
let t = (0, import_fs3.readFileSync)(csvPath, "utf8");
|
|
4710
|
+
if (!/^resendInviteNotification,/m.test(t)) {
|
|
4711
|
+
if (!t.endsWith("\n")) t += "\n";
|
|
4712
|
+
(0, import_fs3.writeFileSync)(csvPath, t + CSV_ROW);
|
|
4713
|
+
touched.push(NOTIFICATION_CSV);
|
|
4714
|
+
}
|
|
4715
|
+
}
|
|
4716
|
+
const htmlPath = import_path22.default.join(process.cwd(), RESEND_INVITE_HTML);
|
|
4717
|
+
(0, import_fs3.mkdirSync)(import_path22.default.dirname(htmlPath), { recursive: true });
|
|
4718
|
+
if (!(0, import_fs3.existsSync)(htmlPath)) {
|
|
4719
|
+
(0, import_fs3.writeFileSync)(htmlPath, RESEND_INVITE_HTML_CONTENT);
|
|
4720
|
+
touched.push(RESEND_INVITE_HTML);
|
|
4721
|
+
}
|
|
4722
|
+
if (touched.length === 0) {
|
|
4723
|
+
console.log(" Nothing to update (already present or anchors not found).");
|
|
4724
|
+
return;
|
|
4725
|
+
}
|
|
4726
|
+
console.log(` Updated:
|
|
4727
|
+
${touched.map((f) => ` - ${f}`).join("\n")}`);
|
|
4728
|
+
}
|
|
4729
|
+
|
|
3456
4730
|
// src/migrations/v2.0/simplify-analytics-precalculations.ts
|
|
3457
|
-
var
|
|
3458
|
-
var
|
|
3459
|
-
var
|
|
4731
|
+
var import_ts_morph21 = require("ts-morph");
|
|
4732
|
+
var import_fs4 = __toESM(require("fs"));
|
|
4733
|
+
var import_path23 = __toESM(require("path"));
|
|
3460
4734
|
var ANALYTICS_FILE_REL = "src/analytics/analytics.ts";
|
|
3461
4735
|
var FUNCTION_NAME = "precalculateAdditionalAnalytics";
|
|
3462
4736
|
var IMPORT_NAMES_TO_REMOVE = /* @__PURE__ */ new Set(["Event", "precalculateBirthEvent"]);
|
|
@@ -3492,10 +4766,10 @@ function findPrecalculateFunction(sourceFile) {
|
|
|
3492
4766
|
return void 0;
|
|
3493
4767
|
}
|
|
3494
4768
|
function getFunctionBodyBlock(fn) {
|
|
3495
|
-
if (
|
|
4769
|
+
if (import_ts_morph21.Node.isFunctionDeclaration(fn)) return fn.getBody();
|
|
3496
4770
|
const initializer = fn.getInitializer();
|
|
3497
4771
|
if (!initializer) return void 0;
|
|
3498
|
-
if (!
|
|
4772
|
+
if (!import_ts_morph21.Node.isArrowFunction(initializer) && !import_ts_morph21.Node.isFunctionExpression(initializer)) {
|
|
3499
4773
|
return void 0;
|
|
3500
4774
|
}
|
|
3501
4775
|
return initializer.getBody();
|
|
@@ -3505,9 +4779,9 @@ function simplifyPrecalculateFunction(sourceFile) {
|
|
|
3505
4779
|
const fn = findPrecalculateFunction(sourceFile);
|
|
3506
4780
|
if (!fn) return log;
|
|
3507
4781
|
const body = getFunctionBodyBlock(fn);
|
|
3508
|
-
if (!body || !
|
|
4782
|
+
if (!body || !import_ts_morph21.Node.isBlock(body)) return log;
|
|
3509
4783
|
for (const statement of [...body.getStatements()]) {
|
|
3510
|
-
const references = statement.getDescendantsOfKind(
|
|
4784
|
+
const references = statement.getDescendantsOfKind(import_ts_morph21.SyntaxKind.Identifier).some((id) => IMPORT_NAMES_TO_REMOVE.has(id.getText()));
|
|
3511
4785
|
if (references) {
|
|
3512
4786
|
statement.remove();
|
|
3513
4787
|
log.push(`removed statement in ${FUNCTION_NAME} referencing removed imports`);
|
|
@@ -3515,7 +4789,7 @@ function simplifyPrecalculateFunction(sourceFile) {
|
|
|
3515
4789
|
}
|
|
3516
4790
|
const remaining = body.getStatements();
|
|
3517
4791
|
const last = remaining[remaining.length - 1];
|
|
3518
|
-
const alreadyCorrect = last &&
|
|
4792
|
+
const alreadyCorrect = last && import_ts_morph21.Node.isReturnStatement(last) && last.getExpression()?.getText() === RETURN_EXPRESSION_TEXT;
|
|
3519
4793
|
if (!alreadyCorrect) {
|
|
3520
4794
|
body.addStatements(`return ${RETURN_EXPRESSION_TEXT}`);
|
|
3521
4795
|
log.push(
|
|
@@ -3524,17 +4798,17 @@ function simplifyPrecalculateFunction(sourceFile) {
|
|
|
3524
4798
|
}
|
|
3525
4799
|
return log;
|
|
3526
4800
|
}
|
|
3527
|
-
async function
|
|
3528
|
-
const
|
|
3529
|
-
const absPath =
|
|
3530
|
-
if (!
|
|
4801
|
+
async function main24() {
|
|
4802
|
+
const cwd = process.cwd();
|
|
4803
|
+
const absPath = import_path23.default.join(cwd, ANALYTICS_FILE_REL);
|
|
4804
|
+
if (!import_fs4.default.existsSync(absPath)) {
|
|
3531
4805
|
console.log(
|
|
3532
4806
|
`[${ANALYTICS_FILE_REL}] does not exist \u2014 nothing to clean up.`
|
|
3533
4807
|
);
|
|
3534
4808
|
return;
|
|
3535
4809
|
}
|
|
3536
|
-
const project = new
|
|
3537
|
-
tsConfigFilePath:
|
|
4810
|
+
const project = new import_ts_morph21.Project({
|
|
4811
|
+
tsConfigFilePath: import_path23.default.resolve(cwd, "tsconfig.json"),
|
|
3538
4812
|
skipAddingFilesFromTsConfig: false
|
|
3539
4813
|
});
|
|
3540
4814
|
const sourceFile = project.getSourceFile(absPath);
|
|
@@ -3561,26 +4835,196 @@ async function main18() {
|
|
|
3561
4835
|
Saved ${ANALYTICS_FILE_REL}.`);
|
|
3562
4836
|
}
|
|
3563
4837
|
|
|
3564
|
-
// src/migrations/v2.0/
|
|
3565
|
-
var
|
|
3566
|
-
|
|
3567
|
-
|
|
3568
|
-
|
|
4838
|
+
// src/migrations/v2.0/merge-infrastructure-directory.ts
|
|
4839
|
+
var import_child_process2 = require("child_process");
|
|
4840
|
+
var import_fs5 = require("fs");
|
|
4841
|
+
var import_os = require("os");
|
|
4842
|
+
var import_path24 = require("path");
|
|
4843
|
+
var TEMP_REMOTE2 = "opencrvs-upgrade-v19-v20-codemod-merge-infra";
|
|
4844
|
+
var INFRASTRUCTURE_DIR = "infrastructure";
|
|
4845
|
+
var BASE_BRANCH = "release-v1.9";
|
|
4846
|
+
function gitShowBytes(ref, path23) {
|
|
4847
|
+
try {
|
|
4848
|
+
const buf = (0, import_child_process2.execFileSync)("git", ["show", `${ref}:${path23}`], {
|
|
4849
|
+
cwd: process.cwd(),
|
|
4850
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
4851
|
+
});
|
|
4852
|
+
return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
4853
|
+
} catch {
|
|
4854
|
+
return null;
|
|
4855
|
+
}
|
|
4856
|
+
}
|
|
4857
|
+
async function main25({
|
|
4858
|
+
subdirs = []
|
|
4859
|
+
} = {}) {
|
|
4860
|
+
const pathspecs = subdirs.length > 0 ? subdirs.map((s) => `${INFRASTRUCTURE_DIR}/${s}/`) : [`${INFRASTRUCTURE_DIR}/`];
|
|
4861
|
+
const scopeLabel = pathspecs.map((p) => `'${p}'`).join(", ");
|
|
4862
|
+
console.log(
|
|
4863
|
+
`Merging ${scopeLabel} from ${UPSTREAM_URL}@${UPSTREAM_BRANCH} (base: ${BASE_BRANCH})...
|
|
4864
|
+
`
|
|
4865
|
+
);
|
|
4866
|
+
assertIsGitRepo();
|
|
4867
|
+
tryGit(["remote", "remove", TEMP_REMOTE2]);
|
|
4868
|
+
try {
|
|
4869
|
+
console.log(` Adding temporary remote '${TEMP_REMOTE2}' \u2192 ${UPSTREAM_URL}`);
|
|
4870
|
+
runGit(["remote", "add", TEMP_REMOTE2, UPSTREAM_URL], { silent: true });
|
|
4871
|
+
console.log(
|
|
4872
|
+
` Fetching ${TEMP_REMOTE2}/{${UPSTREAM_BRANCH},${BASE_BRANCH}} (depth 1)...`
|
|
4873
|
+
);
|
|
4874
|
+
runGit(["fetch", "--depth=1", TEMP_REMOTE2, UPSTREAM_BRANCH, BASE_BRANCH]);
|
|
4875
|
+
const ref = `${TEMP_REMOTE2}/${UPSTREAM_BRANCH}`;
|
|
4876
|
+
const baseRef = `${TEMP_REMOTE2}/${BASE_BRANCH}`;
|
|
4877
|
+
const upstreamFiles = runGit(
|
|
4878
|
+
["ls-tree", "-r", "--name-only", "-z", ref, "--", ...pathspecs],
|
|
4879
|
+
{ silent: true }
|
|
4880
|
+
).split("\0").filter(Boolean);
|
|
4881
|
+
if (upstreamFiles.length === 0) {
|
|
4882
|
+
console.log(
|
|
4883
|
+
` No files found under ${scopeLabel} on ${ref}. Nothing to merge.`
|
|
4884
|
+
);
|
|
4885
|
+
return;
|
|
4886
|
+
}
|
|
4887
|
+
const tmpDir = (0, import_fs5.mkdtempSync)((0, import_path24.join)((0, import_os.tmpdir)(), "opencrvs-merge-infra-"));
|
|
4888
|
+
const baseTmp = (0, import_path24.join)(tmpDir, "base");
|
|
4889
|
+
const theirsTmp = (0, import_path24.join)(tmpDir, "theirs");
|
|
4890
|
+
let added = 0;
|
|
4891
|
+
let merged = 0;
|
|
4892
|
+
const conflictedFiles = [];
|
|
4893
|
+
for (const file of upstreamFiles) {
|
|
4894
|
+
const fullPath = (0, import_path24.join)(process.cwd(), file);
|
|
4895
|
+
if (!(0, import_fs5.existsSync)(fullPath)) {
|
|
4896
|
+
if (tryGit(["checkout", ref, "--", file])) {
|
|
4897
|
+
console.log(` + ${file} (new from upstream)`);
|
|
4898
|
+
added++;
|
|
4899
|
+
} else {
|
|
4900
|
+
console.warn(` [warn] failed to add new file ${file}`);
|
|
4901
|
+
}
|
|
4902
|
+
continue;
|
|
4903
|
+
}
|
|
4904
|
+
const theirContents = gitShowBytes(ref, file);
|
|
4905
|
+
if (theirContents === null) {
|
|
4906
|
+
console.warn(` [warn] could not read ${file} from ${ref} \u2014 skipping.`);
|
|
4907
|
+
continue;
|
|
4908
|
+
}
|
|
4909
|
+
(0, import_fs5.writeFileSync)(theirsTmp, theirContents);
|
|
4910
|
+
const baseContents = gitShowBytes(baseRef, file);
|
|
4911
|
+
(0, import_fs5.writeFileSync)(baseTmp, baseContents ?? new Uint8Array(0));
|
|
4912
|
+
try {
|
|
4913
|
+
(0, import_child_process2.execFileSync)("git", ["merge-file", fullPath, baseTmp, theirsTmp], {
|
|
4914
|
+
cwd: process.cwd(),
|
|
4915
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
4916
|
+
});
|
|
4917
|
+
runGit(["add", "--", file], { silent: true });
|
|
4918
|
+
merged++;
|
|
4919
|
+
} catch (err) {
|
|
4920
|
+
const status = err.status;
|
|
4921
|
+
if (typeof status === "number" && status > 0) {
|
|
4922
|
+
conflictedFiles.push(file);
|
|
4923
|
+
console.warn(
|
|
4924
|
+
` ! ${file} (${status} conflict${status > 1 ? "s" : ""})`
|
|
4925
|
+
);
|
|
4926
|
+
} else {
|
|
4927
|
+
conflictedFiles.push(file);
|
|
4928
|
+
console.warn(
|
|
4929
|
+
` [warn] merge failed for ${file} (likely binary or unreadable) \u2014 left untouched.`
|
|
4930
|
+
);
|
|
4931
|
+
}
|
|
4932
|
+
}
|
|
4933
|
+
}
|
|
4934
|
+
console.log(
|
|
4935
|
+
`
|
|
4936
|
+
Done. ${added} added, ${merged} merged cleanly, ${conflictedFiles.length} with conflicts.`
|
|
4937
|
+
);
|
|
4938
|
+
if (conflictedFiles.length > 0) {
|
|
4939
|
+
console.warn(
|
|
4940
|
+
`
|
|
4941
|
+
NOTE: ${conflictedFiles.length} file(s) under '${INFRASTRUCTURE_DIR}/' have merge conflicts that you must resolve manually.
|
|
4942
|
+
Look for the standard conflict markers (<<<<<<<, =======, >>>>>>>) in:
|
|
4943
|
+
` + conflictedFiles.map((f) => ` - ${f}`).join("\n") + `
|
|
4944
|
+
After resolving, stage the fixes with: git add ${INFRASTRUCTURE_DIR}/`
|
|
4945
|
+
);
|
|
4946
|
+
}
|
|
4947
|
+
} finally {
|
|
4948
|
+
if (tryGit(["remote", "remove", TEMP_REMOTE2])) {
|
|
4949
|
+
console.log(` Removed temporary remote '${TEMP_REMOTE2}'.`);
|
|
4950
|
+
}
|
|
3569
4951
|
}
|
|
3570
|
-
return cwd;
|
|
3571
4952
|
}
|
|
3572
|
-
|
|
3573
|
-
|
|
3574
|
-
|
|
3575
|
-
|
|
4953
|
+
|
|
4954
|
+
// src/migrations/v2.0/delete-infrastructure-directory.ts
|
|
4955
|
+
var import_fs6 = require("fs");
|
|
4956
|
+
var import_path25 = require("path");
|
|
4957
|
+
var INFRASTRUCTURE_DIR2 = "infrastructure";
|
|
4958
|
+
async function main26({
|
|
4959
|
+
keep = []
|
|
4960
|
+
} = {}) {
|
|
4961
|
+
const fullPath = (0, import_path25.join)(process.cwd(), INFRASTRUCTURE_DIR2);
|
|
4962
|
+
if (!(0, import_fs6.existsSync)(fullPath)) {
|
|
4963
|
+
console.log(
|
|
4964
|
+
`'${INFRASTRUCTURE_DIR2}/' not found in ${process.cwd()} \u2014 nothing to delete.`
|
|
4965
|
+
);
|
|
4966
|
+
return;
|
|
3576
4967
|
}
|
|
3577
|
-
|
|
4968
|
+
assertIsGitRepo();
|
|
4969
|
+
if (keep.length === 0) {
|
|
4970
|
+
console.log(`Deleting '${INFRASTRUCTURE_DIR2}/'...
|
|
4971
|
+
`);
|
|
4972
|
+
runGit(["rm", "-rf", "--ignore-unmatch", "--", `${INFRASTRUCTURE_DIR2}/`], {
|
|
4973
|
+
silent: true
|
|
4974
|
+
});
|
|
4975
|
+
console.log(
|
|
4976
|
+
` Staged deletion of tracked files under '${INFRASTRUCTURE_DIR2}/'.`
|
|
4977
|
+
);
|
|
4978
|
+
if ((0, import_fs6.existsSync)(fullPath)) {
|
|
4979
|
+
(0, import_fs6.rmSync)(fullPath, { recursive: true, force: true });
|
|
4980
|
+
console.log(
|
|
4981
|
+
` Removed remaining untracked files under '${INFRASTRUCTURE_DIR2}/'.`
|
|
4982
|
+
);
|
|
4983
|
+
}
|
|
3578
4984
|
console.log(
|
|
3579
|
-
|
|
4985
|
+
`
|
|
4986
|
+
Done. Review the staged deletion with: git diff --cached -- '${INFRASTRUCTURE_DIR2}/'`
|
|
3580
4987
|
);
|
|
3581
|
-
|
|
4988
|
+
return;
|
|
3582
4989
|
}
|
|
3583
|
-
|
|
4990
|
+
const keepSet = new Set(keep);
|
|
4991
|
+
console.log(
|
|
4992
|
+
`Deleting contents of '${INFRASTRUCTURE_DIR2}/' except: ${[...keepSet].map((name) => `'${name}'`).join(", ")}
|
|
4993
|
+
`
|
|
4994
|
+
);
|
|
4995
|
+
const topLevelEntries = (0, import_fs6.readdirSync)(fullPath, { withFileTypes: true });
|
|
4996
|
+
let deleted = 0;
|
|
4997
|
+
for (const entry of topLevelEntries) {
|
|
4998
|
+
if (keepSet.has(entry.name)) {
|
|
4999
|
+
console.log(` Keeping '${INFRASTRUCTURE_DIR2}/${entry.name}'.`);
|
|
5000
|
+
continue;
|
|
5001
|
+
}
|
|
5002
|
+
const relPath = `${INFRASTRUCTURE_DIR2}/${entry.name}${entry.isDirectory() ? "/" : ""}`;
|
|
5003
|
+
runGit(["rm", "-rf", "--ignore-unmatch", "--", relPath], { silent: true });
|
|
5004
|
+
const fullEntryPath = (0, import_path25.join)(fullPath, entry.name);
|
|
5005
|
+
if ((0, import_fs6.existsSync)(fullEntryPath)) {
|
|
5006
|
+
(0, import_fs6.rmSync)(fullEntryPath, { recursive: true, force: true });
|
|
5007
|
+
}
|
|
5008
|
+
console.log(` Deleted '${relPath}'.`);
|
|
5009
|
+
deleted++;
|
|
5010
|
+
}
|
|
5011
|
+
const presentNames = new Set(topLevelEntries.map((e) => e.name));
|
|
5012
|
+
const missingKeeps = [...keepSet].filter((name) => !presentNames.has(name));
|
|
5013
|
+
if (missingKeeps.length > 0) {
|
|
5014
|
+
console.warn(
|
|
5015
|
+
` [warn] Requested to keep ${missingKeeps.map((n) => `'${n}'`).join(", ")} but they don't exist under '${INFRASTRUCTURE_DIR2}/'.`
|
|
5016
|
+
);
|
|
5017
|
+
}
|
|
5018
|
+
console.log(
|
|
5019
|
+
`
|
|
5020
|
+
Done. Deleted ${deleted} top-level entr${deleted === 1 ? "y" : "ies"}. Review the staged deletions with: git diff --cached -- '${INFRASTRUCTURE_DIR2}/'`
|
|
5021
|
+
);
|
|
5022
|
+
}
|
|
5023
|
+
|
|
5024
|
+
// src/migrations/v2.0/index.ts
|
|
5025
|
+
var NON_SWARM_INFRA_SUBDIRS = ["postgres", "metabase"];
|
|
5026
|
+
async function runUpgrade(dockerSwarm) {
|
|
5027
|
+
await main18();
|
|
3584
5028
|
await main();
|
|
3585
5029
|
await main2();
|
|
3586
5030
|
await main3();
|
|
@@ -3593,9 +5037,21 @@ async function runUpgrade(ccwd) {
|
|
|
3593
5037
|
await main10();
|
|
3594
5038
|
await main11();
|
|
3595
5039
|
await main12();
|
|
5040
|
+
await main13();
|
|
3596
5041
|
await main14();
|
|
3597
5042
|
await main15();
|
|
3598
5043
|
await main16();
|
|
5044
|
+
await main19();
|
|
5045
|
+
await main20();
|
|
5046
|
+
await main21();
|
|
5047
|
+
await main22();
|
|
5048
|
+
await main23();
|
|
5049
|
+
await main24();
|
|
3599
5050
|
await main17();
|
|
3600
|
-
|
|
5051
|
+
if (dockerSwarm) {
|
|
5052
|
+
await main25();
|
|
5053
|
+
} else {
|
|
5054
|
+
await main26({ keep: NON_SWARM_INFRA_SUBDIRS });
|
|
5055
|
+
await main25({ subdirs: NON_SWARM_INFRA_SUBDIRS });
|
|
5056
|
+
}
|
|
3601
5057
|
}
|