@opencrvs/toolkit 1.9.8-rc.34c53bf → 1.9.8-rc.48851c5

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.
@@ -70,6 +70,9 @@ type FieldReference = {
70
70
  $$field: string;
71
71
  $$subfield: string[];
72
72
  };
73
+ type CodeToEvaluate = {
74
+ $$code: string;
75
+ };
73
76
  /**
74
77
  * Generate conditional rules for current date
75
78
  */
@@ -89,6 +92,7 @@ export declare const user: typeof userSerializer & {
89
92
  };
90
93
  };
91
94
  export declare function isFieldReference(value: unknown): value is FieldReference;
95
+ export declare function isCodeToEvaluate(value: unknown): value is CodeToEvaluate;
92
96
  /** Check if an event flag is present */
93
97
  export declare function flag(flagvalue: string): JSONSchema;
94
98
  /** Check if an event flag is present */
@@ -170,6 +174,99 @@ export declare function createFieldConditionals(fieldId: string): {
170
174
  */
171
175
  matches(pattern: string): JSONSchema;
172
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
+ };
173
270
  getId: () => {
174
271
  fieldId: string;
175
272
  };
@@ -229,6 +326,99 @@ export declare function createFieldConditionals(fieldId: string): {
229
326
  */
230
327
  matches(pattern: string): JSONSchema;
231
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
+ };
232
422
  getId: () => {
233
423
  fieldId: string;
234
424
  };
@@ -302,6 +492,99 @@ export declare function createFieldConditionals(fieldId: string): {
302
492
  */
303
493
  matches(pattern: string): JSONSchema;
304
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
+ };
305
588
  getId: () => {
306
589
  fieldId: string;
307
590
  };
@@ -370,6 +653,99 @@ export declare function createFieldConditionals(fieldId: string): {
370
653
  */
371
654
  matches(pattern: string): JSONSchema;
372
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
+ };
373
749
  getId: () => {
374
750
  fieldId: string;
375
751
  };
@@ -437,6 +813,99 @@ export declare function createFieldConditionals(fieldId: string): {
437
813
  */
438
814
  matches(pattern: string): JSONSchema;
439
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
+ };
440
909
  getId: () => {
441
910
  fieldId: string;
442
911
  };
@@ -494,6 +963,99 @@ export declare function createFieldConditionals(fieldId: string): {
494
963
  */
495
964
  matches(pattern: string): JSONSchema;
496
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
+ };
497
1059
  getId: () => {
498
1060
  fieldId: string;
499
1061
  };
@@ -568,6 +1130,99 @@ export declare function createFieldConditionals(fieldId: string): {
568
1130
  */
569
1131
  matches(pattern: string): JSONSchema;
570
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
+ };
571
1226
  getId: () => {
572
1227
  fieldId: string;
573
1228
  };
@@ -627,6 +1282,99 @@ export declare function createFieldConditionals(fieldId: string): {
627
1282
  */
628
1283
  matches(pattern: string): JSONSchema;
629
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
+ };
630
1378
  getId: () => {
631
1379
  fieldId: string;
632
1380
  };
@@ -701,6 +1449,99 @@ export declare function createFieldConditionals(fieldId: string): {
701
1449
  */
702
1450
  matches(pattern: string): JSONSchema;
703
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
+ };
704
1545
  getId: () => {
705
1546
  fieldId: string;
706
1547
  };
@@ -760,6 +1601,99 @@ export declare function createFieldConditionals(fieldId: string): {
760
1601
  */
761
1602
  matches(pattern: string): JSONSchema;
762
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
+ };
763
1697
  getId: () => {
764
1698
  fieldId: string;
765
1699
  };
@@ -817,6 +1751,99 @@ export declare function createFieldConditionals(fieldId: string): {
817
1751
  */
818
1752
  matches(pattern: string): JSONSchema;
819
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
+ };
820
1847
  getId: () => {
821
1848
  fieldId: string;
822
1849
  };