@socketsecurity/cli 0.11.0 → 0.12.0

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 (82) hide show
  1. package/README.md +22 -22
  2. package/bin/npm +2 -0
  3. package/bin/npx +2 -0
  4. package/dist/cli.d.ts +3 -0
  5. package/dist/cli.d.ts.map +1 -0
  6. package/dist/cli.js +3928 -0
  7. package/dist/errors.d.ts +7 -0
  8. package/dist/link.d.ts +2 -0
  9. package/dist/link.js +45 -0
  10. package/dist/npm-cli.d.ts +2 -0
  11. package/dist/npm-cli.js +84 -0
  12. package/dist/npm-injection.d.ts +1 -0
  13. package/dist/npm-injection.js +913 -0
  14. package/dist/npm-injection2.d.ts +25 -0
  15. package/dist/npm-injection2.js +899 -0
  16. package/dist/npx-cli.d.ts +2 -0
  17. package/dist/npx-cli.js +60 -0
  18. package/dist/path-resolve.d.ts +12 -0
  19. package/dist/path-resolve.js +139 -0
  20. package/dist/sdk.d.ts +27 -0
  21. package/dist/sdk.js +224 -0
  22. package/dist/settings.d.ts +9 -0
  23. package/dist/type-helpers.d.ts +3 -0
  24. package/dist/vendor.js +25421 -0
  25. package/package.json +108 -52
  26. package/{lib/shadow/translations.json → translations.json} +20 -20
  27. package/cli.js +0 -72
  28. package/lib/commands/audit-log/index.js +0 -162
  29. package/lib/commands/cdxgen/index.js +0 -211
  30. package/lib/commands/dependencies/index.js +0 -150
  31. package/lib/commands/index.js +0 -15
  32. package/lib/commands/info/index.js +0 -287
  33. package/lib/commands/login/index.js +0 -170
  34. package/lib/commands/logout/index.js +0 -35
  35. package/lib/commands/npm/index.js +0 -27
  36. package/lib/commands/npx/index.js +0 -22
  37. package/lib/commands/organizations/index.js +0 -81
  38. package/lib/commands/raw-npm/index.js +0 -59
  39. package/lib/commands/raw-npx/index.js +0 -59
  40. package/lib/commands/report/create.js +0 -251
  41. package/lib/commands/report/index.js +0 -24
  42. package/lib/commands/report/view.js +0 -176
  43. package/lib/commands/repos/create.js +0 -166
  44. package/lib/commands/repos/delete.js +0 -93
  45. package/lib/commands/repos/index.js +0 -30
  46. package/lib/commands/repos/list.js +0 -170
  47. package/lib/commands/repos/update.js +0 -166
  48. package/lib/commands/repos/view.js +0 -128
  49. package/lib/commands/scan/create.js +0 -245
  50. package/lib/commands/scan/delete.js +0 -112
  51. package/lib/commands/scan/index.js +0 -30
  52. package/lib/commands/scan/list.js +0 -192
  53. package/lib/commands/scan/metadata.js +0 -113
  54. package/lib/commands/scan/stream.js +0 -115
  55. package/lib/commands/wrapper/index.js +0 -199
  56. package/lib/flags/command.js +0 -14
  57. package/lib/flags/index.js +0 -3
  58. package/lib/flags/output.js +0 -16
  59. package/lib/flags/validation.js +0 -14
  60. package/lib/shadow/bin/npm +0 -2
  61. package/lib/shadow/bin/npx +0 -2
  62. package/lib/shadow/link.cjs +0 -50
  63. package/lib/shadow/npm-cli.cjs +0 -27
  64. package/lib/shadow/npm-injection.cjs +0 -649
  65. package/lib/shadow/npx-cli.cjs +0 -27
  66. package/lib/shadow/package.json +0 -3
  67. package/lib/shadow/tty-server.cjs +0 -222
  68. package/lib/shadow/update-notifier.mjs +0 -3
  69. package/lib/utils/api-helpers.js +0 -42
  70. package/lib/utils/chalk-markdown.js +0 -125
  71. package/lib/utils/errors.js +0 -14
  72. package/lib/utils/flags.js +0 -27
  73. package/lib/utils/format-issues.js +0 -99
  74. package/lib/utils/formatting.js +0 -47
  75. package/lib/utils/issue-rules.cjs +0 -180
  76. package/lib/utils/meow-with-subcommands.js +0 -87
  77. package/lib/utils/misc.js +0 -61
  78. package/lib/utils/path-resolve.js +0 -204
  79. package/lib/utils/sdk.js +0 -99
  80. package/lib/utils/settings.js +0 -69
  81. package/lib/utils/type-helpers.cjs +0 -13
  82. package/lib/utils/update-notifier.js +0 -18
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,60 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ var vendor = require('./vendor.js');
5
+ var require$$0 = require('node:child_process');
6
+ var require$$0$1 = require('node:fs');
7
+ var require$$1 = require('node:path');
8
+ var link = require('./link.js');
9
+
10
+ var npxCli$1 = {};
11
+
12
+ var npxCli = {};
13
+
14
+ var _nodeChild_process = require$$0;
15
+ var _nodeFs = require$$0$1;
16
+ var _nodePath = require$$1;
17
+ var _link = link.link;
18
+ const realFilename = (0, _nodeFs.realpathSync)(__filename);
19
+ const realDirname = _nodePath.dirname(realFilename);
20
+ const npxPath = (0, _link.installLinks)(_nodePath.join(realDirname, 'bin'), 'npx');
21
+ const injectionPath = _nodePath.join(realDirname, 'npm-injection.js');
22
+ process.exitCode = 1;
23
+ (0, _nodeChild_process.spawn)(process.execPath, ['--require', injectionPath, npxPath, ...process.argv.slice(2)], {
24
+ stdio: 'inherit'
25
+ }).on('exit', (code, signal) => {
26
+ if (signal) {
27
+ process.kill(process.pid, signal);
28
+ } else if (code !== null) {
29
+ process.exit(code);
30
+ }
31
+ });
32
+
33
+ (function (exports) {
34
+
35
+ var _interopRequireWildcard = vendor.interopRequireWildcard.default;
36
+ Object.defineProperty(exports, "__esModule", {
37
+ value: true
38
+ });
39
+ var _exportNames = {};
40
+ Object.defineProperty(exports, "default", {
41
+ enumerable: true,
42
+ get: function () {
43
+ return _npxCli.default;
44
+ }
45
+ });
46
+ var _npxCli = _interopRequireWildcard(npxCli, true);
47
+ Object.keys(_npxCli).forEach(function (key) {
48
+ if (key === "default" || key === "__esModule") return;
49
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
50
+ if (key in exports && exports[key] === _npxCli[key]) return;
51
+ Object.defineProperty(exports, key, {
52
+ enumerable: true,
53
+ get: function () {
54
+ return _npxCli[key];
55
+ }
56
+ });
57
+ });
58
+ } (npxCli$1));
59
+
60
+ module.exports = npxCli$1;
@@ -0,0 +1,12 @@
1
+ /// <reference types="node" />
2
+ import { SocketYml } from '@socketsecurity/config';
3
+ import { SocketSdkReturnType } from '@socketsecurity/sdk';
4
+ declare function directories(): ("node_modules" | ".git" | ".log" | ".nyc_output" | ".sass-cache" | ".yarn" | "bower_components" | "coverage" | "flow-typed")[];
5
+ declare function directoryPatterns(): string[];
6
+ declare function arrayUnique<T>(array: T[]): T[];
7
+ declare function getPackageFiles(cwd: string, inputPaths: string[], config: SocketYml | undefined, supportedFiles: SocketSdkReturnType<'getReportSupportedFiles'>['data'], debugLog: typeof console.error): Promise<string[]>;
8
+ declare function getPackageFilesFullScans(cwd: string, inputPaths: string[], supportedFiles: SocketSdkReturnType<'getReportSupportedFiles'>['data'], debugLog: typeof console.error): Promise<string[]>;
9
+ declare function mapGlobResultToFiles(entries: string[], supportedFiles: SocketSdkReturnType<'getReportSupportedFiles'>['data']): Promise<string[]>;
10
+ declare function mapGlobEntryToFiles(entry: string, supportedFiles: SocketSdkReturnType<'getReportSupportedFiles'>['data']): Promise<string[]>;
11
+ declare function findRoot(filepath: string): string | undefined;
12
+ export { directories, directoryPatterns, arrayUnique, getPackageFiles, getPackageFilesFullScans, mapGlobResultToFiles, mapGlobEntryToFiles, findRoot };
@@ -0,0 +1,139 @@
1
+ 'use strict';
2
+
3
+ var require$$1 = require('node:fs/promises');
4
+ var require$$1$1 = require('node:path');
5
+ var vendor = require('./vendor.js');
6
+ var require$$5 = require('ignore');
7
+
8
+ var pathResolve = {};
9
+
10
+ var arrays = {};
11
+
12
+ Object.defineProperty(arrays, "__esModule", {
13
+ value: true
14
+ });
15
+ arrays.arrayUnique = arrayUnique;
16
+ function arrayUnique(array) {
17
+ return [...new Set(array)];
18
+ }
19
+
20
+ var ignoreByDefault = {};
21
+
22
+ Object.defineProperty(ignoreByDefault, "__esModule", {
23
+ value: true
24
+ });
25
+ ignoreByDefault.directories = directories;
26
+ ignoreByDefault.directoryPatterns = directoryPatterns;
27
+ const ignoredDirs = [
28
+ // Taken from ignore-by-default:
29
+ // https://github.com/novemberborn/ignore-by-default/blob/v2.1.0/index.js
30
+ '.git',
31
+ // Git repository files, see <https://git-scm.com/>
32
+ '.log',
33
+ // Log files emitted by tools such as `tsserver`, see <https://github.com/Microsoft/TypeScript/wiki/Standalone-Server-%28tsserver%29>
34
+ '.nyc_output',
35
+ // Temporary directory where nyc stores coverage data, see <https://github.com/bcoe/nyc>
36
+ '.sass-cache',
37
+ // Cache folder for node-sass, see <https://github.com/sass/node-sass>
38
+ '.yarn',
39
+ // Where node modules are installed when using Yarn, see <https://yarnpkg.com/>
40
+ 'bower_components',
41
+ // Where Bower packages are installed, see <http://bower.io/>
42
+ 'coverage',
43
+ // Standard output directory for code coverage reports, see <https://github.com/gotwarlost/istanbul>
44
+ 'node_modules',
45
+ // Where Node modules are installed, see <https://nodejs.org/>
46
+ // Taken from globby:
47
+ // https://github.com/sindresorhus/globby/blob/v14.0.2/ignore.js#L11-L16
48
+ 'flow-typed'];
49
+ const ignoredDirPatterns = ignoredDirs.map(i => `**/${i}`);
50
+ function directories() {
51
+ return [...ignoredDirs];
52
+ }
53
+ function directoryPatterns() {
54
+ return [...ignoredDirPatterns];
55
+ }
56
+
57
+ Object.defineProperty(pathResolve, "__esModule", {
58
+ value: true
59
+ });
60
+ pathResolve.findRoot = findRoot;
61
+ pathResolve.getPackageFiles = getPackageFiles;
62
+ pathResolve.getPackageFilesFullScans = getPackageFilesFullScans;
63
+ pathResolve.mapGlobEntryToFiles = mapGlobEntryToFiles;
64
+ pathResolve.mapGlobResultToFiles = mapGlobResultToFiles;
65
+ var _promises = require$$1;
66
+ var _nodePath = require$$1$1;
67
+ var _globby = vendor.globby;
68
+ var _ignore = require$$5;
69
+ var _arrays = arrays;
70
+ var _ignoreByDefault = ignoreByDefault;
71
+ const BASE_GLOBBY_OPTS = {
72
+ absolute: true,
73
+ expandDirectories: false,
74
+ gitignore: true,
75
+ ignore: (0, _ignoreByDefault.directoryPatterns)(),
76
+ markDirectories: true,
77
+ onlyFiles: true,
78
+ unique: true
79
+ };
80
+ async function getPackageFiles(cwd, inputPaths, config, supportedFiles, debugLog) {
81
+ debugLog(`Globbed resolving ${inputPaths.length} paths:`, inputPaths);
82
+
83
+ // TODO: Does not support `~/` paths
84
+ const entries = await (0, _globby.globby)(inputPaths, {
85
+ ...BASE_GLOBBY_OPTS,
86
+ cwd,
87
+ onlyFiles: false
88
+ });
89
+ debugLog(`Globbed resolved ${inputPaths.length} paths to ${entries.length} paths:`, entries);
90
+ const packageFiles = await mapGlobResultToFiles(entries, supportedFiles);
91
+ debugLog(`Mapped ${entries.length} entries to ${packageFiles.length} files:`, packageFiles);
92
+ const includedPackageFiles = config?.projectIgnorePaths?.length ? _ignore().add(config.projectIgnorePaths).filter(packageFiles.map(item => _nodePath.relative(cwd, item))).map(item => _nodePath.resolve(cwd, item)) : packageFiles;
93
+ return includedPackageFiles;
94
+ }
95
+ async function getPackageFilesFullScans(cwd, inputPaths, supportedFiles, debugLog) {
96
+ debugLog(`Globbed resolving ${inputPaths.length} paths:`, inputPaths);
97
+
98
+ // TODO: Does not support `~/` paths
99
+ const entries = await (0, _globby.globby)(inputPaths, {
100
+ ...BASE_GLOBBY_OPTS,
101
+ cwd,
102
+ onlyFiles: false
103
+ });
104
+ debugLog(`Globbed resolved ${inputPaths.length} paths to ${entries.length} paths:`, entries);
105
+ const packageFiles = await mapGlobResultToFiles(entries, supportedFiles);
106
+ debugLog(`Mapped ${entries.length} entries to ${packageFiles.length} files:`, packageFiles);
107
+ return packageFiles;
108
+ }
109
+ async function mapGlobResultToFiles(entries, supportedFiles) {
110
+ const packageFiles = await Promise.all(entries.map(entry => mapGlobEntryToFiles(entry, supportedFiles)));
111
+ return (0, _arrays.arrayUnique)(packageFiles.flat());
112
+ }
113
+ async function mapGlobEntryToFiles(entry, supportedFiles) {
114
+ const jsSupported = supportedFiles['npm'] ?? {};
115
+ const jsLockFilePatterns = Object.values(jsSupported).map(p => `**/${p.pattern}`);
116
+ const pyFilePatterns = Object.values(supportedFiles['pypi'] ?? {}).map(p => `**/${p.pattern}`);
117
+ const goSupported = supportedFiles['golang'] ?? {};
118
+ const goSupplementalPatterns = Object.values(goSupported).map(p => `**/${p.pattern}`);
119
+ return await (0, _globby.globby)([...jsLockFilePatterns, ...pyFilePatterns, ...goSupplementalPatterns], {
120
+ ...BASE_GLOBBY_OPTS,
121
+ onlyFiles: true,
122
+ cwd: _nodePath.resolve((await (0, _promises.stat)(entry)).isDirectory() ? entry : _nodePath.dirname(entry))
123
+ });
124
+ }
125
+ function findRoot(filepath) {
126
+ let curPath = filepath;
127
+ while (true) {
128
+ if (_nodePath.basename(curPath) === 'npm') {
129
+ return curPath;
130
+ }
131
+ const parent = _nodePath.dirname(curPath);
132
+ if (parent === curPath) {
133
+ return undefined;
134
+ }
135
+ curPath = parent;
136
+ }
137
+ }
138
+
139
+ exports.pathResolve = pathResolve;
package/dist/sdk.d.ts ADDED
@@ -0,0 +1,27 @@
1
+ import { SocketSdk } from '@socketsecurity/sdk';
2
+ // From the 'log-symbols' module
3
+ declare const logSymbols: {
4
+ info: string;
5
+ success: string;
6
+ warning: string;
7
+ error: string;
8
+ };
9
+ declare class ChalkOrMarkdown {
10
+ useMarkdown: boolean;
11
+ constructor(useMarkdown: boolean);
12
+ header(text: string, level?: number): string;
13
+ bold(text: string): string;
14
+ italic(text: string): string;
15
+ hyperlink(text: string, url: string | undefined, { fallback, fallbackToUrl }?: {
16
+ fallback?: boolean;
17
+ fallbackToUrl?: boolean;
18
+ }): string;
19
+ list(items: string[]): string;
20
+ get logSymbols(): typeof logSymbols;
21
+ indent(text: string, level?: number): string;
22
+ json(value: unknown): string;
23
+ }
24
+ declare const FREE_API_KEY = "sktsec_t_--RAN5U4ivauy4w37-6aoKyYPDt5ZbaT5JBVMqiwKo_api";
25
+ declare function getDefaultKey(): string | undefined;
26
+ declare function setupSdk(apiKey?: string | undefined, apiBaseUrl?: string | undefined, proxy?: string | undefined): Promise<SocketSdk>;
27
+ export { logSymbols, ChalkOrMarkdown, FREE_API_KEY, getDefaultKey, setupSdk };
package/dist/sdk.js ADDED
@@ -0,0 +1,224 @@
1
+ 'use strict';
2
+
3
+ var vendor = require('./vendor.js');
4
+ var require$$1$1 = require('node:fs/promises');
5
+ var require$$1 = require('node:path');
6
+ var require$$1$2 = require('@inquirer/prompts');
7
+ var require$$4 = require('@socketsecurity/sdk');
8
+ var require$$5 = require('hpagent');
9
+ var require$$0$1 = require('node:fs');
10
+ var require$$0 = require('node:os');
11
+
12
+ var errors = {};
13
+
14
+ Object.defineProperty(errors, "__esModule", {
15
+ value: true
16
+ });
17
+ errors.InputError = errors.AuthError = void 0;
18
+ class AuthError extends Error {}
19
+ errors.AuthError = AuthError;
20
+ class InputError extends Error {
21
+ constructor(message, body) {
22
+ super(message);
23
+ this.body = body;
24
+ }
25
+ }
26
+ errors.InputError = InputError;
27
+
28
+ var chalkMarkdown = {};
29
+
30
+ var _interopRequireDefault$2 = vendor.interopRequireDefault.default;
31
+ Object.defineProperty(chalkMarkdown, "__esModule", {
32
+ value: true
33
+ });
34
+ chalkMarkdown.logSymbols = chalkMarkdown.ChalkOrMarkdown = void 0;
35
+ var _chalk = _interopRequireDefault$2(vendor.source);
36
+ var _isUnicodeSupported = _interopRequireDefault$2(vendor.isUnicodeSupported);
37
+ var _terminalLink = _interopRequireDefault$2(vendor.terminalLink);
38
+ // From the 'log-symbols' module
39
+ const unicodeLogSymbols = {
40
+ info: _chalk.default.blue('ℹ'),
41
+ success: _chalk.default.green('✔'),
42
+ warning: _chalk.default.yellow('⚠'),
43
+ error: _chalk.default.red('✖')
44
+ };
45
+
46
+ // From the 'log-symbols' module
47
+ const fallbackLogSymbols = {
48
+ info: _chalk.default.blue('i'),
49
+ success: _chalk.default.green('√'),
50
+ warning: _chalk.default.yellow('‼'),
51
+ error: _chalk.default.red('×')
52
+ };
53
+
54
+ // From the 'log-symbols' module
55
+ const logSymbols = chalkMarkdown.logSymbols = (0, _isUnicodeSupported.default)() ? unicodeLogSymbols : fallbackLogSymbols;
56
+ const markdownLogSymbols = {
57
+ info: ':information_source:',
58
+ error: ':stop_sign:',
59
+ success: ':white_check_mark:',
60
+ warning: ':warning:'
61
+ };
62
+ class ChalkOrMarkdown {
63
+ constructor(useMarkdown) {
64
+ this.useMarkdown = !!useMarkdown;
65
+ }
66
+ header(text, level = 1) {
67
+ return this.useMarkdown ? `\n${''.padStart(level, '#')} ${text}\n` : _chalk.default.underline(`\n${level === 1 ? _chalk.default.bold(text) : text}\n`);
68
+ }
69
+ bold(text) {
70
+ return this.useMarkdown ? `**${text}**` : _chalk.default.bold(`${text}`);
71
+ }
72
+ italic(text) {
73
+ return this.useMarkdown ? `_${text}_` : _chalk.default.italic(`${text}`);
74
+ }
75
+ hyperlink(text, url, {
76
+ fallback = true,
77
+ fallbackToUrl
78
+ } = {}) {
79
+ if (!url) return text;
80
+ return this.useMarkdown ? `[${text}](${url})` : (0, _terminalLink.default)(text, url, {
81
+ fallback: fallbackToUrl ? (_text, url) => url : fallback
82
+ });
83
+ }
84
+ list(items) {
85
+ const indentedContent = items.map(item => this.indent(item).trimStart());
86
+ return this.useMarkdown ? '* ' + indentedContent.join('\n* ') + '\n' : indentedContent.join('\n') + '\n';
87
+ }
88
+ get logSymbols() {
89
+ return this.useMarkdown ? markdownLogSymbols : logSymbols;
90
+ }
91
+ indent(text, level = 1) {
92
+ const indent = ''.padStart(level * 2, ' ');
93
+ return indent + text.split('\n').join('\n' + indent);
94
+ }
95
+ json(value) {
96
+ return this.useMarkdown ? '```json\n' + JSON.stringify(value) + '\n```' : JSON.stringify(value);
97
+ }
98
+ }
99
+ chalkMarkdown.ChalkOrMarkdown = ChalkOrMarkdown;
100
+
101
+ var sdk = {};
102
+
103
+ var settings$1 = {};
104
+
105
+ var _interopRequireDefault$1 = vendor.interopRequireDefault.default;
106
+ var _interopRequireWildcard = vendor.interopRequireWildcard.default;
107
+ Object.defineProperty(settings$1, "__esModule", {
108
+ value: true
109
+ });
110
+ settings$1.getSetting = getSetting;
111
+ settings$1.updateSetting = updateSetting;
112
+ var _nodeFs = require$$0$1;
113
+ var os = _interopRequireWildcard(require$$0, true);
114
+ var path = _interopRequireWildcard(require$$1, true);
115
+ var _ora = _interopRequireDefault$1(vendor.ora);
116
+ let dataHome = process.platform === 'win32' ? process.env['LOCALAPPDATA'] : process.env['XDG_DATA_HOME'];
117
+ if (!dataHome) {
118
+ if (process.platform === 'win32') throw new Error('missing %LOCALAPPDATA%');
119
+ const home = os.homedir();
120
+ dataHome = path.join(home, ...(process.platform === 'darwin' ? ['Library', 'Application Support'] : ['.local', 'share']));
121
+ }
122
+ const settingsPath = path.join(dataHome, 'socket', 'settings');
123
+ let settings = {};
124
+ if ((0, _nodeFs.existsSync)(settingsPath)) {
125
+ const raw = (0, _nodeFs.readFileSync)(settingsPath, 'utf-8');
126
+ try {
127
+ settings = JSON.parse(Buffer.from(raw, 'base64').toString());
128
+ } catch {
129
+ (0, _ora.default)(`Failed to parse settings at ${settingsPath}`).warn();
130
+ }
131
+ } else {
132
+ (0, _nodeFs.mkdirSync)(path.dirname(settingsPath), {
133
+ recursive: true
134
+ });
135
+ }
136
+ function getSetting(key) {
137
+ return settings[key];
138
+ }
139
+ let pendingSave = false;
140
+ function updateSetting(key, value) {
141
+ settings[key] = value;
142
+ if (!pendingSave) {
143
+ pendingSave = true;
144
+ process.nextTick(() => {
145
+ pendingSave = false;
146
+ (0, _nodeFs.writeFileSync)(settingsPath, Buffer.from(JSON.stringify(settings)).toString('base64'));
147
+ });
148
+ }
149
+ }
150
+
151
+ var _interopRequireDefault = vendor.interopRequireDefault.default;
152
+ Object.defineProperty(sdk, "__esModule", {
153
+ value: true
154
+ });
155
+ sdk.FREE_API_KEY = void 0;
156
+ sdk.getDefaultKey = getDefaultKey;
157
+ sdk.setupSdk = setupSdk;
158
+ var _promises = require$$1$1;
159
+ var _nodePath = require$$1;
160
+ var _prompts = require$$1$2;
161
+ var _sdk = require$$4;
162
+ var _hpagent = require$$5;
163
+ var _isInteractive = _interopRequireDefault(vendor.isInteractive);
164
+ var _errors = errors;
165
+ var _settings = settings$1;
166
+ const distPath = __dirname;
167
+ const rootPath = _nodePath.resolve(distPath, '..');
168
+ sdk.FREE_API_KEY = 'sktsec_t_--RAN5U4ivauy4w37-6aoKyYPDt5ZbaT5JBVMqiwKo_api';
169
+
170
+ // This API key should be stored globally for the duration of the CLI execution
171
+ let defaultKey;
172
+ function getDefaultKey() {
173
+ defaultKey = process.env['SOCKET_SECURITY_API_KEY'] || (0, _settings.getSetting)('apiKey') || defaultKey;
174
+ return defaultKey;
175
+ }
176
+
177
+ // The API server that should be used for operations
178
+ let defaultAPIBaseUrl;
179
+ function getDefaultAPIBaseUrl() {
180
+ defaultAPIBaseUrl = process.env['SOCKET_SECURITY_API_BASE_URL'] || (0, _settings.getSetting)('apiBaseUrl') || undefined;
181
+ return defaultAPIBaseUrl;
182
+ }
183
+
184
+ // The API server that should be used for operations
185
+ let defaultApiProxy;
186
+ function getDefaultHTTPProxy() {
187
+ defaultApiProxy = process.env['SOCKET_SECURITY_API_PROXY'] || (0, _settings.getSetting)('apiProxy') || undefined;
188
+ return defaultApiProxy;
189
+ }
190
+ async function setupSdk(apiKey = getDefaultKey(), apiBaseUrl = getDefaultAPIBaseUrl(), proxy = getDefaultHTTPProxy()) {
191
+ if (typeof apiKey !== 'string' && (0, _isInteractive.default)()) {
192
+ apiKey = await (0, _prompts.password)({
193
+ message: 'Enter your Socket.dev API key (not saved, use socket login to persist)'
194
+ });
195
+ defaultKey = apiKey;
196
+ }
197
+ if (!apiKey) {
198
+ throw new _errors.AuthError('You need to provide an API key');
199
+ }
200
+ let agent;
201
+ if (proxy) {
202
+ agent = {
203
+ http: new _hpagent.HttpProxyAgent({
204
+ proxy
205
+ }),
206
+ https: new _hpagent.HttpsProxyAgent({
207
+ proxy
208
+ })
209
+ };
210
+ }
211
+ const packageJsonPath = _nodePath.join(rootPath, 'package.json');
212
+ const packageJson = await _promises.readFile(packageJsonPath, 'utf8');
213
+ const sdkOptions = {
214
+ agent,
215
+ baseUrl: apiBaseUrl,
216
+ userAgent: (0, _sdk.createUserAgentFromPkgJson)(JSON.parse(packageJson))
217
+ };
218
+ return new _sdk.SocketSdk(apiKey || '', sdkOptions);
219
+ }
220
+
221
+ exports.chalkMarkdown = chalkMarkdown;
222
+ exports.errors = errors;
223
+ exports.sdk = sdk;
224
+ exports.settings = settings$1;
@@ -0,0 +1,9 @@
1
+ interface Settings {
2
+ apiKey?: string | null;
3
+ enforcedOrgs?: string[] | null;
4
+ apiBaseUrl?: string | null;
5
+ apiProxy?: string | null;
6
+ }
7
+ declare function getSetting<Key extends keyof Settings>(key: Key): Settings[Key];
8
+ declare function updateSetting<Key extends keyof Settings>(key: Key, value: Settings[Key]): void;
9
+ export { getSetting, updateSetting };
@@ -0,0 +1,3 @@
1
+ /// <reference types="node" />
2
+ declare function isErrnoException(value: unknown): value is NodeJS.ErrnoException;
3
+ export { isErrnoException };