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