socket 0.14.40-alpha.9 → 0.14.41

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "socket",
3
- "version": "0.14.40-alpha.9",
3
+ "version": "0.14.41",
4
4
  "description": "CLI tool for Socket.dev",
5
5
  "homepage": "http://github.com/SocketDev/socket-cli",
6
6
  "license": "MIT",
@@ -42,6 +42,9 @@
42
42
  "check:lint": "eslint --report-unused-disable-directives .",
43
43
  "check:tsc": "tsc",
44
44
  "check:type-coverage": "type-coverage --detail --strict --at-least 95 --ignore-files 'test/*'",
45
+ "clean": "run-p --aggregate-output clean:*",
46
+ "clean:dist": "del-cli 'dist' 'test/dist'",
47
+ "clean:node_modules": "del-cli '**/node_modules'",
45
48
  "knip:dependencies": "knip --dependencies",
46
49
  "knip:exports": "knip --include exports,duplicates",
47
50
  "lint": "oxlint -c=./.oxlintrc.json --ignore-path=./.prettierignore --tsconfig=./tsconfig.json .",
@@ -52,35 +55,37 @@
52
55
  "test-ci": "run-s build:* test:*",
53
56
  "test:unit": "tap-run",
54
57
  "test:coverage:c8": "c8 --reporter=none node --test 'test/socket-npm.test.cjs'",
55
- "test:coverage:merge": "cp -r .tap/coverage/*.json coverage/tmp && c8 --reporter=lcov --reporter=text --include 'dist/{module-sync,require}/*.js' --exclude 'dist/require/vendor.js' report"
58
+ "test:coverage:merge": "cp -r .tap/coverage/*.json coverage/tmp && c8 --reporter=lcov --reporter=text --include 'dist/{module-sync,require}/*.js' --exclude 'dist/require/vendor.js' report",
59
+ "update": "run-p --aggregate-output update:**",
60
+ "update:deps": "npx npm-check-updates"
56
61
  },
57
62
  "dependencies": {
58
63
  "@apideck/better-ajv-errors": "^0.3.6",
59
- "@cyclonedx/cdxgen": "^11.0.10",
64
+ "@cyclonedx/cdxgen": "^11.1.5",
60
65
  "@npmcli/promise-spawn": "^8.0.2",
61
- "@socketregistry/hyrious__bun.lockb": "1.0.10",
62
- "@socketregistry/yocto-spinner": "^1.0.3",
66
+ "@socketregistry/hyrious__bun.lockb": "^1.0.12",
67
+ "@socketregistry/indent-string": "^1.0.9",
68
+ "@socketregistry/is-interactive": "^1.0.1",
69
+ "@socketregistry/is-unicode-supported": "^1.0.0",
63
70
  "@socketsecurity/config": "^2.1.3",
64
- "@socketsecurity/registry": "^1.0.68",
71
+ "@socketsecurity/registry": "^1.0.78",
65
72
  "@socketsecurity/sdk": "^1.4.5",
66
73
  "blessed": "^0.1.81",
67
74
  "blessed-contrib": "^4.11.0",
68
75
  "browserslist": "4.24.4",
69
76
  "chalk-table": "^1.0.2",
70
77
  "cmd-shim": "^7.0.0",
71
- "has-flag": "^4.0.0",
78
+ "has-flag": "4.0.0",
72
79
  "hpagent": "^1.2.0",
73
80
  "ignore": "^7.0.3",
74
- "is-interactive": "^2.0.0",
75
- "is-unicode-supported": "^2.1.0",
76
81
  "meow": "^13.2.0",
77
82
  "micromatch": "^4.0.8",
78
83
  "npm-package-arg": "^12.0.1",
79
84
  "open": "^10.1.0",
80
85
  "pony-cause": "^2.1.11",
81
- "semver": "^7.6.3",
86
+ "semver": "^7.7.0",
82
87
  "synp": "^1.9.14",
83
- "terminal-link": "^3.0.0",
88
+ "terminal-link": "2.1.1",
84
89
  "tiny-updater": "^3.5.3",
85
90
  "tinyglobby": "^0.2.10",
86
91
  "which": "^5.0.0",
@@ -89,16 +94,16 @@
89
94
  "yoctocolors-cjs": "^2.1.2"
90
95
  },
