@zohoim/client-sdk 0.0.5-poc02 → 0.0.5-poc04

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,7 +1,12 @@
1
- function validateSchemaKeys(schema, data) {
1
+ function validateSchemaKeys(_ref) {
2
+ let {
3
+ schema,
4
+ data,
5
+ entityName
6
+ } = _ref;
2
7
  Object.keys(schema).forEach(key => {
3
8
  if (!(key in data)) {
4
- console.warn(`Key '${key}' is missing in the data`);
9
+ console.warn(`${entityName} - Key '${key}' is missing in the data`);
5
10
  }
6
11
  });
7
12
  }
@@ -14,44 +19,59 @@ 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
- console.warn(`${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
- console.warn(`${path} must be one of: ${rules.enum.join(', ')}. Received: ${value}`);
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 = function (schema, data) {
49
+ let entityName = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
50
+
51
+ const validate = _ref4 => {
52
+ let {
53
+ schemaObj,
54
+ dataObj,
55
+ path = '',
56
+ entityName
57
+ } = _ref4;
44
58
  // Check if all schema keys exist in data
45
- validateSchemaKeys(schemaObj, dataObj); // Validate each field
59
+ validateSchemaKeys({
60
+ schema: schemaObj,
61
+ data: dataObj,
62
+ entityName,
63
+ path
64
+ }); // Validate each field
46
65
 
47
- Object.entries(schemaObj).forEach(_ref3 => {
48
- let [field, rules] = _ref3;
66
+ Object.entries(schemaObj).forEach(_ref5 => {
67
+ let [field, rules] = _ref5;
49
68
  const value = dataObj[field];
50
69
  const fieldPath = path ? `${path}.${field}` : field;
51
70
  validateRequiredCheck({
52
71
  value,
53
72
  rules,
54
- path: fieldPath
73
+ path: fieldPath,
74
+ entityName
55
75
  });
56
76
 
57
77
  if (value !== null && value !== undefined) {
@@ -59,16 +79,27 @@ export const validateSchema = (schema, data) => {
59
79
  validateEnumCheck({
60
80
  value,
61
81
  rules,
62
- path: fieldPath
82
+ path: fieldPath,
83
+ entityName
63
84
  }); // Nested object validation
64
85
 
65
86
  if (rules.type === 'object' && rules.schema) {
66
- validate(rules.schema, value, fieldPath);
87
+ validate({
88
+ schemaObj: rules.schema,
89
+ dataObj: value,
90
+ path: fieldPath,
91
+ entityName
92
+ });
67
93
  }
68
94
  }
69
95
  });
70
96
  return dataObj;
71
97
  };
72
98
 
73
- return validate(schema, data);
99
+ return validate({
100
+ schema,
101
+ data,
102
+ path: '',
103
+ entityName
104
+ });
74
105
  };
@@ -4,7 +4,7 @@ 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(ActorSchema, data, 'Actor');
8
8
  this.data = {
9
9
  name: validatedData.name,
10
10
  type: validatedData.type,
@@ -3,7 +3,7 @@ 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(AgentSchema, data, 'Agent');
7
7
  this.data = {
8
8
  id: validatedData.id,
9
9
  firstName: validatedData.firstName,
@@ -3,7 +3,7 @@ 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(AttachmentSchema, data, 'Attachment');
7
7
  this.data = {
8
8
  id: validatedData.id,
9
9
  name: validatedData.name,
@@ -3,7 +3,7 @@ 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(BotSchema, data, 'Bot');
7
7
  this.data = {
8
8
  id: validatedData.id,
9
9
  botServiceType: validatedData.botServiceType,
@@ -3,7 +3,7 @@ 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(ChannelSchema, data, 'Channel'); // Set required properties from schema
7
7
 
8
8
  this.id = validatedData.id;
9
9
  this.integrationService = validatedData.integrationService;
@@ -3,7 +3,7 @@ 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(ContactSchema, data, 'Contact');
7
7
  this.data = {
8
8
  id: validatedData.id,
9
9
  name: validatedData.name,
@@ -4,7 +4,7 @@ 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(IntegrationServiceSchema, data, 'IntegrationService');
8
8
  this.data = {
9
9
  label: validatedData.label || '',
10
10
  id: validatedData.id || '',
@@ -4,7 +4,7 @@ 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(ActionSchema, data, 'Action');
8
8
  this.data = {
9
9
  type: validatedData.type,
10
10
  subType: validatedData.subType,
@@ -4,7 +4,7 @@ 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(ExternalInfoSchema, data, 'ExternalInfo');
8
8
  this.data = {
9
9
  action: validatedData.action
10
10
  };
@@ -12,7 +12,7 @@ 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(InfoSchema, data, 'Info');
16
16
  this.data = {
17
17
  actor: new Actor(validatedData.actor).toJSON(),
18
18
  action: validatedData.action,
@@ -3,7 +3,7 @@ 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(InfoTargetSchema, data, 'InfoTarget');
7
7
  this.data = {
8
8
  id: validatedData.id,
9
9
  name: validatedData.name || null,
@@ -3,7 +3,7 @@ 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(LocationSchema, data, 'Location');
7
7
  this.data = {
8
8
  latitude: validatedData.latitude,
9
9
  longitude: validatedData.longitude
@@ -10,7 +10,7 @@ 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(MessageSchema, data, 'Message');
14
14
  this.data = {
15
15
  id: validatedData.id,
16
16
  sessionId: validatedData.sessionId,
@@ -5,7 +5,7 @@ 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(MessageWithSessionSchema, data, 'MessageWithSession');
9
9
  const messageData = new Message(validatedData).toJSON();
10
10
  const sessionData = new Session(validatedData.session).toJSON();
11
11
  this.data = { ...messageData,
@@ -5,7 +5,7 @@ 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(SessionSchema, data, 'Session');
9
9
  this.data = {
10
10
  channelId: validatedData.channelId,
11
11
  status: validatedData.status,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohoim/client-sdk",
3
- "version": "0.0.5-poc02",
3
+ "version": "0.0.5-poc04",
4
4
  "description": "To have the client sdk for the IM",
5
5
  "main": "es/index.js",
6
6
  "module": "es/index.js",