@webitel/ui-sdk 26.8.34 → 26.8.35

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": "26.8.34",
3
+ "version": "26.8.35",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "dev": "npm run docs:dev",
@@ -439,6 +439,9 @@ export default deepmerge(
439
439
  },
440
440
  },
441
441
  validation: {
442
+ hourRange: 'Hours must be from 00 to 23',
443
+ timerangeStartLessThanEnd: 'Time From cannot be greater than To',
444
+ timerangeNotIntersect: 'Time intervals on the same day cannot overlap',
442
445
  required: 'Field is required',
443
446
  numeric: 'Should be numeric',
444
447
  email: 'Should look like email',
@@ -429,6 +429,11 @@ export default {
429
429
  },
430
430
  },
431
431
  validation: {
432
+ hourRange: 'Las horas deben estar entre 00 y 23',
433
+ timerangeStartLessThanEnd:
434
+ 'La hora "Desde" no puede ser posterior a "Hasta"',
435
+ timerangeNotIntersect:
436
+ 'Los intervalos de tiempo del mismo día no pueden superponerse',
432
437
  required: 'Campo requerido',
433
438
  numeric: 'Debe ser numérico',
434
439
  email: 'Debe parecer un correo electrónico',
@@ -432,6 +432,11 @@ export default {
432
432
  },
433
433
  },
434
434
  validation: {
435
+ hourRange: 'Сағат 00-ден 23-ке дейін болуы керек',
436
+ timerangeStartLessThanEnd:
437
+ '"Бастап" уақыты "Дейін" уақытынан кеш болмауы керек',
438
+ timerangeNotIntersect:
439
+ 'Бір күннің уақыт аралықтары бір-бірімен қиыспауы керек',
435
440
  required: 'Өріс міндетті',
436
441
  numeric: 'Сандық болуы керек',
437
442
  email: 'Email сияқты болуы керек',
@@ -432,6 +432,10 @@ export default {
432
432
  },
433
433
  },
434
434
  validation: {
435
+ hourRange: 'Godziny muszą być od 00 do 23',
436
+ timerangeStartLessThanEnd: 'Czas "Od" nie może być późniejszy niż "Do"',
437
+ timerangeNotIntersect:
438
+ 'Interwały czasowe w tym samym dniu nie mogą się nakładać',
435
439
  required: 'Pole jest wymagane',
436
440
  numeric: 'Powinno być numeryczne',
437
441
  email: 'Powinno wyglądać jak email',
@@ -436,6 +436,11 @@ export default {
436
436
  },
437
437
  },
438
438
  validation: {
439
+ hourRange: 'Orele trebuie să fie între 00 și 23',
440
+ timerangeStartLessThanEnd:
441
+ 'Ora "De la" nu poate fi mai târzie decât "Până la"',
442
+ timerangeNotIntersect:
443
+ 'Intervalele de timp din aceeași zi nu se pot suprapune',
439
444
  required: 'Câmpul este obligatoriu',
440
445
  numeric: 'Trebuie să fie numeric',
441
446
  email: 'Trebuie să arate ca un email',
@@ -431,6 +431,10 @@ export default {
431
431
  },
432
432
  },
433
433
  validation: {
434
+ hourRange: 'Часы должны быть от 00 до 23',
435
+ timerangeStartLessThanEnd: 'Время От не может быть больше чем До',
436
+ timerangeNotIntersect:
437
+ 'Временные интервалы в один день не могут пересекаться',
434
438
  required: 'Обязательное поле',
435
439
  numeric: 'Необходимо ввести цифровое значение',
436
440
  email: 'Необходимо ввести адрес электронной почты',
@@ -430,6 +430,9 @@ export default {
430
430
  },
431
431
  },
432
432
  validation: {
433
+ hourRange: 'Години мають бути від 00 до 23',
434
+ timerangeStartLessThanEnd: 'Час Від не може бути більший ніж До',
435
+ timerangeNotIntersect: 'Інтервали часу в один день не можуть перетинатися',
433
436
  required: "Обов'язкове поле",
434
437
  numeric: 'Необхідно ввести цифрові значення',
435
438
  email: 'Необхідно ввести адресу електронної пошти',
@@ -436,6 +436,11 @@ export default {
436
436
  },
437
437
  },
438
438
  validation: {
439
+ hourRange: "Soatlar 00 dan 23 gacha bo'lishi kerak",
440
+ timerangeStartLessThanEnd:
441
+ '"Dan" vaqti "Gacha" vaqtidan kech bo\'lishi mumkin emas',
442
+ timerangeNotIntersect:
443
+ "Bir kundagi vaqt oralig'lari bir-biriga kesilib o'tmasligi kerak",
439
444
  required: "Maydon to'ldirilishi shart",
440
445
  numeric: "Raqam bo'lishi kerak",
441
446
  email: "Email ko'rinishida bo'lishi kerak",
@@ -436,6 +436,10 @@ export default {
436
436
  },
437
437
  },
