@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/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:3a36e9f3: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();
|
|
@@ -2308,10 +2435,17 @@ async function run$x(argv, importMeta, {
|
|
|
2308
2435
|
await runFix();
|
|
2309
2436
|
}
|
|
2310
2437
|
|
|
2311
|
-
async function fetchPackageInfo
|
|
2438
|
+
async function fetchPackageInfo(pkgName, pkgVersion, includeAllIssues) {
|
|
2312
2439
|
const socketSdk = await shadowNpmInject.setupSdk(shadowNpmInject.getPublicToken());
|
|
2440
|
+
|
|
2441
|
+
// Lazily access constants.spinner.
|
|
2442
|
+
const {
|
|
2443
|
+
spinner
|
|
2444
|
+
} = constants;
|
|
2445
|
+
spinner.start(pkgVersion === 'latest' ? `Looking up data for the latest version of ${pkgName}` : `Looking up data for version ${pkgVersion} of ${pkgName}`);
|
|
2313
2446
|
const result = await handleApiCall(socketSdk.getIssuesByNPMPackage(pkgName, pkgVersion), 'looking up package');
|
|
2314
2447
|
const scoreResult = await handleApiCall(socketSdk.getScoreByNPMPackage(pkgName, pkgVersion), 'looking up package score');
|
|
2448
|
+
spinner.successAndStop('Data fetched');
|
|
2315
2449
|
if (result.success === false) {
|
|
2316
2450
|
return handleUnsuccessfulApiResponse('getIssuesByNPMPackage', result);
|
|
2317
2451
|
}
|
|
@@ -2337,8 +2471,8 @@ function formatScore$1(score) {
|
|
|
2337
2471
|
}
|
|
2338
2472
|
return colors.red(`${score}`);
|
|
2339
2473
|
}
|
|
2340
|
-
function
|
|
2341
|
-
const issueDetails = packageData.filter(d => d.value?.severity === shadowNpmInject.
|
|
2474
|
+
function outputPackageIssuesDetails(packageData, outputMarkdown) {
|
|
2475
|
+
const issueDetails = packageData.filter(d => d.value?.severity === shadowNpmInject.ALERT_SEVERITY.critical || d.value?.severity === shadowNpmInject.ALERT_SEVERITY.high);
|
|
2342
2476
|
const uniqueIssueDetails = issueDetails.reduce((acc, issue) => {
|
|
2343
2477
|
const {
|
|
2344
2478
|
type
|
|
@@ -2368,7 +2502,7 @@ function logPackageIssuesDetails(packageData, outputMarkdown) {
|
|
|
2368
2502
|
}
|
|
2369
2503
|
}
|
|
2370
2504
|
}
|
|
2371
|
-
function
|
|
2505
|
+
function outputPackageInfo({
|
|
2372
2506
|
data,
|
|
2373
2507
|
score,
|
|
2374
2508
|
severityCount
|
|
@@ -2406,7 +2540,7 @@ function logPackageInfo$1({
|
|
|
2406
2540
|
logger.logger.log('# Issues\n');
|
|
2407
2541
|
}
|
|
2408
2542
|
logger.logger.log(`Package has these issues: ${shadowNpmInject.formatSeverityCount(severityCount)}\n`);
|
|
2409
|
-
|
|
2543
|
+
outputPackageIssuesDetails(data, outputKind === 'markdown');
|
|
2410
2544
|
} else {
|
|
2411
2545
|
logger.logger.log('Package has no issues');
|
|
2412
2546
|
}
|
|
@@ -2429,7 +2563,7 @@ function logPackageInfo$1({
|
|
|
2429
2563
|
}
|
|
2430
2564
|
}
|
|
2431
2565
|
|
|
2432
|
-
async function
|
|
2566
|
+
async function handlePackageInfo({
|
|
2433
2567
|
commandName,
|
|
2434
2568
|
includeAllIssues,
|
|
2435
2569
|
outputKind,
|
|
@@ -2437,15 +2571,9 @@ async function getPackageInfo({
|
|
|
2437
2571
|
pkgVersion,
|
|
2438
2572
|
strict
|
|
2439
2573
|
}) {
|
|
2440
|
-
|
|
2441
|
-
const {
|
|
2442
|
-
spinner
|
|
2443
|
-
} = constants;
|
|
2444
|
-
spinner.start(pkgVersion === 'latest' ? `Looking up data for the latest version of ${pkgName}` : `Looking up data for version ${pkgVersion} of ${pkgName}`);
|
|
2445
|
-
const packageData = await fetchPackageInfo$1(pkgName, pkgVersion, includeAllIssues);
|
|
2446
|
-
spinner.successAndStop('Data fetched');
|
|
2574
|
+
const packageData = await fetchPackageInfo(pkgName, pkgVersion, includeAllIssues);
|
|
2447
2575
|
if (packageData) {
|
|
2448
|
-
|
|
2576
|
+
outputPackageInfo(packageData, {
|
|
2449
2577
|
name: commandName,
|
|
2450
2578
|
outputKind,
|
|
2451
2579
|
pkgName,
|
|
@@ -2520,7 +2648,7 @@ async function run$w(argv, importMeta, {
|
|
|
2520
2648
|
logger.logger.log(DRY_RUN_BAIL_TEXT$v);
|
|
2521
2649
|
return;
|
|
2522
2650
|
}
|
|
2523
|
-
await
|
|
2651
|
+
await handlePackageInfo({
|
|
2524
2652
|
commandName: `${parentName} ${config$w.commandName}`,
|
|
2525
2653
|
includeAllIssues: Boolean(all),
|
|
2526
2654
|
outputKind: json ? 'json' : markdown ? 'markdown' : 'print',
|
|
@@ -4410,29 +4538,35 @@ async function run$l(argv, importMeta, {
|
|
|
4410
4538
|
await applyOptimization(cwd, Boolean(cli.flags['pin']), Boolean(cli.flags['prod']));
|
|
4411
4539
|
}
|
|
4412
4540
|
|
|
4413
|
-
async function
|
|
4541
|
+
async function fetchOrganization() {
|
|
4414
4542
|
const apiToken = shadowNpmInject.getDefaultToken();
|
|
4415
4543
|
if (!apiToken) {
|
|
4416
4544
|
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.');
|
|
4417
4545
|
}
|
|
4418
|
-
await
|
|
4546
|
+
return await fetchOrganizationWithToken(apiToken);
|
|
4419
4547
|
}
|
|
4420
|
-
async function
|
|
4548
|
+
async function fetchOrganizationWithToken(apiToken) {
|
|
4549
|
+
const socketSdk = await shadowNpmInject.setupSdk(apiToken);
|
|
4550
|
+
|
|
4421
4551
|
// Lazily access constants.spinner.
|
|
4422
4552
|
const {
|
|
4423
4553
|
spinner
|
|
4424
4554
|
} = constants;
|
|
4425
|
-
spinner.start('Fetching
|
|
4426
|
-
const socketSdk = await shadowNpmInject.setupSdk(apiToken);
|
|
4555
|
+
spinner.start('Fetching organization list...');
|
|
4427
4556
|
const result = await handleApiCall(socketSdk.getOrganizations(), 'looking up organizations');
|
|
4557
|
+
spinner.successAndStop('Received organization list response.');
|
|
4428
4558
|
if (!result.success) {
|
|
4429
4559
|
handleUnsuccessfulApiResponse('getOrganizations', result);
|
|
4430
4560
|
return;
|
|
4431
4561
|
}
|
|
4432
|
-
|
|
4433
|
-
|
|
4434
|
-
|
|
4435
|
-
|
|
4562
|
+
return result.data;
|
|
4563
|
+
}
|
|
4564
|
+
|
|
4565
|
+
async function outputOrganizationList(data, outputKind = 'text') {
|
|
4566
|
+
const organizations = Object.values(data.organizations);
|
|
4567
|
+
const apiToken = shadowNpmInject.getDefaultToken();
|
|
4568
|
+
const lastFiveOfApiToken = getLastFiveOfApiToken(apiToken ?? '?????');
|
|
4569
|
+
switch (outputKind) {
|
|
4436
4570
|
case 'json':
|
|
4437
4571
|
{
|
|
4438
4572
|
logger.logger.log(JSON.stringify(organizations.map(o => ({
|
|
@@ -4477,6 +4611,12 @@ async function printOrganizationsFromToken(apiToken, format = 'text') {
|
|
|
4477
4611
|
}
|
|
4478
4612
|
}
|
|
4479
4613
|
|
|
4614
|
+
async function handleOrganizationList(outputKind = 'text') {
|
|
4615
|
+
const data = await fetchOrganization();
|
|
4616
|
+
if (!data) return;
|
|
4617
|
+
await outputOrganizationList(data, outputKind);
|
|
4618
|
+
}
|
|
4619
|
+
|
|
4480
4620
|
const {
|
|
4481
4621
|
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$k
|
|
4482
4622
|
} = constants;
|
|
@@ -4528,48 +4668,63 @@ ${colors.bgRed(colors.white('Input error'))}: Please provide the required fields
|
|
|
4528
4668
|
logger.logger.log(DRY_RUN_BAIL_TEXT$k);
|
|
4529
4669
|
return;
|
|
4530
4670
|
}
|
|
4531
|
-
await
|
|
4671
|
+
await handleOrganizationList(json ? 'json' : markdown ? 'markdown' : 'text');
|
|
4532
4672
|
}
|
|
4533
4673
|
|
|
4534
|
-
async function
|
|
4674
|
+
async function fetchSecurityPolicy(orgSlug) {
|
|
4535
4675
|
const apiToken = shadowNpmInject.getDefaultToken();
|
|
4536
4676
|
if (!apiToken) {
|
|
4537
4677
|
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.');
|
|
4538
4678
|
}
|
|
4539
|
-
await
|
|
4679
|
+
return await fetchSecurityPolicyWithToken(apiToken, orgSlug);
|
|
4540
4680
|
}
|
|
4541
|
-
async function
|
|
4681
|
+
async function fetchSecurityPolicyWithToken(apiToken, orgSlug) {
|
|
4542
4682
|
// Lazily access constants.spinner.
|
|
4543
4683
|
const {
|
|
4544
4684
|
spinner
|
|
4545
4685
|
} = constants;
|
|
4546
|
-
spinner.start('Fetching organization quota...');
|
|
4547
4686
|
const socketSdk = await shadowNpmInject.setupSdk(apiToken);
|
|
4687
|
+
spinner.start('Fetching organization quota...');
|
|
4548
4688
|
const result = await handleApiCall(socketSdk.getOrgSecurityPolicy(orgSlug), 'looking up organization quota');
|
|
4689
|
+
spinner?.successAndStop('Received organization quota response.');
|
|
4549
4690
|
if (!result.success) {
|
|
4550
4691
|
handleUnsuccessfulApiResponse('getOrgSecurityPolicy', result);
|
|
4551
4692
|
return;
|
|
4552
4693
|
}
|
|
4553
|
-
|
|
4554
|
-
|
|
4555
|
-
|
|
4556
|
-
|
|
4557
|
-
|
|
4558
|
-
|
|
4559
|
-
|
|
4560
|
-
|
|
4561
|
-
|
|
4562
|
-
|
|
4563
|
-
|
|
4564
|
-
|
|
4565
|
-
|
|
4566
|
-
|
|
4567
|
-
|
|
4568
|
-
const mapped = entries.map(([key, value]) => [key, value.action]);
|
|
4569
|
-
mapped.sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
|
|
4570
|
-
logger.logger.log(mdTableOfPairs(mapped, ['name', 'action']));
|
|
4571
|
-
}
|
|
4694
|
+
return result.data;
|
|
4695
|
+
}
|
|
4696
|
+
|
|
4697
|
+
async function getSecurityPolicy(data, outputKind) {
|
|
4698
|
+
if (outputKind === 'json') {
|
|
4699
|
+
let json;
|
|
4700
|
+
try {
|
|
4701
|
+
json = JSON.stringify(data, null, 2);
|
|
4702
|
+
} catch {
|
|
4703
|
+
console.error('Failed to convert the server response to json, try running the same command without --json');
|
|
4704
|
+
return;
|
|
4705
|
+
}
|
|
4706
|
+
logger.logger.log(json);
|
|
4707
|
+
logger.logger.log('');
|
|
4708
|
+
return;
|
|
4572
4709
|
}
|
|
4710
|
+
logger.logger.log('# Security policy');
|
|
4711
|
+
logger.logger.log('');
|
|
4712
|
+
logger.logger.log(`The default security policy setting is: "${data.securityPolicyDefault}"`);
|
|
4713
|
+
logger.logger.log('');
|
|
4714
|
+
logger.logger.log('These are the security policies per setting for your organization:');
|
|
4715
|
+
logger.logger.log('');
|
|
4716
|
+
const rules = data.securityPolicyRules;
|
|
4717
|
+
const entries = Object.entries(rules);
|
|
4718
|
+
const mapped = entries.map(([key, value]) => [key, value.action]);
|
|
4719
|
+
mapped.sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
|
|
4720
|
+
logger.logger.log(mdTableOfPairs(mapped, ['name', 'action']));
|
|
4721
|
+
logger.logger.log('');
|
|
4722
|
+
}
|
|
4723
|
+
|
|
4724
|
+
async function handleSecurityPolicy(orgSlug, outputKind) {
|
|
4725
|
+
const data = await fetchSecurityPolicy(orgSlug);
|
|
4726
|
+
if (!data) return;
|
|
4727
|
+
await getSecurityPolicy(data, outputKind);
|
|
4573
4728
|
}
|
|
4574
4729
|
|
|
4575
4730
|
const {
|
|
@@ -4634,7 +4789,7 @@ ${colors.bgRed(colors.white('Input error'))}: Please provide the required fields
|
|
|
4634
4789
|
logger.logger.log(DRY_RUN_BAIL_TEXT$j);
|
|
4635
4790
|
return;
|
|
4636
4791
|
}
|
|
4637
|
-
await
|
|
4792
|
+
await handleSecurityPolicy(orgSlug, json ? 'json' : markdown ? 'markdown' : 'text');
|
|
4638
4793
|
}
|
|
4639
4794
|
|
|
4640
4795
|
const description$5 = 'Organization policy details';
|
|
@@ -4661,45 +4816,57 @@ const cmdOrganizationPolicy = {
|
|
|
4661
4816
|
}
|
|
4662
4817
|
};
|
|
4663
4818
|
|
|
4664
|
-
async function
|
|
4819
|
+
async function fetchQuota() {
|
|
4665
4820
|
const apiToken = shadowNpmInject.getDefaultToken();
|
|
4666
4821
|
if (!apiToken) {
|
|
4667
4822
|
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.');
|
|
4668
4823
|
}
|
|
4669
|
-
await
|
|
4824
|
+
return await fetchQuotaWithToken(apiToken);
|
|
4670
4825
|
}
|
|
4671
|
-
async function
|
|
4826
|
+
async function fetchQuotaWithToken(apiToken) {
|
|
4672
4827
|
// Lazily access constants.spinner.
|
|
4673
4828
|
const {
|
|
4674
4829
|
spinner
|
|
4675
4830
|
} = constants;
|
|
4676
|
-
spinner.start('Fetching organization quota...');
|
|
4677
4831
|
const socketSdk = await shadowNpmInject.setupSdk(apiToken);
|
|
4832
|
+
spinner.start('Fetching organization quota...');
|
|
4678
4833
|
const result = await handleApiCall(socketSdk.getQuota(), 'looking up organization quota');
|
|
4834
|
+
spinner?.successAndStop('Recieved organization quota response.');
|
|
4679
4835
|
if (!result.success) {
|
|
4680
4836
|
handleUnsuccessfulApiResponse('getQuota', result);
|
|
4681
4837
|
return;
|
|
4682
4838
|
}
|
|
4683
|
-
|
|
4684
|
-
|
|
4685
|
-
|
|
4686
|
-
|
|
4687
|
-
|
|
4688
|
-
|
|
4689
|
-
|
|
4690
|
-
|
|
4691
|
-
|
|
4692
|
-
|
|
4693
|
-
|
|
4694
|
-
|
|
4695
|
-
|
|
4696
|
-
|
|
4697
|
-
|
|
4698
|
-
default:
|
|
4699
|
-
{
|
|
4700
|
-
logger.logger.log(`Quota left on the current API token: ${result.data.quota}\n`);
|
|
4701
|
-
}
|
|
4839
|
+
return result.data;
|
|
4840
|
+
}
|
|
4841
|
+
|
|
4842
|
+
async function outputQuota(data, outputKind = 'text') {
|
|
4843
|
+
if (outputKind === 'json') {
|
|
4844
|
+
let json;
|
|
4845
|
+
try {
|
|
4846
|
+
json = JSON.stringify(data, null, 2);
|
|
4847
|
+
} catch {
|
|
4848
|
+
console.error('Failed to convert the server response to json, try running the same command without --json');
|
|
4849
|
+
return;
|
|
4850
|
+
}
|
|
4851
|
+
logger.logger.log(json);
|
|
4852
|
+
logger.logger.log('');
|
|
4853
|
+
return;
|
|
4702
4854
|
}
|
|
4855
|
+
if (outputKind === 'markdown') {
|
|
4856
|
+
logger.logger.log('# Quota');
|
|
4857
|
+
logger.logger.log('');
|
|
4858
|
+
logger.logger.log(`Quota left on the current API token: ${data.quota}`);
|
|
4859
|
+
logger.logger.log('');
|
|
4860
|
+
return;
|
|
4861
|
+
}
|
|
4862
|
+
logger.logger.log(`Quota left on the current API token: ${data.quota}`);
|
|
4863
|
+
logger.logger.log('');
|
|
4864
|
+
}
|
|
4865
|
+
|
|
4866
|
+
async function handleQuota(outputKind = 'text') {
|
|
4867
|
+
const data = await fetchQuota();
|
|
4868
|
+
if (!data) return;
|
|
4869
|
+
await outputQuota(data, outputKind);
|
|
4703
4870
|
}
|
|
4704
4871
|
|
|
4705
4872
|
const {
|
|
@@ -4753,7 +4920,7 @@ ${colors.bgRed(colors.white('Input error'))}: Please provide the required fields
|
|
|
4753
4920
|
logger.logger.log(DRY_RUN_BAIL_TEXT$i);
|
|
4754
4921
|
return;
|
|
4755
4922
|
}
|
|
4756
|
-
await
|
|
4923
|
+
await handleQuota(json ? 'json' : markdown ? 'markdown' : 'text');
|
|
4757
4924
|
}
|
|
4758
4925
|
|
|
4759
4926
|
const description$4 = 'Account details';
|
|
@@ -4782,68 +4949,15 @@ const cmdOrganization = {
|
|
|
4782
4949
|
}
|
|
4783
4950
|
};
|
|
4784
4951
|
|
|
4785
|
-
|
|
4786
|
-
|
|
4787
|
-
// Not hardcoding the namespace since we don't know what the server accepts.
|
|
4788
|
-
// The ecosystem is considered as the first package if it is not an a-z string.
|
|
4789
|
-
function parsePackageSpecifiers(ecosystem, pkgs) {
|
|
4790
|
-
let valid = true;
|
|
4791
|
-
const purls = [];
|
|
4792
|
-
if (!ecosystem) {
|
|
4793
|
-
valid = false;
|
|
4794
|
-
} else if (/^[a-zA-Z]+$/.test(ecosystem)) {
|
|
4795
|
-
for (let i = 0; i < pkgs.length; ++i) {
|
|
4796
|
-
const pkg = pkgs[i] ?? '';
|
|
4797
|
-
if (!pkg) {
|
|
4798
|
-
valid = false;
|
|
4799
|
-
break;
|
|
4800
|
-
} else if (pkg.startsWith('pkg:')) {
|
|
4801
|
-
// keep
|
|
4802
|
-
purls.push(pkg);
|
|
4803
|
-
} else if (pkg.includes('/')) {
|
|
4804
|
-
// Looks like this arg was already namespaced
|
|
4805
|
-
purls.push('pkg:' + pkg);
|
|
4806
|
-
} else {
|
|
4807
|
-
purls.push('pkg:' + ecosystem + '/' + pkg);
|
|
4808
|
-
}
|
|
4809
|
-
}
|
|
4810
|
-
if (!purls.length) {
|
|
4811
|
-
valid = false;
|
|
4812
|
-
}
|
|
4813
|
-
} else {
|
|
4814
|
-
// Assume ecosystem is a purl, too
|
|
4815
|
-
pkgs.unshift(ecosystem);
|
|
4816
|
-
for (let i = 0; i < pkgs.length; ++i) {
|
|
4817
|
-
const pkg = pkgs[i] ?? '';
|
|
4818
|
-
if (!/^(?:pkg:)?[a-zA-Z]+\/./.test(pkg)) {
|
|
4819
|
-
// At least one purl did not start with `pkg:eco/x` or `eco/x`
|
|
4820
|
-
valid = false;
|
|
4821
|
-
break;
|
|
4822
|
-
} else if (pkg.startsWith('pkg:')) {
|
|
4823
|
-
purls.push(pkg);
|
|
4824
|
-
} else {
|
|
4825
|
-
purls.push('pkg:' + pkg);
|
|
4826
|
-
}
|
|
4827
|
-
}
|
|
4828
|
-
if (!purls.length) {
|
|
4829
|
-
valid = false;
|
|
4830
|
-
}
|
|
4831
|
-
}
|
|
4832
|
-
return {
|
|
4833
|
-
purls,
|
|
4834
|
-
valid
|
|
4835
|
-
};
|
|
4836
|
-
}
|
|
4837
|
-
|
|
4838
|
-
async function fetchPackageInfo(purls) {
|
|
4839
|
-
const socketSdk = await shadowNpmInject.setupSdk(shadowNpmInject.getPublicToken());
|
|
4952
|
+
async function fetchPurlsShallowScore(purls) {
|
|
4953
|
+
logger.logger.error(`Requesting shallow score data for ${purls.length} package urls (purl): ${purls.join(', ')}`);
|
|
4840
4954
|
|
|
4841
4955
|
// Lazily access constants.spinner.
|
|
4842
4956
|
const {
|
|
4843
4957
|
spinner
|
|
4844
4958
|
} = constants;
|
|
4845
|
-
logger.logger.error(`Requesting shallow score data for ${purls.length} package urls (purl): ${purls.join(', ')}`);
|
|
4846
4959
|
spinner.start(`Requesting data ...`);
|
|
4960
|
+
const socketSdk = await shadowNpmInject.setupSdk(shadowNpmInject.getPublicToken());
|
|
4847
4961
|
const result = await handleApiCall(socketSdk.batchPackageFetch({
|
|
4848
4962
|
alerts: 'true'
|
|
4849
4963
|
// compact: false,
|
|
@@ -4858,12 +4972,11 @@ async function fetchPackageInfo(purls) {
|
|
|
4858
4972
|
spinner.successAndStop('Request completed');
|
|
4859
4973
|
if (result.success) {
|
|
4860
4974
|
return result;
|
|
4861
|
-
} else {
|
|
4862
|
-
handleUnsuccessfulApiResponse('batchPackageFetch', result);
|
|
4863
4975
|
}
|
|
4976
|
+
handleUnsuccessfulApiResponse('batchPackageFetch', result);
|
|
4864
4977
|
}
|
|
4865
4978
|
|
|
4866
|
-
function
|
|
4979
|
+
function outputPurlsShallowScore(purls, packageData, outputKind) {
|
|
4867
4980
|
if (outputKind === 'json') {
|
|
4868
4981
|
// In JSON simply return what the server responds with. Don't bother trying
|
|
4869
4982
|
// to match the response with the requested packages/purls.
|
|
@@ -4943,16 +5056,69 @@ function getAlertString(alerts, noColor = false) {
|
|
|
4943
5056
|
}
|
|
4944
5057
|
}
|
|
4945
5058
|
|
|
4946
|
-
async function
|
|
5059
|
+
async function handlePurlsShallowScore({
|
|
4947
5060
|
outputKind,
|
|
4948
5061
|
purls
|
|
4949
5062
|
}) {
|
|
4950
|
-
const packageData = await
|
|
5063
|
+
const packageData = await fetchPurlsShallowScore(purls);
|
|
4951
5064
|
if (packageData) {
|
|
4952
|
-
|
|
5065
|
+
outputPurlsShallowScore(purls, packageData.data, outputKind);
|
|
4953
5066
|
}
|
|
4954
5067
|
}
|
|
4955
5068
|
|
|
5069
|
+
// Either an ecosystem was given or all args must be (namespaced) purls
|
|
5070
|
+
// The `pkg:` part is optional here. We'll scan for `eco/name@version`.
|
|
5071
|
+
// Not hardcoding the namespace since we don't know what the server accepts.
|
|
5072
|
+
// The ecosystem is considered as the first package if it is not an a-z string.
|
|
5073
|
+
function parsePackageSpecifiers(ecosystem, pkgs) {
|
|
5074
|
+
let valid = true;
|
|
5075
|
+
const purls = [];
|
|
5076
|
+
if (!ecosystem) {
|
|
5077
|
+
valid = false;
|
|
5078
|
+
} else if (/^[a-zA-Z]+$/.test(ecosystem)) {
|
|
5079
|
+
for (let i = 0; i < pkgs.length; ++i) {
|
|
5080
|
+
const pkg = pkgs[i] ?? '';
|
|
5081
|
+
if (!pkg) {
|
|
5082
|
+
valid = false;
|
|
5083
|
+
break;
|
|
5084
|
+
} else if (pkg.startsWith('pkg:')) {
|
|
5085
|
+
// keep
|
|
5086
|
+
purls.push(pkg);
|
|
5087
|
+
} else if (pkg.includes('/')) {
|
|
5088
|
+
// Looks like this arg was already namespaced
|
|
5089
|
+
purls.push('pkg:' + pkg);
|
|
5090
|
+
} else {
|
|
5091
|
+
purls.push('pkg:' + ecosystem + '/' + pkg);
|
|
5092
|
+
}
|
|
5093
|
+
}
|
|
5094
|
+
if (!purls.length) {
|
|
5095
|
+
valid = false;
|
|
5096
|
+
}
|
|
5097
|
+
} else {
|
|
5098
|
+
// Assume ecosystem is a purl, too
|
|
5099
|
+
pkgs.unshift(ecosystem);
|
|
5100
|
+
for (let i = 0; i < pkgs.length; ++i) {
|
|
5101
|
+
const pkg = pkgs[i] ?? '';
|
|
5102
|
+
if (!/^(?:pkg:)?[a-zA-Z]+\/./.test(pkg)) {
|
|
5103
|
+
// At least one purl did not start with `pkg:eco/x` or `eco/x`
|
|
5104
|
+
valid = false;
|
|
5105
|
+
break;
|
|
5106
|
+
} else if (pkg.startsWith('pkg:')) {
|
|
5107
|
+
purls.push(pkg);
|
|
5108
|
+
} else {
|
|
5109
|
+
purls.push('pkg:' + pkg);
|
|
5110
|
+
}
|
|
5111
|
+
}
|
|
5112
|
+
if (!purls.length) {
|
|
5113
|
+
valid = false;
|
|
5114
|
+
}
|
|
5115
|
+
}
|
|
5116
|
+
return {
|
|
5117
|
+
purls,
|
|
5118
|
+
valid
|
|
5119
|
+
};
|
|
5120
|
+
}
|
|
5121
|
+
|
|
4956
5122
|
const {
|
|
4957
5123
|
DRY_RUN_BAIL_TEXT: DRY_RUN_BAIL_TEXT$h
|
|
4958
5124
|
} = constants;
|
|
@@ -5042,7 +5208,7 @@ async function run$h(argv, importMeta, {
|
|
|
5042
5208
|
logger.logger.log(DRY_RUN_BAIL_TEXT$h);
|
|
5043
5209
|
return;
|
|
5044
5210
|
}
|
|
5045
|
-
await
|
|
5211
|
+
await handlePurlsShallowScore({
|
|
5046
5212
|
outputKind: json ? 'json' : markdown ? 'markdown' : 'text',
|
|
5047
5213
|
purls
|
|
5048
5214
|
});
|
|
@@ -5321,10 +5487,10 @@ async function getFullScan(orgSlug, fullScanId) {
|
|
|
5321
5487
|
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.');
|
|
5322
5488
|
}
|
|
5323
5489
|
spinner.start('Fetching full-scan...');
|
|
5324
|
-
const response = await
|
|
5490
|
+
const response = await queryApi(`orgs/${orgSlug}/full-scans/${encodeURIComponent(fullScanId)}`, apiToken);
|
|
5325
5491
|
spinner.stop('Fetch complete.');
|
|
5326
5492
|
if (!response.ok) {
|
|
5327
|
-
const err = await
|
|
5493
|
+
const err = await handleApiError(response.status);
|
|
5328
5494
|
logger.logger.fail(`${colors.bgRed(colors.white(response.statusText))}: Fetch error: ${err}`);
|
|
5329
5495
|
return;
|
|
5330
5496
|
}
|
|
@@ -5518,7 +5684,7 @@ const cmdReport = {
|
|
|
5518
5684
|
}
|
|
5519
5685
|
};
|
|
5520
5686
|
|
|
5521
|
-
async function
|
|
5687
|
+
async function fetchCreateRepo({
|
|
5522
5688
|
default_branch,
|
|
5523
5689
|
description,
|
|
5524
5690
|
homepage,
|
|
@@ -5530,8 +5696,7 @@ async function createRepo({
|
|
|
5530
5696
|
if (!apiToken) {
|
|
5531
5697
|
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.');
|
|
5532
5698
|
}
|
|
5533
|
-
await
|
|
5534
|
-
apiToken,
|
|
5699
|
+
return await fetchCreateRepoWithToken(apiToken, {
|
|
5535
5700
|
default_branch,
|
|
5536
5701
|
description,
|
|
5537
5702
|
homepage,
|
|
@@ -5540,8 +5705,7 @@ async function createRepo({
|
|
|
5540
5705
|
visibility
|
|
5541
5706
|
});
|
|
5542
5707
|
}
|
|
5543
|
-
async function
|
|
5544
|
-
apiToken,
|
|
5708
|
+
async function fetchCreateRepoWithToken(apiToken, {
|
|
5545
5709
|
default_branch,
|
|
5546
5710
|
description,
|
|
5547
5711
|
homepage,
|
|
@@ -5553,8 +5717,8 @@ async function createRepoWithToken({
|
|
|
5553
5717
|
const {
|
|
5554
5718
|
spinner
|
|
5555
5719
|
} = constants;
|
|
5556
|
-
spinner.start('Creating repository...');
|
|
5557
5720
|
const socketSdk = await shadowNpmInject.setupSdk(apiToken);
|
|
5721
|
+
spinner.start('Sending request ot create a repository...');
|
|
5558
5722
|
const result = await handleApiCall(socketSdk.createOrgRepo(orgSlug, {
|
|
5559
5723
|
name: repoName,
|
|
5560
5724
|
description,
|
|
@@ -5562,11 +5726,36 @@ async function createRepoWithToken({
|
|
|
5562
5726
|
default_branch,
|
|
5563
5727
|
visibility
|
|
5564
5728
|
}), 'creating repository');
|
|
5729
|
+
spinner.successAndStop('Received response requesting to create a repository.');
|
|
5565
5730
|
if (!result.success) {
|
|
5566
5731
|
handleUnsuccessfulApiResponse('createOrgRepo', result);
|
|
5567
5732
|
return;
|
|
5568
5733
|
}
|
|
5569
|
-
|
|
5734
|
+
return result.data;
|
|
5735
|
+
}
|
|
5736
|
+
|
|
5737
|
+
async function outputCreateRepo(_data) {
|
|
5738
|
+
logger.logger.success('Repository created successfully');
|
|
5739
|
+
}
|
|
5740
|
+
|
|
5741
|
+
async function handleCreateRepo({
|
|
5742
|
+
default_branch,
|
|
5743
|
+
description,
|
|
5744
|
+
homepage,
|
|
5745
|
+
orgSlug,
|
|
5746
|
+
repoName,
|
|
5747
|
+
visibility
|
|
5748
|
+
}) {
|
|
5749
|
+
const data = await fetchCreateRepo({
|
|
5750
|
+
default_branch,
|
|
5751
|
+
description,
|
|
5752
|
+
homepage,
|
|
5753
|
+
orgSlug,
|
|
5754
|
+
repoName,
|
|
5755
|
+
visibility
|
|
5756
|
+
});
|
|
5757
|
+
if (!data) return;
|
|
5758
|
+
await outputCreateRepo();
|
|
5570
5759
|
}
|
|
5571
5760
|
|
|
5572
5761
|
const {
|
|
@@ -5652,7 +5841,7 @@ async function run$c(argv, importMeta, {
|
|
|
5652
5841
|
logger.logger.log(DRY_RUN_BAIL_TEXT$c);
|
|
5653
5842
|
return;
|
|
5654
5843
|
}
|
|
5655
|
-
await
|
|
5844
|
+
await handleCreateRepo({
|
|
5656
5845
|
orgSlug,
|
|
5657
5846
|
repoName,
|
|
5658
5847
|
description: String(cli.flags['repoDescription'] || ''),
|
|
@@ -5662,7 +5851,7 @@ async function run$c(argv, importMeta, {
|
|
|
5662
5851
|
});
|
|
5663
5852
|
}
|
|
5664
5853
|
|
|
5665
|
-
async function
|
|
5854
|
+
async function handleDeleteRepo(orgSlug, repoName) {
|
|
5666
5855
|
const apiToken = shadowNpmInject.getDefaultToken();
|
|
5667
5856
|
if (!apiToken) {
|
|
5668
5857
|
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.');
|
|
@@ -5738,14 +5927,12 @@ async function run$b(argv, importMeta, {
|
|
|
5738
5927
|
logger.logger.log(DRY_RUN_BAIL_TEXT$b);
|
|
5739
5928
|
return;
|
|
5740
5929
|
}
|
|
5741
|
-
await
|
|
5930
|
+
await handleDeleteRepo(orgSlug, repoName);
|
|
5742
5931
|
}
|
|
5743
5932
|
|
|
5744
|
-
|
|
5745
|
-
async function listRepos({
|
|
5933
|
+
async function fetchListRepos({
|
|
5746
5934
|
direction,
|
|
5747
5935
|
orgSlug,
|
|
5748
|
-
outputKind,
|
|
5749
5936
|
page,
|
|
5750
5937
|
per_page,
|
|
5751
5938
|
sort
|
|
@@ -5754,21 +5941,17 @@ async function listRepos({
|
|
|
5754
5941
|
if (!apiToken) {
|
|
5755
5942
|
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.');
|
|
5756
5943
|
}
|
|
5757
|
-
await
|
|
5758
|
-
apiToken,
|
|
5944
|
+
return await fetchListReposWithToken(apiToken, {
|
|
5759
5945
|
direction,
|
|
5760
5946
|
orgSlug,
|
|
5761
|
-
outputKind,
|
|
5762
5947
|
page,
|
|
5763
5948
|
per_page,
|
|
5764
5949
|
sort
|
|
5765
5950
|
});
|
|
5766
5951
|
}
|
|
5767
|
-
async function
|
|
5768
|
-
apiToken,
|
|
5952
|
+
async function fetchListReposWithToken(apiToken, {
|
|
5769
5953
|
direction,
|
|
5770
5954
|
orgSlug,
|
|
5771
|
-
outputKind,
|
|
5772
5955
|
page,
|
|
5773
5956
|
per_page,
|
|
5774
5957
|
sort
|
|
@@ -5777,28 +5960,33 @@ async function listReposWithToken({
|
|
|
5777
5960
|
const {
|
|
5778
5961
|
spinner
|
|
5779
5962
|
} = constants;
|
|
5780
|
-
spinner.start('Fetching list of repositories...');
|
|
5781
5963
|
const socketSdk = await shadowNpmInject.setupSdk(apiToken);
|
|
5964
|
+
spinner.start('Fetching list of repositories...');
|
|
5782
5965
|
const result = await handleApiCall(socketSdk.getOrgRepoList(orgSlug, {
|
|
5783
5966
|
sort,
|
|
5784
5967
|
direction,
|
|
5785
5968
|
per_page: String(per_page),
|
|
5786
5969
|
page: String(page)
|
|
5787
5970
|
}), 'listing repositories');
|
|
5971
|
+
spinner.successAndStop('Received response for repository list.');
|
|
5788
5972
|
if (!result.success) {
|
|
5789
5973
|
handleUnsuccessfulApiResponse('getOrgRepoList', result);
|
|
5790
5974
|
return;
|
|
5791
5975
|
}
|
|
5792
|
-
|
|
5976
|
+
return result.data;
|
|
5977
|
+
}
|
|
5978
|
+
|
|
5979
|
+
// @ts-ignore
|
|
5980
|
+
async function outputListRepos(data, outputKind) {
|
|
5793
5981
|
if (outputKind === 'json') {
|
|
5794
|
-
const
|
|
5982
|
+
const json = data.results.map(o => ({
|
|
5795
5983
|
id: o.id,
|
|
5796
5984
|
name: o.name,
|
|
5797
5985
|
visibility: o.visibility,
|
|
5798
5986
|
defaultBranch: o.default_branch,
|
|
5799
5987
|
archived: o.archived
|
|
5800
5988
|
}));
|
|
5801
|
-
logger.logger.log(JSON.stringify(
|
|
5989
|
+
logger.logger.log(JSON.stringify(json, null, 2));
|
|
5802
5990
|
return;
|
|
5803
5991
|
}
|
|
5804
5992
|
const options = {
|
|
@@ -5819,7 +6007,26 @@ async function listReposWithToken({
|
|
|
5819
6007
|
name: colors.magenta('Archived')
|
|
5820
6008
|
}]
|
|
5821
6009
|
};
|
|
5822
|
-
logger.logger.log(chalkTable(options,
|
|
6010
|
+
logger.logger.log(chalkTable(options, data.results));
|
|
6011
|
+
}
|
|
6012
|
+
|
|
6013
|
+
async function handleListRepos({
|
|
6014
|
+
direction,
|
|
6015
|
+
orgSlug,
|
|
6016
|
+
outputKind,
|
|
6017
|
+
page,
|
|
6018
|
+
per_page,
|
|
6019
|
+
sort
|
|
6020
|
+
}) {
|
|
6021
|
+
const data = await fetchListRepos({
|
|
6022
|
+
direction,
|
|
6023
|
+
orgSlug,
|
|
6024
|
+
page,
|
|
6025
|
+
per_page,
|
|
6026
|
+
sort
|
|
6027
|
+
});
|
|
6028
|
+
if (!data) return;
|
|
6029
|
+
await outputListRepos(data, outputKind);
|
|
5823
6030
|
}
|
|
5824
6031
|
|
|
5825
6032
|
const {
|
|
@@ -5898,7 +6105,7 @@ async function run$a(argv, importMeta, {
|
|
|
5898
6105
|
logger.logger.log(DRY_RUN_BAIL_TEXT$a);
|
|
5899
6106
|
return;
|
|
5900
6107
|
}
|
|
5901
|
-
await
|
|
6108
|
+
await handleListRepos({
|
|
5902
6109
|
direction: cli.flags['direction'] === 'asc' ? 'asc' : 'desc',
|
|
5903
6110
|
orgSlug,
|
|
5904
6111
|
outputKind: cli.flags['json'] ? 'json' : cli.flags['markdown'] ? 'markdown' : 'print',
|
|
@@ -5908,7 +6115,7 @@ async function run$a(argv, importMeta, {
|
|
|
5908
6115
|
});
|
|
5909
6116
|
}
|
|
5910
6117
|
|
|
5911
|
-
async function
|
|
6118
|
+
async function fetchUpdateRepo({
|
|
5912
6119
|
default_branch,
|
|
5913
6120
|
description,
|
|
5914
6121
|
homepage,
|
|
@@ -5920,8 +6127,7 @@ async function updateRepo({
|
|
|
5920
6127
|
if (!apiToken) {
|
|
5921
6128
|
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.');
|
|
5922
6129
|
}
|
|
5923
|
-
await
|
|
5924
|
-
apiToken,
|
|
6130
|
+
return await fetchUpdateRepoWithToken(apiToken, {
|
|
5925
6131
|
default_branch,
|
|
5926
6132
|
description,
|
|
5927
6133
|
homepage,
|
|
@@ -5930,8 +6136,7 @@ async function updateRepo({
|
|
|
5930
6136
|
visibility
|
|
5931
6137
|
});
|
|
5932
6138
|
}
|
|
5933
|
-
async function
|
|
5934
|
-
apiToken,
|
|
6139
|
+
async function fetchUpdateRepoWithToken(apiToken, {
|
|
5935
6140
|
default_branch,
|
|
5936
6141
|
description,
|
|
5937
6142
|
homepage,
|
|
@@ -5943,7 +6148,7 @@ async function updateRepoWithToken({
|
|
|
5943
6148
|
const {
|
|
5944
6149
|
spinner
|
|
5945
6150
|
} = constants;
|
|
5946
|
-
spinner.start('
|
|
6151
|
+
spinner.start('Sending request to update a repository...');
|
|
5947
6152
|
const socketSdk = await shadowNpmInject.setupSdk(apiToken);
|
|
5948
6153
|
const result = await handleApiCall(socketSdk.updateOrgRepo(orgSlug, repoName, {
|
|
5949
6154
|
orgSlug,
|
|
@@ -5953,11 +6158,36 @@ async function updateRepoWithToken({
|
|
|
5953
6158
|
default_branch,
|
|
5954
6159
|
visibility
|
|
5955
6160
|
}), 'updating repository');
|
|
6161
|
+
spinner.successAndStop('Received response trying to update a repository');
|
|
5956
6162
|
if (!result.success) {
|
|
5957
6163
|
handleUnsuccessfulApiResponse('updateOrgRepo', result);
|
|
5958
6164
|
return;
|
|
5959
6165
|
}
|
|
5960
|
-
|
|
6166
|
+
return result.data;
|
|
6167
|
+
}
|
|
6168
|
+
|
|
6169
|
+
async function outputUpdateRepo(_data) {
|
|
6170
|
+
logger.logger.success('Repository updated successfully');
|
|
6171
|
+
}
|
|
6172
|
+
|
|
6173
|
+
async function handleUpdateRepo({
|
|
6174
|
+
default_branch,
|
|
6175
|
+
description,
|
|
6176
|
+
homepage,
|
|
6177
|
+
orgSlug,
|
|
6178
|
+
repoName,
|
|
6179
|
+
visibility
|
|
6180
|
+
}) {
|
|
6181
|
+
const data = await fetchUpdateRepo({
|
|
6182
|
+
default_branch,
|
|
6183
|
+
description,
|
|
6184
|
+
homepage,
|
|
6185
|
+
orgSlug,
|
|
6186
|
+
repoName,
|
|
6187
|
+
visibility
|
|
6188
|
+
});
|
|
6189
|
+
if (!data) return;
|
|
6190
|
+
await outputUpdateRepo();
|
|
5961
6191
|
}
|
|
5962
6192
|
|
|
5963
6193
|
const {
|
|
@@ -6045,7 +6275,7 @@ async function run$9(argv, importMeta, {
|
|
|
6045
6275
|
logger.logger.log(DRY_RUN_BAIL_TEXT$9);
|
|
6046
6276
|
return;
|
|
6047
6277
|
}
|
|
6048
|
-
await
|
|
6278
|
+
await handleUpdateRepo({
|
|
6049
6279
|
orgSlug,
|
|
6050
6280
|
repoName,
|
|
6051
6281
|
description: String(cli.flags['repoDescription'] || ''),
|
|
@@ -6055,27 +6285,31 @@ async function run$9(argv, importMeta, {
|
|
|
6055
6285
|
});
|
|
6056
6286
|
}
|
|
6057
6287
|
|
|
6058
|
-
|
|
6059
|
-
async function viewRepo(orgSlug, repoName, outputKind) {
|
|
6288
|
+
async function fetchViewRepo(orgSlug, repoName) {
|
|
6060
6289
|
const apiToken = shadowNpmInject.getDefaultToken();
|
|
6061
6290
|
if (!apiToken) {
|
|
6062
6291
|
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.');
|
|
6063
6292
|
}
|
|
6064
|
-
await
|
|
6293
|
+
return await fetchViewRepoWithToken(orgSlug, repoName, apiToken);
|
|
6065
6294
|
}
|
|
6066
|
-
async function
|
|
6295
|
+
async function fetchViewRepoWithToken(orgSlug, repoName, apiToken) {
|
|
6067
6296
|
// Lazily access constants.spinner.
|
|
6068
6297
|
const {
|
|
6069
6298
|
spinner
|
|
6070
6299
|
} = constants;
|
|
6071
|
-
spinner.start('Fetching repository data...');
|
|
6072
6300
|
const socketSdk = await shadowNpmInject.setupSdk(apiToken);
|
|
6301
|
+
spinner.start('Fetching repository data...');
|
|
6073
6302
|
const result = await handleApiCall(socketSdk.getOrgRepo(orgSlug, repoName), 'fetching repository');
|
|
6303
|
+
spinner.successAndStop('Received response while fetched repository data.');
|
|
6074
6304
|
if (!result.success) {
|
|
6075
6305
|
handleUnsuccessfulApiResponse('getOrgRepo', result);
|
|
6076
6306
|
return;
|
|
6077
6307
|
}
|
|
6078
|
-
|
|
6308
|
+
return result.data;
|
|
6309
|
+
}
|
|
6310
|
+
|
|
6311
|
+
// @ts-ignore
|
|
6312
|
+
async function outputViewRepo(data, outputKind) {
|
|
6079
6313
|
if (outputKind === 'json') {
|
|
6080
6314
|
const {
|
|
6081
6315
|
archived,
|
|
@@ -6085,7 +6319,7 @@ async function viewRepoWithToken(orgSlug, repoName, apiToken, outputKind) {
|
|
|
6085
6319
|
id,
|
|
6086
6320
|
name,
|
|
6087
6321
|
visibility
|
|
6088
|
-
} =
|
|
6322
|
+
} = data;
|
|
6089
6323
|
logger.logger.log(JSON.stringify({
|
|
6090
6324
|
id,
|
|
6091
6325
|
name,
|
|
@@ -6121,7 +6355,13 @@ async function viewRepoWithToken(orgSlug, repoName, apiToken, outputKind) {
|
|
|
6121
6355
|
name: colors.magenta('Created at')
|
|
6122
6356
|
}]
|
|
6123
6357
|
};
|
|
6124
|
-
logger.logger.log(chalkTable(options, [
|
|
6358
|
+
logger.logger.log(chalkTable(options, [data]));
|
|
6359
|
+
}
|
|
6360
|
+
|
|
6361
|
+
async function handleViewRepo(orgSlug, repoName, outputKind) {
|
|
6362
|
+
const data = await fetchViewRepo(orgSlug, repoName);
|
|
6363
|
+
if (!data) return;
|
|
6364
|
+
await outputViewRepo(data, outputKind);
|
|
6125
6365
|
}
|
|
6126
6366
|
|
|
6127
6367
|
const {
|
|
@@ -6165,7 +6405,11 @@ async function run$8(argv, importMeta, {
|
|
|
6165
6405
|
importMeta,
|
|
6166
6406
|
parentName
|
|
6167
6407
|
});
|
|
6168
|
-
const
|
|
6408
|
+
const {
|
|
6409
|
+
json,
|
|
6410
|
+
markdown,
|
|
6411
|
+
repoName
|
|
6412
|
+
} = cli.flags;
|
|
6169
6413
|
const [orgSlug = ''] = cli.input;
|
|
6170
6414
|
if (!repoName || typeof repoName !== 'string' || !orgSlug) {
|
|
6171
6415
|
// Use exit status of 2 to indicate incorrect usage, generally invalid
|
|
@@ -6185,7 +6429,7 @@ async function run$8(argv, importMeta, {
|
|
|
6185
6429
|
logger.logger.log(DRY_RUN_BAIL_TEXT$8);
|
|
6186
6430
|
return;
|
|
6187
6431
|
}
|
|
6188
|
-
await
|
|
6432
|
+
await handleViewRepo(orgSlug, repoName, json ? 'json' : markdown ? 'markdown' : 'text');
|
|
6189
6433
|
}
|
|
6190
6434
|
|
|
6191
6435
|
const description$1 = 'Repositories related commands';
|
|
@@ -7075,11 +7319,11 @@ includeSecurityPolicy) {
|
|
|
7075
7319
|
// licensePolicyMaybe,
|
|
7076
7320
|
securityPolicyMaybe] = await Promise.all([(async () => {
|
|
7077
7321
|
try {
|
|
7078
|
-
const response = await
|
|
7322
|
+
const response = await queryApi(`orgs/${orgSlug}/full-scans/${encodeURIComponent(fullScanId)}`, apiToken);
|
|
7079
7323
|
haveScan = true;
|
|
7080
7324
|
updateProgress();
|
|
7081
7325
|
if (!response.ok) {
|
|
7082
|
-
const err = await
|
|
7326
|
+
const err = await handleApiError(response.status);
|
|
7083
7327
|
logger.logger.fail(`${colors.bgRed(colors.white(response.statusText))}: Fetch error: ${err}`);
|
|
7084
7328
|
return undefined;
|
|
7085
7329
|
}
|
|
@@ -7793,7 +8037,7 @@ async function getThreatFeedWithToken({
|
|
|
7793
8037
|
} = constants;
|
|
7794
8038
|
const queryParams = new URLSearchParams([['direction', direction], ['ecosystem', ecosystem], ['filter', filter], ['page', page], ['per_page', String(perPage)]]);
|
|
7795
8039
|
spinner.start('Fetching Threat Feed data...');
|
|
7796
|
-
const response = await
|
|
8040
|
+
const response = await queryApi(`threat-feed?${queryParams}`, apiToken);
|
|
7797
8041
|
const data = await response.json();
|
|
7798
8042
|
spinner.stop('Threat feed data fetched');
|
|
7799
8043
|
if (outputKind === 'json') {
|
|
@@ -8216,7 +8460,7 @@ void (async () => {
|
|
|
8216
8460
|
await updateNotifier({
|
|
8217
8461
|
name: SOCKET_CLI_BIN_NAME,
|
|
8218
8462
|
// The '@rollup/plugin-replace' will replace "process.env['INLINED_SOCKET_CLI_VERSION']".
|
|
8219
|
-
version: "0.14.
|
|
8463
|
+
version: "0.14.66",
|
|
8220
8464
|
ttl: 86_400_000 /* 24 hours in milliseconds */
|
|
8221
8465
|
});
|
|
8222
8466
|
try {
|
|
@@ -8283,5 +8527,5 @@ void (async () => {
|
|
|
8283
8527
|
await shadowNpmInject.captureException(e);
|
|
8284
8528
|
}
|
|
8285
8529
|
})();
|
|
8286
|
-
//# debugId=
|
|
8530
|
+
//# debugId=640f53d3-ca09-4212-b657-069970ae5d97
|
|
8287
8531
|
//# sourceMappingURL=cli.js.map
|