@zohoim/client-sdk 1.0.0-poc8 → 1.0.0-poc9

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 (40) hide show
  1. package/es/config/urls/channels/index.js +2 -0
  2. package/es/config/urls/channels/urls-channel-agents.js +11 -0
  3. package/es/core/constants/HttpMethods.js +8 -0
  4. package/es/core/constants/index.js +3 -1
  5. package/es/core/errors/AdapterError.js +7 -0
  6. package/es/core/errors/index.js +3 -0
  7. package/es/domain/entities/Agent/Agent.js +1 -1
  8. package/es/domain/interfaces/BaseAPI.js +33 -0
  9. package/es/domain/interfaces/channels/IChannelAgent.js +3 -2
  10. package/es/domain/services/channels/ChannelAgentService.js +16 -5
  11. package/es/index.js +4 -1
  12. package/es/infrastructure/adapters/BaseAdapter.js +23 -0
  13. package/es/infrastructure/adapters/channels/ChannelAgentAdapter.js +35 -0
  14. package/es/infrastructure/adapters/channels/index.js +2 -0
  15. package/es/infrastructure/api/channels/ChannelAgentAPI.js +25 -0
  16. package/es/infrastructure/api/channels/index.js +2 -0
  17. package/es/infrastructure/api/index.js +1 -0
  18. package/es/infrastructure/interfaces/api/channels/agents/GetChannelAgentsRequest.js +13 -0
  19. package/es/infrastructure/interfaces/api/channels/index.js +1 -0
  20. package/es/infrastructure/interfaces/api/index.js +1 -0
  21. package/es/infrastructure/interfaces/index.js +1 -0
  22. package/es/infrastructure/managers/ModuleFactory.js +15 -0
  23. package/es/infrastructure/managers/ModuleManager.js +46 -0
  24. package/es/{sdk → infrastructure/sdk}/IMSDK.js +10 -4
  25. package/es/{modules/channels/sdk → infrastructure/sdk/channels}/ChannelAgentsSDK.js +12 -3
  26. package/es/infrastructure/sdk/channels/ChannelSDK.js +19 -0
  27. package/package.json +1 -1
  28. package/es/domain/errors/index.js +0 -2
  29. package/es/domain/types/channels/GetChannelAgentsRequest.js +0 -7
  30. package/es/managers/ModuleFactor.js +0 -6
  31. package/es/managers/ModuleManager.js +0 -30
  32. package/es/modules/channels/index.js +0 -1
  33. package/es/modules/channels/sdk/ChannelSDK.js +0 -7
  34. /package/es/{domain/types → config/urls}/index.js +0 -0
  35. /package/es/{domain → core}/errors/ValidationError.js +0 -0
  36. /package/es/{modules → infrastructure/adapters}/index.js +0 -0
  37. /package/es/{domain/types/channels → infrastructure/interfaces/api/channels/agents}/index.js +0 -0
  38. /package/es/{managers → infrastructure/managers}/index.js +0 -0
  39. /package/es/{modules/channels/sdk → infrastructure/sdk/channels}/index.js +0 -0
  40. /package/es/{sdk → infrastructure/sdk}/index.js +0 -0
@@ -0,0 +1,2 @@
1
+ import CHANNEL_AGENTS_URLS from './urls-channel-agents';
2
+ export { CHANNEL_AGENTS_URLS };
@@ -0,0 +1,11 @@
1
+ import { HTTP_METHODS, IM_API_PREFIX } from '../../../core/constants';
2
+ import { GetChannelAgentsRequest } from '../../../infrastructure/interfaces/api';
3
+ const BASE_URL = `${IM_API_PREFIX}/channels/:channelId/agents`;
4
+ const CHANNEL_AGENTS_URLS = {
5
+ LIST: {
6
+ url: BASE_URL,
7
+ method: HTTP_METHODS.GET,
8
+ ...GetChannelAgentsRequest
9
+ }
10
+ };
11
+ export default CHANNEL_AGENTS_URLS;
@@ -0,0 +1,8 @@
1
+ const HTTP_METHODS = {
2
+ GET: 'GET',
3
+ POST: 'POST',
4
+ PUT: 'PUT',
5
+ PATCH: 'PATCH',
6
+ DELETE: 'DELETE'
7
+ };
8
+ export default HTTP_METHODS;
@@ -1,2 +1,4 @@
1
+ import HTTP_METHODS from './HTTPMethods';
1
2
  import ModuleNames from './ModuleNames';
