@opencrvs/toolkit 1.9.13-rc.f1fdcea → 1.9.13-rc.f6200fe

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.
@@ -69,6 +69,7 @@ __export(events_exports, {
69
69
  CheckboxFieldValue: () => CheckboxFieldValue,
70
70
  Clause: () => Clause,
71
71
  ClientSpecificAction: () => ClientSpecificAction,
72
+ ComputedDefaultValue: () => ComputedDefaultValue,
72
73
  Conditional: () => Conditional,
73
74
  ConditionalType: () => ConditionalType,
74
75
  ConfirmableActions: () => ConfirmableActions,
@@ -227,8 +228,10 @@ __export(events_exports, {
227
228
  applyDraftToEventIndex: () => applyDraftToEventIndex,
228
229
  areCertificateConditionsMet: () => areCertificateConditionsMet,
229
230
  areConditionsMet: () => areConditionsMet,
231
+ buildClientFunctionContext: () => buildClientFunctionContext,
230
232
  buildFormState: () => buildFormState,
231
233
  canUserReadEvent: () => canUserReadEvent,
234
+ compileClientFunction: () => compileClientFunction,
232
235
  compositeFieldTypes: () => compositeFieldTypes,
233
236
  configurableEventScopeAllowed: () => configurableEventScopeAllowed,
234
237
  createEmptyDraft: () => createEmptyDraft,
@@ -250,6 +253,7 @@ __export(events_exports, {
250
253
  defineWorkqueuesColumns: () => defineWorkqueuesColumns,
251
254
  deserializeQuery: () => deserializeQuery,
252
255
  errorMessages: () => errorMessages,
256
+ evaluate: () => evaluate,
253
257
  event: () => event,
254
258
  eventMetadataLabelMap: () => eventMetadataLabelMap,
255
259
  eventPayloadGenerator: () => eventPayloadGenerator,
@@ -313,6 +317,7 @@ __export(events_exports, {
313
317
  isBulletListFieldType: () => isBulletListFieldType,
314
318
  isButtonFieldType: () => isButtonFieldType,
315
319
  isCheckboxFieldType: () => isCheckboxFieldType,
320
+ isCodeToEvaluate: () => isCodeToEvaluate,
316
321
  isConditionMet: () => isConditionMet,
317
322
  isCountryFieldType: () => isCountryFieldType,
318
323
  isDataFieldType: () => isDataFieldType,
@@ -379,10 +384,12 @@ __export(events_exports, {
379
384
  or: () => or,
380
385
  plainDateToLocalDate: () => plainDateToLocalDate,
381
386
  resolveDateOfEvent: () => resolveDateOfEvent,
387
+ runClientFunction: () => runClientFunction,
382
388
  runFieldValidations: () => runFieldValidations,
383
389
  runStructuralValidations: () => runStructuralValidations,
384
390
  safeUnion: () => safeUnion,
385
391
  timePeriodToDateRange: () => timePeriodToDateRange,
392
+ todayISO: () => todayISO,
386
393
  user: () => user,
387
394
  validate: () => validate,
388
395
  validateFieldInput: () => validateFieldInput,
@@ -1982,11 +1989,26 @@ var FieldId = import_zod17.z.string().refine(
1982
1989
  })
1983
1990
  ).describe("Unique identifier for the field");
1984
1991
  var FieldReference = import_zod17.z.object({
1985
- $$field: FieldId,
1992
+ $$field: FieldId.describe(
1993
+ "Field whose value is passed as the first argument to the computation"
1994
+ ),
1986
1995
  $$subfield: import_zod17.z.array(import_zod17.z.string()).optional().default([]).describe(
1987
1996
  'If the FieldValue is an object, subfield can be used to refer to e.g. `["foo", "bar"]` in `{ foo: { bar: 3 } }`'
1997
+ ),
1998
+ $$code: import_zod17.z.string().optional().describe(
1999
+ "Serialised client-side function body. When present the expression is evaluated rather than dereferenced."
1988
2000
  )
1989
- }).describe("Reference to a field by its ID");
2001
+ }).describe(
2002
+ "Reference to a field value, with an optional client-side computation applied."
2003
+ );
2004
+ function isCodeToEvaluate(v) {
2005
+ return !!v && typeof v === "object" && "$$code" in v;
2006
+ }
2007
+ var ComputedDefaultValue = import_zod17.z.object({
2008
+ $$code: import_zod17.z.string().describe(
2009
+ "Serialised client-side function body. Receives (undefined, context) where context includes $now, $online, and system variables."
2010
+ )
2011
+ }).describe("A context-only computation used as a field default value.");
1990
2012
  var ValidationConfig = import_zod17.z.object({
1991
2013
  validator: Conditional,
1992
2014
  message: TranslationConfig
@@ -2020,7 +2042,7 @@ var BaseField = import_zod17.z.object({
2020
2042
  "Indicates whether the field can be modified during record correction."
2021
2043
  ),
2022
2044
  value: FieldReference.or(import_zod17.z.array(FieldReference)).optional().describe(
2023
- "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."
2045
+ "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."
2024
2046
  ),
2025
2047
  analytics: import_zod17.z.boolean().default(false).optional().describe(
2026
2048
  "Indicates whether the field is included in analytics. When enabled, its value becomes available in the analytics dashboard."
@@ -2031,7 +2053,7 @@ var Divider = BaseField.extend({
2031
2053
  });
2032
2054
  var TextField = BaseField.extend({
2033
2055
  type: import_zod17.z.literal(FieldType.TEXT),
2034
- defaultValue: import_zod17.z.union([NonEmptyTextValue, SerializedUserField]).optional(),
2056
+ defaultValue: import_zod17.z.union([NonEmptyTextValue, SerializedUserField, ComputedDefaultValue]).optional(),
2035
2057
  configuration: import_zod17.z.object({
2036
2058
  maxLength: import_zod17.z.number().optional().describe("Maximum length of the text"),
2037
2059
  type: import_zod17.z.enum(["text", "password"]).optional(),
@@ -2041,7 +2063,7 @@ var TextField = BaseField.extend({
2041
2063
  }).describe("Text input");
2042
2064
  var NumberField = BaseField.extend({
2043
2065
  type: import_zod17.z.literal(FieldType.NUMBER),
2044
- defaultValue: NumberFieldValue.optional(),
2066
+ defaultValue: NumberFieldValue.or(ComputedDefaultValue).optional(),
2045
2067
  configuration: import_zod17.z.object({
2046
2068
  min: import_zod17.z.number().optional().describe("Minimum value"),
2047
2069
  max: import_zod17.z.number().optional().describe("Maximum value"),
@@ -2051,7 +2073,7 @@ var NumberField = BaseField.extend({
2051
2073
  }).describe("Number input");
2052
2074
  var TextAreaField = BaseField.extend({
2053
2075
  type: import_zod17.z.literal(FieldType.TEXTAREA),
2054
- defaultValue: NonEmptyTextValue.optional(),
2076
+ defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional(),
2055
2077
  configuration: import_zod17.z.object({
2056
2078
  maxLength: import_zod17.z.number().optional().describe("Maximum length of the text"),
2057
2079
  rows: import_zod17.z.number().optional().describe("Number of visible text lines"),
@@ -2082,7 +2104,7 @@ var SignatureField = BaseField.extend({
2082
2104
  signaturePromptLabel: TranslationConfig.describe(
2083
2105
  "Title of the signature modal"
2084
2106
  ),
2085
- defaultValue: SignatureFieldValue.optional(),
2107
+ defaultValue: SignatureFieldValue.or(ComputedDefaultValue).optional(),
2086
2108
  configuration: import_zod17.z.object({
2087
2109
  maxFileSize: import_zod17.z.number().describe("Maximum file size in bytes").default(DEFAULT_MAX_FILE_SIZE_BYTES),
2088
2110
  acceptedFileTypes: MimeType.array().optional().describe("List of allowed file formats for the signature")
@@ -2095,11 +2117,11 @@ var EmailField = BaseField.extend({
2095
2117
  configuration: import_zod17.z.object({
2096
2118
  maxLength: import_zod17.z.number().optional().describe("Maximum length of the text")
2097
2119
  }).default({ maxLength: 10 }).optional(),
2098
- defaultValue: NonEmptyTextValue.optional()
2120
+ defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional()
2099
2121
  });
2100
2122
  var DateField = BaseField.extend({
2101
2123
  type: import_zod17.z.literal(FieldType.DATE),
2102
- defaultValue: SerializedNowDateTime.or(PlainDate).optional().openapi({ effectType: "input", type: "string" }).describe("Default date value(yyyy-MM-dd)"),
2124
+ defaultValue: SerializedNowDateTime.or(PlainDate).or(ComputedDefaultValue).optional().openapi({ effectType: "input", type: "string" }).describe("Default date value(yyyy-MM-dd)"),
2103
2125
  configuration: import_zod17.z.object({
2104
2126
  notice: TranslationConfig.describe(
2105
2127
  "Text to display above the date input"
@@ -2108,7 +2130,7 @@ var DateField = BaseField.extend({
2108
2130
  }).describe("A single date input (yyyy-MM-dd)");
2109
2131
  var AgeField = BaseField.extend({
2110
2132
  type: import_zod17.z.literal(FieldType.AGE),
2111
- defaultValue: NumberFieldValue.optional(),
2133
+ defaultValue: NumberFieldValue.or(ComputedDefaultValue).optional(),
2112
2134
  configuration: import_zod17.z.object({
2113
2135
  asOfDate: FieldReference,
2114
2136
  prefix: TranslationConfig.optional(),
@@ -2117,7 +2139,7 @@ var AgeField = BaseField.extend({
2117
2139
  }).describe("An age input field which uses the current date as the asOfDate");
2118
2140
  var TimeField = BaseField.extend({
2119
2141
  type: import_zod17.z.literal(FieldType.TIME),
2120
- defaultValue: SerializedNowDateTime.or(TimeValue).optional().openapi({ effectType: "input", type: "object" }).describe("Default time value (HH-mm)"),
2142
+ defaultValue: SerializedNowDateTime.or(TimeValue).or(ComputedDefaultValue).optional().openapi({ effectType: "input", type: "object" }).describe("Default time value (HH-mm)"),
2121
2143
  configuration: import_zod17.z.object({
2122
2144
  use12HourFormat: import_zod17.z.boolean().optional().describe("Whether to use 12-hour format"),
2123
2145
  notice: TranslationConfig.describe(
@@ -2127,7 +2149,7 @@ var TimeField = BaseField.extend({
2127
2149
  }).describe("A single date input (HH-mm)");
2128
2150
  var DateRangeField = BaseField.extend({
2129
2151
  type: import_zod17.z.literal(FieldType.DATE_RANGE),
2130
- defaultValue: DateRangeFieldValue.optional(),
2152
+ defaultValue: DateRangeFieldValue.or(ComputedDefaultValue).optional(),
2131
2153
  configuration: import_zod17.z.object({
2132
2154
  notice: TranslationConfig.describe(
2133
2155
  "Text to display above the date input"
@@ -2154,16 +2176,14 @@ var ParagraphConfiguration = import_zod17.z.object({
2154
2176
  }).default({});
2155
2177
  var Paragraph = BaseField.extend({
2156
2178
  type: import_zod17.z.literal(FieldType.PARAGRAPH),
2157
- defaultValue: NonEmptyTextValue.optional(),
2158
2179
  configuration: ParagraphConfiguration
2159
2180
  }).describe("A read-only HTML <p> paragraph");
2160
2181
  var PageHeader = BaseField.extend({
2161
- type: import_zod17.z.literal(FieldType.PAGE_HEADER),
2162
- defaultValue: NonEmptyTextValue.optional()
2182
+ type: import_zod17.z.literal(FieldType.PAGE_HEADER)
2163
2183
  }).describe("A read-only header component for form pages");
2164
2184
  var File = BaseField.extend({
2165
2185
  type: import_zod17.z.literal(FieldType.FILE),
2166
- defaultValue: FileFieldValue.optional(),
2186
+ defaultValue: FileFieldValue.or(ComputedDefaultValue).optional(),
2167
2187
  configuration: import_zod17.z.object({
2168
2188
  maxFileSize: import_zod17.z.number().describe("Maximum file size in bytes").default(DEFAULT_MAX_FILE_SIZE_BYTES),
2169
2189
  acceptedFileTypes: MimeType.array().optional().describe("List of allowed file formats for the signature"),
@@ -2187,7 +2207,7 @@ var SelectOption = import_zod17.z.object({
2187
2207
  });
2188
2208
  var NumberWithUnitField = BaseField.extend({
2189
2209
  type: import_zod17.z.literal(FieldType.NUMBER_WITH_UNIT),
2190
- defaultValue: NumberWithUnitFieldValue.optional(),
2210
+ defaultValue: NumberWithUnitFieldValue.or(ComputedDefaultValue).optional(),
2191
2211
  options: import_zod17.z.array(SelectOption).describe("A list of options for the unit select"),
2192
2212
  configuration: import_zod17.z.object({
2193
2213
  min: import_zod17.z.number().optional().describe("Minimum value of the number field"),
@@ -2199,7 +2219,7 @@ var NumberWithUnitField = BaseField.extend({
2199
2219
  }).describe("Number with unit input");
2200
2220
  var RadioGroup = BaseField.extend({
2201
2221
  type: import_zod17.z.literal(FieldType.RADIO_GROUP),
2202
- defaultValue: TextValue.optional(),
2222
+ defaultValue: TextValue.or(ComputedDefaultValue).optional(),
2203
2223
  options: import_zod17.z.array(SelectOption).describe("A list of options"),
2204
2224
  configuration: import_zod17.z.object({
2205
2225
  styles: import_zod17.z.object({
@@ -2209,7 +2229,6 @@ var RadioGroup = BaseField.extend({
2209
2229
  }).describe("Grouped radio options");
2210
2230
  var BulletList = BaseField.extend({
2211
2231
  type: import_zod17.z.literal(FieldType.BULLET_LIST),
2212
- defaultValue: TextValue.optional(),
2213
2232
  items: import_zod17.z.array(TranslationConfig).describe("A list of items"),
2214
2233
  configuration: import_zod17.z.object({
2215
2234
  styles: import_zod17.z.object({
@@ -2219,7 +2238,7 @@ var BulletList = BaseField.extend({
2219
2238
  }).describe("A list of bullet points");
2220
2239
  var Select = BaseField.extend({
2221
2240
  type: import_zod17.z.literal(FieldType.SELECT),
2222
- defaultValue: TextValue.optional(),
2241
+ defaultValue: TextValue.or(ComputedDefaultValue).optional(),
2223
2242
  options: import_zod17.z.array(SelectOption).describe("A list of options"),
2224
2243
  noOptionsMessage: TranslationConfig.optional().describe(
2225
2244
  `
@@ -2238,7 +2257,7 @@ var SelectDateRangeOption = import_zod17.z.object({
2238
2257
  });
2239
2258
  var SelectDateRangeField = BaseField.extend({
2240
2259
  type: import_zod17.z.literal(FieldType.SELECT_DATE_RANGE),
2241
- defaultValue: SelectDateRangeValue.optional(),
2260
+ defaultValue: SelectDateRangeValue.or(ComputedDefaultValue).optional(),
2242
2261
  options: import_zod17.z.array(SelectDateRangeOption).describe("A list of options")
2243
2262
  }).describe("Select input with date range options");
2244
2263
  var NameConfig = import_zod17.z.object({
@@ -2252,7 +2271,7 @@ var NameField = BaseField.extend({
2252
2271
  firstname: SerializedUserField.or(NonEmptyTextValue).optional(),
2253
2272
  middlename: SerializedUserField.or(NonEmptyTextValue).optional(),
2254
2273
  surname: SerializedUserField.or(NonEmptyTextValue).optional()
2255
- }).optional(),
2274
+ }).or(ComputedDefaultValue).optional(),
2256
2275
  configuration: import_zod17.z.object({
2257
2276
  name: NameConfig.default({
2258
2277
  firstname: { required: true },
@@ -2273,20 +2292,20 @@ var NameField = BaseField.extend({
2273
2292
  }).optional()
2274
2293
  }).describe("Name input field");
2275
2294
  var PhoneField = BaseField.extend({
2276
- defaultValue: NonEmptyTextValue.optional(),
2295
+ defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional(),
2277
2296
  type: import_zod17.z.literal(FieldType.PHONE)
2278
2297
  }).describe("Phone input field");
2279
2298
  var IdField = BaseField.extend({
2280
- defaultValue: NonEmptyTextValue.optional(),
2299
+ defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional(),
2281
2300
  type: import_zod17.z.literal(FieldType.ID)
2282
2301
  }).describe("ID input field");
2283
2302
  var Checkbox = BaseField.extend({
2284
2303
  type: import_zod17.z.literal(FieldType.CHECKBOX),
2285
- defaultValue: CheckboxFieldValue.default(false)
2304
+ defaultValue: CheckboxFieldValue.or(ComputedDefaultValue).default(false)
2286
2305
  }).describe("Boolean checkbox field");
2287
2306
  var Country = BaseField.extend({
2288
2307
  type: import_zod17.z.literal(FieldType.COUNTRY),
2289
- defaultValue: NonEmptyTextValue.optional(),
2308
+ defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional(),
2290
2309
  optionOverrides: import_zod17.z.array(SelectOption.omit({ label: true })).optional().describe(
2291
2310
  "Conditionals for specific countries. Countries not listed are always shown and enabled."
2292
2311
  )
@@ -2302,12 +2321,12 @@ var AdministrativeAreaConfiguration = import_zod17.z.object({
2302
2321
  }).describe("Administrative area options");
2303
2322
  var AdministrativeArea = BaseField.extend({
2304
2323
  type: import_zod17.z.literal(FieldType.ADMINISTRATIVE_AREA),
2305
- defaultValue: import_zod17.z.union([NonEmptyTextValue, SerializedUserField]).optional(),
2324
+ defaultValue: import_zod17.z.union([NonEmptyTextValue, SerializedUserField, ComputedDefaultValue]).optional(),
2306
2325
  configuration: AdministrativeAreaConfiguration
2307
2326
  }).describe("Administrative area input field e.g. facility, office");
2308
2327
  var LocationInput = BaseField.extend({
2309
2328
  type: import_zod17.z.literal(FieldType.LOCATION),
2310
- defaultValue: NonEmptyTextValue.optional(),
2329
+ defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional(),
2311
2330
  configuration: import_zod17.z.object({
2312
2331
  searchableResource: import_zod17.z.array(import_zod17.z.enum(["locations", "facilities", "offices"]))
2313
2332
  })
@@ -2315,7 +2334,7 @@ var LocationInput = BaseField.extend({
2315
2334
  var FileUploadWithOptions = BaseField.extend({
2316
2335
  type: import_zod17.z.literal(FieldType.FILE_WITH_OPTIONS),
2317
2336
  options: import_zod17.z.array(SelectOption).describe("A list of options"),
2318
- defaultValue: FileFieldWithOptionValue.optional(),
2337
+ defaultValue: FileFieldWithOptionValue.or(ComputedDefaultValue).optional(),
2319
2338
  configuration: import_zod17.z.object({
2320
2339
  maxFileSize: import_zod17.z.number().describe("Maximum file size in bytes").default(DEFAULT_MAX_FILE_SIZE_BYTES),
2321
2340
  maxImageSize: import_zod17.z.object({
@@ -2328,11 +2347,11 @@ var FileUploadWithOptions = BaseField.extend({
2328
2347
  });
2329
2348
  var Facility = BaseField.extend({
2330
2349
  type: import_zod17.z.literal(FieldType.FACILITY),
2331
- defaultValue: NonEmptyTextValue.optional()
2350
+ defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional()
2332
2351
  }).describe("Input field for a facility");
2333
2352
  var Office = BaseField.extend({
2334
2353
  type: import_zod17.z.literal(FieldType.OFFICE),
2335
- defaultValue: NonEmptyTextValue.optional()
2354
+ defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional()
2336
2355
  }).describe("Input field for an office");
2337
2356
  var DefaultAddressFieldValue = DomesticAddressFieldValue.extend({
2338
2357
  administrativeArea: import_zod17.z.union([UUID, SerializedUserField]).optional()
@@ -2366,7 +2385,7 @@ var Address = BaseField.extend({
2366
2385
  })
2367
2386
  ).optional()
2368
2387
  }).optional(),
2369
- defaultValue: DefaultAddressFieldValue.optional()
2388
+ defaultValue: DefaultAddressFieldValue.or(ComputedDefaultValue).optional()
2370
2389
  }).describe("Address input field \u2013 a combination of location and text fields");
2371
2390
  var StaticDataEntry = import_zod17.z.object({
2372
2391
  id: import_zod17.z.string().describe("ID for the data entry."),
@@ -2385,7 +2404,7 @@ var DataField = BaseField.extend({
2385
2404
  }).describe("Data field for displaying read-only data");
2386
2405
  var ButtonField = BaseField.extend({
2387
2406
  type: import_zod17.z.literal(FieldType.BUTTON),
2388
- defaultValue: ButtonFieldValue.optional(),
2407
+ defaultValue: ButtonFieldValue.or(ComputedDefaultValue).optional(),
2389
2408
  configuration: import_zod17.z.object({
2390
2409
  icon: import_zod17.z.string().optional().describe(
2391
2410
  "Icon for the button. You can find icons from OpenCRVS UI-Kit."
@@ -2410,7 +2429,7 @@ var AlphaPrintButton = BaseField.extend({
2410
2429
  }).describe("Print button field for printing certificates");
2411
2430
  var HttpField = BaseField.extend({
2412
2431
  type: import_zod17.z.literal(FieldType.HTTP),
2413
- defaultValue: HttpFieldValue.optional(),
2432
+ defaultValue: HttpFieldValue.or(ComputedDefaultValue).optional(),
2414
2433
  configuration: import_zod17.z.object({
2415
2434
  trigger: FieldReference,
2416
2435
  url: import_zod17.z.string().describe("URL to send the HTTP request to"),
@@ -2465,7 +2484,7 @@ var LinkButtonField = BaseField.extend({
2465
2484
  }).describe("Button that opens a link");
2466
2485
  var VerificationStatus = BaseField.extend({
2467
2486
  type: import_zod17.z.literal(FieldType.VERIFICATION_STATUS),
2468
- defaultValue: VerificationStatusValue.optional(),
2487
+ defaultValue: VerificationStatusValue.or(ComputedDefaultValue).optional(),
2469
2488
  configuration: import_zod17.z.object({
2470
2489
  status: TranslationConfig.describe("Text to display on the status pill."),
2471
2490
  description: TranslationConfig.describe(
@@ -2483,7 +2502,7 @@ var QueryParamReaderField = BaseField.extend({
2483
2502
  );
2484
2503
  var QrReaderField = BaseField.extend({
2485
2504
  type: import_zod17.z.literal(FieldType.QR_READER),
2486
- defaultValue: QrReaderFieldValue.optional(),
2505
+ defaultValue: QrReaderFieldValue.or(ComputedDefaultValue).optional(),
2487
2506
  configuration: import_zod17.z.object({
2488
2507
  validator: import_zod17.z.custom(
2489
2508
  (val) => typeof val === "object" && val !== null
@@ -2492,7 +2511,7 @@ var QrReaderField = BaseField.extend({
2492
2511
  });
2493
2512
  var IdReaderField = BaseField.extend({
2494
2513
  type: import_zod17.z.literal(FieldType.ID_READER),
2495
- defaultValue: IdReaderFieldValue.optional(),
2514
+ defaultValue: IdReaderFieldValue.or(ComputedDefaultValue).optional(),
2496
2515
  methods: import_zod17.z.array(
2497
2516
  import_zod17.z.union([QrReaderField, LinkButtonField]).describe("Methods for reading an ID")
2498
2517
  )
@@ -3368,7 +3387,37 @@ function resolveDataPath(rootData, dataPath, instancePath) {
3368
3387
  }
3369
3388
  return current;
3370
3389
  }
3390
+ function todayISO() {
3391
+ return (0, import_date_fns.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" });
3392
+ }
3393
+ var compiledFunctionCache = /* @__PURE__ */ new Map();
3394
+ function compileClientFunction(code) {
3395
+ let fn = compiledFunctionCache.get(code);
3396
+ if (!fn) {
3397
+ fn = new Function(`return (${code})`)();
3398
+ compiledFunctionCache.set(code, fn);
3399
+ }
3400
+ return fn;
3401
+ }
3371
3402
  (0, import_ajv_formats.default)(ajv);
3403
+ function buildClientFunctionContext(input) {
3404
+ return {
3405
+ $form: input.form,
3406
+ $now: todayISO(),
3407
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
3408
+ $online: isOnline(),
3409
+ $user: input.validatorContext?.user,
3410
+ $event: input.validatorContext?.event,
3411
+ $leafAdminStructureLocationIds: input.validatorContext?.leafAdminStructureLocationIds ?? [],
3412
+ user: input.systemVariables?.user,
3413
+ $window: input.systemVariables?.$window,
3414
+ locations: input.locations,
3415
+ adminLevelIds: input.adminLevelIds
3416
+ };
3417
+ }
3418
+ function runClientFunction(code, data, context) {
3419
+ return compileClientFunction(code)(data, context);
3420
+ }
3372
3421
  ajv.addKeyword({
3373
3422
  keyword: "daysFromDate",
3374
3423
  type: "string",
@@ -3413,12 +3462,32 @@ ajv.addKeyword({
3413
3462
  $data: true,
3414
3463
  errors: true,
3415
3464
  // @ts-ignore -- Force type. We will move this away from AJV next. Parsing the array will take seconds and is only called by core.
3416
- validate(schema, data, _2, dataContext) {
3465
+ validate(_schema, data, _2, dataContext) {
3417
3466
  const locationIdInput = data;
3418
3467
  const locations = dataContext?.rootData.$leafAdminStructureLocationIds ?? [];
3419
3468
  return locations.some((location) => location.id === locationIdInput);
3420
3469
  }
3421
3470
  });
3471
+ function mergeWithBaseFormState(values, context) {
3472
+ return { ...context.baseFormState, ...values };
3473
+ }
3474
+ ajv.addKeyword({
3475
+ keyword: "customClientValidator",
3476
+ schemaType: "object",
3477
+ errors: true,
3478
+ // @ts-expect-error -- AJV's public types don't expose `rootData`. All
3479
+ // `validate()` callers build root data via `buildClientFunctionContext`,
3480
+ // so the cast holds.
3481
+ validate(schema, data, _2, dataContext) {
3482
+ return Boolean(
3483
+ runClientFunction(
3484
+ schema.code,
3485
+ data,
3486
+ dataContext?.rootData ?? buildClientFunctionContext({ form: {} })
3487
+ )
3488
+ );
3489
+ }
3490
+ });
3422
3491
  function validate(schema, data) {
3423
3492
  const validator = ajv.getSchema(schema.$id) || ajv.compile(schema);
3424
3493
  if ("$form" in data) {
@@ -3460,14 +3529,13 @@ function isOnline() {
3460
3529
  return true;
3461
3530
  }
3462
3531
  function isConditionMet(conditional, values, context) {
3463
- return validate(conditional, {
3464
- $form: values,
3465
- $now: (0, import_date_fns.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" }),
3466
- $online: isOnline(),
3467
- $user: context.user,
3468
- $leafAdminStructureLocationIds: context.leafAdminStructureLocationIds ?? [],
3469
- $event: context.event
3470
- });
3532
+ return validate(
3533
+ conditional,
3534
+ buildClientFunctionContext({
3535
+ form: mergeWithBaseFormState(values, context),
3536
+ validatorContext: context
3537
+ })
3538
+ );
3471
3539
  }
3472
3540
  function getConditionalActionsForField(field3, values) {
3473
3541
  if (!field3.conditionals) {
@@ -3487,14 +3555,13 @@ function isFieldConditionMet(field3, form, conditionalType, context) {
3487
3555
  if (!hasRule) {
3488
3556
  return true;
3489
3557
  }
3490
- const validConditionals = getConditionalActionsForField(field3, {
3491
- $form: form,
3492
- $now: (0, import_date_fns.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" }),
3493
- $online: isOnline(),
3494
- $user: context.user,
3495
- $leafAdminStructureLocationIds: context.leafAdminStructureLocationIds ?? [],
3496
- $event: context.event
3497
- });
3558
+ const validConditionals = getConditionalActionsForField(
3559
+ field3,
3560
+ buildClientFunctionContext({
3561
+ form: mergeWithBaseFormState(form, context),
3562
+ validatorContext: context
3563
+ })
3564
+ );
3498
3565
  return validConditionals.includes(conditionalType);
3499
3566
  }
3500
3567
  function isFieldVisible(field3, form, context) {
@@ -3640,20 +3707,10 @@ function runFieldValidations({
3640
3707
  if (!isFieldVisible(field3.config, form, context)) {
3641
3708
  return [];
3642
3709
  }
3643
- const conditionalParameters = {
3644
- $form: form,
3645
- $now: (0, import_date_fns.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" }),
3646
- /**
3647
- * In real use cases, there can be hundreds of thousands of locations.
3648
- * Make sure that the context contains only the locations that are needed for validation.
3649
- * E.g. if the user is a leaf admin, only the leaf locations under their admin structure are needed.
3650
- *
3651
- * Loading few megabytes of locations to memory just for validation is not efficient and will choke the application.
3652
- */
3653
- $leafAdminStructureLocationIds: context.leafAdminStructureLocationIds ?? [],
3654
- $online: isOnline(),
3655
- $user: context.user
3656
- };
3710
+ const conditionalParameters = buildClientFunctionContext({
3711
+ form: mergeWithBaseFormState(form, context),
3712
+ validatorContext: context
3713
+ });
3657
3714
  if (isFieldGroupFieldType(field3)) {
3658
3715
  const subfieldErrors = buildFormState(
3659
3716
  field3.config.fields,
@@ -3873,7 +3930,7 @@ function omitHiddenPaginatedFields(formConfig, values, validatorContext, include
3873
3930
  const visibleFields = formConfig.pages.filter((p) => isPageVisible(p, values, validatorContext)).flatMap((p) => p.fields);
3874
3931
  const hiddenFields = formConfig.pages.filter((p) => !isPageVisible(p, values, validatorContext)).flatMap((p) => p.fields);
3875
3932
  const valuesExceptHiddenPage = (0, import_lodash.omitBy)(values, (_2, fieldId) => {
3876
- return hiddenFields.some((f) => f.id === fieldId);
3933
+ return hiddenFields.some((f) => f.id === fieldId) && !visibleFields.some((f) => f.id === fieldId);
3877
3934
  });
3878
3935
  return omitHiddenFields(
3879
3936
  visibleFields,
@@ -3920,11 +3977,10 @@ function getVisibleVerificationPageIds(pages, annotation, context) {
3920
3977
  }
3921
3978
  function omitHiddenAnnotationFields(actionConfig, declaration, annotation, context) {
3922
3979
  const annotationFields = getActionAnnotationFields(actionConfig);
3923
- return omitHiddenFields(
3924
- annotationFields,
3925
- { ...declaration, ...annotation },
3926
- context
3927
- );
3980
+ return omitHiddenFields(annotationFields, annotation, {
3981
+ ...context,
3982
+ baseFormState: declaration
3983
+ });
3928
3984
  }
3929
3985
  function deepMerge(currentDocument, actionDocument) {
3930
3986
  const currentDocumentClone = (0, import_lodash.cloneDeep)(currentDocument);
@@ -4098,20 +4154,16 @@ function getPendingAction(actions) {
4098
4154
  }
4099
4155
  return pendingActions[0];
4100
4156
  }
4101
- function getCompleteActionAnnotation(annotation, event2, action) {
4157
+ function getCompleteActionAnnotation(event2, action) {
4102
4158
  if (action.originalActionId) {
4103
4159
  const originalAction = event2.actions.find(
4104
4160
  ({ id }) => id === action.originalActionId
4105
4161
  );
4106
- if (originalAction?.status !== ActionStatus.Requested) {
4107
- return annotation;
4162
+ if (originalAction?.status === ActionStatus.Requested) {
4163
+ return deepMerge(originalAction.annotation ?? {}, action.annotation ?? {});
4108
4164
  }
4109
- return deepMerge(
4110
- deepMerge(annotation, originalAction.annotation ?? {}),
4111
- action.annotation ?? {}
4112
- );
4113
4165
  }
4114
- return deepMerge(annotation, action.annotation ?? {});
4166
+ return action.annotation ?? {};
4115
4167
  }
4116
4168
  function getCompleteActionDeclaration(declaration, event2, action) {
4117
4169
  if (action.originalActionId) {
@@ -4131,7 +4183,7 @@ function getAcceptedActions(event2) {
4131
4183
  return event2.actions.filter(isAcceptedAction).map((action) => ({
4132
4184
  ...action,
4133
4185
  declaration: getCompleteActionDeclaration({}, event2, action),
4134
- annotation: getCompleteActionAnnotation({}, event2, action)
4186
+ annotation: getCompleteActionAnnotation(event2, action)
4135
4187
  }));
4136
4188
  }
4137
4189
  var EXCLUDED_ACTIONS = [
@@ -4726,7 +4778,54 @@ function createFieldConditionals(fieldId) {
4726
4778
  }
4727
4779
  },
4728
4780
  required: [fieldId]
4729
- })
4781
+ }),
4782
+ /**
4783
+ * Custom client-side validator. The provided function is serialised and executed
4784
+ * just-in-time on the client only. External references (e.g. lodash) are not
4785
+ * available inside the function body — all logic must be self-contained.
4786
+ *
4787
+ * @example
4788
+ * field('nid').customClientValidator((value) => {
4789
+ * // LUHN check — all logic must be inline
4790
+ * const digits = String(value).split('').map(Number)
4791
+ * // ...
4792
+ * return isValid
4793
+ * })
4794
+ */
4795
+ customClientValidator(validationFn) {
4796
+ const code = validationFn.toString();
4797
+ return defineFormConditional({
4798
+ type: "object",
4799
+ properties: wrapToPath(
4800
+ { [fieldId]: { customClientValidator: { code } } },
4801
+ this.$$subfield
4802
+ ),
4803
+ required: [fieldId]
4804
+ });
4805
+ },
4806
+ /**
4807
+ * Custom client-side evaluation. Returns a {@link FieldReference} descriptor
4808
+ * that can be used as the `value` property or a DATA component entry.
4809
+ * The function receives the referenced field's value as the first argument and
4810
+ * the full form context as the second; its return value replaces the field reference.
4811
+ * The function is serialised and executed just-in-time on the client only.
4812
+ * External references (e.g. lodash) are not available inside the function body.
4813
+ *
4814
+ * For computing a default value without referencing a specific field, use
4815
+ * `evaluate(fn)` in the `defaultValue` property instead.
4816
+ *
4817
+ * @example
4818
+ * field('a').customClientEvaluation((aValue, ctx) =>
4819
+ * Number(aValue) + Number(ctx.$form.b)
4820
+ * )
4821
+ */
4822
+ customClientEvaluation(computationFn) {
4823
+ return {
4824
+ $$code: computationFn.toString(),
4825
+ $$field: fieldId,
4826
+ $$subfield: this.$$subfield
4827
+ };
4828
+ }
4730
4829
  };
4731
4830
  }
4732
4831
 
@@ -5307,6 +5406,8 @@ var BaseActionInput = import_zod34.z.object({
5307
5406
  originalActionId: UUID.optional(),
5308
5407
  // should not be part of base action.
5309
5408
  keepAssignment: import_zod34.z.boolean().optional(),
5409
+ keepAssignmentIfAccepted: import_zod34.z.boolean().optional(),
5410
+ keepAssignmentIfRejected: import_zod34.z.boolean().optional(),
5310
5411
  // For normal users, the createdAtLocation is resolved on the backend from the user's primaryOfficeId.
5311
5412
  createdAtLocation: CreatedAtLocation.describe(
5312
5413
  "A valid office location ID. This is required for system users performing actions. The provided location must be a leaf-location, i.e. it must not have any children locations."
@@ -5877,7 +5978,7 @@ function getActionAnnotation({
5877
5978
  const action = (0, import_lodash3.findLast)(activeActions, (a) => a.type === actionType);
5878
5979
  const actionWithCompleteAnnotation = action && {
5879
5980
  ...action,
5880
- annotation: getCompleteActionAnnotation({}, event2, action)
5981
+ annotation: getCompleteActionAnnotation(event2, action)
5881
5982
  };
5882
5983
  const matchingDraft = draft?.action.type === actionType ? draft : void 0;
5883
5984
  const sortedActions = (0, import_lodash3.orderBy)(
@@ -5919,6 +6020,9 @@ function createFieldConfig(fieldId, options) {
5919
6020
  }
5920
6021
 
5921
6022
  // ../commons/src/events/field.ts
6023
+ function evaluate(computationFn) {
6024
+ return { $$code: computationFn.toString() };
6025
+ }
5922
6026
  function field(fieldId, options = {}) {
5923
6027
  return {
5924
6028
  ...createFieldConditionals(fieldId),