@secure-exec/core 0.1.1-rc.1 → 0.1.1-rc.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bridge.js CHANGED
@@ -5961,6 +5961,21 @@ var bridge = (() => {
5961
5961
  classification: "hardened",
5962
5962
  rationale: "Host-to-sandbox HTTP server dispatch entrypoint."
5963
5963
  },
5964
+ {
5965
+ name: "_httpServerUpgradeDispatch",
5966
+ classification: "hardened",
5967
+ rationale: "Host-to-sandbox HTTP server upgrade dispatch entrypoint."
5968
+ },
5969
+ {
5970
+ name: "_upgradeSocketData",
5971
+ classification: "hardened",
5972
+ rationale: "Host-to-sandbox upgrade socket data push entrypoint."
5973
+ },
5974
+ {
5975
+ name: "_upgradeSocketEnd",
5976
+ classification: "hardened",
5977
+ rationale: "Host-to-sandbox upgrade socket end push entrypoint."
5978
+ },
5964
5979
  {
5965
5980
  name: "ProcessExitError",
5966
5981
  classification: "hardened",
@@ -6006,6 +6021,71 @@ var bridge = (() => {
6006
6021
  classification: "hardened",
6007
6022
  rationale: "Host entropy bridge reference for crypto.randomUUID."
6008
6023
  },
6024
+ {
6025
+ name: "_cryptoHashDigest",
6026
+ classification: "hardened",
6027
+ rationale: "Host crypto bridge reference for createHash digest computation."
6028
+ },
6029
+ {
6030
+ name: "_cryptoHmacDigest",
6031
+ classification: "hardened",
6032
+ rationale: "Host crypto bridge reference for createHmac digest computation."
6033
+ },
6034
+ {
6035
+ name: "_cryptoPbkdf2",
6036
+ classification: "hardened",
6037
+ rationale: "Host crypto bridge reference for pbkdf2 key derivation."
6038
+ },
6039
+ {
6040
+ name: "_cryptoScrypt",
6041
+ classification: "hardened",
6042
+ rationale: "Host crypto bridge reference for scrypt key derivation."
6043
+ },
6044
+ {
6045
+ name: "_cryptoCipheriv",
6046
+ classification: "hardened",
6047
+ rationale: "Host crypto bridge reference for createCipheriv encryption."
6048
+ },
6049
+ {
6050
+ name: "_cryptoDecipheriv",
6051
+ classification: "hardened",
6052
+ rationale: "Host crypto bridge reference for createDecipheriv decryption."
6053
+ },
6054
+ {
6055
+ name: "_cryptoCipherivCreate",
6056
+ classification: "hardened",
6057
+ rationale: "Host crypto bridge reference for stateful cipher/decipher creation."
6058
+ },
6059
+ {
6060
+ name: "_cryptoCipherivUpdate",
6061
+ classification: "hardened",
6062
+ rationale: "Host crypto bridge reference for stateful cipher/decipher update."
6063
+ },
6064
+ {
6065
+ name: "_cryptoCipherivFinal",
6066
+ classification: "hardened",
6067
+ rationale: "Host crypto bridge reference for stateful cipher/decipher final."
6068
+ },
6069
+ {
6070
+ name: "_cryptoSign",
6071
+ classification: "hardened",
6072
+ rationale: "Host crypto bridge reference for sign operations."
6073
+ },
6074
+ {
6075
+ name: "_cryptoVerify",
6076
+ classification: "hardened",
6077
+ rationale: "Host crypto bridge reference for verify operations."
6078
+ },
6079
+ {
6080
+ name: "_cryptoGenerateKeyPairSync",
6081
+ classification: "hardened",
6082
+ rationale: "Host crypto bridge reference for generateKeyPairSync."
6083
+ },
6084
+ {
6085
+ name: "_cryptoSubtle",
6086
+ classification: "hardened",
6087
+ rationale: "Host crypto bridge reference for Web Crypto subtle operations."
6088
+ },
6009
6089
  {
6010
6090
  name: "_fsReadFile",
6011
6091
  classification: "hardened",
@@ -6156,6 +6236,21 @@ var bridge = (() => {
6156
6236
  classification: "hardened",
6157
6237
  rationale: "Host network bridge reference."
6158
6238
  },
6239
+ {
6240
+ name: "_upgradeSocketWriteRaw",
6241
+ classification: "hardened",
6242
+ rationale: "Host upgrade socket write bridge reference."
6243
+ },
6244
+ {
6245
+ name: "_upgradeSocketEndRaw",
6246
+ classification: "hardened",
6247
+ rationale: "Host upgrade socket end bridge reference."
6248
+ },
6249
+ {
6250
+ name: "_upgradeSocketDestroyRaw",
6251
+ classification: "hardened",
6252
+ rationale: "Host upgrade socket destroy bridge reference."
6253
+ },
6159
6254
  {
6160
6255
  name: "_ptySetRawMode",
6161
6256
  classification: "hardened",
@@ -7145,11 +7240,11 @@ var bridge = (() => {
7145
7240
  const encoding = typeof options === "string" ? options : options?.encoding;
7146
7241
  try {
7147
7242
  if (encoding) {
7148
- const content = _fs.readFile(pathStr);
7243
+ const content = _fs.readFile.applySyncPromise(void 0, [pathStr]);
7149
7244
  return content;
7150
7245
  } else {
7151
- const binaryData = _fs.readFileBinary(pathStr);
7152
- return import_buffer.Buffer.from(binaryData);
7246
+ const base64Content = _fs.readFileBinary.applySyncPromise(void 0, [pathStr]);
7247
+ return import_buffer.Buffer.from(base64Content, "base64");
7153
7248
  }
7154
7249
  } catch (err) {
7155
7250
  const errMsg = err.message || String(err);
@@ -7177,12 +7272,13 @@ var bridge = (() => {
7177
7272
  if (!rawPath) throw createFsError("EBADF", "EBADF: bad file descriptor", "write");
7178
7273
  const pathStr = rawPath;
7179
7274
  if (typeof data === "string") {
7180
- return _fs.writeFile(pathStr, data);
7275
+ return _fs.writeFile.applySyncPromise(void 0, [pathStr, data]);
7181
7276
  } else if (ArrayBuffer.isView(data)) {
7182
7277
  const uint8 = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
7183
- return _fs.writeFileBinary(pathStr, uint8);
7278
+ const base64 = import_buffer.Buffer.from(uint8).toString("base64");
7279
+ return _fs.writeFileBinary.applySyncPromise(void 0, [pathStr, base64]);
7184
7280
  } else {
7185
- return _fs.writeFile(pathStr, String(data));
7281
+ return _fs.writeFile.applySyncPromise(void 0, [pathStr, String(data)]);
7186
7282
  }
7187
7283
  },
7188
7284
  appendFileSync(path, data, options) {
@@ -7193,9 +7289,9 @@ var bridge = (() => {
7193
7289
  readdirSync(path, options) {
7194
7290
  const rawPath = toPathString(path);
7195
7291
  const pathStr = rawPath;
7196
- let entries;
7292
+ let entriesJson;
7197
7293
  try {
7198
- entries = _fs.readDir(pathStr);
7294
+ entriesJson = _fs.readDir.applySyncPromise(void 0, [pathStr]);
7199
7295
  } catch (err) {
7200
7296
  const errMsg = err.message || String(err);
7201
7297
  if (errMsg.includes("entry not found") || errMsg.includes("not found")) {
@@ -7208,6 +7304,7 @@ var bridge = (() => {
7208
7304
  }
7209
7305
  throw err;
7210
7306
  }
7307
+ const entries = JSON.parse(entriesJson);
7211
7308
  if (options?.withFileTypes) {
7212
7309
  return entries.map((e) => new Dirent(e.name, e.isDirectory, rawPath));
7213
7310
  }
@@ -7217,12 +7314,12 @@ var bridge = (() => {
7217
7314
  const rawPath = toPathString(path);
7218
7315
  const pathStr = rawPath;
7219
7316
  const recursive = typeof options === "object" ? options?.recursive ?? false : false;
7220
- _fs.mkdir(pathStr, recursive);
7317
+ _fs.mkdir.applySyncPromise(void 0, [pathStr, recursive]);
7221
7318
  return recursive ? rawPath : void 0;
7222
7319
  },
7223
7320
  rmdirSync(path, _options) {
7224
7321
  const pathStr = toPathString(path);
7225
- _fs.rmdir(pathStr);
7322
+ _fs.rmdir.applySyncPromise(void 0, [pathStr]);
7226
7323
  },
7227
7324
  rmSync(path, options) {
7228
7325
  const pathStr = toPathString(path);
@@ -7257,14 +7354,14 @@ var bridge = (() => {
7257
7354
  },
7258
7355
  existsSync(path) {
7259
7356
  const pathStr = toPathString(path);
7260
- return _fs.exists(pathStr);
7357
+ return _fs.exists.applySyncPromise(void 0, [pathStr]);
7261
7358
  },
7262
7359
  statSync(path, _options) {
7263
7360
  const rawPath = toPathString(path);
7264
7361
  const pathStr = rawPath;
7265
- let stat;
7362
+ let statJson;
7266
7363
  try {
7267
- stat = _fs.stat(pathStr);
7364
+ statJson = _fs.stat.applySyncPromise(void 0, [pathStr]);
7268
7365
  } catch (err) {
7269
7366
  const errMsg = err.message || String(err);
7270
7367
  if (errMsg.includes("entry not found") || errMsg.includes("not found") || errMsg.includes("ENOENT") || errMsg.includes("no such file or directory")) {
@@ -7277,21 +7374,23 @@ var bridge = (() => {
7277
7374
  }
7278
7375
  throw err;
7279
7376
  }
7377
+ const stat = JSON.parse(statJson);
7280
7378
  return new Stats(stat);
7281
7379
  },
7282
7380
  lstatSync(path, _options) {
7283
7381
  const pathStr = toPathString(path);
7284
- const stat = bridgeCall(() => _fs.lstat(pathStr), "lstat", pathStr);
7382
+ const statJson = bridgeCall(() => _fs.lstat.applySyncPromise(void 0, [pathStr]), "lstat", pathStr);
7383
+ const stat = JSON.parse(statJson);
7285
7384
  return new Stats(stat);
7286
7385
  },
7287
7386
  unlinkSync(path) {
7288
7387
  const pathStr = toPathString(path);
7289
- _fs.unlink(pathStr);
7388
+ _fs.unlink.applySyncPromise(void 0, [pathStr]);
7290
7389
  },
7291
7390
  renameSync(oldPath, newPath) {
7292
7391
  const oldPathStr = toPathString(oldPath);
7293
7392
  const newPathStr = toPathString(newPath);
7294
- _fs.rename(oldPathStr, newPathStr);
7393
+ _fs.rename.applySyncPromise(void 0, [oldPathStr, newPathStr]);
7295
7394
  },
7296
7395
  copyFileSync(src, dest, _mode) {
7297
7396
  const content = fs.readFileSync(src);
@@ -7549,35 +7648,35 @@ var bridge = (() => {
7549
7648
  chmodSync(path, mode) {
7550
7649
  const pathStr = toPathString(path);
7551
7650
  const modeNum = typeof mode === "string" ? parseInt(mode, 8) : mode;
7552
- bridgeCall(() => _fs.chmod(pathStr, modeNum), "chmod", pathStr);
7651
+ bridgeCall(() => _fs.chmod.applySyncPromise(void 0, [pathStr, modeNum]), "chmod", pathStr);
7553
7652
  },
7554
7653
  chownSync(path, uid, gid) {
7555
7654
  const pathStr = toPathString(path);
7556
- bridgeCall(() => _fs.chown(pathStr, uid, gid), "chown", pathStr);
7655
+ bridgeCall(() => _fs.chown.applySyncPromise(void 0, [pathStr, uid, gid]), "chown", pathStr);
7557
7656
  },
7558
7657
  linkSync(existingPath, newPath) {
7559
7658
  const existingStr = toPathString(existingPath);
7560
7659
  const newStr = toPathString(newPath);
7561
- bridgeCall(() => _fs.link(existingStr, newStr), "link", newStr);
7660
+ bridgeCall(() => _fs.link.applySyncPromise(void 0, [existingStr, newStr]), "link", newStr);
7562
7661
  },
7563
7662
  symlinkSync(target, path, _type) {
7564
7663
  const targetStr = toPathString(target);
7565
7664
  const pathStr = toPathString(path);
7566
- bridgeCall(() => _fs.symlink(targetStr, pathStr), "symlink", pathStr);
7665
+ bridgeCall(() => _fs.symlink.applySyncPromise(void 0, [targetStr, pathStr]), "symlink", pathStr);
7567
7666
  },
7568
7667
  readlinkSync(path, _options) {
7569
7668
  const pathStr = toPathString(path);
7570
- return bridgeCall(() => _fs.readlink(pathStr), "readlink", pathStr);
7669
+ return bridgeCall(() => _fs.readlink.applySyncPromise(void 0, [pathStr]), "readlink", pathStr);
7571
7670
  },
7572
7671
  truncateSync(path, len) {
7573
7672
  const pathStr = toPathString(path);
7574
- bridgeCall(() => _fs.truncate(pathStr, len ?? 0), "truncate", pathStr);
7673
+ bridgeCall(() => _fs.truncate.applySyncPromise(void 0, [pathStr, len ?? 0]), "truncate", pathStr);
7575
7674
  },
7576
7675
  utimesSync(path, atime, mtime) {
7577
7676
  const pathStr = toPathString(path);
7578
7677
  const atimeNum = typeof atime === "number" ? atime : new Date(atime).getTime() / 1e3;
7579
7678
  const mtimeNum = typeof mtime === "number" ? mtime : new Date(mtime).getTime() / 1e3;
7580
- bridgeCall(() => _fs.utimes(pathStr, atimeNum, mtimeNum), "utimes", pathStr);
7679
+ bridgeCall(() => _fs.utimes.applySyncPromise(void 0, [pathStr, atimeNum, mtimeNum]), "utimes", pathStr);
7581
7680
  },
7582
7681
  // Async methods - wrap sync methods in callbacks/promises
7583
7682
  //
@@ -8958,11 +9057,12 @@ var bridge = (() => {
8958
9057
  throw new Error("child_process.execSync requires CommandExecutor to be configured");
8959
9058
  }
8960
9059
  const maxBuffer = opts.maxBuffer ?? 1024 * 1024;
8961
- const result = _childProcessSpawnSync(
9060
+ const jsonResult = _childProcessSpawnSync.applySyncPromise(void 0, [
8962
9061
  "bash",
8963
9062
  JSON.stringify(["-c", command]),
8964
9063
  JSON.stringify({ cwd: opts.cwd, env: opts.env, maxBuffer })
8965
- );
9064
+ ]);
9065
+ const result = JSON.parse(jsonResult);
8966
9066
  if (result.maxBufferExceeded) {
8967
9067
  const err = new Error("stdout maxBuffer length exceeded");
8968
9068
  err.code = "ERR_CHILD_PROCESS_STDIO_MAXBUFFER";
@@ -8997,11 +9097,11 @@ var bridge = (() => {
8997
9097
  child.spawnargs = [command, ...argsArray];
8998
9098
  if (typeof _childProcessSpawnStart !== "undefined") {
8999
9099
  const effectiveCwd = opts.cwd ?? (typeof process !== "undefined" ? process.cwd() : "/");
9000
- const sessionId = _childProcessSpawnStart(
9100
+ const sessionId = _childProcessSpawnStart.applySync(void 0, [
9001
9101
  command,
9002
9102
  JSON.stringify(argsArray),
9003
9103
  JSON.stringify({ cwd: effectiveCwd, env: opts.env })
9004
- );
9104
+ ]);
9005
9105
  activeChildren.set(sessionId, child);
9006
9106
  if (typeof _registerHandle === "function") {
9007
9107
  _registerHandle(`child:${sessionId}`, `child_process: ${command} ${argsArray.join(" ")}`);
@@ -9009,19 +9109,19 @@ var bridge = (() => {
9009
9109
  child.stdin.write = (data) => {
9010
9110
  if (typeof _childProcessStdinWrite === "undefined") return false;
9011
9111
  const bytes = typeof data === "string" ? new TextEncoder().encode(data) : data;
9012
- _childProcessStdinWrite(sessionId, bytes);
9112
+ _childProcessStdinWrite.applySync(void 0, [sessionId, bytes]);
9013
9113
  return true;
9014
9114
  };
9015
9115
  child.stdin.end = () => {
9016
9116
  if (typeof _childProcessStdinClose !== "undefined") {
9017
- _childProcessStdinClose(sessionId);
9117
+ _childProcessStdinClose.applySync(void 0, [sessionId]);
9018
9118
  }
9019
9119
  child.stdin.writable = false;
9020
9120
  };
9021
9121
  child.kill = (signal) => {
9022
9122
  if (typeof _childProcessKill === "undefined") return false;
9023
9123
  const sig = signal === "SIGKILL" || signal === 9 ? 9 : signal === "SIGINT" || signal === 2 ? 2 : 15;
9024
- _childProcessKill(sessionId, sig);
9124
+ _childProcessKill.applySync(void 0, [sessionId, sig]);
9025
9125
  child.killed = true;
9026
9126
  child.signalCode = typeof signal === "string" ? signal : "SIGTERM";
9027
9127
  return true;
@@ -9060,11 +9160,12 @@ var bridge = (() => {
9060
9160
  try {
9061
9161
  const effectiveCwd = opts.cwd ?? (typeof process !== "undefined" ? process.cwd() : "/");
9062
9162
  const maxBuffer = opts.maxBuffer;
9063
- const result = _childProcessSpawnSync(
9163
+ const jsonResult = _childProcessSpawnSync.applySyncPromise(void 0, [
9064
9164
  command,
9065
9165
  JSON.stringify(argsArray),
9066
9166
  JSON.stringify({ cwd: effectiveCwd, env: opts.env, maxBuffer })
9067
- );
9167
+ ]);
9168
+ const result = JSON.parse(jsonResult);
9068
9169
  const stdoutBuf = typeof Buffer !== "undefined" ? Buffer.from(result.stdout) : result.stdout;
9069
9170
  const stderrBuf = typeof Buffer !== "undefined" ? Buffer.from(result.stderr) : result.stderr;
9070
9171
  if (result.maxBufferExceeded) {
@@ -9225,26 +9326,43 @@ var bridge = (() => {
9225
9326
  fetch: () => fetch,
9226
9327
  http: () => http,
9227
9328
  http2: () => http2,
9228
- https: () => https
9329
+ https: () => https,
9330
+ net: () => net,
9331
+ tlsModule: () => tlsModule
9229
9332
  });
9230
9333
  var MAX_HTTP_BODY_BYTES = 50 * 1024 * 1024;
9231
- async function fetch(url, options = {}) {
9334
+ async function fetch(input, options = {}) {
9232
9335
  if (typeof _networkFetchRaw === "undefined") {
9233
9336
  console.error("fetch requires NetworkAdapter to be configured");
9234
9337
  throw new Error("fetch requires NetworkAdapter to be configured");
9235
9338
  }
9339
+ let resolvedUrl;
9340
+ if (input instanceof Request) {
9341
+ resolvedUrl = input.url;
9342
+ options = {
9343
+ method: input.method,
9344
+ headers: Object.fromEntries(input.headers.entries()),
9345
+ body: input.body,
9346
+ ...options
9347
+ };
9348
+ } else {
9349
+ resolvedUrl = String(input);
9350
+ }
9236
9351
  const optionsJson = JSON.stringify({
9237
9352
  method: options.method || "GET",
9238
9353
  headers: options.headers || {},
9239
9354
  body: options.body || null
9240
9355
  });
9241
- const response = await _networkFetchRaw(String(url), optionsJson);
9356
+ const responseJson = await _networkFetchRaw.apply(void 0, [resolvedUrl, optionsJson], {
9357
+ result: { promise: true }
9358
+ });
9359
+ const response = JSON.parse(responseJson);
9242
9360
  return {
9243
9361
  ok: response.ok,
9244
9362
  status: response.status,
9245
9363
  statusText: response.statusText,
9246
9364
  headers: new Map(Object.entries(response.headers || {})),
9247
- url: response.url || String(url),
9365
+ url: response.url || resolvedUrl,
9248
9366
  redirected: response.redirected || false,
9249
9367
  type: "basic",
9250
9368
  async text() {
@@ -9377,7 +9495,8 @@ var bridge = (() => {
9377
9495
  if (typeof options === "function") {
9378
9496
  cb = options;
9379
9497
  }
9380
- _networkDnsLookupRaw(hostname).then((result) => {
9498
+ _networkDnsLookupRaw.apply(void 0, [hostname], { result: { promise: true } }).then((resultJson) => {
9499
+ const result = JSON.parse(resultJson);
9381
9500
  if (result.error) {
9382
9501
  const err = new Error(result.error);
9383
9502
  err.code = result.code || "ENOTFOUND";
@@ -9754,12 +9873,23 @@ var bridge = (() => {
9754
9873
  body: this._body || null,
9755
9874
  ...tls
9756
9875
  });
9757
- const response = await _networkHttpRequestRaw(url, optionsJson);
9876
+ const responseJson = await _networkHttpRequestRaw.apply(void 0, [url, optionsJson], {
9877
+ result: { promise: true }
9878
+ });
9879
+ const response = JSON.parse(responseJson);
9758
9880
  this.finished = true;
9759
9881
  if (response.status === 101) {
9760
9882
  const res2 = new IncomingMessage(response);
9761
- const head = typeof Buffer !== "undefined" ? Buffer.alloc(0) : new Uint8Array(0);
9762
- this._emit("upgrade", res2, this.socket, head);
9883
+ let socket = this.socket;
9884
+ if (response.upgradeSocketId != null) {
9885
+ socket = new UpgradeSocket(response.upgradeSocketId, {
9886
+ host: this._options.hostname,
9887
+ port: Number(this._options.port) || 80
9888
+ });
9889
+ upgradeSocketInstances.set(response.upgradeSocketId, socket);
9890
+ }
9891
+ const head = typeof Buffer !== "undefined" ? response.body ? Buffer.from(response.body, "base64") : Buffer.alloc(0) : new Uint8Array(0);
9892
+ this._emit("upgrade", res2, socket, head);
9763
9893
  return;
9764
9894
  }
9765
9895
  const res = new IncomingMessage(response);
@@ -9966,6 +10096,7 @@ var bridge = (() => {
9966
10096
  };
9967
10097
  var nextServerId = 1;
9968
10098
  var serverRequestListeners = /* @__PURE__ */ new Map();
10099
+ var serverInstances = /* @__PURE__ */ new Map();
9969
10100
  var ServerIncomingMessage = class {
9970
10101
  headers;
9971
10102
  rawHeaders;
@@ -10275,7 +10406,9 @@ var bridge = (() => {
10275
10406
  } else {
10276
10407
  serverRequestListeners.set(this._serverId, () => void 0);
10277
10408
  }
10409
+ serverInstances.set(this._serverId, this);
10278
10410
  }
10411
+ /** @internal Emit an event — used by upgrade dispatch to fire 'upgrade' events. */
10279
10412
  _emit(event, ...args) {
10280
10413
  const listeners = this._listeners[event];
10281
10414
  if (!listeners || listeners.length === 0) return;
@@ -10287,9 +10420,12 @@ var bridge = (() => {
10287
10420
  "http.createServer requires NetworkAdapter.httpServerListen support"
10288
10421
  );
10289
10422
  }
10290
- const result = await _networkHttpServerListenRaw(
10291
- JSON.stringify({ serverId: this._serverId, port, hostname })
10423
+ const resultJson = await _networkHttpServerListenRaw.apply(
10424
+ void 0,
10425
+ [JSON.stringify({ serverId: this._serverId, port, hostname })],
10426
+ { result: { promise: true } }
10292
10427
  );
10428
+ const result = JSON.parse(resultJson);
10293
10429
  this._address = result.address;
10294
10430
  this.listening = true;
10295
10431
  this._handleId = `http-server:${this._serverId}`;
@@ -10318,10 +10454,13 @@ var bridge = (() => {
10318
10454
  await this._listenPromise;
10319
10455
  }
10320
10456
  if (this.listening && typeof _networkHttpServerCloseRaw !== "undefined") {
10321
- await _networkHttpServerCloseRaw(this._serverId);
10457
+ await _networkHttpServerCloseRaw.apply(void 0, [this._serverId], {
10458
+ result: { promise: true }
10459
+ });
10322
10460
  }
10323
10461
  this.listening = false;
10324
10462
  this._address = null;
10463
+ serverInstances.delete(this._serverId);
10325
10464
  if (this._handleId && typeof _unregisterHandle === "function") {
10326
10465
  _unregisterHandle(this._handleId);
10327
10466
  }
@@ -10387,11 +10526,12 @@ var bridge = (() => {
10387
10526
  return this;
10388
10527
  }
10389
10528
  };
10390
- async function dispatchServerRequest(serverId, request) {
10529
+ async function dispatchServerRequest(serverId, requestJson) {
10391
10530
  const listener = serverRequestListeners.get(serverId);
10392
10531
  if (!listener) {
10393
10532
  throw new Error(`Unknown HTTP server: ${serverId}`);
10394
10533
  }
10534
+ const request = JSON.parse(requestJson);
10395
10535
  const incoming = new ServerIncomingMessage(request);
10396
10536
  const outgoing = new ServerResponseBridge();
10397
10537
  try {
@@ -10413,7 +10553,183 @@ var bridge = (() => {
10413
10553
  outgoing.end();
10414
10554
  }
10415
10555
  await outgoing.waitForClose();
10416
- return outgoing.serialize();
10556
+ return JSON.stringify(outgoing.serialize());
10557
+ }
10558
+ var upgradeSocketInstances = /* @__PURE__ */ new Map();
10559
+ var UpgradeSocket = class {
10560
+ remoteAddress;
10561
+ remotePort;
10562
+ localAddress = "127.0.0.1";
10563
+ localPort = 0;
10564
+ connecting = false;
10565
+ destroyed = false;
10566
+ writable = true;
10567
+ readable = true;
10568
+ readyState = "open";
10569
+ bytesWritten = 0;
10570
+ _listeners = {};
10571
+ _socketId;
10572
+ // Readable stream state stub for ws compatibility (socketOnClose checks _readableState.endEmitted)
10573
+ _readableState = { endEmitted: false };
10574
+ _writableState = { finished: false, errorEmitted: false };
10575
+ constructor(socketId, options) {
10576
+ this._socketId = socketId;
10577
+ this.remoteAddress = options?.host || "127.0.0.1";
10578
+ this.remotePort = options?.port || 80;
10579
+ }
10580
+ setTimeout(_ms, _cb) {
10581
+ return this;
10582
+ }
10583
+ setNoDelay(_noDelay) {
10584
+ return this;
10585
+ }
10586
+ setKeepAlive(_enable, _delay) {
10587
+ return this;
10588
+ }
10589
+ ref() {
10590
+ return this;
10591
+ }
10592
+ unref() {
10593
+ return this;
10594
+ }
10595
+ cork() {
10596
+ }
10597
+ uncork() {
10598
+ }
10599
+ pause() {
10600
+ return this;
10601
+ }
10602
+ resume() {
10603
+ return this;
10604
+ }
10605
+ address() {
10606
+ return { address: this.localAddress, family: "IPv4", port: this.localPort };
10607
+ }
10608
+ on(event, listener) {
10609
+ if (!this._listeners[event]) this._listeners[event] = [];
10610
+ this._listeners[event].push(listener);
10611
+ return this;
10612
+ }
10613
+ addListener(event, listener) {
10614
+ return this.on(event, listener);
10615
+ }
10616
+ once(event, listener) {
10617
+ const wrapper = (...args) => {
10618
+ this.off(event, wrapper);
10619
+ listener(...args);
10620
+ };
10621
+ return this.on(event, wrapper);
10622
+ }
10623
+ off(event, listener) {
10624
+ if (this._listeners[event]) {
10625
+ const idx = this._listeners[event].indexOf(listener);
10626
+ if (idx !== -1) this._listeners[event].splice(idx, 1);
10627
+ }
10628
+ return this;
10629
+ }
10630
+ removeListener(event, listener) {
10631
+ return this.off(event, listener);
10632
+ }
10633
+ removeAllListeners(event) {
10634
+ if (event) {
10635
+ delete this._listeners[event];
10636
+ } else {
10637
+ this._listeners = {};
10638
+ }
10639
+ return this;
10640
+ }
10641
+ emit(event, ...args) {
10642
+ const handlers = this._listeners[event];
10643
+ if (handlers) handlers.slice().forEach((fn) => fn.call(this, ...args));
10644
+ return handlers !== void 0 && handlers.length > 0;
10645
+ }
10646
+ listenerCount(event) {
10647
+ return this._listeners[event]?.length || 0;
10648
+ }
10649
+ write(data, encodingOrCb, cb) {
10650
+ if (this.destroyed) return false;
10651
+ const callback = typeof encodingOrCb === "function" ? encodingOrCb : cb;
10652
+ if (typeof _upgradeSocketWriteRaw !== "undefined") {
10653
+ let base64;
10654
+ if (typeof Buffer !== "undefined" && Buffer.isBuffer(data)) {
10655
+ base64 = data.toString("base64");
10656
+ } else if (typeof data === "string") {
10657
+ base64 = typeof Buffer !== "undefined" ? Buffer.from(data).toString("base64") : btoa(data);
10658
+ } else if (data instanceof Uint8Array) {
10659
+ base64 = typeof Buffer !== "undefined" ? Buffer.from(data).toString("base64") : btoa(String.fromCharCode(...data));
10660
+ } else {
10661
+ base64 = typeof Buffer !== "undefined" ? Buffer.from(String(data)).toString("base64") : btoa(String(data));
10662
+ }
10663
+ this.bytesWritten += base64.length;
10664
+ _upgradeSocketWriteRaw.applySync(void 0, [this._socketId, base64]);
10665
+ }
10666
+ if (callback) callback();
10667
+ return true;
10668
+ }
10669
+ end(data) {
10670
+ if (data) this.write(data);
10671
+ if (typeof _upgradeSocketEndRaw !== "undefined" && !this.destroyed) {
10672
+ _upgradeSocketEndRaw.applySync(void 0, [this._socketId]);
10673
+ }
10674
+ this.writable = false;
10675
+ this.emit("finish");
10676
+ return this;
10677
+ }
10678
+ destroy(err) {
10679
+ if (this.destroyed) return this;
10680
+ this.destroyed = true;
10681
+ this.writable = false;
10682
+ this.readable = false;
10683
+ this._readableState.endEmitted = true;
10684
+ this._writableState.finished = true;
10685
+ if (typeof _upgradeSocketDestroyRaw !== "undefined") {
10686
+ _upgradeSocketDestroyRaw.applySync(void 0, [this._socketId]);
10687
+ }
10688
+ upgradeSocketInstances.delete(this._socketId);
10689
+ if (err) this.emit("error", err);
10690
+ this.emit("close", false);
10691
+ return this;
10692
+ }
10693
+ // Push data received from the host into this socket
10694
+ _pushData(data) {
10695
+ this.emit("data", data);
10696
+ }
10697
+ // Signal end-of-stream from the host
10698
+ _pushEnd() {
10699
+ this.readable = false;
10700
+ this._readableState.endEmitted = true;
10701
+ this._writableState.finished = true;
10702
+ this.emit("end");
10703
+ this.emit("close", false);
10704
+ upgradeSocketInstances.delete(this._socketId);
10705
+ }
10706
+ };
10707
+ function dispatchUpgradeRequest(serverId, requestJson, headBase64, socketId) {
10708
+ const server = serverInstances.get(serverId);
10709
+ if (!server) {
10710
+ throw new Error(`Unknown HTTP server for upgrade: ${serverId}`);
10711
+ }
10712
+ const request = JSON.parse(requestJson);
10713
+ const incoming = new ServerIncomingMessage(request);
10714
+ const head = typeof Buffer !== "undefined" ? Buffer.from(headBase64, "base64") : new Uint8Array(0);
10715
+ const socket = new UpgradeSocket(socketId, {
10716
+ host: incoming.headers["host"]?.split(":")[0] || "127.0.0.1"
10717
+ });
10718
+ upgradeSocketInstances.set(socketId, socket);
10719
+ server._emit("upgrade", incoming, socket, head);
10720
+ }
10721
+ function onUpgradeSocketData(socketId, dataBase64) {
10722
+ const socket = upgradeSocketInstances.get(socketId);
10723
+ if (socket) {
10724
+ const data = typeof Buffer !== "undefined" ? Buffer.from(dataBase64, "base64") : new Uint8Array(0);
10725
+ socket._pushData(data);
10726
+ }
10727
+ }
10728
+ function onUpgradeSocketEnd(socketId) {
10729
+ const socket = upgradeSocketInstances.get(socketId);
10730
+ if (socket) {
10731
+ socket._pushEnd();
10732
+ }
10417
10733
  }
10418
10734
  function ServerResponseCallable() {
10419
10735
  this.statusCode = 200;
@@ -10555,11 +10871,396 @@ var bridge = (() => {
10555
10871
  throw new Error("http2.createSecureServer is not supported in sandbox");
10556
10872
  }
10557
10873
  };
10874
+ var netSocketInstances = /* @__PURE__ */ new Map();
10875
+ var NetSocket = class {
10876
+ remoteAddress = "";
10877
+ remotePort = 0;
10878
+ remoteFamily = "";
10879
+ localAddress = "0.0.0.0";
10880
+ localPort = 0;
10881
+ connecting = true;
10882
+ pending = true;
10883
+ destroyed = false;
10884
+ writable = true;
10885
+ readable = true;
10886
+ readyState = "opening";
10887
+ bytesRead = 0;
10888
+ bytesWritten = 0;
10889
+ _listeners = {};
10890
+ /** @internal socket ID shared with TLS upgrade bridge */
10891
+ _socketId = -1;
10892
+ _connectHost = "";
10893
+ _connectPort = 0;
10894
+ // Stream state stubs for compatibility (ssh2 checks _readableState.ended)
10895
+ _readableState = { endEmitted: false, ended: false };
10896
+ _writableState = { finished: false, errorEmitted: false, ended: false };
10897
+ constructor(_options) {
10898
+ }
10899
+ connect(...args) {
10900
+ let port;
10901
+ let host;
10902
+ let connectListener;
10903
+ if (typeof args[0] === "object" && args[0] !== null) {
10904
+ const opts = args[0];
10905
+ port = Number(opts.port);
10906
+ host = String(opts.host || "127.0.0.1");
10907
+ if (typeof args[1] === "function") connectListener = args[1];
10908
+ } else {
10909
+ port = Number(args[0]);
10910
+ host = typeof args[1] === "string" ? args[1] : "127.0.0.1";
10911
+ if (typeof args[1] === "function") {
10912
+ connectListener = args[1];
10913
+ host = "127.0.0.1";
10914
+ } else if (typeof args[2] === "function") {
10915
+ connectListener = args[2];
10916
+ }
10917
+ }
10918
+ this._connectHost = host;
10919
+ this._connectPort = port;
10920
+ if (connectListener) this.once("connect", connectListener);
10921
+ if (typeof _netSocketConnectRaw === "undefined") {
10922
+ Promise.resolve().then(() => {
10923
+ const err = new Error("net.Socket requires NetworkAdapter to be configured");
10924
+ this._onError(err.message);
10925
+ });
10926
+ return this;
10927
+ }
10928
+ if (typeof _registerHandle !== "undefined") {
10929
+ _registerHandle(`net.socket:${host}:${port}`, `TCP connection to ${host}:${port}`);
10930
+ }
10931
+ this._socketId = _netSocketConnectRaw.applySync(void 0, [host, port]);
10932
+ netSocketInstances.set(this._socketId, this);
10933
+ return this;
10934
+ }
10935
+ setTimeout(_ms, _cb) {
10936
+ return this;
10937
+ }
10938
+ setNoDelay(_noDelay) {
10939
+ return this;
10940
+ }
10941
+ setKeepAlive(_enable, _delay) {
10942
+ return this;
10943
+ }
10944
+ setMaxListeners(_n) {
10945
+ return this;
10946
+ }
10947
+ getMaxListeners() {
10948
+ return 10;
10949
+ }
10950
+ ref() {
10951
+ return this;
10952
+ }
10953
+ unref() {
10954
+ return this;
10955
+ }
10956
+ cork() {
10957
+ }
10958
+ uncork() {
10959
+ }
10960
+ pause() {
10961
+ return this;
10962
+ }
10963
+ resume() {
10964
+ return this;
10965
+ }
10966
+ pipe(destination) {
10967
+ return destination;
10968
+ }
10969
+ address() {
10970
+ return { address: this.localAddress, family: "IPv4", port: this.localPort };
10971
+ }
10972
+ listeners(event) {
10973
+ return (this._listeners[event] || []).slice();
10974
+ }
10975
+ rawListeners(event) {
10976
+ return this.listeners(event);
10977
+ }
10978
+ eventNames() {
10979
+ return Object.keys(this._listeners).filter((k) => (this._listeners[k]?.length ?? 0) > 0);
10980
+ }
10981
+ prependListener(event, listener) {
10982
+ if (!this._listeners[event]) this._listeners[event] = [];
10983
+ this._listeners[event].unshift(listener);
10984
+ return this;
10985
+ }
10986
+ prependOnceListener(event, listener) {
10987
+ const wrapper = (...args) => {
10988
+ this.off(event, wrapper);
10989
+ listener(...args);
10990
+ };
10991
+ return this.prependListener(event, wrapper);
10992
+ }
10993
+ on(event, listener) {
10994
+ if (!this._listeners[event]) this._listeners[event] = [];
10995
+ this._listeners[event].push(listener);
10996
+ return this;
10997
+ }
10998
+ addListener(event, listener) {
10999
+ return this.on(event, listener);
11000
+ }
11001
+ once(event, listener) {
11002
+ const wrapper = (...args) => {
11003
+ this.off(event, wrapper);
11004
+ listener(...args);
11005
+ };
11006
+ return this.on(event, wrapper);
11007
+ }
11008
+ off(event, listener) {
11009
+ if (this._listeners[event]) {
11010
+ const idx = this._listeners[event].indexOf(listener);
11011
+ if (idx !== -1) this._listeners[event].splice(idx, 1);
11012
+ }
11013
+ return this;
11014
+ }
11015
+ removeListener(event, listener) {
11016
+ return this.off(event, listener);
11017
+ }
11018
+ removeAllListeners(event) {
11019
+ if (event) {
11020
+ delete this._listeners[event];
11021
+ } else {
11022
+ this._listeners = {};
11023
+ }
11024
+ return this;
11025
+ }
11026
+ emit(event, ...args) {
11027
+ const handlers = this._listeners[event];
11028
+ if (handlers) handlers.slice().forEach((fn) => fn.call(this, ...args));
11029
+ return handlers !== void 0 && handlers.length > 0;
11030
+ }
11031
+ listenerCount(event) {
11032
+ return this._listeners[event]?.length || 0;
11033
+ }
11034
+ write(data, encodingOrCb, cb) {
11035
+ if (this.destroyed) return false;
11036
+ const callback = typeof encodingOrCb === "function" ? encodingOrCb : cb;
11037
+ if (typeof _netSocketWriteRaw !== "undefined" && this._socketId >= 0) {
11038
+ let base64;
11039
+ if (typeof Buffer !== "undefined" && Buffer.isBuffer(data)) {
11040
+ base64 = data.toString("base64");
11041
+ } else if (typeof data === "string") {
11042
+ const encoding = typeof encodingOrCb === "string" ? encodingOrCb : "utf8";
11043
+ base64 = typeof Buffer !== "undefined" ? Buffer.from(data, encoding).toString("base64") : btoa(data);
11044
+ } else if (data instanceof Uint8Array) {
11045
+ base64 = typeof Buffer !== "undefined" ? Buffer.from(data).toString("base64") : btoa(String.fromCharCode(...data));
11046
+ } else {
11047
+ base64 = typeof Buffer !== "undefined" ? Buffer.from(String(data)).toString("base64") : btoa(String(data));
11048
+ }
11049
+ this.bytesWritten += base64.length;
11050
+ _netSocketWriteRaw.applySync(void 0, [this._socketId, base64]);
11051
+ }
11052
+ if (callback) callback();
11053
+ return true;
11054
+ }
11055
+ end(data, encodingOrCb, cb) {
11056
+ if (data !== void 0 && data !== null) this.write(data, encodingOrCb, cb);
11057
+ if (typeof _netSocketEndRaw !== "undefined" && this._socketId >= 0 && !this.destroyed) {
11058
+ _netSocketEndRaw.applySync(void 0, [this._socketId]);
11059
+ }
11060
+ this.writable = false;
11061
+ this.readyState = this.readable ? "readOnly" : "closed";
11062
+ this.emit("finish");
11063
+ return this;
11064
+ }
11065
+ destroy(err) {
11066
+ if (this.destroyed) return this;
11067
+ this.destroyed = true;
11068
+ this.writable = false;
11069
+ this.readable = false;
11070
+ this.readyState = "closed";
11071
+ this._readableState.endEmitted = true;
11072
+ this._writableState.finished = true;
11073
+ if (typeof _netSocketDestroyRaw !== "undefined" && this._socketId >= 0) {
11074
+ _netSocketDestroyRaw.applySync(void 0, [this._socketId]);
11075
+ }
11076
+ this._cleanup();
11077
+ if (err) this.emit("error", err);
11078
+ this.emit("close", !!err);
11079
+ return this;
11080
+ }
11081
+ // Host→Guest event dispatch handlers
11082
+ _onConnect() {
11083
+ this.connecting = false;
11084
+ this.pending = false;
11085
+ this.remoteAddress = this._connectHost;
11086
+ this.remotePort = this._connectPort;
11087
+ this.remoteFamily = "IPv4";
11088
+ this.readyState = "open";
11089
+ this.emit("connect");
11090
+ this.emit("ready");
11091
+ }
11092
+ _onData(dataBase64) {
11093
+ const buf = typeof Buffer !== "undefined" ? Buffer.from(dataBase64, "base64") : new Uint8Array(0);
11094
+ this.bytesRead += buf.length;
11095
+ this.emit("data", buf);
11096
+ }
11097
+ _onEnd() {
11098
+ this.readable = false;
11099
+ this._readableState.endEmitted = true;
11100
+ this._readableState.ended = true;
11101
+ this.readyState = this.writable ? "writeOnly" : "closed";
11102
+ this.emit("end");
11103
+ }
11104
+ _onError(message) {
11105
+ const err = new Error(message);
11106
+ this.destroy(err);
11107
+ }
11108
+ _onClose(hadError) {
11109
+ this._cleanup();
11110
+ if (!this.destroyed) {
11111
+ this.destroyed = true;
11112
+ this.readable = false;
11113
+ this.writable = false;
11114
+ this.readyState = "closed";
11115
+ this.emit("close", hadError);
11116
+ }
11117
+ }
11118
+ _cleanup() {
11119
+ if (this._socketId >= 0) {
11120
+ netSocketInstances.delete(this._socketId);
11121
+ if (typeof _unregisterHandle !== "undefined") {
11122
+ _unregisterHandle(`net.socket:${this._connectHost}:${this._connectPort}`);
11123
+ }
11124
+ }
11125
+ }
11126
+ };
11127
+ function onNetSocketDispatch(socketId, type, data) {
11128
+ const socket = netSocketInstances.get(socketId);
11129
+ if (!socket) return;
11130
+ switch (type) {
11131
+ case "connect":
11132
+ socket._onConnect();
11133
+ break;
11134
+ case "data":
11135
+ socket._onData(data);
11136
+ break;
11137
+ case "end":
11138
+ socket._onEnd();
11139
+ break;
11140
+ case "error":
11141
+ socket._onError(data);
11142
+ break;
11143
+ case "close":
11144
+ socket._onClose(data === "1");
11145
+ break;
11146
+ case "secureConnect":
11147
+ socket.emit("secureConnect");
11148
+ break;
11149
+ }
11150
+ }
11151
+ function netIsIP(input) {
11152
+ if (typeof input !== "string") return 0;
11153
+ if (/^(\d{1,3}\.){3}\d{1,3}$/.test(input)) {
11154
+ const parts = input.split(".");
11155
+ if (parts.every((p) => {
11156
+ const n = Number(p);
11157
+ return n >= 0 && n <= 255;
11158
+ })) return 4;
11159
+ }
11160
+ if (/^(::)?([0-9a-fA-F]{1,4}(::?)){0,7}([0-9a-fA-F]{1,4})?$/.test(input)) return 6;
11161
+ if (/^::ffff:\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(input)) return 6;
11162
+ return 0;
11163
+ }
11164
+ var net = {
11165
+ Socket: NetSocket,
11166
+ connect(portOrOpts, hostOrCb, cb) {
11167
+ const socket = new NetSocket();
11168
+ socket.connect(portOrOpts, hostOrCb, cb);
11169
+ return socket;
11170
+ },
11171
+ createConnection(portOrOpts, hostOrCb, cb) {
11172
+ return net.connect(portOrOpts, hostOrCb, cb);
11173
+ },
11174
+ createServer() {
11175
+ throw new Error("net.createServer is not supported in sandbox");
11176
+ },
11177
+ isIP: netIsIP,
11178
+ isIPv4(input) {
11179
+ return netIsIP(input) === 4;
11180
+ },
11181
+ isIPv6(input) {
11182
+ return netIsIP(input) === 6;
11183
+ }
11184
+ };
11185
+ var TLSSocket = class extends NetSocket {
11186
+ encrypted = true;
11187
+ authorized = false;
11188
+ authorizationError = null;
11189
+ alpnProtocol = false;
11190
+ _wrappedSocket = null;
11191
+ constructor(originalSocket) {
11192
+ super();
11193
+ this._wrappedSocket = originalSocket;
11194
+ this.remoteAddress = originalSocket.remoteAddress;
11195
+ this.remotePort = originalSocket.remotePort;
11196
+ this.remoteFamily = originalSocket.remoteFamily;
11197
+ this.localAddress = originalSocket.localAddress;
11198
+ this.localPort = originalSocket.localPort;
11199
+ this.connecting = false;
11200
+ this.pending = false;
11201
+ this.readyState = "open";
11202
+ this._socketId = originalSocket._socketId;
11203
+ this._connectHost = originalSocket._connectHost;
11204
+ this._connectPort = originalSocket._connectPort;
11205
+ netSocketInstances.set(this._socketId, this);
11206
+ }
11207
+ _onSecureConnect() {
11208
+ this.authorized = true;
11209
+ this.emit("secureConnect");
11210
+ }
11211
+ // Forward end/close to the wrapped raw socket — Node.js tls.TLSSocket
11212
+ // closes the underlying socket, which fires its 'close' event. Libraries
11213
+ // like pg rely on the original socket's 'close' listener to detect shutdown.
11214
+ _onEnd() {
11215
+ super._onEnd();
11216
+ if (this._wrappedSocket) this._wrappedSocket._onEnd();
11217
+ }
11218
+ _onClose(hadError) {
11219
+ super._onClose(hadError);
11220
+ if (this._wrappedSocket) {
11221
+ this._wrappedSocket._onClose(hadError);
11222
+ this._wrappedSocket = null;
11223
+ }
11224
+ }
11225
+ };
11226
+ var tlsModule = {
11227
+ TLSSocket,
11228
+ connect(options) {
11229
+ const existingSocket = options.socket;
11230
+ if (!existingSocket || existingSocket._socketId < 0) {
11231
+ throw new Error("tls.connect requires an existing connected socket via options.socket");
11232
+ }
11233
+ const tlsSocket = new TLSSocket(existingSocket);
11234
+ if (typeof _netSocketUpgradeTlsRaw === "undefined") {
11235
+ Promise.resolve().then(() => {
11236
+ tlsSocket._onError("tls.connect requires NetworkAdapter TLS support");
11237
+ });
11238
+ return tlsSocket;
11239
+ }
11240
+ _netSocketUpgradeTlsRaw.applySync(void 0, [
11241
+ existingSocket._socketId,
11242
+ JSON.stringify({
11243
+ rejectUnauthorized: options.rejectUnauthorized ?? true,
11244
+ servername: options.servername
11245
+ })
11246
+ ]);
11247
+ return tlsSocket;
11248
+ },
11249
+ createSecureContext(_options) {
11250
+ return {};
11251
+ }
11252
+ };
10558
11253
  exposeCustomGlobal("_httpModule", http);
10559
11254
  exposeCustomGlobal("_httpsModule", https);
10560
11255
  exposeCustomGlobal("_http2Module", http2);
10561
11256
  exposeCustomGlobal("_dnsModule", dns);
11257
+ exposeCustomGlobal("_netModule", net);
11258
+ exposeCustomGlobal("_tlsModule", tlsModule);
10562
11259
  exposeCustomGlobal("_httpServerDispatch", dispatchServerRequest);
11260
+ exposeCustomGlobal("_httpServerUpgradeDispatch", dispatchUpgradeRequest);
11261
+ exposeCustomGlobal("_upgradeSocketData", onUpgradeSocketData);
11262
+ exposeCustomGlobal("_upgradeSocketEnd", onUpgradeSocketEnd);
11263
+ exposeCustomGlobal("_netSocketDispatch", onNetSocketDispatch);
10563
11264
  exposeCustomGlobal("fetch", fetch);
10564
11265
  exposeCustomGlobal("Headers", Headers);
10565
11266
  exposeCustomGlobal("Request", Request);
@@ -10577,6 +11278,8 @@ var bridge = (() => {
10577
11278
  http,
10578
11279
  https,
10579
11280
  http2,
11281
+ net,
11282
+ tls: tlsModule,
10580
11283
  IncomingMessage,
10581
11284
  ClientRequest
10582
11285
  };
@@ -10630,12 +11333,6 @@ var bridge = (() => {
10630
11333
  }
10631
11334
  var _exitCode = 0;
10632
11335
  var _exited = false;
10633
- globalThis.__runtimeResetProcessState = function() {
10634
- _processStartTime = typeof performance !== "undefined" && performance.now ? performance.now() : Date.now();
10635
- _exitCode = 0;
10636
- _exited = false;
10637
- delete globalThis.__runtimeResetProcessState;
10638
- };
10639
11336
  var ProcessExitError = class extends Error {
10640
11337
  code;
10641
11338
  constructor(code) {
@@ -10700,7 +11397,7 @@ var bridge = (() => {
10700
11397
  _processMaxListenersWarned.add(event);
10701
11398
  const warning = `MaxListenersExceededWarning: Possible EventEmitter memory leak detected. ${total} ${event} listeners added to [process]. MaxListeners is ${_processMaxListeners}. Use emitter.setMaxListeners() to increase limit`;
10702
11399
  if (typeof _error !== "undefined") {
10703
- _error(warning);
11400
+ _error.applySync(void 0, [warning]);
10704
11401
  }
10705
11402
  }
10706
11403
  }
@@ -10741,7 +11438,7 @@ var bridge = (() => {
10741
11438
  var _stdout = {
10742
11439
  write(data) {
10743
11440
  if (typeof _log !== "undefined") {
10744
- _log(String(data).replace(/\n$/, ""));
11441
+ _log.applySync(void 0, [String(data).replace(/\n$/, "")]);
10745
11442
  }
10746
11443
  return true;
10747
11444
  },
@@ -10765,7 +11462,7 @@ var bridge = (() => {
10765
11462
  var _stderr = {
10766
11463
  write(data) {
10767
11464
  if (typeof _error !== "undefined") {
10768
- _error(String(data).replace(/\n$/, ""));
11465
+ _error.applySync(void 0, [String(data).replace(/\n$/, "")]);
10769
11466
  }
10770
11467
  return true;
10771
11468
  },
@@ -10901,7 +11598,7 @@ var bridge = (() => {
10901
11598
  throw new Error("setRawMode is not supported when stdin is not a TTY");
10902
11599
  }
10903
11600
  if (typeof _ptySetRawMode !== "undefined") {
10904
- _ptySetRawMode(mode);
11601
+ _ptySetRawMode.applySync(void 0, [mode]);
10905
11602
  }
10906
11603
  return this;
10907
11604
  },
@@ -11000,9 +11697,9 @@ var bridge = (() => {
11000
11697
  return _cwd;
11001
11698
  },
11002
11699
  chdir(dir) {
11003
- let stat;
11700
+ let statJson;
11004
11701
  try {
11005
- stat = _fs.stat(dir);
11702
+ statJson = _fs.stat.applySyncPromise(void 0, [dir]);
11006
11703
  } catch {
11007
11704
  const err = new Error(`ENOENT: no such file or directory, chdir '${dir}'`);
11008
11705
  err.code = "ENOENT";
@@ -11011,7 +11708,8 @@ var bridge = (() => {
11011
11708
  err.path = dir;
11012
11709
  throw err;
11013
11710
  }
11014
- if (!stat.isDirectory) {
11711
+ const parsed = JSON.parse(statJson);
11712
+ if (!parsed.isDirectory) {
11015
11713
  const err = new Error(`ENOTDIR: not a directory, chdir '${dir}'`);
11016
11714
  err.code = "ENOTDIR";
11017
11715
  err.errno = -20;
@@ -11266,6 +11964,12 @@ var bridge = (() => {
11266
11964
  process2.memoryUsage.rss = function() {
11267
11965
  return 50 * 1024 * 1024;
11268
11966
  };
11967
+ Object.defineProperty(process2, Symbol.toStringTag, {
11968
+ value: "process",
11969
+ writable: false,
11970
+ configurable: true,
11971
+ enumerable: false
11972
+ });
11269
11973
  var process_default = process2;
11270
11974
  var _timerId = 0;
11271
11975
  var _timers = /* @__PURE__ */ new Map();
@@ -11308,7 +12012,7 @@ var bridge = (() => {
11308
12012
  _timers.set(id, handle);
11309
12013
  const actualDelay = delay ?? 0;
11310
12014
  if (typeof _scheduleTimer !== "undefined" && actualDelay > 0) {
11311
- _scheduleTimer(actualDelay).then(() => {
12015
+ _scheduleTimer.apply(void 0, [actualDelay], { result: { promise: true } }).then(() => {
11312
12016
  if (_timers.has(id)) {
11313
12017
  _timers.delete(id);
11314
12018
  try {
@@ -11343,7 +12047,7 @@ var bridge = (() => {
11343
12047
  const scheduleNext = () => {
11344
12048
  if (!_intervals.has(id)) return;
11345
12049
  if (typeof _scheduleTimer !== "undefined" && actualDelay > 0) {
11346
- _scheduleTimer(actualDelay).then(() => {
12050
+ _scheduleTimer.apply(void 0, [actualDelay], { result: { promise: true } }).then(() => {
11347
12051
  if (_intervals.has(id)) {
11348
12052
  try {
11349
12053
  callback(...args);
@@ -11380,6 +12084,22 @@ var bridge = (() => {
11380
12084
  var URL2 = import_whatwg_url.URL;
11381
12085
  var URLSearchParams = import_whatwg_url.URLSearchParams;
11382
12086
  var Buffer3 = import_buffer2.Buffer;
12087
+ var bp = import_buffer2.Buffer.prototype;
12088
+ var sliceEncodings = ["utf8", "ascii", "latin1", "binary", "hex", "base64", "ucs2", "utf16le"];
12089
+ for (const enc of sliceEncodings) {
12090
+ const sliceKey = `${enc}Slice`;
12091
+ if (typeof bp[sliceKey] !== "function") {
12092
+ bp[sliceKey] = function(start, end) {
12093
+ return this.toString(enc, start, end);
12094
+ };
12095
+ }
12096
+ const writeKey = `${enc}Write`;
12097
+ if (typeof bp[writeKey] !== "function") {
12098
+ bp[writeKey] = function(str, offset, length) {
12099
+ return this.write(str, offset, length, enc);
12100
+ };
12101
+ }
12102
+ }
11383
12103
  function throwUnsupportedCryptoApi(api) {
11384
12104
  throw new Error(`crypto.${api} is not supported in sandbox`);
11385
12105
  }
@@ -11399,7 +12119,8 @@ var bridge = (() => {
11399
12119
  array.byteLength
11400
12120
  );
11401
12121
  try {
11402
- const hostBytes = _cryptoRandomFill(bytes.byteLength);
12122
+ const base64 = _cryptoRandomFill.applySync(void 0, [bytes.byteLength]);
12123
+ const hostBytes = import_buffer2.Buffer.from(base64, "base64");
11403
12124
  if (hostBytes.byteLength !== bytes.byteLength) {
11404
12125
  throw new Error("invalid host entropy size");
11405
12126
  }
@@ -11414,7 +12135,7 @@ var bridge = (() => {
11414
12135
  throwUnsupportedCryptoApi("randomUUID");
11415
12136
  }
11416
12137
  try {
11417
- const uuid = _cryptoRandomUUID();
12138
+ const uuid = _cryptoRandomUUID.applySync(void 0, []);
11418
12139
  if (typeof uuid !== "string") {
11419
12140
  throw new Error("invalid host uuid");
11420
12141
  }
@@ -11546,7 +12267,10 @@ var bridge = (() => {
11546
12267
  return paths;
11547
12268
  };
11548
12269
  const resolve = function(request, _options) {
11549
- const resolved = _resolveModule(request, dirname);
12270
+ const resolved = _resolveModule.applySyncPromise(void 0, [
12271
+ request,
12272
+ dirname
12273
+ ]);
11550
12274
  if (resolved === null) {
11551
12275
  const err = new Error("Cannot find module '" + request + "'");
11552
12276
  err.code = "MODULE_NOT_FOUND";
@@ -11613,7 +12337,10 @@ var bridge = (() => {
11613
12337
  );
11614
12338
  const moduleRequire = (request) => _requireFrom(request, this.path);
11615
12339
  moduleRequire.resolve = (request) => {
11616
- const resolved = _resolveModule(request, this.path);
12340
+ const resolved = _resolveModule.applySyncPromise(void 0, [
12341
+ request,
12342
+ this.path
12343
+ ]);
11617
12344
  if (resolved === null) {
11618
12345
  const err = new Error("Cannot find module '" + request + "'");
11619
12346
  err.code = "MODULE_NOT_FOUND";
@@ -11643,7 +12370,10 @@ var bridge = (() => {
11643
12370
  static _cache = typeof _moduleCache !== "undefined" ? _moduleCache : {};
11644
12371
  static _resolveFilename(request, parent, _isMain, _options) {
11645
12372
  const parentDir = parent && parent.path ? parent.path : "/";
11646
- const resolved = _resolveModule(request, parentDir);
12373
+ const resolved = _resolveModule.applySyncPromise(void 0, [
12374
+ request,
12375
+ parentDir
12376
+ ]);
11647
12377
  if (resolved === null) {
11648
12378
  const err = new Error("Cannot find module '" + request + "'");
11649
12379
  err.code = "MODULE_NOT_FOUND";