@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
@@ -2436,13 +2436,9 @@ class IssueReporter {
2436
2436
 
2437
2437
  setTimeout(() => {
2438
2438
  if (isArray) {
2439
- payload = payload.map(message => {
2440
- message._retry = retry + 1;
2441
- return message;
2442
- });
2443
- } else {
2444
- // $FlowFixMe
2445
- payload._retry = retry + 1;
2439
+ payload = payload.map(message => this._writeRetryCount(message, retry + 1));
2440
+ } else if (payload && typeof payload === 'object') {
2441
+ payload = this._writeRetryCount(payload, retry + 1);
2446
2442
  }
2447
2443
 
2448
2444
  this._sendDebugToGrafana(payload, retry + 1);
@@ -2450,6 +2446,15 @@ class IssueReporter {
2450
2446
  });
2451
2447
  }
2452
2448
 
2449
+ _writeRetryCount(message , count ) {
2450
+ if (message && typeof message === 'object') {
2451
+ // $FlowFixMe
2452
+ message._retry = count;
2453
+ }
2454
+
2455
+ return message;
2456
+ }
2457
+
2453
2458
  _isLevelAbove(level1 , level2 ) {
2454
2459
  const index1 = LOG_LEVELS.indexOf(level1);
2455
2460
  const index2 = LOG_LEVELS.indexOf(level2);
@@ -2791,9 +2796,12 @@ var authMethods = (client , baseUrl ) => ({
2791
2796
  expiration: expiration || DETAULT_EXPIRATION,
2792
2797
  refresh_token: refreshToken,
2793
2798
  client_id: client.clientId,
2794
- tenant_id: tenantId,
2795
2799
  };
2796
2800
 
2801
+ if (tenantId) {
2802
+ body.tenant_id = tenantId;
2803
+ }
2804
+
2797
2805
  const headers = {
2798
2806
  'Content-Type': 'application/json',
2799
2807
  ...(isMobile ? { 'Wazo-Session-Type': 'mobile' } : {}),
@@ -4572,6 +4580,7 @@ class ApiClient {
4572
4580
 
4573
4581
 
4574
4582
 
4583
+
4575
4584
 
4576
4585
 
4577
4586
 
@@ -4624,23 +4633,31 @@ class ApiClient {
4624
4633
  return null;
4625
4634
  }
4626
4635
 
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 });
4636
+ try {
4637
+ const session = await this.auth.refreshToken(
4638
+ this.refreshToken,
4639
+ this.refreshBackend,
4640
+ this.refreshExpiration,
4641
+ this.isMobile,
4642
+ this.refreshTenantId,
4643
+ );
4644
+
4645
+ logger.info('token refreshed', { token: session.token });
4646
+
4647
+ if (this.onRefreshToken) {
4648
+ this.onRefreshToken(session.token, session);
4649
+ }
4636
4650
 
4637
- if (this.onRefreshToken) {
4638
- this.onRefreshToken(session.token, session);
4639
- }
4651
+ this.setToken(session.token);
4640
4652
 
4641
- this.setToken(session.token);
4653
+ return session.token;
4654
+ } catch (error) {
4655
+ logger.error('token refresh, error', error);
4642
4656
 
4643
- return session.token;
4657
+ if (this.onRefreshTokenError) {
4658
+ this.onRefreshTokenError(error);
4659
+ }
4660
+ }
4644
4661
  }
4645
4662
 
4646
4663
  setToken(token ) {
@@ -4663,6 +4680,10 @@ class ApiClient {
4663
4680
  this.onRefreshToken = onRefreshToken;
4664
4681
  }
4665
4682
 
4683
+ setOnRefreshTokenError(callback ) {
4684
+ this.onRefreshTokenError = callback;
4685
+ }
4686
+
4666
4687
  setRefreshExpiration(refreshExpiration ) {
4667
4688
  this.refreshExpiration = refreshExpiration;
4668
4689
  }
@@ -4698,7 +4719,9 @@ global.wazoClients = global.wazoClients || {};
4698
4719
  global.wazoClientId = global.wazoClientId || {};
4699
4720
  global.wazoClientToken = global.wazoClientToken || {};
4700
4721
  global.wazoRefreshToken = global.wazoRefreshToken || {};
4722
+ global.wazoRefreshTenantId = global.wazoRefreshTenantId || {};
4701
4723
  global.wazoOnRefreshToken = global.wazoOnRefreshToken || {};
4724
+ global.wazoOnRefreshTokenError = global.wazoOnRefreshTokenError || {};
4702
4725
  global.wazoRefreshExpiration = global.wazoRefreshExpiration || {};
4703
4726
  global.wazoRefreshBackend = global.wazoRefreshBackend || {};
4704
4727
  global.wazoIsMobile = global.wazoIsMobile || {};
@@ -4714,12 +4737,20 @@ const fillClient = (apiClient ) => {
4714
4737
 
4715
4738
  apiClient.setRefreshToken(global.wazoRefreshToken[server] || global.wazoRefreshToken[null] || apiClient.refreshToken);
4716
4739
 
4740
+ apiClient.setRefreshTenantId(
4741
+ global.wazoRefreshTenantId[server] || global.wazoRefreshTenantId[null] || apiClient.refreshTenantId,
4742
+ );
4743
+
4717
4744
  apiClient.setFetchOptions(global.wazoFetchOptions[server] || global.wazoFetchOptions[null] || apiClient.fetchOptions);
4718
4745
 
4719
4746
  apiClient.setOnRefreshToken(
4720
4747
  global.wazoOnRefreshToken[server] || global.wazoOnRefreshToken[null] || apiClient.onRefreshToken,
4721
4748
  );
4722
4749
 
4750
+ apiClient.setOnRefreshTokenError(
4751
+ global.wazoOnRefreshTokenError[server] || global.wazoOnRefreshTokenError[null] || apiClient.onRefreshTokenError,
4752
+ );
4753
+
4723
4754
  apiClient.setRefreshExpiration(
4724
4755
  global.wazoRefreshExpiration[server] || global.wazoRefreshExpiration[null] || apiClient.refreshExpiration,
4725
4756
  );
@@ -4733,7 +4764,7 @@ const fillClient = (apiClient ) => {
4733
4764
  return apiClient;
4734
4765
  };
4735
4766
 
4736
- var getApiClient = (forServer ) => {
4767
+ var getApiClient = (forServer = null) => {
4737
4768
  const server = forServer || global.wazoCurrentServer || '';
4738
4769
  if (server in global.wazoClients) {
4739
4770
  return fillClient(global.wazoClients[server]);
@@ -365,13 +365,9 @@ class IssueReporter {
365
365
 
366
366
  setTimeout(() => {
367
367
  if (isArray) {
368
- payload = payload.map(message => {
369
- message._retry = retry + 1;
370
- return message;
371
- });
372
- } else {
373
- // $FlowFixMe
374
- payload._retry = retry + 1;
368
+ payload = payload.map(message => this._writeRetryCount(message, retry + 1));
369
+ } else if (payload && typeof payload === 'object') {
370
+ payload = this._writeRetryCount(payload, retry + 1);
375
371
  }
376
372
 
377
373
  this._sendDebugToGrafana(payload, retry + 1);
@@ -379,6 +375,15 @@ class IssueReporter {
379
375
  });
380
376
  }
381
377
 
378
+ _writeRetryCount(message , count ) {
379
+ if (message && typeof message === 'object') {
380
+ // $FlowFixMe
381
+ message._retry = count;
382
+ }
383
+
384
+ return message;
385
+ }
386
+
382
387
  _isLevelAbove(level1 , level2 ) {
383
388
  const index1 = LOG_LEVELS.indexOf(level1);
384
389
  const index2 = LOG_LEVELS.indexOf(level2);
@@ -365,13 +365,9 @@ class IssueReporter {
365
365
 
366
366
  setTimeout(() => {
367
367
  if (isArray) {
368
- payload = payload.map(message => {
369
- message._retry = retry + 1;
370
- return message;
371
- });
372
- } else {
373
- // $FlowFixMe
374
- payload._retry = retry + 1;
368
+ payload = payload.map(message => this._writeRetryCount(message, retry + 1));
369
+ } else if (payload && typeof payload === 'object') {
370
+ payload = this._writeRetryCount(payload, retry + 1);
375
371
  }
376
372
 
377
373
  this._sendDebugToGrafana(payload, retry + 1);
@@ -379,6 +375,15 @@ class IssueReporter {
379
375
  });
380
376
  }
381
377
 
378
+ _writeRetryCount(message , count ) {
379
+ if (message && typeof message === 'object') {
380
+ // $FlowFixMe
381
+ message._retry = count;
382
+ }
383
+
384
+ return message;
385
+ }
386
+
382
387
  _isLevelAbove(level1 , level2 ) {
383
388
  const index1 = LOG_LEVELS.indexOf(level1);
384
389
  const index2 = LOG_LEVELS.indexOf(level2);
@@ -494,4 +499,10 @@ describe('IssueReporter', () => {
494
499
  expect(IssueReporter$1.removeSlashes('\"')).toBe("'");
495
500
  expect(IssueReporter$1.removeSlashes('\\\"')).toBe("'");
496
501
  });
502
+
503
+ it('Add retry count', () => {
504
+ expect(IssueReporter$1._writeRetryCount('', 1)).toBe('');
505
+ expect(IssueReporter$1._writeRetryCount('{}', 1)).toBe('{}');
506
+ expect(IssueReporter$1._writeRetryCount({}, 1)).toEqual({ _retry: 1 });
507
+ });
497
508
  });
@@ -404,13 +404,9 @@ class IssueReporter {
404
404
 
405
405
  setTimeout(() => {
406
406
  if (isArray) {
407
- payload = payload.map(message => {
408
- message._retry = retry + 1;
409
- return message;
410
- });
411
- } else {
412
- // $FlowFixMe
413
- payload._retry = retry + 1;
407
+ payload = payload.map(message => this._writeRetryCount(message, retry + 1));
408
+ } else if (payload && typeof payload === 'object') {
409
+ payload = this._writeRetryCount(payload, retry + 1);
414
410
  }
415
411
 
416
412
  this._sendDebugToGrafana(payload, retry + 1);
@@ -418,6 +414,15 @@ class IssueReporter {
418
414
  });
419
415
  }
420
416
 
417
+ _writeRetryCount(message , count ) {
418
+ if (message && typeof message === 'object') {
419
+ // $FlowFixMe
420
+ message._retry = count;
421
+ }
422
+
423
+ return message;
424
+ }
425
+
421
426
  _isLevelAbove(level1 , level2 ) {
422
427
  const index1 = LOG_LEVELS.indexOf(level1);
423
428
  const index2 = LOG_LEVELS.indexOf(level2);
@@ -2253,9 +2258,12 @@ var authMethods = (client , baseUrl ) => ({
2253
2258
  expiration: expiration || DETAULT_EXPIRATION,
2254
2259
  refresh_token: refreshToken,
2255
2260
  client_id: client.clientId,
2256
- tenant_id: tenantId,
2257
2261
  };
2258
2262
 
2263
+ if (tenantId) {
2264
+ body.tenant_id = tenantId;
2265
+ }
2266
+
2259
2267
  const headers = {
2260
2268
  'Content-Type': 'application/json',
2261
2269
  ...(isMobile ? { 'Wazo-Session-Type': 'mobile' } : {}),
@@ -4574,6 +4582,7 @@ class ApiClient {
4574
4582
 
4575
4583
 
4576
4584
 
4585
+
4577
4586
 
4578
4587
 
4579
4588
 
@@ -4626,23 +4635,31 @@ class ApiClient {
4626
4635
  return null;
4627
4636
  }
4628
4637
 
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 });
4638
+ try {
4639
+ const session = await this.auth.refreshToken(
4640
+ this.refreshToken,
4641
+ this.refreshBackend,
4642
+ this.refreshExpiration,
4643
+ this.isMobile,
4644
+ this.refreshTenantId,
4645
+ );
4646
+
4647
+ logger.info('token refreshed', { token: session.token });
4648
+
4649
+ if (this.onRefreshToken) {
4650
+ this.onRefreshToken(session.token, session);
4651
+ }
4638
4652
 
4639
- if (this.onRefreshToken) {
4640
- this.onRefreshToken(session.token, session);
4641
- }
4653
+ this.setToken(session.token);
4642
4654
 
4643
- this.setToken(session.token);
4655
+ return session.token;
4656
+ } catch (error) {
4657
+ logger.error('token refresh, error', error);
4644
4658
 
4645
- return session.token;
4659
+ if (this.onRefreshTokenError) {
4660
+ this.onRefreshTokenError(error);
4661
+ }
4662
+ }
4646
4663
  }
4647
4664
 
4648
4665
  setToken(token ) {
@@ -4665,6 +4682,10 @@ class ApiClient {
4665
4682
  this.onRefreshToken = onRefreshToken;
4666
4683
  }
4667
4684
 
4685
+ setOnRefreshTokenError(callback ) {
4686
+ this.onRefreshTokenError = callback;
4687
+ }
4688
+
4668
4689
  setRefreshExpiration(refreshExpiration ) {
4669
4690
  this.refreshExpiration = refreshExpiration;
4670
4691
  }
@@ -4700,7 +4721,9 @@ global.wazoClients = global.wazoClients || {};
4700
4721
  global.wazoClientId = global.wazoClientId || {};
4701
4722
  global.wazoClientToken = global.wazoClientToken || {};
4702
4723
  global.wazoRefreshToken = global.wazoRefreshToken || {};
4724
+ global.wazoRefreshTenantId = global.wazoRefreshTenantId || {};
4703
4725
  global.wazoOnRefreshToken = global.wazoOnRefreshToken || {};
4726
+ global.wazoOnRefreshTokenError = global.wazoOnRefreshTokenError || {};
4704
4727
  global.wazoRefreshExpiration = global.wazoRefreshExpiration || {};
4705
4728
  global.wazoRefreshBackend = global.wazoRefreshBackend || {};
4706
4729
  global.wazoIsMobile = global.wazoIsMobile || {};
@@ -4722,10 +4745,18 @@ const setRefreshToken = (newRefreshToken , forServer = null) =>
4722
4745
  global.wazoRefreshToken[forServer] = newRefreshToken;
4723
4746
  };
4724
4747
 
4748
+ const setRefreshTenantId = (refreshTenantId , forServer = null) => {
4749
+ global.wazoRefreshTenantId[forServer] = refreshTenantId;
4750
+ };
4751
+
4725
4752
  const setOnRefreshToken = (onRefreshToken , forServer = null) => {
4726
4753
  global.wazoOnRefreshToken[forServer] = onRefreshToken;
4727
4754
  };
4728
4755
 
4756
+ const setOnRefreshTokenError = (callback , forServer = null) => {
4757
+ global.wazoOnRefreshTokenError[forServer] = callback;
4758
+ };
4759
+
4729
4760
  const setRefreshExpiration = (refreshExpiration , forServer = null) => {
4730
4761
  global.wazoRefreshExpiration[forServer] = refreshExpiration;
4731
4762
  };
@@ -4752,12 +4783,20 @@ const fillClient = (apiClient ) => {
4752
4783
 
4753
4784
  apiClient.setRefreshToken(global.wazoRefreshToken[server] || global.wazoRefreshToken[null] || apiClient.refreshToken);
4754
4785
 
4786
+ apiClient.setRefreshTenantId(
4787
+ global.wazoRefreshTenantId[server] || global.wazoRefreshTenantId[null] || apiClient.refreshTenantId,
4788
+ );
4789
+
4755
4790
  apiClient.setFetchOptions(global.wazoFetchOptions[server] || global.wazoFetchOptions[null] || apiClient.fetchOptions);
4756
4791
 
4757
4792
  apiClient.setOnRefreshToken(
4758
4793
  global.wazoOnRefreshToken[server] || global.wazoOnRefreshToken[null] || apiClient.onRefreshToken,
4759
4794
  );
4760
4795
 
4796
+ apiClient.setOnRefreshTokenError(
4797
+ global.wazoOnRefreshTokenError[server] || global.wazoOnRefreshTokenError[null] || apiClient.onRefreshTokenError,
4798
+ );
4799
+
4761
4800
  apiClient.setRefreshExpiration(
4762
4801
  global.wazoRefreshExpiration[server] || global.wazoRefreshExpiration[null] || apiClient.refreshExpiration,
4763
4802
  );
@@ -4771,7 +4810,7 @@ const fillClient = (apiClient ) => {
4771
4810
  return apiClient;
4772
4811
  };
4773
4812
 
4774
- var getApiClient = (forServer ) => {
4813
+ var getApiClient = (forServer = null) => {
4775
4814
  const server = forServer || global.wazoCurrentServer || '';
4776
4815
  if (server in global.wazoClients) {
4777
4816
  return fillClient(global.wazoClients[server]);
@@ -4789,6 +4828,8 @@ exports.setCurrentServer = setCurrentServer;
4789
4828
  exports.setFetchOptions = setFetchOptions;
4790
4829
  exports.setIsMobile = setIsMobile;
4791
4830
  exports.setOnRefreshToken = setOnRefreshToken;
4831
+ exports.setOnRefreshTokenError = setOnRefreshTokenError;
4792
4832
  exports.setRefreshBackend = setRefreshBackend;
4793
4833
  exports.setRefreshExpiration = setRefreshExpiration;
4834
+ exports.setRefreshTenantId = setRefreshTenantId;
4794
4835
  exports.setRefreshToken = setRefreshToken;