@phpsandbox/sdk 0.0.41 → 0.0.43

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.
@@ -1249,6 +1249,22 @@ var PHPSandbox = (() => {
1249
1249
  }
1250
1250
  };
1251
1251
 
1252
+ // src/config.ts
1253
+ var Config = class {
1254
+ constructor(okra) {
1255
+ this.okra = okra;
1256
+ }
1257
+ get() {
1258
+ return this.okra.invoke("config.get");
1259
+ }
1260
+ update(config) {
1261
+ return this.okra.invoke("config.update", { config });
1262
+ }
1263
+ setPorts(ports) {
1264
+ return this.okra.invoke("config.set-ports", { ports });
1265
+ }
1266
+ };
1267
+
1252
1268
  // node_modules/@msgpack/msgpack/dist.esm/utils/utf8.mjs
1253
1269
  function utf8Count(str) {
1254
1270
  const strLength = str.length;
@@ -3360,7 +3376,6 @@ var PHPSandbox = (() => {
3360
3376
  };
3361
3377
  var _Transport_instances, connect_fn, startPeriodicPing_fn;
3362
3378
  var Transport = class {
3363
- // 30 seconds
3364
3379
  constructor(url, eventEmitter, options = {}) {
3365
3380
  this.eventEmitter = eventEmitter;
3366
3381
  this.options = options;
@@ -3386,6 +3401,8 @@ var PHPSandbox = (() => {
3386
3401
  this.messageQueue = [];
3387
3402
  this.MAX_QUEUE_SIZE = 100;
3388
3403
  this.QUEUE_TIMEOUT = 3e4;
3404
+ // 30 seconds
3405
+ this.incomingMessageChain = Promise.resolve();
3389
3406
  this.validateConfiguration(options);
3390
3407
  this.url = new URL(url);
3391
3408
  this.PING_INTERVAL = options.pingInterval ?? 3e4;
@@ -3450,53 +3467,17 @@ var PHPSandbox = (() => {
3450
3467
  }
3451
3468
  async registerWatchers() {
3452
3469
  const onMessage = (ev) => {
3453
- if (!(ev.data instanceof Blob)) {
3454
- const error = new Error("Unexpected message type: " + typeof ev.data);
3470
+ this.incomingMessageChain = this.incomingMessageChain.catch(() => void 0).then(() => this.processIncomingMessage(ev)).catch((error) => {
3455
3471
  this.connectionStats.totalErrors++;
3456
- this.log("error", "Unexpected WebSocket message type", {
3457
- error: error.message,
3458
- messageType: typeof ev.data
3472
+ this.log("error", "Failed to process queued WebSocket frame", {
3473
+ error: error instanceof Error ? error.message : String(error)
3459
3474
  });
3460
3475
  this.eventEmitter.emit("transport.error", {
3461
- type: "message_type_error",
3476
+ type: "message_handle_error",
3462
3477
  error,
3463
3478
  rawMessage: ev.data,
3464
3479
  timestamp: Date.now()
3465
3480
  });
3466
- return;
3467
- }
3468
- ev.data.arrayBuffer().then((buffer) => {
3469
- if (buffer.byteLength === 0) {
3470
- this.log("warn", "Ignoring empty WebSocket frame");
3471
- return;
3472
- }
3473
- try {
3474
- void this.handleRawMessage(decode(buffer)).catch((error) => {
3475
- this.connectionStats.totalErrors++;
3476
- this.log("error", "Failed to process WebSocket frame", {
3477
- error: error instanceof Error ? error.message : String(error),
3478
- byteLength: buffer.byteLength
3479
- });
3480
- this.eventEmitter.emit("transport.error", {
3481
- type: "message_handle_error",
3482
- error,
3483
- rawMessage: buffer,
3484
- timestamp: Date.now()
3485
- });
3486
- });
3487
- } catch (error) {
3488
- this.connectionStats.totalErrors++;
3489
- this.log("error", "Failed to decode WebSocket frame", {
3490
- error: error instanceof Error ? error.message : String(error),
3491
- byteLength: buffer.byteLength
3492
- });
3493
- this.eventEmitter.emit("transport.error", {
3494
- type: "message_decode_error",
3495
- error,
3496
- rawMessage: buffer,
3497
- timestamp: Date.now()
3498
- });
3499
- }
3500
3481
  });
3501
3482
  };
3502
3483
  this.rws.addEventListener("message", onMessage);
@@ -3506,6 +3487,60 @@ var PHPSandbox = (() => {
3506
3487
  }
3507
3488
  });
3508
3489
  }
3490
+ async processIncomingMessage(ev) {
3491
+ if (!(ev.data instanceof Blob)) {
3492
+ const error = new Error("Unexpected message type: " + typeof ev.data);
3493
+ this.connectionStats.totalErrors++;
3494
+ this.log("error", "Unexpected WebSocket message type", {
3495
+ error: error.message,
3496
+ messageType: typeof ev.data
3497
+ });
3498
+ this.eventEmitter.emit("transport.error", {
3499
+ type: "message_type_error",
3500
+ error,
3501
+ rawMessage: ev.data,
3502
+ timestamp: Date.now()
3503
+ });
3504
+ return;
3505
+ }
3506
+ const buffer = await ev.data.arrayBuffer();
3507
+ if (buffer.byteLength === 0) {
3508
+ this.log("warn", "Ignoring empty WebSocket frame");
3509
+ return;
3510
+ }
3511
+ let decoded;
3512
+ try {
3513
+ decoded = decode(buffer);
3514
+ } catch (error) {
3515
+ this.connectionStats.totalErrors++;
3516
+ this.log("error", "Failed to decode WebSocket frame", {
3517
+ error: error instanceof Error ? error.message : String(error),
3518
+ byteLength: buffer.byteLength
3519
+ });
3520
+ this.eventEmitter.emit("transport.error", {
3521
+ type: "message_decode_error",
3522
+ error,
3523
+ rawMessage: buffer,
3524
+ timestamp: Date.now()
3525
+ });
3526
+ return;
3527
+ }
3528
+ try {
3529
+ await this.handleRawMessage(decoded);
3530
+ } catch (error) {
3531
+ this.connectionStats.totalErrors++;
3532
+ this.log("error", "Failed to process WebSocket frame", {
3533
+ error: error instanceof Error ? error.message : String(error),
3534
+ byteLength: buffer.byteLength
3535
+ });
3536
+ this.eventEmitter.emit("transport.error", {
3537
+ type: "message_handle_error",
3538
+ error,
3539
+ rawMessage: buffer,
3540
+ timestamp: Date.now()
3541
+ });
3542
+ }
3543
+ }
3509
3544
  async handleRawMessage(ev) {
3510
3545
  if (this.closed) {
3511
3546
  this.log("debug", "Ignoring message received after transport was closed");
@@ -5255,6 +5290,7 @@ var PHPSandbox = (() => {
5255
5290
  this.shell = new Shell(this);
5256
5291
  this.git = new Git(this);
5257
5292
  this.services = new Services(this);
5293
+ this.config = new Config(this);
5258
5294
  this.secrets = new NotebookSecrets(client, this.data.id);
5259
5295
  this.preview = new NotebookPreview(client, this.data.id);
5260
5296
  this.mail = new NotebookMail(client, this.data.id);