@webex/calling 3.12.0 → 3.13.0-next.10

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 (326) hide show
  1. package/README.md +1 -1
  2. package/dist/CallHistory/CallHistory.js +1 -1
  3. package/dist/CallHistory/CallHistory.js.map +1 -1
  4. package/dist/CallHistory/CallHistory.test.js +2 -1
  5. package/dist/CallHistory/CallHistory.test.js.map +1 -1
  6. package/dist/CallQueue/CallQueue.js +1322 -0
  7. package/dist/CallQueue/CallQueue.js.map +1 -0
  8. package/dist/CallQueue/CallQueue.test.js +3321 -0
  9. package/dist/CallQueue/CallQueue.test.js.map +1 -0
  10. package/dist/CallQueue/constants.js +65 -0
  11. package/dist/CallQueue/constants.js.map +1 -0
  12. package/dist/CallQueue/types.js +4 -0
  13. package/dist/CallQueue/types.js.map +1 -0
  14. package/dist/CallQueue/utils.js +370 -0
  15. package/dist/CallQueue/utils.js.map +1 -0
  16. package/dist/CallQueue/utils.test.js +548 -0
  17. package/dist/CallQueue/utils.test.js.map +1 -0
  18. package/dist/CallRecording/CallRecording.js +160 -0
  19. package/dist/CallRecording/CallRecording.js.map +1 -0
  20. package/dist/CallRecording/CallRecording.test.js +257 -0
  21. package/dist/CallRecording/CallRecording.test.js.map +1 -0
  22. package/dist/CallRecording/WxcCallRecordingConnector.js +748 -0
  23. package/dist/CallRecording/WxcCallRecordingConnector.js.map +1 -0
  24. package/dist/CallRecording/WxcCallRecordingConnector.test.js +824 -0
  25. package/dist/CallRecording/WxcCallRecordingConnector.test.js.map +1 -0
  26. package/dist/CallRecording/callRecordingFixtures.js +266 -0
  27. package/dist/CallRecording/callRecordingFixtures.js.map +1 -0
  28. package/dist/CallRecording/constants.js +35 -0
  29. package/dist/CallRecording/constants.js.map +1 -0
  30. package/dist/CallRecording/types.js +142 -0
  31. package/dist/CallRecording/types.js.map +1 -0
  32. package/dist/CallRecording/userhub.js +117 -0
  33. package/dist/CallRecording/userhub.js.map +1 -0
  34. package/dist/CallRecording/utils.js +42 -0
  35. package/dist/CallRecording/utils.js.map +1 -0
  36. package/dist/CallRecording/utils.test.js +97 -0
  37. package/dist/CallRecording/utils.test.js.map +1 -0
  38. package/dist/CallingClient/CallingClient.js +469 -233
  39. package/dist/CallingClient/CallingClient.js.map +1 -1
  40. package/dist/CallingClient/CallingClient.test.js +736 -179
  41. package/dist/CallingClient/CallingClient.test.js.map +1 -1
  42. package/dist/CallingClient/calling/CallerId/index.js +3 -1
  43. package/dist/CallingClient/calling/CallerId/index.js.map +1 -1
  44. package/dist/CallingClient/calling/CallerId/index.test.js +12 -2
  45. package/dist/CallingClient/calling/CallerId/index.test.js.map +1 -1
  46. package/dist/CallingClient/calling/call.js +645 -458
  47. package/dist/CallingClient/calling/call.js.map +1 -1
  48. package/dist/CallingClient/calling/call.test.js +928 -498
  49. package/dist/CallingClient/calling/call.test.js.map +1 -1
  50. package/dist/CallingClient/calling/callManager.js +106 -35
  51. package/dist/CallingClient/calling/callManager.js.map +1 -1
  52. package/dist/CallingClient/calling/callManager.test.js +140 -0
  53. package/dist/CallingClient/calling/callManager.test.js.map +1 -1
  54. package/dist/CallingClient/calling/types.js +5 -0
  55. package/dist/CallingClient/calling/types.js.map +1 -1
  56. package/dist/CallingClient/constants.js +34 -4
  57. package/dist/CallingClient/constants.js.map +1 -1
  58. package/dist/CallingClient/line/index.js +27 -3
  59. package/dist/CallingClient/line/index.js.map +1 -1
  60. package/dist/CallingClient/line/line.test.js +102 -17
  61. package/dist/CallingClient/line/line.test.js.map +1 -1
  62. package/dist/CallingClient/registration/register.js +971 -506
  63. package/dist/CallingClient/registration/register.js.map +1 -1
  64. package/dist/CallingClient/registration/register.test.js +1037 -116
  65. package/dist/CallingClient/registration/register.test.js.map +1 -1
  66. package/dist/CallingClient/registration/types.js +26 -0
  67. package/dist/CallingClient/registration/types.js.map +1 -1
  68. package/dist/CallingClient/registration/webWorker.js +41 -104
  69. package/dist/CallingClient/registration/webWorker.js.map +1 -1
  70. package/dist/CallingClient/registration/webWorker.test.js +39 -153
  71. package/dist/CallingClient/registration/webWorker.test.js.map +1 -1
  72. package/dist/CallingClient/registration/webWorkerStr.js +1 -1
  73. package/dist/CallingClient/registration/webWorkerStr.js.map +1 -1
  74. package/dist/CallingClient/types.js +7 -0
  75. package/dist/CallingClient/types.js.map +1 -1
  76. package/dist/CallingClient/utils/constants.js +58 -0
  77. package/dist/CallingClient/utils/constants.js.map +1 -0
  78. package/dist/CallingClient/utils/index.js +63 -0
  79. package/dist/CallingClient/utils/index.js.map +1 -0
  80. package/dist/CallingClient/utils/mobiusSocketMapper.js +122 -0
  81. package/dist/CallingClient/utils/mobiusSocketMapper.js.map +1 -0
  82. package/dist/CallingClient/utils/mobiusSocketMapper.test.js +221 -0
  83. package/dist/CallingClient/utils/mobiusSocketMapper.test.js.map +1 -0
  84. package/dist/CallingClient/utils/request.js +435 -0
  85. package/dist/CallingClient/utils/request.js.map +1 -0
  86. package/dist/CallingClient/utils/request.test.js +999 -0
  87. package/dist/CallingClient/utils/request.test.js.map +1 -0
  88. package/dist/CallingClient/utils/types.js +7 -0
  89. package/dist/CallingClient/utils/types.js.map +1 -0
  90. package/dist/CallingClient/utils/wsFeatureFlag.js +70 -0
  91. package/dist/CallingClient/utils/wsFeatureFlag.js.map +1 -0
  92. package/dist/CallingClient/utils/wsFeatureFlag.test.js +139 -0
  93. package/dist/CallingClient/utils/wsFeatureFlag.test.js.map +1 -0
  94. package/dist/Contacts/ContactsClient.js +13 -11
  95. package/dist/Contacts/ContactsClient.js.map +1 -1
  96. package/dist/Contacts/ContactsClient.test.js +3 -8
  97. package/dist/Contacts/ContactsClient.test.js.map +1 -1
  98. package/dist/Errors/types.js +2 -0
  99. package/dist/Errors/types.js.map +1 -1
  100. package/dist/Events/types.js +39 -11
  101. package/dist/Events/types.js.map +1 -1
  102. package/dist/Metrics/index.js +63 -2
  103. package/dist/Metrics/index.js.map +1 -1
  104. package/dist/Metrics/index.test.js +357 -1
  105. package/dist/Metrics/index.test.js.map +1 -1
  106. package/dist/Metrics/types.js +19 -1
  107. package/dist/Metrics/types.js.map +1 -1
  108. package/dist/SDKConnector/types.js.map +1 -1
  109. package/dist/Voicemail/Voicemail.js +10 -10
  110. package/dist/Voicemail/Voicemail.js.map +1 -1
  111. package/dist/Voicemail/Voicemail.test.js +40 -20
  112. package/dist/Voicemail/Voicemail.test.js.map +1 -1
  113. package/dist/api.js +95 -0
  114. package/dist/api.js.map +1 -1
  115. package/dist/common/Utils.js +259 -133
  116. package/dist/common/Utils.js.map +1 -1
  117. package/dist/common/Utils.test.js +643 -298
  118. package/dist/common/Utils.test.js.map +1 -1
  119. package/dist/common/callUtils.js +187 -0
  120. package/dist/common/callUtils.js.map +1 -0
  121. package/dist/common/callUtils.test.js +313 -0
  122. package/dist/common/callUtils.test.js.map +1 -0
  123. package/dist/common/constants.js +27 -1
  124. package/dist/common/constants.js.map +1 -1
  125. package/dist/common/index.js +11 -0
  126. package/dist/common/index.js.map +1 -1
  127. package/dist/common/testUtil.js +11 -5
  128. package/dist/common/testUtil.js.map +1 -1
  129. package/dist/common/types.js +3 -0
  130. package/dist/common/types.js.map +1 -1
  131. package/dist/index.js +228 -40
  132. package/dist/index.js.map +1 -1
  133. package/dist/mobius-socket/config.js +24 -0
  134. package/dist/mobius-socket/config.js.map +1 -0
  135. package/dist/mobius-socket/errors.js +143 -0
  136. package/dist/mobius-socket/errors.js.map +1 -0
  137. package/dist/mobius-socket/errors.test.js +20 -0
  138. package/dist/mobius-socket/errors.test.js.map +1 -0
  139. package/dist/mobius-socket/index.js +57 -0
  140. package/dist/mobius-socket/index.js.map +1 -0
  141. package/dist/mobius-socket/mobius-socket-events.test.js +493 -0
  142. package/dist/mobius-socket/mobius-socket-events.test.js.map +1 -0
  143. package/dist/mobius-socket/mobius-socket.js +849 -0
  144. package/dist/mobius-socket/mobius-socket.js.map +1 -0
  145. package/dist/mobius-socket/mobius-socket.test.js +1898 -0
  146. package/dist/mobius-socket/mobius-socket.test.js.map +1 -0
  147. package/dist/mobius-socket/socket/constants.js +55 -0
  148. package/dist/mobius-socket/socket/constants.js.map +1 -0
  149. package/dist/mobius-socket/socket/index.js +15 -0
  150. package/dist/mobius-socket/socket/index.js.map +1 -0
  151. package/dist/mobius-socket/socket/socket-base.js +614 -0
  152. package/dist/mobius-socket/socket/socket-base.js.map +1 -0
  153. package/dist/mobius-socket/socket/socket.js +19 -0
  154. package/dist/mobius-socket/socket/socket.js.map +1 -0
  155. package/dist/mobius-socket/socket/socket.shim.js +26 -0
  156. package/dist/mobius-socket/socket/socket.shim.js.map +1 -0
  157. package/dist/mobius-socket/socket/types.js +7 -0
  158. package/dist/mobius-socket/socket/types.js.map +1 -0
  159. package/dist/mobius-socket/socket.test.js +747 -0
  160. package/dist/mobius-socket/socket.test.js.map +1 -0
  161. package/dist/mobius-socket/test/mocha-helpers.js +23 -0
  162. package/dist/mobius-socket/test/mocha-helpers.js.map +1 -0
  163. package/dist/mobius-socket/test/promise-tick.js +28 -0
  164. package/dist/mobius-socket/test/promise-tick.js.map +1 -0
  165. package/dist/mobius-socket/types.js +7 -0
  166. package/dist/mobius-socket/types.js.map +1 -0
  167. package/dist/module/CallHistory/CallHistory.js +1 -1
  168. package/dist/module/CallQueue/CallQueue.js +718 -0
  169. package/dist/module/CallQueue/constants.js +41 -0
  170. package/dist/module/CallQueue/types.js +1 -0
  171. package/dist/module/CallQueue/utils.js +253 -0
  172. package/dist/module/CallRecording/CallRecording.js +56 -0
  173. package/dist/module/CallRecording/WxcCallRecordingConnector.js +349 -0
  174. package/dist/module/CallRecording/callRecordingFixtures.js +231 -0
  175. package/dist/module/CallRecording/constants.js +27 -0
  176. package/dist/module/CallRecording/types.js +19 -0
  177. package/dist/module/CallRecording/userhub.js +100 -0
  178. package/dist/module/CallRecording/utils.js +14 -0
  179. package/dist/module/CallingClient/CallingClient.js +137 -20
  180. package/dist/module/CallingClient/calling/CallerId/index.js +2 -2
  181. package/dist/module/CallingClient/calling/call.js +207 -68
  182. package/dist/module/CallingClient/calling/callManager.js +51 -11
  183. package/dist/module/CallingClient/calling/types.js +2 -0
  184. package/dist/module/CallingClient/constants.js +29 -1
  185. package/dist/module/CallingClient/line/index.js +11 -3
  186. package/dist/module/CallingClient/registration/register.js +297 -68
  187. package/dist/module/CallingClient/registration/types.js +5 -1
  188. package/dist/module/CallingClient/registration/webWorker.js +42 -61
  189. package/dist/module/CallingClient/registration/webWorkerStr.js +47 -82
  190. package/dist/module/CallingClient/utils/constants.js +36 -0
  191. package/dist/module/CallingClient/utils/index.js +5 -0
  192. package/dist/module/CallingClient/utils/mobiusSocketMapper.js +72 -0
  193. package/dist/module/CallingClient/utils/request.js +211 -0
  194. package/dist/module/CallingClient/utils/types.js +1 -0
  195. package/dist/module/CallingClient/utils/wsFeatureFlag.js +41 -0
  196. package/dist/module/Contacts/ContactsClient.js +1 -1
  197. package/dist/module/Errors/types.js +2 -0
  198. package/dist/module/Events/types.js +24 -10
  199. package/dist/module/Metrics/index.js +48 -1
  200. package/dist/module/Metrics/types.js +18 -0
  201. package/dist/module/Voicemail/Voicemail.js +10 -10
  202. package/dist/module/api.js +6 -2
  203. package/dist/module/common/Utils.js +110 -63
  204. package/dist/module/common/callUtils.js +90 -0
  205. package/dist/module/common/constants.js +11 -0
  206. package/dist/module/common/index.js +1 -0
  207. package/dist/module/common/testUtil.js +7 -1
  208. package/dist/module/common/types.js +3 -0
  209. package/dist/module/index.js +10 -3
  210. package/dist/module/mobius-socket/config.js +15 -0
  211. package/dist/module/mobius-socket/errors.js +58 -0
  212. package/dist/module/mobius-socket/index.js +24 -0
  213. package/dist/module/mobius-socket/mobius-socket.js +593 -0
  214. package/dist/module/mobius-socket/socket/constants.js +26 -0
  215. package/dist/module/mobius-socket/socket/index.js +4 -0
  216. package/dist/module/mobius-socket/socket/socket-base.js +376 -0
  217. package/dist/module/mobius-socket/socket/socket.js +9 -0
  218. package/dist/module/mobius-socket/socket/socket.shim.js +12 -0
  219. package/dist/module/mobius-socket/socket/types.js +1 -0
  220. package/dist/module/mobius-socket/types.js +1 -0
  221. package/dist/types/CallQueue/CallQueue.d.ts +45 -0
  222. package/dist/types/CallQueue/CallQueue.d.ts.map +1 -0
  223. package/dist/types/CallQueue/constants.d.ts +37 -0
  224. package/dist/types/CallQueue/constants.d.ts.map +1 -0
  225. package/dist/types/CallQueue/types.d.ts +97 -0
  226. package/dist/types/CallQueue/types.d.ts.map +1 -0
  227. package/dist/types/CallQueue/utils.d.ts +19 -0
  228. package/dist/types/CallQueue/utils.d.ts.map +1 -0
  229. package/dist/types/CallRecording/CallRecording.d.ts +18 -0
  230. package/dist/types/CallRecording/CallRecording.d.ts.map +1 -0
  231. package/dist/types/CallRecording/WxcCallRecordingConnector.d.ts +27 -0
  232. package/dist/types/CallRecording/WxcCallRecordingConnector.d.ts.map +1 -0
  233. package/dist/types/CallRecording/callRecordingFixtures.d.ts +152 -0
  234. package/dist/types/CallRecording/callRecordingFixtures.d.ts.map +1 -0
  235. package/dist/types/CallRecording/constants.d.ts +28 -0
  236. package/dist/types/CallRecording/constants.d.ts.map +1 -0
  237. package/dist/types/CallRecording/types.d.ts +184 -0
  238. package/dist/types/CallRecording/types.d.ts.map +1 -0
  239. package/dist/types/CallRecording/userhub.d.ts +44 -0
  240. package/dist/types/CallRecording/userhub.d.ts.map +1 -0
  241. package/dist/types/CallRecording/utils.d.ts +3 -0
  242. package/dist/types/CallRecording/utils.d.ts.map +1 -0
  243. package/dist/types/CallingClient/CallingClient.d.ts +8 -0
  244. package/dist/types/CallingClient/CallingClient.d.ts.map +1 -1
  245. package/dist/types/CallingClient/calling/CallerId/index.d.ts.map +1 -1
  246. package/dist/types/CallingClient/calling/call.d.ts +17 -3
  247. package/dist/types/CallingClient/calling/call.d.ts.map +1 -1
  248. package/dist/types/CallingClient/calling/callManager.d.ts +8 -4
  249. package/dist/types/CallingClient/calling/callManager.d.ts.map +1 -1
  250. package/dist/types/CallingClient/calling/types.d.ts +38 -9
  251. package/dist/types/CallingClient/calling/types.d.ts.map +1 -1
  252. package/dist/types/CallingClient/constants.d.ts +29 -1
  253. package/dist/types/CallingClient/constants.d.ts.map +1 -1
  254. package/dist/types/CallingClient/line/index.d.ts +3 -2
  255. package/dist/types/CallingClient/line/index.d.ts.map +1 -1
  256. package/dist/types/CallingClient/registration/register.d.ts +9 -1
  257. package/dist/types/CallingClient/registration/register.d.ts.map +1 -1
  258. package/dist/types/CallingClient/registration/types.d.ts +26 -2
  259. package/dist/types/CallingClient/registration/types.d.ts.map +1 -1
  260. package/dist/types/CallingClient/registration/webWorker.d.ts.map +1 -1
  261. package/dist/types/CallingClient/registration/webWorkerStr.d.ts +1 -1
  262. package/dist/types/CallingClient/registration/webWorkerStr.d.ts.map +1 -1
  263. package/dist/types/CallingClient/types.d.ts +6 -2
  264. package/dist/types/CallingClient/types.d.ts.map +1 -1
  265. package/dist/types/CallingClient/utils/constants.d.ts +35 -0
  266. package/dist/types/CallingClient/utils/constants.d.ts.map +1 -0
  267. package/dist/types/CallingClient/utils/index.d.ts +6 -0
  268. package/dist/types/CallingClient/utils/index.d.ts.map +1 -0
  269. package/dist/types/CallingClient/utils/mobiusSocketMapper.d.ts +5 -0
  270. package/dist/types/CallingClient/utils/mobiusSocketMapper.d.ts.map +1 -0
  271. package/dist/types/CallingClient/utils/request.d.ts +28 -0
  272. package/dist/types/CallingClient/utils/request.d.ts.map +1 -0
  273. package/dist/types/CallingClient/utils/types.d.ts +34 -0
  274. package/dist/types/CallingClient/utils/types.d.ts.map +1 -0
  275. package/dist/types/CallingClient/utils/wsFeatureFlag.d.ts +4 -0
  276. package/dist/types/CallingClient/utils/wsFeatureFlag.d.ts.map +1 -0
  277. package/dist/types/Errors/types.d.ts +2 -0
  278. package/dist/types/Errors/types.d.ts.map +1 -1
  279. package/dist/types/Events/types.d.ts +81 -16
  280. package/dist/types/Events/types.d.ts.map +1 -1
  281. package/dist/types/Metrics/index.d.ts.map +1 -1
  282. package/dist/types/Metrics/types.d.ts +19 -2
  283. package/dist/types/Metrics/types.d.ts.map +1 -1
  284. package/dist/types/SDKConnector/types.d.ts +41 -13
  285. package/dist/types/SDKConnector/types.d.ts.map +1 -1
  286. package/dist/types/api.d.ts +10 -4
  287. package/dist/types/api.d.ts.map +1 -1
  288. package/dist/types/common/Utils.d.ts +11 -5
  289. package/dist/types/common/Utils.d.ts.map +1 -1
  290. package/dist/types/common/callUtils.d.ts +6 -0
  291. package/dist/types/common/callUtils.d.ts.map +1 -0
  292. package/dist/types/common/constants.d.ts +6 -0
  293. package/dist/types/common/constants.d.ts.map +1 -1
  294. package/dist/types/common/index.d.ts +1 -0
  295. package/dist/types/common/index.d.ts.map +1 -1
  296. package/dist/types/common/testUtil.d.ts +6 -1
  297. package/dist/types/common/testUtil.d.ts.map +1 -1
  298. package/dist/types/common/types.d.ts +5 -1
  299. package/dist/types/common/types.d.ts.map +1 -1
  300. package/dist/types/index.d.ts +13 -4
  301. package/dist/types/index.d.ts.map +1 -1
  302. package/dist/types/mobius-socket/config.d.ts +17 -0
  303. package/dist/types/mobius-socket/config.d.ts.map +1 -0
  304. package/dist/types/mobius-socket/errors.d.ts +32 -0
  305. package/dist/types/mobius-socket/errors.d.ts.map +1 -0
  306. package/dist/types/mobius-socket/index.d.ts +14 -0
  307. package/dist/types/mobius-socket/index.d.ts.map +1 -0
  308. package/dist/types/mobius-socket/mobius-socket.d.ts +48 -0
  309. package/dist/types/mobius-socket/mobius-socket.d.ts.map +1 -0
  310. package/dist/types/mobius-socket/socket/constants.d.ts +27 -0
  311. package/dist/types/mobius-socket/socket/constants.d.ts.map +1 -0
  312. package/dist/types/mobius-socket/socket/index.d.ts +5 -0
  313. package/dist/types/mobius-socket/socket/index.d.ts.map +1 -0
  314. package/dist/types/mobius-socket/socket/socket-base.d.ts +43 -0
  315. package/dist/types/mobius-socket/socket/socket-base.d.ts.map +1 -0
  316. package/dist/types/mobius-socket/socket/socket.d.ts +6 -0
  317. package/dist/types/mobius-socket/socket/socket.d.ts.map +1 -0
  318. package/dist/types/mobius-socket/socket/socket.shim.d.ts +6 -0
  319. package/dist/types/mobius-socket/socket/socket.shim.d.ts.map +1 -0
  320. package/dist/types/mobius-socket/socket/types.d.ts +61 -0
  321. package/dist/types/mobius-socket/socket/types.d.ts.map +1 -0
  322. package/dist/types/mobius-socket/types.d.ts +21 -0
  323. package/dist/types/mobius-socket/types.d.ts.map +1 -0
  324. package/package.json +21 -18
  325. package/src/mobius-socket/socket/socket.shim.ts +22 -0
  326. package/src/mobius-socket/socket/socket.ts +14 -0
