@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
@@ -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]);
@@ -5631,6 +5665,7 @@ class Auth {
5631
5665
 
5632
5666
 
5633
5667
 
5668
+
5634
5669
 
5635
5670
 
5636
5671
 
@@ -5668,6 +5703,14 @@ class Auth {
5668
5703
  this.onRefreshTokenCallback(token, session);
5669
5704
  }
5670
5705
  });
5706
+
5707
+ setOnRefreshTokenError(error => {
5708
+ logger$9.error('on refresh token error', error);
5709
+
5710
+ if (this.onRefreshTokenCallbackError) {
5711
+ this.onRefreshTokenCallbackError(error);
5712
+ }
5713
+ });
5671
5714
  }
5672
5715
 
5673
5716
  setFetchOptions(options ) {
@@ -5756,6 +5799,10 @@ class Auth {
5756
5799
  this.onRefreshTokenCallback = callback;
5757
5800
  }
5758
5801
 
5802
+ setOnRefreshTokenError(callback ) {
5803
+ this.onRefreshTokenCallbackError = callback;
5804
+ }
5805
+
5759
5806
  checkAuthorizations(session , authorizationName ) {
5760
5807
  if (!authorizationName) {
5761
5808
  return;
@@ -5788,6 +5835,12 @@ class Auth {
5788
5835
  setRefreshToken(refreshToken);
5789
5836
  }
5790
5837
 
5838
+ setRefreshTenantId(refreshTenantId ) {
5839
+ setRefreshTenantId(refreshTenantId);
5840
+
5841
+ getApiClient().setRefreshTenantId(refreshTenantId);
5842
+ }
5843
+
5791
5844
  forceRefreshToken() {
5792
5845
  getApiClient().forceRefreshToken();
5793
5846
  }
@@ -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]);
@@ -5631,6 +5665,7 @@ class Auth {
5631
5665
 
5632
5666
 
5633
5667
 
5668
+
5634
5669
 
5635
5670
 
5636
5671
 
@@ -5668,6 +5703,14 @@ class Auth {
5668
5703
  this.onRefreshTokenCallback(token, session);
5669
5704
  }
5670
5705
  });
5706
+
5707
+ setOnRefreshTokenError(error => {
5708
+ logger$9.error('on refresh token error', error);
5709
+
5710
+ if (this.onRefreshTokenCallbackError) {
5711
+ this.onRefreshTokenCallbackError(error);
5712
+ }
5713
+ });
5671
5714
  }
5672
5715
 
5673
5716
  setFetchOptions(options ) {
@@ -5756,6 +5799,10 @@ class Auth {
5756
5799
  this.onRefreshTokenCallback = callback;
5757
5800
  }
5758
5801
 
5802
+ setOnRefreshTokenError(callback ) {
5803
+ this.onRefreshTokenCallbackError = callback;
5804
+ }
5805
+
5759
5806
  checkAuthorizations(session , authorizationName ) {
5760
5807
  if (!authorizationName) {
5761
5808
  return;
@@ -5788,6 +5835,12 @@ class Auth {
5788
5835
  setRefreshToken(refreshToken);
5789
5836
  }
5790
5837
 
5838
+ setRefreshTenantId(refreshTenantId ) {
5839
+ setRefreshTenantId(refreshTenantId);
5840
+
5841
+ getApiClient().setRefreshTenantId(refreshTenantId);
5842
+ }
5843
+
5791
5844
  forceRefreshToken() {
5792
5845
  getApiClient().forceRefreshToken();
5793
5846
  }
@@ -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
- );
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
+ }
5191
5204
 
5192
- logger$1.info('token refreshed', { token: session.token });
5205
+ this.setToken(session.token);
5193
5206
 
5194
- if (this.onRefreshToken) {
5195
- this.onRefreshToken(session.token, session);
5196
- }
5197
-
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
  }
@@ -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' } : {}),
@@ -3541,7 +3544,9 @@ global.wazoClients = global.wazoClients || {};
3541
3544
  global.wazoClientId = global.wazoClientId || {};
3542
3545
  global.wazoClientToken = global.wazoClientToken || {};
