@socketsecurity/lib 5.18.2 → 5.19.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/CHANGELOG.md +43 -0
- package/README.md +6 -5
- package/dist/abort.d.ts +3 -0
- package/dist/abort.js +1 -0
- package/dist/agent.d.ts +66 -49
- package/dist/agent.js +51 -50
- package/dist/ansi.d.ts +2 -5
- package/dist/ansi.js +3 -2
- package/dist/archives.d.ts +25 -21
- package/dist/archives.js +35 -34
- package/dist/argv/flags.d.ts +100 -91
- package/dist/argv/flags.js +88 -87
- package/dist/argv/parse.d.ts +30 -40
- package/dist/argv/parse.js +33 -32
- package/dist/arrays.d.ts +4 -8
- package/dist/arrays.js +1 -0
- package/dist/bin.d.ts +7 -5
- package/dist/bin.js +52 -29
- package/dist/cacache.d.ts +13 -12
- package/dist/cacache.js +9 -8
- package/dist/cache-with-ttl.d.ts +53 -35
- package/dist/cache-with-ttl.js +1 -0
- package/dist/colors.d.ts +5 -5
- package/dist/colors.js +1 -0
- package/dist/constants/agents.d.ts +5 -9
- package/dist/constants/agents.js +3 -2
- package/dist/constants/core.d.ts +5 -10
- package/dist/constants/core.js +2 -1
- package/dist/constants/encoding.d.ts +3 -3
- package/dist/constants/encoding.js +1 -0
- package/dist/constants/github.d.ts +3 -3
- package/dist/constants/github.js +1 -0
- package/dist/constants/licenses.d.ts +9 -2
- package/dist/constants/licenses.js +1 -0
- package/dist/constants/lifecycle-script-names.js +1 -0
- package/dist/constants/maintained-node-versions.d.ts +3 -0
- package/dist/constants/maintained-node-versions.js +1 -0
- package/dist/constants/node.d.ts +125 -16
- package/dist/constants/node.js +74 -73
- package/dist/constants/package-default-node-range.d.ts +3 -1
- package/dist/constants/package-default-node-range.js +2 -1
- package/dist/constants/package-default-socket-categories.d.ts +0 -1
- package/dist/constants/package-default-socket-categories.js +1 -0
- package/dist/constants/packages.d.ts +12 -17
- package/dist/constants/packages.js +31 -16
- package/dist/constants/platform.d.ts +1 -2
- package/dist/constants/platform.js +2 -1
- package/dist/constants/process.d.ts +18 -0
- package/dist/constants/process.js +1 -0
- package/dist/constants/socket.d.ts +4 -10
- package/dist/constants/socket.js +2 -1
- package/dist/constants/testing.d.ts +3 -3
- package/dist/constants/testing.js +1 -0
- package/dist/constants/time.d.ts +3 -4
- package/dist/constants/time.js +1 -0
- package/dist/constants/typescript.d.ts +10 -3
- package/dist/constants/typescript.js +5 -4
- package/dist/cover/code.d.ts +3 -0
- package/dist/cover/code.js +12 -12
- package/dist/cover/formatters.d.ts +12 -9
- package/dist/cover/formatters.js +19 -18
- package/dist/cover/type.d.ts +3 -0
- package/dist/cover/type.js +1 -0
- package/dist/cover/types.js +1 -0
- package/dist/debug.d.ts +32 -47
- package/dist/debug.js +97 -96
- package/dist/dlx/arborist.d.ts +134 -0
- package/dist/dlx/arborist.js +177 -0
- package/dist/dlx/binary.d.ts +25 -9
- package/dist/dlx/binary.js +34 -12
- package/dist/dlx/cache.d.ts +1 -0
- package/dist/dlx/cache.js +2 -1
- package/dist/dlx/detect.d.ts +15 -0
- package/dist/dlx/detect.js +28 -20
- package/dist/dlx/dir.d.ts +1 -11
- package/dist/dlx/dir.js +2 -12
- package/dist/dlx/integrity.d.ts +86 -0
- package/dist/dlx/integrity.js +112 -0
- package/dist/dlx/lockfile.d.ts +115 -0
- package/dist/dlx/lockfile.js +139 -0
- package/dist/dlx/manifest.d.ts +26 -1
- package/dist/dlx/manifest.js +9 -6
- package/dist/dlx/package.d.ts +58 -3
- package/dist/dlx/package.js +101 -74
- package/dist/dlx/packages.d.ts +1 -11
- package/dist/dlx/packages.js +3 -14
- package/dist/dlx/paths.d.ts +1 -0
- package/dist/dlx/paths.js +2 -1
- package/dist/effects/pulse-frames.js +1 -0
- package/dist/effects/text-shimmer.d.ts +13 -2
- package/dist/effects/text-shimmer.js +50 -46
- package/dist/effects/types.js +1 -0
- package/dist/effects/ultra.js +1 -0
- package/dist/env/ci.d.ts +6 -1
- package/dist/env/ci.js +1 -0
- package/dist/env/debug.d.ts +5 -1
- package/dist/env/debug.js +1 -0
- package/dist/env/github.d.ts +19 -23
- package/dist/env/github.js +5 -4
- package/dist/env/helpers.d.ts +21 -9
- package/dist/env/helpers.js +5 -11
- package/dist/env/home.d.ts +17 -4
- package/dist/env/home.js +2 -1
- package/dist/env/locale.d.ts +4 -3
- package/dist/env/locale.js +1 -0
- package/dist/env/node-auth-token.d.ts +5 -1
- package/dist/env/node-auth-token.js +1 -0
- package/dist/env/node-env.d.ts +5 -1
- package/dist/env/node-env.js +1 -0
- package/dist/env/npm.d.ts +4 -5
- package/dist/env/npm.js +1 -0
- package/dist/env/package-manager.d.ts +4 -3
- package/dist/env/package-manager.js +2 -1
- package/dist/env/path.d.ts +5 -1
- package/dist/env/path.js +1 -0
- package/dist/env/pre-commit.d.ts +5 -1
- package/dist/env/pre-commit.js +1 -0
- package/dist/env/rewire.d.ts +10 -0
- package/dist/env/rewire.js +7 -5
- package/dist/env/shell.d.ts +5 -1
- package/dist/env/shell.js +1 -0
- package/dist/env/socket-cli-shadow.d.ts +4 -5
- package/dist/env/socket-cli-shadow.js +1 -0
- package/dist/env/socket-cli.d.ts +4 -14
- package/dist/env/socket-cli.js +1 -0
- package/dist/env/socket.d.ts +6 -18
- package/dist/env/socket.js +4 -3
- package/dist/env/temp-dir.d.ts +4 -3
- package/dist/env/temp-dir.js +1 -0
- package/dist/env/term.d.ts +5 -1
- package/dist/env/term.js +1 -0
- package/dist/env/test.d.ts +4 -3
- package/dist/env/test.js +1 -0
- package/dist/env/windows.d.ts +4 -4
- package/dist/env/windows.js +1 -0
- package/dist/env/xdg.d.ts +4 -3
- package/dist/env/xdg.js +1 -0
- package/dist/env.d.ts +83 -23
- package/dist/env.js +112 -80
- package/dist/errors.js +1 -0
- package/dist/external/@npmcli/package-json.js +9 -3968
- package/dist/external/@socketregistry/packageurl-js.js +2 -2
- package/dist/external/debug.js +162 -328
- package/dist/external/external-pack.js +3 -2835
- package/dist/external/npm-pack.js +13939 -33342
- package/dist/external/zod.js +160 -7558
- package/dist/fs.d.ts +92 -113
- package/dist/fs.js +35 -35
- package/dist/git.d.ts +170 -164
- package/dist/git.js +113 -87
- package/dist/github.d.ts +249 -227
- package/dist/github.js +82 -81
- package/dist/globs.d.ts +31 -17
- package/dist/globs.js +51 -58
- package/dist/http-request.d.ts +99 -99
- package/dist/http-request.js +182 -156
- package/dist/ipc-cli.d.ts +28 -0
- package/dist/{utils/get-ipc.js → ipc-cli.js} +4 -3
- package/dist/ipc.d.ts +9 -299
- package/dist/ipc.js +18 -204
- package/dist/json/edit.d.ts +3 -1
- package/dist/json/edit.js +30 -30
- package/dist/json/format.d.ts +36 -36
- package/dist/json/format.js +22 -21
- package/dist/json/parse.d.ts +4 -2
- package/dist/json/parse.js +1 -0
- package/dist/json/types.js +1 -0
- package/dist/{links/index.d.ts → links.d.ts} +6 -2
- package/dist/{links/index.js → links.js} +5 -4
- package/dist/logger.d.ts +4 -6
- package/dist/logger.js +61 -53
- package/dist/memoization.d.ts +52 -49
- package/dist/memoization.js +55 -33
- package/dist/objects.d.ts +25 -44
- package/dist/objects.js +2 -1
- package/dist/package-extensions.d.ts +6 -0
- package/dist/package-extensions.js +2 -1
- package/dist/packages/edit.d.ts +3 -5
- package/dist/packages/edit.js +4 -3
- package/dist/packages/exports.d.ts +11 -14
- package/dist/packages/exports.js +11 -10
- package/dist/packages/isolation.d.ts +4 -0
- package/dist/packages/isolation.js +20 -19
- package/dist/packages/licenses.d.ts +3 -10
- package/dist/packages/licenses.js +2 -1
- package/dist/packages/manifest.d.ts +3 -3
- package/dist/packages/manifest.js +1 -0
- package/dist/packages/normalize.d.ts +3 -4
- package/dist/packages/normalize.js +1 -0
- package/dist/packages/operations.d.ts +3 -10
- package/dist/packages/operations.js +1 -0
- package/dist/packages/provenance.d.ts +10 -8
- package/dist/packages/provenance.js +55 -54
- package/dist/packages/specs.d.ts +3 -5
- package/dist/packages/specs.js +1 -0
- package/dist/packages/validation.d.ts +3 -3
- package/dist/packages/validation.js +1 -0
- package/dist/packages.d.ts +2 -17
- package/dist/packages.js +2 -1
- package/dist/paths/dirnames.d.ts +0 -2
- package/dist/paths/dirnames.js +1 -0
- package/dist/paths/exts.d.ts +0 -1
- package/dist/paths/exts.js +1 -0
- package/dist/paths/filenames.d.ts +0 -1
- package/dist/paths/filenames.js +1 -0
- package/dist/paths/globs.d.ts +0 -1
- package/dist/paths/globs.js +1 -0
- package/dist/paths/normalize.d.ts +115 -123
- package/dist/paths/normalize.js +128 -127
- package/dist/paths/packages.d.ts +3 -2
- package/dist/paths/packages.js +2 -1
- package/dist/paths/rewire.d.ts +9 -0
- package/dist/paths/rewire.js +5 -3
- package/dist/paths/socket.d.ts +37 -23
- package/dist/paths/socket.js +26 -25
- package/dist/performance.d.ts +87 -84
- package/dist/performance.js +97 -96
- package/dist/process-lock.d.ts +41 -1
- package/dist/process-lock.js +24 -17
- package/dist/promise-queue.d.ts +6 -0
- package/dist/promise-queue.js +1 -0
- package/dist/promises.d.ts +40 -55
- package/dist/promises.js +12 -11
- package/dist/regexps.d.ts +0 -5
- package/dist/regexps.js +1 -0
- package/dist/releases/github.d.ts +59 -63
- package/dist/releases/github.js +95 -100
- package/dist/releases/socket-btm.d.ts +9 -2
- package/dist/releases/socket-btm.js +32 -25
- package/dist/sea.d.ts +5 -0
- package/dist/sea.js +1 -0
- package/dist/shadow.d.ts +4 -0
- package/dist/shadow.js +1 -0
- package/dist/signal-exit.d.ts +7 -7
- package/dist/signal-exit.js +46 -45
- package/dist/sorts.d.ts +5 -7
- package/dist/sorts.js +11 -10
- package/dist/spawn.d.ts +96 -77
- package/dist/spawn.js +39 -38
- package/dist/spinner.d.ts +21 -22
- package/dist/spinner.js +15 -11
- package/dist/ssri.d.ts +31 -36
- package/dist/ssri.js +15 -14
- package/dist/stdio/_stream.d.ts +31 -0
- package/dist/stdio/_stream.js +57 -0
- package/dist/stdio/divider.d.ts +40 -36
- package/dist/stdio/divider.js +10 -9
- package/dist/stdio/footer.d.ts +20 -0
- package/dist/stdio/footer.js +12 -2
- package/dist/stdio/header.d.ts +4 -16
- package/dist/stdio/header.js +1 -9
- package/dist/stdio/stderr.d.ts +51 -39
- package/dist/stdio/stderr.js +19 -22
- package/dist/stdio/stdout.d.ts +54 -52
- package/dist/stdio/stdout.js +35 -33
- package/dist/streams.d.ts +4 -3
- package/dist/streams.js +1 -0
- package/dist/strings.d.ts +31 -85
- package/dist/strings.js +5 -49
- package/dist/suppress-warnings.d.ts +32 -15
- package/dist/suppress-warnings.js +14 -13
- package/dist/tables.d.ts +30 -26
- package/dist/tables.js +24 -23
- package/dist/temporary-executor.d.ts +4 -0
- package/dist/temporary-executor.js +1 -0
- package/dist/themes/context.d.ts +30 -26
- package/dist/themes/context.js +19 -18
- package/dist/themes/index.d.ts +0 -4
- package/dist/themes/index.js +1 -0
- package/dist/themes/themes.d.ts +1 -1
- package/dist/themes/themes.js +1 -0
- package/dist/themes/types.js +1 -0
- package/dist/themes/utils.d.ts +46 -43
- package/dist/themes/utils.js +45 -44
- package/dist/types.d.ts +48 -52
- package/dist/types.js +35 -35
- package/dist/url.d.ts +48 -53
- package/dist/url.js +38 -37
- package/dist/validation/json-parser.d.ts +19 -190
- package/dist/validation/json-parser.js +5 -69
- package/dist/validation/types.d.ts +9 -33
- package/dist/validation/types.js +1 -0
- package/dist/versions.d.ts +1 -0
- package/dist/versions.js +2 -1
- package/dist/words.d.ts +3 -6
- package/dist/words.js +1 -0
- package/dist/zod.js +1 -0
- package/package.json +34 -66
- package/dist/external/@inquirer/checkbox.js +0 -5
- package/dist/external/@inquirer/confirm.js +0 -5
- package/dist/external/@inquirer/input.js +0 -5
- package/dist/external/@inquirer/password.js +0 -5
- package/dist/external/@inquirer/search.js +0 -5
- package/dist/external/@inquirer/select.js +0 -5
- package/dist/functions.d.ts +0 -57
- package/dist/functions.js +0 -70
- package/dist/stdio/clear.d.ts +0 -140
- package/dist/stdio/clear.js +0 -95
- package/dist/stdio/mask.d.ts +0 -151
- package/dist/stdio/mask.js +0 -224
- package/dist/stdio/progress.d.ts +0 -148
- package/dist/stdio/progress.js +0 -212
- package/dist/stdio/prompts.d.ts +0 -195
- package/dist/stdio/prompts.js +0 -176
- package/dist/utils/get-ipc.d.ts +0 -15
package/dist/http-request.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/* Socket Lib - Built with esbuild */
|
|
3
|
+
"use strict";
|
|
3
4
|
var __defProp = Object.defineProperty;
|
|
4
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
@@ -33,158 +34,50 @@ __export(http_request_exports, {
|
|
|
33
34
|
});
|
|
34
35
|
module.exports = __toCommonJS(http_request_exports);
|
|
35
36
|
var import_socket = require("./constants/socket");
|
|
36
|
-
var import_fs = require("./fs
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
var import_fs = require("./fs");
|
|
38
|
+
class HttpResponseError extends Error {
|
|
39
|
+
response;
|
|
40
|
+
constructor(response, message) {
|
|
41
|
+
const statusCode = response.status ?? "unknown";
|
|
42
|
+
const statusMessage = response.statusText || "No status message";
|
|
43
|
+
super(message ?? `HTTP ${statusCode}: ${statusMessage}`);
|
|
44
|
+
this.name = "HttpResponseError";
|
|
45
|
+
this.response = response;
|
|
46
|
+
Error.captureStackTrace(this, HttpResponseError);
|
|
42
47
|
}
|
|
43
|
-
return _fs;
|
|
44
48
|
}
|
|
49
|
+
let _fs;
|
|
45
50
|
let _crypto;
|
|
46
51
|
let _http;
|
|
47
52
|
let _https;
|
|
48
53
|
// @__NO_SIDE_EFFECTS__
|
|
49
54
|
function getCrypto() {
|
|
50
55
|
if (_crypto === void 0) {
|
|
51
|
-
_crypto = require("crypto");
|
|
56
|
+
_crypto = require("node:crypto");
|
|
52
57
|
}
|
|
53
58
|
return _crypto;
|
|
54
59
|
}
|
|
55
60
|
// @__NO_SIDE_EFFECTS__
|
|
61
|
+
function getFs() {
|
|
62
|
+
if (_fs === void 0) {
|
|
63
|
+
_fs = require("node:fs");
|
|
64
|
+
}
|
|
65
|
+
return _fs;
|
|
66
|
+
}
|
|
67
|
+
// @__NO_SIDE_EFFECTS__
|
|
56
68
|
function getHttp() {
|
|
57
69
|
if (_http === void 0) {
|
|
58
|
-
_http = require("http");
|
|
70
|
+
_http = require("node:http");
|
|
59
71
|
}
|
|
60
72
|
return _http;
|
|
61
73
|
}
|
|
62
74
|
// @__NO_SIDE_EFFECTS__
|
|
63
75
|
function getHttps() {
|
|
64
76
|
if (_https === void 0) {
|
|
65
|
-
_https = require("https");
|
|
77
|
+
_https = require("node:https");
|
|
66
78
|
}
|
|
67
79
|
return _https;
|
|
68
80
|
}
|
|
69
|
-
async function readIncomingResponse(msg) {
|
|
70
|
-
const chunks = [];
|
|
71
|
-
for await (const chunk of msg) {
|
|
72
|
-
chunks.push(chunk);
|
|
73
|
-
}
|
|
74
|
-
const body = Buffer.concat(chunks);
|
|
75
|
-
const status = msg.statusCode ?? 0;
|
|
76
|
-
const statusText = msg.statusMessage ?? "";
|
|
77
|
-
return {
|
|
78
|
-
arrayBuffer: () => body.buffer.slice(
|
|
79
|
-
body.byteOffset,
|
|
80
|
-
body.byteOffset + body.byteLength
|
|
81
|
-
),
|
|
82
|
-
body,
|
|
83
|
-
headers: msg.headers,
|
|
84
|
-
json: () => JSON.parse(body.toString("utf8")),
|
|
85
|
-
ok: status >= 200 && status < 300,
|
|
86
|
-
rawResponse: msg,
|
|
87
|
-
status,
|
|
88
|
-
statusText,
|
|
89
|
-
text: () => body.toString("utf8")
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
class HttpResponseError extends Error {
|
|
93
|
-
response;
|
|
94
|
-
constructor(response, message) {
|
|
95
|
-
const statusCode = response.status ?? "unknown";
|
|
96
|
-
const statusMessage = response.statusText || "No status message";
|
|
97
|
-
super(message ?? `HTTP ${statusCode}: ${statusMessage}`);
|
|
98
|
-
this.name = "HttpResponseError";
|
|
99
|
-
this.response = response;
|
|
100
|
-
Error.captureStackTrace(this, HttpResponseError);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
function parseRetryAfterHeader(value) {
|
|
104
|
-
if (!value) {
|
|
105
|
-
return void 0;
|
|
106
|
-
}
|
|
107
|
-
const raw = Array.isArray(value) ? value[0] : value;
|
|
108
|
-
if (!raw) {
|
|
109
|
-
return void 0;
|
|
110
|
-
}
|
|
111
|
-
const trimmed = raw.trim();
|
|
112
|
-
if (/^\d+$/.test(trimmed)) {
|
|
113
|
-
const seconds = Number(trimmed);
|
|
114
|
-
return seconds * 1e3;
|
|
115
|
-
}
|
|
116
|
-
const date = new Date(raw);
|
|
117
|
-
if (!Number.isNaN(date.getTime())) {
|
|
118
|
-
const delayMs = date.getTime() - Date.now();
|
|
119
|
-
if (delayMs > 0) {
|
|
120
|
-
return delayMs;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
return void 0;
|
|
124
|
-
}
|
|
125
|
-
function sanitizeHeaders(headers) {
|
|
126
|
-
if (!headers) {
|
|
127
|
-
return {};
|
|
128
|
-
}
|
|
129
|
-
const sensitiveHeaders = /* @__PURE__ */ new Set([
|
|
130
|
-
"authorization",
|
|
131
|
-
"cookie",
|
|
132
|
-
"proxy-authorization",
|
|
133
|
-
"proxy-authenticate",
|
|
134
|
-
"set-cookie",
|
|
135
|
-
"www-authenticate"
|
|
136
|
-
]);
|
|
137
|
-
const result = { __proto__: null };
|
|
138
|
-
for (const key of Object.keys(headers)) {
|
|
139
|
-
const value = headers[key];
|
|
140
|
-
if (sensitiveHeaders.has(key.toLowerCase())) {
|
|
141
|
-
result[key] = "[REDACTED]";
|
|
142
|
-
} else if (Array.isArray(value)) {
|
|
143
|
-
result[key] = value.join(", ");
|
|
144
|
-
} else if (value !== void 0 && value !== null) {
|
|
145
|
-
result[key] = String(value);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
return result;
|
|
149
|
-
}
|
|
150
|
-
function parseChecksums(text) {
|
|
151
|
-
const checksums = { __proto__: null };
|
|
152
|
-
for (const line of text.split("\n")) {
|
|
153
|
-
const trimmed = line.trim();
|
|
154
|
-
if (!trimmed || trimmed.startsWith("#")) {
|
|
155
|
-
continue;
|
|
156
|
-
}
|
|
157
|
-
const bsdMatch = trimmed.match(
|
|
158
|
-
/^SHA256\s+\((.+)\)\s+=\s+([a-fA-F0-9]{64})$/
|
|
159
|
-
);
|
|
160
|
-
if (bsdMatch) {
|
|
161
|
-
checksums[bsdMatch[1]] = bsdMatch[2].toLowerCase();
|
|
162
|
-
continue;
|
|
163
|
-
}
|
|
164
|
-
const gnuMatch = trimmed.match(/^([a-fA-F0-9]{64})\s+(.+)$/);
|
|
165
|
-
if (gnuMatch) {
|
|
166
|
-
checksums[gnuMatch[2]] = gnuMatch[1].toLowerCase();
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
return checksums;
|
|
170
|
-
}
|
|
171
|
-
async function fetchChecksums(url, options) {
|
|
172
|
-
const {
|
|
173
|
-
ca,
|
|
174
|
-
headers = {},
|
|
175
|
-
timeout = 3e4
|
|
176
|
-
} = {
|
|
177
|
-
__proto__: null,
|
|
178
|
-
...options
|
|
179
|
-
};
|
|
180
|
-
const response = await httpRequest(url, { ca, headers, timeout });
|
|
181
|
-
if (!response.ok) {
|
|
182
|
-
throw new Error(
|
|
183
|
-
`Failed to fetch checksums from ${url}: ${response.status} ${response.statusText}`
|
|
184
|
-
);
|
|
185
|
-
}
|
|
186
|
-
return parseChecksums(response.body.toString("utf8"));
|
|
187
|
-
}
|
|
188
81
|
async function httpDownloadAttempt(url, destPath, options) {
|
|
189
82
|
const {
|
|
190
83
|
ca,
|
|
@@ -204,7 +97,8 @@ async function httpDownloadAttempt(url, destPath, options) {
|
|
|
204
97
|
timeout
|
|
205
98
|
});
|
|
206
99
|
if (!response.ok) {
|
|
207
|
-
throw new
|
|
100
|
+
throw new HttpResponseError(
|
|
101
|
+
response,
|
|
208
102
|
`Download failed: HTTP ${response.status} ${response.statusText}`
|
|
209
103
|
);
|
|
210
104
|
}
|
|
@@ -220,8 +114,13 @@ async function httpDownloadAttempt(url, destPath, options) {
|
|
|
220
114
|
return await new Promise((resolve, reject) => {
|
|
221
115
|
let downloadedSize = 0;
|
|
222
116
|
const fileStream = createWriteStream(destPath);
|
|
117
|
+
const cleanupPartial = () => {
|
|
118
|
+
(/* @__PURE__ */ getFs()).promises.unlink(destPath).catch(() => {
|
|
119
|
+
});
|
|
120
|
+
};
|
|
223
121
|
fileStream.on("error", (error) => {
|
|
224
|
-
fileStream.
|
|
122
|
+
fileStream.destroy();
|
|
123
|
+
cleanupPartial();
|
|
225
124
|
reject(
|
|
226
125
|
new Error(`Failed to write file: ${error.message}`, { cause: error })
|
|
227
126
|
);
|
|
@@ -245,33 +144,13 @@ async function httpDownloadAttempt(url, destPath, options) {
|
|
|
245
144
|
});
|
|
246
145
|
});
|
|
247
146
|
res.on("error", (error) => {
|
|
248
|
-
fileStream.
|
|
147
|
+
fileStream.destroy();
|
|
148
|
+
cleanupPartial();
|
|
249
149
|
reject(error);
|
|
250
150
|
});
|
|
251
151
|
res.pipe(fileStream);
|
|
252
152
|
});
|
|
253
153
|
}
|
|
254
|
-
function enrichErrorMessage(url, method, error) {
|
|
255
|
-
const code = error.code;
|
|
256
|
-
let message = `${method} request failed: ${url}`;
|
|
257
|
-
if (code === "ECONNREFUSED") {
|
|
258
|
-
message += "\n\u2192 Connection refused. Server is unreachable.\n\u2192 Check: Network connectivity and firewall settings.";
|
|
259
|
-
} else if (code === "ENOTFOUND") {
|
|
260
|
-
message += "\n\u2192 DNS lookup failed. Cannot resolve hostname.\n\u2192 Check: Internet connection and DNS settings.";
|
|
261
|
-
} else if (code === "ETIMEDOUT") {
|
|
262
|
-
message += "\n\u2192 Connection timed out. Network or server issue.\n\u2192 Try: Check network connectivity and retry.";
|
|
263
|
-
} else if (code === "ECONNRESET") {
|
|
264
|
-
message += "\n\u2192 Connection reset by server. Possible network interruption.\n\u2192 Try: Retry the request.";
|
|
265
|
-
} else if (code === "EPIPE") {
|
|
266
|
-
message += "\n\u2192 Broken pipe. Server closed connection unexpectedly.\n\u2192 Check: Authentication credentials and permissions.";
|
|
267
|
-
} else if (code === "CERT_HAS_EXPIRED" || code === "UNABLE_TO_VERIFY_LEAF_SIGNATURE") {
|
|
268
|
-
message += "\n\u2192 SSL/TLS certificate error.\n\u2192 Check: System time and date are correct.\n\u2192 Try: Update CA certificates on your system.";
|
|
269
|
-
} else if (code) {
|
|
270
|
-
message += `
|
|
271
|
-
\u2192 Error code: ${code}`;
|
|
272
|
-
}
|
|
273
|
-
return message;
|
|
274
|
-
}
|
|
275
154
|
async function httpRequestAttempt(url, options) {
|
|
276
155
|
const {
|
|
277
156
|
body,
|
|
@@ -369,13 +248,29 @@ async function httpRequestAttempt(url, options) {
|
|
|
369
248
|
);
|
|
370
249
|
return;
|
|
371
250
|
}
|
|
251
|
+
let redirectHeaders = headers;
|
|
252
|
+
if (new URL(url).origin !== redirectParsed.origin) {
|
|
253
|
+
redirectHeaders = { __proto__: null };
|
|
254
|
+
const stripped = /* @__PURE__ */ new Set([
|
|
255
|
+
"authorization",
|
|
256
|
+
"cookie",
|
|
257
|
+
"proxy-authorization",
|
|
258
|
+
"proxy-authenticate"
|
|
259
|
+
]);
|
|
260
|
+
for (const key of Object.keys(headers)) {
|
|
261
|
+
if (!stripped.has(key.toLowerCase())) {
|
|
262
|
+
;
|
|
263
|
+
redirectHeaders[key] = headers[key];
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
372
267
|
settled = true;
|
|
373
268
|
resolve(
|
|
374
269
|
httpRequestAttempt(redirectUrl, {
|
|
375
270
|
body,
|
|
376
271
|
ca,
|
|
377
272
|
followRedirects,
|
|
378
|
-
headers,
|
|
273
|
+
headers: redirectHeaders,
|
|
379
274
|
hooks,
|
|
380
275
|
maxRedirects: maxRedirects - 1,
|
|
381
276
|
maxResponseSize,
|
|
@@ -502,6 +397,44 @@ async function httpRequestAttempt(url, options) {
|
|
|
502
397
|
}
|
|
503
398
|
});
|
|
504
399
|
}
|
|
400
|
+
function enrichErrorMessage(url, method, error) {
|
|
401
|
+
const code = error.code;
|
|
402
|
+
let message = `${method} request failed: ${url}`;
|
|
403
|
+
if (code === "ECONNREFUSED") {
|
|
404
|
+
message += "\n\u2192 Connection refused. Server is unreachable.\n\u2192 Check: Network connectivity and firewall settings.";
|
|
405
|
+
} else if (code === "ENOTFOUND") {
|
|
406
|
+
message += "\n\u2192 DNS lookup failed. Cannot resolve hostname.\n\u2192 Check: Internet connection and DNS settings.";
|
|
407
|
+
} else if (code === "ETIMEDOUT") {
|
|
408
|
+
message += "\n\u2192 Connection timed out. Network or server issue.\n\u2192 Try: Check network connectivity and retry.";
|
|
409
|
+
} else if (code === "ECONNRESET") {
|
|
410
|
+
message += "\n\u2192 Connection reset by server. Possible network interruption.\n\u2192 Try: Retry the request.";
|
|
411
|
+
} else if (code === "EPIPE") {
|
|
412
|
+
message += "\n\u2192 Broken pipe. Server closed connection unexpectedly.\n\u2192 Check: Authentication credentials and permissions.";
|
|
413
|
+
} else if (code === "CERT_HAS_EXPIRED" || code === "UNABLE_TO_VERIFY_LEAF_SIGNATURE") {
|
|
414
|
+
message += "\n\u2192 SSL/TLS certificate error.\n\u2192 Check: System time and date are correct.\n\u2192 Try: Update CA certificates on your system.";
|
|
415
|
+
} else if (code) {
|
|
416
|
+
message += `
|
|
417
|
+
\u2192 Error code: ${code}`;
|
|
418
|
+
}
|
|
419
|
+
return message;
|
|
420
|
+
}
|
|
421
|
+
async function fetchChecksums(url, options) {
|
|
422
|
+
const {
|
|
423
|
+
ca,
|
|
424
|
+
headers = {},
|
|
425
|
+
timeout = 3e4
|
|
426
|
+
} = {
|
|
427
|
+
__proto__: null,
|
|
428
|
+
...options
|
|
429
|
+
};
|
|
430
|
+
const response = await httpRequest(url, { ca, headers, timeout });
|
|
431
|
+
if (!response.ok) {
|
|
432
|
+
throw new Error(
|
|
433
|
+
`Failed to fetch checksums from ${url}: ${response.status} ${response.statusText}`
|
|
434
|
+
);
|
|
435
|
+
}
|
|
436
|
+
return parseChecksums(response.body.toString("utf8"));
|
|
437
|
+
}
|
|
505
438
|
async function httpDownload(url, destPath, options) {
|
|
506
439
|
const {
|
|
507
440
|
ca,
|
|
@@ -609,7 +542,7 @@ async function httpJson(url, options) {
|
|
|
609
542
|
...restOptions
|
|
610
543
|
});
|
|
611
544
|
if (!response.ok) {
|
|
612
|
-
throw new
|
|
545
|
+
throw new HttpResponseError(response);
|
|
613
546
|
}
|
|
614
547
|
try {
|
|
615
548
|
return response.json();
|
|
@@ -707,10 +640,103 @@ async function httpText(url, options) {
|
|
|
707
640
|
...restOptions
|
|
708
641
|
});
|
|
709
642
|
if (!response.ok) {
|
|
710
|
-
throw new
|
|
643
|
+
throw new HttpResponseError(response);
|
|
711
644
|
}
|
|
712
645
|
return response.text();
|
|
713
646
|
}
|
|
647
|
+
function parseChecksums(text) {
|
|
648
|
+
const checksums = { __proto__: null };
|
|
649
|
+
for (const line of text.split("\n")) {
|
|
650
|
+
const trimmed = line.trim();
|
|
651
|
+
if (!trimmed || trimmed.startsWith("#")) {
|
|
652
|
+
continue;
|
|
653
|
+
}
|
|
654
|
+
const bsdMatch = trimmed.match(
|
|
655
|
+
/^SHA256\s+\((.+)\)\s+=\s+([a-fA-F0-9]{64})$/
|
|
656
|
+
);
|
|
657
|
+
if (bsdMatch) {
|
|
658
|
+
checksums[bsdMatch[1]] = bsdMatch[2].toLowerCase();
|
|
659
|
+
continue;
|
|
660
|
+
}
|
|
661
|
+
const gnuMatch = trimmed.match(/^([a-fA-F0-9]{64})\s+(.+)$/);
|
|
662
|
+
if (gnuMatch) {
|
|
663
|
+
checksums[gnuMatch[2]] = gnuMatch[1].toLowerCase();
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
return checksums;
|
|
667
|
+
}
|
|
668
|
+
function parseRetryAfterHeader(value) {
|
|
669
|
+
if (!value) {
|
|
670
|
+
return void 0;
|
|
671
|
+
}
|
|
672
|
+
const raw = Array.isArray(value) ? value[0] : value;
|
|
673
|
+
if (!raw) {
|
|
674
|
+
return void 0;
|
|
675
|
+
}
|
|
676
|
+
const trimmed = raw.trim();
|
|
677
|
+
if (/^\d+$/.test(trimmed)) {
|
|
678
|
+
const seconds = Number(trimmed);
|
|
679
|
+
return seconds * 1e3;
|
|
680
|
+
}
|
|
681
|
+
const date = new Date(raw);
|
|
682
|
+
if (!Number.isNaN(date.getTime())) {
|
|
683
|
+
const delayMs = date.getTime() - Date.now();
|
|
684
|
+
if (delayMs > 0) {
|
|
685
|
+
return delayMs;
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
return void 0;
|
|
689
|
+
}
|
|
690
|
+
async function readIncomingResponse(msg) {
|
|
691
|
+
const chunks = [];
|
|
692
|
+
for await (const chunk of msg) {
|
|
693
|
+
chunks.push(chunk);
|
|
694
|
+
}
|
|
695
|
+
const body = Buffer.concat(chunks);
|
|
696
|
+
const status = msg.statusCode ?? 0;
|
|
697
|
+
const statusText = msg.statusMessage ?? "";
|
|
698
|
+
return {
|
|
699
|
+
arrayBuffer: () => body.buffer.slice(
|
|
700
|
+
body.byteOffset,
|
|
701
|
+
body.byteOffset + body.byteLength
|
|
702
|
+
),
|
|
703
|
+
body,
|
|
704
|
+
headers: msg.headers,
|
|
705
|
+
json: () => JSON.parse(body.toString("utf8")),
|
|
706
|
+
ok: status >= 200 && status < 300,
|
|
707
|
+
rawResponse: msg,
|
|
708
|
+
status,
|
|
709
|
+
statusText,
|
|
710
|
+
text: () => body.toString("utf8")
|
|
711
|
+
};
|
|
712
|
+
}
|
|
713
|
+
function sanitizeHeaders(headers) {
|
|
714
|
+
if (!headers) {
|
|
715
|
+
return {};
|
|
716
|
+
}
|
|
717
|
+
const sensitiveHeaders = /* @__PURE__ */ new Set([
|
|
718
|
+
"authorization",
|
|
719
|
+
"cookie",
|
|
720
|
+
"proxy-authorization",
|
|
721
|
+
"proxy-authenticate",
|
|
722
|
+
"set-cookie",
|
|
723
|
+
"www-authenticate"
|
|
724
|
+
]);
|
|
725
|
+
const result = {
|
|
726
|
+
__proto__: null
|
|
727
|
+
};
|
|
728
|
+
for (const key of Object.keys(headers)) {
|
|
729
|
+
const value = headers[key];
|
|
730
|
+
if (sensitiveHeaders.has(key.toLowerCase())) {
|
|
731
|
+
result[key] = "[REDACTED]";
|
|
732
|
+
} else if (Array.isArray(value)) {
|
|
733
|
+
result[key] = value.join(", ");
|
|
734
|
+
} else if (value !== void 0 && value !== null) {
|
|
735
|
+
result[key] = String(value);
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
return result;
|
|
739
|
+
}
|
|
714
740
|
// Annotate the CommonJS export names for ESM import in node:
|
|
715
741
|
0 && (module.exports = {
|
|
716
742
|
HttpResponseError,
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Socket CLI child-process IPC object getter.
|
|
3
|
+
* Lazily builds an `IpcObject` from `SOCKET_CLI_*` environment variables so
|
|
4
|
+
* child processes can read flags and tokens forwarded by the parent Socket
|
|
5
|
+
* CLI without re-parsing `process.env` each call. Complements the filesystem
|
|
6
|
+
* stub IPC in `@socketsecurity/lib/ipc` (`getIpcStubPath`, `writeIpcStub`)
|
|
7
|
+
* for cases where data exceeds env-var size limits.
|
|
8
|
+
*/
|
|
9
|
+
export interface IpcObject {
|
|
10
|
+
SOCKET_CLI_FIX?: string | undefined;
|
|
11
|
+
SOCKET_CLI_OPTIMIZE?: boolean | undefined;
|
|
12
|
+
SOCKET_CLI_SHADOW_ACCEPT_RISKS?: boolean | undefined;
|
|
13
|
+
SOCKET_CLI_SHADOW_API_TOKEN?: string | undefined;
|
|
14
|
+
SOCKET_CLI_SHADOW_BIN?: string | undefined;
|
|
15
|
+
SOCKET_CLI_SHADOW_PROGRESS?: boolean | undefined;
|
|
16
|
+
SOCKET_CLI_SHADOW_SILENT?: boolean | undefined;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Get IPC data forwarded by a parent Socket CLI via `SOCKET_CLI_*` env vars.
|
|
20
|
+
* Call without arguments to receive the full frozen `IpcObject`, or pass a
|
|
21
|
+
* key to read a single field. The object is lazily built and cached; keys
|
|
22
|
+
* that weren't set in the environment are returned as `undefined`.
|
|
23
|
+
*
|
|
24
|
+
* @param key - Optional `IpcObject` field name to read
|
|
25
|
+
* @returns The full `IpcObject` or the value at `key` (possibly `undefined`).
|
|
26
|
+
*/
|
|
27
|
+
export declare function getIpc(): Promise<IpcObject>;
|
|
28
|
+
export declare function getIpc<K extends keyof IpcObject>(key: K): Promise<IpcObject[K]>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/* Socket Lib - Built with esbuild */
|
|
3
|
+
"use strict";
|
|
3
4
|
var __defProp = Object.defineProperty;
|
|
4
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
@@ -17,11 +18,11 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
18
|
return to;
|
|
18
19
|
};
|
|
19
20
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
-
var
|
|
21
|
-
__export(
|
|
21
|
+
var ipc_cli_exports = {};
|
|
22
|
+
__export(ipc_cli_exports, {
|
|
22
23
|
getIpc: () => getIpc
|
|
23
24
|
});
|
|
24
|
-
module.exports = __toCommonJS(
|
|
25
|
+
module.exports = __toCommonJS(ipc_cli_exports);
|
|
25
26
|
let _ipcObject;
|
|
26
27
|
async function getIpc(key) {
|
|
27
28
|
if (_ipcObject === void 0) {
|