secure-exec 0.0.1 → 0.1.0-rc.1

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 (112) hide show
  1. package/LICENSE +191 -0
  2. package/README.md +7 -0
  3. package/dist/bridge/active-handles.d.ts +21 -0
  4. package/dist/bridge/active-handles.js +60 -0
  5. package/dist/bridge/child-process.d.ts +87 -0
  6. package/dist/bridge/child-process.js +523 -0
  7. package/dist/bridge/fs.d.ts +227 -0
  8. package/dist/bridge/fs.js +1572 -0
  9. package/dist/bridge/index.d.ts +10 -0
  10. package/dist/bridge/index.js +41 -0
  11. package/dist/bridge/module.d.ts +73 -0
  12. package/dist/bridge/module.js +329 -0
  13. package/dist/bridge/network.d.ts +208 -0
  14. package/dist/bridge/network.js +1117 -0
  15. package/dist/bridge/os.d.ts +13 -0
  16. package/dist/bridge/os.js +257 -0
  17. package/dist/bridge/polyfills.d.ts +2 -0
  18. package/dist/bridge/polyfills.js +12 -0
  19. package/dist/bridge/process.d.ts +64 -0
  20. package/dist/bridge/process.js +916 -0
  21. package/dist/bridge-loader.d.ts +1 -0
  22. package/dist/bridge-loader.js +2 -0
  23. package/dist/bridge-setup.d.ts +1 -0
  24. package/dist/bridge-setup.js +2 -0
  25. package/dist/bridge.js +10586 -0
  26. package/dist/browser/driver.d.ts +42 -0
  27. package/dist/browser/driver.js +263 -0
  28. package/dist/browser/index.d.ts +5 -0
  29. package/dist/browser/index.js +4 -0
  30. package/dist/browser/worker.d.ts +1 -0
  31. package/dist/browser/worker.js +3 -0
  32. package/dist/browser-runtime.d.ts +6 -0
  33. package/dist/browser-runtime.js +4 -0
  34. package/dist/esm-compiler.d.ts +1 -0
  35. package/dist/esm-compiler.js +2 -0
  36. package/dist/execution.d.ts +1 -0
  37. package/dist/execution.js +2 -0
  38. package/dist/fs-helpers.d.ts +2 -0
  39. package/dist/fs-helpers.js +1 -0
  40. package/dist/generated/isolate-runtime.d.ts +19 -0
  41. package/dist/generated/isolate-runtime.js +21 -0
  42. package/dist/generated/polyfills.d.ts +82 -0
  43. package/dist/generated/polyfills.js +82 -0
  44. package/dist/index.d.ts +15 -0
  45. package/dist/index.js +11 -0
  46. package/dist/isolate-runtime/apply-custom-global-policy.js +54 -0
  47. package/dist/isolate-runtime/apply-timing-mitigation-freeze.js +44 -0
  48. package/dist/isolate-runtime/apply-timing-mitigation-off.js +14 -0
  49. package/dist/isolate-runtime/bridge-attach.js +29 -0
  50. package/dist/isolate-runtime/bridge-initial-globals.js +78 -0
  51. package/dist/isolate-runtime/eval-script-result.js +8 -0
  52. package/dist/isolate-runtime/global-exposure-helpers.js +36 -0
  53. package/dist/isolate-runtime/init-commonjs-module-globals.js +28 -0
  54. package/dist/isolate-runtime/override-process-cwd.js +8 -0
  55. package/dist/isolate-runtime/override-process-env.js +8 -0
  56. package/dist/isolate-runtime/require-setup.js +606 -0
  57. package/dist/isolate-runtime/set-commonjs-file-globals.js +36 -0
  58. package/dist/isolate-runtime/set-stdin-data.js +10 -0
  59. package/dist/isolate-runtime/setup-dynamic-import.js +64 -0
  60. package/dist/isolate-runtime/setup-fs-facade.js +40 -0
  61. package/dist/isolate.d.ts +1 -0
  62. package/dist/isolate.js +2 -0
  63. package/dist/module-resolver.d.ts +1 -0
  64. package/dist/module-resolver.js +2 -0
  65. package/dist/node/bridge-setup.d.ts +1 -0
  66. package/dist/node/bridge-setup.js +2 -0
  67. package/dist/node/driver.d.ts +2 -0
  68. package/dist/node/driver.js +2 -0
  69. package/dist/node/esm-compiler.d.ts +1 -0
  70. package/dist/node/esm-compiler.js +2 -0
  71. package/dist/node/execution-driver.d.ts +2 -0
  72. package/dist/node/execution-driver.js +2 -0
  73. package/dist/node/execution-lifecycle.d.ts +1 -0
  74. package/dist/node/execution-lifecycle.js +2 -0
  75. package/dist/node/isolate-bootstrap.d.ts +2 -0
  76. package/dist/node/isolate-bootstrap.js +1 -0
  77. package/dist/node/module-access.d.ts +2 -0
  78. package/dist/node/module-access.js +2 -0
  79. package/dist/node/module-resolver.d.ts +1 -0
  80. package/dist/node/module-resolver.js +2 -0
  81. package/dist/package-bundler.d.ts +2 -0
  82. package/dist/package-bundler.js +1 -0
  83. package/dist/polyfills.d.ts +1 -0
  84. package/dist/polyfills.js +2 -0
  85. package/dist/python-runtime.d.ts +2 -0
  86. package/dist/python-runtime.js +2 -0
  87. package/dist/runtime-driver.d.ts +1 -0
  88. package/dist/runtime-driver.js +1 -0
  89. package/dist/runtime.d.ts +2 -0
  90. package/dist/runtime.js +2 -0
  91. package/dist/shared/api-types.d.ts +1 -0
  92. package/dist/shared/api-types.js +1 -0
  93. package/dist/shared/bridge-contract.d.ts +2 -0
  94. package/dist/shared/bridge-contract.js +1 -0
  95. package/dist/shared/console-formatter.d.ts +2 -0
  96. package/dist/shared/console-formatter.js +1 -0
  97. package/dist/shared/errors.d.ts +2 -0
  98. package/dist/shared/errors.js +1 -0
  99. package/dist/shared/esm-utils.d.ts +1 -0
  100. package/dist/shared/esm-utils.js +2 -0
  101. package/dist/shared/global-exposure.d.ts +2 -0
  102. package/dist/shared/global-exposure.js +1 -0
  103. package/dist/shared/in-memory-fs.d.ts +1 -0
  104. package/dist/shared/in-memory-fs.js +2 -0
  105. package/dist/shared/permissions.d.ts +1 -0
  106. package/dist/shared/permissions.js +2 -0
  107. package/dist/shared/require-setup.d.ts +1 -0
  108. package/dist/shared/require-setup.js +2 -0
  109. package/dist/types.d.ts +2 -0
  110. package/dist/types.js +1 -0
  111. package/package.json +51 -4
  112. package/index.js +0 -1
