@socketsecurity/cli 0.14.42 → 0.14.44

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 (44) hide show
  1. package/README.md +16 -38
  2. package/bin/cli.js +17 -7
  3. package/bin/npm-cli.js +1 -1
  4. package/bin/npx-cli.js +1 -1
  5. package/dist/constants.d.ts +121 -11
  6. package/dist/constants.js +91 -10
  7. package/dist/constants.js.map +1 -0
  8. package/dist/init.gradle +250 -0
  9. package/dist/module-sync/cli.js +6115 -3836
  10. package/dist/module-sync/cli.js.map +1 -0
  11. package/dist/module-sync/edge.d.ts +66 -0
  12. package/dist/module-sync/errors.d.ts +6 -1
  13. package/dist/module-sync/index.d.ts +192 -0
  14. package/dist/module-sync/index.js +1879 -0
  15. package/dist/module-sync/index.js.map +1 -0
  16. package/dist/module-sync/logging.d.ts +3 -3
  17. package/dist/module-sync/node.d.ts +84 -0
  18. package/dist/module-sync/npm-injection.js +7 -1495
  19. package/dist/module-sync/npm-injection.js.map +1 -0
  20. package/dist/module-sync/npm-paths.d.ts +3 -2
  21. package/dist/module-sync/npm-paths.js +91 -42
  22. package/dist/module-sync/npm-paths.js.map +1 -0
  23. package/dist/module-sync/npm.d.ts +24 -0
  24. package/dist/module-sync/npm.js +99 -0
  25. package/dist/module-sync/npm.js.map +1 -0
  26. package/dist/module-sync/path-resolve.d.ts +1 -1
  27. package/dist/module-sync/proc-log.d.ts +3 -0
  28. package/dist/module-sync/reify.d.ts +1018 -0
  29. package/dist/module-sync/sdk.d.ts +5 -0
  30. package/dist/module-sync/settings.d.ts +5 -4
  31. package/dist/module-sync/shadow-bin.d.ts +1 -1
  32. package/dist/module-sync/shadow-bin.js +33 -12
  33. package/dist/module-sync/shadow-bin.js.map +1 -0
  34. package/dist/module-sync/types.d.ts +45 -0
  35. package/dist/require/cli.js +6114 -3836
  36. package/dist/require/constants.js +1 -1
  37. package/dist/require/index.js +3 -0
  38. package/dist/require/npm.js +3 -0
  39. package/dist/require/vendor.js +2336 -6
  40. package/package.json +69 -42
  41. package/dist/constants.d.ts.map +0 -1
  42. package/dist/module-sync/socket-url.d.ts +0 -40
  43. package/dist/module-sync/socket-url.js +0 -301
  44. package/dist/require/socket-url.js +0 -3
@@ -0,0 +1,5 @@
1
+ import { SocketSdk } from '@socketsecurity/sdk';
2
+ declare function getDefaultToken(): string | undefined;
3
+ declare function getPublicToken(): string;
4
+ declare function setupSdk(apiToken?: string | undefined, apiBaseUrl?: string | undefined, proxy?: string | undefined): Promise<SocketSdk>;
5
+ export { getDefaultToken, getPublicToken, setupSdk };
@@ -1,9 +1,10 @@
1
1
  import config from '@socketsecurity/config';
2
2
  interface Settings {
3
- apiKey?: string | null;
4
- enforcedOrgs?: string[] | null;
5
- apiBaseUrl?: string | null;
6
- apiProxy?: string | null;
3
+ apiBaseUrl?: string | null | undefined;
4
+ apiKey?: string | null | undefined;
5
+ apiProxy?: string | null | undefined;
6
+ enforcedOrgs?: string[] | null | undefined;
7
+ apiToken?: string | null | undefined;
7
8
  }
