@webitel/api-services 1.0.5 → 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.
Files changed (232) hide show
  1. package/package.json +2 -1
  2. package/src/api/clients/caseComments/caseComments.ts +141 -0
  3. package/src/api/clients/caseFiles/caseFiles.ts +79 -0
  4. package/src/api/clients/caseLinks/caseLinks.ts +150 -0
  5. package/src/api/clients/caseRelatedCases/caseRelatedCases.ts +125 -0
  6. package/src/api/clients/caseServices/services.ts +38 -72
  7. package/src/api/clients/cases/_internals/ftsService.ts +67 -0
  8. package/src/api/clients/cases/_internals/stringifyCaseFilters.ts +156 -0
  9. package/src/api/clients/cases/cases.ts +360 -0
  10. package/src/api/clients/chatMessagesHistory/chatMessagesHistory.ts +64 -0
  11. package/src/api/clients/configurations/configurations.ts +56 -39
  12. package/src/api/clients/contactCases/contactCases.ts +109 -0
  13. package/src/api/clients/emails/emails.ts +11 -7
  14. package/src/api/clients/index.ts +9 -0
  15. package/src/api/clients/labels/labels.ts +24 -29
  16. package/src/api/clients/phones/phones.ts +11 -7
  17. package/src/api/clients/timeline/timeline.ts +124 -0
  18. package/src/api/clients/variables/variables.ts +10 -5
  19. package/src/api/clients/wtTypes/_shared/utils/assignFieldPositions.ts +28 -0
  20. package/src/api/clients/wtTypes/_shared/utils/sortDynamicFields.ts +7 -9
  21. package/src/api/clients/wtTypes/adjunctTypeRecords/adjunctTypeRecords.ts +19 -16
  22. package/src/api/clients/wtTypes/adjunctTypes/adjunctTypes.ts +4 -0
  23. package/src/api/clients/wtTypes/typeExtensions/typeExtensions.ts +21 -31
  24. package/src/api/clients//321/201ontacts/contacts.ts +103 -234
  25. package/src/api/clients//321/201ontacts/getContactAccessFromMode.ts +9 -0
  26. package/src/api/clients//321/201ontacts/index.ts +1 -1
  27. package/src/gen/_models/contactsCallFile.ts +3 -0
  28. package/src/gen/_models/contactsCallFileType.ts +18 -0
  29. package/src/gen/_models/index.ts +9 -0
  30. package/src/gen/_models/webitelCasesCallFile.ts +3 -0
  31. package/src/gen/_models/webitelCasesCallFileType.ts +18 -0
  32. package/src/gen-wire/_models/contactsCallFile.ts +3 -0
  33. package/src/gen-wire/_models/contactsCallFileType.ts +18 -0
  34. package/src/gen-wire/_models/index.ts +2 -0
  35. package/src/gen-wire/_models/webitelCasesCallFile.ts +3 -0
  36. package/src/gen-wire/_models/webitelCasesCallFileType.ts +18 -0
  37. package/src/gen-wire/access-store/access-store.ts +1 -1
  38. package/src/gen-wire/agent-absence-service/agent-absence-service.ts +1 -1
  39. package/src/gen-wire/agent-chat-service/agent-chat-service.ts +1 -1
  40. package/src/gen-wire/agent-pause-cause-service/agent-pause-cause-service.ts +1 -1
  41. package/src/gen-wire/agent-service/agent-service.ts +1 -1
  42. package/src/gen-wire/agent-skill-service/agent-skill-service.ts +1 -1
  43. package/src/gen-wire/agent-team-service/agent-team-service.ts +1 -1
  44. package/src/gen-wire/agent-working-conditions-service/agent-working-conditions-service.ts +1 -1
  45. package/src/gen-wire/agent-working-schedule-service/agent-working-schedule-service.ts +1 -1
  46. package/src/gen-wire/articles/articles.ts +1 -1
  47. package/src/gen-wire/attachments/attachments.ts +1 -1
  48. package/src/gen-wire/audit-form-service/audit-form-service.ts +1 -1
  49. package/src/gen-wire/auth/auth.ts +1 -1
  50. package/src/gen-wire/backend-profile-service/backend-profile-service.ts +1 -1
  51. package/src/gen-wire/bucket-service/bucket-service.ts +1 -1
  52. package/src/gen-wire/calendar-service/calendar-service.ts +1 -1
  53. package/src/gen-wire/call-service/call-service.ts +1 -1
  54. package/src/gen-wire/case-comments/case-comments.ts +1 -1
  55. package/src/gen-wire/case-communications/case-communications.ts +1 -1
  56. package/src/gen-wire/case-files/case-files.ts +1 -1
  57. package/src/gen-wire/case-links/case-links.ts +1 -1
  58. package/src/gen-wire/case-timeline/case-timeline.ts +1 -1
  59. package/src/gen-wire/case-timeline/case-timeline.zod.ts +14 -0
  60. package/src/gen-wire/cases/cases.ts +1 -1
  61. package/src/gen-wire/cases-chat-catalog/cases-chat-catalog.ts +1 -1
  62. package/src/gen-wire/catalogs/catalogs.ts +1 -1
  63. package/src/gen-wire/classes/classes.ts +1 -1
  64. package/src/gen-wire/close-reason-groups/close-reason-groups.ts +1 -1
  65. package/src/gen-wire/close-reasons/close-reasons.ts +1 -1
  66. package/src/gen-wire/cognitive-profile-service/cognitive-profile-service.ts +1 -1
  67. package/src/gen-wire/comments/comments.ts +1 -1
  68. package/src/gen-wire/communication-type-service/communication-type-service.ts +1 -1
  69. package/src/gen-wire/config-service/config-service.ts +1 -1
  70. package/src/gen-wire/contact-groups/contact-groups.ts +1 -1
  71. package/src/gen-wire/contact-linking-service/contact-linking-service.ts +1 -1
  72. package/src/gen-wire/contacts/contacts.ts +1 -1
  73. package/src/gen-wire/contacts-chat-catalog/contacts-chat-catalog.ts +1 -1
  74. package/src/gen-wire/customer/customer.ts +1 -1
  75. package/src/gen-wire/customers/customers.ts +1 -1
  76. package/src/gen-wire/devices/devices.ts +1 -1
  77. package/src/gen-wire/dictionaries/dictionaries.ts +1 -1
  78. package/src/gen-wire/domains/domains.ts +1 -1
  79. package/src/gen-wire/dynamic-conditions/dynamic-conditions.ts +1 -1
  80. package/src/gen-wire/dynamic-groups/dynamic-groups.ts +1 -1
  81. package/src/gen-wire/email-profile-service/email-profile-service.ts +1 -1
  82. package/src/gen-wire/emails/emails.ts +1 -1
  83. package/src/gen-wire/embedding-models/embedding-models.ts +1 -1
  84. package/src/gen-wire/extensions/extensions.ts +1 -1
  85. package/src/gen-wire/feedback-service/feedback-service.ts +1 -1
  86. package/src/gen-wire/file-policies-service/file-policies-service.ts +1 -1
  87. package/src/gen-wire/file-service/file-service.ts +1 -1
  88. package/src/gen-wire/file-transcript-service/file-transcript-service.ts +1 -1
  89. package/src/gen-wire/forecast-calculation-service/forecast-calculation-service.ts +1 -1
  90. package/src/gen-wire/ftsservice/ftsservice.ts +1 -1
  91. package/src/gen-wire/groups/groups.ts +1 -1
  92. package/src/gen-wire/im-service-provider-v1-telegrambotservice/im-service-provider-v1-telegrambotservice.ts +1 -1
  93. package/src/gen-wire/imclients/imclients.ts +1 -1
  94. package/src/gen-wire/import-template-service/import-template-service.ts +1 -1
  95. package/src/gen-wire/index.ts +2 -0
  96. package/src/gen-wire/knowledgebase-search/knowledgebase-search.ts +1 -1
  97. package/src/gen-wire/labels/labels.ts +1 -1
  98. package/src/gen-wire/languages/languages.ts +1 -1
  99. package/src/gen-wire/ldap/ldap.ts +1 -1
  100. package/src/gen-wire/list-service/list-service.ts +1 -1
  101. package/src/gen-wire/logger-service/logger-service.ts +1 -1
  102. package/src/gen-wire/managers/managers.ts +1 -1
  103. package/src/gen-wire/media-file-service/media-file-service.ts +1 -1
  104. package/src/gen-wire/meeting-service/meeting-service.ts +1 -1
  105. package/src/gen-wire/member-service/member-service.ts +1 -1
  106. package/src/gen-wire/messages/messages.ts +1 -1
  107. package/src/gen-wire/oauth2-federation/oauth2-federation.ts +1 -1
  108. package/src/gen-wire/online-skills/online-skills.ts +1 -1
  109. package/src/gen-wire/outbound-resource-group-service/outbound-resource-group-service.ts +1 -1
  110. package/src/gen-wire/outbound-resource-service/outbound-resource-service.ts +1 -1
  111. package/src/gen-wire/pause-template-service/pause-template-service.ts +1 -1
  112. package/src/gen-wire/pdf-service/pdf-service.ts +1 -1
  113. package/src/gen-wire/permissions/permissions.ts +1 -1
  114. package/src/gen-wire/phones/phones.ts +1 -1
  115. package/src/gen-wire/photos/photos.ts +1 -1
  116. package/src/gen-wire/presence/presence.ts +1 -1
  117. package/src/gen-wire/preset-query-service/preset-query-service.ts +1 -1
  118. package/src/gen-wire/priorities/priorities.ts +1 -1
  119. package/src/gen-wire/queue-bucket-service/queue-bucket-service.ts +1 -1
  120. package/src/gen-wire/queue-hook-service/queue-hook-service.ts +1 -1
  121. package/src/gen-wire/queue-resources-service/queue-resources-service.ts +1 -1
  122. package/src/gen-wire/queue-service/queue-service.ts +1 -1
  123. package/src/gen-wire/queue-skill-service/queue-skill-service.ts +1 -1
  124. package/src/gen-wire/quick-replies-service/quick-replies-service.ts +1 -1
  125. package/src/gen-wire/records/records.ts +1 -1
  126. package/src/gen-wire/region-service/region-service.ts +1 -1
  127. package/src/gen-wire/related-cases/related-cases.ts +1 -1
  128. package/src/gen-wire/retrieval/retrieval.ts +1 -1
  129. package/src/gen-wire/routing-chat-plan-service/routing-chat-plan-service.ts +1 -1
  130. package/src/gen-wire/routing-outbound-call-service/routing-outbound-call-service.ts +1 -1
  131. package/src/gen-wire/routing-schema-service/routing-schema-service.ts +1 -1
  132. package/src/gen-wire/routing-variable-service/routing-variable-service.ts +1 -1
  133. package/src/gen-wire/schema-variables-service/schema-variables-service.ts +1 -1
  134. package/src/gen-wire/schema-version-service/schema-version-service.ts +1 -1
  135. package/src/gen-wire/services/services.ts +1 -1
  136. package/src/gen-wire/shift-template-service/shift-template-service.ts +1 -1
  137. package/src/gen-wire/skill-service/skill-service.ts +1 -1
  138. package/src/gen-wire/slaconditions/slaconditions.ts +1 -1
  139. package/src/gen-wire/slas/slas.ts +1 -1
  140. package/src/gen-wire/sources/sources.ts +1 -1
  141. package/src/gen-wire/spaces/spaces.ts +1 -1
  142. package/src/gen-wire/status-conditions/status-conditions.ts +1 -1
  143. package/src/gen-wire/statuses/statuses.ts +1 -1
  144. package/src/gen-wire/system-setting-service/system-setting-service.ts +1 -1
  145. package/src/gen-wire/tags/tags.ts +1 -1
  146. package/src/gen-wire/team-hook-service/team-hook-service.ts +1 -1
  147. package/src/gen-wire/team-trigger-service/team-trigger-service.ts +1 -1
  148. package/src/gen-wire/timeline/timeline.ts +1 -1
  149. package/src/gen-wire/timeline/timeline.zod.ts +14 -0
  150. package/src/gen-wire/timezones/timezones.ts +1 -1
  151. package/src/gen-wire/trigger-service/trigger-service.ts +1 -1
  152. package/src/gen-wire/two-factor-authentication/two-factor-authentication.ts +1 -1
  153. package/src/gen-wire/types/types.ts +1 -1
  154. package/src/gen-wire/user-access-tokens/user-access-tokens.ts +1 -1
  155. package/src/gen-wire/user-helper-service/user-helper-service.ts +1 -1
  156. package/src/gen-wire/users/users.ts +1 -1
  157. package/src/gen-wire/variables/variables.ts +1 -1
  158. package/src/gen-wire/versions/versions.ts +1 -1
  159. package/src/gen-wire/web-hook-service/web-hook-service.ts +1 -1
  160. package/src/gen-wire/webitel-im-api-gateway-v1-account/webitel-im-api-gateway-v1-account.ts +1 -1
  161. package/src/gen-wire/webitel-im-api-gateway-v1-bots/webitel-im-api-gateway-v1-bots.ts +1 -1
  162. package/src/gen-wire/webitel-im-api-gateway-v1-contacts/webitel-im-api-gateway-v1-contacts.ts +1 -1
  163. package/src/gen-wire/webitel-im-api-gateway-v1-contactsettingsmanagement/webitel-im-api-gateway-v1-contactsettingsmanagement.ts +1 -1
  164. package/src/gen-wire/webitel-im-api-gateway-v1-message/webitel-im-api-gateway-v1-message.ts +1 -1
  165. package/src/gen-wire/webitel-im-api-gateway-v1-messagehistory/webitel-im-api-gateway-v1-messagehistory.ts +1 -1
  166. package/src/gen-wire/webitel-im-api-gateway-v1-threadmanagement/webitel-im-api-gateway-v1-threadmanagement.ts +1 -1
  167. package/src/gen-wire/webitel-im-api-gateway-v1-threadpermission/webitel-im-api-gateway-v1-threadpermission.ts +1 -1
  168. package/src/gen-wire/webitel-im-api-provider-v1-facebookservice/webitel-im-api-provider-v1-facebookservice.ts +1 -1
  169. package/src/gen-wire/webitel-im-api-provider-v1-instagramservice/webitel-im-api-provider-v1-instagramservice.ts +1 -1
  170. package/src/gen-wire/webitel-im-api-provider-v1-metaappservice/webitel-im-api-provider-v1-metaappservice.ts +1 -1
  171. package/src/gen-wire/webitel-im-api-provider-v1-metaoauthservice/webitel-im-api-provider-v1-metaoauthservice.ts +1 -1
  172. package/src/gen-wire/webitel-im-api-provider-v1-whatsappservice/webitel-im-api-provider-v1-whatsappservice.ts +1 -1
  173. package/src/gen-wire/webitel-im-provider-v1-facebookservice/webitel-im-provider-v1-facebookservice.ts +1 -1
  174. package/src/gen-wire/webitel-im-provider-v1-gateservice/webitel-im-provider-v1-gateservice.ts +1 -1
  175. package/src/gen-wire/webitel-im-provider-v1-gatetemplateservice/webitel-im-provider-v1-gatetemplateservice.ts +1 -1
  176. package/src/gen-wire/webitel-im-provider-v1-instagramservice/webitel-im-provider-v1-instagramservice.ts +1 -1
  177. package/src/gen-wire/webitel-im-provider-v1-metaappservice/webitel-im-provider-v1-metaappservice.ts +1 -1
  178. package/src/gen-wire/webitel-im-provider-v1-metaoauthservice/webitel-im-provider-v1-metaoauthservice.ts +1 -1
  179. package/src/gen-wire/webitel-im-provider-v1-providermessageservice/webitel-im-provider-v1-providermessageservice.ts +1 -1
  180. package/src/gen-wire/webitel-im-provider-v1-viberservice/webitel-im-provider-v1-viberservice.ts +1 -1
  181. package/src/gen-wire/webitel-im-provider-v1-whatsappservice/webitel-im-provider-v1-whatsappservice.ts +1 -1
  182. package/src/gen-wire/working-condition-service/working-condition-service.ts +1 -1
  183. package/src/gen-wire/working-schedule-service/working-schedule-service.ts +1 -1
  184. package/src/validations/adjunctType/adjunctType.validations.ts +18 -0
  185. package/src/validations/case/case.validations.ts +33 -0
  186. package/src/validations/caseClose/caseClose.validations.ts +30 -0
  187. package/src/validations/caseExportOptions/caseExportOptions.validations.ts +27 -0
  188. package/src/validations/contact/contact.validations.ts +12 -7
  189. package/src/validations/index.ts +5 -0
  190. package/src/validations/typeExtension/typeExtension.validations.ts +8 -0
  191. package/types/.tsbuildinfo +1 -1
  192. package/types/api/clients/caseComments/caseComments.d.ts +20 -0
  193. package/types/api/clients/caseFiles/caseFiles.d.ts +10 -0
  194. package/types/api/clients/caseLinks/caseLinks.d.ts +22 -0
  195. package/types/api/clients/caseRelatedCases/caseRelatedCases.d.ts +14 -0
  196. package/types/api/clients/caseServices/services.d.ts +3 -12
  197. package/types/api/clients/cases/_internals/ftsService.d.ts +7 -0
  198. package/types/api/clients/cases/_internals/stringifyCaseFilters.d.ts +2 -0
  199. package/types/api/clients/cases/cases.d.ts +35 -0
  200. package/types/api/clients/chatMessagesHistory/chatMessagesHistory.d.ts +15 -0
  201. package/types/api/clients/contactCases/contactCases.d.ts +9 -0
  202. package/types/api/clients/index.d.ts +9 -0
  203. package/types/api/clients/labels/labels.d.ts +2 -2
  204. package/types/api/clients/timeline/timeline.d.ts +16 -0
  205. package/types/api/clients/wtTypes/_shared/utils/assignFieldPositions.d.ts +2 -0
  206. package/types/api/clients/wtTypes/_shared/utils/sortDynamicFields.d.ts +2 -2
  207. package/types/api/clients/wtTypes/adjunctTypeRecords/adjunctTypeRecords.d.ts +11 -11
  208. package/types/api/clients/wtTypes/typeExtensions/typeExtensions.d.ts +1 -1
  209. package/types/api/clients//321/201ontacts/getContactAccessFromMode.d.ts +5 -0
  210. package/types/api/clients//321/201ontacts/index.d.ts +1 -1
  211. package/types/gen/_models/contactsCallFile.d.ts +3 -0
  212. package/types/gen/_models/contactsCallFileType.d.ts +15 -0
  213. package/types/gen/_models/index.d.ts +8 -0
  214. package/types/gen/_models/webitelCasesCallFile.d.ts +3 -0
  215. package/types/gen/_models/webitelCasesCallFileType.d.ts +15 -0
  216. package/types/gen-wire/_models/contactsCallFile.d.ts +3 -0
  217. package/types/gen-wire/_models/contactsCallFileType.d.ts +15 -0
  218. package/types/gen-wire/_models/index.d.ts +2 -0
  219. package/types/gen-wire/_models/webitelCasesCallFile.d.ts +3 -0
  220. package/types/gen-wire/_models/webitelCasesCallFileType.d.ts +15 -0
  221. package/types/gen-wire/case-timeline/case-timeline.zod.d.ts +10 -0
  222. package/types/gen-wire/index.d.ts +2 -2
  223. package/types/gen-wire/timeline/timeline.zod.d.ts +10 -0
  224. package/types/validations/adjunctType/adjunctType.validations.d.ts +11 -0
  225. package/types/validations/case/case.validations.d.ts +31 -0
  226. package/types/validations/caseClose/caseClose.validations.d.ts +8 -0
  227. package/types/validations/caseExportOptions/caseExportOptions.validations.d.ts +9 -0
  228. package/types/validations/contact/contact.validations.d.ts +15 -15
  229. package/types/validations/index.d.ts +5 -0
  230. package/types/validations/typeExtension/typeExtension.validations.d.ts +20 -0
  231. package/src/api/clients//321/201ontacts/types/ContactEntity.types.ts +0 -25
  232. package/types/api/clients//321/201ontacts/types/ContactEntity.types.d.ts +0 -14
