@wazo/sdk 0.37.40 → 0.37.43

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 (109) hide show
  1. package/dist/wazo-sdk.js +3 -3
  2. package/esm/__tests__/api-client.test.js +45 -22
  3. package/esm/__tests__/web-rtc-client.test.js +49 -24
  4. package/esm/api/agentd.js +12 -7
  5. package/esm/api/amid.js +12 -7
  6. package/esm/api/application.js +12 -7
  7. package/esm/api/auth.js +16 -8
  8. package/esm/api/call-logd.js +12 -7
  9. package/esm/api/calld.js +12 -7
  10. package/esm/api/chatd.js +12 -7
  11. package/esm/api/confd.js +12 -7
  12. package/esm/api/ctid-ng.js +14 -7
  13. package/esm/api/dird.js +12 -7
  14. package/esm/api/webhookd.js +12 -7
  15. package/esm/api-client.js +45 -22
  16. package/esm/checker/Checker.js +50 -25
  17. package/esm/checker/checks/aor.js +45 -22
  18. package/esm/checker/checks/api.js +45 -22
  19. package/esm/checker/checks/index.js +50 -25
  20. package/esm/checker/checks/wazo-websocket.js +13 -8
  21. package/esm/checker/checks/webrtc-transport.js +49 -24
  22. package/esm/checker/checks/webrtc.js +49 -24
  23. package/esm/domain/AdHocAPIConference.js +54 -23
  24. package/esm/domain/Features.js +54 -23
  25. package/esm/domain/Phone/CTIPhone.js +54 -23
  26. package/esm/domain/Phone/WebRTCPhone.js +18 -11
  27. package/esm/index.js +89 -29
  28. package/esm/lib/WazoSessionDescriptionHandler.js +12 -7
  29. package/esm/service/CallApi.js +54 -23
  30. package/esm/service/IssueReporter.js +12 -7
  31. package/esm/service/__tests__/IssueReporter.test.js +18 -7
  32. package/esm/service/getApiClient.js +63 -24
  33. package/esm/simple/Auth.js +89 -29
  34. package/esm/simple/Configuration.js +89 -29
  35. package/esm/simple/Directory.js +54 -23
  36. package/esm/simple/Phone.js +89 -29
  37. package/esm/simple/Websocket.js +13 -8
  38. package/esm/simple/index.js +89 -29
  39. package/esm/simple/room/LocalParticipant.js +89 -29
  40. package/esm/simple/room/Participant.js +89 -29
  41. package/esm/simple/room/RemoteParticipant.js +89 -29
  42. package/esm/simple/room/Room.js +89 -29
  43. package/esm/simple/room/SipRoom.js +89 -29
  44. package/esm/simple/room/Stream.js +89 -29
  45. package/esm/simple/room/__tests__/RemoteParticipant.test.js +89 -29
  46. package/esm/simple/utils.js +89 -29
  47. package/esm/utils/__tests__/api-requester.test.js +12 -7
  48. package/esm/utils/api-requester.js +12 -7
  49. package/esm/web-rtc-client.js +49 -24
  50. package/esm/websocket-client.js +13 -8
  51. package/lib/__tests__/api-client.test.js +45 -22
  52. package/lib/__tests__/web-rtc-client.test.js +49 -24
  53. package/lib/api/agentd.js +12 -7
  54. package/lib/api/amid.js +12 -7
  55. package/lib/api/application.js +12 -7
  56. package/lib/api/auth.js +16 -8
  57. package/lib/api/call-logd.js +12 -7
  58. package/lib/api/calld.js +12 -7
  59. package/lib/api/chatd.js +12 -7
  60. package/lib/api/confd.js +12 -7
  61. package/lib/api/ctid-ng.js +14 -7
  62. package/lib/api/dird.js +12 -7
  63. package/lib/api/webhookd.js +12 -7
  64. package/lib/api-client.js +45 -22
  65. package/lib/checker/Checker.js +50 -25
  66. package/lib/checker/checks/aor.js +45 -22
  67. package/lib/checker/checks/api.js +45 -22
  68. package/lib/checker/checks/index.js +50 -25
  69. package/lib/checker/checks/wazo-websocket.js +13 -8
  70. package/lib/checker/checks/webrtc-transport.js +49 -24
  71. package/lib/checker/checks/webrtc.js +49 -24
  72. package/lib/domain/AdHocAPIConference.js +54 -23
  73. package/lib/domain/Features.js +54 -23
  74. package/lib/domain/Phone/CTIPhone.js +54 -23
  75. package/lib/domain/Phone/WebRTCPhone.js +18 -11
  76. package/lib/index.js +89 -29
  77. package/lib/lib/WazoSessionDescriptionHandler.js +12 -7
  78. package/lib/service/CallApi.js +54 -23
  79. package/lib/service/IssueReporter.js +12 -7
  80. package/lib/service/__tests__/IssueReporter.test.js +18 -7
  81. package/lib/service/getApiClient.js +64 -23
  82. package/lib/simple/Auth.js +89 -29
  83. package/lib/simple/Configuration.js +89 -29
  84. package/lib/simple/Directory.js +54 -23
  85. package/lib/simple/Phone.js +89 -29
  86. package/lib/simple/Websocket.js +13 -8
  87. package/lib/simple/index.js +89 -29
  88. package/lib/simple/room/LocalParticipant.js +89 -29
  89. package/lib/simple/room/Participant.js +89 -29
  90. package/lib/simple/room/RemoteParticipant.js +89 -29
  91. package/lib/simple/room/Room.js +89 -29
  92. package/lib/simple/room/SipRoom.js +89 -29
  93. package/lib/simple/room/Stream.js +89 -29
  94. package/lib/simple/room/__tests__/RemoteParticipant.test.js +89 -29
  95. package/lib/simple/utils.js +89 -29
  96. package/lib/utils/__tests__/api-requester.test.js +12 -7
  97. package/lib/utils/api-requester.js +12 -7
  98. package/lib/web-rtc-client.js +49 -24
  99. package/lib/websocket-client.js +13 -8
  100. package/package.json +1 -1
  101. package/src/api/auth.js +4 -1
  102. package/src/api-client.js +26 -13
  103. package/src/domain/Phone/WebRTCPhone.js +4 -4
  104. package/src/service/IssueReporter.js +12 -7
  105. package/src/service/__tests__/IssueReporter.test.js +6 -0
  106. package/src/service/getApiClient.js +19 -1
  107. package/src/simple/Auth.js +21 -0
  108. package/src/web-rtc-client.js +4 -2
  109. package/src/websocket-client.js +1 -1
