@opencrvs/toolkit 1.8.0-rc.f7e8fb5 → 1.8.0-rc.f8e4107

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.
Files changed (34) hide show
  1. package/README.md +1 -1
  2. package/dist/commons/api/router.d.ts +6649 -9067
  3. package/dist/commons/conditionals/conditionals.d.ts +91 -3
  4. package/dist/commons/conditionals/validate-address.test.d.ts +2 -0
  5. package/dist/commons/conditionals/validate.d.ts +41 -17
  6. package/dist/commons/conditionals/validate.test.d.ts +2 -0
  7. package/dist/commons/events/ActionConfig.d.ts +1123 -2056
  8. package/dist/commons/events/ActionDocument.d.ts +9644 -363
  9. package/dist/commons/events/ActionInput.d.ts +5329 -472
  10. package/dist/commons/events/ActionType.d.ts +26 -11
  11. package/dist/commons/events/AdvancedSearchConfig.d.ts +107 -14
  12. package/dist/commons/events/CompositeFieldValue.d.ts +152 -2
  13. package/dist/commons/events/Conditional.d.ts +21 -5
  14. package/dist/commons/events/Draft.d.ts +361 -53
  15. package/dist/commons/events/EventConfig.d.ts +634 -1223
  16. package/dist/commons/events/EventConfigInput.d.ts +6 -3
  17. package/dist/commons/events/EventDocument.d.ts +3495 -499
  18. package/dist/commons/events/EventIndex.d.ts +752 -7
  19. package/dist/commons/events/EventMetadata.d.ts +9 -3
  20. package/dist/commons/events/FieldConfig.d.ts +571 -119
  21. package/dist/commons/events/FieldType.d.ts +2 -1
  22. package/dist/commons/events/FieldTypeMapping.d.ts +154 -3
  23. package/dist/commons/events/FieldValue.d.ts +76 -2
  24. package/dist/commons/events/FormConfig.d.ts +633 -48
  25. package/dist/commons/events/PageConfig.d.ts +335 -0
  26. package/dist/commons/events/TemplateConfig.d.ts +5 -5
  27. package/dist/commons/events/defineConfig.d.ts +94 -215
  28. package/dist/commons/events/index.d.ts +2 -1
  29. package/dist/commons/events/test.utils.d.ts +140 -213
  30. package/dist/commons/events/utils.d.ts +125 -86
  31. package/dist/commons/events/utils.test.d.ts +2 -0
  32. package/dist/conditionals/index.js +215 -81
  33. package/dist/events/index.js +1949 -1232
  34. package/package.json +1 -1
@@ -3,11 +3,14 @@ import { EventState } from '../events/ActionDocument';
3
3
  import { ITokenPayload as TokenPayload, Scope } from '../authentication';
4
4
  import { ActionType } from '../events/ActionType';
5
5
  import { PartialSchema as AjvJSONSchemaType } from 'ajv/dist/types/json-schema';
6
+ import { SelectOption } from '../events/FieldConfig';
7
+ import { MetadataField } from '../utils';
6
8
  /** @knipignore */
7
9
  export type JSONSchema = {
8
10
  readonly __nominal__type: 'JSONSchema';
9
11
  };
10
12
  export declare function defineConditional(schema: any): JSONSchema;
