@opencrvs/toolkit 1.9.7-rc.a5fcb91 → 1.9.7

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.
@@ -10,10 +10,13 @@ declare const FuzzyMatcher: z.ZodObject<z.objectUtil.extendShape<{
10
10
  fieldId: z.ZodString;
11
11
  options: z.ZodDefault<z.ZodOptional<z.ZodObject<{
12
12
  boost: z.ZodOptional<z.ZodNumber>;
13
+ matchAgainst: z.ZodOptional<z.ZodString>;
13
14
  }, "strip", z.ZodTypeAny, {
14
15
  boost?: number | undefined;
16
+ matchAgainst?: string | undefined;
15
17
  }, {
16
18
  boost?: number | undefined;
19
+ matchAgainst?: string | undefined;
17
20
  }>>>;
18
21
  }, {
19
22
  type: z.ZodLiteral<"fuzzy">;
@@ -25,11 +28,14 @@ declare const FuzzyMatcher: z.ZodObject<z.objectUtil.extendShape<{
25
28
  */
26
29
  fuzziness: z.ZodDefault<z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>>;
27
30
  boost: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
31
+ matchAgainst: z.ZodOptional<z.ZodString>;
28
32
  }, "strip", z.ZodTypeAny, {
29
33
  boost: number;
30
34
  fuzziness: string | number;
35
+ matchAgainst?: string | undefined;
31
36
  }, {
32
37
  boost?: number | undefined;
38
+ matchAgainst?: string | undefined;
33
39
  fuzziness?: string | number | undefined;
34
40
  }>>>;
35
41
  }>, "strip", z.ZodTypeAny, {
@@ -37,6 +43,7 @@ declare const FuzzyMatcher: z.ZodObject<z.objectUtil.extendShape<{
37
43
  options: {
38
44
  boost: number;
39
45
  fuzziness: string | number;
46
+ matchAgainst?: string | undefined;
40
47
  };
41
48
  fieldId: string;
42
49
  }, {
@@ -44,6 +51,7 @@ declare const FuzzyMatcher: z.ZodObject<z.objectUtil.extendShape<{
44
51
  fieldId: string;
45
52
  options?: {
46
53
  boost?: number | undefined;
54
+ matchAgainst?: string | undefined;
47
55
  fuzziness?: string | number | undefined;
48
56
  } | undefined;
49
57
  }>;
@@ -58,10 +66,13 @@ declare const StrictMatcher: z.ZodObject<z.objectUtil.extendShape<{
58
66
  fieldId: z.ZodString;
59
67
  options: z.ZodDefault<z.ZodOptional<z.ZodObject<{
60
68
  boost: z.ZodOptional<z.ZodNumber>;
69
+ matchAgainst: z.ZodOptional<z.ZodString>;
61
70
  }, "strip", z.ZodTypeAny, {
62
71
  boost?: number | undefined;
72
+ matchAgainst?: string | undefined;
63
73
  }, {
64
74
  boost?: number | undefined;
75
+ matchAgainst?: string | undefined;
65
76
  }>>>;
66
77
  }, {
67
78
  type: z.ZodLiteral<"strict">;
@@ -71,18 +82,22 @@ declare const StrictMatcher: z.ZodObject<z.objectUtil.extendShape<{
71
82
  * The constant value to be present in the field for both records
72
83
  */
73
84
  value: z.ZodOptional<z.ZodString>;
85
+ matchAgainst: z.ZodOptional<z.ZodString>;
74
86
  }, "strip", z.ZodTypeAny, {
75
87
  boost: number;
76
88
  value?: string | undefined;
89
+ matchAgainst?: string | undefined;
77
90
  }, {
78
91
  value?: string | undefined;
79
92
  boost?: number | undefined;
93
+ matchAgainst?: string | undefined;
80
94
  }>>>;
81
95
  }>, "strip", z.ZodTypeAny, {
82
96
  type: "strict";
83
97
  options: {
84
98
  boost: number;
85
99
  value?: string | undefined;
100
+ matchAgainst?: string | undefined;
86
101
  };
87
102
  fieldId: string;
88
103
  }, {
@@ -91,6 +106,7 @@ declare const StrictMatcher: z.ZodObject<z.objectUtil.extendShape<{
91
106
  options?: {
92
107
  value?: string | undefined;
93
108
  boost?: number | undefined;
109
+ matchAgainst?: string | undefined;
94
110
  } | undefined;
95
111
  }>;
96
112
  export type StrictMatcherOptions = z.input<typeof StrictMatcher>['options'];
@@ -104,10 +120,13 @@ declare const DateRangeMatcher: z.ZodObject<z.objectUtil.extendShape<{
104
120
  fieldId: z.ZodString;
105
121
  options: z.ZodDefault<z.ZodOptional<z.ZodObject<{
106
122
  boost: z.ZodOptional<z.ZodNumber>;
123
+ matchAgainst: z.ZodOptional<z.ZodString>;
107
124
  }, "strip", z.ZodTypeAny, {
108
125
  boost?: number | undefined;
126
+ matchAgainst?: string | undefined;
109
127
  }, {
110
128
  boost?: number | undefined;
129
+ matchAgainst?: string | undefined;
111
130
  }>>>;
112
131
  }, {
113
132
  type: z.ZodLiteral<"dateRange">;
@@ -119,13 +138,16 @@ declare const DateRangeMatcher: z.ZodObject<z.objectUtil.extendShape<{
119
138
  pivot: z.ZodOptional<z.ZodNumber>;
120
139
  days: z.ZodNumber;
121
140
  boost: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
141
+ matchAgainst: z.ZodOptional<z.ZodString>;
122
142
  }, "strip", z.ZodTypeAny, {
123
143
  boost: number;
124
144
  days: number;
145
+ matchAgainst?: string | undefined;
125
146
  pivot?: number | undefined;
126
147
  }, {
127
148
  days: number;
128
149
  boost?: number | undefined;
150
+ matchAgainst?: string | undefined;
129
151
  pivot?: number | undefined;
130
152
  }>;
131
153
  }>, "strip", z.ZodTypeAny, {
@@ -133,6 +155,7 @@ declare const DateRangeMatcher: z.ZodObject<z.objectUtil.extendShape<{
133
155
  options: {
134
156
  boost: number;
135
157
  days: number;
158
+ matchAgainst?: string | undefined;
136
159
  pivot?: number | undefined;
137
160
  };
138
161
  fieldId: string;
@@ -141,6 +164,7 @@ declare const DateRangeMatcher: z.ZodObject<z.objectUtil.extendShape<{
141
164
  options: {
142
165
  days: number;
143
166
  boost?: number | undefined;
167
+ matchAgainst?: string | undefined;
144
168
  pivot?: number | undefined;
145
169
  };
146
170
  fieldId: string;
@@ -8,6 +8,7 @@ export declare function field(fieldId: string): {
8
8
  type: "fuzzy";
9
9
  options: {
10
10
  boost?: number | undefined;
11
+ matchAgainst?: string | undefined;
11
12
  fuzziness?: string | number | undefined;
12
13
  } | undefined;
13
14
  };
@@ -17,14 +18,50 @@ export declare function field(fieldId: string): {
17
18
  options: {
18
19
  value?: string | undefined;
19
20
  boost?: number | undefined;
21
+ matchAgainst?: string | undefined;
20
22
  } | undefined;
21
23
  };
24
+ /**
25
+ * Creates a date range matcher that finds records where date field fall within a specified range.
26
+ *
27
+ * By default, matches against the field specified in `field()` (e.g., 'mother.dob').
28
+ * When `matchAgainst` is provided, it overwrites the default field and searches against that field with OR logic .
29
+ *
30
+ * @param options - Configuration for the date range matching
31
+ * @param options.days - Number of days before and after the target date to search (creates a ±days range)
32
+ * @param options.pivot - Optional. Distance in days where relevance scoring drops by 50%. Defaults to ⌊(days * 2) / 3⌋
33
+ * @param options.boost - Optional. Scoring boost multiplier for matching results. Defaults to 1
34
+ * @param options.matchAgainst - Optional. Additional field to match against. When provided,
35
+ * the query matches if the field fall within the date range. The default field is always excluded in the search in that case.
36
+ *
37
+ * @returns A clause that matches records where at least one of the specified date field is within the range
38
+ *
39
+ * @example
40
+ * // Matches only against mother.dob (±365 days)
41
+ * field('mother.dob').dateRangeMatches({ days: 365 })
42
+ *
43
+ * @example
44
+ * // Matches against mother.age OR spouse.dob, not mother.dob
45
+ * field('mother.dob').dateRangeMatches({
46
+ * days: 365,
47
+ * matchAgainst: $field('mother.age')
48
+ * })
49
+ *
50
+ * @example
51
+ * // With custom pivot and boost
52
+ * field('mother.dob').dateRangeMatches({
53
+ * days: 730,
54
+ * pivot: 365,
55
+ * boost: 2
56
+ * })
57
+ */
22
58
  dateRangeMatches: (options: DateRangeMatcherOptions) => {
23
59
  fieldId: string;
24
60
  type: "dateRange";
25
61
  options: {
26
62
  days: number;
27
63
  boost?: number | undefined;
64
+ matchAgainst?: string | undefined;
28
65
  pivot?: number | undefined;
29
66
  };
30
67
  };
@@ -8,6 +8,7 @@ export declare function field(fieldId: string): {
8
8
  type: "fuzzy";
9
9
  options: {
10
10
  boost?: number | undefined;
11
+ matchAgainst?: string | undefined;
11
12
  fuzziness?: string | number | undefined;
12
13
  } | undefined;
13
14
  };
@@ -17,14 +18,50 @@ export declare function field(fieldId: string): {
17
18
  options: {
18
19
  value?: string | undefined;
19
20
  boost?: number | undefined;
21
+ matchAgainst?: string | undefined;
20
22
  } | undefined;
21
23
  };
24
+ /**
25
+ * Creates a date range matcher that finds records where date field fall within a specified range.
26
+ *
27
+ * By default, matches against the field specified in `field()` (e.g., 'mother.dob').
28
+ * When `matchAgainst` is provided, it overwrites the default field and searches against that field with OR logic .
29
+ *
30
+ * @param options - Configuration for the date range matching
31
+ * @param options.days - Number of days before and after the target date to search (creates a ±days range)
32
+ * @param options.pivot - Optional. Distance in days where relevance scoring drops by 50%. Defaults to ⌊(days * 2) / 3⌋
33
+ * @param options.boost - Optional. Scoring boost multiplier for matching results. Defaults to 1
34
+ * @param options.matchAgainst - Optional. Additional field to match against. When provided,
35
+ * the query matches if the field fall within the date range. The default field is always excluded in the search in that case.
36
+ *
37
+ * @returns A clause that matches records where at least one of the specified date field is within the range
38
+ *
39
+ * @example
40
+ * // Matches only against mother.dob (±365 days)
41
+ * field('mother.dob').dateRangeMatches({ days: 365 })
42
+ *
43
+ * @example
44
+ * // Matches against mother.age OR spouse.dob, not mother.dob
45
+ * field('mother.dob').dateRangeMatches({
46
+ * days: 365,
47
+ * matchAgainst: $field('mother.age')
48
+ * })
49
+ *
50
+ * @example
51
+ * // With custom pivot and boost
52
+ * field('mother.dob').dateRangeMatches({
53
+ * days: 730,
54
+ * pivot: 365,
55
+ * boost: 2
56
+ * })
57
+ */
22
58
  dateRangeMatches: (options: DateRangeMatcherOptions) => {
23
59
  fieldId: string;
24
60
  type: "dateRange";
25
61
  options: {
26
62
  days: number;
27
63
  boost?: number | undefined;
64
+ matchAgainst?: string | undefined;
28
65
  pivot?: number | undefined;
29
66
  };
30
67
  };
@@ -58,6 +58,40 @@ function field(fieldId) {
58
58
  type: "strict",
59
59
  options
60
60
  }),
61
+ /**
62
+ * Creates a date range matcher that finds records where date field fall within a specified range.
63
+ *
64
+ * By default, matches against the field specified in `field()` (e.g., 'mother.dob').
65
+ * When `matchAgainst` is provided, it overwrites the default field and searches against that field with OR logic .
66
+ *
67
+ * @param options - Configuration for the date range matching
68
+ * @param options.days - Number of days before and after the target date to search (creates a ±days range)
69
+ * @param options.pivot - Optional. Distance in days where relevance scoring drops by 50%. Defaults to ⌊(days * 2) / 3⌋
70
+ * @param options.boost - Optional. Scoring boost multiplier for matching results. Defaults to 1
71
+ * @param options.matchAgainst - Optional. Additional field to match against. When provided,
72
+ * the query matches if the field fall within the date range. The default field is always excluded in the search in that case.
73
+ *
74
+ * @returns A clause that matches records where at least one of the specified date field is within the range
75
+ *
76
+ * @example
77
+ * // Matches only against mother.dob (±365 days)
78
+ * field('mother.dob').dateRangeMatches({ days: 365 })
79
+ *
80
+ * @example
81
+ * // Matches against mother.age OR spouse.dob, not mother.dob
82
+ * field('mother.dob').dateRangeMatches({
83
+ * days: 365,
84
+ * matchAgainst: $field('mother.age')
85
+ * })
86
+ *
87
+ * @example
88
+ * // With custom pivot and boost
89
+ * field('mother.dob').dateRangeMatches({
90
+ * days: 730,
91
+ * pivot: 365,
92
+ * boost: 2
93
+ * })
94
+ */
61
95
  dateRangeMatches: (options) => ({
62
96
  fieldId,
63
97
  type: "dateRange",
@@ -716,7 +716,7 @@ var FileFieldValueWithOption = import_zod6.z.object({
716
716
  type: import_zod6.z.string(),
717
717
  option: import_zod6.z.string()
718
718
  });
719
- var FileFieldWithOptionValue = import_zod6.z.array(FileFieldValueWithOption).min(1);
719
+ var FileFieldWithOptionValue = import_zod6.z.array(FileFieldValueWithOption);
720
720
  var HttpFieldValue = import_zod6.z.object({
721
721
  loading: import_zod6.z.boolean(),
722
722
  error: import_zod6.z.object({ statusCode: import_zod6.z.number(), message: import_zod6.z.string() }).nullish(),
@@ -2557,7 +2557,8 @@ var Matcher = import_zod19.z.object({
2557
2557
  */
2558
2558
  fieldId: FieldReference2,
2559
2559
  options: import_zod19.z.object({
2560
- boost: import_zod19.z.number().optional()
2560
+ boost: import_zod19.z.number().optional(),
2561
+ matchAgainst: FieldReference2.optional()
2561
2562
  }).optional().default({
2562
2563
  boost: 1
2563
2564
  })
@@ -2571,7 +2572,8 @@ var FuzzyMatcher = Matcher.extend({
2571
2572
  * Names of length >7 characters = 2 edits allowed
2572
2573
  */
2573
2574
  fuzziness: import_zod19.z.union([import_zod19.z.string(), import_zod19.z.number()]).optional().default("AUTO:4,7"),
2574
- boost: import_zod19.z.number().optional().default(1)
2575
+ boost: import_zod19.z.number().optional().default(1),
2576
+ matchAgainst: FieldReference2.optional()
2575
2577
  }).optional().default({
2576
2578
  fuzziness: "AUTO:4,7",
2577
2579
  boost: 1
@@ -2584,7 +2586,8 @@ var StrictMatcher = Matcher.extend({
2584
2586
  /**
2585
2587
  * The constant value to be present in the field for both records
2586
2588
  */
2587
- value: import_zod19.z.string().optional()
2589
+ value: import_zod19.z.string().optional(),
2590
+ matchAgainst: FieldReference2.optional()
2588
2591
  }).optional().default({
2589
2592
  boost: 1
2590
2593
  })
@@ -2598,7 +2601,8 @@ var DateRangeMatcher = Matcher.extend({
2598
2601
  */
2599
2602
  pivot: import_zod19.z.number().optional(),
2600
2603
  days: import_zod19.z.number(),
2601
- boost: import_zod19.z.number().optional().default(1)
2604
+ boost: import_zod19.z.number().optional().default(1),
2605
+ matchAgainst: FieldReference2.optional()
2602
2606
  })
2603
2607
  });
2604
2608
  var Not = import_zod19.z.object({
@@ -3019,7 +3023,7 @@ function mapFieldTypeToZod(field3, actionType) {
3019
3023
  schema = FileFieldValue;
3020
3024
  break;
3021
3025
  case FieldType.FILE_WITH_OPTIONS:
3022
- schema = FileFieldWithOptionValue;
3026
+ schema = field3.required ? FileFieldWithOptionValue.min(1) : FileFieldWithOptionValue;
3023
3027
  break;
3024
3028
  case FieldType.ADDRESS:
3025
3029
  schema = getDynamicAddressFieldValue(field3);
@@ -3896,11 +3900,14 @@ function isRequestedAction(a) {
3896
3900
  function isAcceptedAction(a) {
3897
3901
  return a.status === ActionStatus.Accepted;
3898
3902
  }
3903
+ function isRejectedAction(a) {
3904
+ return a.status === ActionStatus.Rejected;
3905
+ }
3899
3906
  function getPendingAction(actions) {
3900
3907
  const requestedActions = actions.filter(isRequestedAction);
3901
3908
  const pendingActions = requestedActions.filter(
3902
3909
  ({ id }) => !actions.some(
3903
- (action) => isAcceptedAction(action) && action.originalActionId === id
3910
+ (action) => (isAcceptedAction(action) || isRejectedAction(action)) && action.originalActionId === id
3904
3911
  )
3905
3912
  );
3906
3913
  if (pendingActions.length !== 1) {
@@ -7813,8 +7820,35 @@ var mother = defineFormPage({
7813
7820
  secured: true,
7814
7821
  validation: [],
7815
7822
  label: generateTranslationConfig("Date of birth"),
7823
+ conditionals: [
7824
+ {
7825
+ type: "SHOW",
7826
+ conditional: not(field("mother.dobUnknown").isEqualTo(true))
7827
+ }
7828
+ ]
7829
+ },
7830
+ {
7831
+ id: "mother.dobUnknown",
7832
+ type: "CHECKBOX",
7833
+ label: generateTranslationConfig("Exact date of birth unknown"),
7816
7834
  conditionals: []
7817
7835
  },
7836
+ {
7837
+ id: "mother.age",
7838
+ type: FieldType.AGE,
7839
+ required: true,
7840
+ analytics: true,
7841
+ label: generateTranslationConfig("Age of mother"),
7842
+ configuration: {
7843
+ asOfDate: field("child.dob")
7844
+ },
7845
+ conditionals: [
7846
+ {
7847
+ type: "SHOW",
7848
+ conditional: field("mother.dobUnknown").isEqualTo(true)
7849
+ }
7850
+ ]
7851
+ },
7818
7852
  {
7819
7853
  id: "mother.idType",
7820
7854
  type: FieldType.SELECT,
@@ -373,7 +373,7 @@ var FileFieldValueWithOption = import_zod6.z.object({
373
373
  type: import_zod6.z.string(),
374
374
  option: import_zod6.z.string()
375
375
  });
376
- var FileFieldWithOptionValue = import_zod6.z.array(FileFieldValueWithOption).min(1);
376
+ var FileFieldWithOptionValue = import_zod6.z.array(FileFieldValueWithOption);
377
377
  var HttpFieldValue = import_zod6.z.object({
378
378
  loading: import_zod6.z.boolean(),
379
379
  error: import_zod6.z.object({ statusCode: import_zod6.z.number(), message: import_zod6.z.string() }).nullish(),
@@ -2079,7 +2079,8 @@ var Matcher = import_zod19.z.object({
2079
2079
  */
2080
2080
  fieldId: FieldReference2,
2081
2081
  options: import_zod19.z.object({
2082
- boost: import_zod19.z.number().optional()
2082
+ boost: import_zod19.z.number().optional(),
2083
+ matchAgainst: FieldReference2.optional()
2083
2084
  }).optional().default({
2084
2085
  boost: 1
2085
2086
  })
@@ -2093,7 +2094,8 @@ var FuzzyMatcher = Matcher.extend({
2093
2094
  * Names of length >7 characters = 2 edits allowed
2094
2095
  */
2095
2096
  fuzziness: import_zod19.z.union([import_zod19.z.string(), import_zod19.z.number()]).optional().default("AUTO:4,7"),
2096
- boost: import_zod19.z.number().optional().default(1)
2097
+ boost: import_zod19.z.number().optional().default(1),
2098
+ matchAgainst: FieldReference2.optional()
2097
2099
  }).optional().default({
2098
2100
  fuzziness: "AUTO:4,7",
2099
2101
  boost: 1
@@ -2106,7 +2108,8 @@ var StrictMatcher = Matcher.extend({
2106
2108
  /**
2107
2109
  * The constant value to be present in the field for both records
2108
2110
  */
2109
- value: import_zod19.z.string().optional()
2111
+ value: import_zod19.z.string().optional(),
2112
+ matchAgainst: FieldReference2.optional()
2110
2113
  }).optional().default({
2111
2114
  boost: 1
2112
2115
  })
@@ -2120,7 +2123,8 @@ var DateRangeMatcher = Matcher.extend({
2120
2123
  */
2121
2124
  pivot: import_zod19.z.number().optional(),
2122
2125
  days: import_zod19.z.number(),
2123
- boost: import_zod19.z.number().optional().default(1)
2126
+ boost: import_zod19.z.number().optional().default(1),
2127
+ matchAgainst: FieldReference2.optional()
2124
2128
  })
2125
2129
  });
2126
2130
  var Not = import_zod19.z.object({
@@ -6066,8 +6070,35 @@ var mother = defineFormPage({
6066
6070
  secured: true,
6067
6071
  validation: [],
6068
6072
  label: generateTranslationConfig("Date of birth"),
6073
+ conditionals: [
6074
+ {
6075
+ type: "SHOW",
6076
+ conditional: not(field("mother.dobUnknown").isEqualTo(true))
6077
+ }
6078
+ ]
6079
+ },
6080
+ {
6081
+ id: "mother.dobUnknown",
6082
+ type: "CHECKBOX",
6083
+ label: generateTranslationConfig("Exact date of birth unknown"),
6069
6084
  conditionals: []
6070
6085
  },
6086
+ {
6087
+ id: "mother.age",
6088
+ type: FieldType.AGE,
6089
+ required: true,
6090
+ analytics: true,
6091
+ label: generateTranslationConfig("Age of mother"),
6092
+ configuration: {
6093
+ asOfDate: field("child.dob")
6094
+ },
6095
+ conditionals: [
6096
+ {
6097
+ type: "SHOW",
6098
+ conditional: field("mother.dobUnknown").isEqualTo(true)
6099
+ }
6100
+ ]
6101
+ },
6071
6102
  {
6072
6103
  id: "mother.idType",
6073
6104
  type: FieldType.SELECT,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opencrvs/toolkit",
3
- "version": "1.9.7-rc.a5fcb91",
3
+ "version": "1.9.7",
4
4
  "description": "OpenCRVS toolkit for building country configurations",
5
5
  "license": "MPL-2.0",
6
6
  "exports": {