@zohoim/client-sdk 1.0.0-leftPanelPoc2 → 1.0.0-leftPanelPoc4

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.
Files changed (44) hide show
  1. package/es/application/services/index.js +2 -1
  2. package/es/application/services/whatsAppPricing/WhatsAppPricingService.js +21 -0
  3. package/es/application/services/whatsAppPricing/index.js +2 -0
  4. package/es/core/constants/ModuleNames.js +2 -1
  5. package/es/core/constants/ModuleTypes.js +5 -0
  6. package/es/core/constants/index.js +2 -1
  7. package/es/core/utils/validateSchema.js +25 -0
  8. package/es/domain/dto/index.js +2 -1
  9. package/es/domain/dto/sessions/getSessionAttachmentsRequest.js +6 -1
  10. package/es/domain/dto/whatsAppPricing/calculateWhatsAppPricingRequest.js +14 -0
  11. package/es/domain/dto/whatsAppPricing/index.js +1 -0
  12. package/es/domain/entities/WhatsAppPricing/WhatsAppPricing.js +25 -0
  13. package/es/domain/entities/WhatsAppPricing/WhatsAppPricingCategory.js +22 -0
  14. package/es/domain/entities/WhatsAppPricing/index.js +3 -0
  15. package/es/domain/entities/index.js +2 -1
  16. package/es/domain/interfaces/repositories/index.js +2 -1
  17. package/es/domain/interfaces/repositories/whatsAppPricing/IWhatsAppPricingRepository.js +18 -0
  18. package/es/domain/interfaces/repositories/whatsAppPricing/index.js +2 -0
  19. package/es/domain/schema/index.js +2 -1
  20. package/es/domain/schema/whatsAppPricing/WhatsAppPricingCategorySchema.js +11 -0
  21. package/es/domain/schema/whatsAppPricing/WhatsAppPricingSchema.js +21 -0
  22. package/es/domain/schema/whatsAppPricing/index.js +3 -0
  23. package/es/frameworks/managers/ModuleFactory.js +61 -30
  24. package/es/frameworks/managers/ModuleManager.js +25 -2
  25. package/es/frameworks/sdk/IMSDK.js +20 -13
  26. package/es/frameworks/sdk/whatsAppPricing/WhatsAppPricingSDK.js +28 -0
  27. package/es/frameworks/sdk/whatsAppPricing/index.js +2 -0
  28. package/es/infrastructure/adapters/index.js +2 -1
  29. package/es/infrastructure/adapters/whatsAppPricing/WhatsAppPricingAdapter.js +22 -0
  30. package/es/infrastructure/adapters/whatsAppPricing/index.js +2 -0
  31. package/es/infrastructure/api/BaseAPI.js +5 -4
  32. package/es/infrastructure/api/index.js +2 -1
  33. package/es/infrastructure/api/registry/createPublicBaseUrl.js +4 -0
  34. package/es/infrastructure/api/registry/getRegistryConfig.js +3 -1
  35. package/es/infrastructure/api/registry/whatsAppPricing/constructWhatsAppPricingEndPoint.js +10 -0
  36. package/es/infrastructure/api/registry/whatsAppPricing/index.js +2 -0
  37. package/es/infrastructure/api/registry/whatsAppPricing/whatsAppPricingAPIRegistry.js +13 -0
  38. package/es/infrastructure/api/whatsAppPricing/WhatsAppPricingAPI.js +14 -0
  39. package/es/infrastructure/api/whatsAppPricing/index.js +2 -0
  40. package/es/infrastructure/config/configRegistry.js +8 -1
  41. package/es/infrastructure/repositories/index.js +2 -1
  42. package/es/infrastructure/repositories/whatsAppPricing/WhatsAppPricingRepository.js +49 -0
  43. package/es/infrastructure/repositories/whatsAppPricing/index.js +2 -0
  44. package/package.json +1 -1
@@ -7,4 +7,5 @@ export * from './contacts';
7
7
  export * from './cannedMessages';
8
8
  export * from './templateMessages';
9
9
  export * from './integrationServices';
