@wazo/sdk 0.39.13 → 0.39.15

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 +3 -3
  2. package/esm/api/amid.js +12 -4
  3. package/esm/api-client.js +3 -2
  4. package/esm/domain/Phone/WebRTCPhone.js +7 -0
  5. package/esm/service/IssueReporter.js +9 -1
  6. package/esm/simple/Auth.js +2 -3
  7. package/esm/simple/Phone.js +20 -16
  8. package/esm/simple/Websocket.js +2 -1
  9. package/esm/types/api/amid.d.ts.map +1 -1
  10. package/esm/types/api-client.d.ts.map +1 -1
  11. package/esm/types/domain/Phone/WebRTCPhone.d.ts.map +1 -1
  12. package/esm/types/index.d.ts +2 -0
  13. package/esm/types/index.d.ts.map +1 -1
  14. package/esm/types/service/IssueReporter.d.ts +1 -0
  15. package/esm/types/service/IssueReporter.d.ts.map +1 -1
  16. package/esm/types/simple/Auth.d.ts.map +1 -1
  17. package/esm/types/simple/Phone.d.ts.map +1 -1
  18. package/esm/types/simple/Websocket.d.ts.map +1 -1
  19. package/esm/types/simple/index.d.ts +1 -0
  20. package/esm/types/simple/index.d.ts.map +1 -1
  21. package/esm/types/utils/string.d.ts +1 -0
  22. package/esm/types/utils/string.d.ts.map +1 -1
  23. package/esm/types/web-rtc-client.d.ts +1 -0
  24. package/esm/types/web-rtc-client.d.ts.map +1 -1
  25. package/esm/types/websocket-client.d.ts.map +1 -1
  26. package/esm/utils/__tests__/string.test.js +26 -1
  27. package/esm/utils/string.js +6 -0
  28. package/esm/web-rtc-client.js +20 -2
  29. package/esm/websocket-client.js +10 -9
  30. package/lib/.DS_Store +0 -0
  31. package/lib/api/amid.js +12 -4
  32. package/lib/api-client.js +3 -2
  33. package/lib/domain/Phone/WebRTCPhone.js +7 -0
  34. package/lib/service/IssueReporter.js +9 -1
  35. package/lib/simple/Auth.js +2 -3
  36. package/lib/simple/Phone.js +20 -16
  37. package/lib/simple/Websocket.js +2 -1
  38. package/lib/types/api/amid.d.ts.map +1 -1
  39. package/lib/types/api-client.d.ts.map +1 -1
  40. package/lib/types/domain/Phone/WebRTCPhone.d.ts.map +1 -1
  41. package/lib/types/index.d.ts +2 -0
  42. package/lib/types/index.d.ts.map +1 -1
  43. package/lib/types/service/IssueReporter.d.ts +1 -0
  44. package/lib/types/service/IssueReporter.d.ts.map +1 -1
  45. package/lib/types/simple/Auth.d.ts.map +1 -1
  46. package/lib/types/simple/Phone.d.ts.map +1 -1
  47. package/lib/types/simple/Websocket.d.ts.map +1 -1
  48. package/lib/types/simple/index.d.ts +1 -0
  49. package/lib/types/simple/index.d.ts.map +1 -1
  50. package/lib/types/utils/string.d.ts +1 -0
  51. package/lib/types/utils/string.d.ts.map +1 -1
  52. package/lib/types/web-rtc-client.d.ts +1 -0
  53. package/lib/types/web-rtc-client.d.ts.map +1 -1
  54. package/lib/types/websocket-client.d.ts.map +1 -1
  55. package/lib/utils/__tests__/string.test.js +25 -0
  56. package/lib/utils/string.js +8 -1
  57. package/lib/web-rtc-client.js +22 -2
  58. package/lib/websocket-client.js +10 -9
  59. package/package.json +1 -1
  60. package/src/api/amid.ts +13 -4
  61. package/src/api-client.ts +3 -2
  62. package/src/domain/Phone/WebRTCPhone.ts +9 -0
  63. package/src/service/IssueReporter.ts +11 -1
  64. package/src/simple/Auth.ts +3 -3
  65. package/src/simple/Phone.ts +21 -16
  66. package/src/simple/Websocket.ts +2 -1
  67. package/src/utils/__tests__/string.test.ts +31 -1
  68. package/src/utils/string.ts +8 -0
  69. package/src/web-rtc-client.ts +24 -2
  70. package/src/websocket-client.ts +10 -9
