@ecrvs/opencrvs-toolkit 1.8.1-rc.b48c48d → 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 (34) hide show
  1. package/dist/commons/api/router.d.ts +15651 -3988
  2. package/dist/commons/conditionals/abbreviation.d.ts +5 -0
  3. package/dist/commons/conditionals/conditionals.d.ts +186 -33
  4. package/dist/commons/conditionals/ill-defined.d.ts +2 -0
  5. package/dist/commons/conditionals/validate.d.ts +21 -54
  6. package/dist/commons/events/ActionConfig.d.ts +96 -549
  7. package/dist/commons/events/ActionDocument.d.ts +23760 -5269
  8. package/dist/commons/events/ActionInput.d.ts +18368 -3952
  9. package/dist/commons/events/ActionType.d.ts +3 -3
  10. package/dist/commons/events/AdvancedSearchConfig.d.ts +441 -9
  11. package/dist/commons/events/CompositeFieldValue.d.ts +19 -0
  12. package/dist/commons/events/CountryConfigQueryInput.d.ts +308 -308
  13. package/dist/commons/events/Draft.d.ts +1111 -103
  14. package/dist/commons/events/EventConfig.d.ts +41 -393
  15. package/dist/commons/events/EventDocument.d.ts +12855 -2663
  16. package/dist/commons/events/EventIndex.d.ts +233 -5
  17. package/dist/commons/events/FieldConfig.d.ts +5692 -1218
  18. package/dist/commons/events/FieldType.d.ts +10 -3
  19. package/dist/commons/events/FieldTypeMapping.d.ts +421 -12
  20. package/dist/commons/events/FieldValue.d.ts +433 -10
  21. package/dist/commons/events/WorkqueueConfig.d.ts +484 -484
  22. package/dist/commons/events/defineConfig.d.ts +6 -94
  23. package/dist/commons/events/field.d.ts +175 -27
  24. package/dist/commons/events/index.d.ts +0 -1
  25. package/dist/commons/events/state/index.d.ts +52 -3
  26. package/dist/commons/events/state/utils.d.ts +1579 -219
  27. package/dist/commons/events/test.utils.d.ts +800 -39
  28. package/dist/commons/events/utils.d.ts +114 -104
  29. package/dist/commons/notification/UserNotifications.d.ts +130 -0
  30. package/dist/conditionals/index.js +298 -192
  31. package/dist/events/index.js +2360 -755
  32. package/dist/notification/index.js +2128 -618
  33. package/package.json +2 -2
  34. package/dist/commons/events/User.d.ts +0 -45
