@opencrvs/toolkit 1.9.13-rc.f05e2b4 → 1.9.13-rc.f568f39
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 +2488 -166
- package/dist/commons/conditionals/conditionals.d.ts +1 -292
- package/dist/commons/conditionals/validate.d.ts +1 -8
- package/dist/commons/events/ActionInput.d.ts +204 -0
- package/dist/commons/events/Draft.d.ts +6 -0
- package/dist/commons/events/FieldConfig.d.ts +261 -3359
- package/dist/commons/events/field.d.ts +0 -22
- package/dist/commons/events/utils.d.ts +2 -171
- package/dist/conditionals/index.js +1 -2028
- package/dist/events/index.js +26 -115
- package/dist/notification/index.js +9 -82
- package/package.json +7 -7
package/dist/events/index.js
CHANGED
|
@@ -69,7 +69,6 @@ __export(events_exports, {
|
|
|
69
69
|
CheckboxFieldValue: () => CheckboxFieldValue,
|
|
70
70
|
Clause: () => Clause,
|
|
71
71
|
ClientSpecificAction: () => ClientSpecificAction,
|
|
72
|
-
CodeToEvaluate: () => CodeToEvaluate,
|
|
73
72
|
Conditional: () => Conditional,
|
|
74
73
|
ConditionalType: () => ConditionalType,
|
|
75
74
|
ConfirmableActions: () => ConfirmableActions,
|
|
@@ -230,7 +229,6 @@ __export(events_exports, {
|
|
|
230
229
|
areConditionsMet: () => areConditionsMet,
|
|
231
230
|
buildFormState: () => buildFormState,
|
|
232
231
|
canUserReadEvent: () => canUserReadEvent,
|
|
233
|
-
compileClientFunction: () => compileClientFunction,
|
|
234
232
|
compositeFieldTypes: () => compositeFieldTypes,
|
|
235
233
|
configurableEventScopeAllowed: () => configurableEventScopeAllowed,
|
|
236
234
|
createEmptyDraft: () => createEmptyDraft,
|
|
@@ -315,7 +313,6 @@ __export(events_exports, {
|
|
|
315
313
|
isBulletListFieldType: () => isBulletListFieldType,
|
|
316
314
|
isButtonFieldType: () => isButtonFieldType,
|
|
317
315
|
isCheckboxFieldType: () => isCheckboxFieldType,
|
|
318
|
-
isCodeToEvaluate: () => isCodeToEvaluate,
|
|
319
316
|
isConditionMet: () => isConditionMet,
|
|
320
317
|
isCountryFieldType: () => isCountryFieldType,
|
|
321
318
|
isDataFieldType: () => isDataFieldType,
|
|
@@ -356,7 +353,6 @@ __export(events_exports, {
|
|
|
356
353
|
isQrReaderFieldType: () => isQrReaderFieldType,
|
|
357
354
|
isQueryParamReaderFieldType: () => isQueryParamReaderFieldType,
|
|
358
355
|
isRadioGroupFieldType: () => isRadioGroupFieldType,
|
|
359
|
-
isResolvableValueReference: () => isResolvableValueReference,
|
|
360
356
|
isSearchFieldType: () => isSearchFieldType,
|
|
361
357
|
isSelectDateRangeFieldType: () => isSelectDateRangeFieldType,
|
|
362
358
|
isSelectFieldType: () => isSelectFieldType,
|
|
@@ -387,7 +383,6 @@ __export(events_exports, {
|
|
|
387
383
|
runStructuralValidations: () => runStructuralValidations,
|
|
388
384
|
safeUnion: () => safeUnion,
|
|
389
385
|
timePeriodToDateRange: () => timePeriodToDateRange,
|
|
390
|
-
todayISO: () => todayISO,
|
|
391
386
|
user: () => user,
|
|
392
387
|
validate: () => validate,
|
|
393
388
|
validateFieldInput: () => validateFieldInput,
|
|
@@ -1992,18 +1987,6 @@ var FieldReference = import_zod17.z.object({
|
|
|
1992
1987
|
'If the FieldValue is an object, subfield can be used to refer to e.g. `["foo", "bar"]` in `{ foo: { bar: 3 } }`'
|
|
1993
1988
|
)
|
|
1994
1989
|
}).describe("Reference to a field by its ID");
|
|
1995
|
-
var CodeToEvaluate = import_zod17.z.object({
|
|
1996
|
-
$$code: import_zod17.z.string().describe("Serialised client-side function body"),
|
|
1997
|
-
$$field: FieldId.describe(
|
|
1998
|
-
"Field whose value is passed as the first argument"
|
|
1999
|
-
),
|
|
2000
|
-
$$subfield: import_zod17.z.array(import_zod17.z.string()).optional().default([]).describe("Optional nested path within the field value")
|
|
2001
|
-
}).describe(
|
|
2002
|
-
"Serialised client-side evaluation function. Executed just-in-time on the client only."
|
|
2003
|
-
);
|
|
2004
|
-
function isCodeToEvaluate(v) {
|
|
2005
|
-
return !!v && typeof v === "object" && "$$code" in v;
|
|
2006
|
-
}
|
|
2007
1990
|
var ValidationConfig = import_zod17.z.object({
|
|
2008
1991
|
validator: Conditional,
|
|
2009
1992
|
message: TranslationConfig
|
|
@@ -2036,11 +2019,8 @@ var BaseField = import_zod17.z.object({
|
|
|
2036
2019
|
uncorrectable: import_zod17.z.boolean().default(false).optional().describe(
|
|
2037
2020
|
"Indicates whether the field can be modified during record correction."
|
|
2038
2021
|
),
|
|
2039
|
-
value: FieldReference.or(
|
|
2040
|
-
"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.
|
|
2041
|
-
),
|
|
2042
|
-
evaluatedDefaultValue: CodeToEvaluate.optional().describe(
|
|
2043
|
-
"Custom client-side function used to compute the default value. Executed just-in-time on the client. Takes precedence over defaultValue when set."
|
|
2022
|
+
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."
|
|
2044
2024
|
),
|
|
2045
2025
|
analytics: import_zod17.z.boolean().default(false).optional().describe(
|
|
2046
2026
|
"Indicates whether the field is included in analytics. When enabled, its value becomes available in the analytics dashboard."
|
|
@@ -2174,12 +2154,10 @@ var ParagraphConfiguration = import_zod17.z.object({
|
|
|
2174
2154
|
}).default({});
|
|
2175
2155
|
var Paragraph = BaseField.extend({
|
|
2176
2156
|
type: import_zod17.z.literal(FieldType.PARAGRAPH),
|
|
2177
|
-
defaultValue: NonEmptyTextValue.optional(),
|
|
2178
2157
|
configuration: ParagraphConfiguration
|
|
2179
2158
|
}).describe("A read-only HTML <p> paragraph");
|
|
2180
2159
|
var PageHeader = BaseField.extend({
|
|
2181
|
-
type: import_zod17.z.literal(FieldType.PAGE_HEADER)
|
|
2182
|
-
defaultValue: NonEmptyTextValue.optional()
|
|
2160
|
+
type: import_zod17.z.literal(FieldType.PAGE_HEADER)
|
|
2183
2161
|
}).describe("A read-only header component for form pages");
|
|
2184
2162
|
var File = BaseField.extend({
|
|
2185
2163
|
type: import_zod17.z.literal(FieldType.FILE),
|
|
@@ -2229,7 +2207,6 @@ var RadioGroup = BaseField.extend({
|
|
|
2229
2207
|
}).describe("Grouped radio options");
|
|
2230
2208
|
var BulletList = BaseField.extend({
|
|
2231
2209
|
type: import_zod17.z.literal(FieldType.BULLET_LIST),
|
|
2232
|
-
defaultValue: TextValue.optional(),
|
|
2233
2210
|
items: import_zod17.z.array(TranslationConfig).describe("A list of items"),
|
|
2234
2211
|
configuration: import_zod17.z.object({
|
|
2235
2212
|
styles: import_zod17.z.object({
|
|
@@ -2391,7 +2368,7 @@ var Address = BaseField.extend({
|
|
|
2391
2368
|
var StaticDataEntry = import_zod17.z.object({
|
|
2392
2369
|
id: import_zod17.z.string().describe("ID for the data entry."),
|
|
2393
2370
|
label: TranslationConfig,
|
|
2394
|
-
value: TranslationConfig.or(import_zod17.z.string()).or(FieldReference)
|
|
2371
|
+
value: TranslationConfig.or(import_zod17.z.string()).or(FieldReference)
|
|
2395
2372
|
}).describe("Static data entry");
|
|
2396
2373
|
var DataEntry = import_zod17.z.union([StaticDataEntry, import_zod17.z.object({ fieldId: import_zod17.z.string() })]).describe(
|
|
2397
2374
|
"Data entry can be either a static data entry, or a reference to another field in the current form or the declaration."
|
|
@@ -2438,7 +2415,7 @@ var HttpField = BaseField.extend({
|
|
|
2438
2415
|
headers: import_zod17.z.record(import_zod17.z.string()).optional(),
|
|
2439
2416
|
body: import_zod17.z.record(import_zod17.z.any()).optional(),
|
|
2440
2417
|
errorValue: import_zod17.z.any().optional().describe("Value to set if the request fails"),
|
|
2441
|
-
params: import_zod17.z.record(import_zod17.z.string(), import_zod17.z.union([import_zod17.z.string(), FieldReference
|
|
2418
|
+
params: import_zod17.z.record(import_zod17.z.string(), import_zod17.z.union([import_zod17.z.string(), FieldReference])).optional(),
|
|
2442
2419
|
timeout: import_zod17.z.number().default(15e3).describe("Request timeout in milliseconds")
|
|
2443
2420
|
})
|
|
2444
2421
|
}).describe("HTTP request function triggered by a button click or other event");
|
|
@@ -3388,18 +3365,6 @@ function resolveDataPath(rootData, dataPath, instancePath) {
|
|
|
3388
3365
|
}
|
|
3389
3366
|
return current;
|
|
3390
3367
|
}
|
|
3391
|
-
function todayISO() {
|
|
3392
|
-
return (0, import_date_fns.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" });
|
|
3393
|
-
}
|
|
3394
|
-
var compiledFunctionCache = /* @__PURE__ */ new Map();
|
|
3395
|
-
function compileClientFunction(code) {
|
|
3396
|
-
let fn = compiledFunctionCache.get(code);
|
|
3397
|
-
if (!fn) {
|
|
3398
|
-
fn = new Function(`return (${code})`)();
|
|
3399
|
-
compiledFunctionCache.set(code, fn);
|
|
3400
|
-
}
|
|
3401
|
-
return fn;
|
|
3402
|
-
}
|
|
3403
3368
|
(0, import_ajv_formats.default)(ajv);
|
|
3404
3369
|
ajv.addKeyword({
|
|
3405
3370
|
keyword: "daysFromDate",
|
|
@@ -3445,21 +3410,15 @@ ajv.addKeyword({
|
|
|
3445
3410
|
$data: true,
|
|
3446
3411
|
errors: true,
|
|
3447
3412
|
// @ts-ignore -- Force type. We will move this away from AJV next. Parsing the array will take seconds and is only called by core.
|
|
3448
|
-
validate(
|
|
3413
|
+
validate(schema, data, _2, dataContext) {
|
|
3449
3414
|
const locationIdInput = data;
|
|
3450
3415
|
const locations = dataContext?.rootData.$leafAdminStructureLocationIds ?? [];
|
|
3451
3416
|
return locations.some((location) => location.id === locationIdInput);
|
|
3452
3417
|
}
|
|
3453
3418
|
});
|
|
3454
|
-
|
|
3455
|
-
|
|
3456
|
-
|
|
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
|
-
});
|
|
3419
|
+
function mergeWithBaseFormState(values, context) {
|
|
3420
|
+
return { ...context.baseFormState, ...values };
|
|
3421
|
+
}
|
|
3463
3422
|
function validate(schema, data) {
|
|
3464
3423
|
const validator = ajv.getSchema(schema.$id) || ajv.compile(schema);
|
|
3465
3424
|
if ("$form" in data) {
|
|
@@ -3502,7 +3461,7 @@ function isOnline() {
|
|
|
3502
3461
|
}
|
|
3503
3462
|
function isConditionMet(conditional, values, context) {
|
|
3504
3463
|
return validate(conditional, {
|
|
3505
|
-
$form: values,
|
|
3464
|
+
$form: mergeWithBaseFormState(values, context),
|
|
3506
3465
|
$now: (0, import_date_fns.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" }),
|
|
3507
3466
|
$online: isOnline(),
|
|
3508
3467
|
$user: context.user,
|
|
@@ -3529,7 +3488,7 @@ function isFieldConditionMet(field3, form, conditionalType, context) {
|
|
|
3529
3488
|
return true;
|
|
3530
3489
|
}
|
|
3531
3490
|
const validConditionals = getConditionalActionsForField(field3, {
|
|
3532
|
-
$form: form,
|
|
3491
|
+
$form: mergeWithBaseFormState(form, context),
|
|
3533
3492
|
$now: (0, import_date_fns.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" }),
|
|
3534
3493
|
$online: isOnline(),
|
|
3535
3494
|
$user: context.user,
|
|
@@ -3682,7 +3641,7 @@ function runFieldValidations({
|
|
|
3682
3641
|
return [];
|
|
3683
3642
|
}
|
|
3684
3643
|
const conditionalParameters = {
|
|
3685
|
-
$form: form,
|
|
3644
|
+
$form: mergeWithBaseFormState(form, context),
|
|
3686
3645
|
$now: (0, import_date_fns.formatISO)(/* @__PURE__ */ new Date(), { representation: "date" }),
|
|
3687
3646
|
/**
|
|
3688
3647
|
* In real use cases, there can be hundreds of thousands of locations.
|
|
@@ -3914,7 +3873,7 @@ function omitHiddenPaginatedFields(formConfig, values, validatorContext, include
|
|
|
3914
3873
|
const visibleFields = formConfig.pages.filter((p) => isPageVisible(p, values, validatorContext)).flatMap((p) => p.fields);
|
|
3915
3874
|
const hiddenFields = formConfig.pages.filter((p) => !isPageVisible(p, values, validatorContext)).flatMap((p) => p.fields);
|
|
3916
3875
|
const valuesExceptHiddenPage = (0, import_lodash.omitBy)(values, (_2, fieldId) => {
|
|
3917
|
-
return hiddenFields.some((f) => f.id === fieldId);
|
|
3876
|
+
return hiddenFields.some((f) => f.id === fieldId) && !visibleFields.some((f) => f.id === fieldId);
|
|
3918
3877
|
});
|
|
3919
3878
|
return omitHiddenFields(
|
|
3920
3879
|
visibleFields,
|
|
@@ -3961,11 +3920,10 @@ function getVisibleVerificationPageIds(pages, annotation, context) {
|
|
|
3961
3920
|
}
|
|
3962
3921
|
function omitHiddenAnnotationFields(actionConfig, declaration, annotation, context) {
|
|
3963
3922
|
const annotationFields = getActionAnnotationFields(actionConfig);
|
|
3964
|
-
return omitHiddenFields(
|
|
3965
|
-
|
|
3966
|
-
|
|
3967
|
-
|
|
3968
|
-
);
|
|
3923
|
+
return omitHiddenFields(annotationFields, annotation, {
|
|
3924
|
+
...context,
|
|
3925
|
+
baseFormState: declaration
|
|
3926
|
+
});
|
|
3969
3927
|
}
|
|
3970
3928
|
function deepMerge(currentDocument, actionDocument) {
|
|
3971
3929
|
const currentDocumentClone = (0, import_lodash.cloneDeep)(currentDocument);
|
|
@@ -4139,20 +4097,16 @@ function getPendingAction(actions) {
|
|
|
4139
4097
|
}
|
|
4140
4098
|
return pendingActions[0];
|
|
4141
4099
|
}
|
|
4142
|
-
function getCompleteActionAnnotation(
|
|
4100
|
+
function getCompleteActionAnnotation(event2, action) {
|
|
4143
4101
|
if (action.originalActionId) {
|
|
4144
4102
|
const originalAction = event2.actions.find(
|
|
4145
4103
|
({ id }) => id === action.originalActionId
|
|
4146
4104
|
);
|
|
4147
|
-
if (originalAction?.status
|
|
4148
|
-
return annotation;
|
|
4105
|
+
if (originalAction?.status === ActionStatus.Requested) {
|
|
4106
|
+
return deepMerge(originalAction.annotation ?? {}, action.annotation ?? {});
|
|
4149
4107
|
}
|
|
4150
|
-
return deepMerge(
|
|
4151
|
-
deepMerge(annotation, originalAction.annotation ?? {}),
|
|
4152
|
-
action.annotation ?? {}
|
|
4153
|
-
);
|
|
4154
4108
|
}
|
|
4155
|
-
return
|
|
4109
|
+
return action.annotation ?? {};
|
|
4156
4110
|
}
|
|
4157
4111
|
function getCompleteActionDeclaration(declaration, event2, action) {
|
|
4158
4112
|
if (action.originalActionId) {
|
|
@@ -4172,7 +4126,7 @@ function getAcceptedActions(event2) {
|
|
|
4172
4126
|
return event2.actions.filter(isAcceptedAction).map((action) => ({
|
|
4173
4127
|
...action,
|
|
4174
4128
|
declaration: getCompleteActionDeclaration({}, event2, action),
|
|
4175
|
-
annotation: getCompleteActionAnnotation(
|
|
4129
|
+
annotation: getCompleteActionAnnotation(event2, action)
|
|
4176
4130
|
}));
|
|
4177
4131
|
}
|
|
4178
4132
|
var EXCLUDED_ACTIONS = [
|
|
@@ -4333,9 +4287,6 @@ function isFieldReference(value) {
|
|
|
4333
4287
|
function isEventFieldReference(value) {
|
|
4334
4288
|
return typeof value === "object" && value !== null && "$$event" in value;
|
|
4335
4289
|
}
|
|
4336
|
-
function isResolvableValueReference(value) {
|
|
4337
|
-
return isFieldReference(value) || isCodeToEvaluate(value);
|
|
4338
|
-
}
|
|
4339
4290
|
function getDateRangeToFieldReference(field3, comparedField, clause) {
|
|
4340
4291
|
return {
|
|
4341
4292
|
type: "object",
|
|
@@ -4770,49 +4721,7 @@ function createFieldConditionals(fieldId) {
|
|
|
4770
4721
|
}
|
|
4771
4722
|
},
|
|
4772
4723
|
required: [fieldId]
|
|
4773
|
-
})
|
|
4774
|
-
/**
|
|
4775
|
-
* Custom client-side validator. The provided function is serialised and executed
|
|
4776
|
-
* just-in-time on the client only. External references (e.g. lodash) are not
|
|
4777
|
-
* available inside the function body — all logic must be self-contained.
|
|
4778
|
-
*
|
|
4779
|
-
* @example
|
|
4780
|
-
* field('nid').customClientValidator((value) => {
|
|
4781
|
-
* // LUHN check — all logic must be inline
|
|
4782
|
-
* const digits = String(value).split('').map(Number)
|
|
4783
|
-
* // ...
|
|
4784
|
-
* return isValid
|
|
4785
|
-
* })
|
|
4786
|
-
*/
|
|
4787
|
-
customClientValidator(validationFn) {
|
|
4788
|
-
const code = validationFn.toString();
|
|
4789
|
-
return defineFormConditional({
|
|
4790
|
-
type: "object",
|
|
4791
|
-
properties: wrapToPath(
|
|
4792
|
-
{ [fieldId]: { customClientValidator: { code } } },
|
|
4793
|
-
this.$$subfield
|
|
4794
|
-
),
|
|
4795
|
-
required: [fieldId]
|
|
4796
|
-
});
|
|
4797
|
-
},
|
|
4798
|
-
/**
|
|
4799
|
-
* Custom client-side evaluation. Returns a {@link CodeToEvaluate} descriptor
|
|
4800
|
-
* that can be used as `value`, `evaluatedDefaultValue`, or a DATA component entry.
|
|
4801
|
-
* The function is serialised and executed just-in-time on the client only.
|
|
4802
|
-
* External references (e.g. lodash) are not available inside the function body.
|
|
4803
|
-
*
|
|
4804
|
-
* @example
|
|
4805
|
-
* field('a').customClientEvaluation((aValue, ctx) =>
|
|
4806
|
-
* Number(aValue) + Number(ctx.$form.b)
|
|
4807
|
-
* )
|
|
4808
|
-
*/
|
|
4809
|
-
customClientEvaluation(computationFn) {
|
|
4810
|
-
return {
|
|
4811
|
-
$$code: computationFn.toString(),
|
|
4812
|
-
$$field: fieldId,
|
|
4813
|
-
$$subfield: this.$$subfield
|
|
4814
|
-
};
|
|
4815
|
-
}
|
|
4724
|
+
})
|
|
4816
4725
|
};
|
|
4817
4726
|
}
|
|
4818
4727
|
|
|
@@ -5393,6 +5302,8 @@ var BaseActionInput = import_zod34.z.object({
|
|
|
5393
5302
|
originalActionId: UUID.optional(),
|
|
5394
5303
|
// should not be part of base action.
|
|
5395
5304
|
keepAssignment: import_zod34.z.boolean().optional(),
|
|
5305
|
+
keepAssignmentIfAccepted: import_zod34.z.boolean().optional(),
|
|
5306
|
+
keepAssignmentIfRejected: import_zod34.z.boolean().optional(),
|
|
5396
5307
|
// For normal users, the createdAtLocation is resolved on the backend from the user's primaryOfficeId.
|
|
5397
5308
|
createdAtLocation: CreatedAtLocation.describe(
|
|
5398
5309
|
"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."
|
|
@@ -5963,7 +5874,7 @@ function getActionAnnotation({
|
|
|
5963
5874
|
const action = (0, import_lodash3.findLast)(activeActions, (a) => a.type === actionType);
|
|
5964
5875
|
const actionWithCompleteAnnotation = action && {
|
|
5965
5876
|
...action,
|
|
5966
|
-
annotation: getCompleteActionAnnotation(
|
|
5877
|
+
annotation: getCompleteActionAnnotation(event2, action)
|
|
5967
5878
|
};
|
|
5968
5879
|
const matchingDraft = draft?.action.type === actionType ? draft : void 0;
|
|
5969
5880
|
const sortedActions = (0, import_lodash3.orderBy)(
|
|
@@ -1493,15 +1493,6 @@ var FieldReference = import_zod17.z.object({
|
|
|
1493
1493
|
'If the FieldValue is an object, subfield can be used to refer to e.g. `["foo", "bar"]` in `{ foo: { bar: 3 } }`'
|
|
1494
1494
|
)
|
|
1495
1495
|
}).describe("Reference to a field by its ID");
|
|
1496
|
-
var CodeToEvaluate = import_zod17.z.object({
|
|
1497
|
-
$$code: import_zod17.z.string().describe("Serialised client-side function body"),
|
|
1498
|
-
$$field: FieldId.describe(
|
|
1499
|
-
"Field whose value is passed as the first argument"
|
|
1500
|
-
),
|
|
1501
|
-
$$subfield: import_zod17.z.array(import_zod17.z.string()).optional().default([]).describe("Optional nested path within the field value")
|
|
1502
|
-
}).describe(
|
|
1503
|
-
"Serialised client-side evaluation function. Executed just-in-time on the client only."
|
|
1504
|
-
);
|
|
1505
1496
|
var ValidationConfig = import_zod17.z.object({
|
|
1506
1497
|
validator: Conditional,
|
|
1507
1498
|
message: TranslationConfig
|
|
@@ -1534,11 +1525,8 @@ var BaseField = import_zod17.z.object({
|
|
|
1534
1525
|
uncorrectable: import_zod17.z.boolean().default(false).optional().describe(
|
|
1535
1526
|
"Indicates whether the field can be modified during record correction."
|
|
1536
1527
|
),
|
|
1537
|
-
value: FieldReference.or(
|
|
1538
|
-
"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.
|
|
1539
|
-
),
|
|
1540
|
-
evaluatedDefaultValue: CodeToEvaluate.optional().describe(
|
|
1541
|
-
"Custom client-side function used to compute the default value. Executed just-in-time on the client. Takes precedence over defaultValue when set."
|
|
1528
|
+
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."
|
|
1542
1530
|
),
|
|
1543
1531
|
analytics: import_zod17.z.boolean().default(false).optional().describe(
|
|
1544
1532
|
"Indicates whether the field is included in analytics. When enabled, its value becomes available in the analytics dashboard."
|
|
@@ -1672,12 +1660,10 @@ var ParagraphConfiguration = import_zod17.z.object({
|
|
|
1672
1660
|
}).default({});
|
|
1673
1661
|
var Paragraph = BaseField.extend({
|
|
1674
1662
|
type: import_zod17.z.literal(FieldType.PARAGRAPH),
|
|
1675
|
-
defaultValue: NonEmptyTextValue.optional(),
|
|
1676
1663
|
configuration: ParagraphConfiguration
|
|
1677
1664
|
}).describe("A read-only HTML <p> paragraph");
|
|
1678
1665
|
var PageHeader = BaseField.extend({
|
|
1679
|
-
type: import_zod17.z.literal(FieldType.PAGE_HEADER)
|
|
1680
|
-
defaultValue: NonEmptyTextValue.optional()
|
|
1666
|
+
type: import_zod17.z.literal(FieldType.PAGE_HEADER)
|
|
1681
1667
|
}).describe("A read-only header component for form pages");
|
|
1682
1668
|
var File = BaseField.extend({
|
|
1683
1669
|
type: import_zod17.z.literal(FieldType.FILE),
|
|
@@ -1727,7 +1713,6 @@ var RadioGroup = BaseField.extend({
|
|
|
1727
1713
|
}).describe("Grouped radio options");
|
|
1728
1714
|
var BulletList = BaseField.extend({
|
|
1729
1715
|
type: import_zod17.z.literal(FieldType.BULLET_LIST),
|
|
1730
|
-
defaultValue: TextValue.optional(),
|
|
1731
1716
|
items: import_zod17.z.array(TranslationConfig).describe("A list of items"),
|
|
1732
1717
|
configuration: import_zod17.z.object({
|
|
1733
1718
|
styles: import_zod17.z.object({
|
|
@@ -1889,7 +1874,7 @@ var Address = BaseField.extend({
|
|
|
1889
1874
|
var StaticDataEntry = import_zod17.z.object({
|
|
1890
1875
|
id: import_zod17.z.string().describe("ID for the data entry."),
|
|
1891
1876
|
label: TranslationConfig,
|
|
1892
|
-
value: TranslationConfig.or(import_zod17.z.string()).or(FieldReference)
|
|
1877
|
+
value: TranslationConfig.or(import_zod17.z.string()).or(FieldReference)
|
|
1893
1878
|
}).describe("Static data entry");
|
|
1894
1879
|
var DataEntry = import_zod17.z.union([StaticDataEntry, import_zod17.z.object({ fieldId: import_zod17.z.string() })]).describe(
|
|
1895
1880
|
"Data entry can be either a static data entry, or a reference to another field in the current form or the declaration."
|
|
@@ -1936,7 +1921,7 @@ var HttpField = BaseField.extend({
|
|
|
1936
1921
|
headers: import_zod17.z.record(import_zod17.z.string()).optional(),
|
|
1937
1922
|
body: import_zod17.z.record(import_zod17.z.any()).optional(),
|
|
1938
1923
|
errorValue: import_zod17.z.any().optional().describe("Value to set if the request fails"),
|
|
1939
|
-
params: import_zod17.z.record(import_zod17.z.string(), import_zod17.z.union([import_zod17.z.string(), FieldReference
|
|
1924
|
+
params: import_zod17.z.record(import_zod17.z.string(), import_zod17.z.union([import_zod17.z.string(), FieldReference])).optional(),
|
|
1940
1925
|
timeout: import_zod17.z.number().default(15e3).describe("Request timeout in milliseconds")
|
|
1941
1926
|
})
|
|
1942
1927
|
}).describe("HTTP request function triggered by a button click or other event");
|
|
@@ -2571,15 +2556,6 @@ function resolveDataPath(rootData, dataPath, instancePath) {
|
|
|
2571
2556
|
}
|
|
2572
2557
|
return current;
|
|
2573
2558
|
}
|
|
2574
|
-
var compiledFunctionCache = /* @__PURE__ */ new Map();
|
|
2575
|
-
function compileClientFunction(code) {
|
|
2576
|
-
let fn = compiledFunctionCache.get(code);
|
|
2577
|
-
if (!fn) {
|
|
2578
|
-
fn = new Function(`return (${code})`)();
|
|
2579
|
-
compiledFunctionCache.set(code, fn);
|
|
2580
|
-
}
|
|
2581
|
-
return fn;
|
|
2582
|
-
}
|
|
2583
2559
|
(0, import_ajv_formats.default)(ajv);
|
|
2584
2560
|
ajv.addKeyword({
|
|
2585
2561
|
keyword: "daysFromDate",
|
|
@@ -2625,21 +2601,12 @@ ajv.addKeyword({
|
|
|
2625
2601
|
$data: true,
|
|
2626
2602
|
errors: true,
|
|
2627
2603
|
// @ts-ignore -- Force type. We will move this away from AJV next. Parsing the array will take seconds and is only called by core.
|
|
2628
|
-
validate(
|
|
2604
|
+
validate(schema, data, _2, dataContext) {
|
|
2629
2605
|
const locationIdInput = data;
|
|
2630
2606
|
const locations = dataContext?.rootData.$leafAdminStructureLocationIds ?? [];
|
|
2631
2607
|
return locations.some((location) => location.id === locationIdInput);
|
|
2632
2608
|
}
|
|
2633
2609
|
});
|
|
2634
|
-
ajv.addKeyword({
|
|
2635
|
-
keyword: "customClientValidator",
|
|
2636
|
-
schemaType: "object",
|
|
2637
|
-
errors: true,
|
|
2638
|
-
// @ts-ignore -- DataContext is not typed in AJV's public API
|
|
2639
|
-
validate(schema, data, _2, dataContext) {
|
|
2640
|
-
return compileClientFunction(schema.code)(data, dataContext?.rootData);
|
|
2641
|
-
}
|
|
2642
|
-
});
|
|
2643
2610
|
|
|
2644
2611
|
// ../commons/src/utils.ts
|
|
2645
2612
|
var z29 = __toESM(require("zod"));
|
|
@@ -3262,49 +3229,7 @@ function createFieldConditionals(fieldId) {
|
|
|
3262
3229
|
}
|
|
3263
3230
|
},
|
|
3264
3231
|
required: [fieldId]
|
|
3265
|
-
})
|
|
3266
|
-
/**
|
|
3267
|
-
* Custom client-side validator. The provided function is serialised and executed
|
|
3268
|
-
* just-in-time on the client only. External references (e.g. lodash) are not
|
|
3269
|
-
* available inside the function body — all logic must be self-contained.
|
|
3270
|
-
*
|
|
3271
|
-
* @example
|
|
3272
|
-
* field('nid').customClientValidator((value) => {
|
|
3273
|
-
* // LUHN check — all logic must be inline
|
|
3274
|
-
* const digits = String(value).split('').map(Number)
|
|
3275
|
-
* // ...
|
|
3276
|
-
* return isValid
|
|
3277
|
-
* })
|
|
3278
|
-
*/
|
|
3279
|
-
customClientValidator(validationFn) {
|
|
3280
|
-
const code = validationFn.toString();
|
|
3281
|
-
return defineFormConditional({
|
|
3282
|
-
type: "object",
|
|
3283
|
-
properties: wrapToPath(
|
|
3284
|
-
{ [fieldId]: { customClientValidator: { code } } },
|
|
3285
|
-
this.$$subfield
|
|
3286
|
-
),
|
|
3287
|
-
required: [fieldId]
|
|
3288
|
-
});
|
|
3289
|
-
},
|
|
3290
|
-
/**
|
|
3291
|
-
* Custom client-side evaluation. Returns a {@link CodeToEvaluate} descriptor
|
|
3292
|
-
* that can be used as `value`, `evaluatedDefaultValue`, or a DATA component entry.
|
|
3293
|
-
* The function is serialised and executed just-in-time on the client only.
|
|
3294
|
-
* External references (e.g. lodash) are not available inside the function body.
|
|
3295
|
-
*
|
|
3296
|
-
* @example
|
|
3297
|
-
* field('a').customClientEvaluation((aValue, ctx) =>
|
|
3298
|
-
* Number(aValue) + Number(ctx.$form.b)
|
|
3299
|
-
* )
|
|
3300
|
-
*/
|
|
3301
|
-
customClientEvaluation(computationFn) {
|
|
3302
|
-
return {
|
|
3303
|
-
$$code: computationFn.toString(),
|
|
3304
|
-
$$field: fieldId,
|
|
3305
|
-
$$subfield: this.$$subfield
|
|
3306
|
-
};
|
|
3307
|
-
}
|
|
3232
|
+
})
|
|
3308
3233
|
};
|
|
3309
3234
|
}
|
|
3310
3235
|
|
|
@@ -3876,6 +3801,8 @@ var BaseActionInput = import_zod34.z.object({
|
|
|
3876
3801
|
originalActionId: UUID.optional(),
|
|
3877
3802
|
// should not be part of base action.
|
|
3878
3803
|
keepAssignment: import_zod34.z.boolean().optional(),
|
|
3804
|
+
keepAssignmentIfAccepted: import_zod34.z.boolean().optional(),
|
|
3805
|
+
keepAssignmentIfRejected: import_zod34.z.boolean().optional(),
|
|
3879
3806
|
// For normal users, the createdAtLocation is resolved on the backend from the user's primaryOfficeId.
|
|
3880
3807
|
createdAtLocation: CreatedAtLocation.describe(
|
|
3881
3808
|
"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."
|
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.f568f39",
|
|
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",
|