@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
@@ -1,4 +1,5 @@
1
1
  import { getMemberService } from '@webitel/api-services/gen';
2
+ import type { SearchMemberInQueueParams } from '@webitel/api-services/gen/models';
2
3
  import { getShallowFieldsToSendFromZodSchema } from '@webitel/api-services/gen/utils';
3
4
  import { queueMemberSchema } from '@webitel/api-services/validations';
4
5
  import deepCopy from 'deep-copy';
@@ -152,7 +153,7 @@ const getMembersList = async (params: ApiParams) => {
152
153
  'attempts.to': attempts?.to,
153
154
  name,
154
155
  destination,
155
- },
156
+ } as SearchMemberInQueueParams,
156
157
  );
157
158
  const { items, next } = applyTransform(response.data, [
158
159
  snakeToCamel(doNotConvertKeys),
@@ -383,12 +384,20 @@ const deleteMembersBulk = async ({
383
384
  id?: ApiId[];
384
385
  filters?: ApiParams;
385
386
  }) => {
386
- const created = range(filters.createdAt, filters.from, filters.to);
387
+ const created = normalizeDatetimeRange(
388
+ filters.createdAt ??
389
+ (filters.from != null || filters.to != null
390
+ ? {
391
+ from: filters.from,
392
+ to: filters.to,
393
+ }
394
+ : undefined),
395
+ );
387
396
 
388
397
  let body: ApiParams = {
389
398
  id,
390
399
  q: filters.search,
391
- createdAt: created.from || created.to ? created : undefined,
400
+ createdAt: created?.from || created?.to ? created : undefined,
392
401
  priority: filters.memberPriority ?? filters.priority,
393
402
  stopCause: filters.stopCause ?? filters.cause,
394
403
  bucketId: filters.bucket,
@@ -0,0 +1,293 @@
1
+ import {
2
+ getVariables,
3
+ ListVariablesQueryParams,
4
+ MergeVariablesBodyItem,
5
+ UpdateVariableBody,
6
+ } from '@webitel/api-services/gen';
7
+ import type {
8
+ ContactsInputVariable,
9
+ DeleteVariablesParams,
10
+ MergeVariablesParams,
11
+ ResetVariablesParams,
12
+ } from '@webitel/api-services/gen/models';
13
+ import { getShallowFieldsToSendFromZodSchema } from '@webitel/api-services/gen/utils';
14
+ import type { AxiosRequestConfig } from 'axios';
15
+ import { getDefaultGetListResponse, getDefaultGetParams } from '../../defaults';
16
+ import {
17
+ applyTransform,
18
+ camelToSnake,
19
+ merge,
20
+ notify,
21
+ sanitize,
22
+ snakeToCamel,
23
+ starToSearch,
24
+ } from '../../transformers';
25
+
26
+ const getVariablesList = async ({
27
+ parentId,
28
+ ...rest
29
+ }: Record<string, unknown> & {
30
+ parentId: string;
31
+ }) => {
32
+ const listFieldsToSend = getShallowFieldsToSendFromZodSchema(
33
+ ListVariablesQueryParams,
34
+ );
35
+
36
+ const { fields = [], ...queryParams } = applyTransform(rest, [
37
+ sanitize(listFieldsToSend),
38
+ merge(getDefaultGetParams()),
39
+ starToSearch('q'),
40
+ ]);
41
+ try {
42
+ const response = await getVariables().listVariables(parentId, {
43
+ ...queryParams,
44
+ fields: [
45
+ 'etag',
46
+ ...fields,
47
+ ],
48
+ });
49
+ const { data, next } = applyTransform(response.data, [
50
+ snakeToCamel(),
51
+ merge(getDefaultGetListResponse()),
52
+ ]);
53
+ return {
54
+ items: data,
55
+ next,
56
+ };
57
+ } catch (err) {
58
+ throw applyTransform(err, [
59
+ notify,
60
+ ]);
61
+ }
62
+ };
63
+
64
+ // no dedicated "locate one" endpoint exists for variables — reuse the list
65
+ // endpoint filtered to a single id, matching what the crm-local adapter did
66
+ const getVariable = async ({
67
+ itemId,
68
+ parentId,
69
+ }: {
70
+ itemId: string;
71
+ parentId: string;
72
+ }) => {
73
+ try {
74
+ const response = await getVariables().listVariables(parentId, {
75
+ page: 1,
76
+ size: 1,
77
+ fields: [
78
+ 'key',
79
+ 'value',
80
+ 'etag',
81
+ ],
82
+ id: [
83
+ itemId,
84
+ ],
85
+ });
86
+ const { data } = applyTransform(response.data, [
87
+ snakeToCamel(),
88
+ ]);
89
+ return data[0];
90
+ } catch (err) {
91
+ throw applyTransform(err, [
92
+ notify,
93
+ ]);
94
+ }
95
+ };
96
+
97
+ const addFieldsToSend = getShallowFieldsToSendFromZodSchema(
98
+ MergeVariablesBodyItem,
99
+ );
100
+
101
+ const addVariable = async ({
102
+ parentId,
103
+ itemInstance,
104
+ }: {
105
+ parentId: string;
106
+ itemInstance: Record<string, unknown>;
107
+ }) => {
108
+ const item = applyTransform(itemInstance, [
109
+ sanitize(addFieldsToSend),
110
+ camelToSnake(),
111
+ ]);
112
+ try {
113
+ const response = await getVariables().mergeVariables(parentId, [
114
+ item,
115
+ ]);
116
+ const { data } = applyTransform(response.data, [
117
+ snakeToCamel(),
118
+ ]);
119
+ return data[0];
120
+ } catch (err) {
121
+ throw applyTransform(err, [
122
+ notify,
123
+ ]);
124
+ }
125
+ };
126
+
127
+ const updateFieldsToSend =
128
+ getShallowFieldsToSendFromZodSchema(UpdateVariableBody);
129
+
130
+ const updateVariable = async ({
131
+ itemInstance,
132
+ parentId,
133
+ }: {
134
+ itemInstance: Record<string, unknown> & {
135
+ etag: string;
136
+ };
137
+ parentId: string;
138
+ }) => {
139
+ const item = applyTransform(itemInstance, [
140
+ sanitize(updateFieldsToSend),
141
+ camelToSnake(),
142
+ ]);
143
+ try {
144
+ const response = await getVariables().updateVariable(
145
+ parentId,
146
+ itemInstance.etag,
147
+ item,
148
+ );
149
+ const { data } = applyTransform(response.data, [
150
+ snakeToCamel(),
151
+ ]);
152
+ return data[0];
153
+ } catch (err) {
154
+ throw applyTransform(err, [
155
+ notify,
156
+ ]);
157
+ }
158
+ };
159
+
160
+ const deleteVariable = async ({
161
+ etag,
162
+ parentId,
163
+ }: {
164
+ etag: string;
165
+ parentId: string;
166
+ }) => {
167
+ try {
168
+ const response = await getVariables().deleteVariable(parentId, etag);
169
+ return applyTransform(response.data, []);
170
+ } catch (err) {
171
+ throw applyTransform(err, [
172
+ notify,
173
+ ]);
174
+ }
175
+ };
176
+
177
+ const getVariablesLookup = (
178
+ params: Record<string, unknown> & {
179
+ parentId: string;
180
+ },
181
+ ) =>
182
+ getVariablesList({
183
+ ...params,
184
+ fields: (params.fields as string[]) || [
185
+ 'etag',
186
+ 'key',
187
+ 'value',
188
+ ],
189
+ });
190
+
191
+ /**
192
+ * raw bulk endpoints — take/return the whole variables array in one call,
193
+ * unlike add/update above which normalize a single item for createCardStore
194
+ */
195
+ const mergeVariables = async ({
196
+ contactId,
197
+ variables,
198
+ params,
199
+ options,
200
+ }: {
201
+ contactId: string;
202
+ variables: ContactsInputVariable[];
203
+ params?: MergeVariablesParams;
204
+ options?: AxiosRequestConfig;
205
+ }) => {
206
+ const body = applyTransform(variables, [
207
+ camelToSnake(),
208
+ ]);
209
+ try {
210
+ const response = await getVariables().mergeVariables(
211
+ contactId,
212
+ body,
213
+ params,
214
+ options,
215
+ );
216
+ return applyTransform(response.data, [
217
+ snakeToCamel(),
218
+ ]);
219
+ } catch (err) {
220
+ throw applyTransform(err, [
221
+ notify,
222
+ ]);
223
+ }
224
+ };
225
+
226
+ const resetVariables = async ({
227
+ contactId,
228
+ variables,
229
+ params,
230
+ options,
231
+ }: {
232
+ contactId: string;
233
+ variables: ContactsInputVariable[];
234
+ params?: ResetVariablesParams;
235
+ options?: AxiosRequestConfig;
236
+ }) => {
237
+ const body = applyTransform(variables, [
238
+ camelToSnake(),
239
+ ]);
240
+ try {
241
+ const response = await getVariables().resetVariables(
242
+ contactId,
243
+ body,
244
+ params,
245
+ options,
246
+ );
247
+ return applyTransform(response.data, [
248
+ snakeToCamel(),
249
+ ]);
250
+ } catch (err) {
251
+ throw applyTransform(err, [
252
+ notify,
253
+ ]);
254
+ }
255
+ };
256
+
257
+ const deleteVariables = async ({
258
+ contactId,
259
+ params,
260
+ options,
261
+ }: {
262
+ contactId: string;
263
+ params: DeleteVariablesParams;
264
+ options?: AxiosRequestConfig;
265
+ }) => {
266
+ try {
267
+ const response = await getVariables().deleteVariables(
268
+ contactId,
269
+ params,
270
+ options,
271
+ );
272
+ return applyTransform(response.data, [
273
+ snakeToCamel(),
274
+ ]);
275
+ } catch (err) {
276
+ throw applyTransform(err, [
277
+ notify,
278
+ ]);
279
+ }
280
+ };
281
+
282
+ export const VariablesAPI = {
283
+ getList: getVariablesList,
284
+ get: getVariable,
285
+ add: addVariable,
286
+ update: updateVariable,
287
+ delete: deleteVariable,
288
+ getLookup: getVariablesLookup,
289
+
290
+ merge: mergeVariables,
291
+ reset: resetVariables,
292
+ deleteMany: deleteVariables,
293
+ };
@@ -1,3 +1,4 @@
1
1
  export * from './contactChatMessagesHistory';
2
2
  export * from './contacts';
3
3
  export * from './enums/ContactsSearchMode';
4
+ export * from './types/ContactEntity.types';
@@ -0,0 +1,25 @@
1
+ import type {
2
+ ContactsManager,
3
+ ContactsTimezone,
4
+ WebitelContactsContact,
5
+ WebitelContactsLabel,
6
+ WebitelContactsLookup,
7
+ } from '@webitel/api-services/gen/models';
8
+
9
+ /**
10
+ * `ContactsAPI` (../contacts.ts) unwraps the generated `WebitelContactsContact`'s
11
+ * paginated `{data:[...]}` envelopes for these fields into plain arrays (and
12
+ * `name` into a plain string) on read, and wraps them back on write. This type
13
+ * reflects that actual runtime shape.
14
+ */
15
+ export interface ContactEntity
16
+ extends Omit<
17
+ WebitelContactsContact,
18
+ 'name' | 'timezones' | 'managers' | 'labels' | 'groups'
19
+ > {
20
+ name?: string;
21
+ timezones?: ContactsTimezone[];
22
+ managers?: ContactsManager[];
23
+ labels?: WebitelContactsLabel[];
24
+ groups?: WebitelContactsLookup[];
25
+ }
@@ -0,0 +1,13 @@
1
+ import { z } from 'zod';
2
+ import type { ContactEntity } from '../../api/clients/сontacts/types/ContactEntity.types';
3
+ import type { ZodShape } from '../types';
4
+
5
+ export const contactSchema = z.object<ZodShape<ContactEntity>>({
6
+ name: z.string().optional(),
7
+ timezones: z.array(z.any()).optional(),
8
+ managers: z.array(z.any()).optional(),
9
+ groups: z.array(z.any()).optional(),
10
+ labels: z.array(z.any()).optional(),
11
+ about: z.string().nullish(),
12
+ user: z.any().nullish(),
13
+ });
@@ -0,0 +1,9 @@
1
+ import type { ContactsEmailAddress } from '@webitel/api-services/gen/models';
2
+ import { z } from 'zod';
3
+ import type { ZodShape } from '../types';
4
+
5
+ export const contactEmailSchema = z.object<ZodShape<ContactsEmailAddress>>({
6
+ email: z.string().min(1).email(),
7
+ type: z.any(),
8
+ primary: z.boolean().optional(),
9
+ });
@@ -0,0 +1,9 @@
1
+ import type { ContactsPhoneNumber } from '@webitel/api-services/gen/models';
2
+ import { z } from 'zod';
3
+ import type { ZodShape } from '../types';
4
+
5
+ export const contactPhoneSchema = z.object<ZodShape<ContactsPhoneNumber>>({
6
+ number: z.string().min(1),
7
+ type: z.any(),
8
+ primary: z.boolean().optional(),
9
+ });
@@ -12,8 +12,11 @@ export * from './caseServiceCatalog/caseServiceCatalog.validations';
12
12
  export * from './caseSource/caseSource.validations';
13
13
  export * from './caseStatus/caseStatus.validations';
14
14
  export * from './caseStatusCondition/caseStatusCondition.validations';
15
+ export * from './contact/contact.validations';
16
+ export * from './contactEmail/contactEmail.validations';
15
17
  export * from './contactGroup/contactGroup.validations';
16
18
  export * from './contactGroupCondition/contactGroupCondition.validations';
19
+ export * from './contactPhone/contactPhone.validations';
17
20
  export * from './OAuth/OAuth.validations';
18
21
  export * from './onlineSkill/onlineSkill.validations';
19
22
  export * from './queue/queue.rules';
@@ -30,3 +33,4 @@ export * from './queueSkill/queueSkill.validations';
30
33
  export * from './sla/sla.validations';
31
34
  export * from './slaCondition/slaCondition.validations';
32
35
  export * from './types';
36
+ export * from './variable/variable.validations';
@@ -0,0 +1,8 @@
1
+ import type { ContactsVariable } from '@webitel/api-services/gen/models';
2
+ import { z } from 'zod';
3
+ import type { ZodShape } from '../types';
4
+
5
+ export const variableSchema = z.object<ZodShape<ContactsVariable>>({
6
+ key: z.string().min(1),
7
+ value: z.string().min(1),
8
+ });