10
- export * from './userPreferences';
10
+ export * from './userPreferences';
11
+ export * from './whatsAppPricing';
@@ -0,0 +1,21 @@
1
+ import { IWhatsAppPricingRepository } from '../../../domain/interfaces/repositories';
2
+ export default class WhatsAppPricingService extends IWhatsAppPricingRepository {
3
+ constructor(_ref) {
4
+ let {
5
+ whatsAppPricingRepository
6
+ } = _ref;
7
+ super();
8
+ this.whatsAppPricingRepository = whatsAppPricingRepository;
9
+ }
10
+
11
+ async calculateWhatsAppPricing(request) {
12
+ return this.whatsAppPricingRepository.calculateWhatsAppPricing(request);
13
+ }
14
+
15
+ toJSON() {
16
+ return {
17
+ calculateWhatsAppPricing: this.calculateWhatsAppPricing.bind(this)
18
+ };
19
+ }
20
+
21
+ }
@@ -0,0 +1,2 @@
1
+ import WhatsAppPricingService from './WhatsAppPricingService';
2
+ export { WhatsAppPricingService };
@@ -9,6 +9,7 @@ const ModuleNames = {
9
9
  TEMPLATE_MESSAGES: 'templateMessages',
10
10
  CUSTOM_REPLY_EXTENSIONS: 'articles',
11
11
  INTEGRATION_SERVICES: 'integrationServices',
12
- USER_PREFERENCES: 'userPreferences'
12
+ USER_PREFERENCES: 'userPreferences',
13
+ WHATSAPP_PRICING: 'whatsAppPricing'
13
14
  };
14
15
  export default ModuleNames;
@@ -0,0 +1,5 @@
1
+ const ModuleTypes = {
2
+ AUTHENTICATED: 'authenticated',
3
+ PUBLIC: 'public'
4
+ };
5
+ export default ModuleTypes;
@@ -1,6 +1,7 @@
1
1
  import { HttpMethods } from '@zohoim/http-client';
2
2
  import ModuleNames from './ModuleNames';
3
+ import ModuleTypes from './ModuleTypes';
3
4
  import ResponseTypes from './ResponseTypes';
4
5
  const IM_API_PREFIX = '/api/v1';
5
6
  const HTTP_METHODS = HttpMethods;
6
- export { ModuleNames, IM_API_PREFIX, HTTP_METHODS, ResponseTypes };
7
+ export { ModuleNames, ModuleTypes, IM_API_PREFIX, HTTP_METHODS, ResponseTypes };
@@ -94,6 +94,31 @@ export const validateSchema = _ref4 => {
94
94
  path: fieldPath,
95
95
  entityName
96
96
  });
97
+ } // Array validation — schema (objects) or enum (primitives), not both
98
+
99
+
100
+ if (rules.type === 'array' && Array.isArray(value)) {
101
+ if (rules.schema && rules.enum) {
102
+ console.warn(`${entityName} - ${fieldPath} must define either schema or enum for array, not both`);
103
+ } else if (rules.schema) {
104
+ value.forEach((item, index) => {
105
+ validate({
106
+ schema: rules.schema,
107
+ data: item,
108
+ path: `${fieldPath}[${index}]`,
109
+ entityName
110
+ });
111
+ });
112
+ } else if (rules.enum) {
113
+ value.forEach((item, index) => {
114
+ validateEnumCheck({
115
+ value: item,
116
+ rules,
117
+ path: `${fieldPath}[${index}]`,
118
+ entityName
119
+ });
120
+ });
121
+ }
97
122
  }
98
123
  }
99
124
  });
@@ -7,4 +7,5 @@ export * from './contacts';
7
7
  export * from './cannedMessages';
8
8
  export * from './templateMessages';
9
9
  export * from './integrationServices';
10
- export * from './userPreferences';
10
+ export * from './userPreferences';
11
+ export * from './whatsAppPricing';
@@ -2,11 +2,16 @@ import RequestBuilder from '../RequestBuilder';
2
2
 
3
3
  function getSessionAttachmentsRequest() {
4
4
  let {
5
- params = {}
5
+ params = {},
6
+ query = {}
6
7
  } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
7
8
  return new RequestBuilder().withParams({
8
9
  sessionId: null,
9
10
  ...params
11
+ }).withQuery({
12
+ from: null,
13
+ limit: null,
14
+ ...query
10
15
  }).build();
11
16
  }
12
17
 
