@opencrvs/toolkit 2.0.0-rc.7f97781 → 2.0.0-rc.7faa6f9

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.
@@ -324,7 +324,7 @@ var PlainDate = import_zod.z.string().date().brand("PlainDate").describe("Date i
324
324
  // ../commons/src/events/FieldValue.ts
325
325
  var TextValue = z7.string();
326
326
  var HiddenFieldValue = z7.string();
327
- var NonEmptyTextValue = TextValue.min(1);
327
+ var NonEmptyTextValue = z7.string().trim().min(1);
328
328
  var DateValue = z7.iso.date().describe("Date in the format YYYY-MM-DD");
329
329
  var AgeValue = z7.object({
330
330
  age: z7.number(),
@@ -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
@@ -1326,7 +1326,7 @@ function plainDateToLocalDate(date) {
1326
1326
  // ../commons/src/events/FieldValue.ts
1327
1327
  var TextValue = z12.string();
1328
1328
  var HiddenFieldValue = z12.string();
1329
- var NonEmptyTextValue = TextValue.min(1);
1329
+ var NonEmptyTextValue = z12.string().trim().min(1);
1330
1330
  var DateValue = z12.iso.date().describe("Date in the format YYYY-MM-DD");
1331
1331
  var AgeValue = z12.object({
1332
1332
  age: z12.number(),
@@ -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.REQUEST_CORRECTION) {
6419
+ if (type === ActionType.REJECT) {
6394
6420
  return true;
6395
6421
  }
6396
- if (type === ActionType.APPROVE_CORRECTION) {
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 getEventFlags(event2, config) {
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
- const flags = Object.entries(actionStatus).filter(([, status2]) => status2 !== ActionStatus.Accepted).map(([type, status2]) => {
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
- if (isCorrectionRequested(sortedActions)) {
6487
- flags.push(InherentFlags.CORRECTION_REQUESTED);
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(sortedActions)) {
6490
- flags.push(InherentFlags.INCOMPLETE);
6511
+ if (isDeclarationIncomplete(acceptedActions)) {
6512
+ inherentFlags.push(InherentFlags.INCOMPLETE);
6491
6513
  }
6492
- if (isRejected(sortedActions)) {
6493
- flags.push(InherentFlags.REJECTED);
6514
+ if (isRejected(acceptedActions)) {
6515
+ inherentFlags.push(InherentFlags.REJECTED);
6494
6516
  }
6495
- if (isPotentialDuplicate(sortedActions)) {
6496
- flags.push(InherentFlags.POTENTIAL_DUPLICATE);
6517
+ if (isPotentialDuplicate(acceptedActions)) {
6518
+ inherentFlags.push(InherentFlags.POTENTIAL_DUPLICATE);
6497
6519
  }
6498
- if (isEditInProgress(sortedActions)) {
6499
- flags.push(InherentFlags.EDIT_IN_PROGRESS);
6520
+ if (isEditInProgress(acceptedActions)) {
6521
+ inherentFlags.push(InherentFlags.EDIT_IN_PROGRESS);
6500
6522
  }
6501
- return [...flags, ...resolveEventCustomFlags(event2, config)];
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
@@ -888,7 +888,7 @@ var PlainDate = import_zod.z.string().date().brand("PlainDate").describe("Date i
888
888
  // ../commons/src/events/FieldValue.ts
889
889
  var TextValue = z12.string();
890
890
  var HiddenFieldValue = z12.string();
891
- var NonEmptyTextValue = TextValue.min(1);
891
+ var NonEmptyTextValue = z12.string().trim().min(1);
892
892
  var DateValue = z12.iso.date().describe("Date in the format YYYY-MM-DD");
893
893
  var AgeValue = z12.object({
894
894
  age: z12.number(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opencrvs/toolkit",
3
- "version": "2.0.0-rc.7f97781",
3
+ "version": "2.0.0-rc.7faa6f9",
4
4
  "description": "OpenCRVS toolkit for building country configurations",
5
5
  "license": "MPL-2.0",
6
6
  "bin": {