@zohoim/client-sdk 1.0.0-poc5 → 1.0.0-poc51

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 (228) hide show
  1. package/es/application/services/agents/AgentService.js +21 -0
  2. package/es/application/services/agents/index.js +2 -0
  3. package/es/application/services/bots/BotService.js +21 -0
  4. package/es/application/services/bots/index.js +2 -0
  5. package/es/application/services/channels/ChannelAgentService.js +21 -0
  6. package/es/application/services/channels/ChannelService.js +21 -0
  7. package/es/application/services/channels/index.js +3 -0
  8. package/es/application/services/contacts/ContactService.js +21 -0
  9. package/es/application/services/contacts/index.js +2 -0
  10. package/es/application/services/index.js +6 -0
  11. package/es/application/services/messages/MessageService.js +56 -0
  12. package/es/application/services/messages/index.js +2 -0
  13. package/es/application/services/sessions/SessionService.js +51 -0
  14. package/es/application/services/sessions/index.js +2 -0
  15. package/es/core/constants/ModuleNames.js +9 -0
  16. package/es/core/constants/index.js +5 -0
  17. package/es/core/errors/AdapterError.js +7 -0
  18. package/es/core/errors/index.js +3 -0
  19. package/es/core/utils/ResponseUtils.js +24 -0
  20. package/es/core/utils/index.js +3 -0
  21. package/es/core/utils/validateSchema.js +76 -0
  22. package/es/domain/dto/RequestBuilder.js +44 -0
  23. package/es/domain/dto/agents/getAgentsRequest.js +12 -0
  24. package/es/domain/dto/agents/index.js +1 -0
  25. package/es/domain/dto/bots/getBotsRequest.js +15 -0
  26. package/es/domain/dto/bots/index.js +1 -0
  27. package/es/domain/dto/channels/agents/getChannelAgentsRequest.js +13 -0
  28. package/es/domain/dto/channels/agents/index.js +1 -0
  29. package/es/domain/dto/channels/getChannelsRequest.js +23 -0
  30. package/es/domain/dto/channels/index.js +3 -0
  31. package/es/domain/dto/contacts/getContactsRequest.js +10 -0
  32. package/es/domain/dto/contacts/index.js +1 -0
  33. package/es/domain/dto/index.js +6 -0
  34. package/es/domain/dto/messages/deleteMessageRequest.js +14 -0
  35. package/es/domain/dto/messages/getFullContentRequest.js +14 -0
  36. package/es/domain/dto/messages/getMessagesRequest.js +20 -0
  37. package/es/domain/dto/messages/index.js +8 -0
  38. package/es/domain/dto/messages/initiateSessionRequest.js +21 -0
  39. package/es/domain/dto/messages/resendMessageRequest.js +14 -0
  40. package/es/domain/dto/messages/searchMessagesRequest.js +22 -0
  41. package/es/domain/dto/messages/sendAttachmentRequest.js +20 -0
  42. package/es/domain/dto/messages/sendMessageRequest.js +17 -0
  43. package/es/domain/dto/sessions/getSessionAttachmentsRequest.js +13 -0
  44. package/es/domain/dto/sessions/getSessionLastMessagesRequest.js +13 -0
  45. package/es/domain/dto/sessions/getSessionRequest.js +13 -0
  46. package/es/domain/dto/sessions/getSessionsRequest.js +26 -0
  47. package/es/domain/dto/sessions/index.js +7 -0
  48. package/es/domain/dto/sessions/markSessionAsReadRequest.js +13 -0
  49. package/es/domain/dto/sessions/updateSessionAssigneeRequest.js +12 -0
  50. package/es/domain/dto/sessions/updateSessionStatusRequest.js +17 -0
  51. package/es/domain/entities/Actor/Actor.js +28 -0
  52. package/es/domain/entities/Actor/index.js +2 -2
  53. package/es/domain/entities/Agent/Agent.js +16 -102
  54. package/es/domain/entities/Agent/index.js +1 -1
  55. package/es/domain/entities/Attachment/Attachment.js +22 -0
  56. package/es/domain/entities/Attachment/index.js +2 -0
  57. package/es/domain/entities/Bot/Bot.js +23 -0
  58. package/es/domain/entities/Bot/index.js +2 -0
  59. package/es/domain/entities/Channel/Channel.js +38 -0
  60. package/es/domain/entities/Channel/index.js +2 -0
  61. package/es/domain/entities/Contact/Contact.js +22 -0
  62. package/es/domain/entities/Contact/index.js +2 -0
  63. package/es/domain/entities/Message/Action.js +19 -0
  64. package/es/domain/entities/Message/ExternalInfo.js +17 -0
  65. package/es/domain/entities/Message/Info.js +21 -0
  66. package/es/domain/entities/Message/Location.js +18 -0
  67. package/es/domain/entities/Message/Message.js +45 -0
  68. package/es/domain/entities/Message/MessageWithSession.js +21 -0
  69. package/es/domain/entities/Message/index.js +6 -0
  70. package/es/domain/entities/Session/Session.js +35 -0
  71. package/es/domain/entities/Session/index.js +2 -0
  72. package/es/domain/entities/index.js +8 -2
  73. package/es/domain/enum/actor/ActorType.js +7 -0
  74. package/es/domain/enum/actor/index.js +2 -0
  75. package/es/domain/enum/bot/BotServiceType.js +7 -0
  76. package/es/domain/enum/bot/index.js +2 -0
  77. package/es/domain/enum/index.js +5 -0
  78. package/es/domain/enum/integrationServices/IntegrationServices.js +11 -0
  79. package/es/domain/enum/integrationServices/index.js +2 -0
  80. package/es/domain/enum/message/ActionSubType.js +6 -0
  81. package/es/domain/enum/message/ActionType.js +6 -0
  82. package/es/domain/enum/message/ExternalInfoAction.js +9 -0
  83. package/es/domain/enum/message/InfoAction.js +17 -0
  84. package/es/domain/enum/message/InfoSessionStatus.js +10 -0
  85. package/es/domain/enum/message/MessageContentType.js +6 -0
  86. package/es/domain/enum/message/MessageDirection.js +6 -0
  87. package/es/domain/enum/message/MessageStatus.js +11 -0
  88. package/es/domain/enum/message/MessageType.js +11 -0
  89. package/es/domain/enum/message/index.js +10 -0
  90. package/es/domain/enum/session/SessionReplyStatus.js +20 -0
  91. package/es/domain/enum/session/SessionStatus.js +9 -0
  92. package/es/domain/enum/session/index.js +3 -0
  93. package/es/domain/interfaces/IAdapter.js +6 -0
  94. package/es/domain/interfaces/index.js +3 -1
  95. package/es/domain/interfaces/repositories/agents/IAgentRepository.js +9 -0
  96. package/es/domain/interfaces/repositories/agents/index.js +2 -0
  97. package/es/domain/interfaces/repositories/bots/IBotRepository.js +9 -0
  98. package/es/domain/interfaces/repositories/bots/index.js +2 -0
  99. package/es/domain/interfaces/repositories/channels/IChannelAgentRepository.js +9 -0
  100. package/es/domain/interfaces/repositories/channels/IChannelRepository.js +9 -0
  101. package/es/domain/interfaces/repositories/channels/index.js +3 -0
  102. package/es/domain/interfaces/repositories/contacts/IContactRepository.js +9 -0
  103. package/es/domain/interfaces/repositories/contacts/index.js +2 -0
  104. package/es/domain/interfaces/repositories/index.js +6 -0
  105. package/es/domain/interfaces/repositories/messages/IMessageRepository.js +43 -0
  106. package/es/domain/interfaces/repositories/messages/index.js +2 -0
  107. package/es/domain/interfaces/repositories/sessions/ISessionRepository.js +39 -0
  108. package/es/domain/interfaces/repositories/sessions/index.js +2 -0
  109. package/es/domain/schema/actor/ActorSchema.js +33 -0
  110. package/es/domain/schema/actor/AgentSchema.js +33 -0
  111. package/es/domain/schema/actor/index.js +3 -0
  112. package/es/domain/schema/attachment/AttachmentSchema.js +27 -0
  113. package/es/domain/schema/attachment/index.js +2 -0
  114. package/es/domain/schema/bot/BotSchema.js +33 -0
  115. package/es/domain/schema/bot/index.js +2 -0
  116. package/es/domain/schema/channel/ChannelSchema.js +49 -0
  117. package/es/domain/schema/channel/index.js +2 -0
  118. package/es/domain/schema/contact/ContactSchema.js +27 -0
  119. package/es/domain/schema/contact/index.js +2 -0
  120. package/es/domain/schema/index.js +8 -0
  121. package/es/domain/schema/integrationService/IntegrationServiceSchema.js +31 -0
  122. package/es/domain/schema/integrationService/index.js +2 -0
  123. package/es/domain/schema/message/ActionSchema.js +18 -0
  124. package/es/domain/schema/message/ExternalInfoSchema.js +9 -0
  125. package/es/domain/schema/message/InfoSchema.js +24 -0
  126. package/es/domain/schema/message/LocationSchema.js +11 -0
  127. package/es/domain/schema/message/MessageSchema.js +112 -0
  128. package/es/domain/schema/message/MessageWithSessionSchema.js +10 -0
  129. package/es/domain/schema/message/index.js +7 -0
  130. package/es/domain/schema/session/SessionSchema.js +82 -0
  131. package/es/domain/schema/session/index.js +2 -0
  132. package/es/frameworks/managers/ModuleFactory.js +58 -0
  133. package/es/frameworks/managers/ModuleManager.js +44 -0
  134. package/es/frameworks/managers/index.js +2 -0
  135. package/es/frameworks/sdk/IMSDK.js +62 -0
  136. package/es/frameworks/sdk/agents/AgentSDK.js +30 -0
  137. package/es/frameworks/sdk/agents/index.js +2 -0
  138. package/es/frameworks/sdk/bots/BotSDK.js +30 -0
  139. package/es/frameworks/sdk/bots/index.js +2 -0
  140. package/es/frameworks/sdk/channels/ChannelSDK.js +37 -0
  141. package/es/frameworks/sdk/channels/index.js +2 -0
  142. package/es/frameworks/sdk/contacts/ContactSDK.js +30 -0
  143. package/es/frameworks/sdk/contacts/index.js +2 -0
  144. package/es/frameworks/sdk/index.js +2 -0
  145. package/es/frameworks/sdk/messages/MessageSDK.js +32 -0
  146. package/es/frameworks/sdk/messages/index.js +2 -0
  147. package/es/frameworks/sdk/sessions/SessionSDK.js +34 -0
  148. package/es/frameworks/sdk/sessions/index.js +2 -0
  149. package/es/index.js +9 -6
  150. package/es/infrastructure/adapters/agents/AgentAdapter.js +29 -0
  151. package/es/infrastructure/adapters/agents/index.js +2 -0
  152. package/es/infrastructure/adapters/attachments/AttachmentAdapter.js +24 -0
  153. package/es/infrastructure/adapters/attachments/index.js +2 -0
  154. package/es/infrastructure/adapters/bots/BotAdapter.js +25 -0
  155. package/es/infrastructure/adapters/bots/index.js +2 -0
  156. package/es/infrastructure/adapters/channels/ChannelAdapter.js +29 -0
  157. package/es/infrastructure/adapters/channels/ChannelAgentAdapter.js +30 -0
  158. package/es/infrastructure/adapters/channels/index.js +3 -0
  159. package/es/infrastructure/adapters/contacts/ContactAdapter.js +24 -0
  160. package/es/infrastructure/adapters/contacts/index.js +2 -0
  161. package/es/infrastructure/adapters/index.js +7 -0
  162. package/es/infrastructure/adapters/messages/MessageAdapter.js +41 -0
  163. package/es/infrastructure/adapters/messages/MessageWithSessionAdapter.js +23 -0
  164. package/es/infrastructure/adapters/messages/index.js +2 -0
  165. package/es/infrastructure/adapters/sessions/SessionAdapter.js +36 -0
  166. package/es/infrastructure/adapters/sessions/index.js +2 -0
  167. package/es/infrastructure/api/BaseAPI.js +92 -0
  168. package/es/infrastructure/api/agents/AgentAPI.js +21 -0
  169. package/es/infrastructure/api/agents/index.js +2 -0
  170. package/es/infrastructure/api/bots/BotAPI.js +21 -0
  171. package/es/infrastructure/api/bots/index.js +2 -0
  172. package/es/infrastructure/api/channels/ChannelAPI.js +21 -0
  173. package/es/infrastructure/api/channels/ChannelAgentAPI.js +29 -0
  174. package/es/infrastructure/api/channels/index.js +3 -0
  175. package/es/infrastructure/api/contacts/ContactAPI.js +21 -0
  176. package/es/infrastructure/api/contacts/index.js +2 -0
  177. package/es/infrastructure/api/index.js +6 -0
  178. package/es/infrastructure/api/messages/MessageAPI.js +91 -0
  179. package/es/infrastructure/api/messages/index.js +2 -0
  180. package/es/infrastructure/api/registry/agents/agentAPIRegistry.js +12 -0
  181. package/es/infrastructure/api/registry/agents/constructAgentEndPoint.js +10 -0
  182. package/es/infrastructure/api/registry/agents/index.js +2 -0
  183. package/es/infrastructure/api/registry/bots/botAPIRegistry.js +12 -0
  184. package/es/infrastructure/api/registry/bots/constructBotEndPoint.js +10 -0
  185. package/es/infrastructure/api/registry/bots/index.js +2 -0
  186. package/es/infrastructure/api/registry/channels/channelAPIRegistry.js +16 -0
  187. package/es/infrastructure/api/registry/channels/channelAgentAPIRegistry.js +12 -0
  188. package/es/infrastructure/api/registry/channels/constructChannelEndPoint.js +10 -0
  189. package/es/infrastructure/api/registry/channels/index.js +2 -0
  190. package/es/infrastructure/api/registry/contacts/constructContactEndPoint.js +10 -0
  191. package/es/infrastructure/api/registry/contacts/contactAPIRegistry.js +12 -0
  192. package/es/infrastructure/api/registry/contacts/index.js +2 -0
  193. package/es/infrastructure/api/registry/createAPIRegistry.js +7 -0
  194. package/es/infrastructure/api/registry/createBaseUrl.js +3 -0
  195. package/es/infrastructure/api/registry/getRegistryConfig.js +26 -0
  196. package/es/infrastructure/api/registry/index.js +2 -0
  197. package/es/infrastructure/api/registry/messages/constructMessageEndPoint.js +4 -0
  198. package/es/infrastructure/api/registry/messages/index.js +2 -0
  199. package/es/infrastructure/api/registry/messages/messageAPIRegistry.js +57 -0
  200. package/es/infrastructure/api/registry/sessions/constructSessionEndPoint.js +10 -0
  201. package/es/infrastructure/api/registry/sessions/index.js +2 -0
  202. package/es/infrastructure/api/registry/sessions/sessionAPIRegistry.js +46 -0
  203. package/es/infrastructure/api/sessions/SessionAPI.js +81 -0
  204. package/es/infrastructure/api/sessions/index.js +2 -0
  205. package/es/infrastructure/config/configRegistry.js +27 -0
  206. package/es/infrastructure/config/index.js +2 -0
  207. package/es/infrastructure/repositories/agents/AgentRepository.js +27 -0
  208. package/es/infrastructure/repositories/agents/index.js +2 -0
  209. package/es/infrastructure/repositories/bots/BotRepository.js +27 -0
  210. package/es/infrastructure/repositories/bots/index.js +2 -0
  211. package/es/infrastructure/repositories/channels/ChannelAgentRepository.js +27 -0
  212. package/es/infrastructure/repositories/channels/ChannelRepository.js +27 -0
  213. package/es/infrastructure/repositories/channels/index.js +3 -0
  214. package/es/infrastructure/repositories/contacts/ContactRepository.js +27 -0
  215. package/es/infrastructure/repositories/contacts/index.js +2 -0
  216. package/es/infrastructure/repositories/index.js +6 -0
  217. package/es/infrastructure/repositories/messages/MessageRepository.js +72 -0
  218. package/es/infrastructure/repositories/messages/index.js +2 -0
  219. package/es/infrastructure/repositories/sessions/SessionRepository.js +67 -0
  220. package/es/infrastructure/repositories/sessions/index.js +2 -0
  221. package/package.json +4 -1
  222. package/es/domain/entities/Actor/ActorType.js +0 -6
  223. package/es/domain/interfaces/channels/IChannelAgent.js +0 -6
  224. package/es/domain/interfaces/channels/index.js +0 -2
  225. package/es/domain/services/channels/ChannelAgentService.js +0 -14
  226. package/es/domain/services/channels/index.js +0 -2
  227. package/es/domain/services/index.js +0 -1
  228. /package/es/{domain → core}/errors/ValidationError.js +0 -0