91
96
  "devDependencies": {
92
- "@babel/core": "^7.26.0",
97
+ "@babel/core": "^7.26.7",
93
98
  "@babel/plugin-proposal-export-default-from": "^7.25.9",
94
99
  "@babel/plugin-syntax-dynamic-import": "^7.8.3",
95
100
  "@babel/plugin-transform-export-namespace-from": "^7.25.9",
96
101
  "@babel/plugin-transform-runtime": "^7.25.9",
97
- "@babel/preset-env": "^7.26.0",
102
+ "@babel/preset-env": "^7.26.7",
98
103
  "@babel/preset-typescript": "^7.26.0",
99
- "@babel/runtime": "^7.26.0",
104
+ "@babel/runtime": "^7.26.7",
100
105
  "@eslint/compat": "^1.2.5",
101
- "@eslint/js": "^9.18.0",
106
+ "@eslint/js": "^9.19.0",
102
107
  "@rollup/plugin-commonjs": "^28.0.2",
103
108
  "@rollup/plugin-json": "^6.1.0",
104
109
  "@rollup/plugin-node-resolve": "^16.0.0",
@@ -110,39 +115,40 @@
110
115
  "@types/micromatch": "^4.0.9",
111
116
  "@types/mocha": "^10.0.10",
112
117
  "@types/mock-fs": "^4.13.4",
113
- "@types/node": "^22.10.6",
114
- "@types/npmcli__arborist": "^5.6.11",
118
+ "@types/node": "^22.12.0",
119
+ "@types/npmcli__arborist": "^6.3.0",
115
120
  "@types/npmcli__promise-spawn": "^6.0.3",
116
121
  "@types/proc-log": "^3.0.4",
117
122
  "@types/semver": "^7.5.8",
118
123
  "@types/update-notifier": "^6.0.8",
119
124
  "@types/which": "^3.0.4",
120
125
  "@types/yargs-parser": "^21.0.3",
121
- "@typescript-eslint/eslint-plugin": "^8.20.0",
122
- "@typescript-eslint/parser": "^8.20.0",
126
+ "@typescript-eslint/eslint-plugin": "^8.22.0",
127
+ "@typescript-eslint/parser": "^8.22.0",
123
128
  "c8": "^10.1.3",
124
129
  "custompatch": "^1.1.4",
125
- "eslint": "^9.18.0",
126
- "eslint-import-resolver-oxc": "^0.8.0",
130
+ "del-cli": "^6.0.0",
131
+ "eslint": "^9.19.0",
132
+ "eslint-import-resolver-oxc": "^0.10.1",
127
133
  "eslint-plugin-depend": "^0.12.0",
128
134
  "eslint-plugin-import-x": "^4.6.1",
129
135
  "eslint-plugin-n": "^17.15.1",
130
136
  "eslint-plugin-sort-destructure-keys": "^2.0.0",
131
137
  "eslint-plugin-unicorn": "^56.0.1",
132
138
  "husky": "^9.1.7",
133
- "knip": "^5.42.0",
139
+ "knip": "^5.43.6",
134
140
  "magic-string": "^0.30.17",
135
141
  "mock-fs": "^5.4.1",
136
- "nock": "^13.5.6",
142
+ "nock": "^14.0.0",
137
143
  "npm-run-all2": "^7.0.2",
138
- "oxlint": "0.15.6",
144
+ "oxlint": "0.15.8",
139
145
  "prettier": "3.4.2",
140
146
  "read-package-up": "^11.0.0",
141
- "rollup": "4.30.1",
147
+ "rollup": "4.32.1",
142
148
  "rollup-plugin-ts": "^3.4.5",
143
149
  "type-coverage": "^2.29.7",
144
150
  "typescript": "5.4.5",
145
- "typescript-eslint": "^8.20.0",
151
+ "typescript-eslint": "^8.22.0",
146
152
  "unplugin-purge-polyfills": "^0.0.7"
147
153
  },
