@binance/common 1.0.6 → 1.1.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.
package/dist/index.d.mts CHANGED
@@ -943,7 +943,7 @@ interface WebsocketStream<T> {
943
943
  * @param event - Event name (currently supports "message").
944
944
  * @param callback - Callback function to handle incoming data.
945
945
  */
946
- on(event: 'message', callback: (data: T) => void): void;
946
+ on(event: 'message', callback: (data: T) => void | Promise<void>): void;
947
947
  /**
948
948
  * Unsubscribe from the stream and clean up resources.
949
949
  */
package/dist/index.d.ts CHANGED
@@ -943,7 +943,7 @@ interface WebsocketStream<T> {
943
943
  * @param event - Event name (currently supports "message").
944
944
  * @param callback - Callback function to handle incoming data.
945
945
  */
946
- on(event: 'message', callback: (data: T) => void): void;
946
+ on(event: 'message', callback: (data: T) => void | Promise<void>): void;
947
947
  /**
948
948
  * Unsubscribe from the stream and clean up resources.
949
949
  */
package/dist/index.js CHANGED
@@ -477,7 +477,7 @@ var httpRequestFunction = async function(axiosArgs, configuration) {
477
477
  };
478
478
  if (configuration?.keepAlive) {
479
479
  axiosRequestArgs.httpsAgent = new import_https.default.Agent({
480
- ...configuration?.httpsAgent instanceof import_https.default.Agent ? configuration.httpsAgent.options : {},
480
+ ...configuration?.baseOptions?.httpsAgent instanceof import_https.default.Agent ? configuration.baseOptions.httpsAgent.options : {},
481
481
  keepAlive: true
482
482
  });
483
483
  }
@@ -499,7 +499,13 @@ var httpRequestFunction = async function(axiosArgs, configuration) {
499
499
  });
500
500
  const rateLimits = parseRateLimitHeaders(response.headers);
501
501
  return {
502
- data: async () => JSON.parse(response.data),
502
+ data: async () => {
503
+ try {
504
+ return JSON.parse(response.data);
505
+ } catch (err) {
506
+ throw new Error(`Failed to parse JSON response: ${err}`);
507
+ }
508
+ },
503
509
  status: response.status,
504
510
  headers: response.headers,
505
511
  rateLimits
@@ -520,7 +526,11 @@ var httpRequestFunction = async function(axiosArgs, configuration) {
520
526
  let data = {};
521
527
  if (responseData && responseData !== null) {
522
528
  if (typeof responseData === "string" && responseData !== "")
523
- data = JSON.parse(responseData);
529
+ try {
530
+ data = JSON.parse(responseData);
531
+ } catch {
532
+ data = {};
533
+ }
524
534
  else if (typeof responseData === "object")
525
535
  data = responseData;
526
536
  }
@@ -1469,7 +1479,11 @@ function createStreamHandler(websocketBase, streamOrId, id) {
1469
1479
  return {
1470
1480
  on: (event, callback) => {
1471
1481
  if (event === "message") {
1472
- registeredCallback = (data) => callback(data);
1482
+ registeredCallback = (data) => {
1483
+ Promise.resolve(callback(data)).catch((err) => {
1484
+ websocketBase.logger.error(`Error in stream callback: ${err}`);
1485
+ });
1486
+ };
1473
1487
  const callbackSet = websocketBase.streamCallbackMap.get(streamOrId) ?? /* @__PURE__ */ new Set();
1474
1488
  callbackSet.add(registeredCallback);
1475
1489
  websocketBase.streamCallbackMap.set(streamOrId, callbackSet);