@ecrvs/opencrvs-toolkit 1.8.1-rc.fb8610c → 1.9.0-rc.d21dcd8

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 (33) hide show
  1. package/dist/commons/api/router.d.ts +15651 -3988
  2. package/dist/commons/conditionals/conditionals.d.ts +184 -31
  3. package/dist/commons/conditionals/ill-defined.d.ts +2 -0
  4. package/dist/commons/conditionals/validate.d.ts +21 -54
  5. package/dist/commons/events/ActionConfig.d.ts +96 -549
  6. package/dist/commons/events/ActionDocument.d.ts +23760 -5269
  7. package/dist/commons/events/ActionInput.d.ts +18368 -3952
  8. package/dist/commons/events/ActionType.d.ts +3 -3
  9. package/dist/commons/events/AdvancedSearchConfig.d.ts +441 -9
  10. package/dist/commons/events/CompositeFieldValue.d.ts +19 -0
  11. package/dist/commons/events/CountryConfigQueryInput.d.ts +308 -308
  12. package/dist/commons/events/Draft.d.ts +1111 -103
  13. package/dist/commons/events/EventConfig.d.ts +41 -393
  14. package/dist/commons/events/EventDocument.d.ts +12855 -2663
  15. package/dist/commons/events/EventIndex.d.ts +233 -5
  16. package/dist/commons/events/FieldConfig.d.ts +5692 -1218
  17. package/dist/commons/events/FieldType.d.ts +10 -3
  18. package/dist/commons/events/FieldTypeMapping.d.ts +421 -12
  19. package/dist/commons/events/FieldValue.d.ts +433 -10
  20. package/dist/commons/events/WorkqueueConfig.d.ts +484 -484
  21. package/dist/commons/events/defineConfig.d.ts +6 -94
  22. package/dist/commons/events/field.d.ts +176 -24
  23. package/dist/commons/events/index.d.ts +0 -1
  24. package/dist/commons/events/state/index.d.ts +52 -3
  25. package/dist/commons/events/state/utils.d.ts +1579 -219
  26. package/dist/commons/events/test.utils.d.ts +800 -39
  27. package/dist/commons/events/utils.d.ts +114 -104
  28. package/dist/commons/notification/UserNotifications.d.ts +130 -0
  29. package/dist/conditionals/index.js +291 -170
  30. package/dist/events/index.js +1329 -650
  31. package/dist/notification/index.js +1085 -501
  32. package/package.json +2 -2
  33. package/dist/commons/events/User.d.ts +0 -45
@@ -11,20 +11,18 @@ export type JSONSchema = {
11
11
  };
12
12
  export declare function defineConditional(schema: any): JSONSchema;
13
13
  export declare function defineFormConditional(schema: Record<string, unknown>): JSONSchema;
