@webex/contact-center 0.0.0-next.1

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 (177) hide show
  1. package/README.md +81 -0
  2. package/__mocks__/workerMock.js +15 -0
  3. package/babel.config.js +15 -0
  4. package/dist/cc.js +1416 -0
  5. package/dist/cc.js.map +1 -0
  6. package/dist/config.js +72 -0
  7. package/dist/config.js.map +1 -0
  8. package/dist/constants.js +58 -0
  9. package/dist/constants.js.map +1 -0
  10. package/dist/index.js +142 -0
  11. package/dist/index.js.map +1 -0
  12. package/dist/logger-proxy.js +115 -0
  13. package/dist/logger-proxy.js.map +1 -0
  14. package/dist/metrics/MetricsManager.js +474 -0
  15. package/dist/metrics/MetricsManager.js.map +1 -0
  16. package/dist/metrics/behavioral-events.js +322 -0
  17. package/dist/metrics/behavioral-events.js.map +1 -0
  18. package/dist/metrics/constants.js +134 -0
  19. package/dist/metrics/constants.js.map +1 -0
  20. package/dist/services/WebCallingService.js +323 -0
  21. package/dist/services/WebCallingService.js.map +1 -0
  22. package/dist/services/agent/index.js +177 -0
  23. package/dist/services/agent/index.js.map +1 -0
  24. package/dist/services/agent/types.js +137 -0
  25. package/dist/services/agent/types.js.map +1 -0
  26. package/dist/services/config/Util.js +203 -0
  27. package/dist/services/config/Util.js.map +1 -0
  28. package/dist/services/config/constants.js +221 -0
  29. package/dist/services/config/constants.js.map +1 -0
  30. package/dist/services/config/index.js +607 -0
  31. package/dist/services/config/index.js.map +1 -0
  32. package/dist/services/config/types.js +334 -0
  33. package/dist/services/config/types.js.map +1 -0
  34. package/dist/services/constants.js +117 -0
  35. package/dist/services/constants.js.map +1 -0
  36. package/dist/services/core/Err.js +43 -0
  37. package/dist/services/core/Err.js.map +1 -0
  38. package/dist/services/core/GlobalTypes.js +6 -0
  39. package/dist/services/core/GlobalTypes.js.map +1 -0
  40. package/dist/services/core/Utils.js +126 -0
  41. package/dist/services/core/Utils.js.map +1 -0
  42. package/dist/services/core/WebexRequest.js +96 -0
  43. package/dist/services/core/WebexRequest.js.map +1 -0
  44. package/dist/services/core/aqm-reqs.js +246 -0
  45. package/dist/services/core/aqm-reqs.js.map +1 -0
  46. package/dist/services/core/constants.js +109 -0
  47. package/dist/services/core/constants.js.map +1 -0
  48. package/dist/services/core/types.js +6 -0
  49. package/dist/services/core/types.js.map +1 -0
  50. package/dist/services/core/websocket/WebSocketManager.js +187 -0
  51. package/dist/services/core/websocket/WebSocketManager.js.map +1 -0
  52. package/dist/services/core/websocket/connection-service.js +111 -0
  53. package/dist/services/core/websocket/connection-service.js.map +1 -0
  54. package/dist/services/core/websocket/keepalive.worker.js +94 -0
  55. package/dist/services/core/websocket/keepalive.worker.js.map +1 -0
  56. package/dist/services/core/websocket/types.js +6 -0
  57. package/dist/services/core/websocket/types.js.map +1 -0
  58. package/dist/services/index.js +78 -0
  59. package/dist/services/index.js.map +1 -0
  60. package/dist/services/task/AutoWrapup.js +88 -0
  61. package/dist/services/task/AutoWrapup.js.map +1 -0
  62. package/dist/services/task/TaskManager.js +369 -0
  63. package/dist/services/task/TaskManager.js.map +1 -0
  64. package/dist/services/task/constants.js +58 -0
  65. package/dist/services/task/constants.js.map +1 -0
  66. package/dist/services/task/contact.js +464 -0
  67. package/dist/services/task/contact.js.map +1 -0
  68. package/dist/services/task/dialer.js +60 -0
  69. package/dist/services/task/dialer.js.map +1 -0
  70. package/dist/services/task/index.js +1188 -0
  71. package/dist/services/task/index.js.map +1 -0
  72. package/dist/services/task/types.js +214 -0
  73. package/dist/services/task/types.js.map +1 -0
  74. package/dist/types/cc.d.ts +676 -0
  75. package/dist/types/config.d.ts +66 -0
  76. package/dist/types/constants.d.ts +45 -0
  77. package/dist/types/index.d.ts +178 -0
  78. package/dist/types/logger-proxy.d.ts +71 -0
  79. package/dist/types/metrics/MetricsManager.d.ts +223 -0
  80. package/dist/types/metrics/behavioral-events.d.ts +29 -0
  81. package/dist/types/metrics/constants.d.ts +127 -0
  82. package/dist/types/services/WebCallingService.d.ts +1 -0
  83. package/dist/types/services/agent/index.d.ts +46 -0
  84. package/dist/types/services/agent/types.d.ts +413 -0
  85. package/dist/types/services/config/Util.d.ts +19 -0
  86. package/dist/types/services/config/constants.d.ts +203 -0
  87. package/dist/types/services/config/index.d.ts +171 -0
  88. package/dist/types/services/config/types.d.ts +1113 -0
  89. package/dist/types/services/constants.d.ts +97 -0
  90. package/dist/types/services/core/Err.d.ts +119 -0
  91. package/dist/types/services/core/GlobalTypes.d.ts +33 -0
  92. package/dist/types/services/core/Utils.d.ts +36 -0
  93. package/dist/types/services/core/WebexRequest.d.ts +22 -0
  94. package/dist/types/services/core/aqm-reqs.d.ts +16 -0
  95. package/dist/types/services/core/constants.d.ts +85 -0
  96. package/dist/types/services/core/types.d.ts +47 -0
  97. package/dist/types/services/core/websocket/WebSocketManager.d.ts +34 -0
  98. package/dist/types/services/core/websocket/connection-service.d.ts +27 -0
  99. package/dist/types/services/core/websocket/keepalive.worker.d.ts +2 -0
  100. package/dist/types/services/core/websocket/types.d.ts +37 -0
  101. package/dist/types/services/index.d.ts +52 -0
  102. package/dist/types/services/task/AutoWrapup.d.ts +40 -0
  103. package/dist/types/services/task/TaskManager.d.ts +1 -0
  104. package/dist/types/services/task/constants.d.ts +46 -0
  105. package/dist/types/services/task/contact.d.ts +59 -0
  106. package/dist/types/services/task/dialer.d.ts +28 -0
  107. package/dist/types/services/task/index.d.ts +569 -0
  108. package/dist/types/services/task/types.d.ts +1041 -0
  109. package/dist/types/types.d.ts +452 -0
  110. package/dist/types/webex-config.d.ts +53 -0
  111. package/dist/types/webex.d.ts +7 -0
  112. package/dist/types.js +292 -0
  113. package/dist/types.js.map +1 -0
  114. package/dist/webex-config.js +60 -0
  115. package/dist/webex-config.js.map +1 -0
  116. package/dist/webex.js +99 -0
  117. package/dist/webex.js.map +1 -0
  118. package/jest.config.js +45 -0
  119. package/package.json +83 -0
  120. package/src/cc.ts +1618 -0
  121. package/src/config.ts +65 -0
  122. package/src/constants.ts +51 -0
  123. package/src/index.ts +220 -0
  124. package/src/logger-proxy.ts +110 -0
  125. package/src/metrics/MetricsManager.ts +512 -0
  126. package/src/metrics/behavioral-events.ts +332 -0
  127. package/src/metrics/constants.ts +135 -0
  128. package/src/services/WebCallingService.ts +351 -0
  129. package/src/services/agent/index.ts +149 -0
  130. package/src/services/agent/types.ts +440 -0
  131. package/src/services/config/Util.ts +261 -0
  132. package/src/services/config/constants.ts +249 -0
  133. package/src/services/config/index.ts +743 -0
  134. package/src/services/config/types.ts +1117 -0
  135. package/src/services/constants.ts +111 -0
  136. package/src/services/core/Err.ts +126 -0
  137. package/src/services/core/GlobalTypes.ts +34 -0
  138. package/src/services/core/Utils.ts +132 -0
  139. package/src/services/core/WebexRequest.ts +103 -0
  140. package/src/services/core/aqm-reqs.ts +272 -0
  141. package/src/services/core/constants.ts +106 -0
  142. package/src/services/core/types.ts +48 -0
  143. package/src/services/core/websocket/WebSocketManager.ts +196 -0
  144. package/src/services/core/websocket/connection-service.ts +142 -0
  145. package/src/services/core/websocket/keepalive.worker.js +88 -0
  146. package/src/services/core/websocket/types.ts +40 -0
  147. package/src/services/index.ts +71 -0
  148. package/src/services/task/AutoWrapup.ts +86 -0
  149. package/src/services/task/TaskManager.ts +420 -0
  150. package/src/services/task/constants.ts +52 -0
  151. package/src/services/task/contact.ts +429 -0
  152. package/src/services/task/dialer.ts +52 -0
  153. package/src/services/task/index.ts +1375 -0
  154. package/src/services/task/types.ts +1113 -0
  155. package/src/types.ts +639 -0
  156. package/src/webex-config.ts +54 -0
  157. package/src/webex.js +96 -0
  158. package/test/unit/spec/cc.ts +1985 -0
  159. package/test/unit/spec/metrics/MetricsManager.ts +491 -0
  160. package/test/unit/spec/metrics/behavioral-events.ts +102 -0
  161. package/test/unit/spec/services/WebCallingService.ts +416 -0
  162. package/test/unit/spec/services/agent/index.ts +65 -0
  163. package/test/unit/spec/services/config/index.ts +1035 -0
  164. package/test/unit/spec/services/core/Utils.ts +279 -0
  165. package/test/unit/spec/services/core/WebexRequest.ts +144 -0
  166. package/test/unit/spec/services/core/aqm-reqs.ts +570 -0
  167. package/test/unit/spec/services/core/websocket/WebSocketManager.ts +378 -0
  168. package/test/unit/spec/services/core/websocket/connection-service.ts +178 -0
  169. package/test/unit/spec/services/task/TaskManager.ts +1351 -0
  170. package/test/unit/spec/services/task/contact.ts +204 -0
  171. package/test/unit/spec/services/task/dialer.ts +157 -0
  172. package/test/unit/spec/services/task/index.ts +1474 -0
  173. package/tsconfig.json +6 -0
  174. package/typedoc.json +37 -0
  175. package/typedoc.md +240 -0
  176. package/umd/contact-center.min.js +3 -0
  177. package/umd/contact-center.min.js.map +1 -0
