@webitel/api-services 1.0.9 → 1.0.11

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 (107) 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 +21 -31
  17. package/src/api/clients/caseStatuses/caseStatuses.ts +10 -21
  18. package/src/api/clients/cases/cases.ts +6 -3
  19. package/src/api/clients/catalog/catalog.ts +2 -8
  20. package/src/api/clients/changelogs/changelogs.ts +8 -0
  21. package/src/api/clients/chatplans/chatplans.ts +173 -0
  22. package/src/api/clients/cognitiveProfiles/cognitiveProfiles.ts +209 -0
  23. package/src/api/clients/communications/communications.ts +38 -42
  24. package/src/api/clients/dialplans/dialplans.ts +197 -0
  25. package/src/api/clients/emailProfiles/emailProfiles.ts +222 -0
  26. package/src/api/clients/fileServices/fileServices.ts +7 -2
  27. package/src/api/clients/flows/flow.ts +54 -43
  28. package/src/api/clients/fts/fts.ts +61 -0
  29. package/src/api/clients/history/transcript/callTranscript.ts +10 -20
  30. package/src/api/clients/importTemplates/importTemplates.ts +180 -0
  31. package/src/api/clients/index.ts +30 -0
  32. package/src/api/clients/lists/blacklistNumbers.ts +155 -0
  33. package/src/api/clients/lists/blacklists.ts +20 -25
  34. package/src/api/clients/logs/logs.ts +157 -0
  35. package/src/api/clients/media/media.ts +19 -15
  36. package/src/api/clients/object/object.ts +3 -14
  37. package/src/api/clients/outboundResourceGroups/outboundResourceGroups.ts +187 -0
  38. package/src/api/clients/outboundResourceGroups/resourcesInGroup.ts +169 -0
  39. package/src/api/clients/outboundResources/outboundResources.ts +225 -0
  40. package/src/api/clients/outboundResources/resourceDisplays.ts +165 -0
  41. package/src/api/clients/pauseTemplates/pauseTemplates.ts +203 -0
  42. package/src/api/clients/queues/__tests__/queueLogs.spec.ts +3 -3
  43. package/src/api/clients/queues/__tests__/queueMembers.spec.ts +4 -4
  44. package/src/api/clients/queues/queueLogs.ts +8 -3
  45. package/src/api/clients/queues/queueMembers.ts +3 -3
  46. package/src/api/clients/queues/queues.ts +52 -0
  47. package/src/api/clients/regions/regions.ts +21 -25
  48. package/src/api/clients/schemaVariables/schemaVariables.ts +167 -0
  49. package/src/api/clients/shiftTemplates/shiftTemplates.ts +176 -0
  50. package/src/api/clients/skills/skillAgents.ts +190 -0
  51. package/src/api/clients/skills/skills.ts +21 -25
  52. package/src/api/clients/storagePolicies/storagePolicies.ts +270 -0
  53. package/src/api/clients/teamHooks/teamHooks.ts +195 -0
  54. package/src/api/clients/teamTriggers/agentTriggers.ts +77 -0
  55. package/src/api/clients/teamTriggers/teamFlows.ts +194 -0
  56. package/src/api/clients/teams/teams.ts +31 -31
  57. package/src/api/clients/triggers/triggerJobs.ts +63 -0
  58. package/src/api/clients/triggers/triggers.ts +266 -0
  59. package/src/api/clients/userSettings/userSettings.ts +8 -9
  60. package/src/api/clients/users/users.ts +2 -0
  61. package/src/api/clients/workingConditions/workingConditions.ts +184 -0
  62. package/src/api/clients/workspaceWidgets/workspaceWidgets.ts +73 -0
  63. package/src/api/clients/wtTypes/adjunctTypeRecords/adjunctTypeRecords.ts +3 -3
  64. package/src/api/clients/wtTypes/adjunctTypes/adjunctTypes.ts +1 -1
  65. package/src/api/clients//321/201ontacts/contactChatMessagesHistory.ts +15 -26
  66. package/types/.tsbuildinfo +1 -1
  67. package/types/api/clients/activeCalls/activeCalls.d.ts +7 -0
  68. package/types/api/clients/agentPauseCauses/agentPauseCauses.d.ts +21 -0
  69. package/types/api/clients/agentSkills/agentSkills.d.ts +12 -0
  70. package/types/api/clients/agents/agents.d.ts +23 -2
  71. package/types/api/clients/auditForms/auditForms.d.ts +7 -0
  72. package/types/api/clients/auditForms/auditRates.d.ts +10 -0
  73. package/types/api/clients/backendProfiles/backendProfiles.d.ts +21 -0
  74. package/types/api/clients/callHistory/callAnnotations.d.ts +12 -0
  75. package/types/api/clients/callHistory/callHistory.d.ts +24 -3
  76. package/types/api/clients/caseStatusConditions/caseStatusConditions.d.ts +4 -4
  77. package/types/api/clients/cases/cases.d.ts +5 -2
  78. package/types/api/clients/chatplans/chatplans.d.ts +21 -0
  79. package/types/api/clients/cognitiveProfiles/cognitiveProfiles.d.ts +21 -0
  80. package/types/api/clients/dialplans/dialplans.d.ts +16 -0
  81. package/types/api/clients/emailProfiles/emailProfiles.d.ts +27 -0
  82. package/types/api/clients/fileServices/fileServices.d.ts +1 -1
  83. package/types/api/clients/fts/fts.d.ts +7 -0
  84. package/types/api/clients/importTemplates/importTemplates.d.ts +21 -0
  85. package/types/api/clients/index.d.ts +30 -0
  86. package/types/api/clients/lists/blacklistNumbers.d.ts +11 -0
  87. package/types/api/clients/logs/logs.d.ts +15 -0
  88. package/types/api/clients/outboundResourceGroups/outboundResourceGroups.d.ts +20 -0
  89. package/types/api/clients/outboundResourceGroups/resourcesInGroup.d.ts +11 -0
  90. package/types/api/clients/outboundResources/outboundResources.d.ts +21 -0
  91. package/types/api/clients/outboundResources/resourceDisplays.d.ts +11 -0
  92. package/types/api/clients/pauseTemplates/pauseTemplates.d.ts +20 -0
  93. package/types/api/clients/queues/queues.d.ts +5 -0
  94. package/types/api/clients/schemaVariables/schemaVariables.d.ts +21 -0
  95. package/types/api/clients/shiftTemplates/shiftTemplates.d.ts +20 -0
  96. package/types/api/clients/skills/skillAgents.d.ts +13 -0
  97. package/types/api/clients/storagePolicies/storagePolicies.d.ts +26 -0
  98. package/types/api/clients/teamHooks/teamHooks.d.ts +12 -0
  99. package/types/api/clients/teamTriggers/agentTriggers.d.ts +23 -0
  100. package/types/api/clients/teamTriggers/teamFlows.d.ts +12 -0
  101. package/types/api/clients/triggers/triggerJobs.d.ts +7 -0
  102. package/types/api/clients/triggers/triggers.d.ts +22 -0
  103. package/types/api/clients/userSettings/userSettings.d.ts +2 -2
  104. package/types/api/clients/workingConditions/workingConditions.d.ts +20 -0
  105. package/types/api/clients/workspaceWidgets/workspaceWidgets.d.ts +3 -0
  106. package/types/api/clients/wtTypes/adjunctTypeRecords/adjunctTypeRecords.d.ts +2 -2
  107. package/types/api/clients/wtTypes/adjunctTypes/adjunctTypes.d.ts +2 -2
