@webitel/api-services 0.1.71 → 0.1.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 (28) hide show
  1. package/package.json +1 -1
  2. package/src/api/clients/emails/emails.ts +50 -49
  3. package/src/api/clients/imClients/imClients.ts +102 -0
  4. package/src/api/clients/index.ts +2 -0
  5. package/src/api/clients/phones/phones.ts +148 -104
  6. package/src/api/clients/queues/queueLogs.ts +2 -1
  7. package/src/api/clients/queues/queueMembers.ts +12 -3
  8. package/src/api/clients/variables/variables.ts +293 -0
  9. package/src/api/clients//321/201ontacts/index.ts +1 -0
  10. package/src/api/clients//321/201ontacts/types/ContactEntity.types.ts +25 -0
  11. package/src/validations/contact/contact.validations.ts +13 -0
  12. package/src/validations/contactEmail/contactEmail.validations.ts +9 -0
  13. package/src/validations/contactPhone/contactPhone.validations.ts +9 -0
  14. package/src/validations/index.ts +4 -0
  15. package/src/validations/variable/variable.validations.ts +8 -0
  16. package/types/.tsbuildinfo +1 -1
  17. package/types/api/clients/emails/emails.d.ts +10 -9
  18. package/types/api/clients/imClients/imClients.d.ts +19 -0
  19. package/types/api/clients/index.d.ts +2 -0
  20. package/types/api/clients/phones/phones.d.ts +29 -39
  21. package/types/api/clients/variables/variables.d.ts +51 -0
  22. package/types/api/clients//321/201ontacts/index.d.ts +1 -0
  23. package/types/api/clients//321/201ontacts/types/ContactEntity.types.d.ts +14 -0
  24. package/types/validations/contact/contact.validations.d.ts +25 -0
  25. package/types/validations/contactEmail/contactEmail.validations.d.ts +14 -0
  26. package/types/validations/contactPhone/contactPhone.validations.d.ts +14 -0
  27. package/types/validations/index.d.ts +4 -0
  28. package/types/validations/variable/variable.validations.d.ts +12 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webitel/api-services",
3
- "version": "0.1.71",
3
+ "version": "0.1.72",
4
4
  "private": false,
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,4 +1,10 @@
1
- import { getEmails } from '@webitel/api-services/gen';
1
+ import {
2
+ getEmails,
3
+ ListEmailsQueryParams,
4
+ MergeEmailsBodyItem,
5
+ UpdateEmailBody,
6
+ } from '@webitel/api-services/gen';
7
+ import { getShallowFieldsToSendFromZodSchema } from '@webitel/api-services/gen/utils';
2
8
  import { getDefaultGetListResponse, getDefaultGetParams } from '../../defaults';
