socket 1.1.0 → 1.1.1

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.
Files changed (42) hide show
  1. package/dist/cli.js +123 -324
  2. package/dist/cli.js.map +1 -1
  3. package/dist/constants.js +3 -3
  4. package/dist/constants.js.map +1 -1
  5. package/dist/shadow-npm-bin.js +4 -4
  6. package/dist/shadow-npm-bin.js.map +1 -1
  7. package/dist/shadow-npm-inject.js +4 -4
  8. package/dist/shadow-npm-inject.js.map +1 -1
  9. package/dist/socket-completion.bash +1 -1
  10. package/dist/tsconfig.dts.tsbuildinfo +1 -1
  11. package/dist/types/commands/fix/cmd-fix.d.mts.map +1 -1
  12. package/dist/types/commands/fix/coana-fix.d.mts.map +1 -1
  13. package/dist/types/commands/fix/{fix-env-helpers.d.mts → env-helpers.d.mts} +1 -1
  14. package/dist/types/commands/fix/env-helpers.d.mts.map +1 -0
  15. package/dist/types/commands/fix/git.d.mts +13 -0
  16. package/dist/types/commands/fix/git.d.mts.map +1 -0
  17. package/dist/types/commands/fix/pull-request.d.mts +10 -53
  18. package/dist/types/commands/fix/pull-request.d.mts.map +1 -1
  19. package/dist/types/commands/scan/fetch-supported-scan-file-names.d.mts +2 -0
  20. package/dist/types/commands/scan/fetch-supported-scan-file-names.d.mts.map +1 -1
  21. package/dist/types/shadow/npm/paths.d.mts +0 -1
  22. package/dist/types/shadow/npm/paths.d.mts.map +1 -1
  23. package/dist/types/utils/fs.d.mts +0 -1
  24. package/dist/types/utils/fs.d.mts.map +1 -1
  25. package/dist/types/utils/github.d.mts +38 -0
  26. package/dist/types/utils/github.d.mts.map +1 -0
  27. package/dist/types/utils/glob.d.mts +0 -1
  28. package/dist/types/utils/glob.d.mts.map +1 -1
  29. package/dist/utils.js +205 -18
  30. package/dist/utils.js.map +1 -1
  31. package/dist/vendor.js +55 -49
  32. package/external/@socketsecurity/registry/external/libnpmpack.js +96569 -41361
  33. package/external/@socketsecurity/registry/external/pacote.js +77357 -68133
  34. package/external/@socketsecurity/registry/lib/fs.js +13 -27
  35. package/external/@socketsecurity/registry/lib/json.js +42 -0
  36. package/external/@socketsecurity/registry/manifest.json +4 -4
  37. package/package.json +6 -6
  38. package/dist/types/commands/fix/fix-branch-helpers.d.mts +0 -4
  39. package/dist/types/commands/fix/fix-branch-helpers.d.mts.map +0 -1
  40. package/dist/types/commands/fix/fix-env-helpers.d.mts.map +0 -1
  41. package/dist/types/commands/fix/socket-git.d.mts +0 -32
  42. package/dist/types/commands/fix/socket-git.d.mts.map +0 -1
package/dist/cli.js CHANGED
@@ -18,13 +18,13 @@ var spawn = require('../external/@socketsecurity/registry/lib/spawn');
18
18
  var fs$2 = require('../external/@socketsecurity/registry/lib/fs');
19
19
  var strings = require('../external/@socketsecurity/registry/lib/strings');
20
20
  var arrays = require('../external/@socketsecurity/registry/lib/arrays');
21
- var regexps = require('../external/@socketsecurity/registry/lib/regexps');
22
21
  var path$1 = require('../external/@socketsecurity/registry/lib/path');
23
22
  var shadowNpmBin = require('./shadow-npm-bin.js');
24
- var require$$10 = require('../external/@socketsecurity/registry/lib/objects');
23
+ var require$$11 = require('../external/@socketsecurity/registry/lib/objects');
25
24
  var registry = require('../external/@socketsecurity/registry');
26
25
  var packages = require('../external/@socketsecurity/registry/lib/packages');
27
- var require$$11 = require('../external/@socketsecurity/registry/lib/promises');
26
+ var require$$12 = require('../external/@socketsecurity/registry/lib/promises');
27
+ var regexps = require('../external/@socketsecurity/registry/lib/regexps');
28
28
  var require$$1 = require('node:util');
29
29
  var os = require('node:os');
30
30
  var promises = require('node:stream/promises');