@@ -180,8 +180,12 @@ class WebRTCClient extends Emitter_1.default {
180
180
  this.audio = media.audio;
181
181
  }
182
182
  createUserAgent(uaConfigOverrides) {
183
+ var _a;
183
184
  const uaOptions = this._createUaOptions(uaConfigOverrides);
184
- logger.info('sdk webrtc, creating UA', { uaOptions, clientId: this.clientId });
185
+ logger.info('sdk webrtc, creating UA', {
186
+ uaOptions: Object.assign(Object.assign({}, uaOptions), { authorizationPassword: `${(_a = uaOptions === null || uaOptions === void 0 ? void 0 : uaOptions.authorizationPassword) === null || _a === void 0 ? void 0 : _a.slice(0, 5)}xxxx` }),
187
+ clientId: this.clientId,
188
+ });
185
189
  uaOptions.delegate = {
186
190
  onConnect: this.onConnect.bind(this),
187
191
  onDisconnect: this.onDisconnect.bind(this),
@@ -319,7 +323,7 @@ class WebRTCClient extends Emitter_1.default {
319
323
  };
320
324
  return this._connectIfNeeded().then(() => {
321
325
  // Avoid race condition with the close method called just before register and setting userAgent to null
322
- // during the resolution of the primise.
326
+ // during the resolution of the promise.
323
327
  if (!this.userAgent) {
324
328
  logger.info('sdk webrtc recreating User Agent after connection');
325
329
  this.userAgent = this.createUserAgent(this.uaConfigOverrides);
@@ -1559,6 +1563,22 @@ class WebRTCClient extends Emitter_1.default {
1559
1563
  this.eventEmitter.emit(TRANSPORT_ERROR);
1560
1564
  this.attemptReconnection();
1561
1565
  }
1566
+ enableLogger(logConnector) {
1567
+ var _a;
1568
+ if (!this.userAgent) {
1569
+ return;
1570
+ }
1571
+ if ((_a = this.userAgent) === null || _a === void 0 ? void 0 : _a.transport) {
1572
+ // @ts-ignore
1573
+ this.userAgent.transport.configuration.traceSip = true;
1574
+ }
1575
+ // @ts-ignore
1576
+ this.userAgent.loggerFactory.builtinEnabled = true;
1577
+ // @ts-ignore
1578
+ this.userAgent.loggerFactory.level = 3; // debug
1579
+ // @ts-ignore
1580
+ this.userAgent.loggerFactory.connector = logConnector;
1581
+ }
1562
1582
  _onHeartbeat(message) {
1563
1583
  const body = message && typeof message === 'object' ? message.data : message;
1564
1584
  if (body && body.indexOf('200 OK') !== -1) {
@@ -19,6 +19,7 @@ const reconnecting_websocket_1 = __importDefault(require("reconnecting-websocket
19
19
  const Emitter_1 = __importDefault(require("./utils/Emitter"));
20
20
  const IssueReporter_1 = __importDefault(require("./service/IssueReporter"));
21
21
  const Heartbeat_1 = __importDefault(require("./utils/Heartbeat"));
22
+ const string_1 = require("./utils/string");
22
23
  exports.SOCKET_EVENTS = {
23
24
  ON_OPEN: 'onopen',
24
25
  ON_MESSAGE: 'onmessage',
@@ -136,7 +137,7 @@ class WebSocketClient extends Emitter_1.default {
136
137
  connect() {
137
138
  logger.info('connect method started', {
138
139
  host: this.host,
139
- token: this.token,
140
+ token: (0, string_1.obfuscateToken)(this.token),
140
141
  });
141
142
  this.socket = new reconnecting_websocket_1.default(this._getUrl.bind(this), [], this.options);
142
143
  if (this.options.binaryType) {
@@ -185,7 +186,7 @@ class WebSocketClient extends Emitter_1.default {
185
186
  code: event.code,
186
187
  readyState: event.target.readyState,
187
188
  host: this.host,
188
- token: this.token,
189
+ token: (0, string_1.obfuscateToken)(this.token),
189
190
  });
190
191
  this.initialized = false;
191
192
  this.eventEmitter.emit(exports.SOCKET_EVENTS.ON_CLOSE, event);
@@ -211,7 +212,7 @@ class WebSocketClient extends Emitter_1.default {
211
212
  logger.info('Wazo WS close', {
212
213
  socket: !!this.socket,
213
214
  host: this.host,
214
- token: this.token,
215
+ token: (0, string_1.obfuscateToken)(this.token),
215
216
  });
216
217
  if (!this.socket) {
217
218
  return;
@@ -228,7 +229,7 @@ class WebSocketClient extends Emitter_1.default {
228
229
  this.token = token;
229
230
  logger.info('Wazo WS updating token', {
230
231
  url: this._getUrl(),
231
- token,
232
+ token: (0, string_1.obfuscateToken)(token),
232
233
  socket: !!this.socket,
233
234
  });
234
235
  if (this.socket) {
@@ -252,7 +253,7 @@ class WebSocketClient extends Emitter_1.default {
252
253
  startHeartbeat() {
253
254
  logger.info('Wazo WS start heartbeat', {
254
255
  host: this.host,
255
- token: this.token,
256
+ token: (0, string_1.obfuscateToken)(this.token),
256
257
  });
257
258
  if (!this.socket) {
258
259
  this.heartbeat.stop();
@@ -265,7 +266,7 @@ class WebSocketClient extends Emitter_1.default {
265
266
  stopHeartbeat() {
266
267
  logger.info('Wazo WS stop heartbeat', {
267
268
  host: this.host,
268
- token: this.token,
269
+ token: (0, string_1.obfuscateToken)(this.token),
269
270
  });
270
271
  this.heartbeat.stop();
271
272
  }
@@ -298,7 +299,7 @@ class WebSocketClient extends Emitter_1.default {
298
299
  reason,
299
300
  socket: !!this.socket,
300
301
  host: this.host,
301
- token: this.token,
302
+ token: (0, string_1.obfuscateToken)(this.token),
302
303
  });
303
304
  if (!this.socket) {
304
305
  return;
@@ -358,7 +359,7 @@ class WebSocketClient extends Emitter_1.default {
358
359
  url += `&userUuid=${this.session.uuid}`;
359
360
  }
360
361
  logger.info('Wazo WS url computed to reconnect', {
361
- url,
362
+ url: url.replace(this.token, (0, string_1.obfuscateToken)(this.token)),
362
363
  });
363
364
  return url;
364
365
  }
@@ -372,7 +373,7 @@ class WebSocketClient extends Emitter_1.default {
372
373
  return __awaiter(this, void 0, void 0, function* () {
373
374
  logger.log('heartbeat timed out', {
374
375
  host: this.host,
375
- token: this.token,
376
+ token: (0, string_1.obfuscateToken)(this.token),
376
377
  });
377
378
  this.close();
378
379
  this.eventEmitter.emit(exports.SOCKET_EVENTS.ON_CLOSE, new Error('Websocket ping failure.'));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wazo/sdk",
3
- "version": "0.39.13",
3
+ "version": "0.39.15",
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/amid.ts CHANGED
@@ -8,9 +8,18 @@ export interface AmiD {
8
8
  export default ((client: ApiRequester, baseUrl: string): AmiD => ({
9
9
  action: (action: string, args: Record<string, any> = {}): Promise<string> => client.post(`${baseUrl}/action/${action}`, args),
10
10
  getAors: async (endpoint: string) => {
11
- const rawEvents = await client.post(`${baseUrl}/action/PJSIPShowEndpoint`, {
12
- Endpoint: endpoint,
13
- }) || [];
14
- return rawEvents.filter((event: Record<string, any>) => event.Event === 'ContactStatusDetail');
11
+ try {
12
+ const rawEvents = await client.post(`${baseUrl}/action/PJSIPShowEndpoint`, {
13
+ Endpoint: endpoint,
14
+ }) || [];
15
+
16
+ if (!rawEvents) {
17
+ return [];
18
+ }
19
+
20
+ return rawEvents.filter((event: Record<string, any>) => event.Event === 'ContactStatusDetail');
21
+ } catch {
22
+ return [];
23
+ }
15
24
  },
16
25
  }));
package/src/api-client.ts CHANGED
@@ -11,6 +11,7 @@ import webhookdMethods, { WebhookD } from './api/webhookd';
11
11
  import amidMethods, { AmiD } from './api/amid';
12
12
  import ApiRequester from './utils/api-requester';
13
13
  import IssueReporter from './service/IssueReporter';
14
+ import { obfuscateToken } from './utils/string';
14
15
 
15
16
  type ConstructorParams = {
16
17
  server: string;
@@ -132,7 +133,7 @@ export default class ApiClient {
132
133
 
133
134
  async refreshTokenCallback(): Promise<string | null> {
134
135
  logger.info('refresh token callback called', {
135
- refreshToken: this.refreshToken,
136
+ refreshToken: obfuscateToken(this.refreshToken),
136
137
  refreshBackend: this.refreshBackend,
137
138
  refreshTenantId: this.refreshTenantId,
138
139
  refreshDomainName: this.refreshDomainName,
@@ -151,7 +152,7 @@ export default class ApiClient {
151
152
  }
152
153
 
153
154
  logger.info('token refreshed', {
154
- token: session.token,
155
+ token: obfuscateToken(session.token),
155
156
  });
156
157
 
157
158
  if (this.onRefreshToken) {
@@ -594,6 +594,15 @@ export default class WebRTCPhone extends Emitter implements Phone {
594
594
 
595
595
  const callSession = this._createAcceptedCallSession(sipSession, cameraEnabled);
596
596
 
597
+ if (this.currentSipSession && !this.isCurrentCallSipSession(callSession)) {
598
+ logger.info('WebRTC phone - on call accepted with another ongoing call, holding it', {
599
+ sipId: sipSession.id,
600
+ cameraEnabled,
601
+ });
602
+
603
+ this.holdSipSession(this.currentSipSession, this.currentCallSession, true);
604
+ }
605
+
597
606
  this.currentSipSession = sipSession;
598
607
  this.currentCallSession = callSession;
599
608
  this.eventEmitter.emit(ON_TERMINATE_SOUND, callSession, 'call accepted');
@@ -4,6 +4,7 @@
4
4
  import moment from 'moment';
5
5
  import { realFetch } from '../utils/api-requester';
6
6
  import isMobile from '../utils/isMobile';
7
+ import { obfuscateToken } from '../utils/string';
7
8
 
8
9
  const TRACE = 'trace';
9
10
  const DEBUG = 'debug';
@@ -133,6 +134,15 @@ class IssueReporter {
133
134
  return str.replace(/"/g, "'").replace(/\\/g, '');
134
135
  }
135
136
 
137
+ obfuscateHeaderToken(headers: object): object {
138
+ const newHeaders: object = { ...headers };
139
+ if ('X-Auth-Token' in newHeaders) {
140
+ newHeaders['X-Auth-Token'] = obfuscateToken(newHeaders['X-Auth-Token'] as string);
141
+ }
142
+
143
+ return newHeaders;
144
+ }
145
+
136
146
  log(level: string, ...args: any) {
137
147
  if (!this.enabled) {
138
148
  return;
@@ -229,7 +239,7 @@ class IssueReporter {
229
239
  status,
230
240
  body: this.removeSlashes(JSON.stringify(options.body)),
231
241
  method: options.method,
232
- headers: options.headers,
242
+ headers: this.obfuscateHeaderToken(options.headers),
233
243
  duration,
234
244
  });
235
245
  }
@@ -18,6 +18,7 @@ import getApiClient, {
18
18
  import IssueReporter from '../service/IssueReporter';
19
19
  import Wazo from './index';
20
20
  import SipLine from '../domain/SipLine';
21
+ import { obfuscateToken } from '../utils/string';
21
22
 
22
23
  export class InvalidSubscription extends Error {}
23
24
  export class InvalidAuthorization extends Error {}
@@ -115,9 +116,8 @@ class Auth implements IAuth {
115
116
  setApiClientId(this.clientId);
116
117
  setRefreshExpiration(this.expiration);
117
118
  setOnRefreshToken((token: string, session: Session) => {
118
- logger.info('on refresh token done', {
119
- token,
120
- });
119
+ logger.info('on refresh token done', { token: obfuscateToken(token) });
120
+
121
121
  setApiToken(token);
122
122
  Wazo.Websocket.updateToken(token);
123
123
 
@@ -290,22 +290,7 @@ class Phone extends Emitter implements IPhone {
290
290
  options.log.builtinEnabled = false;
291
291
  options.log.logLevel = 'debug';
292
292
 
293
- options.log.connector = (level: any, className: string, label: any, content: string) => {
294
- const protocolIndex = content && content.indexOf ? protocolDebugMessages.findIndex(prefix => content.indexOf(prefix) !== -1) : -1;
295
-
296
- if (className === 'sip.Transport' && protocolIndex !== -1) {
297
- const direction = protocolIndex === 0 ? 'receiving' : 'sending';
298
- const message = content.replace(`${protocolDebugMessages[protocolIndex]}\n\n`, '').replace('\r\n', '\n');
299
- protocolLogger.trace(message, {
300
- className,
301
- direction,
302
- });
303
- } else {
304
- sipLogger.trace(content, {
305
- className,
306
- });
307
- }
308
- };
293
+ options.log.connector = this._logConnector;
309
294
  }
310
295
 
311
296
  this.client = new WazoWebRTCClient({
@@ -609,6 +594,10 @@ class Phone extends Emitter implements IPhone {
609
594
  }
610
595
  }
611
596
 
597
+ enableLogger(): void {
598
+ this.client.enableLogger(this._logConnector);
599
+ }
600
+
612
601
  _transferEvents() {
613
602
  this.unbind();
614
603
  [...clientEvents, ...transportEvents].forEach(event => {
@@ -623,6 +612,22 @@ class Phone extends Emitter implements IPhone {
623
612
  });
624
613
  }
625
614
 
615
+ _logConnector(level: any, className: string, label: any, content: string): void {
616
+ const protocolIndex = content && content.indexOf ? protocolDebugMessages.findIndex(prefix => content.indexOf(prefix) !== -1) : -1;
617
+
618
+ if (className === 'sip.Transport' && protocolIndex !== -1) {
619
+ const direction = protocolIndex === 0 ? 'receiving' : 'sending';
620
+ const message = content.replace(`${protocolDebugMessages[protocolIndex]}\n\n`, '').replace('\r\n', '\n');
621
+ protocolLogger.trace(message, {
622
+ className,
623
+ direction,
624
+ });
625
+ } else {
626
+ sipLogger.trace(content, {
627
+ className,
628
+ });
629
+ }
630
+ }
626
631
  }
627
632
 
628
633
  if (!global.wazoTelephonyInstance) {
@@ -2,6 +2,7 @@ import type Session from '../domain/Session';
2
2
  import WazoWebSocketClient, * as WebSocketClient from '../websocket-client';
3
3
  import Emitter, { IEmitter } from '../utils/Emitter';
4
4
  import IssueReporter from '../service/IssueReporter';
5
+ import { obfuscateToken } from '../utils/string';
5
6
 
6
7
  const {
7
8
  SOCKET_EVENTS,
@@ -59,7 +60,7 @@ class Websocket extends Emitter implements IWebsocket {
59
60
  open(host: string, session: Session) {
60
61
  logger.info('open simple WebSocket', {
61
62
  host,
62
- token: session.token,
63
+ token: obfuscateToken(session.token),
63
64
  });
64
65
  this.ws = new WazoWebSocketClient({
65
66
  host,
@@ -1,4 +1,4 @@
1
- import { camelToUnderscore } from '../string';
1
+ import { camelToUnderscore, obfuscateToken } from '../string';
2
2
 
3
3
  describe('string utils', () => {
4
4
  describe('camelToUnderscore', () => {
@@ -22,4 +22,34 @@ describe('string utils', () => {
22
22
  expect(camelToUnderscore('L123')).toEqual('l123');
23
23
  });
24
24
  });
25
+
26
+ describe('obfuscateToken', () => {
27
+ it('should return null when token is null', () => {
28
+ const result = obfuscateToken(null);
29
+ expect(result).toBeNull();
30
+ });
31
+
32
+ it('should return undefined when token is undefined', () => {
33
+ const result = obfuscateToken(undefined);
34
+ expect(result).toBeUndefined();
35
+ });
36
+
37
+ it('should obfuscate the token by replacing characters after the first part with "xxxxxx"', () => {
38
+ const token = '12345-67890-abcdef';
39
+ const result = obfuscateToken(token);
40
+ expect(result).toBe('12345-xxxxxx-xxxxxx');
41
+ });
42
+
43
+ it('should handle tokens with a single part', () => {
44
+ const token = 'singlepart';
45
+ const result = obfuscateToken(token);
46
+ expect(result).toBe('singlepart');
47
+ });
48
+
49
+ it('should handle tokens with two parts', () => {
50
+ const token = 'part1-part2';
51
+ const result = obfuscateToken(token);
52
+ expect(result).toBe('part1-xxxxxx');
53
+ });
54
+ });
25
55
  });
@@ -5,3 +5,11 @@ export const camelToUnderscore = (key: string): string => {
5
5
 
6
6
  return key.charAt(0).toLowerCase() + key.substring(1).replace(/([A-Z])/g, '_$1').toLowerCase();
7
7
  };
8
+
9
+ export const obfuscateToken = (token: string | null | undefined) => {
10
+ if (!token) {
11
+ return token;
12
+ }
13
+
14
+ return token.split('-').map((part, index) => (index === 0 ? part : 'xxxxxx')).join('-');
15
+ };
@@ -253,7 +253,11 @@ export default class WebRTCClient extends Emitter {
253
253
  createUserAgent(uaConfigOverrides?: UserAgentConfigOverrides): UserAgent {
254
254
  const uaOptions = this._createUaOptions(uaConfigOverrides);
255
255
 
256
- logger.info('sdk webrtc, creating UA', { uaOptions, clientId: this.clientId });
256
+ logger.info('sdk webrtc, creating UA', {
257
+ uaOptions: { ...uaOptions, authorizationPassword: `${uaOptions?.authorizationPassword?.slice(0, 5)}xxxx` },
258
+ clientId: this.clientId,
259
+ });
260
+
257
261
  uaOptions.delegate = {
258
262
  onConnect: this.onConnect.bind(this),
259
263
  onDisconnect: this.onDisconnect.bind(this),
@@ -412,7 +416,7 @@ export default class WebRTCClient extends Emitter {
412
416
 
413
417
  return this._connectIfNeeded().then(() => {
414
418
  // Avoid race condition with the close method called just before register and setting userAgent to null
415
- // during the resolution of the primise.
419
+ // during the resolution of the promise.
416
420
  if (!this.userAgent) {
417
421
  logger.info('sdk webrtc recreating User Agent after connection');
418
422
  this.userAgent = this.createUserAgent(this.uaConfigOverrides);
@@ -1874,6 +1878,24 @@ export default class WebRTCClient extends Emitter {
1874
1878
  this.attemptReconnection();
1875
1879
  }
1876
1880
 
1881
+ enableLogger(logConnector: (level: any, className: string, label: any, content: string) => void): void {
1882
+ if (!this.userAgent) {
1883
+ return;
1884
+ }
1885
+
1886
+ if (this.userAgent?.transport) {
1887
+ // @ts-ignore
1888
+ this.userAgent.transport.configuration.traceSip = true;
1889
+ }
1890
+
1891
+ // @ts-ignore
1892
+ this.userAgent.loggerFactory.builtinEnabled = true;
1893
+ // @ts-ignore
1894
+ this.userAgent.loggerFactory.level = 3; // debug
1895
+ // @ts-ignore
1896
+ this.userAgent.loggerFactory.connector = logConnector;
1897
+ }
1898
+
1877
1899
  _onHeartbeat(message: string | Record<string, any>): void {
1878
1900
  const body = message && typeof message === 'object' ? message.data : message;
1879
1901
 
@@ -6,6 +6,7 @@ import Emitter from './utils/Emitter';
6
6
  import type { WebSocketMessage } from './types/WebSocketMessage';
7
7
  import IssueReporter from './service/IssueReporter';
8
8
  import Heartbeat from './utils/Heartbeat';
9
+ import { obfuscateToken } from './utils/string';
9
10
 
10
11
  export const SOCKET_EVENTS = {
11
12
  ON_OPEN: 'onopen',
@@ -177,7 +178,7 @@ class WebSocketClient extends Emitter {
177
178
  connect() {
178
179
  logger.info('connect method started', {
179
180
  host: this.host,
180
- token: this.token,
181
+ token: obfuscateToken(this.token),
181
182
  });
182
183
  this.socket = new ReconnectingWebSocket(this._getUrl.bind(this), [], this.options);
183
184
 
@@ -234,7 +235,7 @@ class WebSocketClient extends Emitter {
234
235
  code: event.code,
235
236
  readyState: event.target.readyState,
236
237
  host: this.host,
237
- token: this.token,
238
+ token: obfuscateToken(this.token),
238
239
  });
239
240
  this.initialized = false;
240
241
  this.eventEmitter.emit(SOCKET_EVENTS.ON_CLOSE, event);
@@ -265,7 +266,7 @@ class WebSocketClient extends Emitter {
265
266
  logger.info('Wazo WS close', {
266
267
  socket: !!this.socket,
267
268
  host: this.host,
268
- token: this.token,
269
+ token: obfuscateToken(this.token),
269
270
  });
270
271
 
271
272
  if (!this.socket) {
@@ -286,7 +287,7 @@ class WebSocketClient extends Emitter {
286
287
  this.token = token;
287
288
  logger.info('Wazo WS updating token', {
288
289
  url: this._getUrl(),
289
- token,
290
+ token: obfuscateToken(token),
290
291
  socket: !!this.socket,
291
292
  });
292
293
 
@@ -312,7 +313,7 @@ class WebSocketClient extends Emitter {
312
313
  startHeartbeat() {
313
314
  logger.info('Wazo WS start heartbeat', {
314
315
  host: this.host,
315
- token: this.token,
316
+ token: obfuscateToken(this.token),
316
317
  });
317
318
 
318
319
  if (!this.socket) {
@@ -328,7 +329,7 @@ class WebSocketClient extends Emitter {
328
329
  stopHeartbeat() {
329
330
  logger.info('Wazo WS stop heartbeat', {
330
331
  host: this.host,
331
- token: this.token,
332
+ token: obfuscateToken(this.token),
332
333
  });
333
334
  this.heartbeat.stop();
334
335
  }
@@ -366,7 +367,7 @@ class WebSocketClient extends Emitter {
366
367
  reason,
367
368
  socket: !!this.socket,
368
369
  host: this.host,
369
- token: this.token,
370
+ token: obfuscateToken(this.token),
370
371
  });
371
372
 
372
373
  if (!this.socket) {
@@ -439,7 +440,7 @@ class WebSocketClient extends Emitter {
439
440
  }
440
441
 
441
442
  logger.info('Wazo WS url computed to reconnect', {
442
- url,
443
+ url: url.replace(this.token!, obfuscateToken(this.token) as string),
443
444
  });
444
445
  return url;
445
446
  }
@@ -454,7 +455,7 @@ class WebSocketClient extends Emitter {
454
455
  async _onHeartbeatTimeout() {
455
456
  logger.log('heartbeat timed out', {
456
457
  host: this.host,
457
- token: this.token,
458
+ token: obfuscateToken(this.token),
458
459
  });
459
460
  this.close();
460
461
  this.eventEmitter.emit(SOCKET_EVENTS.ON_CLOSE, new Error('Websocket ping failure.'));