@zohoim/client-sdk 1.0.0-poc39 → 1.0.0-poc40

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 (33) hide show
  1. package/es/config/registry/bots/botAPIRegistry.js +12 -0
  2. package/es/config/registry/bots/constructBotEndPoint.js +10 -0
  3. package/es/config/registry/bots/index.js +2 -0
  4. package/es/config/registry/channels/channelAPIRegistry.js +16 -0
  5. package/es/config/registry/channels/channelAgentAPIRegistry.js +12 -0
  6. package/es/config/registry/channels/constructChannelEndPoint.js +10 -0
  7. package/es/config/registry/channels/index.js +2 -0
  8. package/es/config/registry/createAPIRegistry.js +7 -0
  9. package/es/config/registry/createBaseUrl.js +3 -0
  10. package/es/config/registry/getRegistryConfig.js +20 -0
  11. package/es/config/registry/index.js +2 -0
  12. package/es/config/registry/sessions/constructSessionEndPoint.js +10 -0
  13. package/es/config/registry/sessions/index.js +2 -0
  14. package/es/config/registry/sessions/sessionAPIRegistry.js +12 -0
  15. package/es/domain/interfaces/BaseAPI.js +28 -16
  16. package/es/domain/services/bots/BotService.js +1 -6
  17. package/es/domain/services/channels/ChannelAgentService.js +1 -6
  18. package/es/domain/services/channels/ChannelService.js +1 -6
  19. package/es/domain/services/sessions/SessionService.js +1 -6
  20. package/es/infrastructure/api/bots/BotAPI.js +8 -9
  21. package/es/infrastructure/api/channels/ChannelAPI.js +8 -9
  22. package/es/infrastructure/api/channels/ChannelAgentAPI.js +8 -9
  23. package/es/infrastructure/api/sessions/SessionAPI.js +8 -9
  24. package/package.json +1 -1
  25. package/es/config/urls/base/index.js +0 -11
  26. package/es/config/urls/bots/bots-api-url.js +0 -8
  27. package/es/config/urls/bots/index.js +0 -2
  28. package/es/config/urls/channels/channel-agents-api-url.js +0 -8
  29. package/es/config/urls/channels/channels-api-url.js +0 -8
  30. package/es/config/urls/channels/index.js +0 -3
  31. package/es/config/urls/index.js +0 -17
  32. package/es/config/urls/sessions/index.js +0 -2
  33. package/es/config/urls/sessions/sessions-api-url.js +0 -9
