@phpsandbox/sdk 0.1.6 → 0.1.10

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.
Files changed (59) hide show
  1. package/README.md +42 -50
  2. package/dist/beacon/index.d.ts +1 -7
  3. package/dist/beacon/index.js +14 -13
  4. package/dist/beacon/navigator.d.ts +8 -36
  5. package/dist/beacon/navigator.js +1 -62
  6. package/dist/browser/phpsandbox-sdk.esm.js +547 -691
  7. package/dist/browser/phpsandbox-sdk.esm.min.js +23 -23
  8. package/dist/browser/phpsandbox-sdk.iife.js +547 -691
  9. package/dist/browser/phpsandbox-sdk.iife.min.js +35 -35
  10. package/dist/composer.d.ts +10 -8
  11. package/dist/composer.js +18 -18
  12. package/dist/errors/index.d.ts +43 -8
  13. package/dist/errors/index.js +120 -14
  14. package/dist/feedback.js +1 -2
  15. package/dist/filesystem.d.ts +0 -17
  16. package/dist/filesystem.js +2 -21
  17. package/dist/git.d.ts +1 -5
  18. package/dist/git.js +6 -8
  19. package/dist/index.d.ts +66 -156
  20. package/dist/index.js +172 -289
  21. package/dist/integrations.d.ts +0 -2
  22. package/dist/integrations.js +5 -11
  23. package/dist/log.d.ts +0 -2
  24. package/dist/lsp.js +1 -1
  25. package/dist/metrics.d.ts +3 -3
  26. package/dist/ports.d.ts +1 -1
  27. package/dist/publications.d.ts +4 -54
  28. package/dist/publications.js +25 -103
  29. package/dist/runtime/rest.js +34 -17
  30. package/dist/runtime.d.ts +68 -0
  31. package/dist/runtime.js +46 -0
  32. package/dist/sandbox-integrations.d.ts +1 -2
  33. package/dist/sandbox-integrations.js +11 -14
  34. package/dist/schemas/publications.d.ts +0 -6
  35. package/dist/schemas/publications.js +0 -1
  36. package/dist/servers.d.ts +4 -2
  37. package/dist/servers.js +5 -8
  38. package/dist/shell.d.ts +2 -14
  39. package/dist/shell.js +1 -21
  40. package/dist/socket/index.d.ts +6 -7
  41. package/dist/socket/index.js +39 -25
  42. package/dist/types.d.ts +0 -12
  43. package/dist/types.js +1 -15
  44. package/docs/api-summary.md +28 -28
  45. package/docs/cdn-usage.md +43 -55
  46. package/docs/getting-started.md +43 -26
  47. package/examples/README.md +5 -35
  48. package/examples/basic.ts +9 -18
  49. package/examples/get.ts +2 -2
  50. package/examples/git-merge-smoke.ts +2 -3
  51. package/examples/laravel-load-test.ts +31 -36
  52. package/examples/notebook-readonly-smoke.ts +12 -26
  53. package/examples/publication-provider-label.ts +1 -1
  54. package/examples/publish-cloudflare-container.ts +2 -2
  55. package/examples/publish-laravel-cloud.ts +2 -2
  56. package/examples/publish-ssh-agent.ts +2 -2
  57. package/package.json +4 -3
  58. package/dist/container.d.ts +0 -65
  59. package/dist/container.js +0 -30
@@ -13,46 +13,133 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
13
13
  var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
14
14
 
15
15
  // src/errors/index.ts
