@wazo/sdk 0.37.41 → 0.38.0

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 (112) 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 +14 -7
  27. package/esm/index.js +233 -25
  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 +233 -25
  34. package/esm/simple/Configuration.js +233 -25
  35. package/esm/simple/Directory.js +54 -23
  36. package/esm/simple/Phone.js +233 -25
  37. package/esm/simple/Softphone.js +148 -0
  38. package/esm/simple/Websocket.js +13 -8
  39. package/esm/simple/index.js +233 -25
  40. package/esm/simple/room/LocalParticipant.js +233 -25
  41. package/esm/simple/room/Participant.js +233 -25
  42. package/esm/simple/room/RemoteParticipant.js +233 -25
  43. package/esm/simple/room/Room.js +233 -25
  44. package/esm/simple/room/SipRoom.js +233 -25
  45. package/esm/simple/room/Stream.js +233 -25
  46. package/esm/simple/room/__tests__/RemoteParticipant.test.js +233 -25
  47. package/esm/simple/utils.js +233 -25
  48. package/esm/utils/__tests__/api-requester.test.js +12 -7
  49. package/esm/utils/api-requester.js +12 -7
  50. package/esm/web-rtc-client.js +49 -24
  51. package/esm/websocket-client.js +13 -8
  52. package/lib/__tests__/api-client.test.js +45 -22
  53. package/lib/__tests__/web-rtc-client.test.js +49 -24
  54. package/lib/api/agentd.js +12 -7
  55. package/lib/api/amid.js +12 -7
  56. package/lib/api/application.js +12 -7
  57. package/lib/api/auth.js +16 -8
  58. package/lib/api/call-logd.js +12 -7
  59. package/lib/api/calld.js +12 -7
  60. package/lib/api/chatd.js +12 -7
  61. package/lib/api/confd.js +12 -7
  62. package/lib/api/ctid-ng.js +14 -7
  63. package/lib/api/dird.js +12 -7
  64. package/lib/api/webhookd.js +12 -7
  65. package/lib/api-client.js +45 -22
  66. package/lib/checker/Checker.js +50 -25
  67. package/lib/checker/checks/aor.js +45 -22
  68. package/lib/checker/checks/api.js +45 -22
  69. package/lib/checker/checks/index.js +50 -25
  70. package/lib/checker/checks/wazo-websocket.js +13 -8
  71. package/lib/checker/checks/webrtc-transport.js +49 -24
  72. package/lib/checker/checks/webrtc.js +49 -24
  73. package/lib/domain/AdHocAPIConference.js +54 -23
  74. package/lib/domain/Features.js +54 -23
  75. package/lib/domain/Phone/CTIPhone.js +54 -23
  76. package/lib/domain/Phone/WebRTCPhone.js +14 -7
  77. package/lib/index.js +233 -25
  78. package/lib/lib/WazoSessionDescriptionHandler.js +12 -7
  79. package/lib/service/CallApi.js +54 -23
  80. package/lib/service/IssueReporter.js +12 -7
  81. package/lib/service/__tests__/IssueReporter.test.js +18 -7
  82. package/lib/service/getApiClient.js +64 -23
  83. package/lib/simple/Auth.js +233 -25
  84. package/lib/simple/Configuration.js +233 -25
  85. package/lib/simple/Directory.js +54 -23
  86. package/lib/simple/Phone.js +233 -25
  87. package/lib/simple/Softphone.js +150 -0
  88. package/lib/simple/Websocket.js +13 -8
  89. package/lib/simple/index.js +233 -25
  90. package/lib/simple/room/LocalParticipant.js +233 -25
  91. package/lib/simple/room/Participant.js +233 -25
  92. package/lib/simple/room/RemoteParticipant.js +233 -25
  93. package/lib/simple/room/Room.js +233 -25
  94. package/lib/simple/room/SipRoom.js +233 -25
  95. package/lib/simple/room/Stream.js +233 -25
  96. package/lib/simple/room/__tests__/RemoteParticipant.test.js +233 -25
  97. package/lib/simple/utils.js +233 -25
  98. package/lib/utils/__tests__/api-requester.test.js +12 -7
  99. package/lib/utils/api-requester.js +12 -7
  100. package/lib/web-rtc-client.js +49 -24
  101. package/lib/websocket-client.js +13 -8
  102. package/package.json +1 -1
  103. package/src/api/auth.js +4 -1
  104. package/src/api-client.js +26 -13
  105. package/src/service/IssueReporter.js +12 -7
  106. package/src/service/__tests__/IssueReporter.test.js +6 -0
  107. package/src/service/getApiClient.js +19 -1
  108. package/src/simple/Auth.js +21 -0
  109. package/src/simple/Softphone.js +148 -0
  110. package/src/simple/index.js +2 -0
  111. package/src/web-rtc-client.js +4 -2
  112. package/src/websocket-client.js +1 -1