@@ -0,0 +1,12 @@
1
+ import { HTTP_METHODS } from "../../../core/constants";
2
+ import { getBotsRequest } from "../../../infrastructure/interfaces/api/bots";
3
+ import createAPIRegistry from "../createAPIRegistry";
4
+ import constructBotEndPoint from "./constructBotEndPoint";
5
+
6
+ function getBots() {
7
+ return createAPIRegistry(constructBotEndPoint(), HTTP_METHODS.GET, getBotsRequest());
8
+ }
9
+
10
+ export default {
11
+ getBots
12
+ };
@@ -0,0 +1,10 @@
1
+ import createBaseUrl from "../createBaseUrl";
2
+ export default function constructBotEndPoint(extra) {
3
+ const base = '/bots';
4
+
5
+ if (extra) {
6
+ return createBaseUrl(base + extra);
7
+ }
8
+
9
+ return createBaseUrl(base);
10
+ }
@@ -0,0 +1,2 @@
1
+ import botAPIRegistry from "./botAPIRegistry";
2
+ export { botAPIRegistry };
@@ -0,0 +1,16 @@
1
+ import { HTTP_METHODS } from "../../../core/constants";
2
+ import { getChannelsRequest } from "../../../infrastructure/interfaces/api/channels";
3
+ import createAPIRegistry from "../createAPIRegistry";
4
+ import channelAgentAPIRegistry from "./channelAgentAPIRegistry";
5
+ import constructChannelEndPoint from "./constructChannelEndPoint";
6
+
7
+ function getChannels() {
8
+ return createAPIRegistry(constructChannelEndPoint(), HTTP_METHODS.GET, getChannelsRequest());
9
+ }
10
+
11
+ const channelAPIRegistry = {
12
+ getChannels,
13
+ agents: { ...channelAgentAPIRegistry
14
+ }
15
+ };
16
+ export default channelAPIRegistry;
@@ -0,0 +1,12 @@
1
+ import { HTTP_METHODS } from "../../../core/constants";
2
+ import { getChannelAgentsRequest } from "../../../infrastructure/interfaces/api/channels";
3
+ import createAPIRegistry from "../createAPIRegistry";
4
+ import constructChannelEndPoint from "./constructChannelEndPoint";
5
+
6
+ function getAgents() {
7
+ return createAPIRegistry(constructChannelEndPoint('/:channelId/agents'), HTTP_METHODS.GET, getChannelAgentsRequest());
8
+ }
9
+
10
+ export default {
11
+ getAgents
12
+ };
@@ -0,0 +1,10 @@
1
+ import createBaseUrl from "../createBaseUrl";
2
+ export default function constructChannelEndPoint(extra) {
3
+ const base = '/channels';
4
+
5
+ if (extra) {
6
+ return createBaseUrl(base + extra);
7
+ }
8
+
9
+ return createBaseUrl(base);
10
+ }
@@ -0,0 +1,2 @@
1
+ import channelAPIRegistry from "./channelAPIRegistry";
2
+ export { channelAPIRegistry };
@@ -0,0 +1,7 @@
1
+ export default function createAPIRegistry(endpoint, method, requestDefinition) {
2
+ return {
3
+ endpoint,
4
+ method,
5
+ ...requestDefinition
6
+ };
7
+ }
@@ -0,0 +1,3 @@
1
+ export default function createBaseUrl(path) {
2
+ return `/api/v1${path}`;
3
+ }
@@ -0,0 +1,20 @@
1
+ import selectn from 'selectn';
2
+ import { channelAPIRegistry } from "./channels";
3
+ import { ModuleNames } from "../../core/constants";
4
+ import { sessionAPIRegistry } from "./sessions";
5
+ import { botAPIRegistry } from "./bots";
6
+ const APIRegistry = {
7
+ [ModuleNames.CHANNELS]: channelAPIRegistry,
8
+ [ModuleNames.SESSIONS]: sessionAPIRegistry,
9
+ [ModuleNames.BOTS]: botAPIRegistry
10
+ };
11
+ export default function getRegistryConfig(module, operation) {
12
+ const moduleConfig = selectn(module, APIRegistry);
13
+
14
+ if (!moduleConfig) {
15
+ return null;
16
+ }
17
+
18
+ const operationConfig = moduleConfig[operation];
19
+ return operationConfig ? operationConfig() : null;
20
+ }
@@ -0,0 +1,2 @@
1
+ import getRegistryConfig from "./getRegistryConfig";
2
+ export { getRegistryConfig };
@@ -0,0 +1,10 @@
1
+ import createBaseUrl from "../createBaseUrl";
2
+ export default function constructSessionEndPoint(extra) {
3
+ const base = '/sessions';
4
+
5
+ if (extra) {
6
+ return createBaseUrl(base + extra);
7
+ }
8
+
9
+ return createBaseUrl(base);
10
+ }
@@ -0,0 +1,2 @@
1
+ import sessionAPIRegistry from "./sessionAPIRegistry";
2
+ export { sessionAPIRegistry };
@@ -0,0 +1,12 @@
1
+ import { HTTP_METHODS } from "../../../core/constants";
2
+ import { updateSessionAssigneeRequest } from "../../../infrastructure/interfaces/api/sessions";
3
+ import createAPIRegistry from "../createAPIRegistry";
4
+ import constructSessionEndPoint from "./constructSessionEndPoint";
5
+
6
+ function updateAssignee() {
7
+ return createAPIRegistry(constructSessionEndPoint('/:sessionId'), HTTP_METHODS.PATCH, updateSessionAssigneeRequest());
8
+ }
9
+
10
+ export default {
11
+ updateAssignee
12
+ };
@@ -1,25 +1,30 @@
1
+ import { getRegistryConfig } from "../../config/registry";
1
2
  import { configRegistry } from "../../infrastructure/sdk/config";
