@socketsecurity/cli 0.14.64 → 0.14.66
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/constants.d.ts +1 -4
- package/dist/constants.js +26 -37
- package/dist/constants.js.map +1 -1
- package/dist/module-sync/artifact.d.ts +12 -60
- package/dist/module-sync/cli.js +524 -280
- package/dist/module-sync/cli.js.map +1 -1
- package/dist/module-sync/shadow-npm-inject.js +130 -230
- package/dist/module-sync/shadow-npm-inject.js.map +1 -1
- package/dist/module-sync/shadow-npm-paths.js +22 -12
- package/dist/module-sync/shadow-npm-paths.js.map +1 -1
- package/dist/module-sync/socket-package-alert.d.ts +1 -1
- package/dist/require/cli.js +524 -280
- package/dist/require/cli.js.map +1 -1
- package/package.json +11 -14
- package/dist/module-sync/fs.d.ts +0 -22
package/dist/require/cli.js
CHANGED
|
@@ -20,6 +20,7 @@ var commonTags = _socketInterop(require('common-tags'));
|
|
|
20
20
|
var fs = require('node:fs/promises');
|
|
21
21
|
var ScreenWidget = _socketInterop(require('blessed/lib/widgets/screen'));
|
|
22
22
|
var contrib = _socketInterop(require('blessed-contrib'));
|
|
23
|
+
var strings = require('@socketsecurity/registry/lib/strings');
|
|
23
24
|
var shadowNpmInject = require('./shadow-npm-inject.js');
|
|
24
25
|
var constants = require('./constants.js');
|
|
25
26
|
var path$1 = require('node:path');
|
|
@@ -46,7 +47,6 @@ var semver = _socketInterop(require('semver'));
|
|
|
46
47
|
var which = _socketInterop(require('which'));
|
|
47
48
|
var index_cjs = require('@socketregistry/hyrious__bun.lockb/index.cjs');
|
|
48
49
|
var sorts = require('@socketsecurity/registry/lib/sorts');
|
|
49
|
-
var strings = require('@socketsecurity/registry/lib/strings');
|
|
50
50
|
var registryConstants = require('@socketsecurity/registry/lib/constants');
|
|
51
51
|
var isInteractive = require('@socketregistry/is-interactive/index.cjs');
|
|
52
52
|
var terminalLink = _socketInterop(require('terminal-link'));
|
|
@@ -62,14 +62,12 @@ var BoxWidget = _socketInterop(require('blessed/lib/widgets/box'));
|
|
|
62
62
|
var TableWidget = _socketInterop(require('blessed-contrib/lib/widget/table'));
|
|
63
63
|
var readline$1 = require('node:readline');
|
|
64
64
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
const message = typeof resultErrorMessage === 'string' ? resultErrorMessage : 'No error message returned';
|
|
72
|
-
if (result.status === 401 || result.status === 403) {
|
|
65
|
+
function handleUnsuccessfulApiResponse(_name, sockSdkError) {
|
|
66
|
+
const message = sockSdkError.error || 'No error message returned';
|
|
67
|
+
const {
|
|
68
|
+
status
|
|
69
|
+
} = sockSdkError;
|
|
70
|
+
if (status === 401 || status === 403) {
|
|
73
71
|
// Lazily access constants.spinner.
|
|
74
72
|
const {
|
|
75
73
|
spinner
|
|
@@ -91,22 +89,29 @@ async function handleApiCall(value, description) {
|
|
|
91
89
|
}
|
|
92
90
|
return result;
|
|
93
91
|
}
|
|
94
|
-
async function
|
|
92
|
+
async function handleApiError(code) {
|
|
95
93
|
if (code === 400) {
|
|
96
94
|
return 'One of the options passed might be incorrect.';
|
|
97
95
|
} else if (code === 403) {
|
|
98
96
|
return 'You might be trying to access an organization that is not linked to the API key you are logged in with.';
|
|
99
|
-
}
|
|
97
|
+
} else ;
|
|
100
98
|
}
|
|
101
99
|
function getLastFiveOfApiToken(token) {
|
|
102
100
|
// Get the last 5 characters of the API token before the trailing "_api".
|
|
103
101
|
return token.slice(-9, -4);
|
|
104
102
|
}
|
|
105
|
-
|
|
103
|
+
|
|
104
|
+
// The API server that should be used for operations.
|
|
105
|
+
function getDefaultApiBaseUrl() {
|
|
106
|
+
const baseUrl = process$1.env['SOCKET_SECURITY_API_BASE_URL'] || shadowNpmInject.getSetting('apiBaseUrl');
|
|
107
|
+
return strings.isNonEmptyString(baseUrl) ? baseUrl : undefined;
|
|
108
|
+
}
|
|
109
|
+
async function queryApi(path, apiToken) {
|
|
110
|
+
const API_V0_URL = getDefaultApiBaseUrl();
|
|
106
111
|
return await fetch(`${API_V0_URL}/${path}`, {
|
|
107
112
|
method: 'GET',
|
|
108
113
|
headers: {
|
|
109
|
-
Authorization: `Basic ${btoa(`${apiToken}
|
|
114
|
+
Authorization: `Basic ${btoa(`${apiToken}:`)}`
|
|
110
115
|
}
|
|
111
116
|
});
|
|
112
117
|
}
|
|
@@ -648,7 +653,7 @@ function emitBanner(name) {
|
|
|
648
653
|
}
|
|
649
654
|
function getAsciiHeader(command) {
|
|
650
655
|
const cliVersion = // The '@rollup/plugin-replace' will replace "process.env['INLINED_SOCKET_CLI_VERSION_HASH']".
|
|
651
|
-
"0.14.
|
|
656
|
+
"0.14.66:3dec148:bec4e6c6:pub";
|
|
652
657
|
const nodeVersion = process.version;
|
|
653
658
|
const apiToken = shadowNpmInject.getSetting('apiToken');
|
|
654
659
|
const shownToken = apiToken ? getLastFiveOfApiToken(apiToken) : 'no';
|
|
@@ -773,7 +778,7 @@ async function run$C(argv, importMeta, {
|
|
|
773
778
|
});
|
|
774
779
|
}
|
|
775
780
|
|
|
776
|
-
async function
|
|
781
|
+
async function fetchAuditLog({
|
|
777
782
|
logType,
|
|
778
783
|
orgSlug,
|
|
779
784
|
outputKind,
|
|
@@ -784,16 +789,59 @@ async function getAuditLog({
|
|
|
784
789
|
if (!apiToken) {
|
|
785
790
|
throw new shadowNpmInject.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
786
791
|
}
|
|
787
|
-
|
|
788
|
-
|
|
792
|
+
return await fetchAuditLogWithToken(apiToken, {
|
|
793
|
+
logType,
|
|
789
794
|
orgSlug,
|
|
790
795
|
outputKind,
|
|
791
796
|
page,
|
|
792
|
-
perPage
|
|
793
|
-
logType
|
|
797
|
+
perPage
|
|
794
798
|
});
|
|
795
|
-
|
|
796
|
-
|
|
799
|
+
}
|
|
800
|
+
async function fetchAuditLogWithToken(apiToken, {
|
|
801
|
+
logType,
|
|
802
|
+
orgSlug,
|
|
803
|
+
outputKind,
|
|
804
|
+
page,
|
|
805
|
+
perPage
|
|
806
|
+
}) {
|
|
807
|
+
// Lazily access constants.spinner.
|
|
808
|
+
const {
|
|
809
|
+
spinner
|
|
810
|
+
} = constants;
|
|
811
|
+
spinner.start(`Looking up audit log for ${orgSlug}`);
|
|
812
|
+
const socketSdk = await shadowNpmInject.setupSdk(apiToken);
|
|
813
|
+
const result = await handleApiCall(socketSdk.getAuditLogEvents(orgSlug, {
|
|
814
|
+
// I'm not sure this is used at all.
|
|
815
|
+
outputJson: String(outputKind === 'json'),
|
|
816
|
+
// I'm not sure this is used at all.
|
|
817
|
+
outputMarkdown: String(outputKind === 'markdown'),
|
|
818
|
+
orgSlug,
|
|
819
|
+
type: logType,
|
|
820
|
+
page: String(page),
|
|
821
|
+
per_page: String(perPage)
|
|
822
|
+
}), `Looking up audit log for ${orgSlug}\n`);
|
|
823
|
+
if (!result.success) {
|
|
824
|
+
handleUnsuccessfulApiResponse('getAuditLogEvents', result);
|
|
825
|
+
return;
|
|
826
|
+
}
|
|
827
|
+
spinner.stop();
|
|
828
|
+
return result.data;
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
async function outputAuditLog(auditLogs, {
|
|
832
|
+
logType,
|
|
833
|
+
orgSlug,
|
|
834
|
+
outputKind,
|
|
835
|
+
page,
|
|
836
|
+
perPage
|
|
837
|
+
}) {
|
|
838
|
+
if (outputKind === 'json') {
|
|
839
|
+
await outputAsJson(auditLogs.results, orgSlug, logType, page, perPage);
|
|
840
|
+
} else if (outputKind === 'markdown') {
|
|
841
|
+
await outputAsMarkdown(auditLogs.results, orgSlug, logType, page, perPage);
|
|
842
|
+
} else {
|
|
843
|
+
await outputAsPrint(auditLogs.results, orgSlug, logType);
|
|
844
|
+
}
|
|
797
845
|
}
|
|
798
846
|
async function outputAsJson(auditLogs, orgSlug, logType, page, perPage) {
|
|
799
847
|
let json;
|
|
@@ -879,36 +927,29 @@ async function outputAsPrint(auditLogs, orgSlug, logType) {
|
|
|
879
927
|
pageSize: 30
|
|
880
928
|
})]);
|
|
881
929
|
}
|
|
882
|
-
|
|
883
|
-
|
|
930
|
+
|
|
931
|
+
async function handleAuditLog({
|
|
884
932
|
logType,
|
|
885
933
|
orgSlug,
|
|
886
934
|
outputKind,
|
|
887
935
|
page,
|
|
888
936
|
perPage
|
|
889
937
|
}) {
|
|
890
|
-
|
|
891
|
-
const {
|
|
892
|
-
spinner
|
|
893
|
-
} = constants;
|
|
894
|
-
spinner.start(`Looking up audit log for ${orgSlug}`);
|
|
895
|
-
const socketSdk = await shadowNpmInject.setupSdk(apiToken);
|
|
896
|
-
const result = await handleApiCall(socketSdk.getAuditLogEvents(orgSlug, {
|
|
897
|
-
// I'm not sure this is used at all.
|
|
898
|
-
outputJson: String(outputKind === 'json'),
|
|
899
|
-
// I'm not sure this is used at all.
|
|
900
|
-
outputMarkdown: String(outputKind === 'markdown'),
|
|
938
|
+
const auditLogs = await fetchAuditLog({
|
|
901
939
|
orgSlug,
|
|
902
|
-
|
|
903
|
-
page
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
940
|
+
outputKind,
|
|
941
|
+
page,
|
|
942
|
+
perPage,
|
|
943
|
+
logType
|
|
944
|
+
});
|
|
945
|
+
if (!auditLogs) return;
|
|
946
|
+
await outputAuditLog(auditLogs, {
|
|
947
|
+
logType,
|
|
948
|
+
orgSlug,
|
|
949
|
+
outputKind,
|
|
950
|
+
page,
|
|
951
|
+
perPage
|
|
952
|
+
});
|
|
912
953
|
}
|
|
913
954
|
|
|
914
955
|
const {
|
|
@@ -992,7 +1033,7 @@ async function run$B(argv, importMeta, {
|
|
|
992
1033
|
logger.logger.log(DRY_RUN_BAIL_TEXT$A);
|
|
993
1034
|
return;
|
|
994
1035
|
}
|
|
995
|
-
await
|
|
1036
|
+
await handleAuditLog({
|
|
996
1037
|
orgSlug,
|
|
997
1038
|
outputKind: json ? 'json' : markdown ? 'markdown' : 'print',
|
|
998
1039
|
page: Number(page || 0),
|
|
@@ -1251,36 +1292,60 @@ async function run$A(argv, importMeta, {
|
|
|
1251
1292
|
await runCycloneDX(yargv);
|
|
1252
1293
|
}
|
|
1253
1294
|
|
|
1254
|
-
|
|
1255
|
-
async function findDependencies({
|
|
1295
|
+
async function fetchDependencies({
|
|
1256
1296
|
limit,
|
|
1257
|
-
offset
|
|
1258
|
-
outputJson
|
|
1297
|
+
offset
|
|
1259
1298
|
}) {
|
|
1260
1299
|
const apiToken = shadowNpmInject.getDefaultToken();
|
|
1261
1300
|
if (!apiToken) {
|
|
1262
1301
|
throw new shadowNpmInject.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
1263
1302
|
}
|
|
1303
|
+
return await fetchDependenciesWithToken(apiToken, {
|
|
1304
|
+
limit,
|
|
1305
|
+
offset
|
|
1306
|
+
});
|
|
1307
|
+
}
|
|
1308
|
+
async function fetchDependenciesWithToken(apiToken, {
|
|
1309
|
+
limit,
|
|
1310
|
+
offset
|
|
1311
|
+
}) {
|
|
1264
1312
|
// Lazily access constants.spinner.
|
|
1265
1313
|
const {
|
|
1266
1314
|
spinner
|
|
1267
1315
|
} = constants;
|
|
1268
|
-
spinner.start('
|
|
1316
|
+
spinner.start('Fetching organization dependencies...');
|
|
1269
1317
|
const socketSdk = await shadowNpmInject.setupSdk(apiToken);
|
|
1270
1318
|
const result = await handleApiCall(socketSdk.searchDependencies({
|
|
1271
1319
|
limit,
|
|
1272
1320
|
offset
|
|
1273
1321
|
}), 'Searching dependencies');
|
|
1322
|
+
spinner?.successAndStop('Received organization dependencies response.');
|
|
1274
1323
|
if (!result.success) {
|
|
1275
1324
|
handleUnsuccessfulApiResponse('searchDependencies', result);
|
|
1276
1325
|
return;
|
|
1277
1326
|
}
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1327
|
+
return result.data;
|
|
1328
|
+
}
|
|
1329
|
+
|
|
1330
|
+
// @ts-ignore
|
|
1331
|
+
async function outputDependencies(data, {
|
|
1332
|
+
limit,
|
|
1333
|
+
offset,
|
|
1334
|
+
outputKind
|
|
1335
|
+
}) {
|
|
1336
|
+
if (outputKind === 'json') {
|
|
1337
|
+
let json;
|
|
1338
|
+
try {
|
|
1339
|
+
json = JSON.stringify(data, null, 2);
|
|
1340
|
+
} catch (e) {
|
|
1341
|
+
process.exitCode = 1;
|
|
1342
|
+
logger.logger.fail('There was a problem converting the data to JSON, please try without the `--json` flag');
|
|
1343
|
+
return;
|
|
1344
|
+
}
|
|
1345
|
+
logger.logger.log(json);
|
|
1281
1346
|
return;
|
|
1282
1347
|
}
|
|
1283
|
-
logger.logger.log('Request details: Offset:', offset, ', limit:', limit, ', is there more data after this?',
|
|
1348
|
+
logger.logger.log('Request details: Offset:', offset, ', limit:', limit, ', is there more data after this?', data.end ? 'no' : 'yes');
|
|
1284
1349
|
const options = {
|
|
1285
1350
|
columns: [{
|
|
1286
1351
|
field: 'namespace',
|
|
@@ -1305,7 +1370,24 @@ async function findDependencies({
|
|
|
1305
1370
|
name: colors.cyan('Direct')
|
|
1306
1371
|
}]
|
|
1307
1372
|
};
|
|
1308
|
-
logger.logger.log(chalkTable(options,
|
|
1373
|
+
logger.logger.log(chalkTable(options, data.rows));
|
|
1374
|
+
}
|
|
1375
|
+
|
|
1376
|
+
async function handleDependencies({
|
|
1377
|
+
limit,
|
|
1378
|
+
offset,
|
|
1379
|
+
outputKind
|
|
1380
|
+
}) {
|
|
1381
|
+
const data = await fetchDependencies({
|
|
1382
|
+
limit,
|
|
1383
|
+
offset
|
|
1384
|
+
});
|
|
1385
|
+
if (!data) return;
|
|
1386
|
+
await outputDependencies(data, {
|
|
1387
|
+
limit,
|
|
1388
|
+
offset,
|
|
1389
|
+
outputKind
|
|
1390
|
+
});
|
|
1309
1391
|
}
|
|
1310
1392
|
|
|
1311
1393
|
const {
|
|
@@ -1356,70 +1438,71 @@ async function run$z(argv, importMeta, {
|
|
|
1356
1438
|
importMeta,
|
|
1357
1439
|
parentName
|
|
1358
1440
|
});
|
|
1441
|
+
const {
|
|
1442
|
+
json,
|
|
1443
|
+
limit,
|
|
1444
|
+
markdown,
|
|
1445
|
+
offset
|
|
1446
|
+
} = cli.flags;
|
|
1359
1447
|
if (cli.flags['dryRun']) {
|
|
1360
1448
|
logger.logger.log(DRY_RUN_BAIL_TEXT$y);
|
|
1361
1449
|
return;
|
|
1362
1450
|
}
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
offset: Number(cli.flags['offset'] || 0) || 0,
|
|
1368
|
-
outputJson: Boolean(cli.flags['json'])
|
|
1451
|
+
await handleDependencies({
|
|
1452
|
+
limit: Number(limit || 0) || 0,
|
|
1453
|
+
offset: Number(offset || 0) || 0,
|
|
1454
|
+
outputKind: json ? 'json' : markdown ? 'markdown' : 'text'
|
|
1369
1455
|
});
|
|
1370
1456
|
}
|
|
1371
1457
|
|
|
1372
|
-
async function
|
|
1458
|
+
async function fetchDiffScan({
|
|
1373
1459
|
after,
|
|
1374
1460
|
before,
|
|
1375
|
-
|
|
1376
|
-
file,
|
|
1377
|
-
orgSlug,
|
|
1378
|
-
outputJson
|
|
1461
|
+
orgSlug
|
|
1379
1462
|
}) {
|
|
1380
1463
|
const apiToken = shadowNpmInject.getDefaultToken();
|
|
1381
1464
|
if (!apiToken) {
|
|
1382
1465
|
throw new shadowNpmInject.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
1383
1466
|
}
|
|
1384
|
-
await
|
|
1467
|
+
return await fetchDiffScanWithToken(apiToken, {
|
|
1385
1468
|
after,
|
|
1386
1469
|
before,
|
|
1387
|
-
|
|
1388
|
-
file,
|
|
1389
|
-
orgSlug,
|
|
1390
|
-
outputJson,
|
|
1391
|
-
apiToken
|
|
1470
|
+
orgSlug
|
|
1392
1471
|
});
|
|
1393
1472
|
}
|
|
1394
|
-
async function
|
|
1473
|
+
async function fetchDiffScanWithToken(apiToken, {
|
|
1395
1474
|
after,
|
|
1396
|
-
apiToken,
|
|
1397
1475
|
before,
|
|
1398
|
-
|
|
1399
|
-
file,
|
|
1400
|
-
orgSlug,
|
|
1401
|
-
outputJson
|
|
1476
|
+
orgSlug
|
|
1402
1477
|
}) {
|
|
1403
1478
|
// Lazily access constants.spinner.
|
|
1404
1479
|
const {
|
|
1405
1480
|
spinner
|
|
1406
1481
|
} = constants;
|
|
1407
|
-
spinner.start('
|
|
1408
|
-
const response = await
|
|
1482
|
+
spinner.start('Fetching diff-scan...');
|
|
1483
|
+
const response = await queryApi(`orgs/${orgSlug}/full-scans/diff?before=${encodeURIComponent(before)}&after=${encodeURIComponent(after)}`, apiToken);
|
|
1484
|
+
spinner?.successAndStop('Received diff-scan response');
|
|
1409
1485
|
if (!response.ok) {
|
|
1410
|
-
const err = await
|
|
1486
|
+
const err = await handleApiError(response.status);
|
|
1411
1487
|
spinner.errorAndStop(`${colors.bgRed(colors.white(response.statusText))}: ${err}`);
|
|
1412
1488
|
return;
|
|
1413
1489
|
}
|
|
1414
1490
|
const result = await handleApiCall(await response.json(), 'Deserializing json');
|
|
1415
|
-
|
|
1416
|
-
|
|
1491
|
+
return result;
|
|
1492
|
+
}
|
|
1493
|
+
|
|
1494
|
+
async function outputDiffScan(result, {
|
|
1495
|
+
depth,
|
|
1496
|
+
file,
|
|
1497
|
+
outputKind
|
|
1498
|
+
}) {
|
|
1499
|
+
const dashboardUrl = result.diff_report_url;
|
|
1417
1500
|
const dashboardMessage = dashboardUrl ? `\n View this diff scan in the Socket dashboard: ${colors.cyan(dashboardUrl)}` : '';
|
|
1418
1501
|
|
|
1419
1502
|
// When forcing json, or dumping to file, serialize to string such that it
|
|
1420
1503
|
// won't get truncated. The only way to dump the full raw JSON to stdout is
|
|
1421
1504
|
// to use `--json --file -` (the dash is a standard notation for stdout)
|
|
1422
|
-
if (
|
|
1505
|
+
if (outputKind === 'json' || file) {
|
|
1423
1506
|
let json;
|
|
1424
1507
|
try {
|
|
1425
1508
|
json = JSON.stringify(result, null, 2);
|
|
@@ -1464,6 +1547,27 @@ async function getDiffScanWithToken({
|
|
|
1464
1547
|
logger.logger.log(dashboardMessage);
|
|
1465
1548
|
}
|
|
1466
1549
|
|
|
1550
|
+
async function handleDiffScan({
|
|
1551
|
+
after,
|
|
1552
|
+
before,
|
|
1553
|
+
depth,
|
|
1554
|
+
file,
|
|
1555
|
+
orgSlug,
|
|
1556
|
+
outputKind
|
|
1557
|
+
}) {
|
|
1558
|
+
const data = await fetchDiffScan({
|
|
1559
|
+
after,
|
|
1560
|
+
before,
|
|
1561
|
+
orgSlug
|
|
1562
|
+
});
|
|
1563
|
+
if (!data) return;
|
|
1564
|
+
await outputDiffScan(data, {
|
|
1565
|
+
depth,
|
|
1566
|
+
file,
|
|
1567
|
+
outputKind
|
|
1568
|
+
});
|
|
1569
|
+
}
|
|
1570
|
+
|
|
1467
1571
|
const {
|
|
1468
1572
|
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$x
|
|
1469
1573
|
} = constants;
|
|
@@ -1532,8 +1636,14 @@ async function run$y(argv, importMeta, {
|
|
|
1532
1636
|
importMeta,
|
|
1533
1637
|
parentName
|
|
1534
1638
|
});
|
|
1535
|
-
const
|
|
1536
|
-
|
|
1639
|
+
const {
|
|
1640
|
+
after,
|
|
1641
|
+
before,
|
|
1642
|
+
depth,
|
|
1643
|
+
file,
|
|
1644
|
+
json,
|
|
1645
|
+
markdown
|
|
1646
|
+
} = cli.flags;
|
|
1537
1647
|
const [orgSlug = ''] = cli.input;
|
|
1538
1648
|
if (!before || !after || cli.input.length < 1) {
|
|
1539
1649
|
// Use exit status of 2 to indicate incorrect usage, generally invalid
|
|
@@ -1551,13 +1661,13 @@ async function run$y(argv, importMeta, {
|
|
|
1551
1661
|
logger.logger.log(DRY_RUN_BAIL_TEXT$x);
|
|
1552
1662
|
return;
|
|
1553
1663
|
}
|
|
1554
|
-
await
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
depth: Number(cli.flags['depth']),
|
|
1664
|
+
await handleDiffScan({
|
|
1665
|
+
before: String(before || ''),
|
|
1666
|
+
after: String(after || ''),
|
|
1667
|
+
depth: Number(depth),
|
|
1559
1668
|
orgSlug,
|
|
1560
|
-
|
|
1669
|
+
outputKind: json ? 'json' : markdown ? 'markdown' : 'text',
|
|
1670
|
+
file: String(file || '')
|
|
1561
1671
|
});
|
|
1562
1672
|
}
|
|
1563
1673
|
|
|
@@ -1696,11 +1806,17 @@ async function npmFix(_pkgEnvDetails, cwd, options) {
|
|
|
1696
1806
|
|
|
1697
1807
|
async function getAlertsMapFromPnpmLockfile(lockfile, options) {
|
|
1698
1808
|
const {
|
|
1809
|
+
include: _include,
|
|
1699
1810
|
spinner
|
|
1700
1811
|
} = {
|
|
1701
1812
|
__proto__: null,
|
|
1702
1813
|
...options
|
|
1703
1814
|
};
|
|
1815
|
+
const include = {
|
|
1816
|
+
__proto__: null,
|
|
1817
|
+
unfixable: true,
|
|
1818
|
+
..._include
|
|
1819
|
+
};
|
|
1704
1820
|
const depTypes = lockfile_detectDepTypes.detectDepTypes(lockfile);
|
|
1705
1821
|
const pkgIds = Object.keys(depTypes);
|
|
1706
1822
|
let {
|
|
@@ -1712,12 +1828,23 @@ async function getAlertsMapFromPnpmLockfile(lockfile, options) {
|
|
|
1712
1828
|
}
|
|
1713
1829
|
const getText = () => `Looking up data for ${remaining} packages`;
|
|
1714
1830
|
spinner?.start(getText());
|
|
1831
|
+
const socketSdk = await shadowNpmInject.setupSdk(shadowNpmInject.getPublicToken());
|
|
1715
1832
|
const toAlertsMapOptions = {
|
|
1716
1833
|
overrides: lockfile.overrides,
|
|
1717
1834
|
...options
|
|
1718
1835
|
};
|
|
1719
|
-
for await (const
|
|
1720
|
-
|
|
1836
|
+
for await (const batchPackageFetchResult of socketSdk.batchPackageStream({
|
|
1837
|
+
alerts: 'true',
|
|
1838
|
+
compact: 'true',
|
|
1839
|
+
fixable: include.unfixable ? 'false' : 'true'
|
|
1840
|
+
}, {
|
|
1841
|
+
components: pkgIds.map(id => ({
|
|
1842
|
+
purl: `pkg:npm/${id}`
|
|
1843
|
+
}))
|
|
1844
|
+
})) {
|
|
1845
|
+
if (batchPackageFetchResult.success) {
|
|
1846
|
+
await shadowNpmInject.addArtifactToAlertsMap(batchPackageFetchResult.data, alertsByPkgId, toAlertsMapOptions);
|
|
1847
|
+
}
|
|
1721
1848
|
remaining -= 1;
|
|
1722
1849
|
if (spinner && remaining > 0) {
|
|
1723
1850
|
spinner.start();
|
|
@@ -2304,10 +2431,17 @@ async function run$x(argv, importMeta, {
|
|
|
2304
2431
|
await runFix();
|
|
2305
2432
|
}
|
|
2306
2433
|
|
|
2307
|
-
async function fetchPackageInfo
|
|
2434
|
+
async function fetchPackageInfo(pkgName, pkgVersion, includeAllIssues) {
|
|
2308
2435
|
const socketSdk = await shadowNpmInject.setupSdk(shadowNpmInject.getPublicToken());
|
|
2436
|
+
|
|
2437
|
+
// Lazily access constants.spinner.
|
|
2438
|
+
const {
|
|
2439
|
+
spinner
|
|
2440
|
+
} = constants;
|
|
2441
|
+
spinner.start(pkgVersion === 'latest' ? `Looking up data for the latest version of ${pkgName}` : `Looking up data for version ${pkgVersion} of ${pkgName}`);
|
|
2309
2442
|
const result = await handleApiCall(socketSdk.getIssuesByNPMPackage(pkgName, pkgVersion), 'looking up package');
|
|
2310
2443
|
const scoreResult = await handleApiCall(socketSdk.getScoreByNPMPackage(pkgName, pkgVersion), 'looking up package score');
|
|
2444
|
+
spinner.successAndStop('Data fetched');
|
|
2311
2445
|
if (result.success === false) {
|
|
2312
2446
|
return handleUnsuccessfulApiResponse('getIssuesByNPMPackage', result);
|
|
2313
2447
|
}
|
|
@@ -2333,8 +2467,8 @@ function formatScore$1(score) {
|
|
|
2333
2467
|
}
|
|
2334
2468
|
return colors.red(`${score}`);
|
|
2335
2469
|
}
|
|
2336
|
-
function
|
|
2337
|
-
const issueDetails = packageData.filter(d => d.value?.severity === shadowNpmInject.
|
|
2470
|
+
function outputPackageIssuesDetails(packageData, outputMarkdown) {
|
|
2471
|
+
const issueDetails = packageData.filter(d => d.value?.severity === shadowNpmInject.ALERT_SEVERITY.critical || d.value?.severity === shadowNpmInject.ALERT_SEVERITY.high);
|
|
2338
2472
|
const uniqueIssueDetails = issueDetails.reduce((acc, issue) => {
|
|
2339
2473
|
const {
|
|
2340
2474
|
type
|
|
@@ -2364,7 +2498,7 @@ function logPackageIssuesDetails(packageData, outputMarkdown) {
|
|
|
2364
2498
|
}
|
|
2365
2499
|
}
|
|
2366
2500
|
}
|
|
2367
|
-
function
|
|
2501
|
+
function outputPackageInfo({
|
|
2368
2502
|
data,
|
|
2369
2503
|
score,
|
|
2370
2504
|
severityCount
|
|
@@ -2402,7 +2536,7 @@ function logPackageInfo$1({
|
|
|
2402
2536
|
logger.logger.log('# Issues\n');
|
|
2403
2537
|
}
|
|
2404
2538
|
logger.logger.log(`Package has these issues: ${shadowNpmInject.formatSeverityCount(severityCount)}\n`);
|
|
2405
|
-
|
|
2539
|
+
outputPackageIssuesDetails(data, outputKind === 'markdown');
|
|
2406
2540
|
} else {
|
|
2407
2541
|
logger.logger.log('Package has no issues');
|
|
2408
2542
|
}
|
|
@@ -2425,7 +2559,7 @@ function logPackageInfo$1({
|
|
|
2425
2559
|
}
|
|
2426
2560
|
}
|
|
2427
2561
|
|
|
2428
|
-
async function
|
|
2562
|
+
async function handlePackageInfo({
|
|
2429
2563
|
commandName,
|
|
2430
2564
|
includeAllIssues,
|
|
2431
2565
|
outputKind,
|
|
@@ -2433,15 +2567,9 @@ async function getPackageInfo({
|
|
|
2433
2567
|
pkgVersion,
|
|
2434
2568
|
strict
|
|
2435
2569
|
}) {
|
|
2436
|
-
|
|
2437
|
-
const {
|
|
2438
|
-
spinner
|
|
2439
|
-
} = constants;
|
|
2440
|
-
spinner.start(pkgVersion === 'latest' ? `Looking up data for the latest version of ${pkgName}` : `Looking up data for version ${pkgVersion} of ${pkgName}`);
|
|
2441
|
-
const packageData = await fetchPackageInfo$1(pkgName, pkgVersion, includeAllIssues);
|
|
2442
|
-
spinner.successAndStop('Data fetched');
|
|
2570
|
+
const packageData = await fetchPackageInfo(pkgName, pkgVersion, includeAllIssues);
|
|
2443
2571
|
if (packageData) {
|
|
2444
|
-
|
|
2572
|
+
outputPackageInfo(packageData, {
|
|
2445
2573
|
name: commandName,
|
|
2446
2574
|
outputKind,
|
|
2447
2575
|
pkgName,
|
|
@@ -2516,7 +2644,7 @@ async function run$w(argv, importMeta, {
|
|
|
2516
2644
|
logger.logger.log(DRY_RUN_BAIL_TEXT$v);
|
|
2517
2645
|
return;
|
|
2518
2646
|
}
|
|
2519
|
-
await
|
|
2647
|
+
await handlePackageInfo({
|
|
2520
2648
|
commandName: `${parentName} ${config$w.commandName}`,
|
|
2521
2649
|
includeAllIssues: Boolean(all),
|
|
2522
2650
|
outputKind: json ? 'json' : markdown ? 'markdown' : 'print',
|
|
@@ -4406,29 +4534,35 @@ async function run$l(argv, importMeta, {
|
|
|
4406
4534
|
await applyOptimization(cwd, Boolean(cli.flags['pin']), Boolean(cli.flags['prod']));
|
|
4407
4535
|
}
|
|
4408
4536
|
|
|
4409
|
-
async function
|
|
4537
|
+
async function fetchOrganization() {
|
|
4410
4538
|
const apiToken = shadowNpmInject.getDefaultToken();
|
|
4411
4539
|
if (!apiToken) {
|
|
4412
4540
|
throw new shadowNpmInject.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
4413
4541
|
}
|
|
4414
|
-
await
|
|
4542
|
+
return await fetchOrganizationWithToken(apiToken);
|
|
4415
4543
|
}
|
|
4416
|
-
async function
|
|
4544
|
+
async function fetchOrganizationWithToken(apiToken) {
|
|
4545
|
+
const socketSdk = await shadowNpmInject.setupSdk(apiToken);
|
|
4546
|
+
|
|
4417
4547
|
// Lazily access constants.spinner.
|
|
4418
4548
|
const {
|
|
4419
4549
|
spinner
|
|
4420
4550
|
} = constants;
|
|
4421
|
-
spinner.start('Fetching
|
|
4422
|
-
const socketSdk = await shadowNpmInject.setupSdk(apiToken);
|
|
4551
|
+
spinner.start('Fetching organization list...');
|
|
4423
4552
|
const result = await handleApiCall(socketSdk.getOrganizations(), 'looking up organizations');
|
|
4553
|
+
spinner.successAndStop('Received organization list response.');
|
|
4424
4554
|
if (!result.success) {
|
|
4425
4555
|
handleUnsuccessfulApiResponse('getOrganizations', result);
|
|
4426
4556
|
return;
|
|
4427
4557
|
}
|
|
4428
|
-
|
|
4429
|
-
|
|
4430
|
-
|
|
4431
|
-
|
|
4558
|
+
return result.data;
|
|
4559
|
+
}
|
|
4560
|
+
|
|
4561
|
+
async function outputOrganizationList(data, outputKind = 'text') {
|
|
4562
|
+
const organizations = Object.values(data.organizations);
|
|
4563
|
+
const apiToken = shadowNpmInject.getDefaultToken();
|
|
4564
|
+
const lastFiveOfApiToken = getLastFiveOfApiToken(apiToken ?? '?????');
|
|
4565
|
+
switch (outputKind) {
|
|
4432
4566
|
case 'json':
|
|
4433
4567
|
{
|
|
4434
4568
|
logger.logger.log(JSON.stringify(organizations.map(o => ({
|
|
@@ -4473,6 +4607,12 @@ async function printOrganizationsFromToken(apiToken, format = 'text') {
|
|
|
4473
4607
|
}
|
|
4474
4608
|
}
|
|
4475
4609
|
|
|
4610
|
+
async function handleOrganizationList(outputKind = 'text') {
|
|
4611
|
+
const data = await fetchOrganization();
|
|
4612
|
+
if (!data) return;
|
|
4613
|
+
await outputOrganizationList(data, outputKind);
|
|
4614
|
+
}
|
|
4615
|
+
|
|
4476
4616
|
const {
|
|
4477
4617
|
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$k
|
|
4478
4618
|
} = constants;
|
|
@@ -4524,48 +4664,63 @@ ${colors.bgRed(colors.white('Input error'))}: Please provide the required fields
|
|
|
4524
4664
|
logger.logger.log(DRY_RUN_BAIL_TEXT$k);
|
|
4525
4665
|
return;
|
|
4526
4666
|
}
|
|
4527
|
-
await
|
|
4667
|
+
await handleOrganizationList(json ? 'json' : markdown ? 'markdown' : 'text');
|
|
4528
4668
|
}
|
|
4529
4669
|
|
|
4530
|
-
async function
|
|
4670
|
+
async function fetchSecurityPolicy(orgSlug) {
|
|
4531
4671
|
const apiToken = shadowNpmInject.getDefaultToken();
|
|
4532
4672
|
if (!apiToken) {
|
|
4533
4673
|
throw new shadowNpmInject.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
4534
4674
|
}
|
|
4535
|
-
await
|
|
4675
|
+
return await fetchSecurityPolicyWithToken(apiToken, orgSlug);
|
|
4536
4676
|
}
|
|
4537
|
-
async function
|
|
4677
|
+
async function fetchSecurityPolicyWithToken(apiToken, orgSlug) {
|
|
4538
4678
|
// Lazily access constants.spinner.
|
|
4539
4679
|
const {
|
|
4540
4680
|
spinner
|
|
4541
4681
|
} = constants;
|
|
4542
|
-
spinner.start('Fetching organization quota...');
|
|
4543
4682
|
const socketSdk = await shadowNpmInject.setupSdk(apiToken);
|
|
4683
|
+
spinner.start('Fetching organization quota...');
|
|
4544
4684
|
const result = await handleApiCall(socketSdk.getOrgSecurityPolicy(orgSlug), 'looking up organization quota');
|
|
4685
|
+
spinner?.successAndStop('Received organization quota response.');
|
|
4545
4686
|
if (!result.success) {
|
|
4546
4687
|
handleUnsuccessfulApiResponse('getOrgSecurityPolicy', result);
|
|
4547
4688
|
return;
|
|
4548
4689
|
}
|
|
4549
|
-
|
|
4550
|
-
|
|
4551
|
-
|
|
4552
|
-
|
|
4553
|
-
|
|
4554
|
-
|
|
4555
|
-
|
|
4556
|
-
|
|
4557
|
-
|
|
4558
|
-
|
|
4559
|
-
|
|
4560
|
-
|
|
4561
|
-
|
|
4562
|
-
|
|
4563
|
-
|
|
4564
|
-
const mapped = entries.map(([key, value]) => [key, value.action]);
|
|
4565
|
-
mapped.sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
|
|
4566
|
-
logger.logger.log(mdTableOfPairs(mapped, ['name', 'action']));
|
|
4567
|
-
}
|
|
4690
|
+
return result.data;
|
|
4691
|
+
}
|
|
4692
|
+
|
|
4693
|
+
async function getSecurityPolicy(data, outputKind) {
|
|
4694
|
+
if (outputKind === 'json') {
|
|
4695
|
+
let json;
|
|
4696
|
+
try {
|
|
4697
|
+
json = JSON.stringify(data, null, 2);
|
|
4698
|
+
} catch {
|
|
4699
|
+
console.error('Failed to convert the server response to json, try running the same command without --json');
|
|
4700
|
+
return;
|
|
4701
|
+
}
|
|
4702
|
+
logger.logger.log(json);
|
|
4703
|
+
logger.logger.log('');
|
|
4704
|
+
return;
|
|
4568
4705
|
}
|
|
4706
|
+
logger.logger.log('# Security policy');
|
|
4707
|
+
logger.logger.log('');
|
|
4708
|
+
logger.logger.log(`The default security policy setting is: "${data.securityPolicyDefault}"`);
|
|
4709
|
+
logger.logger.log('');
|
|
4710
|
+
logger.logger.log('These are the security policies per setting for your organization:');
|
|
4711
|
+
logger.logger.log('');
|
|
4712
|
+
const rules = data.securityPolicyRules;
|
|
4713
|
+
const entries = Object.entries(rules);
|
|
4714
|
+
const mapped = entries.map(([key, value]) => [key, value.action]);
|
|
4715
|
+
mapped.sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
|
|
4716
|
+
logger.logger.log(mdTableOfPairs(mapped, ['name', 'action']));
|
|
4717
|
+
logger.logger.log('');
|
|
4718
|
+
}
|
|
4719
|
+
|
|
4720
|
+
async function handleSecurityPolicy(orgSlug, outputKind) {
|
|
4721
|
+
const data = await fetchSecurityPolicy(orgSlug);
|
|
4722
|
+
if (!data) return;
|
|
4723
|
+
await getSecurityPolicy(data, outputKind);
|
|
4569
4724
|
}
|
|
4570
4725
|
|
|
4571
4726
|
const {
|
|
@@ -4630,7 +4785,7 @@ ${colors.bgRed(colors.white('Input error'))}: Please provide the required fields
|
|
|
4630
4785
|
logger.logger.log(DRY_RUN_BAIL_TEXT$j);
|
|
4631
4786
|
return;
|
|
4632
4787
|
}
|
|
4633
|
-
await
|
|
4788
|
+
await handleSecurityPolicy(orgSlug, json ? 'json' : markdown ? 'markdown' : 'text');
|
|
4634
4789
|
}
|
|
4635
4790
|
|
|
4636
4791
|
const description$5 = 'Organization policy details';
|
|
@@ -4657,45 +4812,57 @@ const cmdOrganizationPolicy = {
|
|
|
4657
4812
|
}
|
|
4658
4813
|
};
|
|
4659
4814
|
|
|
4660
|
-
async function
|
|
4815
|
+
async function fetchQuota() {
|
|
4661
4816
|
const apiToken = shadowNpmInject.getDefaultToken();
|
|
4662
4817
|
if (!apiToken) {
|
|
4663
4818
|
throw new shadowNpmInject.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
4664
4819
|
}
|
|
4665
|
-
await
|
|
4820
|
+
return await fetchQuotaWithToken(apiToken);
|
|
4666
4821
|
}
|
|
4667
|
-
async function
|
|
4822
|
+
async function fetchQuotaWithToken(apiToken) {
|
|
4668
4823
|
// Lazily access constants.spinner.
|
|
4669
4824
|
const {
|
|
4670
4825
|
spinner
|
|
4671
4826
|
} = constants;
|
|
4672
|
-
spinner.start('Fetching organization quota...');
|
|
4673
4827
|
const socketSdk = await shadowNpmInject.setupSdk(apiToken);
|
|
4828
|
+
spinner.start('Fetching organization quota...');
|
|
4674
4829
|
const result = await handleApiCall(socketSdk.getQuota(), 'looking up organization quota');
|
|
4830
|
+
spinner?.successAndStop('Recieved organization quota response.');
|
|
4675
4831
|
if (!result.success) {
|
|
4676
4832
|
handleUnsuccessfulApiResponse('getQuota', result);
|
|
4677
4833
|
return;
|
|
4678
4834
|
}
|
|
4679
|
-
|
|
4680
|
-
|
|
4681
|
-
|
|
4682
|
-
|
|
4683
|
-
|
|
4684
|
-
|
|
4685
|
-
|
|
4686
|
-
|
|
4687
|
-
|
|
4688
|
-
|
|
4689
|
-
|
|
4690
|
-
|
|
4691
|
-
|
|
4692
|
-
|
|
4693
|
-
|
|
4694
|
-
default:
|
|
4695
|
-
{
|
|
4696
|
-
logger.logger.log(`Quota left on the current API token: ${result.data.quota}\n`);
|
|
4697
|
-
}
|
|
4835
|
+
return result.data;
|
|
4836
|
+
}
|
|
4837
|
+
|
|
4838
|
+
async function outputQuota(data, outputKind = 'text') {
|
|
4839
|
+
if (outputKind === 'json') {
|
|
4840
|
+
let json;
|
|
4841
|
+
try {
|
|
4842
|
+
json = JSON.stringify(data, null, 2);
|
|
4843
|
+
} catch {
|
|
4844
|
+
console.error('Failed to convert the server response to json, try running the same command without --json');
|
|
4845
|
+
return;
|
|
4846
|
+
}
|
|
4847
|
+
logger.logger.log(json);
|
|
4848
|
+
logger.logger.log('');
|
|
4849
|
+
return;
|
|
4698
4850
|
}
|
|
4851
|
+
if (outputKind === 'markdown') {
|
|
4852
|
+
logger.logger.log('# Quota');
|
|
4853
|
+
logger.logger.log('');
|
|
4854
|
+
logger.logger.log(`Quota left on the current API token: ${data.quota}`);
|
|
4855
|
+
logger.logger.log('');
|
|
4856
|
+
return;
|
|
4857
|
+
}
|
|
4858
|
+
logger.logger.log(`Quota left on the current API token: ${data.quota}`);
|
|
4859
|
+
logger.logger.log('');
|
|
4860
|
+
}
|
|
4861
|
+
|
|
4862
|
+
async function handleQuota(outputKind = 'text') {
|
|
4863
|
+
const data = await fetchQuota();
|
|
4864
|
+
if (!data) return;
|
|
4865
|
+
await outputQuota(data, outputKind);
|
|
4699
4866
|
}
|
|
4700
4867
|
|
|
4701
4868
|
const {
|
|
@@ -4749,7 +4916,7 @@ ${colors.bgRed(colors.white('Input error'))}: Please provide the required fields
|
|
|
4749
4916
|
logger.logger.log(DRY_RUN_BAIL_TEXT$i);
|
|
4750
4917
|
return;
|
|
4751
4918
|
}
|
|
4752
|
-
await
|
|
4919
|
+
await handleQuota(json ? 'json' : markdown ? 'markdown' : 'text');
|
|
4753
4920
|
}
|
|
4754
4921
|
|
|
4755
4922
|
const description$4 = 'Account details';
|
|
@@ -4778,68 +4945,15 @@ const cmdOrganization = {
|
|
|
4778
4945
|
}
|
|
4779
4946
|
};
|
|
4780
4947
|
|
|
4781
|
-
|
|
4782
|
-
|
|
4783
|
-
// Not hardcoding the namespace since we don't know what the server accepts.
|
|
4784
|
-
// The ecosystem is considered as the first package if it is not an a-z string.
|
|
4785
|
-
function parsePackageSpecifiers(ecosystem, pkgs) {
|
|
4786
|
-
let valid = true;
|
|
4787
|
-
const purls = [];
|
|
4788
|
-
if (!ecosystem) {
|
|
4789
|
-
valid = false;
|
|
4790
|
-
} else if (/^[a-zA-Z]+$/.test(ecosystem)) {
|
|
4791
|
-
for (let i = 0; i < pkgs.length; ++i) {
|
|
4792
|
-
const pkg = pkgs[i] ?? '';
|
|
4793
|
-
if (!pkg) {
|
|
4794
|
-
valid = false;
|
|
4795
|
-
break;
|
|
4796
|
-
} else if (pkg.startsWith('pkg:')) {
|
|
4797
|
-
// keep
|
|
4798
|
-
purls.push(pkg);
|
|
4799
|
-
} else if (pkg.includes('/')) {
|
|
4800
|
-
// Looks like this arg was already namespaced
|
|
4801
|
-
purls.push('pkg:' + pkg);
|
|
4802
|
-
} else {
|
|
4803
|
-
purls.push('pkg:' + ecosystem + '/' + pkg);
|
|
4804
|
-
}
|
|
4805
|
-
}
|
|
4806
|
-
if (!purls.length) {
|
|
4807
|
-
valid = false;
|
|
4808
|
-
}
|
|
4809
|
-
} else {
|
|
4810
|
-
// Assume ecosystem is a purl, too
|
|
4811
|
-
pkgs.unshift(ecosystem);
|
|
4812
|
-
for (let i = 0; i < pkgs.length; ++i) {
|
|
4813
|
-
const pkg = pkgs[i] ?? '';
|
|
4814
|
-
if (!/^(?:pkg:)?[a-zA-Z]+\/./.test(pkg)) {
|
|
4815
|
-
// At least one purl did not start with `pkg:eco/x` or `eco/x`
|
|
4816
|
-
valid = false;
|
|
4817
|
-
break;
|
|
4818
|
-
} else if (pkg.startsWith('pkg:')) {
|
|
4819
|
-
purls.push(pkg);
|
|
4820
|
-
} else {
|
|
4821
|
-
purls.push('pkg:' + pkg);
|
|
4822
|
-
}
|
|
4823
|
-
}
|
|
4824
|
-
if (!purls.length) {
|
|
4825
|
-
valid = false;
|
|
4826
|
-
}
|
|
4827
|
-
}
|
|
4828
|
-
return {
|
|
4829
|
-
purls,
|
|
4830
|
-
valid
|
|
4831
|
-
};
|
|
4832
|
-
}
|
|
4833
|
-
|
|
4834
|
-
async function fetchPackageInfo(purls) {
|
|
4835
|
-
const socketSdk = await shadowNpmInject.setupSdk(shadowNpmInject.getPublicToken());
|
|
4948
|
+
async function fetchPurlsShallowScore(purls) {
|
|
4949
|
+
logger.logger.error(`Requesting shallow score data for ${purls.length} package urls (purl): ${purls.join(', ')}`);
|
|
4836
4950
|
|
|
4837
4951
|
// Lazily access constants.spinner.
|
|
4838
4952
|
const {
|
|
4839
4953
|
spinner
|
|
4840
4954
|
} = constants;
|
|
4841
|
-
logger.logger.error(`Requesting shallow score data for ${purls.length} package urls (purl): ${purls.join(', ')}`);
|
|
4842
4955
|
spinner.start(`Requesting data ...`);
|
|
4956
|
+
const socketSdk = await shadowNpmInject.setupSdk(shadowNpmInject.getPublicToken());
|
|
4843
4957
|
const result = await handleApiCall(socketSdk.batchPackageFetch({
|
|
4844
4958
|
alerts: 'true'
|
|
4845
4959
|
// compact: false,
|
|
@@ -4854,12 +4968,11 @@ async function fetchPackageInfo(purls) {
|
|
|
4854
4968
|
spinner.successAndStop('Request completed');
|
|
4855
4969
|
if (result.success) {
|
|
4856
4970
|
return result;
|
|
4857
|
-
} else {
|
|
4858
|
-
handleUnsuccessfulApiResponse('batchPackageFetch', result);
|
|
4859
4971
|
}
|
|
4972
|
+
handleUnsuccessfulApiResponse('batchPackageFetch', result);
|
|
4860
4973
|
}
|
|
4861
4974
|
|
|
4862
|
-
function
|
|
4975
|
+
function outputPurlsShallowScore(purls, packageData, outputKind) {
|
|
4863
4976
|
if (outputKind === 'json') {
|
|
4864
4977
|
// In JSON simply return what the server responds with. Don't bother trying
|
|
4865
4978
|
// to match the response with the requested packages/purls.
|
|
@@ -4939,16 +5052,69 @@ function getAlertString(alerts, noColor = false) {
|
|
|
4939
5052
|
}
|
|
4940
5053
|
}
|
|
4941
5054
|
|
|
4942
|
-
async function
|
|
5055
|
+
async function handlePurlsShallowScore({
|
|
4943
5056
|
outputKind,
|
|
4944
5057
|
purls
|
|
4945
5058
|
}) {
|
|
4946
|
-
const packageData = await
|
|
5059
|
+
const packageData = await fetchPurlsShallowScore(purls);
|
|
4947
5060
|
if (packageData) {
|
|
4948
|
-
|
|
5061
|
+
outputPurlsShallowScore(purls, packageData.data, outputKind);
|
|
4949
5062
|
}
|
|
4950
5063
|
}
|
|
4951
5064
|
|
|
5065
|
+
// Either an ecosystem was given or all args must be (namespaced) purls
|
|
5066
|
+
// The `pkg:` part is optional here. We'll scan for `eco/name@version`.
|
|
5067
|
+
// Not hardcoding the namespace since we don't know what the server accepts.
|
|
5068
|
+
// The ecosystem is considered as the first package if it is not an a-z string.
|
|
5069
|
+
function parsePackageSpecifiers(ecosystem, pkgs) {
|
|
5070
|
+
let valid = true;
|
|
5071
|
+
const purls = [];
|
|
5072
|
+
if (!ecosystem) {
|
|
5073
|
+
valid = false;
|
|
5074
|
+
} else if (/^[a-zA-Z]+$/.test(ecosystem)) {
|
|
5075
|
+
for (let i = 0; i < pkgs.length; ++i) {
|
|
5076
|
+
const pkg = pkgs[i] ?? '';
|
|
5077
|
+
if (!pkg) {
|
|
5078
|
+
valid = false;
|
|
5079
|
+
break;
|
|
5080
|
+
} else if (pkg.startsWith('pkg:')) {
|
|
5081
|
+
// keep
|
|
5082
|
+
purls.push(pkg);
|
|
5083
|
+
} else if (pkg.includes('/')) {
|
|
5084
|
+
// Looks like this arg was already namespaced
|
|
5085
|
+
purls.push('pkg:' + pkg);
|
|
5086
|
+
} else {
|
|
5087
|
+
purls.push('pkg:' + ecosystem + '/' + pkg);
|
|
5088
|
+
}
|
|
5089
|
+
}
|
|
5090
|
+
if (!purls.length) {
|
|
5091
|
+
valid = false;
|
|
5092
|
+
}
|
|
5093
|
+
} else {
|
|
5094
|
+
// Assume ecosystem is a purl, too
|
|
5095
|
+
pkgs.unshift(ecosystem);
|
|
5096
|
+
for (let i = 0; i < pkgs.length; ++i) {
|
|
5097
|
+
const pkg = pkgs[i] ?? '';
|
|
5098
|
+
if (!/^(?:pkg:)?[a-zA-Z]+\/./.test(pkg)) {
|
|
5099
|
+
// At least one purl did not start with `pkg:eco/x` or `eco/x`
|
|
5100
|
+
valid = false;
|
|
5101
|
+
break;
|
|
5102
|
+
} else if (pkg.startsWith('pkg:')) {
|
|
5103
|
+
purls.push(pkg);
|
|
5104
|
+
} else {
|
|
5105
|
+
purls.push('pkg:' + pkg);
|
|
5106
|
+
}
|
|
5107
|
+
}
|
|
5108
|
+
if (!purls.length) {
|
|
5109
|
+
valid = false;
|
|
5110
|
+
}
|
|
5111
|
+
}
|
|
5112
|
+
return {
|
|
5113
|
+
purls,
|
|
5114
|
+
valid
|
|
5115
|
+
};
|
|
5116
|
+
}
|
|
5117
|
+
|
|
4952
5118
|
const {
|
|
4953
5119
|
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$h
|
|
4954
5120
|
} = constants;
|
|
@@ -5038,7 +5204,7 @@ async function run$h(argv, importMeta, {
|
|
|
5038
5204
|
logger.logger.log(DRY_RUN_BAIL_TEXT$h);
|
|
5039
5205
|
return;
|
|
5040
5206
|
}
|
|
5041
|
-
await
|
|
5207
|
+
await handlePurlsShallowScore({
|
|
5042
5208
|
outputKind: json ? 'json' : markdown ? 'markdown' : 'text',
|
|
5043
5209
|
purls
|
|
5044
5210
|
});
|
|
@@ -5317,10 +5483,10 @@ async function getFullScan(orgSlug, fullScanId) {
|
|
|
5317
5483
|
throw new shadowNpmInject.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
5318
5484
|
}
|
|
5319
5485
|
spinner.start('Fetching full-scan...');
|
|
5320
|
-
const response = await
|
|
5486
|
+
const response = await queryApi(`orgs/${orgSlug}/full-scans/${encodeURIComponent(fullScanId)}`, apiToken);
|
|
5321
5487
|
spinner.stop('Fetch complete.');
|
|
5322
5488
|
if (!response.ok) {
|
|
5323
|
-
const err = await
|
|
5489
|
+
const err = await handleApiError(response.status);
|
|
5324
5490
|
logger.logger.fail(`${colors.bgRed(colors.white(response.statusText))}: Fetch error: ${err}`);
|
|
5325
5491
|
return;
|
|
5326
5492
|
}
|
|
@@ -5514,7 +5680,7 @@ const cmdReport = {
|
|
|
5514
5680
|
}
|
|
5515
5681
|
};
|
|
5516
5682
|
|
|
5517
|
-
async function
|
|
5683
|
+
async function fetchCreateRepo({
|
|
5518
5684
|
default_branch,
|
|
5519
5685
|
description,
|
|
5520
5686
|
homepage,
|
|
@@ -5526,8 +5692,7 @@ async function createRepo({
|
|
|
5526
5692
|
if (!apiToken) {
|
|
5527
5693
|
throw new shadowNpmInject.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
5528
5694
|
}
|
|
5529
|
-
await
|
|
5530
|
-
apiToken,
|
|
5695
|
+
return await fetchCreateRepoWithToken(apiToken, {
|
|
5531
5696
|
default_branch,
|
|
5532
5697
|
description,
|
|
5533
5698
|
homepage,
|
|
@@ -5536,8 +5701,7 @@ async function createRepo({
|
|
|
5536
5701
|
visibility
|
|
5537
5702
|
});
|
|
5538
5703
|
}
|
|
5539
|
-
async function
|
|
5540
|
-
apiToken,
|
|
5704
|
+
async function fetchCreateRepoWithToken(apiToken, {
|
|
5541
5705
|
default_branch,
|
|
5542
5706
|
description,
|
|
5543
5707
|
homepage,
|
|
@@ -5549,8 +5713,8 @@ async function createRepoWithToken({
|
|
|
5549
5713
|
const {
|
|
5550
5714
|
spinner
|
|
5551
5715
|
} = constants;
|
|
5552
|
-
spinner.start('Creating repository...');
|
|
5553
5716
|
const socketSdk = await shadowNpmInject.setupSdk(apiToken);
|
|
5717
|
+
spinner.start('Sending request ot create a repository...');
|
|
5554
5718
|
const result = await handleApiCall(socketSdk.createOrgRepo(orgSlug, {
|
|
5555
5719
|
name: repoName,
|
|
5556
5720
|
description,
|
|
@@ -5558,11 +5722,36 @@ async function createRepoWithToken({
|
|
|
5558
5722
|
default_branch,
|
|
5559
5723
|
visibility
|
|
5560
5724
|
}), 'creating repository');
|
|
5725
|
+
spinner.successAndStop('Received response requesting to create a repository.');
|
|
5561
5726
|
if (!result.success) {
|
|
5562
5727
|
handleUnsuccessfulApiResponse('createOrgRepo', result);
|
|
5563
5728
|
return;
|
|
5564
5729
|
}
|
|
5565
|
-
|
|
5730
|
+
return result.data;
|
|
5731
|
+
}
|
|
5732
|
+
|
|
5733
|
+
async function outputCreateRepo(_data) {
|
|
5734
|
+
logger.logger.success('Repository created successfully');
|
|
5735
|
+
}
|
|
5736
|
+
|
|
5737
|
+
async function handleCreateRepo({
|
|
5738
|
+
default_branch,
|
|
5739
|
+
description,
|
|
5740
|
+
homepage,
|
|
5741
|
+
orgSlug,
|
|
5742
|
+
repoName,
|
|
5743
|
+
visibility
|
|
5744
|
+
}) {
|
|
5745
|
+
const data = await fetchCreateRepo({
|
|
5746
|
+
default_branch,
|
|
5747
|
+
description,
|
|
5748
|
+
homepage,
|
|
5749
|
+
orgSlug,
|
|
5750
|
+
repoName,
|
|
5751
|
+
visibility
|
|
5752
|
+
});
|
|
5753
|
+
if (!data) return;
|
|
5754
|
+
await outputCreateRepo();
|
|
5566
5755
|
}
|
|
5567
5756
|
|
|
5568
5757
|
const {
|
|
@@ -5648,7 +5837,7 @@ async function run$c(argv, importMeta, {
|
|
|
5648
5837
|
logger.logger.log(DRY_RUN_BAIL_TEXT$c);
|
|
5649
5838
|
return;
|
|
5650
5839
|
}
|
|
5651
|
-
await
|
|
5840
|
+
await handleCreateRepo({
|
|
5652
5841
|
orgSlug,
|
|
5653
5842
|
repoName,
|
|
5654
5843
|
description: String(cli.flags['repoDescription'] || ''),
|
|
@@ -5658,7 +5847,7 @@ async function run$c(argv, importMeta, {
|
|
|
5658
5847
|
});
|
|
5659
5848
|
}
|
|
5660
5849
|
|
|
5661
|
-
async function
|
|
5850
|
+
async function handleDeleteRepo(orgSlug, repoName) {
|
|
5662
5851
|
const apiToken = shadowNpmInject.getDefaultToken();
|
|
5663
5852
|
if (!apiToken) {
|
|
5664
5853
|
throw new shadowNpmInject.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
@@ -5734,14 +5923,12 @@ async function run$b(argv, importMeta, {
|
|
|
5734
5923
|
logger.logger.log(DRY_RUN_BAIL_TEXT$b);
|
|
5735
5924
|
return;
|
|
5736
5925
|
}
|
|
5737
|
-
await
|
|
5926
|
+
await handleDeleteRepo(orgSlug, repoName);
|
|
5738
5927
|
}
|
|
5739
5928
|
|
|
5740
|
-
|
|
5741
|
-
async function listRepos({
|
|
5929
|
+
async function fetchListRepos({
|
|
5742
5930
|
direction,
|
|
5743
5931
|
orgSlug,
|
|
5744
|
-
outputKind,
|
|
5745
5932
|
page,
|
|
5746
5933
|
per_page,
|
|
5747
5934
|
sort
|
|
@@ -5750,21 +5937,17 @@ async function listRepos({
|
|
|
5750
5937
|
if (!apiToken) {
|
|
5751
5938
|
throw new shadowNpmInject.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
5752
5939
|
}
|
|
5753
|
-
await
|
|
5754
|
-
apiToken,
|
|
5940
|
+
return await fetchListReposWithToken(apiToken, {
|
|
5755
5941
|
direction,
|
|
5756
5942
|
orgSlug,
|
|
5757
|
-
outputKind,
|
|
5758
5943
|
page,
|
|
5759
5944
|
per_page,
|
|
5760
5945
|
sort
|
|
5761
5946
|
});
|
|
5762
5947
|
}
|
|
5763
|
-
async function
|
|
5764
|
-
apiToken,
|
|
5948
|
+
async function fetchListReposWithToken(apiToken, {
|
|
5765
5949
|
direction,
|
|
5766
5950
|
orgSlug,
|
|
5767
|
-
outputKind,
|
|
5768
5951
|
page,
|
|
5769
5952
|
per_page,
|
|
5770
5953
|
sort
|
|
@@ -5773,28 +5956,33 @@ async function listReposWithToken({
|
|
|
5773
5956
|
const {
|
|
5774
5957
|
spinner
|
|
5775
5958
|
} = constants;
|
|
5776
|
-
spinner.start('Fetching list of repositories...');
|
|
5777
5959
|
const socketSdk = await shadowNpmInject.setupSdk(apiToken);
|
|
5960
|
+
spinner.start('Fetching list of repositories...');
|
|
5778
5961
|
const result = await handleApiCall(socketSdk.getOrgRepoList(orgSlug, {
|
|
5779
5962
|
sort,
|
|
5780
5963
|
direction,
|
|
5781
5964
|
per_page: String(per_page),
|
|
5782
5965
|
page: String(page)
|
|
5783
5966
|
}), 'listing repositories');
|
|
5967
|
+
spinner.successAndStop('Received response for repository list.');
|
|
5784
5968
|
if (!result.success) {
|
|
5785
5969
|
handleUnsuccessfulApiResponse('getOrgRepoList', result);
|
|
5786
5970
|
return;
|
|
5787
5971
|
}
|
|
5788
|
-
|
|
5972
|
+
return result.data;
|
|
5973
|
+
}
|
|
5974
|
+
|
|
5975
|
+
// @ts-ignore
|
|
5976
|
+
async function outputListRepos(data, outputKind) {
|
|
5789
5977
|
if (outputKind === 'json') {
|
|
5790
|
-
const
|
|
5978
|
+
const json = data.results.map(o => ({
|
|
5791
5979
|
id: o.id,
|
|
5792
5980
|
name: o.name,
|
|
5793
5981
|
visibility: o.visibility,
|
|
5794
5982
|
defaultBranch: o.default_branch,
|
|
5795
5983
|
archived: o.archived
|
|
5796
5984
|
}));
|
|
5797
|
-
logger.logger.log(JSON.stringify(
|
|
5985
|
+
logger.logger.log(JSON.stringify(json, null, 2));
|
|
5798
5986
|
return;
|
|
5799
5987
|
}
|
|
5800
5988
|
const options = {
|
|
@@ -5815,7 +6003,26 @@ async function listReposWithToken({
|
|
|
5815
6003
|
name: colors.magenta('Archived')
|
|
5816
6004
|
}]
|
|
5817
6005
|
};
|
|
5818
|
-
logger.logger.log(chalkTable(options,
|
|
6006
|
+
logger.logger.log(chalkTable(options, data.results));
|
|
6007
|
+
}
|
|
6008
|
+
|
|
6009
|
+
async function handleListRepos({
|
|
6010
|
+
direction,
|
|
6011
|
+
orgSlug,
|
|
6012
|
+
outputKind,
|
|
6013
|
+
page,
|
|
6014
|
+
per_page,
|
|
6015
|
+
sort
|
|
6016
|
+
}) {
|
|
6017
|
+
const data = await fetchListRepos({
|
|
6018
|
+
direction,
|
|
6019
|
+
orgSlug,
|
|
6020
|
+
page,
|
|
6021
|
+
per_page,
|
|
6022
|
+
sort
|
|
6023
|
+
});
|
|
6024
|
+
if (!data) return;
|
|
6025
|
+
await outputListRepos(data, outputKind);
|
|
5819
6026
|
}
|
|
5820
6027
|
|
|
5821
6028
|
const {
|
|
@@ -5894,7 +6101,7 @@ async function run$a(argv, importMeta, {
|
|
|
5894
6101
|
logger.logger.log(DRY_RUN_BAIL_TEXT$a);
|
|
5895
6102
|
return;
|
|
5896
6103
|
}
|
|
5897
|
-
await
|
|
6104
|
+
await handleListRepos({
|
|
5898
6105
|
direction: cli.flags['direction'] === 'asc' ? 'asc' : 'desc',
|
|
5899
6106
|
orgSlug,
|
|
5900
6107
|
outputKind: cli.flags['json'] ? 'json' : cli.flags['markdown'] ? 'markdown' : 'print',
|
|
@@ -5904,7 +6111,7 @@ async function run$a(argv, importMeta, {
|
|
|
5904
6111
|
});
|
|
5905
6112
|
}
|
|
5906
6113
|
|
|
5907
|
-
async function
|
|
6114
|
+
async function fetchUpdateRepo({
|
|
5908
6115
|
default_branch,
|
|
5909
6116
|
description,
|
|
5910
6117
|
homepage,
|
|
@@ -5916,8 +6123,7 @@ async function updateRepo({
|
|
|
5916
6123
|
if (!apiToken) {
|
|
5917
6124
|
throw new shadowNpmInject.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
5918
6125
|
}
|
|
5919
|
-
await
|
|
5920
|
-
apiToken,
|
|
6126
|
+
return await fetchUpdateRepoWithToken(apiToken, {
|
|
5921
6127
|
default_branch,
|
|
5922
6128
|
description,
|
|
5923
6129
|
homepage,
|
|
@@ -5926,8 +6132,7 @@ async function updateRepo({
|
|
|
5926
6132
|
visibility
|
|
5927
6133
|
});
|
|
5928
6134
|
}
|
|
5929
|
-
async function
|
|
5930
|
-
apiToken,
|
|
6135
|
+
async function fetchUpdateRepoWithToken(apiToken, {
|
|
5931
6136
|
default_branch,
|
|
5932
6137
|
description,
|
|
5933
6138
|
homepage,
|
|
@@ -5939,7 +6144,7 @@ async function updateRepoWithToken({
|
|
|
5939
6144
|
const {
|
|
5940
6145
|
spinner
|
|
5941
6146
|
} = constants;
|
|
5942
|
-
spinner.start('
|
|
6147
|
+
spinner.start('Sending request to update a repository...');
|
|
5943
6148
|
const socketSdk = await shadowNpmInject.setupSdk(apiToken);
|
|
5944
6149
|
const result = await handleApiCall(socketSdk.updateOrgRepo(orgSlug, repoName, {
|
|
5945
6150
|
orgSlug,
|
|
@@ -5949,11 +6154,36 @@ async function updateRepoWithToken({
|
|
|
5949
6154
|
default_branch,
|
|
5950
6155
|
visibility
|
|
5951
6156
|
}), 'updating repository');
|
|
6157
|
+
spinner.successAndStop('Received response trying to update a repository');
|
|
5952
6158
|
if (!result.success) {
|
|
5953
6159
|
handleUnsuccessfulApiResponse('updateOrgRepo', result);
|
|
5954
6160
|
return;
|
|
5955
6161
|
}
|
|
5956
|
-
|
|
6162
|
+
return result.data;
|
|
6163
|
+
}
|
|
6164
|
+
|
|
6165
|
+
async function outputUpdateRepo(_data) {
|
|
6166
|
+
logger.logger.success('Repository updated successfully');
|
|
6167
|
+
}
|
|
6168
|
+
|
|
6169
|
+
async function handleUpdateRepo({
|
|
6170
|
+
default_branch,
|
|
6171
|
+
description,
|
|
6172
|
+
homepage,
|
|
6173
|
+
orgSlug,
|
|
6174
|
+
repoName,
|
|
6175
|
+
visibility
|
|
6176
|
+
}) {
|
|
6177
|
+
const data = await fetchUpdateRepo({
|
|
6178
|
+
default_branch,
|
|
6179
|
+
description,
|
|
6180
|
+
homepage,
|
|
6181
|
+
orgSlug,
|
|
6182
|
+
repoName,
|
|
6183
|
+
visibility
|
|
6184
|
+
});
|
|
6185
|
+
if (!data) return;
|
|
6186
|
+
await outputUpdateRepo();
|
|
5957
6187
|
}
|
|
5958
6188
|
|
|
5959
6189
|
const {
|
|
@@ -6041,7 +6271,7 @@ async function run$9(argv, importMeta, {
|
|
|
6041
6271
|
logger.logger.log(DRY_RUN_BAIL_TEXT$9);
|
|
6042
6272
|
return;
|
|
6043
6273
|
}
|
|
6044
|
-
await
|
|
6274
|
+
await handleUpdateRepo({
|
|
6045
6275
|
orgSlug,
|
|
6046
6276
|
repoName,
|
|
6047
6277
|
description: String(cli.flags['repoDescription'] || ''),
|
|
@@ -6051,27 +6281,31 @@ async function run$9(argv, importMeta, {
|
|
|
6051
6281
|
});
|
|
6052
6282
|
}
|
|
6053
6283
|
|
|
6054
|
-
|
|
6055
|
-
async function viewRepo(orgSlug, repoName, outputKind) {
|
|
6284
|
+
async function fetchViewRepo(orgSlug, repoName) {
|
|
6056
6285
|
const apiToken = shadowNpmInject.getDefaultToken();
|
|
6057
6286
|
if (!apiToken) {
|
|
6058
6287
|
throw new shadowNpmInject.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
6059
6288
|
}
|
|
6060
|
-
await
|
|
6289
|
+
return await fetchViewRepoWithToken(orgSlug, repoName, apiToken);
|
|
6061
6290
|
}
|
|
6062
|
-
async function
|
|
6291
|
+
async function fetchViewRepoWithToken(orgSlug, repoName, apiToken) {
|
|
6063
6292
|
// Lazily access constants.spinner.
|
|
6064
6293
|
const {
|
|
6065
6294
|
spinner
|
|
6066
6295
|
} = constants;
|
|
6067
|
-
spinner.start('Fetching repository data...');
|
|
6068
6296
|
const socketSdk = await shadowNpmInject.setupSdk(apiToken);
|
|
6297
|
+
spinner.start('Fetching repository data...');
|
|
6069
6298
|
const result = await handleApiCall(socketSdk.getOrgRepo(orgSlug, repoName), 'fetching repository');
|
|
6299
|
+
spinner.successAndStop('Received response while fetched repository data.');
|
|
6070
6300
|
if (!result.success) {
|
|
6071
6301
|
handleUnsuccessfulApiResponse('getOrgRepo', result);
|
|
6072
6302
|
return;
|
|
6073
6303
|
}
|
|
6074
|
-
|
|
6304
|
+
return result.data;
|
|
6305
|
+
}
|
|
6306
|
+
|
|
6307
|
+
// @ts-ignore
|
|
6308
|
+
async function outputViewRepo(data, outputKind) {
|
|
6075
6309
|
if (outputKind === 'json') {
|
|
6076
6310
|
const {
|
|
6077
6311
|
archived,
|
|
@@ -6081,7 +6315,7 @@ async function viewRepoWithToken(orgSlug, repoName, apiToken, outputKind) {
|
|
|
6081
6315
|
id,
|
|
6082
6316
|
name,
|
|
6083
6317
|
visibility
|
|
6084
|
-
} =
|
|
6318
|
+
} = data;
|
|
6085
6319
|
logger.logger.log(JSON.stringify({
|
|
6086
6320
|
id,
|
|
6087
6321
|
name,
|
|
@@ -6117,7 +6351,13 @@ async function viewRepoWithToken(orgSlug, repoName, apiToken, outputKind) {
|
|
|
6117
6351
|
name: colors.magenta('Created at')
|
|
6118
6352
|
}]
|
|
6119
6353
|
};
|
|
6120
|
-
logger.logger.log(chalkTable(options, [
|
|
6354
|
+
logger.logger.log(chalkTable(options, [data]));
|
|
6355
|
+
}
|
|
6356
|
+
|
|
6357
|
+
async function handleViewRepo(orgSlug, repoName, outputKind) {
|
|
6358
|
+
const data = await fetchViewRepo(orgSlug, repoName);
|
|
6359
|
+
if (!data) return;
|
|
6360
|
+
await outputViewRepo(data, outputKind);
|
|
6121
6361
|
}
|
|
6122
6362
|
|
|
6123
6363
|
const {
|
|
@@ -6161,7 +6401,11 @@ async function run$8(argv, importMeta, {
|
|
|
6161
6401
|
importMeta,
|
|
6162
6402
|
parentName
|
|
6163
6403
|
});
|
|
6164
|
-
const
|
|
6404
|
+
const {
|
|
6405
|
+
json,
|
|
6406
|
+
markdown,
|
|
6407
|
+
repoName
|
|
6408
|
+
} = cli.flags;
|
|
6165
6409
|
const [orgSlug = ''] = cli.input;
|
|
6166
6410
|
if (!repoName || typeof repoName !== 'string' || !orgSlug) {
|
|
6167
6411
|
// Use exit status of 2 to indicate incorrect usage, generally invalid
|
|
@@ -6181,7 +6425,7 @@ async function run$8(argv, importMeta, {
|
|
|
6181
6425
|
logger.logger.log(DRY_RUN_BAIL_TEXT$8);
|
|
6182
6426
|
return;
|
|
6183
6427
|
}
|
|
6184
|
-
await
|
|
6428
|
+
await handleViewRepo(orgSlug, repoName, json ? 'json' : markdown ? 'markdown' : 'text');
|
|
6185
6429
|
}
|
|
6186
6430
|
|
|
6187
6431
|
const description$1 = 'Repositories related commands';
|
|
@@ -7071,11 +7315,11 @@ includeSecurityPolicy) {
|
|
|
7071
7315
|
// licensePolicyMaybe,
|
|
7072
7316
|
securityPolicyMaybe] = await Promise.all([(async () => {
|
|
7073
7317
|
try {
|
|
7074
|
-
const response = await
|
|
7318
|
+
const response = await queryApi(`orgs/${orgSlug}/full-scans/${encodeURIComponent(fullScanId)}`, apiToken);
|
|
7075
7319
|
haveScan = true;
|
|
7076
7320
|
updateProgress();
|
|
7077
7321
|
if (!response.ok) {
|
|
7078
|
-
const err = await
|
|
7322
|
+
const err = await handleApiError(response.status);
|
|
7079
7323
|
logger.logger.fail(`${colors.bgRed(colors.white(response.statusText))}: Fetch error: ${err}`);
|
|
7080
7324
|
return undefined;
|
|
7081
7325
|
}
|
|
@@ -7789,7 +8033,7 @@ async function getThreatFeedWithToken({
|
|
|
7789
8033
|
} = constants;
|
|
7790
8034
|
const queryParams = new URLSearchParams([['direction', direction], ['ecosystem', ecosystem], ['filter', filter], ['page', page], ['per_page', String(perPage)]]);
|
|
7791
8035
|
spinner.start('Fetching Threat Feed data...');
|
|
7792
|
-
const response = await
|
|
8036
|
+
const response = await queryApi(`threat-feed?${queryParams}`, apiToken);
|
|
7793
8037
|
const data = await response.json();
|
|
7794
8038
|
spinner.stop('Threat feed data fetched');
|
|
7795
8039
|
if (outputKind === 'json') {
|
|
@@ -8212,7 +8456,7 @@ void (async () => {
|
|
|
8212
8456
|
await vendor.updater({
|
|
8213
8457
|
name: SOCKET_CLI_BIN_NAME,
|
|
8214
8458
|
// The '@rollup/plugin-replace' will replace "process.env['INLINED_SOCKET_CLI_VERSION']".
|
|
8215
|
-
version: "0.14.
|
|
8459
|
+
version: "0.14.66",
|
|
8216
8460
|
ttl: 86_400_000 /* 24 hours in milliseconds */
|
|
8217
8461
|
});
|
|
8218
8462
|
try {
|
|
@@ -8279,5 +8523,5 @@ void (async () => {
|
|
|
8279
8523
|
await shadowNpmInject.captureException(e);
|
|
8280
8524
|
}
|
|
8281
8525
|
})();
|
|
8282
|
-
//# debugId=
|
|
8526
|
+
//# debugId=442c46c8-a006-4075-9a1a-7cc92b7b9849
|
|
8283
8527
|
//# sourceMappingURL=cli.js.map
|