@opencrvs/toolkit 2.0.0-rc.1f9315c → 2.0.0-rc.21b1468

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.
@@ -0,0 +1,73 @@
1
+ #!/usr/bin/env node
2
+
3
+ /*
4
+ * This Source Code Form is subject to the terms of the Mozilla Public
5
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
6
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/.
7
+ *
8
+ * OpenCRVS is also distributed under the terms of the Civil Registration
9
+ * & Healthcare Disclaimer located at http://opencrvs.org/license.
10
+ *
11
+ * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
12
+ */
13
+
14
+ const { execSync } = require('child_process')
15
+ const path = require('path')
16
+ const fs = require('fs')
17
+
18
+ const REPO_URL = 'https://github.com/opencrvs/opencrvs-countryconfig.git'
19
+
20
+ const projectName = process.argv[2]
21
+
22
+ if (!projectName) {
23
+ console.error(
24
+ 'Please specify a project name:\n\n npm create @opencrvs/countryconfig <project-name>\n'
25
+ )
26
+ process.exit(1)
27
+ }
28
+
29
+ const targetDir = path.resolve(process.cwd(), projectName)
30
+
31
+ if (fs.existsSync(targetDir)) {
32
+ console.error(`Error: Directory "${projectName}" already exists.`)
33
+ process.exit(1)
34
+ }
35
+
36
+ console.log(`\nScaffolding OpenCRVS country config in ./${projectName}...\n`)
37
+
38
+ try {
39
+ execSync(`git clone --depth 1 ${REPO_URL} ${projectName}`, {
40
+ stdio: 'inherit'
41
+ })
42
+ } catch (err) {
43
+ console.error('Failed to clone the repository:', err.message)
44
+ process.exit(1)
45
+ }
46
+
47
+ try {
48
+ fs.rmSync(path.join(targetDir, '.git'), { recursive: true, force: true })
49
+ } catch (err) {
50
+ console.error('Failed to remove .git directory:', err.message)
51
+ process.exit(1)
52
+ }
53
+
54
+ const pkgPath = path.join(targetDir, 'package.json')
55
+ if (fs.existsSync(pkgPath)) {
56
+ try {
57
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'))
58
+ pkg.name = projectName
59
+ fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n')
60
+ } catch (err) {
61
+ console.error('Failed to update package.json:', err.message)
62
+ process.exit(1)
63
+ }
64
+ } else {
65
+ console.warn(
66
+ `Warning: No package.json found in the cloned repository. Project name was not updated.`
67
+ )
68
+ }
69
+
70
+ console.log(`\nDone! To get started:\n`)
71
+ console.log(` cd ${projectName}`)
72
+ console.log(` git init`)
73
+ console.log(` npm install\n`)
@@ -0,0 +1,11 @@
1
+ {
2
+ "name": "@opencrvs/create-countryconfig",
3
+ "version": "1.0.0",
4
+ "description": "Scaffold a new OpenCRVS country configuration",
5
+ "bin": {
6
+ "create-countryconfig": "./index.js"
7
+ },
8
+ "files": ["index.js"],
9
+ "keywords": ["opencrvs", "countryconfig", "create"],
10
+ "license": "MPL-2.0"
11
+ }
@@ -772,12 +772,14 @@ var SystemScopeType = z11.enum([
772
772
  "organisation.read-locations",
773
773
  "user.read",
774
774
  "user.create",
775
- "user.edit"
775
+ "user.edit",
776
+ "user.search"
776
777
  ]);
777
778
  var UserScopeType = SystemScopeType.extract([
778
779
  "user.read",
779
780
  "user.create",
780
- "user.edit"
781
+ "user.edit",
782
+ "user.search"
781
783
  ]);
782
784
  var ScopesWithRoleOption = UserScopeType.extract(["user.edit", "user.create"]);
