@socketsecurity/cli 0.10.0 → 0.11.0
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/lib/commands/index.js
CHANGED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
|
|
3
|
+
import chalk from 'chalk'
|
|
4
|
+
import meow from 'meow'
|
|
5
|
+
import ora from 'ora'
|
|
6
|
+
|
|
7
|
+
import { handleApiCall, handleUnsuccessfulApiResponse } from '../../utils/api-helpers.js'
|
|
8
|
+
import { getDefaultKey, setupSdk } from '../../utils/sdk.js'
|
|
9
|
+
|
|
10
|
+
/** @type {import('../../utils/meow-with-subcommands.js').CliSubcommand} */
|
|
11
|
+
export const organizations = {
|
|
12
|
+
description: 'List organizations associated with the API key used',
|
|
13
|
+
async run (argv, importMeta, { parentName }) {
|
|
14
|
+
const name = parentName + ' organizations'
|
|
15
|
+
|
|
16
|
+
setupCommand(name, organizations.description, argv, importMeta)
|
|
17
|
+
await fetchOrganizations()
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Internal functions
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @param {string} name
|
|
25
|
+
* @param {string} description
|
|
26
|
+
* @param {readonly string[]} argv
|
|
27
|
+
* @param {ImportMeta} importMeta
|
|
28
|
+
* @returns {void}
|
|
29
|
+
*/
|
|
30
|
+
function setupCommand (name, description, argv, importMeta) {
|
|
31
|
+
meow(`
|
|
32
|
+
Usage
|
|
33
|
+
$ ${name}
|
|
34
|
+
`, {
|
|
35
|
+
argv,
|
|
36
|
+
description,
|
|
37
|
+
importMeta
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @typedef OrganizationsData
|
|
43
|
+
* @property {import('@socketsecurity/sdk').SocketSdkReturnType<'getOrganizations'>["data"]} data
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @returns {Promise<void|OrganizationsData>}
|
|
48
|
+
*/
|
|
49
|
+
async function fetchOrganizations () {
|
|
50
|
+
const apiKey = getDefaultKey()
|
|
51
|
+
const socketSdk = await setupSdk(apiKey)
|
|
52
|
+
const spinner = ora('Fetching organizations...').start()
|
|
53
|
+
|
|
54
|
+
const result = await handleApiCall(socketSdk.getOrganizations(), 'looking up organizations')
|
|
55
|
+
|
|
56
|
+
if (result.success === false) {
|
|
57
|
+
return handleUnsuccessfulApiResponse('getOrganizations', result, spinner)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
spinner.stop()
|
|
61
|
+
|
|
62
|
+
const organizations = Object.values(result.data.organizations)
|
|
63
|
+
if (apiKey) {
|
|
64
|
+
console.log(`List of organizations associated with your API key: ${chalk.italic(apiKey)}`)
|
|
65
|
+
} else {
|
|
66
|
+
console.log('List of organizations associated with your API key.')
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
organizations.map(o => {
|
|
70
|
+
console.log(`
|
|
71
|
+
Name: ${o?.name}
|
|
72
|
+
ID: ${o?.id}
|
|
73
|
+
Plan: ${o?.plan}
|
|
74
|
+
`)
|
|
75
|
+
return o
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
return {
|
|
79
|
+
data: result.data
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -254,7 +254,7 @@ const ttyServerPromise = chalkPromise.then(async (chalk) => {
|
|
|
254
254
|
const npmEntrypoint = fs.realpathSync(`${process.argv[1]}`)
|
|
255
255
|
/**
|
|
256
256
|
* @param {string} filepath
|
|
257
|
-
* @returns {string}
|
|
257
|
+
* @returns {string | null}
|
|
258
258
|
*/
|
|
259
259
|
function findRoot (filepath) {
|
|
260
260
|
if (path.basename(filepath) === 'npm') {
|
|
@@ -262,21 +262,36 @@ function findRoot (filepath) {
|
|
|
262
262
|
}
|
|
263
263
|
const parent = path.dirname(filepath)
|
|
264
264
|
if (parent === filepath) {
|
|
265
|
-
|
|
265
|
+
return null
|
|
266
266
|
}
|
|
267
267
|
return findRoot(parent)
|
|
268
268
|
}
|
|
269
269
|
const npmDir = findRoot(path.dirname(npmEntrypoint))
|
|
270
|
-
|
|
270
|
+
if (npmDir === null) {
|
|
271
|
+
console.error('Unable to find npm cli install directory, this is potentiall a bug with socket-npm caused by changes to npm cli.')
|
|
272
|
+
console.error(`Searched parent directories of ${npmEntrypoint}`)
|
|
273
|
+
process.exit(127)
|
|
274
|
+
}
|
|
275
|
+
let arboristLibClassPath
|
|
276
|
+
try {
|
|
277
|
+
arboristLibClassPath = path.join(npmDir, 'node_modules', '@npmcli', 'arborist', 'lib', 'arborist', 'index.js')
|
|
278
|
+
} catch (e) {
|
|
279
|
+
console.error('Unable to integrate with npm cli internals, this is potentially a bug with socket-npm caused by changes to npm cli.')
|
|
280
|
+
process.exit(127);
|
|
281
|
+
}
|
|
271
282
|
|
|
272
|
-
const npmVersion = process.env.NPM_VERSION.split('.')
|
|
273
283
|
let npmlog
|
|
274
284
|
|
|
275
|
-
|
|
276
|
-
const { log } = require(path.join(npmDir, 'node_modules', 'proc-log', 'lib', 'index.js'))
|
|
277
|
-
npmlog = log
|
|
278
|
-
} else {
|
|
285
|
+
try {
|
|
279
286
|
npmlog = require(path.join(npmDir, 'node_modules', 'npmlog', 'lib', 'log.js'))
|
|
287
|
+
} catch {
|
|
288
|
+
try {
|
|
289
|
+
const { log } = require(path.join(npmDir, 'node_modules', 'proc-log', 'lib', 'index.js'))
|
|
290
|
+
npmlog = log
|
|
291
|
+
} catch {
|
|
292
|
+
console.error('Unable to integrate with npm cli logging infrastructure, this is potentially a bug with socket-npm caused by changes to npm cli.')
|
|
293
|
+
process.exit(127);
|
|
294
|
+
}
|
|
280
295
|
}
|
|
281
296
|
|
|
282
297
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@socketsecurity/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "CLI tool for Socket.dev",
|
|
5
5
|
"homepage": "http://github.com/SocketDev/socket-cli-js",
|
|
6
6
|
"repository": {
|
|
@@ -101,15 +101,14 @@
|
|
|
101
101
|
"engines": {
|
|
102
102
|
"node": "^20.9.0 || >=21.1.0"
|
|
103
103
|
},
|
|
104
|
-
|
|
105
104
|
"scripts": {
|
|
106
|
-
"check:dependency-check": "dependency-check '*.js' 'lib/shadow/*.cjs' '*.mjs' 'test
|
|
105
|
+
"check:dependency-check": "dependency-check '*.js' 'lib/shadow/*.cjs' '*.mjs' 'test/*.js' --no-dev --ignore-module node:* --ignore-module @cyclonedx/* --ignore-module synp",
|
|
107
106
|
"check:installed-check": "installed-check -i eslint-plugin-jsdoc",
|
|
108
107
|
"check:lint": "eslint --report-unused-disable-directives .",
|
|
109
108
|
"check:tsc": "tsc",
|
|
110
109
|
"check:type-coverage": "type-coverage --detail --strict --at-least 95 --ignore-files 'test/*'",
|
|
111
110
|
"check": "run-p -c --aggregate-output check:*",
|
|
112
|
-
"prepare": "husky
|
|
111
|
+
"prepare": "husky",
|
|
113
112
|
"test:unit": "c8 --reporter=lcov --reporter text node --test",
|
|
114
113
|
"test-ci": "run-s test:*",
|
|
115
114
|
"test": "run-s check test:*",
|