@opencrvs/toolkit 1.9.13 → 1.9.14

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.
@@ -33,8 +33,8 @@ export declare const defineConfig: (config: EventConfigInput) => {
33
33
  };
34
34
  deduplication?: {
35
35
  id: string;
36
- query: import("./DeduplicationConfig").ClauseOutput;
37
36
  label: import("./TranslationConfig").TranslationConfig;
37
+ query: import("./DeduplicationConfig").ClauseOutput;
38
38
  } | undefined;
39
39
  } | {
40
40
  type: "VALIDATE";
@@ -45,8 +45,8 @@ export declare const defineConfig: (config: EventConfigInput) => {
45
45
  };
46
46
  deduplication?: {
47
47
  id: string;
48
- query: import("./DeduplicationConfig").ClauseOutput;
49
48
  label: import("./TranslationConfig").TranslationConfig;
49
+ query: import("./DeduplicationConfig").ClauseOutput;
50
50
  } | undefined;
51
51
  } | {
52
52
  type: "REJECT";
@@ -63,8 +63,8 @@ export declare const defineConfig: (config: EventConfigInput) => {
63
63
  };
64
64
  deduplication?: {
65
65
  id: string;
66
- query: import("./DeduplicationConfig").ClauseOutput;
67
66
  label: import("./TranslationConfig").TranslationConfig;
67
+ query: import("./DeduplicationConfig").ClauseOutput;
68
68
  } | undefined;
69
69
  } | {
70
70
  type: "DELETE";
@@ -167,7 +167,7 @@ export declare const defineConfig: (config: EventConfigInput) => {
167
167
  title: import("./TranslationConfig").TranslationConfig;
168
168
  fields: ({
169
169
  config: {
170
- type: "exact" | "fuzzy" | "range" | "within";
170
+ type: "exact" | "range" | "fuzzy" | "within";
171
171
  searchFields?: string[] | undefined;
172
172
  };
173
173
  fieldId: string;
@@ -202,10 +202,10 @@ export declare const defineConfig: (config: EventConfigInput) => {
202
202
  }[] | undefined;
203
203
  } | {
204
204
  config: {
205
- type: "exact" | "fuzzy" | "range" | "within";
205
+ type: "exact" | "range" | "fuzzy" | "within";
206
206
  searchFields?: string[] | undefined;
207
207
  };
208
- fieldId: "event.status" | "event.trackingId" | "event.updatedAt" | "event.legalStatuses.REGISTERED.acceptedAt" | "event.legalStatuses.REGISTERED.createdAtLocation" | "event.legalStatuses.REGISTERED.registrationNumber";
208
+ fieldId: "event.trackingId" | "event.status" | "event.legalStatuses.REGISTERED.acceptedAt" | "event.legalStatuses.REGISTERED.createdAtLocation" | "event.legalStatuses.REGISTERED.registrationNumber" | "event.updatedAt";
209
209
  fieldType: "event";
210
210
  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;
211
211
  options?: {
@@ -240,8 +240,9 @@ export declare const defineConfig: (config: EventConfigInput) => {
240
240
  dateOfEvent?: {
241
241
  $$field: string;
242
242
  $$subfield: string[];
243
+ $$code?: string | undefined;
243
244
  } | {
244
- $$event: "createdAt" | "updatedAt" | "legalStatuses.DECLARED.createdAt" | "legalStatuses.DECLARED.acceptedAt" | "legalStatuses.REGISTERED.createdAt" | "legalStatuses.REGISTERED.acceptedAt";
245
+ $$event: "createdAt" | "updatedAt" | "legalStatuses.REGISTERED.acceptedAt" | "legalStatuses.DECLARED.createdAt" | "legalStatuses.DECLARED.acceptedAt" | "legalStatuses.REGISTERED.createdAt";
245
246
  } | undefined;
246
247
  fallbackTitle?: import("./TranslationConfig").TranslationConfig | undefined;
247
248
  };
@@ -1,6 +1,30 @@
1
+ import { FormConditionalParameters } from '../conditionals/conditionals';
1
2
  import { FieldConditional } from './Conditional';
2
3
  import { TranslationConfig } from './TranslationConfig';
3
- import { SelectOption, ValidationConfig } from './FieldConfig';
4
+ import { ComputedDefaultValue, SelectOption, ValidationConfig } from './FieldConfig';
5
+ /**
6
+ * Creates a {@link ComputedDefaultValue} descriptor for use in a field's `defaultValue`.
7
+ *
8
+ * Unlike `field(id).customClientEvaluation(fn)`, this builder is **not tied to any
9
+ * specific field**. Use it when the initial value should be derived purely from
10
+ * context variables (`$now`, `$online`, system variables such as `$user`) rather
11
+ * than from another field's current value.
12
+ *
13
+ * The serialised function receives `(undefined, context)` at runtime, where
14
+ * `context` is a {@link FormConditionalParameters} object.
15
+ *
16
+ * External references (e.g. lodash) are **not** available inside the function body —
17
+ * all logic must be self-contained so the code survives serialisation.
18
+ *
19
+ * @example
20
+ * // Default a date field to today
21
+ * defaultValue: evaluate((_, ctx) => ctx.$now)
22
+ *
23
+ * @example
24
+ * // Default to the current user's role
25
+ * defaultValue: evaluate((_, ctx) => ctx.user.role)
26
+ */
27
+ export declare function evaluate(computationFn: (fieldValue: undefined, context: FormConditionalParameters) => unknown): ComputedDefaultValue;
4
28
  /**
5
29
  * Entry point for defining conditional logic or configuration for a form field.
6
30
  * @param fieldId - The ID of the field to define rules or config for.
@@ -107,6 +131,8 @@ export declare function field(fieldId: string, options?: {
107
131
  fieldId: string;
108
132
  };
109
133
  object: (options: Record<string, any>) => import("../conditionals/conditionals").JSONSchema;
134
+ customClientValidator(validationFn: (fieldValue: unknown, context: import(".").ClientFunctionContext) => boolean): import("../conditionals/conditionals").JSONSchema;
135
+ customClientEvaluation(computationFn: (fieldValue: unknown, context: import(".").ClientFunctionContext) => unknown): import("./FieldConfig").CodeToEvaluate;
110
136
  };
111
137
  asDob(): any;
112
138
  asAge(): any;
@@ -144,6 +170,8 @@ export declare function field(fieldId: string, options?: {
144
170
  fieldId: string;
145
171
  };
146
172
  object: (options: Record<string, any>) => import("../conditionals/conditionals").JSONSchema;
173
+ customClientValidator(validationFn: (fieldValue: unknown, context: import(".").ClientFunctionContext) => boolean): import("../conditionals/conditionals").JSONSchema;
174
+ customClientEvaluation(computationFn: (fieldValue: unknown, context: import(".").ClientFunctionContext) => unknown): import("./FieldConfig").CodeToEvaluate;
147
175
  };
148
176
  getByPath(fieldPath: string[]): {
149
177
  $$subfield: string[];
@@ -189,6 +217,8 @@ export declare function field(fieldId: string, options?: {
189
217
  fieldId: string;
190
218
  };
191
219
  object: (options: Record<string, any>) => import("../conditionals/conditionals").JSONSchema;
220
+ customClientValidator(validationFn: (fieldValue: unknown, context: import(".").ClientFunctionContext) => boolean): import("../conditionals/conditionals").JSONSchema;
221
+ customClientEvaluation(computationFn: (fieldValue: unknown, context: import(".").ClientFunctionContext) => unknown): import("./FieldConfig").CodeToEvaluate;
192
222
  };
193
223
  getByPath(fieldPath: string[]): any;
194
224
  asDob(): {
@@ -232,6 +262,8 @@ export declare function field(fieldId: string, options?: {
232
262
  fieldId: string;
233
263
  };
234
264
  object: (options: Record<string, any>) => import("../conditionals/conditionals").JSONSchema;
265
+ customClientValidator(validationFn: (fieldValue: unknown, context: import(".").ClientFunctionContext) => boolean): import("../conditionals/conditionals").JSONSchema;
266
+ customClientEvaluation(computationFn: (fieldValue: unknown, context: import(".").ClientFunctionContext) => unknown): import("./FieldConfig").CodeToEvaluate;
235
267
  };
236
268
  asAge(): {
237
269
  $$subfield: string[];
@@ -274,6 +306,8 @@ export declare function field(fieldId: string, options?: {
274
306
  fieldId: string;
275
307
  };
276
308
  object: (options: Record<string, any>) => import("../conditionals/conditionals").JSONSchema;
309
+ customClientValidator(validationFn: (fieldValue: unknown, context: import(".").ClientFunctionContext) => boolean): import("../conditionals/conditionals").JSONSchema;
310
+ customClientEvaluation(computationFn: (fieldValue: unknown, context: import(".").ClientFunctionContext) => unknown): import("./FieldConfig").CodeToEvaluate;
277
311
  };
278
312
  isAfter(): {
279
313
  days: (days: number) => {
@@ -309,6 +343,8 @@ export declare function field(fieldId: string, options?: {
309
343
  fieldId: string;
310
344
  };
311
345
  object: (options: Record<string, any>) => import("../conditionals/conditionals").JSONSchema;
346
+ customClientValidator(validationFn: (fieldValue: unknown, context: import(".").ClientFunctionContext) => boolean): import("../conditionals/conditionals").JSONSchema;
347
+ customClientEvaluation(computationFn: (fieldValue: unknown, context: import(".").ClientFunctionContext) => unknown): import("./FieldConfig").CodeToEvaluate;
312
348
  };
313
349
  asDob(): {
314
350
  $$subfield: string[];
@@ -355,6 +391,8 @@ export declare function field(fieldId: string, options?: {
355
391
  fieldId: string;
356
392
  };
357
393
  object: (options: Record<string, any>) => import("../conditionals/conditionals").JSONSchema;
394
+ customClientValidator(validationFn: (fieldValue: unknown, context: import(".").ClientFunctionContext) => boolean): import("../conditionals/conditionals").JSONSchema;
395
+ customClientEvaluation(computationFn: (fieldValue: unknown, context: import(".").ClientFunctionContext) => unknown): import("./FieldConfig").CodeToEvaluate;
358
396
  };
359
397
  asDob(): any;
360
398
  asAge(): any;
@@ -392,6 +430,8 @@ export declare function field(fieldId: string, options?: {
392
430
  fieldId: string;
393
431
  };
394
432
  object: (options: Record<string, any>) => import("../conditionals/conditionals").JSONSchema;
433
+ customClientValidator(validationFn: (fieldValue: unknown, context: import(".").ClientFunctionContext) => boolean): import("../conditionals/conditionals").JSONSchema;
434
+ customClientEvaluation(computationFn: (fieldValue: unknown, context: import(".").ClientFunctionContext) => unknown): import("./FieldConfig").CodeToEvaluate;
395
435
  };
396
436
  asAge(): {
397
437
  $$subfield: string[];
@@ -438,6 +478,8 @@ export declare function field(fieldId: string, options?: {
438
478
  fieldId: string;
439
479
  };
440
480
  object: (options: Record<string, any>) => import("../conditionals/conditionals").JSONSchema;
481
+ customClientValidator(validationFn: (fieldValue: unknown, context: import(".").ClientFunctionContext) => boolean): import("../conditionals/conditionals").JSONSchema;
482
+ customClientEvaluation(computationFn: (fieldValue: unknown, context: import(".").ClientFunctionContext) => unknown): import("./FieldConfig").CodeToEvaluate;
441
483
  };
442
484
  asDob(): any;
443
485
  asAge(): any;
@@ -475,6 +517,8 @@ export declare function field(fieldId: string, options?: {
475
517
  fieldId: string;
476
518
  };
477
519
  object: (options: Record<string, any>) => import("../conditionals/conditionals").JSONSchema;
520
+ customClientValidator(validationFn: (fieldValue: unknown, context: import(".").ClientFunctionContext) => boolean): import("../conditionals/conditionals").JSONSchema;
521
+ customClientEvaluation(computationFn: (fieldValue: unknown, context: import(".").ClientFunctionContext) => unknown): import("./FieldConfig").CodeToEvaluate;
478
522
  };
479
523
  isAfter(): {
480
524
  days: (days: number) => {
@@ -510,5 +554,7 @@ export declare function field(fieldId: string, options?: {
510
554
  fieldId: string;
511
555
  };
512
556
  object: (options: Record<string, any>) => import("../conditionals/conditionals").JSONSchema;
557
+ customClientValidator(validationFn: (fieldValue: unknown, context: import(".").ClientFunctionContext) => boolean): import("../conditionals/conditionals").JSONSchema;
558
+ customClientEvaluation(computationFn: (fieldValue: unknown, context: import(".").ClientFunctionContext) => unknown): import("./FieldConfig").CodeToEvaluate;
513
559
  };
514
560
  //# sourceMappingURL=field.d.ts.map
@@ -242,8 +242,8 @@ export declare function getEventConfigById(eventConfigs: EventConfig[], id: stri
242
242
  };
243
243
  deduplication?: {
244
244
  id: string;
245
- query: import("./DeduplicationConfig").ClauseOutput;
246
245
  label: import("./TranslationConfig").TranslationConfig;
246
+ query: import("./DeduplicationConfig").ClauseOutput;
247
247
  } | undefined;
248
248
  } | {
249
249
  type: "VALIDATE";
@@ -254,8 +254,8 @@ export declare function getEventConfigById(eventConfigs: EventConfig[], id: stri
254
254
  };
255
255
  deduplication?: {
256
256
  id: string;
257
- query: import("./DeduplicationConfig").ClauseOutput;
258
257
  label: import("./TranslationConfig").TranslationConfig;
258
+ query: import("./DeduplicationConfig").ClauseOutput;
259
259
  } | undefined;
260
260
  } | {
261
261
  type: "REJECT";
@@ -272,8 +272,8 @@ export declare function getEventConfigById(eventConfigs: EventConfig[], id: stri
272
272
  };
273
273
  deduplication?: {
274
274
  id: string;
275
- query: import("./DeduplicationConfig").ClauseOutput;
276
275
  label: import("./TranslationConfig").TranslationConfig;
276
+ query: import("./DeduplicationConfig").ClauseOutput;
277
277
  } | undefined;
278
278
  } | {
279
279
  type: "DELETE";
@@ -376,7 +376,7 @@ export declare function getEventConfigById(eventConfigs: EventConfig[], id: stri
376
376
  title: import("./TranslationConfig").TranslationConfig;
377
377
  fields: ({
378
378
  config: {
379
- type: "exact" | "fuzzy" | "range" | "within";
379
+ type: "exact" | "range" | "fuzzy" | "within";
380
380
  searchFields?: string[] | undefined;
381
381
  };
382
382
  fieldId: string;
@@ -411,10 +411,10 @@ export declare function getEventConfigById(eventConfigs: EventConfig[], id: stri
411
411
  }[] | undefined;
412
412
  } | {
413
413
  config: {
414
- type: "exact" | "fuzzy" | "range" | "within";
414
+ type: "exact" | "range" | "fuzzy" | "within";
415
415
  searchFields?: string[] | undefined;
416
416
  };
417
- fieldId: "event.status" | "event.trackingId" | "event.updatedAt" | "event.legalStatuses.REGISTERED.acceptedAt" | "event.legalStatuses.REGISTERED.createdAtLocation" | "event.legalStatuses.REGISTERED.registrationNumber";
417
+ fieldId: "event.trackingId" | "event.status" | "event.legalStatuses.REGISTERED.acceptedAt" | "event.legalStatuses.REGISTERED.createdAtLocation" | "event.legalStatuses.REGISTERED.registrationNumber" | "event.updatedAt";
418
418
  fieldType: "event";
419
419
  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;
420
420
  options?: {
@@ -449,8 +449,9 @@ export declare function getEventConfigById(eventConfigs: EventConfig[], id: stri
449
449
  dateOfEvent?: {
450
450
  $$field: string;
451
451
  $$subfield: string[];
452
+ $$code?: string | undefined;
452
453
  } | {
453
- $$event: "createdAt" | "updatedAt" | "legalStatuses.DECLARED.createdAt" | "legalStatuses.DECLARED.acceptedAt" | "legalStatuses.REGISTERED.createdAt" | "legalStatuses.REGISTERED.acceptedAt";
454
+ $$event: "createdAt" | "updatedAt" | "legalStatuses.REGISTERED.acceptedAt" | "legalStatuses.DECLARED.createdAt" | "legalStatuses.DECLARED.acceptedAt" | "legalStatuses.REGISTERED.createdAt";
454
455
  } | undefined;
455
456
  fallbackTitle?: import("./TranslationConfig").TranslationConfig | undefined;
456
457
  };
@@ -460,7 +461,7 @@ export declare function timePeriodToDateRange(value: SelectDateRangeValue): {
460
461
  };
461
462
  export declare function mergeDrafts(currentDraft: Draft, incomingDraft: Draft): Draft;
462
463
  export declare function getPendingAction(actions: Action[]): ActionDocument;
463
- export declare function getCompleteActionAnnotation(annotation: ActionUpdate, event: EventDocument, action: ActionDocument): ActionUpdate;
464
+ export declare function getCompleteActionAnnotation(event: EventDocument, action: ActionDocument): ActionUpdate;
464
465
  export declare function getCompleteActionDeclaration<T extends EventState | ActionUpdate>(declaration: T, event: EventDocument, action: ActionDocument): T;
465
466
  export declare function getAcceptedActions(event: EventDocument): ActionDocument[];
466
467
  export declare function aggregateActionDeclarations(event: EventDocument): EventState;
@@ -684,6 +684,53 @@ function createFieldConditionals(fieldId) {
684
684
  }
685
685
  },
686
686
  required: [fieldId]
687
- })
687
+ }),
688
+ /**
689
+ * Custom client-side validator. The provided function is serialised and executed
690
+ * just-in-time on the client only. External references (e.g. lodash) are not
691
+ * available inside the function body — all logic must be self-contained.
692
+ *
693
+ * @example
694
+ * field('nid').customClientValidator((value) => {
695
+ * // LUHN check — all logic must be inline
696
+ * const digits = String(value).split('').map(Number)
697
+ * // ...
698
+ * return isValid
699
+ * })
700
+ */
701
+ customClientValidator(validationFn) {
702
+ const code = validationFn.toString();
703
+ return defineFormConditional({
704
+ type: "object",
705
+ properties: wrapToPath(
706
+ { [fieldId]: { customClientValidator: { code } } },
707
+ this.$$subfield
708
+ ),
709
+ required: [fieldId]
710
+ });
711
+ },
712
+ /**
713
+ * Custom client-side evaluation. Returns a {@link FieldReference} descriptor
714
+ * that can be used as the `value` property or a DATA component entry.
715
+ * The function receives the referenced field's value as the first argument and
716
+ * the full form context as the second; its return value replaces the field reference.
717
+ * The function is serialised and executed just-in-time on the client only.
718
+ * External references (e.g. lodash) are not available inside the function body.
719
+ *
720
+ * For computing a default value without referencing a specific field, use
721
+ * `evaluate(fn)` in the `defaultValue` property instead.
722
+ *
723
+ * @example
724
+ * field('a').customClientEvaluation((aValue, ctx) =>
725
+ * Number(aValue) + Number(ctx.$form.b)
726
+ * )
727
+ */
728
+ customClientEvaluation(computationFn) {
729
+ return {
730
+ $$code: computationFn.toString(),
731
+ $$field: fieldId,
732
+ $$subfield: this.$$subfield
733
+ };
734
+ }
688
735
  };
689
736
  }