@opencrvs/toolkit 2.0.0-rc.b69177b → 2.0.0-rc.b6b0009
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 +253 -102
- package/dist/cli.js +215 -39
- package/dist/commons/api/router.d.ts +3355 -212
- 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 -36
- package/dist/commons/events/AdvancedSearchConfig.d.ts +342 -0
- package/dist/commons/events/Draft.d.ts +4 -3
- package/dist/commons/events/EventDocument.d.ts +3 -0
- package/dist/commons/events/EventIndex.d.ts +0 -4
- package/dist/commons/events/EventMetadata.d.ts +0 -8
- 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 -5
- 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 +943 -239
- 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 +213 -37
- package/dist/migrations/v2.0/migrate-scopes.d.ts.map +1 -1
- package/dist/migrations/v2.0/migrate-scopes.js +54 -30
- package/dist/notification/index.js +793 -138
- package/dist/scopes/index.d.ts +4 -6
- package/dist/scopes/index.js +12 -4
- package/opencrvs-toolkit-2.0.0-rc.b6b0009.tgz +0 -0
- package/package.json +6 -2
- package/tsconfig.tsbuildinfo +1 -1
- package/opencrvs-toolkit-2.0.0-rc.b69177b.tgz +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fix-accept-requested-registration-function-type.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/fix-accept-requested-registration-function-type.ts"],"names":[],"mappings":"AAuFA,iBAAe,IAAI,kBA6ClB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
4
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
5
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
6
|
+
*
|
|
7
|
+
* OpenCRVS is also distributed under the terms of the Civil Registration
|
|
8
|
+
* & Healthcare Disclaimer located at http://opencrvs.org/license.
|
|
9
|
+
*
|
|
10
|
+
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
|
|
11
|
+
*/
|
|
12
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.main = main;
|
|
26
|
+
/**
|
|
27
|
+
* Codemod: In `acceptRequestedRegistration`, update the `action` parameter type from:
|
|
28
|
+
* action: ActionInput
|
|
29
|
+
* to:
|
|
30
|
+
* action: Extract<ActionInput, { type?: 'REGISTER' }>
|
|
31
|
+
*
|
|
32
|
+
* What it does:
|
|
33
|
+
* - Scans all TypeScript files under `src/`
|
|
34
|
+
* - Finds `acceptRequestedRegistration` (function declaration or const assignment)
|
|
35
|
+
* - Rewrites only the `action` parameter when its type is exactly `ActionInput`
|
|
36
|
+
* - Saves modified files in-place
|
|
37
|
+
*/
|
|
38
|
+
/* eslint-disable no-console */
|
|
39
|
+
const ts_morph_1 = require("ts-morph");
|
|
40
|
+
const path_1 = __importDefault(require("path"));
|
|
41
|
+
const TARGET_FUNCTION_NAME = 'acceptRequestedRegistration';
|
|
42
|
+
const ACTION_PARAMETER_NAME = 'action';
|
|
43
|
+
const OLD_TYPE = 'ActionInput';
|
|
44
|
+
const NEW_TYPE = "Extract<ActionInput, { type?: 'REGISTER' }>";
|
|
45
|
+
function isAcceptRequestedRegistrationParameter(parameter) {
|
|
46
|
+
const functionDeclaration = parameter.getFirstAncestorByKind(ts_morph_1.SyntaxKind.FunctionDeclaration);
|
|
47
|
+
if ((functionDeclaration === null || functionDeclaration === void 0 ? void 0 : functionDeclaration.getName()) === TARGET_FUNCTION_NAME) {
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
const arrowFunction = parameter.getFirstAncestorByKind(ts_morph_1.SyntaxKind.ArrowFunction);
|
|
51
|
+
const variableDeclaration = arrowFunction === null || arrowFunction === void 0 ? void 0 : arrowFunction.getFirstAncestorByKind(ts_morph_1.SyntaxKind.VariableDeclaration);
|
|
52
|
+
return (variableDeclaration === null || variableDeclaration === void 0 ? void 0 : variableDeclaration.getName()) === TARGET_FUNCTION_NAME;
|
|
53
|
+
}
|
|
54
|
+
function processFile(filePath, project) {
|
|
55
|
+
const sourceFile = project.getSourceFile(filePath);
|
|
56
|
+
if (!sourceFile)
|
|
57
|
+
return 0;
|
|
58
|
+
let updatedCount = 0;
|
|
59
|
+
for (const parameter of sourceFile.getDescendantsOfKind(ts_morph_1.SyntaxKind.Parameter)) {
|
|
60
|
+
if (parameter.getName() !== ACTION_PARAMETER_NAME) {
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
if (!isAcceptRequestedRegistrationParameter(parameter)) {
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
const typeNode = parameter.getTypeNode();
|
|
67
|
+
if (!typeNode || typeNode.getText() !== OLD_TYPE) {
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
parameter.setType(NEW_TYPE);
|
|
71
|
+
updatedCount++;
|
|
72
|
+
console.log(` [${path_1.default.relative(process.cwd(), filePath)}] Updated '${ACTION_PARAMETER_NAME}' in ${TARGET_FUNCTION_NAME} to ${NEW_TYPE}`);
|
|
73
|
+
}
|
|
74
|
+
return updatedCount;
|
|
75
|
+
}
|
|
76
|
+
function main() {
|
|
77
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
+
const srcDir = path_1.default.join(process.cwd(), 'src');
|
|
79
|
+
console.log(`Scanning for ${TARGET_FUNCTION_NAME} in: ${srcDir}\n`);
|
|
80
|
+
const project = new ts_morph_1.Project({
|
|
81
|
+
tsConfigFilePath: path_1.default.resolve(srcDir, '../tsconfig.json'),
|
|
82
|
+
skipAddingFilesFromTsConfig: false
|
|
83
|
+
});
|
|
84
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
85
|
+
const filePath = sf.getFilePath();
|
|
86
|
+
return filePath.includes('/src/') && !filePath.includes('/node_modules/');
|
|
87
|
+
});
|
|
88
|
+
let totalUpdated = 0;
|
|
89
|
+
const modifiedFiles = [];
|
|
90
|
+
for (const sourceFile of sourceFiles) {
|
|
91
|
+
const filePath = sourceFile.getFilePath();
|
|
92
|
+
const updated = processFile(filePath, project);
|
|
93
|
+
if (updated > 0) {
|
|
94
|
+
totalUpdated += updated;
|
|
95
|
+
modifiedFiles.push(filePath);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (modifiedFiles.length === 0) {
|
|
99
|
+
console.log(`No '${ACTION_PARAMETER_NAME}: ${OLD_TYPE}' parameter in ${TARGET_FUNCTION_NAME} found. Nothing to do.`);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
console.log(`\nSaving ${modifiedFiles.length} modified file(s)...`);
|
|
103
|
+
for (const filePath of modifiedFiles) {
|
|
104
|
+
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
105
|
+
yield sourceFile.save();
|
|
106
|
+
console.log(` Saved: ${path_1.default.relative(process.cwd(), filePath)}`);
|
|
107
|
+
}
|
|
108
|
+
console.log(`\nDone. Updated ${totalUpdated} parameter type annotation(s) in ${TARGET_FUNCTION_NAME}.`);
|
|
109
|
+
});
|
|
110
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/index.ts"],"names":[],"mappings":"AA8CA;;;;;;;;;;GAUG;AACH,wBAAsB,UAAU,CAAC,WAAW,EAAE,OAAO,iBAiCpD"}
|
|
@@ -1895,9 +1895,9 @@ function updateRouteHandlers(sourceFiles, group, srcDir, relCwd) {
|
|
|
1895
1895
|
}
|
|
1896
1896
|
return replacedCount;
|
|
1897
1897
|
}
|
|
1898
|
-
function resolveConfigChain(configObj,
|
|
1898
|
+
function resolveConfigChain(configObj, path24) {
|
|
1899
1899
|
let current = configObj;
|
|
1900
|
-
for (const key of
|
|
1900
|
+
for (const key of path24) {
|
|
1901
1901
|
if (!import_ts_morph10.Node.isObjectLiteralExpression(current)) return null;
|
|
1902
1902
|
const prop = current.getProperty(key);
|
|
1903
1903
|
if (!prop || !import_ts_morph10.Node.isPropertyAssignment(prop)) return null;
|
|
@@ -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
|
|
|
@@ -4764,9 +4851,9 @@ var import_path24 = require("path");
|
|
|
4764
4851
|
var TEMP_REMOTE2 = "opencrvs-upgrade-v19-v20-codemod-merge-infra";
|
|
4765
4852
|
var INFRASTRUCTURE_DIR = "infrastructure";
|
|
4766
4853
|
var BASE_BRANCH = "release-v1.9";
|
|
4767
|
-
function gitShowBytes(ref,
|
|
4854
|
+
function gitShowBytes(ref, path24) {
|
|
4768
4855
|
try {
|
|
4769
|
-
const buf = (0, import_child_process2.execFileSync)("git", ["show", `${ref}:${
|
|
4856
|
+
const buf = (0, import_child_process2.execFileSync)("git", ["show", `${ref}:${path24}`], {
|
|
4770
4857
|
cwd: process.cwd(),
|
|
4771
4858
|
stdio: ["ignore", "pipe", "pipe"]
|
|
4772
4859
|
});
|
|
@@ -4942,6 +5029,94 @@ async function main26({
|
|
|
4942
5029
|
);
|
|
4943
5030
|
}
|
|
4944
5031
|
|
|
5032
|
+
// src/migrations/v2.0/fix-accept-requested-registration-function-type.ts
|
|
5033
|
+
var import_ts_morph22 = require("ts-morph");
|
|
5034
|
+
var import_path26 = __toESM(require("path"));
|
|
5035
|
+
var TARGET_FUNCTION_NAME = "acceptRequestedRegistration";
|
|
5036
|
+
var ACTION_PARAMETER_NAME = "action";
|
|
5037
|
+
var OLD_TYPE = "ActionInput";
|
|
5038
|
+
var NEW_TYPE = "Extract<ActionInput, { type?: 'REGISTER' }>";
|
|
5039
|
+
function isAcceptRequestedRegistrationParameter(parameter) {
|
|
5040
|
+
const functionDeclaration = parameter.getFirstAncestorByKind(
|
|
5041
|
+
import_ts_morph22.SyntaxKind.FunctionDeclaration
|
|
5042
|
+
);
|
|
5043
|
+
if (functionDeclaration?.getName() === TARGET_FUNCTION_NAME) {
|
|
5044
|
+
return true;
|
|
5045
|
+
}
|
|
5046
|
+
const arrowFunction = parameter.getFirstAncestorByKind(
|
|
5047
|
+
import_ts_morph22.SyntaxKind.ArrowFunction
|
|
5048
|
+
);
|
|
5049
|
+
const variableDeclaration = arrowFunction?.getFirstAncestorByKind(
|
|
5050
|
+
import_ts_morph22.SyntaxKind.VariableDeclaration
|
|
5051
|
+
);
|
|
5052
|
+
return variableDeclaration?.getName() === TARGET_FUNCTION_NAME;
|
|
5053
|
+
}
|
|
5054
|
+
function processFile14(filePath, project) {
|
|
5055
|
+
const sourceFile = project.getSourceFile(filePath);
|
|
5056
|
+
if (!sourceFile) return 0;
|
|
5057
|
+
let updatedCount = 0;
|
|
5058
|
+
for (const parameter of sourceFile.getDescendantsOfKind(
|
|
5059
|
+
import_ts_morph22.SyntaxKind.Parameter
|
|
5060
|
+
)) {
|
|
5061
|
+
if (parameter.getName() !== ACTION_PARAMETER_NAME) {
|
|
5062
|
+
continue;
|
|
5063
|
+
}
|
|
5064
|
+
if (!isAcceptRequestedRegistrationParameter(parameter)) {
|
|
5065
|
+
continue;
|
|
5066
|
+
}
|
|
5067
|
+
const typeNode = parameter.getTypeNode();
|
|
5068
|
+
if (!typeNode || typeNode.getText() !== OLD_TYPE) {
|
|
5069
|
+
continue;
|
|
5070
|
+
}
|
|
5071
|
+
parameter.setType(NEW_TYPE);
|
|
5072
|
+
updatedCount++;
|
|
5073
|
+
console.log(
|
|
5074
|
+
` [${import_path26.default.relative(process.cwd(), filePath)}] Updated '${ACTION_PARAMETER_NAME}' in ${TARGET_FUNCTION_NAME} to ${NEW_TYPE}`
|
|
5075
|
+
);
|
|
5076
|
+
}
|
|
5077
|
+
return updatedCount;
|
|
5078
|
+
}
|
|
5079
|
+
async function main27() {
|
|
5080
|
+
const srcDir = import_path26.default.join(process.cwd(), "src");
|
|
5081
|
+
console.log(`Scanning for ${TARGET_FUNCTION_NAME} in: ${srcDir}
|
|
5082
|
+
`);
|
|
5083
|
+
const project = new import_ts_morph22.Project({
|
|
5084
|
+
tsConfigFilePath: import_path26.default.resolve(srcDir, "../tsconfig.json"),
|
|
5085
|
+
skipAddingFilesFromTsConfig: false
|
|
5086
|
+
});
|
|
5087
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
5088
|
+
const filePath = sf.getFilePath();
|
|
5089
|
+
return filePath.includes("/src/") && !filePath.includes("/node_modules/");
|
|
5090
|
+
});
|
|
5091
|
+
let totalUpdated = 0;
|
|
5092
|
+
const modifiedFiles = [];
|
|
5093
|
+
for (const sourceFile of sourceFiles) {
|
|
5094
|
+
const filePath = sourceFile.getFilePath();
|
|
5095
|
+
const updated = processFile14(filePath, project);
|
|
5096
|
+
if (updated > 0) {
|
|
5097
|
+
totalUpdated += updated;
|
|
5098
|
+
modifiedFiles.push(filePath);
|
|
5099
|
+
}
|
|
5100
|
+
}
|
|
5101
|
+
if (modifiedFiles.length === 0) {
|
|
5102
|
+
console.log(
|
|
5103
|
+
`No '${ACTION_PARAMETER_NAME}: ${OLD_TYPE}' parameter in ${TARGET_FUNCTION_NAME} found. Nothing to do.`
|
|
5104
|
+
);
|
|
5105
|
+
return;
|
|
5106
|
+
}
|
|
5107
|
+
console.log(`
|
|
5108
|
+
Saving ${modifiedFiles.length} modified file(s)...`);
|
|
5109
|
+
for (const filePath of modifiedFiles) {
|
|
5110
|
+
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
5111
|
+
await sourceFile.save();
|
|
5112
|
+
console.log(` Saved: ${import_path26.default.relative(process.cwd(), filePath)}`);
|
|
5113
|
+
}
|
|
5114
|
+
console.log(
|
|
5115
|
+
`
|
|
5116
|
+
Done. Updated ${totalUpdated} parameter type annotation(s) in ${TARGET_FUNCTION_NAME}.`
|
|
5117
|
+
);
|
|
5118
|
+
}
|
|
5119
|
+
|
|
4945
5120
|
// src/migrations/v2.0/index.ts
|
|
4946
5121
|
var NON_SWARM_INFRA_SUBDIRS = ["postgres", "metabase"];
|
|
4947
5122
|
async function runUpgrade(dockerSwarm) {
|
|
@@ -4968,6 +5143,7 @@ async function runUpgrade(dockerSwarm) {
|
|
|
4968
5143
|
await main22();
|
|
4969
5144
|
await main23();
|
|
4970
5145
|
await main24();
|
|
5146
|
+
await main27();
|
|
4971
5147
|
await main17();
|
|
4972
5148
|
if (dockerSwarm) {
|
|
4973
5149
|
await main25();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrate-scopes.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/migrate-scopes.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"migrate-scopes.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.0/migrate-scopes.ts"],"names":[],"mappings":"AAoXA,iBAAe,IAAI,kBAmDlB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
|
|
@@ -25,7 +25,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
25
25
|
exports.main = main;
|
|
26
26
|
const ts_morph_1 = require("ts-morph");
|
|
27
27
|
const path_1 = __importDefault(require("path"));
|
|
28
|
-
const scopes_1 = require("../commons/scopes");
|
|
29
28
|
const scopes_deprecated_do_not_use_1 = require("../commons/scopes.deprecated.do-not-use");
|
|
30
29
|
const ROLES_FILE_RELATIVE_PATH = 'src/data-seeding/roles/roles.ts';
|
|
31
30
|
const SCOPES_PROPERTY_NAME = 'scopes';
|
|
@@ -65,60 +64,85 @@ function resolveLegacyScopeFromElement(element) {
|
|
|
65
64
|
}
|
|
66
65
|
return null;
|
|
67
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Walks each `scopes: [...]` array in the roles file, classifies elements,
|
|
69
|
+
* and rewrites the whole array using `migrateLegacyScopesArrayToV2Scopes`
|
|
70
|
+
* (which preserves v1.9 AND semantics by merging pairs of legacy scopes
|
|
71
|
+
* that targeted the same v2 type). See issue #12489.
|
|
72
|
+
*
|
|
73
|
+
* Elements are partitioned into three kinds:
|
|
74
|
+
* - drop: `SCOPES.X` references where X is not in the SCOPES map (warned
|
|
75
|
+
* and removed, matching pre-refactor behavior).
|
|
76
|
+
* - raw: non-literal expressions we cannot statically resolve (e.g.
|
|
77
|
+
* `...sharedScopes` spreads). Preserved verbatim in output so authoring
|
|
78
|
+
* intent isn't lost.
|
|
79
|
+
* - legacy: literal strings or resolvable `SCOPES.X` references.
|
|
80
|
+
* Collected and passed as a batch to the merge function.
|
|
81
|
+
*
|
|
82
|
+
* The output array text is `[...rawTexts, ...mergedScopesAsJson]`. Order of
|
|
83
|
+
* legacy entries relative to raw expressions is not preserved — scopes in a
|
|
84
|
+
* v2 array compose with OR, so position is semantically irrelevant.
|
|
85
|
+
*/
|
|
68
86
|
function migrateScopesArrays(rolesFilePath, project) {
|
|
69
87
|
const sourceFile = project.getSourceFile(rolesFilePath);
|
|
70
|
-
if (!sourceFile)
|
|
71
|
-
return { migratedCount: 0, removedCount: 0 };
|
|
88
|
+
if (!sourceFile) {
|
|
89
|
+
return { migratedCount: 0, removedCount: 0, mergedCount: 0 };
|
|
90
|
+
}
|
|
72
91
|
let migratedCount = 0;
|
|
73
92
|
let removedCount = 0;
|
|
93
|
+
let mergedCount = 0;
|
|
74
94
|
const scopesProperties = sourceFile
|
|
75
95
|
.getDescendantsOfKind(ts_morph_1.SyntaxKind.PropertyAssignment)
|
|
76
96
|
.filter((prop) => prop.getName() === SCOPES_PROPERTY_NAME);
|
|
97
|
+
const relPath = path_1.default.relative(process.cwd(), rolesFilePath);
|
|
77
98
|
for (const scopesProp of scopesProperties) {
|
|
78
99
|
const initializer = scopesProp.getInitializer();
|
|
79
100
|
if (!initializer || !ts_morph_1.Node.isArrayLiteralExpression(initializer))
|
|
80
101
|
continue;
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
continue;
|
|
102
|
+
const rawTexts = [];
|
|
103
|
+
const legacyStrings = [];
|
|
104
|
+
let anyChange = false;
|
|
105
|
+
for (const element of initializer.getElements()) {
|
|
86
106
|
const scopeKey = resolveScopeKeyFromElementAccess(element);
|
|
87
107
|
if (scopeKey && !(scopeKey in scopes_deprecated_do_not_use_1.SCOPES)) {
|
|
88
108
|
// eslint-disable-next-line no-console
|
|
89
|
-
console.warn(` [${
|
|
90
|
-
initializer.removeElement(index);
|
|
109
|
+
console.warn(` [${relPath}] Removing unknown scope reference: SCOPES.${scopeKey}`);
|
|
91
110
|
removedCount++;
|
|
111
|
+
anyChange = true;
|
|
92
112
|
continue;
|
|
93
113
|
}
|
|
94
114
|
const legacyScope = resolveLegacyScopeFromElement(element);
|
|
95
115
|
if (!legacyScope) {
|
|
96
116
|
// eslint-disable-next-line no-console
|
|
97
|
-
console.warn(` [${
|
|
117
|
+
console.warn(` [${relPath}] Preserving non-literal scope expression verbatim: ${element.getText()}`);
|
|
118
|
+
rawTexts.push(element.getText());
|
|
98
119
|
continue;
|
|
99
120
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}
|
|
111
|
-
catch (error) {
|
|
112
|
-
// eslint-disable-next-line no-console
|
|
113
|
-
console.warn(` [${path_1.default.relative(process.cwd(), rolesFilePath)}] Could not migrate scope '${legacyScope}': ${error}`);
|
|
114
|
-
}
|
|
121
|
+
legacyStrings.push(legacyScope);
|
|
122
|
+
anyChange = true;
|
|
123
|
+
}
|
|
124
|
+
if (!anyChange)
|
|
125
|
+
continue;
|
|
126
|
+
let mergedScopes;
|
|
127
|
+
try {
|
|
128
|
+
mergedScopes = (0, scopes_deprecated_do_not_use_1.migrateLegacyScopesArrayToV2Scopes)(legacyStrings);
|
|
129
|
+
}
|
|
130
|
+
catch (error) {
|
|
131
|
+
throw new Error(`[${relPath}] Failed to migrate scopes for role: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
115
132
|
}
|
|
133
|
+
migratedCount += legacyStrings.length;
|
|
134
|
+
mergedCount += legacyStrings.length - mergedScopes.length;
|
|
135
|
+
const outputElements = [
|
|
136
|
+
...rawTexts,
|
|
137
|
+
...mergedScopes.map((s) => JSON.stringify(s))
|
|
138
|
+
];
|
|
139
|
+
scopesProp.setInitializer(`[${outputElements.join(', ')}]`);
|
|
116
140
|
}
|
|
117
141
|
if (removedCount > 0) {
|
|
118
142
|
// eslint-disable-next-line no-console
|
|
119
|
-
console.log(` Removed ${removedCount} unknown SCOPES reference(s) from '${
|
|
143
|
+
console.log(` Removed ${removedCount} unknown SCOPES reference(s) from '${relPath}'.`);
|
|
120
144
|
}
|
|
121
|
-
return { migratedCount, removedCount };
|
|
145
|
+
return { migratedCount, removedCount, mergedCount };
|
|
122
146
|
}
|
|
123
147
|
function ensureScopesHelpersImport(rolesFilePath, project) {
|
|
124
148
|
const sourceFile = project.getSourceFile(rolesFilePath);
|
|
@@ -262,7 +286,7 @@ function main() {
|
|
|
262
286
|
return;
|
|
263
287
|
}
|
|
264
288
|
const importChanged = ensureScopesHelpersImport(rolesFilePath, project);
|
|
265
|
-
const { migratedCount, removedCount } = migrateScopesArrays(rolesFilePath, project);
|
|
289
|
+
const { migratedCount, removedCount, mergedCount } = migrateScopesArrays(rolesFilePath, project);
|
|
266
290
|
const wrappedScopesCount = wrapScopesArraysWithDefineScopes(rolesFilePath, project);
|
|
267
291
|
const wrappedRoles = wrapRolesWithDefineRoles(rolesFilePath, project);
|
|
268
292
|
const removedRoleType = removeRoleTypeDefinitionAndUnusedImports(rolesFilePath, project);
|
|
@@ -276,6 +300,6 @@ function main() {
|
|
|
276
300
|
return;
|
|
277
301
|
}
|
|
278
302
|
yield sourceFile.save();
|
|
279
|
-
console.log(`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.' : '.'}`);
|
|
303
|
+
console.log(`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.' : '.'}`);
|
|
280
304
|
});
|
|
281
305
|
}
|