@@ -687,13 +687,9 @@ class IssueReporter {
687
687
 
688
688
  setTimeout(() => {
689
689
  if (isArray) {
690
- payload = payload.map(message => {
691
- message._retry = retry + 1;
692
- return message;
693
- });
694
- } else {
695
- // $FlowFixMe
696
- payload._retry = retry + 1;
690
+ payload = payload.map(message => this._writeRetryCount(message, retry + 1));
691
+ } else if (payload && typeof payload === 'object') {
692
+ payload = this._writeRetryCount(payload, retry + 1);
697
693
  }
698
694
 
699
695
  this._sendDebugToGrafana(payload, retry + 1);
@@ -701,6 +697,15 @@ class IssueReporter {
701
697
  });
702
698
  }
703
699
 
700
+ _writeRetryCount(message , count ) {
701
+ if (message && typeof message === 'object') {
702
+ // $FlowFixMe
703
+ message._retry = count;
704
+ }
705
+
706
+ return message;
707
+ }
708
+
704
709
  _isLevelAbove(level1 , level2 ) {
705
710
  const index1 = LOG_LEVELS.indexOf(level1);
706
711
  const index2 = LOG_LEVELS.indexOf(level2);
@@ -2802,9 +2807,12 @@ var authMethods = (client , baseUrl ) => ({
2802
2807
  expiration: expiration || DETAULT_EXPIRATION,
2803
2808
  refresh_token: refreshToken,
2804
2809
  client_id: client.clientId,
2805
- tenant_id: tenantId,
2806
2810
  };
2807
2811
 
2812
+ if (tenantId) {
2813
+ body.tenant_id = tenantId;
2814
+ }
2815
+
2808
2816
  const headers = {
2809
2817
  'Content-Type': 'application/json',
2810
2818
  ...(isMobile ? { 'Wazo-Session-Type': 'mobile' } : {}),
@@ -4092,7 +4100,9 @@ global.wazoClients = global.wazoClients || {};
4092
4100
  global.wazoClientId = global.wazoClientId || {};
4093
4101
  global.wazoClientToken = global.wazoClientToken || {};
4094
4102
  global.wazoRefreshToken = global.wazoRefreshToken || {};
4103
+ global.wazoRefreshTenantId = global.wazoRefreshTenantId || {};
4095
4104
  global.wazoOnRefreshToken = global.wazoOnRefreshToken || {};
4105
+ global.wazoOnRefreshTokenError = global.wazoOnRefreshTokenError || {};
4096
4106
  global.wazoRefreshExpiration = global.wazoRefreshExpiration || {};
4097
4107
  global.wazoRefreshBackend = global.wazoRefreshBackend || {};
4098
4108
  global.wazoIsMobile = global.wazoIsMobile || {};
@@ -5138,6 +5148,7 @@ class ApiClient {
5138
5148
 
5139
5149
 
5140
5150
 
5151
+
5141
5152
 
5142
5153
 
5143
5154
 
@@ -5190,23 +5201,31 @@ class ApiClient {
5190
5201
  return null;
5191
5202
  }
5192
5203
 
5193
- const session = await this.auth.refreshToken(
5194
- this.refreshToken,
5195
- this.refreshBackend,
5196
- this.refreshExpiration,
5197
- this.isMobile,
5198
- this.refreshTenantId,
5199
- );
5200
-
5201
- logger$1.info('token refreshed', { token: session.token });
5204
+ try {
5205
+ const session = await this.auth.refreshToken(
5206
+ this.refreshToken,
5207
+ this.refreshBackend,
5208
+ this.refreshExpiration,
5209
+ this.isMobile,
5210
+ this.refreshTenantId,
5211
+ );
5212
+
5213
+ logger$1.info('token refreshed', { token: session.token });
5214
+
5215
+ if (this.onRefreshToken) {
5216
+ this.onRefreshToken(session.token, session);
5217
+ }
5202
5218
 
5203
- if (this.onRefreshToken) {
5204
- this.onRefreshToken(session.token, session);
5205
- }
5219
+ this.setToken(session.token);
5206
5220
 
5207
- this.setToken(session.token);
5221
+ return session.token;
5222
+ } catch (error) {
5223
+ logger$1.error('token refresh, error', error);
5208
5224
 
5209
- return session.token;
5225
+ if (this.onRefreshTokenError) {
5226
+ this.onRefreshTokenError(error);
5227
+ }
5228
+ }
5210
5229
  }
5211
5230
 
5212
5231
  setToken(token ) {
@@ -5229,6 +5248,10 @@ class ApiClient {
5229
5248
  this.onRefreshToken = onRefreshToken;
5230
5249
  }
5231
5250
 
5251
+ setOnRefreshTokenError(callback ) {
5252
+ this.onRefreshTokenError = callback;
5253
+ }
5254
+
5232
5255
  setRefreshExpiration(refreshExpiration ) {
5233
5256
  this.refreshExpiration = refreshExpiration;
5234
5257
  }
@@ -6093,8 +6116,10 @@ class WebRTCClient extends Emitter {
6093
6116
  conference: isConference,
6094
6117
  };
6095
6118
 
6096
- // Avoid sdh to created a new stream
6097
- session.sessionDescriptionHandler.localMediaStreamConstraints = options.constraints;
6119
+ // Avoid sdh to create a new stream
6120
+ if (session.sessionDescriptionHandler) {
6121
+ session.sessionDescriptionHandler.localMediaStreamConstraints = options.constraints;
6122
+ }
6098
6123
 
6099
6124
  // Send re-INVITE
6100
6125
  return session.invite(options);
package/lib/api/agentd.js CHANGED
@@ -398,13 +398,9 @@ class IssueReporter {
398
398
 
399
399
  setTimeout(() => {
400
400
  if (isArray) {
401
- payload = payload.map(message => {
402
- message._retry = retry + 1;
403
- return message;
404
- });
405
- } else {
406
- // $FlowFixMe
407
- payload._retry = retry + 1;
401
+ payload = payload.map(message => this._writeRetryCount(message, retry + 1));
402
+ } else if (payload && typeof payload === 'object') {
403
+ payload = this._writeRetryCount(payload, retry + 1);
408
404
  }
409
405
 
410
406
  this._sendDebugToGrafana(payload, retry + 1);
@@ -412,6 +408,15 @@ class IssueReporter {
412
408
  });
413
409
  }
414
410
 
411
+ _writeRetryCount(message , count ) {
412
+ if (message && typeof message === 'object') {
413
+ // $FlowFixMe
414
+ message._retry = count;
415
+ }
416
+
417
+ return message;
418
+ }
419
+
415
420
  _isLevelAbove(level1 , level2 ) {
416
421
  const index1 = LOG_LEVELS.indexOf(level1);
417
422
  const index2 = LOG_LEVELS.indexOf(level2);
package/lib/api/amid.js CHANGED
@@ -337,13 +337,9 @@ class IssueReporter {
337
337
 
338
338
  setTimeout(() => {
339
339
  if (isArray) {
340
- payload = payload.map(message => {
341
- message._retry = retry + 1;
342
- return message;
343
- });
344
- } else {
345
- // $FlowFixMe
346
- payload._retry = retry + 1;
340
+ payload = payload.map(message => this._writeRetryCount(message, retry + 1));
341
+ } else if (payload && typeof payload === 'object') {
342
+ payload = this._writeRetryCount(payload, retry + 1);
347
343
  }
348
344
 
349
345
  this._sendDebugToGrafana(payload, retry + 1);
@@ -351,6 +347,15 @@ class IssueReporter {
351
347
  });
352
348
  }
353
349
 
350
+ _writeRetryCount(message , count ) {
351
+ if (message && typeof message === 'object') {
352
+ // $FlowFixMe
353
+ message._retry = count;
354
+ }
355
+
356
+ return message;
357
+ }
358
+
354
359
  _isLevelAbove(level1 , level2 ) {
355
360
  const index1 = LOG_LEVELS.indexOf(level1);
356
361
  const index2 = LOG_LEVELS.indexOf(level2);
@@ -398,13 +398,9 @@ class IssueReporter {
398
398
 
399
399
  setTimeout(() => {
400
400
  if (isArray) {
401
- payload = payload.map(message => {
402
- message._retry = retry + 1;
403
- return message;
404
- });
405
- } else {
406
- // $FlowFixMe
407
- payload._retry = retry + 1;
401
+ payload = payload.map(message => this._writeRetryCount(message, retry + 1));
402
+ } else if (payload && typeof payload === 'object') {
403
+ payload = this._writeRetryCount(payload, retry + 1);
408
404
  }
409
405
 
410
406
  this._sendDebugToGrafana(payload, retry + 1);
@@ -412,6 +408,15 @@ class IssueReporter {
412
408
  });
413
409
  }
414
410
 
411
+ _writeRetryCount(message , count ) {
412
+ if (message && typeof message === 'object') {
413
+ // $FlowFixMe
414
+ message._retry = count;
415
+ }
416
+
417
+ return message;
418
+ }
419
+
415
420
  _isLevelAbove(level1 , level2 ) {
416
421
  const index1 = LOG_LEVELS.indexOf(level1);
417
422
  const index2 = LOG_LEVELS.indexOf(level2);
package/lib/api/auth.js CHANGED
@@ -401,13 +401,9 @@ class IssueReporter {
401
401
 
402
402
  setTimeout(() => {
403
403
  if (isArray) {
404
- payload = payload.map(message => {
405
- message._retry = retry + 1;
406
- return message;
407
- });
408
- } else {
409
- // $FlowFixMe
410
- payload._retry = retry + 1;
404
+ payload = payload.map(message => this._writeRetryCount(message, retry + 1));
405
+ } else if (payload && typeof payload === 'object') {
406
+ payload = this._writeRetryCount(payload, retry + 1);
411
407
  }
412
408
 
413
409
  this._sendDebugToGrafana(payload, retry + 1);
@@ -415,6 +411,15 @@ class IssueReporter {
415
411
  });
416
412
  }
417
413
 
414
+ _writeRetryCount(message , count ) {
415
+ if (message && typeof message === 'object') {
416
+ // $FlowFixMe
417
+ message._retry = count;
418
+ }
419
+
420
+ return message;
421
+ }
422
+
418
423
  _isLevelAbove(level1 , level2 ) {
419
424
  const index1 = LOG_LEVELS.indexOf(level1);
420
425
  const index2 = LOG_LEVELS.indexOf(level2);
@@ -1011,9 +1016,12 @@ var auth = (client , baseUrl ) => ({
1011
1016
  expiration: expiration || DETAULT_EXPIRATION,
1012
1017
  refresh_token: refreshToken,
1013
1018
  client_id: client.clientId,
1014
- tenant_id: tenantId,
1015
1019
  };
1016
1020
 
1021
+ if (tenantId) {
1022
+ body.tenant_id = tenantId;
1023
+ }
1024
+
1017
1025
  const headers = {
1018
1026
  'Content-Type': 'application/json',
1019
1027
  ...(isMobile ? { 'Wazo-Session-Type': 'mobile' } : {}),
@@ -338,13 +338,9 @@ class IssueReporter {
338
338
 
339
339
  setTimeout(() => {
340
340
  if (isArray) {
341
- payload = payload.map(message => {
342
- message._retry = retry + 1;
343
- return message;
344
- });
345
- } else {
346
- // $FlowFixMe
347
- payload._retry = retry + 1;
341
+ payload = payload.map(message => this._writeRetryCount(message, retry + 1));
342
+ } else if (payload && typeof payload === 'object') {
343
+ payload = this._writeRetryCount(payload, retry + 1);
348
344
  }
349
345
 
350
346
  this._sendDebugToGrafana(payload, retry + 1);
@@ -352,6 +348,15 @@ class IssueReporter {
352
348
  });
353
349
  }
354
350
 
351
+ _writeRetryCount(message , count ) {
352
+ if (message && typeof message === 'object') {
353
+ // $FlowFixMe
354
+ message._retry = count;
355
+ }
356
+
357
+ return message;
358
+ }
359
+
355
360
  _isLevelAbove(level1 , level2 ) {
356
361
  const index1 = LOG_LEVELS.indexOf(level1);
357
362
  const index2 = LOG_LEVELS.indexOf(level2);
package/lib/api/calld.js CHANGED
@@ -399,13 +399,9 @@ class IssueReporter {
399
399
 
400
400
  setTimeout(() => {
401
401
  if (isArray) {
402
- payload = payload.map(message => {
403
- message._retry = retry + 1;
404
- return message;
405
- });
406
- } else {
407
- // $FlowFixMe
408
- payload._retry = retry + 1;
402
+ payload = payload.map(message => this._writeRetryCount(message, retry + 1));
403
+ } else if (payload && typeof payload === 'object') {
404
+ payload = this._writeRetryCount(payload, retry + 1);
409
405
  }
410
406
 
411
407
  this._sendDebugToGrafana(payload, retry + 1);
@@ -413,6 +409,15 @@ class IssueReporter {
413
409
  });
414
410
  }
415
411
 
412
+ _writeRetryCount(message , count ) {
413
+ if (message && typeof message === 'object') {
414
+ // $FlowFixMe
415
+ message._retry = count;
416
+ }
417
+
418
+ return message;
419
+ }
420
+
416
421
  _isLevelAbove(level1 , level2 ) {
417
422
  const index1 = LOG_LEVELS.indexOf(level1);
418
423
  const index2 = LOG_LEVELS.indexOf(level2);
package/lib/api/chatd.js CHANGED
@@ -398,13 +398,9 @@ class IssueReporter {
398
398
 
399
399
  setTimeout(() => {
400
400
  if (isArray) {
401
- payload = payload.map(message => {
402
- message._retry = retry + 1;
403
- return message;
404
- });
405
- } else {
406
- // $FlowFixMe
407
- payload._retry = retry + 1;
401
+ payload = payload.map(message => this._writeRetryCount(message, retry + 1));
402
+ } else if (payload && typeof payload === 'object') {
403
+ payload = this._writeRetryCount(payload, retry + 1);
408
404
  }
409
405
 
410
406
  this._sendDebugToGrafana(payload, retry + 1);
@@ -412,6 +408,15 @@ class IssueReporter {
412
408
  });
413
409
  }
414
410
 
411
+ _writeRetryCount(message , count ) {
412
+ if (message && typeof message === 'object') {
413
+ // $FlowFixMe
414
+ message._retry = count;
415
+ }
416
+
417
+ return message;
418
+ }
419
+
415
420
  _isLevelAbove(level1 , level2 ) {
416
421
  const index1 = LOG_LEVELS.indexOf(level1);
417
422
  const index2 = LOG_LEVELS.indexOf(level2);
package/lib/api/confd.js CHANGED
@@ -398,13 +398,9 @@ class IssueReporter {
398
398
 
399
399
  setTimeout(() => {
400
400
  if (isArray) {
401
- payload = payload.map(message => {
402
- message._retry = retry + 1;
403
- return message;
404
- });
405
- } else {
406
- // $FlowFixMe
407
- payload._retry = retry + 1;
401
+ payload = payload.map(message => this._writeRetryCount(message, retry + 1));
402
+ } else if (payload && typeof payload === 'object') {
403
+ payload = this._writeRetryCount(payload, retry + 1);
408
404
  }
409
405
 
410
406
  this._sendDebugToGrafana(payload, retry + 1);
@@ -412,6 +408,15 @@ class IssueReporter {
412
408
  });
413
409
  }
414
410
 
411
+ _writeRetryCount(message , count ) {
412
+ if (message && typeof message === 'object') {
413
+ // $FlowFixMe
414
+ message._retry = count;
415
+ }
416
+
417
+ return message;
418
+ }
419
+
415
420
  _isLevelAbove(level1 , level2 ) {
416
421
  const index1 = LOG_LEVELS.indexOf(level1);
417
422
  const index2 = LOG_LEVELS.indexOf(level2);
@@ -402,13 +402,9 @@ class IssueReporter {
402
402
 
403
403
  setTimeout(() => {
404
404
  if (isArray) {
405
- payload = payload.map(message => {
406
- message._retry = retry + 1;
407
- return message;
408
- });
409
- } else {
410
- // $FlowFixMe
411
- payload._retry = retry + 1;
405
+ payload = payload.map(message => this._writeRetryCount(message, retry + 1));
406
+ } else if (payload && typeof payload === 'object') {
407
+ payload = this._writeRetryCount(payload, retry + 1);
412
408
  }
413
409
 
414
410
  this._sendDebugToGrafana(payload, retry + 1);
@@ -416,6 +412,15 @@ class IssueReporter {
416
412
  });
417
413
  }
418
414
 
415
+ _writeRetryCount(message , count ) {
416
+ if (message && typeof message === 'object') {
417
+ // $FlowFixMe
418
+ message._retry = count;
419
+ }
420
+
421
+ return message;
422
+ }
423
+
419
424
  _isLevelAbove(level1 , level2 ) {
420
425
  const index1 = LOG_LEVELS.indexOf(level1);
421
426
  const index2 = LOG_LEVELS.indexOf(level2);
@@ -1180,7 +1185,9 @@ global.wazoClients = global.wazoClients || {};
1180
1185
  global.wazoClientId = global.wazoClientId || {};
1181
1186
  global.wazoClientToken = global.wazoClientToken || {};
1182
1187
  global.wazoRefreshToken = global.wazoRefreshToken || {};
1188
+ global.wazoRefreshTenantId = global.wazoRefreshTenantId || {};
1183
1189
  global.wazoOnRefreshToken = global.wazoOnRefreshToken || {};
1190
+ global.wazoOnRefreshTokenError = global.wazoOnRefreshTokenError || {};
1184
1191
  global.wazoRefreshExpiration = global.wazoRefreshExpiration || {};
1185
1192
  global.wazoRefreshBackend = global.wazoRefreshBackend || {};
1186
1193
  global.wazoIsMobile = global.wazoIsMobile || {};
package/lib/api/dird.js CHANGED
@@ -400,13 +400,9 @@ class IssueReporter {
400
400
 
401
401
  setTimeout(() => {
402
402
  if (isArray) {
403
- payload = payload.map(message => {
404
- message._retry = retry + 1;
405
- return message;
406
- });
407
- } else {
408
- // $FlowFixMe
409
- payload._retry = retry + 1;
403
+ payload = payload.map(message => this._writeRetryCount(message, retry + 1));
404
+ } else if (payload && typeof payload === 'object') {
405
+ payload = this._writeRetryCount(payload, retry + 1);
410
406
  }
411
407
 
412
408
  this._sendDebugToGrafana(payload, retry + 1);
@@ -414,6 +410,15 @@ class IssueReporter {
414
410
  });
415
411
  }
416
412
 
413
+ _writeRetryCount(message , count ) {
414
+ if (message && typeof message === 'object') {
415
+ // $FlowFixMe
416
+ message._retry = count;
417
+ }
418
+
419
+ return message;
420
+ }
421
+
417
422
  _isLevelAbove(level1 , level2 ) {
418
423
  const index1 = LOG_LEVELS.indexOf(level1);
419
424
  const index2 = LOG_LEVELS.indexOf(level2);
@@ -337,13 +337,9 @@ class IssueReporter {
337
337
 
338
338
  setTimeout(() => {
339
339
  if (isArray) {
340
- payload = payload.map(message => {
341
- message._retry = retry + 1;
342
- return message;
343
- });
344
- } else {
345
- // $FlowFixMe
346
- payload._retry = retry + 1;
340
+ payload = payload.map(message => this._writeRetryCount(message, retry + 1));
341
+ } else if (payload && typeof payload === 'object') {
342
+ payload = this._writeRetryCount(payload, retry + 1);
347
343
  }
348
344
 
349
345
  this._sendDebugToGrafana(payload, retry + 1);
@@ -351,6 +347,15 @@ class IssueReporter {
351
347
  });
352
348
  }
353
349
 
350
+ _writeRetryCount(message , count ) {
351
+ if (message && typeof message === 'object') {
352
+ // $FlowFixMe
353
+ message._retry = count;
354
+ }
355
+
356
+ return message;
357
+ }
358
+
354
359
  _isLevelAbove(level1 , level2 ) {
355
360
  const index1 = LOG_LEVELS.indexOf(level1);
356
361
  const index2 = LOG_LEVELS.indexOf(level2);
package/lib/api-client.js CHANGED
@@ -402,13 +402,9 @@ class IssueReporter {
402
402
 
403
403
  setTimeout(() => {
404
404
  if (isArray) {
405
- payload = payload.map(message => {
406
- message._retry = retry + 1;
407
- return message;
408
- });
409
- } else {
410
- // $FlowFixMe
411
- payload._retry = retry + 1;
405
+ payload = payload.map(message => this._writeRetryCount(message, retry + 1));
406
+ } else if (payload && typeof payload === 'object') {
407
+ payload = this._writeRetryCount(payload, retry + 1);
412
408
  }
413
409
 
414
410
  this._sendDebugToGrafana(payload, retry + 1);
@@ -416,6 +412,15 @@ class IssueReporter {
416
412
  });
417
413
  }
418
414
 
415
+ _writeRetryCount(message , count ) {
416
+ if (message && typeof message === 'object') {
417
+ // $FlowFixMe
418
+ message._retry = count;
419
+ }
420
+
421
+ return message;
422
+ }
423
+
419
424
  _isLevelAbove(level1 , level2 ) {
420
425
  const index1 = LOG_LEVELS.indexOf(level1);
421
426
  const index2 = LOG_LEVELS.indexOf(level2);
@@ -2251,9 +2256,12 @@ var authMethods = (client , baseUrl ) => ({
2251
2256
  expiration: expiration || DETAULT_EXPIRATION,
2252
2257
  refresh_token: refreshToken,
2253
2258
  client_id: client.clientId,
2254
- tenant_id: tenantId,
2255
2259
  };
2256
2260
 
2261
+ if (tenantId) {
2262
+ body.tenant_id = tenantId;
2263
+ }
2264
+
2257
2265
  const headers = {
2258
2266
  'Content-Type': 'application/json',
2259
2267
  ...(isMobile ? { 'Wazo-Session-Type': 'mobile' } : {}),
@@ -3541,7 +3549,9 @@ global.wazoClients = global.wazoClients || {};
3541
3549
  global.wazoClientId = global.wazoClientId || {};
3542
3550
  global.wazoClientToken = global.wazoClientToken || {};
3543
3551
  global.wazoRefreshToken = global.wazoRefreshToken || {};
3552
+ global.wazoRefreshTenantId = global.wazoRefreshTenantId || {};
3544
3553
  global.wazoOnRefreshToken = global.wazoOnRefreshToken || {};
3554
+ global.wazoOnRefreshTokenError = global.wazoOnRefreshTokenError || {};
3545
3555
  global.wazoRefreshExpiration = global.wazoRefreshExpiration || {};
3546
3556
  global.wazoRefreshBackend = global.wazoRefreshBackend || {};
3547
3557
  global.wazoIsMobile = global.wazoIsMobile || {};
@@ -4587,6 +4597,7 @@ class ApiClient {
4587
4597
 
4588
4598
 
4589
4599
 
4600
+
4590
4601
 
4591
4602
 
4592
4603
 
@@ -4639,23 +4650,31 @@ class ApiClient {
4639
4650
  return null;
4640
4651
  }
4641
4652
 
4642
- const session = await this.auth.refreshToken(
4643
- this.refreshToken,
4644
- this.refreshBackend,
4645
- this.refreshExpiration,
4646
- this.isMobile,
4647
- this.refreshTenantId,
4648
- );
4649
-
4650
- logger.info('token refreshed', { token: session.token });
4653
+ try {
4654
+ const session = await this.auth.refreshToken(
4655
+ this.refreshToken,
4656
+ this.refreshBackend,
4657
+ this.refreshExpiration,
4658
+ this.isMobile,
4659
+ this.refreshTenantId,
4660
+ );
4661
+
4662
+ logger.info('token refreshed', { token: session.token });
4663
+
4664
+ if (this.onRefreshToken) {
4665
+ this.onRefreshToken(session.token, session);
4666
+ }
4651
4667
 
4652
- if (this.onRefreshToken) {
4653
- this.onRefreshToken(session.token, session);
4654
- }
4668
+ this.setToken(session.token);
4655
4669
 
4656
- this.setToken(session.token);
4670
+ return session.token;
4671
+ } catch (error) {
4672
+ logger.error('token refresh, error', error);
4657
4673
 
4658
- return session.token;
4674
+ if (this.onRefreshTokenError) {
4675
+ this.onRefreshTokenError(error);
4676
+ }
4677
+ }
4659
4678
  }
4660
4679
 
4661
4680
  setToken(token ) {
@@ -4678,6 +4697,10 @@ class ApiClient {
4678
4697
  this.onRefreshToken = onRefreshToken;
4679
4698
  }
4680
4699
 
4700
+ setOnRefreshTokenError(callback ) {
4701
+ this.onRefreshTokenError = callback;
4702
+ }
4703
+
4681
4704
  setRefreshExpiration(refreshExpiration ) {
4682
4705
  this.refreshExpiration = refreshExpiration;
4683
4706
  }