@@ -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
+ };
@@ -0,0 +1,360 @@
1
+ import { getShallowFieldsToSendFromZodSchema } from '@webitel/api-services/gen/utils';
2
+ import { snakeToKebab } from '@webitel/api-services/utils';
3
+ import {
4
+ CreateCaseBody,
5
+ getCases,
6
+ UpdateCase2Body,
7
+ UpdateCaseBody,
8
+ } from '../../../gen-wire';
9
+ import { getDefaultGetListResponse, getDefaultGetParams } from '../../defaults';
10
+ import {
11
+ applyTransform,
12
+ camelToSnake,
13
+ merge,
14
+ notify,
15
+ sanitizeToWire,
16
+ snakeToCamel,
17
+ } from '../../transformers';
18
+ import { generatePermissionsApi } from '../_shared/generatePermissionsApi';
19
+ import type {
20
+ AddItemParams,
21
+ ApiId,
22
+ ApiParams,
23
+ DeleteItemParams,
24
+ GetItemParams,
25
+ } from '../_shared/types';
26
+ import { FTSServiceAPI } from './_internals/ftsService';
27
+ import { stringifyCaseFilters } from './_internals/stringifyCaseFilters';
28
+
29
+ const casesService = getCases();
30
+
31
+ const baseUrl = '/cases';
32
+
33
+ function transformSourceType(data: ApiParams | ApiParams[]) {
34
+ if (Array.isArray(data)) {
35
+ return data.map((item) => {
36
+ if (item.source?.type) {
37
+ item.source.type = snakeToKebab(item.source.type.toLowerCase());
38
+ }
39
+ return item;
40
+ });
41
+ }
42
+
43
+ if (data.source?.type) {
44
+ data.source.type = snakeToKebab(data.source.type.toLowerCase());
45
+ }
46
+ return data;
47
+ }
48
+
49
+ const transformCustomFields = (data: ApiParams) => {
50
+ if (!data.custom) {
51
+ data.custom = {};
52
+ }
53
+
54
+ return data;
55
+ };
56
+
57
+ const checkCustomFields = (data: ApiParams) => {
58
+ if (!Object.keys(data.custom).length) {
59
+ delete data.custom;
60
+ }
61
+
62
+ return data;
63
+ };
64
+
65
+ const getCasesList = async (params: ApiParams) => {
66
+ let ftsIds: string[] | undefined;
67
+ const { fts } = params;
68
+ if (fts) {
69
+ try {
70
+ const { items } = await FTSServiceAPI.getList({
71
+ page: params.page,
72
+ size: params.size,
73
+ fts: params.fts,
74
+ sort: params.sort,
75
+ objectName: [
76
+ 'cases',
77
+ 'case_comments',
78
+ ],
79
+ });
80
+ ftsIds = items.map(({ id }: ApiParams) => id);
81
+ } catch {
82
+ // skip error, load cases without fts
83
+ }
84
+ }
85
+
86
+ const { page, size, q, ids, sort, fields, options, ...filters } =
87
+ applyTransform(
88
+ {
89
+ ...params,
90
+ ids: params.ids || ftsIds,
91
+ },
92
+ [
93
+ merge(getDefaultGetParams()),
94
+ (params) => ({
95
+ ...params,
96
+ q: params.search,
97
+ }),
98
+ ],
99
+ );
100
+
101
+ try {
102
+ const response = await casesService.searchCases(
103
+ {
104
+ page,
105
+ size,
106
+ q,
107
+ ids,
108
+ sort,
109
+ fields: [
110
+ 'custom',
111
+ 'priority',
112
+ 'description',
113
+ 'comments',
114
+ ...fields,
115
+ ],
116
+ filters: stringifyCaseFilters(filters),
117
+ },
118
+ options,
119
+ );
120
+
121
+ const { items, next } = applyTransform(response.data, [
122
+ merge(getDefaultGetListResponse()),
123
+ ]);
124
+ return {
125
+ items: applyTransform(items, [
126
+ snakeToCamel(),
127
+ transformSourceType,
128
+ ]),
129
+ next,
130
+ };
131
+ } catch (err) {
132
+ throw applyTransform(err, [
133
+ notify,
134
+ ]);
135
+ }
136
+ };
137
+
138
+ const caseFieldsToSend = [
139
+ 'etag',
140
+ 'id',
141
+ 'name',
142
+ 'subject',
143
+ 'description',
144
+ 'contact_info',
145
+ 'created_at',
146
+ 'planned_reaction_at',
147
+ 'planned_resolve_at',
148
+ 'status_lookup',
149
+ 'close_reason_lookup',
150
+ 'author',
151
+ 'assignee',
152
+ 'reporter',
153
+ 'impacted',
154
+ 'group',
155
+ 'priority',
156
+ 'source',
157
+ 'status',
158
+ 'close_reason',
159
+ 'close_result',
160
+ 'rating',
161
+ 'rating_comment',
162
+ 'reacted_at',
163
+ 'resolved_at',
164
+ 'sla_condition',
165
+ 'difference_in_reaction',
166
+ 'difference_in_resolve',
167
+ 'sla',
168
+ 'service',
169
+ 'comments',
170
+ 'related_cases',
171
+ 'links',
172
+ 'status_condition',
173
+ 'created_by',
174
+ 'custom',
175
+ ];
176
+
177
+ const getCase = async ({ itemId: id }: GetItemParams) => {
178
+ try {
179
+ const response = await casesService.locateCase(String(id), {
180
+ fields: caseFieldsToSend,
181
+ });
182
+ return applyTransform(response.data, [
183
+ snakeToCamel([
184
+ 'custom',
185
+ ]),
186
+ transformCustomFields,
187
+ transformSourceType,
188
+ ]);
189
+ } catch (err) {
190
+ throw applyTransform(err, [
191
+ notify,
192
+ ]);
193
+ }
194
+ };
195
+
196
+ const deleteCase = async ({ id }: DeleteItemParams) => {
197
+ try {
198
+ const response = await casesService.deleteCase(String(id));
199
+ return applyTransform(response.data, []);
200
+ } catch (err) {
201
+ throw applyTransform(err, [
202
+ notify,
203
+ ]);
204
+ }
205
+ };
206
+
207
+ const updateFieldsToSend = getShallowFieldsToSendFromZodSchema(UpdateCaseBody);
208
+
209
+ const updateCase = async ({ itemInstance }: AddItemParams) => {
210
+ const { etag } = itemInstance;
211
+
212
+ const item = applyTransform(itemInstance, [
213
+ sanitizeToWire(updateFieldsToSend),
214
+ camelToSnake([
215
+ 'custom',
216
+ ]),
217
+ checkCustomFields,
218
+ ]);
219
+
220
+ try {
221
+ const response = await casesService.updateCase(etag, item, {
222
+ fields: caseFieldsToSend,
223
+ });
224
+ return applyTransform(response.data.case, [
225
+ snakeToCamel([
226
+ 'custom',
227
+ ]),
228
+ transformCustomFields,
229
+ transformSourceType,
230
+ ]);
231
+ } catch (err) {
232
+ throw applyTransform(err, [
233
+ notify,
234
+ ]);
235
+ }
236
+ };
237
+
238
+ const addFieldsToSend = getShallowFieldsToSendFromZodSchema(CreateCaseBody);
239
+
240
+ const addCase = async ({ itemInstance }: AddItemParams) => {
241
+ const item = applyTransform(itemInstance, [
242
+ sanitizeToWire(addFieldsToSend),
243
+ camelToSnake([
244
+ 'custom',
245
+ ]),
246
+ ]);
247
+ try {
248
+ const response = await casesService.createCase(item);
249
+ return applyTransform(response.data, [
250
+ snakeToCamel(),
251
+ ]);
252
+ } catch (err) {
253
+ throw applyTransform(err, [
254
+ notify,
255
+ ]);
256
+ }
257
+ };
258
+
259
+ const patchCase = async ({
260
+ changes,
261
+ etag,
262
+ }: {
263
+ changes: ApiParams;
264
+ etag: ApiId;
265
+ }) => {
266
+ const body = applyTransform(changes, [
267
+ sanitizeToWire(getShallowFieldsToSendFromZodSchema(UpdateCase2Body)),
268
+ camelToSnake(),
269
+ ]);
270
+ try {
271
+ const response = await casesService.updateCase2(String(etag), body, {
272
+ fields: caseFieldsToSend,
273
+ });
274
+ return applyTransform(response.data.case, [
275
+ snakeToCamel([
276
+ 'custom',
277
+ ]),
278
+ transformCustomFields,
279
+ transformSourceType,
280
+ ]);
281
+ } catch (err) {
282
+ throw applyTransform(err, [
283
+ notify,
284
+ ]);
285
+ }
286
+ };
287
+
288
+ const exportCase = async (params: ApiParams) => {
289
+ const { q, sort, fields, options, format, separator, ids, ...filters } =
290
+ applyTransform(
291
+ {
292
+ ...params,
293
+ },
294
+ [
295
+ merge(getDefaultGetParams()),
296
+ (params) => ({
297
+ ...params,
298
+ q: params.search,
299
+ }),
300
+ ],
301
+ );
302
+
303
+ delete filters.page;
304
+ delete filters.size;
305
+
306
+ const exportParams: Record<string, unknown> = {
307
+ q,
308
+ sort,
309
+ fields,
310
+ format,
311
+ separator,
312
+ filters: stringifyCaseFilters(filters),
313
+ };
314
+
315
+ if (ids?.length) {
316
+ exportParams.ids = ids;
317
+ }
318
+
319
+ try {
320
+ const response = await casesService.exportCases(exportParams, {
321
+ ...options,
322
+ responseType: 'blob',
323
+ });
324
+
325
+ return {
326
+ response,
327
+ };
328
+ } catch (err) {
329
+ throw applyTransform(err, [
330
+ notify,
331
+ ]);
332
+ }
333
+ };
334
+
335
+ const getCasesLookup = (params: Parameters<typeof getCasesList>[0]) =>
336
+ getCasesList({
337
+ ...params,
338
+ fields: params.fields || [
339
+ 'id',
340
+ 'name',
341
+ 'subject',
342
+ 'priority',
343
+ ],
344
+ });
345
+
346
+ export const CasesAPI = {
347
+ getList: getCasesList,
348
+ getLookup: getCasesLookup,
349
+ get: getCase,
350
+ delete: deleteCase,
351
+ update: updateCase,
352
+ add: addCase,
353
+ patch: patchCase,
354
+ exportData: exportCase,
355
+
356
+ ...generatePermissionsApi(baseUrl),
357
+ };
358
+
359
+ export { FTSServiceAPI } from './_internals/ftsService';
360
+ export { stringifyCaseFilters } from './_internals/stringifyCaseFilters';
@@ -0,0 +1,64 @@
1
+ import { getCasesChatCatalog, getContactsChatCatalog } from '../../../gen-wire';
2
+ import { applyTransform, notify, snakeToCamel } from '../../transformers';
3
+ import type { ApiId, ApiParams } from '../_shared/types';
4
+
5
+ const mergeChatMessagesData = ({
6
+ messages,
7
+ peers,
8
+ }: {
9
+ messages: ApiParams[];
10
+ peers: ApiParams[];
11
+ }) => {
12
+ if (!messages) return [];
13
+ return messages.map(({ from, ...message }) => {
14
+ return {
15
+ ...message,
16
+ peer: from && peers ? peers[from.id - 1] : undefined,
17
+ };
18
+ });
19
+ };
20
+
21
+ const buildGetChatHistory =
22
+ (
23
+ getChatHistory: (
24
+ parentId: string,
25
+ taskId: string,
26
+ ) => Promise<{
27
+ data: ApiParams;
28
+ }>,
29
+ ) =>
30
+ async ({ parentId, taskId }: { parentId: ApiId; taskId: ApiId }) => {
31
+ try {
32
+ const response = await getChatHistory(String(parentId), String(taskId));
33
+ const { messages, peers } = applyTransform(response.data, [
34
+ snakeToCamel(),
35
+ ]);
36
+ return {
37
+ items: applyTransform(
38
+ {
39
+ messages,
40
+ peers,
41
+ },
42
+ [
43
+ mergeChatMessagesData,
44
+ ],
45
+ ),
46
+ };
47
+ } catch (err) {
48
+ throw applyTransform(err, [
49
+ notify,
50
+ ]);
51
+ }
52
+ };
53
+
54
+ export const ChatMessagesHistoryAPI = {
55
+ getContactChatHistory: buildGetChatHistory((contactId, chatId) =>
56
+ getContactsChatCatalog().contactsChatCatalogGetContactChatHistory(
57
+ contactId,
58
+ chatId,
59
+ ),
60
+ ),
61
+ getCaseChatHistory: buildGetChatHistory((caseId, chatId) =>
62
+ getCasesChatCatalog().casesChatCatalogGetCaseChatHistory(caseId, chatId),
63
+ ),
64
+ };