@zohoim/client-sdk 1.0.0-poc63 → 1.0.0-poc65

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.
@@ -0,0 +1,4 @@
1
+ const LIST = 'list';
2
+ const SINGLE = 'single';
3
+ const NONE = 'none';
4
+ export { LIST, SINGLE, NONE };
@@ -1,5 +1,6 @@
1
1
  import { HttpMethods } from '@zohoim/http-client';
2
2
  import ModuleNames from "./ModuleNames";
3
+ import { LIST, SINGLE, NONE } from "./ResponseTypes";
3
4
  const IM_API_PREFIX = '/api/v1';
4
5
  const HTTP_METHODS = HttpMethods;
5
- export { ModuleNames, IM_API_PREFIX, HTTP_METHODS };
6
+ export { ModuleNames, IM_API_PREFIX, HTTP_METHODS, LIST, SINGLE, NONE };
@@ -3,7 +3,8 @@ import RequestBuilder from "../RequestBuilder";
3
3
  function getContactsRequest() {
4
4
  return new RequestBuilder().withQuery({
5
5
  from: 0,
6
- limit: 10
6
+ limit: 10,
7
+ searchStr: null
7
8
  }).build();
8
9
  }
9
10
 
@@ -21,7 +21,7 @@ const AttachmentSchema = {
21
21
  },
22
22
  url: {
23
23
  type: 'string',
24
- required: true
24
+ required: false
25
25
  }
26
26
  };
27
27
  export default AttachmentSchema;
@@ -1,3 +1,5 @@
1
+ import { LIST, NONE, SINGLE } from "../../core/constants";
2
+ import { ResponseUtils } from "../../core/utils";
1
3
  import configRegistry from "../config/configRegistry";
2
4
  import { getRegistryConfig } from "./registry";
3
5
  export default class BaseAPI {
@@ -60,15 +62,18 @@ export default class BaseAPI {
60
62
  acc[key] = value;
61
63
  return acc;
62
64
  }, {});
63
- return new URLSearchParams(filteredQuery).toString();
65
+ return Object.entries(filteredQuery).map(_ref5 => {
66
+ let [key, value] = _ref5;
67
+ return `${key}=${value}`;
68
+ }).join('&');
64
69
  }
65
70
 
