@zohoim/client-sdk 1.0.0-leftPanelPoc1 → 1.0.0-leftPanelPoc3
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.
- package/es/application/services/index.js +2 -1
- package/es/application/services/whatsAppPricing/WhatsAppPricingService.js +21 -0
- package/es/application/services/whatsAppPricing/index.js +2 -0
- package/es/core/constants/ModuleNames.js +2 -1
- package/es/core/constants/ModuleTypes.js +5 -0
- package/es/core/constants/index.js +2 -1
- package/es/core/utils/validateSchema.js +12 -0
- package/es/domain/dto/index.js +2 -1
- package/es/domain/dto/sessions/getSessionAttachmentsRequest.js +6 -1
- package/es/domain/dto/whatsAppPricing/calculateWhatsAppPricingRequest.js +14 -0
- package/es/domain/dto/whatsAppPricing/index.js +1 -0
- package/es/domain/entities/Channel/Channel.js +3 -1
- package/es/domain/entities/WhatsAppPricing/WhatsAppPricing.js +25 -0
- package/es/domain/entities/WhatsAppPricing/WhatsAppPricingCategory.js +22 -0
- package/es/domain/entities/WhatsAppPricing/index.js +3 -0
- package/es/domain/entities/index.js +2 -1
- package/es/domain/interfaces/repositories/index.js +2 -1
- package/es/domain/interfaces/repositories/whatsAppPricing/IWhatsAppPricingRepository.js +18 -0
- package/es/domain/interfaces/repositories/whatsAppPricing/index.js +2 -0
- package/es/domain/schema/channel/ChannelSchema.js +4 -0
- package/es/domain/schema/index.js +2 -1
- package/es/domain/schema/whatsAppPricing/WhatsAppPricingCategorySchema.js +11 -0
- package/es/domain/schema/whatsAppPricing/WhatsAppPricingSchema.js +21 -0
- package/es/domain/schema/whatsAppPricing/index.js +3 -0
- package/es/frameworks/managers/ModuleFactory.js +61 -30
- package/es/frameworks/managers/ModuleManager.js +25 -2
- package/es/frameworks/sdk/IMSDK.js +20 -13
- package/es/frameworks/sdk/whatsAppPricing/WhatsAppPricingSDK.js +28 -0
- package/es/frameworks/sdk/whatsAppPricing/index.js +2 -0
- package/es/infrastructure/adapters/channels/ChannelAdapter.js +2 -1
- package/es/infrastructure/adapters/index.js +2 -1
- package/es/infrastructure/adapters/whatsAppPricing/WhatsAppPricingAdapter.js +22 -0
- package/es/infrastructure/adapters/whatsAppPricing/index.js +2 -0
- package/es/infrastructure/api/BaseAPI.js +5 -4
- package/es/infrastructure/api/index.js +2 -1
- package/es/infrastructure/api/registry/createPublicBaseUrl.js +4 -0
- package/es/infrastructure/api/registry/getRegistryConfig.js +3 -1
- package/es/infrastructure/api/registry/whatsAppPricing/constructWhatsAppPricingEndPoint.js +10 -0
- package/es/infrastructure/api/registry/whatsAppPricing/index.js +2 -0
- package/es/infrastructure/api/registry/whatsAppPricing/whatsAppPricingAPIRegistry.js +13 -0
- package/es/infrastructure/api/whatsAppPricing/WhatsAppPricingAPI.js +14 -0
- package/es/infrastructure/api/whatsAppPricing/index.js +2 -0
- package/es/infrastructure/config/configRegistry.js +8 -1
- package/es/infrastructure/repositories/index.js +2 -1
- package/es/infrastructure/repositories/whatsAppPricing/WhatsAppPricingRepository.js +49 -0
- package/es/infrastructure/repositories/whatsAppPricing/index.js +2 -0
- package/package.json +1 -1
|
@@ -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
|
+
}
|
|
@@ -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;
|
|
@@ -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
|
});
|
package/es/domain/dto/index.js
CHANGED
|
@@ -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';
|
|
@@ -29,6 +29,7 @@ export default class Channel {
|
|
|
29
29
|
this.authorizationPending = validatedData.authorizationPending || false;
|
|
30
30
|
this.meta = validatedData.meta || [];
|
|
31
31
|
this.logoURL = validatedData.logoURL || null;
|
|
32
|
+
this.workspaceId = validatedData.workspaceId || '';
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
toJSON() {
|
|
@@ -51,7 +52,8 @@ export default class Channel {
|
|
|
51
52
|
configParams: this.configParams,
|
|
52
53
|
authorizationPending: this.authorizationPending,
|
|
53
54
|
meta: this.meta,
|
|
54
|
-
logoURL: this.logoURL
|
|
55
|
+
logoURL: this.logoURL,
|
|
56
|
+
workspaceId: this.workspaceId
|
|
55
57
|
};
|
|
56
58
|
}
|
|
57
59
|
|
|
@@ -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,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,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;
|
|
@@ -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
|
|
18
|
-
|
|
19
|
-
|
|
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
|
|
26
|
-
|
|
27
|
-
|
|
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
|
|
34
|
-
|
|
35
|
-
|
|
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
|
|
42
|
-
|
|
43
|
-
|
|
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
|
|
50
|
-
|
|
51
|
-
|
|
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
|
|
58
|
-
|
|
59
|
-
|
|
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
|
|
66
|
-
|
|
67
|
-
|
|
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
|
|
74
|
-
|
|
75
|
-
|
|
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
|
|
82
|
-
|
|
83
|
-
|
|
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
|
|
108
|
+
return {
|
|
109
|
+
[ModuleTypes.AUTHENTICATED]: new UserPreferencesSDK({
|
|
110
|
+
config
|
|
111
|
+
}).toJSON()
|
|
112
|
+
};
|
|
113
|
+
},
|
|
114
|
+
[ModuleNames.WHATSAPP_PRICING]: _ref11 => {
|
|
115
|
+
let {
|
|
90
116
|
config
|
|
91
|
-
}
|
|
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.
|
|
25
|
+
return this._moduleManager.getModuleByType(ModuleNames.CHANNELS);
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
get sessions() {
|
|
27
|
-
return this._moduleManager.
|
|
29
|
+
return this._moduleManager.getModuleByType(ModuleNames.SESSIONS);
|
|
28
30
|
}
|
|
29
31
|
|
|
30
32
|
get bots() {
|
|
31
|
-
return this._moduleManager.
|
|
33
|
+
return this._moduleManager.getModuleByType(ModuleNames.BOTS);
|
|
32
34
|
}
|
|
33
35
|
|
|
34
36
|
get messages() {
|
|
35
|
-
return this._moduleManager.
|
|
37
|
+
return this._moduleManager.getModuleByType(ModuleNames.MESSAGES);
|
|
36
38
|
}
|
|
37
39
|
|
|
38
40
|
get agents() {
|
|
39
|
-
return this._moduleManager.
|
|
41
|
+
return this._moduleManager.getModuleByType(ModuleNames.AGENTS);
|
|
40
42
|
}
|
|
41
43
|
|
|
42
44
|
get contacts() {
|
|
43
|
-
return this._moduleManager.
|
|
45
|
+
return this._moduleManager.getModuleByType(ModuleNames.CONTACTS);
|
|
44
46
|
}
|
|
45
47
|
|
|
46
48
|
get cannedMessages() {
|
|
47
|
-
return this._moduleManager.
|
|
49
|
+
return this._moduleManager.getModuleByType(ModuleNames.CANNED_MESSAGES);
|
|
48
50
|
}
|
|
49
51
|
|
|
50
52
|
get templateMessages() {
|
|
51
|
-
return this._moduleManager.
|
|
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.
|
|
61
|
+
return this._moduleManager.getModuleByType(ModuleNames.INTEGRATION_SERVICES);
|
|
56
62
|
}
|
|
57
63
|
|
|
58
64
|
get userPreferences() {
|
|
59
|
-
return this._moduleManager.
|
|
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;
|
|
@@ -32,7 +32,8 @@ export default class ChannelAdapter extends IAdapter {
|
|
|
32
32
|
configParams: rawChannel.configParams,
|
|
33
33
|
authorizationPending: rawChannel.authorizationPending,
|
|
34
34
|
meta: rawChannel.meta,
|
|
35
|
-
logoURL: rawChannel.logoURL
|
|
35
|
+
logoURL: rawChannel.logoURL,
|
|
36
|
+
workspaceId: rawChannel.workspaceId
|
|
36
37
|
}).toJSON();
|
|
37
38
|
} catch (error) {
|
|
38
39
|
throw new AdapterError(`Failed to adapt channel: ${error.message}`);
|
|
@@ -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
|
+
}
|
|
@@ -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
|
|
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) {
|
|
@@ -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,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
|
+
}
|
|
@@ -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();
|
|
@@ -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
|
+
}
|