@openclaw/diagnostics-otel 2026.7.1-beta.2 → 2026.7.1-beta.4
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/index.js +1 -2404
- package/dist/runtime-api-BUlvn2ET.js +2589 -0
- package/dist/runtime-api.js +2 -0
- package/node_modules/@types/node/README.md +1 -1
- package/node_modules/@types/node/assert/strict.d.ts +10 -1
- package/node_modules/@types/node/assert.d.ts +144 -17
- package/node_modules/@types/node/async_hooks.d.ts +9 -9
- package/node_modules/@types/node/buffer.d.ts +64 -30
- package/node_modules/@types/node/child_process.d.ts +17 -21
- package/node_modules/@types/node/cluster.d.ts +13 -13
- package/node_modules/@types/node/console.d.ts +1 -1
- package/node_modules/@types/node/crypto.d.ts +471 -575
- package/node_modules/@types/node/diagnostics_channel.d.ts +274 -32
- package/node_modules/@types/node/dns.d.ts +15 -15
- package/node_modules/@types/node/events.d.ts +3 -3
- package/node_modules/@types/node/ffi.d.ts +486 -0
- package/node_modules/@types/node/fs/promises.d.ts +7 -4
- package/node_modules/@types/node/fs.d.ts +24 -18
- package/node_modules/@types/node/globals.d.ts +4 -4
- package/node_modules/@types/node/http.d.ts +30 -5
- package/node_modules/@types/node/http2.d.ts +5 -1
- package/node_modules/@types/node/index.d.ts +1 -3
- package/node_modules/@types/node/inspector.d.ts +1 -1
- package/node_modules/@types/node/module.d.ts +16 -45
- package/node_modules/@types/node/net.d.ts +1 -1
- package/node_modules/@types/node/os.d.ts +2 -2
- package/node_modules/@types/node/package.json +4 -4
- package/node_modules/@types/node/perf_hooks.d.ts +1 -9
- package/node_modules/@types/node/process.d.ts +25 -12
- package/node_modules/@types/node/quic.d.ts +92 -11
- package/node_modules/@types/node/readline.d.ts +12 -11
- package/node_modules/@types/node/repl.d.ts +10 -10
- package/node_modules/@types/node/sqlite.d.ts +56 -1
- package/node_modules/@types/node/stream/iter.d.ts +150 -0
- package/node_modules/@types/node/stream/promises.d.ts +2 -2
- package/node_modules/@types/node/stream/web.d.ts +1 -1
- package/node_modules/@types/node/stream.d.ts +37 -5
- package/node_modules/@types/node/test/reporters.d.ts +1 -1
- package/node_modules/@types/node/test.d.ts +120 -10
- package/node_modules/@types/node/tls.d.ts +1 -1
- package/node_modules/@types/node/ts5.6/index.d.ts +2 -4
- package/node_modules/@types/node/ts5.7/index.d.ts +1 -3
- package/node_modules/@types/node/url.d.ts +3 -3
- package/node_modules/@types/node/util/types.d.ts +1 -1
- package/node_modules/@types/node/util.d.ts +22 -22
- package/node_modules/@types/node/v8.d.ts +85 -3
- package/node_modules/@types/node/vm.d.ts +9 -9
- package/node_modules/@types/node/web-globals/domexception.d.ts +15 -0
- package/node_modules/@types/node/worker_threads.d.ts +10 -12
- package/node_modules/@types/node/zlib.d.ts +3 -3
- package/node_modules/acorn/CHANGELOG.md +14 -0
- package/node_modules/acorn/README.md +3 -0
- package/node_modules/acorn/dist/acorn.d.mts +6 -0
- package/node_modules/acorn/dist/acorn.d.ts +6 -0
- package/node_modules/acorn/dist/acorn.js +87 -49
- package/node_modules/acorn/dist/acorn.mjs +87 -49
- package/node_modules/acorn/package.json +2 -2
- package/node_modules/import-in-the-middle/CHANGELOG.md +21 -0
- package/node_modules/import-in-the-middle/README.md +60 -0
- package/node_modules/import-in-the-middle/create-hook.mjs +375 -146
- package/node_modules/import-in-the-middle/lib/get-exports.mjs +88 -52
- package/node_modules/import-in-the-middle/lib/io.mjs +78 -0
- package/node_modules/import-in-the-middle/package.json +1 -1
- package/node_modules/import-in-the-middle/register-hooks.d.ts +35 -0
- package/node_modules/import-in-the-middle/register-hooks.mjs +63 -0
- package/node_modules/undici-types/agent.d.ts +0 -2
- package/node_modules/undici-types/client.d.ts +25 -19
- package/node_modules/undici-types/dispatcher.d.ts +7 -33
- package/node_modules/undici-types/dispatcher1-wrapper.d.ts +7 -0
- package/node_modules/undici-types/fetch.d.ts +24 -4
- package/node_modules/undici-types/h2c-client.d.ts +6 -6
- package/node_modules/undici-types/handlers.d.ts +1 -2
- package/node_modules/undici-types/header.d.ts +5 -0
- package/node_modules/undici-types/index.d.ts +3 -1
- package/node_modules/undici-types/interceptors.d.ts +1 -1
- package/node_modules/undici-types/package.json +1 -1
- package/node_modules/undici-types/pool.d.ts +0 -2
- package/node_modules/undici-types/proxy-agent.d.ts +2 -2
- package/node_modules/undici-types/round-robin-pool.d.ts +0 -2
- package/node_modules/undici-types/snapshot-agent.d.ts +4 -0
- package/node_modules/undici-types/socks5-proxy-agent.d.ts +2 -2
- package/node_modules/undici-types/webidl.d.ts +0 -1
- package/node_modules/yargs/CHANGELOG.md +330 -0
- package/node_modules/yargs/build/index.cjs +1 -1
- package/node_modules/yargs/package.json +6 -4
- package/node_modules/yargs/yargs +5 -9
- package/node_modules/yargs/yargs.cjs +15 -0
- package/npm-shrinkwrap.json +18 -18
- package/package.json +4 -4
- package/node_modules/@types/node/compatibility/iterators.d.ts +0 -21
- package/node_modules/yargs/browser.d.ts +0 -5
|
@@ -1,17 +1,29 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
import getEsmExports from './get-esm-exports.mjs'
|
|
4
|
-
import { parse as parseCjs,
|
|
4
|
+
import { parse as parseCjs, initSync } from 'cjs-module-lexer'
|
|
5
5
|
import { readFileSync, existsSync } from 'fs'
|
|
6
6
|
import { builtinModules, createRequire } from 'module'
|
|
7
7
|
import { fileURLToPath, pathToFileURL } from 'url'
|
|
8
8
|
import { dirname, join } from 'path'
|
|
9
|
+
import { LOAD } from './io.mjs'
|
|
9
10
|
|
|
10
11
|
const nodeMajor = Number(process.versions.node.split('.')[0])
|
|
11
12
|
export const hasModuleExportsCJSDefault = nodeMajor >= 23
|
|
12
13
|
|
|
13
14
|
let parserInitialized = false
|
|
14
15
|
|
|
16
|
+
// The CJS export scanner is backed by WebAssembly. `initSync` compiles it
|
|
17
|
+
// up front so the scanner can run inside synchronous loader hooks
|
|
18
|
+
// (`module.registerHooks`) as well as the off-thread loader; it is a one-time
|
|
19
|
+
// cost on the first CommonJS module either way.
|
|
20
|
+
function ensureParserInitialized () {
|
|
21
|
+
if (!parserInitialized) {
|
|
22
|
+
initSync()
|
|
23
|
+
parserInitialized = true
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
15
27
|
function addDefault (arr) {
|
|
16
28
|
return new Set(['default', ...arr])
|
|
17
29
|
}
|
|
@@ -142,15 +154,33 @@ const BUILT_INS = new Map()
|
|
|
142
154
|
|
|
143
155
|
let require
|
|
144
156
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
157
|
+
// Returns a builtin's exports object. `process.getBuiltinModule` (Node >=
|
|
158
|
+
// 20.16 / >= 22.3) bypasses registered loader hooks; `require` does not. Under
|
|
159
|
+
// the in-thread `module.registerHooks` loader a plain `require(name)` here
|
|
160
|
+
// re-enters iitm's own hooks and resolves to the half-built wrapper instead of
|
|
161
|
+
// the native module. The off-thread `module.register` loader runs `require` on
|
|
162
|
+
// the loader thread where the hooks aren't installed, so the fallback stays
|
|
163
|
+
// correct on older Node that lacks getBuiltinModule.
|
|
164
|
+
function loadBuiltin (name) {
|
|
165
|
+
if (typeof process.getBuiltinModule === 'function') {
|
|
166
|
+
return process.getBuiltinModule(name)
|
|
167
|
+
}
|
|
148
168
|
if (!require) {
|
|
149
169
|
require = createRequire(import.meta.url)
|
|
150
170
|
}
|
|
171
|
+
return require(name)
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function getExportsForNodeBuiltIn (name) {
|
|
175
|
+
let exports = BUILT_INS.get(name)
|
|
151
176
|
|
|
152
177
|
if (!exports) {
|
|
153
|
-
|
|
178
|
+
// get all properties both enumerable and non-enumerable
|
|
179
|
+
exports = new Set(addDefault(Object.getOwnPropertyNames(loadBuiltin(name))))
|
|
180
|
+
// added in node 23 as alias for default in cjs modules
|
|
181
|
+
if (hasModuleExportsCJSDefault) {
|
|
182
|
+
exports.add('module.exports')
|
|
183
|
+
}
|
|
154
184
|
BUILT_INS.set(name, exports)
|
|
155
185
|
}
|
|
156
186
|
|
|
@@ -215,52 +245,54 @@ function resolvePackageImports (specifier, fromUrl) {
|
|
|
215
245
|
return null
|
|
216
246
|
}
|
|
217
247
|
|
|
218
|
-
|
|
248
|
+
function * getCjsExports (url, context, source) {
|
|
219
249
|
if (urlsBeingProcessed.has(url)) {
|
|
220
250
|
return new Set()
|
|
221
251
|
}
|
|
222
252
|
urlsBeingProcessed.add(url)
|
|
223
253
|
|
|
224
254
|
try {
|
|
225
|
-
|
|
226
|
-
await parserInit()
|
|
227
|
-
parserInitialized = true
|
|
228
|
-
}
|
|
255
|
+
ensureParserInitialized()
|
|
229
256
|
const result = parseCjs(source)
|
|
230
257
|
const full = addDefault(result.exports)
|
|
231
258
|
|
|
232
|
-
|
|
233
|
-
if (
|
|
234
|
-
for (const each of getExportsForNodeBuiltIn(
|
|
259
|
+
for (const reexport of result.reexports) {
|
|
260
|
+
if (reexport.startsWith('node:') || builtinModules.includes(reexport)) {
|
|
261
|
+
for (const each of getExportsForNodeBuiltIn(reexport)) {
|
|
235
262
|
full.add(each)
|
|
236
263
|
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
re = './'
|
|
240
|
-
}
|
|
264
|
+
continue
|
|
265
|
+
}
|
|
241
266
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
267
|
+
// Resolve each re-export relative to the current module. Keep the
|
|
268
|
+
// resolution scoped to this iteration: a `#`-import rewrites both the
|
|
269
|
+
// base URL and the specifier, and that rewrite must not leak into the
|
|
270
|
+
// next re-export.
|
|
271
|
+
let reUrl = url
|
|
272
|
+
let reSpecifier = reexport === '.' ? './' : reexport
|
|
273
|
+
|
|
274
|
+
// Entries in the import field should always start with #
|
|
275
|
+
if (reSpecifier.startsWith('#')) {
|
|
276
|
+
const resolved = resolvePackageImports(reSpecifier, url)
|
|
277
|
+
if (!resolved) continue
|
|
278
|
+
;[reUrl, reSpecifier] = resolved
|
|
279
|
+
}
|
|
248
280
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
281
|
+
if (!require) {
|
|
282
|
+
require = createRequire(import.meta.url)
|
|
283
|
+
}
|
|
284
|
+
const newUrl = pathToFileURL(
|
|
285
|
+
require.resolve(reSpecifier, { paths: [dirname(fileURLToPath(reUrl))] })
|
|
286
|
+
).href
|
|
254
287
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
288
|
+
if (newUrl.endsWith('.node') || newUrl.endsWith('.json')) {
|
|
289
|
+
continue
|
|
290
|
+
}
|
|
258
291
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
}
|
|
292
|
+
for (const each of yield * getExports(newUrl, context)) {
|
|
293
|
+
full.add(each)
|
|
262
294
|
}
|
|
263
|
-
}
|
|
295
|
+
}
|
|
264
296
|
|
|
265
297
|
// added in node 23 as alias for default in cjs modules
|
|
266
298
|
if (full.has('default') && hasModuleExportsCJSDefault) {
|
|
@@ -276,26 +308,30 @@ async function getCjsExports (url, context, parentLoad, source) {
|
|
|
276
308
|
}
|
|
277
309
|
|
|
278
310
|
/**
|
|
279
|
-
* Inspects a module for its type (commonjs or module),
|
|
280
|
-
*
|
|
281
|
-
*
|
|
311
|
+
* Inspects a module for its type (commonjs or module), obtains the source code
|
|
312
|
+
* for said module from the loader API, and parses the result for the entities
|
|
313
|
+
* exported from that module.
|
|
314
|
+
*
|
|
315
|
+
* This is a "sans-io" generator: instead of calling the loader's `load` hook
|
|
316
|
+
* directly, it `yield`s `[LOAD, url, context]` and is driven by either
|
|
317
|
+
* {@link driveSync} or {@link driveAsync} (see `lib/io.mjs`). The same body
|
|
318
|
+
* therefore serves both the off-thread loader and `module.registerHooks`.
|
|
282
319
|
*
|
|
283
|
-
* @param {string} url A file URL string pointing to the module that
|
|
284
|
-
*
|
|
285
|
-
* @param {object} context Context object as provided by the `load`
|
|
286
|
-
*
|
|
287
|
-
* @param {Function} parentLoad Next hook function in the loaders API
|
|
288
|
-
* hook chain.
|
|
320
|
+
* @param {string} url A file URL string pointing to the module that we should
|
|
321
|
+
* get the exports of.
|
|
322
|
+
* @param {object} context Context object as provided by the `load` hook from
|
|
323
|
+
* the loaders API.
|
|
289
324
|
*
|
|
290
|
-
* @returns {
|
|
325
|
+
* @returns {Generator<Array, Set<string>>} A generator that yields I/O
|
|
326
|
+
* operations and ultimately returns the identifiers exported by the module.
|
|
291
327
|
* Please see {@link getEsmExports} for caveats on special identifiers that may
|
|
292
328
|
* be included in the result set.
|
|
293
329
|
*/
|
|
294
|
-
export
|
|
295
|
-
// `
|
|
296
|
-
//
|
|
297
|
-
//
|
|
298
|
-
const parentCtx =
|
|
330
|
+
export function * getExports (url, context) {
|
|
331
|
+
// `[LOAD, ...]` gives us the possibility of getting the source from an
|
|
332
|
+
// upstream loader. This doesn't always work though, so later on we fall back
|
|
333
|
+
// to reading it from disk.
|
|
334
|
+
const parentCtx = yield [LOAD, url, context]
|
|
299
335
|
let source = parentCtx.source
|
|
300
336
|
const format = parentCtx.format
|
|
301
337
|
|
|
@@ -331,7 +367,7 @@ export async function getExports (url, context, parentLoad) {
|
|
|
331
367
|
}
|
|
332
368
|
|
|
333
369
|
if (format === 'commonjs') {
|
|
334
|
-
return
|
|
370
|
+
return yield * getCjsExports(url, context, source)
|
|
335
371
|
}
|
|
336
372
|
|
|
337
373
|
// At this point our `format` is either undefined or not known by us. Fall
|
|
@@ -344,7 +380,7 @@ export async function getExports (url, context, parentLoad) {
|
|
|
344
380
|
if (!hasEsmSyntax(source)) {
|
|
345
381
|
// It might be possible to get here if the format
|
|
346
382
|
// isn't set at first and yet we have an ESM module with no exports.
|
|
347
|
-
return
|
|
383
|
+
return yield * getCjsExports(url, context, source)
|
|
348
384
|
}
|
|
349
385
|
}
|
|
350
386
|
return esmExports
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
// The export-collection logic (resolving star re-exports, reading source,
|
|
4
|
+
// parsing exports) is identical whether `import-in-the-middle` runs as an
|
|
5
|
+
// off-thread loader (`module.register`, asynchronous `nextResolve`/`nextLoad`)
|
|
6
|
+
// or as an in-thread synchronous loader (`module.registerHooks`). To keep a
|
|
7
|
+
// single implementation of that logic — instead of two copies that drift — it
|
|
8
|
+
// is written as "sans-io" generators that `yield` the I/O they need and let a
|
|
9
|
+
// driver fulfil it. The async driver awaits; the sync driver calls straight
|
|
10
|
+
// through. Everything between the yields is shared.
|
|
11
|
+
|
|
12
|
+
// Operation kinds a loader generator may yield. Each is `[KIND, ...args]`.
|
|
13
|
+
export const LOAD = 0 // [LOAD, url, context] -> resolves to { source, format }
|
|
14
|
+
export const RESOLVE = 1 // [RESOLVE, specifier, context] -> resolves to { url, format }
|
|
15
|
+
|
|
16
|
+
function runOp (op, io) {
|
|
17
|
+
if (op[0] === RESOLVE) {
|
|
18
|
+
return io.resolve(op[1], op[2])
|
|
19
|
+
}
|
|
20
|
+
return io.load(op[1], op[2])
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Drives a loader generator to completion, fulfilling each yielded I/O
|
|
25
|
+
* operation synchronously. Used with `module.registerHooks`, whose
|
|
26
|
+
* `nextResolve`/`nextLoad` return their result directly.
|
|
27
|
+
*
|
|
28
|
+
* Errors from I/O are thrown back into the generator (via `gen.throw`) so its
|
|
29
|
+
* `try`/`finally` blocks run exactly as they would for an `await` rejection.
|
|
30
|
+
*
|
|
31
|
+
* @template T
|
|
32
|
+
* @param {Generator<Array, T>} gen
|
|
33
|
+
* @param {{ load: Function, resolve?: Function }} io
|
|
34
|
+
* @returns {T}
|
|
35
|
+
*/
|
|
36
|
+
export function driveSync (gen, io) {
|
|
37
|
+
let next = gen.next()
|
|
38
|
+
while (next.done === false) {
|
|
39
|
+
let result
|
|
40
|
+
let error
|
|
41
|
+
let threw = false
|
|
42
|
+
try {
|
|
43
|
+
result = runOp(next.value, io)
|
|
44
|
+
} catch (err) {
|
|
45
|
+
threw = true
|
|
46
|
+
error = err
|
|
47
|
+
}
|
|
48
|
+
next = threw ? gen.throw(error) : gen.next(result)
|
|
49
|
+
}
|
|
50
|
+
return next.value
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Drives a loader generator to completion, awaiting each yielded I/O
|
|
55
|
+
* operation. Used with the off-thread `module.register` loader, whose
|
|
56
|
+
* `nextResolve`/`nextLoad` are asynchronous.
|
|
57
|
+
*
|
|
58
|
+
* @template T
|
|
59
|
+
* @param {Generator<Array, T>} gen
|
|
60
|
+
* @param {{ load: Function, resolve?: Function }} io
|
|
61
|
+
* @returns {Promise<T>}
|
|
62
|
+
*/
|
|
63
|
+
export async function driveAsync (gen, io) {
|
|
64
|
+
let next = gen.next()
|
|
65
|
+
while (next.done === false) {
|
|
66
|
+
let result
|
|
67
|
+
let error
|
|
68
|
+
let threw = false
|
|
69
|
+
try {
|
|
70
|
+
result = await runOp(next.value, io)
|
|
71
|
+
} catch (err) {
|
|
72
|
+
threw = true
|
|
73
|
+
error = err
|
|
74
|
+
}
|
|
75
|
+
next = threw ? gen.throw(error) : gen.next(result)
|
|
76
|
+
}
|
|
77
|
+
return next.value
|
|
78
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for {@link register}. `include`/`exclude` accept bare specifiers,
|
|
3
|
+
* `file:` URLs or regular expressions, matched against the module being
|
|
4
|
+
* resolved.
|
|
5
|
+
*/
|
|
6
|
+
export type RegisterHooksOptions = {
|
|
7
|
+
include?: Array<string | RegExp>
|
|
8
|
+
exclude?: Array<string | RegExp>
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Registers `import-in-the-middle` as a *synchronous*, in-thread loader hook via
|
|
13
|
+
* [`module.registerHooks()`](https://nodejs.org/api/module.html#moduleregisterhooksoptions).
|
|
14
|
+
*
|
|
15
|
+
* Unlike `module.register('import-in-the-middle/hook.mjs', ...)`, which runs the
|
|
16
|
+
* loader on a separate thread and pays an IPC round-trip per resolved module,
|
|
17
|
+
* synchronous hooks run on the application thread, so `Hook()` registrations are
|
|
18
|
+
* visible to the loader directly and no acknowledgement step is required.
|
|
19
|
+
*
|
|
20
|
+
* Requires a Node.js version with `module.registerHooks()` (>= 22.15.0 / >= 24).
|
|
21
|
+
*
|
|
22
|
+
* ```ts
|
|
23
|
+
* import { register } from 'import-in-the-middle/register-hooks.mjs'
|
|
24
|
+
* import { Hook } from 'import-in-the-middle'
|
|
25
|
+
*
|
|
26
|
+
* register({ include: ['package-i-want-to-include'] })
|
|
27
|
+
*
|
|
28
|
+
* Hook(['package-i-want-to-include'], (exported, name, baseDir) => {
|
|
29
|
+
* // Instrument the module
|
|
30
|
+
* })
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @throws If `module.registerHooks()` is unavailable in the running Node.js.
|
|
34
|
+
*/
|
|
35
|
+
export declare function register(options?: RegisterHooksOptions): void
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import * as module from 'module'
|
|
2
|
+
import { createHook, supportsSyncHooks } from './create-hook.mjs'
|
|
3
|
+
|
|
4
|
+
export { supportsSyncHooks }
|
|
5
|
+
|
|
6
|
+
const hook = createHook(import.meta)
|
|
7
|
+
|
|
8
|
+
let registered = false
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Registers `import-in-the-middle` as a *synchronous*, in-thread loader hook via
|
|
12
|
+
* [`module.registerHooks()`](https://nodejs.org/api/module.html#moduleregisterhooksoptions).
|
|
13
|
+
*
|
|
14
|
+
* Unlike `module.register('import-in-the-middle/hook.mjs', ...)`, which runs the
|
|
15
|
+
* loader on a separate thread and pays an IPC round-trip per resolved module,
|
|
16
|
+
* synchronous hooks run in the application thread. There is no message channel
|
|
17
|
+
* to bridge, so `Hook()` registrations from the main `import-in-the-middle`
|
|
18
|
+
* entry point are visible to the loader directly and no acknowledgement step is
|
|
19
|
+
* required.
|
|
20
|
+
*
|
|
21
|
+
* Requires a Node.js version whose `module.registerHooks` accepts the nullish
|
|
22
|
+
* CommonJS source the loader relies on: >= 22.22.3, >= 24.11.1, >= 25.1.0, or
|
|
23
|
+
* >= 26.0.0 (see `supportsSyncHooks`). Use that predicate to fall back to the
|
|
24
|
+
* asynchronous `module.register` loader on unsupported versions.
|
|
25
|
+
*
|
|
26
|
+
* ```js
|
|
27
|
+
* import { register } from 'import-in-the-middle/register-hooks.mjs'
|
|
28
|
+
* import { Hook } from 'import-in-the-middle'
|
|
29
|
+
*
|
|
30
|
+
* register({ include: ['package-i-want-to-include'] })
|
|
31
|
+
*
|
|
32
|
+
* Hook(['package-i-want-to-include'], (exported, name, baseDir) => {
|
|
33
|
+
* // Instrument the module
|
|
34
|
+
* })
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @param {object} [options]
|
|
38
|
+
* @param {Array<string|RegExp>} [options.include] Only intercept these modules.
|
|
39
|
+
* @param {Array<string|RegExp>} [options.exclude] Never intercept these modules.
|
|
40
|
+
* @returns {void}
|
|
41
|
+
*/
|
|
42
|
+
export function register (options) {
|
|
43
|
+
if (!supportsSyncHooks()) {
|
|
44
|
+
throw new Error(
|
|
45
|
+
"'import-in-the-middle' synchronous hooks require a Node.js version whose " +
|
|
46
|
+
'module.registerHooks accepts nullish CommonJS source ' +
|
|
47
|
+
'(>= 22.22.3, >= 24.11.1, >= 25.1.0, or >= 26.0.0); ' +
|
|
48
|
+
'see https://github.com/nodejs/node/pull/59929'
|
|
49
|
+
)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (registered) {
|
|
53
|
+
process.emitWarning("'import-in-the-middle' synchronous hooks have already been registered")
|
|
54
|
+
return
|
|
55
|
+
}
|
|
56
|
+
registered = true
|
|
57
|
+
|
|
58
|
+
if (options) {
|
|
59
|
+
hook.applyOptions(options)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
module.registerHooks({ resolve: hook.resolveSync, load: hook.loadSync })
|
|
63
|
+
}
|
|
@@ -22,8 +22,6 @@ declare namespace Agent {
|
|
|
22
22
|
export interface Options extends Pool.Options {
|
|
23
23
|
/** Default: `(origin, opts) => new Pool(origin, opts)`. */
|
|
24
24
|
factory?(origin: string | URL, opts: Object): Dispatcher;
|
|
25
|
-
|
|
26
|
-
interceptors?: { Agent?: readonly Dispatcher.DispatchInterceptor[] } & Pool.Options['interceptors']
|
|
27
25
|
maxOrigins?: number
|
|
28
26
|
}
|
|
29
27
|
|
|
@@ -3,7 +3,7 @@ import Dispatcher from './dispatcher'
|
|
|
3
3
|
import buildConnector from './connector'
|
|
4
4
|
import TClientStats from './client-stats'
|
|
5
5
|
|
|
6
|
-
type ClientConnectOptions = Omit<Dispatcher.ConnectOptions
|
|
6
|
+
type ClientConnectOptions<TOpaque = null> = Omit<Dispatcher.ConnectOptions<TOpaque>, 'origin'>
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* A basic HTTP/1.1 client, mapped on top a single TCP/TLS connection. Pipelining is disabled by default.
|
|
@@ -20,22 +20,17 @@ export class Client extends Dispatcher {
|
|
|
20
20
|
readonly stats: TClientStats
|
|
21
21
|
|
|
22
22
|
// Override dispatcher APIs.
|
|
23
|
-
override connect (
|
|
24
|
-
options: ClientConnectOptions
|
|
25
|
-
): Promise<Dispatcher.ConnectData
|
|
26
|
-
override connect (
|
|
27
|
-
options: ClientConnectOptions
|
|
28
|
-
callback: (err: Error | null, data: Dispatcher.ConnectData) => void
|
|
23
|
+
override connect<TOpaque = null> (
|
|
24
|
+
options: ClientConnectOptions<TOpaque>
|
|
25
|
+
): Promise<Dispatcher.ConnectData<TOpaque>>
|
|
26
|
+
override connect<TOpaque = null> (
|
|
27
|
+
options: ClientConnectOptions<TOpaque>,
|
|
28
|
+
callback: (err: Error | null, data: Dispatcher.ConnectData<TOpaque>) => void
|
|
29
29
|
): void
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
export declare namespace Client {
|
|
33
|
-
export interface OptionsInterceptors {
|
|
34
|
-
Client: readonly Dispatcher.DispatchInterceptor[];
|
|
35
|
-
}
|
|
36
33
|
export interface Options {
|
|
37
|
-
/** TODO */
|
|
38
|
-
interceptors?: OptionsInterceptors;
|
|
39
34
|
/** The maximum length of request headers in bytes. Default: Node.js' `--max-http-header-size` or `16384` (16KiB). */
|
|
40
35
|
maxHeaderSize?: number;
|
|
41
36
|
/** The amount of time, in milliseconds, the parser will wait to receive the complete HTTP headers (Node 14 and above only). Default: `300e3` milliseconds (300s). */
|
|
@@ -44,7 +39,7 @@ export declare namespace Client {
|
|
|
44
39
|
socketTimeout?: never;
|
|
45
40
|
/** @deprecated unsupported requestTimeout, use headersTimeout & bodyTimeout instead */
|
|
46
41
|
requestTimeout?: never;
|
|
47
|
-
/**
|
|
42
|
+
/** The timeout for establishing a socket connection, in milliseconds. Use `0` to disable it entirely. Default: `10e3` milliseconds (10s). */
|
|
48
43
|
connectTimeout?: number;
|
|
49
44
|
/** The timeout after which a request will time out, in milliseconds. Monitors time between receiving body data. Use `0` to disable it entirely. Default: `300e3` milliseconds (300s). */
|
|
50
45
|
bodyTimeout?: number;
|
|
@@ -60,7 +55,7 @@ export declare namespace Client {
|
|
|
60
55
|
keepAliveMaxTimeout?: number;
|
|
61
56
|
/** A number of milliseconds subtracted from server *keep-alive* hints when overriding `idleTimeout` to account for timing inaccuracies caused by e.g. transport latency. Default: `1e3` milliseconds (1s). */
|
|
62
57
|
keepAliveTimeoutThreshold?: number;
|
|
63
|
-
/**
|
|
58
|
+
/** An IPC endpoint, either a Unix domain socket or Windows named pipe. Default: `null`. */
|
|
64
59
|
socketPath?: string;
|
|
65
60
|
/** The amount of concurrent requests to be sent over the single TCP/TLS connection according to [RFC7230](https://tools.ietf.org/html/rfc7230#section-6.3.2). Default: `1`. */
|
|
66
61
|
pipelining?: number;
|
|
@@ -68,23 +63,25 @@ export declare namespace Client {
|
|
|
68
63
|
tls?: never;
|
|
69
64
|
/** If `true`, an error is thrown when the request content-length header doesn't match the length of the request body. Default: `true`. */
|
|
70
65
|
strictContentLength?: boolean;
|
|
71
|
-
/**
|
|
66
|
+
/** Maximum number of TLS cached sessions used by the built-in connector. Use `0` to disable TLS session caching. Default: `100`. */
|
|
72
67
|
maxCachedSessions?: number;
|
|
73
|
-
/**
|
|
68
|
+
/** Connector options passed to `buildConnector`, or a custom connector function. Default: `null`. */
|
|
74
69
|
connect?: Partial<buildConnector.BuildOptions> | buildConnector.connector;
|
|
75
|
-
/**
|
|
70
|
+
/** The maximum number of requests to send over a single connection before it is reset. Use `0` to disable this limit. Default: `null`. */
|
|
76
71
|
maxRequestsPerClient?: number;
|
|
77
|
-
/**
|
|
72
|
+
/** Local IP address the socket should connect from. */
|
|
78
73
|
localAddress?: string;
|
|
79
74
|
/** Max response body size in bytes, -1 is disabled */
|
|
80
75
|
maxResponseSize?: number;
|
|
76
|
+
/** WebSocket-specific options */
|
|
77
|
+
webSocket?: Client.WebSocketOptions;
|
|
81
78
|
/** Enables a family autodetection algorithm that loosely implements section 5 of RFC 8305. */
|
|
82
79
|
autoSelectFamily?: boolean;
|
|
83
80
|
/** The amount of time in milliseconds to wait for a connection attempt to finish before trying the next address when using the `autoSelectFamily` option. */
|
|
84
81
|
autoSelectFamilyAttemptTimeout?: number;
|
|
85
82
|
/**
|
|
86
83
|
* @description Enables support for H2 if the server has assigned bigger priority to it through ALPN negotiation.
|
|
87
|
-
* @default
|
|
84
|
+
* @default true
|
|
88
85
|
*/
|
|
89
86
|
allowH2?: boolean;
|
|
90
87
|
/**
|
|
@@ -118,6 +115,15 @@ export declare namespace Client {
|
|
|
118
115
|
bytesWritten?: number
|
|
119
116
|
bytesRead?: number
|
|
120
117
|
}
|
|
118
|
+
export interface WebSocketOptions {
|
|
119
|
+
/**
|
|
120
|
+
* Maximum allowed payload size in bytes for WebSocket messages.
|
|
121
|
+
* Applied to uncompressed messages, compressed frame payloads, and decompressed (permessage-deflate) messages.
|
|
122
|
+
* Set to 0 to disable the limit.
|
|
123
|
+
* @default 134217728 (128 MB)
|
|
124
|
+
*/
|
|
125
|
+
maxPayloadSize?: number;
|
|
126
|
+
}
|
|
121
127
|
}
|
|
122
128
|
|
|
123
129
|
export default Client
|
|
@@ -2,17 +2,15 @@ import { URL } from 'node:url'
|
|
|
2
2
|
import { Duplex, Readable, Writable } from 'node:stream'
|
|
3
3
|
import { EventEmitter } from 'node:events'
|
|
4
4
|
import { Blob } from 'node:buffer'
|
|
5
|
-
import { IncomingHttpHeaders } from './header'
|
|
5
|
+
import { IncomingHttpHeaders, OutgoingHttpHeaders } from './header'
|
|
6
6
|
import BodyReadable from './readable'
|
|
7
7
|
import { FormData } from './formdata'
|
|
8
8
|
import Errors from './errors'
|
|
9
9
|
import { Autocomplete } from './utility'
|
|
10
10
|
|
|
11
|
-
type AbortSignal = unknown
|
|
12
|
-
|
|
13
11
|
export default Dispatcher
|
|
14
12
|
|
|
15
|
-
export type UndiciHeaders =
|
|
13
|
+
export type UndiciHeaders = OutgoingHttpHeaders | string[] | Iterable<[string, string | string[] | undefined]> | null
|
|
16
14
|
|
|
17
15
|
/** Dispatcher is the core API used to dispatch requests. */
|
|
18
16
|
declare class Dispatcher extends EventEmitter {
|
|
@@ -123,8 +121,6 @@ declare namespace Dispatcher {
|
|
|
123
121
|
bodyTimeout?: number | null;
|
|
124
122
|
/** Whether the request should stablish a keep-alive or not. Default `false` */
|
|
125
123
|
reset?: boolean;
|
|
126
|
-
/** Whether Undici should throw an error upon receiving a 4xx or 5xx response from the server. Defaults to false */
|
|
127
|
-
throwOnError?: boolean;
|
|
128
124
|
/** For H2, it appends the expect: 100-continue header, and halts the request body until a 100-continue is received from the remote server */
|
|
129
125
|
expectContinue?: boolean;
|
|
130
126
|
}
|
|
@@ -137,8 +133,6 @@ declare namespace Dispatcher {
|
|
|
137
133
|
signal?: AbortSignal | EventEmitter | null;
|
|
138
134
|
/** This argument parameter is passed through to `ConnectData` */
|
|
139
135
|
opaque?: TOpaque;
|
|
140
|
-
/** Default: false */
|
|
141
|
-
redirectionLimitReached?: boolean;
|
|
142
136
|
/** Default: `null` */
|
|
143
137
|
responseHeaders?: 'raw' | null;
|
|
144
138
|
}
|
|
@@ -147,8 +141,6 @@ declare namespace Dispatcher {
|
|
|
147
141
|
opaque?: TOpaque;
|
|
148
142
|
/** Default: `null` */
|
|
149
143
|
signal?: AbortSignal | EventEmitter | null;
|
|
150
|
-
/** Default: false */
|
|
151
|
-
redirectionLimitReached?: boolean;
|
|
152
144
|
/** Default: `null` */
|
|
153
145
|
onInfo?: (info: { statusCode: number, headers: Record<string, string | string[]> }) => void;
|
|
154
146
|
/** Default: `null` */
|
|
@@ -170,8 +162,6 @@ declare namespace Dispatcher {
|
|
|
170
162
|
protocol?: string;
|
|
171
163
|
/** Default: `null` */
|
|
172
164
|
signal?: AbortSignal | EventEmitter | null;
|
|
173
|
-
/** Default: false */
|
|
174
|
-
redirectionLimitReached?: boolean;
|
|
175
165
|
/** Default: `null` */
|
|
176
166
|
responseHeaders?: 'raw' | null;
|
|
177
167
|
}
|
|
@@ -218,6 +208,8 @@ declare namespace Dispatcher {
|
|
|
218
208
|
get aborted(): boolean
|
|
219
209
|
get paused(): boolean
|
|
220
210
|
get reason(): Error | null
|
|
211
|
+
rawHeaders?: Buffer[] | string[] | IncomingHttpHeaders | null
|
|
212
|
+
rawTrailers?: Buffer[] | string[] | IncomingHttpHeaders | null
|
|
221
213
|
abort(reason: Error): void
|
|
222
214
|
pause(): void
|
|
223
215
|
resume(): void
|
|
@@ -231,30 +223,12 @@ declare namespace Dispatcher {
|
|
|
231
223
|
onResponseEnd?(controller: DispatchController, trailers: IncomingHttpHeaders): void;
|
|
232
224
|
onResponseError?(controller: DispatchController, error: Error): void;
|
|
233
225
|
|
|
234
|
-
/** Invoked before request is dispatched on socket. May be invoked multiple times when a request is retried when the request at the head of the pipeline fails. */
|
|
235
|
-
/** @deprecated */
|
|
236
|
-
onConnect?(abort: (err?: Error) => void): void;
|
|
237
|
-
/** Invoked when an error has occurred. */
|
|
238
|
-
/** @deprecated */
|
|
239
|
-
onError?(err: Error): void;
|
|
240
|
-
/** Invoked when request is upgraded either due to a `Upgrade` header or `CONNECT` method. */
|
|
241
|
-
/** @deprecated */
|
|
242
|
-
onUpgrade?(statusCode: number, headers: Buffer[] | string[] | null, socket: Duplex): void;
|
|
243
226
|
/** Invoked when response is received, before headers have been read. **/
|
|
244
|
-
/** @deprecated */
|
|
245
227
|
onResponseStarted?(): void;
|
|
246
|
-
/** Invoked when statusCode and headers have been received. May be invoked multiple times due to 1xx informational headers. */
|
|
247
|
-
/** @deprecated */
|
|
248
|
-
onHeaders?(statusCode: number, headers: Buffer[], resume: () => void, statusText: string): boolean;
|
|
249
|
-
/** Invoked when response payload data is received. */
|
|
250
|
-
/** @deprecated */
|
|
251
|
-
onData?(chunk: Buffer): boolean;
|
|
252
|
-
/** Invoked when response payload and trailers have been received and the request has completed. */
|
|
253
|
-
/** @deprecated */
|
|
254
|
-
onComplete?(trailers: string[] | null): void;
|
|
255
228
|
/** Invoked when a body chunk is sent to the server. May be invoked multiple times for chunked requests */
|
|
256
|
-
|
|
257
|
-
|
|
229
|
+
onBodySent?(chunk: Buffer): void;
|
|
230
|
+
/** Invoked after the request body is fully sent. */
|
|
231
|
+
onRequestSent?(): void;
|
|
258
232
|
}
|
|
259
233
|
export type PipelineHandler<TOpaque = null> = (data: PipelineHandlerData<TOpaque>) => Readable
|
|
260
234
|
export type HttpMethod = Autocomplete<'GET' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE' | 'PATCH'>
|