@opencrvs/toolkit 2.0.0-rc.8a44fb7 → 2.0.0-rc.8c5d91b

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.
Files changed (47) hide show
  1. package/create-countryconfig/index.js +73 -0
  2. package/create-countryconfig/package.json +11 -0
  3. package/dist/application-config/index.js +56 -32
  4. package/dist/cli.js +539 -175
  5. package/dist/commons/api/router.d.ts +3327 -241
  6. package/dist/commons/application-config/index.d.ts +16 -4
  7. package/dist/commons/conditionals/conditionals.d.ts +6 -6
  8. package/dist/commons/conditionals/validate.d.ts +1 -0
  9. package/dist/commons/events/ActionInput.d.ts +108 -0
  10. package/dist/commons/events/Draft.d.ts +3 -0
  11. package/dist/commons/events/FieldConfig.d.ts +10 -0
  12. package/dist/commons/events/locations.d.ts +38 -1
  13. package/dist/commons/events/mocks.test.utils.d.ts +19 -0
  14. package/dist/commons/events/scopes.d.ts +24 -1
  15. package/dist/commons/events/utils.d.ts +1 -1
  16. package/dist/conditionals/index.js +40 -8
  17. package/dist/events/index.js +161 -42
  18. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts.map +1 -1
  19. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.js +60 -35
  20. package/dist/migrations/v2.0/checkout-upstream-files.d.ts +1 -1
  21. package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +1 -1
  22. package/dist/migrations/v2.0/checkout-upstream-files.js +1 -2
  23. package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts +9 -1
  24. package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts.map +1 -1
  25. package/dist/migrations/v2.0/delete-infrastructure-directory.js +66 -20
  26. package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.d.ts +3 -0
  27. package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.d.ts.map +1 -0
  28. package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.js +110 -0
  29. package/dist/migrations/v2.0/index.d.ts +5 -3
  30. package/dist/migrations/v2.0/index.d.ts.map +1 -1
  31. package/dist/migrations/v2.0/index.js +537 -173
  32. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts.map +1 -1
  33. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.js +90 -1
  34. package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts +11 -1
  35. package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts.map +1 -1
  36. package/dist/migrations/v2.0/merge-infrastructure-directory.js +17 -16
  37. package/dist/migrations/v2.0/migrate-scopes.d.ts.map +1 -1
  38. package/dist/migrations/v2.0/migrate-scopes.js +54 -30
  39. package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts.map +1 -1
  40. package/dist/migrations/v2.0/migrate-workqueue-configs.js +140 -59
  41. package/dist/notification/index.js +55 -28
  42. package/dist/scopes/index.d.ts +87 -10
  43. package/dist/scopes/index.js +46 -9
  44. package/opencrvs-toolkit-2.0.0-rc.8c5d91b.tgz +0 -0
  45. package/package.json +1 -1
  46. package/tsconfig.tsbuildinfo +1 -1
  47. package/opencrvs-toolkit-2.0.0-rc.8a44fb7.tgz +0 -0
@@ -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
+ }
@@ -418,28 +418,20 @@ function schemaPriority(schema) {
418
418
  return idx === -1 ? 9999 : idx;
419
419
  }
