@opencrvs/toolkit 1.9.12-rc.bce2e6f → 1.9.12-rc.bf52336
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/application-config/index.js +2038 -45
- package/dist/cli.js +850 -35
- package/dist/commons/api/router.d.ts +86 -79
- package/dist/commons/application-config/index.d.ts +6 -4
- package/dist/commons/events/ActionDocument.d.ts +6 -6
- package/dist/commons/events/ActionType.d.ts +3 -3
- package/dist/commons/events/AdvancedSearchConfig.d.ts +10 -10
- package/dist/commons/events/CountryConfigQueryInput.d.ts +222 -222
- package/dist/commons/events/Draft.d.ts +8 -8
- package/dist/commons/events/EventConfig.d.ts +1 -1
- package/dist/commons/events/EventDocument.d.ts +3 -3
- package/dist/commons/events/EventIndex.d.ts +15 -15
- package/dist/commons/events/EventMetadata.d.ts +12 -12
- package/dist/commons/events/FieldConfig.d.ts +26 -26
- package/dist/commons/events/FieldType.d.ts +1 -1
- package/dist/commons/events/FieldTypeMapping.d.ts +4 -4
- package/dist/commons/events/WorkqueueColumnConfig.d.ts +13 -13
- package/dist/commons/events/WorkqueueConfig.d.ts +239 -239
- package/dist/commons/events/state/index.d.ts +2 -2
- package/dist/commons/events/state/utils.d.ts +3 -3
- package/dist/commons/events/utils.d.ts +3 -3
- package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts.map +1 -1
- package/dist/migrations/v2.0/convert-config-files-to-ts.js +97 -21
- package/dist/migrations/v2.0/index.d.ts.map +1 -1
- package/dist/migrations/v2.0/index.js +848 -33
- package/dist/migrations/v2.0/migrate-scopes.d.ts.map +1 -1
- package/dist/migrations/v2.0/migrate-scopes.js +6 -5
- package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts +3 -0
- package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts.map +1 -0
- package/dist/migrations/v2.0/migrate-workqueue-configs.js +237 -0
- package/dist/migrations/v2.0/remove-demo-scope.d.ts +3 -0
- package/dist/migrations/v2.0/remove-demo-scope.d.ts.map +1 -0
- package/dist/migrations/v2.0/remove-demo-scope.js +75 -0
- package/dist/migrations/v2.0/remove-hearth-migrations.d.ts +3 -0
- package/dist/migrations/v2.0/remove-hearth-migrations.d.ts.map +1 -0
- package/dist/migrations/v2.0/remove-hearth-migrations.js +78 -0
- package/opencrvs-toolkit-1.9.12-rc.bf52336.tgz +0 -0
- package/package.json +1 -1
- package/tsconfig.json +3 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/opencrvs-toolkit-1.9.12-rc.bce2e6f.tgz +0 -0
package/dist/cli.js
CHANGED
|
@@ -903,8 +903,8 @@ function isBirthConfig(configArg) {
|
|
|
903
903
|
}
|
|
904
904
|
return false;
|
|
905
905
|
}
|
|
906
|
-
function hasElementWithId(
|
|
907
|
-
for (const el of
|
|
906
|
+
function hasElementWithId(array3, id) {
|
|
907
|
+
for (const el of array3.getElements()) {
|
|
908
908
|
if (!import_ts_morph6.Node.isObjectLiteralExpression(el)) continue;
|
|
909
909
|
const idProp = el.getProperty("id");
|
|
910
910
|
if (!idProp || !import_ts_morph6.Node.isPropertyAssignment(idProp)) continue;
|
|
@@ -1166,15 +1166,15 @@ function processFile7(filePath, project) {
|
|
|
1166
1166
|
const arrayLiterals = sourceFile.getDescendantsOfKind(
|
|
1167
1167
|
import_ts_morph7.SyntaxKind.ArrayLiteralExpression
|
|
1168
1168
|
);
|
|
1169
|
-
for (const
|
|
1169
|
+
for (const array3 of arrayLiterals) {
|
|
1170
1170
|
const indicesToRemove = [];
|
|
1171
|
-
|
|
1171
|
+
array3.getElements().forEach((element, index) => {
|
|
1172
1172
|
if (isPendingCertificationFlag(element)) {
|
|
1173
1173
|
indicesToRemove.push(index);
|
|
1174
1174
|
}
|
|
1175
1175
|
});
|
|
1176
1176
|
for (const index of indicesToRemove.reverse()) {
|
|
1177
|
-
|
|
1177
|
+
array3.removeElement(index);
|
|
1178
1178
|
removedCount++;
|
|
1179
1179
|
console.log(
|
|
1180
1180
|
` [${import_path7.default.relative(getCwd(), filePath)}] Removed InherentFlags.PENDING_CERTIFICATION from array`
|
|
@@ -1623,25 +1623,6 @@ ${elementParts.join(",\n")}
|
|
|
1623
1623
|
]`;
|
|
1624
1624
|
}
|
|
1625
1625
|
function generateTsContent(configObj, exportName, group, isProd) {
|
|
1626
|
-
const headerLines = [];
|
|
1627
|
-
if (isProd) {
|
|
1628
|
-
headerLines.push(`import { env } from './environment'`);
|
|
1629
|
-
}
|
|
1630
|
-
headerLines.push(`import { ${group.defineFn} } from '${group.importFrom}'`);
|
|
1631
|
-
if (group.applicationConfigImportPath) {
|
|
1632
|
-
headerLines.push(
|
|
1633
|
-
`import { applicationConfig } from '${group.applicationConfigImportPath}'`
|
|
1634
|
-
);
|
|
1635
|
-
}
|
|
1636
|
-
headerLines.push("");
|
|
1637
|
-
if (isProd) {
|
|
1638
|
-
headerLines.push(`const scheme = 'https'`);
|
|
1639
|
-
headerLines.push(`const hostname = env.DOMAIN`);
|
|
1640
|
-
headerLines.push(`const sentry = env.SENTRY_DSN`);
|
|
1641
|
-
} else {
|
|
1642
|
-
headerLines.push(`const scheme = 'http'`);
|
|
1643
|
-
headerLines.push(`const hostname = 'localhost'`);
|
|
1644
|
-
}
|
|
1645
1626
|
const propertyLines = [];
|
|
1646
1627
|
const seenKeys = /* @__PURE__ */ new Set();
|
|
1647
1628
|
const appConfigKeySet = new Set(group.applicationConfigKeys ?? []);
|
|
@@ -1677,6 +1658,27 @@ function generateTsContent(configObj, exportName, group, isProd) {
|
|
|
1677
1658
|
propertyLines.push(` ${key}: applicationConfig.${key}`);
|
|
1678
1659
|
}
|
|
1679
1660
|
const body = propertyLines.join(",\n");
|
|
1661
|
+
const headerLines = [];
|
|
1662
|
+
headerLines.push(`import * as fs from 'fs'`);
|
|
1663
|
+
headerLines.push(`import { join } from 'path'`);
|
|
1664
|
+
if (isProd) {
|
|
1665
|
+
headerLines.push(`import { env } from './environment'`);
|
|
1666
|
+
}
|
|
1667
|
+
headerLines.push(`import { ${group.defineFn} } from '${group.importFrom}'`);
|
|
1668
|
+
if (group.applicationConfigImportPath) {
|
|
1669
|
+
headerLines.push(
|
|
1670
|
+
`import { applicationConfig } from '${group.applicationConfigImportPath}'`
|
|
1671
|
+
);
|
|
1672
|
+
}
|
|
1673
|
+
headerLines.push("");
|
|
1674
|
+
if (isProd) {
|
|
1675
|
+
headerLines.push(`const scheme = 'https'`);
|
|
1676
|
+
headerLines.push(`const hostname = env.DOMAIN`);
|
|
1677
|
+
headerLines.push(`const sentry = env.SENTRY_DSN`);
|
|
1678
|
+
} else {
|
|
1679
|
+
headerLines.push(`const scheme = 'http'`);
|
|
1680
|
+
headerLines.push(`const hostname = 'localhost'`);
|
|
1681
|
+
}
|
|
1680
1682
|
return [
|
|
1681
1683
|
...headerLines,
|
|
1682
1684
|
"",
|
|
@@ -1811,9 +1813,9 @@ function updateRouteHandlers(sourceFiles, group, srcDir, relCwd) {
|
|
|
1811
1813
|
}
|
|
1812
1814
|
return replacedCount;
|
|
1813
1815
|
}
|
|
1814
|
-
function resolveConfigChain(configObj,
|
|
1816
|
+
function resolveConfigChain(configObj, path15) {
|
|
1815
1817
|
let current = configObj;
|
|
1816
|
-
for (const key of
|
|
1818
|
+
for (const key of path15) {
|
|
1817
1819
|
if (!import_ts_morph10.Node.isObjectLiteralExpression(current)) return null;
|
|
1818
1820
|
const prop = current.getProperty(key);
|
|
1819
1821
|
if (!prop || !import_ts_morph10.Node.isPropertyAssignment(prop)) return null;
|
|
@@ -1823,6 +1825,40 @@ function resolveConfigChain(configObj, path12) {
|
|
|
1823
1825
|
}
|
|
1824
1826
|
return current.getText();
|
|
1825
1827
|
}
|
|
1828
|
+
function rewriteDirnameRefs(text, relDir) {
|
|
1829
|
+
if (!relDir || relDir === ".") return text;
|
|
1830
|
+
const relForward = relDir.replace(/\\/g, "/");
|
|
1831
|
+
return text.replace(
|
|
1832
|
+
/\b((?:path\.)?(?:join|resolve))\s*\(\s*__dirname\s*,/g,
|
|
1833
|
+
`$1(__dirname, '${relForward}',`
|
|
1834
|
+
);
|
|
1835
|
+
}
|
|
1836
|
+
function ensureFsImport(sf) {
|
|
1837
|
+
const hasFs = sf.getImportDeclarations().some(
|
|
1838
|
+
(d) => d.getModuleSpecifierValue() === "fs" && (d.getNamespaceImport() || d.getDefaultImport())
|
|
1839
|
+
);
|
|
1840
|
+
if (hasFs) return;
|
|
1841
|
+
sf.addImportDeclaration({
|
|
1842
|
+
moduleSpecifier: "fs",
|
|
1843
|
+
namespaceImport: "fs"
|
|
1844
|
+
});
|
|
1845
|
+
}
|
|
1846
|
+
function ensureJoinImport(sf) {
|
|
1847
|
+
const pathImports = sf.getImportDeclarations().filter((d) => d.getModuleSpecifierValue() === "path");
|
|
1848
|
+
if (pathImports.some(
|
|
1849
|
+
(d) => d.getNamedImports().some((ni) => ni.getName() === "join")
|
|
1850
|
+
)) {
|
|
1851
|
+
return;
|
|
1852
|
+
}
|
|
1853
|
+
if (pathImports.length > 0) {
|
|
1854
|
+
pathImports[0].addNamedImport("join");
|
|
1855
|
+
return;
|
|
1856
|
+
}
|
|
1857
|
+
sf.addImportDeclaration({
|
|
1858
|
+
moduleSpecifier: "path",
|
|
1859
|
+
namedImports: ["join"]
|
|
1860
|
+
});
|
|
1861
|
+
}
|
|
1826
1862
|
async function main10() {
|
|
1827
1863
|
const srcDir = import_path10.default.join(getCwd(), "src");
|
|
1828
1864
|
const relCwd = (fp) => import_path10.default.relative(getCwd(), fp);
|
|
@@ -1868,12 +1904,15 @@ async function main10() {
|
|
|
1868
1904
|
});
|
|
1869
1905
|
if (propsToRemove.length > 0) {
|
|
1870
1906
|
const filesToSaveAfterInlining = /* @__PURE__ */ new Set();
|
|
1907
|
+
const appConfigDir = import_path10.default.dirname(appConfigAbsPath);
|
|
1871
1908
|
for (const removedProp of propsToRemove) {
|
|
1872
1909
|
const key = removedProp.getName();
|
|
1873
1910
|
for (const sf of appConfigProject.getSourceFiles()) {
|
|
1874
1911
|
if (sf.getFilePath() === appConfigAbsPath) continue;
|
|
1875
1912
|
if (!sf.getFilePath().includes("/src/")) continue;
|
|
1876
1913
|
if (sf.getFilePath().includes("/node_modules/")) continue;
|
|
1914
|
+
const targetDir = import_path10.default.dirname(sf.getFilePath());
|
|
1915
|
+
const relDirFromTarget = import_path10.default.relative(targetDir, appConfigDir);
|
|
1877
1916
|
let madeReplacement = true;
|
|
1878
1917
|
while (madeReplacement) {
|
|
1879
1918
|
madeReplacement = false;
|
|
@@ -1898,9 +1937,19 @@ async function main10() {
|
|
|
1898
1937
|
);
|
|
1899
1938
|
continue;
|
|
1900
1939
|
}
|
|
1901
|
-
|
|
1940
|
+
const adjustedValue = rewriteDirnameRefs(
|
|
1941
|
+
resolvedValue,
|
|
1942
|
+
relDirFromTarget
|
|
1943
|
+
);
|
|
1944
|
+
node.replaceWithText(adjustedValue);
|
|
1945
|
+
if (/\bfs\s*\./.test(adjustedValue)) {
|
|
1946
|
+
ensureFsImport(sf);
|
|
1947
|
+
}
|
|
1948
|
+
if (/\bjoin\s*\(/.test(adjustedValue)) {
|
|
1949
|
+
ensureJoinImport(sf);
|
|
1950
|
+
}
|
|
1902
1951
|
console.log(
|
|
1903
|
-
` Inlined applicationConfig.${accessPath.join(".")} \u2192 ${
|
|
1952
|
+
` Inlined applicationConfig.${accessPath.join(".")} \u2192 ${adjustedValue} in ${import_path10.default.relative(getCwd(), sf.getFilePath())}`
|
|
1904
1953
|
);
|
|
1905
1954
|
filesToSaveAfterInlining.add(sf);
|
|
1906
1955
|
madeReplacement = true;
|
|
@@ -2000,7 +2049,486 @@ Done. Converted ${convertedCount} config file(s), replaced ${totalReplaced} rout
|
|
|
2000
2049
|
// src/migrations/v2.0/migrate-scopes.ts
|
|
2001
2050
|
var import_ts_morph11 = require("ts-morph");
|
|
2002
2051
|
var import_path11 = __toESM(require("path"));
|
|
2003
|
-
|
|
2052
|
+
|
|
2053
|
+
// ../commons/src/scopes.ts
|
|
2054
|
+
var z3 = __toESM(require("zod/v4"));
|
|
2055
|
+
var qs = __toESM(require("qs"));
|
|
2056
|
+
|
|
2057
|
+
// ../commons/src/uuid.ts
|
|
2058
|
+
var import_uuid = require("uuid");
|
|
2059
|
+
var z = __toESM(require("zod/v4"));
|
|
2060
|
+
var UUID = z.uuid().brand("UUID");
|
|
2061
|
+
|
|
2062
|
+
// ../commons/src/authentication.ts
|
|
2063
|
+
var import_jwt_decode = __toESM(require("jwt-decode"));
|
|
2064
|
+
var z2 = __toESM(require("zod/v4"));
|
|
2065
|
+
var TokenUserType = z2.enum(["user", "system"]);
|
|
2066
|
+
var TokenWithBearer = z2.string().regex(/^Bearer\s/);
|
|
2067
|
+
|
|
2068
|
+
// ../commons/src/scopes.ts
|
|
2069
|
+
var JurisdictionFilter = z3.enum(["administrativeArea", "location", "all"]).describe(
|
|
2070
|
+
"Filters based on user jurisdiction relative to their office location in hierarchy."
|
|
2071
|
+
);
|
|
2072
|
+
var UserFilter = z3.enum(["user"]).describe("Filters based on the user. Limits to self.");
|
|
2073
|
+
var RecordScopeTypeV2 = z3.enum([
|
|
2074
|
+
"record.search",
|
|
2075
|
+
"record.create",
|
|
2076
|
+
"record.read",
|
|
2077
|
+
"record.declare",
|
|
2078
|
+
"record.notify",
|
|
2079
|
+
"record.edit",
|
|
2080
|
+
"record.reject",
|
|
2081
|
+
"record.archive",
|
|
2082
|
+
"record.review-duplicates",
|
|
2083
|
+
"record.register",
|
|
2084
|
+
"record.print-certified-copies",
|
|
2085
|
+
"record.request-correction",
|
|
2086
|
+
"record.correct",
|
|
2087
|
+
"record.unassign-others",
|
|
2088
|
+
"record.custom-action"
|
|
2089
|
+
]);
|
|
2090
|
+
var PlainScopeType = z3.enum([
|
|
2091
|
+
// Misc. system scopes
|
|
2092
|
+
"bypassratelimit",
|
|
2093
|
+
"record.reindex",
|
|
2094
|
+
"user.data-seeding",
|
|
2095
|
+
"integration.create",
|
|
2096
|
+
"record.import",
|
|
2097
|
+
"config.update-all",
|
|
2098
|
+
"attachment.upload",
|
|
2099
|
+
"profile.electronic-signature",
|
|
2100
|
+
"user.read-only-my-audit",
|
|
2101
|
+
// Performance dashboard
|
|
2102
|
+
"performance.read",
|
|
2103
|
+
"performance.read-dashboards",
|
|
2104
|
+
"performance.vital-statistics-export",
|
|
2105
|
+
// Scopes used exclusively by countryconfig integration token
|
|
2106
|
+
"record.confirm-registration",
|
|
2107
|
+
"record.reject-registration"
|
|
2108
|
+
]);
|
|
2109
|
+
var scopeByEvent = z3.preprocess(
|
|
2110
|
+
(val) => val === void 0 ? void 0 : [val].flat(),
|
|
2111
|
+
z3.array(z3.string()).optional()
|
|
2112
|
+
).describe("Event type, e.g. birth, death");
|
|
2113
|
+
var scopeOptionsPlaceEvent = z3.object({
|
|
2114
|
+
event: scopeByEvent,
|
|
2115
|
+
placeOfEvent: JurisdictionFilter.optional()
|
|
2116
|
+
}).describe("Options applicable to all record scopes.");
|
|
2117
|
+
var scopeOptionsDeclared = scopeOptionsPlaceEvent.extend({
|
|
2118
|
+
declaredIn: JurisdictionFilter.optional(),
|
|
2119
|
+
declaredBy: UserFilter.optional()
|
|
2120
|
+
}).describe("Options applicable to actions that may take place after DECLARE");
|
|
2121
|
+
var AllRecordScopeOptions = scopeOptionsDeclared.extend({
|
|
2122
|
+
registeredIn: JurisdictionFilter.optional(),
|
|
2123
|
+
registeredBy: UserFilter.optional()
|
|
2124
|
+
}).describe(
|
|
2125
|
+
"Options applicable to actions that may take place after REGISTER, with full filtering capabilities."
|
|
2126
|
+
);
|
|
2127
|
+
var CustomActionScopeOptions = AllRecordScopeOptions.extend({
|
|
2128
|
+
customActionTypes: z3.preprocess(
|
|
2129
|
+
(val) => val === void 0 ? void 0 : [val].flat(),
|
|
2130
|
+
z3.array(z3.string()).optional()
|
|
2131
|
+
).describe("Allowed custom action types")
|
|
2132
|
+
});
|
|
2133
|
+
var AccessLevelOptions = z3.object({
|
|
2134
|
+
accessLevel: JurisdictionFilter.optional()
|
|
2135
|
+
});
|
|
2136
|
+
var WorkqueueOrDashboardOptions = z3.object({
|
|
2137
|
+
ids: z3.preprocess(
|
|
2138
|
+
(val) => val === void 0 ? void 0 : [val].flat(),
|
|
2139
|
+
z3.array(z3.string())
|
|
2140
|
+
).describe("Must contain a list of workqueue or dashboard ids.")
|
|
2141
|
+
});
|
|
2142
|
+
var AllScopeOptions = z3.object({
|
|
2143
|
+
...AllRecordScopeOptions.shape,
|
|
2144
|
+
...AccessLevelOptions.shape,
|
|
2145
|
+
...WorkqueueOrDashboardOptions.shape
|
|
2146
|
+
});
|
|
2147
|
+
var ScopeOptionKey = AllScopeOptions.keyof();
|
|
2148
|
+
var ResolvedScopeOptionsPlaceEvent = z3.object({
|
|
2149
|
+
event: scopeByEvent,
|
|
2150
|
+
placeOfEvent: UUID.nullish()
|
|
2151
|
+
}).describe(
|
|
2152
|
+
"Resolved options applicable to all record scopes, with location ID instead of jurisdiction filter."
|
|
2153
|
+
);
|
|
2154
|
+
var ResolvedScopeOptionsDeclared = ResolvedScopeOptionsPlaceEvent.extend({
|
|
2155
|
+
declaredIn: UUID.nullish(),
|
|
2156
|
+
declaredBy: z3.string().optional()
|
|
2157
|
+
}).describe(
|
|
2158
|
+
"Resolved options applicable to actions that may take place after DECLARE, with location ID and user ID instead of filters."
|
|
2159
|
+
);
|
|
2160
|
+
var ResolvedScopeOptionsFull = ResolvedScopeOptionsDeclared.extend({
|
|
2161
|
+
registeredIn: UUID.nullish(),
|
|
2162
|
+
registeredBy: z3.string().optional()
|
|
2163
|
+
}).describe(
|
|
2164
|
+
"Resolved options applicable to actions that may take place after REGISTER, with full filtering capabilities and location/user IDs instead of filters."
|
|
2165
|
+
);
|
|
2166
|
+
var ScopesWithPlaceEventOptions = RecordScopeTypeV2.extract([
|
|
2167
|
+
"record.create",
|
|
2168
|
+
"record.declare",
|
|
2169
|
+
"record.notify"
|
|
2170
|
+
]);
|
|
2171
|
+
var ScopesWithDeclaredOptions = RecordScopeTypeV2.extract([
|
|
2172
|
+
"record.edit",
|
|
2173
|
+
"record.reject",
|
|
2174
|
+
"record.archive",
|
|
2175
|
+
"record.review-duplicates",
|
|
2176
|
+
"record.register"
|
|
2177
|
+
]);
|
|
2178
|
+
var ScopesWithFullOptions = RecordScopeTypeV2.extract([
|
|
2179
|
+
"record.search",
|
|
2180
|
+
"record.read",
|
|
2181
|
+
"record.request-correction",
|
|
2182
|
+
"record.correct",
|
|
2183
|
+
"record.unassign-others"
|
|
2184
|
+
]);
|
|
2185
|
+
var ScopeOptionsPrintCertifiedCopies = AllRecordScopeOptions.extend({
|
|
2186
|
+
templates: z3.preprocess(
|
|
2187
|
+
(val) => val === void 0 ? void 0 : [val].flat(),
|
|
2188
|
+
z3.array(z3.string()).optional()
|
|
2189
|
+
).describe(
|
|
2190
|
+
"Template IDs for certified copies. Controls which certificate templates are returned to the client via the config service. Certificate printing is a client-side operation \u2014 this option is not validated when the printCertificate action is submitted."
|
|
2191
|
+
)
|
|
2192
|
+
});
|
|
2193
|
+
var RecordScopeV2 = z3.discriminatedUnion("type", [
|
|
2194
|
+
z3.object({
|
|
2195
|
+
type: ScopesWithPlaceEventOptions,
|
|
2196
|
+
options: scopeOptionsPlaceEvent.optional()
|
|
2197
|
+
}),
|
|
2198
|
+
z3.object({
|
|
2199
|
+
type: ScopesWithDeclaredOptions,
|
|
2200
|
+
options: scopeOptionsDeclared.optional()
|
|
2201
|
+
}),
|
|
2202
|
+
z3.object({
|
|
2203
|
+
type: ScopesWithFullOptions,
|
|
2204
|
+
options: AllRecordScopeOptions.optional()
|
|
2205
|
+
}),
|
|
2206
|
+
z3.object({
|
|
2207
|
+
type: z3.literal("record.custom-action"),
|
|
2208
|
+
options: CustomActionScopeOptions.optional()
|
|
2209
|
+
}),
|
|
2210
|
+
z3.object({
|
|
2211
|
+
type: z3.literal("record.print-certified-copies"),
|
|
2212
|
+
options: ScopeOptionsPrintCertifiedCopies.optional()
|
|
2213
|
+
})
|
|
2214
|
+
]).describe(
|
|
2215
|
+
"Scopes used to check user's permission to perform actions on a record."
|
|
2216
|
+
);
|
|
2217
|
+
var ResolvedRecordScopeV2 = z3.discriminatedUnion("type", [
|
|
2218
|
+
z3.object({
|
|
2219
|
+
type: ScopesWithPlaceEventOptions,
|
|
2220
|
+
options: ResolvedScopeOptionsPlaceEvent.optional()
|
|
2221
|
+
}),
|
|
2222
|
+
z3.object({
|
|
2223
|
+
type: ScopesWithDeclaredOptions,
|
|
2224
|
+
options: ResolvedScopeOptionsDeclared.optional()
|
|
2225
|
+
}),
|
|
2226
|
+
z3.object({
|
|
2227
|
+
type: ScopesWithFullOptions,
|
|
2228
|
+
options: ResolvedScopeOptionsFull.optional()
|
|
2229
|
+
}),
|
|
2230
|
+
z3.object({
|
|
2231
|
+
type: z3.literal("record.print-certified-copies"),
|
|
2232
|
+
options: ResolvedScopeOptionsFull.extend({
|
|
2233
|
+
templates: z3.array(z3.string()).optional()
|
|
2234
|
+
}).optional()
|
|
2235
|
+
})
|
|
2236
|
+
]).describe("Resolved scope with location/user IDs instead of filters.");
|
|
2237
|
+
var SystemScopeType = z3.enum([
|
|
2238
|
+
"organisation.read-locations",
|
|
2239
|
+
"user.read",
|
|
2240
|
+
"user.create",
|
|
2241
|
+
"user.edit"
|
|
2242
|
+
]);
|
|
2243
|
+
var Scope2 = z3.discriminatedUnion("type", [
|
|
2244
|
+
z3.object({ type: PlainScopeType }),
|
|
2245
|
+
...RecordScopeV2.options,
|
|
2246
|
+
z3.object({ type: SystemScopeType, options: AccessLevelOptions.optional() }),
|
|
2247
|
+
z3.object({
|
|
2248
|
+
type: z3.literal("workqueue"),
|
|
2249
|
+
options: WorkqueueOrDashboardOptions
|
|
2250
|
+
}),
|
|
2251
|
+
z3.object({
|
|
2252
|
+
type: z3.literal("dashboard.view"),
|
|
2253
|
+
options: WorkqueueOrDashboardOptions
|
|
2254
|
+
})
|
|
2255
|
+
]);
|
|
2256
|
+
var ScopeType2 = z3.enum([
|
|
2257
|
+
...SystemScopeType.options,
|
|
2258
|
+
...RecordScopeTypeV2.options,
|
|
2259
|
+
...PlainScopeType.options,
|
|
2260
|
+
"workqueue",
|
|
2261
|
+
"dashboard.view"
|
|
2262
|
+
]);
|
|
2263
|
+
var flattenScope = (scope) => ({
|
|
2264
|
+
type: scope.type,
|
|
2265
|
+
..."options" in scope ? scope.options : {}
|
|
2266
|
+
});
|
|
2267
|
+
var unflattenScope = (input) => {
|
|
2268
|
+
const { type, ...options } = input;
|
|
2269
|
+
return { type, options };
|
|
2270
|
+
};
|
|
2271
|
+
var EncodedScope2 = z3.string().brand("EncodedScope");
|
|
2272
|
+
var encodeScope = (scope) => {
|
|
2273
|
+
const flattened = flattenScope(scope);
|
|
2274
|
+
return qs.stringify(flattened, {
|
|
2275
|
+
arrayFormat: "comma",
|
|
2276
|
+
allowDots: true,
|
|
2277
|
+
addQueryPrefix: false,
|
|
2278
|
+
encode: false
|
|
2279
|
+
});
|
|
2280
|
+
};
|
|
2281
|
+
var decodeScope = (query) => {
|
|
2282
|
+
const scope = qs.parse(query, {
|
|
2283
|
+
ignoreQueryPrefix: true,
|
|
2284
|
+
comma: true,
|
|
2285
|
+
allowDots: true
|
|
2286
|
+
});
|
|
2287
|
+
const unflattenedScope = unflattenScope(scope);
|
|
2288
|
+
return Scope2.safeParse(unflattenedScope)?.data;
|
|
2289
|
+
};
|
|
2290
|
+
var DEFAULT_SCOPE_OPTIONS = {
|
|
2291
|
+
placeOfEvent: JurisdictionFilter.enum.all,
|
|
2292
|
+
accessLevel: JurisdictionFilter.enum.all
|
|
2293
|
+
};
|
|
2294
|
+
|
|
2295
|
+
// ../commons/src/scopes.deprecated.do-not-use.ts
|
|
2296
|
+
var z4 = __toESM(require("zod/v4"));
|
|
2297
|
+
var rawConfigurableScopeRegex = /^([a-zA-Z][a-zA-Z0-9.-]*(?:\.[a-zA-Z0-9.-]+)*)\[((?:\w+=[\w.-]+(?:\|[\w.-]+)*)(?:,[\w]+=[\w.-]+(?:\|[\w.-]+)*)*)\]$/;
|
|
2298
|
+
var rawConfigurableScope = z4.string().regex(rawConfigurableScopeRegex);
|
|
2299
|
+
var SearchScope = z4.object({
|
|
2300
|
+
type: z4.literal("search"),
|
|
2301
|
+
options: z4.object({
|
|
2302
|
+
event: z4.array(z4.string()).length(1),
|
|
2303
|
+
access: z4.array(z4.enum(["my-jurisdiction", "all"])).length(1)
|
|
2304
|
+
})
|
|
2305
|
+
});
|
|
2306
|
+
var CreateUserScope = z4.object({
|
|
2307
|
+
type: z4.literal("user.create"),
|
|
2308
|
+
options: z4.object({
|
|
2309
|
+
role: z4.array(z4.string())
|
|
2310
|
+
})
|
|
2311
|
+
});
|
|
2312
|
+
var EditUserScope = z4.object({
|
|
2313
|
+
type: z4.literal("user.edit"),
|
|
2314
|
+
options: z4.object({
|
|
2315
|
+
role: z4.array(z4.string())
|
|
2316
|
+
})
|
|
2317
|
+
});
|
|
2318
|
+
var WorkqueueScope = z4.object({
|
|
2319
|
+
type: z4.literal("workqueue"),
|
|
2320
|
+
options: z4.object({
|
|
2321
|
+
id: z4.array(z4.string())
|
|
2322
|
+
})
|
|
2323
|
+
});
|
|
2324
|
+
var PrintCertifiedCopiesScope = z4.object({
|
|
2325
|
+
type: z4.literal("record.registered.print-certified-copies"),
|
|
2326
|
+
options: z4.object({
|
|
2327
|
+
event: z4.array(z4.string()).describe("Event type, e.g. birth, death"),
|
|
2328
|
+
templates: z4.array(z4.string()).optional().describe(
|
|
2329
|
+
"Template IDs for certified copies. If not provided, all templates will be used."
|
|
2330
|
+
)
|
|
2331
|
+
})
|
|
2332
|
+
});
|
|
2333
|
+
var LegacyRecordScope = z4.object({
|
|
2334
|
+
type: z4.enum([
|
|
2335
|
+
"record.create",
|
|
2336
|
+
"record.read",
|
|
2337
|
+
"record.declare",
|
|
2338
|
+
"record.notify",
|
|
2339
|
+
"record.declared.edit",
|
|
2340
|
+
"record.declared.validate",
|
|
2341
|
+
"record.declared.reject",
|
|
2342
|
+
"record.declared.archive",
|
|
2343
|
+
"record.declared.review-duplicates",
|
|
2344
|
+
"record.register",
|
|
2345
|
+
"record.registered.request-correction",
|
|
2346
|
+
"record.registered.correct",
|
|
2347
|
+
"record.unassign-others"
|
|
2348
|
+
]),
|
|
2349
|
+
options: z4.object({
|
|
2350
|
+
event: z4.array(z4.string()).describe("Event type, e.g. birth, death")
|
|
2351
|
+
})
|
|
2352
|
+
}).describe(
|
|
2353
|
+
"Scopes used to check user's permission to perform actions on a record."
|
|
2354
|
+
);
|
|
2355
|
+
var ConfigurableRawScopes = z4.discriminatedUnion("type", [
|
|
2356
|
+
SearchScope,
|
|
2357
|
+
LegacyRecordScope,
|
|
2358
|
+
PrintCertifiedCopiesScope,
|
|
2359
|
+
CreateUserScope,
|
|
2360
|
+
EditUserScope,
|
|
2361
|
+
WorkqueueScope
|
|
2362
|
+
]);
|
|
2363
|
+
function getScopeOptions(rawOptions) {
|
|
2364
|
+
return rawOptions.split(",").reduce((acc, option) => {
|
|
2365
|
+
const [key, value] = option.split("=");
|
|
2366
|
+
acc[key] = value.split("|");
|
|
2367
|
+
return acc;
|
|
2368
|
+
}, {});
|
|
2369
|
+
}
|
|
2370
|
+
function parseConfigurableScope(scope) {
|
|
2371
|
+
const maybeConfigurableScope = rawConfigurableScope.safeParse(scope);
|
|
2372
|
+
if (!maybeConfigurableScope.success) {
|
|
2373
|
+
return;
|
|
2374
|
+
}
|
|
2375
|
+
const rawScope = maybeConfigurableScope.data;
|
|
2376
|
+
const [, type, rawOptions] = rawScope.match(rawConfigurableScopeRegex) ?? [];
|
|
2377
|
+
const options = getScopeOptions(rawOptions);
|
|
2378
|
+
const parsedScope = {
|
|
2379
|
+
type,
|
|
2380
|
+
options
|
|
2381
|
+
};
|
|
2382
|
+
const result = ConfigurableRawScopes.safeParse(parsedScope);
|
|
2383
|
+
return result.success ? result.data : void 0;
|
|
2384
|
+
}
|
|
2385
|
+
var SCOPES = {
|
|
2386
|
+
BYPASSRATELIMIT: "bypassratelimit",
|
|
2387
|
+
RECORD_REINDEX: "record.reindex",
|
|
2388
|
+
RECORD_IMPORT: "record.import",
|
|
2389
|
+
ATTACHMENT_UPLOAD: "attachment.upload",
|
|
2390
|
+
USER_DATA_SEEDING: "user.data-seeding",
|
|
2391
|
+
INTEGRATION_CREATE: "integration.create",
|
|
2392
|
+
PERFORMANCE_EXPORT_VITAL_STATISTICS: "performance.vital-statistics-export",
|
|
2393
|
+
PROFILE_ELECTRONIC_SIGNATURE: "profile.electronic-signature",
|
|
2394
|
+
PERFORMANCE_READ: "performance.read",
|
|
2395
|
+
PERFORMANCE_READ_DASHBOARDS: "performance.read-dashboards",
|
|
2396
|
+
CONFIG_UPDATE_ALL: "config.update-all",
|
|
2397
|
+
ORGANISATION_READ_LOCATIONS: "organisation.read-locations",
|
|
2398
|
+
ORGANISATION_READ_LOCATIONS_MY_OFFICE: "organisation.read-locations:my-office",
|
|
2399
|
+
ORGANISATION_READ_LOCATIONS_MY_JURISDICTION: "organisation.read-locations:my-jurisdiction",
|
|
2400
|
+
USER_CREATE: "user.create:all",
|
|
2401
|
+
USER_READ: "user.read:all",
|
|
2402
|
+
USER_UPDATE: "user.update:all",
|
|
2403
|
+
USER_READ_MY_OFFICE: "user.read:my-office",
|
|
2404
|
+
USER_READ_MY_JURISDICTION: "user.read:my-jurisdiction",
|
|
2405
|
+
USER_READ_ONLY_MY_AUDIT: "user.read:only-my-audit",
|
|
2406
|
+
USER_CREATE_MY_JURISDICTION: "user.create:my-jurisdiction",
|
|
2407
|
+
USER_UPDATE_MY_JURISDICTION: "user.update:my-jurisdiction"
|
|
2408
|
+
};
|
|
2409
|
+
var literalScopeToV2ScopeMap = {
|
|
2410
|
+
[SCOPES.BYPASSRATELIMIT]: { type: "bypassratelimit" },
|
|
2411
|
+
[SCOPES.RECORD_REINDEX]: { type: "record.reindex" },
|
|
2412
|
+
[SCOPES.RECORD_IMPORT]: { type: "record.import" },
|
|
2413
|
+
[SCOPES.ATTACHMENT_UPLOAD]: { type: "attachment.upload" },
|
|
2414
|
+
[SCOPES.USER_DATA_SEEDING]: { type: "user.data-seeding" },
|
|
2415
|
+
[SCOPES.INTEGRATION_CREATE]: { type: "integration.create" },
|
|
2416
|
+
[SCOPES.PERFORMANCE_EXPORT_VITAL_STATISTICS]: {
|
|
2417
|
+
type: "performance.vital-statistics-export"
|
|
2418
|
+
},
|
|
2419
|
+
[SCOPES.PROFILE_ELECTRONIC_SIGNATURE]: {
|
|
2420
|
+
type: "profile.electronic-signature"
|
|
2421
|
+
},
|
|
2422
|
+
[SCOPES.PERFORMANCE_READ]: { type: "performance.read" },
|
|
2423
|
+
[SCOPES.PERFORMANCE_READ_DASHBOARDS]: { type: "performance.read-dashboards" },
|
|
2424
|
+
[SCOPES.CONFIG_UPDATE_ALL]: { type: "config.update-all" },
|
|
2425
|
+
[SCOPES.ORGANISATION_READ_LOCATIONS]: {
|
|
2426
|
+
type: "organisation.read-locations"
|
|
2427
|
+
},
|
|
2428
|
+
[SCOPES.ORGANISATION_READ_LOCATIONS_MY_OFFICE]: {
|
|
2429
|
+
type: "organisation.read-locations",
|
|
2430
|
+
options: { accessLevel: "location" }
|
|
2431
|
+
},
|
|
2432
|
+
[SCOPES.ORGANISATION_READ_LOCATIONS_MY_JURISDICTION]: {
|
|
2433
|
+
type: "organisation.read-locations",
|
|
2434
|
+
options: { accessLevel: "administrativeArea" }
|
|
2435
|
+
},
|
|
2436
|
+
[SCOPES.USER_CREATE]: { type: "user.create" },
|
|
2437
|
+
[SCOPES.USER_CREATE_MY_JURISDICTION]: {
|
|
2438
|
+
type: "user.create",
|
|
2439
|
+
options: { accessLevel: "administrativeArea" }
|
|
2440
|
+
},
|
|
2441
|
+
[SCOPES.USER_READ]: { type: "user.read" },
|
|
2442
|
+
[SCOPES.USER_READ_MY_OFFICE]: {
|
|
2443
|
+
type: "user.read",
|
|
2444
|
+
options: { accessLevel: "location" }
|
|
2445
|
+
},
|
|
2446
|
+
[SCOPES.USER_READ_MY_JURISDICTION]: {
|
|
2447
|
+
type: "user.read",
|
|
2448
|
+
options: { accessLevel: "administrativeArea" }
|
|
2449
|
+
},
|
|
2450
|
+
[SCOPES.USER_READ_ONLY_MY_AUDIT]: { type: "user.read-only-my-audit" },
|
|
2451
|
+
[SCOPES.USER_UPDATE]: { type: "user.edit" },
|
|
2452
|
+
[SCOPES.USER_UPDATE_MY_JURISDICTION]: {
|
|
2453
|
+
type: "user.edit",
|
|
2454
|
+
options: { accessLevel: "administrativeArea" }
|
|
2455
|
+
}
|
|
2456
|
+
};
|
|
2457
|
+
function parseLiteralScope(scope) {
|
|
2458
|
+
if (scope in literalScopeToV2ScopeMap) {
|
|
2459
|
+
return literalScopeToV2ScopeMap[scope];
|
|
2460
|
+
}
|
|
2461
|
+
return void 0;
|
|
2462
|
+
}
|
|
2463
|
+
var v1ToV2ConfigScopeTypeMap = {
|
|
2464
|
+
search: "record.search",
|
|
2465
|
+
workqueue: "workqueue",
|
|
2466
|
+
"user.create": "user.create",
|
|
2467
|
+
"user.edit": "user.edit",
|
|
2468
|
+
"record.create": "record.create",
|
|
2469
|
+
"record.read": "record.read",
|
|
2470
|
+
"record.declare": "record.declare",
|
|
2471
|
+
"record.notify": "record.notify",
|
|
2472
|
+
"record.register": "record.register",
|
|
2473
|
+
"record.unassign-others": "record.unassign-others",
|
|
2474
|
+
"record.declared.reject": "record.reject",
|
|
2475
|
+
"record.declared.archive": "record.archive",
|
|
2476
|
+
"record.declared.review-duplicates": "record.review-duplicates",
|
|
2477
|
+
"record.registered.print-certified-copies": "record.print-certified-copies",
|
|
2478
|
+
"record.registered.request-correction": "record.request-correction",
|
|
2479
|
+
"record.registered.correct": "record.correct",
|
|
2480
|
+
"record.declared.edit": "record.edit",
|
|
2481
|
+
"record.declared.validate": "record.custom-action"
|
|
2482
|
+
};
|
|
2483
|
+
var legacyScopeToV2Scope = (v1Scope) => {
|
|
2484
|
+
const configurableV1Scope = parseConfigurableScope(v1Scope);
|
|
2485
|
+
const literalV1Scope = parseLiteralScope(v1Scope);
|
|
2486
|
+
if (!configurableV1Scope && !literalV1Scope) {
|
|
2487
|
+
throw new Error(`Invalid V1 scope: ${v1Scope}`);
|
|
2488
|
+
}
|
|
2489
|
+
if (literalV1Scope) {
|
|
2490
|
+
return encodeScope(literalV1Scope);
|
|
2491
|
+
}
|
|
2492
|
+
if (configurableV1Scope) {
|
|
2493
|
+
const type = v1ToV2ConfigScopeTypeMap[configurableV1Scope.type];
|
|
2494
|
+
if (type === void 0) {
|
|
2495
|
+
throw new Error(`Unsupported V1 scope type: ${configurableV1Scope.type}`);
|
|
2496
|
+
}
|
|
2497
|
+
if (configurableV1Scope.type === "workqueue") {
|
|
2498
|
+
return encodeScope({
|
|
2499
|
+
type: "workqueue",
|
|
2500
|
+
options: {
|
|
2501
|
+
ids: configurableV1Scope.options.id || []
|
|
2502
|
+
}
|
|
2503
|
+
});
|
|
2504
|
+
}
|
|
2505
|
+
if (configurableV1Scope.type === "search") {
|
|
2506
|
+
return encodeScope({
|
|
2507
|
+
type,
|
|
2508
|
+
options: {
|
|
2509
|
+
event: configurableV1Scope.options.event || [],
|
|
2510
|
+
placeOfEvent: configurableV1Scope.options.access[0] === "my-jurisdiction" ? "administrativeArea" : "all"
|
|
2511
|
+
}
|
|
2512
|
+
});
|
|
2513
|
+
}
|
|
2514
|
+
if (configurableV1Scope.type === "record.declared.validate") {
|
|
2515
|
+
return encodeScope({
|
|
2516
|
+
type: "record.custom-action",
|
|
2517
|
+
options: {
|
|
2518
|
+
event: configurableV1Scope.options.event,
|
|
2519
|
+
customActionTypes: ["VALIDATE_DECLARATION"]
|
|
2520
|
+
}
|
|
2521
|
+
});
|
|
2522
|
+
}
|
|
2523
|
+
return encodeScope({
|
|
2524
|
+
type,
|
|
2525
|
+
options: configurableV1Scope.options
|
|
2526
|
+
});
|
|
2527
|
+
}
|
|
2528
|
+
throw new Error(`Unsupported V1 scope type: ${v1Scope}`);
|
|
2529
|
+
};
|
|
2530
|
+
|
|
2531
|
+
// src/migrations/v2.0/migrate-scopes.ts
|
|
2004
2532
|
var ROLES_FILE_RELATIVE_PATH = "src/data-seeding/roles/roles.ts";
|
|
2005
2533
|
var SCOPES_PROPERTY_NAME = "scopes";
|
|
2006
2534
|
var TOOLKIT_SCOPES_MODULE = "@opencrvs/toolkit/scopes";
|
|
@@ -2024,7 +2552,7 @@ function resolveLegacyScopeFromElement(element) {
|
|
|
2024
2552
|
}
|
|
2025
2553
|
const scopeKey = resolveScopeKeyFromElementAccess(element);
|
|
2026
2554
|
if (scopeKey) {
|
|
2027
|
-
const scopeValue =
|
|
2555
|
+
const scopeValue = SCOPES[scopeKey];
|
|
2028
2556
|
return typeof scopeValue === "string" ? scopeValue : null;
|
|
2029
2557
|
}
|
|
2030
2558
|
const expressionType = element.getType();
|
|
@@ -2048,7 +2576,7 @@ function migrateScopesArrays(rolesFilePath, project) {
|
|
|
2048
2576
|
const element = elements[index];
|
|
2049
2577
|
if (!import_ts_morph11.Node.isExpression(element)) continue;
|
|
2050
2578
|
const scopeKey = resolveScopeKeyFromElementAccess(element);
|
|
2051
|
-
if (scopeKey && !(scopeKey in
|
|
2579
|
+
if (scopeKey && !(scopeKey in SCOPES)) {
|
|
2052
2580
|
console.warn(
|
|
2053
2581
|
` [${import_path11.default.relative(getCwd(), rolesFilePath)}] Removing unknown scope reference: SCOPES.${scopeKey}`
|
|
2054
2582
|
);
|
|
@@ -2064,8 +2592,8 @@ function migrateScopesArrays(rolesFilePath, project) {
|
|
|
2064
2592
|
continue;
|
|
2065
2593
|
}
|
|
2066
2594
|
try {
|
|
2067
|
-
const migratedScope =
|
|
2068
|
-
const scope =
|
|
2595
|
+
const migratedScope = legacyScopeToV2Scope(legacyScope);
|
|
2596
|
+
const scope = decodeScope(migratedScope);
|
|
2069
2597
|
if (!scope) {
|
|
2070
2598
|
console.warn(
|
|
2071
2599
|
` [${import_path11.default.relative(getCwd(), rolesFilePath)}] Could not decode migrated scope '${migratedScope}'.`
|
|
@@ -2314,6 +2842,290 @@ Saving ${modifiedFiles.length} modified file(s)...`);
|
|
|
2314
2842
|
Done. Removed ${totalRemoved} deprecated import(s).`);
|
|
2315
2843
|
}
|
|
2316
2844
|
|
|
2845
|
+
// src/migrations/v2.0/migrate-workqueue-configs.ts
|
|
2846
|
+
var import_ts_morph13 = require("ts-morph");
|
|
2847
|
+
var import_path13 = __toESM(require("path"));
|
|
2848
|
+
var DEFINE_WORKQUEUES_NAME3 = "defineWorkqueues";
|
|
2849
|
+
var ACTIONS_PROPERTY_NAME5 = "actions";
|
|
2850
|
+
var ACTION_PROPERTY_NAME2 = "action";
|
|
2851
|
+
var CONDITIONALS_PROPERTY_NAME = "conditionals";
|
|
2852
|
+
var TYPE_PROPERTY_NAME7 = "type";
|
|
2853
|
+
var SLUG_PROPERTY_NAME = "slug";
|
|
2854
|
+
var SUPPORTED_WORKQUEUE_ACTION_TYPES = /* @__PURE__ */ new Set([
|
|
2855
|
+
"READ",
|
|
2856
|
+
"DELETE",
|
|
2857
|
+
"DECLARE",
|
|
2858
|
+
"REGISTER",
|
|
2859
|
+
"EDIT",
|
|
2860
|
+
"REJECT",
|
|
2861
|
+
"MARK_AS_DUPLICATE",
|
|
2862
|
+
"ARCHIVE",
|
|
2863
|
+
"PRINT_CERTIFICATE",
|
|
2864
|
+
"REQUEST_CORRECTION"
|
|
2865
|
+
]);
|
|
2866
|
+
function getWorkqueueLabel(workqueue) {
|
|
2867
|
+
const slugProperty = workqueue.getProperty(SLUG_PROPERTY_NAME);
|
|
2868
|
+
if (!slugProperty || !import_ts_morph13.Node.isPropertyAssignment(slugProperty)) {
|
|
2869
|
+
return "(unknown slug)";
|
|
2870
|
+
}
|
|
2871
|
+
const slugInitializer = slugProperty.getInitializer();
|
|
2872
|
+
if (!slugInitializer || !import_ts_morph13.Node.isStringLiteral(slugInitializer)) {
|
|
2873
|
+
return "(unknown slug)";
|
|
2874
|
+
}
|
|
2875
|
+
return slugInitializer.getLiteralValue();
|
|
2876
|
+
}
|
|
2877
|
+
function getActionTypeName(action) {
|
|
2878
|
+
const typeProperty = action.getProperty(TYPE_PROPERTY_NAME7);
|
|
2879
|
+
if (!typeProperty || !import_ts_morph13.Node.isPropertyAssignment(typeProperty)) {
|
|
2880
|
+
return null;
|
|
2881
|
+
}
|
|
2882
|
+
const typeInitializer = typeProperty.getInitializer();
|
|
2883
|
+
if (!typeInitializer) {
|
|
2884
|
+
return null;
|
|
2885
|
+
}
|
|
2886
|
+
if (import_ts_morph13.Node.isStringLiteral(typeInitializer)) {
|
|
2887
|
+
return typeInitializer.getLiteralValue();
|
|
2888
|
+
}
|
|
2889
|
+
if (import_ts_morph13.Node.isPropertyAccessExpression(typeInitializer)) {
|
|
2890
|
+
return typeInitializer.getName();
|
|
2891
|
+
}
|
|
2892
|
+
return null;
|
|
2893
|
+
}
|
|
2894
|
+
function isUnsupportedActionType(action) {
|
|
2895
|
+
const typeName = getActionTypeName(action);
|
|
2896
|
+
if (!typeName) {
|
|
2897
|
+
return false;
|
|
2898
|
+
}
|
|
2899
|
+
return !SUPPORTED_WORKQUEUE_ACTION_TYPES.has(typeName);
|
|
2900
|
+
}
|
|
2901
|
+
function migrateWorkqueueActions(workqueue, relPath) {
|
|
2902
|
+
const actionsProperty = workqueue.getProperty(ACTIONS_PROPERTY_NAME5);
|
|
2903
|
+
if (!actionsProperty || !import_ts_morph13.Node.isPropertyAssignment(actionsProperty)) {
|
|
2904
|
+
return 0;
|
|
2905
|
+
}
|
|
2906
|
+
const actionsInitializer = actionsProperty.getInitializer();
|
|
2907
|
+
if (!actionsInitializer || !import_ts_morph13.Node.isArrayLiteralExpression(actionsInitializer)) {
|
|
2908
|
+
return 0;
|
|
2909
|
+
}
|
|
2910
|
+
const workqueueLabel = getWorkqueueLabel(workqueue);
|
|
2911
|
+
const existingActionProperty = workqueue.getProperty(ACTION_PROPERTY_NAME2);
|
|
2912
|
+
if (existingActionProperty) {
|
|
2913
|
+
if (import_ts_morph13.Node.isPropertyAssignment(existingActionProperty)) {
|
|
2914
|
+
const existingActionInitializer = existingActionProperty.getInitializer();
|
|
2915
|
+
if (existingActionInitializer && import_ts_morph13.Node.isObjectLiteralExpression(existingActionInitializer)) {
|
|
2916
|
+
const conditionalsProperty2 = existingActionInitializer.getProperty(
|
|
2917
|
+
CONDITIONALS_PROPERTY_NAME
|
|
2918
|
+
);
|
|
2919
|
+
if (conditionalsProperty2) {
|
|
2920
|
+
conditionalsProperty2.remove();
|
|
2921
|
+
console.log(
|
|
2922
|
+
` [${relPath}] Removed deprecated 'conditionals' from 'action' on workqueue '${workqueueLabel}'`
|
|
2923
|
+
);
|
|
2924
|
+
}
|
|
2925
|
+
if (isUnsupportedActionType(existingActionInitializer)) {
|
|
2926
|
+
existingActionProperty.remove();
|
|
2927
|
+
console.log(
|
|
2928
|
+
` [${relPath}] Removed unsupported 'action' type on workqueue '${workqueueLabel}'`
|
|
2929
|
+
);
|
|
2930
|
+
}
|
|
2931
|
+
}
|
|
2932
|
+
}
|
|
2933
|
+
actionsProperty.remove();
|
|
2934
|
+
console.log(
|
|
2935
|
+
` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' (existing 'action' kept)`
|
|
2936
|
+
);
|
|
2937
|
+
return 1;
|
|
2938
|
+
}
|
|
2939
|
+
const actionCandidates = actionsInitializer.getElements().filter(
|
|
2940
|
+
(element) => import_ts_morph13.Node.isObjectLiteralExpression(element)
|
|
2941
|
+
);
|
|
2942
|
+
if (actionCandidates.length === 0) {
|
|
2943
|
+
actionsProperty.remove();
|
|
2944
|
+
console.log(
|
|
2945
|
+
` [${relPath}] Removed empty 'actions' from workqueue '${workqueueLabel}'`
|
|
2946
|
+
);
|
|
2947
|
+
return 1;
|
|
2948
|
+
}
|
|
2949
|
+
if (actionCandidates.length > 1) {
|
|
2950
|
+
const droppedCount = actionCandidates.length - 1;
|
|
2951
|
+
console.warn(
|
|
2952
|
+
` [${relPath}] Workqueue '${workqueueLabel}' has ${actionCandidates.length} actions; keeping first as 'action' and dropping ${droppedCount} extra action(s)`
|
|
2953
|
+
);
|
|
2954
|
+
}
|
|
2955
|
+
const conditionalsProperty = actionCandidates[0].getProperty(
|
|
2956
|
+
CONDITIONALS_PROPERTY_NAME
|
|
2957
|
+
);
|
|
2958
|
+
if (conditionalsProperty) {
|
|
2959
|
+
conditionalsProperty.remove();
|
|
2960
|
+
console.log(
|
|
2961
|
+
` [${relPath}] Removed deprecated 'conditionals' from migrated 'action' on workqueue '${workqueueLabel}'`
|
|
2962
|
+
);
|
|
2963
|
+
}
|
|
2964
|
+
if (isUnsupportedActionType(actionCandidates[0])) {
|
|
2965
|
+
actionsProperty.remove();
|
|
2966
|
+
console.log(
|
|
2967
|
+
` [${relPath}] Removed deprecated 'actions' from workqueue '${workqueueLabel}' because action type is unsupported`
|
|
2968
|
+
);
|
|
2969
|
+
return 1;
|
|
2970
|
+
}
|
|
2971
|
+
const firstActionText = actionCandidates[0].getText();
|
|
2972
|
+
workqueue.addPropertyAssignment({
|
|
2973
|
+
name: ACTION_PROPERTY_NAME2,
|
|
2974
|
+
initializer: firstActionText
|
|
2975
|
+
});
|
|
2976
|
+
actionsProperty.remove();
|
|
2977
|
+
console.log(
|
|
2978
|
+
` [${relPath}] Replaced 'actions' with 'action' on workqueue '${workqueueLabel}'`
|
|
2979
|
+
);
|
|
2980
|
+
return 1;
|
|
2981
|
+
}
|
|
2982
|
+
function processFile11(filePath, project) {
|
|
2983
|
+
const sourceFile = project.getSourceFile(filePath);
|
|
2984
|
+
if (!sourceFile) return 0;
|
|
2985
|
+
let migratedWorkqueues = 0;
|
|
2986
|
+
const relPath = import_path13.default.relative(getCwd(), filePath);
|
|
2987
|
+
const callExpressions = sourceFile.getDescendantsOfKind(
|
|
2988
|
+
import_ts_morph13.SyntaxKind.CallExpression
|
|
2989
|
+
);
|
|
2990
|
+
for (const call of callExpressions) {
|
|
2991
|
+
const expression = call.getExpression();
|
|
2992
|
+
if (!import_ts_morph13.Node.isIdentifier(expression) || expression.getText() !== DEFINE_WORKQUEUES_NAME3) {
|
|
2993
|
+
continue;
|
|
2994
|
+
}
|
|
2995
|
+
const args2 = call.getArguments();
|
|
2996
|
+
if (args2.length === 0) continue;
|
|
2997
|
+
const workqueuesArg = args2[0];
|
|
2998
|
+
if (!import_ts_morph13.Node.isArrayLiteralExpression(workqueuesArg)) continue;
|
|
2999
|
+
for (const element of workqueuesArg.getElements()) {
|
|
3000
|
+
if (!import_ts_morph13.Node.isObjectLiteralExpression(element)) continue;
|
|
3001
|
+
migratedWorkqueues += migrateWorkqueueActions(element, relPath);
|
|
3002
|
+
}
|
|
3003
|
+
}
|
|
3004
|
+
return migratedWorkqueues;
|
|
3005
|
+
}
|
|
3006
|
+
async function main13() {
|
|
3007
|
+
const srcDir = import_path13.default.join(getCwd(), "src");
|
|
3008
|
+
console.log(`Scanning for defineWorkqueues calls in: ${srcDir}
|
|
3009
|
+
`);
|
|
3010
|
+
const project = new import_ts_morph13.Project({
|
|
3011
|
+
tsConfigFilePath: import_path13.default.resolve(srcDir, "../tsconfig.json"),
|
|
3012
|
+
skipAddingFilesFromTsConfig: false
|
|
3013
|
+
});
|
|
3014
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
3015
|
+
const fp = sf.getFilePath();
|
|
3016
|
+
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
3017
|
+
});
|
|
3018
|
+
console.log(`Found ${sourceFiles.length} source file(s) to analyse.
|
|
3019
|
+
`);
|
|
3020
|
+
let totalMigrated = 0;
|
|
3021
|
+
const modifiedFiles = [];
|
|
3022
|
+
for (const sourceFile of sourceFiles) {
|
|
3023
|
+
const filePath = sourceFile.getFilePath();
|
|
3024
|
+
const migrated = processFile11(filePath, project);
|
|
3025
|
+
if (migrated > 0) {
|
|
3026
|
+
totalMigrated += migrated;
|
|
3027
|
+
modifiedFiles.push(filePath);
|
|
3028
|
+
}
|
|
3029
|
+
}
|
|
3030
|
+
if (modifiedFiles.length === 0) {
|
|
3031
|
+
console.log(
|
|
3032
|
+
"No deprecated workqueue 'actions' arrays found inside defineWorkqueues calls. Nothing to do."
|
|
3033
|
+
);
|
|
3034
|
+
return;
|
|
3035
|
+
}
|
|
3036
|
+
console.log(`
|
|
3037
|
+
Saving ${modifiedFiles.length} modified file(s)...`);
|
|
3038
|
+
for (const filePath of modifiedFiles) {
|
|
3039
|
+
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
3040
|
+
await sourceFile.save();
|
|
3041
|
+
console.log(` Saved: ${import_path13.default.relative(getCwd(), filePath)}`);
|
|
3042
|
+
}
|
|
3043
|
+
console.log(
|
|
3044
|
+
`
|
|
3045
|
+
Done. Migrated ${totalMigrated} deprecated workqueue 'actions' definition(s) to 'action'.`
|
|
3046
|
+
);
|
|
3047
|
+
}
|
|
3048
|
+
|
|
3049
|
+
// src/migrations/v2.0/remove-demo-scope.ts
|
|
3050
|
+
var import_path14 = __toESM(require("path"));
|
|
3051
|
+
var import_ts_morph14 = require("ts-morph");
|
|
3052
|
+
var ROLES_HANDLER_RELATIVE_PATH = "src/data-seeding/roles/handler.ts";
|
|
3053
|
+
async function main14() {
|
|
3054
|
+
const rolesHandlerPath = import_path14.default.join(getCwd(), ROLES_HANDLER_RELATIVE_PATH);
|
|
3055
|
+
const project = new import_ts_morph14.Project({
|
|
3056
|
+
tsConfigFilePath: import_path14.default.resolve(getCwd(), "tsconfig.json"),
|
|
3057
|
+
skipAddingFilesFromTsConfig: false
|
|
3058
|
+
});
|
|
3059
|
+
const sourceFile = project.getSourceFile(rolesHandlerPath);
|
|
3060
|
+
if (!sourceFile) {
|
|
3061
|
+
console.log(
|
|
3062
|
+
`No roles handler found at '${ROLES_HANDLER_RELATIVE_PATH}'. Nothing to do.`
|
|
3063
|
+
);
|
|
3064
|
+
return;
|
|
3065
|
+
}
|
|
3066
|
+
let changed = false;
|
|
3067
|
+
const constantsImport = sourceFile.getImportDeclaration(
|
|
3068
|
+
(decl) => decl.getModuleSpecifierValue() === "@countryconfig/constants"
|
|
3069
|
+
);
|
|
3070
|
+
if (constantsImport) {
|
|
3071
|
+
constantsImport.remove();
|
|
3072
|
+
changed = true;
|
|
3073
|
+
}
|
|
3074
|
+
const rolesHandler = sourceFile.getFunction("rolesHandler");
|
|
3075
|
+
if (!rolesHandler) {
|
|
3076
|
+
console.log(
|
|
3077
|
+
`No rolesHandler export found in '${ROLES_HANDLER_RELATIVE_PATH}'. Nothing to do.`
|
|
3078
|
+
);
|
|
3079
|
+
return;
|
|
3080
|
+
}
|
|
3081
|
+
const secondParam = rolesHandler.getParameters()[1];
|
|
3082
|
+
const secondParamName = secondParam?.getName();
|
|
3083
|
+
const responseToolkitIdentifier = secondParamName || "h";
|
|
3084
|
+
const currentBodyText = rolesHandler.getBodyText();
|
|
3085
|
+
const normalizedCurrent = currentBodyText?.replace(/\s+/g, " ").trim() ?? "";
|
|
3086
|
+
const normalizedDesired = `return ${responseToolkitIdentifier}.response(roles)`;
|
|
3087
|
+
if (normalizedCurrent !== normalizedDesired) {
|
|
3088
|
+
rolesHandler.setBodyText(`return ${responseToolkitIdentifier}.response(roles)`);
|
|
3089
|
+
changed = true;
|
|
3090
|
+
}
|
|
3091
|
+
if (!changed) {
|
|
3092
|
+
console.log(
|
|
3093
|
+
`No changes needed in '${ROLES_HANDLER_RELATIVE_PATH}'.`
|
|
3094
|
+
);
|
|
3095
|
+
return;
|
|
3096
|
+
}
|
|
3097
|
+
await sourceFile.save();
|
|
3098
|
+
console.log(
|
|
3099
|
+
`Updated '${ROLES_HANDLER_RELATIVE_PATH}' to remove demo scope behavior while preserving file structure.`
|
|
3100
|
+
);
|
|
3101
|
+
}
|
|
3102
|
+
|
|
3103
|
+
// src/migrations/v2.0/remove-hearth-migrations.ts
|
|
3104
|
+
var fs2 = __toESM(require("fs"));
|
|
3105
|
+
var import_path15 = __toESM(require("path"));
|
|
3106
|
+
var PATHS_TO_REMOVE = [
|
|
3107
|
+
{
|
|
3108
|
+
relativePath: "src/migrations/hearth",
|
|
3109
|
+
label: "Hearth migrations directory"
|
|
3110
|
+
},
|
|
3111
|
+
{
|
|
3112
|
+
relativePath: "src/migrations/user-mgnt",
|
|
3113
|
+
label: "user-mgnt migrations directory"
|
|
3114
|
+
},
|
|
3115
|
+
{ relativePath: "src/utils/hearth-helpers.ts", label: "Hearth helpers file" }
|
|
3116
|
+
];
|
|
3117
|
+
async function main15() {
|
|
3118
|
+
for (const { relativePath, label } of PATHS_TO_REMOVE) {
|
|
3119
|
+
const absolutePath = import_path15.default.join(getCwd(), relativePath);
|
|
3120
|
+
if (fs2.existsSync(absolutePath)) {
|
|
3121
|
+
fs2.rmSync(absolutePath, { recursive: true, force: true });
|
|
3122
|
+
console.log(`Removed ${label} '${relativePath}'.`);
|
|
3123
|
+
} else {
|
|
3124
|
+
console.log(`No ${label} found at '${relativePath}'.`);
|
|
3125
|
+
}
|
|
3126
|
+
}
|
|
3127
|
+
}
|
|
3128
|
+
|
|
2317
3129
|
// src/migrations/v2.0/index.ts
|
|
2318
3130
|
var cwd;
|
|
2319
3131
|
function getCwd() {
|
|
@@ -2333,6 +3145,7 @@ async function runUpgrade(ccwd) {
|
|
|
2333
3145
|
);
|
|
2334
3146
|
cwd = process.cwd();
|
|
2335
3147
|
}
|
|
3148
|
+
await main13();
|
|
2336
3149
|
await main();
|
|
2337
3150
|
await main2();
|
|
2338
3151
|
await main3();
|
|
@@ -2345,6 +3158,8 @@ async function runUpgrade(ccwd) {
|
|
|
2345
3158
|
await main10();
|
|
2346
3159
|
await main11();
|
|
2347
3160
|
await main12();
|
|
3161
|
+
await main14();
|
|
3162
|
+
await main15();
|
|
2348
3163
|
}
|
|
2349
3164
|
|
|
2350
3165
|
// src/cli.ts
|
|
@@ -2359,7 +3174,7 @@ Commands:
|
|
|
2359
3174
|
|
|
2360
3175
|
Run 'opencrvs <command> --help' for more information on a command.
|
|
2361
3176
|
`.trim();
|
|
2362
|
-
function
|
|
3177
|
+
function main16() {
|
|
2363
3178
|
const command = args[0];
|
|
2364
3179
|
if (!command || command === "--help" || command === "-h") {
|
|
2365
3180
|
console.log(USAGE);
|
|
@@ -2419,4 +3234,4 @@ function handleCheckTranslations() {
|
|
|
2419
3234
|
console.warn("This command is not implemented yet!");
|
|
2420
3235
|
process.exit(1);
|
|
2421
3236
|
}
|
|
2422
|
-
|
|
3237
|
+
main16();
|