@wazo/sdk 0.37.0-rc.5 → 0.37.2

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 (149) hide show
  1. package/dist/wazo-sdk.js +5 -5
  2. package/esm/__tests__/api-client.test.js +93 -16
  3. package/esm/__tests__/web-rtc-client.test.js +153 -54
  4. package/esm/api/agentd.js +24 -3
  5. package/esm/api/amid.js +7 -1
  6. package/esm/api/application.js +24 -3
  7. package/esm/api/auth.js +24 -3
  8. package/esm/api/call-logd.js +78 -20
  9. package/esm/api/calld.js +24 -20
  10. package/esm/api/chatd.js +24 -3
  11. package/esm/api/confd.js +24 -3
  12. package/esm/api/ctid-ng.js +24 -3
  13. package/esm/api/dird.js +27 -6
  14. package/esm/api/webhookd.js +7 -1
  15. package/esm/api-client.js +93 -16
  16. package/esm/checker/Checker.js +156 -54
  17. package/esm/checker/checks/aor.js +95 -16
  18. package/esm/checker/checks/api.js +94 -16
  19. package/esm/checker/checks/index.js +156 -54
  20. package/esm/checker/checks/wazo-websocket.js +7 -1
  21. package/esm/checker/checks/webrtc-transport.js +153 -54
  22. package/esm/checker/checks/webrtc.js +153 -54
  23. package/esm/domain/AdHocAPIConference.js +1717 -1640
  24. package/esm/domain/CallLog.js +71 -19
  25. package/esm/domain/CallSession.js +1 -18
  26. package/esm/domain/Contact.js +3 -3
  27. package/esm/domain/Features.js +93 -16
  28. package/esm/domain/IndirectTransfer.js +0 -17
  29. package/esm/domain/Phone/CTIPhone.js +100 -19
  30. package/esm/domain/Phone/Phone.js +0 -17
  31. package/esm/domain/Phone/WebRTCPhone.js +51 -36
  32. package/esm/domain/Recording.js +51 -0
  33. package/esm/domain/Room.js +0 -17
  34. package/esm/domain/SwitchboardCall.js +0 -17
  35. package/esm/domain/__tests__/CallLog.test.js +89 -19
  36. package/esm/domain/__tests__/CallSession.test.js +1 -18
  37. package/esm/domain/__tests__/Contact.test.js +3 -3
  38. package/esm/domain/__tests__/IndirectTransfer.test.js +1 -18
  39. package/esm/domain/__tests__/Room.test.js +1 -18
  40. package/esm/domain/__tests__/Session.test.js +7 -0
  41. package/esm/index.js +3436 -2911
  42. package/esm/lib/WazoSessionDescriptionHandler.js +28 -10
  43. package/esm/service/CallApi.js +93 -16
  44. package/esm/service/IssueReporter.js +7 -1
  45. package/esm/service/__tests__/IssueReporter.test.js +26 -2
  46. package/esm/service/getApiClient.js +93 -16
  47. package/esm/simple/Auth.js +619 -97
  48. package/esm/simple/Configuration.js +619 -97
  49. package/esm/simple/Directory.js +93 -16
  50. package/esm/simple/Phone.js +3261 -2739
  51. package/esm/simple/Websocket.js +7 -1
  52. package/esm/simple/index.js +619 -97
  53. package/esm/simple/room/LocalParticipant.js +619 -97
  54. package/esm/simple/room/Participant.js +619 -97
  55. package/esm/simple/room/RemoteParticipant.js +619 -97
  56. package/esm/simple/room/Room.js +619 -97
  57. package/esm/simple/room/Stream.js +619 -97
  58. package/esm/simple/room/__tests__/RemoteParticipant.test.js +619 -97
  59. package/esm/simple/utils.js +619 -97
  60. package/esm/utils/__tests__/api-requester.test.js +32 -6
  61. package/esm/utils/api-requester.js +24 -3
  62. package/esm/web-rtc-client.js +153 -54
  63. package/esm/websocket-client.js +7 -1
  64. package/lib/__tests__/api-client.test.js +93 -16
  65. package/lib/__tests__/web-rtc-client.test.js +154 -55
  66. package/lib/api/agentd.js +24 -3
  67. package/lib/api/amid.js +7 -1
  68. package/lib/api/application.js +24 -3
  69. package/lib/api/auth.js +24 -3
  70. package/lib/api/call-logd.js +78 -20
  71. package/lib/api/calld.js +24 -20
  72. package/lib/api/chatd.js +24 -3
  73. package/lib/api/confd.js +24 -3
  74. package/lib/api/ctid-ng.js +24 -3
  75. package/lib/api/dird.js +27 -6
  76. package/lib/api/webhookd.js +7 -1
  77. package/lib/api-client.js +93 -16
  78. package/lib/checker/Checker.js +157 -55
  79. package/lib/checker/checks/aor.js +95 -16
  80. package/lib/checker/checks/api.js +94 -16
  81. package/lib/checker/checks/index.js +157 -55
  82. package/lib/checker/checks/wazo-websocket.js +7 -1
  83. package/lib/checker/checks/webrtc-transport.js +154 -55
  84. package/lib/checker/checks/webrtc.js +154 -55
  85. package/lib/domain/AdHocAPIConference.js +1717 -1640
  86. package/lib/domain/CallLog.js +71 -19
  87. package/lib/domain/CallSession.js +1 -18
  88. package/lib/domain/Contact.js +3 -3
  89. package/lib/domain/Features.js +93 -16
  90. package/lib/domain/IndirectTransfer.js +0 -17
  91. package/lib/domain/Phone/CTIPhone.js +100 -19
  92. package/lib/domain/Phone/Phone.js +0 -16
  93. package/lib/domain/Phone/WebRTCPhone.js +51 -36
  94. package/lib/domain/Recording.js +57 -0
  95. package/lib/domain/Room.js +0 -17
  96. package/lib/domain/SwitchboardCall.js +0 -17
  97. package/lib/domain/__tests__/CallLog.test.js +89 -19
  98. package/lib/domain/__tests__/CallSession.test.js +1 -18
  99. package/lib/domain/__tests__/Contact.test.js +3 -3
  100. package/lib/domain/__tests__/IndirectTransfer.test.js +1 -18
  101. package/lib/domain/__tests__/Room.test.js +1 -18
  102. package/lib/domain/__tests__/Session.test.js +7 -0
  103. package/lib/index.js +3437 -2912
  104. package/lib/lib/WazoSessionDescriptionHandler.js +28 -10
  105. package/lib/service/CallApi.js +93 -16
  106. package/lib/service/IssueReporter.js +7 -1
  107. package/lib/service/__tests__/IssueReporter.test.js +26 -2
  108. package/lib/service/getApiClient.js +93 -16
  109. package/lib/simple/Auth.js +620 -98
  110. package/lib/simple/Configuration.js +620 -98
  111. package/lib/simple/Directory.js +93 -16
  112. package/lib/simple/Phone.js +3262 -2740
  113. package/lib/simple/Websocket.js +7 -1
  114. package/lib/simple/index.js +620 -98
  115. package/lib/simple/room/LocalParticipant.js +620 -98
  116. package/lib/simple/room/Participant.js +620 -98
  117. package/lib/simple/room/RemoteParticipant.js +620 -98
  118. package/lib/simple/room/Room.js +620 -98
  119. package/lib/simple/room/Stream.js +620 -98
  120. package/lib/simple/room/__tests__/RemoteParticipant.test.js +620 -98
  121. package/lib/simple/utils.js +620 -98
  122. package/lib/utils/__tests__/api-requester.test.js +32 -6
  123. package/lib/utils/api-requester.js +24 -3
  124. package/lib/web-rtc-client.js +154 -55
  125. package/lib/websocket-client.js +7 -1
  126. package/package.json +1 -1
  127. package/src/api-client.js +4 -0
  128. package/src/checker/checks/aor.js +2 -0
  129. package/src/checker/checks/api.js +1 -0
  130. package/src/domain/CallLog.js +18 -11
  131. package/src/domain/CallSession.js +1 -2
  132. package/src/domain/Contact.js +3 -3
  133. package/src/domain/Phone/CTIPhone.js +6 -2
  134. package/src/domain/Phone/Phone.js +2 -0
  135. package/src/domain/Phone/WebRTCPhone.js +26 -16
  136. package/src/domain/Recording.js +48 -0
  137. package/src/domain/__tests__/CallLog.test.js +19 -0
  138. package/src/domain/__tests__/Session.test.js +7 -0
  139. package/src/index.js +6 -0
  140. package/src/lib/WazoSessionDescriptionHandler.js +21 -9
  141. package/src/service/IssueReporter.js +7 -1
  142. package/src/service/__tests__/IssueReporter.test.js +20 -1
  143. package/src/simple/Phone.js +5 -1
  144. package/src/simple/index.js +6 -0
  145. package/src/simple/room/Room.js +18 -15
  146. package/src/simple/room/Stream.js +1 -4
  147. package/src/utils/__tests__/api-requester.test.js +9 -4
  148. package/src/utils/api-requester.js +17 -2
  149. package/src/web-rtc-client.js +40 -13