@@ -0,0 +1,14 @@
1
+ import RequestBuilder from '../RequestBuilder';
2
+
3
+ function calculateWhatsAppPricingRequest() {
4
+ let {
5
+ body = {}
6
+ } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
7
+ return new RequestBuilder().withBody({
8
+ currency: null,
9
+ data: null,
10
+ ...body
11
+ }).build();
12
+ }
13
+
14
+ export default calculateWhatsAppPricingRequest;
@@ -0,0 +1 @@
1
+ export { default as calculateWhatsAppPricingRequest } from './calculateWhatsAppPricingRequest';
@@ -0,0 +1,25 @@
1
+ import { validateSchema } from '../../../core/utils';
2
+ import { WhatsAppPricingSchema } from '../../schema';
3
+ import WhatsAppPricingCategory from './WhatsAppPricingCategory';
4
+ export default class WhatsAppPricing {
5
+ constructor() {
6
+ let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
7
+ const validatedData = validateSchema({
8
+ schema: WhatsAppPricingSchema,
9
+ data,
10
+ entityName: 'WhatsAppPricing'
11
+ });
12
+ this.data = {
13
+ total: validatedData.total,
14
+ creditsCount: validatedData.creditsCount,
15
+ actutalCreditsAmount: validatedData.actutalCreditsAmount,
16
+ category: validatedData.category.map(item => new WhatsAppPricingCategory(item).toJSON())
17
+ };
18
+ }
19
+
20
+ toJSON() {
21
+ return { ...this.data
22
+ };
23
+ }
24
+
25
+ }
@@ -0,0 +1,22 @@
1
+ import { validateSchema } from '../../../core/utils';
2
+ import { WhatsAppPricingCategorySchema } from '../../schema';
3
+ export default class WhatsAppPricingCategory {
4
+ constructor() {
5
+ let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
6
+ const validatedData = validateSchema({
7
+ schema: WhatsAppPricingCategorySchema,
8
+ data,
9
+ entityName: 'WhatsAppPricingCategory'
10
+ });
11
+ this.data = {
12
+ type: validatedData.type,
13
+ value: validatedData.value
14
+ };
15
+ }
16
+
17
+ toJSON() {
18
+ return { ...this.data
19
+ };
20
+ }
21
+
22
+ }
@@ -0,0 +1,3 @@
1
+ import WhatsAppPricing from './WhatsAppPricing';
2
+ import WhatsAppPricingCategory from './WhatsAppPricingCategory';
3
+ export { WhatsAppPricing, WhatsAppPricingCategory };
@@ -10,4 +10,5 @@ export * from './IntegrationService';
10
10
  export * from './CannedMessage';
11
11
  export * from './TemplateMessage';
12
12
  export * from './CustomReplyExtension';
13
- export * from './UserPreference';
13
+ export * from './UserPreference';
14
+ export * from './WhatsAppPricing';
@@ -7,4 +7,5 @@ export * from './contacts';
7
7
  export * from './cannedMessages';
8
8
  export * from './templateMessages';
9
9
  export * from './integrationServices';
10
- export * from './userPreferences';
10
+ export * from './userPreferences';
11
+ export * from './whatsAppPricing';
@@ -0,0 +1,18 @@
1
+ /* eslint-disable no-unused-vars */
2
+ import { ModuleNames, ModuleTypes } from '../../../../core/constants';
3
+ import BaseAPI from '../../../../infrastructure/api/BaseAPI';
4
+ import { calculateWhatsAppPricingRequest } from '../../../dto';
5
+ export default class IWhatsAppPricingRepository extends BaseAPI {
6
+ constructor() {
7
+ super({
8
+ module: ModuleNames.WHATSAPP_PRICING,
9
+ moduleType: ModuleTypes.PUBLIC
10
+ });
11
+ }
12
+
13
+ async calculateWhatsAppPricing() {
14
+ let request = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : calculateWhatsAppPricingRequest();
15
+ throw new Error('Method not implemented');
16
+ }
17
+
18
+ }
@@ -0,0 +1,2 @@
1
+ import IWhatsAppPricingRepository from './IWhatsAppPricingRepository';
2
+ export { IWhatsAppPricingRepository };
@@ -9,4 +9,5 @@ export * from './contact';
9
9
  export * from './cannedMessage';
10
10
  export * from './templateMessage';
11
11
  export * from './customReplyExtension';
12
- export * from './userPreference';
12
+ export * from './userPreference';
13
+ export * from './whatsAppPricing';
@@ -0,0 +1,11 @@
1
+ const WhatsAppPricingCategorySchema = {
2
+ type: {
3
+ type: 'string',
4
+ required: true
5
+ },
6
+ value: {
7
+ type: 'number',
8
+ required: true
9
+ }
10
+ };
11
+ export default WhatsAppPricingCategorySchema;
@@ -0,0 +1,21 @@
1
+ import WhatsAppPricingCategorySchema from './WhatsAppPricingCategorySchema';
2
+ const WhatsAppPricingSchema = {
3
+ total: {
4
+ type: 'number',
5
+ required: true
6
+ },
7
+ creditsCount: {
8
+ type: 'number',
9
+ required: true
10
+ },
11
+ actutalCreditsAmount: {
12
+ type: 'number',
13
+ required: true
14
+ },
15
+ category: {
16
+ type: 'array',
17
+ required: true,
18
+ schema: WhatsAppPricingCategorySchema
19
+ }
20
+ };
21
+ export default WhatsAppPricingSchema;
@@ -0,0 +1,3 @@
1
+ import WhatsAppPricingSchema from './WhatsAppPricingSchema';
2
+ import WhatsAppPricingCategorySchema from './WhatsAppPricingCategorySchema';
3
+ export { WhatsAppPricingSchema, WhatsAppPricingCategorySchema };
@@ -1,4 +1,4 @@
1
- import { ModuleNames } from '../../core/constants';
1
+ import { ModuleNames, ModuleTypes } from '../../core/constants';
2
2
  import { BotSDK } from '../sdk/bots';
