@opencrvs/toolkit 2.0.0-rc.6d4a31a → 2.0.0-rc.6de0270

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.
@@ -22,6 +22,7 @@ export * from './FieldValue';
22
22
  export * from './FormConfig';
23
23
  export * from './CompositeFieldValue';
24
24
  export * from './state';
25
+ export * from './state/flags';
25
26
  export * from './utils';
26
27
  export * from './defineConfig';
27
28
  export * from './DeduplicationConfig';
@@ -1,6 +1,9 @@
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;
6
+ export declare function isPotentialDuplicate(actions: Action[]): boolean;
4
7
  /**
5
8
  * This function resolves custom flags for an event based on its actions.
6
9
  * Flags are not stored to the event state or any database directly, instead they are always computed/evaluated from the event actions.
@@ -18,5 +21,18 @@ import { EventDocument } from '../EventDocument';
18
21
  * // Returns: ['flag-1', 'flag-3']
19
22
  */
20
23
  export declare function resolveEventCustomFlags(event: EventDocument, eventConfiguration: EventConfig): CustomFlag[];
24
+ /**
25
+ * Computes all flags (inherent, action status, and custom) that should be attached to the given event,
26
+ * based on its actions and event-specific configuration.
27
+ *
28
+ * Flags are determined by combining:
29
+ * - Action status flags (format 'ActionType:ActionStatus')
30
+ * - Inherent flags (e.g. incomplete, rejected, correction requested, potential duplicate, edit in progress)
31
+ * - Event type-specific custom flags defined in the event configuration
32
+ *
33
+ * @param event - The EventDocument containing the action history and payload
34
+ * @param config - The EventConfig providing rules for custom flag evaluation
35
+ * @returns An array of flags currently relevant/applicable to the event
36
+ */
21
37
  export declare function getEventFlags(event: EventDocument, config: EventConfig): Flag[];
22
38
  //# sourceMappingURL=flags.d.ts.map