@@ -678,13 +678,9 @@ class IssueReporter {
678
678
 
679
679
  setTimeout(() => {
680
680
  if (isArray) {
681
- payload = payload.map(message => {
682
- message._retry = retry + 1;
683
- return message;
684
- });
685
- } else {
686
- // $FlowFixMe
687
- payload._retry = retry + 1;
681
+ payload = payload.map(message => this._writeRetryCount(message, retry + 1));
682
+ } else if (payload && typeof payload === 'object') {
683
+ payload = this._writeRetryCount(payload, retry + 1);
688
684
  }
689
685
 
690
686
  this._sendDebugToGrafana(payload, retry + 1);
@@ -692,6 +688,15 @@ class IssueReporter {
692
688
  });
693
689
  }
694
690
 
691
+ _writeRetryCount(message , count ) {
692
+ if (message && typeof message === 'object') {
693
+ // $FlowFixMe
694
+ message._retry = count;
695
+ }
696
+
697
+ return message;
698
+ }
699
+
695
700
  _isLevelAbove(level1 , level2 ) {
696
701
  const index1 = LOG_LEVELS.indexOf(level1);
697
702
  const index2 = LOG_LEVELS.indexOf(level2);
@@ -2793,9 +2798,12 @@ var authMethods = (client , baseUrl ) => ({
2793
2798
  expiration: expiration || DETAULT_EXPIRATION,
2794
2799
  refresh_token: refreshToken,
2795
2800
  client_id: client.clientId,
2796
- tenant_id: tenantId,
2797
2801
  };
2798
2802
 
2803
+ if (tenantId) {
2804
+ body.tenant_id = tenantId;
2805
+ }
2806
+
2799
2807
  const headers = {
2800
2808
  'Content-Type': 'application/json',
2801
2809
  ...(isMobile ? { 'Wazo-Session-Type': 'mobile' } : {}),
@@ -4083,7 +4091,9 @@ global.wazoClients = global.wazoClients || {};
4083
4091
  global.wazoClientId = global.wazoClientId || {};
4084
4092
  global.wazoClientToken = global.wazoClientToken || {};
4085
4093
  global.wazoRefreshToken = global.wazoRefreshToken || {};
4094
+ global.wazoRefreshTenantId = global.wazoRefreshTenantId || {};
4086
4095
  global.wazoOnRefreshToken = global.wazoOnRefreshToken || {};
4096
+ global.wazoOnRefreshTokenError = global.wazoOnRefreshTokenError || {};
4087
4097
  global.wazoRefreshExpiration = global.wazoRefreshExpiration || {};
4088
4098
  global.wazoRefreshBackend = global.wazoRefreshBackend || {};
4089
4099
  global.wazoIsMobile = global.wazoIsMobile || {};
@@ -5129,6 +5139,7 @@ class ApiClient {
5129
5139
 
5130
5140
 
5131
5141
 
5142
+
5132
5143
 
5133
5144
 
5134
5145
 
@@ -5181,23 +5192,31 @@ class ApiClient {
5181
5192
  return null;
5182
5193
  }
5183
5194
 
5184
- const session = await this.auth.refreshToken(
5185
- this.refreshToken,
5186
- this.refreshBackend,
5187
- this.refreshExpiration,
5188
- this.isMobile,
5189
- this.refreshTenantId,
5190
- );
5191
-
5192
- logger$1.info('token refreshed', { token: session.token });
5195
+ try {
5196
+ const session = await this.auth.refreshToken(
5197
+ this.refreshToken,
5198
+ this.refreshBackend,
5199
+ this.refreshExpiration,
5200
+ this.isMobile,
5201
+ this.refreshTenantId,
5202
+ );
5203
+
5204
+ logger$1.info('token refreshed', { token: session.token });
5205
+
5206
+ if (this.onRefreshToken) {
5207
+ this.onRefreshToken(session.token, session);
5208
+ }
5193
5209
 
5194
- if (this.onRefreshToken) {
5195
- this.onRefreshToken(session.token, session);
5196
- }
5210
+ this.setToken(session.token);
5197
5211
 
5198
- this.setToken(session.token);
5212
+ return session.token;
5213
+ } catch (error) {
5214
+ logger$1.error('token refresh, error', error);
5199
5215
 
5200
- return session.token;
5216
+ if (this.onRefreshTokenError) {
5217
+ this.onRefreshTokenError(error);
5218
+ }
5219
+ }
5201
5220
  }
5202
5221
 
5203
5222
  setToken(token ) {
@@ -5220,6 +5239,10 @@ class ApiClient {
5220
5239
  this.onRefreshToken = onRefreshToken;
5221
5240
  }
5222
5241
 
5242
+ setOnRefreshTokenError(callback ) {
5243
+ this.onRefreshTokenError = callback;
5244
+ }
5245
+
5223
5246
  setRefreshExpiration(refreshExpiration ) {
5224
5247
  this.refreshExpiration = refreshExpiration;
5225
5248
  }
@@ -6084,8 +6107,10 @@ class WebRTCClient extends Emitter {
6084
6107
  conference: isConference,
6085
6108
  };
6086
6109
 
6087
- // Avoid sdh to created a new stream
6088
- session.sessionDescriptionHandler.localMediaStreamConstraints = options.constraints;
6110
+ // Avoid sdh to create a new stream
6111
+ if (session.sessionDescriptionHandler) {
6112
+ session.sessionDescriptionHandler.localMediaStreamConstraints = options.constraints;
6113
+ }
6089
6114
 
6090
6115
  // Send re-INVITE
6091
6116
  return session.invite(options);
@@ -678,13 +678,9 @@ class IssueReporter {
678
678
 
679
679
  setTimeout(() => {
680
680
  if (isArray) {
681
- payload = payload.map(message => {
682
- message._retry = retry + 1;
683
- return message;
684
- });
685
- } else {
686
- // $FlowFixMe
687
- payload._retry = retry + 1;
681
+ payload = payload.map(message => this._writeRetryCount(message, retry + 1));
682
+ } else if (payload && typeof payload === 'object') {
683
+ payload = this._writeRetryCount(payload, retry + 1);
688
684
  }
689
685
 
690
686
  this._sendDebugToGrafana(payload, retry + 1);
@@ -692,6 +688,15 @@ class IssueReporter {
692
688
  });
693
689
  }
694
690
 
691
+ _writeRetryCount(message , count ) {
692
+ if (message && typeof message === 'object') {
693
+ // $FlowFixMe
694
+ message._retry = count;
695
+ }
696
+
697
+ return message;
698
+ }
699
+
695
700
  _isLevelAbove(level1 , level2 ) {
696
701
  const index1 = LOG_LEVELS.indexOf(level1);
697
702
  const index2 = LOG_LEVELS.indexOf(level2);
@@ -2793,9 +2798,12 @@ var authMethods = (client , baseUrl ) => ({
2793
2798
  expiration: expiration || DETAULT_EXPIRATION,
2794
2799
  refresh_token: refreshToken,
2795
2800
  client_id: client.clientId,
2796
- tenant_id: tenantId,
2797
2801
  };
2798
2802
 
2803
+ if (tenantId) {
2804
+ body.tenant_id = tenantId;
2805
+ }
2806
+
2799
2807
  const headers = {
2800
2808
  'Content-Type': 'application/json',
2801
2809
  ...(isMobile ? { 'Wazo-Session-Type': 'mobile' } : {}),
@@ -4083,7 +4091,9 @@ global.wazoClients = global.wazoClients || {};
4083
4091
  global.wazoClientId = global.wazoClientId || {};
4084
4092
  global.wazoClientToken = global.wazoClientToken || {};
4085
4093
  global.wazoRefreshToken = global.wazoRefreshToken || {};
4094
+ global.wazoRefreshTenantId = global.wazoRefreshTenantId || {};
4086
4095
  global.wazoOnRefreshToken = global.wazoOnRefreshToken || {};
4096
+ global.wazoOnRefreshTokenError = global.wazoOnRefreshTokenError || {};
4087
4097
  global.wazoRefreshExpiration = global.wazoRefreshExpiration || {};
4088
4098
  global.wazoRefreshBackend = global.wazoRefreshBackend || {};
4089
4099
  global.wazoIsMobile = global.wazoIsMobile || {};
@@ -5129,6 +5139,7 @@ class ApiClient {
5129
5139
 
5130
5140
 
5131
5141
 
5142
+
5132
5143
 
5133
5144
 
5134
5145
 
@@ -5181,23 +5192,31 @@ class ApiClient {
5181
5192
  return null;
5182
5193
  }
5183
5194
 
5184
- const session = await this.auth.refreshToken(
5185
- this.refreshToken,
5186
- this.refreshBackend,
5187
- this.refreshExpiration,
5188
- this.isMobile,
5189
- this.refreshTenantId,
5190
- );
5191
-
5192
- logger$1.info('token refreshed', { token: session.token });
5195
+ try {
5196
+ const session = await this.auth.refreshToken(
5197
+ this.refreshToken,
5198
+ this.refreshBackend,
5199
+ this.refreshExpiration,
5200
+ this.isMobile,
5201
+ this.refreshTenantId,
5202
+ );
5203
+
5204
+ logger$1.info('token refreshed', { token: session.token });
5205
+
5206
+ if (this.onRefreshToken) {
5207
+ this.onRefreshToken(session.token, session);
5208
+ }
5193
5209
 
5194
- if (this.onRefreshToken) {
5195
- this.onRefreshToken(session.token, session);
5196
- }
5210
+ this.setToken(session.token);
5197
5211
 
5198
- this.setToken(session.token);
5212
+ return session.token;
5213
+ } catch (error) {
5214
+ logger$1.error('token refresh, error', error);
5199
5215
 
5200
- return session.token;
5216
+ if (this.onRefreshTokenError) {
5217
+ this.onRefreshTokenError(error);
5218
+ }
5219
+ }
5201
5220
  }
5202
5221
 
5203
5222
  setToken(token ) {
@@ -5220,6 +5239,10 @@ class ApiClient {
5220
5239
  this.onRefreshToken = onRefreshToken;
5221
5240
  }
5222
5241
 
5242
+ setOnRefreshTokenError(callback ) {
5243
+ this.onRefreshTokenError = callback;
5244
+ }
5245
+
5223
5246
  setRefreshExpiration(refreshExpiration ) {
5224
5247
  this.refreshExpiration = refreshExpiration;
5225
5248
  }
@@ -6084,8 +6107,10 @@ class WebRTCClient extends Emitter {
6084
6107
  conference: isConference,
6085
6108
  };
6086
6109
 
6087
- // Avoid sdh to created a new stream
6088
- session.sessionDescriptionHandler.localMediaStreamConstraints = options.constraints;
6110
+ // Avoid sdh to create a new stream
6111
+ if (session.sessionDescriptionHandler) {
6112
+ session.sessionDescriptionHandler.localMediaStreamConstraints = options.constraints;
6113
+ }
6089
6114
 
6090
6115
  // Send re-INVITE
6091
6116
  return session.invite(options);
@@ -616,13 +616,9 @@ class IssueReporter {
616
616
 
617
617
  setTimeout(() => {
618
618
  if (isArray) {
619
- payload = payload.map(message => {
620
- message._retry = retry + 1;
621
- return message;
622
- });
623
- } else {
624
- // $FlowFixMe
625
- payload._retry = retry + 1;
619
+ payload = payload.map(message => this._writeRetryCount(message, retry + 1));
620
+ } else if (payload && typeof payload === 'object') {
621
+ payload = this._writeRetryCount(payload, retry + 1);
626
622
  }
627
623
 
628
624
  this._sendDebugToGrafana(payload, retry + 1);
@@ -630,6 +626,15 @@ class IssueReporter {
630
626
  });
631
627
  }
632
628
 
629
+ _writeRetryCount(message , count ) {
630
+ if (message && typeof message === 'object') {
631
+ // $FlowFixMe
632
+ message._retry = count;
633
+ }
634
+
635
+ return message;
636
+ }
637
+
633
638
  _isLevelAbove(level1 , level2 ) {
634
639
  const index1 = LOG_LEVELS.indexOf(level1);
635
640
  const index2 = LOG_LEVELS.indexOf(level2);
@@ -2454,9 +2459,12 @@ var authMethods = (client , baseUrl ) => ({
2454
2459
  expiration: expiration || DETAULT_EXPIRATION,
2455
2460
  refresh_token: refreshToken,
2456
2461
  client_id: client.clientId,
2457
- tenant_id: tenantId,
2458
2462
  };
2459
2463
 
2464
+ if (tenantId) {
2465
+ body.tenant_id = tenantId;
2466
+ }
2467
+
2460
2468
  const headers = {
2461
2469
  'Content-Type': 'application/json',
2462
2470
  ...(isMobile ? { 'Wazo-Session-Type': 'mobile' } : {}),
@@ -4566,6 +4574,7 @@ class ApiClient {
4566
4574
 
4567
4575
 
4568
4576
 
4577
+
4569
4578
 
4570
4579
 
4571
4580
 
@@ -4618,23 +4627,31 @@ class ApiClient {
4618
4627
  return null;
4619
4628
  }
4620
4629
 
4621
- const session = await this.auth.refreshToken(
4622
- this.refreshToken,
4623
- this.refreshBackend,
4624
- this.refreshExpiration,
4625
- this.isMobile,
4626
- this.refreshTenantId,
4627
- );
4628
-
4629
- logger.info('token refreshed', { token: session.token });
4630
+ try {
4631
+ const session = await this.auth.refreshToken(
4632
+ this.refreshToken,
4633
+ this.refreshBackend,
4634
+ this.refreshExpiration,
4635
+ this.isMobile,
4636
+ this.refreshTenantId,
4637
+ );
4638
+
4639
+ logger.info('token refreshed', { token: session.token });
4640
+
4641
+ if (this.onRefreshToken) {
4642
+ this.onRefreshToken(session.token, session);
4643
+ }
4630
4644
 
4631
- if (this.onRefreshToken) {
4632
- this.onRefreshToken(session.token, session);
4633
- }
4645
+ this.setToken(session.token);
4634
4646
 
4635
- this.setToken(session.token);
4647
+ return session.token;
4648
+ } catch (error) {
4649
+ logger.error('token refresh, error', error);
4636
4650
 
4637
- return session.token;
4651
+ if (this.onRefreshTokenError) {
4652
+ this.onRefreshTokenError(error);
4653
+ }
4654
+ }
4638
4655
  }
4639
4656
 
4640
4657
  setToken(token ) {
@@ -4657,6 +4674,10 @@ class ApiClient {
4657
4674
  this.onRefreshToken = onRefreshToken;
4658
4675
  }
4659
4676
 
4677
+ setOnRefreshTokenError(callback ) {
4678
+ this.onRefreshTokenError = callback;
4679
+ }
4680
+
4660
4681
  setRefreshExpiration(refreshExpiration ) {
4661
4682
  this.refreshExpiration = refreshExpiration;
4662
4683
  }
@@ -4692,7 +4713,9 @@ global.wazoClients = global.wazoClients || {};
4692
4713
  global.wazoClientId = global.wazoClientId || {};
4693
4714
  global.wazoClientToken = global.wazoClientToken || {};
4694
4715
  global.wazoRefreshToken = global.wazoRefreshToken || {};
4716
+ global.wazoRefreshTenantId = global.wazoRefreshTenantId || {};
4695
4717
  global.wazoOnRefreshToken = global.wazoOnRefreshToken || {};
4718
+ global.wazoOnRefreshTokenError = global.wazoOnRefreshTokenError || {};
4696
4719
  global.wazoRefreshExpiration = global.wazoRefreshExpiration || {};
4697
4720
  global.wazoRefreshBackend = global.wazoRefreshBackend || {};
4698
4721
  global.wazoIsMobile = global.wazoIsMobile || {};
@@ -4708,12 +4731,20 @@ const fillClient = (apiClient ) => {
4708
4731
 
4709
4732
  apiClient.setRefreshToken(global.wazoRefreshToken[server] || global.wazoRefreshToken[null] || apiClient.refreshToken);
4710
4733
 
4734
+ apiClient.setRefreshTenantId(
4735
+ global.wazoRefreshTenantId[server] || global.wazoRefreshTenantId[null] || apiClient.refreshTenantId,
4736
+ );
4737
+
4711
4738
  apiClient.setFetchOptions(global.wazoFetchOptions[server] || global.wazoFetchOptions[null] || apiClient.fetchOptions);
4712
4739
 
4713
4740
  apiClient.setOnRefreshToken(
4714
4741
  global.wazoOnRefreshToken[server] || global.wazoOnRefreshToken[null] || apiClient.onRefreshToken,
4715
4742
  );
4716
4743
 
4744
+ apiClient.setOnRefreshTokenError(
4745
+ global.wazoOnRefreshTokenError[server] || global.wazoOnRefreshTokenError[null] || apiClient.onRefreshTokenError,
4746
+ );
4747
+
4717
4748
  apiClient.setRefreshExpiration(
4718
4749
  global.wazoRefreshExpiration[server] || global.wazoRefreshExpiration[null] || apiClient.refreshExpiration,
4719
4750
  );
@@ -4727,7 +4758,7 @@ const fillClient = (apiClient ) => {
4727
4758
  return apiClient;
4728
4759
  };
4729
4760
 
4730
- var getApiClient = (forServer ) => {
4761
+ var getApiClient = (forServer = null) => {
4731
4762
  const server = forServer || global.wazoCurrentServer || '';
4732
4763
  if (server in global.wazoClients) {
4733
4764
  return fillClient(global.wazoClients[server]);
@@ -396,13 +396,9 @@ class IssueReporter {
396
396
 
397
397
  setTimeout(() => {
398
398
  if (isArray) {
399
- payload = payload.map(message => {
400
- message._retry = retry + 1;
401
- return message;
402
- });
403
- } else {
404
- // $FlowFixMe
405
- payload._retry = retry + 1;
399
+ payload = payload.map(message => this._writeRetryCount(message, retry + 1));
400
+ } else if (payload && typeof payload === 'object') {
401
+ payload = this._writeRetryCount(payload, retry + 1);
406
402
  }
407
403
 
408
404
  this._sendDebugToGrafana(payload, retry + 1);
@@ -410,6 +406,15 @@ class IssueReporter {
410
406
  });
411
407
  }
412
408
 
409
+ _writeRetryCount(message , count ) {
410
+ if (message && typeof message === 'object') {
411
+ // $FlowFixMe
412
+ message._retry = count;
413
+ }
414
+
415
+ return message;
416
+ }
417
+
413
418
  _isLevelAbove(level1 , level2 ) {
414
419
  const index1 = LOG_LEVELS.indexOf(level1);
415
420
  const index2 = LOG_LEVELS.indexOf(level2);
@@ -2245,9 +2250,12 @@ var authMethods = (client , baseUrl ) => ({
2245
2250
  expiration: expiration || DETAULT_EXPIRATION,
2246
2251
  refresh_token: refreshToken,
2247
2252
  client_id: client.clientId,
2248
- tenant_id: tenantId,
2249
2253
  };
2250
2254
 
2255
+ if (tenantId) {
2256
+ body.tenant_id = tenantId;
2257
+ }
2258
+
2251
2259
  const headers = {
2252
2260
  'Content-Type': 'application/json',
2253
2261
  ...(isMobile ? { 'Wazo-Session-Type': 'mobile' } : {}),
@@ -4566,6 +4574,7 @@ class ApiClient {
4566
4574
 
4567
4575
 
4568
4576
 
4577
+
4569
4578
 
4570
4579
 
4571
4580
 
@@ -4618,23 +4627,31 @@ class ApiClient {
4618
4627
  return null;
4619
4628
  }
4620
4629
 
4621
- const session = await this.auth.refreshToken(
4622
- this.refreshToken,
4623
- this.refreshBackend,
4624
- this.refreshExpiration,
4625
- this.isMobile,
4626
- this.refreshTenantId,
4627
- );
4628
-
4629
- logger.info('token refreshed', { token: session.token });
4630
+ try {
4631
+ const session = await this.auth.refreshToken(
4632
+ this.refreshToken,
4633
+ this.refreshBackend,
4634
+ this.refreshExpiration,
4635
+ this.isMobile,
4636
+ this.refreshTenantId,
4637
+ );
4638
+
4639
+ logger.info('token refreshed', { token: session.token });
4640
+
4641
+ if (this.onRefreshToken) {
4642
+ this.onRefreshToken(session.token, session);
4643
+ }
4630
4644
 
4631
- if (this.onRefreshToken) {
4632
- this.onRefreshToken(session.token, session);
4633
- }
4645
+ this.setToken(session.token);
4634
4646
 
4635
- this.setToken(session.token);
4647
+ return session.token;
4648
+ } catch (error) {
4649
+ logger.error('token refresh, error', error);
4636
4650
 
4637
- return session.token;
4651
+ if (this.onRefreshTokenError) {
4652
+ this.onRefreshTokenError(error);
4653
+ }
4654
+ }
4638
4655
  }
4639
4656
 
4640
4657
  setToken(token ) {
@@ -4657,6 +4674,10 @@ class ApiClient {
4657
4674
  this.onRefreshToken = onRefreshToken;
4658
4675
  }
4659
4676
 
4677
+ setOnRefreshTokenError(callback ) {
4678
+ this.onRefreshTokenError = callback;
4679
+ }
4680
+
4660
4681
  setRefreshExpiration(refreshExpiration ) {
4661
4682
  this.refreshExpiration = refreshExpiration;
4662
4683
  }
@@ -4692,7 +4713,9 @@ global.wazoClients = global.wazoClients || {};
4692
4713
  global.wazoClientId = global.wazoClientId || {};
4693
4714
  global.wazoClientToken = global.wazoClientToken || {};
4694
4715
  global.wazoRefreshToken = global.wazoRefreshToken || {};
4716
+ global.wazoRefreshTenantId = global.wazoRefreshTenantId || {};
4695
4717
  global.wazoOnRefreshToken = global.wazoOnRefreshToken || {};
4718
+ global.wazoOnRefreshTokenError = global.wazoOnRefreshTokenError || {};
4696
4719
  global.wazoRefreshExpiration = global.wazoRefreshExpiration || {};
4697
4720
  global.wazoRefreshBackend = global.wazoRefreshBackend || {};
4698
4721
  global.wazoIsMobile = global.wazoIsMobile || {};
@@ -4708,12 +4731,20 @@ const fillClient = (apiClient ) => {
4708
4731
 
4709
4732
  apiClient.setRefreshToken(global.wazoRefreshToken[server] || global.wazoRefreshToken[null] || apiClient.refreshToken);
4710
4733
 
4734
+ apiClient.setRefreshTenantId(
4735
+ global.wazoRefreshTenantId[server] || global.wazoRefreshTenantId[null] || apiClient.refreshTenantId,
4736
+ );
4737
+
4711
4738
  apiClient.setFetchOptions(global.wazoFetchOptions[server] || global.wazoFetchOptions[null] || apiClient.fetchOptions);
4712
4739
 
4713
4740
  apiClient.setOnRefreshToken(
4714
4741
  global.wazoOnRefreshToken[server] || global.wazoOnRefreshToken[null] || apiClient.onRefreshToken,
4715
4742
  );
4716
4743
 
4744
+ apiClient.setOnRefreshTokenError(
4745
+ global.wazoOnRefreshTokenError[server] || global.wazoOnRefreshTokenError[null] || apiClient.onRefreshTokenError,
4746
+ );
4747
+
4717
4748
  apiClient.setRefreshExpiration(
4718
4749
  global.wazoRefreshExpiration[server] || global.wazoRefreshExpiration[null] || apiClient.refreshExpiration,
4719
4750
  );
@@ -4727,7 +4758,7 @@ const fillClient = (apiClient ) => {
4727
4758
  return apiClient;
4728
4759
  };
4729
4760
 
4730
- var getApiClient = (forServer ) => {
4761
+ var getApiClient = (forServer = null) => {
4731
4762
  const server = forServer || global.wazoCurrentServer || '';
4732
4763
  if (server in global.wazoClients) {
4733
4764
  return fillClient(global.wazoClients[server]);