@opencrvs/toolkit 2.0.0-rc.0f51ec5 → 2.0.0-rc.0fb1707

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,7 +75,6 @@ __export(events_exports, {
75
75
  CheckboxFieldValue: () => CheckboxFieldValue,
76
76
  Clause: () => Clause,
77
77
  ClientSpecificAction: () => ClientSpecificAction,
78
- ComputedDefaultValue: () => ComputedDefaultValue,
79
78
  Conditional: () => Conditional,
80
79
  ConditionalType: () => ConditionalType,
81
80
  ConfirmableActions: () => ConfirmableActions,
@@ -201,7 +200,6 @@ __export(events_exports, {
201
200
  SelectDateRangeValue: () => SelectDateRangeValue,
202
201
  SelectOption: () => SelectOption,
203
202
  ShowConditional: () => ShowConditional,
204
- SignatureFieldValue: () => SignatureFieldValue,
205
203
  StaticDataEntry: () => StaticDataEntry,
206
204
  StreetLevelDetailsUpdateValue: () => StreetLevelDetailsUpdateValue,
207
205
  SummaryConfig: () => SummaryConfig,
@@ -248,12 +246,10 @@ __export(events_exports, {
248
246
  applyDraftToEventIndex: () => applyDraftToEventIndex,
249
247
  areCertificateConditionsMet: () => areCertificateConditionsMet,
250
248
  areConditionsMet: () => areConditionsMet,
251
- buildClientFunctionContext: () => buildClientFunctionContext,
252
249
  buildFormState: () => buildFormState,
253
250
  canAccessEventWithScope: () => canAccessEventWithScope,
254
251
  canAccessOtherUserWithScopes: () => canAccessOtherUserWithScopes,
255
252
  canAccessUserWithScope: () => canAccessUserWithScope,
256
- compileClientFunction: () => compileClientFunction,
257
253
  compositeFieldTypes: () => compositeFieldTypes,
258
254
  createEmptyDraft: () => createEmptyDraft,
259
255
  createFieldConditionals: () => createFieldConditionals,
@@ -274,7 +270,6 @@ __export(events_exports, {
274
270
  defineWorkqueuesColumns: () => defineWorkqueuesColumns,
275
271
  deserializeQuery: () => deserializeQuery,
276
272
  errorMessages: () => errorMessages,
277
- evaluate: () => evaluate,
278
273
  event: () => event,
279
274
  eventMetadataLabelMap: () => eventMetadataLabelMap,
280
275
  eventPayloadGenerator: () => eventPayloadGenerator,
@@ -352,7 +347,6 @@ __export(events_exports, {
352
347
  isBulletListFieldType: () => isBulletListFieldType,
353
348
  isButtonFieldType: () => isButtonFieldType,
354
349
  isCheckboxFieldType: () => isCheckboxFieldType,
355
- isCodeToEvaluate: () => isCodeToEvaluate,
356
350
  isConditionMet: () => isConditionMet,
357
351
  isCountryFieldType: () => isCountryFieldType,
358
352
  isCustomFieldType: () => isCustomFieldType,
@@ -429,13 +423,11 @@ __export(events_exports, {
429
423
  resolveDateOfEvent: () => resolveDateOfEvent,
430
424
  resolveEventCustomFlags: () => resolveEventCustomFlags,
431
425
  resolvePlaceOfEvent: () => resolvePlaceOfEvent,
432
- runClientFunction: () => runClientFunction,
433
426
  runFieldValidations: () => runFieldValidations,
434
427
  runStructuralValidations: () => runStructuralValidations,
435
428
  safeUnion: () => safeUnion,
436
429
  status: () => status,
437
430
  timePeriodToDateRange: () => timePeriodToDateRange,
438
- todayISO: () => todayISO,
439
431
  user: () => user,
440
432
  userCanAccessEventWithScopes: () => userCanAccessEventWithScopes,
441
433
  validate: () => validate,
@@ -1367,7 +1359,6 @@ var DateRangeFieldValue = z12.object({
1367
1359
  var EmailValue = z12.email();
1368
1360
  var CheckboxFieldValue = z12.boolean();
1369
1361
  var NumberFieldValue = z12.number();
1370
- var SignatureFieldValue = FileFieldValue;
1371
1362
  var ButtonFieldValue = z12.number();
1372
1363
  var VerificationStatusValue = z12.enum([
1373
1364
  "verified",
@@ -2198,21 +2189,8 @@ var FieldReference = import_v43.default.object({
2198
2189
  $$field: FieldId.describe("Id of the field to reference"),
2199
2190
  $$subfield: import_v43.default.array(import_v43.default.string()).optional().default([]).describe(
2200
2191
  '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."
2204
- )
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
2192
  )
2215
- }).describe("A context-only computation used as a field default value.");
2193
+ }).describe("Reference to a field by its ID");
2216
2194
  var ValidationConfig = import_v43.default.object({
2217
2195
  validator: Conditional.describe(
2218
2196
  "Conditional expression that must hold for the field value to be considered valid."
@@ -2253,7 +2231,7 @@ var BaseField = import_v43.default.object({
2253
2231
  "Indicates whether the field can be modified during record correction."
2254
2232
  ),
2255
2233
  value: FieldReference.or(import_v43.default.array(FieldReference)).optional().describe(
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."
2234
+ "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."
2257
2235
  ),
2258
2236
  analytics: import_v43.default.boolean().default(false).optional().describe(
2259
2237
  "Indicates whether the field is included in analytics. When enabled, its value becomes available in the analytics dashboard."
@@ -2267,7 +2245,7 @@ var Divider = BaseField.extend({
2267
2245
  });
2268
2246
  var TextField = BaseField.extend({
2269
2247
  type: import_v43.default.literal(FieldType.TEXT),
2270
- defaultValue: import_v43.default.union([NonEmptyTextValue, SerializedUserField, ComputedDefaultValue]).optional(),
2248
+ defaultValue: import_v43.default.union([NonEmptyTextValue, SerializedUserField]).optional(),
2271
2249
  configuration: import_v43.default.object({
2272
2250
  maxLength: import_v43.default.number().optional().describe("Maximum length of the text"),
2273
2251
  type: import_v43.default.enum(["text", "password"]).optional(),
@@ -2280,7 +2258,7 @@ var TextField = BaseField.extend({
2280
2258
  });
2281
2259
  var NumberField = BaseField.extend({
2282
2260
  type: import_v43.default.literal(FieldType.NUMBER),
2283
- defaultValue: NumberFieldValue.or(ComputedDefaultValue).optional(),
2261
+ defaultValue: NumberFieldValue.optional(),
2284
2262
  configuration: import_v43.default.object({
2285
2263
  min: import_v43.default.number().optional().describe("Minimum value"),
2286
2264
  max: import_v43.default.number().optional().describe("Maximum value"),
@@ -2293,7 +2271,7 @@ var NumberField = BaseField.extend({
2293
2271
  });
2294
2272
  var TextAreaField = BaseField.extend({
2295
2273
  type: import_v43.default.literal(FieldType.TEXTAREA),
2296
- defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional(),
2274
+ defaultValue: NonEmptyTextValue.optional(),
2297
2275
  configuration: import_v43.default.object({
2298
2276
  maxLength: import_v43.default.number().optional().describe("Maximum length of the text"),
2299
2277
  rows: import_v43.default.number().optional().describe("Number of visible text lines"),
@@ -2327,7 +2305,7 @@ var SignatureField = BaseField.extend({
2327
2305
  signaturePromptLabel: TranslationConfig.describe(
2328
2306
  "Title of the signature modal"
2329
2307
  ),
2330
- defaultValue: SignatureFieldValue.or(ComputedDefaultValue).optional(),
2308
+ defaultValue: FieldValue.optional(),
2331
2309
  configuration: import_v43.default.object({
2332
2310
  maxFileSize: import_v43.default.number().describe("Maximum file size in bytes").default(DEFAULT_MAX_FILE_SIZE_BYTES),
2333
2311
  acceptedFileTypes: MimeType.array().optional().describe("List of allowed file formats for the signature")
@@ -2343,14 +2321,14 @@ var EmailField = BaseField.extend({
2343
2321
  configuration: import_v43.default.object({
2344
2322
  maxLength: import_v43.default.number().optional().describe("Maximum length of the text")
2345
2323
  }).default({ maxLength: 255 }).optional(),
2346
- defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional()
2324
+ defaultValue: NonEmptyTextValue.optional()
2347
2325
  }).meta({
2348
2326
  description: "An email input field",
2349
2327
  id: "EmailField"
2350
2328
  });
2351
2329
  var DateField = BaseField.extend({
2352
2330
  type: import_v43.default.literal(FieldType.DATE),
2353
- defaultValue: SerializedNowDateTime.or(PlainDate).or(ComputedDefaultValue).optional().describe("Default date value(yyyy-MM-dd)"),
2331
+ defaultValue: SerializedNowDateTime.or(PlainDate).optional().describe("Default date value(yyyy-MM-dd)"),
2354
2332
  configuration: import_v43.default.object({
2355
2333
  notice: TranslationConfig.describe(
2356
2334
  "Text to display above the date input"
@@ -2362,7 +2340,7 @@ var DateField = BaseField.extend({
2362
2340
  });
2363
2341
  var AgeField = BaseField.extend({
2364
2342
  type: import_v43.default.literal(FieldType.AGE),
2365
- defaultValue: NumberFieldValue.or(ComputedDefaultValue).optional(),
2343
+ defaultValue: NumberFieldValue.optional(),
2366
2344
  configuration: import_v43.default.object({
2367
2345
  asOfDate: FieldReference,
2368
2346
  prefix: TranslationConfig.optional(),
@@ -2374,7 +2352,7 @@ var AgeField = BaseField.extend({
2374
2352
  });
2375
2353
  var TimeField = BaseField.extend({
2376
2354
  type: import_v43.default.literal(FieldType.TIME),
2377
- defaultValue: SerializedNowDateTime.or(TimeValue).or(ComputedDefaultValue).optional().describe("Default time value (HH-mm)"),
2355
+ defaultValue: SerializedNowDateTime.or(TimeValue).optional().describe("Default time value (HH-mm)"),
2378
2356
  configuration: import_v43.default.object({
2379
2357
  use12HourFormat: import_v43.default.boolean().optional().describe("Whether to use 12-hour format"),
2380
2358
  notice: TranslationConfig.describe(
@@ -2387,7 +2365,7 @@ var TimeField = BaseField.extend({
2387
2365
  });
2388
2366
  var DateRangeField = BaseField.extend({
2389
2367
  type: import_v43.default.literal(FieldType.DATE_RANGE),
2390
- defaultValue: DateRangeFieldValue.or(ComputedDefaultValue).optional(),
2368
+ defaultValue: DateRangeFieldValue.optional(),
2391
2369
  configuration: import_v43.default.object({
2392
2370
  notice: TranslationConfig.describe(
2393
2371
  "Text to display above the date input"
@@ -2466,7 +2444,7 @@ var PageHeader = BaseField.extend({
2466
2444
  });
2467
2445
  var File = BaseField.extend({
2468
2446
  type: import_v43.default.literal(FieldType.FILE),
2469
- defaultValue: FileFieldValue.or(ComputedDefaultValue).optional(),
2447
+ defaultValue: FileFieldValue.optional(),
2470
2448
  configuration: import_v43.default.object({
2471
2449
  maxFileSize: import_v43.default.number().describe("Maximum file size in bytes").default(DEFAULT_MAX_FILE_SIZE_BYTES),
2472
2450
  acceptedFileTypes: MimeType.array().optional().describe("List of allowed file formats for the signature"),
@@ -2493,7 +2471,7 @@ var SelectOption = import_v43.default.object({
2493
2471
  });
2494
2472
  var NumberWithUnitField = BaseField.extend({
2495
2473
  type: import_v43.default.literal(FieldType.NUMBER_WITH_UNIT),
2496
- defaultValue: NumberWithUnitFieldValue.or(ComputedDefaultValue).optional(),
2474
+ defaultValue: NumberWithUnitFieldValue.optional(),
2497
2475
  options: import_v43.default.array(SelectOption).describe("A list of options for the unit select"),
2498
2476
  configuration: import_v43.default.object({
2499
2477
  min: import_v43.default.number().optional().describe("Minimum value of the number field"),
@@ -2508,7 +2486,7 @@ var NumberWithUnitField = BaseField.extend({
2508
2486
  });
2509
2487
  var RadioGroup = BaseField.extend({
2510
2488
  type: import_v43.default.literal(FieldType.RADIO_GROUP),
2511
- defaultValue: TextValue.or(ComputedDefaultValue).optional(),
2489
+ defaultValue: TextValue.optional(),
2512
2490
  options: import_v43.default.array(SelectOption).describe("A list of options"),
2513
2491
  configuration: import_v43.default.object({
2514
2492
  styles: import_v43.default.object({
@@ -2533,7 +2511,7 @@ var BulletList = BaseField.extend({
2533
2511
  });
2534
2512
  var Select = BaseField.extend({
2535
2513
  type: import_v43.default.literal(FieldType.SELECT),
2536
- defaultValue: TextValue.or(ComputedDefaultValue).optional(),
2514
+ defaultValue: TextValue.optional(),
2537
2515
  options: import_v43.default.array(SelectOption).describe("A list of options"),
2538
2516
  noOptionsMessage: TranslationConfig.optional().describe(
2539
2517
  `
@@ -2555,7 +2533,7 @@ var SelectDateRangeOption = import_v43.default.object({
2555
2533
  });
2556
2534
  var SelectDateRangeField = BaseField.extend({
2557
2535
  type: import_v43.default.literal(FieldType.SELECT_DATE_RANGE),
2558
- defaultValue: SelectDateRangeValue.or(ComputedDefaultValue).optional(),
2536
+ defaultValue: SelectDateRangeValue.optional(),
2559
2537
  options: import_v43.default.array(SelectDateRangeOption).describe("A list of options")
2560
2538
  }).meta({
2561
2539
  description: "A date range selection field",
@@ -2572,7 +2550,7 @@ var NameField = BaseField.extend({
2572
2550
  firstname: SerializedUserField.or(NonEmptyTextValue).optional(),
2573
2551
  middlename: SerializedUserField.or(NonEmptyTextValue).optional(),
2574
2552
  surname: SerializedUserField.or(NonEmptyTextValue).optional()
2575
- }).or(ComputedDefaultValue).optional(),
2553
+ }).optional(),
2576
2554
  configuration: import_v43.default.object({
2577
2555
  name: NameConfig.default({
2578
2556
  firstname: { required: true },
@@ -2596,14 +2574,14 @@ var NameField = BaseField.extend({
2596
2574
  id: "NameField"
2597
2575
  });
2598
2576
  var PhoneField = BaseField.extend({
2599
- defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional(),
2577
+ defaultValue: NonEmptyTextValue.optional(),
2600
2578
  type: import_v43.default.literal(FieldType.PHONE)
2601
2579
  }).meta({
2602
2580
  description: "A field for entering a phone number",
2603
2581
  id: "PhoneField"
2604
2582
  });
2605
2583
  var IdField = BaseField.extend({
2606
- defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional(),
2584
+ defaultValue: NonEmptyTextValue.optional(),
2607
2585
  type: import_v43.default.literal(FieldType.ID)
2608
2586
  }).meta({
2609
2587
  description: "A field for entering an ID",
@@ -2611,14 +2589,14 @@ var IdField = BaseField.extend({
2611
2589
  });
2612
2590
  var Checkbox = BaseField.extend({
2613
2591
  type: import_v43.default.literal(FieldType.CHECKBOX),
2614
- defaultValue: CheckboxFieldValue.or(ComputedDefaultValue).default(false)
2592
+ defaultValue: CheckboxFieldValue.default(false)
2615
2593
  }).meta({
2616
2594
  description: "A boolean checkbox field",
2617
2595
  id: "Checkbox"
2618
2596
  });
2619
2597
  var Country = BaseField.extend({
2620
2598
  type: import_v43.default.literal(FieldType.COUNTRY),
2621
- defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional(),
2599
+ defaultValue: NonEmptyTextValue.optional(),
2622
2600
  optionOverrides: import_v43.default.array(SelectOption.omit({ label: true })).optional().describe(
2623
2601
  "Conditionals for specific countries. Countries not listed are always shown and enabled."
2624
2602
  )
@@ -2636,7 +2614,7 @@ var AdministrativeAreas = import_v43.default.enum([
2636
2614
  ]);
2637
2615
  var AdministrativeAreaField = BaseField.extend({
2638
2616
  type: import_v43.default.literal(FieldType.ADMINISTRATIVE_AREA),
2639
- defaultValue: import_v43.default.union([NonEmptyTextValue, SerializedUserField, ComputedDefaultValue]).optional(),
2617
+ defaultValue: import_v43.default.union([NonEmptyTextValue, SerializedUserField]).optional(),
2640
2618
  configuration: import_v43.default.object({
2641
2619
  partOf: FieldReference.optional().describe("Parent location"),
2642
2620
  type: AdministrativeAreas,
@@ -2648,7 +2626,7 @@ var AdministrativeAreaField = BaseField.extend({
2648
2626
  });
2649
2627
  var LocationInput = BaseField.extend({
2650
2628
  type: import_v43.default.literal(FieldType.LOCATION),
2651
- defaultValue: import_v43.default.union([NonEmptyTextValue, SerializedUserField, ComputedDefaultValue]).optional(),
2629
+ defaultValue: import_v43.default.union([NonEmptyTextValue, SerializedUserField]).optional(),
2652
2630
  configuration: import_v43.default.object({
2653
2631
  locationTypes: import_v43.default.array(import_v43.default.string()).optional().describe("Types of the locations that are available for selection."),
2654
2632
  allowedLocations: AllowedLocations
@@ -2660,7 +2638,7 @@ var LocationInput = BaseField.extend({
2660
2638
  var FileUploadWithOptions = BaseField.extend({
2661
2639
  type: import_v43.default.literal(FieldType.FILE_WITH_OPTIONS),
2662
2640
  options: import_v43.default.array(SelectOption).describe("A list of options"),
2663
- defaultValue: FileFieldWithOptionValue.or(ComputedDefaultValue).optional(),
2641
+ defaultValue: FileFieldWithOptionValue.optional(),
2664
2642
  configuration: import_v43.default.object({
2665
2643
  maxFileSize: import_v43.default.number().describe("Maximum file size in bytes").default(DEFAULT_MAX_FILE_SIZE_BYTES),
2666
2644
  maxImageSize: import_v43.default.object({
@@ -2676,12 +2654,12 @@ var FileUploadWithOptions = BaseField.extend({
2676
2654
  });
2677
2655
  var Facility = BaseField.extend({
2678
2656
  type: import_v43.default.literal(FieldType.FACILITY),
2679
- defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional(),
2657
+ defaultValue: NonEmptyTextValue.optional(),
2680
2658
  configuration: import_v43.default.object({ allowedLocations: AllowedLocations }).optional()
2681
2659
  }).describe("Input field for a facility");
2682
2660
  var Office = BaseField.extend({
2683
2661
  type: import_v43.default.literal(FieldType.OFFICE),
2684
- defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional(),
2662
+ defaultValue: NonEmptyTextValue.optional(),
2685
2663
  configuration: import_v43.default.object({ allowedLocations: AllowedLocations }).optional()
2686
2664
  }).describe("Input field for an office");
2687
2665
  var DefaultAddressFieldValue = DomesticAddressFieldValue.extend({
@@ -2717,7 +2695,7 @@ var Address = BaseField.extend({
2717
2695
  ).optional(),
2718
2696
  allowedLocations: AllowedLocations
2719
2697
  }).optional(),
2720
- defaultValue: DefaultAddressFieldValue.or(ComputedDefaultValue).optional()
2698
+ defaultValue: DefaultAddressFieldValue.optional()
2721
2699
  }).meta({
2722
2700
  description: "Address input field \u2013 a combination of location and text fields",
2723
2701
  id: "Address"
@@ -2764,7 +2742,7 @@ var ButtonConfiguration = import_v43.default.object({
2764
2742
  });
2765
2743
  var ButtonField = BaseField.extend({
2766
2744
  type: import_v43.default.literal(FieldType.BUTTON),
2767
- defaultValue: ButtonFieldValue.or(ComputedDefaultValue).optional(),
2745
+ defaultValue: ButtonFieldValue.optional(),
2768
2746
  configuration: ButtonConfiguration
2769
2747
  }).meta({
2770
2748
  description: "A generic button that can be used to trigger an action",
@@ -2792,7 +2770,7 @@ var AlphaPrintButton = BaseField.extend({
2792
2770
  });
2793
2771
  var HttpField = BaseField.extend({
2794
2772
  type: import_v43.default.literal(FieldType.HTTP),
2795
- defaultValue: HttpFieldValue.or(ComputedDefaultValue).optional(),
2773
+ defaultValue: HttpFieldValue.optional(),
2796
2774
  configuration: import_v43.default.object({
2797
2775
  trigger: FieldReference.optional().describe(
2798
2776
  "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."
@@ -2878,7 +2856,7 @@ var LinkButtonField = BaseField.extend({
2878
2856
  });
2879
2857
  var VerificationStatus = BaseField.extend({
2880
2858
  type: import_v43.default.literal(FieldType.VERIFICATION_STATUS),
2881
- defaultValue: VerificationStatusValue.or(ComputedDefaultValue).optional(),
2859
+ defaultValue: VerificationStatusValue.optional(),
2882
2860
  configuration: import_v43.default.object({
2883
2861
  status: TranslationConfig.describe("Text to display on the status pill."),
2884
2862
  description: TranslationConfig.describe(
@@ -2900,7 +2878,7 @@ var QueryParamReaderField = BaseField.extend({
2900
2878
  });
2901
2879
  var QrReaderField = BaseField.extend({
2902
2880
  type: import_v43.default.literal(FieldType.QR_READER),
2903
- defaultValue: QrReaderFieldValue.or(ComputedDefaultValue).optional(),
2881
+ defaultValue: QrReaderFieldValue.optional(),
2904
2882
  configuration: import_v43.default.object({
2905
2883
  validator: import_v43.default.any().meta({
2906
2884
  description: "JSON Schema to validate the scanned QR code data against before populating the form fields.",
@@ -2913,7 +2891,7 @@ var QrReaderField = BaseField.extend({
2913
2891
  });
2914
2892
  var IdReaderField = BaseField.extend({
2915
2893
  type: import_v43.default.literal(FieldType.ID_READER),
2916
- defaultValue: IdReaderFieldValue.or(ComputedDefaultValue).optional(),
2894
+ defaultValue: IdReaderFieldValue.optional(),
2917
2895
  methods: import_v43.default.array(
2918
2896
  import_v43.default.union([QrReaderField, LinkButtonField]).describe("Methods for reading an ID")
2919
2897
  )
@@ -3931,37 +3909,7 @@ function resolveDataPath(rootData, dataPath, instancePath) {
3931
3909
  }
3932
3910
  return current;
3933
3911
  }
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
- }
3946
3912
  (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
- }
3965
3913
  ajv.addKeyword({
3966
3914
  keyword: "daysFromDate",
3967
3915
  type: "string",
@@ -4006,7 +3954,7 @@ ajv.addKeyword({
4006
3954
  $data: true,
4007
3955
  errors: true,
4008
3956
  // @ts-ignore -- Force type. We will move this away from AJV next. Parsing the array will take seconds and is only called by core.
4009
- validate(_schema, data, _2, dataContext) {
3957
+ validate(schema, data, _2, dataContext) {
4010
3958
  const locationIdInput = data;
4011
3959
  const locations = dataContext?.rootData.$leafAdminStructureLocationIds ?? [];
4012
3960
  return locations.some((location) => location.id === locationIdInput);
@@ -4037,23 +3985,6 @@ function isAgeValue(value) {
4037
3985
  function mergeWithBaseFormState(values, context) {
4038
3986
  return { ...context.baseFormState, ...values };
4039
3987
  }
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
- });
4057
3988
  function validate(schema, data) {
4058
3989
  const validator = ajv.getSchema(schema.$id) || ajv.compile(schema);
4059
3990
  if ("$form" in data) {
@@ -4090,14 +4021,17 @@ function isOnline() {
4090
4021
  }
4091
4022
  return true;
4092
4023
  }
4093
- function isConditionMet(conditional, values, context) {
4094
- return validate(
4095
- conditional,
4096
- buildClientFunctionContext({
4097
- form: mergeWithBaseFormState(values, context),
4098
- validatorContext: context
4099
- })
4100
- );
4024
+ function isConditionMet(conditional, values, context, eventIndex) {
4025
+ return validate(conditional, {
4026
+ $form: mergeWithBaseFormState(values, context),
4027
+ $now: (0, import_date_fns.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" }),
4028
+ $online: isOnline(),
4029
+ $user: context.user,
4030
+ $leafAdminStructureLocationIds: context.leafAdminStructureLocationIds ?? [],
4031
+ $flags: eventIndex?.flags ?? [],
4032
+ $status: eventIndex?.status,
4033
+ $event: context.event
4034
+ });
4101
4035
  }
4102
4036
  function getConditionalActionsForField(field3, values) {
4103
4037
  if (!field3.conditionals) {
@@ -4105,9 +4039,9 @@ function getConditionalActionsForField(field3, values) {
4105
4039
  }
4106
4040
  return field3.conditionals.filter((conditional) => validate(conditional.conditional, values)).map((conditional) => conditional.type);
4107
4041
  }
4108
- function areConditionsMet(conditions, values, context, _event) {
4042
+ function areConditionsMet(conditions, values, context, event2) {
4109
4043
  return conditions.every(
4110
- (condition) => isConditionMet(condition.conditional, values, context)
4044
+ (condition) => isConditionMet(condition.conditional, values, context, event2)
4111
4045
  );
4112
4046
  }
4113
4047
  function isFieldConditionMet(field3, form, conditionalType, context) {
@@ -4117,13 +4051,14 @@ function isFieldConditionMet(field3, form, conditionalType, context) {
4117
4051
  if (!hasRule) {
4118
4052
  return true;
4119
4053
  }
4120
- const validConditionals = getConditionalActionsForField(
4121
- field3,
4122
- buildClientFunctionContext({
4123
- form: mergeWithBaseFormState(form, context),
4124
- validatorContext: context
4125
- })
4126
- );
4054
+ const validConditionals = getConditionalActionsForField(field3, {
4055
+ $form: mergeWithBaseFormState(form, context),
4056
+ $now: (0, import_date_fns.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" }),
4057
+ $online: isOnline(),
4058
+ $user: context.user,
4059
+ $leafAdminStructureLocationIds: context.leafAdminStructureLocationIds ?? [],
4060
+ $event: context.event
4061
+ });
4127
4062
  return validConditionals.includes(conditionalType);
4128
4063
  }
4129
4064
  function isFieldVisible(field3, form, context) {
@@ -4149,14 +4084,7 @@ function isActionConditionMet(actionConfig, event2, context, conditionalType) {
4149
4084
  if (!rule) {
4150
4085
  return true;
4151
4086
  }
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
- });
4087
+ return isConditionMet(rule.conditional, event2.declaration, context, event2);
4160
4088
  }
4161
4089
  function isActionEnabled(actionConfig, event2, context) {
4162
4090
  return isActionConditionMet(
@@ -4315,10 +4243,19 @@ function runFieldValidations({
4315
4243
  if (!isFieldVisible(field3.config, form, context)) {
4316
4244
  return [];
4317
4245
  }
4318
- const conditionalParameters = buildClientFunctionContext({
4319
- form: mergeWithBaseFormState(form, context),
4320
- validatorContext: context
4321
- });
4246
+ const conditionalParameters = {
4247
+ $form: mergeWithBaseFormState(form, context),
4248
+ $now: (0, import_date_fns.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" }),
4249
+ /**
4250
+ * In real use cases, there can be hundreds of thousands of locations.
4251
+ * Make sure that the context contains only the locations that are needed for validation.
4252
+ * E.g. if the user is a leaf admin, only the leaf locations under their admin structure are needed.
4253
+ * Loading few megabytes of locations to memory just for validation is not efficient and will choke the application.
4254
+ */
4255
+ $leafAdminStructureLocationIds: context.leafAdminStructureLocationIds ?? [],
4256
+ $online: isOnline(),
4257
+ $user: context.user
4258
+ };
4322
4259
  if (isFieldGroupFieldType(field3)) {
4323
4260
  const subfieldErrors = buildFormState(
4324
4261
  field3.config.fields,
@@ -4802,16 +4739,19 @@ function getPendingAction(actions) {
4802
4739
  }
4803
4740
  return pendingActions[0];
4804
4741
  }
4805
- function getCompleteActionAnnotation(event2, action) {
4742
+ function getCompleteActionAnnotation(annotation, event2, action) {
4806
4743
  if (action.originalActionId) {
4807
4744
  const originalAction = event2.actions.find(
4808
4745
  ({ id }) => id === action.originalActionId
4809
4746
  );
4810
4747
  if (originalAction?.status === ActionStatus.Requested) {
4811
- return deepMerge(originalAction.annotation ?? {}, action.annotation ?? {});
4748
+ return deepMerge(
4749
+ deepMerge(annotation, originalAction.annotation ?? {}),
4750
+ action.annotation ?? {}
4751
+ );
4812
4752
  }
4813
4753
  }
4814
- return action.annotation ?? {};
4754
+ return deepMerge(annotation, action.annotation ?? {});
4815
4755
  }
4816
4756
  function getCompleteActionDeclaration(declaration, event2, action) {
4817
4757
  if (action.originalActionId) {
@@ -4831,7 +4771,7 @@ function getAcceptedActions(event2) {
4831
4771
  return event2.actions.filter(isAcceptedAction).map((action) => ({
4832
4772
  ...action,
4833
4773
  declaration: getCompleteActionDeclaration({}, event2, action),
4834
- annotation: getCompleteActionAnnotation(event2, action)
4774
+ annotation: getCompleteActionAnnotation({}, event2, action)
4835
4775
  }));
4836
4776
  }
4837
4777
  var EXCLUDED_ACTIONS = [
@@ -5469,54 +5409,7 @@ function createFieldConditionals(fieldId) {
5469
5409
  }
5470
5410
  },
5471
5411
  required: [fieldId]
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
- }
5412
+ })
5520
5413
  };
5521
5414
  }
5522
5415
 
@@ -6874,7 +6767,7 @@ function getActionAnnotation({
6874
6767
  const action = (0, import_lodash4.findLast)(activeActions, (a) => a.type === actionType);
6875
6768
  const actionWithCompleteAnnotation = action && {
6876
6769
  ...action,
6877
- annotation: getCompleteActionAnnotation(event2, action)
6770
+ annotation: getCompleteActionAnnotation({}, event2, action)
6878
6771
  };
6879
6772
  const matchingDraft = draft?.action.type === actionType ? draft : void 0;
6880
6773
  const sortedActions = (0, import_lodash4.orderBy)(
@@ -6946,9 +6839,6 @@ function createFieldConfig(fieldId, options) {
6946
6839
  }
6947
6840
 
6948
6841
  // ../commons/src/events/field.ts
6949
- function evaluate(computationFn) {
6950
- return { $$code: computationFn.toString() };
6951
- }
6952
6842
  function field(fieldId, options = {}) {
6953
6843
  return {
6954
6844
  ...createFieldConditionals(fieldId),