@@ -0,0 +1,10 @@
1
+ import "./polyfills.js";
2
+ import { _registerHandle, _unregisterHandle, _waitForActiveHandles, _getActiveHandles } from "./active-handles.js";
3
+ import fs from "./fs.js";
4
+ import os from "./os.js";
5
+ import * as childProcess from "./child-process.js";
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";
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, };
10
+ export default fs;
@@ -0,0 +1,41 @@
1
+ // Bridge module entry point
2
+ // This file is compiled to a single JS bundle that gets injected into the isolate
3
+ //
4
+ // Each module provides polyfills for Node.js built-in modules that need to
5
+ // communicate with the host environment via isolated-vm bridge functions.
6
+ // IMPORTANT: Import polyfills FIRST before any other modules!
7
+ // Some packages (like whatwg-url) use TextEncoder/TextDecoder at module load time.
8
+ // This import installs them on globalThis before other imports execute.
9
+ import "./polyfills.js";
10
+ // Active handles mechanism - must be imported early so other modules can use it.
11
+ // See: docs-internal/node/ACTIVE_HANDLES.md
12
+ import { _registerHandle, _unregisterHandle, _waitForActiveHandles, _getActiveHandles, } from "./active-handles.js";
13
+ // File system module
14
+ import fs from "./fs.js";
15
+ // Operating system module
16
+ import os from "./os.js";
17
+ // Child process module
18
+ import * as childProcess from "./child-process.js";
19
+ // Network modules (fetch, dns, http, https)
20
+ import * as network from "./network.js";
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";
23
+ // Module system (createRequire, Module class)
24
+ import moduleModule, { createRequire, Module, SourceMap } from "./module.js";
25
+ // Export all modules
26
+ export {
27
+ // Core modules
28
+ fs, os, childProcess, process, moduleModule as module,
29
+ // Network
30
+ network,
31
+ // Process globals
32
+ setupGlobals, setTimeout, clearTimeout, setInterval, clearInterval, setImmediate, clearImmediate, URL, URLSearchParams, TextEncoder, TextDecoder, Buffer, cryptoPolyfill, ProcessExitError,
33
+ // Module utilities
34
+ createRequire, Module, SourceMap,
35
+ // Active handles (see docs-internal/node/ACTIVE_HANDLES.md)
36
+ _registerHandle, _unregisterHandle, _waitForActiveHandles, _getActiveHandles, };
37
+ // Default export is fs for backward compatibility
38
+ export default fs;
39
+ // Auto-setup globals when bridge loads
40
+ // This installs process, timers, URL, Buffer, crypto, etc. on globalThis
41
+ setupGlobals();
@@ -0,0 +1,73 @@
1
+ interface RequireFunction {
2
+ (request: string): unknown;
3
+ resolve: RequireResolve;
4
+ cache: Record<string, {
5
+ exports: unknown;
6
+ }>;
7
+ main: Module | undefined;
8
+ extensions: Record<string, (module: Module, filename: string) => void>;
9
+ }
10
+ interface RequireResolve {
11
+ (request: string, options?: {
12
+ paths?: string[];
13
+ }): string;
14
+ paths: (request: string) => string[] | null;
15
+ }
16
+ /**
17
+ * Create a require function that resolves relative to the given filename.
18
+ * This mimics Node.js's module.createRequire(filename).
19
+ */
20
+ export declare function createRequire(filename: string | URL): RequireFunction;
21
+ /**
22
+ * Module class constructor (for compatibility with promzard and similar)
23
+ */
24
+ export declare class Module {
25
+ id: string;
26
+ path: string;
27
+ exports: unknown;
28
+ filename: string;
29
+ loaded: boolean;
30
+ children: Module[];
31
+ paths: string[];
32
+ parent: Module | null | undefined;
33
+ isPreloading: boolean;
34
+ constructor(id: string, parent?: Module | null);
35
+ require(request: string): unknown;
36
+ _compile(content: string, filename: string): unknown;
37
+ static _extensions: Record<string, (module: Module, filename: string) => void>;
38
+ static _cache: Record<string, {
39
+ exports: unknown;
40
+ }>;
41
+ static _resolveFilename(request: string, parent: Module | null | undefined, _isMain?: boolean, _options?: unknown): string;
42
+ static wrap(content: string): string;
43
+ static builtinModules: string[];
44
+ static isBuiltin(moduleName: string): boolean;
45
+ static createRequire: typeof createRequire;
46
+ static syncBuiltinESMExports(): void;
47
+ static findSourceMap(_path: string): undefined;
48
+ static _nodeModulePaths(from: string): string[];
49
+ static _load(request: string, parent: Module | null | undefined, _isMain?: boolean): unknown;
50
+ static runMain(): void;
51
+ }
52
+ export declare class SourceMap {
53
+ constructor(_payload: unknown);
54
+ get payload(): never;
55
+ set payload(_value: unknown);
56
+ findEntry(_line: number, _column: number): never;
57
+ }
58
+ declare const moduleModule: {
59
+ Module: typeof Module;
60
+ createRequire: typeof createRequire;
61
+ _extensions: Record<string, (module: Module, filename: string) => void>;
62
+ _cache: Record<string, {
63
+ exports: unknown;
64
+ }>;
65
+ builtinModules: string[];
66
+ isBuiltin: typeof Module.isBuiltin;
67
+ _resolveFilename: typeof Module._resolveFilename;
68
+ wrap: typeof Module.wrap;
69
+ syncBuiltinESMExports: typeof Module.syncBuiltinESMExports;
70
+ findSourceMap: typeof Module.findSourceMap;
71
+ SourceMap: typeof SourceMap;
72
+ };
73
+ export default moduleModule;
@@ -0,0 +1,329 @@
1
+ import { exposeCustomGlobal } from "../shared/global-exposure.js";
2
+ // Path utilities for module resolution
3
+ function _pathDirname(p) {
4
+ const lastSlash = p.lastIndexOf("/");
5
+ if (lastSlash === -1)
6
+ return ".";
7
+ if (lastSlash === 0)
8
+ return "/";
9
+ return p.slice(0, lastSlash);
10
+ }
11
+ function _pathResolve(...segments) {
12
+ let resolvedPath = "";
13
+ let resolvedAbsolute = false;
14
+ for (let i = segments.length - 1; i >= 0 && !resolvedAbsolute; i--) {
15
+ const segment = segments[i];
16
+ if (!segment)
17
+ continue;
18
+ resolvedPath = segment + "/" + resolvedPath;
19
+ resolvedAbsolute = segment.charAt(0) === "/";
20
+ }
21
+ // Normalize the path
22
+ const parts = resolvedPath.split("/").filter(Boolean);
23
+ const result = [];
24
+ for (const part of parts) {
25
+ if (part === "..") {
26
+ result.pop();
27
+ }
28
+ else if (part !== ".") {
29
+ result.push(part);
30
+ }
31
+ }
32
+ return (resolvedAbsolute ? "/" : "") + result.join("/") || ".";
33
+ }
34
+ function _parseFileUrl(url) {
35
+ // Handle file:// URLs
36
+ if (url.startsWith("file://")) {
37
+ // Remove file:// prefix
38
+ let path = url.slice(7);
39
+ // Handle file:///path on Unix (3 slashes = absolute path)
40
+ if (path.startsWith("/")) {
41
+ return path;
42
+ }
43
+ // Handle file://host/path (rare, treat host as empty)
44
+ return "/" + path;
45
+ }
46
+ return url;
47
+ }
48
+ /**
49
+ * Create a require function that resolves relative to the given filename.
50
+ * This mimics Node.js's module.createRequire(filename).
51
+ */
52
+ export function createRequire(filename) {
53
+ if (typeof filename !== "string" && !(filename instanceof URL)) {
54
+ throw new TypeError("filename must be a string or URL");
55
+ }
56
+ // Parse file:// URLs
57
+ const filepath = _parseFileUrl(String(filename));
58
+ const dirname = _pathDirname(filepath);
59
+ const builtins = [
60
+ "fs",
61
+ "path",
62
+ "os",
63
+ "events",
64
+ "util",
65
+ "http",
66
+ "https",
67
+ "dns",
68
+ "child_process",
69
+ "stream",
70
+ "buffer",
71
+ "url",
72
+ "querystring",
73
+ "crypto",
74
+ "zlib",
75
+ "assert",
76
+ "tty",
77
+ "net",
78
+ "tls",
79
+ ];
80
+ // Create resolve.paths function
81
+ const resolvePaths = function (request) {
82
+ // For built-in modules, return null
83
+ if (builtins.includes(request) || request.startsWith("node:")) {
84
+ return null;
85
+ }
86
+ // For relative paths, return array starting from dirname
87
+ if (request.startsWith("./") ||
88
+ request.startsWith("../") ||
89
+ request.startsWith("/")) {
90
+ return [dirname];
91
+ }
92
+ // For bare specifiers, return node_modules search paths
93
+ const paths = [];
94
+ let current = dirname;
95
+ while (current !== "/") {
96
+ paths.push(current + "/node_modules");
97
+ current = _pathDirname(current);
98
+ }
99
+ paths.push("/node_modules");
100
+ return paths;
101
+ };
102
+ // Create resolve function
103
+ const resolve = function (request, _options) {
104
+ const resolved = _resolveModule.applySyncPromise(undefined, [
105
+ request,
106
+ dirname,
107
+ ]);
108
+ if (resolved === null) {
109
+ const err = new Error("Cannot find module '" + request + "'");
110
+ err.code = "MODULE_NOT_FOUND";
111
+ throw err;
112
+ }
113
+ return resolved;
114
+ };
115
+ resolve.paths = resolvePaths;
116
+ // Create a require function bound to this directory
117
+ const requireFn = function (request) {
118
+ return _requireFrom(request, dirname);
119
+ };
120
+ // Add require.resolve
121
+ requireFn.resolve = resolve;
122
+ // Add require.cache reference to global module cache
123
+ requireFn.cache = _moduleCache;
124
+ // Add require.main (null for dynamically created require)
125
+ requireFn.main = undefined;
126
+ // Add require.extensions (deprecated but still used by some tools)
127
+ requireFn.extensions = {
128
+ ".js": function (_module, _filename) {
129
+ // This is a stub - actual loading is handled by our require implementation
130
+ },
131
+ ".json": function (_module, _filename) {
132
+ // JSON loading stub
133
+ },
134
+ ".node": function (_module, _filename) {
135
+ throw new Error(".node extensions are not supported in sandbox");
136
+ },
137
+ };
138
+ return requireFn;
139
+ }
140
+ /**
141
+ * Module class constructor (for compatibility with promzard and similar)
142
+ */
143
+ export class Module {
144
+ id;
145
+ path;
146
+ exports;
147
+ filename;
148
+ loaded;
149
+ children;
150
+ paths;
151
+ parent;
152
+ isPreloading;
153
+ constructor(id, parent) {
154
+ this.id = id;
155
+ this.path = _pathDirname(id);
156
+ this.exports = {};
157
+ this.filename = id;
158
+ this.loaded = false;
159
+ this.children = [];
160
+ this.paths = [];
161
+ this.parent = parent;
162
+ this.isPreloading = false;
163
+ // Build module paths
164
+ let current = this.path;
165
+ while (current !== "/") {
166
+ this.paths.push(current + "/node_modules");
167
+ current = _pathDirname(current);
168
+ }
169
+ this.paths.push("/node_modules");
170
+ }
171
+ require(request) {
172
+ return _requireFrom(request, this.path);
173
+ }
174
+ _compile(content, filename) {
175
+ // Create wrapper function and execute
176
+ const wrapper = new Function("exports", "require", "module", "__filename", "__dirname", content);
177
+ const moduleRequire = (request) => _requireFrom(request, this.path);
178
+ moduleRequire.resolve = (request) => {
179
+ const resolved = _resolveModule.applySyncPromise(undefined, [
180
+ request,
181
+ this.path,
182
+ ]);
183
+ if (resolved === null) {
184
+ const err = new Error("Cannot find module '" + request + "'");
185
+ err.code = "MODULE_NOT_FOUND";
186
+ throw err;
187
+ }
188
+ return resolved;
189
+ };
190
+ wrapper(this.exports, moduleRequire, this, filename, this.path);
191
+ this.loaded = true;
192
+ return this.exports;
193
+ }
194
+ static _extensions = {
195
+ ".js": function (module, filename) {
196
+ const fs = _requireFrom("fs", "/");
197
+ const content = fs.readFileSync(filename, "utf8");
198
+ module._compile(content, filename);
199
+ },
200
+ ".json": function (module, filename) {
201
+ const fs = _requireFrom("fs", "/");
202
+ const content = fs.readFileSync(filename, "utf8");
203
+ module.exports = JSON.parse(content);
204
+ },
205
+ ".node": function () {
206
+ throw new Error(".node extensions are not supported in sandbox");
207
+ },
208
+ };
209
+ static _cache = typeof _moduleCache !== "undefined"
210
+ ? _moduleCache
211
+ : {};
212
+ static _resolveFilename(request, parent, _isMain, _options) {
213
+ const parentDir = parent && parent.path ? parent.path : "/";
214
+ const resolved = _resolveModule.applySyncPromise(undefined, [
215
+ request,
216
+ parentDir,
217
+ ]);
218
+ if (resolved === null) {
219
+ const err = new Error("Cannot find module '" + request + "'");
220
+ err.code = "MODULE_NOT_FOUND";
221
+ throw err;
222
+ }
223
+ return resolved;
224
+ }
225
+ static wrap(content) {
226
+ return ("(function (exports, require, module, __filename, __dirname) { " +
227
+ content +
228
+ "\n});");
229
+ }
230
+ static builtinModules = [
231
+ "assert",
232
+ "buffer",
233
+ "child_process",
234
+ "crypto",
235
+ "dns",
236
+ "events",
237
+ "fs",
238
+ "http",
239
+ "https",
240
+ "net",
241
+ "os",
242
+ "path",
243
+ "querystring",
244
+ "stream",
245
+ "string_decoder",
246
+ "timers",
247
+ "tls",
248
+ "tty",
249
+ "url",
250
+ "util",
251
+ "zlib",
252
+ "vm",
253
+ "module",
254
+ ];
255
+ static isBuiltin(moduleName) {
256
+ const name = moduleName.replace(/^node:/, "");
257
+ return Module.builtinModules.includes(name);
258
+ }
259
+ static createRequire = createRequire;
260
+ static syncBuiltinESMExports() {
261
+ // No-op in our environment
262
+ }
263
+ static findSourceMap(_path) {
264
+ return undefined;
265
+ }
266
+ static _nodeModulePaths(from) {
267
+ // Return array of node_modules paths from the given directory up to root
268
+ const paths = [];
269
+ let current = from;
270
+ while (current !== "/") {
271
+ paths.push(current + "/node_modules");
272
+ current = _pathDirname(current);
273
+ if (current === ".")
274
+ break;
275
+ }
276
+ paths.push("/node_modules");
277
+ return paths;
278
+ }
279
+ static _load(request, parent, _isMain) {
280
+ // Use our require system
281
+ const parentDir = parent && parent.path ? parent.path : "/";
282
+ return _requireFrom(request, parentDir);
283
+ }
284
+ static runMain() {
285
+ // No-op - we don't have a main module in this context
286
+ }
287
+ }
288
+ // SourceMap class - not implemented
289
+ export class SourceMap {
290
+ constructor(_payload) {
291
+ throw new Error("SourceMap is not implemented in sandbox");
292
+ }
293
+ get payload() {
294
+ throw new Error("SourceMap is not implemented in sandbox");
295
+ }
296
+ set payload(_value) {
297
+ throw new Error("SourceMap is not implemented in sandbox");
298
+ }
299
+ findEntry(_line, _column) {
300
+ throw new Error("SourceMap is not implemented in sandbox");
301
+ }
302
+ }
303
+ // Module namespace export matching Node.js 'module' module
304
+ // Note: We don't strictly satisfy typeof nodeModule due to complex intersection types
305
+ const moduleModule = {
306
+ Module: Module,
307
+ createRequire: createRequire,
308
+ // Module._extensions (deprecated alias)
309
+ _extensions: Module._extensions,
310
+ // Module._cache reference
311
+ _cache: Module._cache,
312
+ // Built-in module list
313
+ builtinModules: Module.builtinModules,
314
+ // isBuiltin check
315
+ isBuiltin: Module.isBuiltin,
316
+ // Module._resolveFilename (internal but sometimes used)
317
+ _resolveFilename: Module._resolveFilename,
318
+ // wrap function
319
+ wrap: Module.wrap,
320
+ // syncBuiltinESMExports (stub for ESM interop)
321
+ syncBuiltinESMExports: Module.syncBuiltinESMExports,
322
+ // findSourceMap (stub)
323
+ findSourceMap: Module.findSourceMap,
324
+ // SourceMap class (stub)
325
+ SourceMap: SourceMap,
326
+ };
327
+ // Expose to global for require() to use
328
+ exposeCustomGlobal("_moduleModule", moduleModule);
329
+ export default moduleModule;
@@ -0,0 +1,208 @@
1
+ import type * as nodeHttp from "http";
2
+ interface FetchOptions {
3
+ method?: string;
4
+ headers?: Record<string, string>;
5
+ body?: string | null;
6
+ mode?: string;
7
+ credentials?: string;
8
+ cache?: string;
9
+ redirect?: string;
10
+ referrer?: string;
11
+ integrity?: string;
12
+ }
13
+ interface FetchResponse {
14
+ ok: boolean;
15
+ status: number;
16
+ statusText: string;
17
+ headers: Map<string, string>;
18
+ url: string;
19
+ redirected: boolean;
20
+ type: string;
21
+ text(): Promise<string>;
22
+ json(): Promise<unknown>;
23
+ arrayBuffer(): Promise<ArrayBuffer>;
24
+ blob(): Promise<never>;
25
+ clone(): FetchResponse;
26
+ }
27
+ export declare function fetch(url: string | URL, options?: FetchOptions): Promise<FetchResponse>;
28
+ export declare class Headers {
29
+ private _headers;
30
+ constructor(init?: HeadersInit | Headers | Record<string, string> | [string, string][]);
31
+ get(name: string): string | null;
32
+ set(name: string, value: string): void;
33
+ has(name: string): boolean;
34
+ delete(name: string): void;
35
+ entries(): IterableIterator<[string, string]>;
36
+ [Symbol.iterator](): IterableIterator<[string, string]>;
37
+ keys(): IterableIterator<string>;
38
+ values(): IterableIterator<string>;
39
+ forEach(callback: (value: string, key: string, parent: Headers) => void): void;
40
+ }
41
+ export declare class Request {
42
+ url: string;
43
+ method: string;
44
+ headers: Headers;
45
+ body: string | null;
46
+ mode: string;
47
+ credentials: string;
48
+ cache: string;
49
+ redirect: string;
50
+ referrer: string;
51
+ integrity: string;
52
+ constructor(input: string | Request, init?: FetchOptions);
53
+ clone(): Request;
54
+ }
55
+ export declare class Response {
56
+ private _body;
57
+ status: number;
58
+ statusText: string;
59
+ headers: Headers;
60
+ ok: boolean;
61
+ type: string;
62
+ url: string;
63
+ redirected: boolean;
64
+ constructor(body?: string | null, init?: {
65
+ status?: number;
66
+ statusText?: string;
67
+ headers?: Record<string, string>;
68
+ });
69
+ text(): Promise<string>;
70
+ json(): Promise<unknown>;
71
+ clone(): Response;
72
+ static error(): Response;
73
+ static redirect(url: string, status?: number): Response;
74
+ }
75
+ type DnsCallback = (err: Error | null, address?: string, family?: number) => void;
76
+ type DnsResolveCallback = (err: Error | null, addresses?: string[]) => void;
77
+ export declare const dns: {
78
+ lookup(hostname: string, options: unknown, callback?: DnsCallback): void;
79
+ resolve(hostname: string, rrtype: string | DnsResolveCallback, callback?: DnsResolveCallback): void;
80
+ resolve4(hostname: string, callback: DnsResolveCallback): void;
81
+ resolve6(hostname: string, callback: DnsResolveCallback): void;
82
+ promises: {
83
+ lookup(hostname: string, _options?: unknown): Promise<{
84
+ address: string;
85
+ family: number;
86
+ }>;
87
+ resolve(hostname: string, rrtype?: string): Promise<string[]>;
88
+ };
89
+ };
90
+ type EventListener = (...args: unknown[]) => void;
91
+ export declare class IncomingMessage {
92
+ headers: Record<string, string>;
93
+ rawHeaders: string[];
94
+ trailers: Record<string, string>;
95
+ rawTrailers: string[];
96
+ httpVersion: string;
97
+ httpVersionMajor: number;
98
+ httpVersionMinor: number;
99
+ method: string | null;
100
+ url: string;
101
+ statusCode: number | undefined;
102
+ statusMessage: string | undefined;
103
+ private _body;
104
+ private _isBinary;
105
+ private _listeners;
106
+ complete: boolean;
107
+ aborted: boolean;
108
+ socket: null;
109
+ private _bodyConsumed;
110
+ private _ended;
111
+ private _flowing;
112
+ readable: boolean;
113
+ readableEnded: boolean;
114
+ readableFlowing: boolean | null;
115
+ destroyed: boolean;
116
+ private _encoding?;
117
+ constructor(response?: {
118
+ headers?: Record<string, string>;
119
+ url?: string;
120
+ status?: number;
121
+ statusText?: string;
122
+ body?: string;
123
+ });
124
+ on(event: string, listener: EventListener): this;
125
+ once(event: string, listener: EventListener): this;
126
+ off(event: string, listener: EventListener): this;
127
+ removeListener(event: string, listener: EventListener): this;
128
+ removeAllListeners(event?: string): this;
129
+ emit(event: string, ...args: unknown[]): boolean;
130
+ setEncoding(encoding: string): this;
131
+ read(_size?: number): string | Buffer | null;
132
+ pipe<T extends NodeJS.WritableStream>(dest: T): T;
133
+ pause(): this;
134
+ resume(): this;
135
+ unpipe(_dest?: NodeJS.WritableStream): this;
136
+ destroy(err?: Error): this;
137
+ [Symbol.asyncIterator](): AsyncIterator<string | Buffer>;
138
+ }
139
+ export declare class ClientRequest {
140
+ private _options;
141
+ private _callback?;
142
+ private _listeners;
143
+ private _body;
144
+ private _ended;
145
+ socket: null;
146
+ finished: boolean;
147
+ aborted: boolean;
148
+ constructor(options: nodeHttp.RequestOptions, callback?: (res: IncomingMessage) => void);
149
+ private _execute;
150
+ private _buildUrl;
151
+ on(event: string, listener: EventListener): this;
152
+ once(event: string, listener: EventListener): this;
153
+ off(event: string, listener: EventListener): this;
154
+ private _emit;
155
+ write(data: string): boolean;
156
+ end(data?: string): this;
157
+ abort(): void;
158
+ setTimeout(_timeout: number): this;
159
+ setNoDelay(): this;
160
+ setSocketKeepAlive(): this;
161
+ flushHeaders(): void;
162
+ }
163
+ export declare const http: Partial<typeof nodeHttp>;
164
+ export declare const https: Partial<typeof nodeHttp>;
165
+ export declare const http2: {
166
+ Http2ServerRequest: {
167
+ new (): {};
168
+ };
169
+ Http2ServerResponse: {
170
+ new (): {};
171
+ };
172
+ createServer(): never;
173
+ createSecureServer(): never;
174
+ };
175
+ declare const _default: {
176
+ fetch: typeof fetch;
177
+ Headers: typeof Headers;
178
+ Request: typeof Request;
179
+ Response: typeof Response;
180
+ dns: {
181
+ lookup(hostname: string, options: unknown, callback?: DnsCallback): void;
182
+ resolve(hostname: string, rrtype: string | DnsResolveCallback, callback?: DnsResolveCallback): void;
183
+ resolve4(hostname: string, callback: DnsResolveCallback): void;
184
+ resolve6(hostname: string, callback: DnsResolveCallback): void;
185
+ promises: {
186
+ lookup(hostname: string, _options?: unknown): Promise<{
187
+ address: string;
188
+ family: number;
189
+ }>;
190
+ resolve(hostname: string, rrtype?: string): Promise<string[]>;
191
+ };
192
+ };
193
+ http: Partial<typeof nodeHttp>;
194
+ https: Partial<typeof nodeHttp>;
195
+ http2: {
196
+ Http2ServerRequest: {
197
+ new (): {};
198
+ };
199
+ Http2ServerResponse: {
200
+ new (): {};
201
+ };
202
+ createServer(): never;
203
+ createSecureServer(): never;
204
+ };
205
+ IncomingMessage: typeof IncomingMessage;
206
+ ClientRequest: typeof ClientRequest;
207
+ };
208
+ export default _default;