@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
@@ -130,6 +130,7 @@ class IssueReporter {
130
130
 
131
131
 
132
132
 
133
+
133
134
 
134
135
  constructor() {
135
136
  addLevelsTo(this);
@@ -141,12 +142,17 @@ class IssueReporter {
141
142
  this.bufferTimeout = null;
142
143
  this._boundProcessBuffer = this._processBuffer.bind(this);
143
144
  this._boundParseLoggerBody = this._parseLoggerBody.bind(this);
145
+ this._callback = null;
144
146
  }
145
147
 
146
148
  init() {
147
149
  this._catchConsole();
148
150
  }
149
151
 
152
+ setCallback(cb ) {
153
+ this._callback = cb;
154
+ }
155
+
150
156
  configureRemoteClient(configuration = { tag: 'wazo-sdk', host: null, port: null, level: null, extra: {} }) {
151
157
  this.remoteClientConfiguration = configuration;
152
158
  }
@@ -182,6 +188,7 @@ class IssueReporter {
182
188
 
183
189
  // Handle category label
184
190
  let category = null;
191
+ let skipSendToRemote = false;
185
192
  let extra = {};
186
193
  if (args[0].indexOf(CATEGORY_PREFIX) === 0) {
187
194
  category = args[0].split('=')[1];
@@ -197,6 +204,7 @@ class IssueReporter {
197
204
  errorMessage: lastArg.message,
198
205
  errorStack: lastArg.stack,
199
206
  errorType: lastArg.constructor.name,
207
+ skipSendToRemote: lastArg.skipSendToRemote,
200
208
  };
201
209
  } else {
202
210
  extra = lastArg;
@@ -205,6 +213,11 @@ class IssueReporter {
205
213
  args.splice(1, 1);
206
214
  }
207
215
 
216
+ if (extra.skipSendToRemote) {
217
+ skipSendToRemote = true;
218
+ delete extra.skipSendToRemote;
219
+ }
220
+
208
221
  const date = moment().format('YYYY-MM-DD HH:mm:ss.SSS');
209
222
  const message = args.join(', ');
210
223
  let consoleMessage = message;
@@ -225,7 +238,13 @@ class IssueReporter {
225
238
  const oldMethod = this.oldConsoleMethods[consoleLevel] || this.oldConsoleMethods.log;
226
239
  oldMethod.apply(oldMethod, [date, consoleMessage]);
227
240
 
228
- this._sendToRemoteLogger(level, { date, message, category, ...extra });
241
+ if (this._callback) {
242
+ this._callback(level, consoleMessage);
243
+ }
244
+
245
+ if (!skipSendToRemote) {
246
+ this._sendToRemoteLogger(level, { date, message, category, ...extra });
247
+ }
229
248
  }
230
249
 
231
250
  logRequest(url , options , response , start ) {
@@ -370,7 +389,11 @@ class IssueReporter {
370
389
  },
371
390
  // $FlowFixMe
372
391
  body,
373
- }).catch(() => {
392
+ }).catch((e ) => {
393
+ // $FlowFixMe
394
+ e.skipSendToRemote = true;
395
+ this.log('error', this._makeCategory('grafana'), 'Sending log to grafana, error', e);
396
+
374
397
  setTimeout(() => {
375
398
  if (isArray) {
376
399
  payload = payload.map(message => {
@@ -417,7 +440,7 @@ var IssueReporter$1 = new IssueReporter();
417
440
 
418
441
  const methods = ['head', 'get', 'post', 'put', 'delete'];
419
442
 
420
- const logger$1 = IssueReporter$1 ? IssueReporter$1.loggerFor('api') : console;
443
+ const logger = IssueReporter$1 ? IssueReporter$1.loggerFor('api') : console;
421
444
 
422
445
  // Use a function here to be able to mock it in tests
423
446
  const realFetch = () => {
@@ -556,7 +579,7 @@ class ApiRequester {
556
579
  };
557
580
 
558
581
  if (this.refreshTokenPromise) {
559
- logger$1.info('A token is already refreshing, waiting ...', { url });
582
+ logger.info('A token is already refreshing, waiting ...', { url });
560
583
  await this.refreshTokenPromise;
561
584
  }
562
585
 
@@ -576,7 +599,7 @@ class ApiRequester {
576
599
  return promise.then(async (err ) => {
577
600
  // Check if the token is still valid
578
601
  if (firstCall && this._checkTokenExpired(response, err)) {
579
- logger$1.warn('token expired', { error: err.reason });
602
+ logger.warn('token expired', { error: err.reason });
580
603
  // Replay the call after refreshing the token
581
604
  return this._replayWithNewToken(err, path, method, body, headers, parse);
582
605
  }
@@ -586,7 +609,7 @@ class ApiRequester {
586
609
  : exceptionClass.fromResponse(err, response.status);
587
610
 
588
611
  if (this.shouldLogErrors) {
589
- logger$1.error('API error', error);
612
+ logger.error('API error', error);
590
613
  }
591
614
 
592
615
  throw error;
@@ -596,7 +619,7 @@ class ApiRequester {
596
619
  return newParse(response, isJson);
597
620
  }).catch(error => {
598
621
  if (this.shouldLogErrors) {
599
- logger$1.error('Fetch failed', { url, options, message: error.message, stack: error.stack });
622
+ logger.error('Fetch failed', { url, options, message: error.message, stack: error.stack });
600
623
  }
601
624
 
602
625
  throw error;
@@ -624,13 +647,13 @@ class ApiRequester {
624
647
  ) {
625
648
  const isTokenNotFound = this._isTokenNotFound(err);
626
649
  let newPath = path;
627
- logger$1.info('refreshing token', { inProgress: !!this.refreshTokenPromise });
650
+ logger.info('refreshing token', { inProgress: !!this.refreshTokenPromise });
628
651
 
629
652
  this.refreshTokenPromise = this.refreshTokenPromise || this.refreshTokenCallback();
630
653
 
631
654
  return this.refreshTokenPromise.then(() => {
632
655
  this.refreshTokenPromise = null;
633
- logger$1.info('token refreshed', { isTokenNotFound });
656
+ logger.info('token refreshed', { isTokenNotFound });
634
657
  if (isTokenNotFound) {
635
658
  const pathParts = path.split('/');
636
659
  pathParts.pop();
@@ -1508,6 +1531,9 @@ class Contact {
1508
1531
  }
1509
1532
 
1510
1533
  static parseMany(response ) {
1534
+ if (!response || !response.results) {
1535
+ return [];
1536
+ }
1511
1537
  return response.results.map(r => Contact.parse(r, response.column_types));
1512
1538
  }
1513
1539
 
@@ -2585,8 +2611,9 @@ class ExternalApp {
2585
2611
 
2586
2612
 
2587
2613
 
2588
-
2614
+
2589
2615
 
2616
+
2590
2617
 
2591
2618
 
2592
2619
  class Meeting {
@@ -2597,9 +2624,10 @@ class Meeting {
2597
2624
 
2598
2625
 
2599
2626
 
2600
-
2627
+
2601
2628
 
2602
2629
 
2630
+
2603
2631
 
2604
2632
  static parse(plain ) {
2605
2633
  return new Meeting({
@@ -2609,24 +2637,43 @@ class Meeting {
2609
2637
  ownerUuids: plain.owner_uuids,
2610
2638
  port: plain.port,
2611
2639
  uuid: plain.uuid,
2612
- number: plain.number,
2640
+ extension: plain.exten,
2613
2641
  persistent: plain.persistent,
2642
+ creationTime: moment(plain.creation_time).toDate(),
2614
2643
  });
2615
2644
  }
2616
2645
 
2646
+ static parseMany(items ) {
2647
+ if (!items) {
2648
+ return [];
2649
+ }
2650
+ return items.map(plain => Meeting.parse(plain));
2651
+ }
2652
+
2617
2653
  static newFrom(meeting ) {
2618
2654
  return newFrom(meeting, Meeting);
2619
2655
  }
2620
2656
 
2621
- constructor({ uuid, name, guestSipAuthorization, ownerUuids, port, uri, number, persistent } = {}) {
2657
+ constructor({
2658
+ uuid,
2659
+ name,
2660
+ guestSipAuthorization,
2661
+ ownerUuids,
2662
+ port,
2663
+ uri,
2664
+ extension,
2665
+ persistent,
2666
+ creationTime,
2667
+ } = {}) {
2622
2668
  this.guestSipAuthorization = guestSipAuthorization;
2623
2669
  this.uri = uri;
2624
2670
  this.name = name;
2625
2671
  this.ownerUuids = ownerUuids;
2626
2672
  this.port = port;
2627
2673
  this.uuid = uuid;
2628
- this.number = number;
2674
+ this.extension = extension;
2629
2675
  this.persistent = persistent;
2676
+ this.creationTime = creationTime;
2630
2677
 
2631
2678
  // Useful to compare instead of instanceof with minified code
2632
2679
  this.type = 'Meeting';
@@ -2704,8 +2751,11 @@ var confdMethods = (client , baseUrl ) => ({
2704
2751
  }
2705
2752
  },
2706
2753
 
2707
- createMyMeeting: (name ) =>
2708
- client.post(`${baseUrl}/users/me/meetings`, { name }).then(Meeting.parse),
2754
+ getMyMeetings: () =>
2755
+ client.get(`${baseUrl}/users/me/meetings`).then(response => Meeting.parseMany(response.items)),
2756
+
2757
+ createMyMeeting: (name , persistent ) =>
2758
+ client.post(`${baseUrl}/users/me/meetings`, { name, persistent }).then(Meeting.parse),
2709
2759
 
2710
2760
  deleteMyMeeting: (meetingUuid ) =>
2711
2761
  client.delete(`${baseUrl}/users/me/meetings/${meetingUuid}`, null),
@@ -2801,6 +2851,10 @@ class ChatMessage {
2801
2851
 
2802
2852
 
2803
2853
  static parseMany(plain ) {
2854
+ if (!plain || !plain.items) {
2855
+ return [];
2856
+ }
2857
+
2804
2858
  return plain.items.map(item => ChatMessage.parse(item));
2805
2859
  }
2806
2860
 
@@ -2910,6 +2964,9 @@ class Voicemail {
2910
2964
  }
2911
2965
 
2912
2966
  static parseMany(plain ) {
2967
+ if (!plain) {
2968
+ return [];
2969
+ }
2913
2970
  const plainUnread = plain.folders.filter(folder => folder.type === 'new')[0].messages;
2914
2971
  const plainRead = plain.folders.filter(folder => folder.type === 'old')[0].messages;
2915
2972
 
@@ -3019,6 +3076,9 @@ class Call {
3019
3076
 
3020
3077
 
3021
3078
  static parseMany(plain ) {
3079
+ if (!plain) {
3080
+ return [];
3081
+ }
3022
3082
  return plain.map((plainCall ) => Call.parse(plainCall));
3023
3083
  }
3024
3084
 
@@ -3191,6 +3251,9 @@ class Recording {
3191
3251
 
3192
3252
 
3193
3253
  static parseMany(recordings = []) {
3254
+ if (!recordings) {
3255
+ return [];
3256
+ }
3194
3257
  return recordings.map(item => Recording.parse(item));
3195
3258
  }
3196
3259
 
@@ -3292,6 +3355,10 @@ class CallLog {
3292
3355
  }
3293
3356
 
3294
3357
  static parseMany(plain ) {
3358
+ if (!plain || !plain.items) {
3359
+ return [];
3360
+ }
3361
+
3295
3362
  return plain.items.map(item => CallLog.parse(item));
3296
3363
  }
3297
3364
 
@@ -3513,7 +3580,7 @@ const TRANSFER_FLOW_BLIND = 'blind';
3513
3580
 
3514
3581
  // const MINIMUM_WAZO_ENGINE_VERSION_FOR_CTI_HOLD = '20.11';
3515
3582
 
3516
- IssueReporter$1 ? IssueReporter$1.loggerFor('cti-phone') : console;
3583
+ const logger$1 = IssueReporter$1 ? IssueReporter$1.loggerFor('cti-phone') : console;
3517
3584
 
3518
3585
  /* */
3519
3586
 
@@ -3849,6 +3916,9 @@ class ChatRoom {
3849
3916
 
3850
3917
 
3851
3918
  static parseMany(plain ) {
3919
+ if (!plain || !plain.items) {
3920
+ return [];
3921
+ }
3852
3922
  return plain.items.map(item => ChatRoom.parse(item));
3853
3923
  }
3854
3924
 
@@ -4429,7 +4499,7 @@ const AGENTD_VERSION = '1.0';
4429
4499
  const WEBHOOKD_VERSION = '1.0';
4430
4500
  const AMID_VERSION = '1.0';
4431
4501
 
4432
- const logger = IssueReporter$1 ? IssueReporter$1.loggerFor('api') : console;
4502
+ const logger$2 = IssueReporter$1 ? IssueReporter$1.loggerFor('api') : console;
4433
4503
 
4434
4504
  class ApiClient {
4435
4505
 
@@ -4481,12 +4551,12 @@ class ApiClient {
4481
4551
  }
4482
4552
 
4483
4553
  async forceRefreshToken() {
4484
- logger.info('forcing refresh token, calling callback');
4554
+ logger$2.info('forcing refresh token, calling callback');
4485
4555
  return this.refreshTokenCallback();
4486
4556
  }
4487
4557
 
4488
4558
  async refreshTokenCallback() {
4489
- logger.info('refresh token callback called', {
4559
+ logger$2.info('refresh token callback called', {
4490
4560
  refreshToken: this.refreshToken,
4491
4561
  refreshBackend: this.refreshBackend,
4492
4562
  refreshExpiration: this.refreshExpiration,
@@ -4504,7 +4574,7 @@ class ApiClient {
4504
4574
  this.isMobile,
4505
4575
  );
4506
4576
 
4507
- logger.info('token refreshed', { token: session.token });
4577
+ logger$2.info('token refreshed', { token: session.token });
4508
4578
 
4509
4579
  if (this.onRefreshToken) {
4510
4580
  this.onRefreshToken(session.token, session);