@secure-exec/nodejs 0.2.0-rc.1 → 0.2.0-rc.2

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.
@@ -13,7 +13,7 @@ const childProcessInstances = new Map();
13
13
  * Routes stdout/stderr chunks and exit codes to the corresponding ChildProcess
14
14
  * instance by session ID, and unregisters the active handle on exit.
15
15
  */
16
- const childProcessDispatch = (sessionId, type, data) => {
16
+ function routeChildProcessEvent(sessionId, type, data) {
17
17
  const child = childProcessInstances.get(sessionId);
18
18
  if (!child)
19
19
  return;
@@ -38,6 +38,52 @@ const childProcessDispatch = (sessionId, type, data) => {
38
38
  _unregisterHandle(`child:${sessionId}`);
39
39
  }
40
40
  }
41
+ }
42
+ const childProcessDispatch = (eventTypeOrSessionId, payloadOrType, data) => {
43
+ if (typeof eventTypeOrSessionId === "number") {
44
+ routeChildProcessEvent(eventTypeOrSessionId, payloadOrType, data);
45
+ return;
46
+ }
47
+ const payload = (() => {
48
+ if (payloadOrType && typeof payloadOrType === "object") {
49
+ return payloadOrType;
50
+ }
51
+ if (typeof payloadOrType === "string") {
52
+ try {
53
+ return JSON.parse(payloadOrType);
54
+ }
55
+ catch {
56
+ return null;
57
+ }
58
+ }
59
+ return null;
60
+ })();
61
+ const sessionId = typeof payload?.sessionId === "number"
62
+ ? payload.sessionId
63
+ : Number(payload?.sessionId);
64
+ if (!Number.isFinite(sessionId)) {
65
+ return;
66
+ }
67
+ if (eventTypeOrSessionId === "child_stdout" || eventTypeOrSessionId === "child_stderr") {
68
+ const encoded = typeof payload?.dataBase64 === "string"
69
+ ? payload.dataBase64
70
+ : typeof payload?.data === "string"
71
+ ? payload.data
72
+ : "";
73
+ const bytes = typeof Buffer !== "undefined"
74
+ ? Buffer.from(encoded, "base64")
75
+ : new Uint8Array(atob(encoded)
76
+ .split("")
77
+ .map((char) => char.charCodeAt(0)));
78
+ routeChildProcessEvent(sessionId, eventTypeOrSessionId === "child_stdout" ? "stdout" : "stderr", bytes);
79
+ return;
80
+ }
81
+ if (eventTypeOrSessionId === "child_exit") {
82
+ const code = typeof payload?.code === "number"
83
+ ? payload.code
84
+ : Number(payload?.code ?? 1);
85
+ routeChildProcessEvent(sessionId, "exit", code);
86
+ }
41
87
  };
42
88
  exposeCustomGlobal("_childProcessDispatch", childProcessDispatch);
43
89
  /** Warn when listener count exceeds max (Node.js: warn, don't crash) */
