@secure-exec/core 0.1.1-rc.2 → 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.
@@ -376,8 +376,13 @@ function execSync(command, options) {
376
376
  }
377
377
  // Default maxBuffer 1MB (Node.js convention)
378
378
  const maxBuffer = opts.maxBuffer ?? 1024 * 1024;
379
- // Use synchronous bridge call
380
- const result = _childProcessSpawnSync("bash", JSON.stringify(["-c", command]), JSON.stringify({ cwd: opts.cwd, env: opts.env, maxBuffer }));
379
+ // Use synchronous bridge call - result is JSON string
380
+ const jsonResult = _childProcessSpawnSync.applySyncPromise(undefined, [
381
+ "bash",
382
+ JSON.stringify(["-c", command]),
383
+ JSON.stringify({ cwd: opts.cwd, env: opts.env, maxBuffer }),
384
+ ]);
385
+ const result = JSON.parse(jsonResult);
381
386
  if (result.maxBufferExceeded) {
382
387
  const err = new Error("stdout maxBuffer length exceeded");
383
388
  err.code = "ERR_CHILD_PROCESS_STDIO_MAXBUFFER";
@@ -418,7 +423,11 @@ function spawn(command, args, options) {
418
423
  // This ensures process.chdir() changes are reflected in child processes
419
424
  const effectiveCwd = opts.cwd ?? (typeof process !== "undefined" ? process.cwd() : "/");
420
425
  // Streaming mode - spawn immediately
421
- const sessionId = _childProcessSpawnStart(command, JSON.stringify(argsArray), JSON.stringify({ cwd: effectiveCwd, env: opts.env }));
426
+ const sessionId = _childProcessSpawnStart.applySync(undefined, [
427
+ command,
428
+ JSON.stringify(argsArray),
429
+ JSON.stringify({ cwd: effectiveCwd, env: opts.env }),
430
+ ]);
422
431
  activeChildren.set(sessionId, child);
423
432
  // Register handle to keep sandbox alive until child exits
424
433
  // See: docs-internal/node/ACTIVE_HANDLES.md
@@ -430,12 +439,12 @@ function spawn(command, args, options) {
430
439
  if (typeof _childProcessStdinWrite === "undefined")
431
440
  return false;
432
441
  const bytes = typeof data === "string" ? new TextEncoder().encode(data) : data;
433
- _childProcessStdinWrite(sessionId, bytes);
442
+ _childProcessStdinWrite.applySync(undefined, [sessionId, bytes]);
434
443
  return true;
435
444
  };
436
445
  child.stdin.end = () => {
437
446
  if (typeof _childProcessStdinClose !== "undefined") {
438
- _childProcessStdinClose(sessionId);
447
+ _childProcessStdinClose.applySync(undefined, [sessionId]);
439
448
  }
440
449
  child.stdin.writable = false;
441
450
  };
@@ -448,7 +457,7 @@ function spawn(command, args, options) {
448
457
  : signal === "SIGINT" || signal === 2
449
458
  ? 2
450
459
  : 15;
451
- _childProcessKill(sessionId, sig);
460
+ _childProcessKill.applySync(undefined, [sessionId, sig]);
452
461
  child.killed = true;
453
462
  child.signalCode = (typeof signal === "string" ? signal : "SIGTERM");
454
463
  return true;
@@ -492,8 +501,13 @@ function spawnSync(command, args, options) {
492
501
  const effectiveCwd = opts.cwd ?? (typeof process !== "undefined" ? process.cwd() : "/");
493
502
  // Pass maxBuffer through to host for enforcement
494
503
  const maxBuffer = opts.maxBuffer;
495
- // Args and options passed as JSON strings for transferability
496
- const result = _childProcessSpawnSync(command, JSON.stringify(argsArray), JSON.stringify({ cwd: effectiveCwd, env: opts.env, maxBuffer }));
504
+ // Args passed as JSON string for transferability
505
+ const jsonResult = _childProcessSpawnSync.applySyncPromise(undefined, [
506
+ command,
507
+ JSON.stringify(argsArray),
508
+ JSON.stringify({ cwd: effectiveCwd, env: opts.env, maxBuffer }),
509
+ ]);
510
+ const result = JSON.parse(jsonResult);
497
511
  const stdoutBuf = typeof Buffer !== "undefined" ? Buffer.from(result.stdout) : result.stdout;
498
512
  const stderrBuf = typeof Buffer !== "undefined" ? Buffer.from(result.stderr) : result.stderr;
499
513
  if (result.maxBufferExceeded) {
package/dist/bridge/fs.js CHANGED
@@ -919,13 +919,13 @@ const fs = {
919
919
  try {
920
920
  if (encoding) {
921
921
  // Text mode - use text read
922
- const content = _fs.readFile(pathStr);
922
+ const content = _fs.readFile.applySyncPromise(undefined, [pathStr]);
923
923
  return content;
924
924
  }
925
925
  else {
926
- // Binary mode - host returns raw Uint8Array via MessagePack bin
927
- const binaryData = _fs.readFileBinary(pathStr);
928
- return Buffer.from(binaryData);
926
+ // Binary mode - use binary read with base64 encoding
927
+ const base64Content = _fs.readFileBinary.applySyncPromise(undefined, [pathStr]);
928
+ return Buffer.from(base64Content, "base64");
929
929
  }
930
930
  }
931
931
  catch (err) {
@@ -952,16 +952,17 @@ const fs = {
952
952
  if (typeof data === "string") {
953
953
  // Text mode - use text write
954
954
  // Return the result so async callers (fs.promises) can await it.
955
- return _fs.writeFile(pathStr, data);
955
+ return _fs.writeFile.applySyncPromise(undefined, [pathStr, data]);
956
956
  }
957
957
  else if (ArrayBuffer.isView(data)) {
958
- // Binary mode - send raw Uint8Array via MessagePack bin
958
+ // Binary mode - convert to base64 and use binary write
959
959
  const uint8 = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
960
- return _fs.writeFileBinary(pathStr, uint8);
960
+ const base64 = Buffer.from(uint8).toString("base64");
961
+ return _fs.writeFileBinary.applySyncPromise(undefined, [pathStr, base64]);
961
962
  }
962
963
  else {
963
964
  // Fallback to text mode
964
- return _fs.writeFile(pathStr, String(data));
965
+ return _fs.writeFile.applySyncPromise(undefined, [pathStr, String(data)]);
965
966
  }
966
967
  },
967
968
  appendFileSync(path, data, options) {
@@ -974,9 +975,9 @@ const fs = {
974
975
  readdirSync(path, options) {
975
976
  const rawPath = toPathString(path);
976
977
  const pathStr = rawPath;
977
- let entries;
978
+ let entriesJson;
978
979
  try {
979
- entries = _fs.readDir(pathStr);
980
+ entriesJson = _fs.readDir.applySyncPromise(undefined, [pathStr]);
980
981
  }
981
982
  catch (err) {
982
983
  // Convert "entry not found" and similar errors to proper ENOENT
@@ -986,6 +987,7 @@ const fs = {
986
987
  }
987
988
  throw err;
988
989
  }
990
+ const entries = JSON.parse(entriesJson);
989
991
  if (options?.withFileTypes) {
990
992
  return entries.map((e) => new Dirent(e.name, e.isDirectory, rawPath));
991
993
  }
@@ -995,12 +997,12 @@ const fs = {
995
997
  const rawPath = toPathString(path);
996
998
  const pathStr = rawPath;
997
999
  const recursive = typeof options === "object" ? options?.recursive ?? false : false;
998
- _fs.mkdir(pathStr, recursive);
1000
+ _fs.mkdir.applySyncPromise(undefined, [pathStr, recursive]);
999
1001
  return recursive ? rawPath : undefined;
1000
1002
  },
1001
1003
  rmdirSync(path, _options) {
1002
1004
  const pathStr = toPathString(path);
1003
- _fs.rmdir(pathStr);
1005
+ _fs.rmdir.applySyncPromise(undefined, [pathStr]);
1004
1006
  },
1005
1007
  rmSync(path, options) {
1006
1008
  const pathStr = toPathString(path);
@@ -1040,14 +1042,14 @@ const fs = {
1040
1042
  },
1041
1043
  existsSync(path) {
1042
1044
  const pathStr = toPathString(path);
1043
- return _fs.exists(pathStr);
1045
+ return _fs.exists.applySyncPromise(undefined, [pathStr]);
1044
1046
  },
1045
1047
  statSync(path, _options) {
1046
1048
  const rawPath = toPathString(path);
1047
1049
  const pathStr = rawPath;
1048
- let stat;
1050
+ let statJson;
1049
1051
  try {
1050
- stat = _fs.stat(pathStr);
1052
+ statJson = _fs.stat.applySyncPromise(undefined, [pathStr]);
1051
1053
  }
1052
1054
  catch (err) {
1053
1055
  // Convert various "not found" errors to proper ENOENT
@@ -1060,21 +1062,23 @@ const fs = {
1060
1062
  }
1061
1063
  throw err;
1062
1064
  }
1065
+ const stat = JSON.parse(statJson);
1063
1066
  return new Stats(stat);
1064
1067
  },
1065
1068
  lstatSync(path, _options) {
1066
1069
  const pathStr = toPathString(path);
1067
- const stat = bridgeCall(() => _fs.lstat(pathStr), "lstat", pathStr);
1070
+ const statJson = bridgeCall(() => _fs.lstat.applySyncPromise(undefined, [pathStr]), "lstat", pathStr);
1071
+ const stat = JSON.parse(statJson);
1068
1072
  return new Stats(stat);
1069
1073
  },
1070
1074
  unlinkSync(path) {
1071
1075
  const pathStr = toPathString(path);
1072
- _fs.unlink(pathStr);
1076
+ _fs.unlink.applySyncPromise(undefined, [pathStr]);
1073
1077
  },
1074
1078
  renameSync(oldPath, newPath) {
1075
1079
  const oldPathStr = toPathString(oldPath);
1076
1080
  const newPathStr = toPathString(newPath);
1077
- _fs.rename(oldPathStr, newPathStr);
1081
+ _fs.rename.applySyncPromise(undefined, [oldPathStr, newPathStr]);
1078
1082
  },
1079
1083
  copyFileSync(src, dest, _mode) {
1080
1084
  // readFileSync and writeFileSync already normalize paths
@@ -1336,35 +1340,35 @@ const fs = {
1336
1340
  chmodSync(path, mode) {
1337
1341
  const pathStr = toPathString(path);
1338
1342
  const modeNum = typeof mode === "string" ? parseInt(mode, 8) : mode;
1339
- bridgeCall(() => _fs.chmod(pathStr, modeNum), "chmod", pathStr);
1343
+ bridgeCall(() => _fs.chmod.applySyncPromise(undefined, [pathStr, modeNum]), "chmod", pathStr);
1340
1344
  },
1341
1345
  chownSync(path, uid, gid) {
1342
1346
  const pathStr = toPathString(path);
1343
- bridgeCall(() => _fs.chown(pathStr, uid, gid), "chown", pathStr);
1347
+ bridgeCall(() => _fs.chown.applySyncPromise(undefined, [pathStr, uid, gid]), "chown", pathStr);
1344
1348
  },
1345
1349
  linkSync(existingPath, newPath) {
1346
1350
  const existingStr = toPathString(existingPath);
1347
1351
  const newStr = toPathString(newPath);
1348
- bridgeCall(() => _fs.link(existingStr, newStr), "link", newStr);
1352
+ bridgeCall(() => _fs.link.applySyncPromise(undefined, [existingStr, newStr]), "link", newStr);
1349
1353
  },
1350
1354
  symlinkSync(target, path, _type) {
1351
1355
  const targetStr = toPathString(target);
1352
1356
  const pathStr = toPathString(path);
1353
- bridgeCall(() => _fs.symlink(targetStr, pathStr), "symlink", pathStr);
1357
+ bridgeCall(() => _fs.symlink.applySyncPromise(undefined, [targetStr, pathStr]), "symlink", pathStr);
1354
1358
  },
1355
1359
  readlinkSync(path, _options) {
1356
1360
  const pathStr = toPathString(path);
1357
- return bridgeCall(() => _fs.readlink(pathStr), "readlink", pathStr);
1361
+ return bridgeCall(() => _fs.readlink.applySyncPromise(undefined, [pathStr]), "readlink", pathStr);
1358
1362
  },
1359
1363
  truncateSync(path, len) {
1360
1364
  const pathStr = toPathString(path);
1361
- bridgeCall(() => _fs.truncate(pathStr, len ?? 0), "truncate", pathStr);
1365
+ bridgeCall(() => _fs.truncate.applySyncPromise(undefined, [pathStr, len ?? 0]), "truncate", pathStr);
1362
1366
  },
1363
1367
  utimesSync(path, atime, mtime) {
1364
1368
  const pathStr = toPathString(path);
1365
1369
  const atimeNum = typeof atime === "number" ? atime : new Date(atime).getTime() / 1000;
1366
1370
  const mtimeNum = typeof mtime === "number" ? mtime : new Date(mtime).getTime() / 1000;
1367
- bridgeCall(() => _fs.utimes(pathStr, atimeNum, mtimeNum), "utimes", pathStr);
1371
+ bridgeCall(() => _fs.utimes.applySyncPromise(undefined, [pathStr, atimeNum, mtimeNum]), "utimes", pathStr);
1368
1372
  },
1369
1373
  // Async methods - wrap sync methods in callbacks/promises
1370
1374
  //
@@ -78,7 +78,10 @@ export function createRequire(filename) {
78
78
  };
79
79
  // Create resolve function
80
80
  const resolve = function (request, _options) {
81
- const resolved = _resolveModule(request, dirname);
81
+ const resolved = _resolveModule.applySyncPromise(undefined, [
82
+ request,
83
+ dirname,
84
+ ]);
82
85
  if (resolved === null) {
83
86
  const err = new Error("Cannot find module '" + request + "'");
84
87
  err.code = "MODULE_NOT_FOUND";
@@ -152,7 +155,10 @@ export class Module {
152
155
  const wrapper = new Function("exports", "require", "module", "__filename", "__dirname", content);
153
156
  const moduleRequire = (request) => _requireFrom(request, this.path);
154
157
  moduleRequire.resolve = (request) => {
155
- const resolved = _resolveModule(request, this.path);
158
+ const resolved = _resolveModule.applySyncPromise(undefined, [
159
+ request,
160
+ this.path,
161
+ ]);
156
162
  if (resolved === null) {
157
163
  const err = new Error("Cannot find module '" + request + "'");
158
164
  err.code = "MODULE_NOT_FOUND";
@@ -184,7 +190,10 @@ export class Module {
184
190
  : {};
185
191
  static _resolveFilename(request, parent, _isMain, _options) {
186
192
  const parentDir = parent && parent.path ? parent.path : "/";
187
- const resolved = _resolveModule(request, parentDir);
193
+ const resolved = _resolveModule.applySyncPromise(undefined, [
194
+ request,
195
+ parentDir,
196
+ ]);
188
197
  if (resolved === null) {
189
198
  const err = new Error("Cannot find module '" + request + "'");
190
199
  err.code = "MODULE_NOT_FOUND";
@@ -24,7 +24,7 @@ interface FetchResponse {
24
24
  blob(): Promise<never>;
25
25
  clone(): FetchResponse;
26
26
  }
27
- export declare function fetch(url: string | URL, options?: FetchOptions): Promise<FetchResponse>;
27
+ export declare function fetch(input: string | URL | Request, options?: FetchOptions): Promise<FetchResponse>;
28
28
  export declare class Headers {
29
29
  private _headers;
30
30
  constructor(init?: HeadersInit | Headers | Record<string, string> | [string, string][]);
@@ -214,6 +214,92 @@ export declare const http2: {
214
214
  createServer(): never;
215
215
  createSecureServer(): never;
216
216
  };
217
+ declare class NetSocket {
218
+ remoteAddress: string;
219
+ remotePort: number;
220
+ remoteFamily: string;
221
+ localAddress: string;
222
+ localPort: number;
223
+ connecting: boolean;
224
+ pending: boolean;
225
+ destroyed: boolean;
226
+ writable: boolean;
227
+ readable: boolean;
228
+ readyState: "opening" | "open" | "readOnly" | "writeOnly" | "closed";
229
+ bytesRead: number;
230
+ bytesWritten: number;
231
+ private _listeners;
232
+ /** @internal socket ID shared with TLS upgrade bridge */
233
+ _socketId: number;
234
+ private _connectHost;
235
+ private _connectPort;
236
+ _readableState: {
237
+ endEmitted: boolean;
238
+ ended: boolean;
239
+ };
240
+ _writableState: {
241
+ finished: boolean;
242
+ errorEmitted: boolean;
243
+ ended: boolean;
244
+ };
245
+ constructor(_options?: Record<string, unknown>);
246
+ connect(...args: unknown[]): this;
247
+ setTimeout(_ms: number, _cb?: () => void): this;
248
+ setNoDelay(_noDelay?: boolean): this;
249
+ setKeepAlive(_enable?: boolean, _delay?: number): this;
250
+ setMaxListeners(_n: number): this;
251
+ getMaxListeners(): number;
252
+ ref(): this;
253
+ unref(): this;
254
+ cork(): void;
255
+ uncork(): void;
256
+ pause(): this;
257
+ resume(): this;
258
+ pipe<T>(destination: T): T;
259
+ address(): {
260
+ address: string;
261
+ family: string;
262
+ port: number;
263
+ };
264
+ listeners(event: string): EventListener[];
265
+ rawListeners(event: string): EventListener[];
266
+ eventNames(): string[];
267
+ prependListener(event: string, listener: EventListener): this;
268
+ prependOnceListener(event: string, listener: EventListener): this;
269
+ on(event: string, listener: EventListener): this;
270
+ addListener(event: string, listener: EventListener): this;
271
+ once(event: string, listener: EventListener): this;
272
+ off(event: string, listener: EventListener): this;
273
+ removeListener(event: string, listener: EventListener): this;
274
+ removeAllListeners(event?: string): this;
275
+ emit(event: string, ...args: unknown[]): boolean;
276
+ listenerCount(event: string): number;
277
+ [key: string | symbol]: unknown;
278
+ write(data: unknown, encodingOrCb?: string | (() => void), cb?: (() => void)): boolean;
279
+ end(data?: unknown, encodingOrCb?: string | (() => void), cb?: (() => void)): this;
280
+ destroy(err?: Error): this;
281
+ _onConnect(): void;
282
+ _onData(dataBase64: string): void;
283
+ _onEnd(): void;
284
+ _onError(message: string): void;
285
+ _onClose(hadError: boolean): void;
286
+ private _cleanup;
287
+ }
288
+ declare function netIsIP(input: string): number;
289
+ export declare const net: {
290
+ Socket: typeof import("net").Socket;
291
+ connect(portOrOpts: number | Record<string, unknown>, hostOrCb?: string | (() => void), cb?: () => void): NetSocket;
292
+ createConnection(portOrOpts: number | Record<string, unknown>, hostOrCb?: string | (() => void), cb?: () => void): NetSocket;
293
+ createServer(): never;
294
+ isIP: typeof netIsIP;
295
+ isIPv4(input: string): boolean;
296
+ isIPv6(input: string): boolean;
297
+ };
298
+ export declare const tlsModule: {
299
+ TLSSocket: typeof import("tls").TLSSocket;
300
+ connect(options: Record<string, unknown>): NetSocket;
301
+ createSecureContext(_options?: Record<string, unknown>): Record<string, unknown>;
302
+ };
217
303
  declare const _default: {
218
304
  fetch: typeof fetch;
219
305
  Headers: typeof Headers;
@@ -244,6 +330,20 @@ declare const _default: {
244
330
  createServer(): never;
245
331
  createSecureServer(): never;
246
332
  };
333
+ net: {
334
+ Socket: typeof import("net").Socket;
335
+ connect(portOrOpts: number | Record<string, unknown>, hostOrCb?: string | (() => void), cb?: () => void): NetSocket;
336
+ createConnection(portOrOpts: number | Record<string, unknown>, hostOrCb?: string | (() => void), cb?: () => void): NetSocket;
337
+ createServer(): never;
338
+ isIP: typeof netIsIP;
339
+ isIPv4(input: string): boolean;
340
+ isIPv6(input: string): boolean;
341
+ };
342
+ tls: {
343
+ TLSSocket: typeof import("tls").TLSSocket;
344
+ connect(options: Record<string, unknown>): NetSocket;
345
+ createSecureContext(_options?: Record<string, unknown>): Record<string, unknown>;
346
+ };
247
347
  IncomingMessage: typeof IncomingMessage;
248
348
  ClientRequest: typeof ClientRequest;
249
349
  };