@opencrvs/toolkit 2.0.0-rc.45e2fdc → 2.0.0-rc.487f96e
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 -59
- package/dist/commons/application-config/index.d.ts +16 -4
- package/dist/commons/conditionals/conditionals.d.ts +3 -3
- package/dist/commons/events/ActionInput.d.ts +0 -36
- package/dist/commons/events/Draft.d.ts +0 -1
- 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 +25 -1
- package/dist/conditionals/index.js +35 -7
- package/dist/events/index.js +128 -8
- package/dist/migrations/v2.0/index.js +35 -7
- package/dist/notification/index.js +35 -8
- package/dist/scopes/index.d.ts +82 -10
- package/dist/scopes/index.js +41 -8
- package/opencrvs-toolkit-2.0.0-rc.487f96e.tgz +0 -0
- package/package.json +1 -1
- package/opencrvs-toolkit-2.0.0-rc.45e2fdc.tgz +0 -0
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
|
|
@@ -5862,7 +5898,6 @@ var BaseActionInput = z38.object({
|
|
|
5862
5898
|
originalActionId: UUID.optional(),
|
|
5863
5899
|
// should not be part of base action.
|
|
5864
5900
|
keepAssignment: z38.boolean().optional(),
|
|
5865
|
-
waitFor: z38.boolean().optional(),
|
|
5866
5901
|
// For normal users, the createdAtLocation is resolved on the backend from the user's primaryOfficeId.
|
|
5867
5902
|
// @TODO: createdAtLocation should be limited to actions that system users can perform. For normal users, it should not be part of the base action.
|
|
5868
5903
|
createdAtLocation: UUID.nullish().describe(
|
|
@@ -9931,11 +9966,77 @@ function canAccessEventWithScope(event2, scope, user2, customActionType) {
|
|
|
9931
9966
|
}
|
|
9932
9967
|
return true;
|
|
9933
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
|
+
}
|
|
9934
10002
|
function userCanAccessEventWithScopes(event2, scopes, user2, customActionType) {
|
|
9935
10003
|
return scopes.some(
|
|
9936
10004
|
(scope) => canAccessEventWithScope(event2, scope, user2, customActionType)
|
|
9937
10005
|
);
|
|
9938
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
|
+
}
|
|
9939
10040
|
|
|
9940
10041
|
// ../commons/src/events/scopes.ts
|
|
9941
10042
|
var ACTION_SCOPE_MAP = {
|
|
@@ -10010,6 +10111,25 @@ function isActionInScope({
|
|
|
10010
10111
|
);
|
|
10011
10112
|
return canAccess;
|
|
10012
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
|
+
}
|
|
10013
10133
|
|
|
10014
10134
|
// ../commons/src/events/serializers/user/deserializer.ts
|
|
10015
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
|
|
@@ -4150,7 +4178,6 @@ var BaseActionInput = z38.object({
|
|
|
4150
4178
|
originalActionId: UUID.optional(),
|
|
4151
4179
|
// should not be part of base action.
|
|
4152
4180
|
keepAssignment: z38.boolean().optional(),
|
|
4153
|
-
waitFor: z38.boolean().optional(),
|
|
4154
4181
|
// For normal users, the createdAtLocation is resolved on the backend from the user's primaryOfficeId.
|
|
4155
4182
|
// @TODO: createdAtLocation should be limited to actions that system users can perform. For normal users, it should not be part of the base action.
|
|
4156
4183
|
createdAtLocation: UUID.nullish().describe(
|
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;
|
package/dist/scopes/index.js
CHANGED
|
@@ -42,6 +42,7 @@ __export(scopes_exports, {
|
|
|
42
42
|
ScopesWithFullOptions: () => ScopesWithFullOptions,
|
|
43
43
|
ScopesWithPlaceEventOptions: () => ScopesWithPlaceEventOptions,
|
|
44
44
|
UserFilter: () => UserFilter,
|
|
45
|
+
UserScopeV2: () => UserScopeV2,
|
|
45
46
|
canUserCreateEvent: () => canUserCreateEvent,
|
|
46
47
|
decodeScope: () => decodeScope,
|
|
47
48
|
defineRoles: () => defineRoles,
|
|
@@ -54,7 +55,8 @@ __export(scopes_exports, {
|
|
|
54
55
|
isCustomActionScope: () => isCustomActionScope,
|
|
55
56
|
scopeUsesDeclaredOptions: () => scopeUsesDeclaredOptions,
|
|
56
57
|
scopeUsesFullOptions: () => scopeUsesFullOptions,
|
|
57
|
-
scopeUsesPrintCertifiedCopiesOptions: () => scopeUsesPrintCertifiedCopiesOptions
|
|
58
|
+
scopeUsesPrintCertifiedCopiesOptions: () => scopeUsesPrintCertifiedCopiesOptions,
|
|
59
|
+
scopeUsesRoleOptions: () => scopeUsesRoleOptions
|
|
58
60
|
});
|
|
59
61
|
module.exports = __toCommonJS(scopes_exports);
|
|
60
62
|
var z4 = __toESM(require("zod/v4"));
|
|
@@ -139,6 +141,10 @@ var scopeByEvent = z3.preprocess(
|
|
|
139
141
|
(val) => val === void 0 ? void 0 : [val].flat(),
|
|
140
142
|
z3.array(z3.string()).optional()
|
|
141
143
|
).describe("Event type, e.g. birth, death");
|
|
144
|
+
var userRole = z3.preprocess(
|
|
145
|
+
(val) => val === void 0 ? void 0 : [val].flat(),
|
|
146
|
+
z3.array(z3.string()).optional()
|
|
147
|
+
).describe("User role, e.g. admin, field agent");
|
|
142
148
|
var scopeOptionsPlaceEvent = z3.object({
|
|
143
149
|
event: scopeByEvent,
|
|
144
150
|
placeOfEvent: JurisdictionFilter.optional()
|
|
@@ -162,6 +168,9 @@ var CustomActionScopeOptions = AllRecordScopeOptions.extend({
|
|
|
162
168
|
var AccessLevelOptions = z3.object({
|
|
163
169
|
accessLevel: JurisdictionFilter.optional()
|
|
164
170
|
});
|
|
171
|
+
var AllUserScopeOptions = AccessLevelOptions.extend({
|
|
172
|
+
role: userRole.optional()
|
|
173
|
+
});
|
|
165
174
|
var WorkqueueOrDashboardOptions = z3.object({
|
|
166
175
|
ids: z3.preprocess(
|
|
167
176
|
(val) => val === void 0 ? void 0 : [val].flat(),
|
|
@@ -171,6 +180,7 @@ var WorkqueueOrDashboardOptions = z3.object({
|
|
|
171
180
|
var AllScopeOptions = z3.object({
|
|
172
181
|
...AllRecordScopeOptions.shape,
|
|
173
182
|
...AccessLevelOptions.shape,
|
|
183
|
+
...AllUserScopeOptions.shape,
|
|
174
184
|
...WorkqueueOrDashboardOptions.shape
|
|
175
185
|
});
|
|
176
186
|
var ScopeOptionKey = AllScopeOptions.keyof();
|
|
@@ -243,6 +253,31 @@ var RecordScopeV2 = z3.discriminatedUnion("type", [
|
|
|
243
253
|
]).describe(
|
|
244
254
|
"Scopes used to check user's permission to perform actions on a record."
|
|
245
255
|
);
|
|
256
|
+
var SystemScopeType = z3.enum([
|
|
257
|
+
"organisation.read-locations",
|
|
258
|
+
"user.read",
|
|
259
|
+
"user.create",
|
|
260
|
+
"user.edit"
|
|
261
|
+
]);
|
|
262
|
+
var UserScopeType = SystemScopeType.extract([
|
|
263
|
+
"user.read",
|
|
264
|
+
"user.create",
|
|
265
|
+
"user.edit"
|
|
266
|
+
]);
|
|
267
|
+
var ScopesWithRoleOption = UserScopeType.extract(["user.edit", "user.create"]);
|
|
268
|
+
var UserScopeV2 = z3.discriminatedUnion("type", [
|
|
269
|
+
z3.object({
|
|
270
|
+
type: ScopesWithRoleOption,
|
|
271
|
+
options: AllUserScopeOptions.optional()
|
|
272
|
+
}),
|
|
273
|
+
z3.object({
|
|
274
|
+
type: UserScopeType.extract(["user.read"]),
|
|
275
|
+
options: AccessLevelOptions.optional()
|
|
276
|
+
})
|
|
277
|
+
]);
|
|
278
|
+
function scopeUsesRoleOptions(scope) {
|
|
279
|
+
return ScopesWithRoleOption?.options.some((opt) => opt === scope.type);
|
|
280
|
+
}
|
|
246
281
|
function scopeUsesDeclaredOptions(scope) {
|
|
247
282
|
return !ScopesWithPlaceEventOptions.options.some((opt) => opt === scope.type);
|
|
248
283
|
}
|
|
@@ -275,16 +310,14 @@ var ResolvedRecordScopeV2 = z3.discriminatedUnion("type", [
|
|
|
275
310
|
}).optional()
|
|
276
311
|
})
|
|
277
312
|
]).describe("Resolved scope with location/user IDs instead of filters.");
|
|
278
|
-
var SystemScopeType = z3.enum([
|
|
279
|
-
"organisation.read-locations",
|
|
280
|
-
"user.read",
|
|
281
|
-
"user.create",
|
|
282
|
-
"user.edit"
|
|
283
|
-
]);
|
|
284
313
|
var Scope2 = z3.discriminatedUnion("type", [
|
|
285
314
|
z3.object({ type: PlainScopeType }),
|
|
286
315
|
...RecordScopeV2.options,
|
|
287
|
-
|
|
316
|
+
...UserScopeV2.options,
|
|
317
|
+
z3.object({
|
|
318
|
+
type: z3.literal("organisation.read-locations"),
|
|
319
|
+
options: AccessLevelOptions.optional()
|
|
320
|
+
}),
|
|
288
321
|
z3.object({
|
|
289
322
|
type: z3.literal("workqueue"),
|
|
290
323
|
options: WorkqueueOrDashboardOptions
|
|
Binary file
|
package/package.json
CHANGED
|
Binary file
|