@opencrvs/toolkit
Advanced tools
Comparing version
import { ConditionalParameters, JSONSchema } from './conditionals'; | ||
import { FieldConfig } from '../events/FieldConfig'; | ||
import { ActionFormData } from '../events/ActionDocument'; | ||
import { FieldConfig } from '../events/FieldConfig'; | ||
import { TranslationConfig } from '../events/TranslationConfig'; | ||
@@ -5,0 +5,0 @@ export declare function validate(schema: JSONSchema, data: ConditionalParameters): boolean; |
@@ -27,8 +27,7 @@ import { z } from 'zod'; | ||
originalFilename: string; | ||
}>> | z.ZodOptional<z.ZodDiscriminatedUnion<"urbanOrRural", [z.ZodObject<z.objectUtil.extendShape<{ | ||
country: z.ZodString; | ||
province: z.ZodString; | ||
district: z.ZodString; | ||
}, { | ||
urbanOrRural: z.ZodLiteral<"URBAN">; | ||
}>> | z.ZodOptional<z.ZodObject<{ | ||
country: z.ZodOptional<z.ZodString>; | ||
province: z.ZodOptional<z.ZodString>; | ||
district: z.ZodOptional<z.ZodString>; | ||
urbanOrRural: z.ZodOptional<z.ZodString>; | ||
town: z.ZodOptional<z.ZodString>; | ||
@@ -39,8 +38,9 @@ residentialArea: z.ZodOptional<z.ZodString>; | ||
zipCode: z.ZodOptional<z.ZodString>; | ||
}>, "strip", z.ZodTypeAny, { | ||
country: string; | ||
district: string; | ||
province: string; | ||
urbanOrRural: "URBAN"; | ||
village: z.ZodOptional<z.ZodString>; | ||
}, "strip", z.ZodTypeAny, { | ||
number?: string | undefined; | ||
country?: string | undefined; | ||
district?: string | undefined; | ||
province?: string | undefined; | ||
urbanOrRural?: string | undefined; | ||
town?: string | undefined; | ||
@@ -50,8 +50,9 @@ residentialArea?: string | undefined; | ||
zipCode?: string | undefined; | ||
village?: string | undefined; | ||
}, { | ||
country: string; | ||
district: string; | ||
province: string; | ||
urbanOrRural: "URBAN"; | ||
number?: string | undefined; | ||
country?: string | undefined; | ||
district?: string | undefined; | ||
province?: string | undefined; | ||
urbanOrRural?: string | undefined; | ||
town?: string | undefined; | ||
@@ -61,22 +62,4 @@ residentialArea?: string | undefined; | ||
zipCode?: string | undefined; | ||
}>, z.ZodObject<z.objectUtil.extendShape<{ | ||
country: z.ZodString; | ||
province: z.ZodString; | ||
district: z.ZodString; | ||
}, { | ||
urbanOrRural: z.ZodLiteral<"RURAL">; | ||
village: z.ZodOptional<z.ZodString>; | ||
}>, "strip", z.ZodTypeAny, { | ||
country: string; | ||
district: string; | ||
province: string; | ||
urbanOrRural: "RURAL"; | ||
village?: string | undefined; | ||
}, { | ||
country: string; | ||
district: string; | ||
province: string; | ||
urbanOrRural: "RURAL"; | ||
village?: string | undefined; | ||
}>]>> | z.ZodOptional<z.ZodArray<z.ZodObject<{ | ||
}>> | z.ZodOptional<z.ZodArray<z.ZodObject<{ | ||
filename: z.ZodString; | ||
@@ -103,7 +86,7 @@ originalFilename: z.ZodString; | ||
} | { | ||
country: string; | ||
district: string; | ||
province: string; | ||
urbanOrRural: "URBAN"; | ||
number?: string | undefined; | ||
country?: string | undefined; | ||
district?: string | undefined; | ||
province?: string | undefined; | ||
urbanOrRural?: string | undefined; | ||
town?: string | undefined; | ||
@@ -113,7 +96,2 @@ residentialArea?: string | undefined; | ||
zipCode?: string | undefined; | ||
} | { | ||
country: string; | ||
district: string; | ||
province: string; | ||
urbanOrRural: "RURAL"; | ||
village?: string | undefined; | ||
@@ -132,7 +110,7 @@ } | { | ||
} | { | ||
country: string; | ||
district: string; | ||
province: string; | ||
urbanOrRural: "URBAN"; | ||
number?: string | undefined; | ||
country?: string | undefined; | ||
district?: string | undefined; | ||
province?: string | undefined; | ||
urbanOrRural?: string | undefined; | ||
town?: string | undefined; | ||
@@ -142,7 +120,2 @@ residentialArea?: string | undefined; | ||
zipCode?: string | undefined; | ||
} | { | ||
country: string; | ||
district: string; | ||
province: string; | ||
urbanOrRural: "RURAL"; | ||
village?: string | undefined; | ||
@@ -149,0 +122,0 @@ } | { |
@@ -20,8 +20,7 @@ import { z } from 'zod'; | ||
export type FileFieldValue = z.infer<typeof FileFieldValue>; | ||
export declare const AddressFieldValue: z.ZodDiscriminatedUnion<"urbanOrRural", [z.ZodObject<z.objectUtil.extendShape<{ | ||
country: z.ZodString; | ||
province: z.ZodString; | ||
district: z.ZodString; | ||
}, { | ||
urbanOrRural: z.ZodLiteral<"URBAN">; | ||
export declare const AddressFieldValue: z.ZodObject<{ | ||
country: z.ZodOptional<z.ZodString>; | ||
province: z.ZodOptional<z.ZodString>; | ||
district: z.ZodOptional<z.ZodString>; | ||
urbanOrRural: z.ZodOptional<z.ZodString>; | ||
town: z.ZodOptional<z.ZodString>; | ||
@@ -32,8 +31,9 @@ residentialArea: z.ZodOptional<z.ZodString>; | ||
zipCode: z.ZodOptional<z.ZodString>; | ||
}>, "strip", z.ZodTypeAny, { | ||
country: string; | ||
district: string; | ||
province: string; | ||
urbanOrRural: "URBAN"; | ||
village: z.ZodOptional<z.ZodString>; | ||
}, "strip", z.ZodTypeAny, { | ||
number?: string | undefined; | ||
country?: string | undefined; | ||
district?: string | undefined; | ||
province?: string | undefined; | ||
urbanOrRural?: string | undefined; | ||
town?: string | undefined; | ||
@@ -43,8 +43,9 @@ residentialArea?: string | undefined; | ||
zipCode?: string | undefined; | ||
village?: string | undefined; | ||
}, { | ||
country: string; | ||
district: string; | ||
province: string; | ||
urbanOrRural: "URBAN"; | ||
number?: string | undefined; | ||
country?: string | undefined; | ||
district?: string | undefined; | ||
province?: string | undefined; | ||
urbanOrRural?: string | undefined; | ||
town?: string | undefined; | ||
@@ -54,22 +55,4 @@ residentialArea?: string | undefined; | ||
zipCode?: string | undefined; | ||
}>, z.ZodObject<z.objectUtil.extendShape<{ | ||
country: z.ZodString; | ||
province: z.ZodString; | ||
district: z.ZodString; | ||
}, { | ||
urbanOrRural: z.ZodLiteral<"RURAL">; | ||
village: z.ZodOptional<z.ZodString>; | ||
}>, "strip", z.ZodTypeAny, { | ||
country: string; | ||
district: string; | ||
province: string; | ||
urbanOrRural: "RURAL"; | ||
village?: string | undefined; | ||
}, { | ||
country: string; | ||
district: string; | ||
province: string; | ||
urbanOrRural: "RURAL"; | ||
village?: string | undefined; | ||
}>]>; | ||
}>; | ||
export type AddressFieldValue = z.infer<typeof AddressFieldValue>; | ||
@@ -141,8 +124,7 @@ export declare const FileFieldValueWithOption: z.ZodObject<{ | ||
originalFilename: string; | ||
}>, "many">, z.ZodBoolean, z.ZodNumber, z.ZodObject<z.objectUtil.extendShape<{ | ||
country: z.ZodString; | ||
province: z.ZodString; | ||
district: z.ZodString; | ||
}, { | ||
urbanOrRural: z.ZodLiteral<"URBAN">; | ||
}>, "many">, z.ZodBoolean, z.ZodObject<{ | ||
country: z.ZodOptional<z.ZodString>; | ||
province: z.ZodOptional<z.ZodString>; | ||
district: z.ZodOptional<z.ZodString>; | ||
urbanOrRural: z.ZodOptional<z.ZodString>; | ||
town: z.ZodOptional<z.ZodString>; | ||
@@ -153,8 +135,9 @@ residentialArea: z.ZodOptional<z.ZodString>; | ||
zipCode: z.ZodOptional<z.ZodString>; | ||
}>, "strip", z.ZodTypeAny, { | ||
country: string; | ||
district: string; | ||
province: string; | ||
urbanOrRural: "URBAN"; | ||
village: z.ZodOptional<z.ZodString>; | ||
}, "strip", z.ZodTypeAny, { | ||
number?: string | undefined; | ||
country?: string | undefined; | ||
district?: string | undefined; | ||
province?: string | undefined; | ||
urbanOrRural?: string | undefined; | ||
town?: string | undefined; | ||
@@ -164,8 +147,9 @@ residentialArea?: string | undefined; | ||
zipCode?: string | undefined; | ||
village?: string | undefined; | ||
}, { | ||
country: string; | ||
district: string; | ||
province: string; | ||
urbanOrRural: "URBAN"; | ||
number?: string | undefined; | ||
country?: string | undefined; | ||
district?: string | undefined; | ||
province?: string | undefined; | ||
urbanOrRural?: string | undefined; | ||
town?: string | undefined; | ||
@@ -175,22 +159,4 @@ residentialArea?: string | undefined; | ||
zipCode?: string | undefined; | ||
}>, z.ZodObject<z.objectUtil.extendShape<{ | ||
country: z.ZodString; | ||
province: z.ZodString; | ||
district: z.ZodString; | ||
}, { | ||
urbanOrRural: z.ZodLiteral<"RURAL">; | ||
village: z.ZodOptional<z.ZodString>; | ||
}>, "strip", z.ZodTypeAny, { | ||
country: string; | ||
district: string; | ||
province: string; | ||
urbanOrRural: "RURAL"; | ||
village?: string | undefined; | ||
}, { | ||
country: string; | ||
district: string; | ||
province: string; | ||
urbanOrRural: "RURAL"; | ||
village?: string | undefined; | ||
}>]>; | ||
}>, z.ZodNumber]>; | ||
export type FieldValue = z.infer<typeof FieldValue>; | ||
@@ -197,0 +163,0 @@ /** |
@@ -70,7 +70,7 @@ import { TranslationConfig } from './TranslationConfig'; | ||
} | { | ||
country: string; | ||
district: string; | ||
province: string; | ||
urbanOrRural: "URBAN"; | ||
number?: string | undefined; | ||
country?: string | undefined; | ||
district?: string | undefined; | ||
province?: string | undefined; | ||
urbanOrRural?: string | undefined; | ||
town?: string | undefined; | ||
@@ -80,7 +80,2 @@ residentialArea?: string | undefined; | ||
zipCode?: string | undefined; | ||
} | { | ||
country: string; | ||
district: string; | ||
province: string; | ||
urbanOrRural: "RURAL"; | ||
village?: string | undefined; | ||
@@ -87,0 +82,0 @@ } | { |
@@ -228,23 +228,14 @@ "use strict"; | ||
}); | ||
var AdminStructure = import_zod3.z.object({ | ||
var AddressFieldValue = import_zod3.z.object({ | ||
country: import_zod3.z.string(), | ||
province: import_zod3.z.string(), | ||
district: import_zod3.z.string() | ||
}); | ||
var UrbanAddress = AdminStructure.extend({ | ||
urbanOrRural: import_zod3.z.literal("URBAN"), | ||
town: import_zod3.z.string().optional(), | ||
residentialArea: import_zod3.z.string().optional(), | ||
street: import_zod3.z.string().optional(), | ||
number: import_zod3.z.string().optional(), | ||
zipCode: import_zod3.z.string().optional() | ||
}); | ||
var RuralAddress = AdminStructure.extend({ | ||
urbanOrRural: import_zod3.z.literal("RURAL"), | ||
village: import_zod3.z.string().optional() | ||
}); | ||
var AddressFieldValue = import_zod3.z.discriminatedUnion("urbanOrRural", [ | ||
UrbanAddress, | ||
RuralAddress | ||
]); | ||
district: import_zod3.z.string(), | ||
urbanOrRural: import_zod3.z.string(), | ||
town: import_zod3.z.string(), | ||
residentialArea: import_zod3.z.string(), | ||
street: import_zod3.z.string(), | ||
number: import_zod3.z.string(), | ||
zipCode: import_zod3.z.string(), | ||
village: import_zod3.z.string() | ||
}).partial(); | ||
var FileFieldValueWithOption = import_zod3.z.object({ | ||
@@ -265,5 +256,4 @@ filename: import_zod3.z.string(), | ||
CheckboxFieldValue, | ||
NumberFieldValue, | ||
UrbanAddress, | ||
RuralAddress | ||
AddressFieldValue, | ||
NumberFieldValue | ||
]); | ||
@@ -313,3 +303,3 @@ | ||
maxLength: import_zod4.z.number().optional().describe("Maximum length of the text"), | ||
type: import_zod4.z.enum(["text", "password"]).optional(), | ||
type: import_zod4.z.enum(["text", "email", "password"]).optional(), | ||
prefix: TranslationConfig.optional(), | ||
@@ -352,5 +342,2 @@ postfix: TranslationConfig.optional() | ||
type: import_zod4.z.literal(FieldType.EMAIL), | ||
configuration: import_zod4.z.object({ | ||
maxLength: import_zod4.z.number().optional().describe("Maximum length of the text") | ||
}).default({ maxLength: 10 }).optional(), | ||
defaultValue: import_zod4.z.union([RequiredTextValue, DependencyExpression]).optional() | ||
@@ -1188,30 +1175,8 @@ }); | ||
} | ||
if (issue.code === "invalid_string" && issue.validation === "email") { | ||
return { | ||
message: { | ||
message: { | ||
defaultMessage: "Invalid email address", | ||
description: "This is the error message for invalid email fields", | ||
id: "v2.error.invalidEmail" | ||
} | ||
} | ||
}; | ||
} | ||
if (issue.code === "invalid_type" && issue.expected !== issue.received && issue.received === "undefined") { | ||
return { | ||
message: { | ||
message: { | ||
defaultMessage: "Required for registration", | ||
description: "This is the error message for required fields", | ||
id: "v2.error.required" | ||
} | ||
} | ||
}; | ||
} | ||
return { | ||
message: { | ||
message: { | ||
defaultMessage: "Invalid input", | ||
description: "This is the error message for invalid field value", | ||
id: "v2.error.invalid" | ||
defaultMessage: "Required for registration", | ||
description: "This is the error message for required fields", | ||
id: "v2.error.required" | ||
} | ||
@@ -1272,10 +1237,10 @@ } | ||
}) { | ||
const rawError = mapFieldTypeToZod(field2.type, field2.required).safeParse( | ||
value, | ||
{ | ||
// @ts-expect-error | ||
errorMap: zodToIntlErrorMap | ||
} | ||
); | ||
return rawError.error?.issues.map((issue) => issue.message) ?? []; | ||
const error = mapFieldTypeToZod(field2.type, field2.required).safeParse(value, { | ||
// @ts-expect-error | ||
errorMap: zodToIntlErrorMap | ||
}).error?.format(); | ||
if (!error) { | ||
return []; | ||
} | ||
return error._errors; | ||
} | ||
@@ -1282,0 +1247,0 @@ |
{ | ||
"name": "@opencrvs/toolkit", | ||
"version": "1.7.0-rc.cb767c2", | ||
"version": "1.7.0-rc.d303b86", | ||
"description": "OpenCRVS toolkit for building country configurations", | ||
@@ -5,0 +5,0 @@ "license": "MPL-2.0", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
1173582
-7.72%31024
-11.83%