@opencrvs/toolkit 1.9.8-rc.0cafd28 → 1.9.8-rc.0cf339f

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 (59) hide show
  1. package/dist/commons/api/router.d.ts +31001 -2467
  2. package/dist/commons/conditionals/conditionals.d.ts +1037 -1
  3. package/dist/commons/conditionals/validate.d.ts +11 -4
  4. package/dist/commons/events/ActionConfig.d.ts +26853 -1552
  5. package/dist/commons/events/ActionDocument.d.ts +846 -1899
  6. package/dist/commons/events/ActionInput.d.ts +277 -1073
  7. package/dist/commons/events/ActionType.d.ts +86 -9
  8. package/dist/commons/events/AdvancedSearchConfig.d.ts +228 -1238
  9. package/dist/commons/events/CompositeFieldValue.d.ts +29 -190
  10. package/dist/commons/events/Conditional.d.ts +26 -38
  11. package/dist/commons/events/Constants.d.ts +1 -1
  12. package/dist/commons/events/CountryConfigQueryInput.d.ts +1195 -4223
  13. package/dist/commons/events/DeduplicationConfig.d.ts +15 -171
  14. package/dist/commons/events/Draft.d.ts +71 -106
  15. package/dist/commons/events/DynamicFieldValue.d.ts +7 -91
  16. package/dist/commons/events/EventConfig.d.ts +21436 -2120
  17. package/dist/commons/events/EventConfigInput.d.ts +1 -1
  18. package/dist/commons/events/EventDocument.d.ts +337 -1349
  19. package/dist/commons/events/EventIndex.d.ts +196 -983
  20. package/dist/commons/events/EventInput.d.ts +3 -8
  21. package/dist/commons/events/EventMetadata.d.ts +113 -354
  22. package/dist/commons/events/FieldConfig.d.ts +4974 -12346
  23. package/dist/commons/events/FieldType.d.ts +20 -4
  24. package/dist/commons/events/FieldTypeMapping.d.ts +193 -897
  25. package/dist/commons/events/FieldValue.d.ts +87 -396
  26. package/dist/commons/events/Flag.d.ts +67 -0
  27. package/dist/commons/events/FormConfig.d.ts +15108 -721
  28. package/dist/commons/events/PageConfig.d.ts +10092 -319
  29. package/dist/commons/events/SummaryConfig.d.ts +14 -161
  30. package/dist/commons/events/TemplateConfig.d.ts +2 -3
  31. package/dist/commons/events/TranslationConfig.d.ts +2 -2
  32. package/dist/commons/events/WorkqueueColumnConfig.d.ts +74 -37
  33. package/dist/commons/events/WorkqueueConfig.d.ts +1865 -7177
  34. package/dist/commons/events/deduplication.d.ts +3 -3
  35. package/dist/commons/events/defineConfig.d.ts +28019 -147
  36. package/dist/commons/events/eventConfigValidation.d.ts +8 -0
  37. package/dist/commons/events/field.d.ts +154 -0
  38. package/dist/commons/events/index.d.ts +1 -0
  39. package/dist/commons/events/locations.d.ts +26 -19
  40. package/dist/commons/events/scopes.d.ts +5 -4
  41. package/dist/commons/events/state/availableActions.d.ts +0 -2
  42. package/dist/commons/events/state/flags.d.ts +21 -3
  43. package/dist/commons/events/state/index.d.ts +24 -21
  44. package/dist/commons/events/state/utils.d.ts +150 -132
  45. package/dist/commons/events/test.utils.d.ts +31 -8
  46. package/dist/commons/events/transactions.d.ts +1 -1
  47. package/dist/commons/events/utils.d.ts +56079 -370
  48. package/dist/commons/notification/UserNotifications.d.ts +55 -636
  49. package/dist/conditionals/index.d.ts.map +1 -1
  50. package/dist/conditionals/index.js +155 -11
  51. package/dist/events/deduplication.d.ts +3 -3
  52. package/dist/events/index.js +2210 -1734
  53. package/dist/notification/index.d.ts.map +1 -1
  54. package/dist/notification/index.js +1802 -1571
  55. package/dist/scopes/index.d.ts +169 -133
  56. package/dist/scopes/index.d.ts.map +1 -1
  57. package/dist/scopes/index.js +135 -94
  58. package/package.json +5 -5
  59. package/dist/commons/events/CreatedAtLocation.d.ts +0 -2
@@ -5,6 +5,7 @@ import { PartialSchema as AjvJSONSchemaType } from 'ajv/dist/types/json-schema';
5
5
  import { userSerializer } from '../events/serializers/user/serializer';
6
6
  import { UUID } from '../uuid';
7
7
  import { todayDateTimeValueSerializer } from '../events/serializers/date/serializer';
8
+ import { EventStatus } from '../events/EventMetadata';
8
9
  /** @knipignore */
9
10
  export type JSONSchema = {
10
11
  $id: string;
@@ -28,7 +29,11 @@ export type FormConditionalParameters = CommonConditionalParameters & {
28
29
  id: UUID;
29
30
  }>;
30
31
  };
31
- export type ConditionalParameters = UserConditionalParameters | EventConditionalParameters | FormConditionalParameters;
32
+ export type EventStateConditionalParameters = CommonConditionalParameters & {
33
+ $flags: string[];
34
+ $status: EventStatus;
35
+ };
36
+ export type ConditionalParameters = UserConditionalParameters | EventConditionalParameters | FormConditionalParameters | EventStateConditionalParameters;
32
37
  type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
33
38
  type AjvJSONSchema = AjvJSONSchemaType<UnionToIntersection<ConditionalParameters>>;
34
39
  /**
@@ -65,6 +70,9 @@ type FieldReference = {
65
70
  $$field: string;
66
71
  $$subfield: string[];
67
72
  };
73
+ type CodeToEvaluate = {
74
+ $$code: string;
75
+ };
68
76
  /**
69
77
  * Generate conditional rules for current date
70
78
  */
@@ -84,6 +92,11 @@ export declare const user: typeof userSerializer & {
84
92
  };
85
93
  };
86
94
  export declare function isFieldReference(value: unknown): value is FieldReference;
95
+ export declare function isCodeToEvaluate(value: unknown): value is CodeToEvaluate;
96
+ /** Check if an event flag is present */
97
+ export declare function flag(flagvalue: string): JSONSchema;
98
+ /** Check if an event flag is present */
99
+ export declare function status(statusValue: EventStatus): JSONSchema;
87
100
  /**
88
101
  * Generate conditional rules for a form field.
89
102
  *
@@ -161,6 +174,99 @@ export declare function createFieldConditionals(fieldId: string): {
161
174
  */
162
175
  matches(pattern: string): JSONSchema;
163
176
  isBetween(min: number, max: number): JSONSchema;
