@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/require/cli.js
CHANGED
|
@@ -10,6 +10,7 @@ function _socketInterop(e) {
|
|
|
10
10
|
return c ? e.default : e
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
var process$1 = require('node:process');
|
|
13
14
|
var require$$0 = require('node:url');
|
|
14
15
|
var ponyCause = _socketInterop(require('pony-cause'));
|
|
15
16
|
var vendor = require('./vendor.js');
|
|
@@ -20,41 +21,43 @@ var yargsParse = _socketInterop(require('yargs-parser'));
|
|
|
20
21
|
var npm$1 = require('@socketsecurity/registry/lib/npm');
|
|
21
22
|
var words = require('@socketsecurity/registry/lib/words');
|
|
22
23
|
var constants = require('./constants.js');
|
|
23
|
-
var
|
|
24
|
-
var
|
|
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');
|
|
28
|
+
var registryConstants = require('@socketsecurity/registry/lib/constants');
|
|
29
|
+
var socketUrl = require('./socket-url.js');
|
|
30
|
+
var terminalLink = _socketInterop(require('terminal-link'));
|
|
31
|
+
var isInteractive = require('@socketregistry/is-interactive/index.cjs');
|
|
25
32
|
var prompts = require('@socketsecurity/registry/lib/prompts');
|
|
26
33
|
var fs$1 = require('node:fs/promises');
|
|
27
|
-
var spawn = _socketInterop(require('@npmcli/promise-spawn'));
|
|
28
34
|
var npa = _socketInterop(require('npm-package-arg'));
|
|
29
35
|
var semver = _socketInterop(require('semver'));
|
|
30
36
|
var tinyglobby = _socketInterop(require('tinyglobby'));
|
|
31
37
|
var yaml = _socketInterop(require('yaml'));
|
|
32
38
|
var registry = require('@socketsecurity/registry');
|
|
33
|
-
var objects = require('@socketsecurity/registry/lib/objects');
|
|
34
39
|
var packages = require('@socketsecurity/registry/lib/packages');
|
|
35
40
|
var promises = require('@socketsecurity/registry/lib/promises');
|
|
36
41
|
var regexps = require('@socketsecurity/registry/lib/regexps');
|
|
37
42
|
var strings = require('@socketsecurity/registry/lib/strings');
|
|
38
43
|
var browserslist = _socketInterop(require('browserslist'));
|
|
39
44
|
var which = _socketInterop(require('which'));
|
|
40
|
-
var
|
|
41
|
-
var pathResolve = require('./path-resolve.js');
|
|
45
|
+
var index_cjs = require('@socketregistry/hyrious__bun.lockb/index.cjs');
|
|
42
46
|
var betterAjvErrors = _socketInterop(require('@apideck/better-ajv-errors'));
|
|
43
47
|
var config = require('@socketsecurity/config');
|
|
44
48
|
var os = require('node:os');
|
|
45
49
|
var readline = require('node:readline');
|
|
46
|
-
var process$1 = require('node:process');
|
|
47
50
|
var readline$1 = require('node:readline/promises');
|
|
48
51
|
var chalkTable = _socketInterop(require('chalk-table'));
|
|
49
52
|
var ScreenWidget = _socketInterop(require('blessed/lib/widgets/screen'));
|
|
50
|
-
var BarChart = _socketInterop(require('blessed-contrib/lib/widget/charts/bar'));
|
|
51
53
|
var GridLayout = _socketInterop(require('blessed-contrib/lib/layout/grid'));
|
|
54
|
+
var BarChart = _socketInterop(require('blessed-contrib/lib/widget/charts/bar'));
|
|
52
55
|
var LineChart = _socketInterop(require('blessed-contrib/lib/widget/charts/line'));
|
|
53
56
|
var require$$0$1 = require('node:util');
|
|
54
57
|
var TableWidget = _socketInterop(require('blessed-contrib/lib/widget/table'));
|
|
55
58
|
|
|
56
59
|
const {
|
|
57
|
-
NPM: NPM$
|
|
60
|
+
NPM: NPM$5,
|
|
58
61
|
PNPM: PNPM$2,
|
|
59
62
|
cdxgenBinPath,
|
|
60
63
|
synpBinPath
|
|
@@ -65,10 +68,10 @@ const {
|
|
|
65
68
|
SBOM_SIGN_PRIVATE_KEY,
|
|
66
69
|
// Location to the RSA private key
|
|
67
70
|
SBOM_SIGN_PUBLIC_KEY // Optional. Location to the RSA public key
|
|
68
|
-
} = process.env;
|
|
71
|
+
} = process$1.env;
|
|
69
72
|
const toLower = arg => arg.toLowerCase();
|
|
70
73
|
const arrayToLower = arg => arg.map(toLower);
|
|
71
|
-
const nodejsPlatformTypes = new Set(['javascript', 'js', 'nodejs', NPM$
|
|
74
|
+
const nodejsPlatformTypes = new Set(['javascript', 'js', 'nodejs', NPM$5, PNPM$2, 'ts', 'tsx', 'typescript']);
|
|
72
75
|
const yargsConfig = {
|
|
73
76
|
configuration: {
|
|
74
77
|
'camel-case-expansion': false,
|
|
@@ -172,20 +175,20 @@ const cdxgen = {
|
|
|
172
175
|
length: unknownLength
|
|
173
176
|
} = unknown;
|
|
174
177
|
if (unknownLength) {
|
|
178
|
+
process$1.exitCode = 1;
|
|
175
179
|
console.error(`Unknown ${words.pluralize('argument', unknownLength)}: ${yargv._.join(', ')}`);
|
|
176
|
-
process.exitCode = 1;
|
|
177
180
|
return;
|
|
178
181
|
}
|
|
179
182
|
let cleanupPackageLock = false;
|
|
180
183
|
if (yargv.type !== 'yarn' && nodejsPlatformTypes.has(yargv.type) && fs.existsSync('./yarn.lock')) {
|
|
181
184
|
if (fs.existsSync('./package-lock.json')) {
|
|
182
|
-
yargv.type = NPM$
|
|
185
|
+
yargv.type = NPM$5;
|
|
183
186
|
} else {
|
|
184
187
|
// Use synp to create a package-lock.json from the yarn.lock,
|
|
185
188
|
// based on the node_modules folder, for a more accurate SBOM.
|
|
186
189
|
try {
|
|
187
190
|
await npm$1.runBin(await fs.promises.realpath(synpBinPath), ['--source-file', './yarn.lock']);
|
|
188
|
-
yargv.type = NPM$
|
|
191
|
+
yargv.type = NPM$5;
|
|
189
192
|
cleanupPackageLock = true;
|
|
190
193
|
} catch {}
|
|
191
194
|
}
|
|
@@ -207,13 +210,82 @@ const cdxgen = {
|
|
|
207
210
|
await fs.promises.rm('./package-lock.json');
|
|
208
211
|
} catch {}
|
|
209
212
|
}
|
|
210
|
-
const fullOutputPath = path.join(process.cwd(), yargv.output);
|
|
213
|
+
const fullOutputPath = path.join(process$1.cwd(), yargv.output);
|
|
211
214
|
if (fs.existsSync(fullOutputPath)) {
|
|
212
215
|
console.log(colors.cyanBright(`${yargv.output} created!`));
|
|
213
216
|
}
|
|
214
217
|
}
|
|
215
218
|
};
|
|
216
219
|
|
|
220
|
+
const {
|
|
221
|
+
abortSignal: abortSignal$3
|
|
222
|
+
} = constants;
|
|
223
|
+
function shadowNpmInstall(opts) {
|
|
224
|
+
const {
|
|
225
|
+
flags = [],
|
|
226
|
+
ipc,
|
|
227
|
+
...spawnOptions
|
|
228
|
+
} = {
|
|
229
|
+
__proto__: null,
|
|
230
|
+
...opts
|
|
231
|
+
};
|
|
232
|
+
const useIpc = objects.isObject(ipc);
|
|
233
|
+
const useDebug = pathResolve.isDebug();
|
|
234
|
+
const promise = spawn(
|
|
235
|
+
// Lazily access constants.execPath.
|
|
236
|
+
constants.execPath, [
|
|
237
|
+
// Lazily access constants.rootBinPath.
|
|
238
|
+
path.join(constants.rootBinPath, 'npm-cli.js'), 'install',
|
|
239
|
+
// Even though the 'silent' flag is passed npm will still run through code
|
|
240
|
+
// paths for 'audit' and 'fund' unless '--no-audit' and '--no-fund' flags
|
|
241
|
+
// are passed.
|
|
242
|
+
...(useDebug ? ['--no-audit', '--no-fund'] : ['silent', '--no-audit', '--no-fund']), ...flags], {
|
|
243
|
+
signal: abortSignal$3,
|
|
244
|
+
// Set stdio to include 'ipc'.
|
|
245
|
+
// See https://github.com/nodejs/node/blob/v23.6.0/lib/child_process.js#L161-L166
|
|
246
|
+
// and https://github.com/nodejs/node/blob/v23.6.0/lib/internal/child_process.js#L238.
|
|
247
|
+
stdio: useDebug ?
|
|
248
|
+
// 'inherit'
|
|
249
|
+
useIpc ? [0, 1, 2, 'ipc'] : 'inherit' :
|
|
250
|
+
// 'ignore'
|
|
251
|
+
useIpc ? ['ignore', 'ignore', 'ignore', 'ipc'] : 'ignore',
|
|
252
|
+
...spawnOptions,
|
|
253
|
+
env: {
|
|
254
|
+
...process$1.env,
|
|
255
|
+
...spawnOptions.env
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
if (useIpc) {
|
|
259
|
+
promise.process.send(ipc);
|
|
260
|
+
}
|
|
261
|
+
return promise;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const {
|
|
265
|
+
SOCKET_CLI_FIX_PACKAGE_LOCK_FILE,
|
|
266
|
+
SOCKET_IPC_HANDSHAKE: SOCKET_IPC_HANDSHAKE$1
|
|
267
|
+
} = constants;
|
|
268
|
+
const fix = {
|
|
269
|
+
description: 'Fix "fixable" Socket alerts',
|
|
270
|
+
hidden: true,
|
|
271
|
+
async run() {
|
|
272
|
+
const spinner$1 = new spinner.Spinner().start();
|
|
273
|
+
try {
|
|
274
|
+
await shadowNpmInstall({
|
|
275
|
+
ipc: {
|
|
276
|
+
[SOCKET_IPC_HANDSHAKE$1]: {
|
|
277
|
+
[SOCKET_CLI_FIX_PACKAGE_LOCK_FILE]: true
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
} catch (e) {
|
|
282
|
+
console.error(e);
|
|
283
|
+
} finally {
|
|
284
|
+
spinner$1.stop();
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
|
|
217
289
|
const commonFlags = {
|
|
218
290
|
help: {
|
|
219
291
|
type: 'boolean',
|
|
@@ -270,10 +342,10 @@ function handleUnsuccessfulApiResponse(_name, result, spinner) {
|
|
|
270
342
|
const message = typeof resultErrorMessage === 'string' ? resultErrorMessage : 'No error message returned';
|
|
271
343
|
if (result.status === 401 || result.status === 403) {
|
|
272
344
|
spinner.stop();
|
|
273
|
-
throw new
|
|
345
|
+
throw new socketUrl.AuthError(message);
|
|
274
346
|
}
|
|
275
347
|
spinner.error(`${colors.bgRed(colors.white('API returned an error:'))} ${message}`);
|
|
276
|
-
process.exit(1);
|
|
348
|
+
process$1.exit(1);
|
|
277
349
|
}
|
|
278
350
|
async function handleApiCall(value, description) {
|
|
279
351
|
let result;
|
|
@@ -318,6 +390,46 @@ function pick(input, keys) {
|
|
|
318
390
|
return result;
|
|
319
391
|
}
|
|
320
392
|
|
|
393
|
+
function getFlagListOutput(list, indent, {
|
|
394
|
+
keyPrefix = '--',
|
|
395
|
+
padName
|
|
396
|
+
} = {}) {
|
|
397
|
+
return getHelpListOutput({
|
|
398
|
+
...list
|
|
399
|
+
}, indent, {
|
|
400
|
+
keyPrefix,
|
|
401
|
+
padName
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
function getHelpListOutput(list, indent, {
|
|
405
|
+
keyPrefix = '',
|
|
406
|
+
padName = 18
|
|
407
|
+
} = {}) {
|
|
408
|
+
let result = '';
|
|
409
|
+
const names = Object.keys(list).sort();
|
|
410
|
+
for (const name of names) {
|
|
411
|
+
const rawDescription = list[name];
|
|
412
|
+
const description = (typeof rawDescription === 'object' ? rawDescription.description : rawDescription) || '';
|
|
413
|
+
result += ''.padEnd(indent) + (keyPrefix + name).padEnd(padName) + description + '\n';
|
|
414
|
+
}
|
|
415
|
+
return result.trim();
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
function stringJoinWithSeparateFinalSeparator(list, separator = ' and ') {
|
|
419
|
+
const values = list.filter(Boolean);
|
|
420
|
+
const {
|
|
421
|
+
length
|
|
422
|
+
} = values;
|
|
423
|
+
if (!length) {
|
|
424
|
+
return '';
|
|
425
|
+
}
|
|
426
|
+
if (length === 1) {
|
|
427
|
+
return values[0];
|
|
428
|
+
}
|
|
429
|
+
const finalValue = values.pop();
|
|
430
|
+
return `${values.join(', ')}${separator}${finalValue}`;
|
|
431
|
+
}
|
|
432
|
+
|
|
321
433
|
const SEVERITIES_BY_ORDER = ['critical', 'high', 'middle', 'low'];
|
|
322
434
|
function getDesiredSeverities(lowestToInclude) {
|
|
323
435
|
const result = [];
|
|
@@ -336,7 +448,7 @@ function formatSeverityCount(severityCount) {
|
|
|
336
448
|
summary.push(`${severityCount[severity]} ${severity}`);
|
|
337
449
|
}
|
|
338
450
|
}
|
|
339
|
-
return
|
|
451
|
+
return stringJoinWithSeparateFinalSeparator(summary);
|
|
340
452
|
}
|
|
341
453
|
function getSeverityCount(issues, lowestToInclude) {
|
|
342
454
|
const severityCount = pick({
|
|
@@ -346,7 +458,9 @@ function getSeverityCount(issues, lowestToInclude) {
|
|
|
346
458
|
critical: 0
|
|
347
459
|
}, getDesiredSeverities(lowestToInclude));
|
|
348
460
|
for (const issue of issues) {
|
|
349
|
-
const
|
|
461
|
+
const {
|
|
462
|
+
value
|
|
463
|
+
} = issue;
|
|
350
464
|
if (!value) {
|
|
351
465
|
continue;
|
|
352
466
|
}
|
|
@@ -357,34 +471,9 @@ function getSeverityCount(issues, lowestToInclude) {
|
|
|
357
471
|
return severityCount;
|
|
358
472
|
}
|
|
359
473
|
|
|
360
|
-
function printFlagList(list, indent, {
|
|
361
|
-
keyPrefix = '--',
|
|
362
|
-
padName
|
|
363
|
-
} = {}) {
|
|
364
|
-
return printHelpList({
|
|
365
|
-
...list
|
|
366
|
-
}, indent, {
|
|
367
|
-
keyPrefix,
|
|
368
|
-
padName
|
|
369
|
-
});
|
|
370
|
-
}
|
|
371
|
-
function printHelpList(list, indent, {
|
|
372
|
-
keyPrefix = '',
|
|
373
|
-
padName = 18
|
|
374
|
-
} = {}) {
|
|
375
|
-
let result = '';
|
|
376
|
-
const names = Object.keys(list).sort();
|
|
377
|
-
for (const name of names) {
|
|
378
|
-
const rawDescription = list[name];
|
|
379
|
-
const description = (typeof rawDescription === 'object' ? rawDescription.description : rawDescription) || '';
|
|
380
|
-
result += ''.padEnd(indent) + (keyPrefix + name).padEnd(padName) + description + '\n';
|
|
381
|
-
}
|
|
382
|
-
return result.trim();
|
|
383
|
-
}
|
|
384
|
-
|
|
385
474
|
const {
|
|
386
|
-
|
|
387
|
-
} =
|
|
475
|
+
NPM: NPM$4
|
|
476
|
+
} = registryConstants;
|
|
388
477
|
const info = {
|
|
389
478
|
description: 'Look up info regarding a package',
|
|
390
479
|
async run(argv, importMeta, {
|
|
@@ -394,15 +483,15 @@ const info = {
|
|
|
394
483
|
const commandContext = setupCommand$m(name, info.description, argv, importMeta);
|
|
395
484
|
if (commandContext) {
|
|
396
485
|
const spinnerText = commandContext.pkgVersion === 'latest' ? `Looking up data for the latest version of ${commandContext.pkgName}` : `Looking up data for version ${commandContext.pkgVersion} of ${commandContext.pkgName}`;
|
|
397
|
-
const spinner =
|
|
486
|
+
const spinner$1 = new spinner.Spinner({
|
|
398
487
|
text: spinnerText
|
|
399
488
|
}).start();
|
|
400
|
-
const packageData = await fetchPackageData(commandContext.pkgName, commandContext.pkgVersion, commandContext, spinner);
|
|
489
|
+
const packageData = await fetchPackageData(commandContext.pkgName, commandContext.pkgVersion, commandContext, spinner$1);
|
|
401
490
|
if (packageData) {
|
|
402
491
|
formatPackageDataOutput(packageData, {
|
|
403
492
|
name,
|
|
404
493
|
...commandContext
|
|
405
|
-
}, spinner);
|
|
494
|
+
}, spinner$1);
|
|
406
495
|
}
|
|
407
496
|
}
|
|
408
497
|
}
|
|
@@ -421,7 +510,7 @@ function setupCommand$m(name, description, argv, importMeta) {
|
|
|
421
510
|
$ ${name} <name>
|
|
422
511
|
|
|
423
512
|
Options
|
|
424
|
-
${
|
|
513
|
+
${getFlagListOutput(flags, 6)}
|
|
425
514
|
|
|
426
515
|
Examples
|
|
427
516
|
$ ${name} webtorrent
|
|
@@ -433,7 +522,7 @@ function setupCommand$m(name, description, argv, importMeta) {
|
|
|
433
522
|
flags
|
|
434
523
|
});
|
|
435
524
|
if (cli.input.length > 1) {
|
|
436
|
-
throw new
|
|
525
|
+
throw new socketUrl.InputError('Only one package lookup supported at once');
|
|
437
526
|
}
|
|
438
527
|
const {
|
|
439
528
|
0: rawPkgName = ''
|
|
@@ -461,7 +550,7 @@ function setupCommand$m(name, description, argv, importMeta) {
|
|
|
461
550
|
async function fetchPackageData(pkgName, pkgVersion, {
|
|
462
551
|
includeAllIssues
|
|
463
552
|
}, spinner) {
|
|
464
|
-
const socketSdk = await
|
|
553
|
+
const socketSdk = await socketUrl.setupSdk(socketUrl.getPublicToken());
|
|
465
554
|
const result = await handleApiCall(socketSdk.getIssuesByNPMPackage(pkgName, pkgVersion), 'looking up package');
|
|
466
555
|
const scoreResult = await handleApiCall(socketSdk.getScoreByNPMPackage(pkgName, pkgVersion), 'looking up package score');
|
|
467
556
|
if (result.success === false) {
|
|
@@ -508,8 +597,8 @@ function formatPackageDataOutput({
|
|
|
508
597
|
} else {
|
|
509
598
|
spinner.success('Package has no issues');
|
|
510
599
|
}
|
|
511
|
-
const format = new
|
|
512
|
-
const url =
|
|
600
|
+
const format = new socketUrl.ColorOrMarkdown(!!outputMarkdown);
|
|
601
|
+
const url = socketUrl.getSocketDevPackageOverviewUrl(NPM$4, pkgName, pkgVersion);
|
|
513
602
|
console.log('\n');
|
|
514
603
|
if (pkgVersion === 'latest') {
|
|
515
604
|
console.log(`Detailed info on socket.dev: ${format.hyperlink(`${pkgName}`, url, {
|
|
@@ -525,7 +614,7 @@ function formatPackageDataOutput({
|
|
|
525
614
|
}
|
|
526
615
|
}
|
|
527
616
|
if (strict && objectSome(severityCount)) {
|
|
528
|
-
process.exit(1);
|
|
617
|
+
process$1.exit(1);
|
|
529
618
|
}
|
|
530
619
|
}
|
|
531
620
|
function formatPackageIssuesDetails(packageData, outputMarkdown) {
|
|
@@ -546,9 +635,9 @@ function formatPackageIssuesDetails(packageData, outputMarkdown) {
|
|
|
546
635
|
}
|
|
547
636
|
return acc;
|
|
548
637
|
}, {});
|
|
549
|
-
const format = new
|
|
638
|
+
const format = new socketUrl.ColorOrMarkdown(!!outputMarkdown);
|
|
550
639
|
for (const issue of Object.keys(uniqueIssues)) {
|
|
551
|
-
const issueWithLink = format.hyperlink(`${uniqueIssues[issue]?.label}`,
|
|
640
|
+
const issueWithLink = format.hyperlink(`${uniqueIssues[issue]?.label}`, socketUrl.getSocketDevAlertUrl(issue), {
|
|
552
641
|
fallbackToUrl: true
|
|
553
642
|
});
|
|
554
643
|
if (uniqueIssues[issue]?.count === 1) {
|
|
@@ -568,7 +657,7 @@ function formatScore(score) {
|
|
|
568
657
|
}
|
|
569
658
|
|
|
570
659
|
const {
|
|
571
|
-
|
|
660
|
+
SOCKET_PUBLIC_API_TOKEN
|
|
572
661
|
} = constants;
|
|
573
662
|
const description$5 = 'Socket API login';
|
|
574
663
|
const flags = {
|
|
@@ -597,7 +686,7 @@ const login = {
|
|
|
597
686
|
Logs into the Socket API by prompting for an API key
|
|
598
687
|
|
|
599
688
|
Options
|
|
600
|
-
${
|
|
689
|
+
${getFlagListOutput({
|
|
601
690
|
'api-base-url': flags['apiBaseUrl'].description,
|
|
602
691
|
'api-proxy': flags['apiProxy'].description
|
|
603
692
|
}, 8)}
|
|
@@ -618,30 +707,30 @@ const login = {
|
|
|
618
707
|
cli.showHelp();
|
|
619
708
|
return;
|
|
620
709
|
}
|
|
621
|
-
if (!
|
|
622
|
-
throw new
|
|
710
|
+
if (!isInteractive()) {
|
|
711
|
+
throw new socketUrl.InputError('Cannot prompt for credentials in a non-interactive shell');
|
|
623
712
|
}
|
|
624
|
-
const
|
|
625
|
-
message: `Enter your ${
|
|
626
|
-
})) ||
|
|
713
|
+
const apiToken = (await prompts.password({
|
|
714
|
+
message: `Enter your ${terminalLink('Socket.dev API key', 'https://docs.socket.dev/docs/api-keys')} (leave blank for a public key)`
|
|
715
|
+
})) || SOCKET_PUBLIC_API_TOKEN;
|
|
627
716
|
let apiBaseUrl = cli.flags['apiBaseUrl'];
|
|
628
|
-
apiBaseUrl ??=
|
|
717
|
+
apiBaseUrl ??= socketUrl.getSetting('apiBaseUrl') ?? undefined;
|
|
629
718
|
let apiProxy = cli.flags['apiProxy'];
|
|
630
|
-
apiProxy ??=
|
|
631
|
-
const spinner =
|
|
719
|
+
apiProxy ??= socketUrl.getSetting('apiProxy') ?? undefined;
|
|
720
|
+
const spinner$1 = new spinner.Spinner({
|
|
632
721
|
text: 'Verifying API key...'
|
|
633
722
|
}).start();
|
|
634
723
|
let orgs;
|
|
635
724
|
try {
|
|
636
|
-
const sdk
|
|
637
|
-
const result = await sdk
|
|
725
|
+
const sdk = await socketUrl.setupSdk(apiToken, apiBaseUrl, apiProxy);
|
|
726
|
+
const result = await sdk.getOrganizations();
|
|
638
727
|
if (!result.success) {
|
|
639
|
-
throw new
|
|
728
|
+
throw new socketUrl.AuthError();
|
|
640
729
|
}
|
|
641
730
|
orgs = result.data;
|
|
642
|
-
spinner.success('API key verified');
|
|
731
|
+
spinner$1.success('API key verified');
|
|
643
732
|
} catch {
|
|
644
|
-
spinner.error('Invalid API key');
|
|
733
|
+
spinner$1.error('Invalid API key');
|
|
645
734
|
return;
|
|
646
735
|
}
|
|
647
736
|
const enforcedChoices = Object.values(orgs.organizations).filter(nonNullish).filter(org => org.plan === 'enterprise').map(org => ({
|
|
@@ -673,12 +762,13 @@ const login = {
|
|
|
673
762
|
}
|
|
674
763
|
}
|
|
675
764
|
}
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
765
|
+
socketUrl.updateSetting('enforcedOrgs', enforcedOrgs);
|
|
766
|
+
// TODO: Rename the 'apiKey' setting to 'apiToken'.
|
|
767
|
+
const oldToken = socketUrl.getSetting('apiKey');
|
|
768
|
+
socketUrl.updateSetting('apiKey', apiToken);
|
|
769
|
+
socketUrl.updateSetting('apiBaseUrl', apiBaseUrl);
|
|
770
|
+
socketUrl.updateSetting('apiProxy', apiProxy);
|
|
771
|
+
spinner$1.success(`API credentials ${oldToken ? 'updated' : 'set'}`);
|
|
682
772
|
}
|
|
683
773
|
};
|
|
684
774
|
|
|
@@ -710,11 +800,11 @@ const logout = {
|
|
|
710
800
|
cli.showHelp();
|
|
711
801
|
return;
|
|
712
802
|
}
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
803
|
+
socketUrl.updateSetting('apiKey', null);
|
|
804
|
+
socketUrl.updateSetting('apiBaseUrl', null);
|
|
805
|
+
socketUrl.updateSetting('apiProxy', null);
|
|
806
|
+
socketUrl.updateSetting('enforcedOrgs', null);
|
|
807
|
+
new spinner.Spinner().success('Successfully logged out');
|
|
718
808
|
}
|
|
719
809
|
};
|
|
720
810
|
|
|
@@ -749,7 +839,7 @@ function existsSync(filepath) {
|
|
|
749
839
|
return false;
|
|
750
840
|
}
|
|
751
841
|
async function findUp(name, {
|
|
752
|
-
cwd = process.cwd()
|
|
842
|
+
cwd = process$1.cwd()
|
|
753
843
|
}) {
|
|
754
844
|
let dir = path.resolve(cwd);
|
|
755
845
|
const {
|
|
@@ -791,6 +881,7 @@ const {
|
|
|
791
881
|
NPM: NPM$2,
|
|
792
882
|
PNPM: PNPM$1,
|
|
793
883
|
VLT: VLT$1,
|
|
884
|
+
YARN,
|
|
794
885
|
YARN_BERRY: YARN_BERRY$1,
|
|
795
886
|
YARN_CLASSIC: YARN_CLASSIC$1
|
|
796
887
|
} = constants;
|
|
@@ -801,10 +892,20 @@ const {
|
|
|
801
892
|
numeric: true,
|
|
802
893
|
sensitivity: 'base'
|
|
803
894
|
});
|
|
895
|
+
const binByAgent = {
|
|
896
|
+
__proto__: null,
|
|
897
|
+
[BUN$1]: BUN$1,
|
|
898
|
+
[NPM$2]: NPM$2,
|
|
899
|
+
[PNPM$1]: PNPM$1,
|
|
900
|
+
[YARN_BERRY$1]: YARN,
|
|
901
|
+
[YARN_CLASSIC$1]: YARN,
|
|
902
|
+
[VLT$1]: VLT$1
|
|
903
|
+
};
|
|
804
904
|
async function getAgentExecPath(agent) {
|
|
805
|
-
|
|
905
|
+
const binName = binByAgent[agent];
|
|
906
|
+
return (await which(binName, {
|
|
806
907
|
nothrow: true
|
|
807
|
-
})) ??
|
|
908
|
+
})) ?? binName;
|
|
808
909
|
}
|
|
809
910
|
async function getAgentVersion(agentExecPath, cwd) {
|
|
810
911
|
let result;
|
|
@@ -860,7 +961,7 @@ const readLockFileByAgent = (() => {
|
|
|
860
961
|
const lockBuffer = await binaryReader(lockPath);
|
|
861
962
|
if (lockBuffer) {
|
|
862
963
|
try {
|
|
863
|
-
return
|
|
964
|
+
return index_cjs.parse(lockBuffer);
|
|
864
965
|
} catch {}
|
|
865
966
|
}
|
|
866
967
|
// To print a Yarn lockfile to your console without writing it to disk
|
|
@@ -878,7 +979,7 @@ const readLockFileByAgent = (() => {
|
|
|
878
979
|
};
|
|
879
980
|
})();
|
|
880
981
|
async function detect({
|
|
881
|
-
cwd = process.cwd(),
|
|
982
|
+
cwd = process$1.cwd(),
|
|
882
983
|
onUnknown
|
|
883
984
|
} = {}) {
|
|
884
985
|
let lockPath = await findUp(Object.keys(LOCKS), {
|
|
@@ -985,25 +1086,25 @@ const {
|
|
|
985
1086
|
BUN,
|
|
986
1087
|
LOCK_EXT,
|
|
987
1088
|
NPM: NPM$1,
|
|
1089
|
+
OVERRIDES,
|
|
988
1090
|
PNPM,
|
|
989
|
-
|
|
1091
|
+
RESOLUTIONS,
|
|
1092
|
+
SOCKET_CLI_UPDATE_OVERRIDES_IN_PACKAGE_LOCK_FILE,
|
|
1093
|
+
SOCKET_IPC_HANDSHAKE,
|
|
990
1094
|
VLT,
|
|
991
1095
|
YARN_BERRY,
|
|
992
1096
|
YARN_CLASSIC,
|
|
993
|
-
abortSignal: abortSignal$2
|
|
994
|
-
execPath,
|
|
995
|
-
rootBinPath
|
|
1097
|
+
abortSignal: abortSignal$2
|
|
996
1098
|
} = constants;
|
|
997
1099
|
const COMMAND_TITLE = 'Socket Optimize';
|
|
998
|
-
const OVERRIDES_FIELD_NAME = 'overrides';
|
|
999
1100
|
const NPM_OVERRIDE_PR_URL = 'https://github.com/npm/cli/pull/7025';
|
|
1000
1101
|
const PNPM_FIELD_NAME = PNPM;
|
|
1001
1102
|
const PNPM_WORKSPACE = `${PNPM}-workspace`;
|
|
1002
|
-
const RESOLUTIONS_FIELD_NAME = 'resolutions';
|
|
1003
1103
|
const manifestNpmOverrides = registry.getManifestData(NPM$1);
|
|
1004
1104
|
const getOverridesDataByAgent = {
|
|
1105
|
+
__proto__: null,
|
|
1005
1106
|
[BUN](pkgJson) {
|
|
1006
|
-
const overrides = pkgJson?.
|
|
1107
|
+
const overrides = pkgJson?.[RESOLUTIONS] ?? {};
|
|
1007
1108
|
return {
|
|
1008
1109
|
type: YARN_BERRY,
|
|
1009
1110
|
overrides
|
|
@@ -1012,7 +1113,7 @@ const getOverridesDataByAgent = {
|
|
|
1012
1113
|
// npm overrides documentation:
|
|
1013
1114
|
// https://docs.npmjs.com/cli/v10/configuring-npm/package-json#overrides
|
|
1014
1115
|
[NPM$1](pkgJson) {
|
|
1015
|
-
const overrides = pkgJson?.
|
|
1116
|
+
const overrides = pkgJson?.[OVERRIDES] ?? {};
|
|
1016
1117
|
return {
|
|
1017
1118
|
type: NPM$1,
|
|
1018
1119
|
overrides
|
|
@@ -1021,14 +1122,14 @@ const getOverridesDataByAgent = {
|
|
|
1021
1122
|
// pnpm overrides documentation:
|
|
1022
1123
|
// https://pnpm.io/package_json#pnpmoverrides
|
|
1023
1124
|
[PNPM](pkgJson) {
|
|
1024
|
-
const overrides = pkgJson?.pnpm?.
|
|
1125
|
+
const overrides = pkgJson?.pnpm?.[OVERRIDES] ?? {};
|
|
1025
1126
|
return {
|
|
1026
1127
|
type: PNPM,
|
|
1027
1128
|
overrides
|
|
1028
1129
|
};
|
|
1029
1130
|
},
|
|
1030
1131
|
[VLT](pkgJson) {
|
|
1031
|
-
const overrides = pkgJson?.
|
|
1132
|
+
const overrides = pkgJson?.[OVERRIDES] ?? {};
|
|
1032
1133
|
return {
|
|
1033
1134
|
type: VLT,
|
|
1034
1135
|
overrides
|
|
@@ -1037,7 +1138,7 @@ const getOverridesDataByAgent = {
|
|
|
1037
1138
|
// Yarn resolutions documentation:
|
|
1038
1139
|
// https://yarnpkg.com/configuration/manifest#resolutions
|
|
1039
1140
|
[YARN_BERRY](pkgJson) {
|
|
1040
|
-
const overrides = pkgJson?.
|
|
1141
|
+
const overrides = pkgJson?.[RESOLUTIONS] ?? {};
|
|
1041
1142
|
return {
|
|
1042
1143
|
type: YARN_BERRY,
|
|
1043
1144
|
overrides
|
|
@@ -1046,7 +1147,7 @@ const getOverridesDataByAgent = {
|
|
|
1046
1147
|
// Yarn resolutions documentation:
|
|
1047
1148
|
// https://classic.yarnpkg.com/en/docs/selective-version-resolutions
|
|
1048
1149
|
[YARN_CLASSIC](pkgJson) {
|
|
1049
|
-
const overrides = pkgJson?.
|
|
1150
|
+
const overrides = pkgJson?.[RESOLUTIONS] ?? {};
|
|
1050
1151
|
return {
|
|
1051
1152
|
type: YARN_CLASSIC,
|
|
1052
1153
|
overrides
|
|
@@ -1070,6 +1171,7 @@ const lockIncludesByAgent = (() => {
|
|
|
1070
1171
|
`(?<=(?:^\\s*|,\\s*)"?)${escapedName}(?=@)`, 'm').test(lockSrc);
|
|
1071
1172
|
}
|
|
1072
1173
|
return {
|
|
1174
|
+
__proto__: null,
|
|
1073
1175
|
[BUN](lockSrc, name, lockBasename) {
|
|
1074
1176
|
// This is a bit counterintuitive. When lockBasename ends with a .lockb
|
|
1075
1177
|
// we treat it as a yarn.lock. When lockBasename ends with a .lock we
|
|
@@ -1133,7 +1235,7 @@ const updateManifestByAgent = (() => {
|
|
|
1133
1235
|
[field]: undefined
|
|
1134
1236
|
});
|
|
1135
1237
|
}
|
|
1136
|
-
} else if (field ===
|
|
1238
|
+
} else if (field === OVERRIDES || field === RESOLUTIONS) {
|
|
1137
1239
|
// Properties with undefined values are omitted when saved as JSON.
|
|
1138
1240
|
editablePkgJson.update({
|
|
1139
1241
|
[field]: objects.hasKeys(value) ? value : undefined
|
|
@@ -1145,7 +1247,7 @@ const updateManifestByAgent = (() => {
|
|
|
1145
1247
|
}
|
|
1146
1248
|
return;
|
|
1147
1249
|
}
|
|
1148
|
-
if ((field ===
|
|
1250
|
+
if ((field === OVERRIDES || field === PNPM_FIELD_NAME || field === RESOLUTIONS) && !objects.hasKeys(value)) {
|
|
1149
1251
|
return;
|
|
1150
1252
|
}
|
|
1151
1253
|
// Since the field doesn't exist we want to insert it into the package.json
|
|
@@ -1154,17 +1256,17 @@ const updateManifestByAgent = (() => {
|
|
|
1154
1256
|
const entries = Object.entries(pkgJson);
|
|
1155
1257
|
let insertIndex = -1;
|
|
1156
1258
|
let isPlacingHigher = false;
|
|
1157
|
-
if (field ===
|
|
1158
|
-
insertIndex = getLowestEntryIndex(entries, [
|
|
1259
|
+
if (field === OVERRIDES) {
|
|
1260
|
+
insertIndex = getLowestEntryIndex(entries, [RESOLUTIONS]);
|
|
1159
1261
|
if (insertIndex === -1) {
|
|
1160
1262
|
isPlacingHigher = true;
|
|
1161
1263
|
insertIndex = getHighestEntryIndex(entries, [...depFields, PNPM]);
|
|
1162
1264
|
}
|
|
1163
|
-
} else if (field ===
|
|
1265
|
+
} else if (field === RESOLUTIONS) {
|
|
1164
1266
|
isPlacingHigher = true;
|
|
1165
|
-
insertIndex = getHighestEntryIndex(entries, [...depFields,
|
|
1267
|
+
insertIndex = getHighestEntryIndex(entries, [...depFields, OVERRIDES, PNPM]);
|
|
1166
1268
|
} else if (field === PNPM_FIELD_NAME) {
|
|
1167
|
-
insertIndex = getLowestEntryIndex(entries, [
|
|
1269
|
+
insertIndex = getLowestEntryIndex(entries, [OVERRIDES, RESOLUTIONS]);
|
|
1168
1270
|
if (insertIndex === -1) {
|
|
1169
1271
|
isPlacingHigher = true;
|
|
1170
1272
|
insertIndex = getHighestEntryIndex(entries, depFields);
|
|
@@ -1186,12 +1288,13 @@ const updateManifestByAgent = (() => {
|
|
|
1186
1288
|
editablePkgJson.fromJSON(`${JSON.stringify(Object.fromEntries(entries), null, 2)}\n`);
|
|
1187
1289
|
}
|
|
1188
1290
|
function updateOverrides(editablePkgJson, overrides) {
|
|
1189
|
-
updatePkgJson(editablePkgJson,
|
|
1291
|
+
updatePkgJson(editablePkgJson, OVERRIDES, overrides);
|
|
1190
1292
|
}
|
|
1191
1293
|
function updateResolutions(editablePkgJson, overrides) {
|
|
1192
|
-
updatePkgJson(editablePkgJson,
|
|
1294
|
+
updatePkgJson(editablePkgJson, RESOLUTIONS, overrides);
|
|
1193
1295
|
}
|
|
1194
1296
|
return {
|
|
1297
|
+
__proto__: null,
|
|
1195
1298
|
[BUN]: updateResolutions,
|
|
1196
1299
|
[NPM$1]: updateOverrides,
|
|
1197
1300
|
[PNPM](editablePkgJson, overrides) {
|
|
@@ -1253,6 +1356,7 @@ const lsByAgent = (() => {
|
|
|
1253
1356
|
return cleanupQueryStdout(stdout);
|
|
1254
1357
|
}
|
|
1255
1358
|
return {
|
|
1359
|
+
__proto__: null,
|
|
1256
1360
|
async [BUN](agentExecPath, cwd) {
|
|
1257
1361
|
try {
|
|
1258
1362
|
// Bun does not support filtering by production packages yet.
|
|
@@ -1330,6 +1434,7 @@ const depsIncludesByAgent = (() => {
|
|
|
1330
1434
|
return stdout.includes(`"${name}"`);
|
|
1331
1435
|
}
|
|
1332
1436
|
return {
|
|
1437
|
+
__proto__: null,
|
|
1333
1438
|
[BUN]: matchHumanStdout,
|
|
1334
1439
|
[NPM$1]: matchQueryStdout,
|
|
1335
1440
|
[PNPM]: matchQueryStdout,
|
|
@@ -1339,7 +1444,7 @@ const depsIncludesByAgent = (() => {
|
|
|
1339
1444
|
};
|
|
1340
1445
|
})();
|
|
1341
1446
|
function createActionMessage(verb, overrideCount, workspaceCount) {
|
|
1342
|
-
return `${verb} ${overrideCount} Socket.dev optimized
|
|
1447
|
+
return `${verb} ${overrideCount} Socket.dev optimized ${words.pluralize('override', overrideCount)}${workspaceCount ? ` in ${workspaceCount} ${words.pluralize('workspace', workspaceCount)}` : ''}`;
|
|
1343
1448
|
}
|
|
1344
1449
|
function getDependencyEntries(pkgJson) {
|
|
1345
1450
|
const {
|
|
@@ -1512,7 +1617,7 @@ async function addOverrides({
|
|
|
1512
1617
|
const oldSpec = overrideExists ? overrides[origPkgName] : undefined;
|
|
1513
1618
|
const depAlias = depAliasMap.get(origPkgName);
|
|
1514
1619
|
const regSpecStartsLike = `${NPM$1}:${regPkgName}@`;
|
|
1515
|
-
let newSpec = `${regSpecStartsLike}
|
|
1620
|
+
let newSpec = `${regSpecStartsLike}${pin ? version : `^${major}`}`;
|
|
1516
1621
|
let thisVersion = version;
|
|
1517
1622
|
if (depAlias && type === NPM$1) {
|
|
1518
1623
|
// With npm one may not set an override for a package that one directly
|
|
@@ -1529,7 +1634,7 @@ async function addOverrides({
|
|
|
1529
1634
|
if (pin) {
|
|
1530
1635
|
thisVersion = semver.major(semver.coerce(npa(thisSpec).rawSpec)?.version ?? version) === major ? version : (await packages.fetchPackageManifest(thisSpec))?.version ?? version;
|
|
1531
1636
|
}
|
|
1532
|
-
newSpec = `${regSpecStartsLike}
|
|
1637
|
+
newSpec = `${regSpecStartsLike}${pin ? thisVersion : `^${semver.major(thisVersion)}`}`;
|
|
1533
1638
|
} else {
|
|
1534
1639
|
newSpec = oldSpec;
|
|
1535
1640
|
}
|
|
@@ -1597,7 +1702,7 @@ const optimize = {
|
|
|
1597
1702
|
pin,
|
|
1598
1703
|
prod
|
|
1599
1704
|
} = commandContext;
|
|
1600
|
-
const cwd = process.cwd();
|
|
1705
|
+
const cwd = process$1.cwd();
|
|
1601
1706
|
const {
|
|
1602
1707
|
agent,
|
|
1603
1708
|
agentExecPath,
|
|
@@ -1644,13 +1749,13 @@ const optimize = {
|
|
|
1644
1749
|
if (lockPath && path.relative(cwd, lockPath).startsWith('.')) {
|
|
1645
1750
|
console.warn(`⚠️ ${COMMAND_TITLE}: Package ${lockName} found at ${lockPath}`);
|
|
1646
1751
|
}
|
|
1647
|
-
const spinner =
|
|
1752
|
+
const spinner$1 = new spinner.Spinner({
|
|
1648
1753
|
text: 'Socket optimizing...'
|
|
1649
1754
|
});
|
|
1650
1755
|
const state = createAddOverridesState({
|
|
1651
|
-
spinner
|
|
1756
|
+
spinner: spinner$1
|
|
1652
1757
|
});
|
|
1653
|
-
spinner.start();
|
|
1758
|
+
spinner$1.start();
|
|
1654
1759
|
const nodeRange = `>=${minimumNodeVersion}`;
|
|
1655
1760
|
const manifestEntries = manifestNpmOverrides.filter(({
|
|
1656
1761
|
1: data
|
|
@@ -1668,7 +1773,7 @@ const optimize = {
|
|
|
1668
1773
|
prod,
|
|
1669
1774
|
rootPath: pkgPath
|
|
1670
1775
|
}, state);
|
|
1671
|
-
spinner.stop();
|
|
1776
|
+
spinner$1.stop();
|
|
1672
1777
|
const addedCount = state.added.size;
|
|
1673
1778
|
const updatedCount = state.updated.size;
|
|
1674
1779
|
const pkgJsonChanged = addedCount > 0 || updatedCount > 0;
|
|
@@ -1686,23 +1791,24 @@ const optimize = {
|
|
|
1686
1791
|
if (isNpm || pkgJsonChanged) {
|
|
1687
1792
|
// Always update package-lock.json until the npm overrides PR lands:
|
|
1688
1793
|
// https://github.com/npm/cli/pull/7025
|
|
1689
|
-
spinner.start(`Updating ${lockName}...`);
|
|
1794
|
+
spinner$1.start(`Updating ${lockName}...`);
|
|
1690
1795
|
try {
|
|
1691
1796
|
if (isNpm) {
|
|
1692
|
-
const
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
stdio: 'ignore',
|
|
1696
|
-
env: {
|
|
1697
|
-
...process.env,
|
|
1698
|
-
[UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE]: '1'
|
|
1797
|
+
const ipc = {
|
|
1798
|
+
[SOCKET_IPC_HANDSHAKE]: {
|
|
1799
|
+
[SOCKET_CLI_UPDATE_OVERRIDES_IN_PACKAGE_LOCK_FILE]: true
|
|
1699
1800
|
}
|
|
1700
1801
|
};
|
|
1701
|
-
await
|
|
1802
|
+
await shadowNpmInstall({
|
|
1803
|
+
ipc
|
|
1804
|
+
});
|
|
1702
1805
|
// TODO: This is a temporary workaround for a `npm ci` bug where it
|
|
1703
1806
|
// will error out after Socket Optimize generates a lock file. More
|
|
1704
1807
|
// investigation is needed.
|
|
1705
|
-
await
|
|
1808
|
+
await shadowNpmInstall({
|
|
1809
|
+
flags: ['--ignore-scripts', '--package-lock-only'],
|
|
1810
|
+
ipc
|
|
1811
|
+
});
|
|
1706
1812
|
} else {
|
|
1707
1813
|
// All package managers support the "install" command.
|
|
1708
1814
|
await spawn(agentExecPath, ['install'], {
|
|
@@ -1710,12 +1816,13 @@ const optimize = {
|
|
|
1710
1816
|
stdio: 'ignore'
|
|
1711
1817
|
});
|
|
1712
1818
|
}
|
|
1713
|
-
spinner.stop();
|
|
1819
|
+
spinner$1.stop();
|
|
1714
1820
|
if (isNpm) {
|
|
1715
1821
|
console.log(`💡 Re-run ${COMMAND_TITLE} whenever ${lockName} changes.\n This can be skipped once npm ships ${NPM_OVERRIDE_PR_URL}.`);
|
|
1716
1822
|
}
|
|
1717
|
-
} catch {
|
|
1718
|
-
spinner.error(`${COMMAND_TITLE}: ${agent} install failed to update ${lockName}`);
|
|
1823
|
+
} catch (e) {
|
|
1824
|
+
spinner$1.error(`${COMMAND_TITLE}: ${agent} install failed to update ${lockName}`);
|
|
1825
|
+
console.error(e);
|
|
1719
1826
|
}
|
|
1720
1827
|
}
|
|
1721
1828
|
}
|
|
@@ -1742,7 +1849,7 @@ function setupCommand$l(name, description, argv, importMeta) {
|
|
|
1742
1849
|
$ ${name}
|
|
1743
1850
|
|
|
1744
1851
|
Options
|
|
1745
|
-
${
|
|
1852
|
+
${getFlagListOutput(flags, 6)}
|
|
1746
1853
|
|
|
1747
1854
|
Examples
|
|
1748
1855
|
$ ${name}
|
|
@@ -1790,20 +1897,20 @@ function setupCommand$k(name, description, argv, importMeta) {
|
|
|
1790
1897
|
});
|
|
1791
1898
|
}
|
|
1792
1899
|
async function fetchOrganizations() {
|
|
1793
|
-
const apiKey =
|
|
1900
|
+
const apiKey = socketUrl.getDefaultToken();
|
|
1794
1901
|
if (!apiKey) {
|
|
1795
|
-
throw new
|
|
1902
|
+
throw new socketUrl.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
1796
1903
|
}
|
|
1797
|
-
const spinner =
|
|
1904
|
+
const spinner$1 = new spinner.Spinner({
|
|
1798
1905
|
text: 'Fetching organizations...'
|
|
1799
1906
|
}).start();
|
|
1800
|
-
const socketSdk = await
|
|
1907
|
+
const socketSdk = await socketUrl.setupSdk(apiKey);
|
|
1801
1908
|
const result = await handleApiCall(socketSdk.getOrganizations(), 'looking up organizations');
|
|
1802
1909
|
if (result.success === false) {
|
|
1803
|
-
handleUnsuccessfulApiResponse('getOrganizations', result, spinner);
|
|
1910
|
+
handleUnsuccessfulApiResponse('getOrganizations', result, spinner$1);
|
|
1804
1911
|
return;
|
|
1805
1912
|
}
|
|
1806
|
-
spinner.stop(`List of organizations associated with your API key: ${colors.italic(apiKey)}`);
|
|
1913
|
+
spinner$1.stop(`List of organizations associated with your API key: ${colors.italic(apiKey)}`);
|
|
1807
1914
|
const organizations = Object.values(result.data.organizations);
|
|
1808
1915
|
for (const o of organizations) {
|
|
1809
1916
|
console.log(`
|
|
@@ -1837,7 +1944,7 @@ async function setupCommand$j(name, description, argv, importMeta) {
|
|
|
1837
1944
|
$ ${name} <${binName$1} command>
|
|
1838
1945
|
|
|
1839
1946
|
Options
|
|
1840
|
-
${
|
|
1947
|
+
${getFlagListOutput(flags, 6)}
|
|
1841
1948
|
|
|
1842
1949
|
Examples
|
|
1843
1950
|
$ ${name} install
|
|
@@ -1862,7 +1969,7 @@ async function setupCommand$j(name, description, argv, importMeta) {
|
|
|
1862
1969
|
// The exit code 127 indicates that the command or binary being executed
|
|
1863
1970
|
// could not be found.
|
|
1864
1971
|
console.error(`Socket unable to locate ${binName$1}; ensure it is available in the PATH environment variable.`);
|
|
1865
|
-
process.exit(127);
|
|
1972
|
+
process$1.exit(127);
|
|
1866
1973
|
}
|
|
1867
1974
|
const spawnPromise = spawn(binPath, argv, {
|
|
1868
1975
|
signal: abortSignal$1,
|
|
@@ -1874,9 +1981,9 @@ async function setupCommand$j(name, description, argv, importMeta) {
|
|
|
1874
1981
|
return;
|
|
1875
1982
|
}
|
|
1876
1983
|
if (signalName) {
|
|
1877
|
-
process.kill(process.pid, signalName);
|
|
1984
|
+
process$1.kill(process$1.pid, signalName);
|
|
1878
1985
|
} else if (code !== null) {
|
|
1879
|
-
process.exit(code);
|
|
1986
|
+
process$1.exit(code);
|
|
1880
1987
|
}
|
|
1881
1988
|
});
|
|
1882
1989
|
await spawnPromise;
|
|
@@ -1905,7 +2012,7 @@ async function setupCommand$i(name, description, argv, importMeta) {
|
|
|
1905
2012
|
$ ${name} <${binName} command>
|
|
1906
2013
|
|
|
1907
2014
|
Options
|
|
1908
|
-
${
|
|
2015
|
+
${getFlagListOutput(flags, 6)}
|
|
1909
2016
|
|
|
1910
2017
|
Examples
|
|
1911
2018
|
$ ${name} install
|
|
@@ -1930,7 +2037,7 @@ async function setupCommand$i(name, description, argv, importMeta) {
|
|
|
1930
2037
|
// The exit code 127 indicates that the command or binary being executed
|
|
1931
2038
|
// could not be found.
|
|
1932
2039
|
console.error(`Socket unable to locate ${binName}; ensure it is available in the PATH environment variable.`);
|
|
1933
|
-
process.exit(127);
|
|
2040
|
+
process$1.exit(127);
|
|
1934
2041
|
}
|
|
1935
2042
|
const spawnPromise = spawn(binPath, argv, {
|
|
1936
2043
|
signal: abortSignal,
|
|
@@ -1942,9 +2049,9 @@ async function setupCommand$i(name, description, argv, importMeta) {
|
|
|
1942
2049
|
return;
|
|
1943
2050
|
}
|
|
1944
2051
|
if (signalName) {
|
|
1945
|
-
process.kill(process.pid, signalName);
|
|
2052
|
+
process$1.kill(process$1.pid, signalName);
|
|
1946
2053
|
} else if (code !== null) {
|
|
1947
|
-
process.exit(code);
|
|
2054
|
+
process$1.exit(code);
|
|
1948
2055
|
}
|
|
1949
2056
|
});
|
|
1950
2057
|
await spawnPromise;
|
|
@@ -1980,7 +2087,7 @@ function setupCommand$h(name, description, argv, importMeta) {
|
|
|
1980
2087
|
$ ${name} <report-identifier>
|
|
1981
2088
|
|
|
1982
2089
|
Options
|
|
1983
|
-
${
|
|
2090
|
+
${getFlagListOutput(flags, 6)}
|
|
1984
2091
|
|
|
1985
2092
|
Examples
|
|
1986
2093
|
$ ${name} QXU8PmK7LfH608RAwfIKdbcHgwEd_ZeWJ9QEGv05FJUQ
|
|
@@ -2002,7 +2109,7 @@ function setupCommand$h(name, description, argv, importMeta) {
|
|
|
2002
2109
|
}
|
|
2003
2110
|
// Validate the input.
|
|
2004
2111
|
if (extraInput.length) {
|
|
2005
|
-
throw new
|
|
2112
|
+
throw new socketUrl.InputError(`Can only handle a single report ID at a time, but got ${cli.input.length} report ID:s: ${cli.input.join(', ')}`);
|
|
2006
2113
|
}
|
|
2007
2114
|
return {
|
|
2008
2115
|
includeAllIssues: cli.flags['all'],
|
|
@@ -2018,8 +2125,8 @@ async function fetchReportData(reportId, {
|
|
|
2018
2125
|
strict
|
|
2019
2126
|
}) {
|
|
2020
2127
|
// Do the API call
|
|
2021
|
-
const socketSdk = await
|
|
2022
|
-
const spinner =
|
|
2128
|
+
const socketSdk = await socketUrl.setupSdk();
|
|
2129
|
+
const spinner$1 = new spinner.Spinner({
|
|
2023
2130
|
text: `Fetching report with ID ${reportId} (this could take a while)`
|
|
2024
2131
|
}).start();
|
|
2025
2132
|
let result;
|
|
@@ -2034,23 +2141,23 @@ async function fetchReportData(reportId, {
|
|
|
2034
2141
|
}
|
|
2035
2142
|
}
|
|
2036
2143
|
if (result.success === false) {
|
|
2037
|
-
return handleUnsuccessfulApiResponse('getReport', result, spinner);
|
|
2144
|
+
return handleUnsuccessfulApiResponse('getReport', result, spinner$1);
|
|
2038
2145
|
}
|
|
2039
2146
|
|
|
2040
2147
|
// Conclude the status of the API call
|
|
2041
2148
|
|
|
2042
2149
|
if (strict) {
|
|
2043
2150
|
if (result.data.healthy) {
|
|
2044
|
-
spinner.success('Report result is healthy and great!');
|
|
2151
|
+
spinner$1.success('Report result is healthy and great!');
|
|
2045
2152
|
} else {
|
|
2046
|
-
spinner.error('Report result deemed unhealthy for project');
|
|
2153
|
+
spinner$1.error('Report result deemed unhealthy for project');
|
|
2047
2154
|
}
|
|
2048
2155
|
} else if (result.data.healthy === false) {
|
|
2049
2156
|
const severityCount = getSeverityCount(result.data.issues, includeAllIssues ? undefined : 'high');
|
|
2050
2157
|
const issueSummary = formatSeverityCount(severityCount);
|
|
2051
|
-
spinner.success(`Report has these issues: ${issueSummary}`);
|
|
2158
|
+
spinner$1.success(`Report has these issues: ${issueSummary}`);
|
|
2052
2159
|
} else {
|
|
2053
|
-
spinner.success('Report has no issues');
|
|
2160
|
+
spinner$1.success('Report has no issues');
|
|
2054
2161
|
}
|
|
2055
2162
|
return result.data;
|
|
2056
2163
|
}
|
|
@@ -2064,7 +2171,7 @@ function formatReportDataOutput(data, {
|
|
|
2064
2171
|
if (outputJson) {
|
|
2065
2172
|
console.log(JSON.stringify(data, undefined, 2));
|
|
2066
2173
|
} else {
|
|
2067
|
-
const format = new
|
|
2174
|
+
const format = new socketUrl.ColorOrMarkdown(!!outputMarkdown);
|
|
2068
2175
|
console.log('\nDetailed info on socket.dev: ' + format.hyperlink(reportId, data.url, {
|
|
2069
2176
|
fallbackToUrl: true
|
|
2070
2177
|
}));
|
|
@@ -2073,7 +2180,7 @@ function formatReportDataOutput(data, {
|
|
|
2073
2180
|
}
|
|
2074
2181
|
}
|
|
2075
2182
|
if (strict && data.healthy === false) {
|
|
2076
|
-
process.exit(1);
|
|
2183
|
+
process$1.exit(1);
|
|
2077
2184
|
}
|
|
2078
2185
|
}
|
|
2079
2186
|
|
|
@@ -2088,7 +2195,6 @@ const create$2 = {
|
|
|
2088
2195
|
const {
|
|
2089
2196
|
config,
|
|
2090
2197
|
cwd,
|
|
2091
|
-
debugLog,
|
|
2092
2198
|
dryRun,
|
|
2093
2199
|
includeAllIssues,
|
|
2094
2200
|
outputJson,
|
|
@@ -2100,7 +2206,6 @@ const create$2 = {
|
|
|
2100
2206
|
const result = input && (await createReport(packagePaths, {
|
|
2101
2207
|
config,
|
|
2102
2208
|
cwd,
|
|
2103
|
-
debugLog,
|
|
2104
2209
|
dryRun
|
|
2105
2210
|
}));
|
|
2106
2211
|
if (result && view) {
|
|
@@ -2136,12 +2241,6 @@ async function setupCommand$g(name, description, argv, importMeta) {
|
|
|
2136
2241
|
...commonFlags,
|
|
2137
2242
|
...outputFlags,
|
|
2138
2243
|
...validationFlags,
|
|
2139
|
-
debug: {
|
|
2140
|
-
type: 'boolean',
|
|
2141
|
-
shortFlag: 'd',
|
|
2142
|
-
default: false,
|
|
2143
|
-
description: 'Output debug information'
|
|
2144
|
-
},
|
|
2145
2244
|
dryRun: {
|
|
2146
2245
|
type: 'boolean',
|
|
2147
2246
|
default: false,
|
|
@@ -2168,9 +2267,8 @@ async function setupCommand$g(name, description, argv, importMeta) {
|
|
|
2168
2267
|
default ignores from the "ignore-by-default" module.
|
|
2169
2268
|
|
|
2170
2269
|
Options
|
|
2171
|
-
${
|
|
2270
|
+
${getFlagListOutput({
|
|
2172
2271
|
all: 'Include all issues',
|
|
2173
|
-
debug: 'Output debug information',
|
|
2174
2272
|
'dry-run': 'Only output what will be done without actually doing it',
|
|
2175
2273
|
json: 'Output result as json',
|
|
2176
2274
|
markdown: 'Output result as markdown',
|
|
@@ -2200,10 +2298,9 @@ async function setupCommand$g(name, description, argv, importMeta) {
|
|
|
2200
2298
|
const {
|
|
2201
2299
|
dryRun
|
|
2202
2300
|
} = cli.flags;
|
|
2203
|
-
const debugLog = sdk.createDebugLogger(!dryRun || cli.flags['debug']);
|
|
2204
2301
|
|
|
2205
2302
|
// TODO: Allow setting a custom cwd and/or configFile path?
|
|
2206
|
-
const cwd = process.cwd();
|
|
2303
|
+
const cwd = process$1.cwd();
|
|
2207
2304
|
const absoluteConfigPath = path.join(cwd, 'socket.yml');
|
|
2208
2305
|
const config$1 = await config.readSocketConfig(absoluteConfigPath).catch(cause => {
|
|
2209
2306
|
if (cause && typeof cause === 'object' && cause instanceof config.SocketValidationError) {
|
|
@@ -2215,27 +2312,26 @@ async function setupCommand$g(name, description, argv, importMeta) {
|
|
|
2215
2312
|
errors: cause.validationErrors,
|
|
2216
2313
|
schema: cause.schema
|
|
2217
2314
|
});
|
|
2218
|
-
throw new
|
|
2315
|
+
throw new socketUrl.InputError('The socket.yml config is not valid', betterErrors.map(err => `[${err.path}] ${err.message}.${err.suggestion ? err.suggestion : ''}`).join('\n'));
|
|
2219
2316
|
} else {
|
|
2220
2317
|
throw new ponyCause.ErrorWithCause('Failed to read socket.yml config', {
|
|
2221
2318
|
cause
|
|
2222
2319
|
});
|
|
2223
2320
|
}
|
|
2224
2321
|
});
|
|
2225
|
-
const socketSdk = await
|
|
2322
|
+
const socketSdk = await socketUrl.setupSdk();
|
|
2226
2323
|
const supportedFiles = await socketSdk.getReportSupportedFiles().then(res => {
|
|
2227
|
-
if (!res.success) handleUnsuccessfulApiResponse('getReportSupportedFiles', res,
|
|
2324
|
+
if (!res.success) handleUnsuccessfulApiResponse('getReportSupportedFiles', res, new spinner.Spinner());
|
|
2228
2325
|
return res.data;
|
|
2229
2326
|
}).catch(cause => {
|
|
2230
2327
|
throw new ponyCause.ErrorWithCause('Failed getting supported files for report', {
|
|
2231
2328
|
cause
|
|
2232
2329
|
});
|
|
2233
2330
|
});
|
|
2234
|
-
const packagePaths = await pathResolve.getPackageFiles(cwd, cli.input, config$1, supportedFiles
|
|
2331
|
+
const packagePaths = await pathResolve.getPackageFiles(cwd, cli.input, config$1, supportedFiles);
|
|
2235
2332
|
return {
|
|
2236
2333
|
config: config$1,
|
|
2237
2334
|
cwd,
|
|
2238
|
-
debugLog,
|
|
2239
2335
|
dryRun,
|
|
2240
2336
|
includeAllIssues: cli.flags['all'],
|
|
2241
2337
|
outputJson: cli.flags['json'],
|
|
@@ -2248,24 +2344,23 @@ async function setupCommand$g(name, description, argv, importMeta) {
|
|
|
2248
2344
|
async function createReport(packagePaths, {
|
|
2249
2345
|
config,
|
|
2250
2346
|
cwd,
|
|
2251
|
-
debugLog,
|
|
2252
2347
|
dryRun
|
|
2253
2348
|
}) {
|
|
2254
|
-
debugLog('Uploading:', packagePaths.join(`\n${
|
|
2349
|
+
pathResolve.debugLog('Uploading:', packagePaths.join(`\n${pathResolve.logSymbols.info} Uploading: `));
|
|
2255
2350
|
if (dryRun) {
|
|
2256
2351
|
return;
|
|
2257
2352
|
}
|
|
2258
|
-
const socketSdk = await
|
|
2259
|
-
const spinner =
|
|
2353
|
+
const socketSdk = await socketUrl.setupSdk();
|
|
2354
|
+
const spinner$1 = new spinner.Spinner({
|
|
2260
2355
|
text: `Creating report with ${packagePaths.length} package files`
|
|
2261
2356
|
}).start();
|
|
2262
2357
|
const apiCall = socketSdk.createReportFromFilePaths(packagePaths, cwd, config?.issueRules);
|
|
2263
2358
|
const result = await handleApiCall(apiCall, 'creating report');
|
|
2264
2359
|
if (result.success) {
|
|
2265
|
-
spinner.success();
|
|
2360
|
+
spinner$1.success();
|
|
2266
2361
|
return result;
|
|
2267
2362
|
}
|
|
2268
|
-
handleUnsuccessfulApiResponse('createReport', result, spinner);
|
|
2363
|
+
handleUnsuccessfulApiResponse('createReport', result, spinner$1);
|
|
2269
2364
|
return undefined;
|
|
2270
2365
|
}
|
|
2271
2366
|
function formatReportCreationOutput(data, {
|
|
@@ -2276,7 +2371,7 @@ function formatReportCreationOutput(data, {
|
|
|
2276
2371
|
console.log(JSON.stringify(data, undefined, 2));
|
|
2277
2372
|
return;
|
|
2278
2373
|
}
|
|
2279
|
-
const format = new
|
|
2374
|
+
const format = new socketUrl.ColorOrMarkdown(!!outputMarkdown);
|
|
2280
2375
|
console.log(`New report: ${format.hyperlink(data.id, data.url, {
|
|
2281
2376
|
fallbackToUrl: true
|
|
2282
2377
|
})}`);
|
|
@@ -2318,13 +2413,13 @@ async function meowWithSubcommands(subcommands, options) {
|
|
|
2318
2413
|
$ ${name} <command>
|
|
2319
2414
|
|
|
2320
2415
|
Commands
|
|
2321
|
-
${
|
|
2322
|
-
...objects.toSortedObject(subcommands),
|
|
2323
|
-
...objects.toSortedObject(aliases)
|
|
2416
|
+
${getHelpListOutput({
|
|
2417
|
+
...objects.toSortedObject(Object.fromEntries(Object.entries(subcommands).filter(entry => !entry[1].hidden))),
|
|
2418
|
+
...objects.toSortedObject(Object.fromEntries(Object.entries(aliases).filter(entry => !subcommands[entry[1]?.argv[0]]?.hidden)))
|
|
2324
2419
|
}, 6)}
|
|
2325
2420
|
|
|
2326
2421
|
Options
|
|
2327
|
-
${
|
|
2422
|
+
${getFlagListOutput(flags, 6)}
|
|
2328
2423
|
|
|
2329
2424
|
Examples
|
|
2330
2425
|
$ ${name} --help
|
|
@@ -2355,8 +2450,9 @@ const report = {
|
|
|
2355
2450
|
}
|
|
2356
2451
|
};
|
|
2357
2452
|
|
|
2358
|
-
const
|
|
2359
|
-
const
|
|
2453
|
+
const HOME_DIR = os.homedir();
|
|
2454
|
+
const BASH_FILE = `${HOME_DIR}/.bashrc`;
|
|
2455
|
+
const ZSH_BASH_FILE = `${HOME_DIR}/.zshrc`;
|
|
2360
2456
|
const wrapper = {
|
|
2361
2457
|
description: 'Enable or disable the Socket npm/npx wrapper',
|
|
2362
2458
|
async run(argv, importMeta, {
|
|
@@ -2372,7 +2468,7 @@ function setupCommand$f(name, description, argv, importMeta) {
|
|
|
2372
2468
|
$ ${name} <flag>
|
|
2373
2469
|
|
|
2374
2470
|
Options
|
|
2375
|
-
${
|
|
2471
|
+
${getFlagListOutput(flags, 6)}
|
|
2376
2472
|
|
|
2377
2473
|
Examples
|
|
2378
2474
|
$ ${name} --enable
|
|
@@ -2427,21 +2523,18 @@ function setupCommand$f(name, description, argv, importMeta) {
|
|
|
2427
2523
|
console.error('There was an issue setting up the alias in your bash profile');
|
|
2428
2524
|
}
|
|
2429
2525
|
}
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2526
|
+
function addAlias(file) {
|
|
2527
|
+
return fs.appendFile(file, 'alias npm="socket npm"\nalias npx="socket npx"\n', err => {
|
|
2528
|
+
if (err) {
|
|
2529
|
+
return new Error(`There was an error setting up the alias: ${err}`);
|
|
2530
|
+
}
|
|
2531
|
+
console.log(`
|
|
2532
|
+
The alias was added to ${file}. Running 'npm install' will now be wrapped in Socket's "safe npm" 🎉
|
|
2533
|
+
If you want to disable it at any time, run \`socket wrapper --disable\`
|
|
2437
2534
|
`);
|
|
2438
|
-
const rl = readline.createInterface({
|
|
2439
|
-
input: process.stdin,
|
|
2440
|
-
output: process.stdout
|
|
2441
2535
|
});
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
const askQuestion = (rl, query) => {
|
|
2536
|
+
}
|
|
2537
|
+
function askQuestion(rl, query) {
|
|
2445
2538
|
rl.question(query, ans => {
|
|
2446
2539
|
if (ans.toLowerCase() === 'y') {
|
|
2447
2540
|
try {
|
|
@@ -2461,19 +2554,31 @@ const askQuestion = (rl, query) => {
|
|
|
2461
2554
|
rl.close();
|
|
2462
2555
|
}
|
|
2463
2556
|
});
|
|
2464
|
-
}
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
}
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2557
|
+
}
|
|
2558
|
+
function checkSocketWrapperAlreadySetup(file) {
|
|
2559
|
+
const fileContent = fs.readFileSync(file, 'utf8');
|
|
2560
|
+
const linesWithSocketAlias = fileContent.split('\n').filter(l => l === 'alias npm="socket npm"' || l === 'alias npx="socket npx"');
|
|
2561
|
+
if (linesWithSocketAlias.length) {
|
|
2562
|
+
console.log(`The Socket npm/npx wrapper is set up in your bash profile (${file}).`);
|
|
2563
|
+
return true;
|
|
2564
|
+
}
|
|
2565
|
+
return false;
|
|
2566
|
+
}
|
|
2567
|
+
function installSafeNpm(query) {
|
|
2568
|
+
console.log(`
|
|
2569
|
+
_____ _ _
|
|
2570
|
+
| __|___ ___| |_ ___| |_
|
|
2571
|
+
|__ | . | _| '_| -_| _|
|
|
2572
|
+
|_____|___|___|_,_|___|_|
|
|
2573
|
+
|
|
2473
2574
|
`);
|
|
2575
|
+
const rl = readline.createInterface({
|
|
2576
|
+
input: process$1.stdin,
|
|
2577
|
+
output: process$1.stdout
|
|
2474
2578
|
});
|
|
2475
|
-
|
|
2476
|
-
|
|
2579
|
+
return askQuestion(rl, query);
|
|
2580
|
+
}
|
|
2581
|
+
function removeAlias(file) {
|
|
2477
2582
|
return fs.readFile(file, 'utf8', function (err, data) {
|
|
2478
2583
|
if (err) {
|
|
2479
2584
|
console.error(`There was an error removing the alias: ${err}`);
|
|
@@ -2490,16 +2595,7 @@ const removeAlias = file => {
|
|
|
2490
2595
|
}
|
|
2491
2596
|
});
|
|
2492
2597
|
});
|
|
2493
|
-
}
|
|
2494
|
-
const checkSocketWrapperAlreadySetup = file => {
|
|
2495
|
-
const fileContent = fs.readFileSync(file, 'utf8');
|
|
2496
|
-
const linesWithSocketAlias = fileContent.split('\n').filter(l => l === 'alias npm="socket npm"' || l === 'alias npx="socket npx"');
|
|
2497
|
-
if (linesWithSocketAlias.length) {
|
|
2498
|
-
console.log(`The Socket npm/npx wrapper is set up in your bash profile (${file}).`);
|
|
2499
|
-
return true;
|
|
2500
|
-
}
|
|
2501
|
-
return false;
|
|
2502
|
-
};
|
|
2598
|
+
}
|
|
2503
2599
|
|
|
2504
2600
|
const create$1 = {
|
|
2505
2601
|
description: 'Create a scan',
|
|
@@ -2509,15 +2605,15 @@ const create$1 = {
|
|
|
2509
2605
|
const name = `${parentName} create`;
|
|
2510
2606
|
const input = await setupCommand$e(name, create$1.description, argv, importMeta);
|
|
2511
2607
|
if (input) {
|
|
2512
|
-
const apiKey =
|
|
2608
|
+
const apiKey = socketUrl.getDefaultToken();
|
|
2513
2609
|
if (!apiKey) {
|
|
2514
|
-
throw new
|
|
2610
|
+
throw new socketUrl.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
2515
2611
|
}
|
|
2516
2612
|
const spinnerText = 'Creating a scan... \n';
|
|
2517
|
-
const spinner =
|
|
2613
|
+
const spinner$1 = new spinner.Spinner({
|
|
2518
2614
|
text: spinnerText
|
|
2519
2615
|
}).start();
|
|
2520
|
-
await createFullScan(input, spinner, apiKey);
|
|
2616
|
+
await createFullScan(input, spinner$1, apiKey);
|
|
2521
2617
|
}
|
|
2522
2618
|
}
|
|
2523
2619
|
};
|
|
@@ -2588,7 +2684,7 @@ async function setupCommand$e(name, description, argv, importMeta) {
|
|
|
2588
2684
|
$ ${name} [...options]
|
|
2589
2685
|
|
|
2590
2686
|
Options
|
|
2591
|
-
${
|
|
2687
|
+
${getFlagListOutput(flags, 6)}
|
|
2592
2688
|
|
|
2593
2689
|
Examples
|
|
2594
2690
|
$ ${name} --org=FakeOrg --repo=test-repo --branch=main ./package.json
|
|
@@ -2609,10 +2705,10 @@ async function setupCommand$e(name, description, argv, importMeta) {
|
|
|
2609
2705
|
const {
|
|
2610
2706
|
0: orgSlug = ''
|
|
2611
2707
|
} = cli.input;
|
|
2612
|
-
const cwd = process.cwd();
|
|
2613
|
-
const socketSdk = await
|
|
2708
|
+
const cwd = process$1.cwd();
|
|
2709
|
+
const socketSdk = await socketUrl.setupSdk();
|
|
2614
2710
|
const supportedFiles = await socketSdk.getReportSupportedFiles().then(res => {
|
|
2615
|
-
if (!res.success) handleUnsuccessfulApiResponse('getReportSupportedFiles', res,
|
|
2711
|
+
if (!res.success) handleUnsuccessfulApiResponse('getReportSupportedFiles', res, new spinner.Spinner());
|
|
2616
2712
|
return res.data;
|
|
2617
2713
|
}).catch(/** @type {(cause: Error) => never} */
|
|
2618
2714
|
cause => {
|
|
@@ -2620,8 +2716,7 @@ async function setupCommand$e(name, description, argv, importMeta) {
|
|
|
2620
2716
|
cause
|
|
2621
2717
|
});
|
|
2622
2718
|
});
|
|
2623
|
-
const
|
|
2624
|
-
const packagePaths = await pathResolve.getPackageFilesFullScans(cwd, cli.input, supportedFiles, debugLog);
|
|
2719
|
+
const packagePaths = await pathResolve.getPackageFilesFullScans(cwd, cli.input, supportedFiles);
|
|
2625
2720
|
const {
|
|
2626
2721
|
branch: branchName,
|
|
2627
2722
|
repo: repoName
|
|
@@ -2652,7 +2747,7 @@ async function setupCommand$e(name, description, argv, importMeta) {
|
|
|
2652
2747
|
};
|
|
2653
2748
|
}
|
|
2654
2749
|
async function createFullScan(input, spinner, apiKey) {
|
|
2655
|
-
const socketSdk = await
|
|
2750
|
+
const socketSdk = await socketUrl.setupSdk(apiKey);
|
|
2656
2751
|
const {
|
|
2657
2752
|
branchName,
|
|
2658
2753
|
commitMessage,
|
|
@@ -2697,15 +2792,15 @@ const del$1 = {
|
|
|
2697
2792
|
const name = `${parentName} del`;
|
|
2698
2793
|
const input = setupCommand$d(name, del$1.description, argv, importMeta);
|
|
2699
2794
|
if (input) {
|
|
2700
|
-
const apiKey =
|
|
2795
|
+
const apiKey = socketUrl.getDefaultToken();
|
|
2701
2796
|
if (!apiKey) {
|
|
2702
|
-
throw new
|
|
2797
|
+
throw new socketUrl.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
2703
2798
|
}
|
|
2704
2799
|
const spinnerText = 'Deleting scan...';
|
|
2705
|
-
const spinner =
|
|
2800
|
+
const spinner$1 = new spinner.Spinner({
|
|
2706
2801
|
text: spinnerText
|
|
2707
2802
|
}).start();
|
|
2708
|
-
await deleteOrgFullScan(input.orgSlug, input.fullScanId, spinner, apiKey);
|
|
2803
|
+
await deleteOrgFullScan(input.orgSlug, input.fullScanId, spinner$1, apiKey);
|
|
2709
2804
|
}
|
|
2710
2805
|
}
|
|
2711
2806
|
};
|
|
@@ -2722,7 +2817,7 @@ function setupCommand$d(name, description, argv, importMeta) {
|
|
|
2722
2817
|
$ ${name} <org slug> <scan ID>
|
|
2723
2818
|
|
|
2724
2819
|
Options
|
|
2725
|
-
${
|
|
2820
|
+
${getFlagListOutput(flags, 6)}
|
|
2726
2821
|
|
|
2727
2822
|
Examples
|
|
2728
2823
|
$ ${name} FakeOrg 000aaaa1-0000-0a0a-00a0-00a0000000a0
|
|
@@ -2753,7 +2848,7 @@ function setupCommand$d(name, description, argv, importMeta) {
|
|
|
2753
2848
|
};
|
|
2754
2849
|
}
|
|
2755
2850
|
async function deleteOrgFullScan(orgSlug, fullScanId, spinner, apiKey) {
|
|
2756
|
-
const socketSdk = await
|
|
2851
|
+
const socketSdk = await socketUrl.setupSdk(apiKey);
|
|
2757
2852
|
const result = await handleApiCall(socketSdk.deleteOrgFullScan(orgSlug, fullScanId), 'Deleting scan');
|
|
2758
2853
|
if (result.success) {
|
|
2759
2854
|
spinner.success('Scan deleted successfully');
|
|
@@ -2762,6 +2857,7 @@ async function deleteOrgFullScan(orgSlug, fullScanId, spinner, apiKey) {
|
|
|
2762
2857
|
}
|
|
2763
2858
|
}
|
|
2764
2859
|
|
|
2860
|
+
// @ts-ignore
|
|
2765
2861
|
const list$1 = {
|
|
2766
2862
|
description: 'List scans for an organization',
|
|
2767
2863
|
async run(argv, importMeta, {
|
|
@@ -2770,15 +2866,15 @@ const list$1 = {
|
|
|
2770
2866
|
const name = `${parentName} list`;
|
|
2771
2867
|
const input = setupCommand$c(name, list$1.description, argv, importMeta);
|
|
2772
2868
|
if (input) {
|
|
2773
|
-
const apiKey =
|
|
2869
|
+
const apiKey = socketUrl.getDefaultToken();
|
|
2774
2870
|
if (!apiKey) {
|
|
2775
|
-
throw new
|
|
2871
|
+
throw new socketUrl.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
2776
2872
|
}
|
|
2777
2873
|
const spinnerText = 'Listing scans... \n';
|
|
2778
|
-
const spinner =
|
|
2874
|
+
const spinner$1 = new spinner.Spinner({
|
|
2779
2875
|
text: spinnerText
|
|
2780
2876
|
}).start();
|
|
2781
|
-
await listOrgFullScan(input.orgSlug, input, spinner, apiKey);
|
|
2877
|
+
await listOrgFullScan(input.orgSlug, input, spinner$1, apiKey);
|
|
2782
2878
|
}
|
|
2783
2879
|
}
|
|
2784
2880
|
};
|
|
@@ -2834,7 +2930,7 @@ function setupCommand$c(name, description, argv, importMeta) {
|
|
|
2834
2930
|
$ ${name} <org slug>
|
|
2835
2931
|
|
|
2836
2932
|
Options
|
|
2837
|
-
${
|
|
2933
|
+
${getFlagListOutput(flags, 6)}
|
|
2838
2934
|
|
|
2839
2935
|
Examples
|
|
2840
2936
|
$ ${name} FakeOrg
|
|
@@ -2869,7 +2965,7 @@ function setupCommand$c(name, description, argv, importMeta) {
|
|
|
2869
2965
|
};
|
|
2870
2966
|
}
|
|
2871
2967
|
async function listOrgFullScan(orgSlug, input, spinner, apiKey) {
|
|
2872
|
-
const socketSdk = await
|
|
2968
|
+
const socketSdk = await socketUrl.setupSdk(apiKey);
|
|
2873
2969
|
const result = await handleApiCall(socketSdk.getOrgFullScanList(orgSlug, input), 'Listing scans');
|
|
2874
2970
|
if (!result.success) {
|
|
2875
2971
|
handleUnsuccessfulApiResponse('getOrgFullScanList', result, spinner);
|
|
@@ -2914,15 +3010,15 @@ const metadata = {
|
|
|
2914
3010
|
const name = `${parentName} metadata`;
|
|
2915
3011
|
const input = setupCommand$b(name, metadata.description, argv, importMeta);
|
|
2916
3012
|
if (input) {
|
|
2917
|
-
const apiKey =
|
|
3013
|
+
const apiKey = socketUrl.getDefaultToken();
|
|
2918
3014
|
if (!apiKey) {
|
|
2919
|
-
throw new
|
|
3015
|
+
throw new socketUrl.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
2920
3016
|
}
|
|
2921
3017
|
const spinnerText = "Getting scan's metadata... \n";
|
|
2922
|
-
const spinner =
|
|
3018
|
+
const spinner$1 = new spinner.Spinner({
|
|
2923
3019
|
text: spinnerText
|
|
2924
3020
|
}).start();
|
|
2925
|
-
await getOrgScanMetadata(input.orgSlug, input.scanID, spinner, apiKey);
|
|
3021
|
+
await getOrgScanMetadata(input.orgSlug, input.scanID, spinner$1, apiKey);
|
|
2926
3022
|
}
|
|
2927
3023
|
}
|
|
2928
3024
|
};
|
|
@@ -2939,7 +3035,7 @@ function setupCommand$b(name, description, argv, importMeta) {
|
|
|
2939
3035
|
$ ${name} <org slug> <scan id>
|
|
2940
3036
|
|
|
2941
3037
|
Options
|
|
2942
|
-
${
|
|
3038
|
+
${getFlagListOutput(flags, 6)}
|
|
2943
3039
|
|
|
2944
3040
|
Examples
|
|
2945
3041
|
$ ${name} FakeOrg 000aaaa1-0000-0a0a-00a0-00a0000000a0
|
|
@@ -2970,7 +3066,7 @@ function setupCommand$b(name, description, argv, importMeta) {
|
|
|
2970
3066
|
};
|
|
2971
3067
|
}
|
|
2972
3068
|
async function getOrgScanMetadata(orgSlug, scanId, spinner, apiKey) {
|
|
2973
|
-
const socketSdk = await
|
|
3069
|
+
const socketSdk = await socketUrl.setupSdk(apiKey);
|
|
2974
3070
|
const result = await handleApiCall(socketSdk.getOrgFullScanMetadata(orgSlug, scanId), 'Listing scans');
|
|
2975
3071
|
if (!result.success) {
|
|
2976
3072
|
handleUnsuccessfulApiResponse('getOrgFullScanMetadata', result, spinner);
|
|
@@ -2988,18 +3084,18 @@ const stream = {
|
|
|
2988
3084
|
const name = `${parentName} stream`;
|
|
2989
3085
|
const input = setupCommand$a(name, stream.description, argv, importMeta);
|
|
2990
3086
|
if (input) {
|
|
2991
|
-
const apiKey =
|
|
3087
|
+
const apiKey = socketUrl.getDefaultToken();
|
|
2992
3088
|
if (!apiKey) {
|
|
2993
|
-
throw new
|
|
3089
|
+
throw new socketUrl.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
2994
3090
|
}
|
|
2995
|
-
const spinner =
|
|
3091
|
+
const spinner$1 = new spinner.Spinner({
|
|
2996
3092
|
text: 'Streaming scan...'
|
|
2997
3093
|
}).start();
|
|
2998
3094
|
const result = await getOrgFullScan(input.orgSlug, input.fullScanId, input.file, apiKey);
|
|
2999
3095
|
if (result?.success) {
|
|
3000
|
-
spinner.stop(input.file ? `Full scan details written to ${input.file}` : '');
|
|
3096
|
+
spinner$1.stop(input.file ? `Full scan details written to ${input.file}` : '');
|
|
3001
3097
|
} else {
|
|
3002
|
-
handleUnsuccessfulApiResponse('getOrgFullScan', result, spinner);
|
|
3098
|
+
handleUnsuccessfulApiResponse('getOrgFullScan', result, spinner$1);
|
|
3003
3099
|
}
|
|
3004
3100
|
}
|
|
3005
3101
|
}
|
|
@@ -3017,7 +3113,7 @@ function setupCommand$a(name, description, argv, importMeta) {
|
|
|
3017
3113
|
$ ${name} <org slug> <scan ID> <path to output file>
|
|
3018
3114
|
|
|
3019
3115
|
Options
|
|
3020
|
-
${
|
|
3116
|
+
${getFlagListOutput(flags, 6)}
|
|
3021
3117
|
|
|
3022
3118
|
Examples
|
|
3023
3119
|
$ ${name} FakeOrg 000aaaa1-0000-0a0a-00a0-00a0000000a0 ./stream.txt
|
|
@@ -3050,7 +3146,7 @@ function setupCommand$a(name, description, argv, importMeta) {
|
|
|
3050
3146
|
};
|
|
3051
3147
|
}
|
|
3052
3148
|
async function getOrgFullScan(orgSlug, fullScanId, file, apiKey) {
|
|
3053
|
-
const socketSdk = await
|
|
3149
|
+
const socketSdk = await socketUrl.setupSdk(apiKey);
|
|
3054
3150
|
return await handleApiCall(socketSdk.getOrgFullScan(orgSlug, fullScanId, file), 'Streaming a scan');
|
|
3055
3151
|
}
|
|
3056
3152
|
|
|
@@ -3083,14 +3179,14 @@ const auditLog = {
|
|
|
3083
3179
|
const name = parentName + ' audit-log';
|
|
3084
3180
|
const input = setupCommand$9(name, auditLog.description, argv, importMeta);
|
|
3085
3181
|
if (input) {
|
|
3086
|
-
const apiKey =
|
|
3182
|
+
const apiKey = socketUrl.getDefaultToken();
|
|
3087
3183
|
if (!apiKey) {
|
|
3088
|
-
throw new
|
|
3184
|
+
throw new socketUrl.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
3089
3185
|
}
|
|
3090
|
-
const spinner =
|
|
3186
|
+
const spinner$1 = new spinner.Spinner({
|
|
3091
3187
|
text: `Looking up audit log for ${input.orgSlug}\n`
|
|
3092
3188
|
}).start();
|
|
3093
|
-
await fetchOrgAuditLog(input.orgSlug, input, spinner, apiKey);
|
|
3189
|
+
await fetchOrgAuditLog(input.orgSlug, input, spinner$1, apiKey);
|
|
3094
3190
|
}
|
|
3095
3191
|
}
|
|
3096
3192
|
};
|
|
@@ -3128,7 +3224,7 @@ function setupCommand$9(name, description, argv, importMeta) {
|
|
|
3128
3224
|
$ ${name} <org slug>
|
|
3129
3225
|
|
|
3130
3226
|
Options
|
|
3131
|
-
${
|
|
3227
|
+
${getFlagListOutput(flags, 6)}
|
|
3132
3228
|
|
|
3133
3229
|
Examples
|
|
3134
3230
|
$ ${name} FakeOrg
|
|
@@ -3167,7 +3263,7 @@ function setupCommand$9(name, description, argv, importMeta) {
|
|
|
3167
3263
|
};
|
|
3168
3264
|
}
|
|
3169
3265
|
async function fetchOrgAuditLog(orgSlug, input, spinner, apiKey) {
|
|
3170
|
-
const socketSdk = await
|
|
3266
|
+
const socketSdk = await socketUrl.setupSdk(apiKey);
|
|
3171
3267
|
const result = await handleApiCall(socketSdk.getAuditLogEvents(orgSlug, input), `Looking up audit log for ${orgSlug}\n`);
|
|
3172
3268
|
if (!result.success) {
|
|
3173
3269
|
handleUnsuccessfulApiResponse('getAuditLogEvents', result, spinner);
|
|
@@ -3207,15 +3303,15 @@ const create = {
|
|
|
3207
3303
|
const name = `${parentName} create`;
|
|
3208
3304
|
const input = setupCommand$8(name, create.description, argv, importMeta);
|
|
3209
3305
|
if (input) {
|
|
3210
|
-
const apiKey =
|
|
3306
|
+
const apiKey = socketUrl.getDefaultToken();
|
|
3211
3307
|
if (!apiKey) {
|
|
3212
|
-
throw new
|
|
3308
|
+
throw new socketUrl.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
3213
3309
|
}
|
|
3214
3310
|
const spinnerText = 'Creating repository... \n';
|
|
3215
|
-
const spinner =
|
|
3311
|
+
const spinner$1 = new spinner.Spinner({
|
|
3216
3312
|
text: spinnerText
|
|
3217
3313
|
}).start();
|
|
3218
|
-
await createRepo(input.orgSlug, input, spinner, apiKey);
|
|
3314
|
+
await createRepo(input.orgSlug, input, spinner$1, apiKey);
|
|
3219
3315
|
}
|
|
3220
3316
|
}
|
|
3221
3317
|
};
|
|
@@ -3265,7 +3361,7 @@ function setupCommand$8(name, description, argv, importMeta) {
|
|
|
3265
3361
|
$ ${name} <org slug>
|
|
3266
3362
|
|
|
3267
3363
|
Options
|
|
3268
|
-
${
|
|
3364
|
+
${getFlagListOutput(flags, 6)}
|
|
3269
3365
|
|
|
3270
3366
|
Examples
|
|
3271
3367
|
$ ${name} FakeOrg --repoName=test-repo
|
|
@@ -3303,7 +3399,7 @@ function setupCommand$8(name, description, argv, importMeta) {
|
|
|
3303
3399
|
};
|
|
3304
3400
|
}
|
|
3305
3401
|
async function createRepo(orgSlug, input, spinner, apiKey) {
|
|
3306
|
-
const socketSdk = await
|
|
3402
|
+
const socketSdk = await socketUrl.setupSdk(apiKey);
|
|
3307
3403
|
const result = await handleApiCall(socketSdk.createOrgRepo(orgSlug, input), 'creating repository');
|
|
3308
3404
|
if (result.success) {
|
|
3309
3405
|
spinner.success('Repository created successfully');
|
|
@@ -3320,15 +3416,15 @@ const del = {
|
|
|
3320
3416
|
const name = `${parentName} del`;
|
|
3321
3417
|
const input = setupCommand$7(name, del.description, argv, importMeta);
|
|
3322
3418
|
if (input) {
|
|
3323
|
-
const apiKey =
|
|
3419
|
+
const apiKey = socketUrl.getDefaultToken();
|
|
3324
3420
|
if (!apiKey) {
|
|
3325
|
-
throw new
|
|
3421
|
+
throw new socketUrl.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
3326
3422
|
}
|
|
3327
3423
|
const spinnerText = 'Deleting repository... \n';
|
|
3328
|
-
const spinner =
|
|
3424
|
+
const spinner$1 = new spinner.Spinner({
|
|
3329
3425
|
text: spinnerText
|
|
3330
3426
|
}).start();
|
|
3331
|
-
await deleteRepository(input.orgSlug, input.repoName, spinner, apiKey);
|
|
3427
|
+
await deleteRepository(input.orgSlug, input.repoName, spinner$1, apiKey);
|
|
3332
3428
|
}
|
|
3333
3429
|
}
|
|
3334
3430
|
};
|
|
@@ -3366,7 +3462,7 @@ function setupCommand$7(name, description, argv, importMeta) {
|
|
|
3366
3462
|
};
|
|
3367
3463
|
}
|
|
3368
3464
|
async function deleteRepository(orgSlug, repoName, spinner, apiKey) {
|
|
3369
|
-
const socketSdk = await
|
|
3465
|
+
const socketSdk = await socketUrl.setupSdk(apiKey);
|
|
3370
3466
|
const result = await handleApiCall(socketSdk.deleteOrgRepo(orgSlug, repoName), 'deleting repository');
|
|
3371
3467
|
if (result.success) {
|
|
3372
3468
|
spinner.success('Repository deleted successfully');
|
|
@@ -3375,6 +3471,7 @@ async function deleteRepository(orgSlug, repoName, spinner, apiKey) {
|
|
|
3375
3471
|
}
|
|
3376
3472
|
}
|
|
3377
3473
|
|
|
3474
|
+
// @ts-ignore
|
|
3378
3475
|
const list = {
|
|
3379
3476
|
description: 'List repositories in an organization',
|
|
3380
3477
|
async run(argv, importMeta, {
|
|
@@ -3383,15 +3480,15 @@ const list = {
|
|
|
3383
3480
|
const name = `${parentName} list`;
|
|
3384
3481
|
const input = setupCommand$6(name, list.description, argv, importMeta);
|
|
3385
3482
|
if (input) {
|
|
3386
|
-
const apiKey =
|
|
3483
|
+
const apiKey = socketUrl.getDefaultToken();
|
|
3387
3484
|
if (!apiKey) {
|
|
3388
|
-
throw new
|
|
3485
|
+
throw new socketUrl.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
3389
3486
|
}
|
|
3390
3487
|
const spinnerText = 'Listing repositories... \n';
|
|
3391
|
-
const spinner =
|
|
3488
|
+
const spinner$1 = new spinner.Spinner({
|
|
3392
3489
|
text: spinnerText
|
|
3393
3490
|
}).start();
|
|
3394
|
-
await listOrgRepos(input.orgSlug, input, spinner, apiKey);
|
|
3491
|
+
await listOrgRepos(input.orgSlug, input, spinner$1, apiKey);
|
|
3395
3492
|
}
|
|
3396
3493
|
}
|
|
3397
3494
|
};
|
|
@@ -3434,7 +3531,7 @@ function setupCommand$6(name, description, argv, importMeta) {
|
|
|
3434
3531
|
$ ${name} <org slug>
|
|
3435
3532
|
|
|
3436
3533
|
Options
|
|
3437
|
-
${
|
|
3534
|
+
${getFlagListOutput(flags, 6)}
|
|
3438
3535
|
|
|
3439
3536
|
Examples
|
|
3440
3537
|
$ ${name} FakeOrg
|
|
@@ -3467,7 +3564,7 @@ function setupCommand$6(name, description, argv, importMeta) {
|
|
|
3467
3564
|
};
|
|
3468
3565
|
}
|
|
3469
3566
|
async function listOrgRepos(orgSlug, input, spinner, apiKey) {
|
|
3470
|
-
const socketSdk = await
|
|
3567
|
+
const socketSdk = await socketUrl.setupSdk(apiKey);
|
|
3471
3568
|
const result = await handleApiCall(socketSdk.getOrgRepoList(orgSlug, input), 'listing repositories');
|
|
3472
3569
|
if (!result.success) {
|
|
3473
3570
|
handleUnsuccessfulApiResponse('getOrgRepoList', result, spinner);
|
|
@@ -3502,15 +3599,15 @@ const update = {
|
|
|
3502
3599
|
const name = `${parentName} update`;
|
|
3503
3600
|
const input = setupCommand$5(name, update.description, argv, importMeta);
|
|
3504
3601
|
if (input) {
|
|
3505
|
-
const apiKey =
|
|
3602
|
+
const apiKey = socketUrl.getDefaultToken();
|
|
3506
3603
|
if (!apiKey) {
|
|
3507
|
-
throw new
|
|
3604
|
+
throw new socketUrl.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
3508
3605
|
}
|
|
3509
3606
|
const spinnerText = 'Updating repository... \n';
|
|
3510
|
-
const spinner =
|
|
3607
|
+
const spinner$1 = new spinner.Spinner({
|
|
3511
3608
|
text: spinnerText
|
|
3512
3609
|
}).start();
|
|
3513
|
-
await updateRepository(input.orgSlug, input, spinner, apiKey);
|
|
3610
|
+
await updateRepository(input.orgSlug, input, spinner$1, apiKey);
|
|
3514
3611
|
}
|
|
3515
3612
|
}
|
|
3516
3613
|
};
|
|
@@ -3560,7 +3657,7 @@ function setupCommand$5(name, description, argv, importMeta) {
|
|
|
3560
3657
|
$ ${name} <org slug>
|
|
3561
3658
|
|
|
3562
3659
|
Options
|
|
3563
|
-
${
|
|
3660
|
+
${getFlagListOutput(flags, 6)}
|
|
3564
3661
|
|
|
3565
3662
|
Examples
|
|
3566
3663
|
$ ${name} FakeOrg
|
|
@@ -3598,7 +3695,7 @@ function setupCommand$5(name, description, argv, importMeta) {
|
|
|
3598
3695
|
};
|
|
3599
3696
|
}
|
|
3600
3697
|
async function updateRepository(orgSlug, input, spinner, apiKey) {
|
|
3601
|
-
const socketSdk = await
|
|
3698
|
+
const socketSdk = await socketUrl.setupSdk(apiKey);
|
|
3602
3699
|
const result = await handleApiCall(socketSdk.updateOrgRepo(orgSlug, input.name, input), 'updating repository');
|
|
3603
3700
|
if (result.success) {
|
|
3604
3701
|
spinner.success('Repository updated successfully');
|
|
@@ -3607,6 +3704,7 @@ async function updateRepository(orgSlug, input, spinner, apiKey) {
|
|
|
3607
3704
|
}
|
|
3608
3705
|
}
|
|
3609
3706
|
|
|
3707
|
+
// @ts-ignore
|
|
3610
3708
|
const view = {
|
|
3611
3709
|
description: 'View repositories in an organization',
|
|
3612
3710
|
async run(argv, importMeta, {
|
|
@@ -3615,15 +3713,15 @@ const view = {
|
|
|
3615
3713
|
const name = `${parentName} view`;
|
|
3616
3714
|
const input = setupCommand$4(name, view.description, argv, importMeta);
|
|
3617
3715
|
if (input) {
|
|
3618
|
-
const apiKey =
|
|
3716
|
+
const apiKey = socketUrl.getDefaultToken();
|
|
3619
3717
|
if (!apiKey) {
|
|
3620
|
-
throw new
|
|
3718
|
+
throw new socketUrl.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
3621
3719
|
}
|
|
3622
3720
|
const spinnerText = 'Fetching repository... \n';
|
|
3623
|
-
const spinner =
|
|
3721
|
+
const spinner$1 = new spinner.Spinner({
|
|
3624
3722
|
text: spinnerText
|
|
3625
3723
|
}).start();
|
|
3626
|
-
await viewRepository(input.orgSlug, input.repositoryName, spinner, apiKey);
|
|
3724
|
+
await viewRepository(input.orgSlug, input.repositoryName, spinner$1, apiKey);
|
|
3627
3725
|
}
|
|
3628
3726
|
}
|
|
3629
3727
|
};
|
|
@@ -3640,7 +3738,7 @@ function setupCommand$4(name, description, argv, importMeta) {
|
|
|
3640
3738
|
$ ${name} <org slug>
|
|
3641
3739
|
|
|
3642
3740
|
Options
|
|
3643
|
-
${
|
|
3741
|
+
${getFlagListOutput(flags, 6)}
|
|
3644
3742
|
|
|
3645
3743
|
Examples
|
|
3646
3744
|
$ ${name} FakeOrg
|
|
@@ -3671,7 +3769,7 @@ function setupCommand$4(name, description, argv, importMeta) {
|
|
|
3671
3769
|
};
|
|
3672
3770
|
}
|
|
3673
3771
|
async function viewRepository(orgSlug, repoName, spinner, apiKey) {
|
|
3674
|
-
const socketSdk = await
|
|
3772
|
+
const socketSdk = await socketUrl.setupSdk(apiKey);
|
|
3675
3773
|
const result = await handleApiCall(socketSdk.getOrgRepo(orgSlug, repoName), 'fetching repository');
|
|
3676
3774
|
if (!result.success) {
|
|
3677
3775
|
handleUnsuccessfulApiResponse('getOrgRepo', result, spinner);
|
|
@@ -3725,6 +3823,7 @@ const repo = {
|
|
|
3725
3823
|
}
|
|
3726
3824
|
};
|
|
3727
3825
|
|
|
3826
|
+
// @ts-ignore
|
|
3728
3827
|
const dependencies = {
|
|
3729
3828
|
description: 'Search for any dependency that is being used in your organization',
|
|
3730
3829
|
async run(argv, importMeta, {
|
|
@@ -3765,7 +3864,7 @@ function setupCommand$3(name, description, argv, importMeta) {
|
|
|
3765
3864
|
$ ${name}
|
|
3766
3865
|
|
|
3767
3866
|
Options
|
|
3768
|
-
${
|
|
3867
|
+
${getFlagListOutput(flags, 6)}
|
|
3769
3868
|
|
|
3770
3869
|
Examples
|
|
3771
3870
|
$ ${name}
|
|
@@ -3793,23 +3892,23 @@ async function searchDeps({
|
|
|
3793
3892
|
offset,
|
|
3794
3893
|
outputJson
|
|
3795
3894
|
}) {
|
|
3796
|
-
const apiKey =
|
|
3895
|
+
const apiKey = socketUrl.getDefaultToken();
|
|
3797
3896
|
if (!apiKey) {
|
|
3798
|
-
throw new
|
|
3897
|
+
throw new socketUrl.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
3799
3898
|
}
|
|
3800
|
-
const spinner =
|
|
3899
|
+
const spinner$1 = new spinner.Spinner({
|
|
3801
3900
|
text: 'Searching dependencies...'
|
|
3802
3901
|
}).start();
|
|
3803
|
-
const socketSdk = await
|
|
3902
|
+
const socketSdk = await socketUrl.setupSdk(apiKey);
|
|
3804
3903
|
const result = await handleApiCall(socketSdk.searchDependencies({
|
|
3805
3904
|
limit,
|
|
3806
3905
|
offset
|
|
3807
3906
|
}), 'Searching dependencies');
|
|
3808
3907
|
if (!result.success) {
|
|
3809
|
-
handleUnsuccessfulApiResponse('searchDependencies', result, spinner);
|
|
3908
|
+
handleUnsuccessfulApiResponse('searchDependencies', result, spinner$1);
|
|
3810
3909
|
return;
|
|
3811
3910
|
}
|
|
3812
|
-
spinner.stop('Organization dependencies:');
|
|
3911
|
+
spinner$1.stop('Organization dependencies:');
|
|
3813
3912
|
if (outputJson) {
|
|
3814
3913
|
console.log(result.data);
|
|
3815
3914
|
return;
|
|
@@ -3850,18 +3949,18 @@ const analytics = {
|
|
|
3850
3949
|
const name = parentName + ' analytics';
|
|
3851
3950
|
const input = setupCommand$2(name, analytics.description, argv, importMeta);
|
|
3852
3951
|
if (input) {
|
|
3853
|
-
const apiKey =
|
|
3952
|
+
const apiKey = socketUrl.getDefaultToken();
|
|
3854
3953
|
if (!apiKey) {
|
|
3855
|
-
throw new
|
|
3954
|
+
throw new socketUrl.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
3856
3955
|
}
|
|
3857
|
-
const spinner =
|
|
3956
|
+
const spinner$1 = new spinner.Spinner({
|
|
3858
3957
|
text: 'Fetching analytics data'
|
|
3859
3958
|
}).start();
|
|
3860
3959
|
if (input.scope === 'org') {
|
|
3861
|
-
await fetchOrgAnalyticsData(input.time, spinner, apiKey, input.outputJson, input.file);
|
|
3960
|
+
await fetchOrgAnalyticsData(input.time, spinner$1, apiKey, input.outputJson, input.file);
|
|
3862
3961
|
} else {
|
|
3863
3962
|
if (input.repo) {
|
|
3864
|
-
await fetchRepoAnalyticsData(input.repo, input.time, spinner, apiKey, input.outputJson, input.file);
|
|
3963
|
+
await fetchRepoAnalyticsData(input.repo, input.time, spinner$1, apiKey, input.outputJson, input.file);
|
|
3865
3964
|
}
|
|
3866
3965
|
}
|
|
3867
3966
|
}
|
|
@@ -3907,7 +4006,7 @@ function setupCommand$2(name, description, argv, importMeta) {
|
|
|
3907
4006
|
$ ${name} --scope=<scope> --time=<time filter>
|
|
3908
4007
|
|
|
3909
4008
|
Options
|
|
3910
|
-
${
|
|
4009
|
+
${getFlagListOutput(flags, 6)}
|
|
3911
4010
|
|
|
3912
4011
|
Examples
|
|
3913
4012
|
$ ${name} --scope=org --time=7
|
|
@@ -3925,10 +4024,10 @@ function setupCommand$2(name, description, argv, importMeta) {
|
|
|
3925
4024
|
time
|
|
3926
4025
|
} = cli.flags;
|
|
3927
4026
|
if (scope !== 'org' && scope !== 'repo') {
|
|
3928
|
-
throw new
|
|
4027
|
+
throw new socketUrl.InputError("The scope must either be 'org' or 'repo'");
|
|
3929
4028
|
}
|
|
3930
4029
|
if (time !== 7 && time !== 30 && time !== 90) {
|
|
3931
|
-
throw new
|
|
4030
|
+
throw new socketUrl.InputError('The time filter must either be 7, 30 or 90');
|
|
3932
4031
|
}
|
|
3933
4032
|
let showHelp = cli.flags['help'];
|
|
3934
4033
|
if (scope === 'repo' && !repo) {
|
|
@@ -3949,7 +4048,7 @@ function setupCommand$2(name, description, argv, importMeta) {
|
|
|
3949
4048
|
}
|
|
3950
4049
|
const METRICS = ['total_critical_alerts', 'total_high_alerts', 'total_medium_alerts', 'total_low_alerts', 'total_critical_added', 'total_medium_added', 'total_low_added', 'total_high_added', 'total_critical_prevented', 'total_high_prevented', 'total_medium_prevented', 'total_low_prevented'];
|
|
3951
4050
|
async function fetchOrgAnalyticsData(time, spinner, apiKey, outputJson, filePath) {
|
|
3952
|
-
const socketSdk = await
|
|
4051
|
+
const socketSdk = await socketUrl.setupSdk(apiKey);
|
|
3953
4052
|
const result = await handleApiCall(socketSdk.getOrgAnalytics(time.toString()), 'fetching analytics data');
|
|
3954
4053
|
if (result.success === false) {
|
|
3955
4054
|
return handleUnsuccessfulApiResponse('getOrgAnalytics', result, spinner);
|
|
@@ -4062,7 +4161,7 @@ const formatData = (data, scope) => {
|
|
|
4062
4161
|
};
|
|
4063
4162
|
};
|
|
4064
4163
|
async function fetchRepoAnalyticsData(repo, time, spinner, apiKey, outputJson, filePath) {
|
|
4065
|
-
const socketSdk = await
|
|
4164
|
+
const socketSdk = await socketUrl.setupSdk(apiKey);
|
|
4066
4165
|
const result = await handleApiCall(socketSdk.getRepoAnalytics(repo, time.toString()), 'fetching analytics data');
|
|
4067
4166
|
if (result.success === false) {
|
|
4068
4167
|
return handleUnsuccessfulApiResponse('getRepoAnalytics', result, spinner);
|
|
@@ -4150,15 +4249,15 @@ const get = {
|
|
|
4150
4249
|
const name = `${parentName} get`;
|
|
4151
4250
|
const input = setupCommand$1(name, get.description, argv, importMeta);
|
|
4152
4251
|
if (input) {
|
|
4153
|
-
const apiKey =
|
|
4252
|
+
const apiKey = socketUrl.getDefaultToken();
|
|
4154
4253
|
if (!apiKey) {
|
|
4155
|
-
throw new
|
|
4254
|
+
throw new socketUrl.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
4156
4255
|
}
|
|
4157
4256
|
const spinnerText = 'Getting diff scan... \n';
|
|
4158
|
-
const spinner =
|
|
4257
|
+
const spinner$1 = new spinner.Spinner({
|
|
4159
4258
|
text: spinnerText
|
|
4160
4259
|
}).start();
|
|
4161
|
-
await getDiffScan(input, spinner, apiKey);
|
|
4260
|
+
await getDiffScan(input, spinner$1, apiKey);
|
|
4162
4261
|
}
|
|
4163
4262
|
}
|
|
4164
4263
|
};
|
|
@@ -4202,7 +4301,7 @@ function setupCommand$1(name, description, argv, importMeta) {
|
|
|
4202
4301
|
$ ${name} <org slug> --before=<before> --after=<after>
|
|
4203
4302
|
|
|
4204
4303
|
Options
|
|
4205
|
-
${
|
|
4304
|
+
${getFlagListOutput(flags, 6)}
|
|
4206
4305
|
|
|
4207
4306
|
Examples
|
|
4208
4307
|
$ ${name} FakeCorp --before=aaa0aa0a-aaaa-0000-0a0a-0000000a00a0 --after=aaa1aa1a-aaaa-1111-1a1a-1111111a11a1
|
|
@@ -4293,7 +4392,6 @@ const diffScan = {
|
|
|
4293
4392
|
}
|
|
4294
4393
|
};
|
|
4295
4394
|
|
|
4296
|
-
// @ts-ignore
|
|
4297
4395
|
const threatFeed = {
|
|
4298
4396
|
description: 'Look up the threat feed',
|
|
4299
4397
|
async run(argv, importMeta, {
|
|
@@ -4302,14 +4400,14 @@ const threatFeed = {
|
|
|
4302
4400
|
const name = `${parentName} threat-feed`;
|
|
4303
4401
|
const input = setupCommand(name, threatFeed.description, argv, importMeta);
|
|
4304
4402
|
{
|
|
4305
|
-
const apiKey =
|
|
4403
|
+
const apiKey = socketUrl.getDefaultToken();
|
|
4306
4404
|
if (!apiKey) {
|
|
4307
|
-
throw new
|
|
4405
|
+
throw new socketUrl.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
4308
4406
|
}
|
|
4309
|
-
const spinner =
|
|
4407
|
+
const spinner$1 = new spinner.Spinner({
|
|
4310
4408
|
text: 'Looking up the threat feed'
|
|
4311
4409
|
}).start();
|
|
4312
|
-
await fetchThreatFeed(input, spinner, apiKey);
|
|
4410
|
+
await fetchThreatFeed(input, spinner$1, apiKey);
|
|
4313
4411
|
}
|
|
4314
4412
|
}
|
|
4315
4413
|
};
|
|
@@ -4353,7 +4451,7 @@ function setupCommand(name, description, argv, importMeta) {
|
|
|
4353
4451
|
$ ${name}
|
|
4354
4452
|
|
|
4355
4453
|
Options
|
|
4356
|
-
${
|
|
4454
|
+
${getFlagListOutput(flags, 6)}
|
|
4357
4455
|
|
|
4358
4456
|
Examples
|
|
4359
4457
|
$ ${name}
|
|
@@ -4429,7 +4527,7 @@ async function fetchThreatFeed({
|
|
|
4429
4527
|
data: formattedOutput
|
|
4430
4528
|
});
|
|
4431
4529
|
screen.render();
|
|
4432
|
-
screen.key(['escape', 'q', 'C-c'], () => process.exit(0));
|
|
4530
|
+
screen.key(['escape', 'q', 'C-c'], () => process$1.exit(0));
|
|
4433
4531
|
}
|
|
4434
4532
|
const formatResults = data => {
|
|
4435
4533
|
return data.map(d => {
|
|
@@ -4454,6 +4552,7 @@ var cliCommands = {
|
|
|
4454
4552
|
cdxgen: cdxgen,
|
|
4455
4553
|
dependencies: dependencies,
|
|
4456
4554
|
diffScan: diffScan,
|
|
4555
|
+
fix: fix,
|
|
4457
4556
|
info: info,
|
|
4458
4557
|
login: login,
|
|
4459
4558
|
logout: logout,
|
|
@@ -4497,7 +4596,7 @@ void (async () => {
|
|
|
4497
4596
|
argv: ['report', 'create', '--view', '--strict']
|
|
4498
4597
|
}
|
|
4499
4598
|
},
|
|
4500
|
-
argv: process.argv.slice(2),
|
|
4599
|
+
argv: process$1.argv.slice(2),
|
|
4501
4600
|
name: 'socket',
|
|
4502
4601
|
importMeta: {
|
|
4503
4602
|
url: `${require$$0.pathToFileURL(__filename)}`
|
|
@@ -4507,10 +4606,10 @@ void (async () => {
|
|
|
4507
4606
|
let errorBody;
|
|
4508
4607
|
let errorTitle;
|
|
4509
4608
|
let errorMessage = '';
|
|
4510
|
-
if (err instanceof
|
|
4609
|
+
if (err instanceof socketUrl.AuthError) {
|
|
4511
4610
|
errorTitle = 'Authentication error';
|
|
4512
4611
|
errorMessage = err.message;
|
|
4513
|
-
} else if (err instanceof
|
|
4612
|
+
} else if (err instanceof socketUrl.InputError) {
|
|
4514
4613
|
errorTitle = 'Invalid input';
|
|
4515
4614
|
errorMessage = err.message;
|
|
4516
4615
|
errorBody = err.body;
|
|
@@ -4521,10 +4620,10 @@ void (async () => {
|
|
|
4521
4620
|
} else {
|
|
4522
4621
|
errorTitle = 'Unexpected error with no details';
|
|
4523
4622
|
}
|
|
4524
|
-
console.error(`${
|
|
4623
|
+
console.error(`${pathResolve.logSymbols.error} ${colors.bgRed(colors.white(errorTitle + ':'))} ${errorMessage}`);
|
|
4525
4624
|
if (errorBody) {
|
|
4526
4625
|
console.error(`\n${errorBody}`);
|
|
4527
4626
|
}
|
|
4528
|
-
process.exit(1);
|
|
4627
|
+
process$1.exit(1);
|
|
4529
4628
|
}
|
|
4530
4629
|
})();
|