@buildinternet/uploads 0.48.0 → 0.49.0
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/README.md +5 -1
- package/dist/cli-help.js +2 -0
- package/dist/commands/completion.js +5 -1
- package/dist/commands/mcp.js +3 -3
- package/dist/commands.d.ts +10 -1
- package/dist/commands.js +117 -34
- package/dist/fetch-upload-source.d.ts +35 -0
- package/dist/fetch-upload-source.js +185 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/mcp/args.d.ts +6 -6
- package/dist/mcp/args.js +8 -6
- package/dist/mcp/output-schemas.d.ts +1 -1
- package/dist/mcp/output-schemas.js +8 -4
- package/dist/mcp/server.d.ts +13 -10
- package/dist/mcp/server.js +17 -5
- package/dist/mcp/tools.d.ts +1 -1
- package/dist/mcp/tools.js +100 -34
- package/dist/private-host.d.ts +14 -0
- package/dist/private-host.js +92 -0
- package/dist/screenshot.d.ts +2 -8
- package/dist/screenshot.js +2 -51
- package/package.json +2 -1
package/dist/screenshot.js
CHANGED
|
@@ -13,7 +13,9 @@ import { basename, resolve as resolvePath } from "node:path";
|
|
|
13
13
|
import { pathToFileURL } from "node:url";
|
|
14
14
|
import { UploadsError } from "./errors.js";
|
|
15
15
|
import { isMetaStateValue } from "./metadata-vocab.js";
|
|
16
|
+
import { isPrivateOrLocalHost } from "./private-host.js";
|
|
16
17
|
import { captureRemote, MAX_REMOTE_HTML_BYTES } from "./screenshot-remote.js";
|
|
18
|
+
export { isPrivateOrLocalHost };
|
|
17
19
|
/**
|
|
18
20
|
* Host selectors for framework dev toolbars/overlays that otherwise pollute a
|
|
19
21
|
* screenshot of a running dev server. Hidden (display:none) automatically when
|
|
@@ -84,57 +86,6 @@ export function parseWaitUntil(raw) {
|
|
|
84
86
|
return Number.parseInt(raw, 10);
|
|
85
87
|
throw new UploadsError(`invalid wait strategy: ${raw} (use load, domcontentloaded, networkidle, or a millisecond count)`, "USAGE");
|
|
86
88
|
}
|
|
87
|
-
/** IPv4 loopback/private/link-local ranges. Mirrors the server's isPrivateRenderTarget. */
|
|
88
|
-
const PRIVATE_IPV4_RE = /^(127\.\d+\.\d+\.\d+|0\.0\.0\.0|10\.\d+\.\d+\.\d+|192\.168\.\d+\.\d+|172\.(1[6-9]|2\d|3[01])\.\d+\.\d+|169\.254\.\d+\.\d+)$/;
|
|
89
|
-
/** Hostname forms treated as local/private regardless of DNS resolution. */
|
|
90
|
-
const PRIVATE_HOSTNAME_RE = /^((.+\.)?localhost|.+\.local|.+\.internal)$/i;
|
|
91
|
-
/** IPv6 unique local addresses, fc00::/7 (RFC 4193). */
|
|
92
|
-
const IPV6_ULA_RE = /^f[cd][0-9a-f]{2}:/i;
|
|
93
|
-
/** IPv6 link-local addresses, fe80::/10. */
|
|
94
|
-
const IPV6_LINK_LOCAL_RE = /^fe[89ab][0-9a-f]:/i;
|
|
95
|
-
function isPrivateIPv4(host) {
|
|
96
|
-
return PRIVATE_IPV4_RE.test(host);
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* True for localhost / private-network / link-local hosts — only reachable
|
|
100
|
-
* by the local backend. Accepts a bare hostname or an IPv6 literal with its
|
|
101
|
-
* brackets still attached (as returned by `new URL(...).hostname`, e.g.
|
|
102
|
-
* `"[::1]"`). Mirrors the server's `isPrivateRenderTarget` so `--via remote`
|
|
103
|
-
* fails fast for the same targets the render endpoint itself would reject.
|
|
104
|
-
*/
|
|
105
|
-
export function isPrivateOrLocalHost(hostname) {
|
|
106
|
-
const host = /^\[.+\]$/.test(hostname) ? hostname.slice(1, -1) : hostname;
|
|
107
|
-
if (isPrivateIPv4(host))
|
|
108
|
-
return true;
|
|
109
|
-
if (PRIVATE_HOSTNAME_RE.test(host))
|
|
110
|
-
return true;
|
|
111
|
-
if (host === "::1" || host === "::")
|
|
112
|
-
return true;
|
|
113
|
-
if (IPV6_ULA_RE.test(host))
|
|
114
|
-
return true;
|
|
115
|
-
if (IPV6_LINK_LOCAL_RE.test(host))
|
|
116
|
-
return true;
|
|
117
|
-
// IPv4-mapped IPv6, e.g. "::ffff:10.0.0.1" or "::ffff:a00:1" — private iff
|
|
118
|
-
// the mapped IPv4 quad is private.
|
|
119
|
-
const mapped = /^::ffff:(.+)$/i.exec(host);
|
|
120
|
-
if (mapped) {
|
|
121
|
-
const rest = mapped[1];
|
|
122
|
-
if (isPrivateIPv4(rest))
|
|
123
|
-
return true;
|
|
124
|
-
const hex = /^([0-9a-f]{1,4}):([0-9a-f]{1,4})$/i.exec(rest);
|
|
125
|
-
if (hex) {
|
|
126
|
-
const hi = Number.parseInt(hex[1], 16);
|
|
127
|
-
const lo = Number.parseInt(hex[2], 16);
|
|
128
|
-
const a = (hi >> 8) & 0xff;
|
|
129
|
-
const b = hi & 0xff;
|
|
130
|
-
const c = (lo >> 8) & 0xff;
|
|
131
|
-
const d = lo & 0xff;
|
|
132
|
-
if (isPrivateIPv4(`${a}.${b}.${c}.${d}`))
|
|
133
|
-
return true;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
return false;
|
|
137
|
-
}
|
|
138
89
|
/** Classifies a CLI target: http(s) URL, or a path to a local .html file. */
|
|
139
90
|
export function classifyTarget(target) {
|
|
140
91
|
if (/^https?:\/\//i.test(target)) {
|
package/package.json
CHANGED