@webitel/api-services 1.0.6 → 1.0.8

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 (64) hide show
  1. package/package.json +2 -1
  2. package/src/api/clients/calendars/__tests__/calendars.spec.ts +71 -0
  3. package/src/api/clients/calendars/calendars.ts +2 -2
  4. package/src/api/clients/caseComments/caseComments.ts +141 -0
  5. package/src/api/clients/caseFiles/caseFiles.ts +79 -0
  6. package/src/api/clients/caseLinks/caseLinks.ts +150 -0
  7. package/src/api/clients/caseRelatedCases/caseRelatedCases.ts +125 -0
  8. package/src/api/clients/caseServices/services.ts +38 -72
  9. package/src/api/clients/cases/_internals/ftsService.ts +67 -0
  10. package/src/api/clients/cases/_internals/stringifyCaseFilters.ts +156 -0
  11. package/src/api/clients/cases/cases.ts +360 -0
  12. package/src/api/clients/chatMessagesHistory/chatMessagesHistory.ts +64 -0
  13. package/src/api/clients/configurations/configurations.ts +56 -39
  14. package/src/api/clients/contactCases/contactCases.ts +109 -0
  15. package/src/api/clients/emails/emails.ts +11 -7
  16. package/src/api/clients/index.ts +9 -0
  17. package/src/api/clients/labels/labels.ts +24 -29
  18. package/src/api/clients/phones/phones.ts +11 -7
  19. package/src/api/clients/timeline/timeline.ts +124 -0
  20. package/src/api/clients/variables/variables.ts +10 -5
  21. package/src/api/clients/wtTypes/_shared/utils/assignFieldPositions.ts +28 -0
  22. package/src/api/clients/wtTypes/_shared/utils/sortDynamicFields.ts +7 -9
  23. package/src/api/clients/wtTypes/adjunctTypeRecords/adjunctTypeRecords.ts +19 -16
  24. package/src/api/clients/wtTypes/adjunctTypes/adjunctTypes.ts +4 -0
  25. package/src/api/clients/wtTypes/typeExtensions/typeExtensions.ts +21 -31
  26. package/src/api/clients//321/201ontacts/contacts.ts +103 -234
  27. package/src/api/clients//321/201ontacts/getContactAccessFromMode.ts +9 -0
  28. package/src/api/clients//321/201ontacts/index.ts +1 -1
  29. package/src/validations/adjunctType/adjunctType.validations.ts +18 -0
  30. package/src/validations/case/case.validations.ts +33 -0
  31. package/src/validations/caseClose/caseClose.validations.ts +30 -0
  32. package/src/validations/caseExportOptions/caseExportOptions.validations.ts +27 -0
  33. package/src/validations/contact/contact.validations.ts +12 -7
  34. package/src/validations/index.ts +5 -0
  35. package/src/validations/typeExtension/typeExtension.validations.ts +8 -0
  36. package/types/.tsbuildinfo +1 -1
  37. package/types/api/clients/caseComments/caseComments.d.ts +20 -0
  38. package/types/api/clients/caseFiles/caseFiles.d.ts +10 -0
  39. package/types/api/clients/caseLinks/caseLinks.d.ts +22 -0
  40. package/types/api/clients/caseRelatedCases/caseRelatedCases.d.ts +14 -0
  41. package/types/api/clients/caseServices/services.d.ts +3 -12
  42. package/types/api/clients/cases/_internals/ftsService.d.ts +7 -0
  43. package/types/api/clients/cases/_internals/stringifyCaseFilters.d.ts +2 -0
  44. package/types/api/clients/cases/cases.d.ts +35 -0
  45. package/types/api/clients/chatMessagesHistory/chatMessagesHistory.d.ts +15 -0
  46. package/types/api/clients/contactCases/contactCases.d.ts +9 -0
  47. package/types/api/clients/index.d.ts +9 -0
  48. package/types/api/clients/labels/labels.d.ts +2 -2
  49. package/types/api/clients/timeline/timeline.d.ts +16 -0
  50. package/types/api/clients/wtTypes/_shared/utils/assignFieldPositions.d.ts +2 -0
  51. package/types/api/clients/wtTypes/_shared/utils/sortDynamicFields.d.ts +2 -2
  52. package/types/api/clients/wtTypes/adjunctTypeRecords/adjunctTypeRecords.d.ts +11 -11
  53. package/types/api/clients/wtTypes/typeExtensions/typeExtensions.d.ts +1 -1
  54. package/types/api/clients//321/201ontacts/getContactAccessFromMode.d.ts +5 -0
  55. package/types/api/clients//321/201ontacts/index.d.ts +1 -1
  56. package/types/validations/adjunctType/adjunctType.validations.d.ts +11 -0
  57. package/types/validations/case/case.validations.d.ts +31 -0
  58. package/types/validations/caseClose/caseClose.validations.d.ts +8 -0
  59. package/types/validations/caseExportOptions/caseExportOptions.validations.d.ts +9 -0
  60. package/types/validations/contact/contact.validations.d.ts +15 -15
  61. package/types/validations/index.d.ts +5 -0
  62. package/types/validations/typeExtension/typeExtension.validations.d.ts +20 -0
  63. package/src/api/clients//321/201ontacts/types/ContactEntity.types.ts +0 -25
  64. package/types/api/clients//321/201ontacts/types/ContactEntity.types.d.ts +0 -14
