@opencrvs/toolkit 1.8.1-rc.b6b235d → 1.8.1-rc.b8eea90
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 -3
- package/dist/commons/conditionals/validate.d.ts +2 -3
- package/dist/commons/events/ActionConfig.d.ts +13593 -4629
- package/dist/commons/events/EventConfig.d.ts +7441 -3499
- package/dist/commons/events/EventIndex.d.ts +0 -3
- package/dist/commons/events/EventMetadata.d.ts +0 -3
- package/dist/commons/events/FieldConfig.d.ts +1050 -362
- package/dist/commons/events/FieldType.d.ts +3 -1
- package/dist/commons/events/FieldTypeMapping.d.ts +15 -1
- package/dist/commons/events/FieldValue.d.ts +4 -0
- package/dist/commons/events/FormConfig.d.ts +6350 -2138
- package/dist/commons/events/PageConfig.d.ts +2058 -1014
- package/dist/commons/events/WorkqueueConfig.d.ts +8 -8
- package/dist/commons/events/defineConfig.d.ts +638 -8
- package/dist/commons/events/event.d.ts +1 -55
- package/dist/commons/events/utils.d.ts +1136 -16
- package/dist/events/index.js +75 -112
- package/package.json +1 -1
package/dist/events/index.js
CHANGED
@@ -60,6 +60,7 @@ __export(events_exports, {
|
|
60
60
|
BIRTH_EVENT: () => BIRTH_EVENT,
|
61
61
|
BaseActionInput: () => BaseActionInput,
|
62
62
|
BearerTokenByUserType: () => BearerTokenByUserType,
|
63
|
+
ButtonFieldValue: () => ButtonFieldValue,
|
63
64
|
CONFIG_GET_ALLOWED_SCOPES: () => CONFIG_GET_ALLOWED_SCOPES,
|
64
65
|
CONFIG_SEARCH_ALLOWED_SCOPES: () => CONFIG_SEARCH_ALLOWED_SCOPES,
|
65
66
|
CertificateConfig: () => CertificateConfig,
|
@@ -125,6 +126,7 @@ __export(events_exports, {
|
|
125
126
|
GenericAddressUpdateValue: () => GenericAddressUpdateValue,
|
126
127
|
GenericAddressValue: () => GenericAddressValue,
|
127
128
|
GeographicalArea: () => GeographicalArea,
|
129
|
+
HttpFieldValue: () => HttpFieldValue,
|
128
130
|
ImageMimeType: () => ImageMimeType,
|
129
131
|
InherentFlags: () => InherentFlags,
|
130
132
|
LanguageConfig: () => LanguageConfig,
|
@@ -198,7 +200,6 @@ __export(events_exports, {
|
|
198
200
|
annotationActions: () => annotationActions,
|
199
201
|
applyDeclarationToEventIndex: () => applyDeclarationToEventIndex,
|
200
202
|
applyDraftsToEventIndex: () => applyDraftsToEventIndex,
|
201
|
-
areCertificateConditionsMet: () => areCertificateConditionsMet,
|
202
203
|
areConditionsMet: () => areConditionsMet,
|
203
204
|
compositeFieldTypes: () => compositeFieldTypes,
|
204
205
|
createEmptyDraft: () => createEmptyDraft,
|
@@ -271,6 +272,7 @@ __export(events_exports, {
|
|
271
272
|
isAddressFieldType: () => isAddressFieldType,
|
272
273
|
isAdministrativeAreaFieldType: () => isAdministrativeAreaFieldType,
|
273
274
|
isBulletListFieldType: () => isBulletListFieldType,
|
275
|
+
isButtonFieldType: () => isButtonFieldType,
|
274
276
|
isCheckboxFieldType: () => isCheckboxFieldType,
|
275
277
|
isConditionMet: () => isConditionMet,
|
276
278
|
isCountryFieldType: () => isCountryFieldType,
|
@@ -288,6 +290,7 @@ __export(events_exports, {
|
|
288
290
|
isFieldVisible: () => isFieldVisible,
|
289
291
|
isFileFieldType: () => isFileFieldType,
|
290
292
|
isFileFieldWithOptionType: () => isFileFieldWithOptionType,
|
293
|
+
isHttpFieldType: () => isHttpFieldType,
|
291
294
|
isIdFieldType: () => isIdFieldType,
|
292
295
|
isLocationFieldType: () => isLocationFieldType,
|
293
296
|
isMetaAction: () => isMetaAction,
|
@@ -539,7 +542,9 @@ var FieldType = {
|
|
539
542
|
FACILITY: "FACILITY",
|
540
543
|
OFFICE: "OFFICE",
|
541
544
|
SIGNATURE: "SIGNATURE",
|
542
|
-
DATA: "DATA"
|
545
|
+
DATA: "DATA",
|
546
|
+
BUTTON: "BUTTON",
|
547
|
+
HTTP: "HTTP"
|
543
548
|
};
|
544
549
|
var fieldTypes = Object.values(FieldType);
|
545
550
|
var compositeFieldTypes = [
|
@@ -679,6 +684,8 @@ var CheckboxFieldValue = import_zod6.z.boolean();
|
|
679
684
|
var NumberFieldValue = import_zod6.z.number();
|
680
685
|
var DataFieldValue = import_zod6.z.undefined();
|
681
686
|
var SignatureFieldValue = import_zod6.z.string();
|
687
|
+
var ButtonFieldValue = import_zod6.z.undefined();
|
688
|
+
var HttpFieldValue = import_zod6.z.undefined();
|
682
689
|
var FieldValue = import_zod6.z.union([
|
683
690
|
TextValue,
|
684
691
|
DateValue,
|
@@ -1006,6 +1013,28 @@ var DataField = BaseField.extend({
|
|
1006
1013
|
data: import_zod7.z.array(DataEntry)
|
1007
1014
|
})
|
1008
1015
|
}).describe("Data field for displaying read-only data");
|
1016
|
+
var ButtonField = BaseField.extend({
|
1017
|
+
type: import_zod7.z.literal(FieldType.BUTTON),
|
1018
|
+
configuration: import_zod7.z.object({
|
1019
|
+
onClick: FieldReference,
|
1020
|
+
icon: import_zod7.z.string().optional().describe(
|
1021
|
+
"Icon for the button. Use icon names from the OpenCRVS UI-Kit."
|
1022
|
+
),
|
1023
|
+
shouldHandleLoadingState: import_zod7.z.boolean().default(false).optional(),
|
1024
|
+
buttonLabel: TranslationConfig,
|
1025
|
+
loadingLabel: TranslationConfig.optional()
|
1026
|
+
})
|
1027
|
+
}).describe("Button for triggering HTTP requests");
|
1028
|
+
var HttpField = BaseField.extend({
|
1029
|
+
type: import_zod7.z.literal(FieldType.HTTP),
|
1030
|
+
configuration: import_zod7.z.object({
|
1031
|
+
method: import_zod7.z.enum(["GET", "POST", "PUT", "DELETE"]),
|
1032
|
+
headers: import_zod7.z.record(import_zod7.z.string()).optional(),
|
1033
|
+
body: import_zod7.z.record(import_zod7.z.string()).optional(),
|
1034
|
+
params: import_zod7.z.record(import_zod7.z.string()).optional(),
|
1035
|
+
url: import_zod7.z.string().describe("URL to send the HTTP request to")
|
1036
|
+
})
|
1037
|
+
}).describe("HTTP request function triggered by a button click");
|
1009
1038
|
var FieldConfig = import_zod7.z.discriminatedUnion("type", [
|
1010
1039
|
Address,
|
1011
1040
|
TextField,
|
@@ -1034,7 +1063,9 @@ var FieldConfig = import_zod7.z.discriminatedUnion("type", [
|
|
1034
1063
|
SignatureField,
|
1035
1064
|
EmailField,
|
1036
1065
|
FileUploadWithOptions,
|
1037
|
-
DataField
|
1066
|
+
DataField,
|
1067
|
+
ButtonField,
|
1068
|
+
HttpField
|
1038
1069
|
]).openapi({
|
1039
1070
|
description: "Form field configuration",
|
1040
1071
|
ref: "FieldConfig"
|
@@ -1224,8 +1255,7 @@ var CertificateConfig = import_zod11.z.object({
|
|
1224
1255
|
delayed: import_zod11.z.number()
|
1225
1256
|
}),
|
1226
1257
|
svgUrl: import_zod11.z.string(),
|
1227
|
-
fonts: import_zod11.z.record(FontFamily).optional()
|
1228
|
-
conditionals: import_zod11.z.array(ShowConditional).optional()
|
1258
|
+
fonts: import_zod11.z.record(FontFamily).optional()
|
1229
1259
|
});
|
1230
1260
|
var CertificateTemplateConfig = CertificateConfig.extend({
|
1231
1261
|
hash: import_zod11.z.string().optional(),
|
@@ -2047,7 +2077,7 @@ var ResolvedUser = import_zod19.z.object({
|
|
2047
2077
|
});
|
2048
2078
|
|
2049
2079
|
// ../commons/src/conditionals/validate.ts
|
2050
|
-
var
|
2080
|
+
var import_ajv = __toESM(require("ajv"));
|
2051
2081
|
var import_ajv_formats = __toESM(require("ajv-formats"));
|
2052
2082
|
var import_date_fns = require("date-fns");
|
2053
2083
|
|
@@ -2110,6 +2140,12 @@ function mapFieldTypeToZod(type, required) {
|
|
2110
2140
|
case FieldType.NAME:
|
2111
2141
|
schema = required ? NameFieldValue : NameFieldUpdateValue;
|
2112
2142
|
break;
|
2143
|
+
case FieldType.BUTTON:
|
2144
|
+
schema = ButtonFieldValue;
|
2145
|
+
break;
|
2146
|
+
case FieldType.HTTP:
|
2147
|
+
schema = ButtonFieldValue;
|
2148
|
+
break;
|
2113
2149
|
}
|
2114
2150
|
return required ? schema : schema.nullish();
|
2115
2151
|
}
|
@@ -2143,6 +2179,8 @@ function mapFieldTypeToEmptyValue(field2) {
|
|
2143
2179
|
case FieldType.DATE_RANGE:
|
2144
2180
|
case FieldType.SELECT_DATE_RANGE:
|
2145
2181
|
case FieldType.DATA:
|
2182
|
+
case FieldType.BUTTON:
|
2183
|
+
case FieldType.HTTP:
|
2146
2184
|
case FieldType.NAME:
|
2147
2185
|
case FieldType.PHONE:
|
2148
2186
|
case FieldType.ID:
|
@@ -2256,16 +2294,20 @@ var isOfficeFieldType = (field2) => {
|
|
2256
2294
|
var isDataFieldType = (field2) => {
|
2257
2295
|
return field2.config.type === FieldType.DATA;
|
2258
2296
|
};
|
2297
|
+
var isButtonFieldType = (field2) => {
|
2298
|
+
return field2.config.type === FieldType.BUTTON;
|
2299
|
+
};
|
2300
|
+
var isHttpFieldType = (field2) => {
|
2301
|
+
return field2.config.type === FieldType.HTTP;
|
2302
|
+
};
|
2259
2303
|
var isNonInteractiveFieldType = (field2) => {
|
2260
2304
|
return field2.type === FieldType.DIVIDER || field2.type === FieldType.PAGE_HEADER || field2.type === FieldType.PARAGRAPH || field2.type === FieldType.BULLET_LIST || field2.type === FieldType.DATA;
|
2261
2305
|
};
|
2262
2306
|
|
2263
2307
|
// ../commons/src/conditionals/validate.ts
|
2264
|
-
var ajv = new
|
2308
|
+
var ajv = new import_ajv.default({
|
2265
2309
|
$data: true,
|
2266
|
-
allowUnionTypes: true
|
2267
|
-
strict: false
|
2268
|
-
// Allow minContains and other newer features
|
2310
|
+
allowUnionTypes: true
|
2269
2311
|
});
|
2270
2312
|
(0, import_ajv_formats.default)(ajv);
|
2271
2313
|
ajv.addKeyword({
|
@@ -2503,11 +2545,6 @@ function getValidatorsForField(fieldId, validations) {
|
|
2503
2545
|
};
|
2504
2546
|
}).filter((x) => x !== null);
|
2505
2547
|
}
|
2506
|
-
function areCertificateConditionsMet(conditions, values) {
|
2507
|
-
return conditions.every((condition) => {
|
2508
|
-
return ajv.validate(condition.conditional, values);
|
2509
|
-
});
|
2510
|
-
}
|
2511
2548
|
|
2512
2549
|
// ../commons/src/utils.ts
|
2513
2550
|
function getOrThrow(x, message) {
|
@@ -3231,107 +3268,32 @@ function eventFn(fieldId) {
|
|
3231
3268
|
var event = Object.assign(eventFn, {
|
3232
3269
|
/**
|
3233
3270
|
* Checks if the event contains a specific action type.
|
3234
|
-
* Can be used directly as a conditional or chained with additional methods.
|
3235
3271
|
* @param action - The action type to check for.
|
3236
3272
|
*/
|
3237
|
-
hasAction: (action) => {
|
3238
|
-
|
3239
|
-
|
3240
|
-
|
3241
|
-
$event: {
|
3242
|
-
type: "object",
|
3243
|
-
properties: {
|
3244
|
-
actions: {
|
3245
|
-
type: "array",
|
3246
|
-
contains: {
|
3247
|
-
type: "object",
|
3248
|
-
properties: {
|
3249
|
-
type: {
|
3250
|
-
const: action
|
3251
|
-
}
|
3252
|
-
},
|
3253
|
-
required: ["type"]
|
3254
|
-
}
|
3255
|
-
}
|
3256
|
-
},
|
3257
|
-
required: ["actions"]
|
3258
|
-
}
|
3259
|
-
},
|
3260
|
-
required: ["$event"]
|
3261
|
-
});
|
3262
|
-
const buildActionConstraints = (additionalFields) => {
|
3263
|
-
const actionProperties = {
|
3264
|
-
type: { const: action }
|
3265
|
-
};
|
3266
|
-
const requiredFields = ["type"];
|
3267
|
-
if (additionalFields) {
|
3268
|
-
Object.entries(additionalFields).forEach(([key, value]) => {
|
3269
|
-
actionProperties[key] = { const: value };
|
3270
|
-
requiredFields.push(key);
|
3271
|
-
});
|
3272
|
-
}
|
3273
|
-
return { actionProperties, requiredFields };
|
3274
|
-
};
|
3275
|
-
const createCountConditional = (countType, count, additionalFields) => {
|
3276
|
-
const { actionProperties, requiredFields } = buildActionConstraints(additionalFields);
|
3277
|
-
return defineConditional({
|
3273
|
+
hasAction: (action) => defineConditional({
|
3274
|
+
type: "object",
|
3275
|
+
properties: {
|
3276
|
+
$event: {
|
3278
3277
|
type: "object",
|
3279
3278
|
properties: {
|
3280
|
-
|
3281
|
-
type: "
|
3282
|
-
|
3283
|
-
|
3284
|
-
|
3285
|
-
|
3286
|
-
|
3287
|
-
|
3288
|
-
|
3289
|
-
|
3290
|
-
|
3291
|
-
}
|
3292
|
-
},
|
3293
|
-
required: ["actions"]
|
3279
|
+
actions: {
|
3280
|
+
type: "array",
|
3281
|
+
contains: {
|
3282
|
+
type: "object",
|
3283
|
+
properties: {
|
3284
|
+
type: {
|
3285
|
+
const: action
|
3286
|
+
}
|
3287
|
+
},
|
3288
|
+
required: ["type"]
|
3289
|
+
}
|
3294
3290
|
}
|
3295
3291
|
},
|
3296
|
-
required: ["
|
3297
|
-
}
|
3298
|
-
}
|
3299
|
-
|
3300
|
-
|
3301
|
-
/**
|
3302
|
-
* Creates a conditional that checks if the event contains a specific action type
|
3303
|
-
* with a minimum count of occurrences.
|
3304
|
-
*
|
3305
|
-
* @param minCount - The minimum number of actions required.
|
3306
|
-
*/
|
3307
|
-
minCount: (minCount) => createCountConditional("minContains", minCount, additionalFields),
|
3308
|
-
/**
|
3309
|
-
* Builds a conditional that sets a maximum count for the number of actions.
|
3310
|
-
* This is useful for limiting the number of actions of a specific type in a single event.
|
3311
|
-
*/
|
3312
|
-
maxCount: (maxCount) => createCountConditional("maxContains", maxCount, additionalFields)
|
3313
|
-
};
|
3314
|
-
};
|
3315
|
-
const chainableMethods = {
|
3316
|
-
/**
|
3317
|
-
* Adds additional field constraints to the action matching.
|
3318
|
-
*
|
3319
|
-
* @param fields - Object containing additional fields to match on the action.
|
3320
|
-
*/
|
3321
|
-
withFields: (fields) => withMinMax(fields),
|
3322
|
-
/**
|
3323
|
-
* Adds template ID constraint to the action matching.
|
3324
|
-
* This is a convenience method that adds content.templateId to the fields.
|
3325
|
-
*
|
3326
|
-
* @param id - The template ID to match against.
|
3327
|
-
*/
|
3328
|
-
withTemplate: (id) => withMinMax({
|
3329
|
-
content: { templateId: id }
|
3330
|
-
}),
|
3331
|
-
...withMinMax()
|
3332
|
-
};
|
3333
|
-
return { ...basicConditional, ...chainableMethods };
|
3334
|
-
},
|
3292
|
+
required: ["actions"]
|
3293
|
+
}
|
3294
|
+
},
|
3295
|
+
required: ["$event"]
|
3296
|
+
}),
|
3335
3297
|
field(field2) {
|
3336
3298
|
return {
|
3337
3299
|
$event: field2
|
@@ -3416,8 +3378,7 @@ var EventMetadata = import_zod23.z.object({
|
|
3416
3378
|
trackingId: import_zod23.z.string().describe(
|
3417
3379
|
"System-generated tracking ID used by informants or registrars to look up the event."
|
3418
3380
|
),
|
3419
|
-
flags: import_zod23.z.array(Flag)
|
3420
|
-
modifiedAt: import_zod23.z.string().optional()
|
3381
|
+
flags: import_zod23.z.array(Flag)
|
3421
3382
|
});
|
3422
3383
|
var EventMetadataKeysArray = [
|
3423
3384
|
"id",
|
@@ -6575,6 +6536,8 @@ function mapFieldTypeToMockValue(field2, i, rng) {
|
|
6575
6536
|
case FieldType.PHONE:
|
6576
6537
|
case FieldType.ID:
|
6577
6538
|
case FieldType.OFFICE:
|
6539
|
+
case FieldType.HTTP:
|
6540
|
+
case FieldType.BUTTON:
|
6578
6541
|
return `${field2.id}-${field2.type}-${i}`;
|
6579
6542
|
case FieldType.NAME:
|
6580
6543
|
return generateRandomName(rng);
|