@zohoim/client-sdk 1.0.0-replyAreaPoc5 → 1.0.0-replyAreaPoc7

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.
@@ -1,10 +1,15 @@
1
- import { ValidationError } from '../errors'; // function validateSchemaKeys(schema, data) {
2
- // Object.keys(schema).forEach((key) => {
3
- // if (!(key in data)) {
4
- // throw new ValidationError(`Key '${key}' is missing in the data`);
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(_ref) {
22
+ function validateRequiredCheck(_ref2) {
18
23
  let {
19
24
  value,
20
25
  rules,
21
- path
22
- } = _ref;
26
+ path,
27
+ entityName
28
+ } = _ref2;
23
29
 
24
30
  if (rules.required && isEmpty(value)) {
25
- throw new ValidationError(rules.message || `${path} is required`);
31
+ console.warn(`${entityName} - ${path} is required`);
26
32
  }
27
33
  }
28
34
 
29
- function validateEnumCheck(_ref2) {
35
+ function validateEnumCheck(_ref3) {
30
36
  let {
31
37
  value,
32
38
  rules,
33
- path
34
- } = _ref2;
39
+ path,
40
+ entityName
41
+ } = _ref3;
35
42
 
36
43
  if (rules.enum && !rules.enum.includes(value)) {
37
- throw new ValidationError(`${path} must be one of: ${rules.enum.join(', ')}`);
44
+ console.warn(`${entityName} - ${path} must be one of: ${rules.enum.join(', ')}. Received: ${value}`);
38
45
  }
39
46
  }
40
47
 
41
- export const validateSchema = (schema, data) => {
42
- const validate = function (schemaObj, dataObj) {
43
- let path = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
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
- // validateSchemaKeys(schemaObj, dataObj);
46
- // Validate each field
47
- Object.entries(schemaObj).forEach(_ref3 => {
48
- let [field, rules] = _ref3;
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(rules.schema, value, fieldPath);
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(schema, data);
103
+ return validate({
104
+ schema,
105
+ data,
106
+ entityName
107
+ });
74
108
  };
@@ -15,6 +15,8 @@ function initiateSessionRequest() {
15
15
  language: null,
16
16
  parameters: {},
17
17
  message: null,
18
+ headerMessage: null,
19
+ urlMessage: null,
18
20
  ...body
19
21
  }).build();
20
22
  }
@@ -19,6 +19,7 @@ function getSessionsRequest() {
19
19
  assigneeFilter: null,
20
20
  workspaceId: null,
21
21
  botIds: null,
22
+ excludeSyncingChannels: false,
22
23
  ...query
23
24
  }).build();
24
25
  }
@@ -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(ActorSchema, data);
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(AgentSchema, data);
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(AttachmentSchema, data);
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(BotSchema, data);
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,
@@ -5,7 +5,11 @@ import { Actor } from '../Actor';
5
5
  export default class CannedMessage {
6
6
  constructor() {
7
7
  let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
8
- const validatedData = validateSchema(CannedMessageSchema, data);
8
+ const validatedData = validateSchema({
9
+ schema: CannedMessageSchema,
10
+ data,
11
+ entityName: 'CannedMessage'
12
+ });
9
13
  this.data = {
10
14
  id: validatedData.id,
11
15
  title: validatedData.title,
@@ -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(ChannelSchema, data); // Set required properties from schema
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(ContactSchema, data);
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,
@@ -3,7 +3,11 @@ import { CustomReplyExtensionSchema } from '../../schema';
3
3
  export default class CustomReplyExtension {
4
4
  constructor() {
5
5
  let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
6
- const validatedData = validateSchema(CustomReplyExtensionSchema, data);
6
+ const validatedData = validateSchema({
7
+ schema: CustomReplyExtensionSchema,
8
+ data,
9
+ entityName: 'CustomReplyExtension'
10
+ });
7
11
  this.data = {
8
12
  id: validatedData.id,
9
13
  title: validatedData.title,
@@ -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(IntegrationServiceSchema, data);
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(ActionSchema, data);
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(ExternalInfoSchema, data);
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(InfoSchema, data);
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(InfoTargetSchema, data);
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(LocationSchema, data);
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(MessageSchema, data);
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(MessageWithSessionSchema, data);
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(SessionSchema, data);
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,
@@ -4,7 +4,11 @@ import { TemplateCreditExhaustStatusSchema } from '../../schema';
4
4
  export default class TemplateCreditExhaustStatus {
5
5
  constructor() {
6
6
  let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
7
- const validatedData = validateSchema(TemplateCreditExhaustStatusSchema, data);
7
+ const validatedData = validateSchema({
8
+ schema: TemplateCreditExhaustStatusSchema,
9
+ data,
10
+ entityName: 'TemplateCreditExhaustStatus'
11
+ });
8
12
  this.data = {
9
13
  code: validatedData.code,
10
14
  message: validatedData.message
@@ -3,7 +3,11 @@ import { TemplateLanguageSchema } from '../../schema';
3
3
  export default class TemplateLanguage {
4
4
  constructor() {
5
5
  let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
6
- const validatedData = validateSchema(TemplateLanguageSchema, data);
6
+ const validatedData = validateSchema({
7
+ schema: TemplateLanguageSchema,
8
+ data,
9
+ entityName: 'TemplateLanguage'
10
+ });
7
11
  this.data = {
8
12
  code: validatedData.code,
9
13
  language: validatedData.language
@@ -1,4 +1,5 @@
1
1
  const MessageMeta = {
2
- SYSTEM_MESSAGE_TYPE: 'SYSTEM_MESSAGE_TYPE'
2
+ SYSTEM_MESSAGE_TYPE: 'SYSTEM_MESSAGE_TYPE',
3
+ MESSAGE_SOURCE: 'MESSAGE_SOURCE'
3
4
  };
4
5
  export default MessageMeta;
@@ -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
- export { MessageTypes, MessageStatus, MessageDirection, MessageContentType, MessageMeta, ActionType, ActionSubType, ExternalInfoAction, InfoSessionStatus, InfoAction, InfoTargetType, MetaSystemMessageType };
13
+ import MetaMessageSourceType from './MetaMessageSourceType';
14
+ export { MessageTypes, MessageStatus, MessageDirection, MessageContentType, MessageMeta, ActionType, ActionSubType, ExternalInfoAction, InfoSessionStatus, InfoAction, InfoTargetType, MetaSystemMessageType, MetaMessageSourceType };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohoim/client-sdk",
3
- "version": "1.0.0-replyAreaPoc5",
3
+ "version": "1.0.0-replyAreaPoc7",
4
4
  "description": "To have the client sdk for the IM",
5
5
  "main": "es/index.js",
6
6
  "module": "es/index.js",