@webitel/api-services 26.8.70 → 26.8.72

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 (55) hide show
  1. package/package.json +1 -1
  2. package/src/api/clients/outboundResources/outboundResources.ts +44 -81
  3. package/src/api/clients/outboundResources/resourceDisplays.ts +106 -32
  4. package/src/enums/ResourceCidType/ResourceCidType.ts +8 -0
  5. package/src/enums/ResourceIgnoreEarlyMedia/ResourceIgnoreEarlyMedia.ts +9 -0
  6. package/src/enums/index.ts +4 -0
  7. package/src/locale/en/en.ts +4 -0
  8. package/src/locale/es/es.ts +4 -0
  9. package/src/locale/kz/kz.ts +4 -0
  10. package/src/locale/pl/pl.ts +4 -0
  11. package/src/locale/ro/ro.ts +4 -0
  12. package/src/locale/ru/ru.ts +4 -0
  13. package/src/locale/uk/uk.ts +4 -0
  14. package/src/locale/uz/uz.ts +4 -0
  15. package/src/locale/vi/vi.ts +4 -0
  16. package/src/scripts/convertTimeUnits/__tests__/convertTimeUnits.spec.ts +19 -0
  17. package/src/scripts/convertTimeUnits/convertTimeUnits.ts +3 -0
  18. package/src/scripts/index.ts +3 -0
  19. package/src/validations/_shared/timeRange.validations.ts +103 -0
  20. package/src/validations/calendar/__tests__/calendar.validations.spec.ts +9 -9
  21. package/src/validations/calendar/calendar.validations.ts +10 -131
  22. package/src/validations/index.ts +5 -0
  23. package/src/validations/resource/__tests__/resource.validations.spec.ts +102 -0
  24. package/src/validations/resource/resource.validations.ts +28 -0
  25. package/src/validations/resourceDisplay/__tests__/resourceDisplay.validations.spec.ts +45 -0
  26. package/src/validations/resourceDisplay/resourceDisplay.validations.ts +9 -0
  27. package/src/validations/resourceGroup/__tests__/resourceGroup.validations.spec.ts +191 -0
  28. package/src/validations/resourceGroup/resourceGroup.validations.ts +36 -0
  29. package/src/validations/resourceInGroup/__tests__/resourceInGroup.validations.spec.ts +38 -0
  30. package/src/validations/resourceInGroup/resourceInGroup.validations.ts +16 -0
  31. package/types/.tsbuildinfo +1 -1
  32. package/types/api/clients/outboundResources/outboundResources.d.ts +2 -7
  33. package/types/api/clients/outboundResources/resourceDisplays.d.ts +7 -1
  34. package/types/enums/ResourceCidType/ResourceCidType.d.ts +6 -0
  35. package/types/enums/ResourceIgnoreEarlyMedia/ResourceIgnoreEarlyMedia.d.ts +7 -0
  36. package/types/enums/index.d.ts +3 -1
  37. package/types/locale/en/en.d.ts +3 -0
  38. package/types/locale/es/es.d.ts +3 -0
  39. package/types/locale/index.d.ts +27 -0
  40. package/types/locale/kz/kz.d.ts +3 -0
  41. package/types/locale/pl/pl.d.ts +3 -0
  42. package/types/locale/ro/ro.d.ts +3 -0
  43. package/types/locale/ru/ru.d.ts +3 -0
  44. package/types/locale/uk/uk.d.ts +3 -0
  45. package/types/locale/uz/uz.d.ts +3 -0
  46. package/types/locale/vi/vi.d.ts +3 -0
  47. package/types/scripts/convertTimeUnits/convertTimeUnits.d.ts +2 -0
  48. package/types/scripts/index.d.ts +2 -1
  49. package/types/validations/_shared/timeRange.validations.d.ts +18 -0
  50. package/types/validations/calendar/calendar.validations.d.ts +1 -7
  51. package/types/validations/index.d.ts +5 -0
  52. package/types/validations/resource/resource.validations.d.ts +26 -0
  53. package/types/validations/resourceDisplay/resourceDisplay.validations.d.ts +5 -0
  54. package/types/validations/resourceGroup/resourceGroup.validations.d.ts +17 -0
  55. package/types/validations/resourceInGroup/resourceInGroup.validations.d.ts +8 -0
