@zohoim/client-sdk 1.0.0-poc62 → 1.0.0-poc64

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.
@@ -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;
@@ -99,7 +99,7 @@ export default class BaseAPI {
99
99
  return new Proxy({}, {
100
100
  get: (target, prop) => {
101
101
  // For methods, check if custom implementation exists
102
- if (typeof prop === 'string' && typeof customAPI[prop] === 'function' && this.isMethodOverridden(defaultAPI, customAPI, prop)) {
102
+ if (typeof prop === 'string' && typeof customAPI[prop] === 'function' && this.isMethodOverridden(customAPI, prop)) {
103
103
  // Use custom implementation if available
104
104
  return customAPI[prop].bind(customAPI);
105
105
  } // Fall back to default implementation
@@ -110,10 +110,10 @@ export default class BaseAPI {
110
110
  });
111
111
  }
112
112
 
113
- isMethodOverridden(defaultAPI, customAPI, methodName) {
114
- const basePrototype = defaultAPI.prototype;
115
- const injectedMethod = customAPI[methodName];
116
- return injectedMethod !== basePrototype[methodName];
113
+ isMethodOverridden(customAPI, methodName) {
114
+ const customPrototype = Object.getPrototypeOf(customAPI);
115
+ return typeof customAPI[methodName] === 'function' && // Method is defined directly on custom prototype
116
+ Object.prototype.hasOwnProperty.call(customPrototype, methodName);
117
117
  }
118
118
 
119
119
  }
@@ -9,12 +9,20 @@ 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
 
16
18
  async getAgents(request) {
17
19
  const response = await this.agentAPI.getAgents(request);
20
+ const isOverridden = this.isMethodOverridden(this.customAPI, 'getAgents');
21
+
22
+ if (isOverridden) {
23
+ return response;
24
+ }
25
+
18
26
  return ResponseUtils.adaptListResponse(response, this.agentAdapter.adapt);
19
27
  }
20
28
 
@@ -10,17 +10,14 @@ 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);
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(this.defaultAPI, this.botAPI, methodName);
19
- }
20
-
21
18
  async getBots(request) {
22
19
  const response = await this.botAPI.getBots(request);
23
- const isOverridden = this.isOverridden('getBots');
20
+ const isOverridden = this.isMethodOverridden(this.customAPI, 'getBots');
24
21
 
25
22
  if (isOverridden) {
26
23
  return response;
@@ -9,12 +9,20 @@ 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
 
16
18
  async getAgents(request) {
17
19
  const response = await this.channelAgentAPI.getAgents(request);
20
+ const isOverridden = this.isMethodOverridden(this.customAPI, 'getAgents');
21
+
22
+ if (isOverridden) {
23
+ return response;
24
+ }
25
+
18
26
  return ResponseUtils.adaptListResponse(response, this.channelAgentAdapter.adapt);
19
27
  }
20
28
 
@@ -9,12 +9,20 @@ 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
 
16
18
  async getChannels(request) {
17
19
  const response = await this.channelAPI.getChannels(request);
20
+ const isOverridden = this.isMethodOverridden(this.customAPI, 'getChannels');
21
+
22
+ if (isOverridden) {
23
+ return response;
24
+ }
25
+
18
26
  return ResponseUtils.adaptListResponse(response, this.channelAdapter.adapt);
19
27
  }
20
28
 
@@ -9,12 +9,20 @@ 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
 
16
18
  async getContacts(request) {
17
19
  const response = await this.contactAPI.getContacts(request);
20
+ const isOverridden = this.isMethodOverridden(this.customAPI, 'getContacts');
21
+
22
+ if (isOverridden) {
23
+ return response;
24
+ }
25
+
18
26
  return ResponseUtils.adaptListResponse(response, this.contactAdapter.adapt);
19
27
  }
20
28
 
@@ -11,13 +11,21 @@ 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
 
19
21
  async getMessages(request) {
20
22
  const response = await this.messageAPI.getMessages(request);
23
+ const isOverridden = this.isMethodOverridden(this.customAPI, 'getMessages');
24
+
25
+ if (isOverridden) {
26
+ return response;
27
+ }
28
+
21
29
  return ResponseUtils.adaptListResponse(response, this.messageAdapter.adapt);
22
30
  }
23
31
 
@@ -28,31 +36,67 @@ export default class MessageRepository extends IMessageRepository {
28
36
 
29
37
  async sendMessage(request) {
30
38
  const response = await this.messageAPI.sendMessage(request);
39
+ const isOverridden = this.isMethodOverridden(this.customAPI, 'sendMessage');
40
+
41
+ if (isOverridden) {
42
+ return response;
43
+ }
44
+
31
45
  return ResponseUtils.adaptSingleResponse(response, this.messageAdapter.adapt);
32
46
  }
33
47
 
34
48
  async sendAttachment(request) {
35
49
  const response = await this.messageAPI.sendAttachment(request);
50
+ const isOverridden = this.isMethodOverridden(this.customAPI, 'sendAttachment');
51
+
52
+ if (isOverridden) {
53
+ return response;
54
+ }
55
+
36
56
  return ResponseUtils.adaptSingleResponse(response, this.messageAdapter.adapt);
37
57
  }
38
58
 
39
59
  async resendMessage(request) {
40
60
  const response = await this.messageAPI.resendMessage(request);
61
+ const isOverridden = this.isMethodOverridden(this.customAPI, 'resendMessage');
62
+
63
+ if (isOverridden) {
64
+ return response;
65
+ }
66
+
41
67
  return ResponseUtils.adaptSingleResponse(response, this.messageAdapter.adapt);
42
68
  }
43
69
 
44
70
  async deleteMessage(request) {
45
71
  const response = await this.messageAPI.deleteMessage(request);
72
+ const isOverridden = this.isMethodOverridden(this.customAPI, 'deleteMessage');
73
+
74
+ if (isOverridden) {
75
+ return response;
76
+ }
77
+
46
78
  return ResponseUtils.adaptSingleResponse(response, this.messageAdapter.adapt);
47
79
  }
48
80
 
49
81
  async initiateSession(request) {
50
82
  const response = await this.messageAPI.initiateSession(request);
83
+ const isOverridden = this.isMethodOverridden(this.customAPI, 'initiateSession');
84
+
85
+ if (isOverridden) {
86
+ return response;
87
+ }
88
+
51
89
  return ResponseUtils.adaptSingleResponse(response, this.messageAdapter.adapt);
52
90
  }
53
91
 
54
92
  async searchMessages(request) {
55
93
  const response = await this.messageAPI.searchMessages(request);
94
+ const isOverridden = this.isMethodOverridden(this.customAPI, 'searchMessages');
95
+
96
+ if (isOverridden) {
97
+ return response;
98
+ }
99
+
56
100
  return ResponseUtils.adaptListResponse(response, this.messageWithSessionAdapter.adapt);
57
101
  }
58
102
 
@@ -11,7 +11,9 @@ 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();
@@ -19,36 +21,78 @@ export default class SessionRepository extends ISessionRepository {
19
21
 
20
22
  async updateAssignee(request) {
21
23
  const response = await this.sessionAPI.updateAssignee(request);
24
+ const isOverridden = this.isMethodOverridden(this.customAPI, 'updateAssignee');
25
+
26
+ if (isOverridden) {
27
+ return response;
28
+ }
29
+
22
30
  return ResponseUtils.adaptSingleResponse(response, this.sessionAdapter.adapt);
23
31
  }
24
32
 
25
33
  async getSessions(request) {
26
34
  const response = await this.sessionAPI.getSessions(request);
35
+ const isOverridden = this.isMethodOverridden(this.customAPI, 'getSessions');
36
+
37
+ if (isOverridden) {
38
+ return response;
39
+ }
40
+
27
41
  return ResponseUtils.adaptListResponse(response, this.sessionAdapter.adapt);
28
42
  }
29
43
 
30
44
  async getSession(request) {
31
45
  const response = await this.sessionAPI.getSession(request);
46
+ const isOverridden = this.isMethodOverridden(this.customAPI, 'getSession');
47
+
48
+ if (isOverridden) {
49
+ return response;
50
+ }
51
+
32
52
  return ResponseUtils.adaptSingleResponse(response, this.sessionAdapter.adapt);
33
53
  }
34
54
 
35
55
  async getSessionAttachments(request) {
36
56
  const response = await this.sessionAPI.getSessionAttachments(request);
57
+ const isOverridden = this.isMethodOverridden(this.customAPI, 'getSessionAttachments');
58
+
59
+ if (isOverridden) {
60
+ return response;
61
+ }
62
+
37
63
  return ResponseUtils.adaptListResponse(response, this.attachmentAdapter.adapt);
38
64
  }
39
65
 
40
66
  async getSessionLastMessages(request) {
41
67
  const response = await this.sessionAPI.getSessionLastMessages(request);
68
+ const isOverridden = this.isMethodOverridden(this.customAPI, 'getSessionLastMessages');
69
+
70
+ if (isOverridden) {
71
+ return response;
72
+ }
73
+
42
74
  return ResponseUtils.adaptListResponse(response, this.messageAdapter.adapt);
43
75
  }
44
76
 
45
77
  async markSessionAsRead(request) {
46
78
  const response = await this.sessionAPI.markSessionAsRead(request);
79
+ const isOverridden = this.isMethodOverridden(this.customAPI, 'markSessionAsRead');
80
+
81
+ if (isOverridden) {
82
+ return response;
83
+ }
84
+
47
85
  return ResponseUtils.adaptSingleResponse(response, this.sessionAdapter.adapt);
48
86
  }
49
87
 
50
88
  async updateSessionStatus(request) {
51
89
  const response = await this.sessionAPI.updateSessionStatus(request);
90
+ const isOverridden = this.isMethodOverridden(this.customAPI, 'updateSessionStatus');
91
+
92
+ if (isOverridden) {
93
+ return response;
94
+ }
95
+
52
96
  return ResponseUtils.adaptSingleResponse(response, this.sessionAdapter.adapt);
53
97
  }
54
98
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohoim/client-sdk",
3
- "version": "1.0.0-poc62",
3
+ "version": "1.0.0-poc64",
4
4
  "description": "To have the client sdk for the IM",
5
5
  "main": "es/index.js",
6
6
  "module": "es/index.js",