@socketsecurity/cli 0.14.38 → 0.14.40

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": "@socketsecurity/cli",
3
- "version": "0.14.38",
3
+ "version": "0.14.40",
4
4
  "description": "CLI tool for Socket.dev",
5
5
  "homepage": "http://github.com/SocketDev/socket-cli",
6
6
  "license": "MIT",
@@ -57,23 +57,23 @@
57
57
  },
58
58
  "dependencies": {
59
59
  "@apideck/better-ajv-errors": "^0.3.6",
60
- "@cyclonedx/cdxgen": "^11.0.7",
60
+ "@cyclonedx/cdxgen": "^11.1.0",
61
61
  "@npmcli/promise-spawn": "^8.0.2",
62
- "@socketregistry/hyrious__bun.lockb": "1.0.7",
63
- "@socketregistry/yocto-spinner": "^1.0.2",
62
+ "@socketregistry/hyrious__bun.lockb": "^1.0.11",
63
+ "@socketregistry/indent-string": "^1.0.9",
64
+ "@socketregistry/is-interactive": "^1.0.1",
65
+ "@socketregistry/is-unicode-supported": "^1.0.0",
64
66
  "@socketsecurity/config": "^2.1.3",
65
- "@socketsecurity/registry": "^1.0.57",
66
- "@socketsecurity/sdk": "^1.3.0",
67
+ "@socketsecurity/registry": "^1.0.74",
68
+ "@socketsecurity/sdk": "^1.4.5",
67
69
  "blessed": "^0.1.81",
68
70
  "blessed-contrib": "^4.11.0",
69
- "browserslist": "4.24.3",
71
+ "browserslist": "4.24.4",
70
72
  "chalk-table": "^1.0.2",
71
73
  "cmd-shim": "^7.0.0",
72
- "has-flag": "^4.0.0",
74
+ "has-flag": "4.0.0",
73
75
  "hpagent": "^1.2.0",
74
- "ignore": "^7.0.0",
75
- "is-interactive": "^2.0.0",
76
- "is-unicode-supported": "^2.1.0",
76
+ "ignore": "^7.0.3",
77
77
  "meow": "^13.2.0",
78
78
  "micromatch": "^4.0.8",
79
79
  "npm-package-arg": "^12.0.1",
@@ -81,11 +81,11 @@
81
81
  "pony-cause": "^2.1.11",
82
82
  "semver": "^7.6.3",
83
83
  "synp": "^1.9.14",
84
- "terminal-link": "^3.0.0",
85
- "tiny-updater": "^3.5.2",
84
+ "terminal-link": "2.1.1",
85
+ "tiny-updater": "^3.5.3",
86
86
  "tinyglobby": "^0.2.10",
87
87
  "which": "^5.0.0",
88
- "yaml": "^2.6.1",
88
+ "yaml": "^2.7.0",
89
89
  "yargs-parser": "^21.1.1",
90
90
  "yoctocolors-cjs": "^2.1.2"
91
91
  },
@@ -98,8 +98,8 @@
98
98
  "@babel/preset-env": "^7.26.0",
99
99
  "@babel/preset-typescript": "^7.26.0",
100
100
  "@babel/runtime": "^7.26.0",
101
- "@eslint/compat": "^1.2.4",
102
- "@eslint/js": "^9.17.0",
101
+ "@eslint/compat": "^1.2.5",
102
+ "@eslint/js": "^9.18.0",
103
103
  "@rollup/plugin-commonjs": "^28.0.2",
104
104
  "@rollup/plugin-json": "^6.1.0",
105
105
  "@rollup/plugin-node-resolve": "^16.0.0",
@@ -111,39 +111,39 @@
111
111
  "@types/micromatch": "^4.0.9",
112
112
  "@types/mocha": "^10.0.10",
113
113
  "@types/mock-fs": "^4.13.4",
114
- "@types/node": "^22.10.2",
115
- "@types/npmcli__arborist": "^5.6.11",
114
+ "@types/node": "^22.10.7",
115
+ "@types/npmcli__arborist": "^6.3.0",
116
116
  "@types/npmcli__promise-spawn": "^6.0.3",
117
117
  "@types/proc-log": "^3.0.4",
118
118
  "@types/semver": "^7.5.8",
119
119
  "@types/update-notifier": "^6.0.8",
120
120
  "@types/which": "^3.0.4",
121
121
  "@types/yargs-parser": "^21.0.3",
122
- "@typescript-eslint/eslint-plugin": "^8.18.2",
123
- "@typescript-eslint/parser": "^8.18.2",
122
+ "@typescript-eslint/eslint-plugin": "^8.21.0",
123
+ "@typescript-eslint/parser": "^8.21.0",
124
124
  "c8": "^10.1.3",
125
- "custompatch": "^1.0.28",
126
- "eslint": "^9.17.0",
127
- "eslint-import-resolver-oxc": "^0.7.0",
125
+ "custompatch": "^1.1.4",
126
+ "eslint": "^9.18.0",
127
+ "eslint-import-resolver-oxc": "^0.9.1",
128
128
  "eslint-plugin-depend": "^0.12.0",
129
129
  "eslint-plugin-import-x": "^4.6.1",
130
130
  "eslint-plugin-n": "^17.15.1",
131
131
  "eslint-plugin-sort-destructure-keys": "^2.0.0",
132
132
  "eslint-plugin-unicorn": "^56.0.1",
133
133
  "husky": "^9.1.7",
134
- "knip": "^5.41.1",
134
+ "knip": "^5.42.2",
135
135
  "magic-string": "^0.30.17",
