@opencrvs/toolkit 2.0.0-rc.abfa56e → 2.0.0-rc.ac001d6
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.
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { Action, RequestedCorrectionAction } from '../ActionDocument';
|
|
1
2
|
import { Flag, CustomFlag } from '../Flag';
|
|
2
3
|
import { EventConfig } from '../EventConfig';
|
|
3
4
|
import { EventDocument } from '../EventDocument';
|
|
5
|
+
export declare function findPendingCorrectionAction(writeActions: Action[]): RequestedCorrectionAction | undefined;
|
|
4
6
|
/**
|
|
5
7
|
* This function resolves custom flags for an event based on its actions.
|
|
6
8
|
* Flags are not stored to the event state or any database directly, instead they are always computed/evaluated from the event actions.
|
|
@@ -18,5 +20,18 @@ import { EventDocument } from '../EventDocument';
|
|
|
18
20
|
* // Returns: ['flag-1', 'flag-3']
|
|
19
21
|
*/
|
|
20
22
|
export declare function resolveEventCustomFlags(event: EventDocument, eventConfiguration: EventConfig): CustomFlag[];
|
|
23
|
+
/**
|
|
24
|
+
* Computes all flags (inherent, action status, and custom) that should be attached to the given event,
|
|
25
|
+
* based on its actions and event-specific configuration.
|
|
26
|
+
*
|
|
27
|
+
* Flags are determined by combining:
|
|
28
|
+
* - Action status flags (format 'ActionType:ActionStatus')
|
|
29
|
+
* - Inherent flags (e.g. incomplete, rejected, correction requested, potential duplicate, edit in progress)
|
|
30
|
+
* - Event type-specific custom flags defined in the event configuration
|
|
31
|
+
*
|
|
32
|
+
* @param event - The EventDocument containing the action history and payload
|
|
33
|
+
* @param config - The EventConfig providing rules for custom flag evaluation
|
|
34
|
+
* @returns An array of flags currently relevant/applicable to the event
|
|
35
|
+
*/
|
|
21
36
|
export declare function getEventFlags(event: EventDocument, config: EventConfig): Flag[];
|
|
22
37
|
//# sourceMappingURL=flags.d.ts.map
|
package/dist/events/index.js
CHANGED
|
@@ -6388,26 +6388,43 @@ var import_date_fns3 = require("date-fns");
|
|
|
6388
6388
|
function isEditInProgress(actions) {
|
|
6389
6389
|
return actions.at(-1)?.type === ActionType.EDIT;
|
|
6390
6390
|
}
|
|
6391
|
+
function findPendingCorrectionAction(writeActions2) {
|
|
6392
|
+
let correctionRequestAction;
|
|
6393
|
+
for (let i = writeActions2.length - 1; i >= 0; i--) {
|
|
6394
|
+
const action = writeActions2[i];
|
|
6395
|
+
if (action.type === ActionType.APPROVE_CORRECTION || action.type === ActionType.REJECT_CORRECTION) {
|
|
6396
|
+
break;
|
|
6397
|
+
}
|
|
6398
|
+
if (action.type === ActionType.REQUEST_CORRECTION) {
|
|
6399
|
+
correctionRequestAction = action;
|
|
6400
|
+
break;
|
|
6401
|
+
}
|
|
6402
|
+
}
|
|
6403
|
+
return correctionRequestAction;
|
|
6404
|
+
}
|
|
6391
6405
|
function isCorrectionRequested(actions) {
|
|
6406
|
+
return findPendingCorrectionAction(actions) !== void 0;
|
|
6407
|
+
}
|
|
6408
|
+
function isDeclarationIncomplete(actions) {
|
|
6409
|
+
return getStatusFromActions(actions) === EventStatus.enum.NOTIFIED;
|
|
6410
|
+
}
|
|
6411
|
+
function isRejected(actions) {
|
|
6412
|
+
const resettingActionTypes = [
|
|
6413
|
+
ActionType.NOTIFY,
|
|
6414
|
+
ActionType.DECLARE,
|
|
6415
|
+
ActionType.EDIT,
|
|
6416
|
+
ActionType.REGISTER
|
|
6417
|
+
];
|
|
6392
6418
|
return actions.reduce((prev, { type }) => {
|
|
6393
|
-
if (type === ActionType.
|
|
6419
|
+
if (type === ActionType.REJECT) {
|
|
6394
6420
|
return true;
|
|
6395
6421
|
}
|
|
6396
|
-
if (type
|
|
6397
|
-
return false;
|
|
6398
|
-
}
|
|
6399
|
-
if (type === ActionType.REJECT_CORRECTION) {
|
|
6422
|
+
if (resettingActionTypes.includes(type)) {
|
|
6400
6423
|
return false;
|
|
6401
6424
|
}
|
|
6402
6425
|
return prev;
|
|
6403
6426
|
}, false);
|
|
6404
6427
|
}
|
|
6405
|
-
function isDeclarationIncomplete(actions) {
|
|
6406
|
-
return getStatusFromActions(actions) === EventStatus.enum.NOTIFIED;
|
|
6407
|
-
}
|
|
6408
|
-
function isRejected(actions) {
|
|
6409
|
-
return actions.at(-1)?.type === ActionType.REJECT;
|
|
6410
|
-
}
|
|
6411
6428
|
function isPotentialDuplicate(actions) {
|
|
6412
6429
|
return actions.reduce((prev, { type }) => {
|
|
6413
6430
|
if (type === ActionType.DUPLICATE_DETECTED) {
|
|
@@ -6470,8 +6487,7 @@ function resolveEventCustomFlags(event2, eventConfiguration) {
|
|
|
6470
6487
|
return (0, import_lodash3.uniq)(flags);
|
|
6471
6488
|
}, []);
|
|
6472
6489
|
}
|
|
6473
|
-
function
|
|
6474
|
-
const sortedActions = event2.actions.filter(({ type }) => !isMetaAction(type)).sort((a, b) => a.createdAt.localeCompare(b.createdAt));
|
|
6490
|
+
function getActionStatusFlags(sortedActions) {
|
|
6475
6491
|
const actionStatus = sortedActions.reduce(
|
|
6476
6492
|
(actionStatuses, { type, status: status2 }) => ({
|
|
6477
6493
|
...actionStatuses,
|
|
@@ -6479,26 +6495,40 @@ function getEventFlags(event2, config) {
|
|
|
6479
6495
|
}),
|
|
6480
6496
|
{}
|
|
6481
6497
|
);
|
|
6482
|
-
|
|
6498
|
+
return Object.entries(actionStatus).filter(([, status2]) => status2 !== ActionStatus.Accepted).map(([type, status2]) => {
|
|
6483
6499
|
const flag2 = joinValues([type, status2], ":").toLowerCase();
|
|
6484
6500
|
return flag2;
|
|
6485
6501
|
});
|
|
6486
|
-
|
|
6487
|
-
|
|
6502
|
+
}
|
|
6503
|
+
function getInherentFlags(sortedActions) {
|
|
6504
|
+
const acceptedActions = sortedActions.filter(
|
|
6505
|
+
({ status: status2 }) => status2 === ActionStatus.Accepted
|
|
6506
|
+
);
|
|
6507
|
+
const inherentFlags = [];
|
|
6508
|
+
if (isCorrectionRequested(acceptedActions)) {
|
|
6509
|
+
inherentFlags.push(InherentFlags.CORRECTION_REQUESTED);
|
|
6488
6510
|
}
|
|
6489
|
-
if (isDeclarationIncomplete(
|
|
6490
|
-
|
|
6511
|
+
if (isDeclarationIncomplete(acceptedActions)) {
|
|
6512
|
+
inherentFlags.push(InherentFlags.INCOMPLETE);
|
|
6491
6513
|
}
|
|
6492
|
-
if (isRejected(
|
|
6493
|
-
|
|
6514
|
+
if (isRejected(acceptedActions)) {
|
|
6515
|
+
inherentFlags.push(InherentFlags.REJECTED);
|
|
6494
6516
|
}
|
|
6495
|
-
if (isPotentialDuplicate(
|
|
6496
|
-
|
|
6517
|
+
if (isPotentialDuplicate(acceptedActions)) {
|
|
6518
|
+
inherentFlags.push(InherentFlags.POTENTIAL_DUPLICATE);
|
|
6497
6519
|
}
|
|
6498
|
-
if (isEditInProgress(
|
|
6499
|
-
|
|
6520
|
+
if (isEditInProgress(acceptedActions)) {
|
|
6521
|
+
inherentFlags.push(InherentFlags.EDIT_IN_PROGRESS);
|
|
6500
6522
|
}
|
|
6501
|
-
return
|
|
6523
|
+
return inherentFlags;
|
|
6524
|
+
}
|
|
6525
|
+
function getEventFlags(event2, config) {
|
|
6526
|
+
const sortedActions = event2.actions.filter(({ type }) => !isMetaAction(type)).sort((a, b) => a.createdAt.localeCompare(b.createdAt));
|
|
6527
|
+
return [
|
|
6528
|
+
...getActionStatusFlags(sortedActions),
|
|
6529
|
+
...getInherentFlags(sortedActions),
|
|
6530
|
+
...resolveEventCustomFlags(event2, config)
|
|
6531
|
+
];
|
|
6502
6532
|
}
|
|
6503
6533
|
|
|
6504
6534
|
// ../commons/src/events/state/index.ts
|
|
Binary file
|
package/package.json
CHANGED
|
Binary file
|