@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
package/lib/api/auth.js CHANGED
@@ -314,7 +314,13 @@ class IssueReporter {
314
314
  }
315
315
 
316
316
  _isLevelAbove(level1 , level2 ) {
317
- return LOG_LEVELS.indexOf(level1) > LOG_LEVELS.indexOf(level2);
317
+ const index1 = LOG_LEVELS.indexOf(level1);
318
+ const index2 = LOG_LEVELS.indexOf(level2);
319
+ if (index1 === -1 || index2 === -1) {
320
+ return false;
321
+ }
322
+
323
+ return index1 > index2;
318
324
  }
319
325
 
320
326
  _makeCategory(category ) {
@@ -372,6 +378,7 @@ class ApiRequester {
372
378
 
373
379
 
374
380
 
381
+
375
382
 
376
383
 
377
384
 
@@ -411,6 +418,8 @@ class ApiRequester {
411
418
  this.token = token;
412
419
  }
413
420
 
421
+ this.shouldLogErrors = true;
422
+
414
423
  methods.forEach(method => {
415
424
  // $FlowFixMe
416
425
  ApiRequester.prototype[method] = function sugar(...args) {
@@ -434,6 +443,14 @@ class ApiRequester {
434
443
  this.fetchOptions = options;
435
444
  }
436
445
 
446
+ disableErrorLogging() {
447
+ this.shouldLogErrors = false;
448
+ }
449
+
450
+ enableErrorLogging() {
451
+ this.shouldLogErrors = true;
452
+ }
453
+
437
454
  async call(
438
455
  path ,
439
456
  method = 'get',
@@ -494,7 +511,9 @@ class ApiRequester {
494
511
  ? exceptionClass.fromText(err, response.status)
495
512
  : exceptionClass.fromResponse(err, response.status);
496
513
 
497
- logger.error('API error', error);
514
+ if (this.shouldLogErrors) {
515
+ logger.error('API error', error);
516
+ }
498
517
 
499
518
  throw error;
500
519
  });
@@ -502,7 +521,9 @@ class ApiRequester {
502
521
 
503
522
  return newParse(response, isJson);
504
523
  }).catch(error => {
505
- logger.error('Fetch failed', { url, options, message: error.message, stack: error.stack });
524
+ if (this.shouldLogErrors) {
525
+ logger.error('Fetch failed', { url, options, message: error.message, stack: error.stack });
526
+ }
506
527
 
507
528
  throw error;
508
529
  });
@@ -251,7 +251,13 @@ class IssueReporter {
251
251
  }
252
252
 
253
253
  _isLevelAbove(level1 , level2 ) {
254
- return LOG_LEVELS.indexOf(level1) > LOG_LEVELS.indexOf(level2);
254
+ const index1 = LOG_LEVELS.indexOf(level1);
255
+ const index2 = LOG_LEVELS.indexOf(level2);
256
+ if (index1 === -1 || index2 === -1) {
257
+ return false;
258
+ }
259
+
260
+ return index1 > index2;
255
261
  }
256
262
 
257
263
  _makeCategory(category ) {
@@ -291,6 +297,17 @@ const realFetch = () => {
291
297
 
292
298
  //
293
299
 
300
+ var newFrom = (instance , ToClass ) => {
301
+ const args = {};
302
+ Object.getOwnPropertyNames(instance).forEach(prop => {
303
+ args[prop] = instance[prop];
304
+ });
305
+
306
+ return new ToClass(args);
307
+ };
308
+
309
+ //
310
+
294
311
  const swarmPublicKey = `-----BEGIN PUBLIC KEY-----
295
312
  MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAmkXOuNfY8u5xoTiIhkb8
296
313
  djnbIwG/Wrz3vpo8BZir8L5e1a1nSy740qBjP7ZINBQoALDhFfmdOfJnCyEGiHuz
@@ -303,32 +320,70 @@ BwIDAQAB
303
320
 
304
321
  //
305
322
 
306
- var newFrom = (instance , ToClass ) => {
307
- const args = {};
308
- Object.getOwnPropertyNames(instance).forEach(prop => {
309
- args[prop] = instance[prop];
310
- });
311
-
312
- return new ToClass(args);
313
- };
323
+ jsrsasign.KEYUTIL.getKey(swarmPublicKey);
314
324
 
315
325
  //
316
326
 
317
- jsrsasign.KEYUTIL.getKey(swarmPublicKey);
327
+
328
+
329
+
330
+
331
+
332
+
333
+
334
+
335
+
336
+
337
+
338
+
339
+
340
+
341
+
342
+
343
+ class Recording {
344
+
345
+
346
+
347
+
348
+
349
+
350
+ static parseMany(recordings ) {
351
+ return recordings.map(item => Recording.parse(item));
352
+ }
353
+
354
+ static parse(plain ) {
355
+ return new Recording({
356
+ deleted: plain.deleted,
357
+ fileName: plain.filename,
358
+ end: plain.end_time ? moment__default['default'](plain.end_time).toDate() : null,
359
+ start: moment__default['default'](plain.start_time).toDate(),
360
+ uuid: plain.uuid,
361
+ });
362
+ }
363
+
364
+ constructor({ deleted, end, fileName, start, uuid } ) {
365
+ this.deleted = deleted;
366
+ this.end = end;
367
+ this.fileName = fileName;
368
+ this.start = start;
369
+ this.uuid = uuid;
370
+ }
371
+ }
318
372
 
319
373
  //
320
374
 
321
375
 
322
-
376
+
323
377
 
324
378
 
325
379
 
326
380
 
327
381
 
328
-
382
+
329
383
 
330
384
 
331
385
 
386
+
332
387
 
333
388
 
334
389
 
@@ -341,7 +396,7 @@ jsrsasign.KEYUTIL.getKey(swarmPublicKey);
341
396
 
342
397
 
343
398
 
344
-
399
+
345
400
 
346
401
 
347
402
 
@@ -356,13 +411,14 @@ jsrsasign.KEYUTIL.getKey(swarmPublicKey);
356
411
 
357
412
 
358
413
 
359
-
414
+
415
+
360
416
 
361
417
 
362
418
  class CallLog {
363
419
 
364
420
 
365
-
421
+
366
422
 
367
423
 
368
424
 
@@ -379,7 +435,7 @@ class CallLog {
379
435
 
380
436
 
381
437
 
382
-
438
+
383
439
 
384
440
  static merge(current , toMerge ) {
385
441
  const onlyUnique = (value, index, self) => self.indexOf(value) === index;
@@ -396,7 +452,7 @@ class CallLog {
396
452
 
397
453
  static parse(plain ) {
398
454
  return new CallLog({
399
- answer: moment__default['default'](plain.answer).toDate(),
455
+ answer: plain.answer ? moment__default['default'](plain.answer).toDate() : null,
400
456
  answered: plain.answered,
401
457
  callDirection: plain.call_direction,
402
458
  destination: {
@@ -410,13 +466,14 @@ class CallLog {
410
466
  id: plain.id,
411
467
  duration: (plain.duration || 0) * 1000, // duration is in seconds
412
468
  start: moment__default['default'](plain.start).toDate(),
413
- end: moment__default['default'](plain.end).toDate(),
469
+ end: plain.end ? moment__default['default'](plain.end).toDate() : null,
470
+ recordings: Recording.parseMany(plain.recordings),
414
471
  });
415
472
  }
416
473
 
417
474
  static parseNew(plain , session ) {
418
475
  return new CallLog({
419
- answer: moment__default['default'](plain.answer).toDate(),
476
+ answer: plain.answer ? moment__default['default'](plain.answer).toDate() : null,
420
477
  answered: plain.answered,
421
478
  callDirection: plain.call_direction,
422
479
  destination: {
@@ -430,7 +487,8 @@ class CallLog {
430
487
  id: plain.id,
431
488
  duration: (plain.duration || 0) * 1000, // duration is in seconds
432
489
  start: moment__default['default'](plain.start).toDate(),
433
- end: moment__default['default'](plain.end).toDate(),
490
+ end: plain.end ? moment__default['default'](plain.end).toDate() : null,
491
+ recordings: Recording.parseMany(plain.recordings),
434
492
  // @TODO: FIXME add verification declined vs missed call
435
493
  newMissedCall: session
436
494
  && session.hasExtension(plain.requested_extension || plain.destination_extension) && !plain.answered,
package/lib/api/calld.js CHANGED
@@ -3,7 +3,6 @@
3
3
  var jsBase64 = require('js-base64');
4
4
  var moment = require('moment');
5
5
  require('sip.js/lib/api/session-state');
6
- var jsrsasign = require('jsrsasign');
7
6
 
8
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
9
8
 
@@ -313,7 +312,13 @@ class IssueReporter {
313
312
  }
314
313
 
315
314
  _isLevelAbove(level1 , level2 ) {
316
- return LOG_LEVELS.indexOf(level1) > LOG_LEVELS.indexOf(level2);
315
+ const index1 = LOG_LEVELS.indexOf(level1);
316
+ const index2 = LOG_LEVELS.indexOf(level2);
317
+ if (index1 === -1 || index2 === -1) {
318
+ return false;
319
+ }
320
+
321
+ return index1 > index2;
317
322
  }
318
323
 
319
324
  _makeCategory(category ) {
@@ -371,6 +376,7 @@ class ApiRequester {
371
376
 
372
377
 
373
378
 
379
+
374
380
 
375
381
 
376
382
 
@@ -410,6 +416,8 @@ class ApiRequester {
410
416
  this.token = token;
411
417
  }
412
418
 
419
+ this.shouldLogErrors = true;
420
+
413
421
  methods.forEach(method => {
414
422
  // $FlowFixMe
415
423
  ApiRequester.prototype[method] = function sugar(...args) {
@@ -433,6 +441,14 @@ class ApiRequester {
433
441
  this.fetchOptions = options;
434
442
  }
435
443
 
444
+ disableErrorLogging() {
445
+ this.shouldLogErrors = false;
446
+ }
447
+
448
+ enableErrorLogging() {
449
+ this.shouldLogErrors = true;
450
+ }
451
+
436
452
  async call(
437
453
  path ,
438
454
  method = 'get',
@@ -493,7 +509,9 @@ class ApiRequester {
493
509
  ? exceptionClass.fromText(err, response.status)
494
510
  : exceptionClass.fromResponse(err, response.status);
495
511
 
496
- logger.error('API error', error);
512
+ if (this.shouldLogErrors) {
513
+ logger.error('API error', error);
514
+ }
497
515
 
498
516
  throw error;
499
517
  });
@@ -501,7 +519,9 @@ class ApiRequester {
501
519
 
502
520
  return newParse(response, isJson);
503
521
  }).catch(error => {
504
- logger.error('Fetch failed', { url, options, message: error.message, stack: error.stack });
522
+ if (this.shouldLogErrors) {
523
+ logger.error('Fetch failed', { url, options, message: error.message, stack: error.stack });
524
+ }
505
525
 
506
526
  throw error;
507
527
  });
@@ -1016,22 +1036,6 @@ class Call {
1016
1036
  }
1017
1037
  }
1018
1038
 
1019
- //
1020
-
1021
- const swarmPublicKey = `-----BEGIN PUBLIC KEY-----
1022
- MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAmkXOuNfY8u5xoTiIhkb8
1023
- djnbIwG/Wrz3vpo8BZir8L5e1a1nSy740qBjP7ZINBQoALDhFfmdOfJnCyEGiHuz
1024
- ZW6jbG6C3PryE3Bu6GKwqSmD6k3q4Zk27fpwYAnNl+rWhYYM563rJZBda/INyHNN
1025
- pK7M1mixWi7gNdjjXwoEXSSBx+VpYMkY6LiAB2mvHXTY9M1qI14dvgGoQISZQoKi
1026
- NMTRCg5UP2ic0Dd9nSz/XpcOxGfa+0fwIl1F7RC1tJXOqvkGGPTOV4LLfg/Yta3h
1027
- nUPX9EZZDIX6vO/0IBV1LzjSl2A1bYFYAjJfowv3i1CpvONBOClHjSY5t9Y8MH6p
1028
- BwIDAQAB
1029
- -----END PUBLIC KEY-----`;
1030
-
1031
- //
1032
-
1033
- jsrsasign.KEYUTIL.getKey(swarmPublicKey);
1034
-
1035
1039
  //
1036
1040
  /* eslint-disable no-param-reassign */
1037
1041
 
package/lib/api/chatd.js CHANGED
@@ -311,7 +311,13 @@ class IssueReporter {
311
311
  }
312
312
 
313
313
  _isLevelAbove(level1 , level2 ) {
314
- return LOG_LEVELS.indexOf(level1) > LOG_LEVELS.indexOf(level2);
314
+ const index1 = LOG_LEVELS.indexOf(level1);
315
+ const index2 = LOG_LEVELS.indexOf(level2);
316
+ if (index1 === -1 || index2 === -1) {
317
+ return false;
318
+ }
319
+
320
+ return index1 > index2;
315
321
  }
316
322
 
317
323
  _makeCategory(category ) {
@@ -369,6 +375,7 @@ class ApiRequester {
369
375
 
370
376
 
371
377
 
378
+
372
379
 
373
380
 
374
381
 
@@ -408,6 +415,8 @@ class ApiRequester {
408
415
  this.token = token;
409
416
  }
410
417
 
418
+ this.shouldLogErrors = true;
419
+
411
420
  methods.forEach(method => {
412
421
  // $FlowFixMe
413
422
  ApiRequester.prototype[method] = function sugar(...args) {
@@ -431,6 +440,14 @@ class ApiRequester {
431
440
  this.fetchOptions = options;
432
441
  }
433
442
 
443
+ disableErrorLogging() {
444
+ this.shouldLogErrors = false;
445
+ }
446
+
447
+ enableErrorLogging() {
448
+ this.shouldLogErrors = true;
449
+ }
450
+
434
451
  async call(
435
452
  path ,
436
453
  method = 'get',
@@ -491,7 +508,9 @@ class ApiRequester {
491
508
  ? exceptionClass.fromText(err, response.status)
492
509
  : exceptionClass.fromResponse(err, response.status);
493
510
 
494
- logger.error('API error', error);
511
+ if (this.shouldLogErrors) {
512
+ logger.error('API error', error);
513
+ }
495
514
 
496
515
  throw error;
497
516
  });
@@ -499,7 +518,9 @@ class ApiRequester {
499
518
 
500
519
  return newParse(response, isJson);
501
520
  }).catch(error => {
502
- logger.error('Fetch failed', { url, options, message: error.message, stack: error.stack });
521
+ if (this.shouldLogErrors) {
522
+ logger.error('Fetch failed', { url, options, message: error.message, stack: error.stack });
523
+ }
503
524
 
504
525
  throw error;
505
526
  });
package/lib/api/confd.js CHANGED
@@ -311,7 +311,13 @@ class IssueReporter {
311
311
  }
312
312
 
313
313
  _isLevelAbove(level1 , level2 ) {
314
- return LOG_LEVELS.indexOf(level1) > LOG_LEVELS.indexOf(level2);
314
+ const index1 = LOG_LEVELS.indexOf(level1);
315
+ const index2 = LOG_LEVELS.indexOf(level2);
316
+ if (index1 === -1 || index2 === -1) {
317
+ return false;
318
+ }
319
+
320
+ return index1 > index2;
315
321
  }
316
322
 
317
323
  _makeCategory(category ) {
@@ -369,6 +375,7 @@ class ApiRequester {
369
375
 
370
376
 
371
377
 
378
+
372
379
 
373
380
 
374
381
 
@@ -408,6 +415,8 @@ class ApiRequester {
408
415
  this.token = token;
409
416
  }
410
417
 
418
+ this.shouldLogErrors = true;
419
+
411
420
  methods.forEach(method => {
412
421
  // $FlowFixMe
413
422
  ApiRequester.prototype[method] = function sugar(...args) {
@@ -431,6 +440,14 @@ class ApiRequester {
431
440
  this.fetchOptions = options;
432
441
  }
433
442
 
443
+ disableErrorLogging() {
444
+ this.shouldLogErrors = false;
445
+ }
446
+
447
+ enableErrorLogging() {
448
+ this.shouldLogErrors = true;
449
+ }
450
+
434
451
  async call(
435
452
  path ,
436
453
  method = 'get',
@@ -491,7 +508,9 @@ class ApiRequester {
491
508
  ? exceptionClass.fromText(err, response.status)
492
509
  : exceptionClass.fromResponse(err, response.status);
493
510
 
494
- logger.error('API error', error);
511
+ if (this.shouldLogErrors) {
512
+ logger.error('API error', error);
513
+ }
495
514
 
496
515
  throw error;
497
516
  });
@@ -499,7 +518,9 @@ class ApiRequester {
499
518
 
500
519
  return newParse(response, isJson);
501
520
  }).catch(error => {
502
- logger.error('Fetch failed', { url, options, message: error.message, stack: error.stack });
521
+ if (this.shouldLogErrors) {
522
+ logger.error('Fetch failed', { url, options, message: error.message, stack: error.stack });
523
+ }
503
524
 
504
525
  throw error;
505
526
  });
@@ -315,7 +315,13 @@ class IssueReporter {
315
315
  }
316
316
 
317
317
  _isLevelAbove(level1 , level2 ) {
318
- return LOG_LEVELS.indexOf(level1) > LOG_LEVELS.indexOf(level2);
318
+ const index1 = LOG_LEVELS.indexOf(level1);
319
+ const index2 = LOG_LEVELS.indexOf(level2);
320
+ if (index1 === -1 || index2 === -1) {
321
+ return false;
322
+ }
323
+
324
+ return index1 > index2;
319
325
  }
320
326
 
321
327
  _makeCategory(category ) {
@@ -373,6 +379,7 @@ class ApiRequester {
373
379
 
374
380
 
375
381
 
382
+
376
383
 
377
384
 
378
385
 
@@ -412,6 +419,8 @@ class ApiRequester {
412
419
  this.token = token;
413
420
  }
414
421
 
422
+ this.shouldLogErrors = true;
423
+
415
424
  methods.forEach(method => {
416
425
  // $FlowFixMe
417
426
  ApiRequester.prototype[method] = function sugar(...args) {
@@ -435,6 +444,14 @@ class ApiRequester {
435
444
  this.fetchOptions = options;
436
445
  }
437
446
 
447
+ disableErrorLogging() {
448
+ this.shouldLogErrors = false;
449
+ }
450
+
451
+ enableErrorLogging() {
452
+ this.shouldLogErrors = true;
453
+ }
454
+
438
455
  async call(
439
456
  path ,
440
457
  method = 'get',
@@ -495,7 +512,9 @@ class ApiRequester {
495
512
  ? exceptionClass.fromText(err, response.status)
496
513
  : exceptionClass.fromResponse(err, response.status);
497
514
 
498
- logger.error('API error', error);
515
+ if (this.shouldLogErrors) {
516
+ logger.error('API error', error);
517
+ }
499
518
 
500
519
  throw error;
501
520
  });
@@ -503,7 +522,9 @@ class ApiRequester {
503
522
 
504
523
  return newParse(response, isJson);
505
524
  }).catch(error => {
506
- logger.error('Fetch failed', { url, options, message: error.message, stack: error.stack });
525
+ if (this.shouldLogErrors) {
526
+ logger.error('Fetch failed', { url, options, message: error.message, stack: error.stack });
527
+ }
507
528
 
508
529
  throw error;
509
530
  });
package/lib/api/dird.js CHANGED
@@ -313,7 +313,13 @@ class IssueReporter {
313
313
  }
314
314
 
315
315
  _isLevelAbove(level1 , level2 ) {
316
- return LOG_LEVELS.indexOf(level1) > LOG_LEVELS.indexOf(level2);
316
+ const index1 = LOG_LEVELS.indexOf(level1);
317
+ const index2 = LOG_LEVELS.indexOf(level2);
318
+ if (index1 === -1 || index2 === -1) {
319
+ return false;
320
+ }
321
+
322
+ return index1 > index2;
317
323
  }
318
324
 
319
325
  _makeCategory(category ) {
@@ -371,6 +377,7 @@ class ApiRequester {
371
377
 
372
378
 
373
379
 
380
+
374
381
 
375
382
 
376
383
 
@@ -410,6 +417,8 @@ class ApiRequester {
410
417
  this.token = token;
411
418
  }
412
419
 
420
+ this.shouldLogErrors = true;
421
+
413
422
  methods.forEach(method => {
414
423
  // $FlowFixMe
415
424
  ApiRequester.prototype[method] = function sugar(...args) {
@@ -433,6 +442,14 @@ class ApiRequester {
433
442
  this.fetchOptions = options;
434
443
  }
435
444
 
445
+ disableErrorLogging() {
446
+ this.shouldLogErrors = false;
447
+ }
448
+
449
+ enableErrorLogging() {
450
+ this.shouldLogErrors = true;
451
+ }
452
+
436
453
  async call(
437
454
  path ,
438
455
  method = 'get',
@@ -493,7 +510,9 @@ class ApiRequester {
493
510
  ? exceptionClass.fromText(err, response.status)
494
511
  : exceptionClass.fromResponse(err, response.status);
495
512
 
496
- logger.error('API error', error);
513
+ if (this.shouldLogErrors) {
514
+ logger.error('API error', error);
515
+ }
497
516
 
498
517
  throw error;
499
518
  });
@@ -501,7 +520,9 @@ class ApiRequester {
501
520
 
502
521
  return newParse(response, isJson);
503
522
  }).catch(error => {
504
- logger.error('Fetch failed', { url, options, message: error.message, stack: error.stack });
523
+ if (this.shouldLogErrors) {
524
+ logger.error('Fetch failed', { url, options, message: error.message, stack: error.stack });
525
+ }
505
526
 
506
527
  throw error;
507
528
  });
@@ -1037,7 +1058,7 @@ class Contact {
1037
1058
 
1038
1059
  return new Contact({
1039
1060
  sourceId: single.id || '',
1040
- name: single.displayName,
1061
+ name: single.displayName || '',
1041
1062
  number: numbers.length ? numbers[0].number : '',
1042
1063
  numbers,
1043
1064
  emails,
@@ -1068,7 +1089,7 @@ class Contact {
1068
1089
 
1069
1090
  return new Contact({
1070
1091
  sourceId: single.id || '',
1071
- name: single.name,
1092
+ name: single.name || '',
1072
1093
  number: numbers.length ? numbers[0].number : '',
1073
1094
  numbers,
1074
1095
  emails,
@@ -1169,7 +1190,7 @@ class Contact {
1169
1190
  } = {}) {
1170
1191
  this.id = id;
1171
1192
  this.uuid = uuid;
1172
- this.name = name;
1193
+ this.name = name || '';
1173
1194
  this.number = number;
1174
1195
  this.numbers = numbers;
1175
1196
  this.email = email;
@@ -250,7 +250,13 @@ class IssueReporter {
250
250
  }
251
251
 
252
252
  _isLevelAbove(level1 , level2 ) {
253
- return LOG_LEVELS.indexOf(level1) > LOG_LEVELS.indexOf(level2);
253
+ const index1 = LOG_LEVELS.indexOf(level1);
254
+ const index2 = LOG_LEVELS.indexOf(level2);
255
+ if (index1 === -1 || index2 === -1) {
256
+ return false;
257
+ }
258
+
259
+ return index1 > index2;
254
260
  }
255
261
 
256
262
  _makeCategory(category ) {