@socketsecurity/cli 0.14.39 → 0.14.41
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 +1 -1
- package/bin/cli.js +12 -6
- package/dist/{module-sync/constants.d.ts → constants.d.ts} +13 -2
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +24 -10
- package/dist/module-sync/cli.js +455 -404
- package/dist/module-sync/debug.d.ts +3 -0
- package/dist/module-sync/errors.d.ts +3 -1
- package/dist/module-sync/logging.d.ts +16 -0
- package/dist/module-sync/npm-injection.js +1119 -1095
- package/dist/module-sync/path-resolve.d.ts +1 -1
- package/dist/module-sync/path-resolve.js +50 -5
- package/dist/module-sync/settings.d.ts +6 -1
- package/dist/module-sync/shadow-bin.d.ts +2 -2
- package/dist/module-sync/shadow-bin.js +23 -40
- package/dist/module-sync/socket-url.d.ts +40 -0
- package/dist/module-sync/socket-url.js +301 -0
- package/dist/require/cli.js +454 -401
- package/dist/require/npm-injection.js +2 -1511
- package/dist/require/path-resolve.js +2 -200
- package/dist/require/shadow-bin.js +2 -102
- package/dist/require/socket-url.js +3 -0
- package/dist/require/vendor.js +53 -400
- package/package.json +39 -31
- package/dist/module-sync/color-or-markdown.d.ts +0 -23
- package/dist/module-sync/constants.d.ts.map +0 -1
- package/dist/module-sync/sdk.d.ts +0 -8
- package/dist/module-sync/sdk.js +0 -214
- package/dist/require/constants.d.ts.map +0 -1
- package/dist/require/sdk.js +0 -212
package/dist/require/cli.js
CHANGED
|
@@ -10,6 +10,7 @@ function _socketInterop(e) {
|
|
|
10
10
|
return c ? e.default : e
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
var process$1 = require('node:process');
|
|
13
14
|
var require$$0 = require('node:url');
|
|
14
15
|
var ponyCause = _socketInterop(require('pony-cause'));
|
|
15
16
|
var vendor = require('./vendor.js');
|
|
@@ -20,41 +21,44 @@ var yargsParse = _socketInterop(require('yargs-parser'));
|
|
|
20
21
|
var npm$1 = require('@socketsecurity/registry/lib/npm');
|
|
21
22
|
var words = require('@socketsecurity/registry/lib/words');
|
|
22
23
|
var constants = require('./constants.js');
|
|
23
|
-
var
|
|
24
|
-
var sdk = require('./sdk.js');
|
|
25
|
-
var prompts = require('@socketsecurity/registry/lib/prompts');
|
|
26
|
-
var fs$1 = require('node:fs/promises');
|
|
24
|
+
var spinner = require('@socketsecurity/registry/lib/spinner');
|
|
27
25
|
var spawn = _socketInterop(require('@npmcli/promise-spawn'));
|
|
26
|
+
var objects = require('@socketsecurity/registry/lib/objects');
|
|
27
|
+
var pathResolve = require('./path-resolve.js');
|
|
28
|
+
var registryConstants = require('@socketsecurity/registry/lib/constants');
|
|
29
|
+
var socketUrl = require('./socket-url.js');
|
|
30
|
+
var terminalLink = _socketInterop(require('terminal-link'));
|
|
31
|
+
var isInteractive = require('@socketregistry/is-interactive/index.cjs');
|
|
32
|
+
var prompts = require('@socketsecurity/registry/lib/prompts');
|
|
28
33
|
var npa = _socketInterop(require('npm-package-arg'));
|
|
29
34
|
var semver = _socketInterop(require('semver'));
|
|
30
35
|
var tinyglobby = _socketInterop(require('tinyglobby'));
|
|
31
36
|
var yaml = _socketInterop(require('yaml'));
|
|
32
37
|
var registry = require('@socketsecurity/registry');
|
|
33
|
-
var objects = require('@socketsecurity/registry/lib/objects');
|
|
34
38
|
var packages = require('@socketsecurity/registry/lib/packages');
|
|
35
39
|
var promises = require('@socketsecurity/registry/lib/promises');
|
|
36
40
|
var regexps = require('@socketsecurity/registry/lib/regexps');
|
|
37
41
|
var strings = require('@socketsecurity/registry/lib/strings');
|
|
38
42
|
var browserslist = _socketInterop(require('browserslist'));
|
|
39
43
|
var which = _socketInterop(require('which'));
|
|
40
|
-
var
|
|
41
|
-
var
|
|
44
|
+
var index_cjs = require('@socketregistry/hyrious__bun.lockb/index.cjs');
|
|
45
|
+
var sorts = require('@socketsecurity/registry/lib/sorts');
|
|
42
46
|
var betterAjvErrors = _socketInterop(require('@apideck/better-ajv-errors'));
|
|
43
47
|
var config = require('@socketsecurity/config');
|
|
44
48
|
var os = require('node:os');
|
|
45
49
|
var readline = require('node:readline');
|
|
46
|
-
var process$1 = require('node:process');
|
|
47
50
|
var readline$1 = require('node:readline/promises');
|
|
48
51
|
var chalkTable = _socketInterop(require('chalk-table'));
|
|
52
|
+
var fs$1 = require('node:fs/promises');
|
|
49
53
|
var ScreenWidget = _socketInterop(require('blessed/lib/widgets/screen'));
|
|
50
|
-
var BarChart = _socketInterop(require('blessed-contrib/lib/widget/charts/bar'));
|
|
51
54
|
var GridLayout = _socketInterop(require('blessed-contrib/lib/layout/grid'));
|
|
55
|
+
var BarChart = _socketInterop(require('blessed-contrib/lib/widget/charts/bar'));
|
|
52
56
|
var LineChart = _socketInterop(require('blessed-contrib/lib/widget/charts/line'));
|
|
53
57
|
var require$$0$1 = require('node:util');
|
|
54
58
|
var TableWidget = _socketInterop(require('blessed-contrib/lib/widget/table'));
|
|
55
59
|
|
|
56
60
|
const {
|
|
57
|
-
NPM: NPM$
|
|
61
|
+
NPM: NPM$5,
|
|
58
62
|
PNPM: PNPM$2,
|
|
59
63
|
cdxgenBinPath,
|
|
60
64
|
synpBinPath
|
|
@@ -65,10 +69,10 @@ const {
|
|
|
65
69
|
SBOM_SIGN_PRIVATE_KEY,
|
|
66
70
|
// Location to the RSA private key
|
|
67
71
|
SBOM_SIGN_PUBLIC_KEY // Optional. Location to the RSA public key
|
|
68
|
-
} = process.env;
|
|
72
|
+
} = process$1.env;
|
|
69
73
|
const toLower = arg => arg.toLowerCase();
|
|
70
74
|
const arrayToLower = arg => arg.map(toLower);
|
|
71
|
-
const nodejsPlatformTypes = new Set(['javascript', 'js', 'nodejs', NPM$
|
|
75
|
+
const nodejsPlatformTypes = new Set(['javascript', 'js', 'nodejs', NPM$5, PNPM$2, 'ts', 'tsx', 'typescript']);
|
|
72
76
|
const yargsConfig = {
|
|
73
77
|
configuration: {
|
|
74
78
|
'camel-case-expansion': false,
|
|
@@ -172,20 +176,20 @@ const cdxgen = {
|
|
|
172
176
|
length: unknownLength
|
|
173
177
|
} = unknown;
|
|
174
178
|
if (unknownLength) {
|
|
179
|
+
process$1.exitCode = 1;
|
|
175
180
|
console.error(`Unknown ${words.pluralize('argument', unknownLength)}: ${yargv._.join(', ')}`);
|
|
176
|
-
process.exitCode = 1;
|
|
177
181
|
return;
|
|
178
182
|
}
|
|
179
183
|
let cleanupPackageLock = false;
|
|
180
184
|
if (yargv.type !== 'yarn' && nodejsPlatformTypes.has(yargv.type) && fs.existsSync('./yarn.lock')) {
|
|
181
185
|
if (fs.existsSync('./package-lock.json')) {
|
|
182
|
-
yargv.type = NPM$
|
|
186
|
+
yargv.type = NPM$5;
|
|
183
187
|
} else {
|
|
184
188
|
// Use synp to create a package-lock.json from the yarn.lock,
|
|
185
189
|
// based on the node_modules folder, for a more accurate SBOM.
|
|
186
190
|
try {
|
|
187
191
|
await npm$1.runBin(await fs.promises.realpath(synpBinPath), ['--source-file', './yarn.lock']);
|
|
188
|
-
yargv.type = NPM$
|
|
192
|
+
yargv.type = NPM$5;
|
|
189
193
|
cleanupPackageLock = true;
|
|
190
194
|
} catch {}
|
|
191
195
|
}
|
|
@@ -207,13 +211,82 @@ const cdxgen = {
|
|
|
207
211
|
await fs.promises.rm('./package-lock.json');
|
|
208
212
|
} catch {}
|
|
209
213
|
}
|
|
210
|
-
const fullOutputPath = path.join(process.cwd(), yargv.output);
|
|
214
|
+
const fullOutputPath = path.join(process$1.cwd(), yargv.output);
|
|
211
215
|
if (fs.existsSync(fullOutputPath)) {
|
|
212
216
|
console.log(colors.cyanBright(`${yargv.output} created!`));
|
|
213
217
|
}
|
|
214
218
|
}
|
|
215
219
|
};
|
|
216
220
|
|
|
221
|
+
const {
|
|
222
|
+
abortSignal: abortSignal$3
|
|
223
|
+
} = constants;
|
|
224
|
+
function shadowNpmInstall(opts) {
|
|
225
|
+
const {
|
|
226
|
+
flags = [],
|
|
227
|
+
ipc,
|
|
228
|
+
...spawnOptions
|
|
229
|
+
} = {
|
|
230
|
+
__proto__: null,
|
|
231
|
+
...opts
|
|
232
|
+
};
|
|
233
|
+
const useIpc = objects.isObject(ipc);
|
|
234
|
+
const useDebug = pathResolve.isDebug();
|
|
235
|
+
const promise = spawn(
|
|
236
|
+
// Lazily access constants.execPath.
|
|
237
|
+
constants.execPath, [
|
|
238
|
+
// Lazily access constants.rootBinPath.
|
|
239
|
+
path.join(constants.rootBinPath, 'npm-cli.js'), 'install',
|
|
240
|
+
// Even though the '--silent' flag is passed npm will still run through
|
|
241
|
+
// code paths for 'audit' and 'fund' unless '--no-audit' and '--no-fund'
|
|
242
|
+
// flags are passed.
|
|
243
|
+
...(useDebug ? ['--no-audit', '--no-fund'] : ['--silent', '--no-audit', '--no-fund']), ...flags], {
|
|
244
|
+
signal: abortSignal$3,
|
|
245
|
+
// Set stdio to include 'ipc'.
|
|
246
|
+
// See https://github.com/nodejs/node/blob/v23.6.0/lib/child_process.js#L161-L166
|
|
247
|
+
// and https://github.com/nodejs/node/blob/v23.6.0/lib/internal/child_process.js#L238.
|
|
248
|
+
stdio: useDebug ?
|
|
249
|
+
// 'inherit'
|
|
250
|
+
useIpc ? [0, 1, 2, 'ipc'] : 'inherit' :
|
|
251
|
+
// 'ignore'
|
|
252
|
+
useIpc ? ['ignore', 'ignore', 'ignore', 'ipc'] : 'ignore',
|
|
253
|
+
...spawnOptions,
|
|
254
|
+
env: {
|
|
255
|
+
...process$1.env,
|
|
256
|
+
...spawnOptions.env
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
if (useIpc) {
|
|
260
|
+
promise.process.send(ipc);
|
|
261
|
+
}
|
|
262
|
+
return promise;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
const {
|
|
266
|
+
SOCKET_CLI_FIX_PACKAGE_LOCK_FILE,
|
|
267
|
+
SOCKET_IPC_HANDSHAKE: SOCKET_IPC_HANDSHAKE$1
|
|
268
|
+
} = constants;
|
|
269
|
+
const fix = {
|
|
270
|
+
description: 'Fix "fixable" Socket alerts',
|
|
271
|
+
hidden: true,
|
|
272
|
+
async run() {
|
|
273
|
+
const spinner$1 = new spinner.Spinner().start();
|
|
274
|
+
try {
|
|
275
|
+
await shadowNpmInstall({
|
|
276
|
+
ipc: {
|
|
277
|
+
[SOCKET_IPC_HANDSHAKE$1]: {
|
|
278
|
+
[SOCKET_CLI_FIX_PACKAGE_LOCK_FILE]: true
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
} catch (e) {
|
|
283
|
+
console.error(e);
|
|
284
|
+
} finally {
|
|
285
|
+
spinner$1.stop();
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
|
|
217
290
|
const commonFlags = {
|
|
218
291
|
help: {
|
|
219
292
|
type: 'boolean',
|
|
@@ -261,47 +334,6 @@ const validationFlags = {
|
|
|
261
334
|
}
|
|
262
335
|
};
|
|
263
336
|
|
|
264
|
-
const {
|
|
265
|
-
API_V0_URL
|
|
266
|
-
} = constants;
|
|
267
|
-
function handleUnsuccessfulApiResponse(_name, result, spinner) {
|
|
268
|
-
// SocketSdkErrorType['error'] is not typed.
|
|
269
|
-
const resultErrorMessage = result.error?.message;
|
|
270
|
-
const message = typeof resultErrorMessage === 'string' ? resultErrorMessage : 'No error message returned';
|
|
271
|
-
if (result.status === 401 || result.status === 403) {
|
|
272
|
-
spinner.stop();
|
|
273
|
-
throw new sdk.AuthError(message);
|
|
274
|
-
}
|
|
275
|
-
spinner.error(`${colors.bgRed(colors.white('API returned an error:'))} ${message}`);
|
|
276
|
-
process.exit(1);
|
|
277
|
-
}
|
|
278
|
-
async function handleApiCall(value, description) {
|
|
279
|
-
let result;
|
|
280
|
-
try {
|
|
281
|
-
result = await value;
|
|
282
|
-
} catch (cause) {
|
|
283
|
-
throw new ponyCause.ErrorWithCause(`Failed ${description}`, {
|
|
284
|
-
cause
|
|
285
|
-
});
|
|
286
|
-
}
|
|
287
|
-
return result;
|
|
288
|
-
}
|
|
289
|
-
async function handleAPIError(code) {
|
|
290
|
-
if (code === 400) {
|
|
291
|
-
return 'One of the options passed might be incorrect.';
|
|
292
|
-
} else if (code === 403) {
|
|
293
|
-
return 'You might be trying to access an organization that is not linked to the API key you are logged in with.';
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
async function queryAPI(path, apiKey) {
|
|
297
|
-
return await fetch(`${API_V0_URL}/${path}`, {
|
|
298
|
-
method: 'GET',
|
|
299
|
-
headers: {
|
|
300
|
-
Authorization: `Basic ${btoa(`${apiKey}:${apiKey}`)}`
|
|
301
|
-
}
|
|
302
|
-
});
|
|
303
|
-
}
|
|
304
|
-
|
|
305
337
|
function objectSome(obj) {
|
|
306
338
|
for (const key in obj) {
|
|
307
339
|
if (obj[key]) {
|
|
@@ -318,6 +350,22 @@ function pick(input, keys) {
|
|
|
318
350
|
return result;
|
|
319
351
|
}
|
|
320
352
|
|
|
353
|
+
function stringJoinWithSeparateFinalSeparator(list, separator = ' and ') {
|
|
354
|
+
const values = list.filter(Boolean);
|
|
355
|
+
const {
|
|
356
|
+
length
|
|
357
|
+
} = values;
|
|
358
|
+
if (!length) {
|
|
359
|
+
return '';
|
|
360
|
+
}
|
|
361
|
+
if (length === 1) {
|
|
362
|
+
return values[0];
|
|
363
|
+
}
|
|
364
|
+
const finalValue = values.pop();
|
|
365
|
+
return `${values.join(', ')}${separator}${finalValue}`;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
// Ordered from most severe to least.
|
|
321
369
|
const SEVERITIES_BY_ORDER = ['critical', 'high', 'middle', 'low'];
|
|
322
370
|
function getDesiredSeverities(lowestToInclude) {
|
|
323
371
|
const result = [];
|
|
@@ -336,7 +384,7 @@ function formatSeverityCount(severityCount) {
|
|
|
336
384
|
summary.push(`${severityCount[severity]} ${severity}`);
|
|
337
385
|
}
|
|
338
386
|
}
|
|
339
|
-
return
|
|
387
|
+
return stringJoinWithSeparateFinalSeparator(summary);
|
|
340
388
|
}
|
|
341
389
|
function getSeverityCount(issues, lowestToInclude) {
|
|
342
390
|
const severityCount = pick({
|
|
@@ -346,7 +394,9 @@ function getSeverityCount(issues, lowestToInclude) {
|
|
|
346
394
|
critical: 0
|
|
347
395
|
}, getDesiredSeverities(lowestToInclude));
|
|
348
396
|
for (const issue of issues) {
|
|
349
|
-
const
|
|
397
|
+
const {
|
|
398
|
+
value
|
|
399
|
+
} = issue;
|
|
350
400
|
if (!value) {
|
|
351
401
|
continue;
|
|
352
402
|
}
|
|
@@ -357,18 +407,59 @@ function getSeverityCount(issues, lowestToInclude) {
|
|
|
357
407
|
return severityCount;
|
|
358
408
|
}
|
|
359
409
|
|
|
360
|
-
|
|
410
|
+
const {
|
|
411
|
+
API_V0_URL
|
|
412
|
+
} = constants;
|
|
413
|
+
function handleUnsuccessfulApiResponse(_name, result, spinner) {
|
|
414
|
+
// SocketSdkErrorType['error'] is not typed.
|
|
415
|
+
const resultErrorMessage = result.error?.message;
|
|
416
|
+
const message = typeof resultErrorMessage === 'string' ? resultErrorMessage : 'No error message returned';
|
|
417
|
+
if (result.status === 401 || result.status === 403) {
|
|
418
|
+
spinner.stop();
|
|
419
|
+
throw new socketUrl.AuthError(message);
|
|
420
|
+
}
|
|
421
|
+
spinner.error(`${colors.bgRed(colors.white('API returned an error:'))} ${message}`);
|
|
422
|
+
process$1.exit(1);
|
|
423
|
+
}
|
|
424
|
+
async function handleApiCall(value, description) {
|
|
425
|
+
let result;
|
|
426
|
+
try {
|
|
427
|
+
result = await value;
|
|
428
|
+
} catch (cause) {
|
|
429
|
+
throw new ponyCause.ErrorWithCause(`Failed ${description}`, {
|
|
430
|
+
cause
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
return result;
|
|
434
|
+
}
|
|
435
|
+
async function handleAPIError(code) {
|
|
436
|
+
if (code === 400) {
|
|
437
|
+
return 'One of the options passed might be incorrect.';
|
|
438
|
+
} else if (code === 403) {
|
|
439
|
+
return 'You might be trying to access an organization that is not linked to the API key you are logged in with.';
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
async function queryAPI(path, apiKey) {
|
|
443
|
+
return await fetch(`${API_V0_URL}/${path}`, {
|
|
444
|
+
method: 'GET',
|
|
445
|
+
headers: {
|
|
446
|
+
Authorization: `Basic ${btoa(`${apiKey}:${apiKey}`)}`
|
|
447
|
+
}
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
function getFlagListOutput(list, indent, {
|
|
361
452
|
keyPrefix = '--',
|
|
362
453
|
padName
|
|
363
454
|
} = {}) {
|
|
364
|
-
return
|
|
455
|
+
return getHelpListOutput({
|
|
365
456
|
...list
|
|
366
457
|
}, indent, {
|
|
367
458
|
keyPrefix,
|
|
368
459
|
padName
|
|
369
460
|
});
|
|
370
461
|
}
|
|
371
|
-
function
|
|
462
|
+
function getHelpListOutput(list, indent, {
|
|
372
463
|
keyPrefix = '',
|
|
373
464
|
padName = 18
|
|
374
465
|
} = {}) {
|
|
@@ -383,8 +474,8 @@ function printHelpList(list, indent, {
|
|
|
383
474
|
}
|
|
384
475
|
|
|
385
476
|
const {
|
|
386
|
-
|
|
387
|
-
} =
|
|
477
|
+
NPM: NPM$4
|
|
478
|
+
} = registryConstants;
|
|
388
479
|
const info = {
|
|
389
480
|
description: 'Look up info regarding a package',
|
|
390
481
|
async run(argv, importMeta, {
|
|
@@ -394,15 +485,15 @@ const info = {
|
|
|
394
485
|
const commandContext = setupCommand$m(name, info.description, argv, importMeta);
|
|
395
486
|
if (commandContext) {
|
|
396
487
|
const spinnerText = commandContext.pkgVersion === 'latest' ? `Looking up data for the latest version of ${commandContext.pkgName}` : `Looking up data for version ${commandContext.pkgVersion} of ${commandContext.pkgName}`;
|
|
397
|
-
const spinner =
|
|
488
|
+
const spinner$1 = new spinner.Spinner({
|
|
398
489
|
text: spinnerText
|
|
399
490
|
}).start();
|
|
400
|
-
const packageData = await fetchPackageData(commandContext.pkgName, commandContext.pkgVersion, commandContext, spinner);
|
|
491
|
+
const packageData = await fetchPackageData(commandContext.pkgName, commandContext.pkgVersion, commandContext, spinner$1);
|
|
401
492
|
if (packageData) {
|
|
402
493
|
formatPackageDataOutput(packageData, {
|
|
403
494
|
name,
|
|
404
495
|
...commandContext
|
|
405
|
-
}, spinner);
|
|
496
|
+
}, spinner$1);
|
|
406
497
|
}
|
|
407
498
|
}
|
|
408
499
|
}
|
|
@@ -421,7 +512,7 @@ function setupCommand$m(name, description, argv, importMeta) {
|
|
|
421
512
|
$ ${name} <name>
|
|
422
513
|
|
|
423
514
|
Options
|
|
424
|
-
${
|
|
515
|
+
${getFlagListOutput(flags, 6)}
|
|
425
516
|
|
|
426
517
|
Examples
|
|
427
518
|
$ ${name} webtorrent
|
|
@@ -433,7 +524,7 @@ function setupCommand$m(name, description, argv, importMeta) {
|
|
|
433
524
|
flags
|
|
434
525
|
});
|
|
435
526
|
if (cli.input.length > 1) {
|
|
436
|
-
throw new
|
|
527
|
+
throw new socketUrl.InputError('Only one package lookup supported at once');
|
|
437
528
|
}
|
|
438
529
|
const {
|
|
439
530
|
0: rawPkgName = ''
|
|
@@ -461,7 +552,7 @@ function setupCommand$m(name, description, argv, importMeta) {
|
|
|
461
552
|
async function fetchPackageData(pkgName, pkgVersion, {
|
|
462
553
|
includeAllIssues
|
|
463
554
|
}, spinner) {
|
|
464
|
-
const socketSdk = await
|
|
555
|
+
const socketSdk = await socketUrl.setupSdk(socketUrl.getPublicToken());
|
|
465
556
|
const result = await handleApiCall(socketSdk.getIssuesByNPMPackage(pkgName, pkgVersion), 'looking up package');
|
|
466
557
|
const scoreResult = await handleApiCall(socketSdk.getScoreByNPMPackage(pkgName, pkgVersion), 'looking up package score');
|
|
467
558
|
if (result.success === false) {
|
|
@@ -508,8 +599,8 @@ function formatPackageDataOutput({
|
|
|
508
599
|
} else {
|
|
509
600
|
spinner.success('Package has no issues');
|
|
510
601
|
}
|
|
511
|
-
const format = new
|
|
512
|
-
const url =
|
|
602
|
+
const format = new socketUrl.ColorOrMarkdown(!!outputMarkdown);
|
|
603
|
+
const url = socketUrl.getSocketDevPackageOverviewUrl(NPM$4, pkgName, pkgVersion);
|
|
513
604
|
console.log('\n');
|
|
514
605
|
if (pkgVersion === 'latest') {
|
|
515
606
|
console.log(`Detailed info on socket.dev: ${format.hyperlink(`${pkgName}`, url, {
|
|
@@ -525,7 +616,7 @@ function formatPackageDataOutput({
|
|
|
525
616
|
}
|
|
526
617
|
}
|
|
527
618
|
if (strict && objectSome(severityCount)) {
|
|
528
|
-
process.exit(1);
|
|
619
|
+
process$1.exit(1);
|
|
529
620
|
}
|
|
530
621
|
}
|
|
531
622
|
function formatPackageIssuesDetails(packageData, outputMarkdown) {
|
|
@@ -546,9 +637,9 @@ function formatPackageIssuesDetails(packageData, outputMarkdown) {
|
|
|
546
637
|
}
|
|
547
638
|
return acc;
|
|
548
639
|
}, {});
|
|
549
|
-
const format = new
|
|
640
|
+
const format = new socketUrl.ColorOrMarkdown(!!outputMarkdown);
|
|
550
641
|
for (const issue of Object.keys(uniqueIssues)) {
|
|
551
|
-
const issueWithLink = format.hyperlink(`${uniqueIssues[issue]?.label}`,
|
|
642
|
+
const issueWithLink = format.hyperlink(`${uniqueIssues[issue]?.label}`, socketUrl.getSocketDevAlertUrl(issue), {
|
|
552
643
|
fallbackToUrl: true
|
|
553
644
|
});
|
|
554
645
|
if (uniqueIssues[issue]?.count === 1) {
|
|
@@ -568,7 +659,7 @@ function formatScore(score) {
|
|
|
568
659
|
}
|
|
569
660
|
|
|
570
661
|
const {
|
|
571
|
-
|
|
662
|
+
SOCKET_PUBLIC_API_TOKEN
|
|
572
663
|
} = constants;
|
|
573
664
|
const description$5 = 'Socket API login';
|
|
574
665
|
const flags = {
|
|
@@ -597,7 +688,7 @@ const login = {
|
|
|
597
688
|
Logs into the Socket API by prompting for an API key
|
|
598
689
|
|
|
599
690
|
Options
|
|
600
|
-
${
|
|
691
|
+
${getFlagListOutput({
|
|
601
692
|
'api-base-url': flags['apiBaseUrl'].description,
|
|
602
693
|
'api-proxy': flags['apiProxy'].description
|
|
603
694
|
}, 8)}
|
|
@@ -618,30 +709,30 @@ const login = {
|
|
|
618
709
|
cli.showHelp();
|
|
619
710
|
return;
|
|
620
711
|
}
|
|
621
|
-
if (!
|
|
622
|
-
throw new
|
|
712
|
+
if (!isInteractive()) {
|
|
713
|
+
throw new socketUrl.InputError('Cannot prompt for credentials in a non-interactive shell');
|
|
623
714
|
}
|
|
624
|
-
const
|
|
625
|
-
message: `Enter your ${
|
|
626
|
-
})) ||
|
|
715
|
+
const apiToken = (await prompts.password({
|
|
716
|
+
message: `Enter your ${terminalLink('Socket.dev API key', 'https://docs.socket.dev/docs/api-keys')} (leave blank for a public key)`
|
|
717
|
+
})) || SOCKET_PUBLIC_API_TOKEN;
|
|
627
718
|
let apiBaseUrl = cli.flags['apiBaseUrl'];
|
|
628
|
-
apiBaseUrl ??=
|
|
719
|
+
apiBaseUrl ??= socketUrl.getSetting('apiBaseUrl') ?? undefined;
|
|
629
720
|
let apiProxy = cli.flags['apiProxy'];
|
|
630
|
-
apiProxy ??=
|
|
631
|
-
const spinner =
|
|
721
|
+
apiProxy ??= socketUrl.getSetting('apiProxy') ?? undefined;
|
|
722
|
+
const spinner$1 = new spinner.Spinner({
|
|
632
723
|
text: 'Verifying API key...'
|
|
633
724
|
}).start();
|
|
634
725
|
let orgs;
|
|
635
726
|
try {
|
|
636
|
-
const sdk
|
|
637
|
-
const result = await sdk
|
|
727
|
+
const sdk = await socketUrl.setupSdk(apiToken, apiBaseUrl, apiProxy);
|
|
728
|
+
const result = await sdk.getOrganizations();
|
|
638
729
|
if (!result.success) {
|
|
639
|
-
throw new
|
|
730
|
+
throw new socketUrl.AuthError();
|
|
640
731
|
}
|
|
641
732
|
orgs = result.data;
|
|
642
|
-
spinner.success('API key verified');
|
|
733
|
+
spinner$1.success('API key verified');
|
|
643
734
|
} catch {
|
|
644
|
-
spinner.error('Invalid API key');
|
|
735
|
+
spinner$1.error('Invalid API key');
|
|
645
736
|
return;
|
|
646
737
|
}
|
|
647
738
|
const enforcedChoices = Object.values(orgs.organizations).filter(nonNullish).filter(org => org.plan === 'enterprise').map(org => ({
|
|
@@ -673,12 +764,13 @@ const login = {
|
|
|
673
764
|
}
|
|
674
765
|
}
|
|
675
766
|
}
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
767
|
+
socketUrl.updateSetting('enforcedOrgs', enforcedOrgs);
|
|
768
|
+
// TODO: Rename the 'apiKey' setting to 'apiToken'.
|
|
769
|
+
const oldToken = socketUrl.getSetting('apiKey');
|
|
770
|
+
socketUrl.updateSetting('apiKey', apiToken);
|
|
771
|
+
socketUrl.updateSetting('apiBaseUrl', apiBaseUrl);
|
|
772
|
+
socketUrl.updateSetting('apiProxy', apiProxy);
|
|
773
|
+
spinner$1.success(`API credentials ${oldToken ? 'updated' : 'set'}`);
|
|
682
774
|
}
|
|
683
775
|
};
|
|
684
776
|
|
|
@@ -710,11 +802,11 @@ const logout = {
|
|
|
710
802
|
cli.showHelp();
|
|
711
803
|
return;
|
|
712
804
|
}
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
805
|
+
socketUrl.updateSetting('apiKey', null);
|
|
806
|
+
socketUrl.updateSetting('apiBaseUrl', null);
|
|
807
|
+
socketUrl.updateSetting('apiProxy', null);
|
|
808
|
+
socketUrl.updateSetting('enforcedOrgs', null);
|
|
809
|
+
new spinner.Spinner().success('Successfully logged out');
|
|
718
810
|
}
|
|
719
811
|
};
|
|
720
812
|
|
|
@@ -742,48 +834,6 @@ const npx = {
|
|
|
742
834
|
}
|
|
743
835
|
};
|
|
744
836
|
|
|
745
|
-
function existsSync(filepath) {
|
|
746
|
-
try {
|
|
747
|
-
return filepath ? fs.existsSync(filepath) : false;
|
|
748
|
-
} catch {}
|
|
749
|
-
return false;
|
|
750
|
-
}
|
|
751
|
-
async function findUp(name, {
|
|
752
|
-
cwd = process.cwd()
|
|
753
|
-
}) {
|
|
754
|
-
let dir = path.resolve(cwd);
|
|
755
|
-
const {
|
|
756
|
-
root
|
|
757
|
-
} = path.parse(dir);
|
|
758
|
-
const names = [name].flat();
|
|
759
|
-
while (dir && dir !== root) {
|
|
760
|
-
for (const name of names) {
|
|
761
|
-
const filePath = path.join(dir, name);
|
|
762
|
-
try {
|
|
763
|
-
// eslint-disable-next-line no-await-in-loop
|
|
764
|
-
const stats = await fs.promises.stat(filePath);
|
|
765
|
-
if (stats.isFile()) {
|
|
766
|
-
return filePath;
|
|
767
|
-
}
|
|
768
|
-
} catch {}
|
|
769
|
-
}
|
|
770
|
-
dir = path.dirname(dir);
|
|
771
|
-
}
|
|
772
|
-
return undefined;
|
|
773
|
-
}
|
|
774
|
-
async function readFileBinary(filepath, options) {
|
|
775
|
-
return await fs.promises.readFile(filepath, {
|
|
776
|
-
...options,
|
|
777
|
-
encoding: 'binary'
|
|
778
|
-
});
|
|
779
|
-
}
|
|
780
|
-
async function readFileUtf8(filepath, options) {
|
|
781
|
-
return await fs.promises.readFile(filepath, {
|
|
782
|
-
...options,
|
|
783
|
-
encoding: 'utf8'
|
|
784
|
-
});
|
|
785
|
-
}
|
|
786
|
-
|
|
787
837
|
const {
|
|
788
838
|
BINARY_LOCK_EXT,
|
|
789
839
|
BUN: BUN$1,
|
|
@@ -791,20 +841,25 @@ const {
|
|
|
791
841
|
NPM: NPM$2,
|
|
792
842
|
PNPM: PNPM$1,
|
|
793
843
|
VLT: VLT$1,
|
|
844
|
+
YARN,
|
|
794
845
|
YARN_BERRY: YARN_BERRY$1,
|
|
795
846
|
YARN_CLASSIC: YARN_CLASSIC$1
|
|
796
847
|
} = constants;
|
|
797
848
|
const AGENTS = [BUN$1, NPM$2, PNPM$1, YARN_BERRY$1, YARN_CLASSIC$1, VLT$1];
|
|
798
|
-
const {
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
849
|
+
const binByAgent = {
|
|
850
|
+
__proto__: null,
|
|
851
|
+
[BUN$1]: BUN$1,
|
|
852
|
+
[NPM$2]: NPM$2,
|
|
853
|
+
[PNPM$1]: PNPM$1,
|
|
854
|
+
[YARN_BERRY$1]: YARN,
|
|
855
|
+
[YARN_CLASSIC$1]: YARN,
|
|
856
|
+
[VLT$1]: VLT$1
|
|
857
|
+
};
|
|
804
858
|
async function getAgentExecPath(agent) {
|
|
805
|
-
|
|
859
|
+
const binName = binByAgent[agent];
|
|
860
|
+
return (await which(binName, {
|
|
806
861
|
nothrow: true
|
|
807
|
-
})) ??
|
|
862
|
+
})) ?? binName;
|
|
808
863
|
}
|
|
809
864
|
async function getAgentVersion(agentExecPath, cwd) {
|
|
810
865
|
let result;
|
|
@@ -848,8 +903,8 @@ const readLockFileByAgent = (() => {
|
|
|
848
903
|
return undefined;
|
|
849
904
|
};
|
|
850
905
|
}
|
|
851
|
-
const binaryReader = wrapReader(readFileBinary);
|
|
852
|
-
const defaultReader = wrapReader(async lockPath => await readFileUtf8(lockPath));
|
|
906
|
+
const binaryReader = wrapReader(socketUrl.readFileBinary);
|
|
907
|
+
const defaultReader = wrapReader(async lockPath => await socketUrl.readFileUtf8(lockPath));
|
|
853
908
|
return {
|
|
854
909
|
[BUN$1]: wrapReader(async (lockPath, agentExecPath) => {
|
|
855
910
|
const ext = path.extname(lockPath);
|
|
@@ -860,7 +915,7 @@ const readLockFileByAgent = (() => {
|
|
|
860
915
|
const lockBuffer = await binaryReader(lockPath);
|
|
861
916
|
if (lockBuffer) {
|
|
862
917
|
try {
|
|
863
|
-
return
|
|
918
|
+
return index_cjs.parse(lockBuffer);
|
|
864
919
|
} catch {}
|
|
865
920
|
}
|
|
866
921
|
// To print a Yarn lockfile to your console without writing it to disk
|
|
@@ -878,18 +933,18 @@ const readLockFileByAgent = (() => {
|
|
|
878
933
|
};
|
|
879
934
|
})();
|
|
880
935
|
async function detect({
|
|
881
|
-
cwd = process.cwd(),
|
|
936
|
+
cwd = process$1.cwd(),
|
|
882
937
|
onUnknown
|
|
883
938
|
} = {}) {
|
|
884
|
-
let lockPath = await findUp(Object.keys(LOCKS), {
|
|
939
|
+
let lockPath = await socketUrl.findUp(Object.keys(LOCKS), {
|
|
885
940
|
cwd
|
|
886
941
|
});
|
|
887
942
|
let lockBasename = lockPath ? path.basename(lockPath) : undefined;
|
|
888
943
|
const isHiddenLockFile = lockBasename === '.package-lock.json';
|
|
889
|
-
const pkgJsonPath = lockPath ? path.resolve(lockPath, `${isHiddenLockFile ? '../' : ''}../package.json`) : await findUp('package.json', {
|
|
944
|
+
const pkgJsonPath = lockPath ? path.resolve(lockPath, `${isHiddenLockFile ? '../' : ''}../package.json`) : await socketUrl.findUp('package.json', {
|
|
890
945
|
cwd
|
|
891
946
|
});
|
|
892
|
-
const pkgPath = existsSync(pkgJsonPath) ? path.dirname(pkgJsonPath) : undefined;
|
|
947
|
+
const pkgPath = pkgJsonPath && fs.existsSync(pkgJsonPath) ? path.dirname(pkgJsonPath) : undefined;
|
|
893
948
|
const editablePkgJson = pkgPath ? await packages.readPackageJson(pkgPath, {
|
|
894
949
|
editable: true
|
|
895
950
|
}) : undefined;
|
|
@@ -946,7 +1001,7 @@ async function detect({
|
|
|
946
1001
|
}
|
|
947
1002
|
const browserslistQuery = pkgJson['browserslist'];
|
|
948
1003
|
if (Array.isArray(browserslistQuery)) {
|
|
949
|
-
const browserslistTargets = browserslist(browserslistQuery).map(s => s.toLowerCase()).sort(
|
|
1004
|
+
const browserslistTargets = browserslist(browserslistQuery).map(s => s.toLowerCase()).sort(sorts.naturalCompare);
|
|
950
1005
|
const browserslistNodeTargets = browserslistTargets.filter(v => v.startsWith('node ')).map(v => v.slice(5 /*'node '.length*/));
|
|
951
1006
|
if (!targets.browser && browserslistTargets.length) {
|
|
952
1007
|
targets.browser = browserslistTargets.length !== browserslistNodeTargets.length;
|
|
@@ -985,25 +1040,25 @@ const {
|
|
|
985
1040
|
BUN,
|
|
986
1041
|
LOCK_EXT,
|
|
987
1042
|
NPM: NPM$1,
|
|
1043
|
+
OVERRIDES,
|
|
988
1044
|
PNPM,
|
|
989
|
-
|
|
1045
|
+
RESOLUTIONS,
|
|
1046
|
+
SOCKET_CLI_UPDATE_OVERRIDES_IN_PACKAGE_LOCK_FILE,
|
|
1047
|
+
SOCKET_IPC_HANDSHAKE,
|
|
990
1048
|
VLT,
|
|
991
1049
|
YARN_BERRY,
|
|
992
1050
|
YARN_CLASSIC,
|
|
993
|
-
abortSignal: abortSignal$2
|
|
994
|
-
execPath,
|
|
995
|
-
rootBinPath
|
|
1051
|
+
abortSignal: abortSignal$2
|
|
996
1052
|
} = constants;
|
|
997
1053
|
const COMMAND_TITLE = 'Socket Optimize';
|
|
998
|
-
const OVERRIDES_FIELD_NAME = 'overrides';
|
|
999
1054
|
const NPM_OVERRIDE_PR_URL = 'https://github.com/npm/cli/pull/7025';
|
|
1000
1055
|
const PNPM_FIELD_NAME = PNPM;
|
|
1001
1056
|
const PNPM_WORKSPACE = `${PNPM}-workspace`;
|
|
1002
|
-
const RESOLUTIONS_FIELD_NAME = 'resolutions';
|
|
1003
1057
|
const manifestNpmOverrides = registry.getManifestData(NPM$1);
|
|
1004
1058
|
const getOverridesDataByAgent = {
|
|
1059
|
+
__proto__: null,
|
|
1005
1060
|
[BUN](pkgJson) {
|
|
1006
|
-
const overrides = pkgJson?.
|
|
1061
|
+
const overrides = pkgJson?.[RESOLUTIONS] ?? {};
|
|
1007
1062
|
return {
|
|
1008
1063
|
type: YARN_BERRY,
|
|
1009
1064
|
overrides
|
|
@@ -1012,7 +1067,7 @@ const getOverridesDataByAgent = {
|
|
|
1012
1067
|
// npm overrides documentation:
|
|
1013
1068
|
// https://docs.npmjs.com/cli/v10/configuring-npm/package-json#overrides
|
|
1014
1069
|
[NPM$1](pkgJson) {
|
|
1015
|
-
const overrides = pkgJson?.
|
|
1070
|
+
const overrides = pkgJson?.[OVERRIDES] ?? {};
|
|
1016
1071
|
return {
|
|
1017
1072
|
type: NPM$1,
|
|
1018
1073
|
overrides
|
|
@@ -1021,14 +1076,14 @@ const getOverridesDataByAgent = {
|
|
|
1021
1076
|
// pnpm overrides documentation:
|
|
1022
1077
|
// https://pnpm.io/package_json#pnpmoverrides
|
|
1023
1078
|
[PNPM](pkgJson) {
|
|
1024
|
-
const overrides = pkgJson?.pnpm?.
|
|
1079
|
+
const overrides = pkgJson?.pnpm?.[OVERRIDES] ?? {};
|
|
1025
1080
|
return {
|
|
1026
1081
|
type: PNPM,
|
|
1027
1082
|
overrides
|
|
1028
1083
|
};
|
|
1029
1084
|
},
|
|
1030
1085
|
[VLT](pkgJson) {
|
|
1031
|
-
const overrides = pkgJson?.
|
|
1086
|
+
const overrides = pkgJson?.[OVERRIDES] ?? {};
|
|
1032
1087
|
return {
|
|
1033
1088
|
type: VLT,
|
|
1034
1089
|
overrides
|
|
@@ -1037,7 +1092,7 @@ const getOverridesDataByAgent = {
|
|
|
1037
1092
|
// Yarn resolutions documentation:
|
|
1038
1093
|
// https://yarnpkg.com/configuration/manifest#resolutions
|
|
1039
1094
|
[YARN_BERRY](pkgJson) {
|
|
1040
|
-
const overrides = pkgJson?.
|
|
1095
|
+
const overrides = pkgJson?.[RESOLUTIONS] ?? {};
|
|
1041
1096
|
return {
|
|
1042
1097
|
type: YARN_BERRY,
|
|
1043
1098
|
overrides
|
|
@@ -1046,7 +1101,7 @@ const getOverridesDataByAgent = {
|
|
|
1046
1101
|
// Yarn resolutions documentation:
|
|
1047
1102
|
// https://classic.yarnpkg.com/en/docs/selective-version-resolutions
|
|
1048
1103
|
[YARN_CLASSIC](pkgJson) {
|
|
1049
|
-
const overrides = pkgJson?.
|
|
1104
|
+
const overrides = pkgJson?.[RESOLUTIONS] ?? {};
|
|
1050
1105
|
return {
|
|
1051
1106
|
type: YARN_CLASSIC,
|
|
1052
1107
|
overrides
|
|
@@ -1070,6 +1125,7 @@ const lockIncludesByAgent = (() => {
|
|
|
1070
1125
|
`(?<=(?:^\\s*|,\\s*)"?)${escapedName}(?=@)`, 'm').test(lockSrc);
|
|
1071
1126
|
}
|
|
1072
1127
|
return {
|
|
1128
|
+
__proto__: null,
|
|
1073
1129
|
[BUN](lockSrc, name, lockBasename) {
|
|
1074
1130
|
// This is a bit counterintuitive. When lockBasename ends with a .lockb
|
|
1075
1131
|
// we treat it as a yarn.lock. When lockBasename ends with a .lock we
|
|
@@ -1133,7 +1189,7 @@ const updateManifestByAgent = (() => {
|
|
|
1133
1189
|
[field]: undefined
|
|
1134
1190
|
});
|
|
1135
1191
|
}
|
|
1136
|
-
} else if (field ===
|
|
1192
|
+
} else if (field === OVERRIDES || field === RESOLUTIONS) {
|
|
1137
1193
|
// Properties with undefined values are omitted when saved as JSON.
|
|
1138
1194
|
editablePkgJson.update({
|
|
1139
1195
|
[field]: objects.hasKeys(value) ? value : undefined
|
|
@@ -1145,7 +1201,7 @@ const updateManifestByAgent = (() => {
|
|
|
1145
1201
|
}
|
|
1146
1202
|
return;
|
|
1147
1203
|
}
|
|
1148
|
-
if ((field ===
|
|
1204
|
+
if ((field === OVERRIDES || field === PNPM_FIELD_NAME || field === RESOLUTIONS) && !objects.hasKeys(value)) {
|
|
1149
1205
|
return;
|
|
1150
1206
|
}
|
|
1151
1207
|
// Since the field doesn't exist we want to insert it into the package.json
|
|
@@ -1154,17 +1210,17 @@ const updateManifestByAgent = (() => {
|
|
|
1154
1210
|
const entries = Object.entries(pkgJson);
|
|
1155
1211
|
let insertIndex = -1;
|
|
1156
1212
|
let isPlacingHigher = false;
|
|
1157
|
-
if (field ===
|
|
1158
|
-
insertIndex = getLowestEntryIndex(entries, [
|
|
1213
|
+
if (field === OVERRIDES) {
|
|
1214
|
+
insertIndex = getLowestEntryIndex(entries, [RESOLUTIONS]);
|
|
1159
1215
|
if (insertIndex === -1) {
|
|
1160
1216
|
isPlacingHigher = true;
|
|
1161
1217
|
insertIndex = getHighestEntryIndex(entries, [...depFields, PNPM]);
|
|
1162
1218
|
}
|
|
1163
|
-
} else if (field ===
|
|
1219
|
+
} else if (field === RESOLUTIONS) {
|
|
1164
1220
|
isPlacingHigher = true;
|
|
1165
|
-
insertIndex = getHighestEntryIndex(entries, [...depFields,
|
|
1221
|
+
insertIndex = getHighestEntryIndex(entries, [...depFields, OVERRIDES, PNPM]);
|
|
1166
1222
|
} else if (field === PNPM_FIELD_NAME) {
|
|
1167
|
-
insertIndex = getLowestEntryIndex(entries, [
|
|
1223
|
+
insertIndex = getLowestEntryIndex(entries, [OVERRIDES, RESOLUTIONS]);
|
|
1168
1224
|
if (insertIndex === -1) {
|
|
1169
1225
|
isPlacingHigher = true;
|
|
1170
1226
|
insertIndex = getHighestEntryIndex(entries, depFields);
|
|
@@ -1186,12 +1242,13 @@ const updateManifestByAgent = (() => {
|
|
|
1186
1242
|
editablePkgJson.fromJSON(`${JSON.stringify(Object.fromEntries(entries), null, 2)}\n`);
|
|
1187
1243
|
}
|
|
1188
1244
|
function updateOverrides(editablePkgJson, overrides) {
|
|
1189
|
-
updatePkgJson(editablePkgJson,
|
|
1245
|
+
updatePkgJson(editablePkgJson, OVERRIDES, overrides);
|
|
1190
1246
|
}
|
|
1191
1247
|
function updateResolutions(editablePkgJson, overrides) {
|
|
1192
|
-
updatePkgJson(editablePkgJson,
|
|
1248
|
+
updatePkgJson(editablePkgJson, RESOLUTIONS, overrides);
|
|
1193
1249
|
}
|
|
1194
1250
|
return {
|
|
1251
|
+
__proto__: null,
|
|
1195
1252
|
[BUN]: updateResolutions,
|
|
1196
1253
|
[NPM$1]: updateOverrides,
|
|
1197
1254
|
[PNPM](editablePkgJson, overrides) {
|
|
@@ -1253,6 +1310,7 @@ const lsByAgent = (() => {
|
|
|
1253
1310
|
return cleanupQueryStdout(stdout);
|
|
1254
1311
|
}
|
|
1255
1312
|
return {
|
|
1313
|
+
__proto__: null,
|
|
1256
1314
|
async [BUN](agentExecPath, cwd) {
|
|
1257
1315
|
try {
|
|
1258
1316
|
// Bun does not support filtering by production packages yet.
|
|
@@ -1330,6 +1388,7 @@ const depsIncludesByAgent = (() => {
|
|
|
1330
1388
|
return stdout.includes(`"${name}"`);
|
|
1331
1389
|
}
|
|
1332
1390
|
return {
|
|
1391
|
+
__proto__: null,
|
|
1333
1392
|
[BUN]: matchHumanStdout,
|
|
1334
1393
|
[NPM$1]: matchQueryStdout,
|
|
1335
1394
|
[PNPM]: matchQueryStdout,
|
|
@@ -1339,7 +1398,7 @@ const depsIncludesByAgent = (() => {
|
|
|
1339
1398
|
};
|
|
1340
1399
|
})();
|
|
1341
1400
|
function createActionMessage(verb, overrideCount, workspaceCount) {
|
|
1342
|
-
return `${verb} ${overrideCount} Socket.dev optimized
|
|
1401
|
+
return `${verb} ${overrideCount} Socket.dev optimized ${words.pluralize('override', overrideCount)}${workspaceCount ? ` in ${workspaceCount} ${words.pluralize('workspace', workspaceCount)}` : ''}`;
|
|
1343
1402
|
}
|
|
1344
1403
|
function getDependencyEntries(pkgJson) {
|
|
1345
1404
|
const {
|
|
@@ -1368,11 +1427,11 @@ async function getWorkspaceGlobs(agent, pkgPath, pkgJson) {
|
|
|
1368
1427
|
let workspacePatterns;
|
|
1369
1428
|
if (agent === PNPM) {
|
|
1370
1429
|
for (const workspacePath of [path.join(pkgPath, `${PNPM_WORKSPACE}.yaml`), path.join(pkgPath, `${PNPM_WORKSPACE}.yml`)]) {
|
|
1371
|
-
|
|
1430
|
+
// eslint-disable-next-line no-await-in-loop
|
|
1431
|
+
const yml = await socketUrl.safeReadFile(workspacePath, 'utf8');
|
|
1432
|
+
if (yml) {
|
|
1372
1433
|
try {
|
|
1373
|
-
workspacePatterns = yaml.parse(
|
|
1374
|
-
// eslint-disable-next-line no-await-in-loop
|
|
1375
|
-
await fs$1.readFile(workspacePath, 'utf8'))?.packages;
|
|
1434
|
+
workspacePatterns = yaml.parse(yml)?.packages;
|
|
1376
1435
|
} catch {}
|
|
1377
1436
|
if (workspacePatterns) {
|
|
1378
1437
|
break;
|
|
@@ -1512,7 +1571,7 @@ async function addOverrides({
|
|
|
1512
1571
|
const oldSpec = overrideExists ? overrides[origPkgName] : undefined;
|
|
1513
1572
|
const depAlias = depAliasMap.get(origPkgName);
|
|
1514
1573
|
const regSpecStartsLike = `${NPM$1}:${regPkgName}@`;
|
|
1515
|
-
let newSpec = `${regSpecStartsLike}
|
|
1574
|
+
let newSpec = `${regSpecStartsLike}${pin ? version : `^${major}`}`;
|
|
1516
1575
|
let thisVersion = version;
|
|
1517
1576
|
if (depAlias && type === NPM$1) {
|
|
1518
1577
|
// With npm one may not set an override for a package that one directly
|
|
@@ -1529,7 +1588,7 @@ async function addOverrides({
|
|
|
1529
1588
|
if (pin) {
|
|
1530
1589
|
thisVersion = semver.major(semver.coerce(npa(thisSpec).rawSpec)?.version ?? version) === major ? version : (await packages.fetchPackageManifest(thisSpec))?.version ?? version;
|
|
1531
1590
|
}
|
|
1532
|
-
newSpec = `${regSpecStartsLike}
|
|
1591
|
+
newSpec = `${regSpecStartsLike}${pin ? thisVersion : `^${semver.major(thisVersion)}`}`;
|
|
1533
1592
|
} else {
|
|
1534
1593
|
newSpec = oldSpec;
|
|
1535
1594
|
}
|
|
@@ -1597,7 +1656,7 @@ const optimize = {
|
|
|
1597
1656
|
pin,
|
|
1598
1657
|
prod
|
|
1599
1658
|
} = commandContext;
|
|
1600
|
-
const cwd = process.cwd();
|
|
1659
|
+
const cwd = process$1.cwd();
|
|
1601
1660
|
const {
|
|
1602
1661
|
agent,
|
|
1603
1662
|
agentExecPath,
|
|
@@ -1644,13 +1703,13 @@ const optimize = {
|
|
|
1644
1703
|
if (lockPath && path.relative(cwd, lockPath).startsWith('.')) {
|
|
1645
1704
|
console.warn(`⚠️ ${COMMAND_TITLE}: Package ${lockName} found at ${lockPath}`);
|
|
1646
1705
|
}
|
|
1647
|
-
const spinner =
|
|
1706
|
+
const spinner$1 = new spinner.Spinner({
|
|
1648
1707
|
text: 'Socket optimizing...'
|
|
1649
1708
|
});
|
|
1650
1709
|
const state = createAddOverridesState({
|
|
1651
|
-
spinner
|
|
1710
|
+
spinner: spinner$1
|
|
1652
1711
|
});
|
|
1653
|
-
spinner.start();
|
|
1712
|
+
spinner$1.start();
|
|
1654
1713
|
const nodeRange = `>=${minimumNodeVersion}`;
|
|
1655
1714
|
const manifestEntries = manifestNpmOverrides.filter(({
|
|
1656
1715
|
1: data
|
|
@@ -1668,7 +1727,7 @@ const optimize = {
|
|
|
1668
1727
|
prod,
|
|
1669
1728
|
rootPath: pkgPath
|
|
1670
1729
|
}, state);
|
|
1671
|
-
spinner.stop();
|
|
1730
|
+
spinner$1.stop();
|
|
1672
1731
|
const addedCount = state.added.size;
|
|
1673
1732
|
const updatedCount = state.updated.size;
|
|
1674
1733
|
const pkgJsonChanged = addedCount > 0 || updatedCount > 0;
|
|
@@ -1686,23 +1745,24 @@ const optimize = {
|
|
|
1686
1745
|
if (isNpm || pkgJsonChanged) {
|
|
1687
1746
|
// Always update package-lock.json until the npm overrides PR lands:
|
|
1688
1747
|
// https://github.com/npm/cli/pull/7025
|
|
1689
|
-
spinner.start(`Updating ${lockName}...`);
|
|
1748
|
+
spinner$1.start(`Updating ${lockName}...`);
|
|
1690
1749
|
try {
|
|
1691
1750
|
if (isNpm) {
|
|
1692
|
-
const
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
stdio: 'ignore',
|
|
1696
|
-
env: {
|
|
1697
|
-
...process.env,
|
|
1698
|
-
[UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE]: '1'
|
|
1751
|
+
const ipc = {
|
|
1752
|
+
[SOCKET_IPC_HANDSHAKE]: {
|
|
1753
|
+
[SOCKET_CLI_UPDATE_OVERRIDES_IN_PACKAGE_LOCK_FILE]: true
|
|
1699
1754
|
}
|
|
1700
1755
|
};
|
|
1701
|
-
await
|
|
1756
|
+
await shadowNpmInstall({
|
|
1757
|
+
ipc
|
|
1758
|
+
});
|
|
1702
1759
|
// TODO: This is a temporary workaround for a `npm ci` bug where it
|
|
1703
1760
|
// will error out after Socket Optimize generates a lock file. More
|
|
1704
1761
|
// investigation is needed.
|
|
1705
|
-
await
|
|
1762
|
+
await shadowNpmInstall({
|
|
1763
|
+
flags: ['--ignore-scripts', '--package-lock-only'],
|
|
1764
|
+
ipc
|
|
1765
|
+
});
|
|
1706
1766
|
} else {
|
|
1707
1767
|
// All package managers support the "install" command.
|
|
1708
1768
|
await spawn(agentExecPath, ['install'], {
|
|
@@ -1710,12 +1770,13 @@ const optimize = {
|
|
|
1710
1770
|
stdio: 'ignore'
|
|
1711
1771
|
});
|
|
1712
1772
|
}
|
|
1713
|
-
spinner.stop();
|
|
1773
|
+
spinner$1.stop();
|
|
1714
1774
|
if (isNpm) {
|
|
1715
1775
|
console.log(`💡 Re-run ${COMMAND_TITLE} whenever ${lockName} changes.\n This can be skipped once npm ships ${NPM_OVERRIDE_PR_URL}.`);
|
|
1716
1776
|
}
|
|
1717
|
-
} catch {
|
|
1718
|
-
spinner.error(`${COMMAND_TITLE}: ${agent} install failed to update ${lockName}`);
|
|
1777
|
+
} catch (e) {
|
|
1778
|
+
spinner$1.error(`${COMMAND_TITLE}: ${agent} install failed to update ${lockName}`);
|
|
1779
|
+
console.error(e);
|
|
1719
1780
|
}
|
|
1720
1781
|
}
|
|
1721
1782
|
}
|
|
@@ -1742,7 +1803,7 @@ function setupCommand$l(name, description, argv, importMeta) {
|
|
|
1742
1803
|
$ ${name}
|
|
1743
1804
|
|
|
1744
1805
|
Options
|
|
1745
|
-
${
|
|
1806
|
+
${getFlagListOutput(flags, 6)}
|
|
1746
1807
|
|
|
1747
1808
|
Examples
|
|
1748
1809
|
$ ${name}
|
|
@@ -1790,20 +1851,20 @@ function setupCommand$k(name, description, argv, importMeta) {
|
|
|
1790
1851
|
});
|
|
1791
1852
|
}
|
|
1792
1853
|
async function fetchOrganizations() {
|
|
1793
|
-
const apiKey =
|
|
1854
|
+
const apiKey = socketUrl.getDefaultToken();
|
|
1794
1855
|
if (!apiKey) {
|
|
1795
|
-
throw new
|
|
1856
|
+
throw new socketUrl.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
1796
1857
|
}
|
|
1797
|
-
const spinner =
|
|
1858
|
+
const spinner$1 = new spinner.Spinner({
|
|
1798
1859
|
text: 'Fetching organizations...'
|
|
1799
1860
|
}).start();
|
|
1800
|
-
const socketSdk = await
|
|
1861
|
+
const socketSdk = await socketUrl.setupSdk(apiKey);
|
|
1801
1862
|
const result = await handleApiCall(socketSdk.getOrganizations(), 'looking up organizations');
|
|
1802
1863
|
if (result.success === false) {
|
|
1803
|
-
handleUnsuccessfulApiResponse('getOrganizations', result, spinner);
|
|
1864
|
+
handleUnsuccessfulApiResponse('getOrganizations', result, spinner$1);
|
|
1804
1865
|
return;
|
|
1805
1866
|
}
|
|
1806
|
-
spinner.stop(`List of organizations associated with your API key: ${colors.italic(apiKey)}`);
|
|
1867
|
+
spinner$1.stop(`List of organizations associated with your API key: ${colors.italic(apiKey)}`);
|
|
1807
1868
|
const organizations = Object.values(result.data.organizations);
|
|
1808
1869
|
for (const o of organizations) {
|
|
1809
1870
|
console.log(`
|
|
@@ -1837,7 +1898,7 @@ async function setupCommand$j(name, description, argv, importMeta) {
|
|
|
1837
1898
|
$ ${name} <${binName$1} command>
|
|
1838
1899
|
|
|
1839
1900
|
Options
|
|
1840
|
-
${
|
|
1901
|
+
${getFlagListOutput(flags, 6)}
|
|
1841
1902
|
|
|
1842
1903
|
Examples
|
|
1843
1904
|
$ ${name} install
|
|
@@ -1862,7 +1923,7 @@ async function setupCommand$j(name, description, argv, importMeta) {
|
|
|
1862
1923
|
// The exit code 127 indicates that the command or binary being executed
|
|
1863
1924
|
// could not be found.
|
|
1864
1925
|
console.error(`Socket unable to locate ${binName$1}; ensure it is available in the PATH environment variable.`);
|
|
1865
|
-
process.exit(127);
|
|
1926
|
+
process$1.exit(127);
|
|
1866
1927
|
}
|
|
1867
1928
|
const spawnPromise = spawn(binPath, argv, {
|
|
1868
1929
|
signal: abortSignal$1,
|
|
@@ -1874,9 +1935,9 @@ async function setupCommand$j(name, description, argv, importMeta) {
|
|
|
1874
1935
|
return;
|
|
1875
1936
|
}
|
|
1876
1937
|
if (signalName) {
|
|
1877
|
-
process.kill(process.pid, signalName);
|
|
1938
|
+
process$1.kill(process$1.pid, signalName);
|
|
1878
1939
|
} else if (code !== null) {
|
|
1879
|
-
process.exit(code);
|
|
1940
|
+
process$1.exit(code);
|
|
1880
1941
|
}
|
|
1881
1942
|
});
|
|
1882
1943
|
await spawnPromise;
|
|
@@ -1905,7 +1966,7 @@ async function setupCommand$i(name, description, argv, importMeta) {
|
|
|
1905
1966
|
$ ${name} <${binName} command>
|
|
1906
1967
|
|
|
1907
1968
|
Options
|
|
1908
|
-
${
|
|
1969
|
+
${getFlagListOutput(flags, 6)}
|
|
1909
1970
|
|
|
1910
1971
|
Examples
|
|
1911
1972
|
$ ${name} install
|
|
@@ -1930,7 +1991,7 @@ async function setupCommand$i(name, description, argv, importMeta) {
|
|
|
1930
1991
|
// The exit code 127 indicates that the command or binary being executed
|
|
1931
1992
|
// could not be found.
|
|
1932
1993
|
console.error(`Socket unable to locate ${binName}; ensure it is available in the PATH environment variable.`);
|
|
1933
|
-
process.exit(127);
|
|
1994
|
+
process$1.exit(127);
|
|
1934
1995
|
}
|
|
1935
1996
|
const spawnPromise = spawn(binPath, argv, {
|
|
1936
1997
|
signal: abortSignal,
|
|
@@ -1942,9 +2003,9 @@ async function setupCommand$i(name, description, argv, importMeta) {
|
|
|
1942
2003
|
return;
|
|
1943
2004
|
}
|
|
1944
2005
|
if (signalName) {
|
|
1945
|
-
process.kill(process.pid, signalName);
|
|
2006
|
+
process$1.kill(process$1.pid, signalName);
|
|
1946
2007
|
} else if (code !== null) {
|
|
1947
|
-
process.exit(code);
|
|
2008
|
+
process$1.exit(code);
|
|
1948
2009
|
}
|
|
1949
2010
|
});
|
|
1950
2011
|
await spawnPromise;
|
|
@@ -1980,7 +2041,7 @@ function setupCommand$h(name, description, argv, importMeta) {
|
|
|
1980
2041
|
$ ${name} <report-identifier>
|
|
1981
2042
|
|
|
1982
2043
|
Options
|
|
1983
|
-
${
|
|
2044
|
+
${getFlagListOutput(flags, 6)}
|
|
1984
2045
|
|
|
1985
2046
|
Examples
|
|
1986
2047
|
$ ${name} QXU8PmK7LfH608RAwfIKdbcHgwEd_ZeWJ9QEGv05FJUQ
|
|
@@ -2002,7 +2063,7 @@ function setupCommand$h(name, description, argv, importMeta) {
|
|
|
2002
2063
|
}
|
|
2003
2064
|
// Validate the input.
|
|
2004
2065
|
if (extraInput.length) {
|
|
2005
|
-
throw new
|
|
2066
|
+
throw new socketUrl.InputError(`Can only handle a single report ID at a time, but got ${cli.input.length} report ID:s: ${cli.input.join(', ')}`);
|
|
2006
2067
|
}
|
|
2007
2068
|
return {
|
|
2008
2069
|
includeAllIssues: cli.flags['all'],
|
|
@@ -2018,8 +2079,8 @@ async function fetchReportData(reportId, {
|
|
|
2018
2079
|
strict
|
|
2019
2080
|
}) {
|
|
2020
2081
|
// Do the API call
|
|
2021
|
-
const socketSdk = await
|
|
2022
|
-
const spinner =
|
|
2082
|
+
const socketSdk = await socketUrl.setupSdk();
|
|
2083
|
+
const spinner$1 = new spinner.Spinner({
|
|
2023
2084
|
text: `Fetching report with ID ${reportId} (this could take a while)`
|
|
2024
2085
|
}).start();
|
|
2025
2086
|
let result;
|
|
@@ -2034,23 +2095,23 @@ async function fetchReportData(reportId, {
|
|
|
2034
2095
|
}
|
|
2035
2096
|
}
|
|
2036
2097
|
if (result.success === false) {
|
|
2037
|
-
return handleUnsuccessfulApiResponse('getReport', result, spinner);
|
|
2098
|
+
return handleUnsuccessfulApiResponse('getReport', result, spinner$1);
|
|
2038
2099
|
}
|
|
2039
2100
|
|
|
2040
2101
|
// Conclude the status of the API call
|
|
2041
2102
|
|
|
2042
2103
|
if (strict) {
|
|
2043
2104
|
if (result.data.healthy) {
|
|
2044
|
-
spinner.success('Report result is healthy and great!');
|
|
2105
|
+
spinner$1.success('Report result is healthy and great!');
|
|
2045
2106
|
} else {
|
|
2046
|
-
spinner.error('Report result deemed unhealthy for project');
|
|
2107
|
+
spinner$1.error('Report result deemed unhealthy for project');
|
|
2047
2108
|
}
|
|
2048
2109
|
} else if (result.data.healthy === false) {
|
|
2049
2110
|
const severityCount = getSeverityCount(result.data.issues, includeAllIssues ? undefined : 'high');
|
|
2050
2111
|
const issueSummary = formatSeverityCount(severityCount);
|
|
2051
|
-
spinner.success(`Report has these issues: ${issueSummary}`);
|
|
2112
|
+
spinner$1.success(`Report has these issues: ${issueSummary}`);
|
|
2052
2113
|
} else {
|
|
2053
|
-
spinner.success('Report has no issues');
|
|
2114
|
+
spinner$1.success('Report has no issues');
|
|
2054
2115
|
}
|
|
2055
2116
|
return result.data;
|
|
2056
2117
|
}
|
|
@@ -2064,7 +2125,7 @@ function formatReportDataOutput(data, {
|
|
|
2064
2125
|
if (outputJson) {
|
|
2065
2126
|
console.log(JSON.stringify(data, undefined, 2));
|
|
2066
2127
|
} else {
|
|
2067
|
-
const format = new
|
|
2128
|
+
const format = new socketUrl.ColorOrMarkdown(!!outputMarkdown);
|
|
2068
2129
|
console.log('\nDetailed info on socket.dev: ' + format.hyperlink(reportId, data.url, {
|
|
2069
2130
|
fallbackToUrl: true
|
|
2070
2131
|
}));
|
|
@@ -2073,7 +2134,7 @@ function formatReportDataOutput(data, {
|
|
|
2073
2134
|
}
|
|
2074
2135
|
}
|
|
2075
2136
|
if (strict && data.healthy === false) {
|
|
2076
|
-
process.exit(1);
|
|
2137
|
+
process$1.exit(1);
|
|
2077
2138
|
}
|
|
2078
2139
|
}
|
|
2079
2140
|
|
|
@@ -2088,7 +2149,6 @@ const create$2 = {
|
|
|
2088
2149
|
const {
|
|
2089
2150
|
config,
|
|
2090
2151
|
cwd,
|
|
2091
|
-
debugLog,
|
|
2092
2152
|
dryRun,
|
|
2093
2153
|
includeAllIssues,
|
|
2094
2154
|
outputJson,
|
|
@@ -2100,7 +2160,6 @@ const create$2 = {
|
|
|
2100
2160
|
const result = input && (await createReport(packagePaths, {
|
|
2101
2161
|
config,
|
|
2102
2162
|
cwd,
|
|
2103
|
-
debugLog,
|
|
2104
2163
|
dryRun
|
|
2105
2164
|
}));
|
|
2106
2165
|
if (result && view) {
|
|
@@ -2136,12 +2195,6 @@ async function setupCommand$g(name, description, argv, importMeta) {
|
|
|
2136
2195
|
...commonFlags,
|
|
2137
2196
|
...outputFlags,
|
|
2138
2197
|
...validationFlags,
|
|
2139
|
-
debug: {
|
|
2140
|
-
type: 'boolean',
|
|
2141
|
-
shortFlag: 'd',
|
|
2142
|
-
default: false,
|
|
2143
|
-
description: 'Output debug information'
|
|
2144
|
-
},
|
|
2145
2198
|
dryRun: {
|
|
2146
2199
|
type: 'boolean',
|
|
2147
2200
|
default: false,
|
|
@@ -2168,9 +2221,8 @@ async function setupCommand$g(name, description, argv, importMeta) {
|
|
|
2168
2221
|
default ignores from the "ignore-by-default" module.
|
|
2169
2222
|
|
|
2170
2223
|
Options
|
|
2171
|
-
${
|
|
2224
|
+
${getFlagListOutput({
|
|
2172
2225
|
all: 'Include all issues',
|
|
2173
|
-
debug: 'Output debug information',
|
|
2174
2226
|
'dry-run': 'Only output what will be done without actually doing it',
|
|
2175
2227
|
json: 'Output result as json',
|
|
2176
2228
|
markdown: 'Output result as markdown',
|
|
@@ -2200,10 +2252,9 @@ async function setupCommand$g(name, description, argv, importMeta) {
|
|
|
2200
2252
|
const {
|
|
2201
2253
|
dryRun
|
|
2202
2254
|
} = cli.flags;
|
|
2203
|
-
const debugLog = sdk.createDebugLogger(!dryRun || cli.flags['debug']);
|
|
2204
2255
|
|
|
2205
2256
|
// TODO: Allow setting a custom cwd and/or configFile path?
|
|
2206
|
-
const cwd = process.cwd();
|
|
2257
|
+
const cwd = process$1.cwd();
|
|
2207
2258
|
const absoluteConfigPath = path.join(cwd, 'socket.yml');
|
|
2208
2259
|
const config$1 = await config.readSocketConfig(absoluteConfigPath).catch(cause => {
|
|
2209
2260
|
if (cause && typeof cause === 'object' && cause instanceof config.SocketValidationError) {
|
|
@@ -2215,27 +2266,26 @@ async function setupCommand$g(name, description, argv, importMeta) {
|
|
|
2215
2266
|
errors: cause.validationErrors,
|
|
2216
2267
|
schema: cause.schema
|
|
2217
2268
|
});
|
|
2218
|
-
throw new
|
|
2269
|
+
throw new socketUrl.InputError('The socket.yml config is not valid', betterErrors.map(err => `[${err.path}] ${err.message}.${err.suggestion ? err.suggestion : ''}`).join('\n'));
|
|
2219
2270
|
} else {
|
|
2220
2271
|
throw new ponyCause.ErrorWithCause('Failed to read socket.yml config', {
|
|
2221
2272
|
cause
|
|
2222
2273
|
});
|
|
2223
2274
|
}
|
|
2224
2275
|
});
|
|
2225
|
-
const socketSdk = await
|
|
2276
|
+
const socketSdk = await socketUrl.setupSdk();
|
|
2226
2277
|
const supportedFiles = await socketSdk.getReportSupportedFiles().then(res => {
|
|
2227
|
-
if (!res.success) handleUnsuccessfulApiResponse('getReportSupportedFiles', res,
|
|
2278
|
+
if (!res.success) handleUnsuccessfulApiResponse('getReportSupportedFiles', res, new spinner.Spinner());
|
|
2228
2279
|
return res.data;
|
|
2229
2280
|
}).catch(cause => {
|
|
2230
2281
|
throw new ponyCause.ErrorWithCause('Failed getting supported files for report', {
|
|
2231
2282
|
cause
|
|
2232
2283
|
});
|
|
2233
2284
|
});
|
|
2234
|
-
const packagePaths = await pathResolve.getPackageFiles(cwd, cli.input, config$1, supportedFiles
|
|
2285
|
+
const packagePaths = await pathResolve.getPackageFiles(cwd, cli.input, config$1, supportedFiles);
|
|
2235
2286
|
return {
|
|
2236
2287
|
config: config$1,
|
|
2237
2288
|
cwd,
|
|
2238
|
-
debugLog,
|
|
2239
2289
|
dryRun,
|
|
2240
2290
|
includeAllIssues: cli.flags['all'],
|
|
2241
2291
|
outputJson: cli.flags['json'],
|
|
@@ -2248,24 +2298,23 @@ async function setupCommand$g(name, description, argv, importMeta) {
|
|
|
2248
2298
|
async function createReport(packagePaths, {
|
|
2249
2299
|
config,
|
|
2250
2300
|
cwd,
|
|
2251
|
-
debugLog,
|
|
2252
2301
|
dryRun
|
|
2253
2302
|
}) {
|
|
2254
|
-
debugLog('Uploading:', packagePaths.join(`\n${
|
|
2303
|
+
pathResolve.debugLog('Uploading:', packagePaths.join(`\n${pathResolve.logSymbols.info} Uploading: `));
|
|
2255
2304
|
if (dryRun) {
|
|
2256
2305
|
return;
|
|
2257
2306
|
}
|
|
2258
|
-
const socketSdk = await
|
|
2259
|
-
const spinner =
|
|
2307
|
+
const socketSdk = await socketUrl.setupSdk();
|
|
2308
|
+
const spinner$1 = new spinner.Spinner({
|
|
2260
2309
|
text: `Creating report with ${packagePaths.length} package files`
|
|
2261
2310
|
}).start();
|
|
2262
2311
|
const apiCall = socketSdk.createReportFromFilePaths(packagePaths, cwd, config?.issueRules);
|
|
2263
2312
|
const result = await handleApiCall(apiCall, 'creating report');
|
|
2264
2313
|
if (result.success) {
|
|
2265
|
-
spinner.success();
|
|
2314
|
+
spinner$1.success();
|
|
2266
2315
|
return result;
|
|
2267
2316
|
}
|
|
2268
|
-
handleUnsuccessfulApiResponse('createReport', result, spinner);
|
|
2317
|
+
handleUnsuccessfulApiResponse('createReport', result, spinner$1);
|
|
2269
2318
|
return undefined;
|
|
2270
2319
|
}
|
|
2271
2320
|
function formatReportCreationOutput(data, {
|
|
@@ -2276,7 +2325,7 @@ function formatReportCreationOutput(data, {
|
|
|
2276
2325
|
console.log(JSON.stringify(data, undefined, 2));
|
|
2277
2326
|
return;
|
|
2278
2327
|
}
|
|
2279
|
-
const format = new
|
|
2328
|
+
const format = new socketUrl.ColorOrMarkdown(!!outputMarkdown);
|
|
2280
2329
|
console.log(`New report: ${format.hyperlink(data.id, data.url, {
|
|
2281
2330
|
fallbackToUrl: true
|
|
2282
2331
|
})}`);
|
|
@@ -2318,13 +2367,13 @@ async function meowWithSubcommands(subcommands, options) {
|
|
|
2318
2367
|
$ ${name} <command>
|
|
2319
2368
|
|
|
2320
2369
|
Commands
|
|
2321
|
-
${
|
|
2322
|
-
...objects.toSortedObject(subcommands),
|
|
2323
|
-
...objects.toSortedObject(aliases)
|
|
2370
|
+
${getHelpListOutput({
|
|
2371
|
+
...objects.toSortedObject(Object.fromEntries(Object.entries(subcommands).filter(entry => !entry[1].hidden))),
|
|
2372
|
+
...objects.toSortedObject(Object.fromEntries(Object.entries(aliases).filter(entry => !subcommands[entry[1]?.argv[0]]?.hidden)))
|
|
2324
2373
|
}, 6)}
|
|
2325
2374
|
|
|
2326
2375
|
Options
|
|
2327
|
-
${
|
|
2376
|
+
${getFlagListOutput(flags, 6)}
|
|
2328
2377
|
|
|
2329
2378
|
Examples
|
|
2330
2379
|
$ ${name} --help
|
|
@@ -2355,8 +2404,9 @@ const report = {
|
|
|
2355
2404
|
}
|
|
2356
2405
|
};
|
|
2357
2406
|
|
|
2358
|
-
const
|
|
2359
|
-
const
|
|
2407
|
+
const HOME_DIR = os.homedir();
|
|
2408
|
+
const BASH_FILE = `${HOME_DIR}/.bashrc`;
|
|
2409
|
+
const ZSH_BASH_FILE = `${HOME_DIR}/.zshrc`;
|
|
2360
2410
|
const wrapper = {
|
|
2361
2411
|
description: 'Enable or disable the Socket npm/npx wrapper',
|
|
2362
2412
|
async run(argv, importMeta, {
|
|
@@ -2372,7 +2422,7 @@ function setupCommand$f(name, description, argv, importMeta) {
|
|
|
2372
2422
|
$ ${name} <flag>
|
|
2373
2423
|
|
|
2374
2424
|
Options
|
|
2375
|
-
${
|
|
2425
|
+
${getFlagListOutput(flags, 6)}
|
|
2376
2426
|
|
|
2377
2427
|
Examples
|
|
2378
2428
|
$ ${name} --enable
|
|
@@ -2427,21 +2477,18 @@ function setupCommand$f(name, description, argv, importMeta) {
|
|
|
2427
2477
|
console.error('There was an issue setting up the alias in your bash profile');
|
|
2428
2478
|
}
|
|
2429
2479
|
}
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2480
|
+
function addAlias(file) {
|
|
2481
|
+
return fs.appendFile(file, 'alias npm="socket npm"\nalias npx="socket npx"\n', err => {
|
|
2482
|
+
if (err) {
|
|
2483
|
+
return new Error(`There was an error setting up the alias: ${err}`);
|
|
2484
|
+
}
|
|
2485
|
+
console.log(`
|
|
2486
|
+
The alias was added to ${file}. Running 'npm install' will now be wrapped in Socket's "safe npm" 🎉
|
|
2487
|
+
If you want to disable it at any time, run \`socket wrapper --disable\`
|
|
2437
2488
|
`);
|
|
2438
|
-
const rl = readline.createInterface({
|
|
2439
|
-
input: process.stdin,
|
|
2440
|
-
output: process.stdout
|
|
2441
2489
|
});
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
const askQuestion = (rl, query) => {
|
|
2490
|
+
}
|
|
2491
|
+
function askQuestion(rl, query) {
|
|
2445
2492
|
rl.question(query, ans => {
|
|
2446
2493
|
if (ans.toLowerCase() === 'y') {
|
|
2447
2494
|
try {
|
|
@@ -2461,19 +2508,31 @@ const askQuestion = (rl, query) => {
|
|
|
2461
2508
|
rl.close();
|
|
2462
2509
|
}
|
|
2463
2510
|
});
|
|
2464
|
-
}
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
}
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2511
|
+
}
|
|
2512
|
+
function checkSocketWrapperAlreadySetup(file) {
|
|
2513
|
+
const fileContent = fs.readFileSync(file, 'utf8');
|
|
2514
|
+
const linesWithSocketAlias = fileContent.split('\n').filter(l => l === 'alias npm="socket npm"' || l === 'alias npx="socket npx"');
|
|
2515
|
+
if (linesWithSocketAlias.length) {
|
|
2516
|
+
console.log(`The Socket npm/npx wrapper is set up in your bash profile (${file}).`);
|
|
2517
|
+
return true;
|
|
2518
|
+
}
|
|
2519
|
+
return false;
|
|
2520
|
+
}
|
|
2521
|
+
function installSafeNpm(query) {
|
|
2522
|
+
console.log(`
|
|
2523
|
+
_____ _ _
|
|
2524
|
+
| __|___ ___| |_ ___| |_
|
|
2525
|
+
|__ | . | _| '_| -_| _|
|
|
2526
|
+
|_____|___|___|_,_|___|_|
|
|
2527
|
+
|
|
2473
2528
|
`);
|
|
2529
|
+
const rl = readline.createInterface({
|
|
2530
|
+
input: process$1.stdin,
|
|
2531
|
+
output: process$1.stdout
|
|
2474
2532
|
});
|
|
2475
|
-
|
|
2476
|
-
|
|
2533
|
+
return askQuestion(rl, query);
|
|
2534
|
+
}
|
|
2535
|
+
function removeAlias(file) {
|
|
2477
2536
|
return fs.readFile(file, 'utf8', function (err, data) {
|
|
2478
2537
|
if (err) {
|
|
2479
2538
|
console.error(`There was an error removing the alias: ${err}`);
|
|
@@ -2490,16 +2549,7 @@ const removeAlias = file => {
|
|
|
2490
2549
|
}
|
|
2491
2550
|
});
|
|
2492
2551
|
});
|
|
2493
|
-
}
|
|
2494
|
-
const checkSocketWrapperAlreadySetup = file => {
|
|
2495
|
-
const fileContent = fs.readFileSync(file, 'utf8');
|
|
2496
|
-
const linesWithSocketAlias = fileContent.split('\n').filter(l => l === 'alias npm="socket npm"' || l === 'alias npx="socket npx"');
|
|
2497
|
-
if (linesWithSocketAlias.length) {
|
|
2498
|
-
console.log(`The Socket npm/npx wrapper is set up in your bash profile (${file}).`);
|
|
2499
|
-
return true;
|
|
2500
|
-
}
|
|
2501
|
-
return false;
|
|
2502
|
-
};
|
|
2552
|
+
}
|
|
2503
2553
|
|
|
2504
2554
|
const create$1 = {
|
|
2505
2555
|
description: 'Create a scan',
|
|
@@ -2509,15 +2559,15 @@ const create$1 = {
|
|
|
2509
2559
|
const name = `${parentName} create`;
|
|
2510
2560
|
const input = await setupCommand$e(name, create$1.description, argv, importMeta);
|
|
2511
2561
|
if (input) {
|
|
2512
|
-
const apiKey =
|
|
2562
|
+
const apiKey = socketUrl.getDefaultToken();
|
|
2513
2563
|
if (!apiKey) {
|
|
2514
|
-
throw new
|
|
2564
|
+
throw new socketUrl.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
2515
2565
|
}
|
|
2516
2566
|
const spinnerText = 'Creating a scan... \n';
|
|
2517
|
-
const spinner =
|
|
2567
|
+
const spinner$1 = new spinner.Spinner({
|
|
2518
2568
|
text: spinnerText
|
|
2519
2569
|
}).start();
|
|
2520
|
-
await createFullScan(input, spinner, apiKey);
|
|
2570
|
+
await createFullScan(input, spinner$1, apiKey);
|
|
2521
2571
|
}
|
|
2522
2572
|
}
|
|
2523
2573
|
};
|
|
@@ -2588,7 +2638,7 @@ async function setupCommand$e(name, description, argv, importMeta) {
|
|
|
2588
2638
|
$ ${name} [...options]
|
|
2589
2639
|
|
|
2590
2640
|
Options
|
|
2591
|
-
${
|
|
2641
|
+
${getFlagListOutput(flags, 6)}
|
|
2592
2642
|
|
|
2593
2643
|
Examples
|
|
2594
2644
|
$ ${name} --org=FakeOrg --repo=test-repo --branch=main ./package.json
|
|
@@ -2609,10 +2659,10 @@ async function setupCommand$e(name, description, argv, importMeta) {
|
|
|
2609
2659
|
const {
|
|
2610
2660
|
0: orgSlug = ''
|
|
2611
2661
|
} = cli.input;
|
|
2612
|
-
const cwd = process.cwd();
|
|
2613
|
-
const socketSdk = await
|
|
2662
|
+
const cwd = process$1.cwd();
|
|
2663
|
+
const socketSdk = await socketUrl.setupSdk();
|
|
2614
2664
|
const supportedFiles = await socketSdk.getReportSupportedFiles().then(res => {
|
|
2615
|
-
if (!res.success) handleUnsuccessfulApiResponse('getReportSupportedFiles', res,
|
|
2665
|
+
if (!res.success) handleUnsuccessfulApiResponse('getReportSupportedFiles', res, new spinner.Spinner());
|
|
2616
2666
|
return res.data;
|
|
2617
2667
|
}).catch(/** @type {(cause: Error) => never} */
|
|
2618
2668
|
cause => {
|
|
@@ -2620,8 +2670,7 @@ async function setupCommand$e(name, description, argv, importMeta) {
|
|
|
2620
2670
|
cause
|
|
2621
2671
|
});
|
|
2622
2672
|
});
|
|
2623
|
-
const
|
|
2624
|
-
const packagePaths = await pathResolve.getPackageFilesFullScans(cwd, cli.input, supportedFiles, debugLog);
|
|
2673
|
+
const packagePaths = await pathResolve.getPackageFilesFullScans(cwd, cli.input, supportedFiles);
|
|
2625
2674
|
const {
|
|
2626
2675
|
branch: branchName,
|
|
2627
2676
|
repo: repoName
|
|
@@ -2652,7 +2701,7 @@ async function setupCommand$e(name, description, argv, importMeta) {
|
|
|
2652
2701
|
};
|
|
2653
2702
|
}
|
|
2654
2703
|
async function createFullScan(input, spinner, apiKey) {
|
|
2655
|
-
const socketSdk = await
|
|
2704
|
+
const socketSdk = await socketUrl.setupSdk(apiKey);
|
|
2656
2705
|
const {
|
|
2657
2706
|
branchName,
|
|
2658
2707
|
commitMessage,
|
|
@@ -2697,15 +2746,15 @@ const del$1 = {
|
|
|
2697
2746
|
const name = `${parentName} del`;
|
|
2698
2747
|
const input = setupCommand$d(name, del$1.description, argv, importMeta);
|
|
2699
2748
|
if (input) {
|
|
2700
|
-
const apiKey =
|
|
2749
|
+
const apiKey = socketUrl.getDefaultToken();
|
|
2701
2750
|
if (!apiKey) {
|
|
2702
|
-
throw new
|
|
2751
|
+
throw new socketUrl.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
2703
2752
|
}
|
|
2704
2753
|
const spinnerText = 'Deleting scan...';
|
|
2705
|
-
const spinner =
|
|
2754
|
+
const spinner$1 = new spinner.Spinner({
|
|
2706
2755
|
text: spinnerText
|
|
2707
2756
|
}).start();
|
|
2708
|
-
await deleteOrgFullScan(input.orgSlug, input.fullScanId, spinner, apiKey);
|
|
2757
|
+
await deleteOrgFullScan(input.orgSlug, input.fullScanId, spinner$1, apiKey);
|
|
2709
2758
|
}
|
|
2710
2759
|
}
|
|
2711
2760
|
};
|
|
@@ -2722,7 +2771,7 @@ function setupCommand$d(name, description, argv, importMeta) {
|
|
|
2722
2771
|
$ ${name} <org slug> <scan ID>
|
|
2723
2772
|
|
|
2724
2773
|
Options
|
|
2725
|
-
${
|
|
2774
|
+
${getFlagListOutput(flags, 6)}
|
|
2726
2775
|
|
|
2727
2776
|
Examples
|
|
2728
2777
|
$ ${name} FakeOrg 000aaaa1-0000-0a0a-00a0-00a0000000a0
|
|
@@ -2753,7 +2802,7 @@ function setupCommand$d(name, description, argv, importMeta) {
|
|
|
2753
2802
|
};
|
|
2754
2803
|
}
|
|
2755
2804
|
async function deleteOrgFullScan(orgSlug, fullScanId, spinner, apiKey) {
|
|
2756
|
-
const socketSdk = await
|
|
2805
|
+
const socketSdk = await socketUrl.setupSdk(apiKey);
|
|
2757
2806
|
const result = await handleApiCall(socketSdk.deleteOrgFullScan(orgSlug, fullScanId), 'Deleting scan');
|
|
2758
2807
|
if (result.success) {
|
|
2759
2808
|
spinner.success('Scan deleted successfully');
|
|
@@ -2762,6 +2811,7 @@ async function deleteOrgFullScan(orgSlug, fullScanId, spinner, apiKey) {
|
|
|
2762
2811
|
}
|
|
2763
2812
|
}
|
|
2764
2813
|
|
|
2814
|
+
// @ts-ignore
|
|
2765
2815
|
const list$1 = {
|
|
2766
2816
|
description: 'List scans for an organization',
|
|
2767
2817
|
async run(argv, importMeta, {
|
|
@@ -2770,15 +2820,15 @@ const list$1 = {
|
|
|
2770
2820
|
const name = `${parentName} list`;
|
|
2771
2821
|
const input = setupCommand$c(name, list$1.description, argv, importMeta);
|
|
2772
2822
|
if (input) {
|
|
2773
|
-
const apiKey =
|
|
2823
|
+
const apiKey = socketUrl.getDefaultToken();
|
|
2774
2824
|
if (!apiKey) {
|
|
2775
|
-
throw new
|
|
2825
|
+
throw new socketUrl.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
2776
2826
|
}
|
|
2777
2827
|
const spinnerText = 'Listing scans... \n';
|
|
2778
|
-
const spinner =
|
|
2828
|
+
const spinner$1 = new spinner.Spinner({
|
|
2779
2829
|
text: spinnerText
|
|
2780
2830
|
}).start();
|
|
2781
|
-
await listOrgFullScan(input.orgSlug, input, spinner, apiKey);
|
|
2831
|
+
await listOrgFullScan(input.orgSlug, input, spinner$1, apiKey);
|
|
2782
2832
|
}
|
|
2783
2833
|
}
|
|
2784
2834
|
};
|
|
@@ -2834,7 +2884,7 @@ function setupCommand$c(name, description, argv, importMeta) {
|
|
|
2834
2884
|
$ ${name} <org slug>
|
|
2835
2885
|
|
|
2836
2886
|
Options
|
|
2837
|
-
${
|
|
2887
|
+
${getFlagListOutput(flags, 6)}
|
|
2838
2888
|
|
|
2839
2889
|
Examples
|
|
2840
2890
|
$ ${name} FakeOrg
|
|
@@ -2869,7 +2919,7 @@ function setupCommand$c(name, description, argv, importMeta) {
|
|
|
2869
2919
|
};
|
|
2870
2920
|
}
|
|
2871
2921
|
async function listOrgFullScan(orgSlug, input, spinner, apiKey) {
|
|
2872
|
-
const socketSdk = await
|
|
2922
|
+
const socketSdk = await socketUrl.setupSdk(apiKey);
|
|
2873
2923
|
const result = await handleApiCall(socketSdk.getOrgFullScanList(orgSlug, input), 'Listing scans');
|
|
2874
2924
|
if (!result.success) {
|
|
2875
2925
|
handleUnsuccessfulApiResponse('getOrgFullScanList', result, spinner);
|
|
@@ -2914,15 +2964,15 @@ const metadata = {
|
|
|
2914
2964
|
const name = `${parentName} metadata`;
|
|
2915
2965
|
const input = setupCommand$b(name, metadata.description, argv, importMeta);
|
|
2916
2966
|
if (input) {
|
|
2917
|
-
const apiKey =
|
|
2967
|
+
const apiKey = socketUrl.getDefaultToken();
|
|
2918
2968
|
if (!apiKey) {
|
|
2919
|
-
throw new
|
|
2969
|
+
throw new socketUrl.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
2920
2970
|
}
|
|
2921
2971
|
const spinnerText = "Getting scan's metadata... \n";
|
|
2922
|
-
const spinner =
|
|
2972
|
+
const spinner$1 = new spinner.Spinner({
|
|
2923
2973
|
text: spinnerText
|
|
2924
2974
|
}).start();
|
|
2925
|
-
await getOrgScanMetadata(input.orgSlug, input.scanID, spinner, apiKey);
|
|
2975
|
+
await getOrgScanMetadata(input.orgSlug, input.scanID, spinner$1, apiKey);
|
|
2926
2976
|
}
|
|
2927
2977
|
}
|
|
2928
2978
|
};
|
|
@@ -2939,7 +2989,7 @@ function setupCommand$b(name, description, argv, importMeta) {
|
|
|
2939
2989
|
$ ${name} <org slug> <scan id>
|
|
2940
2990
|
|
|
2941
2991
|
Options
|
|
2942
|
-
${
|
|
2992
|
+
${getFlagListOutput(flags, 6)}
|
|
2943
2993
|
|
|
2944
2994
|
Examples
|
|
2945
2995
|
$ ${name} FakeOrg 000aaaa1-0000-0a0a-00a0-00a0000000a0
|
|
@@ -2970,7 +3020,7 @@ function setupCommand$b(name, description, argv, importMeta) {
|
|
|
2970
3020
|
};
|
|
2971
3021
|
}
|
|
2972
3022
|
async function getOrgScanMetadata(orgSlug, scanId, spinner, apiKey) {
|
|
2973
|
-
const socketSdk = await
|
|
3023
|
+
const socketSdk = await socketUrl.setupSdk(apiKey);
|
|
2974
3024
|
const result = await handleApiCall(socketSdk.getOrgFullScanMetadata(orgSlug, scanId), 'Listing scans');
|
|
2975
3025
|
if (!result.success) {
|
|
2976
3026
|
handleUnsuccessfulApiResponse('getOrgFullScanMetadata', result, spinner);
|
|
@@ -2988,18 +3038,18 @@ const stream = {
|
|
|
2988
3038
|
const name = `${parentName} stream`;
|
|
2989
3039
|
const input = setupCommand$a(name, stream.description, argv, importMeta);
|
|
2990
3040
|
if (input) {
|
|
2991
|
-
const apiKey =
|
|
3041
|
+
const apiKey = socketUrl.getDefaultToken();
|
|
2992
3042
|
if (!apiKey) {
|
|
2993
|
-
throw new
|
|
3043
|
+
throw new socketUrl.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
2994
3044
|
}
|
|
2995
|
-
const spinner =
|
|
3045
|
+
const spinner$1 = new spinner.Spinner({
|
|
2996
3046
|
text: 'Streaming scan...'
|
|
2997
3047
|
}).start();
|
|
2998
3048
|
const result = await getOrgFullScan(input.orgSlug, input.fullScanId, input.file, apiKey);
|
|
2999
3049
|
if (result?.success) {
|
|
3000
|
-
spinner.stop(input.file ? `Full scan details written to ${input.file}` : '');
|
|
3050
|
+
spinner$1.stop(input.file ? `Full scan details written to ${input.file}` : '');
|
|
3001
3051
|
} else {
|
|
3002
|
-
handleUnsuccessfulApiResponse('getOrgFullScan', result, spinner);
|
|
3052
|
+
handleUnsuccessfulApiResponse('getOrgFullScan', result, spinner$1);
|
|
3003
3053
|
}
|
|
3004
3054
|
}
|
|
3005
3055
|
}
|
|
@@ -3017,7 +3067,7 @@ function setupCommand$a(name, description, argv, importMeta) {
|
|
|
3017
3067
|
$ ${name} <org slug> <scan ID> <path to output file>
|
|
3018
3068
|
|
|
3019
3069
|
Options
|
|
3020
|
-
${
|
|
3070
|
+
${getFlagListOutput(flags, 6)}
|
|
3021
3071
|
|
|
3022
3072
|
Examples
|
|
3023
3073
|
$ ${name} FakeOrg 000aaaa1-0000-0a0a-00a0-00a0000000a0 ./stream.txt
|
|
@@ -3050,7 +3100,7 @@ function setupCommand$a(name, description, argv, importMeta) {
|
|
|
3050
3100
|
};
|
|
3051
3101
|
}
|
|
3052
3102
|
async function getOrgFullScan(orgSlug, fullScanId, file, apiKey) {
|
|
3053
|
-
const socketSdk = await
|
|
3103
|
+
const socketSdk = await socketUrl.setupSdk(apiKey);
|
|
3054
3104
|
return await handleApiCall(socketSdk.getOrgFullScan(orgSlug, fullScanId, file), 'Streaming a scan');
|
|
3055
3105
|
}
|
|
3056
3106
|
|
|
@@ -3083,14 +3133,14 @@ const auditLog = {
|
|
|
3083
3133
|
const name = parentName + ' audit-log';
|
|
3084
3134
|
const input = setupCommand$9(name, auditLog.description, argv, importMeta);
|
|
3085
3135
|
if (input) {
|
|
3086
|
-
const apiKey =
|
|
3136
|
+
const apiKey = socketUrl.getDefaultToken();
|
|
3087
3137
|
if (!apiKey) {
|
|
3088
|
-
throw new
|
|
3138
|
+
throw new socketUrl.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
3089
3139
|
}
|
|
3090
|
-
const spinner =
|
|
3140
|
+
const spinner$1 = new spinner.Spinner({
|
|
3091
3141
|
text: `Looking up audit log for ${input.orgSlug}\n`
|
|
3092
3142
|
}).start();
|
|
3093
|
-
await fetchOrgAuditLog(input.orgSlug, input, spinner, apiKey);
|
|
3143
|
+
await fetchOrgAuditLog(input.orgSlug, input, spinner$1, apiKey);
|
|
3094
3144
|
}
|
|
3095
3145
|
}
|
|
3096
3146
|
};
|
|
@@ -3128,7 +3178,7 @@ function setupCommand$9(name, description, argv, importMeta) {
|
|
|
3128
3178
|
$ ${name} <org slug>
|
|
3129
3179
|
|
|
3130
3180
|
Options
|
|
3131
|
-
${
|
|
3181
|
+
${getFlagListOutput(flags, 6)}
|
|
3132
3182
|
|
|
3133
3183
|
Examples
|
|
3134
3184
|
$ ${name} FakeOrg
|
|
@@ -3167,7 +3217,7 @@ function setupCommand$9(name, description, argv, importMeta) {
|
|
|
3167
3217
|
};
|
|
3168
3218
|
}
|
|
3169
3219
|
async function fetchOrgAuditLog(orgSlug, input, spinner, apiKey) {
|
|
3170
|
-
const socketSdk = await
|
|
3220
|
+
const socketSdk = await socketUrl.setupSdk(apiKey);
|
|
3171
3221
|
const result = await handleApiCall(socketSdk.getAuditLogEvents(orgSlug, input), `Looking up audit log for ${orgSlug}\n`);
|
|
3172
3222
|
if (!result.success) {
|
|
3173
3223
|
handleUnsuccessfulApiResponse('getAuditLogEvents', result, spinner);
|
|
@@ -3207,15 +3257,15 @@ const create = {
|
|
|
3207
3257
|
const name = `${parentName} create`;
|
|
3208
3258
|
const input = setupCommand$8(name, create.description, argv, importMeta);
|
|
3209
3259
|
if (input) {
|
|
3210
|
-
const apiKey =
|
|
3260
|
+
const apiKey = socketUrl.getDefaultToken();
|
|
3211
3261
|
if (!apiKey) {
|
|
3212
|
-
throw new
|
|
3262
|
+
throw new socketUrl.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
3213
3263
|
}
|
|
3214
3264
|
const spinnerText = 'Creating repository... \n';
|
|
3215
|
-
const spinner =
|
|
3265
|
+
const spinner$1 = new spinner.Spinner({
|
|
3216
3266
|
text: spinnerText
|
|
3217
3267
|
}).start();
|
|
3218
|
-
await createRepo(input.orgSlug, input, spinner, apiKey);
|
|
3268
|
+
await createRepo(input.orgSlug, input, spinner$1, apiKey);
|
|
3219
3269
|
}
|
|
3220
3270
|
}
|
|
3221
3271
|
};
|
|
@@ -3265,7 +3315,7 @@ function setupCommand$8(name, description, argv, importMeta) {
|
|
|
3265
3315
|
$ ${name} <org slug>
|
|
3266
3316
|
|
|
3267
3317
|
Options
|
|
3268
|
-
${
|
|
3318
|
+
${getFlagListOutput(flags, 6)}
|
|
3269
3319
|
|
|
3270
3320
|
Examples
|
|
3271
3321
|
$ ${name} FakeOrg --repoName=test-repo
|
|
@@ -3303,7 +3353,7 @@ function setupCommand$8(name, description, argv, importMeta) {
|
|
|
3303
3353
|
};
|
|
3304
3354
|
}
|
|
3305
3355
|
async function createRepo(orgSlug, input, spinner, apiKey) {
|
|
3306
|
-
const socketSdk = await
|
|
3356
|
+
const socketSdk = await socketUrl.setupSdk(apiKey);
|
|
3307
3357
|
const result = await handleApiCall(socketSdk.createOrgRepo(orgSlug, input), 'creating repository');
|
|
3308
3358
|
if (result.success) {
|
|
3309
3359
|
spinner.success('Repository created successfully');
|
|
@@ -3320,15 +3370,15 @@ const del = {
|
|
|
3320
3370
|
const name = `${parentName} del`;
|
|
3321
3371
|
const input = setupCommand$7(name, del.description, argv, importMeta);
|
|
3322
3372
|
if (input) {
|
|
3323
|
-
const apiKey =
|
|
3373
|
+
const apiKey = socketUrl.getDefaultToken();
|
|
3324
3374
|
if (!apiKey) {
|
|
3325
|
-
throw new
|
|
3375
|
+
throw new socketUrl.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
3326
3376
|
}
|
|
3327
3377
|
const spinnerText = 'Deleting repository... \n';
|
|
3328
|
-
const spinner =
|
|
3378
|
+
const spinner$1 = new spinner.Spinner({
|
|
3329
3379
|
text: spinnerText
|
|
3330
3380
|
}).start();
|
|
3331
|
-
await deleteRepository(input.orgSlug, input.repoName, spinner, apiKey);
|
|
3381
|
+
await deleteRepository(input.orgSlug, input.repoName, spinner$1, apiKey);
|
|
3332
3382
|
}
|
|
3333
3383
|
}
|
|
3334
3384
|
};
|
|
@@ -3366,7 +3416,7 @@ function setupCommand$7(name, description, argv, importMeta) {
|
|
|
3366
3416
|
};
|
|
3367
3417
|
}
|
|
3368
3418
|
async function deleteRepository(orgSlug, repoName, spinner, apiKey) {
|
|
3369
|
-
const socketSdk = await
|
|
3419
|
+
const socketSdk = await socketUrl.setupSdk(apiKey);
|
|
3370
3420
|
const result = await handleApiCall(socketSdk.deleteOrgRepo(orgSlug, repoName), 'deleting repository');
|
|
3371
3421
|
if (result.success) {
|
|
3372
3422
|
spinner.success('Repository deleted successfully');
|
|
@@ -3375,6 +3425,7 @@ async function deleteRepository(orgSlug, repoName, spinner, apiKey) {
|
|
|
3375
3425
|
}
|
|
3376
3426
|
}
|
|
3377
3427
|
|
|
3428
|
+
// @ts-ignore
|
|
3378
3429
|
const list = {
|
|
3379
3430
|
description: 'List repositories in an organization',
|
|
3380
3431
|
async run(argv, importMeta, {
|
|
@@ -3383,15 +3434,15 @@ const list = {
|
|
|
3383
3434
|
const name = `${parentName} list`;
|
|
3384
3435
|
const input = setupCommand$6(name, list.description, argv, importMeta);
|
|
3385
3436
|
if (input) {
|
|
3386
|
-
const apiKey =
|
|
3437
|
+
const apiKey = socketUrl.getDefaultToken();
|
|
3387
3438
|
if (!apiKey) {
|
|
3388
|
-
throw new
|
|
3439
|
+
throw new socketUrl.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
3389
3440
|
}
|
|
3390
3441
|
const spinnerText = 'Listing repositories... \n';
|
|
3391
|
-
const spinner =
|
|
3442
|
+
const spinner$1 = new spinner.Spinner({
|
|
3392
3443
|
text: spinnerText
|
|
3393
3444
|
}).start();
|
|
3394
|
-
await listOrgRepos(input.orgSlug, input, spinner, apiKey);
|
|
3445
|
+
await listOrgRepos(input.orgSlug, input, spinner$1, apiKey);
|
|
3395
3446
|
}
|
|
3396
3447
|
}
|
|
3397
3448
|
};
|
|
@@ -3434,7 +3485,7 @@ function setupCommand$6(name, description, argv, importMeta) {
|
|
|
3434
3485
|
$ ${name} <org slug>
|
|
3435
3486
|
|
|
3436
3487
|
Options
|
|
3437
|
-
${
|
|
3488
|
+
${getFlagListOutput(flags, 6)}
|
|
3438
3489
|
|
|
3439
3490
|
Examples
|
|
3440
3491
|
$ ${name} FakeOrg
|
|
@@ -3467,7 +3518,7 @@ function setupCommand$6(name, description, argv, importMeta) {
|
|
|
3467
3518
|
};
|
|
3468
3519
|
}
|
|
3469
3520
|
async function listOrgRepos(orgSlug, input, spinner, apiKey) {
|
|
3470
|
-
const socketSdk = await
|
|
3521
|
+
const socketSdk = await socketUrl.setupSdk(apiKey);
|
|
3471
3522
|
const result = await handleApiCall(socketSdk.getOrgRepoList(orgSlug, input), 'listing repositories');
|
|
3472
3523
|
if (!result.success) {
|
|
3473
3524
|
handleUnsuccessfulApiResponse('getOrgRepoList', result, spinner);
|
|
@@ -3502,15 +3553,15 @@ const update = {
|
|
|
3502
3553
|
const name = `${parentName} update`;
|
|
3503
3554
|
const input = setupCommand$5(name, update.description, argv, importMeta);
|
|
3504
3555
|
if (input) {
|
|
3505
|
-
const apiKey =
|
|
3556
|
+
const apiKey = socketUrl.getDefaultToken();
|
|
3506
3557
|
if (!apiKey) {
|
|
3507
|
-
throw new
|
|
3558
|
+
throw new socketUrl.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
3508
3559
|
}
|
|
3509
3560
|
const spinnerText = 'Updating repository... \n';
|
|
3510
|
-
const spinner =
|
|
3561
|
+
const spinner$1 = new spinner.Spinner({
|
|
3511
3562
|
text: spinnerText
|
|
3512
3563
|
}).start();
|
|
3513
|
-
await updateRepository(input.orgSlug, input, spinner, apiKey);
|
|
3564
|
+
await updateRepository(input.orgSlug, input, spinner$1, apiKey);
|
|
3514
3565
|
}
|
|
3515
3566
|
}
|
|
3516
3567
|
};
|
|
@@ -3560,7 +3611,7 @@ function setupCommand$5(name, description, argv, importMeta) {
|
|
|
3560
3611
|
$ ${name} <org slug>
|
|
3561
3612
|
|
|
3562
3613
|
Options
|
|
3563
|
-
${
|
|
3614
|
+
${getFlagListOutput(flags, 6)}
|
|
3564
3615
|
|
|
3565
3616
|
Examples
|
|
3566
3617
|
$ ${name} FakeOrg
|
|
@@ -3598,7 +3649,7 @@ function setupCommand$5(name, description, argv, importMeta) {
|
|
|
3598
3649
|
};
|
|
3599
3650
|
}
|
|
3600
3651
|
async function updateRepository(orgSlug, input, spinner, apiKey) {
|
|
3601
|
-
const socketSdk = await
|
|
3652
|
+
const socketSdk = await socketUrl.setupSdk(apiKey);
|
|
3602
3653
|
const result = await handleApiCall(socketSdk.updateOrgRepo(orgSlug, input.name, input), 'updating repository');
|
|
3603
3654
|
if (result.success) {
|
|
3604
3655
|
spinner.success('Repository updated successfully');
|
|
@@ -3607,6 +3658,7 @@ async function updateRepository(orgSlug, input, spinner, apiKey) {
|
|
|
3607
3658
|
}
|
|
3608
3659
|
}
|
|
3609
3660
|
|
|
3661
|
+
// @ts-ignore
|
|
3610
3662
|
const view = {
|
|
3611
3663
|
description: 'View repositories in an organization',
|
|
3612
3664
|
async run(argv, importMeta, {
|
|
@@ -3615,15 +3667,15 @@ const view = {
|
|
|
3615
3667
|
const name = `${parentName} view`;
|
|
3616
3668
|
const input = setupCommand$4(name, view.description, argv, importMeta);
|
|
3617
3669
|
if (input) {
|
|
3618
|
-
const apiKey =
|
|
3670
|
+
const apiKey = socketUrl.getDefaultToken();
|
|
3619
3671
|
if (!apiKey) {
|
|
3620
|
-
throw new
|
|
3672
|
+
throw new socketUrl.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
3621
3673
|
}
|
|
3622
3674
|
const spinnerText = 'Fetching repository... \n';
|
|
3623
|
-
const spinner =
|
|
3675
|
+
const spinner$1 = new spinner.Spinner({
|
|
3624
3676
|
text: spinnerText
|
|
3625
3677
|
}).start();
|
|
3626
|
-
await viewRepository(input.orgSlug, input.repositoryName, spinner, apiKey);
|
|
3678
|
+
await viewRepository(input.orgSlug, input.repositoryName, spinner$1, apiKey);
|
|
3627
3679
|
}
|
|
3628
3680
|
}
|
|
3629
3681
|
};
|
|
@@ -3640,7 +3692,7 @@ function setupCommand$4(name, description, argv, importMeta) {
|
|
|
3640
3692
|
$ ${name} <org slug>
|
|
3641
3693
|
|
|
3642
3694
|
Options
|
|
3643
|
-
${
|
|
3695
|
+
${getFlagListOutput(flags, 6)}
|
|
3644
3696
|
|
|
3645
3697
|
Examples
|
|
3646
3698
|
$ ${name} FakeOrg
|
|
@@ -3671,7 +3723,7 @@ function setupCommand$4(name, description, argv, importMeta) {
|
|
|
3671
3723
|
};
|
|
3672
3724
|
}
|
|
3673
3725
|
async function viewRepository(orgSlug, repoName, spinner, apiKey) {
|
|
3674
|
-
const socketSdk = await
|
|
3726
|
+
const socketSdk = await socketUrl.setupSdk(apiKey);
|
|
3675
3727
|
const result = await handleApiCall(socketSdk.getOrgRepo(orgSlug, repoName), 'fetching repository');
|
|
3676
3728
|
if (!result.success) {
|
|
3677
3729
|
handleUnsuccessfulApiResponse('getOrgRepo', result, spinner);
|
|
@@ -3725,6 +3777,7 @@ const repo = {
|
|
|
3725
3777
|
}
|
|
3726
3778
|
};
|
|
3727
3779
|
|
|
3780
|
+
// @ts-ignore
|
|
3728
3781
|
const dependencies = {
|
|
3729
3782
|
description: 'Search for any dependency that is being used in your organization',
|
|
3730
3783
|
async run(argv, importMeta, {
|
|
@@ -3765,7 +3818,7 @@ function setupCommand$3(name, description, argv, importMeta) {
|
|
|
3765
3818
|
$ ${name}
|
|
3766
3819
|
|
|
3767
3820
|
Options
|
|
3768
|
-
${
|
|
3821
|
+
${getFlagListOutput(flags, 6)}
|
|
3769
3822
|
|
|
3770
3823
|
Examples
|
|
3771
3824
|
$ ${name}
|
|
@@ -3793,23 +3846,23 @@ async function searchDeps({
|
|
|
3793
3846
|
offset,
|
|
3794
3847
|
outputJson
|
|
3795
3848
|
}) {
|
|
3796
|
-
const apiKey =
|
|
3849
|
+
const apiKey = socketUrl.getDefaultToken();
|
|
3797
3850
|
if (!apiKey) {
|
|
3798
|
-
throw new
|
|
3851
|
+
throw new socketUrl.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
3799
3852
|
}
|
|
3800
|
-
const spinner =
|
|
3853
|
+
const spinner$1 = new spinner.Spinner({
|
|
3801
3854
|
text: 'Searching dependencies...'
|
|
3802
3855
|
}).start();
|
|
3803
|
-
const socketSdk = await
|
|
3856
|
+
const socketSdk = await socketUrl.setupSdk(apiKey);
|
|
3804
3857
|
const result = await handleApiCall(socketSdk.searchDependencies({
|
|
3805
3858
|
limit,
|
|
3806
3859
|
offset
|
|
3807
3860
|
}), 'Searching dependencies');
|
|
3808
3861
|
if (!result.success) {
|
|
3809
|
-
handleUnsuccessfulApiResponse('searchDependencies', result, spinner);
|
|
3862
|
+
handleUnsuccessfulApiResponse('searchDependencies', result, spinner$1);
|
|
3810
3863
|
return;
|
|
3811
3864
|
}
|
|
3812
|
-
spinner.stop('Organization dependencies:');
|
|
3865
|
+
spinner$1.stop('Organization dependencies:');
|
|
3813
3866
|
if (outputJson) {
|
|
3814
3867
|
console.log(result.data);
|
|
3815
3868
|
return;
|
|
@@ -3850,18 +3903,18 @@ const analytics = {
|
|
|
3850
3903
|
const name = parentName + ' analytics';
|
|
3851
3904
|
const input = setupCommand$2(name, analytics.description, argv, importMeta);
|
|
3852
3905
|
if (input) {
|
|
3853
|
-
const apiKey =
|
|
3906
|
+
const apiKey = socketUrl.getDefaultToken();
|
|
3854
3907
|
if (!apiKey) {
|
|
3855
|
-
throw new
|
|
3908
|
+
throw new socketUrl.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
3856
3909
|
}
|
|
3857
|
-
const spinner =
|
|
3910
|
+
const spinner$1 = new spinner.Spinner({
|
|
3858
3911
|
text: 'Fetching analytics data'
|
|
3859
3912
|
}).start();
|
|
3860
3913
|
if (input.scope === 'org') {
|
|
3861
|
-
await fetchOrgAnalyticsData(input.time, spinner, apiKey, input.outputJson, input.file);
|
|
3914
|
+
await fetchOrgAnalyticsData(input.time, spinner$1, apiKey, input.outputJson, input.file);
|
|
3862
3915
|
} else {
|
|
3863
3916
|
if (input.repo) {
|
|
3864
|
-
await fetchRepoAnalyticsData(input.repo, input.time, spinner, apiKey, input.outputJson, input.file);
|
|
3917
|
+
await fetchRepoAnalyticsData(input.repo, input.time, spinner$1, apiKey, input.outputJson, input.file);
|
|
3865
3918
|
}
|
|
3866
3919
|
}
|
|
3867
3920
|
}
|
|
@@ -3907,7 +3960,7 @@ function setupCommand$2(name, description, argv, importMeta) {
|
|
|
3907
3960
|
$ ${name} --scope=<scope> --time=<time filter>
|
|
3908
3961
|
|
|
3909
3962
|
Options
|
|
3910
|
-
${
|
|
3963
|
+
${getFlagListOutput(flags, 6)}
|
|
3911
3964
|
|
|
3912
3965
|
Examples
|
|
3913
3966
|
$ ${name} --scope=org --time=7
|
|
@@ -3925,10 +3978,10 @@ function setupCommand$2(name, description, argv, importMeta) {
|
|
|
3925
3978
|
time
|
|
3926
3979
|
} = cli.flags;
|
|
3927
3980
|
if (scope !== 'org' && scope !== 'repo') {
|
|
3928
|
-
throw new
|
|
3981
|
+
throw new socketUrl.InputError("The scope must either be 'org' or 'repo'");
|
|
3929
3982
|
}
|
|
3930
3983
|
if (time !== 7 && time !== 30 && time !== 90) {
|
|
3931
|
-
throw new
|
|
3984
|
+
throw new socketUrl.InputError('The time filter must either be 7, 30 or 90');
|
|
3932
3985
|
}
|
|
3933
3986
|
let showHelp = cli.flags['help'];
|
|
3934
3987
|
if (scope === 'repo' && !repo) {
|
|
@@ -3949,7 +4002,7 @@ function setupCommand$2(name, description, argv, importMeta) {
|
|
|
3949
4002
|
}
|
|
3950
4003
|
const METRICS = ['total_critical_alerts', 'total_high_alerts', 'total_medium_alerts', 'total_low_alerts', 'total_critical_added', 'total_medium_added', 'total_low_added', 'total_high_added', 'total_critical_prevented', 'total_high_prevented', 'total_medium_prevented', 'total_low_prevented'];
|
|
3951
4004
|
async function fetchOrgAnalyticsData(time, spinner, apiKey, outputJson, filePath) {
|
|
3952
|
-
const socketSdk = await
|
|
4005
|
+
const socketSdk = await socketUrl.setupSdk(apiKey);
|
|
3953
4006
|
const result = await handleApiCall(socketSdk.getOrgAnalytics(time.toString()), 'fetching analytics data');
|
|
3954
4007
|
if (result.success === false) {
|
|
3955
4008
|
return handleUnsuccessfulApiResponse('getOrgAnalytics', result, spinner);
|
|
@@ -4062,7 +4115,7 @@ const formatData = (data, scope) => {
|
|
|
4062
4115
|
};
|
|
4063
4116
|
};
|
|
4064
4117
|
async function fetchRepoAnalyticsData(repo, time, spinner, apiKey, outputJson, filePath) {
|
|
4065
|
-
const socketSdk = await
|
|
4118
|
+
const socketSdk = await socketUrl.setupSdk(apiKey);
|
|
4066
4119
|
const result = await handleApiCall(socketSdk.getRepoAnalytics(repo, time.toString()), 'fetching analytics data');
|
|
4067
4120
|
if (result.success === false) {
|
|
4068
4121
|
return handleUnsuccessfulApiResponse('getRepoAnalytics', result, spinner);
|
|
@@ -4150,15 +4203,15 @@ const get = {
|
|
|
4150
4203
|
const name = `${parentName} get`;
|
|
4151
4204
|
const input = setupCommand$1(name, get.description, argv, importMeta);
|
|
4152
4205
|
if (input) {
|
|
4153
|
-
const apiKey =
|
|
4206
|
+
const apiKey = socketUrl.getDefaultToken();
|
|
4154
4207
|
if (!apiKey) {
|
|
4155
|
-
throw new
|
|
4208
|
+
throw new socketUrl.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
4156
4209
|
}
|
|
4157
4210
|
const spinnerText = 'Getting diff scan... \n';
|
|
4158
|
-
const spinner =
|
|
4211
|
+
const spinner$1 = new spinner.Spinner({
|
|
4159
4212
|
text: spinnerText
|
|
4160
4213
|
}).start();
|
|
4161
|
-
await getDiffScan(input, spinner, apiKey);
|
|
4214
|
+
await getDiffScan(input, spinner$1, apiKey);
|
|
4162
4215
|
}
|
|
4163
4216
|
}
|
|
4164
4217
|
};
|
|
@@ -4202,7 +4255,7 @@ function setupCommand$1(name, description, argv, importMeta) {
|
|
|
4202
4255
|
$ ${name} <org slug> --before=<before> --after=<after>
|
|
4203
4256
|
|
|
4204
4257
|
Options
|
|
4205
|
-
${
|
|
4258
|
+
${getFlagListOutput(flags, 6)}
|
|
4206
4259
|
|
|
4207
4260
|
Examples
|
|
4208
4261
|
$ ${name} FakeCorp --before=aaa0aa0a-aaaa-0000-0a0a-0000000a00a0 --after=aaa1aa1a-aaaa-1111-1a1a-1111111a11a1
|
|
@@ -4293,7 +4346,6 @@ const diffScan = {
|
|
|
4293
4346
|
}
|
|
4294
4347
|
};
|
|
4295
4348
|
|
|
4296
|
-
// @ts-ignore
|
|
4297
4349
|
const threatFeed = {
|
|
4298
4350
|
description: 'Look up the threat feed',
|
|
4299
4351
|
async run(argv, importMeta, {
|
|
@@ -4302,14 +4354,14 @@ const threatFeed = {
|
|
|
4302
4354
|
const name = `${parentName} threat-feed`;
|
|
4303
4355
|
const input = setupCommand(name, threatFeed.description, argv, importMeta);
|
|
4304
4356
|
{
|
|
4305
|
-
const apiKey =
|
|
4357
|
+
const apiKey = socketUrl.getDefaultToken();
|
|
4306
4358
|
if (!apiKey) {
|
|
4307
|
-
throw new
|
|
4359
|
+
throw new socketUrl.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
4308
4360
|
}
|
|
4309
|
-
const spinner =
|
|
4361
|
+
const spinner$1 = new spinner.Spinner({
|
|
4310
4362
|
text: 'Looking up the threat feed'
|
|
4311
4363
|
}).start();
|
|
4312
|
-
await fetchThreatFeed(input, spinner, apiKey);
|
|
4364
|
+
await fetchThreatFeed(input, spinner$1, apiKey);
|
|
4313
4365
|
}
|
|
4314
4366
|
}
|
|
4315
4367
|
};
|
|
@@ -4353,7 +4405,7 @@ function setupCommand(name, description, argv, importMeta) {
|
|
|
4353
4405
|
$ ${name}
|
|
4354
4406
|
|
|
4355
4407
|
Options
|
|
4356
|
-
${
|
|
4408
|
+
${getFlagListOutput(flags, 6)}
|
|
4357
4409
|
|
|
4358
4410
|
Examples
|
|
4359
4411
|
$ ${name}
|
|
@@ -4429,7 +4481,7 @@ async function fetchThreatFeed({
|
|
|
4429
4481
|
data: formattedOutput
|
|
4430
4482
|
});
|
|
4431
4483
|
screen.render();
|
|
4432
|
-
screen.key(['escape', 'q', 'C-c'], () => process.exit(0));
|
|
4484
|
+
screen.key(['escape', 'q', 'C-c'], () => process$1.exit(0));
|
|
4433
4485
|
}
|
|
4434
4486
|
const formatResults = data => {
|
|
4435
4487
|
return data.map(d => {
|
|
@@ -4454,6 +4506,7 @@ var cliCommands = {
|
|
|
4454
4506
|
cdxgen: cdxgen,
|
|
4455
4507
|
dependencies: dependencies,
|
|
4456
4508
|
diffScan: diffScan,
|
|
4509
|
+
fix: fix,
|
|
4457
4510
|
info: info,
|
|
4458
4511
|
login: login,
|
|
4459
4512
|
logout: logout,
|
|
@@ -4497,7 +4550,7 @@ void (async () => {
|
|
|
4497
4550
|
argv: ['report', 'create', '--view', '--strict']
|
|
4498
4551
|
}
|
|
4499
4552
|
},
|
|
4500
|
-
argv: process.argv.slice(2),
|
|
4553
|
+
argv: process$1.argv.slice(2),
|
|
4501
4554
|
name: 'socket',
|
|
4502
4555
|
importMeta: {
|
|
4503
4556
|
url: `${require$$0.pathToFileURL(__filename)}`
|
|
@@ -4507,10 +4560,10 @@ void (async () => {
|
|
|
4507
4560
|
let errorBody;
|
|
4508
4561
|
let errorTitle;
|
|
4509
4562
|
let errorMessage = '';
|
|
4510
|
-
if (err instanceof
|
|
4563
|
+
if (err instanceof socketUrl.AuthError) {
|
|
4511
4564
|
errorTitle = 'Authentication error';
|
|
4512
4565
|
errorMessage = err.message;
|
|
4513
|
-
} else if (err instanceof
|
|
4566
|
+
} else if (err instanceof socketUrl.InputError) {
|
|
4514
4567
|
errorTitle = 'Invalid input';
|
|
4515
4568
|
errorMessage = err.message;
|
|
4516
4569
|
errorBody = err.body;
|
|
@@ -4521,10 +4574,10 @@ void (async () => {
|
|
|
4521
4574
|
} else {
|
|
4522
4575
|
errorTitle = 'Unexpected error with no details';
|
|
4523
4576
|
}
|
|
4524
|
-
console.error(`${
|
|
4577
|
+
console.error(`${pathResolve.logSymbols.error} ${colors.bgRed(colors.white(errorTitle + ':'))} ${errorMessage}`);
|
|
4525
4578
|
if (errorBody) {
|
|
4526
4579
|
console.error(`\n${errorBody}`);
|
|
4527
4580
|
}
|
|
4528
|
-
process.exit(1);
|
|
4581
|
+
process$1.exit(1);
|
|
4529
4582
|
}
|
|
4530
4583
|
})();
|