@webitel/api-services 26.8.64 → 26.8.65

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/api-services",
3
- "version": "26.8.64",
3
+ "version": "26.8.65",
4
4
  "private": false,
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,9 +1,13 @@
1
+ import { getShallowFieldsToSendFromZodSchema } from '@webitel/api-services/gen/utils';
1
2
  import { FormatDateMode } from '../../../enums';
2
- import { getAgentService } from '../../../gen-wire';
3
- // @author @Lera
4
- // fixme: change on library
5
- // https://webitel.atlassian.net/browse/WTEL-7842?focusedCommentId=702198
6
- //
3
+ import {
4
+ CreateAgentBody,
5
+ getAgentService,
6
+ PatchAgentBody,
7
+ SearchAgentQueryParams,
8
+ SearchUserStatusQueryParams,
9
+ UpdateAgentBody,
10
+ } from '../../../gen-wire';
7
11
  import { convertDuration, normalizeDatetimeRange } from '../../../scripts';
8
12
  import { formatDate } from '../../../utils';
9
13
  import { getDefaultGetListResponse, getDefaultGetParams } from '../../defaults';
@@ -13,7 +17,7 @@ import {
13
17
  merge,
14
18
  mergeEach,
15
19
  notify,
16
- sanitize,
20
+ sanitizeToWire,
17
21
  snakeToCamel,
18
22
  starToSearch,
19
23
  } from '../../transformers';
@@ -42,27 +46,9 @@ const getAgentsList = async (params: ApiParams) => {
42
46
  statusDuration: convertStatusDuration(item.statusDuration),
43
47
  }));
44
48
  };
45
- const fieldsToSend = [
46
- 'page',
47
- 'size',
48
- 'q',
49
- 'sort',
50
- 'fields',
51
- 'id',
52
- 'allow_channels',
53
- 'team_id',
54
- 'region_id',
55
- 'auditor_id',
56
- 'skill_id',
57
- 'queue_id',
58
- 'is_supervisor',
59
- 'not_supervisor',
60
- 'user_id',
61
- 'not_team_id',
62
- 'supervisor_id',
63
- 'not_skill_id',
64
- 'not_user_id',
65
- ];
49
+ const fieldsToSend = getShallowFieldsToSendFromZodSchema(
50
+ SearchAgentQueryParams,
51
+ );
66
52
  const requestParams = applyTransform(params, [
67
53
  camelToSnake(),
68
54
  merge(getDefaultGetParams()),
@@ -78,7 +64,7 @@ const getAgentsList = async (params: ApiParams) => {
78
64
  skill_id: params.skill_id ?? params.skill,
79
65
  not_supervisor: params.not_supervisor ?? params.is_not_supervisor,
80
66
  }),
81
- sanitize(fieldsToSend),
67
+ sanitizeToWire(fieldsToSend),
82
68
  ]);
83
69
 