@@ -1,10 +1,5 @@
1
- import { SkillServiceApiFactory } from 'webitel-sdk';
2
- import {
3
- getDefaultGetListResponse,
4
- getDefaultGetParams,
5
- getDefaultInstance,
6
- getDefaultOpenAPIConfig,
7
- } from '../../defaults';
1
+ import { getSkillService } 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 skillService = SkillServiceApiFactory(configuration, '', instance);
29
-
30
20
  const getSkillsList = 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 skillService.searchSkill(
38
- page,
39
- size,
40
- search,
41
- sort,
42
- fields,
43
- id,
44
- );
40
+ const response = await getSkillService().searchSkill(requestParams);
45
41
  const { items, next } = applyTransform(response.data, [
46
42
  snakeToCamel(),
47
43
  merge(getDefaultGetListResponse()),
@@ -59,7 +55,7 @@ const getSkillsList = async (params: ApiParams) => {
59
55
 
60
56
  const getSkill = async ({ itemId: id }: GetItemParams) => {
61
57
  try {
62
- const response = await skillService.readSkill(String(id));
58
+ const response = await getSkillService().readSkill(String(id));
63
59
  return applyTransform(response.data, [
64
60
  snakeToCamel(),
65
61
  ]);
@@ -81,7 +77,7 @@ const addSkill = async ({ itemInstance }: AddItemParams) => {
81
77
  camelToSnake(),
82
78
  ]);
83
79
  try {
84
- const response = await skillService.createSkill(item);
80
+ const response = await getSkillService().createSkill(item);
85
81
  return applyTransform(response.data, [
86
82
  snakeToCamel(),
87
83
  ]);
@@ -98,7 +94,7 @@ const updateSkill = async ({ itemInstance, itemId: id }: UpdateItemParams) => {
98
94
  camelToSnake(),
99
95
  ]);
100
96
  try {
101
- const response = await skillService.updateSkill(String(id), item);
97
+ const response = await getSkillService().updateSkill(String(id), item);
102
98
  return applyTransform(response.data, [
103
99
  snakeToCamel(),
104
100
  ]);
@@ -111,7 +107,7 @@ const updateSkill = async ({ itemInstance, itemId: id }: UpdateItemParams) => {
111
107
 
112
108
  const deleteSkill = async ({ id }: DeleteItemParams) => {
113
109
  try {
114
- const response = await skillService.deleteSkill(String(id));
110
+ const response = await getSkillService().deleteSkill(String(id));
115
111
  return applyTransform(response.data, []);
116
112
  } catch (err) {
117
113
  throw applyTransform(err, [
@@ -0,0 +1,270 @@
1
+ import deepCopy from 'deep-copy';
2
+ import { getFilePoliciesService } from '../../../gen-wire';
3
+ import { getDefaultGetListResponse, getDefaultGetParams } from '../../defaults';
4
+ import {
5
+ applyTransform,
6
+ camelToSnake,
7
+ merge,
8
+ mergeEach,
9
+ notify,
10
+ sanitize,
11
+ snakeToCamel,
12
+ starToSearch,
13
+ } from '../../transformers';
14
+ import type {
15
+ AddItemParams,
16
+ ApiId,
17
+ ApiParams,
18
+ DeleteItemParams,
19
+ GetItemParams,
20
+ PatchItemParams,
21
+ UpdateItemParams,
22
+ } from '../_shared/types';
23
+
24
+ const fieldsToSend = [
25
+ 'name',
26
+ 'description',
27
+ 'channels',
28
+ 'mimeTypes',
29
+ 'retentionDays',
30
+ 'speedDownload',
31
+ 'speedUpload',
32
+ 'maxUploadSize',
33
+ 'enabled',
34
+ 'encrypt',
35
+ ];
36
+
37
+ /**
38
+ * The list endpoint returns nothing useful without an explicit field list, so
39
+ * this client always asks for the full row.
40
+ */
41
+ const listFields = [
42
+ 'id',
43
+ 'name',
44
+ 'description',
45
+ 'channels',
46
+ 'mime_types',
47
+ 'retention_days',
48
+ 'speed_download',
49
+ 'speed_upload',
50
+ 'max_upload_size',
51
+ 'position',
52
+ 'enabled',
53
+ 'encrypt',
54
+ ];
55
+
56
+ const defaultObject = {
57
+ name: '',
58
+ description: '',
59
+ channels: [],
60
+ mimeTypes: [],
61
+ retentionDays: 0,
62
+ speedDownload: 0,
63
+ speedUpload: 0,
64
+ maxUploadSize: 0,
65
+ position: 0,
66
+ enabled: false,
67
+ };
68
+
69
+ const preRequestHandler = (item: ApiParams) => {
70
+ const copy = deepCopy(item);
71
+ return {
72
+ ...copy,
73
+ channels: item.channels.map(
74
+ (channel: ApiParams) => channel.value || channel,
75
+ ),
76
+ };
77
+ };
78
+
79
+ const getStoragePoliciesList = async (params: ApiParams) => {
80
+ const { page, size, search, sort, id } = applyTransform(params, [
81
+ merge(getDefaultGetParams()),
82
+ starToSearch('search'),
83
+ ]);
84
+
85
+ try {
86
+ const response = await getFilePoliciesService().searchFilePolicies({
87
+ page,
88
+ size,
89
+ // the generated param is `q`; `search` is what the datalist store sends
90
+ q: search,
91
+ sort,
92
+ fields: listFields,
93
+ id,
94
+ });
95
+ const { items, next } = applyTransform(response.data, [
96
+ snakeToCamel(),
97
+ merge(getDefaultGetListResponse()),
98
+ ]);
99
+ return {
100
+ items: applyTransform(items, [
101
+ mergeEach(defaultObject),
102
+ ]),
103
+ next,
104
+ };
105
+ } catch (err) {
106
+ throw applyTransform(err, [
107
+ notify,
108
+ ]);
109
+ }
110
+ };
111
+
112
+ const getStoragePolicy = async ({ itemId: id }: GetItemParams) => {
113
+ try {
114
+ const response = await getFilePoliciesService().readFilePolicy(Number(id));
115
+ return applyTransform(response.data, [
116
+ snakeToCamel(),
117
+ merge(defaultObject),
118
+ ]);
119
+ } catch (err) {
120
+ throw applyTransform(err, [
121
+ notify,
122
+ ]);
123
+ }
124
+ };
125
+
126
+ const addStoragePolicy = async ({ itemInstance }: AddItemParams) => {
127
+ const item = applyTransform(itemInstance, [
128
+ preRequestHandler,
129
+ sanitize(fieldsToSend),
130
+ // `channels` values mirror the StorageUploadFileChannel enum and stay camelCase
131
+ camelToSnake([
132
+ 'channels',
133
+ ]),
134
+ ]);
135
+ try {
136
+ const response = await getFilePoliciesService().createFilePolicy(item);
137
+ return applyTransform(response.data, [
138
+ snakeToCamel(),
139
+ ]);
140
+ } catch (err) {
141
+ throw applyTransform(err, [
142
+ notify,
143
+ ]);
144
+ }
145
+ };
146
+
147
+ const updateStoragePolicy = async ({
148
+ itemInstance,
149
+ itemId: id,
150
+ }: UpdateItemParams) => {
151
+ const item = applyTransform(itemInstance, [
152
+ preRequestHandler,
153
+ sanitize(fieldsToSend),
154
+ // `channels` values mirror the StorageUploadFileChannel enum and stay camelCase
155
+ camelToSnake([
156
+ 'channels',
157
+ ]),
158
+ ]);
159
+ try {
160
+ const response = await getFilePoliciesService().updateFilePolicy(
161
+ Number(id),
162
+ item,
163
+ );
164
+ return applyTransform(response.data, [
165
+ snakeToCamel(),
166
+ ]);
167
+ } catch (err) {
168
+ throw applyTransform(err, [
169
+ notify,
170
+ ]);
171
+ }
172
+ };
173
+
174
+ const patchStoragePolicy = async ({ changes, id }: PatchItemParams) => {
175
+ const body = applyTransform(changes, [
176
+ sanitize(fieldsToSend),
177
+ camelToSnake(),
178
+ ]);
179
+ try {
180
+ const response = await getFilePoliciesService().patchFilePolicy(
181
+ Number(id),
182
+ body,
183
+ );
184
+ return applyTransform(response.data, [
185
+ snakeToCamel(),
186
+ ]);
187
+ } catch (err) {
188
+ throw applyTransform(err, [
189
+ notify,
190
+ ]);
191
+ }
192
+ };
193
+
194
+ const deleteStoragePolicy = async ({ id }: DeleteItemParams) => {
195
+ try {
196
+ const response = await getFilePoliciesService().deleteFilePolicy(
197
+ Number(id),
198
+ );
199
+ return applyTransform(response.data, []);
200
+ } catch (err) {
201
+ throw applyTransform(err, [
202
+ notify,
203
+ ]);
204
+ }
205
+ };
206
+
207
+ const movePositionStoragePolicy = async ({
208
+ fromId,
209
+ toId,
210
+ }: {
211
+ fromId: ApiId;
212
+ toId: ApiId;
213
+ }) => {
214
+ try {
215
+ const response = await getFilePoliciesService().movePositionFilePolicy(
216
+ Number(fromId),
217
+ Number(toId),
218
+ {},
219
+ );
220
+ return applyTransform(response.data, [
221
+ notify(({ callback }) =>
222
+ callback({
223
+ type: 'success',
224
+ text: 'Successfully saved',
225
+ }),
226
+ ),
227
+ ]);
228
+ } catch (err) {
229
+ throw applyTransform(err, [
230
+ notify,
231
+ ]);
232
+ }
233
+ };
234
+
235
+ const applyStoragePolicies = async (id: ApiId) => {
236
+ try {
237
+ const response = await getFilePoliciesService().filePolicyApply(
238
+ Number(id),
239
+ {},
240
+ );
241
+ return response.data;
242
+ } catch (err) {
243
+ throw applyTransform(err, [
244
+ notify,
245
+ ]);
246
+ }
247
+ };
248
+
249
+ const getStoragePoliciesLookup = (
250
+ params: Parameters<typeof getStoragePoliciesList>[0],
251
+ ) =>
252
+ getStoragePoliciesList({
253
+ ...params,
254
+ fields: params.fields || [
255
+ 'id',
256
+ 'name',
257
+ ],
258
+ });
259
+
260
+ export const StoragePoliciesAPI = {
261
+ getList: getStoragePoliciesList,
262
+ get: getStoragePolicy,
263
+ add: addStoragePolicy,
264
+ patch: patchStoragePolicy,
265
+ update: updateStoragePolicy,
266
+ delete: deleteStoragePolicy,
267
+ movePosition: movePositionStoragePolicy,
268
+ applyPolicies: applyStoragePolicies,
269
+ getLookup: getStoragePoliciesLookup,
270
+ };
@@ -0,0 +1,195 @@
1
+ import { getTeamHookService } 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
+ ApiId,
15
+ ApiParams,
16
+ NestedAddItemParams,
17
+ NestedDeleteItemParams,
18
+ NestedGetItemParams,
19
+ NestedPatchItemParams,
20
+ NestedUpdateItemParams,
21
+ } from '../_shared/types';
22
+
23
+ const fieldsToSend = [
24
+ 'event',
25
+ 'properties',
26
+ 'schema',
27
+ 'enabled',
28
+ ];
29
+
30
+ const preRequestHandler = (parentId: ApiId) => (item: ApiParams) => ({
31
+ ...item,
32
+ teamId: parentId,
33
+ });
34
+
35
+ const getTeamHooksList = async (params: ApiParams) => {
36
+ const defaultObject = {
37
+ enabled: false,
38
+ };
39
+
40
+ const { page, size, search, sort, fields, id, parentId } = applyTransform(
41
+ params,
42
+ [
43
+ merge(getDefaultGetParams()),
44
+ starToSearch('search'),
45
+ ],
46
+ );
47
+
48
+ try {
49
+ const response = await getTeamHookService().searchTeamHook(
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
+ },
60
+ );
61
+ const { items, next } = applyTransform(response.data, [
62
+ snakeToCamel(),
63
+ merge(getDefaultGetListResponse()),
64
+ ]);
65
+ return {
66
+ items: applyTransform(items, [
67
+ mergeEach(defaultObject),
68
+ ]),
69
+ next,
70
+ };
71
+ } catch (err) {
72
+ throw applyTransform(err, [
73
+ notify,
74
+ ]);
75
+ }
76
+ };
77
+
78
+ const getTeamHook = async ({ parentId, itemId: id }: NestedGetItemParams) => {
79
+ const defaultObject = {
80
+ event: '',
81
+ properties: [],
82
+ schema: {},
83
+ enabled: false,
84
+ };
85
+
86
+ try {
87
+ const response = await getTeamHookService().readTeamHook(
88
+ String(parentId),
89
+ Number(id),
90
+ );
91
+ return applyTransform(response.data, [
92
+ snakeToCamel(),
93
+ merge(defaultObject),
94
+ ]);
95
+ } catch (err) {
96
+ throw applyTransform(err, [
97
+ notify,
98
+ ]);
99
+ }
100
+ };
101
+
102
+ const addTeamHook = async ({ parentId, itemInstance }: NestedAddItemParams) => {
103
+ const item = applyTransform(itemInstance, [
104
+ preRequestHandler(parentId),
105
+ sanitize(fieldsToSend),
106
+ camelToSnake(),
107
+ ]);
108
+ try {
109
+ const response = await getTeamHookService().createTeamHook(
110
+ String(parentId),
111
+ item,
112
+ );
113
+ return applyTransform(response.data, [
114
+ snakeToCamel(),
115
+ ]);
116
+ } catch (err) {
117
+ throw applyTransform(err, [
118
+ notify,
119
+ ]);
120
+ }
121
+ };
122
+
123
+ const patchTeamHook = async ({
124
+ parentId,
125
+ changes,
126
+ id,
127
+ }: NestedPatchItemParams) => {
128
+ const body = applyTransform(changes, [
129
+ sanitize(fieldsToSend),
130
+ camelToSnake(),
131
+ ]);
132
+ try {
133
+ const response = await getTeamHookService().patchTeamHook(
134
+ String(parentId),
135
+ Number(id),
136
+ body,
137
+ );
138
+ return applyTransform(response.data, [
139
+ snakeToCamel(),
140
+ ]);
141
+ } catch (err) {
142
+ throw applyTransform(err, [
143
+ notify,
144
+ ]);
145
+ }
146
+ };
147
+
148
+ const updateTeamHook = async ({
149
+ parentId,
150
+ itemInstance,
151
+ itemId: id,
152
+ }: NestedUpdateItemParams) => {
153
+ const item = applyTransform(itemInstance, [
154
+ preRequestHandler(parentId),
155
+ sanitize(fieldsToSend),
156
+ camelToSnake(),
157
+ ]);
158
+ try {
159
+ const response = await getTeamHookService().updateTeamHook(
160
+ String(parentId),
161
+ Number(id),
162
+ item,
163
+ );
164
+ return applyTransform(response.data, [
165
+ snakeToCamel(),
166
+ ]);
167
+ } catch (err) {
168
+ throw applyTransform(err, [
169
+ notify,
170
+ ]);
171
+ }
172
+ };
173
+
174
+ const deleteTeamHook = async ({ parentId, id }: NestedDeleteItemParams) => {
175
+ try {
176
+ const response = await getTeamHookService().deleteTeamHook(
177
+ String(parentId),
178
+ Number(id),
179
+ );
180
+ return applyTransform(response.data, []);
181
+ } catch (err) {
182
+ throw applyTransform(err, [
183
+ notify,
184
+ ]);
185
+ }
186
+ };
187
+
188
+ export const TeamHooksAPI = {
189
+ getList: getTeamHooksList,
190
+ get: getTeamHook,
191
+ add: addTeamHook,
192
+ patch: patchTeamHook,
193
+ update: updateTeamHook,
194
+ delete: deleteTeamHook,
195
+ };
@@ -0,0 +1,77 @@
1
+ import { getTeamTriggerService } from '../../../gen-wire';
2
+ import { getDefaultGetListResponse } from '../../defaults';
3
+ import {
4
+ applyTransform,
5
+ merge,
6
+ mergeEach,
7
+ snakeToCamel,
8
+ starToSearch,
9
+ } from '../../transformers';
10
+ import type { ApiId, ApiParams } from '../_shared/types';
11
+
12
+ /**
13
+ * Triggers visible to the signed-in agent, across every team they belong to.
14
+ * `TeamFlowsAPI` is the admin-side view of the same entity, scoped to one team.
15
+ */
16
+ const getAgentTriggersList = async (params: ApiParams) => {
17
+ const defaultObject = {
18
+ enabled: false,
19
+ };
20
+
21
+ const { page, size, search, sort, fields, id, enabled } = applyTransform(
22
+ params,
23
+ [
24
+ starToSearch('search'),
25
+ ],
26
+ );
27
+
28
+ const response = await getTeamTriggerService().searchAgentTrigger({
29
+ page,
30
+ size,
31
+ // the generated param is `q`; `search` is what the datalist store sends
32
+ q: search,
33
+ sort,
34
+ fields,
35
+ enabled,
36
+ id,
37
+ });
38
+ const { items, next } = applyTransform(response.data, [
39
+ snakeToCamel(),
40
+ merge(getDefaultGetListResponse()),
41
+ ]);
42
+ return {
43
+ items: applyTransform(items, [
44
+ mergeEach(defaultObject),
45
+ ]),
46
+ next,
47
+ };
48
+ };
49
+
50
+ /**
51
+ * Deliberately does not notify: callers word the success and failure toasts
52
+ * themselves, and a notify here would double them.
53
+ */
54
+ const runAgentTrigger = async ({ id }: { id: ApiId }) => {
55
+ const response = await getTeamTriggerService().runTeamTrigger(Number(id), {});
56
+ return applyTransform(response.data, [
57
+ snakeToCamel(),
58
+ ]);
59
+ };
60
+
61
+ const getAgentTriggersLookup = (
62
+ params: Parameters<typeof getAgentTriggersList>[0],
63
+ ) =>
64
+ getAgentTriggersList({
65
+ ...params,
66
+ fields: params.fields || [
67
+ 'id',
68
+ 'name',
69
+ 'enabled',
70
+ ],
71
+ });
72
+
73
+ export const AgentTriggersAPI = {
74
+ getList: getAgentTriggersList,
75
+ run: runAgentTrigger,
76
+ getLookup: getAgentTriggersLookup,
77
+ };