@socketsecurity/cli-with-sentry 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/instrument-with-sentry.js +2 -2
- package/dist/instrument-with-sentry.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 +12 -15
- 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:3a36e9f3: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();
|
|
@@ -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 vendor.updater({
|
|
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=af4902b3-7202-4316-abae-4f8c0524080c
|
|
8285
8529
|
//# sourceMappingURL=cli.js.map
|