@opencrvs/toolkit 2.0.0-rc.fe35c20 → 2.0.0-rc.fe577a4

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.
@@ -58,6 +58,12 @@ export declare const CheckboxFieldValue: z.ZodBoolean;
58
58
  export type CheckboxFieldValue = z.infer<typeof CheckboxFieldValue>;
59
59
  export declare const NumberFieldValue: z.ZodNumber;
60
60
  export type NumberFieldValue = z.infer<typeof NumberFieldValue>;
61
+ export declare const SignatureFieldValue: z.ZodObject<{
62
+ path: z.core.$ZodBranded<z.ZodString, "DocumentPath", "out">;
63
+ originalFilename: z.ZodString;
64
+ type: z.ZodString;
65
+ }, z.core.$strip>;
66
+ export type SignatureFieldValue = z.infer<typeof SignatureFieldValue>;
61
67
  export declare const ButtonFieldValue: z.ZodNumber;
62
68
  export type ButtonFieldValue = z.infer<typeof ButtonFieldValue>;
63
69
  export declare const VerificationStatusValue: z.ZodEnum<{
@@ -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
@@ -241,6 +241,9 @@ export declare function getActionUpdateMetadata(actions: Action[]): Partial<{
241
241
  createdAtLocation?: (string & import("zod").$brand<"UUID">) | null | undefined;
242
242
  annotation?: Record<string, import("..").FieldUpdateValue> | null | undefined;
243
243
  originalActionId?: (string & import("zod").$brand<"UUID">) | null | undefined;
244
+ content?: {
245
+ immediateCorrection?: boolean | undefined;
246
+ } | undefined;
244
247
  } | {
245
248
  id: string & import("zod").$brand<"UUID">;
246
249
  transactionId: string;
@@ -386,6 +386,9 @@ export declare function findLastAssignmentAction(actions: Action[]): {
386
386
  createdAtLocation?: (string & import("zod").$brand<"UUID">) | null | undefined;
387
387
  annotation?: Record<string, import("./FieldValue").FieldUpdateValue> | null | undefined;
388
388
  originalActionId?: (string & import("zod").$brand<"UUID">) | null | undefined;
389
+ content?: {
390
+ immediateCorrection?: boolean | undefined;
391
+ } | undefined;
389
392
  } | {
390
393
  id: string & import("zod").$brand<"UUID">;
391
394
  transactionId: string;
@@ -559,7 +562,15 @@ export declare function timePeriodToDateRange(value: SelectDateRangeValue): {
559
562
  };
560
563
  export declare function mergeDrafts(currentDraft: Draft, incomingDraft: Draft): Draft;
561
564
  export declare function getPendingAction(actions: Action[]): ActionDocument;
562
- export declare function getCompleteActionAnnotation(annotation: ActionUpdate, event: EventDocument, action: ActionDocument): ActionUpdate;
565
+ export declare function getCompleteActionAnnotation(event: EventDocument, action: ActionDocument): ActionUpdate;
566
+ /**
567
+ * Resolves the complete content for an action, inheriting from its original
568
+ * Requested action when the Accepted action carries no content of its own.
569
+ *
570
+ * Mirrors the same "originalActionId → merge from Requested" pattern used by
571
+ * getCompleteActionAnnotation and getCompleteActionDeclaration.
572
+ */
573
+ export declare function getCompleteActionContent(event: EventDocument, action: ActionDocument): Record<string, unknown> | null | undefined;
563
574
  export declare function getCompleteActionDeclaration<T extends EventState | ActionUpdate>(declaration: T, event: EventDocument, action: ActionDocument): T;
564
575
  export declare function getAcceptedActions(event: EventDocument): ActionDocument[];
565
576
  export declare function aggregateActionDeclarations(event: EventDocument): EventState;
@@ -1005,7 +1005,54 @@ function createFieldConditionals(fieldId) {
1005
1005
  }
1006
1006
  },
1007
1007
  required: [fieldId]
1008
- })
1008
+ }),
1009
+ /**
1010
+ * Custom client-side validator. The provided function is serialised and executed
1011
+ * just-in-time on the client only. External references (e.g. lodash) are not
1012
+ * available inside the function body — all logic must be self-contained.
1013
+ *
1014
+ * @example
1015
+ * field('nid').customClientValidator((value) => {
1016
+ * // LUHN check — all logic must be inline
1017
+ * const digits = String(value).split('').map(Number)
1018
+ * // ...
1019
+ * return isValid
1020
+ * })
1021
+ */
1022
+ customClientValidator(validationFn) {
1023
+ const code = validationFn.toString();
1024
+ return defineFormConditional({
1025
+ type: "object",
1026
+ properties: wrapToPath(
1027
+ { [fieldId]: { customClientValidator: { code } } },
1028
+ this.$$subfield
1029
+ ),
1030
+ required: [fieldId]
1031
+ });
1032
+ },
1033
+ /**
1034
+ * Custom client-side evaluation. Returns a {@link FieldReference} descriptor
1035
+ * that can be used as the `value` property or a DATA component entry.
1036
+ * The function receives the referenced field's value as the first argument and
1037
+ * the full form context as the second; its return value replaces the field reference.
1038
+ * The function is serialised and executed just-in-time on the client only.
1039
+ * External references (e.g. lodash) are not available inside the function body.
1040
+ *
1041
+ * For computing a default value without referencing a specific field, use
1042
+ * `evaluate(fn)` in the `defaultValue` property instead.
1043
+ *
1044
+ * @example
1045
+ * field('a').customClientEvaluation((aValue, ctx) =>
1046
+ * Number(aValue) + Number(ctx.$form.b)
1047
+ * )
1048
+ */
1049
+ customClientEvaluation(computationFn) {
1050
+ return {
1051
+ $$code: computationFn.toString(),
1052
+ $$field: fieldId,
1053
+ $$subfield: this.$$subfield
1054
+ };
1055
+ }
1009
1056
  };
1010
1057
  }
1011
1058