@@ -282,6 +282,7 @@ __export(events_exports, {
282
282
  findActiveDraftForEvent: () => findActiveDraftForEvent,
283
283
  findAllFields: () => findAllFields,
284
284
  findLastAssignmentAction: () => findLastAssignmentAction,
285
+ findPendingCorrectionAction: () => findPendingCorrectionAction,
285
286
  findRecordActionPages: () => findRecordActionPages,
286
287
  flag: () => flag,
287
288
  flattenFieldReference: () => flattenFieldReference,
@@ -323,6 +324,7 @@ __export(events_exports, {
323
324
  getDeclarationFields: () => getDeclarationFields,
324
325
  getDeclarationPages: () => getDeclarationPages,
325
326
  getEventConfigById: () => getEventConfigById,
327
+ getEventFlags: () => getEventFlags,
326
328
  getFilePathsFromEvent: () => getFilePathsFromEvent,
327
329
  getLocationHierarchy: () => getLocationHierarchy,
328
330
  getMixedPath: () => getMixedPath,
@@ -385,6 +387,7 @@ __export(events_exports, {
385
387
  isPageVisible: () => isPageVisible,
386
388
  isParagraphFieldType: () => isParagraphFieldType,
387
389
  isPhoneFieldType: () => isPhoneFieldType,
390
+ isPotentialDuplicate: () => isPotentialDuplicate,
388
391
  isPrintButtonFieldType: () => isPrintButtonFieldType,
389
392
  isQrReaderFieldType: () => isQrReaderFieldType,
390
393
  isQueryParamReaderFieldType: () => isQueryParamReaderFieldType,
@@ -418,6 +421,7 @@ __export(events_exports, {
418
421
  plainDateToLocalDate: () => plainDateToLocalDate,
419
422
  precompileActionSchemas: () => precompileActionSchemas,
420
423
  resolveDateOfEvent: () => resolveDateOfEvent,
424
+ resolveEventCustomFlags: () => resolveEventCustomFlags,
421
425
  resolvePlaceOfEvent: () => resolvePlaceOfEvent,
422
426
  runFieldValidations: () => runFieldValidations,
423
427
  runStructuralValidations: () => runStructuralValidations,
@@ -6388,26 +6392,43 @@ var import_date_fns3 = require("date-fns");
6388
6392
  function isEditInProgress(actions) {
6389
6393
  return actions.at(-1)?.type === ActionType.EDIT;
6390
6394
  }
6395
+ function findPendingCorrectionAction(writeActions2) {
6396
+ let correctionRequestAction;
6397
+ for (let i = writeActions2.length - 1; i >= 0; i--) {
6398
+ const action = writeActions2[i];
6399
+ if (action.type === ActionType.APPROVE_CORRECTION || action.type === ActionType.REJECT_CORRECTION) {
6400
+ break;
6401
+ }
6402
+ if (action.type === ActionType.REQUEST_CORRECTION) {
6403
+ correctionRequestAction = action;
6404
+ break;
6405
+ }
6406
+ }
6407
+ return correctionRequestAction;
6408
+ }
6391
6409
  function isCorrectionRequested(actions) {
6410
+ return findPendingCorrectionAction(actions) !== void 0;
6411
+ }
6412
+ function isDeclarationIncomplete(actions) {
6413
+ return getStatusFromActions(actions) === EventStatus.enum.NOTIFIED;
6414
+ }
6415
+ function isRejected(actions) {
6416
+ const resettingActionTypes = [
6417
+ ActionType.NOTIFY,
6418
+ ActionType.DECLARE,
6419
+ ActionType.EDIT,
6420
+ ActionType.REGISTER
6421
+ ];
6392
6422
  return actions.reduce((prev, { type }) => {
6393
- if (type === ActionType.REQUEST_CORRECTION) {
6423
+ if (type === ActionType.REJECT) {
6394
6424
  return true;
6395
6425
  }
6396
- if (type === ActionType.APPROVE_CORRECTION) {
6397
- return false;
6398
- }
6399
- if (type === ActionType.REJECT_CORRECTION) {
6426
+ if (resettingActionTypes.includes(type)) {
6400
6427
  return false;
6401
6428
  }
6402
6429
  return prev;
6403
6430
  }, false);
6404
6431
  }
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
6432
  function isPotentialDuplicate(actions) {
6412
6433
  return actions.reduce((prev, { type }) => {
6413
6434
  if (type === ActionType.DUPLICATE_DETECTED) {
@@ -6470,8 +6491,7 @@ function resolveEventCustomFlags(event2, eventConfiguration) {
6470
6491
  return (0, import_lodash3.uniq)(flags);
6471
6492
  }, []);
6472
6493
  }
6473
- function getEventFlags(event2, config) {
6474
- const sortedActions = event2.actions.filter(({ type }) => !isMetaAction(type)).sort((a, b) => a.createdAt.localeCompare(b.createdAt));
6494
+ function getActionStatusFlags(sortedActions) {
6475
6495
  const actionStatus = sortedActions.reduce(
6476
6496
  (actionStatuses, { type, status: status2 }) => ({
6477
6497
  ...actionStatuses,
@@ -6479,26 +6499,40 @@ function getEventFlags(event2, config) {
6479
6499
  }),
6480
6500
  {}
6481
6501
  );
6482
- const flags = Object.entries(actionStatus).filter(([, status2]) => status2 !== ActionStatus.Accepted).map(([type, status2]) => {
6502
+ return Object.entries(actionStatus).filter(([, status2]) => status2 !== ActionStatus.Accepted).map(([type, status2]) => {
6483
6503
  const flag2 = joinValues([type, status2], ":").toLowerCase();
6484
6504
  return flag2;
6485
6505
  });
6486
- if (isCorrectionRequested(sortedActions)) {
6487
- flags.push(InherentFlags.CORRECTION_REQUESTED);
6506
+ }
6507
+ function getInherentFlags(sortedActions) {
6508
+ const acceptedActions = sortedActions.filter(
6509
+ ({ status: status2 }) => status2 === ActionStatus.Accepted
6510
+ );
6511
+ const inherentFlags = [];
6512
+ if (isCorrectionRequested(acceptedActions)) {
6513
+ inherentFlags.push(InherentFlags.CORRECTION_REQUESTED);
6488
6514
  }
6489
- if (isDeclarationIncomplete(sortedActions)) {
6490
- flags.push(InherentFlags.INCOMPLETE);
6515
+ if (isDeclarationIncomplete(acceptedActions)) {
6516
+ inherentFlags.push(InherentFlags.INCOMPLETE);
6491
6517
  }
6492
- if (isRejected(sortedActions)) {
6493
- flags.push(InherentFlags.REJECTED);
6518
+ if (isRejected(acceptedActions)) {
6519
+ inherentFlags.push(InherentFlags.REJECTED);
6494
6520
  }
6495
- if (isPotentialDuplicate(sortedActions)) {
6496
- flags.push(InherentFlags.POTENTIAL_DUPLICATE);
6521
+ if (isPotentialDuplicate(acceptedActions)) {
6522
+ inherentFlags.push(InherentFlags.POTENTIAL_DUPLICATE);
6497
6523
  }
6498
- if (isEditInProgress(sortedActions)) {
6499
- flags.push(InherentFlags.EDIT_IN_PROGRESS);
6524
+ if (isEditInProgress(acceptedActions)) {
6525
+ inherentFlags.push(InherentFlags.EDIT_IN_PROGRESS);
6500
6526
  }
6501
- return [...flags, ...resolveEventCustomFlags(event2, config)];
6527
+ return inherentFlags;
6528
+ }
6529
+ function getEventFlags(event2, config) {
6530
+ const sortedActions = event2.actions.filter(({ type }) => !isMetaAction(type)).sort((a, b) => a.createdAt.localeCompare(b.createdAt));
6531
+ return [
6532
+ ...getActionStatusFlags(sortedActions),
6533
+ ...getInherentFlags(sortedActions),
6534
+ ...resolveEventCustomFlags(event2, config)
6535
+ ];
6502
6536
  }
6503
6537
 
6504
6538
  // ../commons/src/events/state/index.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opencrvs/toolkit",
3
- "version": "2.0.0-rc.6d4a31a",
3
+ "version": "2.0.0-rc.6de0270",
4
4
  "description": "OpenCRVS toolkit for building country configurations",
5
5
  "license": "MPL-2.0",
6
6
  "bin": {