@opencrvs/toolkit 2.0.0-rc.a456517 → 2.0.0-rc.bee2b7b

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()
@@ -760,6 +764,33 @@ var RecordScopeV2 = z11.discriminatedUnion("type", [
760
764
  ]).describe(
761
765
  "Scopes used to check user's permission to perform actions on a record."
762
766
  );
767
+ var SystemScopeType = z11.enum([
768
+ "organisation.read-locations",
769
+ "user.read",
770
+ "user.create",
771
+ "user.edit"
772
+ ]);
773
+ var UserScopeType = SystemScopeType.extract([
774
+ "user.read",
775
+ "user.create",
776
+ "user.edit"
777
+ ]);
778
+ var ScopesWithRoleOption = UserScopeType.extract(["user.edit", "user.create"]);
779
+ var UserScopeV2 = z11.discriminatedUnion("type", [
780
+ z11.object({
781
+ type: ScopesWithRoleOption,
782
+ options: z11.object({
783
+ accessLevel: JurisdictionFilter.optional(),
784
+ role: userRole.optional()
785
+ }).optional()
786
+ }),
787
+ z11.object({
788
+ type: UserScopeType.extract(["user.read"]),
789
+ options: z11.object({
790
+ accessLevel: JurisdictionFilter.optional()
791
+ }).optional()
792
+ })
793
+ ]);
763
794
  var ResolvedRecordScopeV2 = z11.discriminatedUnion("type", [
764
795
  z11.object({
765
796
  type: ScopesWithPlaceEventOptions,
@@ -780,16 +811,14 @@ var ResolvedRecordScopeV2 = z11.discriminatedUnion("type", [
780
811
  }).optional()
781
812
  })
782
813
  ]).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
