@opencrvs/toolkit 2.0.0-rc.c22cdf5 → 2.0.0-rc.c298173
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 +273 -120
- package/dist/cli.js +164 -69
- package/dist/commons/api/router.d.ts +3359 -217
- 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/ActionConfig.d.ts +28 -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/CountryConfigQueryInput.d.ts +42 -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 +14 -3
- package/dist/commons/events/EventMetadata.d.ts +0 -7
- package/dist/commons/events/FieldConfig.d.ts +378 -50
- package/dist/commons/events/FieldType.d.ts +1 -0
- package/dist/commons/events/FieldTypeMapping.d.ts +1 -1
- package/dist/commons/events/FieldValue.d.ts +6 -0
- package/dist/commons/events/WorkqueueConfig.d.ts +189 -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 +1077 -285
- 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 -1
- package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.d.ts +3 -0
- package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.d.ts.map +1 -0
- package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.js +110 -0
- package/dist/migrations/v2.0/index.d.ts.map +1 -1
- package/dist/migrations/v2.0/index.js +162 -67
- package/dist/notification/index.js +901 -156
- package/dist/scopes/index.d.ts +4 -6
- package/dist/scopes/index.js +12 -4
- package/opencrvs-toolkit-2.0.0-rc.c298173.tgz +0 -0
- package/package.json +6 -2
- package/tsconfig.tsbuildinfo +1 -1
- package/opencrvs-toolkit-2.0.0-rc.c22cdf5.tgz +0 -0
package/dist/cli.js
CHANGED
|
@@ -1883,9 +1883,9 @@ function updateRouteHandlers(sourceFiles, group, srcDir, relCwd) {
|
|
|
1883
1883
|
}
|
|
1884
1884
|
return replacedCount;
|
|
1885
1885
|
}
|
|
1886
|
-
function resolveConfigChain(configObj,
|
|
1886
|
+
function resolveConfigChain(configObj, path24) {
|
|
1887
1887
|
let current = configObj;
|
|
1888
|
-
for (const key of
|
|
1888
|
+
for (const key of path24) {
|
|
1889
1889
|
if (!import_ts_morph10.Node.isObjectLiteralExpression(current)) return null;
|
|
1890
1890
|
const prop = current.getProperty(key);
|
|
1891
1891
|
if (!prop || !import_ts_morph10.Node.isPropertyAssignment(prop)) return null;
|
|
@@ -2382,18 +2382,26 @@ var encodeScope = (scope) => {
|
|
|
2382
2382
|
encode: false
|
|
2383
2383
|
});
|
|
2384
2384
|
};
|
|
2385
|
-
var
|
|
2386
|
-
|
|
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, {
|
|
2387
2391
|
ignoreQueryPrefix: true,
|
|
2388
2392
|
comma: true,
|
|
2389
2393
|
allowDots: true
|
|
2390
2394
|
});
|
|
2391
2395
|
const unflattenedScope = unflattenScope(scope);
|
|
2392
|
-
|
|
2396
|
+
const result = Scope2.safeParse(unflattenedScope)?.data;
|
|
2397
|
+
decodedScopeCache.set(encodedScope, result);
|
|
2398
|
+
return result;
|
|
2393
2399
|
};
|
|
2394
2400
|
var DEFAULT_SCOPE_OPTIONS = {
|
|
2395
2401
|
placeOfEvent: JurisdictionFilter.enum.all,
|
|
2396
|
-
accessLevel: JurisdictionFilter.enum.all
|
|
2402
|
+
accessLevel: JurisdictionFilter.enum.all,
|
|
2403
|
+
registeredIn: JurisdictionFilter.enum.all,
|
|
2404
|
+
declaredIn: JurisdictionFilter.enum.all
|
|
2397
2405
|
};
|
|
2398
2406
|
|
|
2399
2407
|
// ../commons/src/scopes.deprecated.do-not-use.ts
|
|
@@ -2634,71 +2642,69 @@ var MERGEABLE_USER_SCOPE_TYPES = ["user.create", "user.edit"];
|
|
|
2634
2642
|
function isMergeableUserScopeType(type) {
|
|
2635
2643
|
return MERGEABLE_USER_SCOPE_TYPES.includes(type);
|
|
2636
2644
|
}
|
|
2637
|
-
function
|
|
2638
|
-
const
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
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 : {}
|
|
2649
2672
|
);
|
|
2650
|
-
const
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
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
|
+
);
|
|
2655
2684
|
}
|
|
2656
|
-
const
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
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);
|
|
2668
2700
|
if (!isMergeableUserScopeType(type)) {
|
|
2669
2701
|
console.warn(
|
|
2670
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.`
|
|
2671
2703
|
);
|
|
2672
|
-
|
|
2673
|
-
continue;
|
|
2704
|
+
return deduped.map((e) => e.scope);
|
|
2674
2705
|
}
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
for (const entry of deduped) {
|
|
2678
|
-
const opts = "options" in entry.scope && entry.scope.options ? entry.scope.options : {};
|
|
2679
|
-
for (const [key, value] of Object.entries(opts)) {
|
|
2680
|
-
if (value === void 0) continue;
|
|
2681
|
-
if (key in mergedOptions) {
|
|
2682
|
-
const previous = optionSources.get(key) ?? [];
|
|
2683
|
-
const conflicting = [...previous, entry.legacy];
|
|
2684
|
-
throw new Error(
|
|
2685
|
-
`Cannot auto-merge two '${type}' scopes that both define '${key}'. Conflicting legacy scopes: [${conflicting.map((s) => JSON.stringify(s)).join(", ")}]. Resolve manually in roles.ts and re-run.`
|
|
2686
|
-
);
|
|
2687
|
-
}
|
|
2688
|
-
mergedOptions[key] = value;
|
|
2689
|
-
optionSources.set(key, [entry.legacy]);
|
|
2690
|
-
}
|
|
2691
|
-
}
|
|
2692
|
-
const merged = Object.keys(mergedOptions).length > 0 ? { type, options: mergedOptions } : { type };
|
|
2693
|
-
const parsed = Scope2.safeParse(merged);
|
|
2694
|
-
if (!parsed.success) {
|
|
2695
|
-
throw new Error(
|
|
2696
|
-
`Merged '${type}' scope failed schema validation: ${parsed.error.message}. Legacy scopes: [${deduped.map((e) => JSON.stringify(e.legacy)).join(", ")}].`
|
|
2697
|
-
);
|
|
2698
|
-
}
|
|
2699
|
-
result.push(parsed.data);
|
|
2700
|
-
}
|
|
2701
|
-
return result;
|
|
2706
|
+
return [mergeEntries(type, deduped)];
|
|
2707
|
+
});
|
|
2702
2708
|
}
|
|
2703
2709
|
|
|
2704
2710
|
// src/migrations/v2.0/migrate-scopes.ts
|
|
@@ -4294,7 +4300,7 @@ Saved ${handlerRelPath}.`);
|
|
|
4294
4300
|
// src/migrations/v2.0/checkout-upstream-files.ts
|
|
4295
4301
|
var import_child_process = require("child_process");
|
|
4296
4302
|
var UPSTREAM_URL = "https://github.com/opencrvs/opencrvs-countryconfig.git";
|
|
4297
|
-
var UPSTREAM_BRANCH = "release
|
|
4303
|
+
var UPSTREAM_BRANCH = "release/2.0.0";
|
|
4298
4304
|
var TEMP_REMOTE = "opencrvs-upgrade-v19-v20-codemod";
|
|
4299
4305
|
var FILES_TO_CHECKOUT = [
|
|
4300
4306
|
"src/analytics/analytics.ts",
|
|
@@ -4833,9 +4839,9 @@ var import_path24 = require("path");
|
|
|
4833
4839
|
var TEMP_REMOTE2 = "opencrvs-upgrade-v19-v20-codemod-merge-infra";
|
|
4834
4840
|
var INFRASTRUCTURE_DIR = "infrastructure";
|
|
4835
4841
|
var BASE_BRANCH = "release-v1.9";
|
|
4836
|
-
function gitShowBytes(ref,
|
|
4842
|
+
function gitShowBytes(ref, path24) {
|
|
4837
4843
|
try {
|
|
4838
|
-
const buf = (0, import_child_process2.execFileSync)("git", ["show", `${ref}:${
|
|
4844
|
+
const buf = (0, import_child_process2.execFileSync)("git", ["show", `${ref}:${path24}`], {
|
|
4839
4845
|
cwd: process.cwd(),
|
|
4840
4846
|
stdio: ["ignore", "pipe", "pipe"]
|
|
4841
4847
|
});
|
|
@@ -5011,6 +5017,94 @@ async function main26({
|
|
|
5011
5017
|
);
|
|
5012
5018
|
}
|
|
5013
5019
|
|
|
5020
|
+
// src/migrations/v2.0/fix-accept-requested-registration-function-type.ts
|
|
5021
|
+
var import_ts_morph22 = require("ts-morph");
|
|
5022
|
+
var import_path26 = __toESM(require("path"));
|
|
5023
|
+
var TARGET_FUNCTION_NAME = "acceptRequestedRegistration";
|
|
5024
|
+
var ACTION_PARAMETER_NAME = "action";
|
|
5025
|
+
var OLD_TYPE = "ActionInput";
|
|
5026
|
+
var NEW_TYPE = "Extract<ActionInput, { type?: 'REGISTER' }>";
|
|
5027
|
+
function isAcceptRequestedRegistrationParameter(parameter) {
|
|
5028
|
+
const functionDeclaration = parameter.getFirstAncestorByKind(
|
|
5029
|
+
import_ts_morph22.SyntaxKind.FunctionDeclaration
|
|
5030
|
+
);
|
|
5031
|
+
if (functionDeclaration?.getName() === TARGET_FUNCTION_NAME) {
|
|
5032
|
+
return true;
|
|
5033
|
+
}
|
|
5034
|
+
const arrowFunction = parameter.getFirstAncestorByKind(
|
|
5035
|
+
import_ts_morph22.SyntaxKind.ArrowFunction
|
|
5036
|
+
);
|
|
5037
|
+
const variableDeclaration = arrowFunction?.getFirstAncestorByKind(
|
|
5038
|
+
import_ts_morph22.SyntaxKind.VariableDeclaration
|
|
5039
|
+
);
|
|
5040
|
+
return variableDeclaration?.getName() === TARGET_FUNCTION_NAME;
|
|
5041
|
+
}
|
|
5042
|
+
function processFile14(filePath, project) {
|
|
5043
|
+
const sourceFile = project.getSourceFile(filePath);
|
|
5044
|
+
if (!sourceFile) return 0;
|
|
5045
|
+
let updatedCount = 0;
|
|
5046
|
+
for (const parameter of sourceFile.getDescendantsOfKind(
|
|
5047
|
+
import_ts_morph22.SyntaxKind.Parameter
|
|
5048
|
+
)) {
|
|
5049
|
+
if (parameter.getName() !== ACTION_PARAMETER_NAME) {
|
|
5050
|
+
continue;
|
|
5051
|
+
}
|
|
5052
|
+
if (!isAcceptRequestedRegistrationParameter(parameter)) {
|
|
5053
|
+
continue;
|
|
5054
|
+
}
|
|
5055
|
+
const typeNode = parameter.getTypeNode();
|
|
5056
|
+
if (!typeNode || typeNode.getText() !== OLD_TYPE) {
|
|
5057
|
+
continue;
|
|
5058
|
+
}
|
|
5059
|
+
parameter.setType(NEW_TYPE);
|
|
5060
|
+
updatedCount++;
|
|
5061
|
+
console.log(
|
|
5062
|
+
` [${import_path26.default.relative(process.cwd(), filePath)}] Updated '${ACTION_PARAMETER_NAME}' in ${TARGET_FUNCTION_NAME} to ${NEW_TYPE}`
|
|
5063
|
+
);
|
|
5064
|
+
}
|
|
5065
|
+
return updatedCount;
|
|
5066
|
+
}
|
|
5067
|
+
async function main27() {
|
|
5068
|
+
const srcDir = import_path26.default.join(process.cwd(), "src");
|
|
5069
|
+
console.log(`Scanning for ${TARGET_FUNCTION_NAME} in: ${srcDir}
|
|
5070
|
+
`);
|
|
5071
|
+
const project = new import_ts_morph22.Project({
|
|
5072
|
+
tsConfigFilePath: import_path26.default.resolve(srcDir, "../tsconfig.json"),
|
|
5073
|
+
skipAddingFilesFromTsConfig: false
|
|
5074
|
+
});
|
|
5075
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
5076
|
+
const filePath = sf.getFilePath();
|
|
5077
|
+
return filePath.includes("/src/") && !filePath.includes("/node_modules/");
|
|
5078
|
+
});
|
|
5079
|
+
let totalUpdated = 0;
|
|
5080
|
+
const modifiedFiles = [];
|
|
5081
|
+
for (const sourceFile of sourceFiles) {
|
|
5082
|
+
const filePath = sourceFile.getFilePath();
|
|
5083
|
+
const updated = processFile14(filePath, project);
|
|
5084
|
+
if (updated > 0) {
|
|
5085
|
+
totalUpdated += updated;
|
|
5086
|
+
modifiedFiles.push(filePath);
|
|
5087
|
+
}
|
|
5088
|
+
}
|
|
5089
|
+
if (modifiedFiles.length === 0) {
|
|
5090
|
+
console.log(
|
|
5091
|
+
`No '${ACTION_PARAMETER_NAME}: ${OLD_TYPE}' parameter in ${TARGET_FUNCTION_NAME} found. Nothing to do.`
|
|
5092
|
+
);
|
|
5093
|
+
return;
|
|
5094
|
+
}
|
|
5095
|
+
console.log(`
|
|
5096
|
+
Saving ${modifiedFiles.length} modified file(s)...`);
|
|
5097
|
+
for (const filePath of modifiedFiles) {
|
|
5098
|
+
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
5099
|
+
await sourceFile.save();
|
|
5100
|
+
console.log(` Saved: ${import_path26.default.relative(process.cwd(), filePath)}`);
|
|
5101
|
+
}
|
|
5102
|
+
console.log(
|
|
5103
|
+
`
|
|
5104
|
+
Done. Updated ${totalUpdated} parameter type annotation(s) in ${TARGET_FUNCTION_NAME}.`
|
|
5105
|
+
);
|
|
5106
|
+
}
|
|
5107
|
+
|
|
5014
5108
|
// src/migrations/v2.0/index.ts
|
|
5015
5109
|
var NON_SWARM_INFRA_SUBDIRS = ["postgres", "metabase"];
|
|
5016
5110
|
async function runUpgrade(dockerSwarm) {
|
|
@@ -5037,6 +5131,7 @@ async function runUpgrade(dockerSwarm) {
|
|
|
5037
5131
|
await main22();
|
|
5038
5132
|
await main23();
|
|
5039
5133
|
await main24();
|
|
5134
|
+
await main27();
|
|
5040
5135
|
await main17();
|
|
5041
5136
|
if (dockerSwarm) {
|
|
5042
5137
|
await main25();
|
|
@@ -5071,7 +5166,7 @@ Options:
|
|
|
5071
5166
|
'infrastructure/' directory is deleted (default).
|
|
5072
5167
|
-h, --help Show this message.
|
|
5073
5168
|
`.trim();
|
|
5074
|
-
function
|
|
5169
|
+
function main28() {
|
|
5075
5170
|
const command = args[0];
|
|
5076
5171
|
if (!command || command === "--help" || command === "-h") {
|
|
5077
5172
|
console.log(USAGE);
|
|
@@ -5146,4 +5241,4 @@ function handleCheckTranslations() {
|
|
|
5146
5241
|
console.warn("This command is not implemented yet!");
|
|
5147
5242
|
process.exit(1);
|
|
5148
5243
|
}
|
|
5149
|
-
|
|
5244
|
+
main28();
|