@zohoim/client-sdk 1.0.0-replyAreaPoc5 → 1.0.0-replyAreaPoc6
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/core/utils/validateSchema.js +60 -26
- package/es/domain/dto/messages/initiateSessionRequest.js +2 -0
- package/es/domain/dto/sessions/getSessionsRequest.js +1 -0
- package/es/domain/entities/Actor/Actor.js +5 -1
- package/es/domain/entities/Agent/Agent.js +5 -1
- package/es/domain/entities/Attachment/Attachment.js +5 -1
- package/es/domain/entities/Bot/Bot.js +5 -1
- package/es/domain/entities/Channel/Channel.js +5 -1
- package/es/domain/entities/Contact/Contact.js +5 -1
- package/es/domain/entities/IntegrationService/IntegrationService.js +5 -1
- package/es/domain/entities/Message/Action.js +5 -1
- package/es/domain/entities/Message/ExternalInfo.js +5 -1
- package/es/domain/entities/Message/Info.js +5 -1
- package/es/domain/entities/Message/InfoTarget.js +5 -1
- package/es/domain/entities/Message/Location.js +5 -1
- package/es/domain/entities/Message/Message.js +25 -2
- package/es/domain/entities/Message/MessageWithSession.js +5 -1
- package/es/domain/entities/Session/Session.js +5 -1
- package/es/domain/enum/message/MessageMeta.js +2 -1
- package/es/domain/enum/message/MetaMessageSourceType.js +6 -0
- package/es/domain/enum/message/index.js +2 -1
- package/package.json +1 -1
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
function validateSchemaKeys(_ref) {
|
|
2
|
+
let {
|
|
3
|
+
schema = {},
|
|
4
|
+
data = {},
|
|
5
|
+
entityName = ''
|
|
6
|
+
} = _ref;
|
|
7
|
+
Object.keys(schema).forEach(key => {
|
|
8
|
+
if (!(key in data)) {
|
|
9
|
+
console.warn(`${entityName} - Key '${key}' is missing in the data`);
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
}
|
|
8
13
|
|
|
9
14
|
function isEmpty(value) {
|
|
10
15
|
if (value === null || value === undefined || value === '') {
|
|
@@ -14,44 +19,63 @@ function isEmpty(value) {
|
|
|
14
19
|
return false;
|
|
15
20
|
}
|
|
16
21
|
|
|
17
|
-
function validateRequiredCheck(
|
|
22
|
+
function validateRequiredCheck(_ref2) {
|
|
18
23
|
let {
|
|
19
24
|
value,
|
|
20
25
|
rules,
|
|
21
|
-
path
|
|
22
|
-
|
|
26
|
+
path,
|
|
27
|
+
entityName
|
|
28
|
+
} = _ref2;
|
|
23
29
|
|
|
24
30
|
if (rules.required && isEmpty(value)) {
|
|
25
|
-
|
|
31
|
+
console.warn(`${entityName} - ${path} is required`);
|
|
26
32
|
}
|
|
27
33
|
}
|
|
28
34
|
|
|
29
|
-
function validateEnumCheck(
|
|
35
|
+
function validateEnumCheck(_ref3) {
|
|
30
36
|
let {
|
|
31
37
|
value,
|
|
32
38
|
rules,
|
|
33
|
-
path
|
|
34
|
-
|
|
39
|
+
path,
|
|
40
|
+
entityName
|
|
41
|
+
} = _ref3;
|
|
35
42
|
|
|
36
43
|
if (rules.enum && !rules.enum.includes(value)) {
|
|
37
|
-
|
|
44
|
+
console.warn(`${entityName} - ${path} must be one of: ${rules.enum.join(', ')}. Received: ${value}`);
|
|
38
45
|
}
|
|
39
46
|
}
|
|
40
47
|
|
|
41
|
-
export const validateSchema =
|
|
42
|
-
|
|
43
|
-
|
|
48
|
+
export const validateSchema = _ref4 => {
|
|
49
|
+
let {
|
|
50
|
+
schema,
|
|
51
|
+
data,
|
|
52
|
+
entityName = ''
|
|
53
|
+
} = _ref4;
|
|
54
|
+
|
|
55
|
+
const validate = _ref5 => {
|
|
56
|
+
let {
|
|
57
|
+
schema: schemaObj,
|
|
58
|
+
data: dataObj,
|
|
59
|
+
path = '',
|
|
60
|
+
entityName
|
|
61
|
+
} = _ref5;
|
|
44
62
|
// Check if all schema keys exist in data
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
63
|
+
validateSchemaKeys({
|
|
64
|
+
schema: schemaObj,
|
|
65
|
+
data: dataObj,
|
|
66
|
+
entityName,
|
|
67
|
+
path
|
|
68
|
+
}); // Validate each field
|
|
69
|
+
|
|
70
|
+
Object.entries(schemaObj).forEach(_ref6 => {
|
|
71
|
+
let [field, rules] = _ref6;
|
|
49
72
|
const value = dataObj[field];
|
|
50
73
|
const fieldPath = path ? `${path}.${field}` : field;
|
|
51
74
|
validateRequiredCheck({
|
|
52
75
|
value,
|
|
53
76
|
rules,
|
|
54
|
-
path: fieldPath
|
|
77
|
+
path: fieldPath,
|
|
78
|
+
entityName
|
|
55
79
|
});
|
|
56
80
|
|
|
57
81
|
if (value !== null && value !== undefined) {
|
|
@@ -59,16 +83,26 @@ export const validateSchema = (schema, data) => {
|
|
|
59
83
|
validateEnumCheck({
|
|
60
84
|
value,
|
|
61
85
|
rules,
|
|
62
|
-
path: fieldPath
|
|
86
|
+
path: fieldPath,
|
|
87
|
+
entityName
|
|
63
88
|
}); // Nested object validation
|
|
64
89
|
|
|
65
90
|
if (rules.type === 'object' && rules.schema) {
|
|
66
|
-
validate(
|
|
91
|
+
validate({
|
|
92
|
+
schema: rules.schema,
|
|
93
|
+
data: value,
|
|
94
|
+
path: fieldPath,
|
|
95
|
+
entityName
|
|
96
|
+
});
|
|
67
97
|
}
|
|
68
98
|
}
|
|
69
99
|
});
|
|
70
100
|
return dataObj;
|
|
71
101
|
};
|
|
72
102
|
|
|
73
|
-
return validate(
|
|
103
|
+
return validate({
|
|
104
|
+
schema,
|
|
105
|
+
data,
|
|
106
|
+
entityName
|
|
107
|
+
});
|
|
74
108
|
};
|
|
@@ -4,7 +4,11 @@ import { ActorSchema } from '../../schema';
|
|
|
4
4
|
export default class Actor {
|
|
5
5
|
constructor() {
|
|
6
6
|
let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
7
|
-
const validatedData = validateSchema(
|
|
7
|
+
const validatedData = validateSchema({
|
|
8
|
+
schema: ActorSchema,
|
|
9
|
+
data,
|
|
10
|
+
entityName: 'Actor'
|
|
11
|
+
});
|
|
8
12
|
this.data = {
|
|
9
13
|
name: validatedData.name,
|
|
10
14
|
type: validatedData.type,
|
|
@@ -3,7 +3,11 @@ import { AgentSchema } from '../../schema';
|
|
|
3
3
|
export default class Agent {
|
|
4
4
|
constructor() {
|
|
5
5
|
let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
6
|
-
const validatedData = validateSchema(
|
|
6
|
+
const validatedData = validateSchema({
|
|
7
|
+
schema: AgentSchema,
|
|
8
|
+
data,
|
|
9
|
+
entityName: 'Agent'
|
|
10
|
+
});
|
|
7
11
|
this.data = {
|
|
8
12
|
id: validatedData.id,
|
|
9
13
|
firstName: validatedData.firstName,
|
|
@@ -3,7 +3,11 @@ import { AttachmentSchema } from '../../schema';
|
|
|
3
3
|
export default class Attachment {
|
|
4
4
|
constructor() {
|
|
5
5
|
let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
6
|
-
const validatedData = validateSchema(
|
|
6
|
+
const validatedData = validateSchema({
|
|
7
|
+
schema: AttachmentSchema,
|
|
8
|
+
data,
|
|
9
|
+
entityName: 'Attachment'
|
|
10
|
+
});
|
|
7
11
|
this.data = {
|
|
8
12
|
id: validatedData.id,
|
|
9
13
|
name: validatedData.name,
|
|
@@ -3,7 +3,11 @@ import { BotSchema } from '../../schema';
|
|
|
3
3
|
export default class Bot {
|
|
4
4
|
constructor() {
|
|
5
5
|
let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
6
|
-
const validatedData = validateSchema(
|
|
6
|
+
const validatedData = validateSchema({
|
|
7
|
+
schema: BotSchema,
|
|
8
|
+
data,
|
|
9
|
+
entityName: 'Bot'
|
|
10
|
+
});
|
|
7
11
|
this.data = {
|
|
8
12
|
id: validatedData.id,
|
|
9
13
|
botServiceType: validatedData.botServiceType,
|
|
@@ -3,7 +3,11 @@ import { ChannelSchema } from '../../schema';
|
|
|
3
3
|
export default class Channel {
|
|
4
4
|
constructor() {
|
|
5
5
|
let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
6
|
-
const validatedData = validateSchema(
|
|
6
|
+
const validatedData = validateSchema({
|
|
7
|
+
schema: ChannelSchema,
|
|
8
|
+
data,
|
|
9
|
+
entityName: 'Channel'
|
|
10
|
+
}); // Set required properties from schema
|
|
7
11
|
|
|
8
12
|
this.id = validatedData.id;
|
|
9
13
|
this.integrationService = validatedData.integrationService;
|
|
@@ -3,7 +3,11 @@ import { ContactSchema } from '../../schema';
|
|
|
3
3
|
export default class Contact {
|
|
4
4
|
constructor() {
|
|
5
5
|
let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
6
|
-
const validatedData = validateSchema(
|
|
6
|
+
const validatedData = validateSchema({
|
|
7
|
+
schema: ContactSchema,
|
|
8
|
+
data,
|
|
9
|
+
entityName: 'Contact'
|
|
10
|
+
});
|
|
7
11
|
this.data = {
|
|
8
12
|
id: validatedData.id,
|
|
9
13
|
name: validatedData.name,
|
|
@@ -4,7 +4,11 @@ import { IntegrationServiceSchema } from '../../schema';
|
|
|
4
4
|
export default class IntegrationService {
|
|
5
5
|
constructor() {
|
|
6
6
|
let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
7
|
-
const validatedData = validateSchema(
|
|
7
|
+
const validatedData = validateSchema({
|
|
8
|
+
schema: IntegrationServiceSchema,
|
|
9
|
+
data,
|
|
10
|
+
entityName: 'IntegrationService'
|
|
11
|
+
});
|
|
8
12
|
this.data = {
|
|
9
13
|
label: validatedData.label || '',
|
|
10
14
|
id: validatedData.id || '',
|
|
@@ -4,7 +4,11 @@ import { ActionSchema } from '../../schema';
|
|
|
4
4
|
export default class Action {
|
|
5
5
|
constructor() {
|
|
6
6
|
let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
7
|
-
const validatedData = validateSchema(
|
|
7
|
+
const validatedData = validateSchema({
|
|
8
|
+
schema: ActionSchema,
|
|
9
|
+
data,
|
|
10
|
+
entityName: 'Action'
|
|
11
|
+
});
|
|
8
12
|
this.data = {
|
|
9
13
|
type: validatedData.type,
|
|
10
14
|
subType: validatedData.subType,
|
|
@@ -4,7 +4,11 @@ import { ExternalInfoSchema } from '../../schema';
|
|
|
4
4
|
export default class ExternalInfo {
|
|
5
5
|
constructor() {
|
|
6
6
|
let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
7
|
-
const validatedData = validateSchema(
|
|
7
|
+
const validatedData = validateSchema({
|
|
8
|
+
schema: ExternalInfoSchema,
|
|
9
|
+
data,
|
|
10
|
+
entityName: 'ExternalInfo'
|
|
11
|
+
});
|
|
8
12
|
this.data = {
|
|
9
13
|
action: validatedData.action
|
|
10
14
|
};
|
|
@@ -12,7 +12,11 @@ function adaptTargets() {
|
|
|
12
12
|
export default class Info {
|
|
13
13
|
constructor() {
|
|
14
14
|
let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
15
|
-
const validatedData = validateSchema(
|
|
15
|
+
const validatedData = validateSchema({
|
|
16
|
+
schema: InfoSchema,
|
|
17
|
+
data,
|
|
18
|
+
entityName: 'Info'
|
|
19
|
+
});
|
|
16
20
|
this.data = {
|
|
17
21
|
actor: new Actor(validatedData.actor).toJSON(),
|
|
18
22
|
action: validatedData.action,
|
|
@@ -3,7 +3,11 @@ import { InfoTargetSchema } from '../../schema/message';
|
|
|
3
3
|
export default class InfoTarget {
|
|
4
4
|
constructor() {
|
|
5
5
|
let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
6
|
-
const validatedData = validateSchema(
|
|
6
|
+
const validatedData = validateSchema({
|
|
7
|
+
schema: InfoTargetSchema,
|
|
8
|
+
data,
|
|
9
|
+
entityName: 'InfoTarget'
|
|
10
|
+
});
|
|
7
11
|
this.data = {
|
|
8
12
|
id: validatedData.id,
|
|
9
13
|
name: validatedData.name || null,
|
|
@@ -3,7 +3,11 @@ import { LocationSchema } from '../../schema';
|
|
|
3
3
|
export default class Location {
|
|
4
4
|
constructor() {
|
|
5
5
|
let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
6
|
-
const validatedData = validateSchema(
|
|
6
|
+
const validatedData = validateSchema({
|
|
7
|
+
schema: LocationSchema,
|
|
8
|
+
data,
|
|
9
|
+
entityName: 'Location'
|
|
10
|
+
});
|
|
7
11
|
this.data = {
|
|
8
12
|
latitude: validatedData.latitude,
|
|
9
13
|
longitude: validatedData.longitude
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { validateSchema } from '../../../core/utils';
|
|
2
|
-
import { MessageDirection, MessageStatus, MessageTypes, MessageMeta, MetaSystemMessageType } from '../../enum';
|
|
2
|
+
import { MessageDirection, MessageStatus, MessageTypes, MessageMeta, MetaSystemMessageType, MetaMessageSourceType } from '../../enum';
|
|
3
3
|
import { MessageSchema } from '../../schema';
|
|
4
4
|
import { Actor } from '../Actor';
|
|
5
5
|
import { Attachment } from '../Attachment';
|
|
@@ -10,7 +10,11 @@ import Location from './Location';
|
|
|
10
10
|
export default class Message {
|
|
11
11
|
constructor() {
|
|
12
12
|
let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
13
|
-
const validatedData = validateSchema(
|
|
13
|
+
const validatedData = validateSchema({
|
|
14
|
+
schema: MessageSchema,
|
|
15
|
+
data,
|
|
16
|
+
entityName: 'Message'
|
|
17
|
+
});
|
|
14
18
|
this.data = {
|
|
15
19
|
id: validatedData.id,
|
|
16
20
|
sessionId: validatedData.sessionId,
|
|
@@ -121,6 +125,25 @@ export default class Message {
|
|
|
121
125
|
return messageType === MetaSystemMessageType.UN_SUPPORTED_FILE;
|
|
122
126
|
}
|
|
123
127
|
|
|
128
|
+
static getMessageSourceValue(meta) {
|
|
129
|
+
return Message.getMetaValue(meta, MessageMeta.MESSAGE_SOURCE);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
static isHistoryMessage(meta) {
|
|
133
|
+
const messageType = Message.getMessageSourceValue(meta);
|
|
134
|
+
return messageType === MetaMessageSourceType.HISTORY_MESSAGE;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
static isHistoryMessageViaMobileWBApp(meta) {
|
|
138
|
+
const messageType = Message.getMessageSourceValue(meta);
|
|
139
|
+
return messageType === MetaMessageSourceType.HISTORY_MESSAGE_VIA_MOBILE_WHATSAPP_BUSINESS_APP;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
static isMessageViaMobileWBApp(meta) {
|
|
143
|
+
const messageType = Message.getMessageSourceValue(meta);
|
|
144
|
+
return messageType === MetaMessageSourceType.VIA_MOBILE_WHATSAPP_BUSINESS_APP;
|
|
145
|
+
}
|
|
146
|
+
|
|
124
147
|
static isFailed(status) {
|
|
125
148
|
return status === MessageStatus.FAILED;
|
|
126
149
|
}
|
|
@@ -5,7 +5,11 @@ import Message from './Message';
|
|
|
5
5
|
export default class MessageWithSession {
|
|
6
6
|
constructor() {
|
|
7
7
|
let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
8
|
-
const validatedData = validateSchema(
|
|
8
|
+
const validatedData = validateSchema({
|
|
9
|
+
schema: MessageWithSessionSchema,
|
|
10
|
+
data,
|
|
11
|
+
entityName: 'MessageWithSession'
|
|
12
|
+
});
|
|
9
13
|
const messageData = new Message(validatedData).toJSON();
|
|
10
14
|
const sessionData = new Session(validatedData.session).toJSON();
|
|
11
15
|
this.data = { ...messageData,
|
|
@@ -5,7 +5,11 @@ import { SessionReplyStatus, SessionStatus } from '../../enum';
|
|
|
5
5
|
export default class Session {
|
|
6
6
|
constructor() {
|
|
7
7
|
let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
8
|
-
const validatedData = validateSchema(
|
|
8
|
+
const validatedData = validateSchema({
|
|
9
|
+
schema: SessionSchema,
|
|
10
|
+
data,
|
|
11
|
+
entityName: 'Session'
|
|
12
|
+
});
|
|
9
13
|
this.data = {
|
|
10
14
|
channelId: validatedData.channelId,
|
|
11
15
|
status: validatedData.status,
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
const MetaMessageSourceType = {
|
|
2
|
+
HISTORY_MESSAGE_VIA_MOBILE_WHATSAPP_BUSINESS_APP: 'HISTORY_MESSAGE_VIA_MOBILE_WHATSAPP_BUSINESS_APP',
|
|
3
|
+
HISTORY_MESSAGE: 'HISTORY_MESSAGE',
|
|
4
|
+
VIA_MOBILE_WHATSAPP_BUSINESS_APP: 'VIA_MOBILE_WHATSAPP_BUSINESS_APP'
|
|
5
|
+
};
|
|
6
|
+
export default MetaMessageSourceType;
|
|
@@ -10,4 +10,5 @@ import InfoAction from './InfoAction';
|
|
|
10
10
|
import ActionSubType from './ActionSubType';
|
|
11
11
|
import InfoTargetType from './InfoTargetType';
|
|
12
12
|
import MetaSystemMessageType from './MetaSystemMessageType';
|
|
13
|
-
|
|
13
|
+
import MetaMessageSourceType from './MetaMessageSourceType';
|
|
14
|
+
export { MessageTypes, MessageStatus, MessageDirection, MessageContentType, MessageMeta, ActionType, ActionSubType, ExternalInfoAction, InfoSessionStatus, InfoAction, InfoTargetType, MetaSystemMessageType, MetaMessageSourceType };
|