@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
@@ -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]);
@@ -5643,6 +5677,7 @@ class Auth {
5643
5677
 
5644
5678
 
5645
5679
 
5680
+
5646
5681
 
5647
5682
 
5648
5683
 
@@ -5680,6 +5715,14 @@ class Auth {
5680
5715
  this.onRefreshTokenCallback(token, session);
5681
5716
  }
5682
5717
  });
5718
+
5719
+ setOnRefreshTokenError(error => {
5720
+ logger$9.error('on refresh token error', error);
5721
+
5722
+ if (this.onRefreshTokenCallbackError) {
5723
+ this.onRefreshTokenCallbackError(error);
5724
+ }
5725
+ });
5683
5726
  }
5684
5727
 
5685
5728
  setFetchOptions(options ) {
@@ -5768,6 +5811,10 @@ class Auth {
5768
5811
  this.onRefreshTokenCallback = callback;
5769
5812
  }
5770
5813
 
5814
+ setOnRefreshTokenError(callback ) {
5815
+ this.onRefreshTokenCallbackError = callback;
5816
+ }
5817
+
5771
5818
  checkAuthorizations(session , authorizationName ) {
5772
5819
  if (!authorizationName) {
5773
5820
  return;
@@ -5800,6 +5847,12 @@ class Auth {
5800
5847
  setRefreshToken(refreshToken);
5801
5848
  }
5802
5849
 
5850
+ setRefreshTenantId(refreshTenantId ) {
5851
+ setRefreshTenantId(refreshTenantId);
5852
+
5853
+ getApiClient().setRefreshTenantId(refreshTenantId);
5854
+ }
5855
+
5803
5856
  forceRefreshToken() {
5804
5857
  getApiClient().forceRefreshToken();
5805
5858
  }
@@ -2804,9 +2804,12 @@ var authMethods = (client , baseUrl ) => ({
2804
2804
  expiration: expiration || DETAULT_EXPIRATION,
2805
2805
  refresh_token: refreshToken,
2806
2806
  client_id: client.clientId,
2807
- tenant_id: tenantId,
2808
2807
  };
2809
2808
 
2809
+ if (tenantId) {
2810
+ body.tenant_id = tenantId;
2811
+ }
2812
+
2810
2813
  const headers = {
2811
2814
  'Content-Type': 'application/json',
2812
2815
  ...(isMobile ? { 'Wazo-Session-Type': 'mobile' } : {}),
@@ -4094,7 +4097,9 @@ global.wazoClients = global.wazoClients || {};
4094
4097
  global.wazoClientId = global.wazoClientId || {};
4095
4098
  global.wazoClientToken = global.wazoClientToken || {};
4096
4099
  global.wazoRefreshToken = global.wazoRefreshToken || {};
4100
+ global.wazoRefreshTenantId = global.wazoRefreshTenantId || {};
4097
4101
  global.wazoOnRefreshToken = global.wazoOnRefreshToken || {};
4102
+ global.wazoOnRefreshTokenError = global.wazoOnRefreshTokenError || {};
4098
4103
  global.wazoRefreshExpiration = global.wazoRefreshExpiration || {};
4099
4104
  global.wazoRefreshBackend = global.wazoRefreshBackend || {};
4100
4105
  global.wazoIsMobile = global.wazoIsMobile || {};
@@ -5140,6 +5145,7 @@ class ApiClient {
5140
5145
 
5141
5146
 
5142
5147
 
5148
+
5143
5149
 
5144
5150
 
5145
5151
 
@@ -5192,23 +5198,31 @@ class ApiClient {
5192
5198
  return null;
5193
5199
  }
5194
5200
 
5195
- const session = await this.auth.refreshToken(
5196
- this.refreshToken,
5197
- this.refreshBackend,
5198
- this.refreshExpiration,
5199
- this.isMobile,
5200
- this.refreshTenantId,
5201
- );
5201
+ try {
5202
+ const session = await this.auth.refreshToken(
5203
+ this.refreshToken,
5204
+ this.refreshBackend,
5205
+ this.refreshExpiration,
5206
+ this.isMobile,
5207
+ this.refreshTenantId,
5208
+ );
5209
+
5210
+ logger$1.info('token refreshed', { token: session.token });
5211
+
5212
+ if (this.onRefreshToken) {
5213
+ this.onRefreshToken(session.token, session);
5214
+ }
5202
5215
 
5203
- logger$1.info('token refreshed', { token: session.token });
5216
+ this.setToken(session.token);
5204
5217
 
5205
- if (this.onRefreshToken) {
5206
- this.onRefreshToken(session.token, session);
5207
- }
5208
-
5209
- this.setToken(session.token);
5218
+ return session.token;
5219
+ } catch (error) {
5220
+ logger$1.error('token refresh, error', error);
5210
5221
 
5211
- return session.token;
5222
+ if (this.onRefreshTokenError) {
5223
+ this.onRefreshTokenError(error);
5224
+ }
5225
+ }
5212
5226
  }
5213
5227
 
5214
5228
  setToken(token ) {
@@ -5231,6 +5245,10 @@ class ApiClient {
5231
5245
  this.onRefreshToken = onRefreshToken;
5232
5246
  }
5233
5247
 
5248
+ setOnRefreshTokenError(callback ) {
5249
+ this.onRefreshTokenError = callback;
5250
+ }
5251
+
5234
5252
  setRefreshExpiration(refreshExpiration ) {
5235
5253
  this.refreshExpiration = refreshExpiration;
5236
5254
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wazo/sdk",
3
- "version": "0.37.41",
3
+ "version": "0.37.42",
4
4
  "description": "Wazo's JavaScript Software Development Kit.",
5
5
  "main": "dist/wazo-sdk.js",
6
6
  "author": "Wazo (http://wazo.io)",
package/src/api/auth.js CHANGED
@@ -74,9 +74,12 @@ export default (client: ApiRequester, baseUrl: string) => ({
74
74
  expiration: expiration || DETAULT_EXPIRATION,
75
75
  refresh_token: refreshToken,
76
76
  client_id: client.clientId,
77
- tenant_id: tenantId,
78
77
  };
79
78
 
79
+ if (tenantId) {
80
+ body.tenant_id = tenantId;
81
+ }
82
+
80
83
  const headers: Object = {
81
84
  'Content-Type': 'application/json',
82
85
  ...(isMobile ? { 'Wazo-Session-Type': 'mobile' } : {}),
package/src/api-client.js CHANGED
@@ -53,6 +53,7 @@ export default class ApiClient {
53
53
 
54
54
  refreshToken: ?string;
55
55
  onRefreshToken: ?Function;
56
+ onRefreshTokenError: ?Function;
56
57
  refreshExpiration: ?number;
57
58
  refreshBackend: ?string;
58
59
  refreshTenantId: ?string;
@@ -105,23 +106,31 @@ export default class ApiClient {
105
106
  return null;
106
107
  }
107
108
 
108
- const session = await this.auth.refreshToken(
109
- this.refreshToken,
110
- this.refreshBackend,
111
- this.refreshExpiration,
112
- this.isMobile,
113
- this.refreshTenantId,
114
- );
109
+ try {
110
+ const session = await this.auth.refreshToken(
111
+ this.refreshToken,
112
+ this.refreshBackend,
113
+ this.refreshExpiration,
114
+ this.isMobile,
115
+ this.refreshTenantId,
116
+ );
115
117
 
116
- logger.info('token refreshed', { token: session.token });
118
+ logger.info('token refreshed', { token: session.token });
117
119
 
118
- if (this.onRefreshToken) {
119
- this.onRefreshToken(session.token, session);
120
- }
120
+ if (this.onRefreshToken) {
121
+ this.onRefreshToken(session.token, session);
122
+ }
123
+
124
+ this.setToken(session.token);
121
125
 
122
- this.setToken(session.token);
126
+ return session.token;
127
+ } catch (error) {
128
+ logger.error('token refresh, error', error);
123
129
 
124
- return session.token;
130
+ if (this.onRefreshTokenError) {
131
+ this.onRefreshTokenError(error);
132
+ }
133
+ }
125
134
  }
126
135
 
127
136
  setToken(token: string) {
@@ -144,6 +153,10 @@ export default class ApiClient {
144
153
  this.onRefreshToken = onRefreshToken;
145
154
  }
146
155
 
156
+ setOnRefreshTokenError(callback: Function) {
157
+ this.onRefreshTokenError = callback;
158
+ }
159
+
147
160
  setRefreshExpiration(refreshExpiration: number) {
148
161
  this.refreshExpiration = refreshExpiration;
149
162
  }
@@ -10,7 +10,9 @@ global.wazoClients = global.wazoClients || {};
10
10
  global.wazoClientId = global.wazoClientId || {};
11
11
  global.wazoClientToken = global.wazoClientToken || {};
12
12
  global.wazoRefreshToken = global.wazoRefreshToken || {};
13
+ global.wazoRefreshTenantId = global.wazoRefreshTenantId || {};
13
14
  global.wazoOnRefreshToken = global.wazoOnRefreshToken || {};
15
+ global.wazoOnRefreshTokenError = global.wazoOnRefreshTokenError || {};
14
16
  global.wazoRefreshExpiration = global.wazoRefreshExpiration || {};
15
17
  global.wazoRefreshBackend = global.wazoRefreshBackend || {};
16
18
  global.wazoIsMobile = global.wazoIsMobile || {};
@@ -32,10 +34,18 @@ export const setRefreshToken = (newRefreshToken: ?string, forServer: ?string = n
32
34
  global.wazoRefreshToken[forServer] = newRefreshToken;
33
35
  };
34
36
 
37
+ export const setRefreshTenantId = (refreshTenantId: ?string, forServer: ?string = null) => {
38
+ global.wazoRefreshTenantId[forServer] = refreshTenantId;
39
+ };
40
+
35
41
  export const setOnRefreshToken = (onRefreshToken: Function, forServer: ?string = null) => {
36
42
  global.wazoOnRefreshToken[forServer] = onRefreshToken;
37
43
  };
38
44
 
45
+ export const setOnRefreshTokenError = (callback: Function, forServer: ?string = null) => {
46
+ global.wazoOnRefreshTokenError[forServer] = callback;
47
+ };
48
+
39
49
  export const setRefreshExpiration = (refreshExpiration: number, forServer: ?string = null) => {
40
50
  global.wazoRefreshExpiration[forServer] = refreshExpiration;
41
51
  };
@@ -62,12 +72,20 @@ const fillClient = (apiClient: WazoApiClient) => {
62
72
 
63
73
  apiClient.setRefreshToken(global.wazoRefreshToken[server] || global.wazoRefreshToken[null] || apiClient.refreshToken);
64
74
 
75
+ apiClient.setRefreshTenantId(
76
+ global.wazoRefreshTenantId[server] || global.wazoRefreshTenantId[null] || apiClient.refreshTenantId,
77
+ );
78
+
65
79
  apiClient.setFetchOptions(global.wazoFetchOptions[server] || global.wazoFetchOptions[null] || apiClient.fetchOptions);
66
80
 
67
81
  apiClient.setOnRefreshToken(
68
82
  global.wazoOnRefreshToken[server] || global.wazoOnRefreshToken[null] || apiClient.onRefreshToken,
69
83
  );
70
84
 
85
+ apiClient.setOnRefreshTokenError(
86
+ global.wazoOnRefreshTokenError[server] || global.wazoOnRefreshTokenError[null] || apiClient.onRefreshTokenError,
87
+ );
88
+
71
89
  apiClient.setRefreshExpiration(
72
90
  global.wazoRefreshExpiration[server] || global.wazoRefreshExpiration[null] || apiClient.refreshExpiration,
73
91
  );
@@ -81,7 +99,7 @@ const fillClient = (apiClient: WazoApiClient) => {
81
99
  return apiClient;
82
100
  };
83
101
 
84
- export default (forServer: ?string): WazoApiClient => {
102
+ export default (forServer: ?string = null): WazoApiClient => {
85
103
  const server: string = forServer || global.wazoCurrentServer || '';
86
104
  if (server in global.wazoClients) {
87
105
  return fillClient(global.wazoClients[server]);
@@ -10,6 +10,8 @@ import getApiClient, {
10
10
  setRefreshExpiration,
11
11
  setOnRefreshToken,
12
12
  setFetchOptions,
13
+ setRefreshTenantId,
14
+ setOnRefreshTokenError,
13
15
  } from '../service/getApiClient';
14
16
  import IssueReporter from '../service/IssueReporter';
15
17
 
@@ -29,6 +31,7 @@ class Auth {
29
31
  host: ?string;
30
32
  session: ?Session;
31
33
  onRefreshTokenCallback: ?Function;
34
+ onRefreshTokenCallbackError: ?Function;
32
35
  authenticated: boolean;
33
36
  mobile: boolean;
34
37
  BACKEND_WAZO: string;
@@ -66,6 +69,14 @@ class Auth {
66
69
  this.onRefreshTokenCallback(token, session);
67
70
  }
68
71
  });
72
+
73
+ setOnRefreshTokenError(error => {
74
+ logger.error('on refresh token error', error);
75
+
76
+ if (this.onRefreshTokenCallbackError) {
77
+ this.onRefreshTokenCallbackError(error);
78
+ }
79
+ });
69
80
  }
70
81
 
71
82
  setFetchOptions(options: Object) {
@@ -154,6 +165,10 @@ class Auth {
154
165
  this.onRefreshTokenCallback = callback;
155
166
  }
156
167
 
168
+ setOnRefreshTokenError(callback: Function) {
169
+ this.onRefreshTokenCallbackError = callback;
170
+ }
171
+
157
172
  checkAuthorizations(session: Session, authorizationName: ?string) {
158
173
  if (!authorizationName) {
159
174
  return;
@@ -186,6 +201,12 @@ class Auth {
186
201
  setRefreshToken(refreshToken);
187
202
  }
188
203
 
204
+ setRefreshTenantId(refreshTenantId: string) {
205
+ setRefreshTenantId(refreshTenantId);
206
+
207
+ getApiClient().setRefreshTenantId(refreshTenantId);
208
+ }
209
+
189
210
  forceRefreshToken() {
190
211
  getApiClient().forceRefreshToken();
191
212
  }