@opencrvs/toolkit 1.9.13-rc.17d2842 → 1.9.13-rc.2299d16
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.
- package/dist/commons/api/router.d.ts +1 -0
- package/dist/commons/conditionals/conditionals.d.ts +345 -2
- package/dist/commons/conditionals/validate.d.ts +8 -0
- package/dist/commons/events/EventConfig.d.ts +7 -0
- package/dist/commons/events/FieldConfig.d.ts +1489 -88
- package/dist/commons/events/defineConfig.d.ts +1 -0
- package/dist/commons/events/field.d.ts +47 -1
- package/dist/commons/events/utils.d.ts +2 -1
- package/dist/conditionals/index.js +48 -1
- package/dist/events/index.js +135 -48
- package/dist/notification/index.js +112 -35
- package/package.json +7 -7
|
@@ -1488,11 +1488,23 @@ 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
|
|
1491
|
+
$$field: FieldId.describe(
|
|
1492
|
+
"Field whose value is passed as the first argument to the computation"
|
|
1493
|
+
),
|
|
1492
1494
|
$$subfield: import_zod17.z.array(import_zod17.z.string()).optional().default([]).describe(
|
|
1493
1495
|
'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."
|
|
1494
1506
|
)
|
|
1495
|
-
}).describe("
|
|
1507
|
+
}).describe("A context-only computation used as a field default value.");
|
|
1496
1508
|
var ValidationConfig = import_zod17.z.object({
|
|
1497
1509
|
validator: Conditional,
|
|
1498
1510
|
message: TranslationConfig
|
|
@@ -1526,7 +1538,7 @@ var BaseField = import_zod17.z.object({
|
|
|
1526
1538
|
"Indicates whether the field can be modified during record correction."
|
|
1527
1539
|
),
|
|
1528
1540
|
value: FieldReference.or(import_zod17.z.array(FieldReference)).optional().describe(
|
|
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."
|
|
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."
|
|
1530
1542
|
),
|
|
1531
1543
|
analytics: import_zod17.z.boolean().default(false).optional().describe(
|
|
1532
1544
|
"Indicates whether the field is included in analytics. When enabled, its value becomes available in the analytics dashboard."
|
|
@@ -1537,7 +1549,7 @@ var Divider = BaseField.extend({
|
|
|
1537
1549
|
});
|
|
1538
1550
|
var TextField = BaseField.extend({
|
|
1539
1551
|
type: import_zod17.z.literal(FieldType.TEXT),
|
|
1540
|
-
defaultValue: import_zod17.z.union([NonEmptyTextValue, SerializedUserField]).optional(),
|
|
1552
|
+
defaultValue: import_zod17.z.union([NonEmptyTextValue, SerializedUserField, ComputedDefaultValue]).optional(),
|
|
1541
1553
|
configuration: import_zod17.z.object({
|
|
1542
1554
|
maxLength: import_zod17.z.number().optional().describe("Maximum length of the text"),
|
|
1543
1555
|
type: import_zod17.z.enum(["text", "password"]).optional(),
|
|
@@ -1547,7 +1559,7 @@ var TextField = BaseField.extend({
|
|
|
1547
1559
|
}).describe("Text input");
|
|
1548
1560
|
var NumberField = BaseField.extend({
|
|
1549
1561
|
type: import_zod17.z.literal(FieldType.NUMBER),
|
|
1550
|
-
defaultValue: NumberFieldValue.optional(),
|
|
1562
|
+
defaultValue: NumberFieldValue.or(ComputedDefaultValue).optional(),
|
|
1551
1563
|
configuration: import_zod17.z.object({
|
|
1552
1564
|
min: import_zod17.z.number().optional().describe("Minimum value"),
|
|
1553
1565
|
max: import_zod17.z.number().optional().describe("Maximum value"),
|
|
@@ -1557,7 +1569,7 @@ var NumberField = BaseField.extend({
|
|
|
1557
1569
|
}).describe("Number input");
|
|
1558
1570
|
var TextAreaField = BaseField.extend({
|
|
1559
1571
|
type: import_zod17.z.literal(FieldType.TEXTAREA),
|
|
1560
|
-
defaultValue: NonEmptyTextValue.optional(),
|
|
1572
|
+
defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional(),
|
|
1561
1573
|
configuration: import_zod17.z.object({
|
|
1562
1574
|
maxLength: import_zod17.z.number().optional().describe("Maximum length of the text"),
|
|
1563
1575
|
rows: import_zod17.z.number().optional().describe("Number of visible text lines"),
|
|
@@ -1588,7 +1600,7 @@ var SignatureField = BaseField.extend({
|
|
|
1588
1600
|
signaturePromptLabel: TranslationConfig.describe(
|
|
1589
1601
|
"Title of the signature modal"
|
|
1590
1602
|
),
|
|
1591
|
-
defaultValue: SignatureFieldValue.optional(),
|
|
1603
|
+
defaultValue: SignatureFieldValue.or(ComputedDefaultValue).optional(),
|
|
1592
1604
|
configuration: import_zod17.z.object({
|
|
1593
1605
|
maxFileSize: import_zod17.z.number().describe("Maximum file size in bytes").default(DEFAULT_MAX_FILE_SIZE_BYTES),
|
|
1594
1606
|
acceptedFileTypes: MimeType.array().optional().describe("List of allowed file formats for the signature")
|
|
@@ -1601,11 +1613,11 @@ var EmailField = BaseField.extend({
|
|
|
1601
1613
|
configuration: import_zod17.z.object({
|
|
1602
1614
|
maxLength: import_zod17.z.number().optional().describe("Maximum length of the text")
|
|
1603
1615
|
}).default({ maxLength: 10 }).optional(),
|
|
1604
|
-
defaultValue: NonEmptyTextValue.optional()
|
|
1616
|
+
defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional()
|
|
1605
1617
|
});
|
|
1606
1618
|
var DateField = BaseField.extend({
|
|
1607
1619
|
type: import_zod17.z.literal(FieldType.DATE),
|
|
1608
|
-
defaultValue: SerializedNowDateTime.or(PlainDate).optional().openapi({ effectType: "input", type: "string" }).describe("Default date value(yyyy-MM-dd)"),
|
|
1620
|
+
defaultValue: SerializedNowDateTime.or(PlainDate).or(ComputedDefaultValue).optional().openapi({ effectType: "input", type: "string" }).describe("Default date value(yyyy-MM-dd)"),
|
|
1609
1621
|
configuration: import_zod17.z.object({
|
|
1610
1622
|
notice: TranslationConfig.describe(
|
|
1611
1623
|
"Text to display above the date input"
|
|
@@ -1614,7 +1626,7 @@ var DateField = BaseField.extend({
|
|
|
1614
1626
|
}).describe("A single date input (yyyy-MM-dd)");
|
|
1615
1627
|
var AgeField = BaseField.extend({
|
|
1616
1628
|
type: import_zod17.z.literal(FieldType.AGE),
|
|
1617
|
-
defaultValue: NumberFieldValue.optional(),
|
|
1629
|
+
defaultValue: NumberFieldValue.or(ComputedDefaultValue).optional(),
|
|
1618
1630
|
configuration: import_zod17.z.object({
|
|
1619
1631
|
asOfDate: FieldReference,
|
|
1620
1632
|
prefix: TranslationConfig.optional(),
|
|
@@ -1623,7 +1635,7 @@ var AgeField = BaseField.extend({
|
|
|
1623
1635
|
}).describe("An age input field which uses the current date as the asOfDate");
|
|
1624
1636
|
var TimeField = BaseField.extend({
|
|
1625
1637
|
type: import_zod17.z.literal(FieldType.TIME),
|
|
1626
|
-
defaultValue: SerializedNowDateTime.or(TimeValue).optional().openapi({ effectType: "input", type: "object" }).describe("Default time value (HH-mm)"),
|
|
1638
|
+
defaultValue: SerializedNowDateTime.or(TimeValue).or(ComputedDefaultValue).optional().openapi({ effectType: "input", type: "object" }).describe("Default time value (HH-mm)"),
|
|
1627
1639
|
configuration: import_zod17.z.object({
|
|
1628
1640
|
use12HourFormat: import_zod17.z.boolean().optional().describe("Whether to use 12-hour format"),
|
|
1629
1641
|
notice: TranslationConfig.describe(
|
|
@@ -1633,7 +1645,7 @@ var TimeField = BaseField.extend({
|
|
|
1633
1645
|
}).describe("A single date input (HH-mm)");
|
|
1634
1646
|
var DateRangeField = BaseField.extend({
|
|
1635
1647
|
type: import_zod17.z.literal(FieldType.DATE_RANGE),
|
|
1636
|
-
defaultValue: DateRangeFieldValue.optional(),
|
|
1648
|
+
defaultValue: DateRangeFieldValue.or(ComputedDefaultValue).optional(),
|
|
1637
1649
|
configuration: import_zod17.z.object({
|
|
1638
1650
|
notice: TranslationConfig.describe(
|
|
1639
1651
|
"Text to display above the date input"
|
|
@@ -1667,7 +1679,7 @@ var PageHeader = BaseField.extend({
|
|
|
1667
1679
|
}).describe("A read-only header component for form pages");
|
|
1668
1680
|
var File = BaseField.extend({
|
|
1669
1681
|
type: import_zod17.z.literal(FieldType.FILE),
|
|
1670
|
-
defaultValue: FileFieldValue.optional(),
|
|
1682
|
+
defaultValue: FileFieldValue.or(ComputedDefaultValue).optional(),
|
|
1671
1683
|
configuration: import_zod17.z.object({
|
|
1672
1684
|
maxFileSize: import_zod17.z.number().describe("Maximum file size in bytes").default(DEFAULT_MAX_FILE_SIZE_BYTES),
|
|
1673
1685
|
acceptedFileTypes: MimeType.array().optional().describe("List of allowed file formats for the signature"),
|
|
@@ -1691,7 +1703,7 @@ var SelectOption = import_zod17.z.object({
|
|
|
1691
1703
|
});
|
|
1692
1704
|
var NumberWithUnitField = BaseField.extend({
|
|
1693
1705
|
type: import_zod17.z.literal(FieldType.NUMBER_WITH_UNIT),
|
|
1694
|
-
defaultValue: NumberWithUnitFieldValue.optional(),
|
|
1706
|
+
defaultValue: NumberWithUnitFieldValue.or(ComputedDefaultValue).optional(),
|
|
1695
1707
|
options: import_zod17.z.array(SelectOption).describe("A list of options for the unit select"),
|
|
1696
1708
|
configuration: import_zod17.z.object({
|
|
1697
1709
|
min: import_zod17.z.number().optional().describe("Minimum value of the number field"),
|
|
@@ -1703,7 +1715,7 @@ var NumberWithUnitField = BaseField.extend({
|
|
|
1703
1715
|
}).describe("Number with unit input");
|
|
1704
1716
|
var RadioGroup = BaseField.extend({
|
|
1705
1717
|
type: import_zod17.z.literal(FieldType.RADIO_GROUP),
|
|
1706
|
-
defaultValue: TextValue.optional(),
|
|
1718
|
+
defaultValue: TextValue.or(ComputedDefaultValue).optional(),
|
|
1707
1719
|
options: import_zod17.z.array(SelectOption).describe("A list of options"),
|
|
1708
1720
|
configuration: import_zod17.z.object({
|
|
1709
1721
|
styles: import_zod17.z.object({
|
|
@@ -1722,7 +1734,7 @@ var BulletList = BaseField.extend({
|
|
|
1722
1734
|
}).describe("A list of bullet points");
|
|
1723
1735
|
var Select = BaseField.extend({
|
|
1724
1736
|
type: import_zod17.z.literal(FieldType.SELECT),
|
|
1725
|
-
defaultValue: TextValue.optional(),
|
|
1737
|
+
defaultValue: TextValue.or(ComputedDefaultValue).optional(),
|
|
1726
1738
|
options: import_zod17.z.array(SelectOption).describe("A list of options"),
|
|
1727
1739
|
noOptionsMessage: TranslationConfig.optional().describe(
|
|
1728
1740
|
`
|
|
@@ -1741,7 +1753,7 @@ var SelectDateRangeOption = import_zod17.z.object({
|
|
|
1741
1753
|
});
|
|
1742
1754
|
var SelectDateRangeField = BaseField.extend({
|
|
1743
1755
|
type: import_zod17.z.literal(FieldType.SELECT_DATE_RANGE),
|
|
1744
|
-
defaultValue: SelectDateRangeValue.optional(),
|
|
1756
|
+
defaultValue: SelectDateRangeValue.or(ComputedDefaultValue).optional(),
|
|
1745
1757
|
options: import_zod17.z.array(SelectDateRangeOption).describe("A list of options")
|
|
1746
1758
|
}).describe("Select input with date range options");
|
|
1747
1759
|
var NameConfig = import_zod17.z.object({
|
|
@@ -1755,7 +1767,7 @@ var NameField = BaseField.extend({
|
|
|
1755
1767
|
firstname: SerializedUserField.or(NonEmptyTextValue).optional(),
|
|
1756
1768
|
middlename: SerializedUserField.or(NonEmptyTextValue).optional(),
|
|
1757
1769
|
surname: SerializedUserField.or(NonEmptyTextValue).optional()
|
|
1758
|
-
}).optional(),
|
|
1770
|
+
}).or(ComputedDefaultValue).optional(),
|
|
1759
1771
|
configuration: import_zod17.z.object({
|
|
1760
1772
|
name: NameConfig.default({
|
|
1761
1773
|
firstname: { required: true },
|
|
@@ -1776,20 +1788,20 @@ var NameField = BaseField.extend({
|
|
|
1776
1788
|
}).optional()
|
|
1777
1789
|
}).describe("Name input field");
|
|
1778
1790
|
var PhoneField = BaseField.extend({
|
|
1779
|
-
defaultValue: NonEmptyTextValue.optional(),
|
|
1791
|
+
defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional(),
|
|
1780
1792
|
type: import_zod17.z.literal(FieldType.PHONE)
|
|
1781
1793
|
}).describe("Phone input field");
|
|
1782
1794
|
var IdField = BaseField.extend({
|
|
1783
|
-
defaultValue: NonEmptyTextValue.optional(),
|
|
1795
|
+
defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional(),
|
|
1784
1796
|
type: import_zod17.z.literal(FieldType.ID)
|
|
1785
1797
|
}).describe("ID input field");
|
|
1786
1798
|
var Checkbox = BaseField.extend({
|
|
1787
1799
|
type: import_zod17.z.literal(FieldType.CHECKBOX),
|
|
1788
|
-
defaultValue: CheckboxFieldValue.default(false)
|
|
1800
|
+
defaultValue: CheckboxFieldValue.or(ComputedDefaultValue).default(false)
|
|
1789
1801
|
}).describe("Boolean checkbox field");
|
|
1790
1802
|
var Country = BaseField.extend({
|
|
1791
1803
|
type: import_zod17.z.literal(FieldType.COUNTRY),
|
|
1792
|
-
defaultValue: NonEmptyTextValue.optional(),
|
|
1804
|
+
defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional(),
|
|
1793
1805
|
optionOverrides: import_zod17.z.array(SelectOption.omit({ label: true })).optional().describe(
|
|
1794
1806
|
"Conditionals for specific countries. Countries not listed are always shown and enabled."
|
|
1795
1807
|
)
|
|
@@ -1805,12 +1817,12 @@ var AdministrativeAreaConfiguration = import_zod17.z.object({
|
|
|
1805
1817
|
}).describe("Administrative area options");
|
|
1806
1818
|
var AdministrativeArea = BaseField.extend({
|
|
1807
1819
|
type: import_zod17.z.literal(FieldType.ADMINISTRATIVE_AREA),
|
|
1808
|
-
defaultValue: import_zod17.z.union([NonEmptyTextValue, SerializedUserField]).optional(),
|
|
1820
|
+
defaultValue: import_zod17.z.union([NonEmptyTextValue, SerializedUserField, ComputedDefaultValue]).optional(),
|
|
1809
1821
|
configuration: AdministrativeAreaConfiguration
|
|
1810
1822
|
}).describe("Administrative area input field e.g. facility, office");
|
|
1811
1823
|
var LocationInput = BaseField.extend({
|
|
1812
1824
|
type: import_zod17.z.literal(FieldType.LOCATION),
|
|
1813
|
-
defaultValue: NonEmptyTextValue.optional(),
|
|
1825
|
+
defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional(),
|
|
1814
1826
|
configuration: import_zod17.z.object({
|
|
1815
1827
|
searchableResource: import_zod17.z.array(import_zod17.z.enum(["locations", "facilities", "offices"]))
|
|
1816
1828
|
})
|
|
@@ -1818,7 +1830,7 @@ var LocationInput = BaseField.extend({
|
|
|
1818
1830
|
var FileUploadWithOptions = BaseField.extend({
|
|
1819
1831
|
type: import_zod17.z.literal(FieldType.FILE_WITH_OPTIONS),
|
|
1820
1832
|
options: import_zod17.z.array(SelectOption).describe("A list of options"),
|
|
1821
|
-
defaultValue: FileFieldWithOptionValue.optional(),
|
|
1833
|
+
defaultValue: FileFieldWithOptionValue.or(ComputedDefaultValue).optional(),
|
|
1822
1834
|
configuration: import_zod17.z.object({
|
|
1823
1835
|
maxFileSize: import_zod17.z.number().describe("Maximum file size in bytes").default(DEFAULT_MAX_FILE_SIZE_BYTES),
|
|
1824
1836
|
maxImageSize: import_zod17.z.object({
|
|
@@ -1831,11 +1843,11 @@ var FileUploadWithOptions = BaseField.extend({
|
|
|
1831
1843
|
});
|
|
1832
1844
|
var Facility = BaseField.extend({
|
|
1833
1845
|
type: import_zod17.z.literal(FieldType.FACILITY),
|
|
1834
|
-
defaultValue: NonEmptyTextValue.optional()
|
|
1846
|
+
defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional()
|
|
1835
1847
|
}).describe("Input field for a facility");
|
|
1836
1848
|
var Office = BaseField.extend({
|
|
1837
1849
|
type: import_zod17.z.literal(FieldType.OFFICE),
|
|
1838
|
-
defaultValue: NonEmptyTextValue.optional()
|
|
1850
|
+
defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional()
|
|
1839
1851
|
}).describe("Input field for an office");
|
|
1840
1852
|
var DefaultAddressFieldValue = DomesticAddressFieldValue.extend({
|
|
1841
1853
|
administrativeArea: import_zod17.z.union([UUID, SerializedUserField]).optional()
|
|
@@ -1869,7 +1881,7 @@ var Address = BaseField.extend({
|
|
|
1869
1881
|
})
|
|
1870
1882
|
).optional()
|
|
1871
1883
|
}).optional(),
|
|
1872
|
-
defaultValue: DefaultAddressFieldValue.optional()
|
|
1884
|
+
defaultValue: DefaultAddressFieldValue.or(ComputedDefaultValue).optional()
|
|
1873
1885
|
}).describe("Address input field \u2013 a combination of location and text fields");
|
|
1874
1886
|
var StaticDataEntry = import_zod17.z.object({
|
|
1875
1887
|
id: import_zod17.z.string().describe("ID for the data entry."),
|
|
@@ -1888,7 +1900,7 @@ var DataField = BaseField.extend({
|
|
|
1888
1900
|
}).describe("Data field for displaying read-only data");
|
|
1889
1901
|
var ButtonField = BaseField.extend({
|
|
1890
1902
|
type: import_zod17.z.literal(FieldType.BUTTON),
|
|
1891
|
-
defaultValue: ButtonFieldValue.optional(),
|
|
1903
|
+
defaultValue: ButtonFieldValue.or(ComputedDefaultValue).optional(),
|
|
1892
1904
|
configuration: import_zod17.z.object({
|
|
1893
1905
|
icon: import_zod17.z.string().optional().describe(
|
|
1894
1906
|
"Icon for the button. You can find icons from OpenCRVS UI-Kit."
|
|
@@ -1913,7 +1925,7 @@ var AlphaPrintButton = BaseField.extend({
|
|
|
1913
1925
|
}).describe("Print button field for printing certificates");
|
|
1914
1926
|
var HttpField = BaseField.extend({
|
|
1915
1927
|
type: import_zod17.z.literal(FieldType.HTTP),
|
|
1916
|
-
defaultValue: HttpFieldValue.optional(),
|
|
1928
|
+
defaultValue: HttpFieldValue.or(ComputedDefaultValue).optional(),
|
|
1917
1929
|
configuration: import_zod17.z.object({
|
|
1918
1930
|
trigger: FieldReference,
|
|
1919
1931
|
url: import_zod17.z.string().describe("URL to send the HTTP request to"),
|
|
@@ -1968,7 +1980,7 @@ var LinkButtonField = BaseField.extend({
|
|
|
1968
1980
|
}).describe("Button that opens a link");
|
|
1969
1981
|
var VerificationStatus = BaseField.extend({
|
|
1970
1982
|
type: import_zod17.z.literal(FieldType.VERIFICATION_STATUS),
|
|
1971
|
-
defaultValue: VerificationStatusValue.optional(),
|
|
1983
|
+
defaultValue: VerificationStatusValue.or(ComputedDefaultValue).optional(),
|
|
1972
1984
|
configuration: import_zod17.z.object({
|
|
1973
1985
|
status: TranslationConfig.describe("Text to display on the status pill."),
|
|
1974
1986
|
description: TranslationConfig.describe(
|
|
@@ -1986,7 +1998,7 @@ var QueryParamReaderField = BaseField.extend({
|
|
|
1986
1998
|
);
|
|
1987
1999
|
var QrReaderField = BaseField.extend({
|
|
1988
2000
|
type: import_zod17.z.literal(FieldType.QR_READER),
|
|
1989
|
-
defaultValue: QrReaderFieldValue.optional(),
|
|
2001
|
+
defaultValue: QrReaderFieldValue.or(ComputedDefaultValue).optional(),
|
|
1990
2002
|
configuration: import_zod17.z.object({
|
|
1991
2003
|
validator: import_zod17.z.custom(
|
|
1992
2004
|
(val) => typeof val === "object" && val !== null
|
|
@@ -1995,7 +2007,7 @@ var QrReaderField = BaseField.extend({
|
|
|
1995
2007
|
});
|
|
1996
2008
|
var IdReaderField = BaseField.extend({
|
|
1997
2009
|
type: import_zod17.z.literal(FieldType.ID_READER),
|
|
1998
|
-
defaultValue: IdReaderFieldValue.optional(),
|
|
2010
|
+
defaultValue: IdReaderFieldValue.or(ComputedDefaultValue).optional(),
|
|
1999
2011
|
methods: import_zod17.z.array(
|
|
2000
2012
|
import_zod17.z.union([QrReaderField, LinkButtonField]).describe("Methods for reading an ID")
|
|
2001
2013
|
)
|
|
@@ -2556,6 +2568,15 @@ function resolveDataPath(rootData, dataPath, instancePath) {
|
|
|
2556
2568
|
}
|
|
2557
2569
|
return current;
|
|
2558
2570
|
}
|
|
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
|
+
}
|
|
2559
2580
|
(0, import_ajv_formats.default)(ajv);
|
|
2560
2581
|
ajv.addKeyword({
|
|
2561
2582
|
keyword: "daysFromDate",
|
|
@@ -2601,12 +2622,21 @@ ajv.addKeyword({
|
|
|
2601
2622
|
$data: true,
|
|
2602
2623
|
errors: true,
|
|
2603
2624
|
// @ts-ignore -- Force type. We will move this away from AJV next. Parsing the array will take seconds and is only called by core.
|
|
2604
|
-
validate(
|
|
2625
|
+
validate(_schema, data, _2, dataContext) {
|
|
2605
2626
|
const locationIdInput = data;
|
|
2606
2627
|
const locations = dataContext?.rootData.$leafAdminStructureLocationIds ?? [];
|
|
2607
2628
|
return locations.some((location) => location.id === locationIdInput);
|
|
2608
2629
|
}
|
|
2609
2630
|
});
|
|
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
|
+
});
|
|
2610
2640
|
|
|
2611
2641
|
// ../commons/src/utils.ts
|
|
2612
2642
|
var z29 = __toESM(require("zod"));
|
|
@@ -3229,7 +3259,54 @@ function createFieldConditionals(fieldId) {
|
|
|
3229
3259
|
}
|
|
3230
3260
|
},
|
|
3231
3261
|
required: [fieldId]
|
|
3232
|
-
})
|
|
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
|
+
}
|
|
3233
3310
|
};
|
|
3234
3311
|
}
|
|
3235
3312
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opencrvs/toolkit",
|
|
3
|
-
"version": "1.9.13-rc.
|
|
3
|
+
"version": "1.9.13-rc.2299d16",
|
|
4
4
|
"description": "OpenCRVS toolkit for building country configurations",
|
|
5
5
|
"license": "MPL-2.0",
|
|
6
6
|
"exports": {
|
|
@@ -17,21 +17,21 @@
|
|
|
17
17
|
"build:all": "lerna run build --include-dependencies --scope @opencrvs/toolkit && ./build.sh"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"
|
|
20
|
+
"@trpc/client": "11.4.3",
|
|
21
|
+
"@trpc/server": "11.4.3",
|
|
21
22
|
"ajv": "^8.17.1",
|
|
22
23
|
"ajv-formats": "^3.0.1",
|
|
23
24
|
"object-hash": "^3.0.0",
|
|
24
25
|
"superjson": "1.9.0-0",
|
|
25
|
-
"
|
|
26
|
-
"@trpc/server": "11.4.3",
|
|
26
|
+
"uuid": "^9.0.0",
|
|
27
27
|
"zod-openapi": "^4.2.4"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
+
"@opencrvs/events": "^1.9.0",
|
|
31
|
+
"@types/object-hash": "^3.0.6",
|
|
30
32
|
"@types/uuid": "^9.0.3",
|
|
31
33
|
"esbuild": "^0.24.0",
|
|
32
|
-
"typescript": "^5.6.3"
|
|
33
|
-
"@opencrvs/events": "^1.9.0",
|
|
34
|
-
"@types/object-hash": "^3.0.6"
|
|
34
|
+
"typescript": "^5.6.3"
|
|
35
35
|
},
|
|
36
36
|
"moduleNameMapper": {
|
|
37
37
|
"@opencrvs/commons/events": "@opencrvs/commons/build/dist/common/events/index.js",
|