@socketsecurity/cli-with-sentry 0.14.153 → 0.14.154

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/cli.js CHANGED
@@ -2045,8 +2045,8 @@ async function fetchSupportedScanFileNames() {
2045
2045
  'fetching supported scan file types'
2046
2046
  )
2047
2047
  spinner.stop()
2048
- logger.logger.success(
2049
- 'Received response while fetched supported scan file types.'
2048
+ logger.logger.error(
2049
+ 'Received response while fetching supported scan file types.'
2050
2050
  )
2051
2051
  if (!result.success) {
2052
2052
  return handleFailedApiResponse('getReportSupportedFiles', result)
@@ -2089,7 +2089,7 @@ async function fetchReportData(orgSlug, scanId, includeLicensePolicy) {
2089
2089
  function updateProgress() {
2090
2090
  if (finishedFetching) {
2091
2091
  spinner.stop()
2092
- logger.logger.info(
2092
+ logger.logger.error(
2093
2093
  `Scan result: ${scanStatus}. Security policy: ${policyStatus}.`
2094
2094
  )
2095
2095
  } else {
@@ -2110,7 +2110,7 @@ async function fetchReportData(orgSlug, scanId, includeLicensePolicy) {
2110
2110
  return {
2111
2111
  ok: false,
2112
2112
  message: 'Socket API returned an error',
2113
- cause: `${response.statusText}${err ? ` (cause: ${err}` : ''}`
2113
+ cause: `${response.statusText}${err ? ` (cause: ${err})` : ''}`
2114
2114
  }
2115
2115
  }
2116
2116
  updateScan(`ok, downloading response..`)
@@ -2196,6 +2196,8 @@ async function fetchReportData(orgSlug, scanId, includeLicensePolicy) {
2196
2196
  }
2197
2197
  }
2198
2198
 
2199
+ // Note: The returned cresult will only be ok:false when the generation
2200
+ // failed. It won't reflect the healthy state.
2199
2201
  function generateReport(
2200
2202
  scan,
2201
2203
  securityPolicy,
@@ -2334,21 +2336,36 @@ function generateReport(
2334
2336
  })
2335
2337
  }
2336
2338
  spinner?.successAndStop(`Generated reported in ${Date.now() - now} ms`)
2337
- const report = short
2338
- ? {
2339
+ if (short) {
2340
+ return {
2341
+ ok: true,
2342
+ data: {
2339
2343
  healthy
2340
2344
  }
2341
- : {
2342
- healthy,
2343
- orgSlug,
2344
- scanId,
2345
- options: {
2346
- fold,
2347
- reportLevel
2348
- },
2349
- alerts: violations
2350
- }
2351
- return report
2345
+ }
2346
+ }
2347
+ const report = {
2348
+ healthy,
2349
+ orgSlug,
2350
+ scanId,
2351
+ options: {
2352
+ fold,
2353
+ reportLevel
2354
+ },
2355
+ alerts: violations
2356
+ }
2357
+ if (!healthy) {
2358
+ return {
2359
+ ok: true,
2360
+ message:
2361
+ 'The report contains at least one alert that violates the policies set by your organization',
2362
+ data: report
2363
+ }
2364
+ }
2365
+ return {
2366
+ ok: true,
2367
+ data: report
2368
+ }
2352
2369
  }
2353
2370
  function createLeaf(art, alert, policyAction) {
2354
2371
  const leaf = {
@@ -2512,16 +2529,32 @@ async function outputScanReport(
2512
2529
  spinner: constants.spinner
2513
2530
  }
2514
2531
  )
2515
- if (!scanReport.healthy) {
2516
- process.exitCode = 1 // TODO: we could use a different code to distinct program error from health check failure...
2532
+ if (!scanReport.ok) {
2533
+ // Note: this means generation failed, it does not reflect the healthy state
2534
+ process.exitCode = scanReport.code ?? 1
2535
+
2536
+ // If report generation somehow failed then .data should not be set.
2537
+ if (outputKind === 'json') {
2538
+ logger.logger.log(serializeResultJson(scanReport))
2539
+ return
2540
+ }
2541
+ logger.logger.fail(failMsgWithBadge(scanReport.message, scanReport.cause))
2542
+ return
2517
2543
  }
2544
+
2545
+ // I don't think we emit the default error message with banner for an unhealhty report, do we?
2546
+ // if (!scanReport.data.healhty) {
2547
+ // logger.fail(failMsgWithBadge(scanReport.message, scanReport.cause))
2548
+ // return
2549
+ // }
2550
+
2518
2551
  if (
2519
2552
  outputKind === 'json' ||
2520
2553
  (outputKind === 'text' && filePath && filePath.endsWith('.json'))
2521
2554
  ) {
2522
2555
  const json = short
2523
- ? JSON.stringify(scanReport, null, 2)
2524
- : toJsonReport(scanReport, includeLicensePolicy)
2556
+ ? serializeResultJson(scanReport)
2557
+ : toJsonReport(scanReport.data, includeLicensePolicy)
2525
2558
  if (filePath && filePath !== '-') {
2526
2559
  logger.logger.log('Writing json report to', filePath)
2527
2560
  return await fs.writeFile(filePath, json)
@@ -2531,8 +2564,12 @@ async function outputScanReport(
2531
2564
  }
2532
2565
  if (outputKind === 'markdown' || (filePath && filePath.endsWith('.md'))) {
2533
2566
  const md = short
2534
- ? `healthy = ${scanReport.healthy}`
2535
- : toMarkdownReport(scanReport, includeLicensePolicy)
2567
+ ? `healthy = ${scanReport.data.healthy}`
2568
+ : toMarkdownReport(
2569
+ scanReport.data,
2570
+ // not short so must be regular report
2571
+ includeLicensePolicy
2572
+ )
2536
2573
  if (filePath && filePath !== '-') {
2537
2574
  logger.logger.log('Writing markdown report to', filePath)
2538
2575
  return await fs.writeFile(filePath, md)
@@ -2542,25 +2579,24 @@ async function outputScanReport(
2542
2579
  return
2543
2580
  }
2544
2581
  if (short) {
2545
- logger.logger.log(scanReport.healthy ? 'OK' : 'ERR')
2582
+ logger.logger.log(scanReport.data.healthy ? 'OK' : 'ERR')
2546
2583
  } else {
2547
- logger.logger.dir(scanReport, {
2584
+ logger.logger.dir(scanReport.data, {
2548
2585
  depth: null
2549
2586
  })
2550
2587
  }
2551
2588
  }
2552
2589
  function toJsonReport(report, includeLicensePolicy) {
2553
2590
  const obj = mapToObject(report.alerts)
2554
- const json = JSON.stringify(
2555
- {
2556
- includeLicensePolicy,
2557
- ...report,
2558
- alerts: obj
2559
- },
2560
- null,
2561
- 2
2562
- )
2563
- return json
2591
+ const newReport = {
2592
+ includeLicensePolicy,
2593
+ ...report,
2594
+ alerts: obj
2595
+ }
2596
+ return serializeResultJson({
2597
+ ok: true,
2598
+ data: newReport
2599
+ })
2564
2600
  }
2565
2601
  function toMarkdownReport(report, includeLicensePolicy) {
2566
2602
  const flatData = Array.from(walkNestedMap(report.alerts)).map(
@@ -4501,6 +4537,7 @@ async function npmFix(
4501
4537
 
4502
4538
  // Lazily access constants.ENV.CI.
4503
4539
  const isCi = constants.ENV.CI
4540
+ const baseBranch = isCi ? getBaseGitBranch() : ''
4504
4541
  const workspacePkgJsonPaths = await shadowNpmInject.globWorkspace(
4505
4542
  pkgEnvDetails.agent,
4506
4543
  rootPath
@@ -4634,6 +4671,13 @@ async function npmFix(
4634
4671
  debug.debugLog(
4635
4672
  `Nothing changed for ${workspaceName}, skipping install`
4636
4673
  )
4674
+ // Reset things just in case.
4675
+ if (isCi) {
4676
+ // eslint-disable-next-line no-await-in-loop
4677
+ await gitHardReset(baseBranch, cwd)
4678
+ // eslint-disable-next-line no-await-in-loop
4679
+ await gitCleanFdx(cwd)
4680
+ }
4637
4681
  continue
4638
4682
  }
4639
4683
  spinner?.info(`Installing ${newId} in ${workspaceName}`)
@@ -4659,7 +4703,6 @@ async function npmFix(
4659
4703
  errored = true
4660
4704
  error = e
4661
4705
  }
4662
- const baseBranch = isCi ? getBaseGitBranch() : ''
4663
4706
  if (!errored && isCi) {
4664
4707
  const branch = getSocketBranchName(
4665
4708
  oldPurl,
@@ -4722,7 +4765,9 @@ async function npmFix(
4722
4765
  // eslint-disable-next-line no-await-in-loop
4723
4766
  await Promise.all([
4724
4767
  shadowNpmInject.removeNodeModules(cwd),
4725
- editablePkgJson.save()
4768
+ editablePkgJson.save({
4769
+ ignoreWhitespace: true
4770
+ })
4726
4771
  ])
4727
4772
  // eslint-disable-next-line no-await-in-loop
4728
4773
  await install$1(arb.idealTree, {
@@ -4956,6 +5001,7 @@ async function pnpmFix(
4956
5001
 
4957
5002
  // Lazily access constants.ENV.CI.
4958
5003
  const isCi = constants.ENV.CI
5004
+ const baseBranch = isCi ? getBaseGitBranch() : ''
4959
5005
  const workspacePkgJsonPaths = await shadowNpmInject.globWorkspace(
4960
5006
  pkgEnvDetails.agent,
4961
5007
  rootPath
@@ -5120,6 +5166,13 @@ async function pnpmFix(
5120
5166
  debug.debugLog(
5121
5167
  `Nothing changed for ${workspaceName}, skipping install`
5122
5168
  )
5169
+ // Reset things just in case.
5170
+ if (isCi) {
5171
+ // eslint-disable-next-line no-await-in-loop
5172
+ await gitHardReset(baseBranch, cwd)
5173
+ // eslint-disable-next-line no-await-in-loop
5174
+ await gitCleanFdx(cwd)
5175
+ }
5123
5176
  continue
5124
5177
  }
5125
5178
  spinner?.info(`Installing ${newId} in ${workspaceName}`)
@@ -5146,7 +5199,6 @@ async function pnpmFix(
5146
5199
  error = e
5147
5200
  errored = true
5148
5201
  }
5149
- const baseBranch = isCi ? getBaseGitBranch() : ''
5150
5202
  if (!errored && isCi) {
5151
5203
  const branch = getSocketBranchName(
5152
5204
  oldPurl,
@@ -5210,7 +5262,9 @@ async function pnpmFix(
5210
5262
  // eslint-disable-next-line no-await-in-loop
5211
5263
  await Promise.all([
5212
5264
  shadowNpmInject.removeNodeModules(cwd),
5213
- editablePkgJson.save()
5265
+ editablePkgJson.save({
5266
+ ignoreWhitespace: true
5267
+ })
5214
5268
  ])
5215
5269
  // eslint-disable-next-line no-await-in-loop
5216
5270
  actualTree = await install(pkgEnvDetails, {
@@ -9020,7 +9074,7 @@ const cmdOrganization = {
9020
9074
  }
9021
9075
 
9022
9076
  async function fetchPurlDeepScore(purl) {
9023
- logger.logger.info(`Requesting deep score data for this purl: ${purl}`)
9077
+ logger.logger.error(`Requesting deep score data for this purl: ${purl}`)
9024
9078
  const apiToken = shadowNpmInject.getDefaultToken()
9025
9079
  if (!apiToken) {
9026
9080
  return {
@@ -9056,7 +9110,7 @@ async function fetchPurlDeepScore(purl) {
9056
9110
  return {
9057
9111
  ok: false,
9058
9112
  message: 'Socket API returned an error',
9059
- cause: `${result.statusText}${err ? ` (cause: ${err}` : ''}`
9113
+ cause: `${result.statusText}${err ? ` (cause: ${err})` : ''}`
9060
9114
  }
9061
9115
  }
9062
9116
  const data = await handleApiCall(await result.text(), 'Reading text')
@@ -9427,7 +9481,7 @@ async function run$j(argv, importMeta, { parentName }) {
9427
9481
  }
9428
9482
 
9429
9483
  async function fetchPurlsShallowScore(purls) {
9430
- logger.logger.info(
9484
+ logger.logger.error(
9431
9485
  `Requesting shallow score data for ${purls.length} package urls (purl): ${purls.join(', ')}`
9432
9486
  )
9433
9487
  const sockSdk = await shadowNpmInject.setupSdk(
@@ -9454,9 +9508,11 @@ async function fetchPurlsShallowScore(purls) {
9454
9508
  if (!result.success) {
9455
9509
  return handleFailedApiResponse('batchPackageFetch', result)
9456
9510
  }
9511
+
9512
+ // TODO: seems like there's a bug in the typing since we absolutely have to return the .data here
9457
9513
  return {
9458
9514
  ok: true,
9459
- data: result
9515
+ data: result.data
9460
9516
  }
9461
9517
  }
9462
9518
 
@@ -9979,7 +10035,7 @@ async function fetchCreateRepo({
9979
10035
  }
9980
10036
  }
9981
10037
 
9982
- async function outputCreateRepo(result, outputKind) {
10038
+ async function outputCreateRepo(result, requestedName, outputKind) {
9983
10039
  if (!result.ok) {
9984
10040
  process.exitCode = result.code ?? 1
9985
10041
  }
@@ -9991,7 +10047,9 @@ async function outputCreateRepo(result, outputKind) {
9991
10047
  logger.logger.fail(failMsgWithBadge(result.message, result.cause))
9992
10048
  return
9993
10049
  }
9994
- logger.logger.success('Repository created successfully')
10050
+ logger.logger.success(
10051
+ `OK. Repository created successfully, slug: \`${result.data.slug}\`${result.data.slug !== requestedName ? ' (Warning: slug is not the same as name that was requested!)' : ''}`
10052
+ )
9995
10053
  }
9996
10054
 
9997
10055
  async function handleCreateRepo(
@@ -10006,7 +10064,7 @@ async function handleCreateRepo(
10006
10064
  repoName,
10007
10065
  visibility
10008
10066
  })
10009
- await outputCreateRepo(data, outputKind)
10067
+ await outputCreateRepo(data, repoName, outputKind)
10010
10068
  }
10011
10069
 
10012
10070
  const { DRY_RUN_BAILING_NOW: DRY_RUN_BAILING_NOW$d } = constants
@@ -10016,6 +10074,7 @@ const config$d = {
10016
10074
  hidden: false,
10017
10075
  flags: {
10018
10076
  ...commonFlags,
10077
+ ...outputFlags,
10019
10078
  defaultBranch: {
10020
10079
  type: 'string',
10021
10080
  shortFlag: 'b',
@@ -10179,7 +10238,7 @@ async function fetchDeleteRepo(orgSlug, repoName) {
10179
10238
  }
10180
10239
  }
10181
10240
 
10182
- async function outputDeleteRepo(result, outputKind) {
10241
+ async function outputDeleteRepo(result, repoName, outputKind) {
10183
10242
  if (!result.ok) {
10184
10243
  process.exitCode = result.code ?? 1
10185
10244
  }
@@ -10191,12 +10250,12 @@ async function outputDeleteRepo(result, outputKind) {
10191
10250
  logger.logger.fail(failMsgWithBadge(result.message, result.cause))
10192
10251
  return
10193
10252
  }
10194
- logger.logger.success('Repository deleted successfully')
10253
+ logger.logger.success(`OK. Repository \`${repoName}\` deleted successfully`)
10195
10254
  }
10196
10255
 
10197
10256
  async function handleDeleteRepo(orgSlug, repoName, outputKind) {
10198
10257
  const data = await fetchDeleteRepo(orgSlug, repoName)
10199
- await outputDeleteRepo(data, outputKind)
10258
+ await outputDeleteRepo(data, repoName, outputKind)
10200
10259
  }
10201
10260
 
10202
10261
  const { DRY_RUN_BAILING_NOW: DRY_RUN_BAILING_NOW$c } = constants
@@ -10206,6 +10265,7 @@ const config$c = {
10206
10265
  hidden: false,
10207
10266
  flags: {
10208
10267
  ...commonFlags,
10268
+ ...outputFlags,
10209
10269
  interactive: {
10210
10270
  type: 'boolean',
10211
10271
  default: true,
@@ -10246,8 +10306,7 @@ async function run$c(argv, importMeta, { parentName }) {
10246
10306
  parentName
10247
10307
  })
10248
10308
  const { dryRun, interactive, json, markdown, org: orgFlag } = cli.flags
10249
- const outputKind = getOutputKind(json, markdown) // TODO: impl json/md further
10250
-
10309
+ const outputKind = getOutputKind(json, markdown)
10251
10310
  const [orgSlug, defaultOrgSlug] = await determineOrgSlug(
10252
10311
  String(orgFlag || ''),
10253
10312
  cli.input[0] || '',
@@ -10387,6 +10446,7 @@ const config$b = {
10387
10446
  hidden: false,
10388
10447
  flags: {
10389
10448
  ...commonFlags,
10449
+ ...outputFlags,
10390
10450
  sort: {
10391
10451
  type: 'string',
10392
10452
  shortFlag: 's',
@@ -10420,8 +10480,7 @@ const config$b = {
10420
10480
  shortFlag: 'p',
10421
10481
  default: 1,
10422
10482
  description: 'Page number'
10423
- },
10424
- ...outputFlags
10483
+ }
10425
10484
  },
10426
10485
  help: (command, config) => `
10427
10486
  Usage
@@ -10539,7 +10598,7 @@ async function fetchUpdateRepo({
10539
10598
  }
10540
10599
  }
10541
10600
 
10542
- async function outputUpdateRepo(result, outputKind) {
10601
+ async function outputUpdateRepo(result, repoName, outputKind) {
10543
10602
  if (!result.ok) {
10544
10603
  process.exitCode = result.code ?? 1
10545
10604
  }
@@ -10551,7 +10610,7 @@ async function outputUpdateRepo(result, outputKind) {
10551
10610
  logger.logger.fail(failMsgWithBadge(result.message, result.cause))
10552
10611
  return
10553
10612
  }
10554
- logger.logger.success('Repository updated successfully')
10613
+ logger.logger.success(`Repository \`${repoName}\` updated successfully`)
10555
10614
  }
10556
10615
 
10557
10616
  async function handleUpdateRepo(
@@ -10566,7 +10625,7 @@ async function handleUpdateRepo(
10566
10625
  repoName,
10567
10626
  visibility
10568
10627
  })
10569
- await outputUpdateRepo(data, outputKind)
10628
+ await outputUpdateRepo(data, repoName, outputKind)
10570
10629
  }
10571
10630
 
10572
10631
  const { DRY_RUN_BAILING_NOW: DRY_RUN_BAILING_NOW$a } = constants
@@ -10576,6 +10635,7 @@ const config$a = {
10576
10635
  hidden: false,
10577
10636
  flags: {
10578
10637
  ...commonFlags,
10638
+ ...outputFlags,
10579
10639
  defaultBranch: {
10580
10640
  type: 'string',
10581
10641
  shortFlag: 'b',
@@ -11413,7 +11473,7 @@ async function fetchDiffScan({ id1, id2, orgSlug }) {
11413
11473
  return {
11414
11474
  ok: false,
11415
11475
  message: 'Socket API returned an error',
11416
- cause: `${response.statusText}${err ? ` (cause: ${err}` : ''}`
11476
+ cause: `${response.statusText}${err ? ` (cause: ${err})` : ''}`
11417
11477
  }
11418
11478
  }
11419
11479
  const result = await handleApiCall(
@@ -12353,7 +12413,7 @@ async function run$3(argv, importMeta, { parentName }) {
12353
12413
  },
12354
12414
  {
12355
12415
  test: !!scanId,
12356
- message: 'Scan ID to fetch',
12416
+ message: 'Scan ID to report on',
12357
12417
  pass: 'ok',
12358
12418
  fail: 'missing'
12359
12419
  },
@@ -12416,7 +12476,7 @@ async function fetchScan(orgSlug, scanId) {
12416
12476
  return {
12417
12477
  ok: false,
12418
12478
  message: 'Socket API returned an error',
12419
- cause: `${response.statusText}${err ? ` (cause: ${err}` : ''}`
12479
+ cause: `${response.statusText}${err ? ` (cause: ${err})` : ''}`
12420
12480
  }
12421
12481
  }
12422
12482
 
@@ -12645,7 +12705,7 @@ async function run$2(argv, importMeta, { parentName }) {
12645
12705
  },
12646
12706
  {
12647
12707
  test: !!scanId,
12648
- message: 'Scan ID to delete',
12708
+ message: 'Scan ID to view',
12649
12709
  pass: 'ok',
12650
12710
  fail: 'missing'
12651
12711
  },
@@ -13406,5 +13466,5 @@ void (async () => {
13406
13466
  await shadowNpmInject.captureException(e)
13407
13467
  }
13408
13468
  })()
13409
- //# debugId=a3d4578d-d282-43c9-a0a8-92f02a4c7983
13469
+ //# debugId=406eb2c1-5d4f-41ac-a034-b9fcf6230684
13410
13470
  //# sourceMappingURL=cli.js.map