Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 32 additions & 32 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,28 @@ import { messageWithCauses, stackWithCauses } from 'pony-cause'
import updateNotifier from 'tiny-updater'
import colors from 'yoctocolors-cjs'

import { cmdAction } from './commands/action/cmd-action.ts'
import { cmdAnalytics } from './commands/analytics/cmd-analytics.ts'
import { cmdAuditLog } from './commands/audit-log/cmd-audit-log.ts'
import { cmdCdxgen } from './commands/cdxgen/cmd-cdxgen.ts'
import { cmdScanCreate } from './commands/dependencies/cmd-dependencies.ts'
import { cmdDiffScan } from './commands/diff-scan/cmd-diff-scan.ts'
import { cmdFix } from './commands/fix/cmd-fix.ts'
import { cmdInfo } from './commands/info/cmd-info.ts'
import { loginCommand } from './commands/login'
import { logoutCommand } from './commands/logout'
import { cmdManifest } from './commands/manifest/cmd-manifest.ts'
import { npmCommand } from './commands/npm'
import { npxCommand } from './commands/npx'
import { optimizeCommand } from './commands/optimize'
import { organizationCommand } from './commands/organization'
import { rawNpmCommand } from './commands/raw-npm'
import { rawNpxCommand } from './commands/raw-npx'
import { cmdReport } from './commands/report/cmd-report.ts'
import { cmdRepos } from './commands/repos/cmd-repos.ts'
import { cmdScan } from './commands/scan/cmd-scan.ts'
import { threatFeedCommand } from './commands/threat-feed'
import { wrapperCommand } from './commands/wrapper'
import { cmdAction } from './commands/action/cmd-action'
import { cmdAnalytics } from './commands/analytics/cmd-analytics'
import { cmdAuditLog } from './commands/audit-log/cmd-audit-log'
import { cmdCdxgen } from './commands/cdxgen/cmd-cdxgen'
import { cmdScanCreate } from './commands/dependencies/cmd-dependencies'
import { cmdDiffScan } from './commands/diff-scan/cmd-diff-scan'
import { cmdFix } from './commands/fix/cmd-fix'
import { cmdInfo } from './commands/info/cmd-info'
import { cmdLogin } from './commands/login/cmd-login'
import { cmdLogout } from './commands/logout/cmd-logout'
import { cmdManifest } from './commands/manifest/cmd-manifest'
import { cmdNpm } from './commands/npm/cmd-npm'
import { cmdNpx } from './commands/npx/cmd-npx'
import { cmdOptimize } from './commands/optimize/cmd-optimize'
import { cmdOrganizations } from './commands/organizations/cmd-organizations'
import { cmdRawNpm } from './commands/raw-npm/cmd-raw-npm'
import { cmdRawNpx } from './commands/raw-npx/cmd-raw-npx'
import { cmdReport } from './commands/report/cmd-report'
import { cmdRepos } from './commands/repos/cmd-repos'
import { cmdScan } from './commands/scan/cmd-scan'
import { cmdThreatFeed } from './commands/threat-feed/cmd-threat-feed'
import { cmdWrapper } from './commands/wrapper/cmd-wrapper'
import constants from './constants'
import { AuthError, InputError } from './utils/errors'
import { logSymbols } from './utils/logging'
Expand All @@ -51,23 +51,23 @@ void (async () => {
cdxgen: cmdCdxgen,
fix: cmdFix,
info: cmdInfo,
login: loginCommand,
logout: logoutCommand,
npm: npmCommand,
npx: npxCommand,
optimize: optimizeCommand,
organization: organizationCommand,
'raw-npm': rawNpmCommand,
'raw-npx': rawNpxCommand,
login: cmdLogin,
logout: cmdLogout,
npm: cmdNpm,
npx: cmdNpx,
optimize: cmdOptimize,
organization: cmdOrganizations,
'raw-npm': cmdRawNpm,
'raw-npx': cmdRawNpx,
report: cmdReport,
wrapper: wrapperCommand,
wrapper: cmdWrapper,
scan: cmdScan,
'audit-log': cmdAuditLog,
repos: cmdRepos,
dependencies: cmdScanCreate,
analytics: cmdAnalytics,
'diff-scan': cmdDiffScan,
'threat-feed': threatFeedCommand,
'threat-feed': cmdThreatFeed,
manifest: cmdManifest
},
{
Expand Down
50 changes: 2 additions & 48 deletions src/commands/fix/cmd-fix.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import meowOrExit from 'meow'

import { Spinner } from '@socketsecurity/registry/lib/spinner'

import constants from '../../constants'
import { shadowNpmInstall } from '../../utils/npm'
import { runFix } from './run-fix.ts'
import { getFlagListOutput } from '../../utils/output-formatting.ts'

import type { CliCommandConfig } from '../../utils/meow-with-subcommands.ts'

const { SOCKET_CLI_IN_FIX_CMD, SOCKET_IPC_HANDSHAKE } = constants

const config: CliCommandConfig = {
commandName: 'fix',
description: 'Fix "fixable" Socket alerts',
Expand Down Expand Up @@ -42,46 +37,5 @@ async function run(
flags: config.flags
})

// const prev = new Set(alerts.map(a => a.key))
// let ret: SafeNode | undefined
// /* eslint-disable no-await-in-loop */
// while (alerts.length > 0) {
// await updateAdvisoryNodes(this, alerts)
// ret = await this[kRiskyReify](...args)
// await this.loadActual()
// await this.buildIdealTree()
// needInfoOn = getPackagesToQueryFromDiff(this.diff, {
// includeUnchanged: true
// })
// alerts = (
// await getPackagesAlerts(needInfoOn, {
// includeExisting: true,
// includeUnfixable: true
// })
// ).filter(({ key }) => {
// const unseen = !prev.has(key)
// if (unseen) {
// prev.add(key)
// }
// return unseen
// })
// }
// /* eslint-enable no-await-in-loop */
// return ret!

const spinner = new Spinner().start()
try {
await shadowNpmInstall({
ipc: {
[SOCKET_IPC_HANDSHAKE]: {
[SOCKET_CLI_IN_FIX_CMD]: true
}
}
})
} catch (e: any) {
console.error(e)
spinner.error()
} finally {
spinner.stop()
}
await runFix()
}
51 changes: 51 additions & 0 deletions src/commands/fix/run-fix.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { Spinner } from '@socketsecurity/registry/lib/spinner'

import constants from '../../constants.ts'
import { shadowNpmInstall } from '../../utils/npm.ts'

const { SOCKET_CLI_IN_FIX_CMD, SOCKET_IPC_HANDSHAKE } = constants

export async function runFix() {
// const prev = new Set(alerts.map(a => a.key))
// let ret: SafeNode | undefined
// /* eslint-disable no-await-in-loop */
// while (alerts.length > 0) {
// await updateAdvisoryNodes(this, alerts)
// ret = await this[kRiskyReify](...args)
// await this.loadActual()
// await this.buildIdealTree()
// needInfoOn = getPackagesToQueryFromDiff(this.diff, {
// includeUnchanged: true
// })
// alerts = (
// await getPackagesAlerts(needInfoOn, {
// includeExisting: true,
// includeUnfixable: true
// })
// ).filter(({ key }) => {
// const unseen = !prev.has(key)
// if (unseen) {
// prev.add(key)
// }
// return unseen
// })
// }
// /* eslint-enable no-await-in-loop */
// return ret!

const spinner = new Spinner().start()
try {
await shadowNpmInstall({
ipc: {
[SOCKET_IPC_HANDSHAKE]: {
[SOCKET_CLI_IN_FIX_CMD]: true
}
}
})
} catch (e: any) {
console.error(e)
spinner.error()
} finally {
spinner.stop()
}
}
165 changes: 0 additions & 165 deletions src/commands/login.ts

This file was deleted.

13 changes: 13 additions & 0 deletions src/commands/login/apply-login.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { updateSetting } from '../../utils/settings.ts'

export function applyLogin(
apiToken: string,
enforcedOrgs: Array<string>,
apiBaseUrl: string | undefined,
apiProxy: string | undefined
) {
updateSetting('enforcedOrgs', enforcedOrgs)
updateSetting('apiToken', apiToken)
updateSetting('apiBaseUrl', apiBaseUrl)
updateSetting('apiProxy', apiProxy)
}
Loading
Loading