177
+ /**
178
+ * Executes a custom validation function defined by country configuration.
179
+ *
180
+ * **Use this as a last resort when predefined toolkit methods are insufficient.**
181
+ *
182
+ * The function is serialized via toString() and transmitted as part of the JSON Schema.
183
+ * It is deserialized just-in-time during validation on the client.
184
+ *
185
+ * @param fn - Validation function that receives the field value and form context.
186
+ * Must return true if valid, false if invalid.
187
+ *
188
+ * @returns JSONSchema conditional for AJV validation
189
+ *
190
+ * @example
191
+ * // Simple age validation
192
+ * field('age').customClientValidator((value, ctx) => {
193
+ * return value >= 18
194
+ * })
195
+ *
196
+ * @example
197
+ * // Cross-field validation: child DOB must be after mother DOB
198
+ * field('child.dob').customClientValidator((value, ctx) => {
199
+ * const motherDob = ctx.$form['mother.dob']
200
+ * if (!motherDob || !value) return false
201
+ * return new Date(value) > new Date(motherDob)
202
+ * })
203
+ *
204
+ * @example
205
+ * // Two number fields validated together
206
+ * field('fieldA').customClientValidator((value, ctx) => {
207
+ * const fieldB = ctx.$form['fieldB']
208
+ * if (!fieldB) return false
209
+ * return value + fieldB > 100
210
+ * })
211
+ *
212
+ * @remarks
213
+ * Limitations:
214
+ * - Client-side only. For backend validation, use country config event triggers.
215
+ * - Cannot reference external libraries (lodash, etc.)
216
+ * - Function must be pure — no side effects, no closures over external state
217
+ * - Function must be serialisable via toString()
218
+ * - Receives (value, context) parameters where context contains $form, $now, $online, etc.
219
+ * - Must return boolean: true = valid, false = invalid
220
+ *
221
+ * @see https://github.com/opencrvs/opencrvs-core/issues/11653
222
+ */
223
+ customClientValidator(fn: (value: unknown, context: CommonConditionalParameters & {
224
+ $form: EventState | Record<string, unknown>;
225
+ }) => boolean): JSONSchema;
226
+ /**
227
+ * Defines a client-side computation function for dynamic field values.
228
+ *
229
+ * **Use this as a last resort when predefined toolkit methods are insufficient.**
230
+ *
231
+ * The function is serialized via toString() and transmitted to the client,
232
+ * where it is deserialized and executed to compute field values dynamically.
233
+ *
234
+ * @param fn - Computation function that receives the field value and form context.
235
+ * Returns the computed value (any type).
236
+ *
237
+ * @returns CodeToEvaluate object for client-side execution
238
+ *
239
+ * @example
240
+ * // Concatenate first and last name
241
+ * field('fullName').customClientEvaluation((value, ctx) => {
242
+ * return `${ctx.$form.firstName} ${ctx.$form.lastName}`
243
+ * })
244
+ *
245
+ * @example
246
+ * // Calculate age from date of birth
247
+ * field('childAge').customClientEvaluation((value, ctx) => {
248
+ * const dob = ctx.$form['child.dob']
249
+ * if (!dob) return undefined
250
+ * const age = Math.floor((new Date(ctx.$now) - new Date(dob)) / (365.25 * 24 * 60 * 60 * 1000))
251
+ * return age
252
+ * })
253
+ *
254
+ * @remarks
255
+ * Limitations:
256
+ * - Client-side only. For backend computation, use country config event triggers.
257
+ * - Cannot reference external libraries (lodash, etc.)
258
+ * - Function must be pure — no side effects, no closures over external state
259
+ * - Function must be serialisable via toString()
260
+ * - Receives (value, context) parameters where context contains $form, $now, $online, etc.
261
+ * - Should return the computed value (any type)
262
+ *
263
+ * @see https://github.com/opencrvs/opencrvs-core/issues/11653
264
+ */
265
+ customClientEvaluation(fn: (value: unknown, context: CommonConditionalParameters & {
266
+ $form: EventState | Record<string, unknown>;
267
+ }) => any): {
268
+ $$code: string;
269
+ };
164
270
  getId: () => {
165
271
  fieldId: string;
166
272
  };
