@socketsecurity/cli 0.14.39 → 0.14.40
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 +426 -329
- 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 +1148 -1075
- package/dist/module-sync/path-resolve.d.ts +1 -1
- package/dist/module-sync/path-resolve.js +50 -5
- 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 +24 -0
- package/dist/module-sync/socket-url.js +222 -0
- package/dist/require/cli.js +425 -326
- 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 +27 -25
- 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/module-sync/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 node_url = require('node:url');
|
|
14
15
|
var ponyCause = _socketInterop(require('pony-cause'));
|
|
15
16
|
var updateNotifier = _socketInterop(require('tiny-updater'));
|
|
@@ -20,45 +21,45 @@ 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');
|
|
24
|
+
var spinner = require('@socketsecurity/registry/lib/spinner');
|
|
25
|
+
var spawn = _socketInterop(require('@npmcli/promise-spawn'));
|
|
26
|
+
var objects = require('@socketsecurity/registry/lib/objects');
|
|
27
|
+
var pathResolve = require('./path-resolve.js');
|
|
23
28
|
var meow = _socketInterop(require('meow'));
|
|
24
|
-
var
|
|
25
|
-
var
|
|
26
|
-
var prompts = require('@socketsecurity/registry/lib/prompts');
|
|
27
|
-
var isInteractive = _socketInterop(require('is-interactive'));
|
|
29
|
+
var registryConstants = require('@socketsecurity/registry/lib/constants');
|
|
30
|
+
var socketUrl = require('./socket-url.js');
|
|
28
31
|
var terminalLink = _socketInterop(require('terminal-link'));
|
|
32
|
+
var isInteractive = require('@socketregistry/is-interactive/index.cjs');
|
|
33
|
+
var prompts = require('@socketsecurity/registry/lib/prompts');
|
|
29
34
|
var fs$1 = require('node:fs/promises');
|
|
30
|
-
var spawn = _socketInterop(require('@npmcli/promise-spawn'));
|
|
31
35
|
var npa = _socketInterop(require('npm-package-arg'));
|
|
32
36
|
var semver = _socketInterop(require('semver'));
|
|
33
37
|
var tinyglobby = _socketInterop(require('tinyglobby'));
|
|
34
38
|
var yaml = _socketInterop(require('yaml'));
|
|
35
39
|
var registry = require('@socketsecurity/registry');
|
|
36
|
-
var objects = require('@socketsecurity/registry/lib/objects');
|
|
37
40
|
var packages = require('@socketsecurity/registry/lib/packages');
|
|
38
41
|
var promises = require('@socketsecurity/registry/lib/promises');
|
|
39
42
|
var regexps = require('@socketsecurity/registry/lib/regexps');
|
|
40
43
|
var strings = require('@socketsecurity/registry/lib/strings');
|
|
41
44
|
var browserslist = _socketInterop(require('browserslist'));
|
|
42
45
|
var which = _socketInterop(require('which'));
|
|
43
|
-
var
|
|
44
|
-
var pathResolve = require('./path-resolve.js');
|
|
46
|
+
var index_cjs = require('@socketregistry/hyrious__bun.lockb/index.cjs');
|
|
45
47
|
var betterAjvErrors = _socketInterop(require('@apideck/better-ajv-errors'));
|
|
46
48
|
var config = require('@socketsecurity/config');
|
|
47
|
-
var
|
|
49
|
+
var os = require('node:os');
|
|
48
50
|
var readline = require('node:readline');
|
|
49
|
-
var node_process = require('node:process');
|
|
50
51
|
var readline$1 = require('node:readline/promises');
|
|
51
52
|
var open = _socketInterop(require('open'));
|
|
52
53
|
var chalkTable = _socketInterop(require('chalk-table'));
|
|
53
54
|
var ScreenWidget = _socketInterop(require('blessed/lib/widgets/screen'));
|
|
54
|
-
var BarChart = _socketInterop(require('blessed-contrib/lib/widget/charts/bar'));
|
|
55
55
|
var GridLayout = _socketInterop(require('blessed-contrib/lib/layout/grid'));
|
|
56
|
+
var BarChart = _socketInterop(require('blessed-contrib/lib/widget/charts/bar'));
|
|
56
57
|
var LineChart = _socketInterop(require('blessed-contrib/lib/widget/charts/line'));
|
|
57
58
|
var util = require('node:util');
|
|
58
59
|
var TableWidget = _socketInterop(require('blessed-contrib/lib/widget/table'));
|
|
59
60
|
|
|
60
61
|
const {
|
|
61
|
-
NPM: NPM$
|
|
62
|
+
NPM: NPM$5,
|
|
62
63
|
PNPM: PNPM$2,
|
|
63
64
|
cdxgenBinPath,
|
|
64
65
|
synpBinPath
|
|
@@ -69,10 +70,10 @@ const {
|
|
|
69
70
|
SBOM_SIGN_PRIVATE_KEY,
|
|
70
71
|
// Location to the RSA private key
|
|
71
72
|
SBOM_SIGN_PUBLIC_KEY // Optional. Location to the RSA public key
|
|
72
|
-
} = process.env;
|
|
73
|
+
} = process$1.env;
|
|
73
74
|
const toLower = arg => arg.toLowerCase();
|
|
74
75
|
const arrayToLower = arg => arg.map(toLower);
|
|
75
|
-
const nodejsPlatformTypes = new Set(['javascript', 'js', 'nodejs', NPM$
|
|
76
|
+
const nodejsPlatformTypes = new Set(['javascript', 'js', 'nodejs', NPM$5, PNPM$2, 'ts', 'tsx', 'typescript']);
|
|
76
77
|
const yargsConfig = {
|
|
77
78
|
configuration: {
|
|
78
79
|
'camel-case-expansion': false,
|
|
@@ -176,20 +177,20 @@ const cdxgen = {
|
|
|
176
177
|
length: unknownLength
|
|
177
178
|
} = unknown;
|
|
178
179
|
if (unknownLength) {
|
|
180
|
+
process$1.exitCode = 1;
|
|
179
181
|
console.error(`Unknown ${words.pluralize('argument', unknownLength)}: ${yargv._.join(', ')}`);
|
|
180
|
-
process.exitCode = 1;
|
|
181
182
|
return;
|
|
182
183
|
}
|
|
183
184
|
let cleanupPackageLock = false;
|
|
184
185
|
if (yargv.type !== 'yarn' && nodejsPlatformTypes.has(yargv.type) && fs.existsSync('./yarn.lock')) {
|
|
185
186
|
if (fs.existsSync('./package-lock.json')) {
|
|
186
|
-
yargv.type = NPM$
|
|
187
|
+
yargv.type = NPM$5;
|
|
187
188
|
} else {
|
|
188
189
|
// Use synp to create a package-lock.json from the yarn.lock,
|
|
189
190
|
// based on the node_modules folder, for a more accurate SBOM.
|
|
190
191
|
try {
|
|
191
192
|
await npm$1.runBin(await fs.promises.realpath(synpBinPath), ['--source-file', './yarn.lock']);
|
|
192
|
-
yargv.type = NPM$
|
|
193
|
+
yargv.type = NPM$5;
|
|
193
194
|
cleanupPackageLock = true;
|
|
194
195
|
} catch {}
|
|
195
196
|
}
|
|
@@ -211,13 +212,82 @@ const cdxgen = {
|
|
|
211
212
|
await fs.promises.rm('./package-lock.json');
|
|
212
213
|
} catch {}
|
|
213
214
|
}
|
|
214
|
-
const fullOutputPath = path.join(process.cwd(), yargv.output);
|
|
215
|
+
const fullOutputPath = path.join(process$1.cwd(), yargv.output);
|
|
215
216
|
if (fs.existsSync(fullOutputPath)) {
|
|
216
217
|
console.log(colors.cyanBright(`${yargv.output} created!`));
|
|
217
218
|
}
|
|
218
219
|
}
|
|
219
220
|
};
|
|
220
221
|
|
|
222
|
+
const {
|
|
223
|
+
abortSignal: abortSignal$3
|
|
224
|
+
} = constants;
|
|
225
|
+
function shadowNpmInstall(opts) {
|
|
226
|
+
const {
|
|
227
|
+
flags = [],
|
|
228
|
+
ipc,
|
|
229
|
+
...spawnOptions
|
|
230
|
+
} = {
|
|
231
|
+
__proto__: null,
|
|
232
|
+
...opts
|
|
233
|
+
};
|
|
234
|
+
const useIpc = objects.isObject(ipc);
|
|
235
|
+
const useDebug = pathResolve.isDebug();
|
|
236
|
+
const promise = spawn(
|
|
237
|
+
// Lazily access constants.execPath.
|
|
238
|
+
constants.execPath, [
|
|
239
|
+
// Lazily access constants.rootBinPath.
|
|
240
|
+
path.join(constants.rootBinPath, 'npm-cli.js'), 'install',
|
|
241
|
+
// Even though the 'silent' flag is passed npm will still run through code
|
|
242
|
+
// paths for 'audit' and 'fund' unless '--no-audit' and '--no-fund' flags
|
|
243
|
+
// are passed.
|
|
244
|
+
...(useDebug ? ['--no-audit', '--no-fund'] : ['silent', '--no-audit', '--no-fund']), ...flags], {
|
|
245
|
+
signal: abortSignal$3,
|
|
246
|
+
// Set stdio to include 'ipc'.
|
|
247
|
+
// See https://github.com/nodejs/node/blob/v23.6.0/lib/child_process.js#L161-L166
|
|
248
|
+
// and https://github.com/nodejs/node/blob/v23.6.0/lib/internal/child_process.js#L238.
|
|
249
|
+
stdio: useDebug ?
|
|
250
|
+
// 'inherit'
|
|
251
|
+
useIpc ? [0, 1, 2, 'ipc'] : 'inherit' :
|
|
252
|
+
// 'ignore'
|
|
253
|
+
useIpc ? ['ignore', 'ignore', 'ignore', 'ipc'] : 'ignore',
|
|
254
|
+
...spawnOptions,
|
|
255
|
+
env: {
|
|
256
|
+
...process$1.env,
|
|
257
|
+
...spawnOptions.env
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
if (useIpc) {
|
|
261
|
+
promise.process.send(ipc);
|
|
262
|
+
}
|
|
263
|
+
return promise;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
const {
|
|
267
|
+
SOCKET_CLI_FIX_PACKAGE_LOCK_FILE,
|
|
268
|
+
SOCKET_IPC_HANDSHAKE: SOCKET_IPC_HANDSHAKE$1
|
|
269
|
+
} = constants;
|
|
270
|
+
const fix = {
|
|
271
|
+
description: 'Fix "fixable" Socket alerts',
|
|
272
|
+
hidden: true,
|
|
273
|
+
async run() {
|
|
274
|
+
const spinner$1 = new spinner.Spinner().start();
|
|
275
|
+
try {
|
|
276
|
+
await shadowNpmInstall({
|
|
277
|
+
ipc: {
|
|
278
|
+
[SOCKET_IPC_HANDSHAKE$1]: {
|
|
279
|
+
[SOCKET_CLI_FIX_PACKAGE_LOCK_FILE]: true
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
} catch (e) {
|
|
284
|
+
console.error(e);
|
|
285
|
+
} finally {
|
|
286
|
+
spinner$1.stop();
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
|
|
221
291
|
const commonFlags = {
|
|
222
292
|
help: {
|
|
223
293
|
type: 'boolean',
|
|
@@ -274,10 +344,10 @@ function handleUnsuccessfulApiResponse(_name, result, spinner) {
|
|
|
274
344
|
const message = typeof resultErrorMessage === 'string' ? resultErrorMessage : 'No error message returned';
|
|
275
345
|
if (result.status === 401 || result.status === 403) {
|
|
276
346
|
spinner.stop();
|
|
277
|
-
throw new
|
|
347
|
+
throw new socketUrl.AuthError(message);
|
|
278
348
|
}
|
|
279
349
|
spinner.error(`${colors.bgRed(colors.white('API returned an error:'))} ${message}`);
|
|
280
|
-
process.exit(1);
|
|
350
|
+
process$1.exit(1);
|
|
281
351
|
}
|
|
282
352
|
async function handleApiCall(value, description) {
|
|
283
353
|
let result;
|
|
@@ -322,6 +392,46 @@ function pick(input, keys) {
|
|
|
322
392
|
return result;
|
|
323
393
|
}
|
|
324
394
|
|
|
395
|
+
function getFlagListOutput(list, indent, {
|
|
396
|
+
keyPrefix = '--',
|
|
397
|
+
padName
|
|
398
|
+
} = {}) {
|
|
399
|
+
return getHelpListOutput({
|
|
400
|
+
...list
|
|
401
|
+
}, indent, {
|
|
402
|
+
keyPrefix,
|
|
403
|
+
padName
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
function getHelpListOutput(list, indent, {
|
|
407
|
+
keyPrefix = '',
|
|
408
|
+
padName = 18
|
|
409
|
+
} = {}) {
|
|
410
|
+
let result = '';
|
|
411
|
+
const names = Object.keys(list).sort();
|
|
412
|
+
for (const name of names) {
|
|
413
|
+
const rawDescription = list[name];
|
|
414
|
+
const description = (typeof rawDescription === 'object' ? rawDescription.description : rawDescription) || '';
|
|
415
|
+
result += ''.padEnd(indent) + (keyPrefix + name).padEnd(padName) + description + '\n';
|
|
416
|
+
}
|
|
417
|
+
return result.trim();
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
function stringJoinWithSeparateFinalSeparator(list, separator = ' and ') {
|
|
421
|
+
const values = list.filter(Boolean);
|
|
422
|
+
const {
|
|
423
|
+
length
|
|
424
|
+
} = values;
|
|
425
|
+
if (!length) {
|
|
426
|
+
return '';
|
|
427
|
+
}
|
|
428
|
+
if (length === 1) {
|
|
429
|
+
return values[0];
|
|
430
|
+
}
|
|
431
|
+
const finalValue = values.pop();
|
|
432
|
+
return `${values.join(', ')}${separator}${finalValue}`;
|
|
433
|
+
}
|
|
434
|
+
|
|
325
435
|
const SEVERITIES_BY_ORDER = ['critical', 'high', 'middle', 'low'];
|
|
326
436
|
function getDesiredSeverities(lowestToInclude) {
|
|
327
437
|
const result = [];
|
|
@@ -340,7 +450,7 @@ function formatSeverityCount(severityCount) {
|
|
|
340
450
|
summary.push(`${severityCount[severity]} ${severity}`);
|
|
341
451
|
}
|
|
342
452
|
}
|
|
343
|
-
return
|
|
453
|
+
return stringJoinWithSeparateFinalSeparator(summary);
|
|
344
454
|
}
|
|
345
455
|
function getSeverityCount(issues, lowestToInclude) {
|
|
346
456
|
const severityCount = pick({
|
|
@@ -350,7 +460,9 @@ function getSeverityCount(issues, lowestToInclude) {
|
|
|
350
460
|
critical: 0
|
|
351
461
|
}, getDesiredSeverities(lowestToInclude));
|
|
352
462
|
for (const issue of issues) {
|
|
353
|
-
const
|
|
463
|
+
const {
|
|
464
|
+
value
|
|
465
|
+
} = issue;
|
|
354
466
|
if (!value) {
|
|
355
467
|
continue;
|
|
356
468
|
}
|
|
@@ -361,34 +473,9 @@ function getSeverityCount(issues, lowestToInclude) {
|
|
|
361
473
|
return severityCount;
|
|
362
474
|
}
|
|
363
475
|
|
|
364
|
-
function printFlagList(list, indent, {
|
|
365
|
-
keyPrefix = '--',
|
|
366
|
-
padName
|
|
367
|
-
} = {}) {
|
|
368
|
-
return printHelpList({
|
|
369
|
-
...list
|
|
370
|
-
}, indent, {
|
|
371
|
-
keyPrefix,
|
|
372
|
-
padName
|
|
373
|
-
});
|
|
374
|
-
}
|
|
375
|
-
function printHelpList(list, indent, {
|
|
376
|
-
keyPrefix = '',
|
|
377
|
-
padName = 18
|
|
378
|
-
} = {}) {
|
|
379
|
-
let result = '';
|
|
380
|
-
const names = Object.keys(list).sort();
|
|
381
|
-
for (const name of names) {
|
|
382
|
-
const rawDescription = list[name];
|
|
383
|
-
const description = (typeof rawDescription === 'object' ? rawDescription.description : rawDescription) || '';
|
|
384
|
-
result += ''.padEnd(indent) + (keyPrefix + name).padEnd(padName) + description + '\n';
|
|
385
|
-
}
|
|
386
|
-
return result.trim();
|
|
387
|
-
}
|
|
388
|
-
|
|
389
476
|
const {
|
|
390
|
-
|
|
391
|
-
} =
|
|
477
|
+
NPM: NPM$4
|
|
478
|
+
} = registryConstants;
|
|
392
479
|
const info = {
|
|
393
480
|
description: 'Look up info regarding a package',
|
|
394
481
|
async run(argv, importMeta, {
|
|
@@ -398,15 +485,15 @@ const info = {
|
|
|
398
485
|
const commandContext = setupCommand$m(name, info.description, argv, importMeta);
|
|
399
486
|
if (commandContext) {
|
|
400
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}`;
|
|
401
|
-
const spinner =
|
|
488
|
+
const spinner$1 = new spinner.Spinner({
|
|
402
489
|
text: spinnerText
|
|
403
490
|
}).start();
|
|
404
|
-
const packageData = await fetchPackageData(commandContext.pkgName, commandContext.pkgVersion, commandContext, spinner);
|
|
491
|
+
const packageData = await fetchPackageData(commandContext.pkgName, commandContext.pkgVersion, commandContext, spinner$1);
|
|
405
492
|
if (packageData) {
|
|
406
493
|
formatPackageDataOutput(packageData, {
|
|
407
494
|
name,
|
|
408
495
|
...commandContext
|
|
409
|
-
}, spinner);
|
|
496
|
+
}, spinner$1);
|
|
410
497
|
}
|
|
411
498
|
}
|
|
412
499
|
}
|
|
@@ -425,7 +512,7 @@ function setupCommand$m(name, description, argv, importMeta) {
|
|
|
425
512
|
$ ${name} <name>
|
|
426
513
|
|
|
427
514
|
Options
|
|
428
|
-
${
|
|
515
|
+
${getFlagListOutput(flags, 6)}
|
|
429
516
|
|
|
430
517
|
Examples
|
|
431
518
|
$ ${name} webtorrent
|
|
@@ -437,7 +524,7 @@ function setupCommand$m(name, description, argv, importMeta) {
|
|
|
437
524
|
flags
|
|
438
525
|
});
|
|
439
526
|
if (cli.input.length > 1) {
|
|
440
|
-
throw new
|
|
527
|
+
throw new socketUrl.InputError('Only one package lookup supported at once');
|
|
441
528
|
}
|
|
442
529
|
const {
|
|
443
530
|
0: rawPkgName = ''
|
|
@@ -465,7 +552,7 @@ function setupCommand$m(name, description, argv, importMeta) {
|
|
|
465
552
|
async function fetchPackageData(pkgName, pkgVersion, {
|
|
466
553
|
includeAllIssues
|
|
467
554
|
}, spinner) {
|
|
468
|
-
const socketSdk = await
|
|
555
|
+
const socketSdk = await socketUrl.setupSdk(socketUrl.getPublicToken());
|
|
469
556
|
const result = await handleApiCall(socketSdk.getIssuesByNPMPackage(pkgName, pkgVersion), 'looking up package');
|
|
470
557
|
const scoreResult = await handleApiCall(socketSdk.getScoreByNPMPackage(pkgName, pkgVersion), 'looking up package score');
|
|
471
558
|
if (result.success === false) {
|
|
@@ -512,8 +599,8 @@ function formatPackageDataOutput({
|
|
|
512
599
|
} else {
|
|
513
600
|
spinner.success('Package has no issues');
|
|
514
601
|
}
|
|
515
|
-
const format = new
|
|
516
|
-
const url =
|
|
602
|
+
const format = new socketUrl.ColorOrMarkdown(!!outputMarkdown);
|
|
603
|
+
const url = socketUrl.getSocketDevPackageOverviewUrl(NPM$4, pkgName, pkgVersion);
|
|
517
604
|
console.log('\n');
|
|
518
605
|
if (pkgVersion === 'latest') {
|
|
519
606
|
console.log(`Detailed info on socket.dev: ${format.hyperlink(`${pkgName}`, url, {
|
|
@@ -529,7 +616,7 @@ function formatPackageDataOutput({
|
|
|
529
616
|
}
|
|
530
617
|
}
|
|
531
618
|
if (strict && objectSome(severityCount)) {
|
|
532
|
-
process.exit(1);
|
|
619
|
+
process$1.exit(1);
|
|
533
620
|
}
|
|
534
621
|
}
|
|
535
622
|
function formatPackageIssuesDetails(packageData, outputMarkdown) {
|
|
@@ -550,9 +637,9 @@ function formatPackageIssuesDetails(packageData, outputMarkdown) {
|
|
|
550
637
|
}
|
|
551
638
|
return acc;
|
|
552
639
|
}, {});
|
|
553
|
-
const format = new
|
|
640
|
+
const format = new socketUrl.ColorOrMarkdown(!!outputMarkdown);
|
|
554
641
|
for (const issue of Object.keys(uniqueIssues)) {
|
|
555
|
-
const issueWithLink = format.hyperlink(`${uniqueIssues[issue]?.label}`,
|
|
642
|
+
const issueWithLink = format.hyperlink(`${uniqueIssues[issue]?.label}`, socketUrl.getSocketDevAlertUrl(issue), {
|
|
556
643
|
fallbackToUrl: true
|
|
557
644
|
});
|
|
558
645
|
if (uniqueIssues[issue]?.count === 1) {
|
|
@@ -572,7 +659,7 @@ function formatScore(score) {
|
|
|
572
659
|
}
|
|
573
660
|
|
|
574
661
|
const {
|
|
575
|
-
|
|
662
|
+
SOCKET_PUBLIC_API_TOKEN
|
|
576
663
|
} = constants;
|
|
577
664
|
const description$5 = 'Socket API login';
|
|
578
665
|
const flags = {
|
|
@@ -601,7 +688,7 @@ const login = {
|
|
|
601
688
|
Logs into the Socket API by prompting for an API key
|
|
602
689
|
|
|
603
690
|
Options
|
|
604
|
-
${
|
|
691
|
+
${getFlagListOutput({
|
|
605
692
|
'api-base-url': flags['apiBaseUrl'].description,
|
|
606
693
|
'api-proxy': flags['apiProxy'].description
|
|
607
694
|
}, 8)}
|
|
@@ -623,29 +710,29 @@ const login = {
|
|
|
623
710
|
return;
|
|
624
711
|
}
|
|
625
712
|
if (!isInteractive()) {
|
|
626
|
-
throw new
|
|
713
|
+
throw new socketUrl.InputError('Cannot prompt for credentials in a non-interactive shell');
|
|
627
714
|
}
|
|
628
|
-
const
|
|
715
|
+
const apiToken = (await prompts.password({
|
|
629
716
|
message: `Enter your ${terminalLink('Socket.dev API key', 'https://docs.socket.dev/docs/api-keys')} (leave blank for a public key)`
|
|
630
|
-
})) ||
|
|
717
|
+
})) || SOCKET_PUBLIC_API_TOKEN;
|
|
631
718
|
let apiBaseUrl = cli.flags['apiBaseUrl'];
|
|
632
|
-
apiBaseUrl ??=
|
|
719
|
+
apiBaseUrl ??= socketUrl.getSetting('apiBaseUrl') ?? undefined;
|
|
633
720
|
let apiProxy = cli.flags['apiProxy'];
|
|
634
|
-
apiProxy ??=
|
|
635
|
-
const spinner =
|
|
721
|
+
apiProxy ??= socketUrl.getSetting('apiProxy') ?? undefined;
|
|
722
|
+
const spinner$1 = new spinner.Spinner({
|
|
636
723
|
text: 'Verifying API key...'
|
|
637
724
|
}).start();
|
|
638
725
|
let orgs;
|
|
639
726
|
try {
|
|
640
|
-
const sdk
|
|
641
|
-
const result = await sdk
|
|
727
|
+
const sdk = await socketUrl.setupSdk(apiToken, apiBaseUrl, apiProxy);
|
|
728
|
+
const result = await sdk.getOrganizations();
|
|
642
729
|
if (!result.success) {
|
|
643
|
-
throw new
|
|
730
|
+
throw new socketUrl.AuthError();
|
|
644
731
|
}
|
|
645
732
|
orgs = result.data;
|
|
646
|
-
spinner.success('API key verified');
|
|
733
|
+
spinner$1.success('API key verified');
|
|
647
734
|
} catch {
|
|
648
|
-
spinner.error('Invalid API key');
|
|
735
|
+
spinner$1.error('Invalid API key');
|
|
649
736
|
return;
|
|
650
737
|
}
|
|
651
738
|
const enforcedChoices = Object.values(orgs.organizations).filter(nonNullish).filter(org => org.plan === 'enterprise').map(org => ({
|
|
@@ -677,12 +764,13 @@ const login = {
|
|
|
677
764
|
}
|
|
678
765
|
}
|
|
679
766
|
}
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
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'}`);
|
|
686
774
|
}
|
|
687
775
|
};
|
|
688
776
|
|
|
@@ -714,11 +802,11 @@ const logout = {
|
|
|
714
802
|
cli.showHelp();
|
|
715
803
|
return;
|
|
716
804
|
}
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
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');
|
|
722
810
|
}
|
|
723
811
|
};
|
|
724
812
|
|
|
@@ -753,7 +841,7 @@ function existsSync(filepath) {
|
|
|
753
841
|
return false;
|
|
754
842
|
}
|
|
755
843
|
async function findUp(name, {
|
|
756
|
-
cwd = process.cwd()
|
|
844
|
+
cwd = process$1.cwd()
|
|
757
845
|
}) {
|
|
758
846
|
let dir = path.resolve(cwd);
|
|
759
847
|
const {
|
|
@@ -795,6 +883,7 @@ const {
|
|
|
795
883
|
NPM: NPM$2,
|
|
796
884
|
PNPM: PNPM$1,
|
|
797
885
|
VLT: VLT$1,
|
|
886
|
+
YARN,
|
|
798
887
|
YARN_BERRY: YARN_BERRY$1,
|
|
799
888
|
YARN_CLASSIC: YARN_CLASSIC$1
|
|
800
889
|
} = constants;
|
|
@@ -805,10 +894,20 @@ const {
|
|
|
805
894
|
numeric: true,
|
|
806
895
|
sensitivity: 'base'
|
|
807
896
|
});
|
|
897
|
+
const binByAgent = {
|
|
898
|
+
__proto__: null,
|
|
899
|
+
[BUN$1]: BUN$1,
|
|
900
|
+
[NPM$2]: NPM$2,
|
|
901
|
+
[PNPM$1]: PNPM$1,
|
|
902
|
+
[YARN_BERRY$1]: YARN,
|
|
903
|
+
[YARN_CLASSIC$1]: YARN,
|
|
904
|
+
[VLT$1]: VLT$1
|
|
905
|
+
};
|
|
808
906
|
async function getAgentExecPath(agent) {
|
|
809
|
-
|
|
907
|
+
const binName = binByAgent[agent];
|
|
908
|
+
return (await which(binName, {
|
|
810
909
|
nothrow: true
|
|
811
|
-
})) ??
|
|
910
|
+
})) ?? binName;
|
|
812
911
|
}
|
|
813
912
|
async function getAgentVersion(agentExecPath, cwd) {
|
|
814
913
|
let result;
|
|
@@ -864,7 +963,7 @@ const readLockFileByAgent = (() => {
|
|
|
864
963
|
const lockBuffer = await binaryReader(lockPath);
|
|
865
964
|
if (lockBuffer) {
|
|
866
965
|
try {
|
|
867
|
-
return
|
|
966
|
+
return index_cjs.parse(lockBuffer);
|
|
868
967
|
} catch {}
|
|
869
968
|
}
|
|
870
969
|
// To print a Yarn lockfile to your console without writing it to disk
|
|
@@ -882,7 +981,7 @@ const readLockFileByAgent = (() => {
|
|
|
882
981
|
};
|
|
883
982
|
})();
|
|
884
983
|
async function detect({
|
|
885
|
-
cwd = process.cwd(),
|
|
984
|
+
cwd = process$1.cwd(),
|
|
886
985
|
onUnknown
|
|
887
986
|
} = {}) {
|
|
888
987
|
let lockPath = await findUp(Object.keys(LOCKS), {
|
|
@@ -989,25 +1088,25 @@ const {
|
|
|
989
1088
|
BUN,
|
|
990
1089
|
LOCK_EXT,
|
|
991
1090
|
NPM: NPM$1,
|
|
1091
|
+
OVERRIDES,
|
|
992
1092
|
PNPM,
|
|
993
|
-
|
|
1093
|
+
RESOLUTIONS,
|
|
1094
|
+
SOCKET_CLI_UPDATE_OVERRIDES_IN_PACKAGE_LOCK_FILE,
|
|
1095
|
+
SOCKET_IPC_HANDSHAKE,
|
|
994
1096
|
VLT,
|
|
995
1097
|
YARN_BERRY,
|
|
996
1098
|
YARN_CLASSIC,
|
|
997
|
-
abortSignal: abortSignal$2
|
|
998
|
-
execPath,
|
|
999
|
-
rootBinPath
|
|
1099
|
+
abortSignal: abortSignal$2
|
|
1000
1100
|
} = constants;
|
|
1001
1101
|
const COMMAND_TITLE = 'Socket Optimize';
|
|
1002
|
-
const OVERRIDES_FIELD_NAME = 'overrides';
|
|
1003
1102
|
const NPM_OVERRIDE_PR_URL = 'https://github.com/npm/cli/pull/7025';
|
|
1004
1103
|
const PNPM_FIELD_NAME = PNPM;
|
|
1005
1104
|
const PNPM_WORKSPACE = `${PNPM}-workspace`;
|
|
1006
|
-
const RESOLUTIONS_FIELD_NAME = 'resolutions';
|
|
1007
1105
|
const manifestNpmOverrides = registry.getManifestData(NPM$1);
|
|
1008
1106
|
const getOverridesDataByAgent = {
|
|
1107
|
+
__proto__: null,
|
|
1009
1108
|
[BUN](pkgJson) {
|
|
1010
|
-
const overrides = pkgJson?.
|
|
1109
|
+
const overrides = pkgJson?.[RESOLUTIONS] ?? {};
|
|
1011
1110
|
return {
|
|
1012
1111
|
type: YARN_BERRY,
|
|
1013
1112
|
overrides
|
|
@@ -1016,7 +1115,7 @@ const getOverridesDataByAgent = {
|
|
|
1016
1115
|
// npm overrides documentation:
|
|
1017
1116
|
// https://docs.npmjs.com/cli/v10/configuring-npm/package-json#overrides
|
|
1018
1117
|
[NPM$1](pkgJson) {
|
|
1019
|
-
const overrides = pkgJson?.
|
|
1118
|
+
const overrides = pkgJson?.[OVERRIDES] ?? {};
|
|
1020
1119
|
return {
|
|
1021
1120
|
type: NPM$1,
|
|
1022
1121
|
overrides
|
|
@@ -1025,14 +1124,14 @@ const getOverridesDataByAgent = {
|
|
|
1025
1124
|
// pnpm overrides documentation:
|
|
1026
1125
|
// https://pnpm.io/package_json#pnpmoverrides
|
|
1027
1126
|
[PNPM](pkgJson) {
|
|
1028
|
-
const overrides = pkgJson?.pnpm?.
|
|
1127
|
+
const overrides = pkgJson?.pnpm?.[OVERRIDES] ?? {};
|
|
1029
1128
|
return {
|
|
1030
1129
|
type: PNPM,
|
|
1031
1130
|
overrides
|
|
1032
1131
|
};
|
|
1033
1132
|
},
|
|
1034
1133
|
[VLT](pkgJson) {
|
|
1035
|
-
const overrides = pkgJson?.
|
|
1134
|
+
const overrides = pkgJson?.[OVERRIDES] ?? {};
|
|
1036
1135
|
return {
|
|
1037
1136
|
type: VLT,
|
|
1038
1137
|
overrides
|
|
@@ -1041,7 +1140,7 @@ const getOverridesDataByAgent = {
|
|
|
1041
1140
|
// Yarn resolutions documentation:
|
|
1042
1141
|
// https://yarnpkg.com/configuration/manifest#resolutions
|
|
1043
1142
|
[YARN_BERRY](pkgJson) {
|
|
1044
|
-
const overrides = pkgJson?.
|
|
1143
|
+
const overrides = pkgJson?.[RESOLUTIONS] ?? {};
|
|
1045
1144
|
return {
|
|
1046
1145
|
type: YARN_BERRY,
|
|
1047
1146
|
overrides
|
|
@@ -1050,7 +1149,7 @@ const getOverridesDataByAgent = {
|
|
|
1050
1149
|
// Yarn resolutions documentation:
|
|
1051
1150
|
// https://classic.yarnpkg.com/en/docs/selective-version-resolutions
|
|
1052
1151
|
[YARN_CLASSIC](pkgJson) {
|
|
1053
|
-
const overrides = pkgJson?.
|
|
1152
|
+
const overrides = pkgJson?.[RESOLUTIONS] ?? {};
|
|
1054
1153
|
return {
|
|
1055
1154
|
type: YARN_CLASSIC,
|
|
1056
1155
|
overrides
|
|
@@ -1074,6 +1173,7 @@ const lockIncludesByAgent = (() => {
|
|
|
1074
1173
|
`(?<=(?:^\\s*|,\\s*)"?)${escapedName}(?=@)`, 'm').test(lockSrc);
|
|
1075
1174
|
}
|
|
1076
1175
|
return {
|
|
1176
|
+
__proto__: null,
|
|
1077
1177
|
[BUN](lockSrc, name, lockBasename) {
|
|
1078
1178
|
// This is a bit counterintuitive. When lockBasename ends with a .lockb
|
|
1079
1179
|
// we treat it as a yarn.lock. When lockBasename ends with a .lock we
|
|
@@ -1137,7 +1237,7 @@ const updateManifestByAgent = (() => {
|
|
|
1137
1237
|
[field]: undefined
|
|
1138
1238
|
});
|
|
1139
1239
|
}
|
|
1140
|
-
} else if (field ===
|
|
1240
|
+
} else if (field === OVERRIDES || field === RESOLUTIONS) {
|
|
1141
1241
|
// Properties with undefined values are omitted when saved as JSON.
|
|
1142
1242
|
editablePkgJson.update({
|
|
1143
1243
|
[field]: objects.hasKeys(value) ? value : undefined
|
|
@@ -1149,7 +1249,7 @@ const updateManifestByAgent = (() => {
|
|
|
1149
1249
|
}
|
|
1150
1250
|
return;
|
|
1151
1251
|
}
|
|
1152
|
-
if ((field ===
|
|
1252
|
+
if ((field === OVERRIDES || field === PNPM_FIELD_NAME || field === RESOLUTIONS) && !objects.hasKeys(value)) {
|
|
1153
1253
|
return;
|
|
1154
1254
|
}
|
|
1155
1255
|
// Since the field doesn't exist we want to insert it into the package.json
|
|
@@ -1158,17 +1258,17 @@ const updateManifestByAgent = (() => {
|
|
|
1158
1258
|
const entries = Object.entries(pkgJson);
|
|
1159
1259
|
let insertIndex = -1;
|
|
1160
1260
|
let isPlacingHigher = false;
|
|
1161
|
-
if (field ===
|
|
1162
|
-
insertIndex = getLowestEntryIndex(entries, [
|
|
1261
|
+
if (field === OVERRIDES) {
|
|
1262
|
+
insertIndex = getLowestEntryIndex(entries, [RESOLUTIONS]);
|
|
1163
1263
|
if (insertIndex === -1) {
|
|
1164
1264
|
isPlacingHigher = true;
|
|
1165
1265
|
insertIndex = getHighestEntryIndex(entries, [...depFields, PNPM]);
|
|
1166
1266
|
}
|
|
1167
|
-
} else if (field ===
|
|
1267
|
+
} else if (field === RESOLUTIONS) {
|
|
1168
1268
|
isPlacingHigher = true;
|
|
1169
|
-
insertIndex = getHighestEntryIndex(entries, [...depFields,
|
|
1269
|
+
insertIndex = getHighestEntryIndex(entries, [...depFields, OVERRIDES, PNPM]);
|
|
1170
1270
|
} else if (field === PNPM_FIELD_NAME) {
|
|
1171
|
-
insertIndex = getLowestEntryIndex(entries, [
|
|
1271
|
+
insertIndex = getLowestEntryIndex(entries, [OVERRIDES, RESOLUTIONS]);
|
|
1172
1272
|
if (insertIndex === -1) {
|
|
1173
1273
|
isPlacingHigher = true;
|
|
1174
1274
|
insertIndex = getHighestEntryIndex(entries, depFields);
|
|
@@ -1190,12 +1290,13 @@ const updateManifestByAgent = (() => {
|
|
|
1190
1290
|
editablePkgJson.fromJSON(`${JSON.stringify(Object.fromEntries(entries), null, 2)}\n`);
|
|
1191
1291
|
}
|
|
1192
1292
|
function updateOverrides(editablePkgJson, overrides) {
|
|
1193
|
-
updatePkgJson(editablePkgJson,
|
|
1293
|
+
updatePkgJson(editablePkgJson, OVERRIDES, overrides);
|
|
1194
1294
|
}
|
|
1195
1295
|
function updateResolutions(editablePkgJson, overrides) {
|
|
1196
|
-
updatePkgJson(editablePkgJson,
|
|
1296
|
+
updatePkgJson(editablePkgJson, RESOLUTIONS, overrides);
|
|
1197
1297
|
}
|
|
1198
1298
|
return {
|
|
1299
|
+
__proto__: null,
|
|
1199
1300
|
[BUN]: updateResolutions,
|
|
1200
1301
|
[NPM$1]: updateOverrides,
|
|
1201
1302
|
[PNPM](editablePkgJson, overrides) {
|
|
@@ -1257,6 +1358,7 @@ const lsByAgent = (() => {
|
|
|
1257
1358
|
return cleanupQueryStdout(stdout);
|
|
1258
1359
|
}
|
|
1259
1360
|
return {
|
|
1361
|
+
__proto__: null,
|
|
1260
1362
|
async [BUN](agentExecPath, cwd) {
|
|
1261
1363
|
try {
|
|
1262
1364
|
// Bun does not support filtering by production packages yet.
|
|
@@ -1334,6 +1436,7 @@ const depsIncludesByAgent = (() => {
|
|
|
1334
1436
|
return stdout.includes(`"${name}"`);
|
|
1335
1437
|
}
|
|
1336
1438
|
return {
|
|
1439
|
+
__proto__: null,
|
|
1337
1440
|
[BUN]: matchHumanStdout,
|
|
1338
1441
|
[NPM$1]: matchQueryStdout,
|
|
1339
1442
|
[PNPM]: matchQueryStdout,
|
|
@@ -1343,7 +1446,7 @@ const depsIncludesByAgent = (() => {
|
|
|
1343
1446
|
};
|
|
1344
1447
|
})();
|
|
1345
1448
|
function createActionMessage(verb, overrideCount, workspaceCount) {
|
|
1346
|
-
return `${verb} ${overrideCount} Socket.dev optimized
|
|
1449
|
+
return `${verb} ${overrideCount} Socket.dev optimized ${words.pluralize('override', overrideCount)}${workspaceCount ? ` in ${workspaceCount} ${words.pluralize('workspace', workspaceCount)}` : ''}`;
|
|
1347
1450
|
}
|
|
1348
1451
|
function getDependencyEntries(pkgJson) {
|
|
1349
1452
|
const {
|
|
@@ -1516,7 +1619,7 @@ async function addOverrides({
|
|
|
1516
1619
|
const oldSpec = overrideExists ? overrides[origPkgName] : undefined;
|
|
1517
1620
|
const depAlias = depAliasMap.get(origPkgName);
|
|
1518
1621
|
const regSpecStartsLike = `${NPM$1}:${regPkgName}@`;
|
|
1519
|
-
let newSpec = `${regSpecStartsLike}
|
|
1622
|
+
let newSpec = `${regSpecStartsLike}${pin ? version : `^${major}`}`;
|
|
1520
1623
|
let thisVersion = version;
|
|
1521
1624
|
if (depAlias && type === NPM$1) {
|
|
1522
1625
|
// With npm one may not set an override for a package that one directly
|
|
@@ -1533,7 +1636,7 @@ async function addOverrides({
|
|
|
1533
1636
|
if (pin) {
|
|
1534
1637
|
thisVersion = semver.major(semver.coerce(npa(thisSpec).rawSpec)?.version ?? version) === major ? version : (await packages.fetchPackageManifest(thisSpec))?.version ?? version;
|
|
1535
1638
|
}
|
|
1536
|
-
newSpec = `${regSpecStartsLike}
|
|
1639
|
+
newSpec = `${regSpecStartsLike}${pin ? thisVersion : `^${semver.major(thisVersion)}`}`;
|
|
1537
1640
|
} else {
|
|
1538
1641
|
newSpec = oldSpec;
|
|
1539
1642
|
}
|
|
@@ -1601,7 +1704,7 @@ const optimize = {
|
|
|
1601
1704
|
pin,
|
|
1602
1705
|
prod
|
|
1603
1706
|
} = commandContext;
|
|
1604
|
-
const cwd = process.cwd();
|
|
1707
|
+
const cwd = process$1.cwd();
|
|
1605
1708
|
const {
|
|
1606
1709
|
agent,
|
|
1607
1710
|
agentExecPath,
|
|
@@ -1648,13 +1751,13 @@ const optimize = {
|
|
|
1648
1751
|
if (lockPath && path.relative(cwd, lockPath).startsWith('.')) {
|
|
1649
1752
|
console.warn(`⚠️ ${COMMAND_TITLE}: Package ${lockName} found at ${lockPath}`);
|
|
1650
1753
|
}
|
|
1651
|
-
const spinner =
|
|
1754
|
+
const spinner$1 = new spinner.Spinner({
|
|
1652
1755
|
text: 'Socket optimizing...'
|
|
1653
1756
|
});
|
|
1654
1757
|
const state = createAddOverridesState({
|
|
1655
|
-
spinner
|
|
1758
|
+
spinner: spinner$1
|
|
1656
1759
|
});
|
|
1657
|
-
spinner.start();
|
|
1760
|
+
spinner$1.start();
|
|
1658
1761
|
const nodeRange = `>=${minimumNodeVersion}`;
|
|
1659
1762
|
const manifestEntries = manifestNpmOverrides.filter(({
|
|
1660
1763
|
1: data
|
|
@@ -1672,7 +1775,7 @@ const optimize = {
|
|
|
1672
1775
|
prod,
|
|
1673
1776
|
rootPath: pkgPath
|
|
1674
1777
|
}, state);
|
|
1675
|
-
spinner.stop();
|
|
1778
|
+
spinner$1.stop();
|
|
1676
1779
|
const addedCount = state.added.size;
|
|
1677
1780
|
const updatedCount = state.updated.size;
|
|
1678
1781
|
const pkgJsonChanged = addedCount > 0 || updatedCount > 0;
|
|
@@ -1690,23 +1793,24 @@ const optimize = {
|
|
|
1690
1793
|
if (isNpm || pkgJsonChanged) {
|
|
1691
1794
|
// Always update package-lock.json until the npm overrides PR lands:
|
|
1692
1795
|
// https://github.com/npm/cli/pull/7025
|
|
1693
|
-
spinner.start(`Updating ${lockName}...`);
|
|
1796
|
+
spinner$1.start(`Updating ${lockName}...`);
|
|
1694
1797
|
try {
|
|
1695
1798
|
if (isNpm) {
|
|
1696
|
-
const
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
stdio: 'ignore',
|
|
1700
|
-
env: {
|
|
1701
|
-
...process.env,
|
|
1702
|
-
[UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE]: '1'
|
|
1799
|
+
const ipc = {
|
|
1800
|
+
[SOCKET_IPC_HANDSHAKE]: {
|
|
1801
|
+
[SOCKET_CLI_UPDATE_OVERRIDES_IN_PACKAGE_LOCK_FILE]: true
|
|
1703
1802
|
}
|
|
1704
1803
|
};
|
|
1705
|
-
await
|
|
1804
|
+
await shadowNpmInstall({
|
|
1805
|
+
ipc
|
|
1806
|
+
});
|
|
1706
1807
|
// TODO: This is a temporary workaround for a `npm ci` bug where it
|
|
1707
1808
|
// will error out after Socket Optimize generates a lock file. More
|
|
1708
1809
|
// investigation is needed.
|
|
1709
|
-
await
|
|
1810
|
+
await shadowNpmInstall({
|
|
1811
|
+
flags: ['--ignore-scripts', '--package-lock-only'],
|
|
1812
|
+
ipc
|
|
1813
|
+
});
|
|
1710
1814
|
} else {
|
|
1711
1815
|
// All package managers support the "install" command.
|
|
1712
1816
|
await spawn(agentExecPath, ['install'], {
|
|
@@ -1714,12 +1818,13 @@ const optimize = {
|
|
|
1714
1818
|
stdio: 'ignore'
|
|
1715
1819
|
});
|
|
1716
1820
|
}
|
|
1717
|
-
spinner.stop();
|
|
1821
|
+
spinner$1.stop();
|
|
1718
1822
|
if (isNpm) {
|
|
1719
1823
|
console.log(`💡 Re-run ${COMMAND_TITLE} whenever ${lockName} changes.\n This can be skipped once npm ships ${NPM_OVERRIDE_PR_URL}.`);
|
|
1720
1824
|
}
|
|
1721
|
-
} catch {
|
|
1722
|
-
spinner.error(`${COMMAND_TITLE}: ${agent} install failed to update ${lockName}`);
|
|
1825
|
+
} catch (e) {
|
|
1826
|
+
spinner$1.error(`${COMMAND_TITLE}: ${agent} install failed to update ${lockName}`);
|
|
1827
|
+
console.error(e);
|
|
1723
1828
|
}
|
|
1724
1829
|
}
|
|
1725
1830
|
}
|
|
@@ -1746,7 +1851,7 @@ function setupCommand$l(name, description, argv, importMeta) {
|
|
|
1746
1851
|
$ ${name}
|
|
1747
1852
|
|
|
1748
1853
|
Options
|
|
1749
|
-
${
|
|
1854
|
+
${getFlagListOutput(flags, 6)}
|
|
1750
1855
|
|
|
1751
1856
|
Examples
|
|
1752
1857
|
$ ${name}
|
|
@@ -1794,20 +1899,20 @@ function setupCommand$k(name, description, argv, importMeta) {
|
|
|
1794
1899
|
});
|
|
1795
1900
|
}
|
|
1796
1901
|
async function fetchOrganizations() {
|
|
1797
|
-
const apiKey =
|
|
1902
|
+
const apiKey = socketUrl.getDefaultToken();
|
|
1798
1903
|
if (!apiKey) {
|
|
1799
|
-
throw new
|
|
1904
|
+
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.');
|
|
1800
1905
|
}
|
|
1801
|
-
const spinner =
|
|
1906
|
+
const spinner$1 = new spinner.Spinner({
|
|
1802
1907
|
text: 'Fetching organizations...'
|
|
1803
1908
|
}).start();
|
|
1804
|
-
const socketSdk = await
|
|
1909
|
+
const socketSdk = await socketUrl.setupSdk(apiKey);
|
|
1805
1910
|
const result = await handleApiCall(socketSdk.getOrganizations(), 'looking up organizations');
|
|
1806
1911
|
if (result.success === false) {
|
|
1807
|
-
handleUnsuccessfulApiResponse('getOrganizations', result, spinner);
|
|
1912
|
+
handleUnsuccessfulApiResponse('getOrganizations', result, spinner$1);
|
|
1808
1913
|
return;
|
|
1809
1914
|
}
|
|
1810
|
-
spinner.stop(`List of organizations associated with your API key: ${colors.italic(apiKey)}`);
|
|
1915
|
+
spinner$1.stop(`List of organizations associated with your API key: ${colors.italic(apiKey)}`);
|
|
1811
1916
|
const organizations = Object.values(result.data.organizations);
|
|
1812
1917
|
for (const o of organizations) {
|
|
1813
1918
|
console.log(`
|
|
@@ -1841,7 +1946,7 @@ async function setupCommand$j(name, description, argv, importMeta) {
|
|
|
1841
1946
|
$ ${name} <${binName$1} command>
|
|
1842
1947
|
|
|
1843
1948
|
Options
|
|
1844
|
-
${
|
|
1949
|
+
${getFlagListOutput(flags, 6)}
|
|
1845
1950
|
|
|
1846
1951
|
Examples
|
|
1847
1952
|
$ ${name} install
|
|
@@ -1866,7 +1971,7 @@ async function setupCommand$j(name, description, argv, importMeta) {
|
|
|
1866
1971
|
// The exit code 127 indicates that the command or binary being executed
|
|
1867
1972
|
// could not be found.
|
|
1868
1973
|
console.error(`Socket unable to locate ${binName$1}; ensure it is available in the PATH environment variable.`);
|
|
1869
|
-
process.exit(127);
|
|
1974
|
+
process$1.exit(127);
|
|
1870
1975
|
}
|
|
1871
1976
|
const spawnPromise = spawn(binPath, argv, {
|
|
1872
1977
|
signal: abortSignal$1,
|
|
@@ -1878,9 +1983,9 @@ async function setupCommand$j(name, description, argv, importMeta) {
|
|
|
1878
1983
|
return;
|
|
1879
1984
|
}
|
|
1880
1985
|
if (signalName) {
|
|
1881
|
-
process.kill(process.pid, signalName);
|
|
1986
|
+
process$1.kill(process$1.pid, signalName);
|
|
1882
1987
|
} else if (code !== null) {
|
|
1883
|
-
process.exit(code);
|
|
1988
|
+
process$1.exit(code);
|
|
1884
1989
|
}
|
|
1885
1990
|
});
|
|
1886
1991
|
await spawnPromise;
|
|
@@ -1909,7 +2014,7 @@ async function setupCommand$i(name, description, argv, importMeta) {
|
|
|
1909
2014
|
$ ${name} <${binName} command>
|
|
1910
2015
|
|
|
1911
2016
|
Options
|
|
1912
|
-
${
|
|
2017
|
+
${getFlagListOutput(flags, 6)}
|
|
1913
2018
|
|
|
1914
2019
|
Examples
|
|
1915
2020
|
$ ${name} install
|
|
@@ -1934,7 +2039,7 @@ async function setupCommand$i(name, description, argv, importMeta) {
|
|
|
1934
2039
|
// The exit code 127 indicates that the command or binary being executed
|
|
1935
2040
|
// could not be found.
|
|
1936
2041
|
console.error(`Socket unable to locate ${binName}; ensure it is available in the PATH environment variable.`);
|
|
1937
|
-
process.exit(127);
|
|
2042
|
+
process$1.exit(127);
|
|
1938
2043
|
}
|
|
1939
2044
|
const spawnPromise = spawn(binPath, argv, {
|
|
1940
2045
|
signal: abortSignal,
|
|
@@ -1946,9 +2051,9 @@ async function setupCommand$i(name, description, argv, importMeta) {
|
|
|
1946
2051
|
return;
|
|
1947
2052
|
}
|
|
1948
2053
|
if (signalName) {
|
|
1949
|
-
process.kill(process.pid, signalName);
|
|
2054
|
+
process$1.kill(process$1.pid, signalName);
|
|
1950
2055
|
} else if (code !== null) {
|
|
1951
|
-
process.exit(code);
|
|
2056
|
+
process$1.exit(code);
|
|
1952
2057
|
}
|
|
1953
2058
|
});
|
|
1954
2059
|
await spawnPromise;
|
|
@@ -1984,7 +2089,7 @@ function setupCommand$h(name, description, argv, importMeta) {
|
|
|
1984
2089
|
$ ${name} <report-identifier>
|
|
1985
2090
|
|
|
1986
2091
|
Options
|
|
1987
|
-
${
|
|
2092
|
+
${getFlagListOutput(flags, 6)}
|
|
1988
2093
|
|
|
1989
2094
|
Examples
|
|
1990
2095
|
$ ${name} QXU8PmK7LfH608RAwfIKdbcHgwEd_ZeWJ9QEGv05FJUQ
|
|
@@ -2006,7 +2111,7 @@ function setupCommand$h(name, description, argv, importMeta) {
|
|
|
2006
2111
|
}
|
|
2007
2112
|
// Validate the input.
|
|
2008
2113
|
if (extraInput.length) {
|
|
2009
|
-
throw new
|
|
2114
|
+
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(', ')}`);
|
|
2010
2115
|
}
|
|
2011
2116
|
return {
|
|
2012
2117
|
includeAllIssues: cli.flags['all'],
|
|
@@ -2022,8 +2127,8 @@ async function fetchReportData(reportId, {
|
|
|
2022
2127
|
strict
|
|
2023
2128
|
}) {
|
|
2024
2129
|
// Do the API call
|
|
2025
|
-
const socketSdk = await
|
|
2026
|
-
const spinner =
|
|
2130
|
+
const socketSdk = await socketUrl.setupSdk();
|
|
2131
|
+
const spinner$1 = new spinner.Spinner({
|
|
2027
2132
|
text: `Fetching report with ID ${reportId} (this could take a while)`
|
|
2028
2133
|
}).start();
|
|
2029
2134
|
let result;
|
|
@@ -2038,23 +2143,23 @@ async function fetchReportData(reportId, {
|
|
|
2038
2143
|
}
|
|
2039
2144
|
}
|
|
2040
2145
|
if (result.success === false) {
|
|
2041
|
-
return handleUnsuccessfulApiResponse('getReport', result, spinner);
|
|
2146
|
+
return handleUnsuccessfulApiResponse('getReport', result, spinner$1);
|
|
2042
2147
|
}
|
|
2043
2148
|
|
|
2044
2149
|
// Conclude the status of the API call
|
|
2045
2150
|
|
|
2046
2151
|
if (strict) {
|
|
2047
2152
|
if (result.data.healthy) {
|
|
2048
|
-
spinner.success('Report result is healthy and great!');
|
|
2153
|
+
spinner$1.success('Report result is healthy and great!');
|
|
2049
2154
|
} else {
|
|
2050
|
-
spinner.error('Report result deemed unhealthy for project');
|
|
2155
|
+
spinner$1.error('Report result deemed unhealthy for project');
|
|
2051
2156
|
}
|
|
2052
2157
|
} else if (result.data.healthy === false) {
|
|
2053
2158
|
const severityCount = getSeverityCount(result.data.issues, includeAllIssues ? undefined : 'high');
|
|
2054
2159
|
const issueSummary = formatSeverityCount(severityCount);
|
|
2055
|
-
spinner.success(`Report has these issues: ${issueSummary}`);
|
|
2160
|
+
spinner$1.success(`Report has these issues: ${issueSummary}`);
|
|
2056
2161
|
} else {
|
|
2057
|
-
spinner.success('Report has no issues');
|
|
2162
|
+
spinner$1.success('Report has no issues');
|
|
2058
2163
|
}
|
|
2059
2164
|
return result.data;
|
|
2060
2165
|
}
|
|
@@ -2068,7 +2173,7 @@ function formatReportDataOutput(data, {
|
|
|
2068
2173
|
if (outputJson) {
|
|
2069
2174
|
console.log(JSON.stringify(data, undefined, 2));
|
|
2070
2175
|
} else {
|
|
2071
|
-
const format = new
|
|
2176
|
+
const format = new socketUrl.ColorOrMarkdown(!!outputMarkdown);
|
|
2072
2177
|
console.log('\nDetailed info on socket.dev: ' + format.hyperlink(reportId, data.url, {
|
|
2073
2178
|
fallbackToUrl: true
|
|
2074
2179
|
}));
|
|
@@ -2077,7 +2182,7 @@ function formatReportDataOutput(data, {
|
|
|
2077
2182
|
}
|
|
2078
2183
|
}
|
|
2079
2184
|
if (strict && data.healthy === false) {
|
|
2080
|
-
process.exit(1);
|
|
2185
|
+
process$1.exit(1);
|
|
2081
2186
|
}
|
|
2082
2187
|
}
|
|
2083
2188
|
|
|
@@ -2092,7 +2197,6 @@ const create$2 = {
|
|
|
2092
2197
|
const {
|
|
2093
2198
|
config,
|
|
2094
2199
|
cwd,
|
|
2095
|
-
debugLog,
|
|
2096
2200
|
dryRun,
|
|
2097
2201
|
includeAllIssues,
|
|
2098
2202
|
outputJson,
|
|
@@ -2104,7 +2208,6 @@ const create$2 = {
|
|
|
2104
2208
|
const result = input && (await createReport(packagePaths, {
|
|
2105
2209
|
config,
|
|
2106
2210
|
cwd,
|
|
2107
|
-
debugLog,
|
|
2108
2211
|
dryRun
|
|
2109
2212
|
}));
|
|
2110
2213
|
if (result && view) {
|
|
@@ -2140,12 +2243,6 @@ async function setupCommand$g(name, description, argv, importMeta) {
|
|
|
2140
2243
|
...commonFlags,
|
|
2141
2244
|
...outputFlags,
|
|
2142
2245
|
...validationFlags,
|
|
2143
|
-
debug: {
|
|
2144
|
-
type: 'boolean',
|
|
2145
|
-
shortFlag: 'd',
|
|
2146
|
-
default: false,
|
|
2147
|
-
description: 'Output debug information'
|
|
2148
|
-
},
|
|
2149
2246
|
dryRun: {
|
|
2150
2247
|
type: 'boolean',
|
|
2151
2248
|
default: false,
|
|
@@ -2172,9 +2269,8 @@ async function setupCommand$g(name, description, argv, importMeta) {
|
|
|
2172
2269
|
default ignores from the "ignore-by-default" module.
|
|
2173
2270
|
|
|
2174
2271
|
Options
|
|
2175
|
-
${
|
|
2272
|
+
${getFlagListOutput({
|
|
2176
2273
|
all: 'Include all issues',
|
|
2177
|
-
debug: 'Output debug information',
|
|
2178
2274
|
'dry-run': 'Only output what will be done without actually doing it',
|
|
2179
2275
|
json: 'Output result as json',
|
|
2180
2276
|
markdown: 'Output result as markdown',
|
|
@@ -2204,10 +2300,9 @@ async function setupCommand$g(name, description, argv, importMeta) {
|
|
|
2204
2300
|
const {
|
|
2205
2301
|
dryRun
|
|
2206
2302
|
} = cli.flags;
|
|
2207
|
-
const debugLog = sdk.createDebugLogger(!dryRun || cli.flags['debug']);
|
|
2208
2303
|
|
|
2209
2304
|
// TODO: Allow setting a custom cwd and/or configFile path?
|
|
2210
|
-
const cwd = process.cwd();
|
|
2305
|
+
const cwd = process$1.cwd();
|
|
2211
2306
|
const absoluteConfigPath = path.join(cwd, 'socket.yml');
|
|
2212
2307
|
const config$1 = await config.readSocketConfig(absoluteConfigPath).catch(cause => {
|
|
2213
2308
|
if (cause && typeof cause === 'object' && cause instanceof config.SocketValidationError) {
|
|
@@ -2219,27 +2314,26 @@ async function setupCommand$g(name, description, argv, importMeta) {
|
|
|
2219
2314
|
errors: cause.validationErrors,
|
|
2220
2315
|
schema: cause.schema
|
|
2221
2316
|
});
|
|
2222
|
-
throw new
|
|
2317
|
+
throw new socketUrl.InputError('The socket.yml config is not valid', betterErrors.map(err => `[${err.path}] ${err.message}.${err.suggestion ? err.suggestion : ''}`).join('\n'));
|
|
2223
2318
|
} else {
|
|
2224
2319
|
throw new ponyCause.ErrorWithCause('Failed to read socket.yml config', {
|
|
2225
2320
|
cause
|
|
2226
2321
|
});
|
|
2227
2322
|
}
|
|
2228
2323
|
});
|
|
2229
|
-
const socketSdk = await
|
|
2324
|
+
const socketSdk = await socketUrl.setupSdk();
|
|
2230
2325
|
const supportedFiles = await socketSdk.getReportSupportedFiles().then(res => {
|
|
2231
|
-
if (!res.success) handleUnsuccessfulApiResponse('getReportSupportedFiles', res,
|
|
2326
|
+
if (!res.success) handleUnsuccessfulApiResponse('getReportSupportedFiles', res, new spinner.Spinner());
|
|
2232
2327
|
return res.data;
|
|
2233
2328
|
}).catch(cause => {
|
|
2234
2329
|
throw new ponyCause.ErrorWithCause('Failed getting supported files for report', {
|
|
2235
2330
|
cause
|
|
2236
2331
|
});
|
|
2237
2332
|
});
|
|
2238
|
-
const packagePaths = await pathResolve.getPackageFiles(cwd, cli.input, config$1, supportedFiles
|
|
2333
|
+
const packagePaths = await pathResolve.getPackageFiles(cwd, cli.input, config$1, supportedFiles);
|
|
2239
2334
|
return {
|
|
2240
2335
|
config: config$1,
|
|
2241
2336
|
cwd,
|
|
2242
|
-
debugLog,
|
|
2243
2337
|
dryRun,
|
|
2244
2338
|
includeAllIssues: cli.flags['all'],
|
|
2245
2339
|
outputJson: cli.flags['json'],
|
|
@@ -2252,24 +2346,23 @@ async function setupCommand$g(name, description, argv, importMeta) {
|
|
|
2252
2346
|
async function createReport(packagePaths, {
|
|
2253
2347
|
config,
|
|
2254
2348
|
cwd,
|
|
2255
|
-
debugLog,
|
|
2256
2349
|
dryRun
|
|
2257
2350
|
}) {
|
|
2258
|
-
debugLog('Uploading:', packagePaths.join(`\n${
|
|
2351
|
+
pathResolve.debugLog('Uploading:', packagePaths.join(`\n${pathResolve.logSymbols.info} Uploading: `));
|
|
2259
2352
|
if (dryRun) {
|
|
2260
2353
|
return;
|
|
2261
2354
|
}
|
|
2262
|
-
const socketSdk = await
|
|
2263
|
-
const spinner =
|
|
2355
|
+
const socketSdk = await socketUrl.setupSdk();
|
|
2356
|
+
const spinner$1 = new spinner.Spinner({
|
|
2264
2357
|
text: `Creating report with ${packagePaths.length} package files`
|
|
2265
2358
|
}).start();
|
|
2266
2359
|
const apiCall = socketSdk.createReportFromFilePaths(packagePaths, cwd, config?.issueRules);
|
|
2267
2360
|
const result = await handleApiCall(apiCall, 'creating report');
|
|
2268
2361
|
if (result.success) {
|
|
2269
|
-
spinner.success();
|
|
2362
|
+
spinner$1.success();
|
|
2270
2363
|
return result;
|
|
2271
2364
|
}
|
|
2272
|
-
handleUnsuccessfulApiResponse('createReport', result, spinner);
|
|
2365
|
+
handleUnsuccessfulApiResponse('createReport', result, spinner$1);
|
|
2273
2366
|
return undefined;
|
|
2274
2367
|
}
|
|
2275
2368
|
function formatReportCreationOutput(data, {
|
|
@@ -2280,7 +2373,7 @@ function formatReportCreationOutput(data, {
|
|
|
2280
2373
|
console.log(JSON.stringify(data, undefined, 2));
|
|
2281
2374
|
return;
|
|
2282
2375
|
}
|
|
2283
|
-
const format = new
|
|
2376
|
+
const format = new socketUrl.ColorOrMarkdown(!!outputMarkdown);
|
|
2284
2377
|
console.log(`New report: ${format.hyperlink(data.id, data.url, {
|
|
2285
2378
|
fallbackToUrl: true
|
|
2286
2379
|
})}`);
|
|
@@ -2322,13 +2415,13 @@ async function meowWithSubcommands(subcommands, options) {
|
|
|
2322
2415
|
$ ${name} <command>
|
|
2323
2416
|
|
|
2324
2417
|
Commands
|
|
2325
|
-
${
|
|
2326
|
-
...objects.toSortedObject(subcommands),
|
|
2327
|
-
...objects.toSortedObject(aliases)
|
|
2418
|
+
${getHelpListOutput({
|
|
2419
|
+
...objects.toSortedObject(Object.fromEntries(Object.entries(subcommands).filter(entry => !entry[1].hidden))),
|
|
2420
|
+
...objects.toSortedObject(Object.fromEntries(Object.entries(aliases).filter(entry => !subcommands[entry[1]?.argv[0]]?.hidden)))
|
|
2328
2421
|
}, 6)}
|
|
2329
2422
|
|
|
2330
2423
|
Options
|
|
2331
|
-
${
|
|
2424
|
+
${getFlagListOutput(flags, 6)}
|
|
2332
2425
|
|
|
2333
2426
|
Examples
|
|
2334
2427
|
$ ${name} --help
|
|
@@ -2359,8 +2452,9 @@ const report = {
|
|
|
2359
2452
|
}
|
|
2360
2453
|
};
|
|
2361
2454
|
|
|
2362
|
-
const
|
|
2363
|
-
const
|
|
2455
|
+
const HOME_DIR = os.homedir();
|
|
2456
|
+
const BASH_FILE = `${HOME_DIR}/.bashrc`;
|
|
2457
|
+
const ZSH_BASH_FILE = `${HOME_DIR}/.zshrc`;
|
|
2364
2458
|
const wrapper = {
|
|
2365
2459
|
description: 'Enable or disable the Socket npm/npx wrapper',
|
|
2366
2460
|
async run(argv, importMeta, {
|
|
@@ -2376,7 +2470,7 @@ function setupCommand$f(name, description, argv, importMeta) {
|
|
|
2376
2470
|
$ ${name} <flag>
|
|
2377
2471
|
|
|
2378
2472
|
Options
|
|
2379
|
-
${
|
|
2473
|
+
${getFlagListOutput(flags, 6)}
|
|
2380
2474
|
|
|
2381
2475
|
Examples
|
|
2382
2476
|
$ ${name} --enable
|
|
@@ -2431,21 +2525,18 @@ function setupCommand$f(name, description, argv, importMeta) {
|
|
|
2431
2525
|
console.error('There was an issue setting up the alias in your bash profile');
|
|
2432
2526
|
}
|
|
2433
2527
|
}
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2528
|
+
function addAlias(file) {
|
|
2529
|
+
return fs.appendFile(file, 'alias npm="socket npm"\nalias npx="socket npx"\n', err => {
|
|
2530
|
+
if (err) {
|
|
2531
|
+
return new Error(`There was an error setting up the alias: ${err}`);
|
|
2532
|
+
}
|
|
2533
|
+
console.log(`
|
|
2534
|
+
The alias was added to ${file}. Running 'npm install' will now be wrapped in Socket's "safe npm" 🎉
|
|
2535
|
+
If you want to disable it at any time, run \`socket wrapper --disable\`
|
|
2441
2536
|
`);
|
|
2442
|
-
const rl = readline.createInterface({
|
|
2443
|
-
input: process.stdin,
|
|
2444
|
-
output: process.stdout
|
|
2445
2537
|
});
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
const askQuestion = (rl, query) => {
|
|
2538
|
+
}
|
|
2539
|
+
function askQuestion(rl, query) {
|
|
2449
2540
|
rl.question(query, ans => {
|
|
2450
2541
|
if (ans.toLowerCase() === 'y') {
|
|
2451
2542
|
try {
|
|
@@ -2465,19 +2556,31 @@ const askQuestion = (rl, query) => {
|
|
|
2465
2556
|
rl.close();
|
|
2466
2557
|
}
|
|
2467
2558
|
});
|
|
2468
|
-
}
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
}
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2559
|
+
}
|
|
2560
|
+
function checkSocketWrapperAlreadySetup(file) {
|
|
2561
|
+
const fileContent = fs.readFileSync(file, 'utf8');
|
|
2562
|
+
const linesWithSocketAlias = fileContent.split('\n').filter(l => l === 'alias npm="socket npm"' || l === 'alias npx="socket npx"');
|
|
2563
|
+
if (linesWithSocketAlias.length) {
|
|
2564
|
+
console.log(`The Socket npm/npx wrapper is set up in your bash profile (${file}).`);
|
|
2565
|
+
return true;
|
|
2566
|
+
}
|
|
2567
|
+
return false;
|
|
2568
|
+
}
|
|
2569
|
+
function installSafeNpm(query) {
|
|
2570
|
+
console.log(`
|
|
2571
|
+
_____ _ _
|
|
2572
|
+
| __|___ ___| |_ ___| |_
|
|
2573
|
+
|__ | . | _| '_| -_| _|
|
|
2574
|
+
|_____|___|___|_,_|___|_|
|
|
2575
|
+
|
|
2477
2576
|
`);
|
|
2577
|
+
const rl = readline.createInterface({
|
|
2578
|
+
input: process$1.stdin,
|
|
2579
|
+
output: process$1.stdout
|
|
2478
2580
|
});
|
|
2479
|
-
|
|
2480
|
-
|
|
2581
|
+
return askQuestion(rl, query);
|
|
2582
|
+
}
|
|
2583
|
+
function removeAlias(file) {
|
|
2481
2584
|
return fs.readFile(file, 'utf8', function (err, data) {
|
|
2482
2585
|
if (err) {
|
|
2483
2586
|
console.error(`There was an error removing the alias: ${err}`);
|
|
@@ -2494,16 +2597,7 @@ const removeAlias = file => {
|
|
|
2494
2597
|
}
|
|
2495
2598
|
});
|
|
2496
2599
|
});
|
|
2497
|
-
}
|
|
2498
|
-
const checkSocketWrapperAlreadySetup = file => {
|
|
2499
|
-
const fileContent = fs.readFileSync(file, 'utf8');
|
|
2500
|
-
const linesWithSocketAlias = fileContent.split('\n').filter(l => l === 'alias npm="socket npm"' || l === 'alias npx="socket npx"');
|
|
2501
|
-
if (linesWithSocketAlias.length) {
|
|
2502
|
-
console.log(`The Socket npm/npx wrapper is set up in your bash profile (${file}).`);
|
|
2503
|
-
return true;
|
|
2504
|
-
}
|
|
2505
|
-
return false;
|
|
2506
|
-
};
|
|
2600
|
+
}
|
|
2507
2601
|
|
|
2508
2602
|
const create$1 = {
|
|
2509
2603
|
description: 'Create a scan',
|
|
@@ -2513,15 +2607,15 @@ const create$1 = {
|
|
|
2513
2607
|
const name = `${parentName} create`;
|
|
2514
2608
|
const input = await setupCommand$e(name, create$1.description, argv, importMeta);
|
|
2515
2609
|
if (input) {
|
|
2516
|
-
const apiKey =
|
|
2610
|
+
const apiKey = socketUrl.getDefaultToken();
|
|
2517
2611
|
if (!apiKey) {
|
|
2518
|
-
throw new
|
|
2612
|
+
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.');
|
|
2519
2613
|
}
|
|
2520
2614
|
const spinnerText = 'Creating a scan... \n';
|
|
2521
|
-
const spinner =
|
|
2615
|
+
const spinner$1 = new spinner.Spinner({
|
|
2522
2616
|
text: spinnerText
|
|
2523
2617
|
}).start();
|
|
2524
|
-
await createFullScan(input, spinner, apiKey);
|
|
2618
|
+
await createFullScan(input, spinner$1, apiKey);
|
|
2525
2619
|
}
|
|
2526
2620
|
}
|
|
2527
2621
|
};
|
|
@@ -2592,7 +2686,7 @@ async function setupCommand$e(name, description, argv, importMeta) {
|
|
|
2592
2686
|
$ ${name} [...options]
|
|
2593
2687
|
|
|
2594
2688
|
Options
|
|
2595
|
-
${
|
|
2689
|
+
${getFlagListOutput(flags, 6)}
|
|
2596
2690
|
|
|
2597
2691
|
Examples
|
|
2598
2692
|
$ ${name} --org=FakeOrg --repo=test-repo --branch=main ./package.json
|
|
@@ -2613,10 +2707,10 @@ async function setupCommand$e(name, description, argv, importMeta) {
|
|
|
2613
2707
|
const {
|
|
2614
2708
|
0: orgSlug = ''
|
|
2615
2709
|
} = cli.input;
|
|
2616
|
-
const cwd = process.cwd();
|
|
2617
|
-
const socketSdk = await
|
|
2710
|
+
const cwd = process$1.cwd();
|
|
2711
|
+
const socketSdk = await socketUrl.setupSdk();
|
|
2618
2712
|
const supportedFiles = await socketSdk.getReportSupportedFiles().then(res => {
|
|
2619
|
-
if (!res.success) handleUnsuccessfulApiResponse('getReportSupportedFiles', res,
|
|
2713
|
+
if (!res.success) handleUnsuccessfulApiResponse('getReportSupportedFiles', res, new spinner.Spinner());
|
|
2620
2714
|
return res.data;
|
|
2621
2715
|
}).catch(/** @type {(cause: Error) => never} */
|
|
2622
2716
|
cause => {
|
|
@@ -2624,8 +2718,7 @@ async function setupCommand$e(name, description, argv, importMeta) {
|
|
|
2624
2718
|
cause
|
|
2625
2719
|
});
|
|
2626
2720
|
});
|
|
2627
|
-
const
|
|
2628
|
-
const packagePaths = await pathResolve.getPackageFilesFullScans(cwd, cli.input, supportedFiles, debugLog);
|
|
2721
|
+
const packagePaths = await pathResolve.getPackageFilesFullScans(cwd, cli.input, supportedFiles);
|
|
2629
2722
|
const {
|
|
2630
2723
|
branch: branchName,
|
|
2631
2724
|
repo: repoName
|
|
@@ -2656,7 +2749,7 @@ async function setupCommand$e(name, description, argv, importMeta) {
|
|
|
2656
2749
|
};
|
|
2657
2750
|
}
|
|
2658
2751
|
async function createFullScan(input, spinner, apiKey) {
|
|
2659
|
-
const socketSdk = await
|
|
2752
|
+
const socketSdk = await socketUrl.setupSdk(apiKey);
|
|
2660
2753
|
const {
|
|
2661
2754
|
branchName,
|
|
2662
2755
|
commitMessage,
|
|
@@ -2683,8 +2776,8 @@ async function createFullScan(input, spinner, apiKey) {
|
|
|
2683
2776
|
const link = colors.underline(colors.cyan(`${result.data.html_report_url}`));
|
|
2684
2777
|
console.log(`Available at: ${link}`);
|
|
2685
2778
|
const rl = readline$1.createInterface({
|
|
2686
|
-
input:
|
|
2687
|
-
output:
|
|
2779
|
+
input: process$1.stdin,
|
|
2780
|
+
output: process$1.stdout
|
|
2688
2781
|
});
|
|
2689
2782
|
const answer = await rl.question('Would you like to open it in your browser? (y/n)');
|
|
2690
2783
|
if (answer.toLowerCase() === 'y') {
|
|
@@ -2701,15 +2794,15 @@ const del$1 = {
|
|
|
2701
2794
|
const name = `${parentName} del`;
|
|
2702
2795
|
const input = setupCommand$d(name, del$1.description, argv, importMeta);
|
|
2703
2796
|
if (input) {
|
|
2704
|
-
const apiKey =
|
|
2797
|
+
const apiKey = socketUrl.getDefaultToken();
|
|
2705
2798
|
if (!apiKey) {
|
|
2706
|
-
throw new
|
|
2799
|
+
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.');
|
|
2707
2800
|
}
|
|
2708
2801
|
const spinnerText = 'Deleting scan...';
|
|
2709
|
-
const spinner =
|
|
2802
|
+
const spinner$1 = new spinner.Spinner({
|
|
2710
2803
|
text: spinnerText
|
|
2711
2804
|
}).start();
|
|
2712
|
-
await deleteOrgFullScan(input.orgSlug, input.fullScanId, spinner, apiKey);
|
|
2805
|
+
await deleteOrgFullScan(input.orgSlug, input.fullScanId, spinner$1, apiKey);
|
|
2713
2806
|
}
|
|
2714
2807
|
}
|
|
2715
2808
|
};
|
|
@@ -2726,7 +2819,7 @@ function setupCommand$d(name, description, argv, importMeta) {
|
|
|
2726
2819
|
$ ${name} <org slug> <scan ID>
|
|
2727
2820
|
|
|
2728
2821
|
Options
|
|
2729
|
-
${
|
|
2822
|
+
${getFlagListOutput(flags, 6)}
|
|
2730
2823
|
|
|
2731
2824
|
Examples
|
|
2732
2825
|
$ ${name} FakeOrg 000aaaa1-0000-0a0a-00a0-00a0000000a0
|
|
@@ -2757,7 +2850,7 @@ function setupCommand$d(name, description, argv, importMeta) {
|
|
|
2757
2850
|
};
|
|
2758
2851
|
}
|
|
2759
2852
|
async function deleteOrgFullScan(orgSlug, fullScanId, spinner, apiKey) {
|
|
2760
|
-
const socketSdk = await
|
|
2853
|
+
const socketSdk = await socketUrl.setupSdk(apiKey);
|
|
2761
2854
|
const result = await handleApiCall(socketSdk.deleteOrgFullScan(orgSlug, fullScanId), 'Deleting scan');
|
|
2762
2855
|
if (result.success) {
|
|
2763
2856
|
spinner.success('Scan deleted successfully');
|
|
@@ -2766,6 +2859,7 @@ async function deleteOrgFullScan(orgSlug, fullScanId, spinner, apiKey) {
|
|
|
2766
2859
|
}
|
|
2767
2860
|
}
|
|
2768
2861
|
|
|
2862
|
+
// @ts-ignore
|
|
2769
2863
|
const list$1 = {
|
|
2770
2864
|
description: 'List scans for an organization',
|
|
2771
2865
|
async run(argv, importMeta, {
|
|
@@ -2774,15 +2868,15 @@ const list$1 = {
|
|
|
2774
2868
|
const name = `${parentName} list`;
|
|
2775
2869
|
const input = setupCommand$c(name, list$1.description, argv, importMeta);
|
|
2776
2870
|
if (input) {
|
|
2777
|
-
const apiKey =
|
|
2871
|
+
const apiKey = socketUrl.getDefaultToken();
|
|
2778
2872
|
if (!apiKey) {
|
|
2779
|
-
throw new
|
|
2873
|
+
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.');
|
|
2780
2874
|
}
|
|
2781
2875
|
const spinnerText = 'Listing scans... \n';
|
|
2782
|
-
const spinner =
|
|
2876
|
+
const spinner$1 = new spinner.Spinner({
|
|
2783
2877
|
text: spinnerText
|
|
2784
2878
|
}).start();
|
|
2785
|
-
await listOrgFullScan(input.orgSlug, input, spinner, apiKey);
|
|
2879
|
+
await listOrgFullScan(input.orgSlug, input, spinner$1, apiKey);
|
|
2786
2880
|
}
|
|
2787
2881
|
}
|
|
2788
2882
|
};
|
|
@@ -2838,7 +2932,7 @@ function setupCommand$c(name, description, argv, importMeta) {
|
|
|
2838
2932
|
$ ${name} <org slug>
|
|
2839
2933
|
|
|
2840
2934
|
Options
|
|
2841
|
-
${
|
|
2935
|
+
${getFlagListOutput(flags, 6)}
|
|
2842
2936
|
|
|
2843
2937
|
Examples
|
|
2844
2938
|
$ ${name} FakeOrg
|
|
@@ -2873,7 +2967,7 @@ function setupCommand$c(name, description, argv, importMeta) {
|
|
|
2873
2967
|
};
|
|
2874
2968
|
}
|
|
2875
2969
|
async function listOrgFullScan(orgSlug, input, spinner, apiKey) {
|
|
2876
|
-
const socketSdk = await
|
|
2970
|
+
const socketSdk = await socketUrl.setupSdk(apiKey);
|
|
2877
2971
|
const result = await handleApiCall(socketSdk.getOrgFullScanList(orgSlug, input), 'Listing scans');
|
|
2878
2972
|
if (!result.success) {
|
|
2879
2973
|
handleUnsuccessfulApiResponse('getOrgFullScanList', result, spinner);
|
|
@@ -2918,15 +3012,15 @@ const metadata = {
|
|
|
2918
3012
|
const name = `${parentName} metadata`;
|
|
2919
3013
|
const input = setupCommand$b(name, metadata.description, argv, importMeta);
|
|
2920
3014
|
if (input) {
|
|
2921
|
-
const apiKey =
|
|
3015
|
+
const apiKey = socketUrl.getDefaultToken();
|
|
2922
3016
|
if (!apiKey) {
|
|
2923
|
-
throw new
|
|
3017
|
+
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.');
|
|
2924
3018
|
}
|
|
2925
3019
|
const spinnerText = "Getting scan's metadata... \n";
|
|
2926
|
-
const spinner =
|
|
3020
|
+
const spinner$1 = new spinner.Spinner({
|
|
2927
3021
|
text: spinnerText
|
|
2928
3022
|
}).start();
|
|
2929
|
-
await getOrgScanMetadata(input.orgSlug, input.scanID, spinner, apiKey);
|
|
3023
|
+
await getOrgScanMetadata(input.orgSlug, input.scanID, spinner$1, apiKey);
|
|
2930
3024
|
}
|
|
2931
3025
|
}
|
|
2932
3026
|
};
|
|
@@ -2943,7 +3037,7 @@ function setupCommand$b(name, description, argv, importMeta) {
|
|
|
2943
3037
|
$ ${name} <org slug> <scan id>
|
|
2944
3038
|
|
|
2945
3039
|
Options
|
|
2946
|
-
${
|
|
3040
|
+
${getFlagListOutput(flags, 6)}
|
|
2947
3041
|
|
|
2948
3042
|
Examples
|
|
2949
3043
|
$ ${name} FakeOrg 000aaaa1-0000-0a0a-00a0-00a0000000a0
|
|
@@ -2974,7 +3068,7 @@ function setupCommand$b(name, description, argv, importMeta) {
|
|
|
2974
3068
|
};
|
|
2975
3069
|
}
|
|
2976
3070
|
async function getOrgScanMetadata(orgSlug, scanId, spinner, apiKey) {
|
|
2977
|
-
const socketSdk = await
|
|
3071
|
+
const socketSdk = await socketUrl.setupSdk(apiKey);
|
|
2978
3072
|
const result = await handleApiCall(socketSdk.getOrgFullScanMetadata(orgSlug, scanId), 'Listing scans');
|
|
2979
3073
|
if (!result.success) {
|
|
2980
3074
|
handleUnsuccessfulApiResponse('getOrgFullScanMetadata', result, spinner);
|
|
@@ -2992,18 +3086,18 @@ const stream = {
|
|
|
2992
3086
|
const name = `${parentName} stream`;
|
|
2993
3087
|
const input = setupCommand$a(name, stream.description, argv, importMeta);
|
|
2994
3088
|
if (input) {
|
|
2995
|
-
const apiKey =
|
|
3089
|
+
const apiKey = socketUrl.getDefaultToken();
|
|
2996
3090
|
if (!apiKey) {
|
|
2997
|
-
throw new
|
|
3091
|
+
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.');
|
|
2998
3092
|
}
|
|
2999
|
-
const spinner =
|
|
3093
|
+
const spinner$1 = new spinner.Spinner({
|
|
3000
3094
|
text: 'Streaming scan...'
|
|
3001
3095
|
}).start();
|
|
3002
3096
|
const result = await getOrgFullScan(input.orgSlug, input.fullScanId, input.file, apiKey);
|
|
3003
3097
|
if (result?.success) {
|
|
3004
|
-
spinner.stop(input.file ? `Full scan details written to ${input.file}` : '');
|
|
3098
|
+
spinner$1.stop(input.file ? `Full scan details written to ${input.file}` : '');
|
|
3005
3099
|
} else {
|
|
3006
|
-
handleUnsuccessfulApiResponse('getOrgFullScan', result, spinner);
|
|
3100
|
+
handleUnsuccessfulApiResponse('getOrgFullScan', result, spinner$1);
|
|
3007
3101
|
}
|
|
3008
3102
|
}
|
|
3009
3103
|
}
|
|
@@ -3021,7 +3115,7 @@ function setupCommand$a(name, description, argv, importMeta) {
|
|
|
3021
3115
|
$ ${name} <org slug> <scan ID> <path to output file>
|
|
3022
3116
|
|
|
3023
3117
|
Options
|
|
3024
|
-
${
|
|
3118
|
+
${getFlagListOutput(flags, 6)}
|
|
3025
3119
|
|
|
3026
3120
|
Examples
|
|
3027
3121
|
$ ${name} FakeOrg 000aaaa1-0000-0a0a-00a0-00a0000000a0 ./stream.txt
|
|
@@ -3054,7 +3148,7 @@ function setupCommand$a(name, description, argv, importMeta) {
|
|
|
3054
3148
|
};
|
|
3055
3149
|
}
|
|
3056
3150
|
async function getOrgFullScan(orgSlug, fullScanId, file, apiKey) {
|
|
3057
|
-
const socketSdk = await
|
|
3151
|
+
const socketSdk = await socketUrl.setupSdk(apiKey);
|
|
3058
3152
|
return await handleApiCall(socketSdk.getOrgFullScan(orgSlug, fullScanId, file), 'Streaming a scan');
|
|
3059
3153
|
}
|
|
3060
3154
|
|
|
@@ -3087,14 +3181,14 @@ const auditLog = {
|
|
|
3087
3181
|
const name = parentName + ' audit-log';
|
|
3088
3182
|
const input = setupCommand$9(name, auditLog.description, argv, importMeta);
|
|
3089
3183
|
if (input) {
|
|
3090
|
-
const apiKey =
|
|
3184
|
+
const apiKey = socketUrl.getDefaultToken();
|
|
3091
3185
|
if (!apiKey) {
|
|
3092
|
-
throw new
|
|
3186
|
+
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.');
|
|
3093
3187
|
}
|
|
3094
|
-
const spinner =
|
|
3188
|
+
const spinner$1 = new spinner.Spinner({
|
|
3095
3189
|
text: `Looking up audit log for ${input.orgSlug}\n`
|
|
3096
3190
|
}).start();
|
|
3097
|
-
await fetchOrgAuditLog(input.orgSlug, input, spinner, apiKey);
|
|
3191
|
+
await fetchOrgAuditLog(input.orgSlug, input, spinner$1, apiKey);
|
|
3098
3192
|
}
|
|
3099
3193
|
}
|
|
3100
3194
|
};
|
|
@@ -3132,7 +3226,7 @@ function setupCommand$9(name, description, argv, importMeta) {
|
|
|
3132
3226
|
$ ${name} <org slug>
|
|
3133
3227
|
|
|
3134
3228
|
Options
|
|
3135
|
-
${
|
|
3229
|
+
${getFlagListOutput(flags, 6)}
|
|
3136
3230
|
|
|
3137
3231
|
Examples
|
|
3138
3232
|
$ ${name} FakeOrg
|
|
@@ -3171,7 +3265,7 @@ function setupCommand$9(name, description, argv, importMeta) {
|
|
|
3171
3265
|
};
|
|
3172
3266
|
}
|
|
3173
3267
|
async function fetchOrgAuditLog(orgSlug, input, spinner, apiKey) {
|
|
3174
|
-
const socketSdk = await
|
|
3268
|
+
const socketSdk = await socketUrl.setupSdk(apiKey);
|
|
3175
3269
|
const result = await handleApiCall(socketSdk.getAuditLogEvents(orgSlug, input), `Looking up audit log for ${orgSlug}\n`);
|
|
3176
3270
|
if (!result.success) {
|
|
3177
3271
|
handleUnsuccessfulApiResponse('getAuditLogEvents', result, spinner);
|
|
@@ -3211,15 +3305,15 @@ const create = {
|
|
|
3211
3305
|
const name = `${parentName} create`;
|
|
3212
3306
|
const input = setupCommand$8(name, create.description, argv, importMeta);
|
|
3213
3307
|
if (input) {
|
|
3214
|
-
const apiKey =
|
|
3308
|
+
const apiKey = socketUrl.getDefaultToken();
|
|
3215
3309
|
if (!apiKey) {
|
|
3216
|
-
throw new
|
|
3310
|
+
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.');
|
|
3217
3311
|
}
|
|
3218
3312
|
const spinnerText = 'Creating repository... \n';
|
|
3219
|
-
const spinner =
|
|
3313
|
+
const spinner$1 = new spinner.Spinner({
|
|
3220
3314
|
text: spinnerText
|
|
3221
3315
|
}).start();
|
|
3222
|
-
await createRepo(input.orgSlug, input, spinner, apiKey);
|
|
3316
|
+
await createRepo(input.orgSlug, input, spinner$1, apiKey);
|
|
3223
3317
|
}
|
|
3224
3318
|
}
|
|
3225
3319
|
};
|
|
@@ -3269,7 +3363,7 @@ function setupCommand$8(name, description, argv, importMeta) {
|
|
|
3269
3363
|
$ ${name} <org slug>
|
|
3270
3364
|
|
|
3271
3365
|
Options
|
|
3272
|
-
${
|
|
3366
|
+
${getFlagListOutput(flags, 6)}
|
|
3273
3367
|
|
|
3274
3368
|
Examples
|
|
3275
3369
|
$ ${name} FakeOrg --repoName=test-repo
|
|
@@ -3307,7 +3401,7 @@ function setupCommand$8(name, description, argv, importMeta) {
|
|
|
3307
3401
|
};
|
|
3308
3402
|
}
|
|
3309
3403
|
async function createRepo(orgSlug, input, spinner, apiKey) {
|
|
3310
|
-
const socketSdk = await
|
|
3404
|
+
const socketSdk = await socketUrl.setupSdk(apiKey);
|
|
3311
3405
|
const result = await handleApiCall(socketSdk.createOrgRepo(orgSlug, input), 'creating repository');
|
|
3312
3406
|
if (result.success) {
|
|
3313
3407
|
spinner.success('Repository created successfully');
|
|
@@ -3324,15 +3418,15 @@ const del = {
|
|
|
3324
3418
|
const name = `${parentName} del`;
|
|
3325
3419
|
const input = setupCommand$7(name, del.description, argv, importMeta);
|
|
3326
3420
|
if (input) {
|
|
3327
|
-
const apiKey =
|
|
3421
|
+
const apiKey = socketUrl.getDefaultToken();
|
|
3328
3422
|
if (!apiKey) {
|
|
3329
|
-
throw new
|
|
3423
|
+
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.');
|
|
3330
3424
|
}
|
|
3331
3425
|
const spinnerText = 'Deleting repository... \n';
|
|
3332
|
-
const spinner =
|
|
3426
|
+
const spinner$1 = new spinner.Spinner({
|
|
3333
3427
|
text: spinnerText
|
|
3334
3428
|
}).start();
|
|
3335
|
-
await deleteRepository(input.orgSlug, input.repoName, spinner, apiKey);
|
|
3429
|
+
await deleteRepository(input.orgSlug, input.repoName, spinner$1, apiKey);
|
|
3336
3430
|
}
|
|
3337
3431
|
}
|
|
3338
3432
|
};
|
|
@@ -3370,7 +3464,7 @@ function setupCommand$7(name, description, argv, importMeta) {
|
|
|
3370
3464
|
};
|
|
3371
3465
|
}
|
|
3372
3466
|
async function deleteRepository(orgSlug, repoName, spinner, apiKey) {
|
|
3373
|
-
const socketSdk = await
|
|
3467
|
+
const socketSdk = await socketUrl.setupSdk(apiKey);
|
|
3374
3468
|
const result = await handleApiCall(socketSdk.deleteOrgRepo(orgSlug, repoName), 'deleting repository');
|
|
3375
3469
|
if (result.success) {
|
|
3376
3470
|
spinner.success('Repository deleted successfully');
|
|
@@ -3379,6 +3473,7 @@ async function deleteRepository(orgSlug, repoName, spinner, apiKey) {
|
|
|
3379
3473
|
}
|
|
3380
3474
|
}
|
|
3381
3475
|
|
|
3476
|
+
// @ts-ignore
|
|
3382
3477
|
const list = {
|
|
3383
3478
|
description: 'List repositories in an organization',
|
|
3384
3479
|
async run(argv, importMeta, {
|
|
@@ -3387,15 +3482,15 @@ const list = {
|
|
|
3387
3482
|
const name = `${parentName} list`;
|
|
3388
3483
|
const input = setupCommand$6(name, list.description, argv, importMeta);
|
|
3389
3484
|
if (input) {
|
|
3390
|
-
const apiKey =
|
|
3485
|
+
const apiKey = socketUrl.getDefaultToken();
|
|
3391
3486
|
if (!apiKey) {
|
|
3392
|
-
throw new
|
|
3487
|
+
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.');
|
|
3393
3488
|
}
|
|
3394
3489
|
const spinnerText = 'Listing repositories... \n';
|
|
3395
|
-
const spinner =
|
|
3490
|
+
const spinner$1 = new spinner.Spinner({
|
|
3396
3491
|
text: spinnerText
|
|
3397
3492
|
}).start();
|
|
3398
|
-
await listOrgRepos(input.orgSlug, input, spinner, apiKey);
|
|
3493
|
+
await listOrgRepos(input.orgSlug, input, spinner$1, apiKey);
|
|
3399
3494
|
}
|
|
3400
3495
|
}
|
|
3401
3496
|
};
|
|
@@ -3438,7 +3533,7 @@ function setupCommand$6(name, description, argv, importMeta) {
|
|
|
3438
3533
|
$ ${name} <org slug>
|
|
3439
3534
|
|
|
3440
3535
|
Options
|
|
3441
|
-
${
|
|
3536
|
+
${getFlagListOutput(flags, 6)}
|
|
3442
3537
|
|
|
3443
3538
|
Examples
|
|
3444
3539
|
$ ${name} FakeOrg
|
|
@@ -3471,7 +3566,7 @@ function setupCommand$6(name, description, argv, importMeta) {
|
|
|
3471
3566
|
};
|
|
3472
3567
|
}
|
|
3473
3568
|
async function listOrgRepos(orgSlug, input, spinner, apiKey) {
|
|
3474
|
-
const socketSdk = await
|
|
3569
|
+
const socketSdk = await socketUrl.setupSdk(apiKey);
|
|
3475
3570
|
const result = await handleApiCall(socketSdk.getOrgRepoList(orgSlug, input), 'listing repositories');
|
|
3476
3571
|
if (!result.success) {
|
|
3477
3572
|
handleUnsuccessfulApiResponse('getOrgRepoList', result, spinner);
|
|
@@ -3506,15 +3601,15 @@ const update = {
|
|
|
3506
3601
|
const name = `${parentName} update`;
|
|
3507
3602
|
const input = setupCommand$5(name, update.description, argv, importMeta);
|
|
3508
3603
|
if (input) {
|
|
3509
|
-
const apiKey =
|
|
3604
|
+
const apiKey = socketUrl.getDefaultToken();
|
|
3510
3605
|
if (!apiKey) {
|
|
3511
|
-
throw new
|
|
3606
|
+
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.');
|
|
3512
3607
|
}
|
|
3513
3608
|
const spinnerText = 'Updating repository... \n';
|
|
3514
|
-
const spinner =
|
|
3609
|
+
const spinner$1 = new spinner.Spinner({
|
|
3515
3610
|
text: spinnerText
|
|
3516
3611
|
}).start();
|
|
3517
|
-
await updateRepository(input.orgSlug, input, spinner, apiKey);
|
|
3612
|
+
await updateRepository(input.orgSlug, input, spinner$1, apiKey);
|
|
3518
3613
|
}
|
|
3519
3614
|
}
|
|
3520
3615
|
};
|
|
@@ -3564,7 +3659,7 @@ function setupCommand$5(name, description, argv, importMeta) {
|
|
|
3564
3659
|
$ ${name} <org slug>
|
|
3565
3660
|
|
|
3566
3661
|
Options
|
|
3567
|
-
${
|
|
3662
|
+
${getFlagListOutput(flags, 6)}
|
|
3568
3663
|
|
|
3569
3664
|
Examples
|
|
3570
3665
|
$ ${name} FakeOrg
|
|
@@ -3602,7 +3697,7 @@ function setupCommand$5(name, description, argv, importMeta) {
|
|
|
3602
3697
|
};
|
|
3603
3698
|
}
|
|
3604
3699
|
async function updateRepository(orgSlug, input, spinner, apiKey) {
|
|
3605
|
-
const socketSdk = await
|
|
3700
|
+
const socketSdk = await socketUrl.setupSdk(apiKey);
|
|
3606
3701
|
const result = await handleApiCall(socketSdk.updateOrgRepo(orgSlug, input.name, input), 'updating repository');
|
|
3607
3702
|
if (result.success) {
|
|
3608
3703
|
spinner.success('Repository updated successfully');
|
|
@@ -3611,6 +3706,7 @@ async function updateRepository(orgSlug, input, spinner, apiKey) {
|
|
|
3611
3706
|
}
|
|
3612
3707
|
}
|
|
3613
3708
|
|
|
3709
|
+
// @ts-ignore
|
|
3614
3710
|
const view = {
|
|
3615
3711
|
description: 'View repositories in an organization',
|
|
3616
3712
|
async run(argv, importMeta, {
|
|
@@ -3619,15 +3715,15 @@ const view = {
|
|
|
3619
3715
|
const name = `${parentName} view`;
|
|
3620
3716
|
const input = setupCommand$4(name, view.description, argv, importMeta);
|
|
3621
3717
|
if (input) {
|
|
3622
|
-
const apiKey =
|
|
3718
|
+
const apiKey = socketUrl.getDefaultToken();
|
|
3623
3719
|
if (!apiKey) {
|
|
3624
|
-
throw new
|
|
3720
|
+
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.');
|
|
3625
3721
|
}
|
|
3626
3722
|
const spinnerText = 'Fetching repository... \n';
|
|
3627
|
-
const spinner =
|
|
3723
|
+
const spinner$1 = new spinner.Spinner({
|
|
3628
3724
|
text: spinnerText
|
|
3629
3725
|
}).start();
|
|
3630
|
-
await viewRepository(input.orgSlug, input.repositoryName, spinner, apiKey);
|
|
3726
|
+
await viewRepository(input.orgSlug, input.repositoryName, spinner$1, apiKey);
|
|
3631
3727
|
}
|
|
3632
3728
|
}
|
|
3633
3729
|
};
|
|
@@ -3644,7 +3740,7 @@ function setupCommand$4(name, description, argv, importMeta) {
|
|
|
3644
3740
|
$ ${name} <org slug>
|
|
3645
3741
|
|
|
3646
3742
|
Options
|
|
3647
|
-
${
|
|
3743
|
+
${getFlagListOutput(flags, 6)}
|
|
3648
3744
|
|
|
3649
3745
|
Examples
|
|
3650
3746
|
$ ${name} FakeOrg
|
|
@@ -3675,7 +3771,7 @@ function setupCommand$4(name, description, argv, importMeta) {
|
|
|
3675
3771
|
};
|
|
3676
3772
|
}
|
|
3677
3773
|
async function viewRepository(orgSlug, repoName, spinner, apiKey) {
|
|
3678
|
-
const socketSdk = await
|
|
3774
|
+
const socketSdk = await socketUrl.setupSdk(apiKey);
|
|
3679
3775
|
const result = await handleApiCall(socketSdk.getOrgRepo(orgSlug, repoName), 'fetching repository');
|
|
3680
3776
|
if (!result.success) {
|
|
3681
3777
|
handleUnsuccessfulApiResponse('getOrgRepo', result, spinner);
|
|
@@ -3729,6 +3825,7 @@ const repo = {
|
|
|
3729
3825
|
}
|
|
3730
3826
|
};
|
|
3731
3827
|
|
|
3828
|
+
// @ts-ignore
|
|
3732
3829
|
const dependencies = {
|
|
3733
3830
|
description: 'Search for any dependency that is being used in your organization',
|
|
3734
3831
|
async run(argv, importMeta, {
|
|
@@ -3769,7 +3866,7 @@ function setupCommand$3(name, description, argv, importMeta) {
|
|
|
3769
3866
|
$ ${name}
|
|
3770
3867
|
|
|
3771
3868
|
Options
|
|
3772
|
-
${
|
|
3869
|
+
${getFlagListOutput(flags, 6)}
|
|
3773
3870
|
|
|
3774
3871
|
Examples
|
|
3775
3872
|
$ ${name}
|
|
@@ -3797,23 +3894,23 @@ async function searchDeps({
|
|
|
3797
3894
|
offset,
|
|
3798
3895
|
outputJson
|
|
3799
3896
|
}) {
|
|
3800
|
-
const apiKey =
|
|
3897
|
+
const apiKey = socketUrl.getDefaultToken();
|
|
3801
3898
|
if (!apiKey) {
|
|
3802
|
-
throw new
|
|
3899
|
+
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.');
|
|
3803
3900
|
}
|
|
3804
|
-
const spinner =
|
|
3901
|
+
const spinner$1 = new spinner.Spinner({
|
|
3805
3902
|
text: 'Searching dependencies...'
|
|
3806
3903
|
}).start();
|
|
3807
|
-
const socketSdk = await
|
|
3904
|
+
const socketSdk = await socketUrl.setupSdk(apiKey);
|
|
3808
3905
|
const result = await handleApiCall(socketSdk.searchDependencies({
|
|
3809
3906
|
limit,
|
|
3810
3907
|
offset
|
|
3811
3908
|
}), 'Searching dependencies');
|
|
3812
3909
|
if (!result.success) {
|
|
3813
|
-
handleUnsuccessfulApiResponse('searchDependencies', result, spinner);
|
|
3910
|
+
handleUnsuccessfulApiResponse('searchDependencies', result, spinner$1);
|
|
3814
3911
|
return;
|
|
3815
3912
|
}
|
|
3816
|
-
spinner.stop('Organization dependencies:');
|
|
3913
|
+
spinner$1.stop('Organization dependencies:');
|
|
3817
3914
|
if (outputJson) {
|
|
3818
3915
|
console.log(result.data);
|
|
3819
3916
|
return;
|
|
@@ -3854,18 +3951,18 @@ const analytics = {
|
|
|
3854
3951
|
const name = parentName + ' analytics';
|
|
3855
3952
|
const input = setupCommand$2(name, analytics.description, argv, importMeta);
|
|
3856
3953
|
if (input) {
|
|
3857
|
-
const apiKey =
|
|
3954
|
+
const apiKey = socketUrl.getDefaultToken();
|
|
3858
3955
|
if (!apiKey) {
|
|
3859
|
-
throw new
|
|
3956
|
+
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.');
|
|
3860
3957
|
}
|
|
3861
|
-
const spinner =
|
|
3958
|
+
const spinner$1 = new spinner.Spinner({
|
|
3862
3959
|
text: 'Fetching analytics data'
|
|
3863
3960
|
}).start();
|
|
3864
3961
|
if (input.scope === 'org') {
|
|
3865
|
-
await fetchOrgAnalyticsData(input.time, spinner, apiKey, input.outputJson, input.file);
|
|
3962
|
+
await fetchOrgAnalyticsData(input.time, spinner$1, apiKey, input.outputJson, input.file);
|
|
3866
3963
|
} else {
|
|
3867
3964
|
if (input.repo) {
|
|
3868
|
-
await fetchRepoAnalyticsData(input.repo, input.time, spinner, apiKey, input.outputJson, input.file);
|
|
3965
|
+
await fetchRepoAnalyticsData(input.repo, input.time, spinner$1, apiKey, input.outputJson, input.file);
|
|
3869
3966
|
}
|
|
3870
3967
|
}
|
|
3871
3968
|
}
|
|
@@ -3911,7 +4008,7 @@ function setupCommand$2(name, description, argv, importMeta) {
|
|
|
3911
4008
|
$ ${name} --scope=<scope> --time=<time filter>
|
|
3912
4009
|
|
|
3913
4010
|
Options
|
|
3914
|
-
${
|
|
4011
|
+
${getFlagListOutput(flags, 6)}
|
|
3915
4012
|
|
|
3916
4013
|
Examples
|
|
3917
4014
|
$ ${name} --scope=org --time=7
|
|
@@ -3929,10 +4026,10 @@ function setupCommand$2(name, description, argv, importMeta) {
|
|
|
3929
4026
|
time
|
|
3930
4027
|
} = cli.flags;
|
|
3931
4028
|
if (scope !== 'org' && scope !== 'repo') {
|
|
3932
|
-
throw new
|
|
4029
|
+
throw new socketUrl.InputError("The scope must either be 'org' or 'repo'");
|
|
3933
4030
|
}
|
|
3934
4031
|
if (time !== 7 && time !== 30 && time !== 90) {
|
|
3935
|
-
throw new
|
|
4032
|
+
throw new socketUrl.InputError('The time filter must either be 7, 30 or 90');
|
|
3936
4033
|
}
|
|
3937
4034
|
let showHelp = cli.flags['help'];
|
|
3938
4035
|
if (scope === 'repo' && !repo) {
|
|
@@ -3953,7 +4050,7 @@ function setupCommand$2(name, description, argv, importMeta) {
|
|
|
3953
4050
|
}
|
|
3954
4051
|
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'];
|
|
3955
4052
|
async function fetchOrgAnalyticsData(time, spinner, apiKey, outputJson, filePath) {
|
|
3956
|
-
const socketSdk = await
|
|
4053
|
+
const socketSdk = await socketUrl.setupSdk(apiKey);
|
|
3957
4054
|
const result = await handleApiCall(socketSdk.getOrgAnalytics(time.toString()), 'fetching analytics data');
|
|
3958
4055
|
if (result.success === false) {
|
|
3959
4056
|
return handleUnsuccessfulApiResponse('getOrgAnalytics', result, spinner);
|
|
@@ -4066,7 +4163,7 @@ const formatData = (data, scope) => {
|
|
|
4066
4163
|
};
|
|
4067
4164
|
};
|
|
4068
4165
|
async function fetchRepoAnalyticsData(repo, time, spinner, apiKey, outputJson, filePath) {
|
|
4069
|
-
const socketSdk = await
|
|
4166
|
+
const socketSdk = await socketUrl.setupSdk(apiKey);
|
|
4070
4167
|
const result = await handleApiCall(socketSdk.getRepoAnalytics(repo, time.toString()), 'fetching analytics data');
|
|
4071
4168
|
if (result.success === false) {
|
|
4072
4169
|
return handleUnsuccessfulApiResponse('getRepoAnalytics', result, spinner);
|
|
@@ -4154,15 +4251,15 @@ const get = {
|
|
|
4154
4251
|
const name = `${parentName} get`;
|
|
4155
4252
|
const input = setupCommand$1(name, get.description, argv, importMeta);
|
|
4156
4253
|
if (input) {
|
|
4157
|
-
const apiKey =
|
|
4254
|
+
const apiKey = socketUrl.getDefaultToken();
|
|
4158
4255
|
if (!apiKey) {
|
|
4159
|
-
throw new
|
|
4256
|
+
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.');
|
|
4160
4257
|
}
|
|
4161
4258
|
const spinnerText = 'Getting diff scan... \n';
|
|
4162
|
-
const spinner =
|
|
4259
|
+
const spinner$1 = new spinner.Spinner({
|
|
4163
4260
|
text: spinnerText
|
|
4164
4261
|
}).start();
|
|
4165
|
-
await getDiffScan(input, spinner, apiKey);
|
|
4262
|
+
await getDiffScan(input, spinner$1, apiKey);
|
|
4166
4263
|
}
|
|
4167
4264
|
}
|
|
4168
4265
|
};
|
|
@@ -4206,7 +4303,7 @@ function setupCommand$1(name, description, argv, importMeta) {
|
|
|
4206
4303
|
$ ${name} <org slug> --before=<before> --after=<after>
|
|
4207
4304
|
|
|
4208
4305
|
Options
|
|
4209
|
-
${
|
|
4306
|
+
${getFlagListOutput(flags, 6)}
|
|
4210
4307
|
|
|
4211
4308
|
Examples
|
|
4212
4309
|
$ ${name} FakeCorp --before=aaa0aa0a-aaaa-0000-0a0a-0000000a00a0 --after=aaa1aa1a-aaaa-1111-1a1a-1111111a11a1
|
|
@@ -4297,7 +4394,6 @@ const diffScan = {
|
|
|
4297
4394
|
}
|
|
4298
4395
|
};
|
|
4299
4396
|
|
|
4300
|
-
// @ts-ignore
|
|
4301
4397
|
const threatFeed = {
|
|
4302
4398
|
description: 'Look up the threat feed',
|
|
4303
4399
|
async run(argv, importMeta, {
|
|
@@ -4306,14 +4402,14 @@ const threatFeed = {
|
|
|
4306
4402
|
const name = `${parentName} threat-feed`;
|
|
4307
4403
|
const input = setupCommand(name, threatFeed.description, argv, importMeta);
|
|
4308
4404
|
{
|
|
4309
|
-
const apiKey =
|
|
4405
|
+
const apiKey = socketUrl.getDefaultToken();
|
|
4310
4406
|
if (!apiKey) {
|
|
4311
|
-
throw new
|
|
4407
|
+
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.');
|
|
4312
4408
|
}
|
|
4313
|
-
const spinner =
|
|
4409
|
+
const spinner$1 = new spinner.Spinner({
|
|
4314
4410
|
text: 'Looking up the threat feed'
|
|
4315
4411
|
}).start();
|
|
4316
|
-
await fetchThreatFeed(input, spinner, apiKey);
|
|
4412
|
+
await fetchThreatFeed(input, spinner$1, apiKey);
|
|
4317
4413
|
}
|
|
4318
4414
|
}
|
|
4319
4415
|
};
|
|
@@ -4357,7 +4453,7 @@ function setupCommand(name, description, argv, importMeta) {
|
|
|
4357
4453
|
$ ${name}
|
|
4358
4454
|
|
|
4359
4455
|
Options
|
|
4360
|
-
${
|
|
4456
|
+
${getFlagListOutput(flags, 6)}
|
|
4361
4457
|
|
|
4362
4458
|
Examples
|
|
4363
4459
|
$ ${name}
|
|
@@ -4433,7 +4529,7 @@ async function fetchThreatFeed({
|
|
|
4433
4529
|
data: formattedOutput
|
|
4434
4530
|
});
|
|
4435
4531
|
screen.render();
|
|
4436
|
-
screen.key(['escape', 'q', 'C-c'], () => process.exit(0));
|
|
4532
|
+
screen.key(['escape', 'q', 'C-c'], () => process$1.exit(0));
|
|
4437
4533
|
}
|
|
4438
4534
|
const formatResults = data => {
|
|
4439
4535
|
return data.map(d => {
|
|
@@ -4458,6 +4554,7 @@ var cliCommands = {
|
|
|
4458
4554
|
cdxgen: cdxgen,
|
|
4459
4555
|
dependencies: dependencies,
|
|
4460
4556
|
diffScan: diffScan,
|
|
4557
|
+
fix: fix,
|
|
4461
4558
|
info: info,
|
|
4462
4559
|
login: login,
|
|
4463
4560
|
logout: logout,
|
|
@@ -4501,7 +4598,7 @@ void (async () => {
|
|
|
4501
4598
|
argv: ['report', 'create', '--view', '--strict']
|
|
4502
4599
|
}
|
|
4503
4600
|
},
|
|
4504
|
-
argv: process.argv.slice(2),
|
|
4601
|
+
argv: process$1.argv.slice(2),
|
|
4505
4602
|
name: 'socket',
|
|
4506
4603
|
importMeta: {
|
|
4507
4604
|
url: `${node_url.pathToFileURL(__filename)}`
|
|
@@ -4511,10 +4608,10 @@ void (async () => {
|
|
|
4511
4608
|
let errorBody;
|
|
4512
4609
|
let errorTitle;
|
|
4513
4610
|
let errorMessage = '';
|
|
4514
|
-
if (err instanceof
|
|
4611
|
+
if (err instanceof socketUrl.AuthError) {
|
|
4515
4612
|
errorTitle = 'Authentication error';
|
|
4516
4613
|
errorMessage = err.message;
|
|
4517
|
-
} else if (err instanceof
|
|
4614
|
+
} else if (err instanceof socketUrl.InputError) {
|
|
4518
4615
|
errorTitle = 'Invalid input';
|
|
4519
4616
|
errorMessage = err.message;
|
|
4520
4617
|
errorBody = err.body;
|
|
@@ -4525,10 +4622,10 @@ void (async () => {
|
|
|
4525
4622
|
} else {
|
|
4526
4623
|
errorTitle = 'Unexpected error with no details';
|
|
4527
4624
|
}
|
|
4528
|
-
console.error(`${
|
|
4625
|
+
console.error(`${pathResolve.logSymbols.error} ${colors.bgRed(colors.white(errorTitle + ':'))} ${errorMessage}`);
|
|
4529
4626
|
if (errorBody) {
|
|
4530
4627
|
console.error(`\n${errorBody}`);
|
|
4531
4628
|
}
|
|
4532
|
-
process.exit(1);
|
|
4629
|
+
process$1.exit(1);
|
|
4533
4630
|
}
|
|
4534
4631
|
})();
|