@wazo/sdk 0.37.20 → 0.37.24

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 (147) hide show
  1. package/dist/wazo-sdk.js +6 -6
  2. package/esm/__tests__/api-client.test.js +91 -21
  3. package/esm/__tests__/web-rtc-client.test.js +214 -165
  4. package/esm/api/agentd.js +25 -2
  5. package/esm/api/amid.js +26 -3
  6. package/esm/api/application.js +25 -2
  7. package/esm/api/auth.js +25 -2
  8. package/esm/api/call-logd.js +34 -4
  9. package/esm/api/calld.js +35 -2
  10. package/esm/api/chatd.js +32 -2
  11. package/esm/api/confd.js +56 -9
  12. package/esm/api/ctid-ng.js +38 -5
  13. package/esm/api/dird.js +29 -3
  14. package/esm/api/webhookd.js +26 -3
  15. package/esm/api-client.js +91 -21
  16. package/esm/checker/Checker.js +241 -190
  17. package/esm/checker/checks/aor.js +91 -21
  18. package/esm/checker/checks/api.js +91 -21
  19. package/esm/checker/checks/index.js +231 -180
  20. package/esm/checker/checks/wazo-websocket.js +42 -17
  21. package/esm/checker/checks/webrtc-transport.js +214 -165
  22. package/esm/checker/checks/webrtc.js +214 -165
  23. package/esm/domain/AdHocAPIConference.js +91 -21
  24. package/esm/domain/Call.js +3 -0
  25. package/esm/domain/CallLog.js +8 -1
  26. package/esm/domain/ChatMessage.js +4 -0
  27. package/esm/domain/ChatRoom.js +3 -0
  28. package/esm/domain/Contact.js +4 -1
  29. package/esm/domain/Features.js +91 -21
  30. package/esm/domain/Meeting.js +28 -5
  31. package/esm/domain/Phone/CTIPhone.js +109 -35
  32. package/esm/domain/Phone/WebRTCPhone.js +159 -102
  33. package/esm/domain/Recording.js +3 -0
  34. package/esm/domain/Voicemail.js +3 -0
  35. package/esm/domain/__tests__/Call.test.js +3 -0
  36. package/esm/domain/__tests__/CallLog.test.js +8 -1
  37. package/esm/domain/__tests__/Contact.test.js +4 -1
  38. package/esm/domain/__tests__/Meeting.test.js +144 -0
  39. package/esm/domain/__tests__/Voicemail.test.js +3 -0
  40. package/esm/index.js +509 -414
  41. package/esm/lib/WazoSessionDescriptionHandler.js +26 -41
  42. package/esm/service/CallApi.js +91 -21
  43. package/esm/service/IssueReporter.js +26 -3
  44. package/esm/service/__tests__/IssueReporter.test.js +26 -3
  45. package/esm/service/getApiClient.js +91 -21
  46. package/esm/simple/Auth.js +499 -404
  47. package/esm/simple/Configuration.js +499 -404
  48. package/esm/simple/Directory.js +91 -21
  49. package/esm/simple/Phone.js +499 -404
  50. package/esm/simple/Websocket.js +45 -19
  51. package/esm/simple/index.js +503 -408
  52. package/esm/simple/room/LocalParticipant.js +503 -408
  53. package/esm/simple/room/Participant.js +503 -408
  54. package/esm/simple/room/RemoteParticipant.js +503 -408
  55. package/esm/simple/room/Room.js +504 -409
  56. package/esm/simple/room/SipRoom.js +503 -408
  57. package/esm/simple/room/Stream.js +503 -408
  58. package/esm/simple/room/__tests__/RemoteParticipant.test.js +503 -408
  59. package/esm/simple/utils.js +503 -408
  60. package/esm/types/WebSocketMessage.js +1 -1
  61. package/esm/utils/__tests__/api-requester.test.js +25 -2
  62. package/esm/utils/api-requester.js +25 -2
  63. package/esm/web-rtc-client.js +214 -165
  64. package/esm/websocket-client.js +43 -18
  65. package/lib/__tests__/api-client.test.js +91 -21
  66. package/lib/__tests__/web-rtc-client.test.js +214 -165
  67. package/lib/api/agentd.js +25 -2
  68. package/lib/api/amid.js +26 -3
  69. package/lib/api/application.js +25 -2
  70. package/lib/api/auth.js +25 -2
  71. package/lib/api/call-logd.js +34 -4
  72. package/lib/api/calld.js +35 -2
  73. package/lib/api/chatd.js +32 -2
  74. package/lib/api/confd.js +56 -9
  75. package/lib/api/ctid-ng.js +38 -5
  76. package/lib/api/dird.js +29 -3
  77. package/lib/api/webhookd.js +26 -3
  78. package/lib/api-client.js +91 -21
  79. package/lib/checker/Checker.js +241 -190
  80. package/lib/checker/checks/aor.js +91 -21
  81. package/lib/checker/checks/api.js +91 -21
  82. package/lib/checker/checks/index.js +231 -180
  83. package/lib/checker/checks/wazo-websocket.js +42 -17
  84. package/lib/checker/checks/webrtc-transport.js +214 -165
  85. package/lib/checker/checks/webrtc.js +214 -165
  86. package/lib/domain/AdHocAPIConference.js +91 -21
  87. package/lib/domain/Call.js +3 -0
  88. package/lib/domain/CallLog.js +8 -1
  89. package/lib/domain/ChatMessage.js +4 -0
  90. package/lib/domain/ChatRoom.js +3 -0
  91. package/lib/domain/Contact.js +4 -1
  92. package/lib/domain/Features.js +91 -21
  93. package/lib/domain/Meeting.js +32 -5
  94. package/lib/domain/Phone/CTIPhone.js +109 -35
  95. package/lib/domain/Phone/WebRTCPhone.js +159 -102
  96. package/lib/domain/Recording.js +3 -0
  97. package/lib/domain/Voicemail.js +3 -0
  98. package/lib/domain/__tests__/Call.test.js +3 -0
  99. package/lib/domain/__tests__/CallLog.test.js +8 -1
  100. package/lib/domain/__tests__/Contact.test.js +4 -1
  101. package/lib/domain/__tests__/Meeting.test.js +150 -0
  102. package/lib/domain/__tests__/Voicemail.test.js +3 -0
  103. package/lib/index.js +509 -414
  104. package/lib/lib/WazoSessionDescriptionHandler.js +26 -41
  105. package/lib/service/CallApi.js +91 -21
  106. package/lib/service/IssueReporter.js +26 -3
  107. package/lib/service/__tests__/IssueReporter.test.js +26 -3
  108. package/lib/service/getApiClient.js +91 -21
  109. package/lib/simple/Auth.js +499 -404
  110. package/lib/simple/Configuration.js +499 -404
  111. package/lib/simple/Directory.js +91 -21
  112. package/lib/simple/Phone.js +499 -404
  113. package/lib/simple/Websocket.js +45 -19
  114. package/lib/simple/index.js +503 -408
  115. package/lib/simple/room/LocalParticipant.js +503 -408
  116. package/lib/simple/room/Participant.js +503 -408
  117. package/lib/simple/room/RemoteParticipant.js +503 -408
  118. package/lib/simple/room/Room.js +504 -409
  119. package/lib/simple/room/SipRoom.js +503 -408
  120. package/lib/simple/room/Stream.js +503 -408
  121. package/lib/simple/room/__tests__/RemoteParticipant.test.js +503 -408
  122. package/lib/simple/utils.js +503 -408
  123. package/lib/types/WebSocketMessage.js +2 -0
  124. package/lib/utils/__tests__/api-requester.test.js +25 -2
  125. package/lib/utils/api-requester.js +25 -2
  126. package/lib/web-rtc-client.js +214 -165
  127. package/lib/websocket-client.js +43 -17
  128. package/package.json +1 -1
  129. package/src/api/confd.js +5 -2
  130. package/src/domain/Call.js +3 -0
  131. package/src/domain/CallLog.js +4 -0
  132. package/src/domain/ChatMessage.js +4 -0
  133. package/src/domain/ChatRoom.js +3 -0
  134. package/src/domain/Contact.js +3 -0
  135. package/src/domain/Meeting.js +28 -5
  136. package/src/domain/Phone/CTIPhone.js +4 -0
  137. package/src/domain/Phone/Phone.js +2 -0
  138. package/src/domain/Phone/WebRTCPhone.js +49 -15
  139. package/src/domain/Recording.js +3 -0
  140. package/src/domain/Voicemail.js +3 -0
  141. package/src/domain/__tests__/Meeting.test.js +50 -0
  142. package/src/lib/WazoSessionDescriptionHandler.js +1 -35
  143. package/src/service/IssueReporter.js +25 -2
  144. package/src/simple/Phone.js +5 -0
  145. package/src/types/WebSocketMessage.js +5 -1
  146. package/src/web-rtc-client.js +41 -24
  147. package/src/websocket-client.js +2 -0
