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

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,10 +656,6 @@ 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");
663
659
  var scopeOptionsPlaceEvent = z11.object({
664
660
  event: scopeByEvent,
665
661
  placeOfEvent: JurisdictionFilter.optional()
@@ -683,9 +679,6 @@ var CustomActionScopeOptions = AllRecordScopeOptions.extend({
683
679
  var AccessLevelOptions = z11.object({
684
680
  accessLevel: JurisdictionFilter.optional()
685
681
  });
686
- var AllUserScopeOptions = AccessLevelOptions.extend({
687
- role: userRole.optional()
688
- });
689
682
  var WorkqueueOrDashboardOptions = z11.object({
690
683
  ids: z11.preprocess(
691
684
  (val) => val === void 0 ? void 0 : [val].flat(),
@@ -695,7 +688,6 @@ var WorkqueueOrDashboardOptions = z11.object({
695
688
  var AllScopeOptions = z11.object({
696
689
  ...AllRecordScopeOptions.shape,
697
690
  ...AccessLevelOptions.shape,
698
- ...AllUserScopeOptions.shape,
699
691
  ...WorkqueueOrDashboardOptions.shape
700
692
  });
701
693
  var ScopeOptionKey = AllScopeOptions.keyof();
@@ -768,28 +760,6 @@ var RecordScopeV2 = z11.discriminatedUnion("type", [
768
760
  ]).describe(
769
761
  "Scopes used to check user's permission to perform actions on a record."
770
762
  );
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
- ]);
793
763
  var ResolvedRecordScopeV2 = z11.discriminatedUnion("type", [
794
764
  z11.object({
795
765
  type: ScopesWithPlaceEventOptions,
@@ -810,14 +780,16 @@ var ResolvedRecordScopeV2 = z11.discriminatedUnion("type", [
810
780
  }).optional()
811
781
  })
812
782
  ]).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
+ ]);
813
789
  var Scope = z11.discriminatedUnion("type", [
814
790
  z11.object({ type: PlainScopeType }),
815
791
  ...RecordScopeV2.options,
816
- ...UserScopeV2.options,
817
- z11.object({
818
- type: z11.literal("organisation.read-locations"),
819
- options: AccessLevelOptions.optional()
820
- }),
792
+ z11.object({ type: SystemScopeType, options: AccessLevelOptions.optional() }),
821
793
  z11.object({
822
794
  type: z11.literal("workqueue"),
823
795
  options: WorkqueueOrDashboardOptions
package/dist/cli.js CHANGED
@@ -2110,10 +2110,6 @@ 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");
2117
2113
  var scopeOptionsPlaceEvent = z3.object({
2118
2114
  event: scopeByEvent,
2119
2115
  placeOfEvent: JurisdictionFilter.optional()
@@ -2137,9 +2133,6 @@ var CustomActionScopeOptions = AllRecordScopeOptions.extend({
2137
2133
  var AccessLevelOptions = z3.object({
2138
2134
  accessLevel: JurisdictionFilter.optional()
2139
2135
  });
2140
- var AllUserScopeOptions = AccessLevelOptions.extend({
2141
- role: userRole.optional()
2142
- });
2143
2136
  var WorkqueueOrDashboardOptions = z3.object({
2144
2137
  ids: z3.preprocess(
2145
2138
  (val) => val === void 0 ? void 0 : [val].flat(),
@@ -2149,7 +2142,6 @@ var WorkqueueOrDashboardOptions = z3.object({
2149
2142
  var AllScopeOptions = z3.object({
2150
2143
  ...AllRecordScopeOptions.shape,
2151
2144
  ...AccessLevelOptions.shape,
2152
- ...AllUserScopeOptions.shape,
2153
2145
  ...WorkqueueOrDashboardOptions.shape
2154
2146
  });
2155
2147
  var ScopeOptionKey = AllScopeOptions.keyof();
@@ -2222,28 +2214,6 @@ var RecordScopeV2 = z3.discriminatedUnion("type", [
2222
2214
  ]).describe(
2223
2215
  "Scopes used to check user's permission to perform actions on a record."
2224
2216
  );
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
- ]);
2247
2217
  var ResolvedRecordScopeV2 = z3.discriminatedUnion("type", [
2248
2218
  z3.object({
2249
2219
  type: ScopesWithPlaceEventOptions,
@@ -2264,14 +2234,16 @@ var ResolvedRecordScopeV2 = z3.discriminatedUnion("type", [
2264
2234
  }).optional()
2265
2235
  })
2266
2236
  ]).describe("Resolved scope with location/user IDs instead of filters.");
2237
+ var SystemScopeType = z3.enum([
2238
+ "organisation.read-locations",
2239
+ "user.read",
2240
+ "user.create",
2241
+ "user.edit"
2242
+ ]);
2267
2243
  var Scope2 = z3.discriminatedUnion("type", [
2268
2244
  z3.object({ type: PlainScopeType }),
2269
2245
  ...RecordScopeV2.options,
2270
- ...UserScopeV2.options,
2271
- z3.object({
2272
- type: z3.literal("organisation.read-locations"),
2273
- options: AccessLevelOptions.optional()
2274
- }),
2246
+ z3.object({ type: SystemScopeType, options: AccessLevelOptions.optional() }),
2275
2247
  z3.object({
2276
2248
  type: z3.literal("workqueue"),
2277
2249
  options: WorkqueueOrDashboardOptions
@@ -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: "role" | "event" | "placeOfEvent" | "declaredIn" | "declaredBy" | "registeredIn" | "registeredBy" | "accessLevel" | "ids";
90
+ $option: "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: "role" | "event" | "placeOfEvent" | "declaredIn" | "declaredBy" | "registeredIn" | "registeredBy" | "accessLevel" | "ids";
95
+ $option: "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: "role" | "event" | "placeOfEvent" | "declaredIn" | "declaredBy" | "registeredIn" | "registeredBy" | "accessLevel" | "ids";
99
+ $option: "event" | "placeOfEvent" | "declaredIn" | "declaredBy" | "registeredIn" | "registeredBy" | "accessLevel" | "ids";
100
100
  };
101
101
  };
102
102
  };
@@ -1727,7 +1727,6 @@ declare const AdministrativeAreaField: z.ZodObject<{
1727
1727
  "dashboard.view": "dashboard.view";
1728
1728
  }>;
1729
1729
  $option: z.ZodEnum<{
1730
- role: "role";
1731
1730
  event: "event";
1732
1731
  placeOfEvent: "placeOfEvent";
1733
1732
  declaredIn: "declaredIn";
@@ -1846,7 +1845,6 @@ declare const LocationInput: z.ZodObject<{
1846
1845
  "dashboard.view": "dashboard.view";
1847
1846
  }>;
1848
1847
  $option: z.ZodEnum<{
1849
- role: "role";
1850
1848
  event: "event";
1851
1849
  placeOfEvent: "placeOfEvent";
1852
1850
  declaredIn: "declaredIn";
@@ -2030,7 +2028,6 @@ declare const Facility: z.ZodObject<{
2030
2028
  "dashboard.view": "dashboard.view";
2031
2029
  }>;
2032
2030
  $option: z.ZodEnum<{
2033
- role: "role";
2034
2031
  event: "event";
2035
2032
  placeOfEvent: "placeOfEvent";
2036
2033
  declaredIn: "declaredIn";
@@ -2135,7 +2132,6 @@ declare const Office: z.ZodObject<{
2135
2132
  "dashboard.view": "dashboard.view";
2136
2133
  }>;
2137
2134
  $option: z.ZodEnum<{
2138
- role: "role";
2139
2135
  event: "event";
2140
2136
  placeOfEvent: "placeOfEvent";
2141
2137
  declaredIn: "declaredIn";
@@ -2327,7 +2323,6 @@ declare const Address: z.ZodObject<{
2327
2323
  "dashboard.view": "dashboard.view";
2328
2324
  }>;
2329
2325
  $option: z.ZodEnum<{
2330
- role: "role";
2331
2326
  event: "event";
2332
2327
  placeOfEvent: "placeOfEvent";
2333
2328
  declaredIn: "declaredIn";
@@ -1,8 +1,7 @@
1
- import { UUID } from '../uuid';
2
1
  import * as z from 'zod/v4';
3
2
  import { EventIndex } from './EventIndex';
4
3
  import { ActionCreationMetadata, RegistrationCreationMetadata } from './EventMetadata';
5
- import { RecordScopeV2, UserScopeV2 } from '../scopes';
4
+ import { RecordScopeV2 } from '../scopes';
6
5
  import { SystemContext, UserContext } from '../users/User';
7
6
  /** @deprecated Moving on, location types are arbitrary and defined by the country config. */
8
7
  export declare const LocationTypeV1: z.ZodEnum<{
@@ -52,21 +51,6 @@ export type EventIndexWithAdministrativeHierarchy = Omit<ToArrayFields<EventInde
52
51
  *
53
52
  */
54
53
  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;
70
54
  /**
71
55
  * Given indexed event and list of resolved scopes, determine if any of the scopes allow access to the event.
72
56
  *
@@ -182,10 +182,6 @@ 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");
189
185
  var scopeOptionsPlaceEvent = z6.object({
190
186
  event: scopeByEvent,
191
187
  placeOfEvent: JurisdictionFilter.optional()
@@ -209,9 +205,6 @@ var CustomActionScopeOptions = AllRecordScopeOptions.extend({
209
205
  var AccessLevelOptions = z6.object({
210
206
  accessLevel: JurisdictionFilter.optional()
211
207
  });
212
- var AllUserScopeOptions = AccessLevelOptions.extend({
213
- role: userRole.optional()
214
- });
215
208
  var WorkqueueOrDashboardOptions = z6.object({
216
209
  ids: z6.preprocess(
217
210
  (val) => val === void 0 ? void 0 : [val].flat(),
@@ -221,7 +214,6 @@ var WorkqueueOrDashboardOptions = z6.object({
221
214
  var AllScopeOptions = z6.object({
222
215
  ...AllRecordScopeOptions.shape,
223
216
  ...AccessLevelOptions.shape,
224
- ...AllUserScopeOptions.shape,
225
217
  ...WorkqueueOrDashboardOptions.shape
226
218
  });
227
219
  var ScopeOptionKey = AllScopeOptions.keyof();
@@ -294,28 +286,6 @@ var RecordScopeV2 = z6.discriminatedUnion("type", [
294
286
  ]).describe(
295
287
  "Scopes used to check user's permission to perform actions on a record."
296
288
  );
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
- ]);
319
289
  var ResolvedRecordScopeV2 = z6.discriminatedUnion("type", [
320
290
  z6.object({
321
291
  type: ScopesWithPlaceEventOptions,
@@ -336,14 +306,16 @@ var ResolvedRecordScopeV2 = z6.discriminatedUnion("type", [
336
306
  }).optional()
337
307
  })
338
308
  ]).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
+ ]);
339
315
  var Scope2 = z6.discriminatedUnion("type", [
340
316
  z6.object({ type: PlainScopeType }),
341
317
  ...RecordScopeV2.options,
342
- ...UserScopeV2.options,
343
- z6.object({
344
- type: z6.literal("organisation.read-locations"),
345
- options: AccessLevelOptions.optional()
346
- }),
318
+ z6.object({ type: SystemScopeType, options: AccessLevelOptions.optional() }),
347
319
  z6.object({
348
320
  type: z6.literal("workqueue"),
349
321
  options: WorkqueueOrDashboardOptions
@@ -243,8 +243,6 @@ __export(events_exports, {
243
243
  areConditionsMet: () => areConditionsMet,
244
244
  buildFormState: () => buildFormState,
245
245
  canAccessEventWithScope: () => canAccessEventWithScope,
246
- canAccessOtherUserWithScopes: () => canAccessOtherUserWithScopes,
247
- canAccessUserWithScope: () => canAccessUserWithScope,
248
246
  compositeFieldTypes: () => compositeFieldTypes,
249
247
  createEmptyDraft: () => createEmptyDraft,
250
248
  createFieldConditionals: () => createFieldConditionals,
@@ -491,10 +489,6 @@ var scopeByEvent = z2.preprocess(
491
489
  (val) => val === void 0 ? void 0 : [val].flat(),
492
490
  z2.array(z2.string()).optional()
493
491
  ).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");
498
492
  var scopeOptionsPlaceEvent = z2.object({
499
493
  event: scopeByEvent,
500
494
  placeOfEvent: JurisdictionFilter.optional()
@@ -518,9 +512,6 @@ var CustomActionScopeOptions = AllRecordScopeOptions.extend({
518
512
  var AccessLevelOptions = z2.object({
519
513
  accessLevel: JurisdictionFilter.optional()
520
514
  });
521
- var AllUserScopeOptions = AccessLevelOptions.extend({
522
- role: userRole.optional()
523
- });
524
515
  var WorkqueueOrDashboardOptions = z2.object({
525
516
  ids: z2.preprocess(
526
517
  (val) => val === void 0 ? void 0 : [val].flat(),
@@ -530,7 +521,6 @@ var WorkqueueOrDashboardOptions = z2.object({
530
521
  var AllScopeOptions = z2.object({
531
522
  ...AllRecordScopeOptions.shape,
532
523
  ...AccessLevelOptions.shape,
533
- ...AllUserScopeOptions.shape,
534
524
  ...WorkqueueOrDashboardOptions.shape
535
525
  });
536
526
  var ScopeOptionKey = AllScopeOptions.keyof();
@@ -603,31 +593,6 @@ var RecordScopeV2 = z2.discriminatedUnion("type", [
603
593
  ]).describe(
604
594
  "Scopes used to check user's permission to perform actions on a record."
605
595
  );
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
- }
631
596
  function scopeUsesDeclaredOptions(scope) {
632
597
  return !ScopesWithPlaceEventOptions.options.some((opt) => opt === scope.type);
633
598
  }
@@ -660,14 +625,16 @@ var ResolvedRecordScopeV2 = z2.discriminatedUnion("type", [
660
625
  }).optional()
661
626
  })
662
627
  ]).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
+ ]);
663
634
  var Scope = z2.discriminatedUnion("type", [
664
635
  z2.object({ type: PlainScopeType }),
665
636
  ...RecordScopeV2.options,
666
- ...UserScopeV2.options,
667
- z2.object({
668
- type: z2.literal("organisation.read-locations"),
669
- options: AccessLevelOptions.optional()
670
- }),
637
+ z2.object({ type: SystemScopeType, options: AccessLevelOptions.optional() }),
671
638
  z2.object({
672
639
  type: z2.literal("workqueue"),
673
640
  options: WorkqueueOrDashboardOptions
@@ -9963,39 +9930,6 @@ function canAccessEventWithScope(event2, scope, user2, customActionType) {
9963
9930
  }
9964
9931
  return true;
9965
9932
  }
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
- }
9999
9933
  function userCanAccessEventWithScopes(event2, scopes, user2, customActionType) {
10000
9934
  return scopes.some(
10001
9935
  (scope) => canAccessEventWithScope(event2, scope, user2, customActionType)
@@ -2122,10 +2122,6 @@ 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");
2129
2125
  var scopeOptionsPlaceEvent = z3.object({
2130
2126
  event: scopeByEvent,
2131
2127
  placeOfEvent: JurisdictionFilter.optional()
@@ -2149,9 +2145,6 @@ var CustomActionScopeOptions = AllRecordScopeOptions.extend({
2149
2145
  var AccessLevelOptions = z3.object({
2150
2146
  accessLevel: JurisdictionFilter.optional()
2151
2147
  });
2152
- var AllUserScopeOptions = AccessLevelOptions.extend({
2153
- role: userRole.optional()
2154
- });
2155
2148
  var WorkqueueOrDashboardOptions = z3.object({
2156
2149
  ids: z3.preprocess(
2157
2150
  (val) => val === void 0 ? void 0 : [val].flat(),
@@ -2161,7 +2154,6 @@ var WorkqueueOrDashboardOptions = z3.object({
2161
2154
  var AllScopeOptions = z3.object({
2162
2155
  ...AllRecordScopeOptions.shape,
2163
2156
  ...AccessLevelOptions.shape,
2164
- ...AllUserScopeOptions.shape,
2165
2157
  ...WorkqueueOrDashboardOptions.shape
2166
2158
  });
2167
2159
  var ScopeOptionKey = AllScopeOptions.keyof();
@@ -2234,28 +2226,6 @@ var RecordScopeV2 = z3.discriminatedUnion("type", [
2234
2226
  ]).describe(
2235
2227
  "Scopes used to check user's permission to perform actions on a record."
2236
2228
  );
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
- ]);
2259
2229
  var ResolvedRecordScopeV2 = z3.discriminatedUnion("type", [
2260
2230
  z3.object({
2261
2231
  type: ScopesWithPlaceEventOptions,
@@ -2276,14 +2246,16 @@ var ResolvedRecordScopeV2 = z3.discriminatedUnion("type", [
2276
2246
  }).optional()
2277
2247
  })
2278
2248
  ]).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
+ ]);
2279
2255
  var Scope2 = z3.discriminatedUnion("type", [
2280
2256
  z3.object({ type: PlainScopeType }),
2281
2257
  ...RecordScopeV2.options,
2282
- ...UserScopeV2.options,
2283
- z3.object({
2284
- type: z3.literal("organisation.read-locations"),
2285
- options: AccessLevelOptions.optional()
2286
- }),
2258
+ z3.object({ type: SystemScopeType, options: AccessLevelOptions.optional() }),
2287
2259
  z3.object({
2288
2260
  type: z3.literal("workqueue"),
2289
2261
  options: WorkqueueOrDashboardOptions
@@ -110,10 +110,6 @@ 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");
117
113
  var scopeOptionsPlaceEvent = z2.object({
118
114
  event: scopeByEvent,
119
115
  placeOfEvent: JurisdictionFilter.optional()
@@ -137,9 +133,6 @@ var CustomActionScopeOptions = AllRecordScopeOptions.extend({
137
133
  var AccessLevelOptions = z2.object({
138
134
  accessLevel: JurisdictionFilter.optional()
139
135
  });
140
- var AllUserScopeOptions = AccessLevelOptions.extend({
141
- role: userRole.optional()
142
- });
143
136
  var WorkqueueOrDashboardOptions = z2.object({
144
137
  ids: z2.preprocess(
145
138
  (val) => val === void 0 ? void 0 : [val].flat(),
@@ -149,7 +142,6 @@ var WorkqueueOrDashboardOptions = z2.object({
149
142
  var AllScopeOptions = z2.object({
150
143
  ...AllRecordScopeOptions.shape,
151
144
  ...AccessLevelOptions.shape,
152
- ...AllUserScopeOptions.shape,
153
145
  ...WorkqueueOrDashboardOptions.shape
154
146
  });
155
147
  var ScopeOptionKey = AllScopeOptions.keyof();
@@ -222,28 +214,6 @@ var RecordScopeV2 = z2.discriminatedUnion("type", [
222
214
  ]).describe(
223
215
  "Scopes used to check user's permission to perform actions on a record."
224
216
  );
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
- ]);
247
217
  var ResolvedRecordScopeV2 = z2.discriminatedUnion("type", [
248
218
  z2.object({
249
219
  type: ScopesWithPlaceEventOptions,
@@ -264,14 +234,16 @@ var ResolvedRecordScopeV2 = z2.discriminatedUnion("type", [
264
234
  }).optional()
265
235
  })
266
236
  ]).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
+ ]);
267
243
  var Scope = z2.discriminatedUnion("type", [
268
244
  z2.object({ type: PlainScopeType }),
269
245
  ...RecordScopeV2.options,
270
- ...UserScopeV2.options,
271
- z2.object({
272
- type: z2.literal("organisation.read-locations"),
273
- options: AccessLevelOptions.optional()
274
- }),
246
+ z2.object({ type: SystemScopeType, options: AccessLevelOptions.optional() }),
275
247
  z2.object({
276
248
  type: z2.literal("workqueue"),
277
249
  options: WorkqueueOrDashboardOptions
@@ -41,7 +41,6 @@ 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>>>>;
45
44
  event: z.ZodPipe<z.ZodTransform<({} | null)[] | undefined, unknown>, z.ZodOptional<z.ZodArray<z.ZodString>>>;
46
45
  placeOfEvent: z.ZodOptional<z.ZodEnum<{
47
46
  administrativeArea: "administrativeArea";
@@ -67,7 +66,6 @@ declare const AllScopeOptions: z.ZodObject<{
67
66
  }, z.core.$strip>;
68
67
  type AllScopeOptions = z.infer<typeof AllScopeOptions>;
69
68
  export declare const ScopeOptionKey: z.ZodEnum<{
70
- role: "role";
71
69
  event: "event";
72
70
  placeOfEvent: "placeOfEvent";
73
71
  declaredIn: "declaredIn";
@@ -222,53 +220,6 @@ export declare const RecordScopeV2: z.ZodDiscriminatedUnion<[z.ZodObject<{
222
220
  templates: z.ZodPipe<z.ZodTransform<({} | null)[] | undefined, unknown>, z.ZodOptional<z.ZodArray<z.ZodString>>>;
223
221
  }, z.core.$strip>>;
224
222
  }, 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
- }>;
272
223
  export declare function scopeUsesDeclaredOptions(scope: Scope): scope is Extract<Scope, {
273
224
  type: z.infer<typeof ScopesWithDeclaredOptions>;
274
225
  }>;
@@ -335,6 +286,13 @@ export declare const ResolvedRecordScopeV2: z.ZodDiscriminatedUnion<[z.ZodObject
335
286
  }, z.core.$strip>], "type">;
336
287
  export type RecordScopeV2 = z.infer<typeof RecordScopeV2>;
337
288
  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>;
338
296
  /** The primary scope schema which gathers all scope types together. All scopes are discriminated by type and options are determined according to the type. */
339
297
  export declare const Scope: z.ZodDiscriminatedUnion<[z.ZodObject<{
340
298
  type: z.ZodEnum<{
@@ -479,30 +437,11 @@ export declare const Scope: z.ZodDiscriminatedUnion<[z.ZodObject<{
479
437
  }, z.core.$strip>>;
480
438
  }, z.core.$strip>, z.ZodObject<{
481
439
  type: z.ZodEnum<{
440
+ "organisation.read-locations": "organisation.read-locations";
441
+ "user.read": "user.read";
482
442
  "user.create": "user.create";
483
443
  "user.edit": "user.edit";
484
444
  }>;
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">;
506
445
  options: z.ZodOptional<z.ZodObject<{
507
446
  accessLevel: z.ZodOptional<z.ZodEnum<{
508
447
  administrativeArea: "administrativeArea";
@@ -628,21 +567,10 @@ export declare const decodeScope: (query: EncodedScope) => {
628
567
  registeredBy?: "user" | undefined;
629
568
  templates?: string[] | undefined;
630
569
  } | 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;
642
570
  } | {
643
571
  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";
644
572
  } | {
645
- type: "organisation.read-locations";
573
+ type: "organisation.read-locations" | "user.read" | "user.create" | "user.edit";
646
574
  options?: {
647
575
  accessLevel?: "administrativeArea" | "location" | "all" | undefined;
648
576
  } | undefined;
@@ -42,7 +42,6 @@ __export(scopes_exports, {
42
42
  ScopesWithFullOptions: () => ScopesWithFullOptions,
43
43
  ScopesWithPlaceEventOptions: () => ScopesWithPlaceEventOptions,
44
44
  UserFilter: () => UserFilter,
45
- UserScopeV2: () => UserScopeV2,
46
45
  canUserCreateEvent: () => canUserCreateEvent,
47
46
  decodeScope: () => decodeScope,
48
47
  defineRoles: () => defineRoles,
@@ -55,8 +54,7 @@ __export(scopes_exports, {
55
54
  isCustomActionScope: () => isCustomActionScope,
56
55
  scopeUsesDeclaredOptions: () => scopeUsesDeclaredOptions,
57
56
  scopeUsesFullOptions: () => scopeUsesFullOptions,
58
- scopeUsesPrintCertifiedCopiesOptions: () => scopeUsesPrintCertifiedCopiesOptions,
59
- scopeUsesRoleOptions: () => scopeUsesRoleOptions
57
+ scopeUsesPrintCertifiedCopiesOptions: () => scopeUsesPrintCertifiedCopiesOptions
60
58
  });
61
59
  module.exports = __toCommonJS(scopes_exports);
62
60
  var z4 = __toESM(require("zod/v4"));
@@ -141,10 +139,6 @@ var scopeByEvent = z3.preprocess(
141
139
  (val) => val === void 0 ? void 0 : [val].flat(),
142
140
  z3.array(z3.string()).optional()
143
141
  ).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");
148
142
  var scopeOptionsPlaceEvent = z3.object({
149
143
  event: scopeByEvent,
150
144
  placeOfEvent: JurisdictionFilter.optional()
@@ -168,9 +162,6 @@ var CustomActionScopeOptions = AllRecordScopeOptions.extend({
168
162
  var AccessLevelOptions = z3.object({
169
163
  accessLevel: JurisdictionFilter.optional()
170
164
  });
171
- var AllUserScopeOptions = AccessLevelOptions.extend({
172
- role: userRole.optional()
173
- });
174
165
  var WorkqueueOrDashboardOptions = z3.object({
175
166
  ids: z3.preprocess(
176
167
  (val) => val === void 0 ? void 0 : [val].flat(),
@@ -180,7 +171,6 @@ var WorkqueueOrDashboardOptions = z3.object({
180
171
  var AllScopeOptions = z3.object({
181
172
  ...AllRecordScopeOptions.shape,
182
173
  ...AccessLevelOptions.shape,
183
- ...AllUserScopeOptions.shape,
184
174
  ...WorkqueueOrDashboardOptions.shape
185
175
  });
186
176
  var ScopeOptionKey = AllScopeOptions.keyof();
@@ -253,31 +243,6 @@ var RecordScopeV2 = z3.discriminatedUnion("type", [
253
243
  ]).describe(
254
244
  "Scopes used to check user's permission to perform actions on a record."
255
245
  );
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
- }
281
246
  function scopeUsesDeclaredOptions(scope) {
282
247
  return !ScopesWithPlaceEventOptions.options.some((opt) => opt === scope.type);
283
248
  }
@@ -310,14 +275,16 @@ var ResolvedRecordScopeV2 = z3.discriminatedUnion("type", [
310
275
  }).optional()
311
276
  })
312
277
  ]).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
+ ]);
313
284
  var Scope2 = z3.discriminatedUnion("type", [
314
285
  z3.object({ type: PlainScopeType }),
315
286
  ...RecordScopeV2.options,
316
- ...UserScopeV2.options,
317
- z3.object({
318
- type: z3.literal("organisation.read-locations"),
319
- options: AccessLevelOptions.optional()
320
- }),
287
+ z3.object({ type: SystemScopeType, options: AccessLevelOptions.optional() }),
321
288
  z3.object({
322
289
  type: z3.literal("workqueue"),
323
290
  options: WorkqueueOrDashboardOptions
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opencrvs/toolkit",
3
- "version": "2.0.0-rc.e12607f",
3
+ "version": "2.0.0-rc.e1f588f",
4
4
  "description": "OpenCRVS toolkit for building country configurations",
5
5
  "license": "MPL-2.0",
6
6
  "bin": {