438
438
  validation: {
439
+ hourRange: 'Giờ phải từ 00 đến 23',
440
+ timerangeStartLessThanEnd: 'Thời gian "Từ" không được muộn hơn "Đến"',
441
+ timerangeNotIntersect:
442
+ 'Các khoảng thời gian trong cùng một ngày không được chồng chéo',
439
443
  required: 'Trường bắt buộc',
440
444
  numeric: 'Phải là số',
441
445
  email: 'Phải là email',
@@ -1,5 +1,10 @@
1
1
  import { SortSymbols } from '../../../scripts/sortQueryAdapters';
2
2
 
3
+ /**
4
+ * `field` is what goes into the `fields` query of `GET <object>/:id/acl`, where
5
+ * the three rule columns all come from one `granted` string — the store asks
6
+ * for it once. The rule letters (`r`, `w`, `d`) are not attributes there.
7
+ */
3
8
  export const headers = [
4
9
  {
5
10
  value: 'grantee',
@@ -0,0 +1,103 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import type { ComposerTranslation } from 'vue-i18n';
3
+ import { z } from 'zod/v4';
4
+
5
+ import { customZodErrorsHandler } from '../customZodErrorsHandler';
6
+
7
+ /** echoes the key so assertions read as "which key was asked for" */
8
+ const t = ((key: string, params?: Record<string, unknown>) =>
9
+ params ? `${key}:${JSON.stringify(params)}` : key) as ComposerTranslation;
10
+
11
+ /** the handler is installed globally, the same way `configureZod` does it */
12
+ const parseWith = <T extends z.ZodType>(schema: T, value: unknown) => {
13
+ z.config({
14
+ customError: customZodErrorsHandler(t),
15
+ });
16
+
17
+ return schema.safeParse(value);
18
+ };
19
+
20
+ const messagesOf = (result: z.ZodSafeParseResult<unknown>) =>
21
+ result.success ? [] : result.error.issues.map((issue) => issue.message);
22
+
23
+ describe('customZodErrorsHandler', () => {
24
+ it('translates a custom rule by its i18nKey param', () => {
25
+ const schema = z.number().refine((value) => value < 10, {
26
+ params: {
27
+ i18nKey: 'hourRange',
28
+ },
29
+ });
30
+
31
+ expect(messagesOf(parseWith(schema, 100))).toEqual([
32
+ 'validation.hourRange',
33
+ ]);
34
+ });
35
+
36
+ it('translates a custom rule reported from superRefine', () => {
37
+ const schema = z
38
+ .object({
39
+ start: z.number(),
40
+ })
41
+ .superRefine((_, ctx) => {
42
+ ctx.addIssue({
43
+ code: 'custom',
44
+ path: [
45
+ 'start',
46
+ ],
47
+ params: {
48
+ i18nKey: 'timerangeStartLessThanEnd',
49
+ },
50
+ });
51
+ });
52
+
53
+ expect(
54
+ messagesOf(
55
+ parseWith(schema, {
56
+ start: 1,
57
+ }),
58
+ ),
59
+ ).toEqual([
60
+ 'validation.timerangeStartLessThanEnd',
61
+ ]);
62
+ });
63
+
64
+ it('leaves a custom rule without an i18nKey to zod', () => {
65
+ const schema = z.number().refine((value) => value < 10);
66
+
67
+ expect(messagesOf(parseWith(schema, 100))).toEqual([
68
+ 'Invalid input',
69
+ ]);
70
+ });
71
+
72
+ it('still reports an empty required field as required', () => {
73
+ const schema = z.object({
74
+ name: z.string().min(1),
75
+ });
76
+
77
+ expect(
78
+ messagesOf(
79
+ parseWith(schema, {
80
+ name: '',
81
+ }),
82
+ ),
83
+ ).toEqual([
84
+ 'validation.required',
85
+ ]);
86
+ });
87
+
88
+ it('reports a too short string by length', () => {
89
+ const schema = z.object({
90
+ name: z.string().min(3),
91
+ });
92
+
93
+ expect(
94
+ messagesOf(
95
+ parseWith(schema, {
96
+ name: 'ab',
97
+ }),
98
+ ),
99
+ ).toEqual([
100
+ 'validation.minLength:{"min":3}',
101
+ ]);
102
+ });
103
+ });
@@ -13,10 +13,24 @@ export const customZodErrorsHandler =
13
13
  case 'invalid_value':
14
14
  case 'invalid_type':
15
15
  return handleInvalid(issue);
16
+ case 'custom':
17
+ return handleCustom(issue);
16
18
  default:
17
19
  return issue.code;
18
20
  }
19
21
 
22
+ /**
23
+ * Schemas outside the app (`@webitel/api-services/validations`) cannot
24
+ * translate, so a custom rule reports its message key through
25
+ * `params.i18nKey` — see the `i18nIssue` helper there. Anything else falls
26
+ * back to zod's own message.
27
+ */
28
+ function handleCustom(issue: z.core.$ZodRawIssue<z.core.$ZodIssueCustom>) {
29
+ const key = issue.params?.i18nKey;
30
+
31
+ return typeof key === 'string' ? t(`validation.${key}`) : undefined;
32
+ }
33
+
20
34
  function handleTooSmall(
21
35
  issue: z.core.$ZodRawIssue<z.core.$ZodIssueTooSmall>,
22
36
  ) {