@@ -0,0 +1,191 @@
1
+ import { getDefaultsFromZodSchema } from '@webitel/api-services/gen/utils';
2
+ import { describe, expect, it } from 'vitest';
3
+ import type { z } from 'zod';
4
+
5
+ import {
6
+ getResourceGroupTimeRangeErrors,
7
+ resourceGroupSchema,
8
+ } from '../resourceGroup.validations';
9
+
10
+ const issueKey = (issue: z.core.$ZodIssue) =>
11
+ issue.code === 'custom' ? issue.params?.i18nKey : undefined;
12
+
13
+ const communication = {
14
+ id: '1',
15
+ name: 'Phone',
16
+ };
17
+
18
+ const validInput = {
19
+ name: 'Group',
20
+ communication,
21
+ time: [
22
+ {
23
+ start: 540,
24
+ end: 1200,
25
+ },
26
+ ],
27
+ };
28
+
29
+ describe('resourceGroupSchema', () => {
30
+ it('seeds a new group with one 9:00-20:00 range', () => {
31
+ expect(getDefaultsFromZodSchema(resourceGroupSchema, {})).toMatchObject({
32
+ description: '',
33
+ time: [
34
+ {
35
+ start: 540,
36
+ end: 1200,
37
+ },
38
+ ],
39
+ });
40
+ });
41
+
42
+ it('accepts a filled group', () => {
43
+ expect(resourceGroupSchema.safeParse(validInput).success).toBe(true);
44
+ });
45
+
46
+ it('requires name and communication', () => {
47
+ const result = resourceGroupSchema.safeParse({
48
+ ...validInput,
49
+ name: '',
50
+ communication: {},
51
+ });
52
+
53
+ const paths = result.error?.issues.map((issue) => issue.path.join('.'));
54
+ expect(paths).toContain('name');
55
+ expect(paths).toContain('communication');
56
+ });
57
+
58
+ it('requires at least one time range', () => {
59
+ const result = resourceGroupSchema.safeParse({
60
+ ...validInput,
61
+ time: [],
62
+ });
63
+
64
+ expect(result.success).toBe(false);
65
+ });
66
+
67
+ it('rejects a range that starts after it ends', () => {
68
+ const result = resourceGroupSchema.safeParse({
69
+ ...validInput,
70
+ time: [
71
+ {
72
+ start: 600,
73
+ end: 540,
74
+ },
75
+ ],
76
+ });
77
+
78
+ expect(result.error?.issues.map(issueKey)).toContain(
79
+ 'timerangeStartLessThanEnd',
80
+ );
81
+ });
82
+
83
+ it('rejects intersecting ranges', () => {
84
+ const result = resourceGroupSchema.safeParse({
85
+ ...validInput,
86
+ time: [
87
+ {
88
+ start: 540,
89
+ end: 720,
90
+ },
91
+ {
92
+ start: 600,
93
+ end: 800,
94
+ },
95
+ ],
96
+ });
97
+
98
+ expect(result.error?.issues.map(issueKey)).toContain(
99
+ 'timerangeNotIntersect',
100
+ );
101
+ });
102
+ });
103
+
104
+ describe('getResourceGroupTimeRangeErrors', () => {
105
+ it('returns nothing for valid ranges', () => {
106
+ expect(
107
+ getResourceGroupTimeRangeErrors([
108
+ {
109
+ start: 540,
110
+ end: 600,
111
+ },
112
+ {
113
+ start: 700,
114
+ end: 800,
115
+ },
116
+ ]),
117
+ ).toEqual([]);
118
+ });
119
+
120
+ it('reports a reversed range on both its ends', () => {
121
+ expect(
122
+ getResourceGroupTimeRangeErrors([
123
+ {
124
+ start: 600,
125
+ end: 540,
126
+ },
127
+ ]),
128
+ ).toEqual([
129
+ {
130
+ index: 0,
131
+ prop: 'start',
132
+ key: 'timerangeStartLessThanEnd',
133
+ },
134
+ {
135
+ index: 0,
136
+ prop: 'end',
137
+ key: 'timerangeStartLessThanEnd',
138
+ },
139
+ ]);
140
+ });
141
+
142
+ it('reports both ends of every intersecting range', () => {
143
+ const errors = getResourceGroupTimeRangeErrors([
144
+ {
145
+ start: 540,
146
+ end: 720,
147
+ },
148
+ {
149
+ start: 1000,
150
+ end: 1100,
151
+ },
152
+ {
153
+ start: 600,
154
+ end: 800,
155
+ },
156
+ ]);
157
+
158
+ expect(errors).toEqual(
159
+ expect.arrayContaining([
160
+ {
161
+ index: 0,
162
+ prop: 'start',
163
+ key: 'timerangeNotIntersect',
164
+ },
165
+ {
166
+ index: 2,
167
+ prop: 'end',
168
+ key: 'timerangeNotIntersect',
169
+ },
170
+ ]),
171
+ );
172
+ expect(errors.some(({ index }) => index === 1)).toBe(false);
173
+ });
174
+
175
+ it('reports a minute outside the day', () => {
176
+ expect(
177
+ getResourceGroupTimeRangeErrors([
178
+ {
179
+ start: 0,
180
+ end: 1440,
181
+ },
182
+ ]),
183
+ ).toEqual([
184
+ {
185
+ index: 0,
186
+ prop: 'end',
187
+ key: 'hourRange',
188
+ },
189
+ ]);
190
+ });
191
+ });
@@ -0,0 +1,36 @@
1
+ import type { EngineOutboundResourceGroup } from '@webitel/api-services/gen/models';
2
+ import { z } from 'zod';
3
+ import { filledLookupSchema } from '../_shared/lookup.validations';
4
+ import {
5
+ getTimeRangeErrors,
6
+ refineTimeRangesNotIntersect,
7
+ type TimeRange,
8
+ timeRangeSchema,
9
+ } from '../_shared/timeRange.validations';
10
+ import type { ZodShape } from '../types';
11
+
12
+ const timeRangesUiArraySchema = z
13
+ .array(timeRangeSchema)
14
+ .min(1)
15
+ .superRefine(refineTimeRangesNotIntersect());
16
+
17
+ export const getResourceGroupTimeRangeErrors = (items: unknown) =>
18
+ getTimeRangeErrors(timeRangesUiArraySchema, items);
19
+
20
+ export const getDefaultResourceGroupTimeRange = (): TimeRange => ({
21
+ start: 9 * 60,
22
+ end: 20 * 60,
23
+ });
24
+
25
+ export const resourceGroupSchema = z.object<
26
+ ZodShape<EngineOutboundResourceGroup> & {
27
+ time?: z.ZodType;
28
+ }
29
+ >({
30
+ name: z.string().min(1),
31
+ communication: filledLookupSchema,
32
+ description: z.string().optional().default(''),
33
+ time: timeRangesUiArraySchema.default(() => [
34
+ getDefaultResourceGroupTimeRange(),
35
+ ]),
36
+ });
@@ -0,0 +1,38 @@
1
+ import { getDefaultsFromZodSchema } from '@webitel/api-services/gen/utils';
2
+ import { describe, expect, it } from 'vitest';
3
+
4
+ import { resourceInGroupSchema } from '../resourceInGroup.validations';
5
+
6
+ const resource = {
7
+ id: '1',
8
+ name: 'Gateway',
9
+ };
10
+
11
+ describe('resourceInGroupSchema', () => {
12
+ it('seeds a new resource with priority 0', () => {
13
+ expect(getDefaultsFromZodSchema(resourceInGroupSchema, {})).toMatchObject({
14
+ priority: 0,
15
+ reserveResource: {},
16
+ });
17
+ });
18
+
19
+ it('requires a resource', () => {
20
+ const result = resourceInGroupSchema.safeParse({
21
+ resource: {},
22
+ });
23
+
24
+ expect(result.error?.issues.map((issue) => issue.path.join('.'))).toContain(
25
+ 'resource',
26
+ );
27
+ });
28
+
29
+ it('lets priority and reserve resource be cleared', () => {
30
+ expect(
31
+ resourceInGroupSchema.safeParse({
32
+ resource,
33
+ priority: null,
34
+ reserveResource: null,
35
+ }).success,
36
+ ).toBe(true);
37
+ });
38
+ });
@@ -0,0 +1,16 @@
1
+ import type { EngineOutboundResourceInGroup } from '@webitel/api-services/gen/models';
2
+ import { z } from 'zod';
3
+ import { clearableNumberSchema } from '../_shared/clearableNumber.validations';
4
+ import {
5
+ filledLookupSchema,
6
+ flexibleLookupSchema,
7
+ } from '../_shared/lookup.validations';
8
+ import type { ZodShape } from '../types';
9
+
10
+ export const resourceInGroupSchema = z.object<
11
+ ZodShape<EngineOutboundResourceInGroup>
12
+ >({
13
+ resource: filledLookupSchema,
14
+ reserveResource: flexibleLookupSchema.nullish().default({}),
15
+ priority: clearableNumberSchema.default(0),
16
+ });