@opencrvs/toolkit 1.8.1-rc.008155b → 1.8.1-rc.0c972dc
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 +384 -384
- package/dist/commons/conditionals/validate.d.ts +11 -2
- package/dist/commons/events/ActionConfig.d.ts +2004 -366
- package/dist/commons/events/ActionDocument.d.ts +736 -736
- package/dist/commons/events/ActionInput.d.ts +600 -600
- package/dist/commons/events/AdvancedSearchConfig.d.ts +18 -18
- package/dist/commons/events/CompositeFieldValue.d.ts +6 -6
- package/dist/commons/events/Draft.d.ts +48 -48
- package/dist/commons/events/EventConfig.d.ts +664 -137
- package/dist/commons/events/EventDocument.d.ts +432 -432
- package/dist/commons/events/EventIndex.d.ts +10 -10
- package/dist/commons/events/FieldConfig.d.ts +253 -35
- package/dist/commons/events/FieldTypeMapping.d.ts +16 -16
- package/dist/commons/events/FieldValue.d.ts +12 -12
- package/dist/commons/events/FormConfig.d.ts +1032 -246
- package/dist/commons/events/PageConfig.d.ts +264 -46
- package/dist/commons/events/defineConfig.d.ts +126 -27
- package/dist/commons/events/event.d.ts +55 -1
- package/dist/commons/events/test.utils.d.ts +12 -12
- package/dist/commons/events/utils.d.ts +232 -56
- package/dist/conditionals/index.js +1 -0
- package/dist/events/index.js +176 -33
- package/package.json +1 -1
- package/tsconfig.json +1 -1
- package/dist/commons/conditionals/conditionals.test.d.ts +0 -2
- package/dist/commons/conditionals/validate-address.test.d.ts +0 -2
- package/dist/commons/conditionals/validate.test.d.ts +0 -2
- package/dist/commons/events/utils.test.d.ts +0 -2
package/dist/events/index.js
CHANGED
@@ -134,6 +134,7 @@ __export(events_exports, {
|
|
134
134
|
METADATA_FIELD_PREFIX: () => METADATA_FIELD_PREFIX,
|
135
135
|
MarkedAsDuplicateActionInput: () => MarkedAsDuplicateActionInput,
|
136
136
|
MimeType: () => MimeType,
|
137
|
+
NameConfig: () => NameConfig,
|
137
138
|
NameFieldUpdateValue: () => NameFieldUpdateValue,
|
138
139
|
NameFieldValue: () => NameFieldValue,
|
139
140
|
NonEmptyTextValue: () => NonEmptyTextValue,
|
@@ -171,6 +172,7 @@ __export(events_exports, {
|
|
171
172
|
TENNIS_CLUB_MEMBERSHIP: () => TENNIS_CLUB_MEMBERSHIP,
|
172
173
|
TEST_SYSTEM_IANA_TIMEZONE: () => TEST_SYSTEM_IANA_TIMEZONE,
|
173
174
|
TestUserRole: () => TestUserRole,
|
175
|
+
TextField: () => TextField,
|
174
176
|
TextValue: () => TextValue,
|
175
177
|
TimeValue: () => TimeValue,
|
176
178
|
TranslationConfig: () => TranslationConfig,
|
@@ -200,6 +202,7 @@ __export(events_exports, {
|
|
200
202
|
annotationActions: () => annotationActions,
|
201
203
|
applyDeclarationToEventIndex: () => applyDeclarationToEventIndex,
|
202
204
|
applyDraftsToEventIndex: () => applyDraftsToEventIndex,
|
205
|
+
areCertificateConditionsMet: () => areCertificateConditionsMet,
|
203
206
|
areConditionsMet: () => areConditionsMet,
|
204
207
|
compositeFieldTypes: () => compositeFieldTypes,
|
205
208
|
createEmptyDraft: () => createEmptyDraft,
|
@@ -323,6 +326,7 @@ __export(events_exports, {
|
|
323
326
|
or: () => or,
|
324
327
|
resolveDateOfEvent: () => resolveDateOfEvent,
|
325
328
|
runFieldValidations: () => runFieldValidations,
|
329
|
+
runStructuralValidations: () => runStructuralValidations,
|
326
330
|
timePeriodToDateRange: () => timePeriodToDateRange,
|
327
331
|
user: () => user,
|
328
332
|
validate: () => validate,
|
@@ -609,13 +613,13 @@ var UrbanAddressUpdateValue = AdminStructure.extend({
|
|
609
613
|
zipCode: import_zod5.z.string().nullish()
|
610
614
|
});
|
611
615
|
var NameFieldValue = import_zod5.z.object({
|
612
|
-
firstname: import_zod5.z.string()
|
613
|
-
surname: import_zod5.z.string()
|
616
|
+
firstname: import_zod5.z.string(),
|
617
|
+
surname: import_zod5.z.string(),
|
614
618
|
middlename: import_zod5.z.string().optional()
|
615
619
|
});
|
616
620
|
var NameFieldUpdateValue = import_zod5.z.object({
|
617
|
-
firstname: import_zod5.z.string()
|
618
|
-
surname: import_zod5.z.string()
|
621
|
+
firstname: import_zod5.z.string(),
|
622
|
+
surname: import_zod5.z.string(),
|
619
623
|
middlename: import_zod5.z.string().nullish()
|
620
624
|
}).or(import_zod5.z.null()).or(import_zod5.z.undefined());
|
621
625
|
var RuralAddressUpdateValue = AdminStructure.extend({
|
@@ -912,18 +916,32 @@ var SelectDateRangeField = BaseField.extend({
|
|
912
916
|
defaultValue: SelectDateRangeValue.optional(),
|
913
917
|
options: import_zod7.z.array(SelectDateRangeOption).describe("A list of options")
|
914
918
|
}).describe("Select input with date range options");
|
919
|
+
var NameConfig = import_zod7.z.object({
|
920
|
+
firstname: import_zod7.z.object({ required: import_zod7.z.boolean() }).optional(),
|
921
|
+
middlename: import_zod7.z.object({ required: import_zod7.z.boolean() }).optional(),
|
922
|
+
surname: import_zod7.z.object({ required: import_zod7.z.boolean() }).optional()
|
923
|
+
});
|
915
924
|
var NameField = BaseField.extend({
|
916
925
|
type: import_zod7.z.literal(FieldType.NAME),
|
917
926
|
defaultValue: import_zod7.z.object({
|
918
|
-
firstname: NonEmptyTextValue,
|
919
|
-
|
927
|
+
firstname: NonEmptyTextValue.optional(),
|
928
|
+
middlename: NonEmptyTextValue.optional(),
|
929
|
+
surname: NonEmptyTextValue.optional()
|
920
930
|
}).optional(),
|
921
931
|
configuration: import_zod7.z.object({
|
932
|
+
name: NameConfig.default({
|
933
|
+
firstname: { required: true },
|
934
|
+
surname: { required: true }
|
935
|
+
}).optional(),
|
922
936
|
maxLength: import_zod7.z.number().optional().describe("Maximum length of the text"),
|
923
937
|
prefix: TranslationConfig.optional(),
|
924
938
|
postfix: TranslationConfig.optional(),
|
925
|
-
includeMiddlename: import_zod7.z.boolean().default(false).optional().describe("To make middle name visible in Name form field"),
|
926
939
|
searchMode: import_zod7.z.boolean().optional()
|
940
|
+
}).default({
|
941
|
+
name: {
|
942
|
+
firstname: { required: true },
|
943
|
+
surname: { required: true }
|
944
|
+
}
|
927
945
|
}).optional()
|
928
946
|
}).describe("Name input field");
|
929
947
|
var PhoneField = BaseField.extend({
|
@@ -1225,7 +1243,8 @@ var CertificateConfig = import_zod11.z.object({
|
|
1225
1243
|
delayed: import_zod11.z.number()
|
1226
1244
|
}),
|
1227
1245
|
svgUrl: import_zod11.z.string(),
|
1228
|
-
fonts: import_zod11.z.record(FontFamily).optional()
|
1246
|
+
fonts: import_zod11.z.record(FontFamily).optional(),
|
1247
|
+
conditionals: import_zod11.z.array(ShowConditional).optional()
|
1229
1248
|
});
|
1230
1249
|
var CertificateTemplateConfig = CertificateConfig.extend({
|
1231
1250
|
hash: import_zod11.z.string().optional(),
|
@@ -2055,7 +2074,7 @@ var ResolvedUser = import_zod19.z.object({
|
|
2055
2074
|
});
|
2056
2075
|
|
2057
2076
|
// ../commons/src/conditionals/validate.ts
|
2058
|
-
var
|
2077
|
+
var import__ = __toESM(require("ajv/dist/2019"));
|
2059
2078
|
var import_ajv_formats = __toESM(require("ajv-formats"));
|
2060
2079
|
var import_date_fns = require("date-fns");
|
2061
2080
|
|
@@ -2269,9 +2288,11 @@ var isNonInteractiveFieldType = (field2) => {
|
|
2269
2288
|
};
|
2270
2289
|
|
2271
2290
|
// ../commons/src/conditionals/validate.ts
|
2272
|
-
var ajv = new
|
2291
|
+
var ajv = new import__.default({
|
2273
2292
|
$data: true,
|
2274
|
-
allowUnionTypes: true
|
2293
|
+
allowUnionTypes: true,
|
2294
|
+
strict: false
|
2295
|
+
// Allow minContains and other newer features
|
2275
2296
|
});
|
2276
2297
|
(0, import_ajv_formats.default)(ajv);
|
2277
2298
|
ajv.addKeyword({
|
@@ -2444,6 +2465,23 @@ function validateFieldInput({
|
|
2444
2465
|
const rawError = zodType.safeParse(value, { errorMap: zodToIntlErrorMap });
|
2445
2466
|
return rawError.error?.issues.map((issue) => issue.message) ?? [];
|
2446
2467
|
}
|
2468
|
+
function runStructuralValidations({
|
2469
|
+
field: field2,
|
2470
|
+
values
|
2471
|
+
}) {
|
2472
|
+
if (!isFieldVisible(field2, values) || isFieldEmptyAndNotRequired(field2, values)) {
|
2473
|
+
return {
|
2474
|
+
errors: []
|
2475
|
+
};
|
2476
|
+
}
|
2477
|
+
const fieldValidationResult = validateFieldInput({
|
2478
|
+
field: field2,
|
2479
|
+
value: values[field2.id]
|
2480
|
+
});
|
2481
|
+
return {
|
2482
|
+
errors: fieldValidationResult
|
2483
|
+
};
|
2484
|
+
}
|
2447
2485
|
function runFieldValidations({
|
2448
2486
|
field: field2,
|
2449
2487
|
values
|
@@ -2509,6 +2547,11 @@ function getValidatorsForField(fieldId, validations) {
|
|
2509
2547
|
};
|
2510
2548
|
}).filter((x) => x !== null);
|
2511
2549
|
}
|
2550
|
+
function areCertificateConditionsMet(conditions, values) {
|
2551
|
+
return conditions.every((condition) => {
|
2552
|
+
return ajv.validate(condition.conditional, values);
|
2553
|
+
});
|
2554
|
+
}
|
2512
2555
|
|
2513
2556
|
// ../commons/src/utils.ts
|
2514
2557
|
function getOrThrow(x, message) {
|
@@ -3105,6 +3148,7 @@ function createFieldConditionals(fieldId) {
|
|
3105
3148
|
properties: {
|
3106
3149
|
[fieldId]: {
|
3107
3150
|
type: "string",
|
3151
|
+
minLength: 1,
|
3108
3152
|
pattern: "^[\\p{Script=Latin}0-9'.-]*(\\([\\p{Script=Latin}0-9'.-]+\\))?[\\p{Script=Latin}0-9'.-]*( [\\p{Script=Latin}0-9'.-]*(\\([\\p{Script=Latin}0-9'.-]+\\))?[\\p{Script=Latin}0-9'.-]*)*$",
|
3109
3153
|
description: "Name must contain only letters, numbers, and allowed special characters ('.-). No double spaces."
|
3110
3154
|
}
|
@@ -3232,32 +3276,107 @@ function eventFn(fieldId) {
|
|
3232
3276
|
var event = Object.assign(eventFn, {
|
3233
3277
|
/**
|
3234
3278
|
* Checks if the event contains a specific action type.
|
3279
|
+
* Can be used directly as a conditional or chained with additional methods.
|
3235
3280
|
* @param action - The action type to check for.
|
3236
3281
|
*/
|
3237
|
-
hasAction: (action) =>
|
3238
|
-
|
3239
|
-
|
3240
|
-
|
3282
|
+
hasAction: (action) => {
|
3283
|
+
const basicConditional = defineConditional({
|
3284
|
+
type: "object",
|
3285
|
+
properties: {
|
3286
|
+
$event: {
|
3287
|
+
type: "object",
|
3288
|
+
properties: {
|
3289
|
+
actions: {
|
3290
|
+
type: "array",
|
3291
|
+
contains: {
|
3292
|
+
type: "object",
|
3293
|
+
properties: {
|
3294
|
+
type: {
|
3295
|
+
const: action
|
3296
|
+
}
|
3297
|
+
},
|
3298
|
+
required: ["type"]
|
3299
|
+
}
|
3300
|
+
}
|
3301
|
+
},
|
3302
|
+
required: ["actions"]
|
3303
|
+
}
|
3304
|
+
},
|
3305
|
+
required: ["$event"]
|
3306
|
+
});
|
3307
|
+
const buildActionConstraints = (additionalFields) => {
|
3308
|
+
const actionProperties = {
|
3309
|
+
type: { const: action }
|
3310
|
+
};
|
3311
|
+
const requiredFields = ["type"];
|
3312
|
+
if (additionalFields) {
|
3313
|
+
Object.entries(additionalFields).forEach(([key, value]) => {
|
3314
|
+
actionProperties[key] = { const: value };
|
3315
|
+
requiredFields.push(key);
|
3316
|
+
});
|
3317
|
+
}
|
3318
|
+
return { actionProperties, requiredFields };
|
3319
|
+
};
|
3320
|
+
const createCountConditional = (countType, count, additionalFields) => {
|
3321
|
+
const { actionProperties, requiredFields } = buildActionConstraints(additionalFields);
|
3322
|
+
return defineConditional({
|
3241
3323
|
type: "object",
|
3242
3324
|
properties: {
|
3243
|
-
|
3244
|
-
type: "
|
3245
|
-
|
3246
|
-
|
3247
|
-
|
3248
|
-
|
3249
|
-
|
3250
|
-
|
3251
|
-
|
3252
|
-
|
3253
|
-
|
3325
|
+
$event: {
|
3326
|
+
type: "object",
|
3327
|
+
properties: {
|
3328
|
+
actions: {
|
3329
|
+
type: "array",
|
3330
|
+
contains: {
|
3331
|
+
type: "object",
|
3332
|
+
properties: actionProperties,
|
3333
|
+
required: requiredFields
|
3334
|
+
},
|
3335
|
+
[countType]: count
|
3336
|
+
}
|
3337
|
+
},
|
3338
|
+
required: ["actions"]
|
3254
3339
|
}
|
3255
3340
|
},
|
3256
|
-
required: ["
|
3257
|
-
}
|
3258
|
-
}
|
3259
|
-
|
3260
|
-
|
3341
|
+
required: ["$event"]
|
3342
|
+
});
|
3343
|
+
};
|
3344
|
+
const withMinMax = (additionalFields) => {
|
3345
|
+
return {
|
3346
|
+
/**
|
3347
|
+
* Creates a conditional that checks if the event contains a specific action type
|
3348
|
+
* with a minimum count of occurrences.
|
3349
|
+
*
|
3350
|
+
* @param minCount - The minimum number of actions required.
|
3351
|
+
*/
|
3352
|
+
minCount: (minCount) => createCountConditional("minContains", minCount, additionalFields),
|
3353
|
+
/**
|
3354
|
+
* Builds a conditional that sets a maximum count for the number of actions.
|
3355
|
+
* This is useful for limiting the number of actions of a specific type in a single event.
|
3356
|
+
*/
|
3357
|
+
maxCount: (maxCount) => createCountConditional("maxContains", maxCount, additionalFields)
|
3358
|
+
};
|
3359
|
+
};
|
3360
|
+
const chainableMethods = {
|
3361
|
+
/**
|
3362
|
+
* Adds additional field constraints to the action matching.
|
3363
|
+
*
|
3364
|
+
* @param fields - Object containing additional fields to match on the action.
|
3365
|
+
*/
|
3366
|
+
withFields: (fields) => withMinMax(fields),
|
3367
|
+
/**
|
3368
|
+
* Adds template ID constraint to the action matching.
|
3369
|
+
* This is a convenience method that adds content.templateId to the fields.
|
3370
|
+
*
|
3371
|
+
* @param id - The template ID to match against.
|
3372
|
+
*/
|
3373
|
+
withTemplate: (id) => withMinMax({
|
3374
|
+
content: { templateId: id }
|
3375
|
+
}),
|
3376
|
+
...withMinMax()
|
3377
|
+
};
|
3378
|
+
return { ...basicConditional, ...chainableMethods };
|
3379
|
+
},
|
3261
3380
|
field(field2) {
|
3262
3381
|
return {
|
3263
3382
|
$event: field2
|
@@ -5174,7 +5293,27 @@ var TENNIS_CLUB_DECLARATION_FORM = defineDeclarationForm({
|
|
5174
5293
|
defaultMessage: "Applicant's name",
|
5175
5294
|
description: "This is the label for the field",
|
5176
5295
|
id: "v2.event.tennis-club-membership.action.declare.form.section.who.field.firstname.label"
|
5177
|
-
}
|
5296
|
+
},
|
5297
|
+
configuration: {
|
5298
|
+
name: {
|
5299
|
+
firstname: { required: true },
|
5300
|
+
middlename: { required: false },
|
5301
|
+
surname: { required: true }
|
5302
|
+
}
|
5303
|
+
},
|
5304
|
+
validation: [
|
5305
|
+
{
|
5306
|
+
validator: field("applicant.name").object({
|
5307
|
+
firstname: field("firstname").isValidEnglishName(),
|
5308
|
+
surname: field("surname").isValidEnglishName()
|
5309
|
+
}),
|
5310
|
+
message: {
|
5311
|
+
defaultMessage: "Input contains invalid characters. Please use only letters (a-z, A-Z), numbers (0-9), hyphens (-), apostrophes(') and underscores (_)",
|
5312
|
+
description: "This is the error message for invalid name",
|
5313
|
+
id: "v2.error.invalidName"
|
5314
|
+
}
|
5315
|
+
}
|
5316
|
+
]
|
5178
5317
|
},
|
5179
5318
|
{
|
5180
5319
|
id: "applicant.email",
|
@@ -6847,7 +6986,11 @@ function generateActionDocument({
|
|
6847
6986
|
case ActionType.NOTIFY:
|
6848
6987
|
return { ...actionBase, type: action };
|
6849
6988
|
case ActionType.PRINT_CERTIFICATE:
|
6850
|
-
return {
|
6989
|
+
return {
|
6990
|
+
...actionBase,
|
6991
|
+
type: action,
|
6992
|
+
content: defaults.content
|
6993
|
+
};
|
6851
6994
|
case ActionType.REQUEST_CORRECTION:
|
6852
6995
|
return { ...actionBase, type: action };
|
6853
6996
|
case ActionType.APPROVE_CORRECTION:
|
package/package.json
CHANGED
package/tsconfig.json
CHANGED
@@ -19,7 +19,7 @@
|
|
19
19
|
"@opencrvs/commons/events": ["../commons/src/events/index.ts"]
|
20
20
|
}
|
21
21
|
},
|
22
|
-
"references": [{ "path": "../commons" }],
|
22
|
+
"references": [{ "path": "../commons/tsconfig-commonjs.json" }],
|
23
23
|
"include": ["src/**/*.ts"],
|
24
24
|
"exclude": ["**/node_modules/**", "dist"]
|
25
25
|
}
|