@@ -136,6 +136,7 @@ class IssueReporter {
136
136
 
137
137
 
138
138
 
139
+
139
140
 
140
141
  constructor() {
141
142
  addLevelsTo(this);
@@ -147,12 +148,17 @@ class IssueReporter {
147
148
  this.bufferTimeout = null;
148
149
  this._boundProcessBuffer = this._processBuffer.bind(this);
149
150
  this._boundParseLoggerBody = this._parseLoggerBody.bind(this);
151
+ this._callback = null;
150
152
  }
151
153
 
152
154
  init() {
153
155
  this._catchConsole();
154
156
  }
155
157
 
158
+ setCallback(cb ) {
159
+ this._callback = cb;
160
+ }
161
+
156
162
  configureRemoteClient(configuration = { tag: 'wazo-sdk', host: null, port: null, level: null, extra: {} }) {
157
163
  this.remoteClientConfiguration = configuration;
158
164
  }
@@ -188,6 +194,7 @@ class IssueReporter {
188
194
 
189
195
  // Handle category label
190
196
  let category = null;
197
+ let skipSendToRemote = false;
191
198
  let extra = {};
192
199
  if (args[0].indexOf(CATEGORY_PREFIX) === 0) {
193
200
  category = args[0].split('=')[1];
@@ -203,6 +210,7 @@ class IssueReporter {
203
210
  errorMessage: lastArg.message,
204
211
  errorStack: lastArg.stack,
205
212
  errorType: lastArg.constructor.name,
213
+ skipSendToRemote: lastArg.skipSendToRemote,
206
214
  };
207
215
  } else {
208
216
  extra = lastArg;
@@ -211,6 +219,11 @@ class IssueReporter {
211
219
  args.splice(1, 1);
212
220
  }
213
221
 
222
+ if (extra.skipSendToRemote) {
223
+ skipSendToRemote = true;
224
+ delete extra.skipSendToRemote;
225
+ }
226
+
214
227
  const date = moment__default['default']().format('YYYY-MM-DD HH:mm:ss.SSS');
215
228
  const message = args.join(', ');
216
229
  let consoleMessage = message;
@@ -231,7 +244,13 @@ class IssueReporter {
231
244
  const oldMethod = this.oldConsoleMethods[consoleLevel] || this.oldConsoleMethods.log;
232
245
  oldMethod.apply(oldMethod, [date, consoleMessage]);
233
246
 
234
- this._sendToRemoteLogger(level, { date, message, category, ...extra });
247
+ if (this._callback) {
248
+ this._callback(level, consoleMessage);
249
+ }
250
+
251
+ if (!skipSendToRemote) {
252
+ this._sendToRemoteLogger(level, { date, message, category, ...extra });
253
+ }
235
254
  }
236
255
 
237
256
  logRequest(url , options , response , start ) {
@@ -376,7 +395,11 @@ class IssueReporter {
376
395
  },
377
396
  // $FlowFixMe
378
397
  body,
379
- }).catch(() => {
398
+ }).catch((e ) => {
399
+ // $FlowFixMe
400
+ e.skipSendToRemote = true;
401
+ this.log('error', this._makeCategory('grafana'), 'Sending log to grafana, error', e);
402
+
380
403
  setTimeout(() => {
381
404
  if (isArray) {
382
405
  payload = payload.map(message => {
@@ -423,7 +446,7 @@ var IssueReporter$1 = new IssueReporter();
423
446
 
424
447
  const methods = ['head', 'get', 'post', 'put', 'delete'];
425
448
 
426
- const logger$1 = IssueReporter$1 ? IssueReporter$1.loggerFor('api') : console;
449
+ const logger = IssueReporter$1 ? IssueReporter$1.loggerFor('api') : console;
427
450
 
428
451
  // Use a function here to be able to mock it in tests
429
452
  const realFetch = () => {
@@ -562,7 +585,7 @@ class ApiRequester {
562
585
  };
563
586
 
564
587
  if (this.refreshTokenPromise) {
565
- logger$1.info('A token is already refreshing, waiting ...', { url });
588
+ logger.info('A token is already refreshing, waiting ...', { url });
566
589
  await this.refreshTokenPromise;
567
590
  }
568
591
 
@@ -582,7 +605,7 @@ class ApiRequester {
582
605
  return promise.then(async (err ) => {
583
606
  // Check if the token is still valid
584
607
  if (firstCall && this._checkTokenExpired(response, err)) {
585
- logger$1.warn('token expired', { error: err.reason });
608
+ logger.warn('token expired', { error: err.reason });
586
609
  // Replay the call after refreshing the token
587
610
  return this._replayWithNewToken(err, path, method, body, headers, parse);
588
611
  }
@@ -592,7 +615,7 @@ class ApiRequester {
592
615
  : exceptionClass.fromResponse(err, response.status);
593
616
 
594
617
  if (this.shouldLogErrors) {
595
- logger$1.error('API error', error);
618
+ logger.error('API error', error);
596
619
  }
597
620
 
598
621
  throw error;
@@ -602,7 +625,7 @@ class ApiRequester {
602
625
  return newParse(response, isJson);
603
626
  }).catch(error => {
604
627
  if (this.shouldLogErrors) {
605
- logger$1.error('Fetch failed', { url, options, message: error.message, stack: error.stack });
628
+ logger.error('Fetch failed', { url, options, message: error.message, stack: error.stack });
606
629
  }
607
630
 
608
631
  throw error;
@@ -630,13 +653,13 @@ class ApiRequester {
630
653
  ) {
631
654
  const isTokenNotFound = this._isTokenNotFound(err);
632
655
  let newPath = path;
633
- logger$1.info('refreshing token', { inProgress: !!this.refreshTokenPromise });
656
+ logger.info('refreshing token', { inProgress: !!this.refreshTokenPromise });
634
657
 
635
658
  this.refreshTokenPromise = this.refreshTokenPromise || this.refreshTokenCallback();
636
659
 
637
660
  return this.refreshTokenPromise.then(() => {
638
661
  this.refreshTokenPromise = null;
639
- logger$1.info('token refreshed', { isTokenNotFound });
662
+ logger.info('token refreshed', { isTokenNotFound });
640
663
  if (isTokenNotFound) {
641
664
  const pathParts = path.split('/');
642
665
  pathParts.pop();
@@ -1514,6 +1537,9 @@ class Contact {
1514
1537
  }
1515
1538
 
1516
1539
  static parseMany(response ) {
1540
+ if (!response || !response.results) {
1541
+ return [];
1542
+ }
1517
1543
  return response.results.map(r => Contact.parse(r, response.column_types));
1518
1544
  }
1519
1545
 
@@ -2591,8 +2617,9 @@ class ExternalApp {
2591
2617
 
2592
2618
 
2593
2619
 
2594
-
2620
+
2595
2621
 
2622
+
2596
2623
 
2597
2624
 
2598
2625
  class Meeting {
@@ -2603,9 +2630,10 @@ class Meeting {
2603
2630
 
2604
2631
 
2605
2632
 
2606
-
2633
+
2607
2634
 
2608
2635
 
2636
+
2609
2637
 
2610
2638
  static parse(plain ) {
2611
2639
  return new Meeting({
@@ -2615,24 +2643,43 @@ class Meeting {
2615
2643
  ownerUuids: plain.owner_uuids,
2616
2644
  port: plain.port,
2617
2645
  uuid: plain.uuid,
2618
- number: plain.number,
2646
+ extension: plain.exten,
2619
2647
  persistent: plain.persistent,
2648
+ creationTime: moment__default['default'](plain.creation_time).toDate(),
2620
2649
  });
2621
2650
  }
2622
2651
 
2652
+ static parseMany(items ) {
2653
+ if (!items) {
2654
+ return [];
2655
+ }
2656
+ return items.map(plain => Meeting.parse(plain));
2657
+ }
2658
+
2623
2659
  static newFrom(meeting ) {
2624
2660
  return newFrom(meeting, Meeting);
2625
2661
  }
2626
2662
 
2627
- constructor({ uuid, name, guestSipAuthorization, ownerUuids, port, uri, number, persistent } = {}) {
2663
+ constructor({
2664
+ uuid,
2665
+ name,
2666
+ guestSipAuthorization,
2667
+ ownerUuids,
2668
+ port,
2669
+ uri,
2670
+ extension,
2671
+ persistent,
2672
+ creationTime,
2673
+ } = {}) {
2628
2674
  this.guestSipAuthorization = guestSipAuthorization;
2629
2675
  this.uri = uri;
2630
2676
  this.name = name;
2631
2677
  this.ownerUuids = ownerUuids;
2632
2678
  this.port = port;
2633
2679
  this.uuid = uuid;
2634
- this.number = number;
2680
+ this.extension = extension;
2635
2681
  this.persistent = persistent;
2682
+ this.creationTime = creationTime;
2636
2683
 
2637
2684
  // Useful to compare instead of instanceof with minified code
2638
2685
  this.type = 'Meeting';
@@ -2710,8 +2757,11 @@ var confdMethods = (client , baseUrl ) => ({
2710
2757
  }
2711
2758
  },
2712
2759
 
2713
- createMyMeeting: (name ) =>
2714
- client.post(`${baseUrl}/users/me/meetings`, { name }).then(Meeting.parse),
2760
+ getMyMeetings: () =>
2761
+ client.get(`${baseUrl}/users/me/meetings`).then(response => Meeting.parseMany(response.items)),
2762
+
2763
+ createMyMeeting: (name , persistent ) =>
2764
+ client.post(`${baseUrl}/users/me/meetings`, { name, persistent }).then(Meeting.parse),
2715
2765
 
2716
2766
  deleteMyMeeting: (meetingUuid ) =>
2717
2767
  client.delete(`${baseUrl}/users/me/meetings/${meetingUuid}`, null),
@@ -2807,6 +2857,10 @@ class ChatMessage {
2807
2857
 
2808
2858
 
2809
2859
  static parseMany(plain ) {
2860
+ if (!plain || !plain.items) {
2861
+ return [];
2862
+ }
2863
+
2810
2864
  return plain.items.map(item => ChatMessage.parse(item));
2811
2865
  }
2812
2866
 
@@ -2916,6 +2970,9 @@ class Voicemail {
2916
2970
  }
2917
2971
 
2918
2972
  static parseMany(plain ) {
2973
+ if (!plain) {
2974
+ return [];
2975
+ }
2919
2976
  const plainUnread = plain.folders.filter(folder => folder.type === 'new')[0].messages;
2920
2977
  const plainRead = plain.folders.filter(folder => folder.type === 'old')[0].messages;
2921
2978
 
@@ -3025,6 +3082,9 @@ class Call {
3025
3082
 
3026
3083
 
3027
3084
  static parseMany(plain ) {
3085
+ if (!plain) {
3086
+ return [];
3087
+ }
3028
3088
  return plain.map((plainCall ) => Call.parse(plainCall));
3029
3089
  }
3030
3090
 
@@ -3197,6 +3257,9 @@ class Recording {
3197
3257
 
3198
3258
 
3199
3259
  static parseMany(recordings = []) {
3260
+ if (!recordings) {
3261
+ return [];
3262
+ }
3200
3263
  return recordings.map(item => Recording.parse(item));
3201
3264
  }
3202
3265
 
@@ -3298,6 +3361,10 @@ class CallLog {
3298
3361
  }
3299
3362
 
3300
3363
  static parseMany(plain ) {
3364
+ if (!plain || !plain.items) {
3365
+ return [];
3366
+ }
3367
+
3301
3368
  return plain.items.map(item => CallLog.parse(item));
3302
3369
  }
3303
3370
 
@@ -3519,7 +3586,7 @@ const TRANSFER_FLOW_BLIND = 'blind';
3519
3586
 
3520
3587
  // const MINIMUM_WAZO_ENGINE_VERSION_FOR_CTI_HOLD = '20.11';
3521
3588
 
3522
- IssueReporter$1 ? IssueReporter$1.loggerFor('cti-phone') : console;
3589
+ const logger$1 = IssueReporter$1 ? IssueReporter$1.loggerFor('cti-phone') : console;
3523
3590
 
3524
3591
  /* */
3525
3592
 
@@ -3855,6 +3922,9 @@ class ChatRoom {
3855
3922
 
3856
3923
 
3857
3924
  static parseMany(plain ) {
3925
+ if (!plain || !plain.items) {
3926
+ return [];
3927
+ }
3858
3928
  return plain.items.map(item => ChatRoom.parse(item));
3859
3929
  }
3860
3930
 
@@ -4435,7 +4505,7 @@ const AGENTD_VERSION = '1.0';
4435
4505
  const WEBHOOKD_VERSION = '1.0';
4436
4506
  const AMID_VERSION = '1.0';
4437
4507
 
4438
- const logger = IssueReporter$1 ? IssueReporter$1.loggerFor('api') : console;
4508
+ const logger$2 = IssueReporter$1 ? IssueReporter$1.loggerFor('api') : console;
4439
4509
 
4440
4510
  class ApiClient {
4441
4511
 
@@ -4487,12 +4557,12 @@ class ApiClient {
4487
4557
  }
4488
4558
 
4489
4559
  async forceRefreshToken() {
4490
- logger.info('forcing refresh token, calling callback');
4560
+ logger$2.info('forcing refresh token, calling callback');
4491
4561
  return this.refreshTokenCallback();
4492
4562
  }
4493
4563
 
4494
4564
  async refreshTokenCallback() {
4495
- logger.info('refresh token callback called', {
4565
+ logger$2.info('refresh token callback called', {
4496
4566
  refreshToken: this.refreshToken,
4497
4567
  refreshBackend: this.refreshBackend,
4498
4568
  refreshExpiration: this.refreshExpiration,
@@ -4510,7 +4580,7 @@ class ApiClient {
4510
4580
  this.isMobile,
4511
4581
  );
4512
4582
 
4513
- logger.info('token refreshed', { token: session.token });
4583
+ logger$2.info('token refreshed', { token: session.token });
4514
4584
 
4515
4585
  if (this.onRefreshToken) {
4516
4586
  this.onRefreshToken(session.token, session);