@@ -19,13 +19,29 @@ import {
19
19
  starToSearch,
20
20
  } from '../../transformers';
21
21
  import type {
22
+ AddItemParams,
22
23
  ApiId,
23
24
  ApiParams,
24
25
  DeleteItemParams,
25
26
  GetItemParams,
26
27
  PatchItemParams,
28
+ UpdateItemParams,
27
29
  } from '../_shared/types';
28
30
 
31
+ const preRequestHandler = (item: ApiParams) => {
32
+ return {
33
+ ...item,
34
+ state: item.state ?? true,
35
+ sla_id: item.sla?.id,
36
+ status_id: item.status?.id,
37
+ close_reason_id: item.closeReason?.id,
38
+ team_ids: item.teams?.map((team: ApiParams) => team.id),
39
+ skill_ids: item.skills?.map((skill: ApiParams) => skill.id),
40
+ assignee:
41
+ item.group?.type === ContactsGroupType.Dynamic ? {} : item.assignee,
42
+ };
43
+ };
44
+
29
45
  const getServicesList = async ({
30
46
  parentId,
31
47
  rootId,
@@ -34,7 +50,7 @@ const getServicesList = async ({
34
50
  parentId?: ApiId;
35
51
  rootId: ApiId;
36
52
  } & ApiParams) => {
37
- const fieldsToSend = getShallowFieldsToSendFromZodSchema(
53
+ const listFieldsToSend = getShallowFieldsToSendFromZodSchema(
38
54
  ListServicesQueryParams,
39
55
  );
40
56
 
@@ -45,7 +61,7 @@ const getServicesList = async ({
45
61
  ...params,
46
62
  q: params.search,
47
63
  }),
48
- sanitizeToWire(fieldsToSend),
64
+ sanitizeToWire(listFieldsToSend),
49
65
  camelToSnake(),
50
66
  ]);
51
67
 
@@ -53,11 +69,11 @@ const getServicesList = async ({
53
69
  const response = await getServices().listServices({
54
70
  page,
55
71
  size,
56
- fields,
57
72
  sort,
58
73
  id,
59
74
  q,
60
75
  root_id: String(rootId ?? parentId),
76
+ fields,
61
77
  });
62
78
  const { items, next } = applyTransform(response.data, [
63
79
  merge(getDefaultGetListResponse()),
@@ -75,26 +91,15 @@ const getServicesList = async ({
75
91
  }
76
92
  };
77
93
 
78
- const getService = async ({ itemId: id }: GetItemParams) => {
79
- const fieldsToSend = [
80
- 'name',
81
- 'code',
82
- 'sla',
83
- 'state',
84
- 'prefix',
85
- 'group',
86
- 'assignee',
87
- 'description',
88
- 'default_priority',
89
- 'catalog_id',
90
- 'root_id',
91
- ];
94
+ const serviceFieldsToSend =
95
+ getShallowFieldsToSendFromZodSchema(CreateServiceBody);
92
96
 
97
+ const getService = async ({ itemId: id }: GetItemParams) => {
93
98
  const itemResponseHandler = (item: ApiParams) => item.service;
94
99
 
95
100
  try {
96
101
  const response = await getServices().locateService(String(id), {
97
- fields: fieldsToSend,
102
+ fields: serviceFieldsToSend,
98
103
  });
99
104
  return applyTransform(response.data, [
100
105
  snakeToCamel(),
@@ -107,42 +112,14 @@ const getService = async ({ itemId: id }: GetItemParams) => {
107
112
  }
108
113
  };
109
114
 
110
- const preRequestHandler = ({
111
- rootId,
112
- catalogId,
113
- }: {
114
- rootId: ApiId;
115
- catalogId: ApiId;
116
- }) => {
117
- return (item: ApiParams) => ({
118
- ...item,
119
- assignee:
120
- item.group?.type === ContactsGroupType.Dynamic ? {} : item.assignee,
121
- rootId: rootId ?? item.rootId,
122
- catalogId: catalogId ?? item.catalogId,
123
- });
124
- };
125
-
126
- const addService = async ({
127
- itemInstance,
128
- rootId,
129
- catalogId,
130
- }: {
131
- itemInstance: ApiParams;
132
- rootId: ApiId;
133
- catalogId: ApiId;
134
- }) => {
135
- const fieldsToSend = getShallowFieldsToSendFromZodSchema(CreateServiceBody);
115
+ const addFieldsToSend = getShallowFieldsToSendFromZodSchema(CreateServiceBody);
136
116
 
117
+ const addService = async ({ itemInstance }: AddItemParams) => {
137
118
  const item = applyTransform(itemInstance, [
138
- preRequestHandler({
139
- rootId,
140
- catalogId,
141
- }),
142
- sanitizeToWire(fieldsToSend),
119
+ sanitizeToWire(addFieldsToSend),
120
+ preRequestHandler,
143
121
  camelToSnake(),
144
122
  ]);
145
-
146
123
  try {
147
124
  const response = await getServices().createService(item);
148
125
  return applyTransform(response.data, [
@@ -155,28 +132,18 @@ const addService = async ({
155
132
  }
156
133
  };
157
134
 
135
+ const updateFieldsToSend =
136
+ getShallowFieldsToSendFromZodSchema(UpdateServiceBody);
137
+
158
138
  const updateService = async ({
159
139
  itemInstance,
160
140
  itemId: id,
161
- rootId,
162
- catalogId,
163
- }: {
164
- itemInstance: ApiParams;
165
- itemId: ApiId;
166
- rootId: ApiId;
167
- catalogId: ApiId;
168
- }) => {
169
- const fieldsToSend = getShallowFieldsToSendFromZodSchema(UpdateServiceBody);
170
-
141
+ }: UpdateItemParams) => {
171
142
  const item = applyTransform(itemInstance, [
172
- preRequestHandler({
173
- rootId,
174
- catalogId,
175
- }),
176
- sanitizeToWire(fieldsToSend),
143
+ sanitizeToWire(updateFieldsToSend),
144
+ preRequestHandler,
177
145
  camelToSnake(),
178
146
  ]);
179
-
180
147
  try {
181
148
  const response = await getServices().updateService(String(id), item);
182
149
  return applyTransform(response.data, [
@@ -189,11 +156,12 @@ const updateService = async ({
189
156
  }
190
157
  };
191
158
 
192
- const patchService = async ({ changes, id }: PatchItemParams) => {
193
- const fieldsToSend = getShallowFieldsToSendFromZodSchema(UpdateService2Body);
159
+ const patchFieldsToSend =
160
+ getShallowFieldsToSendFromZodSchema(UpdateService2Body);
194
161
 
162
+ const patchService = async ({ changes, id }: PatchItemParams) => {
195
163
  const body = applyTransform(changes, [
196
- sanitizeToWire(fieldsToSend),
164
+ sanitizeToWire(patchFieldsToSend),
197
165
  camelToSnake(),
198
166
  ]);
199
167
  try {
@@ -221,9 +189,7 @@ const deleteService = async ({ id }: DeleteItemParams) => {
221
189
  }
222
190
  };
223
191
 
224
- const getServicesLookup = async (
225
- params: Parameters<typeof getServicesList>[0],
226
- ) =>
192
+ const getServicesLookup = (params: Parameters<typeof getServicesList>[0]) =>
227
193
  getServicesList({
228
194
  ...params,
229
195
  fields: params.fields || [
@@ -0,0 +1,67 @@
1
+ import { getShallowFieldsToSendFromZodSchema } from '@webitel/api-services/gen/utils';
2
+ import { getFtsservice, SearchQueryParams } from '../../../../gen-wire';
3
+ import {
4
+ getDefaultGetListResponse,
5
+ getDefaultGetParams,
6
+ } from '../../../defaults';
7
+ import {
8
+ applyTransform,
9
+ merge,
10
+ notify,
11
+ sanitizeToWire,
12
+ snakeToCamel,
13
+ } from '../../../transformers';
14
+ import type { ApiParams } from '../../_shared/types';
15
+
16
+ const getSearchList = async (params: ApiParams) => {
17
+ const fieldsToSend = getShallowFieldsToSendFromZodSchema(SearchQueryParams);
18
+
19
+ const {
20
+ page,
21
+ size,
22
+ q,
23
+ sort,
24
+ fields,
25
+ options,
26
+ object_name: objectName,
27
+ } = applyTransform(params, [
28
+ merge(getDefaultGetParams()),
29
+ (params) => ({
30
+ ...params,
31
+ q: params.fts,
32
+ }),
33
+ sanitizeToWire(fieldsToSend),
34
+ ]);
35
+
36
+ try {
37
+ const response = await getFtsservice().search(
38
+ {
39
+ page,
40
+ size,
41
+ q,
42
+ sort,
43
+ fields,
44
+ object_name: objectName,
45
+ },
46
+ options,
47
+ );
48
+
49
+ const { items, next } = applyTransform(response.data, [
50
+ merge(getDefaultGetListResponse()),
51
+ ]);
52
+ return {
53
+ items: applyTransform(items, [
54
+ snakeToCamel(),
55
+ ]),
56
+ next,
57
+ };
58
+ } catch (err) {
59
+ throw applyTransform(err, [
60
+ notify,
61
+ ]);
62
+ }
63
+ };
64
+
65
+ export const FTSServiceAPI = {
66
+ getList: getSearchList,
67
+ };
@@ -0,0 +1,156 @@
1
+ import { isObject } from 'lodash-es';
2
+ import { RelativeDatetimeValue } from '../../../../enums';
3
+ import {
4
+ isRelativeDatetimeValue,
5
+ normalizeToTimestamp,
6
+ } from '../../../../scripts';
7
+ import type { ApiParams } from '../../_shared/types';
8
+
9
+ // filter values are heterogeneous (string, number, object, array) — not worth
10
+ // modeling per filter key
11
+ type FilterTransformer = (
12
+ // biome-ignore lint/suspicious/noExplicitAny: see comment above
13
+ value: any,
14
+ key: string,
15
+ ) => string | string[] | undefined;
16
+
17
+ const filterTransformersMap: Record<string, FilterTransformer> = {
18
+ createdAt: (createdAt) => {
19
+ const arr = [];
20
+ if (!createdAt) {
21
+ arr.push(
22
+ `created_at.from=${normalizeToTimestamp(RelativeDatetimeValue.Today, {
23
+ round: 'start',
24
+ })}`,
25
+ );
26
+ } else {
27
+ if (typeof createdAt === 'string') {
28
+ arr.push(
29
+ `created_at.from=${normalizeToTimestamp(createdAt, {
30
+ round: 'start',
31
+ })}`,
32
+ `created_at.to=${normalizeToTimestamp(createdAt, {
33
+ round: 'end',
34
+ })}`,
35
+ );
36
+ } else {
37
+ if (createdAt.from) arr.push(`created_at.from=${createdAt.from}`);
38
+ if (createdAt.to) arr.push(`created_at.to=${createdAt.to}`);
39
+ }
40
+ }
41
+ return arr;
42
+ },
43
+ status: (value) => `status_condition=${value.conditions}`,
44
+ source: (value) => `source=${value}`,
45
+ author: (value) => `created_by=${value}`,
46
+ reporter: (value) => `reporter=${value}`,
47
+ impacted: (value) => `impacted=${value}`,
48
+ assignee: (value) =>
49
+ value.unassigned
50
+ ? `assignee=${value.list},${null}`
51
+ : `assignee=${value.list}`,
52
+ contactGroup: (value) =>
53
+ value.unassigned ? `group=${value.list},${null}` : `group=${value.list}`,
54
+ priority: (value) => `priority=${value}`,
55
+ closeReasonGroups: (value) => `close_reason=${value.conditions}`,
56
+ rating: (value) => {
57
+ const arr = [];
58
+ if (value.from) arr.push(`rating.from=${value.from}`);
59
+ if (value.to) arr.push(`rating.to=${value.to}`);
60
+ return arr;
61
+ },
62
+ service: (value) => `service=${value}`,
63
+ sla: (value) => `sla=${value}`,
64
+ slaCondition: (value) => `sla_condition=${value.conditions}`,
65
+ reactionTime: (value) => {
66
+ const arr = [];
67
+ if (value.from) arr.push(`planned_reaction_at.from=${value.from}`);
68
+ if (value.to) arr.push(`planned_reaction_at.to=${value.to}`);
69
+ return arr;
70
+ },
71
+ resolutionTime: (value) => {
72
+ const arr = [];
73
+ if (value.from) arr.push(`planned_resolve_at.from=${value.from}`);
74
+ if (value.to) arr.push(`planned_resolve_at.to=${value.to}`);
75
+ return arr;
76
+ },
77
+ actualReactionTime: (value) => {
78
+ const arr = [];
79
+ if (value.from) arr.push(`reacted_at.from=${value.from}`);
80
+ if (value.to) arr.push(`reacted_at.to=${value.to}`);
81
+ return arr;
82
+ },
83
+ actualResolutionTime: (value) => {
84
+ const arr = [];
85
+ if (value.from) arr.push(`resolved_at.from=${value.from}`);
86
+ if (value.to) arr.push(`resolved_at.to=${value.to}`);
87
+ return arr;
88
+ },
89
+ hasAttachment: (value) => `attachments=${value}`,
90
+ others: (value, key) => {
91
+ const makeArrWithStringValuesFromObjectValue = (
92
+ value: ApiParams,
93
+ key: string,
94
+ ) => {
95
+ return Object.entries(value).map(
96
+ ([propKey, propValue]) => `${key}.${propKey}=${propValue}`,
97
+ );
98
+ };
99
+
100
+ /* then value is magic datetime string */
101
+ if (isRelativeDatetimeValue(value)) {
102
+ const normalizedValue = {
103
+ from: normalizeToTimestamp(value, {
104
+ round: 'start',
105
+ }),
106
+ to: normalizeToTimestamp(value, {
107
+ round: 'end',
108
+ }),
109
+ };
110
+ return makeArrWithStringValuesFromObjectValue(normalizedValue, key);
111
+ }
112
+
113
+ /**
114
+ * @author @dlohvinov
115
+ * if..., then assume its a datetime
116
+ */
117
+ if (value?.from || value?.to) {
118
+ const normalizedValue: {
119
+ from?: number;
120
+ to?: number;
121
+ } = {};
122
+
123
+ if (value.from) {
124
+ normalizedValue.from = normalizeToTimestamp(value.from);
125
+ }
126
+
127
+ if (value.to) {
128
+ normalizedValue.to = normalizeToTimestamp(value.to);
129
+ }
130
+
131
+ return makeArrWithStringValuesFromObjectValue(normalizedValue, key);
132
+ }
133
+
134
+ if (!isObject(value) || Array.isArray(value)) return `${key}=${value}`;
135
+
136
+ return makeArrWithStringValuesFromObjectValue(value, key);
137
+ },
138
+ };
139
+
140
+ export const stringifyCaseFilters = (filters: ApiParams) => {
141
+ const result: string[] = [];
142
+
143
+ for (const [key, value] of Object.entries(filters)) {
144
+ const transformer =
145
+ filterTransformersMap[key] || filterTransformersMap.others;
146
+
147
+ const strValue = transformer(value, key);
148
+
149
+ if (value != null && strValue) {
150
+ if (Array.isArray(strValue)) {
151
+ result.push(...strValue);
152
+ } else result.push(strValue);
153
+ }
154
+ }
155
+ return result;
156
+ };