@webitel/ui-sdk 26.8.34 → 26.8.36

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.
Files changed (42) hide show
  1. package/package.json +1 -1
  2. package/src/locale/en/en.js +7 -0
  3. package/src/locale/es/es.js +9 -0
  4. package/src/locale/kz/kz.js +9 -0
  5. package/src/locale/pl/pl.js +8 -0
  6. package/src/locale/ro/ro.js +9 -0
  7. package/src/locale/ru/ru.js +8 -0
  8. package/src/locale/uk/uk.js +7 -0
  9. package/src/locale/uz/uz.js +9 -0
  10. package/src/locale/vi/vi.js +8 -0
  11. package/src/modules/AgentStatusSelect/api/agent-status.js +2 -0
  12. package/src/modules/AgentStatusSelect/components/_internals/wt-cc-activity-type-popup.vue +104 -0
  13. package/src/modules/AgentStatusSelect/components/wt-cc-agent-status-select.vue +148 -37
  14. package/src/modules/AgentStatusSelect/composables/useCCenterModeSwitcher.ts +43 -0
  15. package/src/modules/AgentStatusSelect/types/StatusChangePayload.types.ts +9 -0
  16. package/src/modules/AgentStatusSelect/types/UseCCenterModeSwitcherParams.types.ts +9 -0
  17. package/src/modules/ObjectPermissions/headers/headers.ts +5 -0
  18. package/src/types/LookupOption.types.ts +4 -0
  19. package/src/types/index.ts +1 -0
  20. package/src/validations/config/errors/__tests__/customZodErrorsHandler.spec.ts +103 -0
  21. package/src/validations/config/errors/customZodErrorsHandler.ts +14 -0
  22. package/types/.tsbuildinfo +1 -1
  23. package/types/locale/en/en.d.ts +7 -0
  24. package/types/locale/es/es.d.ts +10 -2
  25. package/types/locale/i18n.d.ts +63 -0
  26. package/types/locale/index.d.ts +63 -0
  27. package/types/locale/kz/kz.d.ts +10 -2
  28. package/types/locale/pl/pl.d.ts +10 -2
  29. package/types/locale/ro/ro.d.ts +10 -2
  30. package/types/locale/ru/ru.d.ts +10 -2
  31. package/types/locale/uk/uk.d.ts +10 -2
  32. package/types/locale/uz/uz.d.ts +10 -2
  33. package/types/locale/vi/vi.d.ts +10 -2
  34. package/types/modules/AgentStatusSelect/api/agent-status.d.ts +2 -1
  35. package/types/modules/AgentStatusSelect/components/_internals/wt-cc-activity-type-popup.vue.d.ts +15 -0
  36. package/types/modules/AgentStatusSelect/components/wt-cc-agent-status-select.vue.d.ts +21 -32
  37. package/types/modules/AgentStatusSelect/composables/useCCenterModeSwitcher.d.ts +5 -0
  38. package/types/modules/AgentStatusSelect/types/StatusChangePayload.types.d.ts +8 -0
  39. package/types/modules/AgentStatusSelect/types/UseCCenterModeSwitcherParams.types.d.ts +8 -0
  40. package/types/modules/ObjectPermissions/headers/headers.d.ts +5 -0
  41. package/types/types/LookupOption.types.d.ts +4 -0
  42. package/types/types/index.d.ts +1 -0
@@ -0,0 +1,4 @@
1
+ export type LookupOption = {
2
+ id: string | number;
3
+ name: string;
4
+ };
@@ -1 +1,2 @@
1
+ export type { LookupOption } from './LookupOption.types';
1
2
  export type { ResultCallbacks } from './ResultCallbacks.types';
@@ -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
  ) {