2
3
  export default class BaseAPI {
3
- constructor() {
4
+ constructor(_ref) {
5
+ let {
6
+ module
7
+ } = _ref;
4
8
  this.httpClient = configRegistry.getHttpClient();
5
9
  this.baseURL = configRegistry.getBaseURL();
10
+ this.module = module;
6
11
  }
7
12
 
8
13
  replacePathParams(url, params) {
9
14
  let _url = url;
10
- Object.entries(params).forEach(_ref => {
11
- let [key, value] = _ref;
15
+ Object.entries(params).forEach(_ref2 => {
16
+ let [key, value] = _ref2;
12
17
  _url = url.replace(`:${key}`, value);
13
18
  });
14
19
  return _url;
15
20
  }
16
21
 
17
- buildUrl(_ref2) {
22
+ buildUrl(_ref3) {
18
23
  let {
19
24
  url,
20
25
  params,
21
26
  query
22
- } = _ref2;
27
+ } = _ref3;
23
28
 
24
29
  const _params = params || {};
25
30
 
@@ -41,31 +46,38 @@ export default class BaseAPI {
41
46
  }
42
47
 
43
48
  buildQuery(query) {
44
- const filteredQuery = Object.entries(query).filter(_ref3 => {
45
- let [, value] = _ref3;
49
+ const filteredQuery = Object.entries(query).filter(_ref4 => {
50
+ let [, value] = _ref4;
46
51
  return value !== undefined && value !== null && value !== '';
47
- }).reduce((acc, _ref4) => {
48
- let [key, value] = _ref4;
52
+ }).reduce((acc, _ref5) => {
53
+ let [key, value] = _ref5;
49
54
  acc[key] = value;
50
55
  return acc;
51
56
  }, {});
52
57
  return new URLSearchParams(filteredQuery).toString();
53
58
  }
54
59
 
55
- async request(_ref5) {
60
+ async request(_ref6) {
56
61
  let {
57
- urlConfig,
58
- request
59
- } = _ref5;
62
+ request,
63
+ operation,
64
+ header
65
+ } = _ref6;
66
+ const config = getRegistryConfig(this.module, operation);
67
+
68
+ if (!config) {
69
+ throw new Error(`Operation "${operation}" not found in registry for module "${this.module}"`);
70
+ }
71
+
60
72
  const url = this.buildUrl({
61
- url: urlConfig.url,
73
+ url: config.endpoint,
62
74
  params: request.params || {},
63
75
  query: request.query || {}
64
76
  });
65
77
  const httpRequest = await this.httpClient.request({
66
78
  url,
67
- method: urlConfig.method,
68
- header: urlConfig.header,
79
+ method: config.method,
80
+ header,
69
81
  payload: request.body || {}
70
82
  });
71
83
  return httpRequest;
@@ -1,5 +1,3 @@
1
- import { getUrlConfig } from "../../../config/urls";
2
- import { ModuleNames } from "../../../core/constants";
3
1
  import { ResponseUtils } from "../../../core/utils";
4
2
  import { BotAdapter } from "../../../infrastructure/adapters";
5
3
  import { BotAPI } from "../../../infrastructure/api";
@@ -11,10 +9,7 @@ export default class BotService extends IBot {
11
9
  botAdapter
12
10
  } = _ref;
13
11
  super();
14
- const urlConfig = getUrlConfig(ModuleNames.BOTS);
15
- this.botAPI = botAPI || new BotAPI({
16
- urlConfig
17
- });
12
+ this.botAPI = botAPI || new BotAPI();
18
13
  this.botAdapter = botAdapter || new BotAdapter();
19
14
  }
20
15
 
@@ -1,5 +1,3 @@
1
- import { getUrlConfig } from "../../../config/urls";
2
- import { ModuleNames } from "../../../core/constants";
3
1
  import { ResponseUtils } from "../../../core/utils";
4
2
  import { ChannelAgentAdapter } from "../../../infrastructure/adapters";
5
3
  import { ChannelAgentAPI } from "../../../infrastructure/api";
@@ -11,10 +9,7 @@ export default class ChannelAgentService extends IChannelAgent {
11
9
  channelAgentAdapter
12
10
  } = _ref;
13
11
  super();
14
- const urlConfig = getUrlConfig(`${ModuleNames.CHANNELS}.agents`);
15
- this.channelAgentAPI = channelAgentAPI || new ChannelAgentAPI({
16
- urlConfig
17
- });
12
+ this.channelAgentAPI = channelAgentAPI || new ChannelAgentAPI();
18
13
  this.channelAgentAdapter = channelAgentAdapter || new ChannelAgentAdapter();
19
14
  }
20
15
 
@@ -1,5 +1,3 @@
1
- import { getUrlConfig } from "../../../config/urls";
2
- import { ModuleNames } from "../../../core/constants";
3
1
  import { ResponseUtils } from "../../../core/utils";
4
2
  import { ChannelAdapter } from "../../../infrastructure/adapters";
5
3
  import { ChannelAPI } from "../../../infrastructure/api";
@@ -11,10 +9,7 @@ export default class ChannelService extends IChannel {
11
9
  channelAdapter
12
10
  } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
13
11
  super();
14
- const urlConfig = getUrlConfig(ModuleNames.CHANNELS);
15
- this.channelAPI = channelAPI || new ChannelAPI({
16
- urlConfig
17
- });
12
+ this.channelAPI = channelAPI || new ChannelAPI();
18
13
  this.channelAdapter = channelAdapter || new ChannelAdapter();
19
14
  }
20
15
 
@@ -1,5 +1,3 @@
1
- import { getUrlConfig } from "../../../config/urls";
2
- import { ModuleNames } from "../../../core/constants";
3
1
  import { ResponseUtils } from "../../../core/utils";
4
2
  import { SessionAdapter } from "../../../infrastructure/adapters";
5
3
  import { SessionAPI } from "../../../infrastructure/api";
@@ -11,10 +9,7 @@ export default class SessionService extends ISession {
11
9
  sessionAdapter
12
10
  } = _ref;
13
11
  super();
14
- const urlConfig = getUrlConfig(ModuleNames.SESSIONS);
15
- this.sessionAPI = sessionAPI || new SessionAPI({
16
- urlConfig
17
- });
12
+ this.sessionAPI = sessionAPI || new SessionAPI();
18
13
  this.sessionAdapter = sessionAdapter || new SessionAdapter();
19
14
  }
20
15
 
@@ -1,20 +1,19 @@
1
+ import { ModuleNames } from "../../../core/constants";
1
2
  import { IBot } from "../../../domain/interfaces";
2
3
  import { getBotsRequest } from "../../interfaces/api";
3
4
  export default class BotAPI extends IBot {
4
- constructor(_ref) {
5
- let {
6
- urlConfig
7
- } = _ref;
8
- super();
9
- this.urlConfig = urlConfig;
5
+ constructor() {
6
+ super({
7
+ module: ModuleNames.BOTS
8
+ });
10
9
  }
11
10
 
12
11
  async getBots() {
13
12
  let request = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getBotsRequest();
14
- const urlConfig = this.urlConfig.LIST;
13
+ const operation = 'getBots';
15
14
  const httpRequest = await this.request({
16
- urlConfig,
17
- request
15
+ request,
16
+ operation
18
17
  });
19
18
  return httpRequest;
20
19
  }
@@ -1,20 +1,19 @@
1
+ import { ModuleNames } from "../../../core/constants";
1
2
  import { IChannel } from "../../../domain/interfaces";
2
3
  import { getChannelsRequest } from "../../interfaces/api";
3
4
  export default class ChannelAPI extends IChannel {
4
- constructor(_ref) {
5
- let {
6
- urlConfig
7
- } = _ref;
8
- super();
9
- this.urlConfig = urlConfig;
5
+ constructor() {
6
+ super({
7
+ module: ModuleNames.CHANNELS
8
+ });
10
9
  }
11
10
 
12
11
  async getChannels() {
13
12
  let request = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getChannelsRequest();
14
- const urlConfig = this.urlConfig.LIST;
13
+ const operation = 'getChannels';
15
14
  const httpRequest = await this.request({
16
- urlConfig,
17
- request
15
+ request,
16
+ operation
18
17
  });
19
18
  return httpRequest;
20
19
  }
@@ -1,12 +1,11 @@
1
+ import { ModuleNames } from "../../../core/constants";
1
2
  import IChannelAgent from "../../../domain/interfaces/channels/IChannelAgent";
2
3
  import { getChannelAgentsRequest } from "../../interfaces/api";
3
4
  export default class ChannelAgentAPI extends IChannelAgent {
4
- constructor(_ref) {
5
- let {
6
- urlConfig
7
- } = _ref;
8
- super();
9
- this.urlConfig = urlConfig;
5
+ constructor() {
6
+ super({
7
+ module: `${ModuleNames.CHANNELS}.agents`
8
+ });
10
9
  }
11
10
 
12
11
  async getAgents() {
@@ -19,10 +18,10 @@ export default class ChannelAgentAPI extends IChannelAgent {
19
18
  request.query.searchStr = `*${encodeURIComponent(searchStr)}*`;
20
19
  }
21
20
 
22
- const urlConfig = this.urlConfig.LIST;
21
+ const operation = 'getAgents';
23
22
  const httpRequest = await this.request({
24
- urlConfig,
25
- request
23
+ request,
24
+ operation
26
25
  });
27
26
  return httpRequest;
28
27
  }
@@ -1,20 +1,19 @@
1
+ import { ModuleNames } from "../../../core/constants";
1
2
  import { ISession } from "../../../domain/interfaces";
2
3
  import { updateSessionAssigneeRequest } from "../../interfaces/api";
3
4
  export default class SessionAPI extends ISession {
4
- constructor(_ref) {
5
- let {
6
- urlConfig
7
- } = _ref;
8
- super();
9
- this.urlConfig = urlConfig;
5
+ constructor() {
6
+ super({
7
+ module: ModuleNames.SESSIONS
8
+ });
10
9
  }
11
10
 
12
11
  async updateAssignee() {
13
12
  let request = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : updateSessionAssigneeRequest();
14
- const urlConfig = this.urlConfig.UPDATE_SESSION_ASSIGNEE;
13
+ const operation = 'updateAssignee';
15
14
  const httpRequest = await this.request({
16
- urlConfig,
17
- request
15
+ request,
16
+ operation
18
17
  });
19
18
  return httpRequest;
20
19
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohoim/client-sdk",
3
- "version": "1.0.0-poc39",
3
+ "version": "1.0.0-poc40",
4
4
  "description": "To have the client sdk for the IM",
5
5
  "main": "es/index.js",
6
6
  "module": "es/index.js",
@@ -1,11 +0,0 @@
1
- import { IM_API_PREFIX } from "../../../core/constants";
2
-
3
- const createBaseUrl = path => `${IM_API_PREFIX}${path}`;
4
-
5
- const createEndpoint = (url, method, requestInterface) => ({
6
- url,
7
- method,
8
- ...requestInterface
9
- });
10
-
11
- export { createBaseUrl, createEndpoint };
@@ -1,8 +0,0 @@
1
- import { HTTP_METHODS } from "../../../core/constants";
2
- import { getBotsRequest } from "../../../infrastructure/interfaces/api";
3
- import { createBaseUrl, createEndpoint } from "../base";
4
- const BASE_URL = createBaseUrl('/bots');
5
- const BOTS_API_URLS = {
6
- LIST: createEndpoint(BASE_URL, HTTP_METHODS.GET, getBotsRequest())
7
- };
8
- export default BOTS_API_URLS;
@@ -1,2 +0,0 @@
1
- import BOTS_API_URLS from "./bots-api-url";
2
- export { BOTS_API_URLS };
@@ -1,8 +0,0 @@
1
- import { HTTP_METHODS } from "../../../core/constants";
2
- import { getChannelAgentsRequest } from "../../../infrastructure/interfaces/api";
3
- import { createBaseUrl, createEndpoint } from "../base";
4
- const BASE_URL = createBaseUrl('/channels/:channelId/agents');
5
- const CHANNEL_AGENTS_API_URLS = {
6
- LIST: createEndpoint(BASE_URL, HTTP_METHODS.GET, getChannelAgentsRequest())
7
- };
8
- export default CHANNEL_AGENTS_API_URLS;
@@ -1,8 +0,0 @@
1
- import { HTTP_METHODS } from "../../../core/constants";
2
- import { getChannelsRequest } from "../../../infrastructure/interfaces/api";
3
- import { createBaseUrl, createEndpoint } from "../base";
4
- const BASE_URL = createBaseUrl('/channels');
5
- const CHANNELS_API_URLS = {
6
- LIST: createEndpoint(BASE_URL, HTTP_METHODS.GET, getChannelsRequest())
7
- };
8
- export default CHANNELS_API_URLS;
@@ -1,3 +0,0 @@
1
- import CHANNEL_AGENTS_API_URLS from "./channel-agents-api-url";
2
- import CHANNELS_API_URLS from "./channels-api-url";
3
- export { CHANNELS_API_URLS, CHANNEL_AGENTS_API_URLS };
@@ -1,17 +0,0 @@
1
- import { ModuleNames } from "../../core/constants";
2
- import { BOTS_API_URLS } from "./bots";
3
- import { CHANNEL_AGENTS_API_URLS, CHANNELS_API_URLS } from "./channels";
4
- import { SESSIONS_API_URLS } from "./sessions";
5
- import selectn from 'selectn';
6
- const urlMapping = {
7
- [ModuleNames.BOTS]: BOTS_API_URLS,
8
- [ModuleNames.CHANNELS]: {
9
- agents: CHANNEL_AGENTS_API_URLS,
10
- ...CHANNELS_API_URLS
11
- },
12
- [ModuleNames.SESSIONS]: SESSIONS_API_URLS
13
- };
14
- export function getUrlConfig(module) {
15
- const urlConfig = selectn(module, urlMapping) || {};
16
- return urlConfig;
17
- }
@@ -1,2 +0,0 @@
1
- import SESSIONS_API_URLS from "./sessions-api-url";
2
- export { SESSIONS_API_URLS };
@@ -1,9 +0,0 @@
1
- import { updateSessionAssigneeRequest } from "../../../infrastructure/interfaces/api";
2
- import { HTTP_METHODS } from "../../../core/constants";
3
- import { createBaseUrl, createEndpoint } from "../base";
4
- const BASE_URL = createBaseUrl('/sessions');
5
- const SINGLE_SESSION_URL = `${BASE_URL}/:sessionId`;
6
- const SESSIONS_API_URLS = {
7
- UPDATE_SESSION_ASSIGNEE: createEndpoint(SINGLE_SESSION_URL, HTTP_METHODS.PATCH, updateSessionAssigneeRequest())
8
- };
9
- export default SESSIONS_API_URLS;