3543
3546
  global.wazoRefreshToken = global.wazoRefreshToken || {};
3547
+ global.wazoRefreshTenantId = global.wazoRefreshTenantId || {};
3544
3548
  global.wazoOnRefreshToken = global.wazoOnRefreshToken || {};
3549
+ global.wazoOnRefreshTokenError = global.wazoOnRefreshTokenError || {};
3545
3550
  global.wazoRefreshExpiration = global.wazoRefreshExpiration || {};
3546
3551
  global.wazoRefreshBackend = global.wazoRefreshBackend || {};
3547
3552
  global.wazoIsMobile = global.wazoIsMobile || {};
@@ -4587,6 +4592,7 @@ class ApiClient {
4587
4592
 
4588
4593
 
4589
4594
 
4595
+
4590
4596
 
4591
4597
 
4592
4598
 
@@ -4639,23 +4645,31 @@ class ApiClient {
4639
4645
  return null;
4640
4646
  }
4641
4647
 
4642
- const session = await this.auth.refreshToken(
4643
- this.refreshToken,
4644
- this.refreshBackend,
4645
- this.refreshExpiration,
4646
- this.isMobile,
4647
- this.refreshTenantId,
4648
- );
4649
-
4650
- logger.info('token refreshed', { token: session.token });
4648
+ try {
4649
+ const session = await this.auth.refreshToken(
4650
+ this.refreshToken,
4651
+ this.refreshBackend,
4652
+ this.refreshExpiration,
4653
+ this.isMobile,
4654
+ this.refreshTenantId,
4655
+ );
4656
+
4657
+ logger.info('token refreshed', { token: session.token });
4658
+
4659
+ if (this.onRefreshToken) {
4660
+ this.onRefreshToken(session.token, session);
4661
+ }
4651
4662
 
4652
- if (this.onRefreshToken) {
4653
- this.onRefreshToken(session.token, session);
4654
- }
4663
+ this.setToken(session.token);
4655
4664
 
4656
- this.setToken(session.token);
4665
+ return session.token;
4666
+ } catch (error) {
4667
+ logger.error('token refresh, error', error);
4657
4668
 
4658
- return session.token;
4669
+ if (this.onRefreshTokenError) {
4670
+ this.onRefreshTokenError(error);
4671
+ }
4672
+ }
4659
4673
  }
4660
4674
 
