@wazo/sdk 0.38.22 → 0.39.0-beta.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 (883) hide show
  1. package/README.md +62 -293
  2. package/dist/wazo-sdk.js +9 -25
  3. package/esm/__tests__/api-client.test.js +183 -5059
  4. package/esm/__tests__/web-rtc-client.test.js +177 -7930
  5. package/esm/api/agentd.js +23 -832
  6. package/esm/api/amid.js +9 -411
  7. package/esm/api/application.js +60 -829
  8. package/esm/api/auth.js +164 -1213
  9. package/esm/api/call-logd.js +24 -733
  10. package/esm/api/calld.js +114 -1469
  11. package/esm/api/chatd.js +48 -1311
  12. package/esm/api/confd.js +67 -1580
  13. package/esm/api/ctid-ng.js +92 -1343
  14. package/esm/api/dird.js +100 -1590
  15. package/esm/api/webhookd.js +7 -513
  16. package/esm/api-client.js +143 -4880
  17. package/esm/checker/Checker.js +45 -8727
  18. package/esm/checker/checks/aor.js +24 -4924
  19. package/esm/checker/checks/api.js +70 -4968
  20. package/esm/checker/checks/ice-ipv4.js +63 -117
  21. package/esm/checker/checks/index.js +8 -8677
  22. package/esm/checker/checks/symmetric-nat.js +54 -102
  23. package/esm/checker/checks/wazo-websocket.js +34 -999
  24. package/esm/checker/checks/webrtc-transport.js +28 -7845
  25. package/esm/checker/checks/webrtc.js +31 -7852
  26. package/esm/domain/AdHocAPIConference.js +86 -5115
  27. package/esm/domain/Agent.js +27 -61
  28. package/esm/domain/BadResponse.js +20 -43
  29. package/esm/domain/Call.js +120 -210
  30. package/esm/domain/CallLog.js +123 -305
  31. package/esm/domain/CallSession.js +251 -423
  32. package/esm/domain/ChatMessage.js +52 -105
  33. package/esm/domain/ChatRoom.js +28 -60
  34. package/esm/domain/Contact.js +435 -741
  35. package/esm/domain/Country.js +17 -19
  36. package/esm/domain/Device/DebugDevice.js +31 -47
  37. package/esm/domain/Device/Device.js +1 -1
  38. package/esm/domain/DirectorySource.js +1 -1
  39. package/esm/domain/ExternalApp.js +23 -56
  40. package/esm/domain/Features.js +57 -5009
  41. package/esm/domain/ForwardOption.js +35 -70
  42. package/esm/domain/IndirectTransfer.js +38 -97
  43. package/esm/domain/Line.js +37 -88
  44. package/esm/domain/Meeting.js +58 -113
  45. package/esm/domain/MeetingAuthorization.js +38 -68
  46. package/esm/domain/MeetingStatus.js +13 -28
  47. package/esm/domain/NotificationOptions.js +43 -77
  48. package/esm/domain/Phone/CTIPhone.js +245 -5743
  49. package/esm/domain/Phone/Phone.js +1 -2
  50. package/esm/domain/Phone/WebRTCPhone.js +1457 -2671
  51. package/esm/domain/Profile.js +120 -405
  52. package/esm/domain/Recording.js +27 -51
  53. package/esm/domain/Relocation.js +16 -40
  54. package/esm/domain/Room.js +90 -133
  55. package/esm/domain/SFUNotAvailableError.js +5 -8
  56. package/esm/domain/ServerError.js +8 -61
  57. package/esm/domain/Session.js +125 -251
  58. package/esm/domain/SipLine.js +78 -155
  59. package/esm/domain/Subscription.js +39 -83
  60. package/esm/domain/SwitchboardCall.js +51 -143
  61. package/esm/domain/Voicemail.js +57 -122
  62. package/esm/domain/__tests__/Agent.test.js +31 -101
  63. package/esm/domain/__tests__/Call.test.js +24 -232
  64. package/esm/domain/__tests__/CallLog.test.js +60 -386
  65. package/esm/domain/__tests__/CallSession.test.js +74 -502
  66. package/esm/domain/__tests__/Contact.test.js +220 -902
  67. package/esm/domain/__tests__/IndirectTransfer.test.js +63 -546
  68. package/esm/domain/__tests__/Line.test.js +48 -156
  69. package/esm/domain/__tests__/Meeting.test.js +73 -226
  70. package/esm/domain/__tests__/MeetingAuthorization.test.js +45 -105
  71. package/esm/domain/__tests__/Profile.test.js +135 -496
  72. package/esm/domain/__tests__/Room.test.js +227 -719
  73. package/esm/domain/__tests__/Session.test.js +357 -1025
  74. package/esm/domain/__tests__/SipLine.test.js +24 -179
  75. package/esm/domain/__tests__/Voicemail.test.js +82 -200
  76. package/esm/domain/types.js +1 -1
  77. package/esm/index.js +63 -14985
  78. package/esm/lib/WazoSessionDescriptionHandler.js +406 -890
  79. package/esm/pubkey.js +10 -0
  80. package/esm/service/CallApi.js +42 -5014
  81. package/esm/service/IssueReporter.js +278 -360
  82. package/esm/service/__tests__/IssueReporter.test.js +92 -494
  83. package/esm/service/getApiClient.js +53 -4972
  84. package/esm/simple/Auth.js +212 -14747
  85. package/esm/simple/Configuration.js +8 -14796
  86. package/esm/simple/Directory.js +6 -4964
  87. package/esm/simple/Phone.js +309 -14727
  88. package/esm/simple/Websocket.js +68 -1112
  89. package/esm/simple/index.js +125 -14792
  90. package/esm/simple/room/LocalParticipant.js +1 -14797
  91. package/esm/simple/room/Participant.js +274 -14760
  92. package/esm/simple/room/RemoteParticipant.js +6 -14796
  93. package/esm/simple/room/Room.js +648 -14736
  94. package/esm/simple/room/SipRoom.js +111 -14790
  95. package/esm/simple/room/Stream.js +40 -14792
  96. package/esm/simple/room/__tests__/Participant.test.js +68 -14872
  97. package/esm/simple/room/__tests__/RemoteParticipant.test.js +10 -14805
  98. package/esm/simple/utils.js +9 -14799
  99. package/esm/types/WebSocketMessage.js +1 -1
  100. package/esm/types/__tests__/api-client.test.d.ts +2 -0
  101. package/esm/types/__tests__/api-client.test.d.ts.map +1 -0
  102. package/esm/types/__tests__/web-rtc-client.test.d.ts +2 -0
  103. package/esm/types/__tests__/web-rtc-client.test.d.ts.map +1 -0
  104. package/esm/types/api/agentd.d.ts +17 -0
  105. package/esm/types/api/agentd.d.ts.map +1 -0
  106. package/esm/types/api/amid.d.ts +8 -0
  107. package/esm/types/api/amid.d.ts.map +1 -0
  108. package/esm/types/api/application.d.ts +34 -0
  109. package/esm/types/api/application.d.ts.map +1 -0
  110. package/esm/types/api/auth.d.ts +64 -0
  111. package/esm/types/api/auth.d.ts.map +1 -0
  112. package/esm/types/api/call-logd.d.ts +12 -0
  113. package/esm/types/api/call-logd.d.ts.map +1 -0
  114. package/esm/types/api/calld.d.ts +51 -0
  115. package/esm/types/api/calld.d.ts.map +1 -0
  116. package/esm/types/api/chatd.d.ts +42 -0
  117. package/esm/types/api/chatd.d.ts.map +1 -0
  118. package/esm/types/api/confd.d.ts +39 -0
  119. package/esm/types/api/confd.d.ts.map +1 -0
  120. package/esm/types/api/ctid-ng.d.ts +36 -0
  121. package/esm/types/api/ctid-ng.d.ts.map +1 -0
  122. package/esm/types/api/dird.d.ts +38 -0
  123. package/esm/types/api/dird.d.ts.map +1 -0
  124. package/esm/types/api/webhookd.d.ts +24 -0
  125. package/esm/types/api/webhookd.d.ts.map +1 -0
  126. package/esm/types/api-client.d.ts +63 -0
  127. package/esm/types/api-client.d.ts.map +1 -0
  128. package/esm/types/checker/Checker.d.ts +13 -0
  129. package/esm/types/checker/Checker.d.ts.map +1 -0
  130. package/esm/types/checker/checks/aor.d.ts +6 -0
  131. package/esm/types/checker/checks/aor.d.ts.map +1 -0
  132. package/esm/types/checker/checks/api.d.ts +6 -0
  133. package/esm/types/checker/checks/api.d.ts.map +1 -0
  134. package/esm/types/checker/checks/ice-ipv4.d.ts +6 -0
  135. package/esm/types/checker/checks/ice-ipv4.d.ts.map +1 -0
  136. package/esm/types/checker/checks/index.d.ts +9 -0
  137. package/esm/types/checker/checks/index.d.ts.map +1 -0
  138. package/esm/types/checker/checks/symmetric-nat.d.ts +6 -0
  139. package/esm/types/checker/checks/symmetric-nat.d.ts.map +1 -0
  140. package/esm/types/checker/checks/wazo-websocket.d.ts +6 -0
  141. package/esm/types/checker/checks/wazo-websocket.d.ts.map +1 -0
  142. package/esm/types/checker/checks/webrtc-transport.d.ts +7 -0
  143. package/esm/types/checker/checks/webrtc-transport.d.ts.map +1 -0
  144. package/esm/types/checker/checks/webrtc.d.ts +6 -0
  145. package/esm/types/checker/checks/webrtc.d.ts.map +1 -0
  146. package/esm/types/domain/AdHocAPIConference.d.ts +54 -0
  147. package/esm/types/domain/AdHocAPIConference.d.ts.map +1 -0
  148. package/esm/types/domain/Agent.d.ts +31 -0
  149. package/esm/types/domain/Agent.d.ts.map +1 -0
  150. package/esm/types/domain/BadResponse.d.ts +11 -0
  151. package/esm/types/domain/BadResponse.d.ts.map +1 -0
  152. package/esm/types/domain/Call.d.ts +79 -0
  153. package/esm/types/domain/Call.d.ts.map +1 -0
  154. package/esm/types/domain/CallLog.d.ts +91 -0
  155. package/esm/types/domain/CallLog.d.ts.map +1 -0
  156. package/esm/types/domain/CallSession.d.ts +120 -0
  157. package/esm/types/domain/CallSession.d.ts.map +1 -0
  158. package/esm/types/domain/ChatMessage.d.ts +41 -0
  159. package/esm/types/domain/ChatMessage.d.ts.map +1 -0
  160. package/esm/types/domain/ChatRoom.d.ts +22 -0
  161. package/esm/types/domain/ChatRoom.d.ts.map +1 -0
  162. package/esm/types/domain/Contact.d.ts +316 -0
  163. package/esm/types/domain/Contact.d.ts.map +1 -0
  164. package/esm/types/domain/Country.d.ts +20 -0
  165. package/esm/types/domain/Country.d.ts.map +1 -0
  166. package/esm/types/domain/Device/DebugDevice.d.ts +14 -0
  167. package/esm/types/domain/Device/DebugDevice.d.ts.map +1 -0
  168. package/esm/types/domain/Device/Device.d.ts +13 -0
  169. package/esm/types/domain/Device/Device.d.ts.map +1 -0
  170. package/esm/types/domain/DirectorySource.d.ts +13 -0
  171. package/esm/types/domain/DirectorySource.d.ts.map +1 -0
  172. package/esm/types/domain/ExternalApp.d.ts +22 -0
  173. package/esm/types/domain/ExternalApp.d.ts.map +1 -0
  174. package/esm/types/domain/Features.d.ts +24 -0
  175. package/esm/types/domain/Features.d.ts.map +1 -0
  176. package/esm/types/domain/ForwardOption.d.ts +27 -0
  177. package/esm/types/domain/ForwardOption.d.ts.map +1 -0
  178. package/esm/types/domain/IndirectTransfer.d.ts +31 -0
  179. package/esm/types/domain/IndirectTransfer.d.ts.map +1 -0
  180. package/esm/types/domain/Line.d.ts +46 -0
  181. package/esm/types/domain/Line.d.ts.map +1 -0
  182. package/esm/types/domain/Meeting.d.ts +45 -0
  183. package/esm/types/domain/Meeting.d.ts.map +1 -0
  184. package/esm/types/domain/MeetingAuthorization.d.ts +26 -0
  185. package/esm/types/domain/MeetingAuthorization.d.ts.map +1 -0
  186. package/esm/types/domain/MeetingStatus.d.ts +10 -0
  187. package/esm/types/domain/MeetingStatus.d.ts.map +1 -0
  188. package/esm/types/domain/NotificationOptions.d.ts +22 -0
  189. package/esm/types/domain/NotificationOptions.d.ts.map +1 -0
  190. package/esm/types/domain/Phone/CTIPhone.d.ts +76 -0
  191. package/esm/types/domain/Phone/CTIPhone.d.ts.map +1 -0
  192. package/esm/types/domain/Phone/Phone.d.ts +71 -0
  193. package/esm/types/domain/Phone/Phone.d.ts.map +1 -0
  194. package/esm/types/domain/Phone/WebRTCPhone.d.ts +179 -0
  195. package/esm/types/domain/Phone/WebRTCPhone.d.ts.map +1 -0
  196. package/esm/types/domain/Profile.d.ts +151 -0
  197. package/esm/types/domain/Profile.d.ts.map +1 -0
  198. package/esm/types/domain/Recording.d.ts +26 -0
  199. package/esm/types/domain/Recording.d.ts.map +1 -0
  200. package/esm/types/domain/Relocation.d.ts +23 -0
  201. package/esm/types/domain/Relocation.d.ts.map +1 -0
  202. package/esm/types/domain/Room.d.ts +35 -0
  203. package/esm/types/domain/Room.d.ts.map +1 -0
  204. package/esm/types/domain/SFUNotAvailableError.d.ts +4 -0
  205. package/esm/types/domain/SFUNotAvailableError.d.ts.map +1 -0
  206. package/esm/types/domain/ServerError.d.ts +6 -0
  207. package/esm/types/domain/ServerError.d.ts.map +1 -0
  208. package/esm/types/domain/Session.d.ts +90 -0
  209. package/esm/types/domain/Session.d.ts.map +1 -0
  210. package/esm/types/domain/SipLine.d.ts +54 -0
  211. package/esm/types/domain/SipLine.d.ts.map +1 -0
  212. package/esm/types/domain/Subscription.d.ts +43 -0
  213. package/esm/types/domain/Subscription.d.ts.map +1 -0
  214. package/esm/types/domain/SwitchboardCall.d.ts +62 -0
  215. package/esm/types/domain/SwitchboardCall.d.ts.map +1 -0
  216. package/esm/types/domain/Voicemail.d.ts +50 -0
  217. package/esm/types/domain/Voicemail.d.ts.map +1 -0
  218. package/esm/types/domain/__tests__/Agent.test.d.ts +2 -0
  219. package/esm/types/domain/__tests__/Agent.test.d.ts.map +1 -0
  220. package/esm/types/domain/__tests__/Call.test.d.ts +2 -0
  221. package/esm/types/domain/__tests__/Call.test.d.ts.map +1 -0
  222. package/esm/types/domain/__tests__/CallLog.test.d.ts +2 -0
  223. package/esm/types/domain/__tests__/CallLog.test.d.ts.map +1 -0
  224. package/esm/types/domain/__tests__/CallSession.test.d.ts +2 -0
  225. package/esm/types/domain/__tests__/CallSession.test.d.ts.map +1 -0
  226. package/esm/types/domain/__tests__/Contact.test.d.ts +2 -0
  227. package/esm/types/domain/__tests__/Contact.test.d.ts.map +1 -0
  228. package/esm/types/domain/__tests__/IndirectTransfer.test.d.ts +2 -0
  229. package/esm/types/domain/__tests__/IndirectTransfer.test.d.ts.map +1 -0
  230. package/esm/types/domain/__tests__/Line.test.d.ts +2 -0
  231. package/esm/types/domain/__tests__/Line.test.d.ts.map +1 -0
  232. package/esm/types/domain/__tests__/Meeting.test.d.ts +2 -0
  233. package/esm/types/domain/__tests__/Meeting.test.d.ts.map +1 -0
  234. package/esm/types/domain/__tests__/MeetingAuthorization.test.d.ts +2 -0
  235. package/esm/types/domain/__tests__/MeetingAuthorization.test.d.ts.map +1 -0
  236. package/esm/types/domain/__tests__/Profile.test.d.ts +2 -0
  237. package/esm/types/domain/__tests__/Profile.test.d.ts.map +1 -0
  238. package/esm/types/domain/__tests__/Room.test.d.ts +2 -0
  239. package/esm/types/domain/__tests__/Room.test.d.ts.map +1 -0
  240. package/esm/types/domain/__tests__/Session.test.d.ts +2 -0
  241. package/esm/types/domain/__tests__/Session.test.d.ts.map +1 -0
  242. package/esm/types/domain/__tests__/SipLine.test.d.ts +2 -0
  243. package/esm/types/domain/__tests__/SipLine.test.d.ts.map +1 -0
  244. package/esm/types/domain/__tests__/Voicemail.test.d.ts +2 -0
  245. package/esm/types/domain/__tests__/Voicemail.test.d.ts.map +1 -0
  246. package/esm/types/domain/types.d.ts +217 -0
  247. package/esm/types/domain/types.d.ts.map +1 -0
  248. package/esm/types/index.d.ts +304 -0
  249. package/esm/types/index.d.ts.map +1 -0
  250. package/esm/types/lib/WazoSessionDescriptionHandler.d.ts +30 -0
  251. package/esm/types/lib/WazoSessionDescriptionHandler.d.ts.map +1 -0
  252. package/esm/types/pubkey.d.ts +3 -0
  253. package/esm/types/pubkey.d.ts.map +1 -0
  254. package/esm/types/service/CallApi.d.ts +28 -0
  255. package/esm/types/service/CallApi.d.ts.map +1 -0
  256. package/esm/types/service/IssueReporter.d.ts +40 -0
  257. package/esm/types/service/IssueReporter.d.ts.map +1 -0
  258. package/esm/types/service/__tests__/IssueReporter.test.d.ts +2 -0
  259. package/esm/types/service/__tests__/IssueReporter.test.d.ts.map +1 -0
  260. package/esm/types/service/getApiClient.d.ts +16 -0
  261. package/esm/types/service/getApiClient.d.ts.map +1 -0
  262. package/esm/types/simple/Auth.d.ts +51 -0
  263. package/esm/types/simple/Auth.d.ts.map +1 -0
  264. package/esm/types/simple/Configuration.d.ts +3 -0
  265. package/esm/types/simple/Configuration.d.ts.map +1 -0
  266. package/esm/types/simple/Directory.d.ts +3 -0
  267. package/esm/types/simple/Directory.d.ts.map +1 -0
  268. package/esm/types/simple/Phone.d.ts +115 -0
  269. package/esm/types/simple/Phone.d.ts.map +1 -0
  270. package/esm/types/simple/Websocket.d.ts +19 -0
  271. package/esm/types/simple/Websocket.d.ts.map +1 -0
  272. package/esm/types/simple/index.d.ts +147 -0
  273. package/esm/types/simple/index.d.ts.map +1 -0
  274. package/esm/types/simple/room/LocalParticipant.d.ts +5 -0
  275. package/esm/types/simple/room/LocalParticipant.d.ts.map +1 -0
  276. package/esm/types/simple/room/Participant.d.ts +76 -0
  277. package/esm/types/simple/room/Participant.d.ts.map +1 -0
  278. package/esm/types/simple/room/RemoteParticipant.d.ts +7 -0
  279. package/esm/types/simple/room/RemoteParticipant.d.ts.map +1 -0
  280. package/esm/types/simple/room/Room.d.ts +116 -0
  281. package/esm/types/simple/room/Room.d.ts.map +1 -0
  282. package/esm/types/simple/room/SipRoom.d.ts +14 -0
  283. package/esm/types/simple/room/SipRoom.d.ts.map +1 -0
  284. package/esm/types/simple/room/Stream.d.ts +13 -0
  285. package/esm/types/simple/room/Stream.d.ts.map +1 -0
  286. package/esm/types/simple/room/__tests__/Participant.test.d.ts +2 -0
  287. package/esm/types/simple/room/__tests__/Participant.test.d.ts.map +1 -0
  288. package/esm/types/simple/room/__tests__/RemoteParticipant.test.d.ts +2 -0
  289. package/esm/types/simple/room/__tests__/RemoteParticipant.test.d.ts.map +1 -0
  290. package/esm/types/simple/utils.d.ts +3 -0
  291. package/esm/types/simple/utils.d.ts.map +1 -0
  292. package/esm/types/types/WebSocketMessage.d.ts +285 -0
  293. package/esm/types/types/WebSocketMessage.d.ts.map +1 -0
  294. package/esm/types/utils/Emitter.d.ts +18 -0
  295. package/esm/types/utils/Emitter.d.ts.map +1 -0
  296. package/esm/types/utils/Heartbeat.d.ts +21 -0
  297. package/esm/types/utils/Heartbeat.d.ts.map +1 -0
  298. package/esm/types/utils/PhoneNumberUtil.d.ts +8 -0
  299. package/esm/types/utils/PhoneNumberUtil.d.ts.map +1 -0
  300. package/esm/types/utils/__tests__/Heartbeat.test.d.ts +2 -0
  301. package/esm/types/utils/__tests__/Heartbeat.test.d.ts.map +1 -0
  302. package/esm/types/utils/__tests__/PhoneNumberUtil.test.d.ts +2 -0
  303. package/esm/types/utils/__tests__/PhoneNumberUtil.test.d.ts.map +1 -0
  304. package/esm/types/utils/__tests__/api-requester.test.d.ts +2 -0
  305. package/esm/types/utils/__tests__/api-requester.test.d.ts.map +1 -0
  306. package/esm/types/utils/__tests__/array.test.d.ts +2 -0
  307. package/esm/types/utils/__tests__/array.test.d.ts.map +1 -0
  308. package/esm/types/utils/__tests__/compare-version.test.d.ts +2 -0
  309. package/esm/types/utils/__tests__/compare-version.test.d.ts.map +1 -0
  310. package/esm/types/utils/__tests__/object.test.d.ts +2 -0
  311. package/esm/types/utils/__tests__/object.test.d.ts.map +1 -0
  312. package/esm/types/utils/__tests__/sdp.test.d.ts +2 -0
  313. package/esm/types/utils/__tests__/sdp.test.d.ts.map +1 -0
  314. package/esm/types/utils/__tests__/string.test.d.ts +2 -0
  315. package/esm/types/utils/__tests__/string.test.d.ts.map +1 -0
  316. package/esm/types/utils/api-requester.d.ts +45 -0
  317. package/esm/types/utils/api-requester.d.ts.map +1 -0
  318. package/esm/types/utils/array.d.ts +2 -0
  319. package/esm/types/utils/array.d.ts.map +1 -0
  320. package/esm/types/utils/compare-version.d.ts +3 -0
  321. package/esm/types/utils/compare-version.d.ts.map +1 -0
  322. package/esm/types/utils/isMobile.d.ts +3 -0
  323. package/esm/types/utils/isMobile.d.ts.map +1 -0
  324. package/esm/types/utils/new-from.d.ts +3 -0
  325. package/esm/types/utils/new-from.d.ts.map +1 -0
  326. package/esm/types/utils/object.d.ts +2 -0
  327. package/esm/types/utils/object.d.ts.map +1 -0
  328. package/esm/types/utils/once.d.ts +2 -0
  329. package/esm/types/utils/once.d.ts.map +1 -0
  330. package/esm/types/utils/sdp.d.ts +13 -0
  331. package/esm/types/utils/sdp.d.ts.map +1 -0
  332. package/esm/types/utils/string.d.ts +2 -0
  333. package/esm/types/utils/string.d.ts.map +1 -0
  334. package/esm/types/utils/update-from.d.ts +3 -0
  335. package/esm/types/utils/update-from.d.ts.map +1 -0
  336. package/esm/types/utils/webrtc.d.ts +15 -0
  337. package/esm/types/utils/webrtc.d.ts.map +1 -0
  338. package/esm/types/web-rtc-client.d.ts +220 -0
  339. package/esm/types/web-rtc-client.d.ts.map +1 -0
  340. package/esm/types/websocket-client.d.ts +134 -0
  341. package/esm/types/websocket-client.d.ts.map +1 -0
  342. package/esm/utils/Emitter.js +17 -27
  343. package/esm/utils/Heartbeat.js +60 -83
  344. package/esm/utils/PhoneNumberUtil.js +48 -63
  345. package/esm/utils/__tests__/Heartbeat.test.js +59 -168
  346. package/esm/utils/__tests__/PhoneNumberUtil.test.js +55 -125
  347. package/esm/utils/__tests__/api-requester.test.js +127 -780
  348. package/esm/utils/__tests__/array.test.js +16 -19
  349. package/esm/utils/__tests__/compare-version.test.js +8 -26
  350. package/esm/utils/__tests__/object.test.js +73 -54
  351. package/esm/utils/__tests__/sdp.test.js +87 -216
  352. package/esm/utils/__tests__/string.test.js +21 -27
  353. package/esm/utils/api-requester.js +197 -675
  354. package/esm/utils/array.js +7 -11
  355. package/esm/utils/compare-version.js +12 -15
  356. package/esm/utils/isMobile.js +0 -2
  357. package/esm/utils/new-from.js +7 -12
  358. package/esm/utils/object.js +9 -23
  359. package/esm/utils/once.js +12 -13
  360. package/esm/utils/sdp.js +87 -131
  361. package/esm/utils/string.js +5 -9
  362. package/esm/utils/update-from.js +9 -16
  363. package/esm/utils/webrtc.js +35 -36
  364. package/esm/web-rtc-client.js +2038 -7677
  365. package/esm/websocket-client.js +352 -944
  366. package/lib/__tests__/api-client.test.js +199 -5067
  367. package/lib/__tests__/web-rtc-client.test.js +191 -7941
  368. package/lib/api/agentd.js +27 -837
  369. package/lib/api/amid.js +18 -415
  370. package/lib/api/application.js +64 -834
  371. package/lib/api/auth.js +166 -1222
  372. package/lib/api/call-logd.js +28 -738
  373. package/lib/api/calld.js +126 -1473
  374. package/lib/api/chatd.js +65 -1316
  375. package/lib/api/confd.js +79 -1584
  376. package/lib/api/ctid-ng.js +96 -1348
  377. package/lib/api/dird.js +105 -1596
  378. package/lib/api/webhookd.js +11 -518
  379. package/lib/api-client.js +139 -4884
  380. package/lib/checker/Checker.js +61 -8739
  381. package/lib/checker/checks/aor.js +37 -4929
  382. package/lib/checker/checks/api.js +81 -4971
  383. package/lib/checker/checks/ice-ipv4.js +66 -118
  384. package/lib/checker/checks/index.js +13 -8687
  385. package/lib/checker/checks/symmetric-nat.js +56 -104
  386. package/lib/checker/checks/wazo-websocket.js +58 -1006
  387. package/lib/checker/checks/webrtc-transport.js +41 -7853
  388. package/lib/checker/checks/webrtc.js +42 -7858
  389. package/lib/domain/AdHocAPIConference.js +80 -5116
  390. package/lib/domain/Agent.js +23 -64
  391. package/lib/domain/BadResponse.js +17 -44
  392. package/lib/domain/Call.js +108 -215
  393. package/lib/domain/CallLog.js +117 -311
  394. package/lib/domain/CallSession.js +221 -424
  395. package/lib/domain/ChatMessage.js +49 -110
  396. package/lib/domain/ChatRoom.js +28 -60
  397. package/lib/domain/Contact.js +409 -742
  398. package/lib/domain/Country.js +19 -21
  399. package/lib/domain/Device/DebugDevice.js +34 -49
  400. package/lib/domain/Device/Device.js +2 -2
  401. package/lib/domain/DirectorySource.js +2 -2
  402. package/lib/domain/ExternalApp.js +24 -56
  403. package/lib/domain/Features.js +68 -5018
  404. package/lib/domain/ForwardOption.js +36 -71
  405. package/lib/domain/IndirectTransfer.js +39 -98
  406. package/lib/domain/Line.js +35 -88
  407. package/lib/domain/Meeting.js +51 -118
  408. package/lib/domain/MeetingAuthorization.js +35 -75
  409. package/lib/domain/MeetingStatus.js +13 -29
  410. package/lib/domain/NotificationOptions.js +45 -77
  411. package/lib/domain/Phone/CTIPhone.js +283 -5755
  412. package/lib/domain/Phone/Phone.js +2 -5
  413. package/lib/domain/Phone/WebRTCPhone.js +1457 -2716
  414. package/lib/domain/Profile.js +127 -406
  415. package/lib/domain/Recording.js +28 -57
  416. package/lib/domain/Relocation.js +15 -43
  417. package/lib/domain/Room.js +73 -134
  418. package/lib/domain/SFUNotAvailableError.js +7 -9
  419. package/lib/domain/ServerError.js +14 -63
  420. package/lib/domain/Session.js +118 -251
  421. package/lib/domain/SipLine.js +70 -155
  422. package/lib/domain/Subscription.js +32 -86
  423. package/lib/domain/SwitchboardCall.js +45 -145
  424. package/lib/domain/Voicemail.js +56 -127
  425. package/lib/domain/__tests__/Agent.test.js +36 -103
  426. package/lib/domain/__tests__/Call.test.js +28 -237
  427. package/lib/domain/__tests__/CallLog.test.js +65 -392
  428. package/lib/domain/__tests__/CallSession.test.js +78 -503
  429. package/lib/domain/__tests__/Contact.test.js +224 -903
  430. package/lib/domain/__tests__/IndirectTransfer.test.js +75 -546
  431. package/lib/domain/__tests__/Line.test.js +52 -157
  432. package/lib/domain/__tests__/Meeting.test.js +78 -232
  433. package/lib/domain/__tests__/MeetingAuthorization.test.js +50 -107
  434. package/lib/domain/__tests__/Profile.test.js +161 -496
  435. package/lib/domain/__tests__/Room.test.js +239 -719
  436. package/lib/domain/__tests__/Session.test.js +350 -1024
  437. package/lib/domain/__tests__/SipLine.test.js +28 -180
  438. package/lib/domain/__tests__/Voicemail.test.js +86 -205
  439. package/lib/domain/types.js +2 -2
  440. package/lib/index.js +105 -15010
  441. package/lib/lib/WazoSessionDescriptionHandler.js +409 -898
  442. package/lib/pubkey.js +12 -0
  443. package/lib/service/CallApi.js +88 -5015
  444. package/lib/service/IssueReporter.js +264 -366
  445. package/lib/service/__tests__/IssueReporter.test.js +97 -500
  446. package/lib/service/getApiClient.js +70 -4990
  447. package/lib/simple/Auth.js +272 -14777
  448. package/lib/simple/Configuration.js +23 -14805
  449. package/lib/simple/Directory.js +18 -4966
  450. package/lib/simple/Phone.js +345 -14746
  451. package/lib/simple/Websocket.js +98 -1117
  452. package/lib/simple/index.js +151 -14800
  453. package/lib/simple/room/LocalParticipant.js +7 -14808
  454. package/lib/simple/room/Participant.js +269 -14778
  455. package/lib/simple/room/RemoteParticipant.js +11 -14806
  456. package/lib/simple/room/Room.js +655 -14761
  457. package/lib/simple/room/SipRoom.js +136 -14805
  458. package/lib/simple/room/Stream.js +43 -14802
  459. package/lib/simple/room/__tests__/Participant.test.js +79 -14879
  460. package/lib/simple/room/__tests__/RemoteParticipant.test.js +14 -14814
  461. package/lib/simple/utils.js +22 -14808
  462. package/lib/types/WebSocketMessage.js +2 -4
  463. package/lib/types/__tests__/api-client.test.d.ts +2 -0
  464. package/lib/types/__tests__/api-client.test.d.ts.map +1 -0
  465. package/lib/types/__tests__/web-rtc-client.test.d.ts +2 -0
  466. package/lib/types/__tests__/web-rtc-client.test.d.ts.map +1 -0
  467. package/lib/types/api/agentd.d.ts +17 -0
  468. package/lib/types/api/agentd.d.ts.map +1 -0
  469. package/lib/types/api/amid.d.ts +8 -0
  470. package/lib/types/api/amid.d.ts.map +1 -0
  471. package/lib/types/api/application.d.ts +34 -0
  472. package/lib/types/api/application.d.ts.map +1 -0
  473. package/lib/types/api/auth.d.ts +64 -0
  474. package/lib/types/api/auth.d.ts.map +1 -0
  475. package/lib/types/api/call-logd.d.ts +12 -0
  476. package/lib/types/api/call-logd.d.ts.map +1 -0
  477. package/lib/types/api/calld.d.ts +51 -0
  478. package/lib/types/api/calld.d.ts.map +1 -0
  479. package/lib/types/api/chatd.d.ts +42 -0
  480. package/lib/types/api/chatd.d.ts.map +1 -0
  481. package/lib/types/api/confd.d.ts +39 -0
  482. package/lib/types/api/confd.d.ts.map +1 -0
  483. package/lib/types/api/ctid-ng.d.ts +36 -0
  484. package/lib/types/api/ctid-ng.d.ts.map +1 -0
  485. package/lib/types/api/dird.d.ts +38 -0
  486. package/lib/types/api/dird.d.ts.map +1 -0
  487. package/lib/types/api/webhookd.d.ts +24 -0
  488. package/lib/types/api/webhookd.d.ts.map +1 -0
  489. package/lib/types/api-client.d.ts +63 -0
  490. package/lib/types/api-client.d.ts.map +1 -0
  491. package/lib/types/checker/Checker.d.ts +13 -0
  492. package/lib/types/checker/Checker.d.ts.map +1 -0
  493. package/lib/types/checker/checks/aor.d.ts +6 -0
  494. package/lib/types/checker/checks/aor.d.ts.map +1 -0
  495. package/lib/types/checker/checks/api.d.ts +6 -0
  496. package/lib/types/checker/checks/api.d.ts.map +1 -0
  497. package/lib/types/checker/checks/ice-ipv4.d.ts +6 -0
  498. package/lib/types/checker/checks/ice-ipv4.d.ts.map +1 -0
  499. package/lib/types/checker/checks/index.d.ts +9 -0
  500. package/lib/types/checker/checks/index.d.ts.map +1 -0
  501. package/lib/types/checker/checks/symmetric-nat.d.ts +6 -0
  502. package/lib/types/checker/checks/symmetric-nat.d.ts.map +1 -0
  503. package/lib/types/checker/checks/wazo-websocket.d.ts +6 -0
  504. package/lib/types/checker/checks/wazo-websocket.d.ts.map +1 -0
  505. package/lib/types/checker/checks/webrtc-transport.d.ts +7 -0
  506. package/lib/types/checker/checks/webrtc-transport.d.ts.map +1 -0
  507. package/lib/types/checker/checks/webrtc.d.ts +6 -0
  508. package/lib/types/checker/checks/webrtc.d.ts.map +1 -0
  509. package/lib/types/domain/AdHocAPIConference.d.ts +54 -0
  510. package/lib/types/domain/AdHocAPIConference.d.ts.map +1 -0
  511. package/lib/types/domain/Agent.d.ts +31 -0
  512. package/lib/types/domain/Agent.d.ts.map +1 -0
  513. package/lib/types/domain/BadResponse.d.ts +11 -0
  514. package/lib/types/domain/BadResponse.d.ts.map +1 -0
  515. package/lib/types/domain/Call.d.ts +79 -0
  516. package/lib/types/domain/Call.d.ts.map +1 -0
  517. package/lib/types/domain/CallLog.d.ts +91 -0
  518. package/lib/types/domain/CallLog.d.ts.map +1 -0
  519. package/lib/types/domain/CallSession.d.ts +120 -0
  520. package/lib/types/domain/CallSession.d.ts.map +1 -0
  521. package/lib/types/domain/ChatMessage.d.ts +41 -0
  522. package/lib/types/domain/ChatMessage.d.ts.map +1 -0
  523. package/lib/types/domain/ChatRoom.d.ts +22 -0
  524. package/lib/types/domain/ChatRoom.d.ts.map +1 -0
  525. package/lib/types/domain/Contact.d.ts +316 -0
  526. package/lib/types/domain/Contact.d.ts.map +1 -0
  527. package/lib/types/domain/Country.d.ts +20 -0
  528. package/lib/types/domain/Country.d.ts.map +1 -0
  529. package/lib/types/domain/Device/DebugDevice.d.ts +14 -0
  530. package/lib/types/domain/Device/DebugDevice.d.ts.map +1 -0
  531. package/lib/types/domain/Device/Device.d.ts +13 -0
  532. package/lib/types/domain/Device/Device.d.ts.map +1 -0
  533. package/lib/types/domain/DirectorySource.d.ts +13 -0
  534. package/lib/types/domain/DirectorySource.d.ts.map +1 -0
  535. package/lib/types/domain/ExternalApp.d.ts +22 -0
  536. package/lib/types/domain/ExternalApp.d.ts.map +1 -0
  537. package/lib/types/domain/Features.d.ts +24 -0
  538. package/lib/types/domain/Features.d.ts.map +1 -0
  539. package/lib/types/domain/ForwardOption.d.ts +27 -0
  540. package/lib/types/domain/ForwardOption.d.ts.map +1 -0
  541. package/lib/types/domain/IndirectTransfer.d.ts +31 -0
  542. package/lib/types/domain/IndirectTransfer.d.ts.map +1 -0
  543. package/lib/types/domain/Line.d.ts +46 -0
  544. package/lib/types/domain/Line.d.ts.map +1 -0
  545. package/lib/types/domain/Meeting.d.ts +45 -0
  546. package/lib/types/domain/Meeting.d.ts.map +1 -0
  547. package/lib/types/domain/MeetingAuthorization.d.ts +26 -0
  548. package/lib/types/domain/MeetingAuthorization.d.ts.map +1 -0
  549. package/lib/types/domain/MeetingStatus.d.ts +10 -0
  550. package/lib/types/domain/MeetingStatus.d.ts.map +1 -0
  551. package/lib/types/domain/NotificationOptions.d.ts +22 -0
  552. package/lib/types/domain/NotificationOptions.d.ts.map +1 -0
  553. package/lib/types/domain/Phone/CTIPhone.d.ts +76 -0
  554. package/lib/types/domain/Phone/CTIPhone.d.ts.map +1 -0
  555. package/lib/types/domain/Phone/Phone.d.ts +71 -0
  556. package/lib/types/domain/Phone/Phone.d.ts.map +1 -0
  557. package/lib/types/domain/Phone/WebRTCPhone.d.ts +179 -0
  558. package/lib/types/domain/Phone/WebRTCPhone.d.ts.map +1 -0
  559. package/lib/types/domain/Profile.d.ts +151 -0
  560. package/lib/types/domain/Profile.d.ts.map +1 -0
  561. package/lib/types/domain/Recording.d.ts +26 -0
  562. package/lib/types/domain/Recording.d.ts.map +1 -0
  563. package/lib/types/domain/Relocation.d.ts +23 -0
  564. package/lib/types/domain/Relocation.d.ts.map +1 -0
  565. package/lib/types/domain/Room.d.ts +35 -0
  566. package/lib/types/domain/Room.d.ts.map +1 -0
  567. package/lib/types/domain/SFUNotAvailableError.d.ts +4 -0
  568. package/lib/types/domain/SFUNotAvailableError.d.ts.map +1 -0
  569. package/lib/types/domain/ServerError.d.ts +6 -0
  570. package/lib/types/domain/ServerError.d.ts.map +1 -0
  571. package/lib/types/domain/Session.d.ts +90 -0
  572. package/lib/types/domain/Session.d.ts.map +1 -0
  573. package/lib/types/domain/SipLine.d.ts +54 -0
  574. package/lib/types/domain/SipLine.d.ts.map +1 -0
  575. package/lib/types/domain/Subscription.d.ts +43 -0
  576. package/lib/types/domain/Subscription.d.ts.map +1 -0
  577. package/lib/types/domain/SwitchboardCall.d.ts +62 -0
  578. package/lib/types/domain/SwitchboardCall.d.ts.map +1 -0
  579. package/lib/types/domain/Voicemail.d.ts +50 -0
  580. package/lib/types/domain/Voicemail.d.ts.map +1 -0
  581. package/lib/types/domain/__tests__/Agent.test.d.ts +2 -0
  582. package/lib/types/domain/__tests__/Agent.test.d.ts.map +1 -0
  583. package/lib/types/domain/__tests__/Call.test.d.ts +2 -0
  584. package/lib/types/domain/__tests__/Call.test.d.ts.map +1 -0
  585. package/lib/types/domain/__tests__/CallLog.test.d.ts +2 -0
  586. package/lib/types/domain/__tests__/CallLog.test.d.ts.map +1 -0
  587. package/lib/types/domain/__tests__/CallSession.test.d.ts +2 -0
  588. package/lib/types/domain/__tests__/CallSession.test.d.ts.map +1 -0
  589. package/lib/types/domain/__tests__/Contact.test.d.ts +2 -0
  590. package/lib/types/domain/__tests__/Contact.test.d.ts.map +1 -0
  591. package/lib/types/domain/__tests__/IndirectTransfer.test.d.ts +2 -0
  592. package/lib/types/domain/__tests__/IndirectTransfer.test.d.ts.map +1 -0
  593. package/lib/types/domain/__tests__/Line.test.d.ts +2 -0
  594. package/lib/types/domain/__tests__/Line.test.d.ts.map +1 -0
  595. package/lib/types/domain/__tests__/Meeting.test.d.ts +2 -0
  596. package/lib/types/domain/__tests__/Meeting.test.d.ts.map +1 -0
  597. package/lib/types/domain/__tests__/MeetingAuthorization.test.d.ts +2 -0
  598. package/lib/types/domain/__tests__/MeetingAuthorization.test.d.ts.map +1 -0
  599. package/lib/types/domain/__tests__/Profile.test.d.ts +2 -0
  600. package/lib/types/domain/__tests__/Profile.test.d.ts.map +1 -0
  601. package/lib/types/domain/__tests__/Room.test.d.ts +2 -0
  602. package/lib/types/domain/__tests__/Room.test.d.ts.map +1 -0
  603. package/lib/types/domain/__tests__/Session.test.d.ts +2 -0
  604. package/lib/types/domain/__tests__/Session.test.d.ts.map +1 -0
  605. package/lib/types/domain/__tests__/SipLine.test.d.ts +2 -0
  606. package/lib/types/domain/__tests__/SipLine.test.d.ts.map +1 -0
  607. package/lib/types/domain/__tests__/Voicemail.test.d.ts +2 -0
  608. package/lib/types/domain/__tests__/Voicemail.test.d.ts.map +1 -0
  609. package/lib/types/domain/types.d.ts +217 -0
  610. package/lib/types/domain/types.d.ts.map +1 -0
  611. package/lib/types/index.d.ts +304 -0
  612. package/lib/types/index.d.ts.map +1 -0
  613. package/lib/types/lib/WazoSessionDescriptionHandler.d.ts +30 -0
  614. package/lib/types/lib/WazoSessionDescriptionHandler.d.ts.map +1 -0
  615. package/lib/types/pubkey.d.ts +3 -0
  616. package/lib/types/pubkey.d.ts.map +1 -0
  617. package/lib/types/service/CallApi.d.ts +28 -0
  618. package/lib/types/service/CallApi.d.ts.map +1 -0
  619. package/lib/types/service/IssueReporter.d.ts +40 -0
  620. package/lib/types/service/IssueReporter.d.ts.map +1 -0
  621. package/lib/types/service/__tests__/IssueReporter.test.d.ts +2 -0
  622. package/lib/types/service/__tests__/IssueReporter.test.d.ts.map +1 -0
  623. package/lib/types/service/getApiClient.d.ts +16 -0
  624. package/lib/types/service/getApiClient.d.ts.map +1 -0
  625. package/lib/types/simple/Auth.d.ts +51 -0
  626. package/lib/types/simple/Auth.d.ts.map +1 -0
  627. package/lib/types/simple/Configuration.d.ts +3 -0
  628. package/lib/types/simple/Configuration.d.ts.map +1 -0
  629. package/lib/types/simple/Directory.d.ts +3 -0
  630. package/lib/types/simple/Directory.d.ts.map +1 -0
  631. package/lib/types/simple/Phone.d.ts +115 -0
  632. package/lib/types/simple/Phone.d.ts.map +1 -0
  633. package/lib/types/simple/Websocket.d.ts +19 -0
  634. package/lib/types/simple/Websocket.d.ts.map +1 -0
  635. package/lib/types/simple/index.d.ts +147 -0
  636. package/lib/types/simple/index.d.ts.map +1 -0
  637. package/lib/types/simple/room/LocalParticipant.d.ts +5 -0
  638. package/lib/types/simple/room/LocalParticipant.d.ts.map +1 -0
  639. package/lib/types/simple/room/Participant.d.ts +76 -0
  640. package/lib/types/simple/room/Participant.d.ts.map +1 -0
  641. package/lib/types/simple/room/RemoteParticipant.d.ts +7 -0
  642. package/lib/types/simple/room/RemoteParticipant.d.ts.map +1 -0
  643. package/lib/types/simple/room/Room.d.ts +116 -0
  644. package/lib/types/simple/room/Room.d.ts.map +1 -0
  645. package/lib/types/simple/room/SipRoom.d.ts +14 -0
  646. package/lib/types/simple/room/SipRoom.d.ts.map +1 -0
  647. package/lib/types/simple/room/Stream.d.ts +13 -0
  648. package/lib/types/simple/room/Stream.d.ts.map +1 -0
  649. package/lib/types/simple/room/__tests__/Participant.test.d.ts +2 -0
  650. package/lib/types/simple/room/__tests__/Participant.test.d.ts.map +1 -0
  651. package/lib/types/simple/room/__tests__/RemoteParticipant.test.d.ts +2 -0
  652. package/lib/types/simple/room/__tests__/RemoteParticipant.test.d.ts.map +1 -0
  653. package/lib/types/simple/utils.d.ts +3 -0
  654. package/lib/types/simple/utils.d.ts.map +1 -0
  655. package/lib/types/types/WebSocketMessage.d.ts +285 -0
  656. package/lib/types/types/WebSocketMessage.d.ts.map +1 -0
  657. package/lib/types/utils/Emitter.d.ts +18 -0
  658. package/lib/types/utils/Emitter.d.ts.map +1 -0
  659. package/lib/types/utils/Heartbeat.d.ts +21 -0
  660. package/lib/types/utils/Heartbeat.d.ts.map +1 -0
  661. package/lib/types/utils/PhoneNumberUtil.d.ts +8 -0
  662. package/lib/types/utils/PhoneNumberUtil.d.ts.map +1 -0
  663. package/lib/types/utils/__tests__/Heartbeat.test.d.ts +2 -0
  664. package/lib/types/utils/__tests__/Heartbeat.test.d.ts.map +1 -0
  665. package/lib/types/utils/__tests__/PhoneNumberUtil.test.d.ts +2 -0
  666. package/lib/types/utils/__tests__/PhoneNumberUtil.test.d.ts.map +1 -0
  667. package/lib/types/utils/__tests__/api-requester.test.d.ts +2 -0
  668. package/lib/types/utils/__tests__/api-requester.test.d.ts.map +1 -0
  669. package/lib/types/utils/__tests__/array.test.d.ts +2 -0
  670. package/lib/types/utils/__tests__/array.test.d.ts.map +1 -0
  671. package/lib/types/utils/__tests__/compare-version.test.d.ts +2 -0
  672. package/lib/types/utils/__tests__/compare-version.test.d.ts.map +1 -0
  673. package/lib/types/utils/__tests__/object.test.d.ts +2 -0
  674. package/lib/types/utils/__tests__/object.test.d.ts.map +1 -0
  675. package/lib/types/utils/__tests__/sdp.test.d.ts +2 -0
  676. package/lib/types/utils/__tests__/sdp.test.d.ts.map +1 -0
  677. package/lib/types/utils/__tests__/string.test.d.ts +2 -0
  678. package/lib/types/utils/__tests__/string.test.d.ts.map +1 -0
  679. package/lib/types/utils/api-requester.d.ts +45 -0
  680. package/lib/types/utils/api-requester.d.ts.map +1 -0
  681. package/lib/types/utils/array.d.ts +2 -0
  682. package/lib/types/utils/array.d.ts.map +1 -0
  683. package/lib/types/utils/compare-version.d.ts +3 -0
  684. package/lib/types/utils/compare-version.d.ts.map +1 -0
  685. package/lib/types/utils/isMobile.d.ts +3 -0
  686. package/lib/types/utils/isMobile.d.ts.map +1 -0
  687. package/lib/types/utils/new-from.d.ts +3 -0
  688. package/lib/types/utils/new-from.d.ts.map +1 -0
  689. package/lib/types/utils/object.d.ts +2 -0
  690. package/lib/types/utils/object.d.ts.map +1 -0
  691. package/lib/types/utils/once.d.ts +2 -0
  692. package/lib/types/utils/once.d.ts.map +1 -0
  693. package/lib/types/utils/sdp.d.ts +13 -0
  694. package/lib/types/utils/sdp.d.ts.map +1 -0
  695. package/lib/types/utils/string.d.ts +2 -0
  696. package/lib/types/utils/string.d.ts.map +1 -0
  697. package/lib/types/utils/update-from.d.ts +3 -0
  698. package/lib/types/utils/update-from.d.ts.map +1 -0
  699. package/lib/types/utils/webrtc.d.ts +15 -0
  700. package/lib/types/utils/webrtc.d.ts.map +1 -0
  701. package/lib/types/web-rtc-client.d.ts +220 -0
  702. package/lib/types/web-rtc-client.d.ts.map +1 -0
  703. package/lib/types/websocket-client.d.ts +134 -0
  704. package/lib/types/websocket-client.d.ts.map +1 -0
  705. package/lib/utils/Emitter.js +22 -33
  706. package/lib/utils/Heartbeat.js +54 -86
  707. package/lib/utils/PhoneNumberUtil.js +60 -77
  708. package/lib/utils/__tests__/Heartbeat.test.js +73 -170
  709. package/lib/utils/__tests__/PhoneNumberUtil.test.js +57 -131
  710. package/lib/utils/__tests__/api-requester.test.js +139 -784
  711. package/lib/utils/__tests__/array.test.js +18 -21
  712. package/lib/utils/__tests__/compare-version.test.js +12 -27
  713. package/lib/utils/__tests__/object.test.js +75 -56
  714. package/lib/utils/__tests__/sdp.test.js +99 -220
  715. package/lib/utils/__tests__/string.test.js +23 -29
  716. package/lib/utils/api-requester.js +191 -685
  717. package/lib/utils/array.js +10 -14
  718. package/lib/utils/compare-version.js +15 -18
  719. package/lib/utils/isMobile.js +3 -5
  720. package/lib/utils/new-from.js +9 -14
  721. package/lib/utils/object.js +12 -26
  722. package/lib/utils/once.js +15 -15
  723. package/lib/utils/sdp.js +97 -150
  724. package/lib/utils/string.js +8 -12
  725. package/lib/utils/update-from.js +11 -18
  726. package/lib/utils/webrtc.js +38 -39
  727. package/lib/web-rtc-client.js +2070 -7694
  728. package/lib/websocket-client.js +357 -1021
  729. package/package.json +41 -34
  730. package/src/__tests__/{api-client.test.js → api-client.test.ts} +71 -29
  731. package/src/__tests__/{web-rtc-client.test.js → web-rtc-client.test.ts} +95 -35
  732. package/src/api/agentd.ts +37 -0
  733. package/src/api/amid.ts +16 -0
  734. package/src/api/application.ts +96 -0
  735. package/src/api/auth.ts +259 -0
  736. package/src/api/call-logd.ts +38 -0
  737. package/src/api/calld.ts +183 -0
  738. package/src/api/chatd.ts +101 -0
  739. package/src/api/confd.ts +110 -0
  740. package/src/api/ctid-ng.ts +152 -0
  741. package/src/api/dird.ts +146 -0
  742. package/src/api/webhookd.ts +30 -0
  743. package/src/{api-client.js → api-client.ts} +103 -67
  744. package/src/checker/{Checker.js → Checker.ts} +27 -20
  745. package/src/checker/checks/{aor.js → aor.ts} +10 -6
  746. package/src/checker/checks/{api.js → api.ts} +18 -17
  747. package/src/checker/checks/{ice-ipv4.js → ice-ipv4.ts} +23 -26
  748. package/src/checker/checks/{index.js → index.ts} +1 -9
  749. package/src/checker/checks/{symmetric-nat.js → symmetric-nat.ts} +14 -15
  750. package/src/checker/checks/{wazo-websocket.js → wazo-websocket.ts} +7 -5
  751. package/src/checker/checks/{webrtc-transport.js → webrtc-transport.ts} +3 -2
  752. package/src/checker/checks/{webrtc.js → webrtc.ts} +3 -4
  753. package/src/domain/{AdHocAPIConference.js → AdHocAPIConference.ts} +38 -54
  754. package/src/domain/{Agent.js → Agent.ts} +11 -7
  755. package/src/domain/BadResponse.ts +29 -0
  756. package/src/domain/{Call.js → Call.ts} +62 -46
  757. package/src/domain/{CallLog.js → CallLog.ts} +61 -63
  758. package/src/domain/{CallSession.js → CallSession.ts} +55 -52
  759. package/src/domain/{ChatMessage.js → ChatMessage.ts} +32 -21
  760. package/src/domain/{ChatRoom.js → ChatRoom.ts} +15 -11
  761. package/src/domain/{Contact.js → Contact.ts} +380 -262
  762. package/src/domain/Device/{DebugDevice.js → DebugDevice.ts} +3 -5
  763. package/src/domain/Device/{Device.js → Device.ts} +0 -11
  764. package/src/domain/DirectorySource.ts +13 -0
  765. package/src/domain/{ExternalApp.js → ExternalApp.ts} +14 -13
  766. package/src/domain/{Features.js → Features.ts} +43 -17
  767. package/src/domain/{ForwardOption.js → ForwardOption.ts} +16 -16
  768. package/src/domain/{IndirectTransfer.js → IndirectTransfer.ts} +21 -19
  769. package/src/domain/{Line.js → Line.ts} +39 -26
  770. package/src/domain/{Meeting.js → Meeting.ts} +36 -29
  771. package/src/domain/{MeetingAuthorization.js → MeetingAuthorization.ts} +13 -12
  772. package/src/domain/{MeetingStatus.js → MeetingStatus.ts} +2 -6
  773. package/src/domain/{NotificationOptions.js → NotificationOptions.ts} +14 -13
  774. package/src/domain/Phone/{CTIPhone.js → CTIPhone.ts} +90 -60
  775. package/src/domain/Phone/{Phone.js → Phone.ts} +27 -72
  776. package/src/domain/Phone/{WebRTCPhone.js → WebRTCPhone.ts} +456 -422
  777. package/src/domain/{Profile.js → Profile.ts} +117 -100
  778. package/src/domain/{Recording.js → Recording.ts} +25 -16
  779. package/src/domain/{Relocation.js → Relocation.ts} +15 -14
  780. package/src/domain/{Room.js → Room.ts} +58 -27
  781. package/src/domain/{SFUNotAvailableError.js → SFUNotAvailableError.ts} +2 -2
  782. package/src/domain/ServerError.ts +12 -0
  783. package/src/domain/{Session.js → Session.ts} +89 -67
  784. package/src/domain/{SipLine.js → SipLine.ts} +52 -45
  785. package/src/domain/{Subscription.js → Subscription.ts} +22 -13
  786. package/src/domain/{SwitchboardCall.js → SwitchboardCall.ts} +48 -43
  787. package/src/domain/{Voicemail.js → Voicemail.ts} +38 -34
  788. package/src/domain/__tests__/{Agent.test.js → Agent.test.ts} +11 -19
  789. package/src/domain/__tests__/{Call.test.js → Call.test.ts} +12 -9
  790. package/src/domain/__tests__/CallLog.test.ts +65 -0
  791. package/src/domain/__tests__/{CallSession.test.js → CallSession.test.ts} +15 -19
  792. package/src/domain/__tests__/Contact.test.ts +238 -0
  793. package/src/domain/__tests__/{IndirectTransfer.test.js → IndirectTransfer.test.ts} +38 -31
  794. package/src/domain/__tests__/Line.test.ts +53 -0
  795. package/src/domain/__tests__/{Meeting.test.js → Meeting.test.ts} +12 -38
  796. package/src/domain/__tests__/{MeetingAuthorization.test.js → MeetingAuthorization.test.ts} +13 -21
  797. package/src/domain/__tests__/Profile.test.ts +139 -0
  798. package/src/domain/__tests__/{Room.test.js → Room.test.ts} +114 -76
  799. package/src/domain/__tests__/{Session.test.js → Session.test.ts} +137 -162
  800. package/src/domain/__tests__/{SipLine.test.js → SipLine.test.ts} +7 -3
  801. package/src/domain/__tests__/{Voicemail.test.js → Voicemail.test.ts} +26 -20
  802. package/src/domain/types.ts +227 -0
  803. package/src/{index.js → index.ts} +4 -28
  804. package/src/lib/WazoSessionDescriptionHandler.ts +534 -0
  805. package/{config.js → src/pubkey.ts} +3 -3
  806. package/src/service/{CallApi.js → CallApi.ts} +14 -18
  807. package/src/service/{IssueReporter.js → IssueReporter.ts} +105 -56
  808. package/src/service/__tests__/{IssueReporter.test.js → IssueReporter.test.ts} +27 -23
  809. package/src/service/getApiClient.ts +94 -0
  810. package/src/simple/{Auth.js → Auth.ts} +130 -101
  811. package/src/simple/{Configuration.js → Configuration.ts} +2 -3
  812. package/src/simple/{Directory.js → Directory.ts} +2 -3
  813. package/src/simple/Phone.ts +623 -0
  814. package/src/simple/Websocket.ts +119 -0
  815. package/src/simple/{index.js → index.ts} +51 -21
  816. package/src/simple/room/{LocalParticipant.js → LocalParticipant.ts} +1 -3
  817. package/src/simple/room/{Participant.js → Participant.ts} +108 -46
  818. package/src/simple/room/{RemoteParticipant.js → RemoteParticipant.ts} +5 -4
  819. package/src/simple/room/{Room.js → Room.ts} +266 -183
  820. package/src/simple/room/{SipRoom.js → SipRoom.ts} +46 -29
  821. package/src/simple/room/{Stream.js → Stream.ts} +8 -6
  822. package/src/simple/room/__tests__/{Participant.test.js → Participant.test.ts} +9 -15
  823. package/src/simple/room/__tests__/{RemoteParticipant.test.js → RemoteParticipant.test.ts} +5 -1
  824. package/src/simple/utils.ts +12 -0
  825. package/src/types/WebSocketMessage.ts +335 -0
  826. package/src/types/global.d.ts +26 -0
  827. package/src/utils/Emitter.ts +34 -0
  828. package/src/utils/{Heartbeat.js → Heartbeat.ts} +17 -11
  829. package/src/utils/{PhoneNumberUtil.js → PhoneNumberUtil.ts} +12 -18
  830. package/src/utils/__tests__/{Heartbeat.test.js → Heartbeat.test.ts} +0 -15
  831. package/src/utils/__tests__/{PhoneNumberUtil.test.js → PhoneNumberUtil.test.ts} +6 -4
  832. package/src/utils/__tests__/{api-requester.test.js → api-requester.test.ts} +75 -24
  833. package/src/utils/__tests__/{array.test.js → array.test.ts} +10 -2
  834. package/src/utils/__tests__/object.test.ts +77 -0
  835. package/src/utils/__tests__/{sdp.test.js → sdp.test.ts} +15 -37
  836. package/src/utils/__tests__/{string.test.js → string.test.ts} +4 -2
  837. package/src/utils/{api-requester.js → api-requester.ts} +104 -83
  838. package/src/utils/{array.js → array.ts} +2 -2
  839. package/src/utils/{compare-version.js → compare-version.ts} +3 -2
  840. package/src/utils/{isMobile.js → isMobile.ts} +1 -1
  841. package/src/utils/{new-from.js → new-from.ts} +3 -6
  842. package/src/utils/{object.js → object.ts} +3 -6
  843. package/src/utils/{once.js → once.ts} +5 -5
  844. package/src/utils/sdp.ts +119 -0
  845. package/src/utils/{string.js → string.ts} +2 -3
  846. package/src/utils/update-from.ts +11 -0
  847. package/src/utils/{webrtc.js → webrtc.ts} +21 -3
  848. package/src/{web-rtc-client.js → web-rtc-client.ts} +879 -476
  849. package/src/{websocket-client.js → websocket-client.ts} +146 -144
  850. package/esm/simple/Softphone.js +0 -394
  851. package/lib/simple/Softphone.js +0 -396
  852. package/src/api/agentd.js +0 -74
  853. package/src/api/amid.js +0 -13
  854. package/src/api/application.js +0 -137
  855. package/src/api/auth.js +0 -279
  856. package/src/api/call-logd.js +0 -20
  857. package/src/api/calld.js +0 -214
  858. package/src/api/chatd.js +0 -80
  859. package/src/api/confd.js +0 -127
  860. package/src/api/ctid-ng.js +0 -153
  861. package/src/api/dird.js +0 -159
  862. package/src/api/webhookd.js +0 -31
  863. package/src/domain/BadResponse.js +0 -42
  864. package/src/domain/DirectorySource.js +0 -16
  865. package/src/domain/ServerError.js +0 -18
  866. package/src/domain/__tests__/CallLog.test.js +0 -75
  867. package/src/domain/__tests__/Contact.test.js +0 -170
  868. package/src/domain/__tests__/Line.test.js +0 -73
  869. package/src/domain/__tests__/Profile.test.js +0 -104
  870. package/src/domain/types.js +0 -248
  871. package/src/lib/WazoSessionDescriptionHandler.js +0 -467
  872. package/src/service/getApiClient.js +0 -122
  873. package/src/simple/Phone.js +0 -425
  874. package/src/simple/Softphone.js +0 -392
  875. package/src/simple/Websocket.js +0 -86
  876. package/src/simple/utils.js +0 -17
  877. package/src/types/WebSocketMessage.js +0 -232
  878. package/src/utils/Emitter.js +0 -26
  879. package/src/utils/__tests__/object.test.js +0 -35
  880. package/src/utils/sdp.js +0 -140
  881. package/src/utils/update-from.js +0 -15
  882. /package/src/domain/{Country.js → Country.ts} +0 -0
  883. /package/src/utils/__tests__/{compare-version.test.js → compare-version.test.ts} +0 -0