2
- export { ModuleNames };
3
+ const IM_API_PREFIX = '/api/v1';
4
+ export { ModuleNames, IM_API_PREFIX, HTTP_METHODS };
@@ -0,0 +1,7 @@
1
+ export default class AdapterError extends Error {
2
+ constructor(message) {
3
+ super(message);
4
+ this.name = 'AdapterError';
5
+ }
6
+
7
+ }
@@ -0,0 +1,3 @@
1
+ import AdapterError from './AdapterError';
2
+ import ValidationError from './ValidationError';
3
+ export { ValidationError, AdapterError };
@@ -1,4 +1,4 @@
1
- import { ValidationError } from '../../errors';
1
+ import { ValidationError } from '../../../core/errors';
2
2
  import ActorType from '../Actor/ActorType';
3
3
  export default class Agent {
4
4
  constructor() {
@@ -0,0 +1,33 @@
1
+ export default class BaseAPI {
2
+ replacePathParams(url, params) {
3
+ let _url = url;
4
+ Object.entries(params).forEach(_ref => {
5
+ let [key, value] = _ref;
6
+ _url = url.replace(`:${key}`, value);
7
+ });
8
+ return _url;
9
+ }
10
+
11
+ buildUrl(_ref2) {
12
+ let {
13
+ url,
14
+ params,
15
+ query
16
+ } = _ref2;
17
+
18
+ const _url = this.replacePathParams(url, params);
19
+
20
+ const queryString = this.buildQuery(query);
21
+
22
+ if (queryString) {
23
+ return `${_url}?${queryString}`;
24
+ }
25
+
26
+ return _url;
27
+ }
28
+
29
+ buildQuery(object) {
30
+ return new URLSearchParams(object).toString();
31
+ }
32
+
33
+ }
@@ -1,5 +1,6 @@
1
- import GetChannelAgentsRequest from '../../types/channels/GetChannelAgentsRequest';
2
- export default class IChannelAgent {
1
+ import { GetChannelAgentsRequest } from '../../../infrastructure/interfaces/api';
2
+ import BaseAPI from '../BaseAPI';
3
+ export default class IChannelAgent extends BaseAPI {
3
4
  // eslint-disable-next-line no-unused-vars
4
5
  getChannelAgents() {
5
6
  let request = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : GetChannelAgentsRequest;
@@ -1,15 +1,26 @@
1
+ import { ChannelAgentAdapter } from '../../../infrastructure/adapters';
2
+ import { ChannelAgentAPI } from '../../../infrastructure/api';
3
+ import { GetChannelAgentsRequest } from '../../../infrastructure/interfaces/api';
1
4
  import IChannelAgent from '../../interfaces/channels/IChannelAgent';
2
- import GetChannelAgentsRequest from '../../types/channels/GetChannelAgentsRequest';
3
5
  export default class ChannelAgentService extends IChannelAgent {
4
- constructor(channelAPI, channelAgentAdapter) {
6
+ constructor(_ref) {
7
+ let {
8
+ channelAgentAPI,
9
+ channelAgentAdapter,
10
+ httpClient
11
+ } = _ref;
5
12
  super();
6
- this.channelAPI = channelAPI;
7
- this.channelAgentAdapter = channelAgentAdapter;
13
+ const urlConfig = GetChannelAgentsRequest;
14
+ this.channelAgentAPI = channelAgentAPI || new ChannelAgentAPI({
15
+ httpClient,
16
+ urlConfig
17
+ });
18
+ this.channelAgentAdapter = channelAgentAdapter || new ChannelAgentAdapter();
8
19
  }
9
20
 
10
21
  async getChannelAgents() {
11
22
  let request = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : GetChannelAgentsRequest;
12
- const channelAgents = await this.channelAPI.getChannelAgents(request);
23
+ const channelAgents = await this.channelAgentAPI.getChannelAgents(request);
13
24
  return channelAgents.map(this.channelAgentAdapter.adapt);
14
25
  }
15
26
 
package/es/index.js CHANGED
@@ -1,4 +1,7 @@
1
1
  export * from './domain/entities';
2
2
  export * from './domain/interfaces';
3
3
  export * from './domain/services';
4
- export * from './sdk';
4
+ export * from './infrastructure/sdk';
5
+ export * from './infrastructure/adapters';
6
+ export * from './infrastructure/api';
7
+ export * from './infrastructure/interfaces/api';
@@ -0,0 +1,23 @@
1
+ import { AdapterError } from '../../core/errors';
2
+ /**
3
+ * Base adapter class that defines the contract for all adapters
4
+ * @abstract
5
+ */
6
+
7
+ export default class BaseAdapter {
8
+ /**
9
+ * Adapts the input data to required format
10
+ * @param {*} data - Data to adapt
11
+ * @throws {AdapterError} When method is not implemented
12
+ */
13
+ adapt(data) {
14
+ if (this.constructor === BaseAdapter) {
15
+ throw new AdapterError(`${this.constructor.name}: adapt() must be implemented by subclass`);
16
+ }
17
+
18
+ if (!data) {
19
+ throw new AdapterError(`${this.constructor.name}: data parameter is required`);
20
+ }
21
+ }
22
+
23
+ }
@@ -0,0 +1,35 @@
1
+ import BaseAdapter from '../BaseAdapter';
2
+ import { AdapterError } from '../../../core/errors';
3
+ import { Agent } from '../../../domain/entities';
4
+ /**
5
+ * Adapter for Channel Agent data
6
+ * @extends BaseAdapter
7
+ */
8
+
9
+ export default class ChannelAgentAdapter extends BaseAdapter {
10
+ /**
11
+ * Adapts channel agent data to Agent entity
12
+ * @param {Object} channelAgent - Channel agent data to adapt
13
+ * @returns {Object} Adapted agent data
14
+ * @throws {AdapterError} When adaptation fails
15
+ */
16
+ static adapt(channelAgent) {
17
+ if (!channelAgent) {
18
+ throw new AdapterError('Channel agent data is required');
19
+ }
20
+
21
+ try {
22
+ return new Agent({
23
+ id: channelAgent.id,
24
+ name: channelAgent.name,
25
+ email: channelAgent.email,
26
+ photoURL: channelAgent.photoURL || '',
27
+ zuid: channelAgent.zuid,
28
+ type: channelAgent.type
29
+ }).toJSON();
30
+ } catch (error) {
31
+ throw new AdapterError(`Failed to adapt channel agent: ${error.message}`);
32
+ }
33
+ }
34
+
35
+ }
@@ -0,0 +1,2 @@
1
+ import ChannelAgentAdapter from './ChannelAgentAdapter';
2
+ export { ChannelAgentAdapter };
@@ -0,0 +1,25 @@
1
+ import IChannelAgent from '../../../domain/interfaces/channels/IChannelAgent';
2
+ import { GetChannelAgentsRequest } from '../../interfaces/api';
3
+ export default class ChannelAgentAPI extends IChannelAgent {
4
+ constructor(_ref) {
5
+ let {
6
+ httpClient,
7
+ urlConfig
8
+ } = _ref;
9
+ super();
10
+ this.httpClient = httpClient;
11
+ this.urlConfig = urlConfig;
12
+ }
13
+
14
+ async getChannelAgents() {
15
+ let request = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : GetChannelAgentsRequest;
16
+ const url = this.buildUrl(this.urlConfig.url, request.params, request.query);
17
+ const httpRequest = await this.httpClient.request({
18
+ url,
19
+ method: this.urlConfig.method,
20
+ header: this.urlConfig.header
21
+ });
22
+ return httpRequest;
23
+ }
24
+
25
+ }
@@ -0,0 +1,2 @@
1
+ import ChannelAgentAPI from './ChannelAgentAPI';
2
+ export { ChannelAgentAPI };
@@ -0,0 +1 @@
1
+ export * from './channels';
@@ -0,0 +1,13 @@
1
+ const params = {
2
+ channelId: ''
3
+ };
4
+ const query = {
5
+ from: 0,
6
+ limit: 10,
7
+ searchStr: ''
8
+ };
9
+ const GetChannelAgentsRequest = {
10
+ params,
11
+ query
12
+ };
13
+ export default GetChannelAgentsRequest;
@@ -0,0 +1 @@
1
+ export * from './agents';
@@ -0,0 +1 @@
1
+ export * from './channels';
@@ -0,0 +1 @@
1
+ export * from './api';
@@ -0,0 +1,15 @@
1
+ import { ModuleNames } from '../../core/constants';
2
+ import { ChannelSDK } from '../sdk/channels';
3
+ const ModuleFactory = {
4
+ [ModuleNames.CHANNELS]: _ref => {
5
+ let {
6
+ config,
7
+ httpClient
8
+ } = _ref;
9
+ return new ChannelSDK({
10
+ config,
11
+ httpClient
12
+ });
13
+ }
14
+ };
15
+ export default ModuleFactory;
@@ -0,0 +1,46 @@
1
+ import ModuleFactory from './ModuleFactory';
2
+ export default class ModuleManager {
3
+ constructor() {
4
+ this._modules = new Map();
5
+ }
6
+
7
+ initialize(_ref) {
8
+ let {
9
+ config,
10
+ httpClient
11
+ } = _ref;
12
+ Object.entries(config).forEach(_ref2 => {
13
+ let [moduleName, moduleConfig] = _ref2;
14
+ this.initializeModule({
15
+ moduleName,
16
+ config: moduleConfig,
17
+ httpClient
18
+ });
19
+ });
20
+ }
21
+
22
+ initializeModule(_ref3) {
23
+ let {
24
+ moduleName,
25
+ config,
26
+ httpClient
27
+ } = _ref3;
28
+ const createModule = ModuleFactory[moduleName];
29
+
30
+ if (createModule) {
31
+ this._modules.set(moduleName, createModule({
32
+ config,
33
+ httpClient
34
+ }));
35
+ }
36
+ }
37
+
38
+ getModule(moduleName) {
39
+ return this._modules.get(moduleName);
40
+ }
41
+
42
+ hasModule(moduleName) {
43
+ return this._modules.has(moduleName);
44
+ }
45
+
46
+ }
@@ -1,11 +1,17 @@
1
- import { ModuleNames } from '../core/constants';
1
+ import { ModuleNames } from '../../core/constants';
2
2
  import { ModuleManager } from '../managers';
3
3
  export default class IMSDK {
4
- constructor() {
5
- let config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
4
+ constructor(_ref) {
5
+ let {
6
+ config = {},
7
+ httpClient
8
+ } = _ref;
6
9
  this._moduleManager = new ModuleManager();
7
10
 
8
- this._moduleManager.initialize(config);
11
+ this._moduleManager.initialize({
12
+ config,
13
+ httpClient
14
+ });
9
15
  }
10
16
 
11
17
  get channels() {
@@ -1,8 +1,17 @@
1
1
  import { ChannelAgentService } from '../../../domain/services';
2
- import { GetChannelAgentsRequest } from '../../../domain/types';
2
+ import { GetChannelAgentsRequest } from '../../interfaces/api';
3
3
  export default class ChannelAgentsSDK {
4
- constructor(agentAPI, agentAdapter) {
5
- this.channelAgentService = new ChannelAgentService(agentAPI, agentAdapter);
4
+ constructor(_ref) {
5
+ let {
6
+ channelAgentAPI,
7
+ channelAgentAdapter,
8
+ httpClient
9
+ } = _ref;
10
+ this.channelAgentService = new ChannelAgentService({
11
+ channelAgentAPI,
12
+ channelAgentAdapter,
13
+ httpClient
14
+ });
6
15
  }
7
16
 
8
17
  async getAgents() {
@@ -0,0 +1,19 @@
1
+ import ChannelAgentsSDK from './ChannelAgentsSDK';
2
+ export default class ChannelSDK {
3
+ constructor(_ref) {
4
+ let {
5
+ config,
6
+ httpClient
7
+ } = _ref;
8
+ const {
9
+ channelAgentAPI,
10
+ channelAgentAdapter
11
+ } = config;
12
+ this.agents = new ChannelAgentsSDK({
13
+ channelAgentAPI,
14
+ channelAgentAdapter,
15
+ httpClient
16
+ });
17
+ }
18
+
19
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohoim/client-sdk",
3
- "version": "1.0.0-poc8",
3
+ "version": "1.0.0-poc9",
4
4
  "description": "To have the client sdk for the IM",
5
5
  "main": "es/index.js",
6
6
  "module": "es/index.js",
@@ -1,2 +0,0 @@
1
- import ValidationError from './ValidationError';
2
- export { ValidationError };
@@ -1,7 +0,0 @@
1
- const GetChannelAgentsRequest = {
2
- channelId: '',
3
- from: 0,
4
- limit: 20,
5
- searchStr: ''
6
- };
7
- export default GetChannelAgentsRequest;
@@ -1,6 +0,0 @@
1
- import { ModuleNames } from '../core/constants';
2
- import { ChannelSDK } from '../modules';
3
- const ModuleFactory = {
4
- [ModuleNames.CHANNELS]: config => new ChannelSDK(config)
5
- };
6
- export default ModuleFactory;
@@ -1,30 +0,0 @@
1
- import ModuleFactory from './ModuleFactor';
2
- export default class ModuleManager {
3
- constructor() {
4
- this._modules = new Map();
5
- }
6
-
7
- initialize(config) {
8
- Object.entries(config).forEach(_ref => {
9
- let [moduleName, moduleConfig] = _ref;
10
- this.initializeModule(moduleName, moduleConfig);
11
- });
12
- }
13
-
14
- initializeModule(moduleName, config) {
15
- const createModule = ModuleFactory[moduleName];
16
-
17
- if (createModule) {
18
- this._modules.set(moduleName, createModule(config));
19
- }
20
- }
21
-
22
- getModule(moduleName) {
23
- return this._modules.get(moduleName);
24
- }
25
-
26
- hasModule(moduleName) {
27
- return this._modules.has(moduleName);
28
- }
29
-
30
- }
@@ -1 +0,0 @@
1
- export * from './sdk';
@@ -1,7 +0,0 @@
1
- import ChannelAgentsSDK from './ChannelAgentsSDK';
2
- export default class ChannelSDK {
3
- constructor(config) {
4
- this.agents = new ChannelAgentsSDK(config.agentAPI, config.agentAdapter);
5
- }
6
-
7
- }
File without changes
File without changes
File without changes