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