814
  var Scope = z11.discriminatedUnion("type", [
790
815
  z11.object({ type: PlainScopeType }),
791
816
  ...RecordScopeV2.options,
792
- z11.object({ type: SystemScopeType, options: AccessLevelOptions.optional() }),
817
+ ...UserScopeV2.options,
818
+ z11.object({
819
+ type: z11.literal("organisation.read-locations"),
820
+ options: AccessLevelOptions.optional()
821
+ }),
793
822
  z11.object({
794
823
  type: z11.literal("workqueue"),
795
824
  options: WorkqueueOrDashboardOptions
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()
@@ -2214,6 +2218,33 @@ var RecordScopeV2 = z3.discriminatedUnion("type", [
2214
2218
  ]).describe(
2215
2219
  "Scopes used to check user's permission to perform actions on a record."
2216
2220
  );
2221
+ var SystemScopeType = z3.enum([
2222
+ "organisation.read-locations",
2223
+ "user.read",
2224
+ "user.create",
2225
+ "user.edit"
2226
+ ]);
2227
+ var UserScopeType = SystemScopeType.extract([
2228
+ "user.read",
2229
+ "user.create",
2230
+ "user.edit"
2231
+ ]);
2232
+ var ScopesWithRoleOption = UserScopeType.extract(["user.edit", "user.create"]);
2233
+ var UserScopeV2 = z3.discriminatedUnion("type", [
2234
+ z3.object({
2235
+ type: ScopesWithRoleOption,
2236
+ options: z3.object({
2237
+ accessLevel: JurisdictionFilter.optional(),
2238
+ role: userRole.optional()
2239
+ }).optional()
2240
+ }),
2241
+ z3.object({
2242
+ type: UserScopeType.extract(["user.read"]),
2243
+ options: z3.object({
2244
+ accessLevel: JurisdictionFilter.optional()
2245
+ }).optional()
2246
+ })
2247
+ ]);
2217
2248
  var ResolvedRecordScopeV2 = z3.discriminatedUnion("type", [
2218
2249
  z3.object({
2219
2250
  type: ScopesWithPlaceEventOptions,
@@ -2234,16 +2265,14 @@ var ResolvedRecordScopeV2 = z3.discriminatedUnion("type", [
2234
2265
  }).optional()
2235
2266
  })
2236
2267
  ]).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
2268
  var Scope2 = z3.discriminatedUnion("type", [
2244
2269
  z3.object({ type: PlainScopeType }),
2245
2270
  ...RecordScopeV2.options,
2246
- z3.object({ type: SystemScopeType, options: AccessLevelOptions.optional() }),
2271
+ ...UserScopeV2.options,
2272
+ z3.object({
2273
+ type: z3.literal("organisation.read-locations"),
2274
+ options: AccessLevelOptions.optional()
2275
+ }),
2247
2276
  z3.object({
2248
2277
  type: z3.literal("workqueue"),
2249
2278
  options: WorkqueueOrDashboardOptions
@@ -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()
@@ -286,6 +290,33 @@ var RecordScopeV2 = z6.discriminatedUnion("type", [
286
290
  ]).describe(
287
291
  "Scopes used to check user's permission to perform actions on a record."
288
292
  );
293
+ var SystemScopeType = z6.enum([
294
+ "organisation.read-locations",
295
+ "user.read",
296
+ "user.create",
297
+ "user.edit"
298
+ ]);
299
+ var UserScopeType = SystemScopeType.extract([
300
+ "user.read",
301
+ "user.create",
302
+ "user.edit"
303
+ ]);
304
+ var ScopesWithRoleOption = UserScopeType.extract(["user.edit", "user.create"]);
305
+ var UserScopeV2 = z6.discriminatedUnion("type", [
306
+ z6.object({
307
+ type: ScopesWithRoleOption,
308
+ options: z6.object({
309
+ accessLevel: JurisdictionFilter.optional(),
310
+ role: userRole.optional()
311
+ }).optional()
312
+ }),
313
+ z6.object({
314
+ type: UserScopeType.extract(["user.read"]),
315
+ options: z6.object({
316
+ accessLevel: JurisdictionFilter.optional()
317
+ }).optional()
318
+ })
319
+ ]);
289
320
  var ResolvedRecordScopeV2 = z6.discriminatedUnion("type", [
290
321
  z6.object({
291
322
  type: ScopesWithPlaceEventOptions,
@@ -306,16 +337,14 @@ var ResolvedRecordScopeV2 = z6.discriminatedUnion("type", [
306
337
  }).optional()
307
338
  })
308
339
  ]).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
340
  var Scope2 = z6.discriminatedUnion("type", [
316
341
  z6.object({ type: PlainScopeType }),
317
342
  ...RecordScopeV2.options,
318
- z6.object({ type: SystemScopeType, options: AccessLevelOptions.optional() }),
343
+ ...UserScopeV2.options,
344
+ z6.object({
345
+ type: z6.literal("organisation.read-locations"),
346
+ options: AccessLevelOptions.optional()
347
+ }),
319
348
  z6.object({
320
349
  type: z6.literal("workqueue"),
321
350
  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()
@@ -593,6 +599,36 @@ var RecordScopeV2 = z2.discriminatedUnion("type", [
593
599
  ]).describe(
594
600
  "Scopes used to check user's permission to perform actions on a record."
595
601
  );
602
+ var SystemScopeType = z2.enum([
603
+ "organisation.read-locations",
604
+ "user.read",
605
+ "user.create",
606
+ "user.edit"
607
+ ]);
608
+ var UserScopeType = SystemScopeType.extract([
609
+ "user.read",
610
+ "user.create",
611
+ "user.edit"
612
+ ]);
613
+ var ScopesWithRoleOption = UserScopeType.extract(["user.edit", "user.create"]);
614
+ var UserScopeV2 = z2.discriminatedUnion("type", [
615
+ z2.object({
616
+ type: ScopesWithRoleOption,
617
+ options: z2.object({
618
+ accessLevel: JurisdictionFilter.optional(),
619
+ role: userRole.optional()
620
+ }).optional()
621
+ }),
622
+ z2.object({
623
+ type: UserScopeType.extract(["user.read"]),
624
+ options: z2.object({
625
+ accessLevel: JurisdictionFilter.optional()
626
+ }).optional()
627
+ })
628
+ ]);
629
+ function scopeUsesRoleOptions(scope) {
630
+ return ScopesWithRoleOption?.options.some((opt) => opt === scope.type);
631
+ }
596
632
  function scopeUsesDeclaredOptions(scope) {
597
633
  return !ScopesWithPlaceEventOptions.options.some((opt) => opt === scope.type);
598
634
  }
@@ -625,16 +661,14 @@ var ResolvedRecordScopeV2 = z2.discriminatedUnion("type", [
625
661
  }).optional()
626
662
  })
627
663
  ]).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
664
  var Scope = z2.discriminatedUnion("type", [
635
665
  z2.object({ type: PlainScopeType }),
636
666
  ...RecordScopeV2.options,
637
- z2.object({ type: SystemScopeType, options: AccessLevelOptions.optional() }),
667
+ ...UserScopeV2.options,
668
+ z2.object({
669
+ type: z2.literal("organisation.read-locations"),
670
+ options: AccessLevelOptions.optional()
671
+ }),
638
672
  z2.object({
639
673
  type: z2.literal("workqueue"),
640
674
  options: WorkqueueOrDashboardOptions
@@ -9930,6 +9964,39 @@ function canAccessEventWithScope(event2, scope, user2, customActionType) {
9930
9964
  }
9931
9965
  return true;
9932
9966
  }
9967
+ function canAccessUserWithScope({
9968
+ userToAccess,
9969
+ scope,
9970
+ user: user2
9971
+ }) {
9972
+ const opts = scope.options;
9973
+ const hasSameOffice = user2.primaryOfficeId === userToAccess.primaryOfficeId;
9974
+ if (opts?.accessLevel === JurisdictionFilter.enum.location && !hasSameOffice) {
9975
+ return false;
9976
+ }
9977
+ const hasAdministrativeAreaInHierarchy = userToAccess.administrativeHierarchy.some(
9978
+ (id) => user2.administrativeAreaId === id
9979
+ ) || user2.administrativeAreaId === null;
9980
+ if (opts?.accessLevel === JurisdictionFilter.enum.administrativeArea && !hasAdministrativeAreaInHierarchy) {
9981
+ return false;
9982
+ }
9983
+ if (scopeUsesRoleOptions(scope)) {
9984
+ const { options } = scope;
9985
+ if (options?.role && !options.role.includes(userToAccess.role)) {
9986
+ return false;
9987
+ }
9988
+ }
9989
+ return true;
9990
+ }
9991
+ function canAccessOtherUserWithScopes({
9992
+ scopes,
9993
+ userToAccess,
9994
+ user: user2
9995
+ }) {
9996
+ return scopes.some(
9997
+ (scope) => canAccessUserWithScope({ userToAccess, scope, user: user2 })
9998
+ );
9999
+ }
9933
10000
  function userCanAccessEventWithScopes(event2, scopes, user2, customActionType) {
9934
10001
  return scopes.some(
9935
10002
  (scope) => canAccessEventWithScope(event2, scope, user2, customActionType)
@@ -2123,6 +2123,10 @@ var scopeByEvent = z3.preprocess(
2123
2123
  (val) => val === void 0 ? void 0 : [val].flat(),
2124
2124
  z3.array(z3.string()).optional()
2125
2125
  ).describe("Event type, e.g. birth, death");
2126
+ var userRole = z3.preprocess(
2127
+ (val) => val === void 0 ? void 0 : [val].flat(),
2128
+ z3.array(z3.string()).optional()
2129
+ ).describe("User role, e.g. admin, field agent");
2126
2130
  var scopeOptionsPlaceEvent = z3.object({
2127
2131
  event: scopeByEvent,
2128
2132
  placeOfEvent: JurisdictionFilter.optional()
@@ -2227,6 +2231,33 @@ var RecordScopeV2 = z3.discriminatedUnion("type", [
2227
2231
  ]).describe(
2228
2232
  "Scopes used to check user's permission to perform actions on a record."
2229
2233
  );
2234
+ var SystemScopeType = z3.enum([
2235
+ "organisation.read-locations",
2236
+ "user.read",
2237
+ "user.create",
2238
+ "user.edit"
2239
+ ]);
2240
+ var UserScopeType = SystemScopeType.extract([
2241
+ "user.read",
2242
+ "user.create",
2243
+ "user.edit"
2244
+ ]);
2245
+ var ScopesWithRoleOption = UserScopeType.extract(["user.edit", "user.create"]);
2246
+ var UserScopeV2 = z3.discriminatedUnion("type", [
2247
+ z3.object({
2248
+ type: ScopesWithRoleOption,
2249
+ options: z3.object({
2250
+ accessLevel: JurisdictionFilter.optional(),
2251
+ role: userRole.optional()
2252
+ }).optional()
2253
+ }),
2254
+ z3.object({
2255
+ type: UserScopeType.extract(["user.read"]),
2256
+ options: z3.object({
2257
+ accessLevel: JurisdictionFilter.optional()
2258
+ }).optional()
2259
+ })
2260
+ ]);
2230
2261
  var ResolvedRecordScopeV2 = z3.discriminatedUnion("type", [
2231
2262
  z3.object({
2232
2263
  type: ScopesWithPlaceEventOptions,
@@ -2247,16 +2278,14 @@ var ResolvedRecordScopeV2 = z3.discriminatedUnion("type", [
2247
2278
  }).optional()
2248
2279
  })
2249
2280
  ]).describe("Resolved scope with location/user IDs instead of filters.");
2250
- var SystemScopeType = z3.enum([
2251
- "organisation.read-locations",
2252
- "user.read",
2253
- "user.create",
2254
- "user.edit"
2255
- ]);
2256
2281
  var Scope2 = z3.discriminatedUnion("type", [
2257
2282
  z3.object({ type: PlainScopeType }),
2258
2283
  ...RecordScopeV2.options,
2259
- z3.object({ type: SystemScopeType, options: AccessLevelOptions.optional() }),
2284
+ ...UserScopeV2.options,
2285
+ z3.object({
2286
+ type: z3.literal("organisation.read-locations"),
2287
+ options: AccessLevelOptions.optional()
2288
+ }),
2260
2289
  z3.object({
2261
2290
  type: z3.literal("workqueue"),
2262
2291
  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()
@@ -214,6 +218,33 @@ var RecordScopeV2 = z2.discriminatedUnion("type", [
214
218
  ]).describe(
215
219
  "Scopes used to check user's permission to perform actions on a record."
216
220
  );
221
+ var SystemScopeType = z2.enum([
222
+ "organisation.read-locations",
223
+ "user.read",
224
+ "user.create",
225
+ "user.edit"
226
+ ]);
227
+ var UserScopeType = SystemScopeType.extract([
228
+ "user.read",
229
+ "user.create",
230
+ "user.edit"
231
+ ]);
232
+ var ScopesWithRoleOption = UserScopeType.extract(["user.edit", "user.create"]);
233
+ var UserScopeV2 = z2.discriminatedUnion("type", [
234
+ z2.object({
235
+ type: ScopesWithRoleOption,
236
+ options: z2.object({
237
+ accessLevel: JurisdictionFilter.optional(),
238
+ role: userRole.optional()
239
+ }).optional()
240
+ }),
241
+ z2.object({
242
+ type: UserScopeType.extract(["user.read"]),
243
+ options: z2.object({
244
+ accessLevel: JurisdictionFilter.optional()
245
+ }).optional()
246
+ })
247
+ ]);
217
248
  var ResolvedRecordScopeV2 = z2.discriminatedUnion("type", [
218
249
  z2.object({
219
250
  type: ScopesWithPlaceEventOptions,
@@ -234,16 +265,14 @@ var ResolvedRecordScopeV2 = z2.discriminatedUnion("type", [
234
265
  }).optional()
235
266
  })
236
267
  ]).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
268
  var Scope = z2.discriminatedUnion("type", [
244
269
  z2.object({ type: PlainScopeType }),
245
270
  ...RecordScopeV2.options,
246
- z2.object({ type: SystemScopeType, options: AccessLevelOptions.optional() }),
271
+ ...UserScopeV2.options,
272
+ z2.object({
273
+ type: z2.literal("organisation.read-locations"),
274
+ options: AccessLevelOptions.optional()
275
+ }),
247
276
  z2.object({
248
277
  type: z2.literal("workqueue"),
249
278
  options: WorkqueueOrDashboardOptions
@@ -220,6 +220,53 @@ export declare const RecordScopeV2: z.ZodDiscriminatedUnion<[z.ZodObject<{
220
220
  templates: z.ZodPipe<z.ZodTransform<({} | null)[] | undefined, unknown>, z.ZodOptional<z.ZodArray<z.ZodString>>>;
221
221
  }, z.core.$strip>>;
222
222
  }, z.core.$strip>], "type">;
223
+ declare const SystemScopeType: z.ZodEnum<{
224
+ "organisation.read-locations": "organisation.read-locations";
225
+ "user.read": "user.read";
226
+ "user.create": "user.create";
227
+ "user.edit": "user.edit";
228
+ }>;
229
+ export type SystemScopeType = z.infer<typeof SystemScopeType>;
230
+ declare const UserScopeType: z.ZodEnum<{
231
+ "user.read": "user.read";
232
+ "user.create": "user.create";
233
+ "user.edit": "user.edit";
234
+ }>;
235
+ export type UserScopeType = z.infer<typeof UserScopeType>;
236
+ declare const ScopesWithRoleOption: z.ZodEnum<{
237
+ "user.create": "user.create";
238
+ "user.edit": "user.edit";
239
+ }>;
240
+ export type ScopesWithRoleOption = z.infer<typeof ScopesWithRoleOption>;
241
+ export declare const UserScopeV2: z.ZodDiscriminatedUnion<[z.ZodObject<{
242
+ type: z.ZodEnum<{
243
+ "user.create": "user.create";
244
+ "user.edit": "user.edit";
245
+ }>;
246
+ options: z.ZodOptional<z.ZodObject<{
247
+ accessLevel: z.ZodOptional<z.ZodEnum<{
248
+ administrativeArea: "administrativeArea";
249
+ location: "location";
250
+ all: "all";
251
+ }>>;
252
+ role: z.ZodOptional<z.ZodPipe<z.ZodTransform<({} | null)[] | undefined, unknown>, z.ZodOptional<z.ZodArray<z.ZodString>>>>;
253
+ }, z.core.$strip>>;
254
+ }, z.core.$strip>, z.ZodObject<{
255
+ type: z.ZodEnum<{
256
+ "user.read": "user.read";
257
+ }>;
258
+ options: z.ZodOptional<z.ZodObject<{
259
+ accessLevel: z.ZodOptional<z.ZodEnum<{
260
+ administrativeArea: "administrativeArea";
261
+ location: "location";
262
+ all: "all";
263
+ }>>;
264
+ }, z.core.$strip>>;
265
+ }, z.core.$strip>], "type">;
266
+ export type UserScopeV2 = z.infer<typeof UserScopeV2>;
267
+ export declare function scopeUsesRoleOptions(scope: UserScopeV2): scope is Extract<UserScopeV2, {
268
+ type: ScopesWithRoleOption;
269
+ }>;
223
270
  export declare function scopeUsesDeclaredOptions(scope: Scope): scope is Extract<Scope, {
224
271
  type: z.infer<typeof ScopesWithDeclaredOptions>;
225
272
  }>;
@@ -286,13 +333,6 @@ export declare const ResolvedRecordScopeV2: z.ZodDiscriminatedUnion<[z.ZodObject
286
333
  }, z.core.$strip>], "type">;
287
334
  export type RecordScopeV2 = z.infer<typeof RecordScopeV2>;
288
335
  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
336
  /** 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
337
  export declare const Scope: z.ZodDiscriminatedUnion<[z.ZodObject<{
298
338
  type: z.ZodEnum<{
@@ -437,11 +477,30 @@ export declare const Scope: z.ZodDiscriminatedUnion<[z.ZodObject<{
437
477
  }, z.core.$strip>>;
438
478
  }, z.core.$strip>, z.ZodObject<{
439
479
  type: z.ZodEnum<{
440
- "organisation.read-locations": "organisation.read-locations";
441
- "user.read": "user.read";
442
480
  "user.create": "user.create";
443
481
  "user.edit": "user.edit";
444
482
  }>;
483
+ options: z.ZodOptional<z.ZodObject<{
484
+ accessLevel: z.ZodOptional<z.ZodEnum<{
485
+ administrativeArea: "administrativeArea";
486
+ location: "location";
487
+ all: "all";
488
+ }>>;
489
+ role: z.ZodOptional<z.ZodPipe<z.ZodTransform<({} | null)[] | undefined, unknown>, z.ZodOptional<z.ZodArray<z.ZodString>>>>;
490
+ }, z.core.$strip>>;
491
+ }, z.core.$strip>, z.ZodObject<{
492
+ type: z.ZodEnum<{
493
+ "user.read": "user.read";
494
+ }>;
495
+ options: z.ZodOptional<z.ZodObject<{
496
+ accessLevel: z.ZodOptional<z.ZodEnum<{
497
+ administrativeArea: "administrativeArea";
498
+ location: "location";
499
+ all: "all";
500
+ }>>;
501
+ }, z.core.$strip>>;
502
+ }, z.core.$strip>, z.ZodObject<{
503
+ type: z.ZodLiteral<"organisation.read-locations">;
445
504
  options: z.ZodOptional<z.ZodObject<{
446
505
  accessLevel: z.ZodOptional<z.ZodEnum<{
447
506
  administrativeArea: "administrativeArea";
@@ -567,10 +626,21 @@ export declare const decodeScope: (query: EncodedScope) => {
567
626
  registeredBy?: "user" | undefined;
568
627
  templates?: string[] | undefined;
569
628
  } | undefined;
629
+ } | {
630
+ type: "user.create" | "user.edit";
631
+ options?: {
632
+ accessLevel?: "administrativeArea" | "location" | "all" | undefined;
633
+ role?: string[] | undefined;
634
+ } | undefined;
635
+ } | {
636
+ type: "user.read";
637
+ options?: {
638
+ accessLevel?: "administrativeArea" | "location" | "all" | undefined;
639
+ } | undefined;
570
640
  } | {
571
641
  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
642
  } | {
573
- type: "organisation.read-locations" | "user.read" | "user.create" | "user.edit";
643
+ type: "organisation.read-locations";
574
644
  options?: {
575
645
  accessLevel?: "administrativeArea" | "location" | "all" | undefined;
576
646
  } | 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()
@@ -243,6 +249,36 @@ var RecordScopeV2 = z3.discriminatedUnion("type", [
243
249
  ]).describe(
244
250
  "Scopes used to check user's permission to perform actions on a record."
245
251
  );
252
+ var SystemScopeType = z3.enum([
253
+ "organisation.read-locations",
254
+ "user.read",
255
+ "user.create",
256
+ "user.edit"
257
+ ]);
258
+ var UserScopeType = SystemScopeType.extract([
259
+ "user.read",
260
+ "user.create",
261
+ "user.edit"
262
+ ]);
263
+ var ScopesWithRoleOption = UserScopeType.extract(["user.edit", "user.create"]);
264
+ var UserScopeV2 = z3.discriminatedUnion("type", [
265
+ z3.object({
266
+ type: ScopesWithRoleOption,
267
+ options: z3.object({
268
+ accessLevel: JurisdictionFilter.optional(),
269
+ role: userRole.optional()
270
+ }).optional()
271
+ }),
272
+ z3.object({
273
+ type: UserScopeType.extract(["user.read"]),
274
+ options: z3.object({
275
+ accessLevel: JurisdictionFilter.optional()
276
+ }).optional()
277
+ })
278
+ ]);
279
+ function scopeUsesRoleOptions(scope) {
280
+ return ScopesWithRoleOption?.options.some((opt) => opt === scope.type);
281
+ }
246
282
  function scopeUsesDeclaredOptions(scope) {
247
283
  return !ScopesWithPlaceEventOptions.options.some((opt) => opt === scope.type);
248
284
  }
@@ -275,16 +311,14 @@ var ResolvedRecordScopeV2 = z3.discriminatedUnion("type", [
275
311
  }).optional()
276
312
  })
277
313
  ]).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
314
  var Scope2 = z3.discriminatedUnion("type", [
285
315
  z3.object({ type: PlainScopeType }),
286
316
  ...RecordScopeV2.options,
287
- z3.object({ type: SystemScopeType, options: AccessLevelOptions.optional() }),
317
+ ...UserScopeV2.options,
318
+ z3.object({
319
+ type: z3.literal("organisation.read-locations"),
320
+ options: AccessLevelOptions.optional()
321
+ }),
288
322
  z3.object({
289
323
  type: z3.literal("workqueue"),
290
324
  options: WorkqueueOrDashboardOptions
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opencrvs/toolkit",
3
- "version": "2.0.0-rc.a456517",
3
+ "version": "2.0.0-rc.bee2b7b",
4
4
  "description": "OpenCRVS toolkit for building country configurations",
5
5
  "license": "MPL-2.0",
6
6
  "bin": {