@wazo/sdk 0.37.41 → 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 (70) hide show
  1. package/dist/wazo-sdk.js +2 -2
  2. package/esm/__tests__/api-client.test.js +33 -15
  3. package/esm/__tests__/web-rtc-client.test.js +33 -15
  4. package/esm/api/auth.js +4 -1
  5. package/esm/api/ctid-ng.js +2 -0
  6. package/esm/api-client.js +33 -15
  7. package/esm/checker/Checker.js +33 -15
  8. package/esm/checker/checks/aor.js +33 -15
  9. package/esm/checker/checks/api.js +33 -15
  10. package/esm/checker/checks/index.js +33 -15
  11. package/esm/checker/checks/webrtc-transport.js +33 -15
  12. package/esm/checker/checks/webrtc.js +33 -15
  13. package/esm/domain/AdHocAPIConference.js +42 -16
  14. package/esm/domain/Features.js +42 -16
  15. package/esm/domain/Phone/CTIPhone.js +42 -16
  16. package/esm/domain/Phone/WebRTCPhone.js +2 -0
  17. package/esm/index.js +68 -15
  18. package/esm/service/CallApi.js +42 -16
  19. package/esm/service/getApiClient.js +51 -17
  20. package/esm/simple/Auth.js +68 -15
  21. package/esm/simple/Configuration.js +68 -15
  22. package/esm/simple/Directory.js +42 -16
  23. package/esm/simple/Phone.js +68 -15
  24. package/esm/simple/index.js +68 -15
  25. package/esm/simple/room/LocalParticipant.js +68 -15
  26. package/esm/simple/room/Participant.js +68 -15
  27. package/esm/simple/room/RemoteParticipant.js +68 -15
  28. package/esm/simple/room/Room.js +68 -15
  29. package/esm/simple/room/SipRoom.js +68 -15
  30. package/esm/simple/room/Stream.js +68 -15
  31. package/esm/simple/room/__tests__/RemoteParticipant.test.js +68 -15
  32. package/esm/simple/utils.js +68 -15
  33. package/esm/web-rtc-client.js +33 -15
  34. package/lib/__tests__/api-client.test.js +33 -15
  35. package/lib/__tests__/web-rtc-client.test.js +33 -15
  36. package/lib/api/auth.js +4 -1
  37. package/lib/api/ctid-ng.js +2 -0
  38. package/lib/api-client.js +33 -15
  39. package/lib/checker/Checker.js +33 -15
  40. package/lib/checker/checks/aor.js +33 -15
  41. package/lib/checker/checks/api.js +33 -15
  42. package/lib/checker/checks/index.js +33 -15
  43. package/lib/checker/checks/webrtc-transport.js +33 -15
  44. package/lib/checker/checks/webrtc.js +33 -15
  45. package/lib/domain/AdHocAPIConference.js +42 -16
  46. package/lib/domain/Features.js +42 -16
  47. package/lib/domain/Phone/CTIPhone.js +42 -16
  48. package/lib/domain/Phone/WebRTCPhone.js +2 -0
  49. package/lib/index.js +68 -15
  50. package/lib/service/CallApi.js +42 -16
  51. package/lib/service/getApiClient.js +52 -16
  52. package/lib/simple/Auth.js +68 -15
  53. package/lib/simple/Configuration.js +68 -15
  54. package/lib/simple/Directory.js +42 -16
  55. package/lib/simple/Phone.js +68 -15
  56. package/lib/simple/index.js +68 -15
  57. package/lib/simple/room/LocalParticipant.js +68 -15
  58. package/lib/simple/room/Participant.js +68 -15
  59. package/lib/simple/room/RemoteParticipant.js +68 -15
  60. package/lib/simple/room/Room.js +68 -15
  61. package/lib/simple/room/SipRoom.js +68 -15
  62. package/lib/simple/room/Stream.js +68 -15
  63. package/lib/simple/room/__tests__/RemoteParticipant.test.js +68 -15
  64. package/lib/simple/utils.js +68 -15
  65. package/lib/web-rtc-client.js +33 -15
  66. package/package.json +1 -1
  67. package/src/api/auth.js +4 -1
  68. package/src/api-client.js +26 -13
  69. package/src/service/getApiClient.js +19 -1
  70. package/src/simple/Auth.js +21 -0
