@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
@@ -2253,9 +2253,12 @@ var authMethods = (client , baseUrl ) => ({
2253
2253
  expiration: expiration || DETAULT_EXPIRATION,
2254
2254
  refresh_token: refreshToken,
2255
2255
  client_id: client.clientId,
2256
- tenant_id: tenantId,
2257
2256
  };
2258
2257
 
2258
+ if (tenantId) {
2259
+ body.tenant_id = tenantId;
2260
+ }
2261
+
2259
2262
  const headers = {
2260
2263
  'Content-Type': 'application/json',
2261
2264
  ...(isMobile ? { 'Wazo-Session-Type': 'mobile' } : {}),
@@ -4574,6 +4577,7 @@ class ApiClient {
4574
4577
 
4575
4578
 
4576
4579
 
4580
+
4577
4581
 
4578
4582
 
4579
4583
 
@@ -4626,23 +4630,31 @@ class ApiClient {
4626
4630
  return null;
4627
4631
  }
4628
4632
 
4629
- const session = await this.auth.refreshToken(
4630
- this.refreshToken,
4631
- this.refreshBackend,
4632
- this.refreshExpiration,
4633
- this.isMobile,
4634
- this.refreshTenantId,
4635
- );
4636
-
4637
- logger.info('token refreshed', { token: session.token });
4633
+ try {
4634
+ const session = await this.auth.refreshToken(
4635
+ this.refreshToken,
4636
+ this.refreshBackend,
4637
+ this.refreshExpiration,
4638
+ this.isMobile,
4639
+ this.refreshTenantId,
4640
+ );
4641
+
4642
+ logger.info('token refreshed', { token: session.token });
4643
+
4644
+ if (this.onRefreshToken) {
4645
+ this.onRefreshToken(session.token, session);
4646
+ }
4638
4647
 
4639
- if (this.onRefreshToken) {
4640
- this.onRefreshToken(session.token, session);
4641
- }
4648
+ this.setToken(session.token);
4642
4649
 
4643
- this.setToken(session.token);
4650
+ return session.token;
4651
+ } catch (error) {
4652
+ logger.error('token refresh, error', error);
4644
4653
 
4645
- return session.token;
4654
+ if (this.onRefreshTokenError) {
4655
+ this.onRefreshTokenError(error);
4656
+ }
4657
+ }
4646
4658
  }
4647
4659
 
4648
4660
  setToken(token ) {
@@ -4665,6 +4677,10 @@ class ApiClient {
4665
4677
  this.onRefreshToken = onRefreshToken;
4666
4678
  }
4667
4679
 
4680
+ setOnRefreshTokenError(callback ) {
4681
+ this.onRefreshTokenError = callback;
4682
+ }
4683
+
4668
4684
  setRefreshExpiration(refreshExpiration ) {
4669
4685
  this.refreshExpiration = refreshExpiration;
4670
4686
  }
@@ -4700,7 +4716,9 @@ global.wazoClients = global.wazoClients || {};
4700
4716
  global.wazoClientId = global.wazoClientId || {};
4701
4717
  global.wazoClientToken = global.wazoClientToken || {};
4702
4718
  global.wazoRefreshToken = global.wazoRefreshToken || {};
4719
+ global.wazoRefreshTenantId = global.wazoRefreshTenantId || {};
4703
4720
  global.wazoOnRefreshToken = global.wazoOnRefreshToken || {};
4721
+ global.wazoOnRefreshTokenError = global.wazoOnRefreshTokenError || {};
4704
4722
  global.wazoRefreshExpiration = global.wazoRefreshExpiration || {};
4705
4723
  global.wazoRefreshBackend = global.wazoRefreshBackend || {};
4706
4724
  global.wazoIsMobile = global.wazoIsMobile || {};
@@ -4722,10 +4740,18 @@ const setRefreshToken = (newRefreshToken , forServer = null) =>
4722
4740
  global.wazoRefreshToken[forServer] = newRefreshToken;
4723
4741
  };
4724
4742
 
4743
+ const setRefreshTenantId = (refreshTenantId , forServer = null) => {
4744
+ global.wazoRefreshTenantId[forServer] = refreshTenantId;
4745
+ };
4746
+
4725
4747
  const setOnRefreshToken = (onRefreshToken , forServer = null) => {
4726
4748
  global.wazoOnRefreshToken[forServer] = onRefreshToken;
4727
4749
  };
4728
4750
 
4751
+ const setOnRefreshTokenError = (callback , forServer = null) => {
4752
+ global.wazoOnRefreshTokenError[forServer] = callback;
4753
+ };
4754
+
4729
4755
  const setRefreshExpiration = (refreshExpiration , forServer = null) => {
4730
4756
  global.wazoRefreshExpiration[forServer] = refreshExpiration;
4731
4757
  };
@@ -4752,12 +4778,20 @@ const fillClient = (apiClient ) => {
4752
4778
 
4753
4779
  apiClient.setRefreshToken(global.wazoRefreshToken[server] || global.wazoRefreshToken[null] || apiClient.refreshToken);
4754
4780
 
4781
+ apiClient.setRefreshTenantId(
4782
+ global.wazoRefreshTenantId[server] || global.wazoRefreshTenantId[null] || apiClient.refreshTenantId,
4783
+ );
4784
+
4755
4785
  apiClient.setFetchOptions(global.wazoFetchOptions[server] || global.wazoFetchOptions[null] || apiClient.fetchOptions);
4756
4786
 
4757
4787
  apiClient.setOnRefreshToken(
4758
4788
  global.wazoOnRefreshToken[server] || global.wazoOnRefreshToken[null] || apiClient.onRefreshToken,
4759
4789
  );
4760
4790
 
4791
+ apiClient.setOnRefreshTokenError(
4792
+ global.wazoOnRefreshTokenError[server] || global.wazoOnRefreshTokenError[null] || apiClient.onRefreshTokenError,
4793
+ );
4794
+
4761
4795
  apiClient.setRefreshExpiration(
4762
4796
  global.wazoRefreshExpiration[server] || global.wazoRefreshExpiration[null] || apiClient.refreshExpiration,
4763
4797
  );
@@ -4771,7 +4805,7 @@ const fillClient = (apiClient ) => {
4771
4805
  return apiClient;
4772
4806
  };
4773
4807
 
4774
- var getApiClient = (forServer ) => {
4808
+ var getApiClient = (forServer = null) => {
4775
4809
  const server = forServer || global.wazoCurrentServer || '';
4776
4810
  if (server in global.wazoClients) {
4777
4811
  return fillClient(global.wazoClients[server]);
@@ -4789,6 +4823,8 @@ exports.setCurrentServer = setCurrentServer;
4789
4823
  exports.setFetchOptions = setFetchOptions;
4790
4824
  exports.setIsMobile = setIsMobile;
4791
4825
  exports.setOnRefreshToken = setOnRefreshToken;
4826
+ exports.setOnRefreshTokenError = setOnRefreshTokenError;
4792
4827
  exports.setRefreshBackend = setRefreshBackend;
4793
4828
  exports.setRefreshExpiration = setRefreshExpiration;
4829
+ exports.setRefreshTenantId = setRefreshTenantId;
4794
4830
  exports.setRefreshToken = setRefreshToken;
@@ -2277,9 +2277,12 @@ var authMethods = (client , baseUrl ) => ({
2277
2277
  expiration: expiration || DETAULT_EXPIRATION,
2278
2278
  refresh_token: refreshToken,
2279
2279
  client_id: client.clientId,
2280
- tenant_id: tenantId,
2281
2280
  };
2282
2281
 
2282
+ if (tenantId) {
2283
+ body.tenant_id = tenantId;
2284
+ }
2285
+
2283
2286
  const headers = {
2284
2287
  'Content-Type': 'application/json',
2285
2288
  ...(isMobile ? { 'Wazo-Session-Type': 'mobile' } : {}),
@@ -5427,6 +5430,7 @@ class ApiClient {
5427
5430
 
5428
5431
 
5429
5432
 
5433
+
5430
5434
 
5431
5435
 
5432
5436
 
@@ -5479,23 +5483,31 @@ class ApiClient {
5479
5483
  return null;
5480
5484
  }
5481
5485
 
5482
- const session = await this.auth.refreshToken(
5483
- this.refreshToken,
5484
- this.refreshBackend,
5485
- this.refreshExpiration,
5486
- this.isMobile,
5487
- this.refreshTenantId,
5488
- );
5486
+ try {
5487
+ const session = await this.auth.refreshToken(
5488
+ this.refreshToken,
5489
+ this.refreshBackend,
5490
+ this.refreshExpiration,
5491
+ this.isMobile,
5492
+ this.refreshTenantId,
5493
+ );
5489
5494
 
5490
- logger$a.info('token refreshed', { token: session.token });
5495
+ logger$a.info('token refreshed', { token: session.token });
5491
5496
 
5492
- if (this.onRefreshToken) {
5493
- this.onRefreshToken(session.token, session);
5494
- }
5497
+ if (this.onRefreshToken) {
5498
+ this.onRefreshToken(session.token, session);
5499
+ }
5495
5500
 
5496
- this.setToken(session.token);
5501
+ this.setToken(session.token);
5497
5502
 
5498
- return session.token;
5503
+ return session.token;
5504
+ } catch (error) {
5505
+ logger$a.error('token refresh, error', error);
5506
+
5507
+ if (this.onRefreshTokenError) {
5508
+ this.onRefreshTokenError(error);
5509
+ }
5510
+ }
5499
5511
  }
5500
5512
 
5501
5513
  setToken(token ) {
@@ -5518,6 +5530,10 @@ class ApiClient {
5518
5530
  this.onRefreshToken = onRefreshToken;
5519
5531
  }
5520
5532
 
5533
+ setOnRefreshTokenError(callback ) {
5534
+ this.onRefreshTokenError = callback;
5535
+ }
5536
+
5521
5537
  setRefreshExpiration(refreshExpiration ) {
5522
5538
  this.refreshExpiration = refreshExpiration;
5523
5539
  }
@@ -5553,7 +5569,9 @@ global.wazoClients = global.wazoClients || {};
5553
5569
  global.wazoClientId = global.wazoClientId || {};
5554
5570
  global.wazoClientToken = global.wazoClientToken || {};
5555
5571
  global.wazoRefreshToken = global.wazoRefreshToken || {};
5572
+ global.wazoRefreshTenantId = global.wazoRefreshTenantId || {};
5556
5573
  global.wazoOnRefreshToken = global.wazoOnRefreshToken || {};
5574
+ global.wazoOnRefreshTokenError = global.wazoOnRefreshTokenError || {};
5557
5575
  global.wazoRefreshExpiration = global.wazoRefreshExpiration || {};
5558
5576
  global.wazoRefreshBackend = global.wazoRefreshBackend || {};
5559
5577
  global.wazoIsMobile = global.wazoIsMobile || {};
@@ -5575,10 +5593,18 @@ const setRefreshToken = (newRefreshToken , forServer = null) =>
5575
5593
  global.wazoRefreshToken[forServer] = newRefreshToken;
5576
5594
  };
5577
5595
 
5596
+ const setRefreshTenantId = (refreshTenantId , forServer = null) => {
5597
+ global.wazoRefreshTenantId[forServer] = refreshTenantId;
5598
+ };
5599
+
5578
5600
  const setOnRefreshToken = (onRefreshToken , forServer = null) => {
5579
5601
  global.wazoOnRefreshToken[forServer] = onRefreshToken;
5580
5602
  };
5581
5603
 
5604
+ const setOnRefreshTokenError = (callback , forServer = null) => {
5605
+ global.wazoOnRefreshTokenError[forServer] = callback;
5606
+ };
5607
+
5582
5608
  const setRefreshExpiration = (refreshExpiration , forServer = null) => {
5583
5609
  global.wazoRefreshExpiration[forServer] = refreshExpiration;
5584
5610
  };
@@ -5597,12 +5623,20 @@ const fillClient = (apiClient ) => {
5597
5623
 
5598
5624
  apiClient.setRefreshToken(global.wazoRefreshToken[server] || global.wazoRefreshToken[null] || apiClient.refreshToken);
5599
5625
 
5626
+ apiClient.setRefreshTenantId(
5627
+ global.wazoRefreshTenantId[server] || global.wazoRefreshTenantId[null] || apiClient.refreshTenantId,
5628
+ );
5629
+
5600
5630
  apiClient.setFetchOptions(global.wazoFetchOptions[server] || global.wazoFetchOptions[null] || apiClient.fetchOptions);
5601
5631
 
5602
5632
  apiClient.setOnRefreshToken(
5603
5633
  global.wazoOnRefreshToken[server] || global.wazoOnRefreshToken[null] || apiClient.onRefreshToken,
5604
5634
  );
5605
5635
 
5636
+ apiClient.setOnRefreshTokenError(
5637
+ global.wazoOnRefreshTokenError[server] || global.wazoOnRefreshTokenError[null] || apiClient.onRefreshTokenError,
5638
+ );
5639
+
5606
5640
  apiClient.setRefreshExpiration(
5607
5641
  global.wazoRefreshExpiration[server] || global.wazoRefreshExpiration[null] || apiClient.refreshExpiration,
5608
5642
  );
@@ -5616,7 +5650,7 @@ const fillClient = (apiClient ) => {
5616
5650
  return apiClient;
5617
5651
  };
5618
5652
 
5619
- var getApiClient = (forServer ) => {
5653
+ var getApiClient = (forServer = null) => {
5620
5654
  const server = forServer || global.wazoCurrentServer || '';
5621
5655
  if (server in global.wazoClients) {
5622
5656
  return fillClient(global.wazoClients[server]);
@@ -13730,6 +13764,7 @@ class Auth {
13730
13764
 
13731
13765
 
13732
13766
 
13767
+
13733
13768
 
13734
13769
 
13735
13770
 
@@ -13767,6 +13802,14 @@ class Auth {
13767
13802
  this.onRefreshTokenCallback(token, session);
13768
13803
  }
13769
13804
  });
13805
+
13806
+ setOnRefreshTokenError(error => {
13807
+ logger.error('on refresh token error', error);
13808
+
13809
+ if (this.onRefreshTokenCallbackError) {
13810
+ this.onRefreshTokenCallbackError(error);
13811
+ }
13812
+ });
13770
13813
  }
13771
13814
 
13772
13815
  setFetchOptions(options ) {
@@ -13855,6 +13898,10 @@ class Auth {
13855
13898
  this.onRefreshTokenCallback = callback;
13856
13899
  }
13857
13900
 
13901
+ setOnRefreshTokenError(callback ) {
13902
+ this.onRefreshTokenCallbackError = callback;
13903
+ }
13904
+
13858
13905
  checkAuthorizations(session , authorizationName ) {
13859
13906
  if (!authorizationName) {
13860
13907
  return;
@@ -13887,6 +13934,12 @@ class Auth {
13887
13934
  setRefreshToken(refreshToken);
13888
13935
  }
13889
13936
 
13937
+ setRefreshTenantId(refreshTenantId ) {
13938
+ setRefreshTenantId(refreshTenantId);
13939
+
13940
+ getApiClient().setRefreshTenantId(refreshTenantId);
13941
+ }
13942
+
13890
13943
  forceRefreshToken() {
13891
13944
  getApiClient().forceRefreshToken();
13892
13945
  }
@@ -2275,9 +2275,12 @@ var authMethods = (client , baseUrl ) => ({
2275
2275
  expiration: expiration || DETAULT_EXPIRATION,
2276
2276
  refresh_token: refreshToken,
2277
2277
  client_id: client.clientId,
2278
- tenant_id: tenantId,
2279
2278
  };
2280
2279
 
2280
+ if (tenantId) {
2281
+ body.tenant_id = tenantId;
2282
+ }
2283
+
2281
2284
  const headers = {
2282
2285
  'Content-Type': 'application/json',
2283
2286
  ...(isMobile ? { 'Wazo-Session-Type': 'mobile' } : {}),
@@ -5425,6 +5428,7 @@ class ApiClient {
5425
5428
 
5426
5429
 
5427
5430
 
5431
+
5428
5432
 
5429
5433
 
5430
5434
 
@@ -5477,23 +5481,31 @@ class ApiClient {
5477
5481
  return null;
5478
5482
  }
5479
5483
 
5480
- const session = await this.auth.refreshToken(
5481
- this.refreshToken,
5482
- this.refreshBackend,
5483
- this.refreshExpiration,
5484
- this.isMobile,
5485
- this.refreshTenantId,
5486
- );
5484
+ try {
5485
+ const session = await this.auth.refreshToken(
5486
+ this.refreshToken,
5487
+ this.refreshBackend,
5488
+ this.refreshExpiration,
5489
+ this.isMobile,
5490
+ this.refreshTenantId,
5491
+ );
5487
5492
 
5488
- logger$a.info('token refreshed', { token: session.token });
5493
+ logger$a.info('token refreshed', { token: session.token });
5489
5494
 
5490
- if (this.onRefreshToken) {
5491
- this.onRefreshToken(session.token, session);
5492
- }
5495
+ if (this.onRefreshToken) {
5496
+ this.onRefreshToken(session.token, session);
5497
+ }
5493
5498
 
5494
- this.setToken(session.token);
5499
+ this.setToken(session.token);
5495
5500
 
5496
- return session.token;
5501
+ return session.token;
5502
+ } catch (error) {
5503
+ logger$a.error('token refresh, error', error);
5504
+
5505
+ if (this.onRefreshTokenError) {
5506
+ this.onRefreshTokenError(error);
5507
+ }
5508
+ }
5497
5509
  }
5498
5510
 
5499
5511
  setToken(token ) {
@@ -5516,6 +5528,10 @@ class ApiClient {
5516
5528
  this.onRefreshToken = onRefreshToken;
5517
5529
  }
5518
5530
 
5531
+ setOnRefreshTokenError(callback ) {
5532
+ this.onRefreshTokenError = callback;
5533
+ }
5534
+
5519
5535
  setRefreshExpiration(refreshExpiration ) {
5520
5536
  this.refreshExpiration = refreshExpiration;
5521
5537
  }
@@ -5551,7 +5567,9 @@ global.wazoClients = global.wazoClients || {};
5551
5567
  global.wazoClientId = global.wazoClientId || {};
5552
5568
  global.wazoClientToken = global.wazoClientToken || {};
5553
5569
  global.wazoRefreshToken = global.wazoRefreshToken || {};
5570
+ global.wazoRefreshTenantId = global.wazoRefreshTenantId || {};
5554
5571
  global.wazoOnRefreshToken = global.wazoOnRefreshToken || {};
5572
+ global.wazoOnRefreshTokenError = global.wazoOnRefreshTokenError || {};
5555
5573
  global.wazoRefreshExpiration = global.wazoRefreshExpiration || {};
5556
5574
  global.wazoRefreshBackend = global.wazoRefreshBackend || {};
5557
5575
  global.wazoIsMobile = global.wazoIsMobile || {};
@@ -5573,10 +5591,18 @@ const setRefreshToken = (newRefreshToken , forServer = null) =>
5573
5591
  global.wazoRefreshToken[forServer] = newRefreshToken;
5574
5592
  };
5575
5593
 
5594
+ const setRefreshTenantId = (refreshTenantId , forServer = null) => {
5595
+ global.wazoRefreshTenantId[forServer] = refreshTenantId;
5596
+ };
5597
+
5576
5598
  const setOnRefreshToken = (onRefreshToken , forServer = null) => {
5577
5599
  global.wazoOnRefreshToken[forServer] = onRefreshToken;
5578
5600
  };
5579
5601
 
5602
+ const setOnRefreshTokenError = (callback , forServer = null) => {
5603
+ global.wazoOnRefreshTokenError[forServer] = callback;
5604
+ };
5605
+
5580
5606
  const setRefreshExpiration = (refreshExpiration , forServer = null) => {
5581
5607
  global.wazoRefreshExpiration[forServer] = refreshExpiration;
5582
5608
  };
@@ -5595,12 +5621,20 @@ const fillClient = (apiClient ) => {
5595
5621
 
5596
5622
  apiClient.setRefreshToken(global.wazoRefreshToken[server] || global.wazoRefreshToken[null] || apiClient.refreshToken);
5597
5623
 
5624
+ apiClient.setRefreshTenantId(
5625
+ global.wazoRefreshTenantId[server] || global.wazoRefreshTenantId[null] || apiClient.refreshTenantId,
5626
+ );
5627
+
5598
5628
  apiClient.setFetchOptions(global.wazoFetchOptions[server] || global.wazoFetchOptions[null] || apiClient.fetchOptions);
5599
5629
 
5600
5630
  apiClient.setOnRefreshToken(
5601
5631
  global.wazoOnRefreshToken[server] || global.wazoOnRefreshToken[null] || apiClient.onRefreshToken,
5602
5632
  );
5603
5633
 
5634
+ apiClient.setOnRefreshTokenError(
5635
+ global.wazoOnRefreshTokenError[server] || global.wazoOnRefreshTokenError[null] || apiClient.onRefreshTokenError,
5636
+ );
5637
+
5604
5638
  apiClient.setRefreshExpiration(
5605
5639
  global.wazoRefreshExpiration[server] || global.wazoRefreshExpiration[null] || apiClient.refreshExpiration,
5606
5640
  );
@@ -5614,7 +5648,7 @@ const fillClient = (apiClient ) => {
5614
5648
  return apiClient;
5615
5649
  };
5616
5650
 
5617
- var getApiClient = (forServer ) => {
5651
+ var getApiClient = (forServer = null) => {
5618
5652
  const server = forServer || global.wazoCurrentServer || '';
5619
5653
  if (server in global.wazoClients) {
5620
5654
  return fillClient(global.wazoClients[server]);
@@ -13711,6 +13745,7 @@ class Auth {
13711
13745
 
13712
13746
 
13713
13747
 
13748
+
13714
13749
 
13715
13750
 
13716
13751
 
@@ -13748,6 +13783,14 @@ class Auth {
13748
13783
  this.onRefreshTokenCallback(token, session);
13749
13784
  }
13750
13785
  });
13786
+
13787
+ setOnRefreshTokenError(error => {
13788
+ logger.error('on refresh token error', error);
13789
+
13790
+ if (this.onRefreshTokenCallbackError) {
13791
+ this.onRefreshTokenCallbackError(error);
13792
+ }
13793
+ });
13751
13794
  }
13752
13795
 
13753
13796
  setFetchOptions(options ) {
@@ -13836,6 +13879,10 @@ class Auth {
13836
13879
  this.onRefreshTokenCallback = callback;
13837
13880
  }
13838
13881
 
13882
+ setOnRefreshTokenError(callback ) {
13883
+ this.onRefreshTokenCallbackError = callback;
13884
+ }
13885
+
13839
13886
  checkAuthorizations(session , authorizationName ) {
13840
13887
  if (!authorizationName) {
13841
13888
  return;
@@ -13868,6 +13915,12 @@ class Auth {
13868
13915
  setRefreshToken(refreshToken);
13869
13916
  }
13870
13917
 
13918
+ setRefreshTenantId(refreshTenantId ) {
13919
+ setRefreshTenantId(refreshTenantId);
13920
+
13921
+ getApiClient().setRefreshTenantId(refreshTenantId);
13922
+ }
13923
+
13871
13924
  forceRefreshToken() {
13872
13925
  getApiClient().forceRefreshToken();
13873
13926
  }
@@ -2251,9 +2251,12 @@ var authMethods = (client , baseUrl ) => ({
2251
2251
  expiration: expiration || DETAULT_EXPIRATION,
2252
2252
  refresh_token: refreshToken,
2253
2253
  client_id: client.clientId,
2254
- tenant_id: tenantId,
2255
2254
  };
2256
2255
 
2256
+ if (tenantId) {
2257
+ body.tenant_id = tenantId;
2258
+ }
2259
+
2257
2260
  const headers = {
2258
2261
  'Content-Type': 'application/json',
2259
2262
  ...(isMobile ? { 'Wazo-Session-Type': 'mobile' } : {}),
@@ -4572,6 +4575,7 @@ class ApiClient {
4572
4575
 
4573
4576
 
4574
4577
 
4578
+
4575
4579
 
4576
4580
 
4577
4581
 
@@ -4624,23 +4628,31 @@ class ApiClient {
4624
4628
  return null;
4625
4629
  }
4626
4630
 
4627
- const session = await this.auth.refreshToken(
4628
- this.refreshToken,
4629
- this.refreshBackend,
4630
- this.refreshExpiration,
4631
- this.isMobile,
4632
- this.refreshTenantId,
4633
- );
4634
-
4635
- logger.info('token refreshed', { token: session.token });
4631
+ try {
4632
+ const session = await this.auth.refreshToken(
4633
+ this.refreshToken,
4634
+ this.refreshBackend,
4635
+ this.refreshExpiration,
4636
+ this.isMobile,
4637
+ this.refreshTenantId,
4638
+ );
4639
+
4640
+ logger.info('token refreshed', { token: session.token });
4641
+
4642
+ if (this.onRefreshToken) {
4643
+ this.onRefreshToken(session.token, session);
4644
+ }
4636
4645
 
4637
- if (this.onRefreshToken) {
4638
- this.onRefreshToken(session.token, session);
4639
- }
4646
+ this.setToken(session.token);
4640
4647
 
4641
- this.setToken(session.token);
4648
+ return session.token;
4649
+ } catch (error) {
4650
+ logger.error('token refresh, error', error);
4642
4651
 
4643
- return session.token;
4652
+ if (this.onRefreshTokenError) {
4653
+ this.onRefreshTokenError(error);
4654
+ }
4655
+ }
4644
4656
  }
4645
4657
 
4646
4658
  setToken(token ) {
@@ -4663,6 +4675,10 @@ class ApiClient {
4663
4675
  this.onRefreshToken = onRefreshToken;
4664
4676
  }
4665
4677
 
4678
+ setOnRefreshTokenError(callback ) {
4679
+ this.onRefreshTokenError = callback;
4680
+ }
4681
+
4666
4682
  setRefreshExpiration(refreshExpiration ) {
4667
4683
  this.refreshExpiration = refreshExpiration;
4668
4684
  }
@@ -4698,7 +4714,9 @@ global.wazoClients = global.wazoClients || {};
4698
4714
  global.wazoClientId = global.wazoClientId || {};
4699
4715
  global.wazoClientToken = global.wazoClientToken || {};
4700
4716
  global.wazoRefreshToken = global.wazoRefreshToken || {};
4717
+ global.wazoRefreshTenantId = global.wazoRefreshTenantId || {};
4701
4718
  global.wazoOnRefreshToken = global.wazoOnRefreshToken || {};
4719
+ global.wazoOnRefreshTokenError = global.wazoOnRefreshTokenError || {};
4702
4720
  global.wazoRefreshExpiration = global.wazoRefreshExpiration || {};
4703
4721
  global.wazoRefreshBackend = global.wazoRefreshBackend || {};
4704
4722
  global.wazoIsMobile = global.wazoIsMobile || {};
@@ -4714,12 +4732,20 @@ const fillClient = (apiClient ) => {
4714
4732
 
4715
4733
  apiClient.setRefreshToken(global.wazoRefreshToken[server] || global.wazoRefreshToken[null] || apiClient.refreshToken);
4716
4734
 
4735
+ apiClient.setRefreshTenantId(
4736
+ global.wazoRefreshTenantId[server] || global.wazoRefreshTenantId[null] || apiClient.refreshTenantId,
4737
+ );
4738
+
4717
4739
  apiClient.setFetchOptions(global.wazoFetchOptions[server] || global.wazoFetchOptions[null] || apiClient.fetchOptions);
4718
4740
 
4719
4741
  apiClient.setOnRefreshToken(
4720
4742
  global.wazoOnRefreshToken[server] || global.wazoOnRefreshToken[null] || apiClient.onRefreshToken,
4721
4743
  );
4722
4744
 
4745
+ apiClient.setOnRefreshTokenError(
4746
+ global.wazoOnRefreshTokenError[server] || global.wazoOnRefreshTokenError[null] || apiClient.onRefreshTokenError,
4747
+ );
4748
+
4723
4749
  apiClient.setRefreshExpiration(
4724
4750
  global.wazoRefreshExpiration[server] || global.wazoRefreshExpiration[null] || apiClient.refreshExpiration,
4725
4751
  );
@@ -4733,7 +4759,7 @@ const fillClient = (apiClient ) => {
4733
4759
  return apiClient;
4734
4760
  };
4735
4761
 
4736
- var getApiClient = (forServer ) => {
4762
+ var getApiClient = (forServer = null) => {
4737
4763
  const server = forServer || global.wazoCurrentServer || '';
4738
4764
  if (server in global.wazoClients) {
4739
4765
  return fillClient(global.wazoClients[server]);