3
3
  import { ChannelSDK } from '../sdk/channels';
4
4
  import { SessionSDK } from '../sdk/sessions';
@@ -7,6 +7,7 @@ import { AgentSDK } from '../sdk/agents';
7
7
  import { ContactSDK } from '../sdk/contacts';
8
8
  import { CannedMessageSDK } from '../sdk/cannedMessages';
9
9
  import { TemplateMessageSDK } from '../sdk/templateMessages';
10
+ import { WhatsAppPricingSDK } from '../sdk/whatsAppPricing';
10
11
  import { IntegrationServiceSDK } from '../sdk/integrationServices';
11
12
  import { UserPreferencesSDK } from '../sdk/userPreferences';
12
13
  const ModuleFactory = {
@@ -14,81 +15,111 @@ const ModuleFactory = {
14
15
  let {
15
16
  config
16
17
  } = _ref;
17
- return new ChannelSDK({
18
- config
19
- }).toJSON();
18
+ return {
19
+ [ModuleTypes.AUTHENTICATED]: new ChannelSDK({
20
+ config
21
+ }).toJSON()
22
+ };
20
23
  },
21
24
  [ModuleNames.SESSIONS]: _ref2 => {
22
25
  let {
23
26
  config
24
27
  } = _ref2;
25
- return new SessionSDK({
26
- config
27
- }).toJSON();
28
+ return {
29
+ [ModuleTypes.AUTHENTICATED]: new SessionSDK({
30
+ config
31
+ }).toJSON()
32
+ };
28
33
  },
29
34
  [ModuleNames.BOTS]: _ref3 => {
30
35
  let {
31
36
  config
32
37
  } = _ref3;
33
- return new BotSDK({
34
- config
35
- }).toJSON();
38
+ return {
39
+ [ModuleTypes.AUTHENTICATED]: new BotSDK({
40
+ config
41
+ }).toJSON()
42
+ };
36
43
  },
37
44
  [ModuleNames.AGENTS]: _ref4 => {
38
45
  let {
39
46
  config
40
47
  } = _ref4;
41
- return new AgentSDK({
42
- config
43
- }).toJSON();
48
+ return {
49
+ [ModuleTypes.AUTHENTICATED]: new AgentSDK({
50
+ config
51
+ }).toJSON()
52
+ };
44
53
  },
45
54
  [ModuleNames.CONTACTS]: _ref5 => {
46
55
  let {
47
56
  config
48
57
  } = _ref5;
49
- return new ContactSDK({
50
- config
51
- }).toJSON();
58
+ return {
59
+ [ModuleTypes.AUTHENTICATED]: new ContactSDK({
60
+ config
61
+ }).toJSON()
62
+ };
52
63
  },
53
64
  [ModuleNames.MESSAGES]: _ref6 => {
54
65
  let {
55
66
  config
56
67
  } = _ref6;
57
- return new MessageSDK({
58
- config
59
- }).toJSON();
68
+ return {
69
+ [ModuleTypes.AUTHENTICATED]: new MessageSDK({
70
+ config
71
+ }).toJSON()
72
+ };
60
73
  },
61
74
  [ModuleNames.CANNED_MESSAGES]: _ref7 => {
62
75
  let {
63
76
  config
64
77
  } = _ref7;
65
- return new CannedMessageSDK({
66
- config
67
- }).toJSON();
78
+ return {
79
+ [ModuleTypes.AUTHENTICATED]: new CannedMessageSDK({
80
+ config
81
+ }).toJSON()
82
+ };
68
83
  },
69
84
  [ModuleNames.TEMPLATE_MESSAGES]: _ref8 => {
70
85
  let {
71
86
  config
72
87
  } = _ref8;
73
- return new TemplateMessageSDK({
74
- config
75
- }).toJSON();
88
+ return {
89
+ [ModuleTypes.AUTHENTICATED]: new TemplateMessageSDK({
90
+ config
91
+ }).toJSON()
92
+ };
76
93
  },
77
94
  [ModuleNames.INTEGRATION_SERVICES]: _ref9 => {
78
95
  let {
79
96
  config
80
97
  } = _ref9;
81
- return new IntegrationServiceSDK({
82
- config
83
- }).toJSON();
98
+ return {
99
+ [ModuleTypes.AUTHENTICATED]: new IntegrationServiceSDK({
100
+ config
101
+ }).toJSON()
102
+ };
84
103
  },
85
104
  [ModuleNames.USER_PREFERENCES]: _ref10 => {
86
105
  let {
87
106
  config
88
107
  } = _ref10;
89
- return new UserPreferencesSDK({
108
+ return {
109
+ [ModuleTypes.AUTHENTICATED]: new UserPreferencesSDK({
110
+ config
111
+ }).toJSON()
112
+ };
113
+ },
114
+ [ModuleNames.WHATSAPP_PRICING]: _ref11 => {
115
+ let {
90
116
  config
91
- }).toJSON();
117
+ } = _ref11;
118
+ return {
119
+ [ModuleTypes.PUBLIC]: new WhatsAppPricingSDK({
120
+ config
121
+ }).toJSON()
122
+ };
92
123
  }
93
124
  };
