@webitel/api-services 1.0.6 → 1.0.7
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 +2 -1
- package/src/api/clients/caseComments/caseComments.ts +141 -0
- package/src/api/clients/caseFiles/caseFiles.ts +79 -0
- package/src/api/clients/caseLinks/caseLinks.ts +150 -0
- package/src/api/clients/caseRelatedCases/caseRelatedCases.ts +125 -0
- package/src/api/clients/caseServices/services.ts +38 -72
- package/src/api/clients/cases/_internals/ftsService.ts +67 -0
- package/src/api/clients/cases/_internals/stringifyCaseFilters.ts +156 -0
- package/src/api/clients/cases/cases.ts +360 -0
- package/src/api/clients/chatMessagesHistory/chatMessagesHistory.ts +64 -0
- package/src/api/clients/configurations/configurations.ts +56 -39
- package/src/api/clients/contactCases/contactCases.ts +109 -0
- package/src/api/clients/emails/emails.ts +11 -7
- package/src/api/clients/index.ts +9 -0
- package/src/api/clients/labels/labels.ts +24 -29
- package/src/api/clients/phones/phones.ts +11 -7
- package/src/api/clients/timeline/timeline.ts +124 -0
- package/src/api/clients/variables/variables.ts +10 -5
- package/src/api/clients/wtTypes/_shared/utils/assignFieldPositions.ts +28 -0
- package/src/api/clients/wtTypes/_shared/utils/sortDynamicFields.ts +7 -9
- package/src/api/clients/wtTypes/adjunctTypeRecords/adjunctTypeRecords.ts +19 -16
- package/src/api/clients/wtTypes/adjunctTypes/adjunctTypes.ts +4 -0
- package/src/api/clients/wtTypes/typeExtensions/typeExtensions.ts +21 -31
- package/src/api/clients//321/201ontacts/contacts.ts +103 -234
- package/src/api/clients//321/201ontacts/getContactAccessFromMode.ts +9 -0
- package/src/api/clients//321/201ontacts/index.ts +1 -1
- package/src/validations/adjunctType/adjunctType.validations.ts +18 -0
- package/src/validations/case/case.validations.ts +33 -0
- package/src/validations/caseClose/caseClose.validations.ts +30 -0
- package/src/validations/caseExportOptions/caseExportOptions.validations.ts +27 -0
- package/src/validations/contact/contact.validations.ts +12 -7
- package/src/validations/index.ts +5 -0
- package/src/validations/typeExtension/typeExtension.validations.ts +8 -0
- package/types/.tsbuildinfo +1 -1
- package/types/api/clients/caseComments/caseComments.d.ts +20 -0
- package/types/api/clients/caseFiles/caseFiles.d.ts +10 -0
- package/types/api/clients/caseLinks/caseLinks.d.ts +22 -0
- package/types/api/clients/caseRelatedCases/caseRelatedCases.d.ts +14 -0
- package/types/api/clients/caseServices/services.d.ts +3 -12
- package/types/api/clients/cases/_internals/ftsService.d.ts +7 -0
- package/types/api/clients/cases/_internals/stringifyCaseFilters.d.ts +2 -0
- package/types/api/clients/cases/cases.d.ts +35 -0
- package/types/api/clients/chatMessagesHistory/chatMessagesHistory.d.ts +15 -0
- package/types/api/clients/contactCases/contactCases.d.ts +9 -0
- package/types/api/clients/index.d.ts +9 -0
- package/types/api/clients/labels/labels.d.ts +2 -2
- package/types/api/clients/timeline/timeline.d.ts +16 -0
- package/types/api/clients/wtTypes/_shared/utils/assignFieldPositions.d.ts +2 -0
- package/types/api/clients/wtTypes/_shared/utils/sortDynamicFields.d.ts +2 -2
- package/types/api/clients/wtTypes/adjunctTypeRecords/adjunctTypeRecords.d.ts +11 -11
- package/types/api/clients/wtTypes/typeExtensions/typeExtensions.d.ts +1 -1
- package/types/api/clients//321/201ontacts/getContactAccessFromMode.d.ts +5 -0
- package/types/api/clients//321/201ontacts/index.d.ts +1 -1
- package/types/validations/adjunctType/adjunctType.validations.d.ts +11 -0
- package/types/validations/case/case.validations.d.ts +31 -0
- package/types/validations/caseClose/caseClose.validations.d.ts +8 -0
- package/types/validations/caseExportOptions/caseExportOptions.validations.d.ts +9 -0
- package/types/validations/contact/contact.validations.d.ts +15 -15
- package/types/validations/index.d.ts +5 -0
- package/types/validations/typeExtension/typeExtension.validations.d.ts +20 -0
- package/src/api/clients//321/201ontacts/types/ContactEntity.types.ts +0 -25
- package/types/api/clients//321/201ontacts/types/ContactEntity.types.d.ts +0 -14
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getShallowFieldsToSendFromZodSchema } from '@webitel/api-services/gen/utils';
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} from '
|
|
3
|
+
CreateSystemSettingBody,
|
|
4
|
+
getSystemSettingService,
|
|
5
|
+
SearchAvailableSystemSettingQueryParams,
|
|
6
|
+
SearchSystemSettingQueryParams,
|
|
7
|
+
} from '../../../gen-wire';
|
|
8
|
+
import { getDefaultGetListResponse, getDefaultGetParams } from '../../defaults';
|
|
8
9
|
import {
|
|
9
10
|
applyTransform,
|
|
10
11
|
camelToSnake,
|
|
11
12
|
merge,
|
|
12
13
|
notify,
|
|
13
|
-
|
|
14
|
+
sanitizeToWire,
|
|
14
15
|
snakeToCamel,
|
|
15
16
|
starToSearch,
|
|
16
17
|
} from '../../transformers';
|
|
@@ -22,30 +23,30 @@ import type {
|
|
|
22
23
|
UpdateItemParams,
|
|
23
24
|
} from '../_shared/types';
|
|
24
25
|
|
|
25
|
-
const instance = getDefaultInstance();
|
|
26
|
-
const configuration = getDefaultOpenAPIConfig();
|
|
27
|
-
|
|
28
|
-
const configurationService = SystemSettingServiceApiFactory(
|
|
29
|
-
configuration,
|
|
30
|
-
'',
|
|
31
|
-
instance,
|
|
32
|
-
);
|
|
33
|
-
|
|
34
26
|
const getList = async (params: ApiParams) => {
|
|
35
|
-
const
|
|
27
|
+
const listFieldsToSend = getShallowFieldsToSendFromZodSchema(
|
|
28
|
+
SearchSystemSettingQueryParams,
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
const { page, size, fields, sort, name, q } = applyTransform(params, [
|
|
36
32
|
merge(getDefaultGetParams()),
|
|
37
|
-
|
|
33
|
+
merge({
|
|
34
|
+
q: params.search,
|
|
35
|
+
}),
|
|
36
|
+
sanitizeToWire(listFieldsToSend),
|
|
37
|
+
starToSearch('q'),
|
|
38
|
+
camelToSnake(),
|
|
38
39
|
]);
|
|
39
40
|
|
|
40
41
|
try {
|
|
41
|
-
const response = await
|
|
42
|
+
const response = await getSystemSettingService().searchSystemSetting({
|
|
42
43
|
page,
|
|
43
44
|
size,
|
|
44
|
-
search,
|
|
45
|
-
sort,
|
|
46
45
|
fields,
|
|
46
|
+
sort,
|
|
47
47
|
name,
|
|
48
|
-
|
|
48
|
+
q,
|
|
49
|
+
});
|
|
49
50
|
const { items, next } = applyTransform(response.data, [
|
|
50
51
|
snakeToCamel(),
|
|
51
52
|
merge(getDefaultGetListResponse()),
|
|
@@ -63,7 +64,9 @@ const getList = async (params: ApiParams) => {
|
|
|
63
64
|
|
|
64
65
|
const get = async ({ itemId: id }: GetItemParams) => {
|
|
65
66
|
try {
|
|
66
|
-
const response = await
|
|
67
|
+
const response = await getSystemSettingService().readSystemSetting(
|
|
68
|
+
Number(id),
|
|
69
|
+
);
|
|
67
70
|
return applyTransform(response.data, [
|
|
68
71
|
snakeToCamel(),
|
|
69
72
|
]);
|
|
@@ -74,19 +77,21 @@ const get = async ({ itemId: id }: GetItemParams) => {
|
|
|
74
77
|
}
|
|
75
78
|
};
|
|
76
79
|
|
|
80
|
+
// `value` is a free-form `google.protobuf.Value` on the backend and has no
|
|
81
|
+
// fixed shape, so it's not part of the generated body schema — kept on the
|
|
82
|
+
// allowlist by hand alongside it (mirrors `custom` on contacts).
|
|
77
83
|
const fieldsToSend = [
|
|
78
|
-
|
|
79
|
-
'name',
|
|
84
|
+
...getShallowFieldsToSendFromZodSchema(CreateSystemSettingBody),
|
|
80
85
|
'value',
|
|
81
86
|
];
|
|
82
87
|
|
|
83
88
|
const add = async ({ itemInstance }: AddItemParams) => {
|
|
84
89
|
const item = applyTransform(itemInstance, [
|
|
85
|
-
|
|
90
|
+
sanitizeToWire(fieldsToSend),
|
|
86
91
|
camelToSnake(),
|
|
87
92
|
]);
|
|
88
93
|
try {
|
|
89
|
-
const response = await
|
|
94
|
+
const response = await getSystemSettingService().createSystemSetting(item);
|
|
90
95
|
return applyTransform(response.data, [
|
|
91
96
|
snakeToCamel(),
|
|
92
97
|
]);
|
|
@@ -99,11 +104,11 @@ const add = async ({ itemInstance }: AddItemParams) => {
|
|
|
99
104
|
|
|
100
105
|
const update = async ({ itemInstance, itemId: id }: UpdateItemParams) => {
|
|
101
106
|
const item = applyTransform(itemInstance, [
|
|
102
|
-
|
|
107
|
+
sanitizeToWire(fieldsToSend),
|
|
103
108
|
camelToSnake(),
|
|
104
109
|
]);
|
|
105
110
|
try {
|
|
106
|
-
const response = await
|
|
111
|
+
const response = await getSystemSettingService().updateSystemSetting(
|
|
107
112
|
Number(id),
|
|
108
113
|
item,
|
|
109
114
|
);
|
|
@@ -127,7 +132,9 @@ const getLookup = (params: Parameters<typeof getList>[0]) =>
|
|
|
127
132
|
|
|
128
133
|
const deleteItem = async ({ id }: DeleteItemParams) => {
|
|
129
134
|
try {
|
|
130
|
-
const response = await
|
|
135
|
+
const response = await getSystemSettingService().deleteSystemSetting(
|
|
136
|
+
Number(id),
|
|
137
|
+
);
|
|
131
138
|
return applyTransform(response.data, []);
|
|
132
139
|
} catch (err) {
|
|
133
140
|
throw applyTransform(err, [
|
|
@@ -137,19 +144,29 @@ const deleteItem = async ({ id }: DeleteItemParams) => {
|
|
|
137
144
|
};
|
|
138
145
|
|
|
139
146
|
const getObjectsList = async (params: ApiParams) => {
|
|
140
|
-
const
|
|
147
|
+
const listFieldsToSend = getShallowFieldsToSendFromZodSchema(
|
|
148
|
+
SearchAvailableSystemSettingQueryParams,
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
const { page, size, fields, sort, q } = applyTransform(params, [
|
|
141
152
|
merge(getDefaultGetParams()),
|
|
142
|
-
|
|
153
|
+
merge({
|
|
154
|
+
q: params.search,
|
|
155
|
+
}),
|
|
156
|
+
sanitizeToWire(listFieldsToSend),
|
|
157
|
+
starToSearch('q'),
|
|
158
|
+
camelToSnake(),
|
|
143
159
|
]);
|
|
144
160
|
|
|
145
161
|
try {
|
|
146
|
-
const response =
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
162
|
+
const response =
|
|
163
|
+
await getSystemSettingService().searchAvailableSystemSetting({
|
|
164
|
+
page,
|
|
165
|
+
size,
|
|
166
|
+
fields,
|
|
167
|
+
sort,
|
|
168
|
+
q,
|
|
169
|
+
});
|
|
153
170
|
const { items, next } = applyTransform(response.data, [
|
|
154
171
|
snakeToCamel(),
|
|
155
172
|
merge(getDefaultGetListResponse()),
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { snakeToKebab } from '@webitel/api-services/utils';
|
|
2
|
+
import { getCases } from '../../../gen-wire';
|
|
3
|
+
import { getDefaultGetListResponse, getDefaultGetParams } from '../../defaults';
|
|
4
|
+
import {
|
|
5
|
+
applyTransform,
|
|
6
|
+
merge,
|
|
7
|
+
notify,
|
|
8
|
+
snakeToCamel,
|
|
9
|
+
} from '../../transformers';
|
|
10
|
+
import type { ApiId, ApiParams } from '../_shared/types';
|
|
11
|
+
import { FTSServiceAPI } from '../cases/_internals/ftsService';
|
|
12
|
+
import { stringifyCaseFilters } from '../cases/_internals/stringifyCaseFilters';
|
|
13
|
+
|
|
14
|
+
function transformSourceType(data: ApiParams) {
|
|
15
|
+
if (Array.isArray(data)) {
|
|
16
|
+
return data.map((item) => {
|
|
17
|
+
if (item.source?.type) {
|
|
18
|
+
item.source.type = snakeToKebab(item.source.type.toLowerCase());
|
|
19
|
+
}
|
|
20
|
+
return item;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (data.source?.type) {
|
|
25
|
+
data.source.type = snakeToKebab(data.source.type.toLowerCase());
|
|
26
|
+
}
|
|
27
|
+
return data;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const getContactCasesList = async ({
|
|
31
|
+
parentId,
|
|
32
|
+
...params
|
|
33
|
+
}: {
|
|
34
|
+
parentId: ApiId;
|
|
35
|
+
} & ApiParams) => {
|
|
36
|
+
let ftsIds: Array<string | number> | undefined;
|
|
37
|
+
const { fts } = params;
|
|
38
|
+
if (fts) {
|
|
39
|
+
try {
|
|
40
|
+
const { items } = await FTSServiceAPI.getList({
|
|
41
|
+
page: params.page,
|
|
42
|
+
size: params.size,
|
|
43
|
+
fts: params.fts,
|
|
44
|
+
sort: params.sort,
|
|
45
|
+
objectName: [
|
|
46
|
+
'cases',
|
|
47
|
+
'case_comments',
|
|
48
|
+
],
|
|
49
|
+
});
|
|
50
|
+
ftsIds = items.map(({ id }: ApiParams) => id);
|
|
51
|
+
} catch {
|
|
52
|
+
// skip error, load cases without fts
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/* everything left over after pulling out the technical query params is a
|
|
57
|
+
* filter, keyed by the (camelCase) filter names stringifyCaseFilters expects */
|
|
58
|
+
const { page, size, q, ids, sort, fields, ...filters } = applyTransform(
|
|
59
|
+
{
|
|
60
|
+
...params,
|
|
61
|
+
ids: params.ids || ftsIds,
|
|
62
|
+
},
|
|
63
|
+
[
|
|
64
|
+
merge(getDefaultGetParams()),
|
|
65
|
+
(params) => ({
|
|
66
|
+
...params,
|
|
67
|
+
q: params.search,
|
|
68
|
+
}),
|
|
69
|
+
],
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
try {
|
|
73
|
+
const response = await getCases().searchCases2(String(parentId), {
|
|
74
|
+
page,
|
|
75
|
+
size,
|
|
76
|
+
q,
|
|
77
|
+
ids,
|
|
78
|
+
sort,
|
|
79
|
+
fields: [
|
|
80
|
+
...(fields || []),
|
|
81
|
+
'etag',
|
|
82
|
+
'id',
|
|
83
|
+
'custom',
|
|
84
|
+
],
|
|
85
|
+
filters: stringifyCaseFilters(filters),
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
const { items, next } = applyTransform(response.data, [
|
|
89
|
+
merge(getDefaultGetListResponse()),
|
|
90
|
+
]);
|
|
91
|
+
return {
|
|
92
|
+
items: applyTransform(items, [
|
|
93
|
+
snakeToCamel([
|
|
94
|
+
'custom',
|
|
95
|
+
]),
|
|
96
|
+
transformSourceType,
|
|
97
|
+
]),
|
|
98
|
+
next,
|
|
99
|
+
};
|
|
100
|
+
} catch (err) {
|
|
101
|
+
throw applyTransform(err, [
|
|
102
|
+
notify,
|
|
103
|
+
]);
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
export const ContactCasesAPI = {
|
|
108
|
+
getList: getContactCasesList,
|
|
109
|
+
};
|
|
@@ -62,6 +62,13 @@ const getList = async ({
|
|
|
62
62
|
}
|
|
63
63
|
};
|
|
64
64
|
|
|
65
|
+
const emailFieldsToSend = [
|
|
66
|
+
'email',
|
|
67
|
+
'primary',
|
|
68
|
+
'etag',
|
|
69
|
+
'type',
|
|
70
|
+
];
|
|
71
|
+
|
|
65
72
|
const get = async ({
|
|
66
73
|
itemId,
|
|
67
74
|
parentId,
|
|
@@ -69,18 +76,12 @@ const get = async ({
|
|
|
69
76
|
itemId: ApiId;
|
|
70
77
|
parentId: ApiId;
|
|
71
78
|
}) => {
|
|
72
|
-
const fields = [
|
|
73
|
-
'email',
|
|
74
|
-
'primary',
|
|
75
|
-
'etag',
|
|
76
|
-
'type',
|
|
77
|
-
];
|
|
78
79
|
try {
|
|
79
80
|
const response = await getEmails().locateEmail(
|
|
80
81
|
String(parentId),
|
|
81
82
|
String(itemId),
|
|
82
83
|
{
|
|
83
|
-
fields,
|
|
84
|
+
fields: emailFieldsToSend,
|
|
84
85
|
},
|
|
85
86
|
);
|
|
86
87
|
return applyTransform(response.data, [
|
|
@@ -142,6 +143,9 @@ const update = async ({
|
|
|
142
143
|
String(parentId),
|
|
143
144
|
itemInstance.etag,
|
|
144
145
|
item,
|
|
146
|
+
{
|
|
147
|
+
fields: emailFieldsToSend,
|
|
148
|
+
},
|
|
145
149
|
);
|
|
146
150
|
const { data } = applyTransform(response.data, [
|
|
147
151
|
snakeToCamel(),
|
package/src/api/clients/index.ts
CHANGED
|
@@ -8,18 +8,25 @@ export * from './calendars/calendars';
|
|
|
8
8
|
export * from './callHistory/callHistory';
|
|
9
9
|
export * from './caseCloseReasonGroups/caseCloseReasonGroups';
|
|
10
10
|
export * from './caseCloseReasons/caseCloseReasons';
|
|
11
|
+
export * from './caseComments/caseComments';
|
|
12
|
+
export * from './caseFiles/caseFiles';
|
|
13
|
+
export * from './caseLinks/caseLinks';
|
|
11
14
|
export * from './casePriorities/casePriorities';
|
|
15
|
+
export * from './caseRelatedCases/caseRelatedCases';
|
|
12
16
|
export * from './caseServiceCatalogs/serviceCatalogs';
|
|
13
17
|
export * from './caseServices/services';
|
|
14
18
|
export * from './caseSources/caseSources';
|
|
15
19
|
export * from './caseStatusConditions/caseStatusConditions';
|
|
16
20
|
export * from './caseStatuses/caseStatuses';
|
|
21
|
+
export * from './cases/cases';
|
|
17
22
|
export * from './catalog/catalog';
|
|
18
23
|
export * from './changelogs/changelogs';
|
|
19
24
|
export * from './chatDialogs/chatDialogs';
|
|
20
25
|
export * from './chatGateways/chatGateways';
|
|
26
|
+
export * from './chatMessagesHistory/chatMessagesHistory';
|
|
21
27
|
export * from './communications/communications';
|
|
22
28
|
export * from './configurations/configurations';
|
|
29
|
+
export * from './contactCases/contactCases';
|
|
23
30
|
export * from './contactGroups/contactGroups';
|
|
24
31
|
export * from './dynamicConditions/dynamicConditions';
|
|
25
32
|
export * from './dynamicGroups/dynamicGroups';
|
|
@@ -51,8 +58,10 @@ export * from './quickReplies/quickReplies';
|
|
|
51
58
|
export * from './regions/regions';
|
|
52
59
|
// export * from './roles/roles'; fixme: ApplicationAccess import
|
|
53
60
|
export * from './skills/skills';
|
|
61
|
+
export * from './slaConditions/slaConditions';
|
|
54
62
|
export * from './slas/slas';
|
|
55
63
|
export * from './teams/teams';
|
|
64
|
+
export * from './timeline/timeline';
|
|
56
65
|
export * from './userSettings/userSettings';
|
|
57
66
|
export * from './users/users';
|
|
58
67
|
export * from './variables/variables';
|
|
@@ -1,42 +1,38 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
getDefaultInstance,
|
|
5
|
-
getDefaultOpenAPIConfig,
|
|
6
|
-
} from '../../defaults';
|
|
1
|
+
import { getShallowFieldsToSendFromZodSchema } from '@webitel/api-services/gen/utils';
|
|
2
|
+
import { GetLabelsQueryParams, getLabels } from '../../../gen-wire';
|
|
3
|
+
import { getDefaultGetParams } from '../../defaults';
|
|
7
4
|
import {
|
|
8
5
|
applyTransform,
|
|
9
6
|
camelToSnake,
|
|
10
7
|
merge,
|
|
11
8
|
notify,
|
|
12
|
-
|
|
9
|
+
sanitizeToWire,
|
|
13
10
|
snakeToCamel,
|
|
14
11
|
starToSearch,
|
|
15
12
|
} from '../../transformers';
|
|
16
13
|
import type { ApiParams } from '../_shared/types';
|
|
17
14
|
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
const service = LabelsApiFactory(configuration, '', instance);
|
|
15
|
+
const getLabelsList = async (params: ApiParams) => {
|
|
16
|
+
const listFieldsToSend =
|
|
17
|
+
getShallowFieldsToSendFromZodSchema(GetLabelsQueryParams);
|
|
22
18
|
|
|
23
|
-
const
|
|
24
|
-
const fieldsToSend = [
|
|
25
|
-
'page',
|
|
26
|
-
'size',
|
|
27
|
-
'search',
|
|
28
|
-
'sort',
|
|
29
|
-
'fields',
|
|
30
|
-
'id',
|
|
31
|
-
];
|
|
32
|
-
const { page, size, search } = applyTransform(params, [
|
|
33
|
-
sanitize(fieldsToSend),
|
|
19
|
+
const { page, size, q, fields } = applyTransform(params, [
|
|
34
20
|
merge(getDefaultGetParams()),
|
|
35
|
-
|
|
21
|
+
merge({
|
|
22
|
+
q: params.search,
|
|
23
|
+
}),
|
|
24
|
+
sanitizeToWire(listFieldsToSend),
|
|
25
|
+
starToSearch('q'),
|
|
36
26
|
camelToSnake(),
|
|
37
27
|
]);
|
|
28
|
+
|
|
38
29
|
try {
|
|
39
|
-
const response = await
|
|
30
|
+
const response = await getLabels().getLabels({
|
|
31
|
+
page,
|
|
32
|
+
size,
|
|
33
|
+
q,
|
|
34
|
+
fields,
|
|
35
|
+
});
|
|
40
36
|
const { labels, next } = applyTransform(response.data, [
|
|
41
37
|
snakeToCamel(),
|
|
42
38
|
merge({
|
|
@@ -55,16 +51,15 @@ const getList = async (params: ApiParams) => {
|
|
|
55
51
|
}
|
|
56
52
|
};
|
|
57
53
|
|
|
58
|
-
const getLabelsLookup = (params: Parameters<typeof
|
|
59
|
-
|
|
54
|
+
const getLabelsLookup = (params: Parameters<typeof getLabelsList>[0]) =>
|
|
55
|
+
getLabelsList({
|
|
60
56
|
...params,
|
|
61
57
|
fields: params.fields || [
|
|
62
|
-
'
|
|
63
|
-
'name',
|
|
58
|
+
'label',
|
|
64
59
|
],
|
|
65
60
|
});
|
|
66
61
|
|
|
67
62
|
export const LabelsAPI = {
|
|
68
|
-
getList,
|
|
63
|
+
getList: getLabelsList,
|
|
69
64
|
getLookup: getLabelsLookup,
|
|
70
65
|
};
|
|
@@ -63,6 +63,13 @@ const getPhonesList = async ({
|
|
|
63
63
|
}
|
|
64
64
|
};
|
|
65
65
|
|
|
66
|
+
const phoneFieldsToSend = [
|
|
67
|
+
'number',
|
|
68
|
+
'primary',
|
|
69
|
+
'etag',
|
|
70
|
+
'type',
|
|
71
|
+
];
|
|
72
|
+
|
|
66
73
|
const getPhone = async ({
|
|
67
74
|
itemId,
|
|
68
75
|
parentId,
|
|
@@ -70,18 +77,12 @@ const getPhone = async ({
|
|
|
70
77
|
itemId: ApiId;
|
|
71
78
|
parentId: ApiId;
|
|
72
79
|
}) => {
|
|
73
|
-
const fields = [
|
|
74
|
-
'number',
|
|
75
|
-
'primary',
|
|
76
|
-
'etag',
|
|
77
|
-
'type',
|
|
78
|
-
];
|
|
79
80
|
try {
|
|
80
81
|
const response = await getPhones().locatePhone(
|
|
81
82
|
String(parentId),
|
|
82
83
|
String(itemId),
|
|
83
84
|
{
|
|
84
|
-
fields,
|
|
85
|
+
fields: phoneFieldsToSend,
|
|
85
86
|
},
|
|
86
87
|
);
|
|
87
88
|
return applyTransform(response.data, [
|
|
@@ -143,6 +144,9 @@ const updatePhone = async ({
|
|
|
143
144
|
String(parentId),
|
|
144
145
|
itemInstance.etag,
|
|
145
146
|
item,
|
|
147
|
+
{
|
|
148
|
+
fields: phoneFieldsToSend,
|
|
149
|
+
},
|
|
146
150
|
);
|
|
147
151
|
const { data } = applyTransform(response.data, [
|
|
148
152
|
snakeToCamel(),
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { getShallowFieldsToSendFromZodSchema } from '@webitel/api-services/gen/utils';
|
|
2
|
+
import {
|
|
3
|
+
GetTimelineQueryParams,
|
|
4
|
+
GetTimelineTimelineQueryParams,
|
|
5
|
+
getCaseTimeline,
|
|
6
|
+
getTimeline,
|
|
7
|
+
} from '../../../gen-wire';
|
|
8
|
+
|
|
9
|
+
import { getDefaultGetParams } from '../../defaults';
|
|
10
|
+
import {
|
|
11
|
+
applyTransform,
|
|
12
|
+
merge,
|
|
13
|
+
notify,
|
|
14
|
+
sanitizeToWire,
|
|
15
|
+
snakeToCamel,
|
|
16
|
+
} from '../../transformers';
|
|
17
|
+
import type { ApiId, ApiParams } from '../_shared/types';
|
|
18
|
+
|
|
19
|
+
type TimelineEntity = 'case' | 'contact';
|
|
20
|
+
|
|
21
|
+
const clients = {
|
|
22
|
+
case: {
|
|
23
|
+
getTimeline: (parentId, params) =>
|
|
24
|
+
getCaseTimeline().getTimeline(parentId, params),
|
|
25
|
+
getTimelineCounter: (parentId) =>
|
|
26
|
+
getCaseTimeline().getTimelineCounter(parentId),
|
|
27
|
+
queryParamsSchema: GetTimelineQueryParams,
|
|
28
|
+
},
|
|
29
|
+
contact: {
|
|
30
|
+
getTimeline: (parentId, params) =>
|
|
31
|
+
getTimeline().getTimelineTimeline(parentId, params),
|
|
32
|
+
getTimelineCounter: (parentId) =>
|
|
33
|
+
getTimeline().getTimelineCounterTimeline(parentId),
|
|
34
|
+
queryParamsSchema: GetTimelineTimelineQueryParams,
|
|
35
|
+
},
|
|
36
|
+
} satisfies Record<
|
|
37
|
+
TimelineEntity,
|
|
38
|
+
{
|
|
39
|
+
getTimeline: (
|
|
40
|
+
parentId: string,
|
|
41
|
+
params: ApiParams,
|
|
42
|
+
) => Promise<{
|
|
43
|
+
data: unknown;
|
|
44
|
+
}>;
|
|
45
|
+
getTimelineCounter: (parentId: string) => Promise<{
|
|
46
|
+
data: unknown;
|
|
47
|
+
}>;
|
|
48
|
+
queryParamsSchema: unknown;
|
|
49
|
+
}
|
|
50
|
+
>;
|
|
51
|
+
|
|
52
|
+
const getList = async ({
|
|
53
|
+
entity,
|
|
54
|
+
parentId,
|
|
55
|
+
...rest
|
|
56
|
+
}: {
|
|
57
|
+
entity: TimelineEntity;
|
|
58
|
+
parentId: ApiId;
|
|
59
|
+
} & ApiParams) => {
|
|
60
|
+
const { getTimeline, queryParamsSchema } = clients[entity];
|
|
61
|
+
const fieldsToSend = getShallowFieldsToSendFromZodSchema(queryParamsSchema);
|
|
62
|
+
|
|
63
|
+
const { dateFrom, dateTo, type, page, size } = applyTransform(rest, [
|
|
64
|
+
merge(getDefaultGetParams()),
|
|
65
|
+
sanitizeToWire(fieldsToSend),
|
|
66
|
+
]);
|
|
67
|
+
|
|
68
|
+
try {
|
|
69
|
+
const response = await getTimeline(String(parentId), {
|
|
70
|
+
page,
|
|
71
|
+
size,
|
|
72
|
+
dateFrom,
|
|
73
|
+
dateTo,
|
|
74
|
+
type,
|
|
75
|
+
});
|
|
76
|
+
// `days` can be a large, deeply-nested tree — merge() would recursively
|
|
77
|
+
// clone the whole thing via deepmerge just to add unused `items`/`next`
|
|
78
|
+
// defaults, which risks a stack overflow on large histories.
|
|
79
|
+
const data = applyTransform(response.data, [
|
|
80
|
+
snakeToCamel(),
|
|
81
|
+
]);
|
|
82
|
+
return {
|
|
83
|
+
days: data?.days ?? [],
|
|
84
|
+
next: data?.next ?? false,
|
|
85
|
+
};
|
|
86
|
+
} catch (err) {
|
|
87
|
+
throw applyTransform(err, [
|
|
88
|
+
notify,
|
|
89
|
+
]);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const getCounters = async ({
|
|
94
|
+
entity,
|
|
95
|
+
parentId,
|
|
96
|
+
}: {
|
|
97
|
+
entity: TimelineEntity;
|
|
98
|
+
parentId: ApiId;
|
|
99
|
+
}) => {
|
|
100
|
+
const { getTimelineCounter } = clients[entity];
|
|
101
|
+
const defaultObject = {
|
|
102
|
+
callsCount: 0,
|
|
103
|
+
chatsCount: 0,
|
|
104
|
+
emailsCount: 0,
|
|
105
|
+
dateFrom: Date.now(),
|
|
106
|
+
dateTo: Date.now(),
|
|
107
|
+
};
|
|
108
|
+
try {
|
|
109
|
+
const response = await getTimelineCounter(String(parentId));
|
|
110
|
+
return applyTransform(response.data, [
|
|
111
|
+
snakeToCamel(),
|
|
112
|
+
merge(defaultObject),
|
|
113
|
+
]);
|
|
114
|
+
} catch (err) {
|
|
115
|
+
throw applyTransform(err, [
|
|
116
|
+
notify,
|
|
117
|
+
]);
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
export const TimelineAPI = {
|
|
122
|
+
getList,
|
|
123
|
+
getCounters,
|
|
124
|
+
};
|
|
@@ -61,6 +61,12 @@ const getVariablesList = async ({
|
|
|
61
61
|
}
|
|
62
62
|
};
|
|
63
63
|
|
|
64
|
+
const variableFieldsToSend = [
|
|
65
|
+
'key',
|
|
66
|
+
'value',
|
|
67
|
+
'etag',
|
|
68
|
+
];
|
|
69
|
+
|
|
64
70
|
// no dedicated "locate one" endpoint exists for variables — reuse the list
|
|
65
71
|
// endpoint filtered to a single id, matching what the crm-local adapter did
|
|
66
72
|
const getVariable = async ({
|
|
@@ -74,11 +80,7 @@ const getVariable = async ({
|
|
|
74
80
|
const response = await getVariables().listVariables(parentId, {
|
|
75
81
|
page: 1,
|
|
76
82
|
size: 1,
|
|
77
|
-
fields:
|
|
78
|
-
'key',
|
|
79
|
-
'value',
|
|
80
|
-
'etag',
|
|
81
|
-
],
|
|
83
|
+
fields: variableFieldsToSend,
|
|
82
84
|
id: [
|
|
83
85
|
itemId,
|
|
84
86
|
],
|
|
@@ -145,6 +147,9 @@ const updateVariable = async ({
|
|
|
145
147
|
parentId,
|
|
146
148
|
itemInstance.etag,
|
|
147
149
|
item,
|
|
150
|
+
{
|
|
151
|
+
fields: variableFieldsToSend,
|
|
152
|
+
},
|
|
148
153
|
);
|
|
149
154
|
const { data } = applyTransform(response.data, [
|
|
150
155
|
snakeToCamel(),
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
DataField,
|
|
3
|
+
ProtoDataStruct,
|
|
4
|
+
} from '@webitel/api-services/gen/models';
|
|
5
|
+
|
|
6
|
+
type PositionableDataField = DataField & {
|
|
7
|
+
position?: number;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
// readonly (system) fields never get a position; every other field is
|
|
11
|
+
// numbered in the order the backend returns it, 1-based.
|
|
12
|
+
export const assignFieldPositions = (
|
|
13
|
+
item: ProtoDataStruct,
|
|
14
|
+
): ProtoDataStruct => {
|
|
15
|
+
let position = 1;
|
|
16
|
+
|
|
17
|
+
const fields = ((item.fields ?? []) as PositionableDataField[]).map(
|
|
18
|
+
(field) => ({
|
|
19
|
+
...field,
|
|
20
|
+
position: field.readonly ? undefined : position++,
|
|
21
|
+
}),
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
...item,
|
|
26
|
+
fields,
|
|
27
|
+
};
|
|
28
|
+
};
|
|
@@ -1,18 +1,16 @@
|
|
|
1
|
-
import deepCopy from 'deep-copy';
|
|
2
1
|
import type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
} from 'webitel-
|
|
2
|
+
DataField,
|
|
3
|
+
ProtoDataStruct,
|
|
4
|
+
} from '@webitel/api-services/gen/models';
|
|
5
|
+
import deepCopy from 'deep-copy';
|
|
6
6
|
|
|
7
|
-
// The generated
|
|
7
|
+
// The generated type omits `position`, but the backend returns it
|
|
8
8
|
// and it drives ordering of dynamic fields.
|
|
9
|
-
type SortableDataField =
|
|
9
|
+
type SortableDataField = DataField & {
|
|
10
10
|
position?: number;
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
export const sortDynamicFields = (
|
|
14
|
-
item: WebitelProtoDataStruct,
|
|
15
|
-
): WebitelProtoDataStruct => {
|
|
13
|
+
export const sortDynamicFields = (item: ProtoDataStruct): ProtoDataStruct => {
|
|
16
14
|
const allFields = (item.fields ?? []) as SortableDataField[];
|
|
17
15
|
|
|
18
16
|
const unSortableFields = allFields.filter((field) => !field.position);
|