@opencrvs/toolkit 2.0.0-rc.adf3f22 → 2.0.0-rc.afe621f
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/dist/application-config/index.js +12 -20
- package/dist/cli.js +295 -122
- package/dist/commons/api/router.d.ts +2881 -143
- package/dist/commons/conditionals/validate.d.ts +1 -0
- package/dist/commons/events/ActionInput.d.ts +108 -0
- package/dist/commons/events/Draft.d.ts +3 -0
- package/dist/commons/events/utils.d.ts +1 -1
- package/dist/events/index.js +28 -34
- package/dist/migrations/v2.0/checkout-upstream-files.d.ts +1 -1
- package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +1 -1
- package/dist/migrations/v2.0/checkout-upstream-files.js +1 -2
- package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts +9 -1
- package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts.map +1 -1
- package/dist/migrations/v2.0/delete-infrastructure-directory.js +66 -20
- package/dist/migrations/v2.0/index.d.ts +5 -3
- package/dist/migrations/v2.0/index.d.ts.map +1 -1
- package/dist/migrations/v2.0/index.js +295 -122
- package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts +11 -1
- package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts.map +1 -1
- package/dist/migrations/v2.0/merge-infrastructure-directory.js +17 -16
- package/dist/migrations/v2.0/migrate-scopes.d.ts.map +1 -1
- package/dist/migrations/v2.0/migrate-scopes.js +54 -30
- package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts.map +1 -1
- package/dist/migrations/v2.0/migrate-workqueue-configs.js +140 -59
- package/dist/notification/index.js +15 -20
- package/opencrvs-toolkit-2.0.0-rc.afe621f.tgz +0 -0
- package/package.json +1 -1
- package/opencrvs-toolkit-2.0.0-rc.adf3f22.tgz +0 -0
|
@@ -418,28 +418,20 @@ function schemaPriority(schema) {
|
|
|
418
418
|
return idx === -1 ? 9999 : idx;
|
|
419
419
|
}
|
|
420
420
|
function safeUnion(schemas) {
|
|
421
|
+
const sortedSchemas = [...schemas].sort(
|
|
422
|
+
(a, b) => schemaPriority(a) - schemaPriority(b)
|
|
423
|
+
);
|
|
421
424
|
return z7.any().superRefine((val, ctx) => {
|
|
422
|
-
const
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
if (successful.length === 0) {
|
|
427
|
-
ctx.addIssue({
|
|
428
|
-
code: "invalid_type",
|
|
429
|
-
expected: "custom",
|
|
430
|
-
message: "Value does not match any schema"
|
|
431
|
-
});
|
|
432
|
-
return;
|
|
433
|
-
}
|
|
434
|
-
successful.sort((a, b) => schemaPriority(a) - schemaPriority(b));
|
|
435
|
-
const best = successful[0];
|
|
436
|
-
if (!best.safeParse(val).success) {
|
|
437
|
-
ctx.addIssue({
|
|
438
|
-
expected: "custom",
|
|
439
|
-
code: "invalid_type",
|
|
440
|
-
message: "Value did not match the best schema"
|
|
441
|
-
});
|
|
425
|
+
for (const schema of sortedSchemas) {
|
|
426
|
+
if (schema.safeParse(val).success) {
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
442
429
|
}
|
|
430
|
+
ctx.addIssue({
|
|
431
|
+
code: "invalid_type",
|
|
432
|
+
expected: "custom",
|
|
433
|
+
message: "Value does not match any schema"
|
|
434
|
+
});
|
|
443
435
|
}).meta({
|
|
444
436
|
description: "Value that matches exactly one of the possible schema types (TextValue, DateValue, DateRangeFieldValue). The best matching schema is chosen by priority."
|
|
445
437
|
});
|
package/dist/cli.js
CHANGED
|
@@ -2120,6 +2120,10 @@ Done. Converted ${convertedCount} config file(s), replaced ${totalReplaced} rout
|
|
|
2120
2120
|
var import_ts_morph11 = require("ts-morph");
|
|
2121
2121
|
var import_path11 = __toESM(require("path"));
|
|
2122
2122
|
|
|
2123
|
+
// ../commons/src/scopes.deprecated.do-not-use.ts
|
|
2124
|
+
var z4 = __toESM(require("zod/v4"));
|
|
2125
|
+
var import_lodash = require("lodash");
|
|
2126
|
+
|
|
2123
2127
|
// ../commons/src/scopes.ts
|
|
2124
2128
|
var z3 = __toESM(require("zod/v4"));
|
|
2125
2129
|
var qs = __toESM(require("qs"));
|
|
@@ -2393,7 +2397,6 @@ var DEFAULT_SCOPE_OPTIONS = {
|
|
|
2393
2397
|
};
|
|
2394
2398
|
|
|
2395
2399
|
// ../commons/src/scopes.deprecated.do-not-use.ts
|
|
2396
|
-
var z4 = __toESM(require("zod/v4"));
|
|
2397
2400
|
var rawConfigurableScopeRegex = /^([a-zA-Z][a-zA-Z0-9.-]*(?:\.[a-zA-Z0-9.-]+)*)\[((?:\w+=[\w.-]+(?:\|[\w.-]+)*)(?:,[\w]+=[\w.-]+(?:\|[\w.-]+)*)*)\]$/;
|
|
2398
2401
|
var rawConfigurableScope = z4.string().regex(rawConfigurableScopeRegex);
|
|
2399
2402
|
var SearchScope = z4.object({
|
|
@@ -2627,6 +2630,74 @@ var legacyScopeToV2Scope = (v1Scope) => {
|
|
|
2627
2630
|
}
|
|
2628
2631
|
throw new Error(`Unsupported V1 scope type: ${v1Scope}`);
|
|
2629
2632
|
};
|
|
2633
|
+
var MERGEABLE_USER_SCOPE_TYPES = ["user.create", "user.edit"];
|
|
2634
|
+
function isMergeableUserScopeType(type) {
|
|
2635
|
+
return MERGEABLE_USER_SCOPE_TYPES.includes(type);
|
|
2636
|
+
}
|
|
2637
|
+
function decodeLegacyScope(legacy) {
|
|
2638
|
+
const encoded = legacyScopeToV2Scope(legacy);
|
|
2639
|
+
const scope = decodeScope(encoded);
|
|
2640
|
+
if (!scope) {
|
|
2641
|
+
throw new Error(
|
|
2642
|
+
`Could not decode migrated scope from legacy '${legacy}' (encoded: '${encoded}').`
|
|
2643
|
+
);
|
|
2644
|
+
}
|
|
2645
|
+
return { legacy, scope };
|
|
2646
|
+
}
|
|
2647
|
+
function groupByType(entries) {
|
|
2648
|
+
return entries.reduce(
|
|
2649
|
+
(groups, entry) => ({
|
|
2650
|
+
...groups,
|
|
2651
|
+
[entry.scope.type]: [...groups[entry.scope.type] ?? [], entry]
|
|
2652
|
+
}),
|
|
2653
|
+
{}
|
|
2654
|
+
);
|
|
2655
|
+
}
|
|
2656
|
+
function deduplicateEntries(entries) {
|
|
2657
|
+
return entries.filter(
|
|
2658
|
+
(entry, index) => entries.findIndex((e) => (0, import_lodash.isEqual)(e.scope, entry.scope)) === index
|
|
2659
|
+
);
|
|
2660
|
+
}
|
|
2661
|
+
function mergeEntries(type, entries) {
|
|
2662
|
+
const optionsList = entries.map(
|
|
2663
|
+
(e) => "options" in e.scope && e.scope.options ? e.scope.options : {}
|
|
2664
|
+
);
|
|
2665
|
+
const allKeys = optionsList.flatMap(
|
|
2666
|
+
(opts) => Object.keys(opts).filter((k) => opts[k] !== void 0)
|
|
2667
|
+
);
|
|
2668
|
+
const conflictKey = allKeys.find((key, i) => allKeys.indexOf(key) !== i);
|
|
2669
|
+
if (conflictKey) {
|
|
2670
|
+
const conflicting = entries.filter(
|
|
2671
|
+
(e) => conflictKey in ("options" in e.scope && e.scope.options || {})
|
|
2672
|
+
).map((e) => JSON.stringify(e.legacy));
|
|
2673
|
+
throw new Error(
|
|
2674
|
+
`Cannot auto-merge two '${type}' scopes that both define '${conflictKey}'. Conflicting legacy scopes: [${conflicting.join(", ")}]. Resolve manually in roles.ts and re-run.`
|
|
2675
|
+
);
|
|
2676
|
+
}
|
|
2677
|
+
const mergedOptions = Object.assign({}, ...optionsList);
|
|
2678
|
+
const merged = Object.keys(mergedOptions).length > 0 ? { type, options: mergedOptions } : { type };
|
|
2679
|
+
const parsed = Scope2.safeParse(merged);
|
|
2680
|
+
if (!parsed.success) {
|
|
2681
|
+
throw new Error(
|
|
2682
|
+
`Merged '${type}' scope failed schema validation: ${parsed.error.message}. Legacy scopes: [${entries.map((e) => JSON.stringify(e.legacy)).join(", ")}].`
|
|
2683
|
+
);
|
|
2684
|
+
}
|
|
2685
|
+
return parsed.data;
|
|
2686
|
+
}
|
|
2687
|
+
function migrateLegacyScopesArrayToV2Scopes(legacyScopes) {
|
|
2688
|
+
const groups = groupByType(legacyScopes.map(decodeLegacyScope));
|
|
2689
|
+
return Object.entries(groups).flatMap(([type, entries]) => {
|
|
2690
|
+
const deduped = deduplicateEntries(entries);
|
|
2691
|
+
if (deduped.length <= 1) return deduped.map((e) => e.scope);
|
|
2692
|
+
if (!isMergeableUserScopeType(type)) {
|
|
2693
|
+
console.warn(
|
|
2694
|
+
`Multiple non-mergeable '${type}' scopes detected after dedup \u2014 kept all as-is. Legacy scopes: [${deduped.map((e) => JSON.stringify(e.legacy)).join(", ")}]. Review whether the duplication is intentional.`
|
|
2695
|
+
);
|
|
2696
|
+
return deduped.map((e) => e.scope);
|
|
2697
|
+
}
|
|
2698
|
+
return [mergeEntries(type, deduped)];
|
|
2699
|
+
});
|
|
2700
|
+
}
|
|
2630
2701
|
|
|
2631
2702
|
// src/migrations/v2.0/migrate-scopes.ts
|
|
2632
2703
|
var ROLES_FILE_RELATIVE_PATH = "src/data-seeding/roles/roles.ts";
|
|
@@ -2664,57 +2735,65 @@ function resolveLegacyScopeFromElement(element) {
|
|
|
2664
2735
|
}
|
|
2665
2736
|
function migrateScopesArrays(rolesFilePath, project) {
|
|
2666
2737
|
const sourceFile = project.getSourceFile(rolesFilePath);
|
|
2667
|
-
if (!sourceFile)
|
|
2738
|
+
if (!sourceFile) {
|
|
2739
|
+
return { migratedCount: 0, removedCount: 0, mergedCount: 0 };
|
|
2740
|
+
}
|
|
2668
2741
|
let migratedCount = 0;
|
|
2669
2742
|
let removedCount = 0;
|
|
2743
|
+
let mergedCount = 0;
|
|
2670
2744
|
const scopesProperties = sourceFile.getDescendantsOfKind(import_ts_morph11.SyntaxKind.PropertyAssignment).filter((prop) => prop.getName() === SCOPES_PROPERTY_NAME);
|
|
2745
|
+
const relPath = import_path11.default.relative(process.cwd(), rolesFilePath);
|
|
2671
2746
|
for (const scopesProp of scopesProperties) {
|
|
2672
2747
|
const initializer = scopesProp.getInitializer();
|
|
2673
2748
|
if (!initializer || !import_ts_morph11.Node.isArrayLiteralExpression(initializer)) continue;
|
|
2674
|
-
const
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2749
|
+
const rawTexts = [];
|
|
2750
|
+
const legacyStrings = [];
|
|
2751
|
+
let anyChange = false;
|
|
2752
|
+
for (const element of initializer.getElements()) {
|
|
2678
2753
|
const scopeKey = resolveScopeKeyFromElementAccess(element);
|
|
2679
2754
|
if (scopeKey && !(scopeKey in SCOPES)) {
|
|
2680
2755
|
console.warn(
|
|
2681
|
-
` [${
|
|
2756
|
+
` [${relPath}] Removing unknown scope reference: SCOPES.${scopeKey}`
|
|
2682
2757
|
);
|
|
2683
|
-
initializer.removeElement(index);
|
|
2684
2758
|
removedCount++;
|
|
2759
|
+
anyChange = true;
|
|
2685
2760
|
continue;
|
|
2686
2761
|
}
|
|
2687
2762
|
const legacyScope = resolveLegacyScopeFromElement(element);
|
|
2688
2763
|
if (!legacyScope) {
|
|
2689
2764
|
console.warn(
|
|
2690
|
-
` [${
|
|
2765
|
+
` [${relPath}] Preserving non-literal scope expression verbatim: ${element.getText()}`
|
|
2691
2766
|
);
|
|
2767
|
+
rawTexts.push(element.getText());
|
|
2692
2768
|
continue;
|
|
2693
2769
|
}
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
const scope = decodeScope(migratedScope);
|
|
2697
|
-
if (!scope) {
|
|
2698
|
-
console.warn(
|
|
2699
|
-
` [${import_path11.default.relative(process.cwd(), rolesFilePath)}] Could not decode migrated scope '${migratedScope}'.`
|
|
2700
|
-
);
|
|
2701
|
-
continue;
|
|
2702
|
-
}
|
|
2703
|
-
element.replaceWithText(JSON.stringify(scope));
|
|
2704
|
-
migratedCount++;
|
|
2705
|
-
} catch (error) {
|
|
2706
|
-
console.warn(
|
|
2707
|
-
` [${import_path11.default.relative(process.cwd(), rolesFilePath)}] Could not migrate scope '${legacyScope}': ${error}`
|
|
2708
|
-
);
|
|
2709
|
-
}
|
|
2770
|
+
legacyStrings.push(legacyScope);
|
|
2771
|
+
anyChange = true;
|
|
2710
2772
|
}
|
|
2773
|
+
if (!anyChange) continue;
|
|
2774
|
+
let mergedScopes;
|
|
2775
|
+
try {
|
|
2776
|
+
mergedScopes = migrateLegacyScopesArrayToV2Scopes(legacyStrings);
|
|
2777
|
+
} catch (error) {
|
|
2778
|
+
throw new Error(
|
|
2779
|
+
`[${relPath}] Failed to migrate scopes for role: ${error instanceof Error ? error.message : String(error)}`,
|
|
2780
|
+
{ cause: error }
|
|
2781
|
+
);
|
|
2782
|
+
}
|
|
2783
|
+
migratedCount += legacyStrings.length;
|
|
2784
|
+
mergedCount += legacyStrings.length - mergedScopes.length;
|
|
2785
|
+
const outputElements = [
|
|
2786
|
+
...rawTexts,
|
|
2787
|
+
...mergedScopes.map((s) => JSON.stringify(s))
|
|
2788
|
+
];
|
|
2789
|
+
scopesProp.setInitializer(`[${outputElements.join(", ")}]`);
|
|
2711
2790
|
}
|
|
2712
2791
|
if (removedCount > 0) {
|
|
2713
2792
|
console.log(
|
|
2714
|
-
` Removed ${removedCount} unknown SCOPES reference(s) from '${
|
|
2793
|
+
` Removed ${removedCount} unknown SCOPES reference(s) from '${relPath}'.`
|
|
2715
2794
|
);
|
|
2716
2795
|
}
|
|
2717
|
-
return { migratedCount, removedCount };
|
|
2796
|
+
return { migratedCount, removedCount, mergedCount };
|
|
2718
2797
|
}
|
|
2719
2798
|
function ensureScopesHelpersImport(rolesFilePath, project) {
|
|
2720
2799
|
const sourceFile = project.getSourceFile(rolesFilePath);
|
|
@@ -2849,7 +2928,7 @@ async function main11() {
|
|
|
2849
2928
|
return;
|
|
2850
2929
|
}
|
|
2851
2930
|
const importChanged = ensureScopesHelpersImport(rolesFilePath, project);
|
|
2852
|
-
const { migratedCount, removedCount } = migrateScopesArrays(
|
|
2931
|
+
const { migratedCount, removedCount, mergedCount } = migrateScopesArrays(
|
|
2853
2932
|
rolesFilePath,
|
|
2854
2933
|
project
|
|
2855
2934
|
);
|
|
@@ -2868,7 +2947,7 @@ async function main11() {
|
|
|
2868
2947
|
}
|
|
2869
2948
|
await sourceFile.save();
|
|
2870
2949
|
console.log(
|
|
2871
|
-
`Done. Migrated ${migratedCount} legacy scope(s), removed ${removedCount} unknown SCOPES reference(s), wrapped ${wrappedScopesCount} scope array(s) with defineScopes()${wrappedRoles ? ", wrapped roles with defineRoles()" : ""}${removedRoleType ? ", and removed Role type definition" : ""}${importChanged ? ". Updated toolkit/scopes imports." : "."}`
|
|
2950
|
+
`Done. Migrated ${migratedCount} legacy scope(s), merged ${mergedCount} AND-paired scope(s) into single v2 objects (privilege-escalation fix, see issue #12489), removed ${removedCount} unknown SCOPES reference(s), wrapped ${wrappedScopesCount} scope array(s) with defineScopes()${wrappedRoles ? ", wrapped roles with defineRoles()" : ""}${removedRoleType ? ", and removed Role type definition" : ""}${importChanged ? ". Updated toolkit/scopes imports." : "."}`
|
|
2872
2951
|
);
|
|
2873
2952
|
}
|
|
2874
2953
|
|
|
@@ -3674,6 +3753,10 @@ var ACTION_PROPERTY_NAME2 = "action";
|
|
|
3674
3753
|
var CONDITIONALS_PROPERTY_NAME = "conditionals";
|
|
3675
3754
|
var TYPE_PROPERTY_NAME7 = "type";
|
|
3676
3755
|
var SLUG_PROPERTY_NAME = "slug";
|
|
3756
|
+
var READ_ACTION_TYPE = "READ";
|
|
3757
|
+
var ACTION_TYPE_IMPORT_NAME = "ActionType";
|
|
3758
|
+
var TOOLKIT_EVENTS_MODULE2 = "@opencrvs/toolkit/events";
|
|
3759
|
+
var READ_ACTION_FALLBACK_INITIALIZER = `{ type: ${ACTION_TYPE_IMPORT_NAME}.${READ_ACTION_TYPE} }`;
|
|
3677
3760
|
var SUPPORTED_WORKQUEUE_ACTION_TYPES = /* @__PURE__ */ new Set([
|
|
3678
3761
|
"READ",
|
|
3679
3762
|
"DELETE",
|
|
@@ -3721,91 +3804,137 @@ function isUnsupportedActionType(action) {
|
|
|
3721
3804
|
}
|
|
3722
3805
|
return !SUPPORTED_WORKQUEUE_ACTION_TYPES.has(typeName);
|
|
3723
3806
|
}
|
|
3724
|
-
function
|
|
3725
|
-
const
|
|
3726
|
-
|
|
3727
|
-
|
|
3728
|
-
|
|
3729
|
-
|
|
3730
|
-
|
|
3731
|
-
|
|
3807
|
+
function ensureValidAction(workqueue, relPath) {
|
|
3808
|
+
const workqueueLabel = getWorkqueueLabel(workqueue);
|
|
3809
|
+
const actionProperty = workqueue.getProperty(ACTION_PROPERTY_NAME2);
|
|
3810
|
+
if (actionProperty && import_ts_morph17.Node.isPropertyAssignment(actionProperty)) {
|
|
3811
|
+
const initializer = actionProperty.getInitializer();
|
|
3812
|
+
if (initializer && import_ts_morph17.Node.isObjectLiteralExpression(initializer)) {
|
|
3813
|
+
if (!isUnsupportedActionType(initializer)) {
|
|
3814
|
+
return { changed: false, usedReadFallback: false };
|
|
3815
|
+
}
|
|
3816
|
+
actionProperty.set({
|
|
3817
|
+
name: ACTION_PROPERTY_NAME2,
|
|
3818
|
+
initializer: READ_ACTION_FALLBACK_INITIALIZER
|
|
3819
|
+
});
|
|
3820
|
+
console.log(
|
|
3821
|
+
` [${relPath}] Replaced unsupported 'action' type with '${ACTION_TYPE_IMPORT_NAME}.${READ_ACTION_TYPE}' on workqueue '${workqueueLabel}'`
|
|
3822
|
+
);
|
|
3823
|
+
return { changed: true, usedReadFallback: true };
|
|
3824
|
+
}
|
|
3732
3825
|
}
|
|
3826
|
+
workqueue.addPropertyAssignment({
|
|
3827
|
+
name: ACTION_PROPERTY_NAME2,
|
|
3828
|
+
initializer: READ_ACTION_FALLBACK_INITIALIZER
|
|
3829
|
+
});
|
|
3830
|
+
console.log(
|
|
3831
|
+
` [${relPath}] Added default 'action: ${READ_ACTION_FALLBACK_INITIALIZER}' to workqueue '${workqueueLabel}'`
|
|
3832
|
+
);
|
|
3833
|
+
return { changed: true, usedReadFallback: true };
|
|
3834
|
+
}
|
|
3835
|
+
function migrateWorkqueueActions(workqueue, relPath) {
|
|
3733
3836
|
const workqueueLabel = getWorkqueueLabel(workqueue);
|
|
3734
|
-
const
|
|
3735
|
-
|
|
3736
|
-
|
|
3737
|
-
|
|
3738
|
-
|
|
3739
|
-
|
|
3740
|
-
|
|
3837
|
+
const actionsProperty = workqueue.getProperty(ACTIONS_PROPERTY_NAME5);
|
|
3838
|
+
let actionsArrayMigrated = false;
|
|
3839
|
+
if (actionsProperty && import_ts_morph17.Node.isPropertyAssignment(actionsProperty)) {
|
|
3840
|
+
const actionsInitializer = actionsProperty.getInitializer();
|
|
3841
|
+
if (actionsInitializer && import_ts_morph17.Node.isArrayLiteralExpression(actionsInitializer)) {
|
|
3842
|
+
const existingActionProperty = workqueue.getProperty(ACTION_PROPERTY_NAME2);
|
|
3843
|
+
if (existingActionProperty) {
|
|
3844
|
+
if (import_ts_morph17.Node.isPropertyAssignment(existingActionProperty)) {
|
|
3845
|
+
const existingActionInitializer = existingActionProperty.getInitializer();
|
|
3846
|
+
if (existingActionInitializer && import_ts_morph17.Node.isObjectLiteralExpression(existingActionInitializer)) {
|
|
3847
|
+
const conditionalsProperty = existingActionInitializer.getProperty(
|
|
3848
|
+
CONDITIONALS_PROPERTY_NAME
|
|
3849
|
+
);
|
|
3850
|
+
if (conditionalsProperty) {
|
|
3851
|
+
conditionalsProperty.remove();
|
|
3852
|
+
console.log(
|
|
3853
|
+
` [${relPath}] Removed deprecated 'conditionals' from 'action' on workqueue '${workqueueLabel}'`
|
|
3854
|
+
);
|
|
3855
|
+
}
|
|
3856
|
+
}
|
|
3857
|
+
}
|
|
3858
|
+
actionsProperty.remove();
|
|
3859
|
+
console.log(
|
|
3860
|
+
` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' (existing 'action' kept)`
|
|
3861
|
+
);
|
|
3862
|
+
actionsArrayMigrated = true;
|
|
3863
|
+
} else {
|
|
3864
|
+
const actionCandidates = actionsInitializer.getElements().filter(
|
|
3865
|
+
(element) => import_ts_morph17.Node.isObjectLiteralExpression(element)
|
|
3741
3866
|
);
|
|
3742
|
-
if (
|
|
3743
|
-
|
|
3867
|
+
if (actionCandidates.length === 0) {
|
|
3868
|
+
actionsProperty.remove();
|
|
3744
3869
|
console.log(
|
|
3745
|
-
` [${relPath}] Removed
|
|
3870
|
+
` [${relPath}] Removed empty 'actions' from workqueue '${workqueueLabel}'`
|
|
3746
3871
|
);
|
|
3747
|
-
|
|
3748
|
-
|
|
3749
|
-
|
|
3750
|
-
|
|
3751
|
-
|
|
3872
|
+
actionsArrayMigrated = true;
|
|
3873
|
+
} else {
|
|
3874
|
+
if (actionCandidates.length > 1) {
|
|
3875
|
+
const droppedCount = actionCandidates.length - 1;
|
|
3876
|
+
console.warn(
|
|
3877
|
+
` [${relPath}] Workqueue '${workqueueLabel}' has ${actionCandidates.length} actions; keeping first as 'action' and dropping ${droppedCount} extra action(s)`
|
|
3878
|
+
);
|
|
3879
|
+
}
|
|
3880
|
+
const conditionalsProperty = actionCandidates[0].getProperty(
|
|
3881
|
+
CONDITIONALS_PROPERTY_NAME
|
|
3752
3882
|
);
|
|
3883
|
+
if (conditionalsProperty) {
|
|
3884
|
+
conditionalsProperty.remove();
|
|
3885
|
+
console.log(
|
|
3886
|
+
` [${relPath}] Removed deprecated 'conditionals' from migrated 'action' on workqueue '${workqueueLabel}'`
|
|
3887
|
+
);
|
|
3888
|
+
}
|
|
3889
|
+
if (isUnsupportedActionType(actionCandidates[0])) {
|
|
3890
|
+
actionsProperty.remove();
|
|
3891
|
+
console.log(
|
|
3892
|
+
` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' because action type is unsupported`
|
|
3893
|
+
);
|
|
3894
|
+
actionsArrayMigrated = true;
|
|
3895
|
+
} else {
|
|
3896
|
+
const firstActionText = actionCandidates[0].getText();
|
|
3897
|
+
workqueue.addPropertyAssignment({
|
|
3898
|
+
name: ACTION_PROPERTY_NAME2,
|
|
3899
|
+
initializer: firstActionText
|
|
3900
|
+
});
|
|
3901
|
+
actionsProperty.remove();
|
|
3902
|
+
console.log(
|
|
3903
|
+
` [${relPath}] Replaced 'actions' with 'action' on workqueue '${workqueueLabel}'`
|
|
3904
|
+
);
|
|
3905
|
+
actionsArrayMigrated = true;
|
|
3906
|
+
}
|
|
3753
3907
|
}
|
|
3754
3908
|
}
|
|
3755
3909
|
}
|
|
3756
|
-
actionsProperty.remove();
|
|
3757
|
-
console.log(
|
|
3758
|
-
` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' (existing 'action' kept)`
|
|
3759
|
-
);
|
|
3760
|
-
return 1;
|
|
3761
|
-
}
|
|
3762
|
-
const actionCandidates = actionsInitializer.getElements().filter(
|
|
3763
|
-
(element) => import_ts_morph17.Node.isObjectLiteralExpression(element)
|
|
3764
|
-
);
|
|
3765
|
-
if (actionCandidates.length === 0) {
|
|
3766
|
-
actionsProperty.remove();
|
|
3767
|
-
console.log(
|
|
3768
|
-
` [${relPath}] Removed empty 'actions' from workqueue '${workqueueLabel}'`
|
|
3769
|
-
);
|
|
3770
|
-
return 1;
|
|
3771
|
-
}
|
|
3772
|
-
if (actionCandidates.length > 1) {
|
|
3773
|
-
const droppedCount = actionCandidates.length - 1;
|
|
3774
|
-
console.warn(
|
|
3775
|
-
` [${relPath}] Workqueue '${workqueueLabel}' has ${actionCandidates.length} actions; keeping first as 'action' and dropping ${droppedCount} extra action(s)`
|
|
3776
|
-
);
|
|
3777
3910
|
}
|
|
3778
|
-
const
|
|
3779
|
-
|
|
3911
|
+
const fallback = ensureValidAction(workqueue, relPath);
|
|
3912
|
+
return {
|
|
3913
|
+
changed: actionsArrayMigrated || fallback.changed,
|
|
3914
|
+
usedReadFallback: fallback.usedReadFallback
|
|
3915
|
+
};
|
|
3916
|
+
}
|
|
3917
|
+
function ensureActionTypeImport(sourceFile) {
|
|
3918
|
+
const existingImport = sourceFile.getImportDeclaration(
|
|
3919
|
+
(decl) => decl.getModuleSpecifierValue() === TOOLKIT_EVENTS_MODULE2
|
|
3780
3920
|
);
|
|
3781
|
-
if (
|
|
3782
|
-
|
|
3783
|
-
|
|
3784
|
-
|
|
3785
|
-
|
|
3786
|
-
|
|
3787
|
-
if (isUnsupportedActionType(actionCandidates[0])) {
|
|
3788
|
-
actionsProperty.remove();
|
|
3789
|
-
console.log(
|
|
3790
|
-
` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' because action type is unsupported`
|
|
3791
|
-
);
|
|
3792
|
-
return 1;
|
|
3921
|
+
if (existingImport) {
|
|
3922
|
+
const alreadyImported = existingImport.getNamedImports().some((ni) => ni.getName() === ACTION_TYPE_IMPORT_NAME);
|
|
3923
|
+
if (!alreadyImported) {
|
|
3924
|
+
existingImport.addNamedImport(ACTION_TYPE_IMPORT_NAME);
|
|
3925
|
+
}
|
|
3926
|
+
return;
|
|
3793
3927
|
}
|
|
3794
|
-
|
|
3795
|
-
|
|
3796
|
-
|
|
3797
|
-
initializer: firstActionText
|
|
3928
|
+
sourceFile.addImportDeclaration({
|
|
3929
|
+
moduleSpecifier: TOOLKIT_EVENTS_MODULE2,
|
|
3930
|
+
namedImports: [ACTION_TYPE_IMPORT_NAME]
|
|
3798
3931
|
});
|
|
3799
|
-
actionsProperty.remove();
|
|
3800
|
-
console.log(
|
|
3801
|
-
` [${relPath}] Replaced 'actions' with 'action' on workqueue '${workqueueLabel}'`
|
|
3802
|
-
);
|
|
3803
|
-
return 1;
|
|
3804
3932
|
}
|
|
3805
3933
|
function processFile13(filePath, project) {
|
|
3806
3934
|
const sourceFile = project.getSourceFile(filePath);
|
|
3807
3935
|
if (!sourceFile) return 0;
|
|
3808
3936
|
let migratedWorkqueues = 0;
|
|
3937
|
+
let needsActionTypeImport = false;
|
|
3809
3938
|
const relPath = import_path18.default.relative(process.cwd(), filePath);
|
|
3810
3939
|
const callExpressions = sourceFile.getDescendantsOfKind(
|
|
3811
3940
|
import_ts_morph17.SyntaxKind.CallExpression
|
|
@@ -3821,9 +3950,14 @@ function processFile13(filePath, project) {
|
|
|
3821
3950
|
if (!import_ts_morph17.Node.isArrayLiteralExpression(workqueuesArg)) continue;
|
|
3822
3951
|
for (const element of workqueuesArg.getElements()) {
|
|
3823
3952
|
if (!import_ts_morph17.Node.isObjectLiteralExpression(element)) continue;
|
|
3824
|
-
|
|
3953
|
+
const result = migrateWorkqueueActions(element, relPath);
|
|
3954
|
+
if (result.changed) migratedWorkqueues++;
|
|
3955
|
+
if (result.usedReadFallback) needsActionTypeImport = true;
|
|
3825
3956
|
}
|
|
3826
3957
|
}
|
|
3958
|
+
if (needsActionTypeImport) {
|
|
3959
|
+
ensureActionTypeImport(sourceFile);
|
|
3960
|
+
}
|
|
3827
3961
|
return migratedWorkqueues;
|
|
3828
3962
|
}
|
|
3829
3963
|
async function main18() {
|
|
@@ -4158,7 +4292,7 @@ Saved ${handlerRelPath}.`);
|
|
|
4158
4292
|
// src/migrations/v2.0/checkout-upstream-files.ts
|
|
4159
4293
|
var import_child_process = require("child_process");
|
|
4160
4294
|
var UPSTREAM_URL = "https://github.com/opencrvs/opencrvs-countryconfig.git";
|
|
4161
|
-
var UPSTREAM_BRANCH = "
|
|
4295
|
+
var UPSTREAM_BRANCH = "release-v2.0.0";
|
|
4162
4296
|
var TEMP_REMOTE = "opencrvs-upgrade-v19-v20-codemod";
|
|
4163
4297
|
var FILES_TO_CHECKOUT = [
|
|
4164
4298
|
"src/analytics/analytics.ts",
|
|
@@ -4708,9 +4842,13 @@ function gitShowBytes(ref, path23) {
|
|
|
4708
4842
|
return null;
|
|
4709
4843
|
}
|
|
4710
4844
|
}
|
|
4711
|
-
async function main25(
|
|
4845
|
+
async function main25({
|
|
4846
|
+
subdirs = []
|
|
4847
|
+
} = {}) {
|
|
4848
|
+
const pathspecs = subdirs.length > 0 ? subdirs.map((s) => `${INFRASTRUCTURE_DIR}/${s}/`) : [`${INFRASTRUCTURE_DIR}/`];
|
|
4849
|
+
const scopeLabel = pathspecs.map((p) => `'${p}'`).join(", ");
|
|
4712
4850
|
console.log(
|
|
4713
|
-
`Merging
|
|
4851
|
+
`Merging ${scopeLabel} from ${UPSTREAM_URL}@${UPSTREAM_BRANCH} (base: ${BASE_BRANCH})...
|
|
4714
4852
|
`
|
|
4715
4853
|
);
|
|
4716
4854
|
assertIsGitRepo();
|
|
@@ -4725,20 +4863,12 @@ async function main25() {
|
|
|
4725
4863
|
const ref = `${TEMP_REMOTE2}/${UPSTREAM_BRANCH}`;
|
|
4726
4864
|
const baseRef = `${TEMP_REMOTE2}/${BASE_BRANCH}`;
|
|
4727
4865
|
const upstreamFiles = runGit(
|
|
4728
|
-
[
|
|
4729
|
-
"ls-tree",
|
|
4730
|
-
"-r",
|
|
4731
|
-
"--name-only",
|
|
4732
|
-
"-z",
|
|
4733
|
-
ref,
|
|
4734
|
-
"--",
|
|
4735
|
-
`${INFRASTRUCTURE_DIR}/`
|
|
4736
|
-
],
|
|
4866
|
+
["ls-tree", "-r", "--name-only", "-z", ref, "--", ...pathspecs],
|
|
4737
4867
|
{ silent: true }
|
|
4738
4868
|
).split("\0").filter(Boolean);
|
|
4739
4869
|
if (upstreamFiles.length === 0) {
|
|
4740
4870
|
console.log(
|
|
4741
|
-
` No files found under
|
|
4871
|
+
` No files found under ${scopeLabel} on ${ref}. Nothing to merge.`
|
|
4742
4872
|
);
|
|
4743
4873
|
return;
|
|
4744
4874
|
}
|
|
@@ -4813,7 +4943,9 @@ async function main25() {
|
|
|
4813
4943
|
var import_fs6 = require("fs");
|
|
4814
4944
|
var import_path25 = require("path");
|
|
4815
4945
|
var INFRASTRUCTURE_DIR2 = "infrastructure";
|
|
4816
|
-
async function main26(
|
|
4946
|
+
async function main26({
|
|
4947
|
+
keep = []
|
|
4948
|
+
} = {}) {
|
|
4817
4949
|
const fullPath = (0, import_path25.join)(process.cwd(), INFRASTRUCTURE_DIR2);
|
|
4818
4950
|
if (!(0, import_fs6.existsSync)(fullPath)) {
|
|
4819
4951
|
console.log(
|
|
@@ -4821,24 +4953,64 @@ async function main26() {
|
|
|
4821
4953
|
);
|
|
4822
4954
|
return;
|
|
4823
4955
|
}
|
|
4824
|
-
console.log(`Deleting '${INFRASTRUCTURE_DIR2}/'...
|
|
4825
|
-
`);
|
|
4826
4956
|
assertIsGitRepo();
|
|
4827
|
-
|
|
4828
|
-
|
|
4829
|
-
|
|
4830
|
-
|
|
4831
|
-
|
|
4832
|
-
|
|
4833
|
-
console.log(
|
|
4957
|
+
if (keep.length === 0) {
|
|
4958
|
+
console.log(`Deleting '${INFRASTRUCTURE_DIR2}/'...
|
|
4959
|
+
`);
|
|
4960
|
+
runGit(["rm", "-rf", "--ignore-unmatch", "--", `${INFRASTRUCTURE_DIR2}/`], {
|
|
4961
|
+
silent: true
|
|
4962
|
+
});
|
|
4963
|
+
console.log(
|
|
4964
|
+
` Staged deletion of tracked files under '${INFRASTRUCTURE_DIR2}/'.`
|
|
4965
|
+
);
|
|
4966
|
+
if ((0, import_fs6.existsSync)(fullPath)) {
|
|
4967
|
+
(0, import_fs6.rmSync)(fullPath, { recursive: true, force: true });
|
|
4968
|
+
console.log(
|
|
4969
|
+
` Removed remaining untracked files under '${INFRASTRUCTURE_DIR2}/'.`
|
|
4970
|
+
);
|
|
4971
|
+
}
|
|
4972
|
+
console.log(
|
|
4973
|
+
`
|
|
4974
|
+
Done. Review the staged deletion with: git diff --cached -- '${INFRASTRUCTURE_DIR2}/'`
|
|
4975
|
+
);
|
|
4976
|
+
return;
|
|
4977
|
+
}
|
|
4978
|
+
const keepSet = new Set(keep);
|
|
4979
|
+
console.log(
|
|
4980
|
+
`Deleting contents of '${INFRASTRUCTURE_DIR2}/' except: ${[...keepSet].map((name) => `'${name}'`).join(", ")}
|
|
4981
|
+
`
|
|
4982
|
+
);
|
|
4983
|
+
const topLevelEntries = (0, import_fs6.readdirSync)(fullPath, { withFileTypes: true });
|
|
4984
|
+
let deleted = 0;
|
|
4985
|
+
for (const entry of topLevelEntries) {
|
|
4986
|
+
if (keepSet.has(entry.name)) {
|
|
4987
|
+
console.log(` Keeping '${INFRASTRUCTURE_DIR2}/${entry.name}'.`);
|
|
4988
|
+
continue;
|
|
4989
|
+
}
|
|
4990
|
+
const relPath = `${INFRASTRUCTURE_DIR2}/${entry.name}${entry.isDirectory() ? "/" : ""}`;
|
|
4991
|
+
runGit(["rm", "-rf", "--ignore-unmatch", "--", relPath], { silent: true });
|
|
4992
|
+
const fullEntryPath = (0, import_path25.join)(fullPath, entry.name);
|
|
4993
|
+
if ((0, import_fs6.existsSync)(fullEntryPath)) {
|
|
4994
|
+
(0, import_fs6.rmSync)(fullEntryPath, { recursive: true, force: true });
|
|
4995
|
+
}
|
|
4996
|
+
console.log(` Deleted '${relPath}'.`);
|
|
4997
|
+
deleted++;
|
|
4998
|
+
}
|
|
4999
|
+
const presentNames = new Set(topLevelEntries.map((e) => e.name));
|
|
5000
|
+
const missingKeeps = [...keepSet].filter((name) => !presentNames.has(name));
|
|
5001
|
+
if (missingKeeps.length > 0) {
|
|
5002
|
+
console.warn(
|
|
5003
|
+
` [warn] Requested to keep ${missingKeeps.map((n) => `'${n}'`).join(", ")} but they don't exist under '${INFRASTRUCTURE_DIR2}/'.`
|
|
5004
|
+
);
|
|
4834
5005
|
}
|
|
4835
5006
|
console.log(
|
|
4836
5007
|
`
|
|
4837
|
-
Done. Review the staged
|
|
5008
|
+
Done. Deleted ${deleted} top-level entr${deleted === 1 ? "y" : "ies"}. Review the staged deletions with: git diff --cached -- '${INFRASTRUCTURE_DIR2}/'`
|
|
4838
5009
|
);
|
|
4839
5010
|
}
|
|
4840
5011
|
|
|
4841
5012
|
// src/migrations/v2.0/index.ts
|
|
5013
|
+
var NON_SWARM_INFRA_SUBDIRS = ["postgres", "metabase"];
|
|
4842
5014
|
async function runUpgrade(dockerSwarm) {
|
|
4843
5015
|
await main18();
|
|
4844
5016
|
await main();
|
|
@@ -4867,7 +5039,8 @@ async function runUpgrade(dockerSwarm) {
|
|
|
4867
5039
|
if (dockerSwarm) {
|
|
4868
5040
|
await main25();
|
|
4869
5041
|
} else {
|
|
4870
|
-
await main26();
|
|
5042
|
+
await main26({ keep: NON_SWARM_INFRA_SUBDIRS });
|
|
5043
|
+
await main25({ subdirs: NON_SWARM_INFRA_SUBDIRS });
|
|
4871
5044
|
}
|
|
4872
5045
|
}
|
|
4873
5046
|
|