@zohoim/client-sdk 1.0.0-canned07 → 1.0.0-canned08

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.
@@ -9,7 +9,7 @@ export default class CannedMessage {
9
9
  const validatedData = validateSchema({
10
10
  schema: CannedMessageSchema,
11
11
  data,
12
- entityName: 'CannedMessage'
12
+ entityName: `CannedMessage${data?.id ? `_${data.id}` : ''}`
13
13
  });
14
14
  let {
15
15
  createdBy,
@@ -1,13 +1,32 @@
1
1
  import { validateSchema } from '../../../core/utils';
2
2
  import TranslationsSchema from '../../schema/cannedMessage/TranslationsSchema';
3
+ import { TemplateItemButton, TemplateItemHeader, TemplateItemFooter } from '../TemplateMessage';
3
4
  export default class Translation {
4
5
  constructor() {
5
6
  let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
6
7
  const validatedData = validateSchema({
7
8
  schema: TranslationsSchema,
8
9
  data,
9
- entityName: 'Translation'
10
+ entityName: `Translation${data?.id ? `_${data.id}` : ''}`
10
11
  });
12
+ const {
13
+ templateItems
14
+ } = validatedData;
15
+ let adaptedTemplateItems = null;
16
+
17
+ if (templateItems) {
18
+ const {
19
+ header,
20
+ footer,
21
+ buttons
22
+ } = templateItems;
23
+ adaptedTemplateItems = {
24
+ header: header ? new TemplateItemHeader(header).toJSON() : null,
25
+ footer: footer ? new TemplateItemFooter(footer).toJSON() : null,
26
+ buttons: Array.isArray(buttons) ? buttons.map(btn => new TemplateItemButton(btn).toJSON()) : null
27
+ };
28
+ }
29
+
11
30
  this.data = {
12
31
  id: validatedData.id,
13
32
  language: validatedData.language,
@@ -17,7 +36,7 @@ export default class Translation {
17
36
  status: validatedData.status,
18
37
  modifiedTime: validatedData.modifiedTime,
19
38
  failedReason: validatedData.failedReason,
20
- templateItems: validatedData.templateItems
39
+ templateItems: adaptedTemplateItems
21
40
  };
22
41
  }
23
42
 
@@ -0,0 +1,48 @@
1
+ import { validateSchema } from '../../../core/utils';
2
+ import { TemplateItemButtonType } from '../../enum';
3
+ import { TemplateItemButtonsSchema } from '../../schema';
4
+ export default class TemplateItemButton {
5
+ constructor() {
6
+ let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
7
+ const validatedData = validateSchema({
8
+ schema: TemplateItemButtonsSchema,
9
+ data,
10
+ entityName: 'TemplateItemButton'
11
+ });
12
+ this.data = {
13
+ type: validatedData.type,
14
+ message: validatedData.message,
15
+ action: validatedData.action
16
+ };
17
+ }
18
+
19
+ static isPhoneNumber(type) {
20
+ return type === TemplateItemButtonType.PHONE_NUMBER;
21
+ }
22
+
23
+ static isURL(type) {
24
+ return type === TemplateItemButtonType.URL;
25
+ }
26
+
27
+ static isCallToAction(type) {
28
+ return TemplateItemButton.isPhoneNumber(type) || TemplateItemButton.isURL(type);
29
+ }
30
+
31
+ static isQuickReply(type) {
32
+ return type === TemplateItemButtonType.QUICK_REPLY;
33
+ }
34
+
35
+ static isOTP(type) {
36
+ return type === TemplateItemButtonType.OTP;
37
+ }
38
+
39
+ static isCatalog(type) {
40
+ return type === TemplateItemButtonType.CATALOG;
41
+ }
42
+
43
+ toJSON() {
44
+ return { ...this.data
45
+ };
46
+ }
47
+
48
+ }
@@ -0,0 +1,27 @@
1
+ import { validateSchema } from '../../../core/utils';
2
+ import { TemplateItemFooterType } from '../../enum';
3
+ import { TemplateItemFooterSchema } from '../../schema';
4
+ export default class TemplateItemFooter {
5
+ constructor() {
6
+ let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
7
+ const validatedData = validateSchema({
8
+ schema: TemplateItemFooterSchema,
9
+ data,
10
+ entityName: 'TemplateItemFooter'
11
+ });
12
+ this.data = {
13
+ type: validatedData.type,
14
+ message: validatedData.message
15
+ };
16
+ }
17
+
18
+ static isText(type) {
19
+ return type === TemplateItemFooterType.TEXT;
20
+ }
21
+
22
+ toJSON() {
23
+ return { ...this.data
24
+ };
25
+ }
26
+
27
+ }
@@ -0,0 +1,48 @@
1
+ import { validateSchema } from '../../../core/utils';
2
+ import { TemplateItemHeaderType } from '../../enum';
3
+ import { TemplateItemHeaderSchema } from '../../schema';
4
+ export default class TemplateItemHeader {
5
+ constructor() {
6
+ let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
7
+ const validatedData = validateSchema({
8
+ schema: TemplateItemHeaderSchema,
9
+ data,
10
+ entityName: 'TemplateItemHeader'
11
+ });
12
+ this.data = {
13
+ type: validatedData.type,
14
+ message: validatedData.message,
15
+ attachment: validatedData.attachment
16
+ };
17
+ }
18
+
19
+ static isNone(type) {
20
+ return type === TemplateItemHeaderType.NONE;
21
+ }
22
+
23
+ static isText(type) {
24
+ return type === TemplateItemHeaderType.TEXT;
25
+ }
26
+
27
+ static isImage(type) {
28
+ return type === TemplateItemHeaderType.IMAGE;
29
+ }
30
+
31
+ static isVideo(type) {
32
+ return type === TemplateItemHeaderType.VIDEO;
33
+ }
34
+
35
+ static isDocument(type) {
36
+ return type === TemplateItemHeaderType.DOCUMENT;
37
+ }
38
+
39
+ static isMedia(type) {
40
+ return TemplateItemHeader.isImage(type) || TemplateItemHeader.isVideo(type) || TemplateItemHeader.isDocument(type);
41
+ }
42
+
43
+ toJSON() {
44
+ return { ...this.data
45
+ };
46
+ }
47
+
48
+ }
@@ -1,3 +1,6 @@
1
1
  import TemplateLanguage from './TemplateLanguage';
2
2
  import TemplateCreditExhaustStatus from './TemplateCreditExhaustStatus';
3
- export { TemplateLanguage, TemplateCreditExhaustStatus };
3
+ import TemplateItemButton from './TemplateItemButton';
4
+ import TemplateItemHeader from './TemplateItemHeader';
5
+ import TemplateItemFooter from './TemplateItemFooter';
6
+ export { TemplateLanguage, TemplateCreditExhaustStatus, TemplateItemButton, TemplateItemHeader, TemplateItemFooter };
@@ -6,6 +6,7 @@ const TemplateItemButtonType = {
6
6
  CATALOG: 'CATALOG',
7
7
  MPM: 'MPM',
8
8
  CALL_PERMISSION_REQUEST: 'CALL_PERMISSION_REQUEST',
9
- VOICE_CALL: 'VOICE_CALL'
9
+ VOICE_CALL: 'VOICE_CALL',
10
+ NONE: 'NONE'
10
11
  };
11
12
  export default TemplateItemButtonType;
@@ -1,6 +1,8 @@
1
1
  const TemplateItemHeaderType = {
2
- IMAGE: 'IMAGE',
2
+ NONE: 'NONE',
3
3
  TEXT: 'TEXT',
4
+ MEDIA: 'MEDIA',
5
+ IMAGE: 'IMAGE',
4
6
  VIDEO: 'VIDEO',
5
7
  DOCUMENT: 'DOCUMENT'
6
8
  };
@@ -11,7 +11,7 @@ const TemplateItemButtonsSchema = {
11
11
  },
12
12
  action: {
13
13
  type: 'string',
14
- required: true
14
+ required: false
15
15
  }
16
16
  };
17
17
  export default TemplateItemButtonsSchema;
@@ -1,3 +1,4 @@
1
1
  import CannedMessageSchema from './CannedMessageSchema';
2
2
  import TranslationsSchema from './TranslationsSchema';
3
+ export * from './TemplateItem';
3
4
  export { CannedMessageSchema, TranslationsSchema };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohoim/client-sdk",
3
- "version": "1.0.0-canned07",
3
+ "version": "1.0.0-canned08",
4
4
  "description": "To have the client sdk for the IM",
5
5
  "main": "es/index.js",
6
6
  "module": "es/index.js",