@webitel/api-services 1.0.10 → 1.0.12

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 (102) hide show
  1. package/package.json +1 -1
  2. package/src/api/clients/__tests__/wireParamsCoverage.spec.ts +286 -0
  3. package/src/api/clients/activeCalls/activeCalls.ts +72 -0
  4. package/src/api/clients/agentPauseCauses/agentPauseCauses.ts +182 -0
  5. package/src/api/clients/agentSkills/agentSkills.ts +193 -0
  6. package/src/api/clients/agents/__tests__/agents.wireParams.spec.ts +51 -0
  7. package/src/api/clients/agents/agents.ts +203 -18
  8. package/src/api/clients/auditForms/auditForms.ts +6 -2
  9. package/src/api/clients/auditForms/auditRates.ts +91 -0
  10. package/src/api/clients/backendProfiles/backendProfiles.ts +194 -0
  11. package/src/api/clients/buckets/buckets.ts +21 -25
  12. package/src/api/clients/callHistory/callAnnotations.ts +91 -0
  13. package/src/api/clients/callHistory/callHistory.ts +76 -7
  14. package/src/api/clients/casePriorities/__tests__/casePriorities.spec.ts +50 -0
  15. package/src/api/clients/casePriorities/casePriorities.ts +25 -41
  16. package/src/api/clients/caseStatusConditions/caseStatusConditions.ts +19 -29
  17. package/src/api/clients/caseStatuses/caseStatuses.ts +10 -21
  18. package/src/api/clients/catalog/catalog.ts +2 -8
  19. package/src/api/clients/changelogs/changelogs.ts +8 -0
  20. package/src/api/clients/chatplans/chatplans.ts +173 -0
  21. package/src/api/clients/cognitiveProfiles/cognitiveProfiles.ts +209 -0
  22. package/src/api/clients/communications/communications.ts +38 -42
  23. package/src/api/clients/dialplans/dialplans.ts +197 -0
  24. package/src/api/clients/emailProfiles/emailProfiles.ts +222 -0
  25. package/src/api/clients/fileServices/fileServices.ts +7 -2
  26. package/src/api/clients/flows/flow.ts +54 -43
  27. package/src/api/clients/fts/fts.ts +61 -0
  28. package/src/api/clients/history/transcript/callTranscript.ts +10 -20
  29. package/src/api/clients/importTemplates/importTemplates.ts +180 -0
  30. package/src/api/clients/index.ts +30 -0
  31. package/src/api/clients/lists/blacklistNumbers.ts +155 -0
  32. package/src/api/clients/lists/blacklists.ts +20 -25
  33. package/src/api/clients/logs/logs.ts +157 -0
  34. package/src/api/clients/media/media.ts +19 -15
  35. package/src/api/clients/object/object.ts +3 -14
  36. package/src/api/clients/outboundResourceGroups/outboundResourceGroups.ts +187 -0
  37. package/src/api/clients/outboundResourceGroups/resourcesInGroup.ts +169 -0
  38. package/src/api/clients/outboundResources/outboundResources.ts +225 -0
  39. package/src/api/clients/outboundResources/resourceDisplays.ts +165 -0
  40. package/src/api/clients/pauseTemplates/pauseTemplates.ts +203 -0
  41. package/src/api/clients/queues/__tests__/queueLogs.spec.ts +3 -3
  42. package/src/api/clients/queues/__tests__/queueMembers.spec.ts +4 -4
  43. package/src/api/clients/queues/queueLogs.ts +8 -3
  44. package/src/api/clients/queues/queueMembers.ts +3 -3
  45. package/src/api/clients/queues/queues.ts +52 -0
  46. package/src/api/clients/regions/regions.ts +21 -25
  47. package/src/api/clients/schemaVariables/schemaVariables.ts +167 -0
  48. package/src/api/clients/shiftTemplates/shiftTemplates.ts +176 -0
  49. package/src/api/clients/skills/skillAgents.ts +190 -0
  50. package/src/api/clients/skills/skills.ts +21 -25
  51. package/src/api/clients/storagePolicies/storagePolicies.ts +270 -0
  52. package/src/api/clients/teamHooks/teamHooks.ts +195 -0
  53. package/src/api/clients/teamTriggers/agentTriggers.ts +77 -0
  54. package/src/api/clients/teamTriggers/teamFlows.ts +194 -0
  55. package/src/api/clients/teams/teams.ts +31 -31
  56. package/src/api/clients/triggers/triggerJobs.ts +63 -0
  57. package/src/api/clients/triggers/triggers.ts +266 -0
  58. package/src/api/clients/userSettings/userSettings.ts +8 -9
  59. package/src/api/clients/users/users.ts +2 -0
  60. package/src/api/clients/workingConditions/workingConditions.ts +184 -0
  61. package/src/api/clients/workspaceWidgets/workspaceWidgets.ts +73 -0
  62. package/src/api/clients//321/201ontacts/contactChatMessagesHistory.ts +15 -26
  63. package/src/validations/calendar/__tests__/calendar.validations.spec.ts +85 -0
  64. package/src/validations/calendar/calendar.validations.ts +1 -1
  65. package/types/.tsbuildinfo +1 -1
  66. package/types/api/clients/activeCalls/activeCalls.d.ts +7 -0
  67. package/types/api/clients/agentPauseCauses/agentPauseCauses.d.ts +21 -0
  68. package/types/api/clients/agentSkills/agentSkills.d.ts +12 -0
  69. package/types/api/clients/agents/agents.d.ts +23 -2
  70. package/types/api/clients/auditForms/auditForms.d.ts +7 -0
  71. package/types/api/clients/auditForms/auditRates.d.ts +10 -0
  72. package/types/api/clients/backendProfiles/backendProfiles.d.ts +21 -0
  73. package/types/api/clients/callHistory/callAnnotations.d.ts +12 -0
  74. package/types/api/clients/callHistory/callHistory.d.ts +24 -3
  75. package/types/api/clients/chatplans/chatplans.d.ts +21 -0
  76. package/types/api/clients/cognitiveProfiles/cognitiveProfiles.d.ts +21 -0
  77. package/types/api/clients/dialplans/dialplans.d.ts +16 -0
  78. package/types/api/clients/emailProfiles/emailProfiles.d.ts +27 -0
  79. package/types/api/clients/fileServices/fileServices.d.ts +1 -1
  80. package/types/api/clients/fts/fts.d.ts +7 -0
  81. package/types/api/clients/importTemplates/importTemplates.d.ts +21 -0
  82. package/types/api/clients/index.d.ts +30 -0
  83. package/types/api/clients/lists/blacklistNumbers.d.ts +11 -0
  84. package/types/api/clients/logs/logs.d.ts +15 -0
  85. package/types/api/clients/outboundResourceGroups/outboundResourceGroups.d.ts +20 -0
  86. package/types/api/clients/outboundResourceGroups/resourcesInGroup.d.ts +11 -0
  87. package/types/api/clients/outboundResources/outboundResources.d.ts +21 -0
  88. package/types/api/clients/outboundResources/resourceDisplays.d.ts +11 -0
  89. package/types/api/clients/pauseTemplates/pauseTemplates.d.ts +20 -0
  90. package/types/api/clients/queues/queues.d.ts +5 -0
  91. package/types/api/clients/schemaVariables/schemaVariables.d.ts +21 -0
  92. package/types/api/clients/shiftTemplates/shiftTemplates.d.ts +20 -0
  93. package/types/api/clients/skills/skillAgents.d.ts +13 -0
  94. package/types/api/clients/storagePolicies/storagePolicies.d.ts +26 -0
  95. package/types/api/clients/teamHooks/teamHooks.d.ts +12 -0
  96. package/types/api/clients/teamTriggers/agentTriggers.d.ts +23 -0
  97. package/types/api/clients/teamTriggers/teamFlows.d.ts +12 -0
  98. package/types/api/clients/triggers/triggerJobs.d.ts +7 -0
  99. package/types/api/clients/triggers/triggers.d.ts +22 -0
  100. package/types/api/clients/userSettings/userSettings.d.ts +2 -2
  101. package/types/api/clients/workingConditions/workingConditions.d.ts +20 -0
  102. package/types/api/clients/workspaceWidgets/workspaceWidgets.d.ts +3 -0
