@zohoim/client-sdk 1.0.0-poc30 → 1.0.0-poc32
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/channels-api-url.js +8 -0
- package/es/config/urls/channels/index.js +2 -1
- package/es/config/urls/index.js +3 -2
- package/es/domain/entities/Channel/Channel.js +38 -0
- package/es/domain/entities/Channel/index.js +2 -0
- package/es/domain/entities/index.js +2 -1
- package/es/domain/interfaces/channels/IChannel.js +10 -0
- package/es/domain/interfaces/channels/index.js +2 -1
- package/es/domain/schema/channel/ChannelSchema.js +49 -0
- package/es/domain/schema/channel/index.js +2 -0
- package/es/domain/schema/index.js +3 -1
- package/es/domain/schema/integrationService/IntegrationServiceSchema.js +31 -0
- package/es/domain/schema/integrationService/index.js +2 -0
- package/es/domain/services/bots/BotService.js +1 -3
- package/es/domain/services/channels/ChannelAgentService.js +1 -3
- package/es/domain/services/channels/ChannelService.js +31 -0
- package/es/domain/services/channels/index.js +2 -1
- package/es/domain/services/sessions/SessionService.js +1 -3
- package/es/infrastructure/adapters/bots/BotAdapter.js +1 -1
- package/es/infrastructure/adapters/channels/ChannelAdapter.js +29 -0
- package/es/infrastructure/adapters/channels/ChannelAgentAdapter.js +1 -1
- package/es/infrastructure/adapters/channels/index.js +2 -1
- package/es/infrastructure/adapters/sessions/SessionAdapter.js +1 -1
- package/es/infrastructure/api/channels/ChannelAPI.js +22 -0
- package/es/infrastructure/api/channels/ChannelAgentAPI.js +9 -1
- package/es/infrastructure/api/channels/index.js +2 -1
- package/es/infrastructure/interfaces/api/bots/getBotsRequest.js +1 -0
- package/es/infrastructure/interfaces/api/channels/getChannelsRequest.js +27 -0
- package/es/infrastructure/interfaces/api/channels/index.js +3 -1
- package/es/infrastructure/interfaces/api/sessions/updateSessionAssigneeRequest.js +1 -1
- package/es/infrastructure/sdk/channels/ChannelSDK.js +12 -5
- package/package.json +1 -1
|
@@ -0,0 +1,8 @@
|
|
|
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;
|
package/es/config/urls/index.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { ModuleNames } from "../../core/constants";
|
|
2
2
|
import { BOTS_API_URLS } from "./bots";
|
|
3
|
-
import { CHANNEL_AGENTS_API_URLS } from "./channels";
|
|
3
|
+
import { CHANNEL_AGENTS_API_URLS, CHANNELS_API_URLS } from "./channels";
|
|
4
4
|
import { SESSIONS_API_URLS } from "./sessions";
|
|
5
5
|
import selectn from 'selectn';
|
|
6
6
|
const urlMapping = {
|
|
7
7
|
[ModuleNames.BOTS]: BOTS_API_URLS,
|
|
8
8
|
[ModuleNames.CHANNELS]: {
|
|
9
|
-
agents: CHANNEL_AGENTS_API_URLS
|
|
9
|
+
agents: CHANNEL_AGENTS_API_URLS,
|
|
10
|
+
...CHANNELS_API_URLS
|
|
10
11
|
},
|
|
11
12
|
[ModuleNames.SESSIONS]: SESSIONS_API_URLS
|
|
12
13
|
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { validateSchema } from "../../../core/utils";
|
|
2
|
+
import { ChannelSchema } from "../../schema";
|
|
3
|
+
export default class Channel {
|
|
4
|
+
constructor() {
|
|
5
|
+
let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
6
|
+
const validatedData = validateSchema(ChannelSchema, data); // Set required properties from schema
|
|
7
|
+
|
|
8
|
+
this.id = validatedData.id;
|
|
9
|
+
this.integrationService = validatedData.integrationService;
|
|
10
|
+
this.name = validatedData.name;
|
|
11
|
+
this.isActive = validatedData.isActive;
|
|
12
|
+
this.createdTime = validatedData.createdTime; // Set optional properties from schema
|
|
13
|
+
|
|
14
|
+
this.defaultBotId = validatedData.defaultBotId || null;
|
|
15
|
+
this.accountName = validatedData.accountName || null;
|
|
16
|
+
this.isSubscribed = validatedData.isSubscribed || false;
|
|
17
|
+
this.createdBy = validatedData.createdBy || null;
|
|
18
|
+
this.isOwner = validatedData.isOwner || false;
|
|
19
|
+
this.logoURL = validatedData.logoURL || null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
toJSON() {
|
|
23
|
+
return {
|
|
24
|
+
id: this.id,
|
|
25
|
+
integrationService: this.integrationService,
|
|
26
|
+
name: this.name,
|
|
27
|
+
defaultBotId: this.defaultBotId,
|
|
28
|
+
isActive: this.isActive,
|
|
29
|
+
createdTime: this.createdTime,
|
|
30
|
+
accountName: this.accountName,
|
|
31
|
+
isSubscribed: this.isSubscribed,
|
|
32
|
+
createdBy: this.createdBy,
|
|
33
|
+
isOwner: this.isOwner,
|
|
34
|
+
logoURL: this.logoURL
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { getChannelsRequest } from "../../../infrastructure/interfaces/api";
|
|
2
|
+
import BaseAPI from "../BaseAPI";
|
|
3
|
+
export default class IChannel extends BaseAPI {
|
|
4
|
+
// eslint-disable-next-line no-unused-vars
|
|
5
|
+
getChannels() {
|
|
6
|
+
let request = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getChannelsRequest();
|
|
7
|
+
throw new Error('Method not implemented.');
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { IntegrationServiceSchema } from "../integrationService";
|
|
2
|
+
const ChannelSchema = {
|
|
3
|
+
id: {
|
|
4
|
+
type: 'string',
|
|
5
|
+
required: true
|
|
6
|
+
},
|
|
7
|
+
integrationService: {
|
|
8
|
+
type: 'object',
|
|
9
|
+
required: true,
|
|
10
|
+
schema: IntegrationServiceSchema
|
|
11
|
+
},
|
|
12
|
+
name: {
|
|
13
|
+
type: 'string',
|
|
14
|
+
required: true
|
|
15
|
+
},
|
|
16
|
+
defaultBotId: {
|
|
17
|
+
type: 'string',
|
|
18
|
+
required: false
|
|
19
|
+
},
|
|
20
|
+
isActive: {
|
|
21
|
+
type: 'boolean',
|
|
22
|
+
required: true
|
|
23
|
+
},
|
|
24
|
+
createdTime: {
|
|
25
|
+
type: 'string',
|
|
26
|
+
required: true
|
|
27
|
+
},
|
|
28
|
+
accountName: {
|
|
29
|
+
type: 'string',
|
|
30
|
+
required: false
|
|
31
|
+
},
|
|
32
|
+
isSubscribed: {
|
|
33
|
+
type: 'boolean',
|
|
34
|
+
required: false
|
|
35
|
+
},
|
|
36
|
+
createdBy: {
|
|
37
|
+
type: 'string',
|
|
38
|
+
required: false
|
|
39
|
+
},
|
|
40
|
+
isOwner: {
|
|
41
|
+
type: 'boolean',
|
|
42
|
+
required: false
|
|
43
|
+
},
|
|
44
|
+
logoURL: {
|
|
45
|
+
type: 'string',
|
|
46
|
+
required: false
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
export default ChannelSchema;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { IntegrationServices } from "../../enum";
|
|
2
|
+
const IntegrationServiceSchema = {
|
|
3
|
+
label: {
|
|
4
|
+
type: 'string',
|
|
5
|
+
required: true
|
|
6
|
+
},
|
|
7
|
+
id: {
|
|
8
|
+
type: 'string',
|
|
9
|
+
required: true,
|
|
10
|
+
enum: Object.values(IntegrationServices)
|
|
11
|
+
},
|
|
12
|
+
provider: {
|
|
13
|
+
type: 'object',
|
|
14
|
+
required: true,
|
|
15
|
+
schema: {
|
|
16
|
+
name: {
|
|
17
|
+
type: 'string',
|
|
18
|
+
required: true
|
|
19
|
+
},
|
|
20
|
+
domain: {
|
|
21
|
+
type: 'string',
|
|
22
|
+
required: true
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
logoURL: {
|
|
27
|
+
type: 'string',
|
|
28
|
+
required: false
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
export default IntegrationServiceSchema;
|
|
@@ -2,7 +2,6 @@ import { getUrlConfig } from "../../../config/urls";
|
|
|
2
2
|
import { ModuleNames } from "../../../core/constants";
|
|
3
3
|
import { BotAdapter } from "../../../infrastructure/adapters";
|
|
4
4
|
import { BotAPI } from "../../../infrastructure/api";
|
|
5
|
-
import { getBotsRequest } from "../../../infrastructure/interfaces/api";
|
|
6
5
|
import { IBot } from "../../interfaces";
|
|
7
6
|
export default class BotService extends IBot {
|
|
8
7
|
constructor(_ref) {
|
|
@@ -18,8 +17,7 @@ export default class BotService extends IBot {
|
|
|
18
17
|
this.botAdapter = botAdapter || new BotAdapter();
|
|
19
18
|
}
|
|
20
19
|
|
|
21
|
-
async getBots() {
|
|
22
|
-
let request = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getBotsRequest();
|
|
20
|
+
async getBots(request) {
|
|
23
21
|
const bots = await this.botAPI.getBots(request);
|
|
24
22
|
return bots.map(this.botAdapter.adapt);
|
|
25
23
|
}
|
|
@@ -2,7 +2,6 @@ import { getUrlConfig } from "../../../config/urls";
|
|
|
2
2
|
import { ModuleNames } from "../../../core/constants";
|
|
3
3
|
import { ChannelAgentAdapter } from "../../../infrastructure/adapters";
|
|
4
4
|
import { ChannelAgentAPI } from "../../../infrastructure/api";
|
|
5
|
-
import { getChannelAgentsRequest } from "../../../infrastructure/interfaces/api";
|
|
6
5
|
import { IChannelAgent } from "../../interfaces";
|
|
7
6
|
export default class ChannelAgentService extends IChannelAgent {
|
|
8
7
|
constructor(_ref) {
|
|
@@ -18,8 +17,7 @@ export default class ChannelAgentService extends IChannelAgent {
|
|
|
18
17
|
this.channelAgentAdapter = channelAgentAdapter || new ChannelAgentAdapter();
|
|
19
18
|
}
|
|
20
19
|
|
|
21
|
-
async getAgents() {
|
|
22
|
-
let request = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getChannelAgentsRequest();
|
|
20
|
+
async getAgents(request) {
|
|
23
21
|
const channelAgents = await this.channelAgentAPI.getAgents(request);
|
|
24
22
|
return channelAgents.map(this.channelAgentAdapter.adapt);
|
|
25
23
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { getUrlConfig } from "../../../config/urls";
|
|
2
|
+
import { ModuleNames } from "../../../core/constants";
|
|
3
|
+
import { ChannelAdapter } from "../../../infrastructure/adapters";
|
|
4
|
+
import { ChannelAPI } from "../../../infrastructure/api";
|
|
5
|
+
import { IChannel } from "../../interfaces";
|
|
6
|
+
export default class ChannelService extends IChannel {
|
|
7
|
+
constructor() {
|
|
8
|
+
let {
|
|
9
|
+
channelAPI,
|
|
10
|
+
channelAdapter
|
|
11
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
12
|
+
super();
|
|
13
|
+
const urlConfig = getUrlConfig(ModuleNames.CHANNELS);
|
|
14
|
+
this.channelAPI = channelAPI || new ChannelAPI({
|
|
15
|
+
urlConfig
|
|
16
|
+
});
|
|
17
|
+
this.channelAdapter = channelAdapter || new ChannelAdapter();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async getChannels(request) {
|
|
21
|
+
const channels = await this.channelAPI.getChannels(request);
|
|
22
|
+
return channels.map(channel => this.channelAdapter.adapt(channel));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
toJSON() {
|
|
26
|
+
return {
|
|
27
|
+
getChannels: this.getChannels.bind(this)
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
}
|
|
@@ -2,7 +2,6 @@ import { getUrlConfig } from "../../../config/urls";
|
|
|
2
2
|
import { ModuleNames } from "../../../core/constants";
|
|
3
3
|
import { SessionAdapter } from "../../../infrastructure/adapters";
|
|
4
4
|
import { SessionAPI } from "../../../infrastructure/api";
|
|
5
|
-
import { updateSessionAssigneeRequest } from "../../../infrastructure/interfaces/api";
|
|
6
5
|
import { ISession } from "../../interfaces";
|
|
7
6
|
export default class SessionService extends ISession {
|
|
8
7
|
constructor(_ref) {
|
|
@@ -18,8 +17,7 @@ export default class SessionService extends ISession {
|
|
|
18
17
|
this.sessionAdapter = sessionAdapter || new SessionAdapter();
|
|
19
18
|
}
|
|
20
19
|
|
|
21
|
-
async updateAssignee() {
|
|
22
|
-
let request = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : updateSessionAssigneeRequest();
|
|
20
|
+
async updateAssignee(request) {
|
|
23
21
|
const session = await this.sessionAPI.updateAssignee(request);
|
|
24
22
|
return this.sessionAdapter.adapt(session);
|
|
25
23
|
}
|
|
@@ -2,7 +2,7 @@ import { AdapterError } from "../../../core/errors";
|
|
|
2
2
|
import { Bot } from "../../../domain/entities";
|
|
3
3
|
import IAdapter from "../../../domain/interfaces/IAdapter";
|
|
4
4
|
export default class BotAdapter extends IAdapter {
|
|
5
|
-
|
|
5
|
+
adapt(botData) {
|
|
6
6
|
if (!botData) {
|
|
7
7
|
throw new AdapterError('Bot data is required');
|
|
8
8
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { AdapterError } from "../../../core/errors";
|
|
2
|
+
import { Channel } from "../../../domain/entities";
|
|
3
|
+
import IAdapter from "../../../domain/interfaces/IAdapter";
|
|
4
|
+
export default class ChannelAdapter extends IAdapter {
|
|
5
|
+
adapt(rawChannel) {
|
|
6
|
+
if (!rawChannel) {
|
|
7
|
+
throw new AdapterError('Channel data is required');
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
try {
|
|
11
|
+
return new Channel({
|
|
12
|
+
id: rawChannel.id,
|
|
13
|
+
integrationService: rawChannel.integrationService,
|
|
14
|
+
name: rawChannel.name,
|
|
15
|
+
defaultBotId: rawChannel.defaultBotId,
|
|
16
|
+
isActive: rawChannel.isActive,
|
|
17
|
+
createdTime: rawChannel.createdTime,
|
|
18
|
+
accountName: rawChannel.accountName,
|
|
19
|
+
isSubscribed: rawChannel.isSubscribed,
|
|
20
|
+
createdBy: rawChannel.createdBy,
|
|
21
|
+
isOwner: rawChannel.isOwner,
|
|
22
|
+
logoURL: rawChannel.logoURL
|
|
23
|
+
}).toJSON();
|
|
24
|
+
} catch (error) {
|
|
25
|
+
throw new AdapterError(`Failed to adapt channel: ${error.message}`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
}
|
|
@@ -8,7 +8,7 @@ export default class ChannelAgentAdapter extends IAdapter {
|
|
|
8
8
|
* @returns {Object} Adapted agent data
|
|
9
9
|
* @throws {AdapterError} When adaptation fails
|
|
10
10
|
*/
|
|
11
|
-
|
|
11
|
+
adapt(channelAgent) {
|
|
12
12
|
if (!channelAgent) {
|
|
13
13
|
throw new AdapterError('Channel agent data is required');
|
|
14
14
|
}
|
|
@@ -2,7 +2,7 @@ import { AdapterError } from "../../../core/errors";
|
|
|
2
2
|
import { Session } from "../../../domain/entities";
|
|
3
3
|
import IAdapter from "../../../domain/interfaces/IAdapter";
|
|
4
4
|
export default class SessionAdapter extends IAdapter {
|
|
5
|
-
|
|
5
|
+
adapt(sessionData) {
|
|
6
6
|
if (!sessionData) {
|
|
7
7
|
throw new AdapterError('Session data is required');
|
|
8
8
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { IChannel } from "../../../domain/interfaces";
|
|
2
|
+
import { getChannelsRequest } from "../../interfaces/api";
|
|
3
|
+
export default class ChannelAPI extends IChannel {
|
|
4
|
+
constructor(_ref) {
|
|
5
|
+
let {
|
|
6
|
+
urlConfig
|
|
7
|
+
} = _ref;
|
|
8
|
+
super();
|
|
9
|
+
this.urlConfig = urlConfig;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async getChannels() {
|
|
13
|
+
let request = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getChannelsRequest();
|
|
14
|
+
const urlConfig = this.urlConfig.LIST;
|
|
15
|
+
const httpRequest = await this.request({
|
|
16
|
+
urlConfig,
|
|
17
|
+
request
|
|
18
|
+
});
|
|
19
|
+
return httpRequest.data || [];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
}
|
|
@@ -11,12 +11,20 @@ export default class ChannelAgentAPI extends IChannelAgent {
|
|
|
11
11
|
|
|
12
12
|
async getAgents() {
|
|
13
13
|
let request = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getChannelAgentsRequest();
|
|
14
|
+
const {
|
|
15
|
+
searchStr
|
|
16
|
+
} = request.query;
|
|
17
|
+
|
|
18
|
+
if (searchStr) {
|
|
19
|
+
request.query.searchStr = `*${encodeURIComponent(searchStr)}*`;
|
|
20
|
+
}
|
|
21
|
+
|
|
14
22
|
const urlConfig = this.urlConfig.LIST;
|
|
15
23
|
const httpRequest = await this.request({
|
|
16
24
|
urlConfig,
|
|
17
25
|
request
|
|
18
26
|
});
|
|
19
|
-
return httpRequest;
|
|
27
|
+
return httpRequest.data || [];
|
|
20
28
|
}
|
|
21
29
|
|
|
22
30
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { RequestBuilder } from "../base";
|
|
2
|
+
|
|
3
|
+
function getChannelsRequest() {
|
|
4
|
+
let {
|
|
5
|
+
query = {}
|
|
6
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
7
|
+
return new RequestBuilder().withQuery({
|
|
8
|
+
from: 0,
|
|
9
|
+
limit: 10,
|
|
10
|
+
modifiedAfter: null,
|
|
11
|
+
integrationServiceId: null,
|
|
12
|
+
externalAccountId: null,
|
|
13
|
+
isSandBox: null,
|
|
14
|
+
isActive: null,
|
|
15
|
+
includeDeleted: null,
|
|
16
|
+
onlyDeleted: null,
|
|
17
|
+
configName: null,
|
|
18
|
+
configValue: null,
|
|
19
|
+
channelIds: null,
|
|
20
|
+
include: null,
|
|
21
|
+
// meta|configParams
|
|
22
|
+
includeUnsubscribed: null,
|
|
23
|
+
...query
|
|
24
|
+
}).build();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export default getChannelsRequest;
|
|
@@ -1,23 +1,30 @@
|
|
|
1
|
-
import { ChannelAgentService } from "../../../domain/services";
|
|
1
|
+
import { ChannelAgentService, ChannelService } from "../../../domain/services";
|
|
2
2
|
export default class ChannelSDK {
|
|
3
3
|
constructor(_ref) {
|
|
4
4
|
let {
|
|
5
5
|
config
|
|
6
6
|
} = _ref;
|
|
7
7
|
const {
|
|
8
|
+
channelAPI,
|
|
9
|
+
channelAdapter,
|
|
8
10
|
channelAgentAPI,
|
|
9
11
|
channelAgentAdapter
|
|
10
12
|
} = config;
|
|
11
|
-
|
|
13
|
+
const channelAgentService = new ChannelAgentService({
|
|
12
14
|
channelAgentAPI,
|
|
13
15
|
channelAgentAdapter
|
|
14
16
|
}).toJSON();
|
|
17
|
+
const channelService = new ChannelService({
|
|
18
|
+
channelAPI,
|
|
19
|
+
channelAdapter
|
|
20
|
+
}).toJSON();
|
|
21
|
+
this.services = { ...channelService,
|
|
22
|
+
agents: channelAgentService
|
|
23
|
+
};
|
|
15
24
|
}
|
|
16
25
|
|
|
17
26
|
toJSON() {
|
|
18
|
-
return
|
|
19
|
-
agents: this.agents
|
|
20
|
-
};
|
|
27
|
+
return this.services;
|
|
21
28
|
}
|
|
22
29
|
|
|
23
30
|
}
|