94
125
  export default ModuleFactory;
@@ -1,9 +1,9 @@
1
- import { ModuleNames } from '../../core/constants';
1
+ import { ModuleNames, ModuleTypes } from '../../core/constants';
2
2
  import ModuleFactory from './ModuleFactory';
3
3
  export default class ModuleManager {
4
4
  constructor() {
5
5
  this._modules = new Map();
6
- this.supportedModules = [ModuleNames.CHANNELS, ModuleNames.SESSIONS, ModuleNames.BOTS, ModuleNames.MESSAGES, ModuleNames.AGENTS, ModuleNames.CONTACTS, ModuleNames.CANNED_MESSAGES, ModuleNames.TEMPLATE_MESSAGES, ModuleNames.INTEGRATION_SERVICES, ModuleNames.USER_PREFERENCES];
6
+ this.supportedModules = [ModuleNames.CHANNELS, ModuleNames.SESSIONS, ModuleNames.BOTS, ModuleNames.MESSAGES, ModuleNames.AGENTS, ModuleNames.CONTACTS, ModuleNames.CANNED_MESSAGES, ModuleNames.TEMPLATE_MESSAGES, ModuleNames.INTEGRATION_SERVICES, ModuleNames.USER_PREFERENCES, ModuleNames.WHATSAPP_PRICING];
7
7
  }
8
8
 
9
9
  initialize(_ref) {
@@ -37,6 +37,29 @@ export default class ModuleManager {
37
37
  return this._modules.get(moduleName);
38
38
  }
39
39
 
40
+ getModuleByType(moduleName) {
41
+ let type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ModuleTypes.AUTHENTICATED;
42
+ const moduleEntry = this.getModule(moduleName);
43
+
44
+ if (!moduleEntry) {
45
+ return undefined;
46
+ }
47
+
48
+ return moduleEntry[type];
49
+ }
50
+
51
+ getModulesByType(type) {
52
+ const result = {};
53
+
54
+ this._modules.forEach((moduleEntry, moduleName) => {
55
+ if (moduleEntry[type]) {
56
+ result[moduleName] = moduleEntry[type];
57
+ }
58
+ });
59
+
60
+ return result;
61
+ }
62
+
40
63
  hasModule(moduleName) {
41
64
  return this._modules.has(moduleName);
42
65
  }
@@ -1,4 +1,4 @@
1
- import { ModuleNames } from '../../core/constants';
1
+ import { ModuleNames, ModuleTypes } from '../../core/constants';
2
2
  import configRegistry from '../../infrastructure/config/configRegistry';
3
3
  import { ModuleManager } from '../managers';
4
4
  export default class IMSDK {
@@ -6,11 +6,13 @@ export default class IMSDK {
6
6
  let {
7
7
  baseURL,
8
8
  apiConfig = {},
9
- httpClient
9
+ httpClient,
10
+ publicHttpClient
10
11
  } = _ref;
11
12
  configRegistry.setConfig({
12
13
  baseURL,
13
- httpClient
14
+ httpClient,
15
+ publicHttpClient
14
16
  });
15
17
  this._moduleManager = new ModuleManager();
16
18
 
@@ -20,43 +22,47 @@ export default class IMSDK {
20
22
  }
21
23
 
22
24
  get channels() {
23
- return this._moduleManager.getModule(ModuleNames.CHANNELS);
25
+ return this._moduleManager.getModuleByType(ModuleNames.CHANNELS);
24
26
  }
25
27
 
26
28
  get sessions() {
27
- return this._moduleManager.getModule(ModuleNames.SESSIONS);
29
+ return this._moduleManager.getModuleByType(ModuleNames.SESSIONS);
28
30
  }
29
31
 
30
32
  get bots() {
31
- return this._moduleManager.getModule(ModuleNames.BOTS);
33
+ return this._moduleManager.getModuleByType(ModuleNames.BOTS);
32
34
  }
33
35
 
34
36
  get messages() {
35
- return this._moduleManager.getModule(ModuleNames.MESSAGES);
37
+ return this._moduleManager.getModuleByType(ModuleNames.MESSAGES);
36
38
  }
37
39
 
38
40
  get agents() {
39
- return this._moduleManager.getModule(ModuleNames.AGENTS);
41
+ return this._moduleManager.getModuleByType(ModuleNames.AGENTS);
40
42
  }
41
43
 
42
44
  get contacts() {
43
- return this._moduleManager.getModule(ModuleNames.CONTACTS);
45
+ return this._moduleManager.getModuleByType(ModuleNames.CONTACTS);
44
46
  }
45
47
 
46
48
  get cannedMessages() {
47
- return this._moduleManager.getModule(ModuleNames.CANNED_MESSAGES);
49
+ return this._moduleManager.getModuleByType(ModuleNames.CANNED_MESSAGES);
48
50
  }
49
51
 
50
52
  get templateMessages() {
51
- return this._moduleManager.getModule(ModuleNames.TEMPLATE_MESSAGES);
53
+ return this._moduleManager.getModuleByType(ModuleNames.TEMPLATE_MESSAGES);
54
+ }
55
+
56
+ get public() {
57
+ return this._moduleManager.getModulesByType(ModuleTypes.PUBLIC);
52
58
  }
53
59
 
54
60
  get integrationServices() {
55
- return this._moduleManager.getModule(ModuleNames.INTEGRATION_SERVICES);
61
+ return this._moduleManager.getModuleByType(ModuleNames.INTEGRATION_SERVICES);
56
62
  }
57
63
 
58
64
  get userPreferences() {
59
- return this._moduleManager.getModule(ModuleNames.USER_PREFERENCES);
65
+ return this._moduleManager.getModuleByType(ModuleNames.USER_PREFERENCES);
60
66
  }
61
67
 
62
68
  hasModule(moduleName) {
@@ -75,6 +81,7 @@ export default class IMSDK {
75
81
  templateMessages: this.templateMessages,
76
82
  integrationServices: this.integrationServices,
77
83
  userPreferences: this.userPreferences,
84
+ public: this.public,
78
85
  hasModule: this.hasModule.bind(this)
79
86
  };
80
87
  }
@@ -0,0 +1,28 @@
1
+ import { WhatsAppPricingService } from '../../../application/services';
2
+ import { WhatsAppPricingRepository } from '../../../infrastructure/repositories';
3
+
4
+ class WhatsAppPricingSDK {
5
+ constructor(_ref) {
6
+ let {
7
+ config
8
+ } = _ref;
9
+ const {
10
+ whatsAppPricingAPI
11
+ } = config;
12
+ const whatsAppPricingRepository = new WhatsAppPricingRepository({
13
+ whatsAppPricingAPI
14
+ }).toJSON();
15
+ const whatsAppPricingService = new WhatsAppPricingService({
16
+ whatsAppPricingRepository
17
+ }).toJSON();
18
+ this.services = { ...whatsAppPricingService
19
+ };
20
+ }
21
+
22
+ toJSON() {
23
+ return this.services;
24
+ }
25
+
26
+ }
27
+
28
+ export default WhatsAppPricingSDK;
@@ -0,0 +1,2 @@
1
+ import WhatsAppPricingSDK from './WhatsAppPricingSDK';
2
+ export { WhatsAppPricingSDK };
@@ -9,4 +9,5 @@ export * from './cannedMessages';
9
9
  export * from './templateMessages';
10
10
  export * from './customReplyExtension';
11
11
  export * from './integrationServices';
12
- export * from './userPreferences';
12
+ export * from './userPreferences';
13
+ export * from './whatsAppPricing';
@@ -0,0 +1,22 @@
1
+ import { AdapterError } from '../../../core/errors';
2
+ import { WhatsAppPricing } from '../../../domain/entities';
3
+ import { IAdapter } from '../../../domain/interfaces';
4
+ export default class WhatsAppPricingAdapter extends IAdapter {
5
+ adapt(whatsAppPricingData) {
6
+ if (!whatsAppPricingData) {
7
+ throw new AdapterError('whatsAppPricing data is required');
8
+ }
9
+
10
+ try {
11
+ return new WhatsAppPricing({
12
+ total: whatsAppPricingData.total,
13
+ creditsCount: whatsAppPricingData.creditsCount,
14
+ actutalCreditsAmount: whatsAppPricingData.actutalCreditsAmount,
15
+ category: whatsAppPricingData.category
16
+ }).toJSON();
17
+ } catch (error) {
18
+ throw new AdapterError(`Failed to adapt WhatsAppPricing: ${error.message}`);
19
+ }
20
+ }
21
+
22
+ }
@@ -0,0 +1,2 @@
1
+ import WhatsAppPricingAdapter from './WhatsAppPricingAdapter';
2
+ export { WhatsAppPricingAdapter };
@@ -1,4 +1,4 @@
1
- import { ResponseTypes } from '../../core/constants';
1
+ import { ModuleTypes, ResponseTypes } from '../../core/constants';
2
2
  import { ResponseUtils } from '../../core/utils';
3
3
  import configRegistry from '../config/configRegistry';
4
4
  import { getRegistryConfig } from './registry';
@@ -7,18 +7,19 @@ export default class BaseAPI {
7
7
  constructor() {
8
8
  let {
9
9
  module,
10
+ moduleType = ModuleTypes.AUTHENTICATED,
10
11
  configProvider = configRegistry,
11
12
  registryProvider = {
12
13
  getRegistryConfig
13
14
  },
14
- urlBuilder = new UrlBuilder()
15
+ urlBuilder
15
16
  } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
16
17
  this.configProvider = configProvider;
17
18
  this.registryProvider = registryProvider;
18
- this.httpClient = this.configProvider.getHttpClient();
19
+ this.httpClient = moduleType === ModuleTypes.PUBLIC ? this.configProvider.getPublicHttpClient() : this.configProvider.getHttpClient();
19
20
  this.baseURL = this.configProvider.getBaseURL();
20
21
  this.module = module;
21
- this.urlBuilder = urlBuilder;
22
+ this.urlBuilder = urlBuilder || new UrlBuilder(this.baseURL);
22
23
  }
23
24
 
24
25
  async request(_ref) {
@@ -7,4 +7,5 @@ export * from './contacts';
7
7
  export * from './cannedMessages';
8
8
  export * from './templateMessages';
9
9
  export * from './integrationServices';
10
- export * from './userPreferences';
10
+ export * from './userPreferences';
11
+ export * from './whatsAppPricing';
@@ -0,0 +1,4 @@
1
+ import createBaseUrl from './createBaseUrl';
2
+ export default function createPublicBaseUrl(path) {
3
+ return createBaseUrl(`/public${path}`);
4
+ }
@@ -8,6 +8,7 @@ import { contactAPIRegistry } from './contacts';
8
8
  import { cannedMessageAPIRegistry } from './cannedMessages';
9
9
  import { templateMessageAPIRegistry } from './templateMessages';
10
10
  import { integrationServiceAPIRegistry } from './integrationServices';
11
+ import { whatsAppPricingAPIRegistry } from './whatsAppPricing';
11
12
  import { ModuleNames } from '../../../core/constants';
12
13
  import { userPreferenceAPIRegistry } from './userPreferences';
13
14
  const APIRegistry = {
@@ -20,7 +21,8 @@ const APIRegistry = {
20
21
  [ModuleNames.CANNED_MESSAGES]: cannedMessageAPIRegistry,
21
22
  [ModuleNames.TEMPLATE_MESSAGES]: templateMessageAPIRegistry,
22
23
  [ModuleNames.INTEGRATION_SERVICES]: integrationServiceAPIRegistry,
23
- [ModuleNames.USER_PREFERENCES]: userPreferenceAPIRegistry
24
+ [ModuleNames.USER_PREFERENCES]: userPreferenceAPIRegistry,
25
+ [ModuleNames.WHATSAPP_PRICING]: whatsAppPricingAPIRegistry
24
26
  };
25
27
  export default function getRegistryConfig(module, operation) {
26
28
  const moduleConfig = selectn(module, APIRegistry);
@@ -0,0 +1,10 @@
1
+ import createPublicBaseUrl from '../createPublicBaseUrl';
2
+ export default function constructWhatsAppPricingEndPoint(extra) {
3
+ const base = '/whatsAppPricing';
4
+
5
+ if (extra) {
6
+ return createPublicBaseUrl(base + extra);
7
+ }
8
+
9
+ return createPublicBaseUrl(base);
10
+ }
@@ -0,0 +1,2 @@
1
+ import whatsAppPricingAPIRegistry from './whatsAppPricingAPIRegistry';
2
+ export { whatsAppPricingAPIRegistry };
@@ -0,0 +1,13 @@
1
+ import { HTTP_METHODS } from '../../../../core/constants';
2
+ import { calculateWhatsAppPricingRequest } from '../../../../domain/dto';
3
+ import createAPIRegistry from '../createAPIRegistry';
4
+ import constructWhatsAppPricingEndPoint from './constructWhatsAppPricingEndPoint';
5
+
6
+ function calculateWhatsAppPricing() {
7
+ return createAPIRegistry(constructWhatsAppPricingEndPoint(), HTTP_METHODS.POST, calculateWhatsAppPricingRequest());
8
+ }
9
+
10
+ const whatsAppPricingAPIRegistry = {
11
+ calculateWhatsAppPricing
12
+ };
13
+ export default whatsAppPricingAPIRegistry;
@@ -0,0 +1,14 @@
1
+ import { calculateWhatsAppPricingRequest } from '../../../domain/dto';
2
+ import { IWhatsAppPricingRepository } from '../../../domain/interfaces/repositories';
3
+ export default class WhatsAppPricingAPI extends IWhatsAppPricingRepository {
4
+ async calculateWhatsAppPricing() {
5
+ let request = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : calculateWhatsAppPricingRequest();
6
+ const operation = 'calculateWhatsAppPricing';
7
+ const httpRequest = await this.request({
8
+ request,
9
+ operation
10
+ });
11
+ return httpRequest;
12
+ }
13
+
14
+ }
@@ -0,0 +1,2 @@
1
+ import WhatsAppPricingAPI from './WhatsAppPricingAPI';
2
+ export { WhatsAppPricingAPI };
@@ -2,15 +2,18 @@ class ConfigRegistry {
2
2
  constructor() {
3
3
  this.baseURL = null;
4
4
  this.httpClient = null;
5
+ this.publicHttpClient = null;
5
6
  }
6
7
 
7
8
  setConfig(_ref) {
8
9
  let {
9
10
  baseURL,
10
- httpClient
11
+ httpClient,
12
+ publicHttpClient
11
13
  } = _ref;
12
14
  this.baseURL = baseURL;
13
15
  this.httpClient = httpClient;
16
+ this.publicHttpClient = publicHttpClient || null;
14
17
  }
15
18
 
16
19
  getBaseURL() {
@@ -21,6 +24,10 @@ class ConfigRegistry {
21
24
  return this.httpClient;
22
25
  }
23
26
 
27
+ getPublicHttpClient() {
28
+ return this.publicHttpClient;
29
+ }
30
+
24
31
  }
25
32
 
26
33
  const configRegistry = new ConfigRegistry();
@@ -7,4 +7,5 @@ export * from './contacts';
7
7
  export * from './cannedMessages';
8
8
  export * from './templateMessages';
9
9
  export * from './integrationServices';
10
- export * from './userPreferences';
10
+ export * from './userPreferences';
11
+ export * from './whatsAppPricing';
@@ -0,0 +1,49 @@
1
+ import { IWhatsAppPricingRepository } from '../../../domain/interfaces/repositories';
2
+ import { WhatsAppPricingAdapter } from '../../adapters';
3
+ import { WhatsAppPricingAPI } from '../../api';
4
+ import { ResponseTypes } from '../../../core/constants';
5
+ export default class WhatsAppPricingRepository extends IWhatsAppPricingRepository {
6
+ constructor(_ref) {
7
+ let {
8
+ whatsAppPricingAPI,
9
+ whatsAppPricingAdapter
10
+ } = _ref;
11
+ super();
12
+ this.defaultAPI = new WhatsAppPricingAPI();
13
+ this.customAPI = whatsAppPricingAPI;
14
+ this.whatsAppPricingAPI = this.createAPIProxy(this.customAPI, this.defaultAPI);
15
+ this.whatsAppPricingAdapter = whatsAppPricingAdapter || new WhatsAppPricingAdapter();
16
+ }
17
+
18
+ async invokeAPI(_ref2) {
19
+ let {
20
+ operation,
21
+ request,
22
+ adapter = this.whatsAppPricingAdapter,
23
+ responseType
24
+ } = _ref2;
25
+ return this.executeAPICall({
26
+ operation,
27
+ request,
28
+ apiProxy: this.whatsAppPricingAPI,
29
+ customAPI: this.customAPI,
30
+ adapter,
31
+ responseType
32
+ });
33
+ }
34
+
35
+ async calculateWhatsAppPricing(request) {
36
+ return this.invokeAPI({
37
+ operation: 'calculateWhatsAppPricing',
38
+ request,
39
+ responseType: ResponseTypes.SINGLE
40
+ });
41
+ }
42
+
43
+ toJSON() {
44
+ return {
45
+ calculateWhatsAppPricing: this.calculateWhatsAppPricing.bind(this)
46
+ };
47
+ }
48
+
49
+ }
@@ -0,0 +1,2 @@
1
+ import WhatsAppPricingRepository from './WhatsAppPricingRepository';
2
+ export { WhatsAppPricingRepository };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohoim/client-sdk",
3
- "version": "1.0.0-leftPanelPoc2",
3
+ "version": "1.0.0-leftPanelPoc4",
4
4
  "description": "To have the client sdk for the IM",
5
5
  "main": "es/index.js",
6
6
  "module": "es/index.js",