@@ -100,7 +100,12 @@ declare class FileHandle {
100
100
  chmod(mode: Mode): Promise<void>;
101
101
  chown(uid: number, gid: number): Promise<void>;
102
102
  utimes(atime: string | number | Date, mtime: string | number | Date): Promise<void>;
103
- read(buffer: NodeJS.ArrayBufferView | null, offset?: number, length?: number, position?: number | null): Promise<{
103
+ read(buffer: NodeJS.ArrayBufferView | {
104
+ buffer?: NodeJS.ArrayBufferView | null;
105
+ offset?: number;
106
+ length?: number;
107
+ position?: number | null;
108
+ } | null, offset?: number, length?: number, position?: number | null): Promise<{
104
109
  bytesRead: number;
105
110
  buffer: NodeJS.ArrayBufferView;
106
111
  }>;
package/dist/bridge/fs.js CHANGED
@@ -417,15 +417,24 @@ class FileHandle {
417
417
  async read(buffer, offset, length, position) {
418
418
  const handle = FileHandle._assertHandle(this);
419
419
  let target = buffer;
420
+ let readOffset = offset;
421
+ let readLength = length;
422
+ let readPosition = position;
423
+ if (target !== null && typeof target === "object" && !ArrayBuffer.isView(target)) {
424
+ readOffset = target.offset;
425
+ readLength = target.length;
426
+ readPosition = target.position;
427
+ target = target.buffer ?? null;
428
+ }
420
429
  if (target === null) {
421
430
  target = Buffer.alloc(FILE_HANDLE_READ_BUFFER_BYTES);
422
431
  }
423
432
  if (!ArrayBuffer.isView(target)) {
424
433
  throw createInvalidArgTypeError("buffer", "an instance of ArrayBufferView", target);
425
434
  }
426
- const readOffset = offset ?? 0;
427
- const readLength = length ?? (target.byteLength - readOffset);
428
- const bytesRead = fs.readSync(handle.fd, target, readOffset, readLength, position ?? null);
435
+ const normalizedOffset = readOffset ?? 0;
436
+ const normalizedLength = readLength ?? (target.byteLength - normalizedOffset);
437
+ const bytesRead = fs.readSync(handle.fd, target, normalizedOffset, normalizedLength, readPosition ?? null);
429
438
  return { bytesRead, buffer: target };
430
439
  }
431
440
  async write(buffer, offsetOrPosition, lengthOrEncoding, position) {
@@ -4,7 +4,7 @@ import fs from "./fs.js";
4
4
  import os from "./os.js";
5
5
  import * as childProcess from "./child-process.js";
6
6
  import * as network from "./network.js";
7
- import process, { setupGlobals, setTimeout, clearTimeout, setInterval, clearInterval, setImmediate, clearImmediate, URL, URLSearchParams, TextEncoder, TextDecoder, Buffer, cryptoPolyfill, ProcessExitError } from "./process.js";
7
+ import process, { setupGlobals, setTimeout, clearTimeout, setInterval, clearInterval, setImmediate, clearImmediate, URL, URLSearchParams, TextEncoder, TextDecoder, Event, CustomEvent, EventTarget, Buffer, cryptoPolyfill, ProcessExitError } from "./process.js";
8
8
  import moduleModule, { createRequire, Module, SourceMap } from "./module.js";
9
- export { fs, os, childProcess, process, moduleModule as module, network, setupGlobals, setTimeout, clearTimeout, setInterval, clearInterval, setImmediate, clearImmediate, URL, URLSearchParams, TextEncoder, TextDecoder, Buffer, cryptoPolyfill, ProcessExitError, createRequire, Module, SourceMap, _registerHandle, _unregisterHandle, _waitForActiveHandles, _getActiveHandles, };
9
+ export { fs, os, childProcess, process, moduleModule as module, network, setupGlobals, setTimeout, clearTimeout, setInterval, clearInterval, setImmediate, clearImmediate, URL, URLSearchParams, TextEncoder, TextDecoder, Event, CustomEvent, EventTarget, Buffer, cryptoPolyfill, ProcessExitError, createRequire, Module, SourceMap, _registerHandle, _unregisterHandle, _waitForActiveHandles, _getActiveHandles, };
10
10
  export default fs;
@@ -19,7 +19,7 @@ import * as childProcess from "./child-process.js";
19
19
  // Network modules (fetch, dns, http, https)
20
20
  import * as network from "./network.js";
21
21
  // Process and global polyfills
22
- import process, { setupGlobals, setTimeout, clearTimeout, setInterval, clearInterval, setImmediate, clearImmediate, URL, URLSearchParams, TextEncoder, TextDecoder, Buffer, cryptoPolyfill, ProcessExitError, } from "./process.js";
22
+ import process, { setupGlobals, setTimeout, clearTimeout, setInterval, clearInterval, setImmediate, clearImmediate, URL, URLSearchParams, TextEncoder, TextDecoder, Event, CustomEvent, EventTarget, Buffer, cryptoPolyfill, ProcessExitError, } from "./process.js";
23
23
  // Module system (createRequire, Module class)
24
24
  import moduleModule, { createRequire, Module, SourceMap } from "./module.js";
25
25
  // Export all modules
@@ -29,7 +29,7 @@ fs, os, childProcess, process, moduleModule as module,
29
29
  // Network
30
30
  network,
31
31
  // Process globals
32
- setupGlobals, setTimeout, clearTimeout, setInterval, clearInterval, setImmediate, clearImmediate, URL, URLSearchParams, TextEncoder, TextDecoder, Buffer, cryptoPolyfill, ProcessExitError,
32
+ setupGlobals, setTimeout, clearTimeout, setInterval, clearInterval, setImmediate, clearImmediate, URL, URLSearchParams, TextEncoder, TextDecoder, Event, CustomEvent, EventTarget, Buffer, cryptoPolyfill, ProcessExitError,
33
33
  // Module utilities
34
34
  createRequire, Module, SourceMap,
35
35
  // Active handles (see docs-internal/node/ACTIVE_HANDLES.md)
@@ -2,7 +2,7 @@ import type * as nodeHttp from "http";
2
2
  import type * as nodeDgram from "node:dgram";
3
3
  interface FetchOptions {
4
4
  method?: string;
5
- headers?: Record<string, string>;
5
+ headers?: Headers | Record<string, string> | Array<[string, string]> | readonly string[];
6
6
  body?: string | null;
7
7
  mode?: string;
8
8
  credentials?: string;
@@ -19,6 +19,7 @@ interface FetchResponse {
19
19
  url: string;
20
20
  redirected: boolean;
21
21
  type: string;
22
+ body: ReadableStream<Uint8Array> | null;
22
23
  text(): Promise<string>;
23
24
  json(): Promise<unknown>;
24
25
  arrayBuffer(): Promise<ArrayBuffer>;
@@ -443,13 +444,30 @@ declare class Http2SocketProxy extends Http2EventEmitter {
443
444
  remoteFamily: string;
444
445
  servername?: string;
445
446
  alpnProtocol: string | false;
447
+ readable: boolean;
448
+ writable: boolean;
446
449
  destroyed: boolean;
450
+ _bridgeReadPollTimer: ReturnType<typeof setTimeout> | null;
451
+ _loopbackServer: null;
447
452
  private _onDestroy?;
453
+ private _destroyCallbackInvoked;
448
454
  constructor(state?: SerializedHttp2SocketState, onDestroy?: () => void);
449
455
  _applyState(state?: SerializedHttp2SocketState): void;
456
+ _clearTimeoutTimer(): void;
457
+ _emitNet(event: string, error?: Error): void;
450
458
  end(): this;
451
459
  destroy(): this;
452
460
  }
461
+ declare class NghttpError extends Error {
462
+ code: string;
463
+ constructor(message: string);
464
+ }
465
+ declare function nghttp2ErrorString(code: number): string;
466
+ declare class Http2Stream {
467
+ private readonly _streamId;
468
+ constructor(_streamId: number);
469
+ respond(headers?: Http2HeadersRecord): number;
470
+ }
453
471
  declare class ClientHttp2Stream extends Http2EventEmitter {
454
472
  private _streamId;
455
473
  private _encoding?;
@@ -492,7 +510,10 @@ declare class ClientHttp2Stream extends Http2EventEmitter {
492
510
  }
493
511
  declare class ServerHttp2Stream extends Http2EventEmitter {
494
512
  private _streamId;
513
+ private _binding;
495
514
  private _responded;
515
+ private _endQueued;
516
+ private _pendingSyntheticErrorSuppressions;
496
517
  private _requestHeaders?;
497
518
  private _isPushStream;
498
519
  session: Http2Session;
@@ -509,6 +530,12 @@ declare class ServerHttp2Stream extends Http2EventEmitter {
509
530
  ended: boolean;
510
531
  };
511
532
  constructor(streamId: number, session: Http2Session, requestHeaders?: Http2HeadersRecord, isPushStream?: boolean);
533
+ private _closeWithCode;
534
+ private _markSyntheticClose;
535
+ _shouldSuppressHostError(): boolean;
536
+ private _emitNghttp2Error;
537
+ private _emitInternalStreamError;
538
+ private _submitResponse;
512
539
  respond(headers?: Http2HeadersRecord): void;
513
540
  pushStream(headers: Http2HeadersRecord, optionsOrCallback?: Record<string, unknown> | ((error: Error | null, stream?: ServerHttp2Stream, headers?: Http2HeadersRecord) => void), maybeCallback?: (error: Error | null, stream?: ServerHttp2Stream, headers?: Http2HeadersRecord) => void): void;
514
541
  write(data: unknown): boolean;
@@ -519,6 +546,7 @@ declare class ServerHttp2Stream extends Http2EventEmitter {
519
546
  respondWithFD(fdOrHandle: number | {
520
547
  fd?: unknown;
521
548
  }, headers?: Record<string, unknown>, options?: Record<string, unknown>): void;
549
+ destroy(error?: Error): this;
522
550
  _emitData(dataBase64?: string): void;
523
551
  _emitEnd(): void;
524
552
  _emitDrain(): void;
@@ -647,6 +675,9 @@ declare function connectHttp2(authorityOrOptions: unknown, optionsOrListener?: R
647
675
  export declare const http2: {
648
676
  Http2ServerRequest: typeof Http2ServerRequest;
649
677
  Http2ServerResponse: typeof Http2ServerResponse;
678
+ Http2Stream: typeof Http2Stream;
679
+ NghttpError: typeof NghttpError;
680
+ nghttp2ErrorString: typeof nghttp2ErrorString;
650
681
  constants: Record<string, string | number>;
651
682
  getDefaultSettings(): Http2SettingsRecord;
652
683
  connect: typeof connectHttp2;
@@ -1053,6 +1084,9 @@ declare const _default: {
1053
1084
  http2: {
1054
1085
  Http2ServerRequest: typeof Http2ServerRequest;
1055
1086
  Http2ServerResponse: typeof Http2ServerResponse;
1087
+ Http2Stream: typeof Http2Stream;
1088
+ NghttpError: typeof NghttpError;
1089
+ nghttp2ErrorString: typeof nghttp2ErrorString;
1056
1090
  constants: Record<string, string | number>;
1057
1091
  getDefaultSettings(): Http2SettingsRecord;
1058
1092
  connect: typeof connectHttp2;