@wazo/sdk 0.37.39 → 0.37.42

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 (73) hide show
  1. package/README.md +2 -1
  2. package/dist/wazo-sdk.js +2 -2
  3. package/esm/__tests__/api-client.test.js +33 -15
  4. package/esm/__tests__/web-rtc-client.test.js +39 -18
  5. package/esm/api/auth.js +4 -1
  6. package/esm/api/ctid-ng.js +2 -0
  7. package/esm/api-client.js +33 -15
  8. package/esm/checker/Checker.js +39 -18
  9. package/esm/checker/checks/aor.js +33 -15
  10. package/esm/checker/checks/api.js +33 -15
  11. package/esm/checker/checks/index.js +39 -18
  12. package/esm/checker/checks/webrtc-transport.js +39 -18
  13. package/esm/checker/checks/webrtc.js +39 -18
  14. package/esm/domain/AdHocAPIConference.js +42 -16
  15. package/esm/domain/Features.js +42 -16
  16. package/esm/domain/Phone/CTIPhone.js +42 -16
  17. package/esm/domain/Phone/WebRTCPhone.js +5 -3
  18. package/esm/index.js +77 -21
  19. package/esm/service/CallApi.js +42 -16
  20. package/esm/service/getApiClient.js +51 -17
  21. package/esm/simple/Auth.js +77 -21
  22. package/esm/simple/Configuration.js +77 -21
  23. package/esm/simple/Directory.js +42 -16
  24. package/esm/simple/Phone.js +77 -21
  25. package/esm/simple/index.js +77 -21
  26. package/esm/simple/room/LocalParticipant.js +77 -21
  27. package/esm/simple/room/Participant.js +77 -21
  28. package/esm/simple/room/RemoteParticipant.js +77 -21
  29. package/esm/simple/room/Room.js +77 -21
  30. package/esm/simple/room/SipRoom.js +77 -21
  31. package/esm/simple/room/Stream.js +77 -21
  32. package/esm/simple/room/__tests__/RemoteParticipant.test.js +77 -21
  33. package/esm/simple/utils.js +77 -21
  34. package/esm/web-rtc-client.js +39 -18
  35. package/lib/__tests__/api-client.test.js +33 -15
  36. package/lib/__tests__/web-rtc-client.test.js +39 -18
  37. package/lib/api/auth.js +4 -1
  38. package/lib/api/ctid-ng.js +2 -0
  39. package/lib/api-client.js +33 -15
  40. package/lib/checker/Checker.js +39 -18
  41. package/lib/checker/checks/aor.js +33 -15
  42. package/lib/checker/checks/api.js +33 -15
  43. package/lib/checker/checks/index.js +39 -18
  44. package/lib/checker/checks/webrtc-transport.js +39 -18
  45. package/lib/checker/checks/webrtc.js +39 -18
  46. package/lib/domain/AdHocAPIConference.js +42 -16
  47. package/lib/domain/Features.js +42 -16
  48. package/lib/domain/Phone/CTIPhone.js +42 -16
  49. package/lib/domain/Phone/WebRTCPhone.js +5 -3
  50. package/lib/index.js +77 -21
  51. package/lib/service/CallApi.js +42 -16
  52. package/lib/service/getApiClient.js +52 -16
  53. package/lib/simple/Auth.js +77 -21
  54. package/lib/simple/Configuration.js +77 -21
  55. package/lib/simple/Directory.js +42 -16
  56. package/lib/simple/Phone.js +77 -21
  57. package/lib/simple/index.js +77 -21
  58. package/lib/simple/room/LocalParticipant.js +77 -21
  59. package/lib/simple/room/Participant.js +77 -21
  60. package/lib/simple/room/RemoteParticipant.js +77 -21
  61. package/lib/simple/room/Room.js +77 -21
  62. package/lib/simple/room/SipRoom.js +77 -21
  63. package/lib/simple/room/Stream.js +77 -21
  64. package/lib/simple/room/__tests__/RemoteParticipant.test.js +77 -21
  65. package/lib/simple/utils.js +77 -21
  66. package/lib/web-rtc-client.js +39 -18
  67. package/package.json +1 -1
  68. package/src/api/auth.js +4 -1
  69. package/src/api-client.js +26 -13
  70. package/src/domain/Phone/WebRTCPhone.js +3 -3
  71. package/src/service/getApiClient.js +19 -1
  72. package/src/simple/Auth.js +21 -0
  73. package/src/web-rtc-client.js +7 -4
