@webitel/ui-sdk 25.8.7 → 25.8.8
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webitel/ui-sdk",
|
|
3
|
-
"version": "25.8.
|
|
3
|
+
"version": "25.8.8",
|
|
4
4
|
"private": false,
|
|
5
5
|
"scripts": {
|
|
6
6
|
"dev": "npm run docs:dev",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"src/enums/*",
|
|
37
37
|
"src/mixins/*",
|
|
38
38
|
"src/scripts/*",
|
|
39
|
-
"src/validations
|
|
39
|
+
"src/validations/*",
|
|
40
40
|
"src/modules/*",
|
|
41
41
|
"src/plugins/*",
|
|
42
42
|
"src/store/*",
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { ComposerTranslation as I18nComposerTranslation } from 'vue-i18n';
|
|
2
|
+
import { z } from 'zod/v4';
|
|
3
|
+
|
|
4
|
+
import { isEmpty } from '../../../scripts';
|
|
5
|
+
|
|
6
|
+
export const customZodErrorsHandler =
|
|
7
|
+
(t: I18nComposerTranslation) => (issue: z.core.$ZodIssue) => {
|
|
8
|
+
switch (issue.code) {
|
|
9
|
+
case 'too_small':
|
|
10
|
+
return handleTooSmall(issue);
|
|
11
|
+
case 'too_big':
|
|
12
|
+
return handleTooBig(issue);
|
|
13
|
+
case 'invalid_value':
|
|
14
|
+
case 'invalid_type':
|
|
15
|
+
return handleInvalid(issue);
|
|
16
|
+
default:
|
|
17
|
+
return issue.code;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function handleTooSmall(issue: z.core.$ZodIssueTooSmall) {
|
|
21
|
+
const showRequiredMsg = () => {
|
|
22
|
+
return t('validation.required');
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
if (isEmpty(issue.input) as boolean) {
|
|
26
|
+
return showRequiredMsg();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return t('validation.minLength', {
|
|
30
|
+
min: issue.minimum,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function handleTooBig(issue: z.core.$ZodIssueTooBig) {
|
|
35
|
+
return t('validation.maxLength', {
|
|
36
|
+
max: issue.maximum,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function handleInvalid(
|
|
41
|
+
issue: z.core.$ZodIssueInvalidType | z.core.$ZodIssueInvalidValue,
|
|
42
|
+
) {
|
|
43
|
+
if (isEmpty(issue.input)) {
|
|
44
|
+
return t('validation.required');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
console.error('Unknown Invalid Zod issue:', issue);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { z } from 'zod/v4';
|
|
2
|
+
import { ComposerTranslation as I18nComposerTranslation } from 'vue-i18n';
|
|
3
|
+
|
|
4
|
+
import { customZodErrorsHandler } from "./errors/customZodErrorsHandler";
|
|
5
|
+
|
|
6
|
+
export const configureZod = ({ zodInstance, t }: {
|
|
7
|
+
t: I18nComposerTranslation;
|
|
8
|
+
zodInstance?: typeof z;
|
|
9
|
+
}) => {
|
|
10
|
+
const configuredZod = zodInstance || z;
|
|
11
|
+
|
|
12
|
+
configuredZod.config({
|
|
13
|
+
customError: customZodErrorsHandler(t),
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './config';
|