@opencrvs/toolkit 1.9.2-rc.e91fddd → 1.9.2-rc.f0b9560
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.
|
@@ -9,7 +9,7 @@ export declare const InherentFlags: {
|
|
|
9
9
|
* This flag is set by the Edit-action and removed after the declaration or registration.
|
|
10
10
|
* A record should never stay with the EDIT_IN_PROGRESS flag, since it should always be declared or registered right after.
|
|
11
11
|
*
|
|
12
|
-
* We only use this flag to determine that a DECLARE or REGISTER action is allowed next.
|
|
12
|
+
* We only use this flag to determine that a NOTIFY, DECLARE or REGISTER action is allowed next.
|
|
13
13
|
*/
|
|
14
14
|
readonly EDIT_IN_PROGRESS: "edit-in-progress";
|
|
15
15
|
};
|
|
@@ -29,7 +29,7 @@ export declare const Flag: z.ZodUnion<[z.ZodUnion<[z.ZodString, z.ZodEnum<{
|
|
|
29
29
|
* This flag is set by the Edit-action and removed after the declaration or registration.
|
|
30
30
|
* A record should never stay with the EDIT_IN_PROGRESS flag, since it should always be declared or registered right after.
|
|
31
31
|
*
|
|
32
|
-
* We only use this flag to determine that a DECLARE or REGISTER action is allowed next.
|
|
32
|
+
* We only use this flag to determine that a NOTIFY, DECLARE or REGISTER action is allowed next.
|
|
33
33
|
*/
|
|
34
34
|
readonly EDIT_IN_PROGRESS: "edit-in-progress";
|
|
35
35
|
}>]>, z.ZodString]>;
|
|
@@ -57,7 +57,7 @@ export declare const ActionFlagConfig: z.ZodObject<{
|
|
|
57
57
|
* This flag is set by the Edit-action and removed after the declaration or registration.
|
|
58
58
|
* A record should never stay with the EDIT_IN_PROGRESS flag, since it should always be declared or registered right after.
|
|
59
59
|
*
|
|
60
|
-
* We only use this flag to determine that a DECLARE or REGISTER action is allowed next.
|
|
60
|
+
* We only use this flag to determine that a NOTIFY, DECLARE or REGISTER action is allowed next.
|
|
61
61
|
*/
|
|
62
62
|
readonly EDIT_IN_PROGRESS: "edit-in-progress";
|
|
63
63
|
}>]>, z.ZodString]>;
|
|
@@ -37,7 +37,7 @@ export declare function configurableEventScopeAllowed(scopes: Scope[], allowedCo
|
|
|
37
37
|
* @param {string} eventType - The type of event for which the action is being checked.
|
|
38
38
|
* @returns {boolean} True if the action is in scope for the user, otherwise false.
|
|
39
39
|
*/
|
|
40
|
-
export declare function isActionInScope(scopes: Scope[], action: DisplayableAction, eventType: string): boolean;
|
|
40
|
+
export declare function isActionInScope(scopes: Scope[], action: DisplayableAction, eventType: string, customActionType?: string): boolean;
|
|
41
41
|
/**
|
|
42
42
|
* A shared utility to check if the user can read a record.
|
|
43
43
|
* This will be removed in 1.10 and implemented by scopes.
|
package/dist/events/index.js
CHANGED
|
@@ -1195,12 +1195,12 @@ function flattenAndMergeScopes(scopes2) {
|
|
|
1195
1195
|
}
|
|
1196
1196
|
return { type, options: mergedOptions };
|
|
1197
1197
|
}
|
|
1198
|
-
function
|
|
1198
|
+
function findScopes(scopes2, scopeType) {
|
|
1199
1199
|
const parsedScopes = scopes2.map(parseConfigurableScope);
|
|
1200
1200
|
const searchScopes = parsedScopes.filter((scope) => scope?.type === "search");
|
|
1201
1201
|
const otherScopes = parsedScopes.filter((scope) => scope?.type !== "search");
|
|
1202
1202
|
const mergedSearchScope = flattenAndMergeScopes(searchScopes);
|
|
1203
|
-
return [...otherScopes, mergedSearchScope].
|
|
1203
|
+
return [...otherScopes, mergedSearchScope].filter(
|
|
1204
1204
|
(scope) => scope?.type === scopeType
|
|
1205
1205
|
);
|
|
1206
1206
|
}
|
|
@@ -1587,7 +1587,7 @@ var InherentFlags = {
|
|
|
1587
1587
|
* This flag is set by the Edit-action and removed after the declaration or registration.
|
|
1588
1588
|
* A record should never stay with the EDIT_IN_PROGRESS flag, since it should always be declared or registered right after.
|
|
1589
1589
|
*
|
|
1590
|
-
* We only use this flag to determine that a DECLARE or REGISTER action is allowed next.
|
|
1590
|
+
* We only use this flag to determine that a NOTIFY, DECLARE or REGISTER action is allowed next.
|
|
1591
1591
|
*/
|
|
1592
1592
|
EDIT_IN_PROGRESS: "edit-in-progress"
|
|
1593
1593
|
};
|
|
@@ -8806,18 +8806,22 @@ function hasAnyOfScopes(a, b) {
|
|
|
8806
8806
|
return (0, import_lodash6.intersection)(a, b).length > 0;
|
|
8807
8807
|
}
|
|
8808
8808
|
function configurableEventScopeAllowed(scopes2, allowedConfigurableScopes, eventType, customActionType) {
|
|
8809
|
-
const parsedScopes = allowedConfigurableScopes.
|
|
8810
|
-
|
|
8811
|
-
|
|
8812
|
-
if (
|
|
8813
|
-
const
|
|
8814
|
-
|
|
8815
|
-
return false;
|
|
8816
|
-
}
|
|
8809
|
+
const parsedScopes = allowedConfigurableScopes.flatMap(
|
|
8810
|
+
(scope) => findScopes(scopes2, scope)
|
|
8811
|
+
);
|
|
8812
|
+
if (!customActionType) {
|
|
8813
|
+
const authorizedEvents2 = getAuthorizedEventsFromScopes(parsedScopes);
|
|
8814
|
+
return authorizedEvents2.includes(eventType);
|
|
8817
8815
|
}
|
|
8816
|
+
const scopesWithCorrectCustomActionType = parsedScopes.filter(
|
|
8817
|
+
({ options }) => "customActionType" in options && options.customActionType.includes(customActionType)
|
|
8818
|
+
);
|
|
8819
|
+
const authorizedEvents = getAuthorizedEventsFromScopes(
|
|
8820
|
+
scopesWithCorrectCustomActionType
|
|
8821
|
+
);
|
|
8818
8822
|
return authorizedEvents.includes(eventType);
|
|
8819
8823
|
}
|
|
8820
|
-
function isActionInScope(scopes2, action, eventType) {
|
|
8824
|
+
function isActionInScope(scopes2, action, eventType, customActionType) {
|
|
8821
8825
|
const allowedConfigurableScopes = ACTION_SCOPE_MAP[action];
|
|
8822
8826
|
if (allowedConfigurableScopes === null) {
|
|
8823
8827
|
return true;
|
|
@@ -8828,7 +8832,8 @@ function isActionInScope(scopes2, action, eventType) {
|
|
|
8828
8832
|
return configurableEventScopeAllowed(
|
|
8829
8833
|
scopes2,
|
|
8830
8834
|
allowedConfigurableScopes,
|
|
8831
|
-
eventType
|
|
8835
|
+
eventType,
|
|
8836
|
+
customActionType
|
|
8832
8837
|
);
|
|
8833
8838
|
}
|
|
8834
8839
|
function canUserReadEvent(event2, {
|
|
@@ -8961,6 +8966,9 @@ function filterActionsByFlags(actions, flags) {
|
|
|
8961
8966
|
return actions.filter((action) => ACTION_FILTERS[action]?.(flags) ?? true);
|
|
8962
8967
|
}
|
|
8963
8968
|
function getAvailableActionsWithoutFlagFilters(status2, flags) {
|
|
8969
|
+
if (flags.includes(InherentFlags.EDIT_IN_PROGRESS)) {
|
|
8970
|
+
return [ActionType.NOTIFY, ActionType.DECLARE, ActionType.REGISTER];
|
|
8971
|
+
}
|
|
8964
8972
|
switch (status2) {
|
|
8965
8973
|
case EventStatus.enum.CREATED: {
|
|
8966
8974
|
return AVAILABLE_ACTIONS_BY_EVENT_STATUS[status2];
|
|
@@ -8981,9 +8989,6 @@ function getAvailableActionsWithoutFlagFilters(status2, flags) {
|
|
|
8981
8989
|
flags.filter((flag2) => flag2 !== InherentFlags.REJECTED)
|
|
8982
8990
|
).filter((action) => action !== ActionType.DELETE).concat(ActionType.EDIT).concat(ActionType.ARCHIVE);
|
|
8983
8991
|
}
|
|
8984
|
-
if (flags.includes(InherentFlags.EDIT_IN_PROGRESS)) {
|
|
8985
|
-
return [ActionType.DECLARE, ActionType.REGISTER];
|
|
8986
|
-
}
|
|
8987
8992
|
return AVAILABLE_ACTIONS_BY_EVENT_STATUS[status2];
|
|
8988
8993
|
}
|
|
8989
8994
|
case EventStatus.enum.REGISTERED: {
|
|
@@ -1177,7 +1177,7 @@ var InherentFlags = {
|
|
|
1177
1177
|
* This flag is set by the Edit-action and removed after the declaration or registration.
|
|
1178
1178
|
* A record should never stay with the EDIT_IN_PROGRESS flag, since it should always be declared or registered right after.
|
|
1179
1179
|
*
|
|
1180
|
-
* We only use this flag to determine that a DECLARE or REGISTER action is allowed next.
|
|
1180
|
+
* We only use this flag to determine that a NOTIFY, DECLARE or REGISTER action is allowed next.
|
|
1181
1181
|
*/
|
|
1182
1182
|
EDIT_IN_PROGRESS: "edit-in-progress"
|
|
1183
1183
|
};
|
package/dist/scopes/index.d.ts
CHANGED
|
@@ -244,6 +244,45 @@ export declare function findScope<T extends ConfigurableScopeType>(scopes: strin
|
|
|
244
244
|
}> | Extract<FlattenedSearchScope, {
|
|
245
245
|
type: T;
|
|
246
246
|
}> | undefined;
|
|
247
|
+
export declare function findScopes<T extends ConfigurableScopeType>(scopes: string[], scopeType: T): (Extract<{
|
|
248
|
+
type: "user.create";
|
|
249
|
+
options: {
|
|
250
|
+
role: string[];
|
|
251
|
+
};
|
|
252
|
+
}, {
|
|
253
|
+
type: T;
|
|
254
|
+
}> | Extract<{
|
|
255
|
+
type: "user.edit";
|
|
256
|
+
options: {
|
|
257
|
+
role: string[];
|
|
258
|
+
};
|
|
259
|
+
}, {
|
|
260
|
+
type: T;
|
|
261
|
+
}> | Extract<{
|
|
262
|
+
type: "workqueue";
|
|
263
|
+
options: {
|
|
264
|
+
id: string[];
|
|
265
|
+
};
|
|
266
|
+
}, {
|
|
267
|
+
type: T;
|
|
268
|
+
}> | Extract<{
|
|
269
|
+
type: "record.unassign-others" | "record.register" | "record.read" | "record.create" | "record.declare" | "record.notify" | "record.declared.edit" | "record.declared.reject" | "record.declared.archive" | "record.declared.review-duplicates" | "record.registered.print-certified-copies" | "record.registered.request-correction" | "record.registered.correct";
|
|
270
|
+
options: {
|
|
271
|
+
event: string[];
|
|
272
|
+
};
|
|
273
|
+
}, {
|
|
274
|
+
type: T;
|
|
275
|
+
}> | Extract<{
|
|
276
|
+
type: "record.custom-action";
|
|
277
|
+
options: {
|
|
278
|
+
event: string[];
|
|
279
|
+
customActionType: string[];
|
|
280
|
+
};
|
|
281
|
+
}, {
|
|
282
|
+
type: T;
|
|
283
|
+
}> | Extract<FlattenedSearchScope, {
|
|
284
|
+
type: T;
|
|
285
|
+
}>)[];
|
|
247
286
|
/**
|
|
248
287
|
* Parses a configurable scope string into a ConfigurableRawScopes object.
|
|
249
288
|
* @param {string} scope - The scope string to parse
|
package/dist/scopes/index.js
CHANGED
|
@@ -38,6 +38,7 @@ __export(scopes_exports, {
|
|
|
38
38
|
SCOPES: () => SCOPES,
|
|
39
39
|
SearchScopes: () => SearchScopes,
|
|
40
40
|
findScope: () => findScope,
|
|
41
|
+
findScopes: () => findScopes,
|
|
41
42
|
getAuthorizedEventsFromScopes: () => getAuthorizedEventsFromScopes,
|
|
42
43
|
parseConfigurableScope: () => parseConfigurableScope,
|
|
43
44
|
parseLiteralScope: () => parseLiteralScope,
|
|
@@ -313,6 +314,15 @@ function findScope(scopes2, scopeType) {
|
|
|
313
314
|
(scope) => scope?.type === scopeType
|
|
314
315
|
);
|
|
315
316
|
}
|
|
317
|
+
function findScopes(scopes2, scopeType) {
|
|
318
|
+
const parsedScopes = scopes2.map(parseConfigurableScope);
|
|
319
|
+
const searchScopes = parsedScopes.filter((scope) => scope?.type === "search");
|
|
320
|
+
const otherScopes = parsedScopes.filter((scope) => scope?.type !== "search");
|
|
321
|
+
const mergedSearchScope = flattenAndMergeScopes(searchScopes);
|
|
322
|
+
return [...otherScopes, mergedSearchScope].filter(
|
|
323
|
+
(scope) => scope?.type === scopeType
|
|
324
|
+
);
|
|
325
|
+
}
|
|
316
326
|
function getScopeOptions(rawOptions) {
|
|
317
327
|
return rawOptions.split(",").reduce((acc, option) => {
|
|
318
328
|
const [key, value] = option.split("=");
|