3
9
  import {
4
10
  applyTransform,
@@ -12,36 +18,32 @@ import {
12
18
  } from '../../transformers';
13
19
  import type { ApiId, ApiParams } from '../_shared/types';
14
20
 
15
- const getList = async (params: ApiParams) => {
21
+ const getList = async ({
22
+ parentId,
23
+ ...rest
24
+ }: ApiParams & {
25
+ parentId: ApiId;
26
+ }) => {
16
27
  const defaultObject = {
17
28
  primary: false,
18
29
  };
19
30
 
20
- const fieldsToSend = [
21
- 'parentId',
22
- 'page',
23
- 'size',
24
- 'q',
25
- 'sort',
26
- 'fields',
27
- 'id',
28
- ];
29
- const { parentId, page, size, q, sort, fields, id } = applyTransform(params, [
30
- sanitize(fieldsToSend),
31
+ const listFieldsToSend = getShallowFieldsToSendFromZodSchema(
32
+ ListEmailsQueryParams,
33
+ );
34
+
35
+ const { fields = [], ...queryParams } = applyTransform(rest, [
36
+ sanitize(listFieldsToSend),
31
37
  merge(getDefaultGetParams()),
32
38
  starToSearch('q'),
33
39
  ]);
34
40
  try {
35
- const response = await getEmails().listEmails(parentId, {
36
- page,
37
- size,
38
- q,
39
- sort,
41
+ const response = await getEmails().listEmails(String(parentId), {
42
+ ...queryParams,
40
43
  fields: [
41
44
  'etag',
42
45
  ...fields,
43
46
  ],
44
- id,
45
47
  });
46
48
  const { data, next } = applyTransform(response.data, [
47
49
  snakeToCamel(),
@@ -91,62 +93,60 @@ const get = async ({
91
93
  }
92
94
  };
93
95
 
94
- const fieldsToSend = [
95
- 'email',
96
- 'type',
97
- 'primary',
98
- ];
96
+ const addFieldsToSend =
97
+ getShallowFieldsToSendFromZodSchema(MergeEmailsBodyItem);
99
98
 
100
99
  const add = async ({
101
- contactId,
102
- emails,
103
- params,
104
- options,
100
+ parentId,
101
+ itemInstance,
105
102
  }: {
106
- contactId: ApiId;
107
- emails: ApiParams[];
108
- params: ApiParams;
109
- options: ApiParams;
103
+ parentId: ApiId;
104
+ itemInstance: ApiParams;
110
105
  }) => {
111
- const item = applyTransform(emails, [
106
+ const item = applyTransform(itemInstance, [
107
+ sanitize(addFieldsToSend),
112
108
  camelToSnake(),
113
109
  ]);
114
- console.log(item);
115
-
116
110
  try {
117
- const response = await getEmails().mergeEmails(
118
- String(contactId),
111
+ const response = await getEmails().mergeEmails(String(parentId), [
119
112
  item,
120
- params,
121
- options,
122
- );
123
- return applyTransform(response.data, [
113
+ ]);
114
+ const { data } = applyTransform(response.data, [
124
115
  snakeToCamel(),
125
116
  ]);
117
+ return data[0];
126
118
  } catch (err) {
127
119
  throw applyTransform(err, [
128
120
  notify,
129
121
  ]);
130
122
  }
131
123
  };
124
+
125
+ const updateFieldsToSend = getShallowFieldsToSendFromZodSchema(UpdateEmailBody);
126
+
132
127
  const update = async ({
133
128
  itemInstance,
134
- etag: id,
135
129
  parentId,
136
130
  }: {
137
- itemInstance: ApiParams;
138
- etag: string;
131
+ itemInstance: ApiParams & {
132
+ etag: string;
133
+ };
139
134
  parentId: ApiId;
140
135
  }) => {
141
136
  const item = applyTransform(itemInstance, [
142
- sanitize(fieldsToSend),
137
+ sanitize(updateFieldsToSend),
143
138
  camelToSnake(),
144
139
  ]);
145
140
  try {
146
- const response = await getEmails().updateEmail(String(parentId), id, item);
147
- return applyTransform(response.data, [
141
+ const response = await getEmails().updateEmail(
142
+ String(parentId),
143
+ itemInstance.etag,
144
+ item,
145
+ );
146
+ const { data } = applyTransform(response.data, [
148
147
  snakeToCamel(),
149
148
  ]);
149
+ return data[0];
150
150
  } catch (err) {
151
151
  throw applyTransform(err, [
152
152
  notify,
@@ -164,7 +164,7 @@ const patch = async ({
164
164
  etag: string;
165
165
  }) => {
166
166
  const body = applyTransform(changes, [
167
- sanitize(fieldsToSend),
167
+ sanitize(updateFieldsToSend),
168
168
  camelToSnake(),
169
169
  ]);
170
170
  try {
@@ -173,9 +173,10 @@ const patch = async ({
173
173
  etag,
174
174
  body,
175
175
  );
176
- return applyTransform(response.data, [
176
+ const { data } = applyTransform(response.data, [
177
177
  snakeToCamel(),
178
178
  ]);
179
+ return data[0];
179
180
  } catch (err) {
180
181
  throw applyTransform(err, [
181
182
  notify,
@@ -0,0 +1,102 @@
1
+ import {
2
+ getImclients,
3
+ ListIMClientsQueryParams,
4
+ } from '@webitel/api-services/gen';
5
+ import { getShallowFieldsToSendFromZodSchema } from '@webitel/api-services/gen/utils';
6
+ import { getDefaultGetListResponse, getDefaultGetParams } from '../../defaults';
7
+ import {
8
+ applyTransform,
9
+ merge,
10
+ notify,
11
+ sanitize,
12
+ snakeToCamel,
13
+ starToSearch,
14
+ } from '../../transformers';
15
+ import type { ApiId, ApiParams } from '../_shared/types';
16
+
17
+ const getIMClientsList = async ({
18
+ parentId,
19
+ ...rest
20
+ }: ApiParams & {
21
+ parentId: ApiId;
22
+ }) => {
23
+ const listFieldsToSend = getShallowFieldsToSendFromZodSchema(
24
+ ListIMClientsQueryParams,
25
+ );
26
+
27
+ const {
28
+ page,
29
+ size,
30
+ q,
31
+ sort,
32
+ fields = [],
33
+ id,
34
+ } = applyTransform(rest, [
35
+ sanitize(listFieldsToSend),
36
+ merge(getDefaultGetParams()),
37
+ starToSearch('q'),
38
+ ]);
39
+ try {
40
+ const response = await getImclients().listIMClients(String(parentId), {
41
+ page,
42
+ size,
43
+ q,
44
+ sort,
45
+ fields,
46
+ id,
47
+ });
48
+ const { data, next } = applyTransform(response.data, [
49
+ snakeToCamel(),
50
+ merge(getDefaultGetListResponse()),
51
+ ]);
52
+ return {
53
+ items: data,
54
+ next,
55
+ };
56
+ } catch (err) {
57
+ throw applyTransform(err, [
58
+ notify,
59
+ ]);
60
+ }
61
+ };
62
+
63
+ const deleteIMClient = async ({
64
+ id,
65
+ parentId,
66
+ }: {
67
+ id: ApiId;
68
+ parentId: ApiId;
69
+ }) => {
70
+ try {
71
+ const response = await getImclients().deleteIMClient(
72
+ String(parentId),
73
+ String(id),
74
+ );
75
+ return applyTransform(response.data, []);
76
+ } catch (err) {
77
+ throw applyTransform(err, [
78
+ notify,
79
+ ]);
80
+ }
81
+ };
82
+
83
+ const getIMClientsLookup = (
84
+ params: ApiParams & {
85
+ parentId: ApiId;
86
+ },
87
+ ) =>
88
+ getIMClientsList({
89
+ ...params,
90
+ fields: (params.fields as string[]) || [
91
+ 'id',
92
+ 'user',
93
+ 'app',
94
+ 'protocol',
95
+ ],
96
+ });
97
+
98
+ export const IMClientsAPI = {
99
+ getList: getIMClientsList,
100
+ delete: deleteIMClient,
101
+ getLookup: getIMClientsLookup,
102
+ };
@@ -28,6 +28,7 @@ export * from './fileServices/fileServices';
28
28
  export * from './flows/flow';
29
29
  export * from './gateways/gateways';
30
30
  export * from './history/transcript/callTranscript';
31
+ export * from './imClients/imClients';
31
32
  export * from './labels/labels';
32
33
  export * from './lists/blacklists';
33
34
  export * from './media/media';
@@ -54,6 +55,7 @@ export * from './slas/slas';
54
55
  export * from './teams/teams';
55
56
  export * from './userSettings/userSettings';
56
57
  export * from './users/users';
58
+ export * from './variables/variables';
57
59
  export * from './wtTypes/adjunctTypeRecords/adjunctTypeRecords';
58
60
  export * from './wtTypes/adjunctTypes/adjunctTypes';
59
61
  export * from './wtTypes/sysTypes/sysTypes';
@@ -1,40 +1,59 @@
1
- import { getPhones } from '@webitel/api-services/gen';
1
+ import {
2
+ getPhones,
3
+ ListPhonesQueryParams,
4
+ MergePhonesBodyItem,
5
+ UpdatePhoneBody,
6
+ } from '@webitel/api-services/gen';
2
7
  import type { DeletePhonesParams } from '@webitel/api-services/gen/models';
8
+ import { getShallowFieldsToSendFromZodSchema } from '@webitel/api-services/gen/utils';
3
9
  import { getDefaultGetListResponse, getDefaultGetParams } from '../../defaults';
4
10
  import {
5
11
  applyTransform,
6
12
  camelToSnake,
7
13
  merge,
14
+ mergeEach,
8
15
  notify,
16
+ sanitize,
9
17
  snakeToCamel,
10
18
  starToSearch,
11
19
  } from '../../transformers';
12
20
  import type { ApiId, ApiParams } from '../_shared/types';
13
21
 
14
22
  const getPhonesList = async ({
15
- contactId,
16
- options,
17
- ...params
18
- }: {
19
- contactId: ApiId;
20
- options: ApiParams;
21
- } & ApiParams) => {
22
- const listParams = applyTransform(params, [
23
+ parentId,
24
+ ...rest
25
+ }: ApiParams & {
26
+ parentId: ApiId;
27
+ }) => {
28
+ const defaultObject = {
29
+ primary: false,
30
+ };
31
+
32
+ const listFieldsToSend = getShallowFieldsToSendFromZodSchema(
33
+ ListPhonesQueryParams,
34
+ );
35
+
36
+ const { fields = [], ...queryParams } = applyTransform(rest, [
37
+ sanitize(listFieldsToSend),
23
38
  merge(getDefaultGetParams()),
24
- starToSearch('search'),
39
+ starToSearch('q'),
25
40
  ]);
26
41
  try {
27
- const response = await getPhones().listPhones(
28
- String(contactId),
29
- listParams,
30
- options,
31
- );
32
- const { items, next } = applyTransform(response.data, [
42
+ const response = await getPhones().listPhones(String(parentId), {
43
+ ...queryParams,
44
+ fields: [
45
+ 'etag',
46
+ ...fields,
47
+ ],
48
+ });
49
+ const { data, next } = applyTransform(response.data, [
33
50
  snakeToCamel(),
34
51
  merge(getDefaultGetListResponse()),
35
52
  ]);
36
53
  return {
37
- items,
54
+ items: applyTransform(data, [
55
+ mergeEach(defaultObject),
56
+ ]),
38
57
  next,
39
58
  };
40
59
  } catch (err) {
@@ -45,22 +64,25 @@ const getPhonesList = async ({
45
64
  };
46
65
 
47
66
  const getPhone = async ({
48
- contactId,
49
- etag,
50
- params,
51
- options,
67
+ itemId,
68
+ parentId,
52
69
  }: {
53
- contactId: ApiId;
54
- etag: string;
55
- params: ApiParams;
56
- options: ApiParams;
70
+ itemId: ApiId;
71
+ parentId: ApiId;
57
72
  }) => {
73
+ const fields = [
74
+ 'number',
75
+ 'primary',
76
+ 'etag',
77
+ 'type',
78
+ ];
58
79
  try {
59
80
  const response = await getPhones().locatePhone(
60
- String(contactId),
61
- etag,
62
- params,
63
- options,
81
+ String(parentId),
82
+ String(itemId),
83
+ {
84
+ fields,
85
+ },
64
86
  );
65
87
  return applyTransform(response.data, [
66
88
  snakeToCamel(),
@@ -72,30 +94,28 @@ const getPhone = async ({
72
94
  }
73
95
  };
74
96
 
75
- const mergePhones = async ({
76
- contactId,
77
- phones,
78
- params,
79
- options,
97
+ const addFieldsToSend =
98
+ getShallowFieldsToSendFromZodSchema(MergePhonesBodyItem);
99
+
100
+ const addPhone = async ({
101
+ parentId,
102
+ itemInstance,
80
103
  }: {
81
- contactId: ApiId;
82
- phones: ApiParams[];
83
- params: ApiParams;
84
- options: ApiParams;
104
+ parentId: ApiId;
105
+ itemInstance: ApiParams;
85
106
  }) => {
86
- const body = applyTransform(phones, [
107
+ const item = applyTransform(itemInstance, [
108
+ sanitize(addFieldsToSend),
87
109
  camelToSnake(),
88
110
  ]);
89
111
  try {
90
- const response = await getPhones().mergePhones(
91
- String(contactId),
92
- body,
93
- params,
94
- options,
95
- );
96
- return applyTransform(response.data, [
112
+ const response = await getPhones().mergePhones(String(parentId), [
113
+ item,
114
+ ]);
115
+ const { data } = applyTransform(response.data, [
97
116
  snakeToCamel(),
98
117
  ]);
118
+ return data[0];
99
119
  } catch (err) {
100
120
  throw applyTransform(err, [
101
121
  notify,
@@ -103,30 +123,31 @@ const mergePhones = async ({
103
123
  }
104
124
  };
105
125
 
106
- const resetPhones = async ({
107
- contactId,
108
- phones,
109
- params,
110
- options,
126
+ const updateFieldsToSend = getShallowFieldsToSendFromZodSchema(UpdatePhoneBody);
127
+
128
+ const updatePhone = async ({
129
+ itemInstance,
130
+ parentId,
111
131
  }: {
112
- contactId: ApiId;
113
- phones: ApiParams[];
114
- params: ApiParams;
115
- options: ApiParams;
132
+ itemInstance: ApiParams & {
133
+ etag: string;
134
+ };
135
+ parentId: ApiId;
116
136
  }) => {
117
- const body = applyTransform(phones, [
137
+ const item = applyTransform(itemInstance, [
138
+ sanitize(updateFieldsToSend),
118
139
  camelToSnake(),
119
140
  ]);
120
141
  try {
121
- const response = await getPhones().resetPhones(
122
- String(contactId),
123
- body,
124
- params,
125
- options,
142
+ const response = await getPhones().updatePhone(
143
+ String(parentId),
144
+ itemInstance.etag,
145
+ item,
126
146
  );
127
- return applyTransform(response.data, [
147
+ const { data } = applyTransform(response.data, [
128
148
  snakeToCamel(),
129
149
  ]);
150
+ return data[0];
130
151
  } catch (err) {
131
152
  throw applyTransform(err, [
132
153
  notify,
@@ -134,33 +155,29 @@ const resetPhones = async ({
134
155
  }
135
156
  };
136
157
 
137
- const updatePhone = async ({
138
- contactId,
158
+ const patchPhone = async ({
159
+ parentId,
160
+ changes,
139
161
  etag,
140
- data,
141
- params,
142
- options,
143
162
  }: {
144
- contactId: ApiId;
163
+ parentId: ApiId;
164
+ changes: ApiParams;
145
165
  etag: string;
146
- data: ApiParams;
147
- params: ApiParams;
148
- options: ApiParams;
149
166
  }) => {
150
- const body = applyTransform(data, [
167
+ const body = applyTransform(changes, [
168
+ sanitize(updateFieldsToSend),
151
169
  camelToSnake(),
152
170
  ]);
153
171
  try {
154
- const response = await getPhones().updatePhone(
155
- String(contactId),
172
+ const response = await getPhones().updatePhone2(
173
+ String(parentId),
156
174
  etag,
157
175
  body,
158
- params,
159
- options,
160
176
  );
161
- return applyTransform(response.data, [
177
+ const { data } = applyTransform(response.data, [
162
178
  snakeToCamel(),
163
179
  ]);
180
+ return data[0];
164
181
  } catch (err) {
165
182
  throw applyTransform(err, [
166
183
  notify,
@@ -168,26 +185,58 @@ const updatePhone = async ({
168
185
  }
169
186
  };
170
187
 
171
- const patchPhone = async ({
172
- contactId,
188
+ const deletePhone = async ({
173
189
  etag,
174
- changes,
190
+ parentId,
191
+ }: {
192
+ etag: string;
193
+ parentId: ApiId;
194
+ }) => {
195
+ try {
196
+ const response = await getPhones().deletePhone(String(parentId), etag);
197
+ return applyTransform(response.data, []);
198
+ } catch (err) {
199
+ throw applyTransform(err, [
200
+ notify,
201
+ ]);
202
+ }
203
+ };
204
+
205
+ const getPhonesLookup = (
206
+ params: ApiParams & {
207
+ parentId: ApiId;
208
+ },
209
+ ) =>
210
+ getPhonesList({
211
+ ...params,
212
+ fields: (params.fields as string[]) || [
213
+ 'etag',
214
+ 'number',
215
+ 'primary',
216
+ ],
217
+ });
218
+
219
+ /**
220
+ * raw bulk endpoints — take/return the whole phones array in one call,
221
+ * unlike add/update above which normalize a single item for createCardStore
222
+ */
223
+ const mergePhones = async ({
224
+ contactId,
225
+ phones,
175
226
  params,
176
227
  options,
177
228
  }: {
178
229
  contactId: ApiId;
179
- etag: string;
180
- changes: ApiParams;
230
+ phones: ApiParams[];
181
231
  params: ApiParams;
182
232
  options: ApiParams;
183
233
  }) => {
184
- const body = applyTransform(changes, [
234
+ const body = applyTransform(phones, [
185
235
  camelToSnake(),
186
236
  ]);
187
237
  try {
188
- const response = await getPhones().updatePhone2(
238
+ const response = await getPhones().mergePhones(
189
239
  String(contactId),
190
- etag,
191
240
  body,
192
241
  params,
193
242
  options,
@@ -202,21 +251,24 @@ const patchPhone = async ({
202
251
  }
203
252
  };
204
253
 
205
- const deletePhone = async ({
254
+ const resetPhones = async ({
206
255
  contactId,
207
- etag,
256
+ phones,
208
257
  params,
209
258
  options,
210
259
  }: {
211
260
  contactId: ApiId;
212
- etag: string;
261
+ phones: ApiParams[];
213
262
  params: ApiParams;
214
263
  options: ApiParams;
215
264
  }) => {
265
+ const body = applyTransform(phones, [
266
+ camelToSnake(),
267
+ ]);
216
268
  try {
217
- const response = await getPhones().deletePhone(
269
+ const response = await getPhones().resetPhones(
218
270
  String(contactId),
219
- etag,
271
+ body,
220
272
  params,
221
273
  options,
222
274
  );
@@ -255,24 +307,16 @@ const deletePhones = async ({
255
307
  }
256
308
  };
257
309
 
258
- const getPhonesLookup = (params: Parameters<typeof getPhonesList>[0]) =>
259
- getPhonesList({
260
- ...params,
261
- fields: params?.fields || [
262
- 'etag',
263
- 'number',
264
- 'priority',
265
- ],
266
- });
267
-
268
310
  export const PhonesAPI = {
269
311
  getList: getPhonesList,
270
- getLookup: getPhonesLookup,
271
- merge: mergePhones,
272
- reset: resetPhones,
273
- deleteMany: deletePhones,
274
312
  get: getPhone,
313
+ add: addPhone,
275
314
  update: updatePhone,
276
315
  patch: patchPhone,
277
316
  delete: deletePhone,
317
+ getLookup: getPhonesLookup,
318
+
319
+ merge: mergePhones,
320
+ reset: resetPhones,
321
+ deleteMany: deletePhones,
278
322
  };
@@ -1,4 +1,5 @@
1
1
  import { getMemberService } from '@webitel/api-services/gen';
2
+ import type { SearchAttemptsHistoryParams } from '@webitel/api-services/gen/models';
2
3
  import { normalizeDatetimeRange } from '../../../scripts';
3
4
  import { getDefaultGetListResponse, getDefaultGetParams } from '../../defaults';
4
5
  import {
@@ -59,7 +60,7 @@ const getQueueLogs = async (params: ApiParams) => {
59
60
  'offering_at.to': offeringAt?.to,
60
61
  'duration.from': duration?.from,
61
62
  'duration.to': duration?.to,
62
- });
63
+ } as SearchAttemptsHistoryParams);
63
64
  const { items, next } = applyTransform(response.data, [
64
65
  snakeToCamel(),
65
66
  merge(getDefaultGetListResponse()),