136
136
  "mock-fs": "^5.4.1",
137
137
  "nock": "^13.5.6",
138
138
  "npm-run-all2": "^7.0.2",
139
- "oxlint": "0.15.3",
139
+ "oxlint": "0.15.7",
140
140
  "prettier": "3.4.2",
141
141
  "read-package-up": "^11.0.0",
142
- "rollup": "4.29.1",
142
+ "rollup": "4.31.0",
143
143
  "rollup-plugin-ts": "^3.4.5",
144
144
  "type-coverage": "^2.29.7",
145
145
  "typescript": "5.4.5",
146
- "typescript-eslint": "^8.18.2",
146
+ "typescript-eslint": "^8.21.0",
147
147
  "unplugin-purge-polyfills": "^0.0.7"
148
148
  },
149
149
  "overrides": {
@@ -166,6 +166,7 @@
166
166
  "safer-buffer": "npm:@socketregistry/safer-buffer@^1",
167
167
  "semver": "$semver",
168
168
  "set-function-length": "npm:@socketregistry/set-function-length@^1",
169
+ "shell-quote": "npm:shell-quote@^1",
169
170
  "side-channel": "npm:@socketregistry/side-channel@^1",
170
171
  "tiny-colors": "$yoctocolors-cjs",
171
172
  "typedarray": "npm:@socketregistry/typedarray@^1",
@@ -191,6 +192,7 @@
191
192
  "safer-buffer": "npm:@socketregistry/safer-buffer@^1",
192
193
  "semver": "^7.6.3",
193
194
  "set-function-length": "npm:@socketregistry/set-function-length@^1",
195
+ "shell-quote": "npm:shell-quote@^1",
194
196
  "side-channel": "npm:@socketregistry/side-channel@^1",
195
197
  "tiny-colors": "npm:yoctocolors-cjs@^2.1.2",
196
198
  "typedarray": "npm:@socketregistry/typedarray@^1",
@@ -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":"AAIA,OAAO,iBAAiB,MAAM,wCAAwC,CAAA;AAEtE,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,4CAA4C,EAAE,OAAO,CAAA;KACtD,CAAA;IACD,QAAQ,CAAC,SAAS,EAAE,aAAa,GAAG,SAAS,CAAA;IAC7C,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAA;IAC1B,QAAQ,CAAC,gBAAgB,EAAE,4BAA4B,CAAA;IACvD,QAAQ,CAAC,GAAG,EAAE,KAAK,CAAA;IACnB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,qBAAqB,EAAE,gDAAgD,CAAA;IAChF,QAAQ,CAAC,4CAA4C,EAAE,8CAA8C,CAAA;IACrG,QAAQ,CAAC,GAAG,EAAE,KAAK,CAAA;IACnB,QAAQ,CAAC,UAAU,EAAE,YAAY,CAAA;IACjC,QAAQ,CAAC,YAAY,EAAE,cAAc,CAAA;IACrC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAA;IAC9B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;IAC5B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;IAC7B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAA;IAChC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAA;IAC9B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;CAC7B,GAAG,OAAO,iBAAiB,CAAA;AAwE5B,QAAA,MAAM,SAAS,WA4Cd,CAAA"}
@@ -1,8 +0,0 @@
1
- /// <reference types="node" />
2
- import { SocketSdk } from '@socketsecurity/sdk';
3
- declare function createDebugLogger(printDebugLogs?: boolean): 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 colors = _socketInterop(require('yoctocolors-cjs'));
13
- var isUnicodeSupported = _socketInterop(require('is-unicode-supported'));
14
- var terminalLink = _socketInterop(require('terminal-link'));
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 constants = require('./constants.js');
21
- var fs = require('node:fs');
22
- var homedir = require('node:os');
23
- var path = require('node:path');
24
- var yoctoSpinner = require('@socketregistry/yocto-spinner');
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
- yoctoSpinner().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":"AAIA,OAAO,iBAAiB,MAAM,wCAAwC,CAAA;AAEtE,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,4CAA4C,EAAE,OAAO,CAAA;KACtD,CAAA;IACD,QAAQ,CAAC,SAAS,EAAE,aAAa,GAAG,SAAS,CAAA;IAC7C,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAA;IAC1B,QAAQ,CAAC,gBAAgB,EAAE,4BAA4B,CAAA;IACvD,QAAQ,CAAC,GAAG,EAAE,KAAK,CAAA;IACnB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,qBAAqB,EAAE,gDAAgD,CAAA;IAChF,QAAQ,CAAC,4CAA4C,EAAE,8CAA8C,CAAA;IACrG,QAAQ,CAAC,GAAG,EAAE,KAAK,CAAA;IACnB,QAAQ,CAAC,UAAU,EAAE,YAAY,CAAA;IACjC,QAAQ,CAAC,YAAY,EAAE,cAAc,CAAA;IACrC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAA;IAC9B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;IAC5B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;IAC7B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAA;IAChC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAA;IAC9B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;CAC7B,GAAG,OAAO,iBAAiB,CAAA;AAwE5B,QAAA,MAAM,SAAS,WA4Cd,CAAA"}
@@ -1,212 +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 colors = _socketInterop(require('yoctocolors-cjs'));
13
- var vendor = require('./vendor.js');
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 constants = require('./constants.js');
19
- var fs = require('node:fs');
20
- var os = require('node:os');
21
- var path = require('node:path');
22
- var yoctoSpinner = require('@socketregistry/yocto-spinner');
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
- yoctoSpinner().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;