socket 0.14.40-alpha.9 → 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 +2 -0
- package/dist/{module-sync/constants.d.ts → constants.d.ts} +9 -2
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +16 -12
- package/dist/module-sync/cli.js +292 -251
- 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 +1027 -939
- package/dist/module-sync/path-resolve.d.ts +1 -1
- package/dist/module-sync/path-resolve.js +49 -1
- package/dist/module-sync/shadow-bin.d.ts +2 -2
- package/dist/module-sync/shadow-bin.js +10 -7
- package/dist/module-sync/socket-url.d.ts +24 -0
- package/dist/module-sync/socket-url.js +222 -0
- package/dist/require/cli.js +292 -249
- package/dist/require/npm-injection.js +2 -1500
- package/dist/require/path-resolve.js +2 -197
- package/dist/require/shadow-bin.js +2 -82
- package/dist/require/socket-url.js +3 -0
- package/dist/require/vendor.js +53 -400
- package/package.json +18 -18
- 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'));
|
|
@@ -22,10 +23,13 @@ var words = require('@socketsecurity/registry/lib/words');
|
|
|
22
23
|
var constants = require('./constants.js');
|
|
23
24
|
var spinner = require('@socketsecurity/registry/lib/spinner');
|
|
24
25
|
var spawn = _socketInterop(require('@npmcli/promise-spawn'));
|
|
26
|
+
var objects = require('@socketsecurity/registry/lib/objects');
|
|
27
|
+
var pathResolve = require('./path-resolve.js');
|
|
25
28
|
var meow = _socketInterop(require('meow'));
|
|
26
|
-
var
|
|
27
|
-
var
|
|
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');
|
|
29
33
|
var prompts = require('@socketsecurity/registry/lib/prompts');
|
|
30
34
|
var fs$1 = require('node:fs/promises');
|
|
31
35
|
var npa = _socketInterop(require('npm-package-arg'));
|
|
@@ -33,20 +37,17 @@ 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'));
|
|
@@ -58,7 +59,7 @@ 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) {
|
|
179
|
-
process.exitCode = 1;
|
|
180
|
+
process$1.exitCode = 1;
|
|
180
181
|
console.error(`Unknown ${words.pluralize('argument', unknownLength)}: ${yargv._.join(', ')}`);
|
|
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,7 +212,7 @@ 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
|
}
|
|
@@ -221,45 +222,62 @@ const cdxgen = {
|
|
|
221
222
|
const {
|
|
222
223
|
abortSignal: abortSignal$3
|
|
223
224
|
} = constants;
|
|
224
|
-
|
|
225
|
+
function shadowNpmInstall(opts) {
|
|
225
226
|
const {
|
|
226
227
|
flags = [],
|
|
228
|
+
ipc,
|
|
227
229
|
...spawnOptions
|
|
228
230
|
} = {
|
|
229
231
|
__proto__: null,
|
|
230
232
|
...opts
|
|
231
233
|
};
|
|
232
|
-
|
|
233
|
-
const
|
|
234
|
-
|
|
235
|
-
} = constants.ENV;
|
|
236
|
-
return await spawn(
|
|
234
|
+
const useIpc = objects.isObject(ipc);
|
|
235
|
+
const useDebug = pathResolve.isDebug();
|
|
236
|
+
const promise = spawn(
|
|
237
237
|
// Lazily access constants.execPath.
|
|
238
238
|
constants.execPath, [
|
|
239
239
|
// Lazily access constants.rootBinPath.
|
|
240
|
-
path.join(constants.rootBinPath, 'npm-cli.js'), 'install',
|
|
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], {
|
|
241
245
|
signal: abortSignal$3,
|
|
242
|
-
//
|
|
243
|
-
|
|
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',
|
|
244
254
|
...spawnOptions,
|
|
245
255
|
env: {
|
|
246
|
-
...process.env,
|
|
256
|
+
...process$1.env,
|
|
247
257
|
...spawnOptions.env
|
|
248
258
|
}
|
|
249
259
|
});
|
|
260
|
+
if (useIpc) {
|
|
261
|
+
promise.process.send(ipc);
|
|
262
|
+
}
|
|
263
|
+
return promise;
|
|
250
264
|
}
|
|
251
265
|
|
|
252
266
|
const {
|
|
253
|
-
SOCKET_CLI_FIX_PACKAGE_LOCK_FILE
|
|
267
|
+
SOCKET_CLI_FIX_PACKAGE_LOCK_FILE,
|
|
268
|
+
SOCKET_IPC_HANDSHAKE: SOCKET_IPC_HANDSHAKE$1
|
|
254
269
|
} = constants;
|
|
255
270
|
const fix = {
|
|
256
271
|
description: 'Fix "fixable" Socket alerts',
|
|
272
|
+
hidden: true,
|
|
257
273
|
async run() {
|
|
258
274
|
const spinner$1 = new spinner.Spinner().start();
|
|
259
275
|
try {
|
|
260
276
|
await shadowNpmInstall({
|
|
261
|
-
|
|
262
|
-
[
|
|
277
|
+
ipc: {
|
|
278
|
+
[SOCKET_IPC_HANDSHAKE$1]: {
|
|
279
|
+
[SOCKET_CLI_FIX_PACKAGE_LOCK_FILE]: true
|
|
280
|
+
}
|
|
263
281
|
}
|
|
264
282
|
});
|
|
265
283
|
} catch (e) {
|
|
@@ -326,10 +344,10 @@ function handleUnsuccessfulApiResponse(_name, result, spinner) {
|
|
|
326
344
|
const message = typeof resultErrorMessage === 'string' ? resultErrorMessage : 'No error message returned';
|
|
327
345
|
if (result.status === 401 || result.status === 403) {
|
|
328
346
|
spinner.stop();
|
|
329
|
-
throw new
|
|
347
|
+
throw new socketUrl.AuthError(message);
|
|
330
348
|
}
|
|
331
349
|
spinner.error(`${colors.bgRed(colors.white('API returned an error:'))} ${message}`);
|
|
332
|
-
process.exit(1);
|
|
350
|
+
process$1.exit(1);
|
|
333
351
|
}
|
|
334
352
|
async function handleApiCall(value, description) {
|
|
335
353
|
let result;
|
|
@@ -374,6 +392,46 @@ function pick(input, keys) {
|
|
|
374
392
|
return result;
|
|
375
393
|
}
|
|
376
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
|
+
|
|
377
435
|
const SEVERITIES_BY_ORDER = ['critical', 'high', 'middle', 'low'];
|
|
378
436
|
function getDesiredSeverities(lowestToInclude) {
|
|
379
437
|
const result = [];
|
|
@@ -392,7 +450,7 @@ function formatSeverityCount(severityCount) {
|
|
|
392
450
|
summary.push(`${severityCount[severity]} ${severity}`);
|
|
393
451
|
}
|
|
394
452
|
}
|
|
395
|
-
return
|
|
453
|
+
return stringJoinWithSeparateFinalSeparator(summary);
|
|
396
454
|
}
|
|
397
455
|
function getSeverityCount(issues, lowestToInclude) {
|
|
398
456
|
const severityCount = pick({
|
|
@@ -402,7 +460,9 @@ function getSeverityCount(issues, lowestToInclude) {
|
|
|
402
460
|
critical: 0
|
|
403
461
|
}, getDesiredSeverities(lowestToInclude));
|
|
404
462
|
for (const issue of issues) {
|
|
405
|
-
const
|
|
463
|
+
const {
|
|
464
|
+
value
|
|
465
|
+
} = issue;
|
|
406
466
|
if (!value) {
|
|
407
467
|
continue;
|
|
408
468
|
}
|
|
@@ -413,34 +473,9 @@ function getSeverityCount(issues, lowestToInclude) {
|
|
|
413
473
|
return severityCount;
|
|
414
474
|
}
|
|
415
475
|
|
|
416
|
-
function printFlagList(list, indent, {
|
|
417
|
-
keyPrefix = '--',
|
|
418
|
-
padName
|
|
419
|
-
} = {}) {
|
|
420
|
-
return printHelpList({
|
|
421
|
-
...list
|
|
422
|
-
}, indent, {
|
|
423
|
-
keyPrefix,
|
|
424
|
-
padName
|
|
425
|
-
});
|
|
426
|
-
}
|
|
427
|
-
function printHelpList(list, indent, {
|
|
428
|
-
keyPrefix = '',
|
|
429
|
-
padName = 18
|
|
430
|
-
} = {}) {
|
|
431
|
-
let result = '';
|
|
432
|
-
const names = Object.keys(list).sort();
|
|
433
|
-
for (const name of names) {
|
|
434
|
-
const rawDescription = list[name];
|
|
435
|
-
const description = (typeof rawDescription === 'object' ? rawDescription.description : rawDescription) || '';
|
|
436
|
-
result += ''.padEnd(indent) + (keyPrefix + name).padEnd(padName) + description + '\n';
|
|
437
|
-
}
|
|
438
|
-
return result.trim();
|
|
439
|
-
}
|
|
440
|
-
|
|
441
476
|
const {
|
|
442
|
-
|
|
443
|
-
} =
|
|
477
|
+
NPM: NPM$4
|
|
478
|
+
} = registryConstants;
|
|
444
479
|
const info = {
|
|
445
480
|
description: 'Look up info regarding a package',
|
|
446
481
|
async run(argv, importMeta, {
|
|
@@ -477,7 +512,7 @@ function setupCommand$m(name, description, argv, importMeta) {
|
|
|
477
512
|
$ ${name} <name>
|
|
478
513
|
|
|
479
514
|
Options
|
|
480
|
-
${
|
|
515
|
+
${getFlagListOutput(flags, 6)}
|
|
481
516
|
|
|
482
517
|
Examples
|
|
483
518
|
$ ${name} webtorrent
|
|
@@ -489,7 +524,7 @@ function setupCommand$m(name, description, argv, importMeta) {
|
|
|
489
524
|
flags
|
|
490
525
|
});
|
|
491
526
|
if (cli.input.length > 1) {
|
|
492
|
-
throw new
|
|
527
|
+
throw new socketUrl.InputError('Only one package lookup supported at once');
|
|
493
528
|
}
|
|
494
529
|
const {
|
|
495
530
|
0: rawPkgName = ''
|
|
@@ -517,7 +552,7 @@ function setupCommand$m(name, description, argv, importMeta) {
|
|
|
517
552
|
async function fetchPackageData(pkgName, pkgVersion, {
|
|
518
553
|
includeAllIssues
|
|
519
554
|
}, spinner) {
|
|
520
|
-
const socketSdk = await
|
|
555
|
+
const socketSdk = await socketUrl.setupSdk(socketUrl.getPublicToken());
|
|
521
556
|
const result = await handleApiCall(socketSdk.getIssuesByNPMPackage(pkgName, pkgVersion), 'looking up package');
|
|
522
557
|
const scoreResult = await handleApiCall(socketSdk.getScoreByNPMPackage(pkgName, pkgVersion), 'looking up package score');
|
|
523
558
|
if (result.success === false) {
|
|
@@ -564,8 +599,8 @@ function formatPackageDataOutput({
|
|
|
564
599
|
} else {
|
|
565
600
|
spinner.success('Package has no issues');
|
|
566
601
|
}
|
|
567
|
-
const format = new
|
|
568
|
-
const url =
|
|
602
|
+
const format = new socketUrl.ColorOrMarkdown(!!outputMarkdown);
|
|
603
|
+
const url = socketUrl.getSocketDevPackageOverviewUrl(NPM$4, pkgName, pkgVersion);
|
|
569
604
|
console.log('\n');
|
|
570
605
|
if (pkgVersion === 'latest') {
|
|
571
606
|
console.log(`Detailed info on socket.dev: ${format.hyperlink(`${pkgName}`, url, {
|
|
@@ -581,7 +616,7 @@ function formatPackageDataOutput({
|
|
|
581
616
|
}
|
|
582
617
|
}
|
|
583
618
|
if (strict && objectSome(severityCount)) {
|
|
584
|
-
process.exit(1);
|
|
619
|
+
process$1.exit(1);
|
|
585
620
|
}
|
|
586
621
|
}
|
|
587
622
|
function formatPackageIssuesDetails(packageData, outputMarkdown) {
|
|
@@ -602,9 +637,9 @@ function formatPackageIssuesDetails(packageData, outputMarkdown) {
|
|
|
602
637
|
}
|
|
603
638
|
return acc;
|
|
604
639
|
}, {});
|
|
605
|
-
const format = new
|
|
640
|
+
const format = new socketUrl.ColorOrMarkdown(!!outputMarkdown);
|
|
606
641
|
for (const issue of Object.keys(uniqueIssues)) {
|
|
607
|
-
const issueWithLink = format.hyperlink(`${uniqueIssues[issue]?.label}`,
|
|
642
|
+
const issueWithLink = format.hyperlink(`${uniqueIssues[issue]?.label}`, socketUrl.getSocketDevAlertUrl(issue), {
|
|
608
643
|
fallbackToUrl: true
|
|
609
644
|
});
|
|
610
645
|
if (uniqueIssues[issue]?.count === 1) {
|
|
@@ -624,7 +659,7 @@ function formatScore(score) {
|
|
|
624
659
|
}
|
|
625
660
|
|
|
626
661
|
const {
|
|
627
|
-
|
|
662
|
+
SOCKET_PUBLIC_API_TOKEN
|
|
628
663
|
} = constants;
|
|
629
664
|
const description$5 = 'Socket API login';
|
|
630
665
|
const flags = {
|
|
@@ -653,7 +688,7 @@ const login = {
|
|
|
653
688
|
Logs into the Socket API by prompting for an API key
|
|
654
689
|
|
|
655
690
|
Options
|
|
656
|
-
${
|
|
691
|
+
${getFlagListOutput({
|
|
657
692
|
'api-base-url': flags['apiBaseUrl'].description,
|
|
658
693
|
'api-proxy': flags['apiProxy'].description
|
|
659
694
|
}, 8)}
|
|
@@ -675,24 +710,24 @@ const login = {
|
|
|
675
710
|
return;
|
|
676
711
|
}
|
|
677
712
|
if (!isInteractive()) {
|
|
678
|
-
throw new
|
|
713
|
+
throw new socketUrl.InputError('Cannot prompt for credentials in a non-interactive shell');
|
|
679
714
|
}
|
|
680
|
-
const
|
|
715
|
+
const apiToken = (await prompts.password({
|
|
681
716
|
message: `Enter your ${terminalLink('Socket.dev API key', 'https://docs.socket.dev/docs/api-keys')} (leave blank for a public key)`
|
|
682
|
-
})) ||
|
|
717
|
+
})) || SOCKET_PUBLIC_API_TOKEN;
|
|
683
718
|
let apiBaseUrl = cli.flags['apiBaseUrl'];
|
|
684
|
-
apiBaseUrl ??=
|
|
719
|
+
apiBaseUrl ??= socketUrl.getSetting('apiBaseUrl') ?? undefined;
|
|
685
720
|
let apiProxy = cli.flags['apiProxy'];
|
|
686
|
-
apiProxy ??=
|
|
721
|
+
apiProxy ??= socketUrl.getSetting('apiProxy') ?? undefined;
|
|
687
722
|
const spinner$1 = new spinner.Spinner({
|
|
688
723
|
text: 'Verifying API key...'
|
|
689
724
|
}).start();
|
|
690
725
|
let orgs;
|
|
691
726
|
try {
|
|
692
|
-
const sdk
|
|
693
|
-
const result = await sdk
|
|
727
|
+
const sdk = await socketUrl.setupSdk(apiToken, apiBaseUrl, apiProxy);
|
|
728
|
+
const result = await sdk.getOrganizations();
|
|
694
729
|
if (!result.success) {
|
|
695
|
-
throw new
|
|
730
|
+
throw new socketUrl.AuthError();
|
|
696
731
|
}
|
|
697
732
|
orgs = result.data;
|
|
698
733
|
spinner$1.success('API key verified');
|
|
@@ -729,12 +764,13 @@ const login = {
|
|
|
729
764
|
}
|
|
730
765
|
}
|
|
731
766
|
}
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
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'}`);
|
|
738
774
|
}
|
|
739
775
|
};
|
|
740
776
|
|
|
@@ -766,10 +802,10 @@ const logout = {
|
|
|
766
802
|
cli.showHelp();
|
|
767
803
|
return;
|
|
768
804
|
}
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
805
|
+
socketUrl.updateSetting('apiKey', null);
|
|
806
|
+
socketUrl.updateSetting('apiBaseUrl', null);
|
|
807
|
+
socketUrl.updateSetting('apiProxy', null);
|
|
808
|
+
socketUrl.updateSetting('enforcedOrgs', null);
|
|
773
809
|
new spinner.Spinner().success('Successfully logged out');
|
|
774
810
|
}
|
|
775
811
|
};
|
|
@@ -805,7 +841,7 @@ function existsSync(filepath) {
|
|
|
805
841
|
return false;
|
|
806
842
|
}
|
|
807
843
|
async function findUp(name, {
|
|
808
|
-
cwd = process.cwd()
|
|
844
|
+
cwd = process$1.cwd()
|
|
809
845
|
}) {
|
|
810
846
|
let dir = path.resolve(cwd);
|
|
811
847
|
const {
|
|
@@ -847,6 +883,7 @@ const {
|
|
|
847
883
|
NPM: NPM$2,
|
|
848
884
|
PNPM: PNPM$1,
|
|
849
885
|
VLT: VLT$1,
|
|
886
|
+
YARN,
|
|
850
887
|
YARN_BERRY: YARN_BERRY$1,
|
|
851
888
|
YARN_CLASSIC: YARN_CLASSIC$1
|
|
852
889
|
} = constants;
|
|
@@ -857,10 +894,20 @@ const {
|
|
|
857
894
|
numeric: true,
|
|
858
895
|
sensitivity: 'base'
|
|
859
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
|
+
};
|
|
860
906
|
async function getAgentExecPath(agent) {
|
|
861
|
-
|
|
907
|
+
const binName = binByAgent[agent];
|
|
908
|
+
return (await which(binName, {
|
|
862
909
|
nothrow: true
|
|
863
|
-
})) ??
|
|
910
|
+
})) ?? binName;
|
|
864
911
|
}
|
|
865
912
|
async function getAgentVersion(agentExecPath, cwd) {
|
|
866
913
|
let result;
|
|
@@ -916,7 +963,7 @@ const readLockFileByAgent = (() => {
|
|
|
916
963
|
const lockBuffer = await binaryReader(lockPath);
|
|
917
964
|
if (lockBuffer) {
|
|
918
965
|
try {
|
|
919
|
-
return
|
|
966
|
+
return index_cjs.parse(lockBuffer);
|
|
920
967
|
} catch {}
|
|
921
968
|
}
|
|
922
969
|
// To print a Yarn lockfile to your console without writing it to disk
|
|
@@ -934,7 +981,7 @@ const readLockFileByAgent = (() => {
|
|
|
934
981
|
};
|
|
935
982
|
})();
|
|
936
983
|
async function detect({
|
|
937
|
-
cwd = process.cwd(),
|
|
984
|
+
cwd = process$1.cwd(),
|
|
938
985
|
onUnknown
|
|
939
986
|
} = {}) {
|
|
940
987
|
let lockPath = await findUp(Object.keys(LOCKS), {
|
|
@@ -1045,6 +1092,7 @@ const {
|
|
|
1045
1092
|
PNPM,
|
|
1046
1093
|
RESOLUTIONS,
|
|
1047
1094
|
SOCKET_CLI_UPDATE_OVERRIDES_IN_PACKAGE_LOCK_FILE,
|
|
1095
|
+
SOCKET_IPC_HANDSHAKE,
|
|
1048
1096
|
VLT,
|
|
1049
1097
|
YARN_BERRY,
|
|
1050
1098
|
YARN_CLASSIC,
|
|
@@ -1056,6 +1104,7 @@ const PNPM_FIELD_NAME = PNPM;
|
|
|
1056
1104
|
const PNPM_WORKSPACE = `${PNPM}-workspace`;
|
|
1057
1105
|
const manifestNpmOverrides = registry.getManifestData(NPM$1);
|
|
1058
1106
|
const getOverridesDataByAgent = {
|
|
1107
|
+
__proto__: null,
|
|
1059
1108
|
[BUN](pkgJson) {
|
|
1060
1109
|
const overrides = pkgJson?.[RESOLUTIONS] ?? {};
|
|
1061
1110
|
return {
|
|
@@ -1124,6 +1173,7 @@ const lockIncludesByAgent = (() => {
|
|
|
1124
1173
|
`(?<=(?:^\\s*|,\\s*)"?)${escapedName}(?=@)`, 'm').test(lockSrc);
|
|
1125
1174
|
}
|
|
1126
1175
|
return {
|
|
1176
|
+
__proto__: null,
|
|
1127
1177
|
[BUN](lockSrc, name, lockBasename) {
|
|
1128
1178
|
// This is a bit counterintuitive. When lockBasename ends with a .lockb
|
|
1129
1179
|
// we treat it as a yarn.lock. When lockBasename ends with a .lock we
|
|
@@ -1246,6 +1296,7 @@ const updateManifestByAgent = (() => {
|
|
|
1246
1296
|
updatePkgJson(editablePkgJson, RESOLUTIONS, overrides);
|
|
1247
1297
|
}
|
|
1248
1298
|
return {
|
|
1299
|
+
__proto__: null,
|
|
1249
1300
|
[BUN]: updateResolutions,
|
|
1250
1301
|
[NPM$1]: updateOverrides,
|
|
1251
1302
|
[PNPM](editablePkgJson, overrides) {
|
|
@@ -1307,6 +1358,7 @@ const lsByAgent = (() => {
|
|
|
1307
1358
|
return cleanupQueryStdout(stdout);
|
|
1308
1359
|
}
|
|
1309
1360
|
return {
|
|
1361
|
+
__proto__: null,
|
|
1310
1362
|
async [BUN](agentExecPath, cwd) {
|
|
1311
1363
|
try {
|
|
1312
1364
|
// Bun does not support filtering by production packages yet.
|
|
@@ -1384,6 +1436,7 @@ const depsIncludesByAgent = (() => {
|
|
|
1384
1436
|
return stdout.includes(`"${name}"`);
|
|
1385
1437
|
}
|
|
1386
1438
|
return {
|
|
1439
|
+
__proto__: null,
|
|
1387
1440
|
[BUN]: matchHumanStdout,
|
|
1388
1441
|
[NPM$1]: matchQueryStdout,
|
|
1389
1442
|
[PNPM]: matchQueryStdout,
|
|
@@ -1566,7 +1619,7 @@ async function addOverrides({
|
|
|
1566
1619
|
const oldSpec = overrideExists ? overrides[origPkgName] : undefined;
|
|
1567
1620
|
const depAlias = depAliasMap.get(origPkgName);
|
|
1568
1621
|
const regSpecStartsLike = `${NPM$1}:${regPkgName}@`;
|
|
1569
|
-
let newSpec = `${regSpecStartsLike}
|
|
1622
|
+
let newSpec = `${regSpecStartsLike}${pin ? version : `^${major}`}`;
|
|
1570
1623
|
let thisVersion = version;
|
|
1571
1624
|
if (depAlias && type === NPM$1) {
|
|
1572
1625
|
// With npm one may not set an override for a package that one directly
|
|
@@ -1583,7 +1636,7 @@ async function addOverrides({
|
|
|
1583
1636
|
if (pin) {
|
|
1584
1637
|
thisVersion = semver.major(semver.coerce(npa(thisSpec).rawSpec)?.version ?? version) === major ? version : (await packages.fetchPackageManifest(thisSpec))?.version ?? version;
|
|
1585
1638
|
}
|
|
1586
|
-
newSpec = `${regSpecStartsLike}
|
|
1639
|
+
newSpec = `${regSpecStartsLike}${pin ? thisVersion : `^${semver.major(thisVersion)}`}`;
|
|
1587
1640
|
} else {
|
|
1588
1641
|
newSpec = oldSpec;
|
|
1589
1642
|
}
|
|
@@ -1651,7 +1704,7 @@ const optimize = {
|
|
|
1651
1704
|
pin,
|
|
1652
1705
|
prod
|
|
1653
1706
|
} = commandContext;
|
|
1654
|
-
const cwd = process.cwd();
|
|
1707
|
+
const cwd = process$1.cwd();
|
|
1655
1708
|
const {
|
|
1656
1709
|
agent,
|
|
1657
1710
|
agentExecPath,
|
|
@@ -1743,19 +1796,20 @@ const optimize = {
|
|
|
1743
1796
|
spinner$1.start(`Updating ${lockName}...`);
|
|
1744
1797
|
try {
|
|
1745
1798
|
if (isNpm) {
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
[SOCKET_CLI_UPDATE_OVERRIDES_IN_PACKAGE_LOCK_FILE]:
|
|
1799
|
+
const ipc = {
|
|
1800
|
+
[SOCKET_IPC_HANDSHAKE]: {
|
|
1801
|
+
[SOCKET_CLI_UPDATE_OVERRIDES_IN_PACKAGE_LOCK_FILE]: true
|
|
1749
1802
|
}
|
|
1803
|
+
};
|
|
1804
|
+
await shadowNpmInstall({
|
|
1805
|
+
ipc
|
|
1750
1806
|
});
|
|
1751
1807
|
// TODO: This is a temporary workaround for a `npm ci` bug where it
|
|
1752
1808
|
// will error out after Socket Optimize generates a lock file. More
|
|
1753
1809
|
// investigation is needed.
|
|
1754
1810
|
await shadowNpmInstall({
|
|
1755
1811
|
flags: ['--ignore-scripts', '--package-lock-only'],
|
|
1756
|
-
|
|
1757
|
-
[SOCKET_CLI_UPDATE_OVERRIDES_IN_PACKAGE_LOCK_FILE]: '1'
|
|
1758
|
-
}
|
|
1812
|
+
ipc
|
|
1759
1813
|
});
|
|
1760
1814
|
} else {
|
|
1761
1815
|
// All package managers support the "install" command.
|
|
@@ -1797,7 +1851,7 @@ function setupCommand$l(name, description, argv, importMeta) {
|
|
|
1797
1851
|
$ ${name}
|
|
1798
1852
|
|
|
1799
1853
|
Options
|
|
1800
|
-
${
|
|
1854
|
+
${getFlagListOutput(flags, 6)}
|
|
1801
1855
|
|
|
1802
1856
|
Examples
|
|
1803
1857
|
$ ${name}
|
|
@@ -1845,14 +1899,14 @@ function setupCommand$k(name, description, argv, importMeta) {
|
|
|
1845
1899
|
});
|
|
1846
1900
|
}
|
|
1847
1901
|
async function fetchOrganizations() {
|
|
1848
|
-
const apiKey =
|
|
1902
|
+
const apiKey = socketUrl.getDefaultToken();
|
|
1849
1903
|
if (!apiKey) {
|
|
1850
|
-
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.');
|
|
1851
1905
|
}
|
|
1852
1906
|
const spinner$1 = new spinner.Spinner({
|
|
1853
1907
|
text: 'Fetching organizations...'
|
|
1854
1908
|
}).start();
|
|
1855
|
-
const socketSdk = await
|
|
1909
|
+
const socketSdk = await socketUrl.setupSdk(apiKey);
|
|
1856
1910
|
const result = await handleApiCall(socketSdk.getOrganizations(), 'looking up organizations');
|
|
1857
1911
|
if (result.success === false) {
|
|
1858
1912
|
handleUnsuccessfulApiResponse('getOrganizations', result, spinner$1);
|
|
@@ -1892,7 +1946,7 @@ async function setupCommand$j(name, description, argv, importMeta) {
|
|
|
1892
1946
|
$ ${name} <${binName$1} command>
|
|
1893
1947
|
|
|
1894
1948
|
Options
|
|
1895
|
-
${
|
|
1949
|
+
${getFlagListOutput(flags, 6)}
|
|
1896
1950
|
|
|
1897
1951
|
Examples
|
|
1898
1952
|
$ ${name} install
|
|
@@ -1917,7 +1971,7 @@ async function setupCommand$j(name, description, argv, importMeta) {
|
|
|
1917
1971
|
// The exit code 127 indicates that the command or binary being executed
|
|
1918
1972
|
// could not be found.
|
|
1919
1973
|
console.error(`Socket unable to locate ${binName$1}; ensure it is available in the PATH environment variable.`);
|
|
1920
|
-
process.exit(127);
|
|
1974
|
+
process$1.exit(127);
|
|
1921
1975
|
}
|
|
1922
1976
|
const spawnPromise = spawn(binPath, argv, {
|
|
1923
1977
|
signal: abortSignal$1,
|
|
@@ -1929,9 +1983,9 @@ async function setupCommand$j(name, description, argv, importMeta) {
|
|
|
1929
1983
|
return;
|
|
1930
1984
|
}
|
|
1931
1985
|
if (signalName) {
|
|
1932
|
-
process.kill(process.pid, signalName);
|
|
1986
|
+
process$1.kill(process$1.pid, signalName);
|
|
1933
1987
|
} else if (code !== null) {
|
|
1934
|
-
process.exit(code);
|
|
1988
|
+
process$1.exit(code);
|
|
1935
1989
|
}
|
|
1936
1990
|
});
|
|
1937
1991
|
await spawnPromise;
|
|
@@ -1960,7 +2014,7 @@ async function setupCommand$i(name, description, argv, importMeta) {
|
|
|
1960
2014
|
$ ${name} <${binName} command>
|
|
1961
2015
|
|
|
1962
2016
|
Options
|
|
1963
|
-
${
|
|
2017
|
+
${getFlagListOutput(flags, 6)}
|
|
1964
2018
|
|
|
1965
2019
|
Examples
|
|
1966
2020
|
$ ${name} install
|
|
@@ -1985,7 +2039,7 @@ async function setupCommand$i(name, description, argv, importMeta) {
|
|
|
1985
2039
|
// The exit code 127 indicates that the command or binary being executed
|
|
1986
2040
|
// could not be found.
|
|
1987
2041
|
console.error(`Socket unable to locate ${binName}; ensure it is available in the PATH environment variable.`);
|
|
1988
|
-
process.exit(127);
|
|
2042
|
+
process$1.exit(127);
|
|
1989
2043
|
}
|
|
1990
2044
|
const spawnPromise = spawn(binPath, argv, {
|
|
1991
2045
|
signal: abortSignal,
|
|
@@ -1997,9 +2051,9 @@ async function setupCommand$i(name, description, argv, importMeta) {
|
|
|
1997
2051
|
return;
|
|
1998
2052
|
}
|
|
1999
2053
|
if (signalName) {
|
|
2000
|
-
process.kill(process.pid, signalName);
|
|
2054
|
+
process$1.kill(process$1.pid, signalName);
|
|
2001
2055
|
} else if (code !== null) {
|
|
2002
|
-
process.exit(code);
|
|
2056
|
+
process$1.exit(code);
|
|
2003
2057
|
}
|
|
2004
2058
|
});
|
|
2005
2059
|
await spawnPromise;
|
|
@@ -2035,7 +2089,7 @@ function setupCommand$h(name, description, argv, importMeta) {
|
|
|
2035
2089
|
$ ${name} <report-identifier>
|
|
2036
2090
|
|
|
2037
2091
|
Options
|
|
2038
|
-
${
|
|
2092
|
+
${getFlagListOutput(flags, 6)}
|
|
2039
2093
|
|
|
2040
2094
|
Examples
|
|
2041
2095
|
$ ${name} QXU8PmK7LfH608RAwfIKdbcHgwEd_ZeWJ9QEGv05FJUQ
|
|
@@ -2057,7 +2111,7 @@ function setupCommand$h(name, description, argv, importMeta) {
|
|
|
2057
2111
|
}
|
|
2058
2112
|
// Validate the input.
|
|
2059
2113
|
if (extraInput.length) {
|
|
2060
|
-
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(', ')}`);
|
|
2061
2115
|
}
|
|
2062
2116
|
return {
|
|
2063
2117
|
includeAllIssues: cli.flags['all'],
|
|
@@ -2073,7 +2127,7 @@ async function fetchReportData(reportId, {
|
|
|
2073
2127
|
strict
|
|
2074
2128
|
}) {
|
|
2075
2129
|
// Do the API call
|
|
2076
|
-
const socketSdk = await
|
|
2130
|
+
const socketSdk = await socketUrl.setupSdk();
|
|
2077
2131
|
const spinner$1 = new spinner.Spinner({
|
|
2078
2132
|
text: `Fetching report with ID ${reportId} (this could take a while)`
|
|
2079
2133
|
}).start();
|
|
@@ -2119,7 +2173,7 @@ function formatReportDataOutput(data, {
|
|
|
2119
2173
|
if (outputJson) {
|
|
2120
2174
|
console.log(JSON.stringify(data, undefined, 2));
|
|
2121
2175
|
} else {
|
|
2122
|
-
const format = new
|
|
2176
|
+
const format = new socketUrl.ColorOrMarkdown(!!outputMarkdown);
|
|
2123
2177
|
console.log('\nDetailed info on socket.dev: ' + format.hyperlink(reportId, data.url, {
|
|
2124
2178
|
fallbackToUrl: true
|
|
2125
2179
|
}));
|
|
@@ -2128,7 +2182,7 @@ function formatReportDataOutput(data, {
|
|
|
2128
2182
|
}
|
|
2129
2183
|
}
|
|
2130
2184
|
if (strict && data.healthy === false) {
|
|
2131
|
-
process.exit(1);
|
|
2185
|
+
process$1.exit(1);
|
|
2132
2186
|
}
|
|
2133
2187
|
}
|
|
2134
2188
|
|
|
@@ -2143,7 +2197,6 @@ const create$2 = {
|
|
|
2143
2197
|
const {
|
|
2144
2198
|
config,
|
|
2145
2199
|
cwd,
|
|
2146
|
-
debugLog,
|
|
2147
2200
|
dryRun,
|
|
2148
2201
|
includeAllIssues,
|
|
2149
2202
|
outputJson,
|
|
@@ -2155,7 +2208,6 @@ const create$2 = {
|
|
|
2155
2208
|
const result = input && (await createReport(packagePaths, {
|
|
2156
2209
|
config,
|
|
2157
2210
|
cwd,
|
|
2158
|
-
debugLog,
|
|
2159
2211
|
dryRun
|
|
2160
2212
|
}));
|
|
2161
2213
|
if (result && view) {
|
|
@@ -2191,12 +2243,6 @@ async function setupCommand$g(name, description, argv, importMeta) {
|
|
|
2191
2243
|
...commonFlags,
|
|
2192
2244
|
...outputFlags,
|
|
2193
2245
|
...validationFlags,
|
|
2194
|
-
debug: {
|
|
2195
|
-
type: 'boolean',
|
|
2196
|
-
shortFlag: 'd',
|
|
2197
|
-
default: false,
|
|
2198
|
-
description: 'Output debug information'
|
|
2199
|
-
},
|
|
2200
2246
|
dryRun: {
|
|
2201
2247
|
type: 'boolean',
|
|
2202
2248
|
default: false,
|
|
@@ -2223,9 +2269,8 @@ async function setupCommand$g(name, description, argv, importMeta) {
|
|
|
2223
2269
|
default ignores from the "ignore-by-default" module.
|
|
2224
2270
|
|
|
2225
2271
|
Options
|
|
2226
|
-
${
|
|
2272
|
+
${getFlagListOutput({
|
|
2227
2273
|
all: 'Include all issues',
|
|
2228
|
-
debug: 'Output debug information',
|
|
2229
2274
|
'dry-run': 'Only output what will be done without actually doing it',
|
|
2230
2275
|
json: 'Output result as json',
|
|
2231
2276
|
markdown: 'Output result as markdown',
|
|
@@ -2255,10 +2300,9 @@ async function setupCommand$g(name, description, argv, importMeta) {
|
|
|
2255
2300
|
const {
|
|
2256
2301
|
dryRun
|
|
2257
2302
|
} = cli.flags;
|
|
2258
|
-
const debugLog = sdk.createDebugLogger(!dryRun || cli.flags['debug']);
|
|
2259
2303
|
|
|
2260
2304
|
// TODO: Allow setting a custom cwd and/or configFile path?
|
|
2261
|
-
const cwd = process.cwd();
|
|
2305
|
+
const cwd = process$1.cwd();
|
|
2262
2306
|
const absoluteConfigPath = path.join(cwd, 'socket.yml');
|
|
2263
2307
|
const config$1 = await config.readSocketConfig(absoluteConfigPath).catch(cause => {
|
|
2264
2308
|
if (cause && typeof cause === 'object' && cause instanceof config.SocketValidationError) {
|
|
@@ -2270,14 +2314,14 @@ async function setupCommand$g(name, description, argv, importMeta) {
|
|
|
2270
2314
|
errors: cause.validationErrors,
|
|
2271
2315
|
schema: cause.schema
|
|
2272
2316
|
});
|
|
2273
|
-
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'));
|
|
2274
2318
|
} else {
|
|
2275
2319
|
throw new ponyCause.ErrorWithCause('Failed to read socket.yml config', {
|
|
2276
2320
|
cause
|
|
2277
2321
|
});
|
|
2278
2322
|
}
|
|
2279
2323
|
});
|
|
2280
|
-
const socketSdk = await
|
|
2324
|
+
const socketSdk = await socketUrl.setupSdk();
|
|
2281
2325
|
const supportedFiles = await socketSdk.getReportSupportedFiles().then(res => {
|
|
2282
2326
|
if (!res.success) handleUnsuccessfulApiResponse('getReportSupportedFiles', res, new spinner.Spinner());
|
|
2283
2327
|
return res.data;
|
|
@@ -2286,11 +2330,10 @@ async function setupCommand$g(name, description, argv, importMeta) {
|
|
|
2286
2330
|
cause
|
|
2287
2331
|
});
|
|
2288
2332
|
});
|
|
2289
|
-
const packagePaths = await pathResolve.getPackageFiles(cwd, cli.input, config$1, supportedFiles
|
|
2333
|
+
const packagePaths = await pathResolve.getPackageFiles(cwd, cli.input, config$1, supportedFiles);
|
|
2290
2334
|
return {
|
|
2291
2335
|
config: config$1,
|
|
2292
2336
|
cwd,
|
|
2293
|
-
debugLog,
|
|
2294
2337
|
dryRun,
|
|
2295
2338
|
includeAllIssues: cli.flags['all'],
|
|
2296
2339
|
outputJson: cli.flags['json'],
|
|
@@ -2303,14 +2346,13 @@ async function setupCommand$g(name, description, argv, importMeta) {
|
|
|
2303
2346
|
async function createReport(packagePaths, {
|
|
2304
2347
|
config,
|
|
2305
2348
|
cwd,
|
|
2306
|
-
debugLog,
|
|
2307
2349
|
dryRun
|
|
2308
2350
|
}) {
|
|
2309
|
-
debugLog('Uploading:', packagePaths.join(`\n${
|
|
2351
|
+
pathResolve.debugLog('Uploading:', packagePaths.join(`\n${pathResolve.logSymbols.info} Uploading: `));
|
|
2310
2352
|
if (dryRun) {
|
|
2311
2353
|
return;
|
|
2312
2354
|
}
|
|
2313
|
-
const socketSdk = await
|
|
2355
|
+
const socketSdk = await socketUrl.setupSdk();
|
|
2314
2356
|
const spinner$1 = new spinner.Spinner({
|
|
2315
2357
|
text: `Creating report with ${packagePaths.length} package files`
|
|
2316
2358
|
}).start();
|
|
@@ -2331,7 +2373,7 @@ function formatReportCreationOutput(data, {
|
|
|
2331
2373
|
console.log(JSON.stringify(data, undefined, 2));
|
|
2332
2374
|
return;
|
|
2333
2375
|
}
|
|
2334
|
-
const format = new
|
|
2376
|
+
const format = new socketUrl.ColorOrMarkdown(!!outputMarkdown);
|
|
2335
2377
|
console.log(`New report: ${format.hyperlink(data.id, data.url, {
|
|
2336
2378
|
fallbackToUrl: true
|
|
2337
2379
|
})}`);
|
|
@@ -2373,13 +2415,13 @@ async function meowWithSubcommands(subcommands, options) {
|
|
|
2373
2415
|
$ ${name} <command>
|
|
2374
2416
|
|
|
2375
2417
|
Commands
|
|
2376
|
-
${
|
|
2377
|
-
...objects.toSortedObject(subcommands),
|
|
2378
|
-
...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)))
|
|
2379
2421
|
}, 6)}
|
|
2380
2422
|
|
|
2381
2423
|
Options
|
|
2382
|
-
${
|
|
2424
|
+
${getFlagListOutput(flags, 6)}
|
|
2383
2425
|
|
|
2384
2426
|
Examples
|
|
2385
2427
|
$ ${name} --help
|
|
@@ -2410,8 +2452,9 @@ const report = {
|
|
|
2410
2452
|
}
|
|
2411
2453
|
};
|
|
2412
2454
|
|
|
2413
|
-
const
|
|
2414
|
-
const
|
|
2455
|
+
const HOME_DIR = os.homedir();
|
|
2456
|
+
const BASH_FILE = `${HOME_DIR}/.bashrc`;
|
|
2457
|
+
const ZSH_BASH_FILE = `${HOME_DIR}/.zshrc`;
|
|
2415
2458
|
const wrapper = {
|
|
2416
2459
|
description: 'Enable or disable the Socket npm/npx wrapper',
|
|
2417
2460
|
async run(argv, importMeta, {
|
|
@@ -2427,7 +2470,7 @@ function setupCommand$f(name, description, argv, importMeta) {
|
|
|
2427
2470
|
$ ${name} <flag>
|
|
2428
2471
|
|
|
2429
2472
|
Options
|
|
2430
|
-
${
|
|
2473
|
+
${getFlagListOutput(flags, 6)}
|
|
2431
2474
|
|
|
2432
2475
|
Examples
|
|
2433
2476
|
$ ${name} --enable
|
|
@@ -2482,21 +2525,18 @@ function setupCommand$f(name, description, argv, importMeta) {
|
|
|
2482
2525
|
console.error('There was an issue setting up the alias in your bash profile');
|
|
2483
2526
|
}
|
|
2484
2527
|
}
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
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\`
|
|
2492
2536
|
`);
|
|
2493
|
-
const rl = readline.createInterface({
|
|
2494
|
-
input: process.stdin,
|
|
2495
|
-
output: process.stdout
|
|
2496
2537
|
});
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
const askQuestion = (rl, query) => {
|
|
2538
|
+
}
|
|
2539
|
+
function askQuestion(rl, query) {
|
|
2500
2540
|
rl.question(query, ans => {
|
|
2501
2541
|
if (ans.toLowerCase() === 'y') {
|
|
2502
2542
|
try {
|
|
@@ -2516,19 +2556,31 @@ const askQuestion = (rl, query) => {
|
|
|
2516
2556
|
rl.close();
|
|
2517
2557
|
}
|
|
2518
2558
|
});
|
|
2519
|
-
}
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
}
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
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
|
+
|
|
2528
2576
|
`);
|
|
2577
|
+
const rl = readline.createInterface({
|
|
2578
|
+
input: process$1.stdin,
|
|
2579
|
+
output: process$1.stdout
|
|
2529
2580
|
});
|
|
2530
|
-
|
|
2531
|
-
|
|
2581
|
+
return askQuestion(rl, query);
|
|
2582
|
+
}
|
|
2583
|
+
function removeAlias(file) {
|
|
2532
2584
|
return fs.readFile(file, 'utf8', function (err, data) {
|
|
2533
2585
|
if (err) {
|
|
2534
2586
|
console.error(`There was an error removing the alias: ${err}`);
|
|
@@ -2545,16 +2597,7 @@ const removeAlias = file => {
|
|
|
2545
2597
|
}
|
|
2546
2598
|
});
|
|
2547
2599
|
});
|
|
2548
|
-
}
|
|
2549
|
-
const checkSocketWrapperAlreadySetup = file => {
|
|
2550
|
-
const fileContent = fs.readFileSync(file, 'utf8');
|
|
2551
|
-
const linesWithSocketAlias = fileContent.split('\n').filter(l => l === 'alias npm="socket npm"' || l === 'alias npx="socket npx"');
|
|
2552
|
-
if (linesWithSocketAlias.length) {
|
|
2553
|
-
console.log(`The Socket npm/npx wrapper is set up in your bash profile (${file}).`);
|
|
2554
|
-
return true;
|
|
2555
|
-
}
|
|
2556
|
-
return false;
|
|
2557
|
-
};
|
|
2600
|
+
}
|
|
2558
2601
|
|
|
2559
2602
|
const create$1 = {
|
|
2560
2603
|
description: 'Create a scan',
|
|
@@ -2564,9 +2607,9 @@ const create$1 = {
|
|
|
2564
2607
|
const name = `${parentName} create`;
|
|
2565
2608
|
const input = await setupCommand$e(name, create$1.description, argv, importMeta);
|
|
2566
2609
|
if (input) {
|
|
2567
|
-
const apiKey =
|
|
2610
|
+
const apiKey = socketUrl.getDefaultToken();
|
|
2568
2611
|
if (!apiKey) {
|
|
2569
|
-
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.');
|
|
2570
2613
|
}
|
|
2571
2614
|
const spinnerText = 'Creating a scan... \n';
|
|
2572
2615
|
const spinner$1 = new spinner.Spinner({
|
|
@@ -2643,7 +2686,7 @@ async function setupCommand$e(name, description, argv, importMeta) {
|
|
|
2643
2686
|
$ ${name} [...options]
|
|
2644
2687
|
|
|
2645
2688
|
Options
|
|
2646
|
-
${
|
|
2689
|
+
${getFlagListOutput(flags, 6)}
|
|
2647
2690
|
|
|
2648
2691
|
Examples
|
|
2649
2692
|
$ ${name} --org=FakeOrg --repo=test-repo --branch=main ./package.json
|
|
@@ -2664,8 +2707,8 @@ async function setupCommand$e(name, description, argv, importMeta) {
|
|
|
2664
2707
|
const {
|
|
2665
2708
|
0: orgSlug = ''
|
|
2666
2709
|
} = cli.input;
|
|
2667
|
-
const cwd = process.cwd();
|
|
2668
|
-
const socketSdk = await
|
|
2710
|
+
const cwd = process$1.cwd();
|
|
2711
|
+
const socketSdk = await socketUrl.setupSdk();
|
|
2669
2712
|
const supportedFiles = await socketSdk.getReportSupportedFiles().then(res => {
|
|
2670
2713
|
if (!res.success) handleUnsuccessfulApiResponse('getReportSupportedFiles', res, new spinner.Spinner());
|
|
2671
2714
|
return res.data;
|
|
@@ -2675,8 +2718,7 @@ async function setupCommand$e(name, description, argv, importMeta) {
|
|
|
2675
2718
|
cause
|
|
2676
2719
|
});
|
|
2677
2720
|
});
|
|
2678
|
-
const
|
|
2679
|
-
const packagePaths = await pathResolve.getPackageFilesFullScans(cwd, cli.input, supportedFiles, debugLog);
|
|
2721
|
+
const packagePaths = await pathResolve.getPackageFilesFullScans(cwd, cli.input, supportedFiles);
|
|
2680
2722
|
const {
|
|
2681
2723
|
branch: branchName,
|
|
2682
2724
|
repo: repoName
|
|
@@ -2707,7 +2749,7 @@ async function setupCommand$e(name, description, argv, importMeta) {
|
|
|
2707
2749
|
};
|
|
2708
2750
|
}
|
|
2709
2751
|
async function createFullScan(input, spinner, apiKey) {
|
|
2710
|
-
const socketSdk = await
|
|
2752
|
+
const socketSdk = await socketUrl.setupSdk(apiKey);
|
|
2711
2753
|
const {
|
|
2712
2754
|
branchName,
|
|
2713
2755
|
commitMessage,
|
|
@@ -2734,8 +2776,8 @@ async function createFullScan(input, spinner, apiKey) {
|
|
|
2734
2776
|
const link = colors.underline(colors.cyan(`${result.data.html_report_url}`));
|
|
2735
2777
|
console.log(`Available at: ${link}`);
|
|
2736
2778
|
const rl = readline$1.createInterface({
|
|
2737
|
-
input:
|
|
2738
|
-
output:
|
|
2779
|
+
input: process$1.stdin,
|
|
2780
|
+
output: process$1.stdout
|
|
2739
2781
|
});
|
|
2740
2782
|
const answer = await rl.question('Would you like to open it in your browser? (y/n)');
|
|
2741
2783
|
if (answer.toLowerCase() === 'y') {
|
|
@@ -2752,9 +2794,9 @@ const del$1 = {
|
|
|
2752
2794
|
const name = `${parentName} del`;
|
|
2753
2795
|
const input = setupCommand$d(name, del$1.description, argv, importMeta);
|
|
2754
2796
|
if (input) {
|
|
2755
|
-
const apiKey =
|
|
2797
|
+
const apiKey = socketUrl.getDefaultToken();
|
|
2756
2798
|
if (!apiKey) {
|
|
2757
|
-
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.');
|
|
2758
2800
|
}
|
|
2759
2801
|
const spinnerText = 'Deleting scan...';
|
|
2760
2802
|
const spinner$1 = new spinner.Spinner({
|
|
@@ -2777,7 +2819,7 @@ function setupCommand$d(name, description, argv, importMeta) {
|
|
|
2777
2819
|
$ ${name} <org slug> <scan ID>
|
|
2778
2820
|
|
|
2779
2821
|
Options
|
|
2780
|
-
${
|
|
2822
|
+
${getFlagListOutput(flags, 6)}
|
|
2781
2823
|
|
|
2782
2824
|
Examples
|
|
2783
2825
|
$ ${name} FakeOrg 000aaaa1-0000-0a0a-00a0-00a0000000a0
|
|
@@ -2808,7 +2850,7 @@ function setupCommand$d(name, description, argv, importMeta) {
|
|
|
2808
2850
|
};
|
|
2809
2851
|
}
|
|
2810
2852
|
async function deleteOrgFullScan(orgSlug, fullScanId, spinner, apiKey) {
|
|
2811
|
-
const socketSdk = await
|
|
2853
|
+
const socketSdk = await socketUrl.setupSdk(apiKey);
|
|
2812
2854
|
const result = await handleApiCall(socketSdk.deleteOrgFullScan(orgSlug, fullScanId), 'Deleting scan');
|
|
2813
2855
|
if (result.success) {
|
|
2814
2856
|
spinner.success('Scan deleted successfully');
|
|
@@ -2826,9 +2868,9 @@ const list$1 = {
|
|
|
2826
2868
|
const name = `${parentName} list`;
|
|
2827
2869
|
const input = setupCommand$c(name, list$1.description, argv, importMeta);
|
|
2828
2870
|
if (input) {
|
|
2829
|
-
const apiKey =
|
|
2871
|
+
const apiKey = socketUrl.getDefaultToken();
|
|
2830
2872
|
if (!apiKey) {
|
|
2831
|
-
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.');
|
|
2832
2874
|
}
|
|
2833
2875
|
const spinnerText = 'Listing scans... \n';
|
|
2834
2876
|
const spinner$1 = new spinner.Spinner({
|
|
@@ -2890,7 +2932,7 @@ function setupCommand$c(name, description, argv, importMeta) {
|
|
|
2890
2932
|
$ ${name} <org slug>
|
|
2891
2933
|
|
|
2892
2934
|
Options
|
|
2893
|
-
${
|
|
2935
|
+
${getFlagListOutput(flags, 6)}
|
|
2894
2936
|
|
|
2895
2937
|
Examples
|
|
2896
2938
|
$ ${name} FakeOrg
|
|
@@ -2925,7 +2967,7 @@ function setupCommand$c(name, description, argv, importMeta) {
|
|
|
2925
2967
|
};
|
|
2926
2968
|
}
|
|
2927
2969
|
async function listOrgFullScan(orgSlug, input, spinner, apiKey) {
|
|
2928
|
-
const socketSdk = await
|
|
2970
|
+
const socketSdk = await socketUrl.setupSdk(apiKey);
|
|
2929
2971
|
const result = await handleApiCall(socketSdk.getOrgFullScanList(orgSlug, input), 'Listing scans');
|
|
2930
2972
|
if (!result.success) {
|
|
2931
2973
|
handleUnsuccessfulApiResponse('getOrgFullScanList', result, spinner);
|
|
@@ -2970,9 +3012,9 @@ const metadata = {
|
|
|
2970
3012
|
const name = `${parentName} metadata`;
|
|
2971
3013
|
const input = setupCommand$b(name, metadata.description, argv, importMeta);
|
|
2972
3014
|
if (input) {
|
|
2973
|
-
const apiKey =
|
|
3015
|
+
const apiKey = socketUrl.getDefaultToken();
|
|
2974
3016
|
if (!apiKey) {
|
|
2975
|
-
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.');
|
|
2976
3018
|
}
|
|
2977
3019
|
const spinnerText = "Getting scan's metadata... \n";
|
|
2978
3020
|
const spinner$1 = new spinner.Spinner({
|
|
@@ -2995,7 +3037,7 @@ function setupCommand$b(name, description, argv, importMeta) {
|
|
|
2995
3037
|
$ ${name} <org slug> <scan id>
|
|
2996
3038
|
|
|
2997
3039
|
Options
|
|
2998
|
-
${
|
|
3040
|
+
${getFlagListOutput(flags, 6)}
|
|
2999
3041
|
|
|
3000
3042
|
Examples
|
|
3001
3043
|
$ ${name} FakeOrg 000aaaa1-0000-0a0a-00a0-00a0000000a0
|
|
@@ -3026,7 +3068,7 @@ function setupCommand$b(name, description, argv, importMeta) {
|
|
|
3026
3068
|
};
|
|
3027
3069
|
}
|
|
3028
3070
|
async function getOrgScanMetadata(orgSlug, scanId, spinner, apiKey) {
|
|
3029
|
-
const socketSdk = await
|
|
3071
|
+
const socketSdk = await socketUrl.setupSdk(apiKey);
|
|
3030
3072
|
const result = await handleApiCall(socketSdk.getOrgFullScanMetadata(orgSlug, scanId), 'Listing scans');
|
|
3031
3073
|
if (!result.success) {
|
|
3032
3074
|
handleUnsuccessfulApiResponse('getOrgFullScanMetadata', result, spinner);
|
|
@@ -3044,9 +3086,9 @@ const stream = {
|
|
|
3044
3086
|
const name = `${parentName} stream`;
|
|
3045
3087
|
const input = setupCommand$a(name, stream.description, argv, importMeta);
|
|
3046
3088
|
if (input) {
|
|
3047
|
-
const apiKey =
|
|
3089
|
+
const apiKey = socketUrl.getDefaultToken();
|
|
3048
3090
|
if (!apiKey) {
|
|
3049
|
-
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.');
|
|
3050
3092
|
}
|
|
3051
3093
|
const spinner$1 = new spinner.Spinner({
|
|
3052
3094
|
text: 'Streaming scan...'
|
|
@@ -3073,7 +3115,7 @@ function setupCommand$a(name, description, argv, importMeta) {
|
|
|
3073
3115
|
$ ${name} <org slug> <scan ID> <path to output file>
|
|
3074
3116
|
|
|
3075
3117
|
Options
|
|
3076
|
-
${
|
|
3118
|
+
${getFlagListOutput(flags, 6)}
|
|
3077
3119
|
|
|
3078
3120
|
Examples
|
|
3079
3121
|
$ ${name} FakeOrg 000aaaa1-0000-0a0a-00a0-00a0000000a0 ./stream.txt
|
|
@@ -3106,7 +3148,7 @@ function setupCommand$a(name, description, argv, importMeta) {
|
|
|
3106
3148
|
};
|
|
3107
3149
|
}
|
|
3108
3150
|
async function getOrgFullScan(orgSlug, fullScanId, file, apiKey) {
|
|
3109
|
-
const socketSdk = await
|
|
3151
|
+
const socketSdk = await socketUrl.setupSdk(apiKey);
|
|
3110
3152
|
return await handleApiCall(socketSdk.getOrgFullScan(orgSlug, fullScanId, file), 'Streaming a scan');
|
|
3111
3153
|
}
|
|
3112
3154
|
|
|
@@ -3139,9 +3181,9 @@ const auditLog = {
|
|
|
3139
3181
|
const name = parentName + ' audit-log';
|
|
3140
3182
|
const input = setupCommand$9(name, auditLog.description, argv, importMeta);
|
|
3141
3183
|
if (input) {
|
|
3142
|
-
const apiKey =
|
|
3184
|
+
const apiKey = socketUrl.getDefaultToken();
|
|
3143
3185
|
if (!apiKey) {
|
|
3144
|
-
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.');
|
|
3145
3187
|
}
|
|
3146
3188
|
const spinner$1 = new spinner.Spinner({
|
|
3147
3189
|
text: `Looking up audit log for ${input.orgSlug}\n`
|
|
@@ -3184,7 +3226,7 @@ function setupCommand$9(name, description, argv, importMeta) {
|
|
|
3184
3226
|
$ ${name} <org slug>
|
|
3185
3227
|
|
|
3186
3228
|
Options
|
|
3187
|
-
${
|
|
3229
|
+
${getFlagListOutput(flags, 6)}
|
|
3188
3230
|
|
|
3189
3231
|
Examples
|
|
3190
3232
|
$ ${name} FakeOrg
|
|
@@ -3223,7 +3265,7 @@ function setupCommand$9(name, description, argv, importMeta) {
|
|
|
3223
3265
|
};
|
|
3224
3266
|
}
|
|
3225
3267
|
async function fetchOrgAuditLog(orgSlug, input, spinner, apiKey) {
|
|
3226
|
-
const socketSdk = await
|
|
3268
|
+
const socketSdk = await socketUrl.setupSdk(apiKey);
|
|
3227
3269
|
const result = await handleApiCall(socketSdk.getAuditLogEvents(orgSlug, input), `Looking up audit log for ${orgSlug}\n`);
|
|
3228
3270
|
if (!result.success) {
|
|
3229
3271
|
handleUnsuccessfulApiResponse('getAuditLogEvents', result, spinner);
|
|
@@ -3263,9 +3305,9 @@ const create = {
|
|
|
3263
3305
|
const name = `${parentName} create`;
|
|
3264
3306
|
const input = setupCommand$8(name, create.description, argv, importMeta);
|
|
3265
3307
|
if (input) {
|
|
3266
|
-
const apiKey =
|
|
3308
|
+
const apiKey = socketUrl.getDefaultToken();
|
|
3267
3309
|
if (!apiKey) {
|
|
3268
|
-
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.');
|
|
3269
3311
|
}
|
|
3270
3312
|
const spinnerText = 'Creating repository... \n';
|
|
3271
3313
|
const spinner$1 = new spinner.Spinner({
|
|
@@ -3321,7 +3363,7 @@ function setupCommand$8(name, description, argv, importMeta) {
|
|
|
3321
3363
|
$ ${name} <org slug>
|
|
3322
3364
|
|
|
3323
3365
|
Options
|
|
3324
|
-
${
|
|
3366
|
+
${getFlagListOutput(flags, 6)}
|
|
3325
3367
|
|
|
3326
3368
|
Examples
|
|
3327
3369
|
$ ${name} FakeOrg --repoName=test-repo
|
|
@@ -3359,7 +3401,7 @@ function setupCommand$8(name, description, argv, importMeta) {
|
|
|
3359
3401
|
};
|
|
3360
3402
|
}
|
|
3361
3403
|
async function createRepo(orgSlug, input, spinner, apiKey) {
|
|
3362
|
-
const socketSdk = await
|
|
3404
|
+
const socketSdk = await socketUrl.setupSdk(apiKey);
|
|
3363
3405
|
const result = await handleApiCall(socketSdk.createOrgRepo(orgSlug, input), 'creating repository');
|
|
3364
3406
|
if (result.success) {
|
|
3365
3407
|
spinner.success('Repository created successfully');
|
|
@@ -3376,9 +3418,9 @@ const del = {
|
|
|
3376
3418
|
const name = `${parentName} del`;
|
|
3377
3419
|
const input = setupCommand$7(name, del.description, argv, importMeta);
|
|
3378
3420
|
if (input) {
|
|
3379
|
-
const apiKey =
|
|
3421
|
+
const apiKey = socketUrl.getDefaultToken();
|
|
3380
3422
|
if (!apiKey) {
|
|
3381
|
-
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.');
|
|
3382
3424
|
}
|
|
3383
3425
|
const spinnerText = 'Deleting repository... \n';
|
|
3384
3426
|
const spinner$1 = new spinner.Spinner({
|
|
@@ -3422,7 +3464,7 @@ function setupCommand$7(name, description, argv, importMeta) {
|
|
|
3422
3464
|
};
|
|
3423
3465
|
}
|
|
3424
3466
|
async function deleteRepository(orgSlug, repoName, spinner, apiKey) {
|
|
3425
|
-
const socketSdk = await
|
|
3467
|
+
const socketSdk = await socketUrl.setupSdk(apiKey);
|
|
3426
3468
|
const result = await handleApiCall(socketSdk.deleteOrgRepo(orgSlug, repoName), 'deleting repository');
|
|
3427
3469
|
if (result.success) {
|
|
3428
3470
|
spinner.success('Repository deleted successfully');
|
|
@@ -3440,9 +3482,9 @@ const list = {
|
|
|
3440
3482
|
const name = `${parentName} list`;
|
|
3441
3483
|
const input = setupCommand$6(name, list.description, argv, importMeta);
|
|
3442
3484
|
if (input) {
|
|
3443
|
-
const apiKey =
|
|
3485
|
+
const apiKey = socketUrl.getDefaultToken();
|
|
3444
3486
|
if (!apiKey) {
|
|
3445
|
-
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.');
|
|
3446
3488
|
}
|
|
3447
3489
|
const spinnerText = 'Listing repositories... \n';
|
|
3448
3490
|
const spinner$1 = new spinner.Spinner({
|
|
@@ -3491,7 +3533,7 @@ function setupCommand$6(name, description, argv, importMeta) {
|
|
|
3491
3533
|
$ ${name} <org slug>
|
|
3492
3534
|
|
|
3493
3535
|
Options
|
|
3494
|
-
${
|
|
3536
|
+
${getFlagListOutput(flags, 6)}
|
|
3495
3537
|
|
|
3496
3538
|
Examples
|
|
3497
3539
|
$ ${name} FakeOrg
|
|
@@ -3524,7 +3566,7 @@ function setupCommand$6(name, description, argv, importMeta) {
|
|
|
3524
3566
|
};
|
|
3525
3567
|
}
|
|
3526
3568
|
async function listOrgRepos(orgSlug, input, spinner, apiKey) {
|
|
3527
|
-
const socketSdk = await
|
|
3569
|
+
const socketSdk = await socketUrl.setupSdk(apiKey);
|
|
3528
3570
|
const result = await handleApiCall(socketSdk.getOrgRepoList(orgSlug, input), 'listing repositories');
|
|
3529
3571
|
if (!result.success) {
|
|
3530
3572
|
handleUnsuccessfulApiResponse('getOrgRepoList', result, spinner);
|
|
@@ -3559,9 +3601,9 @@ const update = {
|
|
|
3559
3601
|
const name = `${parentName} update`;
|
|
3560
3602
|
const input = setupCommand$5(name, update.description, argv, importMeta);
|
|
3561
3603
|
if (input) {
|
|
3562
|
-
const apiKey =
|
|
3604
|
+
const apiKey = socketUrl.getDefaultToken();
|
|
3563
3605
|
if (!apiKey) {
|
|
3564
|
-
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.');
|
|
3565
3607
|
}
|
|
3566
3608
|
const spinnerText = 'Updating repository... \n';
|
|
3567
3609
|
const spinner$1 = new spinner.Spinner({
|
|
@@ -3617,7 +3659,7 @@ function setupCommand$5(name, description, argv, importMeta) {
|
|
|
3617
3659
|
$ ${name} <org slug>
|
|
3618
3660
|
|
|
3619
3661
|
Options
|
|
3620
|
-
${
|
|
3662
|
+
${getFlagListOutput(flags, 6)}
|
|
3621
3663
|
|
|
3622
3664
|
Examples
|
|
3623
3665
|
$ ${name} FakeOrg
|
|
@@ -3655,7 +3697,7 @@ function setupCommand$5(name, description, argv, importMeta) {
|
|
|
3655
3697
|
};
|
|
3656
3698
|
}
|
|
3657
3699
|
async function updateRepository(orgSlug, input, spinner, apiKey) {
|
|
3658
|
-
const socketSdk = await
|
|
3700
|
+
const socketSdk = await socketUrl.setupSdk(apiKey);
|
|
3659
3701
|
const result = await handleApiCall(socketSdk.updateOrgRepo(orgSlug, input.name, input), 'updating repository');
|
|
3660
3702
|
if (result.success) {
|
|
3661
3703
|
spinner.success('Repository updated successfully');
|
|
@@ -3673,9 +3715,9 @@ const view = {
|
|
|
3673
3715
|
const name = `${parentName} view`;
|
|
3674
3716
|
const input = setupCommand$4(name, view.description, argv, importMeta);
|
|
3675
3717
|
if (input) {
|
|
3676
|
-
const apiKey =
|
|
3718
|
+
const apiKey = socketUrl.getDefaultToken();
|
|
3677
3719
|
if (!apiKey) {
|
|
3678
|
-
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.');
|
|
3679
3721
|
}
|
|
3680
3722
|
const spinnerText = 'Fetching repository... \n';
|
|
3681
3723
|
const spinner$1 = new spinner.Spinner({
|
|
@@ -3698,7 +3740,7 @@ function setupCommand$4(name, description, argv, importMeta) {
|
|
|
3698
3740
|
$ ${name} <org slug>
|
|
3699
3741
|
|
|
3700
3742
|
Options
|
|
3701
|
-
${
|
|
3743
|
+
${getFlagListOutput(flags, 6)}
|
|
3702
3744
|
|
|
3703
3745
|
Examples
|
|
3704
3746
|
$ ${name} FakeOrg
|
|
@@ -3729,7 +3771,7 @@ function setupCommand$4(name, description, argv, importMeta) {
|
|
|
3729
3771
|
};
|
|
3730
3772
|
}
|
|
3731
3773
|
async function viewRepository(orgSlug, repoName, spinner, apiKey) {
|
|
3732
|
-
const socketSdk = await
|
|
3774
|
+
const socketSdk = await socketUrl.setupSdk(apiKey);
|
|
3733
3775
|
const result = await handleApiCall(socketSdk.getOrgRepo(orgSlug, repoName), 'fetching repository');
|
|
3734
3776
|
if (!result.success) {
|
|
3735
3777
|
handleUnsuccessfulApiResponse('getOrgRepo', result, spinner);
|
|
@@ -3824,7 +3866,7 @@ function setupCommand$3(name, description, argv, importMeta) {
|
|
|
3824
3866
|
$ ${name}
|
|
3825
3867
|
|
|
3826
3868
|
Options
|
|
3827
|
-
${
|
|
3869
|
+
${getFlagListOutput(flags, 6)}
|
|
3828
3870
|
|
|
3829
3871
|
Examples
|
|
3830
3872
|
$ ${name}
|
|
@@ -3852,14 +3894,14 @@ async function searchDeps({
|
|
|
3852
3894
|
offset,
|
|
3853
3895
|
outputJson
|
|
3854
3896
|
}) {
|
|
3855
|
-
const apiKey =
|
|
3897
|
+
const apiKey = socketUrl.getDefaultToken();
|
|
3856
3898
|
if (!apiKey) {
|
|
3857
|
-
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.');
|
|
3858
3900
|
}
|
|
3859
3901
|
const spinner$1 = new spinner.Spinner({
|
|
3860
3902
|
text: 'Searching dependencies...'
|
|
3861
3903
|
}).start();
|
|
3862
|
-
const socketSdk = await
|
|
3904
|
+
const socketSdk = await socketUrl.setupSdk(apiKey);
|
|
3863
3905
|
const result = await handleApiCall(socketSdk.searchDependencies({
|
|
3864
3906
|
limit,
|
|
3865
3907
|
offset
|
|
@@ -3909,9 +3951,9 @@ const analytics = {
|
|
|
3909
3951
|
const name = parentName + ' analytics';
|
|
3910
3952
|
const input = setupCommand$2(name, analytics.description, argv, importMeta);
|
|
3911
3953
|
if (input) {
|
|
3912
|
-
const apiKey =
|
|
3954
|
+
const apiKey = socketUrl.getDefaultToken();
|
|
3913
3955
|
if (!apiKey) {
|
|
3914
|
-
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.');
|
|
3915
3957
|
}
|
|
3916
3958
|
const spinner$1 = new spinner.Spinner({
|
|
3917
3959
|
text: 'Fetching analytics data'
|
|
@@ -3966,7 +4008,7 @@ function setupCommand$2(name, description, argv, importMeta) {
|
|
|
3966
4008
|
$ ${name} --scope=<scope> --time=<time filter>
|
|
3967
4009
|
|
|
3968
4010
|
Options
|
|
3969
|
-
${
|
|
4011
|
+
${getFlagListOutput(flags, 6)}
|
|
3970
4012
|
|
|
3971
4013
|
Examples
|
|
3972
4014
|
$ ${name} --scope=org --time=7
|
|
@@ -3984,10 +4026,10 @@ function setupCommand$2(name, description, argv, importMeta) {
|
|
|
3984
4026
|
time
|
|
3985
4027
|
} = cli.flags;
|
|
3986
4028
|
if (scope !== 'org' && scope !== 'repo') {
|
|
3987
|
-
throw new
|
|
4029
|
+
throw new socketUrl.InputError("The scope must either be 'org' or 'repo'");
|
|
3988
4030
|
}
|
|
3989
4031
|
if (time !== 7 && time !== 30 && time !== 90) {
|
|
3990
|
-
throw new
|
|
4032
|
+
throw new socketUrl.InputError('The time filter must either be 7, 30 or 90');
|
|
3991
4033
|
}
|
|
3992
4034
|
let showHelp = cli.flags['help'];
|
|
3993
4035
|
if (scope === 'repo' && !repo) {
|
|
@@ -4008,7 +4050,7 @@ function setupCommand$2(name, description, argv, importMeta) {
|
|
|
4008
4050
|
}
|
|
4009
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'];
|
|
4010
4052
|
async function fetchOrgAnalyticsData(time, spinner, apiKey, outputJson, filePath) {
|
|
4011
|
-
const socketSdk = await
|
|
4053
|
+
const socketSdk = await socketUrl.setupSdk(apiKey);
|
|
4012
4054
|
const result = await handleApiCall(socketSdk.getOrgAnalytics(time.toString()), 'fetching analytics data');
|
|
4013
4055
|
if (result.success === false) {
|
|
4014
4056
|
return handleUnsuccessfulApiResponse('getOrgAnalytics', result, spinner);
|
|
@@ -4121,7 +4163,7 @@ const formatData = (data, scope) => {
|
|
|
4121
4163
|
};
|
|
4122
4164
|
};
|
|
4123
4165
|
async function fetchRepoAnalyticsData(repo, time, spinner, apiKey, outputJson, filePath) {
|
|
4124
|
-
const socketSdk = await
|
|
4166
|
+
const socketSdk = await socketUrl.setupSdk(apiKey);
|
|
4125
4167
|
const result = await handleApiCall(socketSdk.getRepoAnalytics(repo, time.toString()), 'fetching analytics data');
|
|
4126
4168
|
if (result.success === false) {
|
|
4127
4169
|
return handleUnsuccessfulApiResponse('getRepoAnalytics', result, spinner);
|
|
@@ -4209,9 +4251,9 @@ const get = {
|
|
|
4209
4251
|
const name = `${parentName} get`;
|
|
4210
4252
|
const input = setupCommand$1(name, get.description, argv, importMeta);
|
|
4211
4253
|
if (input) {
|
|
4212
|
-
const apiKey =
|
|
4254
|
+
const apiKey = socketUrl.getDefaultToken();
|
|
4213
4255
|
if (!apiKey) {
|
|
4214
|
-
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.');
|
|
4215
4257
|
}
|
|
4216
4258
|
const spinnerText = 'Getting diff scan... \n';
|
|
4217
4259
|
const spinner$1 = new spinner.Spinner({
|
|
@@ -4261,7 +4303,7 @@ function setupCommand$1(name, description, argv, importMeta) {
|
|
|
4261
4303
|
$ ${name} <org slug> --before=<before> --after=<after>
|
|
4262
4304
|
|
|
4263
4305
|
Options
|
|
4264
|
-
${
|
|
4306
|
+
${getFlagListOutput(flags, 6)}
|
|
4265
4307
|
|
|
4266
4308
|
Examples
|
|
4267
4309
|
$ ${name} FakeCorp --before=aaa0aa0a-aaaa-0000-0a0a-0000000a00a0 --after=aaa1aa1a-aaaa-1111-1a1a-1111111a11a1
|
|
@@ -4352,7 +4394,6 @@ const diffScan = {
|
|
|
4352
4394
|
}
|
|
4353
4395
|
};
|
|
4354
4396
|
|
|
4355
|
-
// @ts-ignore
|
|
4356
4397
|
const threatFeed = {
|
|
4357
4398
|
description: 'Look up the threat feed',
|
|
4358
4399
|
async run(argv, importMeta, {
|
|
@@ -4361,9 +4402,9 @@ const threatFeed = {
|
|
|
4361
4402
|
const name = `${parentName} threat-feed`;
|
|
4362
4403
|
const input = setupCommand(name, threatFeed.description, argv, importMeta);
|
|
4363
4404
|
{
|
|
4364
|
-
const apiKey =
|
|
4405
|
+
const apiKey = socketUrl.getDefaultToken();
|
|
4365
4406
|
if (!apiKey) {
|
|
4366
|
-
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.');
|
|
4367
4408
|
}
|
|
4368
4409
|
const spinner$1 = new spinner.Spinner({
|
|
4369
4410
|
text: 'Looking up the threat feed'
|
|
@@ -4412,7 +4453,7 @@ function setupCommand(name, description, argv, importMeta) {
|
|
|
4412
4453
|
$ ${name}
|
|
4413
4454
|
|
|
4414
4455
|
Options
|
|
4415
|
-
${
|
|
4456
|
+
${getFlagListOutput(flags, 6)}
|
|
4416
4457
|
|
|
4417
4458
|
Examples
|
|
4418
4459
|
$ ${name}
|
|
@@ -4488,7 +4529,7 @@ async function fetchThreatFeed({
|
|
|
4488
4529
|
data: formattedOutput
|
|
4489
4530
|
});
|
|
4490
4531
|
screen.render();
|
|
4491
|
-
screen.key(['escape', 'q', 'C-c'], () => process.exit(0));
|
|
4532
|
+
screen.key(['escape', 'q', 'C-c'], () => process$1.exit(0));
|
|
4492
4533
|
}
|
|
4493
4534
|
const formatResults = data => {
|
|
4494
4535
|
return data.map(d => {
|
|
@@ -4557,7 +4598,7 @@ void (async () => {
|
|
|
4557
4598
|
argv: ['report', 'create', '--view', '--strict']
|
|
4558
4599
|
}
|
|
4559
4600
|
},
|
|
4560
|
-
argv: process.argv.slice(2),
|
|
4601
|
+
argv: process$1.argv.slice(2),
|
|
4561
4602
|
name: 'socket',
|
|
4562
4603
|
importMeta: {
|
|
4563
4604
|
url: `${node_url.pathToFileURL(__filename)}`
|
|
@@ -4567,10 +4608,10 @@ void (async () => {
|
|
|
4567
4608
|
let errorBody;
|
|
4568
4609
|
let errorTitle;
|
|
4569
4610
|
let errorMessage = '';
|
|
4570
|
-
if (err instanceof
|
|
4611
|
+
if (err instanceof socketUrl.AuthError) {
|
|
4571
4612
|
errorTitle = 'Authentication error';
|
|
4572
4613
|
errorMessage = err.message;
|
|
4573
|
-
} else if (err instanceof
|
|
4614
|
+
} else if (err instanceof socketUrl.InputError) {
|
|
4574
4615
|
errorTitle = 'Invalid input';
|
|
4575
4616
|
errorMessage = err.message;
|
|
4576
4617
|
errorBody = err.body;
|
|
@@ -4581,10 +4622,10 @@ void (async () => {
|
|
|
4581
4622
|
} else {
|
|
4582
4623
|
errorTitle = 'Unexpected error with no details';
|
|
4583
4624
|
}
|
|
4584
|
-
console.error(`${
|
|
4625
|
+
console.error(`${pathResolve.logSymbols.error} ${colors.bgRed(colors.white(errorTitle + ':'))} ${errorMessage}`);
|
|
4585
4626
|
if (errorBody) {
|
|
4586
4627
|
console.error(`\n${errorBody}`);
|
|
4587
4628
|
}
|
|
4588
|
-
process.exit(1);
|
|
4629
|
+
process$1.exit(1);
|
|
4589
4630
|
}
|
|
4590
4631
|
})();
|