@@ -1,5033 +1,61 @@
1
- import moment from 'moment';
2
- import { jws, b64utoutf8, KEYUTIL } from 'jsrsasign';
3
- import 'sip.js/lib/api/session-state';
4
- import { Base64 } from 'js-base64';
5
- import 'events';
6
- import { jsonToGraphQLQuery } from 'json-to-graphql-query/lib/jsonToGraphQLQuery';
7
-
8
- //
9
-
10
- var newFrom = (instance , ToClass ) => {
11
- const args = {};
12
- Object.getOwnPropertyNames(instance).forEach(prop => {
13
- args[prop] = instance[prop];
14
- });
15
-
16
- return new ToClass(args);
17
- };
18
-
19
- //
20
-
21
- const RECORD_STATE_ACTIVE = 'active';
22
-
23
-
24
-
25
-
26
-
27
-
28
-
29
-
30
-
31
-
32
-
33
-
34
-
35
-
36
-
37
-
38
-
39
-
40
-
41
-
42
-
43
-
44
-
45
-
46
-
47
-
48
-
49
-
50
-
51
-
52
-
53
-
54
-
55
-
56
-
57
-
58
-
59
-
60
-
61
- class Call {
62
-
63
-
64
-
65
-
66
-
67
-
68
-
69
-
70
-
71
-
72
-
73
-
74
-
75
-
76
-
77
-
78
-
79
-
80
-
81
- static parseMany(plain ) {
82
- if (!plain) {
83
- return [];
1
+ import Call from '../domain/Call';
2
+ import getApiClient from './getApiClient';
3
+ export default class CallApi {
4
+ static async fetchCallLogs(offset, limit) {
5
+ return getApiClient().callLogd.listCallLogs(offset, limit);
84
6
  }
85
- return plain.map((plainCall ) => Call.parse(plainCall));
86
- }
87
-
88
- static parse(plain ) {
89
- return new Call({
90
- id: plain.call_id,
91
- sipCallId: plain.sip_call_id,
92
- callerName: plain.caller_id_name,
93
- callerNumber: plain.caller_id_number,
94
- calleeName: plain.peer_caller_id_name,
95
- calleeNumber: plain.peer_caller_id_number,
96
- dialedExtension: plain.dialed_extension,
97
- isCaller: plain.is_caller,
98
- isVideo: plain.is_video,
99
- muted: plain.muted,
100
- onHold: plain.on_hold,
101
- status: plain.status,
102
- lineId: plain.line_id,
103
- startingTime: moment(plain.creation_time).toDate(),
104
- talkingToIds: Object.keys(plain.talking_to || {}),
105
- recording: plain.record_state === RECORD_STATE_ACTIVE,
106
- });
107
- }
108
-
109
- static newFrom(call ) {
110
- return newFrom(call, Call);
111
- }
112
-
113
- constructor({
114
- id,
115
- sipCallId,
116
- callerName,
117
- callerNumber,
118
- calleeName,
119
- calleeNumber,
120
- dialedExtension,
121
- isCaller,
122
- isVideo,
123
- lineId,
124
- muted,
125
- onHold,
126
- status,
127
- startingTime,
128
- talkingToIds,
129
- recording,
130
- } = {}) {
131
- this.id = id;
132
- this.sipCallId = sipCallId;
133
- this.callerName = callerName;
134
- this.callerNumber = callerNumber;
135
- this.calleeName = calleeName;
136
- this.calleeNumber = calleeNumber;
137
- this.dialedExtension = dialedExtension;
138
- this.muted = muted;
139
- this.onHold = onHold;
140
- this.isCaller = isCaller;
141
- this.lineId = lineId;
142
- this.status = status;
143
- this.startingTime = startingTime;
144
- this.talkingToIds = talkingToIds || [];
145
- this.recording = recording;
146
- this.isVideo = !!isVideo;
147
-
148
- // Useful to compare instead of instanceof with minified code
149
- this.type = 'Call';
150
- }
151
-
152
- getElapsedTimeInSeconds() {
153
- const now = Date.now();
154
- return (now - this.startingTime) / 1000;
155
- }
156
-
157
- separateCalleeName() {
158
- const names = this.calleeName.split(' ');
159
- const firstName = names[0];
160
- const lastName = names.slice(1).join(' ');
161
-
162
- return { firstName, lastName };
163
- }
164
-
165
- is(other ) {
166
- return !!other && this.id === other.id;
167
- }
168
-
169
- hasACalleeName() {
170
- return this.calleeName.length > 0;
171
- }
172
-
173
- hasNumber(number ) {
174
- return this.calleeNumber === number;
175
- }
176
-
177
- isUp() {
178
- return this.status === 'Up';
179
- }
180
-
181
- isDown() {
182
- return this.status === 'Down';
183
- }
184
-
185
- isRinging() {
186
- return this.isRingingIncoming() || this.isRingingOutgoing();
187
- }
188
-
189
- isRingingIncoming() {
190
- return this.status === 'Ringing';
191
- }
192
-
193
- isRingingOutgoing() {
194
- return this.status === 'Ring';
195
- }
196
-
197
- isFromTransfer() {
198
- return this.status === 'Down' || this.status === 'Ringing';
199
- }
200
-
201
- isOnHold() {
202
- return this.onHold;
203
- }
204
-
205
- putOnHold() {
206
- this.onHold = true;
207
- }
208
-
209
- resume() {
210
- this.onHold = false;
211
- }
212
-
213
- isRecording() {
214
- return this.recording;
215
- }
216
- }
217
-
218
- //
219
-
220
- const swarmPublicKey = `-----BEGIN PUBLIC KEY-----
221
- MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAmkXOuNfY8u5xoTiIhkb8
222
- djnbIwG/Wrz3vpo8BZir8L5e1a1nSy740qBjP7ZINBQoALDhFfmdOfJnCyEGiHuz
223
- ZW6jbG6C3PryE3Bu6GKwqSmD6k3q4Zk27fpwYAnNl+rWhYYM563rJZBda/INyHNN
224
- pK7M1mixWi7gNdjjXwoEXSSBx+VpYMkY6LiAB2mvHXTY9M1qI14dvgGoQISZQoKi
225
- NMTRCg5UP2ic0Dd9nSz/XpcOxGfa+0fwIl1F7RC1tJXOqvkGGPTOV4LLfg/Yta3h
226
- nUPX9EZZDIX6vO/0IBV1LzjSl2A1bYFYAjJfowv3i1CpvONBOClHjSY5t9Y8MH6p
227
- BwIDAQAB
228
- -----END PUBLIC KEY-----`;
229
-
230
- //
231
-
232
-
233
-
234
-
235
-
236
-
237
-
238
-
239
-
240
-
241
-
242
-
243
-
244
-
245
-
246
-
247
-
248
-
249
-
250
-
251
-
252
-
253
-
254
-
255
-
256
-
257
-
258
-
259
-
260
-
261
- class Line {
262
-
263
-
264
-
265
-
266
-
267
-
268
-
269
-
270
- static parse(plain ) {
271
- return new Line({
272
- id: plain.id,
273
- extensions: plain.extensions,
274
- endpointCustom: plain.endpoint_custom || null,
275
- endpointSccp: plain.endpoint_sccp || null,
276
- endpointSip: plain.endpoint_sip || null,
277
- });
278
- }
279
-
280
- static newFrom(profile ) {
281
- return newFrom(profile, Line);
282
- }
283
-
284
- is(line ) {
285
- return line ? this.id === line.id : false;
286
- }
287
-
288
- hasExtension(extension ) {
289
- if (!this.extensions) {
290
- return false;
291
- }
292
-
293
- return this.extensions.some(ext => ext.exten === extension);
294
- }
295
-
296
- constructor({ id, extensions, endpointCustom, endpointSccp, endpointSip } = {}) {
297
- this.id = id;
298
- this.extensions = extensions;
299
- this.endpointCustom = endpointCustom || null;
300
- this.endpointSccp = endpointSccp || null;
301
- this.endpointSip = endpointSip || null;
302
-
303
- // Useful to compare instead of instanceof with minified code
304
- this.type = 'Line';
305
- }
306
- }
307
-
308
- //
309
-
310
-
311
-
312
-
313
-
314
-
315
- const FORWARD_KEYS = {
316
- BUSY: 'busy',
317
- NO_ANSWER: 'noanswer',
318
- UNCONDITIONAL: 'unconditional',
319
- };
320
-
321
-
322
-
323
-
324
-
325
-
326
-
327
- class ForwardOption {
328
-
329
-
330
-
331
-
332
- static parse(plain , key ) {
333
- return new ForwardOption({
334
- destination: plain.destination || '',
335
- enabled: plain.enabled,
336
- key,
337
- });
338
- }
339
-
340
- static newFrom(profile ) {
341
- return newFrom(profile, ForwardOption);
342
- }
343
-
344
- constructor({ destination, enabled, key } = {}) {
345
- this.destination = destination;
346
- this.enabled = enabled;
347
- this.key = key;
348
- }
349
-
350
- setDestination(number ) {
351
- this.destination = number;
352
-
353
- return this;
354
- }
355
-
356
- setEnabled(enabled ) {
357
- this.enabled = enabled;
358
-
359
- return this;
360
- }
361
-
362
- is(other ) {
363
- return this.key === other.key;
364
- }
365
- }
366
-
367
- //
368
-
369
-
370
- const availableCodecs = ['vp8', 'vp9', 'h264'];
371
-
372
-
373
-
374
-
375
-
376
-
377
-
378
-
379
-
380
-
381
-
382
-
383
-
384
-
385
-
386
-
387
-
388
-
389
-
390
-
391
-
392
-
393
-
394
-
395
-
396
-
397
-
398
-
399
-
400
-
401
-
402
-
403
- class SipLine {
404
-
405
-
406
-
407
-
408
-
409
-
410
-
411
-
412
-
413
-
414
-
415
-
416
-
417
- static parse(plain ) {
418
- let { username, secret, host } = plain;
419
-
420
- // Since 20.13 engine so options are now in section
421
- if (plain.auth_section_options) {
422
- // $FlowFixMe
423
- const findOption = (options , name ) => options.find(option => option[0] === name);
424
-
425
- const usernameOption = findOption(plain.auth_section_options, 'username');
426
- const secretOption = findOption(plain.auth_section_options, 'password');
427
- const hostOption = findOption(plain.endpoint_section_options, 'media_address');
428
-
429
- username = usernameOption ? usernameOption[1] : '';
430
- secret = secretOption ? secretOption[1] : '';
431
- host = hostOption ? hostOption[1] : '';
432
- }
433
-
434
- return new SipLine({
435
- id: plain.id,
436
- uuid: plain.uuid,
437
- tenantUuid: plain.tenant_uuid,
438
- username,
439
- secret,
440
- type: plain.type,
441
- host,
442
- options: plain.options,
443
- endpointSectionOptions: plain.endpoint_section_options,
444
- links: plain.links,
445
- trunk: plain.trunk,
446
- line: plain.line,
447
- });
448
- }
449
-
450
- static newFrom(sipLine ) {
451
- return newFrom(sipLine, SipLine);
452
- }
453
-
454
- is(line ) {
455
- if (line.uuid) {
456
- return this.uuid === line.uuid;
457
- }
458
- return this.id === line.id;
459
- }
460
-
461
- getOptions() {
462
- // `options` params have beend remove since 20.13... we should now use endpointSectionOptions
463
- return this.endpointSectionOptions || this.options || [];
464
- }
465
-
466
- isWebRtc() {
467
- return this.getOptions().some(option => option[0] === 'webrtc' && option[1] === 'yes');
468
- }
469
-
470
- hasVideo() {
471
- const allow = this.getOptions().find(option => option[0] === 'allow');
472
- return Array.isArray(allow) && allow[1].split(',').some(codec => availableCodecs.some(c => c === codec));
473
- }
474
-
475
- hasVideoConference() {
476
- return (
477
- this.getOptions().some(option => option[0] === 'max_audio_streams' && parseInt(option[1], 10) > 0)
478
- && this.getOptions().some(option => option[0] === 'max_video_streams' && parseInt(option[1], 10) > 1)
479
- );
480
- }
481
-
482
- constructor({
483
- id,
484
- uuid,
485
- tenantUuid,
486
- username,
487
- secret,
488
- type,
489
- host,
490
- options,
491
- endpointSectionOptions,
492
- links,
493
- trunk,
494
- line,
495
- } = {}) {
496
- this.id = id;
497
- this.uuid = uuid;
498
- this.tenantUuid = tenantUuid;
499
- this.username = username;
500
- this.secret = secret;
501
- this.type = type;
502
- this.host = host;
503
- this.options = options;
504
- this.endpointSectionOptions = endpointSectionOptions;
505
- this.links = links;
506
- this.trunk = trunk;
507
- this.line = line;
508
-
509
- // Useful to compare instead of instanceof with minified code
510
- this.type = 'SipLine';
511
- }
512
- }
513
-
514
- //
515
-
516
- const STATE = {
517
- AVAILABLE: 'available',
518
- UNAVAILABLE: 'unavailable',
519
- INVISIBLE: 'invisible',
520
- DISCONNECTED: 'disconnected',
521
- AWAY: 'away',
522
- };
523
-
524
- const LINE_STATE = {
525
- AVAILABLE: 'available',
526
- HOLDING: 'holding',
527
- RINGING: 'ringing',
528
- TALKING: 'talking',
529
- UNAVAILABLE: 'unavailable',
530
- PROGRESSING: 'progressing',
531
- };
532
-
533
-
534
-
535
-
536
-
537
-
538
-
539
-
540
-
541
-
542
-
543
-
544
-
545
-
546
-
547
-
548
-
549
-
550
-
551
-
552
-
553
-
554
-
555
-
556
-
557
-
558
-
559
-
560
-
561
-
562
-
563
-
564
-
565
-
566
-
567
-
568
-
569
-
570
-
571
-
572
-
573
-
574
-
575
-
576
-
577
-
578
-
579
-
580
-
581
-
582
-
583
-
584
-
585
-
586
-
587
-
588
-
589
-
590
-
591
-
592
-
593
-
594
-
595
-
596
-
597
-
598
-
599
-
600
-
601
-
602
-
603
-
604
-
605
-
606
-
607
-
608
-
609
-
610
-
611
-
612
-
613
-
614
-
615
-
616
-
617
-
618
-
619
-
620
-
621
-
622
-
623
- class Profile {
624
-
625
-
626
-
627
-
628
-
629
-
630
-
631
-
632
-
633
-
634
-
635
-
636
-
637
-
638
-
639
-
640
-
641
-
642
-
643
-
644
- static parse(plain ) {
645
- return new Profile({
646
- id: plain.uuid,
647
- firstName: plain.firstName || plain.firstname || '',
648
- lastName: plain.lastName || plain.lastname || '',
649
- email: plain.email,
650
- lines: plain.lines.map(line => Line.parse(line)),
651
- username: plain.username,
652
- mobileNumber: plain.mobile_phone_number || '',
653
- ringSeconds: plain.ring_seconds,
654
- forwards: [
655
- ForwardOption.parse(plain.forwards.unconditional, FORWARD_KEYS.UNCONDITIONAL),
656
- ForwardOption.parse(plain.forwards.noanswer, FORWARD_KEYS.NO_ANSWER),
657
- ForwardOption.parse(plain.forwards.busy, FORWARD_KEYS.BUSY),
658
- ],
659
- doNotDisturb: plain.services.dnd.enabled,
660
- subscriptionType: plain.subscription_type,
661
- voicemail: plain.voicemail,
662
- switchboards: plain.switchboards || [],
663
- agent: plain.agent,
664
- status: '',
665
- callPickupTargetUsers: plain.call_pickup_target_users || [],
666
- onlineCallRecordEnabled: plain.online_call_record_enabled,
667
- });
668
- }
669
-
670
- static newFrom(profile ) {
671
- return newFrom(profile, Profile);
672
- }
673
-
674
- constructor({
675
- id,
676
- firstName,
677
- lastName,
678
- email,
679
- lines,
680
- username,
681
- mobileNumber,
682
- forwards,
683
- doNotDisturb,
684
- state,
685
- subscriptionType,
686
- voicemail,
687
- switchboards,
688
- agent,
689
- status,
690
- ringSeconds,
691
- sipLines,
692
- callPickupTargetUsers,
693
- onlineCallRecordEnabled,
694
- } = {}) {
695
- this.id = id;
696
- this.firstName = firstName;
697
- this.lastName = lastName;
698
- this.email = email;
699
- this.lines = lines;
700
- this.username = username;
701
- this.mobileNumber = mobileNumber;
702
- this.forwards = forwards;
703
- this.doNotDisturb = doNotDisturb;
704
- this.state = state;
705
- this.voicemail = voicemail;
706
- this.subscriptionType = subscriptionType;
707
- this.switchboards = switchboards;
708
- this.agent = agent;
709
- this.status = status;
710
- this.callPickupTargetUsers = callPickupTargetUsers;
711
- this.onlineCallRecordEnabled = onlineCallRecordEnabled;
712
- this.ringSeconds = ringSeconds;
713
-
714
- this.sipLines = sipLines || [];
715
- }
716
-
717
- static getLinesState(lines ) {
718
- let result = LINE_STATE.UNAVAILABLE;
719
-
720
- // eslint-disable-next-line
721
- for (const line of lines) {
722
- if (line.state === LINE_STATE.RINGING) {
723
- result = LINE_STATE.RINGING;
724
- break;
725
- }
726
-
727
- if (line.state === LINE_STATE.TALKING) {
728
- result = LINE_STATE.TALKING;
729
- break;
730
- }
731
-
732
- if (line.state === LINE_STATE.AVAILABLE) {
733
- result = LINE_STATE.AVAILABLE;
734
- }
735
- }
736
-
737
- return result;
738
- }
739
-
740
- hasId(id ) {
741
- return id === this.id;
742
- }
743
-
744
- setMobileNumber(number ) {
745
- this.mobileNumber = number;
746
-
747
- return this;
748
- }
749
-
750
- setForwardOption(forwardOption ) {
751
- const updatedForwardOptions = this.forwards.slice();
752
- const index = updatedForwardOptions.findIndex(forward => forward.is(forwardOption));
753
- updatedForwardOptions.splice(index, 1, forwardOption);
754
-
755
- this.forwards = updatedForwardOptions;
756
-
757
- return this;
758
- }
759
-
760
- setDoNotDisturb(enabled ) {
761
- this.doNotDisturb = enabled;
762
-
763
- return this;
764
- }
765
-
766
- setState(state ) {
767
- this.state = state;
768
-
769
- return this;
770
- }
771
- }
772
-
773
- //
774
-
775
-
776
- const BACKEND = {
777
- OFFICE365: 'office365',
778
- PERSONAL: 'personal',
779
- GOOGLE: 'google',
780
- WAZO: 'wazo',
781
- };
782
-
783
-
784
-
785
-
786
-
787
-
788
-
789
-
790
-
791
-
792
-
793
-
794
-
795
-
796
-
797
-
798
-
799
-
800
-
801
-
802
-
803
-
804
-
805
-
806
-
807
-
808
-
809
-
810
-
811
-
812
-
813
-
814
-
815
-
816
-
817
-
818
-
819
-
820
-
821
-
822
-
823
-
824
-
825
-
826
-
827
-
828
-
829
-
830
-
831
-
832
-
833
-
834
-
835
-
836
-
837
-
838
-
839
-
840
-
841
-
842
-
843
-
844
-
845
-
846
-
847
-
848
-
849
-
850
-
851
-
852
-
853
-
854
-
855
-
856
- // @see: https://github.com/rt2zz/react-native-contacts#example-contact-record
857
-
858
-
859
-
860
-
861
-
862
-
863
-
864
-
865
-
866
-
867
-
868
-
869
-
870
-
871
-
872
-
873
-
874
-
875
-
876
-
877
-
878
-
879
-
880
-
881
-
882
-
883
-
884
-
885
-
886
-
887
-
888
-
889
-
890
-
891
-
892
-
893
-
894
-
895
-
896
-
897
-
898
-
899
-
900
-
901
-
902
-
903
-
904
-
905
-
906
-
907
-
908
-
909
-
910
-
911
-
912
-
913
-
914
-
915
-
916
-
917
-
918
-
919
-
920
-
921
-
922
-
923
-
924
-
925
-
926
-
927
-
928
-
929
-
930
-
931
-
932
-
933
-
934
-
935
-
936
-
937
-
938
-
939
-
940
-
941
-
942
-
943
-
944
-
945
-
946
-
947
-
948
-
949
-
950
-
951
-
952
-
953
-
954
-
955
-
956
-
957
-
958
-
959
-
960
-
961
-
962
-
963
-
964
-
965
-
966
-
967
-
968
-
969
-
970
-
971
-
972
-
973
-
974
-
975
-
976
-
977
-
978
-
979
-
980
-
981
-
982
-
983
-
984
-
985
-
986
-
987
-
988
-
989
-
990
-
991
-
992
-
993
-
994
- const SOURCE_MOBILE = 'mobile';
995
-
996
- class Contact {
997
-
998
-
999
-
1000
-
1001
-
1002
-
1003
-
1004
-
1005
-
1006
-
1007
-
1008
-
1009
-
1010
-
1011
-
1012
-
1013
-
1014
-
1015
-
1016
-
1017
-
1018
-
1019
-
1020
-
1021
-
1022
-
1023
-
1024
-
1025
-
1026
-
1027
-
1028
-
1029
- static merge(oldContacts , newContacts ) {
1030
- return newContacts.map(current => {
1031
- const old = oldContacts.find(contact => contact && contact.is(current));
1032
-
1033
- return old ? current.merge(old) : current;
1034
- });
1035
- }
1036
-
1037
- static sortContacts(a , b ) {
1038
- const aNames = a.separateName();
1039
- const bNames = b.separateName();
1040
- const aLastName = aNames.lastName;
1041
- const bLastName = bNames.lastName;
1042
-
1043
- // last Name can be empty
1044
- if (aLastName === bLastName) {
1045
- return aNames.firstName.localeCompare(bNames.firstName);
1046
- }
1047
-
1048
- return aLastName.localeCompare(bLastName);
1049
- }
1050
-
1051
- static parseMany(response ) {
1052
- if (!response || !response.results) {
1053
- return [];
1054
- }
1055
- return response.results.map(r => Contact.parse(r, response.column_types));
1056
- }
1057
-
1058
- static manyGraphQlWithNumbersParser(numbers ) {
1059
- return (response ) => {
1060
- if (!response.data || !response.data.me || !response.data.me.contacts) {
1061
- return [];
1062
- }
1063
-
1064
- return response.data.me.contacts.edges.map((edge, i) => {
1065
- if (!edge.node) {
1066
- return null;
1067
- }
1068
-
1069
- const { email } = edge.node;
1070
- const name = edge.node.firstname && edge.node.lastname
1071
- ? `${edge.node.firstname || ''} ${edge.node.lastname || ''}` : edge.node.wazoReverse;
1072
-
1073
- return new Contact({
1074
- name,
1075
- number: numbers[i],
1076
- numbers: [{ label: 'primary', number: numbers[i] }],
1077
- backend: edge.node.wazoBackend,
1078
- source: edge.node.wazoSourceName,
1079
- sourceId: edge.node.wazoSourceEntryId || '',
1080
- email: email || '',
1081
- emails: email ? [{ label: 'primary', email }] : [],
1082
- uuid: edge.node.userUuid,
1083
- });
1084
- }).filter(contact => !!contact);
1085
- };
1086
- }
1087
-
1088
- static fetchNumbers(plain , columns ) {
1089
- const numberColumns = columns
1090
- .map((e, index) => ({ index, columnName: e }))
1091
- .filter(e => e.columnName === 'number' || e.columnName === 'callable')
1092
- .map(e => e.index);
1093
-
1094
- return plain.column_values.filter((e, index) => numberColumns.some(i => i === index) && e !== null);
1095
- }
1096
-
1097
- static parse(plain , columns ) {
1098
- const numbers = Contact.fetchNumbers(plain, columns);
1099
- const email = plain.column_values[columns.indexOf('email')];
1100
-
1101
- return new Contact({
1102
- name: plain.column_values[columns.indexOf('name')],
1103
- number: numbers.length ? numbers[0] : '',
1104
- numbers: numbers.map((number, i) => ({ label: i === 0 ? 'primary' : 'secondary', number })),
1105
- favorited: plain.column_values[columns.indexOf('favorite')],
1106
- email: email || '',
1107
- emails: email ? [{ label: 'primary', email }] : [],
1108
- entreprise: plain.column_values[columns.indexOf('entreprise')] || '',
1109
- birthday: plain.column_values[columns.indexOf('birthday')] || '',
1110
- address: plain.column_values[columns.indexOf('address')] || '',
1111
- note: plain.column_values[columns.indexOf('note')] || '',
1112
- endpointId: plain.relations.endpoint_id,
1113
- personal: plain.column_values[columns.indexOf('personal')],
1114
- source: plain.source,
1115
- sourceId: plain.relations.source_entry_id || '',
1116
- uuid: plain.relations.user_uuid,
1117
- backend: plain.backend || '',
1118
- });
1119
- }
1120
-
1121
- static parseManyPersonal(results ) {
1122
- return results.map(r => Contact.parsePersonal(r));
1123
- }
1124
-
1125
- static parsePersonal(plain ) {
1126
- return new Contact({
1127
- name: `${plain.firstName || plain.firstname || ''} ${plain.lastName || plain.lastname || ''}`,
1128
- number: plain.number || '',
1129
- numbers: plain.number ? [{ label: 'primary', number: plain.number }] : [],
1130
- email: plain.email || '',
1131
- emails: plain.email ? [{ label: 'primary', email: plain.email }] : [],
1132
- source: 'personal',
1133
- sourceId: plain.id || '',
1134
- entreprise: plain.entreprise || '',
1135
- birthday: plain.birthday || '',
1136
- address: plain.address || '',
1137
- note: plain.note || '',
1138
- favorited: plain.favorited,
1139
- personal: true,
1140
- backend: plain.backend || BACKEND.PERSONAL,
1141
- });
1142
- }
1143
-
1144
- static parseMobile(plain ) {
1145
- let address = '';
1146
- if (plain.postalAddresses.length) {
1147
- const postalAddress = plain.postalAddresses[0];
1148
-
1149
- address = `${postalAddress.street} ${postalAddress.city} ${postalAddress.postCode} ${postalAddress.country}`;
1150
- }
1151
-
1152
- return new Contact({
1153
- name: `${plain.givenName || ''} ${plain.familyName || ''}`,
1154
- number: plain.phoneNumbers.length ? plain.phoneNumbers[0].number : '',
1155
- numbers: plain.phoneNumbers.length ? [{ label: 'primary', number: plain.phoneNumbers[0].number }] : [],
1156
- email: plain.emailAddresses.length ? plain.emailAddresses[0].email : '',
1157
- emails: plain.emailAddresses.length ? [{ label: 'primary', email: plain.emailAddresses[0].email }] : [],
1158
- source: SOURCE_MOBILE,
1159
- sourceId: plain.recordID || '',
1160
- birthday: plain.birthday ? `${plain.birthday.year}-${plain.birthday.month}-${plain.birthday.day}` : '',
1161
- address,
1162
- note: plain.note || '',
1163
- favorited: false,
1164
- personal: true,
1165
- });
1166
- }
1167
-
1168
- static parseManyOffice365(response , source ) {
1169
- return response.map(r => Contact.parseOffice365(r, source));
1170
- }
1171
-
1172
- static parseOffice365(single , source ) {
1173
- const emails = [];
1174
- const numbers = [];
1175
-
1176
- if (single.emailAddresses) {
1177
- single.emailAddresses.map(email => emails.push({ email: email.address }));
1178
- }
1179
-
1180
- if (single.businessPhones) {
1181
- single.businessPhones.map(phone => numbers.push({ label: 'business', number: phone }));
1182
- }
1183
-
1184
- if (single.mobilePhone) {
1185
- numbers.push({ label: 'mobile', number: single.mobilePhone });
1186
- }
1187
-
1188
- if (single.homePhones) {
1189
- single.homePhones.map(phone => numbers.push({ label: 'home', number: phone }));
1190
- }
1191
-
1192
- return new Contact({
1193
- sourceId: single.id || '',
1194
- name: single.displayName || '',
1195
- number: numbers.length ? numbers[0].number : '',
1196
- numbers,
1197
- emails,
1198
- source: source.name,
1199
- backend: BACKEND.OFFICE365,
1200
- });
1201
- }
1202
-
1203
- static parseManyGoogle(response , source ) {
1204
- return response.map(r => Contact.parseGoogle(r, source));
1205
- }
1206
-
1207
- static parseGoogle(single , source ) {
1208
- const emails = [];
1209
- const numbers = [];
1210
-
1211
- if (single.emails) {
1212
- single.emails.forEach(email =>
1213
- (typeof email === 'object' ? { email: email.address, label: email.label } : { email }));
1214
- }
1215
-
1216
- if (single.numbers_by_label) {
1217
- Object.keys(single.numbers_by_label).forEach(label =>
1218
- numbers.push({ label, number: single.numbers_by_label[label] }));
1219
- } else if (single.numbers) {
1220
- single.numbers.forEach(phone => numbers.push({ number: phone }));
1221
- }
1222
-
1223
- return new Contact({
1224
- sourceId: single.id || '',
1225
- name: single.name || '',
1226
- number: numbers.length ? numbers[0].number : '',
1227
- numbers,
1228
- emails,
1229
- source: source.name,
1230
- backend: BACKEND.GOOGLE,
1231
- });
1232
- }
1233
-
1234
- static parseManyWazo(response , source ) {
1235
- return response.map(r => Contact.parseWazo(r, source));
1236
- }
1237
-
1238
- static parseWazo(single , source ) {
1239
- const emails = [];
1240
- const numbers = [];
1241
-
1242
- if (single.email) {
1243
- emails.push({ label: 'email', email: single.email });
1244
- }
1245
-
1246
- if (single.exten) {
1247
- numbers.push({ label: 'exten', number: single.exten });
1248
- }
1249
-
1250
- if (single.mobile_phone_number) {
1251
- numbers.push({ label: 'mobile', number: single.mobile_phone_number });
1252
- }
1253
-
1254
- return new Contact({
1255
- uuid: single.uuid,
1256
- sourceId: String(single.id) || '',
1257
- name: `${single.firstname}${single.lastname ? ` ${single.lastname}` : ''}`,
1258
- number: numbers.length ? numbers[0].number : '',
1259
- numbers,
1260
- emails,
1261
- source: source.name,
1262
- backend: BACKEND.WAZO,
1263
- });
1264
- }
1265
-
1266
- static parseManyConference(response , source ) {
1267
- return response.map(r => Contact.parseConference(r, source));
1268
- }
1269
-
1270
- static parseConference(single , source ) {
1271
- const numbers = [];
1272
- let firstNumber = '';
1273
-
1274
- if (single && single.extensions && single.extensions.length > 0 && single.extensions[0].exten) {
1275
- firstNumber = single.extensions[0].exten;
1276
- numbers.push({ label: 'exten', number: firstNumber });
1277
- }
1278
-
1279
- return new Contact({
1280
- sourceId: String(single.id),
1281
- name: single.name,
1282
- number: firstNumber,
1283
- numbers,
1284
- source: source.name,
1285
- backend: 'conference',
1286
- });
1287
- }
1288
-
1289
- static newFrom(contact ) {
1290
- return newFrom(contact, Contact);
1291
- }
1292
-
1293
- constructor({
1294
- id,
1295
- uuid,
1296
- name,
1297
- number,
1298
- numbers,
1299
- email,
1300
- emails,
1301
- source,
1302
- sourceId,
1303
- entreprise,
1304
- birthday,
1305
- address,
1306
- note,
1307
- state,
1308
- lineState,
1309
- lastActivity,
1310
- mobile,
1311
- status,
1312
- endpointId,
1313
- personal,
1314
- favorited,
1315
- backend,
1316
- personalStatus,
1317
- sessions,
1318
- connected,
1319
- doNotDisturb,
1320
- ringing,
1321
- previousPresential,
1322
- lines,
1323
- } = {}) {
1324
- this.id = id;
1325
- this.uuid = uuid;
1326
- this.name = name || '';
1327
- this.number = number;
1328
- this.numbers = numbers;
1329
- this.email = email;
1330
- this.emails = emails;
1331
- this.source = source;
1332
- this.sourceId = sourceId;
1333
- this.entreprise = entreprise;
1334
- this.birthday = birthday;
1335
- this.address = address;
1336
- this.note = note;
1337
- this.state = state;
1338
- this.lineState = lineState;
1339
- this.lastActivity = lastActivity;
1340
- this.mobile = mobile;
1341
- this.status = status;
1342
- this.endpointId = endpointId;
1343
- this.personal = personal;
1344
- this.favorited = favorited;
1345
- this.backend = backend;
1346
- this.personalStatus = personalStatus || '';
1347
- this.sessions = sessions || [];
1348
- this.connected = connected;
1349
- this.doNotDisturb = doNotDisturb;
1350
- this.ringing = ringing;
1351
- this.previousPresential = previousPresential;
1352
- this.lines = lines || [];
1353
-
1354
- // Useful to compare instead of instanceof with minified code
1355
- this.type = 'Contact';
1356
- }
1357
-
1358
- setFavorite(value ) {
1359
- this.favorited = value;
1360
-
1361
- return this;
1362
- }
1363
-
1364
- is(other ) {
1365
- const sameSourceId = this.sourceId !== null && other.sourceId !== null && this.sourceId === other.sourceId;
1366
- const sameUuid = !!this.uuid && !!other.uuid && this.uuid === other.uuid;
1367
-
1368
- const hasSameId = sameSourceId || sameUuid;
1369
- const hasSameBackend = !!this.backend && !!other.backend && this.backend === other.backend;
1370
- const hasSameSource = !!this.source && !!other.source && this.source === other.source;
1371
-
1372
- return !!other && hasSameId && hasSameBackend && hasSameSource;
1373
- }
1374
-
1375
- hasId(id ) {
1376
- return this.uuid === id;
1377
- }
1378
-
1379
- hasNumber(number ) {
1380
- return this.number === number;
1381
- }
1382
-
1383
- hasEndpointId(endpointId ) {
1384
- return this.endpointId === endpointId;
1385
- }
1386
-
1387
- isAvailable() {
1388
- return this.state === STATE.AVAILABLE;
1389
- }
1390
-
1391
- isAway() {
1392
- return this.state === STATE.AWAY;
1393
- }
1394
-
1395
- isUnavailable() {
1396
- return this.state === STATE.UNAVAILABLE;
1397
- }
1398
-
1399
- isInvisible() {
1400
- return this.state === STATE.INVISIBLE;
1401
- }
1402
-
1403
- isInCall() {
1404
- return this.lineState === LINE_STATE.TALKING || this.lineState === LINE_STATE.HOLDING;
1405
- }
1406
-
1407
- isRinging() {
1408
- return this.ringing;
1409
- }
1410
-
1411
- isInUseOrRinging() {
1412
- return this.lineState === LINE_STATE.TALKING || this.lineState === LINE_STATE.RINGING;
1413
- }
1414
-
1415
- isProgressing() {
1416
- return this.lineState === LINE_STATE.PROGRESSING;
1417
- }
1418
-
1419
- merge(old ) {
1420
- Object.keys(old).filter(key => key !== 'lineState').forEach(key => {
1421
- // $FlowFixMe
1422
- this[key] = old[key] || this[key];
1423
- });
1424
-
1425
- if (old.lineState) {
1426
- this.lineState = old.lineState;
1427
- }
1428
-
1429
- return this;
1430
- }
1431
-
1432
- isIntern() {
1433
- return !!this.uuid;
1434
- }
1435
-
1436
- hasSourceId() {
1437
- return !!this.sourceId;
1438
- }
1439
-
1440
- isCallable(session ) {
1441
- return !!this.number && !!session && !session.is(this);
1442
- }
1443
-
1444
- isFromMobile() {
1445
- return this.source === SOURCE_MOBILE;
1446
- }
1447
-
1448
- isFavorite() {
1449
- return this.favorited;
1450
- }
1451
-
1452
- separateName() {
1453
- if (!this.name) {
1454
- return {
1455
- firstName: '',
1456
- lastName: '',
1457
- };
1458
- }
1459
- const names = this.name.split(/\s+/);
1460
- const firstName = names[0];
1461
- const lastName = names.slice(1).join(' ');
1462
-
1463
- return {
1464
- firstName,
1465
- lastName,
1466
- };
1467
- }
1468
- }
1469
-
1470
- // Can't use `semver` package as Wazo version aren't in semver format
1471
-
1472
- const compareVersions = (a, b) => {
1473
- let i;
1474
- let diff;
1475
- const regExStrip0 = /(\.0+)+$/;
1476
- const segmentsA = a.replace(regExStrip0, '').split('.');
1477
- const segmentsB = b.replace(regExStrip0, '').split('.');
1478
- const l = Math.min(segmentsA.length, segmentsB.length);
1479
-
1480
- for (i = 0; i < l; i++) {
1481
- diff = parseInt(segmentsA[i], 10) - parseInt(segmentsB[i], 10);
1482
- if (diff) {
1483
- return diff;
1484
- }
1485
- }
1486
- return segmentsA.length - segmentsB.length;
1487
- };
1488
-
1489
- //
1490
-
1491
- const swarmKey = KEYUTIL.getKey(swarmPublicKey);
1492
- const MINIMUM_WAZO_ENGINE_VERSION_FOR_DEFAULT_CONTEXT = '19.08';
1493
-
1494
-
1495
-
1496
-
1497
-
1498
-
1499
-
1500
-
1501
-
1502
-
1503
-
1504
-
1505
-
1506
-
1507
-
1508
-
1509
-
1510
-
1511
-
1512
-
1513
-
1514
-
1515
-
1516
-
1517
-
1518
-
1519
-
1520
-
1521
-
1522
-
1523
-
1524
-
1525
-
1526
-
1527
-
1528
-
1529
-
1530
-
1531
-
1532
-
1533
-
1534
-
1535
-
1536
-
1537
-
1538
-
1539
-
1540
-
1541
-
1542
- class Session {
1543
-
1544
-
1545
-
1546
-
1547
-
1548
-
1549
-
1550
-
1551
-
1552
-
1553
-
1554
-
1555
- static parse(plain ) {
1556
- const token = plain.data.metadata ? plain.data.metadata.jwt : null;
1557
- let authorizations = [];
1558
-
1559
- // Add authorizations from JWT
1560
- if (token) {
1561
- const isValid = jws.JWS.verifyJWT(token, swarmKey, { alg: ['RS256'], verifyAt: new Date() });
1562
- if (isValid) {
1563
- const decodedToken = jws.JWS.readSafeJSONString(b64utoutf8(token.split('.')[1]));
1564
- authorizations = decodedToken ? decodedToken.authorizations : [];
1565
- }
7
+ static async fetchDistinctCallLogs(offset, limit, distinct = 'peer_exten') {
8
+ return getApiClient().callLogd.listDistinctCallLogs(offset, limit, distinct);
1566
9
  }
1567
-
1568
- return new Session({
1569
- token: plain.data.token,
1570
- refreshToken: plain.data.refresh_token || null,
1571
- uuid: plain.data.metadata ? plain.data.metadata.uuid : null,
1572
- sessionUuid: plain.data.session_uuid,
1573
- authorizations,
1574
- acl: plain.data.acls ? plain.data.acls : plain.data.acl ? plain.data.acl : [],
1575
- tenantUuid: plain.data.metadata ? plain.data.metadata.tenant_uuid : undefined,
1576
- expiresAt: new Date(`${plain.data.utc_expires_at}z`),
1577
- engineUuid: plain.data.xivo_uuid,
1578
- });
1579
- }
1580
-
1581
- static newFrom(profile ) {
1582
- return newFrom(profile, Session);
1583
- }
1584
-
1585
- constructor({
1586
- token,
1587
- uuid,
1588
- tenantUuid,
1589
- profile,
1590
- expiresAt,
1591
- authorizations,
1592
- acl,
1593
- engineVersion,
1594
- refreshToken,
1595
- sessionUuid,
1596
- engineUuid,
1597
- } = {}) {
1598
- this.token = token;
1599
- this.uuid = uuid;
1600
- this.tenantUuid = tenantUuid || null;
1601
- this.profile = profile;
1602
- this.expiresAt = expiresAt;
1603
- this.authorizations = authorizations || [];
1604
- this.acl = acl || [];
1605
- this.engineVersion = engineVersion;
1606
- this.refreshToken = refreshToken;
1607
- this.sessionUuid = sessionUuid;
1608
- this.engineUuid = engineUuid;
1609
- }
1610
-
1611
- hasExpired(date = new Date()) {
1612
- return date >= this.expiresAt;
1613
- }
1614
-
1615
- is(contact ) {
1616
- return Boolean(contact) && this.uuid === contact.uuid;
1617
- }
1618
-
1619
- using(profile ) {
1620
- this.profile = profile;
1621
-
1622
- return this;
1623
- }
1624
-
1625
- hasAuthorizations() {
1626
- return this.authorizations && !!this.authorizations.length;
1627
- }
1628
-
1629
- displayName() {
1630
- return this.profile ? `${this.profile.firstName} ${this.profile.lastName}` : '';
1631
- }
1632
-
1633
- hasAccessToVoicemail() {
1634
- if (!this.profile) {
1635
- return false;
10
+ static async fetchActiveCalls() {
11
+ return getApiClient().calld.listCalls();
1636
12
  }
1637
- return !!this.profile.voicemail;
1638
- }
1639
-
1640
- primaryLine() {
1641
- return this.profile && this.profile.lines.length > 0 ? this.profile.lines[0] : null;
1642
- }
1643
-
1644
- primarySipLine() {
1645
- return this.profile && this.profile.sipLines.length > 0 ? this.profile.sipLines[0] : null;
1646
- }
1647
-
1648
- primaryWebRtcLine() {
1649
- return this.profile && (this.profile.sipLines || []).find(sipLine => sipLine && sipLine.isWebRtc());
1650
- }
1651
-
1652
- primaryCtiLine() {
1653
- return this.profile && (this.profile.sipLines || []).find(sipLine => sipLine && !sipLine.isWebRtc());
1654
- }
1655
-
1656
- primaryContext() {
1657
- if (this.engineVersion) {
1658
- if (this.hasEngineVersionGte(MINIMUM_WAZO_ENGINE_VERSION_FOR_DEFAULT_CONTEXT)) {
1659
- return 'default';
1660
- }
13
+ static async fetchCallLogsFromDate(from, number) {
14
+ return getApiClient().callLogd.listCallLogsFromDate(from, number);
1661
15
  }
1662
-
1663
- const line = this.primaryLine();
1664
-
1665
- return line && line.extensions.length > 0 ? line.extensions[0].context : 'default';
1666
- }
1667
-
1668
- hasEngineVersionGte(version ) {
1669
- return this.engineVersion && compareVersions(String(this.engineVersion), String(version)) >= 0;
1670
- }
1671
-
1672
- primaryNumber() {
1673
- const line = this.primaryLine();
1674
-
1675
- return line && line.extensions.length ? line.extensions[0].exten : null;
1676
- }
1677
-
1678
- allLines() {
1679
- return this.profile ? this.profile.lines || [] : [];
1680
- }
1681
-
1682
- allNumbers() {
1683
- const extensions = this.allLines().map(line => line.extensions.map(extension => extension.exten));
1684
- if (!extensions.length) {
1685
- return [];
16
+ static async search(query, limit) {
17
+ return getApiClient().callLogd.search(query, limit);
1686
18
  }
1687
-
1688
- return extensions.reduce((a, b) => a.concat(b));
1689
- }
1690
-
1691
- hasExtension(extension ) {
1692
- return this.allNumbers().some(number => number === extension);
1693
- }
1694
-
1695
- get acls() {
1696
- console.warn('`acls` property of Session has been removed in Wazo\'s SDK, please use `acl` instead.');
1697
- return this.acl;
1698
- }
1699
- }
1700
-
1701
- //
1702
-
1703
-
1704
-
1705
-
1706
-
1707
-
1708
-
1709
-
1710
-
1711
-
1712
-
1713
-
1714
-
1715
-
1716
-
1717
-
1718
-
1719
- class Recording {
1720
-
1721
-
1722
-
1723
-
1724
-
1725
-
1726
- static parseMany(recordings = []) {
1727
- if (!recordings) {
1728
- return [];
1729
- }
1730
- return recordings.map(item => Recording.parse(item));
1731
- }
1732
-
1733
- static parse(plain ) {
1734
- return new Recording({
1735
- deleted: plain.deleted,
1736
- fileName: plain.filename,
1737
- end: plain.end_time ? moment(plain.end_time).toDate() : null,
1738
- start: moment(plain.start_time).toDate(),
1739
- uuid: plain.uuid,
1740
- });
1741
- }
1742
-
1743
- constructor({ deleted, end, fileName, start, uuid } ) {
1744
- this.deleted = deleted;
1745
- this.end = end;
1746
- this.fileName = fileName;
1747
- this.start = start;
1748
- this.uuid = uuid;
1749
- }
1750
- }
1751
-
1752
- //
1753
-
1754
-
1755
-
1756
-
1757
-
1758
-
1759
-
1760
-
1761
-
1762
-
1763
-
1764
-
1765
-
1766
-
1767
-
1768
-
1769
-
1770
-
1771
-
1772
-
1773
-
1774
-
1775
-
1776
-
1777
-
1778
-
1779
-
1780
-
1781
-
1782
-
1783
-
1784
-
1785
-
1786
-
1787
-
1788
-
1789
-
1790
-
1791
-
1792
-
1793
-
1794
-
1795
-
1796
-
1797
-
1798
-
1799
-
1800
-
1801
- class CallLog {
1802
-
1803
-
1804
-
1805
-
1806
-
1807
-
1808
-
1809
-
1810
-
1811
-
1812
-
1813
-
1814
-
1815
-
1816
-
1817
-
1818
-
1819
-
1820
-
1821
-
1822
-
1823
-
1824
-
1825
- static merge(current , toMerge ) {
1826
- const onlyUnique = (value, index, self) => self.indexOf(value) === index;
1827
-
1828
- const allLogs = current.concat(toMerge);
1829
- const onlyUniqueIds = allLogs.map(c => c.id).filter(onlyUnique);
1830
-
1831
- return onlyUniqueIds.map(id => allLogs.find(log => log && log.id === id));
1832
- }
1833
-
1834
- static parseMany(plain ) {
1835
- if (!plain || !plain.items) {
1836
- return [];
1837
- }
1838
-
1839
- return plain.items.map(item => CallLog.parse(item));
1840
- }
1841
-
1842
- static parse(plain ) {
1843
- return new CallLog({
1844
- answer: plain.answer ? moment(plain.answer).toDate() : null,
1845
- answered: plain.answered,
1846
- callDirection: plain.call_direction,
1847
- destination: {
1848
- // @TEMP: Temporarily assuming empty numbers are meetings
1849
- // which is admittedly a very dangerous assumption. Did i mention it was temporary?
1850
- extension: plain.requested_extension
1851
- || plain.destination_extension
1852
- || `meeting-${plain.requested_name || plain.destination_name || ''}`,
1853
- name: plain.requested_name || plain.destination_name || '',
1854
- uuid: plain.destination_user_uuid,
1855
- },
1856
- source: {
1857
- extension: plain.source_extension,
1858
- name: plain.source_name,
1859
- uuid: plain.source_user_uuid,
1860
- },
1861
- id: plain.id,
1862
- duration: (plain.duration || 0) * 1000, // duration is in seconds
1863
- start: moment(plain.start).toDate(),
1864
- end: plain.end ? moment(plain.end).toDate() : null,
1865
- recordings: Recording.parseMany(plain.recordings || []),
1866
- });
1867
- }
1868
-
1869
- static parseNew(plain , session ) {
1870
- const callLog = CallLog.parse(plain);
1871
- // @TODO: FIXME add verification declined vs missed call
1872
- callLog.newMissedCall = session
1873
- && session.hasExtension(plain.requested_extension || plain.destination_extension) && !plain.answered;
1874
- return callLog;
1875
- }
1876
-
1877
- static newFrom(profile ) {
1878
- return newFrom(profile, CallLog);
1879
- }
1880
-
1881
- constructor({
1882
- answer,
1883
- answered,
1884
- callDirection,
1885
- destination,
1886
- source,
1887
- id,
1888
- duration,
1889
- start,
1890
- end,
1891
- recordings,
1892
- } = {}) {
1893
- this.answer = answer;
1894
- this.answered = answered;
1895
- this.callDirection = callDirection;
1896
- this.destination = destination;
1897
- this.source = source;
1898
- this.id = id;
1899
- this.duration = duration;
1900
- this.start = start;
1901
- this.end = end;
1902
- this.recordings = recordings || [];
1903
-
1904
- // Useful to compare instead of instanceof with minified code
1905
- this.type = 'CallLog';
1906
- }
1907
-
1908
- isFromSameParty(other , session ) {
1909
- return this.theOtherParty(session).extension === other.theOtherParty(session).extension;
1910
- }
1911
-
1912
- theOtherParty(session ) {
1913
- if (this.callDirection === 'inbound') {
1914
- return this.source;
1915
- }
1916
-
1917
- if (this.callDirection === 'outbound') {
1918
- return this.destination;
1919
- }
1920
-
1921
- return session && session.hasExtension(this.source.extension) ? this.destination : this.source;
1922
- }
1923
-
1924
- isNewMissedCall() {
1925
- return this.newMissedCall;
1926
- }
1927
-
1928
- acknowledgeCall() {
1929
- this.newMissedCall = false;
1930
-
1931
- return this;
1932
- }
1933
-
1934
- isAcknowledged() {
1935
- return this.newMissedCall;
1936
- }
1937
-
1938
- isAnswered() {
1939
- return this.answered;
1940
- }
1941
-
1942
- isOutgoing(session ) {
1943
- if (this.callDirection === 'internal') {
1944
- return session.hasExtension(this.source.extension);
1945
- }
1946
-
1947
- return this.callDirection === 'outbound';
1948
- }
1949
-
1950
- isIncoming(session ) {
1951
- if (this.callDirection === 'internal') {
1952
- return session.hasExtension(this.destination.extension);
1953
- }
1954
-
1955
- return this.callDirection === 'inbound';
1956
- }
1957
-
1958
- isAnOutgoingCall(session ) {
1959
- console.warn(`@wazo/sdk
1960
- CallLog.isAnOutgoingcall(session) method is obsolete.
1961
- Please use CallLog.isOutgoing(session).
1962
- `);
1963
-
1964
- return session.hasExtension(this.source.extension) && this.answered;
1965
- }
1966
-
1967
- isAMissedOutgoingCall(session ) {
1968
- return session.hasExtension(this.source.extension) && !this.answered;
1969
- }
1970
-
1971
- isAnIncomingCall(session ) {
1972
- console.warn(`@wazo/sdk
1973
- CallLog.isAnIncomingCall(session) method is obsolete.
1974
- Please use CallLog.isIncoming(session).
1975
- `);
1976
-
1977
- return session.hasExtension(this.destination.extension) && this.answered;
1978
- }
1979
-
1980
- isADeclinedCall(session ) {
1981
- return !this.answered && session.hasExtension(this.destination.extension);
1982
- }
1983
-
1984
- getRecordings() {
1985
- return this.recordings;
1986
- }
1987
- }
1988
-
1989
- //
1990
-
1991
-
1992
-
1993
-
1994
-
1995
-
1996
-
1997
-
1998
-
1999
-
2000
-
2001
-
2002
-
2003
-
2004
-
2005
-
2006
- class Relocation {
2007
-
2008
-
2009
-
2010
-
2011
-
2012
-
2013
-
2014
-
2015
- static parse(response ) {
2016
- return new Relocation({
2017
- initiatorCall: response.initiator_call,
2018
- recipientCall: response.recipient_call,
2019
- relocatedCall: response.relocated_call,
2020
- });
2021
- }
2022
-
2023
- constructor({ relocatedCall, initiatorCall, recipientCall } ) {
2024
- this.initiatorCall = initiatorCall || '';
2025
- this.relocatedCall = relocatedCall || '';
2026
- this.recipientCall = recipientCall || '';
2027
- }
2028
- }
2029
-
2030
- Relocation.MIN_ENGINE_VERSION_REQUIRED = '19.09';
2031
-
2032
- //
2033
- /* eslint-disable no-param-reassign */
2034
-
2035
- var updateFrom = (instance , from ) => {
2036
- Object.keys(from).forEach(key => {
2037
- // $FlowFixMe
2038
- if (
2039
- (!instance[key] && from[key])
2040
- || (typeof instance[key] !== 'undefined' && typeof from[key] !== 'undefined' && instance[key] !== from[key])
2041
- ) {
2042
- // $FlowFixMe
2043
- instance[key] = from[key];
2044
- }
2045
- });
2046
- };
2047
-
2048
- /* */
2049
-
2050
- class BadResponse extends Error {
2051
- static fromResponse(error , status ) {
2052
- return new BadResponse(
2053
- error.message || JSON.stringify(error),
2054
- status,
2055
- error.timestamp,
2056
- error.error_id,
2057
- error.details,
2058
- error,
2059
- );
2060
- }
2061
-
2062
- static fromText(response , status ) {
2063
- return new BadResponse(response, status);
2064
- }
2065
-
2066
-
2067
-
2068
-
2069
-
2070
-
2071
-
2072
-
2073
- constructor(
2074
- message ,
2075
- status ,
2076
- timestamp = null,
2077
- errorId = null,
2078
- details = null,
2079
- error = null,
2080
- ) {
2081
- super(message);
2082
-
2083
- this.timestamp = timestamp;
2084
- this.status = status;
2085
- this.errorId = errorId;
2086
- this.details = details;
2087
- this.error = error;
2088
- }
2089
- }
2090
-
2091
- /* */
2092
-
2093
- class ServerError extends BadResponse {
2094
- static fromResponse(error , status ) {
2095
- return new ServerError(
2096
- error.message || JSON.stringify(error),
2097
- status,
2098
- error.timestamp,
2099
- error.error_id,
2100
- error.details,
2101
- );
2102
- }
2103
-
2104
- static fromText(response , status ) {
2105
- return new ServerError(response, status);
2106
- }
2107
- }
2108
-
2109
- /* */
2110
- /* global navigator */
2111
- const isMobile = () => typeof navigator !== 'undefined' && navigator.product === 'ReactNative';
2112
-
2113
- /* global window */
2114
-
2115
- const TRACE = 'trace';
2116
- const DEBUG = 'debug';
2117
- const INFO = 'info';
2118
- const LOG = 'log';
2119
- const WARN = 'warn';
2120
- const ERROR = 'error';
2121
- const CONSOLE_METHODS = [INFO, LOG, WARN, ERROR];
2122
- const LOG_LEVELS = [TRACE, DEBUG, INFO, LOG, WARN, ERROR];
2123
- const CATEGORY_PREFIX = 'logger-category=';
2124
-
2125
- const MAX_REMOTE_RETRY = 100;
2126
-
2127
- const addLevelsTo = (instance , withMethods = false) => {
2128
- instance.TRACE = TRACE;
2129
- instance.DEBUG = DEBUG;
2130
- instance.INFO = INFO;
2131
- instance.LOG = LOG;
2132
- instance.WARN = WARN;
2133
- instance.ERROR = ERROR;
2134
-
2135
- if (withMethods) {
2136
- instance.trace = (...args) => instance.apply(null, [TRACE, ...args]);
2137
- instance.debug = (...args) => instance.apply(null, [DEBUG, ...args]);
2138
- instance.info = (...args) => instance.apply(null, [INFO, ...args]);
2139
- instance.log = (...args) => instance.apply(null, [LOG, ...args]);
2140
- instance.warn = (...args) => instance.apply(null, [WARN, ...args]);
2141
- instance.error = (...args) => instance.apply(null, [ERROR, ...args]);
2142
- }
2143
-
2144
- return instance;
2145
- };
2146
-
2147
- const safeStringify = (object ) => {
2148
- const result = '{"message": "Not parsable JSON"}';
2149
- try {
2150
- return JSON.stringify(object);
2151
- } catch (e) {
2152
- // Nothing to do
2153
- }
2154
-
2155
- return result;
2156
- };
2157
-
2158
- class IssueReporter {
2159
-
2160
-
2161
-
2162
-
2163
-
2164
-
2165
-
2166
-
2167
-
2168
-
2169
-
2170
-
2171
-
2172
-
2173
-
2174
-
2175
- constructor() {
2176
- addLevelsTo(this);
2177
-
2178
- this.oldConsoleMethods = null;
2179
- this.enabled = false;
2180
- this.remoteClientConfiguration = null;
2181
- this.buffer = [];
2182
- this.bufferTimeout = null;
2183
- this._boundProcessBuffer = this._processBuffer.bind(this);
2184
- this._boundParseLoggerBody = this._parseLoggerBody.bind(this);
2185
- this._callback = null;
2186
- }
2187
-
2188
- init() {
2189
- this._catchConsole();
2190
- }
2191
-
2192
- setCallback(cb ) {
2193
- this._callback = cb;
2194
- }
2195
-
2196
- configureRemoteClient(configuration = { tag: 'wazo-sdk', host: null, port: null, level: null, extra: {} }) {
2197
- this.remoteClientConfiguration = configuration;
2198
- }
2199
-
2200
- enable() {
2201
- if (!this.oldConsoleMethods) {
2202
- this.init();
19
+ static async searchBy(field, value, limit) {
20
+ return getApiClient().callLogd.searchBy(field, value, limit);
2203
21
  }
2204
-
2205
- this.enabled = true;
2206
- }
2207
-
2208
- disable() {
2209
- this.enabled = false;
2210
- }
2211
-
2212
- loggerFor(category ) {
2213
- const logger = (level , ...args ) => {
2214
- this.log.apply(this, [level, this._makeCategory(category), ...args]);
2215
- };
2216
-
2217
- return addLevelsTo(logger, true);
2218
- }
2219
-
2220
- removeSlashes(str ) {
2221
- return str.replace(/"/g, "'").replace(/\\/g, '');
2222
- }
2223
-
2224
- log(level , ...args ) {
2225
- if (!this.enabled) {
2226
- return;
22
+ static async fetchSIP(session, line) {
23
+ const lineToUse = line || session.primaryLine();
24
+ return getApiClient().confd.getUserLineSip(session.uuid, lineToUse ? lineToUse.id : '');
2227
25
  }
2228
-
2229
- // Handle category label
2230
- let category = null;
2231
- let skipSendToRemote = false;
2232
- let extra = {};
2233
- if (args[0].indexOf(CATEGORY_PREFIX) === 0) {
2234
- category = args[0].split('=')[1];
2235
- // eslint-disable-next-line no-param-reassign
2236
- args.splice(0, 1);
26
+ static async cancelCall(callSession) {
27
+ return getApiClient().calld.cancelCall(callSession.callId);
2237
28
  }
2238
-
2239
- // Handle extra data as object for the last argument
2240
- const lastArg = args[args.length - 1];
2241
- if (lastArg && ((typeof lastArg === 'object' && Object.keys(lastArg).length) || lastArg instanceof Error)) {
2242
- if (lastArg instanceof Error) {
2243
- extra = {
2244
- errorMessage: lastArg.message,
2245
- errorStack: lastArg.stack,
2246
- errorType: lastArg.constructor.name,
2247
- skipSendToRemote: lastArg.skipSendToRemote,
2248
- };
2249
- } else {
2250
- extra = lastArg;
2251
- }
2252
- // eslint-disable-next-line no-param-reassign
2253
- args.splice(1, 1);
29
+ static async makeCall(callFromLine, extension, isMobile = false, callbackAllLines = false) {
30
+ const lineId = callFromLine ? callFromLine.id : null;
31
+ const response = await getApiClient().calld.makeCall(extension, isMobile, lineId, callbackAllLines);
32
+ return Call.parse(response);
2254
33
  }
2255
-
2256
- if (extra.skipSendToRemote) {
2257
- skipSendToRemote = true;
2258
- delete extra.skipSendToRemote;
34
+ static async relocateCall(callId, line, contactIdentifier) {
35
+ return getApiClient().calld.relocateCall(callId, 'line', line, contactIdentifier);
2259
36
  }
2260
-
2261
- const date = moment().format('YYYY-MM-DD HH:mm:ss.SSS');
2262
- const message = args.join(', ');
2263
- let consoleMessage = message;
2264
-
2265
- if (Object.keys(extra).length) {
2266
- const parsedExtra = safeStringify(extra);
2267
- consoleMessage = `${consoleMessage} (${parsedExtra})`;
37
+ static async hold(callId) {
38
+ return getApiClient().calld.hold(callId);
2268
39
  }
2269
-
2270
- if (category) {
2271
- consoleMessage = `[${category}] ${consoleMessage}`;
40
+ static async resume(callId) {
41
+ return getApiClient().calld.resume(callId);
2272
42
  }
2273
-
2274
- // Log the message in the console anyway (but don't console.error on mobile)
2275
- const consoleLevel = isMobile() && level === 'error' ? WARN : level;
2276
-
2277
- // eslint-disable-next-line
2278
- const oldMethod = this.oldConsoleMethods[consoleLevel] || this.oldConsoleMethods.log;
2279
- oldMethod.apply(oldMethod, [date, consoleMessage]);
2280
-
2281
- if (this._callback) {
2282
- this._callback(level, consoleMessage);
43
+ static async mute(callId) {
44
+ return getApiClient().calld.mute(callId);
2283
45
  }
2284
-
2285
- if (!skipSendToRemote) {
2286
- this._sendToRemoteLogger(level, { date, message, category, ...extra });
46
+ static async sendDTMF(callId, digits) {
47
+ return getApiClient().calld.sendDTMF(callId, digits);
2287
48
  }
2288
- }
2289
-
2290
- logRequest(url , options , response , start ) {
2291
- if (!this.enabled) {
2292
- return;
49
+ static async unmute(callId) {
50
+ return getApiClient().calld.unmute(callId);
2293
51
  }
2294
- const { status } = response;
2295
- const duration = new Date() - start;
2296
-
2297
- let level = TRACE;
2298
- if (status >= 400 && status < 500) {
2299
- level = WARN;
2300
- } else if (status >= 500) {
2301
- level = ERROR;
2302
- }
2303
-
2304
- this.log(level, this._makeCategory('http'), url, {
2305
- status,
2306
- body: this.removeSlashes(JSON.stringify(options.body)),
2307
- method: options.method,
2308
- headers: options.headers,
2309
- duration,
2310
- });
2311
- }
2312
-
2313
- // Logs aren't stored anymore
2314
- getLogs() {
2315
- console.warn('IssueReporter\'s logs aren\'t stored anymore. Please use fluentd to store them');
2316
- return [];
2317
- }
2318
-
2319
- getParsedLogs() {
2320
- console.warn('IssueReporter\'s logs aren\'t stored anymore. Please use fluentd to store them');
2321
- return [];
2322
- }
2323
-
2324
- getReport() {
2325
- return this.getParsedLogs().join('\r\n');
2326
- }
2327
-
2328
- _catchConsole() {
2329
- this.oldConsoleMethods = {};
2330
- CONSOLE_METHODS.forEach((methodName ) => {
2331
- // eslint-disable-next-line
2332
- this.oldConsoleMethods[methodName] = console[methodName];
2333
- window.console[methodName] = (...args) => {
2334
- // Store message
2335
- try {
2336
- this.log(methodName, args.join(' '));
2337
- // Use old console method to log it normally
2338
- this.oldConsoleMethods[methodName].apply(null, args);
2339
- } catch (e) {
2340
- // Avoid circular structure issues
2341
- }
2342
- };
2343
- });
2344
- }
2345
-
2346
- _sendToRemoteLogger(level , payload = {}) {
2347
- if (!this.remoteClientConfiguration) {
2348
- return;
2349
- }
2350
-
2351
- const { level: minLevel, bufferSize } = this.remoteClientConfiguration;
2352
- if (!minLevel || this._isLevelAbove(minLevel, level)) {
2353
- return;
2354
- }
2355
-
2356
- payload.level = level;
2357
-
2358
- if (bufferSize > 0) {
2359
- return this._addToBuffer(payload);
2360
- }
2361
-
2362
- this._sendDebugToGrafana(payload);
2363
- }
2364
-
2365
- _parseLoggerBody(payload ) {
2366
- const { level } = payload;
2367
- const { maxMessageSize, extra } = this.remoteClientConfiguration || {};
2368
-
2369
- delete payload.level;
2370
-
2371
- if (maxMessageSize && typeof payload.message === 'string' && payload.message.length > maxMessageSize) {
2372
- payload.message = `${payload.message.substr(0, maxMessageSize)}...`;
2373
- }
2374
-
2375
- return safeStringify({
2376
- level,
2377
- ...payload,
2378
- ...extra,
2379
- });
2380
- }
2381
-
2382
- _addToBuffer(payload ) {
2383
- // Reset buffer timer
2384
- if (this.bufferTimeout) {
2385
- clearTimeout(this.bufferTimeout);
2386
- this.bufferTimeout = null;
2387
- }
2388
-
2389
- this.buffer.push(payload);
2390
-
2391
- // $FlowFixMe
2392
- const { bufferSize, bufferTimeout } = this.remoteClientConfiguration;
2393
-
2394
- if (this.buffer.length > bufferSize) {
2395
- return this._processBuffer();
2396
- }
2397
-
2398
- if (bufferTimeout > 0) {
2399
- this.bufferTimeout = setTimeout(this._boundProcessBuffer, bufferTimeout);
2400
- }
2401
- }
2402
-
2403
- _processBuffer() {
2404
- this._sendDebugToGrafana(this.buffer);
2405
-
2406
- this.buffer = [];
2407
- if (this.bufferTimeout) {
2408
- clearTimeout(this.bufferTimeout);
2409
- this.bufferTimeout = null;
2410
- }
2411
- }
2412
-
2413
- _sendDebugToGrafana(payload , retry = 0) {
2414
- if (!this.remoteClientConfiguration || retry >= MAX_REMOTE_RETRY) {
2415
- return;
2416
- }
2417
-
2418
- const { tag, host, port } = this.remoteClientConfiguration;
2419
- const isArray = Array.isArray(payload);
2420
- const isSecure = +port === 443;
2421
- const url = `http${isSecure ? 's' : ''}://${host}${isSecure ? '' : `:${port}`}/${tag}`;
2422
- const body = isArray ? `[${payload.map(this._boundParseLoggerBody).join(',')}]` : this._parseLoggerBody(payload);
2423
-
2424
- realFetch()(url, {
2425
- method: 'POST',
2426
- headers: {
2427
- Accept: 'application/json',
2428
- 'Content-Type': 'application/json',
2429
- },
2430
- // $FlowFixMe
2431
- body,
2432
- }).catch((e ) => {
2433
- // $FlowFixMe
2434
- e.skipSendToRemote = true;
2435
- this.log('error', this._makeCategory('grafana'), 'Sending log to grafana, error', e);
2436
-
2437
- setTimeout(() => {
2438
- if (isArray) {
2439
- payload = payload.map(message => this._writeRetryCount(message, retry + 1));
2440
- } else if (payload && typeof payload === 'object') {
2441
- payload = this._writeRetryCount(payload, retry + 1);
2442
- }
2443
-
2444
- this._sendDebugToGrafana(payload, retry + 1);
2445
- }, 5000 + retry * 1000);
2446
- });
2447
- }
2448
-
2449
- _writeRetryCount(message , count ) {
2450
- if (message && typeof message === 'object') {
2451
- // $FlowFixMe
2452
- message._retry = count;
2453
- }
2454
-
2455
- return message;
2456
- }
2457
-
2458
- _isLevelAbove(level1 , level2 ) {
2459
- const index1 = LOG_LEVELS.indexOf(level1);
2460
- const index2 = LOG_LEVELS.indexOf(level2);
2461
- if (index1 === -1 || index2 === -1) {
2462
- return false;
2463
- }
2464
-
2465
- return index1 > index2;
2466
- }
2467
-
2468
- _makeCategory(category ) {
2469
- return `${CATEGORY_PREFIX}${category}`;
2470
- }
2471
- }
2472
-
2473
- var IssueReporter$1 = new IssueReporter();
2474
-
2475
- /* */
2476
-
2477
-
2478
-
2479
-
2480
-
2481
-
2482
-
2483
-
2484
-
2485
-
2486
- const methods = ['head', 'get', 'post', 'put', 'delete'];
2487
-
2488
- const logger$1 = IssueReporter$1 ? IssueReporter$1.loggerFor('api') : console;
2489
-
2490
- // Use a function here to be able to mock it in tests
2491
- const realFetch = () => {
2492
- if (typeof document !== 'undefined' && window.fetch) {
2493
- // Browser
2494
- return window.fetch;
2495
- }
2496
-
2497
- if (isMobile()) {
2498
- // React native
2499
- return fetch;
2500
- }
2501
-
2502
- // nodejs
2503
- // this package is disable for react-native in package.json because it requires nodejs modules
2504
- // Used to trick the optimizer to avoid requiring `node-fetch/lib/index` directly
2505
- // It causes to require it on browsers when delivered by a nodejs engine (cf: vitejs).
2506
- try {
2507
- // $FlowFixMe
2508
- return require(Math.random() >= 0 ? 'node-fetch/lib/index' : '');
2509
- } catch (e) {
2510
- return fetch;
2511
- }
2512
- };
2513
-
2514
- class ApiRequester {
2515
-
2516
-
2517
-
2518
-
2519
-
2520
-
2521
-
2522
-
2523
-
2524
-
2525
-
2526
-
2527
-
2528
-
2529
-
2530
-
2531
- // eslint-disable-next-line
2532
- static successResponseParser(response , isJson ) {
2533
- return response.status === 204 || response.status === 201 || response.status === 200;
2534
- }
2535
-
2536
- static defaultParser(response ) {
2537
- return response.json().then((data ) => data);
2538
- }
2539
-
2540
- static getQueryString(obj ) {
2541
- return Object.keys(obj)
2542
- .filter(key => obj[key])
2543
- .map(key => `${key}=${encodeURIComponent(obj[key])}`)
2544
- .join('&');
2545
- }
2546
-
2547
- static base64Encode(str ) {
2548
- return typeof btoa !== 'undefined' ? btoa(str) : Base64.encode(str);
2549
- }
2550
-
2551
- // @see https://github.com/facebook/flow/issues/183#issuecomment-358607052
2552
- constructor({ server, refreshTokenCallback, clientId, agent = null, token = null, fetchOptions } ) {
2553
- this.server = server;
2554
- this.agent = agent;
2555
- this.clientId = clientId;
2556
- this.refreshTokenCallback = refreshTokenCallback;
2557
- this.refreshTokenPromise = null;
2558
- this.fetchOptions = fetchOptions || {};
2559
- if (token) {
2560
- this.token = token;
52
+ static async transferCall(callId, number, flow) {
53
+ return getApiClient().calld.transferCall(callId, number, flow);
2561
54
  }
2562
-
2563
- this.shouldLogErrors = true;
2564
-
2565
- methods.forEach(method => {
2566
- // $FlowFixMe
2567
- ApiRequester.prototype[method] = function sugar(...args) {
2568
- // Add method in arguments passed to `call`
2569
- args.splice(1, 0, method);
2570
-
2571
- return this.call.call(this, ...args);
2572
- };
2573
- });
2574
- }
2575
-
2576
- setTenant(tenant ) {
2577
- this.tenant = tenant;
2578
- }
2579
-
2580
- setToken(token ) {
2581
- this.token = token;
2582
- }
2583
-
2584
- setFetchOptions(options ) {
2585
- this.fetchOptions = options;
2586
- }
2587
-
2588
- disableErrorLogging() {
2589
- this.shouldLogErrors = false;
2590
- }
2591
-
2592
- enableErrorLogging() {
2593
- this.shouldLogErrors = true;
2594
- }
2595
-
2596
- async call(
2597
- path ,
2598
- method = 'get',
2599
- body = null,
2600
- headers = null,
2601
- parse = ApiRequester.defaultParser,
2602
- firstCall = true,
2603
- ) {
2604
- const url = this.computeUrl(method, path, body);
2605
- const newHeaders = this.getHeaders(headers);
2606
- let newBody = method === 'get' ? null : body;
2607
- if (newBody && newHeaders['Content-Type'] === 'application/json') {
2608
- newBody = JSON.stringify(newBody);
55
+ static async cancelCallTransfer(transferId) {
56
+ return getApiClient().calld.cancelCallTransfer(transferId);
2609
57
  }
2610
- const isHead = method === 'head';
2611
- const hasEmptyResponse = method === 'delete' || isHead;
2612
- const newParse = hasEmptyResponse ? ApiRequester.successResponseParser : parse;
2613
-
2614
- const fetchOptions = { ...this.fetchOptions || {} };
2615
- const extraHeaders = fetchOptions.headers || {};
2616
- delete fetchOptions.headers;
2617
-
2618
- const options = {
2619
- method,
2620
- body: newBody,
2621
- headers: { ...this.getHeaders(headers), ...extraHeaders },
2622
- agent: this.agent,
2623
- ...fetchOptions,
2624
- };
2625
-
2626
- if (this.refreshTokenPromise) {
2627
- logger$1.info('A token is already refreshing, waiting ...', { url });
2628
- await this.refreshTokenPromise;
58
+ static async confirmCallTransfer(transferId) {
59
+ return getApiClient().calld.confirmCallTransfer(transferId);
2629
60
  }
2630
-
2631
- const start = new Date();
2632
-
2633
- return realFetch()(url, options).then(response => {
2634
- const contentType = response.headers.get('content-type') || '';
2635
- const isJson = contentType.indexOf('application/json') !== -1;
2636
-
2637
- IssueReporter$1.logRequest(url, options, response, start);
2638
-
2639
- // Throw an error only if status >= 400
2640
- if ((isHead && response.status >= 500) || (!isHead && response.status >= 400)) {
2641
- const promise = isJson ? response.json() : response.text();
2642
- const exceptionClass = response.status >= 500 ? ServerError : BadResponse;
2643
-
2644
- return promise.then(async (err ) => {
2645
- // Check if the token is still valid
2646
- if (firstCall && this._checkTokenExpired(response, err)) {
2647
- logger$1.warn('token expired', { error: err.reason });
2648
- // Replay the call after refreshing the token
2649
- return this._replayWithNewToken(err, path, method, body, headers, parse);
2650
- }
2651
-
2652
- const error = typeof err === 'string'
2653
- ? exceptionClass.fromText(err, response.status)
2654
- : exceptionClass.fromResponse(err, response.status);
2655
-
2656
- if (this.shouldLogErrors) {
2657
- logger$1.error('API error', error);
2658
- }
2659
-
2660
- throw error;
2661
- });
2662
- }
2663
-
2664
- return newParse(response, isJson);
2665
- }).catch(error => {
2666
- if (this.shouldLogErrors) {
2667
- logger$1.error('Fetch failed', { url, options, message: error.message, stack: error.stack });
2668
- }
2669
-
2670
- throw error;
2671
- });
2672
- }
2673
-
2674
- _checkTokenExpired(response , err ) {
2675
- // Special case when authenticating form a token: we got a 404
2676
- const isTokenNotFound = response.status === 404 && this._isTokenNotFound(err);
2677
-
2678
- return response.status === 401 || isTokenNotFound;
2679
- }
2680
-
2681
- _isTokenNotFound(err ) {
2682
- return err && err.reason && err.reason[0] === 'No such token';
2683
- }
2684
-
2685
- _replayWithNewToken(
2686
- err ,
2687
- path ,
2688
- method ,
2689
- body = null,
2690
- headers = null,
2691
- parse ,
2692
- ) {
2693
- const isTokenNotFound = this._isTokenNotFound(err);
2694
- let newPath = path;
2695
- logger$1.info('refreshing token', { inProgress: !!this.refreshTokenPromise });
2696
-
2697
- this.refreshTokenPromise = this.refreshTokenPromise || this.refreshTokenCallback();
2698
-
2699
- return this.refreshTokenPromise.then(() => {
2700
- this.refreshTokenPromise = null;
2701
- logger$1.info('token refreshed', { isTokenNotFound });
2702
- if (isTokenNotFound) {
2703
- const pathParts = path.split('/');
2704
- pathParts.pop();
2705
- pathParts.push(this.token);
2706
- newPath = pathParts.join('/');
2707
- }
2708
-
2709
- return this.call(newPath, method, body, headers, parse, false);
2710
- }).catch((e) => {
2711
- this.refreshTokenPromise = null;
2712
- throw e;
2713
- });
2714
- }
2715
-
2716
- getHeaders(header ) {
2717
- if (header instanceof Object) {
2718
- return header;
2719
- }
2720
-
2721
- return {
2722
- 'X-Auth-Token': this.token,
2723
- ...(this.tenant ? { 'Wazo-Tenant': this.tenant } : null),
2724
- Accept: 'application/json',
2725
- 'Content-Type': 'application/json',
2726
- };
2727
- }
2728
-
2729
- computeUrl(method , path , body ) {
2730
- const url = `${this.baseUrl}/${path}`;
2731
-
2732
- return method === 'get' && body && Object.keys(body).length ? `${url}?${ApiRequester.getQueryString(body)}` : url;
2733
- }
2734
-
2735
- get baseUrl() {
2736
- return `https://${this.server}/api`;
2737
- }
2738
- }
2739
-
2740
- /* */
2741
-
2742
- const DEFAULT_BACKEND_USER = 'wazo_user';
2743
- const DETAULT_EXPIRATION = 3600;
2744
-
2745
- var authMethods = (client , baseUrl ) => ({
2746
- checkToken: (token ) => client.head(`${baseUrl}/token/${token}`, null, {}),
2747
-
2748
- authenticate: (token ) =>
2749
- client.get(`${baseUrl}/token/${token}`, null, {}).then(response => Session.parse(response)),
2750
-
2751
- logIn(params
2752
-
2753
-
2754
-
2755
-
2756
-
2757
-
2758
-
2759
- ) {
2760
- const body = {
2761
- backend: params.backend || DEFAULT_BACKEND_USER,
2762
- expiration: params.expiration || DETAULT_EXPIRATION,
2763
- };
2764
- const headers = {
2765
- Authorization: `Basic ${ApiRequester.base64Encode(`${params.username}:${params.password}`)}`,
2766
- 'Content-Type': 'application/json',
2767
- };
2768
-
2769
- if (client.clientId) {
2770
- body.access_type = 'offline';
2771
- body.client_id = client.clientId;
2772
- }
2773
-
2774
- if (params.mobile) {
2775
- headers['Wazo-Session-Type'] = 'mobile';
2776
- }
2777
-
2778
- if (params.tenantId) {
2779
- console.warn('Use of `tenantId` is deprecated when calling logIn() method, use `domainName` instead.');
2780
- body.tenant_id = params.tenantId;
2781
- }
2782
-
2783
- if (params.domainName) {
2784
- body.domain_name = params.domainName;
2785
- }
2786
-
2787
- return client.post(`${baseUrl}/token`, body, headers).then(response => Session.parse(response));
2788
- },
2789
-
2790
- logOut: (token ) =>
2791
- client.delete(`${baseUrl}/token/${token}`, null, {}, ApiRequester.successResponseParser),
2792
-
2793
- refreshToken: (
2794
- refreshToken ,
2795
- backend ,
2796
- expiration ,
2797
- isMobile = false,
2798
- tenantId ,
2799
- domainName ,
2800
- ) => {
2801
- const body = {
2802
- backend: backend || DEFAULT_BACKEND_USER,
2803
- expiration: expiration || DETAULT_EXPIRATION,
2804
- refresh_token: refreshToken,
2805
- client_id: client.clientId,
2806
- };
2807
-
2808
- if (tenantId) {
2809
- console.warn('Use of `tenantId` is deprecated when calling refreshToken() method, use `domainName` instead.');
2810
- body.tenant_id = tenantId;
2811
- }
2812
-
2813
- if (domainName) {
2814
- body.domain_name = domainName;
2815
- }
2816
-
2817
- const headers = {
2818
- 'Content-Type': 'application/json',
2819
- ...(isMobile ? { 'Wazo-Session-Type': 'mobile' } : {}),
2820
- };
2821
-
2822
- return client.post(`${baseUrl}/token`, body, headers, ApiRequester.defaultParser, false).then(Session.parse);
2823
- },
2824
-
2825
- deleteRefreshToken: (clientId ) =>
2826
- client.delete(`${baseUrl}/users/me/tokens/${clientId}`, null, null, ApiRequester.successResponseParser),
2827
-
2828
- updatePassword: (userUuid , oldPassword , newPassword ) => {
2829
- const body = {
2830
- new_password: newPassword,
2831
- old_password: oldPassword,
2832
- };
2833
-
2834
- return client.put(`${baseUrl}/users/${userUuid}/password`, body, null, ApiRequester.successResponseParser);
2835
- },
2836
-
2837
- sendDeviceToken: (userUuid , deviceToken , apnsVoipToken , apnsNotificationToken ) => {
2838
- const body = {
2839
- token: deviceToken,
2840
- };
2841
-
2842
- if (apnsVoipToken) {
2843
- // Should be called `voip_token`, but we can't changed it to be retro-compatible
2844
- body.apns_token = apnsVoipToken;
2845
- body.apns_voip_token = apnsVoipToken;
2846
- }
2847
-
2848
- if (apnsNotificationToken) {
2849
- body.apns_notification_token = apnsNotificationToken;
2850
- }
2851
-
2852
- return client.post(`${baseUrl}/users/${userUuid}/external/mobile`, body);
2853
- },
2854
-
2855
- getPushNotificationSenderId: (userUuid ) =>
2856
- client.get(`${baseUrl}/users/${userUuid}/external/mobile/sender_id`, null).then(response => response.sender_id),
2857
-
2858
- /**
2859
- * `username` or `email` should be set.
2860
- */
2861
- sendResetPasswordEmail: ({ username, email } ) => {
2862
- const body = {};
2863
- if (username) {
2864
- body.username = username;
2865
- }
2866
- if (email) {
2867
- body.email = email;
2868
- }
2869
-
2870
- return client.get(`${baseUrl}/users/password/reset`, body, {}, ApiRequester.successResponseParser);
2871
- },
2872
-
2873
- resetPassword: (userUuid , password ) => {
2874
- const body = {
2875
- password,
2876
- };
2877
-
2878
- return client.post(
2879
- `${baseUrl}/users/password/reset?user_uuid=${userUuid}`,
2880
- body,
2881
- null,
2882
- ApiRequester.successResponseParser,
2883
- );
2884
- },
2885
-
2886
- removeDeviceToken: (userUuid ) => client.delete(`${baseUrl}/users/${userUuid}/external/mobile`),
2887
-
2888
- createUser: (
2889
- username ,
2890
- password ,
2891
- firstname ,
2892
- lastname ,
2893
- ) => {
2894
- const body = {
2895
- username,
2896
- password,
2897
- firstname,
2898
- lastname,
2899
- };
2900
-
2901
- return client.post(`${baseUrl}/users`, body);
2902
- },
2903
-
2904
- addUserEmail: (userUuid , email , main ) => {
2905
- const body = {
2906
- emails: [
2907
- {
2908
- address: email,
2909
- main,
2910
- },
2911
- ],
2912
- };
2913
-
2914
- return client.put(`${baseUrl}/users/${userUuid}/emails`, body);
2915
- },
2916
-
2917
- addUserPolicy: (userUuid , policyUuid ) =>
2918
- client.put(`${baseUrl}/users/${userUuid}/policies/${policyUuid}`),
2919
-
2920
- getRestrictionPolicies: (scopes ) =>
2921
- client.post(`${baseUrl}/token/${client.token}/scopes/check`, { scopes }),
2922
-
2923
- deleteUserPolicy: (userUuid , policyUuid ) =>
2924
- client.delete(`${baseUrl}/users/${userUuid}/policies/${policyUuid}`),
2925
-
2926
- addUserGroup: (userUuid , groupUuid ) => client.put(`${baseUrl}/groups/${groupUuid}/users/${userUuid}`),
2927
-
2928
- listUsersGroup: (groupUuid ) => client.get(`${baseUrl}/groups/${groupUuid}/users`),
2929
-
2930
- deleteUserGroup: (userUuid , groupUuid ) =>
2931
- client.delete(`${baseUrl}/groups/${groupUuid}/users/${userUuid}`),
2932
-
2933
- getUser: (userUuid ) => client.get(`${baseUrl}/users/${userUuid}`),
2934
-
2935
- getUserSession: (userUuid ) => client.get(`${baseUrl}/users/${userUuid}/sessions`),
2936
-
2937
- deleteUserSession: (userUuid , sessionUuids ) =>
2938
- client.delete(`${baseUrl}/users/${userUuid}/sessions/${sessionUuids}`),
2939
-
2940
- listUsers: () => client.get(`${baseUrl}/users`),
2941
-
2942
- deleteUser: (userUuid ) => client.delete(`${baseUrl}/users/${userUuid}`),
2943
-
2944
- listTenants: () => client.get(`${baseUrl}/tenants`),
2945
-
2946
- getTenant: (tenantUuid ) => client.get(`${baseUrl}/tenants/${tenantUuid}`),
2947
-
2948
- createTenant: (name ) => client.post(`${baseUrl}/tenants`, { name }),
2949
-
2950
- updateTenant: (
2951
- uuid ,
2952
- name ,
2953
- contact ,
2954
- phone ,
2955
- address ,
2956
- ) => {
2957
- const body = {
2958
- name,
2959
- contact,
2960
- phone,
2961
- address,
2962
- };
2963
-
2964
- return client.put(`${baseUrl}/tenants/${uuid}`, body);
2965
- },
2966
-
2967
- deleteTenant: (uuid ) => client.delete(`${baseUrl}/tenants/${uuid}`),
2968
-
2969
- createGroup: (name ) => client.post(`${baseUrl}/groups`, { name }),
2970
-
2971
- listGroups: () => client.get(`${baseUrl}/groups`),
2972
-
2973
- deleteGroup: (uuid ) => client.delete(`${baseUrl}/groups/${uuid}`),
2974
-
2975
- createPolicy: (name , description , aclTemplates ) => {
2976
- const body = {
2977
- name,
2978
- description,
2979
- acl_templates: aclTemplates, // deprecated
2980
- acl: aclTemplates,
2981
- };
2982
-
2983
- client.post(`${baseUrl}/policies`, body);
2984
- },
2985
-
2986
- listPolicies: () => client.get(`${baseUrl}/policies`),
2987
-
2988
- deletePolicy: (policyUuid ) =>
2989
- client.delete(`${baseUrl}/policies/${policyUuid}`),
2990
-
2991
- getProviders: (userUuid ) => client.get(`${baseUrl}/users/${userUuid}/external`),
2992
-
2993
- getProviderToken: (userUuid , provider ) =>
2994
- client.get(`${baseUrl}/users/${userUuid}/external/${provider}`),
2995
-
2996
- getProviderAuthUrl: (userUuid , provider ) =>
2997
- client.post(`${baseUrl}/users/${userUuid}/external/${provider}`, {}),
2998
-
2999
- deleteProviderToken: (userUuid , provider ) =>
3000
- client.delete(`${baseUrl}/users/${userUuid}/external/${provider}`),
3001
- });
3002
-
3003
- /* */
3004
-
3005
-
3006
- var applicationMethods = (client , baseUrl ) => ({
3007
- bridgeCall(
3008
- applicationUuid ,
3009
- callId ,
3010
- context ,
3011
- exten ,
3012
- autoanswer ,
3013
- displayed_caller_id_number ,
3014
- ) {
3015
- const url = `${baseUrl}/${applicationUuid}/nodes`;
3016
- const body = { calls: [{ id: callId }] };
3017
-
3018
- return client
3019
- .post(url, body, null, res => res.json().then(response => response.uuid))
3020
- .then(nodeUuid =>
3021
- client
3022
- .post(`${url}/${nodeUuid}/calls`, { context, exten, autoanswer, displayed_caller_id_number })
3023
- .then(data => ({
3024
- nodeUuid,
3025
- data,
3026
- })));
3027
- },
3028
-
3029
- answerCall: (applicationUuid , callId ) =>
3030
- client.put(`${baseUrl}/${applicationUuid}/calls/${callId}/answer`, {}, null, ApiRequester.successResponseParser),
3031
-
3032
- calls: (applicationUuid ) => client.get(`${baseUrl}/${applicationUuid}/calls`),
3033
-
3034
- hangupCall: (applicationUuid , callId ) =>
3035
- client.delete(`${baseUrl}/${applicationUuid}/calls/${callId}`),
3036
-
3037
- startPlaybackCall: (applicationUuid , callId , language , uri ) =>
3038
- client.post(`${baseUrl}/${applicationUuid}/calls/${callId}/playbacks`, { language, uri }),
3039
-
3040
- stopPlaybackCall: (applicationUuid , playbackUuid ) =>
3041
- client.delete(`${baseUrl}/${applicationUuid}/playbacks/${playbackUuid}`),
3042
-
3043
- startProgressCall: (applicationUuid , callId ) =>
3044
- client.put(
3045
- `${baseUrl}/${applicationUuid}/calls/${callId}/progress/start`,
3046
- {},
3047
- null,
3048
- ApiRequester.successResponseParser,
3049
- ),
3050
-
3051
- stopProgressCall: (applicationUuid , callId ) =>
3052
- client.put(
3053
- `${baseUrl}/${applicationUuid}/calls/${callId}/progress/stop`,
3054
- {},
3055
- null,
3056
- ApiRequester.successResponseParser,
3057
- ),
3058
-
3059
- startMohCall: (applicationUuid , callId , mohUuid ) =>
3060
- client.put(
3061
- `${baseUrl}/${applicationUuid}/calls/${callId}/moh/${mohUuid}/start`,
3062
- {},
3063
- null,
3064
- ApiRequester.successResponseParser,
3065
- ),
3066
-
3067
- stopMohCall: (applicationUuid , callId ) =>
3068
- client.put(`${baseUrl}/${applicationUuid}/calls/${callId}/moh/stop`, {}, null, ApiRequester.successResponseParser),
3069
-
3070
- startHoldCall: (applicationUuid , callId ) =>
3071
- client.put(
3072
- `${baseUrl}/${applicationUuid}/calls/${callId}/hold/start`,
3073
- {},
3074
- null,
3075
- ApiRequester.successResponseParser,
3076
- ),
3077
-
3078
- stopHoldCall: (applicationUuid , callId ) =>
3079
- client.put(`${baseUrl}/${applicationUuid}/calls/${callId}/hold/stop`, {}, null, ApiRequester.successResponseParser),
3080
-
3081
- startMuteCall: (applicationUuid , callId ) =>
3082
- client.put(
3083
- `${baseUrl}/${applicationUuid}/calls/${callId}/mute/start`,
3084
- {},
3085
- null,
3086
- ApiRequester.successResponseParser,
3087
- ),
3088
-
3089
- stopMuteCall: (applicationUuid , callId ) =>
3090
- client.put(`${baseUrl}/${applicationUuid}/calls/${callId}/mute/stop`, {}, null, ApiRequester.successResponseParser),
3091
-
3092
- sendDTMFCall: (applicationUuid , callId , digits ) =>
3093
- client.put(`${baseUrl}/${applicationUuid}/calls/${callId}/dtmf`, { digits }, null,
3094
- ApiRequester.successResponseParser),
3095
-
3096
- addCallNodes: (applicationUuid , nodeUuid , callId ) =>
3097
- client.put(
3098
- `${baseUrl}/${applicationUuid}/nodes/${nodeUuid}/calls/${callId}`,
3099
- {},
3100
- null,
3101
- ApiRequester.successResponseParser,
3102
- ),
3103
-
3104
- createNewNodeWithCall: (applicationUuid , calls ) =>
3105
- client.post(`${baseUrl}/${applicationUuid}/nodes`, { calls }),
3106
-
3107
- addNewCallNodes: (applicationUuid , nodeUuid , context , exten , autoanswer ) =>
3108
- client.post(`${baseUrl}/${applicationUuid}/nodes/${nodeUuid}/calls`, { context, exten, autoanswer }),
3109
-
3110
- listCallsNodes: (applicationUuid , nodeUuid ) =>
3111
- client.get(`${baseUrl}/${applicationUuid}/nodes/${nodeUuid}`),
3112
-
3113
- listNodes: (applicationUuid ) => client.get(`${baseUrl}/${applicationUuid}/nodes`),
3114
-
3115
- removeNode: (applicationUuid , nodeUuid ) =>
3116
- client.delete(`${baseUrl}/${applicationUuid}/nodes/${nodeUuid}`),
3117
-
3118
- removeCallNodes: (applicationUuid , nodeUuid , callId ) =>
3119
- client.delete(`${baseUrl}/${applicationUuid}/nodes/${nodeUuid}/calls/${callId}`),
3120
-
3121
- listSnoop: (applicationUuid ) =>
3122
- client.get(`${baseUrl}/${applicationUuid}/snoops`),
3123
-
3124
- removeSnoop: (applicationUuid , snoopUuid ) =>
3125
- client.delete(`${baseUrl}/${applicationUuid}/snoops/${snoopUuid}`),
3126
-
3127
- viewSnoop: (applicationUuid , snoopUuid ) =>
3128
- client.get(`${baseUrl}/${applicationUuid}/snoops/${snoopUuid}`),
3129
-
3130
- createSnoop: (applicationUuid , callId , snoopingCallId , whisperMode ) =>
3131
- client.post(`${baseUrl}/${applicationUuid}/calls/${callId}/snoops`,
3132
- { snooping_call_id: snoopingCallId, whisper_mode: whisperMode }),
3133
-
3134
- updateSnoop: (applicationUuid , snoopUuid , whisperMode ) =>
3135
- client.put(`${baseUrl}/${applicationUuid}/snoops/${snoopUuid}`, { whisper_mode: whisperMode }, null,
3136
- ApiRequester.successResponseParser),
3137
- });
3138
-
3139
- //
3140
-
3141
-
3142
-
3143
-
3144
-
3145
-
3146
-
3147
-
3148
-
3149
-
3150
-
3151
-
3152
-
3153
-
3154
-
3155
- class ExternalApp {
3156
-
3157
-
3158
-
3159
-
3160
- static parse(plain ) {
3161
- return new ExternalApp({
3162
- name: plain.name,
3163
- configuration: plain.configuration,
3164
- });
3165
- }
3166
-
3167
- static parseMany(plain ) {
3168
- return plain.items.map(item => ExternalApp.parse(item));
3169
- }
3170
-
3171
- static newFrom(profile ) {
3172
- return newFrom(profile, ExternalApp);
3173
- }
3174
-
3175
- constructor({ name, configuration } = {}) {
3176
- this.name = name;
3177
- this.configuration = configuration;
3178
-
3179
- // Useful to compare instead of instanceof with minified code
3180
- this.type = 'ExternalApp';
3181
- }
3182
- }
3183
-
3184
- //
3185
-
3186
- class MeetingAuthorization {
3187
-
3188
-
3189
-
3190
-
3191
-
3192
-
3193
- constructor({
3194
- meetingUuid,
3195
- uuid,
3196
- userUuid,
3197
- userName,
3198
- } = {}) {
3199
- this.meetingUuid = meetingUuid;
3200
- this.uuid = uuid;
3201
- this.userUuid = userUuid;
3202
- this.userName = userName;
3203
- }
3204
-
3205
- setStatus(status ) {
3206
- this.status = status;
3207
- }
3208
-
3209
- getStatus() {
3210
- return this.status;
3211
- }
3212
-
3213
- static parse(plain ) {
3214
- const {
3215
- meeting_uuid: meetingUuid,
3216
- uuid,
3217
- guest_uuid: userUuid,
3218
- guest_name: userName,
3219
- } = plain;
3220
-
3221
- return new MeetingAuthorization({
3222
- meetingUuid,
3223
- uuid,
3224
- userUuid,
3225
- userName,
3226
- });
3227
- }
3228
-
3229
- static parseMany(items ) {
3230
- if (!items) {
3231
- return [];
3232
- }
3233
- return items.map(MeetingAuthorization.parse);
3234
- }
3235
- }
3236
-
3237
- //
3238
-
3239
-
3240
-
3241
-
3242
-
3243
-
3244
-
3245
-
3246
-
3247
-
3248
-
3249
-
3250
-
3251
-
3252
-
3253
-
3254
-
3255
-
3256
-
3257
-
3258
-
3259
-
3260
-
3261
-
3262
-
3263
- class Meeting {
3264
-
3265
-
3266
-
3267
-
3268
-
3269
-
3270
-
3271
-
3272
-
3273
-
3274
-
3275
-
3276
-
3277
-
3278
- static parse(plain ) {
3279
- return new Meeting({
3280
- guestSipAuthorization: plain.guest_sip_authorization,
3281
- uri: plain.ingress_http_uri,
3282
- name: plain.name,
3283
- ownerUuids: plain.owner_uuids,
3284
- port: plain.port,
3285
- uuid: plain.uuid,
3286
- extension: plain.exten,
3287
- persistent: plain.persistent,
3288
- creationTime: moment(plain.creation_time).toDate(),
3289
- requireAuthorization: plain.require_authorization,
3290
- });
3291
- }
3292
-
3293
- static parseMany(items ) {
3294
- if (!items) {
3295
- return [];
3296
- }
3297
- return items.map(plain => Meeting.parse(plain));
3298
- }
3299
-
3300
- static newFrom(meeting ) {
3301
- return newFrom(meeting, Meeting);
3302
- }
3303
-
3304
- constructor({
3305
- uuid,
3306
- name,
3307
- guestSipAuthorization,
3308
- ownerUuids,
3309
- port,
3310
- uri,
3311
- extension,
3312
- persistent,
3313
- creationTime,
3314
- requireAuthorization,
3315
- } = {}) {
3316
- this.guestSipAuthorization = guestSipAuthorization;
3317
- this.uri = uri;
3318
- this.name = name;
3319
- this.ownerUuids = ownerUuids;
3320
- this.port = port;
3321
- this.uuid = uuid;
3322
- this.extension = extension;
3323
- this.persistent = persistent;
3324
- this.creationTime = creationTime;
3325
- this.requireAuthorization = requireAuthorization;
3326
-
3327
- // Useful to compare instead of instanceof with minified code
3328
- this.type = 'Meeting';
3329
- }
3330
-
3331
- getGuestSipCredentials() {
3332
- // eslint-disable-next-line no-undef
3333
- const [username, secret] = atob(this.guestSipAuthorization).split(':');
3334
- return { username, secret };
3335
- }
3336
-
3337
- }
3338
-
3339
- //
3340
-
3341
- const camelToUnderscore = (key ) => {
3342
- if (typeof key !== 'string') {
3343
- throw new Error('Input is not a string');
3344
- }
3345
- return key.charAt(0).toLowerCase() + key.substring(1).replace(/([A-Z])/g, '_$1').toLowerCase();
3346
- };
3347
-
3348
- //
3349
-
3350
- const convertKeysFromCamelToUnderscore = (args ) => {
3351
- if (!args || typeof args !== 'object' || Array.isArray(args)) {
3352
- throw new Error('Input is not an object');
3353
- }
3354
-
3355
- return Object.keys(args).reduce((acc, key) => {
3356
- acc[camelToUnderscore(key)] = typeof args[key] === 'object' && !Array.isArray(args[key])
3357
- ? convertKeysFromCamelToUnderscore(args[key]) : args[key];
3358
- return acc;
3359
- }, {});
3360
- };
3361
-
3362
- /* */
3363
-
3364
- var confdMethods = (client , baseUrl ) => ({
3365
- listUsers: () => client.get(`${baseUrl}/users`, null),
3366
-
3367
- getUser: (userUuid ) => client.get(`${baseUrl}/users/${userUuid}`, null).then(Profile.parse),
3368
-
3369
- updateUser: (userUuid , profile ) => {
3370
- const body = {
3371
- firstname: profile.firstName,
3372
- lastname: profile.lastName,
3373
- email: profile.email,
3374
- mobile_phone_number: profile.mobileNumber,
3375
- };
3376
-
3377
- return client.put(`${baseUrl}/users/${userUuid}`, body, null, ApiRequester.successResponseParser);
3378
- },
3379
-
3380
- updateForwardOption: (userUuid , key , destination , enabled ) => {
3381
- const url = `${baseUrl}/users/${userUuid}/forwards/${key}`;
3382
- return client.put(url, { destination, enabled }, null, ApiRequester.successResponseParser);
3383
- },
3384
-
3385
- updateDoNotDisturb: (userUuid , enabled ) =>
3386
- client.put(`${baseUrl}/users/${userUuid}/services/dnd`, { enabled }, null, ApiRequester.successResponseParser),
3387
-
3388
- getUserLineSip: (userUuid , lineId ) =>
3389
- client.get(`${baseUrl}/users/${userUuid}/lines/${lineId}/associated/endpoints/sip?view=merged`).then(SipLine.parse),
3390
-
3391
- getUserLinesSip(userUuid , lineIds ) {
3392
- // We have to catch all exception, unless Promise.all will returns an empty array for 2 lines with a custom one:
3393
- // The custom line will throw a 404 and break the Promise.all.
3394
- // $FlowFixMe
3395
- return Promise.all(lineIds.map(lineId => this.getUserLineSip(userUuid, lineId).catch(() => null)));
3396
- },
3397
-
3398
- getUserLineSipFromToken(userUuid ) {
3399
- return this.getUser(userUuid).then(user => {
3400
- if (!user.lines.length) {
3401
- console.warn(`No sip line for user: ${userUuid}`);
3402
- return null;
3403
- }
3404
- const line = user.lines[0];
3405
-
3406
- return this.getUserLineSip(userUuid, line.uuid || line.id);
3407
- });
3408
- },
3409
-
3410
- listApplications: () => client.get(`${baseUrl}/applications`, null),
3411
-
3412
- getInfos: () => client.get(`${baseUrl}/infos`, null),
3413
-
3414
- getExternalApps: (userUuid ) =>
3415
- client.get(`${baseUrl}/users/${userUuid}/external/apps`).then(ExternalApp.parseMany),
3416
-
3417
- getExternalApp: async (userUuid , name ) => {
3418
- const url = `${baseUrl}/users/${userUuid}/external/apps/${name}?view=fallback`;
3419
-
3420
- try {
3421
- return await client.get(url).then(ExternalApp.parse);
3422
- } catch (e) {
3423
- return null;
3424
- }
3425
- },
3426
-
3427
- getMyMeetings: () =>
3428
- client.get(`${baseUrl}/users/me/meetings`).then(response => Meeting.parseMany(response.items)),
3429
-
3430
- createMyMeeting: (args ) =>
3431
- client
3432
- .post(`${baseUrl}/users/me/meetings`, convertKeysFromCamelToUnderscore(args))
3433
- .then(Meeting.parse),
3434
-
3435
- updateMyMeeting: (meetingUuid , data ) =>
3436
- client.put(
3437
- `${baseUrl}/users/me/meetings/${meetingUuid}`,
3438
- convertKeysFromCamelToUnderscore(data),
3439
- null,
3440
- ApiRequester.successResponseParser,
3441
- ),
3442
-
3443
- deleteMyMeeting: (meetingUuid ) =>
3444
- client.delete(`${baseUrl}/users/me/meetings/${meetingUuid}`, null),
3445
-
3446
- getMeeting: (meetingUuid ) =>
3447
- client.get(`${baseUrl}/meetings/${meetingUuid}`, null).then(Meeting.parse),
3448
-
3449
- meetingAuthorizations: (meetingUuid ) =>
3450
- client.get(`${baseUrl}/users/me/meetings/${meetingUuid}/authorizations`, null).then(MeetingAuthorization.parseMany),
3451
-
3452
- meetingAuthorizationReject: (meetingUuid , authorizationUuid ) =>
3453
- client.put(
3454
- `${baseUrl}/users/me/meetings/${meetingUuid}/authorizations/${authorizationUuid}/reject`,
3455
- {},
3456
- null,
3457
- ApiRequester.successResponseParser,
3458
- ),
3459
-
3460
- meetingAuthorizationAccept: (meetingUuid , authorizationUuid ) =>
3461
- client.put(
3462
- `${baseUrl}/users/me/meetings/${meetingUuid}/authorizations/${authorizationUuid}/accept`,
3463
- {},
3464
- null,
3465
- ApiRequester.successResponseParser,
3466
- ),
3467
-
3468
- guestGetMeeting: (meetingUuid ) =>
3469
- client.get(`${baseUrl}/guests/me/meetings/${meetingUuid}`, null).then(Meeting.parse),
3470
-
3471
- guestAuthorizationRequest: (userUuid , meetingUuid , username ) =>
3472
- client
3473
- .post(`${baseUrl}/guests/${userUuid}/meetings/${meetingUuid}/authorizations`, { guest_name: username })
3474
- .then(MeetingAuthorization.parse),
3475
-
3476
- guestAuthorizationCheck: (userUuid , meetingUuid , authorizationUuid ) =>
3477
- client.get(`${baseUrl}/guests/${userUuid}/meetings/${meetingUuid}/authorizations/${authorizationUuid}`, null),
3478
-
3479
- });
3480
-
3481
- //
3482
-
3483
-
3484
-
3485
-
3486
-
3487
-
3488
-
3489
-
3490
-
3491
-
3492
-
3493
-
3494
-
3495
-
3496
-
3497
-
3498
-
3499
-
3500
-
3501
-
3502
-
3503
-
3504
-
3505
-
3506
-
3507
-
3508
-
3509
-
3510
- class ChatMessage {
3511
-
3512
-
3513
-
3514
-
3515
-
3516
-
3517
-
3518
-
3519
-
3520
-
3521
- static parseMany(plain ) {
3522
- if (!plain || !plain.items) {
3523
- return [];
3524
- }
3525
-
3526
- return plain.items.map(item => ChatMessage.parse(item));
3527
- }
3528
-
3529
- static parse(plain ) {
3530
- return new ChatMessage({
3531
- uuid: plain.uuid,
3532
- date: moment(plain.created_at).toDate(),
3533
- content: plain.content,
3534
- alias: plain.alias,
3535
- userUuid: plain.user_uuid,
3536
- read: true,
3537
- roomUuid: plain.room ? plain.room.uuid : null,
3538
- });
3539
- }
3540
-
3541
- static newFrom(message ) {
3542
- return newFrom(message, ChatMessage);
3543
- }
3544
-
3545
- constructor({ uuid, date, content, userUuid, alias, roomUuid, read } = {}) {
3546
- this.uuid = uuid;
3547
- this.date = date;
3548
- this.content = content;
3549
- this.userUuid = userUuid;
3550
- this.alias = alias;
3551
- this.roomUuid = roomUuid;
3552
-
3553
- // @TODO: change after message read status available
3554
- this.read = read;
3555
-
3556
- // Useful to compare instead of instanceof with minified code
3557
- this.type = 'ChatMessage';
3558
- }
3559
-
3560
- is(other ) {
3561
- return this.uuid === other.uuid;
3562
- }
3563
-
3564
- isIncoming(userUuid ) {
3565
- return this.userUuid !== userUuid;
3566
- }
3567
-
3568
- acknowledge() {
3569
- // @TODO: change after message read status available
3570
- this.read = true;
3571
- return this;
3572
- }
3573
- }
3574
-
3575
- //
3576
-
3577
-
3578
-
3579
-
3580
-
3581
-
3582
-
3583
-
3584
-
3585
-
3586
-
3587
-
3588
-
3589
-
3590
-
3591
-
3592
-
3593
-
3594
-
3595
-
3596
-
3597
-
3598
-
3599
-
3600
-
3601
-
3602
-
3603
-
3604
-
3605
-
3606
-
3607
-
3608
-
3609
- class Voicemail {
3610
-
3611
-
3612
-
3613
-
3614
-
3615
-
3616
-
3617
-
3618
-
3619
-
3620
-
3621
- static parse(plain ) {
3622
- return new Voicemail({
3623
- id: plain.id,
3624
- date: moment(plain.timestamp * 1000).toDate(),
3625
- duration: plain.duration * 1000,
3626
- caller: {
3627
- name: plain.caller_id_name,
3628
- number: plain.caller_id_num,
3629
- },
3630
- unread: plain.folder ? plain.folder.type === 'new' : null,
3631
- });
3632
- }
3633
-
3634
- static parseMany(plain ) {
3635
- if (!plain) {
3636
- return [];
3637
- }
3638
- const plainUnread = plain.folders.filter(folder => folder.type === 'new')[0].messages;
3639
- const plainRead = plain.folders.filter(folder => folder.type === 'old')[0].messages;
3640
-
3641
- const unread = plainUnread.map(message => Voicemail.parse(message)).map(voicemail => voicemail.makeAsUnRead());
3642
- const read = plainRead.map(message => Voicemail.parse(message)).map(voicemail => voicemail.acknowledge());
3643
-
3644
- return [...unread, ...read];
3645
- }
3646
-
3647
- static newFrom(profile ) {
3648
- return newFrom(profile, Voicemail);
3649
- }
3650
-
3651
- constructor({ id, date, duration, caller, unread } = {}) {
3652
- this.id = id;
3653
- this.date = date;
3654
- this.duration = duration;
3655
- this.caller = caller;
3656
- this.unread = unread;
3657
-
3658
- // Useful to compare instead of instanceof with minified code
3659
- this.type = 'Voicemail';
3660
- }
3661
-
3662
- is(other ) {
3663
- return other && this.id === other.id;
3664
- }
3665
-
3666
- acknowledge() {
3667
- this.unread = false;
3668
-
3669
- return this;
3670
- }
3671
-
3672
- makeAsUnRead() {
3673
- this.unread = true;
3674
-
3675
- return this;
3676
- }
3677
-
3678
- contains(query ) {
3679
- if (!query) {
3680
- return true;
3681
- }
3682
-
3683
- return this.caller.name.toUpperCase().includes(query.toUpperCase()) || this.caller.number.includes(query);
3684
- }
3685
- }
3686
-
3687
- //
3688
- const TRANSFER_FLOW_BLIND = 'blind';
3689
-
3690
- // const MINIMUM_WAZO_ENGINE_VERSION_FOR_CTI_HOLD = '20.11';
3691
-
3692
- IssueReporter$1 ? IssueReporter$1.loggerFor('cti-phone') : console;
3693
-
3694
- /* */
3695
-
3696
-
3697
-
3698
-
3699
-
3700
-
3701
-
3702
-
3703
- var ctidNgMethods = (client , baseUrl ) => ({
3704
- updatePresence: (presence ) =>
3705
- client.put(`${baseUrl}/users/me/presences`, { presence }, null, ApiRequester.successResponseParser),
3706
-
3707
- listMessages: (participantUuid , limit ) => {
3708
- const query = {};
3709
-
3710
- if (participantUuid) {
3711
- query.participant_user_uuid = participantUuid;
3712
- }
3713
-
3714
- if (limit) {
3715
- query.limit = limit;
3716
- }
3717
-
3718
- return client.get(`${baseUrl}/users/me/chats`, query).then(ChatMessage.parseMany);
3719
- },
3720
-
3721
- sendMessage: (alias , msg , toUserId ) => {
3722
- const body = { alias, msg, to: toUserId };
3723
-
3724
- return client.post(`${baseUrl}/users/me/chats`, body, null, ApiRequester.successResponseParser);
3725
- },
3726
-
3727
- makeCall: (extension , fromMobile , lineId , allLines = false) => {
3728
- const query = {
3729
- from_mobile: fromMobile,
3730
- extension,
3731
- };
3732
-
3733
- if (lineId) {
3734
- query.line_id = lineId;
3735
- }
3736
-
3737
- if (allLines) {
3738
- query.all_lines = true;
3739
- }
3740
-
3741
- return client.post(`${baseUrl}/users/me/calls`, query);
3742
- },
3743
-
3744
- cancelCall: (callId ) => client.delete(`${baseUrl}/users/me/calls/${callId}`),
3745
-
3746
- listCalls: () =>
3747
- client.get(`${baseUrl}/users/me/calls`).then(response => Call.parseMany(response.items)),
3748
-
3749
- relocateCall(callId , destination , lineId , contact ) {
3750
- const body = {
3751
- completions: ['answer'],
3752
- destination,
3753
- initiator_call: callId,
3754
- auto_answer: true,
3755
- };
3756
-
3757
- if (lineId || contact) {
3758
- body.location = {};
3759
- }
3760
-
3761
- if (lineId) {
3762
- body.location.line_id = lineId;
3763
- }
3764
-
3765
- if (contact) {
3766
- body.location.contact = contact;
3767
- }
3768
-
3769
- return client.post(`${baseUrl}/users/me/relocates`, body).then(response => Relocation.parse(response));
3770
- },
3771
-
3772
- transferCall(
3773
- callId ,
3774
- number ,
3775
- flow = TRANSFER_FLOW_BLIND,
3776
- ) {
3777
- const body = {
3778
- exten: number,
3779
- flow,
3780
- initiator_call: callId,
3781
- };
3782
-
3783
- return client.post(`${baseUrl}/users/me/transfers`, body).then(response => response);
3784
- },
3785
-
3786
- // @TODO: fix response type
3787
- cancelCallTransfer: (transferId ) =>
3788
- client.delete(`${baseUrl}/users/me/transfers/${transferId}`),
3789
-
3790
- // @TODO: fix response type
3791
- confirmCallTransfer: (transferId ) =>
3792
- client.put(`${baseUrl}/users/me/transfers/${transferId}/complete`),
3793
-
3794
- listVoicemails: () =>
3795
- client.get(`${baseUrl}/users/me/voicemails`, null).then(response => Voicemail.parseMany(response)),
3796
-
3797
- deleteVoicemail: (voicemailId ) =>
3798
- client.delete(`${baseUrl}/users/me/voicemails/messages/${voicemailId}`, null),
3799
-
3800
- getPresence: (contactUuid ) =>
3801
- client.get(`${baseUrl}/users/${contactUuid}/presences`, null),
3802
-
3803
- getStatus: (lineUuid ) => client.get(`${baseUrl}/lines/${lineUuid}/presences`, null),
3804
-
3805
- fetchSwitchboardHeldCalls: (switchboardUuid ) =>
3806
- client.get(`${baseUrl}/switchboards/${switchboardUuid}/calls/held`, null),
3807
-
3808
- holdSwitchboardCall: (switchboardUuid , callId ) =>
3809
- client.put(
3810
- `${baseUrl}/switchboards/${switchboardUuid}/calls/held/${callId}`,
3811
- null,
3812
- null,
3813
- ApiRequester.successResponseParser,
3814
- ),
3815
-
3816
- answerSwitchboardHeldCall: (switchboardUuid , callId ) =>
3817
- client.put(`${baseUrl}/switchboards/${switchboardUuid}/calls/held/${callId}/answer`, null),
3818
-
3819
- fetchSwitchboardQueuedCalls: (switchboardUuid ) =>
3820
- client.get(`${baseUrl}/switchboards/${switchboardUuid}/calls/queued`, null),
3821
-
3822
- answerSwitchboardQueuedCall: (switchboardUuid , callId ) =>
3823
- client.put(`${baseUrl}/switchboards/${switchboardUuid}/calls/queued/${callId}/answer`, null),
3824
-
3825
- sendFax: (extension , fax , callerId = null) => {
3826
- const headers = {
3827
- 'Content-type': 'application/pdf',
3828
- 'X-Auth-Token': client.token,
3829
- };
3830
- const params = ApiRequester.getQueryString({ extension, caller_id: callerId });
3831
-
3832
- return client.post(`${baseUrl}/users/me/faxes?${params}`, fax, headers);
3833
- },
3834
-
3835
- });
3836
-
3837
- /* */
3838
-
3839
-
3840
-
3841
-
3842
- const getContactPayload = (contact ) => ({
3843
- email: contact.email,
3844
- firstname: contact.firstName ? contact.firstName : '',
3845
- lastname: contact.lastName ? contact.lastName : '',
3846
- number: contact.phoneNumber ? contact.phoneNumber : '',
3847
- entreprise: contact.entreprise ? contact.entreprise : '',
3848
- birthday: contact.birthday ? contact.birthday : '',
3849
- address: contact.address ? contact.address : '',
3850
- note: contact.note ? contact.note : '',
3851
- });
3852
-
3853
-
3854
-
3855
-
3856
-
3857
-
3858
-
3859
-
3860
-
3861
-
3862
- var dirdMethods = (client , baseUrl ) => ({
3863
- search: (context , term ) =>
3864
- client.get(`${baseUrl}/directories/lookup/${context}`, { term }).then(Contact.parseMany),
3865
-
3866
- listPersonalContacts: (queryParams = null) =>
3867
- client.get(`${baseUrl}/personal`, queryParams).then(response => Contact.parseManyPersonal(response.items)),
3868
-
3869
- fetchPersonalContact: (contactUuid ) =>
3870
- client
3871
- .get(`${baseUrl}/personal/${contactUuid}`)
3872
- .then(Contact.parsePersonal),
3873
-
3874
- addContact: (contact ) =>
3875
- client.post(`${baseUrl}/personal`, getContactPayload(contact)).then(Contact.parsePersonal),
3876
-
3877
- editContact: (contact ) =>
3878
- client
3879
- .put(`${baseUrl}/personal/${contact.sourceId || contact.id || ''}`, getContactPayload(contact))
3880
- .then(Contact.parsePersonal),
3881
-
3882
- importContacts: (csv ) => {
3883
- const headers = {
3884
- 'Content-Type': 'text/csv; charset=utf-8',
3885
- 'X-Auth-Token': client.token,
3886
- };
3887
-
3888
- return client.post(`${baseUrl}/personal/import`, csv, headers)
3889
- .then(result => Contact.parseManyPersonal(result.created));
3890
- },
3891
-
3892
- deleteContact: (contactUuid ) => client.delete(`${baseUrl}/personal/${contactUuid}`),
3893
-
3894
- listFavorites: (context ) =>
3895
- client.get(`${baseUrl}/directories/favorites/${context}`).then(Contact.parseMany),
3896
-
3897
- markAsFavorite: (source , sourceId ) => {
3898
- const url = `${baseUrl}/directories/favorites/${source}/${sourceId}`;
3899
-
3900
- return client.put(url, null, null, ApiRequester.successResponseParser);
3901
- },
3902
-
3903
- removeFavorite: (source , sourceId ) =>
3904
- client.delete(`${baseUrl}/directories/favorites/${source}/${sourceId}`),
3905
-
3906
- fetchOffice365Source: (context ) =>
3907
- client.get(`${baseUrl}/directories/${context}/sources`, { backend: 'office365' }),
3908
-
3909
- fetchOffice365Contacts: (source ,
3910
- queryParams = null) => {
3911
- if (!source) {
3912
- return null;
3913
- }
3914
-
3915
- return client
3916
- .get(`${baseUrl}/backends/office365/sources/${source.uuid}/contacts`, queryParams)
3917
- .then(response => Contact.parseManyOffice365(response.items, source));
3918
- },
3919
-
3920
- fetchWazoSource: (context ) =>
3921
- client.get(`${baseUrl}/directories/${context}/sources`, { backend: 'wazo' }),
3922
-
3923
- // Can be used with `queryParams = { uuid: uuid1, uuid2 }` to fetch multiple contacts
3924
- fetchWazoContacts: (source , queryParams = null) => {
3925
- if (!source) {
3926
- return null;
3927
- }
3928
- return client
3929
- .get(`${baseUrl}/backends/wazo/sources/${source.uuid}/contacts`, queryParams)
3930
- .then(response => Contact.parseManyWazo(response.items, source));
3931
- },
3932
-
3933
- fetchGoogleSource: (context ) =>
3934
- client.get(`${baseUrl}/directories/${context}/sources`, { backend: 'google' }),
3935
-
3936
- fetchGoogleContacts: (source , queryParams = null) => {
3937
- if (!source) {
3938
- return null;
3939
- }
3940
-
3941
- return client
3942
- .get(`${baseUrl}/backends/google/sources/${source.uuid}/contacts`, queryParams)
3943
- .then(response => Contact.parseManyGoogle(response.items, source));
3944
- },
3945
-
3946
- fetchConferenceSource: (context ) =>
3947
- client.get(`${baseUrl}/directories/${context}/sources`, { backend: 'conference' }),
3948
-
3949
- fetchConferenceContacts: (source ) => {
3950
- if (!source) {
3951
- return null;
3952
- }
3953
-
3954
- return client
3955
- .get(`${baseUrl}/backends/conference/sources/${source.uuid}/contacts`)
3956
- .then(response => Contact.parseManyConference(response.items, source));
3957
- },
3958
-
3959
- // Graphql
3960
- findMultipleContactsByNumber: (numbers , fields = null) => {
3961
- const query = jsonToGraphQLQuery({
3962
- me: {
3963
- contacts: {
3964
- __args: {
3965
- profile: 'default',
3966
- extens: numbers,
3967
- },
3968
- edges: {
3969
- node: fields || {
3970
- firstname: true,
3971
- lastname: true,
3972
- wazoReverse: true,
3973
- wazoBackend: true,
3974
- email: true,
3975
- wazoSourceEntryId: true,
3976
- wazoSourceName: true,
3977
- '... on WazoContact': {
3978
- userUuid: true,
3979
- },
3980
- },
3981
- },
3982
- },
3983
- },
3984
- });
3985
-
3986
- return client.post(`${baseUrl}/graphql`, { query: `{${query}}` })
3987
- .then(Contact.manyGraphQlWithNumbersParser(numbers));
3988
- },
3989
-
3990
- });
3991
-
3992
- /* */
3993
-
3994
- var callLogdMethods = (client , baseUrl ) => ({
3995
- search: (search , limit = 5) =>
3996
- client.get(`${baseUrl}/users/me/cdr`, { search, limit }).then(CallLog.parseMany),
3997
-
3998
- searchBy: (field , value , limit = 5) =>
3999
- client.get(`${baseUrl}/users/me/cdr`, { [field]: value, limit }).then(CallLog.parseMany),
4000
-
4001
- listCallLogs: (offset , limit = 5) =>
4002
- client.get(`${baseUrl}/users/me/cdr`, { offset, limit }).then(CallLog.parseMany),
4003
-
4004
- listDistinctCallLogs: (offset , limit = 5, distinct ) =>
4005
- client.get(`${baseUrl}/users/me/cdr`, { offset, limit, distinct }).then(CallLog.parseMany),
4006
-
4007
- listCallLogsFromDate: (from , number ) =>
4008
- client.get(`${baseUrl}/users/me/cdr`, { from: from.toISOString(), number }).then(CallLog.parseMany),
4009
- });
4010
-
4011
- //
4012
-
4013
-
4014
-
4015
-
4016
-
4017
-
4018
-
4019
-
4020
-
4021
-
4022
-
4023
-
4024
-
4025
- class ChatRoom {
4026
-
4027
-
4028
-
4029
-
4030
-
4031
-
4032
- static parseMany(plain ) {
4033
- if (!plain || !plain.items) {
4034
- return [];
4035
- }
4036
- return plain.items.map(item => ChatRoom.parse(item));
4037
- }
4038
-
4039
- static parse(plain ) {
4040
- return new ChatRoom({
4041
- uuid: plain.uuid,
4042
- name: plain.name,
4043
- users: plain.users,
4044
- });
4045
- }
4046
-
4047
- static newFrom(room ) {
4048
- return newFrom(room, ChatRoom);
4049
- }
4050
-
4051
- constructor({ uuid, name, users } = {}) {
4052
- this.uuid = uuid;
4053
- this.name = name;
4054
- this.users = users;
4055
-
4056
- // Useful to compare instead of instanceof with minified code
4057
- this.type = 'ChatRoom';
4058
- }
4059
- }
4060
-
4061
- /* */
4062
-
4063
-
4064
-
4065
-
4066
-
4067
-
4068
-
4069
-
4070
-
4071
-
4072
-
4073
-
4074
-
4075
-
4076
-
4077
-
4078
-
4079
-
4080
-
4081
-
4082
-
4083
-
4084
-
4085
-
4086
- var chatdMethods = (client , baseUrl ) => ({
4087
- updateState: (contactUuid , state ) =>
4088
- client.put(`${baseUrl}/users/${contactUuid}/presences`, { state }, null, ApiRequester.successResponseParser),
4089
-
4090
- updateStatus: (contactUuid , state , status ) => {
4091
- const body = { state, status };
4092
-
4093
- return client.put(`${baseUrl}/users/${contactUuid}/presences`, body, null, ApiRequester.successResponseParser);
4094
- },
4095
-
4096
- getState: async (contactUuid ) =>
4097
- client.get(`${baseUrl}/users/${contactUuid}/presences`).then((response ) => response.state),
4098
-
4099
- getContactStatusInfo: async (contactUuid ) =>
4100
- client.get(`${baseUrl}/users/${contactUuid}/presences`).then((response ) => response),
4101
-
4102
- getLineState: async (contactUuid ) =>
4103
- client
4104
- .get(`${baseUrl}/users/${contactUuid}/presences`)
4105
- .then((response ) => Profile.getLinesState(response.lines)),
4106
-
4107
- getMultipleLineState: async (contactUuids ) => {
4108
- const body = {};
4109
- if (contactUuids && contactUuids.length) {
4110
- body.user_uuid = contactUuids.join(',');
4111
- }
4112
-
4113
- return client.get(`${baseUrl}/users/presences`, body).then((response ) => response.items);
4114
- },
4115
-
4116
- getUserRooms: async () => client.get(`${baseUrl}/users/me/rooms`).then(ChatRoom.parseMany),
4117
-
4118
- createRoom: async (name , users ) =>
4119
- client.post(`${baseUrl}/users/me/rooms`, { name, users }).then(ChatRoom.parse),
4120
-
4121
- getRoomMessages: async (roomUuid , params = {}) => {
4122
- const qs = ApiRequester.getQueryString(params);
4123
-
4124
- return client
4125
- .get(`${baseUrl}/users/me/rooms/${roomUuid}/messages${qs.length ? `?${qs}` : ''}`)
4126
- .then((response ) => ChatMessage.parseMany(response));
4127
- },
4128
-
4129
- sendRoomMessage: async (roomUuid , message ) =>
4130
- client.post(`${baseUrl}/users/me/rooms/${roomUuid}/messages`, message).then(ChatMessage.parse),
4131
-
4132
- getMessages: async (options ) =>
4133
- client.get(`${baseUrl}/users/me/rooms/messages`, options),
4134
- });
4135
-
4136
- //
4137
-
4138
-
4139
-
4140
-
4141
-
4142
-
4143
-
4144
-
4145
-
4146
-
4147
-
4148
-
4149
-
4150
-
4151
-
4152
-
4153
-
4154
-
4155
- class IndirectTransfer {
4156
-
4157
-
4158
-
4159
-
4160
-
4161
-
4162
-
4163
-
4164
- constructor({ sourceId, destinationId, status, id } ) {
4165
- this.sourceId = sourceId;
4166
- this.destinationId = destinationId;
4167
- this.status = status;
4168
- this.id = id;
4169
- }
4170
-
4171
- static parseFromCallSession(source , destination ) {
4172
- return new IndirectTransfer({
4173
- sourceId: source.getId(),
4174
- destinationId: destination.getId(),
4175
- });
4176
- }
4177
-
4178
- static parseFromApi(plain ) {
4179
- return new IndirectTransfer({
4180
- id: plain.id,
4181
- status: plain.status,
4182
- sourceId: plain.initiator_call,
4183
- destinationId: plain.recipient_call,
4184
- });
4185
- }
4186
-
4187
- destinationIs(callSession ) {
4188
- return callSession.isId(this.destinationId);
4189
- }
4190
-
4191
- sourceIs(callSession ) {
4192
- return callSession.isId(this.sourceId);
4193
- }
4194
-
4195
- updateFrom(indirectTransfer ) {
4196
- updateFrom(this, indirectTransfer);
4197
- }
4198
-
4199
- static newFrom(indirectTransfer ) {
4200
- return newFrom(indirectTransfer, IndirectTransfer);
4201
- }
4202
- }
4203
-
4204
- //
4205
-
4206
-
4207
-
4208
-
4209
-
4210
- class MeetingStatus {
4211
-
4212
-
4213
-
4214
-
4215
- constructor({
4216
- full,
4217
- } = {}) {
4218
- this.full = full;
4219
-
4220
- // Useful to compare instead of instanceof with minified code
4221
- this.type = 'MeetingStatus';
4222
- }
4223
-
4224
- static parse(plain ) {
4225
- return new MeetingStatus({
4226
- full: plain.full,
4227
- });
4228
- }
4229
-
4230
- }
4231
-
4232
- /* */
4233
-
4234
-
4235
-
4236
-
4237
-
4238
-
4239
-
4240
-
4241
- var calldMethods = (client , baseUrl ) => ({
4242
- updatePresence: (presence ) =>
4243
- client.put(`${baseUrl}/users/me/presences`, { presence }, null, ApiRequester.successResponseParser),
4244
-
4245
- listMessages: (participantUuid , limit ) => {
4246
- const query = {};
4247
-
4248
- if (participantUuid) {
4249
- query.participant_user_uuid = participantUuid;
4250
- }
4251
-
4252
- if (limit) {
4253
- query.limit = limit;
4254
- }
4255
-
4256
- return client.get(`${baseUrl}/users/me/chats`, query).then(response => ChatMessage.parseMany(response));
4257
- },
4258
-
4259
- sendMessage: (alias , msg , toUserId ) => {
4260
- const body = { alias, msg, to: toUserId };
4261
-
4262
- return client.post(`${baseUrl}/users/me/chats`, body, null, ApiRequester.successResponseParser);
4263
- },
4264
-
4265
- makeCall: (extension , fromMobile , lineId , allLines = false) => {
4266
- const query = {
4267
- from_mobile: fromMobile,
4268
- extension,
4269
- };
4270
-
4271
- if (lineId) {
4272
- query.line_id = lineId;
4273
- }
4274
-
4275
- if (allLines) {
4276
- query.all_lines = true;
4277
- }
4278
-
4279
- return client.post(`${baseUrl}/users/me/calls`, query);
4280
- },
4281
-
4282
- cancelCall: (callId ) => client.delete(`${baseUrl}/users/me/calls/${callId}`, null),
4283
-
4284
- listCalls: () =>
4285
- client.get(`${baseUrl}/users/me/calls`, null).then(response => Call.parseMany(response.items)),
4286
-
4287
- relocateCall(callId , destination , lineId , contact ) {
4288
- const body = {
4289
- completions: ['answer'],
4290
- destination,
4291
- initiator_call: callId,
4292
- auto_answer: true,
4293
- };
4294
-
4295
- if (lineId || contact) {
4296
- body.location = {};
4297
- }
4298
-
4299
- if (lineId) {
4300
- body.location.line_id = lineId;
4301
- }
4302
-
4303
- if (contact) {
4304
- body.location.contact = contact;
4305
- }
4306
-
4307
- return client.post(`${baseUrl}/users/me/relocates`, body).then(response => Relocation.parse(response));
4308
- },
4309
-
4310
- listVoicemails: () =>
4311
- client.get(`${baseUrl}/users/me/voicemails`).then(response => Voicemail.parseMany(response)),
4312
-
4313
- deleteVoicemail: (voicemailId ) =>
4314
- client.delete(`${baseUrl}/users/me/voicemails/messages/${voicemailId}`),
4315
-
4316
- getVoicemailUrl: (voicemail ) => {
4317
- const body = { token: client.token };
4318
-
4319
- return client.computeUrl('get', `${baseUrl}/users/me/voicemails/messages/${voicemail.id}/recording`, body);
4320
- },
4321
-
4322
- fetchSwitchboardHeldCalls: (switchboardUuid ) =>
4323
- client.get(`${baseUrl}/switchboards/${switchboardUuid}/calls/held`),
4324
-
4325
- holdSwitchboardCall: (switchboardUuid , callId ) =>
4326
- client.put(
4327
- `${baseUrl}/switchboards/${switchboardUuid}/calls/held/${callId}`,
4328
- null,
4329
- null,
4330
- ApiRequester.successResponseParser,
4331
- ),
4332
-
4333
- answerSwitchboardHeldCall: (switchboardUuid , callId , lineId = null) =>
4334
- client.put(
4335
- `${baseUrl}/switchboards/${switchboardUuid}/calls/held/${callId}/answer${lineId ? `?line_id=${lineId}` : ''}`,
4336
- ),
4337
-
4338
- fetchSwitchboardQueuedCalls: (switchboardUuid ) =>
4339
- client.get(`${baseUrl}/switchboards/${switchboardUuid}/calls/queued`),
4340
-
4341
- answerSwitchboardQueuedCall: (switchboardUuid , callId , lineId = null) =>
4342
- client.put(
4343
- `${baseUrl}/switchboards/${switchboardUuid}/calls/queued/${callId}/answer${lineId ? `?line_id=${lineId}` : ''}`,
4344
- ),
4345
-
4346
- sendFax: (extension , fax , callerId = null) => {
4347
- const headers = {
4348
- 'Content-type': 'application/pdf',
4349
- 'X-Auth-Token': client.token,
4350
- };
4351
- const params = ApiRequester.getQueryString({ extension, caller_id: callerId });
4352
-
4353
- return client.post(`${baseUrl}/users/me/faxes?${params}`, fax, headers);
4354
- },
4355
-
4356
- getConferenceParticipantsAsUser: async (conferenceId ) =>
4357
- client.get(`${baseUrl}/users/me/conferences/${conferenceId}/participants`),
4358
-
4359
- getMeetingParticipantsAsUser: async (meetingUuid ) =>
4360
- client.get(`${baseUrl}/users/me/meetings/${meetingUuid}/participants`),
4361
-
4362
- banMeetingParticipant: (meetingUuid , participantUuid ) =>
4363
- client.delete(
4364
- `${baseUrl}/users/me/meetings/${meetingUuid}/participants/${participantUuid}`,
4365
- null,
4366
- null,
4367
- ApiRequester.successResponseParser,
4368
- ),
4369
-
4370
- listTrunks: () => client.get(`${baseUrl}/trunks`),
4371
-
4372
- mute: (callId ) =>
4373
- client.put(`${baseUrl}/users/me/calls/${callId}/mute/start`, null, null, ApiRequester.successResponseParser),
4374
-
4375
- unmute: (callId ) =>
4376
- client.put(`${baseUrl}/users/me/calls/${callId}/mute/stop`, null, null, ApiRequester.successResponseParser),
4377
-
4378
- hold: (callId ) =>
4379
- client.put(`${baseUrl}/users/me/calls/${callId}/hold/start`, null, null, ApiRequester.successResponseParser),
4380
-
4381
- resume: (callId ) =>
4382
- client.put(`${baseUrl}/users/me/calls/${callId}/hold/stop`, null, null, ApiRequester.successResponseParser),
4383
-
4384
- // eslint-disable-next-line camelcase
4385
- transferCall: (initiator_call , exten , flow ) =>
4386
- client.post(`${baseUrl}/users/me/transfers`, { initiator_call, exten, flow }).then(IndirectTransfer.parseFromApi),
4387
-
4388
- confirmCallTransfer: (transferId ) => client.put(`${baseUrl}/users/me/transfers/${transferId}/complete`),
4389
-
4390
- cancelCallTransfer: (transferId ) => client.delete(`${baseUrl}/users/me/transfers/${transferId}`),
4391
-
4392
- sendDTMF: (callId , digits ) =>
4393
- client.put(`${baseUrl}/users/me/calls/${callId}/dtmf?digits=${encodeURIComponent(digits)}`,
4394
- null, null, ApiRequester.successResponseParser),
4395
-
4396
- // @deprecated: check for engine version >= 20.12 instead
4397
- isAhHocConferenceAPIEnabled: () => client.head(`${baseUrl}/users/me/conferences/adhoc`, null, null,
4398
- ApiRequester.successResponseParser),
4399
-
4400
- createAdHocConference: (hostCallId , participantCallIds ) =>
4401
- client.post(`${baseUrl}/users/me/conferences/adhoc`, {
4402
- host_call_id: hostCallId,
4403
- participant_call_ids: participantCallIds,
4404
- }),
4405
-
4406
- addAdHocConferenceParticipant: (conferenceId , callId ) =>
4407
- client.put(`${baseUrl}/users/me/conferences/adhoc/${conferenceId}/participants/${callId}`, null, null,
4408
- ApiRequester.successResponseParser),
4409
-
4410
- removeAdHocConferenceParticipant: (conferenceId , participantCallId ) =>
4411
- client.delete(`${baseUrl}/users/me/conferences/adhoc/${conferenceId}/participants/${participantCallId}`, null, null,
4412
- ApiRequester.successResponseParser),
4413
-
4414
- deleteAdHocConference: (conferenceId ) =>
4415
- client.delete(`${baseUrl}/users/me/conferences/adhoc/${conferenceId}`, null, null,
4416
- ApiRequester.successResponseParser),
4417
-
4418
- startRecording: (callId ) =>
4419
- client.put(`${baseUrl}/users/me/calls/${callId}/record/start`, null, null,
4420
- ApiRequester.successResponseParser),
4421
-
4422
- stopRecording: (callId ) =>
4423
- client.put(`${baseUrl}/users/me/calls/${callId}/record/stop`, null, null,
4424
- ApiRequester.successResponseParser),
4425
-
4426
- pauseRecording: (callId ) =>
4427
- client.put(`${baseUrl}/users/me/calls/${callId}/record/pause`, null, null,
4428
- ApiRequester.successResponseParser),
4429
-
4430
- resumeRecording: (callId ) =>
4431
- client.put(`${baseUrl}/users/me/calls/${callId}/record/resume`, null, null,
4432
- ApiRequester.successResponseParser),
4433
-
4434
- guestGetMeetingStatus: (meetingUuid ) =>
4435
- client.get(`${baseUrl}/guests/me/meetings/${meetingUuid}/status`).then(MeetingStatus.parse),
4436
- });
4437
-
4438
- //
4439
-
4440
-
4441
-
4442
-
4443
-
4444
-
4445
-
4446
-
4447
-
4448
-
4449
-
4450
-
4451
-
4452
-
4453
-
4454
-
4455
-
4456
-
4457
-
4458
-
4459
-
4460
- class Agent {
4461
-
4462
-
4463
-
4464
-
4465
-
4466
-
4467
-
4468
-
4469
-
4470
- static parse(plain ) {
4471
- return new Agent({
4472
- context: plain.context,
4473
- extension: plain.extension,
4474
- id: plain.id,
4475
- logged: plain.logged,
4476
- number: plain.number,
4477
- paused: plain.paused,
4478
- pausedReason: plain.paused_reason,
4479
- });
4480
- }
4481
-
4482
- constructor({
4483
- context,
4484
- extension,
4485
- id,
4486
- logged,
4487
- number,
4488
- paused,
4489
- pausedReason,
4490
- } ) {
4491
- this.context = context;
4492
- this.extension = extension;
4493
- this.id = id;
4494
- this.logged = logged;
4495
- this.number = number;
4496
- this.paused = paused;
4497
- this.pausedReason = pausedReason;
4498
- }
4499
- }
4500
-
4501
- /* */
4502
-
4503
- var agentdMethods = (client , baseUrl ) => ({
4504
- getAgent: (agentId ) =>
4505
- client.get(`${baseUrl}/agents/by-id/${agentId}`, null).then(Agent.parse),
4506
-
4507
- login: (agentNumber , context , extension ) =>
4508
- client.post(
4509
- `${baseUrl}/agents/by-number/${agentNumber}/login`,
4510
- { context, extension },
4511
- null,
4512
- ApiRequester.successResponseParser,
4513
- ),
4514
-
4515
- loginWithLineId: (lineId ) =>
4516
- client.post(
4517
- `${baseUrl}/users/me/agents/login`,
4518
- { line_id: lineId },
4519
- null,
4520
- ApiRequester.successResponseParser,
4521
- ),
4522
-
4523
- logout: (agentNumber ) =>
4524
- client.post(
4525
- `${baseUrl}/agents/by-number/${agentNumber}/logoff`,
4526
- null,
4527
- null,
4528
- ApiRequester.successResponseParser,
4529
- ),
4530
-
4531
- pause: (agentNumber ) =>
4532
- client.post(
4533
- `${baseUrl}/agents/by-number/${agentNumber}/pause`,
4534
- { reason: 'songbird_reason' },
4535
- null,
4536
- ApiRequester.successResponseParser,
4537
- ),
4538
-
4539
- resume: (agentNumber ) =>
4540
- client.post(
4541
- `${baseUrl}/agents/by-number/${agentNumber}/unpause`,
4542
- null,
4543
- null,
4544
- ApiRequester.successResponseParser,
4545
- ),
4546
-
4547
- getStatus: () => client.get(`${baseUrl}/users/me/agents`, null).then(Agent.parse),
4548
-
4549
- staticLogout: () =>
4550
- client.post(
4551
- `${baseUrl}/users/me/agents/logoff`,
4552
- null,
4553
- null,
4554
- ApiRequester.successResponseParser,
4555
- ),
4556
-
4557
- staticPause: () =>
4558
- client.post(
4559
- `${baseUrl}/users/me/agents/pause`,
4560
- { reason: 'songbird_reason' },
4561
- null,
4562
- ApiRequester.successResponseParser,
4563
- ),
4564
-
4565
- staticResume: () =>
4566
- client.post(
4567
- `${baseUrl}/users/me/agents/unpause`,
4568
- null,
4569
- null,
4570
- ApiRequester.successResponseParser,
4571
- ),
4572
- });
4573
-
4574
- //
4575
-
4576
-
4577
-
4578
-
4579
-
4580
-
4581
-
4582
-
4583
-
4584
-
4585
-
4586
-
4587
-
4588
-
4589
-
4590
-
4591
-
4592
-
4593
-
4594
-
4595
-
4596
-
4597
-
4598
-
4599
-
4600
-
4601
-
4602
- class Subscription {
4603
-
4604
-
4605
-
4606
-
4607
-
4608
-
4609
-
4610
-
4611
-
4612
-
4613
-
4614
-
4615
- static parse(plain ) {
4616
- return new Subscription({
4617
- name: plain.name,
4618
- events: plain.events,
4619
- config: plain.config,
4620
- uuid: plain.uuid,
4621
- service: plain.service,
4622
- eventsUserUuid: plain.events_user_uuid,
4623
- eventsWazoUuid: plain.events_wazo_uuid,
4624
- metadata: plain.metadata,
4625
- ownerTenantUuid: plain.owner_tenant_uuid,
4626
- ownerUserUuid: plain.owner_user_uuid,
4627
- });
4628
- }
4629
-
4630
- static parseMany(response ) {
4631
- return response.items.map(payload => Subscription.parse(payload));
4632
- }
4633
-
4634
- constructor({
4635
- name,
4636
- events,
4637
- config,
4638
- uuid,
4639
- service,
4640
- eventsUserUuid,
4641
- eventsWazoUuid,
4642
- metadata,
4643
- ownerTenantUuid,
4644
- ownerUserUuid,
4645
- } ) {
4646
- this.name = name;
4647
- this.events = events;
4648
- this.config = config;
4649
- this.uuid = uuid;
4650
- this.service = service;
4651
- this.eventsUserUuid = eventsUserUuid;
4652
- this.eventsWazoUuid = eventsWazoUuid;
4653
- this.metadata = metadata;
4654
- this.ownerTenantUuid = ownerTenantUuid;
4655
- this.ownerUserUuid = ownerUserUuid;
4656
- }
4657
- }
4658
-
4659
- /* */
4660
-
4661
-
4662
-
4663
-
4664
-
4665
-
4666
-
4667
-
4668
-
4669
-
4670
-
4671
-
4672
-
4673
-
4674
-
4675
- var webhookdMethods = (client , baseUrl ) => ({
4676
- getSubscriptions: () =>
4677
- client.get(`${baseUrl}/users/me/subscriptions`).then(Subscription.parseMany),
4678
-
4679
- getSubscription: (uuid ) =>
4680
- client.get(`${baseUrl}/users/me/subscriptions/${uuid}`).then(Subscription.parse),
4681
-
4682
- createSubscription: (payload ) =>
4683
- client.post(`${baseUrl}/users/me/subscriptions`, payload),
4684
-
4685
- removeSubscription: (uuid ) =>
4686
- client.delete(`${baseUrl}/users/me/subscriptions/${uuid}`),
4687
- });
4688
-
4689
- /* */
4690
-
4691
- var amidMethods = (client , baseUrl ) => ({
4692
- action: (action , args = {}) =>
4693
- client.post(`${baseUrl}/action/${action}`, args),
4694
-
4695
- getAors: async (endpoint ) => {
4696
- const rawEvents = await client.post(`${baseUrl}/action/PJSIPShowEndpoint`, { Endpoint: endpoint });
4697
-
4698
- return rawEvents.filter(event => event.Event === 'ContactStatusDetail');
4699
- },
4700
- });
4701
-
4702
- /* */
4703
-
4704
-
4705
-
4706
-
4707
-
4708
-
4709
-
4710
-
4711
-
4712
-
4713
- const AUTH_VERSION = '0.1';
4714
- const APPLICATION_VERSION = '1.0';
4715
- const CONFD_VERSION = '1.1';
4716
- const CTIDNG_VERSION = '1.0';
4717
- const DIRD_VERSION = '0.1';
4718
- const CALL_LOGD_VERSION = '1.0';
4719
- const CHATD_VERSION = '1.0';
4720
- const CALLD_VERSION = '1.0';
4721
- const AGENTD_VERSION = '1.0';
4722
- const WEBHOOKD_VERSION = '1.0';
4723
- const AMID_VERSION = '1.0';
4724
-
4725
- const logger = IssueReporter$1 ? IssueReporter$1.loggerFor('api') : console;
4726
-
4727
- class ApiClient {
4728
-
4729
-
4730
-
4731
-
4732
-
4733
-
4734
-
4735
-
4736
-
4737
-
4738
-
4739
-
4740
-
4741
-
4742
-
4743
-
4744
-
4745
-
4746
-
4747
-
4748
-
4749
-
4750
-
4751
- // @see https://github.com/facebook/flow/issues/183#issuecomment-358607052
4752
- constructor({ server, agent = null, refreshToken, clientId, isMobile = false, fetchOptions } ) {
4753
- this.updateParameters({ server, agent, clientId, fetchOptions });
4754
- this.refreshToken = refreshToken;
4755
- this.isMobile = isMobile || false;
4756
- }
4757
-
4758
- initializeEndpoints() {
4759
- this.auth = authMethods(this.client, `auth/${AUTH_VERSION}`);
4760
- this.application = applicationMethods(this.client, `calld/${APPLICATION_VERSION}/applications`);
4761
- this.confd = confdMethods(this.client, `confd/${CONFD_VERSION}`);
4762
- this.ctidNg = ctidNgMethods(this.client, `ctid-ng/${CTIDNG_VERSION}`);
4763
- this.dird = dirdMethods(this.client, `dird/${DIRD_VERSION}`);
4764
- this.callLogd = callLogdMethods(this.client, `call-logd/${CALL_LOGD_VERSION}`);
4765
- this.chatd = chatdMethods(this.client, `chatd/${CHATD_VERSION}`);
4766
- this.calld = calldMethods(this.client, `calld/${CALLD_VERSION}`);
4767
- this.agentd = agentdMethods(this.client, `agentd/${AGENTD_VERSION}`);
4768
- this.webhookd = webhookdMethods(this.client, `webhookd/${WEBHOOKD_VERSION}`);
4769
- this.amid = amidMethods(this.client, `amid/${AMID_VERSION}`);
4770
- }
4771
-
4772
- updateParameters({ server, agent, clientId, fetchOptions } ) {
4773
- const refreshTokenCallback = this.refreshTokenCallback.bind(this);
4774
- this.client = new ApiRequester({ server, agent, refreshTokenCallback, clientId, fetchOptions });
4775
-
4776
- this.initializeEndpoints();
4777
- }
4778
-
4779
- async forceRefreshToken() {
4780
- logger.info('forcing refresh token, calling callback');
4781
- return this.refreshTokenCallback();
4782
- }
4783
-
4784
- async refreshTokenCallback() {
4785
- logger.info('refresh token callback called', {
4786
- refreshToken: this.refreshToken,
4787
- refreshBackend: this.refreshBackend,
4788
- refreshTenantId: this.refreshTenantId,
4789
- refreshDomainName: this.refreshDomainName,
4790
- refreshExpiration: this.refreshExpiration,
4791
- isMobile: this.isMobile,
4792
- });
4793
-
4794
- if (!this.refreshToken) {
4795
- return null;
4796
- }
4797
-
4798
- try {
4799
- const session = await this.auth.refreshToken(
4800
- this.refreshToken,
4801
- this.refreshBackend,
4802
- this.refreshExpiration,
4803
- this.isMobile,
4804
- this.refreshTenantId,
4805
- this.refreshDomainName,
4806
- );
4807
-
4808
- logger.info('token refreshed', { token: session.token });
4809
-
4810
- if (this.onRefreshToken) {
4811
- this.onRefreshToken(session.token, session);
4812
- }
4813
-
4814
- this.setToken(session.token);
4815
-
4816
- return session.token;
4817
- } catch (error) {
4818
- logger.error('token refresh, error', error);
4819
-
4820
- if (this.onRefreshTokenError) {
4821
- this.onRefreshTokenError(error);
4822
- }
4823
- }
4824
- }
4825
-
4826
- setToken(token ) {
4827
- this.client.setToken(token);
4828
- }
4829
-
4830
- setTenant(tenant ) {
4831
- this.client.setTenant(tenant);
4832
- }
4833
-
4834
- setRefreshToken(refreshToken ) {
4835
- this.refreshToken = refreshToken;
4836
- }
4837
-
4838
- setClientId(clientId ) {
4839
- this.client.clientId = clientId;
4840
- }
4841
-
4842
- setOnRefreshToken(onRefreshToken ) {
4843
- this.onRefreshToken = onRefreshToken;
4844
- }
4845
-
4846
- setOnRefreshTokenError(callback ) {
4847
- this.onRefreshTokenError = callback;
4848
- }
4849
-
4850
- setRefreshExpiration(refreshExpiration ) {
4851
- this.refreshExpiration = refreshExpiration;
4852
- }
4853
-
4854
- setRefreshBackend(refreshBackend ) {
4855
- this.refreshBackend = refreshBackend;
4856
- }
4857
-
4858
- setRefreshTenantId(tenantId ) {
4859
- console.warn('Use of `setRefreshTenantId` is deprecated, use `setRefreshDomainName` instead');
4860
- this.refreshTenantId = tenantId;
4861
- }
4862
-
4863
- setRefreshDomainName(domainName ) {
4864
- this.refreshDomainName = domainName;
4865
- }
4866
-
4867
- setIsMobile(isMobile ) {
4868
- this.isMobile = isMobile;
4869
- }
4870
-
4871
- setFetchOptions(fetchOptions ) {
4872
- this.fetchOptions = fetchOptions;
4873
- this.client.setFetchOptions(fetchOptions);
4874
- }
4875
-
4876
- disableErrorLogging() {
4877
- this.client.disableErrorLogging();
4878
- }
4879
- }
4880
-
4881
- /* eslint-disable dot-notation */
4882
-
4883
- // Can't use node cache mechanism here because when requiring lib/CallApi.js
4884
- // this file will be merge with CallApi.js and the cache will be lost.
4885
- // So we have to store values in global scope.
4886
- global.wazoClients = global.wazoClients || {};
4887
- global.wazoClientId = global.wazoClientId || {};
4888
- global.wazoClientToken = global.wazoClientToken || {};
4889
- global.wazoRefreshToken = global.wazoRefreshToken || {};
4890
- global.wazoRefreshTenantId = global.wazoRefreshTenantId || {};
4891
- global.wazoRefreshDomainName = global.wazoRefreshDomainName || {};
4892
- global.wazoOnRefreshToken = global.wazoOnRefreshToken || {};
4893
- global.wazoOnRefreshTokenError = global.wazoOnRefreshTokenError || {};
4894
- global.wazoRefreshExpiration = global.wazoRefreshExpiration || {};
4895
- global.wazoRefreshBackend = global.wazoRefreshBackend || {};
4896
- global.wazoIsMobile = global.wazoIsMobile || {};
4897
- global.wazoFetchOptions = global.wazoFetchOptions || {};
4898
-
4899
- const fillClient = (apiClient ) => {
4900
- const { server, token, clientId } = apiClient.client;
4901
- const tenantId = global.wazoRefreshTenantId[server] || global.wazoRefreshTenantId[null] || apiClient.refreshTenantId;
4902
-
4903
- // try with null server when dealing with non-related server info
4904
- apiClient.setToken(global.wazoClientToken[server] || global.wazoClientToken[null] || token);
4905
-
4906
- apiClient.setClientId(global.wazoClientId[server] || global.wazoClientId[null] || clientId);
4907
-
4908
- apiClient.setRefreshToken(global.wazoRefreshToken[server] || global.wazoRefreshToken[null] || apiClient.refreshToken);
4909
-
4910
- if (tenantId) {
4911
- apiClient.setRefreshTenantId(tenantId);
4912
- }
4913
-
4914
- apiClient.setRefreshDomainName(
4915
- global.wazoRefreshDomainName[server] || global.wazoRefreshDomainName[null] || apiClient.refreshDomainName,
4916
- );
4917
-
4918
- apiClient.setFetchOptions(global.wazoFetchOptions[server] || global.wazoFetchOptions[null] || apiClient.fetchOptions);
4919
-
4920
- apiClient.setOnRefreshToken(
4921
- global.wazoOnRefreshToken[server] || global.wazoOnRefreshToken[null] || apiClient.onRefreshToken,
4922
- );
4923
-
4924
- apiClient.setOnRefreshTokenError(
4925
- global.wazoOnRefreshTokenError[server] || global.wazoOnRefreshTokenError[null] || apiClient.onRefreshTokenError,
4926
- );
4927
-
4928
- apiClient.setRefreshExpiration(
4929
- global.wazoRefreshExpiration[server] || global.wazoRefreshExpiration[null] || apiClient.refreshExpiration,
4930
- );
4931
-
4932
- apiClient.setRefreshBackend(
4933
- global.wazoRefreshBackend[server] || global.wazoRefreshBackend[null] || apiClient.refreshBackend,
4934
- );
4935
-
4936
- apiClient.setIsMobile(global.wazoIsMobile[server] || global.wazoIsMobile[null] || apiClient.isMobile);
4937
-
4938
- return apiClient;
4939
- };
4940
-
4941
- var getApiClient = (forServer = null) => {
4942
- const server = forServer || global.wazoCurrentServer || '';
4943
- if (server in global.wazoClients) {
4944
- return fillClient(global.wazoClients[server]);
4945
- }
4946
-
4947
- global.wazoClients[server] = new ApiClient({ server });
4948
-
4949
- return fillClient(global.wazoClients[server]);
4950
- };
4951
-
4952
- //
4953
-
4954
- class CallApi {
4955
- static async fetchCallLogs(offset , limit ) {
4956
- return getApiClient().callLogd.listCallLogs(offset, limit);
4957
- }
4958
-
4959
- static async fetchDistinctCallLogs(offset , limit , distinct = 'peer_exten') {
4960
- return getApiClient().callLogd.listDistinctCallLogs(offset, limit, distinct);
4961
- }
4962
-
4963
- static async fetchActiveCalls() {
4964
- return getApiClient().calld.listCalls();
4965
- }
4966
-
4967
- static async fetchCallLogsFromDate(from , number ) {
4968
- return getApiClient().callLogd.listCallLogsFromDate(from, number);
4969
- }
4970
-
4971
- static async search(query , limit ) {
4972
- return getApiClient().callLogd.search(query, limit);
4973
- }
4974
-
4975
- static async searchBy(field , value , limit ) {
4976
- return getApiClient().callLogd.searchBy(field, value, limit);
4977
- }
4978
-
4979
- static async fetchSIP(session , line ) {
4980
- const lineToUse = line || session.primaryLine();
4981
- return getApiClient().confd.getUserLineSip(session.uuid, lineToUse ? lineToUse.id : null);
4982
- }
4983
-
4984
- static async cancelCall(callSession ) {
4985
- return getApiClient().calld.cancelCall(callSession.callId);
4986
- }
4987
-
4988
- static async makeCall(callFromLine , extension , isMobile = false,
4989
- callbackAllLines = false) {
4990
- const lineId = callFromLine ? callFromLine.id : null;
4991
-
4992
- const response = await getApiClient().calld.makeCall(extension, isMobile, lineId, callbackAllLines);
4993
- return Call.parse(response);
4994
- }
4995
-
4996
- static async relocateCall(callId , line , contactIdentifier ) {
4997
- return getApiClient().calld.relocateCall(callId, 'line', line, contactIdentifier);
4998
- }
4999
-
5000
- static async hold(callId ) {
5001
- return getApiClient().calld.hold(callId);
5002
- }
5003
-
5004
- static async resume(callId ) {
5005
- return getApiClient().calld.resume(callId);
5006
- }
5007
-
5008
- static async mute(callId ) {
5009
- return getApiClient().calld.mute(callId);
5010
- }
5011
-
5012
- static async sendDTMF(callId , digits ) {
5013
- return getApiClient().calld.sendDTMF(callId, digits);
5014
- }
5015
-
5016
- static async unmute(callId ) {
5017
- return getApiClient().calld.unmute(callId);
5018
- }
5019
-
5020
- static async transferCall(callId , number , flow ) {
5021
- return getApiClient().calld.transferCall(callId, number, flow);
5022
- }
5023
-
5024
- static async cancelCallTransfer(transferId ) {
5025
- return getApiClient().calld.cancelCallTransfer(transferId);
5026
- }
5027
-
5028
- static async confirmCallTransfer(transferId ) {
5029
- return getApiClient().calld.confirmCallTransfer(transferId);
5030
- }
5031
61
  }
5032
-
5033
- export default CallApi;