420
420
  function safeUnion(schemas) {
421
+ const sortedSchemas = [...schemas].sort(
422
+ (a, b) => schemaPriority(a) - schemaPriority(b)
423
+ );
421
424
  return z7.any().superRefine((val, ctx) => {
422
- const successful = schemas.filter((s) => s.safeParse(val).success);
423
- if (successful.length === 1) {
424
- return;
425
- }
426
- if (successful.length === 0) {
427
- ctx.addIssue({
428
- code: "invalid_type",
429
- expected: "custom",
430
- message: "Value does not match any schema"
431
- });
432
- return;
433
- }
434
- successful.sort((a, b) => schemaPriority(a) - schemaPriority(b));
435
- const best = successful[0];
436
- if (!best.safeParse(val).success) {
437
- ctx.addIssue({
438
- expected: "custom",
439
- code: "invalid_type",
440
- message: "Value did not match the best schema"
441
- });
425
+ for (const schema of sortedSchemas) {
426
+ if (schema.safeParse(val).success) {
427
+ return;
428
+ }
442
429
  }
430
+ ctx.addIssue({
431
+ code: "invalid_type",
432
+ expected: "custom",
433
+ message: "Value does not match any schema"
434
+ });
443
435
  }).meta({
444
436
  description: "Value that matches exactly one of the possible schema types (TextValue, DateValue, DateRangeFieldValue). The best matching schema is chosen by priority."
445
437
  });
@@ -656,6 +648,10 @@ var scopeByEvent = z11.preprocess(
656
648
  (val) => val === void 0 ? void 0 : [val].flat(),
657
649
  z11.array(z11.string()).optional()
658
650
  ).describe("Event type, e.g. birth, death");
651
+ var userRole = z11.preprocess(
652
+ (val) => val === void 0 ? void 0 : [val].flat(),
653
+ z11.array(z11.string()).optional()
654
+ ).describe("User role, e.g. admin, field agent");
659
655
  var scopeOptionsPlaceEvent = z11.object({
660
656
  event: scopeByEvent,
661
657
  placeOfEvent: JurisdictionFilter.optional()
@@ -679,6 +675,9 @@ var CustomActionScopeOptions = AllRecordScopeOptions.extend({
679
675
  var AccessLevelOptions = z11.object({
680
676
  accessLevel: JurisdictionFilter.optional()
681
677
  });
678
+ var AllUserScopeOptions = AccessLevelOptions.extend({
679
+ role: userRole.optional()
680
+ });
682
681
  var WorkqueueOrDashboardOptions = z11.object({
683
682
  ids: z11.preprocess(
684
683
  (val) => val === void 0 ? void 0 : [val].flat(),
@@ -688,6 +687,7 @@ var WorkqueueOrDashboardOptions = z11.object({
688
687
  var AllScopeOptions = z11.object({
689
688
  ...AllRecordScopeOptions.shape,
690
689
  ...AccessLevelOptions.shape,
690
+ ...AllUserScopeOptions.shape,
691
691
  ...WorkqueueOrDashboardOptions.shape
692
692
  });
693
693
  var ScopeOptionKey = AllScopeOptions.keyof();
@@ -760,6 +760,30 @@ var RecordScopeV2 = z11.discriminatedUnion("type", [
760
760
  ]).describe(
761
761
  "Scopes used to check user's permission to perform actions on a record."
762
762
  );
763
+ var SystemScopeType = z11.enum([
764
+ "organisation.read-locations",
765
+ "user.read",
766
+ "user.create",
767
+ "user.edit",
768
+ "user.search"
769
+ ]);
770
+ var UserScopeType = SystemScopeType.extract([
771
+ "user.read",
772
+ "user.create",
773
+ "user.edit",
774
+ "user.search"
775
+ ]);
776
+ var ScopesWithRoleOption = UserScopeType.extract(["user.edit", "user.create"]);
777
+ var UserScopeV2 = z11.discriminatedUnion("type", [
778
+ z11.object({
779
+ type: ScopesWithRoleOption,
780
+ options: AllUserScopeOptions.optional()
781
+ }),
782
+ z11.object({
783
+ type: UserScopeType.extract(["user.read", "user.search"]),
784
+ options: AccessLevelOptions.optional()
785
+ })
786
+ ]);
763
787
  var ResolvedRecordScopeV2 = z11.discriminatedUnion("type", [
764
788
  z11.object({
765
789
  type: ScopesWithPlaceEventOptions,
@@ -780,16 +804,14 @@ var ResolvedRecordScopeV2 = z11.discriminatedUnion("type", [
780
804
  }).optional()
781
805
  })
782
806
  ]).describe("Resolved scope with location/user IDs instead of filters.");
783
- var SystemScopeType = z11.enum([
784
- "organisation.read-locations",
785
- "user.read",
786
- "user.create",
787
- "user.edit"
788
- ]);
789
807
  var Scope = z11.discriminatedUnion("type", [
790
808
  z11.object({ type: PlainScopeType }),
791
809
  ...RecordScopeV2.options,
792
- z11.object({ type: SystemScopeType, options: AccessLevelOptions.optional() }),
810
+ ...UserScopeV2.options,
811
+ z11.object({
812
+ type: z11.literal("organisation.read-locations"),
813
+ options: AccessLevelOptions.optional()
814
+ }),
793
815
  z11.object({
794
816
  type: z11.literal("workqueue"),
795
817
  options: WorkqueueOrDashboardOptions
@@ -809,7 +831,9 @@ var ScopeType = z11.enum([
809
831
  var EncodedScope = z11.string().brand("EncodedScope");
810
832
  var DEFAULT_SCOPE_OPTIONS = {
811
833
  placeOfEvent: JurisdictionFilter.enum.all,
812
- accessLevel: JurisdictionFilter.enum.all
834
+ accessLevel: JurisdictionFilter.enum.all,
835
+ registeredIn: JurisdictionFilter.enum.all,
836
+ declaredIn: JurisdictionFilter.enum.all
813
837
  };
814
838
 
815
839
  // ../commons/src/authentication.ts
@@ -2078,8 +2102,8 @@ var ApplicationConfig = z20.object({
2078
2102
  })
2079
2103
  ),
2080
2104
  PHONE_NUMBER_PATTERN: z20.string().or(z20.instanceof(RegExp)),
2081
- USER_NOTIFICATION_DELIVERY_METHOD: z20.string(),
2082
- INFORMANT_NOTIFICATION_DELIVERY_METHOD: z20.string(),
2105
+ USER_NOTIFICATION_DELIVERY_METHOD: z20.enum(["email", "sms"]),
2106
+ INFORMANT_NOTIFICATION_DELIVERY_METHOD: z20.enum(["email", "sms"]),
2083
2107
  SEARCH_DEFAULT_CRITERIA: SearchCriteria.optional().default("TRACKING_ID"),
2084
2108
  ADDITIONAL_USER_FIELDS: z20.array(FieldConfig).optional().default([])
2085
2109
  });
@@ -2097,8 +2121,8 @@ var BackgroundConfig = z20.object({
2097
2121
  var LoginConfig = z20.object({
2098
2122
  COUNTRY: z20.string(),
2099
2123
  LANGUAGES: z20.array(z20.string()),
2100
- USER_NOTIFICATION_DELIVERY_METHOD: z20.string(),
2101
- INFORMANT_NOTIFICATION_DELIVERY_METHOD: z20.string(),
2124
+ USER_NOTIFICATION_DELIVERY_METHOD: z20.enum(["email", "sms"]),
2125
+ INFORMANT_NOTIFICATION_DELIVERY_METHOD: z20.enum(["email", "sms"]),
2102
2126
  PHONE_NUMBER_PATTERN: z20.string().or(z20.instanceof(RegExp)),
2103
2127
  LOGIN_BACKGROUND: BackgroundConfig,
2104
2128
  SENTRY: z20.string().optional()