@socketsecurity/cli-with-sentry 0.14.66 → 0.14.67
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/constants.d.ts +2 -0
- package/dist/constants.js +10 -2
- package/dist/constants.js.map +1 -1
- package/dist/instrument-with-sentry.js +2 -2
- package/dist/instrument-with-sentry.js.map +1 -1
- package/dist/module-sync/cli.js +872 -391
- package/dist/module-sync/cli.js.map +1 -1
- package/dist/module-sync/config.d.ts +19 -0
- package/dist/module-sync/path-resolve.d.ts +2 -2
- package/dist/module-sync/shadow-npm-inject.js +93 -83
- package/dist/module-sync/shadow-npm-inject.js.map +1 -1
- package/dist/module-sync/shadow-npm-paths.js +3 -3
- package/dist/module-sync/shadow-npm-paths.js.map +1 -1
- package/dist/require/cli.js +872 -391
- package/dist/require/cli.js.map +1 -1
- package/package.json +11 -11
- package/dist/module-sync/settings.d.ts +0 -15
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import config from '@socketsecurity/config';
|
|
2
|
+
interface LocalConfig {
|
|
3
|
+
apiBaseUrl?: string | null | undefined;
|
|
4
|
+
apiKey?: string | null | undefined;
|
|
5
|
+
apiProxy?: string | null | undefined;
|
|
6
|
+
apiToken?: string | null | undefined;
|
|
7
|
+
defaultOrg?: string;
|
|
8
|
+
enforcedOrgs?: string[] | readonly string[] | null | undefined;
|
|
9
|
+
test?: unknown;
|
|
10
|
+
}
|
|
11
|
+
declare const supportedConfigKeys: Map<keyof LocalConfig, string>;
|
|
12
|
+
declare const sensitiveConfigKeys: Set<keyof LocalConfig>;
|
|
13
|
+
declare function findSocketYmlSync(): {
|
|
14
|
+
path: string;
|
|
15
|
+
parsed: config.SocketYml;
|
|
16
|
+
} | null;
|
|
17
|
+
declare function getConfigValue<Key extends keyof LocalConfig>(key: Key): LocalConfig[Key];
|
|
18
|
+
declare function updateConfigValue<Key extends keyof LocalConfig>(key: keyof LocalConfig, value: LocalConfig[Key]): void;
|
|
19
|
+
export { LocalConfig, supportedConfigKeys, sensitiveConfigKeys, findSocketYmlSync, getConfigValue, updateConfigValue };
|
|
@@ -6,5 +6,5 @@ declare function findBinPathDetailsSync(binName: string): {
|
|
|
6
6
|
shadowed: boolean;
|
|
7
7
|
};
|
|
8
8
|
declare function findNpmPathSync(npmBinPath: string): string | undefined;
|
|
9
|
-
declare function
|
|
10
|
-
export { findBinPathDetailsSync, findNpmPathSync,
|
|
9
|
+
declare function getPackageFilesForScan(cwd: string, inputPaths: string[], supportedFiles: SocketSdkReturnType<'getReportSupportedFiles'>['data'], config?: SocketYml | undefined): Promise<string[]>;
|
|
10
|
+
export { findBinPathDetailsSync, findNpmPathSync, getPackageFilesForScan };
|
|
@@ -26,51 +26,17 @@ var isInteractive = require('@socketregistry/is-interactive/index.cjs');
|
|
|
26
26
|
var registryConstants = require('@socketsecurity/registry/lib/constants');
|
|
27
27
|
var strings = require('@socketsecurity/registry/lib/strings');
|
|
28
28
|
var sdk = require('@socketsecurity/sdk');
|
|
29
|
-
var promises = require('node:timers/promises');
|
|
30
29
|
var fs = require('node:fs');
|
|
31
30
|
var os = require('node:os');
|
|
32
31
|
var path = require('node:path');
|
|
33
32
|
var config = require('@socketsecurity/config');
|
|
33
|
+
var promises = require('node:timers/promises');
|
|
34
34
|
var packages = require('@socketsecurity/registry/lib/packages');
|
|
35
35
|
var sorts = require('@socketsecurity/registry/lib/sorts');
|
|
36
36
|
var terminalLink = _socketInterop(require('terminal-link'));
|
|
37
37
|
var colors = _socketInterop(require('yoctocolors-cjs'));
|
|
38
38
|
var indentString = require('@socketregistry/indent-string/index.cjs');
|
|
39
39
|
|
|
40
|
-
const {
|
|
41
|
-
kInternalsSymbol: kInternalsSymbol$1,
|
|
42
|
-
[kInternalsSymbol$1]: {
|
|
43
|
-
getSentry
|
|
44
|
-
}
|
|
45
|
-
} = constants;
|
|
46
|
-
class AuthError extends Error {}
|
|
47
|
-
class InputError extends Error {
|
|
48
|
-
constructor(message, body) {
|
|
49
|
-
super(message);
|
|
50
|
-
this.body = body;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
async function captureException(exception, hint) {
|
|
54
|
-
const result = captureExceptionSync(exception, hint);
|
|
55
|
-
// "Sleep" for a second, just in case, hopefully enough time to initiate fetch.
|
|
56
|
-
await promises.setTimeout(1000);
|
|
57
|
-
return result;
|
|
58
|
-
}
|
|
59
|
-
function captureExceptionSync(exception, hint) {
|
|
60
|
-
const Sentry = getSentry();
|
|
61
|
-
if (!Sentry) {
|
|
62
|
-
return '';
|
|
63
|
-
}
|
|
64
|
-
debug.debugLog('captureException: Sending exception to Sentry.');
|
|
65
|
-
return Sentry.captureException(exception, hint);
|
|
66
|
-
}
|
|
67
|
-
function isErrnoException(value) {
|
|
68
|
-
if (!(value instanceof Error)) {
|
|
69
|
-
return false;
|
|
70
|
-
}
|
|
71
|
-
return value.code !== undefined;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
40
|
const {
|
|
75
41
|
abortSignal
|
|
76
42
|
} = constants;
|
|
@@ -143,34 +109,36 @@ function safeReadFileSync(filepath, options) {
|
|
|
143
109
|
const LOCALAPPDATA = 'LOCALAPPDATA';
|
|
144
110
|
// Default app data folder env var on Mac/Linux
|
|
145
111
|
const XDG_DATA_HOME = 'XDG_DATA_HOME';
|
|
146
|
-
const SOCKET_APP_DIR = 'socket/settings';
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
let
|
|
112
|
+
const SOCKET_APP_DIR = 'socket/settings'; // It used to be settings...
|
|
113
|
+
|
|
114
|
+
const supportedConfigKeys = new Map([['apiBaseUrl', 'Base URL of the API endpoint'], ['apiToken', 'The API token required to access most API endpoints'], ['apiProxy', 'A proxy through which to access the API'], ['enforcedOrgs', 'Orgs in this list have their security policies enforced on this machine']]);
|
|
115
|
+
const sensitiveConfigKeys = new Set(['apiToken']);
|
|
116
|
+
let cachedConfig;
|
|
117
|
+
let configPath;
|
|
118
|
+
let warnedConfigPathWin32Missing = false;
|
|
151
119
|
let pendingSave = false;
|
|
152
|
-
function
|
|
153
|
-
if (
|
|
154
|
-
|
|
155
|
-
const
|
|
156
|
-
if (
|
|
157
|
-
const raw = safeReadFileSync(
|
|
120
|
+
function getConfigValues() {
|
|
121
|
+
if (cachedConfig === undefined) {
|
|
122
|
+
cachedConfig = {};
|
|
123
|
+
const configPath = getConfigPath();
|
|
124
|
+
if (configPath) {
|
|
125
|
+
const raw = safeReadFileSync(configPath);
|
|
158
126
|
if (raw) {
|
|
159
127
|
try {
|
|
160
|
-
Object.assign(
|
|
128
|
+
Object.assign(cachedConfig, JSON.parse(Buffer.from(raw, 'base64').toString()));
|
|
161
129
|
} catch {
|
|
162
|
-
logger.logger.warn(`Failed to parse
|
|
130
|
+
logger.logger.warn(`Failed to parse config at ${configPath}`);
|
|
163
131
|
}
|
|
164
132
|
} else {
|
|
165
|
-
fs.mkdirSync(path.dirname(
|
|
133
|
+
fs.mkdirSync(path.dirname(configPath), {
|
|
166
134
|
recursive: true
|
|
167
135
|
});
|
|
168
136
|
}
|
|
169
137
|
}
|
|
170
138
|
}
|
|
171
|
-
return
|
|
139
|
+
return cachedConfig;
|
|
172
140
|
}
|
|
173
|
-
function
|
|
141
|
+
function getConfigPath() {
|
|
174
142
|
// Get the OS app data folder:
|
|
175
143
|
// - Win: %LOCALAPPDATA% or fail?
|
|
176
144
|
// - Mac: %XDG_DATA_HOME% or fallback to "~/Library/Application Support/"
|
|
@@ -183,7 +151,7 @@ function getSettingsPath() {
|
|
|
183
151
|
// - Mac: %XDG_DATA_HOME%/socket/settings or "~/Library/Application Support/socket/settings"
|
|
184
152
|
// - Linux: %XDG_DATA_HOME%/socket/settings or "~/.local/share/socket/settings"
|
|
185
153
|
|
|
186
|
-
if (
|
|
154
|
+
if (configPath === undefined) {
|
|
187
155
|
// Lazily access constants.WIN32.
|
|
188
156
|
const {
|
|
189
157
|
WIN32
|
|
@@ -191,22 +159,22 @@ function getSettingsPath() {
|
|
|
191
159
|
let dataHome = WIN32 ? process$1.env[LOCALAPPDATA] : process$1.env[XDG_DATA_HOME];
|
|
192
160
|
if (!dataHome) {
|
|
193
161
|
if (WIN32) {
|
|
194
|
-
if (!
|
|
195
|
-
|
|
162
|
+
if (!warnedConfigPathWin32Missing) {
|
|
163
|
+
warnedConfigPathWin32Missing = true;
|
|
196
164
|
logger.logger.warn(`Missing %${LOCALAPPDATA}%`);
|
|
197
165
|
}
|
|
198
166
|
} else {
|
|
199
167
|
dataHome = path.join(os.homedir(), ...(process$1.platform === 'darwin' ? ['Library', 'Application Support'] : ['.local', 'share']));
|
|
200
168
|
}
|
|
201
169
|
}
|
|
202
|
-
|
|
170
|
+
configPath = dataHome ? path.join(dataHome, SOCKET_APP_DIR) : undefined;
|
|
203
171
|
}
|
|
204
|
-
return
|
|
172
|
+
return configPath;
|
|
205
173
|
}
|
|
206
|
-
function
|
|
174
|
+
function normalizeConfigKey(key) {
|
|
207
175
|
const normalizedKey = key === 'apiToken' ? 'apiKey' : key;
|
|
208
|
-
if (!
|
|
209
|
-
throw new Error(`Invalid
|
|
176
|
+
if (normalizedKey !== 'apiKey' && normalizedKey !== 'test' && !supportedConfigKeys.has(normalizedKey)) {
|
|
177
|
+
throw new Error(`Invalid config key: ${normalizedKey}`);
|
|
210
178
|
}
|
|
211
179
|
return normalizedKey;
|
|
212
180
|
}
|
|
@@ -235,37 +203,72 @@ function findSocketYmlSync() {
|
|
|
235
203
|
}
|
|
236
204
|
return null;
|
|
237
205
|
}
|
|
238
|
-
function
|
|
239
|
-
return
|
|
206
|
+
function getConfigValue(key) {
|
|
207
|
+
return getConfigValues()[normalizeConfigKey(key)];
|
|
240
208
|
}
|
|
241
|
-
function
|
|
242
|
-
const
|
|
243
|
-
|
|
209
|
+
function updateConfigValue(key, value) {
|
|
210
|
+
const localConfig = getConfigValues();
|
|
211
|
+
localConfig[normalizeConfigKey(key)] = value;
|
|
244
212
|
if (!pendingSave) {
|
|
245
213
|
pendingSave = true;
|
|
246
214
|
process$1.nextTick(() => {
|
|
247
215
|
pendingSave = false;
|
|
248
|
-
const
|
|
249
|
-
if (
|
|
250
|
-
fs.writeFileSync(
|
|
216
|
+
const configPath = getConfigPath();
|
|
217
|
+
if (configPath) {
|
|
218
|
+
fs.writeFileSync(configPath, Buffer.from(JSON.stringify(localConfig)).toString('base64'));
|
|
251
219
|
}
|
|
252
220
|
});
|
|
253
221
|
}
|
|
254
222
|
}
|
|
255
223
|
|
|
256
224
|
const {
|
|
257
|
-
|
|
225
|
+
kInternalsSymbol: kInternalsSymbol$1,
|
|
226
|
+
[kInternalsSymbol$1]: {
|
|
227
|
+
getSentry
|
|
228
|
+
}
|
|
229
|
+
} = constants;
|
|
230
|
+
class AuthError extends Error {}
|
|
231
|
+
class InputError extends Error {
|
|
232
|
+
constructor(message, body) {
|
|
233
|
+
super(message);
|
|
234
|
+
this.body = body;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
async function captureException(exception, hint) {
|
|
238
|
+
const result = captureExceptionSync(exception, hint);
|
|
239
|
+
// "Sleep" for a second, just in case, hopefully enough time to initiate fetch.
|
|
240
|
+
await promises.setTimeout(1000);
|
|
241
|
+
return result;
|
|
242
|
+
}
|
|
243
|
+
function captureExceptionSync(exception, hint) {
|
|
244
|
+
const Sentry = getSentry();
|
|
245
|
+
if (!Sentry) {
|
|
246
|
+
return '';
|
|
247
|
+
}
|
|
248
|
+
debug.debugLog('captureException: Sending exception to Sentry.');
|
|
249
|
+
return Sentry.captureException(exception, hint);
|
|
250
|
+
}
|
|
251
|
+
function isErrnoException(value) {
|
|
252
|
+
if (!(value instanceof Error)) {
|
|
253
|
+
return false;
|
|
254
|
+
}
|
|
255
|
+
return value.code !== undefined;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
const {
|
|
259
|
+
SOCKET_CLI_NO_API_TOKEN,
|
|
260
|
+
SOCKET_SECURITY_API_TOKEN
|
|
258
261
|
} = constants;
|
|
259
262
|
|
|
260
263
|
// The API server that should be used for operations.
|
|
261
264
|
function getDefaultApiBaseUrl() {
|
|
262
|
-
const baseUrl = process$1.env['SOCKET_SECURITY_API_BASE_URL'] ||
|
|
265
|
+
const baseUrl = process$1.env['SOCKET_SECURITY_API_BASE_URL'] || getConfigValue('apiBaseUrl');
|
|
263
266
|
return strings.isNonEmptyString(baseUrl) ? baseUrl : undefined;
|
|
264
267
|
}
|
|
265
268
|
|
|
266
269
|
// The API server that should be used for operations.
|
|
267
270
|
function getDefaultHttpProxy() {
|
|
268
|
-
const apiProxy = process$1.env['SOCKET_SECURITY_API_PROXY'] ||
|
|
271
|
+
const apiProxy = process$1.env['SOCKET_SECURITY_API_PROXY'] || getConfigValue('apiProxy');
|
|
269
272
|
return strings.isNonEmptyString(apiProxy) ? apiProxy : undefined;
|
|
270
273
|
}
|
|
271
274
|
|
|
@@ -276,16 +279,18 @@ function getDefaultToken() {
|
|
|
276
279
|
if (constants.ENV[SOCKET_CLI_NO_API_TOKEN]) {
|
|
277
280
|
_defaultToken = undefined;
|
|
278
281
|
} else {
|
|
279
|
-
const key =
|
|
280
|
-
//
|
|
281
|
-
|
|
282
|
-
process$1.env['SOCKET_SECURITY_API_KEY'] || getSetting('apiToken') || _defaultToken;
|
|
282
|
+
const key =
|
|
283
|
+
// Lazily access constants.ENV[SOCKET_SECURITY_API_TOKEN].
|
|
284
|
+
constants.ENV[SOCKET_SECURITY_API_TOKEN] || getConfigValue('apiToken') || _defaultToken;
|
|
283
285
|
_defaultToken = strings.isNonEmptyString(key) ? key : undefined;
|
|
284
286
|
}
|
|
285
287
|
return _defaultToken;
|
|
286
288
|
}
|
|
287
289
|
function getPublicToken() {
|
|
288
|
-
return (
|
|
290
|
+
return (
|
|
291
|
+
// Lazily access constants.ENV[SOCKET_SECURITY_API_TOKEN].
|
|
292
|
+
(constants.ENV[SOCKET_SECURITY_API_TOKEN] || getDefaultToken()) ?? registryConstants.SOCKET_PUBLIC_API_TOKEN
|
|
293
|
+
);
|
|
289
294
|
}
|
|
290
295
|
async function setupSdk(apiToken = getDefaultToken(), apiBaseUrl = getDefaultApiBaseUrl(), proxy = getDefaultHttpProxy()) {
|
|
291
296
|
if (typeof apiToken !== 'string' && isInteractive()) {
|
|
@@ -306,7 +311,7 @@ async function setupSdk(apiToken = getDefaultToken(), apiBaseUrl = getDefaultApi
|
|
|
306
311
|
// The '@rollup/plugin-replace' will replace "process.env['INLINED_SOCKET_CLI_NAME']".
|
|
307
312
|
name: "@socketsecurity/cli",
|
|
308
313
|
// The '@rollup/plugin-replace' will replace "process.env['INLINED_SOCKET_CLI_VERSION']".
|
|
309
|
-
version: "0.14.
|
|
314
|
+
version: "0.14.67",
|
|
310
315
|
// The '@rollup/plugin-replace' will replace "process.env['INLINED_SOCKET_CLI_HOMEPAGE']".
|
|
311
316
|
homepage: "https://github.com/SocketDev/socket-cli"
|
|
312
317
|
})
|
|
@@ -1213,7 +1218,7 @@ async function uxLookup(settings) {
|
|
|
1213
1218
|
}
|
|
1214
1219
|
})();
|
|
1215
1220
|
// Remove any organizations not being enforced.
|
|
1216
|
-
const enforcedOrgs =
|
|
1221
|
+
const enforcedOrgs = getConfigValue('enforcedOrgs') ?? [];
|
|
1217
1222
|
for (const {
|
|
1218
1223
|
0: i,
|
|
1219
1224
|
1: org
|
|
@@ -1638,7 +1643,10 @@ function getDetailsFromDiff(diff_, options) {
|
|
|
1638
1643
|
}
|
|
1639
1644
|
function getUrlOrigin(input) {
|
|
1640
1645
|
try {
|
|
1641
|
-
|
|
1646
|
+
// TODO: URL.parse is available in Node 22.1.0. We can use it when we drop Node 18.
|
|
1647
|
+
// https://nodejs.org/docs/latest-v22.x/api/url.html#urlparseinput-base
|
|
1648
|
+
// return URL.parse(input)?.origin ?? ''
|
|
1649
|
+
return new URL(input).origin ?? '';
|
|
1642
1650
|
} catch {}
|
|
1643
1651
|
return '';
|
|
1644
1652
|
}
|
|
@@ -1719,12 +1727,12 @@ async function getAlertsMapFromArborist(arb, options) {
|
|
|
1719
1727
|
return [key, overrideSet.value];
|
|
1720
1728
|
}));
|
|
1721
1729
|
}
|
|
1722
|
-
const
|
|
1730
|
+
const sockSdk = await setupSdk(getPublicToken());
|
|
1723
1731
|
const toAlertsMapOptions = {
|
|
1724
1732
|
overrides,
|
|
1725
1733
|
...options
|
|
1726
1734
|
};
|
|
1727
|
-
for await (const batchPackageFetchResult of
|
|
1735
|
+
for await (const batchPackageFetchResult of sockSdk.batchPackageStream({
|
|
1728
1736
|
alerts: 'true',
|
|
1729
1737
|
compact: 'true',
|
|
1730
1738
|
fixable: include.unfixable ? 'false' : 'true'
|
|
@@ -1936,18 +1944,20 @@ exports.findPackageNodes = findPackageNodes;
|
|
|
1936
1944
|
exports.findUp = findUp;
|
|
1937
1945
|
exports.formatSeverityCount = formatSeverityCount;
|
|
1938
1946
|
exports.getAlertsMapFromArborist = getAlertsMapFromArborist;
|
|
1947
|
+
exports.getConfigValue = getConfigValue;
|
|
1939
1948
|
exports.getCveInfoByAlertsMap = getCveInfoByAlertsMap;
|
|
1940
1949
|
exports.getDefaultToken = getDefaultToken;
|
|
1941
1950
|
exports.getPublicToken = getPublicToken;
|
|
1942
|
-
exports.getSetting = getSetting;
|
|
1943
1951
|
exports.getSeverityCount = getSeverityCount;
|
|
1944
1952
|
exports.getSocketDevAlertUrl = getSocketDevAlertUrl;
|
|
1945
1953
|
exports.getSocketDevPackageOverviewUrl = getSocketDevPackageOverviewUrl;
|
|
1946
1954
|
exports.readFileBinary = readFileBinary;
|
|
1947
1955
|
exports.readFileUtf8 = readFileUtf8;
|
|
1948
1956
|
exports.safeReadFile = safeReadFile;
|
|
1957
|
+
exports.sensitiveConfigKeys = sensitiveConfigKeys;
|
|
1949
1958
|
exports.setupSdk = setupSdk;
|
|
1959
|
+
exports.supportedConfigKeys = supportedConfigKeys;
|
|
1960
|
+
exports.updateConfigValue = updateConfigValue;
|
|
1950
1961
|
exports.updateNode = updateNode;
|
|
1951
|
-
|
|
1952
|
-
//# debugId=86178861-a8cc-486b-ac92-f49e627e80af
|
|
1962
|
+
//# debugId=be8eae0e-badd-401f-9719-bf4c7157004d
|
|
1953
1963
|
//# sourceMappingURL=shadow-npm-inject.js.map
|