@socketsecurity/cli-with-sentry 1.0.65 → 1.0.66
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 +522 -345
- package/dist/cli.js.map +1 -1
- package/dist/constants.js +3 -3
- package/dist/constants.js.map +1 -1
- package/dist/shadow-npm-inject.js +6 -6
- package/dist/shadow-npm-inject.js.map +1 -1
- package/dist/types/commands/analytics/fetch-org-analytics.d.mts +6 -2
- package/dist/types/commands/analytics/fetch-org-analytics.d.mts.map +1 -1
- package/dist/types/commands/analytics/fetch-repo-analytics.d.mts +6 -2
- package/dist/types/commands/analytics/fetch-repo-analytics.d.mts.map +1 -1
- package/dist/types/commands/analytics/output-analytics.d.mts +4 -4
- package/dist/types/commands/analytics/output-analytics.d.mts.map +1 -1
- package/dist/types/commands/audit-log/fetch-audit-log.d.mts +10 -5
- package/dist/types/commands/audit-log/fetch-audit-log.d.mts.map +1 -1
- package/dist/types/commands/audit-log/handle-audit-log.d.mts +1 -1
- package/dist/types/commands/audit-log/handle-audit-log.d.mts.map +1 -1
- package/dist/types/commands/audit-log/output-audit-log.d.mts +6 -6
- package/dist/types/commands/audit-log/output-audit-log.d.mts.map +1 -1
- package/dist/types/commands/ci/fetch-default-org-slug.d.mts +1 -1
- package/dist/types/commands/ci/fetch-default-org-slug.d.mts.map +1 -1
- package/dist/types/commands/ci/handle-ci.d.mts +1 -1
- package/dist/types/commands/ci/handle-ci.d.mts.map +1 -1
- package/dist/types/commands/fix/cmd-fix.d.mts.map +1 -1
- package/dist/types/commands/fix/handle-fix.d.mts +2 -1
- package/dist/types/commands/fix/handle-fix.d.mts.map +1 -1
- package/dist/types/commands/login/attempt-login.d.mts.map +1 -1
- package/dist/types/commands/organization/fetch-dependencies.d.mts +8 -3
- package/dist/types/commands/organization/fetch-dependencies.d.mts.map +1 -1
- package/dist/types/commands/organization/fetch-license-policy.d.mts +6 -2
- package/dist/types/commands/organization/fetch-license-policy.d.mts.map +1 -1
- package/dist/types/commands/organization/fetch-organization-list.d.mts +6 -2
- package/dist/types/commands/organization/fetch-organization-list.d.mts.map +1 -1
- package/dist/types/commands/organization/fetch-quota.d.mts +6 -2
- package/dist/types/commands/organization/fetch-quota.d.mts.map +1 -1
- package/dist/types/commands/organization/fetch-security-policy.d.mts +6 -2
- package/dist/types/commands/organization/fetch-security-policy.d.mts.map +1 -1
- package/dist/types/commands/organization/output-dependencies.d.mts +2 -2
- package/dist/types/commands/organization/output-dependencies.d.mts.map +1 -1
- package/dist/types/commands/organization/output-license-policy.d.mts +2 -2
- package/dist/types/commands/organization/output-license-policy.d.mts.map +1 -1
- package/dist/types/commands/organization/output-organization-list.d.mts +2 -2
- package/dist/types/commands/organization/output-organization-list.d.mts.map +1 -1
- package/dist/types/commands/organization/output-quota.d.mts +2 -2
- package/dist/types/commands/organization/output-quota.d.mts.map +1 -1
- package/dist/types/commands/organization/output-security-policy.d.mts +2 -2
- package/dist/types/commands/organization/output-security-policy.d.mts.map +1 -1
- package/dist/types/commands/package/fetch-purls-shallow-score.d.mts +6 -2
- package/dist/types/commands/package/fetch-purls-shallow-score.d.mts.map +1 -1
- package/dist/types/commands/repository/fetch-create-repo.d.mts +11 -6
- package/dist/types/commands/repository/fetch-create-repo.d.mts.map +1 -1
- package/dist/types/commands/repository/fetch-delete-repo.d.mts +6 -2
- package/dist/types/commands/repository/fetch-delete-repo.d.mts.map +1 -1
- package/dist/types/commands/repository/fetch-list-all-repos.d.mts +8 -6
- package/dist/types/commands/repository/fetch-list-all-repos.d.mts.map +1 -1
- package/dist/types/commands/repository/fetch-list-repos.d.mts +9 -4
- package/dist/types/commands/repository/fetch-list-repos.d.mts.map +1 -1
- package/dist/types/commands/repository/fetch-update-repo.d.mts +11 -6
- package/dist/types/commands/repository/fetch-update-repo.d.mts.map +1 -1
- package/dist/types/commands/repository/fetch-view-repo.d.mts +6 -2
- package/dist/types/commands/repository/fetch-view-repo.d.mts.map +1 -1
- package/dist/types/commands/repository/handle-create-repo.d.mts +2 -2
- package/dist/types/commands/repository/handle-create-repo.d.mts.map +1 -1
- package/dist/types/commands/repository/handle-list-repos.d.mts +2 -2
- package/dist/types/commands/repository/handle-list-repos.d.mts.map +1 -1
- package/dist/types/commands/repository/handle-update-repo.d.mts +2 -2
- package/dist/types/commands/repository/handle-update-repo.d.mts.map +1 -1
- package/dist/types/commands/repository/output-create-repo.d.mts +2 -2
- package/dist/types/commands/repository/output-create-repo.d.mts.map +1 -1
- package/dist/types/commands/repository/output-delete-repo.d.mts +2 -2
- package/dist/types/commands/repository/output-delete-repo.d.mts.map +1 -1
- package/dist/types/commands/repository/output-list-repos.d.mts +2 -2
- package/dist/types/commands/repository/output-list-repos.d.mts.map +1 -1
- package/dist/types/commands/repository/output-update-repo.d.mts +2 -2
- package/dist/types/commands/repository/output-update-repo.d.mts.map +1 -1
- package/dist/types/commands/repository/output-view-repo.d.mts +2 -2
- package/dist/types/commands/repository/output-view-repo.d.mts.map +1 -1
- package/dist/types/commands/scan/create-scan-from-github.d.mts.map +1 -1
- package/dist/types/commands/scan/fetch-create-org-full-scan.d.mts +12 -3
- package/dist/types/commands/scan/fetch-create-org-full-scan.d.mts.map +1 -1
- package/dist/types/commands/scan/fetch-delete-org-full-scan.d.mts +6 -2
- package/dist/types/commands/scan/fetch-delete-org-full-scan.d.mts.map +1 -1
- package/dist/types/commands/scan/fetch-diff-scan.d.mts +2 -2
- package/dist/types/commands/scan/fetch-diff-scan.d.mts.map +1 -1
- package/dist/types/commands/scan/fetch-list-scans.d.mts +9 -4
- package/dist/types/commands/scan/fetch-list-scans.d.mts.map +1 -1
- package/dist/types/commands/scan/fetch-report-data.d.mts +8 -3
- package/dist/types/commands/scan/fetch-report-data.d.mts.map +1 -1
- package/dist/types/commands/scan/fetch-scan-metadata.d.mts +6 -2
- package/dist/types/commands/scan/fetch-scan-metadata.d.mts.map +1 -1
- package/dist/types/commands/scan/fetch-supported-scan-file-names.d.mts +6 -2
- package/dist/types/commands/scan/fetch-supported-scan-file-names.d.mts.map +1 -1
- package/dist/types/commands/scan/generate-report.d.mts +2 -2
- package/dist/types/commands/scan/generate-report.d.mts.map +1 -1
- package/dist/types/commands/scan/handle-create-new-scan.d.mts.map +1 -1
- package/dist/types/commands/scan/handle-list-scans.d.mts +2 -2
- package/dist/types/commands/scan/handle-list-scans.d.mts.map +1 -1
- package/dist/types/commands/scan/handle-scan-report.d.mts.map +1 -1
- package/dist/types/commands/scan/output-create-new-scan.d.mts +2 -2
- package/dist/types/commands/scan/output-create-new-scan.d.mts.map +1 -1
- package/dist/types/commands/scan/output-delete-scan.d.mts +2 -2
- package/dist/types/commands/scan/output-delete-scan.d.mts.map +1 -1
- package/dist/types/commands/scan/output-diff-scan.d.mts +2 -2
- package/dist/types/commands/scan/output-diff-scan.d.mts.map +1 -1
- package/dist/types/commands/scan/output-list-scans.d.mts +2 -2
- package/dist/types/commands/scan/output-list-scans.d.mts.map +1 -1
- package/dist/types/commands/scan/output-scan-metadata.d.mts +2 -2
- package/dist/types/commands/scan/output-scan-metadata.d.mts.map +1 -1
- package/dist/types/commands/scan/output-scan-report.d.mts +2 -2
- package/dist/types/commands/scan/output-scan-report.d.mts.map +1 -1
- package/dist/types/commands/scan/stream-scan.d.mts +6 -1
- package/dist/types/commands/scan/stream-scan.d.mts.map +1 -1
- package/dist/types/commands/scan/suggest-org-slug.d.mts.map +1 -1
- package/dist/types/commands/scan/suggest-repo-slug.d.mts +5 -1
- package/dist/types/commands/scan/suggest-repo-slug.d.mts.map +1 -1
- package/dist/types/utils/alert/severity.d.mts +2 -2
- package/dist/types/utils/alert/severity.d.mts.map +1 -1
- package/dist/types/utils/alerts-map.d.mts.map +1 -1
- package/dist/types/utils/api.d.mts +8 -3
- package/dist/types/utils/api.d.mts.map +1 -1
- package/dist/types/utils/coana.d.mts.map +1 -1
- package/dist/types/utils/glob.d.mts +4 -2
- package/dist/types/utils/glob.d.mts.map +1 -1
- package/dist/types/utils/path-resolve.d.mts +2 -2
- package/dist/types/utils/path-resolve.d.mts.map +1 -1
- package/dist/types/utils/sdk.d.mts +6 -1
- package/dist/types/utils/sdk.d.mts.map +1 -1
- package/dist/utils.js +208 -104
- package/dist/utils.js.map +1 -1
- package/dist/vendor.js +141 -61
- package/external/@socketsecurity/registry/external/@inquirer/select.js +14 -2
- package/external/@socketsecurity/registry/external/@npmcli/package-json/index.js +4 -4
- package/external/@socketsecurity/registry/external/libnpmpack.js +4 -4
- package/external/@socketsecurity/registry/external/npm-package-arg.js +4 -4
- package/external/@socketsecurity/registry/external/pacote.js +4 -4
- package/external/@socketsecurity/registry/external/validate-npm-package-name.js +4 -4
- package/external/@socketsecurity/registry/lib/regexps.js +1 -1
- package/external/@socketsecurity/registry/lib/spinner.js +15 -5
- package/package.json +12 -12
package/dist/utils.js
CHANGED
|
@@ -5,22 +5,22 @@ var logger = require('../external/@socketsecurity/registry/lib/logger');
|
|
|
5
5
|
var strings = require('../external/@socketsecurity/registry/lib/strings');
|
|
6
6
|
var debug = require('../external/@socketsecurity/registry/lib/debug');
|
|
7
7
|
var arrays = require('../external/@socketsecurity/registry/lib/arrays');
|
|
8
|
-
var
|
|
8
|
+
var require$$7 = require('../external/@socketsecurity/registry/lib/objects');
|
|
9
9
|
var path$1 = require('../external/@socketsecurity/registry/lib/path');
|
|
10
10
|
var sorts = require('../external/@socketsecurity/registry/lib/sorts');
|
|
11
11
|
var constants = require('./constants.js');
|
|
12
12
|
var path = require('node:path');
|
|
13
13
|
var regexps = require('../external/@socketsecurity/registry/lib/regexps');
|
|
14
14
|
var prompts = require('../external/@socketsecurity/registry/lib/prompts');
|
|
15
|
-
var promises = require('node:timers/promises');
|
|
16
15
|
var spawn = require('../external/@socketsecurity/registry/lib/spawn');
|
|
17
16
|
var fs = require('node:fs');
|
|
18
17
|
var fs$1 = require('../external/@socketsecurity/registry/lib/fs');
|
|
19
|
-
var require$$
|
|
18
|
+
var require$$8 = require('../external/@socketsecurity/registry/lib/promises');
|
|
20
19
|
var packages = require('../external/@socketsecurity/registry/lib/packages');
|
|
21
20
|
var registry = require('../external/@socketsecurity/registry');
|
|
22
21
|
var require$$5 = require('node:module');
|
|
23
22
|
var npm = require('../external/@socketsecurity/registry/lib/npm');
|
|
23
|
+
var promises = require('node:timers/promises');
|
|
24
24
|
|
|
25
25
|
const ignoredDirs = [
|
|
26
26
|
// Taken from ignore-by-default:
|
|
@@ -128,7 +128,11 @@ function workspacePatternToGlobPattern(workspace) {
|
|
|
128
128
|
// Things like "packages/a" or "packages/*"
|
|
129
129
|
return `${workspace}/package.json`;
|
|
130
130
|
}
|
|
131
|
-
|
|
131
|
+
function filterBySupportedScanFiles(filepaths, supportedFiles) {
|
|
132
|
+
const patterns = getSupportedFilePatterns(supportedFiles);
|
|
133
|
+
return filepaths.filter(p => vendor.micromatchExports.some(p, patterns));
|
|
134
|
+
}
|
|
135
|
+
function getSupportedFilePatterns(supportedFiles) {
|
|
132
136
|
const patterns = [];
|
|
133
137
|
for (const key of Object.keys(supportedFiles)) {
|
|
134
138
|
const supported = supportedFiles[key];
|
|
@@ -136,7 +140,7 @@ async function filterGlobResultToSupportedFiles(entries, supportedFiles) {
|
|
|
136
140
|
patterns.push(...Object.values(supported).map(p => `**/${p.pattern}`));
|
|
137
141
|
}
|
|
138
142
|
}
|
|
139
|
-
return
|
|
143
|
+
return patterns;
|
|
140
144
|
}
|
|
141
145
|
async function globWithGitIgnore(patterns, options) {
|
|
142
146
|
const {
|
|
@@ -147,15 +151,16 @@ async function globWithGitIgnore(patterns, options) {
|
|
|
147
151
|
__proto__: null,
|
|
148
152
|
...options
|
|
149
153
|
};
|
|
150
|
-
const projectIgnorePaths = socketConfig?.projectIgnorePaths;
|
|
151
154
|
const ignoreFiles = await vendor.distExports.glob(['**/.gitignore'], {
|
|
152
155
|
absolute: true,
|
|
153
156
|
cwd,
|
|
154
157
|
expandDirectories: true
|
|
155
158
|
});
|
|
159
|
+
const projectIgnorePaths = socketConfig?.projectIgnorePaths;
|
|
156
160
|
const ignores = [...ignoredDirPatterns, ...(Array.isArray(projectIgnorePaths) ? ignoreFileLinesToGlobPatterns(projectIgnorePaths, path.join(cwd, '.gitignore'), cwd) : []), ...(await Promise.all(ignoreFiles.map(async filepath => ignoreFileToGlobPatterns((await safeReadFile(filepath)) ?? '', filepath, cwd)))).flat()];
|
|
157
161
|
const hasNegatedPattern = ignores.some(p => p.charCodeAt(0) === 33 /*'!'*/);
|
|
158
162
|
const globOptions = {
|
|
163
|
+
__proto__: null,
|
|
159
164
|
absolute: true,
|
|
160
165
|
cwd,
|
|
161
166
|
dot: true,
|
|
@@ -167,14 +172,11 @@ async function globWithGitIgnore(patterns, options) {
|
|
|
167
172
|
if (!hasNegatedPattern) {
|
|
168
173
|
return result;
|
|
169
174
|
}
|
|
170
|
-
const {
|
|
171
|
-
absolute
|
|
172
|
-
} = globOptions;
|
|
173
175
|
|
|
174
176
|
// Note: the input files must be INSIDE the cwd. If you get strange looking
|
|
175
177
|
// relative path errors here, most likely your path is outside the given cwd.
|
|
176
|
-
const filtered = vendor.ignoreExports().add(ignores).filter(absolute ? result.map(p => path.relative(cwd, p)) : result);
|
|
177
|
-
return absolute ? filtered.map(p => path.resolve(cwd, p)) : filtered;
|
|
178
|
+
const filtered = vendor.ignoreExports().add(ignores).filter(globOptions.absolute ? result.map(p => path.relative(cwd, p)) : result);
|
|
179
|
+
return globOptions.absolute ? filtered.map(p => path.resolve(cwd, p)) : filtered;
|
|
178
180
|
}
|
|
179
181
|
async function globNodeModules(cwd = process.cwd()) {
|
|
180
182
|
return await vendor.distExports.glob('**/node_modules', {
|
|
@@ -192,6 +194,10 @@ async function globWorkspace(agent, cwd = process.cwd()) {
|
|
|
192
194
|
ignore: ['**/node_modules/**', '**/bower_components/**']
|
|
193
195
|
}) : [];
|
|
194
196
|
}
|
|
197
|
+
function isReportSupportedFile(filepath, supportedFiles) {
|
|
198
|
+
const patterns = getSupportedFilePatterns(supportedFiles);
|
|
199
|
+
return vendor.micromatchExports.some(filepath, patterns);
|
|
200
|
+
}
|
|
195
201
|
function pathsToGlobPatterns(paths) {
|
|
196
202
|
// TODO: Does not support `~/` paths.
|
|
197
203
|
return paths.map(p => p === '.' || p === './' ? '**/*' : p);
|
|
@@ -199,7 +205,7 @@ function pathsToGlobPatterns(paths) {
|
|
|
199
205
|
|
|
200
206
|
async function removeNodeModules(cwd = process.cwd()) {
|
|
201
207
|
const nodeModulesPaths = await globNodeModules(cwd);
|
|
202
|
-
await require$$
|
|
208
|
+
await require$$8.pEach(nodeModulesPaths, 3, p => fs$1.remove(p, {
|
|
203
209
|
force: true,
|
|
204
210
|
recursive: true
|
|
205
211
|
}), {
|
|
@@ -597,7 +603,14 @@ function getPublicToken() {
|
|
|
597
603
|
// Lazily access constants.SOCKET_PUBLIC_API_TOKEN.
|
|
598
604
|
constants.SOCKET_PUBLIC_API_TOKEN;
|
|
599
605
|
}
|
|
600
|
-
async function setupSdk(
|
|
606
|
+
async function setupSdk(options) {
|
|
607
|
+
const opts = {
|
|
608
|
+
__proto__: null,
|
|
609
|
+
...options
|
|
610
|
+
};
|
|
611
|
+
let {
|
|
612
|
+
apiToken = getDefaultToken()
|
|
613
|
+
} = opts;
|
|
601
614
|
if (typeof apiToken !== 'string' && vendor.isInteractiveExports()) {
|
|
602
615
|
apiToken = await prompts.password({
|
|
603
616
|
message: 'Enter your Socket.dev API key (not saved, use socket login to persist)'
|
|
@@ -611,15 +624,21 @@ async function setupSdk(apiToken = getDefaultToken(), apiBaseUrl = getDefaultApi
|
|
|
611
624
|
cause: 'You need to provide an API Token. Run `socket login` first.'
|
|
612
625
|
};
|
|
613
626
|
}
|
|
614
|
-
|
|
615
|
-
|
|
627
|
+
let {
|
|
628
|
+
apiProxy
|
|
629
|
+
} = opts;
|
|
630
|
+
if (!isUrl(apiProxy)) {
|
|
631
|
+
apiProxy = getDefaultProxyUrl();
|
|
616
632
|
}
|
|
617
|
-
const
|
|
633
|
+
const {
|
|
634
|
+
apiBaseUrl = getDefaultApiBaseUrl$1()
|
|
635
|
+
} = opts;
|
|
636
|
+
const ProxyAgent = apiProxy?.startsWith('http:') ? vendor.HttpProxyAgent : vendor.HttpsProxyAgent;
|
|
618
637
|
return {
|
|
619
638
|
ok: true,
|
|
620
639
|
data: new vendor.distExports$2.SocketSdk(apiToken, {
|
|
621
|
-
agent:
|
|
622
|
-
proxy
|
|
640
|
+
agent: apiProxy ? new ProxyAgent({
|
|
641
|
+
proxy: apiProxy
|
|
623
642
|
}) : undefined,
|
|
624
643
|
baseUrl: apiBaseUrl,
|
|
625
644
|
userAgent: vendor.distExports$2.createUserAgentFromPkgJson({
|
|
@@ -634,59 +653,79 @@ async function setupSdk(apiToken = getDefaultToken(), apiBaseUrl = getDefaultApi
|
|
|
634
653
|
};
|
|
635
654
|
}
|
|
636
655
|
|
|
637
|
-
|
|
638
|
-
|
|
656
|
+
const NO_ERROR_MESSAGE = 'No error message returned';
|
|
657
|
+
async function handleApiCall(value, options) {
|
|
639
658
|
const {
|
|
659
|
+
desc,
|
|
640
660
|
spinner
|
|
641
|
-
} =
|
|
642
|
-
|
|
643
|
-
|
|
661
|
+
} = {
|
|
662
|
+
__proto__: null,
|
|
663
|
+
...options
|
|
664
|
+
};
|
|
665
|
+
if (desc) {
|
|
666
|
+
spinner?.start(`Requesting ${desc} from API...`);
|
|
667
|
+
} else {
|
|
668
|
+
spinner?.start();
|
|
669
|
+
}
|
|
670
|
+
let sdkResult;
|
|
644
671
|
try {
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
672
|
+
sdkResult = await value;
|
|
673
|
+
if (desc) {
|
|
674
|
+
// TODO: info, not success (looks weird when response is non-200)
|
|
675
|
+
spinner?.successAndStop(`Received API response (after requesting ${desc}).`);
|
|
676
|
+
} else {
|
|
677
|
+
spinner?.stop();
|
|
678
|
+
}
|
|
649
679
|
} catch (e) {
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
680
|
+
if (desc) {
|
|
681
|
+
spinner?.failAndStop(`An error was thrown while requesting ${desc}`);
|
|
682
|
+
debug.debugFn('error', `caught: ${desc} error`);
|
|
683
|
+
} else {
|
|
684
|
+
spinner?.stop();
|
|
685
|
+
debug.debugFn('error', `caught: error`);
|
|
686
|
+
}
|
|
654
687
|
debug.debugDir('inspect', {
|
|
655
688
|
error: e
|
|
656
689
|
});
|
|
657
690
|
return {
|
|
658
691
|
ok: false,
|
|
659
692
|
message: 'Socket API returned an error',
|
|
660
|
-
cause:
|
|
693
|
+
cause: vendor.messageWithCauses(e)
|
|
661
694
|
};
|
|
662
695
|
} finally {
|
|
663
|
-
spinner
|
|
696
|
+
spinner?.stop();
|
|
664
697
|
}
|
|
665
698
|
|
|
666
|
-
// Note: TS can't narrow down the type of result due to generics
|
|
667
|
-
if (
|
|
668
|
-
const
|
|
669
|
-
const message = `${
|
|
699
|
+
// Note: TS can't narrow down the type of result due to generics.
|
|
700
|
+
if (sdkResult.success === false) {
|
|
701
|
+
const errorResult = sdkResult;
|
|
702
|
+
const message = `${errorResult.error || NO_ERROR_MESSAGE}`;
|
|
670
703
|
const {
|
|
671
704
|
cause: reason
|
|
672
|
-
} =
|
|
673
|
-
|
|
705
|
+
} = errorResult;
|
|
706
|
+
if (desc) {
|
|
707
|
+
debug.debugFn('error', `fail: ${desc} bad response`);
|
|
708
|
+
} else {
|
|
709
|
+
debug.debugFn('error', 'fail: bad response');
|
|
710
|
+
}
|
|
674
711
|
debug.debugDir('inspect', {
|
|
675
|
-
|
|
712
|
+
sdkResult
|
|
676
713
|
});
|
|
677
714
|
return {
|
|
678
715
|
ok: false,
|
|
679
716
|
message: 'Socket API returned an error',
|
|
680
717
|
cause: `${message}${reason ? ` ( Reason: ${reason} )` : ''}`,
|
|
681
718
|
data: {
|
|
682
|
-
code:
|
|
719
|
+
code: sdkResult.status
|
|
683
720
|
}
|
|
684
721
|
};
|
|
685
722
|
} else {
|
|
686
|
-
const
|
|
723
|
+
const {
|
|
724
|
+
data
|
|
725
|
+
} = sdkResult;
|
|
687
726
|
return {
|
|
688
727
|
ok: true,
|
|
689
|
-
data
|
|
728
|
+
data
|
|
690
729
|
};
|
|
691
730
|
}
|
|
692
731
|
}
|
|
@@ -695,8 +734,8 @@ async function handleApiCallNoSpinner(value, description) {
|
|
|
695
734
|
try {
|
|
696
735
|
result = await value;
|
|
697
736
|
} catch (e) {
|
|
698
|
-
const message = `${e ||
|
|
699
|
-
const reason = `${e ||
|
|
737
|
+
const message = `${e || NO_ERROR_MESSAGE}`;
|
|
738
|
+
const reason = `${e || NO_ERROR_MESSAGE}`;
|
|
700
739
|
debug.debugFn('error', `caught: ${description} error`);
|
|
701
740
|
debug.debugDir('inspect', {
|
|
702
741
|
error: e
|
|
@@ -711,7 +750,7 @@ async function handleApiCallNoSpinner(value, description) {
|
|
|
711
750
|
// Note: TS can't narrow down the type of result due to generics
|
|
712
751
|
if (result.success === false) {
|
|
713
752
|
const error = result;
|
|
714
|
-
const message = `${error.error ||
|
|
753
|
+
const message = `${error.error || NO_ERROR_MESSAGE}`;
|
|
715
754
|
debug.debugFn('error', `fail: ${description} bad response`);
|
|
716
755
|
debug.debugDir('inspect', {
|
|
717
756
|
error
|
|
@@ -1120,7 +1159,7 @@ function getHelpListOutput(list, options) {
|
|
|
1120
1159
|
if (entry && 'hidden' in entry && entry?.hidden) {
|
|
1121
1160
|
continue;
|
|
1122
1161
|
}
|
|
1123
|
-
const description = (
|
|
1162
|
+
const description = (require$$7.isObject(entry) ? entry.description : entry) || '';
|
|
1124
1163
|
result += ''.padEnd(indent) + (keyPrefix + name).padEnd(padName) + description + '\n';
|
|
1125
1164
|
}
|
|
1126
1165
|
return result.trim() || '(none)';
|
|
@@ -1277,10 +1316,10 @@ async function meowWithSubcommands(subcommands, options) {
|
|
|
1277
1316
|
function formatCommandsForHelp(isRootCommand) {
|
|
1278
1317
|
if (!isRootCommand) {
|
|
1279
1318
|
return getHelpListOutput({
|
|
1280
|
-
...
|
|
1319
|
+
...require$$7.toSortedObject(Object.fromEntries(Object.entries(subcommands).filter(({
|
|
1281
1320
|
1: subcommand
|
|
1282
1321
|
}) => !subcommand.hidden))),
|
|
1283
|
-
...
|
|
1322
|
+
...require$$7.toSortedObject(Object.fromEntries(Object.entries(aliases).filter(({
|
|
1284
1323
|
1: alias
|
|
1285
1324
|
}) => {
|
|
1286
1325
|
const {
|
|
@@ -1525,41 +1564,54 @@ function msAtHome(isoTimeStamp) {
|
|
|
1525
1564
|
}
|
|
1526
1565
|
}
|
|
1527
1566
|
|
|
1528
|
-
async function
|
|
1529
|
-
const
|
|
1567
|
+
async function fetchOrganization(options) {
|
|
1568
|
+
const {
|
|
1569
|
+
sdkOptions
|
|
1570
|
+
} = {
|
|
1571
|
+
__proto__: null,
|
|
1572
|
+
...options
|
|
1573
|
+
};
|
|
1574
|
+
const sockSdkCResult = await setupSdk(sdkOptions);
|
|
1530
1575
|
if (!sockSdkCResult.ok) {
|
|
1531
|
-
return;
|
|
1576
|
+
return sockSdkCResult;
|
|
1532
1577
|
}
|
|
1533
1578
|
const sockSdk = sockSdkCResult.data;
|
|
1534
|
-
|
|
1579
|
+
return await handleApiCall(sockSdk.getOrganizations(), {
|
|
1580
|
+
desc: 'organization list'
|
|
1581
|
+
});
|
|
1582
|
+
}
|
|
1583
|
+
|
|
1584
|
+
async function suggestOrgSlug() {
|
|
1585
|
+
const orgsCResult = await fetchOrganization();
|
|
1586
|
+
if (!orgsCResult.ok) {
|
|
1587
|
+
logger.logger.fail('Failed to lookup organization list from API, unable to suggest');
|
|
1588
|
+
return undefined;
|
|
1589
|
+
}
|
|
1535
1590
|
|
|
1536
1591
|
// Ignore a failed request here. It was not the primary goal of
|
|
1537
1592
|
// running this command and reporting it only leads to end-user confusion.
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
return proceed;
|
|
1559
|
-
}
|
|
1560
|
-
} else {
|
|
1561
|
-
logger.logger.fail('Failed to lookup organization list from API, unable to suggest');
|
|
1593
|
+
const {
|
|
1594
|
+
organizations
|
|
1595
|
+
} = orgsCResult.data;
|
|
1596
|
+
const proceed = await prompts.select({
|
|
1597
|
+
message: 'Missing org name; do you want to use any of these orgs for this scan?',
|
|
1598
|
+
choices: [...Object.values(organizations).map(o => {
|
|
1599
|
+
const name = o.name ?? o.slug;
|
|
1600
|
+
return {
|
|
1601
|
+
name: `Yes [${name}]`,
|
|
1602
|
+
value: name,
|
|
1603
|
+
description: `Use "${name}" as the organization`
|
|
1604
|
+
};
|
|
1605
|
+
}), {
|
|
1606
|
+
name: 'No',
|
|
1607
|
+
value: '',
|
|
1608
|
+
description: 'Do not use any of these organizations (will end in a no-op)'
|
|
1609
|
+
}]
|
|
1610
|
+
});
|
|
1611
|
+
if (proceed) {
|
|
1612
|
+
return proceed;
|
|
1562
1613
|
}
|
|
1614
|
+
return undefined;
|
|
1563
1615
|
}
|
|
1564
1616
|
|
|
1565
1617
|
async function suggestToPersistOrgSlug(orgSlug) {
|
|
@@ -1637,6 +1689,47 @@ async function determineOrgSlug(orgFlag, interactive, dryRun) {
|
|
|
1637
1689
|
return [orgSlug, defaultOrgSlug];
|
|
1638
1690
|
}
|
|
1639
1691
|
|
|
1692
|
+
// Use the config defaultOrg when set, otherwise discover from remote.
|
|
1693
|
+
async function getDefaultOrgSlug() {
|
|
1694
|
+
const defaultOrgResult = getConfigValueOrUndef('defaultOrg');
|
|
1695
|
+
if (defaultOrgResult) {
|
|
1696
|
+
debug.debugFn('notice', 'use: default org', defaultOrgResult);
|
|
1697
|
+
return {
|
|
1698
|
+
ok: true,
|
|
1699
|
+
data: defaultOrgResult
|
|
1700
|
+
};
|
|
1701
|
+
}
|
|
1702
|
+
const orgsCResult = await fetchOrganization();
|
|
1703
|
+
if (!orgsCResult.ok) {
|
|
1704
|
+
return orgsCResult;
|
|
1705
|
+
}
|
|
1706
|
+
const {
|
|
1707
|
+
organizations
|
|
1708
|
+
} = orgsCResult.data;
|
|
1709
|
+
const keys = Object.keys(organizations);
|
|
1710
|
+
if (!keys.length) {
|
|
1711
|
+
return {
|
|
1712
|
+
ok: false,
|
|
1713
|
+
message: 'Failed to establish identity',
|
|
1714
|
+
data: `API did not return any organization associated with the current API token. Unable to continue.`
|
|
1715
|
+
};
|
|
1716
|
+
}
|
|
1717
|
+
const slug = organizations[keys[0]]?.name ?? undefined;
|
|
1718
|
+
if (!slug) {
|
|
1719
|
+
return {
|
|
1720
|
+
ok: false,
|
|
1721
|
+
message: 'Failed to establish identity',
|
|
1722
|
+
data: `Was unable to determine the default organization for the current API token. Unable to continue.`
|
|
1723
|
+
};
|
|
1724
|
+
}
|
|
1725
|
+
debug.debugFn('notice', 'resolve: org', slug);
|
|
1726
|
+
return {
|
|
1727
|
+
ok: true,
|
|
1728
|
+
message: 'Retrieved default org from server',
|
|
1729
|
+
data: slug
|
|
1730
|
+
};
|
|
1731
|
+
}
|
|
1732
|
+
|
|
1640
1733
|
async function getBaseBranch(cwd = process.cwd()) {
|
|
1641
1734
|
// Lazily access constants.ENV properties.
|
|
1642
1735
|
const {
|
|
@@ -2042,16 +2135,15 @@ function* walkNestedMap(map, keys = []) {
|
|
|
2042
2135
|
}
|
|
2043
2136
|
}
|
|
2044
2137
|
|
|
2045
|
-
const {
|
|
2046
|
-
NODE_MODULES: NODE_MODULES$1,
|
|
2047
|
-
NPM: NPM$4,
|
|
2048
|
-
shadowBinPath
|
|
2049
|
-
} = constants;
|
|
2050
2138
|
function findBinPathDetailsSync(binName) {
|
|
2051
2139
|
const binPaths = vendor.libExports$1.sync(binName, {
|
|
2052
2140
|
all: true,
|
|
2053
2141
|
nothrow: true
|
|
2054
2142
|
}) ?? [];
|
|
2143
|
+
// Lazily access constants.shadowBinPath.
|
|
2144
|
+
const {
|
|
2145
|
+
shadowBinPath
|
|
2146
|
+
} = constants;
|
|
2055
2147
|
let shadowIndex = -1;
|
|
2056
2148
|
let theBinPath;
|
|
2057
2149
|
for (let i = 0, {
|
|
@@ -2079,7 +2171,7 @@ function findNpmPathSync(npmBinPath) {
|
|
|
2079
2171
|
} = constants;
|
|
2080
2172
|
let thePath = npmBinPath;
|
|
2081
2173
|
while (true) {
|
|
2082
|
-
const libNmNpmPath = path.join(thePath, 'lib'
|
|
2174
|
+
const libNmNpmPath = path.join(thePath, 'lib/node_modules/npm');
|
|
2083
2175
|
// mise puts its npm bin in a path like:
|
|
2084
2176
|
// /Users/SomeUsername/.local/share/mise/installs/node/vX.X.X/bin/npm.
|
|
2085
2177
|
// HOWEVER, the location of the npm install is:
|
|
@@ -2089,9 +2181,9 @@ function findNpmPathSync(npmBinPath) {
|
|
|
2089
2181
|
// will throw an ENOTDIR error for paths like ./a-file-that-exists/a-directory-that-does-not.
|
|
2090
2182
|
// See https://github.com/nodejs/node/issues/56993.
|
|
2091
2183
|
fs.existsSync(libNmNpmPath) && safeStatsSync(libNmNpmPath)?.isDirectory()) {
|
|
2092
|
-
thePath = path.join(libNmNpmPath,
|
|
2184
|
+
thePath = path.join(libNmNpmPath, 'npm');
|
|
2093
2185
|
}
|
|
2094
|
-
const nmPath = path.join(thePath,
|
|
2186
|
+
const nmPath = path.join(thePath, 'node_modules');
|
|
2095
2187
|
if (
|
|
2096
2188
|
// npm bin paths may look like:
|
|
2097
2189
|
// /usr/local/share/npm/bin/npm
|
|
@@ -2105,9 +2197,9 @@ function findNpmPathSync(npmBinPath) {
|
|
|
2105
2197
|
// C:\Program Files\nodejs\node_modules
|
|
2106
2198
|
fs.existsSync(nmPath) && safeStatsSync(nmPath)?.isDirectory() && (
|
|
2107
2199
|
// Optimistically look for the default location.
|
|
2108
|
-
path.basename(thePath) ===
|
|
2200
|
+
path.basename(thePath) === 'npm' ||
|
|
2109
2201
|
// Chocolatey installs npm bins in the same directory as node bins.
|
|
2110
|
-
WIN32 && fs.existsSync(path.join(thePath,
|
|
2202
|
+
WIN32 && fs.existsSync(path.join(thePath, 'npm.cmd')))) {
|
|
2111
2203
|
return thePath;
|
|
2112
2204
|
}
|
|
2113
2205
|
const parent = path.dirname(thePath);
|
|
@@ -2125,11 +2217,11 @@ async function getPackageFilesForScan(inputPaths, supportedFiles, options) {
|
|
|
2125
2217
|
__proto__: null,
|
|
2126
2218
|
...options
|
|
2127
2219
|
};
|
|
2128
|
-
const
|
|
2220
|
+
const filepaths = await globWithGitIgnore(pathsToGlobPatterns(inputPaths), {
|
|
2129
2221
|
cwd,
|
|
2130
2222
|
socketConfig
|
|
2131
2223
|
});
|
|
2132
|
-
return
|
|
2224
|
+
return filterBySupportedScanFiles(filepaths, supportedFiles);
|
|
2133
2225
|
}
|
|
2134
2226
|
|
|
2135
2227
|
async function readOrDefaultSocketJson(cwd) {
|
|
@@ -2566,7 +2658,7 @@ async function addArtifactToAlertsMap(artifact, alertsByPurl, options) {
|
|
|
2566
2658
|
const fixableCve = fixType === ALERT_FIX_TYPE.cve;
|
|
2567
2659
|
const fixableUpgrade = fixType === ALERT_FIX_TYPE.upgrade;
|
|
2568
2660
|
const fixable = fixableCve || fixableUpgrade;
|
|
2569
|
-
const upgradable = fixableUpgrade && !
|
|
2661
|
+
const upgradable = fixableUpgrade && !require$$7.hasOwn(overrides, name);
|
|
2570
2662
|
if (include.blocked && blocked || include.critical && critical || include.cve && cve || include.unfixable && !fixable || include.upgradable && upgradable) {
|
|
2571
2663
|
sockPkgAlerts.push({
|
|
2572
2664
|
name,
|
|
@@ -2931,7 +3023,7 @@ function parsePnpmLockfile(lockfileContent) {
|
|
|
2931
3023
|
result = vendor.jsYaml.load(strings.stripBom(lockfileContent));
|
|
2932
3024
|
} catch {}
|
|
2933
3025
|
}
|
|
2934
|
-
return
|
|
3026
|
+
return require$$7.isObjectObject(result) ? result : null;
|
|
2935
3027
|
}
|
|
2936
3028
|
function parsePnpmLockfileVersion(version) {
|
|
2937
3029
|
try {
|
|
@@ -2992,7 +3084,9 @@ async function getAlertsMapFromPurls(purls, options) {
|
|
|
2992
3084
|
} = opts;
|
|
2993
3085
|
const getText = () => `Looking up data for ${remaining} packages`;
|
|
2994
3086
|
spinner?.start(getText());
|
|
2995
|
-
const sockSdkCResult = await setupSdk(
|
|
3087
|
+
const sockSdkCResult = await setupSdk({
|
|
3088
|
+
apiToken: getPublicToken()
|
|
3089
|
+
});
|
|
2996
3090
|
if (!sockSdkCResult.ok) {
|
|
2997
3091
|
spinner?.stop();
|
|
2998
3092
|
throw new Error('Auth error: Try to run `socket login` first');
|
|
@@ -3005,18 +3099,20 @@ async function getAlertsMapFromPurls(purls, options) {
|
|
|
3005
3099
|
spinner
|
|
3006
3100
|
};
|
|
3007
3101
|
for await (const batchResult of sockSdk.batchPackageStream({
|
|
3008
|
-
alerts: 'true',
|
|
3009
|
-
compact: 'true',
|
|
3010
|
-
...(opts.include.actions ? {
|
|
3011
|
-
actions: opts.include.actions.join(',')
|
|
3012
|
-
} : {}),
|
|
3013
|
-
...(opts.include.unfixable ? {} : {
|
|
3014
|
-
fixable: 'true'
|
|
3015
|
-
})
|
|
3016
|
-
}, {
|
|
3017
3102
|
components: uniqPurls.map(purl => ({
|
|
3018
3103
|
purl
|
|
3019
3104
|
}))
|
|
3105
|
+
}, {
|
|
3106
|
+
queryParams: {
|
|
3107
|
+
alerts: 'true',
|
|
3108
|
+
compact: 'true',
|
|
3109
|
+
...(opts.include.actions ? {
|
|
3110
|
+
actions: opts.include.actions.join(',')
|
|
3111
|
+
} : {}),
|
|
3112
|
+
...(opts.include.unfixable ? {} : {
|
|
3113
|
+
fixable: 'true'
|
|
3114
|
+
})
|
|
3115
|
+
}
|
|
3020
3116
|
})) {
|
|
3021
3117
|
if (batchResult.success) {
|
|
3022
3118
|
await addArtifactToAlertsMap(batchResult.data, alertsByPurl, alertsMapOptions);
|
|
@@ -3101,7 +3197,7 @@ function safeNpmInstall(options) {
|
|
|
3101
3197
|
...options
|
|
3102
3198
|
};
|
|
3103
3199
|
let stdio = spawnOptions.stdio;
|
|
3104
|
-
const useIpc =
|
|
3200
|
+
const useIpc = require$$7.isObject(ipc);
|
|
3105
3201
|
// Include 'ipc' in the spawnOptions.stdio when an options.ipc object is provided.
|
|
3106
3202
|
// See https://github.com/nodejs/node/blob/v23.6.0/lib/child_process.js#L161-L166
|
|
3107
3203
|
// and https://github.com/nodejs/node/blob/v23.6.0/lib/internal/child_process.js#L238.
|
|
@@ -3260,6 +3356,9 @@ async function spawnCoana(args, options, extra) {
|
|
|
3260
3356
|
__proto__: null,
|
|
3261
3357
|
...options
|
|
3262
3358
|
};
|
|
3359
|
+
const orgSlugCResult = await getDefaultOrgSlug();
|
|
3360
|
+
const SOCKET_CLI_API_TOKEN = getDefaultToken();
|
|
3361
|
+
const SOCKET_ORG_SLUG = orgSlugCResult.ok ? orgSlugCResult.data : undefined;
|
|
3263
3362
|
try {
|
|
3264
3363
|
const output = await spawn.spawn(constants.execPath, [
|
|
3265
3364
|
// Lazily access constants.nodeNoWarningsFlags.
|
|
@@ -3271,7 +3370,9 @@ async function spawnCoana(args, options, extra) {
|
|
|
3271
3370
|
...process.env,
|
|
3272
3371
|
// Lazily access constants.processEnv.
|
|
3273
3372
|
...constants.processEnv,
|
|
3274
|
-
|
|
3373
|
+
RUN_WITHOUT_DOCKER: 'true',
|
|
3374
|
+
SOCKET_CLI_API_TOKEN,
|
|
3375
|
+
SOCKET_ORG_SLUG,
|
|
3275
3376
|
...spawnEnv
|
|
3276
3377
|
}
|
|
3277
3378
|
}, extra);
|
|
@@ -3705,6 +3806,7 @@ exports.detectAndValidatePackageEnvironment = detectAndValidatePackageEnvironmen
|
|
|
3705
3806
|
exports.determineOrgSlug = determineOrgSlug;
|
|
3706
3807
|
exports.extractOverridesFromPnpmLockSrc = extractOverridesFromPnpmLockSrc;
|
|
3707
3808
|
exports.failMsgWithBadge = failMsgWithBadge;
|
|
3809
|
+
exports.fetchOrganization = fetchOrganization;
|
|
3708
3810
|
exports.getAlertsMapFromPnpmLockfile = getAlertsMapFromPnpmLockfile;
|
|
3709
3811
|
exports.getAlertsMapFromPurls = getAlertsMapFromPurls;
|
|
3710
3812
|
exports.getBaseBranch = getBaseBranch;
|
|
@@ -3712,6 +3814,7 @@ exports.getBashrcDetails = getBashrcDetails;
|
|
|
3712
3814
|
exports.getConfigValue = getConfigValue;
|
|
3713
3815
|
exports.getConfigValueOrUndef = getConfigValueOrUndef;
|
|
3714
3816
|
exports.getCveInfoFromAlertsMap = getCveInfoFromAlertsMap;
|
|
3817
|
+
exports.getDefaultOrgSlug = getDefaultOrgSlug;
|
|
3715
3818
|
exports.getFlagListOutput = getFlagListOutput;
|
|
3716
3819
|
exports.getMajor = getMajor;
|
|
3717
3820
|
exports.getMinVersion = getMinVersion;
|
|
@@ -3748,6 +3851,7 @@ exports.isHelpFlag = isHelpFlag;
|
|
|
3748
3851
|
exports.isNpmBinPathShadowed = isNpmBinPathShadowed;
|
|
3749
3852
|
exports.isNpxBinPathShadowed = isNpxBinPathShadowed;
|
|
3750
3853
|
exports.isReadOnlyConfig = isReadOnlyConfig;
|
|
3854
|
+
exports.isReportSupportedFile = isReportSupportedFile;
|
|
3751
3855
|
exports.isSensitiveConfigKey = isSensitiveConfigKey;
|
|
3752
3856
|
exports.isSupportedConfigKey = isSupportedConfigKey;
|
|
3753
3857
|
exports.logAlertsMap = logAlertsMap;
|
|
@@ -3780,5 +3884,5 @@ exports.tildify = tildify;
|
|
|
3780
3884
|
exports.updateConfigValue = updateConfigValue;
|
|
3781
3885
|
exports.walkNestedMap = walkNestedMap;
|
|
3782
3886
|
exports.writeSocketJson = writeSocketJson;
|
|
3783
|
-
//# debugId=
|
|
3887
|
+
//# debugId=eeb540f1-2cc9-44c6-8101-3926e319a1db
|
|
3784
3888
|
//# sourceMappingURL=utils.js.map
|