@opencrvs/toolkit 1.9.13-rc.7fdf45e → 1.9.13-rc.8742682
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 +2489 -166
- package/dist/commons/conditionals/conditionals.d.ts +345 -2
- package/dist/commons/conditionals/validate.d.ts +9 -0
- package/dist/commons/events/ActionInput.d.ts +204 -0
- package/dist/commons/events/Draft.d.ts +6 -0
- package/dist/commons/events/EventConfig.d.ts +7 -0
- package/dist/commons/events/FieldConfig.d.ts +1489 -97
- 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 -170
- package/dist/conditionals/index.js +48 -1
- package/dist/events/index.js +143 -51
- package/dist/notification/index.js +115 -39
- 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"
|
|
@@ -2154,16 +2174,14 @@ var ParagraphConfiguration = import_zod17.z.object({
|
|
|
2154
2174
|
}).default({});
|
|
2155
2175
|
var Paragraph = BaseField.extend({
|
|
2156
2176
|
type: import_zod17.z.literal(FieldType.PARAGRAPH),
|
|
2157
|
-
defaultValue: NonEmptyTextValue.optional(),
|
|
2158
2177
|
configuration: ParagraphConfiguration
|
|
2159
2178
|
}).describe("A read-only HTML <p> paragraph");
|
|
2160
2179
|
var PageHeader = BaseField.extend({
|
|
2161
|
-
type: import_zod17.z.literal(FieldType.PAGE_HEADER)
|
|
2162
|
-
defaultValue: NonEmptyTextValue.optional()
|
|
2180
|
+
type: import_zod17.z.literal(FieldType.PAGE_HEADER)
|
|
2163
2181
|
}).describe("A read-only header component for form pages");
|
|
2164
2182
|
var File = BaseField.extend({
|
|
2165
2183
|
type: import_zod17.z.literal(FieldType.FILE),
|
|
2166
|
-
defaultValue: FileFieldValue.optional(),
|
|
2184
|
+
defaultValue: FileFieldValue.or(ComputedDefaultValue).optional(),
|
|
2167
2185
|
configuration: import_zod17.z.object({
|
|
2168
2186
|
maxFileSize: import_zod17.z.number().describe("Maximum file size in bytes").default(DEFAULT_MAX_FILE_SIZE_BYTES),
|
|
2169
2187
|
acceptedFileTypes: MimeType.array().optional().describe("List of allowed file formats for the signature"),
|
|
@@ -2187,7 +2205,7 @@ var SelectOption = import_zod17.z.object({
|
|
|
2187
2205
|
});
|
|
2188
2206
|
var NumberWithUnitField = BaseField.extend({
|
|
2189
2207
|
type: import_zod17.z.literal(FieldType.NUMBER_WITH_UNIT),
|
|
2190
|
-
defaultValue: NumberWithUnitFieldValue.optional(),
|
|
2208
|
+
defaultValue: NumberWithUnitFieldValue.or(ComputedDefaultValue).optional(),
|
|
2191
2209
|
options: import_zod17.z.array(SelectOption).describe("A list of options for the unit select"),
|
|
2192
2210
|
configuration: import_zod17.z.object({
|
|
2193
2211
|
min: import_zod17.z.number().optional().describe("Minimum value of the number field"),
|
|
@@ -2199,7 +2217,7 @@ var NumberWithUnitField = BaseField.extend({
|
|
|
2199
2217
|
}).describe("Number with unit input");
|
|
2200
2218
|
var RadioGroup = BaseField.extend({
|
|
2201
2219
|
type: import_zod17.z.literal(FieldType.RADIO_GROUP),
|
|
2202
|
-
defaultValue: TextValue.optional(),
|
|
2220
|
+
defaultValue: TextValue.or(ComputedDefaultValue).optional(),
|
|
2203
2221
|
options: import_zod17.z.array(SelectOption).describe("A list of options"),
|
|
2204
2222
|
configuration: import_zod17.z.object({
|
|
2205
2223
|
styles: import_zod17.z.object({
|
|
@@ -2209,7 +2227,6 @@ var RadioGroup = BaseField.extend({
|
|
|
2209
2227
|
}).describe("Grouped radio options");
|
|
2210
2228
|
var BulletList = BaseField.extend({
|
|
2211
2229
|
type: import_zod17.z.literal(FieldType.BULLET_LIST),
|
|
2212
|
-
defaultValue: TextValue.optional(),
|
|
2213
2230
|
items: import_zod17.z.array(TranslationConfig).describe("A list of items"),
|
|
2214
2231
|
configuration: import_zod17.z.object({
|
|
2215
2232
|
styles: import_zod17.z.object({
|
|
@@ -2219,7 +2236,7 @@ var BulletList = BaseField.extend({
|
|
|
2219
2236
|
}).describe("A list of bullet points");
|
|
2220
2237
|
var Select = BaseField.extend({
|
|
2221
2238
|
type: import_zod17.z.literal(FieldType.SELECT),
|
|
2222
|
-
defaultValue: TextValue.optional(),
|
|
2239
|
+
defaultValue: TextValue.or(ComputedDefaultValue).optional(),
|
|
2223
2240
|
options: import_zod17.z.array(SelectOption).describe("A list of options"),
|
|
2224
2241
|
noOptionsMessage: TranslationConfig.optional().describe(
|
|
2225
2242
|
`
|
|
@@ -2238,7 +2255,7 @@ var SelectDateRangeOption = import_zod17.z.object({
|
|
|
2238
2255
|
});
|
|
2239
2256
|
var SelectDateRangeField = BaseField.extend({
|
|
2240
2257
|
type: import_zod17.z.literal(FieldType.SELECT_DATE_RANGE),
|
|
2241
|
-
defaultValue: SelectDateRangeValue.optional(),
|
|
2258
|
+
defaultValue: SelectDateRangeValue.or(ComputedDefaultValue).optional(),
|
|
2242
2259
|
options: import_zod17.z.array(SelectDateRangeOption).describe("A list of options")
|
|
2243
2260
|
}).describe("Select input with date range options");
|
|
2244
2261
|
var NameConfig = import_zod17.z.object({
|
|
@@ -2252,7 +2269,7 @@ var NameField = BaseField.extend({
|
|
|
2252
2269
|
firstname: SerializedUserField.or(NonEmptyTextValue).optional(),
|
|
2253
2270
|
middlename: SerializedUserField.or(NonEmptyTextValue).optional(),
|
|
2254
2271
|
surname: SerializedUserField.or(NonEmptyTextValue).optional()
|
|
2255
|
-
}).optional(),
|
|
2272
|
+
}).or(ComputedDefaultValue).optional(),
|
|
2256
2273
|
configuration: import_zod17.z.object({
|
|
2257
2274
|
name: NameConfig.default({
|
|
2258
2275
|
firstname: { required: true },
|
|
@@ -2273,20 +2290,20 @@ var NameField = BaseField.extend({
|
|
|
2273
2290
|
}).optional()
|
|
2274
2291
|
}).describe("Name input field");
|
|
2275
2292
|
var PhoneField = BaseField.extend({
|
|
2276
|
-
defaultValue: NonEmptyTextValue.optional(),
|
|
2293
|
+
defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional(),
|
|
2277
2294
|
type: import_zod17.z.literal(FieldType.PHONE)
|
|
2278
2295
|
}).describe("Phone input field");
|
|
2279
2296
|
var IdField = BaseField.extend({
|
|
2280
|
-
defaultValue: NonEmptyTextValue.optional(),
|
|
2297
|
+
defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional(),
|
|
2281
2298
|
type: import_zod17.z.literal(FieldType.ID)
|
|
2282
2299
|
}).describe("ID input field");
|
|
2283
2300
|
var Checkbox = BaseField.extend({
|
|
2284
2301
|
type: import_zod17.z.literal(FieldType.CHECKBOX),
|
|
2285
|
-
defaultValue: CheckboxFieldValue.default(false)
|
|
2302
|
+
defaultValue: CheckboxFieldValue.or(ComputedDefaultValue).default(false)
|
|
2286
2303
|
}).describe("Boolean checkbox field");
|
|
2287
2304
|
var Country = BaseField.extend({
|
|
2288
2305
|
type: import_zod17.z.literal(FieldType.COUNTRY),
|
|
2289
|
-
defaultValue: NonEmptyTextValue.optional(),
|
|
2306
|
+
defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional(),
|
|
2290
2307
|
optionOverrides: import_zod17.z.array(SelectOption.omit({ label: true })).optional().describe(
|
|
2291
2308
|
"Conditionals for specific countries. Countries not listed are always shown and enabled."
|
|
2292
2309
|
)
|
|
@@ -2302,12 +2319,12 @@ var AdministrativeAreaConfiguration = import_zod17.z.object({
|
|
|
2302
2319
|
}).describe("Administrative area options");
|
|
2303
2320
|
var AdministrativeArea = BaseField.extend({
|
|
2304
2321
|
type: import_zod17.z.literal(FieldType.ADMINISTRATIVE_AREA),
|
|
2305
|
-
defaultValue: import_zod17.z.union([NonEmptyTextValue, SerializedUserField]).optional(),
|
|
2322
|
+
defaultValue: import_zod17.z.union([NonEmptyTextValue, SerializedUserField, ComputedDefaultValue]).optional(),
|
|
2306
2323
|
configuration: AdministrativeAreaConfiguration
|
|
2307
2324
|
}).describe("Administrative area input field e.g. facility, office");
|
|
2308
2325
|
var LocationInput = BaseField.extend({
|
|
2309
2326
|
type: import_zod17.z.literal(FieldType.LOCATION),
|
|
2310
|
-
defaultValue: NonEmptyTextValue.optional(),
|
|
2327
|
+
defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional(),
|
|
2311
2328
|
configuration: import_zod17.z.object({
|
|
2312
2329
|
searchableResource: import_zod17.z.array(import_zod17.z.enum(["locations", "facilities", "offices"]))
|
|
2313
2330
|
})
|
|
@@ -2315,7 +2332,7 @@ var LocationInput = BaseField.extend({
|
|
|
2315
2332
|
var FileUploadWithOptions = BaseField.extend({
|
|
2316
2333
|
type: import_zod17.z.literal(FieldType.FILE_WITH_OPTIONS),
|
|
2317
2334
|
options: import_zod17.z.array(SelectOption).describe("A list of options"),
|
|
2318
|
-
defaultValue: FileFieldWithOptionValue.optional(),
|
|
2335
|
+
defaultValue: FileFieldWithOptionValue.or(ComputedDefaultValue).optional(),
|
|
2319
2336
|
configuration: import_zod17.z.object({
|
|
2320
2337
|
maxFileSize: import_zod17.z.number().describe("Maximum file size in bytes").default(DEFAULT_MAX_FILE_SIZE_BYTES),
|
|
2321
2338
|
maxImageSize: import_zod17.z.object({
|
|
@@ -2328,11 +2345,11 @@ var FileUploadWithOptions = BaseField.extend({
|
|
|
2328
2345
|
});
|
|
2329
2346
|
var Facility = BaseField.extend({
|
|
2330
2347
|
type: import_zod17.z.literal(FieldType.FACILITY),
|
|
2331
|
-
defaultValue: NonEmptyTextValue.optional()
|
|
2348
|
+
defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional()
|
|
2332
2349
|
}).describe("Input field for a facility");
|
|
2333
2350
|
var Office = BaseField.extend({
|
|
2334
2351
|
type: import_zod17.z.literal(FieldType.OFFICE),
|
|
2335
|
-
defaultValue: NonEmptyTextValue.optional()
|
|
2352
|
+
defaultValue: NonEmptyTextValue.or(ComputedDefaultValue).optional()
|
|
2336
2353
|
}).describe("Input field for an office");
|
|
2337
2354
|
var DefaultAddressFieldValue = DomesticAddressFieldValue.extend({
|
|
2338
2355
|
administrativeArea: import_zod17.z.union([UUID, SerializedUserField]).optional()
|
|
@@ -2366,7 +2383,7 @@ var Address = BaseField.extend({
|
|
|
2366
2383
|
})
|
|
2367
2384
|
).optional()
|
|
2368
2385
|
}).optional(),
|
|
2369
|
-
defaultValue: DefaultAddressFieldValue.optional()
|
|
2386
|
+
defaultValue: DefaultAddressFieldValue.or(ComputedDefaultValue).optional()
|
|
2370
2387
|
}).describe("Address input field \u2013 a combination of location and text fields");
|
|
2371
2388
|
var StaticDataEntry = import_zod17.z.object({
|
|
2372
2389
|
id: import_zod17.z.string().describe("ID for the data entry."),
|
|
@@ -2385,7 +2402,7 @@ var DataField = BaseField.extend({
|
|
|
2385
2402
|
}).describe("Data field for displaying read-only data");
|
|
2386
2403
|
var ButtonField = BaseField.extend({
|
|
2387
2404
|
type: import_zod17.z.literal(FieldType.BUTTON),
|
|
2388
|
-
defaultValue: ButtonFieldValue.optional(),
|
|
2405
|
+
defaultValue: ButtonFieldValue.or(ComputedDefaultValue).optional(),
|
|
2389
2406
|
configuration: import_zod17.z.object({
|
|
2390
2407
|
icon: import_zod17.z.string().optional().describe(
|
|
2391
2408
|
"Icon for the button. You can find icons from OpenCRVS UI-Kit."
|
|
@@ -2410,7 +2427,7 @@ var AlphaPrintButton = BaseField.extend({
|
|
|
2410
2427
|
}).describe("Print button field for printing certificates");
|
|
2411
2428
|
var HttpField = BaseField.extend({
|
|
2412
2429
|
type: import_zod17.z.literal(FieldType.HTTP),
|
|
2413
|
-
defaultValue: HttpFieldValue.optional(),
|
|
2430
|
+
defaultValue: HttpFieldValue.or(ComputedDefaultValue).optional(),
|
|
2414
2431
|
configuration: import_zod17.z.object({
|
|
2415
2432
|
trigger: FieldReference,
|
|
2416
2433
|
url: import_zod17.z.string().describe("URL to send the HTTP request to"),
|
|
@@ -2465,7 +2482,7 @@ var LinkButtonField = BaseField.extend({
|
|
|
2465
2482
|
}).describe("Button that opens a link");
|
|
2466
2483
|
var VerificationStatus = BaseField.extend({
|
|
2467
2484
|
type: import_zod17.z.literal(FieldType.VERIFICATION_STATUS),
|
|
2468
|
-
defaultValue: VerificationStatusValue.optional(),
|
|
2485
|
+
defaultValue: VerificationStatusValue.or(ComputedDefaultValue).optional(),
|
|
2469
2486
|
configuration: import_zod17.z.object({
|
|
2470
2487
|
status: TranslationConfig.describe("Text to display on the status pill."),
|
|
2471
2488
|
description: TranslationConfig.describe(
|
|
@@ -2483,7 +2500,7 @@ var QueryParamReaderField = BaseField.extend({
|
|
|
2483
2500
|
);
|
|
2484
2501
|
var QrReaderField = BaseField.extend({
|
|
2485
2502
|
type: import_zod17.z.literal(FieldType.QR_READER),
|
|
2486
|
-
defaultValue: QrReaderFieldValue.optional(),
|
|
2503
|
+
defaultValue: QrReaderFieldValue.or(ComputedDefaultValue).optional(),
|
|
2487
2504
|
configuration: import_zod17.z.object({
|
|
2488
2505
|
validator: import_zod17.z.custom(
|
|
2489
2506
|
(val) => typeof val === "object" && val !== null
|
|
@@ -2492,7 +2509,7 @@ var QrReaderField = BaseField.extend({
|
|
|
2492
2509
|
});
|
|
2493
2510
|
var IdReaderField = BaseField.extend({
|
|
2494
2511
|
type: import_zod17.z.literal(FieldType.ID_READER),
|
|
2495
|
-
defaultValue: IdReaderFieldValue.optional(),
|
|
2512
|
+
defaultValue: IdReaderFieldValue.or(ComputedDefaultValue).optional(),
|
|
2496
2513
|
methods: import_zod17.z.array(
|
|
2497
2514
|
import_zod17.z.union([QrReaderField, LinkButtonField]).describe("Methods for reading an ID")
|
|
2498
2515
|
)
|
|
@@ -3368,6 +3385,18 @@ function resolveDataPath(rootData, dataPath, instancePath) {
|
|
|
3368
3385
|
}
|
|
3369
3386
|
return current;
|
|
3370
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
|
+
}
|
|
3371
3400
|
(0, import_ajv_formats.default)(ajv);
|
|
3372
3401
|
ajv.addKeyword({
|
|
3373
3402
|
keyword: "daysFromDate",
|
|
@@ -3413,12 +3442,24 @@ ajv.addKeyword({
|
|
|
3413
3442
|
$data: true,
|
|
3414
3443
|
errors: true,
|
|
3415
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.
|
|
3416
|
-
validate(
|
|
3445
|
+
validate(_schema, data, _2, dataContext) {
|
|
3417
3446
|
const locationIdInput = data;
|
|
3418
3447
|
const locations = dataContext?.rootData.$leafAdminStructureLocationIds ?? [];
|
|
3419
3448
|
return locations.some((location) => location.id === locationIdInput);
|
|
3420
3449
|
}
|
|
3421
3450
|
});
|
|
3451
|
+
function mergeWithBaseFormState(values, context) {
|
|
3452
|
+
return { ...context.baseFormState, ...values };
|
|
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) {
|
|
@@ -3461,8 +3502,8 @@ function isOnline() {
|
|
|
3461
3502
|
}
|
|
3462
3503
|
function isConditionMet(conditional, values, context) {
|
|
3463
3504
|
return validate(conditional, {
|
|
3464
|
-
$form: values,
|
|
3465
|
-
$now: (
|
|
3505
|
+
$form: mergeWithBaseFormState(values, context),
|
|
3506
|
+
$now: todayISO(),
|
|
3466
3507
|
$online: isOnline(),
|
|
3467
3508
|
$user: context.user,
|
|
3468
3509
|
$leafAdminStructureLocationIds: context.leafAdminStructureLocationIds ?? [],
|
|
@@ -3488,8 +3529,8 @@ function isFieldConditionMet(field3, form, conditionalType, context) {
|
|
|
3488
3529
|
return true;
|
|
3489
3530
|
}
|
|
3490
3531
|
const validConditionals = getConditionalActionsForField(field3, {
|
|
3491
|
-
$form: form,
|
|
3492
|
-
$now: (
|
|
3532
|
+
$form: mergeWithBaseFormState(form, context),
|
|
3533
|
+
$now: todayISO(),
|
|
3493
3534
|
$online: isOnline(),
|
|
3494
3535
|
$user: context.user,
|
|
3495
3536
|
$leafAdminStructureLocationIds: context.leafAdminStructureLocationIds ?? [],
|
|
@@ -3641,8 +3682,8 @@ function runFieldValidations({
|
|
|
3641
3682
|
return [];
|
|
3642
3683
|
}
|
|
3643
3684
|
const conditionalParameters = {
|
|
3644
|
-
$form: form,
|
|
3645
|
-
$now: (
|
|
3685
|
+
$form: mergeWithBaseFormState(form, context),
|
|
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.
|
|
@@ -3873,7 +3914,7 @@ function omitHiddenPaginatedFields(formConfig, values, validatorContext, include
|
|
|
3873
3914
|
const visibleFields = formConfig.pages.filter((p) => isPageVisible(p, values, validatorContext)).flatMap((p) => p.fields);
|
|
3874
3915
|
const hiddenFields = formConfig.pages.filter((p) => !isPageVisible(p, values, validatorContext)).flatMap((p) => p.fields);
|
|
3875
3916
|
const valuesExceptHiddenPage = (0, import_lodash.omitBy)(values, (_2, fieldId) => {
|
|
3876
|
-
return hiddenFields.some((f) => f.id === fieldId);
|
|
3917
|
+
return hiddenFields.some((f) => f.id === fieldId) && !visibleFields.some((f) => f.id === fieldId);
|
|
3877
3918
|
});
|
|
3878
3919
|
return omitHiddenFields(
|
|
3879
3920
|
visibleFields,
|
|
@@ -3920,11 +3961,10 @@ function getVisibleVerificationPageIds(pages, annotation, context) {
|
|
|
3920
3961
|
}
|
|
3921
3962
|
function omitHiddenAnnotationFields(actionConfig, declaration, annotation, context) {
|
|
3922
3963
|
const annotationFields = getActionAnnotationFields(actionConfig);
|
|
3923
|
-
return omitHiddenFields(
|
|
3924
|
-
|
|
3925
|
-
|
|
3926
|
-
|
|
3927
|
-
);
|
|
3964
|
+
return omitHiddenFields(annotationFields, annotation, {
|
|
3965
|
+
...context,
|
|
3966
|
+
baseFormState: declaration
|
|
3967
|
+
});
|
|
3928
3968
|
}
|
|
3929
3969
|
function deepMerge(currentDocument, actionDocument) {
|
|
3930
3970
|
const currentDocumentClone = (0, import_lodash.cloneDeep)(currentDocument);
|
|
@@ -4726,7 +4766,54 @@ function createFieldConditionals(fieldId) {
|
|
|
4726
4766
|
}
|
|
4727
4767
|
},
|
|
4728
4768
|
required: [fieldId]
|
|
4729
|
-
})
|
|
4769
|
+
}),
|
|
4770
|
+
/**
|
|
4771
|
+
* Custom client-side validator. The provided function is serialised and executed
|
|
4772
|
+
* just-in-time on the client only. External references (e.g. lodash) are not
|
|
4773
|
+
* available inside the function body — all logic must be self-contained.
|
|
4774
|
+
*
|
|
4775
|
+
* @example
|
|
4776
|
+
* field('nid').customClientValidator((value) => {
|
|
4777
|
+
* // LUHN check — all logic must be inline
|
|
4778
|
+
* const digits = String(value).split('').map(Number)
|
|
4779
|
+
* // ...
|
|
4780
|
+
* return isValid
|
|
4781
|
+
* })
|
|
4782
|
+
*/
|
|
4783
|
+
customClientValidator(validationFn) {
|
|
4784
|
+
const code = validationFn.toString();
|
|
4785
|
+
return defineFormConditional({
|
|
4786
|
+
type: "object",
|
|
4787
|
+
properties: wrapToPath(
|
|
4788
|
+
{ [fieldId]: { customClientValidator: { code } } },
|
|
4789
|
+
this.$$subfield
|
|
4790
|
+
),
|
|
4791
|
+
required: [fieldId]
|
|
4792
|
+
});
|
|
4793
|
+
},
|
|
4794
|
+
/**
|
|
4795
|
+
* Custom client-side evaluation. Returns a {@link FieldReference} descriptor
|
|
4796
|
+
* that can be used as the `value` property or a DATA component entry.
|
|
4797
|
+
* The function receives the referenced field's value as the first argument and
|
|
4798
|
+
* the full form context as the second; its return value replaces the field reference.
|
|
4799
|
+
* The function is serialised and executed just-in-time on the client only.
|
|
4800
|
+
* External references (e.g. lodash) are not available inside the function body.
|
|
4801
|
+
*
|
|
4802
|
+
* For computing a default value without referencing a specific field, use
|
|
4803
|
+
* `evaluate(fn)` in the `defaultValue` property instead.
|
|
4804
|
+
*
|
|
4805
|
+
* @example
|
|
4806
|
+
* field('a').customClientEvaluation((aValue, ctx) =>
|
|
4807
|
+
* Number(aValue) + Number(ctx.$form.b)
|
|
4808
|
+
* )
|
|
4809
|
+
*/
|
|
4810
|
+
customClientEvaluation(computationFn) {
|
|
4811
|
+
return {
|
|
4812
|
+
$$code: computationFn.toString(),
|
|
4813
|
+
$$field: fieldId,
|
|
4814
|
+
$$subfield: this.$$subfield
|
|
4815
|
+
};
|
|
4816
|
+
}
|
|
4730
4817
|
};
|
|
4731
4818
|
}
|
|
4732
4819
|
|
|
@@ -5307,6 +5394,8 @@ var BaseActionInput = import_zod34.z.object({
|
|
|
5307
5394
|
originalActionId: UUID.optional(),
|
|
5308
5395
|
// should not be part of base action.
|
|
5309
5396
|
keepAssignment: import_zod34.z.boolean().optional(),
|
|
5397
|
+
keepAssignmentIfAccepted: import_zod34.z.boolean().optional(),
|
|
5398
|
+
keepAssignmentIfRejected: import_zod34.z.boolean().optional(),
|
|
5310
5399
|
// For normal users, the createdAtLocation is resolved on the backend from the user's primaryOfficeId.
|
|
5311
5400
|
createdAtLocation: CreatedAtLocation.describe(
|
|
5312
5401
|
"A valid office location ID. This is required for system users performing actions. The provided location must be a leaf-location, i.e. it must not have any children locations."
|
|
@@ -5919,6 +6008,9 @@ function createFieldConfig(fieldId, options) {
|
|
|
5919
6008
|
}
|
|
5920
6009
|
|
|
5921
6010
|
// ../commons/src/events/field.ts
|
|
6011
|
+
function evaluate(computationFn) {
|
|
6012
|
+
return { $$code: computationFn.toString() };
|
|
6013
|
+
}
|
|
5922
6014
|
function field(fieldId, options = {}) {
|
|
5923
6015
|
return {
|
|
5924
6016
|
...createFieldConditionals(fieldId),
|