@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
package/dist/events/index.js
CHANGED
|
@@ -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,
|
|
@@ -229,6 +230,7 @@ __export(events_exports, {
|
|
|
229
230
|
areConditionsMet: () => areConditionsMet,
|
|
230
231
|
buildFormState: () => buildFormState,
|
|
231
232
|
canUserReadEvent: () => canUserReadEvent,
|
|
233
|
+
compileClientFunction: () => compileClientFunction,
|
|
232
234
|
compositeFieldTypes: () => compositeFieldTypes,
|
|
233
235
|
configurableEventScopeAllowed: () => configurableEventScopeAllowed,
|
|
234
236
|
createEmptyDraft: () => createEmptyDraft,
|
|
@@ -250,6 +252,7 @@ __export(events_exports, {
|
|
|
250
252
|
defineWorkqueuesColumns: () => defineWorkqueuesColumns,
|
|
251
253
|
deserializeQuery: () => deserializeQuery,
|
|
252
254
|
errorMessages: () => errorMessages,
|
|
255
|
+
evaluate: () => evaluate,
|
|
253
256
|
event: () => event,
|
|
254
257
|
eventMetadataLabelMap: () => eventMetadataLabelMap,
|
|
255
258
|
eventPayloadGenerator: () => eventPayloadGenerator,
|
|
@@ -313,6 +316,7 @@ __export(events_exports, {
|
|
|
313
316
|
isBulletListFieldType: () => isBulletListFieldType,
|
|
314
317
|
isButtonFieldType: () => isButtonFieldType,
|
|
315
318
|
isCheckboxFieldType: () => isCheckboxFieldType,
|
|
319
|
+
isCodeToEvaluate: () => isCodeToEvaluate,
|
|
316
320
|
isConditionMet: () => isConditionMet,
|
|
317
321
|
isCountryFieldType: () => isCountryFieldType,
|
|
318
322
|
isDataFieldType: () => isDataFieldType,
|
|
@@ -383,6 +387,7 @@ __export(events_exports, {
|
|
|
383
387
|
runStructuralValidations: () => runStructuralValidations,
|
|
384
388
|
safeUnion: () => safeUnion,
|
|
385
389
|
timePeriodToDateRange: () => timePeriodToDateRange,
|
|
390
|
+
todayISO: () => todayISO,
|
|
386
391
|
user: () => user,
|
|
387
392
|
validate: () => validate,
|
|
388
393
|
validateFieldInput: () => validateFieldInput,
|
|
@@ -1982,11 +1987,26 @@ var FieldId = import_zod17.z.string().refine(
|
|
|
1982
1987
|
})
|
|
1983
1988
|
).describe("Unique identifier for the field");
|
|
1984
1989
|
var FieldReference = import_zod17.z.object({
|
|
1985
|
-
$$field: FieldId
|
|
1990
|
+
$$field: FieldId.describe(
|
|
1991
|
+
"Field whose value is passed as the first argument to the computation"
|
|
1992
|
+
),
|
|
1986
1993
|
$$subfield: import_zod17.z.array(import_zod17.z.string()).optional().default([]).describe(
|
|
1987
1994
|
'If the FieldValue is an object, subfield can be used to refer to e.g. `["foo", "bar"]` in `{ foo: { bar: 3 } }`'
|
|
1995
|
+
),
|
|
1996
|
+
$$code: import_zod17.z.string().optional().describe(
|
|
1997
|
+
"Serialised client-side function body. When present the expression is evaluated rather than dereferenced."
|
|
1998
|
+
)
|
|
1999
|
+
}).describe(
|
|
2000
|
+
"Reference to a field value, with an optional client-side computation applied."
|
|
2001
|
+
);
|
|
2002
|
+
function isCodeToEvaluate(v) {
|
|
2003
|
+
return !!v && typeof v === "object" && "$$code" in v;
|
|
2004
|
+
}
|
|
2005
|
+
var ComputedDefaultValue = import_zod17.z.object({
|
|
2006
|
+
$$code: import_zod17.z.string().describe(
|
|
2007
|
+
"Serialised client-side function body. Receives (undefined, context) where context includes $now, $online, and system variables."
|
|
1988
2008
|
)
|
|
1989
|
-
}).describe("
|
|
2009
|
+
}).describe("A context-only computation used as a field default value.");
|
|
1990
2010
|
var ValidationConfig = import_zod17.z.object({
|
|
1991
2011
|
validator: Conditional,
|
|
1992
2012
|
message: TranslationConfig
|
|
@@ -2020,7 +2040,7 @@ var BaseField = import_zod17.z.object({
|
|
|
2020
2040
|
"Indicates whether the field can be modified during record correction."
|
|
2021
2041
|
),
|
|
2022
2042
|
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."
|
|
2043
|
+
"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
2044
|
),
|
|
2025
2045
|
analytics: import_zod17.z.boolean().default(false).optional().describe(
|
|
2026
2046
|
"Indicates whether the field is included in analytics. When enabled, its value becomes available in the analytics dashboard."
|
|
@@ -2031,7 +2051,7 @@ var Divider = BaseField.extend({
|
|
|
2031
2051
|
});
|
|
2032
2052
|
var TextField = BaseField.extend({
|
|
2033
2053
|
type: import_zod17.z.literal(FieldType.TEXT),
|
|
2034
|
-
defaultValue: import_zod17.z.union([NonEmptyTextValue, SerializedUserField]).optional(),
|
|
2054
|
+
defaultValue: import_zod17.z.union([NonEmptyTextValue, SerializedUserField, ComputedDefaultValue]).optional(),
|
|
2035
2055
|
configuration: import_zod17.z.object({
|
|
2036
2056
|
maxLength: import_zod17.z.number().optional().describe("Maximum length of the text"),
|
|
2037
2057
|
type: import_zod17.z.enum(["text", "password"]).optional(),
|
|
@@ -2041,7 +2061,7 @@ var TextField = BaseField.extend({
|
|
|
2041
2061
|
}).describe("Text input");
|
|
2042
2062
|
var NumberField = BaseField.extend({
|
|
2043
2063
|
type: import_zod17.z.literal(FieldType.NUMBER),
|
|
2044
|
-
defaultValue: NumberFieldValue.optional(),
|
|
2064
|
+
defaultValue: NumberFieldValue.or(ComputedDefaultValue).optional(),
|
|
2045
2065
|
configuration: import_zod17.z.object({
|
|
2046
2066
|
min: import_zod17.z.number().optional().describe("Minimum value"),
|
|
2047
2067
|
max: import_zod17.z.number().optional().describe("Maximum value"),
|
|
@@ -2051,7 +2071,7 @@ var NumberField = BaseField.extend({
|
|
|
2051
2071
|
}).describe("Number input");
|
|
2052
2072
|
var TextAreaField = BaseField.extend({
|
|
2053
2073
|
type: import_zod17.z.literal(FieldType.TEXTAREA),
|
|
2054
|
-
defaultValue: NonEmptyTextValue.optional(),
|
|
2074
|
+
defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional(),
|
|
2055
2075
|
configuration: import_zod17.z.object({
|
|
2056
2076
|
maxLength: import_zod17.z.number().optional().describe("Maximum length of the text"),
|
|
2057
2077
|
rows: import_zod17.z.number().optional().describe("Number of visible text lines"),
|
|
@@ -2082,7 +2102,7 @@ var SignatureField = BaseField.extend({
|
|
|
2082
2102
|
signaturePromptLabel: TranslationConfig.describe(
|
|
2083
2103
|
"Title of the signature modal"
|
|
2084
2104
|
),
|
|
2085
|
-
defaultValue: SignatureFieldValue.optional(),
|
|
2105
|
+
defaultValue: SignatureFieldValue.or(ComputedDefaultValue).optional(),
|
|
2086
2106
|
configuration: import_zod17.z.object({
|
|
2087
2107
|
maxFileSize: import_zod17.z.number().describe("Maximum file size in bytes").default(DEFAULT_MAX_FILE_SIZE_BYTES),
|
|
2088
2108
|
acceptedFileTypes: MimeType.array().optional().describe("List of allowed file formats for the signature")
|
|
@@ -2095,11 +2115,11 @@ var EmailField = BaseField.extend({
|
|
|
2095
2115
|
configuration: import_zod17.z.object({
|
|
2096
2116
|
maxLength: import_zod17.z.number().optional().describe("Maximum length of the text")
|
|
2097
2117
|
}).default({ maxLength: 10 }).optional(),
|
|
2098
|
-
defaultValue: NonEmptyTextValue.optional()
|
|
2118
|
+
defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional()
|
|
2099
2119
|
});
|
|
2100
2120
|
var DateField = BaseField.extend({
|
|
2101
2121
|
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)"),
|
|
2122
|
+
defaultValue: SerializedNowDateTime.or(PlainDate).or(ComputedDefaultValue).optional().openapi({ effectType: "input", type: "string" }).describe("Default date value(yyyy-MM-dd)"),
|
|
2103
2123
|
configuration: import_zod17.z.object({
|
|
2104
2124
|
notice: TranslationConfig.describe(
|
|
2105
2125
|
"Text to display above the date input"
|
|
@@ -2108,7 +2128,7 @@ var DateField = BaseField.extend({
|
|
|
2108
2128
|
}).describe("A single date input (yyyy-MM-dd)");
|
|
2109
2129
|
var AgeField = BaseField.extend({
|
|
2110
2130
|
type: import_zod17.z.literal(FieldType.AGE),
|
|
2111
|
-
defaultValue: NumberFieldValue.optional(),
|
|
2131
|
+
defaultValue: NumberFieldValue.or(ComputedDefaultValue).optional(),
|
|
2112
2132
|
configuration: import_zod17.z.object({
|
|
2113
2133
|
asOfDate: FieldReference,
|
|
2114
2134
|
prefix: TranslationConfig.optional(),
|
|
@@ -2117,7 +2137,7 @@ var AgeField = BaseField.extend({
|
|
|
2117
2137
|
}).describe("An age input field which uses the current date as the asOfDate");
|
|
2118
2138
|
var TimeField = BaseField.extend({
|
|
2119
2139
|
type: import_zod17.z.literal(FieldType.TIME),
|
|
2120
|
-
defaultValue: SerializedNowDateTime.or(TimeValue).optional().openapi({ effectType: "input", type: "object" }).describe("Default time value (HH-mm)"),
|
|
2140
|
+
defaultValue: SerializedNowDateTime.or(TimeValue).or(ComputedDefaultValue).optional().openapi({ effectType: "input", type: "object" }).describe("Default time value (HH-mm)"),
|
|
2121
2141
|
configuration: import_zod17.z.object({
|
|
2122
2142
|
use12HourFormat: import_zod17.z.boolean().optional().describe("Whether to use 12-hour format"),
|
|
2123
2143
|
notice: TranslationConfig.describe(
|
|
@@ -2127,7 +2147,7 @@ var TimeField = BaseField.extend({
|
|
|
2127
2147
|
}).describe("A single date input (HH-mm)");
|
|
2128
2148
|
var DateRangeField = BaseField.extend({
|
|
2129
2149
|
type: import_zod17.z.literal(FieldType.DATE_RANGE),
|
|
2130
|
-
defaultValue: DateRangeFieldValue.optional(),
|
|
2150
|
+
defaultValue: DateRangeFieldValue.or(ComputedDefaultValue).optional(),
|
|
2131
2151
|
configuration: import_zod17.z.object({
|
|
2132
2152
|
notice: TranslationConfig.describe(
|
|
2133
2153
|
"Text to display above the date input"
|
|
@@ -2161,7 +2181,7 @@ var PageHeader = BaseField.extend({
|
|
|
2161
2181
|
}).describe("A read-only header component for form pages");
|
|
2162
2182
|
var File = BaseField.extend({
|
|
2163
2183
|
type: import_zod17.z.literal(FieldType.FILE),
|
|
2164
|
-
defaultValue: FileFieldValue.optional(),
|
|
2184
|
+
defaultValue: FileFieldValue.or(ComputedDefaultValue).optional(),
|
|
2165
2185
|
configuration: import_zod17.z.object({
|
|
2166
2186
|
maxFileSize: import_zod17.z.number().describe("Maximum file size in bytes").default(DEFAULT_MAX_FILE_SIZE_BYTES),
|
|
2167
2187
|
acceptedFileTypes: MimeType.array().optional().describe("List of allowed file formats for the signature"),
|
|
@@ -2185,7 +2205,7 @@ var SelectOption = import_zod17.z.object({
|
|
|
2185
2205
|
});
|
|
2186
2206
|
var NumberWithUnitField = BaseField.extend({
|
|
2187
2207
|
type: import_zod17.z.literal(FieldType.NUMBER_WITH_UNIT),
|
|
2188
|
-
defaultValue: NumberWithUnitFieldValue.optional(),
|
|
2208
|
+
defaultValue: NumberWithUnitFieldValue.or(ComputedDefaultValue).optional(),
|
|
2189
2209
|
options: import_zod17.z.array(SelectOption).describe("A list of options for the unit select"),
|
|
2190
2210
|
configuration: import_zod17.z.object({
|
|
2191
2211
|
min: import_zod17.z.number().optional().describe("Minimum value of the number field"),
|
|
@@ -2197,7 +2217,7 @@ var NumberWithUnitField = BaseField.extend({
|
|
|
2197
2217
|
}).describe("Number with unit input");
|
|
2198
2218
|
var RadioGroup = BaseField.extend({
|
|
2199
2219
|
type: import_zod17.z.literal(FieldType.RADIO_GROUP),
|
|
2200
|
-
defaultValue: TextValue.optional(),
|
|
2220
|
+
defaultValue: TextValue.or(ComputedDefaultValue).optional(),
|
|
2201
2221
|
options: import_zod17.z.array(SelectOption).describe("A list of options"),
|
|
2202
2222
|
configuration: import_zod17.z.object({
|
|
2203
2223
|
styles: import_zod17.z.object({
|
|
@@ -2216,7 +2236,7 @@ var BulletList = BaseField.extend({
|
|
|
2216
2236
|
}).describe("A list of bullet points");
|
|
2217
2237
|
var Select = BaseField.extend({
|
|
2218
2238
|
type: import_zod17.z.literal(FieldType.SELECT),
|
|
2219
|
-
defaultValue: TextValue.optional(),
|
|
2239
|
+
defaultValue: TextValue.or(ComputedDefaultValue).optional(),
|
|
2220
2240
|
options: import_zod17.z.array(SelectOption).describe("A list of options"),
|
|
2221
2241
|
noOptionsMessage: TranslationConfig.optional().describe(
|
|
2222
2242
|
`
|
|
@@ -2235,7 +2255,7 @@ var SelectDateRangeOption = import_zod17.z.object({
|
|
|
2235
2255
|
});
|
|
2236
2256
|
var SelectDateRangeField = BaseField.extend({
|
|
2237
2257
|
type: import_zod17.z.literal(FieldType.SELECT_DATE_RANGE),
|
|
2238
|
-
defaultValue: SelectDateRangeValue.optional(),
|
|
2258
|
+
defaultValue: SelectDateRangeValue.or(ComputedDefaultValue).optional(),
|
|
2239
2259
|
options: import_zod17.z.array(SelectDateRangeOption).describe("A list of options")
|
|
2240
2260
|
}).describe("Select input with date range options");
|
|
2241
2261
|
var NameConfig = import_zod17.z.object({
|
|
@@ -2249,7 +2269,7 @@ var NameField = BaseField.extend({
|
|
|
2249
2269
|
firstname: SerializedUserField.or(NonEmptyTextValue).optional(),
|
|
2250
2270
|
middlename: SerializedUserField.or(NonEmptyTextValue).optional(),
|
|
2251
2271
|
surname: SerializedUserField.or(NonEmptyTextValue).optional()
|
|
2252
|
-
}).optional(),
|
|
2272
|
+
}).or(ComputedDefaultValue).optional(),
|
|
2253
2273
|
configuration: import_zod17.z.object({
|
|
2254
2274
|
name: NameConfig.default({
|
|
2255
2275
|
firstname: { required: true },
|
|
@@ -2270,20 +2290,20 @@ var NameField = BaseField.extend({
|
|
|
2270
2290
|
}).optional()
|
|
2271
2291
|
}).describe("Name input field");
|
|
2272
2292
|
var PhoneField = BaseField.extend({
|
|
2273
|
-
defaultValue: NonEmptyTextValue.optional(),
|
|
2293
|
+
defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional(),
|
|
2274
2294
|
type: import_zod17.z.literal(FieldType.PHONE)
|
|
2275
2295
|
}).describe("Phone input field");
|
|
2276
2296
|
var IdField = BaseField.extend({
|
|
2277
|
-
defaultValue: NonEmptyTextValue.optional(),
|
|
2297
|
+
defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional(),
|
|
2278
2298
|
type: import_zod17.z.literal(FieldType.ID)
|
|
2279
2299
|
}).describe("ID input field");
|
|
2280
2300
|
var Checkbox = BaseField.extend({
|
|
2281
2301
|
type: import_zod17.z.literal(FieldType.CHECKBOX),
|
|
2282
|
-
defaultValue: CheckboxFieldValue.default(false)
|
|
2302
|
+
defaultValue: CheckboxFieldValue.or(ComputedDefaultValue).default(false)
|
|
2283
2303
|
}).describe("Boolean checkbox field");
|
|
2284
2304
|
var Country = BaseField.extend({
|
|
2285
2305
|
type: import_zod17.z.literal(FieldType.COUNTRY),
|
|
2286
|
-
defaultValue: NonEmptyTextValue.optional(),
|
|
2306
|
+
defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional(),
|
|
2287
2307
|
optionOverrides: import_zod17.z.array(SelectOption.omit({ label: true })).optional().describe(
|
|
2288
2308
|
"Conditionals for specific countries. Countries not listed are always shown and enabled."
|
|
2289
2309
|
)
|
|
@@ -2299,12 +2319,12 @@ var AdministrativeAreaConfiguration = import_zod17.z.object({
|
|
|
2299
2319
|
}).describe("Administrative area options");
|
|
2300
2320
|
var AdministrativeArea = BaseField.extend({
|
|
2301
2321
|
type: import_zod17.z.literal(FieldType.ADMINISTRATIVE_AREA),
|
|
2302
|
-
defaultValue: import_zod17.z.union([NonEmptyTextValue, SerializedUserField]).optional(),
|
|
2322
|
+
defaultValue: import_zod17.z.union([NonEmptyTextValue, SerializedUserField, ComputedDefaultValue]).optional(),
|
|
2303
2323
|
configuration: AdministrativeAreaConfiguration
|
|
2304
2324
|
}).describe("Administrative area input field e.g. facility, office");
|
|
2305
2325
|
var LocationInput = BaseField.extend({
|
|
2306
2326
|
type: import_zod17.z.literal(FieldType.LOCATION),
|
|
2307
|
-
defaultValue: NonEmptyTextValue.optional(),
|
|
2327
|
+
defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional(),
|
|
2308
2328
|
configuration: import_zod17.z.object({
|
|
2309
2329
|
searchableResource: import_zod17.z.array(import_zod17.z.enum(["locations", "facilities", "offices"]))
|
|
2310
2330
|
})
|
|
@@ -2312,7 +2332,7 @@ var LocationInput = BaseField.extend({
|
|
|
2312
2332
|
var FileUploadWithOptions = BaseField.extend({
|
|
2313
2333
|
type: import_zod17.z.literal(FieldType.FILE_WITH_OPTIONS),
|
|
2314
2334
|
options: import_zod17.z.array(SelectOption).describe("A list of options"),
|
|
2315
|
-
defaultValue: FileFieldWithOptionValue.optional(),
|
|
2335
|
+
defaultValue: FileFieldWithOptionValue.or(ComputedDefaultValue).optional(),
|
|
2316
2336
|
configuration: import_zod17.z.object({
|
|
2317
2337
|
maxFileSize: import_zod17.z.number().describe("Maximum file size in bytes").default(DEFAULT_MAX_FILE_SIZE_BYTES),
|
|
2318
2338
|
maxImageSize: import_zod17.z.object({
|
|
@@ -2325,11 +2345,11 @@ var FileUploadWithOptions = BaseField.extend({
|
|
|
2325
2345
|
});
|
|
2326
2346
|
var Facility = BaseField.extend({
|
|
2327
2347
|
type: import_zod17.z.literal(FieldType.FACILITY),
|
|
2328
|
-
defaultValue: NonEmptyTextValue.optional()
|
|
2348
|
+
defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional()
|
|
2329
2349
|
}).describe("Input field for a facility");
|
|
2330
2350
|
var Office = BaseField.extend({
|
|
2331
2351
|
type: import_zod17.z.literal(FieldType.OFFICE),
|
|
2332
|
-
defaultValue: NonEmptyTextValue.optional()
|
|
2352
|
+
defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional()
|
|
2333
2353
|
}).describe("Input field for an office");
|
|
2334
2354
|
var DefaultAddressFieldValue = DomesticAddressFieldValue.extend({
|
|
2335
2355
|
administrativeArea: import_zod17.z.union([UUID, SerializedUserField]).optional()
|
|
@@ -2363,7 +2383,7 @@ var Address = BaseField.extend({
|
|
|
2363
2383
|
})
|
|
2364
2384
|
).optional()
|
|
2365
2385
|
}).optional(),
|
|
2366
|
-
defaultValue: DefaultAddressFieldValue.optional()
|
|
2386
|
+
defaultValue: DefaultAddressFieldValue.or(ComputedDefaultValue).optional()
|
|
2367
2387
|
}).describe("Address input field \u2013 a combination of location and text fields");
|
|
2368
2388
|
var StaticDataEntry = import_zod17.z.object({
|
|
2369
2389
|
id: import_zod17.z.string().describe("ID for the data entry."),
|
|
@@ -2382,7 +2402,7 @@ var DataField = BaseField.extend({
|
|
|
2382
2402
|
}).describe("Data field for displaying read-only data");
|
|
2383
2403
|
var ButtonField = BaseField.extend({
|
|
2384
2404
|
type: import_zod17.z.literal(FieldType.BUTTON),
|
|
2385
|
-
defaultValue: ButtonFieldValue.optional(),
|
|
2405
|
+
defaultValue: ButtonFieldValue.or(ComputedDefaultValue).optional(),
|
|
2386
2406
|
configuration: import_zod17.z.object({
|
|
2387
2407
|
icon: import_zod17.z.string().optional().describe(
|
|
2388
2408
|
"Icon for the button. You can find icons from OpenCRVS UI-Kit."
|
|
@@ -2407,7 +2427,7 @@ var AlphaPrintButton = BaseField.extend({
|
|
|
2407
2427
|
}).describe("Print button field for printing certificates");
|
|
2408
2428
|
var HttpField = BaseField.extend({
|
|
2409
2429
|
type: import_zod17.z.literal(FieldType.HTTP),
|
|
2410
|
-
defaultValue: HttpFieldValue.optional(),
|
|
2430
|
+
defaultValue: HttpFieldValue.or(ComputedDefaultValue).optional(),
|
|
2411
2431
|
configuration: import_zod17.z.object({
|
|
2412
2432
|
trigger: FieldReference,
|
|
2413
2433
|
url: import_zod17.z.string().describe("URL to send the HTTP request to"),
|
|
@@ -2462,7 +2482,7 @@ var LinkButtonField = BaseField.extend({
|
|
|
2462
2482
|
}).describe("Button that opens a link");
|
|
2463
2483
|
var VerificationStatus = BaseField.extend({
|
|
2464
2484
|
type: import_zod17.z.literal(FieldType.VERIFICATION_STATUS),
|
|
2465
|
-
defaultValue: VerificationStatusValue.optional(),
|
|
2485
|
+
defaultValue: VerificationStatusValue.or(ComputedDefaultValue).optional(),
|
|
2466
2486
|
configuration: import_zod17.z.object({
|
|
2467
2487
|
status: TranslationConfig.describe("Text to display on the status pill."),
|
|
2468
2488
|
description: TranslationConfig.describe(
|
|
@@ -2480,7 +2500,7 @@ var QueryParamReaderField = BaseField.extend({
|
|
|
2480
2500
|
);
|
|
2481
2501
|
var QrReaderField = BaseField.extend({
|
|
2482
2502
|
type: import_zod17.z.literal(FieldType.QR_READER),
|
|
2483
|
-
defaultValue: QrReaderFieldValue.optional(),
|
|
2503
|
+
defaultValue: QrReaderFieldValue.or(ComputedDefaultValue).optional(),
|
|
2484
2504
|
configuration: import_zod17.z.object({
|
|
2485
2505
|
validator: import_zod17.z.custom(
|
|
2486
2506
|
(val) => typeof val === "object" && val !== null
|
|
@@ -2489,7 +2509,7 @@ var QrReaderField = BaseField.extend({
|
|
|
2489
2509
|
});
|
|
2490
2510
|
var IdReaderField = BaseField.extend({
|
|
2491
2511
|
type: import_zod17.z.literal(FieldType.ID_READER),
|
|
2492
|
-
defaultValue: IdReaderFieldValue.optional(),
|
|
2512
|
+
defaultValue: IdReaderFieldValue.or(ComputedDefaultValue).optional(),
|
|
2493
2513
|
methods: import_zod17.z.array(
|
|
2494
2514
|
import_zod17.z.union([QrReaderField, LinkButtonField]).describe("Methods for reading an ID")
|
|
2495
2515
|
)
|
|
@@ -3365,6 +3385,18 @@ function resolveDataPath(rootData, dataPath, instancePath) {
|
|
|
3365
3385
|
}
|
|
3366
3386
|
return current;
|
|
3367
3387
|
}
|
|
3388
|
+
function todayISO() {
|
|
3389
|
+
return (0, import_date_fns.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" });
|
|
3390
|
+
}
|
|
3391
|
+
var compiledFunctionCache = /* @__PURE__ */ new Map();
|
|
3392
|
+
function compileClientFunction(code) {
|
|
3393
|
+
let fn = compiledFunctionCache.get(code);
|
|
3394
|
+
if (!fn) {
|
|
3395
|
+
fn = new Function(`return (${code})`)();
|
|
3396
|
+
compiledFunctionCache.set(code, fn);
|
|
3397
|
+
}
|
|
3398
|
+
return fn;
|
|
3399
|
+
}
|
|
3368
3400
|
(0, import_ajv_formats.default)(ajv);
|
|
3369
3401
|
ajv.addKeyword({
|
|
3370
3402
|
keyword: "daysFromDate",
|
|
@@ -3410,7 +3442,7 @@ ajv.addKeyword({
|
|
|
3410
3442
|
$data: true,
|
|
3411
3443
|
errors: true,
|
|
3412
3444
|
// @ts-ignore -- Force type. We will move this away from AJV next. Parsing the array will take seconds and is only called by core.
|
|
3413
|
-
validate(
|
|
3445
|
+
validate(_schema, data, _2, dataContext) {
|
|
3414
3446
|
const locationIdInput = data;
|
|
3415
3447
|
const locations = dataContext?.rootData.$leafAdminStructureLocationIds ?? [];
|
|
3416
3448
|
return locations.some((location) => location.id === locationIdInput);
|
|
@@ -3419,6 +3451,15 @@ ajv.addKeyword({
|
|
|
3419
3451
|
function mergeWithBaseFormState(values, context) {
|
|
3420
3452
|
return { ...context.baseFormState, ...values };
|
|
3421
3453
|
}
|
|
3454
|
+
ajv.addKeyword({
|
|
3455
|
+
keyword: "customClientValidator",
|
|
3456
|
+
schemaType: "object",
|
|
3457
|
+
errors: true,
|
|
3458
|
+
// @ts-ignore -- DataContext is not typed in AJV's public API
|
|
3459
|
+
validate(schema, data, _2, dataContext) {
|
|
3460
|
+
return compileClientFunction(schema.code)(data, dataContext?.rootData);
|
|
3461
|
+
}
|
|
3462
|
+
});
|
|
3422
3463
|
function validate(schema, data) {
|
|
3423
3464
|
const validator = ajv.getSchema(schema.$id) || ajv.compile(schema);
|
|
3424
3465
|
if ("$form" in data) {
|
|
@@ -3462,7 +3503,7 @@ function isOnline() {
|
|
|
3462
3503
|
function isConditionMet(conditional, values, context) {
|
|
3463
3504
|
return validate(conditional, {
|
|
3464
3505
|
$form: mergeWithBaseFormState(values, context),
|
|
3465
|
-
$now: (
|
|
3506
|
+
$now: todayISO(),
|
|
3466
3507
|
$online: isOnline(),
|
|
3467
3508
|
$user: context.user,
|
|
3468
3509
|
$leafAdminStructureLocationIds: context.leafAdminStructureLocationIds ?? [],
|
|
@@ -3489,7 +3530,7 @@ function isFieldConditionMet(field3, form, conditionalType, context) {
|
|
|
3489
3530
|
}
|
|
3490
3531
|
const validConditionals = getConditionalActionsForField(field3, {
|
|
3491
3532
|
$form: mergeWithBaseFormState(form, context),
|
|
3492
|
-
$now: (
|
|
3533
|
+
$now: todayISO(),
|
|
3493
3534
|
$online: isOnline(),
|
|
3494
3535
|
$user: context.user,
|
|
3495
3536
|
$leafAdminStructureLocationIds: context.leafAdminStructureLocationIds ?? [],
|
|
@@ -3642,7 +3683,7 @@ function runFieldValidations({
|
|
|
3642
3683
|
}
|
|
3643
3684
|
const conditionalParameters = {
|
|
3644
3685
|
$form: mergeWithBaseFormState(form, context),
|
|
3645
|
-
$now: (
|
|
3686
|
+
$now: todayISO(),
|
|
3646
3687
|
/**
|
|
3647
3688
|
* In real use cases, there can be hundreds of thousands of locations.
|
|
3648
3689
|
* Make sure that the context contains only the locations that are needed for validation.
|
|
@@ -4097,20 +4138,16 @@ function getPendingAction(actions) {
|
|
|
4097
4138
|
}
|
|
4098
4139
|
return pendingActions[0];
|
|
4099
4140
|
}
|
|
4100
|
-
function getCompleteActionAnnotation(
|
|
4141
|
+
function getCompleteActionAnnotation(event2, action) {
|
|
4101
4142
|
if (action.originalActionId) {
|
|
4102
4143
|
const originalAction = event2.actions.find(
|
|
4103
4144
|
({ id }) => id === action.originalActionId
|
|
4104
4145
|
);
|
|
4105
|
-
if (originalAction?.status
|
|
4106
|
-
return annotation;
|
|
4146
|
+
if (originalAction?.status === ActionStatus.Requested) {
|
|
4147
|
+
return deepMerge(originalAction.annotation ?? {}, action.annotation ?? {});
|
|
4107
4148
|
}
|
|
4108
|
-
return deepMerge(
|
|
4109
|
-
deepMerge(annotation, originalAction.annotation ?? {}),
|
|
4110
|
-
action.annotation ?? {}
|
|
4111
|
-
);
|
|
4112
4149
|
}
|
|
4113
|
-
return
|
|
4150
|
+
return action.annotation ?? {};
|
|
4114
4151
|
}
|
|
4115
4152
|
function getCompleteActionDeclaration(declaration, event2, action) {
|
|
4116
4153
|
if (action.originalActionId) {
|
|
@@ -4130,7 +4167,7 @@ function getAcceptedActions(event2) {
|
|
|
4130
4167
|
return event2.actions.filter(isAcceptedAction).map((action) => ({
|
|
4131
4168
|
...action,
|
|
4132
4169
|
declaration: getCompleteActionDeclaration({}, event2, action),
|
|
4133
|
-
annotation: getCompleteActionAnnotation(
|
|
4170
|
+
annotation: getCompleteActionAnnotation(event2, action)
|
|
4134
4171
|
}));
|
|
4135
4172
|
}
|
|
4136
4173
|
var EXCLUDED_ACTIONS = [
|
|
@@ -4725,7 +4762,54 @@ function createFieldConditionals(fieldId) {
|
|
|
4725
4762
|
}
|
|
4726
4763
|
},
|
|
4727
4764
|
required: [fieldId]
|
|
4728
|
-
})
|
|
4765
|
+
}),
|
|
4766
|
+
/**
|
|
4767
|
+
* Custom client-side validator. The provided function is serialised and executed
|
|
4768
|
+
* just-in-time on the client only. External references (e.g. lodash) are not
|
|
4769
|
+
* available inside the function body — all logic must be self-contained.
|
|
4770
|
+
*
|
|
4771
|
+
* @example
|
|
4772
|
+
* field('nid').customClientValidator((value) => {
|
|
4773
|
+
* // LUHN check — all logic must be inline
|
|
4774
|
+
* const digits = String(value).split('').map(Number)
|
|
4775
|
+
* // ...
|
|
4776
|
+
* return isValid
|
|
4777
|
+
* })
|
|
4778
|
+
*/
|
|
4779
|
+
customClientValidator(validationFn) {
|
|
4780
|
+
const code = validationFn.toString();
|
|
4781
|
+
return defineFormConditional({
|
|
4782
|
+
type: "object",
|
|
4783
|
+
properties: wrapToPath(
|
|
4784
|
+
{ [fieldId]: { customClientValidator: { code } } },
|
|
4785
|
+
this.$$subfield
|
|
4786
|
+
),
|
|
4787
|
+
required: [fieldId]
|
|
4788
|
+
});
|
|
4789
|
+
},
|
|
4790
|
+
/**
|
|
4791
|
+
* Custom client-side evaluation. Returns a {@link FieldReference} descriptor
|
|
4792
|
+
* that can be used as the `value` property or a DATA component entry.
|
|
4793
|
+
* The function receives the referenced field's value as the first argument and
|
|
4794
|
+
* the full form context as the second; its return value replaces the field reference.
|
|
4795
|
+
* The function is serialised and executed just-in-time on the client only.
|
|
4796
|
+
* External references (e.g. lodash) are not available inside the function body.
|
|
4797
|
+
*
|
|
4798
|
+
* For computing a default value without referencing a specific field, use
|
|
4799
|
+
* `evaluate(fn)` in the `defaultValue` property instead.
|
|
4800
|
+
*
|
|
4801
|
+
* @example
|
|
4802
|
+
* field('a').customClientEvaluation((aValue, ctx) =>
|
|
4803
|
+
* Number(aValue) + Number(ctx.$form.b)
|
|
4804
|
+
* )
|
|
4805
|
+
*/
|
|
4806
|
+
customClientEvaluation(computationFn) {
|
|
4807
|
+
return {
|
|
4808
|
+
$$code: computationFn.toString(),
|
|
4809
|
+
$$field: fieldId,
|
|
4810
|
+
$$subfield: this.$$subfield
|
|
4811
|
+
};
|
|
4812
|
+
}
|
|
4729
4813
|
};
|
|
4730
4814
|
}
|
|
4731
4815
|
|
|
@@ -5878,7 +5962,7 @@ function getActionAnnotation({
|
|
|
5878
5962
|
const action = (0, import_lodash3.findLast)(activeActions, (a) => a.type === actionType);
|
|
5879
5963
|
const actionWithCompleteAnnotation = action && {
|
|
5880
5964
|
...action,
|
|
5881
|
-
annotation: getCompleteActionAnnotation(
|
|
5965
|
+
annotation: getCompleteActionAnnotation(event2, action)
|
|
5882
5966
|
};
|
|
5883
5967
|
const matchingDraft = draft?.action.type === actionType ? draft : void 0;
|
|
5884
5968
|
const sortedActions = (0, import_lodash3.orderBy)(
|
|
@@ -5920,6 +6004,9 @@ function createFieldConfig(fieldId, options) {
|
|
|
5920
6004
|
}
|
|
5921
6005
|
|
|
5922
6006
|
// ../commons/src/events/field.ts
|
|
6007
|
+
function evaluate(computationFn) {
|
|
6008
|
+
return { $$code: computationFn.toString() };
|
|
6009
|
+
}
|
|
5923
6010
|
function field(fieldId, options = {}) {
|
|
5924
6011
|
return {
|
|
5925
6012
|
...createFieldConditionals(fieldId),
|