@opencrvs/toolkit 2.0.0-rc.df1ed4f → 2.0.0-rc.e12607f

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.
@@ -656,6 +656,10 @@ var scopeByEvent = z11.preprocess(
656
656
  (val) => val === void 0 ? void 0 : [val].flat(),
657
657
  z11.array(z11.string()).optional()
658
658
  ).describe("Event type, e.g. birth, death");
659
+ var userRole = z11.preprocess(
660
+ (val) => val === void 0 ? void 0 : [val].flat(),
661
+ z11.array(z11.string()).optional()
662
+ ).describe("User role, e.g. admin, field agent");
659
663
  var scopeOptionsPlaceEvent = z11.object({
660
664
  event: scopeByEvent,
661
665
  placeOfEvent: JurisdictionFilter.optional()
@@ -679,6 +683,9 @@ var CustomActionScopeOptions = AllRecordScopeOptions.extend({
679
683
  var AccessLevelOptions = z11.object({
680
684
  accessLevel: JurisdictionFilter.optional()
681
685
  });
686
+ var AllUserScopeOptions = AccessLevelOptions.extend({
687
+ role: userRole.optional()
688
+ });
682
689
  var WorkqueueOrDashboardOptions = z11.object({
683
690
  ids: z11.preprocess(
684
691
  (val) => val === void 0 ? void 0 : [val].flat(),
@@ -688,6 +695,7 @@ var WorkqueueOrDashboardOptions = z11.object({
688
695
  var AllScopeOptions = z11.object({
689
696
  ...AllRecordScopeOptions.shape,
690
697
  ...AccessLevelOptions.shape,
698
+ ...AllUserScopeOptions.shape,
691
699
  ...WorkqueueOrDashboardOptions.shape
692
700
  });
693
701
  var ScopeOptionKey = AllScopeOptions.keyof();
@@ -760,6 +768,28 @@ var RecordScopeV2 = z11.discriminatedUnion("type", [
760
768
  ]).describe(
761
769
  "Scopes used to check user's permission to perform actions on a record."
762
770
  );
771
+ var SystemScopeType = z11.enum([
772
+ "organisation.read-locations",
773
+ "user.read",
774
+ "user.create",
775
+ "user.edit"
776
+ ]);
777
+ var UserScopeType = SystemScopeType.extract([
778
+ "user.read",
779
+ "user.create",
780
+ "user.edit"
781
+ ]);
782
+ var ScopesWithRoleOption = UserScopeType.extract(["user.edit", "user.create"]);
783
+ var UserScopeV2 = z11.discriminatedUnion("type", [
784
+ z11.object({
785
+ type: ScopesWithRoleOption,
786
+ options: AllUserScopeOptions.optional()
787
+ }),
788
+ z11.object({
789
+ type: UserScopeType.extract(["user.read"]),
790
+ options: AccessLevelOptions.optional()
791
+ })
792
+ ]);
763
793
  var ResolvedRecordScopeV2 = z11.discriminatedUnion("type", [
764
794
  z11.object({
765
795
  type: ScopesWithPlaceEventOptions,
@@ -780,16 +810,14 @@ var ResolvedRecordScopeV2 = z11.discriminatedUnion("type", [
780
810
  }).optional()
781
811
  })
782
812
  ]).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
813
  var Scope = z11.discriminatedUnion("type", [
790
814
  z11.object({ type: PlainScopeType }),
791
815
  ...RecordScopeV2.options,
792
- z11.object({ type: SystemScopeType, options: AccessLevelOptions.optional() }),
816
+ ...UserScopeV2.options,
817
+ z11.object({
818
+ type: z11.literal("organisation.read-locations"),
819
+ options: AccessLevelOptions.optional()
820
+ }),
793
821
  z11.object({
794
822
  type: z11.literal("workqueue"),
795
823
  options: WorkqueueOrDashboardOptions
@@ -2078,8 +2106,8 @@ var ApplicationConfig = z20.object({
2078
2106
  })
2079
2107
  ),
2080
2108
  PHONE_NUMBER_PATTERN: z20.string().or(z20.instanceof(RegExp)),
2081
- USER_NOTIFICATION_DELIVERY_METHOD: z20.enum(["email", "sms"]),
2082
- INFORMANT_NOTIFICATION_DELIVERY_METHOD: z20.enum(["email", "sms"]),
2109
+ USER_NOTIFICATION_DELIVERY_METHOD: z20.string(),
2110
+ INFORMANT_NOTIFICATION_DELIVERY_METHOD: z20.string(),
2083
2111
  SEARCH_DEFAULT_CRITERIA: SearchCriteria.optional().default("TRACKING_ID"),
2084
2112
  ADDITIONAL_USER_FIELDS: z20.array(FieldConfig).optional().default([])
2085
2113
  });
@@ -2097,8 +2125,8 @@ var BackgroundConfig = z20.object({
2097
2125
  var LoginConfig = z20.object({
2098
2126
  COUNTRY: z20.string(),
2099
2127
  LANGUAGES: z20.array(z20.string()),
2100
- USER_NOTIFICATION_DELIVERY_METHOD: z20.enum(["email", "sms"]),
2101
- INFORMANT_NOTIFICATION_DELIVERY_METHOD: z20.enum(["email", "sms"]),
2128
+ USER_NOTIFICATION_DELIVERY_METHOD: z20.string(),
2129
+ INFORMANT_NOTIFICATION_DELIVERY_METHOD: z20.string(),
2102
2130
  PHONE_NUMBER_PATTERN: z20.string().or(z20.instanceof(RegExp)),
2103
2131
  LOGIN_BACKGROUND: BackgroundConfig,
2104
2132
  SENTRY: z20.string().optional()
package/dist/cli.js CHANGED
@@ -2110,6 +2110,10 @@ var scopeByEvent = z3.preprocess(
2110
2110
  (val) => val === void 0 ? void 0 : [val].flat(),
2111
2111
  z3.array(z3.string()).optional()
2112
2112
  ).describe("Event type, e.g. birth, death");
2113
+ var userRole = z3.preprocess(
2114
+ (val) => val === void 0 ? void 0 : [val].flat(),
2115
+ z3.array(z3.string()).optional()
2116
+ ).describe("User role, e.g. admin, field agent");
2113
2117
  var scopeOptionsPlaceEvent = z3.object({
2114
2118
  event: scopeByEvent,
2115
2119
  placeOfEvent: JurisdictionFilter.optional()
@@ -2133,6 +2137,9 @@ var CustomActionScopeOptions = AllRecordScopeOptions.extend({
2133
2137
  var AccessLevelOptions = z3.object({
2134
2138
  accessLevel: JurisdictionFilter.optional()
2135
2139
  });
2140
+ var AllUserScopeOptions = AccessLevelOptions.extend({
2141
+ role: userRole.optional()
2142
+ });
2136
2143
  var WorkqueueOrDashboardOptions = z3.object({
2137
2144
  ids: z3.preprocess(
2138
2145
  (val) => val === void 0 ? void 0 : [val].flat(),
@@ -2142,6 +2149,7 @@ var WorkqueueOrDashboardOptions = z3.object({
2142
2149
  var AllScopeOptions = z3.object({
2143
2150
  ...AllRecordScopeOptions.shape,
2144
2151
  ...AccessLevelOptions.shape,
2152
+ ...AllUserScopeOptions.shape,
2145
2153
  ...WorkqueueOrDashboardOptions.shape
2146
2154
  });
2147
2155
  var ScopeOptionKey = AllScopeOptions.keyof();
@@ -2214,6 +2222,28 @@ var RecordScopeV2 = z3.discriminatedUnion("type", [
2214
2222
  ]).describe(
2215
2223
  "Scopes used to check user's permission to perform actions on a record."
2216
2224
  );
2225
+ var SystemScopeType = z3.enum([
2226
+ "organisation.read-locations",
2227
+ "user.read",
2228
+ "user.create",
2229
+ "user.edit"
2230
+ ]);
2231
+ var UserScopeType = SystemScopeType.extract([
2232
+ "user.read",
2233
+ "user.create",
2234
+ "user.edit"
2235
+ ]);
2236
+ var ScopesWithRoleOption = UserScopeType.extract(["user.edit", "user.create"]);
2237
+ var UserScopeV2 = z3.discriminatedUnion("type", [
2238
+ z3.object({
2239
+ type: ScopesWithRoleOption,
2240
+ options: AllUserScopeOptions.optional()
2241
+ }),
2242
+ z3.object({
2243
+ type: UserScopeType.extract(["user.read"]),
2244
+ options: AccessLevelOptions.optional()
2245
+ })
2246
+ ]);
2217
2247
  var ResolvedRecordScopeV2 = z3.discriminatedUnion("type", [
2218
2248
  z3.object({
2219
2249
  type: ScopesWithPlaceEventOptions,
@@ -2234,16 +2264,14 @@ var ResolvedRecordScopeV2 = z3.discriminatedUnion("type", [
2234
2264
  }).optional()
2235
2265
  })
2236
2266
  ]).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
2267
  var Scope2 = z3.discriminatedUnion("type", [
2244
2268
  z3.object({ type: PlainScopeType }),
2245
2269
  ...RecordScopeV2.options,
2246
- z3.object({ type: SystemScopeType, options: AccessLevelOptions.optional() }),
2270
+ ...UserScopeV2.options,
2271
+ z3.object({
2272
+ type: z3.literal("organisation.read-locations"),
2273
+ options: AccessLevelOptions.optional()
2274
+ }),
2247
2275
  z3.object({
2248
2276
  type: z3.literal("workqueue"),
2249
2277
  options: WorkqueueOrDashboardOptions
@@ -3975,10 +3975,9 @@ export declare const appRouter: import("@trpc/server").TRPCBuiltRouter<{
3975
3975
  output: {
3976
3976
  id: string & import("zod").$brand<"UUID">;
3977
3977
  name: {
3978
- use: string;
3979
- given: string[];
3980
- family: string;
3981
- }[];
3978
+ firstname: string;
3979
+ surname: string;
3980
+ };
3982
3981
  role: string;
3983
3982
  primaryOfficeId: string & import("zod").$brand<"UUID">;
3984
3983
  type: "user";
@@ -4008,10 +4007,9 @@ export declare const appRouter: import("@trpc/server").TRPCBuiltRouter<{
4008
4007
  create: import("@trpc/server").TRPCMutationProcedure<{
4009
4008
  input: {
4010
4009
  name: {
4011
- use: string;
4012
- given: string[];
4013
- family: string;
4014
- }[];
4010
+ firstname: string;
4011
+ surname: string;
4012
+ };
4015
4013
  role: string;
4016
4014
  primaryOfficeId: string;
4017
4015
  data?: Record<string, unknown> | undefined;
@@ -4030,10 +4028,9 @@ export declare const appRouter: import("@trpc/server").TRPCBuiltRouter<{
4030
4028
  output: {
4031
4029
  id: string & import("zod").$brand<"UUID">;
4032
4030
  name: {
4033
- use: string;
4034
- given: string[];
4035
- family: string;
4036
- }[];
4031
+ firstname: string;
4032
+ surname: string;
4033
+ };
4037
4034
  role: string;
4038
4035
  primaryOfficeId: string & import("zod").$brand<"UUID">;
4039
4036
  type: "user";
@@ -4054,10 +4051,9 @@ export declare const appRouter: import("@trpc/server").TRPCBuiltRouter<{
4054
4051
  id: string;
4055
4052
  data?: Record<string, unknown> | undefined;
4056
4053
  name?: {
4057
- use: string;
4058
- given: string[];
4059
- family: string;
4060
- }[] | undefined;
4054
+ firstname: string;
4055
+ surname: string;
4056
+ } | undefined;
4061
4057
  role?: string | undefined;
4062
4058
  fullHonorificName?: string | undefined;
4063
4059
  device?: string | undefined;
@@ -4074,10 +4070,9 @@ export declare const appRouter: import("@trpc/server").TRPCBuiltRouter<{
4074
4070
  output: {
4075
4071
  id: string & import("zod").$brand<"UUID">;
4076
4072
  name: {
4077
- use: string;
4078
- given: string[];
4079
- family: string;
4080
- }[];
4073
+ firstname: string;
4074
+ surname: string;
4075
+ };
4081
4076
  role: string;
4082
4077
  primaryOfficeId: string & import("zod").$brand<"UUID">;
4083
4078
  type: "user";
@@ -4098,10 +4093,9 @@ export declare const appRouter: import("@trpc/server").TRPCBuiltRouter<{
4098
4093
  output: ({
4099
4094
  id: string & import("zod").$brand<"UUID">;
4100
4095
  name: {
4101
- use: string;
4102
- given: string[];
4103
- family: string;
4104
- }[];
4096
+ firstname: string;
4097
+ surname: string;
4098
+ };
4105
4099
  role: string;
4106
4100
  primaryOfficeId: string & import("zod").$brand<"UUID">;
4107
4101
  type: "user";
@@ -4143,10 +4137,9 @@ export declare const appRouter: import("@trpc/server").TRPCBuiltRouter<{
4143
4137
  output: ({
4144
4138
  id: string & import("zod").$brand<"UUID">;
4145
4139
  name: {
4146
- use: string;
4147
- given: string[];
4148
- family: string;
4149
- }[];
4140
+ firstname: string;
4141
+ surname: string;
4142
+ };
4150
4143
  role: string;
4151
4144
  primaryOfficeId: string & import("zod").$brand<"UUID">;
4152
4145
  type: "user";
@@ -4772,7 +4765,7 @@ export declare const appRouter: import("@trpc/server").TRPCBuiltRouter<{
4772
4765
  'legalStatuses.DECLARED.createdAtLocation'?: {
4773
4766
  type: "within";
4774
4767
  location: string | {
4775
- $userField: "id" | "name" | "administrativeAreaId" | "firstname" | "surname" | "fullHonorificName" | "role" | "device" | "middlename" | "signature" | "avatar" | "primaryOfficeId";
4768
+ $userField: "id" | "name" | "administrativeAreaId" | "firstname" | "surname" | "fullHonorificName" | "role" | "device" | "avatar" | "signature" | "primaryOfficeId" | "middlename";
4776
4769
  $location?: string | undefined;
4777
4770
  };
4778
4771
  } | undefined;
@@ -4794,7 +4787,7 @@ export declare const appRouter: import("@trpc/server").TRPCBuiltRouter<{
4794
4787
  'legalStatuses.REGISTERED.createdAtLocation'?: {
4795
4788
  type: "within";
4796
4789
  location: string | {
4797
- $userField: "id" | "name" | "administrativeAreaId" | "firstname" | "surname" | "fullHonorificName" | "role" | "device" | "middlename" | "signature" | "avatar" | "primaryOfficeId";
4790
+ $userField: "id" | "name" | "administrativeAreaId" | "firstname" | "surname" | "fullHonorificName" | "role" | "device" | "avatar" | "signature" | "primaryOfficeId" | "middlename";
4798
4791
  $location?: string | undefined;
4799
4792
  };
4800
4793
  } | undefined;
@@ -4809,47 +4802,47 @@ export declare const appRouter: import("@trpc/server").TRPCBuiltRouter<{
4809
4802
  createdAtLocation?: {
4810
4803
  type: "within";
4811
4804
  location: string | {
4812
- $userField: "id" | "name" | "administrativeAreaId" | "firstname" | "surname" | "fullHonorificName" | "role" | "device" | "middlename" | "signature" | "avatar" | "primaryOfficeId";
4805
+ $userField: "id" | "name" | "administrativeAreaId" | "firstname" | "surname" | "fullHonorificName" | "role" | "device" | "avatar" | "signature" | "primaryOfficeId" | "middlename";
4813
4806
  $location?: string | undefined;
4814
4807
  };
4815
4808
  } | {
4816
4809
  type: "exact";
4817
4810
  term: string | {
4818
- $userField: "id" | "name" | "administrativeAreaId" | "firstname" | "surname" | "fullHonorificName" | "role" | "device" | "middlename" | "signature" | "avatar" | "primaryOfficeId";
4811
+ $userField: "id" | "name" | "administrativeAreaId" | "firstname" | "surname" | "fullHonorificName" | "role" | "device" | "avatar" | "signature" | "primaryOfficeId" | "middlename";
4819
4812
  $location?: string | undefined;
4820
4813
  };
4821
4814
  } | undefined;
4822
4815
  updatedAtLocation?: {
4823
4816
  type: "within";
4824
4817
  location: string | {
4825
- $userField: "id" | "name" | "administrativeAreaId" | "firstname" | "surname" | "fullHonorificName" | "role" | "device" | "middlename" | "signature" | "avatar" | "primaryOfficeId";
4818
+ $userField: "id" | "name" | "administrativeAreaId" | "firstname" | "surname" | "fullHonorificName" | "role" | "device" | "avatar" | "signature" | "primaryOfficeId" | "middlename";
4826
4819
  $location?: string | undefined;
4827
4820
  };
4828
4821
  } | {
4829
4822
  type: "exact";
4830
4823
  term: string | {
4831
- $userField: "id" | "name" | "administrativeAreaId" | "firstname" | "surname" | "fullHonorificName" | "role" | "device" | "middlename" | "signature" | "avatar" | "primaryOfficeId";
4824
+ $userField: "id" | "name" | "administrativeAreaId" | "firstname" | "surname" | "fullHonorificName" | "role" | "device" | "avatar" | "signature" | "primaryOfficeId" | "middlename";
4832
4825
  $location?: string | undefined;
4833
4826
  };
4834
4827
  } | undefined;
4835
4828
  updatedByUserRole?: {
4836
4829
  type: "exact";
4837
4830
  term: string | {
4838
- $userField: "id" | "name" | "administrativeAreaId" | "firstname" | "surname" | "fullHonorificName" | "role" | "device" | "middlename" | "signature" | "avatar" | "primaryOfficeId";
4831
+ $userField: "id" | "name" | "administrativeAreaId" | "firstname" | "surname" | "fullHonorificName" | "role" | "device" | "avatar" | "signature" | "primaryOfficeId" | "middlename";
4839
4832
  $location?: string | undefined;
4840
4833
  };
4841
4834
  } | undefined;
4842
4835
  assignedTo?: {
4843
4836
  type: "exact";
4844
4837
  term: string | {
4845
- $userField: "id" | "name" | "administrativeAreaId" | "firstname" | "surname" | "fullHonorificName" | "role" | "device" | "middlename" | "signature" | "avatar" | "primaryOfficeId";
4838
+ $userField: "id" | "name" | "administrativeAreaId" | "firstname" | "surname" | "fullHonorificName" | "role" | "device" | "avatar" | "signature" | "primaryOfficeId" | "middlename";
4846
4839
  $location?: string | undefined;
4847
4840
  };
4848
4841
  } | undefined;
4849
4842
  createdBy?: {
4850
4843
  type: "exact";
4851
4844
  term: string | {
4852
- $userField: "id" | "name" | "administrativeAreaId" | "firstname" | "surname" | "fullHonorificName" | "role" | "device" | "middlename" | "signature" | "avatar" | "primaryOfficeId";
4845
+ $userField: "id" | "name" | "administrativeAreaId" | "firstname" | "surname" | "fullHonorificName" | "role" | "device" | "avatar" | "signature" | "primaryOfficeId" | "middlename";
4853
4846
  $location?: string | undefined;
4854
4847
  };
4855
4848
  } | undefined;
@@ -4860,7 +4853,7 @@ export declare const appRouter: import("@trpc/server").TRPCBuiltRouter<{
4860
4853
  updatedBy?: {
4861
4854
  type: "exact";
4862
4855
  term: string | {
4863
- $userField: "id" | "name" | "administrativeAreaId" | "firstname" | "surname" | "fullHonorificName" | "role" | "device" | "middlename" | "signature" | "avatar" | "primaryOfficeId";
4856
+ $userField: "id" | "name" | "administrativeAreaId" | "firstname" | "surname" | "fullHonorificName" | "role" | "device" | "avatar" | "signature" | "primaryOfficeId" | "middlename";
4864
4857
  $location?: string | undefined;
4865
4858
  };
4866
4859
  } | undefined;
@@ -4910,7 +4903,7 @@ export declare const appRouter: import("@trpc/server").TRPCBuiltRouter<{
4910
4903
  'legalStatuses.DECLARED.createdAtLocation'?: {
4911
4904
  type: "within";
4912
4905
  location: string | {
4913
- $userField: "id" | "name" | "administrativeAreaId" | "firstname" | "surname" | "fullHonorificName" | "role" | "device" | "middlename" | "signature" | "avatar" | "primaryOfficeId";
4906
+ $userField: "id" | "name" | "administrativeAreaId" | "firstname" | "surname" | "fullHonorificName" | "role" | "device" | "avatar" | "signature" | "primaryOfficeId" | "middlename";
4914
4907
  $location?: string | undefined;
4915
4908
  };
4916
4909
  } | undefined;
@@ -4932,7 +4925,7 @@ export declare const appRouter: import("@trpc/server").TRPCBuiltRouter<{
4932
4925
  'legalStatuses.REGISTERED.createdAtLocation'?: {
4933
4926
  type: "within";
4934
4927
  location: string | {
4935
- $userField: "id" | "name" | "administrativeAreaId" | "firstname" | "surname" | "fullHonorificName" | "role" | "device" | "middlename" | "signature" | "avatar" | "primaryOfficeId";
4928
+ $userField: "id" | "name" | "administrativeAreaId" | "firstname" | "surname" | "fullHonorificName" | "role" | "device" | "avatar" | "signature" | "primaryOfficeId" | "middlename";
4936
4929
  $location?: string | undefined;
4937
4930
  };
4938
4931
  } | undefined;
@@ -4947,47 +4940,47 @@ export declare const appRouter: import("@trpc/server").TRPCBuiltRouter<{
4947
4940
  createdAtLocation?: {
4948
4941
  type: "within";
4949
4942
  location: string | {
4950
- $userField: "id" | "name" | "administrativeAreaId" | "firstname" | "surname" | "fullHonorificName" | "role" | "device" | "middlename" | "signature" | "avatar" | "primaryOfficeId";
4943
+ $userField: "id" | "name" | "administrativeAreaId" | "firstname" | "surname" | "fullHonorificName" | "role" | "device" | "avatar" | "signature" | "primaryOfficeId" | "middlename";
4951
4944
  $location?: string | undefined;
4952
4945
  };
4953
4946
  } | {
4954
4947
  type: "exact";
4955
4948
  term: string | {
4956
- $userField: "id" | "name" | "administrativeAreaId" | "firstname" | "surname" | "fullHonorificName" | "role" | "device" | "middlename" | "signature" | "avatar" | "primaryOfficeId";
4949
+ $userField: "id" | "name" | "administrativeAreaId" | "firstname" | "surname" | "fullHonorificName" | "role" | "device" | "avatar" | "signature" | "primaryOfficeId" | "middlename";
4957
4950
  $location?: string | undefined;
4958
4951
  };
4959
4952
  } | undefined;
4960
4953
  updatedAtLocation?: {
4961
4954
  type: "within";
4962
4955
  location: string | {
4963
- $userField: "id" | "name" | "administrativeAreaId" | "firstname" | "surname" | "fullHonorificName" | "role" | "device" | "middlename" | "signature" | "avatar" | "primaryOfficeId";
4956
+ $userField: "id" | "name" | "administrativeAreaId" | "firstname" | "surname" | "fullHonorificName" | "role" | "device" | "avatar" | "signature" | "primaryOfficeId" | "middlename";
4964
4957
  $location?: string | undefined;
4965
4958
  };
4966
4959
  } | {
4967
4960
  type: "exact";
4968
4961
  term: string | {
4969
- $userField: "id" | "name" | "administrativeAreaId" | "firstname" | "surname" | "fullHonorificName" | "role" | "device" | "middlename" | "signature" | "avatar" | "primaryOfficeId";
4962
+ $userField: "id" | "name" | "administrativeAreaId" | "firstname" | "surname" | "fullHonorificName" | "role" | "device" | "avatar" | "signature" | "primaryOfficeId" | "middlename";
4970
4963
  $location?: string | undefined;
4971
4964
  };
4972
4965
  } | undefined;
4973
4966
  updatedByUserRole?: {
4974
4967
  type: "exact";
4975
4968
  term: string | {
4976
- $userField: "id" | "name" | "administrativeAreaId" | "firstname" | "surname" | "fullHonorificName" | "role" | "device" | "middlename" | "signature" | "avatar" | "primaryOfficeId";
4969
+ $userField: "id" | "name" | "administrativeAreaId" | "firstname" | "surname" | "fullHonorificName" | "role" | "device" | "avatar" | "signature" | "primaryOfficeId" | "middlename";
4977
4970
  $location?: string | undefined;
4978
4971
  };
4979
4972
  } | undefined;
4980
4973
  assignedTo?: {
4981
4974
  type: "exact";
4982
4975
  term: string | {
4983
- $userField: "id" | "name" | "administrativeAreaId" | "firstname" | "surname" | "fullHonorificName" | "role" | "device" | "middlename" | "signature" | "avatar" | "primaryOfficeId";
4976
+ $userField: "id" | "name" | "administrativeAreaId" | "firstname" | "surname" | "fullHonorificName" | "role" | "device" | "avatar" | "signature" | "primaryOfficeId" | "middlename";
4984
4977
  $location?: string | undefined;
4985
4978
  };
4986
4979
  } | undefined;
4987
4980
  createdBy?: {
4988
4981
  type: "exact";
4989
4982
  term: string | {
4990
- $userField: "id" | "name" | "administrativeAreaId" | "firstname" | "surname" | "fullHonorificName" | "role" | "device" | "middlename" | "signature" | "avatar" | "primaryOfficeId";
4983
+ $userField: "id" | "name" | "administrativeAreaId" | "firstname" | "surname" | "fullHonorificName" | "role" | "device" | "avatar" | "signature" | "primaryOfficeId" | "middlename";
4991
4984
  $location?: string | undefined;
4992
4985
  };
4993
4986
  } | undefined;
@@ -4998,7 +4991,7 @@ export declare const appRouter: import("@trpc/server").TRPCBuiltRouter<{
4998
4991
  updatedBy?: {
4999
4992
  type: "exact";
5000
4993
  term: string | {
5001
- $userField: "id" | "name" | "administrativeAreaId" | "firstname" | "surname" | "fullHonorificName" | "role" | "device" | "middlename" | "signature" | "avatar" | "primaryOfficeId";
4994
+ $userField: "id" | "name" | "administrativeAreaId" | "firstname" | "surname" | "fullHonorificName" | "role" | "device" | "avatar" | "signature" | "primaryOfficeId" | "middlename";
5002
4995
  $location?: string | undefined;
5003
4996
  };
5004
4997
  } | undefined;
@@ -24,14 +24,8 @@ export declare const ApplicationConfig: z.ZodObject<{
24
24
  label: z.ZodObject<import("./events/TranslationConfig").MessageDescriptorZod, z.core.$strip>;
25
25
  }, z.core.$strip>>;
26
26
  PHONE_NUMBER_PATTERN: z.ZodUnion<[z.ZodString, z.ZodCustom<RegExp, RegExp>]>;
27
- USER_NOTIFICATION_DELIVERY_METHOD: z.ZodEnum<{
28
- email: "email";
29
- sms: "sms";
30
- }>;
31
- INFORMANT_NOTIFICATION_DELIVERY_METHOD: z.ZodEnum<{
32
- email: "email";
33
- sms: "sms";
34
- }>;
27
+ USER_NOTIFICATION_DELIVERY_METHOD: z.ZodString;
28
+ INFORMANT_NOTIFICATION_DELIVERY_METHOD: z.ZodString;
35
29
  SEARCH_DEFAULT_CRITERIA: z.ZodDefault<z.ZodOptional<z.ZodEnum<{
36
30
  NAME: "NAME";
37
31
  EMAIL: "EMAIL";
@@ -52,14 +46,8 @@ export declare const BackgroundConfig: z.ZodObject<{
52
46
  export declare const LoginConfig: z.ZodObject<{
53
47
  COUNTRY: z.ZodString;
54
48
  LANGUAGES: z.ZodArray<z.ZodString>;
55
- USER_NOTIFICATION_DELIVERY_METHOD: z.ZodEnum<{
56
- email: "email";
57
- sms: "sms";
58
- }>;
59
- INFORMANT_NOTIFICATION_DELIVERY_METHOD: z.ZodEnum<{
60
- email: "email";
61
- sms: "sms";
62
- }>;
49
+ USER_NOTIFICATION_DELIVERY_METHOD: z.ZodString;
50
+ INFORMANT_NOTIFICATION_DELIVERY_METHOD: z.ZodString;
63
51
  PHONE_NUMBER_PATTERN: z.ZodUnion<[z.ZodString, z.ZodCustom<RegExp, RegExp>]>;
64
52
  LOGIN_BACKGROUND: z.ZodObject<{
65
53
  backgroundColor: z.ZodOptional<z.ZodString>;
@@ -87,16 +87,16 @@ export declare const user: typeof userSerializer & {
87
87
  scope: (scope: import("../scopes").ScopeType) => {
88
88
  attribute: (option: import("../scopes").ScopeOptionKey) => {
89
89
  $scope: "record.search" | "record.create" | "record.read" | "record.declare" | "record.notify" | "record.edit" | "record.reject" | "record.archive" | "record.review-duplicates" | "record.register" | "record.print-certified-copies" | "record.request-correction" | "record.correct" | "record.unassign-others" | "record.custom-action" | "bypassratelimit" | "record.reindex" | "user.data-seeding" | "integration.create" | "record.import" | "config.update-all" | "attachment.upload" | "profile.electronic-signature" | "user.read-only-my-audit" | "performance.read" | "performance.read-dashboards" | "performance.vital-statistics-export" | "record.confirm-registration" | "record.reject-registration" | "organisation.read-locations" | "user.read" | "user.create" | "user.edit" | "workqueue" | "dashboard.view";
90
- $option: "event" | "placeOfEvent" | "declaredIn" | "declaredBy" | "registeredIn" | "registeredBy" | "accessLevel" | "ids";
90
+ $option: "role" | "event" | "placeOfEvent" | "declaredIn" | "declaredBy" | "registeredIn" | "registeredBy" | "accessLevel" | "ids";
91
91
  };
92
92
  };
93
93
  jurisdiction: (jurisdiction: import("../scopes").JurisdictionFilter | {
94
94
  $scope: "record.search" | "record.create" | "record.read" | "record.declare" | "record.notify" | "record.edit" | "record.reject" | "record.archive" | "record.review-duplicates" | "record.register" | "record.print-certified-copies" | "record.request-correction" | "record.correct" | "record.unassign-others" | "record.custom-action" | "bypassratelimit" | "record.reindex" | "user.data-seeding" | "integration.create" | "record.import" | "config.update-all" | "attachment.upload" | "profile.electronic-signature" | "user.read-only-my-audit" | "performance.read" | "performance.read-dashboards" | "performance.vital-statistics-export" | "record.confirm-registration" | "record.reject-registration" | "organisation.read-locations" | "user.read" | "user.create" | "user.edit" | "workqueue" | "dashboard.view";
95
- $option: "event" | "placeOfEvent" | "declaredIn" | "declaredBy" | "registeredIn" | "registeredBy" | "accessLevel" | "ids";
95
+ $option: "role" | "event" | "placeOfEvent" | "declaredIn" | "declaredBy" | "registeredIn" | "registeredBy" | "accessLevel" | "ids";
96
96
  }) => {
97
97
  $jurisdiction: "administrativeArea" | "location" | "all" | {
98
98
  $scope: "record.search" | "record.create" | "record.read" | "record.declare" | "record.notify" | "record.edit" | "record.reject" | "record.archive" | "record.review-duplicates" | "record.register" | "record.print-certified-copies" | "record.request-correction" | "record.correct" | "record.unassign-others" | "record.custom-action" | "bypassratelimit" | "record.reindex" | "user.data-seeding" | "integration.create" | "record.import" | "config.update-all" | "attachment.upload" | "profile.electronic-signature" | "user.read-only-my-audit" | "performance.read" | "performance.read-dashboards" | "performance.vital-statistics-export" | "record.confirm-registration" | "record.reject-registration" | "organisation.read-locations" | "user.read" | "user.create" | "user.edit" | "workqueue" | "dashboard.view";
99
- $option: "event" | "placeOfEvent" | "declaredIn" | "declaredBy" | "registeredIn" | "registeredBy" | "accessLevel" | "ids";
99
+ $option: "role" | "event" | "placeOfEvent" | "declaredIn" | "declaredBy" | "registeredIn" | "registeredBy" | "accessLevel" | "ids";
100
100
  };
101
101
  };
102
102
  };
@@ -1727,6 +1727,7 @@ declare const AdministrativeAreaField: z.ZodObject<{
1727
1727
  "dashboard.view": "dashboard.view";
1728
1728
  }>;
1729
1729
  $option: z.ZodEnum<{
1730
+ role: "role";
1730
1731
  event: "event";
1731
1732
  placeOfEvent: "placeOfEvent";
1732
1733
  declaredIn: "declaredIn";
@@ -1845,6 +1846,7 @@ declare const LocationInput: z.ZodObject<{
1845
1846
  "dashboard.view": "dashboard.view";
1846
1847
  }>;
1847
1848
  $option: z.ZodEnum<{
1849
+ role: "role";
1848
1850
  event: "event";
1849
1851
  placeOfEvent: "placeOfEvent";
1850
1852
  declaredIn: "declaredIn";
@@ -2028,6 +2030,7 @@ declare const Facility: z.ZodObject<{
2028
2030
  "dashboard.view": "dashboard.view";
2029
2031
  }>;
2030
2032
  $option: z.ZodEnum<{
2033
+ role: "role";
2031
2034
  event: "event";
2032
2035
  placeOfEvent: "placeOfEvent";
2033
2036
  declaredIn: "declaredIn";
@@ -2132,6 +2135,7 @@ declare const Office: z.ZodObject<{
2132
2135
  "dashboard.view": "dashboard.view";
2133
2136
  }>;
2134
2137
  $option: z.ZodEnum<{
2138
+ role: "role";
2135
2139
  event: "event";
2136
2140
  placeOfEvent: "placeOfEvent";
2137
2141
  declaredIn: "declaredIn";
@@ -2323,6 +2327,7 @@ declare const Address: z.ZodObject<{
2323
2327
  "dashboard.view": "dashboard.view";
2324
2328
  }>;
2325
2329
  $option: z.ZodEnum<{
2330
+ role: "role";
2326
2331
  event: "event";
2327
2332
  placeOfEvent: "placeOfEvent";
2328
2333
  declaredIn: "declaredIn";
@@ -1,7 +1,8 @@
1
+ import { UUID } from '../uuid';
1
2
  import * as z from 'zod/v4';
2
3
  import { EventIndex } from './EventIndex';
3
4
  import { ActionCreationMetadata, RegistrationCreationMetadata } from './EventMetadata';
4
- import { RecordScopeV2 } from '../scopes';
5
+ import { RecordScopeV2, UserScopeV2 } from '../scopes';
5
6
  import { SystemContext, UserContext } from '../users/User';
6
7
  /** @deprecated Moving on, location types are arbitrary and defined by the country config. */
7
8
  export declare const LocationTypeV1: z.ZodEnum<{
@@ -51,6 +52,21 @@ export type EventIndexWithAdministrativeHierarchy = Omit<ToArrayFields<EventInde
51
52
  *
52
53
  */
53
54
  export declare function canAccessEventWithScope(event: Partial<EventIndexWithAdministrativeHierarchy>, scope: RecordScopeV2, user: UserContext | SystemContext, customActionType?: string): boolean;
55
+ export type UserWithResolvedHierarchy = {
56
+ role: string;
57
+ administrativeHierarchy: UUID[];
58
+ primaryOfficeId: UUID;
59
+ };
60
+ export declare function canAccessUserWithScope({ userToAccess, scope, user }: {
61
+ userToAccess: UserWithResolvedHierarchy;
62
+ scope: UserScopeV2;
63
+ user: UserContext | SystemContext;
64
+ }): boolean;
65
+ export declare function canAccessOtherUserWithScopes({ scopes, userToAccess, user }: {
66
+ scopes: UserScopeV2[];
67
+ userToAccess: UserWithResolvedHierarchy;
68
+ user: UserContext | SystemContext;
69
+ }): boolean;
54
70
  /**
55
71
  * Given indexed event and list of resolved scopes, determine if any of the scopes allow access to the event.
56
72
  *
@@ -182,6 +182,10 @@ var scopeByEvent = z6.preprocess(
182
182
  (val) => val === void 0 ? void 0 : [val].flat(),
183
183
  z6.array(z6.string()).optional()
184
184
  ).describe("Event type, e.g. birth, death");
185
+ var userRole = z6.preprocess(
186
+ (val) => val === void 0 ? void 0 : [val].flat(),
187
+ z6.array(z6.string()).optional()
188
+ ).describe("User role, e.g. admin, field agent");
185
189
  var scopeOptionsPlaceEvent = z6.object({
186
190
  event: scopeByEvent,
187
191
  placeOfEvent: JurisdictionFilter.optional()
@@ -205,6 +209,9 @@ var CustomActionScopeOptions = AllRecordScopeOptions.extend({
205
209
  var AccessLevelOptions = z6.object({
206
210
  accessLevel: JurisdictionFilter.optional()
207
211
  });
212
+ var AllUserScopeOptions = AccessLevelOptions.extend({
213
+ role: userRole.optional()
214
+ });
208
215
  var WorkqueueOrDashboardOptions = z6.object({
209
216
  ids: z6.preprocess(
210
217
  (val) => val === void 0 ? void 0 : [val].flat(),
@@ -214,6 +221,7 @@ var WorkqueueOrDashboardOptions = z6.object({
214
221
  var AllScopeOptions = z6.object({
215
222
  ...AllRecordScopeOptions.shape,
216
223
  ...AccessLevelOptions.shape,
224
+ ...AllUserScopeOptions.shape,
217
225
  ...WorkqueueOrDashboardOptions.shape
218
226
  });
219
227
  var ScopeOptionKey = AllScopeOptions.keyof();
@@ -286,6 +294,28 @@ var RecordScopeV2 = z6.discriminatedUnion("type", [
286
294
  ]).describe(
287
295
  "Scopes used to check user's permission to perform actions on a record."
288
296
  );
297
+ var SystemScopeType = z6.enum([
298
+ "organisation.read-locations",
299
+ "user.read",
300
+ "user.create",
301
+ "user.edit"
302
+ ]);
303
+ var UserScopeType = SystemScopeType.extract([
304
+ "user.read",
305
+ "user.create",
306
+ "user.edit"
307
+ ]);
308
+ var ScopesWithRoleOption = UserScopeType.extract(["user.edit", "user.create"]);
309
+ var UserScopeV2 = z6.discriminatedUnion("type", [
310
+ z6.object({
311
+ type: ScopesWithRoleOption,
312
+ options: AllUserScopeOptions.optional()
313
+ }),
314
+ z6.object({
315
+ type: UserScopeType.extract(["user.read"]),
316
+ options: AccessLevelOptions.optional()
317
+ })
318
+ ]);
289
319
  var ResolvedRecordScopeV2 = z6.discriminatedUnion("type", [
290
320
  z6.object({
291
321
  type: ScopesWithPlaceEventOptions,
@@ -306,16 +336,14 @@ var ResolvedRecordScopeV2 = z6.discriminatedUnion("type", [
306
336
  }).optional()
307
337
  })
308
338
  ]).describe("Resolved scope with location/user IDs instead of filters.");
309
- var SystemScopeType = z6.enum([
310
- "organisation.read-locations",
311
- "user.read",
312
- "user.create",
313
- "user.edit"
314
- ]);
315
339
  var Scope2 = z6.discriminatedUnion("type", [
316
340
  z6.object({ type: PlainScopeType }),
317
341
  ...RecordScopeV2.options,
318
- z6.object({ type: SystemScopeType, options: AccessLevelOptions.optional() }),
342
+ ...UserScopeV2.options,
343
+ z6.object({
344
+ type: z6.literal("organisation.read-locations"),
345
+ options: AccessLevelOptions.optional()
346
+ }),
319
347
  z6.object({
320
348
  type: z6.literal("workqueue"),
321
349
  options: WorkqueueOrDashboardOptions
@@ -243,6 +243,8 @@ __export(events_exports, {
243
243
  areConditionsMet: () => areConditionsMet,
244
244
  buildFormState: () => buildFormState,
245
245
  canAccessEventWithScope: () => canAccessEventWithScope,
246
+ canAccessOtherUserWithScopes: () => canAccessOtherUserWithScopes,
247
+ canAccessUserWithScope: () => canAccessUserWithScope,
246
248
  compositeFieldTypes: () => compositeFieldTypes,
247
249
  createEmptyDraft: () => createEmptyDraft,
248
250
  createFieldConditionals: () => createFieldConditionals,
@@ -489,6 +491,10 @@ var scopeByEvent = z2.preprocess(
489
491
  (val) => val === void 0 ? void 0 : [val].flat(),
490
492
  z2.array(z2.string()).optional()
491
493
  ).describe("Event type, e.g. birth, death");
494
+ var userRole = z2.preprocess(
495
+ (val) => val === void 0 ? void 0 : [val].flat(),
496
+ z2.array(z2.string()).optional()
497
+ ).describe("User role, e.g. admin, field agent");
492
498
  var scopeOptionsPlaceEvent = z2.object({
493
499
  event: scopeByEvent,
494
500
  placeOfEvent: JurisdictionFilter.optional()
@@ -512,6 +518,9 @@ var CustomActionScopeOptions = AllRecordScopeOptions.extend({
512
518
  var AccessLevelOptions = z2.object({
513
519
  accessLevel: JurisdictionFilter.optional()
514
520
  });
521
+ var AllUserScopeOptions = AccessLevelOptions.extend({
522
+ role: userRole.optional()
523
+ });
515
524
  var WorkqueueOrDashboardOptions = z2.object({
516
525
  ids: z2.preprocess(
517
526
  (val) => val === void 0 ? void 0 : [val].flat(),
@@ -521,6 +530,7 @@ var WorkqueueOrDashboardOptions = z2.object({
521
530
  var AllScopeOptions = z2.object({
522
531
  ...AllRecordScopeOptions.shape,
523
532
  ...AccessLevelOptions.shape,
533
+ ...AllUserScopeOptions.shape,
524
534
  ...WorkqueueOrDashboardOptions.shape
525
535
  });
526
536
  var ScopeOptionKey = AllScopeOptions.keyof();
@@ -593,6 +603,31 @@ var RecordScopeV2 = z2.discriminatedUnion("type", [
593
603
  ]).describe(
594
604
  "Scopes used to check user's permission to perform actions on a record."
595
605
  );
606
+ var SystemScopeType = z2.enum([
607
+ "organisation.read-locations",
608
+ "user.read",
609
+ "user.create",
610
+ "user.edit"
611
+ ]);
612
+ var UserScopeType = SystemScopeType.extract([
613
+ "user.read",
614
+ "user.create",
615
+ "user.edit"
616
+ ]);
617
+ var ScopesWithRoleOption = UserScopeType.extract(["user.edit", "user.create"]);
618
+ var UserScopeV2 = z2.discriminatedUnion("type", [
619
+ z2.object({
620
+ type: ScopesWithRoleOption,
621
+ options: AllUserScopeOptions.optional()
622
+ }),
623
+ z2.object({
624
+ type: UserScopeType.extract(["user.read"]),
625
+ options: AccessLevelOptions.optional()
626
+ })
627
+ ]);
628
+ function scopeUsesRoleOptions(scope) {
629
+ return ScopesWithRoleOption?.options.some((opt) => opt === scope.type);
630
+ }
596
631
  function scopeUsesDeclaredOptions(scope) {
597
632
  return !ScopesWithPlaceEventOptions.options.some((opt) => opt === scope.type);
598
633
  }
@@ -625,16 +660,14 @@ var ResolvedRecordScopeV2 = z2.discriminatedUnion("type", [
625
660
  }).optional()
626
661
  })
627
662
  ]).describe("Resolved scope with location/user IDs instead of filters.");
628
- var SystemScopeType = z2.enum([
629
- "organisation.read-locations",
630
- "user.read",
631
- "user.create",
632
- "user.edit"
633
- ]);
634
663
  var Scope = z2.discriminatedUnion("type", [
635
664
  z2.object({ type: PlainScopeType }),
636
665
  ...RecordScopeV2.options,
637
- z2.object({ type: SystemScopeType, options: AccessLevelOptions.optional() }),
666
+ ...UserScopeV2.options,
667
+ z2.object({
668
+ type: z2.literal("organisation.read-locations"),
669
+ options: AccessLevelOptions.optional()
670
+ }),
638
671
  z2.object({
639
672
  type: z2.literal("workqueue"),
640
673
  options: WorkqueueOrDashboardOptions
@@ -9930,6 +9963,39 @@ function canAccessEventWithScope(event2, scope, user2, customActionType) {
9930
9963
  }
9931
9964
  return true;
9932
9965
  }
9966
+ function canAccessUserWithScope({
9967
+ userToAccess,
9968
+ scope,
9969
+ user: user2
9970
+ }) {
9971
+ const opts = scope.options;
9972
+ const hasSameOffice = user2.primaryOfficeId === userToAccess.primaryOfficeId;
9973
+ if (opts?.accessLevel === JurisdictionFilter.enum.location && !hasSameOffice) {
9974
+ return false;
9975
+ }
9976
+ const hasAdministrativeAreaInHierarchy = userToAccess.administrativeHierarchy.some(
9977
+ (id) => user2.administrativeAreaId === id
9978
+ ) || user2.administrativeAreaId === null;
9979
+ if (opts?.accessLevel === JurisdictionFilter.enum.administrativeArea && !hasAdministrativeAreaInHierarchy) {
9980
+ return false;
9981
+ }
9982
+ if (scopeUsesRoleOptions(scope)) {
9983
+ const { options } = scope;
9984
+ if (options?.role && !options.role.includes(userToAccess.role)) {
9985
+ return false;
9986
+ }
9987
+ }
9988
+ return true;
9989
+ }
9990
+ function canAccessOtherUserWithScopes({
9991
+ scopes,
9992
+ userToAccess,
9993
+ user: user2
9994
+ }) {
9995
+ return scopes.some(
9996
+ (scope) => canAccessUserWithScope({ userToAccess, scope, user: user2 })
9997
+ );
9998
+ }
9933
9999
  function userCanAccessEventWithScopes(event2, scopes, user2, customActionType) {
9934
10000
  return scopes.some(
9935
10001
  (scope) => canAccessEventWithScope(event2, scope, user2, customActionType)
@@ -2122,6 +2122,10 @@ var scopeByEvent = z3.preprocess(
2122
2122
  (val) => val === void 0 ? void 0 : [val].flat(),
2123
2123
  z3.array(z3.string()).optional()
2124
2124
  ).describe("Event type, e.g. birth, death");
2125
+ var userRole = z3.preprocess(
2126
+ (val) => val === void 0 ? void 0 : [val].flat(),
2127
+ z3.array(z3.string()).optional()
2128
+ ).describe("User role, e.g. admin, field agent");
2125
2129
  var scopeOptionsPlaceEvent = z3.object({
2126
2130
  event: scopeByEvent,
2127
2131
  placeOfEvent: JurisdictionFilter.optional()
@@ -2145,6 +2149,9 @@ var CustomActionScopeOptions = AllRecordScopeOptions.extend({
2145
2149
  var AccessLevelOptions = z3.object({
2146
2150
  accessLevel: JurisdictionFilter.optional()
2147
2151
  });
2152
+ var AllUserScopeOptions = AccessLevelOptions.extend({
2153
+ role: userRole.optional()
2154
+ });
2148
2155
  var WorkqueueOrDashboardOptions = z3.object({
2149
2156
  ids: z3.preprocess(
2150
2157
  (val) => val === void 0 ? void 0 : [val].flat(),
@@ -2154,6 +2161,7 @@ var WorkqueueOrDashboardOptions = z3.object({
2154
2161
  var AllScopeOptions = z3.object({
2155
2162
  ...AllRecordScopeOptions.shape,
2156
2163
  ...AccessLevelOptions.shape,
2164
+ ...AllUserScopeOptions.shape,
2157
2165
  ...WorkqueueOrDashboardOptions.shape
2158
2166
  });
2159
2167
  var ScopeOptionKey = AllScopeOptions.keyof();
@@ -2226,6 +2234,28 @@ var RecordScopeV2 = z3.discriminatedUnion("type", [
2226
2234
  ]).describe(
2227
2235
  "Scopes used to check user's permission to perform actions on a record."
2228
2236
  );
2237
+ var SystemScopeType = z3.enum([
2238
+ "organisation.read-locations",
2239
+ "user.read",
2240
+ "user.create",
2241
+ "user.edit"
2242
+ ]);
2243
+ var UserScopeType = SystemScopeType.extract([
2244
+ "user.read",
2245
+ "user.create",
2246
+ "user.edit"
2247
+ ]);
2248
+ var ScopesWithRoleOption = UserScopeType.extract(["user.edit", "user.create"]);
2249
+ var UserScopeV2 = z3.discriminatedUnion("type", [
2250
+ z3.object({
2251
+ type: ScopesWithRoleOption,
2252
+ options: AllUserScopeOptions.optional()
2253
+ }),
2254
+ z3.object({
2255
+ type: UserScopeType.extract(["user.read"]),
2256
+ options: AccessLevelOptions.optional()
2257
+ })
2258
+ ]);
2229
2259
  var ResolvedRecordScopeV2 = z3.discriminatedUnion("type", [
2230
2260
  z3.object({
2231
2261
  type: ScopesWithPlaceEventOptions,
@@ -2246,16 +2276,14 @@ var ResolvedRecordScopeV2 = z3.discriminatedUnion("type", [
2246
2276
  }).optional()
2247
2277
  })
2248
2278
  ]).describe("Resolved scope with location/user IDs instead of filters.");
2249
- var SystemScopeType = z3.enum([
2250
- "organisation.read-locations",
2251
- "user.read",
2252
- "user.create",
2253
- "user.edit"
2254
- ]);
2255
2279
  var Scope2 = z3.discriminatedUnion("type", [
2256
2280
  z3.object({ type: PlainScopeType }),
2257
2281
  ...RecordScopeV2.options,
2258
- z3.object({ type: SystemScopeType, options: AccessLevelOptions.optional() }),
2282
+ ...UserScopeV2.options,
2283
+ z3.object({
2284
+ type: z3.literal("organisation.read-locations"),
2285
+ options: AccessLevelOptions.optional()
2286
+ }),
2259
2287
  z3.object({
2260
2288
  type: z3.literal("workqueue"),
2261
2289
  options: WorkqueueOrDashboardOptions
@@ -110,6 +110,10 @@ var scopeByEvent = z2.preprocess(
110
110
  (val) => val === void 0 ? void 0 : [val].flat(),
111
111
  z2.array(z2.string()).optional()
112
112
  ).describe("Event type, e.g. birth, death");
113
+ var userRole = z2.preprocess(
114
+ (val) => val === void 0 ? void 0 : [val].flat(),
115
+ z2.array(z2.string()).optional()
116
+ ).describe("User role, e.g. admin, field agent");
113
117
  var scopeOptionsPlaceEvent = z2.object({
114
118
  event: scopeByEvent,
115
119
  placeOfEvent: JurisdictionFilter.optional()
@@ -133,6 +137,9 @@ var CustomActionScopeOptions = AllRecordScopeOptions.extend({
133
137
  var AccessLevelOptions = z2.object({
134
138
  accessLevel: JurisdictionFilter.optional()
135
139
  });
140
+ var AllUserScopeOptions = AccessLevelOptions.extend({
141
+ role: userRole.optional()
142
+ });
136
143
  var WorkqueueOrDashboardOptions = z2.object({
137
144
  ids: z2.preprocess(
138
145
  (val) => val === void 0 ? void 0 : [val].flat(),
@@ -142,6 +149,7 @@ var WorkqueueOrDashboardOptions = z2.object({
142
149
  var AllScopeOptions = z2.object({
143
150
  ...AllRecordScopeOptions.shape,
144
151
  ...AccessLevelOptions.shape,
152
+ ...AllUserScopeOptions.shape,
145
153
  ...WorkqueueOrDashboardOptions.shape
146
154
  });
147
155
  var ScopeOptionKey = AllScopeOptions.keyof();
@@ -214,6 +222,28 @@ var RecordScopeV2 = z2.discriminatedUnion("type", [
214
222
  ]).describe(
215
223
  "Scopes used to check user's permission to perform actions on a record."
216
224
  );
225
+ var SystemScopeType = z2.enum([
226
+ "organisation.read-locations",
227
+ "user.read",
228
+ "user.create",
229
+ "user.edit"
230
+ ]);
231
+ var UserScopeType = SystemScopeType.extract([
232
+ "user.read",
233
+ "user.create",
234
+ "user.edit"
235
+ ]);
236
+ var ScopesWithRoleOption = UserScopeType.extract(["user.edit", "user.create"]);
237
+ var UserScopeV2 = z2.discriminatedUnion("type", [
238
+ z2.object({
239
+ type: ScopesWithRoleOption,
240
+ options: AllUserScopeOptions.optional()
241
+ }),
242
+ z2.object({
243
+ type: UserScopeType.extract(["user.read"]),
244
+ options: AccessLevelOptions.optional()
245
+ })
246
+ ]);
217
247
  var ResolvedRecordScopeV2 = z2.discriminatedUnion("type", [
218
248
  z2.object({
219
249
  type: ScopesWithPlaceEventOptions,
@@ -234,16 +264,14 @@ var ResolvedRecordScopeV2 = z2.discriminatedUnion("type", [
234
264
  }).optional()
235
265
  })
236
266
  ]).describe("Resolved scope with location/user IDs instead of filters.");
237
- var SystemScopeType = z2.enum([
238
- "organisation.read-locations",
239
- "user.read",
240
- "user.create",
241
- "user.edit"
242
- ]);
243
267
  var Scope = z2.discriminatedUnion("type", [
244
268
  z2.object({ type: PlainScopeType }),
245
269
  ...RecordScopeV2.options,
246
- z2.object({ type: SystemScopeType, options: AccessLevelOptions.optional() }),
270
+ ...UserScopeV2.options,
271
+ z2.object({
272
+ type: z2.literal("organisation.read-locations"),
273
+ options: AccessLevelOptions.optional()
274
+ }),
247
275
  z2.object({
248
276
  type: z2.literal("workqueue"),
249
277
  options: WorkqueueOrDashboardOptions
@@ -41,6 +41,7 @@ declare const AllScopeOptions: z.ZodObject<{
41
41
  location: "location";
42
42
  all: "all";
43
43
  }>>;
44
+ role: z.ZodOptional<z.ZodPipe<z.ZodTransform<({} | null)[] | undefined, unknown>, z.ZodOptional<z.ZodArray<z.ZodString>>>>;
44
45
  event: z.ZodPipe<z.ZodTransform<({} | null)[] | undefined, unknown>, z.ZodOptional<z.ZodArray<z.ZodString>>>;
45
46
  placeOfEvent: z.ZodOptional<z.ZodEnum<{
46
47
  administrativeArea: "administrativeArea";
@@ -66,6 +67,7 @@ declare const AllScopeOptions: z.ZodObject<{
66
67
  }, z.core.$strip>;
67
68
  type AllScopeOptions = z.infer<typeof AllScopeOptions>;
68
69
  export declare const ScopeOptionKey: z.ZodEnum<{
70
+ role: "role";
69
71
  event: "event";
70
72
  placeOfEvent: "placeOfEvent";
71
73
  declaredIn: "declaredIn";
@@ -220,6 +222,53 @@ export declare const RecordScopeV2: z.ZodDiscriminatedUnion<[z.ZodObject<{
220
222
  templates: z.ZodPipe<z.ZodTransform<({} | null)[] | undefined, unknown>, z.ZodOptional<z.ZodArray<z.ZodString>>>;
221
223
  }, z.core.$strip>>;
222
224
  }, z.core.$strip>], "type">;
225
+ declare const SystemScopeType: z.ZodEnum<{
226
+ "organisation.read-locations": "organisation.read-locations";
227
+ "user.read": "user.read";
228
+ "user.create": "user.create";
229
+ "user.edit": "user.edit";
230
+ }>;
231
+ export type SystemScopeType = z.infer<typeof SystemScopeType>;
232
+ declare const UserScopeType: z.ZodEnum<{
233
+ "user.read": "user.read";
234
+ "user.create": "user.create";
235
+ "user.edit": "user.edit";
236
+ }>;
237
+ export type UserScopeType = z.infer<typeof UserScopeType>;
238
+ declare const ScopesWithRoleOption: z.ZodEnum<{
239
+ "user.create": "user.create";
240
+ "user.edit": "user.edit";
241
+ }>;
242
+ export type ScopesWithRoleOption = z.infer<typeof ScopesWithRoleOption>;
243
+ export declare const UserScopeV2: z.ZodDiscriminatedUnion<[z.ZodObject<{
244
+ type: z.ZodEnum<{
245
+ "user.create": "user.create";
246
+ "user.edit": "user.edit";
247
+ }>;
248
+ options: z.ZodOptional<z.ZodObject<{
249
+ accessLevel: z.ZodOptional<z.ZodEnum<{
250
+ administrativeArea: "administrativeArea";
251
+ location: "location";
252
+ all: "all";
253
+ }>>;
254
+ role: z.ZodOptional<z.ZodPipe<z.ZodTransform<({} | null)[] | undefined, unknown>, z.ZodOptional<z.ZodArray<z.ZodString>>>>;
255
+ }, z.core.$strip>>;
256
+ }, z.core.$strip>, z.ZodObject<{
257
+ type: z.ZodEnum<{
258
+ "user.read": "user.read";
259
+ }>;
260
+ options: z.ZodOptional<z.ZodObject<{
261
+ accessLevel: z.ZodOptional<z.ZodEnum<{
262
+ administrativeArea: "administrativeArea";
263
+ location: "location";
264
+ all: "all";
265
+ }>>;
266
+ }, z.core.$strip>>;
267
+ }, z.core.$strip>], "type">;
268
+ export type UserScopeV2 = z.infer<typeof UserScopeV2>;
269
+ export declare function scopeUsesRoleOptions(scope: UserScopeV2): scope is Extract<UserScopeV2, {
270
+ type: ScopesWithRoleOption;
271
+ }>;
223
272
  export declare function scopeUsesDeclaredOptions(scope: Scope): scope is Extract<Scope, {
224
273
  type: z.infer<typeof ScopesWithDeclaredOptions>;
225
274
  }>;
@@ -286,13 +335,6 @@ export declare const ResolvedRecordScopeV2: z.ZodDiscriminatedUnion<[z.ZodObject
286
335
  }, z.core.$strip>], "type">;
287
336
  export type RecordScopeV2 = z.infer<typeof RecordScopeV2>;
288
337
  export type ResolvedRecordScopeV2 = z.infer<typeof ResolvedRecordScopeV2>;
289
- declare const SystemScopeType: z.ZodEnum<{
290
- "organisation.read-locations": "organisation.read-locations";
291
- "user.read": "user.read";
292
- "user.create": "user.create";
293
- "user.edit": "user.edit";
294
- }>;
295
- export type SystemScopeType = z.infer<typeof SystemScopeType>;
296
338
  /** The primary scope schema which gathers all scope types together. All scopes are discriminated by type and options are determined according to the type. */
297
339
  export declare const Scope: z.ZodDiscriminatedUnion<[z.ZodObject<{
298
340
  type: z.ZodEnum<{
@@ -437,11 +479,30 @@ export declare const Scope: z.ZodDiscriminatedUnion<[z.ZodObject<{
437
479
  }, z.core.$strip>>;
438
480
  }, z.core.$strip>, z.ZodObject<{
439
481
  type: z.ZodEnum<{
440
- "organisation.read-locations": "organisation.read-locations";
441
- "user.read": "user.read";
442
482
  "user.create": "user.create";
443
483
  "user.edit": "user.edit";
444
484
  }>;
485
+ options: z.ZodOptional<z.ZodObject<{
486
+ accessLevel: z.ZodOptional<z.ZodEnum<{
487
+ administrativeArea: "administrativeArea";
488
+ location: "location";
489
+ all: "all";
490
+ }>>;
491
+ role: z.ZodOptional<z.ZodPipe<z.ZodTransform<({} | null)[] | undefined, unknown>, z.ZodOptional<z.ZodArray<z.ZodString>>>>;
492
+ }, z.core.$strip>>;
493
+ }, z.core.$strip>, z.ZodObject<{
494
+ type: z.ZodEnum<{
495
+ "user.read": "user.read";
496
+ }>;
497
+ options: z.ZodOptional<z.ZodObject<{
498
+ accessLevel: z.ZodOptional<z.ZodEnum<{
499
+ administrativeArea: "administrativeArea";
500
+ location: "location";
501
+ all: "all";
502
+ }>>;
503
+ }, z.core.$strip>>;
504
+ }, z.core.$strip>, z.ZodObject<{
505
+ type: z.ZodLiteral<"organisation.read-locations">;
445
506
  options: z.ZodOptional<z.ZodObject<{
446
507
  accessLevel: z.ZodOptional<z.ZodEnum<{
447
508
  administrativeArea: "administrativeArea";
@@ -567,10 +628,21 @@ export declare const decodeScope: (query: EncodedScope) => {
567
628
  registeredBy?: "user" | undefined;
568
629
  templates?: string[] | undefined;
569
630
  } | undefined;
631
+ } | {
632
+ type: "user.create" | "user.edit";
633
+ options?: {
634
+ accessLevel?: "administrativeArea" | "location" | "all" | undefined;
635
+ role?: string[] | undefined;
636
+ } | undefined;
637
+ } | {
638
+ type: "user.read";
639
+ options?: {
640
+ accessLevel?: "administrativeArea" | "location" | "all" | undefined;
641
+ } | undefined;
570
642
  } | {
571
643
  type: "bypassratelimit" | "record.reindex" | "user.data-seeding" | "integration.create" | "record.import" | "config.update-all" | "attachment.upload" | "profile.electronic-signature" | "user.read-only-my-audit" | "performance.read" | "performance.read-dashboards" | "performance.vital-statistics-export" | "record.confirm-registration" | "record.reject-registration";
572
644
  } | {
573
- type: "organisation.read-locations" | "user.read" | "user.create" | "user.edit";
645
+ type: "organisation.read-locations";
574
646
  options?: {
575
647
  accessLevel?: "administrativeArea" | "location" | "all" | undefined;
576
648
  } | undefined;
@@ -42,6 +42,7 @@ __export(scopes_exports, {
42
42
  ScopesWithFullOptions: () => ScopesWithFullOptions,
43
43
  ScopesWithPlaceEventOptions: () => ScopesWithPlaceEventOptions,
44
44
  UserFilter: () => UserFilter,
45
+ UserScopeV2: () => UserScopeV2,
45
46
  canUserCreateEvent: () => canUserCreateEvent,
46
47
  decodeScope: () => decodeScope,
47
48
  defineRoles: () => defineRoles,
@@ -54,7 +55,8 @@ __export(scopes_exports, {
54
55
  isCustomActionScope: () => isCustomActionScope,
55
56
  scopeUsesDeclaredOptions: () => scopeUsesDeclaredOptions,
56
57
  scopeUsesFullOptions: () => scopeUsesFullOptions,
57
- scopeUsesPrintCertifiedCopiesOptions: () => scopeUsesPrintCertifiedCopiesOptions
58
+ scopeUsesPrintCertifiedCopiesOptions: () => scopeUsesPrintCertifiedCopiesOptions,
59
+ scopeUsesRoleOptions: () => scopeUsesRoleOptions
58
60
  });
59
61
  module.exports = __toCommonJS(scopes_exports);
60
62
  var z4 = __toESM(require("zod/v4"));
@@ -139,6 +141,10 @@ var scopeByEvent = z3.preprocess(
139
141
  (val) => val === void 0 ? void 0 : [val].flat(),
140
142
  z3.array(z3.string()).optional()
141
143
  ).describe("Event type, e.g. birth, death");
144
+ var userRole = z3.preprocess(
145
+ (val) => val === void 0 ? void 0 : [val].flat(),
146
+ z3.array(z3.string()).optional()
147
+ ).describe("User role, e.g. admin, field agent");
142
148
  var scopeOptionsPlaceEvent = z3.object({
143
149
  event: scopeByEvent,
144
150
  placeOfEvent: JurisdictionFilter.optional()
@@ -162,6 +168,9 @@ var CustomActionScopeOptions = AllRecordScopeOptions.extend({
162
168
  var AccessLevelOptions = z3.object({
163
169
  accessLevel: JurisdictionFilter.optional()
164
170
  });
171
+ var AllUserScopeOptions = AccessLevelOptions.extend({
172
+ role: userRole.optional()
173
+ });
165
174
  var WorkqueueOrDashboardOptions = z3.object({
166
175
  ids: z3.preprocess(
167
176
  (val) => val === void 0 ? void 0 : [val].flat(),
@@ -171,6 +180,7 @@ var WorkqueueOrDashboardOptions = z3.object({
171
180
  var AllScopeOptions = z3.object({
172
181
  ...AllRecordScopeOptions.shape,
173
182
  ...AccessLevelOptions.shape,
183
+ ...AllUserScopeOptions.shape,
174
184
  ...WorkqueueOrDashboardOptions.shape
175
185
  });
176
186
  var ScopeOptionKey = AllScopeOptions.keyof();
@@ -243,6 +253,31 @@ var RecordScopeV2 = z3.discriminatedUnion("type", [
243
253
  ]).describe(
244
254
  "Scopes used to check user's permission to perform actions on a record."
245
255
  );
256
+ var SystemScopeType = z3.enum([
257
+ "organisation.read-locations",
258
+ "user.read",
259
+ "user.create",
260
+ "user.edit"
261
+ ]);
262
+ var UserScopeType = SystemScopeType.extract([
263
+ "user.read",
264
+ "user.create",
265
+ "user.edit"
266
+ ]);
267
+ var ScopesWithRoleOption = UserScopeType.extract(["user.edit", "user.create"]);
268
+ var UserScopeV2 = z3.discriminatedUnion("type", [
269
+ z3.object({
270
+ type: ScopesWithRoleOption,
271
+ options: AllUserScopeOptions.optional()
272
+ }),
273
+ z3.object({
274
+ type: UserScopeType.extract(["user.read"]),
275
+ options: AccessLevelOptions.optional()
276
+ })
277
+ ]);
278
+ function scopeUsesRoleOptions(scope) {
279
+ return ScopesWithRoleOption?.options.some((opt) => opt === scope.type);
280
+ }
246
281
  function scopeUsesDeclaredOptions(scope) {
247
282
  return !ScopesWithPlaceEventOptions.options.some((opt) => opt === scope.type);
248
283
  }
@@ -275,16 +310,14 @@ var ResolvedRecordScopeV2 = z3.discriminatedUnion("type", [
275
310
  }).optional()
276
311
  })
277
312
  ]).describe("Resolved scope with location/user IDs instead of filters.");
278
- var SystemScopeType = z3.enum([
279
- "organisation.read-locations",
280
- "user.read",
281
- "user.create",
282
- "user.edit"
283
- ]);
284
313
  var Scope2 = z3.discriminatedUnion("type", [
285
314
  z3.object({ type: PlainScopeType }),
286
315
  ...RecordScopeV2.options,
287
- z3.object({ type: SystemScopeType, options: AccessLevelOptions.optional() }),
316
+ ...UserScopeV2.options,
317
+ z3.object({
318
+ type: z3.literal("organisation.read-locations"),
319
+ options: AccessLevelOptions.optional()
320
+ }),
288
321
  z3.object({
289
322
  type: z3.literal("workqueue"),
290
323
  options: WorkqueueOrDashboardOptions
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opencrvs/toolkit",
3
- "version": "2.0.0-rc.df1ed4f",
3
+ "version": "2.0.0-rc.e12607f",
4
4
  "description": "OpenCRVS toolkit for building country configurations",
5
5
  "license": "MPL-2.0",
6
6
  "bin": {