@zohoim/client-sdk 1.0.0-poc33 → 1.0.0-poc35

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,15 @@
1
+ export default class ResponseUtils {
2
+ static adaptListResponse(response, adapter) {
3
+ if (!response) return response;
4
+ if (!response.data) return response;
5
+ return { ...response,
6
+ data: response.data.map(item => adapter(item))
7
+ };
8
+ }
9
+
10
+ static adaptSingleResponse(response, adapter) {
11
+ if (!response) return response;
12
+ return adapter(response);
13
+ }
14
+
15
+ }
@@ -1,2 +1,3 @@
1
+ import ResponseUtils from "./ResponseUtils";
1
2
  import { validateSchema } from "./validateSchema";
2
- export { validateSchema };
3
+ export { validateSchema, ResponseUtils };
@@ -1,5 +1,6 @@
1
1
  import { getUrlConfig } from "../../../config/urls";
2
2
  import { ModuleNames } from "../../../core/constants";
3
+ import { ResponseUtils } from "../../../core/utils";
3
4
  import { BotAdapter } from "../../../infrastructure/adapters";
4
5
  import { BotAPI } from "../../../infrastructure/api";
5
6
  import { IBot } from "../../interfaces";
@@ -18,8 +19,8 @@ export default class BotService extends IBot {
18
19
  }
19
20
 
20
21
  async getBots(request) {
21
- const bots = await this.botAPI.getBots(request);
22
- return bots.map(this.botAdapter.adapt);
22
+ const response = await this.botAPI.getBots(request);
23
+ return ResponseUtils.adaptListResponse(response, this.botAdapter.adapt);
23
24
  }
24
25
 
25
26
  toJSON() {
@@ -1,5 +1,6 @@
1
1
  import { getUrlConfig } from "../../../config/urls";
2
2
  import { ModuleNames } from "../../../core/constants";
3
+ import { ResponseUtils } from "../../../core/utils";
3
4
  import { ChannelAgentAdapter } from "../../../infrastructure/adapters";
4
5
  import { ChannelAgentAPI } from "../../../infrastructure/api";
5
6
  import { IChannelAgent } from "../../interfaces";
@@ -18,8 +19,8 @@ export default class ChannelAgentService extends IChannelAgent {
18
19
  }
19
20
 
20
21
  async getAgents(request) {
21
- const channelAgents = await this.channelAgentAPI.getAgents(request);
22
- return channelAgents.map(this.channelAgentAdapter.adapt);
22
+ const response = await this.channelAgentAPI.getAgents(request);
23
+ return ResponseUtils.adaptListResponse(response, this.channelAgentAdapter.adapt);
23
24
  }
24
25
 
25
26
  toJSON() {
@@ -1,5 +1,6 @@
1
1
  import { getUrlConfig } from "../../../config/urls";
2
2
  import { ModuleNames } from "../../../core/constants";
3
+ import { ResponseUtils } from "../../../core/utils";
3
4
  import { ChannelAdapter } from "../../../infrastructure/adapters";
4
5
  import { ChannelAPI } from "../../../infrastructure/api";
5
6
  import { IChannel } from "../../interfaces";
@@ -18,8 +19,8 @@ export default class ChannelService extends IChannel {
18
19
  }
19
20
 
20
21
  async getChannels(request) {
21
- const channels = await this.channelAPI.getChannels(request);
22
- return channels.map(channel => this.channelAdapter.adapt(channel));
22
+ const response = await this.channelAPI.getChannels(request);
23
+ return ResponseUtils.adaptListResponse(response, this.channelAdapter.adapt);
23
24
  }
24
25
 
25
26
  toJSON() {
@@ -1,5 +1,6 @@
1
1
  import { getUrlConfig } from "../../../config/urls";
2
2
  import { ModuleNames } from "../../../core/constants";
3
+ import { ResponseUtils } from "../../../core/utils";
3
4
  import { SessionAdapter } from "../../../infrastructure/adapters";
4
5
  import { SessionAPI } from "../../../infrastructure/api";
5
6
  import { ISession } from "../../interfaces";
@@ -18,8 +19,8 @@ export default class SessionService extends ISession {
18
19
  }
19
20
 
20
21
  async updateAssignee(request) {
21
- const session = await this.sessionAPI.updateAssignee(request);
22
- return this.sessionAdapter.adapt(session);
22
+ const response = await this.sessionAPI.updateAssignee(request);
23
+ return ResponseUtils.adaptSingleResponse(response, this.sessionAdapter.adapt);
23
24
  }
24
25
 
25
26
  toJSON() {
@@ -16,7 +16,7 @@ export default class ChannelAPI extends IChannel {
16
16
  urlConfig,
17
17
  request
18
18
  });
19
- return httpRequest.data || [];
19
+ return httpRequest;
20
20
  }
21
21
 
22
22
  }
@@ -24,7 +24,7 @@ export default class ChannelAgentAPI extends IChannelAgent {
24
24
  urlConfig,
25
25
  request
26
26
  });
27
- return httpRequest.data || [];
27
+ return httpRequest;
28
28
  }
29
29
 
30
30
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohoim/client-sdk",
3
- "version": "1.0.0-poc33",
3
+ "version": "1.0.0-poc35",
4
4
  "description": "To have the client sdk for the IM",
5
5
  "main": "es/index.js",
6
6
  "module": "es/index.js",