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