@wazo/sdk 0.37.41 → 0.38.0

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 (112) hide show
  1. package/dist/wazo-sdk.js +3 -3
  2. package/esm/__tests__/api-client.test.js +45 -22
  3. package/esm/__tests__/web-rtc-client.test.js +49 -24
  4. package/esm/api/agentd.js +12 -7
  5. package/esm/api/amid.js +12 -7
  6. package/esm/api/application.js +12 -7
  7. package/esm/api/auth.js +16 -8
  8. package/esm/api/call-logd.js +12 -7
  9. package/esm/api/calld.js +12 -7
  10. package/esm/api/chatd.js +12 -7
  11. package/esm/api/confd.js +12 -7
  12. package/esm/api/ctid-ng.js +14 -7
  13. package/esm/api/dird.js +12 -7
  14. package/esm/api/webhookd.js +12 -7
  15. package/esm/api-client.js +45 -22
  16. package/esm/checker/Checker.js +50 -25
  17. package/esm/checker/checks/aor.js +45 -22
  18. package/esm/checker/checks/api.js +45 -22
  19. package/esm/checker/checks/index.js +50 -25
  20. package/esm/checker/checks/wazo-websocket.js +13 -8
  21. package/esm/checker/checks/webrtc-transport.js +49 -24
  22. package/esm/checker/checks/webrtc.js +49 -24
  23. package/esm/domain/AdHocAPIConference.js +54 -23
  24. package/esm/domain/Features.js +54 -23
  25. package/esm/domain/Phone/CTIPhone.js +54 -23
  26. package/esm/domain/Phone/WebRTCPhone.js +14 -7
  27. package/esm/index.js +233 -25
  28. package/esm/lib/WazoSessionDescriptionHandler.js +12 -7
  29. package/esm/service/CallApi.js +54 -23
  30. package/esm/service/IssueReporter.js +12 -7
  31. package/esm/service/__tests__/IssueReporter.test.js +18 -7
  32. package/esm/service/getApiClient.js +63 -24
  33. package/esm/simple/Auth.js +233 -25
  34. package/esm/simple/Configuration.js +233 -25
  35. package/esm/simple/Directory.js +54 -23
  36. package/esm/simple/Phone.js +233 -25
  37. package/esm/simple/Softphone.js +148 -0
  38. package/esm/simple/Websocket.js +13 -8
  39. package/esm/simple/index.js +233 -25
  40. package/esm/simple/room/LocalParticipant.js +233 -25
  41. package/esm/simple/room/Participant.js +233 -25
  42. package/esm/simple/room/RemoteParticipant.js +233 -25
  43. package/esm/simple/room/Room.js +233 -25
  44. package/esm/simple/room/SipRoom.js +233 -25
  45. package/esm/simple/room/Stream.js +233 -25
  46. package/esm/simple/room/__tests__/RemoteParticipant.test.js +233 -25
  47. package/esm/simple/utils.js +233 -25
  48. package/esm/utils/__tests__/api-requester.test.js +12 -7
  49. package/esm/utils/api-requester.js +12 -7
  50. package/esm/web-rtc-client.js +49 -24
  51. package/esm/websocket-client.js +13 -8
  52. package/lib/__tests__/api-client.test.js +45 -22
  53. package/lib/__tests__/web-rtc-client.test.js +49 -24
  54. package/lib/api/agentd.js +12 -7
  55. package/lib/api/amid.js +12 -7
  56. package/lib/api/application.js +12 -7
  57. package/lib/api/auth.js +16 -8
  58. package/lib/api/call-logd.js +12 -7
  59. package/lib/api/calld.js +12 -7
  60. package/lib/api/chatd.js +12 -7
  61. package/lib/api/confd.js +12 -7
  62. package/lib/api/ctid-ng.js +14 -7
  63. package/lib/api/dird.js +12 -7
  64. package/lib/api/webhookd.js +12 -7
  65. package/lib/api-client.js +45 -22
  66. package/lib/checker/Checker.js +50 -25
  67. package/lib/checker/checks/aor.js +45 -22
  68. package/lib/checker/checks/api.js +45 -22
  69. package/lib/checker/checks/index.js +50 -25
  70. package/lib/checker/checks/wazo-websocket.js +13 -8
  71. package/lib/checker/checks/webrtc-transport.js +49 -24
  72. package/lib/checker/checks/webrtc.js +49 -24
  73. package/lib/domain/AdHocAPIConference.js +54 -23
  74. package/lib/domain/Features.js +54 -23
  75. package/lib/domain/Phone/CTIPhone.js +54 -23
  76. package/lib/domain/Phone/WebRTCPhone.js +14 -7
  77. package/lib/index.js +233 -25
  78. package/lib/lib/WazoSessionDescriptionHandler.js +12 -7
  79. package/lib/service/CallApi.js +54 -23
  80. package/lib/service/IssueReporter.js +12 -7
  81. package/lib/service/__tests__/IssueReporter.test.js +18 -7
  82. package/lib/service/getApiClient.js +64 -23
  83. package/lib/simple/Auth.js +233 -25
  84. package/lib/simple/Configuration.js +233 -25
  85. package/lib/simple/Directory.js +54 -23
  86. package/lib/simple/Phone.js +233 -25
  87. package/lib/simple/Softphone.js +150 -0
  88. package/lib/simple/Websocket.js +13 -8
  89. package/lib/simple/index.js +233 -25
  90. package/lib/simple/room/LocalParticipant.js +233 -25
  91. package/lib/simple/room/Participant.js +233 -25
  92. package/lib/simple/room/RemoteParticipant.js +233 -25
  93. package/lib/simple/room/Room.js +233 -25
  94. package/lib/simple/room/SipRoom.js +233 -25
  95. package/lib/simple/room/Stream.js +233 -25
  96. package/lib/simple/room/__tests__/RemoteParticipant.test.js +233 -25
  97. package/lib/simple/utils.js +233 -25
  98. package/lib/utils/__tests__/api-requester.test.js +12 -7
  99. package/lib/utils/api-requester.js +12 -7
  100. package/lib/web-rtc-client.js +49 -24
  101. package/lib/websocket-client.js +13 -8
  102. package/package.json +1 -1
  103. package/src/api/auth.js +4 -1
  104. package/src/api-client.js +26 -13
  105. package/src/service/IssueReporter.js +12 -7
  106. package/src/service/__tests__/IssueReporter.test.js +6 -0
  107. package/src/service/getApiClient.js +19 -1
  108. package/src/simple/Auth.js +21 -0
  109. package/src/simple/Softphone.js +148 -0
  110. package/src/simple/index.js +2 -0
  111. package/src/web-rtc-client.js +4 -2
  112. package/src/websocket-client.js +1 -1