package/esm/index.js CHANGED
@@ -2266,9 +2266,12 @@ var authMethods = (client , baseUrl ) => ({
2266
2266
  expiration: expiration || DETAULT_EXPIRATION,
2267
2267
  refresh_token: refreshToken,
2268
2268
  client_id: client.clientId,
2269
- tenant_id: tenantId,
2270
2269
  };
2271
2270
 
2271
+ if (tenantId) {
2272
+ body.tenant_id = tenantId;
2273
+ }
2274
+
2272
2275
  const headers = {
2273
2276
  'Content-Type': 'application/json',
2274
2277
  ...(isMobile ? { 'Wazo-Session-Type': 'mobile' } : {}),
@@ -3976,7 +3979,9 @@ global.wazoClients = global.wazoClients || {};
3976
3979
  global.wazoClientId = global.wazoClientId || {};
3977
3980
  global.wazoClientToken = global.wazoClientToken || {};
3978
3981
  global.wazoRefreshToken = global.wazoRefreshToken || {};
3982
+ global.wazoRefreshTenantId = global.wazoRefreshTenantId || {};
3979
3983
  global.wazoOnRefreshToken = global.wazoOnRefreshToken || {};
3984
+ global.wazoOnRefreshTokenError = global.wazoOnRefreshTokenError || {};
3980
3985
  global.wazoRefreshExpiration = global.wazoRefreshExpiration || {};
3981
3986
  global.wazoRefreshBackend = global.wazoRefreshBackend || {};
3982
3987
  global.wazoIsMobile = global.wazoIsMobile || {};
@@ -3998,10 +4003,18 @@ const setRefreshToken = (newRefreshToken , forServer = null) =>
3998
4003
  global.wazoRefreshToken[forServer] = newRefreshToken;
3999
4004
  };
4000
4005
 
4006
+ const setRefreshTenantId = (refreshTenantId , forServer = null) => {
4007
+ global.wazoRefreshTenantId[forServer] = refreshTenantId;
4008
+ };
4009
+
4001
4010
  const setOnRefreshToken = (onRefreshToken , forServer = null) => {
4002
4011
  global.wazoOnRefreshToken[forServer] = onRefreshToken;
4003
4012
  };
4004
4013
 
4014
+ const setOnRefreshTokenError = (callback , forServer = null) => {
4015
+ global.wazoOnRefreshTokenError[forServer] = callback;
4016
+ };
4017
+
4005
4018
  const setRefreshExpiration = (refreshExpiration , forServer = null) => {
4006
4019
  global.wazoRefreshExpiration[forServer] = refreshExpiration;
4007
4020
  };
@@ -4020,12 +4033,20 @@ const fillClient = (apiClient ) => {
4020
4033
 
4021
4034
  apiClient.setRefreshToken(global.wazoRefreshToken[server] || global.wazoRefreshToken[null] || apiClient.refreshToken);
4022
4035
 
4036
+ apiClient.setRefreshTenantId(
4037
+ global.wazoRefreshTenantId[server] || global.wazoRefreshTenantId[null] || apiClient.refreshTenantId,
4038
+ );
4039
+
4023
4040
  apiClient.setFetchOptions(global.wazoFetchOptions[server] || global.wazoFetchOptions[null] || apiClient.fetchOptions);
4024
4041
 
4025
4042
  apiClient.setOnRefreshToken(
4026
4043
  global.wazoOnRefreshToken[server] || global.wazoOnRefreshToken[null] || apiClient.onRefreshToken,
4027
4044
  );
4028
4045
 
4046
+ apiClient.setOnRefreshTokenError(
4047
+ global.wazoOnRefreshTokenError[server] || global.wazoOnRefreshTokenError[null] || apiClient.onRefreshTokenError,
4048
+ );
4049
+
4029
4050
  apiClient.setRefreshExpiration(
4030
4051
  global.wazoRefreshExpiration[server] || global.wazoRefreshExpiration[null] || apiClient.refreshExpiration,
4031
4052
  );
@@ -4039,7 +4060,7 @@ const fillClient = (apiClient ) => {
4039
4060
  return apiClient;
4040
4061
  };
4041
4062
 
4042
- var getApiClient = (forServer ) => {
4063
+ var getApiClient = (forServer = null) => {
4043
4064
  const server = forServer || global.wazoCurrentServer || '';
4044
4065
  if (server in global.wazoClients) {
4045
4066
  return fillClient(global.wazoClients[server]);
@@ -5499,6 +5520,7 @@ class ApiClient {
5499
5520
 
5500
5521
 
5501
5522
 
5523
+
5502
5524
 
5503
5525
 
5504
5526
 
@@ -5551,23 +5573,31 @@ class ApiClient {
5551
5573
  return null;
5552
5574
  }
5553
5575
 
5554
- const session = await this.auth.refreshToken(
5555
- this.refreshToken,
5556
- this.refreshBackend,
5557
- this.refreshExpiration,
5558
- this.isMobile,
5559
- this.refreshTenantId,
5560
- );
5576
+ try {
5577
+ const session = await this.auth.refreshToken(
5578
+ this.refreshToken,
5579
+ this.refreshBackend,
5580
+ this.refreshExpiration,
5581
+ this.isMobile,
5582
+ this.refreshTenantId,
5583
+ );
5561
5584
 
5562
- logger$a.info('token refreshed', { token: session.token });
5585
+ logger$a.info('token refreshed', { token: session.token });
5563
5586
 
5564
- if (this.onRefreshToken) {
5565
- this.onRefreshToken(session.token, session);
5566
- }
5587
+ if (this.onRefreshToken) {
5588
+ this.onRefreshToken(session.token, session);
5589
+ }
5567
5590
 
5568
- this.setToken(session.token);
5591
+ this.setToken(session.token);
5569
5592
 
5570
- return session.token;
5593
+ return session.token;
5594
+ } catch (error) {
5595
+ logger$a.error('token refresh, error', error);
5596
+
5597
+ if (this.onRefreshTokenError) {
5598
+ this.onRefreshTokenError(error);
5599
+ }
5600
+ }
5571
5601
  }
5572
5602
 
5573
5603
  setToken(token ) {
@@ -5590,6 +5620,10 @@ class ApiClient {
5590
5620
  this.onRefreshToken = onRefreshToken;
5591
5621
  }
5592
5622
 
5623
+ setOnRefreshTokenError(callback ) {
5624
+ this.onRefreshTokenError = callback;
5625
+ }
5626
+
5593
5627
  setRefreshExpiration(refreshExpiration ) {
5594
5628
  this.refreshExpiration = refreshExpiration;
5595
5629
  }
@@ -11721,6 +11755,7 @@ class Auth {
11721
11755
 
11722
11756
 
11723
11757
 
11758
+
11724
11759
 
11725
11760
 
11726
11761
 
@@ -11758,6 +11793,14 @@ class Auth {
11758
11793
  this.onRefreshTokenCallback(token, session);
11759
11794
  }
11760
11795
  });
11796
+
11797
+ setOnRefreshTokenError(error => {
11798
+ logger$5.error('on refresh token error', error);
11799
+
11800
+ if (this.onRefreshTokenCallbackError) {
11801
+ this.onRefreshTokenCallbackError(error);
11802
+ }
11803
+ });
11761
11804
  }
11762
11805
 
11763
11806
  setFetchOptions(options ) {
@@ -11846,6 +11889,10 @@ class Auth {
11846
11889
  this.onRefreshTokenCallback = callback;
11847
11890
  }
11848
11891
 
11892
+ setOnRefreshTokenError(callback ) {
11893
+ this.onRefreshTokenCallbackError = callback;
11894
+ }
11895
+
11849
11896
  checkAuthorizations(session , authorizationName ) {
11850
11897
  if (!authorizationName) {
11851
11898
  return;
@@ -11878,6 +11925,12 @@ class Auth {
11878
11925
  setRefreshToken(refreshToken);
11879
11926
  }
11880
11927
 
11928
+ setRefreshTenantId(refreshTenantId ) {
11929
+ setRefreshTenantId(refreshTenantId);
11930
+
11931
+ getApiClient().setRefreshTenantId(refreshTenantId);
11932
+ }
11933
+
11881
11934
  forceRefreshToken() {
11882
11935
  getApiClient().forceRefreshToken();
11883
11936
  }
@@ -2785,9 +2785,12 @@ var authMethods = (client , baseUrl ) => ({
2785
2785
  expiration: expiration || DETAULT_EXPIRATION,
2786
2786
  refresh_token: refreshToken,
2787
2787
  client_id: client.clientId,
2788
- tenant_id: tenantId,
2789
2788
  };
2790
2789
 
2790
+ if (tenantId) {
2791
+ body.tenant_id = tenantId;
2792
+ }
2793
+
2791
2794
  const headers = {
2792
2795
  'Content-Type': 'application/json',
2793
2796
  ...(isMobile ? { 'Wazo-Session-Type': 'mobile' } : {}),
@@ -4566,6 +4569,7 @@ class ApiClient {
4566
4569
 
4567
4570
 
4568
4571
 
4572
+
4569
4573
 
4570
4574
 
4571
4575
 
@@ -4618,23 +4622,31 @@ class ApiClient {
4618
4622
  return null;
4619
4623
  }
4620
4624
 
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 });
4625
+ try {
4626
+ const session = await this.auth.refreshToken(
4627
+ this.refreshToken,
4628
+ this.refreshBackend,
4629
+ this.refreshExpiration,
4630
+ this.isMobile,
4631
+ this.refreshTenantId,
4632
+ );
4633
+
4634
+ logger.info('token refreshed', { token: session.token });
4635
+
4636
+ if (this.onRefreshToken) {
4637
+ this.onRefreshToken(session.token, session);
4638
+ }
4630
4639
 
4631
- if (this.onRefreshToken) {
4632
- this.onRefreshToken(session.token, session);
4633
- }
4640
+ this.setToken(session.token);
4634
4641
 
4635
- this.setToken(session.token);
4642
+ return session.token;
4643
+ } catch (error) {
4644
+ logger.error('token refresh, error', error);
4636
4645
 
4637
- return session.token;
4646
+ if (this.onRefreshTokenError) {
4647
+ this.onRefreshTokenError(error);
4648
+ }
4649
+ }
4638
4650
  }
4639
4651
 
4640
4652
  setToken(token ) {
@@ -4657,6 +4669,10 @@ class ApiClient {
4657
4669
  this.onRefreshToken = onRefreshToken;
4658
4670
  }
4659
4671
 
4672
+ setOnRefreshTokenError(callback ) {
4673
+ this.onRefreshTokenError = callback;
4674
+ }
4675
+
4660
4676
  setRefreshExpiration(refreshExpiration ) {
4661
4677
  this.refreshExpiration = refreshExpiration;
4662
4678
  }
@@ -4692,7 +4708,9 @@ global.wazoClients = global.wazoClients || {};
4692
4708
  global.wazoClientId = global.wazoClientId || {};
4693
4709
  global.wazoClientToken = global.wazoClientToken || {};
4694
4710
  global.wazoRefreshToken = global.wazoRefreshToken || {};
4711
+ global.wazoRefreshTenantId = global.wazoRefreshTenantId || {};
4695
4712
  global.wazoOnRefreshToken = global.wazoOnRefreshToken || {};
4713
+ global.wazoOnRefreshTokenError = global.wazoOnRefreshTokenError || {};
4696
4714
  global.wazoRefreshExpiration = global.wazoRefreshExpiration || {};
4697
4715
  global.wazoRefreshBackend = global.wazoRefreshBackend || {};
4698
4716
  global.wazoIsMobile = global.wazoIsMobile || {};
@@ -4708,12 +4726,20 @@ const fillClient = (apiClient ) => {
4708
4726
 
4709
4727
  apiClient.setRefreshToken(global.wazoRefreshToken[server] || global.wazoRefreshToken[null] || apiClient.refreshToken);
4710
4728
 
4729
+ apiClient.setRefreshTenantId(
4730
+ global.wazoRefreshTenantId[server] || global.wazoRefreshTenantId[null] || apiClient.refreshTenantId,
4731
+ );
4732
+
4711
4733
  apiClient.setFetchOptions(global.wazoFetchOptions[server] || global.wazoFetchOptions[null] || apiClient.fetchOptions);
4712
4734
 
4713
4735
  apiClient.setOnRefreshToken(
4714
4736
  global.wazoOnRefreshToken[server] || global.wazoOnRefreshToken[null] || apiClient.onRefreshToken,
4715
4737
  );
4716
4738
 
4739
+ apiClient.setOnRefreshTokenError(
4740
+ global.wazoOnRefreshTokenError[server] || global.wazoOnRefreshTokenError[null] || apiClient.onRefreshTokenError,
4741
+ );
4742
+
4717
4743
  apiClient.setRefreshExpiration(
4718
4744
  global.wazoRefreshExpiration[server] || global.wazoRefreshExpiration[null] || apiClient.refreshExpiration,
4719
4745
  );
@@ -4727,7 +4753,7 @@ const fillClient = (apiClient ) => {
4727
4753
  return apiClient;
4728
4754
  };
4729
4755
 
4730
- var getApiClient = (forServer ) => {
4756
+ var getApiClient = (forServer = null) => {
4731
4757
  const server = forServer || global.wazoCurrentServer || '';
4732
4758
  if (server in global.wazoClients) {
4733
4759
  return fillClient(global.wazoClients[server]);
@@ -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' } : {}),
@@ -4566,6 +4569,7 @@ class ApiClient {
4566
4569
 
4567
4570
 
4568
4571
 
4572
+
4569
4573
 
4570
4574
 
4571
4575
 
@@ -4618,23 +4622,31 @@ class ApiClient {
4618
4622
  return null;
4619
4623
  }
4620
4624
 
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 });
4625
+ try {
4626
+ const session = await this.auth.refreshToken(
4627
+ this.refreshToken,
4628
+ this.refreshBackend,
4629
+ this.refreshExpiration,
4630
+ this.isMobile,
4631
+ this.refreshTenantId,
4632
+ );
4633
+
4634
+ logger.info('token refreshed', { token: session.token });
4635
+
4636
+ if (this.onRefreshToken) {
4637
+ this.onRefreshToken(session.token, session);
4638
+ }
4630
4639
 
4631
- if (this.onRefreshToken) {
4632
- this.onRefreshToken(session.token, session);
4633
- }
4640
+ this.setToken(session.token);
4634
4641
 
4635
- this.setToken(session.token);
4642
+ return session.token;
4643
+ } catch (error) {
4644
+ logger.error('token refresh, error', error);
4636
4645
 
4637
- return session.token;
4646
+ if (this.onRefreshTokenError) {
4647
+ this.onRefreshTokenError(error);
4648
+ }
4649
+ }
4638
4650
  }
4639
4651
 
4640
4652
  setToken(token ) {
@@ -4657,6 +4669,10 @@ class ApiClient {
4657
4669
  this.onRefreshToken = onRefreshToken;
4658
4670
  }
4659
4671
 
4672
+ setOnRefreshTokenError(callback ) {
4673
+ this.onRefreshTokenError = callback;
4674
+ }
4675
+
4660
4676
  setRefreshExpiration(refreshExpiration ) {
4661
4677
  this.refreshExpiration = refreshExpiration;
4662
4678
  }
@@ -4692,7 +4708,9 @@ global.wazoClients = global.wazoClients || {};
4692
4708
  global.wazoClientId = global.wazoClientId || {};
4693
4709
  global.wazoClientToken = global.wazoClientToken || {};
4694
4710
  global.wazoRefreshToken = global.wazoRefreshToken || {};
4711
+ global.wazoRefreshTenantId = global.wazoRefreshTenantId || {};
4695
4712
  global.wazoOnRefreshToken = global.wazoOnRefreshToken || {};
4713
+ global.wazoOnRefreshTokenError = global.wazoOnRefreshTokenError || {};
4696
4714
  global.wazoRefreshExpiration = global.wazoRefreshExpiration || {};
4697
4715
  global.wazoRefreshBackend = global.wazoRefreshBackend || {};
4698
4716
  global.wazoIsMobile = global.wazoIsMobile || {};
@@ -4714,10 +4732,18 @@ const setRefreshToken = (newRefreshToken , forServer = null) =>
4714
4732
  global.wazoRefreshToken[forServer] = newRefreshToken;
4715
4733
  };
4716
4734
 
4735
+ const setRefreshTenantId = (refreshTenantId , forServer = null) => {
4736
+ global.wazoRefreshTenantId[forServer] = refreshTenantId;
4737
+ };
4738
+
4717
4739
  const setOnRefreshToken = (onRefreshToken , forServer = null) => {
4718
4740
  global.wazoOnRefreshToken[forServer] = onRefreshToken;
4719
4741
  };
4720
4742
 
4743
+ const setOnRefreshTokenError = (callback , forServer = null) => {
4744
+ global.wazoOnRefreshTokenError[forServer] = callback;
4745
+ };
4746
+
4721
4747
  const setRefreshExpiration = (refreshExpiration , forServer = null) => {
4722
4748
  global.wazoRefreshExpiration[forServer] = refreshExpiration;
4723
4749
  };
@@ -4744,12 +4770,20 @@ const fillClient = (apiClient ) => {
4744
4770
 
4745
4771
  apiClient.setRefreshToken(global.wazoRefreshToken[server] || global.wazoRefreshToken[null] || apiClient.refreshToken);
4746
4772
 
4773
+ apiClient.setRefreshTenantId(
4774
+ global.wazoRefreshTenantId[server] || global.wazoRefreshTenantId[null] || apiClient.refreshTenantId,
4775
+ );
4776
+
4747
4777
  apiClient.setFetchOptions(global.wazoFetchOptions[server] || global.wazoFetchOptions[null] || apiClient.fetchOptions);
4748
4778
 
4749
4779
  apiClient.setOnRefreshToken(
4750
4780
  global.wazoOnRefreshToken[server] || global.wazoOnRefreshToken[null] || apiClient.onRefreshToken,
4751
4781
  );
4752
4782
 
4783
+ apiClient.setOnRefreshTokenError(
4784
+ global.wazoOnRefreshTokenError[server] || global.wazoOnRefreshTokenError[null] || apiClient.onRefreshTokenError,
4785
+ );
4786
+
4753
4787
  apiClient.setRefreshExpiration(
4754
4788
  global.wazoRefreshExpiration[server] || global.wazoRefreshExpiration[null] || apiClient.refreshExpiration,
4755
4789
  );
@@ -4763,7 +4797,7 @@ const fillClient = (apiClient ) => {
4763
4797
  return apiClient;
4764
4798
  };
4765
4799
 
4766
- var getApiClient = (forServer ) => {
4800
+ var getApiClient = (forServer = null) => {
4767
4801
  const server = forServer || global.wazoCurrentServer || '';
4768
4802
  if (server in global.wazoClients) {
4769
4803
  return fillClient(global.wazoClients[server]);
@@ -4775,4 +4809,4 @@ var getApiClient = (forServer ) => {
4775
4809
  };
4776
4810
 
4777
4811
  export default getApiClient;
4778
- export { setApiClientId, setApiToken, setCurrentServer, setFetchOptions, setIsMobile, setOnRefreshToken, setRefreshBackend, setRefreshExpiration, setRefreshToken };
4812
+ export { setApiClientId, setApiToken, setCurrentServer, setFetchOptions, setIsMobile, setOnRefreshToken, setOnRefreshTokenError, setRefreshBackend, setRefreshExpiration, setRefreshTenantId, setRefreshToken };
@@ -2265,9 +2265,12 @@ var authMethods = (client , baseUrl ) => ({
2265
2265
  expiration: expiration || DETAULT_EXPIRATION,
2266
2266
  refresh_token: refreshToken,
2267
2267
  client_id: client.clientId,
2268
- tenant_id: tenantId,
2269
2268
  };
2270
2269
 
2270
+ if (tenantId) {
2271
+ body.tenant_id = tenantId;
2272
+ }
2273
+
2271
2274
  const headers = {
2272
2275
  'Content-Type': 'application/json',
2273
2276
  ...(isMobile ? { 'Wazo-Session-Type': 'mobile' } : {}),
@@ -5415,6 +5418,7 @@ class ApiClient {
5415
5418
 
5416
5419
 
5417
5420
 
5421
+
5418
5422
 
5419
5423
 
5420
5424
 
@@ -5467,23 +5471,31 @@ class ApiClient {
5467
5471
  return null;
5468
5472
  }
5469
5473
 
5470
- const session = await this.auth.refreshToken(
5471
- this.refreshToken,
5472
- this.refreshBackend,
5473
- this.refreshExpiration,
5474
- this.isMobile,
5475
- this.refreshTenantId,
5476
- );
5474
+ try {
5475
+ const session = await this.auth.refreshToken(
5476
+ this.refreshToken,
5477
+ this.refreshBackend,
5478
+ this.refreshExpiration,
5479
+ this.isMobile,
5480
+ this.refreshTenantId,
5481
+ );
5477
5482
 
5478
- logger$a.info('token refreshed', { token: session.token });
5483
+ logger$a.info('token refreshed', { token: session.token });
5479
5484
 
5480
- if (this.onRefreshToken) {
5481
- this.onRefreshToken(session.token, session);
5482
- }
5485
+ if (this.onRefreshToken) {
5486
+ this.onRefreshToken(session.token, session);
5487
+ }
5483
5488
 
5484
- this.setToken(session.token);
5489
+ this.setToken(session.token);
5485
5490
 
5486
- return session.token;
5491
+ return session.token;
5492
+ } catch (error) {
5493
+ logger$a.error('token refresh, error', error);
5494
+
5495
+ if (this.onRefreshTokenError) {
5496
+ this.onRefreshTokenError(error);
5497
+ }
5498
+ }
5487
5499
  }
5488
5500
 
5489
5501
  setToken(token ) {
@@ -5506,6 +5518,10 @@ class ApiClient {
5506
5518
  this.onRefreshToken = onRefreshToken;
5507
5519
  }
5508
5520
 
5521
+ setOnRefreshTokenError(callback ) {
5522
+ this.onRefreshTokenError = callback;
5523
+ }
5524
+
5509
5525
  setRefreshExpiration(refreshExpiration ) {
5510
5526
  this.refreshExpiration = refreshExpiration;
5511
5527
  }
@@ -5541,7 +5557,9 @@ global.wazoClients = global.wazoClients || {};
5541
5557
  global.wazoClientId = global.wazoClientId || {};
5542
5558
  global.wazoClientToken = global.wazoClientToken || {};
5543
5559
  global.wazoRefreshToken = global.wazoRefreshToken || {};
5560
+ global.wazoRefreshTenantId = global.wazoRefreshTenantId || {};
5544
5561
  global.wazoOnRefreshToken = global.wazoOnRefreshToken || {};
5562
+ global.wazoOnRefreshTokenError = global.wazoOnRefreshTokenError || {};
5545
5563
  global.wazoRefreshExpiration = global.wazoRefreshExpiration || {};
5546
5564
  global.wazoRefreshBackend = global.wazoRefreshBackend || {};
5547
5565
  global.wazoIsMobile = global.wazoIsMobile || {};
@@ -5563,10 +5581,18 @@ const setRefreshToken = (newRefreshToken , forServer = null) =>
5563
5581
  global.wazoRefreshToken[forServer] = newRefreshToken;
5564
5582
  };
5565
5583
 
5584
+ const setRefreshTenantId = (refreshTenantId , forServer = null) => {
5585
+ global.wazoRefreshTenantId[forServer] = refreshTenantId;
5586
+ };
5587
+
5566
5588
  const setOnRefreshToken = (onRefreshToken , forServer = null) => {
5567
5589
  global.wazoOnRefreshToken[forServer] = onRefreshToken;
5568
5590
  };
5569
5591
 
5592
+ const setOnRefreshTokenError = (callback , forServer = null) => {
5593
+ global.wazoOnRefreshTokenError[forServer] = callback;
5594
+ };
5595
+
5570
5596
  const setRefreshExpiration = (refreshExpiration , forServer = null) => {
5571
5597
  global.wazoRefreshExpiration[forServer] = refreshExpiration;
5572
5598
  };
@@ -5585,12 +5611,20 @@ const fillClient = (apiClient ) => {
5585
5611
 
5586
5612
  apiClient.setRefreshToken(global.wazoRefreshToken[server] || global.wazoRefreshToken[null] || apiClient.refreshToken);
5587
5613
 
5614
+ apiClient.setRefreshTenantId(
5615
+ global.wazoRefreshTenantId[server] || global.wazoRefreshTenantId[null] || apiClient.refreshTenantId,
5616
+ );
5617
+
5588
5618
  apiClient.setFetchOptions(global.wazoFetchOptions[server] || global.wazoFetchOptions[null] || apiClient.fetchOptions);
5589
5619
 
5590
5620
  apiClient.setOnRefreshToken(
5591
5621
  global.wazoOnRefreshToken[server] || global.wazoOnRefreshToken[null] || apiClient.onRefreshToken,
5592
5622
  );
5593
5623
 
5624
+ apiClient.setOnRefreshTokenError(
5625
+ global.wazoOnRefreshTokenError[server] || global.wazoOnRefreshTokenError[null] || apiClient.onRefreshTokenError,
5626
+ );
5627
+
5594
5628
  apiClient.setRefreshExpiration(
5595
5629
  global.wazoRefreshExpiration[server] || global.wazoRefreshExpiration[null] || apiClient.refreshExpiration,
5596
5630
  );
@@ -5604,7 +5638,7 @@ const fillClient = (apiClient ) => {
5604
5638
  return apiClient;
5605
5639
  };
5606
5640
 
5607
- var getApiClient = (forServer ) => {
5641
+ var getApiClient = (forServer = null) => {
5608
5642
  const server = forServer || global.wazoCurrentServer || '';
5609
5643
  if (server in global.wazoClients) {
5610
5644
  return fillClient(global.wazoClients[server]);
@@ -13718,6 +13752,7 @@ class Auth {
13718
13752
 
13719
13753
 
13720
13754
 
13755
+
13721
13756
 
13722
13757
 
13723
13758
 
@@ -13755,6 +13790,14 @@ class Auth {
13755
13790
  this.onRefreshTokenCallback(token, session);
13756
13791
  }
13757
13792
  });
13793
+
13794
+ setOnRefreshTokenError(error => {
13795
+ logger.error('on refresh token error', error);
13796
+
13797
+ if (this.onRefreshTokenCallbackError) {
13798
+ this.onRefreshTokenCallbackError(error);
13799
+ }
13800
+ });
13758
13801
  }
13759
13802
 
13760
13803
  setFetchOptions(options ) {
@@ -13843,6 +13886,10 @@ class Auth {
13843
13886
  this.onRefreshTokenCallback = callback;
13844
13887
  }
13845
13888
 
13889
+ setOnRefreshTokenError(callback ) {
13890
+ this.onRefreshTokenCallbackError = callback;
13891
+ }
13892
+
13846
13893
  checkAuthorizations(session , authorizationName ) {
13847
13894
  if (!authorizationName) {
13848
13895
  return;
@@ -13875,6 +13922,12 @@ class Auth {
13875
13922
  setRefreshToken(refreshToken);
13876
13923
  }
13877
13924
 
13925
+ setRefreshTenantId(refreshTenantId ) {
13926
+ setRefreshTenantId(refreshTenantId);
13927
+
13928
+ getApiClient().setRefreshTenantId(refreshTenantId);
13929
+ }
13930
+
13878
13931
  forceRefreshToken() {
13879
13932
  getApiClient().forceRefreshToken();
13880
13933
  }