@opencrvs/toolkit 2.0.0-rc.d0cb49b → 2.0.0-rc.d0ccb3c
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/commons/conditionals/conditionals.d.ts +6 -0
- package/dist/commons/events/state/flags.d.ts +15 -0
- package/dist/conditionals/index.js +4 -0
- package/dist/events/index.js +59 -25
- package/opencrvs-toolkit-2.0.0-rc.d0ccb3c.tgz +0 -0
- package/package.json +2 -2
- package/opencrvs-toolkit-2.0.0-rc.d0cb49b.tgz +0 -0
|
@@ -67,6 +67,12 @@ export declare function not(condition: AjvJSONSchema): JSONSchema;
|
|
|
67
67
|
* @returns {JSONSchema} An schema object that always evaluates to false.
|
|
68
68
|
*/
|
|
69
69
|
export declare function never(): JSONSchema;
|
|
70
|
+
/**
|
|
71
|
+
* Returns an JSON Schema object, which is treated as always valid.
|
|
72
|
+
*
|
|
73
|
+
* @returns {JSONSchema} An schema object that always evaluates to true.
|
|
74
|
+
*/
|
|
75
|
+
export declare function always(): JSONSchema;
|
|
70
76
|
/**
|
|
71
77
|
* Generate conditional rules for current date
|
|
72
78
|
*/
|
|
@@ -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
|
|
@@ -30,6 +30,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/conditionals/index.ts
|
|
31
31
|
var conditionals_exports = {};
|
|
32
32
|
__export(conditionals_exports, {
|
|
33
|
+
always: () => always,
|
|
33
34
|
alwaysTrue: () => alwaysTrue,
|
|
34
35
|
and: () => and,
|
|
35
36
|
createFieldConditionals: () => createFieldConditionals,
|
|
@@ -454,6 +455,9 @@ function not(condition) {
|
|
|
454
455
|
function never() {
|
|
455
456
|
return not(alwaysTrue());
|
|
456
457
|
}
|
|
458
|
+
function always() {
|
|
459
|
+
return defineConditional(alwaysTrue());
|
|
460
|
+
}
|
|
457
461
|
function jsonFieldPath(field) {
|
|
458
462
|
return [field.$$field, ...field.$$subfield].join("/");
|
|
459
463
|
}
|
package/dist/events/index.js
CHANGED
|
@@ -238,6 +238,7 @@ __export(events_exports, {
|
|
|
238
238
|
ageToDate: () => ageToDate,
|
|
239
239
|
aggregateActionAnnotations: () => aggregateActionAnnotations,
|
|
240
240
|
aggregateActionDeclarations: () => aggregateActionDeclarations,
|
|
241
|
+
always: () => always,
|
|
241
242
|
alwaysTrue: () => alwaysTrue,
|
|
242
243
|
and: () => and,
|
|
243
244
|
annotationActions: () => annotationActions,
|
|
@@ -4854,6 +4855,9 @@ function not(condition) {
|
|
|
4854
4855
|
function never2() {
|
|
4855
4856
|
return not(alwaysTrue());
|
|
4856
4857
|
}
|
|
4858
|
+
function always() {
|
|
4859
|
+
return defineConditional(alwaysTrue());
|
|
4860
|
+
}
|
|
4857
4861
|
function jsonFieldPath(field3) {
|
|
4858
4862
|
return [field3.$$field, ...field3.$$subfield].join("/");
|
|
4859
4863
|
}
|
|
@@ -6384,26 +6388,43 @@ var import_date_fns3 = require("date-fns");
|
|
|
6384
6388
|
function isEditInProgress(actions) {
|
|
6385
6389
|
return actions.at(-1)?.type === ActionType.EDIT;
|
|
6386
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
|
+
}
|
|
6387
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
|
+
];
|
|
6388
6418
|
return actions.reduce((prev, { type }) => {
|
|
6389
|
-
if (type === ActionType.
|
|
6419
|
+
if (type === ActionType.REJECT) {
|
|
6390
6420
|
return true;
|
|
6391
6421
|
}
|
|
6392
|
-
if (type
|
|
6393
|
-
return false;
|
|
6394
|
-
}
|
|
6395
|
-
if (type === ActionType.REJECT_CORRECTION) {
|
|
6422
|
+
if (resettingActionTypes.includes(type)) {
|
|
6396
6423
|
return false;
|
|
6397
6424
|
}
|
|
6398
6425
|
return prev;
|
|
6399
6426
|
}, false);
|
|
6400
6427
|
}
|
|
6401
|
-
function isDeclarationIncomplete(actions) {
|
|
6402
|
-
return getStatusFromActions(actions) === EventStatus.enum.NOTIFIED;
|
|
6403
|
-
}
|
|
6404
|
-
function isRejected(actions) {
|
|
6405
|
-
return actions.at(-1)?.type === ActionType.REJECT;
|
|
6406
|
-
}
|
|
6407
6428
|
function isPotentialDuplicate(actions) {
|
|
6408
6429
|
return actions.reduce((prev, { type }) => {
|
|
6409
6430
|
if (type === ActionType.DUPLICATE_DETECTED) {
|
|
@@ -6466,8 +6487,7 @@ function resolveEventCustomFlags(event2, eventConfiguration) {
|
|
|
6466
6487
|
return (0, import_lodash3.uniq)(flags);
|
|
6467
6488
|
}, []);
|
|
6468
6489
|
}
|
|
6469
|
-
function
|
|
6470
|
-
const sortedActions = event2.actions.filter(({ type }) => !isMetaAction(type)).sort((a, b) => a.createdAt.localeCompare(b.createdAt));
|
|
6490
|
+
function getActionStatusFlags(sortedActions) {
|
|
6471
6491
|
const actionStatus = sortedActions.reduce(
|
|
6472
6492
|
(actionStatuses, { type, status: status2 }) => ({
|
|
6473
6493
|
...actionStatuses,
|
|
@@ -6475,26 +6495,40 @@ function getEventFlags(event2, config) {
|
|
|
6475
6495
|
}),
|
|
6476
6496
|
{}
|
|
6477
6497
|
);
|
|
6478
|
-
|
|
6498
|
+
return Object.entries(actionStatus).filter(([, status2]) => status2 !== ActionStatus.Accepted).map(([type, status2]) => {
|
|
6479
6499
|
const flag2 = joinValues([type, status2], ":").toLowerCase();
|
|
6480
6500
|
return flag2;
|
|
6481
6501
|
});
|
|
6482
|
-
|
|
6483
|
-
|
|
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);
|
|
6484
6510
|
}
|
|
6485
|
-
if (isDeclarationIncomplete(
|
|
6486
|
-
|
|
6511
|
+
if (isDeclarationIncomplete(acceptedActions)) {
|
|
6512
|
+
inherentFlags.push(InherentFlags.INCOMPLETE);
|
|
6487
6513
|
}
|
|
6488
|
-
if (isRejected(
|
|
6489
|
-
|
|
6514
|
+
if (isRejected(acceptedActions)) {
|
|
6515
|
+
inherentFlags.push(InherentFlags.REJECTED);
|
|
6490
6516
|
}
|
|
6491
|
-
if (isPotentialDuplicate(
|
|
6492
|
-
|
|
6517
|
+
if (isPotentialDuplicate(acceptedActions)) {
|
|
6518
|
+
inherentFlags.push(InherentFlags.POTENTIAL_DUPLICATE);
|
|
6493
6519
|
}
|
|
6494
|
-
if (isEditInProgress(
|
|
6495
|
-
|
|
6520
|
+
if (isEditInProgress(acceptedActions)) {
|
|
6521
|
+
inherentFlags.push(InherentFlags.EDIT_IN_PROGRESS);
|
|
6496
6522
|
}
|
|
6497
|
-
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
|
+
];
|
|
6498
6532
|
}
|
|
6499
6533
|
|
|
6500
6534
|
// ../commons/src/events/state/index.ts
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opencrvs/toolkit",
|
|
3
|
-
"version": "2.0.0-rc.
|
|
3
|
+
"version": "2.0.0-rc.d0ccb3c",
|
|
4
4
|
"description": "OpenCRVS toolkit for building country configurations",
|
|
5
5
|
"license": "MPL-2.0",
|
|
6
6
|
"bin": {
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"jwt-decode": "^3.0.0",
|
|
34
34
|
"lodash": "^4.17.10",
|
|
35
35
|
"object-hash": "^3.0.0",
|
|
36
|
-
"qs": "6.
|
|
36
|
+
"qs": "6.15.2",
|
|
37
37
|
"superjson": "1.9.0-0",
|
|
38
38
|
"ts-morph": "^27.0.2",
|
|
39
39
|
"uuid": "^9.0.0",
|
|
Binary file
|