@socketsecurity/cli-with-sentry 1.0.64 → 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 +704 -521
- package/dist/cli.js.map +1 -1
- package/dist/constants.js +18 -11
- package/dist/constants.js.map +1 -1
- package/dist/instrument-with-sentry.js +4 -9
- package/dist/instrument-with-sentry.js.map +1 -1
- package/dist/shadow-npm-inject.js +13 -16
- 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/config/cmd-config-auto.d.mts.map +1 -1
- package/dist/types/commands/config/cmd-config-get.d.mts.map +1 -1
- package/dist/types/commands/config/cmd-config-set.d.mts.map +1 -1
- package/dist/types/commands/config/cmd-config-unset.d.mts.map +1 -1
- package/dist/types/commands/config/discover-config-value.d.mts.map +1 -1
- package/dist/types/commands/config/output-config-list.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/manifest/convert-conda-to-requirements.d.mts +1 -1
- package/dist/types/commands/manifest/convert-conda-to-requirements.d.mts.map +1 -1
- package/dist/types/commands/manifest/output-requirements.d.mts +1 -1
- package/dist/types/commands/manifest/output-requirements.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/constants.d.mts.map +1 -1
- package/dist/types/shadow/npm/arborist-helpers.d.mts +1 -1
- package/dist/types/shadow/npm/arborist-helpers.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 +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/config.d.mts +4 -2
- package/dist/types/utils/config.d.mts.map +1 -1
- package/dist/types/utils/fs.d.mts +3 -1
- package/dist/types/utils/fs.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 +262 -145
- package/dist/utils.js.map +1 -1
- package/dist/vendor.js +143 -64
- package/external/@socketsecurity/registry/extensions.json +2 -2
- 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/@socketregistry/yocto-spinner.js +20 -11
- 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 +27 -23
- package/external/@socketsecurity/registry/manifest.json +7 -7
- package/package.json +14 -14
package/dist/utils.js
CHANGED
|
@@ -5,28 +5,23 @@ 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
|
-
var
|
|
17
|
+
var fs$1 = require('../external/@socketsecurity/registry/lib/fs');
|
|
18
|
+
var require$$8 = require('../external/@socketsecurity/registry/lib/promises');
|
|
19
19
|
var packages = require('../external/@socketsecurity/registry/lib/packages');
|
|
20
|
+
var registry = require('../external/@socketsecurity/registry');
|
|
20
21
|
var require$$5 = require('node:module');
|
|
21
22
|
var npm = require('../external/@socketsecurity/registry/lib/npm');
|
|
22
|
-
var
|
|
23
|
-
var require$$7 = require('../external/@socketsecurity/registry/lib/promises');
|
|
23
|
+
var promises = require('node:timers/promises');
|
|
24
24
|
|
|
25
|
-
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
26
|
-
const {
|
|
27
|
-
PNPM: PNPM$2
|
|
28
|
-
} = constants;
|
|
29
|
-
const PNPM_WORKSPACE = `${PNPM$2}-workspace`;
|
|
30
25
|
const ignoredDirs = [
|
|
31
26
|
// Taken from ignore-by-default:
|
|
32
27
|
// https://github.com/novemberborn/ignore-by-default/blob/v2.1.0/index.js
|
|
@@ -52,8 +47,8 @@ const ignoredDirs = [
|
|
|
52
47
|
const ignoredDirPatterns = ignoredDirs.map(i => `**/${i}`);
|
|
53
48
|
async function getWorkspaceGlobs(agent, cwd = process.cwd()) {
|
|
54
49
|
let workspacePatterns;
|
|
55
|
-
if (agent ===
|
|
56
|
-
for (const workspacePath of [path.join(cwd,
|
|
50
|
+
if (agent === 'pnpm') {
|
|
51
|
+
for (const workspacePath of [path.join(cwd, 'pnpm-workspace.yaml'), path.join(cwd, 'pnpm-workspace.yml')]) {
|
|
57
52
|
// eslint-disable-next-line no-await-in-loop
|
|
58
53
|
const yml = await safeReadFile(workspacePath);
|
|
59
54
|
if (yml) {
|
|
@@ -133,7 +128,11 @@ function workspacePatternToGlobPattern(workspace) {
|
|
|
133
128
|
// Things like "packages/a" or "packages/*"
|
|
134
129
|
return `${workspace}/package.json`;
|
|
135
130
|
}
|
|
136
|
-
|
|
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) {
|
|
137
136
|
const patterns = [];
|
|
138
137
|
for (const key of Object.keys(supportedFiles)) {
|
|
139
138
|
const supported = supportedFiles[key];
|
|
@@ -141,7 +140,7 @@ async function filterGlobResultToSupportedFiles(entries, supportedFiles) {
|
|
|
141
140
|
patterns.push(...Object.values(supported).map(p => `**/${p.pattern}`));
|
|
142
141
|
}
|
|
143
142
|
}
|
|
144
|
-
return
|
|
143
|
+
return patterns;
|
|
145
144
|
}
|
|
146
145
|
async function globWithGitIgnore(patterns, options) {
|
|
147
146
|
const {
|
|
@@ -152,15 +151,16 @@ async function globWithGitIgnore(patterns, options) {
|
|
|
152
151
|
__proto__: null,
|
|
153
152
|
...options
|
|
154
153
|
};
|
|
155
|
-
const projectIgnorePaths = socketConfig?.projectIgnorePaths;
|
|
156
154
|
const ignoreFiles = await vendor.distExports.glob(['**/.gitignore'], {
|
|
157
155
|
absolute: true,
|
|
158
156
|
cwd,
|
|
159
157
|
expandDirectories: true
|
|
160
158
|
});
|
|
159
|
+
const projectIgnorePaths = socketConfig?.projectIgnorePaths;
|
|
161
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()];
|
|
162
161
|
const hasNegatedPattern = ignores.some(p => p.charCodeAt(0) === 33 /*'!'*/);
|
|
163
162
|
const globOptions = {
|
|
163
|
+
__proto__: null,
|
|
164
164
|
absolute: true,
|
|
165
165
|
cwd,
|
|
166
166
|
dot: true,
|
|
@@ -172,14 +172,11 @@ async function globWithGitIgnore(patterns, options) {
|
|
|
172
172
|
if (!hasNegatedPattern) {
|
|
173
173
|
return result;
|
|
174
174
|
}
|
|
175
|
-
const {
|
|
176
|
-
absolute
|
|
177
|
-
} = globOptions;
|
|
178
175
|
|
|
179
176
|
// Note: the input files must be INSIDE the cwd. If you get strange looking
|
|
180
177
|
// relative path errors here, most likely your path is outside the given cwd.
|
|
181
|
-
const filtered = vendor.ignoreExports().add(ignores).filter(absolute ? result.map(p => path.relative(cwd, p)) : result);
|
|
182
|
-
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;
|
|
183
180
|
}
|
|
184
181
|
async function globNodeModules(cwd = process.cwd()) {
|
|
185
182
|
return await vendor.distExports.glob('**/node_modules', {
|
|
@@ -197,17 +194,18 @@ async function globWorkspace(agent, cwd = process.cwd()) {
|
|
|
197
194
|
ignore: ['**/node_modules/**', '**/bower_components/**']
|
|
198
195
|
}) : [];
|
|
199
196
|
}
|
|
197
|
+
function isReportSupportedFile(filepath, supportedFiles) {
|
|
198
|
+
const patterns = getSupportedFilePatterns(supportedFiles);
|
|
199
|
+
return vendor.micromatchExports.some(filepath, patterns);
|
|
200
|
+
}
|
|
200
201
|
function pathsToGlobPatterns(paths) {
|
|
201
202
|
// TODO: Does not support `~/` paths.
|
|
202
203
|
return paths.map(p => p === '.' || p === './' ? '**/*' : p);
|
|
203
204
|
}
|
|
204
205
|
|
|
205
|
-
const {
|
|
206
|
-
abortSignal
|
|
207
|
-
} = constants;
|
|
208
206
|
async function removeNodeModules(cwd = process.cwd()) {
|
|
209
207
|
const nodeModulesPaths = await globNodeModules(cwd);
|
|
210
|
-
await require$$
|
|
208
|
+
await require$$8.pEach(nodeModulesPaths, 3, p => fs$1.remove(p, {
|
|
211
209
|
force: true,
|
|
212
210
|
recursive: true
|
|
213
211
|
}), {
|
|
@@ -216,7 +214,8 @@ async function removeNodeModules(cwd = process.cwd()) {
|
|
|
216
214
|
}
|
|
217
215
|
async function findUp(name, {
|
|
218
216
|
cwd = process.cwd(),
|
|
219
|
-
|
|
217
|
+
// Lazily access constants.abortSignal.
|
|
218
|
+
signal = constants.abortSignal
|
|
220
219
|
}) {
|
|
221
220
|
let dir = path.resolve(cwd);
|
|
222
221
|
const {
|
|
@@ -243,14 +242,16 @@ async function findUp(name, {
|
|
|
243
242
|
}
|
|
244
243
|
async function readFileBinary(filepath, options) {
|
|
245
244
|
return await fs.promises.readFile(filepath, {
|
|
246
|
-
|
|
245
|
+
// Lazily access constants.abortSignal.
|
|
246
|
+
signal: constants.abortSignal,
|
|
247
247
|
...options,
|
|
248
248
|
encoding: 'binary'
|
|
249
249
|
});
|
|
250
250
|
}
|
|
251
251
|
async function readFileUtf8(filepath, options) {
|
|
252
252
|
return await fs.promises.readFile(filepath, {
|
|
253
|
-
|
|
253
|
+
// Lazily access constants.abortSignal.
|
|
254
|
+
signal: constants.abortSignal,
|
|
254
255
|
...options,
|
|
255
256
|
encoding: 'utf8'
|
|
256
257
|
});
|
|
@@ -259,7 +260,8 @@ async function safeReadFile(filepath, options) {
|
|
|
259
260
|
try {
|
|
260
261
|
return await fs.promises.readFile(filepath, {
|
|
261
262
|
encoding: 'utf8',
|
|
262
|
-
|
|
263
|
+
// Lazily access constants.abortSignal.
|
|
264
|
+
signal: constants.abortSignal,
|
|
263
265
|
...(typeof options === 'string' ? {
|
|
264
266
|
encoding: options
|
|
265
267
|
} : options)
|
|
@@ -288,8 +290,10 @@ function safeStatsSync(filepath, options) {
|
|
|
288
290
|
return undefined;
|
|
289
291
|
}
|
|
290
292
|
|
|
291
|
-
const
|
|
292
|
-
const
|
|
293
|
+
const sensitiveConfigKeyLookup = new Set(['apiToken']);
|
|
294
|
+
const supportedConfig = new Map([['apiBaseUrl', 'Base URL of the API endpoint'], ['apiProxy', 'A proxy through which to access the API'], ['apiToken', 'The API token required to access most API endpoints'], ['defaultOrg', 'The default org slug to use; usually the org your API token has access to. When set, all orgSlug arguments are implied to be this value.'], ['enforcedOrgs', 'Orgs in this list have their security policies enforced on this machine'], ['skipAskToPersistDefaultOrg', 'This flag prevents the CLI from asking you to persist the org slug when you selected one interactively'], ['org', 'Alias for defaultOrg']]);
|
|
295
|
+
const supportedConfigEntries = [...supportedConfig.entries()].sort((a, b) => sorts.naturalCompare(a[0], b[0]));
|
|
296
|
+
const supportedConfigKeys = supportedConfigEntries.map(p => p[0]);
|
|
293
297
|
function getConfigValues() {
|
|
294
298
|
if (_cachedConfig === undefined) {
|
|
295
299
|
// Order: env var > --config flag > file
|
|
@@ -327,7 +331,7 @@ function normalizeConfigKey(key) {
|
|
|
327
331
|
// property apiKey, we'll copy that to apiToken and delete the old property.
|
|
328
332
|
// We added `org` as a convenience alias for `defaultOrg`
|
|
329
333
|
const normalizedKey = key === 'apiKey' ? 'apiToken' : key === 'org' ? 'defaultOrg' : key;
|
|
330
|
-
if (!
|
|
334
|
+
if (!isSupportedConfigKey(normalizedKey)) {
|
|
331
335
|
return {
|
|
332
336
|
ok: false,
|
|
333
337
|
message: `Invalid config key: ${normalizedKey}`,
|
|
@@ -385,9 +389,21 @@ function getConfigValueOrUndef(key) {
|
|
|
385
389
|
}
|
|
386
390
|
return localConfig[keyResult.data];
|
|
387
391
|
}
|
|
392
|
+
function getSupportedConfigEntries() {
|
|
393
|
+
return [...supportedConfigEntries];
|
|
394
|
+
}
|
|
395
|
+
function getSupportedConfigKeys() {
|
|
396
|
+
return [...supportedConfigKeys];
|
|
397
|
+
}
|
|
388
398
|
function isReadOnlyConfig() {
|
|
389
399
|
return _readOnlyConfig;
|
|
390
400
|
}
|
|
401
|
+
function isSensitiveConfigKey(key) {
|
|
402
|
+
return sensitiveConfigKeyLookup.has(key);
|
|
403
|
+
}
|
|
404
|
+
function isSupportedConfigKey(key) {
|
|
405
|
+
return supportedConfig.has(key);
|
|
406
|
+
}
|
|
391
407
|
let _cachedConfig;
|
|
392
408
|
// When using --config or SOCKET_CLI_CONFIG, do not persist the config.
|
|
393
409
|
let _readOnlyConfig = false;
|
|
@@ -397,7 +413,8 @@ function overrideCachedConfig(jsonConfig) {
|
|
|
397
413
|
try {
|
|
398
414
|
config = JSON.parse(String(jsonConfig));
|
|
399
415
|
if (!config || typeof config !== 'object') {
|
|
400
|
-
// `null` is valid json, so are primitive values.
|
|
416
|
+
// `null` is valid json, so are primitive values.
|
|
417
|
+
// They're not valid config objects :)
|
|
401
418
|
return {
|
|
402
419
|
ok: false,
|
|
403
420
|
message: 'Could not parse Config as JSON',
|
|
@@ -405,7 +422,7 @@ function overrideCachedConfig(jsonConfig) {
|
|
|
405
422
|
};
|
|
406
423
|
}
|
|
407
424
|
} catch {
|
|
408
|
-
// Force set an empty config to prevent accidentally using system settings
|
|
425
|
+
// Force set an empty config to prevent accidentally using system settings.
|
|
409
426
|
_cachedConfig = {};
|
|
410
427
|
_readOnlyConfig = true;
|
|
411
428
|
return {
|
|
@@ -419,7 +436,7 @@ function overrideCachedConfig(jsonConfig) {
|
|
|
419
436
|
_cachedConfig = config;
|
|
420
437
|
_readOnlyConfig = true;
|
|
421
438
|
|
|
422
|
-
// Normalize apiKey to apiToken
|
|
439
|
+
// Normalize apiKey to apiToken.
|
|
423
440
|
if (_cachedConfig['apiKey']) {
|
|
424
441
|
if (_cachedConfig['apiToken']) {
|
|
425
442
|
logger.logger.warn('Note: The config override had both apiToken and apiKey. Using the apiToken value. Remove the apiKey to get rid of this message.');
|
|
@@ -434,8 +451,7 @@ function overrideCachedConfig(jsonConfig) {
|
|
|
434
451
|
}
|
|
435
452
|
function overrideConfigApiToken(apiToken) {
|
|
436
453
|
debug.debugFn('notice', 'override: API token (not stored)');
|
|
437
|
-
|
|
438
|
-
// Set token to the local cached config and mark it read-only so it doesn't persist
|
|
454
|
+
// Set token to the local cached config and mark it read-only so it doesn't persist.
|
|
439
455
|
_cachedConfig = {
|
|
440
456
|
...vendor.configExports,
|
|
441
457
|
...(apiToken === undefined ? {} : {
|
|
@@ -452,7 +468,8 @@ function updateConfigValue(configKey, value) {
|
|
|
452
468
|
return keyResult;
|
|
453
469
|
}
|
|
454
470
|
const key = keyResult.data;
|
|
455
|
-
|
|
471
|
+
// Implicitly deleting when serializing.
|
|
472
|
+
let wasDeleted = value === undefined;
|
|
456
473
|
if (key === 'skipAskToPersistDefaultOrg') {
|
|
457
474
|
if (value === 'true' || value === 'false') {
|
|
458
475
|
localConfig['skipAskToPersistDefaultOrg'] = value === 'true';
|
|
@@ -586,7 +603,14 @@ function getPublicToken() {
|
|
|
586
603
|
// Lazily access constants.SOCKET_PUBLIC_API_TOKEN.
|
|
587
604
|
constants.SOCKET_PUBLIC_API_TOKEN;
|
|
588
605
|
}
|
|
589
|
-
async function setupSdk(
|
|
606
|
+
async function setupSdk(options) {
|
|
607
|
+
const opts = {
|
|
608
|
+
__proto__: null,
|
|
609
|
+
...options
|
|
610
|
+
};
|
|
611
|
+
let {
|
|
612
|
+
apiToken = getDefaultToken()
|
|
613
|
+
} = opts;
|
|
590
614
|
if (typeof apiToken !== 'string' && vendor.isInteractiveExports()) {
|
|
591
615
|
apiToken = await prompts.password({
|
|
592
616
|
message: 'Enter your Socket.dev API key (not saved, use socket login to persist)'
|
|
@@ -600,15 +624,21 @@ async function setupSdk(apiToken = getDefaultToken(), apiBaseUrl = getDefaultApi
|
|
|
600
624
|
cause: 'You need to provide an API Token. Run `socket login` first.'
|
|
601
625
|
};
|
|
602
626
|
}
|
|
603
|
-
|
|
604
|
-
|
|
627
|
+
let {
|
|
628
|
+
apiProxy
|
|
629
|
+
} = opts;
|
|
630
|
+
if (!isUrl(apiProxy)) {
|
|
631
|
+
apiProxy = getDefaultProxyUrl();
|
|
605
632
|
}
|
|
606
|
-
const
|
|
633
|
+
const {
|
|
634
|
+
apiBaseUrl = getDefaultApiBaseUrl$1()
|
|
635
|
+
} = opts;
|
|
636
|
+
const ProxyAgent = apiProxy?.startsWith('http:') ? vendor.HttpProxyAgent : vendor.HttpsProxyAgent;
|
|
607
637
|
return {
|
|
608
638
|
ok: true,
|
|
609
639
|
data: new vendor.distExports$2.SocketSdk(apiToken, {
|
|
610
|
-
agent:
|
|
611
|
-
proxy
|
|
640
|
+
agent: apiProxy ? new ProxyAgent({
|
|
641
|
+
proxy: apiProxy
|
|
612
642
|
}) : undefined,
|
|
613
643
|
baseUrl: apiBaseUrl,
|
|
614
644
|
userAgent: vendor.distExports$2.createUserAgentFromPkgJson({
|
|
@@ -623,59 +653,79 @@ async function setupSdk(apiToken = getDefaultToken(), apiBaseUrl = getDefaultApi
|
|
|
623
653
|
};
|
|
624
654
|
}
|
|
625
655
|
|
|
626
|
-
|
|
627
|
-
|
|
656
|
+
const NO_ERROR_MESSAGE = 'No error message returned';
|
|
657
|
+
async function handleApiCall(value, options) {
|
|
628
658
|
const {
|
|
659
|
+
desc,
|
|
629
660
|
spinner
|
|
630
|
-
} =
|
|
631
|
-
|
|
632
|
-
|
|
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;
|
|
633
671
|
try {
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
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
|
+
}
|
|
638
679
|
} catch (e) {
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
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
|
+
}
|
|
643
687
|
debug.debugDir('inspect', {
|
|
644
688
|
error: e
|
|
645
689
|
});
|
|
646
690
|
return {
|
|
647
691
|
ok: false,
|
|
648
692
|
message: 'Socket API returned an error',
|
|
649
|
-
cause:
|
|
693
|
+
cause: vendor.messageWithCauses(e)
|
|
650
694
|
};
|
|
651
695
|
} finally {
|
|
652
|
-
spinner
|
|
696
|
+
spinner?.stop();
|
|
653
697
|
}
|
|
654
698
|
|
|
655
|
-
// Note: TS can't narrow down the type of result due to generics
|
|
656
|
-
if (
|
|
657
|
-
const
|
|
658
|
-
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}`;
|
|
659
703
|
const {
|
|
660
704
|
cause: reason
|
|
661
|
-
} =
|
|
662
|
-
|
|
705
|
+
} = errorResult;
|
|
706
|
+
if (desc) {
|
|
707
|
+
debug.debugFn('error', `fail: ${desc} bad response`);
|
|
708
|
+
} else {
|
|
709
|
+
debug.debugFn('error', 'fail: bad response');
|
|
710
|
+
}
|
|
663
711
|
debug.debugDir('inspect', {
|
|
664
|
-
|
|
712
|
+
sdkResult
|
|
665
713
|
});
|
|
666
714
|
return {
|
|
667
715
|
ok: false,
|
|
668
716
|
message: 'Socket API returned an error',
|
|
669
717
|
cause: `${message}${reason ? ` ( Reason: ${reason} )` : ''}`,
|
|
670
718
|
data: {
|
|
671
|
-
code:
|
|
719
|
+
code: sdkResult.status
|
|
672
720
|
}
|
|
673
721
|
};
|
|
674
722
|
} else {
|
|
675
|
-
const
|
|
723
|
+
const {
|
|
724
|
+
data
|
|
725
|
+
} = sdkResult;
|
|
676
726
|
return {
|
|
677
727
|
ok: true,
|
|
678
|
-
data
|
|
728
|
+
data
|
|
679
729
|
};
|
|
680
730
|
}
|
|
681
731
|
}
|
|
@@ -684,8 +734,8 @@ async function handleApiCallNoSpinner(value, description) {
|
|
|
684
734
|
try {
|
|
685
735
|
result = await value;
|
|
686
736
|
} catch (e) {
|
|
687
|
-
const message = `${e ||
|
|
688
|
-
const reason = `${e ||
|
|
737
|
+
const message = `${e || NO_ERROR_MESSAGE}`;
|
|
738
|
+
const reason = `${e || NO_ERROR_MESSAGE}`;
|
|
689
739
|
debug.debugFn('error', `caught: ${description} error`);
|
|
690
740
|
debug.debugDir('inspect', {
|
|
691
741
|
error: e
|
|
@@ -700,7 +750,7 @@ async function handleApiCallNoSpinner(value, description) {
|
|
|
700
750
|
// Note: TS can't narrow down the type of result due to generics
|
|
701
751
|
if (result.success === false) {
|
|
702
752
|
const error = result;
|
|
703
|
-
const message = `${error.error ||
|
|
753
|
+
const message = `${error.error || NO_ERROR_MESSAGE}`;
|
|
704
754
|
debug.debugFn('error', `fail: ${description} bad response`);
|
|
705
755
|
debug.debugDir('inspect', {
|
|
706
756
|
error
|
|
@@ -1109,7 +1159,7 @@ function getHelpListOutput(list, options) {
|
|
|
1109
1159
|
if (entry && 'hidden' in entry && entry?.hidden) {
|
|
1110
1160
|
continue;
|
|
1111
1161
|
}
|
|
1112
|
-
const description = (
|
|
1162
|
+
const description = (require$$7.isObject(entry) ? entry.description : entry) || '';
|
|
1113
1163
|
result += ''.padEnd(indent) + (keyPrefix + name).padEnd(padName) + description + '\n';
|
|
1114
1164
|
}
|
|
1115
1165
|
return result.trim() || '(none)';
|
|
@@ -1266,10 +1316,10 @@ async function meowWithSubcommands(subcommands, options) {
|
|
|
1266
1316
|
function formatCommandsForHelp(isRootCommand) {
|
|
1267
1317
|
if (!isRootCommand) {
|
|
1268
1318
|
return getHelpListOutput({
|
|
1269
|
-
...
|
|
1319
|
+
...require$$7.toSortedObject(Object.fromEntries(Object.entries(subcommands).filter(({
|
|
1270
1320
|
1: subcommand
|
|
1271
1321
|
}) => !subcommand.hidden))),
|
|
1272
|
-
...
|
|
1322
|
+
...require$$7.toSortedObject(Object.fromEntries(Object.entries(aliases).filter(({
|
|
1273
1323
|
1: alias
|
|
1274
1324
|
}) => {
|
|
1275
1325
|
const {
|
|
@@ -1514,41 +1564,54 @@ function msAtHome(isoTimeStamp) {
|
|
|
1514
1564
|
}
|
|
1515
1565
|
}
|
|
1516
1566
|
|
|
1517
|
-
async function
|
|
1518
|
-
const
|
|
1567
|
+
async function fetchOrganization(options) {
|
|
1568
|
+
const {
|
|
1569
|
+
sdkOptions
|
|
1570
|
+
} = {
|
|
1571
|
+
__proto__: null,
|
|
1572
|
+
...options
|
|
1573
|
+
};
|
|
1574
|
+
const sockSdkCResult = await setupSdk(sdkOptions);
|
|
1519
1575
|
if (!sockSdkCResult.ok) {
|
|
1520
|
-
return;
|
|
1576
|
+
return sockSdkCResult;
|
|
1521
1577
|
}
|
|
1522
1578
|
const sockSdk = sockSdkCResult.data;
|
|
1523
|
-
|
|
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
|
+
}
|
|
1524
1590
|
|
|
1525
1591
|
// Ignore a failed request here. It was not the primary goal of
|
|
1526
1592
|
// running this command and reporting it only leads to end-user confusion.
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
return proceed;
|
|
1548
|
-
}
|
|
1549
|
-
} else {
|
|
1550
|
-
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;
|
|
1551
1613
|
}
|
|
1614
|
+
return undefined;
|
|
1552
1615
|
}
|
|
1553
1616
|
|
|
1554
1617
|
async function suggestToPersistOrgSlug(orgSlug) {
|
|
@@ -1626,6 +1689,47 @@ async function determineOrgSlug(orgFlag, interactive, dryRun) {
|
|
|
1626
1689
|
return [orgSlug, defaultOrgSlug];
|
|
1627
1690
|
}
|
|
1628
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
|
+
|
|
1629
1733
|
async function getBaseBranch(cwd = process.cwd()) {
|
|
1630
1734
|
// Lazily access constants.ENV properties.
|
|
1631
1735
|
const {
|
|
@@ -2031,16 +2135,15 @@ function* walkNestedMap(map, keys = []) {
|
|
|
2031
2135
|
}
|
|
2032
2136
|
}
|
|
2033
2137
|
|
|
2034
|
-
const {
|
|
2035
|
-
NODE_MODULES: NODE_MODULES$1,
|
|
2036
|
-
NPM: NPM$4,
|
|
2037
|
-
shadowBinPath
|
|
2038
|
-
} = constants;
|
|
2039
2138
|
function findBinPathDetailsSync(binName) {
|
|
2040
2139
|
const binPaths = vendor.libExports$1.sync(binName, {
|
|
2041
2140
|
all: true,
|
|
2042
2141
|
nothrow: true
|
|
2043
2142
|
}) ?? [];
|
|
2143
|
+
// Lazily access constants.shadowBinPath.
|
|
2144
|
+
const {
|
|
2145
|
+
shadowBinPath
|
|
2146
|
+
} = constants;
|
|
2044
2147
|
let shadowIndex = -1;
|
|
2045
2148
|
let theBinPath;
|
|
2046
2149
|
for (let i = 0, {
|
|
@@ -2068,7 +2171,7 @@ function findNpmPathSync(npmBinPath) {
|
|
|
2068
2171
|
} = constants;
|
|
2069
2172
|
let thePath = npmBinPath;
|
|
2070
2173
|
while (true) {
|
|
2071
|
-
const libNmNpmPath = path.join(thePath, 'lib'
|
|
2174
|
+
const libNmNpmPath = path.join(thePath, 'lib/node_modules/npm');
|
|
2072
2175
|
// mise puts its npm bin in a path like:
|
|
2073
2176
|
// /Users/SomeUsername/.local/share/mise/installs/node/vX.X.X/bin/npm.
|
|
2074
2177
|
// HOWEVER, the location of the npm install is:
|
|
@@ -2078,9 +2181,9 @@ function findNpmPathSync(npmBinPath) {
|
|
|
2078
2181
|
// will throw an ENOTDIR error for paths like ./a-file-that-exists/a-directory-that-does-not.
|
|
2079
2182
|
// See https://github.com/nodejs/node/issues/56993.
|
|
2080
2183
|
fs.existsSync(libNmNpmPath) && safeStatsSync(libNmNpmPath)?.isDirectory()) {
|
|
2081
|
-
thePath = path.join(libNmNpmPath,
|
|
2184
|
+
thePath = path.join(libNmNpmPath, 'npm');
|
|
2082
2185
|
}
|
|
2083
|
-
const nmPath = path.join(thePath,
|
|
2186
|
+
const nmPath = path.join(thePath, 'node_modules');
|
|
2084
2187
|
if (
|
|
2085
2188
|
// npm bin paths may look like:
|
|
2086
2189
|
// /usr/local/share/npm/bin/npm
|
|
@@ -2094,9 +2197,9 @@ function findNpmPathSync(npmBinPath) {
|
|
|
2094
2197
|
// C:\Program Files\nodejs\node_modules
|
|
2095
2198
|
fs.existsSync(nmPath) && safeStatsSync(nmPath)?.isDirectory() && (
|
|
2096
2199
|
// Optimistically look for the default location.
|
|
2097
|
-
path.basename(thePath) ===
|
|
2200
|
+
path.basename(thePath) === 'npm' ||
|
|
2098
2201
|
// Chocolatey installs npm bins in the same directory as node bins.
|
|
2099
|
-
WIN32 && fs.existsSync(path.join(thePath,
|
|
2202
|
+
WIN32 && fs.existsSync(path.join(thePath, 'npm.cmd')))) {
|
|
2100
2203
|
return thePath;
|
|
2101
2204
|
}
|
|
2102
2205
|
const parent = path.dirname(thePath);
|
|
@@ -2114,11 +2217,11 @@ async function getPackageFilesForScan(inputPaths, supportedFiles, options) {
|
|
|
2114
2217
|
__proto__: null,
|
|
2115
2218
|
...options
|
|
2116
2219
|
};
|
|
2117
|
-
const
|
|
2220
|
+
const filepaths = await globWithGitIgnore(pathsToGlobPatterns(inputPaths), {
|
|
2118
2221
|
cwd,
|
|
2119
2222
|
socketConfig
|
|
2120
2223
|
});
|
|
2121
|
-
return
|
|
2224
|
+
return filterBySupportedScanFiles(filepaths, supportedFiles);
|
|
2122
2225
|
}
|
|
2123
2226
|
|
|
2124
2227
|
async function readOrDefaultSocketJson(cwd) {
|
|
@@ -2440,11 +2543,11 @@ function getMinVersion(range) {
|
|
|
2440
2543
|
return null;
|
|
2441
2544
|
}
|
|
2442
2545
|
|
|
2443
|
-
const require$1 = require$$5.createRequire(
|
|
2546
|
+
const require$1 = require$$5.createRequire(require('node:url').pathToFileURL(__filename).href);
|
|
2444
2547
|
let _translations;
|
|
2445
2548
|
function getTranslations() {
|
|
2446
2549
|
if (_translations === undefined) {
|
|
2447
|
-
_translations = require$1(
|
|
2550
|
+
_translations = /*@__PURE__*/require$1(
|
|
2448
2551
|
// Lazily access constants.rootPath.
|
|
2449
2552
|
path.join(constants.rootPath, 'translations.json'));
|
|
2450
2553
|
}
|
|
@@ -2555,7 +2658,7 @@ async function addArtifactToAlertsMap(artifact, alertsByPurl, options) {
|
|
|
2555
2658
|
const fixableCve = fixType === ALERT_FIX_TYPE.cve;
|
|
2556
2659
|
const fixableUpgrade = fixType === ALERT_FIX_TYPE.upgrade;
|
|
2557
2660
|
const fixable = fixableCve || fixableUpgrade;
|
|
2558
|
-
const upgradable = fixableUpgrade && !
|
|
2661
|
+
const upgradable = fixableUpgrade && !require$$7.hasOwn(overrides, name);
|
|
2559
2662
|
if (include.blocked && blocked || include.critical && critical || include.cve && cve || include.unfixable && !fixable || include.upgradable && upgradable) {
|
|
2560
2663
|
sockPkgAlerts.push({
|
|
2561
2664
|
name,
|
|
@@ -2920,7 +3023,7 @@ function parsePnpmLockfile(lockfileContent) {
|
|
|
2920
3023
|
result = vendor.jsYaml.load(strings.stripBom(lockfileContent));
|
|
2921
3024
|
} catch {}
|
|
2922
3025
|
}
|
|
2923
|
-
return
|
|
3026
|
+
return require$$7.isObjectObject(result) ? result : null;
|
|
2924
3027
|
}
|
|
2925
3028
|
function parsePnpmLockfileVersion(version) {
|
|
2926
3029
|
try {
|
|
@@ -2944,15 +3047,15 @@ async function getAlertsMapFromPnpmLockfile(lockfile, options) {
|
|
|
2944
3047
|
...options
|
|
2945
3048
|
});
|
|
2946
3049
|
}
|
|
2947
|
-
async function getAlertsMapFromPurls(purls,
|
|
2948
|
-
const
|
|
3050
|
+
async function getAlertsMapFromPurls(purls, options) {
|
|
3051
|
+
const opts = {
|
|
2949
3052
|
__proto__: null,
|
|
2950
3053
|
consolidate: false,
|
|
2951
3054
|
include: undefined,
|
|
2952
3055
|
nothrow: false,
|
|
2953
|
-
...
|
|
3056
|
+
...options
|
|
2954
3057
|
};
|
|
2955
|
-
|
|
3058
|
+
opts.include = {
|
|
2956
3059
|
__proto__: null,
|
|
2957
3060
|
// Leave 'actions' unassigned so it can be given a default value in
|
|
2958
3061
|
// subsequent functions where `options` is passed.
|
|
@@ -2963,11 +3066,8 @@ async function getAlertsMapFromPurls(purls, options_) {
|
|
|
2963
3066
|
existing: false,
|
|
2964
3067
|
unfixable: true,
|
|
2965
3068
|
upgradable: false,
|
|
2966
|
-
...
|
|
3069
|
+
...opts.include
|
|
2967
3070
|
};
|
|
2968
|
-
const {
|
|
2969
|
-
spinner
|
|
2970
|
-
} = options;
|
|
2971
3071
|
const uniqPurls = arrays.arrayUnique(purls);
|
|
2972
3072
|
debug.debugDir('silly', {
|
|
2973
3073
|
purls: uniqPurls
|
|
@@ -2979,37 +3079,44 @@ async function getAlertsMapFromPurls(purls, options_) {
|
|
|
2979
3079
|
if (!remaining) {
|
|
2980
3080
|
return alertsByPurl;
|
|
2981
3081
|
}
|
|
3082
|
+
const {
|
|
3083
|
+
spinner
|
|
3084
|
+
} = opts;
|
|
2982
3085
|
const getText = () => `Looking up data for ${remaining} packages`;
|
|
2983
3086
|
spinner?.start(getText());
|
|
2984
|
-
const sockSdkCResult = await setupSdk(
|
|
3087
|
+
const sockSdkCResult = await setupSdk({
|
|
3088
|
+
apiToken: getPublicToken()
|
|
3089
|
+
});
|
|
2985
3090
|
if (!sockSdkCResult.ok) {
|
|
2986
3091
|
spinner?.stop();
|
|
2987
3092
|
throw new Error('Auth error: Try to run `socket login` first');
|
|
2988
3093
|
}
|
|
2989
3094
|
const sockSdk = sockSdkCResult.data;
|
|
2990
3095
|
const alertsMapOptions = {
|
|
2991
|
-
overrides:
|
|
2992
|
-
consolidate:
|
|
2993
|
-
include:
|
|
3096
|
+
overrides: opts.overrides,
|
|
3097
|
+
consolidate: opts.consolidate,
|
|
3098
|
+
include: opts.include,
|
|
2994
3099
|
spinner
|
|
2995
3100
|
};
|
|
2996
3101
|
for await (const batchResult of sockSdk.batchPackageStream({
|
|
2997
|
-
alerts: 'true',
|
|
2998
|
-
compact: 'true',
|
|
2999
|
-
...(options.include.actions ? {
|
|
3000
|
-
actions: options.include.actions.join(',')
|
|
3001
|
-
} : {}),
|
|
3002
|
-
...(options.include.unfixable ? {} : {
|
|
3003
|
-
fixable: 'true'
|
|
3004
|
-
})
|
|
3005
|
-
}, {
|
|
3006
3102
|
components: uniqPurls.map(purl => ({
|
|
3007
3103
|
purl
|
|
3008
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
|
+
}
|
|
3009
3116
|
})) {
|
|
3010
3117
|
if (batchResult.success) {
|
|
3011
3118
|
await addArtifactToAlertsMap(batchResult.data, alertsByPurl, alertsMapOptions);
|
|
3012
|
-
} else if (!
|
|
3119
|
+
} else if (!opts.nothrow) {
|
|
3013
3120
|
const statusCode = batchResult.status ?? 'unknown';
|
|
3014
3121
|
const statusMessage = batchResult.error ?? 'No status message';
|
|
3015
3122
|
throw new Error(`Socket API server error (${statusCode}): ${statusMessage}`);
|
|
@@ -3090,7 +3197,7 @@ function safeNpmInstall(options) {
|
|
|
3090
3197
|
...options
|
|
3091
3198
|
};
|
|
3092
3199
|
let stdio = spawnOptions.stdio;
|
|
3093
|
-
const useIpc =
|
|
3200
|
+
const useIpc = require$$7.isObject(ipc);
|
|
3094
3201
|
// Include 'ipc' in the spawnOptions.stdio when an options.ipc object is provided.
|
|
3095
3202
|
// See https://github.com/nodejs/node/blob/v23.6.0/lib/child_process.js#L161-L166
|
|
3096
3203
|
// and https://github.com/nodejs/node/blob/v23.6.0/lib/internal/child_process.js#L238.
|
|
@@ -3249,6 +3356,9 @@ async function spawnCoana(args, options, extra) {
|
|
|
3249
3356
|
__proto__: null,
|
|
3250
3357
|
...options
|
|
3251
3358
|
};
|
|
3359
|
+
const orgSlugCResult = await getDefaultOrgSlug();
|
|
3360
|
+
const SOCKET_CLI_API_TOKEN = getDefaultToken();
|
|
3361
|
+
const SOCKET_ORG_SLUG = orgSlugCResult.ok ? orgSlugCResult.data : undefined;
|
|
3252
3362
|
try {
|
|
3253
3363
|
const output = await spawn.spawn(constants.execPath, [
|
|
3254
3364
|
// Lazily access constants.nodeNoWarningsFlags.
|
|
@@ -3260,7 +3370,9 @@ async function spawnCoana(args, options, extra) {
|
|
|
3260
3370
|
...process.env,
|
|
3261
3371
|
// Lazily access constants.processEnv.
|
|
3262
3372
|
...constants.processEnv,
|
|
3263
|
-
|
|
3373
|
+
RUN_WITHOUT_DOCKER: 'true',
|
|
3374
|
+
SOCKET_CLI_API_TOKEN,
|
|
3375
|
+
SOCKET_ORG_SLUG,
|
|
3264
3376
|
...spawnEnv
|
|
3265
3377
|
}
|
|
3266
3378
|
}, extra);
|
|
@@ -3694,6 +3806,7 @@ exports.detectAndValidatePackageEnvironment = detectAndValidatePackageEnvironmen
|
|
|
3694
3806
|
exports.determineOrgSlug = determineOrgSlug;
|
|
3695
3807
|
exports.extractOverridesFromPnpmLockSrc = extractOverridesFromPnpmLockSrc;
|
|
3696
3808
|
exports.failMsgWithBadge = failMsgWithBadge;
|
|
3809
|
+
exports.fetchOrganization = fetchOrganization;
|
|
3697
3810
|
exports.getAlertsMapFromPnpmLockfile = getAlertsMapFromPnpmLockfile;
|
|
3698
3811
|
exports.getAlertsMapFromPurls = getAlertsMapFromPurls;
|
|
3699
3812
|
exports.getBaseBranch = getBaseBranch;
|
|
@@ -3701,6 +3814,7 @@ exports.getBashrcDetails = getBashrcDetails;
|
|
|
3701
3814
|
exports.getConfigValue = getConfigValue;
|
|
3702
3815
|
exports.getConfigValueOrUndef = getConfigValueOrUndef;
|
|
3703
3816
|
exports.getCveInfoFromAlertsMap = getCveInfoFromAlertsMap;
|
|
3817
|
+
exports.getDefaultOrgSlug = getDefaultOrgSlug;
|
|
3704
3818
|
exports.getFlagListOutput = getFlagListOutput;
|
|
3705
3819
|
exports.getMajor = getMajor;
|
|
3706
3820
|
exports.getMinVersion = getMinVersion;
|
|
@@ -3715,6 +3829,8 @@ exports.getPurlObject = getPurlObject;
|
|
|
3715
3829
|
exports.getRepoInfo = getRepoInfo;
|
|
3716
3830
|
exports.getRepoName = getRepoName;
|
|
3717
3831
|
exports.getSocketDevPackageOverviewUrlFromPurl = getSocketDevPackageOverviewUrlFromPurl;
|
|
3832
|
+
exports.getSupportedConfigEntries = getSupportedConfigEntries;
|
|
3833
|
+
exports.getSupportedConfigKeys = getSupportedConfigKeys;
|
|
3718
3834
|
exports.getVisibleTokenPrefix = getVisibleTokenPrefix;
|
|
3719
3835
|
exports.gitBranch = gitBranch;
|
|
3720
3836
|
exports.gitCheckoutBranch = gitCheckoutBranch;
|
|
@@ -3735,6 +3851,9 @@ exports.isHelpFlag = isHelpFlag;
|
|
|
3735
3851
|
exports.isNpmBinPathShadowed = isNpmBinPathShadowed;
|
|
3736
3852
|
exports.isNpxBinPathShadowed = isNpxBinPathShadowed;
|
|
3737
3853
|
exports.isReadOnlyConfig = isReadOnlyConfig;
|
|
3854
|
+
exports.isReportSupportedFile = isReportSupportedFile;
|
|
3855
|
+
exports.isSensitiveConfigKey = isSensitiveConfigKey;
|
|
3856
|
+
exports.isSupportedConfigKey = isSupportedConfigKey;
|
|
3738
3857
|
exports.logAlertsMap = logAlertsMap;
|
|
3739
3858
|
exports.mapToObject = mapToObject;
|
|
3740
3859
|
exports.mdTable = mdTable;
|
|
@@ -3757,15 +3876,13 @@ exports.runAgentInstall = runAgentInstall;
|
|
|
3757
3876
|
exports.safeReadFile = safeReadFile;
|
|
3758
3877
|
exports.safeReadFileSync = safeReadFileSync;
|
|
3759
3878
|
exports.safeStatsSync = safeStatsSync;
|
|
3760
|
-
exports.sensitiveConfigKeys = sensitiveConfigKeys;
|
|
3761
3879
|
exports.serializeResultJson = serializeResultJson;
|
|
3762
3880
|
exports.setupSdk = setupSdk;
|
|
3763
3881
|
exports.spawnCoana = spawnCoana;
|
|
3764
3882
|
exports.suggestOrgSlug = suggestOrgSlug;
|
|
3765
|
-
exports.supportedConfigKeys = supportedConfigKeys;
|
|
3766
3883
|
exports.tildify = tildify;
|
|
3767
3884
|
exports.updateConfigValue = updateConfigValue;
|
|
3768
3885
|
exports.walkNestedMap = walkNestedMap;
|
|
3769
3886
|
exports.writeSocketJson = writeSocketJson;
|
|
3770
|
-
//# debugId=
|
|
3887
|
+
//# debugId=eeb540f1-2cc9-44c6-8101-3926e319a1db
|
|
3771
3888
|
//# sourceMappingURL=utils.js.map
|