@@ -309,7 +309,13 @@ class IssueReporter {
309
309
  }
310
310
 
311
311
  _isLevelAbove(level1 , level2 ) {
312
- return LOG_LEVELS.indexOf(level1) > LOG_LEVELS.indexOf(level2);
312
+ const index1 = LOG_LEVELS.indexOf(level1);
313
+ const index2 = LOG_LEVELS.indexOf(level2);
314
+ if (index1 === -1 || index2 === -1) {
315
+ return false;
316
+ }
317
+
318
+ return index1 > index2;
313
319
  }
314
320
 
315
321
  _makeCategory(category ) {
@@ -367,6 +373,7 @@ class ApiRequester {
367
373
 
368
374
 
369
375
 
376
+
370
377
 
371
378
 
372
379
 
@@ -406,6 +413,8 @@ class ApiRequester {
406
413
  this.token = token;
407
414
  }
408
415
 
416
+ this.shouldLogErrors = true;
417
+
409
418
  methods.forEach(method => {
410
419
  // $FlowFixMe
411
420
  ApiRequester.prototype[method] = function sugar(...args) {
@@ -429,6 +438,14 @@ class ApiRequester {
429
438
  this.fetchOptions = options;
430
439
  }
431
440
 
441
+ disableErrorLogging() {
442
+ this.shouldLogErrors = false;
443
+ }
444
+
445
+ enableErrorLogging() {
446
+ this.shouldLogErrors = true;
447
+ }
448
+
432
449
  async call(
433
450
  path ,
434
451
  method = 'get',
@@ -489,7 +506,9 @@ class ApiRequester {
489
506
  ? exceptionClass.fromText(err, response.status)
490
507
  : exceptionClass.fromResponse(err, response.status);
491
508
 
492
- logger$1.error('API error', error);
509
+ if (this.shouldLogErrors) {
510
+ logger$1.error('API error', error);
511
+ }
493
512
 
494
513
  throw error;
495
514
  });
@@ -497,7 +516,9 @@ class ApiRequester {
497
516
 
498
517
  return newParse(response, isJson);
499
518
  }).catch(error => {
500
- logger$1.error('Fetch failed', { url, options, message: error.message, stack: error.stack });
519
+ if (this.shouldLogErrors) {
520
+ logger$1.error('Fetch failed', { url, options, message: error.message, stack: error.stack });
521
+ }
501
522
 
502
523
  throw error;
503
524
  });
@@ -1547,7 +1568,7 @@ class Contact {
1547
1568
 
1548
1569
  return new Contact({
1549
1570
  sourceId: single.id || '',
1550
- name: single.displayName,
1571
+ name: single.displayName || '',
1551
1572
  number: numbers.length ? numbers[0].number : '',
1552
1573
  numbers,
1553
1574
  emails,
@@ -1578,7 +1599,7 @@ class Contact {
1578
1599
 
1579
1600
  return new Contact({
1580
1601
  sourceId: single.id || '',
1581
- name: single.name,
1602
+ name: single.name || '',
1582
1603
  number: numbers.length ? numbers[0].number : '',
1583
1604
  numbers,
1584
1605
  emails,
@@ -1679,7 +1700,7 @@ class Contact {
1679
1700
  } = {}) {
1680
1701
  this.id = id;
1681
1702
  this.uuid = uuid;
1682
- this.name = name;
1703
+ this.name = name || '';
1683
1704
  this.number = number;
1684
1705
  this.numbers = numbers;
1685
1706
  this.email = email;
@@ -2988,17 +3009,66 @@ var updateFrom = (instance , from ) => {
2988
3009
 
2989
3010
  //
2990
3011
 
3012
+
3013
+
3014
+
3015
+
3016
+
3017
+
3018
+
3019
+
3020
+
3021
+
3022
+
3023
+
3024
+
3025
+
3026
+
3027
+
3028
+ class Recording {
3029
+
3030
+
3031
+
3032
+
3033
+
3034
+
3035
+ static parseMany(recordings ) {
3036
+ return recordings.map(item => Recording.parse(item));
3037
+ }
3038
+
3039
+ static parse(plain ) {
3040
+ return new Recording({
3041
+ deleted: plain.deleted,
3042
+ fileName: plain.filename,
3043
+ end: plain.end_time ? moment(plain.end_time).toDate() : null,
3044
+ start: moment(plain.start_time).toDate(),
3045
+ uuid: plain.uuid,
3046
+ });
3047
+ }
3048
+
3049
+ constructor({ deleted, end, fileName, start, uuid } ) {
3050
+ this.deleted = deleted;
3051
+ this.end = end;
3052
+ this.fileName = fileName;
3053
+ this.start = start;
3054
+ this.uuid = uuid;
3055
+ }
3056
+ }
3057
+
3058
+ //
3059
+
2991
3060
 
2992
-
3061
+
2993
3062
 
2994
3063
 
2995
3064
 
2996
3065
 
2997
3066
 
2998
-
3067
+
2999
3068
 
3000
3069
 
3001
3070
 
3071
+
3002
3072
 
3003
3073
 
3004
3074
 
@@ -3011,7 +3081,7 @@ var updateFrom = (instance , from ) => {
3011
3081
 
3012
3082
 
3013
3083
 
3014
-
3084
+
3015
3085
 
3016
3086
 
3017
3087
 
@@ -3026,13 +3096,14 @@ var updateFrom = (instance , from ) => {
3026
3096
 
3027
3097
 
3028
3098
 
3029
-
3099
+
3100
+
3030
3101
 
3031
3102
 
3032
3103
  class CallLog {
3033
3104
 
3034
3105
 
3035
-
3106
+
3036
3107
 
3037
3108
 
3038
3109
 
@@ -3049,7 +3120,7 @@ class CallLog {
3049
3120
 
3050
3121
 
3051
3122
 
3052
-
3123
+
3053
3124
 
3054
3125
  static merge(current , toMerge ) {
3055
3126
  const onlyUnique = (value, index, self) => self.indexOf(value) === index;
@@ -3066,7 +3137,7 @@ class CallLog {
3066
3137
 
3067
3138
  static parse(plain ) {
3068
3139
  return new CallLog({
3069
- answer: moment(plain.answer).toDate(),
3140
+ answer: plain.answer ? moment(plain.answer).toDate() : null,
3070
3141
  answered: plain.answered,
3071
3142
  callDirection: plain.call_direction,
3072
3143
  destination: {
@@ -3080,13 +3151,14 @@ class CallLog {
3080
3151
  id: plain.id,
3081
3152
  duration: (plain.duration || 0) * 1000, // duration is in seconds
3082
3153
  start: moment(plain.start).toDate(),
3083
- end: moment(plain.end).toDate(),
3154
+ end: plain.end ? moment(plain.end).toDate() : null,
3155
+ recordings: Recording.parseMany(plain.recordings),
3084
3156
  });
3085
3157
  }
3086
3158
 
3087
3159
  static parseNew(plain , session ) {
3088
3160
  return new CallLog({
3089
- answer: moment(plain.answer).toDate(),
3161
+ answer: plain.answer ? moment(plain.answer).toDate() : null,
3090
3162
  answered: plain.answered,
3091
3163
  callDirection: plain.call_direction,
3092
3164
  destination: {
@@ -3100,7 +3172,8 @@ class CallLog {
3100
3172
  id: plain.id,
3101
3173
  duration: (plain.duration || 0) * 1000, // duration is in seconds
3102
3174
  start: moment(plain.start).toDate(),
3103
- end: moment(plain.end).toDate(),
3175
+ end: plain.end ? moment(plain.end).toDate() : null,
3176
+ recordings: Recording.parseMany(plain.recordings),
3104
3177
  // @TODO: FIXME add verification declined vs missed call
3105
3178
  newMissedCall: session
3106
3179
  && session.hasExtension(plain.requested_extension || plain.destination_extension) && !plain.answered,
@@ -4336,6 +4409,10 @@ class ApiClient {
4336
4409
  this.fetchOptions = fetchOptions;
4337
4410
  this.client.setFetchOptions(fetchOptions);
4338
4411
  }
4412
+
4413
+ disableErrorLogging() {
4414
+ this.client.disableErrorLogging();
4415
+ }
4339
4416
  }
4340
4417
 
4341
4418
  const mockedResponse = { data: { token: 1 } };