@osd-project/osd-cli 0.0.0 → 0.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +585 -4
- package/THIRD_PARTY_NOTICES.md +96 -0
- package/dist/auth-store.d.ts +38 -0
- package/dist/auth-store.js +239 -0
- package/dist/brand-catalog.d.ts +65 -0
- package/dist/brand-catalog.js +175 -0
- package/dist/connect-gate.d.ts +31 -0
- package/dist/connect-gate.js +82 -0
- package/dist/contracts.d.ts +61 -0
- package/dist/contracts.js +145 -0
- package/dist/exit-codes.d.ts +32 -0
- package/dist/exit-codes.js +40 -0
- package/dist/format.d.ts +71 -0
- package/dist/format.js +99 -0
- package/dist/generated/schemas.d.ts +2 -0
- package/dist/generated/schemas.js +1781 -0
- package/dist/guarded-fetch.d.ts +28 -0
- package/dist/guarded-fetch.js +252 -0
- package/dist/help.d.ts +27 -0
- package/dist/help.js +32 -0
- package/dist/http-fetch.d.ts +1 -0
- package/dist/http-fetch.js +17 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +821 -0
- package/dist/logout.d.ts +16 -0
- package/dist/logout.js +82 -0
- package/dist/mcp-auth.d.ts +70 -0
- package/dist/mcp-auth.js +603 -0
- package/dist/mcp-card.d.ts +23 -0
- package/dist/mcp-card.js +18 -0
- package/dist/mcp-client.d.ts +77 -0
- package/dist/mcp-client.js +193 -0
- package/dist/net-guard.d.ts +66 -0
- package/dist/net-guard.js +152 -0
- package/dist/proxy-config.d.ts +51 -0
- package/dist/proxy-config.js +147 -0
- package/dist/request.d.ts +32 -0
- package/dist/request.js +62 -0
- package/dist/resolve-endpoint.d.ts +62 -0
- package/dist/resolve-endpoint.js +172 -0
- package/dist/search.d.ts +39 -0
- package/dist/search.js +69 -0
- package/dist/skill.d.ts +155 -0
- package/dist/skill.js +320 -0
- package/dist/updates.d.ts +101 -0
- package/dist/updates.js +541 -0
- package/dist/verify.d.ts +92 -0
- package/dist/verify.js +379 -0
- package/package.json +51 -3
- package/skill/osd/SKILL.md +400 -0
- package/skill/osd/references/connect-mcp.md +48 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type AddressLookup, type NetPolicy } from "./net-guard.js";
|
|
2
|
+
/** A request refused by the guard (as opposed to a network failure). */
|
|
3
|
+
export declare class GuardError extends Error {
|
|
4
|
+
}
|
|
5
|
+
export interface GuardedFetch {
|
|
6
|
+
fetchFn: typeof fetch;
|
|
7
|
+
/** Closes the dispatcher's keep-alive sockets so a one-shot process can exit. */
|
|
8
|
+
close(): Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Walks an error's cause chain for a guard refusal. Proxied connections wrap
|
|
12
|
+
* socket failures (ProxyConnectionError et al.), so the refusal is not
|
|
13
|
+
* necessarily the immediate cause.
|
|
14
|
+
*/
|
|
15
|
+
export declare function findGuardError(error: unknown): GuardError | null;
|
|
16
|
+
/**
|
|
17
|
+
* Classifies a fetch failure so callers can report WHAT failed:
|
|
18
|
+
* a guard refusal (address blocked by network policy), a TLS failure, a
|
|
19
|
+
* proxy failure, or any other network error. Walks the full cause chain --
|
|
20
|
+
* undici nests connect/socket/proxy errors under "fetch failed".
|
|
21
|
+
*/
|
|
22
|
+
export declare function describeFetchFailure(cause: unknown): string;
|
|
23
|
+
/**
|
|
24
|
+
* `policy.allowLoopback` is a TEST SEAM ONLY (stub servers on 127.0.0.1).
|
|
25
|
+
* `policy.allowPrivate` left unset defaults from the environment (see
|
|
26
|
+
* resolveNetPolicy; private/reserved targets are denied by default).
|
|
27
|
+
*/
|
|
28
|
+
export declare function createGuardedFetch(lookupAddresses?: AddressLookup, policy?: NetPolicy): GuardedFetch;
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* fetch with net-guard's SSRF checks enforced where they can't be bypassed:
|
|
3
|
+
* on the connection itself. The dispatcher validates the exact addresses each
|
|
4
|
+
* socket connects to -- for every request and every redirect hop, hostnames
|
|
5
|
+
* and IP literals alike -- so there is no separate preflight and no gap
|
|
6
|
+
* between checking a name and connecting to it (DNS rebinding).
|
|
7
|
+
*
|
|
8
|
+
* Proxies:
|
|
9
|
+
* - HTTPS targets honor HTTPS_PROXY / HTTP_PROXY and respect NO_PROXY (see
|
|
10
|
+
* proxy-config.ts). Proxy configuration comes only from the process
|
|
11
|
+
* environment, so a configured proxy is the operator's authorization to
|
|
12
|
+
* use it -- private or reserved proxy addresses included (a loopback
|
|
13
|
+
* sidecar, or one that answers for public names at interception
|
|
14
|
+
* addresses, like Muse's). The origin is never resolved locally: the
|
|
15
|
+
* dispatcher CONNECTs through the proxy and runs TLS to the origin
|
|
16
|
+
* end-to-end through the tunnel, so certificate verification and SNI are
|
|
17
|
+
* unchanged. Destination enforcement is then delegated to the proxy.
|
|
18
|
+
* - Direct connections -- including NO_PROXY requests -- keep the CLI's
|
|
19
|
+
* full address guard: private and reserved destinations stay blocked.
|
|
20
|
+
*
|
|
21
|
+
* Redirects:
|
|
22
|
+
* - GET/HEAD without credentials (server cards, OAuth metadata) are followed
|
|
23
|
+
* by undici as usual; each hop still goes through the guarded connection.
|
|
24
|
+
* - Anything else -- a POST, or a request carrying credentials or an MCP
|
|
25
|
+
* session -- only follows same-origin redirects. A cross-origin redirect
|
|
26
|
+
* is refused outright rather than deciding which headers may travel, and
|
|
27
|
+
* same-origin rules out an https -> http downgrade too.
|
|
28
|
+
*/
|
|
29
|
+
import { isIP } from "node:net";
|
|
30
|
+
// undici's OWN fetch: the Agent/dispatcher must come from the same undici
|
|
31
|
+
// copy as the fetch using it -- mixing our Agent with Node's bundled (and
|
|
32
|
+
// version-skewed) global fetch fails at the handler protocol level.
|
|
33
|
+
import { Agent, ProxyAgent, buildConnector, fetch as undiciFetch } from "undici";
|
|
34
|
+
import { isAllowedAddress, isLoopbackAddress, lookupAllAddresses, plaintextTargetError, privateLiteralError, privateResolutionError, resolveNetPolicy, } from "./net-guard.js";
|
|
35
|
+
import { resolveProxyFor } from "./proxy-config.js";
|
|
36
|
+
const MAX_REDIRECTS = 5;
|
|
37
|
+
/** Headers that make a request stateful: credentials and the MCP session id. */
|
|
38
|
+
const CREDENTIAL_HEADERS = ["authorization", "proxy-authorization", "cookie", "mcp-session-id"];
|
|
39
|
+
/** A request refused by the guard (as opposed to a network failure). */
|
|
40
|
+
export class GuardError extends Error {
|
|
41
|
+
}
|
|
42
|
+
function isRedirectStatus(status) {
|
|
43
|
+
return status === 301 || status === 302 || status === 303 || status === 307 || status === 308;
|
|
44
|
+
}
|
|
45
|
+
function messageOf(error) {
|
|
46
|
+
return error instanceof Error ? error.message : String(error);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Walks an error's cause chain for a guard refusal. Proxied connections wrap
|
|
50
|
+
* socket failures (ProxyConnectionError et al.), so the refusal is not
|
|
51
|
+
* necessarily the immediate cause.
|
|
52
|
+
*/
|
|
53
|
+
export function findGuardError(error) {
|
|
54
|
+
let current = error;
|
|
55
|
+
while (current instanceof Error) {
|
|
56
|
+
if (current instanceof GuardError)
|
|
57
|
+
return current;
|
|
58
|
+
current = current.cause;
|
|
59
|
+
}
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
const TLS_ERROR_CODE = /^(ERR_TLS|ERR_SSL|CERT_|DEPTH_ZERO_|SELF_SIGNED|UNABLE_TO_)/;
|
|
63
|
+
const PROXY_FAILURE = /proxy response \(|http tunneling/i;
|
|
64
|
+
/**
|
|
65
|
+
* Classifies a fetch failure so callers can report WHAT failed:
|
|
66
|
+
* a guard refusal (address blocked by network policy), a TLS failure, a
|
|
67
|
+
* proxy failure, or any other network error. Walks the full cause chain --
|
|
68
|
+
* undici nests connect/socket/proxy errors under "fetch failed".
|
|
69
|
+
*/
|
|
70
|
+
export function describeFetchFailure(cause) {
|
|
71
|
+
const refusal = findGuardError(cause);
|
|
72
|
+
if (refusal !== null)
|
|
73
|
+
return `blocked by network policy: ${refusal.message}`;
|
|
74
|
+
const chain = [];
|
|
75
|
+
let current = cause;
|
|
76
|
+
while (current instanceof Error && !chain.includes(current)) {
|
|
77
|
+
chain.push(current);
|
|
78
|
+
current = current.cause;
|
|
79
|
+
}
|
|
80
|
+
const detail = chain.length > 0 ? chain[chain.length - 1].message : String(cause);
|
|
81
|
+
const code = chain.map((error) => error.code).find((value) => typeof value === "string");
|
|
82
|
+
const suffix = code !== undefined && !detail.includes(code) ? ` [${code}]` : "";
|
|
83
|
+
if (code !== undefined && TLS_ERROR_CODE.test(code))
|
|
84
|
+
return `TLS connection failed: ${detail}${suffix}`;
|
|
85
|
+
if (code === "UND_ERR_PRX_CONN" || code === "UND_ERR_PRX_TLS" || PROXY_FAILURE.test(chain.map((error) => error.message).join(" ")))
|
|
86
|
+
return `proxy connection failed: ${detail}${suffix}`;
|
|
87
|
+
return `connection failed: ${detail}${suffix}`;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* `policy.allowLoopback` is a TEST SEAM ONLY (stub servers on 127.0.0.1).
|
|
91
|
+
* `policy.allowPrivate` left unset defaults from the environment (see
|
|
92
|
+
* resolveNetPolicy; private/reserved targets are denied by default).
|
|
93
|
+
*/
|
|
94
|
+
export function createGuardedFetch(lookupAddresses = lookupAllAddresses, policy = {}) {
|
|
95
|
+
const resolvedPolicy = resolveNetPolicy(policy);
|
|
96
|
+
const guardedConnector = (loopbackOnly) => buildConnector({
|
|
97
|
+
lookup: ((hostname, options, callback) => {
|
|
98
|
+
lookupAddresses(hostname).then((addresses) => {
|
|
99
|
+
if (loopbackOnly && addresses.some((address) => !isLoopbackAddress(address))) {
|
|
100
|
+
callback(new GuardError(plaintextTargetError(hostname)), "");
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
// Split-horizon DNS (private network) can answer with private addresses
|
|
104
|
+
// alongside public ones: dial only the allowed subset, and refuse
|
|
105
|
+
// the name outright only when nothing it resolves to is dialable.
|
|
106
|
+
// The private addresses are never connected to either way.
|
|
107
|
+
const allowed = addresses.filter((address) => isAllowedAddress(address, resolvedPolicy));
|
|
108
|
+
if (allowed.length === 0) {
|
|
109
|
+
if (addresses.length === 0) {
|
|
110
|
+
callback(new GuardError(`could not resolve ${hostname}: no addresses`), "");
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
callback(new GuardError(privateResolutionError(hostname, addresses)), "");
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
else if (options.all) {
|
|
117
|
+
callback(null, allowed.map((address) => ({ address, family: isIP(address) })));
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
callback(null, allowed[0], isIP(allowed[0]));
|
|
121
|
+
}
|
|
122
|
+
}, (cause) => callback(new GuardError(`could not resolve ${hostname}: ${messageOf(cause)}`), ""));
|
|
123
|
+
}),
|
|
124
|
+
});
|
|
125
|
+
const httpConnector = guardedConnector(true);
|
|
126
|
+
const httpsConnector = guardedConnector(false);
|
|
127
|
+
const directDispatcher = new Agent({
|
|
128
|
+
connect: (options, callback) => {
|
|
129
|
+
// IP literals never reach `lookup`, so check them here.
|
|
130
|
+
const host = options.hostname.replace(/^\[|\]$/g, "");
|
|
131
|
+
if (options.protocol === "http:" && isIP(host) !== 0 && !isLoopbackAddress(host)) {
|
|
132
|
+
callback(new GuardError(plaintextTargetError(host)), null);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
if (isIP(host) !== 0 && !isAllowedAddress(host, resolvedPolicy)) {
|
|
136
|
+
callback(new GuardError(privateLiteralError(host)), null);
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
const connector = options.protocol === "http:" ? httpConnector : httpsConnector;
|
|
140
|
+
connector(options, callback);
|
|
141
|
+
},
|
|
142
|
+
});
|
|
143
|
+
// One ProxyAgent per distinct proxy URL, created on first use. A proxy
|
|
144
|
+
// comes from the process environment only, so configuring one IS the
|
|
145
|
+
// operator's authorization to dial it -- wherever it resolves, private or
|
|
146
|
+
// reserved addresses included -- and destination enforcement is delegated
|
|
147
|
+
// to it. TLS to the origin still runs end-to-end through the CONNECT
|
|
148
|
+
// tunnel with default verification.
|
|
149
|
+
const proxyAgents = new Map();
|
|
150
|
+
const proxyAgentFor = (decision) => {
|
|
151
|
+
const key = `${decision.url.href}|${decision.token ?? ""}`;
|
|
152
|
+
const existing = proxyAgents.get(key);
|
|
153
|
+
if (existing !== undefined)
|
|
154
|
+
return existing;
|
|
155
|
+
const agent = new ProxyAgent({
|
|
156
|
+
uri: decision.url.href,
|
|
157
|
+
...(decision.token === undefined ? {} : { token: decision.token }),
|
|
158
|
+
});
|
|
159
|
+
proxyAgents.set(key, agent);
|
|
160
|
+
return agent;
|
|
161
|
+
};
|
|
162
|
+
const dispatcher = {
|
|
163
|
+
dispatch(opts, handler) {
|
|
164
|
+
const origin = opts.origin;
|
|
165
|
+
const decision = resolveProxyFor(new URL(origin));
|
|
166
|
+
if (decision.kind === "invalid") {
|
|
167
|
+
throw new GuardError(decision.message);
|
|
168
|
+
}
|
|
169
|
+
if (decision.kind === "direct") {
|
|
170
|
+
return directDispatcher.dispatch(opts, handler);
|
|
171
|
+
}
|
|
172
|
+
return proxyAgentFor(decision).dispatch(opts, handler);
|
|
173
|
+
},
|
|
174
|
+
close() {
|
|
175
|
+
return Promise.all([
|
|
176
|
+
directDispatcher.close(),
|
|
177
|
+
...[...proxyAgents.values()].map((agent) => agent.close()),
|
|
178
|
+
]);
|
|
179
|
+
},
|
|
180
|
+
destroy(error) {
|
|
181
|
+
return Promise.all([
|
|
182
|
+
directDispatcher.destroy(error ?? null),
|
|
183
|
+
...[...proxyAgents.values()].map((agent) => agent.destroy(error ?? null)),
|
|
184
|
+
]);
|
|
185
|
+
},
|
|
186
|
+
// Test seam (test/helpers/undici.ts reaches the direct agent's connect).
|
|
187
|
+
direct: directDispatcher,
|
|
188
|
+
};
|
|
189
|
+
const send = async (url, init) => {
|
|
190
|
+
try {
|
|
191
|
+
// Cast: undici's RequestInit (dispatcher, its own BodyInit) differs
|
|
192
|
+
// structurally from the DOM lib's; the wire behavior is the same.
|
|
193
|
+
return (await undiciFetch(url, { ...init, dispatcher }));
|
|
194
|
+
}
|
|
195
|
+
catch (error) {
|
|
196
|
+
// undici wraps connect failures in "fetch failed"; surface the guard's reason.
|
|
197
|
+
const refusal = findGuardError(error);
|
|
198
|
+
throw refusal ?? error;
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
const fetchFn = (async (input, init) => {
|
|
202
|
+
let url;
|
|
203
|
+
let requestInit = init ?? {};
|
|
204
|
+
if (typeof input === "string" || input instanceof URL) {
|
|
205
|
+
url = new URL(input);
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
// A bare Request carries its own method/headers; merge them or the
|
|
209
|
+
// typeof fetch contract silently degrades to a bodyless GET. The body
|
|
210
|
+
// stream is intentionally NOT forwarded -- it may already be consumed,
|
|
211
|
+
// and the SDK's callers always pass (url, init) anyway.
|
|
212
|
+
url = new URL(input.url);
|
|
213
|
+
requestInit = { method: input.method, headers: input.headers, ...init };
|
|
214
|
+
}
|
|
215
|
+
if (url.protocol !== "https:" && url.protocol !== "http:") {
|
|
216
|
+
throw new GuardError(`refusing to fetch unsupported URL scheme "${url.protocol}" (http/https only)`);
|
|
217
|
+
}
|
|
218
|
+
const hostname = url.hostname.replace(/^\[|\]$/g, "");
|
|
219
|
+
if (url.protocol === "http:" && isIP(hostname) !== 0 && !isLoopbackAddress(hostname)) {
|
|
220
|
+
throw new GuardError(plaintextTargetError(hostname));
|
|
221
|
+
}
|
|
222
|
+
const method = (requestInit.method ?? "GET").toUpperCase();
|
|
223
|
+
const headers = new Headers(requestInit.headers);
|
|
224
|
+
const stateful = !(method === "GET" || method === "HEAD") || CREDENTIAL_HEADERS.some((name) => headers.has(name));
|
|
225
|
+
if (!stateful || requestInit.redirect === "manual")
|
|
226
|
+
return send(url, requestInit);
|
|
227
|
+
for (let redirects = 0;; redirects++) {
|
|
228
|
+
const response = await send(url, { ...requestInit, redirect: "manual" });
|
|
229
|
+
if (!isRedirectStatus(response.status))
|
|
230
|
+
return response;
|
|
231
|
+
const location = response.headers.get("location");
|
|
232
|
+
if (location === null)
|
|
233
|
+
throw new GuardError(`redirect from ${url} has no Location header`);
|
|
234
|
+
const next = new URL(location, url);
|
|
235
|
+
if (next.origin !== url.origin) {
|
|
236
|
+
throw new GuardError(`refusing to follow a cross-origin redirect from ${url.origin} to ${next.origin} for a ${method} request`);
|
|
237
|
+
}
|
|
238
|
+
if (redirects >= MAX_REDIRECTS)
|
|
239
|
+
throw new GuardError(`too many redirects while fetching ${url}`);
|
|
240
|
+
await response.body?.cancel();
|
|
241
|
+
url = next;
|
|
242
|
+
if (response.status === 303 || ((response.status === 301 || response.status === 302) && method === "POST")) {
|
|
243
|
+
// fetch semantics: these rewrite the request to a bodyless GET.
|
|
244
|
+
requestInit = { ...requestInit, method: "GET", body: undefined };
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
return {
|
|
249
|
+
fetchFn,
|
|
250
|
+
close: () => dispatcher.destroy().then(() => undefined),
|
|
251
|
+
};
|
|
252
|
+
}
|
package/dist/help.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builds the stable JSON command surface for `osd --help-json`.
|
|
3
|
+
*
|
|
4
|
+
* Generated from the live commander tree at runtime, never hand-written, so
|
|
5
|
+
* it cannot drift from the argument parser. The shape is validated in CI
|
|
6
|
+
* against test/fixtures/help-json.schema.json.
|
|
7
|
+
*/
|
|
8
|
+
import type { Command } from "commander";
|
|
9
|
+
export interface OptionJson {
|
|
10
|
+
flags: string;
|
|
11
|
+
description: string;
|
|
12
|
+
default?: unknown;
|
|
13
|
+
}
|
|
14
|
+
export interface CommandJson {
|
|
15
|
+
name: string;
|
|
16
|
+
description: string;
|
|
17
|
+
arguments: string[];
|
|
18
|
+
options: OptionJson[];
|
|
19
|
+
subcommands?: CommandJson[];
|
|
20
|
+
}
|
|
21
|
+
export declare function buildHelpJson(program: Command): {
|
|
22
|
+
name: string;
|
|
23
|
+
version: string;
|
|
24
|
+
description: string;
|
|
25
|
+
options: OptionJson[];
|
|
26
|
+
commands: CommandJson[];
|
|
27
|
+
};
|
package/dist/help.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { CLI_VERSION, REFRESH_COMMAND } from "./updates.js";
|
|
2
|
+
function commandJson(cmd) {
|
|
3
|
+
const json = {
|
|
4
|
+
name: cmd.name(),
|
|
5
|
+
description: cmd.description() ?? "",
|
|
6
|
+
// Argument names arrive without their brackets ("query" for "<query>").
|
|
7
|
+
arguments: cmd.registeredArguments.map((argument) => argument.name()),
|
|
8
|
+
options: cmd.options.map((option) => {
|
|
9
|
+
// Commander types `description` as a plain string property on Option.
|
|
10
|
+
// Defaults are deliberately omitted: some are derived from the
|
|
11
|
+
// environment (e.g. OSD_REGISTRY_URL), which would make this stable
|
|
12
|
+
// surface machine-dependent and could leak a private registry URL.
|
|
13
|
+
return { flags: option.flags, description: option.description ?? "" };
|
|
14
|
+
}),
|
|
15
|
+
};
|
|
16
|
+
const subcommands = cmd.commands.map(commandJson);
|
|
17
|
+
if (subcommands.length > 0)
|
|
18
|
+
json.subcommands = subcommands;
|
|
19
|
+
return json;
|
|
20
|
+
}
|
|
21
|
+
export function buildHelpJson(program) {
|
|
22
|
+
return {
|
|
23
|
+
name: program.name(),
|
|
24
|
+
version: CLI_VERSION,
|
|
25
|
+
description: program.description() ?? "",
|
|
26
|
+
// Program-level options (e.g. --allow-private-addresses) are part of the
|
|
27
|
+
// stable surface too. Defaults omitted as in commandJson.
|
|
28
|
+
options: program.options.map((option) => ({ flags: option.flags, description: option.description ?? "" })),
|
|
29
|
+
// The hidden cache-refresher is an internal, not part of the surface.
|
|
30
|
+
commands: program.commands.filter((cmd) => cmd.name() !== REFRESH_COMMAND).map(commandJson),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const httpFetch: typeof fetch;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The CLI's single fetch for plain (unguarded-dispatcher) requests: registry
|
|
3
|
+
* search and brand catalogs.
|
|
4
|
+
*
|
|
5
|
+
* Why not the global fetch: importing the `undici` package (guarded-fetch.ts
|
|
6
|
+
* needs its Agent/connector) installs undici's dispatcher as the process-wide
|
|
7
|
+
* global dispatcher. Node's BUNDLED fetch then runs on a dispatcher from a
|
|
8
|
+
* different undici major, and on Node 22 that skew silently breaks response
|
|
9
|
+
* decoding -- a `content-encoding: br` body (a CDN, i.e. the production
|
|
10
|
+
* directory) comes back as raw brotli bytes and every search "is not a valid
|
|
11
|
+
* response". Using undici's own fetch keeps fetch and dispatcher from the same
|
|
12
|
+
* copy, which is the same rule guarded-fetch.ts already follows.
|
|
13
|
+
*/
|
|
14
|
+
import { fetch as undiciFetch } from "undici";
|
|
15
|
+
// Cast: undici's RequestInit/Response differ structurally from the DOM lib's;
|
|
16
|
+
// the wire behavior is the same.
|
|
17
|
+
export const httpFetch = ((input, init) => undiciFetch(input, init));
|
package/dist/index.d.ts
ADDED