@phpsandbox/sdk 0.0.18 → 0.0.20

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.
@@ -2962,6 +2962,7 @@ var Transport = class {
2962
2962
  this.closed = false;
2963
2963
  this.disposables = new NamedDisposable();
2964
2964
  this.connectPromise = null;
2965
+ this.pingIntervalStarted = false;
2965
2966
  // Connection health monitoring
2966
2967
  this.connectionStats = {
2967
2968
  connectTime: 0,
@@ -3040,7 +3041,25 @@ var Transport = class {
3040
3041
  throw new Error("Unexpected message type: " + typeof ev.data);
3041
3042
  }
3042
3043
  ev.data.arrayBuffer().then((buffer) => {
3043
- this.handleRawMessage(decode(buffer));
3044
+ if (buffer.byteLength === 0) {
3045
+ this.log("warn", "Ignoring empty WebSocket frame");
3046
+ return;
3047
+ }
3048
+ try {
3049
+ this.handleRawMessage(decode(buffer));
3050
+ } catch (error) {
3051
+ this.connectionStats.totalErrors++;
3052
+ this.log("error", "Failed to decode WebSocket frame", {
3053
+ error: error instanceof Error ? error.message : String(error),
3054
+ byteLength: buffer.byteLength
3055
+ });
3056
+ this.eventEmitter.emit("transport.error", {
3057
+ type: "message_decode_error",
3058
+ error,
3059
+ rawMessage: buffer,
3060
+ timestamp: Date.now()
3061
+ });
3062
+ }
3044
3063
  });
3045
3064
  };
3046
3065
  this.rws.addEventListener("message", onMessage);
@@ -3685,6 +3704,10 @@ connect_fn = function() {
3685
3704
  return this.connectPromise;
3686
3705
  };
3687
3706
  startPeriodicPing_fn = function() {
3707
+ if (this.pingIntervalStarted || this.closed) {
3708
+ return;
3709
+ }
3710
+ this.pingIntervalStarted = true;
3688
3711
  this.disposables.add("pingInterval", () => {
3689
3712
  const interval = setInterval(async () => {
3690
3713
  try {
@@ -3708,6 +3731,7 @@ startPeriodicPing_fn = function() {
3708
3731
  return {
3709
3732
  dispose: () => {
3710
3733
  clearInterval(interval);
3734
+ this.pingIntervalStarted = false;
3711
3735
  }
3712
3736
  };
3713
3737
  });
@@ -4524,9 +4548,11 @@ function isBeaconSupported() {
4524
4548
 
4525
4549
  // src/index.ts
4526
4550
  var NotebookInitError = class extends Error {
4527
- constructor(message) {
4551
+ constructor(message, data = {}) {
4528
4552
  super(message);
4529
4553
  this.message = message;
4554
+ this.data = data;
4555
+ this.name = "NotebookInitError";
4530
4556
  }
4531
4557
  };
4532
4558
  var ApiError = class extends Error {
@@ -4553,6 +4579,10 @@ var NotebookApi = class {
4553
4579
  const response = await this.client.get(`/notebook/${id}`);
4554
4580
  return new NotebookInstance(response.data, this.client);
4555
4581
  }
4582
+ async update(id, input = {}) {
4583
+ const response = await this.client.put(`/notebook/${id}`, input);
4584
+ return new NotebookInstance(response.data, this.client);
4585
+ }
4556
4586
  async delete(id) {
4557
4587
  await this.client.delete(`/notebook/${id}`);
4558
4588
  }
@@ -4596,6 +4626,9 @@ var Client = class {
4596
4626
  delete(path) {
4597
4627
  return this.makeRequest("DELETE", path);
4598
4628
  }
4629
+ put(path, body) {
4630
+ return this.makeRequest("PUT", path, { body: body ? JSON.stringify(body) : void 0 });
4631
+ }
4599
4632
  async makeRequest(method, path, init) {
4600
4633
  const response = await this.fetch(
4601
4634
  new Request(new URL(`v1/${path.replace(/^\//, "")}`, this.baseUrl), {
@@ -4668,7 +4701,9 @@ var NotebookInstance = class {
4668
4701
  return this.invoke("ping");
4669
4702
  }
4670
4703
  listen(event, handler) {
4671
- return this.emitter.listen(event, handler);
4704
+ const disposable = this.emitter.listen(event, handler);
4705
+ this.disposables.push(disposable);
4706
+ return disposable;
4672
4707
  }
4673
4708
  dispose() {
4674
4709
  this.disposables.forEach((d) => d.dispose());
@@ -4726,9 +4761,7 @@ var NotebookInstance = class {
4726
4761
  return this.invoke("notebook.update");
4727
4762
  }
4728
4763
  onDidInitialize(handler) {
4729
- const disposable = this.listen("notebook.initialized", handler);
4730
- this.disposables.push(disposable);
4731
- return disposable;
4764
+ return this.listen("notebook.initialized", handler);
4732
4765
  }
4733
4766
  async reconnect() {
4734
4767
  const whenConnected = this.whenConnected();
@@ -4751,7 +4784,7 @@ init_fn = function() {
4751
4784
  this.onDidInitialize((result) => {
4752
4785
  this.initialized = result;
4753
4786
  if (result.type === "error") {
4754
- reject(new NotebookInitError(result.message));
4787
+ reject(new NotebookInitError(result.message, result.data));
4755
4788
  }
4756
4789
  resolve(result);
4757
4790
  });