@@ -923,7 +923,8 @@ async function fetchCreateOrgFullScan(packagePaths, orgSlug, config, options) {
923
923
 
924
924
  async function fetchSupportedScanFileNames(options) {
925
925
  const {
926
- sdkOpts
926
+ sdkOpts,
927
+ spinner
927
928
  } = {
928
929
  __proto__: null,
929
930
  ...options
@@ -934,7 +935,8 @@ async function fetchSupportedScanFileNames(options) {
934
935
  }
935
936
  const sockSdk = sockSdkCResult.data;
936
937
  return await utils.handleApiCall(sockSdk.getSupportedScanFiles(), {
937
- desc: 'supported scan file types'
938
+ desc: 'supported scan file types',
939
+ spinner
938
940
  });
939
941
  }
940
942
 
@@ -2154,7 +2156,12 @@ async function handleCreateNewScan({
2154
2156
  });
2155
2157
  logger.logger.info('Auto-generation finished. Proceeding with Scan creation.');
2156
2158
  }
2157
- const supportedFilesCResult = await fetchSupportedScanFileNames();
2159
+ const {
2160
+ spinner
2161
+ } = constants;
2162
+ const supportedFilesCResult = await fetchSupportedScanFileNames({
2163
+ spinner
2164
+ });
2158
2165
  if (!supportedFilesCResult.ok) {
2159
2166
  await outputCreateNewScan(supportedFilesCResult, {
2160
2167
  interactive,
@@ -2162,9 +2169,6 @@ async function handleCreateNewScan({
2162
2169
  });
2163
2170
  return;
2164
2171
  }
2165
- const {
2166
- spinner
2167
- } = constants;
2168
2172
  spinner.start('Searching for local files to include in scan...');
2169
2173
  const supportedFiles = supportedFilesCResult.data;
2170
2174
  const packagePaths = await utils.getPackageFilesForScan(targets, supportedFiles, {
@@ -3165,210 +3169,76 @@ const cmdConfig = {
3165
3169
  }
3166
3170
  };
3167
3171
 
3168
- function formatBranchName(name) {
3169
- return name.replace(/[^-a-zA-Z0-9/._-]+/g, '+');
3172
+ const GITHUB_ADVISORIES_URL = 'https://github.com/advisories';
3173
+ function getSocketFixBranchName(ghsaId) {
3174
+ return `socket/fix/${ghsaId}`;
3170
3175
  }
3171
- function createSocketBranchParser(options) {
3172
- const pattern = getSocketBranchPattern(options);
3173
- return function parse(branch) {
3174
- const match = pattern.exec(branch);
3175
- if (!match) {
3176
- return null;
3176
+ function getSocketFixBranchPattern(ghsaId) {
3177
+ return new RegExp(`^socket/fix/(${ghsaId ?? '.+'})$`);
3178
+ }
3179
+ function getSocketFixCommitMessage(ghsaId, details) {
3180
+ const summary = details?.summary;
3181
+ return `fix: ${ghsaId}${summary ? ` - ${summary}` : ''}`;
3182
+ }
3183
+ function getSocketFixPullRequestBody(ghsaIds, ghsaDetails) {
3184
+ const vulnCount = ghsaIds.length;
3185
+ if (vulnCount === 1) {
3186
+ const ghsaId = ghsaIds[0];
3187
+ const details = ghsaDetails?.get(ghsaId);
3188
+ const body = `[Socket](${constants.SOCKET_WEBSITE_URL}) fix for [${ghsaId}](${GITHUB_ADVISORIES_URL}/${ghsaId}).`;
3189
+ if (!details) {
3190
+ return body;
3177
3191
  }
3178
- const {
3179
- 1: type,
3180
- 2: workspace,
3181
- 3: fullName,
3182
- 4: version,
3183
- 5: newVersion
3184
- } = match;
3185
- return {
3186
- fullName,
3187
- newVersion: vendor.semverExports.coerce(newVersion.replaceAll('+', '.'))?.version,
3188
- type,
3189
- workspace,
3190
- version: vendor.semverExports.coerce(version.replaceAll('+', '.'))?.version
3191
- };
3192
- };
3192
+ const packages = details.vulnerabilities.nodes.map(v => `${v.package.name} (${v.package.ecosystem})`);
3193
+ return [body, '', '', `**Vulnerability Summary:** ${details.summary}`, '', `**Severity:** ${details.severity}`, '', `**Affected Packages:** ${arrays.joinAnd(packages)}`].join('\n');
3194
+ }
3195
+ return [`[Socket](${constants.SOCKET_WEBSITE_URL}) fixes for ${vulnCount} GHSAs.`, '', '**Fixed Vulnerabilities:**', ...ghsaIds.map(id => {
3196
+ const details = ghsaDetails?.get(id);
3197
+ const item = `- [${id}](${GITHUB_ADVISORIES_URL}/${id})`;
3198
+ if (details) {
3199
+ const packages = details.vulnerabilities.nodes.map(v => `${v.package.name}`);
3200
+ return `${item} - ${details.summary} (${arrays.joinAnd(packages)})`;
3201
+ }
3202
+ return item;
3203
+ })].join('\n');
3204
+ }
3205
+ function getSocketFixPullRequestTitle(ghsaIds) {
3206
+ const vulnCount = ghsaIds.length;
3207
+ return vulnCount === 1 ? `Fix for ${ghsaIds[0]}` : `Fixes for ${vulnCount} GHSAs`;
3193
3208
  }
3194
- createSocketBranchParser();
3195
- function getSocketBranchPattern(options) {
3209
+
3210
+ async function openSocketFixPr(owner, repo, branch, ghsaIds, options) {
3196
3211
  const {
3197
- newVersion,
3198
- purl,
3199
- workspace
3212
+ baseBranch = 'main',
3213
+ ghsaDetails
3200
3214
  } = {
3201
3215
  __proto__: null,
3202
3216
  ...options
3203
3217
  };
3204
- const purlObj = purl ? utils.getPurlObject(purl) : null;
3205
- const escType = purlObj ? regexps.escapeRegExp(purlObj.type) : '[^/]+';
3206
- const escWorkspace = workspace ? `${regexps.escapeRegExp(formatBranchName(workspace))}` : '.+';
3207
- const escMaybeNamespace = purlObj?.namespace ? `${regexps.escapeRegExp(formatBranchName(purlObj.namespace))}--` : '';
3208
- const escFullName = purlObj ? `${escMaybeNamespace}${regexps.escapeRegExp(formatBranchName(purlObj.name))}` : '[^/_]+';
3209
- const escVersion = purlObj ? regexps.escapeRegExp(formatBranchName(purlObj.version)) : '[^_]+';
3210
- const escNewVersion = newVersion ? regexps.escapeRegExp(formatBranchName(newVersion)) : '[^_]+';
3211
- return new RegExp(`^socket/(${escType})/(${escWorkspace})/(${escFullName})_(${escVersion})_(${escNewVersion})$`);
3212
- }
3213
-
3214
- let _octokit;
3215
- function getOctokit() {
3216
- if (_octokit === undefined) {
3217
- const {
3218
- SOCKET_CLI_GITHUB_TOKEN
3219
- } = constants.ENV;
3220
- if (!SOCKET_CLI_GITHUB_TOKEN) {
3221
- require$$9.debugFn('notice', 'miss: SOCKET_CLI_GITHUB_TOKEN env var');
3222
- }
3223
- const octokitOptions = {
3224
- auth: SOCKET_CLI_GITHUB_TOKEN,
3225
- baseUrl: constants.ENV.GITHUB_API_URL
3218
+ const octokit = utils.getOctokit();
3219
+ try {
3220
+ const octokitPullsCreateParams = {
3221
+ owner,
3222
+ repo,
3223
+ title: getSocketFixPullRequestTitle(ghsaIds),
3224
+ head: branch,
3225
+ base: baseBranch,
3226
+ body: getSocketFixPullRequestBody(ghsaIds, ghsaDetails)
3226
3227
  };
3227
3228
  require$$9.debugDir('inspect', {
3228
- octokitOptions
3229
- });
3230
- _octokit = new vendor.Octokit(octokitOptions);
3231
- }
3232
- return _octokit;
3233
- }
3234
- let _octokitGraphql;
3235
- function getOctokitGraphql() {
3236
- if (!_octokitGraphql) {
3237
- const {
3238
- SOCKET_CLI_GITHUB_TOKEN
3239
- } = constants.ENV;
3240
- if (!SOCKET_CLI_GITHUB_TOKEN) {
3241
- require$$9.debugFn('notice', 'miss: SOCKET_CLI_GITHUB_TOKEN env var');
3242
- }
3243
- _octokitGraphql = vendor.graphql2.defaults({
3244
- headers: {
3245
- authorization: `token ${SOCKET_CLI_GITHUB_TOKEN}`
3246
- }
3247
- });
3248
- }
3249
- return _octokitGraphql;
3250
- }
3251
- async function readCache(key,
3252
- // 5 minute in milliseconds time to live (TTL).
3253
- ttlMs = 5 * 60 * 1000) {
3254
- const cacheJsonPath = path.join(constants.githubCachePath, `${key}.json`);
3255
- const stat = fs$2.safeStatsSync(cacheJsonPath);
3256
- if (stat) {
3257
- const isExpired = Date.now() - stat.mtimeMs > ttlMs;
3258
- if (!isExpired) {
3259
- return await fs$2.readJson(cacheJsonPath);
3260
- }
3261
- }
3262
- return null;
3263
- }
3264
- async function writeCache(key, data) {
3265
- const {
3266
- githubCachePath
3267
- } = constants;
3268
- const cacheJsonPath = path.join(githubCachePath, `${key}.json`);
3269
- if (!fs$1.existsSync(githubCachePath)) {
3270
- await fs$1.promises.mkdir(githubCachePath, {
3271
- recursive: true
3272
- });
3273
- }
3274
- await fs$2.writeJson(cacheJsonPath, data);
3275
- }
3276
- async function cacheFetch(key, fetcher, ttlMs) {
3277
- // Optionally disable cache.
3278
- if (constants.ENV.DISABLE_GITHUB_CACHE) {
3279
- return await fetcher();
3280
- }
3281
- let data = await readCache(key, ttlMs);
3282
- if (!data) {
3283
- data = await fetcher();
3284
- await writeCache(key, data);
3285
- }
3286
- return data;
3287
- }
3288
- async function fetchGhsaDetails(ids) {
3289
- const results = new Map();
3290
- if (!ids.length) {
3291
- return results;
3292
- }
3293
- const octokitGraphql = getOctokitGraphql();
3294
- try {
3295
- const gqlCacheKey = `${ids.join('-')}-graphql-snapshot`;
3296
- const aliases = ids.map((id, index) => `advisory${index}: securityAdvisory(ghsaId: "${id}") {
3297
- ghsaId
3298
- summary
3299
- severity
3300
- publishedAt
3301
- withdrawnAt
3302
- vulnerabilities(first: 10) {
3303
- nodes {
3304
- package {
3305
- ecosystem
3306
- name
3307
- }
3308
- vulnerableVersionRange
3309
- }
3310
- }
3311
- }`).join('\n');
3312
- const gqlResp = await cacheFetch(gqlCacheKey, () => octokitGraphql(`
3313
- query {
3314
- ${aliases}
3315
- }
3316
- `));
3317
- for (let i = 0, {
3318
- length
3319
- } = ids; i < length; i += 1) {
3320
- const id = ids[i];
3321
- const advisoryKey = `advisory${i}`;
3322
- const advisory = gqlResp?.[advisoryKey];
3323
- if (advisory && advisory.ghsaId) {
3324
- results.set(id, advisory);
3325
- } else {
3326
- require$$9.debugFn('notice', `miss: no advisory found for ${id}`);
3327
- }
3328
- }
3329
- } catch (e) {
3330
- require$$9.debugFn('error', `Failed to fetch GHSA details: ${e?.message || 'Unknown error'}`);
3331
- }
3332
- return results;
3333
- }
3334
- async function enablePrAutoMerge({
3335
- node_id: prId
3336
- }) {
3337
- const octokitGraphql = getOctokitGraphql();
3338
- try {
3339
- const gqlResp = await octokitGraphql(`
3340
- mutation EnableAutoMerge($pullRequestId: ID!) {
3341
- enablePullRequestAutoMerge(input: {
3342
- pullRequestId: $pullRequestId,
3343
- mergeMethod: SQUASH
3344
- }) {
3345
- pullRequest {
3346
- number
3347
- }
3348
- }
3349
- }`, {
3350
- pullRequestId: prId
3229
+ octokitPullsCreateParams
3351
3230
  });
3352
- const respPrNumber = gqlResp?.enablePullRequestAutoMerge?.pullRequest?.number;
3353
- if (respPrNumber) {
3354
- return {
3355
- enabled: true
3356
- };
3357
- }
3231
+ return await octokit.pulls.create(octokitPullsCreateParams);
3358
3232
  } catch (e) {
3359
- if (e instanceof vendor.GraphqlResponseError && Array.isArray(e.errors) && e.errors.length) {
3360
- const details = e.errors.map(({
3361
- message: m
3362
- }) => m.trim());
3363
- return {
3364
- enabled: false,
3365
- details
3366
- };
3233
+ let message = `Failed to open pull request`;
3234
+ const errors = e instanceof vendor.RequestError ? e.response?.data?.['errors'] : undefined;
3235
+ if (Array.isArray(errors) && errors.length) {
3236
+ const details = errors.map(d => `- ${d.message?.trim() ?? `${d.resource}.${d.field} (${d.code})`}`).join('\n');
3237
+ message += `:\n${details}`;
3367
3238
  }
3239
+ require$$9.debugFn('error', message);
3368
3240
  }
3369
- return {
3370
- enabled: false
3371
- };
3241
+ return null;
3372
3242
  }
3373
3243
  async function getSocketPrs(owner, repo, options) {
3374
3244
  return (await getSocketPrsWithContext(owner, repo, options)).map(d => d.match);
@@ -3376,22 +3246,23 @@ async function getSocketPrs(owner, repo, options) {
3376
3246
  async function getSocketPrsWithContext(owner, repo, options) {
3377
3247
  const {
3378
3248
  author,
3249
+ ghsaId,
3379
3250
  states: statesValue = 'all'
3380
3251
  } = {
3381
3252
  __proto__: null,
3382
3253
  ...options
3383
3254
  };
3384
- const branchPattern = getSocketBranchPattern(options);
3255
+ const branchPattern = getSocketFixBranchPattern(ghsaId);
3385
3256
  const checkAuthor = strings.isNonEmptyString(author);
3386
- const octokit = getOctokit();
3387
- const octokitGraphql = getOctokitGraphql();
3257
+ const octokit = utils.getOctokit();
3258
+ const octokitGraphql = utils.getOctokitGraphql();
3388
3259
  const contextualMatches = [];
3389
3260
  const states = (typeof statesValue === 'string' ? statesValue.toLowerCase() === 'all' ? ['OPEN', 'CLOSED', 'MERGED'] : [statesValue] : statesValue).map(s => s.toUpperCase());
3390
3261
  try {
3391
3262
  // Optimistically fetch only the first 50 open PRs using GraphQL to minimize
3392
3263
  // API quota usage. Fallback to REST if no matching PRs are found.
3393
3264
  const gqlCacheKey = `${repo}-pr-graphql-snapshot`;
3394
- const gqlResp = await cacheFetch(gqlCacheKey, () => octokitGraphql(`
3265
+ const gqlResp = await utils.cacheFetch(gqlCacheKey, () => octokitGraphql(`
3395
3266
  query($owner: String!, $repo: String!, $states: [PullRequestState!]) {
3396
3267
  repository(owner: $owner, name: $repo) {
3397
3268
  pullRequests(first: 50, states: $states, orderBy: {field: CREATED_AT, direction: DESC}) {
@@ -3448,7 +3319,7 @@ async function getSocketPrsWithContext(owner, repo, options) {
3448
3319
  let allPrs;
3449
3320
  const cacheKey = `${repo}-pull-requests`;
3450
3321
  try {
3451
- allPrs = await cacheFetch(cacheKey, async () => await octokit.paginate(octokit.pulls.list, {
3322
+ allPrs = await utils.cacheFetch(cacheKey, async () => await octokit.paginate(octokit.pulls.list, {
3452
3323
  owner,
3453
3324
  repo,
3454
3325
  state: 'all',
@@ -3497,83 +3368,6 @@ async function getSocketPrsWithContext(owner, repo, options) {
3497
3368
  }
3498
3369
  return contextualMatches;
3499
3370
  }
3500
- async function openCoanaPr(owner, repo, branch, ghsaIds, options) {
3501
- const {
3502
- baseBranch = 'main',
3503
- ghsaDetails
3504
- } = {
3505
- __proto__: null,
3506
- ...options
3507
- };
3508
- const octokit = getOctokit();
3509
- const vulnCount = ghsaIds.length;
3510
- const prTitle = vulnCount === 1 ? `Fix for ${ghsaIds[0]}` : `Fixes for ${vulnCount} GHSAs`;
3511
- let prBody = '';
3512
- if (vulnCount === 1) {
3513
- const ghsaId = ghsaIds[0];
3514
- const details = ghsaDetails?.get(ghsaId);
3515
- prBody = `[Socket](https://socket.dev/) fix for [${ghsaId}](https://github.com/advisories/${ghsaId}).`;
3516
- if (details) {
3517
- const packages = details.vulnerabilities.nodes.map(v => `${v.package.name} (${v.package.ecosystem})`);
3518
- prBody += ['', '', `**Vulnerability Summary:** ${details.summary}`, '', `**Severity:** ${details.severity}`, '', `**Affected Packages:** ${arrays.joinAnd(packages)}`].join('\n');
3519
- }
3520
- } else {
3521
- prBody = [`[Socket](https://socket.dev/) fixes for ${vulnCount} GHSAs.`, '', '**Fixed Vulnerabilities:**', ...ghsaIds.map(id => {
3522
- const details = ghsaDetails?.get(id);
3523
- const item = `- [${id}](https://github.com/advisories/${id})`;
3524
- if (details) {
3525
- const packages = details.vulnerabilities.nodes.map(v => `${v.package.name}`);
3526
- return `${item} - ${details.summary} (${arrays.joinAnd(packages)})`;
3527
- }
3528
- return item;
3529
- })].join('\n');
3530
- }
3531
- try {
3532
- const octokitPullsCreateParams = {
3533
- owner,
3534
- repo,
3535
- title: prTitle,
3536
- head: branch,
3537
- base: baseBranch,
3538
- body: prBody
3539
- };
3540
- require$$9.debugDir('inspect', {
3541
- octokitPullsCreateParams
3542
- });
3543
- return await octokit.pulls.create(octokitPullsCreateParams);
3544
- } catch (e) {
3545
- let message = `Failed to open pull request`;
3546
- const errors = e instanceof vendor.RequestError ? e.response?.data?.['errors'] : undefined;
3547
- if (Array.isArray(errors) && errors.length) {
3548
- const details = errors.map(d => `- ${d.message?.trim() ?? `${d.resource}.${d.field} (${d.code})`}`).join('\n');
3549
- message += `:\n${details}`;
3550
- }
3551
- require$$9.debugFn('error', message);
3552
- }
3553
- return null;
3554
- }
3555
- async function setGitRemoteGithubRepoUrl(owner, repo, token, cwd = process.cwd()) {
3556
- const {
3557
- host
3558
- } = new URL(constants.ENV.GITHUB_SERVER_URL);
3559
- const url = `https://x-access-token:${token}@${host}/${owner}/${repo}`;
3560
- const stdioIgnoreOptions = {
3561
- cwd,
3562
- stdio: require$$9.isDebug('stdio') ? 'inherit' : 'ignore'
3563
- };
3564
- const quotedCmd = `\`git remote set-url origin ${url}\``;
3565
- require$$9.debugFn('stdio', `spawn: ${quotedCmd}`);
3566
- try {
3567
- await spawn.spawn('git', ['remote', 'set-url', 'origin', url], stdioIgnoreOptions);
3568
- return true;
3569
- } catch (e) {
3570
- require$$9.debugFn('error', `caught: ${quotedCmd} failed`);
3571
- require$$9.debugDir('inspect', {
3572
- error: e
3573
- });
3574
- }
3575
- return false;
3576
- }
3577
3371
 
3578
3372
  function ciRepoInfo() {
3579
3373
  const {
@@ -3652,7 +3446,9 @@ async function coanaFix(fixConfig) {
3652
3446
  return sockSdkCResult;
3653
3447
  }
3654
3448
  const sockSdk = sockSdkCResult.data;
3655
- const supportedFilesCResult = await fetchSupportedScanFileNames();
3449
+ const supportedFilesCResult = await fetchSupportedScanFileNames({
3450
+ spinner
3451
+ });
3656
3452
  if (!supportedFilesCResult.ok) {
3657
3453
  return supportedFilesCResult;
3658
3454
  }
@@ -3731,7 +3527,7 @@ async function coanaFix(fixConfig) {
3731
3527
  };
3732
3528
  }
3733
3529
  require$$9.debugFn('notice', `fetch: ${ids.length} GHSA details for ${arrays.joinAnd(ids)}`);
3734
- const ghsaDetails = await fetchGhsaDetails(ids);
3530
+ const ghsaDetails = await utils.fetchGhsaDetails(ids);
3735
3531
  const scanBaseNames = new Set(scanFilepaths.map(p => path.basename(p)));
3736
3532
  require$$9.debugFn('notice', `found: ${ghsaDetails.size} GHSA details`);
3737
3533
  let count = 0;
@@ -3741,18 +3537,18 @@ async function coanaFix(fixConfig) {
3741
3537
  ghsaLoop: for (let i = 0, {
3742
3538
  length
3743
3539
  } = ids; i < length; i += 1) {
3744
- const id = ids[i];
3745
- require$$9.debugFn('notice', `check: ${id}`);
3540
+ const ghsaId = ids[i];
3541
+ require$$9.debugFn('notice', `check: ${ghsaId}`);
3746
3542
 
3747
3543
  // Apply fix for single GHSA ID.
3748
3544
  // eslint-disable-next-line no-await-in-loop
3749
- const fixCResult = await utils.spawnCoana(['compute-fixes-and-upgrade-purls', cwd, '--manifests-tar-hash', tarHash, '--apply-fixes-to', id, ...(fixConfig.rangeStyle ? ['--range-style', fixConfig.rangeStyle] : []), ...fixConfig.unknownFlags], fixConfig.orgSlug, {
3545
+ const fixCResult = await utils.spawnCoana(['compute-fixes-and-upgrade-purls', cwd, '--manifests-tar-hash', tarHash, '--apply-fixes-to', ghsaId, ...(fixConfig.rangeStyle ? ['--range-style', fixConfig.rangeStyle] : []), ...fixConfig.unknownFlags], fixConfig.orgSlug, {
3750
3546
  cwd,
3751
3547
  spinner,
3752
3548
  stdio: 'inherit'
3753
3549
  });
3754
3550
  if (!fixCResult.ok) {
3755
- logger.logger.error(`Update failed for ${id}: ${fixCResult.message || 'Unknown error'}`);
3551
+ logger.logger.error(`Update failed for ${ghsaId}: ${fixCResult.message || 'Unknown error'}`);
3756
3552
  continue ghsaLoop;
3757
3553
  }
3758
3554
 
@@ -3761,11 +3557,11 @@ async function coanaFix(fixConfig) {
3761
3557
  const unstagedCResult = await utils.gitUnstagedModifiedFiles(cwd);
3762
3558
  const modifiedFiles = unstagedCResult.ok ? unstagedCResult.data.filter(relPath => scanBaseNames.has(path.basename(relPath))) : [];
3763
3559
  if (!modifiedFiles.length) {
3764
- require$$9.debugFn('notice', `skip: no changes for ${id}`);
3560
+ require$$9.debugFn('notice', `skip: no changes for ${ghsaId}`);
3765
3561
  continue ghsaLoop;
3766
3562
  }
3767
3563
  overallFixed = true;
3768
- const branch = `socket/fix/${id}`;
3564
+ const branch = getSocketFixBranchName(ghsaId);
3769
3565
  try {
3770
3566
  // Check if branch already exists.
3771
3567
  // eslint-disable-next-line no-await-in-loop
@@ -3773,17 +3569,16 @@ async function coanaFix(fixConfig) {
3773
3569
  require$$9.debugFn('notice', `skip: remote branch "${branch}" exists`);
3774
3570
  continue ghsaLoop;
3775
3571
  }
3776
- require$$9.debugFn('notice', `pr: creating for ${id}`);
3777
- const details = ghsaDetails.get(id);
3778
- const summary = details?.summary;
3779
- require$$9.debugFn('notice', `ghsa: ${id} details ${details ? 'found' : 'missing'}`);
3572
+ require$$9.debugFn('notice', `pr: creating for ${ghsaId}`);
3573
+ const details = ghsaDetails.get(ghsaId);
3574
+ require$$9.debugFn('notice', `ghsa: ${ghsaId} details ${details ? 'found' : 'missing'}`);
3780
3575
  const pushed =
3781
3576
  // eslint-disable-next-line no-await-in-loop
3782
3577
  (await utils.gitCreateBranch(branch, cwd)) && (
3783
3578
  // eslint-disable-next-line no-await-in-loop
3784
3579
  await utils.gitCheckoutBranch(branch, cwd)) && (
3785
3580
  // eslint-disable-next-line no-await-in-loop
3786
- await utils.gitCommit(`fix: ${id}${summary ? ` - ${summary}` : ''}`, modifiedFiles, {
3581
+ await utils.gitCommit(getSocketFixCommitMessage(ghsaId, details), modifiedFiles, {
3787
3582
  cwd,
3788
3583
  email: fixEnv.gitEmail,
3789
3584
  user: fixEnv.gitUser
@@ -3791,7 +3586,7 @@ async function coanaFix(fixConfig) {
3791
3586
  // eslint-disable-next-line no-await-in-loop
3792
3587
  await utils.gitPushBranch(branch, cwd));
3793
3588
  if (!pushed) {
3794
- logger.logger.warn(`Push failed for ${id}, skipping PR creation.`);
3589
+ logger.logger.warn(`Push failed for ${ghsaId}, skipping PR creation.`);
3795
3590
  // eslint-disable-next-line no-await-in-loop
3796
3591
  await utils.gitResetAndClean(fixEnv.baseBranch, cwd);
3797
3592
  // eslint-disable-next-line no-await-in-loop
@@ -3803,12 +3598,12 @@ async function coanaFix(fixConfig) {
3803
3598
 
3804
3599
  // Set up git remote.
3805
3600
  // eslint-disable-next-line no-await-in-loop
3806
- await setGitRemoteGithubRepoUrl(fixEnv.repoInfo.owner, fixEnv.repoInfo.repo, fixEnv.githubToken, cwd);
3601
+ await utils.setGitRemoteGithubRepoUrl(fixEnv.repoInfo.owner, fixEnv.repoInfo.repo, fixEnv.githubToken, cwd);
3807
3602
 
3808
3603
  // eslint-disable-next-line no-await-in-loop
3809
- const prResponse = await openCoanaPr(fixEnv.repoInfo.owner, fixEnv.repoInfo.repo, branch,
3604
+ const prResponse = await openSocketFixPr(fixEnv.repoInfo.owner, fixEnv.repoInfo.repo, branch,
3810
3605
  // Single GHSA ID.
3811
- [id], {
3606
+ [ghsaId], {
3812
3607
  baseBranch: fixEnv.baseBranch,
3813
3608
  cwd,
3814
3609
  ghsaDetails
@@ -3818,7 +3613,7 @@ async function coanaFix(fixConfig) {
3818
3613
  data
3819
3614
  } = prResponse;
3820
3615
  const prRef = `PR #${data.number}`;
3821
- logger.logger.success(`Opened ${prRef} for ${id}.`);
3616
+ logger.logger.success(`Opened ${prRef} for ${ghsaId}.`);
3822
3617
  if (autoMerge) {
3823
3618
  logger.logger.indent();
3824
3619
  spinner?.indent();
@@ -3826,7 +3621,7 @@ async function coanaFix(fixConfig) {
3826
3621
  const {
3827
3622
  details,
3828
3623
  enabled
3829
- } = await enablePrAutoMerge(data);
3624
+ } = await utils.enablePrAutoMerge(data);
3830
3625
  if (enabled) {
3831
3626
  logger.logger.info(`Auto-merge enabled for ${prRef}.`);
3832
3627
  } else {
@@ -3844,7 +3639,7 @@ async function coanaFix(fixConfig) {
3844
3639
  // eslint-disable-next-line no-await-in-loop
3845
3640
  await utils.gitCheckoutBranch(fixEnv.baseBranch, cwd);
3846
3641
  } catch (e) {
3847
- logger.logger.warn(`Unexpected condition: Push failed for ${id}, skipping PR creation.`);
3642
+ logger.logger.warn(`Unexpected condition: Push failed for ${ghsaId}, skipping PR creation.`);
3848
3643
  require$$9.debugDir('inspect', {
3849
3644
  error: e
3850
3645
  });
@@ -3942,12 +3737,11 @@ async function run$I(argv, importMeta, {
3942
3737
  description: `Shorthand for --auto-merge --test`,
3943
3738
  hidden: true
3944
3739
  },
3945
- ghsa: {
3740
+ id: {
3946
3741
  type: 'string',
3947
3742
  default: [],
3948
- description: `Provide a list of ${vendor.terminalLinkExports('GHSA IDs', 'https://docs.github.com/en/code-security/security-advisories/working-with-global-security-advisories-from-the-github-advisory-database/about-the-github-advisory-database#about-ghsa-ids')} to compute fixes for, as either a comma separated value or as multiple flags.\nUse '--ghsa all' to lookup all GHSA IDs and compute fixes for them.`,
3949
- isMultiple: true,
3950
- hidden: true
3743
+ description: `Provide a list of ${vendor.terminalLinkExports('GHSA IDs', 'https://docs.github.com/en/code-security/security-advisories/working-with-global-security-advisories-from-the-github-advisory-database/about-the-github-advisory-database#about-ghsa-ids')} to compute fixes for, as either a comma separated value or as multiple flags`,
3744
+ isMultiple: true
3951
3745
  },
3952
3746
  limit: {
3953
3747
  type: 'number',
@@ -3999,12 +3793,14 @@ Available styles:
3999
3793
  test: {
4000
3794
  type: 'boolean',
4001
3795
  default: false,
4002
- description: 'Verify the fix by running unit tests'
3796
+ description: 'Verify the fix by running unit tests',
3797
+ hidden: true
4003
3798
  },
4004
3799
  testScript: {
4005
3800
  type: 'string',
4006
3801
  default: 'test',
4007
- description: "The test script to run for fix attempts (default 'test')"
3802
+ description: "The test script to run for fix attempts (default 'test')",
3803
+ hidden: true
4008
3804
  }
4009
3805
  },
4010
3806
  help: (command, config) => `
@@ -6847,8 +6643,8 @@ function updatePkgJsonField(editablePkgJson, field, value) {
6847
6643
  if (oldValue) {
6848
6644
  // The field already exists so we simply update the field value.
6849
6645
  if (field === PNPM) {
6850
- const isPnpmObj = require$$10.isObject(oldValue);
6851
- if (require$$10.hasKeys(value)) {
6646
+ const isPnpmObj = require$$11.isObject(oldValue);
6647
+ if (require$$11.hasKeys(value)) {
6852
6648
  editablePkgJson.update({
6853
6649
  [field]: {
6854
6650
  ...(isPnpmObj ? oldValue : {}),
@@ -6860,7 +6656,7 @@ function updatePkgJsonField(editablePkgJson, field, value) {
6860
6656
  });
6861
6657
  } else {
6862
6658
  // Properties with undefined values are deleted when saved as JSON.
6863
- editablePkgJson.update(require$$10.hasKeys(oldValue) ? {
6659
+ editablePkgJson.update(require$$11.hasKeys(oldValue) ? {
6864
6660
  [field]: {
6865
6661
  ...(isPnpmObj ? oldValue : {}),
6866
6662
  overrides: undefined
@@ -6872,7 +6668,7 @@ function updatePkgJsonField(editablePkgJson, field, value) {
6872
6668
  } else if (field === OVERRIDES || field === RESOLUTIONS) {
6873
6669
  // Properties with undefined values are deleted when saved as JSON.
6874
6670
  editablePkgJson.update({
6875
- [field]: require$$10.hasKeys(value) ? value : undefined
6671
+ [field]: require$$11.hasKeys(value) ? value : undefined
6876
6672
  });
6877
6673
  } else {
6878
6674
  editablePkgJson.update({
@@ -6881,7 +6677,7 @@ function updatePkgJsonField(editablePkgJson, field, value) {
6881
6677
  }
6882
6678
  return;
6883
6679
  }
6884
- if ((field === OVERRIDES || field === PNPM || field === RESOLUTIONS) && !require$$10.hasKeys(value)) {
6680
+ if ((field === OVERRIDES || field === PNPM || field === RESOLUTIONS) && !require$$11.hasKeys(value)) {
6885
6681
  return;
6886
6682
  }
6887
6683
  // Since the field doesn't exist we want to insert it into the package.json
@@ -7013,7 +6809,7 @@ async function addOverrides(pkgEnvDetails, pkgPath, options) {
7013
6809
  let loggedAddingText = false;
7014
6810
 
7015
6811
  // Chunk package names to process them in parallel 3 at a time.
7016
- await require$$11.pEach(manifestEntries, async ({
6812
+ await require$$12.pEach(manifestEntries, async ({
7017
6813
  1: data
7018
6814
  }) => {
7019
6815
  const {
@@ -7027,11 +6823,11 @@ async function addOverrides(pkgEnvDetails, pkgPath, options) {
7027
6823
  for (const {
7028
6824
  1: depObj
7029
6825
  } of depEntries) {
7030
- const sockSpec = require$$10.hasOwn(depObj, sockRegPkgName) ? depObj[sockRegPkgName] : undefined;
6826
+ const sockSpec = require$$11.hasOwn(depObj, sockRegPkgName) ? depObj[sockRegPkgName] : undefined;
7031
6827
  if (sockSpec) {
7032
6828
  depAliasMap.set(sockRegPkgName, sockSpec);
7033
6829
  }
7034
- const origSpec = require$$10.hasOwn(depObj, origPkgName) ? depObj[origPkgName] : undefined;
6830
+ const origSpec = require$$11.hasOwn(depObj, origPkgName) ? depObj[origPkgName] : undefined;
7035
6831
  if (origSpec) {
7036
6832
  let thisSpec = origSpec;
7037
6833
  // Add package aliases for direct dependencies to avoid npm EOVERRIDE
@@ -7067,11 +6863,11 @@ async function addOverrides(pkgEnvDetails, pkgPath, options) {
7067
6863
  npmExecPath
7068
6864
  });
7069
6865
  // Chunk package names to process them in parallel 3 at a time.
7070
- await require$$11.pEach(overridesDataObjects, async ({
6866
+ await require$$12.pEach(overridesDataObjects, async ({
7071
6867
  overrides,
7072
6868
  type
7073
6869
  }) => {
7074
- const overrideExists = require$$10.hasOwn(overrides, origPkgName);
6870
+ const overrideExists = require$$11.hasOwn(overrides, origPkgName);
7075
6871
  if (overrideExists || thingScanner(pkgEnvDetails, thingToScan, origPkgName, lockName)) {
7076
6872
  const oldSpec = overrideExists ? overrides[origPkgName] : undefined;
7077
6873
  const origDepAlias = depAliasMap.get(origPkgName);
@@ -7125,7 +6921,7 @@ async function addOverrides(pkgEnvDetails, pkgPath, options) {
7125
6921
  });
7126
6922
  if (isWorkspace) {
7127
6923
  // Chunk package names to process them in parallel 3 at a time.
7128
- await require$$11.pEach(workspacePkgJsonPaths, async workspacePkgJsonPath => {
6924
+ await require$$12.pEach(workspacePkgJsonPaths, async workspacePkgJsonPath => {
7129
6925
  const otherState = await addOverrides(pkgEnvDetails, path.dirname(workspacePkgJsonPath), {
7130
6926
  logger,
7131
6927
  pin,
@@ -7148,7 +6944,7 @@ async function addOverrides(pkgEnvDetails, pkgPath, options) {
7148
6944
  overrides,
7149
6945
  type
7150
6946
  } of overridesDataObjects) {
7151
- updateManifest(type, pkgEnvDetails.editablePkgJson, require$$10.toSortedObject(overrides));
6947
+ updateManifest(type, pkgEnvDetails.editablePkgJson, require$$11.toSortedObject(overrides));
7152
6948
  }
7153
6949
  }
7154
6950
  await pkgEnvDetails.editablePkgJson.save();
@@ -12266,8 +12062,14 @@ async function handleScanReach({
12266
12062
  reachabilityOptions,
12267
12063
  targets
12268
12064
  }) {
12065
+ const {
12066
+ spinner
12067
+ } = constants;
12068
+
12269
12069
  // Get supported file names
12270
- const supportedFilesCResult = await fetchSupportedScanFileNames();
12070
+ const supportedFilesCResult = await fetchSupportedScanFileNames({
12071
+ spinner
12072
+ });
12271
12073
  if (!supportedFilesCResult.ok) {
12272
12074
  await outputScanReach(supportedFilesCResult, {
12273
12075
  cwd,
@@ -12275,9 +12077,6 @@ async function handleScanReach({
12275
12077
  });
12276
12078
  return;
12277
12079
  }
12278
- const {
12279
- spinner
12280
- } = constants;
12281
12080
  spinner.start('Searching for local manifest files to include in reachability analysis...');
12282
12081
  const supportedFiles = supportedFilesCResult.data;
12283
12082
  const packagePaths = await utils.getPackageFilesForScan(targets, supportedFiles, {
@@ -14203,5 +14002,5 @@ void (async () => {
14203
14002
  await utils.captureException(e);
14204
14003
  }
14205
14004
  })();
14206
- //# debugId=2d71faa1-844b-480a-a713-c572fd14e2f4
14005
+ //# debugId=11a3cbfe-6b5a-4bf7-afd9-6885b9deef59
14207
14006
  //# sourceMappingURL=cli.js.map