@@ -287,6 +287,57 @@ export {
287
287
  QueueTypeDefaults,
288
288
  } from './defaults/queueTypeDefaults';
289
289
 
290
+ /**
291
+ * Aggregated queue performance over a joined-at window — the supervisor queues
292
+ * table. Percentages and durations come back raw.
293
+ */
294
+ const getQueuesReportGeneral = async (params: ApiParams) => {
295
+ const {
296
+ page,
297
+ size,
298
+ joinedAtFrom,
299
+ joinedAtTo,
300
+ fields,
301
+ sort,
302
+ search,
303
+ queue,
304
+ team,
305
+ queueType,
306
+ } = applyTransform(params, [
307
+ merge(getDefaultGetParams()),
308
+ starToSearch('search'),
309
+ ]);
310
+
311
+ try {
312
+ const response = await getQueueService().searchQueueReportGeneral({
313
+ page,
314
+ size,
315
+ 'joined_at.from': joinedAtFrom,
316
+ 'joined_at.to': joinedAtTo,
317
+ fields,
318
+ sort,
319
+ // the generated param is `q`; `search` is what the datalist store sends
320
+ q: search,
321
+ queue_id: queue,
322
+ team_id: team,
323
+ type: queueType,
324
+ });
325
+ const { items, next, aggs } = applyTransform(response.data, [
326
+ snakeToCamel(),
327
+ merge(getDefaultGetListResponse()),
328
+ ]);
329
+ return {
330
+ items,
331
+ aggs,
332
+ next,
333
+ };
334
+ } catch (err) {
335
+ throw applyTransform(err, [
336
+ notify,
337
+ ]);
338
+ }
339
+ };
340
+
290
341
  export const QueuesAPI = {
291
342
  getList: getQueuesList,
292
343
  get: getQueue,
@@ -296,6 +347,7 @@ export const QueuesAPI = {
296
347
  delete: deleteQueue,
297
348
  getLookup: getQueuesLookup,
298
349
  getQueuesTags,
350
+ getReportGeneral: getQueuesReportGeneral,
299
351
  // `getPermissionsList` + `patchPermissions`, the pair PermissionsApiModule
300
352
  // adapts for ui-datalist's permissions page.
301
353
  ...generatePermissionsApi(baseUrl),
@@ -1,10 +1,5 @@
1
- import { RegionServiceApiFactory } from 'webitel-sdk';
2
- import {
3
- getDefaultGetListResponse,
4
- getDefaultGetParams,
5
- getDefaultInstance,
6
- getDefaultOpenAPIConfig,
7
- } from '../../defaults';
1
+ import { getRegionService } from '../../../gen-wire';
2
+ import { getDefaultGetListResponse, getDefaultGetParams } from '../../defaults';
8
3
  import {
9
4
  applyTransform,
10
5
  camelToSnake,
@@ -22,26 +17,27 @@ import type {
22
17
  UpdateItemParams,
23
18
  } from '../_shared/types';
24
19
 
25
- const instance = getDefaultInstance();
26
- const configuration = getDefaultOpenAPIConfig();
27
-
28
- const regionService = RegionServiceApiFactory(configuration, '', instance);
29
-
30
20
  const getRegionsList = async (params: ApiParams) => {
31
- const { page, size, search, sort, fields, id } = applyTransform(params, [
21
+ const requestParams = applyTransform(params, [
32
22
  merge(getDefaultGetParams()),
33
23
  starToSearch('search'),
24
+ camelToSnake(),
25
+ (params) => ({
26
+ ...params,
27
+ q: params.search,
28
+ }),
29
+ sanitize([
30
+ 'page',
31
+ 'size',
32
+ 'q',
33
+ 'sort',
34
+ 'fields',
35
+ 'id',
36
+ ]),
34
37
  ]);
35
38
 
36
39
  try {
37
- const response = await regionService.searchRegion(
38
- page,
39
- size,
40
- search,
41
- sort,
42
- fields,
43
- id,
44
- );
40
+ const response = await getRegionService().searchRegion(requestParams);
45
41
  const { items, next } = applyTransform(response.data, [
46
42
  snakeToCamel(),
47
43
  merge(getDefaultGetListResponse()),
@@ -59,7 +55,7 @@ const getRegionsList = async (params: ApiParams) => {
59
55
 
60
56
  const getRegion = async ({ itemId: id }: GetItemParams) => {
61
57
  try {
62
- const response = await regionService.readRegion(String(id));
58
+ const response = await getRegionService().readRegion(String(id));
63
59
  return applyTransform(response.data, [
64
60
  snakeToCamel(),
65
61
  ]);
@@ -82,7 +78,7 @@ const addRegion = async ({ itemInstance }: AddItemParams) => {
82
78
  camelToSnake(),
83
79
  ]);
84
80
  try {
85
- const response = await regionService.createRegion(item);
81
+ const response = await getRegionService().createRegion(item);
86
82
  return applyTransform(response.data, [
87
83
  snakeToCamel(),
88
84
  ]);
@@ -99,7 +95,7 @@ const updateRegion = async ({ itemInstance, itemId: id }: UpdateItemParams) => {
99
95
  camelToSnake(),
100
96
  ]);
101
97
  try {
102
- const response = await regionService.updateRegion(String(id), item);
98
+ const response = await getRegionService().updateRegion(String(id), item);
103
99
  return applyTransform(response.data, [
104
100
  snakeToCamel(),
105
101
  ]);
@@ -112,7 +108,7 @@ const updateRegion = async ({ itemInstance, itemId: id }: UpdateItemParams) => {
112
108
 
113
109
  const deleteRegion = async ({ id }: DeleteItemParams) => {
114
110
  try {
115
- const response = await regionService.deleteRegion(String(id));
111
+ const response = await getRegionService().deleteRegion(String(id));
116
112
  return applyTransform(response.data, []);
117
113
  } catch (err) {
118
114
  throw applyTransform(err, [
@@ -0,0 +1,167 @@
1
+ import { getSchemaVariablesService } from '../../../gen-wire';
2
+ import { getDefaultGetListResponse, getDefaultGetParams } from '../../defaults';
3
+ import {
4
+ applyTransform,
5
+ camelToSnake,
6
+ merge,
7
+ notify,
8
+ sanitize,
9
+ snakeToCamel,
10
+ starToSearch,
11
+ } from '../../transformers';
12
+ import type {
13
+ AddItemParams,
14
+ ApiParams,
15
+ DeleteItemParams,
16
+ GetItemParams,
17
+ PatchItemParams,
18
+ UpdateItemParams,
19
+ } from '../_shared/types';
20
+
21
+ /** "Global variables" in the admin UI. */
22
+ const fieldsToSend = [
23
+ 'id',
24
+ 'name',
25
+ 'value',
26
+ 'encrypt',
27
+ ];
28
+
29
+ const getSchemaVariablesList = async (params: ApiParams) => {
30
+ const { page, size, search, sort, fields } = applyTransform(params, [
31
+ merge(getDefaultGetParams()),
32
+ starToSearch('search'),
33
+ ]);
34
+
35
+ try {
36
+ const response = await getSchemaVariablesService().searchSchemaVariable({
37
+ page,
38
+ size,
39
+ // the generated param is `q`; `search` is what the datalist store sends
40
+ q: search,
41
+ sort,
42
+ fields,
43
+ });
44
+ const { items, next } = applyTransform(response.data, [
45
+ snakeToCamel(),
46
+ merge(getDefaultGetListResponse()),
47
+ ]);
48
+ return {
49
+ items,
50
+ next,
51
+ };
52
+ } catch (err) {
53
+ throw applyTransform(err, [
54
+ notify,
55
+ ]);
56
+ }
57
+ };
58
+
59
+ const getSchemaVariable = async ({ itemId: id }: GetItemParams) => {
60
+ try {
61
+ const response = await getSchemaVariablesService().readSchemaVariable(
62
+ Number(id),
63
+ );
64
+ return applyTransform(response.data, [
65
+ snakeToCamel(),
66
+ ]);
67
+ } catch (err) {
68
+ throw applyTransform(err, [
69
+ notify,
70
+ ]);
71
+ }
72
+ };
73
+
74
+ const addSchemaVariable = async ({ itemInstance }: AddItemParams) => {
75
+ const item = applyTransform(itemInstance, [
76
+ sanitize(fieldsToSend),
77
+ camelToSnake(),
78
+ ]);
79
+ try {
80
+ const response =
81
+ await getSchemaVariablesService().createSchemaVariable(item);
82
+ return applyTransform(response.data, [
83
+ snakeToCamel(),
84
+ ]);
85
+ } catch (err) {
86
+ throw applyTransform(err, [
87
+ notify,
88
+ ]);
89
+ }
90
+ };
91
+
92
+ const updateSchemaVariable = async ({
93
+ itemInstance,
94
+ itemId: id,
95
+ }: UpdateItemParams) => {
96
+ const item = applyTransform(itemInstance, [
97
+ sanitize(fieldsToSend),
98
+ camelToSnake(),
99
+ ]);
100
+ try {
101
+ const response = await getSchemaVariablesService().updateSchemaVariable(
102
+ Number(id),
103
+ item,
104
+ );
105
+ return applyTransform(response.data, [
106
+ snakeToCamel(),
107
+ ]);
108
+ } catch (err) {
109
+ throw applyTransform(err, [
110
+ notify,
111
+ ]);
112
+ }
113
+ };
114
+
115
+ const patchSchemaVariable = async ({ changes, id }: PatchItemParams) => {
116
+ const body = applyTransform(changes, [
117
+ sanitize(fieldsToSend),
118
+ camelToSnake(),
119
+ ]);
120
+ try {
121
+ const response = await getSchemaVariablesService().patchSchemaVariable(
122
+ Number(id),
123
+ body,
124
+ );
125
+ return applyTransform(response.data, [
126
+ snakeToCamel(),
127
+ ]);
128
+ } catch (err) {
129
+ throw applyTransform(err, [
130
+ notify,
131
+ ]);
132
+ }
133
+ };
134
+
135
+ const deleteSchemaVariable = async ({ id }: DeleteItemParams) => {
136
+ try {
137
+ const response = await getSchemaVariablesService().deleteSchemaVariable(
138
+ Number(id),
139
+ );
140
+ return applyTransform(response.data, []);
141
+ } catch (err) {
142
+ throw applyTransform(err, [
143
+ notify,
144
+ ]);
145
+ }
146
+ };
147
+
148
+ const getSchemaVariablesLookup = (
149
+ params: Parameters<typeof getSchemaVariablesList>[0],
150
+ ) =>
151
+ getSchemaVariablesList({
152
+ ...params,
153
+ fields: params.fields || [
154
+ 'id',
155
+ 'name',
156
+ ],
157
+ });
158
+
159
+ export const SchemaVariablesAPI = {
160
+ getList: getSchemaVariablesList,
161
+ get: getSchemaVariable,
162
+ add: addSchemaVariable,
163
+ update: updateSchemaVariable,
164
+ patch: patchSchemaVariable,
165
+ delete: deleteSchemaVariable,
166
+ getLookup: getSchemaVariablesLookup,
167
+ };
@@ -0,0 +1,176 @@
1
+ import { getShiftTemplateService } from '../../../gen-wire';
2
+ import { getDefaultGetListResponse, getDefaultGetParams } from '../../defaults';
3
+ import {
4
+ applyTransform,
5
+ camelToSnake,
6
+ merge,
7
+ notify,
8
+ sanitize,
9
+ snakeToCamel,
10
+ } from '../../transformers';
11
+ import type {
12
+ AddItemParams,
13
+ ApiParams,
14
+ DeleteItemParams,
15
+ GetItemParams,
16
+ UpdateItemParams,
17
+ } from '../_shared/types';
18
+
19
+ const fieldsToSend = [
20
+ 'name',
21
+ 'description',
22
+ 'times',
23
+ ];
24
+
25
+ /**
26
+ * WFM services wrap both request and response payloads in an `item` envelope.
27
+ */
28
+ const itemResponseHandler = (response: ApiParams) => {
29
+ const copy = {
30
+ ...response.item,
31
+ };
32
+
33
+ copy.times = copy.times?.map((time: ApiParams) => ({
34
+ ...time,
35
+ duration: time.end - time.start,
36
+ }));
37
+
38
+ return copy;
39
+ };
40
+
41
+ const getShiftTemplatesList = async (params: ApiParams) => {
42
+ const {
43
+ search: q,
44
+ page,
45
+ size,
46
+ sort,
47
+ fields,
48
+ } = applyTransform(params, [
49
+ merge(getDefaultGetParams()),
50
+ ]);
51
+
52
+ try {
53
+ const response =
54
+ await getShiftTemplateService().shiftTemplateServiceSearchShiftTemplate({
55
+ q,
56
+ page,
57
+ size,
58
+ sort,
59
+ fields,
60
+ });
61
+ const { items, next } = applyTransform(response.data, [
62
+ snakeToCamel(),
63
+ merge(getDefaultGetListResponse()),
64
+ ]);
65
+ return {
66
+ items,
67
+ next,
68
+ };
69
+ } catch (err) {
70
+ throw applyTransform(err, [
71
+ notify,
72
+ ]);
73
+ }
74
+ };
75
+
76
+ const getShiftTemplate = async ({ itemId: id }: GetItemParams) => {
77
+ try {
78
+ const response =
79
+ await getShiftTemplateService().shiftTemplateServiceReadShiftTemplate(
80
+ String(id),
81
+ );
82
+ return applyTransform(response.data, [
83
+ snakeToCamel(),
84
+ itemResponseHandler,
85
+ ]);
86
+ } catch (err) {
87
+ throw applyTransform(err, [
88
+ notify,
89
+ ]);
90
+ }
91
+ };
92
+
93
+ const addShiftTemplate = async ({ itemInstance }: AddItemParams) => {
94
+ const item = applyTransform(itemInstance, [
95
+ sanitize(fieldsToSend),
96
+ camelToSnake(),
97
+ ]);
98
+ try {
99
+ const response =
100
+ await getShiftTemplateService().shiftTemplateServiceCreateShiftTemplate({
101
+ item: {
102
+ ...item,
103
+ },
104
+ });
105
+ return applyTransform(response.data, [
106
+ snakeToCamel(),
107
+ itemResponseHandler,
108
+ ]);
109
+ } catch (err) {
110
+ throw applyTransform(err, [
111
+ notify,
112
+ ]);
113
+ }
114
+ };
115
+
116
+ const updateShiftTemplate = async ({
117
+ itemInstance,
118
+ itemId: id,
119
+ }: UpdateItemParams) => {
120
+ const item = applyTransform(itemInstance, [
121
+ sanitize(fieldsToSend),
122
+ camelToSnake(),
123
+ ]);
124
+ try {
125
+ const response =
126
+ await getShiftTemplateService().shiftTemplateServiceUpdateShiftTemplate(
127
+ String(id),
128
+ {
129
+ item: {
130
+ ...item,
131
+ },
132
+ },
133
+ );
134
+ return applyTransform(response.data, [
135
+ snakeToCamel(),
136
+ ]);
137
+ } catch (err) {
138
+ throw applyTransform(err, [
139
+ notify,
140
+ ]);
141
+ }
142
+ };
143
+
144
+ const deleteShiftTemplate = async ({ id }: DeleteItemParams) => {
145
+ try {
146
+ const response =
147
+ await getShiftTemplateService().shiftTemplateServiceDeleteShiftTemplate(
148
+ String(id),
149
+ );
150
+ return applyTransform(response.data, []);
151
+ } catch (err) {
152
+ throw applyTransform(err, [
153
+ notify,
154
+ ]);
155
+ }
156
+ };
157
+
158
+ const getShiftTemplatesLookup = (
159
+ params: Parameters<typeof getShiftTemplatesList>[0],
160
+ ) =>
161
+ getShiftTemplatesList({
162
+ ...params,
163
+ fields: params.fields || [
164
+ 'id',
165
+ 'name',
166
+ ],
167
+ });
168
+
169
+ export const ShiftTemplatesAPI = {
170
+ getList: getShiftTemplatesList,
171
+ get: getShiftTemplate,
172
+ add: addShiftTemplate,
173
+ update: updateShiftTemplate,
174
+ delete: deleteShiftTemplate,
175
+ getLookup: getShiftTemplatesLookup,
176
+ };
@@ -0,0 +1,190 @@
1
+ import { getSkillService } from '../../../gen-wire';
2
+ import { getDefaultGetListResponse, getDefaultGetParams } from '../../defaults';
3
+ import {
4
+ applyTransform,
5
+ camelToSnake,
6
+ merge,
7
+ mergeEach,
8
+ notify,
9
+ sanitize,
10
+ snakeToCamel,
11
+ starToSearch,
12
+ } from '../../transformers';
13
+ import type {
14
+ ApiParams,
15
+ NestedAddItemParams,
16
+ NestedDeleteItemParams,
17
+ NestedGetItemParams,
18
+ NestedPatchItemParams,
19
+ UpdateItemParams,
20
+ } from '../_shared/types';
21
+
22
+ /** Agents holding a given skill. `parentId` is the skill. */
23
+ const defaultObject = {
24
+ agent: {},
25
+ skill: {},
26
+ team: {},
27
+ capacity: 10,
28
+ enabled: false,
29
+ };
30
+
31
+ const fieldsToSend = [
32
+ 'capacity',
33
+ 'skill',
34
+ 'team',
35
+ 'enabled',
36
+ 'agent',
37
+ 'user',
38
+ 'q',
39
+ ];
40
+
41
+ const getSkillAgentsList = async (params: ApiParams) => {
42
+ const { parentId, page, size, search, sort, fields, id, agentId } =
43
+ applyTransform(params, [
44
+ merge(getDefaultGetParams()),
45
+ starToSearch('search'),
46
+ ]);
47
+
48
+ try {
49
+ const response = await getSkillService().searchSkillAgent(
50
+ String(parentId),
51
+ {
52
+ page,
53
+ size,
54
+ // the generated param is `q`; `search` is what the datalist store sends
55
+ q: search,
56
+ sort,
57
+ fields,
58
+ id,
59
+ agent_id: agentId,
60
+ },
61
+ );
62
+ const { items, next, aggs } = applyTransform(response.data, [
63
+ snakeToCamel(),
64
+ merge(getDefaultGetListResponse()),
65
+ ]);
66
+ return {
67
+ items: applyTransform(items, [
68
+ mergeEach(defaultObject),
69
+ ]),
70
+ next,
71
+ aggs,
72
+ };
73
+ } catch (err) {
74
+ throw applyTransform(err, [
75
+ notify,
76
+ ]);
77
+ }
78
+ };
79
+
80
+ const getSkillAgent = async ({ itemId: id }: NestedGetItemParams) => {
81
+ try {
82
+ const response = await getSkillService().readSkill(String(id));
83
+ return applyTransform(response.data, [
84
+ snakeToCamel(),
85
+ ]);
86
+ } catch (err) {
87
+ throw applyTransform(err, [
88
+ notify,
89
+ ]);
90
+ }
91
+ };
92
+
93
+ const addSkillAgent = async ({
94
+ parentId,
95
+ itemInstance,
96
+ }: NestedAddItemParams) => {
97
+ const item = applyTransform(itemInstance, [
98
+ sanitize(fieldsToSend),
99
+ camelToSnake(),
100
+ ]);
101
+ try {
102
+ const response = await getSkillService().createSkillAgent(
103
+ String(parentId),
104
+ item,
105
+ );
106
+ return applyTransform(response.data, [
107
+ snakeToCamel(),
108
+ ]);
109
+ } catch (err) {
110
+ throw applyTransform(err, [
111
+ notify,
112
+ ]);
113
+ }
114
+ };
115
+
116
+ /**
117
+ * Bulk edit: the body carries the ids to change, so `id` rides along with the
118
+ * sanitized changes rather than going in the path.
119
+ */
120
+ const patchSkillAgent = async ({
121
+ parentId,
122
+ changes,
123
+ id,
124
+ }: NestedPatchItemParams) => {
125
+ const sanitizedChanges = applyTransform(changes, [
126
+ sanitize(fieldsToSend),
127
+ camelToSnake(),
128
+ starToSearch('q'),
129
+ ]);
130
+ try {
131
+ const response = await getSkillService().patchSkillAgent(String(parentId), {
132
+ ...sanitizedChanges,
133
+ id,
134
+ });
135
+ return applyTransform(response.data, [
136
+ snakeToCamel(),
137
+ ]);
138
+ } catch (err) {
139
+ throw applyTransform(err, [
140
+ notify,
141
+ ]);
142
+ }
143
+ };
144
+
145
+ const updateSkillAgent = async ({
146
+ itemId: id,
147
+ itemInstance,
148
+ }: UpdateItemParams) => {
149
+ const item = applyTransform(itemInstance, [
150
+ sanitize(fieldsToSend),
151
+ camelToSnake(),
152
+ ]);
153
+ try {
154
+ const response = await getSkillService().updateSkill(String(id), item);
155
+ return applyTransform(response.data, [
156
+ snakeToCamel(),
157
+ ]);
158
+ } catch (err) {
159
+ throw applyTransform(err, [
160
+ notify,
161
+ ]);
162
+ }
163
+ };
164
+
165
+ const deleteSkillAgent = async ({ parentId, id }: NestedDeleteItemParams) => {
166
+ try {
167
+ const response = await getSkillService().deleteSkillAgent(
168
+ String(parentId),
169
+ {
170
+ id: [
171
+ String(id),
172
+ ],
173
+ },
174
+ );
175
+ return applyTransform(response.data, []);
176
+ } catch (err) {
177
+ throw applyTransform(err, [
178
+ notify,
179
+ ]);
180
+ }
181
+ };
182
+
183
+ export const SkillAgentsAPI = {
184
+ getList: getSkillAgentsList,
185
+ get: getSkillAgent,
186
+ add: addSkillAgent,
187
+ patch: patchSkillAgent,
188
+ update: updateSkillAgent,
189
+ delete: deleteSkillAgent,
190
+ };