@opencrvs/toolkit 2.0.0-rc.b8b53fc → 2.0.0-rc.b942f5a

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(),
@@ -20,5 +20,18 @@ export declare function findPendingCorrectionAction(writeActions: Action[]): Req
20
20
  * // Returns: ['flag-1', 'flag-3']
21
21
  */
22
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
+ */
23
36
  export declare function getEventFlags(event: EventDocument, config: EventConfig): Flag[];
24
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(),
@@ -6392,14 +6392,12 @@ function findPendingCorrectionAction(writeActions2) {
6392
6392
  let correctionRequestAction;
6393
6393
  for (let i = writeActions2.length - 1; i >= 0; i--) {
6394
6394
  const action = writeActions2[i];
6395
- if (action.status === ActionStatus.Accepted) {
6396
- if (action.type === ActionType.APPROVE_CORRECTION || action.type === ActionType.REJECT_CORRECTION) {
6397
- break;
6398
- }
6399
- if (action.type === ActionType.REQUEST_CORRECTION) {
6400
- correctionRequestAction = action;
6401
- break;
6402
- }
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;
6403
6401
  }
6404
6402
  }
6405
6403
  return correctionRequestAction;
@@ -6411,7 +6409,21 @@ function isDeclarationIncomplete(actions) {
6411
6409
  return getStatusFromActions(actions) === EventStatus.enum.NOTIFIED;
6412
6410
  }
6413
6411
  function isRejected(actions) {
6414
- return actions.at(-1)?.type === ActionType.REJECT;
6412
+ const resettingActionTypes = [
6413
+ ActionType.NOTIFY,
6414
+ ActionType.DECLARE,
6415
+ ActionType.EDIT,
6416
+ ActionType.REGISTER
6417
+ ];
6418
+ return actions.reduce((prev, { type }) => {
6419
+ if (type === ActionType.REJECT) {
6420
+ return true;
6421
+ }
6422
+ if (resettingActionTypes.includes(type)) {
6423
+ return false;
6424
+ }
6425
+ return prev;
6426
+ }, false);
6415
6427
  }
6416
6428
  function isPotentialDuplicate(actions) {
6417
6429
  return actions.reduce((prev, { type }) => {
@@ -6475,8 +6487,7 @@ function resolveEventCustomFlags(event2, eventConfiguration) {
6475
6487
  return (0, import_lodash3.uniq)(flags);
6476
6488
  }, []);
6477
6489
  }
6478
- function getEventFlags(event2, config) {
6479
- const sortedActions = event2.actions.filter(({ type }) => !isMetaAction(type)).sort((a, b) => a.createdAt.localeCompare(b.createdAt));
6490
+ function getActionStatusFlags(sortedActions) {
6480
6491
  const actionStatus = sortedActions.reduce(
6481
6492
  (actionStatuses, { type, status: status2 }) => ({
6482
6493
  ...actionStatuses,
@@ -6484,26 +6495,40 @@ function getEventFlags(event2, config) {
6484
6495
  }),
6485
6496
  {}
6486
6497
  );
6487
- 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]) => {
6488
6499
  const flag2 = joinValues([type, status2], ":").toLowerCase();
6489
6500
  return flag2;
6490
6501
  });
6491
- if (isCorrectionRequested(sortedActions)) {
6492
- 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);
6493
6510
  }
6494
- if (isDeclarationIncomplete(sortedActions)) {
6495
- flags.push(InherentFlags.INCOMPLETE);
6511
+ if (isDeclarationIncomplete(acceptedActions)) {
6512
+ inherentFlags.push(InherentFlags.INCOMPLETE);
6496
6513
  }
6497
- if (isRejected(sortedActions)) {
6498
- flags.push(InherentFlags.REJECTED);
6514
+ if (isRejected(acceptedActions)) {
6515
+ inherentFlags.push(InherentFlags.REJECTED);
6499
6516
  }
6500
- if (isPotentialDuplicate(sortedActions)) {
6501
- flags.push(InherentFlags.POTENTIAL_DUPLICATE);
6517
+ if (isPotentialDuplicate(acceptedActions)) {
6518
+ inherentFlags.push(InherentFlags.POTENTIAL_DUPLICATE);
6502
6519
  }
6503
- if (isEditInProgress(sortedActions)) {
6504
- flags.push(InherentFlags.EDIT_IN_PROGRESS);
6520
+ if (isEditInProgress(acceptedActions)) {
6521
+ inherentFlags.push(InherentFlags.EDIT_IN_PROGRESS);
6505
6522
  }
6506
- 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
+ ];
6507
6532
  }
6508
6533
 
6509
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.b8b53fc",
3
+ "version": "2.0.0-rc.b942f5a",
4
4
  "description": "OpenCRVS toolkit for building country configurations",
5
5
  "license": "MPL-2.0",
6
6
  "bin": {