@zohoim/client-sdk 1.0.0-poc10 → 1.0.0-poc11

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.
@@ -1,26 +1,25 @@
1
+ import { configRegistry } from '../../infrastructure/sdk/config';
1
2
  export default class BaseAPI {
2
- constructor(_ref) {
3
- let {
4
- httpClient
5
- } = _ref;
6
- this.httpClient = httpClient;
3
+ constructor() {
4
+ this.httpClient = configRegistry.getHttpClient();
5
+ this.baseURL = configRegistry.getBaseURL();
7
6
  }
8
7
 
9
8
  replacePathParams(url, params) {
10
9
  let _url = url;
11
- Object.entries(params).forEach(_ref2 => {
12
- let [key, value] = _ref2;
10
+ Object.entries(params).forEach(_ref => {
11
+ let [key, value] = _ref;
13
12
  _url = url.replace(`:${key}`, value);
14
13
  });
15
14
  return _url;
16
15
  }
17
16
 
18
- buildUrl(_ref3) {
17
+ buildUrl(_ref2) {
19
18
  let {
20
19
  url,
21
20
  params,
22
21
  query
23
- } = _ref3;
22
+ } = _ref2;
24
23
 
25
24
  const _url = this.replacePathParams(url, params);
26
25
 
@@ -30,18 +29,18 @@ export default class BaseAPI {
30
29
  return `${_url}?${queryString}`;
31
30
  }
32
31
 
33
- return _url;
32
+ return `${this.baseURL}${_url}`;
34
33
  }
35
34
 
36
35
  buildQuery(object) {
37
36
  return new URLSearchParams(object).toString();
38
37
  }
39
38
 
40
- async request(_ref4) {
39
+ async request(_ref3) {
41
40
  let {
42
41
  urlConfig,
43
42
  request
44
- } = _ref4;
43
+ } = _ref3;
45
44
  const url = this.buildUrl({
46
45
  url: urlConfig.url,
47
46
  params: request.params,
@@ -1,17 +1,8 @@
1
1
  import { GetChannelAgentsRequest } from '../../../infrastructure/interfaces/api';
2
2
  import BaseAPI from '../BaseAPI';
3
3
  export default class IChannelAgent extends BaseAPI {
4
- constructor(_ref) {
5
- let {
6
- httpClient
7
- } = _ref;
8
- super({
9
- httpClient
10
- });
11
- } // eslint-disable-next-line no-unused-vars
12
-
13
-
14
- getChannelAgents() {
4
+ // eslint-disable-next-line no-unused-vars
5
+ getAgents() {
15
6
  let request = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : GetChannelAgentsRequest;
16
7
  throw new Error('Method not implemented.');
17
8
  }
@@ -1,16 +1,7 @@
1
1
  import { UpdateSessionAssigneeRequest } from '../../../infrastructure/interfaces/api';
2
2
  import BaseAPI from '../BaseAPI';
3
3
  export default class ISession extends BaseAPI {
4
- constructor(_ref) {
5
- let {
6
- httpClient
7
- } = _ref;
8
- super({
9
- httpClient
10
- });
11
- } // eslint-disable-next-line no-unused-vars
12
-
13
-
4
+ // eslint-disable-next-line no-unused-vars
14
5
  updateAssignee() {
15
6
  let request = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : UpdateSessionAssigneeRequest;
16
7
  throw new Error('Method not implemented.');
@@ -7,20 +7,18 @@ export default class ChannelAgentService extends IChannelAgent {
7
7
  constructor(_ref) {
8
8
  let {
9
9
  channelAgentAPI,
10
- channelAgentAdapter,
11
- httpClient
10
+ channelAgentAdapter
12
11
  } = _ref;
13
12
  super();
14
13
  this.channelAgentAPI = channelAgentAPI || new ChannelAgentAPI({
15
- httpClient,
16
14
  urlConfig: CHANNEL_AGENTS_API_URLS
17
15
  });
18
16
  this.channelAgentAdapter = channelAgentAdapter || new ChannelAgentAdapter();
19
17
  }
20
18
 
21
- async getChannelAgents() {
19
+ async getAgents() {
22
20
  let request = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : GetChannelAgentsRequest;
23
- const channelAgents = await this.channelAgentAPI.getChannelAgents(request);
21
+ const channelAgents = await this.channelAgentAPI.getAgents(request);
24
22
  return channelAgents.map(this.channelAgentAdapter.adapt);
25
23
  }
26
24
 
@@ -7,12 +7,10 @@ export default class SessionService extends ISession {
7
7
  constructor(_ref) {
8
8
  let {
9
9
  sessionAPI,
10
- sessionAdapter,
11
- httpClient
10
+ sessionAdapter
12
11
  } = _ref;
13
12
  super();
14
13
  this.sessionAPI = sessionAPI || new SessionAPI({
15
- httpClient,
16
14
  urlConfig: SESSIONS_API_URLS
17
15
  });
18
16
  this.sessionAdapter = sessionAdapter || new SessionAdapter();
@@ -3,17 +3,13 @@ import { GetChannelAgentsRequest } from '../../interfaces/api';
3
3
  export default class ChannelAgentAPI extends IChannelAgent {
4
4
  constructor(_ref) {
5
5
  let {
6
- httpClient,
7
6
  urlConfig
8
7
  } = _ref;
9
- super({
10
- httpClient
11
- });
12
- this.httpClient = httpClient;
8
+ super();
13
9
  this.urlConfig = urlConfig;
14
10
  }
15
11
 
16
- async getChannelAgents() {
12
+ async getAgents() {
17
13
  let request = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : GetChannelAgentsRequest;
18
14
  const urlConfig = this.urlConfig.LIST;
19
15
  const httpRequest = await this.request({
@@ -3,12 +3,9 @@ import { UpdateSessionAssigneeRequest } from '../../interfaces/api';
3
3
  export default class SessionAPI extends ISession {
4
4
  constructor(_ref) {
5
5
  let {
6
- httpClient,
7
6
  urlConfig
8
7
  } = _ref;
9
- super({
10
- httpClient
11
- });
8
+ super();
12
9
  this.urlConfig = urlConfig;
13
10
  }
14
11
 
@@ -4,22 +4,18 @@ import { SessionSDK } from '../sdk/sessions';
4
4
  const ModuleFactory = {
5
5
  [ModuleNames.CHANNELS]: _ref => {
6
6
  let {
7
- config,
8
- httpClient
7
+ config
9
8
  } = _ref;
10
9
  return new ChannelSDK({
11
- config,
12
- httpClient
10
+ config
13
11
  });
14
12
  },
15
13
  [ModuleNames.SESSIONS]: _ref2 => {
16
14
  let {
17
- config,
18
- httpClient
15
+ config
19
16
  } = _ref2;
20
17
  return new SessionSDK({
21
- config,
22
- httpClient
18
+ config
23
19
  });
24
20
  }
25
21
  };
@@ -6,15 +6,13 @@ export default class ModuleManager {
6
6
 
7
7
  initialize(_ref) {
8
8
  let {
9
- config,
10
- httpClient
9
+ config
11
10
  } = _ref;
12
11
  Object.entries(config).forEach(_ref2 => {
13
12
  let [moduleName, moduleConfig] = _ref2;
14
13
  this.initializeModule({
15
14
  moduleName,
16
- config: moduleConfig,
17
- httpClient
15
+ config: moduleConfig
18
16
  });
19
17
  });
20
18
  }
@@ -22,15 +20,13 @@ export default class ModuleManager {
22
20
  initializeModule(_ref3) {
23
21
  let {
24
22
  moduleName,
25
- config,
26
- httpClient
23
+ config
27
24
  } = _ref3;
28
25
  const createModule = ModuleFactory[moduleName];
29
26
 
30
27
  if (createModule) {
31
28
  this._modules.set(moduleName, createModule({
32
- config,
33
- httpClient
29
+ config
34
30
  }));
35
31
  }
36
32
  }
@@ -1,11 +1,17 @@
1
1
  import { ModuleNames } from '../../core/constants';
2
2
  import { ModuleManager } from '../managers';
3
+ import { configRegistry } from './config';
3
4
  export default class IMSDK {
4
5
  constructor(_ref) {
5
6
  let {
7
+ baseURL,
6
8
  config = {},
7
9
  httpClient
8
10
  } = _ref;
11
+ configRegistry.setConfig({
12
+ baseURL,
13
+ httpClient
14
+ });
9
15
  this._moduleManager = new ModuleManager();
10
16
 
11
17
  this._moduleManager.initialize({
@@ -4,19 +4,17 @@ export default class ChannelAgentsSDK {
4
4
  constructor(_ref) {
5
5
  let {
6
6
  channelAgentAPI,
7
- channelAgentAdapter,
8
- httpClient
7
+ channelAgentAdapter
9
8
  } = _ref;
10
9
  this.channelAgentService = new ChannelAgentService({
11
10
  channelAgentAPI,
12
- channelAgentAdapter,
13
- httpClient
11
+ channelAgentAdapter
14
12
  });
15
13
  }
16
14
 
17
15
  async getAgents() {
18
16
  let request = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : GetChannelAgentsRequest;
19
- return this.channelAgentService.getChannelAgents(request);
17
+ return this.channelAgentService.getAgents(request);
20
18
  }
21
19
 
22
20
  }
@@ -2,8 +2,7 @@ import ChannelAgentsSDK from './ChannelAgentsSDK';
2
2
  export default class ChannelSDK {
3
3
  constructor(_ref) {
4
4
  let {
5
- config,
6
- httpClient
5
+ config
7
6
  } = _ref;
8
7
  const {
9
8
  channelAgentAPI,
@@ -11,8 +10,7 @@ export default class ChannelSDK {
11
10
  } = config;
12
11
  this.agents = new ChannelAgentsSDK({
13
12
  channelAgentAPI,
14
- channelAgentAdapter,
15
- httpClient
13
+ channelAgentAdapter
16
14
  });
17
15
  }
18
16
 
@@ -0,0 +1,27 @@
1
+ class ConfigRegistry {
2
+ constructor() {
3
+ this.baseURL = null;
4
+ this.httpClient = null;
5
+ }
6
+
7
+ setConfig(_ref) {
8
+ let {
9
+ baseURL,
10
+ httpClient
11
+ } = _ref;
12
+ this.baseURL = baseURL;
13
+ this.httpClient = httpClient;
14
+ }
15
+
16
+ getBaseURL() {
17
+ return this.baseURL;
18
+ }
19
+
20
+ getHttpClient() {
21
+ return this.httpClient;
22
+ }
23
+
24
+ }
25
+
26
+ const configRegistry = new ConfigRegistry();
27
+ export default configRegistry;
@@ -0,0 +1,2 @@
1
+ import configRegistry from './configRegistry';
2
+ export { configRegistry };
@@ -3,8 +3,7 @@ import { SessionService } from '../../../domain/services/sessions';
3
3
  class SessionSDK extends SessionService {
4
4
  constructor(_ref) {
5
5
  let {
6
- config,
7
- httpClient
6
+ config
8
7
  } = _ref;
9
8
  const {
10
9
  sessionAPI,
@@ -12,8 +11,7 @@ class SessionSDK extends SessionService {
12
11
  } = config;
13
12
  super({
14
13
  sessionAPI,
15
- sessionAdapter,
16
- httpClient
14
+ sessionAdapter
17
15
  });
18
16
  }
19
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohoim/client-sdk",
3
- "version": "1.0.0-poc10",
3
+ "version": "1.0.0-poc11",
4
4
  "description": "To have the client sdk for the IM",
5
5
  "main": "es/index.js",
6
6
  "module": "es/index.js",