@zohoim/client-sdk 1.1.0-attachmentsList → 1.1.0-whatsapp-calculator

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 +12 -0
  8. package/es/domain/dto/index.js +2 -1
  9. package/es/domain/dto/sessions/getSessionAttachmentsRequest.js +5 -2
  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 +51 -24
  24. package/es/frameworks/managers/ModuleManager.js +25 -2
  25. package/es/frameworks/sdk/IMSDK.js +18 -11
  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
@@ -5,4 +5,5 @@ export * from './messages';
5
5
  export * from './agents';
6
6
  export * from './contacts';
7
7
  export * from './cannedMessages';
8
- export * from './templateMessages';
8
+ export * from './templateMessages';
9
+ 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 };
@@ -7,6 +7,7 @@ const ModuleNames = {
7
7
  AGENTS: 'agents',
8
8
  CANNED_MESSAGES: 'cannedMessages',
9
9
  TEMPLATE_MESSAGES: 'templateMessages',
10
- CUSTOM_REPLY_EXTENSIONS: 'articles'
10
+ CUSTOM_REPLY_EXTENSIONS: 'articles',
11
+ WHATSAPP_PRICING: 'whatsAppPricing'
11
12
  };
12
13
  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,18 @@ export const validateSchema = _ref4 => {
94
94
  path: fieldPath,
95
95
  entityName
96
96
  });
97
+ } // Array item validation
98
+
99
+
100
+ if (rules.type === 'array' && rules.schema && Array.isArray(value)) {
101
+ value.forEach((item, index) => {
102
+ validate({
103
+ schema: rules.schema,
104
+ data: item,
105
+ path: `${fieldPath}[${index}]`,
106
+ entityName
107
+ });
108
+ });
97
109
  }
98
110
  }
99
111
  });
@@ -5,4 +5,5 @@ export * from './messages';
5
5
  export * from './agents';
6
6
  export * from './contacts';
7
7
  export * from './cannedMessages';
8
- export * from './templateMessages';
8
+ export * from './templateMessages';
9
+ export * from './whatsAppPricing';
@@ -2,13 +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,
10
+ ...params
11
+ }).withQuery({
9
12
  from: null,
10
13
  limit: null,
11
- ...params
14
+ ...query
12
15
  }).build();
13
16
  }
14
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 };
@@ -9,4 +9,5 @@ export * from './Contact';
9
9
  export * from './IntegrationService';
10
10
  export * from './CannedMessage';
11
11
  export * from './TemplateMessage';
12
- export * from './CustomReplyExtension';
12
+ export * from './CustomReplyExtension';
13
+ export * from './WhatsAppPricing';
@@ -5,4 +5,5 @@ export * from './messages';
5
5
  export * from './agents';
6
6
  export * from './contacts';
7
7
  export * from './cannedMessages';
8
- export * from './templateMessages';
8
+ export * from './templateMessages';
9
+ 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 };
@@ -8,4 +8,5 @@ export * from './integrationService';
8
8
  export * from './contact';
9
9
  export * from './cannedMessage';
10
10
  export * from './templateMessage';
11
- export * from './customReplyExtension';
11
+ export * from './customReplyExtension';
12
+ 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,70 +7,97 @@ 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
  const ModuleFactory = {
11
12
  [ModuleNames.CHANNELS]: _ref => {
12
13
  let {
13
14
  config
14
15
  } = _ref;
15
- return new ChannelSDK({
16
- config
17
- }).toJSON();
16
+ return {
17
+ [ModuleTypes.AUTHENTICATED]: new ChannelSDK({
18
+ config
19
+ }).toJSON()
20
+ };
18
21
  },
19
22
  [ModuleNames.SESSIONS]: _ref2 => {
20
23
  let {
21
24
  config
22
25
  } = _ref2;
23
- return new SessionSDK({
24
- config
25
- }).toJSON();
26
+ return {
27
+ [ModuleTypes.AUTHENTICATED]: new SessionSDK({
28
+ config
29
+ }).toJSON()
30
+ };
26
31
  },
27
32
  [ModuleNames.BOTS]: _ref3 => {
28
33
  let {
29
34
  config
30
35
  } = _ref3;
31
- return new BotSDK({
32
- config
33
- }).toJSON();
36
+ return {
37
+ [ModuleTypes.AUTHENTICATED]: new BotSDK({
38
+ config
39
+ }).toJSON()
40
+ };
34
41
  },
35
42
  [ModuleNames.AGENTS]: _ref4 => {
36
43
  let {
37
44
  config
38
45
  } = _ref4;
39
- return new AgentSDK({
40
- config
41
- }).toJSON();
46
+ return {
47
+ [ModuleTypes.AUTHENTICATED]: new AgentSDK({
48
+ config
49
+ }).toJSON()
50
+ };
42
51
  },
43
52
  [ModuleNames.CONTACTS]: _ref5 => {
44
53
  let {
45
54
  config
46
55
  } = _ref5;
47
- return new ContactSDK({
48
- config
49
- }).toJSON();
56
+ return {
57
+ [ModuleTypes.AUTHENTICATED]: new ContactSDK({
58
+ config
59
+ }).toJSON()
60
+ };
50
61
  },
51
62
  [ModuleNames.MESSAGES]: _ref6 => {
52
63
  let {
53
64
  config
54
65
  } = _ref6;
55
- return new MessageSDK({
56
- config
57
- }).toJSON();
66
+ return {
67
+ [ModuleTypes.AUTHENTICATED]: new MessageSDK({
68
+ config
69
+ }).toJSON()
70
+ };
58
71
  },
59
72
  [ModuleNames.CANNED_MESSAGES]: _ref7 => {
60
73
  let {
61
74
  config
62
75
  } = _ref7;
63
- return new CannedMessageSDK({
64
- config
65
- }).toJSON();
76
+ return {
77
+ [ModuleTypes.AUTHENTICATED]: new CannedMessageSDK({
78
+ config
79
+ }).toJSON()
80
+ };
66
81
  },
67
82
  [ModuleNames.TEMPLATE_MESSAGES]: _ref8 => {
68
83
  let {
69
84
  config
70
85
  } = _ref8;
71
- return new TemplateMessageSDK({
86
+ return {
87
+ [ModuleTypes.AUTHENTICATED]: new TemplateMessageSDK({
88
+ config
89
+ }).toJSON()
90
+ };
91
+ },
92
+ [ModuleNames.WHATSAPP_PRICING]: _ref9 => {
93
+ let {
72
94
  config
73
- }).toJSON();
95
+ } = _ref9;
96
+ return {
97
+ [ModuleTypes.PUBLIC]: new WhatsAppPricingSDK({
98
+ config
99
+ }).toJSON()
100
+ };
74
101
  }
75
102
  };