@@ -2430,13 +2430,9 @@ class IssueReporter {
2430
2430
 
2431
2431
  setTimeout(() => {
2432
2432
  if (isArray) {
2433
- payload = payload.map(message => {
2434
- message._retry = retry + 1;
2435
- return message;
2436
- });
2437
- } else {
2438
- // $FlowFixMe
2439
- payload._retry = retry + 1;
2433
+ payload = payload.map(message => this._writeRetryCount(message, retry + 1));
2434
+ } else if (payload && typeof payload === 'object') {
2435
+ payload = this._writeRetryCount(payload, retry + 1);
2440
2436
  }
2441
2437
 
2442
2438
  this._sendDebugToGrafana(payload, retry + 1);
@@ -2444,6 +2440,15 @@ class IssueReporter {
2444
2440
  });
2445
2441
  }
2446
2442
 
2443
+ _writeRetryCount(message , count ) {
2444
+ if (message && typeof message === 'object') {
2445
+ // $FlowFixMe
2446
+ message._retry = count;
2447
+ }
2448
+
2449
+ return message;
2450
+ }
2451
+
2447
2452
  _isLevelAbove(level1 , level2 ) {
2448
2453
  const index1 = LOG_LEVELS.indexOf(level1);
2449
2454
  const index2 = LOG_LEVELS.indexOf(level2);
@@ -2785,9 +2790,12 @@ var authMethods = (client , baseUrl ) => ({
2785
2790
  expiration: expiration || DETAULT_EXPIRATION,
2786
2791
  refresh_token: refreshToken,
2787
2792
  client_id: client.clientId,
2788
- tenant_id: tenantId,
2789
2793
  };
2790
2794
 
2795
+ if (tenantId) {
2796
+ body.tenant_id = tenantId;
2797
+ }
2798
+
2791
2799
  const headers = {
2792
2800
  'Content-Type': 'application/json',
2793
2801
  ...(isMobile ? { 'Wazo-Session-Type': 'mobile' } : {}),
@@ -4566,6 +4574,7 @@ class ApiClient {
4566
4574
 
4567
4575
 
4568
4576
 
4577
+
4569
4578
 
4570
4579
 
4571
4580
 
@@ -4618,23 +4627,31 @@ class ApiClient {
4618
4627
  return null;
4619
4628
  }
4620
4629
 
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 });
4630
+ try {
4631
+ const session = await this.auth.refreshToken(
4632
+ this.refreshToken,
4633
+ this.refreshBackend,
4634
+ this.refreshExpiration,
4635
+ this.isMobile,
4636
+ this.refreshTenantId,
4637
+ );
4638
+
4639
+ logger.info('token refreshed', { token: session.token });
4640
+
4641
+ if (this.onRefreshToken) {
4642
+ this.onRefreshToken(session.token, session);
4643
+ }
4630
4644
 
4631
- if (this.onRefreshToken) {
4632
- this.onRefreshToken(session.token, session);
4633
- }
4645
+ this.setToken(session.token);
4634
4646
 
4635
- this.setToken(session.token);
4647
+ return session.token;
4648
+ } catch (error) {
4649
+ logger.error('token refresh, error', error);
4636
4650
 
4637
- return session.token;
4651
+ if (this.onRefreshTokenError) {
4652
+ this.onRefreshTokenError(error);
4653
+ }
4654
+ }
4638
4655
  }
4639
4656
 
4640
4657
  setToken(token ) {
@@ -4657,6 +4674,10 @@ class ApiClient {
4657
4674
  this.onRefreshToken = onRefreshToken;
4658
4675
  }
4659
4676
 
4677
+ setOnRefreshTokenError(callback ) {
4678
+ this.onRefreshTokenError = callback;
4679
+ }
4680
+
4660
4681
  setRefreshExpiration(refreshExpiration ) {
4661
4682
  this.refreshExpiration = refreshExpiration;
4662
4683
  }
@@ -4692,7 +4713,9 @@ global.wazoClients = global.wazoClients || {};
4692
4713
  global.wazoClientId = global.wazoClientId || {};
4693
4714
  global.wazoClientToken = global.wazoClientToken || {};
4694
4715
  global.wazoRefreshToken = global.wazoRefreshToken || {};
4716
+ global.wazoRefreshTenantId = global.wazoRefreshTenantId || {};
4695
4717
  global.wazoOnRefreshToken = global.wazoOnRefreshToken || {};
4718
+ global.wazoOnRefreshTokenError = global.wazoOnRefreshTokenError || {};
4696
4719
  global.wazoRefreshExpiration = global.wazoRefreshExpiration || {};
4697
4720
  global.wazoRefreshBackend = global.wazoRefreshBackend || {};
4698
4721
  global.wazoIsMobile = global.wazoIsMobile || {};
@@ -4708,12 +4731,20 @@ const fillClient = (apiClient ) => {
4708
4731
 
4709
4732
  apiClient.setRefreshToken(global.wazoRefreshToken[server] || global.wazoRefreshToken[null] || apiClient.refreshToken);
4710
4733
 
4734
+ apiClient.setRefreshTenantId(
4735
+ global.wazoRefreshTenantId[server] || global.wazoRefreshTenantId[null] || apiClient.refreshTenantId,
4736
+ );
4737
+
4711
4738
  apiClient.setFetchOptions(global.wazoFetchOptions[server] || global.wazoFetchOptions[null] || apiClient.fetchOptions);
4712
4739
 
4713
4740
  apiClient.setOnRefreshToken(
4714
4741
  global.wazoOnRefreshToken[server] || global.wazoOnRefreshToken[null] || apiClient.onRefreshToken,
4715
4742
  );
4716
4743
 
4744
+ apiClient.setOnRefreshTokenError(
4745
+ global.wazoOnRefreshTokenError[server] || global.wazoOnRefreshTokenError[null] || apiClient.onRefreshTokenError,
4746
+ );
4747
+
4717
4748
  apiClient.setRefreshExpiration(
4718
4749
  global.wazoRefreshExpiration[server] || global.wazoRefreshExpiration[null] || apiClient.refreshExpiration,
4719
4750
  );
@@ -4727,7 +4758,7 @@ const fillClient = (apiClient ) => {
4727
4758
  return apiClient;
4728
4759
  };
4729
4760
 
4730
- var getApiClient = (forServer ) => {
4761
+ var getApiClient = (forServer = null) => {
4731
4762
  const server = forServer || global.wazoCurrentServer || '';
4732
4763
  if (server in global.wazoClients) {
4733
4764
  return fillClient(global.wazoClients[server]);
@@ -359,13 +359,9 @@ class IssueReporter {
359
359
 
360
360
  setTimeout(() => {
361
361
  if (isArray) {
362
- payload = payload.map(message => {
363
- message._retry = retry + 1;
364
- return message;
365
- });
366
- } else {
367
- // $FlowFixMe
368
- payload._retry = retry + 1;
362
+ payload = payload.map(message => this._writeRetryCount(message, retry + 1));
363
+ } else if (payload && typeof payload === 'object') {
364
+ payload = this._writeRetryCount(payload, retry + 1);
369
365
  }
370
366
 
371
367
  this._sendDebugToGrafana(payload, retry + 1);
@@ -373,6 +369,15 @@ class IssueReporter {
373
369
  });
374
370
  }
375
371
 
372
+ _writeRetryCount(message , count ) {
373
+ if (message && typeof message === 'object') {
374
+ // $FlowFixMe
375
+ message._retry = count;
376
+ }
377
+
378
+ return message;
379
+ }
380
+
376
381
  _isLevelAbove(level1 , level2 ) {
377
382
  const index1 = LOG_LEVELS.indexOf(level1);
378
383
  const index2 = LOG_LEVELS.indexOf(level2);
@@ -359,13 +359,9 @@ class IssueReporter {
359
359
 
360
360
  setTimeout(() => {
361
361
  if (isArray) {
362
- payload = payload.map(message => {
363
- message._retry = retry + 1;
364
- return message;
365
- });
366
- } else {
367
- // $FlowFixMe
368
- payload._retry = retry + 1;
362
+ payload = payload.map(message => this._writeRetryCount(message, retry + 1));
363
+ } else if (payload && typeof payload === 'object') {
364
+ payload = this._writeRetryCount(payload, retry + 1);
369
365
  }
370
366
 
371
367
  this._sendDebugToGrafana(payload, retry + 1);
@@ -373,6 +369,15 @@ class IssueReporter {
373
369
  });
374
370
  }
375
371
 
372
+ _writeRetryCount(message , count ) {
373
+ if (message && typeof message === 'object') {
374
+ // $FlowFixMe
375
+ message._retry = count;
376
+ }
377
+
378
+ return message;
379
+ }
380
+
376
381
  _isLevelAbove(level1 , level2 ) {
377
382
  const index1 = LOG_LEVELS.indexOf(level1);
378
383
  const index2 = LOG_LEVELS.indexOf(level2);
@@ -488,4 +493,10 @@ describe('IssueReporter', () => {
488
493
  expect(IssueReporter$1.removeSlashes('\"')).toBe("'");
489
494
  expect(IssueReporter$1.removeSlashes('\\\"')).toBe("'");
490
495
  });
496
+
497
+ it('Add retry count', () => {
498
+ expect(IssueReporter$1._writeRetryCount('', 1)).toBe('');
499
+ expect(IssueReporter$1._writeRetryCount('{}', 1)).toBe('{}');
500
+ expect(IssueReporter$1._writeRetryCount({}, 1)).toEqual({ _retry: 1 });
501
+ });
491
502
  });
@@ -396,13 +396,9 @@ class IssueReporter {
396
396
 
397
397
  setTimeout(() => {
398
398
  if (isArray) {
399
- payload = payload.map(message => {
400
- message._retry = retry + 1;
401
- return message;
402
- });
403
- } else {
404
- // $FlowFixMe
405
- payload._retry = retry + 1;
399
+ payload = payload.map(message => this._writeRetryCount(message, retry + 1));
400
+ } else if (payload && typeof payload === 'object') {
401
+ payload = this._writeRetryCount(payload, retry + 1);
406
402
  }
407
403
 
408
404
  this._sendDebugToGrafana(payload, retry + 1);
@@ -410,6 +406,15 @@ class IssueReporter {
410
406
  });
411
407
  }
412
408
 
409
+ _writeRetryCount(message , count ) {
410
+ if (message && typeof message === 'object') {
411
+ // $FlowFixMe
412
+ message._retry = count;
413
+ }
414
+
415
+ return message;
416
+ }
417
+
413
418
  _isLevelAbove(level1 , level2 ) {
414
419
  const index1 = LOG_LEVELS.indexOf(level1);
415
420
  const index2 = LOG_LEVELS.indexOf(level2);
@@ -2245,9 +2250,12 @@ var authMethods = (client , baseUrl ) => ({
2245
2250
  expiration: expiration || DETAULT_EXPIRATION,
2246
2251
  refresh_token: refreshToken,
2247
2252
  client_id: client.clientId,
2248
- tenant_id: tenantId,
2249
2253
  };
2250
2254
 
2255
+ if (tenantId) {
2256
+ body.tenant_id = tenantId;
2257
+ }
2258
+
2251
2259
  const headers = {
2252
2260
  'Content-Type': 'application/json',
2253
2261
  ...(isMobile ? { 'Wazo-Session-Type': 'mobile' } : {}),
@@ -4566,6 +4574,7 @@ class ApiClient {
4566
4574
 
4567
4575
 
4568
4576
 
4577
+
4569
4578
 
4570
4579
 
4571
4580
 
@@ -4618,23 +4627,31 @@ class ApiClient {
4618
4627
  return null;
4619
4628
  }
4620
4629
 
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 });
4630
+ try {
4631
+ const session = await this.auth.refreshToken(
4632
+ this.refreshToken,
4633
+ this.refreshBackend,
4634
+ this.refreshExpiration,
4635
+ this.isMobile,
4636
+ this.refreshTenantId,
4637
+ );
4638
+
4639
+ logger.info('token refreshed', { token: session.token });
4640
+
4641
+ if (this.onRefreshToken) {
4642
+ this.onRefreshToken(session.token, session);
4643
+ }
4630
4644
 
4631
- if (this.onRefreshToken) {
4632
- this.onRefreshToken(session.token, session);
4633
- }
4645
+ this.setToken(session.token);
4634
4646
 
4635
- this.setToken(session.token);
4647
+ return session.token;
4648
+ } catch (error) {
4649
+ logger.error('token refresh, error', error);
4636
4650
 
4637
- return session.token;
4651
+ if (this.onRefreshTokenError) {
4652
+ this.onRefreshTokenError(error);
4653
+ }
4654
+ }
4638
4655
  }
4639
4656
 
4640
4657
  setToken(token ) {
@@ -4657,6 +4674,10 @@ class ApiClient {
4657
4674
  this.onRefreshToken = onRefreshToken;
4658
4675
  }
4659
4676
 
4677
+ setOnRefreshTokenError(callback ) {
4678
+ this.onRefreshTokenError = callback;
4679
+ }
4680
+
4660
4681
  setRefreshExpiration(refreshExpiration ) {
4661
4682
  this.refreshExpiration = refreshExpiration;
4662
4683
  }
@@ -4692,7 +4713,9 @@ global.wazoClients = global.wazoClients || {};
4692
4713
  global.wazoClientId = global.wazoClientId || {};
4693
4714
  global.wazoClientToken = global.wazoClientToken || {};
4694
4715
  global.wazoRefreshToken = global.wazoRefreshToken || {};
4716
+ global.wazoRefreshTenantId = global.wazoRefreshTenantId || {};
4695
4717
  global.wazoOnRefreshToken = global.wazoOnRefreshToken || {};
4718
+ global.wazoOnRefreshTokenError = global.wazoOnRefreshTokenError || {};
4696
4719
  global.wazoRefreshExpiration = global.wazoRefreshExpiration || {};
4697
4720
  global.wazoRefreshBackend = global.wazoRefreshBackend || {};
4698
4721
  global.wazoIsMobile = global.wazoIsMobile || {};
@@ -4714,10 +4737,18 @@ const setRefreshToken = (newRefreshToken , forServer = null) =>
4714
4737
  global.wazoRefreshToken[forServer] = newRefreshToken;
4715
4738
  };
4716
4739
 
4740
+ const setRefreshTenantId = (refreshTenantId , forServer = null) => {
4741
+ global.wazoRefreshTenantId[forServer] = refreshTenantId;
4742
+ };
4743
+
4717
4744
  const setOnRefreshToken = (onRefreshToken , forServer = null) => {
4718
4745
  global.wazoOnRefreshToken[forServer] = onRefreshToken;
4719
4746
  };
4720
4747
 
4748
+ const setOnRefreshTokenError = (callback , forServer = null) => {
4749
+ global.wazoOnRefreshTokenError[forServer] = callback;
4750
+ };
4751
+
4721
4752
  const setRefreshExpiration = (refreshExpiration , forServer = null) => {
4722
4753
  global.wazoRefreshExpiration[forServer] = refreshExpiration;
4723
4754
  };
@@ -4744,12 +4775,20 @@ const fillClient = (apiClient ) => {
4744
4775
 
4745
4776
  apiClient.setRefreshToken(global.wazoRefreshToken[server] || global.wazoRefreshToken[null] || apiClient.refreshToken);
4746
4777
 
4778
+ apiClient.setRefreshTenantId(
4779
+ global.wazoRefreshTenantId[server] || global.wazoRefreshTenantId[null] || apiClient.refreshTenantId,
4780
+ );
4781
+
4747
4782
  apiClient.setFetchOptions(global.wazoFetchOptions[server] || global.wazoFetchOptions[null] || apiClient.fetchOptions);
4748
4783
 
4749
4784
  apiClient.setOnRefreshToken(
4750
4785
  global.wazoOnRefreshToken[server] || global.wazoOnRefreshToken[null] || apiClient.onRefreshToken,
4751
4786
  );
4752
4787
 
4788
+ apiClient.setOnRefreshTokenError(
4789
+ global.wazoOnRefreshTokenError[server] || global.wazoOnRefreshTokenError[null] || apiClient.onRefreshTokenError,
4790
+ );
4791
+
4753
4792
  apiClient.setRefreshExpiration(
4754
4793
  global.wazoRefreshExpiration[server] || global.wazoRefreshExpiration[null] || apiClient.refreshExpiration,
4755
4794
  );
@@ -4763,7 +4802,7 @@ const fillClient = (apiClient ) => {
4763
4802
  return apiClient;
4764
4803
  };
4765
4804
 
4766
- var getApiClient = (forServer ) => {
4805
+ var getApiClient = (forServer = null) => {
4767
4806
  const server = forServer || global.wazoCurrentServer || '';
4768
4807
  if (server in global.wazoClients) {
4769
4808
  return fillClient(global.wazoClients[server]);
@@ -4775,4 +4814,4 @@ var getApiClient = (forServer ) => {
4775
4814
  };
4776
4815
 
4777
4816
  export default getApiClient;
4778
- export { setApiClientId, setApiToken, setCurrentServer, setFetchOptions, setIsMobile, setOnRefreshToken, setRefreshBackend, setRefreshExpiration, setRefreshToken };
4817
+ export { setApiClientId, setApiToken, setCurrentServer, setFetchOptions, setIsMobile, setOnRefreshToken, setOnRefreshTokenError, setRefreshBackend, setRefreshExpiration, setRefreshTenantId, setRefreshToken };