13
+ export declare function defineFormConditional(schema: Record<string, unknown>): JSONSchema;
11
14
  export type UserConditionalParameters = {
12
15
  $now: string;
13
16
  $user: TokenPayload;
@@ -47,6 +50,12 @@ export declare function or(...conditions: AjvJSONSchema[]): JSONSchema;
47
50
  * @example not(field('foo').isEqualTo('bar'))
48
51
  */
49
52
  export declare function not(condition: AjvJSONSchema): JSONSchema;
53
+ /**
54
+ * Returns an JSON Schema object, which is treated as always invalid.
55
+ *
56
+ * @returns {JSONSchema} An schema object that always evaluates to false.
57
+ */
58
+ export declare function never(): JSONSchema;
50
59
  /**
51
60
  *
52
61
  * Generate conditional rules for user.
@@ -61,6 +70,10 @@ export declare const user: {
61
70
  export declare const event: {
62
71
  hasAction: (action: ActionType) => JSONSchema;
63
72
  };
73
+ type FieldReference = {
74
+ _fieldId: string;
75
+ [key: string]: unknown;
76
+ };
64
77
  /**
65
78
  * Generate conditional rules for a form field.
66
79
  *
@@ -70,12 +83,16 @@ export declare const event: {
70
83
  *
71
84
  */
72
85
  export declare function field(fieldId: string): {
86
+ /**
87
+ * @private Internal property used for field reference tracking.
88
+ */
89
+ _fieldId: string;
73
90
  isAfter: () => {
74
91
  days: (days: number) => {
75
92
  inPast: () => JSONSchema;
76
93
  inFuture: () => JSONSchema;
77
94
  };
78
- date: (date: string) => JSONSchema;
95
+ date: (date: string | FieldReference) => JSONSchema;
79
96
  now: () => JSONSchema;
80
97
  };
81
98
  isBefore: () => {
@@ -83,10 +100,10 @@ export declare function field(fieldId: string): {
83
100
  inPast: () => JSONSchema;
84
101
  inFuture: () => JSONSchema;
85
102
  };
86
- date: (date: string) => JSONSchema;
103
+ date: (date: string | FieldReference) => JSONSchema;
87
104
  now: () => JSONSchema;
88
105
  };
89
- isEqualTo: (value: string | boolean) => JSONSchema;
106
+ isEqualTo: (value: string | boolean | FieldReference) => JSONSchema;
90
107
  /**
91
108
  * Use case: Some fields are rendered when selection is not made, or boolean false is explicitly selected.
92
109
  * @example field('recommender.none').isFalsy() vs not(field('recommender.none').isEqualTo(true))
@@ -98,6 +115,77 @@ export declare function field(fieldId: string): {
98
115
  isFalsy: () => JSONSchema;
99
116
  isUndefined: () => JSONSchema;
100
117
  inArray: (values: string[]) => JSONSchema;
118
+ isValidEnglishName: () => JSONSchema;
119
+ /**
120
+ * Checks if the field value matches a given regular expression pattern.
121
+ * @param pattern - The regular expression pattern to match the field value against.
122
+ * @returns A JSONSchema conditional that validates the field value against the pattern.
123
+ */
124
+ matches: (pattern: string) => JSONSchema;
125
+ isBetween: (min: number, max: number) => JSONSchema;
126
+ /**
127
+ * Creates a range configuration for the specified field.
128
+ *
129
+ * @returns An object containing the field ID and a configuration object with a type of 'RANGE'.
130
+ *
131
+ * @example field('age').range()
132
+ * // {
133
+ * // fieldId: 'age',
134
+ * // config: { type: 'RANGE' }
135
+ * // }
136
+ */
137
+ range: () => {
138
+ fieldId: string;
139
+ config: {
140
+ type: "RANGE";
141
+ };
142
+ };
143
+ /**
144
+ * Creates a configuration for exact matching of the specified field.
145
+ * @returns An object containing the field ID and a configuration object with a type of 'EXACT'.
146
+ * @example field('dob').exact()
147
+ * // {
148
+ * // fieldId: 'dob',
149
+ * // config: { type: 'EXACT' }
150
+ * // }
151
+ */
152
+ exact: () => {
153
+ fieldId: string;
154
+ config: {
155
+ type: "EXACT";
156
+ };
157
+ };
158
+ /**
159
+ * Creates a configuration for fuzzy matching of the specified field.
160
+ * @returns An object containing the field ID and a configuration object with a type of 'EXACT'.
161
+ * @example field('name').fuzzy()
162
+ * // {
163
+ * // fieldId: 'name',
164
+ * // config: { type: 'FUZZY' }
165
+ * // }
166
+ */
167
+ fuzzy: () => {
168
+ fieldId: string;
169
+ config: {
170
+ type: "FUZZY";
171
+ };
172
+ };
173
+ };
174
+ /**
175
+ * @param fieldId - The field ID condition is applied to.
176
+ * @param options - The options for the select field.
177
+ * @returns An object containing the configuration for the searching the metadata fields of an event.
178
+ * @example eventField('status', [{ label: 'Option 1', value: '1' }])
179
+ */
180
+ export declare function eventField(fieldId: MetadataField, options?: SelectOption[]): {
181
+ fieldId: "status" | "trackingId";
182
+ options: {
183
+ value: string;
184
+ label: import("..").TranslationConfig;
185
+ }[] | undefined;
186
+ config: {
187
+ type: "EXACT";
188
+ };
101
189
  };
102
190
  export {};
103
191
  //# sourceMappingURL=conditionals.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=validate-address.test.d.ts.map
@@ -6,6 +6,34 @@ import { TranslationConfig } from '../events/TranslationConfig';
6
6
  export declare function validate(schema: JSONSchema, data: ConditionalParameters): boolean;
7
7
  export declare function isFieldVisible(field: FieldConfig, form: ActionUpdate | EventState): boolean;
8
8
  export declare function isFieldEnabled(field: FieldConfig, form: ActionUpdate | EventState): boolean;
9
+ export declare function isFieldDisplayedOnReview(field: FieldConfig, form: ActionUpdate | EventState): boolean;
10
+ export declare const errorMessages: {
11
+ hiddenField: {
12
+ id: string;
13
+ defaultMessage: string;
14
+ description: string;
15
+ };
16
+ invalidDate: {
17
+ defaultMessage: string;
18
+ description: string;
19
+ id: string;
20
+ };
21
+ invalidEmail: {
22
+ defaultMessage: string;
23
+ description: string;
24
+ id: string;
25
+ };
26
+ requiredField: {
27
+ defaultMessage: string;
28
+ description: string;
29
+ id: string;
30
+ };
31
+ invalidInput: {
32
+ defaultMessage: string;
33
+ description: string;
34
+ id: string;
35
+ };
36
+ };
9
37
  /**
10
38
  * Custom error map for Zod to override the default error messages in intl-formik format.
11
39
  */
@@ -16,23 +44,6 @@ export type CustomZodToIntlErrorMap = {
16
44
  message: TranslationConfig;
17
45
  };
18
46
  };
19
- /**
20
- * Checks if a field has validation errors based on its type and custom conditionals.
21
- *
22
- * @returns an array of error messages for the field
23
- */
24
- export declare function getFieldValidationErrors({ field, values }: {
25
- field: FieldConfig;
26
- values: ActionUpdate;
27
- }): {
28
- errors: {
29
- message: {
30
- id: string;
31
- defaultMessage: string;
32
- description: string;
33
- };
34
- }[];
35
- };
36
47
  /**
37
48
  * Validates primitive fields defined by the FieldConfig type.
38
49
  * e.g. email is proper format, date is a valid date, etc.
@@ -44,4 +55,17 @@ export declare function validateFieldInput({ field, value }: {
44
55
  }): {
45
56
  message: TranslationConfig;
46
57
  }[];
58
+ /**
59
+ * Gets applicable validation errors based on its type and custom validators.
60
+ *
61
+ * @returns an array of error messages for the field
62
+ */
63
+ export declare function getFieldValidationErrors({ field, values }: {
64
+ field: FieldConfig;
65
+ values: ActionUpdate;
66
+ }): {
67
+ errors: {
68
+ message: TranslationConfig;
69
+ }[];
70
+ };
47
71
  //# sourceMappingURL=validate.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=validate.test.d.ts.map