783
785
  var UserScopeV2 = z11.discriminatedUnion("type", [
@@ -786,7 +788,7 @@ var UserScopeV2 = z11.discriminatedUnion("type", [
786
788
  options: AllUserScopeOptions.optional()
787
789
  }),
788
790
  z11.object({
789
- type: UserScopeType.extract(["user.read"]),
791
+ type: UserScopeType.extract(["user.read", "user.search"]),
790
792
  options: AccessLevelOptions.optional()
791
793
  })
792
794
  ]);
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, path23) {
1886
+ function resolveConfigChain(configObj, path24) {
1887
1887
  let current = configObj;
1888
- for (const key of path23) {
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;
@@ -2296,12 +2296,14 @@ var SystemScopeType = z3.enum([
2296
2296
  "organisation.read-locations",
2297
2297
  "user.read",
2298
2298
  "user.create",
2299
- "user.edit"
2299
+ "user.edit",
2300
+ "user.search"
2300
2301
  ]);
2301
2302
  var UserScopeType = SystemScopeType.extract([
2302
2303
  "user.read",
2303
2304
  "user.create",
2304
- "user.edit"
2305
+ "user.edit",
2306
+ "user.search"
2305
2307
  ]);
2306
2308
  var ScopesWithRoleOption = UserScopeType.extract(["user.edit", "user.create"]);
2307
2309
  var UserScopeV2 = z3.discriminatedUnion("type", [
@@ -2310,7 +2312,7 @@ var UserScopeV2 = z3.discriminatedUnion("type", [
2310
2312
  options: AllUserScopeOptions.optional()
2311
2313
  }),
2312
2314
  z3.object({
2313
- type: UserScopeType.extract(["user.read"]),
2315
+ type: UserScopeType.extract(["user.read", "user.search"]),
2314
2316
  options: AccessLevelOptions.optional()
2315
2317
  })
2316
2318
  ]);
@@ -4695,9 +4697,9 @@ var import_path24 = require("path");
4695
4697
  var TEMP_REMOTE2 = "opencrvs-upgrade-v19-v20-codemod-merge-infra";
4696
4698
  var INFRASTRUCTURE_DIR = "infrastructure";
4697
4699
  var BASE_BRANCH = "release-v1.9";
4698
- function gitShowBytes(ref, path23) {
4700
+ function gitShowBytes(ref, path24) {
4699
4701
  try {
4700
- const buf = (0, import_child_process2.execFileSync)("git", ["show", `${ref}:${path23}`], {
4702
+ const buf = (0, import_child_process2.execFileSync)("git", ["show", `${ref}:${path24}`], {
4701
4703
  cwd: process.cwd(),
4702
4704
  stdio: ["ignore", "pipe", "pipe"]
4703
4705
  });
@@ -4836,6 +4838,94 @@ async function main26() {
4836
4838
  );
4837
4839
  }
4838
4840
 
4841
+ // src/migrations/v2.0/fix-action-confirmation-handler-type.ts
4842
+ var import_ts_morph22 = require("ts-morph");
4843
+ var import_path26 = __toESM(require("path"));
4844
+ var TARGET_FUNCTION_NAME = "acceptRequestedRegistration";
4845
+ var ACTION_PARAMETER_NAME = "action";
4846
+ var OLD_TYPE = "ActionInput";
4847
+ var NEW_TYPE = "Extract<ActionInput, { type?: 'REGISTER' }>";
4848
+ function isTargetFunctionParameter(parameter) {
4849
+ const functionDeclaration = parameter.getFirstAncestorByKind(
4850
+ import_ts_morph22.SyntaxKind.FunctionDeclaration
4851
+ );
4852
+ if (functionDeclaration?.getName() === TARGET_FUNCTION_NAME) {
4853
+ return true;
4854
+ }
4855
+ const arrowFunction = parameter.getFirstAncestorByKind(
4856
+ import_ts_morph22.SyntaxKind.ArrowFunction
4857
+ );
4858
+ const variableDeclaration = arrowFunction?.getFirstAncestorByKind(
4859
+ import_ts_morph22.SyntaxKind.VariableDeclaration
4860
+ );
4861
+ return variableDeclaration?.getName() === TARGET_FUNCTION_NAME;
4862
+ }
4863
+ function processFile14(filePath, project) {
4864
+ const sourceFile = project.getSourceFile(filePath);
4865
+ if (!sourceFile) return 0;
4866
+ let updatedCount = 0;
4867
+ const parameters = sourceFile.getDescendantsOfKind(import_ts_morph22.SyntaxKind.Parameter);
4868
+ for (const parameter of parameters) {
4869
+ if (parameter.getName() !== ACTION_PARAMETER_NAME) {
4870
+ continue;
4871
+ }
4872
+ if (!isTargetFunctionParameter(parameter)) {
4873
+ continue;
4874
+ }
4875
+ const typeNode = parameter.getTypeNode();
4876
+ if (!typeNode) continue;
4877
+ if (typeNode.getText() !== OLD_TYPE) {
4878
+ continue;
4879
+ }
4880
+ parameter.setType(NEW_TYPE);
4881
+ updatedCount++;
4882
+ console.log(
4883
+ ` [${import_path26.default.relative(process.cwd(), filePath)}] Updated '${ACTION_PARAMETER_NAME}' parameter type to ${NEW_TYPE}`
4884
+ );
4885
+ }
4886
+ return updatedCount;
4887
+ }
4888
+ async function main27() {
4889
+ const srcDir = import_path26.default.join(process.cwd(), "src");
4890
+ console.log(`Scanning for action confirmation handler types in: ${srcDir}
4891
+ `);
4892
+ const project = new import_ts_morph22.Project({
4893
+ tsConfigFilePath: import_path26.default.resolve(srcDir, "../tsconfig.json"),
4894
+ skipAddingFilesFromTsConfig: false
4895
+ });
4896
+ const sourceFiles = project.getSourceFiles().filter((sf) => {
4897
+ const filePath = sf.getFilePath();
4898
+ return filePath.includes("/src/") && !filePath.includes("/node_modules/");
4899
+ });
4900
+ let totalUpdated = 0;
4901
+ const modifiedFiles = [];
4902
+ for (const sourceFile of sourceFiles) {
4903
+ const filePath = sourceFile.getFilePath();
4904
+ const updated = processFile14(filePath, project);
4905
+ if (updated > 0) {
4906
+ totalUpdated += updated;
4907
+ modifiedFiles.push(filePath);
4908
+ }
4909
+ }
4910
+ if (modifiedFiles.length === 0) {
4911
+ console.log(
4912
+ `No '${ACTION_PARAMETER_NAME}: ${OLD_TYPE}' parameter signatures found. Nothing to do.`
4913
+ );
4914
+ return;
4915
+ }
4916
+ console.log(`
4917
+ Saving ${modifiedFiles.length} modified file(s)...`);
4918
+ for (const filePath of modifiedFiles) {
4919
+ const sourceFile = project.getSourceFileOrThrow(filePath);
4920
+ await sourceFile.save();
4921
+ console.log(` Saved: ${import_path26.default.relative(process.cwd(), filePath)}`);
4922
+ }
4923
+ console.log(
4924
+ `
4925
+ Done. Updated ${totalUpdated} '${ACTION_PARAMETER_NAME}' parameter type annotation(s).`
4926
+ );
4927
+ }
4928
+
4839
4929
  // src/migrations/v2.0/index.ts
4840
4930
  async function runUpgrade(dockerSwarm) {
4841
4931
  await main18();
@@ -4858,6 +4948,7 @@ async function runUpgrade(dockerSwarm) {
4858
4948
  await main19();
4859
4949
  await main20();
4860
4950
  await main21();
4951
+ await main27();
4861
4952
  await main22();
4862
4953
  await main23();
4863
4954
  await main24();
@@ -4894,7 +4985,7 @@ Options:
4894
4985
  'infrastructure/' directory is deleted (default).
4895
4986
  -h, --help Show this message.
4896
4987
  `.trim();
4897
- function main27() {
4988
+ function main28() {
4898
4989
  const command = args[0];
4899
4990
  if (!command || command === "--help" || command === "-h") {
4900
4991
  console.log(USAGE);
@@ -4969,4 +5060,4 @@ function handleCheckTranslations() {
4969
5060
  console.warn("This command is not implemented yet!");
4970
5061
  process.exit(1);
4971
5062
  }
4972
- main27();
5063
+ main28();