package/es/index.js CHANGED
@@ -1,6 +1,9 @@
1
- import * as _entities from './domain/entities';
2
- export { _entities as entities };
3
- import * as _interfaces from './domain/interfaces';
4
- export { _interfaces as interfaces };
5
- import * as _services from './domain/services';
6
- export { _services as services };
1
+ // domain
2
+ export * from "./domain/dto";
3
+ export * from "./domain/entities";
4
+ export * from "./domain/enum";
5
+ export * from "./domain/interfaces"; // frameworks
6
+
7
+ export * from "./frameworks/sdk"; // core
8
+
9
+ export * from "./core/constants";
@@ -0,0 +1,29 @@
1
+ import { AGENT } from 'imclient/src/constants/constants';
2
+ import { AdapterError } from "../../../core/errors";
3
+ import { Agent } from "../../../domain/entities";
4
+ import { ActorType } from "../../../domain/enum";
5
+ import { IAdapter } from "../../../domain/interfaces";
6
+ export default class AgentAdapter extends IAdapter {
7
+ adapt(agentData) {
8
+ if (!agentData) {
9
+ throw new AdapterError('Agent data is required');
10
+ }
11
+
12
+ try {
13
+ return new Agent({
14
+ id: agentData.id,
15
+ firstName: agentData.firstName,
16
+ lastName: agentData.lastName,
17
+ email: agentData.email,
18
+ zuid: agentData.zuid,
19
+ status: agentData.status,
20
+ role: agentData.rolePermissionType,
21
+ photoURL: agentData.photoURL,
22
+ type: [ActorType.AGENT]
23
+ }).toJSON();
24
+ } catch (error) {
25
+ throw new AdapterError(`Failed to adapt Agent: ${error.message}`);
26
+ }
27
+ }
28
+
29
+ }
@@ -0,0 +1,2 @@
1
+ import AgentAdapter from "./AgentAdapter";
2
+ export { AgentAdapter };
@@ -0,0 +1,24 @@
1
+ import { AdapterError } from "../../../core/errors";
2
+ import { Attachment } from "../../../domain/entities";
3
+ import { IAdapter } from "../../../domain/interfaces";
4
+ export default class AttachmentAdapter extends IAdapter {
5
+ adapt(attachmentData) {
6
+ if (!attachmentData) {
7
+ throw new AdapterError('Attachment data is required');
8
+ }
9
+
10
+ try {
11
+ return new Attachment({
12
+ id: attachmentData.id,
13
+ name: attachmentData.name,
14
+ type: attachmentData.type,
15
+ createdTime: attachmentData.createdTime,
16
+ size: attachmentData.size,
17
+ url: attachmentData.url
18
+ }).toJSON();
19
+ } catch (error) {
20
+ throw new AdapterError(`Failed to adapt attachment: ${error.message}`);
21
+ }
22
+ }
23
+
24
+ }
@@ -0,0 +1,2 @@
1
+ import AttachmentAdapter from "./AttachmentAdapter";
2
+ export { AttachmentAdapter };
@@ -0,0 +1,25 @@
1
+ import { AdapterError } from "../../../core/errors";
2
+ import { Bot } from "../../../domain/entities";
3
+ import { IAdapter } from "../../../domain/interfaces";
4
+ export default class BotAdapter extends IAdapter {
5
+ adapt(botData) {
6
+ if (!botData) {
7
+ throw new AdapterError('Bot data is required');
8
+ }
9
+
10
+ try {
11
+ return new Bot({
12
+ id: botData.id,
13
+ botServiceType: botData.botService.id,
14
+ name: botData.name,
15
+ isActive: botData.isActive,
16
+ createdTime: botData.createdTime,
17
+ photoURL: botData.logoURL,
18
+ createdBy: botData.createdBy
19
+ }).toJSON();
20
+ } catch (error) {
21
+ throw new AdapterError(`Failed to adapt bot: ${error.message}`);
22
+ }
23
+ }
24
+
25
+ }
@@ -0,0 +1,2 @@
1
+ import BotAdapter from "./BotAdapter";
2
+ export { BotAdapter };
@@ -0,0 +1,29 @@
1
+ import { AdapterError } from "../../../core/errors";
2
+ import { Channel } from "../../../domain/entities";
3
+ import { IAdapter } from "../../../domain/interfaces";
4
+ export default class ChannelAdapter extends IAdapter {
5
+ adapt(rawChannel) {
6
+ if (!rawChannel) {
7
+ throw new AdapterError('Channel data is required');
8
+ }
9
+
10
+ try {
11
+ return new Channel({
12
+ id: rawChannel.id,
13
+ integrationService: rawChannel.integrationService,
14
+ name: rawChannel.name,
15
+ defaultBotId: rawChannel.defaultBotId,
16
+ isActive: rawChannel.isActive,
17
+ createdTime: rawChannel.createdTime,
18
+ accountName: rawChannel.accountName,
19
+ isSubscribed: rawChannel.isSubscribed,
20
+ createdBy: rawChannel.createdBy,
21
+ isOwner: rawChannel.isOwner,
22
+ photoURL: rawChannel.logoURL
23
+ }).toJSON();
24
+ } catch (error) {
25
+ throw new AdapterError(`Failed to adapt channel: ${error.message}`);
26
+ }
27
+ }
28
+
29
+ }
@@ -0,0 +1,30 @@
1
+ import { AdapterError } from "../../../core/errors";
2
+ import { Agent } from "../../../domain/entities";
3
+ import { IAdapter } from "../../../domain/interfaces";
4
+ export default class ChannelAgentAdapter extends IAdapter {
5
+ /**
6
+ * Adapts channel agent data to Agent entity
7
+ * @param {Object} channelAgent - Channel agent data to adapt
8
+ * @returns {Object} Adapted agent data
9
+ * @throws {AdapterError} When adaptation fails
10
+ */
11
+ adapt(channelAgent) {
12
+ if (!channelAgent) {
13
+ throw new AdapterError('Channel agent data is required');
14
+ }
15
+
16
+ try {
17
+ return new Agent({
18
+ id: channelAgent.id,
19
+ name: channelAgent.name,
20
+ email: channelAgent.email,
21
+ photoURL: channelAgent.photoURL || '',
22
+ zuid: channelAgent.zuid,
23
+ type: channelAgent.type
24
+ }).toJSON();
25
+ } catch (error) {
26
+ throw new AdapterError(`Failed to adapt channel agent: ${error.message}`);
27
+ }
28
+ }
29
+
30
+ }
@@ -0,0 +1,3 @@
1
+ import ChannelAdapter from "./ChannelAdapter";
2
+ import ChannelAgentAdapter from "./ChannelAgentAdapter";
3
+ export { ChannelAgentAdapter, ChannelAdapter };
@@ -0,0 +1,24 @@
1
+ import { AdapterError } from "../../../core/errors";
2
+ import { Contact } from "../../../domain/entities";
3
+ import { IAdapter } from "../../../domain/interfaces";
4
+ export default class ContactAdapter extends IAdapter {
5
+ adapt(contactData) {
6
+ if (!contactData) {
7
+ throw new AdapterError('Contact data is required');
8
+ }
9
+
10
+ try {
11
+ return new Contact({
12
+ id: contactData.id,
13
+ name: contactData.name,
14
+ photoURL: contactData.photoURL,
15
+ email: contactData.email,
16
+ mobile: contactData.mobile,
17
+ phone: contactData.phone
18
+ }).toJSON();
19
+ } catch (error) {
20
+ throw new AdapterError(`Failed to adapt Contact: ${error.message}`);
21
+ }
22
+ }
23
+
24
+ }
@@ -0,0 +1,2 @@
1
+ import ContactAdapter from "./ContactAdapter";
2
+ export { ContactAdapter };
@@ -0,0 +1,7 @@
1
+ export * from "./channels";
2
+ export * from "./sessions";
3
+ export * from "./bots";
4
+ export * from "./attachments";
5
+ export * from "./messages";
6
+ export * from "./agents";
7
+ export * from "./contacts";
@@ -0,0 +1,41 @@
1
+ import { AdapterError } from "../../../core/errors";
2
+ import { Message } from "../../../domain/entities";
3
+ import { IAdapter } from "../../../domain/interfaces";
4
+ export default class MessageAdapter extends IAdapter {
5
+ adapt(messageData) {
6
+ if (!messageData) {
7
+ throw new AdapterError('Message data is required');
8
+ }
9
+
10
+ try {
11
+ return new Message({
12
+ id: messageData.id,
13
+ sessionId: messageData.sessionId,
14
+ displayMessage: messageData.displayMessage,
15
+ statusUpdatedTime: messageData.statusUpdatedTime,
16
+ actor: messageData.actor,
17
+ direction: messageData.direction,
18
+ createdTime: messageData.createdTime,
19
+ index: messageData.index,
20
+ replyToMessage: messageData.replyToMessage,
21
+ status: messageData.status,
22
+ info: messageData.info,
23
+ location: messageData.location,
24
+ externalInfo: messageData.externalInfo,
25
+ layout: messageData.layout,
26
+ action: messageData.action,
27
+ meta: messageData.meta,
28
+ contentType: messageData.contentType,
29
+ fullContentURL: messageData.fullContentURL,
30
+ attachment: messageData.attachment,
31
+ template: messageData.template,
32
+ type: messageData.type,
33
+ isRead: messageData.isRead,
34
+ article: messageData.article
35
+ }).toJSON();
36
+ } catch (error) {
37
+ throw new AdapterError(`Failed to adapt message: ${error.message}`);
38
+ }
39
+ }
40
+
41
+ }
@@ -0,0 +1,23 @@
1
+ import { AdapterError } from "../../../core/errors";
2
+ import { MessageWithSession } from "../../../domain/entities";
3
+ import { IAdapter } from "../../../domain/interfaces";
4
+ import { MessageAdapter, SessionAdapter } from "../index";
5
+ export default class MessageWithSessionAdapter extends IAdapter {
6
+ adapt(messageData) {
7
+ if (!messageData) {
8
+ throw new AdapterError('Message With Session data is required');
9
+ }
10
+
11
+ const message = new MessageAdapter().adapt(messageData);
12
+ const session = new SessionAdapter().adapt(messageData.session);
13
+
14
+ try {
15
+ return new MessageWithSession({ ...message,
16
+ session
17
+ }).toJSON();
18
+ } catch (error) {
19
+ throw new Error(`Failed to adapt message with session: ${error.message}`);
20
+ }
21
+ }
22
+
23
+ }
@@ -0,0 +1,2 @@
1
+ import MessageAdapter from "./MessageAdapter";
2
+ export { MessageAdapter };
@@ -0,0 +1,36 @@
1
+ import { AdapterError } from "../../../core/errors";
2
+ import { Session } from "../../../domain/entities";
3
+ import { IAdapter } from "../../../domain/interfaces";
4
+ export default class SessionAdapter extends IAdapter {
5
+ adapt(sessionData) {
6
+ if (!sessionData) {
7
+ throw new AdapterError('Session data is required');
8
+ }
9
+
10
+ try {
11
+ return new Session({
12
+ id: sessionData.id,
13
+ channelId: sessionData.channelId,
14
+ status: sessionData.status,
15
+ createdTime: sessionData.createdTime,
16
+ agentId: sessionData.agentId,
17
+ botId: sessionData.botId,
18
+ actor: sessionData.actor,
19
+ subject: sessionData.subject,
20
+ messagesCount: sessionData.messagesCount,
21
+ agentLastActiveTime: sessionData.agentLastActiveTime,
22
+ contactLastActiveTime: sessionData.contactLastActiveTime,
23
+ lastActiveTime: sessionData.lastActiveTime,
24
+ unreadMessagesCount: sessionData.unreadMessagesCount,
25
+ integrationServiceId: sessionData.integrationServiceId,
26
+ replyStatus: sessionData.replyStatus,
27
+ contactId: sessionData.contactId,
28
+ meta: sessionData.meta,
29
+ assignee: sessionData.assignee
30
+ }).toJSON();
31
+ } catch (error) {
32
+ throw new AdapterError(`Failed to adapt session: ${error.message}`);
33
+ }
34
+ }
35
+
36
+ }
@@ -0,0 +1,2 @@
1
+ import SessionAdapter from "./SessionAdapter";
2
+ export { SessionAdapter };
@@ -0,0 +1,92 @@
1
+ import configRegistry from "../config/configRegistry";
2
+ import { getRegistryConfig } from "./registry";
3
+ export default class BaseAPI {
4
+ constructor() {
5
+ let {
6
+ module,
7
+ configProvider = configRegistry,
8
+ registryProvider = {
9
+ getRegistryConfig
10
+ }
11
+ } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
12
+ this.configProvider = configProvider;
13
+ this.registryProvider = registryProvider;
14
+ this.httpClient = this.configProvider.getHttpClient();
15
+ this.baseURL = this.configProvider.getBaseURL();
16
+ this.module = module;
17
+ }
18
+
19
+ replacePathParams(url, params) {
20
+ let _url = url;
21
+ Object.entries(params).forEach(_ref => {
22
+ let [key, value] = _ref;
23
+ _url = url.replace(`:${key}`, value);
24
+ });
25
+ return _url;
26
+ }
27
+
28
+ buildUrl(_ref2) {
29
+ let {
30
+ url,
31
+ params,
32
+ query
33
+ } = _ref2;
34
+
35
+ const _params = params || {};
36
+
37
+ const _query = query || {};
38
+
39
+ let _url = this.replacePathParams(url, _params);
40
+
41
+ if (this.baseURL) {
42
+ _url = `${this.baseURL}${_url}`;
43
+ }
44
+
45
+ const queryString = this.buildQuery(_query);
46
+
47
+ if (queryString) {
48
+ return `${_url}?${queryString}`;
49
+ }
50
+
51
+ return _url;
52
+ }
53
+
54
+ buildQuery(query) {
55
+ const filteredQuery = Object.entries(query).filter(_ref3 => {
56
+ let [, value] = _ref3;
57
+ return value !== undefined && value !== null && value !== '';
58
+ }).reduce((acc, _ref4) => {
59
+ let [key, value] = _ref4;
60
+ acc[key] = value;
61
+ return acc;
62
+ }, {});
63
+ return new URLSearchParams(filteredQuery).toString();
64
+ }
65
+
66
+ async request(_ref5) {
67
+ let {
68
+ request,
69
+ operation,
70
+ header
71
+ } = _ref5;
72
+ const config = this.registryProvider.getRegistryConfig(this.module, operation);
73
+
74
+ if (!config) {
75
+ throw new Error(`Operation "${operation}" not found in registry for module "${this.module}"`);
76
+ }
77
+
78
+ const url = this.buildUrl({
79
+ url: config.endpoint,
80
+ params: request.params || {},
81
+ query: request.query || {}
82
+ });
83
+ const httpRequest = await this.httpClient.request({
84
+ url,
85
+ method: config.method,
86
+ header,
87
+ payload: request.body || {}
88
+ });
89
+ return httpRequest;
90
+ }
91
+
92
+ }
@@ -0,0 +1,21 @@
1
+ import { ModuleNames } from "../../../core/constants";
2
+ import { getAgentsRequest } from "../../../domain/dto";
3
+ import BaseAPI from "../BaseAPI";
4
+ export default class AgentAPI extends BaseAPI {
5
+ constructor() {
6
+ super({
7
+ module: ModuleNames.AGENTS
8
+ });
9
+ }
10
+
11
+ async getAgents() {
12
+ let request = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getAgentsRequest();
13
+ const operation = 'getAgents';
14
+ const httpRequest = await this.request({
15
+ request,
16
+ operation
17
+ });
18
+ return httpRequest;
19
+ }
20
+
21
+ }
@@ -0,0 +1,2 @@
1
+ import AgentAPI from "./AgentAPI";
2
+ export { AgentAPI };
@@ -0,0 +1,21 @@
1
+ import { ModuleNames } from "../../../core/constants";
2
+ import { getBotsRequest } from "../../../domain/dto";
3
+ import BaseAPI from "../BaseAPI";
4
+ export default class BotAPI extends BaseAPI {
5
+ constructor() {
6
+ super({
7
+ module: ModuleNames.BOTS
8
+ });
9
+ }
10
+
11
+ async getBots() {
12
+ let request = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getBotsRequest();
13
+ const operation = 'getBots';
14
+ const httpRequest = await this.request({
15
+ request,
16
+ operation
17
+ });
18
+ return httpRequest;
19
+ }
20
+
21
+ }
@@ -0,0 +1,2 @@
1
+ import BotAPI from "./BotAPI";
2
+ export { BotAPI };
@@ -0,0 +1,21 @@
1
+ import { ModuleNames } from "../../../core/constants";
2
+ import { getChannelsRequest } from "../../../domain/dto";
3
+ import BaseAPI from "../BaseAPI";
4
+ export default class ChannelAPI extends BaseAPI {
5
+ constructor() {
6
+ super({
7
+ module: ModuleNames.CHANNELS
8
+ });
9
+ }
10
+
11
+ async getChannels() {
12
+ let request = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getChannelsRequest();
13
+ const operation = 'getChannels';
14
+ const httpRequest = await this.request({
15
+ request,
16
+ operation
17
+ });
18
+ return httpRequest;
19
+ }
20
+
21
+ }
@@ -0,0 +1,29 @@
1
+ import { ModuleNames } from "../../../core/constants";
2
+ import { getChannelAgentsRequest } from "../../../domain/dto";
3
+ import BaseAPI from "../BaseAPI";
4
+ export default class ChannelAgentAPI extends BaseAPI {
5
+ constructor() {
6
+ super({
7
+ module: `${ModuleNames.CHANNELS}.agents`
8
+ });
9
+ }
10
+
11
+ async getAgents() {
12
+ let request = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getChannelAgentsRequest();
13
+ const {
14
+ searchStr
15
+ } = request.query;
16
+
17
+ if (searchStr) {
18
+ request.query.searchStr = `*${encodeURIComponent(searchStr)}*`;
19
+ }
20
+
21
+ const operation = 'getAgents';
22
+ const httpRequest = await this.request({
23
+ request,
24
+ operation
25
+ });
26
+ return httpRequest;
27
+ }
28
+
29
+ }
@@ -0,0 +1,3 @@
1
+ import ChannelAgentAPI from "./ChannelAgentAPI";
2
+ import ChannelAPI from "./ChannelAPI";
3
+ export { ChannelAgentAPI, ChannelAPI };
@@ -0,0 +1,21 @@
1
+ import { ModuleNames } from "../../../core/constants";
2
+ import { getContactsRequest } from "../../../domain/dto";
3
+ import BaseAPI from "../BaseAPI";
4
+ export default class ContactAPI extends BaseAPI {
5
+ constructor() {
6
+ super({
7
+ module: ModuleNames.CONTACTS
8
+ });
9
+ }
10
+
11
+ async getContacts() {
12
+ let request = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getContactsRequest();
13
+ const operation = 'getContacts';
14
+ const httpRequest = await this.request({
15
+ request,
16
+ operation
17
+ });
18
+ return httpRequest;
19
+ }
20
+
21
+ }
@@ -0,0 +1,2 @@
1
+ import ContactAPI from "./ContactAPI";
2
+ export { ContactAPI };
@@ -0,0 +1,6 @@
1
+ export * from "./channels";
2
+ export * from "./sessions";
3
+ export * from "./bots";
4
+ export * from "./messages";
5
+ export * from "./agents";
6
+ export * from "./contacts";
@@ -0,0 +1,91 @@
1
+ import { ModuleNames } from "../../../core/constants";
2
+ import { getMessagesRequest, deleteMessageRequest, getFullContentRequest, resendMessageRequest, sendAttachmentRequest, sendMessageRequest, initiateSessionRequest, searchMessagesRequest } from "../../../domain/dto";
3
+ import BaseAPI from "../BaseAPI";
4
+ export default class MessageAPI extends BaseAPI {
5
+ constructor() {
6
+ super({
7
+ module: ModuleNames.MESSAGES
8
+ });
9
+ }
10
+
11
+ async getMessages() {
12
+ let request = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getMessagesRequest();
13
+ const operation = 'getMessages';
14
+ const httpRequest = await this.request({
15
+ operation,
16
+ request
17
+ });
18
+ return httpRequest;
19
+ }
20
+
21
+ async getFullContent() {
22
+ let request = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getFullContentRequest();
23
+ const operation = 'getFullContent';
24
+ const httpRequest = await this.request({
25
+ operation,
26
+ request
27
+ });
28
+ return httpRequest;
29
+ }
30
+
31
+ async sendMessage() {
32
+ let request = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : sendMessageRequest();
33
+ const operation = 'sendMessage';
34
+ const httpRequest = await this.request({
35
+ operation,
36
+ request
37
+ });
38
+ return httpRequest;
39
+ }
40
+
41
+ async sendAttachment() {
42
+ let request = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : sendAttachmentRequest();
43
+ const operation = 'sendAttachment';
44
+ const httpRequest = await this.request({
45
+ operation,
46
+ request
47
+ });
48
+ return httpRequest;
49
+ }
50
+
51
+ async resendMessage() {
52
+ let request = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : resendMessageRequest();
53
+ const operation = 'resendMessage';
54
+ const httpRequest = await this.request({
55
+ operation,
56
+ request
57
+ });
58
+ return httpRequest;
59
+ }
60
+
61
+ async deleteMessage() {
62
+ let request = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : deleteMessageRequest();
63
+ const operation = 'deleteMessage';
64
+ const httpRequest = await this.request({
65
+ operation,
66
+ request
67
+ });
68
+ return httpRequest;
69
+ }
70
+
71
+ async initiateSession() {
72
+ let request = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : initiateSessionRequest();
73
+ const operation = 'initiateSession';
74
+ const httpRequest = await this.request({
75
+ operation,
76
+ request
77
+ });
78
+ return httpRequest;
79
+ }
80
+
81
+ async searchMessages() {
82
+ let request = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : searchMessagesRequest();
83
+ const operation = 'searchMessages';
84
+ const httpRequest = await this.request({
85
+ operation,
86
+ request
87
+ });
88
+ return httpRequest;
89
+ }
90
+
91
+ }
@@ -0,0 +1,2 @@
1
+ import MessageAPI from "./MessageAPI";
2
+ export { MessageAPI };