@@ -2245,9 +2245,12 @@ var authMethods = (client , baseUrl ) => ({
2245
2245
  expiration: expiration || DETAULT_EXPIRATION,
2246
2246
  refresh_token: refreshToken,
2247
2247
  client_id: client.clientId,
2248
- tenant_id: tenantId,
2249
2248
  };
2250
2249
 
2250
+ if (tenantId) {
2251
+ body.tenant_id = tenantId;
2252
+ }
2253
+
2251
2254
  const headers = {
2252
2255
  'Content-Type': 'application/json',
2253
2256
  ...(isMobile ? { 'Wazo-Session-Type': 'mobile' } : {}),
@@ -3535,7 +3538,9 @@ global.wazoClients = global.wazoClients || {};
3535
3538
  global.wazoClientId = global.wazoClientId || {};
3536
3539
  global.wazoClientToken = global.wazoClientToken || {};
3537
3540
  global.wazoRefreshToken = global.wazoRefreshToken || {};
3541
+ global.wazoRefreshTenantId = global.wazoRefreshTenantId || {};
3538
3542
  global.wazoOnRefreshToken = global.wazoOnRefreshToken || {};
3543
+ global.wazoOnRefreshTokenError = global.wazoOnRefreshTokenError || {};
3539
3544
  global.wazoRefreshExpiration = global.wazoRefreshExpiration || {};
3540
3545
  global.wazoRefreshBackend = global.wazoRefreshBackend || {};
3541
3546
  global.wazoIsMobile = global.wazoIsMobile || {};
@@ -4581,6 +4586,7 @@ class ApiClient {
4581
4586
 
4582
4587
 
4583
4588
 
4589
+
4584
4590
 
4585
4591
 
4586
4592
 
@@ -4633,23 +4639,31 @@ class ApiClient {
4633
4639
  return null;
4634
4640
  }
4635
4641
 
4636
- const session = await this.auth.refreshToken(
4637
- this.refreshToken,
4638
- this.refreshBackend,
4639
- this.refreshExpiration,
4640
- this.isMobile,
4641
- this.refreshTenantId,
4642
- );
4643
-
4644
- logger.info('token refreshed', { token: session.token });
4642
+ try {
4643
+ const session = await this.auth.refreshToken(
4644
+ this.refreshToken,
4645
+ this.refreshBackend,
4646
+ this.refreshExpiration,
4647
+ this.isMobile,
4648
+ this.refreshTenantId,
4649
+ );
4650
+
4651
+ logger.info('token refreshed', { token: session.token });
4652
+
4653
+ if (this.onRefreshToken) {
4654
+ this.onRefreshToken(session.token, session);
4655
+ }
4645
4656
 
4646
- if (this.onRefreshToken) {
4647
- this.onRefreshToken(session.token, session);
4648
- }
4657
+ this.setToken(session.token);
4649
4658
 
4650
- this.setToken(session.token);
4659
+ return session.token;
4660
+ } catch (error) {
4661
+ logger.error('token refresh, error', error);
4651
4662
 
4652
- return session.token;
4663
+ if (this.onRefreshTokenError) {
4664
+ this.onRefreshTokenError(error);
4665
+ }
4666
+ }
4653
4667
  }
4654
4668
 
4655
4669
  setToken(token ) {
@@ -4672,6 +4686,10 @@ class ApiClient {
4672
4686
  this.onRefreshToken = onRefreshToken;
4673
4687
  }
4674
4688
 
4689
+ setOnRefreshTokenError(callback ) {
4690
+ this.onRefreshTokenError = callback;
4691
+ }
4692
+
4675
4693
  setRefreshExpiration(refreshExpiration ) {
4676
4694
  this.refreshExpiration = refreshExpiration;
4677
4695
  }
@@ -2793,9 +2793,12 @@ var authMethods = (client , baseUrl ) => ({
2793
2793
  expiration: expiration || DETAULT_EXPIRATION,
2794
2794
  refresh_token: refreshToken,
2795
2795
  client_id: client.clientId,
2796
- tenant_id: tenantId,
2797
2796
  };
2798
2797
 
2798
+ if (tenantId) {
2799
+ body.tenant_id = tenantId;
2800
+ }
2801
+
2799
2802
  const headers = {
2800
2803
  'Content-Type': 'application/json',
2801
2804
  ...(isMobile ? { 'Wazo-Session-Type': 'mobile' } : {}),
@@ -4083,7 +4086,9 @@ global.wazoClients = global.wazoClients || {};
4083
4086
  global.wazoClientId = global.wazoClientId || {};
4084
4087
  global.wazoClientToken = global.wazoClientToken || {};
4085
4088
  global.wazoRefreshToken = global.wazoRefreshToken || {};
4089
+ global.wazoRefreshTenantId = global.wazoRefreshTenantId || {};
4086
4090
  global.wazoOnRefreshToken = global.wazoOnRefreshToken || {};
4091
+ global.wazoOnRefreshTokenError = global.wazoOnRefreshTokenError || {};
4087
4092
  global.wazoRefreshExpiration = global.wazoRefreshExpiration || {};
4088
4093
  global.wazoRefreshBackend = global.wazoRefreshBackend || {};
4089
4094
  global.wazoIsMobile = global.wazoIsMobile || {};
@@ -5129,6 +5134,7 @@ class ApiClient {
5129
5134
 
5130
5135
 
5131
5136
 
5137
+
5132
5138
 
5133
5139
 
5134
5140
 
@@ -5181,23 +5187,31 @@ class ApiClient {
5181
5187
  return null;
5182
5188
  }
5183
5189
 
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 });
5190
+ try {
5191
+ const session = await this.auth.refreshToken(
5192
+ this.refreshToken,
5193
+ this.refreshBackend,
5194
+ this.refreshExpiration,
5195
+ this.isMobile,
5196
+ this.refreshTenantId,
5197
+ );
5198
+
5199
+ logger$1.info('token refreshed', { token: session.token });
5200
+
5201
+ if (this.onRefreshToken) {
5202
+ this.onRefreshToken(session.token, session);
5203
+ }
5193
5204
 
5194
- if (this.onRefreshToken) {
5195
- this.onRefreshToken(session.token, session);
5196
- }
5205
+ this.setToken(session.token);
5197
5206
 
5198
- this.setToken(session.token);
5207
+ return session.token;
5208
+ } catch (error) {
5209
+ logger$1.error('token refresh, error', error);
5199
5210
 
5200
- return session.token;
5211
+ if (this.onRefreshTokenError) {
5212
+ this.onRefreshTokenError(error);
5213
+ }
5214
+ }
5201
5215
  }
5202
5216
 
5203
5217
  setToken(token ) {
@@ -5220,6 +5234,10 @@ class ApiClient {
5220
5234
  this.onRefreshToken = onRefreshToken;
5221
5235
  }
5222
5236
 
5237
+ setOnRefreshTokenError(callback ) {
5238
+ this.onRefreshTokenError = callback;
5239
+ }
5240
+
5223
5241
  setRefreshExpiration(refreshExpiration ) {
5224
5242
  this.refreshExpiration = refreshExpiration;
5225
5243
  }
@@ -7397,11 +7415,14 @@ class WebRTCClient extends Emitter {
7397
7415
  }
7398
7416
 
7399
7417
  async _disconnectTransport(force = false) {
7400
- if (force) {
7418
+ if (force && this.userAgent && this.userAgent.transport) {
7401
7419
  // Bypass sip.js state machine that prevent to close WS with the state `Connecting`
7402
7420
  this.userAgent.transport.disconnectResolve = () => {};
7403
- // eslint-disable-next-line
7404
- this.userAgent.transport._ws.close(1000);
7421
+
7422
+ if (this.userAgent.transport._ws) {
7423
+ this.userAgent.transport._ws.close(1000);
7424
+ }
7425
+
7405
7426
  return;
7406
7427
  }
7407
7428
 
package/esm/api/auth.js CHANGED
@@ -1003,9 +1003,12 @@ var auth = (client , baseUrl ) => ({
1003
1003
  expiration: expiration || DETAULT_EXPIRATION,
1004
1004
  refresh_token: refreshToken,
1005
1005
  client_id: client.clientId,
1006
- tenant_id: tenantId,
1007
1006
  };
1008
1007
 
1008
+ if (tenantId) {
1009
+ body.tenant_id = tenantId;
1010
+ }
1011
+
1009
1012
  const headers = {
1010
1013
  'Content-Type': 'application/json',
1011
1014
  ...(isMobile ? { 'Wazo-Session-Type': 'mobile' } : {}),
@@ -1174,7 +1174,9 @@ global.wazoClients = global.wazoClients || {};
1174
1174
  global.wazoClientId = global.wazoClientId || {};
1175
1175
  global.wazoClientToken = global.wazoClientToken || {};
1176
1176
  global.wazoRefreshToken = global.wazoRefreshToken || {};
1177
+ global.wazoRefreshTenantId = global.wazoRefreshTenantId || {};
1177
1178
  global.wazoOnRefreshToken = global.wazoOnRefreshToken || {};
1179
+ global.wazoOnRefreshTokenError = global.wazoOnRefreshTokenError || {};
1178
1180
  global.wazoRefreshExpiration = global.wazoRefreshExpiration || {};
1179
1181
  global.wazoRefreshBackend = global.wazoRefreshBackend || {};
1180
1182
  global.wazoIsMobile = global.wazoIsMobile || {};
package/esm/api-client.js CHANGED
@@ -2245,9 +2245,12 @@ var authMethods = (client , baseUrl ) => ({
2245
2245
  expiration: expiration || DETAULT_EXPIRATION,
2246
2246
  refresh_token: refreshToken,
2247
2247
  client_id: client.clientId,
2248
- tenant_id: tenantId,
2249
2248
  };
2250
2249
 
2250
+ if (tenantId) {
2251
+ body.tenant_id = tenantId;
2252
+ }
2253
+
2251
2254
  const headers = {
2252
2255
  'Content-Type': 'application/json',
2253
2256
  ...(isMobile ? { 'Wazo-Session-Type': 'mobile' } : {}),
@@ -3535,7 +3538,9 @@ global.wazoClients = global.wazoClients || {};
3535
3538
  global.wazoClientId = global.wazoClientId || {};
3536
3539
  global.wazoClientToken = global.wazoClientToken || {};
3537
3540
  global.wazoRefreshToken = global.wazoRefreshToken || {};
3541
+ global.wazoRefreshTenantId = global.wazoRefreshTenantId || {};
3538
3542
  global.wazoOnRefreshToken = global.wazoOnRefreshToken || {};
3543
+ global.wazoOnRefreshTokenError = global.wazoOnRefreshTokenError || {};
3539
3544
  global.wazoRefreshExpiration = global.wazoRefreshExpiration || {};
3540
3545
  global.wazoRefreshBackend = global.wazoRefreshBackend || {};
3541
3546
  global.wazoIsMobile = global.wazoIsMobile || {};
@@ -4581,6 +4586,7 @@ class ApiClient {
4581
4586
 
4582
4587
 
4583
4588
 
4589
+
4584
4590
 
4585
4591
 
4586
4592
 
@@ -4633,23 +4639,31 @@ class ApiClient {
4633
4639
  return null;
4634
4640
  }
4635
4641
 
4636
- const session = await this.auth.refreshToken(
4637
- this.refreshToken,
4638
- this.refreshBackend,
4639
- this.refreshExpiration,
4640
- this.isMobile,
4641
- this.refreshTenantId,
4642
- );
4643
-
4644
- logger.info('token refreshed', { token: session.token });
4642
+ try {
4643
+ const session = await this.auth.refreshToken(
4644
+ this.refreshToken,
4645
+ this.refreshBackend,
4646
+ this.refreshExpiration,
4647
+ this.isMobile,
4648
+ this.refreshTenantId,
4649
+ );
4650
+
4651
+ logger.info('token refreshed', { token: session.token });
4652
+
4653
+ if (this.onRefreshToken) {
4654
+ this.onRefreshToken(session.token, session);
4655
+ }
4645
4656
 
4646
- if (this.onRefreshToken) {
4647
- this.onRefreshToken(session.token, session);
4648
- }
4657
+ this.setToken(session.token);
4649
4658
 
4650
- this.setToken(session.token);
4659
+ return session.token;
4660
+ } catch (error) {
4661
+ logger.error('token refresh, error', error);
4651
4662
 
4652
- return session.token;
4663
+ if (this.onRefreshTokenError) {
4664
+ this.onRefreshTokenError(error);
4665
+ }
4666
+ }
4653
4667
  }
4654
4668
 
4655
4669
  setToken(token ) {
@@ -4672,6 +4686,10 @@ class ApiClient {
4672
4686
  this.onRefreshToken = onRefreshToken;
4673
4687
  }
4674
4688
 
4689
+ setOnRefreshTokenError(callback ) {
4690
+ this.onRefreshTokenError = callback;
4691
+ }
4692
+
4675
4693
  setRefreshExpiration(refreshExpiration ) {
4676
4694
  this.refreshExpiration = refreshExpiration;
4677
4695
  }
@@ -2263,9 +2263,12 @@ var authMethods = (client , baseUrl ) => ({
2263
2263
  expiration: expiration || DETAULT_EXPIRATION,
2264
2264
  refresh_token: refreshToken,
2265
2265
  client_id: client.clientId,
2266
- tenant_id: tenantId,
2267
2266
  };
2268
2267
 
2268
+ if (tenantId) {
2269
+ body.tenant_id = tenantId;
2270
+ }
2271
+
2269
2272
  const headers = {
2270
2273
  'Content-Type': 'application/json',
2271
2274
  ...(isMobile ? { 'Wazo-Session-Type': 'mobile' } : {}),
@@ -3579,7 +3582,9 @@ global.wazoClients = global.wazoClients || {};
3579
3582
  global.wazoClientId = global.wazoClientId || {};
3580
3583
  global.wazoClientToken = global.wazoClientToken || {};
3581
3584
  global.wazoRefreshToken = global.wazoRefreshToken || {};
3585
+ global.wazoRefreshTenantId = global.wazoRefreshTenantId || {};
3582
3586
  global.wazoOnRefreshToken = global.wazoOnRefreshToken || {};
3587
+ global.wazoOnRefreshTokenError = global.wazoOnRefreshTokenError || {};
3583
3588
  global.wazoRefreshExpiration = global.wazoRefreshExpiration || {};
3584
3589
  global.wazoRefreshBackend = global.wazoRefreshBackend || {};
3585
3590
  global.wazoIsMobile = global.wazoIsMobile || {};
@@ -4625,6 +4630,7 @@ class ApiClient {
4625
4630
 
4626
4631
 
4627
4632
 
4633
+
4628
4634
 
4629
4635
 
4630
4636
 
@@ -4677,23 +4683,31 @@ class ApiClient {
4677
4683
  return null;
4678
4684
  }
4679
4685
 
4680
- const session = await this.auth.refreshToken(
4681
- this.refreshToken,
4682
- this.refreshBackend,
4683
- this.refreshExpiration,
4684
- this.isMobile,
4685
- this.refreshTenantId,
4686
- );
4687
-
4688
- logger$3.info('token refreshed', { token: session.token });
4686
+ try {
4687
+ const session = await this.auth.refreshToken(
4688
+ this.refreshToken,
4689
+ this.refreshBackend,
4690
+ this.refreshExpiration,
4691
+ this.isMobile,
4692
+ this.refreshTenantId,
4693
+ );
4694
+
4695
+ logger$3.info('token refreshed', { token: session.token });
4696
+
4697
+ if (this.onRefreshToken) {
4698
+ this.onRefreshToken(session.token, session);
4699
+ }
4689
4700
 
4690
- if (this.onRefreshToken) {
4691
- this.onRefreshToken(session.token, session);
4692
- }
4701
+ this.setToken(session.token);
4693
4702
 
4694
- this.setToken(session.token);
4703
+ return session.token;
4704
+ } catch (error) {
4705
+ logger$3.error('token refresh, error', error);
4695
4706
 
4696
- return session.token;
4707
+ if (this.onRefreshTokenError) {
4708
+ this.onRefreshTokenError(error);
4709
+ }
4710
+ }
4697
4711
  }
4698
4712
 
4699
4713
  setToken(token ) {
@@ -4716,6 +4730,10 @@ class ApiClient {
4716
4730
  this.onRefreshToken = onRefreshToken;
4717
4731
  }
4718
4732
 
4733
+ setOnRefreshTokenError(callback ) {
4734
+ this.onRefreshTokenError = callback;
4735
+ }
4736
+
4719
4737
  setRefreshExpiration(refreshExpiration ) {
4720
4738
  this.refreshExpiration = refreshExpiration;
4721
4739
  }
@@ -7982,11 +8000,14 @@ class WebRTCClient extends Emitter {
7982
8000
  }
7983
8001
 
7984
8002
  async _disconnectTransport(force = false) {
7985
- if (force) {
8003
+ if (force && this.userAgent && this.userAgent.transport) {
7986
8004
  // Bypass sip.js state machine that prevent to close WS with the state `Connecting`
7987
8005
  this.userAgent.transport.disconnectResolve = () => {};
7988
- // eslint-disable-next-line
7989
- this.userAgent.transport._ws.close(1000);
8006
+
8007
+ if (this.userAgent.transport._ws) {
8008
+ this.userAgent.transport._ws.close(1000);
8009
+ }
8010
+
7990
8011
  return;
7991
8012
  }
7992
8013
 
@@ -2245,9 +2245,12 @@ var authMethods = (client , baseUrl ) => ({
2245
2245
  expiration: expiration || DETAULT_EXPIRATION,
2246
2246
  refresh_token: refreshToken,
2247
2247
  client_id: client.clientId,
2248
- tenant_id: tenantId,
2249
2248
  };
2250
2249
 
2250
+ if (tenantId) {
2251
+ body.tenant_id = tenantId;
2252
+ }
2253
+
2251
2254
  const headers = {
2252
2255
  'Content-Type': 'application/json',
2253
2256
  ...(isMobile ? { 'Wazo-Session-Type': 'mobile' } : {}),
@@ -3535,7 +3538,9 @@ global.wazoClients = global.wazoClients || {};
3535
3538
  global.wazoClientId = global.wazoClientId || {};
3536
3539
  global.wazoClientToken = global.wazoClientToken || {};
3537
3540
  global.wazoRefreshToken = global.wazoRefreshToken || {};
3541
+ global.wazoRefreshTenantId = global.wazoRefreshTenantId || {};
3538
3542
  global.wazoOnRefreshToken = global.wazoOnRefreshToken || {};
3543
+ global.wazoOnRefreshTokenError = global.wazoOnRefreshTokenError || {};
3539
3544
  global.wazoRefreshExpiration = global.wazoRefreshExpiration || {};
3540
3545
  global.wazoRefreshBackend = global.wazoRefreshBackend || {};
3541
3546
  global.wazoIsMobile = global.wazoIsMobile || {};
@@ -4581,6 +4586,7 @@ class ApiClient {
4581
4586
 
4582
4587
 
4583
4588
 
4589
+
4584
4590
 
4585
4591
 
4586
4592
 
@@ -4633,23 +4639,31 @@ class ApiClient {
4633
4639
  return null;
4634
4640
  }
4635
4641
 
4636
- const session = await this.auth.refreshToken(
4637
- this.refreshToken,
4638
- this.refreshBackend,
4639
- this.refreshExpiration,
4640
- this.isMobile,
4641
- this.refreshTenantId,
4642
- );
4643
-
4644
- logger.info('token refreshed', { token: session.token });
4642
+ try {
4643
+ const session = await this.auth.refreshToken(
4644
+ this.refreshToken,
4645
+ this.refreshBackend,
4646
+ this.refreshExpiration,
4647
+ this.isMobile,
4648
+ this.refreshTenantId,
4649
+ );
4650
+
4651
+ logger.info('token refreshed', { token: session.token });
4652
+
4653
+ if (this.onRefreshToken) {
4654
+ this.onRefreshToken(session.token, session);
4655
+ }
4645
4656
 
4646
- if (this.onRefreshToken) {
4647
- this.onRefreshToken(session.token, session);
4648
- }
4657
+ this.setToken(session.token);
4649
4658
 
4650
- this.setToken(session.token);
4659
+ return session.token;
4660
+ } catch (error) {
4661
+ logger.error('token refresh, error', error);
4651
4662
 
4652
- return session.token;
4663
+ if (this.onRefreshTokenError) {
4664
+ this.onRefreshTokenError(error);
4665
+ }
4666
+ }
4653
4667
  }
4654
4668
 
4655
4669
  setToken(token ) {
@@ -4672,6 +4686,10 @@ class ApiClient {
4672
4686
  this.onRefreshToken = onRefreshToken;
4673
4687
  }
4674
4688
 
4689
+ setOnRefreshTokenError(callback ) {
4690
+ this.onRefreshTokenError = callback;
4691
+ }
4692
+
4675
4693
  setRefreshExpiration(refreshExpiration ) {
4676
4694
  this.refreshExpiration = refreshExpiration;
4677
4695
  }
@@ -2245,9 +2245,12 @@ var authMethods = (client , baseUrl ) => ({
2245
2245
  expiration: expiration || DETAULT_EXPIRATION,
2246
2246
  refresh_token: refreshToken,
2247
2247
  client_id: client.clientId,
2248
- tenant_id: tenantId,
2249
2248
  };
2250
2249
 
2250
+ if (tenantId) {
2251
+ body.tenant_id = tenantId;
2252
+ }
2253
+
2251
2254
  const headers = {
2252
2255
  'Content-Type': 'application/json',
2253
2256
  ...(isMobile ? { 'Wazo-Session-Type': 'mobile' } : {}),
@@ -3535,7 +3538,9 @@ global.wazoClients = global.wazoClients || {};
3535
3538
  global.wazoClientId = global.wazoClientId || {};
3536
3539
  global.wazoClientToken = global.wazoClientToken || {};
3537
3540
  global.wazoRefreshToken = global.wazoRefreshToken || {};
3541
+ global.wazoRefreshTenantId = global.wazoRefreshTenantId || {};
3538
3542
  global.wazoOnRefreshToken = global.wazoOnRefreshToken || {};
3543
+ global.wazoOnRefreshTokenError = global.wazoOnRefreshTokenError || {};
3539
3544
  global.wazoRefreshExpiration = global.wazoRefreshExpiration || {};
3540
3545
  global.wazoRefreshBackend = global.wazoRefreshBackend || {};
3541
3546
  global.wazoIsMobile = global.wazoIsMobile || {};
@@ -4581,6 +4586,7 @@ class ApiClient {
4581
4586
 
4582
4587
 
4583
4588
 
4589
+
4584
4590
 
4585
4591
 
4586
4592
 
@@ -4633,23 +4639,31 @@ class ApiClient {
4633
4639
  return null;
4634
4640
  }
4635
4641
 
4636
- const session = await this.auth.refreshToken(
4637
- this.refreshToken,
4638
- this.refreshBackend,
4639
- this.refreshExpiration,
4640
- this.isMobile,
4641
- this.refreshTenantId,
4642
- );
4643
-
4644
- logger.info('token refreshed', { token: session.token });
4642
+ try {
4643
+ const session = await this.auth.refreshToken(
4644
+ this.refreshToken,
4645
+ this.refreshBackend,
4646
+ this.refreshExpiration,
4647
+ this.isMobile,
4648
+ this.refreshTenantId,
4649
+ );
4650
+
4651
+ logger.info('token refreshed', { token: session.token });
4652
+
4653
+ if (this.onRefreshToken) {
4654
+ this.onRefreshToken(session.token, session);
4655
+ }
4645
4656
 
4646
- if (this.onRefreshToken) {
4647
- this.onRefreshToken(session.token, session);
4648
- }
4657
+ this.setToken(session.token);
4649
4658
 
4650
- this.setToken(session.token);
4659
+ return session.token;
4660
+ } catch (error) {
4661
+ logger.error('token refresh, error', error);
4651
4662
 
4652
- return session.token;
4663
+ if (this.onRefreshTokenError) {
4664
+ this.onRefreshTokenError(error);
4665
+ }
4666
+ }
4653
4667
  }
4654
4668
 
4655
4669
  setToken(token ) {
@@ -4672,6 +4686,10 @@ class ApiClient {
4672
4686
  this.onRefreshToken = onRefreshToken;
4673
4687
  }
4674
4688
 
4689
+ setOnRefreshTokenError(callback ) {
4690
+ this.onRefreshTokenError = callback;
4691
+ }
4692
+
4675
4693
  setRefreshExpiration(refreshExpiration ) {
4676
4694
  this.refreshExpiration = refreshExpiration;
4677
4695
  }