84
70
  try {
@@ -138,24 +124,9 @@ const getAgent = async ({
138
124
  }
139
125
  };
140
126
 
141
- const fieldsToSend = [
142
- 'user',
143
- 'team',
144
- 'supervisor',
145
- 'auditor',
146
- 'region',
147
- 'greetingMedia',
148
- 'progressiveCount',
149
- 'chatCount',
150
- 'taskCount',
151
- 'isSupervisor',
152
- 'screenControl',
153
- 'extraChatCount',
154
- ];
155
-
156
127
  const addAgent = async ({ itemInstance }: AddItemParams) => {
157
128
  const item = applyTransform(itemInstance, [
158
- sanitize(fieldsToSend),
129
+ sanitizeToWire(getShallowFieldsToSendFromZodSchema(CreateAgentBody)),
159
130
  camelToSnake(),
160
131
  ]);
161
132
  try {
@@ -172,7 +143,7 @@ const addAgent = async ({ itemInstance }: AddItemParams) => {
172
143
 
173
144
  const patchAgent = async ({ changes, id }: PatchItemParams) => {
174
145
  const body = applyTransform(changes, [
175
- sanitize(fieldsToSend),
146
+ sanitizeToWire(getShallowFieldsToSendFromZodSchema(PatchAgentBody)),
176
147
  camelToSnake(),
177
148
  ]);
178
149
  try {
@@ -189,7 +160,7 @@ const patchAgent = async ({ changes, id }: PatchItemParams) => {
189
160
 
190
161
  const updateAgent = async ({ itemInstance, itemId: id }: UpdateItemParams) => {
191
162
  const item = applyTransform(itemInstance, [
192
- sanitize(fieldsToSend),
163
+ sanitizeToWire(getShallowFieldsToSendFromZodSchema(UpdateAgentBody)),
193
164
  camelToSnake(),
194
165
  ]);
195
166
  try {
@@ -380,7 +351,13 @@ const getAgentQueues = async (params: ApiParams) => {
380
351
  merge(getDefaultGetListResponse()),
381
352
  ]);
382
353
  return {
383
- items,
354
+ items: applyTransform(items, [
355
+ mergeEach({
356
+ countMembers: 0,
357
+ waitingMembers: 0,
358
+ type: 0,
359
+ }),
360
+ ]),
384
361
  next,
385
362
  };
386
363
  } catch (err) {
@@ -519,14 +496,9 @@ const getAgentUsersOptions = async (params: ApiParams) => {
519
496
  };
520
497
 
521
498
  const getUsersStatus = async (params: ApiParams) => {
522
- const fieldsToSend = [
523
- 'page',
524
- 'size',
525
- 'q',
526
- 'sort',
527
- 'fields',
528
- 'not_user_id',
529
- ];
499
+ const fieldsToSend = getShallowFieldsToSendFromZodSchema(
500
+ SearchUserStatusQueryParams,
501
+ );
530
502
  const requestParams = applyTransform(params, [
531
503
  camelToSnake(),
532
504
  merge(getDefaultGetParams()),
@@ -535,7 +507,7 @@ const getUsersStatus = async (params: ApiParams) => {
535
507
  ...params,
536
508
  q: params.search,
537
509
  }),
538
- sanitize(fieldsToSend),
510
+ sanitizeToWire(fieldsToSend),
539
511
  ]);
540
512
 
541
513
  try {
@@ -0,0 +1,8 @@
1
+ export const AgentStatus = {
2
+ Online: 'online',
3
+ Offline: 'offline',
4
+ Pause: 'pause',
5
+ BreakOut: 'break_out',
6
+ } as const;
7
+
8
+ export type AgentStatus = (typeof AgentStatus)[keyof typeof AgentStatus];
@@ -0,0 +1,16 @@
1
+ export const ChannelState = {
2
+ Waiting: 'waiting',
3
+ Distribute: 'distribute',
4
+ Offering: 'offering',
5
+ Answered: 'answered',
6
+ Active: 'active',
7
+ Bridged: 'bridged',
8
+ Hold: 'hold',
9
+ Missed: 'missed',
10
+ WrapTime: 'wrap_time',
11
+ Processing: 'processing',
12
+ Transfer: 'transfer',
13
+ Form: 'form',
14
+ } as const;
15
+
16
+ export type ChannelState = (typeof ChannelState)[keyof typeof ChannelState];
@@ -0,0 +1,10 @@
1
+ export const ChannelType = {
2
+ Call: 'call',
3
+ Email: 'email',
4
+ Chat: 'chat',
5
+ Job: 'task',
6
+ OutCall: 'out_call',
7
+ Im: 'im',
8
+ } as const;
9
+
10
+ export type ChannelType = (typeof ChannelType)[keyof typeof ChannelType];
@@ -1,4 +1,7 @@
1
+ import { AgentStatus } from './AgentStatus/AgentStatus';
1
2
  import { CallReportingStatus } from './CallReportingStatus/CallReportingStatus';
3
+ import { ChannelState } from './ChannelState/ChannelState';
4
+ import { ChannelType } from './ChannelType/ChannelType';
2
5
  import { ChatGatewayProvider } from './ChatGatewayProvider/ChatGatewayPrivider';
3
6
  import { FormatDateMode } from './FormatDateMode/FormatDateMode';
4
7
  import { MemberStopCause } from './MemberStopCause/MemberStopCause';
@@ -15,7 +18,10 @@ import { UrlProtocol } from './UrlProtocol/UrlProtocol';
15
18
  import { UserPresenceStatus } from './UserPresenceStatus/UserPresenceStatus';
16
19
 
17
20
  export {
21
+ AgentStatus,
18
22
  CallReportingStatus,
23
+ ChannelState,
24
+ ChannelType,
19
25
  ChatGatewayProvider,
20
26
  FormatDateMode,
21
27
  MemberStopCause,
@@ -1,9 +1,3 @@
1
- /*
2
- * @author @Lera
3
- * fixme: change on library
4
- * https://webitel.atlassian.net/browse/WTEL-7842?focusedCommentId=702198
5
- * */
6
-
7
1
  export interface ConvertDurationOptions {
8
2
  /**
9
3
  * Keep the hours segment when the duration is under an hour.
@@ -0,0 +1,96 @@
1
+ import { getDefaultsFromZodSchema } from '@webitel/api-services/gen/utils';
2
+ import { describe, expect, it } from 'vitest';
3
+
4
+ import { agentSchema } from '../agent.validations';
5
+
6
+ const filledAgent = {
7
+ user: {
8
+ id: '1',
9
+ name: 'John',
10
+ },
11
+ team: {
12
+ id: 2,
13
+ name: 'Support',
14
+ },
15
+ chatCount: 1,
16
+ taskCount: 1,
17
+ };
18
+
19
+ const issuePaths = (value: Record<string, unknown>) =>
20
+ agentSchema
21
+ .safeParse(value)
22
+ .error?.issues.map((issue) => issue.path.join('.')) ?? [];
23
+
24
+ describe('agentSchema', () => {
25
+ it('seeds a new agent with the defaults the form expects', () => {
26
+ expect(getDefaultsFromZodSchema(agentSchema, {})).toMatchObject({
27
+ supervisor: [],
28
+ auditor: [],
29
+ region: {},
30
+ greetingMedia: {},
31
+ progressiveCount: null,
32
+ chatCount: 1,
33
+ taskCount: 1,
34
+ extraChatCount: 0,
35
+ isSupervisor: false,
36
+ screenControl: false,
37
+ });
38
+ });
39
+
40
+ it('requires a user and a team', () => {
41
+ const paths = issuePaths({
42
+ user: {},
43
+ team: {},
44
+ chatCount: 1,
45
+ taskCount: 1,
46
+ });
47
+
48
+ expect(paths).toContain('user');
49
+ expect(paths).toContain('team');
50
+ });
51
+
52
+ it('requires chat and task counts of at least 1', () => {
53
+ const paths = issuePaths({
54
+ ...filledAgent,
55
+ chatCount: 0,
56
+ taskCount: null,
57
+ });
58
+
59
+ expect(paths).toContain('chatCount');
60
+ expect(paths).toContain('taskCount');
61
+ });
62
+
63
+ it('accepts an emptied progressive count, rejects one below 1', () => {
64
+ expect(
65
+ issuePaths({
66
+ ...filledAgent,
67
+ progressiveCount: null,
68
+ }),
69
+ ).not.toContain('progressiveCount');
70
+ expect(
71
+ issuePaths({
72
+ ...filledAgent,
73
+ progressiveCount: 0,
74
+ }),
75
+ ).toContain('progressiveCount');
76
+ });
77
+
78
+ it('accepts an emptied extra chat count, rejects a negative one', () => {
79
+ expect(
80
+ issuePaths({
81
+ ...filledAgent,
82
+ extraChatCount: null,
83
+ }),
84
+ ).not.toContain('extraChatCount');
85
+ expect(
86
+ issuePaths({
87
+ ...filledAgent,
88
+ extraChatCount: -1,
89
+ }),
90
+ ).toContain('extraChatCount');
91
+ });
92
+
93
+ it('accepts a valid agent', () => {
94
+ expect(agentSchema.safeParse(filledAgent).success).toBe(true);
95
+ });
96
+ });
@@ -0,0 +1,25 @@
1
+ import type { EngineAgent } from '@webitel/api-services/gen/models';
2
+ import { z } from 'zod';
3
+
4
+ import {
5
+ filledLookupSchema,
6
+ flexibleLookupSchema,
7
+ } from '../_shared/lookup.validations';
8
+ import type { ZodShape } from '../types';
9
+
10
+ export const agentSchema = z.object<ZodShape<EngineAgent>>({
11
+ id: z.string().optional(),
12
+ user: filledLookupSchema,
13
+ team: filledLookupSchema,
14
+ supervisor: z.array(flexibleLookupSchema).optional().default([]),
15
+ auditor: z.array(flexibleLookupSchema).optional().default([]),
16
+ region: flexibleLookupSchema.optional().default({}),
17
+ greetingMedia: flexibleLookupSchema.optional().default({}),
18
+ progressiveCount: z.number().min(1).nullable().optional().default(null),
19
+ chatCount: z.number().min(1).default(1),
20
+ taskCount: z.number().min(1).default(1),
21
+ extraChatCount: z.number().min(0).nullable().optional().default(0),
22
+ isSupervisor: z.boolean().optional().default(false),
23
+ screenControl: z.boolean().optional().default(false),
24
+ allowSetScreenControl: z.boolean().optional(),
25
+ });
@@ -0,0 +1,24 @@
1
+ import { describe, expect, it } from 'vitest';
2
+
3
+ import { agentSubordinateSchema } from '../agentSubordinate.validations';
4
+
5
+ describe('agentSubordinateSchema', () => {
6
+ it('requires an agent', () => {
7
+ expect(
8
+ agentSubordinateSchema.safeParse({
9
+ agent: {},
10
+ }).success,
11
+ ).toBe(false);
12
+ });
13
+
14
+ it('accepts a picked agent', () => {
15
+ expect(
16
+ agentSubordinateSchema.safeParse({
17
+ agent: {
18
+ id: '1',
19
+ name: 'John',
20
+ },
21
+ }).success,
22
+ ).toBe(true);
23
+ });
24
+ });
@@ -0,0 +1,7 @@
1
+ import { z } from 'zod';
2
+
3
+ import { filledLookupSchema } from '../_shared/lookup.validations';
4
+
5
+ export const agentSubordinateSchema = z.object({
6
+ agent: filledLookupSchema,
7
+ });
@@ -5,8 +5,10 @@ export * from './_shared/lookup.validations';
5
5
  export * from './_shared/phoneNumber.validations';
6
6
  export * from './_shared/variablePair.validations';
7
7
  export * from './adjunctType/adjunctType.validations';
8
+ export * from './agent/agent.validations';
8
9
  export * from './agentPauseCause/agentPauseCause.validations';
9
10
  export * from './agentSkill/agentSkill.validations';
11
+ export * from './agentSubordinate/agentSubordinate.validations';
10
12
  export * from './auditForm/auditForm.validations';
11
13
  export * from './bucket/bucket.validations';
12
14
  export * from './calendar/calendar.validations';