8
9
  declare function findSocketYmlSync(): {
9
10
  path: string;
@@ -1,2 +1,2 @@
1
- declare function shadowBin(binName: 'npm' | 'npx', binArgs?: string[]): Promise<void>;
1
+ declare function shadowBin(binName: 'npm' | 'npx', args?: string[]): Promise<void>;
2
2
  export { shadowBin as default };
@@ -9,14 +9,16 @@ function _socketInterop(e) {
9
9
  return c ? e.default : e
10
10
  }
11
11
 
12
- var path = require('node:path');
13
12
  var process = require('node:process');
14
13
  var spawn = _socketInterop(require('@npmcli/promise-spawn'));
14
+ var path = require('node:path');
15
15
  var cmdShim = _socketInterop(require('cmd-shim'));
16
16
  var npmPaths = require('./npm-paths.js');
17
17
  var constants = require('./constants.js');
18
+ var npm = require('./npm.js');
18
19
 
19
20
  const {
21
+ CLI,
20
22
  NPX
21
23
  } = constants;
22
24
  async function installLinks(realBinPath, binName) {
@@ -37,7 +39,7 @@ async function installLinks(realBinPath, binName) {
37
39
  if (WIN32) {
38
40
  await cmdShim(
39
41
  // Lazily access constants.rootDistPath.
40
- path.join(constants.rootDistPath, `${binName}-cli.js`), path.join(realBinPath, binName));
42
+ path.join(constants.rootDistPath, `${binName}-${CLI}.js`), path.join(realBinPath, binName));
41
43
  }
42
44
  process.env['PATH'] = `${realBinPath}${path.delimiter}${process.env['PATH']}`;
43
45
  }
@@ -45,25 +47,37 @@ async function installLinks(realBinPath, binName) {
45
47
  }
46
48
 
47
49
  const {
48
- NPM,
50
+ SOCKET_CLI_SAFE_WRAPPER,
51
+ SOCKET_CLI_SENTRY_BUILD,
52
+ SOCKET_IPC_HANDSHAKE,
49
53
  abortSignal
50
54
  } = constants;
51
- async function shadowBin(binName, binArgs = process.argv.slice(2)) {
55
+ async function shadowBin(binName, args = process.argv.slice(2)) {
52
56
  process.exitCode = 1;
57
+ const terminatorPos = args.indexOf('--');
58
+ const binArgs = (terminatorPos === -1 ? args : args.slice(0, terminatorPos)).filter(a => !npm.isProgressFlag(a));
59
+ const otherArgs = terminatorPos === -1 ? [] : args.slice(terminatorPos);
53
60
  const spawnPromise = spawn(
54
61
  // Lazily access constants.execPath.
55
62
  constants.execPath, [
56
63
  // Lazily access constants.nodeNoWarningsFlags.
57
- ...constants.nodeNoWarningsFlags, '--require',
58
- // Lazily access constants.distPath.
59
- path.join(constants.distPath, 'npm-injection.js'),
64
+ ...constants.nodeNoWarningsFlags,
65
+ // Lazily access constants.ENV[SOCKET_CLI_SENTRY_BUILD].
66
+ ...(constants.ENV[SOCKET_CLI_SENTRY_BUILD] ? ['--require',
67
+ // Lazily access constants.instrumentWithSentryPath.
68
+ constants.instrumentWithSentryPath] : []), '--require',
69
+ // Lazily access constants.npmInjectionPath.
70
+ constants.npmInjectionPath,
60
71
  // Lazily access constants.shadowBinPath.
61
- await installLinks(constants.shadowBinPath, binName), ...(binName === NPM && binArgs.includes('install') ? [
62
- // Add the `--quiet` and `--no-progress` flags to fix input being swallowed
63
- // by the spinner when running the command with recent versions of npm.
64
- ...binArgs.filter(a => a !== '--progress' && a !== '--no-progress'), '--no-progress', ...(binArgs.includes('-q') || binArgs.includes('--quiet') || binArgs.includes('-s') || binArgs.includes('--silent') ? [] : ['--quiet'])] : binArgs)], {
72
+ await installLinks(constants.shadowBinPath, binName),
73
+ // Add `--no-progress` and `--quiet` flags to fix input being swallowed by
74
+ // the spinner when running the command with recent versions of npm.
75
+ '--no-progress',
76
+ // Add the '--quiet' flag if a loglevel flag is not provided.
77
+ ...(binArgs.some(npm.isLoglevelFlag) ? [] : ['--quiet']), ...binArgs, ...otherArgs], {
65
78
  signal: abortSignal,
66
- stdio: 'inherit'
79
+ // 'inherit' + 'ipc'
80
+ stdio: [0, 1, 2, 'ipc']
67
81
  });
68
82
  // See https://nodejs.org/api/all.html#all_child_process_event-exit.
69
83
  spawnPromise.process.on('exit', (code, signalName) => {
@@ -76,7 +90,14 @@ async function shadowBin(binName, binArgs = process.argv.slice(2)) {
76
90
  process.exit(code);
77
91
  }
78
92
  });
93
+ spawnPromise.process.send({
94
+ [SOCKET_IPC_HANDSHAKE]: {
95
+ [SOCKET_CLI_SAFE_WRAPPER]: true
96
+ }
97
+ });
79
98
  await spawnPromise;
80
99
  }
81
100
 
82
101
  module.exports = shadowBin;
102
+ //# debugId=f578bd6f-82f7-4281-b443-42099e9e8c53
103
+ //# sourceMappingURL=shadow-bin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shadow-bin.js","sources":["../../src/shadow/link.ts","../../src/shadow/shadow-bin.ts"],"sourcesContent":["import path from 'node:path'\nimport process from 'node:process'\n\nimport cmdShim from 'cmd-shim'\n\nimport {\n getNpmBinPath,\n getNpxBinPath,\n isNpmBinPathShadowed,\n isNpxBinPathShadowed\n} from './npm-paths'\nimport constants from '../constants'\n\nconst { CLI, NPX } = constants\n\nexport async function installLinks(\n realBinPath: string,\n binName: 'npm' | 'npx'\n): Promise<string> {\n const isNpx = binName === NPX\n // Find package manager being shadowed by this process.\n const binPath = isNpx ? getNpxBinPath() : getNpmBinPath()\n // Lazily access constants.WIN32.\n const { WIN32 } = constants\n // TODO: Is this early exit needed?\n if (WIN32 && binPath) {\n return binPath\n }\n const shadowed = isNpx ? isNpxBinPathShadowed() : isNpmBinPathShadowed()\n // Move our bin directory to front of PATH so its found first.\n if (!shadowed) {\n if (WIN32) {\n await cmdShim(\n // Lazily access constants.rootDistPath.\n path.join(constants.rootDistPath, `${binName}-${CLI}.js`),\n path.join(realBinPath, binName)\n )\n }\n process.env['PATH'] =\n `${realBinPath}${path.delimiter}${process.env['PATH']}`\n }\n return binPath\n}\n","import process from 'node:process'\n\nimport spawn from '@npmcli/promise-spawn'\n\nimport { installLinks } from './link'\nimport constants from '../constants'\nimport { isLoglevelFlag, isProgressFlag } from '../utils/npm'\n\nconst {\n SOCKET_CLI_SAFE_WRAPPER,\n SOCKET_CLI_SENTRY_BUILD,\n SOCKET_IPC_HANDSHAKE,\n abortSignal\n} = constants\n\nexport default async function shadowBin(\n binName: 'npm' | 'npx',\n args = process.argv.slice(2)\n) {\n process.exitCode = 1\n const terminatorPos = args.indexOf('--')\n const binArgs = (\n terminatorPos === -1 ? args : args.slice(0, terminatorPos)\n ).filter(a => !isProgressFlag(a))\n const otherArgs = terminatorPos === -1 ? [] : args.slice(terminatorPos)\n const spawnPromise = spawn(\n // Lazily access constants.execPath.\n constants.execPath,\n [\n // Lazily access constants.nodeNoWarningsFlags.\n ...constants.nodeNoWarningsFlags,\n // Lazily access constants.ENV[SOCKET_CLI_SENTRY_BUILD].\n ...(constants.ENV[SOCKET_CLI_SENTRY_BUILD]\n ? [\n '--require',\n // Lazily access constants.instrumentWithSentryPath.\n constants.instrumentWithSentryPath\n ]\n : []),\n '--require',\n // Lazily access constants.npmInjectionPath.\n constants.npmInjectionPath,\n // Lazily access constants.shadowBinPath.\n await installLinks(constants.shadowBinPath, binName),\n // Add `--no-progress` and `--quiet` flags to fix input being swallowed by\n // the spinner when running the command with recent versions of npm.\n '--no-progress',\n // Add the '--quiet' flag if a loglevel flag is not provided.\n ...(binArgs.some(isLoglevelFlag) ? [] : ['--quiet']),\n ...binArgs,\n ...otherArgs\n ],\n {\n signal: abortSignal,\n // 'inherit' + 'ipc'\n stdio: [0, 1, 2, 'ipc']\n }\n )\n // See https://nodejs.org/api/all.html#all_child_process_event-exit.\n spawnPromise.process.on('exit', (code, signalName) => {\n if (abortSignal.aborted) {\n return\n }\n if (signalName) {\n process.kill(process.pid, signalName)\n } else if (code !== null) {\n process.exit(code)\n }\n })\n spawnPromise.process.send({\n [SOCKET_IPC_HANDSHAKE]: {\n [SOCKET_CLI_SAFE_WRAPPER]: true\n }\n })\n await spawnPromise\n}\n"],"names":["NPX","WIN32","process","abortSignal","constants","signal","spawnPromise"],"mappings":";;;;;;;;;;;;;;;;;;;AAaA;;AAAaA;AAAI;AAEV;AAIL;AACA;;AAEA;;AACQC;AAAM;AACd;;AAEE;AACF;;AAEA;;AAEE;AACE;AACE;;AAIJ;AACAC;AAEF;AACA;AACF;;AClCA;;;;AAIEC;AACF;AAEe;;AAKb;AACA;AAGA;;AAEE;;AAGE;;AAEA;;AAIM;AACAC;AAIN;AACAA;AACA;AACA;AACA;AACA;;AAEA;;AAMAC;AACA;;AAEF;AAEF;;;AAGI;AACF;AACA;;AAEA;AACEH;AACF;AACF;AACAI;AACE;AACE;AACF;AACF;AACA;AACF;;","debugId":"f578bd6f-82f7-4281-b443-42099e9e8c53"}
@@ -0,0 +1,45 @@
1
+ /// <reference types="npmcli__arborist" />
2
+ import { SafeNode } from "./node.js";
3
+ import { ReifyOptions } from '@npmcli/arborist';
4
+ import { Options as ArboristOptions } from "@npmcli/arborist";
5
+ import { Advisory as BaseAdvisory } from "@npmcli/arborist";
6
+ import { Arborist as BaseArborist } from "@npmcli/arborist";
7
+ import { AuditReport as BaseAuditReport } from "@npmcli/arborist";
8
+ import { Diff as BaseDiff } from "@npmcli/arborist";
9
+ type ArboristClass = ArboristInstance & {
10
+ new (...args: any): ArboristInstance;
11
+ };
12
+ type ArboristInstance = Omit<typeof BaseArborist, 'actualTree' | 'auditReport' | 'diff' | 'idealTree' | 'reify'> & {
13
+ auditReport?: AuditReportInstance | null | undefined;
14
+ actualTree?: SafeNode | null | undefined;
15
+ diff: Diff | null;
16
+ idealTree?: SafeNode | null | undefined;
17
+ reify(options?: ArboristReifyOptions): Promise<SafeNode>;
18
+ };
19
+ type ArboristReifyOptions = ReifyOptions & ArboristOptions;
20
+ type AuditReportInstance = Omit<BaseAuditReport, 'report'> & {
21
+ report: {
22
+ [dependency: string]: AuditAdvisory[];
23
+ };
24
+ };
25
+ type AuditAdvisory = Omit<BaseAdvisory, 'id'> & {
26
+ id: number;
27
+ cwe: string[];
28
+ cvss: {
29
+ score: number;
30
+ vectorString: string;
31
+ };
32
+ vulnerable_versions: string;
33
+ };
34
+ type Diff = Omit<BaseDiff, 'actual' | 'children' | 'filterSet' | 'ideal' | 'leaves' | 'removed' | 'shrinkwrapInflated' | 'unchanged'> & {
35
+ actual: SafeNode;
36
+ children: Diff[];
37
+ filterSet: Set<SafeNode>;
38
+ ideal: SafeNode;
39
+ leaves: SafeNode[];
40
+ parent: Diff | null;
41
+ removed: SafeNode[];
42
+ shrinkwrapInflated: Set<SafeNode>;
43
+ unchanged: SafeNode[];
44
+ };
45
+ export { ArboristClass, ArboristInstance, ArboristReifyOptions, AuditReportInstance, AuditAdvisory, Diff };