@opencrvs/toolkit 2.0.0-rc.eade8c4 → 2.0.0-rc.ed2a25c

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(),
@@ -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
  }
@@ -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,
@@ -1325,7 +1326,7 @@ function plainDateToLocalDate(date) {
1325
1326
  // ../commons/src/events/FieldValue.ts
1326
1327
  var TextValue = z12.string();
1327
1328
  var HiddenFieldValue = z12.string();
1328
- var NonEmptyTextValue = TextValue.min(1);
1329
+ var NonEmptyTextValue = z12.string().trim().min(1);
1329
1330
  var DateValue = z12.iso.date().describe("Date in the format YYYY-MM-DD");
1330
1331
  var AgeValue = z12.object({
1331
1332
  age: z12.number(),
@@ -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.REQUEST_CORRECTION) {
6419
+ if (type === ActionType.REJECT) {
6390
6420
  return true;
6391
6421
  }
6392
- if (type === ActionType.APPROVE_CORRECTION) {
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 getEventFlags(event2, config) {
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
- 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]) => {
6479
6499
  const flag2 = joinValues([type, status2], ":").toLowerCase();
6480
6500
  return flag2;
6481
6501
  });
6482
- if (isCorrectionRequested(sortedActions)) {
6483
- 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);
6484
6510
  }
6485
- if (isDeclarationIncomplete(sortedActions)) {
6486
- flags.push(InherentFlags.INCOMPLETE);
6511
+ if (isDeclarationIncomplete(acceptedActions)) {
6512
+ inherentFlags.push(InherentFlags.INCOMPLETE);
6487
6513
  }
6488
- if (isRejected(sortedActions)) {
6489
- flags.push(InherentFlags.REJECTED);
6514
+ if (isRejected(acceptedActions)) {
6515
+ inherentFlags.push(InherentFlags.REJECTED);
6490
6516
  }
6491
- if (isPotentialDuplicate(sortedActions)) {
6492
- flags.push(InherentFlags.POTENTIAL_DUPLICATE);
6517
+ if (isPotentialDuplicate(acceptedActions)) {
6518
+ inherentFlags.push(InherentFlags.POTENTIAL_DUPLICATE);
6493
6519
  }
6494
- if (isEditInProgress(sortedActions)) {
6495
- flags.push(InherentFlags.EDIT_IN_PROGRESS);
6520
+ if (isEditInProgress(acceptedActions)) {
6521
+ inherentFlags.push(InherentFlags.EDIT_IN_PROGRESS);
6496
6522
  }
6497
- 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
+ ];
6498
6532
  }
6499
6533
 
6500
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.eade8c4",
3
+ "version": "2.0.0-rc.ed2a25c",
4
4
  "description": "OpenCRVS toolkit for building country configurations",
5
5
  "license": "MPL-2.0",
6
6
  "bin": {