16
- var PromiseTimeoutError = class extends Error {
17
- constructor(message, time3) {
16
+ var remoteErrorCodes = [
17
+ "ActionNotFound",
18
+ "AuthenticationRequired",
19
+ "BadGateway",
20
+ "BadRequest",
21
+ "Conflict",
22
+ "FileAlreadyExists",
23
+ "FileIsDirectory",
24
+ "FileNotDirectory",
25
+ "FileNotFound",
26
+ "FilesystemUnavailable",
27
+ "InternalError",
28
+ "InvalidArgument",
29
+ "InvalidConfiguration",
30
+ "InvalidRequest",
31
+ "InvalidResponse",
32
+ "InvalidServiceCommand",
33
+ "MethodNotAllowed",
34
+ "NotebookInitializationFailed",
35
+ "NotebookUnavailable",
36
+ "NotFound",
37
+ "PayloadTooLarge",
38
+ "PermissionDenied",
39
+ "RateLimited",
40
+ "RequestFailed",
41
+ "RuntimeOperationFailed",
42
+ "ServiceNotFound",
43
+ "ServiceUnavailable",
44
+ "UnprocessableEntity",
45
+ "ValidationFailed",
46
+ "WorkspaceUnavailable"
47
+ ];
48
+ var PHPSandboxError = class extends Error {
49
+ constructor(message, cause) {
18
50
  super(message);
19
- this.time = time3;
51
+ this.name = new.target.name;
52
+ this.cause = cause;
20
53
  }
21
54
  };
22
- var SendTimeoutError = class _SendTimeoutError extends PromiseTimeoutError {
23
- static fromPromiseTimeoutError(error51) {
24
- return new _SendTimeoutError(error51.message, error51.time);
55
+ var RemoteError = class _RemoteError extends PHPSandboxError {
56
+ constructor(message, options) {
57
+ super(message, options.cause);
58
+ this.source = options.source;
59
+ this.status = options.status;
60
+ this.code = options.code;
61
+ this.details = options.details;
25
62
  }
26
- };
27
- var NotebookUnavailableError = class extends Error {
28
- constructor(message = "Notebook is no longer available", raw = {}) {
29
- super(message);
30
- this.raw = raw;
31
- this.name = "NotebookUnavailableError";
63
+ static is(error51, code) {
64
+ return error51 instanceof _RemoteError && (code === void 0 || error51.code === code);
32
65
  }
33
- };
34
- var UnsupportedRuntimeTransportError = class extends Error {
35
- constructor(message) {
36
- super(message);
37
- this.name = "UnsupportedRuntimeTransportError";
66
+ static isValidation(error51) {
67
+ return _RemoteError.is(error51, "ValidationFailed") && validationDetails(error51.details) !== void 0;
68
+ }
69
+ is(code) {
70
+ return this.code === code;
38
71
  }
39
72
  };
40
-
41
- // src/types.ts
42
- var ErrorEvent = class extends Error {
43
- constructor(code, message, raw = {}) {
44
- super(message);
73
+ var TransportError = class _TransportError extends PHPSandboxError {
74
+ constructor(message, code, cause) {
75
+ super(message, cause);
45
76
  this.code = code;
46
- this.message = message;
47
- this.raw = raw;
77
+ }
78
+ static is(error51, code) {
79
+ return error51 instanceof _TransportError && (code === void 0 || error51.code === code);
80
+ }
81
+ is(code) {
82
+ return this.code === code;
48
83
  }
49
84
  };
50
- var RateLimitError = class extends ErrorEvent {
51
- constructor(message, raw = {}) {
52
- super(429, message, raw);
85
+ function remoteError(source, payload, cause) {
86
+ const error51 = record(payload);
87
+ const status = positiveInteger(error51?.status);
88
+ const code = nonEmptyString(error51?.code);
89
+ const message = nonEmptyString(error51?.message);
90
+ if (status === void 0 || !isRemoteErrorCode(code) || message === void 0) {
91
+ throw new TransportError("PHPSandbox returned an invalid error response.", "InvalidResponse", cause ?? payload);
92
+ }
93
+ return new RemoteError(message, {
94
+ source,
95
+ status,
96
+ code,
97
+ details: error51?.details,
98
+ cause
99
+ });
100
+ }
101
+ function isRemoteErrorCode(value) {
102
+ return typeof value === "string" && remoteErrorCodes.includes(value);
103
+ }
104
+ function positiveInteger(value) {
105
+ return typeof value === "number" && Number.isInteger(value) && value > 0 ? value : void 0;
106
+ }
107
+ function nonEmptyString(value) {
108
+ return typeof value === "string" && value.trim() !== "" ? value.trim() : void 0;
109
+ }
110
+ function record(value) {
111
+ return value !== null && typeof value === "object" && !Array.isArray(value) ? value : void 0;
112
+ }
113
+ function stringArrayRecord(value) {
114
+ const candidate = record(value);
115
+ if (candidate === void 0) {
116
+ return void 0;
117
+ }
118
+ const entries = Object.entries(candidate);
119
+ if (!entries.every(([, messages]) => Array.isArray(messages) && messages.every((message) => typeof message === "string"))) {
120
+ return void 0;
121
+ }
122
+ return Object.fromEntries(entries);
123
+ }
124
+ function validationDetails(value) {
125
+ const details = record(value);
126
+ const errors = stringArrayRecord(details?.errors);
127
+ return errors === void 0 ? void 0 : { errors };
128
+ }
129
+ var PromiseTimeoutError = class extends Error {
130
+ constructor(message, time3) {
131
+ super(message);
132
+ this.time = time3;
53
133
  }
54
134
  };
55
- var PHPSandboxError = class extends ErrorEvent {
135
+ var SendTimeoutError = class _SendTimeoutError extends TransportError {
136
+ constructor(message, time3, cause) {
137
+ super(message, "SendTimeout", cause);
138
+ this.time = time3;
139
+ }
140
+ static fromPromiseTimeoutError(error51) {
141
+ return new _SendTimeoutError(error51.message, error51.time, error51);
142
+ }
56
143
  };
57
144
 
58
145
  // node_modules/nanoid/url-alphabet/index.js
@@ -88,21 +175,6 @@ var FileChangeType = /* @__PURE__ */ ((FileChangeType2) => {
88
175
  FileChangeType2[FileChangeType2["DELETED"] = 3] = "DELETED";
89
176
  return FileChangeType2;
90
177
  })(FileChangeType || {});
91
- var FilesystemErrorType = /* @__PURE__ */ ((FilesystemErrorType2) => {
92
- FilesystemErrorType2["Unavailable"] = "Unavailable";
93
- FilesystemErrorType2["NoPermissions"] = "NoPermissions";
94
- FilesystemErrorType2["FileExists"] = "FileExists";
95
- FilesystemErrorType2["FileNotFound"] = "FileNotFound";
96
- FilesystemErrorType2["FileIsADirectory"] = "FileIsADirectory";
97
- FilesystemErrorType2["FileNotADirectory"] = "FileNotADirectory";
98
- return FilesystemErrorType2;
99
- })(FilesystemErrorType || {});
100
- var FilesystemError = class extends ErrorEvent {
101
- constructor(inner, name) {
102
- super(inner.code, inner.message);
103
- this.name = name;
104
- }
105
- };
106
178
  var FilesystemSubscription = class {
107
179
  constructor(disposable, onDispose) {
108
180
  this.disposable = disposable;
@@ -256,7 +328,7 @@ var Filesystem = class {
256
328
  if (this.okra.runtimeTransport === "rest") {
257
329
  return new ReadableStream({
258
330
  start(controller) {
259
- controller.error(new UnsupportedRuntimeTransportError("Following files requires the realtime transport."));
331
+ controller.error(new PHPSandboxError("Following files requires the realtime transport."));
260
332
  }
261
333
  });
262
334
  }
@@ -476,9 +548,6 @@ var Filesystem = class {
476
548
  return this.okra.invoke("fs.tree", { path });
477
549
  }
478
550
  handleError(e) {
479
- if (e instanceof ErrorEvent && "name" in e.raw) {
480
- throw new FilesystemError(e, e.raw.name);
481
- }
482
551
  throw e;
483
552
  }
484
553
  };
@@ -683,38 +752,6 @@ var Terminals = class {
683
752
  }
684
753
  };
685
754
 
686
- // src/container.ts
687
- var NotebookState = /* @__PURE__ */ ((NotebookState2) => {
688
- NotebookState2["RUNNING"] = "running";
689
- NotebookState2["STOPPED"] = "stopped";
690
- NotebookState2["STARTING"] = "starting";
691
- NotebookState2["STOPPING"] = "stopping";
692
- NotebookState2["KILLED"] = "killed";
693
- NotebookState2["ERROR"] = "error";
694
- NotebookState2["PROVISIONING"] = "provisioning";
695
- return NotebookState2;
696
- })(NotebookState || {});
697
- var Container = class {
698
- constructor(okra) {
699
- this.okra = okra;
700
- }
701
- start() {
702
- return this.okra.invoke("container.start");
703
- }
704
- restart() {
705
- return this.okra.invoke("container.restart");
706
- }
707
- stop() {
708
- return this.okra.invoke("container.stop");
709
- }
710
- state() {
711
- return this.okra.invoke("container.state");
712
- }
713
- setPhp(version2) {
714
- return this.okra.invoke("container.set-php", { version: version2 });
715
- }
716
- };
717
-
718
755
  // src/auth.ts
719
756
  var Auth = class {
720
757
  constructor(okra) {
@@ -762,7 +799,7 @@ var Lsp = class {
762
799
  return LspConnection.create(id, this);
763
800
  }
764
801
  whenSocketConnected() {
765
- return this.okra.whenConnected();
802
+ return this.okra.connected();
766
803
  }
767
804
  };
768
805
  var LspConnection = class _LspConnection {
@@ -808,26 +845,6 @@ function resolveRunInput(command, argsOrOpts = [], opts) {
808
845
  opts: { tty: false, ...resolvedOpts }
809
846
  };
810
847
  }
811
- var CommandError = class extends Error {
812
- constructor(result) {
813
- super(result.output);
814
- this.result = result;
815
- }
816
- };
817
- var ProcessResult = class {
818
- constructor(output, stdout, stderr, exitCode) {
819
- this.output = output;
820
- this.stdout = stdout;
821
- this.stderr = stderr;
822
- this.exitCode = exitCode;
823
- }
824
- throw() {
825
- if (this.exitCode !== 0) {
826
- throw new CommandError(this);
827
- }
828
- return this;
829
- }
830
- };
831
848
  var ProcessReadable = class {
832
849
  constructor() {
833
850
  this.controller = null;
@@ -915,7 +932,7 @@ var ShellProcess = class {
915
932
  { abortSignal }
916
933
  ).then((result) => {
917
934
  finish();
918
- return new ProcessResult(result.output, result.stdout, result.stderr, result.exitCode);
935
+ return result;
919
936
  }).catch((error51) => {
920
937
  fail(error51);
921
938
  throw error51;
@@ -940,6 +957,24 @@ var Shell = class {
940
957
  };
941
958
 
942
959
  // src/composer.ts
960
+ var ComposerCredentials = class {
961
+ constructor(client, notebookId) {
962
+ this.client = client;
963
+ this.notebookId = notebookId;
964
+ }
965
+ async set(input) {
966
+ const response = await this.client.put(
967
+ `/notebook/${this.notebookId}/composer/credentials`,
968
+ input
969
+ );
970
+ return response.data;
971
+ }
972
+ async remove(type, url2) {
973
+ const params = new URLSearchParams({ type });
974
+ if (url2) params.set("url", url2);
975
+ await this.client.delete(`/notebook/${this.notebookId}/composer/credentials?${params.toString()}`);
976
+ }
977
+ };
943
978
  var ComposerProcess = class {
944
979
  constructor(id, okra, command, args, options) {
945
980
  this.id = id;
@@ -977,7 +1012,7 @@ var ComposerProcess = class {
977
1012
  };
978
1013
  this.completion = this.okra.invoke("composer.invoke", { id, command, args, options }).then((result) => {
979
1014
  finish();
980
- return new ProcessResult(result.output, result.stdout, result.stderr, result.exitCode);
1015
+ return result;
981
1016
  }).catch((error51) => {
982
1017
  fail(error51);
983
1018
  throw error51;
@@ -998,21 +1033,6 @@ var Composer = class {
998
1033
  run(command, args = {}, options = {}) {
999
1034
  return new ComposerProcess(nanoid(), this.okra, command, args, options);
1000
1035
  }
1001
- dumpAutoload(options = {}) {
1002
- return this.run("dump-autoload", {}, options);
1003
- }
1004
- install(options = {}) {
1005
- return this.run("install", {}, options);
1006
- }
1007
- update(args, options = {}) {
1008
- return this.run("update", args, options);
1009
- }
1010
- require(packages, options = {}) {
1011
- return this.run("require", packages, options);
1012
- }
1013
- remove(args, options = {}) {
1014
- return this.run("remove", args, options);
1015
- }
1016
1036
  packages() {
1017
1037
  return this.okra.invoke("composer.packages");
1018
1038
  }
@@ -1172,6 +1192,50 @@ var Ports = class {
1172
1192
  }
1173
1193
  };
1174
1194
 
1195
+ // src/runtime.ts
1196
+ var RuntimeMetrics = class {
1197
+ constructor(metrics) {
1198
+ this.metrics = metrics;
1199
+ }
1200
+ current() {
1201
+ return this.metrics.current();
1202
+ }
1203
+ watch(options = {}) {
1204
+ return this.metrics.watch(options);
1205
+ }
1206
+ };
1207
+ var RuntimeLogs = class {
1208
+ constructor(logs) {
1209
+ this.logs = logs;
1210
+ }
1211
+ follow(options = {}) {
1212
+ return this.logs.follow(options);
1213
+ }
1214
+ };
1215
+ var RuntimePorts = class {
1216
+ constructor(ports) {
1217
+ this.ports = ports;
1218
+ }
1219
+ list() {
1220
+ return this.ports.list();
1221
+ }
1222
+ watch(options = {}) {
1223
+ return this.ports.watch(options);
1224
+ }
1225
+ };
1226
+ var Runtime = class {
1227
+ constructor(notebook) {
1228
+ this.notebook = notebook;
1229
+ const telemetry = new RuntimeTelemetry(notebook);
1230
+ this.metrics = new RuntimeMetrics(new Metrics(notebook, telemetry));
1231
+ this.logs = new RuntimeLogs(new Logs(notebook, telemetry));
1232
+ this.ports = new RuntimePorts(new Ports(notebook, telemetry));
1233
+ }
1234
+ setPhpVersion(version2) {
1235
+ return this.notebook.invoke("container.set-php", { version: version2 });
1236
+ }
1237
+ };
1238
+
1175
1239
  // src/repl.ts
1176
1240
  var Repl = class {
1177
1241
  constructor(okra) {
@@ -2059,24 +2123,24 @@ var CachedKeyDecoder = class {
2059
2123
  }
2060
2124
  find(bytes, inputOffset, byteLength) {
2061
2125
  const records = this.caches[byteLength - 1];
2062
- FIND_CHUNK: for (const record2 of records) {
2063
- const recordBytes = record2.bytes;
2126
+ FIND_CHUNK: for (const record3 of records) {
2127
+ const recordBytes = record3.bytes;
2064
2128
  for (let j = 0; j < byteLength; j++) {
2065
2129
  if (recordBytes[j] !== bytes[inputOffset + j]) {
2066
2130
  continue FIND_CHUNK;
2067
2131
  }
2068
2132
  }
2069
- return record2.str;
2133
+ return record3.str;
2070
2134
  }
2071
2135
  return null;
2072
2136
  }
2073
2137
  store(bytes, value) {
2074
2138
  const records = this.caches[bytes.length - 1];
2075
- const record2 = { bytes, str: value };
2139
+ const record3 = { bytes, str: value };
2076
2140
  if (records.length >= this.maxLengthPerKey) {
2077
- records[Math.random() * records.length | 0] = record2;
2141
+ records[Math.random() * records.length | 0] = record3;
2078
2142
  } else {
2079
- records.push(record2);
2143
+ records.push(record3);
2080
2144
  }
2081
2145
  }
2082
2146
  decode(bytes, inputOffset, byteLength) {
@@ -2826,17 +2890,17 @@ var Event = (
2826
2890
  return Event2;
2827
2891
  })()
2828
2892
  );
2829
- var ErrorEvent2 = (
2893
+ var ErrorEvent = (
2830
2894
  /** @class */
2831
2895
  (function(_super) {
2832
- __extends(ErrorEvent3, _super);
2833
- function ErrorEvent3(error51, target) {
2896
+ __extends(ErrorEvent2, _super);
2897
+ function ErrorEvent2(error51, target) {
2834
2898
  var _this = _super.call(this, "error", target) || this;
2835
2899
  _this.message = error51.message;
2836
2900
  _this.error = error51;
2837
2901
  return _this;
2838
2902
  }
2839
- return ErrorEvent3;
2903
+ return ErrorEvent2;
2840
2904
  })(Event)
2841
2905
  );
2842
2906
  var CloseEvent = (
@@ -3261,7 +3325,7 @@ var ReconnectingWebSocket = (
3261
3325
  };
3262
3326
  ReconnectingWebSocket3.prototype._handleTimeout = function() {
3263
3327
  this._debug("timeout event");
3264
- this._handleError(new ErrorEvent2(Error("TIMEOUT"), this));
3328
+ this._handleError(new ErrorEvent(Error("TIMEOUT"), this));
3265
3329
  };
3266
3330
  ReconnectingWebSocket3.prototype._disconnect = function(code, reason) {
3267
3331
  if (code === void 0) {
@@ -3348,12 +3412,12 @@ var extractNestedErrorMessage = (value) => {
3348
3412
  if (!value || typeof value !== "object") {
3349
3413
  return void 0;
3350
3414
  }
3351
- const record2 = value;
3352
- const message = typeof record2.message === "string" && record2.message ? record2.message : typeof record2.reason === "string" && record2.reason ? record2.reason : void 0;
3415
+ const record3 = value;
3416
+ const message = typeof record3.message === "string" && record3.message ? record3.message : typeof record3.reason === "string" && record3.reason ? record3.reason : void 0;
3353
3417
  if (!message) {
3354
3418
  return void 0;
3355
3419
  }
3356
- const name = typeof record2.name === "string" && record2.name ? record2.name : void 0;
3420
+ const name = typeof record3.name === "string" && record3.name ? record3.name : void 0;
3357
3421
  return name ? `${name}: ${message}` : message;
3358
3422
  };
3359
3423
  var describeWebSocketEvent = (event) => {
@@ -3366,29 +3430,29 @@ var describeWebSocketEvent = (event) => {
3366
3430
  if (!event || typeof event !== "object") {
3367
3431
  return String(event);
3368
3432
  }
3369
- const record2 = event;
3433
+ const record3 = event;
3370
3434
  const parts = [];
3371
- const topLevelMessage = extractNestedErrorMessage(record2);
3435
+ const topLevelMessage = extractNestedErrorMessage(record3);
3372
3436
  if (topLevelMessage) {
3373
3437
  parts.push(topLevelMessage);
3374
3438
  }
3375
- const nestedErrorMessage = extractNestedErrorMessage(record2.error);
3439
+ const nestedErrorMessage = extractNestedErrorMessage(record3.error);
3376
3440
  if (nestedErrorMessage && nestedErrorMessage !== topLevelMessage) {
3377
3441
  parts.push(`error=${nestedErrorMessage}`);
3378
3442
  }
3379
- if (typeof record2.type === "string" && record2.type) {
3380
- parts.push(`type=${record2.type}`);
3443
+ if (typeof record3.type === "string" && record3.type) {
3444
+ parts.push(`type=${record3.type}`);
3381
3445
  }
3382
- if (typeof record2.code === "number") {
3383
- parts.push(`code=${record2.code}`);
3446
+ if (typeof record3.code === "number") {
3447
+ parts.push(`code=${record3.code}`);
3384
3448
  }
3385
- if (typeof record2.reason === "string" && record2.reason && record2.reason !== topLevelMessage) {
3386
- parts.push(`reason=${record2.reason}`);
3449
+ if (typeof record3.reason === "string" && record3.reason && record3.reason !== topLevelMessage) {
3450
+ parts.push(`reason=${record3.reason}`);
3387
3451
  }
3388
- if (typeof record2.wasClean === "boolean") {
3389
- parts.push(`wasClean=${record2.wasClean}`);
3452
+ if (typeof record3.wasClean === "boolean") {
3453
+ parts.push(`wasClean=${record3.wasClean}`);
3390
3454
  }
3391
- const target = record2.target ?? record2.currentTarget;
3455
+ const target = record3.target ?? record3.currentTarget;
3392
3456
  if (target && typeof target === "object") {
3393
3457
  if (typeof target.url === "string" && target.url) {
3394
3458
  parts.push(`url=${sanitizeWebSocketUrl(target.url)}`);
@@ -3438,25 +3502,36 @@ var NamedDisposable = class {
3438
3502
  };
3439
3503
 
3440
3504
  // src/socket/index.ts
3505
+ var SAFE_DEBUG_METADATA_KEYS = /* @__PURE__ */ new Set([
3506
+ "url",
3507
+ "action",
3508
+ "event",
3509
+ "responseEvent",
3510
+ "errorEvent",
3511
+ "hasData",
3512
+ "code",
3513
+ "attempt",
3514
+ "maxRetries",
3515
+ "timeout",
3516
+ "errorCount",
3517
+ "byteLength"
3518
+ ]);
3441
3519
  var ReconnectingWebSocket2 = reconnecting_websocket_mjs_default ?? reconnecting_websocket_mjs_exports;
3442
- var ConnectionTimeoutError = class extends Error {
3520
+ var ConnectionTimeoutError = class extends TransportError {
3443
3521
  constructor(message = "WebSocket connection timeout") {
3444
- super(message);
3445
- this.name = "ConnectionTimeoutError";
3522
+ super(message, "ConnectionTimeout");
3446
3523
  }
3447
3524
  };
3448
- var ConnectionFailedError = class extends Error {
3525
+ var ConnectionFailedError = class extends TransportError {
3449
3526
  constructor(message, originalError) {
3450
- super(message);
3527
+ super(message, "ConnectionFailed", originalError);
3451
3528
  this.originalError = originalError;
3452
- this.name = "ConnectionFailedError";
3453
3529
  }
3454
3530
  };
3455
- var InvalidMessageError = class extends Error {
3531
+ var InvalidMessageError = class extends TransportError {
3456
3532
  constructor(message, data) {
3457
- super(message);
3533
+ super(message, "InvalidResponse", data);
3458
3534
  this.data = data;
3459
- this.name = "InvalidMessageError";
3460
3535
  }
3461
3536
  };
3462
3537
  var InvalidConfigurationError = class extends Error {
@@ -3483,7 +3558,6 @@ var Transport = class {
3483
3558
  const urlProvider = typeof url2 === "string" ? this.url.toString() : async () => new URL(await url2()).toString();
3484
3559
  this.PING_INTERVAL = options.pingInterval ?? 3e4;
3485
3560
  this.CONNECT_WAIT_TIMEOUT = options.connectWaitTimeout ?? 3e4;
3486
- const startClosed = options.startClosed !== false;
3487
3561
  this.rws = new ReconnectingWebSocket2(urlProvider, [], {
3488
3562
  WebSocket: options.webSocket ?? globalThis.WebSocket ?? browser_default,
3489
3563
  connectionTimeout: options.connectionTimeout,
@@ -3491,7 +3565,7 @@ var Transport = class {
3491
3565
  minReconnectionDelay: 200,
3492
3566
  maxEnqueuedMessages: 0,
3493
3567
  maxRetries: options.maxRetries ?? 50,
3494
- startClosed
3568
+ startClosed: true
3495
3569
  });
3496
3570
  this.log("debug", "Transport initialized", {
3497
3571
  url: this.url === null ? "dynamic" : transportLogUrl(this.url),
@@ -3522,8 +3596,10 @@ var Transport = class {
3522
3596
  log(level, message, data) {
3523
3597
  if (this.options.debug) {
3524
3598
  const timestamp = (/* @__PURE__ */ new Date()).toISOString();
3525
- const logData = data ? JSON.stringify(data, null, 2) : "";
3526
- console[level](`[Transport ${timestamp}] ${message}${logData ? "\n" + logData : ""}`);
3599
+ const metadata = safeDebugMetadata(data);
3600
+ const logData = metadata ? `
3601
+ ${JSON.stringify(metadata, null, 2)}` : "";
3602
+ console[level](`[Transport ${timestamp}] ${message}${logData}`);
3527
3603
  }
3528
3604
  }
3529
3605
  /**
@@ -3646,10 +3722,12 @@ var Transport = class {
3646
3722
  }
3647
3723
  if (event === "Events.BootError" /* BootError */) {
3648
3724
  const errorData = data;
3649
- const error51 = new NotebookUnavailableError(
3650
- errorData?.message || "Notebook is no longer available",
3651
- errorData || {}
3652
- );
3725
+ const error51 = new RemoteError(errorData?.message || "Notebook is no longer available", {
3726
+ source: "runtime",
3727
+ status: 503,
3728
+ code: "NotebookUnavailable",
3729
+ details: errorData || {}
3730
+ });
3653
3731
  this.log("error", "Boot error received", { data });
3654
3732
  this.terminate(error51, 4e3, error51.message);
3655
3733
  return;
@@ -3792,12 +3870,16 @@ var Transport = class {
3792
3870
  });
3793
3871
  this.listenOnce(errorEvent, (e) => {
3794
3872
  this.log("error", "Message error received", { action, error: e });
3795
- const error51 = e;
3796
- reject(new ErrorEvent(error51.code, error51.message, error51));
3873
+ reject(remoteError("runtime", e));
3797
3874
  });
3798
3875
  closeHandler = (_ev) => {
3799
3876
  if (_ev.code === 1008 && (_ev.reason || "").includes("rate limit")) {
3800
- reject(new RateLimitError(_ev.reason || "Rate limit exceeded", _ev));
3877
+ reject(new RemoteError(_ev.reason || "Rate limit exceeded", {
3878
+ source: "runtime",
3879
+ status: 429,
3880
+ code: "RateLimited",
3881
+ cause: _ev
3882
+ }));
3801
3883
  return;
3802
3884
  }
3803
3885
  const detail = describeWebSocketEvent(_ev);
@@ -3810,7 +3892,7 @@ var Transport = class {
3810
3892
  this.log("debug", "Message sent", { action, data });
3811
3893
  } catch (error51) {
3812
3894
  this.log("error", "Failed to send message", { action, error: error51 });
3813
- reject(error51);
3895
+ reject(new ConnectionFailedError(`Failed to send runtime action ${action}.`, error51));
3814
3896
  }
3815
3897
  };
3816
3898
  const send = async () => {
@@ -3863,7 +3945,7 @@ var Transport = class {
3863
3945
  try {
3864
3946
  return await sender();
3865
3947
  } catch (e) {
3866
- if (e instanceof ErrorEvent || e instanceof RateLimitError || e instanceof InvalidConfigurationError || e instanceof InvalidMessageError || e instanceof NotebookUnavailableError || e instanceof DOMException) {
3948
+ if (e instanceof RemoteError || e instanceof InvalidConfigurationError || e instanceof InvalidMessageError || e instanceof DOMException) {
3867
3949
  this.log("debug", "Non-retryable error, bailing", {
3868
3950
  error: e.message,
3869
3951
  attempt
@@ -3932,7 +4014,7 @@ var Transport = class {
3932
4014
  }
3933
4015
  terminate(error51, code = 4e3, reason = error51.message) {
3934
4016
  this.terminalError = error51;
3935
- if (error51 instanceof NotebookUnavailableError) {
4017
+ if (RemoteError.is(error51, "NotebookUnavailable")) {
3936
4018
  this.eventEmitter.emit("transport.boot_error", {
3937
4019
  error: error51,
3938
4020
  timestamp: Date.now()
@@ -4080,6 +4162,15 @@ startPeriodicPing_fn = function() {
4080
4162
  };
4081
4163
  });
4082
4164
  };
4165
+ function safeDebugMetadata(data) {
4166
+ if (data === null || typeof data !== "object") {
4167
+ return null;
4168
+ }
4169
+ const metadata = Object.entries(data).filter(
4170
+ ([key, value]) => SAFE_DEBUG_METADATA_KEYS.has(key) && ["string", "number", "boolean"].includes(typeof value)
4171
+ );
4172
+ return metadata.length > 0 ? Object.fromEntries(metadata) : null;
4173
+ }
4083
4174
  function transportLogUrl(url2) {
4084
4175
  const safeUrl = new URL(url2);
4085
4176
  safeUrl.search = "";
@@ -4204,8 +4295,9 @@ var Git = class {
4204
4295
  revert(input) {
4205
4296
  return this.okra.invoke("git.revert", input);
4206
4297
  }
4207
- credentials() {
4208
- return this.okra.gitCredentials();
4298
+ async credentials() {
4299
+ const response = await this.client.post(`/notebook/${this.okra.data.id}/git/credentials`);
4300
+ return response.data;
4209
4301
  }
4210
4302
  restore(ref) {
4211
4303
  return this.okra.invoke("git.restore", { ref });
@@ -4265,15 +4357,8 @@ var GitTargetApi = class {
4265
4357
  );
4266
4358
  return new GitTarget(response.data, this.notebookId, this.client);
4267
4359
  }
4268
- async sync(target, input = {}) {
4269
- const response = await this.client.post(
4270
- `/notebook/${this.notebookId}/git/targets/${encodeURIComponent(gitTargetId(target))}/sync`,
4271
- omitUndefined({ ...input })
4272
- );
4273
- return new GitTarget(response.data, this.notebookId, this.client);
4274
- }
4275
4360
  };
4276
- var GitTarget = class {
4361
+ var GitTarget = class _GitTarget {
4277
4362
  constructor(data, notebookId, client) {
4278
4363
  this.data = data;
4279
4364
  this.notebookId = notebookId;
@@ -4282,8 +4367,12 @@ var GitTarget = class {
4282
4367
  get id() {
4283
4368
  return this.data.id;
4284
4369
  }
4285
- sync(input = {}) {
4286
- return new GitTargetApi(this.notebookId, this.client).sync(this, input);
4370
+ async sync(input = {}) {
4371
+ const response = await this.client.post(
4372
+ `/notebook/${this.notebookId}/git/targets/${encodeURIComponent(this.id)}/sync`,
4373
+ omitUndefined({ ...input })
4374
+ );
4375
+ return new _GitTarget(response.data, this.notebookId, this.client);
4287
4376
  }
4288
4377
  };
4289
4378
  function gitTargetId(target) {
@@ -4487,7 +4576,7 @@ __export(external_exports, {
4487
4576
  promise: () => promise,
4488
4577
  property: () => _property,
4489
4578
  readonly: () => readonly,
4490
- record: () => record,
4579
+ record: () => record2,
4491
4580
  refine: () => refine,
4492
4581
  regex: () => _regex,
4493
4582
  regexes: () => regexes_exports,
@@ -16825,7 +16914,7 @@ __export(schemas_exports2, {
16825
16914
  preprocess: () => preprocess,
16826
16915
  promise: () => promise,
16827
16916
  readonly: () => readonly,
16828
- record: () => record,
16917
+ record: () => record2,
16829
16918
  refine: () => refine,
16830
16919
  set: () => set,
16831
16920
  strictObject: () => strictObject,
@@ -17794,7 +17883,7 @@ var ZodRecord = /* @__PURE__ */ $constructor("ZodRecord", (inst, def) => {
17794
17883
  inst.keyType = def.keyType;
17795
17884
  inst.valueType = def.valueType;
17796
17885
  });
17797
- function record(keyType, valueType, params) {
17886
+ function record2(keyType, valueType, params) {
17798
17887
  if (!valueType || !valueType._zod) {
17799
17888
  return new ZodRecord({
17800
17889
  type: "record",
@@ -18261,7 +18350,7 @@ var stringbool = (...args) => _stringbool({
18261
18350
  }, ...args);
18262
18351
  function json(params) {
18263
18352
  const jsonSchema = lazy(() => {
18264
- return union([string2(params), number2(), boolean2(), _null3(), array(jsonSchema), record(string2(), jsonSchema)]);
18353
+ return union([string2(params), number2(), boolean2(), _null3(), array(jsonSchema), record2(string2(), jsonSchema)]);
18265
18354
  });
18266
18355
  return jsonSchema;
18267
18356
  }
@@ -18856,7 +18945,6 @@ var PublicationRegionSchema = external_exports.enum([
18856
18945
  "AFR"
18857
18946
  ]);
18858
18947
  var PublicationJurisdictionSchema = external_exports.enum(["eu", "fedramp"]);
18859
- var PublicationDomainDnsRecordTypeSchema = external_exports.enum(["CNAME", "ALIAS", "ANAME"]);
18860
18948
  var PublicationProtectionModeSchema = external_exports.enum(["none", "password"]);
18861
18949
  var PublicationLogStreamSchema = external_exports.enum(["build", "runtime"]);
18862
18950
  var PublishStreamLogStreamSchema = external_exports.enum(["build", "publish", "runtime"]);
@@ -18947,33 +19035,6 @@ var PublishStreamSseEventSchema = external_exports.discriminatedUnion("event", [
18947
19035
  });
18948
19036
 
18949
19037
  // src/publications.ts
18950
- var NotebookPublicationApi = class {
18951
- constructor(client) {
18952
- this.client = client;
18953
- }
18954
- async current(notebookId) {
18955
- try {
18956
- const response = await this.client.get(
18957
- `/notebook/${notebookId}/publication`
18958
- );
18959
- return new PublicationInstance(response.data, this.client, notebookId);
18960
- } catch (error51) {
18961
- if (error51 instanceof ApiError && error51.status === 404) {
18962
- return null;
18963
- }
18964
- throw error51;
18965
- }
18966
- }
18967
- async publish(notebookId, input) {
18968
- const response = await this.client.post(
18969
- `/notebook/${notebookId}/publication`,
18970
- input
18971
- );
18972
- const run = new PublicationRun(new PublicationInstance(response.data, this.client, notebookId), this.client);
18973
- run.start();
18974
- return run;
18975
- }
18976
- };
18977
19038
  var PublicationApi = class {
18978
19039
  constructor(client) {
18979
19040
  this.client = client;
@@ -18982,60 +19043,6 @@ var PublicationApi = class {
18982
19043
  const response = await this.client.get(`/publications/${id}`);
18983
19044
  return new PublicationInstance(response.data, this.client);
18984
19045
  }
18985
- async destroy(id) {
18986
- await this.client.delete(`/publications/${id}`);
18987
- }
18988
- async setProtection(id, input) {
18989
- const response = await this.client.put(`/publications/${id}/protection`, input);
18990
- return new PublicationInstance(response.data, this.client);
18991
- }
18992
- async protection(id) {
18993
- const response = await this.client.get(`/publications/${id}/protection`);
18994
- return response.data;
18995
- }
18996
- async createProtectionSession(id) {
18997
- const response = await this.client.post(`/publications/${id}/protection/session`);
18998
- return response.data;
18999
- }
19000
- async disableProtection(id) {
19001
- const response = await this.client.delete(`/publications/${id}/protection`);
19002
- return new PublicationInstance(response.data, this.client);
19003
- }
19004
- async listDomains(id) {
19005
- const response = await this.client.get(
19006
- `/publications/${id}/domains`
19007
- );
19008
- return unwrapPublicationDomainCollection(response.data);
19009
- }
19010
- async createDomain(id, input) {
19011
- const response = await this.client.post(`/publications/${id}/domains`, input);
19012
- return response.data;
19013
- }
19014
- async refreshDomain(id, domainId) {
19015
- const response = await this.client.post(`/publications/${id}/domains/${domainId}/refresh`);
19016
- return response.data;
19017
- }
19018
- async deleteDomain(id, domainId) {
19019
- await this.client.delete(`/publications/${id}/domains/${domainId}`);
19020
- }
19021
- async events(id) {
19022
- return parseNdjsonStream(
19023
- await this.client.stream(`/publications/${id}/events/stream`),
19024
- PublicationEventDataSchema
19025
- );
19026
- }
19027
- async buildLogs(id, buildId) {
19028
- return parseNdjsonStream(
19029
- await this.client.stream(`/publications/${id}/builds/${buildId}/logs/stream`),
19030
- PublicationLogChunkDataSchema
19031
- );
19032
- }
19033
- async logs(id) {
19034
- return parseNdjsonStream(
19035
- await this.client.stream(`/publications/${id}/logs/stream`),
19036
- PublicationLogChunkDataSchema
19037
- );
19038
- }
19039
19046
  };
19040
19047
  var PublicationRun = class {
19041
19048
  constructor(initial, client) {
@@ -19154,14 +19161,22 @@ var PublicationInstance = class _PublicationInstance {
19154
19161
  const response = await this.client.get(`/publications/${this.data.id}`);
19155
19162
  return new _PublicationInstance(response.data, this.client, this.notebookId);
19156
19163
  }
19157
- publish() {
19164
+ async publish() {
19158
19165
  if (!this.notebookId) {
19159
19166
  return Promise.reject(new Error("Publishing requires a notebook-scoped publication instance."));
19160
19167
  }
19161
- return this.client.notebook.publication.publish(this.notebookId);
19168
+ const response = await this.client.post(
19169
+ `/notebook/${this.notebookId}/publication`
19170
+ );
19171
+ const run = new PublicationRun(
19172
+ new _PublicationInstance(response.data, this.client, this.notebookId),
19173
+ this.client
19174
+ );
19175
+ run.start();
19176
+ return run;
19162
19177
  }
19163
- destroy() {
19164
- return this.client.publications.destroy(this.data.id);
19178
+ async destroy() {
19179
+ await this.client.delete(`/publications/${this.data.id}`);
19165
19180
  }
19166
19181
  async wait(options = {}) {
19167
19182
  const intervalMs = options.intervalMs ?? 1e3;
@@ -19177,41 +19192,44 @@ var PublicationInstance = class _PublicationInstance {
19177
19192
  }
19178
19193
  return current;
19179
19194
  }
19180
- events() {
19181
- return this.client.publications.events(this.data.id);
19195
+ async events() {
19196
+ return parseNdjsonStream(
19197
+ await this.client.stream(`/publications/${this.data.id}/events/stream`),
19198
+ PublicationEventDataSchema
19199
+ );
19182
19200
  }
19183
19201
  buildLogs(buildId = this.data.latestBuild?.id ?? "") {
19184
19202
  if (buildId === "") {
19185
19203
  return Promise.reject(new Error("Publication has no latest build id"));
19186
19204
  }
19187
- return this.client.publications.buildLogs(this.data.id, buildId);
19188
- }
19189
- logs() {
19190
- return this.client.publications.logs(this.data.id);
19191
- }
19192
- setProtection(input) {
19193
- return this.client.publications.setProtection(this.data.id, input);
19194
- }
19195
- protection() {
19196
- return this.client.publications.protection(this.data.id);
19205
+ return this.client.stream(`/publications/${this.data.id}/builds/${buildId}/logs/stream`).then((stream) => parseNdjsonStream(stream, PublicationLogChunkDataSchema));
19197
19206
  }
19198
- createProtectionSession() {
19199
- return this.client.publications.createProtectionSession(this.data.id);
19200
- }
19201
- disableProtection() {
19202
- return this.client.publications.disableProtection(this.data.id);
19207
+ async logs() {
19208
+ return parseNdjsonStream(
19209
+ await this.client.stream(`/publications/${this.data.id}/logs/stream`),
19210
+ PublicationLogChunkDataSchema
19211
+ );
19203
19212
  }
19204
- domains() {
19205
- return this.client.publications.listDomains(this.data.id);
19213
+ async setProtection(input) {
19214
+ const response = await this.client.put(
19215
+ `/publications/${this.data.id}/protection`,
19216
+ input
19217
+ );
19218
+ return new _PublicationInstance(response.data, this.client, this.notebookId);
19206
19219
  }
19207
- addDomain(input) {
19208
- return this.client.publications.createDomain(this.data.id, input);
19220
+ async protection() {
19221
+ const response = await this.client.get(`/publications/${this.data.id}/protection`);
19222
+ return response.data;
19209
19223
  }
19210
- refreshDomain(domainId) {
19211
- return this.client.publications.refreshDomain(this.data.id, domainId);
19224
+ async createProtectionSession() {
19225
+ const response = await this.client.post(
19226
+ `/publications/${this.data.id}/protection/session`
19227
+ );
19228
+ return response.data;
19212
19229
  }
19213
- deleteDomain(domainId) {
19214
- return this.client.publications.deleteDomain(this.data.id, domainId);
19230
+ async disableProtection() {
19231
+ const response = await this.client.delete(`/publications/${this.data.id}/protection`);
19232
+ return new _PublicationInstance(response.data, this.client, this.notebookId);
19215
19233
  }
19216
19234
  };
19217
19235
  function publicationStatusIsTerminal(status) {
@@ -19220,12 +19238,6 @@ function publicationStatusIsTerminal(status) {
19220
19238
  function delay(ms) {
19221
19239
  return new Promise((resolve) => setTimeout(resolve, ms));
19222
19240
  }
19223
- function unwrapPublicationDomainCollection(input) {
19224
- if (Array.isArray(input)) {
19225
- return input;
19226
- }
19227
- return Array.isArray(input.data) ? input.data : [];
19228
- }
19229
19241
  var AsyncPublishEventQueue = class {
19230
19242
  constructor() {
19231
19243
  this.values = [];
@@ -19392,9 +19404,9 @@ var ServerApi = class {
19392
19404
  constructor(client) {
19393
19405
  this.client = client;
19394
19406
  }
19395
- async list() {
19396
- const response = await this.client.get("/servers");
19397
- return response.data;
19407
+ async list(options = {}) {
19408
+ const query = options.page === void 0 ? "" : `?${new URLSearchParams({ page: String(options.page) }).toString()}`;
19409
+ return this.client.get(`/servers${query}`);
19398
19410
  }
19399
19411
  async create(input) {
19400
19412
  const response = await this.client.post("/servers", input);
@@ -19404,9 +19416,6 @@ var ServerApi = class {
19404
19416
  const response = await this.client.get(`/servers/${id}`);
19405
19417
  return new ServerInstance(response.data, this.client);
19406
19418
  }
19407
- async delete(id) {
19408
- await this.client.delete(`/servers/${id}`);
19409
- }
19410
19419
  };
19411
19420
  var ServerInstance = class {
19412
19421
  constructor(data, client) {
@@ -19416,8 +19425,8 @@ var ServerInstance = class {
19416
19425
  refresh() {
19417
19426
  return this.client.servers.get(this.data.id);
19418
19427
  }
19419
- delete() {
19420
- return this.client.servers.delete(this.data.id);
19428
+ async delete() {
19429
+ await this.client.delete(`/servers/${this.data.id}`);
19421
19430
  }
19422
19431
  async waitReady(options) {
19423
19432
  const timeout2 = options?.timeout ?? 3e5;
@@ -19440,12 +19449,9 @@ var ServerInstance = class {
19440
19449
  // src/runtime/rest.ts
19441
19450
  var restActionRoutes = {
19442
19451
  "runtime.ready": { method: "GET", path: "/runtime" },
19443
- ping: { method: "GET", path: "/runtime/ping" },
19444
19452
  "config.get": { method: "GET", path: "/runtime/config" },
19445
19453
  "config.update": { method: "PATCH", path: "/runtime/config" },
19446
19454
  "config.set-ports": { method: "PUT", path: "/runtime/config/ports" },
19447
- "container.state": { method: "GET", path: "/runtime/container" },
19448
- "container.start": { method: "POST", path: "/runtime/container/start" },
19449
19455
  "container.restart": { method: "POST", path: "/runtime/container/restart" },
19450
19456
  "container.stop": { method: "POST", path: "/runtime/container/stop" },
19451
19457
  "container.set-php": { method: "PUT", path: "/runtime/container/php" },
@@ -19498,10 +19504,14 @@ var RestRuntimeInvoker = class {
19498
19504
  const actionUrl = new URL(runtimeUrl);
19499
19505
  const ticket = actionUrl.searchParams.get("ticket") ?? "";
19500
19506
  if (ticket === "") {
19501
- throw new UnsupportedRuntimeTransportError("The notebook connection does not contain a runtime ticket.");
19507
+ throw new PHPSandboxError("The notebook connection does not contain a runtime ticket.");
19502
19508
  }
19503
19509
  this.ticket = ticket;
19504
- actionUrl.protocol = actionUrl.protocol === "wss:" ? "https:" : "http:";
19510
+ if (actionUrl.protocol === "wss:") {
19511
+ actionUrl.protocol = "https:";
19512
+ } else if (actionUrl.protocol === "ws:") {
19513
+ actionUrl.protocol = "http:";
19514
+ }
19505
19515
  actionUrl.pathname = `/api/v1/notebooks/${encodeURIComponent(this.notebookId)}`;
19506
19516
  actionUrl.searchParams.delete("ticket");
19507
19517
  actionUrl.hash = "";
@@ -19517,27 +19527,28 @@ var RestRuntimeInvoker = class {
19517
19527
  return this.invokeRaw(action, data ?? {}, options);
19518
19528
  }
19519
19529
  send() {
19520
- throw new UnsupportedRuntimeTransportError("Fire-and-forget actions require the realtime transport.");
19530
+ throw new PHPSandboxError("Fire-and-forget actions require the realtime transport.");
19521
19531
  }
19522
19532
  async invokeRaw(action, data, options) {
19523
19533
  const abort = runtimeAbort(options);
19524
19534
  try {
19525
19535
  for (let attempt = 0; attempt < 2; attempt += 1) {
19526
- const response = await this.fetch(this.request(action, data, abort.signal));
19536
+ const response = await runtimeFetch(this.fetch, this.request(action, data, abort.signal));
19527
19537
  if (response.status === 401 && attempt === 0 && this.refresh !== void 0) {
19528
19538
  await this.refreshAuthorization();
19529
19539
  continue;
19530
19540
  }
19531
19541
  const payload = await runtimeActionResponse(response);
19532
19542
  if (!response.ok || payload.error !== void 0) {
19533
- const error51 = payload.error ?? payload;
19534
- const message = typeof error51.message === "string" ? error51.message : `Runtime action ${action} failed.`;
19535
- const code = typeof error51.code === "number" ? error51.code : response.status;
19536
- throw new ErrorEvent(code, message, error51);
19543
+ throw remoteError("runtime", payload.error, response);
19537
19544
  }
19538
19545
  return payload.data;
19539
19546
  }
19540
- throw new ErrorEvent(401, `Runtime action ${action} could not be authorized.`, {});
19547
+ throw new RemoteError(`Runtime action ${action} could not be authorized.`, {
19548
+ source: "runtime",
19549
+ status: 401,
19550
+ code: "AuthenticationRequired"
19551
+ });
19541
19552
  } finally {
19542
19553
  abort.dispose();
19543
19554
  }
@@ -19545,7 +19556,7 @@ var RestRuntimeInvoker = class {
19545
19556
  request(action, data, signal) {
19546
19557
  const route = restActionRoutes[action];
19547
19558
  if (route === void 0) {
19548
- throw new UnsupportedRuntimeTransportError(`Runtime action ${action} requires the realtime transport.`);
19559
+ throw new PHPSandboxError(`Runtime action ${action} requires the realtime transport.`);
19549
19560
  }
19550
19561
  const url2 = new URL(this.actionUrl);
19551
19562
  url2.pathname += route.path;
@@ -19558,7 +19569,8 @@ var RestRuntimeInvoker = class {
19558
19569
  method: route.method,
19559
19570
  headers,
19560
19571
  body: route.method === "GET" ? void 0 : body,
19561
- signal
19572
+ signal,
19573
+ redirect: "error"
19562
19574
  });
19563
19575
  }
19564
19576
  async refreshAuthorization() {
@@ -19572,18 +19584,31 @@ var RestRuntimeInvoker = class {
19572
19584
  }
19573
19585
  }
19574
19586
  };
19587
+ async function runtimeFetch(fetch, request) {
19588
+ try {
19589
+ return await fetch(request);
19590
+ } catch (error51) {
19591
+ if (error51 instanceof DOMException && error51.name === "AbortError") {
19592
+ throw error51;
19593
+ }
19594
+ throw new TransportError("Unable to reach the PHPSandbox runtime.", "ConnectionFailed", error51);
19595
+ }
19596
+ }
19575
19597
  async function runtimeActionResponse(response) {
19576
19598
  if (response.ok && response.headers.get("content-type")?.toLowerCase().startsWith("application/octet-stream")) {
19577
19599
  return { data: new Uint8Array(await response.arrayBuffer()) };
19578
19600
  }
19579
19601
  const body = await response.text();
19580
19602
  if (body === "") {
19603
+ if (response.ok) {
19604
+ throw new TransportError("PHPSandbox runtime returned an empty response.", "InvalidResponse", response);
19605
+ }
19581
19606
  return {};
19582
19607
  }
19583
19608
  try {
19584
19609
  return JSON.parse(body);
19585
- } catch {
19586
- return { error: { code: response.status, message: body } };
19610
+ } catch (error51) {
19611
+ throw new TransportError("PHPSandbox runtime returned an invalid JSON response.", "InvalidResponse", error51);
19587
19612
  }
19588
19613
  }
19589
19614
  function runtimeActionRequestBody(action, data, url2, headers) {
@@ -19677,10 +19702,9 @@ var Feedback = class {
19677
19702
  for (const [name, value] of Object.entries(options)) {
19678
19703
  if (value !== void 0) query.set(name, String(value));
19679
19704
  }
19680
- const response = await this.client.get(
19705
+ return this.client.get(
19681
19706
  `${this.path()}${query.size === 0 ? "" : `?${query.toString()}`}`
19682
19707
  );
19683
- return response.data;
19684
19708
  }
19685
19709
  async get(id) {
19686
19710
  const response = await this.client.get(this.path(`/${encodeURIComponent(id)}`));
@@ -19712,18 +19736,8 @@ var IntegrationApi = class {
19712
19736
  const response = await this.client.get(`/integrations/${encodeURIComponent(integrationId(integration))}`);
19713
19737
  return new Integration(response.data, this.client);
19714
19738
  }
19715
- async update(integration, input) {
19716
- const response = await this.client.patch(
19717
- `/integrations/${encodeURIComponent(integrationId(integration))}`,
19718
- input
19719
- );
19720
- return new Integration(response.data, this.client);
19721
- }
19722
- async unlink(integration) {
19723
- await this.client.delete(`/integrations/${encodeURIComponent(integrationId(integration))}`);
19724
- }
19725
19739
  };
19726
- var Integration = class {
19740
+ var Integration = class _Integration {
19727
19741
  constructor(data, client) {
19728
19742
  this.data = data;
19729
19743
  this.client = client;
@@ -19737,11 +19751,15 @@ var Integration = class {
19737
19751
  get label() {
19738
19752
  return this.data.label;
19739
19753
  }
19740
- update(input) {
19741
- return new IntegrationApi(this.client).update(this, input);
19754
+ async update(input) {
19755
+ const response = await this.client.patch(
19756
+ `/integrations/${encodeURIComponent(this.id)}`,
19757
+ input
19758
+ );
19759
+ return new _Integration(response.data, this.client);
19742
19760
  }
19743
- unlink() {
19744
- return new IntegrationApi(this.client).unlink(this);
19761
+ async unlink() {
19762
+ await this.client.delete(`/integrations/${encodeURIComponent(this.id)}`);
19745
19763
  }
19746
19764
  };
19747
19765
  function integrationId(integration) {
@@ -19769,16 +19787,6 @@ var SandboxIntegrationApi = class {
19769
19787
  const response = await this.client.get(this.bindingPath(integration));
19770
19788
  return new SandboxIntegration(response.data, this.notebookId, this.client);
19771
19789
  }
19772
- async update(integration, input) {
19773
- const response = await this.client.patch(this.bindingPath(integration), {
19774
- ...input,
19775
- integration: input.integration === void 0 ? void 0 : integrationId(input.integration)
19776
- });
19777
- return new SandboxIntegration(response.data, this.notebookId, this.client);
19778
- }
19779
- async detach(integration) {
19780
- await this.client.delete(this.bindingPath(integration));
19781
- }
19782
19790
  path() {
19783
19791
  return `/notebook/${this.notebookId}/integrations`;
19784
19792
  }
@@ -19786,7 +19794,7 @@ var SandboxIntegrationApi = class {
19786
19794
  return `${this.path()}/${encodeURIComponent(sandboxIntegrationId(integration))}`;
19787
19795
  }
19788
19796
  };
19789
- var SandboxIntegration = class {
19797
+ var SandboxIntegration = class _SandboxIntegration {
19790
19798
  constructor(data, notebookId, client) {
19791
19799
  this.data = data;
19792
19800
  this.notebookId = notebookId;
@@ -19801,11 +19809,18 @@ var SandboxIntegration = class {
19801
19809
  get effects() {
19802
19810
  return this.data.effects;
19803
19811
  }
19804
- update(input) {
19805
- return new SandboxIntegrationApi(this.notebookId, this.client).update(this, input);
19812
+ async update(input) {
19813
+ const response = await this.client.patch(this.path(), {
19814
+ ...input,
19815
+ integration: input.integration === void 0 ? void 0 : integrationId(input.integration)
19816
+ });
19817
+ return new _SandboxIntegration(response.data, this.notebookId, this.client);
19818
+ }
19819
+ async detach() {
19820
+ await this.client.delete(this.path());
19806
19821
  }
19807
- detach() {
19808
- return new SandboxIntegrationApi(this.notebookId, this.client).detach(this);
19822
+ path() {
19823
+ return `/notebook/${this.notebookId}/integrations/${encodeURIComponent(this.id)}`;
19809
19824
  }
19810
19825
  };
19811
19826
  function sandboxIntegrationId(integration) {
@@ -19822,87 +19837,20 @@ function normalizeNotebookSecretInputs(input) {
19822
19837
  ...typeof value === "string" ? { value } : value
19823
19838
  }));
19824
19839
  }
19825
- var NotebookInitError = class extends Error {
19826
- constructor(message, data = {}) {
19827
- super(message);
19828
- this.message = message;
19829
- this.data = data;
19830
- this.name = "NotebookInitError";
19831
- }
19832
- };
19833
- var ApiError = class extends Error {
19834
- constructor(response, body) {
19835
- const data = parseApiErrorBody(body);
19836
- const apiMessage = apiErrorMessage(data, body);
19837
- super(`PHPSandbox API Error: ${response.status} ${response.statusText}${apiMessage === "" ? "" : ` - ${apiMessage}`}`);
19838
- this.response = response;
19839
- this.body = body;
19840
- this.status = response.status;
19841
- this.data = data;
19842
- this.apiMessage = apiMessage === "" ? void 0 : apiMessage;
19843
- }
19844
- };
19845
- function parseApiErrorBody(body) {
19846
- try {
19847
- return JSON.parse(body);
19848
- } catch {
19849
- return null;
19850
- }
19851
- }
19852
- function apiErrorMessage(data, fallback) {
19853
- if (data !== null && typeof data === "object") {
19854
- const record2 = data;
19855
- if (typeof record2.message === "string" && record2.message.trim() !== "") {
19856
- return record2.message.trim();
19857
- }
19858
- if (record2.error !== void 0) {
19859
- return typeof record2.error === "string" ? record2.error.trim() : JSON.stringify(record2.error);
19860
- }
19861
- }
19862
- return fallback.trim();
19863
- }
19864
19840
  var NotebookApi = class {
19865
19841
  constructor(client) {
19866
19842
  this.client = client;
19867
- this.secrets = new NotebookSecretApi(client);
19868
- this.composerCredentials = new NotebookComposerCredentialApi(client);
19869
- this.preview = new NotebookPreviewApi(client);
19870
- this.mail = new NotebookMailApi(client);
19871
- this.publication = new NotebookPublicationApi(client);
19872
19843
  }
19873
- async create(template, input = {}, init = true) {
19844
+ async create(template, input = {}) {
19874
19845
  const response = await this.client.post("/notebook", { template, ...input });
19875
- const instance = new NotebookInstance(response.data, this.client);
19876
- if (!init) {
19877
- return instance;
19878
- }
19879
- return this.init(instance);
19846
+ return new NotebookInstance(response.data, this.client);
19880
19847
  }
19881
19848
  async get(id) {
19882
19849
  const response = await this.client.get(`/notebook/${id}`);
19883
19850
  return new NotebookInstance(response.data, this.client);
19884
19851
  }
19885
- async update(id, input = {}) {
19886
- const response = await this.client.put(`/notebook/${id}`, input);
19887
- return new NotebookInstance(response.data, this.client);
19888
- }
19889
- async destroy(id) {
19890
- await this.client.delete(`/notebook/${id}`);
19891
- }
19892
- async fork(id, input = {}) {
19893
- const response = await this.client.post(`/notebook/${id}/fork`, input);
19894
- return new NotebookInstance(response.data, this.client);
19895
- }
19896
- async gitCredentials(id) {
19897
- const response = await this.client.post(`/notebook/${id}/git/credentials`);
19898
- return response.data;
19899
- }
19900
- openFromData(data) {
19901
- return this.init(new NotebookInstance(data, this.client));
19902
- }
19903
- async init(instance) {
19904
- await instance.ready();
19905
- return instance;
19852
+ open(data) {
19853
+ return new NotebookInstance(data, this.client);
19906
19854
  }
19907
19855
  };
19908
19856
  function normalizeApiBaseUrl(url2) {
@@ -19913,15 +19861,15 @@ function normalizeApiBaseUrl(url2) {
19913
19861
  baseUrl.hash = "";
19914
19862
  return baseUrl.toString();
19915
19863
  }
19916
- var Client = class {
19917
- constructor(token, url2 = "https://api.phpsandbox.io/v1", options = {}) {
19918
- this.runtimeTransportValue = "realtime";
19864
+ var ClientImplementation = class {
19865
+ constructor(token, url2 = "https://api.phpsandbox.io/v1", options = {}, runtimeTransport = "realtime") {
19919
19866
  this.fetch = globalThis.fetch;
19920
19867
  this.publications = new PublicationApi(this);
19921
19868
  this.notebook = new NotebookApi(this);
19922
19869
  this.servers = new ServerApi(this);
19923
19870
  this.integrations = new IntegrationApi(this);
19924
- this.options = Object.assign({ startClosed: true }, options);
19871
+ this.options = { ...options };
19872
+ this.runtimeTransportValue = runtimeTransport;
19925
19873
  this.baseUrl = normalizeApiBaseUrl(url2);
19926
19874
  if (options.fetch) {
19927
19875
  this.fetch = options.fetch;
@@ -19951,24 +19899,26 @@ var Client = class {
19951
19899
  return this.makeRequest("PATCH", path, { body: body === void 0 ? void 0 : JSON.stringify(body) });
19952
19900
  }
19953
19901
  async stream(path) {
19954
- const response = await this.fetch(
19902
+ const response = await this.fetchResponse(
19955
19903
  new Request(new URL(path.replace(/^\//, ""), this.baseUrl), {
19956
19904
  method: "GET",
19957
- headers: this.headers
19905
+ headers: this.headers,
19906
+ redirect: "error"
19958
19907
  })
19959
19908
  );
19960
19909
  if (!response.ok) {
19961
- throw new ApiError(response, await response.text());
19910
+ throw remoteError("core", errorPayload(await responsePayload(response)), response);
19962
19911
  }
19963
19912
  if (!response.body) {
19964
- throw new Error("PHPSandbox API Error: response body is not readable");
19913
+ throw new TransportError("PHPSandbox API response body is not readable.", "InvalidResponse", response);
19965
19914
  }
19966
19915
  return response.body;
19967
19916
  }
19968
19917
  async sse(url2) {
19969
- const response = await this.fetch(
19918
+ const response = await this.fetchResponse(
19970
19919
  new Request(url2, {
19971
19920
  method: "GET",
19921
+ redirect: "error",
19972
19922
  headers: {
19973
19923
  ...this.headers,
19974
19924
  "Accept": "text/event-stream"
@@ -19976,140 +19926,90 @@ var Client = class {
19976
19926
  })
19977
19927
  );
19978
19928
  if (!response.ok) {
19979
- throw new ApiError(response, await response.text());
19929
+ throw remoteError("core", errorPayload(await responsePayload(response)), response);
19980
19930
  }
19981
19931
  if (!response.body) {
19982
- throw new Error("PHPSandbox API Error: SSE response body is not readable");
19932
+ throw new TransportError("PHPSandbox API SSE response body is not readable.", "InvalidResponse", response);
19983
19933
  }
19984
19934
  return response.body;
19985
19935
  }
19986
19936
  async makeRequest(method, path, init) {
19987
- const response = await this.fetch(
19937
+ const response = await this.fetchResponse(
19988
19938
  new Request(new URL(path.replace(/^\//, ""), this.baseUrl), {
19989
19939
  method,
19990
19940
  ...init,
19991
- headers: this.headers
19941
+ headers: this.headers,
19942
+ redirect: "error"
19992
19943
  })
19993
19944
  );
19994
19945
  if (!response.ok) {
19995
- throw new ApiError(response, await response.text());
19946
+ throw remoteError("core", errorPayload(await responsePayload(response)), response);
19996
19947
  }
19997
19948
  if (response.status === 204) {
19998
19949
  return { data: void 0 };
19999
19950
  }
20000
19951
  const body = await response.text();
20001
- return { data: body === "" ? void 0 : JSON.parse(body) };
20002
- }
20003
- };
20004
- var PHPSandbox = class _PHPSandbox extends Client {
20005
- static realtime(token, url2 = "https://api.phpsandbox.io/v1", options = {}) {
20006
- return new _PHPSandbox(token, url2, options);
20007
- }
20008
- static rest(token, url2 = "https://api.phpsandbox.io/v1", options = {}) {
20009
- const client = new _PHPSandbox(token, url2, options);
20010
- client.runtimeTransportValue = "rest";
20011
- return client;
20012
- }
20013
- };
20014
- var NotebookSecretApi = class {
20015
- constructor(client) {
20016
- this.client = client;
20017
- }
20018
- async list(id, options) {
20019
- const params = new URLSearchParams();
20020
- if (options?.environment) params.set("environment", options.environment);
20021
- const query = params.toString();
20022
- const response = await this.client.get(`/notebook/${id}/secrets${query ? `?${query}` : ""}`);
20023
- return response.data;
20024
- }
20025
- async set(id, name, input) {
20026
- const payload = typeof input === "string" ? { name, value: input } : { name, ...input };
20027
- const response = await this.client.put(`/notebook/${id}/secrets`, payload);
20028
- return response.data;
20029
- }
20030
- async setMany(id, input) {
20031
- const response = await this.client.put(`/notebook/${id}/secrets`, {
20032
- secrets: normalizeNotebookSecretInputs(input)
20033
- });
20034
- return response.data;
20035
- }
20036
- async delete(id, name, options) {
20037
- const params = new URLSearchParams();
20038
- if (options?.environment) params.set("environment", options.environment);
20039
- const query = params.toString();
20040
- await this.client.delete(`/notebook/${id}/secrets/${encodeURIComponent(name)}${query ? `?${query}` : ""}`);
20041
- }
20042
- };
20043
- var NotebookComposerCredentialApi = class {
20044
- constructor(client) {
20045
- this.client = client;
20046
- }
20047
- async set(id, input) {
20048
- const response = await this.client.put(`/notebook/${id}/composer/credentials`, input);
20049
- return response.data;
19952
+ if (body === "") {
19953
+ throw new TransportError("PHPSandbox API returned an empty response.", "InvalidResponse", response);
19954
+ }
19955
+ try {
19956
+ const payload = JSON.parse(body);
19957
+ if (payload === null || typeof payload !== "object" || Array.isArray(payload) || !Object.prototype.hasOwnProperty.call(payload, "data")) {
19958
+ throw new TransportError("PHPSandbox API returned an invalid success response.", "InvalidResponse", response);
19959
+ }
19960
+ return payload;
19961
+ } catch (error51) {
19962
+ if (TransportError.is(error51)) {
19963
+ throw error51;
19964
+ }
19965
+ throw new TransportError("PHPSandbox API returned an invalid JSON response.", "InvalidResponse", error51);
19966
+ }
20050
19967
  }
20051
- async remove(id, type, url2) {
20052
- const params = new URLSearchParams({ type });
20053
- if (url2) params.set("url", url2);
20054
- await this.client.delete(`/notebook/${id}/composer/credentials?${params.toString()}`);
19968
+ async fetchResponse(request) {
19969
+ try {
19970
+ return await this.fetch(request);
19971
+ } catch (error51) {
19972
+ if (error51 instanceof DOMException && error51.name === "AbortError") {
19973
+ throw error51;
19974
+ }
19975
+ throw new TransportError("Unable to reach the PHPSandbox API.", "ConnectionFailed", error51);
19976
+ }
20055
19977
  }
20056
19978
  };
20057
- var NotebookPreviewApi = class {
20058
- constructor(client) {
20059
- this.client = client;
20060
- }
20061
- async get(id, url2) {
20062
- const query = url2 === void 0 ? "" : `?${new URLSearchParams({ url: url2 }).toString()}`;
20063
- const response = await this.client.get(`/notebook/${id}/preview${query}`);
20064
- return response.data;
20065
- }
20066
- async setPassword(id, input) {
20067
- const response = await this.client.put(`/notebook/${id}/preview`, input);
20068
- return response.data;
20069
- }
20070
- async disable(id) {
20071
- await this.client.delete(`/notebook/${id}/preview`);
20072
- }
20073
- async createSession(id, input) {
20074
- const response = await this.client.post(`/notebook/${id}/preview/session`, input);
20075
- return response.data;
19979
+ async function responsePayload(response) {
19980
+ const body = await response.text();
19981
+ if (body === "") {
19982
+ return void 0;
20076
19983
  }
20077
- async createHandoff(id, input) {
20078
- const response = await this.client.post(`/notebook/${id}/preview/handoff`, input);
20079
- return response.data;
19984
+ try {
19985
+ return JSON.parse(body);
19986
+ } catch (error51) {
19987
+ throw new TransportError("PHPSandbox API returned an invalid JSON response.", "InvalidResponse", error51);
20080
19988
  }
20081
- };
20082
- var NotebookMailApi = class {
19989
+ }
19990
+ function errorPayload(payload) {
19991
+ return payload !== null && typeof payload === "object" && !Array.isArray(payload) ? payload.error : void 0;
19992
+ }
19993
+ var PHPSandbox = class _PHPSandbox {
20083
19994
  constructor(client) {
20084
19995
  this.client = client;
19996
+ this.notebook = client.notebook;
19997
+ this.publications = client.publications;
19998
+ this.servers = client.servers;
19999
+ this.integrations = client.integrations;
20085
20000
  }
20086
- async status(id) {
20087
- const response = await this.client.get(`/notebook/${id}/mail`);
20088
- return response.data;
20089
- }
20090
- async enable(id) {
20091
- const response = await this.client.put(`/notebook/${id}/mail`);
20092
- return response.data;
20093
- }
20094
- async disable(id) {
20095
- await this.client.delete(`/notebook/${id}/mail`);
20096
- }
20097
- async list(id, options = {}) {
20098
- const response = await this.client.get(
20099
- `/notebook/${id}/mails${formatQueryString(options)}`
20100
- );
20101
- return response.data;
20001
+ get runtimeTransport() {
20002
+ return this.client.runtimeTransport;
20102
20003
  }
20103
- async get(id, hash2) {
20104
- const response = await this.client.get(`/notebook/${id}/mails/${encodeURIComponent(hash2)}`);
20105
- return response.data;
20004
+ static realtime(token, url2 = "https://api.phpsandbox.io/v1", options = {}) {
20005
+ return new _PHPSandbox(new ClientImplementation(token, url2, options));
20106
20006
  }
20107
- async delete(id, hash2) {
20108
- await this.client.delete(`/notebook/${id}/mails/${encodeURIComponent(hash2)}`);
20007
+ static rest(token, url2 = "https://api.phpsandbox.io/v1", options = {}) {
20008
+ return new _PHPSandbox(new ClientImplementation(token, url2, options, "rest"));
20109
20009
  }
20110
20010
  };
20111
20011
  var _initPromise, _NotebookInstance_instances, init_fn;
20112
- var NotebookInstance = class {
20012
+ var _NotebookInstance = class _NotebookInstance {
20113
20013
  constructor(data, client) {
20114
20014
  this.data = data;
20115
20015
  this.client = client;
@@ -20138,7 +20038,6 @@ var NotebookInstance = class {
20138
20038
  };
20139
20039
  this.socket = new Transport(connectionUrl, this.emitter, {
20140
20040
  debug: client.options.debug,
20141
- startClosed: client.options.startClosed,
20142
20041
  webSocket: client.options.webSocket
20143
20042
  });
20144
20043
  this.watchConnection();
@@ -20152,12 +20051,8 @@ var NotebookInstance = class {
20152
20051
  this.auth = new Auth(this);
20153
20052
  this.lsp = new Lsp(this);
20154
20053
  this.composer = new Composer(this, client);
20155
- const telemetry = new RuntimeTelemetry(this);
20156
- this.logs = new Logs(this, telemetry);
20157
- this.metrics = new Metrics(this, telemetry);
20158
- this.ports = new Ports(this, telemetry);
20054
+ this.runtime = new Runtime(this);
20159
20055
  this.repl = new Repl(this);
20160
- this.container = new Container(this);
20161
20056
  this.shell = new Shell(this);
20162
20057
  this.git = new Git(this, client);
20163
20058
  this.services = new Services(this);
@@ -20181,21 +20076,33 @@ var NotebookInstance = class {
20181
20076
  throw terminalError;
20182
20077
  }
20183
20078
  const ready = async () => {
20184
- if (this.client.options.startClosed && !socket.isConnected) {
20079
+ if (!socket.isConnected) {
20185
20080
  await socket.connect();
20186
20081
  }
20187
20082
  return __privateGet(this, _initPromise);
20188
20083
  };
20189
20084
  return ready();
20190
20085
  }
20191
- fork(input = {}) {
20192
- return this.client.notebook.fork(this.data.id, input);
20086
+ async fork(input = {}) {
20087
+ const response = await this.client.post(`/notebook/${this.data.id}/fork`, input);
20088
+ return new _NotebookInstance(response.data, this.client);
20193
20089
  }
20194
- publication() {
20195
- return this.client.notebook.publication.current(this.data.id);
20090
+ async publication() {
20091
+ try {
20092
+ const response = await this.client.get(`/notebook/${this.data.id}/publication`);
20093
+ return new PublicationInstance(response.data, this.client, this.data.id);
20094
+ } catch (error51) {
20095
+ if (RemoteError.is(error51) && error51.status === 404) {
20096
+ return null;
20097
+ }
20098
+ throw error51;
20099
+ }
20196
20100
  }
20197
- publish(input) {
20198
- return this.client.notebook.publication.publish(this.data.id, input);
20101
+ async publish(input) {
20102
+ const response = await this.client.post(`/notebook/${this.data.id}/publication`, input);
20103
+ const run = new PublicationRun(new PublicationInstance(response.data, this.client, this.data.id), this.client);
20104
+ run.start();
20105
+ return run;
20199
20106
  }
20200
20107
  run(command, argsOrOpts = [], opts) {
20201
20108
  if (Array.isArray(argsOrOpts)) {
@@ -20209,19 +20116,20 @@ var NotebookInstance = class {
20209
20116
  }
20210
20117
  return this.run(command, argsOrOpts).wait();
20211
20118
  }
20212
- gitCredentials() {
20213
- return this.client.notebook.gitCredentials(this.data.id);
20119
+ async destroy() {
20120
+ await this.client.delete(`/notebook/${this.data.id}`);
20121
+ this.socket?.terminate(new RemoteError("Notebook has been deleted.", {
20122
+ source: "runtime",
20123
+ status: 503,
20124
+ code: "NotebookUnavailable",
20125
+ details: { id: this.data.id }
20126
+ }));
20214
20127
  }
20215
- destroy() {
20216
- return this.client.notebook.destroy(this.data.id).then(() => {
20217
- this.socket?.terminate(new NotebookUnavailableError("Notebook has been deleted.", { id: this.data.id }));
20218
- });
20128
+ restart() {
20129
+ return this.invoke("container.restart");
20219
20130
  }
20220
20131
  stop() {
20221
- return this.container.stop();
20222
- }
20223
- restart() {
20224
- return this.container.restart();
20132
+ return this.invoke("container.stop");
20225
20133
  }
20226
20134
  invoke(action, data = {}, options = {}) {
20227
20135
  if (this.restInvoker !== null) {
@@ -20238,9 +20146,6 @@ var NotebookInstance = class {
20238
20146
  }
20239
20147
  return this.realtimeSocket().send(action, data || {});
20240
20148
  }
20241
- ping() {
20242
- return this.invoke("ping");
20243
- }
20244
20149
  listen(event, handler) {
20245
20150
  const disposable = this.emitter.listen(event, handler);
20246
20151
  this.disposables.push(disposable);
@@ -20255,9 +20160,6 @@ var NotebookInstance = class {
20255
20160
  connected() {
20256
20161
  return this.waitForSocketConnection({ rejectOnClose: true });
20257
20162
  }
20258
- whenConnected() {
20259
- return this.waitForSocketConnection({ rejectOnClose: false });
20260
- }
20261
20163
  waitForSocketConnection(options) {
20262
20164
  const socket = this.realtimeSocket();
20263
20165
  const terminalError = socket.getTerminalError();
@@ -20329,7 +20231,7 @@ var NotebookInstance = class {
20329
20231
  }
20330
20232
  restInitialization() {
20331
20233
  if (this.restInvoker === null) {
20332
- throw new UnsupportedRuntimeTransportError("This operation requires the REST transport.");
20234
+ throw new PHPSandboxError("This operation requires the REST transport.");
20333
20235
  }
20334
20236
  if (__privateGet(this, _initPromise) === null) {
20335
20237
  __privateSet(this, _initPromise, this.restInvoker.ready().then((result) => {
@@ -20342,15 +20244,12 @@ var NotebookInstance = class {
20342
20244
  }
20343
20245
  return __privateGet(this, _initPromise);
20344
20246
  }
20345
- update(input) {
20346
- return this.client.notebook.update(this.data.id, input);
20347
- }
20348
20247
  onDidInitialize(handler) {
20349
20248
  return this.listen("notebook.initialized", handler);
20350
20249
  }
20351
20250
  async reconnect() {
20352
20251
  const socket = this.realtimeSocket();
20353
- const whenConnected = this.whenConnected();
20252
+ const whenConnected = this.waitForSocketConnection({ rejectOnClose: false });
20354
20253
  socket.reconnect();
20355
20254
  this.initialized = false;
20356
20255
  await whenConnected;
@@ -20359,7 +20258,7 @@ var NotebookInstance = class {
20359
20258
  }
20360
20259
  realtimeSocket() {
20361
20260
  if (this.socket === null) {
20362
- throw new UnsupportedRuntimeTransportError("This operation requires the realtime transport.");
20261
+ throw new PHPSandboxError("This operation requires the realtime transport.");
20363
20262
  }
20364
20263
  return this.socket;
20365
20264
  }
@@ -20373,7 +20272,12 @@ init_fn = function() {
20373
20272
  initializationListener.dispose();
20374
20273
  this.initialized = result;
20375
20274
  if (result.type === "error") {
20376
- reject(new NotebookInitError(result.message, result.data));
20275
+ reject(new RemoteError(result.message, {
20276
+ source: "runtime",
20277
+ status: 503,
20278
+ code: "NotebookInitializationFailed",
20279
+ details: result.data
20280
+ }));
20377
20281
  return;
20378
20282
  }
20379
20283
  resolve(result);
@@ -20388,34 +20292,39 @@ init_fn = function() {
20388
20292
  });
20389
20293
  return __privateGet(this, _initPromise);
20390
20294
  };
20295
+ var NotebookInstance = _NotebookInstance;
20391
20296
  var NotebookSecrets = class {
20392
20297
  constructor(client, notebookId) {
20393
20298
  this.client = client;
20394
20299
  this.notebookId = notebookId;
20395
20300
  }
20396
- list(options) {
20397
- return this.client.notebook.secrets.list(this.notebookId, options);
20398
- }
20399
- set(name, input) {
20400
- return this.client.notebook.secrets.set(this.notebookId, name, input);
20401
- }
20402
- setMany(input) {
20403
- return this.client.notebook.secrets.setMany(this.notebookId, input);
20404
- }
20405
- delete(name, options) {
20406
- return this.client.notebook.secrets.delete(this.notebookId, name, options);
20301
+ async list(options) {
20302
+ const params = new URLSearchParams();
20303
+ if (options?.environment) params.set("environment", options.environment);
20304
+ const query = params.toString();
20305
+ const response = await this.client.get(
20306
+ `/notebook/${this.notebookId}/secrets${query ? `?${query}` : ""}`
20307
+ );
20308
+ return response.data;
20407
20309
  }
20408
- };
20409
- var ComposerCredentials = class {
20410
- constructor(client, notebookId) {
20411
- this.client = client;
20412
- this.notebookId = notebookId;
20310
+ async set(name, input) {
20311
+ const payload = typeof input === "string" ? { name, value: input } : { name, ...input };
20312
+ const response = await this.client.put(`/notebook/${this.notebookId}/secrets`, payload);
20313
+ return response.data;
20413
20314
  }
20414
- set(input) {
20415
- return this.client.notebook.composerCredentials.set(this.notebookId, input);
20315
+ async setMany(input) {
20316
+ const response = await this.client.put(`/notebook/${this.notebookId}/secrets`, {
20317
+ secrets: normalizeNotebookSecretInputs(input)
20318
+ });
20319
+ return response.data;
20416
20320
  }
20417
- remove(type, url2) {
20418
- return this.client.notebook.composerCredentials.remove(this.notebookId, type, url2);
20321
+ async delete(name, options) {
20322
+ const params = new URLSearchParams();
20323
+ if (options?.environment) params.set("environment", options.environment);
20324
+ const query = params.toString();
20325
+ await this.client.delete(
20326
+ `/notebook/${this.notebookId}/secrets/${encodeURIComponent(name)}${query ? `?${query}` : ""}`
20327
+ );
20419
20328
  }
20420
20329
  };
20421
20330
  var NotebookPreview = class {
@@ -20423,20 +20332,31 @@ var NotebookPreview = class {
20423
20332
  this.client = client;
20424
20333
  this.notebookId = notebookId;
20425
20334
  }
20426
- get(url2) {
20427
- return this.client.notebook.preview.get(this.notebookId, url2);
20335
+ async get(url2) {
20336
+ const query = url2 === void 0 ? "" : `?${new URLSearchParams({ url: url2 }).toString()}`;
20337
+ const response = await this.client.get(`/notebook/${this.notebookId}/preview${query}`);
20338
+ return response.data;
20428
20339
  }
20429
- setPassword(input) {
20430
- return this.client.notebook.preview.setPassword(this.notebookId, input);
20340
+ async setPassword(input) {
20341
+ const response = await this.client.put(`/notebook/${this.notebookId}/preview`, input);
20342
+ return response.data;
20431
20343
  }
20432
- disable() {
20433
- return this.client.notebook.preview.disable(this.notebookId);
20344
+ async disable() {
20345
+ await this.client.delete(`/notebook/${this.notebookId}/preview`);
20434
20346
  }
20435
- createSession(input) {
20436
- return this.client.notebook.preview.createSession(this.notebookId, input);
20347
+ async createSession(input) {
20348
+ const response = await this.client.post(
20349
+ `/notebook/${this.notebookId}/preview/session`,
20350
+ input
20351
+ );
20352
+ return response.data;
20437
20353
  }
20438
- createHandoff(input) {
20439
- return this.client.notebook.preview.createHandoff(this.notebookId, input);
20354
+ async createHandoff(input) {
20355
+ const response = await this.client.post(
20356
+ `/notebook/${this.notebookId}/preview/handoff`,
20357
+ input
20358
+ );
20359
+ return response.data;
20440
20360
  }
20441
20361
  };
20442
20362
  var NotebookMail = class {
@@ -20444,23 +20364,30 @@ var NotebookMail = class {
20444
20364
  this.client = client;
20445
20365
  this.notebookId = notebookId;
20446
20366
  }
20447
- status() {
20448
- return this.client.notebook.mail.status(this.notebookId);
20367
+ async status() {
20368
+ const response = await this.client.get(`/notebook/${this.notebookId}/mail`);
20369
+ return response.data;
20449
20370
  }
20450
- enable() {
20451
- return this.client.notebook.mail.enable(this.notebookId);
20371
+ async enable() {
20372
+ const response = await this.client.put(`/notebook/${this.notebookId}/mail`);
20373
+ return response.data;
20452
20374
  }
20453
- disable() {
20454
- return this.client.notebook.mail.disable(this.notebookId);
20375
+ async disable() {
20376
+ await this.client.delete(`/notebook/${this.notebookId}/mail`);
20455
20377
  }
20456
- list(options = {}) {
20457
- return this.client.notebook.mail.list(this.notebookId, options);
20378
+ async list(options = {}) {
20379
+ return this.client.get(
20380
+ `/notebook/${this.notebookId}/mails${formatQueryString(options)}`
20381
+ );
20458
20382
  }
20459
- get(hash2) {
20460
- return this.client.notebook.mail.get(this.notebookId, hash2);
20383
+ async get(hash2) {
20384
+ const response = await this.client.get(
20385
+ `/notebook/${this.notebookId}/mails/${encodeURIComponent(hash2)}`
20386
+ );
20387
+ return response.data;
20461
20388
  }
20462
- delete(hash2) {
20463
- return this.client.notebook.mail.delete(this.notebookId, hash2);
20389
+ async delete(hash2) {
20390
+ await this.client.delete(`/notebook/${this.notebookId}/mails/${encodeURIComponent(hash2)}`);
20464
20391
  }
20465
20392
  };
20466
20393
  function formatQueryString(params) {
@@ -20474,88 +20401,17 @@ function formatQueryString(params) {
20474
20401
  return query === "" ? "" : `?${query}`;
20475
20402
  }
20476
20403
  export {
20477
- ApiError,
20478
- Client,
20479
- CommandError,
20480
- ComposerCredentials,
20481
- ErrorEvent,
20482
- Feedback,
20483
20404
  FileChangeFilter,
20484
20405
  FileChangeType,
20485
20406
  FileType,
20486
- Filesystem,
20487
- FilesystemError,
20488
- FilesystemErrorType,
20489
- GitTarget,
20490
- GitTargetApi,
20491
- Integration,
20492
- IntegrationApi,
20493
20407
  LspConnection,
20494
- NotebookApi,
20495
- NotebookComposerCredentialApi,
20496
- NotebookInitError,
20497
20408
  NotebookInstance,
20498
- NotebookMail,
20499
- NotebookMailApi,
20500
- NotebookPreview,
20501
- NotebookPreviewApi,
20502
- NotebookPublicationApi,
20503
- NotebookSecretApi,
20504
- NotebookSecrets,
20505
- NotebookState,
20506
- NotebookUnavailableError,
20507
20409
  PHPSandbox,
20508
20410
  PHPSandboxError,
20509
- ProcessReadable,
20510
- ProcessResult,
20511
- PromiseTimeoutError,
20512
- PublicationApi,
20513
- PublicationBuildStatusSchema,
20514
- PublicationDomainDnsRecordTypeSchema,
20515
- PublicationEventDataSchema,
20516
- PublicationInstance,
20517
- PublicationJurisdictionSchema,
20518
- PublicationLogChunkDataSchema,
20519
- PublicationLogStreamSchema,
20520
- PublicationProtectionModeSchema,
20521
- PublicationProviderNameSchema,
20522
- PublicationRegionSchema,
20523
- PublicationReleaseStatusSchema,
20524
- PublicationRun,
20525
- PublicationSizeSchema,
20526
- PublicationStatusSchema,
20527
- PublishStreamErrorSchema,
20528
- PublishStreamEventSchema,
20529
- PublishStreamLogEventSchema,
20530
- PublishStreamLogSchema,
20531
- PublishStreamLogStreamSchema,
20532
- PublishStreamPhaseEventSchema,
20533
- PublishStreamPhaseSchema,
20534
- PublishStreamResultEventSchema,
20535
- PublishStreamResultSchema,
20536
- PublishStreamSseDoneEventSchema,
20537
- PublishStreamSseErrorEventSchema,
20538
- PublishStreamSseEventNameSchema,
20539
- PublishStreamSseEventSchema,
20540
- PublishStreamSseLogEventSchema,
20541
- PublishStreamSsePhaseEventSchema,
20542
- PublishStreamSseResultEventSchema,
20543
- RateLimitError,
20544
- RuntimeTelemetry,
20545
- SandboxIntegration,
20546
- SandboxIntegrationApi,
20547
- SendTimeoutError,
20548
- ServerApi,
20549
- ServerInstance,
20550
- ShellProcess,
20551
- UnsupportedRuntimeTransportError,
20552
- integrationId,
20411
+ RemoteError,
20412
+ TransportError,
20553
20413
  notebookBuiltinServices,
20554
- notebookKnownServices,
20555
- once,
20556
- sandboxIntegrationId,
20557
- timeout,
20558
- watchRuntimeTelemetry
20414
+ notebookKnownServices
20559
20415
  };
20560
20416
  /*! Bundled license information:
20561
20417