@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.
- package/es/config/urls/channels/index.js +2 -0
- package/es/config/urls/channels/urls-channel-agents.js +11 -0
- package/es/core/constants/HttpMethods.js +8 -0
- package/es/core/constants/index.js +3 -1
- package/es/core/errors/AdapterError.js +7 -0
- package/es/core/errors/index.js +3 -0
- package/es/domain/entities/Agent/Agent.js +1 -1
- package/es/domain/interfaces/BaseAPI.js +33 -0
- package/es/domain/interfaces/channels/IChannelAgent.js +3 -2
- package/es/domain/services/channels/ChannelAgentService.js +16 -5
- package/es/index.js +4 -1
- package/es/infrastructure/adapters/BaseAdapter.js +23 -0
- package/es/infrastructure/adapters/channels/ChannelAgentAdapter.js +35 -0
- package/es/infrastructure/adapters/channels/index.js +2 -0
- package/es/infrastructure/api/channels/ChannelAgentAPI.js +25 -0
- package/es/infrastructure/api/channels/index.js +2 -0
- package/es/infrastructure/api/index.js +1 -0
- package/es/infrastructure/interfaces/api/channels/agents/GetChannelAgentsRequest.js +13 -0
- package/es/infrastructure/interfaces/api/channels/index.js +1 -0
- package/es/infrastructure/interfaces/api/index.js +1 -0
- package/es/infrastructure/interfaces/index.js +1 -0
- package/es/infrastructure/managers/ModuleFactory.js +15 -0
- package/es/infrastructure/managers/ModuleManager.js +46 -0
- package/es/{sdk → infrastructure/sdk}/IMSDK.js +10 -4
- package/es/{modules/channels/sdk → infrastructure/sdk/channels}/ChannelAgentsSDK.js +12 -3
- package/es/infrastructure/sdk/channels/ChannelSDK.js +19 -0
- package/package.json +1 -1
- package/es/domain/errors/index.js +0 -2
- package/es/domain/types/channels/GetChannelAgentsRequest.js +0 -7
- package/es/managers/ModuleFactor.js +0 -6
- package/es/managers/ModuleManager.js +0 -30
- package/es/modules/channels/index.js +0 -1
- package/es/modules/channels/sdk/ChannelSDK.js +0 -7
- /package/es/{domain/types → config/urls}/index.js +0 -0
- /package/es/{domain → core}/errors/ValidationError.js +0 -0
- /package/es/{modules → infrastructure/adapters}/index.js +0 -0
- /package/es/{domain/types/channels → infrastructure/interfaces/api/channels/agents}/index.js +0 -0
- /package/es/{managers → infrastructure/managers}/index.js +0 -0
- /package/es/{modules/channels/sdk → infrastructure/sdk/channels}/index.js +0 -0
- /package/es/{sdk → infrastructure/sdk}/index.js +0 -0
|
@@ -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,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 '
|
|
2
|
-
|
|
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(
|
|
6
|
+
constructor(_ref) {
|
|
7
|
+
let {
|
|
8
|
+
channelAgentAPI,
|
|
9
|
+
channelAgentAdapter,
|
|
10
|
+
httpClient
|
|
11
|
+
} = _ref;
|
|
5
12
|
super();
|
|
6
|
-
|
|
7
|
-
this.
|
|
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.
|
|
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,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 @@
|
|
|
1
|
+
export * from './channels';
|
|
@@ -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 '
|
|
1
|
+
import { ModuleNames } from '../../core/constants';
|
|
2
2
|
import { ModuleManager } from '../managers';
|
|
3
3
|
export default class IMSDK {
|
|
4
|
-
constructor() {
|
|
5
|
-
let
|
|
4
|
+
constructor(_ref) {
|
|
5
|
+
let {
|
|
6
|
+
config = {},
|
|
7
|
+
httpClient
|
|
8
|
+
} = _ref;
|
|
6
9
|
this._moduleManager = new ModuleManager();
|
|
7
10
|
|
|
8
|
-
this._moduleManager.initialize(
|
|
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 '
|
|
2
|
+
import { GetChannelAgentsRequest } from '../../interfaces/api';
|
|
3
3
|
export default class ChannelAgentsSDK {
|
|
4
|
-
constructor(
|
|
5
|
-
|
|
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,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';
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/es/{domain/types/channels → infrastructure/interfaces/api/channels/agents}/index.js
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|