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