@opencrvs/toolkit 2.0.0-rc.0735aa3 → 2.0.0-rc.07fde01

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,
@@ -150,6 +151,7 @@ __export(events_exports, {
150
151
  FormPageConfig: () => FormPageConfig,
151
152
  Fuzzy: () => Fuzzy,
152
153
  GeographicalArea: () => GeographicalArea,
154
+ HiddenFieldTypes: () => HiddenFieldTypes,
153
155
  HiddenFieldValue: () => HiddenFieldValue,
154
156
  HttpFieldUpdateValue: () => HttpFieldUpdateValue,
155
157
  HttpFieldValue: () => HttpFieldValue,
@@ -200,6 +202,7 @@ __export(events_exports, {
200
202
  SelectDateRangeValue: () => SelectDateRangeValue,
201
203
  SelectOption: () => SelectOption,
202
204
  ShowConditional: () => ShowConditional,
205
+ SignatureFieldValue: () => SignatureFieldValue,
203
206
  StaticDataEntry: () => StaticDataEntry,
204
207
  StreetLevelDetailsUpdateValue: () => StreetLevelDetailsUpdateValue,
205
208
  SummaryConfig: () => SummaryConfig,
@@ -246,10 +249,12 @@ __export(events_exports, {
246
249
  applyDraftToEventIndex: () => applyDraftToEventIndex,
247
250
  areCertificateConditionsMet: () => areCertificateConditionsMet,
248
251
  areConditionsMet: () => areConditionsMet,
252
+ buildClientFunctionContext: () => buildClientFunctionContext,
249
253
  buildFormState: () => buildFormState,
250
254
  canAccessEventWithScope: () => canAccessEventWithScope,
251
255
  canAccessOtherUserWithScopes: () => canAccessOtherUserWithScopes,
252
256
  canAccessUserWithScope: () => canAccessUserWithScope,
257
+ compileClientFunction: () => compileClientFunction,
253
258
  compositeFieldTypes: () => compositeFieldTypes,
254
259
  createEmptyDraft: () => createEmptyDraft,
255
260
  createFieldConditionals: () => createFieldConditionals,
@@ -270,6 +275,7 @@ __export(events_exports, {
270
275
  defineWorkqueuesColumns: () => defineWorkqueuesColumns,
271
276
  deserializeQuery: () => deserializeQuery,
272
277
  errorMessages: () => errorMessages,
278
+ evaluate: () => evaluate,
273
279
  event: () => event,
274
280
  eventMetadataLabelMap: () => eventMetadataLabelMap,
275
281
  eventPayloadGenerator: () => eventPayloadGenerator,
@@ -348,6 +354,7 @@ __export(events_exports, {
348
354
  isBulletListFieldType: () => isBulletListFieldType,
349
355
  isButtonFieldType: () => isButtonFieldType,
350
356
  isCheckboxFieldType: () => isCheckboxFieldType,
357
+ isCodeToEvaluate: () => isCodeToEvaluate,
351
358
  isConditionMet: () => isConditionMet,
352
359
  isCountryFieldType: () => isCountryFieldType,
353
360
  isCustomFieldType: () => isCustomFieldType,
@@ -424,11 +431,13 @@ __export(events_exports, {
424
431
  resolveDateOfEvent: () => resolveDateOfEvent,
425
432
  resolveEventCustomFlags: () => resolveEventCustomFlags,
426
433
  resolvePlaceOfEvent: () => resolvePlaceOfEvent,
434
+ runClientFunction: () => runClientFunction,
427
435
  runFieldValidations: () => runFieldValidations,
428
436
  runStructuralValidations: () => runStructuralValidations,
429
437
  safeUnion: () => safeUnion,
430
438
  status: () => status,
431
439
  timePeriodToDateRange: () => timePeriodToDateRange,
440
+ todayISO: () => todayISO,
432
441
  user: () => user,
433
442
  userCanAccessEventWithScopes: () => userCanAccessEventWithScopes,
434
443
  validate: () => validate,
@@ -703,14 +712,20 @@ var unflattenScope = (input) => {
703
712
  return { type, options };
704
713
  };
705
714
  var EncodedScope = z2.string().brand("EncodedScope");
706
- var decodeScope = (query) => {
707
- const scope = qs.parse(query, {
715
+ var decodedScopeCache = /* @__PURE__ */ new Map();
716
+ var decodeScope = (encodedScope) => {
717
+ if (decodedScopeCache.has(encodedScope)) {
718
+ return decodedScopeCache.get(encodedScope);
719
+ }
720
+ const scope = qs.parse(encodedScope, {
708
721
  ignoreQueryPrefix: true,
709
722
  comma: true,
710
723
  allowDots: true
711
724
  });
712
725
  const unflattenedScope = unflattenScope(scope);
713
- return Scope.safeParse(unflattenedScope)?.data;
726
+ const result = Scope.safeParse(unflattenedScope)?.data;
727
+ decodedScopeCache.set(encodedScope, result);
728
+ return result;
714
729
  };
715
730
  var DEFAULT_SCOPE_OPTIONS = {
716
731
  placeOfEvent: JurisdictionFilter.enum.all,
@@ -1205,6 +1220,11 @@ var FieldTypesToHideInReview = [
1205
1220
  FieldType.ALPHA_PRINT_BUTTON,
1206
1221
  FieldType.ALPHA_HIDDEN
1207
1222
  ];
1223
+ var HiddenFieldTypes = [
1224
+ FieldType.HTTP,
1225
+ FieldType.QUERY_PARAM_READER,
1226
+ FieldType.ALPHA_HIDDEN
1227
+ ];
1208
1228
 
1209
1229
  // ../commons/src/events/FieldValue.ts
1210
1230
  var z12 = __toESM(require("zod/v4"));
@@ -1331,7 +1351,7 @@ function plainDateToLocalDate(date) {
1331
1351
  // ../commons/src/events/FieldValue.ts
1332
1352
  var TextValue = z12.string();
1333
1353
  var HiddenFieldValue = z12.string();
1334
- var NonEmptyTextValue = TextValue.min(1);
1354
+ var NonEmptyTextValue = z12.string().trim().min(1);
1335
1355
  var DateValue = z12.iso.date().describe("Date in the format YYYY-MM-DD");
1336
1356
  var AgeValue = z12.object({
1337
1357
  age: z12.number(),
@@ -1360,6 +1380,7 @@ var DateRangeFieldValue = z12.object({
1360
1380
  var EmailValue = z12.email();
1361
1381
  var CheckboxFieldValue = z12.boolean();
1362
1382
  var NumberFieldValue = z12.number();
1383
+ var SignatureFieldValue = FileFieldValue;
1363
1384
  var ButtonFieldValue = z12.number();
1364
1385
  var VerificationStatusValue = z12.enum([
1365
1386
  "verified",
@@ -2191,8 +2212,21 @@ var FieldReference = import_v43.default.object({
2191
2212
  $$field: FieldId.describe("Id of the field to reference"),
2192
2213
  $$subfield: import_v43.default.array(import_v43.default.string()).optional().default([]).describe(
2193
2214
  'If the FieldValue is an object, subfield can be used to refer to e.g. `["foo", "bar"]` in `{ foo: { bar: 3 } }`'
2215
+ ),
2216
+ $$code: import_v43.default.string().optional().describe(
2217
+ "Serialised client-side function body. When present the expression is evaluated rather than dereferenced."
2218
+ )
2219
+ }).describe(
2220
+ "Reference to a field value, with an optional client-side computation applied."
2221
+ );
2222
+ function isCodeToEvaluate(v) {
2223
+ return !!v && typeof v === "object" && "$$code" in v;
2224
+ }
2225
+ var ComputedDefaultValue = import_v43.default.object({
2226
+ $$code: import_v43.default.string().describe(
2227
+ "Serialised client-side function body. Receives (undefined, context) where context includes $now, $online, and system variables."
2194
2228
  )
2195
- }).describe("Reference to a field by its ID");
2229
+ }).describe("A context-only computation used as a field default value.");
2196
2230
  var ValidationConfig = import_v43.default.object({
2197
2231
  validator: Conditional.describe(
2198
2232
  "Conditional expression that must hold for the field value to be considered valid."
@@ -2233,7 +2267,7 @@ var BaseField = import_v43.default.object({
2233
2267
  "Indicates whether the field can be modified during record correction."
2234
2268
  ),
2235
2269
  value: FieldReference.or(import_v43.default.array(FieldReference)).optional().describe(
2236
- "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."
2270
+ "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."
2237
2271
  ),
2238
2272
  analytics: import_v43.default.boolean().default(false).optional().describe(
2239
2273
  "Indicates whether the field is included in analytics. When enabled, its value becomes available in the analytics dashboard."
@@ -2247,7 +2281,7 @@ var Divider = BaseField.extend({
2247
2281
  });
2248
2282
  var TextField = BaseField.extend({
2249
2283
  type: import_v43.default.literal(FieldType.TEXT),
2250
- defaultValue: import_v43.default.union([NonEmptyTextValue, SerializedUserField]).optional(),
2284
+ defaultValue: import_v43.default.union([NonEmptyTextValue, SerializedUserField, ComputedDefaultValue]).optional(),
2251
2285
  configuration: import_v43.default.object({
2252
2286
  maxLength: import_v43.default.number().optional().describe("Maximum length of the text"),
2253
2287
  type: import_v43.default.enum(["text", "password"]).optional(),
@@ -2260,10 +2294,11 @@ var TextField = BaseField.extend({
2260
2294
  });
2261
2295
  var NumberField = BaseField.extend({
2262
2296
  type: import_v43.default.literal(FieldType.NUMBER),
2263
- defaultValue: NumberFieldValue.optional(),
2297
+ defaultValue: NumberFieldValue.or(ComputedDefaultValue).optional(),
2264
2298
  configuration: import_v43.default.object({
2265
2299
  min: import_v43.default.number().optional().describe("Minimum value"),
2266
2300
  max: import_v43.default.number().optional().describe("Maximum value"),
2301
+ integer: import_v43.default.boolean().optional().describe("When true, only whole numbers are allowed"),
2267
2302
  prefix: TranslationConfig.optional(),
2268
2303
  postfix: TranslationConfig.optional()
2269
2304
  }).optional()
@@ -2273,7 +2308,7 @@ var NumberField = BaseField.extend({
2273
2308
  });
2274
2309
  var TextAreaField = BaseField.extend({
2275
2310
  type: import_v43.default.literal(FieldType.TEXTAREA),
2276
- defaultValue: NonEmptyTextValue.optional(),
2311
+ defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional(),
2277
2312
  configuration: import_v43.default.object({
2278
2313
  maxLength: import_v43.default.number().optional().describe("Maximum length of the text"),
2279
2314
  rows: import_v43.default.number().optional().describe("Number of visible text lines"),
@@ -2307,7 +2342,7 @@ var SignatureField = BaseField.extend({
2307
2342
  signaturePromptLabel: TranslationConfig.describe(
2308
2343
  "Title of the signature modal"
2309
2344
  ),
2310
- defaultValue: FieldValue.optional(),
2345
+ defaultValue: SignatureFieldValue.or(ComputedDefaultValue).optional(),
2311
2346
  configuration: import_v43.default.object({
2312
2347
  maxFileSize: import_v43.default.number().describe("Maximum file size in bytes").default(DEFAULT_MAX_FILE_SIZE_BYTES),
2313
2348
  acceptedFileTypes: MimeType.array().optional().describe("List of allowed file formats for the signature")
@@ -2323,14 +2358,14 @@ var EmailField = BaseField.extend({
2323
2358
  configuration: import_v43.default.object({
2324
2359
  maxLength: import_v43.default.number().optional().describe("Maximum length of the text")
2325
2360
  }).default({ maxLength: 255 }).optional(),
2326
- defaultValue: NonEmptyTextValue.optional()
2361
+ defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional()
2327
2362
  }).meta({
2328
2363
  description: "An email input field",
2329
2364
  id: "EmailField"
2330
2365
  });
2331
2366
  var DateField = BaseField.extend({
2332
2367
  type: import_v43.default.literal(FieldType.DATE),
2333
- defaultValue: SerializedNowDateTime.or(PlainDate).optional().describe("Default date value(yyyy-MM-dd)"),
2368
+ defaultValue: SerializedNowDateTime.or(PlainDate).or(ComputedDefaultValue).optional().describe("Default date value(yyyy-MM-dd)"),
2334
2369
  configuration: import_v43.default.object({
2335
2370
  notice: TranslationConfig.describe(
2336
2371
  "Text to display above the date input"
@@ -2342,7 +2377,7 @@ var DateField = BaseField.extend({
2342
2377
  });
2343
2378
  var AgeField = BaseField.extend({
2344
2379
  type: import_v43.default.literal(FieldType.AGE),
2345
- defaultValue: NumberFieldValue.optional(),
2380
+ defaultValue: NumberFieldValue.or(ComputedDefaultValue).optional(),
2346
2381
  configuration: import_v43.default.object({
2347
2382
  asOfDate: FieldReference,
2348
2383
  prefix: TranslationConfig.optional(),
@@ -2354,7 +2389,7 @@ var AgeField = BaseField.extend({
2354
2389
  });
2355
2390
  var TimeField = BaseField.extend({
2356
2391
  type: import_v43.default.literal(FieldType.TIME),
2357
- defaultValue: SerializedNowDateTime.or(TimeValue).optional().describe("Default time value (HH-mm)"),
2392
+ defaultValue: SerializedNowDateTime.or(TimeValue).or(ComputedDefaultValue).optional().describe("Default time value (HH-mm)"),
2358
2393
  configuration: import_v43.default.object({
2359
2394
  use12HourFormat: import_v43.default.boolean().optional().describe("Whether to use 12-hour format"),
2360
2395
  notice: TranslationConfig.describe(
@@ -2367,7 +2402,7 @@ var TimeField = BaseField.extend({
2367
2402
  });
2368
2403
  var DateRangeField = BaseField.extend({
2369
2404
  type: import_v43.default.literal(FieldType.DATE_RANGE),
2370
- defaultValue: DateRangeFieldValue.optional(),
2405
+ defaultValue: DateRangeFieldValue.or(ComputedDefaultValue).optional(),
2371
2406
  configuration: import_v43.default.object({
2372
2407
  notice: TranslationConfig.describe(
2373
2408
  "Text to display above the date input"
@@ -2446,7 +2481,7 @@ var PageHeader = BaseField.extend({
2446
2481
  });
2447
2482
  var File = BaseField.extend({
2448
2483
  type: import_v43.default.literal(FieldType.FILE),
2449
- defaultValue: FileFieldValue.optional(),
2484
+ defaultValue: FileFieldValue.or(ComputedDefaultValue).optional(),
2450
2485
  configuration: import_v43.default.object({
2451
2486
  maxFileSize: import_v43.default.number().describe("Maximum file size in bytes").default(DEFAULT_MAX_FILE_SIZE_BYTES),
2452
2487
  acceptedFileTypes: MimeType.array().optional().describe("List of allowed file formats for the signature"),
@@ -2473,7 +2508,7 @@ var SelectOption = import_v43.default.object({
2473
2508
  });
2474
2509
  var NumberWithUnitField = BaseField.extend({
2475
2510
  type: import_v43.default.literal(FieldType.NUMBER_WITH_UNIT),
2476
- defaultValue: NumberWithUnitFieldValue.optional(),
2511
+ defaultValue: NumberWithUnitFieldValue.or(ComputedDefaultValue).optional(),
2477
2512
  options: import_v43.default.array(SelectOption).describe("A list of options for the unit select"),
2478
2513
  configuration: import_v43.default.object({
2479
2514
  min: import_v43.default.number().optional().describe("Minimum value of the number field"),
@@ -2488,7 +2523,7 @@ var NumberWithUnitField = BaseField.extend({
2488
2523
  });
2489
2524
  var RadioGroup = BaseField.extend({
2490
2525
  type: import_v43.default.literal(FieldType.RADIO_GROUP),
2491
- defaultValue: TextValue.optional(),
2526
+ defaultValue: TextValue.or(ComputedDefaultValue).optional(),
2492
2527
  options: import_v43.default.array(SelectOption).describe("A list of options"),
2493
2528
  configuration: import_v43.default.object({
2494
2529
  styles: import_v43.default.object({
@@ -2513,7 +2548,7 @@ var BulletList = BaseField.extend({
2513
2548
  });
2514
2549
  var Select = BaseField.extend({
2515
2550
  type: import_v43.default.literal(FieldType.SELECT),
2516
- defaultValue: TextValue.optional(),
2551
+ defaultValue: TextValue.or(ComputedDefaultValue).optional(),
2517
2552
  options: import_v43.default.array(SelectOption).describe("A list of options"),
2518
2553
  noOptionsMessage: TranslationConfig.optional().describe(
2519
2554
  `
@@ -2535,7 +2570,7 @@ var SelectDateRangeOption = import_v43.default.object({
2535
2570
  });
2536
2571
  var SelectDateRangeField = BaseField.extend({
2537
2572
  type: import_v43.default.literal(FieldType.SELECT_DATE_RANGE),
2538
- defaultValue: SelectDateRangeValue.optional(),
2573
+ defaultValue: SelectDateRangeValue.or(ComputedDefaultValue).optional(),
2539
2574
  options: import_v43.default.array(SelectDateRangeOption).describe("A list of options")
2540
2575
  }).meta({
2541
2576
  description: "A date range selection field",
@@ -2552,7 +2587,7 @@ var NameField = BaseField.extend({
2552
2587
  firstname: SerializedUserField.or(NonEmptyTextValue).optional(),
2553
2588
  middlename: SerializedUserField.or(NonEmptyTextValue).optional(),
2554
2589
  surname: SerializedUserField.or(NonEmptyTextValue).optional()
2555
- }).optional(),
2590
+ }).or(ComputedDefaultValue).optional(),
2556
2591
  configuration: import_v43.default.object({
2557
2592
  name: NameConfig.default({
2558
2593
  firstname: { required: true },
@@ -2576,14 +2611,14 @@ var NameField = BaseField.extend({
2576
2611
  id: "NameField"
2577
2612
  });
2578
2613
  var PhoneField = BaseField.extend({
2579
- defaultValue: NonEmptyTextValue.optional(),
2614
+ defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional(),
2580
2615
  type: import_v43.default.literal(FieldType.PHONE)
2581
2616
  }).meta({
2582
2617
  description: "A field for entering a phone number",
2583
2618
  id: "PhoneField"
2584
2619
  });
2585
2620
  var IdField = BaseField.extend({
2586
- defaultValue: NonEmptyTextValue.optional(),
2621
+ defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional(),
2587
2622
  type: import_v43.default.literal(FieldType.ID)
2588
2623
  }).meta({
2589
2624
  description: "A field for entering an ID",
@@ -2591,14 +2626,14 @@ var IdField = BaseField.extend({
2591
2626
  });
2592
2627
  var Checkbox = BaseField.extend({
2593
2628
  type: import_v43.default.literal(FieldType.CHECKBOX),
2594
- defaultValue: CheckboxFieldValue.default(false)
2629
+ defaultValue: CheckboxFieldValue.or(ComputedDefaultValue).default(false)
2595
2630
  }).meta({
2596
2631
  description: "A boolean checkbox field",
2597
2632
  id: "Checkbox"
2598
2633
  });
2599
2634
  var Country = BaseField.extend({
2600
2635
  type: import_v43.default.literal(FieldType.COUNTRY),
2601
- defaultValue: NonEmptyTextValue.optional(),
2636
+ defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional(),
2602
2637
  optionOverrides: import_v43.default.array(SelectOption.omit({ label: true })).optional().describe(
2603
2638
  "Conditionals for specific countries. Countries not listed are always shown and enabled."
2604
2639
  )
@@ -2616,7 +2651,7 @@ var AdministrativeAreas = import_v43.default.enum([
2616
2651
  ]);
2617
2652
  var AdministrativeAreaField = BaseField.extend({
2618
2653
  type: import_v43.default.literal(FieldType.ADMINISTRATIVE_AREA),
2619
- defaultValue: import_v43.default.union([NonEmptyTextValue, SerializedUserField]).optional(),
2654
+ defaultValue: import_v43.default.union([NonEmptyTextValue, SerializedUserField, ComputedDefaultValue]).optional(),
2620
2655
  configuration: import_v43.default.object({
2621
2656
  partOf: FieldReference.optional().describe("Parent location"),
2622
2657
  type: AdministrativeAreas,
@@ -2628,7 +2663,7 @@ var AdministrativeAreaField = BaseField.extend({
2628
2663
  });
2629
2664
  var LocationInput = BaseField.extend({
2630
2665
  type: import_v43.default.literal(FieldType.LOCATION),
2631
- defaultValue: import_v43.default.union([NonEmptyTextValue, SerializedUserField]).optional(),
2666
+ defaultValue: import_v43.default.union([NonEmptyTextValue, SerializedUserField, ComputedDefaultValue]).optional(),
2632
2667
  configuration: import_v43.default.object({
2633
2668
  locationTypes: import_v43.default.array(import_v43.default.string()).optional().describe("Types of the locations that are available for selection."),
2634
2669
  allowedLocations: AllowedLocations
@@ -2640,7 +2675,7 @@ var LocationInput = BaseField.extend({
2640
2675
  var FileUploadWithOptions = BaseField.extend({
2641
2676
  type: import_v43.default.literal(FieldType.FILE_WITH_OPTIONS),
2642
2677
  options: import_v43.default.array(SelectOption).describe("A list of options"),
2643
- defaultValue: FileFieldWithOptionValue.optional(),
2678
+ defaultValue: FileFieldWithOptionValue.or(ComputedDefaultValue).optional(),
2644
2679
  configuration: import_v43.default.object({
2645
2680
  maxFileSize: import_v43.default.number().describe("Maximum file size in bytes").default(DEFAULT_MAX_FILE_SIZE_BYTES),
2646
2681
  maxImageSize: import_v43.default.object({
@@ -2656,12 +2691,12 @@ var FileUploadWithOptions = BaseField.extend({
2656
2691
  });
2657
2692
  var Facility = BaseField.extend({
2658
2693
  type: import_v43.default.literal(FieldType.FACILITY),
2659
- defaultValue: NonEmptyTextValue.optional(),
2694
+ defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional(),
2660
2695
  configuration: import_v43.default.object({ allowedLocations: AllowedLocations }).optional()
2661
2696
  }).describe("Input field for a facility");
2662
2697
  var Office = BaseField.extend({
2663
2698
  type: import_v43.default.literal(FieldType.OFFICE),
2664
- defaultValue: NonEmptyTextValue.optional(),
2699
+ defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional(),
2665
2700
  configuration: import_v43.default.object({ allowedLocations: AllowedLocations }).optional()
2666
2701
  }).describe("Input field for an office");
2667
2702
  var DefaultAddressFieldValue = DomesticAddressFieldValue.extend({
@@ -2697,7 +2732,7 @@ var Address = BaseField.extend({
2697
2732
  ).optional(),
2698
2733
  allowedLocations: AllowedLocations
2699
2734
  }).optional(),
2700
- defaultValue: DefaultAddressFieldValue.optional()
2735
+ defaultValue: DefaultAddressFieldValue.or(ComputedDefaultValue).optional()
2701
2736
  }).meta({
2702
2737
  description: "Address input field \u2013 a combination of location and text fields",
2703
2738
  id: "Address"
@@ -2744,7 +2779,7 @@ var ButtonConfiguration = import_v43.default.object({
2744
2779
  });
2745
2780
  var ButtonField = BaseField.extend({
2746
2781
  type: import_v43.default.literal(FieldType.BUTTON),
2747
- defaultValue: ButtonFieldValue.optional(),
2782
+ defaultValue: ButtonFieldValue.or(ComputedDefaultValue).optional(),
2748
2783
  configuration: ButtonConfiguration
2749
2784
  }).meta({
2750
2785
  description: "A generic button that can be used to trigger an action",
@@ -2772,7 +2807,7 @@ var AlphaPrintButton = BaseField.extend({
2772
2807
  });
2773
2808
  var HttpField = BaseField.extend({
2774
2809
  type: import_v43.default.literal(FieldType.HTTP),
2775
- defaultValue: HttpFieldValue.optional(),
2810
+ defaultValue: HttpFieldValue.or(ComputedDefaultValue).optional(),
2776
2811
  configuration: import_v43.default.object({
2777
2812
  trigger: FieldReference.optional().describe(
2778
2813
  "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."
@@ -2858,7 +2893,7 @@ var LinkButtonField = BaseField.extend({
2858
2893
  });
2859
2894
  var VerificationStatus = BaseField.extend({
2860
2895
  type: import_v43.default.literal(FieldType.VERIFICATION_STATUS),
2861
- defaultValue: VerificationStatusValue.optional(),
2896
+ defaultValue: VerificationStatusValue.or(ComputedDefaultValue).optional(),
2862
2897
  configuration: import_v43.default.object({
2863
2898
  status: TranslationConfig.describe("Text to display on the status pill."),
2864
2899
  description: TranslationConfig.describe(
@@ -2880,7 +2915,7 @@ var QueryParamReaderField = BaseField.extend({
2880
2915
  });
2881
2916
  var QrReaderField = BaseField.extend({
2882
2917
  type: import_v43.default.literal(FieldType.QR_READER),
2883
- defaultValue: QrReaderFieldValue.optional(),
2918
+ defaultValue: QrReaderFieldValue.or(ComputedDefaultValue).optional(),
2884
2919
  configuration: import_v43.default.object({
2885
2920
  validator: import_v43.default.any().meta({
2886
2921
  description: "JSON Schema to validate the scanned QR code data against before populating the form fields.",
@@ -2893,7 +2928,7 @@ var QrReaderField = BaseField.extend({
2893
2928
  });
2894
2929
  var IdReaderField = BaseField.extend({
2895
2930
  type: import_v43.default.literal(FieldType.ID_READER),
2896
- defaultValue: IdReaderFieldValue.optional(),
2931
+ defaultValue: IdReaderFieldValue.or(ComputedDefaultValue).optional(),
2897
2932
  methods: import_v43.default.array(
2898
2933
  import_v43.default.union([QrReaderField, LinkButtonField]).describe("Methods for reading an ID")
2899
2934
  )
@@ -3452,6 +3487,9 @@ var BaseField3 = z28.object({
3452
3487
  ),
3453
3488
  validations: z28.array(ValidationConfig).optional().describe(
3454
3489
  `Option for overriding the field validations specifically for advanced search form.`
3490
+ ),
3491
+ allowedLocations: JurisdictionReference.optional().describe(
3492
+ `Override the allowedLocations for a location field in advanced search. Use this when the declaration form's allowedLocations references a scope (e.g. record.create) that search-only users don't have \u2014 specify record.search scope instead.`
3455
3493
  )
3456
3494
  });
3457
3495
  var SearchQueryParams = z28.object({
@@ -3526,9 +3564,11 @@ var z30 = __toESM(require("zod/v4"));
3526
3564
  var z29 = __toESM(require("zod/v4"));
3527
3565
  function getDynamicNameValue(field3) {
3528
3566
  const nameConfiguration = field3.configuration?.name;
3567
+ const firstnameRequired = nameConfiguration?.firstname?.required ?? field3.required;
3568
+ const surnameRequired = nameConfiguration?.surname?.required ?? field3.required;
3529
3569
  return z29.object({
3530
- firstname: nameConfiguration?.firstname?.required ? NonEmptyTextValue : TextValue,
3531
- surname: nameConfiguration?.surname?.required ? NonEmptyTextValue : TextValue,
3570
+ firstname: firstnameRequired ? NonEmptyTextValue : TextValue,
3571
+ surname: surnameRequired ? NonEmptyTextValue : TextValue,
3532
3572
  middlename: nameConfiguration?.middlename?.required ? NonEmptyTextValue : TextValue.optional()
3533
3573
  });
3534
3574
  }
@@ -3911,7 +3951,37 @@ function resolveDataPath(rootData, dataPath, instancePath) {
3911
3951
  }
3912
3952
  return current;
3913
3953
  }
3954
+ function todayISO() {
3955
+ return (0, import_date_fns.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" });
3956
+ }
3957
+ var compiledFunctionCache = /* @__PURE__ */ new Map();
3958
+ function compileClientFunction(code) {
3959
+ let fn = compiledFunctionCache.get(code);
3960
+ if (!fn) {
3961
+ fn = new Function(`return (${code})`)();
3962
+ compiledFunctionCache.set(code, fn);
3963
+ }
3964
+ return fn;
3965
+ }
3914
3966
  (0, import_ajv_formats.default)(ajv);
3967
+ function buildClientFunctionContext(input) {
3968
+ return {
3969
+ $form: input.form,
3970
+ $now: todayISO(),
3971
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
3972
+ $online: isOnline(),
3973
+ $user: input.validatorContext?.user,
3974
+ $event: input.validatorContext?.event,
3975
+ $leafAdminStructureLocationIds: input.validatorContext?.leafAdminStructureLocationIds ?? [],
3976
+ user: input.systemVariables?.user,
3977
+ $window: input.systemVariables?.$window,
3978
+ locations: input.locations,
3979
+ adminLevelIds: input.adminLevelIds
3980
+ };
3981
+ }
3982
+ function runClientFunction(code, data, context) {
3983
+ return compileClientFunction(code)(data, context);
3984
+ }
3915
3985
  ajv.addKeyword({
3916
3986
  keyword: "daysFromDate",
3917
3987
  type: "string",
@@ -3956,7 +4026,7 @@ ajv.addKeyword({
3956
4026
  $data: true,
3957
4027
  errors: true,
3958
4028
  // @ts-ignore -- Force type. We will move this away from AJV next. Parsing the array will take seconds and is only called by core.
3959
- validate(schema, data, _2, dataContext) {
4029
+ validate(_schema, data, _2, dataContext) {
3960
4030
  const locationIdInput = data;
3961
4031
  const locations = dataContext?.rootData.$leafAdminStructureLocationIds ?? [];
3962
4032
  return locations.some((location) => location.id === locationIdInput);
@@ -3987,6 +4057,23 @@ function isAgeValue(value) {
3987
4057
  function mergeWithBaseFormState(values, context) {
3988
4058
  return { ...context.baseFormState, ...values };
3989
4059
  }
4060
+ ajv.addKeyword({
4061
+ keyword: "customClientValidator",
4062
+ schemaType: "object",
4063
+ errors: true,
4064
+ // @ts-expect-error -- AJV's public types don't expose `rootData`. All
4065
+ // `validate()` callers build root data via `buildClientFunctionContext`,
4066
+ // so the cast holds.
4067
+ validate(schema, data, _2, dataContext) {
4068
+ return Boolean(
4069
+ runClientFunction(
4070
+ schema.code,
4071
+ data,
4072
+ dataContext?.rootData ?? buildClientFunctionContext({ form: {} })
4073
+ )
4074
+ );
4075
+ }
4076
+ });
3990
4077
  function validate(schema, data) {
3991
4078
  const validator = ajv.getSchema(schema.$id) || ajv.compile(schema);
3992
4079
  if ("$form" in data) {
@@ -4023,17 +4110,14 @@ function isOnline() {
4023
4110
  }
4024
4111
  return true;
4025
4112
  }
4026
- function isConditionMet(conditional, values, context, eventIndex) {
4027
- return validate(conditional, {
4028
- $form: mergeWithBaseFormState(values, context),
4029
- $now: (0, import_date_fns.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" }),
4030
- $online: isOnline(),
4031
- $user: context.user,
4032
- $leafAdminStructureLocationIds: context.leafAdminStructureLocationIds ?? [],
4033
- $flags: eventIndex?.flags ?? [],
4034
- $status: eventIndex?.status,
4035
- $event: context.event
4036
- });
4113
+ function isConditionMet(conditional, values, context) {
4114
+ return validate(
4115
+ conditional,
4116
+ buildClientFunctionContext({
4117
+ form: mergeWithBaseFormState(values, context),
4118
+ validatorContext: context
4119
+ })
4120
+ );
4037
4121
  }
4038
4122
  function getConditionalActionsForField(field3, values) {
4039
4123
  if (!field3.conditionals) {
@@ -4041,9 +4125,9 @@ function getConditionalActionsForField(field3, values) {
4041
4125
  }
4042
4126
  return field3.conditionals.filter((conditional) => validate(conditional.conditional, values)).map((conditional) => conditional.type);
4043
4127
  }
4044
- function areConditionsMet(conditions, values, context, event2) {
4128
+ function areConditionsMet(conditions, values, context, _event) {
4045
4129
  return conditions.every(
4046
- (condition) => isConditionMet(condition.conditional, values, context, event2)
4130
+ (condition) => isConditionMet(condition.conditional, values, context)
4047
4131
  );
4048
4132
  }
4049
4133
  function isFieldConditionMet(field3, form, conditionalType, context) {
@@ -4053,14 +4137,13 @@ function isFieldConditionMet(field3, form, conditionalType, context) {
4053
4137
  if (!hasRule) {
4054
4138
  return true;
4055
4139
  }
4056
- const validConditionals = getConditionalActionsForField(field3, {
4057
- $form: mergeWithBaseFormState(form, context),
4058
- $now: (0, import_date_fns.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" }),
4059
- $online: isOnline(),
4060
- $user: context.user,
4061
- $leafAdminStructureLocationIds: context.leafAdminStructureLocationIds ?? [],
4062
- $event: context.event
4063
- });
4140
+ const validConditionals = getConditionalActionsForField(
4141
+ field3,
4142
+ buildClientFunctionContext({
4143
+ form: mergeWithBaseFormState(form, context),
4144
+ validatorContext: context
4145
+ })
4146
+ );
4064
4147
  return validConditionals.includes(conditionalType);
4065
4148
  }
4066
4149
  function isFieldVisible(field3, form, context) {
@@ -4086,7 +4169,14 @@ function isActionConditionMet(actionConfig, event2, context, conditionalType) {
4086
4169
  if (!rule) {
4087
4170
  return true;
4088
4171
  }
4089
- return isConditionMet(rule.conditional, event2.declaration, context, event2);
4172
+ return validate(rule.conditional, {
4173
+ ...buildClientFunctionContext({
4174
+ form: mergeWithBaseFormState(event2.declaration, context),
4175
+ validatorContext: context
4176
+ }),
4177
+ $flags: event2.flags,
4178
+ $status: event2.status
4179
+ });
4090
4180
  }
4091
4181
  function isActionEnabled(actionConfig, event2, context) {
4092
4182
  return isActionConditionMet(
@@ -4245,19 +4335,10 @@ function runFieldValidations({
4245
4335
  if (!isFieldVisible(field3.config, form, context)) {
4246
4336
  return [];
4247
4337
  }
4248
- const conditionalParameters = {
4249
- $form: mergeWithBaseFormState(form, context),
4250
- $now: (0, import_date_fns.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" }),
4251
- /**
4252
- * In real use cases, there can be hundreds of thousands of locations.
4253
- * Make sure that the context contains only the locations that are needed for validation.
4254
- * E.g. if the user is a leaf admin, only the leaf locations under their admin structure are needed.
4255
- * Loading few megabytes of locations to memory just for validation is not efficient and will choke the application.
4256
- */
4257
- $leafAdminStructureLocationIds: context.leafAdminStructureLocationIds ?? [],
4258
- $online: isOnline(),
4259
- $user: context.user
4260
- };
4338
+ const conditionalParameters = buildClientFunctionContext({
4339
+ form: mergeWithBaseFormState(form, context),
4340
+ validatorContext: context
4341
+ });
4261
4342
  if (isFieldGroupFieldType(field3)) {
4262
4343
  const subfieldErrors = buildFormState(
4263
4344
  field3.config.fields,
@@ -4741,19 +4822,16 @@ function getPendingAction(actions) {
4741
4822
  }
4742
4823
  return pendingActions[0];
4743
4824
  }
4744
- function getCompleteActionAnnotation(annotation, event2, action) {
4825
+ function getCompleteActionAnnotation(event2, action) {
4745
4826
  if (action.originalActionId) {
4746
4827
  const originalAction = event2.actions.find(
4747
4828
  ({ id }) => id === action.originalActionId
4748
4829
  );
4749
4830
  if (originalAction?.status === ActionStatus.Requested) {
4750
- return deepMerge(
4751
- deepMerge(annotation, originalAction.annotation ?? {}),
4752
- action.annotation ?? {}
4753
- );
4831
+ return deepMerge(originalAction.annotation ?? {}, action.annotation ?? {});
4754
4832
  }
4755
4833
  }
4756
- return deepMerge(annotation, action.annotation ?? {});
4834
+ return action.annotation ?? {};
4757
4835
  }
4758
4836
  function getCompleteActionContent(event2, action) {
4759
4837
  const currentContent = "content" in action ? action.content : void 0;
@@ -4789,7 +4867,7 @@ function getAcceptedActions(event2) {
4789
4867
  return event2.actions.filter(isAcceptedAction).map((action) => ({
4790
4868
  ...action,
4791
4869
  declaration: getCompleteActionDeclaration({}, event2, action),
4792
- annotation: getCompleteActionAnnotation({}, event2, action)
4870
+ annotation: getCompleteActionAnnotation(event2, action)
4793
4871
  }));
4794
4872
  }
4795
4873
  var EXCLUDED_ACTIONS = [
@@ -5427,7 +5505,54 @@ function createFieldConditionals(fieldId) {
5427
5505
  }
5428
5506
  },
5429
5507
  required: [fieldId]
5430
- })
5508
+ }),
5509
+ /**
5510
+ * Custom client-side validator. The provided function is serialised and executed
5511
+ * just-in-time on the client only. External references (e.g. lodash) are not
5512
+ * available inside the function body — all logic must be self-contained.
5513
+ *
5514
+ * @example
5515
+ * field('nid').customClientValidator((value) => {
5516
+ * // LUHN check — all logic must be inline
5517
+ * const digits = String(value).split('').map(Number)
5518
+ * // ...
5519
+ * return isValid
5520
+ * })
5521
+ */
5522
+ customClientValidator(validationFn) {
5523
+ const code = validationFn.toString();
5524
+ return defineFormConditional({
5525
+ type: "object",
5526
+ properties: wrapToPath(
5527
+ { [fieldId]: { customClientValidator: { code } } },
5528
+ this.$$subfield
5529
+ ),
5530
+ required: [fieldId]
5531
+ });
5532
+ },
5533
+ /**
5534
+ * Custom client-side evaluation. Returns a {@link FieldReference} descriptor
5535
+ * that can be used as the `value` property or a DATA component entry.
5536
+ * The function receives the referenced field's value as the first argument and
5537
+ * the full form context as the second; its return value replaces the field reference.
5538
+ * The function is serialised and executed just-in-time on the client only.
5539
+ * External references (e.g. lodash) are not available inside the function body.
5540
+ *
5541
+ * For computing a default value without referencing a specific field, use
5542
+ * `evaluate(fn)` in the `defaultValue` property instead.
5543
+ *
5544
+ * @example
5545
+ * field('a').customClientEvaluation((aValue, ctx) =>
5546
+ * Number(aValue) + Number(ctx.$form.b)
5547
+ * )
5548
+ */
5549
+ customClientEvaluation(computationFn) {
5550
+ return {
5551
+ $$code: computationFn.toString(),
5552
+ $$field: fieldId,
5553
+ $$subfield: this.$$subfield
5554
+ };
5555
+ }
5431
5556
  };
5432
5557
  }
5433
5558
 
@@ -6381,7 +6506,7 @@ function getActionUpdateMetadata(actions) {
6381
6506
  "createdAtLocation",
6382
6507
  "createdByRole"
6383
6508
  ];
6384
- return actions.filter(({ type }) => updateActions.safeParse(type).success).filter(({ status: status2 }) => status2 === ActionStatus.Accepted).reduce(
6509
+ return actions.filter(({ type }) => updateActions.safeParse(type).success).reduce(
6385
6510
  (_2, action) => {
6386
6511
  if (action.originalActionId) {
6387
6512
  const originalAction = actions.find(({ id }) => id === action.originalActionId) ?? action;
@@ -6786,7 +6911,7 @@ function getActionAnnotation({
6786
6911
  const action = (0, import_lodash4.findLast)(activeActions, (a) => a.type === actionType);
6787
6912
  const actionWithCompleteAnnotation = action && {
6788
6913
  ...action,
6789
- annotation: getCompleteActionAnnotation({}, event2, action)
6914
+ annotation: getCompleteActionAnnotation(event2, action)
6790
6915
  };
6791
6916
  const matchingDraft = draft?.action.type === actionType ? draft : void 0;
6792
6917
  const sortedActions = (0, import_lodash4.orderBy)(
@@ -6858,6 +6983,9 @@ function createFieldConfig(fieldId, options) {
6858
6983
  }
6859
6984
 
6860
6985
  // ../commons/src/events/field.ts
6986
+ function evaluate(computationFn) {
6987
+ return { $$code: computationFn.toString() };
6988
+ }
6861
6989
  function field(fieldId, options = {}) {
6862
6990
  return {
6863
6991
  ...createFieldConditionals(fieldId),
@@ -10502,18 +10630,19 @@ var ACTION_FILTERS = {
10502
10630
  function filterActionsByFlags(actions, flags) {
10503
10631
  return actions.filter((action) => ACTION_FILTERS[action]?.(flags) ?? true);
10504
10632
  }
10633
+ var REJECTED_ACTIONS = [
10634
+ ActionType.READ,
10635
+ ActionType.NOTIFY,
10636
+ ActionType.CUSTOM,
10637
+ ActionType.EDIT,
10638
+ ActionType.ARCHIVE
10639
+ ];
10505
10640
  function getAvailableActionsWithoutFlagFilters(status2, flags) {
10506
10641
  if (flags.includes(InherentFlags.EDIT_IN_PROGRESS)) {
10507
10642
  return [ActionType.NOTIFY, ActionType.DECLARE, ActionType.REGISTER];
10508
10643
  }
10509
- if (flags.includes(InherentFlags.REJECTED)) {
10510
- return [
10511
- ActionType.READ,
10512
- ActionType.NOTIFY,
10513
- ActionType.CUSTOM,
10514
- ActionType.EDIT,
10515
- ActionType.ARCHIVE
10516
- ];
10644
+ if (flags.includes(InherentFlags.REJECTED) && status2 !== EventStatus.enum.ARCHIVED) {
10645
+ return REJECTED_ACTIONS;
10517
10646
  }
10518
10647
  return AVAILABLE_ACTIONS_BY_EVENT_STATUS[status2];
10519
10648
  }