@opencrvs/toolkit 2.0.0-rc.ee1414e → 2.0.0-rc.ee6f4f7

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.
@@ -2394,14 +2394,20 @@ var encodeScope = (scope) => {
2394
2394
  encode: false
2395
2395
  });
2396
2396
  };
2397
- var decodeScope = (query) => {
2398
- const scope = qs.parse(query, {
2397
+ var decodedScopeCache = /* @__PURE__ */ new Map();
2398
+ var decodeScope = (encodedScope) => {
2399
+ if (decodedScopeCache.has(encodedScope)) {
2400
+ return decodedScopeCache.get(encodedScope);
2401
+ }
2402
+ const scope = qs.parse(encodedScope, {
2399
2403
  ignoreQueryPrefix: true,
2400
2404
  comma: true,
2401
2405
  allowDots: true
2402
2406
  });
2403
2407
  const unflattenedScope = unflattenScope(scope);
2404
- return Scope2.safeParse(unflattenedScope)?.data;
2408
+ const result = Scope2.safeParse(unflattenedScope)?.data;
2409
+ decodedScopeCache.set(encodedScope, result);
2410
+ return result;
2405
2411
  };
2406
2412
  var DEFAULT_SCOPE_OPTIONS = {
2407
2413
  placeOfEvent: JurisdictionFilter.enum.all,
@@ -770,6 +770,11 @@ var FieldTypesToHideInReview = [
770
770
  FieldType.ALPHA_PRINT_BUTTON,
771
771
  FieldType.ALPHA_HIDDEN
772
772
  ];
773
+ var HiddenFieldTypes = [
774
+ FieldType.HTTP,
775
+ FieldType.QUERY_PARAM_READER,
776
+ FieldType.ALPHA_HIDDEN
777
+ ];
773
778
 
774
779
  // ../commons/src/events/FieldValue.ts
775
780
  var z12 = __toESM(require("zod/v4"));
@@ -888,7 +893,7 @@ var PlainDate = import_zod.z.string().date().brand("PlainDate").describe("Date i
888
893
  // ../commons/src/events/FieldValue.ts
889
894
  var TextValue = z12.string();
890
895
  var HiddenFieldValue = z12.string();
891
- var NonEmptyTextValue = TextValue.min(1);
896
+ var NonEmptyTextValue = z12.string().trim().min(1);
892
897
  var DateValue = z12.iso.date().describe("Date in the format YYYY-MM-DD");
893
898
  var AgeValue = z12.object({
894
899
  age: z12.number(),
@@ -917,6 +922,7 @@ var DateRangeFieldValue = z12.object({
917
922
  var EmailValue = z12.email();
918
923
  var CheckboxFieldValue = z12.boolean();
919
924
  var NumberFieldValue = z12.number();
925
+ var SignatureFieldValue = FileFieldValue;
920
926
  var ButtonFieldValue = z12.number();
921
927
  var VerificationStatusValue = z12.enum([
922
928
  "verified",
@@ -1666,8 +1672,18 @@ var FieldReference = import_v43.default.object({
1666
1672
  $$field: FieldId.describe("Id of the field to reference"),
1667
1673
  $$subfield: import_v43.default.array(import_v43.default.string()).optional().default([]).describe(
1668
1674
  'If the FieldValue is an object, subfield can be used to refer to e.g. `["foo", "bar"]` in `{ foo: { bar: 3 } }`'
1675
+ ),
1676
+ $$code: import_v43.default.string().optional().describe(
1677
+ "Serialised client-side function body. When present the expression is evaluated rather than dereferenced."
1678
+ )
1679
+ }).describe(
1680
+ "Reference to a field value, with an optional client-side computation applied."
1681
+ );
1682
+ var ComputedDefaultValue = import_v43.default.object({
1683
+ $$code: import_v43.default.string().describe(
1684
+ "Serialised client-side function body. Receives (undefined, context) where context includes $now, $online, and system variables."
1669
1685
  )
1670
- }).describe("Reference to a field by its ID");
1686
+ }).describe("A context-only computation used as a field default value.");
1671
1687
  var ValidationConfig = import_v43.default.object({
1672
1688
  validator: Conditional.describe(
1673
1689
  "Conditional expression that must hold for the field value to be considered valid."
@@ -1708,7 +1724,7 @@ var BaseField = import_v43.default.object({
1708
1724
  "Indicates whether the field can be modified during record correction."
1709
1725
  ),
1710
1726
  value: FieldReference.or(import_v43.default.array(FieldReference)).optional().describe(
1711
- "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."
1727
+ "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."
1712
1728
  ),
1713
1729
  analytics: import_v43.default.boolean().default(false).optional().describe(
1714
1730
  "Indicates whether the field is included in analytics. When enabled, its value becomes available in the analytics dashboard."
@@ -1722,7 +1738,7 @@ var Divider = BaseField.extend({
1722
1738
  });
1723
1739
  var TextField = BaseField.extend({
1724
1740
  type: import_v43.default.literal(FieldType.TEXT),
1725
- defaultValue: import_v43.default.union([NonEmptyTextValue, SerializedUserField]).optional(),
1741
+ defaultValue: import_v43.default.union([NonEmptyTextValue, SerializedUserField, ComputedDefaultValue]).optional(),
1726
1742
  configuration: import_v43.default.object({
1727
1743
  maxLength: import_v43.default.number().optional().describe("Maximum length of the text"),
1728
1744
  type: import_v43.default.enum(["text", "password"]).optional(),
@@ -1735,7 +1751,7 @@ var TextField = BaseField.extend({
1735
1751
  });
1736
1752
  var NumberField = BaseField.extend({
1737
1753
  type: import_v43.default.literal(FieldType.NUMBER),
1738
- defaultValue: NumberFieldValue.optional(),
1754
+ defaultValue: NumberFieldValue.or(ComputedDefaultValue).optional(),
1739
1755
  configuration: import_v43.default.object({
1740
1756
  min: import_v43.default.number().optional().describe("Minimum value"),
1741
1757
  max: import_v43.default.number().optional().describe("Maximum value"),
@@ -1748,7 +1764,7 @@ var NumberField = BaseField.extend({
1748
1764
  });
1749
1765
  var TextAreaField = BaseField.extend({
1750
1766
  type: import_v43.default.literal(FieldType.TEXTAREA),
1751
- defaultValue: NonEmptyTextValue.optional(),
1767
+ defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional(),
1752
1768
  configuration: import_v43.default.object({
1753
1769
  maxLength: import_v43.default.number().optional().describe("Maximum length of the text"),
1754
1770
  rows: import_v43.default.number().optional().describe("Number of visible text lines"),
@@ -1782,7 +1798,7 @@ var SignatureField = BaseField.extend({
1782
1798
  signaturePromptLabel: TranslationConfig.describe(
1783
1799
  "Title of the signature modal"
1784
1800
  ),
1785
- defaultValue: FieldValue.optional(),
1801
+ defaultValue: SignatureFieldValue.or(ComputedDefaultValue).optional(),
1786
1802
  configuration: import_v43.default.object({
1787
1803
  maxFileSize: import_v43.default.number().describe("Maximum file size in bytes").default(DEFAULT_MAX_FILE_SIZE_BYTES),
1788
1804
  acceptedFileTypes: MimeType.array().optional().describe("List of allowed file formats for the signature")
@@ -1798,14 +1814,14 @@ var EmailField = BaseField.extend({
1798
1814
  configuration: import_v43.default.object({
1799
1815
  maxLength: import_v43.default.number().optional().describe("Maximum length of the text")
1800
1816
  }).default({ maxLength: 255 }).optional(),
1801
- defaultValue: NonEmptyTextValue.optional()
1817
+ defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional()
1802
1818
  }).meta({
1803
1819
  description: "An email input field",
1804
1820
  id: "EmailField"
1805
1821
  });
1806
1822
  var DateField = BaseField.extend({
1807
1823
  type: import_v43.default.literal(FieldType.DATE),
1808
- defaultValue: SerializedNowDateTime.or(PlainDate).optional().describe("Default date value(yyyy-MM-dd)"),
1824
+ defaultValue: SerializedNowDateTime.or(PlainDate).or(ComputedDefaultValue).optional().describe("Default date value(yyyy-MM-dd)"),
1809
1825
  configuration: import_v43.default.object({
1810
1826
  notice: TranslationConfig.describe(
1811
1827
  "Text to display above the date input"
@@ -1817,7 +1833,7 @@ var DateField = BaseField.extend({
1817
1833
  });
1818
1834
  var AgeField = BaseField.extend({
1819
1835
  type: import_v43.default.literal(FieldType.AGE),
1820
- defaultValue: NumberFieldValue.optional(),
1836
+ defaultValue: NumberFieldValue.or(ComputedDefaultValue).optional(),
1821
1837
  configuration: import_v43.default.object({
1822
1838
  asOfDate: FieldReference,
1823
1839
  prefix: TranslationConfig.optional(),
@@ -1829,7 +1845,7 @@ var AgeField = BaseField.extend({
1829
1845
  });
1830
1846
  var TimeField = BaseField.extend({
1831
1847
  type: import_v43.default.literal(FieldType.TIME),
1832
- defaultValue: SerializedNowDateTime.or(TimeValue).optional().describe("Default time value (HH-mm)"),
1848
+ defaultValue: SerializedNowDateTime.or(TimeValue).or(ComputedDefaultValue).optional().describe("Default time value (HH-mm)"),
1833
1849
  configuration: import_v43.default.object({
1834
1850
  use12HourFormat: import_v43.default.boolean().optional().describe("Whether to use 12-hour format"),
1835
1851
  notice: TranslationConfig.describe(
@@ -1842,7 +1858,7 @@ var TimeField = BaseField.extend({
1842
1858
  });
1843
1859
  var DateRangeField = BaseField.extend({
1844
1860
  type: import_v43.default.literal(FieldType.DATE_RANGE),
1845
- defaultValue: DateRangeFieldValue.optional(),
1861
+ defaultValue: DateRangeFieldValue.or(ComputedDefaultValue).optional(),
1846
1862
  configuration: import_v43.default.object({
1847
1863
  notice: TranslationConfig.describe(
1848
1864
  "Text to display above the date input"
@@ -1921,7 +1937,7 @@ var PageHeader = BaseField.extend({
1921
1937
  });
1922
1938
  var File = BaseField.extend({
1923
1939
  type: import_v43.default.literal(FieldType.FILE),
1924
- defaultValue: FileFieldValue.optional(),
1940
+ defaultValue: FileFieldValue.or(ComputedDefaultValue).optional(),
1925
1941
  configuration: import_v43.default.object({
1926
1942
  maxFileSize: import_v43.default.number().describe("Maximum file size in bytes").default(DEFAULT_MAX_FILE_SIZE_BYTES),
1927
1943
  acceptedFileTypes: MimeType.array().optional().describe("List of allowed file formats for the signature"),
@@ -1948,7 +1964,7 @@ var SelectOption = import_v43.default.object({
1948
1964
  });
1949
1965
  var NumberWithUnitField = BaseField.extend({
1950
1966
  type: import_v43.default.literal(FieldType.NUMBER_WITH_UNIT),
1951
- defaultValue: NumberWithUnitFieldValue.optional(),
1967
+ defaultValue: NumberWithUnitFieldValue.or(ComputedDefaultValue).optional(),
1952
1968
  options: import_v43.default.array(SelectOption).describe("A list of options for the unit select"),
1953
1969
  configuration: import_v43.default.object({
1954
1970
  min: import_v43.default.number().optional().describe("Minimum value of the number field"),
@@ -1963,7 +1979,7 @@ var NumberWithUnitField = BaseField.extend({
1963
1979
  });
1964
1980
  var RadioGroup = BaseField.extend({
1965
1981
  type: import_v43.default.literal(FieldType.RADIO_GROUP),
1966
- defaultValue: TextValue.optional(),
1982
+ defaultValue: TextValue.or(ComputedDefaultValue).optional(),
1967
1983
  options: import_v43.default.array(SelectOption).describe("A list of options"),
1968
1984
  configuration: import_v43.default.object({
1969
1985
  styles: import_v43.default.object({
@@ -1988,7 +2004,7 @@ var BulletList = BaseField.extend({
1988
2004
  });
1989
2005
  var Select = BaseField.extend({
1990
2006
  type: import_v43.default.literal(FieldType.SELECT),
1991
- defaultValue: TextValue.optional(),
2007
+ defaultValue: TextValue.or(ComputedDefaultValue).optional(),
1992
2008
  options: import_v43.default.array(SelectOption).describe("A list of options"),
1993
2009
  noOptionsMessage: TranslationConfig.optional().describe(
1994
2010
  `
@@ -2010,7 +2026,7 @@ var SelectDateRangeOption = import_v43.default.object({
2010
2026
  });
2011
2027
  var SelectDateRangeField = BaseField.extend({
2012
2028
  type: import_v43.default.literal(FieldType.SELECT_DATE_RANGE),
2013
- defaultValue: SelectDateRangeValue.optional(),
2029
+ defaultValue: SelectDateRangeValue.or(ComputedDefaultValue).optional(),
2014
2030
  options: import_v43.default.array(SelectDateRangeOption).describe("A list of options")
2015
2031
  }).meta({
2016
2032
  description: "A date range selection field",
@@ -2027,7 +2043,7 @@ var NameField = BaseField.extend({
2027
2043
  firstname: SerializedUserField.or(NonEmptyTextValue).optional(),
2028
2044
  middlename: SerializedUserField.or(NonEmptyTextValue).optional(),
2029
2045
  surname: SerializedUserField.or(NonEmptyTextValue).optional()
2030
- }).optional(),
2046
+ }).or(ComputedDefaultValue).optional(),
2031
2047
  configuration: import_v43.default.object({
2032
2048
  name: NameConfig.default({
2033
2049
  firstname: { required: true },
@@ -2051,14 +2067,14 @@ var NameField = BaseField.extend({
2051
2067
  id: "NameField"
2052
2068
  });
2053
2069
  var PhoneField = BaseField.extend({
2054
- defaultValue: NonEmptyTextValue.optional(),
2070
+ defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional(),
2055
2071
  type: import_v43.default.literal(FieldType.PHONE)
2056
2072
  }).meta({
2057
2073
  description: "A field for entering a phone number",
2058
2074
  id: "PhoneField"
2059
2075
  });
2060
2076
  var IdField = BaseField.extend({
2061
- defaultValue: NonEmptyTextValue.optional(),
2077
+ defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional(),
2062
2078
  type: import_v43.default.literal(FieldType.ID)
2063
2079
  }).meta({
2064
2080
  description: "A field for entering an ID",
@@ -2066,14 +2082,14 @@ var IdField = BaseField.extend({
2066
2082
  });
2067
2083
  var Checkbox = BaseField.extend({
2068
2084
  type: import_v43.default.literal(FieldType.CHECKBOX),
2069
- defaultValue: CheckboxFieldValue.default(false)
2085
+ defaultValue: CheckboxFieldValue.or(ComputedDefaultValue).default(false)
2070
2086
  }).meta({
2071
2087
  description: "A boolean checkbox field",
2072
2088
  id: "Checkbox"
2073
2089
  });
2074
2090
  var Country = BaseField.extend({
2075
2091
  type: import_v43.default.literal(FieldType.COUNTRY),
2076
- defaultValue: NonEmptyTextValue.optional(),
2092
+ defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional(),
2077
2093
  optionOverrides: import_v43.default.array(SelectOption.omit({ label: true })).optional().describe(
2078
2094
  "Conditionals for specific countries. Countries not listed are always shown and enabled."
2079
2095
  )
@@ -2091,7 +2107,7 @@ var AdministrativeAreas = import_v43.default.enum([
2091
2107
  ]);
2092
2108
  var AdministrativeAreaField = BaseField.extend({
2093
2109
  type: import_v43.default.literal(FieldType.ADMINISTRATIVE_AREA),
2094
- defaultValue: import_v43.default.union([NonEmptyTextValue, SerializedUserField]).optional(),
2110
+ defaultValue: import_v43.default.union([NonEmptyTextValue, SerializedUserField, ComputedDefaultValue]).optional(),
2095
2111
  configuration: import_v43.default.object({
2096
2112
  partOf: FieldReference.optional().describe("Parent location"),
2097
2113
  type: AdministrativeAreas,
@@ -2103,7 +2119,7 @@ var AdministrativeAreaField = BaseField.extend({
2103
2119
  });
2104
2120
  var LocationInput = BaseField.extend({
2105
2121
  type: import_v43.default.literal(FieldType.LOCATION),
2106
- defaultValue: import_v43.default.union([NonEmptyTextValue, SerializedUserField]).optional(),
2122
+ defaultValue: import_v43.default.union([NonEmptyTextValue, SerializedUserField, ComputedDefaultValue]).optional(),
2107
2123
  configuration: import_v43.default.object({
2108
2124
  locationTypes: import_v43.default.array(import_v43.default.string()).optional().describe("Types of the locations that are available for selection."),
2109
2125
  allowedLocations: AllowedLocations
@@ -2115,7 +2131,7 @@ var LocationInput = BaseField.extend({
2115
2131
  var FileUploadWithOptions = BaseField.extend({
2116
2132
  type: import_v43.default.literal(FieldType.FILE_WITH_OPTIONS),
2117
2133
  options: import_v43.default.array(SelectOption).describe("A list of options"),
2118
- defaultValue: FileFieldWithOptionValue.optional(),
2134
+ defaultValue: FileFieldWithOptionValue.or(ComputedDefaultValue).optional(),
2119
2135
  configuration: import_v43.default.object({
2120
2136
  maxFileSize: import_v43.default.number().describe("Maximum file size in bytes").default(DEFAULT_MAX_FILE_SIZE_BYTES),
2121
2137
  maxImageSize: import_v43.default.object({
@@ -2131,12 +2147,12 @@ var FileUploadWithOptions = BaseField.extend({
2131
2147
  });
2132
2148
  var Facility = BaseField.extend({
2133
2149
  type: import_v43.default.literal(FieldType.FACILITY),
2134
- defaultValue: NonEmptyTextValue.optional(),
2150
+ defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional(),
2135
2151
  configuration: import_v43.default.object({ allowedLocations: AllowedLocations }).optional()
2136
2152
  }).describe("Input field for a facility");
2137
2153
  var Office = BaseField.extend({
2138
2154
  type: import_v43.default.literal(FieldType.OFFICE),
2139
- defaultValue: NonEmptyTextValue.optional(),
2155
+ defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional(),
2140
2156
  configuration: import_v43.default.object({ allowedLocations: AllowedLocations }).optional()
2141
2157
  }).describe("Input field for an office");
2142
2158
  var DefaultAddressFieldValue = DomesticAddressFieldValue.extend({
@@ -2172,7 +2188,7 @@ var Address = BaseField.extend({
2172
2188
  ).optional(),
2173
2189
  allowedLocations: AllowedLocations
2174
2190
  }).optional(),
2175
- defaultValue: DefaultAddressFieldValue.optional()
2191
+ defaultValue: DefaultAddressFieldValue.or(ComputedDefaultValue).optional()
2176
2192
  }).meta({
2177
2193
  description: "Address input field \u2013 a combination of location and text fields",
2178
2194
  id: "Address"
@@ -2219,7 +2235,7 @@ var ButtonConfiguration = import_v43.default.object({
2219
2235
  });
2220
2236
  var ButtonField = BaseField.extend({
2221
2237
  type: import_v43.default.literal(FieldType.BUTTON),
2222
- defaultValue: ButtonFieldValue.optional(),
2238
+ defaultValue: ButtonFieldValue.or(ComputedDefaultValue).optional(),
2223
2239
  configuration: ButtonConfiguration
2224
2240
  }).meta({
2225
2241
  description: "A generic button that can be used to trigger an action",
@@ -2247,7 +2263,7 @@ var AlphaPrintButton = BaseField.extend({
2247
2263
  });
2248
2264
  var HttpField = BaseField.extend({
2249
2265
  type: import_v43.default.literal(FieldType.HTTP),
2250
- defaultValue: HttpFieldValue.optional(),
2266
+ defaultValue: HttpFieldValue.or(ComputedDefaultValue).optional(),
2251
2267
  configuration: import_v43.default.object({
2252
2268
  trigger: FieldReference.optional().describe(
2253
2269
  "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."
@@ -2333,7 +2349,7 @@ var LinkButtonField = BaseField.extend({
2333
2349
  });
2334
2350
  var VerificationStatus = BaseField.extend({
2335
2351
  type: import_v43.default.literal(FieldType.VERIFICATION_STATUS),
2336
- defaultValue: VerificationStatusValue.optional(),
2352
+ defaultValue: VerificationStatusValue.or(ComputedDefaultValue).optional(),
2337
2353
  configuration: import_v43.default.object({
2338
2354
  status: TranslationConfig.describe("Text to display on the status pill."),
2339
2355
  description: TranslationConfig.describe(
@@ -2355,7 +2371,7 @@ var QueryParamReaderField = BaseField.extend({
2355
2371
  });
2356
2372
  var QrReaderField = BaseField.extend({
2357
2373
  type: import_v43.default.literal(FieldType.QR_READER),
2358
- defaultValue: QrReaderFieldValue.optional(),
2374
+ defaultValue: QrReaderFieldValue.or(ComputedDefaultValue).optional(),
2359
2375
  configuration: import_v43.default.object({
2360
2376
  validator: import_v43.default.any().meta({
2361
2377
  description: "JSON Schema to validate the scanned QR code data against before populating the form fields.",
@@ -2368,7 +2384,7 @@ var QrReaderField = BaseField.extend({
2368
2384
  });
2369
2385
  var IdReaderField = BaseField.extend({
2370
2386
  type: import_v43.default.literal(FieldType.ID_READER),
2371
- defaultValue: IdReaderFieldValue.optional(),
2387
+ defaultValue: IdReaderFieldValue.or(ComputedDefaultValue).optional(),
2372
2388
  methods: import_v43.default.array(
2373
2389
  import_v43.default.union([QrReaderField, LinkButtonField]).describe("Methods for reading an ID")
2374
2390
  )
@@ -2927,6 +2943,9 @@ var BaseField3 = z28.object({
2927
2943
  ),
2928
2944
  validations: z28.array(ValidationConfig).optional().describe(
2929
2945
  `Option for overriding the field validations specifically for advanced search form.`
2946
+ ),
2947
+ allowedLocations: JurisdictionReference.optional().describe(
2948
+ `Override the allowedLocations for a location field in advanced search. Use this when the declaration form's allowedLocations references a scope (e.g. record.create) that search-only users don't have \u2014 specify record.search scope instead.`
2930
2949
  )
2931
2950
  });
2932
2951
  var SearchQueryParams = z28.object({
@@ -3033,7 +3052,37 @@ function resolveDataPath(rootData, dataPath, instancePath) {
3033
3052
  }
3034
3053
  return current;
3035
3054
  }
3055
+ function todayISO() {
3056
+ return (0, import_date_fns.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" });
3057
+ }
3058
+ var compiledFunctionCache = /* @__PURE__ */ new Map();
3059
+ function compileClientFunction(code) {
3060
+ let fn = compiledFunctionCache.get(code);
3061
+ if (!fn) {
3062
+ fn = new Function(`return (${code})`)();
3063
+ compiledFunctionCache.set(code, fn);
3064
+ }
3065
+ return fn;
3066
+ }
3036
3067
  (0, import_ajv_formats.default)(ajv);
3068
+ function buildClientFunctionContext(input) {
3069
+ return {
3070
+ $form: input.form,
3071
+ $now: todayISO(),
3072
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
3073
+ $online: isOnline(),
3074
+ $user: input.validatorContext?.user,
3075
+ $event: input.validatorContext?.event,
3076
+ $leafAdminStructureLocationIds: input.validatorContext?.leafAdminStructureLocationIds ?? [],
3077
+ user: input.systemVariables?.user,
3078
+ $window: input.systemVariables?.$window,
3079
+ locations: input.locations,
3080
+ adminLevelIds: input.adminLevelIds
3081
+ };
3082
+ }
3083
+ function runClientFunction(code, data, context) {
3084
+ return compileClientFunction(code)(data, context);
3085
+ }
3037
3086
  ajv.addKeyword({
3038
3087
  keyword: "daysFromDate",
3039
3088
  type: "string",
@@ -3078,12 +3127,35 @@ ajv.addKeyword({
3078
3127
  $data: true,
3079
3128
  errors: true,
3080
3129
  // @ts-ignore -- Force type. We will move this away from AJV next. Parsing the array will take seconds and is only called by core.
3081
- validate(schema, data, _2, dataContext) {
3130
+ validate(_schema, data, _2, dataContext) {
3082
3131
  const locationIdInput = data;
3083
3132
  const locations = dataContext?.rootData.$leafAdminStructureLocationIds ?? [];
3084
3133
  return locations.some((location) => location.id === locationIdInput);
3085
3134
  }
3086
3135
  });
3136
+ ajv.addKeyword({
3137
+ keyword: "customClientValidator",
3138
+ schemaType: "object",
3139
+ errors: true,
3140
+ // @ts-expect-error -- AJV's public types don't expose `rootData`. All
3141
+ // `validate()` callers build root data via `buildClientFunctionContext`,
3142
+ // so the cast holds.
3143
+ validate(schema, data, _2, dataContext) {
3144
+ return Boolean(
3145
+ runClientFunction(
3146
+ schema.code,
3147
+ data,
3148
+ dataContext?.rootData ?? buildClientFunctionContext({ form: {} })
3149
+ )
3150
+ );
3151
+ }
3152
+ });
3153
+ function isOnline() {
3154
+ if (typeof window !== "undefined" && typeof navigator !== "undefined") {
3155
+ return navigator.onLine;
3156
+ }
3157
+ return true;
3158
+ }
3087
3159
 
3088
3160
  // ../commons/src/utils.ts
3089
3161
  var z32 = __toESM(require("zod/v4"));
@@ -3702,7 +3774,54 @@ function createFieldConditionals(fieldId) {
3702
3774
  }
3703
3775
  },
3704
3776
  required: [fieldId]
3705
- })
3777
+ }),
3778
+ /**
3779
+ * Custom client-side validator. The provided function is serialised and executed
3780
+ * just-in-time on the client only. External references (e.g. lodash) are not
3781
+ * available inside the function body — all logic must be self-contained.
3782
+ *
3783
+ * @example
3784
+ * field('nid').customClientValidator((value) => {
3785
+ * // LUHN check — all logic must be inline
3786
+ * const digits = String(value).split('').map(Number)
3787
+ * // ...
3788
+ * return isValid
3789
+ * })
3790
+ */
3791
+ customClientValidator(validationFn) {
3792
+ const code = validationFn.toString();
3793
+ return defineFormConditional({
3794
+ type: "object",
3795
+ properties: wrapToPath(
3796
+ { [fieldId]: { customClientValidator: { code } } },
3797
+ this.$$subfield
3798
+ ),
3799
+ required: [fieldId]
3800
+ });
3801
+ },
3802
+ /**
3803
+ * Custom client-side evaluation. Returns a {@link FieldReference} descriptor
3804
+ * that can be used as the `value` property or a DATA component entry.
3805
+ * The function receives the referenced field's value as the first argument and
3806
+ * the full form context as the second; its return value replaces the field reference.
3807
+ * The function is serialised and executed just-in-time on the client only.
3808
+ * External references (e.g. lodash) are not available inside the function body.
3809
+ *
3810
+ * For computing a default value without referencing a specific field, use
3811
+ * `evaluate(fn)` in the `defaultValue` property instead.
3812
+ *
3813
+ * @example
3814
+ * field('a').customClientEvaluation((aValue, ctx) =>
3815
+ * Number(aValue) + Number(ctx.$form.b)
3816
+ * )
3817
+ */
3818
+ customClientEvaluation(computationFn) {
3819
+ return {
3820
+ $$code: computationFn.toString(),
3821
+ $$field: fieldId,
3822
+ $$subfield: this.$$subfield
3823
+ };
3824
+ }
3706
3825
  };
3707
3826
  }
3708
3827
 
@@ -7127,6 +7246,13 @@ var ACTION_FILTERS = {
7127
7246
  [ActionType.UNASSIGN]: (flags) => !flags.some((flag) => flag.endsWith(":requested")),
7128
7247
  [ActionType.CUSTOM]: (flags) => !flags.some((flag) => flag.endsWith(":requested"))
7129
7248
  };
7249
+ var REJECTED_ACTIONS = [
7250
+ ActionType.READ,
7251
+ ActionType.NOTIFY,
7252
+ ActionType.CUSTOM,
7253
+ ActionType.EDIT,
7254
+ ActionType.ARCHIVE
7255
+ ];
7130
7256
 
7131
7257
  // ../commons/src/events/FileUtils.ts
7132
7258
  var import_lodash7 = require("lodash");
@@ -580,14 +580,12 @@ export type EncodedScope = z.infer<typeof EncodedScope>;
580
580
  */
581
581
  export declare const encodeScope: (scope: Scope) => EncodedScope;
582
582
  /**
583
- * Converts a scope object into an encoded query string representation.
583
+ * Converts an encoded scope string into a scope object.
584
584
  *
585
- * @TODO scope param could be defined as EncodedScope instead of string.
586
- *
587
- * @param scope - The scope object to encode.
588
- * @returns The encoded scope as a branded string (`EncodedScope`).
585
+ * @param scope - The encoded scope string to decode.
586
+ * @returns The decoded scope object.
589
587
  */
590
- export declare const decodeScope: (query: EncodedScope) => {
588
+ export declare const decodeScope: (encodedScope: EncodedScope) => {
591
589
  type: "record.create" | "record.declare" | "record.notify";
592
590
  options?: {
593
591
  event?: string[] | undefined;
@@ -354,14 +354,20 @@ var encodeScope = (scope) => {
354
354
  encode: false
355
355
  });
356
356
  };
357
- var decodeScope = (query) => {
358
- const scope = qs.parse(query, {
357
+ var decodedScopeCache = /* @__PURE__ */ new Map();
358
+ var decodeScope = (encodedScope) => {
359
+ if (decodedScopeCache.has(encodedScope)) {
360
+ return decodedScopeCache.get(encodedScope);
361
+ }
362
+ const scope = qs.parse(encodedScope, {
359
363
  ignoreQueryPrefix: true,
360
364
  comma: true,
361
365
  allowDots: true
362
366
  });
363
367
  const unflattenedScope = unflattenScope(scope);
364
- return Scope2.safeParse(unflattenedScope)?.data;
368
+ const result = Scope2.safeParse(unflattenedScope)?.data;
369
+ decodedScopeCache.set(encodedScope, result);
370
+ return result;
365
371
  };
366
372
  var DEFAULT_SCOPE_OPTIONS = {
367
373
  placeOfEvent: JurisdictionFilter.enum.all,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opencrvs/toolkit",
3
- "version": "2.0.0-rc.ee1414e",
3
+ "version": "2.0.0-rc.ee6f4f7",
4
4
  "description": "OpenCRVS toolkit for building country configurations",
5
5
  "license": "MPL-2.0",
6
6
  "bin": {