4661
4675
  setToken(token ) {
@@ -4678,6 +4692,10 @@ class ApiClient {
4678
4692
  this.onRefreshToken = onRefreshToken;
4679
4693
  }
4680
4694
 
4695
+ setOnRefreshTokenError(callback ) {
4696
+ this.onRefreshTokenError = callback;
4697
+ }
4698
+
4681
4699
  setRefreshExpiration(refreshExpiration ) {
4682
4700
  this.refreshExpiration = refreshExpiration;
4683
4701
  }
@@ -2802,9 +2802,12 @@ var authMethods = (client , baseUrl ) => ({
2802
2802
  expiration: expiration || DETAULT_EXPIRATION,
2803
2803
  refresh_token: refreshToken,
2804
2804
  client_id: client.clientId,
2805
- tenant_id: tenantId,
2806
2805
  };
2807
2806
 
2807
+ if (tenantId) {
2808
+ body.tenant_id = tenantId;
2809
+ }
2810
+
2808
2811
  const headers = {
2809
2812
  'Content-Type': 'application/json',
2810
2813
  ...(isMobile ? { 'Wazo-Session-Type': 'mobile' } : {}),
@@ -4092,7 +4095,9 @@ global.wazoClients = global.wazoClients || {};
4092
4095
  global.wazoClientId = global.wazoClientId || {};
4093
4096
  global.wazoClientToken = global.wazoClientToken || {};
4094
4097
  global.wazoRefreshToken = global.wazoRefreshToken || {};
4098
+ global.wazoRefreshTenantId = global.wazoRefreshTenantId || {};
4095
4099
  global.wazoOnRefreshToken = global.wazoOnRefreshToken || {};
4100
+ global.wazoOnRefreshTokenError = global.wazoOnRefreshTokenError || {};
4096
4101
  global.wazoRefreshExpiration = global.wazoRefreshExpiration || {};
4097
4102
  global.wazoRefreshBackend = global.wazoRefreshBackend || {};
4098
4103
  global.wazoIsMobile = global.wazoIsMobile || {};
@@ -5138,6 +5143,7 @@ class ApiClient {
5138
5143
 
5139
5144
 
5140
5145
 
5146
+
5141
5147
 
5142
5148
 
5143
5149
 
@@ -5190,23 +5196,31 @@ class ApiClient {
5190
5196
  return null;
5191
5197
  }
5192
5198
 
5193
- const session = await this.auth.refreshToken(
5194
- this.refreshToken,
5195
- this.refreshBackend,
5196
- this.refreshExpiration,
5197
- this.isMobile,
5198
- this.refreshTenantId,
5199
- );
5199
+ try {
5200
+ const session = await this.auth.refreshToken(
5201
+ this.refreshToken,
5202
+ this.refreshBackend,
5203
+ this.refreshExpiration,
5204
+ this.isMobile,
5205
+ this.refreshTenantId,
5206
+ );
5207
+
5208
+ logger$1.info('token refreshed', { token: session.token });
5209
+
5210
+ if (this.onRefreshToken) {
5211
+ this.onRefreshToken(session.token, session);
5212
+ }
5200
5213
 
5201
- logger$1.info('token refreshed', { token: session.token });
5214
+ this.setToken(session.token);
5202
5215
 
5203
- if (this.onRefreshToken) {
5204
- this.onRefreshToken(session.token, session);
5205
- }
5206
-
5207
- this.setToken(session.token);
5216
+ return session.token;
5217
+ } catch (error) {
5218
+ logger$1.error('token refresh, error', error);
5208
5219
 
5209
- return session.token;
5220
+ if (this.onRefreshTokenError) {
5221
+ this.onRefreshTokenError(error);
5222
+ }
5223
+ }
5210
5224
  }
5211
5225
 
5212
5226
  setToken(token ) {
@@ -5229,6 +5243,10 @@ class ApiClient {
5229
5243
  this.onRefreshToken = onRefreshToken;
5230
5244
  }
5231
5245
 
5246
+ setOnRefreshTokenError(callback ) {
5247
+ this.onRefreshTokenError = callback;
5248
+ }
5249
+
5232
5250
  setRefreshExpiration(refreshExpiration ) {
5233
5251
  this.refreshExpiration = refreshExpiration;
5234
5252
  }
package/lib/api/auth.js CHANGED
@@ -1011,9 +1011,12 @@ var auth = (client , baseUrl ) => ({
1011
1011
  expiration: expiration || DETAULT_EXPIRATION,
1012
1012
  refresh_token: refreshToken,
1013
1013
  client_id: client.clientId,
1014
- tenant_id: tenantId,
1015
1014
  };
1016
1015
 
1016
+ if (tenantId) {
1017
+ body.tenant_id = tenantId;
1018
+ }
1019
+
1017
1020
  const headers = {
1018
1021
  'Content-Type': 'application/json',
1019
1022
  ...(isMobile ? { 'Wazo-Session-Type': 'mobile' } : {}),
@@ -1180,7 +1180,9 @@ global.wazoClients = global.wazoClients || {};
1180
1180
  global.wazoClientId = global.wazoClientId || {};
1181
1181
  global.wazoClientToken = global.wazoClientToken || {};
1182
1182
  global.wazoRefreshToken = global.wazoRefreshToken || {};
1183
+ global.wazoRefreshTenantId = global.wazoRefreshTenantId || {};
1183
1184
  global.wazoOnRefreshToken = global.wazoOnRefreshToken || {};
1185
+ global.wazoOnRefreshTokenError = global.wazoOnRefreshTokenError || {};
1184
1186
  global.wazoRefreshExpiration = global.wazoRefreshExpiration || {};
1185
1187
  global.wazoRefreshBackend = global.wazoRefreshBackend || {};
1186
1188
  global.wazoIsMobile = global.wazoIsMobile || {};