@opencrvs/toolkit 2.0.0-rc.28e4d24 → 2.0.0-rc.2905bb8
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 +50 -20
- package/create-countryconfig/package.json +12 -2
- package/dist/application-config/index.js +264 -118
- package/dist/cli.js +319 -138
- package/dist/commons/api/router.d.ts +2731 -11359
- package/dist/commons/application-config/index.d.ts +1 -0
- package/dist/commons/conditionals/conditionals.d.ts +354 -4
- 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 +377 -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/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 +55 -2
- package/dist/events/index.js +954 -254
- 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/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-action-confirmation-handler-type.js → fix-accept-requested-registration-function-type.js} +11 -14
- 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 +319 -138
- 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 +804 -153
- package/dist/scopes/index.d.ts +4 -6
- package/dist/scopes/index.js +12 -4
- package/opencrvs-toolkit-2.0.0-rc.2905bb8.tgz +0 -0
- package/package.json +6 -2
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/migrations/v2.0/fix-action-confirmation-handler-type.d.ts +0 -3
- package/dist/migrations/v2.0/fix-action-confirmation-handler-type.d.ts.map +0 -1
- package/opencrvs-toolkit-2.0.0-rc.28e4d24.tgz +0 -0
|
@@ -2132,6 +2132,10 @@ Done. Converted ${convertedCount} config file(s), replaced ${totalReplaced} rout
|
|
|
2132
2132
|
var import_ts_morph11 = require("ts-morph");
|
|
2133
2133
|
var import_path11 = __toESM(require("path"));
|
|
2134
2134
|
|
|
2135
|
+
// ../commons/src/scopes.deprecated.do-not-use.ts
|
|
2136
|
+
var z4 = __toESM(require("zod/v4"));
|
|
2137
|
+
var import_lodash = require("lodash");
|
|
2138
|
+
|
|
2135
2139
|
// ../commons/src/scopes.ts
|
|
2136
2140
|
var z3 = __toESM(require("zod/v4"));
|
|
2137
2141
|
var qs = __toESM(require("qs"));
|
|
@@ -2390,22 +2394,29 @@ var encodeScope = (scope) => {
|
|
|
2390
2394
|
encode: false
|
|
2391
2395
|
});
|
|
2392
2396
|
};
|
|
2393
|
-
var
|
|
2394
|
-
|
|
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, {
|
|
2395
2403
|
ignoreQueryPrefix: true,
|
|
2396
2404
|
comma: true,
|
|
2397
2405
|
allowDots: true
|
|
2398
2406
|
});
|
|
2399
2407
|
const unflattenedScope = unflattenScope(scope);
|
|
2400
|
-
|
|
2408
|
+
const result = Scope2.safeParse(unflattenedScope)?.data;
|
|
2409
|
+
decodedScopeCache.set(encodedScope, result);
|
|
2410
|
+
return result;
|
|
2401
2411
|
};
|
|
2402
2412
|
var DEFAULT_SCOPE_OPTIONS = {
|
|
2403
2413
|
placeOfEvent: JurisdictionFilter.enum.all,
|
|
2404
|
-
accessLevel: JurisdictionFilter.enum.all
|
|
2414
|
+
accessLevel: JurisdictionFilter.enum.all,
|
|
2415
|
+
registeredIn: JurisdictionFilter.enum.all,
|
|
2416
|
+
declaredIn: JurisdictionFilter.enum.all
|
|
2405
2417
|
};
|
|
2406
2418
|
|
|
2407
2419
|
// ../commons/src/scopes.deprecated.do-not-use.ts
|
|
2408
|
-
var z4 = __toESM(require("zod/v4"));
|
|
2409
2420
|
var rawConfigurableScopeRegex = /^([a-zA-Z][a-zA-Z0-9.-]*(?:\.[a-zA-Z0-9.-]+)*)\[((?:\w+=[\w.-]+(?:\|[\w.-]+)*)(?:,[\w]+=[\w.-]+(?:\|[\w.-]+)*)*)\]$/;
|
|
2410
2421
|
var rawConfigurableScope = z4.string().regex(rawConfigurableScopeRegex);
|
|
2411
2422
|
var SearchScope = z4.object({
|
|
@@ -2639,6 +2650,74 @@ var legacyScopeToV2Scope = (v1Scope) => {
|
|
|
2639
2650
|
}
|
|
2640
2651
|
throw new Error(`Unsupported V1 scope type: ${v1Scope}`);
|
|
2641
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
|
+
}
|
|
2642
2721
|
|
|
2643
2722
|
// src/migrations/v2.0/migrate-scopes.ts
|
|
2644
2723
|
var ROLES_FILE_RELATIVE_PATH = "src/data-seeding/roles/roles.ts";
|
|
@@ -2676,57 +2755,65 @@ function resolveLegacyScopeFromElement(element) {
|
|
|
2676
2755
|
}
|
|
2677
2756
|
function migrateScopesArrays(rolesFilePath, project) {
|
|
2678
2757
|
const sourceFile = project.getSourceFile(rolesFilePath);
|
|
2679
|
-
if (!sourceFile)
|
|
2758
|
+
if (!sourceFile) {
|
|
2759
|
+
return { migratedCount: 0, removedCount: 0, mergedCount: 0 };
|
|
2760
|
+
}
|
|
2680
2761
|
let migratedCount = 0;
|
|
2681
2762
|
let removedCount = 0;
|
|
2763
|
+
let mergedCount = 0;
|
|
2682
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);
|
|
2683
2766
|
for (const scopesProp of scopesProperties) {
|
|
2684
2767
|
const initializer = scopesProp.getInitializer();
|
|
2685
2768
|
if (!initializer || !import_ts_morph11.Node.isArrayLiteralExpression(initializer)) continue;
|
|
2686
|
-
const
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2769
|
+
const rawTexts = [];
|
|
2770
|
+
const legacyStrings = [];
|
|
2771
|
+
let anyChange = false;
|
|
2772
|
+
for (const element of initializer.getElements()) {
|
|
2690
2773
|
const scopeKey = resolveScopeKeyFromElementAccess(element);
|
|
2691
2774
|
if (scopeKey && !(scopeKey in SCOPES)) {
|
|
2692
2775
|
console.warn(
|
|
2693
|
-
` [${
|
|
2776
|
+
` [${relPath}] Removing unknown scope reference: SCOPES.${scopeKey}`
|
|
2694
2777
|
);
|
|
2695
|
-
initializer.removeElement(index);
|
|
2696
2778
|
removedCount++;
|
|
2779
|
+
anyChange = true;
|
|
2697
2780
|
continue;
|
|
2698
2781
|
}
|
|
2699
2782
|
const legacyScope = resolveLegacyScopeFromElement(element);
|
|
2700
2783
|
if (!legacyScope) {
|
|
2701
2784
|
console.warn(
|
|
2702
|
-
` [${
|
|
2785
|
+
` [${relPath}] Preserving non-literal scope expression verbatim: ${element.getText()}`
|
|
2703
2786
|
);
|
|
2787
|
+
rawTexts.push(element.getText());
|
|
2704
2788
|
continue;
|
|
2705
2789
|
}
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
console.warn(
|
|
2719
|
-
` [${import_path11.default.relative(process.cwd(), rolesFilePath)}] Could not migrate scope '${legacyScope}': ${error}`
|
|
2720
|
-
);
|
|
2721
|
-
}
|
|
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
|
+
);
|
|
2722
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(", ")}]`);
|
|
2723
2810
|
}
|
|
2724
2811
|
if (removedCount > 0) {
|
|
2725
2812
|
console.log(
|
|
2726
|
-
` Removed ${removedCount} unknown SCOPES reference(s) from '${
|
|
2813
|
+
` Removed ${removedCount} unknown SCOPES reference(s) from '${relPath}'.`
|
|
2727
2814
|
);
|
|
2728
2815
|
}
|
|
2729
|
-
return { migratedCount, removedCount };
|
|
2816
|
+
return { migratedCount, removedCount, mergedCount };
|
|
2730
2817
|
}
|
|
2731
2818
|
function ensureScopesHelpersImport(rolesFilePath, project) {
|
|
2732
2819
|
const sourceFile = project.getSourceFile(rolesFilePath);
|
|
@@ -2861,7 +2948,7 @@ async function main11() {
|
|
|
2861
2948
|
return;
|
|
2862
2949
|
}
|
|
2863
2950
|
const importChanged = ensureScopesHelpersImport(rolesFilePath, project);
|
|
2864
|
-
const { migratedCount, removedCount } = migrateScopesArrays(
|
|
2951
|
+
const { migratedCount, removedCount, mergedCount } = migrateScopesArrays(
|
|
2865
2952
|
rolesFilePath,
|
|
2866
2953
|
project
|
|
2867
2954
|
);
|
|
@@ -2880,7 +2967,7 @@ async function main11() {
|
|
|
2880
2967
|
}
|
|
2881
2968
|
await sourceFile.save();
|
|
2882
2969
|
console.log(
|
|
2883
|
-
`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." : "."}`
|
|
2884
2971
|
);
|
|
2885
2972
|
}
|
|
2886
2973
|
|
|
@@ -3686,6 +3773,10 @@ var ACTION_PROPERTY_NAME2 = "action";
|
|
|
3686
3773
|
var CONDITIONALS_PROPERTY_NAME = "conditionals";
|
|
3687
3774
|
var TYPE_PROPERTY_NAME7 = "type";
|
|
3688
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} }`;
|
|
3689
3780
|
var SUPPORTED_WORKQUEUE_ACTION_TYPES = /* @__PURE__ */ new Set([
|
|
3690
3781
|
"READ",
|
|
3691
3782
|
"DELETE",
|
|
@@ -3733,91 +3824,137 @@ function isUnsupportedActionType(action) {
|
|
|
3733
3824
|
}
|
|
3734
3825
|
return !SUPPORTED_WORKQUEUE_ACTION_TYPES.has(typeName);
|
|
3735
3826
|
}
|
|
3736
|
-
function
|
|
3737
|
-
const
|
|
3738
|
-
|
|
3739
|
-
|
|
3740
|
-
|
|
3741
|
-
|
|
3742
|
-
|
|
3743
|
-
|
|
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
|
+
}
|
|
3744
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) {
|
|
3745
3856
|
const workqueueLabel = getWorkqueueLabel(workqueue);
|
|
3746
|
-
const
|
|
3747
|
-
|
|
3748
|
-
|
|
3749
|
-
|
|
3750
|
-
|
|
3751
|
-
|
|
3752
|
-
|
|
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)`
|
|
3753
3881
|
);
|
|
3754
|
-
|
|
3755
|
-
|
|
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();
|
|
3756
3889
|
console.log(
|
|
3757
|
-
` [${relPath}] Removed
|
|
3890
|
+
` [${relPath}] Removed empty 'actions' from workqueue '${workqueueLabel}'`
|
|
3758
3891
|
);
|
|
3759
|
-
|
|
3760
|
-
|
|
3761
|
-
|
|
3762
|
-
|
|
3763
|
-
|
|
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
|
|
3764
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
|
+
}
|
|
3765
3927
|
}
|
|
3766
3928
|
}
|
|
3767
3929
|
}
|
|
3768
|
-
actionsProperty.remove();
|
|
3769
|
-
console.log(
|
|
3770
|
-
` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' (existing 'action' kept)`
|
|
3771
|
-
);
|
|
3772
|
-
return 1;
|
|
3773
3930
|
}
|
|
3774
|
-
const
|
|
3775
|
-
|
|
3776
|
-
|
|
3777
|
-
|
|
3778
|
-
|
|
3779
|
-
|
|
3780
|
-
|
|
3781
|
-
|
|
3782
|
-
|
|
3783
|
-
}
|
|
3784
|
-
if (actionCandidates.length > 1) {
|
|
3785
|
-
const droppedCount = actionCandidates.length - 1;
|
|
3786
|
-
console.warn(
|
|
3787
|
-
` [${relPath}] Workqueue '${workqueueLabel}' has ${actionCandidates.length} actions; keeping first as 'action' and dropping ${droppedCount} extra action(s)`
|
|
3788
|
-
);
|
|
3789
|
-
}
|
|
3790
|
-
const conditionalsProperty = actionCandidates[0].getProperty(
|
|
3791
|
-
CONDITIONALS_PROPERTY_NAME
|
|
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
|
|
3792
3940
|
);
|
|
3793
|
-
if (
|
|
3794
|
-
|
|
3795
|
-
|
|
3796
|
-
|
|
3797
|
-
|
|
3798
|
-
|
|
3799
|
-
if (isUnsupportedActionType(actionCandidates[0])) {
|
|
3800
|
-
actionsProperty.remove();
|
|
3801
|
-
console.log(
|
|
3802
|
-
` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' because action type is unsupported`
|
|
3803
|
-
);
|
|
3804
|
-
return 1;
|
|
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;
|
|
3805
3947
|
}
|
|
3806
|
-
|
|
3807
|
-
|
|
3808
|
-
|
|
3809
|
-
initializer: firstActionText
|
|
3948
|
+
sourceFile.addImportDeclaration({
|
|
3949
|
+
moduleSpecifier: TOOLKIT_EVENTS_MODULE2,
|
|
3950
|
+
namedImports: [ACTION_TYPE_IMPORT_NAME]
|
|
3810
3951
|
});
|
|
3811
|
-
actionsProperty.remove();
|
|
3812
|
-
console.log(
|
|
3813
|
-
` [${relPath}] Replaced 'actions' with 'action' on workqueue '${workqueueLabel}'`
|
|
3814
|
-
);
|
|
3815
|
-
return 1;
|
|
3816
3952
|
}
|
|
3817
3953
|
function processFile13(filePath, project) {
|
|
3818
3954
|
const sourceFile = project.getSourceFile(filePath);
|
|
3819
3955
|
if (!sourceFile) return 0;
|
|
3820
3956
|
let migratedWorkqueues = 0;
|
|
3957
|
+
let needsActionTypeImport = false;
|
|
3821
3958
|
const relPath = import_path18.default.relative(process.cwd(), filePath);
|
|
3822
3959
|
const callExpressions = sourceFile.getDescendantsOfKind(
|
|
3823
3960
|
import_ts_morph17.SyntaxKind.CallExpression
|
|
@@ -3833,9 +3970,14 @@ function processFile13(filePath, project) {
|
|
|
3833
3970
|
if (!import_ts_morph17.Node.isArrayLiteralExpression(workqueuesArg)) continue;
|
|
3834
3971
|
for (const element of workqueuesArg.getElements()) {
|
|
3835
3972
|
if (!import_ts_morph17.Node.isObjectLiteralExpression(element)) continue;
|
|
3836
|
-
|
|
3973
|
+
const result = migrateWorkqueueActions(element, relPath);
|
|
3974
|
+
if (result.changed) migratedWorkqueues++;
|
|
3975
|
+
if (result.usedReadFallback) needsActionTypeImport = true;
|
|
3837
3976
|
}
|
|
3838
3977
|
}
|
|
3978
|
+
if (needsActionTypeImport) {
|
|
3979
|
+
ensureActionTypeImport(sourceFile);
|
|
3980
|
+
}
|
|
3839
3981
|
return migratedWorkqueues;
|
|
3840
3982
|
}
|
|
3841
3983
|
async function main18() {
|
|
@@ -4170,7 +4312,7 @@ Saved ${handlerRelPath}.`);
|
|
|
4170
4312
|
// src/migrations/v2.0/checkout-upstream-files.ts
|
|
4171
4313
|
var import_child_process = require("child_process");
|
|
4172
4314
|
var UPSTREAM_URL = "https://github.com/opencrvs/opencrvs-countryconfig.git";
|
|
4173
|
-
var UPSTREAM_BRANCH = "
|
|
4315
|
+
var UPSTREAM_BRANCH = "release-v2.0.0";
|
|
4174
4316
|
var TEMP_REMOTE = "opencrvs-upgrade-v19-v20-codemod";
|
|
4175
4317
|
var FILES_TO_CHECKOUT = [
|
|
4176
4318
|
"src/analytics/analytics.ts",
|
|
@@ -4720,9 +4862,13 @@ function gitShowBytes(ref, path24) {
|
|
|
4720
4862
|
return null;
|
|
4721
4863
|
}
|
|
4722
4864
|
}
|
|
4723
|
-
async function main25(
|
|
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(", ");
|
|
4724
4870
|
console.log(
|
|
4725
|
-
`Merging
|
|
4871
|
+
`Merging ${scopeLabel} from ${UPSTREAM_URL}@${UPSTREAM_BRANCH} (base: ${BASE_BRANCH})...
|
|
4726
4872
|
`
|
|
4727
4873
|
);
|
|
4728
4874
|
assertIsGitRepo();
|
|
@@ -4737,20 +4883,12 @@ async function main25() {
|
|
|
4737
4883
|
const ref = `${TEMP_REMOTE2}/${UPSTREAM_BRANCH}`;
|
|
4738
4884
|
const baseRef = `${TEMP_REMOTE2}/${BASE_BRANCH}`;
|
|
4739
4885
|
const upstreamFiles = runGit(
|
|
4740
|
-
[
|
|
4741
|
-
"ls-tree",
|
|
4742
|
-
"-r",
|
|
4743
|
-
"--name-only",
|
|
4744
|
-
"-z",
|
|
4745
|
-
ref,
|
|
4746
|
-
"--",
|
|
4747
|
-
`${INFRASTRUCTURE_DIR}/`
|
|
4748
|
-
],
|
|
4886
|
+
["ls-tree", "-r", "--name-only", "-z", ref, "--", ...pathspecs],
|
|
4749
4887
|
{ silent: true }
|
|
4750
4888
|
).split("\0").filter(Boolean);
|
|
4751
4889
|
if (upstreamFiles.length === 0) {
|
|
4752
4890
|
console.log(
|
|
4753
|
-
` No files found under
|
|
4891
|
+
` No files found under ${scopeLabel} on ${ref}. Nothing to merge.`
|
|
4754
4892
|
);
|
|
4755
4893
|
return;
|
|
4756
4894
|
}
|
|
@@ -4825,7 +4963,9 @@ async function main25() {
|
|
|
4825
4963
|
var import_fs6 = require("fs");
|
|
4826
4964
|
var import_path25 = require("path");
|
|
4827
4965
|
var INFRASTRUCTURE_DIR2 = "infrastructure";
|
|
4828
|
-
async function main26(
|
|
4966
|
+
async function main26({
|
|
4967
|
+
keep = []
|
|
4968
|
+
} = {}) {
|
|
4829
4969
|
const fullPath = (0, import_path25.join)(process.cwd(), INFRASTRUCTURE_DIR2);
|
|
4830
4970
|
if (!(0, import_fs6.existsSync)(fullPath)) {
|
|
4831
4971
|
console.log(
|
|
@@ -4833,31 +4973,70 @@ async function main26() {
|
|
|
4833
4973
|
);
|
|
4834
4974
|
return;
|
|
4835
4975
|
}
|
|
4836
|
-
console.log(`Deleting '${INFRASTRUCTURE_DIR2}/'...
|
|
4837
|
-
`);
|
|
4838
4976
|
assertIsGitRepo();
|
|
4839
|
-
|
|
4840
|
-
|
|
4841
|
-
|
|
4842
|
-
|
|
4843
|
-
|
|
4844
|
-
|
|
4845
|
-
console.log(
|
|
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
|
+
}
|
|
4992
|
+
console.log(
|
|
4993
|
+
`
|
|
4994
|
+
Done. Review the staged deletion with: git diff --cached -- '${INFRASTRUCTURE_DIR2}/'`
|
|
4995
|
+
);
|
|
4996
|
+
return;
|
|
4997
|
+
}
|
|
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
|
+
);
|
|
4846
5025
|
}
|
|
4847
5026
|
console.log(
|
|
4848
5027
|
`
|
|
4849
|
-
Done. Review the staged
|
|
5028
|
+
Done. Deleted ${deleted} top-level entr${deleted === 1 ? "y" : "ies"}. Review the staged deletions with: git diff --cached -- '${INFRASTRUCTURE_DIR2}/'`
|
|
4850
5029
|
);
|
|
4851
5030
|
}
|
|
4852
5031
|
|
|
4853
|
-
// src/migrations/v2.0/fix-
|
|
5032
|
+
// src/migrations/v2.0/fix-accept-requested-registration-function-type.ts
|
|
4854
5033
|
var import_ts_morph22 = require("ts-morph");
|
|
4855
5034
|
var import_path26 = __toESM(require("path"));
|
|
4856
5035
|
var TARGET_FUNCTION_NAME = "acceptRequestedRegistration";
|
|
4857
5036
|
var ACTION_PARAMETER_NAME = "action";
|
|
4858
5037
|
var OLD_TYPE = "ActionInput";
|
|
4859
5038
|
var NEW_TYPE = "Extract<ActionInput, { type?: 'REGISTER' }>";
|
|
4860
|
-
function
|
|
5039
|
+
function isAcceptRequestedRegistrationParameter(parameter) {
|
|
4861
5040
|
const functionDeclaration = parameter.getFirstAncestorByKind(
|
|
4862
5041
|
import_ts_morph22.SyntaxKind.FunctionDeclaration
|
|
4863
5042
|
);
|
|
@@ -4876,30 +5055,30 @@ function processFile14(filePath, project) {
|
|
|
4876
5055
|
const sourceFile = project.getSourceFile(filePath);
|
|
4877
5056
|
if (!sourceFile) return 0;
|
|
4878
5057
|
let updatedCount = 0;
|
|
4879
|
-
const
|
|
4880
|
-
|
|
5058
|
+
for (const parameter of sourceFile.getDescendantsOfKind(
|
|
5059
|
+
import_ts_morph22.SyntaxKind.Parameter
|
|
5060
|
+
)) {
|
|
4881
5061
|
if (parameter.getName() !== ACTION_PARAMETER_NAME) {
|
|
4882
5062
|
continue;
|
|
4883
5063
|
}
|
|
4884
|
-
if (!
|
|
5064
|
+
if (!isAcceptRequestedRegistrationParameter(parameter)) {
|
|
4885
5065
|
continue;
|
|
4886
5066
|
}
|
|
4887
5067
|
const typeNode = parameter.getTypeNode();
|
|
4888
|
-
if (!typeNode)
|
|
4889
|
-
if (typeNode.getText() !== OLD_TYPE) {
|
|
5068
|
+
if (!typeNode || typeNode.getText() !== OLD_TYPE) {
|
|
4890
5069
|
continue;
|
|
4891
5070
|
}
|
|
4892
5071
|
parameter.setType(NEW_TYPE);
|
|
4893
5072
|
updatedCount++;
|
|
4894
5073
|
console.log(
|
|
4895
|
-
` [${import_path26.default.relative(process.cwd(), filePath)}] Updated '${ACTION_PARAMETER_NAME}'
|
|
5074
|
+
` [${import_path26.default.relative(process.cwd(), filePath)}] Updated '${ACTION_PARAMETER_NAME}' in ${TARGET_FUNCTION_NAME} to ${NEW_TYPE}`
|
|
4896
5075
|
);
|
|
4897
5076
|
}
|
|
4898
5077
|
return updatedCount;
|
|
4899
5078
|
}
|
|
4900
5079
|
async function main27() {
|
|
4901
5080
|
const srcDir = import_path26.default.join(process.cwd(), "src");
|
|
4902
|
-
console.log(`Scanning for
|
|
5081
|
+
console.log(`Scanning for ${TARGET_FUNCTION_NAME} in: ${srcDir}
|
|
4903
5082
|
`);
|
|
4904
5083
|
const project = new import_ts_morph22.Project({
|
|
4905
5084
|
tsConfigFilePath: import_path26.default.resolve(srcDir, "../tsconfig.json"),
|
|
@@ -4921,7 +5100,7 @@ async function main27() {
|
|
|
4921
5100
|
}
|
|
4922
5101
|
if (modifiedFiles.length === 0) {
|
|
4923
5102
|
console.log(
|
|
4924
|
-
`No '${ACTION_PARAMETER_NAME}: ${OLD_TYPE}' parameter
|
|
5103
|
+
`No '${ACTION_PARAMETER_NAME}: ${OLD_TYPE}' parameter in ${TARGET_FUNCTION_NAME} found. Nothing to do.`
|
|
4925
5104
|
);
|
|
4926
5105
|
return;
|
|
4927
5106
|
}
|
|
@@ -4934,11 +5113,12 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
4934
5113
|
}
|
|
4935
5114
|
console.log(
|
|
4936
5115
|
`
|
|
4937
|
-
Done. Updated ${totalUpdated}
|
|
5116
|
+
Done. Updated ${totalUpdated} parameter type annotation(s) in ${TARGET_FUNCTION_NAME}.`
|
|
4938
5117
|
);
|
|
4939
5118
|
}
|
|
4940
5119
|
|
|
4941
5120
|
// src/migrations/v2.0/index.ts
|
|
5121
|
+
var NON_SWARM_INFRA_SUBDIRS = ["postgres", "metabase"];
|
|
4942
5122
|
async function runUpgrade(dockerSwarm) {
|
|
4943
5123
|
await main18();
|
|
4944
5124
|
await main();
|
|
@@ -4960,14 +5140,15 @@ async function runUpgrade(dockerSwarm) {
|
|
|
4960
5140
|
await main19();
|
|
4961
5141
|
await main20();
|
|
4962
5142
|
await main21();
|
|
4963
|
-
await main27();
|
|
4964
5143
|
await main22();
|
|
4965
5144
|
await main23();
|
|
4966
5145
|
await main24();
|
|
5146
|
+
await main27();
|
|
4967
5147
|
await main17();
|
|
4968
5148
|
if (dockerSwarm) {
|
|
4969
5149
|
await main25();
|
|
4970
5150
|
} else {
|
|
4971
|
-
await main26();
|
|
5151
|
+
await main26({ keep: NON_SWARM_INFRA_SUBDIRS });
|
|
5152
|
+
await main25({ subdirs: NON_SWARM_INFRA_SUBDIRS });
|
|
4972
5153
|
}
|
|
4973
5154
|
}
|