@phpsandbox/sdk 0.0.34 → 0.0.36

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.
@@ -3222,6 +3222,12 @@ var NamedDisposable = class {
3222
3222
  };
3223
3223
 
3224
3224
  // src/socket/index.ts
3225
+ var ConnectionTimeoutError = class extends Error {
3226
+ constructor(message = "WebSocket connection timeout") {
3227
+ super(message);
3228
+ this.name = "ConnectionTimeoutError";
3229
+ }
3230
+ };
3225
3231
  var ConnectionFailedError = class extends Error {
3226
3232
  constructor(message, originalError) {
3227
3233
  super(message);
@@ -3280,6 +3286,7 @@ var Transport = class {
3280
3286
  this.validateConfiguration(options);
3281
3287
  this.url = new URL(url);
3282
3288
  this.PING_INTERVAL = options.pingInterval ?? 3e4;
3289
+ this.CONNECT_WAIT_TIMEOUT = options.connectWaitTimeout ?? 3e4;
3283
3290
  this.connectionStats.connectionStartTime = Date.now();
3284
3291
  const startClosed = options.startClosed !== false;
3285
3292
  this.rws = new reconnecting_websocket_mjs_default(this.url.toString(), [], {
@@ -3309,6 +3316,9 @@ var Transport = class {
3309
3316
  if (options.connectionTimeout !== void 0 && (options.connectionTimeout < 100 || options.connectionTimeout > 3e4)) {
3310
3317
  throw new InvalidConfigurationError("connectionTimeout must be between 100ms and 30000ms");
3311
3318
  }
3319
+ if (options.connectWaitTimeout !== void 0 && (options.connectWaitTimeout < 1e3 || options.connectWaitTimeout > 3e5)) {
3320
+ throw new InvalidConfigurationError("connectWaitTimeout must be between 1000ms and 300000ms");
3321
+ }
3312
3322
  if (options.maxRetries !== void 0 && (options.maxRetries < 0 || options.maxRetries > 100)) {
3313
3323
  throw new InvalidConfigurationError("maxRetries must be between 0 and 100");
3314
3324
  }
@@ -4043,34 +4053,50 @@ connect_fn = function() {
4043
4053
  __privateMethod(this, _Transport_instances, startPeriodicPing_fn).call(this);
4044
4054
  return;
4045
4055
  }
4046
- if (this.rws.readyState === 3) {
4047
- this.rws.reconnect();
4048
- }
4049
4056
  let timeoutId;
4050
- const openHandler = () => {
4057
+ let errorCount = 0;
4058
+ const cleanup = () => {
4051
4059
  this.rws.removeEventListener("open", openHandler);
4052
4060
  this.rws.removeEventListener("error", errorHandler);
4061
+ this.rws.removeEventListener("close", closeHandler);
4053
4062
  clearTimeout(timeoutId);
4063
+ };
4064
+ const openHandler = () => {
4065
+ cleanup();
4054
4066
  this.connectPromise = null;
4055
4067
  resolve();
4056
4068
  __privateMethod(this, _Transport_instances, startPeriodicPing_fn).call(this);
4057
4069
  };
4058
4070
  const errorHandler = (error) => {
4059
- this.rws.removeEventListener("open", openHandler);
4060
- this.rws.removeEventListener("error", errorHandler);
4061
- clearTimeout(timeoutId);
4062
- this.connectPromise = null;
4063
- const detail = describeWebSocketEvent(error);
4064
- reject(new ConnectionFailedError(`WebSocket connection failed: ${detail}`, error));
4071
+ errorCount += 1;
4072
+ this.log("warn", "WebSocket emitted an error while connecting; waiting for reconnect/open", {
4073
+ errorCount,
4074
+ error: describeWebSocketEvent(error)
4075
+ });
4076
+ };
4077
+ const closeHandler = (event) => {
4078
+ const detail = describeWebSocketEvent(event);
4079
+ if ("code" in event && (event.code === 1008 || event.code === 4e3)) {
4080
+ cleanup();
4081
+ this.connectPromise = null;
4082
+ reject(new ConnectionFailedError(`WebSocket connection failed: ${detail}`, event));
4083
+ return;
4084
+ }
4085
+ this.log("warn", "WebSocket closed before opening; waiting for reconnect/open", {
4086
+ error: detail
4087
+ });
4065
4088
  };
4066
- timeoutId = setTimeout(() => {
4067
- this.rws.removeEventListener("open", openHandler);
4068
- this.rws.removeEventListener("error", errorHandler);
4069
- this.connectPromise = null;
4070
- reject(new Error("WebSocket connection timeout"));
4071
- }, 1e4);
4072
4089
  this.rws.addEventListener("open", openHandler);
4073
4090
  this.rws.addEventListener("error", errorHandler);
4091
+ this.rws.addEventListener("close", closeHandler);
4092
+ if (this.rws.readyState === 3) {
4093
+ this.rws.reconnect();
4094
+ }
4095
+ timeoutId = setTimeout(() => {
4096
+ cleanup();
4097
+ this.connectPromise = null;
4098
+ reject(new ConnectionTimeoutError(`WebSocket connection timeout after ${this.CONNECT_WAIT_TIMEOUT}ms`));
4099
+ }, this.CONNECT_WAIT_TIMEOUT);
4074
4100
  });
4075
4101
  return this.connectPromise;
4076
4102
  };
@@ -4945,6 +4971,7 @@ var NotebookApi = class {
4945
4971
  constructor(client) {
4946
4972
  this.client = client;
4947
4973
  this.secrets = new NotebookSecretApi(client);
4974
+ this.previewAuth = new NotebookPreviewAuthApi(client);
4948
4975
  }
4949
4976
  async create(template, input = {}, init = true) {
4950
4977
  const response = await this.client.post("/notebook", { template, ...input });
@@ -5051,6 +5078,22 @@ var NotebookSecretApi = class {
5051
5078
  await this.client.delete(`/notebook/${id}/secrets/${encodeURIComponent(name)}`);
5052
5079
  }
5053
5080
  };
5081
+ var NotebookPreviewAuthApi = class {
5082
+ constructor(client) {
5083
+ this.client = client;
5084
+ }
5085
+ async get(id) {
5086
+ const response = await this.client.get(`/notebook/${id}/preview-auth`);
5087
+ return response.data;
5088
+ }
5089
+ async set(id, input) {
5090
+ const response = await this.client.put(`/notebook/${id}/preview-auth`, input);
5091
+ return response.data;
5092
+ }
5093
+ async delete(id) {
5094
+ await this.client.delete(`/notebook/${id}/preview-auth`);
5095
+ }
5096
+ };
5054
5097
  var _initPromise, _NotebookInstance_instances, init_fn;
5055
5098
  var NotebookInstance = class {
5056
5099
  constructor(data, client) {
@@ -5081,6 +5124,7 @@ var NotebookInstance = class {
5081
5124
  this.git = new Git(this);
5082
5125
  this.services = new Services(this);
5083
5126
  this.secrets = new NotebookSecrets(client, this.data.id);
5127
+ this.previewAuth = new NotebookPreviewAuth(client, this.data.id);
5084
5128
  }
5085
5129
  async ready() {
5086
5130
  const terminalError = this.socket.getTerminalError();
@@ -5254,6 +5298,21 @@ var NotebookSecrets = class {
5254
5298
  return this.client.notebook.secrets.delete(this.notebookId, name);
5255
5299
  }
5256
5300
  };
5301
+ var NotebookPreviewAuth = class {
5302
+ constructor(client, notebookId) {
5303
+ this.client = client;
5304
+ this.notebookId = notebookId;
5305
+ }
5306
+ get() {
5307
+ return this.client.notebook.previewAuth.get(this.notebookId);
5308
+ }
5309
+ set(input) {
5310
+ return this.client.notebook.previewAuth.set(this.notebookId, input);
5311
+ }
5312
+ disable() {
5313
+ return this.client.notebook.previewAuth.delete(this.notebookId);
5314
+ }
5315
+ };
5257
5316
  export {
5258
5317
  ApiError,
5259
5318
  Beacon,
@@ -5273,6 +5332,8 @@ export {
5273
5332
  NotebookApi,
5274
5333
  NotebookInitError,
5275
5334
  NotebookInstance,
5335
+ NotebookPreviewAuth,
5336
+ NotebookPreviewAuthApi,
5276
5337
  NotebookSecretApi,
5277
5338
  NotebookSecrets,
5278
5339
  NotebookState,