@opencrvs/toolkit 2.0.0-rc.c07ca60 → 2.0.0-rc.c0adb49

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.
@@ -75,6 +75,7 @@ __export(events_exports, {
75
75
  CheckboxFieldValue: () => CheckboxFieldValue,
76
76
  Clause: () => Clause,
77
77
  ClientSpecificAction: () => ClientSpecificAction,
78
+ ComputedDefaultValue: () => ComputedDefaultValue,
78
79
  Conditional: () => Conditional,
79
80
  ConditionalType: () => ConditionalType,
80
81
  ConfirmableActions: () => ConfirmableActions,
@@ -200,6 +201,7 @@ __export(events_exports, {
200
201
  SelectDateRangeValue: () => SelectDateRangeValue,
201
202
  SelectOption: () => SelectOption,
202
203
  ShowConditional: () => ShowConditional,
204
+ SignatureFieldValue: () => SignatureFieldValue,
203
205
  StaticDataEntry: () => StaticDataEntry,
204
206
  StreetLevelDetailsUpdateValue: () => StreetLevelDetailsUpdateValue,
205
207
  SummaryConfig: () => SummaryConfig,
@@ -246,10 +248,12 @@ __export(events_exports, {
246
248
  applyDraftToEventIndex: () => applyDraftToEventIndex,
247
249
  areCertificateConditionsMet: () => areCertificateConditionsMet,
248
250
  areConditionsMet: () => areConditionsMet,
251
+ buildClientFunctionContext: () => buildClientFunctionContext,
249
252
  buildFormState: () => buildFormState,
250
253
  canAccessEventWithScope: () => canAccessEventWithScope,
251
254
  canAccessOtherUserWithScopes: () => canAccessOtherUserWithScopes,
252
255
  canAccessUserWithScope: () => canAccessUserWithScope,
256
+ compileClientFunction: () => compileClientFunction,
253
257
  compositeFieldTypes: () => compositeFieldTypes,
254
258
  createEmptyDraft: () => createEmptyDraft,
255
259
  createFieldConditionals: () => createFieldConditionals,
@@ -270,6 +274,7 @@ __export(events_exports, {
270
274
  defineWorkqueuesColumns: () => defineWorkqueuesColumns,
271
275
  deserializeQuery: () => deserializeQuery,
272
276
  errorMessages: () => errorMessages,
277
+ evaluate: () => evaluate,
273
278
  event: () => event,
274
279
  eventMetadataLabelMap: () => eventMetadataLabelMap,
275
280
  eventPayloadGenerator: () => eventPayloadGenerator,
@@ -282,6 +287,7 @@ __export(events_exports, {
282
287
  findActiveDraftForEvent: () => findActiveDraftForEvent,
283
288
  findAllFields: () => findAllFields,
284
289
  findLastAssignmentAction: () => findLastAssignmentAction,
290
+ findPendingCorrectionAction: () => findPendingCorrectionAction,
285
291
  findRecordActionPages: () => findRecordActionPages,
286
292
  flag: () => flag,
287
293
  flattenFieldReference: () => flattenFieldReference,
@@ -323,6 +329,7 @@ __export(events_exports, {
323
329
  getDeclarationFields: () => getDeclarationFields,
324
330
  getDeclarationPages: () => getDeclarationPages,
325
331
  getEventConfigById: () => getEventConfigById,
332
+ getEventFlags: () => getEventFlags,
326
333
  getFilePathsFromEvent: () => getFilePathsFromEvent,
327
334
  getLocationHierarchy: () => getLocationHierarchy,
328
335
  getMixedPath: () => getMixedPath,
@@ -345,6 +352,7 @@ __export(events_exports, {
345
352
  isBulletListFieldType: () => isBulletListFieldType,
346
353
  isButtonFieldType: () => isButtonFieldType,
347
354
  isCheckboxFieldType: () => isCheckboxFieldType,
355
+ isCodeToEvaluate: () => isCodeToEvaluate,
348
356
  isConditionMet: () => isConditionMet,
349
357
  isCountryFieldType: () => isCountryFieldType,
350
358
  isCustomFieldType: () => isCustomFieldType,
@@ -385,6 +393,7 @@ __export(events_exports, {
385
393
  isPageVisible: () => isPageVisible,
386
394
  isParagraphFieldType: () => isParagraphFieldType,
387
395
  isPhoneFieldType: () => isPhoneFieldType,
396
+ isPotentialDuplicate: () => isPotentialDuplicate,
388
397
  isPrintButtonFieldType: () => isPrintButtonFieldType,
389
398
  isQrReaderFieldType: () => isQrReaderFieldType,
390
399
  isQueryParamReaderFieldType: () => isQueryParamReaderFieldType,
@@ -418,12 +427,15 @@ __export(events_exports, {
418
427
  plainDateToLocalDate: () => plainDateToLocalDate,
419
428
  precompileActionSchemas: () => precompileActionSchemas,
420
429
  resolveDateOfEvent: () => resolveDateOfEvent,
430
+ resolveEventCustomFlags: () => resolveEventCustomFlags,
421
431
  resolvePlaceOfEvent: () => resolvePlaceOfEvent,
432
+ runClientFunction: () => runClientFunction,
422
433
  runFieldValidations: () => runFieldValidations,
423
434
  runStructuralValidations: () => runStructuralValidations,
424
435
  safeUnion: () => safeUnion,
425
436
  status: () => status,
426
437
  timePeriodToDateRange: () => timePeriodToDateRange,
438
+ todayISO: () => todayISO,
427
439
  user: () => user,
428
440
  userCanAccessEventWithScopes: () => userCanAccessEventWithScopes,
429
441
  validate: () => validate,
@@ -1355,6 +1367,7 @@ var DateRangeFieldValue = z12.object({
1355
1367
  var EmailValue = z12.email();
1356
1368
  var CheckboxFieldValue = z12.boolean();
1357
1369
  var NumberFieldValue = z12.number();
1370
+ var SignatureFieldValue = FileFieldValue;
1358
1371
  var ButtonFieldValue = z12.number();
1359
1372
  var VerificationStatusValue = z12.enum([
1360
1373
  "verified",
@@ -2185,8 +2198,21 @@ var FieldReference = import_v43.default.object({
2185
2198
  $$field: FieldId.describe("Id of the field to reference"),
2186
2199
  $$subfield: import_v43.default.array(import_v43.default.string()).optional().default([]).describe(
2187
2200
  'If the FieldValue is an object, subfield can be used to refer to e.g. `["foo", "bar"]` in `{ foo: { bar: 3 } }`'
2201
+ ),
2202
+ $$code: import_v43.default.string().optional().describe(
2203
+ "Serialised client-side function body. When present the expression is evaluated rather than dereferenced."
2188
2204
  )
2189
- }).describe("Reference to a field by its ID");
2205
+ }).describe(
2206
+ "Reference to a field value, with an optional client-side computation applied."
2207
+ );
2208
+ function isCodeToEvaluate(v) {
2209
+ return !!v && typeof v === "object" && "$$code" in v;
2210
+ }
2211
+ var ComputedDefaultValue = import_v43.default.object({
2212
+ $$code: import_v43.default.string().describe(
2213
+ "Serialised client-side function body. Receives (undefined, context) where context includes $now, $online, and system variables."
2214
+ )
2215
+ }).describe("A context-only computation used as a field default value.");
2190
2216
  var ValidationConfig = import_v43.default.object({
2191
2217
  validator: Conditional.describe(
2192
2218
  "Conditional expression that must hold for the field value to be considered valid."
@@ -2227,7 +2253,7 @@ var BaseField = import_v43.default.object({
2227
2253
  "Indicates whether the field can be modified during record correction."
2228
2254
  ),
2229
2255
  value: FieldReference.or(import_v43.default.array(FieldReference)).optional().describe(
2230
- "Reference to the source field or fields. When a value is defined, it is copied from the parent field when changed. If multiple references are provided, the first truthy value is used."
2256
+ "Reference to the source field or fields. When a value is defined, it is copied from the parent field when changed. If multiple references are provided, the first truthy value is used. A FieldReference with $$code computes the value via a custom client-side function."
2231
2257
  ),
2232
2258
  analytics: import_v43.default.boolean().default(false).optional().describe(
2233
2259
  "Indicates whether the field is included in analytics. When enabled, its value becomes available in the analytics dashboard."
@@ -2241,7 +2267,7 @@ var Divider = BaseField.extend({
2241
2267
  });
2242
2268
  var TextField = BaseField.extend({
2243
2269
  type: import_v43.default.literal(FieldType.TEXT),
2244
- defaultValue: import_v43.default.union([NonEmptyTextValue, SerializedUserField]).optional(),
2270
+ defaultValue: import_v43.default.union([NonEmptyTextValue, SerializedUserField, ComputedDefaultValue]).optional(),
2245
2271
  configuration: import_v43.default.object({
2246
2272
  maxLength: import_v43.default.number().optional().describe("Maximum length of the text"),
2247
2273
  type: import_v43.default.enum(["text", "password"]).optional(),
@@ -2254,7 +2280,7 @@ var TextField = BaseField.extend({
2254
2280
  });
2255
2281
  var NumberField = BaseField.extend({
2256
2282
  type: import_v43.default.literal(FieldType.NUMBER),
2257
- defaultValue: NumberFieldValue.optional(),
2283
+ defaultValue: NumberFieldValue.or(ComputedDefaultValue).optional(),
2258
2284
  configuration: import_v43.default.object({
2259
2285
  min: import_v43.default.number().optional().describe("Minimum value"),
2260
2286
  max: import_v43.default.number().optional().describe("Maximum value"),
@@ -2267,7 +2293,7 @@ var NumberField = BaseField.extend({
2267
2293
  });
2268
2294
  var TextAreaField = BaseField.extend({
2269
2295
  type: import_v43.default.literal(FieldType.TEXTAREA),
2270
- defaultValue: NonEmptyTextValue.optional(),
2296
+ defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional(),
2271
2297
  configuration: import_v43.default.object({
2272
2298
  maxLength: import_v43.default.number().optional().describe("Maximum length of the text"),
2273
2299
  rows: import_v43.default.number().optional().describe("Number of visible text lines"),
@@ -2301,7 +2327,7 @@ var SignatureField = BaseField.extend({
2301
2327
  signaturePromptLabel: TranslationConfig.describe(
2302
2328
  "Title of the signature modal"
2303
2329
  ),
2304
- defaultValue: FieldValue.optional(),
2330
+ defaultValue: SignatureFieldValue.or(ComputedDefaultValue).optional(),
2305
2331
  configuration: import_v43.default.object({
2306
2332
  maxFileSize: import_v43.default.number().describe("Maximum file size in bytes").default(DEFAULT_MAX_FILE_SIZE_BYTES),
2307
2333
  acceptedFileTypes: MimeType.array().optional().describe("List of allowed file formats for the signature")
@@ -2317,14 +2343,14 @@ var EmailField = BaseField.extend({
2317
2343
  configuration: import_v43.default.object({
2318
2344
  maxLength: import_v43.default.number().optional().describe("Maximum length of the text")
2319
2345
  }).default({ maxLength: 255 }).optional(),
2320
- defaultValue: NonEmptyTextValue.optional()
2346
+ defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional()
2321
2347
  }).meta({
2322
2348
  description: "An email input field",
2323
2349
  id: "EmailField"
2324
2350
  });
2325
2351
  var DateField = BaseField.extend({
2326
2352
  type: import_v43.default.literal(FieldType.DATE),
2327
- defaultValue: SerializedNowDateTime.or(PlainDate).optional().describe("Default date value(yyyy-MM-dd)"),
2353
+ defaultValue: SerializedNowDateTime.or(PlainDate).or(ComputedDefaultValue).optional().describe("Default date value(yyyy-MM-dd)"),
2328
2354
  configuration: import_v43.default.object({
2329
2355
  notice: TranslationConfig.describe(
2330
2356
  "Text to display above the date input"
@@ -2336,7 +2362,7 @@ var DateField = BaseField.extend({
2336
2362
  });
2337
2363
  var AgeField = BaseField.extend({
2338
2364
  type: import_v43.default.literal(FieldType.AGE),
2339
- defaultValue: NumberFieldValue.optional(),
2365
+ defaultValue: NumberFieldValue.or(ComputedDefaultValue).optional(),
2340
2366
  configuration: import_v43.default.object({
2341
2367
  asOfDate: FieldReference,
2342
2368
  prefix: TranslationConfig.optional(),
@@ -2348,7 +2374,7 @@ var AgeField = BaseField.extend({
2348
2374
  });
2349
2375
  var TimeField = BaseField.extend({
2350
2376
  type: import_v43.default.literal(FieldType.TIME),
2351
- defaultValue: SerializedNowDateTime.or(TimeValue).optional().describe("Default time value (HH-mm)"),
2377
+ defaultValue: SerializedNowDateTime.or(TimeValue).or(ComputedDefaultValue).optional().describe("Default time value (HH-mm)"),
2352
2378
  configuration: import_v43.default.object({
2353
2379
  use12HourFormat: import_v43.default.boolean().optional().describe("Whether to use 12-hour format"),
2354
2380
  notice: TranslationConfig.describe(
@@ -2361,7 +2387,7 @@ var TimeField = BaseField.extend({
2361
2387
  });
2362
2388
  var DateRangeField = BaseField.extend({
2363
2389
  type: import_v43.default.literal(FieldType.DATE_RANGE),
2364
- defaultValue: DateRangeFieldValue.optional(),
2390
+ defaultValue: DateRangeFieldValue.or(ComputedDefaultValue).optional(),
2365
2391
  configuration: import_v43.default.object({
2366
2392
  notice: TranslationConfig.describe(
2367
2393
  "Text to display above the date input"
@@ -2440,7 +2466,7 @@ var PageHeader = BaseField.extend({
2440
2466
  });
2441
2467
  var File = BaseField.extend({
2442
2468
  type: import_v43.default.literal(FieldType.FILE),
2443
- defaultValue: FileFieldValue.optional(),
2469
+ defaultValue: FileFieldValue.or(ComputedDefaultValue).optional(),
2444
2470
  configuration: import_v43.default.object({
2445
2471
  maxFileSize: import_v43.default.number().describe("Maximum file size in bytes").default(DEFAULT_MAX_FILE_SIZE_BYTES),
2446
2472
  acceptedFileTypes: MimeType.array().optional().describe("List of allowed file formats for the signature"),
@@ -2467,7 +2493,7 @@ var SelectOption = import_v43.default.object({
2467
2493
  });
2468
2494
  var NumberWithUnitField = BaseField.extend({
2469
2495
  type: import_v43.default.literal(FieldType.NUMBER_WITH_UNIT),
2470
- defaultValue: NumberWithUnitFieldValue.optional(),
2496
+ defaultValue: NumberWithUnitFieldValue.or(ComputedDefaultValue).optional(),
2471
2497
  options: import_v43.default.array(SelectOption).describe("A list of options for the unit select"),
2472
2498
  configuration: import_v43.default.object({
2473
2499
  min: import_v43.default.number().optional().describe("Minimum value of the number field"),
@@ -2482,7 +2508,7 @@ var NumberWithUnitField = BaseField.extend({
2482
2508
  });
2483
2509
  var RadioGroup = BaseField.extend({
2484
2510
  type: import_v43.default.literal(FieldType.RADIO_GROUP),
2485
- defaultValue: TextValue.optional(),
2511
+ defaultValue: TextValue.or(ComputedDefaultValue).optional(),
2486
2512
  options: import_v43.default.array(SelectOption).describe("A list of options"),
2487
2513
  configuration: import_v43.default.object({
2488
2514
  styles: import_v43.default.object({
@@ -2507,7 +2533,7 @@ var BulletList = BaseField.extend({
2507
2533
  });
2508
2534
  var Select = BaseField.extend({
2509
2535
  type: import_v43.default.literal(FieldType.SELECT),
2510
- defaultValue: TextValue.optional(),
2536
+ defaultValue: TextValue.or(ComputedDefaultValue).optional(),
2511
2537
  options: import_v43.default.array(SelectOption).describe("A list of options"),
2512
2538
  noOptionsMessage: TranslationConfig.optional().describe(
2513
2539
  `
@@ -2529,7 +2555,7 @@ var SelectDateRangeOption = import_v43.default.object({
2529
2555
  });
2530
2556
  var SelectDateRangeField = BaseField.extend({
2531
2557
  type: import_v43.default.literal(FieldType.SELECT_DATE_RANGE),
2532
- defaultValue: SelectDateRangeValue.optional(),
2558
+ defaultValue: SelectDateRangeValue.or(ComputedDefaultValue).optional(),
2533
2559
  options: import_v43.default.array(SelectDateRangeOption).describe("A list of options")
2534
2560
  }).meta({
2535
2561
  description: "A date range selection field",
@@ -2546,7 +2572,7 @@ var NameField = BaseField.extend({
2546
2572
  firstname: SerializedUserField.or(NonEmptyTextValue).optional(),
2547
2573
  middlename: SerializedUserField.or(NonEmptyTextValue).optional(),
2548
2574
  surname: SerializedUserField.or(NonEmptyTextValue).optional()
2549
- }).optional(),
2575
+ }).or(ComputedDefaultValue).optional(),
2550
2576
  configuration: import_v43.default.object({
2551
2577
  name: NameConfig.default({
2552
2578
  firstname: { required: true },
@@ -2570,14 +2596,14 @@ var NameField = BaseField.extend({
2570
2596
  id: "NameField"
2571
2597
  });
2572
2598
  var PhoneField = BaseField.extend({
2573
- defaultValue: NonEmptyTextValue.optional(),
2599
+ defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional(),
2574
2600
  type: import_v43.default.literal(FieldType.PHONE)
2575
2601
  }).meta({
2576
2602
  description: "A field for entering a phone number",
2577
2603
  id: "PhoneField"
2578
2604
  });
2579
2605
  var IdField = BaseField.extend({
2580
- defaultValue: NonEmptyTextValue.optional(),
2606
+ defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional(),
2581
2607
  type: import_v43.default.literal(FieldType.ID)
2582
2608
  }).meta({
2583
2609
  description: "A field for entering an ID",
@@ -2585,14 +2611,14 @@ var IdField = BaseField.extend({
2585
2611
  });
2586
2612
  var Checkbox = BaseField.extend({
2587
2613
  type: import_v43.default.literal(FieldType.CHECKBOX),
2588
- defaultValue: CheckboxFieldValue.default(false)
2614
+ defaultValue: CheckboxFieldValue.or(ComputedDefaultValue).default(false)
2589
2615
  }).meta({
2590
2616
  description: "A boolean checkbox field",
2591
2617
  id: "Checkbox"
2592
2618
  });
2593
2619
  var Country = BaseField.extend({
2594
2620
  type: import_v43.default.literal(FieldType.COUNTRY),
2595
- defaultValue: NonEmptyTextValue.optional(),
2621
+ defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional(),
2596
2622
  optionOverrides: import_v43.default.array(SelectOption.omit({ label: true })).optional().describe(
2597
2623
  "Conditionals for specific countries. Countries not listed are always shown and enabled."
2598
2624
  )
@@ -2610,7 +2636,7 @@ var AdministrativeAreas = import_v43.default.enum([
2610
2636
  ]);
2611
2637
  var AdministrativeAreaField = BaseField.extend({
2612
2638
  type: import_v43.default.literal(FieldType.ADMINISTRATIVE_AREA),
2613
- defaultValue: import_v43.default.union([NonEmptyTextValue, SerializedUserField]).optional(),
2639
+ defaultValue: import_v43.default.union([NonEmptyTextValue, SerializedUserField, ComputedDefaultValue]).optional(),
2614
2640
  configuration: import_v43.default.object({
2615
2641
  partOf: FieldReference.optional().describe("Parent location"),
2616
2642
  type: AdministrativeAreas,
@@ -2622,7 +2648,7 @@ var AdministrativeAreaField = BaseField.extend({
2622
2648
  });
2623
2649
  var LocationInput = BaseField.extend({
2624
2650
  type: import_v43.default.literal(FieldType.LOCATION),
2625
- defaultValue: import_v43.default.union([NonEmptyTextValue, SerializedUserField]).optional(),
2651
+ defaultValue: import_v43.default.union([NonEmptyTextValue, SerializedUserField, ComputedDefaultValue]).optional(),
2626
2652
  configuration: import_v43.default.object({
2627
2653
  locationTypes: import_v43.default.array(import_v43.default.string()).optional().describe("Types of the locations that are available for selection."),
2628
2654
  allowedLocations: AllowedLocations
@@ -2634,7 +2660,7 @@ var LocationInput = BaseField.extend({
2634
2660
  var FileUploadWithOptions = BaseField.extend({
2635
2661
  type: import_v43.default.literal(FieldType.FILE_WITH_OPTIONS),
2636
2662
  options: import_v43.default.array(SelectOption).describe("A list of options"),
2637
- defaultValue: FileFieldWithOptionValue.optional(),
2663
+ defaultValue: FileFieldWithOptionValue.or(ComputedDefaultValue).optional(),
2638
2664
  configuration: import_v43.default.object({
2639
2665
  maxFileSize: import_v43.default.number().describe("Maximum file size in bytes").default(DEFAULT_MAX_FILE_SIZE_BYTES),
2640
2666
  maxImageSize: import_v43.default.object({
@@ -2650,12 +2676,12 @@ var FileUploadWithOptions = BaseField.extend({
2650
2676
  });
2651
2677
  var Facility = BaseField.extend({
2652
2678
  type: import_v43.default.literal(FieldType.FACILITY),
2653
- defaultValue: NonEmptyTextValue.optional(),
2679
+ defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional(),
2654
2680
  configuration: import_v43.default.object({ allowedLocations: AllowedLocations }).optional()
2655
2681
  }).describe("Input field for a facility");
2656
2682
  var Office = BaseField.extend({
2657
2683
  type: import_v43.default.literal(FieldType.OFFICE),
2658
- defaultValue: NonEmptyTextValue.optional(),
2684
+ defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional(),
2659
2685
  configuration: import_v43.default.object({ allowedLocations: AllowedLocations }).optional()
2660
2686
  }).describe("Input field for an office");
2661
2687
  var DefaultAddressFieldValue = DomesticAddressFieldValue.extend({
@@ -2691,7 +2717,7 @@ var Address = BaseField.extend({
2691
2717
  ).optional(),
2692
2718
  allowedLocations: AllowedLocations
2693
2719
  }).optional(),
2694
- defaultValue: DefaultAddressFieldValue.optional()
2720
+ defaultValue: DefaultAddressFieldValue.or(ComputedDefaultValue).optional()
2695
2721
  }).meta({
2696
2722
  description: "Address input field \u2013 a combination of location and text fields",
2697
2723
  id: "Address"
@@ -2738,7 +2764,7 @@ var ButtonConfiguration = import_v43.default.object({
2738
2764
  });
2739
2765
  var ButtonField = BaseField.extend({
2740
2766
  type: import_v43.default.literal(FieldType.BUTTON),
2741
- defaultValue: ButtonFieldValue.optional(),
2767
+ defaultValue: ButtonFieldValue.or(ComputedDefaultValue).optional(),
2742
2768
  configuration: ButtonConfiguration
2743
2769
  }).meta({
2744
2770
  description: "A generic button that can be used to trigger an action",
@@ -2766,7 +2792,7 @@ var AlphaPrintButton = BaseField.extend({
2766
2792
  });
2767
2793
  var HttpField = BaseField.extend({
2768
2794
  type: import_v43.default.literal(FieldType.HTTP),
2769
- defaultValue: HttpFieldValue.optional(),
2795
+ defaultValue: HttpFieldValue.or(ComputedDefaultValue).optional(),
2770
2796
  configuration: import_v43.default.object({
2771
2797
  trigger: FieldReference.optional().describe(
2772
2798
  "Reference to the field that triggers the HTTP request when its value changes. If not provided, the HTTP request is triggered once on component mount."
@@ -2852,7 +2878,7 @@ var LinkButtonField = BaseField.extend({
2852
2878
  });
2853
2879
  var VerificationStatus = BaseField.extend({
2854
2880
  type: import_v43.default.literal(FieldType.VERIFICATION_STATUS),
2855
- defaultValue: VerificationStatusValue.optional(),
2881
+ defaultValue: VerificationStatusValue.or(ComputedDefaultValue).optional(),
2856
2882
  configuration: import_v43.default.object({
2857
2883
  status: TranslationConfig.describe("Text to display on the status pill."),
2858
2884
  description: TranslationConfig.describe(
@@ -2874,7 +2900,7 @@ var QueryParamReaderField = BaseField.extend({
2874
2900
  });
2875
2901
  var QrReaderField = BaseField.extend({
2876
2902
  type: import_v43.default.literal(FieldType.QR_READER),
2877
- defaultValue: QrReaderFieldValue.optional(),
2903
+ defaultValue: QrReaderFieldValue.or(ComputedDefaultValue).optional(),
2878
2904
  configuration: import_v43.default.object({
2879
2905
  validator: import_v43.default.any().meta({
2880
2906
  description: "JSON Schema to validate the scanned QR code data against before populating the form fields.",
@@ -2887,7 +2913,7 @@ var QrReaderField = BaseField.extend({
2887
2913
  });
2888
2914
  var IdReaderField = BaseField.extend({
2889
2915
  type: import_v43.default.literal(FieldType.ID_READER),
2890
- defaultValue: IdReaderFieldValue.optional(),
2916
+ defaultValue: IdReaderFieldValue.or(ComputedDefaultValue).optional(),
2891
2917
  methods: import_v43.default.array(
2892
2918
  import_v43.default.union([QrReaderField, LinkButtonField]).describe("Methods for reading an ID")
2893
2919
  )
@@ -3905,7 +3931,37 @@ function resolveDataPath(rootData, dataPath, instancePath) {
3905
3931
  }
3906
3932
  return current;
3907
3933
  }
3934
+ function todayISO() {
3935
+ return (0, import_date_fns.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" });
3936
+ }
3937
+ var compiledFunctionCache = /* @__PURE__ */ new Map();
3938
+ function compileClientFunction(code) {
3939
+ let fn = compiledFunctionCache.get(code);
3940
+ if (!fn) {
3941
+ fn = new Function(`return (${code})`)();
3942
+ compiledFunctionCache.set(code, fn);
3943
+ }
3944
+ return fn;
3945
+ }
3908
3946
  (0, import_ajv_formats.default)(ajv);
3947
+ function buildClientFunctionContext(input) {
3948
+ return {
3949
+ $form: input.form,
3950
+ $now: todayISO(),
3951
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
3952
+ $online: isOnline(),
3953
+ $user: input.validatorContext?.user,
3954
+ $event: input.validatorContext?.event,
3955
+ $leafAdminStructureLocationIds: input.validatorContext?.leafAdminStructureLocationIds ?? [],
3956
+ user: input.systemVariables?.user,
3957
+ $window: input.systemVariables?.$window,
3958
+ locations: input.locations,
3959
+ adminLevelIds: input.adminLevelIds
3960
+ };
3961
+ }
3962
+ function runClientFunction(code, data, context) {
3963
+ return compileClientFunction(code)(data, context);
3964
+ }
3909
3965
  ajv.addKeyword({
3910
3966
  keyword: "daysFromDate",
3911
3967
  type: "string",
@@ -3950,7 +4006,7 @@ ajv.addKeyword({
3950
4006
  $data: true,
3951
4007
  errors: true,
3952
4008
  // @ts-ignore -- Force type. We will move this away from AJV next. Parsing the array will take seconds and is only called by core.
3953
- validate(schema, data, _2, dataContext) {
4009
+ validate(_schema, data, _2, dataContext) {
3954
4010
  const locationIdInput = data;
3955
4011
  const locations = dataContext?.rootData.$leafAdminStructureLocationIds ?? [];
3956
4012
  return locations.some((location) => location.id === locationIdInput);
@@ -3981,6 +4037,23 @@ function isAgeValue(value) {
3981
4037
  function mergeWithBaseFormState(values, context) {
3982
4038
  return { ...context.baseFormState, ...values };
3983
4039
  }
4040
+ ajv.addKeyword({
4041
+ keyword: "customClientValidator",
4042
+ schemaType: "object",
4043
+ errors: true,
4044
+ // @ts-expect-error -- AJV's public types don't expose `rootData`. All
4045
+ // `validate()` callers build root data via `buildClientFunctionContext`,
4046
+ // so the cast holds.
4047
+ validate(schema, data, _2, dataContext) {
4048
+ return Boolean(
4049
+ runClientFunction(
4050
+ schema.code,
4051
+ data,
4052
+ dataContext?.rootData ?? buildClientFunctionContext({ form: {} })
4053
+ )
4054
+ );
4055
+ }
4056
+ });
3984
4057
  function validate(schema, data) {
3985
4058
  const validator = ajv.getSchema(schema.$id) || ajv.compile(schema);
3986
4059
  if ("$form" in data) {
@@ -4017,17 +4090,14 @@ function isOnline() {
4017
4090
  }
4018
4091
  return true;
4019
4092
  }
4020
- function isConditionMet(conditional, values, context, eventIndex) {
4021
- return validate(conditional, {
4022
- $form: mergeWithBaseFormState(values, context),
4023
- $now: (0, import_date_fns.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" }),
4024
- $online: isOnline(),
4025
- $user: context.user,
4026
- $leafAdminStructureLocationIds: context.leafAdminStructureLocationIds ?? [],
4027
- $flags: eventIndex?.flags ?? [],
4028
- $status: eventIndex?.status,
4029
- $event: context.event
4030
- });
4093
+ function isConditionMet(conditional, values, context) {
4094
+ return validate(
4095
+ conditional,
4096
+ buildClientFunctionContext({
4097
+ form: mergeWithBaseFormState(values, context),
4098
+ validatorContext: context
4099
+ })
4100
+ );
4031
4101
  }
4032
4102
  function getConditionalActionsForField(field3, values) {
4033
4103
  if (!field3.conditionals) {
@@ -4035,9 +4105,9 @@ function getConditionalActionsForField(field3, values) {
4035
4105
  }
4036
4106
  return field3.conditionals.filter((conditional) => validate(conditional.conditional, values)).map((conditional) => conditional.type);
4037
4107
  }
4038
- function areConditionsMet(conditions, values, context, event2) {
4108
+ function areConditionsMet(conditions, values, context, _event) {
4039
4109
  return conditions.every(
4040
- (condition) => isConditionMet(condition.conditional, values, context, event2)
4110
+ (condition) => isConditionMet(condition.conditional, values, context)
4041
4111
  );
4042
4112
  }
4043
4113
  function isFieldConditionMet(field3, form, conditionalType, context) {
@@ -4047,14 +4117,13 @@ function isFieldConditionMet(field3, form, conditionalType, context) {
4047
4117
  if (!hasRule) {
4048
4118
  return true;
4049
4119
  }
4050
- const validConditionals = getConditionalActionsForField(field3, {
4051
- $form: mergeWithBaseFormState(form, context),
4052
- $now: (0, import_date_fns.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" }),
4053
- $online: isOnline(),
4054
- $user: context.user,
4055
- $leafAdminStructureLocationIds: context.leafAdminStructureLocationIds ?? [],
4056
- $event: context.event
4057
- });
4120
+ const validConditionals = getConditionalActionsForField(
4121
+ field3,
4122
+ buildClientFunctionContext({
4123
+ form: mergeWithBaseFormState(form, context),
4124
+ validatorContext: context
4125
+ })
4126
+ );
4058
4127
  return validConditionals.includes(conditionalType);
4059
4128
  }
4060
4129
  function isFieldVisible(field3, form, context) {
@@ -4080,7 +4149,14 @@ function isActionConditionMet(actionConfig, event2, context, conditionalType) {
4080
4149
  if (!rule) {
4081
4150
  return true;
4082
4151
  }
4083
- return isConditionMet(rule.conditional, event2.declaration, context, event2);
4152
+ return validate(rule.conditional, {
4153
+ ...buildClientFunctionContext({
4154
+ form: mergeWithBaseFormState(event2.declaration, context),
4155
+ validatorContext: context
4156
+ }),
4157
+ $flags: event2.flags,
4158
+ $status: event2.status
4159
+ });
4084
4160
  }
4085
4161
  function isActionEnabled(actionConfig, event2, context) {
4086
4162
  return isActionConditionMet(
@@ -4239,19 +4315,10 @@ function runFieldValidations({
4239
4315
  if (!isFieldVisible(field3.config, form, context)) {
4240
4316
  return [];
4241
4317
  }
4242
- const conditionalParameters = {
4243
- $form: mergeWithBaseFormState(form, context),
4244
- $now: (0, import_date_fns.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" }),
4245
- /**
4246
- * In real use cases, there can be hundreds of thousands of locations.
4247
- * Make sure that the context contains only the locations that are needed for validation.
4248
- * E.g. if the user is a leaf admin, only the leaf locations under their admin structure are needed.
4249
- * Loading few megabytes of locations to memory just for validation is not efficient and will choke the application.
4250
- */
4251
- $leafAdminStructureLocationIds: context.leafAdminStructureLocationIds ?? [],
4252
- $online: isOnline(),
4253
- $user: context.user
4254
- };
4318
+ const conditionalParameters = buildClientFunctionContext({
4319
+ form: mergeWithBaseFormState(form, context),
4320
+ validatorContext: context
4321
+ });
4255
4322
  if (isFieldGroupFieldType(field3)) {
4256
4323
  const subfieldErrors = buildFormState(
4257
4324
  field3.config.fields,
@@ -4735,19 +4802,16 @@ function getPendingAction(actions) {
4735
4802
  }
4736
4803
  return pendingActions[0];
4737
4804
  }
4738
- function getCompleteActionAnnotation(annotation, event2, action) {
4805
+ function getCompleteActionAnnotation(event2, action) {
4739
4806
  if (action.originalActionId) {
4740
4807
  const originalAction = event2.actions.find(
4741
4808
  ({ id }) => id === action.originalActionId
4742
4809
  );
4743
4810
  if (originalAction?.status === ActionStatus.Requested) {
4744
- return deepMerge(
4745
- deepMerge(annotation, originalAction.annotation ?? {}),
4746
- action.annotation ?? {}
4747
- );
4811
+ return deepMerge(originalAction.annotation ?? {}, action.annotation ?? {});
4748
4812
  }
4749
4813
  }
4750
- return deepMerge(annotation, action.annotation ?? {});
4814
+ return action.annotation ?? {};
4751
4815
  }
4752
4816
  function getCompleteActionDeclaration(declaration, event2, action) {
4753
4817
  if (action.originalActionId) {
@@ -4767,7 +4831,7 @@ function getAcceptedActions(event2) {
4767
4831
  return event2.actions.filter(isAcceptedAction).map((action) => ({
4768
4832
  ...action,
4769
4833
  declaration: getCompleteActionDeclaration({}, event2, action),
4770
- annotation: getCompleteActionAnnotation({}, event2, action)
4834
+ annotation: getCompleteActionAnnotation(event2, action)
4771
4835
  }));
4772
4836
  }
4773
4837
  var EXCLUDED_ACTIONS = [
@@ -5405,7 +5469,54 @@ function createFieldConditionals(fieldId) {
5405
5469
  }
5406
5470
  },
5407
5471
  required: [fieldId]
5408
- })
5472
+ }),
5473
+ /**
5474
+ * Custom client-side validator. The provided function is serialised and executed
5475
+ * just-in-time on the client only. External references (e.g. lodash) are not
5476
+ * available inside the function body — all logic must be self-contained.
5477
+ *
5478
+ * @example
5479
+ * field('nid').customClientValidator((value) => {
5480
+ * // LUHN check — all logic must be inline
5481
+ * const digits = String(value).split('').map(Number)
5482
+ * // ...
5483
+ * return isValid
5484
+ * })
5485
+ */
5486
+ customClientValidator(validationFn) {
5487
+ const code = validationFn.toString();
5488
+ return defineFormConditional({
5489
+ type: "object",
5490
+ properties: wrapToPath(
5491
+ { [fieldId]: { customClientValidator: { code } } },
5492
+ this.$$subfield
5493
+ ),
5494
+ required: [fieldId]
5495
+ });
5496
+ },
5497
+ /**
5498
+ * Custom client-side evaluation. Returns a {@link FieldReference} descriptor
5499
+ * that can be used as the `value` property or a DATA component entry.
5500
+ * The function receives the referenced field's value as the first argument and
5501
+ * the full form context as the second; its return value replaces the field reference.
5502
+ * The function is serialised and executed just-in-time on the client only.
5503
+ * External references (e.g. lodash) are not available inside the function body.
5504
+ *
5505
+ * For computing a default value without referencing a specific field, use
5506
+ * `evaluate(fn)` in the `defaultValue` property instead.
5507
+ *
5508
+ * @example
5509
+ * field('a').customClientEvaluation((aValue, ctx) =>
5510
+ * Number(aValue) + Number(ctx.$form.b)
5511
+ * )
5512
+ */
5513
+ customClientEvaluation(computationFn) {
5514
+ return {
5515
+ $$code: computationFn.toString(),
5516
+ $$field: fieldId,
5517
+ $$subfield: this.$$subfield
5518
+ };
5519
+ }
5409
5520
  };
5410
5521
  }
5411
5522
 
@@ -6388,26 +6499,43 @@ var import_date_fns3 = require("date-fns");
6388
6499
  function isEditInProgress(actions) {
6389
6500
  return actions.at(-1)?.type === ActionType.EDIT;
6390
6501
  }
6502
+ function findPendingCorrectionAction(writeActions2) {
6503
+ let correctionRequestAction;
6504
+ for (let i = writeActions2.length - 1; i >= 0; i--) {
6505
+ const action = writeActions2[i];
6506
+ if (action.type === ActionType.APPROVE_CORRECTION || action.type === ActionType.REJECT_CORRECTION) {
6507
+ break;
6508
+ }
6509
+ if (action.type === ActionType.REQUEST_CORRECTION) {
6510
+ correctionRequestAction = action;
6511
+ break;
6512
+ }
6513
+ }
6514
+ return correctionRequestAction;
6515
+ }
6391
6516
  function isCorrectionRequested(actions) {
6517
+ return findPendingCorrectionAction(actions) !== void 0;
6518
+ }
6519
+ function isDeclarationIncomplete(actions) {
6520
+ return getStatusFromActions(actions) === EventStatus.enum.NOTIFIED;
6521
+ }
6522
+ function isRejected(actions) {
6523
+ const resettingActionTypes = [
6524
+ ActionType.NOTIFY,
6525
+ ActionType.DECLARE,
6526
+ ActionType.EDIT,
6527
+ ActionType.REGISTER
6528
+ ];
6392
6529
  return actions.reduce((prev, { type }) => {
6393
- if (type === ActionType.REQUEST_CORRECTION) {
6530
+ if (type === ActionType.REJECT) {
6394
6531
  return true;
6395
6532
  }
6396
- if (type === ActionType.APPROVE_CORRECTION) {
6397
- return false;
6398
- }
6399
- if (type === ActionType.REJECT_CORRECTION) {
6533
+ if (resettingActionTypes.includes(type)) {
6400
6534
  return false;
6401
6535
  }
6402
6536
  return prev;
6403
6537
  }, false);
6404
6538
  }
6405
- function isDeclarationIncomplete(actions) {
6406
- return getStatusFromActions(actions) === EventStatus.enum.NOTIFIED;
6407
- }
6408
- function isRejected(actions) {
6409
- return actions.at(-1)?.type === ActionType.REJECT;
6410
- }
6411
6539
  function isPotentialDuplicate(actions) {
6412
6540
  return actions.reduce((prev, { type }) => {
6413
6541
  if (type === ActionType.DUPLICATE_DETECTED) {
@@ -6470,8 +6598,7 @@ function resolveEventCustomFlags(event2, eventConfiguration) {
6470
6598
  return (0, import_lodash3.uniq)(flags);
6471
6599
  }, []);
6472
6600
  }
6473
- function getEventFlags(event2, config) {
6474
- const sortedActions = event2.actions.filter(({ type }) => !isMetaAction(type)).sort((a, b) => a.createdAt.localeCompare(b.createdAt));
6601
+ function getActionStatusFlags(sortedActions) {
6475
6602
  const actionStatus = sortedActions.reduce(
6476
6603
  (actionStatuses, { type, status: status2 }) => ({
6477
6604
  ...actionStatuses,
@@ -6479,26 +6606,40 @@ function getEventFlags(event2, config) {
6479
6606
  }),
6480
6607
  {}
6481
6608
  );
6482
- const flags = Object.entries(actionStatus).filter(([, status2]) => status2 !== ActionStatus.Accepted).map(([type, status2]) => {
6609
+ return Object.entries(actionStatus).filter(([, status2]) => status2 !== ActionStatus.Accepted).map(([type, status2]) => {
6483
6610
  const flag2 = joinValues([type, status2], ":").toLowerCase();
6484
6611
  return flag2;
6485
6612
  });
6486
- if (isCorrectionRequested(sortedActions)) {
6487
- flags.push(InherentFlags.CORRECTION_REQUESTED);
6613
+ }
6614
+ function getInherentFlags(sortedActions) {
6615
+ const acceptedActions = sortedActions.filter(
6616
+ ({ status: status2 }) => status2 === ActionStatus.Accepted
6617
+ );
6618
+ const inherentFlags = [];
6619
+ if (isCorrectionRequested(acceptedActions)) {
6620
+ inherentFlags.push(InherentFlags.CORRECTION_REQUESTED);
6488
6621
  }
6489
- if (isDeclarationIncomplete(sortedActions)) {
6490
- flags.push(InherentFlags.INCOMPLETE);
6622
+ if (isDeclarationIncomplete(acceptedActions)) {
6623
+ inherentFlags.push(InherentFlags.INCOMPLETE);
6491
6624
  }
6492
- if (isRejected(sortedActions)) {
6493
- flags.push(InherentFlags.REJECTED);
6625
+ if (isRejected(acceptedActions)) {
6626
+ inherentFlags.push(InherentFlags.REJECTED);
6494
6627
  }
6495
- if (isPotentialDuplicate(sortedActions)) {
6496
- flags.push(InherentFlags.POTENTIAL_DUPLICATE);
6628
+ if (isPotentialDuplicate(acceptedActions)) {
6629
+ inherentFlags.push(InherentFlags.POTENTIAL_DUPLICATE);
6497
6630
  }
6498
- if (isEditInProgress(sortedActions)) {
6499
- flags.push(InherentFlags.EDIT_IN_PROGRESS);
6631
+ if (isEditInProgress(acceptedActions)) {
6632
+ inherentFlags.push(InherentFlags.EDIT_IN_PROGRESS);
6500
6633
  }
6501
- return [...flags, ...resolveEventCustomFlags(event2, config)];
6634
+ return inherentFlags;
6635
+ }
6636
+ function getEventFlags(event2, config) {
6637
+ const sortedActions = event2.actions.filter(({ type }) => !isMetaAction(type)).sort((a, b) => a.createdAt.localeCompare(b.createdAt));
6638
+ return [
6639
+ ...getActionStatusFlags(sortedActions),
6640
+ ...getInherentFlags(sortedActions),
6641
+ ...resolveEventCustomFlags(event2, config)
6642
+ ];
6502
6643
  }
6503
6644
 
6504
6645
  // ../commons/src/events/state/index.ts
@@ -6733,7 +6874,7 @@ function getActionAnnotation({
6733
6874
  const action = (0, import_lodash4.findLast)(activeActions, (a) => a.type === actionType);
6734
6875
  const actionWithCompleteAnnotation = action && {
6735
6876
  ...action,
6736
- annotation: getCompleteActionAnnotation({}, event2, action)
6877
+ annotation: getCompleteActionAnnotation(event2, action)
6737
6878
  };
6738
6879
  const matchingDraft = draft?.action.type === actionType ? draft : void 0;
6739
6880
  const sortedActions = (0, import_lodash4.orderBy)(
@@ -6805,6 +6946,9 @@ function createFieldConfig(fieldId, options) {
6805
6946
  }
6806
6947
 
6807
6948
  // ../commons/src/events/field.ts
6949
+ function evaluate(computationFn) {
6950
+ return { $$code: computationFn.toString() };
6951
+ }
6808
6952
  function field(fieldId, options = {}) {
6809
6953
  return {
6810
6954
  ...createFieldConditionals(fieldId),