@@ -0,0 +1,5 @@
1
+ export declare const medicalAbbreviations: {
2
+ code: string;
3
+ label: string;
4
+ }[];
5
+ //# sourceMappingURL=abbreviation.d.ts.map
@@ -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,74 @@ 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(): {
106
174
  days: (days: number) => {
107
175
  inPast: () => JSONSchema;
108
176
  inFuture: () => JSONSchema;
@@ -110,7 +178,7 @@ export declare function createFieldConditionals(fieldId: string): {
110
178
  date: (date: string | FieldReference) => JSONSchema;
111
179
  now: () => JSONSchema;
112
180
  };
113
- isBefore: () => {
181
+ isBefore(): {
114
182
  days: (days: number) => {
115
183
  inPast: () => JSONSchema;
116
184
  inFuture: () => JSONSchema;
@@ -118,11 +186,12 @@ export declare function createFieldConditionals(fieldId: string): {
118
186
  date: (date: `${string}-${string}-${string}` | FieldReference) => JSONSchema;
119
187
  now: () => JSONSchema;
120
188
  };
121
- isGreaterThan: (value: number | FieldReference) => JSONSchema;
122
- isLessThan: (value: number | FieldReference) => JSONSchema;
123
- isEqualTo(value: string | boolean | FieldReference): JSONSchema;
189
+ isGreaterThan(value: number | FieldReference): JSONSchema;
190
+ isLessThan(value: number | FieldReference): JSONSchema;
191
+ isEqualTo(value: string | boolean | number | FieldReference): JSONSchema;
124
192
  isEqualToSumOf(val1: FieldReference, val2: FieldReference): JSONSchema;
125
- isGreaterThanOrEqualTo(value: number | string | FieldReference): JSONSchema;
193
+ isAbbreviation(): JSONSchema;
194
+ isIllDefined(causesOfDeathFields: FieldReference[], threshold: number): JSONSchema;
126
195
  /**
127
196
  * Use case: Some fields are rendered when selection is not made, or boolean false is explicitly selected.
128
197
  * @example field('recommender.none').isFalsy() vs not(field('recommender.none').isEqualTo(true))
@@ -133,22 +202,96 @@ export declare function createFieldConditionals(fieldId: string): {
133
202
  */
134
203
  isFalsy(): JSONSchema;
135
204
  isUndefined(): JSONSchema;
136
- inArray: (values: string[]) => JSONSchema;
137
- isValidEnglishName: () => JSONSchema;
138
- isValidAdministrativeLeafLevel: () => JSONSchema;
205
+ inArray(values: string[]): JSONSchema;
206
+ isValidEnglishName(isRequiredField?: boolean): JSONSchema;
207
+ isValidAdministrativeLeafLevel(): JSONSchema;
139
208
  /**
140
209
  * Checks if the field value matches a given regular expression pattern.
141
210
  * @param pattern - The regular expression pattern to match the field value against.
142
211
  * @returns A JSONSchema conditional that validates the field value against the pattern.
143
212
  */
144
- matches: (pattern: string) => JSONSchema;
145
- isBetween: (min: number, max: number) => JSONSchema;
213
+ matches(pattern: string): JSONSchema;
214
+ isBetween(min: number, max: number): JSONSchema;
146
215
  getId: () => {
147
216
  fieldId: string;
148
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
+ */
149
227
  object: (options: Record<string, any>) => JSONSchema;
150
228
  };
151
- isAfter: () => {
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(): {
239
+ days: (days: number) => {
240
+ inPast: () => JSONSchema;
241
+ inFuture: () => JSONSchema;
242
+ };
243
+ date: (date: string | FieldReference) => JSONSchema;
244
+ now: () => JSONSchema;
245
+ };
246
+ isBefore(): {
247
+ days: (days: number) => {
248
+ inPast: () => JSONSchema;
249
+ inFuture: () => JSONSchema;
250
+ };
251
+ date: (date: `${string}-${string}-${string}` | FieldReference) => JSONSchema;
252
+ now: () => JSONSchema;
253
+ };
254
+ isGreaterThan(value: number | FieldReference): JSONSchema;
255
+ isLessThan(value: number | FieldReference): JSONSchema;
256
+ isEqualTo(value: string | boolean | number | FieldReference): JSONSchema;
257
+ isEqualToSumOf(val1: FieldReference, val2: FieldReference): JSONSchema;
258
+ isAbbreviation(): JSONSchema;
259
+ isIllDefined(causesOfDeathFields: FieldReference[], threshold: number): JSONSchema;
260
+ /**
261
+ * Use case: Some fields are rendered when selection is not made, or boolean false is explicitly selected.
262
+ * @example field('recommender.none').isFalsy() vs not(field('recommender.none').isEqualTo(true))
263
+ * @returns whether the field is falsy (undefined, false, null, empty string)
264
+ *
265
+ * NOTE: For now, this only works with string, boolean, and null types. 0 is still allowed.
266
+ *
267
+ */
268
+ isFalsy(): JSONSchema;
269
+ isUndefined(): JSONSchema;
270
+ inArray(values: string[]): JSONSchema;
271
+ isValidEnglishName(isRequiredField?: boolean): JSONSchema;
272
+ isValidAdministrativeLeafLevel(): JSONSchema;
273
+ /**
274
+ * Checks if the field value matches a given regular expression pattern.
275
+ * @param pattern - The regular expression pattern to match the field value against.
276
+ * @returns A JSONSchema conditional that validates the field value against the pattern.
277
+ */
278
+ matches(pattern: string): JSONSchema;
279
+ isBetween(min: number, max: number): JSONSchema;
280
+ getId: () => {
281
+ fieldId: string;
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
+ */
292
+ object: (options: Record<string, any>) => JSONSchema;
293
+ };
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
- isGreaterThanOrEqualTo(value: number | string | FieldReference): JSONSchema;
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