66
- async request(_ref5) {
71
+ async request(_ref6) {
67
72
  let {
68
73
  request,
69
74
  operation,
70
75
  header
71
- } = _ref5;
76
+ } = _ref6;
72
77
  const config = this.registryProvider.getRegistryConfig(this.module, operation);
73
78
 
74
79
  if (!config) {
@@ -89,7 +94,7 @@ export default class BaseAPI {
89
94
  return httpRequest;
90
95
  }
91
96
 
92
- createAPIProxy(customAPI, defaultAPI, defaultAPIInstance) {
97
+ createAPIProxy(customAPI, defaultAPI) {
93
98
  // If no custom API provided, just use default
94
99
  if (!customAPI) {
95
100
  return defaultAPI;
@@ -99,7 +104,7 @@ export default class BaseAPI {
99
104
  return new Proxy({}, {
100
105
  get: (target, prop) => {
101
106
  // For methods, check if custom implementation exists
102
- if (typeof prop === 'string' && typeof customAPI[prop] === 'function' && this.isMethodOverridden(defaultAPIInstance, customAPI, prop)) {
107
+ if (typeof prop === 'string' && typeof customAPI[prop] === 'function' && this.isMethodOverridden(customAPI, prop)) {
103
108
  // Use custom implementation if available
104
109
  return customAPI[prop].bind(customAPI);
105
110
  } // Fall back to default implementation
@@ -110,10 +115,33 @@ export default class BaseAPI {
110
115
  });
111
116
  }
112
117
 
113
- isMethodOverridden(defaultAPIInstance, customAPI, methodName) {
114
- const basePrototype = defaultAPIInstance.prototype;
115
- const injectedMethod = customAPI[methodName];
116
- return injectedMethod !== basePrototype[methodName];
118
+ isMethodOverridden(customAPI, methodName) {
119
+ const customPrototype = Object.getPrototypeOf(customAPI);
120
+ return typeof customAPI[methodName] === 'function' && // Method is defined directly on custom prototype
121
+ Object.prototype.hasOwnProperty.call(customPrototype, methodName);
122
+ }
123
+
124
+ async executeAPICall(_ref7) {
125
+ let {
126
+ operation,
127
+ request,
128
+ apiProxy,
129
+ customAPI,
130
+ adapter,
131
+ responseType = SINGLE
132
+ } = _ref7;
133
+ const response = await apiProxy[operation](request);
134
+ const isOverridden = this.isMethodOverridden(customAPI, operation);
135
+
136
+ if (isOverridden) {
137
+ return response;
138
+ }
139
+
140
+ if (responseType === NONE || !adapter) {
141
+ return response;
142
+ }
143
+
144
+ return responseType === LIST ? ResponseUtils.adaptListResponse(response, adapter.adapt) : ResponseUtils.adaptSingleResponse(response, adapter.adapt);
117
145
  }
118
146
 
119
147
  }
@@ -1,7 +1,7 @@
1
- import { ResponseUtils } from "../../../core/utils";
2
1
  import { IAgentRepository } from "../../../domain/interfaces/repositories";
3
2
  import { AgentAdapter } from "../../adapters";
4
3
  import { AgentAPI } from "../../api";
4
+ import { LIST } from "../../../core/constants";
5
5
  export default class AgentRepository extends IAgentRepository {
6
6
  constructor(_ref) {
7
7
  let {
@@ -9,13 +9,35 @@ export default class AgentRepository extends IAgentRepository {
9
9
  agentAdapter
10
10
  } = _ref;
11
11
  super();
12
- this.agentAPI = agentAPI || new AgentAPI();
12
+ this.defaultAPI = new AgentAPI();
13
+ this.customAPI = agentAPI;
14
+ this.agentAPI = this.createAPIProxy(this.customAPI, this.defaultAPI);
13
15
  this.agentAdapter = agentAdapter || new AgentAdapter();
14
16
  }
15
17
 
18
+ async invokeAPI(_ref2) {
19
+ let {
20
+ operation,
21
+ request,
22
+ adapter = this.agentAdapter,
23
+ responseType
24
+ } = _ref2;
25
+ return this.executeAPICall({
26
+ operation,
27
+ request,
28
+ apiProxy: this.agentAPI,
29
+ customAPI: this.customAPI,
30
+ adapter,
31
+ responseType
32
+ });
33
+ }
34
+
16
35
  async getAgents(request) {
17
- const response = await this.agentAPI.getAgents(request);
18
- return ResponseUtils.adaptListResponse(response, this.agentAdapter.adapt);
36
+ return this.invokeAPI({
37
+ operation: 'getAgents',
38
+ request,
39
+ responseType: LIST
40
+ });
19
41
  }
20
42
 
21
43
  toJSON() {
@@ -1,7 +1,7 @@
1
- import { ResponseUtils } from "../../../core/utils";
2
1
  import { IBotRepository } from "../../../domain/interfaces/repositories";
3
2
  import { BotAdapter } from "../../adapters";
4
3
  import { BotAPI } from "../../api";
4
+ import { LIST } from "../../../core/constants";
5
5
  export default class BotRepository extends IBotRepository {
6
6
  constructor(_ref) {
7
7
  let {
@@ -10,23 +10,34 @@ export default class BotRepository extends IBotRepository {
10
10
  } = _ref;
11
11
  super();
12
12
  this.defaultAPI = new BotAPI();
13
- this.botAPI = this.createAPIProxy(botAPI, this.defaultAPI, BotAPI);
13
+ this.customAPI = botAPI;
14
+ this.botAPI = this.createAPIProxy(this.customAPI, this.defaultAPI);
14
15
  this.botAdapter = botAdapter || new BotAdapter();
15
16
  }
16
17
 
17
- isOverridden(methodName) {
18
- return this.isMethodOverridden(BotAPI, this.botAPI, methodName);
18
+ async invokeAPI(_ref2) {
19
+ let {
20
+ operation,
21
+ request,
22
+ adapter = this.botAdapter,
23
+ responseType
24
+ } = _ref2;
25
+ return this.executeAPICall({
26
+ operation,
27
+ request,
28
+ apiProxy: this.botAPI,
29
+ customAPI: this.customAPI,
30
+ adapter,
31
+ responseType
32
+ });
19
33
  }
20
34
 
21
35
  async getBots(request) {
22
- const response = await this.botAPI.getBots(request);
23
- const isOverridden = this.isOverridden('getBots');
24
-
25
- if (isOverridden) {
26
- return response;
27
- }
28
-
29
- return ResponseUtils.adaptListResponse(response, this.botAdapter.adapt);
36
+ return this.invokeAPI({
37
+ operation: 'getBots',
38
+ request,
39
+ responseType: LIST
40
+ });
30
41
  }
31
42
 
32
43
  toJSON() {
@@ -1,7 +1,7 @@
1
- import { ResponseUtils } from "../../../core/utils";
2
1
  import { IChannelAgentRepository } from "../../../domain/interfaces/repositories";
3
2
  import { ChannelAgentAdapter } from "../../adapters";
4
3
  import { ChannelAgentAPI } from "../../api";
4
+ import { LIST } from "../../../core/constants";
5
5
  export default class ChannelAgentRepository extends IChannelAgentRepository {
6
6
  constructor(_ref) {
7
7
  let {
@@ -9,13 +9,35 @@ export default class ChannelAgentRepository extends IChannelAgentRepository {
9
9
  channelAgentAdapter
10
10
  } = _ref;
11
11
  super();
12
- this.channelAgentAPI = channelAgentAPI || new ChannelAgentAPI();
12
+ this.defaultAPI = new ChannelAgentAPI();
13
+ this.customAPI = channelAgentAPI;
14
+ this.channelAgentAPI = this.createAPIProxy(this.customAPI, this.defaultAPI);
13
15
  this.channelAgentAdapter = channelAgentAdapter || new ChannelAgentAdapter();
14
16
  }
15
17
 
18
+ async invokeAPI(_ref2) {
19
+ let {
20
+ operation,
21
+ request,
22
+ adapter = this.channelAgentAdapter,
23
+ responseType
24
+ } = _ref2;
25
+ return this.executeAPICall({
26
+ operation,
27
+ request,
28
+ apiProxy: this.channelAgentAPI,
29
+ customAPI: this.customAPI,
30
+ adapter,
31
+ responseType
32
+ });
33
+ }
34
+
16
35
  async getAgents(request) {
17
- const response = await this.channelAgentAPI.getAgents(request);
18
- return ResponseUtils.adaptListResponse(response, this.channelAgentAdapter.adapt);
36
+ return this.invokeAPI({
37
+ operation: 'getAgents',
38
+ request,
39
+ responseType: LIST
40
+ });
19
41
  }
20
42
 
21
43
  toJSON() {
@@ -1,7 +1,7 @@
1
- import { ResponseUtils } from "../../../core/utils";
2
1
  import { IChannelRepository } from "../../../domain/interfaces/repositories";
3
2
  import { ChannelAdapter } from "../../adapters";
4
3
  import { ChannelAPI } from "../../api";
4
+ import { LIST } from "../../../core/constants";
5
5
  export default class ChannelRepository extends IChannelRepository {
6
6
  constructor() {
7
7
  let {
@@ -9,13 +9,35 @@ export default class ChannelRepository extends IChannelRepository {
9
9
  channelAdapter
10
10
  } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
11
11
  super();
12
- this.channelAPI = channelAPI || new ChannelAPI();
12
+ this.defaultAPI = new ChannelAPI();
13
+ this.customAPI = channelAPI;
14
+ this.channelAPI = this.createAPIProxy(this.customAPI, this.defaultAPI);
13
15
  this.channelAdapter = channelAdapter || new ChannelAdapter();
14
16
  }
15
17
 
18
+ async invokeAPI(_ref) {
19
+ let {
20
+ operation,
21
+ request,
22
+ adapter = this.channelAdapter,
23
+ responseType
24
+ } = _ref;
25
+ return this.executeAPICall({
26
+ operation,
27
+ request,
28
+ apiProxy: this.channelAPI,
29
+ customAPI: this.customAPI,
30
+ adapter,
31
+ responseType
32
+ });
33
+ }
34
+
16
35
  async getChannels(request) {
17
- const response = await this.channelAPI.getChannels(request);
18
- return ResponseUtils.adaptListResponse(response, this.channelAdapter.adapt);
36
+ return this.invokeAPI({
37
+ operation: 'getChannels',
38
+ request,
39
+ responseType: LIST
40
+ });
19
41
  }
20
42
 
21
43
  toJSON() {
@@ -1,7 +1,7 @@
1
- import { ResponseUtils } from "../../../core/utils";
2
1
  import { IContactRepository } from "../../../domain/interfaces/repositories";
3
2
  import { ContactAdapter } from "../../adapters";
4
3
  import { ContactAPI } from "../../api";
4
+ import { LIST } from "../../../core/constants";
5
5
  export default class ContactRepository extends IContactRepository {
6
6
  constructor(_ref) {
7
7
  let {
@@ -9,13 +9,35 @@ export default class ContactRepository extends IContactRepository {
9
9
  contactAdapter
10
10
  } = _ref;
11
11
  super();
12
- this.contactAPI = contactAPI || new ContactAPI();
12
+ this.defaultAPI = new ContactAPI();
13
+ this.customAPI = contactAPI;
14
+ this.contactAPI = this.createAPIProxy(this.customAPI, this.defaultAPI);
13
15
  this.contactAdapter = contactAdapter || new ContactAdapter();
14
16
  }
15
17
 
18
+ async invokeAPI(_ref2) {
19
+ let {
20
+ operation,
21
+ request,
22
+ adapter = this.contactAdapter,
23
+ responseType
24
+ } = _ref2;
25
+ return this.executeAPICall({
26
+ operation,
27
+ request,
28
+ apiProxy: this.contactAPI,
29
+ customAPI: this.customAPI,
30
+ adapter,
31
+ responseType
32
+ });
33
+ }
34
+
16
35
  async getContacts(request) {
17
- const response = await this.contactAPI.getContacts(request);
18
- return ResponseUtils.adaptListResponse(response, this.contactAdapter.adapt);
36
+ return this.invokeAPI({
37
+ operation: 'getContacts',
38
+ request,
39
+ responseType: LIST
40
+ });
19
41
  }
20
42
 
21
43
  toJSON() {
@@ -1,8 +1,8 @@
1
1
  import { MessageAdapter } from "../../adapters";
2
- import { ResponseUtils } from "../../../core/utils";
3
2
  import { MessageAPI } from "../../api";
4
3
  import { IMessageRepository } from "../../../domain/interfaces/repositories/messages";
5
4
  import MessageWithSessionAdapter from "../../adapters/messages/MessageWithSessionAdapter";
5
+ import { LIST, NONE } from "../../../core/constants";
6
6
  export default class MessageRepository extends IMessageRepository {
7
7
  constructor(_ref) {
8
8
  let {
@@ -11,49 +11,88 @@ export default class MessageRepository extends IMessageRepository {
11
11
  messageWithSessionAdapter
12
12
  } = _ref;
13
13
  super();
14
- this.messageAPI = messageAPI || new MessageAPI();
14
+ this.defaultAPI = new MessageAPI();
15
+ this.customAPI = messageAPI;
16
+ this.messageAPI = this.createAPIProxy(this.customAPI, this.defaultAPI);
15
17
  this.messageAdapter = messageAdapter || new MessageAdapter();
16
18
  this.messageWithSessionAdapter = messageWithSessionAdapter || new MessageWithSessionAdapter();
17
19
  }
18
20
 
21
+ async invokeAPI(_ref2) {
22
+ let {
23
+ operation,
24
+ request,
25
+ adapter = this.messageAdapter,
26
+ responseType
27
+ } = _ref2;
28
+ return this.executeAPICall({
29
+ operation,
30
+ request,
31
+ apiProxy: this.messageAPI,
32
+ customAPI: this.customAPI,
33
+ adapter,
34
+ responseType
35
+ });
36
+ }
37
+
19
38
  async getMessages(request) {
20
- const response = await this.messageAPI.getMessages(request);
21
- return ResponseUtils.adaptListResponse(response, this.messageAdapter.adapt);
39
+ return this.invokeAPI({
40
+ operation: 'getMessages',
41
+ request,
42
+ responseType: LIST
43
+ });
22
44
  }
23
45
 
24
46
  async getFullContent(request) {
25
- const response = await this.messageAPI.getFullContent(request);
26
- return response;
47
+ return this.invokeAPI({
48
+ operation: 'getFullContent',
49
+ request,
50
+ responseType: NONE
51
+ });
27
52
  }
28
53
 
29
54
  async sendMessage(request) {
30
- const response = await this.messageAPI.sendMessage(request);
31
- return ResponseUtils.adaptSingleResponse(response, this.messageAdapter.adapt);
55
+ return this.invokeAPI({
56
+ operation: 'sendMessage',
57
+ request
58
+ });
32
59
  }
33
60
 
34
61
  async sendAttachment(request) {
35
- const response = await this.messageAPI.sendAttachment(request);
36
- return ResponseUtils.adaptSingleResponse(response, this.messageAdapter.adapt);
62
+ return this.invokeAPI({
63
+ operation: 'sendAttachment',
64
+ request
65
+ });
37
66
  }
38
67
 
39
68
  async resendMessage(request) {
40
- const response = await this.messageAPI.resendMessage(request);
41
- return ResponseUtils.adaptSingleResponse(response, this.messageAdapter.adapt);
69
+ return this.invokeAPI({
70
+ operation: 'resendMessage',
71
+ request
72
+ });
42
73
  }
43
74
 
44
75
  async deleteMessage(request) {
45
- const response = await this.messageAPI.deleteMessage(request);
46
- return ResponseUtils.adaptSingleResponse(response, this.messageAdapter.adapt);
76
+ return this.invokeAPI({
77
+ operation: 'deleteMessage',
78
+ request
79
+ });
47
80
  }
48
81
 
49
82
  async initiateSession(request) {
50
- const response = await this.messageAPI.initiateSession(request);
51
- return ResponseUtils.adaptSingleResponse(response, this.messageAdapter.adapt);
83
+ return this.invokeAPI({
84
+ operation: 'initiateSession',
85
+ request
86
+ });
52
87
  }
53
88
 
54
89
  async searchMessages(request) {
55
- const response = await this.messageAPI.searchMessages(request);
56
- return ResponseUtils.adaptListResponse(response, this.messageWithSessionAdapter.adapt);
90
+ return this.invokeAPI({
91
+ operation: 'searchMessages',
92
+ request,
93
+ adapter: this.messageWithSessionAdapter,
94
+ responseType: LIST
95
+ });
57
96
  }
58
97
 
59
98
  toJSON() {
@@ -1,7 +1,7 @@
1
1
  import { AttachmentAdapter, MessageAdapter, SessionAdapter } from "../../adapters/index";
2
- import { ResponseUtils } from "../../../core/utils";
3
2
  import { ISessionRepository } from "../../../domain/interfaces/repositories";
4
3
  import { SessionAPI } from "../../api";
4
+ import { LIST } from "../../../core/constants";
5
5
  export default class SessionRepository extends ISessionRepository {
6
6
  constructor(_ref) {
7
7
  let {
@@ -11,45 +11,83 @@ export default class SessionRepository extends ISessionRepository {
11
11
  messageAdapter
12
12
  } = _ref;
13
13
  super();
14
- this.sessionAPI = sessionAPI || new SessionAPI();
14
+ this.defaultAPI = new SessionAPI();
15
+ this.customAPI = sessionAPI;
16
+ this.sessionAPI = this.createAPIProxy(this.customAPI, this.defaultAPI);
15
17
  this.sessionAdapter = sessionAdapter || new SessionAdapter();
16
18
  this.attachmentAdapter = attachmentAdapter || new AttachmentAdapter();
17
19
  this.messageAdapter = messageAdapter || new MessageAdapter();
18
20
  }
19
21
 
22
+ async invokeAPI(_ref2) {
23
+ let {
24
+ operation,
25
+ request,
26
+ adapter = this.sessionAdapter,
27
+ responseType
28
+ } = _ref2;
29
+ return this.executeAPICall({
30
+ operation,
31
+ request,
32
+ apiProxy: this.sessionAPI,
33
+ customAPI: this.customAPI,
34
+ adapter,
35
+ responseType
36
+ });
37
+ }
38
+
20
39
  async updateAssignee(request) {
21
- const response = await this.sessionAPI.updateAssignee(request);
22
- return ResponseUtils.adaptSingleResponse(response, this.sessionAdapter.adapt);
40
+ return this.invokeAPI({
41
+ operation: 'updateAssignee',
42
+ request
43
+ });
23
44
  }
24
45
 
25
46
  async getSessions(request) {
26
- const response = await this.sessionAPI.getSessions(request);
27
- return ResponseUtils.adaptListResponse(response, this.sessionAdapter.adapt);
47
+ return this.invokeAPI({
48
+ operation: 'getSessions',
49
+ request,
50
+ responseType: LIST
51
+ });
28
52
  }
29
53
 
30
54
  async getSession(request) {
31
- const response = await this.sessionAPI.getSession(request);
32
- return ResponseUtils.adaptSingleResponse(response, this.sessionAdapter.adapt);
55
+ return this.invokeAPI({
56
+ operation: 'getSession',
57
+ request
58
+ });
33
59
  }
34
60
 
35
61
  async getSessionAttachments(request) {
36
- const response = await this.sessionAPI.getSessionAttachments(request);
37
- return ResponseUtils.adaptListResponse(response, this.attachmentAdapter.adapt);
62
+ return this.invokeAPI({
63
+ operation: 'getSessionAttachments',
64
+ request,
65
+ adapter: this.attachmentAdapter,
66
+ responseType: LIST
67
+ });
38
68
  }
39
69
 
40
70
  async getSessionLastMessages(request) {
41
- const response = await this.sessionAPI.getSessionLastMessages(request);
42
- return ResponseUtils.adaptListResponse(response, this.messageAdapter.adapt);
71
+ return this.invokeAPI({
72
+ operation: 'getSessionLastMessages',
73
+ request,
74
+ adapter: this.messageAdapter,
75
+ responseType: LIST
76
+ });
43
77
  }
44
78
 
45
79
  async markSessionAsRead(request) {
46
- const response = await this.sessionAPI.markSessionAsRead(request);
47
- return ResponseUtils.adaptSingleResponse(response, this.sessionAdapter.adapt);
80
+ return this.invokeAPI({
81
+ operation: 'markSessionAsRead',
82
+ request
83
+ });
48
84
  }
49
85
 
50
86
  async updateSessionStatus(request) {
51
- const response = await this.sessionAPI.updateSessionStatus(request);
52
- return ResponseUtils.adaptSingleResponse(response, this.sessionAdapter.adapt);
87
+ return this.invokeAPI({
88
+ operation: 'updateSessionStatus',
89
+ request
90
+ });
53
91
  }
54
92
 
55
93
  toJSON() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohoim/client-sdk",
3
- "version": "1.0.0-poc63",
3
+ "version": "1.0.0-poc65",
4
4
  "description": "To have the client sdk for the IM",
5
5
  "main": "es/index.js",
6
6
  "module": "es/index.js",