14
- export type UserConditionalParameters = {
14
+ type CommonConditionalParameters = {
15
15
  $now: string;
16
16
  $online: boolean;
17
+ };
18
+ export type UserConditionalParameters = CommonConditionalParameters & {
17
19
  $user: TokenPayload;
18
20
  };
19
- export type EventConditionalParameters = {
20
- $now: string;
21
- $online: boolean;
21
+ export type EventConditionalParameters = CommonConditionalParameters & {
22
22
  $event: EventDocument;
23
23
  };
24
- export type FormConditionalParameters = {
25
- $now: string;
26
- $online: boolean;
27
- $form: EventState | Record<string, any>;
24
+ export type FormConditionalParameters = CommonConditionalParameters & {
25
+ $form: EventState | Record<string, unknown>;
28
26
  $locations?: Array<{
29
27
  id: UUID;
30
28
  }>;
@@ -62,12 +60,17 @@ export declare function not(condition: AjvJSONSchema): JSONSchema;
62
60
  * @returns {JSONSchema} An schema object that always evaluates to false.
63
61
  */
64
62
  export declare function never(): JSONSchema;
63
+ type FieldReference = {
64
+ $$field: string;
65
+ $$subfield: string[];
66
+ };
65
67
  /**
66
68
  *
67
69
  * Generate conditional rules for user.
68
70
  */
69
71
  export declare const user: typeof userSerializer & {
70
72
  hasScope: (scope: Scope) => JSONSchema;
73
+ hasRole: (role: string) => JSONSchema;
71
74
  isOnline: () => JSONSchema;
72
75
  locationLevel: (adminLevelId: string) => {
73
76
  $user: {
@@ -75,9 +78,7 @@ export declare const user: typeof userSerializer & {
75
78
  };
76
79
  };
77
80
  };
78
- type FieldReference = {
79
- $$field: string;
80
- };
81
+ export declare function isFieldReference(value: unknown): value is FieldReference;
81
82
  /**
82
83
  * Generate conditional rules for a form field.
83
84
  *
@@ -102,7 +103,139 @@ export declare function createFieldConditionals(fieldId: string): {
102
103
  */
103
104
  $$field: string;
104
105
  get(fieldPath: string): any;
105
- isAfter: () => {
106
+ asDob(): any;
107
+ asAge(): any;
108
+ isAfter(): {
109
+ days: (days: number) => {
110
+ inPast: () => JSONSchema;
111
+ inFuture: () => JSONSchema;
112
+ };
113
+ date: (date: string | FieldReference) => JSONSchema;
114
+ now: () => JSONSchema;
115
+ };
116
+ isBefore(): {
117
+ days: (days: number) => {
118
+ inPast: () => JSONSchema;
119
+ inFuture: () => JSONSchema;
120
+ };
121
+ date: (date: `${string}-${string}-${string}` | FieldReference) => JSONSchema;
122
+ now: () => JSONSchema;
123
+ };
124
+ isGreaterThan(value: number | FieldReference): JSONSchema;
125
+ isLessThan(value: number | FieldReference): JSONSchema;
126
+ isEqualTo(value: string | boolean | number | FieldReference): JSONSchema;
127
+ isEqualToSumOf(val1: FieldReference, val2: FieldReference): JSONSchema;
128
+ isAbbreviation(): JSONSchema;
129
+ isIllDefined(causesOfDeathFields: FieldReference[], threshold: number): JSONSchema;
130
+ /**
131
+ * Use case: Some fields are rendered when selection is not made, or boolean false is explicitly selected.
132
+ * @example field('recommender.none').isFalsy() vs not(field('recommender.none').isEqualTo(true))
133
+ * @returns whether the field is falsy (undefined, false, null, empty string)
134
+ *
135
+ * NOTE: For now, this only works with string, boolean, and null types. 0 is still allowed.
136
+ *
137
+ */
138
+ isFalsy(): JSONSchema;
139
+ isUndefined(): JSONSchema;
140
+ inArray(values: string[]): JSONSchema;
141
+ isValidEnglishName(isRequiredField?: boolean): JSONSchema;
142
+ isValidAdministrativeLeafLevel(): JSONSchema;
143
+ /**
144
+ * Checks if the field value matches a given regular expression pattern.
145
+ * @param pattern - The regular expression pattern to match the field value against.
146
+ * @returns A JSONSchema conditional that validates the field value against the pattern.
147
+ */
148
+ matches(pattern: string): JSONSchema;
149
+ isBetween(min: number, max: number): JSONSchema;
150
+ getId: () => {
151
+ fieldId: string;
152
+ };
153
+ /**
154
+ * @deprecated
155
+ * use field(fieldId).get(nestedProperty) instead
156
+ * with 'and' combinator e.g.
157
+ * and(
158
+ * field('child.name').get('firstname').isEqualTo('John'),
159
+ * field('child.name').get('surname').isEqualTo('Doe')
160
+ * )
161
+ */
162
+ object: (options: Record<string, any>) => JSONSchema;
163
+ };
164
+ asDob(): {
165
+ $$subfield: string[];
166
+ /**
167
+ * @private Internal property used for field reference tracking.
168
+ */
169
+ $$field: string;
170
+ get(fieldPath: string): any;
171
+ asDob(): any;
172
+ asAge(): any;
173
+ isAfter(): {
174
+ days: (days: number) => {
175
+ inPast: () => JSONSchema;
176
+ inFuture: () => JSONSchema;
177
+ };
178
+ date: (date: string | FieldReference) => JSONSchema;
179
+ now: () => JSONSchema;
180
+ };
181
+ isBefore(): {
182
+ days: (days: number) => {
183
+ inPast: () => JSONSchema;
184
+ inFuture: () => JSONSchema;
185
+ };
186
+ date: (date: `${string}-${string}-${string}` | FieldReference) => JSONSchema;
187
+ now: () => JSONSchema;
188
+ };
189
+ isGreaterThan(value: number | FieldReference): JSONSchema;
190
+ isLessThan(value: number | FieldReference): JSONSchema;
191
+ isEqualTo(value: string | boolean | number | FieldReference): JSONSchema;
192
+ isEqualToSumOf(val1: FieldReference, val2: FieldReference): JSONSchema;
193
+ isAbbreviation(): JSONSchema;
194
+ isIllDefined(causesOfDeathFields: FieldReference[], threshold: number): JSONSchema;
195
+ /**
196
+ * Use case: Some fields are rendered when selection is not made, or boolean false is explicitly selected.
197
+ * @example field('recommender.none').isFalsy() vs not(field('recommender.none').isEqualTo(true))
198
+ * @returns whether the field is falsy (undefined, false, null, empty string)
199
+ *
200
+ * NOTE: For now, this only works with string, boolean, and null types. 0 is still allowed.
201
+ *
202
+ */
203
+ isFalsy(): JSONSchema;
204
+ isUndefined(): JSONSchema;
205
+ inArray(values: string[]): JSONSchema;
206
+ isValidEnglishName(isRequiredField?: boolean): JSONSchema;
207
+ isValidAdministrativeLeafLevel(): JSONSchema;
208
+ /**
209
+ * Checks if the field value matches a given regular expression pattern.
210
+ * @param pattern - The regular expression pattern to match the field value against.
211
+ * @returns A JSONSchema conditional that validates the field value against the pattern.
212
+ */
213
+ matches(pattern: string): JSONSchema;
214
+ isBetween(min: number, max: number): JSONSchema;
215
+ getId: () => {
216
+ fieldId: string;
217
+ };
218
+ /**
219
+ * @deprecated
220
+ * use field(fieldId).get(nestedProperty) instead
221
+ * with 'and' combinator e.g.
222
+ * and(
223
+ * field('child.name').get('firstname').isEqualTo('John'),
224
+ * field('child.name').get('surname').isEqualTo('Doe')
225
+ * )
226
+ */
227
+ object: (options: Record<string, any>) => JSONSchema;
228
+ };
229
+ asAge(): {
230
+ $$subfield: string[];
231
+ /**
232
+ * @private Internal property used for field reference tracking.
233
+ */
234
+ $$field: string;
235
+ get(fieldPath: string): any;
236
+ asDob(): any;
237
+ asAge(): any;
238
+ isAfter(): {
106
239
  days: (days: number) => {
107
240
  inPast: () => JSONSchema;
108
241
  inFuture: () => JSONSchema;
@@ -110,7 +243,7 @@ export declare function createFieldConditionals(fieldId: string): {
110
243
  date: (date: string | FieldReference) => JSONSchema;
111
244
  now: () => JSONSchema;
112
245
  };
113
- isBefore: () => {
246
+ isBefore(): {
114
247
  days: (days: number) => {
115
248
  inPast: () => JSONSchema;
116
249
  inFuture: () => JSONSchema;
@@ -118,11 +251,12 @@ export declare function createFieldConditionals(fieldId: string): {
118
251
  date: (date: `${string}-${string}-${string}` | FieldReference) => JSONSchema;
119
252
  now: () => JSONSchema;
120
253
  };
121
- isGreaterThan: (value: number | FieldReference) => JSONSchema;
122
- isLessThan: (value: number | FieldReference) => JSONSchema;
123
- isEqualTo(value: string | boolean | FieldReference): JSONSchema;
254
+ isGreaterThan(value: number | FieldReference): JSONSchema;
255
+ isLessThan(value: number | FieldReference): JSONSchema;
256
+ isEqualTo(value: string | boolean | number | FieldReference): JSONSchema;
124
257
  isEqualToSumOf(val1: FieldReference, val2: FieldReference): JSONSchema;
125
258
  isAbbreviation(): JSONSchema;
259
+ isIllDefined(causesOfDeathFields: FieldReference[], threshold: number): JSONSchema;
126
260
  /**
127
261
  * Use case: Some fields are rendered when selection is not made, or boolean false is explicitly selected.
128
262
  * @example field('recommender.none').isFalsy() vs not(field('recommender.none').isEqualTo(true))
@@ -133,22 +267,31 @@ export declare function createFieldConditionals(fieldId: string): {
133
267
  */
134
268
  isFalsy(): JSONSchema;
135
269
  isUndefined(): JSONSchema;
136
- inArray: (values: string[]) => JSONSchema;
137
- isValidEnglishName: () => JSONSchema;
138
- isValidAdministrativeLeafLevel: () => JSONSchema;
270
+ inArray(values: string[]): JSONSchema;
271
+ isValidEnglishName(isRequiredField?: boolean): JSONSchema;
272
+ isValidAdministrativeLeafLevel(): JSONSchema;
139
273
  /**
140
274
  * Checks if the field value matches a given regular expression pattern.
141
275
  * @param pattern - The regular expression pattern to match the field value against.
142
276
  * @returns A JSONSchema conditional that validates the field value against the pattern.
143
277
  */
144
- matches: (pattern: string) => JSONSchema;
145
- isBetween: (min: number, max: number) => JSONSchema;
278
+ matches(pattern: string): JSONSchema;
279
+ isBetween(min: number, max: number): JSONSchema;
146
280
  getId: () => {
147
281
  fieldId: string;
148
282
  };
283
+ /**
284
+ * @deprecated
285
+ * use field(fieldId).get(nestedProperty) instead
286
+ * with 'and' combinator e.g.
287
+ * and(
288
+ * field('child.name').get('firstname').isEqualTo('John'),
289
+ * field('child.name').get('surname').isEqualTo('Doe')
290
+ * )
291
+ */
149
292
  object: (options: Record<string, any>) => JSONSchema;
150
293
  };
151
- isAfter: () => {
294
+ isAfter(): {
152
295
  days: (days: number) => {
153
296
  inPast: () => JSONSchema;
154
297
  inFuture: () => JSONSchema;
@@ -156,7 +299,7 @@ export declare function createFieldConditionals(fieldId: string): {
156
299
  date: (date: string | FieldReference) => JSONSchema;
157
300
  now: () => JSONSchema;
158
301
  };
159
- isBefore: () => {
302
+ isBefore(): {
160
303
  days: (days: number) => {
161
304
  inPast: () => JSONSchema;
162
305
  inFuture: () => JSONSchema;
@@ -164,11 +307,12 @@ export declare function createFieldConditionals(fieldId: string): {
164
307
  date: (date: `${string}-${string}-${string}` | FieldReference) => JSONSchema;
165
308
  now: () => JSONSchema;
166
309
  };
167
- isGreaterThan: (value: number | FieldReference) => JSONSchema;
168
- isLessThan: (value: number | FieldReference) => JSONSchema;
169
- isEqualTo(value: string | boolean | FieldReference): JSONSchema;
310
+ isGreaterThan(value: number | FieldReference): JSONSchema;
311
+ isLessThan(value: number | FieldReference): JSONSchema;
312
+ isEqualTo(value: string | boolean | number | FieldReference): JSONSchema;
170
313
  isEqualToSumOf(val1: FieldReference, val2: FieldReference): JSONSchema;
171
314
  isAbbreviation(): JSONSchema;
315
+ isIllDefined(causesOfDeathFields: FieldReference[], threshold: number): JSONSchema;
172
316
  /**
173
317
  * Use case: Some fields are rendered when selection is not made, or boolean false is explicitly selected.
174
318
  * @example field('recommender.none').isFalsy() vs not(field('recommender.none').isEqualTo(true))
@@ -179,19 +323,28 @@ export declare function createFieldConditionals(fieldId: string): {
179
323
  */
180
324
  isFalsy(): JSONSchema;
181
325
  isUndefined(): JSONSchema;
182
- inArray: (values: string[]) => JSONSchema;
183
- isValidEnglishName: () => JSONSchema;
184
- isValidAdministrativeLeafLevel: () => JSONSchema;
326
+ inArray(values: string[]): JSONSchema;
327
+ isValidEnglishName(isRequiredField?: boolean): JSONSchema;
328
+ isValidAdministrativeLeafLevel(): JSONSchema;
185
329
  /**
186
330
  * Checks if the field value matches a given regular expression pattern.
187
331
  * @param pattern - The regular expression pattern to match the field value against.
188
332
  * @returns A JSONSchema conditional that validates the field value against the pattern.
189
333
  */
190
- matches: (pattern: string) => JSONSchema;
191
- isBetween: (min: number, max: number) => JSONSchema;
334
+ matches(pattern: string): JSONSchema;
335
+ isBetween(min: number, max: number): JSONSchema;
192
336
  getId: () => {
193
337
  fieldId: string;
194
338
  };
339
+ /**
340
+ * @deprecated
341
+ * use field(fieldId).get(nestedProperty) instead
342
+ * with 'and' combinator e.g.
343
+ * and(
344
+ * field('child.name').get('firstname').isEqualTo('John'),
345
+ * field('child.name').get('surname').isEqualTo('Doe')
346
+ * )
347
+ */
195
348
  object: (options: Record<string, any>) => JSONSchema;
196
349
  };
197
350
  export {};
@@ -0,0 +1,2 @@
1
+ export declare const illDefinedConditions: string[];
2
+ //# sourceMappingURL=ill-defined.d.ts.map
@@ -2,49 +2,23 @@ import { ConditionalParameters, JSONSchema } from './conditionals';
2
2
  import { ActionUpdate, EventState } from '../events/ActionDocument';
3
3
  import { FieldConditional } from '../events/Conditional';
4
4
  import { FieldConfig } from '../events/FieldConfig';
5
- import { FieldUpdateValue } from '../events/FieldValue';
5
+ import { FieldUpdateValue, FieldValue } from '../events/FieldValue';
6
6
  import { TranslationConfig } from '../events/TranslationConfig';
7
+ import { ITokenPayload } from '../authentication';
7
8
  import { UUID } from '../uuid';
8
9
  export declare function validate(schema: JSONSchema, data: ConditionalParameters): boolean;
9
10
  export declare function isOnline(): boolean;
10
- export declare function isConditionMet(conditional: JSONSchema, values: Record<string, unknown>): boolean;
11
- export declare function areConditionsMet(conditions: FieldConditional[], values: Record<string, unknown>): boolean;
12
- export declare function isFieldVisible(field: FieldConfig, form: ActionUpdate | EventState): boolean;
13
- export declare function getOnlyVisibleFormValues(field: FieldConfig[], form: EventState): Record<string, string | number | boolean | {
14
- type: string;
15
- path: string;
16
- originalFilename: string;
17
- } | {
18
- firstname: string;
19
- surname: string;
20
- middlename?: string | undefined;
21
- } | {
22
- firstname: string;
23
- surname: string;
24
- middlename?: string | null | undefined;
25
- } | Record<string, string> | {
26
- country: string;
27
- addressType: "DOMESTIC" | "INTERNATIONAL";
28
- administrativeArea?: string | undefined;
29
- streetLevelDetails?: Record<string, string> | undefined;
30
- } | {
31
- type: string;
32
- option: string;
33
- path: string;
34
- originalFilename: string;
35
- }[] | {
36
- loading: boolean;
37
- data?: any;
38
- error?: {
39
- message: string;
40
- statusCode: number;
41
- } | null | undefined;
42
- } | {
43
- start: string;
44
- end: string;
45
- } | null | undefined>;
46
- export declare function isFieldEnabled(field: FieldConfig, form: ActionUpdate | EventState): boolean;
47
- export declare function isFieldDisplayedOnReview(field: FieldConfig, form: ActionUpdate | EventState): boolean;
11
+ export declare function isConditionMet(conditional: JSONSchema, values: Record<string, FieldValue>, context: ValidatorContext): boolean;
12
+ export declare function areConditionsMet(conditions: FieldConditional[], values: Record<string, FieldValue>, context: ValidatorContext): boolean;
13
+ export type ValidatorContext = {
14
+ user?: ITokenPayload;
15
+ leafAdminStructureLocationIds?: Array<{
16
+ id: UUID;
17
+ }>;
18
+ };
19
+ export declare function isFieldVisible(field: FieldConfig, form: ActionUpdate | EventState, context: ValidatorContext): boolean;
20
+ export declare function isFieldEnabled(field: FieldConfig, form: ActionUpdate | EventState, context: ValidatorContext): boolean;
21
+ export declare function isFieldDisplayedOnReview(field: FieldConfig, form: ActionUpdate | EventState, context: ValidatorContext): boolean;
48
22
  export declare const errorMessages: {
49
23
  hiddenField: {
50
24
  id: string;
@@ -103,27 +77,20 @@ export declare function validateFieldInput({ field, value }: {
103
77
  }): {
104
78
  message: TranslationConfig;
105
79
  }[];
106
- export declare function runStructuralValidations({ field, values }: {
80
+ export declare function runStructuralValidations({ field, values, context }: {
107
81
  field: FieldConfig;
108
82
  values: ActionUpdate;
83
+ context: ValidatorContext;
109
84
  }): {
110
- errors: {
111
- message: TranslationConfig;
112
- }[];
113
- };
85
+ message: TranslationConfig;
86
+ }[];
114
87
  export declare function runFieldValidations({ field, values, context }: {
115
88
  field: FieldConfig;
116
89
  values: ActionUpdate;
117
- context?: {
118
- leafAdminStructureLocationIds: Array<{
119
- id: UUID;
120
- }>;
121
- };
90
+ context: ValidatorContext;
122
91
  }): {
123
- errors: {
124
- message: TranslationConfig;
125
- }[];
126
- };
92
+ message: TranslationConfig;
93
+ }[];
127
94
  export declare function getValidatorsForField(fieldId: FieldConfig['id'], validations: NonNullable<FieldConfig['validation']>): NonNullable<FieldConfig['validation']>;
128
- export declare function areCertificateConditionsMet(conditions: FieldConditional[], values: Record<string, unknown>): boolean;
95
+ export declare function areCertificateConditionsMet(conditions: FieldConditional[], values: ConditionalParameters): boolean;
129
96
  //# sourceMappingURL=validate.d.ts.map