@@ -220,6 +326,99 @@ export declare function createFieldConditionals(fieldId: string): {
220
326
  */
221
327
  matches(pattern: string): JSONSchema;
222
328
  isBetween(min: number, max: number): JSONSchema;
329
+ /**
330
+ * Executes a custom validation function defined by country configuration.
331
+ *
332
+ * **Use this as a last resort when predefined toolkit methods are insufficient.**
333
+ *
334
+ * The function is serialized via toString() and transmitted as part of the JSON Schema.
335
+ * It is deserialized just-in-time during validation on the client.
336
+ *
337
+ * @param fn - Validation function that receives the field value and form context.
338
+ * Must return true if valid, false if invalid.
339
+ *
340
+ * @returns JSONSchema conditional for AJV validation
341
+ *
342
+ * @example
343
+ * // Simple age validation
344
+ * field('age').customClientValidator((value, ctx) => {
345
+ * return value >= 18
346
+ * })
347
+ *
348
+ * @example
349
+ * // Cross-field validation: child DOB must be after mother DOB
350
+ * field('child.dob').customClientValidator((value, ctx) => {
351
+ * const motherDob = ctx.$form['mother.dob']
352
+ * if (!motherDob || !value) return false
353
+ * return new Date(value) > new Date(motherDob)
354
+ * })
355
+ *
356
+ * @example
357
+ * // Two number fields validated together
358
+ * field('fieldA').customClientValidator((value, ctx) => {
359
+ * const fieldB = ctx.$form['fieldB']
360
+ * if (!fieldB) return false
361
+ * return value + fieldB > 100
362
+ * })
363
+ *
364
+ * @remarks
365
+ * Limitations:
366
+ * - Client-side only. For backend validation, use country config event triggers.
367
+ * - Cannot reference external libraries (lodash, etc.)
368
+ * - Function must be pure — no side effects, no closures over external state
369
+ * - Function must be serialisable via toString()
370
+ * - Receives (value, context) parameters where context contains $form, $now, $online, etc.
371
+ * - Must return boolean: true = valid, false = invalid
372
+ *
373
+ * @see https://github.com/opencrvs/opencrvs-core/issues/11653
374
+ */
375
+ customClientValidator(fn: (value: unknown, context: CommonConditionalParameters & {
376
+ $form: EventState | Record<string, unknown>;
377
+ }) => boolean): JSONSchema;
378
+ /**
379
+ * Defines a client-side computation function for dynamic field values.
380
+ *
381
+ * **Use this as a last resort when predefined toolkit methods are insufficient.**
382
+ *
383
+ * The function is serialized via toString() and transmitted to the client,
384
+ * where it is deserialized and executed to compute field values dynamically.
385
+ *
386
+ * @param fn - Computation function that receives the field value and form context.
387
+ * Returns the computed value (any type).
388
+ *
389
+ * @returns CodeToEvaluate object for client-side execution
390
+ *
391
+ * @example
392
+ * // Concatenate first and last name
393
+ * field('fullName').customClientEvaluation((value, ctx) => {
394
+ * return `${ctx.$form.firstName} ${ctx.$form.lastName}`
395
+ * })
396
+ *
397
+ * @example
398
+ * // Calculate age from date of birth
399
+ * field('childAge').customClientEvaluation((value, ctx) => {
400
+ * const dob = ctx.$form['child.dob']
401
+ * if (!dob) return undefined
402
+ * const age = Math.floor((new Date(ctx.$now) - new Date(dob)) / (365.25 * 24 * 60 * 60 * 1000))
403
+ * return age
404
+ * })
405
+ *
406
+ * @remarks
407
+ * Limitations:
408
+ * - Client-side only. For backend computation, use country config event triggers.
409
+ * - Cannot reference external libraries (lodash, etc.)
410
+ * - Function must be pure — no side effects, no closures over external state
411
+ * - Function must be serialisable via toString()
412
+ * - Receives (value, context) parameters where context contains $form, $now, $online, etc.
413
+ * - Should return the computed value (any type)
414
+ *
415
+ * @see https://github.com/opencrvs/opencrvs-core/issues/11653
416
+ */
417
+ customClientEvaluation(fn: (value: unknown, context: CommonConditionalParameters & {
418
+ $form: EventState | Record<string, unknown>;
419
+ }) => any): {
420
+ $$code: string;
421
+ };
223
422
  getId: () => {
224
423
  fieldId: string;
225
424
  };
@@ -293,6 +492,99 @@ export declare function createFieldConditionals(fieldId: string): {
293
492
  */
294
493
  matches(pattern: string): JSONSchema;
295
494
  isBetween(min: number, max: number): JSONSchema;
495
+ /**
496
+ * Executes a custom validation function defined by country configuration.
497
+ *
498
+ * **Use this as a last resort when predefined toolkit methods are insufficient.**
499
+ *
500
+ * The function is serialized via toString() and transmitted as part of the JSON Schema.
501
+ * It is deserialized just-in-time during validation on the client.
502
+ *
503
+ * @param fn - Validation function that receives the field value and form context.
504
+ * Must return true if valid, false if invalid.
505
+ *
506
+ * @returns JSONSchema conditional for AJV validation
507
+ *
508
+ * @example
509
+ * // Simple age validation
510
+ * field('age').customClientValidator((value, ctx) => {
511
+ * return value >= 18
512
+ * })
513
+ *
514
+ * @example
515
+ * // Cross-field validation: child DOB must be after mother DOB
516
+ * field('child.dob').customClientValidator((value, ctx) => {
517
+ * const motherDob = ctx.$form['mother.dob']
518
+ * if (!motherDob || !value) return false
519
+ * return new Date(value) > new Date(motherDob)
520
+ * })
521
+ *
522
+ * @example
523
+ * // Two number fields validated together
524
+ * field('fieldA').customClientValidator((value, ctx) => {
525
+ * const fieldB = ctx.$form['fieldB']
526
+ * if (!fieldB) return false
527
+ * return value + fieldB > 100
528
+ * })
529
+ *
530
+ * @remarks
531
+ * Limitations:
532
+ * - Client-side only. For backend validation, use country config event triggers.
533
+ * - Cannot reference external libraries (lodash, etc.)
534
+ * - Function must be pure — no side effects, no closures over external state
535
+ * - Function must be serialisable via toString()
536
+ * - Receives (value, context) parameters where context contains $form, $now, $online, etc.
537
+ * - Must return boolean: true = valid, false = invalid
538
+ *
539
+ * @see https://github.com/opencrvs/opencrvs-core/issues/11653
540
+ */
541
+ customClientValidator(fn: (value: unknown, context: CommonConditionalParameters & {
542
+ $form: EventState | Record<string, unknown>;
543
+ }) => boolean): JSONSchema;
544
+ /**
545
+ * Defines a client-side computation function for dynamic field values.
546
+ *
547
+ * **Use this as a last resort when predefined toolkit methods are insufficient.**
548
+ *
549
+ * The function is serialized via toString() and transmitted to the client,
550
+ * where it is deserialized and executed to compute field values dynamically.
551
+ *
552
+ * @param fn - Computation function that receives the field value and form context.
553
+ * Returns the computed value (any type).
554
+ *
555
+ * @returns CodeToEvaluate object for client-side execution
556
+ *
557
+ * @example
558
+ * // Concatenate first and last name
559
+ * field('fullName').customClientEvaluation((value, ctx) => {
560
+ * return `${ctx.$form.firstName} ${ctx.$form.lastName}`
561
+ * })
562
+ *
563
+ * @example
564
+ * // Calculate age from date of birth
565
+ * field('childAge').customClientEvaluation((value, ctx) => {
566
+ * const dob = ctx.$form['child.dob']
567
+ * if (!dob) return undefined
568
+ * const age = Math.floor((new Date(ctx.$now) - new Date(dob)) / (365.25 * 24 * 60 * 60 * 1000))
569
+ * return age
570
+ * })
571
+ *
572
+ * @remarks
573
+ * Limitations:
574
+ * - Client-side only. For backend computation, use country config event triggers.
575
+ * - Cannot reference external libraries (lodash, etc.)
576
+ * - Function must be pure — no side effects, no closures over external state
577
+ * - Function must be serialisable via toString()
578
+ * - Receives (value, context) parameters where context contains $form, $now, $online, etc.
579
+ * - Should return the computed value (any type)
580
+ *
581
+ * @see https://github.com/opencrvs/opencrvs-core/issues/11653
582
+ */
583
+ customClientEvaluation(fn: (value: unknown, context: CommonConditionalParameters & {
584
+ $form: EventState | Record<string, unknown>;
585
+ }) => any): {
586
+ $$code: string;
587
+ };
296
588
  getId: () => {
297
589
  fieldId: string;
298
590
  };
@@ -361,6 +653,99 @@ export declare function createFieldConditionals(fieldId: string): {
361
653
  */
362
654
  matches(pattern: string): JSONSchema;
363
655
  isBetween(min: number, max: number): JSONSchema;
656
+ /**
657
+ * Executes a custom validation function defined by country configuration.
658
+ *
659
+ * **Use this as a last resort when predefined toolkit methods are insufficient.**
660
+ *
661
+ * The function is serialized via toString() and transmitted as part of the JSON Schema.
662
+ * It is deserialized just-in-time during validation on the client.
663
+ *
664
+ * @param fn - Validation function that receives the field value and form context.
665
+ * Must return true if valid, false if invalid.
666
+ *
667
+ * @returns JSONSchema conditional for AJV validation
668
+ *
669
+ * @example
670
+ * // Simple age validation
671
+ * field('age').customClientValidator((value, ctx) => {
672
+ * return value >= 18
673
+ * })
674
+ *
675
+ * @example
676
+ * // Cross-field validation: child DOB must be after mother DOB
677
+ * field('child.dob').customClientValidator((value, ctx) => {
678
+ * const motherDob = ctx.$form['mother.dob']
679
+ * if (!motherDob || !value) return false
680
+ * return new Date(value) > new Date(motherDob)
681
+ * })
682
+ *
683
+ * @example
684
+ * // Two number fields validated together
685
+ * field('fieldA').customClientValidator((value, ctx) => {
686
+ * const fieldB = ctx.$form['fieldB']
687
+ * if (!fieldB) return false
688
+ * return value + fieldB > 100
689
+ * })
690
+ *
691
+ * @remarks
692
+ * Limitations:
693
+ * - Client-side only. For backend validation, use country config event triggers.
694
+ * - Cannot reference external libraries (lodash, etc.)
695
+ * - Function must be pure — no side effects, no closures over external state
696
+ * - Function must be serialisable via toString()
697
+ * - Receives (value, context) parameters where context contains $form, $now, $online, etc.
698
+ * - Must return boolean: true = valid, false = invalid
699
+ *
700
+ * @see https://github.com/opencrvs/opencrvs-core/issues/11653
701
+ */
702
+ customClientValidator(fn: (value: unknown, context: CommonConditionalParameters & {
703
+ $form: EventState | Record<string, unknown>;
704
+ }) => boolean): JSONSchema;
705
+ /**
706
+ * Defines a client-side computation function for dynamic field values.
707
+ *
708
+ * **Use this as a last resort when predefined toolkit methods are insufficient.**
709
+ *
710
+ * The function is serialized via toString() and transmitted to the client,
711
+ * where it is deserialized and executed to compute field values dynamically.
712
+ *
713
+ * @param fn - Computation function that receives the field value and form context.
714
+ * Returns the computed value (any type).
715
+ *
716
+ * @returns CodeToEvaluate object for client-side execution
717
+ *
718
+ * @example
719
+ * // Concatenate first and last name
720
+ * field('fullName').customClientEvaluation((value, ctx) => {
721
+ * return `${ctx.$form.firstName} ${ctx.$form.lastName}`
722
+ * })
723
+ *
724
+ * @example
725
+ * // Calculate age from date of birth
726
+ * field('childAge').customClientEvaluation((value, ctx) => {
727
+ * const dob = ctx.$form['child.dob']
728
+ * if (!dob) return undefined
729
+ * const age = Math.floor((new Date(ctx.$now) - new Date(dob)) / (365.25 * 24 * 60 * 60 * 1000))
730
+ * return age
731
+ * })
732
+ *
733
+ * @remarks
734
+ * Limitations:
735
+ * - Client-side only. For backend computation, use country config event triggers.
736
+ * - Cannot reference external libraries (lodash, etc.)
737
+ * - Function must be pure — no side effects, no closures over external state
738
+ * - Function must be serialisable via toString()
739
+ * - Receives (value, context) parameters where context contains $form, $now, $online, etc.
740
+ * - Should return the computed value (any type)
741
+ *
742
+ * @see https://github.com/opencrvs/opencrvs-core/issues/11653
743
+ */
744
+ customClientEvaluation(fn: (value: unknown, context: CommonConditionalParameters & {
745
+ $form: EventState | Record<string, unknown>;
746
+ }) => any): {
747
+ $$code: string;
748
+ };
364
749
  getId: () => {
365
750
  fieldId: string;
366
751
  };
@@ -428,6 +813,99 @@ export declare function createFieldConditionals(fieldId: string): {
428
813
  */
429
814
  matches(pattern: string): JSONSchema;
430
815
  isBetween(min: number, max: number): JSONSchema;
816
+ /**
817
+ * Executes a custom validation function defined by country configuration.
818
+ *
819
+ * **Use this as a last resort when predefined toolkit methods are insufficient.**
820
+ *
821
+ * The function is serialized via toString() and transmitted as part of the JSON Schema.
822
+ * It is deserialized just-in-time during validation on the client.
823
+ *
824
+ * @param fn - Validation function that receives the field value and form context.
825
+ * Must return true if valid, false if invalid.
826
+ *
827
+ * @returns JSONSchema conditional for AJV validation
828
+ *
829
+ * @example
830
+ * // Simple age validation
831
+ * field('age').customClientValidator((value, ctx) => {
832
+ * return value >= 18
833
+ * })
834
+ *
835
+ * @example
836
+ * // Cross-field validation: child DOB must be after mother DOB
837
+ * field('child.dob').customClientValidator((value, ctx) => {
838
+ * const motherDob = ctx.$form['mother.dob']
839
+ * if (!motherDob || !value) return false
840
+ * return new Date(value) > new Date(motherDob)
841
+ * })
842
+ *
843
+ * @example
844
+ * // Two number fields validated together
845
+ * field('fieldA').customClientValidator((value, ctx) => {
846
+ * const fieldB = ctx.$form['fieldB']
847
+ * if (!fieldB) return false
848
+ * return value + fieldB > 100
849
+ * })
850
+ *
851
+ * @remarks
852
+ * Limitations:
853
+ * - Client-side only. For backend validation, use country config event triggers.
854
+ * - Cannot reference external libraries (lodash, etc.)
855
+ * - Function must be pure — no side effects, no closures over external state
856
+ * - Function must be serialisable via toString()
857
+ * - Receives (value, context) parameters where context contains $form, $now, $online, etc.
858
+ * - Must return boolean: true = valid, false = invalid
859
+ *
860
+ * @see https://github.com/opencrvs/opencrvs-core/issues/11653
861
+ */
862
+ customClientValidator(fn: (value: unknown, context: CommonConditionalParameters & {
863
+ $form: EventState | Record<string, unknown>;
864
+ }) => boolean): JSONSchema;
865
+ /**
866
+ * Defines a client-side computation function for dynamic field values.
867
+ *
868
+ * **Use this as a last resort when predefined toolkit methods are insufficient.**
869
+ *
870
+ * The function is serialized via toString() and transmitted to the client,
871
+ * where it is deserialized and executed to compute field values dynamically.
872
+ *
873
+ * @param fn - Computation function that receives the field value and form context.
874
+ * Returns the computed value (any type).
875
+ *
876
+ * @returns CodeToEvaluate object for client-side execution
877
+ *
878
+ * @example
879
+ * // Concatenate first and last name
880
+ * field('fullName').customClientEvaluation((value, ctx) => {
881
+ * return `${ctx.$form.firstName} ${ctx.$form.lastName}`
882
+ * })
883
+ *
884
+ * @example
885
+ * // Calculate age from date of birth
886
+ * field('childAge').customClientEvaluation((value, ctx) => {
887
+ * const dob = ctx.$form['child.dob']
888
+ * if (!dob) return undefined
889
+ * const age = Math.floor((new Date(ctx.$now) - new Date(dob)) / (365.25 * 24 * 60 * 60 * 1000))
890
+ * return age
891
+ * })
892
+ *
893
+ * @remarks
894
+ * Limitations:
895
+ * - Client-side only. For backend computation, use country config event triggers.
896
+ * - Cannot reference external libraries (lodash, etc.)
897
+ * - Function must be pure — no side effects, no closures over external state
898
+ * - Function must be serialisable via toString()
899
+ * - Receives (value, context) parameters where context contains $form, $now, $online, etc.
900
+ * - Should return the computed value (any type)
901
+ *
902
+ * @see https://github.com/opencrvs/opencrvs-core/issues/11653
903
+ */
904
+ customClientEvaluation(fn: (value: unknown, context: CommonConditionalParameters & {
905
+ $form: EventState | Record<string, unknown>;
906
+ }) => any): {
907
+ $$code: string;
908
+ };
431
909
  getId: () => {
432
910
  fieldId: string;
433
911
  };
@@ -485,6 +963,99 @@ export declare function createFieldConditionals(fieldId: string): {
485
963
  */
486
964
  matches(pattern: string): JSONSchema;
487
965
  isBetween(min: number, max: number): JSONSchema;
966
+ /**
967
+ * Executes a custom validation function defined by country configuration.
968
+ *
969
+ * **Use this as a last resort when predefined toolkit methods are insufficient.**
970
+ *
971
+ * The function is serialized via toString() and transmitted as part of the JSON Schema.
972
+ * It is deserialized just-in-time during validation on the client.
973
+ *
974
+ * @param fn - Validation function that receives the field value and form context.
975
+ * Must return true if valid, false if invalid.
976
+ *
977
+ * @returns JSONSchema conditional for AJV validation
978
+ *
979
+ * @example
980
+ * // Simple age validation
981
+ * field('age').customClientValidator((value, ctx) => {
982
+ * return value >= 18
983
+ * })
984
+ *
985
+ * @example
986
+ * // Cross-field validation: child DOB must be after mother DOB
987
+ * field('child.dob').customClientValidator((value, ctx) => {
988
+ * const motherDob = ctx.$form['mother.dob']
989
+ * if (!motherDob || !value) return false
990
+ * return new Date(value) > new Date(motherDob)
991
+ * })
992
+ *
993
+ * @example
994
+ * // Two number fields validated together
995
+ * field('fieldA').customClientValidator((value, ctx) => {
996
+ * const fieldB = ctx.$form['fieldB']
997
+ * if (!fieldB) return false
998
+ * return value + fieldB > 100
999
+ * })
1000
+ *
1001
+ * @remarks
1002
+ * Limitations:
1003
+ * - Client-side only. For backend validation, use country config event triggers.
1004
+ * - Cannot reference external libraries (lodash, etc.)
1005
+ * - Function must be pure — no side effects, no closures over external state
1006
+ * - Function must be serialisable via toString()
1007
+ * - Receives (value, context) parameters where context contains $form, $now, $online, etc.
1008
+ * - Must return boolean: true = valid, false = invalid
1009
+ *
1010
+ * @see https://github.com/opencrvs/opencrvs-core/issues/11653
1011
+ */
1012
+ customClientValidator(fn: (value: unknown, context: CommonConditionalParameters & {
1013
+ $form: EventState | Record<string, unknown>;
1014
+ }) => boolean): JSONSchema;
1015
+ /**
1016
+ * Defines a client-side computation function for dynamic field values.
1017
+ *
1018
+ * **Use this as a last resort when predefined toolkit methods are insufficient.**
1019
+ *
1020
+ * The function is serialized via toString() and transmitted to the client,
1021
+ * where it is deserialized and executed to compute field values dynamically.
1022
+ *
1023
+ * @param fn - Computation function that receives the field value and form context.
1024
+ * Returns the computed value (any type).
1025
+ *
1026
+ * @returns CodeToEvaluate object for client-side execution
1027
+ *
1028
+ * @example
1029
+ * // Concatenate first and last name
1030
+ * field('fullName').customClientEvaluation((value, ctx) => {
1031
+ * return `${ctx.$form.firstName} ${ctx.$form.lastName}`
1032
+ * })
1033
+ *
1034
+ * @example
1035
+ * // Calculate age from date of birth
1036
+ * field('childAge').customClientEvaluation((value, ctx) => {
1037
+ * const dob = ctx.$form['child.dob']
1038
+ * if (!dob) return undefined
1039
+ * const age = Math.floor((new Date(ctx.$now) - new Date(dob)) / (365.25 * 24 * 60 * 60 * 1000))
1040
+ * return age
1041
+ * })
1042
+ *
1043
+ * @remarks
1044
+ * Limitations:
1045
+ * - Client-side only. For backend computation, use country config event triggers.
1046
+ * - Cannot reference external libraries (lodash, etc.)
1047
+ * - Function must be pure — no side effects, no closures over external state
1048
+ * - Function must be serialisable via toString()
1049
+ * - Receives (value, context) parameters where context contains $form, $now, $online, etc.
1050
+ * - Should return the computed value (any type)
1051
+ *
1052
+ * @see https://github.com/opencrvs/opencrvs-core/issues/11653
1053
+ */
1054
+ customClientEvaluation(fn: (value: unknown, context: CommonConditionalParameters & {
1055
+ $form: EventState | Record<string, unknown>;
1056
+ }) => any): {
1057
+ $$code: string;
1058
+ };
488
1059
  getId: () => {
489
1060
  fieldId: string;
490
1061
  };
@@ -559,6 +1130,99 @@ export declare function createFieldConditionals(fieldId: string): {
559
1130
  */
560
1131
  matches(pattern: string): JSONSchema;
561
1132
  isBetween(min: number, max: number): JSONSchema;
1133
+ /**
1134
+ * Executes a custom validation function defined by country configuration.
1135
+ *
1136
+ * **Use this as a last resort when predefined toolkit methods are insufficient.**
1137
+ *
1138
+ * The function is serialized via toString() and transmitted as part of the JSON Schema.
1139
+ * It is deserialized just-in-time during validation on the client.
1140
+ *
1141
+ * @param fn - Validation function that receives the field value and form context.
1142
+ * Must return true if valid, false if invalid.
1143
+ *
1144
+ * @returns JSONSchema conditional for AJV validation
1145
+ *
1146
+ * @example
1147
+ * // Simple age validation
1148
+ * field('age').customClientValidator((value, ctx) => {
1149
+ * return value >= 18
1150
+ * })
1151
+ *
1152
+ * @example
1153
+ * // Cross-field validation: child DOB must be after mother DOB
1154
+ * field('child.dob').customClientValidator((value, ctx) => {
1155
+ * const motherDob = ctx.$form['mother.dob']
1156
+ * if (!motherDob || !value) return false
1157
+ * return new Date(value) > new Date(motherDob)
1158
+ * })
1159
+ *
1160
+ * @example
1161
+ * // Two number fields validated together
1162
+ * field('fieldA').customClientValidator((value, ctx) => {
1163
+ * const fieldB = ctx.$form['fieldB']
1164
+ * if (!fieldB) return false
1165
+ * return value + fieldB > 100
1166
+ * })
1167
+ *
1168
+ * @remarks
1169
+ * Limitations:
1170
+ * - Client-side only. For backend validation, use country config event triggers.
1171
+ * - Cannot reference external libraries (lodash, etc.)
1172
+ * - Function must be pure — no side effects, no closures over external state
1173
+ * - Function must be serialisable via toString()
1174
+ * - Receives (value, context) parameters where context contains $form, $now, $online, etc.
1175
+ * - Must return boolean: true = valid, false = invalid
1176
+ *
1177
+ * @see https://github.com/opencrvs/opencrvs-core/issues/11653
1178
+ */
1179
+ customClientValidator(fn: (value: unknown, context: CommonConditionalParameters & {
1180
+ $form: EventState | Record<string, unknown>;
1181
+ }) => boolean): JSONSchema;
1182
+ /**
1183
+ * Defines a client-side computation function for dynamic field values.
1184
+ *
1185
+ * **Use this as a last resort when predefined toolkit methods are insufficient.**
1186
+ *
1187
+ * The function is serialized via toString() and transmitted to the client,
1188
+ * where it is deserialized and executed to compute field values dynamically.
1189
+ *
1190
+ * @param fn - Computation function that receives the field value and form context.
1191
+ * Returns the computed value (any type).
1192
+ *
1193
+ * @returns CodeToEvaluate object for client-side execution
1194
+ *
1195
+ * @example
1196
+ * // Concatenate first and last name
1197
+ * field('fullName').customClientEvaluation((value, ctx) => {
1198
+ * return `${ctx.$form.firstName} ${ctx.$form.lastName}`
1199
+ * })
1200
+ *
1201
+ * @example
1202
+ * // Calculate age from date of birth
1203
+ * field('childAge').customClientEvaluation((value, ctx) => {
1204
+ * const dob = ctx.$form['child.dob']
1205
+ * if (!dob) return undefined
1206
+ * const age = Math.floor((new Date(ctx.$now) - new Date(dob)) / (365.25 * 24 * 60 * 60 * 1000))
1207
+ * return age
1208
+ * })
1209
+ *
1210
+ * @remarks
1211
+ * Limitations:
1212
+ * - Client-side only. For backend computation, use country config event triggers.
1213
+ * - Cannot reference external libraries (lodash, etc.)
1214
+ * - Function must be pure — no side effects, no closures over external state
1215
+ * - Function must be serialisable via toString()
1216
+ * - Receives (value, context) parameters where context contains $form, $now, $online, etc.
1217
+ * - Should return the computed value (any type)
1218
+ *
1219
+ * @see https://github.com/opencrvs/opencrvs-core/issues/11653
1220
+ */
1221
+ customClientEvaluation(fn: (value: unknown, context: CommonConditionalParameters & {
1222
+ $form: EventState | Record<string, unknown>;
1223
+ }) => any): {
1224
+ $$code: string;
1225
+ };
562
1226
  getId: () => {
563
1227
  fieldId: string;
564
1228
  };
@@ -618,6 +1282,99 @@ export declare function createFieldConditionals(fieldId: string): {
618
1282
  */
619
1283
  matches(pattern: string): JSONSchema;
620
1284
  isBetween(min: number, max: number): JSONSchema;
1285
+ /**
1286
+ * Executes a custom validation function defined by country configuration.
1287
+ *
1288
+ * **Use this as a last resort when predefined toolkit methods are insufficient.**
1289
+ *
1290
+ * The function is serialized via toString() and transmitted as part of the JSON Schema.
1291
+ * It is deserialized just-in-time during validation on the client.
1292
+ *
1293
+ * @param fn - Validation function that receives the field value and form context.
1294
+ * Must return true if valid, false if invalid.
1295
+ *
1296
+ * @returns JSONSchema conditional for AJV validation
1297
+ *
1298
+ * @example
1299
+ * // Simple age validation
1300
+ * field('age').customClientValidator((value, ctx) => {
1301
+ * return value >= 18
1302
+ * })
1303
+ *
1304
+ * @example
1305
+ * // Cross-field validation: child DOB must be after mother DOB
1306
+ * field('child.dob').customClientValidator((value, ctx) => {
1307
+ * const motherDob = ctx.$form['mother.dob']
1308
+ * if (!motherDob || !value) return false
1309
+ * return new Date(value) > new Date(motherDob)
1310
+ * })
1311
+ *
1312
+ * @example
1313
+ * // Two number fields validated together
1314
+ * field('fieldA').customClientValidator((value, ctx) => {
1315
+ * const fieldB = ctx.$form['fieldB']
1316
+ * if (!fieldB) return false
1317
+ * return value + fieldB > 100
1318
+ * })
1319
+ *
1320
+ * @remarks
1321
+ * Limitations:
1322
+ * - Client-side only. For backend validation, use country config event triggers.
1323
+ * - Cannot reference external libraries (lodash, etc.)
1324
+ * - Function must be pure — no side effects, no closures over external state
1325
+ * - Function must be serialisable via toString()
1326
+ * - Receives (value, context) parameters where context contains $form, $now, $online, etc.
1327
+ * - Must return boolean: true = valid, false = invalid
1328
+ *
1329
+ * @see https://github.com/opencrvs/opencrvs-core/issues/11653
1330
+ */
1331
+ customClientValidator(fn: (value: unknown, context: CommonConditionalParameters & {
1332
+ $form: EventState | Record<string, unknown>;
1333
+ }) => boolean): JSONSchema;
1334
+ /**
1335
+ * Defines a client-side computation function for dynamic field values.
1336
+ *
1337
+ * **Use this as a last resort when predefined toolkit methods are insufficient.**
1338
+ *
1339
+ * The function is serialized via toString() and transmitted to the client,
1340
+ * where it is deserialized and executed to compute field values dynamically.
1341
+ *
1342
+ * @param fn - Computation function that receives the field value and form context.
1343
+ * Returns the computed value (any type).
1344
+ *
1345
+ * @returns CodeToEvaluate object for client-side execution
1346
+ *
1347
+ * @example
1348
+ * // Concatenate first and last name
1349
+ * field('fullName').customClientEvaluation((value, ctx) => {
1350
+ * return `${ctx.$form.firstName} ${ctx.$form.lastName}`
1351
+ * })
1352
+ *
1353
+ * @example
1354
+ * // Calculate age from date of birth
1355
+ * field('childAge').customClientEvaluation((value, ctx) => {
1356
+ * const dob = ctx.$form['child.dob']
1357
+ * if (!dob) return undefined
1358
+ * const age = Math.floor((new Date(ctx.$now) - new Date(dob)) / (365.25 * 24 * 60 * 60 * 1000))
1359
+ * return age
1360
+ * })
1361
+ *
1362
+ * @remarks
1363
+ * Limitations:
1364
+ * - Client-side only. For backend computation, use country config event triggers.
1365
+ * - Cannot reference external libraries (lodash, etc.)
1366
+ * - Function must be pure — no side effects, no closures over external state
1367
+ * - Function must be serialisable via toString()
1368
+ * - Receives (value, context) parameters where context contains $form, $now, $online, etc.
1369
+ * - Should return the computed value (any type)
1370
+ *
1371
+ * @see https://github.com/opencrvs/opencrvs-core/issues/11653
1372
+ */
1373
+ customClientEvaluation(fn: (value: unknown, context: CommonConditionalParameters & {
1374
+ $form: EventState | Record<string, unknown>;
1375
+ }) => any): {
1376
+ $$code: string;
1377
+ };
621
1378
  getId: () => {
622
1379
  fieldId: string;
623
1380
  };
@@ -692,6 +1449,99 @@ export declare function createFieldConditionals(fieldId: string): {
692
1449
  */
693
1450
  matches(pattern: string): JSONSchema;
694
1451
  isBetween(min: number, max: number): JSONSchema;
1452
+ /**
1453
+ * Executes a custom validation function defined by country configuration.
1454
+ *
1455
+ * **Use this as a last resort when predefined toolkit methods are insufficient.**
1456
+ *
1457
+ * The function is serialized via toString() and transmitted as part of the JSON Schema.
1458
+ * It is deserialized just-in-time during validation on the client.
1459
+ *
1460
+ * @param fn - Validation function that receives the field value and form context.
1461
+ * Must return true if valid, false if invalid.
1462
+ *
1463
+ * @returns JSONSchema conditional for AJV validation
1464
+ *
1465
+ * @example
1466
+ * // Simple age validation
1467
+ * field('age').customClientValidator((value, ctx) => {
1468
+ * return value >= 18
1469
+ * })
1470
+ *
1471
+ * @example
1472
+ * // Cross-field validation: child DOB must be after mother DOB
1473
+ * field('child.dob').customClientValidator((value, ctx) => {
1474
+ * const motherDob = ctx.$form['mother.dob']
1475
+ * if (!motherDob || !value) return false
1476
+ * return new Date(value) > new Date(motherDob)
1477
+ * })
1478
+ *
1479
+ * @example
1480
+ * // Two number fields validated together
1481
+ * field('fieldA').customClientValidator((value, ctx) => {
1482
+ * const fieldB = ctx.$form['fieldB']
1483
+ * if (!fieldB) return false
1484
+ * return value + fieldB > 100
1485
+ * })
1486
+ *
1487
+ * @remarks
1488
+ * Limitations:
1489
+ * - Client-side only. For backend validation, use country config event triggers.
1490
+ * - Cannot reference external libraries (lodash, etc.)
1491
+ * - Function must be pure — no side effects, no closures over external state
1492
+ * - Function must be serialisable via toString()
1493
+ * - Receives (value, context) parameters where context contains $form, $now, $online, etc.
1494
+ * - Must return boolean: true = valid, false = invalid
1495
+ *
1496
+ * @see https://github.com/opencrvs/opencrvs-core/issues/11653
1497
+ */
1498
+ customClientValidator(fn: (value: unknown, context: CommonConditionalParameters & {
1499
+ $form: EventState | Record<string, unknown>;
1500
+ }) => boolean): JSONSchema;
1501
+ /**
1502
+ * Defines a client-side computation function for dynamic field values.
1503
+ *
1504
+ * **Use this as a last resort when predefined toolkit methods are insufficient.**
1505
+ *
1506
+ * The function is serialized via toString() and transmitted to the client,
1507
+ * where it is deserialized and executed to compute field values dynamically.
1508
+ *
1509
+ * @param fn - Computation function that receives the field value and form context.
1510
+ * Returns the computed value (any type).
1511
+ *
1512
+ * @returns CodeToEvaluate object for client-side execution
1513
+ *
1514
+ * @example
1515
+ * // Concatenate first and last name
1516
+ * field('fullName').customClientEvaluation((value, ctx) => {
1517
+ * return `${ctx.$form.firstName} ${ctx.$form.lastName}`
1518
+ * })
1519
+ *
1520
+ * @example
1521
+ * // Calculate age from date of birth
1522
+ * field('childAge').customClientEvaluation((value, ctx) => {
1523
+ * const dob = ctx.$form['child.dob']
1524
+ * if (!dob) return undefined
1525
+ * const age = Math.floor((new Date(ctx.$now) - new Date(dob)) / (365.25 * 24 * 60 * 60 * 1000))
1526
+ * return age
1527
+ * })
1528
+ *
1529
+ * @remarks
1530
+ * Limitations:
1531
+ * - Client-side only. For backend computation, use country config event triggers.
1532
+ * - Cannot reference external libraries (lodash, etc.)
1533
+ * - Function must be pure — no side effects, no closures over external state
1534
+ * - Function must be serialisable via toString()
1535
+ * - Receives (value, context) parameters where context contains $form, $now, $online, etc.
1536
+ * - Should return the computed value (any type)
1537
+ *
1538
+ * @see https://github.com/opencrvs/opencrvs-core/issues/11653
1539
+ */
1540
+ customClientEvaluation(fn: (value: unknown, context: CommonConditionalParameters & {
1541
+ $form: EventState | Record<string, unknown>;
1542
+ }) => any): {
1543
+ $$code: string;
1544
+ };
695
1545
  getId: () => {
696
1546
  fieldId: string;
697
1547
  };
@@ -751,6 +1601,99 @@ export declare function createFieldConditionals(fieldId: string): {
751
1601
  */
752
1602
  matches(pattern: string): JSONSchema;
753
1603
  isBetween(min: number, max: number): JSONSchema;
1604
+ /**
1605
+ * Executes a custom validation function defined by country configuration.
1606
+ *
1607
+ * **Use this as a last resort when predefined toolkit methods are insufficient.**
1608
+ *
1609
+ * The function is serialized via toString() and transmitted as part of the JSON Schema.
1610
+ * It is deserialized just-in-time during validation on the client.
1611
+ *
1612
+ * @param fn - Validation function that receives the field value and form context.
1613
+ * Must return true if valid, false if invalid.
1614
+ *
1615
+ * @returns JSONSchema conditional for AJV validation
1616
+ *
1617
+ * @example
1618
+ * // Simple age validation
1619
+ * field('age').customClientValidator((value, ctx) => {
1620
+ * return value >= 18
1621
+ * })
1622
+ *
1623
+ * @example
1624
+ * // Cross-field validation: child DOB must be after mother DOB
1625
+ * field('child.dob').customClientValidator((value, ctx) => {
1626
+ * const motherDob = ctx.$form['mother.dob']
1627
+ * if (!motherDob || !value) return false
1628
+ * return new Date(value) > new Date(motherDob)
1629
+ * })
1630
+ *
1631
+ * @example
1632
+ * // Two number fields validated together
1633
+ * field('fieldA').customClientValidator((value, ctx) => {
1634
+ * const fieldB = ctx.$form['fieldB']
1635
+ * if (!fieldB) return false
1636
+ * return value + fieldB > 100
1637
+ * })
1638
+ *
1639
+ * @remarks
1640
+ * Limitations:
1641
+ * - Client-side only. For backend validation, use country config event triggers.
1642
+ * - Cannot reference external libraries (lodash, etc.)
1643
+ * - Function must be pure — no side effects, no closures over external state
1644
+ * - Function must be serialisable via toString()
1645
+ * - Receives (value, context) parameters where context contains $form, $now, $online, etc.
1646
+ * - Must return boolean: true = valid, false = invalid
1647
+ *
1648
+ * @see https://github.com/opencrvs/opencrvs-core/issues/11653
1649
+ */
1650
+ customClientValidator(fn: (value: unknown, context: CommonConditionalParameters & {
1651
+ $form: EventState | Record<string, unknown>;
1652
+ }) => boolean): JSONSchema;
1653
+ /**
1654
+ * Defines a client-side computation function for dynamic field values.
1655
+ *
1656
+ * **Use this as a last resort when predefined toolkit methods are insufficient.**
1657
+ *
1658
+ * The function is serialized via toString() and transmitted to the client,
1659
+ * where it is deserialized and executed to compute field values dynamically.
1660
+ *
1661
+ * @param fn - Computation function that receives the field value and form context.
1662
+ * Returns the computed value (any type).
1663
+ *
1664
+ * @returns CodeToEvaluate object for client-side execution
1665
+ *
1666
+ * @example
1667
+ * // Concatenate first and last name
1668
+ * field('fullName').customClientEvaluation((value, ctx) => {
1669
+ * return `${ctx.$form.firstName} ${ctx.$form.lastName}`
1670
+ * })
1671
+ *
1672
+ * @example
1673
+ * // Calculate age from date of birth
1674
+ * field('childAge').customClientEvaluation((value, ctx) => {
1675
+ * const dob = ctx.$form['child.dob']
1676
+ * if (!dob) return undefined
1677
+ * const age = Math.floor((new Date(ctx.$now) - new Date(dob)) / (365.25 * 24 * 60 * 60 * 1000))
1678
+ * return age
1679
+ * })
1680
+ *
1681
+ * @remarks
1682
+ * Limitations:
1683
+ * - Client-side only. For backend computation, use country config event triggers.
1684
+ * - Cannot reference external libraries (lodash, etc.)
1685
+ * - Function must be pure — no side effects, no closures over external state
1686
+ * - Function must be serialisable via toString()
1687
+ * - Receives (value, context) parameters where context contains $form, $now, $online, etc.
1688
+ * - Should return the computed value (any type)
1689
+ *
1690
+ * @see https://github.com/opencrvs/opencrvs-core/issues/11653
1691
+ */
1692
+ customClientEvaluation(fn: (value: unknown, context: CommonConditionalParameters & {
1693
+ $form: EventState | Record<string, unknown>;
1694
+ }) => any): {
1695
+ $$code: string;
1696
+ };
754
1697
  getId: () => {
755
1698
  fieldId: string;
756
1699
  };
@@ -808,6 +1751,99 @@ export declare function createFieldConditionals(fieldId: string): {
808
1751
  */
809
1752
  matches(pattern: string): JSONSchema;
810
1753
  isBetween(min: number, max: number): JSONSchema;
1754
+ /**
1755
+ * Executes a custom validation function defined by country configuration.
1756
+ *
1757
+ * **Use this as a last resort when predefined toolkit methods are insufficient.**
1758
+ *
1759
+ * The function is serialized via toString() and transmitted as part of the JSON Schema.
1760
+ * It is deserialized just-in-time during validation on the client.
1761
+ *
1762
+ * @param fn - Validation function that receives the field value and form context.
1763
+ * Must return true if valid, false if invalid.
1764
+ *
1765
+ * @returns JSONSchema conditional for AJV validation
1766
+ *
1767
+ * @example
1768
+ * // Simple age validation
1769
+ * field('age').customClientValidator((value, ctx) => {
1770
+ * return value >= 18
1771
+ * })
1772
+ *
1773
+ * @example
1774
+ * // Cross-field validation: child DOB must be after mother DOB
1775
+ * field('child.dob').customClientValidator((value, ctx) => {
1776
+ * const motherDob = ctx.$form['mother.dob']
1777
+ * if (!motherDob || !value) return false
1778
+ * return new Date(value) > new Date(motherDob)
1779
+ * })
1780
+ *
1781
+ * @example
1782
+ * // Two number fields validated together
1783
+ * field('fieldA').customClientValidator((value, ctx) => {
1784
+ * const fieldB = ctx.$form['fieldB']
1785
+ * if (!fieldB) return false
1786
+ * return value + fieldB > 100
1787
+ * })
1788
+ *
1789
+ * @remarks
1790
+ * Limitations:
1791
+ * - Client-side only. For backend validation, use country config event triggers.
1792
+ * - Cannot reference external libraries (lodash, etc.)
1793
+ * - Function must be pure — no side effects, no closures over external state
1794
+ * - Function must be serialisable via toString()
1795
+ * - Receives (value, context) parameters where context contains $form, $now, $online, etc.
1796
+ * - Must return boolean: true = valid, false = invalid
1797
+ *
1798
+ * @see https://github.com/opencrvs/opencrvs-core/issues/11653
1799
+ */
1800
+ customClientValidator(fn: (value: unknown, context: CommonConditionalParameters & {
1801
+ $form: EventState | Record<string, unknown>;
1802
+ }) => boolean): JSONSchema;
1803
+ /**
1804
+ * Defines a client-side computation function for dynamic field values.
1805
+ *
1806
+ * **Use this as a last resort when predefined toolkit methods are insufficient.**
1807
+ *
1808
+ * The function is serialized via toString() and transmitted to the client,
1809
+ * where it is deserialized and executed to compute field values dynamically.
1810
+ *
1811
+ * @param fn - Computation function that receives the field value and form context.
1812
+ * Returns the computed value (any type).
1813
+ *
1814
+ * @returns CodeToEvaluate object for client-side execution
1815
+ *
1816
+ * @example
1817
+ * // Concatenate first and last name
1818
+ * field('fullName').customClientEvaluation((value, ctx) => {
1819
+ * return `${ctx.$form.firstName} ${ctx.$form.lastName}`
1820
+ * })
1821
+ *
1822
+ * @example
1823
+ * // Calculate age from date of birth
1824
+ * field('childAge').customClientEvaluation((value, ctx) => {
1825
+ * const dob = ctx.$form['child.dob']
1826
+ * if (!dob) return undefined
1827
+ * const age = Math.floor((new Date(ctx.$now) - new Date(dob)) / (365.25 * 24 * 60 * 60 * 1000))
1828
+ * return age
1829
+ * })
1830
+ *
1831
+ * @remarks
1832
+ * Limitations:
1833
+ * - Client-side only. For backend computation, use country config event triggers.
1834
+ * - Cannot reference external libraries (lodash, etc.)
1835
+ * - Function must be pure — no side effects, no closures over external state
1836
+ * - Function must be serialisable via toString()
1837
+ * - Receives (value, context) parameters where context contains $form, $now, $online, etc.
1838
+ * - Should return the computed value (any type)
1839
+ *
1840
+ * @see https://github.com/opencrvs/opencrvs-core/issues/11653
1841
+ */
1842
+ customClientEvaluation(fn: (value: unknown, context: CommonConditionalParameters & {
1843
+ $form: EventState | Record<string, unknown>;
1844
+ }) => any): {
1845
+ $$code: string;
1846
+ };
811
1847
  getId: () => {
812
1848
  fieldId: string;
813
1849
  };