@socketsecurity/cli
Advanced tools
Comparing version 0.4.1 to 0.4.2-provenance
@@ -7,2 +7,3 @@ /* eslint-disable no-console */ | ||
import { outputFlags, validationFlags } from '../../flags/index.js' | ||
import { handleApiCall, handleUnsuccessfulApiResponse } from '../../utils/api-helpers.js' | ||
@@ -51,2 +52,7 @@ import { ChalkOrMarkdown } from '../../utils/chalk-markdown.js' | ||
function setupCommand (name, description, argv, importMeta) { | ||
const flags = { | ||
...outputFlags, | ||
...validationFlags, | ||
} | ||
const cli = meow(` | ||
@@ -57,8 +63,3 @@ Usage | ||
Options | ||
${printFlagList({ | ||
'--all': 'Include all issues', | ||
'--json': 'Output result as json', | ||
'--markdown': 'Output result as markdown', | ||
'--strict': 'Exits with an error code if any matching issues are found', | ||
}, 6)} | ||
${printFlagList(flags, 6)} | ||
@@ -72,22 +73,3 @@ Examples | ||
importMeta, | ||
flags: { | ||
all: { | ||
type: 'boolean', | ||
default: false, | ||
}, | ||
json: { | ||
type: 'boolean', | ||
alias: 'j', | ||
default: false, | ||
}, | ||
markdown: { | ||
type: 'boolean', | ||
alias: 'm', | ||
default: false, | ||
}, | ||
strict: { | ||
type: 'boolean', | ||
default: false, | ||
}, | ||
} | ||
flags | ||
}) | ||
@@ -154,3 +136,3 @@ | ||
if (result.success === false) { | ||
return handleUnsuccessfulApiResponse(result, spinner) | ||
return handleUnsuccessfulApiResponse('getIssuesByNPMPackage', result, spinner) | ||
} | ||
@@ -157,0 +139,0 @@ |
@@ -12,5 +12,7 @@ /* eslint-disable no-console */ | ||
import { fetchReportData, formatReportDataOutput } from './view.js' | ||
import { outputFlags, validationFlags } from '../../flags/index.js' | ||
import { handleApiCall, handleUnsuccessfulApiResponse } from '../../utils/api-helpers.js' | ||
import { ChalkOrMarkdown, logSymbols } from '../../utils/chalk-markdown.js' | ||
import { InputError } from '../../utils/errors.js' | ||
import { prepareFlags } from '../../utils/flags.js' | ||
import { printFlagList } from '../../utils/formatting.js' | ||
@@ -83,2 +85,24 @@ import { createDebugLogger } from '../../utils/misc.js' | ||
async function setupCommand (name, description, argv, importMeta) { | ||
const flags = prepareFlags({ | ||
...outputFlags, | ||
...validationFlags, | ||
debug: { | ||
type: 'boolean', | ||
alias: 'd', | ||
default: false, | ||
description: 'Output debug information', | ||
}, | ||
dryRun: { | ||
type: 'boolean', | ||
default: false, | ||
description: 'Only output what will be done without actually doing it', | ||
}, | ||
view: { | ||
type: 'boolean', | ||
alias: 'v', | ||
default: false, | ||
description: 'Will wait for and return the created report' | ||
}, | ||
}) | ||
const cli = meow(` | ||
@@ -119,36 +143,3 @@ Usage | ||
importMeta, | ||
flags: { | ||
all: { | ||
type: 'boolean', | ||
default: false, | ||
}, | ||
debug: { | ||
type: 'boolean', | ||
alias: 'd', | ||
default: false, | ||
}, | ||
dryRun: { | ||
type: 'boolean', | ||
default: false, | ||
}, | ||
json: { | ||
type: 'boolean', | ||
alias: 'j', | ||
default: false, | ||
}, | ||
markdown: { | ||
type: 'boolean', | ||
alias: 'm', | ||
default: false, | ||
}, | ||
strict: { | ||
type: 'boolean', | ||
default: false, | ||
}, | ||
view: { | ||
type: 'boolean', | ||
alias: 'v', | ||
default: false, | ||
}, | ||
} | ||
flags, | ||
}) | ||
@@ -230,3 +221,3 @@ | ||
if (result.success === false) { | ||
return handleUnsuccessfulApiResponse(result, spinner) | ||
return handleUnsuccessfulApiResponse('createReport', result, spinner) | ||
} | ||
@@ -233,0 +224,0 @@ |
@@ -7,2 +7,3 @@ /* eslint-disable no-console */ | ||
import { outputFlags, validationFlags } from '../../flags/index.js' | ||
import { handleApiCall, handleUnsuccessfulApiResponse } from '../../utils/api-helpers.js' | ||
@@ -32,3 +33,2 @@ import { ChalkOrMarkdown } from '../../utils/chalk-markdown.js' | ||
// TODO: Share more of the flag setup inbetween the commands | ||
/** | ||
@@ -51,2 +51,7 @@ * @typedef CommandContext | ||
function setupCommand (name, description, argv, importMeta) { | ||
const flags = { | ||
...outputFlags, | ||
...validationFlags, | ||
} | ||
const cli = meow(` | ||
@@ -57,8 +62,3 @@ Usage | ||
Options | ||
${printFlagList({ | ||
'--all': 'Include all issues', | ||
'--json': 'Output result as json', | ||
'--markdown': 'Output result as markdown', | ||
'--strict': 'Exits with an error code if report result is deemed unhealthy', | ||
}, 6)} | ||
${printFlagList(flags, 6)} | ||
@@ -71,22 +71,3 @@ Examples | ||
importMeta, | ||
flags: { | ||
all: { | ||
type: 'boolean', | ||
default: false, | ||
}, | ||
json: { | ||
type: 'boolean', | ||
alias: 'j', | ||
default: false, | ||
}, | ||
markdown: { | ||
type: 'boolean', | ||
alias: 'm', | ||
default: false, | ||
}, | ||
strict: { | ||
type: 'boolean', | ||
default: false, | ||
}, | ||
} | ||
flags, | ||
}) | ||
@@ -142,3 +123,3 @@ | ||
if (result.success === false) { | ||
return handleUnsuccessfulApiResponse(result, spinner) | ||
return handleUnsuccessfulApiResponse('getReport', result, spinner) | ||
} | ||
@@ -145,0 +126,0 @@ |
@@ -7,3 +7,4 @@ import chalk from 'chalk' | ||
/** | ||
* @template T | ||
* @template {import('@socketsecurity/sdk').SocketSdkOperations} T | ||
* @param {T} _name | ||
* @param {import('@socketsecurity/sdk').SocketSdkErrorType<T>} result | ||
@@ -13,3 +14,3 @@ * @param {import('ora').Ora} spinner | ||
*/ | ||
export function handleUnsuccessfulApiResponse (result, spinner) { | ||
export function handleUnsuccessfulApiResponse (_name, result, spinner) { | ||
const resultError = 'error' in result && result.error && typeof result.error === 'object' ? result.error : {} | ||
@@ -16,0 +17,0 @@ const message = 'message' in resultError && typeof resultError.message === 'string' ? resultError.message : 'No error message returned' |
/** @typedef {string|{ description: string }} ListDescription */ | ||
/** | ||
* @typedef HelpListOptions | ||
* @property {string} [keyPrefix] | ||
* @property {number} [padName] | ||
*/ | ||
/** | ||
* @param {Record<string,ListDescription>} list | ||
* @param {number} indent | ||
* @param {number} padName | ||
* @param {HelpListOptions} options | ||
* @returns {string} | ||
*/ | ||
export function printHelpList (list, indent, padName = 18) { | ||
export function printHelpList (list, indent, options = {}) { | ||
const { | ||
keyPrefix = '', | ||
padName = 18, | ||
} = options | ||
const names = Object.keys(list).sort() | ||
@@ -18,3 +29,3 @@ | ||
result += ''.padEnd(indent) + name.padEnd(padName) + description + '\n' | ||
result += ''.padEnd(indent) + (keyPrefix + name).padEnd(padName) + description + '\n' | ||
} | ||
@@ -26,13 +37,13 @@ | ||
/** | ||
* @param {Record<string,ListDescription>} list | ||
* @param {Record<string, ListDescription>} list | ||
* @param {number} indent | ||
* @param {number} padName | ||
* @param {HelpListOptions} options | ||
* @returns {string} | ||
*/ | ||
export function printFlagList (list, indent, padName = 18) { | ||
export function printFlagList (list, indent, options = {}) { | ||
return printHelpList({ | ||
'--help': 'Print this help and exits.', | ||
'--version': 'Prints current version and exits.', | ||
'help': 'Print this help and exits.', | ||
'version': 'Prints current version and exits.', | ||
...list, | ||
}, indent, padName) | ||
}, indent, { keyPrefix: '--', ...options }) | ||
} |
@@ -12,6 +12,13 @@ import { readFile } from 'node:fs/promises' | ||
/** | ||
* @returns {Promise<import('@socketsecurity/sdk').SocketSdk>} | ||
* The API key should be stored globally for the duration of the CLI execution | ||
* | ||
* @type {string | undefined} | ||
*/ | ||
let apiKey | ||
/** @returns {Promise<import('@socketsecurity/sdk').SocketSdk>} */ | ||
export async function setupSdk () { | ||
let apiKey = process.env['SOCKET_SECURITY_API_KEY'] | ||
if (!apiKey) { | ||
apiKey = process.env['SOCKET_SECURITY_API_KEY'] | ||
} | ||
@@ -18,0 +25,0 @@ if (!apiKey && isInteractive()) { |
{ | ||
"name": "@socketsecurity/cli", | ||
"version": "0.4.1", | ||
"version": "0.4.2-provenance", | ||
"description": "CLI tool for Socket.dev", | ||
@@ -41,3 +41,3 @@ "homepage": "http://github.com/SocketDev/socket-cli-js", | ||
"devDependencies": { | ||
"@socketsecurity/eslint-config": "^1.0.0", | ||
"@socketsecurity/eslint-config": "^2.0.0", | ||
"@tsconfig/node14": "^1.0.3", | ||
@@ -50,5 +50,5 @@ "@types/chai": "^4.3.3", | ||
"@types/prompts": "^2.4.1", | ||
"@types/update-notifier": "^6.0.1", | ||
"@typescript-eslint/eslint-plugin": "^5.48.2", | ||
"@typescript-eslint/parser": "^5.48.2", | ||
"@types/update-notifier": "^6.0.2", | ||
"@typescript-eslint/eslint-plugin": "^5.51.0", | ||
"@typescript-eslint/parser": "^5.51.0", | ||
"c8": "^7.12.0", | ||
@@ -58,3 +58,3 @@ "chai": "^4.3.6", | ||
"dependency-check": "^5.0.0-7", | ||
"eslint": "^8.32.0", | ||
"eslint": "^8.34.0", | ||
"eslint-config-standard": "^17.0.0", | ||
@@ -64,6 +64,6 @@ "eslint-config-standard-jsx": "^11.0.0", | ||
"eslint-plugin-import": "^2.27.5", | ||
"eslint-plugin-jsdoc": "^39.5.0", | ||
"eslint-plugin-jsdoc": "^40.0.0", | ||
"eslint-plugin-n": "^15.6.1", | ||
"eslint-plugin-promise": "^6.1.1", | ||
"eslint-plugin-react": "^7.32.1", | ||
"eslint-plugin-react": "^7.32.2", | ||
"eslint-plugin-react-hooks": "^4.6.0", | ||
@@ -78,3 +78,3 @@ "eslint-plugin-unicorn": "^45.0.2", | ||
"type-coverage": "^2.24.1", | ||
"typescript": "~4.9.4" | ||
"typescript": "~4.9.5" | ||
}, | ||
@@ -84,3 +84,3 @@ "dependencies": { | ||
"@socketsecurity/config": "^2.0.0", | ||
"@socketsecurity/sdk": "^0.5.2", | ||
"@socketsecurity/sdk": "^0.5.4", | ||
"chalk": "^5.1.2", | ||
@@ -87,0 +87,0 @@ "globby": "^13.1.3", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
46975
24
1200
1
Updated@socketsecurity/sdk@^0.5.4