@wazo/sdk 0.38.21 → 0.39.0-beta.1

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