@@ -0,0 +1,1322 @@
1
+ "use strict";
2
+
3
+ var _typeof3 = require("@babel/runtime-corejs2/helpers/typeof");
4
+ var _Reflect$construct = require("@babel/runtime-corejs2/core-js/reflect/construct");
5
+ var _Object$keys = require("@babel/runtime-corejs2/core-js/object/keys");
6
+ var _Object$getOwnPropertySymbols = require("@babel/runtime-corejs2/core-js/object/get-own-property-symbols");
7
+ var _Object$getOwnPropertyDescriptor = require("@babel/runtime-corejs2/core-js/object/get-own-property-descriptor");
8
+ var _Object$getOwnPropertyDescriptors = require("@babel/runtime-corejs2/core-js/object/get-own-property-descriptors");
9
+ var _Object$defineProperties = require("@babel/runtime-corejs2/core-js/object/define-properties");
10
+ var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
11
+ var _WeakMap2 = require("@babel/runtime-corejs2/core-js/weak-map");
12
+ var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
13
+ _Object$defineProperty(exports, "__esModule", {
14
+ value: true
15
+ });
16
+ exports.CallQueueClient = void 0;
17
+ exports.createCallQueueClient = createCallQueueClient;
18
+ var _regenerator = _interopRequireDefault(require("@babel/runtime-corejs2/regenerator"));
19
+ var _map = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/map"));
20
+ var _isArray = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/array/is-array"));
21
+ var _weakMap = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/weak-map"));
22
+ var _typeof2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/typeof"));
23
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/toConsumableArray"));
24
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/slicedToArray"));
25
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/asyncToGenerator"));
26
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/classCallCheck"));
27
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/createClass"));
28
+ var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/possibleConstructorReturn"));
29
+ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/getPrototypeOf"));
30
+ var _inherits2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/inherits"));
31
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs2/helpers/defineProperty"));
32
+ var _SDKConnector = _interopRequireDefault(require("../SDKConnector"));
33
+ var _types = require("../common/types");
34
+ var _Logger = _interopRequireDefault(require("../Logger"));
35
+ var _Utils = require("../common/Utils");
36
+ var _constants = require("../common/constants");
37
+ var _impl = require("../Events/impl");
38
+ var _types2 = require("../Events/types");
39
+ var _constants2 = require("./constants");
40
+ var _utils = _interopRequireWildcard(require("./utils"));
41
+ function _interopRequireWildcard(e, t) { if ("function" == typeof _WeakMap2) var r = new _WeakMap2(), n = new _WeakMap2(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof3(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t9 in e) "default" !== _t9 && {}.hasOwnProperty.call(e, _t9) && ((i = (o = _Object$defineProperty) && _Object$getOwnPropertyDescriptor(e, _t9)) && (i.get || i.set) ? o(f, _t9, i) : f[_t9] = e[_t9]); return f; })(e, t); }
42
+ function ownKeys(e, r) { var t = _Object$keys(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
43
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
44
+ function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2.default)(o), (0, _possibleConstructorReturn2.default)(t, _isNativeReflectConstruct() ? _Reflect$construct(o, e || [], (0, _getPrototypeOf2.default)(t).constructor) : o.apply(t, e)); }
45
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(_Reflect$construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
46
+ /**
47
+ * Webex Calling cloud client for call-queue agent status.
48
+ *
49
+ * Reads and updates `GET/PUT /v1/telephony/config/people/me/settings/queues`,
50
+ * asks CXAPI to sync with `POST /v1/telephony/calls/sync/invoke`, and keeps the
51
+ * local status current from Mercury `telephony_agents` events.
52
+ *
53
+ * @example
54
+ * ```javascript
55
+ * const callQueue = createCallQueueClient(webex, logger, {
56
+ * webexApiBaseUrl: 'https://webexapis.com',
57
+ * });
58
+ * const status = await callQueue.getCallQueueSettings();
59
+ * ```
60
+ */
61
+ var CallQueueClient = exports.CallQueueClient = /*#__PURE__*/function (_Eventing) {
62
+ function CallQueueClient(webex, logger, options) {
63
+ var _this;
64
+ (0, _classCallCheck2.default)(this, CallQueueClient);
65
+ _this = _callSuper(this, CallQueueClient);
66
+ (0, _defineProperty2.default)(_this, "webex", void 0);
67
+ (0, _defineProperty2.default)(_this, "callingBackend", void 0);
68
+ (0, _defineProperty2.default)(_this, "webexApiEndpoint", void 0);
69
+ (0, _defineProperty2.default)(_this, "currentByLine", new _map.default());
70
+ (0, _defineProperty2.default)(_this, "queueNames", new _map.default());
71
+ (0, _defineProperty2.default)(_this, "eventGeneration", new _map.default());
72
+ (0, _defineProperty2.default)(_this, "requestSequence", 0);
73
+ (0, _defineProperty2.default)(_this, "committedSequence", new _map.default());
74
+ (0, _defineProperty2.default)(_this, "pendingEventRefresh", new _map.default());
75
+ (0, _defineProperty2.default)(_this, "mercuryListeners", []);
76
+ (0, _defineProperty2.default)(_this, "disposed", false);
77
+ (0, _defineProperty2.default)(_this, "lifecycleEpoch", 0);
78
+ if (!_SDKConnector.default.getWebex()) {
79
+ _SDKConnector.default.setWebex(webex);
80
+ }
81
+ if (_SDKConnector.default.getWebex() !== webex) {
82
+ throw new Error('Call queue Webex instance must match the SDKConnector instance');
83
+ }
84
+ _this.webex = _SDKConnector.default.getWebex();
85
+ var apiBaseUrl = options === null || options === void 0 ? void 0 : options.webexApiBaseUrl;
86
+ var allowedOrigins = [_constants.WEBEX_API_BTS, _constants.WEBEX_API_PROD, _constants.WEBEX_API_FEDRAMP];
87
+ var normalized = typeof apiBaseUrl === 'string' ? apiBaseUrl.replace(/\/$/, '') : '';
88
+ _this.webexApiEndpoint = allowedOrigins.includes(normalized) ? "".concat(normalized, "/v1") : undefined;
89
+ _this.callingBackend = (0, _utils.hasReadyEntitlementModels)(_this.webex) ? (0, _Utils.getCallingBackEnd)(_this.webex) : _types.CALLING_BACKEND.INVALID;
90
+ _Logger.default.setLogger(logger.level, _constants2.CALL_QUEUE_FILE);
91
+ _this.registerAgentListeners();
92
+ return _this;
93
+ }
94
+
95
+ /**
96
+ * Reads the signed-in agent's ACD state and queue join list.
97
+ * Pass `lineOwnerId` to read a secondary line.
98
+ * Queue display names are filled from the queue catalog when settings omit them.
99
+ *
100
+ * @param lineOwnerId - Optional secondary line owner ID; omit for the primary line.
101
+ * @returns The current call queue settings or an error response.
102
+ * @example
103
+ * ```js
104
+ * const result = await callQueue.getCallQueueSettings();
105
+ * ```
106
+ * @public
107
+ */
108
+ (0, _inherits2.default)(CallQueueClient, _Eventing);
109
+ return (0, _createClass2.default)(CallQueueClient, [{
110
+ key: "getCallQueueSettings",
111
+ value: (function () {
112
+ var _getCallQueueSettings = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee(lineOwnerId) {
113
+ var _this$eventGeneration;
114
+ var loggerContext, rejected, epoch, generation, sequence, _response$headers, _this$eventGeneration2, _this$committedSequen, response, parsed, named, latest, failure, _t, _t2;
115
+ return _regenerator.default.wrap(function (_context) {
116
+ while (1) switch (_context.prev = _context.next) {
117
+ case 0:
118
+ loggerContext = {
119
+ file: _constants2.CALL_QUEUE_FILE,
120
+ method: _constants2.METHODS.GET_CALL_QUEUE_SETTINGS
121
+ };
122
+ _Logger.default.info(_constants.METHOD_START_MESSAGE, loggerContext);
123
+ rejected = this.rejectBeforeRequest(lineOwnerId);
124
+ if (!rejected) {
125
+ _context.next = 1;
126
+ break;
127
+ }
128
+ return _context.abrupt("return", rejected);
129
+ case 1:
130
+ epoch = this.lifecycleEpoch;
131
+ generation = (_this$eventGeneration = this.eventGeneration.get(lineOwnerId)) !== null && _this$eventGeneration !== void 0 ? _this$eventGeneration : 0;
132
+ this.requestSequence += 1;
133
+ sequence = this.requestSequence;
134
+ _context.prev = 2;
135
+ _context.next = 3;
136
+ return this.webex.request({
137
+ uri: this.queuesUrl(lineOwnerId),
138
+ method: _types.HTTP_METHODS.GET
139
+ });
140
+ case 3:
141
+ response = _context.sent;
142
+ if (!(epoch !== this.lifecycleEpoch)) {
143
+ _context.next = 4;
144
+ break;
145
+ }
146
+ return _context.abrupt("return", (0, _utils.lifecycleConflictResponse)());
147
+ case 4:
148
+ _Logger.default.log("Response trackingId: ".concat(response === null || response === void 0 ? void 0 : (_response$headers = response.headers) === null || _response$headers === void 0 ? void 0 : _response$headers.trackingid), loggerContext);
149
+ parsed = (0, _utils.parseCallQueueSettings)(response.body, this.currentByLine.get(lineOwnerId));
150
+ if (!parsed) {
151
+ _context.next = 6;
152
+ break;
153
+ }
154
+ _context.next = 5;
155
+ return this.fillQueueNames(parsed);
156
+ case 5:
157
+ _t = _context.sent;
158
+ _context.next = 7;
159
+ break;
160
+ case 6:
161
+ _t = undefined;
162
+ case 7:
163
+ named = _t;
164
+ if (!(epoch !== this.lifecycleEpoch)) {
165
+ _context.next = 8;
166
+ break;
167
+ }
168
+ return _context.abrupt("return", (0, _utils.lifecycleConflictResponse)());
169
+ case 8:
170
+ if (!(((_this$eventGeneration2 = this.eventGeneration.get(lineOwnerId)) !== null && _this$eventGeneration2 !== void 0 ? _this$eventGeneration2 : 0) !== generation || ((_this$committedSequen = this.committedSequence.get(lineOwnerId)) !== null && _this$committedSequen !== void 0 ? _this$committedSequen : 0) > sequence)) {
171
+ _context.next = 11;
172
+ break;
173
+ }
174
+ _context.next = 9;
175
+ return this.waitForEventRefreshes(lineOwnerId);
176
+ case 9:
177
+ if (!(epoch !== this.lifecycleEpoch)) {
178
+ _context.next = 10;
179
+ break;
180
+ }
181
+ return _context.abrupt("return", (0, _utils.lifecycleConflictResponse)());
182
+ case 10:
183
+ latest = this.currentByLine.get(lineOwnerId);
184
+ return _context.abrupt("return", latest ? {
185
+ statusCode: Number(response[_constants.STATUS_CODE]) || 200,
186
+ data: {
187
+ callQueue: latest
188
+ },
189
+ message: _constants.SUCCESS_MESSAGE
190
+ } : {
191
+ statusCode: 409,
192
+ data: {
193
+ error: 'Call queue settings changed while loading; retry the request'
194
+ },
195
+ message: _constants.FAILURE_MESSAGE
196
+ });
197
+ case 11:
198
+ if (named) {
199
+ _context.next = 12;
200
+ break;
201
+ }
202
+ return _context.abrupt("return", {
203
+ statusCode: 502,
204
+ data: {
205
+ error: 'Call queue settings response was invalid or did not include agent status'
206
+ },
207
+ message: _constants.FAILURE_MESSAGE
208
+ });
209
+ case 12:
210
+ this.currentByLine.set(lineOwnerId, named);
211
+ this.committedSequence.set(lineOwnerId, sequence);
212
+ _Logger.default.log("Call queue settings loaded, state=".concat(named.acdState, ", queues=").concat(named.queues.length), loggerContext);
213
+ return _context.abrupt("return", {
214
+ statusCode: Number(response[_constants.STATUS_CODE]) || 200,
215
+ data: {
216
+ callQueue: named
217
+ },
218
+ message: _constants.SUCCESS_MESSAGE
219
+ });
220
+ case 13:
221
+ _context.prev = 13;
222
+ _t2 = _context["catch"](2);
223
+ _context.next = 14;
224
+ return this.fail(_t2, loggerContext, 'Failed to get call queue settings', epoch);
225
+ case 14:
226
+ failure = _context.sent;
227
+ if (!(failure && epoch === this.lifecycleEpoch)) {
228
+ _context.next = 15;
229
+ break;
230
+ }
231
+ return _context.abrupt("return", failure);
232
+ case 15:
233
+ return _context.abrupt("return", (0, _utils.lifecycleConflictResponse)());
234
+ case 16:
235
+ case "end":
236
+ return _context.stop();
237
+ }
238
+ }, _callee, this, [[2, 13]]);
239
+ }));
240
+ function getCallQueueSettings(_x) {
241
+ return _getCallQueueSettings.apply(this, arguments);
242
+ }
243
+ return getCallQueueSettings;
244
+ }()
245
+ /**
246
+ * Sets ACD state, queue join, or both.
247
+ * A queue with `allowLogOffEnabled: false` stays joined.
248
+ *
249
+ * @param request - The agent state and/or queue membership updates.
250
+ * @param lineOwnerId - Optional secondary line owner ID; omit for the primary line.
251
+ * @returns The updated call queue settings or an error response.
252
+ * @example
253
+ * ```js
254
+ * await callQueue.updateCallQueueSettings({agentACDState: 'AVAILABLE'});
255
+ * ```
256
+ * @public
257
+ */
258
+ )
259
+ }, {
260
+ key: "updateCallQueueSettings",
261
+ value: (function () {
262
+ var _updateCallQueueSettings = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee2(request, lineOwnerId) {
263
+ var _this$rejectBeforeReq;
264
+ var loggerContext, rejected, epoch, requestSent, _this$eventGeneration3, _response$headers2, _this$eventGeneration4, _this$committedSequen2, settings, body, generation, sequence, response, current, parsed, local, named, refreshed, failure, _t3, _t4;
265
+ return _regenerator.default.wrap(function (_context2) {
266
+ while (1) switch (_context2.prev = _context2.next) {
267
+ case 0:
268
+ loggerContext = {
269
+ file: _constants2.CALL_QUEUE_FILE,
270
+ method: _constants2.METHODS.UPDATE_CALL_QUEUE_SETTINGS
271
+ };
272
+ _Logger.default.info(_constants.METHOD_START_MESSAGE, loggerContext);
273
+ rejected = (_this$rejectBeforeReq = this.rejectBeforeRequest(lineOwnerId)) !== null && _this$rejectBeforeReq !== void 0 ? _this$rejectBeforeReq : this.rejectUpdate(request);
274
+ if (!rejected) {
275
+ _context2.next = 1;
276
+ break;
277
+ }
278
+ return _context2.abrupt("return", rejected);
279
+ case 1:
280
+ epoch = this.lifecycleEpoch;
281
+ requestSent = false;
282
+ _context2.prev = 2;
283
+ if (!this.needsQueuePolicyRefresh(request, lineOwnerId)) {
284
+ _context2.next = 6;
285
+ break;
286
+ }
287
+ _context2.next = 3;
288
+ return this.getCallQueueSettings(lineOwnerId);
289
+ case 3:
290
+ settings = _context2.sent;
291
+ if (!(epoch !== this.lifecycleEpoch)) {
292
+ _context2.next = 4;
293
+ break;
294
+ }
295
+ return _context2.abrupt("return", (0, _utils.lifecycleConflictResponse)());
296
+ case 4:
297
+ if (!(settings.statusCode >= 400)) {
298
+ _context2.next = 5;
299
+ break;
300
+ }
301
+ return _context2.abrupt("return", settings);
302
+ case 5:
303
+ if (settings.data.callQueue) {
304
+ _context2.next = 6;
305
+ break;
306
+ }
307
+ return _context2.abrupt("return", {
308
+ statusCode: 400,
309
+ data: {
310
+ error: 'Call queue settings are required before updating queue membership'
311
+ },
312
+ message: _constants.FAILURE_MESSAGE
313
+ });
314
+ case 6:
315
+ body = this.buildUpdateBody(request, lineOwnerId);
316
+ generation = (_this$eventGeneration3 = this.eventGeneration.get(lineOwnerId)) !== null && _this$eventGeneration3 !== void 0 ? _this$eventGeneration3 : 0;
317
+ this.requestSequence += 1;
318
+ sequence = this.requestSequence;
319
+ requestSent = true;
320
+ _context2.next = 7;
321
+ return this.webex.request({
322
+ uri: this.queuesUrl(lineOwnerId),
323
+ method: _types.HTTP_METHODS.PUT,
324
+ body: body
325
+ });
326
+ case 7:
327
+ response = _context2.sent;
328
+ if (!(epoch !== this.lifecycleEpoch)) {
329
+ _context2.next = 8;
330
+ break;
331
+ }
332
+ return _context2.abrupt("return", (0, _utils.lifecycleConflictResponse)(true));
333
+ case 8:
334
+ _Logger.default.log("Response trackingId: ".concat(response === null || response === void 0 ? void 0 : (_response$headers2 = response.headers) === null || _response$headers2 === void 0 ? void 0 : _response$headers2.trackingid), loggerContext);
335
+ current = this.currentByLine.get(lineOwnerId);
336
+ parsed = (0, _utils.parseCallQueueSettings)(response.body, current);
337
+ local = parsed !== null && parsed !== void 0 ? parsed : current && !(0, _utils.hasMalformedQueueRecords)(response.body) ? this.applyLocalUpdate(request, lineOwnerId) : undefined;
338
+ if (!local) {
339
+ _context2.next = 10;
340
+ break;
341
+ }
342
+ _context2.next = 9;
343
+ return this.fillQueueNames(local);
344
+ case 9:
345
+ _t3 = _context2.sent;
346
+ _context2.next = 11;
347
+ break;
348
+ case 10:
349
+ _t3 = undefined;
350
+ case 11:
351
+ named = _t3;
352
+ if (!(epoch !== this.lifecycleEpoch)) {
353
+ _context2.next = 12;
354
+ break;
355
+ }
356
+ return _context2.abrupt("return", (0, _utils.lifecycleConflictResponse)(true));
357
+ case 12:
358
+ if (!(!named || ((_this$eventGeneration4 = this.eventGeneration.get(lineOwnerId)) !== null && _this$eventGeneration4 !== void 0 ? _this$eventGeneration4 : 0) !== generation || ((_this$committedSequen2 = this.committedSequence.get(lineOwnerId)) !== null && _this$committedSequen2 !== void 0 ? _this$committedSequen2 : 0) > sequence)) {
359
+ _context2.next = 15;
360
+ break;
361
+ }
362
+ _context2.next = 13;
363
+ return this.getCallQueueSettings(lineOwnerId);
364
+ case 13:
365
+ refreshed = _context2.sent;
366
+ if (!(epoch !== this.lifecycleEpoch)) {
367
+ _context2.next = 14;
368
+ break;
369
+ }
370
+ return _context2.abrupt("return", (0, _utils.lifecycleConflictResponse)(true));
371
+ case 14:
372
+ return _context2.abrupt("return", refreshed.data.callQueue ? {
373
+ statusCode: Number(response[_constants.STATUS_CODE]) || 200,
374
+ data: {
375
+ callQueue: refreshed.data.callQueue
376
+ },
377
+ message: _constants.SUCCESS_MESSAGE
378
+ } : refreshed);
379
+ case 15:
380
+ this.currentByLine.set(lineOwnerId, named);
381
+ this.committedSequence.set(lineOwnerId, sequence);
382
+ _Logger.default.log("Call queue settings updated, state=".concat(named.acdState, ", queues=").concat(named.queues.length), loggerContext);
383
+ return _context2.abrupt("return", {
384
+ statusCode: Number(response[_constants.STATUS_CODE]) || 200,
385
+ data: {
386
+ callQueue: named
387
+ },
388
+ message: _constants.SUCCESS_MESSAGE
389
+ });
390
+ case 16:
391
+ _context2.prev = 16;
392
+ _t4 = _context2["catch"](2);
393
+ _context2.next = 17;
394
+ return this.fail(_t4, loggerContext, 'Failed to update call queue settings', epoch);
395
+ case 17:
396
+ failure = _context2.sent;
397
+ if (!(failure && epoch === this.lifecycleEpoch)) {
398
+ _context2.next = 18;
399
+ break;
400
+ }
401
+ return _context2.abrupt("return", failure);
402
+ case 18:
403
+ return _context2.abrupt("return", (0, _utils.lifecycleConflictResponse)(requestSent));
404
+ case 19:
405
+ case "end":
406
+ return _context2.stop();
407
+ }
408
+ }, _callee2, this, [[2, 16]]);
409
+ }));
410
+ function updateCallQueueSettings(_x2, _x3) {
411
+ return _updateCallQueueSettings.apply(this, arguments);
412
+ }
413
+ return updateCallQueueSettings;
414
+ }()
415
+ /**
416
+ * Asks the calling service to publish the current agent state on Mercury.
417
+ * Sends the registered WDM device URL. The queue list arrives on `telephony_agents.sync`.
418
+ *
419
+ * @returns The sync request result or an error response.
420
+ * @example
421
+ * ```js
422
+ * await callQueue.syncTelephonyCalls();
423
+ * ```
424
+ * @public
425
+ */
426
+ )
427
+ }, {
428
+ key: "syncTelephonyCalls",
429
+ value: (function () {
430
+ var _syncTelephonyCalls = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee3() {
431
+ var _this$webex$internal$;
432
+ var loggerContext, rejected, wdmUrl, epoch, _response$headers3, response, current, failure, _t5;
433
+ return _regenerator.default.wrap(function (_context3) {
434
+ while (1) switch (_context3.prev = _context3.next) {
435
+ case 0:
436
+ loggerContext = {
437
+ file: _constants2.CALL_QUEUE_FILE,
438
+ method: _constants2.METHODS.SYNC_TELEPHONY_CALLS
439
+ };
440
+ _Logger.default.info(_constants.METHOD_START_MESSAGE, loggerContext);
441
+ rejected = this.rejectBeforeRequest();
442
+ if (!rejected) {
443
+ _context3.next = 1;
444
+ break;
445
+ }
446
+ return _context3.abrupt("return", rejected);
447
+ case 1:
448
+ wdmUrl = (_this$webex$internal$ = this.webex.internal.device) === null || _this$webex$internal$ === void 0 ? void 0 : _this$webex$internal$.url;
449
+ if (!(!wdmUrl || !this.wdmDeviceId())) {
450
+ _context3.next = 2;
451
+ break;
452
+ }
453
+ return _context3.abrupt("return", {
454
+ statusCode: 400,
455
+ data: {
456
+ error: 'A registered device is required to sync telephony calls'
457
+ },
458
+ message: _constants.FAILURE_MESSAGE
459
+ });
460
+ case 2:
461
+ epoch = this.lifecycleEpoch;
462
+ _context3.prev = 3;
463
+ _context3.next = 4;
464
+ return this.webex.request({
465
+ uri: this.joinUrl(_constants2.SYNC_PATH),
466
+ method: _types.HTTP_METHODS.POST,
467
+ body: {
468
+ wdmUrl: wdmUrl,
469
+ resources: [{
470
+ resource: 'telephony_agents'
471
+ }]
472
+ }
473
+ });
474
+ case 4:
475
+ response = _context3.sent;
476
+ if (!(epoch !== this.lifecycleEpoch)) {
477
+ _context3.next = 5;
478
+ break;
479
+ }
480
+ return _context3.abrupt("return", (0, _utils.lifecycleConflictResponse)());
481
+ case 5:
482
+ _Logger.default.log("Response trackingId: ".concat(response === null || response === void 0 ? void 0 : (_response$headers3 = response.headers) === null || _response$headers3 === void 0 ? void 0 : _response$headers3.trackingid), loggerContext);
483
+ // The sync endpoint returns 204; authoritative settings arrive via Mercury.
484
+ current = this.currentByLine.get(undefined);
485
+ return _context3.abrupt("return", {
486
+ statusCode: Number(response[_constants.STATUS_CODE]) || 200,
487
+ data: current ? {
488
+ callQueue: current
489
+ } : {},
490
+ message: _constants.SUCCESS_MESSAGE
491
+ });
492
+ case 6:
493
+ _context3.prev = 6;
494
+ _t5 = _context3["catch"](3);
495
+ _context3.next = 7;
496
+ return this.fail(_t5, loggerContext, 'Failed to sync telephony calls', epoch);
497
+ case 7:
498
+ failure = _context3.sent;
499
+ if (!(failure && epoch === this.lifecycleEpoch)) {
500
+ _context3.next = 8;
501
+ break;
502
+ }
503
+ return _context3.abrupt("return", failure);
504
+ case 8:
505
+ return _context3.abrupt("return", (0, _utils.lifecycleConflictResponse)());
506
+ case 9:
507
+ case "end":
508
+ return _context3.stop();
509
+ }
510
+ }, _callee3, this, [[3, 6]]);
511
+ }));
512
+ function syncTelephonyCalls() {
513
+ return _syncTelephonyCalls.apply(this, arguments);
514
+ }
515
+ return syncTelephonyCalls;
516
+ }())
517
+ }, {
518
+ key: "registerAgentListeners",
519
+ value: function registerAgentListeners() {
520
+ var _this2 = this;
521
+ if (this.callingBackend !== _types.CALLING_BACKEND.WXC) {
522
+ return;
523
+ }
524
+ var events = [[_constants2.CALL_QUEUE_MERCURY_EVENT_KEYS.TELEPHONY_AGENT_SYNC, 'sync'], [_constants2.CALL_QUEUE_MERCURY_EVENT_KEYS.TELEPHONY_AGENT_STATE, 'state'], [_constants2.CALL_QUEUE_MERCURY_EVENT_KEYS.TELEPHONY_AGENT_JOIN, 'join'], [_constants2.CALL_QUEUE_MERCURY_EVENT_KEYS.TELEPHONY_AGENT_SYNC_SINGULAR, 'sync'], [_constants2.CALL_QUEUE_MERCURY_EVENT_KEYS.TELEPHONY_AGENT_STATE_SINGULAR, 'state'], [_constants2.CALL_QUEUE_MERCURY_EVENT_KEYS.TELEPHONY_AGENT_JOIN_SINGULAR, 'join']];
525
+ var startingCount = this.mercuryListeners.length;
526
+ try {
527
+ events.forEach(function (_ref) {
528
+ var _ref2 = (0, _slicedToArray2.default)(_ref, 2),
529
+ event = _ref2[0],
530
+ kind = _ref2[1];
531
+ var listener = function listener(data) {
532
+ return _this2.handleAgentEvent(kind, data);
533
+ };
534
+ _this2.mercuryListeners.push({
535
+ event: event,
536
+ listener: listener
537
+ });
538
+ _this2.webex.internal.mercury.on(event, listener);
539
+ });
540
+ } catch (error) {
541
+ var added = this.mercuryListeners.splice(startingCount);
542
+ added.forEach(function (_ref3) {
543
+ var event = _ref3.event,
544
+ listener = _ref3.listener;
545
+ try {
546
+ _this2.webex.internal.mercury.off(event, listener);
547
+ } catch (_unused) {
548
+ _this2.mercuryListeners.push({
549
+ event: event,
550
+ listener: listener
551
+ });
552
+ _Logger.default.warn('Failed to remove call queue Mercury listener after registration failed', {
553
+ file: _constants2.CALL_QUEUE_FILE,
554
+ method: 'registerAgentListeners'
555
+ });
556
+ }
557
+ });
558
+ throw error;
559
+ }
560
+ }
561
+
562
+ /**
563
+ * Refresh backend readiness before reusing this client without issuing a request.
564
+ *
565
+ * @returns False if the client is disposed or its registered backend changed.
566
+ * @example
567
+ * ```js
568
+ * const reusable = callQueue.prepareForReuse();
569
+ * ```
570
+ * @public
571
+ */
572
+ }, {
573
+ key: "prepareForReuse",
574
+ value: function prepareForReuse() {
575
+ if (this.disposed) return false;
576
+ var backend = (0, _utils.hasReadyEntitlementModels)(this.webex) ? (0, _Utils.getCallingBackEnd)(this.webex) : _types.CALLING_BACKEND.INVALID;
577
+ if (this.mercuryListeners.length && backend !== _types.CALLING_BACKEND.WXC) return false;
578
+ this.lifecycleEpoch += 1;
579
+ this.currentByLine.clear();
580
+ this.queueNames.clear();
581
+ this.eventGeneration.clear();
582
+ this.committedSequence.clear();
583
+ this.pendingEventRefresh.clear();
584
+ this.callingBackend = backend;
585
+ if (backend === _types.CALLING_BACKEND.WXC && !this.mercuryListeners.length) {
586
+ this.registerAgentListeners();
587
+ }
588
+ return true;
589
+ }
590
+
591
+ /**
592
+ * Unsubscribe this client from queue Mercury events and clear its local state.
593
+ *
594
+ * @returns Nothing.
595
+ * @example
596
+ * ```js
597
+ * callQueue.dispose();
598
+ * ```
599
+ * @public
600
+ */
601
+ }, {
602
+ key: "dispose",
603
+ value: function dispose() {
604
+ var _this3 = this;
605
+ this.disposed = true;
606
+ this.lifecycleEpoch += 1;
607
+ this.mercuryListeners.forEach(function (_ref4) {
608
+ var event = _ref4.event,
609
+ listener = _ref4.listener;
610
+ _this3.webex.internal.mercury.off(event, listener);
611
+ });
612
+ this.mercuryListeners = [];
613
+ this.currentByLine.clear();
614
+ this.queueNames.clear();
615
+ this.eventGeneration.clear();
616
+ this.committedSequence.clear();
617
+ this.pendingEventRefresh.clear();
618
+ this.removeAllListeners();
619
+ }
620
+ }, {
621
+ key: "eventLine",
622
+ value: function eventLine(event) {
623
+ var _payload$actorType, _payload$actorId, _this$webex$internal$2;
624
+ var payload = (0, _utils.unwrapAgentPayload)(event);
625
+ if ((payload === null || payload === void 0 ? void 0 : payload.actorType) !== undefined && typeof payload.actorType !== 'string') {
626
+ return {
627
+ kind: 'ignore'
628
+ };
629
+ }
630
+ var type = payload === null || payload === void 0 ? void 0 : (_payload$actorType = payload.actorType) === null || _payload$actorType === void 0 ? void 0 : _payload$actorType.toUpperCase();
631
+ var actorId = (_payload$actorId = payload === null || payload === void 0 ? void 0 : payload.actorId) !== null && _payload$actorId !== void 0 ? _payload$actorId : type === 'VIRTUAL_LINE' ? undefined : payload === null || payload === void 0 ? void 0 : payload.actorPersonId;
632
+ if (!actorId) {
633
+ return type ? {
634
+ kind: 'ignore'
635
+ } : {
636
+ kind: 'primary'
637
+ };
638
+ }
639
+ if (typeof actorId !== 'string') return {
640
+ kind: 'ignore'
641
+ };
642
+ var actor = (0, _utils.default)(actorId);
643
+ var actorType = type !== null && type !== void 0 ? type : actor.type;
644
+ var primaryId = (_this$webex$internal$2 = this.webex.internal.device) === null || _this$webex$internal$2 === void 0 ? void 0 : _this$webex$internal$2.userId;
645
+ if (actorType === 'PERSON' || actorType === 'PEOPLE') {
646
+ return primaryId && actor.id === (0, _utils.default)(primaryId).id ? {
647
+ kind: 'primary'
648
+ } : {
649
+ kind: 'ignore'
650
+ };
651
+ }
652
+ if (actorType && actorType !== 'VIRTUAL_LINE') return {
653
+ kind: 'ignore'
654
+ };
655
+ var cachedLine = (0, _toConsumableArray2.default)(this.currentByLine.keys()).find(function (id) {
656
+ return id !== undefined && (0, _utils.default)(id).id === actor.id;
657
+ });
658
+ if (actorType === 'VIRTUAL_LINE') {
659
+ var lineOwnerId = cachedLine !== null && cachedLine !== void 0 ? cachedLine : actor.id;
660
+ return _constants2.LINE_OWNER_ID_PATTERN.test(lineOwnerId) ? {
661
+ kind: 'secondary',
662
+ lineOwnerId: lineOwnerId
663
+ } : {
664
+ kind: 'ignore'
665
+ };
666
+ }
667
+ if (primaryId && actor.id === (0, _utils.default)(primaryId).id) return {
668
+ kind: 'primary'
669
+ };
670
+ return cachedLine ? {
671
+ kind: 'secondary',
672
+ lineOwnerId: cachedLine
673
+ } : {
674
+ kind: 'ignore'
675
+ };
676
+ }
677
+ }, {
678
+ key: "handleAgentEvent",
679
+ value: function handleAgentEvent(kind, event) {
680
+ var _this$eventGeneration5,
681
+ _this4 = this;
682
+ if (this.disposed) return;
683
+ var epoch = this.lifecycleEpoch;
684
+ var line = this.eventLine(event);
685
+ if (line.kind === 'ignore') return;
686
+ var lineOwnerId = line.kind === 'secondary' ? line.lineOwnerId : undefined;
687
+ var current = this.currentByLine.get(lineOwnerId);
688
+ var next = (0, _utils.applyCallQueueEvent)(current, kind, event);
689
+ if (!next || current && next === current) return;
690
+ var generation = ((_this$eventGeneration5 = this.eventGeneration.get(lineOwnerId)) !== null && _this$eventGeneration5 !== void 0 ? _this$eventGeneration5 : 0) + 1;
691
+ this.eventGeneration.set(lineOwnerId, generation);
692
+ if (!current) {
693
+ var pending = this.refreshEventLine(lineOwnerId, generation);
694
+ if (epoch !== this.lifecycleEpoch) return;
695
+ this.pendingEventRefresh.set(lineOwnerId, pending);
696
+ pending.then(function () {
697
+ if (_this4.pendingEventRefresh.get(lineOwnerId) === pending) {
698
+ _this4.pendingEventRefresh.delete(lineOwnerId);
699
+ }
700
+ });
701
+ return;
702
+ }
703
+ if (next.acdState === current.acdState && next.queues === current.queues) {
704
+ return;
705
+ }
706
+ var named = (0, _utils.applyQueueNames)(next, this.queueNames);
707
+ this.currentByLine.set(lineOwnerId, named);
708
+ _Logger.default.log("Call queue ".concat(kind, " event applied, state=").concat(named.acdState, ", queues=").concat(named.queues.length), {
709
+ file: _constants2.CALL_QUEUE_FILE,
710
+ method: 'handleAgentEvent'
711
+ });
712
+ this.emit(_types2.COMMON_EVENT_KEYS.CALL_QUEUE_UPDATED, lineOwnerId ? _objectSpread(_objectSpread({}, named), {}, {
713
+ lineOwnerId: lineOwnerId
714
+ }) : named);
715
+ if (epoch !== this.lifecycleEpoch) return;
716
+ if (named.queues.some(function (queue) {
717
+ return !queue.name;
718
+ })) {
719
+ this.refreshQueueNames(named, generation, lineOwnerId).catch(function (err) {
720
+ _Logger.default.error("Failed to refresh call queue names: ".concat(String(err)), {
721
+ file: _constants2.CALL_QUEUE_FILE,
722
+ method: 'refreshQueueNames'
723
+ });
724
+ });
725
+ }
726
+ }
727
+ }, {
728
+ key: "waitForEventRefreshes",
729
+ value: function () {
730
+ var _waitForEventRefreshes = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee4(lineOwnerId) {
731
+ var pending, next;
732
+ return _regenerator.default.wrap(function (_context4) {
733
+ while (1) switch (_context4.prev = _context4.next) {
734
+ case 0:
735
+ pending = this.pendingEventRefresh.get(lineOwnerId);
736
+ case 1:
737
+ if (!pending) {
738
+ _context4.next = 4;
739
+ break;
740
+ }
741
+ _context4.next = 2;
742
+ return pending;
743
+ case 2:
744
+ next = this.pendingEventRefresh.get(lineOwnerId);
745
+ if (!(next === pending)) {
746
+ _context4.next = 3;
747
+ break;
748
+ }
749
+ return _context4.abrupt("return");
750
+ case 3:
751
+ pending = next;
752
+ _context4.next = 1;
753
+ break;
754
+ case 4:
755
+ case "end":
756
+ return _context4.stop();
757
+ }
758
+ }, _callee4, this);
759
+ }));
760
+ function waitForEventRefreshes(_x4) {
761
+ return _waitForEventRefreshes.apply(this, arguments);
762
+ }
763
+ return waitForEventRefreshes;
764
+ }()
765
+ }, {
766
+ key: "refreshEventLine",
767
+ value: function () {
768
+ var _refreshEventLine = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee5(lineOwnerId, generation) {
769
+ var epoch, sequence, _this$committedSequen3, response, parsed, named, _t6;
770
+ return _regenerator.default.wrap(function (_context5) {
771
+ while (1) switch (_context5.prev = _context5.next) {
772
+ case 0:
773
+ if (!this.rejectBeforeRequest(lineOwnerId)) {
774
+ _context5.next = 1;
775
+ break;
776
+ }
777
+ return _context5.abrupt("return");
778
+ case 1:
779
+ epoch = this.lifecycleEpoch;
780
+ this.requestSequence += 1;
781
+ sequence = this.requestSequence;
782
+ _context5.prev = 2;
783
+ _context5.next = 3;
784
+ return this.webex.request({
785
+ uri: this.queuesUrl(lineOwnerId),
786
+ method: _types.HTTP_METHODS.GET
787
+ });
788
+ case 3:
789
+ response = _context5.sent;
790
+ if (!(epoch !== this.lifecycleEpoch)) {
791
+ _context5.next = 4;
792
+ break;
793
+ }
794
+ return _context5.abrupt("return");
795
+ case 4:
796
+ parsed = (0, _utils.parseCallQueueSettings)(response.body, this.currentByLine.get(lineOwnerId));
797
+ if (parsed) {
798
+ _context5.next = 5;
799
+ break;
800
+ }
801
+ return _context5.abrupt("return");
802
+ case 5:
803
+ _context5.next = 6;
804
+ return this.fillQueueNames(parsed);
805
+ case 6:
806
+ named = _context5.sent;
807
+ if (!(epoch !== this.lifecycleEpoch || generation !== this.eventGeneration.get(lineOwnerId) || ((_this$committedSequen3 = this.committedSequence.get(lineOwnerId)) !== null && _this$committedSequen3 !== void 0 ? _this$committedSequen3 : 0) > sequence)) {
808
+ _context5.next = 7;
809
+ break;
810
+ }
811
+ return _context5.abrupt("return");
812
+ case 7:
813
+ this.currentByLine.set(lineOwnerId, named);
814
+ this.committedSequence.set(lineOwnerId, sequence);
815
+ this.emit(_types2.COMMON_EVENT_KEYS.CALL_QUEUE_UPDATED, lineOwnerId ? _objectSpread(_objectSpread({}, named), {}, {
816
+ lineOwnerId: lineOwnerId
817
+ }) : named);
818
+ _context5.next = 9;
819
+ break;
820
+ case 8:
821
+ _context5.prev = 8;
822
+ _t6 = _context5["catch"](2);
823
+ _Logger.default.error('Failed to refresh call queue settings after an event', {
824
+ file: _constants2.CALL_QUEUE_FILE,
825
+ method: 'refreshEventLine'
826
+ });
827
+ case 9:
828
+ case "end":
829
+ return _context5.stop();
830
+ }
831
+ }, _callee5, this, [[2, 8]]);
832
+ }));
833
+ function refreshEventLine(_x5, _x6) {
834
+ return _refreshEventLine.apply(this, arguments);
835
+ }
836
+ return refreshEventLine;
837
+ }()
838
+ }, {
839
+ key: "refreshQueueNames",
840
+ value: function () {
841
+ var _refreshQueueNames = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee6(status, generation, lineOwnerId) {
842
+ var epoch, named;
843
+ return _regenerator.default.wrap(function (_context6) {
844
+ while (1) switch (_context6.prev = _context6.next) {
845
+ case 0:
846
+ epoch = this.lifecycleEpoch;
847
+ _context6.next = 1;
848
+ return this.fillQueueNames(status);
849
+ case 1:
850
+ named = _context6.sent;
851
+ if (!(epoch !== this.lifecycleEpoch || generation !== this.eventGeneration.get(lineOwnerId) || this.currentByLine.get(lineOwnerId) !== status || named === status)) {
852
+ _context6.next = 2;
853
+ break;
854
+ }
855
+ return _context6.abrupt("return");
856
+ case 2:
857
+ this.currentByLine.set(lineOwnerId, named);
858
+ this.emit(_types2.COMMON_EVENT_KEYS.CALL_QUEUE_UPDATED, lineOwnerId ? _objectSpread(_objectSpread({}, named), {}, {
859
+ lineOwnerId: lineOwnerId
860
+ }) : named);
861
+ case 3:
862
+ case "end":
863
+ return _context6.stop();
864
+ }
865
+ }, _callee6, this);
866
+ }));
867
+ function refreshQueueNames(_x7, _x8, _x9) {
868
+ return _refreshQueueNames.apply(this, arguments);
869
+ }
870
+ return refreshQueueNames;
871
+ }()
872
+ }, {
873
+ key: "fillQueueNames",
874
+ value: function () {
875
+ var _fillQueueNames = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee7(status) {
876
+ var _this5 = this;
877
+ var missingIds;
878
+ return _regenerator.default.wrap(function (_context7) {
879
+ while (1) switch (_context7.prev = _context7.next) {
880
+ case 0:
881
+ missingIds = status.queues.filter(function (queue) {
882
+ return !queue.name && !_this5.queueNames.has((0, _utils.queueIdKey)(queue.id));
883
+ }).map(function (queue) {
884
+ return (0, _utils.queueIdKey)(queue.id);
885
+ });
886
+ if (!(missingIds.length > 0)) {
887
+ _context7.next = 1;
888
+ break;
889
+ }
890
+ _context7.next = 1;
891
+ return this.loadQueueCatalog(missingIds);
892
+ case 1:
893
+ return _context7.abrupt("return", (0, _utils.applyQueueNames)(status, this.queueNames));
894
+ case 2:
895
+ case "end":
896
+ return _context7.stop();
897
+ }
898
+ }, _callee7, this);
899
+ }));
900
+ function fillQueueNames(_x0) {
901
+ return _fillQueueNames.apply(this, arguments);
902
+ }
903
+ return fillQueueNames;
904
+ }()
905
+ }, {
906
+ key: "loadQueueCatalog",
907
+ value: function () {
908
+ var _loadQueueCatalog = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee9(neededIds) {
909
+ var _this6 = this;
910
+ var loggerContext, epoch, _loadPage, statusCode, _t7;
911
+ return _regenerator.default.wrap(function (_context9) {
912
+ while (1) switch (_context9.prev = _context9.next) {
913
+ case 0:
914
+ loggerContext = {
915
+ file: _constants2.CALL_QUEUE_FILE,
916
+ method: _constants2.METHODS.GET_CALL_QUEUE_NAMES
917
+ };
918
+ epoch = this.lifecycleEpoch;
919
+ _loadPage = /*#__PURE__*/function () {
920
+ var _ref5 = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee8(uri, remainingPages) {
921
+ var _response$headers4, _response$headers5;
922
+ var response, catalog, link, headerNext, next;
923
+ return _regenerator.default.wrap(function (_context8) {
924
+ while (1) switch (_context8.prev = _context8.next) {
925
+ case 0:
926
+ if (!(epoch !== _this6.lifecycleEpoch || remainingPages === 0 || neededIds.every(function (id) {
927
+ return _this6.queueNames.has(id);
928
+ }))) {
929
+ _context8.next = 1;
930
+ break;
931
+ }
932
+ return _context8.abrupt("return");
933
+ case 1:
934
+ _context8.next = 2;
935
+ return _this6.webex.request({
936
+ uri: uri,
937
+ method: _types.HTTP_METHODS.GET
938
+ });
939
+ case 2:
940
+ response = _context8.sent;
941
+ if (!(epoch !== _this6.lifecycleEpoch)) {
942
+ _context8.next = 3;
943
+ break;
944
+ }
945
+ return _context8.abrupt("return");
946
+ case 3:
947
+ catalog = (0, _utils.parseCallQueueCatalog)(response.body);
948
+ catalog.entries.forEach(function (entry) {
949
+ if (entry.name) {
950
+ _this6.queueNames.set((0, _utils.queueIdKey)(entry.id), entry.name);
951
+ }
952
+ });
953
+ link = ((_response$headers4 = response.headers) === null || _response$headers4 === void 0 ? void 0 : _response$headers4.link) || ((_response$headers5 = response.headers) === null || _response$headers5 === void 0 ? void 0 : _response$headers5.Link);
954
+ headerNext = link === null || link === void 0 ? void 0 : link.split(',').map(function (entry) {
955
+ var _exec;
956
+ return (_exec = /<([^>]+)>\s*;\s*rel=["']?next["']?/i.exec(entry)) === null || _exec === void 0 ? void 0 : _exec[1];
957
+ }).find(Boolean);
958
+ next = _this6.catalogNextUrl(headerNext || catalog.next);
959
+ if (!next) {
960
+ _context8.next = 4;
961
+ break;
962
+ }
963
+ _context8.next = 4;
964
+ return _loadPage(next, remainingPages - 1);
965
+ case 4:
966
+ case "end":
967
+ return _context8.stop();
968
+ }
969
+ }, _callee8);
970
+ }));
971
+ return function loadPage(_x10, _x11) {
972
+ return _ref5.apply(this, arguments);
973
+ };
974
+ }();
975
+ _context9.prev = 1;
976
+ _context9.next = 2;
977
+ return _loadPage(this.joinUrl(_constants2.QUEUES_CATALOG_PATH), _constants2.MAX_QUEUE_CATALOG_PAGES);
978
+ case 2:
979
+ _context9.next = 4;
980
+ break;
981
+ case 3:
982
+ _context9.prev = 3;
983
+ _t7 = _context9["catch"](1);
984
+ statusCode = _t7 && (0, _typeof2.default)(_t7) === 'object' && 'statusCode' in _t7 ? _t7.statusCode : undefined;
985
+ _Logger.default.error("Failed to load call queue names: status=".concat(statusCode !== null && statusCode !== void 0 ? statusCode : 'unknown'), loggerContext);
986
+ case 4:
987
+ case "end":
988
+ return _context9.stop();
989
+ }
990
+ }, _callee9, this, [[1, 3]]);
991
+ }));
992
+ function loadQueueCatalog(_x1) {
993
+ return _loadQueueCatalog.apply(this, arguments);
994
+ }
995
+ return loadQueueCatalog;
996
+ }()
997
+ }, {
998
+ key: "catalogNextUrl",
999
+ value: function catalogNextUrl(next) {
1000
+ if (!next || next.includes('..') || next.includes('\\') || next.includes('@')) {
1001
+ return undefined;
1002
+ }
1003
+ try {
1004
+ var catalog = new URL(this.joinUrl(_constants2.QUEUES_CATALOG_PATH));
1005
+ var candidate = new URL(next.startsWith(_constants2.QUEUES_CATALOG_PATH) ? this.joinUrl(next) : next, catalog);
1006
+ return candidate.origin === catalog.origin && candidate.pathname === catalog.pathname ? candidate.toString() : undefined;
1007
+ } catch (_unused3) {
1008
+ return undefined;
1009
+ }
1010
+ }
1011
+ }, {
1012
+ key: "wdmDeviceId",
1013
+ value: function wdmDeviceId() {
1014
+ var _this$webex$internal$3;
1015
+ var url = (_this$webex$internal$3 = this.webex.internal.device) === null || _this$webex$internal$3 === void 0 ? void 0 : _this$webex$internal$3.url;
1016
+ var id = typeof url === 'string' ? url.split('/').filter(Boolean).pop() : undefined;
1017
+ if (!id || !_constants2.WDM_DEVICE_ID_PATTERN.test(id)) {
1018
+ return undefined;
1019
+ }
1020
+ return id;
1021
+ }
1022
+ }, {
1023
+ key: "queuesUrl",
1024
+ value: function queuesUrl(lineOwnerId) {
1025
+ if (!lineOwnerId) {
1026
+ return this.joinUrl(_constants2.QUEUES_PATH);
1027
+ }
1028
+ return this.joinUrl("".concat(_constants2.SECONDARY_LINES_PATH, "/").concat(encodeURIComponent((0, _utils.publicApiId)(lineOwnerId, 'VIRTUAL_LINE')), "/queues"));
1029
+ }
1030
+ }, {
1031
+ key: "joinUrl",
1032
+ value: function joinUrl(path) {
1033
+ var endpoint = this.webexApiEndpoint || '';
1034
+ var base = endpoint.endsWith('/') ? endpoint : "".concat(endpoint, "/");
1035
+ return "".concat(base).concat(path);
1036
+ }
1037
+ }, {
1038
+ key: "rejectBeforeRequest",
1039
+ value: function rejectBeforeRequest(lineOwnerId) {
1040
+ if (this.disposed) {
1041
+ return {
1042
+ statusCode: 400,
1043
+ data: {
1044
+ error: 'Call queue client has been disposed'
1045
+ },
1046
+ message: _constants.FAILURE_MESSAGE
1047
+ };
1048
+ }
1049
+ // Device entitlement data may arrive after the client is constructed.
1050
+ this.callingBackend = (0, _utils.hasReadyEntitlementModels)(this.webex) ? (0, _Utils.getCallingBackEnd)(this.webex) : _types.CALLING_BACKEND.INVALID;
1051
+ if (this.callingBackend !== _types.CALLING_BACKEND.WXC) {
1052
+ return {
1053
+ statusCode: 501,
1054
+ data: {
1055
+ error: _constants2.UNSUPPORTED_BACKEND_MESSAGE
1056
+ },
1057
+ message: _constants.FAILURE_MESSAGE
1058
+ };
1059
+ }
1060
+ if (!this.mercuryListeners.length) this.registerAgentListeners();
1061
+ if (lineOwnerId !== undefined && !_constants2.LINE_OWNER_ID_PATTERN.test(lineOwnerId)) {
1062
+ return {
1063
+ statusCode: 400,
1064
+ data: {
1065
+ error: 'lineOwnerId is not a valid line id'
1066
+ },
1067
+ message: _constants.FAILURE_MESSAGE
1068
+ };
1069
+ }
1070
+ if (!this.webexApiEndpoint) {
1071
+ return {
1072
+ statusCode: 400,
1073
+ data: {
1074
+ error: 'A supported Webex API base URL is required for call queues'
1075
+ },
1076
+ message: _constants.FAILURE_MESSAGE
1077
+ };
1078
+ }
1079
+ return undefined;
1080
+ }
1081
+ }, {
1082
+ key: "rejectUpdate",
1083
+ value: function rejectUpdate(request) {
1084
+ var _request$queues;
1085
+ if (!request || (0, _typeof2.default)(request) !== 'object' || (0, _isArray.default)(request)) {
1086
+ return {
1087
+ statusCode: 400,
1088
+ data: {
1089
+ error: 'a call queue settings update is required'
1090
+ },
1091
+ message: _constants.FAILURE_MESSAGE
1092
+ };
1093
+ }
1094
+ var hasState = request.agentACDState !== undefined;
1095
+ var hasQueues = request.queues !== undefined;
1096
+ if (!hasState && !hasQueues) {
1097
+ return {
1098
+ statusCode: 400,
1099
+ data: {
1100
+ error: 'agentACDState or queues is required'
1101
+ },
1102
+ message: _constants.FAILURE_MESSAGE
1103
+ };
1104
+ }
1105
+ if (hasState && !_constants2.SUPPORTED_STATES.has(request.agentACDState)) {
1106
+ return {
1107
+ statusCode: 400,
1108
+ data: {
1109
+ error: 'agentACDState is not a supported ACD state'
1110
+ },
1111
+ message: _constants.FAILURE_MESSAGE
1112
+ };
1113
+ }
1114
+ if (hasQueues && !(0, _isArray.default)(request.queues)) {
1115
+ return {
1116
+ statusCode: 400,
1117
+ data: {
1118
+ error: 'queues must be an array of queue updates'
1119
+ },
1120
+ message: _constants.FAILURE_MESSAGE
1121
+ };
1122
+ }
1123
+ if (hasQueues && ((_request$queues = request.queues) === null || _request$queues === void 0 ? void 0 : _request$queues.length) === 0) {
1124
+ return {
1125
+ statusCode: 400,
1126
+ data: {
1127
+ error: 'queues must include at least one queue update'
1128
+ },
1129
+ message: _constants.FAILURE_MESSAGE
1130
+ };
1131
+ }
1132
+ if (hasQueues) {
1133
+ var _request$queues2;
1134
+ var invalid = (_request$queues2 = request.queues) === null || _request$queues2 === void 0 ? void 0 : _request$queues2.some(function (queue) {
1135
+ return !queue || typeof queue.id !== 'string' || !queue.id.trim() || typeof queue.available !== 'boolean';
1136
+ });
1137
+ if (invalid) {
1138
+ return {
1139
+ statusCode: 400,
1140
+ data: {
1141
+ error: 'each queue update needs an id and an available flag'
1142
+ },
1143
+ message: _constants.FAILURE_MESSAGE
1144
+ };
1145
+ }
1146
+ }
1147
+ return undefined;
1148
+ }
1149
+ }, {
1150
+ key: "buildUpdateBody",
1151
+ value: function buildUpdateBody(request, lineOwnerId) {
1152
+ var _this7 = this;
1153
+ var body = {};
1154
+ if (request.agentACDState) {
1155
+ body.agentACDState = request.agentACDState;
1156
+ }
1157
+ if (request.queues) {
1158
+ body.queues = request.queues.map(function (queue) {
1159
+ return {
1160
+ id: (0, _utils.publicApiId)(queue.id, 'CALL_QUEUE'),
1161
+ available: _this7.canChangeJoin(queue.id, lineOwnerId) ? queue.available : true
1162
+ };
1163
+ });
1164
+ }
1165
+ return body;
1166
+ }
1167
+ }, {
1168
+ key: "canChangeJoin",
1169
+ value: function canChangeJoin(queueId, lineOwnerId) {
1170
+ var _this$currentByLine$g;
1171
+ var known = (_this$currentByLine$g = this.currentByLine.get(lineOwnerId)) === null || _this$currentByLine$g === void 0 ? void 0 : _this$currentByLine$g.queues.find(function (queue) {
1172
+ return (0, _utils.queueIdKey)(queue.id) === (0, _utils.queueIdKey)(queueId);
1173
+ });
1174
+ if (!known || known.allowLogOffEnabled === undefined) {
1175
+ return true;
1176
+ }
1177
+ return known.allowLogOffEnabled;
1178
+ }
1179
+ }, {
1180
+ key: "needsQueuePolicyRefresh",
1181
+ value: function needsQueuePolicyRefresh(request, lineOwnerId) {
1182
+ var _request$queues3;
1183
+ var status = this.currentByLine.get(lineOwnerId);
1184
+ return Boolean((_request$queues3 = request.queues) === null || _request$queues3 === void 0 ? void 0 : _request$queues3.some(function (queue) {
1185
+ return !queue.available && !(status !== null && status !== void 0 && status.queues.some(function (known) {
1186
+ return (0, _utils.queueIdKey)(known.id) === (0, _utils.queueIdKey)(queue.id) && known.allowLogOffEnabled !== undefined;
1187
+ }));
1188
+ }));
1189
+ }
1190
+ }, {
1191
+ key: "applyLocalUpdate",
1192
+ value: function applyLocalUpdate(request, lineOwnerId) {
1193
+ var _this8 = this,
1194
+ _request$agentACDStat;
1195
+ var base = this.currentByLine.get(lineOwnerId);
1196
+ var queues = request.queues ? request.queues.reduce(function (list, update) {
1197
+ var index = list.findIndex(function (queue) {
1198
+ return (0, _utils.queueIdKey)(queue.id) === (0, _utils.queueIdKey)(update.id);
1199
+ });
1200
+ var available = _this8.canChangeJoin(update.id, lineOwnerId) ? update.available : true;
1201
+ if (index === -1) {
1202
+ return list.concat({
1203
+ id: update.id,
1204
+ available: available
1205
+ });
1206
+ }
1207
+ var next = list.slice();
1208
+ next[index] = _objectSpread(_objectSpread({}, list[index]), {}, {
1209
+ available: available
1210
+ });
1211
+ return next;
1212
+ }, base.queues) : base.queues;
1213
+ return {
1214
+ acdState: (_request$agentACDStat = request.agentACDState) !== null && _request$agentACDStat !== void 0 ? _request$agentACDStat : base.acdState,
1215
+ queues: queues
1216
+ };
1217
+ }
1218
+ }, {
1219
+ key: "fail",
1220
+ value: function () {
1221
+ var _fail = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee0(err, loggerContext, message, epoch) {
1222
+ var statusCode, _t8;
1223
+ return _regenerator.default.wrap(function (_context0) {
1224
+ while (1) switch (_context0.prev = _context0.next) {
1225
+ case 0:
1226
+ if (!(epoch !== this.lifecycleEpoch)) {
1227
+ _context0.next = 1;
1228
+ break;
1229
+ }
1230
+ return _context0.abrupt("return", undefined);
1231
+ case 1:
1232
+ statusCode = err && (0, _typeof2.default)(err) === 'object' && 'statusCode' in err ? err.statusCode : undefined;
1233
+ _Logger.default.error("".concat(message, ": status=").concat(statusCode !== null && statusCode !== void 0 ? statusCode : 'unknown'), loggerContext);
1234
+ _context0.prev = 2;
1235
+ _context0.next = 3;
1236
+ return (0, _Utils.uploadLogs)();
1237
+ case 3:
1238
+ _context0.next = 5;
1239
+ break;
1240
+ case 4:
1241
+ _context0.prev = 4;
1242
+ _t8 = _context0["catch"](2);
1243
+ _Logger.default.warn('Unable to upload call queue diagnostic logs', loggerContext);
1244
+ case 5:
1245
+ return _context0.abrupt("return", (0, _Utils.serviceErrorCodeHandler)(err !== null && err !== void 0 ? err : {}, loggerContext));
1246
+ case 6:
1247
+ case "end":
1248
+ return _context0.stop();
1249
+ }
1250
+ }, _callee0, this, [[2, 4]]);
1251
+ }));
1252
+ function fail(_x12, _x13, _x14, _x15) {
1253
+ return _fail.apply(this, arguments);
1254
+ }
1255
+ return fail;
1256
+ }()
1257
+ }]);
1258
+ }(_impl.Eventing);
1259
+ var clientConfigurations = new _weakMap.default();
1260
+
1261
+ /**
1262
+ * Creates a call-queue client for the signed-in Webex Calling user.
1263
+ *
1264
+ * @param webex - The Webex SDK instance used for requests and events.
1265
+ * @param logger - Logging configuration for the Calling SDK.
1266
+ * @param options - Call queue options, including the public API base URL.
1267
+ * @param previousClient - Optional existing client to reuse when its configuration still matches.
1268
+ * @param enabled - When supplied, manage the optional client without interrupting other clients.
1269
+ * @returns A call-queue client, or undefined when managed mode is disabled or fails.
1270
+ * @example
1271
+ * ```js
1272
+ * const callQueue = createCallQueueClient(webex, logger, {webexApiBaseUrl});
1273
+ * ```
1274
+ * @public
1275
+ */
1276
+
1277
+ function createCallQueueClient(webex, logger, options, previousClient, enabled) {
1278
+ var createOrReuse = function createOrReuse() {
1279
+ var _webex$internal$devic, _webex$internal$devic2;
1280
+ var config = {
1281
+ webex: webex,
1282
+ apiBaseUrl: options === null || options === void 0 ? void 0 : options.webexApiBaseUrl,
1283
+ loggerLevel: logger === null || logger === void 0 ? void 0 : logger.level,
1284
+ userId: (_webex$internal$devic = webex.internal.device) === null || _webex$internal$devic === void 0 ? void 0 : _webex$internal$devic.userId,
1285
+ orgId: (_webex$internal$devic2 = webex.internal.device) === null || _webex$internal$devic2 === void 0 ? void 0 : _webex$internal$devic2.orgId
1286
+ };
1287
+ var previousConfig = previousClient && clientConfigurations.get(previousClient);
1288
+ var compatible = previousConfig && previousConfig.webex === config.webex && previousConfig.apiBaseUrl === config.apiBaseUrl && previousConfig.loggerLevel === config.loggerLevel && previousConfig.userId === config.userId && previousConfig.orgId === config.orgId;
1289
+ if (previousClient && compatible) {
1290
+ try {
1291
+ if (previousClient.prepareForReuse()) return previousClient;
1292
+ } catch (error) {
1293
+ previousClient.dispose();
1294
+ throw error;
1295
+ }
1296
+ }
1297
+ previousClient === null || previousClient === void 0 ? void 0 : previousClient.dispose();
1298
+ var client = new CallQueueClient(webex, logger, options);
1299
+ clientConfigurations.set(client, config);
1300
+ return client;
1301
+ };
1302
+
1303
+ // Direct consumers retain their existing return and error behavior.
1304
+ if (enabled === undefined) return createOrReuse();
1305
+ try {
1306
+ if (enabled) return createOrReuse();
1307
+ previousClient === null || previousClient === void 0 ? void 0 : previousClient.dispose();
1308
+ } catch (error) {
1309
+ var context = {
1310
+ file: _constants2.CALL_QUEUE_FILE,
1311
+ method: 'createCallQueueClient'
1312
+ };
1313
+ _Logger.default.warn("Error occurred while initializing callQueue client ".concat(String(error)), context);
1314
+ try {
1315
+ previousClient === null || previousClient === void 0 ? void 0 : previousClient.dispose();
1316
+ } catch (cleanupError) {
1317
+ _Logger.default.warn("Error occurred while disposing callQueue client ".concat(String(cleanupError)), context);
1318
+ }
1319
+ }
1320
+ return undefined;
1321
+ }
1322
+ //# sourceMappingURL=CallQueue.js.map