@webitel/ui-sdk 24.10.4 → 24.10.6
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
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import { ContactsApiFactory } from 'webitel-sdk';
|
|
2
|
+
import {
|
|
3
|
+
getDefaultGetListResponse,
|
|
4
|
+
getDefaultGetParams,
|
|
5
|
+
getDefaultInstance,
|
|
6
|
+
getDefaultOpenAPIConfig,
|
|
7
|
+
} from '../defaults/index.js';
|
|
8
|
+
import applyTransform, {
|
|
9
|
+
camelToSnake,
|
|
10
|
+
merge,
|
|
11
|
+
notify,
|
|
12
|
+
sanitize,
|
|
13
|
+
snakeToCamel,
|
|
14
|
+
} from '../transformers/index.js';
|
|
15
|
+
import ContactsSearchMode from './enums/ContactsSearchMode.js';
|
|
16
|
+
|
|
17
|
+
const instance = getDefaultInstance();
|
|
18
|
+
const configuration = getDefaultOpenAPIConfig();
|
|
19
|
+
|
|
20
|
+
const contactService = new ContactsApiFactory(configuration, '', instance);
|
|
21
|
+
|
|
22
|
+
const formatAccessMode = (item) => ({
|
|
23
|
+
...item,
|
|
24
|
+
access: {
|
|
25
|
+
edit: item.mode.includes('w'),
|
|
26
|
+
delete: item.mode.includes('d'),
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const getList = async (params) => {
|
|
31
|
+
const fieldsToSend = ['page', 'size', 'q', 'sort', 'fields', 'id', 'qin'];
|
|
32
|
+
|
|
33
|
+
if (!params.fields) {
|
|
34
|
+
params.fields = [
|
|
35
|
+
'id',
|
|
36
|
+
'etag',
|
|
37
|
+
'name',
|
|
38
|
+
'managers',
|
|
39
|
+
'labels',
|
|
40
|
+
'about',
|
|
41
|
+
'variables',
|
|
42
|
+
'timezones',
|
|
43
|
+
'phones',
|
|
44
|
+
'emails',
|
|
45
|
+
'imclients',
|
|
46
|
+
];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const listResponseHandler = (items) =>
|
|
50
|
+
items?.map((item) => ({
|
|
51
|
+
...item,
|
|
52
|
+
name: item.name.commonName,
|
|
53
|
+
managers: item.managers ? [...item.managers.data] : [],
|
|
54
|
+
labels: item.labels ? [...item.labels.data] : [],
|
|
55
|
+
variables: item.variables ? [...item.variables.data] : [],
|
|
56
|
+
timezones: item.timezones ? [...item.timezones.data] : [],
|
|
57
|
+
phones: item.phones ? [...item.phones.data] : [],
|
|
58
|
+
emails: item.emails ? [...item.emails.data] : [],
|
|
59
|
+
}));
|
|
60
|
+
|
|
61
|
+
let changedParams;
|
|
62
|
+
|
|
63
|
+
if(params?.search) {
|
|
64
|
+
changedParams = { ...params, q: params.search };
|
|
65
|
+
} else if (params?.q && params?.qin) {
|
|
66
|
+
changedParams = { ...params };
|
|
67
|
+
} else {
|
|
68
|
+
let searchValue = '';
|
|
69
|
+
let searchKey = '';
|
|
70
|
+
|
|
71
|
+
if (params[ContactsSearchMode.NAME]) {
|
|
72
|
+
searchValue = params[ContactsSearchMode.NAME];
|
|
73
|
+
searchKey = ContactsSearchMode.NAME;
|
|
74
|
+
} else if (params[ContactsSearchMode.LABELS]) {
|
|
75
|
+
searchValue = params[ContactsSearchMode.LABELS];
|
|
76
|
+
searchKey = ContactsSearchMode.LABELS;
|
|
77
|
+
} else if (params[ContactsSearchMode.ABOUT]) {
|
|
78
|
+
searchValue = params[ContactsSearchMode.ABOUT];
|
|
79
|
+
searchKey = ContactsSearchMode.ABOUT;
|
|
80
|
+
} else if (params[ContactsSearchMode.VARIABLES]) {
|
|
81
|
+
searchValue = params[ContactsSearchMode.VARIABLES];
|
|
82
|
+
searchKey = ContactsSearchMode.VARIABLES;
|
|
83
|
+
} else if (params[ContactsSearchMode.DESTINATION]) {
|
|
84
|
+
searchValue = params[ContactsSearchMode.DESTINATION];
|
|
85
|
+
searchKey = 'emails,phones';
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// This code needed for adding starToSearch method to applyTransform while searchKey !== SearchMode.VARIABLES because '*' in variables search mode brokes backend logic.
|
|
89
|
+
// if (searchKey !== ContactsSearchMode.VARIABLES) {
|
|
90
|
+
// transformations.push(starToSearch('q')); WTEL-4265
|
|
91
|
+
// }
|
|
92
|
+
|
|
93
|
+
changedParams = {
|
|
94
|
+
...params,
|
|
95
|
+
q: searchValue || '',
|
|
96
|
+
qin: searchKey || '',
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const transformations = [sanitize(fieldsToSend), merge(getDefaultGetParams()), camelToSnake()];
|
|
101
|
+
|
|
102
|
+
const { page, size, q, sort, fields, id, qin } = applyTransform(changedParams, transformations);
|
|
103
|
+
|
|
104
|
+
try {
|
|
105
|
+
const response = await contactService.searchContacts(
|
|
106
|
+
page,
|
|
107
|
+
size,
|
|
108
|
+
q,
|
|
109
|
+
sort || '+name',
|
|
110
|
+
['mode', ...fields],
|
|
111
|
+
id,
|
|
112
|
+
qin,
|
|
113
|
+
);
|
|
114
|
+
const { data, next } = applyTransform(response.data, [
|
|
115
|
+
snakeToCamel(),
|
|
116
|
+
merge(getDefaultGetListResponse()),
|
|
117
|
+
]);
|
|
118
|
+
return {
|
|
119
|
+
items: applyTransform(data, [(items) => items?.map((item) => formatAccessMode(item)), listResponseHandler]),
|
|
120
|
+
next,
|
|
121
|
+
};
|
|
122
|
+
} catch (err) {
|
|
123
|
+
throw applyTransform(err, [notify]);
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
const get = async ({ itemId: id }) => {
|
|
128
|
+
const fields = [
|
|
129
|
+
'name',
|
|
130
|
+
'about',
|
|
131
|
+
'labels',
|
|
132
|
+
'etag',
|
|
133
|
+
'mode',
|
|
134
|
+
'managers',
|
|
135
|
+
'timezones',
|
|
136
|
+
'variables',
|
|
137
|
+
'phones',
|
|
138
|
+
'emails',
|
|
139
|
+
'imclients',
|
|
140
|
+
];
|
|
141
|
+
|
|
142
|
+
const defaultObject = {};
|
|
143
|
+
const itemResponseHandler = (item) => {
|
|
144
|
+
return {
|
|
145
|
+
...item,
|
|
146
|
+
labels: item.labels ? [...item.labels.data] : [],
|
|
147
|
+
managers: item.managers ? [...item.managers.data] : [],
|
|
148
|
+
timezones: item.timezones ? [...item.timezones.data] : [],
|
|
149
|
+
variables: item.variables ? [...item.variables.data] : [],
|
|
150
|
+
phones: item.phones ? [...item.phones.data] : [],
|
|
151
|
+
emails: item.emails ? [...item.emails.data] : [],
|
|
152
|
+
};
|
|
153
|
+
};
|
|
154
|
+
try {
|
|
155
|
+
const response = await contactService.locateContact(id, fields);
|
|
156
|
+
return applyTransform(response.data, [
|
|
157
|
+
snakeToCamel(),
|
|
158
|
+
merge(defaultObject),
|
|
159
|
+
itemResponseHandler,
|
|
160
|
+
formatAccessMode,
|
|
161
|
+
]);
|
|
162
|
+
} catch (err) {
|
|
163
|
+
throw applyTransform(err, [notify]);
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
const fieldsToSend = ['name', 'labels', 'about', 'managers', 'timezones'];
|
|
168
|
+
|
|
169
|
+
const sanitizeManagers = (itemInstance) => {
|
|
170
|
+
// handle many managers and even no managers field cases
|
|
171
|
+
const managers = (itemInstance.managers || []).filter(({ user } = {}) => user.id);
|
|
172
|
+
return { ...itemInstance, managers };
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
const sanitizeTimezones = (itemInstance) => {
|
|
176
|
+
// handle many timezones and even no timezones field cases
|
|
177
|
+
const timezones = (itemInstance.timezones || []).filter(({ timezone } = {}) => timezone.id);
|
|
178
|
+
return { ...itemInstance, timezones };
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
const add = async ({ itemInstance }) => {
|
|
182
|
+
const item = applyTransform(itemInstance, [
|
|
183
|
+
sanitizeManagers,
|
|
184
|
+
sanitizeTimezones,
|
|
185
|
+
sanitize(fieldsToSend),
|
|
186
|
+
camelToSnake(),
|
|
187
|
+
]);
|
|
188
|
+
try {
|
|
189
|
+
const response = await contactService.createContact(item);
|
|
190
|
+
return applyTransform(response.data, [snakeToCamel()]);
|
|
191
|
+
} catch (err) {
|
|
192
|
+
throw applyTransform(err, [notify]);
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
const update = async ({ itemInstance }) => {
|
|
197
|
+
const { etag } = itemInstance;
|
|
198
|
+
const item = applyTransform(itemInstance, [
|
|
199
|
+
sanitizeManagers,
|
|
200
|
+
sanitizeTimezones,
|
|
201
|
+
sanitize(fieldsToSend),
|
|
202
|
+
camelToSnake(),
|
|
203
|
+
]);
|
|
204
|
+
try {
|
|
205
|
+
const response = await contactService.updateContact(etag, item);
|
|
206
|
+
return applyTransform(response.data, [snakeToCamel()]);
|
|
207
|
+
} catch (err) {
|
|
208
|
+
throw applyTransform(err, [notify]);
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
const deleteContact = async ({ id }) => {
|
|
213
|
+
try {
|
|
214
|
+
const response = await contactService.deleteContact(id);
|
|
215
|
+
return applyTransform(response.data, []);
|
|
216
|
+
} catch (err) {
|
|
217
|
+
throw applyTransform(err, [notify]);
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
const getContactsLookup = (params) => getList({
|
|
222
|
+
...params,
|
|
223
|
+
fields: params.fields || ['id', 'name'],
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
const ContactsAPI = {
|
|
227
|
+
getList,
|
|
228
|
+
get,
|
|
229
|
+
add,
|
|
230
|
+
update,
|
|
231
|
+
delete: deleteContact,
|
|
232
|
+
getLookup: getContactsLookup,
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
export default ContactsAPI;
|
package/src/api/crm/index.js
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import ChatGatewayProvider from './ChatGatewayProvider.enum.js';
|
|
2
|
+
|
|
3
|
+
const ProviderIconType = Object.freeze({
|
|
4
|
+
[ChatGatewayProvider.TELEGRAM_BOT]: 'telegram-bot',
|
|
5
|
+
[ChatGatewayProvider.TELEGRAM_APP]: 'messenger-telegram',
|
|
6
|
+
[ChatGatewayProvider.MESSENGER]: 'meta',
|
|
7
|
+
[ChatGatewayProvider.VIBER]: 'messenger-viber',
|
|
8
|
+
[ChatGatewayProvider.WEBCHAT]: 'messenger-web-chat',
|
|
9
|
+
[ChatGatewayProvider.INFOBIP]: 'messenger-infobip',
|
|
10
|
+
[ChatGatewayProvider.CUSTOM]: 'custom-chat-gateway',
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
export default ProviderIconType;
|