starknet 10.6.4 → 10.6.6

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.js CHANGED
@@ -7614,7 +7614,7 @@ var WebSocketChannel = class {
7614
7614
  this.websocket.addEventListener("error", this.errorListener);
7615
7615
  }
7616
7616
  idResolver(id) {
7617
- if (id) return id;
7617
+ if (id !== void 0) return id;
7618
7618
  return this.sendId++;
7619
7619
  }
7620
7620
  /**
@@ -7672,7 +7672,15 @@ var WebSocketChannel = class {
7672
7672
  logger.warn("WebSocket received non-string message data:", event.data);
7673
7673
  return;
7674
7674
  }
7675
- const message = JSON.parse(event.data);
7675
+ let message;
7676
+ try {
7677
+ message = JSON.parse(event.data);
7678
+ } catch (error) {
7679
+ logger.error(
7680
+ `WebSocketChannel: Error parsing incoming message: ${event.data}, Error: ${error}`
7681
+ );
7682
+ return;
7683
+ }
7676
7684
  if (message.id === sendId) {
7677
7685
  clearTimeout(timeoutId);
7678
7686
  this.websocket.removeEventListener("message", messageHandler);
@@ -7755,6 +7763,8 @@ var WebSocketChannel = class {
7755
7763
  this.reconnectStabilityTimeoutId = null;
7756
7764
  }
7757
7765
  this.userInitiatedClose = true;
7766
+ this.isReconnecting = false;
7767
+ this._rejectRequestQueue("the connection was closed by the user");
7758
7768
  this.websocket.close(code, reason);
7759
7769
  }
7760
7770
  /**
@@ -7828,6 +7838,24 @@ var WebSocketChannel = class {
7828
7838
  this.sendReceive(method, params).then(resolve).catch(reject);
7829
7839
  });
7830
7840
  }
7841
+ /**
7842
+ * Reject every request still waiting in the queue.
7843
+ *
7844
+ * A queued request carries no timeout of its own: the `requestTimeout` timer is only
7845
+ * armed once the request is actually put on the wire. So once the channel reaches a state
7846
+ * where the queue can never be flushed — reconnection gave up, or the user closed the
7847
+ * connection — the queued promises would stay pending forever, and no caller-side timeout
7848
+ * could rescue them. Settling them here is the only way out.
7849
+ */
7850
+ _rejectRequestQueue(reason) {
7851
+ if (this.requestQueue.length === 0) return;
7852
+ const pending = this.requestQueue;
7853
+ this.requestQueue = [];
7854
+ logger.info(`WebSocket: Rejecting ${pending.length} queued request(s). Reason: ${reason}.`);
7855
+ pending.forEach(({ method, reject }) => {
7856
+ reject(new WebSocketNotConnectedError(`Request ${method} was never sent: ${reason}`));
7857
+ });
7858
+ }
7831
7859
  async _restoreSubscriptions() {
7832
7860
  const oldSubscriptions = Array.from(this.activeSubscriptions.values());
7833
7861
  this.activeSubscriptions.clear();
@@ -7871,6 +7899,9 @@ var WebSocketChannel = class {
7871
7899
  if (this.reconnectAttempts >= this.reconnectOptions.retries) {
7872
7900
  logger.error("WebSocket: Maximum reconnection retries reached. Giving up.");
7873
7901
  this.isReconnecting = false;
7902
+ this._rejectRequestQueue(
7903
+ `reconnection gave up after ${this.reconnectOptions.retries} attempts`
7904
+ );
7874
7905
  return;
7875
7906
  }
7876
7907
  this.reconnectAttempts += 1;