socket 1.1.8 → 1.1.11
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/CHANGELOG.md +9 -1
- package/README.md +3 -3
- package/dist/cli.js +163 -94
- package/dist/cli.js.map +1 -1
- package/dist/constants.js +11 -8
- package/dist/constants.js.map +1 -1
- package/dist/flags.js +16 -17
- package/dist/flags.js.map +1 -1
- package/dist/shadow-npm-inject.js +8 -10
- package/dist/shadow-npm-inject.js.map +1 -1
- package/dist/socket-completion.bash +0 -0
- package/dist/tsconfig.dts.tsbuildinfo +1 -1
- package/dist/types/commands/analytics/cmd-analytics.d.mts +2 -3
- package/dist/types/commands/analytics/cmd-analytics.d.mts.map +1 -1
- package/dist/types/commands/audit-log/cmd-audit-log.d.mts +2 -3
- package/dist/types/commands/audit-log/cmd-audit-log.d.mts.map +1 -1
- package/dist/types/commands/ci/cmd-ci.d.mts +2 -3
- package/dist/types/commands/ci/cmd-ci.d.mts.map +1 -1
- package/dist/types/commands/config/cmd-config-auto.d.mts +2 -3
- package/dist/types/commands/config/cmd-config-auto.d.mts.map +1 -1
- package/dist/types/commands/config/cmd-config-get.d.mts +2 -3
- package/dist/types/commands/config/cmd-config-get.d.mts.map +1 -1
- package/dist/types/commands/config/cmd-config-list.d.mts +2 -3
- package/dist/types/commands/config/cmd-config-list.d.mts.map +1 -1
- package/dist/types/commands/config/cmd-config-set.d.mts +2 -3
- package/dist/types/commands/config/cmd-config-set.d.mts.map +1 -1
- package/dist/types/commands/config/cmd-config-unset.d.mts +2 -3
- package/dist/types/commands/config/cmd-config-unset.d.mts.map +1 -1
- package/dist/types/commands/fix/cmd-fix.d.mts +2 -3
- package/dist/types/commands/fix/cmd-fix.d.mts.map +1 -1
- package/dist/types/commands/fix/env-helpers.d.mts +1 -1
- package/dist/types/commands/fix/env-helpers.d.mts.map +1 -1
- package/dist/types/commands/fix/git.d.mts +1 -1
- package/dist/types/commands/fix/git.d.mts.map +1 -1
- package/dist/types/commands/fix/handle-fix.d.mts +5 -0
- package/dist/types/commands/fix/handle-fix.d.mts.map +1 -1
- package/dist/types/commands/fix/pull-request.d.mts +1 -1
- package/dist/types/commands/fix/pull-request.d.mts.map +1 -1
- package/dist/types/commands/install/cmd-install-completion.d.mts +2 -3
- package/dist/types/commands/install/cmd-install-completion.d.mts.map +1 -1
- package/dist/types/commands/json/cmd-json.d.mts +2 -3
- package/dist/types/commands/json/cmd-json.d.mts.map +1 -1
- package/dist/types/commands/login/cmd-login.d.mts +2 -3
- package/dist/types/commands/login/cmd-login.d.mts.map +1 -1
- package/dist/types/commands/logout/cmd-logout.d.mts +2 -3
- package/dist/types/commands/logout/cmd-logout.d.mts.map +1 -1
- package/dist/types/commands/manifest/cmd-manifest-auto.d.mts +2 -3
- package/dist/types/commands/manifest/cmd-manifest-auto.d.mts.map +1 -1
- package/dist/types/commands/manifest/cmd-manifest-cdxgen.d.mts +2 -3
- package/dist/types/commands/manifest/cmd-manifest-cdxgen.d.mts.map +1 -1
- package/dist/types/commands/manifest/cmd-manifest-conda.d.mts +2 -3
- package/dist/types/commands/manifest/cmd-manifest-conda.d.mts.map +1 -1
- package/dist/types/commands/manifest/cmd-manifest-gradle.d.mts +2 -3
- package/dist/types/commands/manifest/cmd-manifest-gradle.d.mts.map +1 -1
- package/dist/types/commands/manifest/cmd-manifest-kotlin.d.mts +2 -3
- package/dist/types/commands/manifest/cmd-manifest-kotlin.d.mts.map +1 -1
- package/dist/types/commands/manifest/cmd-manifest-scala.d.mts +2 -3
- package/dist/types/commands/manifest/cmd-manifest-scala.d.mts.map +1 -1
- package/dist/types/commands/manifest/cmd-manifest-setup.d.mts +2 -3
- package/dist/types/commands/manifest/cmd-manifest-setup.d.mts.map +1 -1
- package/dist/types/commands/manifest/cmd-manifest.d.mts +2 -3
- package/dist/types/commands/manifest/cmd-manifest.d.mts.map +1 -1
- package/dist/types/commands/manifest/run-cdxgen.d.mts.map +1 -1
- package/dist/types/commands/npm/cmd-npm.d.mts +2 -3
- package/dist/types/commands/npm/cmd-npm.d.mts.map +1 -1
- package/dist/types/commands/npx/cmd-npx.d.mts +2 -3
- package/dist/types/commands/npx/cmd-npx.d.mts.map +1 -1
- package/dist/types/commands/oops/cmd-oops.d.mts +2 -3
- package/dist/types/commands/oops/cmd-oops.d.mts.map +1 -1
- package/dist/types/commands/optimize/cmd-optimize.d.mts +2 -3
- package/dist/types/commands/optimize/cmd-optimize.d.mts.map +1 -1
- package/dist/types/commands/organization/cmd-organization-dependencies.d.mts +2 -3
- package/dist/types/commands/organization/cmd-organization-dependencies.d.mts.map +1 -1
- package/dist/types/commands/organization/cmd-organization-list.d.mts +2 -3
- package/dist/types/commands/organization/cmd-organization-list.d.mts.map +1 -1
- package/dist/types/commands/organization/cmd-organization-policy-license.d.mts +2 -3
- package/dist/types/commands/organization/cmd-organization-policy-license.d.mts.map +1 -1
- package/dist/types/commands/organization/cmd-organization-policy-security.d.mts +2 -3
- package/dist/types/commands/organization/cmd-organization-policy-security.d.mts.map +1 -1
- package/dist/types/commands/organization/cmd-organization-quota.d.mts +2 -3
- package/dist/types/commands/organization/cmd-organization-quota.d.mts.map +1 -1
- package/dist/types/commands/package/cmd-package-score.d.mts +2 -3
- package/dist/types/commands/package/cmd-package-score.d.mts.map +1 -1
- package/dist/types/commands/package/cmd-package-shallow.d.mts +2 -3
- package/dist/types/commands/package/cmd-package-shallow.d.mts.map +1 -1
- package/dist/types/commands/package/output-purls-shallow-score.d.mts.map +1 -1
- package/dist/types/commands/patch/cmd-patch.d.mts +2 -3
- package/dist/types/commands/patch/cmd-patch.d.mts.map +1 -1
- package/dist/types/commands/patch/handle-patch.d.mts.map +1 -1
- package/dist/types/commands/raw-npm/cmd-raw-npm.d.mts +2 -3
- package/dist/types/commands/raw-npm/cmd-raw-npm.d.mts.map +1 -1
- package/dist/types/commands/raw-npx/cmd-raw-npx.d.mts +2 -3
- package/dist/types/commands/raw-npx/cmd-raw-npx.d.mts.map +1 -1
- package/dist/types/commands/repository/cmd-repository-create.d.mts +2 -3
- package/dist/types/commands/repository/cmd-repository-create.d.mts.map +1 -1
- package/dist/types/commands/repository/cmd-repository-del.d.mts +2 -3
- package/dist/types/commands/repository/cmd-repository-del.d.mts.map +1 -1
- package/dist/types/commands/repository/cmd-repository-list.d.mts +2 -3
- package/dist/types/commands/repository/cmd-repository-list.d.mts.map +1 -1
- package/dist/types/commands/repository/cmd-repository-update.d.mts +2 -3
- package/dist/types/commands/repository/cmd-repository-update.d.mts.map +1 -1
- package/dist/types/commands/repository/cmd-repository-view.d.mts +2 -3
- package/dist/types/commands/repository/cmd-repository-view.d.mts.map +1 -1
- package/dist/types/commands/repository/handle-list-repos.d.mts +2 -1
- package/dist/types/commands/repository/handle-list-repos.d.mts.map +1 -1
- package/dist/types/commands/repository/output-list-repos.d.mts +2 -1
- package/dist/types/commands/repository/output-list-repos.d.mts.map +1 -1
- package/dist/types/commands/repository/types.d.mts +2 -0
- package/dist/types/commands/repository/types.d.mts.map +1 -0
- package/dist/types/commands/scan/cmd-scan-create.d.mts +2 -3
- package/dist/types/commands/scan/cmd-scan-create.d.mts.map +1 -1
- package/dist/types/commands/scan/cmd-scan-del.d.mts +2 -3
- package/dist/types/commands/scan/cmd-scan-del.d.mts.map +1 -1
- package/dist/types/commands/scan/cmd-scan-diff.d.mts +2 -3
- package/dist/types/commands/scan/cmd-scan-diff.d.mts.map +1 -1
- package/dist/types/commands/scan/cmd-scan-github.d.mts +2 -3
- package/dist/types/commands/scan/cmd-scan-github.d.mts.map +1 -1
- package/dist/types/commands/scan/cmd-scan-list.d.mts.map +1 -1
- package/dist/types/commands/scan/cmd-scan-metadata.d.mts.map +1 -1
- package/dist/types/commands/scan/cmd-scan-reach.d.mts +2 -3
- package/dist/types/commands/scan/cmd-scan-reach.d.mts.map +1 -1
- package/dist/types/commands/scan/cmd-scan-report.d.mts.map +1 -1
- package/dist/types/commands/scan/cmd-scan-setup.d.mts +2 -3
- package/dist/types/commands/scan/cmd-scan-setup.d.mts.map +1 -1
- package/dist/types/commands/scan/cmd-scan-view.d.mts.map +1 -1
- package/dist/types/commands/threat-feed/cmd-threat-feed.d.mts +2 -3
- package/dist/types/commands/threat-feed/cmd-threat-feed.d.mts.map +1 -1
- package/dist/types/commands/uninstall/cmd-uninstall-completion.d.mts +2 -3
- package/dist/types/commands/uninstall/cmd-uninstall-completion.d.mts.map +1 -1
- package/dist/types/commands/wrapper/cmd-wrapper.d.mts +2 -3
- package/dist/types/commands/wrapper/cmd-wrapper.d.mts.map +1 -1
- package/dist/types/commands.d.mts +21 -63
- package/dist/types/commands.d.mts.map +1 -1
- package/dist/types/constants.d.mts +3 -1
- package/dist/types/constants.d.mts.map +1 -1
- package/dist/types/flags.d.mts.map +1 -1
- package/dist/types/shadow/npm/arborist-helpers.d.mts.map +1 -1
- package/dist/types/utils/alerts-map.d.mts.map +1 -1
- package/dist/types/utils/api.d.mts +22 -1
- package/dist/types/utils/api.d.mts.map +1 -1
- package/dist/types/utils/cmd.d.mts +25 -1
- package/dist/types/utils/cmd.d.mts.map +1 -1
- package/dist/types/utils/config.d.mts +1 -1
- package/dist/types/utils/config.d.mts.map +1 -1
- package/dist/types/utils/cve-to-ghsa.d.mts +6 -0
- package/dist/types/utils/cve-to-ghsa.d.mts.map +1 -0
- package/dist/types/utils/git.d.mts +4 -4
- package/dist/types/utils/git.d.mts.map +1 -1
- package/dist/types/utils/github.d.mts.map +1 -1
- package/dist/types/utils/lockfile.d.mts +1 -1
- package/dist/types/utils/lockfile.d.mts.map +1 -1
- package/dist/types/utils/meow-with-subcommands.d.mts +16 -1
- package/dist/types/utils/meow-with-subcommands.d.mts.map +1 -1
- package/dist/types/utils/npm-config.d.mts +1 -1
- package/dist/types/utils/npm-config.d.mts.map +1 -1
- package/dist/types/utils/npm-package-arg.d.mts +1 -1
- package/dist/types/utils/npm-package-arg.d.mts.map +1 -1
- package/dist/types/utils/output-formatting.d.mts.map +1 -1
- package/dist/types/utils/pnpm.d.mts +2 -2
- package/dist/types/utils/pnpm.d.mts.map +1 -1
- package/dist/types/utils/purl-to-ghsa.d.mts +6 -0
- package/dist/types/utils/purl-to-ghsa.d.mts.map +1 -0
- package/dist/types/utils/purl.d.mts +6 -6
- package/dist/types/utils/purl.d.mts.map +1 -1
- package/dist/types/utils/requirements.d.mts +4 -0
- package/dist/types/utils/requirements.d.mts.map +1 -1
- package/dist/types/utils/sdk.d.mts.map +1 -1
- package/dist/types/utils/semver.d.mts +3 -4
- package/dist/types/utils/semver.d.mts.map +1 -1
- package/dist/types/utils/strings.d.mts +2 -0
- package/dist/types/utils/strings.d.mts.map +1 -0
- package/dist/utils.js +379 -85
- package/dist/utils.js.map +1 -1
- package/dist/vendor.js +42175 -50468
- package/external/@socketsecurity/registry/lib/url.js +13 -12
- package/external/blessed/lib/tput.js +13 -13
- package/external/blessed/lib/widgets/ansiimage.js +1 -1
- package/external/blessed/lib/widgets/bigtext.js +1 -1
- package/external/blessed/lib/widgets/box.js +1 -1
- package/external/blessed/lib/widgets/button.js +1 -1
- package/external/blessed/lib/widgets/checkbox.js +1 -1
- package/external/blessed/lib/widgets/element.js +1 -1
- package/external/blessed/lib/widgets/filemanager.js +1 -1
- package/external/blessed/lib/widgets/form.js +1 -1
- package/external/blessed/lib/widgets/image.js +1 -1
- package/external/blessed/lib/widgets/input.js +1 -1
- package/external/blessed/lib/widgets/layout.js +1 -1
- package/external/blessed/lib/widgets/line.js +1 -1
- package/external/blessed/lib/widgets/list.js +1 -1
- package/external/blessed/lib/widgets/listbar.js +1 -1
- package/external/blessed/lib/widgets/listtable.js +1 -1
- package/external/blessed/lib/widgets/loading.js +1 -1
- package/external/blessed/lib/widgets/log.js +1 -1
- package/external/blessed/lib/widgets/message.js +1 -1
- package/external/blessed/lib/widgets/node.js +3 -2
- package/external/blessed/lib/widgets/overlayimage.js +1 -1
- package/external/blessed/lib/widgets/progressbar.js +1 -1
- package/external/blessed/lib/widgets/prompt.js +1 -1
- package/external/blessed/lib/widgets/question.js +1 -1
- package/external/blessed/lib/widgets/radiobutton.js +1 -1
- package/external/blessed/lib/widgets/radioset.js +1 -1
- package/external/blessed/lib/widgets/screen.js +8 -6
- package/external/blessed/lib/widgets/scrollablebox.js +1 -1
- package/external/blessed/lib/widgets/scrollabletext.js +1 -1
- package/external/blessed/lib/widgets/table.js +1 -1
- package/external/blessed/lib/widgets/terminal.js +1 -1
- package/external/blessed/lib/widgets/text.js +1 -1
- package/external/blessed/lib/widgets/textarea.js +1 -1
- package/external/blessed/lib/widgets/textbox.js +1 -1
- package/external/blessed/lib/widgets/video.js +1 -1
- package/external/blessed/vendor/tng.js +11 -4
- package/external/blessed-contrib/lib/widget/charts/bar.js +4 -4
- package/external/blessed-contrib/lib/widget/charts/line.js +4 -4
- package/logo-dark.png +0 -0
- package/logo-light.png +0 -0
- package/package.json +65 -96
- package/requirements.json +2 -2
- package/shadow-bin/npm +0 -0
- package/shadow-bin/npx +0 -0
package/dist/utils.js
CHANGED
|
@@ -11,21 +11,21 @@ var path$1 = require('../external/@socketsecurity/registry/lib/path');
|
|
|
11
11
|
var sorts = require('../external/@socketsecurity/registry/lib/sorts');
|
|
12
12
|
var spinner = require('../external/@socketsecurity/registry/lib/spinner');
|
|
13
13
|
var words = require('../external/@socketsecurity/registry/lib/words');
|
|
14
|
-
var Module = require('node:module');
|
|
15
|
-
var path = require('node:path');
|
|
16
14
|
var flags = require('./flags.js');
|
|
15
|
+
var path = require('node:path');
|
|
17
16
|
var regexps = require('../external/@socketsecurity/registry/lib/regexps');
|
|
18
17
|
var prompts = require('../external/@socketsecurity/registry/lib/prompts');
|
|
19
18
|
var spawn = require('../external/@socketsecurity/registry/lib/spawn');
|
|
20
19
|
var fs = require('../external/@socketsecurity/registry/lib/fs');
|
|
20
|
+
var require$$5 = require('node:module');
|
|
21
21
|
var shadowNpmBin = require('./shadow-npm-bin.js');
|
|
22
22
|
var fs$1 = require('node:fs');
|
|
23
|
+
var require$$13 = require('../external/@socketsecurity/registry/lib/url');
|
|
23
24
|
var promises = require('node:timers/promises');
|
|
24
25
|
var npm = require('../external/@socketsecurity/registry/lib/npm');
|
|
25
26
|
var globs = require('../external/@socketsecurity/registry/lib/globs');
|
|
26
27
|
var packages = require('../external/@socketsecurity/registry/lib/packages');
|
|
27
28
|
var streams = require('../external/@socketsecurity/registry/lib/streams');
|
|
28
|
-
var require$$13 = require('../external/@socketsecurity/registry/lib/url');
|
|
29
29
|
|
|
30
30
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
31
31
|
const sensitiveConfigKeyLookup = new Set(['apiToken']);
|
|
@@ -92,20 +92,30 @@ function findSocketYmlSync(dir = process.cwd()) {
|
|
|
92
92
|
if (typeof yml === 'string') {
|
|
93
93
|
try {
|
|
94
94
|
return {
|
|
95
|
-
|
|
96
|
-
|
|
95
|
+
ok: true,
|
|
96
|
+
data: {
|
|
97
|
+
path: ymlPath,
|
|
98
|
+
parsed: vendor.configExports.parseSocketConfig(yml)
|
|
99
|
+
}
|
|
97
100
|
};
|
|
98
101
|
} catch (e) {
|
|
99
102
|
require$$9.debugDir('inspect', {
|
|
100
103
|
error: e
|
|
101
104
|
});
|
|
102
|
-
|
|
105
|
+
return {
|
|
106
|
+
ok: false,
|
|
107
|
+
message: `Found file but was unable to parse ${ymlPath}`,
|
|
108
|
+
cause: e instanceof Error ? e.message : String(e)
|
|
109
|
+
};
|
|
103
110
|
}
|
|
104
111
|
}
|
|
105
112
|
prevDir = dir;
|
|
106
113
|
dir = path.join(dir, '..');
|
|
107
114
|
}
|
|
108
|
-
return
|
|
115
|
+
return {
|
|
116
|
+
ok: true,
|
|
117
|
+
data: undefined
|
|
118
|
+
};
|
|
109
119
|
}
|
|
110
120
|
function getConfigValue(key) {
|
|
111
121
|
const localConfig = getConfigValues();
|
|
@@ -256,6 +266,22 @@ function updateConfigValue(configKey, value) {
|
|
|
256
266
|
};
|
|
257
267
|
}
|
|
258
268
|
|
|
269
|
+
const require$2 = require$$5.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('utils.js', document.baseURI).href)));
|
|
270
|
+
let _requirements;
|
|
271
|
+
function getRequirements() {
|
|
272
|
+
if (_requirements === undefined) {
|
|
273
|
+
_requirements = /*@__PURE__*/require$2(path.join(constants.default.rootPath, 'requirements.json'));
|
|
274
|
+
}
|
|
275
|
+
return _requirements;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Convert command path to requirements key.
|
|
280
|
+
*/
|
|
281
|
+
function getRequirementsKey(cmdPath) {
|
|
282
|
+
return cmdPath.replace(/^socket[: ]/, '').replace(/ +/g, ':');
|
|
283
|
+
}
|
|
284
|
+
|
|
259
285
|
const TOKEN_PREFIX = 'sktsec_';
|
|
260
286
|
const TOKEN_PREFIX_LENGTH = TOKEN_PREFIX.length;
|
|
261
287
|
const TOKEN_VISIBLE_LENGTH = 5;
|
|
@@ -330,10 +356,14 @@ async function setupSdk(options) {
|
|
|
330
356
|
return {
|
|
331
357
|
ok: true,
|
|
332
358
|
data: new vendor.distExports.SocketSdk(apiToken, {
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
359
|
+
...(apiProxy ? {
|
|
360
|
+
agent: new ProxyAgent({
|
|
361
|
+
proxy: apiProxy
|
|
362
|
+
})
|
|
363
|
+
} : {}),
|
|
364
|
+
...(apiBaseUrl ? {
|
|
365
|
+
baseUrl: apiBaseUrl
|
|
366
|
+
} : {}),
|
|
337
367
|
timeout: constants.default.ENV.SOCKET_CLI_API_TIMEOUT,
|
|
338
368
|
userAgent: vendor.distExports.createUserAgentFromPkgJson({
|
|
339
369
|
name: constants.default.ENV.INLINED_SOCKET_CLI_NAME,
|
|
@@ -345,6 +375,32 @@ async function setupSdk(options) {
|
|
|
345
375
|
}
|
|
346
376
|
|
|
347
377
|
const NO_ERROR_MESSAGE = 'No error message returned';
|
|
378
|
+
/**
|
|
379
|
+
* Get command requirements from requirements.json based on command path.
|
|
380
|
+
*/
|
|
381
|
+
function getCommandRequirements(cmdPath) {
|
|
382
|
+
if (!cmdPath) {
|
|
383
|
+
return undefined;
|
|
384
|
+
}
|
|
385
|
+
const requirements = getRequirements();
|
|
386
|
+
const key = getRequirementsKey(cmdPath);
|
|
387
|
+
return requirements.api[key] || undefined;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* Log required permissions for a command when encountering 403 errors.
|
|
392
|
+
*/
|
|
393
|
+
function logPermissionsFor403(cmdPath) {
|
|
394
|
+
const requirements = getCommandRequirements(cmdPath);
|
|
395
|
+
if (!requirements?.permissions?.length) {
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
logger.logger.error('This command requires the following API permissions:');
|
|
399
|
+
for (const permission of requirements.permissions) {
|
|
400
|
+
logger.logger.error(` - ${permission}`);
|
|
401
|
+
}
|
|
402
|
+
logger.logger.error('Please ensure your API token has the required permissions.');
|
|
403
|
+
}
|
|
348
404
|
|
|
349
405
|
// The Socket API server that should be used for operations.
|
|
350
406
|
function getDefaultApiBaseUrl() {
|
|
@@ -355,6 +411,10 @@ function getDefaultApiBaseUrl() {
|
|
|
355
411
|
const API_V0_URL = constants.default.API_V0_URL;
|
|
356
412
|
return API_V0_URL;
|
|
357
413
|
}
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* Get user-friendly error message for HTTP status codes.
|
|
417
|
+
*/
|
|
358
418
|
async function getErrorMessageForHttpStatusCode(code) {
|
|
359
419
|
if (code === 400) {
|
|
360
420
|
return 'One of the options passed might be incorrect';
|
|
@@ -370,8 +430,12 @@ async function getErrorMessageForHttpStatusCode(code) {
|
|
|
370
430
|
}
|
|
371
431
|
return `Server responded with status code ${code}`;
|
|
372
432
|
}
|
|
433
|
+
/**
|
|
434
|
+
* Handle Socket SDK API calls with error handling and permission logging.
|
|
435
|
+
*/
|
|
373
436
|
async function handleApiCall(value, options) {
|
|
374
437
|
const {
|
|
438
|
+
commandPath,
|
|
375
439
|
description,
|
|
376
440
|
spinner
|
|
377
441
|
} = {
|
|
@@ -399,7 +463,7 @@ async function handleApiCall(value, options) {
|
|
|
399
463
|
spinner?.stop();
|
|
400
464
|
const socketSdkErrorResult = {
|
|
401
465
|
ok: false,
|
|
402
|
-
message: 'Socket API
|
|
466
|
+
message: 'Socket API error',
|
|
403
467
|
cause: vendor.messageWithCauses(e)
|
|
404
468
|
};
|
|
405
469
|
if (description) {
|
|
@@ -430,12 +494,17 @@ async function handleApiCall(value, options) {
|
|
|
430
494
|
const cause = reason && message !== reason ? `${message} (reason: ${reason})` : message;
|
|
431
495
|
const socketSdkErrorResult = {
|
|
432
496
|
ok: false,
|
|
433
|
-
message: 'Socket API
|
|
497
|
+
message: 'Socket API error',
|
|
434
498
|
cause,
|
|
435
499
|
data: {
|
|
436
500
|
code: sdkResult.status
|
|
437
501
|
}
|
|
438
502
|
};
|
|
503
|
+
|
|
504
|
+
// Log required permissions for 403 errors when in a command context.
|
|
505
|
+
if (commandPath && sdkResult.status === 403) {
|
|
506
|
+
logPermissionsFor403(commandPath);
|
|
507
|
+
}
|
|
439
508
|
return socketSdkErrorResult;
|
|
440
509
|
}
|
|
441
510
|
const socketSdkSuccessResult = {
|
|
@@ -454,7 +523,7 @@ async function handleApiCallNoSpinner(value, description) {
|
|
|
454
523
|
error: e
|
|
455
524
|
});
|
|
456
525
|
const errStr = e ? String(e).trim() : '';
|
|
457
|
-
const message = 'Socket API
|
|
526
|
+
const message = 'Socket API error';
|
|
458
527
|
const rawCause = errStr || NO_ERROR_MESSAGE;
|
|
459
528
|
const cause = message !== rawCause ? rawCause : '';
|
|
460
529
|
return {
|
|
@@ -479,7 +548,7 @@ async function handleApiCallNoSpinner(value, description) {
|
|
|
479
548
|
const cause = reason && message !== reason ? `${message} (reason: ${reason})` : message;
|
|
480
549
|
return {
|
|
481
550
|
ok: false,
|
|
482
|
-
message: 'Socket API
|
|
551
|
+
message: 'Socket API error',
|
|
483
552
|
cause,
|
|
484
553
|
data: {
|
|
485
554
|
code: sdkResult.status
|
|
@@ -494,9 +563,9 @@ async function handleApiCallNoSpinner(value, description) {
|
|
|
494
563
|
}
|
|
495
564
|
}
|
|
496
565
|
async function queryApi(path, apiToken) {
|
|
497
|
-
const baseUrl = getDefaultApiBaseUrl()
|
|
566
|
+
const baseUrl = getDefaultApiBaseUrl();
|
|
498
567
|
if (!baseUrl) {
|
|
499
|
-
|
|
568
|
+
throw new Error('Socket API endpoint is not configured');
|
|
500
569
|
}
|
|
501
570
|
return await fetch(`${baseUrl}${baseUrl.endsWith('/') ? '' : '/'}${path}`, {
|
|
502
571
|
method: 'GET',
|
|
@@ -505,7 +574,11 @@ async function queryApi(path, apiToken) {
|
|
|
505
574
|
}
|
|
506
575
|
});
|
|
507
576
|
}
|
|
508
|
-
|
|
577
|
+
|
|
578
|
+
/**
|
|
579
|
+
* Query Socket API endpoint and return text response with error handling.
|
|
580
|
+
*/
|
|
581
|
+
async function queryApiSafeText(path, description, commandPath) {
|
|
509
582
|
const apiToken = getDefaultApiToken();
|
|
510
583
|
if (!apiToken) {
|
|
511
584
|
return {
|
|
@@ -550,11 +623,10 @@ async function queryApiSafeText(path, description) {
|
|
|
550
623
|
const {
|
|
551
624
|
status
|
|
552
625
|
} = result;
|
|
553
|
-
const reason = await getErrorMessageForHttpStatusCode(status);
|
|
554
626
|
return {
|
|
555
627
|
ok: false,
|
|
556
|
-
message: 'Socket API
|
|
557
|
-
cause: `${result.statusText} (reason: ${
|
|
628
|
+
message: 'Socket API error',
|
|
629
|
+
cause: `${result.statusText} (reason: ${await getErrorMessageForHttpStatusCode(status)})`,
|
|
558
630
|
data: {
|
|
559
631
|
code: status
|
|
560
632
|
}
|
|
@@ -578,6 +650,10 @@ async function queryApiSafeText(path, description) {
|
|
|
578
650
|
};
|
|
579
651
|
}
|
|
580
652
|
}
|
|
653
|
+
|
|
654
|
+
/**
|
|
655
|
+
* Query Socket API endpoint and return parsed JSON response.
|
|
656
|
+
*/
|
|
581
657
|
async function queryApiSafeJson(path, description = '') {
|
|
582
658
|
const result = await queryApiSafeText(path, description);
|
|
583
659
|
if (!result.ok) {
|
|
@@ -592,10 +668,13 @@ async function queryApiSafeJson(path, description = '') {
|
|
|
592
668
|
return {
|
|
593
669
|
ok: false,
|
|
594
670
|
message: 'Server returned invalid JSON',
|
|
595
|
-
cause: `Please report this. JSON.parse threw an error over the following response: \`${(result.data?.slice?.(0, 100) ||
|
|
671
|
+
cause: `Please report this. JSON.parse threw an error over the following response: \`${(result.data?.slice?.(0, 100) || constants.EMPTY_VALUE).trim() + (result.data?.length > 100 ? '...' : '')}\``
|
|
596
672
|
};
|
|
597
673
|
}
|
|
598
674
|
}
|
|
675
|
+
/**
|
|
676
|
+
* Send POST/PUT request to Socket API with JSON response handling.
|
|
677
|
+
*/
|
|
599
678
|
async function sendApiRequest(path, options) {
|
|
600
679
|
const apiToken = getDefaultApiToken();
|
|
601
680
|
if (!apiToken) {
|
|
@@ -605,12 +684,17 @@ async function sendApiRequest(path, options) {
|
|
|
605
684
|
cause: 'User must be authenticated to run this command. To log in, run the command `socket login` and enter your Socket API token.'
|
|
606
685
|
};
|
|
607
686
|
}
|
|
608
|
-
const baseUrl = getDefaultApiBaseUrl()
|
|
687
|
+
const baseUrl = getDefaultApiBaseUrl();
|
|
609
688
|
if (!baseUrl) {
|
|
610
|
-
|
|
689
|
+
return {
|
|
690
|
+
ok: false,
|
|
691
|
+
message: 'Configuration Error',
|
|
692
|
+
cause: 'Socket API endpoint is not configured. Please check your environment configuration.'
|
|
693
|
+
};
|
|
611
694
|
}
|
|
612
695
|
const {
|
|
613
696
|
body,
|
|
697
|
+
commandPath,
|
|
614
698
|
description,
|
|
615
699
|
method
|
|
616
700
|
} = {
|
|
@@ -663,11 +747,14 @@ async function sendApiRequest(path, options) {
|
|
|
663
747
|
const {
|
|
664
748
|
status
|
|
665
749
|
} = result;
|
|
666
|
-
|
|
750
|
+
// Log required permissions for 403 errors when in a command context.
|
|
751
|
+
if (commandPath && status === 403) {
|
|
752
|
+
logPermissionsFor403(commandPath);
|
|
753
|
+
}
|
|
667
754
|
return {
|
|
668
755
|
ok: false,
|
|
669
|
-
message: 'Socket API
|
|
670
|
-
cause: `${result.statusText} (reason: ${
|
|
756
|
+
message: 'Socket API error',
|
|
757
|
+
cause: `${result.statusText} (reason: ${await getErrorMessageForHttpStatusCode(status)})`,
|
|
671
758
|
data: {
|
|
672
759
|
code: status
|
|
673
760
|
}
|
|
@@ -693,7 +780,7 @@ async function sendApiRequest(path, options) {
|
|
|
693
780
|
}
|
|
694
781
|
|
|
695
782
|
function failMsgWithBadge(badge, message) {
|
|
696
|
-
const prefix = vendor.yoctocolorsCjsExports.
|
|
783
|
+
const prefix = vendor.yoctocolorsCjsExports.bgRedBright(vendor.yoctocolorsCjsExports.bold(vendor.yoctocolorsCjsExports.red(` ${badge}${message ? ': ' : ''}`)));
|
|
697
784
|
const postfix = message ? ` ${vendor.yoctocolorsCjsExports.bold(message)}` : '';
|
|
698
785
|
return `${prefix}${postfix}`;
|
|
699
786
|
}
|
|
@@ -887,18 +974,10 @@ function getOutputKind(json, markdown) {
|
|
|
887
974
|
return constants.OUTPUT_TEXT;
|
|
888
975
|
}
|
|
889
976
|
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
function getRequirements() {
|
|
893
|
-
if (_requirements === undefined) {
|
|
894
|
-
_requirements = /*@__PURE__*/require$2(path.join(constants.default.rootPath, 'requirements.json'));
|
|
895
|
-
}
|
|
896
|
-
return _requirements;
|
|
977
|
+
function camelToKebab(str) {
|
|
978
|
+
return str === '' ? '' : str.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
|
|
897
979
|
}
|
|
898
980
|
|
|
899
|
-
function camelToKebab(string) {
|
|
900
|
-
return string.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
|
|
901
|
-
}
|
|
902
981
|
function getFlagApiRequirementsOutput(cmdPath, options) {
|
|
903
982
|
const {
|
|
904
983
|
indent = 6
|
|
@@ -906,20 +985,21 @@ function getFlagApiRequirementsOutput(cmdPath, options) {
|
|
|
906
985
|
__proto__: null,
|
|
907
986
|
...options
|
|
908
987
|
};
|
|
909
|
-
const key = cmdPath
|
|
988
|
+
const key = getRequirementsKey(cmdPath);
|
|
910
989
|
const requirements = getRequirements();
|
|
911
990
|
const data = requirements.api[key];
|
|
912
991
|
let result = '';
|
|
913
992
|
if (data) {
|
|
914
993
|
const quota = data?.quota;
|
|
915
|
-
const
|
|
994
|
+
const rawPerms = data?.permissions;
|
|
916
995
|
const padding = ''.padEnd(indent);
|
|
917
996
|
const lines = [];
|
|
918
|
-
if (
|
|
997
|
+
if (Number.isFinite(quota) && quota > 0) {
|
|
919
998
|
lines.push(`${padding}- Quota: ${quota} ${words.pluralize('unit', quota)}`);
|
|
920
999
|
}
|
|
921
|
-
if (Array.isArray(
|
|
922
|
-
|
|
1000
|
+
if (Array.isArray(rawPerms) && rawPerms.length) {
|
|
1001
|
+
const perms = rawPerms.slice().sort(sorts.naturalCompare);
|
|
1002
|
+
lines.push(`${padding}- Permissions: ${arrays.joinAnd(perms)}`);
|
|
923
1003
|
}
|
|
924
1004
|
result += lines.join('\n');
|
|
925
1005
|
}
|
|
@@ -980,6 +1060,10 @@ function tildify(cwd) {
|
|
|
980
1060
|
|
|
981
1061
|
const HELP_INDENT = 2;
|
|
982
1062
|
const HELP_PAD_NAME = 28;
|
|
1063
|
+
|
|
1064
|
+
/**
|
|
1065
|
+
* Format a command description for help output.
|
|
1066
|
+
*/
|
|
983
1067
|
function description(command) {
|
|
984
1068
|
const description = command?.description;
|
|
985
1069
|
const str = typeof description === 'string' ? description : String(description);
|
|
@@ -1004,6 +1088,10 @@ function findBestCommandMatch(input, subcommands, aliases) {
|
|
|
1004
1088
|
}
|
|
1005
1089
|
return bestMatch;
|
|
1006
1090
|
}
|
|
1091
|
+
|
|
1092
|
+
/**
|
|
1093
|
+
* Generate the ASCII banner header for Socket CLI commands.
|
|
1094
|
+
*/
|
|
1007
1095
|
function getAsciiHeader(command, orgFlag) {
|
|
1008
1096
|
// Note: In tests we return <redacted> because otherwise snapshots will fail.
|
|
1009
1097
|
const {
|
|
@@ -1047,19 +1135,28 @@ function levenshteinDistance(a, b) {
|
|
|
1047
1135
|
for (let i = 1; i <= a.length; i++) {
|
|
1048
1136
|
for (let j = 1; j <= b.length; j++) {
|
|
1049
1137
|
const cost = a[i - 1] === b[j - 1] ? 0 : 1;
|
|
1050
|
-
matrix[i][j] = Math.min(
|
|
1138
|
+
matrix[i][j] = Math.min(
|
|
1051
1139
|
// Deletion.
|
|
1052
|
-
matrix[i
|
|
1140
|
+
matrix[i - 1][j] + 1,
|
|
1053
1141
|
// Insertion.
|
|
1054
|
-
matrix[i
|
|
1055
|
-
|
|
1142
|
+
matrix[i][j - 1] + 1,
|
|
1143
|
+
// Substitution.
|
|
1144
|
+
matrix[i - 1][j - 1] + cost);
|
|
1056
1145
|
}
|
|
1057
1146
|
}
|
|
1058
1147
|
return matrix[a.length][b.length];
|
|
1059
1148
|
}
|
|
1149
|
+
|
|
1150
|
+
/**
|
|
1151
|
+
* Determine if the banner should be suppressed based on output flags.
|
|
1152
|
+
*/
|
|
1060
1153
|
function shouldSuppressBanner(flags) {
|
|
1061
|
-
return Boolean(flags['json'] || flags['markdown'] || flags['
|
|
1154
|
+
return Boolean(flags['json'] || flags['markdown'] || flags['banner'] === false);
|
|
1062
1155
|
}
|
|
1156
|
+
|
|
1157
|
+
/**
|
|
1158
|
+
* Emit the Socket CLI banner to stderr for branding and debugging.
|
|
1159
|
+
*/
|
|
1063
1160
|
function emitBanner(name, orgFlag) {
|
|
1064
1161
|
// Print a banner at the top of each command.
|
|
1065
1162
|
// This helps with brand recognition and marketing.
|
|
@@ -1071,6 +1168,10 @@ function emitBanner(name, orgFlag) {
|
|
|
1071
1168
|
// The spinner also emits over stderr for example.
|
|
1072
1169
|
logger.logger.error(getAsciiHeader(name, orgFlag));
|
|
1073
1170
|
}
|
|
1171
|
+
|
|
1172
|
+
/**
|
|
1173
|
+
* Main function for handling CLI with subcommands using meow.
|
|
1174
|
+
*/
|
|
1074
1175
|
async function meowWithSubcommands(subcommands, options) {
|
|
1075
1176
|
const {
|
|
1076
1177
|
aliases = {},
|
|
@@ -1083,11 +1184,6 @@ async function meowWithSubcommands(subcommands, options) {
|
|
|
1083
1184
|
__proto__: null,
|
|
1084
1185
|
...options
|
|
1085
1186
|
};
|
|
1086
|
-
const [commandOrAliasName_, ...rawCommandArgv] = argv;
|
|
1087
|
-
let commandOrAliasName = commandOrAliasName_;
|
|
1088
|
-
if (!commandOrAliasName && defaultSub) {
|
|
1089
|
-
commandOrAliasName = defaultSub;
|
|
1090
|
-
}
|
|
1091
1187
|
const flags$1 = {
|
|
1092
1188
|
...flags.commonFlags,
|
|
1093
1189
|
version: {
|
|
@@ -1095,13 +1191,18 @@ async function meowWithSubcommands(subcommands, options) {
|
|
|
1095
1191
|
hidden: true,
|
|
1096
1192
|
description: 'Print the app version'
|
|
1097
1193
|
},
|
|
1098
|
-
...additionalOptions
|
|
1194
|
+
...require$$11.getOwn(additionalOptions, 'flags')
|
|
1099
1195
|
};
|
|
1196
|
+
const [commandOrAliasName_, ...rawCommandArgv] = argv;
|
|
1197
|
+
let commandOrAliasName = commandOrAliasName_;
|
|
1198
|
+
if (!commandOrAliasName && defaultSub) {
|
|
1199
|
+
commandOrAliasName = defaultSub;
|
|
1200
|
+
}
|
|
1100
1201
|
|
|
1101
|
-
// No further args or first arg is a flag (shrug)
|
|
1202
|
+
// No further args or first arg is a flag (shrug).
|
|
1102
1203
|
const isRootCommand = name === 'socket' && (!commandOrAliasName || commandOrAliasName?.startsWith('-'));
|
|
1103
1204
|
|
|
1104
|
-
// Try to support `socket <purl>` as a shorthand for `socket package score <purl
|
|
1205
|
+
// Try to support `socket <purl>` as a shorthand for `socket package score <purl>`.
|
|
1105
1206
|
if (!isRootCommand) {
|
|
1106
1207
|
if (commandOrAliasName?.startsWith('pkg:')) {
|
|
1107
1208
|
logger.logger.info('Invoking `socket package score`.');
|
|
@@ -1174,7 +1275,6 @@ async function meowWithSubcommands(subcommands, options) {
|
|
|
1174
1275
|
if (noSpinner) {
|
|
1175
1276
|
constants.default.spinner.spinner = spinner.getCliSpinners('ci');
|
|
1176
1277
|
}
|
|
1177
|
-
|
|
1178
1278
|
// Hard override the config if instructed to do so.
|
|
1179
1279
|
// The env var overrides the --flag, which overrides the persisted config
|
|
1180
1280
|
// Also, when either of these are used, config updates won't persist.
|
|
@@ -1182,7 +1282,7 @@ async function meowWithSubcommands(subcommands, options) {
|
|
|
1182
1282
|
if (constants.default.ENV.SOCKET_CLI_CONFIG) {
|
|
1183
1283
|
configOverrideResult = overrideCachedConfig(constants.default.ENV.SOCKET_CLI_CONFIG);
|
|
1184
1284
|
} else if (cli1.flags['config']) {
|
|
1185
|
-
configOverrideResult = overrideCachedConfig(
|
|
1285
|
+
configOverrideResult = overrideCachedConfig(cli1.flags['config']);
|
|
1186
1286
|
}
|
|
1187
1287
|
if (constants.default.ENV.SOCKET_CLI_NO_API_TOKEN) {
|
|
1188
1288
|
// This overrides the config override and even the explicit token env var.
|
|
@@ -1216,6 +1316,8 @@ async function meowWithSubcommands(subcommands, options) {
|
|
|
1216
1316
|
const commandDefinition = commandName ? subcommands[commandName] : undefined;
|
|
1217
1317
|
// Third: If a valid command has been found, then we run it...
|
|
1218
1318
|
if (commandDefinition) {
|
|
1319
|
+
// Extract the original command arguments from the full argv
|
|
1320
|
+
// by skipping the command name
|
|
1219
1321
|
return await commandDefinition.run(commandArgv, importMeta, {
|
|
1220
1322
|
parentName: name
|
|
1221
1323
|
});
|
|
@@ -1303,7 +1405,7 @@ async function meowWithSubcommands(subcommands, options) {
|
|
|
1303
1405
|
|
|
1304
1406
|
// Parse it again. Config overrides should now be applied (may affect help).
|
|
1305
1407
|
// Note: this is displayed as help screen if the command does not override it
|
|
1306
|
-
// (which is the case for most sub-commands with sub-commands)
|
|
1408
|
+
// (which is the case for most sub-commands with sub-commands).
|
|
1307
1409
|
const cli2 = vendor.meow({
|
|
1308
1410
|
argv,
|
|
1309
1411
|
importMeta,
|
|
@@ -1323,7 +1425,7 @@ async function meowWithSubcommands(subcommands, options) {
|
|
|
1323
1425
|
// ...else we provide basic instructions and help.
|
|
1324
1426
|
if (!shouldSuppressBanner(cli2.flags)) {
|
|
1325
1427
|
emitBanner(name, orgFlag);
|
|
1326
|
-
//
|
|
1428
|
+
// Meow will add newline so don't add stderr spacing here.
|
|
1327
1429
|
}
|
|
1328
1430
|
if (!cli2.flags['help'] && cli2.flags['dryRun']) {
|
|
1329
1431
|
process.exitCode = 0;
|
|
@@ -1336,7 +1438,8 @@ async function meowWithSubcommands(subcommands, options) {
|
|
|
1336
1438
|
}
|
|
1337
1439
|
|
|
1338
1440
|
/**
|
|
1339
|
-
*
|
|
1441
|
+
* Create meow CLI instance or exit with help/error (meow will exit immediately
|
|
1442
|
+
* if it calls .showHelp()).
|
|
1340
1443
|
*/
|
|
1341
1444
|
function meowOrExit({
|
|
1342
1445
|
allowUnknownFlags = true,
|
|
@@ -1361,14 +1464,19 @@ function meowOrExit({
|
|
|
1361
1464
|
help: strings.trimNewlines(config.help(command, config)),
|
|
1362
1465
|
importMeta
|
|
1363
1466
|
});
|
|
1364
|
-
const
|
|
1467
|
+
const {
|
|
1468
|
+
help,
|
|
1469
|
+
org: orgFlag,
|
|
1470
|
+
spinner: spinnerFlag,
|
|
1471
|
+
version
|
|
1472
|
+
} = cli.flags;
|
|
1473
|
+
const noSpinner = spinnerFlag === false;
|
|
1365
1474
|
|
|
1366
1475
|
// Use CI spinner style when --no-spinner is passed.
|
|
1367
1476
|
if (noSpinner) {
|
|
1368
1477
|
constants.default.spinner.spinner = spinner.getCliSpinners('ci');
|
|
1369
1478
|
}
|
|
1370
1479
|
if (!shouldSuppressBanner(cli.flags)) {
|
|
1371
|
-
const orgFlag = String(cli.flags['org'] || '').trim() || undefined;
|
|
1372
1480
|
emitBanner(command, orgFlag);
|
|
1373
1481
|
// Add newline in stderr.
|
|
1374
1482
|
// Meow help adds a newline too so we do it here.
|
|
@@ -1393,12 +1501,12 @@ function meowOrExit({
|
|
|
1393
1501
|
// })
|
|
1394
1502
|
// }
|
|
1395
1503
|
|
|
1396
|
-
if (
|
|
1504
|
+
if (help) {
|
|
1397
1505
|
cli.showHelp(0);
|
|
1398
1506
|
}
|
|
1399
1507
|
|
|
1400
1508
|
// Meow doesn't detect 'version' as an unknown flag, so we do the leg work here.
|
|
1401
|
-
if (!require$$11.hasOwn(config.flags, 'version')
|
|
1509
|
+
if (version && !require$$11.hasOwn(config.flags, 'version')) {
|
|
1402
1510
|
// Use `console.error` here instead of `logger.error` to match Meow behavior.
|
|
1403
1511
|
console.error('Unknown flag\n--version');
|
|
1404
1512
|
// eslint-disable-next-line n/no-process-exit
|
|
@@ -1408,7 +1516,6 @@ function meowOrExit({
|
|
|
1408
1516
|
// Now test for help state. Run Meow again. If it exits now, it must be due
|
|
1409
1517
|
// to wanting to print the help screen. But it would exit(0) and we want a
|
|
1410
1518
|
// consistent exit(2) for that case (missing input).
|
|
1411
|
-
// TODO: Move away from meow.
|
|
1412
1519
|
process.exitCode = 2;
|
|
1413
1520
|
vendor.meow({
|
|
1414
1521
|
argv,
|
|
@@ -1679,7 +1786,7 @@ async function getBaseBranch(cwd = process.cwd()) {
|
|
|
1679
1786
|
return 'main';
|
|
1680
1787
|
}
|
|
1681
1788
|
async function getRepoInfo(cwd = process.cwd()) {
|
|
1682
|
-
let info
|
|
1789
|
+
let info;
|
|
1683
1790
|
const quotedCmd = '`git remote get-url origin`';
|
|
1684
1791
|
require$$9.debugFn('stdio', `spawn: ${quotedCmd}`);
|
|
1685
1792
|
try {
|
|
@@ -1745,7 +1852,7 @@ async function gitBranch(cwd = process.cwd()) {
|
|
|
1745
1852
|
});
|
|
1746
1853
|
}
|
|
1747
1854
|
}
|
|
1748
|
-
return
|
|
1855
|
+
return undefined;
|
|
1749
1856
|
}
|
|
1750
1857
|
|
|
1751
1858
|
/**
|
|
@@ -2056,7 +2163,7 @@ async function gitUnstagedModifiedFiles(cwd = process.cwd()) {
|
|
|
2056
2163
|
}
|
|
2057
2164
|
const parsedGitRemoteUrlCache = new Map();
|
|
2058
2165
|
function parseGitRemoteUrl(remoteUrl) {
|
|
2059
|
-
let result = parsedGitRemoteUrlCache.get(remoteUrl)
|
|
2166
|
+
let result = parsedGitRemoteUrlCache.get(remoteUrl);
|
|
2060
2167
|
if (result) {
|
|
2061
2168
|
return {
|
|
2062
2169
|
...result
|
|
@@ -2108,7 +2215,7 @@ function getPurlObject(purl, options) {
|
|
|
2108
2215
|
if (shouldThrow) {
|
|
2109
2216
|
throw e;
|
|
2110
2217
|
}
|
|
2111
|
-
return
|
|
2218
|
+
return undefined;
|
|
2112
2219
|
}
|
|
2113
2220
|
}
|
|
2114
2221
|
function normalizePurl(rawPurl) {
|
|
@@ -2501,7 +2608,7 @@ function getNpmRequire() {
|
|
|
2501
2608
|
if (_npmRequire === undefined) {
|
|
2502
2609
|
const npmDirPath = getNpmDirPath();
|
|
2503
2610
|
const npmNmPath = path.join(npmDirPath, `${constants.NODE_MODULES}/npm`);
|
|
2504
|
-
_npmRequire =
|
|
2611
|
+
_npmRequire = require$$5.createRequire(path.join(fs$1.existsSync(npmNmPath) ? npmNmPath : npmDirPath, '<dummy-basename>'));
|
|
2505
2612
|
}
|
|
2506
2613
|
return _npmRequire;
|
|
2507
2614
|
}
|
|
@@ -2530,23 +2637,33 @@ function isNpxBinPathShadowed() {
|
|
|
2530
2637
|
}
|
|
2531
2638
|
|
|
2532
2639
|
const helpFlags = new Set(['--help', '-h']);
|
|
2640
|
+
|
|
2641
|
+
/**
|
|
2642
|
+
* Convert command arguments to a properly formatted string representation.
|
|
2643
|
+
*/
|
|
2533
2644
|
function cmdFlagsToString(args) {
|
|
2534
2645
|
const result = [];
|
|
2535
2646
|
for (let i = 0, {
|
|
2536
2647
|
length
|
|
2537
2648
|
} = args; i < length; i += 1) {
|
|
2538
|
-
|
|
2649
|
+
const arg = args[i].trim();
|
|
2650
|
+
if (arg.startsWith('--')) {
|
|
2651
|
+
const nextArg = i + 1 < length ? args[i + 1].trim() : undefined;
|
|
2539
2652
|
// Check if the next item exists and is NOT another flag.
|
|
2540
|
-
if (
|
|
2541
|
-
result.push(`${
|
|
2653
|
+
if (nextArg?.startsWith('--')) {
|
|
2654
|
+
result.push(`${arg}=${nextArg}`);
|
|
2542
2655
|
i += 1;
|
|
2543
2656
|
} else {
|
|
2544
|
-
result.push(
|
|
2657
|
+
result.push(arg);
|
|
2545
2658
|
}
|
|
2546
2659
|
}
|
|
2547
2660
|
}
|
|
2548
2661
|
return result.join(' ');
|
|
2549
2662
|
}
|
|
2663
|
+
|
|
2664
|
+
/**
|
|
2665
|
+
* Convert flag values to array format for processing.
|
|
2666
|
+
*/
|
|
2550
2667
|
function cmdFlagValueToArray(value) {
|
|
2551
2668
|
if (typeof value === 'string') {
|
|
2552
2669
|
return value.trim().split(/, */).filter(Boolean);
|
|
@@ -2556,10 +2673,81 @@ function cmdFlagValueToArray(value) {
|
|
|
2556
2673
|
}
|
|
2557
2674
|
return [];
|
|
2558
2675
|
}
|
|
2676
|
+
|
|
2677
|
+
/**
|
|
2678
|
+
* Add command name prefix to message text.
|
|
2679
|
+
*/
|
|
2559
2680
|
function cmdPrefixMessage(cmdName, text) {
|
|
2560
2681
|
const cmdPrefix = cmdName ? `${cmdName}: ` : '';
|
|
2561
2682
|
return `${cmdPrefix}${text}`;
|
|
2562
2683
|
}
|
|
2684
|
+
|
|
2685
|
+
/**
|
|
2686
|
+
* Filter out Socket flags from argv before passing to subcommands.
|
|
2687
|
+
*/
|
|
2688
|
+
function filterFlags(argv, flagsToFilter, exceptions) {
|
|
2689
|
+
const filtered = [];
|
|
2690
|
+
|
|
2691
|
+
// Build set of flags to filter from the provided flag objects.
|
|
2692
|
+
const flagsToFilterSet = new Set();
|
|
2693
|
+
const flagsWithValueSet = new Set();
|
|
2694
|
+
for (const [flagName, flag] of Object.entries(flagsToFilter)) {
|
|
2695
|
+
const longFlag = `--${camelToKebab(flagName)}`;
|
|
2696
|
+
// Special case for negated booleans.
|
|
2697
|
+
if (flagName === 'spinner' || flagName === 'banner') {
|
|
2698
|
+
flagsToFilterSet.add(`--no-${flagName}`);
|
|
2699
|
+
} else {
|
|
2700
|
+
flagsToFilterSet.add(longFlag);
|
|
2701
|
+
}
|
|
2702
|
+
if (flag?.shortFlag) {
|
|
2703
|
+
flagsToFilterSet.add(`-${flag.shortFlag}`);
|
|
2704
|
+
}
|
|
2705
|
+
// Track flags that take values.
|
|
2706
|
+
if (flag.type !== 'boolean') {
|
|
2707
|
+
flagsWithValueSet.add(longFlag);
|
|
2708
|
+
if (flag?.shortFlag) {
|
|
2709
|
+
flagsWithValueSet.add(`-${flag.shortFlag}`);
|
|
2710
|
+
}
|
|
2711
|
+
}
|
|
2712
|
+
}
|
|
2713
|
+
for (let i = 0, {
|
|
2714
|
+
length
|
|
2715
|
+
} = argv; i < length; i += 1) {
|
|
2716
|
+
const arg = argv[i];
|
|
2717
|
+
// Check if this flag should be kept as an exception.
|
|
2718
|
+
if (exceptions?.includes(arg)) {
|
|
2719
|
+
filtered.push(arg);
|
|
2720
|
+
// Handle flags that take values.
|
|
2721
|
+
if (flagsWithValueSet.has(arg)) {
|
|
2722
|
+
// Include the next argument (the flag value).
|
|
2723
|
+
i += 1;
|
|
2724
|
+
if (i < length) {
|
|
2725
|
+
filtered.push(argv[i]);
|
|
2726
|
+
}
|
|
2727
|
+
}
|
|
2728
|
+
} else if (flagsToFilterSet.has(arg)) {
|
|
2729
|
+
// Skip flags that take values.
|
|
2730
|
+
if (flagsWithValueSet.has(arg)) {
|
|
2731
|
+
// Skip the next argument (the flag value).
|
|
2732
|
+
i += 1;
|
|
2733
|
+
}
|
|
2734
|
+
// Skip boolean flags (no additional argument to skip).
|
|
2735
|
+
} else if (arg && Array.from(flagsWithValueSet).some(flag => arg.startsWith(`${flag}=`))) {
|
|
2736
|
+
// Skip --flag=value format for Socket flags unless it's an exception.
|
|
2737
|
+
if (exceptions?.some(exc => arg.startsWith(`${exc}=`))) {
|
|
2738
|
+
filtered.push(arg);
|
|
2739
|
+
}
|
|
2740
|
+
// Otherwise skip it.
|
|
2741
|
+
} else {
|
|
2742
|
+
filtered.push(arg);
|
|
2743
|
+
}
|
|
2744
|
+
}
|
|
2745
|
+
return filtered;
|
|
2746
|
+
}
|
|
2747
|
+
|
|
2748
|
+
/**
|
|
2749
|
+
* Check if argument is a help flag.
|
|
2750
|
+
*/
|
|
2563
2751
|
function isHelpFlag(cmdArg) {
|
|
2564
2752
|
return helpFlags.has(cmdArg);
|
|
2565
2753
|
}
|
|
@@ -2809,7 +2997,7 @@ ttlMs = 5 * 60 * 1000) {
|
|
|
2809
2997
|
return await fs.readJson(cacheJsonPath);
|
|
2810
2998
|
}
|
|
2811
2999
|
}
|
|
2812
|
-
return
|
|
3000
|
+
return undefined;
|
|
2813
3001
|
}
|
|
2814
3002
|
async function writeCache(key, data) {
|
|
2815
3003
|
const {
|
|
@@ -2959,8 +3147,17 @@ async function enablePrAutoMerge({
|
|
|
2959
3147
|
}
|
|
2960
3148
|
async function setGitRemoteGithubRepoUrl(owner, repo, token, cwd = process.cwd()) {
|
|
2961
3149
|
const {
|
|
2962
|
-
|
|
2963
|
-
} =
|
|
3150
|
+
GITHUB_SERVER_URL
|
|
3151
|
+
} = constants.default.ENV;
|
|
3152
|
+
const urlObj = require$$13.parseUrl(GITHUB_SERVER_URL);
|
|
3153
|
+
const host = urlObj?.host;
|
|
3154
|
+
if (!host) {
|
|
3155
|
+
require$$9.debugFn('error', 'invalid: GITHUB_SERVER_URL env var');
|
|
3156
|
+
require$$9.debugDir('inspect', {
|
|
3157
|
+
GITHUB_SERVER_URL
|
|
3158
|
+
});
|
|
3159
|
+
return false;
|
|
3160
|
+
}
|
|
2964
3161
|
const url = `https://x-access-token:${token}@${host}/${owner}/${repo}`;
|
|
2965
3162
|
const stdioIgnoreOptions = {
|
|
2966
3163
|
cwd,
|
|
@@ -2980,13 +3177,106 @@ async function setGitRemoteGithubRepoUrl(owner, repo, token, cwd = process.cwd()
|
|
|
2980
3177
|
return false;
|
|
2981
3178
|
}
|
|
2982
3179
|
|
|
2983
|
-
|
|
3180
|
+
/**
|
|
3181
|
+
* Converts CVE IDs to GHSA IDs using GitHub API.
|
|
3182
|
+
*/
|
|
3183
|
+
async function convertCveToGhsa(cveId) {
|
|
3184
|
+
try {
|
|
3185
|
+
const cacheKey = `cve-to-ghsa-${cveId}`;
|
|
3186
|
+
const octokit = getOctokit();
|
|
3187
|
+
const response = await cacheFetch(cacheKey, () => octokit.rest.securityAdvisories.listGlobalAdvisories({
|
|
3188
|
+
cve_id: cveId,
|
|
3189
|
+
per_page: 1
|
|
3190
|
+
}));
|
|
3191
|
+
if (!response.data.length) {
|
|
3192
|
+
return {
|
|
3193
|
+
ok: false,
|
|
3194
|
+
message: `No GHSA found for CVE ${cveId}`
|
|
3195
|
+
};
|
|
3196
|
+
}
|
|
3197
|
+
return {
|
|
3198
|
+
ok: true,
|
|
3199
|
+
data: response.data[0].ghsa_id
|
|
3200
|
+
};
|
|
3201
|
+
} catch (e) {
|
|
3202
|
+
return {
|
|
3203
|
+
ok: false,
|
|
3204
|
+
message: `Failed to convert CVE to GHSA: ${e instanceof Error ? e.message : 'Unknown error'}`
|
|
3205
|
+
};
|
|
3206
|
+
}
|
|
3207
|
+
}
|
|
3208
|
+
|
|
3209
|
+
const PURL_TO_GITHUB_ECOSYSTEM_MAPPING = {
|
|
3210
|
+
__proto__: null,
|
|
3211
|
+
// GitHub Advisory Database supported ecosystems
|
|
3212
|
+
cargo: 'rust',
|
|
3213
|
+
composer: 'composer',
|
|
3214
|
+
gem: 'rubygems',
|
|
3215
|
+
go: 'go',
|
|
3216
|
+
golang: 'go',
|
|
3217
|
+
maven: 'maven',
|
|
3218
|
+
npm: 'npm',
|
|
3219
|
+
nuget: 'nuget',
|
|
3220
|
+
pypi: 'pip',
|
|
3221
|
+
swift: 'swift'
|
|
3222
|
+
};
|
|
3223
|
+
|
|
3224
|
+
/**
|
|
3225
|
+
* Converts PURL to GHSA IDs using GitHub API.
|
|
3226
|
+
*/
|
|
3227
|
+
async function convertPurlToGhsas(purl) {
|
|
3228
|
+
try {
|
|
3229
|
+
const purlObj = getPurlObject(purl, {
|
|
3230
|
+
throws: false
|
|
3231
|
+
});
|
|
3232
|
+
if (!purlObj) {
|
|
3233
|
+
return {
|
|
3234
|
+
ok: false,
|
|
3235
|
+
message: `Invalid PURL format: ${purl}`
|
|
3236
|
+
};
|
|
3237
|
+
}
|
|
3238
|
+
const {
|
|
3239
|
+
name,
|
|
3240
|
+
type: ecosystem,
|
|
3241
|
+
version
|
|
3242
|
+
} = purlObj;
|
|
3243
|
+
|
|
3244
|
+
// Map PURL ecosystem to GitHub ecosystem.
|
|
3245
|
+
const githubEcosystem = PURL_TO_GITHUB_ECOSYSTEM_MAPPING[ecosystem];
|
|
3246
|
+
if (!githubEcosystem) {
|
|
3247
|
+
return {
|
|
3248
|
+
ok: false,
|
|
3249
|
+
message: `Unsupported PURL ecosystem: ${ecosystem}`
|
|
3250
|
+
};
|
|
3251
|
+
}
|
|
3252
|
+
|
|
3253
|
+
// Search for advisories affecting this package.
|
|
3254
|
+
const cacheKey = `purl-to-ghsa-${ecosystem}-${name}-${version || constants.LATEST}`;
|
|
3255
|
+
const octokit = getOctokit();
|
|
3256
|
+
const affects = version ? `${name}@${version}` : name;
|
|
3257
|
+
const response = await cacheFetch(cacheKey, () => octokit.rest.securityAdvisories.listGlobalAdvisories({
|
|
3258
|
+
ecosystem: githubEcosystem,
|
|
3259
|
+
affects
|
|
3260
|
+
}));
|
|
3261
|
+
return {
|
|
3262
|
+
ok: true,
|
|
3263
|
+
data: response.data.map(a => a.ghsa_id)
|
|
3264
|
+
};
|
|
3265
|
+
} catch (e) {
|
|
3266
|
+
return {
|
|
3267
|
+
ok: false,
|
|
3268
|
+
message: `Failed to convert PURL to GHSA: ${e instanceof Error ? e.message : constants.UNKNOWN_ERROR}`
|
|
3269
|
+
};
|
|
3270
|
+
}
|
|
3271
|
+
}
|
|
3272
|
+
|
|
3273
|
+
const RangeStyles = ['pin', 'preserve'];
|
|
2984
3274
|
function getMajor(version) {
|
|
2985
3275
|
try {
|
|
2986
3276
|
const coerced = vendor.semverExports.coerce(version);
|
|
2987
|
-
return coerced ? vendor.semverExports.major(coerced) :
|
|
3277
|
+
return coerced ? vendor.semverExports.major(coerced) : undefined;
|
|
2988
3278
|
} catch {}
|
|
2989
|
-
return
|
|
3279
|
+
return undefined;
|
|
2990
3280
|
}
|
|
2991
3281
|
|
|
2992
3282
|
const COMPLETION_CMD_PREFIX = 'complete -F _socket_completion';
|
|
@@ -3078,7 +3368,7 @@ function npa(...args) {
|
|
|
3078
3368
|
try {
|
|
3079
3369
|
return Reflect.apply(vendor.npaExports, undefined, args);
|
|
3080
3370
|
} catch {}
|
|
3081
|
-
return
|
|
3371
|
+
return undefined;
|
|
3082
3372
|
}
|
|
3083
3373
|
|
|
3084
3374
|
function shadowNpmInstall(options) {
|
|
@@ -3594,7 +3884,7 @@ function toFilterConfig(obj) {
|
|
|
3594
3884
|
return normalized;
|
|
3595
3885
|
}
|
|
3596
3886
|
|
|
3597
|
-
const require$1 =
|
|
3887
|
+
const require$1 = require$$5.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('utils.js', document.baseURI).href)));
|
|
3598
3888
|
let _translations;
|
|
3599
3889
|
function getTranslations() {
|
|
3600
3890
|
if (_translations === undefined) {
|
|
@@ -3987,7 +4277,8 @@ async function getAlertsMapFromPurls(purls, options) {
|
|
|
3987
4277
|
throw new Error('Auth error: Run `socket login` first');
|
|
3988
4278
|
}
|
|
3989
4279
|
const sockSdk = sockSdkCResult.data;
|
|
3990
|
-
const
|
|
4280
|
+
const socketYmlResult = findSocketYmlSync();
|
|
4281
|
+
const socketYml = socketYmlResult.ok ? socketYmlResult.data.parsed : undefined;
|
|
3991
4282
|
const alertsMapOptions = {
|
|
3992
4283
|
consolidate: opts.consolidate,
|
|
3993
4284
|
filter: opts.filter,
|
|
@@ -4053,6 +4344,8 @@ exports.checkCommandInput = checkCommandInput;
|
|
|
4053
4344
|
exports.cmdFlagValueToArray = cmdFlagValueToArray;
|
|
4054
4345
|
exports.cmdFlagsToString = cmdFlagsToString;
|
|
4055
4346
|
exports.cmdPrefixMessage = cmdPrefixMessage;
|
|
4347
|
+
exports.convertCveToGhsa = convertCveToGhsa;
|
|
4348
|
+
exports.convertPurlToGhsas = convertPurlToGhsas;
|
|
4056
4349
|
exports.createEnum = createEnum;
|
|
4057
4350
|
exports.detectAndValidatePackageEnvironment = detectAndValidatePackageEnvironment;
|
|
4058
4351
|
exports.detectDefaultBranch = detectDefaultBranch;
|
|
@@ -4062,6 +4355,7 @@ exports.extractTier1ReachabilityScanId = extractTier1ReachabilityScanId;
|
|
|
4062
4355
|
exports.failMsgWithBadge = failMsgWithBadge;
|
|
4063
4356
|
exports.fetchGhsaDetails = fetchGhsaDetails;
|
|
4064
4357
|
exports.fetchOrganization = fetchOrganization;
|
|
4358
|
+
exports.filterFlags = filterFlags;
|
|
4065
4359
|
exports.findUp = findUp;
|
|
4066
4360
|
exports.getAlertsMapFromPurls = getAlertsMapFromPurls;
|
|
4067
4361
|
exports.getBaseBranch = getBaseBranch;
|
|
@@ -4138,5 +4432,5 @@ exports.toFilterConfig = toFilterConfig;
|
|
|
4138
4432
|
exports.updateConfigValue = updateConfigValue;
|
|
4139
4433
|
exports.walkNestedMap = walkNestedMap;
|
|
4140
4434
|
exports.writeSocketJson = writeSocketJson;
|
|
4141
|
-
//# debugId=
|
|
4435
|
+
//# debugId=5923006d-eb5f-4f79-acbc-223ba7f465ba
|
|
4142
4436
|
//# sourceMappingURL=utils.js.map
|