@opencrvs/toolkit 1.9.13 → 1.9.14-rc.ee7695e

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.
@@ -93,8 +93,8 @@ export declare const appRouter: import("@trpc/server").TRPCBuiltRouter<{
93
93
  };
94
94
  deduplication?: {
95
95
  id: string;
96
- query: import("../commons").ClauseOutput;
97
96
  label: import("../commons").TranslationConfig;
97
+ query: import("../commons").ClauseOutput;
98
98
  } | undefined;
99
99
  } | {
100
100
  type: "VALIDATE";
@@ -105,8 +105,8 @@ export declare const appRouter: import("@trpc/server").TRPCBuiltRouter<{
105
105
  };
106
106
  deduplication?: {
107
107
  id: string;
108
- query: import("../commons").ClauseOutput;
109
108
  label: import("../commons").TranslationConfig;
109
+ query: import("../commons").ClauseOutput;
110
110
  } | undefined;
111
111
  } | {
112
112
  type: "REJECT";
@@ -123,8 +123,8 @@ export declare const appRouter: import("@trpc/server").TRPCBuiltRouter<{
123
123
  };
124
124
  deduplication?: {
125
125
  id: string;
126
- query: import("../commons").ClauseOutput;
127
126
  label: import("../commons").TranslationConfig;
127
+ query: import("../commons").ClauseOutput;
128
128
  } | undefined;
129
129
  } | {
130
130
  type: "DELETE";
@@ -227,7 +227,7 @@ export declare const appRouter: import("@trpc/server").TRPCBuiltRouter<{
227
227
  title: import("../commons").TranslationConfig;
228
228
  fields: ({
229
229
  config: {
230
- type: "exact" | "fuzzy" | "range" | "within";
230
+ type: "exact" | "range" | "fuzzy" | "within";
231
231
  searchFields?: string[] | undefined;
232
232
  };
233
233
  fieldId: string;
@@ -262,10 +262,10 @@ export declare const appRouter: import("@trpc/server").TRPCBuiltRouter<{
262
262
  }[] | undefined;
263
263
  } | {
264
264
  config: {
265
- type: "exact" | "fuzzy" | "range" | "within";
265
+ type: "exact" | "range" | "fuzzy" | "within";
266
266
  searchFields?: string[] | undefined;
267
267
  };
268
- fieldId: "event.status" | "event.trackingId" | "event.updatedAt" | "event.legalStatuses.REGISTERED.acceptedAt" | "event.legalStatuses.REGISTERED.createdAtLocation" | "event.legalStatuses.REGISTERED.registrationNumber";
268
+ fieldId: "event.trackingId" | "event.status" | "event.legalStatuses.REGISTERED.acceptedAt" | "event.legalStatuses.REGISTERED.createdAtLocation" | "event.legalStatuses.REGISTERED.registrationNumber" | "event.updatedAt";
269
269
  fieldType: "event";
270
270
  type?: "NAME" | "PHONE" | "ID" | "ADDRESS" | "TEXT" | "NUMBER" | "NUMBER_WITH_UNIT" | "TEXTAREA" | "EMAIL" | "DATE" | "AGE" | "DATE_RANGE" | "SELECT_DATE_RANGE" | "TIME" | "PARAGRAPH" | "PAGE_HEADER" | "RADIO_GROUP" | "FIELD_GROUP" | "FILE" | "FILE_WITH_OPTIONS" | "BULLET_LIST" | "CHECKBOX" | "SELECT" | "COUNTRY" | "LOCATION" | "DIVIDER" | "ADMINISTRATIVE_AREA" | "FACILITY" | "OFFICE" | "SIGNATURE" | "DATA" | "BUTTON" | "SEARCH" | "ALPHA_PRINT_BUTTON" | "HTTP" | "LINK_BUTTON" | "VERIFICATION_STATUS" | "QUERY_PARAM_READER" | "QR_READER" | "ID_READER" | "LOADER" | undefined;
271
271
  options?: {
@@ -300,8 +300,9 @@ export declare const appRouter: import("@trpc/server").TRPCBuiltRouter<{
300
300
  dateOfEvent?: {
301
301
  $$field: string;
302
302
  $$subfield: string[];
303
+ $$code?: string | undefined;
303
304
  } | {
304
- $$event: "createdAt" | "updatedAt" | "legalStatuses.DECLARED.createdAt" | "legalStatuses.DECLARED.acceptedAt" | "legalStatuses.REGISTERED.createdAt" | "legalStatuses.REGISTERED.acceptedAt";
305
+ $$event: "createdAt" | "updatedAt" | "legalStatuses.REGISTERED.acceptedAt" | "legalStatuses.DECLARED.createdAt" | "legalStatuses.DECLARED.acceptedAt" | "legalStatuses.REGISTERED.createdAt";
305
306
  } | undefined;
306
307
  fallbackTitle?: import("../commons").TranslationConfig | undefined;
307
308
  }[];
@@ -6186,6 +6187,7 @@ export declare const appRouter: import("@trpc/server").TRPCBuiltRouter<{
6186
6187
  type: "DELETE" | "DECLARE" | "VALIDATE" | "REGISTER" | "MARK_AS_DUPLICATE" | "ARCHIVE" | "PRINT_CERTIFICATE" | "REQUEST_CORRECTION" | "READ" | "ASSIGN" | "UNASSIGN" | "DEFAULT";
6187
6188
  conditionals?: import("../commons").JSONSchema[] | undefined;
6188
6189
  }[];
6190
+ icon: "Validated" | "Registered" | "Certified" | "Archived" | "List" | "Draft" | "Archive" | "IdentificationCard" | "Check" | "Assigned" | "Close" | "Collapse" | "DuplicateYellow" | "Expand" | "ExternalValidate" | "FilledCheck" | "InReview" | "Offline" | "RequiresUpdates" | "Sent" | "WaitingApproval" | "ChartActivity" | "Activity" | "ArchiveTray" | "ArrowLeft" | "ArrowRight" | "Buildings" | "Circle" | "CaretDown" | "CaretLeft" | "CaretRight" | "ChartBar" | "ChartLine" | "ChatCircle" | "CheckSquare" | "Compass" | "Copy" | "Database" | "DotsThreeVertical" | "ArrowCounterClockwise" | "MagnifyingGlassMinus" | "MagnifyingGlassPlus" | "Export" | "Eye" | "EyeSlash" | "Envelope" | "File" | "FileSearch" | "FileMinus" | "FilePlus" | "FileText" | "FileX" | "Handshake" | "Gear" | "GitBranch" | "ListBullets" | "Lock" | "MagnifyingGlass" | "MapPin" | "Medal" | "NotePencil" | "Paperclip" | "PaperPlaneTilt" | "Pen" | "Pencil" | "PencilSimpleLine" | "Phone" | "Plus" | "Printer" | "SignOut" | "Star" | "Target" | "TextT" | "Trash" | "UploadSimple" | "User" | "UserPlus" | "Users" | "WarningCircle" | "X" | "CircleWavyCheck" | "CircleWavyQuestion" | "ArchiveBox" | "ArrowCircleDown" | "FileArrowUp" | "FileDotted" | "Files" | "PencilLine" | "PencilCircle" | "UserCircle" | "Clock" | "QrCode" | "Webcam" | "Sun" | "DeviceTabletCamera" | "Globe" | "Fingerprint" | "PushPin" | "Timer";
6189
6191
  query: {
6190
6192
  type: "or";
6191
6193
  clauses: {
@@ -6254,6 +6256,18 @@ export declare const appRouter: import("@trpc/server").TRPCBuiltRouter<{
6254
6256
  type: "timePeriod";
6255
6257
  term: "last7Days" | "last30Days" | "last90Days" | "last365Days";
6256
6258
  } | undefined;
6259
+ eventType?: string | undefined;
6260
+ "legalStatuses.REGISTERED.createdAtLocation"?: {
6261
+ type: "exact";
6262
+ term: string;
6263
+ } | {
6264
+ type: "within";
6265
+ location: string;
6266
+ } | undefined;
6267
+ "legalStatuses.REGISTERED.registrationNumber"?: {
6268
+ type: "exact";
6269
+ term: string;
6270
+ } | undefined;
6257
6271
  updatedByUserRole?: {
6258
6272
  type: "exact";
6259
6273
  term: string | {
@@ -6296,18 +6310,6 @@ export declare const appRouter: import("@trpc/server").TRPCBuiltRouter<{
6296
6310
  type: "timePeriod";
6297
6311
  term: "last7Days" | "last30Days" | "last90Days" | "last365Days";
6298
6312
  } | undefined;
6299
- eventType?: string | undefined;
6300
- "legalStatuses.REGISTERED.createdAtLocation"?: {
6301
- type: "exact";
6302
- term: string;
6303
- } | {
6304
- type: "within";
6305
- location: string;
6306
- } | undefined;
6307
- "legalStatuses.REGISTERED.registrationNumber"?: {
6308
- type: "exact";
6309
- term: string;
6310
- } | undefined;
6311
6313
  }[];
6312
6314
  } | {
6313
6315
  type: "and";
@@ -6377,6 +6379,18 @@ export declare const appRouter: import("@trpc/server").TRPCBuiltRouter<{
6377
6379
  type: "timePeriod";
6378
6380
  term: "last7Days" | "last30Days" | "last90Days" | "last365Days";
6379
6381
  } | undefined;
6382
+ eventType?: string | undefined;
6383
+ "legalStatuses.REGISTERED.createdAtLocation"?: {
6384
+ type: "exact";
6385
+ term: string;
6386
+ } | {
6387
+ type: "within";
6388
+ location: string;
6389
+ } | undefined;
6390
+ "legalStatuses.REGISTERED.registrationNumber"?: {
6391
+ type: "exact";
6392
+ term: string;
6393
+ } | undefined;
6380
6394
  updatedByUserRole?: {
6381
6395
  type: "exact";
6382
6396
  term: string | {
@@ -6419,21 +6433,8 @@ export declare const appRouter: import("@trpc/server").TRPCBuiltRouter<{
6419
6433
  type: "timePeriod";
6420
6434
  term: "last7Days" | "last30Days" | "last90Days" | "last365Days";
6421
6435
  } | undefined;
6422
- eventType?: string | undefined;
6423
- "legalStatuses.REGISTERED.createdAtLocation"?: {
6424
- type: "exact";
6425
- term: string;
6426
- } | {
6427
- type: "within";
6428
- location: string;
6429
- } | undefined;
6430
- "legalStatuses.REGISTERED.registrationNumber"?: {
6431
- type: "exact";
6432
- term: string;
6433
- } | undefined;
6434
6436
  }[];
6435
6437
  };
6436
- icon: "Validated" | "Registered" | "Certified" | "Archived" | "List" | "Draft" | "Archive" | "IdentificationCard" | "Check" | "Assigned" | "Close" | "Collapse" | "DuplicateYellow" | "Expand" | "ExternalValidate" | "FilledCheck" | "InReview" | "Offline" | "RequiresUpdates" | "Sent" | "WaitingApproval" | "ChartActivity" | "Activity" | "ArchiveTray" | "ArrowLeft" | "ArrowRight" | "Buildings" | "Circle" | "CaretDown" | "CaretLeft" | "CaretRight" | "ChartBar" | "ChartLine" | "ChatCircle" | "CheckSquare" | "Compass" | "Copy" | "Database" | "DotsThreeVertical" | "ArrowCounterClockwise" | "MagnifyingGlassMinus" | "MagnifyingGlassPlus" | "Export" | "Eye" | "EyeSlash" | "Envelope" | "File" | "FileSearch" | "FileMinus" | "FilePlus" | "FileText" | "FileX" | "Handshake" | "Gear" | "GitBranch" | "ListBullets" | "Lock" | "MagnifyingGlass" | "MapPin" | "Medal" | "NotePencil" | "Paperclip" | "PaperPlaneTilt" | "Pen" | "Pencil" | "PencilSimpleLine" | "Phone" | "Plus" | "Printer" | "SignOut" | "Star" | "Target" | "TextT" | "Trash" | "UploadSimple" | "User" | "UserPlus" | "Users" | "WarningCircle" | "X" | "CircleWavyCheck" | "CircleWavyQuestion" | "ArchiveBox" | "ArrowCircleDown" | "FileArrowUp" | "FileDotted" | "Files" | "PencilLine" | "PencilCircle" | "UserCircle" | "Clock" | "QrCode" | "Webcam" | "Sun" | "DeviceTabletCamera" | "Globe" | "Fingerprint" | "PushPin" | "Timer";
6437
6438
  slug: string;
6438
6439
  columns: {
6439
6440
  value: {
@@ -1,11 +1,12 @@
1
1
  import { EventDocument } from '../events/EventDocument';
2
- import { EventState } from '../events/ActionDocument';
2
+ import { ActionUpdate, EventState } from '../events/ActionDocument';
3
3
  import { ITokenPayload as TokenPayload, Scope } from '../authentication';
4
4
  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 { FieldReference } from '../events/FieldConfig';
8
+ import { CodeToEvaluate, FieldReference } from '../events/FieldConfig';
9
+ import type { ClientFunctionContext } from './validate';
9
10
  /** @knipignore */
10
11
  export type JSONSchema = {
11
12
  $id: string;
@@ -24,7 +25,7 @@ export type EventConditionalParameters = CommonConditionalParameters & {
24
25
  $event: EventDocument;
25
26
  };
26
27
  export type FormConditionalParameters = CommonConditionalParameters & {
27
- $form: EventState | Record<string, unknown>;
28
+ $form: EventState | ActionUpdate;
28
29
  $leafAdminStructureLocationIds?: Array<{
29
30
  id: UUID;
30
31
  }>;
@@ -81,7 +82,9 @@ export declare const user: typeof userSerializer & {
81
82
  };
82
83
  };
83
84
  export declare function isFieldReference(value: unknown): value is FieldReference;
84
- export declare function isEventFieldReference(value: unknown): value is FieldReference;
85
+ export declare function isEventFieldReference(value: unknown): value is {
86
+ $$event: string;
87
+ };
85
88
  /**
86
89
  * Generate conditional rules for a form field.
87
90
  *
@@ -172,6 +175,37 @@ export declare function createFieldConditionals(fieldId: string): {
172
175
  * )
173
176
  */
174
177
  object: (options: Record<string, any>) => JSONSchema;
178
+ /**
179
+ * Custom client-side validator. The provided function is serialised and executed
180
+ * just-in-time on the client only. External references (e.g. lodash) are not
181
+ * available inside the function body — all logic must be self-contained.
182
+ *
183
+ * @example
184
+ * field('nid').customClientValidator((value) => {
185
+ * // LUHN check — all logic must be inline
186
+ * const digits = String(value).split('').map(Number)
187
+ * // ...
188
+ * return isValid
189
+ * })
190
+ */
191
+ customClientValidator(validationFn: (fieldValue: unknown, context: ClientFunctionContext) => boolean): JSONSchema;
192
+ /**
193
+ * Custom client-side evaluation. Returns a {@link FieldReference} descriptor
194
+ * that can be used as the `value` property or a DATA component entry.
195
+ * The function receives the referenced field's value as the first argument and
196
+ * the full form context as the second; its return value replaces the field reference.
197
+ * The function is serialised and executed just-in-time on the client only.
198
+ * External references (e.g. lodash) are not available inside the function body.
199
+ *
200
+ * For computing a default value without referencing a specific field, use
201
+ * `evaluate(fn)` in the `defaultValue` property instead.
202
+ *
203
+ * @example
204
+ * field('a').customClientEvaluation((aValue, ctx) =>
205
+ * Number(aValue) + Number(ctx.$form.b)
206
+ * )
207
+ */
208
+ customClientEvaluation(computationFn: (fieldValue: unknown, context: ClientFunctionContext) => unknown): CodeToEvaluate;
175
209
  };
176
210
  asDob(): any;
177
211
  asAge(): any;
@@ -231,6 +265,37 @@ export declare function createFieldConditionals(fieldId: string): {
231
265
  * )
232
266
  */
233
267
  object: (options: Record<string, any>) => JSONSchema;
268
+ /**
269
+ * Custom client-side validator. The provided function is serialised and executed
270
+ * just-in-time on the client only. External references (e.g. lodash) are not
271
+ * available inside the function body — all logic must be self-contained.
272
+ *
273
+ * @example
274
+ * field('nid').customClientValidator((value) => {
275
+ * // LUHN check — all logic must be inline
276
+ * const digits = String(value).split('').map(Number)
277
+ * // ...
278
+ * return isValid
279
+ * })
280
+ */
281
+ customClientValidator(validationFn: (fieldValue: unknown, context: ClientFunctionContext) => boolean): JSONSchema;
282
+ /**
283
+ * Custom client-side evaluation. Returns a {@link FieldReference} descriptor
284
+ * that can be used as the `value` property or a DATA component entry.
285
+ * The function receives the referenced field's value as the first argument and
286
+ * the full form context as the second; its return value replaces the field reference.
287
+ * The function is serialised and executed just-in-time on the client only.
288
+ * External references (e.g. lodash) are not available inside the function body.
289
+ *
290
+ * For computing a default value without referencing a specific field, use
291
+ * `evaluate(fn)` in the `defaultValue` property instead.
292
+ *
293
+ * @example
294
+ * field('a').customClientEvaluation((aValue, ctx) =>
295
+ * Number(aValue) + Number(ctx.$form.b)
296
+ * )
297
+ */
298
+ customClientEvaluation(computationFn: (fieldValue: unknown, context: ClientFunctionContext) => unknown): CodeToEvaluate;
234
299
  };
235
300
  getByPath(fieldPath: string[]): {
236
301
  $$subfield: string[];
@@ -304,6 +369,37 @@ export declare function createFieldConditionals(fieldId: string): {
304
369
  * )
305
370
  */
306
371
  object: (options: Record<string, any>) => JSONSchema;
372
+ /**
373
+ * Custom client-side validator. The provided function is serialised and executed
374
+ * just-in-time on the client only. External references (e.g. lodash) are not
375
+ * available inside the function body — all logic must be self-contained.
376
+ *
377
+ * @example
378
+ * field('nid').customClientValidator((value) => {
379
+ * // LUHN check — all logic must be inline
380
+ * const digits = String(value).split('').map(Number)
381
+ * // ...
382
+ * return isValid
383
+ * })
384
+ */
385
+ customClientValidator(validationFn: (fieldValue: unknown, context: ClientFunctionContext) => boolean): JSONSchema;
386
+ /**
387
+ * Custom client-side evaluation. Returns a {@link FieldReference} descriptor
388
+ * that can be used as the `value` property or a DATA component entry.
389
+ * The function receives the referenced field's value as the first argument and
390
+ * the full form context as the second; its return value replaces the field reference.
391
+ * The function is serialised and executed just-in-time on the client only.
392
+ * External references (e.g. lodash) are not available inside the function body.
393
+ *
394
+ * For computing a default value without referencing a specific field, use
395
+ * `evaluate(fn)` in the `defaultValue` property instead.
396
+ *
397
+ * @example
398
+ * field('a').customClientEvaluation((aValue, ctx) =>
399
+ * Number(aValue) + Number(ctx.$form.b)
400
+ * )
401
+ */
402
+ customClientEvaluation(computationFn: (fieldValue: unknown, context: ClientFunctionContext) => unknown): CodeToEvaluate;
307
403
  };
308
404
  getByPath(fieldPath: string[]): any;
309
405
  asDob(): {
@@ -372,6 +468,37 @@ export declare function createFieldConditionals(fieldId: string): {
372
468
  * )
373
469
  */
374
470
  object: (options: Record<string, any>) => JSONSchema;
471
+ /**
472
+ * Custom client-side validator. The provided function is serialised and executed
473
+ * just-in-time on the client only. External references (e.g. lodash) are not
474
+ * available inside the function body — all logic must be self-contained.
475
+ *
476
+ * @example
477
+ * field('nid').customClientValidator((value) => {
478
+ * // LUHN check — all logic must be inline
479
+ * const digits = String(value).split('').map(Number)
480
+ * // ...
481
+ * return isValid
482
+ * })
483
+ */
484
+ customClientValidator(validationFn: (fieldValue: unknown, context: ClientFunctionContext) => boolean): JSONSchema;
485
+ /**
486
+ * Custom client-side evaluation. Returns a {@link FieldReference} descriptor
487
+ * that can be used as the `value` property or a DATA component entry.
488
+ * The function receives the referenced field's value as the first argument and
489
+ * the full form context as the second; its return value replaces the field reference.
490
+ * The function is serialised and executed just-in-time on the client only.
491
+ * External references (e.g. lodash) are not available inside the function body.
492
+ *
493
+ * For computing a default value without referencing a specific field, use
494
+ * `evaluate(fn)` in the `defaultValue` property instead.
495
+ *
496
+ * @example
497
+ * field('a').customClientEvaluation((aValue, ctx) =>
498
+ * Number(aValue) + Number(ctx.$form.b)
499
+ * )
500
+ */
501
+ customClientEvaluation(computationFn: (fieldValue: unknown, context: ClientFunctionContext) => unknown): CodeToEvaluate;
375
502
  };
376
503
  asAge(): {
377
504
  $$subfield: string[];
@@ -439,6 +566,37 @@ export declare function createFieldConditionals(fieldId: string): {
439
566
  * )
440
567
  */
441
568
  object: (options: Record<string, any>) => JSONSchema;
569
+ /**
570
+ * Custom client-side validator. The provided function is serialised and executed
571
+ * just-in-time on the client only. External references (e.g. lodash) are not
572
+ * available inside the function body — all logic must be self-contained.
573
+ *
574
+ * @example
575
+ * field('nid').customClientValidator((value) => {
576
+ * // LUHN check — all logic must be inline
577
+ * const digits = String(value).split('').map(Number)
578
+ * // ...
579
+ * return isValid
580
+ * })
581
+ */
582
+ customClientValidator(validationFn: (fieldValue: unknown, context: ClientFunctionContext) => boolean): JSONSchema;
583
+ /**
584
+ * Custom client-side evaluation. Returns a {@link FieldReference} descriptor
585
+ * that can be used as the `value` property or a DATA component entry.
586
+ * The function receives the referenced field's value as the first argument and
587
+ * the full form context as the second; its return value replaces the field reference.
588
+ * The function is serialised and executed just-in-time on the client only.
589
+ * External references (e.g. lodash) are not available inside the function body.
590
+ *
591
+ * For computing a default value without referencing a specific field, use
592
+ * `evaluate(fn)` in the `defaultValue` property instead.
593
+ *
594
+ * @example
595
+ * field('a').customClientEvaluation((aValue, ctx) =>
596
+ * Number(aValue) + Number(ctx.$form.b)
597
+ * )
598
+ */
599
+ customClientEvaluation(computationFn: (fieldValue: unknown, context: ClientFunctionContext) => unknown): CodeToEvaluate;
442
600
  };
443
601
  isAfter(): {
444
602
  days: (days: number) => {
@@ -496,6 +654,37 @@ export declare function createFieldConditionals(fieldId: string): {
496
654
  * )
497
655
  */
498
656
  object: (options: Record<string, any>) => JSONSchema;
657
+ /**
658
+ * Custom client-side validator. The provided function is serialised and executed
659
+ * just-in-time on the client only. External references (e.g. lodash) are not
660
+ * available inside the function body — all logic must be self-contained.
661
+ *
662
+ * @example
663
+ * field('nid').customClientValidator((value) => {
664
+ * // LUHN check — all logic must be inline
665
+ * const digits = String(value).split('').map(Number)
666
+ * // ...
667
+ * return isValid
668
+ * })
669
+ */
670
+ customClientValidator(validationFn: (fieldValue: unknown, context: ClientFunctionContext) => boolean): JSONSchema;
671
+ /**
672
+ * Custom client-side evaluation. Returns a {@link FieldReference} descriptor
673
+ * that can be used as the `value` property or a DATA component entry.
674
+ * The function receives the referenced field's value as the first argument and
675
+ * the full form context as the second; its return value replaces the field reference.
676
+ * The function is serialised and executed just-in-time on the client only.
677
+ * External references (e.g. lodash) are not available inside the function body.
678
+ *
679
+ * For computing a default value without referencing a specific field, use
680
+ * `evaluate(fn)` in the `defaultValue` property instead.
681
+ *
682
+ * @example
683
+ * field('a').customClientEvaluation((aValue, ctx) =>
684
+ * Number(aValue) + Number(ctx.$form.b)
685
+ * )
686
+ */
687
+ customClientEvaluation(computationFn: (fieldValue: unknown, context: ClientFunctionContext) => unknown): CodeToEvaluate;
499
688
  };
500
689
  asDob(): {
501
690
  $$subfield: string[];
@@ -570,6 +759,37 @@ export declare function createFieldConditionals(fieldId: string): {
570
759
  * )
571
760
  */
572
761
  object: (options: Record<string, any>) => JSONSchema;
762
+ /**
763
+ * Custom client-side validator. The provided function is serialised and executed
764
+ * just-in-time on the client only. External references (e.g. lodash) are not
765
+ * available inside the function body — all logic must be self-contained.
766
+ *
767
+ * @example
768
+ * field('nid').customClientValidator((value) => {
769
+ * // LUHN check — all logic must be inline
770
+ * const digits = String(value).split('').map(Number)
771
+ * // ...
772
+ * return isValid
773
+ * })
774
+ */
775
+ customClientValidator(validationFn: (fieldValue: unknown, context: ClientFunctionContext) => boolean): JSONSchema;
776
+ /**
777
+ * Custom client-side evaluation. Returns a {@link FieldReference} descriptor
778
+ * that can be used as the `value` property or a DATA component entry.
779
+ * The function receives the referenced field's value as the first argument and
780
+ * the full form context as the second; its return value replaces the field reference.
781
+ * The function is serialised and executed just-in-time on the client only.
782
+ * External references (e.g. lodash) are not available inside the function body.
783
+ *
784
+ * For computing a default value without referencing a specific field, use
785
+ * `evaluate(fn)` in the `defaultValue` property instead.
786
+ *
787
+ * @example
788
+ * field('a').customClientEvaluation((aValue, ctx) =>
789
+ * Number(aValue) + Number(ctx.$form.b)
790
+ * )
791
+ */
792
+ customClientEvaluation(computationFn: (fieldValue: unknown, context: ClientFunctionContext) => unknown): CodeToEvaluate;
573
793
  };
574
794
  asDob(): any;
575
795
  asAge(): any;
@@ -629,6 +849,37 @@ export declare function createFieldConditionals(fieldId: string): {
629
849
  * )
630
850
  */
631
851
  object: (options: Record<string, any>) => JSONSchema;
852
+ /**
853
+ * Custom client-side validator. The provided function is serialised and executed
854
+ * just-in-time on the client only. External references (e.g. lodash) are not
855
+ * available inside the function body — all logic must be self-contained.
856
+ *
857
+ * @example
858
+ * field('nid').customClientValidator((value) => {
859
+ * // LUHN check — all logic must be inline
860
+ * const digits = String(value).split('').map(Number)
861
+ * // ...
862
+ * return isValid
863
+ * })
864
+ */
865
+ customClientValidator(validationFn: (fieldValue: unknown, context: ClientFunctionContext) => boolean): JSONSchema;
866
+ /**
867
+ * Custom client-side evaluation. Returns a {@link FieldReference} descriptor
868
+ * that can be used as the `value` property or a DATA component entry.
869
+ * The function receives the referenced field's value as the first argument and
870
+ * the full form context as the second; its return value replaces the field reference.
871
+ * The function is serialised and executed just-in-time on the client only.
872
+ * External references (e.g. lodash) are not available inside the function body.
873
+ *
874
+ * For computing a default value without referencing a specific field, use
875
+ * `evaluate(fn)` in the `defaultValue` property instead.
876
+ *
877
+ * @example
878
+ * field('a').customClientEvaluation((aValue, ctx) =>
879
+ * Number(aValue) + Number(ctx.$form.b)
880
+ * )
881
+ */
882
+ customClientEvaluation(computationFn: (fieldValue: unknown, context: ClientFunctionContext) => unknown): CodeToEvaluate;
632
883
  };
633
884
  asAge(): {
634
885
  $$subfield: string[];
@@ -703,6 +954,37 @@ export declare function createFieldConditionals(fieldId: string): {
703
954
  * )
704
955
  */
705
956
  object: (options: Record<string, any>) => JSONSchema;
957
+ /**
958
+ * Custom client-side validator. The provided function is serialised and executed
959
+ * just-in-time on the client only. External references (e.g. lodash) are not
960
+ * available inside the function body — all logic must be self-contained.
961
+ *
962
+ * @example
963
+ * field('nid').customClientValidator((value) => {
964
+ * // LUHN check — all logic must be inline
965
+ * const digits = String(value).split('').map(Number)
966
+ * // ...
967
+ * return isValid
968
+ * })
969
+ */
970
+ customClientValidator(validationFn: (fieldValue: unknown, context: ClientFunctionContext) => boolean): JSONSchema;
971
+ /**
972
+ * Custom client-side evaluation. Returns a {@link FieldReference} descriptor
973
+ * that can be used as the `value` property or a DATA component entry.
974
+ * The function receives the referenced field's value as the first argument and
975
+ * the full form context as the second; its return value replaces the field reference.
976
+ * The function is serialised and executed just-in-time on the client only.
977
+ * External references (e.g. lodash) are not available inside the function body.
978
+ *
979
+ * For computing a default value without referencing a specific field, use
980
+ * `evaluate(fn)` in the `defaultValue` property instead.
981
+ *
982
+ * @example
983
+ * field('a').customClientEvaluation((aValue, ctx) =>
984
+ * Number(aValue) + Number(ctx.$form.b)
985
+ * )
986
+ */
987
+ customClientEvaluation(computationFn: (fieldValue: unknown, context: ClientFunctionContext) => unknown): CodeToEvaluate;
706
988
  };
707
989
  asDob(): any;
708
990
  asAge(): any;
@@ -762,6 +1044,37 @@ export declare function createFieldConditionals(fieldId: string): {
762
1044
  * )
763
1045
  */
764
1046
  object: (options: Record<string, any>) => JSONSchema;
1047
+ /**
1048
+ * Custom client-side validator. The provided function is serialised and executed
1049
+ * just-in-time on the client only. External references (e.g. lodash) are not
1050
+ * available inside the function body — all logic must be self-contained.
1051
+ *
1052
+ * @example
1053
+ * field('nid').customClientValidator((value) => {
1054
+ * // LUHN check — all logic must be inline
1055
+ * const digits = String(value).split('').map(Number)
1056
+ * // ...
1057
+ * return isValid
1058
+ * })
1059
+ */
1060
+ customClientValidator(validationFn: (fieldValue: unknown, context: ClientFunctionContext) => boolean): JSONSchema;
1061
+ /**
1062
+ * Custom client-side evaluation. Returns a {@link FieldReference} descriptor
1063
+ * that can be used as the `value` property or a DATA component entry.
1064
+ * The function receives the referenced field's value as the first argument and
1065
+ * the full form context as the second; its return value replaces the field reference.
1066
+ * The function is serialised and executed just-in-time on the client only.
1067
+ * External references (e.g. lodash) are not available inside the function body.
1068
+ *
1069
+ * For computing a default value without referencing a specific field, use
1070
+ * `evaluate(fn)` in the `defaultValue` property instead.
1071
+ *
1072
+ * @example
1073
+ * field('a').customClientEvaluation((aValue, ctx) =>
1074
+ * Number(aValue) + Number(ctx.$form.b)
1075
+ * )
1076
+ */
1077
+ customClientEvaluation(computationFn: (fieldValue: unknown, context: ClientFunctionContext) => unknown): CodeToEvaluate;
765
1078
  };
766
1079
  isAfter(): {
767
1080
  days: (days: number) => {
@@ -819,6 +1132,37 @@ export declare function createFieldConditionals(fieldId: string): {
819
1132
  * )
820
1133
  */
821
1134
  object: (options: Record<string, any>) => JSONSchema;
1135
+ /**
1136
+ * Custom client-side validator. The provided function is serialised and executed
1137
+ * just-in-time on the client only. External references (e.g. lodash) are not
1138
+ * available inside the function body — all logic must be self-contained.
1139
+ *
1140
+ * @example
1141
+ * field('nid').customClientValidator((value) => {
1142
+ * // LUHN check — all logic must be inline
1143
+ * const digits = String(value).split('').map(Number)
1144
+ * // ...
1145
+ * return isValid
1146
+ * })
1147
+ */
1148
+ customClientValidator(validationFn: (fieldValue: unknown, context: ClientFunctionContext) => boolean): JSONSchema;
1149
+ /**
1150
+ * Custom client-side evaluation. Returns a {@link FieldReference} descriptor
1151
+ * that can be used as the `value` property or a DATA component entry.
1152
+ * The function receives the referenced field's value as the first argument and
1153
+ * the full form context as the second; its return value replaces the field reference.
1154
+ * The function is serialised and executed just-in-time on the client only.
1155
+ * External references (e.g. lodash) are not available inside the function body.
1156
+ *
1157
+ * For computing a default value without referencing a specific field, use
1158
+ * `evaluate(fn)` in the `defaultValue` property instead.
1159
+ *
1160
+ * @example
1161
+ * field('a').customClientEvaluation((aValue, ctx) =>
1162
+ * Number(aValue) + Number(ctx.$form.b)
1163
+ * )
1164
+ */
1165
+ customClientEvaluation(computationFn: (fieldValue: unknown, context: ClientFunctionContext) => unknown): CodeToEvaluate;
822
1166
  };
823
1167
  export {};
824
1168
  //# sourceMappingURL=conditionals.d.ts.map
@@ -9,6 +9,46 @@ import { UUID } from '../uuid';
9
9
  import { FormState } from '../events/utils';
10
10
  import { ActionType } from '../events/ActionType';
11
11
  import { EventDocument } from '../events/EventDocument';
12
+ import { Location } from '../events/locations';
13
+ import { SystemVariables } from '../events/TemplateConfig';
14
+ /** Returns today's date as an ISO date string (YYYY-MM-DD). */
15
+ export declare function todayISO(): string;
16
+ /**
17
+ * Context passed to every serialised client-side function ({@link runClientFunction}).
18
+ *
19
+ * `$user` (full {@link ITokenPayload}, validator paths) and `user` (a
20
+ * {@link SystemVariables} subset for template substitution, default-value
21
+ * path) are distinct sources, not duplicates.
22
+ */
23
+ export type ClientFunctionContext = {
24
+ $form: EventState | ActionUpdate;
25
+ $now: string;
26
+ $online: boolean;
27
+ $user?: ITokenPayload;
28
+ $event?: EventDocument;
29
+ $leafAdminStructureLocationIds: Array<{
30
+ id: UUID;
31
+ }>;
32
+ user?: SystemVariables['user'];
33
+ $window?: SystemVariables['$window'];
34
+ locations?: Location[];
35
+ adminLevelIds?: string[];
36
+ };
37
+ type CompiledClientFunction = (data: FieldValue | undefined, context: ClientFunctionContext) => unknown;
38
+ /**
39
+ * Deserialises a serialised function string (produced by `.toString()`) into a callable.
40
+ * Results are cached by code string so each unique function body is compiled at most once.
41
+ * Runs in a clean scope — no access to outer closures or external imports.
42
+ */
43
+ export declare function compileClientFunction(code: string): CompiledClientFunction;
44
+ export declare function buildClientFunctionContext(input: {
45
+ form: EventState | ActionUpdate;
46
+ validatorContext?: ValidatorContext;
47
+ systemVariables?: SystemVariables;
48
+ locations?: Location[];
49
+ adminLevelIds?: string[];
50
+ }): ClientFunctionContext;
51
+ export declare function runClientFunction(code: string, data: FieldValue | undefined, context: ClientFunctionContext): unknown;
12
52
  export declare function validate(schema: JSONSchema, data: ConditionalParameters): boolean;
13
53
  export declare function validateValue(schema: JSONSchema, data: unknown): boolean;
14
54
  export declare function isOnline(): boolean;
@@ -102,4 +142,5 @@ export declare function runFieldValidations({ field: config, form, value, contex
102
142
  }>>;
103
143
  export declare function getValidatorsForField(fieldId: FieldConfig['id'], validations: NonNullable<FieldConfig['validation']>): NonNullable<FieldConfig['validation']>;
104
144
  export declare function areCertificateConditionsMet(conditions: FieldConditional[], values: ConditionalParameters): boolean;
145
+ export {};
105
146
  //# sourceMappingURL=validate.d.ts.map