@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
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"));
|
|
@@ -2378,22 +2382,29 @@ var encodeScope = (scope) => {
|
|
|
2378
2382
|
encode: false
|
|
2379
2383
|
});
|
|
2380
2384
|
};
|
|
2381
|
-
var
|
|
2382
|
-
|
|
2385
|
+
var decodedScopeCache = /* @__PURE__ */ new Map();
|
|
2386
|
+
var decodeScope = (encodedScope) => {
|
|
2387
|
+
if (decodedScopeCache.has(encodedScope)) {
|
|
2388
|
+
return decodedScopeCache.get(encodedScope);
|
|
2389
|
+
}
|
|
2390
|
+
const scope = qs.parse(encodedScope, {
|
|
2383
2391
|
ignoreQueryPrefix: true,
|
|
2384
2392
|
comma: true,
|
|
2385
2393
|
allowDots: true
|
|
2386
2394
|
});
|
|
2387
2395
|
const unflattenedScope = unflattenScope(scope);
|
|
2388
|
-
|
|
2396
|
+
const result = Scope2.safeParse(unflattenedScope)?.data;
|
|
2397
|
+
decodedScopeCache.set(encodedScope, result);
|
|
2398
|
+
return result;
|
|
2389
2399
|
};
|
|
2390
2400
|
var DEFAULT_SCOPE_OPTIONS = {
|
|
2391
2401
|
placeOfEvent: JurisdictionFilter.enum.all,
|
|
2392
|
-
accessLevel: JurisdictionFilter.enum.all
|
|
2402
|
+
accessLevel: JurisdictionFilter.enum.all,
|
|
2403
|
+
registeredIn: JurisdictionFilter.enum.all,
|
|
2404
|
+
declaredIn: JurisdictionFilter.enum.all
|
|
2393
2405
|
};
|
|
2394
2406
|
|
|
2395
2407
|
// ../commons/src/scopes.deprecated.do-not-use.ts
|
|
2396
|
-
var z4 = __toESM(require("zod/v4"));
|
|
2397
2408
|
var rawConfigurableScopeRegex = /^([a-zA-Z][a-zA-Z0-9.-]*(?:\.[a-zA-Z0-9.-]+)*)\[((?:\w+=[\w.-]+(?:\|[\w.-]+)*)(?:,[\w]+=[\w.-]+(?:\|[\w.-]+)*)*)\]$/;
|
|
2398
2409
|
var rawConfigurableScope = z4.string().regex(rawConfigurableScopeRegex);
|
|
2399
2410
|
var SearchScope = z4.object({
|
|
@@ -2627,6 +2638,74 @@ var legacyScopeToV2Scope = (v1Scope) => {
|
|
|
2627
2638
|
}
|
|
2628
2639
|
throw new Error(`Unsupported V1 scope type: ${v1Scope}`);
|
|
2629
2640
|
};
|
|
2641
|
+
var MERGEABLE_USER_SCOPE_TYPES = ["user.create", "user.edit"];
|
|
2642
|
+
function isMergeableUserScopeType(type) {
|
|
2643
|
+
return MERGEABLE_USER_SCOPE_TYPES.includes(type);
|
|
2644
|
+
}
|
|
2645
|
+
function decodeLegacyScope(legacy) {
|
|
2646
|
+
const encoded = legacyScopeToV2Scope(legacy);
|
|
2647
|
+
const scope = decodeScope(encoded);
|
|
2648
|
+
if (!scope) {
|
|
2649
|
+
throw new Error(
|
|
2650
|
+
`Could not decode migrated scope from legacy '${legacy}' (encoded: '${encoded}').`
|
|
2651
|
+
);
|
|
2652
|
+
}
|
|
2653
|
+
return { legacy, scope };
|
|
2654
|
+
}
|
|
2655
|
+
function groupByType(entries) {
|
|
2656
|
+
return entries.reduce(
|
|
2657
|
+
(groups, entry) => ({
|
|
2658
|
+
...groups,
|
|
2659
|
+
[entry.scope.type]: [...groups[entry.scope.type] ?? [], entry]
|
|
2660
|
+
}),
|
|
2661
|
+
{}
|
|
2662
|
+
);
|
|
2663
|
+
}
|
|
2664
|
+
function deduplicateEntries(entries) {
|
|
2665
|
+
return entries.filter(
|
|
2666
|
+
(entry, index) => entries.findIndex((e) => (0, import_lodash.isEqual)(e.scope, entry.scope)) === index
|
|
2667
|
+
);
|
|
2668
|
+
}
|
|
2669
|
+
function mergeEntries(type, entries) {
|
|
2670
|
+
const optionsList = entries.map(
|
|
2671
|
+
(e) => "options" in e.scope && e.scope.options ? e.scope.options : {}
|
|
2672
|
+
);
|
|
2673
|
+
const allKeys = optionsList.flatMap(
|
|
2674
|
+
(opts) => Object.keys(opts).filter((k) => opts[k] !== void 0)
|
|
2675
|
+
);
|
|
2676
|
+
const conflictKey = allKeys.find((key, i) => allKeys.indexOf(key) !== i);
|
|
2677
|
+
if (conflictKey) {
|
|
2678
|
+
const conflicting = entries.filter(
|
|
2679
|
+
(e) => conflictKey in ("options" in e.scope && e.scope.options || {})
|
|
2680
|
+
).map((e) => JSON.stringify(e.legacy));
|
|
2681
|
+
throw new Error(
|
|
2682
|
+
`Cannot auto-merge two '${type}' scopes that both define '${conflictKey}'. Conflicting legacy scopes: [${conflicting.join(", ")}]. Resolve manually in roles.ts and re-run.`
|
|
2683
|
+
);
|
|
2684
|
+
}
|
|
2685
|
+
const mergedOptions = Object.assign({}, ...optionsList);
|
|
2686
|
+
const merged = Object.keys(mergedOptions).length > 0 ? { type, options: mergedOptions } : { type };
|
|
2687
|
+
const parsed = Scope2.safeParse(merged);
|
|
2688
|
+
if (!parsed.success) {
|
|
2689
|
+
throw new Error(
|
|
2690
|
+
`Merged '${type}' scope failed schema validation: ${parsed.error.message}. Legacy scopes: [${entries.map((e) => JSON.stringify(e.legacy)).join(", ")}].`
|
|
2691
|
+
);
|
|
2692
|
+
}
|
|
2693
|
+
return parsed.data;
|
|
2694
|
+
}
|
|
2695
|
+
function migrateLegacyScopesArrayToV2Scopes(legacyScopes) {
|
|
2696
|
+
const groups = groupByType(legacyScopes.map(decodeLegacyScope));
|
|
2697
|
+
return Object.entries(groups).flatMap(([type, entries]) => {
|
|
2698
|
+
const deduped = deduplicateEntries(entries);
|
|
2699
|
+
if (deduped.length <= 1) return deduped.map((e) => e.scope);
|
|
2700
|
+
if (!isMergeableUserScopeType(type)) {
|
|
2701
|
+
console.warn(
|
|
2702
|
+
`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.`
|
|
2703
|
+
);
|
|
2704
|
+
return deduped.map((e) => e.scope);
|
|
2705
|
+
}
|
|
2706
|
+
return [mergeEntries(type, deduped)];
|
|
2707
|
+
});
|
|
2708
|
+
}
|
|
2630
2709
|
|
|
2631
2710
|
// src/migrations/v2.0/migrate-scopes.ts
|
|
2632
2711
|
var ROLES_FILE_RELATIVE_PATH = "src/data-seeding/roles/roles.ts";
|
|
@@ -2664,57 +2743,65 @@ function resolveLegacyScopeFromElement(element) {
|
|
|
2664
2743
|
}
|
|
2665
2744
|
function migrateScopesArrays(rolesFilePath, project) {
|
|
2666
2745
|
const sourceFile = project.getSourceFile(rolesFilePath);
|
|
2667
|
-
if (!sourceFile)
|
|
2746
|
+
if (!sourceFile) {
|
|
2747
|
+
return { migratedCount: 0, removedCount: 0, mergedCount: 0 };
|
|
2748
|
+
}
|
|
2668
2749
|
let migratedCount = 0;
|
|
2669
2750
|
let removedCount = 0;
|
|
2751
|
+
let mergedCount = 0;
|
|
2670
2752
|
const scopesProperties = sourceFile.getDescendantsOfKind(import_ts_morph11.SyntaxKind.PropertyAssignment).filter((prop) => prop.getName() === SCOPES_PROPERTY_NAME);
|
|
2753
|
+
const relPath = import_path11.default.relative(process.cwd(), rolesFilePath);
|
|
2671
2754
|
for (const scopesProp of scopesProperties) {
|
|
2672
2755
|
const initializer = scopesProp.getInitializer();
|
|
2673
2756
|
if (!initializer || !import_ts_morph11.Node.isArrayLiteralExpression(initializer)) continue;
|
|
2674
|
-
const
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2757
|
+
const rawTexts = [];
|
|
2758
|
+
const legacyStrings = [];
|
|
2759
|
+
let anyChange = false;
|
|
2760
|
+
for (const element of initializer.getElements()) {
|
|
2678
2761
|
const scopeKey = resolveScopeKeyFromElementAccess(element);
|
|
2679
2762
|
if (scopeKey && !(scopeKey in SCOPES)) {
|
|
2680
2763
|
console.warn(
|
|
2681
|
-
` [${
|
|
2764
|
+
` [${relPath}] Removing unknown scope reference: SCOPES.${scopeKey}`
|
|
2682
2765
|
);
|
|
2683
|
-
initializer.removeElement(index);
|
|
2684
2766
|
removedCount++;
|
|
2767
|
+
anyChange = true;
|
|
2685
2768
|
continue;
|
|
2686
2769
|
}
|
|
2687
2770
|
const legacyScope = resolveLegacyScopeFromElement(element);
|
|
2688
2771
|
if (!legacyScope) {
|
|
2689
2772
|
console.warn(
|
|
2690
|
-
` [${
|
|
2773
|
+
` [${relPath}] Preserving non-literal scope expression verbatim: ${element.getText()}`
|
|
2691
2774
|
);
|
|
2775
|
+
rawTexts.push(element.getText());
|
|
2692
2776
|
continue;
|
|
2693
2777
|
}
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
console.warn(
|
|
2707
|
-
` [${import_path11.default.relative(process.cwd(), rolesFilePath)}] Could not migrate scope '${legacyScope}': ${error}`
|
|
2708
|
-
);
|
|
2709
|
-
}
|
|
2778
|
+
legacyStrings.push(legacyScope);
|
|
2779
|
+
anyChange = true;
|
|
2780
|
+
}
|
|
2781
|
+
if (!anyChange) continue;
|
|
2782
|
+
let mergedScopes;
|
|
2783
|
+
try {
|
|
2784
|
+
mergedScopes = migrateLegacyScopesArrayToV2Scopes(legacyStrings);
|
|
2785
|
+
} catch (error) {
|
|
2786
|
+
throw new Error(
|
|
2787
|
+
`[${relPath}] Failed to migrate scopes for role: ${error instanceof Error ? error.message : String(error)}`,
|
|
2788
|
+
{ cause: error }
|
|
2789
|
+
);
|
|
2710
2790
|
}
|
|
2791
|
+
migratedCount += legacyStrings.length;
|
|
2792
|
+
mergedCount += legacyStrings.length - mergedScopes.length;
|
|
2793
|
+
const outputElements = [
|
|
2794
|
+
...rawTexts,
|
|
2795
|
+
...mergedScopes.map((s) => JSON.stringify(s))
|
|
2796
|
+
];
|
|
2797
|
+
scopesProp.setInitializer(`[${outputElements.join(", ")}]`);
|
|
2711
2798
|
}
|
|
2712
2799
|
if (removedCount > 0) {
|
|
2713
2800
|
console.log(
|
|
2714
|
-
` Removed ${removedCount} unknown SCOPES reference(s) from '${
|
|
2801
|
+
` Removed ${removedCount} unknown SCOPES reference(s) from '${relPath}'.`
|
|
2715
2802
|
);
|
|
2716
2803
|
}
|
|
2717
|
-
return { migratedCount, removedCount };
|
|
2804
|
+
return { migratedCount, removedCount, mergedCount };
|
|
2718
2805
|
}
|
|
2719
2806
|
function ensureScopesHelpersImport(rolesFilePath, project) {
|
|
2720
2807
|
const sourceFile = project.getSourceFile(rolesFilePath);
|
|
@@ -2849,7 +2936,7 @@ async function main11() {
|
|
|
2849
2936
|
return;
|
|
2850
2937
|
}
|
|
2851
2938
|
const importChanged = ensureScopesHelpersImport(rolesFilePath, project);
|
|
2852
|
-
const { migratedCount, removedCount } = migrateScopesArrays(
|
|
2939
|
+
const { migratedCount, removedCount, mergedCount } = migrateScopesArrays(
|
|
2853
2940
|
rolesFilePath,
|
|
2854
2941
|
project
|
|
2855
2942
|
);
|
|
@@ -2868,7 +2955,7 @@ async function main11() {
|
|
|
2868
2955
|
}
|
|
2869
2956
|
await sourceFile.save();
|
|
2870
2957
|
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." : "."}`
|
|
2958
|
+
`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
2959
|
);
|
|
2873
2960
|
}
|
|
2874
2961
|
|
|
@@ -3674,6 +3761,10 @@ var ACTION_PROPERTY_NAME2 = "action";
|
|
|
3674
3761
|
var CONDITIONALS_PROPERTY_NAME = "conditionals";
|
|
3675
3762
|
var TYPE_PROPERTY_NAME7 = "type";
|
|
3676
3763
|
var SLUG_PROPERTY_NAME = "slug";
|
|
3764
|
+
var READ_ACTION_TYPE = "READ";
|
|
3765
|
+
var ACTION_TYPE_IMPORT_NAME = "ActionType";
|
|
3766
|
+
var TOOLKIT_EVENTS_MODULE2 = "@opencrvs/toolkit/events";
|
|
3767
|
+
var READ_ACTION_FALLBACK_INITIALIZER = `{ type: ${ACTION_TYPE_IMPORT_NAME}.${READ_ACTION_TYPE} }`;
|
|
3677
3768
|
var SUPPORTED_WORKQUEUE_ACTION_TYPES = /* @__PURE__ */ new Set([
|
|
3678
3769
|
"READ",
|
|
3679
3770
|
"DELETE",
|
|
@@ -3721,91 +3812,137 @@ function isUnsupportedActionType(action) {
|
|
|
3721
3812
|
}
|
|
3722
3813
|
return !SUPPORTED_WORKQUEUE_ACTION_TYPES.has(typeName);
|
|
3723
3814
|
}
|
|
3724
|
-
function
|
|
3725
|
-
const
|
|
3726
|
-
|
|
3727
|
-
|
|
3728
|
-
|
|
3729
|
-
|
|
3730
|
-
|
|
3731
|
-
|
|
3815
|
+
function ensureValidAction(workqueue, relPath) {
|
|
3816
|
+
const workqueueLabel = getWorkqueueLabel(workqueue);
|
|
3817
|
+
const actionProperty = workqueue.getProperty(ACTION_PROPERTY_NAME2);
|
|
3818
|
+
if (actionProperty && import_ts_morph17.Node.isPropertyAssignment(actionProperty)) {
|
|
3819
|
+
const initializer = actionProperty.getInitializer();
|
|
3820
|
+
if (initializer && import_ts_morph17.Node.isObjectLiteralExpression(initializer)) {
|
|
3821
|
+
if (!isUnsupportedActionType(initializer)) {
|
|
3822
|
+
return { changed: false, usedReadFallback: false };
|
|
3823
|
+
}
|
|
3824
|
+
actionProperty.set({
|
|
3825
|
+
name: ACTION_PROPERTY_NAME2,
|
|
3826
|
+
initializer: READ_ACTION_FALLBACK_INITIALIZER
|
|
3827
|
+
});
|
|
3828
|
+
console.log(
|
|
3829
|
+
` [${relPath}] Replaced unsupported 'action' type with '${ACTION_TYPE_IMPORT_NAME}.${READ_ACTION_TYPE}' on workqueue '${workqueueLabel}'`
|
|
3830
|
+
);
|
|
3831
|
+
return { changed: true, usedReadFallback: true };
|
|
3832
|
+
}
|
|
3732
3833
|
}
|
|
3834
|
+
workqueue.addPropertyAssignment({
|
|
3835
|
+
name: ACTION_PROPERTY_NAME2,
|
|
3836
|
+
initializer: READ_ACTION_FALLBACK_INITIALIZER
|
|
3837
|
+
});
|
|
3838
|
+
console.log(
|
|
3839
|
+
` [${relPath}] Added default 'action: ${READ_ACTION_FALLBACK_INITIALIZER}' to workqueue '${workqueueLabel}'`
|
|
3840
|
+
);
|
|
3841
|
+
return { changed: true, usedReadFallback: true };
|
|
3842
|
+
}
|
|
3843
|
+
function migrateWorkqueueActions(workqueue, relPath) {
|
|
3733
3844
|
const workqueueLabel = getWorkqueueLabel(workqueue);
|
|
3734
|
-
const
|
|
3735
|
-
|
|
3736
|
-
|
|
3737
|
-
|
|
3738
|
-
|
|
3739
|
-
|
|
3740
|
-
|
|
3845
|
+
const actionsProperty = workqueue.getProperty(ACTIONS_PROPERTY_NAME5);
|
|
3846
|
+
let actionsArrayMigrated = false;
|
|
3847
|
+
if (actionsProperty && import_ts_morph17.Node.isPropertyAssignment(actionsProperty)) {
|
|
3848
|
+
const actionsInitializer = actionsProperty.getInitializer();
|
|
3849
|
+
if (actionsInitializer && import_ts_morph17.Node.isArrayLiteralExpression(actionsInitializer)) {
|
|
3850
|
+
const existingActionProperty = workqueue.getProperty(ACTION_PROPERTY_NAME2);
|
|
3851
|
+
if (existingActionProperty) {
|
|
3852
|
+
if (import_ts_morph17.Node.isPropertyAssignment(existingActionProperty)) {
|
|
3853
|
+
const existingActionInitializer = existingActionProperty.getInitializer();
|
|
3854
|
+
if (existingActionInitializer && import_ts_morph17.Node.isObjectLiteralExpression(existingActionInitializer)) {
|
|
3855
|
+
const conditionalsProperty = existingActionInitializer.getProperty(
|
|
3856
|
+
CONDITIONALS_PROPERTY_NAME
|
|
3857
|
+
);
|
|
3858
|
+
if (conditionalsProperty) {
|
|
3859
|
+
conditionalsProperty.remove();
|
|
3860
|
+
console.log(
|
|
3861
|
+
` [${relPath}] Removed deprecated 'conditionals' from 'action' on workqueue '${workqueueLabel}'`
|
|
3862
|
+
);
|
|
3863
|
+
}
|
|
3864
|
+
}
|
|
3865
|
+
}
|
|
3866
|
+
actionsProperty.remove();
|
|
3867
|
+
console.log(
|
|
3868
|
+
` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' (existing 'action' kept)`
|
|
3741
3869
|
);
|
|
3742
|
-
|
|
3743
|
-
|
|
3870
|
+
actionsArrayMigrated = true;
|
|
3871
|
+
} else {
|
|
3872
|
+
const actionCandidates = actionsInitializer.getElements().filter(
|
|
3873
|
+
(element) => import_ts_morph17.Node.isObjectLiteralExpression(element)
|
|
3874
|
+
);
|
|
3875
|
+
if (actionCandidates.length === 0) {
|
|
3876
|
+
actionsProperty.remove();
|
|
3744
3877
|
console.log(
|
|
3745
|
-
` [${relPath}] Removed
|
|
3878
|
+
` [${relPath}] Removed empty 'actions' from workqueue '${workqueueLabel}'`
|
|
3746
3879
|
);
|
|
3747
|
-
|
|
3748
|
-
|
|
3749
|
-
|
|
3750
|
-
|
|
3751
|
-
|
|
3880
|
+
actionsArrayMigrated = true;
|
|
3881
|
+
} else {
|
|
3882
|
+
if (actionCandidates.length > 1) {
|
|
3883
|
+
const droppedCount = actionCandidates.length - 1;
|
|
3884
|
+
console.warn(
|
|
3885
|
+
` [${relPath}] Workqueue '${workqueueLabel}' has ${actionCandidates.length} actions; keeping first as 'action' and dropping ${droppedCount} extra action(s)`
|
|
3886
|
+
);
|
|
3887
|
+
}
|
|
3888
|
+
const conditionalsProperty = actionCandidates[0].getProperty(
|
|
3889
|
+
CONDITIONALS_PROPERTY_NAME
|
|
3752
3890
|
);
|
|
3891
|
+
if (conditionalsProperty) {
|
|
3892
|
+
conditionalsProperty.remove();
|
|
3893
|
+
console.log(
|
|
3894
|
+
` [${relPath}] Removed deprecated 'conditionals' from migrated 'action' on workqueue '${workqueueLabel}'`
|
|
3895
|
+
);
|
|
3896
|
+
}
|
|
3897
|
+
if (isUnsupportedActionType(actionCandidates[0])) {
|
|
3898
|
+
actionsProperty.remove();
|
|
3899
|
+
console.log(
|
|
3900
|
+
` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' because action type is unsupported`
|
|
3901
|
+
);
|
|
3902
|
+
actionsArrayMigrated = true;
|
|
3903
|
+
} else {
|
|
3904
|
+
const firstActionText = actionCandidates[0].getText();
|
|
3905
|
+
workqueue.addPropertyAssignment({
|
|
3906
|
+
name: ACTION_PROPERTY_NAME2,
|
|
3907
|
+
initializer: firstActionText
|
|
3908
|
+
});
|
|
3909
|
+
actionsProperty.remove();
|
|
3910
|
+
console.log(
|
|
3911
|
+
` [${relPath}] Replaced 'actions' with 'action' on workqueue '${workqueueLabel}'`
|
|
3912
|
+
);
|
|
3913
|
+
actionsArrayMigrated = true;
|
|
3914
|
+
}
|
|
3753
3915
|
}
|
|
3754
3916
|
}
|
|
3755
3917
|
}
|
|
3756
|
-
actionsProperty.remove();
|
|
3757
|
-
console.log(
|
|
3758
|
-
` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' (existing 'action' kept)`
|
|
3759
|
-
);
|
|
3760
|
-
return 1;
|
|
3761
3918
|
}
|
|
3762
|
-
const
|
|
3763
|
-
|
|
3764
|
-
|
|
3765
|
-
|
|
3766
|
-
|
|
3767
|
-
|
|
3768
|
-
|
|
3769
|
-
|
|
3770
|
-
|
|
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
|
-
}
|
|
3778
|
-
const conditionalsProperty = actionCandidates[0].getProperty(
|
|
3779
|
-
CONDITIONALS_PROPERTY_NAME
|
|
3919
|
+
const fallback = ensureValidAction(workqueue, relPath);
|
|
3920
|
+
return {
|
|
3921
|
+
changed: actionsArrayMigrated || fallback.changed,
|
|
3922
|
+
usedReadFallback: fallback.usedReadFallback
|
|
3923
|
+
};
|
|
3924
|
+
}
|
|
3925
|
+
function ensureActionTypeImport(sourceFile) {
|
|
3926
|
+
const existingImport = sourceFile.getImportDeclaration(
|
|
3927
|
+
(decl) => decl.getModuleSpecifierValue() === TOOLKIT_EVENTS_MODULE2
|
|
3780
3928
|
);
|
|
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;
|
|
3929
|
+
if (existingImport) {
|
|
3930
|
+
const alreadyImported = existingImport.getNamedImports().some((ni) => ni.getName() === ACTION_TYPE_IMPORT_NAME);
|
|
3931
|
+
if (!alreadyImported) {
|
|
3932
|
+
existingImport.addNamedImport(ACTION_TYPE_IMPORT_NAME);
|
|
3933
|
+
}
|
|
3934
|
+
return;
|
|
3793
3935
|
}
|
|
3794
|
-
|
|
3795
|
-
|
|
3796
|
-
|
|
3797
|
-
initializer: firstActionText
|
|
3936
|
+
sourceFile.addImportDeclaration({
|
|
3937
|
+
moduleSpecifier: TOOLKIT_EVENTS_MODULE2,
|
|
3938
|
+
namedImports: [ACTION_TYPE_IMPORT_NAME]
|
|
3798
3939
|
});
|
|
3799
|
-
actionsProperty.remove();
|
|
3800
|
-
console.log(
|
|
3801
|
-
` [${relPath}] Replaced 'actions' with 'action' on workqueue '${workqueueLabel}'`
|
|
3802
|
-
);
|
|
3803
|
-
return 1;
|
|
3804
3940
|
}
|
|
3805
3941
|
function processFile13(filePath, project) {
|
|
3806
3942
|
const sourceFile = project.getSourceFile(filePath);
|
|
3807
3943
|
if (!sourceFile) return 0;
|
|
3808
3944
|
let migratedWorkqueues = 0;
|
|
3945
|
+
let needsActionTypeImport = false;
|
|
3809
3946
|
const relPath = import_path18.default.relative(process.cwd(), filePath);
|
|
3810
3947
|
const callExpressions = sourceFile.getDescendantsOfKind(
|
|
3811
3948
|
import_ts_morph17.SyntaxKind.CallExpression
|
|
@@ -3821,9 +3958,14 @@ function processFile13(filePath, project) {
|
|
|
3821
3958
|
if (!import_ts_morph17.Node.isArrayLiteralExpression(workqueuesArg)) continue;
|
|
3822
3959
|
for (const element of workqueuesArg.getElements()) {
|
|
3823
3960
|
if (!import_ts_morph17.Node.isObjectLiteralExpression(element)) continue;
|
|
3824
|
-
|
|
3961
|
+
const result = migrateWorkqueueActions(element, relPath);
|
|
3962
|
+
if (result.changed) migratedWorkqueues++;
|
|
3963
|
+
if (result.usedReadFallback) needsActionTypeImport = true;
|
|
3825
3964
|
}
|
|
3826
3965
|
}
|
|
3966
|
+
if (needsActionTypeImport) {
|
|
3967
|
+
ensureActionTypeImport(sourceFile);
|
|
3968
|
+
}
|
|
3827
3969
|
return migratedWorkqueues;
|
|
3828
3970
|
}
|
|
3829
3971
|
async function main18() {
|
|
@@ -4158,7 +4300,7 @@ Saved ${handlerRelPath}.`);
|
|
|
4158
4300
|
// src/migrations/v2.0/checkout-upstream-files.ts
|
|
4159
4301
|
var import_child_process = require("child_process");
|
|
4160
4302
|
var UPSTREAM_URL = "https://github.com/opencrvs/opencrvs-countryconfig.git";
|
|
4161
|
-
var UPSTREAM_BRANCH = "
|
|
4303
|
+
var UPSTREAM_BRANCH = "release-v2.0.0";
|
|
4162
4304
|
var TEMP_REMOTE = "opencrvs-upgrade-v19-v20-codemod";
|
|
4163
4305
|
var FILES_TO_CHECKOUT = [
|
|
4164
4306
|
"src/analytics/analytics.ts",
|
|
@@ -4708,9 +4850,13 @@ function gitShowBytes(ref, path24) {
|
|
|
4708
4850
|
return null;
|
|
4709
4851
|
}
|
|
4710
4852
|
}
|
|
4711
|
-
async function main25(
|
|
4853
|
+
async function main25({
|
|
4854
|
+
subdirs = []
|
|
4855
|
+
} = {}) {
|
|
4856
|
+
const pathspecs = subdirs.length > 0 ? subdirs.map((s) => `${INFRASTRUCTURE_DIR}/${s}/`) : [`${INFRASTRUCTURE_DIR}/`];
|
|
4857
|
+
const scopeLabel = pathspecs.map((p) => `'${p}'`).join(", ");
|
|
4712
4858
|
console.log(
|
|
4713
|
-
`Merging
|
|
4859
|
+
`Merging ${scopeLabel} from ${UPSTREAM_URL}@${UPSTREAM_BRANCH} (base: ${BASE_BRANCH})...
|
|
4714
4860
|
`
|
|
4715
4861
|
);
|
|
4716
4862
|
assertIsGitRepo();
|
|
@@ -4725,20 +4871,12 @@ async function main25() {
|
|
|
4725
4871
|
const ref = `${TEMP_REMOTE2}/${UPSTREAM_BRANCH}`;
|
|
4726
4872
|
const baseRef = `${TEMP_REMOTE2}/${BASE_BRANCH}`;
|
|
4727
4873
|
const upstreamFiles = runGit(
|
|
4728
|
-
[
|
|
4729
|
-
"ls-tree",
|
|
4730
|
-
"-r",
|
|
4731
|
-
"--name-only",
|
|
4732
|
-
"-z",
|
|
4733
|
-
ref,
|
|
4734
|
-
"--",
|
|
4735
|
-
`${INFRASTRUCTURE_DIR}/`
|
|
4736
|
-
],
|
|
4874
|
+
["ls-tree", "-r", "--name-only", "-z", ref, "--", ...pathspecs],
|
|
4737
4875
|
{ silent: true }
|
|
4738
4876
|
).split("\0").filter(Boolean);
|
|
4739
4877
|
if (upstreamFiles.length === 0) {
|
|
4740
4878
|
console.log(
|
|
4741
|
-
` No files found under
|
|
4879
|
+
` No files found under ${scopeLabel} on ${ref}. Nothing to merge.`
|
|
4742
4880
|
);
|
|
4743
4881
|
return;
|
|
4744
4882
|
}
|
|
@@ -4813,7 +4951,9 @@ async function main25() {
|
|
|
4813
4951
|
var import_fs6 = require("fs");
|
|
4814
4952
|
var import_path25 = require("path");
|
|
4815
4953
|
var INFRASTRUCTURE_DIR2 = "infrastructure";
|
|
4816
|
-
async function main26(
|
|
4954
|
+
async function main26({
|
|
4955
|
+
keep = []
|
|
4956
|
+
} = {}) {
|
|
4817
4957
|
const fullPath = (0, import_path25.join)(process.cwd(), INFRASTRUCTURE_DIR2);
|
|
4818
4958
|
if (!(0, import_fs6.existsSync)(fullPath)) {
|
|
4819
4959
|
console.log(
|
|
@@ -4821,31 +4961,70 @@ async function main26() {
|
|
|
4821
4961
|
);
|
|
4822
4962
|
return;
|
|
4823
4963
|
}
|
|
4824
|
-
console.log(`Deleting '${INFRASTRUCTURE_DIR2}/'...
|
|
4825
|
-
`);
|
|
4826
4964
|
assertIsGitRepo();
|
|
4827
|
-
|
|
4828
|
-
|
|
4829
|
-
|
|
4830
|
-
|
|
4831
|
-
|
|
4832
|
-
|
|
4833
|
-
console.log(
|
|
4965
|
+
if (keep.length === 0) {
|
|
4966
|
+
console.log(`Deleting '${INFRASTRUCTURE_DIR2}/'...
|
|
4967
|
+
`);
|
|
4968
|
+
runGit(["rm", "-rf", "--ignore-unmatch", "--", `${INFRASTRUCTURE_DIR2}/`], {
|
|
4969
|
+
silent: true
|
|
4970
|
+
});
|
|
4971
|
+
console.log(
|
|
4972
|
+
` Staged deletion of tracked files under '${INFRASTRUCTURE_DIR2}/'.`
|
|
4973
|
+
);
|
|
4974
|
+
if ((0, import_fs6.existsSync)(fullPath)) {
|
|
4975
|
+
(0, import_fs6.rmSync)(fullPath, { recursive: true, force: true });
|
|
4976
|
+
console.log(
|
|
4977
|
+
` Removed remaining untracked files under '${INFRASTRUCTURE_DIR2}/'.`
|
|
4978
|
+
);
|
|
4979
|
+
}
|
|
4980
|
+
console.log(
|
|
4981
|
+
`
|
|
4982
|
+
Done. Review the staged deletion with: git diff --cached -- '${INFRASTRUCTURE_DIR2}/'`
|
|
4983
|
+
);
|
|
4984
|
+
return;
|
|
4985
|
+
}
|
|
4986
|
+
const keepSet = new Set(keep);
|
|
4987
|
+
console.log(
|
|
4988
|
+
`Deleting contents of '${INFRASTRUCTURE_DIR2}/' except: ${[...keepSet].map((name) => `'${name}'`).join(", ")}
|
|
4989
|
+
`
|
|
4990
|
+
);
|
|
4991
|
+
const topLevelEntries = (0, import_fs6.readdirSync)(fullPath, { withFileTypes: true });
|
|
4992
|
+
let deleted = 0;
|
|
4993
|
+
for (const entry of topLevelEntries) {
|
|
4994
|
+
if (keepSet.has(entry.name)) {
|
|
4995
|
+
console.log(` Keeping '${INFRASTRUCTURE_DIR2}/${entry.name}'.`);
|
|
4996
|
+
continue;
|
|
4997
|
+
}
|
|
4998
|
+
const relPath = `${INFRASTRUCTURE_DIR2}/${entry.name}${entry.isDirectory() ? "/" : ""}`;
|
|
4999
|
+
runGit(["rm", "-rf", "--ignore-unmatch", "--", relPath], { silent: true });
|
|
5000
|
+
const fullEntryPath = (0, import_path25.join)(fullPath, entry.name);
|
|
5001
|
+
if ((0, import_fs6.existsSync)(fullEntryPath)) {
|
|
5002
|
+
(0, import_fs6.rmSync)(fullEntryPath, { recursive: true, force: true });
|
|
5003
|
+
}
|
|
5004
|
+
console.log(` Deleted '${relPath}'.`);
|
|
5005
|
+
deleted++;
|
|
5006
|
+
}
|
|
5007
|
+
const presentNames = new Set(topLevelEntries.map((e) => e.name));
|
|
5008
|
+
const missingKeeps = [...keepSet].filter((name) => !presentNames.has(name));
|
|
5009
|
+
if (missingKeeps.length > 0) {
|
|
5010
|
+
console.warn(
|
|
5011
|
+
` [warn] Requested to keep ${missingKeeps.map((n) => `'${n}'`).join(", ")} but they don't exist under '${INFRASTRUCTURE_DIR2}/'.`
|
|
5012
|
+
);
|
|
4834
5013
|
}
|
|
4835
5014
|
console.log(
|
|
4836
5015
|
`
|
|
4837
|
-
Done. Review the staged
|
|
5016
|
+
Done. Deleted ${deleted} top-level entr${deleted === 1 ? "y" : "ies"}. Review the staged deletions with: git diff --cached -- '${INFRASTRUCTURE_DIR2}/'`
|
|
4838
5017
|
);
|
|
4839
5018
|
}
|
|
4840
5019
|
|
|
4841
|
-
// src/migrations/v2.0/fix-
|
|
5020
|
+
// src/migrations/v2.0/fix-accept-requested-registration-function-type.ts
|
|
4842
5021
|
var import_ts_morph22 = require("ts-morph");
|
|
4843
5022
|
var import_path26 = __toESM(require("path"));
|
|
4844
5023
|
var TARGET_FUNCTION_NAME = "acceptRequestedRegistration";
|
|
4845
5024
|
var ACTION_PARAMETER_NAME = "action";
|
|
4846
5025
|
var OLD_TYPE = "ActionInput";
|
|
4847
5026
|
var NEW_TYPE = "Extract<ActionInput, { type?: 'REGISTER' }>";
|
|
4848
|
-
function
|
|
5027
|
+
function isAcceptRequestedRegistrationParameter(parameter) {
|
|
4849
5028
|
const functionDeclaration = parameter.getFirstAncestorByKind(
|
|
4850
5029
|
import_ts_morph22.SyntaxKind.FunctionDeclaration
|
|
4851
5030
|
);
|
|
@@ -4864,30 +5043,30 @@ function processFile14(filePath, project) {
|
|
|
4864
5043
|
const sourceFile = project.getSourceFile(filePath);
|
|
4865
5044
|
if (!sourceFile) return 0;
|
|
4866
5045
|
let updatedCount = 0;
|
|
4867
|
-
const
|
|
4868
|
-
|
|
5046
|
+
for (const parameter of sourceFile.getDescendantsOfKind(
|
|
5047
|
+
import_ts_morph22.SyntaxKind.Parameter
|
|
5048
|
+
)) {
|
|
4869
5049
|
if (parameter.getName() !== ACTION_PARAMETER_NAME) {
|
|
4870
5050
|
continue;
|
|
4871
5051
|
}
|
|
4872
|
-
if (!
|
|
5052
|
+
if (!isAcceptRequestedRegistrationParameter(parameter)) {
|
|
4873
5053
|
continue;
|
|
4874
5054
|
}
|
|
4875
5055
|
const typeNode = parameter.getTypeNode();
|
|
4876
|
-
if (!typeNode)
|
|
4877
|
-
if (typeNode.getText() !== OLD_TYPE) {
|
|
5056
|
+
if (!typeNode || typeNode.getText() !== OLD_TYPE) {
|
|
4878
5057
|
continue;
|
|
4879
5058
|
}
|
|
4880
5059
|
parameter.setType(NEW_TYPE);
|
|
4881
5060
|
updatedCount++;
|
|
4882
5061
|
console.log(
|
|
4883
|
-
` [${import_path26.default.relative(process.cwd(), filePath)}] Updated '${ACTION_PARAMETER_NAME}'
|
|
5062
|
+
` [${import_path26.default.relative(process.cwd(), filePath)}] Updated '${ACTION_PARAMETER_NAME}' in ${TARGET_FUNCTION_NAME} to ${NEW_TYPE}`
|
|
4884
5063
|
);
|
|
4885
5064
|
}
|
|
4886
5065
|
return updatedCount;
|
|
4887
5066
|
}
|
|
4888
5067
|
async function main27() {
|
|
4889
5068
|
const srcDir = import_path26.default.join(process.cwd(), "src");
|
|
4890
|
-
console.log(`Scanning for
|
|
5069
|
+
console.log(`Scanning for ${TARGET_FUNCTION_NAME} in: ${srcDir}
|
|
4891
5070
|
`);
|
|
4892
5071
|
const project = new import_ts_morph22.Project({
|
|
4893
5072
|
tsConfigFilePath: import_path26.default.resolve(srcDir, "../tsconfig.json"),
|
|
@@ -4909,7 +5088,7 @@ async function main27() {
|
|
|
4909
5088
|
}
|
|
4910
5089
|
if (modifiedFiles.length === 0) {
|
|
4911
5090
|
console.log(
|
|
4912
|
-
`No '${ACTION_PARAMETER_NAME}: ${OLD_TYPE}' parameter
|
|
5091
|
+
`No '${ACTION_PARAMETER_NAME}: ${OLD_TYPE}' parameter in ${TARGET_FUNCTION_NAME} found. Nothing to do.`
|
|
4913
5092
|
);
|
|
4914
5093
|
return;
|
|
4915
5094
|
}
|
|
@@ -4922,11 +5101,12 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
4922
5101
|
}
|
|
4923
5102
|
console.log(
|
|
4924
5103
|
`
|
|
4925
|
-
Done. Updated ${totalUpdated}
|
|
5104
|
+
Done. Updated ${totalUpdated} parameter type annotation(s) in ${TARGET_FUNCTION_NAME}.`
|
|
4926
5105
|
);
|
|
4927
5106
|
}
|
|
4928
5107
|
|
|
4929
5108
|
// src/migrations/v2.0/index.ts
|
|
5109
|
+
var NON_SWARM_INFRA_SUBDIRS = ["postgres", "metabase"];
|
|
4930
5110
|
async function runUpgrade(dockerSwarm) {
|
|
4931
5111
|
await main18();
|
|
4932
5112
|
await main();
|
|
@@ -4948,15 +5128,16 @@ async function runUpgrade(dockerSwarm) {
|
|
|
4948
5128
|
await main19();
|
|
4949
5129
|
await main20();
|
|
4950
5130
|
await main21();
|
|
4951
|
-
await main27();
|
|
4952
5131
|
await main22();
|
|
4953
5132
|
await main23();
|
|
4954
5133
|
await main24();
|
|
5134
|
+
await main27();
|
|
4955
5135
|
await main17();
|
|
4956
5136
|
if (dockerSwarm) {
|
|
4957
5137
|
await main25();
|
|
4958
5138
|
} else {
|
|
4959
|
-
await main26();
|
|
5139
|
+
await main26({ keep: NON_SWARM_INFRA_SUBDIRS });
|
|
5140
|
+
await main25({ subdirs: NON_SWARM_INFRA_SUBDIRS });
|
|
4960
5141
|
}
|
|
4961
5142
|
}
|
|
4962
5143
|
|