148
154
  "overrides": {
@@ -1,23 +0,0 @@
1
- declare const logSymbols: {
2
- __proto__: null;
3
- info: string;
4
- success: string;
5
- warning: string;
6
- error: string;
7
- };
8
- declare class ColorOrMarkdown {
9
- useMarkdown: boolean;
10
- constructor(useMarkdown: boolean);
11
- header(text: string, level?: number): string;
12
- bold(text: string): string;
13
- italic(text: string): string;
14
- hyperlink(text: string, url: string | undefined, { fallback, fallbackToUrl }?: {
15
- fallback?: boolean;
16
- fallbackToUrl?: boolean;
17
- }): string;
18
- list(items: string[]): string;
19
- get logSymbols(): typeof logSymbols;
20
- indent(text: string, level?: number): string;
21
- json(value: unknown): string;
22
- }
23
- export { logSymbols, ColorOrMarkdown };
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAGA,OAAO,iBAAiB,MAAM,wCAAwC,CAAA;AAGtE,KAAK,WAAW,GAAG,OAAO,iBAAiB,CAAC,GAAG,CAAA;AAE/C,KAAK,SAAS,GAAG;IACf,QAAQ,CAAC,UAAU,EAAE,2BAA2B,CAAA;IAChD,QAAQ,CAAC,aAAa,EAAE,gBAAgB,CAAA;IACxC,QAAQ,CAAC,eAAe,EAAE,QAAQ,CAAA;IAClC,QAAQ,CAAC,GAAG,EAAE,KAAK,CAAA;IACnB,QAAQ,CAAC,GAAG,EAAE,WAAW,GAAG;QAC1B,gBAAgB,EA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typeof console.error;
4
- declare function isErrnoException(value: unknown): value is NodeJS.ErrnoException;
5
- declare function stringJoinWithSeparateFinalSeparator(list: (string | undefined)[], separator?: string): string;
6
- declare function getDefaultKey(): string | undefined;
7
- declare function setupSdk(apiKey?: string | undefined, apiBaseUrl?: string | undefined, proxy?: string | undefined): Promise<SocketSdk>;
8
- export { createDebugLogger, isErrnoException, stringJoinWithSeparateFinalSeparator, getDefaultKey, setupSdk };
@@ -1,214 +0,0 @@
1
- 'use strict';
2
-
3
- function _socketInterop(e) {
4
- let c = 0
5
- for (const k in e ?? {}) {
6
- c = c === 0 && k === 'default' ? 1 : 0
7
- if (!c && k !== '__esModule') break
8
- }
9
- return c ? e.default : e
10
- }
11
-
12
- var isUnicodeSupported = _socketInterop(require('is-unicode-supported'));
13
- var terminalLink = _socketInterop(require('terminal-link'));
14
- var colors = _socketInterop(require('yoctocolors-cjs'));
15
- var hpagent = _socketInterop(require('hpagent'));
16
- var isInteractive = _socketInterop(require('is-interactive'));
17
- var prompts = require('@socketsecurity/registry/lib/prompts');
18
- var strings = require('@socketsecurity/registry/lib/strings');
19
- var sdk = require('@socketsecurity/sdk');
20
- var fs = require('node:fs');
21
- var homedir = require('node:os');
22
- var path = require('node:path');
23
- var spinner = require('@socketsecurity/registry/lib/spinner');
24
- var constants = require('./constants.js');
25
-
26
- class AuthError extends Error {}
27
- class InputError extends Error {
28
- constructor(message, body) {
29
- super(message);
30
- this.body = body;
31
- }
32
- }
33
-
34
- // From the 'log-symbols' module
35
- const unicodeLogSymbols = {
36
- __proto__: null,
37
- info: colors.blue('ℹ'),
38
- success: colors.green('✔'),
39
- warning: colors.yellow('⚠'),
40
- error: colors.red('✖')
41
- };
42
-
43
- // From the 'log-symbols' module
44
- const fallbackLogSymbols = {
45
- __proto__: null,
46
- info: colors.blue('i'),
47
- success: colors.green('√'),
48
- warning: colors.yellow('‼'),
49
- error: colors.red('×')
50
- };
51
-
52
- // From the 'log-symbols' module
53
- const logSymbols = isUnicodeSupported() ? unicodeLogSymbols : fallbackLogSymbols;
54
- const markdownLogSymbols = {
55
- __proto__: null,
56
- info: ':information_source:',
57
- error: ':stop_sign:',
58
- success: ':white_check_mark:',
59
- warning: ':warning:'
60
- };
61
- class ColorOrMarkdown {
62
- constructor(useMarkdown) {
63
- this.useMarkdown = !!useMarkdown;
64
- }
65
- header(text, level = 1) {
66
- return this.useMarkdown ? `\n${''.padStart(level, '#')} ${text}\n` : colors.underline(`\n${level === 1 ? colors.bold(text) : text}\n`);
67
- }
68
- bold(text) {
69
- return this.useMarkdown ? `**${text}**` : colors.bold(`${text}`);
70
- }
71
- italic(text) {
72
- return this.useMarkdown ? `_${text}_` : colors.italic(`${text}`);
73
- }
74
- hyperlink(text, url, {
75
- fallback = true,
76
- fallbackToUrl
77
- } = {}) {
78
- if (!url) return text;
79
- return this.useMarkdown ? `[${text}](${url})` : terminalLink(text, url, {
80
- fallback: fallbackToUrl ? (_text, url) => url : fallback
81
- });
82
- }
83
- list(items) {
84
- const indentedContent = items.map(item => this.indent(item).trimStart());
85
- return this.useMarkdown ? `* ${indentedContent.join('\n* ')}\n` : `${indentedContent.join('\n')}\n`;
86
- }
87
- get logSymbols() {
88
- return this.useMarkdown ? markdownLogSymbols : logSymbols;
89
- }
90
- indent(text, level = 1) {
91
- const indent = ''.padStart(level * 2, ' ');
92
- return indent + text.split('\n').join('\n' + indent);
93
- }
94
- json(value) {
95
- return this.useMarkdown ? '```json\n' + JSON.stringify(value) + '\n```' : JSON.stringify(value);
96
- }
97
- }
98
-
99
- function createDebugLogger(printDebugLogs) {
100
- return printDebugLogs ? (...params) => console.error(logSymbols.info, ...params) : () => {};
101
- }
102
- function isErrnoException(value) {
103
- if (!(value instanceof Error)) {
104
- return false;
105
- }
106
- return value.code !== undefined;
107
- }
108
- function stringJoinWithSeparateFinalSeparator(list, separator = ' and ') {
109
- const values = list.filter(value => !!value);
110
- if (values.length < 2) {
111
- return values[0] || '';
112
- }
113
- const finalValue = values.pop();
114
- return values.join(', ') + separator + finalValue;
115
- }
116
-
117
- let dataHome = process.platform === 'win32' ? process.env['LOCALAPPDATA'] : process.env['XDG_DATA_HOME'];
118
- if (!dataHome) {
119
- if (process.platform === 'win32') throw new Error('missing %LOCALAPPDATA%');
120
- const home = homedir.homedir();
121
- dataHome = path.join(home, ...(process.platform === 'darwin' ? ['Library', 'Application Support'] : ['.local', 'share']));
122
- }
123
- const settingsPath = path.join(dataHome, 'socket', 'settings');
124
- let settings = {};
125
- if (fs.existsSync(settingsPath)) {
126
- const raw = fs.readFileSync(settingsPath, 'utf8');
127
- try {
128
- settings = JSON.parse(Buffer.from(raw, 'base64').toString());
129
- } catch {
130
- new spinner.Spinner().warning(`Failed to parse settings at ${settingsPath}`);
131
- }
132
- } else {
133
- fs.mkdirSync(path.dirname(settingsPath), {
134
- recursive: true
135
- });
136
- }
137
- function getSetting(key) {
138
- return settings[key];
139
- }
140
- let pendingSave = false;
141
- function updateSetting(key, value) {
142
- settings[key] = value;
143
- if (!pendingSave) {
144
- pendingSave = true;
145
- process.nextTick(() => {
146
- pendingSave = false;
147
- fs.writeFileSync(settingsPath, Buffer.from(JSON.stringify(settings)).toString('base64'));
148
- });
149
- }
150
- }
151
-
152
- const {
153
- rootPkgJsonPath
154
- } = constants;
155
-
156
- // This API key should be stored globally for the duration of the CLI execution.
157
- let defaultKey;
158
- function getDefaultKey() {
159
- const key = process.env['SOCKET_SECURITY_API_KEY'] || getSetting('apiKey') || defaultKey;
160
- defaultKey = strings.isNonEmptyString(key) ? key : undefined;
161
- return defaultKey;
162
- }
163
-
164
- // The API server that should be used for operations.
165
- function getDefaultAPIBaseUrl() {
166
- const baseUrl = process.env['SOCKET_SECURITY_API_BASE_URL'] || getSetting('apiBaseUrl');
167
- return strings.isNonEmptyString(baseUrl) ? baseUrl : undefined;
168
- }
169
-
170
- // The API server that should be used for operations.
171
- function getDefaultHTTPProxy() {
172
- const apiProxy = process.env['SOCKET_SECURITY_API_PROXY'] || getSetting('apiProxy');
173
- return strings.isNonEmptyString(apiProxy) ? apiProxy : undefined;
174
- }
175
- async function setupSdk(apiKey = getDefaultKey(), apiBaseUrl = getDefaultAPIBaseUrl(), proxy = getDefaultHTTPProxy()) {
176
- if (typeof apiKey !== 'string' && isInteractive()) {
177
- apiKey = await prompts.password({
178
- message: 'Enter your Socket.dev API key (not saved, use socket login to persist)'
179
- });
180
- defaultKey = apiKey;
181
- }
182
- if (!apiKey) {
183
- throw new AuthError('You need to provide an API key');
184
- }
185
- let agent;
186
- if (proxy) {
187
- agent = {
188
- http: new hpagent.HttpProxyAgent({
189
- proxy
190
- }),
191
- https: new hpagent.HttpsProxyAgent({
192
- proxy
193
- })
194
- };
195
- }
196
- const sdkOptions = {
197
- agent,
198
- baseUrl: apiBaseUrl,
199
- userAgent: sdk.createUserAgentFromPkgJson(require(rootPkgJsonPath))
200
- };
201
- return new sdk.SocketSdk(apiKey || '', sdkOptions);
202
- }
203
-
204
- exports.AuthError = AuthError;
205
- exports.ColorOrMarkdown = ColorOrMarkdown;
206
- exports.InputError = InputError;
207
- exports.createDebugLogger = createDebugLogger;
208
- exports.getDefaultKey = getDefaultKey;
209
- exports.getSetting = getSetting;
210
- exports.isErrnoException = isErrnoException;
211
- exports.logSymbols = logSymbols;
212
- exports.setupSdk = setupSdk;
213
- exports.stringJoinWithSeparateFinalSeparator = stringJoinWithSeparateFinalSeparator;
214
- exports.updateSetting = updateSetting;
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAGA,OAAO,iBAAiB,MAAM,wCAAwC,CAAA;AAGtE,KAAK,WAAW,GAAG,OAAO,iBAAiB,CAAC,GAAG,CAAA;AAE/C,KAAK,SAAS,GAAG;IACf,QAAQ,CAAC,UAAU,EAAE,2BAA2B,CAAA;IAChD,QAAQ,CAAC,aAAa,EAAE,gBAAgB,CAAA;IACxC,QAAQ,CAAC,eAAe,EAAE,QAAQ,CAAA;IAClC,QAAQ,CA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,0 @@
1
- 'use strict';
2
-
3
- function _socketInterop(e) {
4
- let c = 0
5
- for (const k in e ?? {}) {
6
- c = c === 0 && k === 'default' ? 1 : 0
7
- if (!c && k !== '__esModule') break
8
- }
9
- return c ? e.default : e
10
- }
11
-
12
- var vendor = require('./vendor.js');
13
- var colors = _socketInterop(require('yoctocolors-cjs'));
14
- var hpagent = _socketInterop(require('hpagent'));
15
- var prompts = require('@socketsecurity/registry/lib/prompts');
16
- var strings = require('@socketsecurity/registry/lib/strings');
17
- var sdk = require('@socketsecurity/sdk');
18
- var fs = require('node:fs');
19
- var os = require('node:os');
20
- var path = require('node:path');
21
- var spinner = require('@socketsecurity/registry/lib/spinner');
22
- var constants = require('./constants.js');
23
-
24
- class AuthError extends Error {}
25
- class InputError extends Error {
26
- constructor(message, body) {
27
- super(message);
28
- this.body = body;
29
- }
30
- }
31
-
32
- // From the 'log-symbols' module
33
- const unicodeLogSymbols = {
34
- __proto__: null,
35
- info: colors.blue('ℹ'),
36
- success: colors.green('✔'),
37
- warning: colors.yellow('⚠'),
38
- error: colors.red('✖')
39
- };
40
-
41
- // From the 'log-symbols' module
42
- const fallbackLogSymbols = {
43
- __proto__: null,
44
- info: colors.blue('i'),
45
- success: colors.green('√'),
46
- warning: colors.yellow('‼'),
47
- error: colors.red('×')
48
- };
49
-
50
- // From the 'log-symbols' module
51
- const logSymbols = vendor.isUnicodeSupported() ? unicodeLogSymbols : fallbackLogSymbols;
52
- const markdownLogSymbols = {
53
- __proto__: null,
54
- info: ':information_source:',
55
- error: ':stop_sign:',
56
- success: ':white_check_mark:',
57
- warning: ':warning:'
58
- };
59
- class ColorOrMarkdown {
60
- constructor(useMarkdown) {
61
- this.useMarkdown = !!useMarkdown;
62
- }
63
- header(text, level = 1) {
64
- return this.useMarkdown ? `\n${''.padStart(level, '#')} ${text}\n` : colors.underline(`\n${level === 1 ? colors.bold(text) : text}\n`);
65
- }
66
- bold(text) {
67
- return this.useMarkdown ? `**${text}**` : colors.bold(`${text}`);
68
- }
69
- italic(text) {
70
- return this.useMarkdown ? `_${text}_` : colors.italic(`${text}`);
71
- }
72
- hyperlink(text, url, {
73
- fallback = true,
74
- fallbackToUrl
75
- } = {}) {
76
- if (!url) return text;
77
- return this.useMarkdown ? `[${text}](${url})` : vendor.terminalLink(text, url, {
78
- fallback: fallbackToUrl ? (_text, url) => url : fallback
79
- });
80
- }
81
- list(items) {
82
- const indentedContent = items.map(item => this.indent(item).trimStart());
83
- return this.useMarkdown ? `* ${indentedContent.join('\n* ')}\n` : `${indentedContent.join('\n')}\n`;
84
- }
85
- get logSymbols() {
86
- return this.useMarkdown ? markdownLogSymbols : logSymbols;
87
- }
88
- indent(text, level = 1) {
89
- const indent = ''.padStart(level * 2, ' ');
90
- return indent + text.split('\n').join('\n' + indent);
91
- }
92
- json(value) {
93
- return this.useMarkdown ? '```json\n' + JSON.stringify(value) + '\n```' : JSON.stringify(value);
94
- }
95
- }
96
-
97
- function createDebugLogger(printDebugLogs) {
98
- return printDebugLogs ? (...params) => console.error(logSymbols.info, ...params) : () => {};
99
- }
100
- function isErrnoException(value) {
101
- if (!(value instanceof Error)) {
102
- return false;
103
- }
104
- return value.code !== undefined;
105
- }
106
- function stringJoinWithSeparateFinalSeparator(list, separator = ' and ') {
107
- const values = list.filter(value => !!value);
108
- if (values.length < 2) {
109
- return values[0] || '';
110
- }
111
- const finalValue = values.pop();
112
- return values.join(', ') + separator + finalValue;
113
- }
114
-
115
- let dataHome = process.platform === 'win32' ? process.env['LOCALAPPDATA'] : process.env['XDG_DATA_HOME'];
116
- if (!dataHome) {
117
- if (process.platform === 'win32') throw new Error('missing %LOCALAPPDATA%');
118
- const home = os.homedir();
119
- dataHome = path.join(home, ...(process.platform === 'darwin' ? ['Library', 'Application Support'] : ['.local', 'share']));
120
- }
121
- const settingsPath = path.join(dataHome, 'socket', 'settings');
122
- let settings = {};
123
- if (fs.existsSync(settingsPath)) {
124
- const raw = fs.readFileSync(settingsPath, 'utf8');
125
- try {
126
- settings = JSON.parse(Buffer.from(raw, 'base64').toString());
127
- } catch {
128
- new spinner.Spinner().warning(`Failed to parse settings at ${settingsPath}`);
129
- }
130
- } else {
131
- fs.mkdirSync(path.dirname(settingsPath), {
132
- recursive: true
133
- });
134
- }
135
- function getSetting(key) {
136
- return settings[key];
137
- }
138
- let pendingSave = false;
139
- function updateSetting(key, value) {
140
- settings[key] = value;
141
- if (!pendingSave) {
142
- pendingSave = true;
143
- process.nextTick(() => {
144
- pendingSave = false;
145
- fs.writeFileSync(settingsPath, Buffer.from(JSON.stringify(settings)).toString('base64'));
146
- });
147
- }
148
- }
149
-
150
- const {
151
- rootPkgJsonPath
152
- } = constants;
153
-
154
- // This API key should be stored globally for the duration of the CLI execution.
155
- let defaultKey;
156
- function getDefaultKey() {
157
- const key = process.env['SOCKET_SECURITY_API_KEY'] || getSetting('apiKey') || defaultKey;
158
- defaultKey = strings.isNonEmptyString(key) ? key : undefined;
159
- return defaultKey;
160
- }
161
-
162
- // The API server that should be used for operations.
163
- function getDefaultAPIBaseUrl() {
164
- const baseUrl = process.env['SOCKET_SECURITY_API_BASE_URL'] || getSetting('apiBaseUrl');
165
- return strings.isNonEmptyString(baseUrl) ? baseUrl : undefined;
166
- }
167
-
168
- // The API server that should be used for operations.
169
- function getDefaultHTTPProxy() {
170
- const apiProxy = process.env['SOCKET_SECURITY_API_PROXY'] || getSetting('apiProxy');
171
- return strings.isNonEmptyString(apiProxy) ? apiProxy : undefined;
172
- }
173
- async function setupSdk(apiKey = getDefaultKey(), apiBaseUrl = getDefaultAPIBaseUrl(), proxy = getDefaultHTTPProxy()) {
174
- if (typeof apiKey !== 'string' && vendor.isInteractive()) {
175
- apiKey = await prompts.password({
176
- message: 'Enter your Socket.dev API key (not saved, use socket login to persist)'
177
- });
178
- defaultKey = apiKey;
179
- }
180
- if (!apiKey) {
181
- throw new AuthError('You need to provide an API key');
182
- }
183
- let agent;
184
- if (proxy) {
185
- agent = {
186
- http: new hpagent.HttpProxyAgent({
187
- proxy
188
- }),
189
- https: new hpagent.HttpsProxyAgent({
190
- proxy
191
- })
192
- };
193
- }
194
- const sdkOptions = {
195
- agent,
196
- baseUrl: apiBaseUrl,
197
- userAgent: sdk.createUserAgentFromPkgJson(require(rootPkgJsonPath))
198
- };
199
- return new sdk.SocketSdk(apiKey || '', sdkOptions);
200
- }
201
-
202
- exports.AuthError = AuthError;
203
- exports.ColorOrMarkdown = ColorOrMarkdown;
204
- exports.InputError = InputError;
205
- exports.createDebugLogger = createDebugLogger;
206
- exports.getDefaultKey = getDefaultKey;
207
- exports.getSetting = getSetting;
208
- exports.isErrnoException = isErrnoException;
209
- exports.logSymbols = logSymbols;
210
- exports.setupSdk = setupSdk;
211
- exports.stringJoinWithSeparateFinalSeparator = stringJoinWithSeparateFinalSeparator;
212
- exports.updateSetting = updateSetting;