@zohoim/client-sdk 1.0.0-poc77 → 1.0.0-poc79
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/domain/dto/messages/initiateSessionRequest.js +0 -1
- package/es/domain/dto/messages/sendAttachmentRequest.js +1 -0
- package/es/domain/dto/messages/sendMessageRequest.js +0 -2
- package/es/domain/dto/sessions/markSessionAsReadRequest.js +1 -5
- package/es/domain/entities/Message/Message.js +4 -0
- package/es/domain/entities/Session/Session.js +0 -4
- package/es/domain/enum/actor/ActorType.js +1 -1
- package/es/domain/enum/message/MessageDirection.js +2 -2
- package/es/domain/enum/message/MessageType.js +1 -4
- package/es/domain/schema/attachment/AttachmentSchema.js +3 -1
- package/es/infrastructure/adapters/attachments/AttachmentAdapter.js +2 -1
- package/es/infrastructure/api/BaseAPI.js +56 -9
- package/package.json +1 -1
- package/es/infrastructure/api/UrlBuilder.js +0 -53
|
@@ -2,15 +2,11 @@ import RequestBuilder from "../RequestBuilder";
|
|
|
2
2
|
|
|
3
3
|
function markSessionAsReadRequest() {
|
|
4
4
|
let {
|
|
5
|
-
body = {}
|
|
6
|
-
params = {}
|
|
5
|
+
body = {}
|
|
7
6
|
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
8
7
|
return new RequestBuilder().withBody({
|
|
9
8
|
lastSeenMessageId: null,
|
|
10
9
|
...body
|
|
11
|
-
}).withParams({
|
|
12
|
-
sessionId: null,
|
|
13
|
-
...params
|
|
14
10
|
}).build();
|
|
15
11
|
}
|
|
16
12
|
|
|
@@ -40,10 +40,6 @@ export default class Session {
|
|
|
40
40
|
return replyStatus === SessionReplyStatus.CHANNEL_INACTIVE;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
static isReplyAccepted(replyStatus) {
|
|
44
|
-
return replyStatus === SessionReplyStatus.ACCEPTED;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
43
|
static isAssignedToOtherService(replyStatus) {
|
|
48
44
|
return replyStatus === SessionReplyStatus.ASSIGNED_TO_OTHER_SERVICE;
|
|
49
45
|
}
|
|
@@ -6,9 +6,6 @@ const MessageTypes = {
|
|
|
6
6
|
LAYOUT: 'LAYOUT',
|
|
7
7
|
EXTERNAL_INFO: 'EXTERNAL_INFO',
|
|
8
8
|
TEMPLATE: 'TEMPLATE',
|
|
9
|
-
ACTION: 'ACTION'
|
|
10
|
-
WELCOMEMSG: 'WELCOMEMSG',
|
|
11
|
-
WORKFLOW_MESSAGE: 'WORKFLOW_MESSAGE',
|
|
12
|
-
WORKFLOW_NOTIFICATION: 'WORKFLOW_NOTIFICATION'
|
|
9
|
+
ACTION: 'ACTION'
|
|
13
10
|
};
|
|
14
11
|
export default MessageTypes;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { AttachmentStatus } from "../../enum";
|
|
1
2
|
const AttachmentSchema = {
|
|
2
3
|
id: {
|
|
3
4
|
type: 'string',
|
|
@@ -25,7 +26,8 @@ const AttachmentSchema = {
|
|
|
25
26
|
},
|
|
26
27
|
status: {
|
|
27
28
|
type: 'string',
|
|
28
|
-
required: false
|
|
29
|
+
required: false,
|
|
30
|
+
enum: Object.values(AttachmentStatus)
|
|
29
31
|
}
|
|
30
32
|
};
|
|
31
33
|
export default AttachmentSchema;
|
|
@@ -14,7 +14,8 @@ export default class AttachmentAdapter extends IAdapter {
|
|
|
14
14
|
type: attachmentData.type,
|
|
15
15
|
createdTime: attachmentData.createdTime,
|
|
16
16
|
size: attachmentData.size,
|
|
17
|
-
url: attachmentData.url
|
|
17
|
+
url: attachmentData.url,
|
|
18
|
+
status: attachmentData.status
|
|
18
19
|
}).toJSON();
|
|
19
20
|
} catch (error) {
|
|
20
21
|
throw new AdapterError(`Failed to adapt attachment: ${error.message}`);
|
|
@@ -2,7 +2,6 @@ import { ResponseTypes } from "../../core/constants";
|
|
|
2
2
|
import { ResponseUtils } from "../../core/utils";
|
|
3
3
|
import configRegistry from "../config/configRegistry";
|
|
4
4
|
import { getRegistryConfig } from "./registry";
|
|
5
|
-
import UrlBuilder from "./UrlBuilder";
|
|
6
5
|
export default class BaseAPI {
|
|
7
6
|
constructor() {
|
|
8
7
|
let {
|
|
@@ -10,30 +9,78 @@ export default class BaseAPI {
|
|
|
10
9
|
configProvider = configRegistry,
|
|
11
10
|
registryProvider = {
|
|
12
11
|
getRegistryConfig
|
|
13
|
-
}
|
|
14
|
-
urlBuilder = new UrlBuilder()
|
|
12
|
+
}
|
|
15
13
|
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
16
14
|
this.configProvider = configProvider;
|
|
17
15
|
this.registryProvider = registryProvider;
|
|
18
16
|
this.httpClient = this.configProvider.getHttpClient();
|
|
19
17
|
this.baseURL = this.configProvider.getBaseURL();
|
|
20
18
|
this.module = module;
|
|
21
|
-
this.urlBuilder = urlBuilder;
|
|
22
19
|
}
|
|
23
20
|
|
|
24
|
-
|
|
21
|
+
replacePathParams(url, params) {
|
|
22
|
+
let _url = url;
|
|
23
|
+
Object.entries(params).forEach(_ref => {
|
|
24
|
+
let [key, value] = _ref;
|
|
25
|
+
_url = url.replace(`:${key}`, value);
|
|
26
|
+
});
|
|
27
|
+
return _url;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
buildUrl(_ref2) {
|
|
31
|
+
let {
|
|
32
|
+
url,
|
|
33
|
+
params,
|
|
34
|
+
query
|
|
35
|
+
} = _ref2;
|
|
36
|
+
|
|
37
|
+
const _params = params || {};
|
|
38
|
+
|
|
39
|
+
const _query = query || {};
|
|
40
|
+
|
|
41
|
+
let _url = this.replacePathParams(url, _params);
|
|
42
|
+
|
|
43
|
+
if (this.baseURL) {
|
|
44
|
+
_url = `${this.baseURL}${_url}`;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const queryString = this.buildQuery(_query);
|
|
48
|
+
|
|
49
|
+
if (queryString) {
|
|
50
|
+
return `${_url}?${queryString}`;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return _url;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
buildQuery(query) {
|
|
57
|
+
const filteredQuery = Object.entries(query).filter(_ref3 => {
|
|
58
|
+
let [, value] = _ref3;
|
|
59
|
+
return value !== undefined && value !== null && value !== '';
|
|
60
|
+
}).reduce((acc, _ref4) => {
|
|
61
|
+
let [key, value] = _ref4;
|
|
62
|
+
acc[key] = value;
|
|
63
|
+
return acc;
|
|
64
|
+
}, {});
|
|
65
|
+
return Object.entries(filteredQuery).map(_ref5 => {
|
|
66
|
+
let [key, value] = _ref5;
|
|
67
|
+
return `${key}=${value}`;
|
|
68
|
+
}).join('&');
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async request(_ref6) {
|
|
25
72
|
let {
|
|
26
73
|
request,
|
|
27
74
|
operation,
|
|
28
75
|
header
|
|
29
|
-
} =
|
|
76
|
+
} = _ref6;
|
|
30
77
|
const config = this.registryProvider.getRegistryConfig(this.module, operation);
|
|
31
78
|
|
|
32
79
|
if (!config) {
|
|
33
80
|
throw new Error(`Operation "${operation}" not found in registry for module "${this.module}"`);
|
|
34
81
|
}
|
|
35
82
|
|
|
36
|
-
const url = this.
|
|
83
|
+
const url = this.buildUrl({
|
|
37
84
|
url: config.endpoint,
|
|
38
85
|
params: request.params || {},
|
|
39
86
|
query: request.query || {}
|
|
@@ -74,7 +121,7 @@ export default class BaseAPI {
|
|
|
74
121
|
Object.prototype.hasOwnProperty.call(customPrototype, methodName);
|
|
75
122
|
}
|
|
76
123
|
|
|
77
|
-
async executeAPICall(
|
|
124
|
+
async executeAPICall(_ref7) {
|
|
78
125
|
let {
|
|
79
126
|
operation,
|
|
80
127
|
request,
|
|
@@ -82,7 +129,7 @@ export default class BaseAPI {
|
|
|
82
129
|
customAPI,
|
|
83
130
|
adapter,
|
|
84
131
|
responseType = ResponseTypes.SINGLE
|
|
85
|
-
} =
|
|
132
|
+
} = _ref7;
|
|
86
133
|
const response = await apiProxy[operation](request);
|
|
87
134
|
const isOverridden = this.isMethodOverridden(customAPI, operation);
|
|
88
135
|
|
package/package.json
CHANGED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
export default class UrlBuilder {
|
|
2
|
-
constructor(baseURL) {
|
|
3
|
-
this.baseURL = baseURL;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
replacePathParams(url, params) {
|
|
7
|
-
let processedUrl = url;
|
|
8
|
-
Object.entries(params).forEach(_ref => {
|
|
9
|
-
let [key, value] = _ref;
|
|
10
|
-
processedUrl = processedUrl.replace(`:${key}`, value);
|
|
11
|
-
});
|
|
12
|
-
return processedUrl;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
buildUrl(_ref2) {
|
|
16
|
-
let {
|
|
17
|
-
url,
|
|
18
|
-
params,
|
|
19
|
-
query
|
|
20
|
-
} = _ref2;
|
|
21
|
-
const paramsObj = params || {};
|
|
22
|
-
const queryObj = query || {};
|
|
23
|
-
let processedUrl = this.replacePathParams(url, paramsObj);
|
|
24
|
-
|
|
25
|
-
if (this.baseURL) {
|
|
26
|
-
processedUrl = `${this.baseURL}${processedUrl}`;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const queryString = this.buildQuery(queryObj);
|
|
30
|
-
|
|
31
|
-
if (queryString) {
|
|
32
|
-
return `${processedUrl}?${queryString}`;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return processedUrl;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
buildQuery(query) {
|
|
39
|
-
const filteredQuery = Object.entries(query).filter(_ref3 => {
|
|
40
|
-
let [, value] = _ref3;
|
|
41
|
-
return value !== undefined && value !== null && value !== '';
|
|
42
|
-
}).reduce((acc, _ref4) => {
|
|
43
|
-
let [key, value] = _ref4;
|
|
44
|
-
acc[key] = value;
|
|
45
|
-
return acc;
|
|
46
|
-
}, {});
|
|
47
|
-
return Object.entries(filteredQuery).map(_ref5 => {
|
|
48
|
-
let [key, value] = _ref5;
|
|
49
|
-
return `${key}=${value}`;
|
|
50
|
-
}).join('&');
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
}
|