76
103
  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];
6
+ this.supportedModules = [ModuleNames.CHANNELS, ModuleNames.SESSIONS, ModuleNames.BOTS, ModuleNames.MESSAGES, ModuleNames.AGENTS, ModuleNames.CONTACTS, ModuleNames.CANNED_MESSAGES, ModuleNames.TEMPLATE_MESSAGES, 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,35 +22,39 @@ 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
  hasModule(moduleName) {
@@ -65,6 +71,7 @@ export default class IMSDK {
65
71
  contacts: this.contacts,
66
72
  cannedMessages: this.cannedMessages,
67
73
  templateMessages: this.templateMessages,
74
+ public: this.public,
68
75
  hasModule: this.hasModule.bind(this)
69
76
  };
70
77
  }
@@ -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 };
@@ -7,4 +7,5 @@ export * from './agents';
7
7
  export * from './contacts';
8
8
  export * from './cannedMessages';
9
9
  export * from './templateMessages';
10
- export * from './customReplyExtension';
10
+ export * from './customReplyExtension';
11
+ 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) {
@@ -5,4 +5,5 @@ export * from './messages';
5
5
  export * from './agents';
6
6
  export * from './contacts';
7
7
  export * from './cannedMessages';
8
- export * from './templateMessages';
8
+ export * from './templateMessages';
9
+ export * from './whatsAppPricing';
@@ -0,0 +1,4 @@
1
+ import createBaseUrl from './createBaseUrl';
2
+ export default function createPublicBaseUrl(path) {
3
+ return createBaseUrl(`/public${path}`);
4
+ }
@@ -7,6 +7,7 @@ import { agentAPIRegistry } from './agents';
7
7
  import { contactAPIRegistry } from './contacts';
8
8
  import { cannedMessageAPIRegistry } from './cannedMessages';
9
9
  import { templateMessageAPIRegistry } from './templateMessages';
10
+ import { whatsAppPricingAPIRegistry } from './whatsAppPricing';
10
11
  import { ModuleNames } from '../../../core/constants';
11
12
  const APIRegistry = {
12
13
  [ModuleNames.CHANNELS]: channelAPIRegistry,
@@ -16,7 +17,8 @@ const APIRegistry = {
16
17
  [ModuleNames.AGENTS]: agentAPIRegistry,
17
18
  [ModuleNames.CONTACTS]: contactAPIRegistry,
18
19
  [ModuleNames.CANNED_MESSAGES]: cannedMessageAPIRegistry,
19
- [ModuleNames.TEMPLATE_MESSAGES]: templateMessageAPIRegistry
20
+ [ModuleNames.TEMPLATE_MESSAGES]: templateMessageAPIRegistry,
21
+ [ModuleNames.WHATSAPP_PRICING]: whatsAppPricingAPIRegistry
20
22
  };
21
23
  export default function getRegistryConfig(module, operation) {
22
24
  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();
@@ -5,4 +5,5 @@ export * from './messages';
5
5
  export * from './agents';
6
6
  export * from './contacts';
7
7
  export * from './cannedMessages';
8
- export * from './templateMessages';
8
+ export * from './templateMessages';
9
+ 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.1.0-attachmentsList",
3
+ "version": "1.1.0-whatsapp-calculator",
4
4
  "description": "To have the client sdk for the IM",
5
5
  "main": "es/index.js",
6
6
  "module": "es/index.js",