@@ -0,0 +1,743 @@
1
+ /**
2
+ * @packageDocumentation
3
+ * @module AgentConfigService
4
+ */
5
+
6
+ import {HTTP_METHODS} from '../../types';
7
+ import LoggerProxy from '../../logger-proxy';
8
+ import {
9
+ DesktopProfileResponse,
10
+ ListAuxCodesResponse,
11
+ AgentResponse,
12
+ OrgInfo,
13
+ OrgSettings,
14
+ TenantData,
15
+ URLMapping,
16
+ TeamList,
17
+ DialPlanEntity,
18
+ Profile,
19
+ ListTeamsResponse,
20
+ AuxCode,
21
+ MultimediaProfileResponse,
22
+ SiteInfo,
23
+ ContactServiceQueue,
24
+ } from './types';
25
+ import WebexRequest from '../core/WebexRequest';
26
+ import {WCC_API_GATEWAY} from '../constants';
27
+ import {CONFIG_FILE_NAME} from '../../constants';
28
+ import {parseAgentConfigs} from './Util';
29
+ import {
30
+ DEFAULT_AUXCODE_ATTRIBUTES,
31
+ DEFAULT_PAGE,
32
+ DEFAULT_PAGE_SIZE,
33
+ endPointMap,
34
+ METHODS,
35
+ } from './constants';
36
+
37
+ /**
38
+ * The AgentConfigService class provides methods to fetch agent configuration data.
39
+ * @private
40
+ * @ignore
41
+ */
42
+ export default class AgentConfigService {
43
+ private webexReq: WebexRequest;
44
+ constructor() {
45
+ this.webexReq = WebexRequest.getInstance();
46
+ }
47
+
48
+ /**
49
+ * Fetches the agent configuration data for the given orgId and agentId.
50
+ * @param {string} orgId - organization ID for which the agent configuration is to be fetched.
51
+ * @param {string} agentId - agent ID for which the configuration is to be fetched.
52
+ * @returns {Promise<Profile>} - A promise that resolves to the agent configuration profile.
53
+ * @throws {Error} - Throws an error if any API call fails or if the response status is not 200.
54
+ * @public
55
+ */
56
+ public async getAgentConfig(orgId: string, agentId: string): Promise<Profile> {
57
+ try {
58
+ const userConfigPromise = this.getUserUsingCI(orgId, agentId);
59
+ const orgInfoPromise = this.getOrgInfo(orgId);
60
+ const orgSettingsPromise = this.getOrganizationSetting(orgId);
61
+ const tenantDataPromise = this.getTenantData(orgId);
62
+ const urlMappingPromise = this.getURLMapping(orgId);
63
+ const auxCodesPromise = this.getAllAuxCodes(
64
+ orgId,
65
+ DEFAULT_PAGE_SIZE,
66
+ [],
67
+ DEFAULT_AUXCODE_ATTRIBUTES
68
+ );
69
+
70
+ const userConfigData = await userConfigPromise;
71
+ LoggerProxy.info(`Fetched user data, userId: ${userConfigData.ciUserId}`, {
72
+ module: CONFIG_FILE_NAME,
73
+ method: METHODS.GET_AGENT_CONFIG,
74
+ });
75
+
76
+ const agentProfilePromise = this.getDesktopProfileById(orgId, userConfigData.agentProfileId);
77
+ const siteInfoPromise = this.getSiteInfo(orgId, userConfigData.siteId);
78
+
79
+ const userDialPlanPromise = agentProfilePromise.then((agentProfileConfigData) =>
80
+ agentProfileConfigData.dialPlanEnabled ? this.getDialPlanData(orgId) : []
81
+ );
82
+
83
+ const userTeamPromise = userConfigData.teamIds
84
+ ? this.getAllTeams(orgId, DEFAULT_PAGE_SIZE, userConfigData.teamIds)
85
+ : Promise.resolve([]);
86
+
87
+ const [
88
+ agentProfileConfigData,
89
+ siteInfo,
90
+ userDialPlanData,
91
+ userTeamData,
92
+ orgInfo,
93
+ orgSettingsData,
94
+ tenantData,
95
+ urlMappingData,
96
+ auxCodesData,
97
+ ] = await Promise.all([
98
+ agentProfilePromise,
99
+ siteInfoPromise,
100
+ userDialPlanPromise,
101
+ userTeamPromise,
102
+ orgInfoPromise,
103
+ orgSettingsPromise,
104
+ tenantDataPromise,
105
+ urlMappingPromise,
106
+ auxCodesPromise,
107
+ ]);
108
+
109
+ const multimediaProfileId =
110
+ userConfigData.multimediaProfileId ||
111
+ userTeamData[0]?.multiMediaProfileId ||
112
+ siteInfo.multimediaProfileId;
113
+
114
+ LoggerProxy.info('Fetched all required data', {
115
+ module: CONFIG_FILE_NAME,
116
+ method: METHODS.GET_AGENT_CONFIG,
117
+ });
118
+
119
+ const response = parseAgentConfigs({
120
+ userData: userConfigData,
121
+ teamData: userTeamData,
122
+ tenantData,
123
+ orgInfoData: orgInfo,
124
+ auxCodes: auxCodesData,
125
+ orgSettingsData,
126
+ agentProfileData: agentProfileConfigData,
127
+ dialPlanData: userDialPlanData,
128
+ urlMapping: urlMappingData,
129
+ multimediaProfileId,
130
+ });
131
+
132
+ LoggerProxy.info('Parsing completed for agent-config', {
133
+ module: CONFIG_FILE_NAME,
134
+ method: METHODS.GET_AGENT_CONFIG,
135
+ });
136
+ LoggerProxy.info('Fetched configuration data successfully', {
137
+ module: CONFIG_FILE_NAME,
138
+ method: METHODS.GET_AGENT_CONFIG,
139
+ });
140
+
141
+ return response;
142
+ } catch (error) {
143
+ LoggerProxy.error(`getAgentConfig call failed with ${error}`, {
144
+ module: CONFIG_FILE_NAME,
145
+ method: METHODS.GET_AGENT_CONFIG,
146
+ });
147
+ throw error;
148
+ }
149
+ }
150
+
151
+ /**
152
+ * Fetches the agent configuration data for the given orgId and agentId.
153
+ * @ignore
154
+ * @param {string} orgId - organization ID for which the agent configuration is to be fetched.
155
+ * @param {string} agentId - agent ID for which the configuration is to be fetched.
156
+ * @returns {Promise<AgentResponse>} - A promise that resolves to the agent configuration response.
157
+ * @throws {Error} - Throws an error if the API call fails or if the response status is not 200.
158
+ * @private
159
+ */
160
+ public async getUserUsingCI(orgId: string, agentId: string): Promise<AgentResponse> {
161
+ LoggerProxy.info('Fetching user data using CI', {
162
+ module: CONFIG_FILE_NAME,
163
+ method: METHODS.GET_USER_USING_CI,
164
+ });
165
+
166
+ try {
167
+ const resource = endPointMap.userByCI(orgId, agentId);
168
+ const response = await this.webexReq.request({
169
+ service: WCC_API_GATEWAY,
170
+ resource,
171
+ method: HTTP_METHODS.GET,
172
+ });
173
+
174
+ if (response.statusCode !== 200) {
175
+ throw new Error(`API call failed with ${response.statusCode}`);
176
+ }
177
+
178
+ LoggerProxy.log('getUserUsingCI api success.', {
179
+ module: CONFIG_FILE_NAME,
180
+ method: METHODS.GET_USER_USING_CI,
181
+ });
182
+
183
+ return Promise.resolve(response.body);
184
+ } catch (error) {
185
+ LoggerProxy.error(`getUserUsingCI API call failed with ${error}`, {
186
+ module: CONFIG_FILE_NAME,
187
+ method: METHODS.GET_USER_USING_CI,
188
+ });
189
+ throw error;
190
+ }
191
+ }
192
+
193
+ /**
194
+ * Fetches the desktop profile data for the given orgId and desktopProfileId.
195
+ * @ignore
196
+ * @param {string} orgId - organization ID for which the desktop profile is to be fetched.
197
+ * @param {string} desktopProfileId - desktop profile ID for which the data is to be fetched.
198
+ * @returns {Promise<DesktopProfileResponse>} - A promise that resolves to the desktop profile response.
199
+ * @throws {Error} - Throws an error if the API call fails or if the response status is not 200.
200
+ * @private
201
+ */
202
+ public async getDesktopProfileById(
203
+ orgId: string,
204
+ desktopProfileId: string
205
+ ): Promise<DesktopProfileResponse> {
206
+ LoggerProxy.info('Fetching desktop profile', {
207
+ module: CONFIG_FILE_NAME,
208
+ method: METHODS.GET_DESKTOP_PROFILE_BY_ID,
209
+ });
210
+
211
+ try {
212
+ const resource = endPointMap.desktopProfile(orgId, desktopProfileId);
213
+ const response = await this.webexReq.request({
214
+ service: WCC_API_GATEWAY,
215
+ resource,
216
+ method: HTTP_METHODS.GET,
217
+ });
218
+
219
+ if (response.statusCode !== 200) {
220
+ throw new Error(`API call failed with ${response.statusCode}`);
221
+ }
222
+
223
+ LoggerProxy.log('getDesktopProfileById api success.', {
224
+ module: CONFIG_FILE_NAME,
225
+ method: METHODS.GET_DESKTOP_PROFILE_BY_ID,
226
+ });
227
+
228
+ return Promise.resolve(response.body);
229
+ } catch (error) {
230
+ LoggerProxy.error(`getDesktopProfileById API call failed with ${error}`, {
231
+ module: CONFIG_FILE_NAME,
232
+ method: METHODS.GET_DESKTOP_PROFILE_BY_ID,
233
+ });
234
+ throw error;
235
+ }
236
+ }
237
+
238
+ /**
239
+ * Fetches the multimedia profile data for the given orgId and multimediaProfileId.
240
+ * @ignore
241
+ * @param {string} orgId - organization ID for which the multimedia profile is to be fetched.
242
+ * @param {string} multimediaProfileId - multimedia profile ID for which the data is to be fetched.
243
+ * @throws {Error} - Throws an error if the API call fails or if the response status is not 200.
244
+ * @returns {Promise<MultimediaProfileResponse>} - A promise that resolves to the multimedia profile response.
245
+ * @private
246
+ */
247
+ public async getMultimediaProfileById(
248
+ orgId: string,
249
+ multimediaProfileId: string
250
+ ): Promise<MultimediaProfileResponse> {
251
+ LoggerProxy.info('Fetching multimedia profile', {
252
+ module: CONFIG_FILE_NAME,
253
+ method: METHODS.GET_MULTIMEDIA_PROFILE_BY_ID,
254
+ });
255
+
256
+ try {
257
+ const resource = endPointMap.multimediaProfile(orgId, multimediaProfileId);
258
+ const response = await this.webexReq.request({
259
+ service: WCC_API_GATEWAY,
260
+ resource,
261
+ method: HTTP_METHODS.GET,
262
+ });
263
+
264
+ if (response.statusCode !== 200) {
265
+ throw new Error(`API call failed with ${response.statusCode}`);
266
+ }
267
+
268
+ LoggerProxy.log('getMultimediaProfileById API success.', {
269
+ module: CONFIG_FILE_NAME,
270
+ method: METHODS.GET_MULTIMEDIA_PROFILE_BY_ID,
271
+ });
272
+
273
+ return Promise.resolve(response.body);
274
+ } catch (error) {
275
+ LoggerProxy.error(`getMultimediaProfileById API call failed with ${error}`, {
276
+ module: CONFIG_FILE_NAME,
277
+ method: METHODS.GET_MULTIMEDIA_PROFILE_BY_ID,
278
+ });
279
+ throw error;
280
+ }
281
+ }
282
+
283
+ /**
284
+ * fetches the list of teams for the given orgId.
285
+ * @ignore
286
+ * @param {string} orgId - organization ID for which the teams are to be fetched.
287
+ * @param {number} page - the page number to fetch.
288
+ * @param {number} pageSize - the number of teams to fetch per page.
289
+ * @param {string[]} filter - optional filter criteria for the teams.
290
+ * @param {string[]} attributes - optional attributes to include in the response.
291
+ * @returns {Promise<ListTeamsResponse>} - A promise that resolves to the list of teams response.
292
+ * @throws {Error} - Throws an error if the API call fails or if the response status is not 200.
293
+ * @private
294
+ */
295
+ public async getListOfTeams(
296
+ orgId: string,
297
+ page: number,
298
+ pageSize: number,
299
+ filter: string[]
300
+ ): Promise<ListTeamsResponse> {
301
+ LoggerProxy.info('Fetching list of teams', {
302
+ module: CONFIG_FILE_NAME,
303
+ method: METHODS.GET_LIST_OF_TEAMS,
304
+ });
305
+
306
+ try {
307
+ const resource = endPointMap.listTeams(orgId, page, pageSize, filter);
308
+ const response = await this.webexReq.request({
309
+ service: WCC_API_GATEWAY,
310
+ resource,
311
+ method: HTTP_METHODS.GET,
312
+ });
313
+
314
+ if (response.statusCode !== 200) {
315
+ throw new Error(`API call failed with ${response.statusCode}`);
316
+ }
317
+
318
+ LoggerProxy.log('getListOfTeams api success.', {
319
+ module: CONFIG_FILE_NAME,
320
+ method: METHODS.GET_LIST_OF_TEAMS,
321
+ });
322
+
323
+ return Promise.resolve(response.body);
324
+ } catch (error) {
325
+ LoggerProxy.error(`getListOfTeams API call failed with ${error}`, {
326
+ module: CONFIG_FILE_NAME,
327
+ method: METHODS.GET_LIST_OF_TEAMS,
328
+ });
329
+ throw error;
330
+ }
331
+ }
332
+
333
+ /**
334
+ * Fetches all teams from all pages for the given orgId
335
+ * @ignore
336
+ * @param {string} orgId - organization ID for which the teams are to be fetched.
337
+ * @param {number} pageSize - the number of teams to fetch per page.
338
+ * @param {string[]} filter - optional filter criteria for the teams.
339
+ * @param {string[]} attributes - optional attributes to include in the response.
340
+ * @returns {Promise<TeamList[]>} - A promise that resolves to the list of teams.
341
+ * @throws {Error} - Throws an error if the API call fails or if the response status is not 200.
342
+ * @private
343
+ */
344
+ public async getAllTeams(orgId: string, pageSize: number, filter: string[]): Promise<TeamList[]> {
345
+ try {
346
+ let allTeams: TeamList[] = [];
347
+ let page = DEFAULT_PAGE;
348
+ const firstResponse = await this.getListOfTeams(orgId, page, pageSize, filter);
349
+ const totalPages = firstResponse.meta.totalPages;
350
+ allTeams = allTeams.concat(firstResponse.data);
351
+ const requests = [];
352
+ for (page = DEFAULT_PAGE + 1; page < totalPages; page += 1) {
353
+ requests.push(this.getListOfTeams(orgId, page, pageSize, filter));
354
+ }
355
+ const responses = await Promise.all(requests);
356
+
357
+ for (const response of responses) {
358
+ allTeams = allTeams.concat(response.data);
359
+ }
360
+
361
+ return allTeams;
362
+ } catch (error) {
363
+ LoggerProxy.error(`getAllTeams API call failed with ${error}`, {
364
+ module: CONFIG_FILE_NAME,
365
+ method: METHODS.GET_ALL_TEAMS,
366
+ });
367
+ throw error;
368
+ }
369
+ }
370
+
371
+ /**
372
+ * fetches the list of aux codes for the given orgId.
373
+ * @ignore
374
+ * @param {string} orgId - organization ID for which the aux codes are to be fetched.
375
+ * @param {number} page - the page number to fetch.
376
+ * @param {number} pageSize - the number of aux codes to fetch per page.
377
+ * @param {string[]} filter - optional filter criteria for the aux codes.
378
+ * @param {string[]} attributes - optional attributes to include in the response.
379
+ * @returns {Promise<ListAuxCodesResponse>} - A promise that resolves to the list of aux codes response.
380
+ * @throws {Error} - Throws an error if the API call fails or if the response status is not 200.
381
+ * @private
382
+ */
383
+ public async getListOfAuxCodes(
384
+ orgId: string,
385
+ page: number,
386
+ pageSize: number,
387
+ filter: string[],
388
+ attributes: string[]
389
+ ): Promise<ListAuxCodesResponse> {
390
+ LoggerProxy.info('Fetching list of aux codes', {
391
+ module: CONFIG_FILE_NAME,
392
+ method: METHODS.GET_LIST_OF_AUX_CODES,
393
+ });
394
+
395
+ try {
396
+ const resource = endPointMap.listAuxCodes(orgId, page, pageSize, filter, attributes);
397
+ const response = await this.webexReq.request({
398
+ service: WCC_API_GATEWAY,
399
+ resource,
400
+ method: HTTP_METHODS.GET,
401
+ });
402
+
403
+ if (response.statusCode !== 200) {
404
+ throw new Error(`API call failed with ${response.statusCode}`);
405
+ }
406
+
407
+ LoggerProxy.log('getListOfAuxCodes api success.', {
408
+ module: CONFIG_FILE_NAME,
409
+ method: METHODS.GET_LIST_OF_AUX_CODES,
410
+ });
411
+
412
+ return Promise.resolve(response.body);
413
+ } catch (error) {
414
+ LoggerProxy.error(`getListOfAuxCodes API call failed with ${error}`, {
415
+ module: CONFIG_FILE_NAME,
416
+ method: METHODS.GET_LIST_OF_AUX_CODES,
417
+ });
418
+ throw error;
419
+ }
420
+ }
421
+
422
+ /**
423
+ * Fetches all aux codes from all pages for the given orgId
424
+ * @ignore
425
+ * @param {string} orgId - organization ID for which the aux codes are to be fetched.
426
+ * @param {number} pageSize - the number of aux codes to fetch per page.
427
+ * @param {string[]} filter - optional filter criteria for the aux codes.
428
+ * @param {string[]} attributes - optional attributes to include in the response.
429
+ * @returns {Promise<AuxCode[]>} - A promise that resolves to the list of aux codes.
430
+ * @throws {Error} - Throws an error if the API call fails or if the response status is not 200.
431
+ * @private
432
+ */
433
+ public async getAllAuxCodes(
434
+ orgId: string,
435
+ pageSize: number,
436
+ filter: string[],
437
+ attributes: string[]
438
+ ): Promise<AuxCode[]> {
439
+ try {
440
+ let allAuxCodes: AuxCode[] = [];
441
+ let page = DEFAULT_PAGE;
442
+
443
+ const firstResponse = await this.getListOfAuxCodes(orgId, page, pageSize, filter, attributes);
444
+ allAuxCodes = allAuxCodes.concat(firstResponse.data);
445
+ const totalPages = firstResponse.meta.totalPages;
446
+
447
+ const promises: Promise<ListAuxCodesResponse>[] = [];
448
+ for (page = DEFAULT_PAGE + 1; page < totalPages; page += 1) {
449
+ promises.push(this.getListOfAuxCodes(orgId, page, pageSize, filter, attributes));
450
+ }
451
+
452
+ const responses = await Promise.all(promises);
453
+
454
+ responses.forEach((response) => {
455
+ allAuxCodes = allAuxCodes.concat(response.data);
456
+ });
457
+
458
+ return allAuxCodes;
459
+ } catch (error) {
460
+ LoggerProxy.error(`getAllAuxCodes API call failed with ${error}`, {
461
+ module: CONFIG_FILE_NAME,
462
+ method: METHODS.GET_ALL_AUX_CODES,
463
+ });
464
+ throw error;
465
+ }
466
+ }
467
+
468
+ /**
469
+ * Fetches the site data for the given orgId and siteId.
470
+ * @ignore
471
+ * @param {string} orgId - organization ID for which the site info is to be fetched.
472
+ * @param {string} siteId - site ID for which the data is to be fetched.
473
+ * @returns {Promise<SiteInfo>} - A promise that resolves to the site info response.
474
+ * @throws {Error} - Throws an error if the API call fails or if the response status is not 200.
475
+ * @private
476
+ */
477
+ public async getSiteInfo(orgId: string, siteId: string): Promise<SiteInfo> {
478
+ LoggerProxy.info('Fetching site information', {
479
+ module: CONFIG_FILE_NAME,
480
+ method: METHODS.GET_SITE_INFO,
481
+ });
482
+ try {
483
+ const resource = endPointMap.siteInfo(orgId, siteId);
484
+ const response = await this.webexReq.request({
485
+ service: WCC_API_GATEWAY,
486
+ resource,
487
+ method: HTTP_METHODS.GET,
488
+ });
489
+
490
+ if (response.statusCode !== 200) {
491
+ throw new Error(`API call failed with ${response.statusCode}`);
492
+ }
493
+
494
+ LoggerProxy.log('getSiteInfo api success.', {
495
+ module: CONFIG_FILE_NAME,
496
+ method: METHODS.GET_SITE_INFO,
497
+ });
498
+
499
+ return Promise.resolve(response.body);
500
+ } catch (error) {
501
+ LoggerProxy.error(`getSiteInfo API call failed with ${error}`, {
502
+ module: CONFIG_FILE_NAME,
503
+ method: METHODS.GET_SITE_INFO,
504
+ });
505
+ throw error;
506
+ }
507
+ }
508
+
509
+ /**
510
+ * Fetches the organization info for the given orgId.
511
+ * @ignore
512
+ * @param {string} orgId - organization ID for which the organization info is to be fetched.
513
+ * @returns {Promise<OrgInfo>} - A promise that resolves to the organization info response.
514
+ * @throws {Error} - Throws an error if the API call fails or if the response status is not 200.
515
+ * @private
516
+ */
517
+ public async getOrgInfo(orgId: string): Promise<OrgInfo> {
518
+ try {
519
+ const resource = endPointMap.orgInfo(orgId);
520
+ const response = await this.webexReq.request({
521
+ service: WCC_API_GATEWAY,
522
+ resource,
523
+ method: HTTP_METHODS.GET,
524
+ });
525
+
526
+ if (response.statusCode !== 200) {
527
+ throw new Error(`API call failed with ${response.statusCode}`);
528
+ }
529
+
530
+ LoggerProxy.log('getOrgInfo api success.', {
531
+ module: CONFIG_FILE_NAME,
532
+ method: METHODS.GET_ORG_INFO,
533
+ });
534
+
535
+ return Promise.resolve(response.body);
536
+ } catch (error) {
537
+ LoggerProxy.error(`getOrgInfo API call failed with ${error}`, {
538
+ module: CONFIG_FILE_NAME,
539
+ method: METHODS.GET_ORG_INFO,
540
+ });
541
+ throw error;
542
+ }
543
+ }
544
+
545
+ /**
546
+ * Fetches the organization settings for the given orgId.
547
+ * @ignore
548
+ * @param {string} orgId - organization ID for which the organization settings are to be fetched.
549
+ * @returns {Promise<OrgSettings>} - A promise that resolves to the organization settings response.
550
+ * @throws {Error} - Throws an error if the API call fails or if the response status is not 200.
551
+ * @private
552
+ */
553
+ public async getOrganizationSetting(orgId: string): Promise<OrgSettings> {
554
+ try {
555
+ const resource = endPointMap.orgSettings(orgId);
556
+ const response = await this.webexReq.request({
557
+ service: WCC_API_GATEWAY,
558
+ resource,
559
+ method: HTTP_METHODS.GET,
560
+ });
561
+
562
+ if (response.statusCode !== 200) {
563
+ throw new Error(`API call failed with ${response.statusCode}`);
564
+ }
565
+
566
+ LoggerProxy.log('getOrganizationSetting api success.', {
567
+ module: CONFIG_FILE_NAME,
568
+ method: METHODS.GET_ORGANIZATION_SETTING,
569
+ });
570
+
571
+ return Promise.resolve(response.body.data[0]);
572
+ } catch (error) {
573
+ LoggerProxy.error(`getOrganizationSetting API call failed with ${error}`, {
574
+ module: CONFIG_FILE_NAME,
575
+ method: METHODS.GET_ORGANIZATION_SETTING,
576
+ });
577
+ throw error;
578
+ }
579
+ }
580
+
581
+ /**
582
+ * Fetches the tenant data for the given orgId.
583
+ * @ignore
584
+ * @param {string} orgId - organization ID for which the tenant data is to be fetched.
585
+ * @returns {Promise<TenantData>} - A promise that resolves to the tenant data response.
586
+ * @throws {Error} - Throws an error if the API call fails or if the response status is not 200.
587
+ * @private
588
+ */
589
+ public async getTenantData(orgId: string): Promise<TenantData> {
590
+ try {
591
+ const resource = endPointMap.tenantData(orgId);
592
+ const response = await this.webexReq.request({
593
+ service: WCC_API_GATEWAY,
594
+ resource,
595
+ method: HTTP_METHODS.GET,
596
+ });
597
+
598
+ if (response.statusCode !== 200) {
599
+ throw new Error(`API call failed with ${response.statusCode}`);
600
+ }
601
+
602
+ LoggerProxy.log('getTenantData api success.', {
603
+ module: CONFIG_FILE_NAME,
604
+ method: METHODS.GET_TENANT_DATA,
605
+ });
606
+
607
+ return Promise.resolve(response.body.data[0]);
608
+ } catch (error) {
609
+ LoggerProxy.error(`getTenantData API call failed with ${error}`, {
610
+ module: CONFIG_FILE_NAME,
611
+ method: METHODS.GET_TENANT_DATA,
612
+ });
613
+ throw error;
614
+ }
615
+ }
616
+
617
+ /**
618
+ * Fetches the URL mapping data for the given orgId.
619
+ * @ignore
620
+ * @param {string} orgId - organization ID for which the URL mapping is to be fetched.
621
+ * @returns {Promise<URLMapping[]>} - A promise that resolves to the URL mapping response.
622
+ * @throws {Error} - Throws an error if the API call fails or if the response status is not 200.
623
+ * @private
624
+ */
625
+ public async getURLMapping(orgId: string): Promise<URLMapping[]> {
626
+ try {
627
+ const resource = endPointMap.urlMapping(orgId);
628
+ const response = await this.webexReq.request({
629
+ service: WCC_API_GATEWAY,
630
+ resource,
631
+ method: HTTP_METHODS.GET,
632
+ });
633
+
634
+ if (response.statusCode !== 200) {
635
+ throw new Error(`API call failed with ${response.statusCode}`);
636
+ }
637
+
638
+ LoggerProxy.log('getURLMapping api success.', {
639
+ module: CONFIG_FILE_NAME,
640
+ method: METHODS.GET_URL_MAPPING,
641
+ });
642
+
643
+ return Promise.resolve(response.body.data);
644
+ } catch (error) {
645
+ LoggerProxy.error(`getURLMapping API call failed with ${error}`, {
646
+ module: CONFIG_FILE_NAME,
647
+ method: METHODS.GET_URL_MAPPING,
648
+ });
649
+ throw error;
650
+ }
651
+ }
652
+
653
+ /**
654
+ * Fetches the dial plan data for the given orgId.
655
+ * @ignore
656
+ * @param {string} orgId - organization ID for which the dial plan data is to be fetched.
657
+ * @returns {Promise<DialPlanEntity[]>} - A promise that resolves to the dial plan data response.
658
+ * @throws {Error} - Throws an error if the API call fails or if the response status is not 200.
659
+ * @private
660
+ */
661
+ public async getDialPlanData(orgId: string): Promise<DialPlanEntity[]> {
662
+ try {
663
+ const resource = endPointMap.dialPlan(orgId);
664
+ const response = await this.webexReq.request({
665
+ service: WCC_API_GATEWAY,
666
+ resource,
667
+ method: HTTP_METHODS.GET,
668
+ });
669
+
670
+ if (response.statusCode !== 200) {
671
+ throw new Error(`API call failed with ${response.statusCode}`);
672
+ }
673
+
674
+ LoggerProxy.log('getDialPlanData api success.', {
675
+ module: CONFIG_FILE_NAME,
676
+ method: METHODS.GET_DIAL_PLAN_DATA,
677
+ });
678
+
679
+ return Promise.resolve(response.body);
680
+ } catch (error) {
681
+ LoggerProxy.error(`getDialPlanData API call failed with ${error}`, {
682
+ module: CONFIG_FILE_NAME,
683
+ method: METHODS.GET_DIAL_PLAN_DATA,
684
+ });
685
+ throw error;
686
+ }
687
+ }
688
+
689
+ /**
690
+ * Fetches the list of queues for the given orgId.
691
+ * @ignore
692
+ * @param {string} orgId - organization ID for which the queues are to be fetched.
693
+ * @param {number} page - the page number to fetch.
694
+ * @param {number} pageSize - the number of queues to fetch per page.
695
+ * @param {string} search - optional search string
696
+ * @param {string} filter - optional filter string
697
+ * @returns Promise<ContactServiceQueue[]> - A promise that resolves to the list of contact service queues.
698
+ * @throws {Error} - Throws an error if the API call fails or if the response status is not 200.
699
+ * @private
700
+ */
701
+ public async getQueues(
702
+ orgId: string,
703
+ page: number,
704
+ pageSize: number,
705
+ search?: string,
706
+ filter?: string
707
+ ): Promise<ContactServiceQueue[]> {
708
+ LoggerProxy.info('Fetching queue list', {
709
+ module: CONFIG_FILE_NAME,
710
+ method: METHODS.GET_QUEUES,
711
+ });
712
+
713
+ try {
714
+ let queryParams = `page=${page}&pageSize=${pageSize}&desktopProfileFilter=true`;
715
+ if (search) queryParams += `&search=${search}`;
716
+ if (filter) queryParams += `&filter=${filter}`;
717
+
718
+ const resource = endPointMap.queueList(orgId, queryParams);
719
+ const response = await this.webexReq.request({
720
+ service: WCC_API_GATEWAY,
721
+ resource,
722
+ method: HTTP_METHODS.GET,
723
+ });
724
+
725
+ if (response.statusCode !== 200) {
726
+ throw new Error(`API call failed with ${response.statusCode}`);
727
+ }
728
+
729
+ LoggerProxy.log('getQueues API success.', {
730
+ module: CONFIG_FILE_NAME,
731
+ method: METHODS.GET_QUEUES,
732
+ });
733
+
734
+ return response.body?.data;
735
+ } catch (error) {
736
+ LoggerProxy.error(`getQueues API call failed with ${error}`, {
737
+ module: CONFIG_FILE_NAME,
738
+ method: METHODS.GET_QUEUES,
739
+ });
740
+ throw error;
741
+ }
742
+ }
743
+ }