@opencrvs/toolkit 1.9.13-rc.0f86459 → 1.9.13-rc.1045e45

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.
@@ -1488,23 +1488,11 @@ var FieldId = import_zod17.z.string().refine(
1488
1488
  })
1489
1489
  ).describe("Unique identifier for the field");
1490
1490
  var FieldReference = import_zod17.z.object({
1491
- $$field: FieldId.describe(
1492
- "Field whose value is passed as the first argument to the computation"
1493
- ),
1491
+ $$field: FieldId,
1494
1492
  $$subfield: import_zod17.z.array(import_zod17.z.string()).optional().default([]).describe(
1495
1493
  'If the FieldValue is an object, subfield can be used to refer to e.g. `["foo", "bar"]` in `{ foo: { bar: 3 } }`'
1496
- ),
1497
- $$code: import_zod17.z.string().optional().describe(
1498
- "Serialised client-side function body. When present the expression is evaluated rather than dereferenced."
1499
- )
1500
- }).describe(
1501
- "Reference to a field value, with an optional client-side computation applied."
1502
- );
1503
- var ComputedDefaultValue = import_zod17.z.object({
1504
- $$code: import_zod17.z.string().describe(
1505
- "Serialised client-side function body. Receives (undefined, context) where context includes $now, $online, and system variables."
1506
1494
  )
1507
- }).describe("A context-only computation used as a field default value.");
1495
+ }).describe("Reference to a field by its ID");
1508
1496
  var ValidationConfig = import_zod17.z.object({
1509
1497
  validator: Conditional,
1510
1498
  message: TranslationConfig
@@ -1538,7 +1526,7 @@ var BaseField = import_zod17.z.object({
1538
1526
  "Indicates whether the field can be modified during record correction."
1539
1527
  ),
1540
1528
  value: FieldReference.or(import_zod17.z.array(FieldReference)).optional().describe(
1541
- "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."
1529
+ "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."
1542
1530
  ),
1543
1531
  analytics: import_zod17.z.boolean().default(false).optional().describe(
1544
1532
  "Indicates whether the field is included in analytics. When enabled, its value becomes available in the analytics dashboard."
@@ -1549,7 +1537,7 @@ var Divider = BaseField.extend({
1549
1537
  });
1550
1538
  var TextField = BaseField.extend({
1551
1539
  type: import_zod17.z.literal(FieldType.TEXT),
1552
- defaultValue: import_zod17.z.union([NonEmptyTextValue, SerializedUserField, ComputedDefaultValue]).optional(),
1540
+ defaultValue: import_zod17.z.union([NonEmptyTextValue, SerializedUserField]).optional(),
1553
1541
  configuration: import_zod17.z.object({
1554
1542
  maxLength: import_zod17.z.number().optional().describe("Maximum length of the text"),
1555
1543
  type: import_zod17.z.enum(["text", "password"]).optional(),
@@ -1559,7 +1547,7 @@ var TextField = BaseField.extend({
1559
1547
  }).describe("Text input");
1560
1548
  var NumberField = BaseField.extend({
1561
1549
  type: import_zod17.z.literal(FieldType.NUMBER),
1562
- defaultValue: NumberFieldValue.or(ComputedDefaultValue).optional(),
1550
+ defaultValue: NumberFieldValue.optional(),
1563
1551
  configuration: import_zod17.z.object({
1564
1552
  min: import_zod17.z.number().optional().describe("Minimum value"),
1565
1553
  max: import_zod17.z.number().optional().describe("Maximum value"),
@@ -1569,7 +1557,7 @@ var NumberField = BaseField.extend({
1569
1557
  }).describe("Number input");
1570
1558
  var TextAreaField = BaseField.extend({
1571
1559
  type: import_zod17.z.literal(FieldType.TEXTAREA),
1572
- defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional(),
1560
+ defaultValue: NonEmptyTextValue.optional(),
1573
1561
  configuration: import_zod17.z.object({
1574
1562
  maxLength: import_zod17.z.number().optional().describe("Maximum length of the text"),
1575
1563
  rows: import_zod17.z.number().optional().describe("Number of visible text lines"),
@@ -1600,7 +1588,7 @@ var SignatureField = BaseField.extend({
1600
1588
  signaturePromptLabel: TranslationConfig.describe(
1601
1589
  "Title of the signature modal"
1602
1590
  ),
1603
- defaultValue: SignatureFieldValue.or(ComputedDefaultValue).optional(),
1591
+ defaultValue: SignatureFieldValue.optional(),
1604
1592
  configuration: import_zod17.z.object({
1605
1593
  maxFileSize: import_zod17.z.number().describe("Maximum file size in bytes").default(DEFAULT_MAX_FILE_SIZE_BYTES),
1606
1594
  acceptedFileTypes: MimeType.array().optional().describe("List of allowed file formats for the signature")
@@ -1613,11 +1601,11 @@ var EmailField = BaseField.extend({
1613
1601
  configuration: import_zod17.z.object({
1614
1602
  maxLength: import_zod17.z.number().optional().describe("Maximum length of the text")
1615
1603
  }).default({ maxLength: 10 }).optional(),
1616
- defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional()
1604
+ defaultValue: NonEmptyTextValue.optional()
1617
1605
  });
1618
1606
  var DateField = BaseField.extend({
1619
1607
  type: import_zod17.z.literal(FieldType.DATE),
1620
- defaultValue: SerializedNowDateTime.or(PlainDate).or(ComputedDefaultValue).optional().openapi({ effectType: "input", type: "string" }).describe("Default date value(yyyy-MM-dd)"),
1608
+ defaultValue: SerializedNowDateTime.or(PlainDate).optional().openapi({ effectType: "input", type: "string" }).describe("Default date value(yyyy-MM-dd)"),
1621
1609
  configuration: import_zod17.z.object({
1622
1610
  notice: TranslationConfig.describe(
1623
1611
  "Text to display above the date input"
@@ -1626,7 +1614,7 @@ var DateField = BaseField.extend({
1626
1614
  }).describe("A single date input (yyyy-MM-dd)");
1627
1615
  var AgeField = BaseField.extend({
1628
1616
  type: import_zod17.z.literal(FieldType.AGE),
1629
- defaultValue: NumberFieldValue.or(ComputedDefaultValue).optional(),
1617
+ defaultValue: NumberFieldValue.optional(),
1630
1618
  configuration: import_zod17.z.object({
1631
1619
  asOfDate: FieldReference,
1632
1620
  prefix: TranslationConfig.optional(),
@@ -1635,7 +1623,7 @@ var AgeField = BaseField.extend({
1635
1623
  }).describe("An age input field which uses the current date as the asOfDate");
1636
1624
  var TimeField = BaseField.extend({
1637
1625
  type: import_zod17.z.literal(FieldType.TIME),
1638
- defaultValue: SerializedNowDateTime.or(TimeValue).or(ComputedDefaultValue).optional().openapi({ effectType: "input", type: "object" }).describe("Default time value (HH-mm)"),
1626
+ defaultValue: SerializedNowDateTime.or(TimeValue).optional().openapi({ effectType: "input", type: "object" }).describe("Default time value (HH-mm)"),
1639
1627
  configuration: import_zod17.z.object({
1640
1628
  use12HourFormat: import_zod17.z.boolean().optional().describe("Whether to use 12-hour format"),
1641
1629
  notice: TranslationConfig.describe(
@@ -1645,7 +1633,7 @@ var TimeField = BaseField.extend({
1645
1633
  }).describe("A single date input (HH-mm)");
1646
1634
  var DateRangeField = BaseField.extend({
1647
1635
  type: import_zod17.z.literal(FieldType.DATE_RANGE),
1648
- defaultValue: DateRangeFieldValue.or(ComputedDefaultValue).optional(),
1636
+ defaultValue: DateRangeFieldValue.optional(),
1649
1637
  configuration: import_zod17.z.object({
1650
1638
  notice: TranslationConfig.describe(
1651
1639
  "Text to display above the date input"
@@ -1679,7 +1667,7 @@ var PageHeader = BaseField.extend({
1679
1667
  }).describe("A read-only header component for form pages");
1680
1668
  var File = BaseField.extend({
1681
1669
  type: import_zod17.z.literal(FieldType.FILE),
1682
- defaultValue: FileFieldValue.or(ComputedDefaultValue).optional(),
1670
+ defaultValue: FileFieldValue.optional(),
1683
1671
  configuration: import_zod17.z.object({
1684
1672
  maxFileSize: import_zod17.z.number().describe("Maximum file size in bytes").default(DEFAULT_MAX_FILE_SIZE_BYTES),
1685
1673
  acceptedFileTypes: MimeType.array().optional().describe("List of allowed file formats for the signature"),
@@ -1703,7 +1691,7 @@ var SelectOption = import_zod17.z.object({
1703
1691
  });
1704
1692
  var NumberWithUnitField = BaseField.extend({
1705
1693
  type: import_zod17.z.literal(FieldType.NUMBER_WITH_UNIT),
1706
- defaultValue: NumberWithUnitFieldValue.or(ComputedDefaultValue).optional(),
1694
+ defaultValue: NumberWithUnitFieldValue.optional(),
1707
1695
  options: import_zod17.z.array(SelectOption).describe("A list of options for the unit select"),
1708
1696
  configuration: import_zod17.z.object({
1709
1697
  min: import_zod17.z.number().optional().describe("Minimum value of the number field"),
@@ -1715,7 +1703,7 @@ var NumberWithUnitField = BaseField.extend({
1715
1703
  }).describe("Number with unit input");
1716
1704
  var RadioGroup = BaseField.extend({
1717
1705
  type: import_zod17.z.literal(FieldType.RADIO_GROUP),
1718
- defaultValue: TextValue.or(ComputedDefaultValue).optional(),
1706
+ defaultValue: TextValue.optional(),
1719
1707
  options: import_zod17.z.array(SelectOption).describe("A list of options"),
1720
1708
  configuration: import_zod17.z.object({
1721
1709
  styles: import_zod17.z.object({
@@ -1734,7 +1722,7 @@ var BulletList = BaseField.extend({
1734
1722
  }).describe("A list of bullet points");
1735
1723
  var Select = BaseField.extend({
1736
1724
  type: import_zod17.z.literal(FieldType.SELECT),
1737
- defaultValue: TextValue.or(ComputedDefaultValue).optional(),
1725
+ defaultValue: TextValue.optional(),
1738
1726
  options: import_zod17.z.array(SelectOption).describe("A list of options"),
1739
1727
  noOptionsMessage: TranslationConfig.optional().describe(
1740
1728
  `
@@ -1753,7 +1741,7 @@ var SelectDateRangeOption = import_zod17.z.object({
1753
1741
  });
1754
1742
  var SelectDateRangeField = BaseField.extend({
1755
1743
  type: import_zod17.z.literal(FieldType.SELECT_DATE_RANGE),
1756
- defaultValue: SelectDateRangeValue.or(ComputedDefaultValue).optional(),
1744
+ defaultValue: SelectDateRangeValue.optional(),
1757
1745
  options: import_zod17.z.array(SelectDateRangeOption).describe("A list of options")
1758
1746
  }).describe("Select input with date range options");
1759
1747
  var NameConfig = import_zod17.z.object({
@@ -1767,7 +1755,7 @@ var NameField = BaseField.extend({
1767
1755
  firstname: SerializedUserField.or(NonEmptyTextValue).optional(),
1768
1756
  middlename: SerializedUserField.or(NonEmptyTextValue).optional(),
1769
1757
  surname: SerializedUserField.or(NonEmptyTextValue).optional()
1770
- }).or(ComputedDefaultValue).optional(),
1758
+ }).optional(),
1771
1759
  configuration: import_zod17.z.object({
1772
1760
  name: NameConfig.default({
1773
1761
  firstname: { required: true },
@@ -1788,20 +1776,20 @@ var NameField = BaseField.extend({
1788
1776
  }).optional()
1789
1777
  }).describe("Name input field");
1790
1778
  var PhoneField = BaseField.extend({
1791
- defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional(),
1779
+ defaultValue: NonEmptyTextValue.optional(),
1792
1780
  type: import_zod17.z.literal(FieldType.PHONE)
1793
1781
  }).describe("Phone input field");
1794
1782
  var IdField = BaseField.extend({
1795
- defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional(),
1783
+ defaultValue: NonEmptyTextValue.optional(),
1796
1784
  type: import_zod17.z.literal(FieldType.ID)
1797
1785
  }).describe("ID input field");
1798
1786
  var Checkbox = BaseField.extend({
1799
1787
  type: import_zod17.z.literal(FieldType.CHECKBOX),
1800
- defaultValue: CheckboxFieldValue.or(ComputedDefaultValue).default(false)
1788
+ defaultValue: CheckboxFieldValue.default(false)
1801
1789
  }).describe("Boolean checkbox field");
1802
1790
  var Country = BaseField.extend({
1803
1791
  type: import_zod17.z.literal(FieldType.COUNTRY),
1804
- defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional(),
1792
+ defaultValue: NonEmptyTextValue.optional(),
1805
1793
  optionOverrides: import_zod17.z.array(SelectOption.omit({ label: true })).optional().describe(
1806
1794
  "Conditionals for specific countries. Countries not listed are always shown and enabled."
1807
1795
  )
@@ -1817,12 +1805,12 @@ var AdministrativeAreaConfiguration = import_zod17.z.object({
1817
1805
  }).describe("Administrative area options");
1818
1806
  var AdministrativeArea = BaseField.extend({
1819
1807
  type: import_zod17.z.literal(FieldType.ADMINISTRATIVE_AREA),
1820
- defaultValue: import_zod17.z.union([NonEmptyTextValue, SerializedUserField, ComputedDefaultValue]).optional(),
1808
+ defaultValue: import_zod17.z.union([NonEmptyTextValue, SerializedUserField]).optional(),
1821
1809
  configuration: AdministrativeAreaConfiguration
1822
1810
  }).describe("Administrative area input field e.g. facility, office");
1823
1811
  var LocationInput = BaseField.extend({
1824
1812
  type: import_zod17.z.literal(FieldType.LOCATION),
1825
- defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional(),
1813
+ defaultValue: NonEmptyTextValue.optional(),
1826
1814
  configuration: import_zod17.z.object({
1827
1815
  searchableResource: import_zod17.z.array(import_zod17.z.enum(["locations", "facilities", "offices"]))
1828
1816
  })
@@ -1830,7 +1818,7 @@ var LocationInput = BaseField.extend({
1830
1818
  var FileUploadWithOptions = BaseField.extend({
1831
1819
  type: import_zod17.z.literal(FieldType.FILE_WITH_OPTIONS),
1832
1820
  options: import_zod17.z.array(SelectOption).describe("A list of options"),
1833
- defaultValue: FileFieldWithOptionValue.or(ComputedDefaultValue).optional(),
1821
+ defaultValue: FileFieldWithOptionValue.optional(),
1834
1822
  configuration: import_zod17.z.object({
1835
1823
  maxFileSize: import_zod17.z.number().describe("Maximum file size in bytes").default(DEFAULT_MAX_FILE_SIZE_BYTES),
1836
1824
  maxImageSize: import_zod17.z.object({
@@ -1843,11 +1831,11 @@ var FileUploadWithOptions = BaseField.extend({
1843
1831
  });
1844
1832
  var Facility = BaseField.extend({
1845
1833
  type: import_zod17.z.literal(FieldType.FACILITY),
1846
- defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional()
1834
+ defaultValue: NonEmptyTextValue.optional()
1847
1835
  }).describe("Input field for a facility");
1848
1836
  var Office = BaseField.extend({
1849
1837
  type: import_zod17.z.literal(FieldType.OFFICE),
1850
- defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional()
1838
+ defaultValue: NonEmptyTextValue.optional()
1851
1839
  }).describe("Input field for an office");
1852
1840
  var DefaultAddressFieldValue = DomesticAddressFieldValue.extend({
1853
1841
  administrativeArea: import_zod17.z.union([UUID, SerializedUserField]).optional()
@@ -1881,7 +1869,7 @@ var Address = BaseField.extend({
1881
1869
  })
1882
1870
  ).optional()
1883
1871
  }).optional(),
1884
- defaultValue: DefaultAddressFieldValue.or(ComputedDefaultValue).optional()
1872
+ defaultValue: DefaultAddressFieldValue.optional()
1885
1873
  }).describe("Address input field \u2013 a combination of location and text fields");
1886
1874
  var StaticDataEntry = import_zod17.z.object({
1887
1875
  id: import_zod17.z.string().describe("ID for the data entry."),
@@ -1900,7 +1888,7 @@ var DataField = BaseField.extend({
1900
1888
  }).describe("Data field for displaying read-only data");
1901
1889
  var ButtonField = BaseField.extend({
1902
1890
  type: import_zod17.z.literal(FieldType.BUTTON),
1903
- defaultValue: ButtonFieldValue.or(ComputedDefaultValue).optional(),
1891
+ defaultValue: ButtonFieldValue.optional(),
1904
1892
  configuration: import_zod17.z.object({
1905
1893
  icon: import_zod17.z.string().optional().describe(
1906
1894
  "Icon for the button. You can find icons from OpenCRVS UI-Kit."
@@ -1925,7 +1913,7 @@ var AlphaPrintButton = BaseField.extend({
1925
1913
  }).describe("Print button field for printing certificates");
1926
1914
  var HttpField = BaseField.extend({
1927
1915
  type: import_zod17.z.literal(FieldType.HTTP),
1928
- defaultValue: HttpFieldValue.or(ComputedDefaultValue).optional(),
1916
+ defaultValue: HttpFieldValue.optional(),
1929
1917
  configuration: import_zod17.z.object({
1930
1918
  trigger: FieldReference,
1931
1919
  url: import_zod17.z.string().describe("URL to send the HTTP request to"),
@@ -1980,7 +1968,7 @@ var LinkButtonField = BaseField.extend({
1980
1968
  }).describe("Button that opens a link");
1981
1969
  var VerificationStatus = BaseField.extend({
1982
1970
  type: import_zod17.z.literal(FieldType.VERIFICATION_STATUS),
1983
- defaultValue: VerificationStatusValue.or(ComputedDefaultValue).optional(),
1971
+ defaultValue: VerificationStatusValue.optional(),
1984
1972
  configuration: import_zod17.z.object({
1985
1973
  status: TranslationConfig.describe("Text to display on the status pill."),
1986
1974
  description: TranslationConfig.describe(
@@ -1998,7 +1986,7 @@ var QueryParamReaderField = BaseField.extend({
1998
1986
  );
1999
1987
  var QrReaderField = BaseField.extend({
2000
1988
  type: import_zod17.z.literal(FieldType.QR_READER),
2001
- defaultValue: QrReaderFieldValue.or(ComputedDefaultValue).optional(),
1989
+ defaultValue: QrReaderFieldValue.optional(),
2002
1990
  configuration: import_zod17.z.object({
2003
1991
  validator: import_zod17.z.custom(
2004
1992
  (val) => typeof val === "object" && val !== null
@@ -2007,7 +1995,7 @@ var QrReaderField = BaseField.extend({
2007
1995
  });
2008
1996
  var IdReaderField = BaseField.extend({
2009
1997
  type: import_zod17.z.literal(FieldType.ID_READER),
2010
- defaultValue: IdReaderFieldValue.or(ComputedDefaultValue).optional(),
1998
+ defaultValue: IdReaderFieldValue.optional(),
2011
1999
  methods: import_zod17.z.array(
2012
2000
  import_zod17.z.union([QrReaderField, LinkButtonField]).describe("Methods for reading an ID")
2013
2001
  )
@@ -2568,15 +2556,6 @@ function resolveDataPath(rootData, dataPath, instancePath) {
2568
2556
  }
2569
2557
  return current;
2570
2558
  }
2571
- var compiledFunctionCache = /* @__PURE__ */ new Map();
2572
- function compileClientFunction(code) {
2573
- let fn = compiledFunctionCache.get(code);
2574
- if (!fn) {
2575
- fn = new Function(`return (${code})`)();
2576
- compiledFunctionCache.set(code, fn);
2577
- }
2578
- return fn;
2579
- }
2580
2559
  (0, import_ajv_formats.default)(ajv);
2581
2560
  ajv.addKeyword({
2582
2561
  keyword: "daysFromDate",
@@ -2622,21 +2601,12 @@ ajv.addKeyword({
2622
2601
  $data: true,
2623
2602
  errors: true,
2624
2603
  // @ts-ignore -- Force type. We will move this away from AJV next. Parsing the array will take seconds and is only called by core.
2625
- validate(_schema, data, _2, dataContext) {
2604
+ validate(schema, data, _2, dataContext) {
2626
2605
  const locationIdInput = data;
2627
2606
  const locations = dataContext?.rootData.$leafAdminStructureLocationIds ?? [];
2628
2607
  return locations.some((location) => location.id === locationIdInput);
2629
2608
  }
2630
2609
  });
2631
- ajv.addKeyword({
2632
- keyword: "customClientValidator",
2633
- schemaType: "object",
2634
- errors: true,
2635
- // @ts-ignore -- DataContext is not typed in AJV's public API
2636
- validate(schema, data, _2, dataContext) {
2637
- return compileClientFunction(schema.code)(data, dataContext?.rootData);
2638
- }
2639
- });
2640
2610
 
2641
2611
  // ../commons/src/utils.ts
2642
2612
  var z29 = __toESM(require("zod"));
@@ -3259,54 +3229,7 @@ function createFieldConditionals(fieldId) {
3259
3229
  }
3260
3230
  },
3261
3231
  required: [fieldId]
3262
- }),
3263
- /**
3264
- * Custom client-side validator. The provided function is serialised and executed
3265
- * just-in-time on the client only. External references (e.g. lodash) are not
3266
- * available inside the function body — all logic must be self-contained.
3267
- *
3268
- * @example
3269
- * field('nid').customClientValidator((value) => {
3270
- * // LUHN check — all logic must be inline
3271
- * const digits = String(value).split('').map(Number)
3272
- * // ...
3273
- * return isValid
3274
- * })
3275
- */
3276
- customClientValidator(validationFn) {
3277
- const code = validationFn.toString();
3278
- return defineFormConditional({
3279
- type: "object",
3280
- properties: wrapToPath(
3281
- { [fieldId]: { customClientValidator: { code } } },
3282
- this.$$subfield
3283
- ),
3284
- required: [fieldId]
3285
- });
3286
- },
3287
- /**
3288
- * Custom client-side evaluation. Returns a {@link FieldReference} descriptor
3289
- * that can be used as the `value` property or a DATA component entry.
3290
- * The function receives the referenced field's value as the first argument and
3291
- * the full form context as the second; its return value replaces the field reference.
3292
- * The function is serialised and executed just-in-time on the client only.
3293
- * External references (e.g. lodash) are not available inside the function body.
3294
- *
3295
- * For computing a default value without referencing a specific field, use
3296
- * `evaluate(fn)` in the `defaultValue` property instead.
3297
- *
3298
- * @example
3299
- * field('a').customClientEvaluation((aValue, ctx) =>
3300
- * Number(aValue) + Number(ctx.$form.b)
3301
- * )
3302
- */
3303
- customClientEvaluation(computationFn) {
3304
- return {
3305
- $$code: computationFn.toString(),
3306
- $$field: fieldId,
3307
- $$subfield: this.$$subfield
3308
- };
3309
- }
3232
+ })
3310
3233
  };
3311
3234
  }
3312
3235
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opencrvs/toolkit",
3
- "version": "1.9.13-rc.0f86459",
3
+ "version": "1.9.13-rc.1045e45",
4
4
  "description": "OpenCRVS toolkit for building country configurations",
5
5
  "license": "MPL-2.0",
6
6
  "exports": {