@opencrvs/toolkit 2.0.0-rc.c2c75ca → 2.0.0-rc.c618db4
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.
- package/dist/application-config/index.js +39 -11
- package/dist/cli.js +35 -7
- package/dist/commons/api/router.d.ts +54 -52
- package/dist/commons/application-config/index.d.ts +16 -4
- package/dist/commons/conditionals/conditionals.d.ts +3 -3
- package/dist/commons/events/FieldConfig.d.ts +5 -0
- package/dist/commons/events/locations.d.ts +38 -1
- package/dist/commons/events/mocks.test.utils.d.ts +19 -0
- package/dist/commons/events/scopes.d.ts +24 -1
- package/dist/conditionals/index.js +35 -7
- package/dist/events/index.js +128 -7
- package/dist/migrations/v2.0/index.js +35 -7
- package/dist/notification/index.js +35 -7
- package/dist/scopes/index.d.ts +82 -10
- package/dist/scopes/index.js +41 -8
- package/opencrvs-toolkit-2.0.0-rc.c618db4.tgz +0 -0
- package/package.json +1 -1
- package/opencrvs-toolkit-2.0.0-rc.c2c75ca.tgz +0 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { AdministrativeArea, Location } from './locations';
|
|
2
|
+
export declare const V2_DEFAULT_MOCK_ADMINISTRATIVE_AREAS: AdministrativeArea[];
|
|
3
|
+
export declare const V2_DEFAULT_MOCK_LOCATIONS: Location[];
|
|
4
|
+
export declare const V2_DEFAULT_MOCK_LOCATIONS_MAP: Map<string & import("zod").$brand<"UUID">, {
|
|
5
|
+
id: string & import("zod").$brand<"UUID">;
|
|
6
|
+
name: string;
|
|
7
|
+
administrativeAreaId: (string & import("zod").$brand<"UUID">) | null;
|
|
8
|
+
validUntil: string | null;
|
|
9
|
+
locationType: string | null;
|
|
10
|
+
externalId?: string | null | undefined;
|
|
11
|
+
}>;
|
|
12
|
+
export declare const V2_DEFAULT_MOCK_ADMINISTRATIVE_AREAS_MAP: Map<string & import("zod").$brand<"UUID">, {
|
|
13
|
+
id: string & import("zod").$brand<"UUID">;
|
|
14
|
+
name: string;
|
|
15
|
+
parentId: (string & import("zod").$brand<"UUID">) | null;
|
|
16
|
+
validUntil: string | null;
|
|
17
|
+
externalId?: string | null | undefined;
|
|
18
|
+
}>;
|
|
19
|
+
//# sourceMappingURL=mocks.test.utils.d.ts.map
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { DisplayableAction } from './ActionType';
|
|
2
|
-
import { EncodedScope } from '../scopes';
|
|
2
|
+
import { EncodedScope, UserScopeV2 } from '../scopes';
|
|
3
3
|
import { EventIndexWithAdministrativeHierarchy } from './locations';
|
|
4
4
|
import { UserContext } from '../users/User';
|
|
5
5
|
import { EventIndex } from './EventIndex';
|
|
6
|
+
import { UUID } from 'src/uuid';
|
|
6
7
|
export declare const ACTION_SCOPE_MAP: {
|
|
7
8
|
READ: "record.read"[];
|
|
8
9
|
CREATE: "record.create"[];
|
|
@@ -53,4 +54,26 @@ export declare function isActionInScope({ scopes, action, event, currentUser }:
|
|
|
53
54
|
event: EventIndexWithAdministrativeHierarchy;
|
|
54
55
|
currentUser: UserContext;
|
|
55
56
|
}): boolean;
|
|
57
|
+
/**
|
|
58
|
+
*
|
|
59
|
+
*
|
|
60
|
+
* @param allRoles - All possible roles in the system
|
|
61
|
+
* @param userLocation - The location and role information of the user whose role options are being determined
|
|
62
|
+
* @param acceptedScopes - The scopes of the user requesting the role update, used to determine which roles they can assign.
|
|
63
|
+
* @param userRequesting - The user context of the user requesting the role update, used to check location-based access to the target user's location.
|
|
64
|
+
*
|
|
65
|
+
* @returns An array of roles that the requesting user is allowed to assign to the target user based on their scopes and location
|
|
66
|
+
*
|
|
67
|
+
* 1) Used to determine which roles should be available in the dropdown when a user is editing another user's role in the user management interface.
|
|
68
|
+
* 2) Used to check if payload includes valid role.
|
|
69
|
+
*/
|
|
70
|
+
export declare function getAvailableRolesForUserUpdatePayload({ allRoles, userLocation, acceptedScopes, userRequesting }: {
|
|
71
|
+
allRoles: string[];
|
|
72
|
+
userRequesting: UserContext;
|
|
73
|
+
acceptedScopes: UserScopeV2[];
|
|
74
|
+
userLocation: {
|
|
75
|
+
administrativeHierarchy: UUID[];
|
|
76
|
+
primaryOfficeId: UUID;
|
|
77
|
+
};
|
|
78
|
+
}): string[];
|
|
56
79
|
//# sourceMappingURL=scopes.d.ts.map
|
|
@@ -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
|
-
|
|
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
|
package/dist/events/index.js
CHANGED
|
@@ -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,
|
|
@@ -300,12 +302,14 @@ __export(events_exports, {
|
|
|
300
302
|
getActionConfig: () => getActionConfig,
|
|
301
303
|
getActionReview: () => getActionReview,
|
|
302
304
|
getActionReviewFields: () => getActionReviewFields,
|
|
305
|
+
getAdministrativeAreaHierarchy: () => getAdministrativeAreaHierarchy,
|
|
303
306
|
getAllUniqueFields: () => getAllUniqueFields,
|
|
304
307
|
getAnnotationFromDrafts: () => getAnnotationFromDrafts,
|
|
305
308
|
getAssignedUserFromActions: () => getAssignedUserFromActions,
|
|
306
309
|
getAssignedUserSignatureFromActions: () => getAssignedUserSignatureFromActions,
|
|
307
310
|
getAssignmentStatus: () => getAssignmentStatus,
|
|
308
311
|
getAvailableActionsForEvent: () => getAvailableActionsForEvent,
|
|
312
|
+
getAvailableRolesForUserUpdatePayload: () => getAvailableRolesForUserUpdatePayload,
|
|
309
313
|
getCompleteActionAnnotation: () => getCompleteActionAnnotation,
|
|
310
314
|
getCompleteActionDeclaration: () => getCompleteActionDeclaration,
|
|
311
315
|
getCurrentEventState: () => getCurrentEventState,
|
|
@@ -316,6 +320,7 @@ __export(events_exports, {
|
|
|
316
320
|
getDeclarationPages: () => getDeclarationPages,
|
|
317
321
|
getEventConfigById: () => getEventConfigById,
|
|
318
322
|
getFilePathsFromEvent: () => getFilePathsFromEvent,
|
|
323
|
+
getLocationHierarchy: () => getLocationHierarchy,
|
|
319
324
|
getMixedPath: () => getMixedPath,
|
|
320
325
|
getPendingAction: () => getPendingAction,
|
|
321
326
|
getPrintCertificatePages: () => getPrintCertificatePages,
|
|
@@ -489,6 +494,10 @@ var scopeByEvent = z2.preprocess(
|
|
|
489
494
|
(val) => val === void 0 ? void 0 : [val].flat(),
|
|
490
495
|
z2.array(z2.string()).optional()
|
|
491
496
|
).describe("Event type, e.g. birth, death");
|
|
497
|
+
var userRole = z2.preprocess(
|
|
498
|
+
(val) => val === void 0 ? void 0 : [val].flat(),
|
|
499
|
+
z2.array(z2.string()).optional()
|
|
500
|
+
).describe("User role, e.g. admin, field agent");
|
|
492
501
|
var scopeOptionsPlaceEvent = z2.object({
|
|
493
502
|
event: scopeByEvent,
|
|
494
503
|
placeOfEvent: JurisdictionFilter.optional()
|
|
@@ -512,6 +521,9 @@ var CustomActionScopeOptions = AllRecordScopeOptions.extend({
|
|
|
512
521
|
var AccessLevelOptions = z2.object({
|
|
513
522
|
accessLevel: JurisdictionFilter.optional()
|
|
514
523
|
});
|
|
524
|
+
var AllUserScopeOptions = AccessLevelOptions.extend({
|
|
525
|
+
role: userRole.optional()
|
|
526
|
+
});
|
|
515
527
|
var WorkqueueOrDashboardOptions = z2.object({
|
|
516
528
|
ids: z2.preprocess(
|
|
517
529
|
(val) => val === void 0 ? void 0 : [val].flat(),
|
|
@@ -521,6 +533,7 @@ var WorkqueueOrDashboardOptions = z2.object({
|
|
|
521
533
|
var AllScopeOptions = z2.object({
|
|
522
534
|
...AllRecordScopeOptions.shape,
|
|
523
535
|
...AccessLevelOptions.shape,
|
|
536
|
+
...AllUserScopeOptions.shape,
|
|
524
537
|
...WorkqueueOrDashboardOptions.shape
|
|
525
538
|
});
|
|
526
539
|
var ScopeOptionKey = AllScopeOptions.keyof();
|
|
@@ -593,6 +606,31 @@ var RecordScopeV2 = z2.discriminatedUnion("type", [
|
|
|
593
606
|
]).describe(
|
|
594
607
|
"Scopes used to check user's permission to perform actions on a record."
|
|
595
608
|
);
|
|
609
|
+
var SystemScopeType = z2.enum([
|
|
610
|
+
"organisation.read-locations",
|
|
611
|
+
"user.read",
|
|
612
|
+
"user.create",
|
|
613
|
+
"user.edit"
|
|
614
|
+
]);
|
|
615
|
+
var UserScopeType = SystemScopeType.extract([
|
|
616
|
+
"user.read",
|
|
617
|
+
"user.create",
|
|
618
|
+
"user.edit"
|
|
619
|
+
]);
|
|
620
|
+
var ScopesWithRoleOption = UserScopeType.extract(["user.edit", "user.create"]);
|
|
621
|
+
var UserScopeV2 = z2.discriminatedUnion("type", [
|
|
622
|
+
z2.object({
|
|
623
|
+
type: ScopesWithRoleOption,
|
|
624
|
+
options: AllUserScopeOptions.optional()
|
|
625
|
+
}),
|
|
626
|
+
z2.object({
|
|
627
|
+
type: UserScopeType.extract(["user.read"]),
|
|
628
|
+
options: AccessLevelOptions.optional()
|
|
629
|
+
})
|
|
630
|
+
]);
|
|
631
|
+
function scopeUsesRoleOptions(scope) {
|
|
632
|
+
return ScopesWithRoleOption?.options.some((opt) => opt === scope.type);
|
|
633
|
+
}
|
|
596
634
|
function scopeUsesDeclaredOptions(scope) {
|
|
597
635
|
return !ScopesWithPlaceEventOptions.options.some((opt) => opt === scope.type);
|
|
598
636
|
}
|
|
@@ -625,16 +663,14 @@ var ResolvedRecordScopeV2 = z2.discriminatedUnion("type", [
|
|
|
625
663
|
}).optional()
|
|
626
664
|
})
|
|
627
665
|
]).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
666
|
var Scope = z2.discriminatedUnion("type", [
|
|
635
667
|
z2.object({ type: PlainScopeType }),
|
|
636
668
|
...RecordScopeV2.options,
|
|
637
|
-
|
|
669
|
+
...UserScopeV2.options,
|
|
670
|
+
z2.object({
|
|
671
|
+
type: z2.literal("organisation.read-locations"),
|
|
672
|
+
options: AccessLevelOptions.optional()
|
|
673
|
+
}),
|
|
638
674
|
z2.object({
|
|
639
675
|
type: z2.literal("workqueue"),
|
|
640
676
|
options: WorkqueueOrDashboardOptions
|
|
@@ -9930,11 +9966,77 @@ function canAccessEventWithScope(event2, scope, user2, customActionType) {
|
|
|
9930
9966
|
}
|
|
9931
9967
|
return true;
|
|
9932
9968
|
}
|
|
9969
|
+
function canAccessUserWithScope({
|
|
9970
|
+
userToAccess,
|
|
9971
|
+
scope,
|
|
9972
|
+
user: user2
|
|
9973
|
+
}) {
|
|
9974
|
+
const opts = scope.options;
|
|
9975
|
+
const hasSameOffice = user2.primaryOfficeId === userToAccess.primaryOfficeId;
|
|
9976
|
+
if (opts?.accessLevel === JurisdictionFilter.enum.location && !hasSameOffice) {
|
|
9977
|
+
return false;
|
|
9978
|
+
}
|
|
9979
|
+
const hasAdministrativeAreaInHierarchy = userToAccess.administrativeHierarchy.some(
|
|
9980
|
+
(id) => user2.administrativeAreaId === id
|
|
9981
|
+
) || user2.administrativeAreaId === null;
|
|
9982
|
+
if (opts?.accessLevel === JurisdictionFilter.enum.administrativeArea && !hasAdministrativeAreaInHierarchy) {
|
|
9983
|
+
return false;
|
|
9984
|
+
}
|
|
9985
|
+
if (scopeUsesRoleOptions(scope)) {
|
|
9986
|
+
const { options } = scope;
|
|
9987
|
+
if (options?.role && !options.role.includes(userToAccess.role)) {
|
|
9988
|
+
return false;
|
|
9989
|
+
}
|
|
9990
|
+
}
|
|
9991
|
+
return true;
|
|
9992
|
+
}
|
|
9993
|
+
function canAccessOtherUserWithScopes({
|
|
9994
|
+
scopes,
|
|
9995
|
+
userToAccess,
|
|
9996
|
+
user: user2
|
|
9997
|
+
}) {
|
|
9998
|
+
return scopes.some(
|
|
9999
|
+
(scope) => canAccessUserWithScope({ userToAccess, scope, user: user2 })
|
|
10000
|
+
);
|
|
10001
|
+
}
|
|
9933
10002
|
function userCanAccessEventWithScopes(event2, scopes, user2, customActionType) {
|
|
9934
10003
|
return scopes.some(
|
|
9935
10004
|
(scope) => canAccessEventWithScope(event2, scope, user2, customActionType)
|
|
9936
10005
|
);
|
|
9937
10006
|
}
|
|
10007
|
+
function getAdministrativeAreaHierarchy(administrativeAreaId, administrativeAreas) {
|
|
10008
|
+
const collectedLocations = [];
|
|
10009
|
+
const parsedAdministrativeAreaId = administrativeAreaId && UUID.safeParse(administrativeAreaId).data;
|
|
10010
|
+
let current = parsedAdministrativeAreaId ? administrativeAreas.get(parsedAdministrativeAreaId) : null;
|
|
10011
|
+
while (current) {
|
|
10012
|
+
collectedLocations.push(current);
|
|
10013
|
+
if (!current.parentId) {
|
|
10014
|
+
break;
|
|
10015
|
+
}
|
|
10016
|
+
const parentId = current.parentId;
|
|
10017
|
+
current = administrativeAreas.get(parentId);
|
|
10018
|
+
}
|
|
10019
|
+
return collectedLocations;
|
|
10020
|
+
}
|
|
10021
|
+
function getLocationHierarchy(selectedId, context) {
|
|
10022
|
+
const { administrativeAreas, locations } = context;
|
|
10023
|
+
const loc = locations.get(selectedId);
|
|
10024
|
+
if (loc) {
|
|
10025
|
+
if (loc.administrativeAreaId) {
|
|
10026
|
+
const hierarchy2 = getAdministrativeAreaHierarchy(
|
|
10027
|
+
loc.administrativeAreaId,
|
|
10028
|
+
administrativeAreas
|
|
10029
|
+
);
|
|
10030
|
+
return [...hierarchy2.reverse().map((area) => area.id), loc.id];
|
|
10031
|
+
}
|
|
10032
|
+
return [loc.id];
|
|
10033
|
+
}
|
|
10034
|
+
const hierarchy = getAdministrativeAreaHierarchy(
|
|
10035
|
+
selectedId,
|
|
10036
|
+
administrativeAreas
|
|
10037
|
+
);
|
|
10038
|
+
return hierarchy.reverse().map((area) => area.id);
|
|
10039
|
+
}
|
|
9938
10040
|
|
|
9939
10041
|
// ../commons/src/events/scopes.ts
|
|
9940
10042
|
var ACTION_SCOPE_MAP = {
|
|
@@ -10009,6 +10111,25 @@ function isActionInScope({
|
|
|
10009
10111
|
);
|
|
10010
10112
|
return canAccess;
|
|
10011
10113
|
}
|
|
10114
|
+
function getAvailableRolesForUserUpdatePayload({
|
|
10115
|
+
allRoles,
|
|
10116
|
+
userLocation,
|
|
10117
|
+
acceptedScopes,
|
|
10118
|
+
userRequesting
|
|
10119
|
+
}) {
|
|
10120
|
+
const availableRoles = allRoles.filter((role) => {
|
|
10121
|
+
const canAccess = canAccessOtherUserWithScopes({
|
|
10122
|
+
userToAccess: {
|
|
10123
|
+
...userLocation,
|
|
10124
|
+
role
|
|
10125
|
+
},
|
|
10126
|
+
user: userRequesting,
|
|
10127
|
+
scopes: acceptedScopes
|
|
10128
|
+
});
|
|
10129
|
+
return canAccess;
|
|
10130
|
+
});
|
|
10131
|
+
return availableRoles;
|
|
10132
|
+
}
|
|
10012
10133
|
|
|
10013
10134
|
// ../commons/src/events/serializers/user/deserializer.ts
|
|
10014
10135
|
function userDeserializer(serializedUserField, user2) {
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
package/dist/scopes/index.d.ts
CHANGED
|
@@ -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"
|
|
645
|
+
type: "organisation.read-locations";
|
|
574
646
|
options?: {
|
|
575
647
|
accessLevel?: "administrativeArea" | "location" | "all" | undefined;
|
|
576
648
|
} | undefined;
|