@akai-workflow-builder/cli-sdk 0.20.0 → 0.20.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.
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,13 @@ All notable changes to `@akai-workflow-builder/cli-sdk` are documented here.
|
|
|
4
4
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
|
6
6
|
|
|
7
|
+
## [0.20.1](https://github.com/akai-workflow-builder/akai-cli-sdk/compare/cli-sdk-v0.20.0...cli-sdk-v0.20.1) (2026-12-02)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Bug Fixes
|
|
11
|
+
|
|
12
|
+
* **ctx:** connect ctx.fetch only to the addresses its egress check vetted (AKAI-4323) ([2331639](https://github.com/akai-workflow-builder/akai-cli-sdk/commit/23316395679c35421d2f64fd5df84569a5239e4a))
|
|
13
|
+
|
|
7
14
|
## [0.20.0](https://github.com/akai-workflow-builder/akai-cli-sdk/compare/cli-sdk-v0.19.0...cli-sdk-v0.20.0) (2026-11-26)
|
|
8
15
|
|
|
9
16
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"safe-fetch.d.ts","sourceRoot":"","sources":["../../src/ctx/safe-fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,KAAK,aAAa,EAAE,MAAM,UAAU,CAAC;AAE/D,OAAO,EAAkB,KAAK,cAAc,EAAE,MAAM,UAAU,CAAC;AAK/D,OAAO,EAAuB,KAAK,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAC9E,OAAO,EAKL,KAAK,0BAA0B,EAC/B,KAAK,gBAAgB,EACtB,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"safe-fetch.d.ts","sourceRoot":"","sources":["../../src/ctx/safe-fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,KAAK,aAAa,EAAE,MAAM,UAAU,CAAC;AAE/D,OAAO,EAAkB,KAAK,cAAc,EAAE,MAAM,UAAU,CAAC;AAK/D,OAAO,EAAuB,KAAK,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAC9E,OAAO,EAKL,KAAK,0BAA0B,EAC/B,KAAK,gBAAgB,EACtB,MAAM,qBAAqB,CAAC;AAI7B;;;;;;;;;;GAUG;AACH,eAAO,MAAM,0BAA0B,QAAkB,CAAC;AAE1D;;;;;;;;GAQG;AACH,eAAO,MAAM,iCAAiC,QAAoB,CAAC;AAEnE;;;;;GAKG;AACH,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,UAAU,CAAC,EAAE,kBAAkB,CAAC;IACzC;;;;OAIG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B;;;;OAIG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACvC,kEAAkE;IAClE,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IACnC;;;;;;;;OAQG;IACH,QAAQ,CAAC,aAAa,CAAC,EAAE,SAAS,gBAAgB,EAAE,CAAC;IACrD,sFAAsF;IACtF,QAAQ,CAAC,sBAAsB,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAC5D;;;;OAIG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC,OAAO,EAAE,aAAa,KAAK,IAAI,CAAC;CAC7D;AAED,MAAM,MAAM,SAAS,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;AA6C/E;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CA0B/C;AASD,2GAA2G;AAC3G,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,GAAG,EAAE,0BAA0B,CAAC;IACzC,+GAA+G;IAC/G,QAAQ,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,CAAC;CACvC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,SAAS,0BAA0B,EAAE,EAC3C,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,GAAG,EACR,SAAS,EAAE,SAAS,MAAM,EAAE,GAC3B,eAAe,GAAG,IAAI,CAsBxB;AAED,6EAA6E;AAC7E,KAAK,YAAY,GAAG,OAAO,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAElD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,YAAY,GAAG,SAAS,GAAG,YAAY,CAEjF;AASD,wBAAsB,gBAAgB,CACpC,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,WAAW,GAAG,SAAS,GAC9B,OAAO,CAAC,aAAa,EAAE,CAAC,CAgB1B;AAkBD,wBAAgB,eAAe,CAAC,OAAO,EAAE,gBAAgB,GAAG,SAAS,CAmKpE;AAmED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,GAAG,cAAc,CASzE"}
|
package/dist/ctx/safe-fetch.js
CHANGED
|
@@ -8,6 +8,7 @@ import { blockedDomainOf } from './blocked-domains.js';
|
|
|
8
8
|
import { reportEgressRefusal } from './egress-refusal.js';
|
|
9
9
|
import { canonicalIp, cidrContains, isForbiddenPinAddress, normalizePrivateEgress, } from './private-egress.js';
|
|
10
10
|
import { ensureTrustedCa } from './trusted-ca.js';
|
|
11
|
+
import { nodeEnvProxyEnabled, rememberVetted, vettedDispatcher } from './vetted-dispatcher.js';
|
|
11
12
|
/**
|
|
12
13
|
* Default per-response byte cap for JSON/text `ctx.fetch` calls (override via
|
|
13
14
|
* {@link SafeFetchBinding.maxResponseBytes}). Grounded in prod trace data
|
|
@@ -334,23 +335,42 @@ export function createSafeFetch(binding) {
|
|
|
334
335
|
// through to plain fetch: there is no TLS handshake to present a cert on.
|
|
335
336
|
//
|
|
336
337
|
// A pinned private-egress call also rides `node:https`, for a different
|
|
337
|
-
// reason:
|
|
338
|
-
//
|
|
339
|
-
// cannot take a per-connection CA. See pinnedHttpsFetch.
|
|
338
|
+
// reason: it needs a per-connection CA and a forced `Host`, which global
|
|
339
|
+
// fetch cannot take. See pinnedHttpsFetch.
|
|
340
340
|
//
|
|
341
341
|
// Extra CAs go into Node's default CA list (extended, never replaced) so
|
|
342
342
|
// every transport below picks them up: global fetch, a host-installed
|
|
343
343
|
// global dispatcher (e.g. a proxy), and the node:https mTLS path.
|
|
344
344
|
if (trustedCa !== undefined && u.protocol === 'https:')
|
|
345
345
|
ensureTrustedCa(trustedCa, { cliId, toolName });
|
|
346
|
-
|
|
347
|
-
|
|
346
|
+
// Every other call connects only to the addresses checked above, never to a
|
|
347
|
+
// second DNS answer (DNS rebinding): global fetch through a dispatcher whose
|
|
348
|
+
// lookup answers with them, the mutual-TLS path through the same lookup it
|
|
349
|
+
// gives a pinned call. Development skips this, as it skips the check. A
|
|
350
|
+
// transport the host installed (a proxy) is left alone: it dials, not us.
|
|
351
|
+
// See vetted-dispatcher.ts.
|
|
352
|
+
const checked = isDev ? null : addresses.map((entry) => entry.address);
|
|
353
|
+
let response;
|
|
354
|
+
if (pinned !== null) {
|
|
355
|
+
response = await pinnedHttpsFetch(u, sanitized, {
|
|
348
356
|
...(clientCert !== undefined ? { identity: clientCert } : {}),
|
|
349
357
|
pin: { addresses: pinned.addresses, ...(pinned.pin.caPem !== undefined ? { caPem: pinned.pin.caPem } : {}) },
|
|
350
|
-
})
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
else if (clientCert !== undefined && u.protocol === 'https:') {
|
|
361
|
+
response = await pinnedHttpsFetch(u, sanitized, {
|
|
362
|
+
identity: clientCert,
|
|
363
|
+
...(checked !== null && checked.length > 0 && !nodeEnvProxyEnabled() ? { connectTo: checked } : {}),
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
else {
|
|
367
|
+
const dispatcher = checked !== null && checked.length > 0 ? await vettedDispatcher() : null;
|
|
368
|
+
if (dispatcher !== null)
|
|
369
|
+
rememberVetted(u.hostname, checked);
|
|
370
|
+
// `dispatcher` is an undici fetch option lib.dom's RequestInit does not name, and the undici
|
|
371
|
+
// package's Dispatcher type is a separate declaration from the one @types/node bundles.
|
|
372
|
+
response = await fetch(url, dispatcher !== null ? { ...sanitized, dispatcher } : sanitized);
|
|
373
|
+
}
|
|
354
374
|
return capResponseBody(response, maxBytes, { hostname: u.hostname, cliId, toolName });
|
|
355
375
|
};
|
|
356
376
|
}
|
|
@@ -438,7 +458,7 @@ export function pinnedLookup(addresses) {
|
|
|
438
458
|
* - `agent: false` opens a fresh connection through that `lookup` instead of
|
|
439
459
|
* reusing a pooled socket that was dialled under another answer.
|
|
440
460
|
*/
|
|
441
|
-
async function pinnedHttpsFetch(url, init, { identity, pin }) {
|
|
461
|
+
async function pinnedHttpsFetch(url, init, { identity, pin, connectTo }) {
|
|
442
462
|
const headers = init.headers;
|
|
443
463
|
const method = (init.method ?? 'GET').toUpperCase();
|
|
444
464
|
let body;
|
|
@@ -472,7 +492,9 @@ async function pinnedHttpsFetch(url, init, { identity, pin }) {
|
|
|
472
492
|
agent: false,
|
|
473
493
|
...(pin.caPem !== undefined ? { ca: pin.caPem } : {}),
|
|
474
494
|
}
|
|
475
|
-
:
|
|
495
|
+
: connectTo !== undefined
|
|
496
|
+
? { lookup: pinnedLookup(connectTo) }
|
|
497
|
+
: {}),
|
|
476
498
|
...(init.signal ? { signal: init.signal } : {}),
|
|
477
499
|
};
|
|
478
500
|
return new Promise((resolve, reject) => {
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hold a `ctx.fetch` connection to the addresses safe-fetch checked.
|
|
3
|
+
*
|
|
4
|
+
* safe-fetch resolves a host and refuses it when any answer is private. Global
|
|
5
|
+
* fetch then resolves the name again on its own, so a name that answers public
|
|
6
|
+
* for the check and private a moment later (DNS rebinding) would be dialled at
|
|
7
|
+
* the private address. The dispatcher here is an undici Agent whose
|
|
8
|
+
* `connect.lookup` never asks DNS: it answers with the addresses safe-fetch
|
|
9
|
+
* vetted for that hostname, the same idea as the worker's `publicLookup`.
|
|
10
|
+
*
|
|
11
|
+
* What stays as it was:
|
|
12
|
+
* - The URL still names the request. The `Host` header and the TLS servername
|
|
13
|
+
* (and so certificate verification) are the hostname; only the address a
|
|
14
|
+
* socket dials comes from the vetted list.
|
|
15
|
+
* - Pooling. One Agent serves every call, so keep-alive works as it did on the
|
|
16
|
+
* global dispatcher. A pooled socket was dialled at an address vetted for its
|
|
17
|
+
* host, so reusing it reaches nothing new.
|
|
18
|
+
* - A host-installed transport. When the global dispatcher is not a plain
|
|
19
|
+
* direct Agent (the worker's PROXY_LOCATION ProxyAgent, Node's env proxy, a
|
|
20
|
+
* test's MockAgent, anything else) it is left alone: {@link vettedDispatcher}
|
|
21
|
+
* returns null and the call rides global fetch as before. A proxy resolves
|
|
22
|
+
* the name itself; the SDK has no say over which address it dials.
|
|
23
|
+
*
|
|
24
|
+
* undici 8 is loaded by file, not through its index: the index claims Node's
|
|
25
|
+
* global dispatcher when it loads, and this module must not change the
|
|
26
|
+
* transport of any other fetch in the host process. The imports are literal
|
|
27
|
+
* dynamic imports so a bundler inlines them: cli-service's baseline bundle
|
|
28
|
+
* carries this runtime to a directory with no node_modules.
|
|
29
|
+
*/
|
|
30
|
+
import { type LookupFunction } from 'node:net';
|
|
31
|
+
import type { Dispatcher1Wrapper as UndiciDispatcher1Wrapper } from 'undici';
|
|
32
|
+
/** Error code for a connection to a hostname with no vetted addresses on record. */
|
|
33
|
+
export declare const UNVETTED_CODE = "ESAFEFETCHUNVETTED";
|
|
34
|
+
/**
|
|
35
|
+
* Record the addresses safe-fetch checked for `hostname`. The next connection
|
|
36
|
+
* the dispatcher opens to that host dials one of these and nothing else. A
|
|
37
|
+
* later call replaces the entry; every entry ever stored passed the check.
|
|
38
|
+
*/
|
|
39
|
+
export declare function rememberVetted(hostname: string, addresses: readonly string[]): void;
|
|
40
|
+
/**
|
|
41
|
+
* The `connect.lookup` of the dispatcher: answers with the vetted addresses
|
|
42
|
+
* for the hostname, in either shape Node asks for (`all: true` for
|
|
43
|
+
* happy-eyeballs, the default since Node 20, or a single address and family),
|
|
44
|
+
* honouring a requested family. A hostname with nothing on record fails the
|
|
45
|
+
* connection rather than falling back to DNS.
|
|
46
|
+
*/
|
|
47
|
+
export declare const vettedLookup: LookupFunction;
|
|
48
|
+
/**
|
|
49
|
+
* The dispatcher a vetted `ctx.fetch` call passes to global fetch, or null when
|
|
50
|
+
* the host has installed a transport of its own (see the module comment) or
|
|
51
|
+
* undici could not be loaded — the call then goes out exactly as it did before
|
|
52
|
+
* this module existed, rather than failing.
|
|
53
|
+
*
|
|
54
|
+
* It mirrors the transport it stands in for: under Node's default it speaks
|
|
55
|
+
* HTTP/1.1 only, as Node's Agent does; under an undici 8 global Agent it keeps
|
|
56
|
+
* undici 8's defaults, HTTP/2 negotiation included. Node 24's fetch speaks the
|
|
57
|
+
* v1 handler API, so the undici 8 Agent sits behind Dispatcher1Wrapper, as in
|
|
58
|
+
* the worker.
|
|
59
|
+
*/
|
|
60
|
+
export declare function vettedDispatcher(): Promise<UndiciDispatcher1Wrapper | null>;
|
|
61
|
+
/**
|
|
62
|
+
* Whether Node routes `node:https` through an env-configured proxy
|
|
63
|
+
* (`NODE_USE_ENV_PROXY` / `--use-env-proxy`). The mutual-TLS path leaves its
|
|
64
|
+
* lookup alone then: the socket goes to the proxy, not to the vetted address.
|
|
65
|
+
*/
|
|
66
|
+
export declare function nodeEnvProxyEnabled(): boolean;
|
|
67
|
+
/** Test seam: forget every vetted address and dispatcher. */
|
|
68
|
+
export declare function resetVettedDispatchForTests(): void;
|
|
69
|
+
//# sourceMappingURL=vetted-dispatcher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vetted-dispatcher.d.ts","sourceRoot":"","sources":["../../src/ctx/vetted-dispatcher.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAGH,OAAO,EAAU,KAAK,cAAc,EAAE,MAAM,UAAU,CAAC;AACvD,OAAO,KAAK,EAAwB,kBAAkB,IAAI,wBAAwB,EAAE,MAAM,QAAQ,CAAC;AAEnG,oFAAoF;AACpF,eAAO,MAAM,aAAa,uBAAuB,CAAC;AAUlD;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,CAWnF;AAED;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,EAAE,cAmB1B,CAAC;AAgDF;;;;;;;;;;;GAWG;AACH,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,wBAAwB,GAAG,IAAI,CAAC,CAmBjF;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,IAAI,OAAO,CAI7C;AAED,6DAA6D;AAC7D,wBAAgB,2BAA2B,IAAI,IAAI,CAIlD"}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hold a `ctx.fetch` connection to the addresses safe-fetch checked.
|
|
3
|
+
*
|
|
4
|
+
* safe-fetch resolves a host and refuses it when any answer is private. Global
|
|
5
|
+
* fetch then resolves the name again on its own, so a name that answers public
|
|
6
|
+
* for the check and private a moment later (DNS rebinding) would be dialled at
|
|
7
|
+
* the private address. The dispatcher here is an undici Agent whose
|
|
8
|
+
* `connect.lookup` never asks DNS: it answers with the addresses safe-fetch
|
|
9
|
+
* vetted for that hostname, the same idea as the worker's `publicLookup`.
|
|
10
|
+
*
|
|
11
|
+
* What stays as it was:
|
|
12
|
+
* - The URL still names the request. The `Host` header and the TLS servername
|
|
13
|
+
* (and so certificate verification) are the hostname; only the address a
|
|
14
|
+
* socket dials comes from the vetted list.
|
|
15
|
+
* - Pooling. One Agent serves every call, so keep-alive works as it did on the
|
|
16
|
+
* global dispatcher. A pooled socket was dialled at an address vetted for its
|
|
17
|
+
* host, so reusing it reaches nothing new.
|
|
18
|
+
* - A host-installed transport. When the global dispatcher is not a plain
|
|
19
|
+
* direct Agent (the worker's PROXY_LOCATION ProxyAgent, Node's env proxy, a
|
|
20
|
+
* test's MockAgent, anything else) it is left alone: {@link vettedDispatcher}
|
|
21
|
+
* returns null and the call rides global fetch as before. A proxy resolves
|
|
22
|
+
* the name itself; the SDK has no say over which address it dials.
|
|
23
|
+
*
|
|
24
|
+
* undici 8 is loaded by file, not through its index: the index claims Node's
|
|
25
|
+
* global dispatcher when it loads, and this module must not change the
|
|
26
|
+
* transport of any other fetch in the host process. The imports are literal
|
|
27
|
+
* dynamic imports so a bundler inlines them: cli-service's baseline bundle
|
|
28
|
+
* carries this runtime to a directory with no node_modules.
|
|
29
|
+
*/
|
|
30
|
+
import { isIPv6 } from 'node:net';
|
|
31
|
+
/** Error code for a connection to a hostname with no vetted addresses on record. */
|
|
32
|
+
export const UNVETTED_CODE = 'ESAFEFETCHUNVETTED';
|
|
33
|
+
/** Hostnames whose vetted addresses are kept. Far more than any one process dials at once. */
|
|
34
|
+
const MAX_VETTED_HOSTS = 4096;
|
|
35
|
+
const vetted = new Map();
|
|
36
|
+
/** The key a hostname is filed under: URL hostnames are already lowercase; IPv6 brackets and case are dropped. */
|
|
37
|
+
const hostKey = (hostname) => hostname.replace(/^\[|\]$/g, '').toLowerCase();
|
|
38
|
+
/**
|
|
39
|
+
* Record the addresses safe-fetch checked for `hostname`. The next connection
|
|
40
|
+
* the dispatcher opens to that host dials one of these and nothing else. A
|
|
41
|
+
* later call replaces the entry; every entry ever stored passed the check.
|
|
42
|
+
*/
|
|
43
|
+
export function rememberVetted(hostname, addresses) {
|
|
44
|
+
const key = hostKey(hostname);
|
|
45
|
+
vetted.delete(key);
|
|
46
|
+
vetted.set(key, addresses.map((address) => ({ address, family: isIPv6(address) ? 6 : 4 })));
|
|
47
|
+
if (vetted.size > MAX_VETTED_HOSTS) {
|
|
48
|
+
const oldest = vetted.keys().next();
|
|
49
|
+
if (!oldest.done)
|
|
50
|
+
vetted.delete(oldest.value);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The `connect.lookup` of the dispatcher: answers with the vetted addresses
|
|
55
|
+
* for the hostname, in either shape Node asks for (`all: true` for
|
|
56
|
+
* happy-eyeballs, the default since Node 20, or a single address and family),
|
|
57
|
+
* honouring a requested family. A hostname with nothing on record fails the
|
|
58
|
+
* connection rather than falling back to DNS.
|
|
59
|
+
*/
|
|
60
|
+
export const vettedLookup = (hostname, options, callback) => {
|
|
61
|
+
const entries = vetted.get(hostKey(hostname));
|
|
62
|
+
if (entries === undefined || entries.length === 0) {
|
|
63
|
+
const err = Object.assign(new Error(`safe-fetch: no checked address for ${hostname}`), { code: UNVETTED_CODE });
|
|
64
|
+
callback(err, '', 4);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const family = options.family === 4 || options.family === 6 ? options.family : null;
|
|
68
|
+
const answers = family === null ? entries : entries.filter((entry) => entry.family === family);
|
|
69
|
+
if (answers.length === 0) {
|
|
70
|
+
const err = Object.assign(new Error(`safe-fetch: no checked IPv${family} address for ${hostname}`), { code: 'ENOTFOUND' });
|
|
71
|
+
callback(err, '', 4);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (options.all) {
|
|
75
|
+
callback(null, answers.map((entry) => ({ ...entry })));
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
callback(null, answers[0].address, answers[0].family);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
/** What a global dispatcher is, judged by its class name: undici's own classes, unminified in node_modules. */
|
|
82
|
+
const className = (value) => typeof value === 'object' && value !== null ? value.constructor?.name : undefined;
|
|
83
|
+
const LEGACY_GLOBAL_DISPATCHER = Symbol.for('undici.globalDispatcher.1');
|
|
84
|
+
const GLOBAL_DISPATCHER = Symbol.for('undici.globalDispatcher.2');
|
|
85
|
+
/**
|
|
86
|
+
* How Node's global fetch connects right now:
|
|
87
|
+
* - `node`: Node's own default Agent (undici 7, HTTP/1.1 only), or none yet —
|
|
88
|
+
* Node creates that same default on its first fetch;
|
|
89
|
+
* - `undici8`: an undici 8 Agent set through its `setGlobalDispatcher`, which
|
|
90
|
+
* stores the Agent and a Dispatcher1Wrapper for Node's fetch (the worker's
|
|
91
|
+
* `installGlobalDispatcher`);
|
|
92
|
+
* - `other`: anything else — a proxy, a mock, a custom dispatcher.
|
|
93
|
+
*/
|
|
94
|
+
function globalTransport() {
|
|
95
|
+
const store = globalThis;
|
|
96
|
+
const legacy = store[LEGACY_GLOBAL_DISPATCHER];
|
|
97
|
+
if (legacy === undefined)
|
|
98
|
+
return 'node';
|
|
99
|
+
const name = className(legacy);
|
|
100
|
+
if (name === 'Agent')
|
|
101
|
+
return 'node';
|
|
102
|
+
if (name === 'Dispatcher1Wrapper' && className(store[GLOBAL_DISPATCHER]) === 'Agent')
|
|
103
|
+
return 'undici8';
|
|
104
|
+
return 'other';
|
|
105
|
+
}
|
|
106
|
+
/** The undici classes, or null once loading them failed (then calls keep global fetch's own dispatcher). */
|
|
107
|
+
let modules = null;
|
|
108
|
+
function loadUndici() {
|
|
109
|
+
modules ??= Promise.all([
|
|
110
|
+
import('undici/lib/dispatcher/agent.js'),
|
|
111
|
+
import('undici/lib/dispatcher/dispatcher1-wrapper.js'),
|
|
112
|
+
]).then(([agent, wrapper]) => ({ Agent: agent.default, Dispatcher1Wrapper: wrapper.default }), () => null);
|
|
113
|
+
return modules;
|
|
114
|
+
}
|
|
115
|
+
const dispatchers = new Map();
|
|
116
|
+
/**
|
|
117
|
+
* The dispatcher a vetted `ctx.fetch` call passes to global fetch, or null when
|
|
118
|
+
* the host has installed a transport of its own (see the module comment) or
|
|
119
|
+
* undici could not be loaded — the call then goes out exactly as it did before
|
|
120
|
+
* this module existed, rather than failing.
|
|
121
|
+
*
|
|
122
|
+
* It mirrors the transport it stands in for: under Node's default it speaks
|
|
123
|
+
* HTTP/1.1 only, as Node's Agent does; under an undici 8 global Agent it keeps
|
|
124
|
+
* undici 8's defaults, HTTP/2 negotiation included. Node 24's fetch speaks the
|
|
125
|
+
* v1 handler API, so the undici 8 Agent sits behind Dispatcher1Wrapper, as in
|
|
126
|
+
* the worker.
|
|
127
|
+
*/
|
|
128
|
+
export async function vettedDispatcher() {
|
|
129
|
+
const transport = globalTransport();
|
|
130
|
+
if (transport === 'other')
|
|
131
|
+
return null;
|
|
132
|
+
let dispatcher = dispatchers.get(transport);
|
|
133
|
+
if (dispatcher === undefined) {
|
|
134
|
+
const loaded = await loadUndici();
|
|
135
|
+
if (loaded === null)
|
|
136
|
+
return null;
|
|
137
|
+
// Another call may have built it while this one waited on the import.
|
|
138
|
+
const built = dispatchers.get(transport);
|
|
139
|
+
if (built !== undefined)
|
|
140
|
+
return built;
|
|
141
|
+
const { Agent, Dispatcher1Wrapper } = loaded;
|
|
142
|
+
const agent = new Agent({
|
|
143
|
+
connect: { lookup: vettedLookup },
|
|
144
|
+
...(transport === 'node' ? { allowH2: false } : {}),
|
|
145
|
+
});
|
|
146
|
+
dispatcher = new Dispatcher1Wrapper(agent);
|
|
147
|
+
dispatchers.set(transport, dispatcher);
|
|
148
|
+
}
|
|
149
|
+
return dispatcher;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Whether Node routes `node:https` through an env-configured proxy
|
|
153
|
+
* (`NODE_USE_ENV_PROXY` / `--use-env-proxy`). The mutual-TLS path leaves its
|
|
154
|
+
* lookup alone then: the socket goes to the proxy, not to the vetted address.
|
|
155
|
+
*/
|
|
156
|
+
export function nodeEnvProxyEnabled() {
|
|
157
|
+
const flag = process.env.NODE_USE_ENV_PROXY;
|
|
158
|
+
if (flag !== undefined && flag !== '' && flag !== '0' && flag.toLowerCase() !== 'false')
|
|
159
|
+
return true;
|
|
160
|
+
return process.execArgv.includes('--use-env-proxy') || (process.env.NODE_OPTIONS ?? '').includes('--use-env-proxy');
|
|
161
|
+
}
|
|
162
|
+
/** Test seam: forget every vetted address and dispatcher. */
|
|
163
|
+
export function resetVettedDispatchForTests() {
|
|
164
|
+
vetted.clear();
|
|
165
|
+
for (const dispatcher of dispatchers.values())
|
|
166
|
+
dispatcher.close().catch(() => { });
|
|
167
|
+
dispatchers.clear();
|
|
168
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@akai-workflow-builder/cli-sdk",
|
|
3
|
-
"version": "0.20.
|
|
3
|
+
"version": "0.20.1",
|
|
4
4
|
"description": "Authoring SDK for atomic, agent-executable CLIs and tools.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"akai",
|
|
@@ -58,7 +58,8 @@
|
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
60
|
"ssh2": "^1.17.0",
|
|
61
|
-
"tar": "^7.5.22"
|
|
61
|
+
"tar": "^7.5.22",
|
|
62
|
+
"undici": "8.12.2"
|
|
62
63
|
},
|
|
63
64
|
"peerDependencies": {
|
|
64
65
|
"zod": "^4.4.1",
|