@binance/common 1.2.0 → 1.2.1

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.
package/dist/index.mjs CHANGED
@@ -816,12 +816,16 @@ var WebsocketCommon = class _WebsocketCommon extends WebsocketEventEmitter {
816
816
  */
817
817
  async closeConnectionGracefully(WebsocketConnectionToClose, connection) {
818
818
  if (!WebsocketConnectionToClose || !connection) return;
819
- this.logger.debug("Waiting for pending requests to complete before disconnecting.");
819
+ this.logger.debug(
820
+ `Waiting for pending requests to complete before disconnecting websocket on connection ${connection.id}.`
821
+ );
820
822
  const closePromise = new Promise((resolve) => {
821
823
  this.scheduleTimer(
822
824
  WebsocketConnectionToClose,
823
825
  () => {
824
- this.logger.warn("Force-closing connection after 30 seconds.");
826
+ this.logger.warn(
827
+ `Force-closing websocket connection after 30 seconds on connection ${connection.id}.`
828
+ );
825
829
  resolve();
826
830
  },
827
831
  3e4
@@ -830,7 +834,9 @@ var WebsocketCommon = class _WebsocketCommon extends WebsocketEventEmitter {
830
834
  WebsocketConnectionToClose,
831
835
  () => {
832
836
  if (connection.pendingRequests.size === 0) {
833
- this.logger.debug("All pending requests completed, closing connection.");
837
+ this.logger.debug(
838
+ `All pending requests completed, closing websocket connection on connection ${connection.id}.`
839
+ );
834
840
  resolve();
835
841
  }
836
842
  },
@@ -839,7 +845,7 @@ var WebsocketCommon = class _WebsocketCommon extends WebsocketEventEmitter {
839
845
  );
840
846
  });
841
847
  await closePromise;
842
- this.logger.info("Closing Websocket connection.");
848
+ this.logger.info(`Closing Websocket connection on connection ${connection.id}.`);
843
849
  WebsocketConnectionToClose.close();
844
850
  this.cleanup(WebsocketConnectionToClose);
845
851
  }
@@ -859,7 +865,7 @@ var WebsocketCommon = class _WebsocketCommon extends WebsocketEventEmitter {
859
865
  req.payload,
860
866
  req.options
861
867
  );
862
- this.logger.debug(`Session re-logon with connection id: ${connection.id}`, data);
868
+ this.logger.debug(`Session re-logon on connection ${connection.id}`, data);
863
869
  try {
864
870
  await this.send(
865
871
  JSON.stringify(data),
@@ -868,12 +874,12 @@ var WebsocketCommon = class _WebsocketCommon extends WebsocketEventEmitter {
868
874
  this.configuration.timeout,
869
875
  connection
870
876
  );
877
+ this.logger.debug(
878
+ `Session re-logon on connection ${connection.id} was successful.`
879
+ );
871
880
  connection.isSessionLoggedOn = true;
872
881
  } catch (err) {
873
- this.logger.error(
874
- `Session re-logon with connection id ${connection.id} failed:`,
875
- err
876
- );
882
+ this.logger.error(`Session re-logon on connection ${connection.id} failed:`, err);
877
883
  }
878
884
  }
879
885
  }
@@ -1237,8 +1243,9 @@ var WebsocketAPIBase = class extends WebsocketCommon {
1237
1243
  if (!this.isConnected()) {
1238
1244
  throw new Error("Not connected");
1239
1245
  }
1240
- const connections = options.isSessionLogon || options.isSessionLogout ? this.getAvailableConnections() : [this.getConnection()];
1241
- const skipAuth = options.isSessionLogon || options.isSessionLogout ? false : this.configuration.autoSessionReLogon && connections[0].isSessionLoggedOn;
1246
+ const isSessionReq = options.isSessionLogon || options.isSessionLogout;
1247
+ const connections = isSessionReq ? this.getAvailableConnections() : [this.getConnection()];
1248
+ const skipAuth = isSessionReq ? false : this.configuration.autoSessionReLogon && connections[0].isSessionLoggedOn;
1242
1249
  const data = buildWebsocketAPIMessage(
1243
1250
  this.configuration,
1244
1251
  method,
@@ -1258,7 +1265,7 @@ var WebsocketAPIBase = class extends WebsocketCommon {
1258
1265
  )
1259
1266
  )
1260
1267
  );
1261
- if ((options.isSessionLogon || options.isSessionLogout) && this.configuration.autoSessionReLogon) {
1268
+ if (isSessionReq && this.configuration.autoSessionReLogon) {
1262
1269
  connections.forEach((connection) => {
1263
1270
  if (options.isSessionLogon) {
1264
1271
  connection.isSessionLoggedOn = true;
@@ -1269,7 +1276,7 @@ var WebsocketAPIBase = class extends WebsocketCommon {
1269
1276
  }
1270
1277
  });
1271
1278
  }
1272
- return connections.length === 1 ? responses[0] : responses;
1279
+ return connections.length === 1 && !isSessionReq ? responses[0] : responses;
1273
1280
  }
1274
1281
  };
1275
1282
  var WebsocketStreamsBase = class extends WebsocketCommon {
@@ -1432,7 +1439,7 @@ var WebsocketStreamsBase = class extends WebsocketCommon {
1432
1439
  connectionStreamMap.forEach((streams2, connection) => {
1433
1440
  if (!this.isConnected(connection)) {
1434
1441
  this.logger.info(
1435
- `Connection is not ready. Queuing subscription for streams: ${streams2}`
1442
+ `Connection ${connection.id} is not ready. Queuing subscription for streams: ${streams2}`
1436
1443
  );
1437
1444
  connection.pendingSubscriptions?.push(...streams2);
1438
1445
  return;