@socketsecurity/cli 0.14.33 → 0.14.35
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/bin/cli.js +34 -4
- package/bin/npm-cli.js +3 -4
- package/bin/npx-cli.js +3 -4
- package/dist/constants.js +59 -0
- package/dist/module-sync/cli.d.ts +0 -1
- package/dist/module-sync/cli.js +637 -1423
- package/dist/module-sync/constants.d.ts +24 -21
- package/dist/module-sync/constants.d.ts.map +1 -0
- package/dist/module-sync/constants.js +2 -79
- package/dist/module-sync/npm-injection.js +116 -436
- package/dist/module-sync/path-resolve.js +24 -45
- package/dist/module-sync/sdk.js +69 -118
- package/dist/module-sync/shadow-bin.d.ts +2 -0
- package/dist/module-sync/shadow-bin.js +109 -0
- package/dist/require/cli.js +633 -1418
- package/dist/require/constants.d.ts.map +1 -0
- package/dist/require/constants.js +2 -79
- package/dist/require/npm-injection.js +116 -435
- package/dist/require/path-resolve.js +24 -45
- package/dist/require/sdk.js +67 -115
- package/dist/require/shadow-bin.js +109 -0
- package/dist/require/vendor.js +8300 -8798
- package/package.json +39 -54
- package/shadow-bin/npm +4 -0
- package/shadow-bin/npx +4 -0
- package/bin/shadow/module-sync/npm +0 -3
- package/bin/shadow/module-sync/npx +0 -3
- package/bin/shadow/require/npm +0 -3
- package/bin/shadow/require/npx +0 -3
- package/dist/module-sync/cli.d.ts.map +0 -1
- package/dist/module-sync/link.d.ts +0 -2
- package/dist/module-sync/link.js +0 -57
- package/dist/module-sync/npm-cli.d.ts +0 -2
- package/dist/module-sync/npm-cli.js +0 -97
- package/dist/module-sync/npx-cli.d.ts +0 -2
- package/dist/module-sync/npx-cli.js +0 -73
- package/dist/module-sync/vendor.js +0 -82
- package/dist/require/cli.d.ts +0 -3
- package/dist/require/cli.d.ts.map +0 -1
- package/dist/require/color-or-markdown.d.ts +0 -23
- package/dist/require/constants.d.ts +0 -21
- package/dist/require/errors.d.ts +0 -7
- package/dist/require/link.d.ts +0 -2
- package/dist/require/link.js +0 -57
- package/dist/require/npm-cli.d.ts +0 -2
- package/dist/require/npm-cli.js +0 -97
- package/dist/require/npm-injection.d.ts +0 -1
- package/dist/require/npx-cli.d.ts +0 -2
- package/dist/require/npx-cli.js +0 -73
- package/dist/require/path-resolve.d.ts +0 -8
- package/dist/require/sdk.d.ts +0 -8
- package/dist/require/settings.d.ts +0 -9
package/dist/module-sync/cli.js
CHANGED
|
@@ -1,90 +1,67 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
-
function
|
|
5
|
-
let
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
d = c++ === 0 && k === 'default' ? e[k] : void 0
|
|
10
|
-
if (!d) break
|
|
11
|
-
}
|
|
4
|
+
function _socketInterop(e) {
|
|
5
|
+
let c = 0
|
|
6
|
+
for (const k in e ?? {}) {
|
|
7
|
+
c = c === 0 && k === 'default' ? 1 : 0
|
|
8
|
+
if (!c && k !== '__esModule') break
|
|
12
9
|
}
|
|
13
|
-
return
|
|
10
|
+
return c ? e.default : e
|
|
14
11
|
}
|
|
15
12
|
|
|
16
|
-
var
|
|
17
|
-
var
|
|
18
|
-
var
|
|
19
|
-
var
|
|
20
|
-
var
|
|
21
|
-
var
|
|
22
|
-
var
|
|
23
|
-
var
|
|
24
|
-
var
|
|
25
|
-
var
|
|
26
|
-
var
|
|
27
|
-
var
|
|
28
|
-
var
|
|
29
|
-
var
|
|
30
|
-
var
|
|
31
|
-
var
|
|
32
|
-
var
|
|
33
|
-
var
|
|
34
|
-
var
|
|
35
|
-
var
|
|
36
|
-
var
|
|
37
|
-
var
|
|
38
|
-
var
|
|
39
|
-
var
|
|
40
|
-
var
|
|
41
|
-
var
|
|
42
|
-
var
|
|
43
|
-
var
|
|
44
|
-
var
|
|
45
|
-
var
|
|
46
|
-
var
|
|
47
|
-
var
|
|
48
|
-
var
|
|
49
|
-
var
|
|
50
|
-
var
|
|
51
|
-
var
|
|
52
|
-
var
|
|
53
|
-
var
|
|
54
|
-
var
|
|
55
|
-
var
|
|
56
|
-
var
|
|
57
|
-
var
|
|
58
|
-
var
|
|
59
|
-
var
|
|
60
|
-
var
|
|
61
|
-
var
|
|
62
|
-
var
|
|
63
|
-
|
|
64
|
-
var require$$2$8 = _interop(require('blessed-contrib/lib/widget/table'));
|
|
65
|
-
|
|
66
|
-
var cli$2 = {};
|
|
67
|
-
|
|
68
|
-
var cli$1 = {};
|
|
69
|
-
|
|
70
|
-
var commands = {};
|
|
71
|
-
|
|
72
|
-
var cdxgen = {};
|
|
73
|
-
|
|
74
|
-
Object.defineProperty(cdxgen, "__esModule", {
|
|
75
|
-
value: true
|
|
76
|
-
});
|
|
77
|
-
cdxgen.cdxgen = void 0;
|
|
78
|
-
var _nodeFs$3 = require$$0;
|
|
79
|
-
var _nodePath$6 = require$$1;
|
|
80
|
-
var _promiseSpawn$6 = require$$1$1;
|
|
81
|
-
var _yoctocolorsCjs$j = require$$1$2;
|
|
82
|
-
var _yargsParser = require$$4;
|
|
83
|
-
var _words$1 = require$$5;
|
|
84
|
-
var _constants$8 = constants.constants;
|
|
13
|
+
var node_url = require('node:url');
|
|
14
|
+
var ponyCause = _socketInterop(require('pony-cause'));
|
|
15
|
+
var updateNotifier = _socketInterop(require('tiny-updater'));
|
|
16
|
+
var colors = _socketInterop(require('yoctocolors-cjs'));
|
|
17
|
+
var fs = require('node:fs');
|
|
18
|
+
var path = require('node:path');
|
|
19
|
+
var yargsParse = _socketInterop(require('yargs-parser'));
|
|
20
|
+
var npm$1 = require('@socketsecurity/registry/lib/npm');
|
|
21
|
+
var words = require('@socketsecurity/registry/lib/words');
|
|
22
|
+
var constants = require('./constants.js');
|
|
23
|
+
var meow = _socketInterop(require('meow'));
|
|
24
|
+
var yoctoSpinner = require('@socketregistry/yocto-spinner');
|
|
25
|
+
var sdk = require('./sdk.js');
|
|
26
|
+
var prompts = require('@socketsecurity/registry/lib/prompts');
|
|
27
|
+
var isInteractive = _socketInterop(require('is-interactive'));
|
|
28
|
+
var terminalLink = _socketInterop(require('terminal-link'));
|
|
29
|
+
var spawn = _socketInterop(require('@npmcli/promise-spawn'));
|
|
30
|
+
var fs$1 = require('node:fs/promises');
|
|
31
|
+
var npa = _socketInterop(require('npm-package-arg'));
|
|
32
|
+
var semver = _socketInterop(require('semver'));
|
|
33
|
+
var tinyglobby = _socketInterop(require('tinyglobby'));
|
|
34
|
+
var yaml = _socketInterop(require('yaml'));
|
|
35
|
+
var registry = require('@socketsecurity/registry');
|
|
36
|
+
var objects = require('@socketsecurity/registry/lib/objects');
|
|
37
|
+
var packages = require('@socketsecurity/registry/lib/packages');
|
|
38
|
+
var promises = require('@socketsecurity/registry/lib/promises');
|
|
39
|
+
var regexps = require('@socketsecurity/registry/lib/regexps');
|
|
40
|
+
var strings = require('@socketsecurity/registry/lib/strings');
|
|
41
|
+
var browserslist = _socketInterop(require('browserslist'));
|
|
42
|
+
var which = _socketInterop(require('which'));
|
|
43
|
+
var hyrious__bun_lockb = require('@socketregistry/hyrious__bun.lockb');
|
|
44
|
+
var registryConstants = require('@socketsecurity/registry/lib/constants');
|
|
45
|
+
var betterAjvErrors = _socketInterop(require('@apideck/better-ajv-errors'));
|
|
46
|
+
var config = require('@socketsecurity/config');
|
|
47
|
+
var pathResolve = require('./path-resolve.js');
|
|
48
|
+
var homedir = require('node:os');
|
|
49
|
+
var readline = require('node:readline');
|
|
50
|
+
var node_process = require('node:process');
|
|
51
|
+
var readline$1 = require('node:readline/promises');
|
|
52
|
+
var open = _socketInterop(require('open'));
|
|
53
|
+
var chalkTable = _socketInterop(require('chalk-table'));
|
|
54
|
+
var ScreenWidget = _socketInterop(require('blessed/lib/widgets/screen'));
|
|
55
|
+
var BarChart = _socketInterop(require('blessed-contrib/lib/widget/charts/bar'));
|
|
56
|
+
var GridLayout = _socketInterop(require('blessed-contrib/lib/layout/grid'));
|
|
57
|
+
var LineChart = _socketInterop(require('blessed-contrib/lib/widget/charts/line'));
|
|
58
|
+
var util = require('node:util');
|
|
59
|
+
var TableWidget = _socketInterop(require('blessed-contrib/lib/widget/table'));
|
|
60
|
+
|
|
85
61
|
const {
|
|
86
|
-
|
|
87
|
-
|
|
62
|
+
cdxgenBinPath,
|
|
63
|
+
synpBinPath
|
|
64
|
+
} = constants;
|
|
88
65
|
const {
|
|
89
66
|
SBOM_SIGN_ALGORITHM,
|
|
90
67
|
// Algorithm. Example: RS512
|
|
@@ -187,32 +164,30 @@ function argvToArray(argv) {
|
|
|
187
164
|
}
|
|
188
165
|
return result;
|
|
189
166
|
}
|
|
190
|
-
cdxgen
|
|
167
|
+
const cdxgen = {
|
|
191
168
|
description: 'Create an SBOM with CycloneDX generator (cdxgen)',
|
|
192
169
|
async run(argv_) {
|
|
193
170
|
const yargv = {
|
|
194
|
-
...
|
|
171
|
+
...yargsParse(argv_, yargsConfig)
|
|
195
172
|
};
|
|
196
173
|
const unknown = yargv._;
|
|
197
174
|
const {
|
|
198
175
|
length: unknownLength
|
|
199
176
|
} = unknown;
|
|
200
177
|
if (unknownLength) {
|
|
201
|
-
console.error(`Unknown ${
|
|
178
|
+
console.error(`Unknown ${words.pluralize('argument', unknownLength)}: ${yargv._.join(', ')}`);
|
|
202
179
|
process.exitCode = 1;
|
|
203
180
|
return;
|
|
204
181
|
}
|
|
205
182
|
let cleanupPackageLock = false;
|
|
206
|
-
if (yargv.type !== 'yarn' && nodejsPlatformTypes.has(yargv.type) &&
|
|
207
|
-
if (
|
|
183
|
+
if (yargv.type !== 'yarn' && nodejsPlatformTypes.has(yargv.type) && fs.existsSync('./yarn.lock')) {
|
|
184
|
+
if (fs.existsSync('./package-lock.json')) {
|
|
208
185
|
yargv.type = 'npm';
|
|
209
186
|
} else {
|
|
210
187
|
// Use synp to create a package-lock.json from the yarn.lock,
|
|
211
188
|
// based on the node_modules folder, for a more accurate SBOM.
|
|
212
189
|
try {
|
|
213
|
-
await
|
|
214
|
-
shell: true
|
|
215
|
-
});
|
|
190
|
+
await npm$1.runBin(await fs.promises.realpath(synpBinPath), ['--source-file', './yarn.lock']);
|
|
216
191
|
yargv.type = 'npm';
|
|
217
192
|
cleanupPackageLock = true;
|
|
218
193
|
} catch {}
|
|
@@ -221,37 +196,28 @@ cdxgen.cdxgen = {
|
|
|
221
196
|
if (yargv.output === undefined) {
|
|
222
197
|
yargv.output = 'socket-cdx.json';
|
|
223
198
|
}
|
|
224
|
-
await
|
|
199
|
+
await npm$1.runBin(await fs.promises.realpath(cdxgenBinPath), argvToArray(yargv), {
|
|
225
200
|
env: {
|
|
226
201
|
NODE_ENV: '',
|
|
227
202
|
SBOM_SIGN_ALGORITHM,
|
|
228
203
|
SBOM_SIGN_PRIVATE_KEY,
|
|
229
204
|
SBOM_SIGN_PUBLIC_KEY
|
|
230
205
|
},
|
|
231
|
-
shell: true,
|
|
232
206
|
stdio: 'inherit'
|
|
233
207
|
});
|
|
234
208
|
if (cleanupPackageLock) {
|
|
235
209
|
try {
|
|
236
|
-
await
|
|
210
|
+
await fs.promises.rm('./package-lock.json');
|
|
237
211
|
} catch {}
|
|
238
212
|
}
|
|
239
|
-
const fullOutputPath =
|
|
240
|
-
if (
|
|
241
|
-
console.log(
|
|
213
|
+
const fullOutputPath = path.join(process.cwd(), yargv.output);
|
|
214
|
+
if (fs.existsSync(fullOutputPath)) {
|
|
215
|
+
console.log(colors.cyanBright(`${yargv.output} created!`));
|
|
242
216
|
}
|
|
243
217
|
}
|
|
244
218
|
};
|
|
245
219
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
var flags$1 = {};
|
|
249
|
-
|
|
250
|
-
Object.defineProperty(flags$1, "__esModule", {
|
|
251
|
-
value: true
|
|
252
|
-
});
|
|
253
|
-
flags$1.validationFlags = flags$1.outputFlags = flags$1.commonFlags = flags$1.commandFlags = void 0;
|
|
254
|
-
flags$1.commonFlags = {
|
|
220
|
+
const commonFlags = {
|
|
255
221
|
help: {
|
|
256
222
|
type: 'boolean',
|
|
257
223
|
default: false,
|
|
@@ -259,7 +225,7 @@ flags$1.commonFlags = {
|
|
|
259
225
|
description: 'Print this help.'
|
|
260
226
|
}
|
|
261
227
|
};
|
|
262
|
-
|
|
228
|
+
const commandFlags = {
|
|
263
229
|
enable: {
|
|
264
230
|
type: 'boolean',
|
|
265
231
|
default: false,
|
|
@@ -271,7 +237,7 @@ flags$1.commandFlags = {
|
|
|
271
237
|
description: 'Disables the Socket npm/npx wrapper'
|
|
272
238
|
}
|
|
273
239
|
};
|
|
274
|
-
|
|
240
|
+
const outputFlags = {
|
|
275
241
|
json: {
|
|
276
242
|
type: 'boolean',
|
|
277
243
|
shortFlag: 'j',
|
|
@@ -285,7 +251,7 @@ flags$1.outputFlags = {
|
|
|
285
251
|
description: 'Output result as markdown'
|
|
286
252
|
}
|
|
287
253
|
};
|
|
288
|
-
|
|
254
|
+
const validationFlags = {
|
|
289
255
|
all: {
|
|
290
256
|
type: 'boolean',
|
|
291
257
|
default: false,
|
|
@@ -298,28 +264,18 @@ flags$1.validationFlags = {
|
|
|
298
264
|
}
|
|
299
265
|
};
|
|
300
266
|
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
value: true
|
|
305
|
-
});
|
|
306
|
-
apiHelpers.handleAPIError = handleAPIError;
|
|
307
|
-
apiHelpers.handleApiCall = handleApiCall;
|
|
308
|
-
apiHelpers.handleUnsuccessfulApiResponse = handleUnsuccessfulApiResponse;
|
|
309
|
-
apiHelpers.queryAPI = queryAPI;
|
|
310
|
-
var _yoctocolorsCjs$i = require$$1$2;
|
|
311
|
-
var _ponyCause$4 = require$$4$1;
|
|
312
|
-
var _errors$l = sdk.errors;
|
|
313
|
-
var _constants$7 = constants.constants;
|
|
267
|
+
const {
|
|
268
|
+
API_V0_URL
|
|
269
|
+
} = constants;
|
|
314
270
|
function handleUnsuccessfulApiResponse(_name, result, spinner) {
|
|
315
271
|
// SocketSdkErrorType['error'] is not typed.
|
|
316
272
|
const resultErrorMessage = result.error?.message;
|
|
317
273
|
const message = typeof resultErrorMessage === 'string' ? resultErrorMessage : 'No error message returned';
|
|
318
274
|
if (result.status === 401 || result.status === 403) {
|
|
319
275
|
spinner.stop();
|
|
320
|
-
throw new
|
|
276
|
+
throw new sdk.AuthError(message);
|
|
321
277
|
}
|
|
322
|
-
spinner.error(`${
|
|
278
|
+
spinner.error(`${colors.bgRed(colors.white('API returned an error:'))} ${message}`);
|
|
323
279
|
process.exit(1);
|
|
324
280
|
}
|
|
325
281
|
async function handleApiCall(value, description) {
|
|
@@ -327,7 +283,7 @@ async function handleApiCall(value, description) {
|
|
|
327
283
|
try {
|
|
328
284
|
result = await value;
|
|
329
285
|
} catch (cause) {
|
|
330
|
-
throw new
|
|
286
|
+
throw new ponyCause.ErrorWithCause(`Failed ${description}`, {
|
|
331
287
|
cause
|
|
332
288
|
});
|
|
333
289
|
}
|
|
@@ -341,7 +297,7 @@ async function handleAPIError(code) {
|
|
|
341
297
|
}
|
|
342
298
|
}
|
|
343
299
|
async function queryAPI(path, apiKey) {
|
|
344
|
-
return await fetch(`${
|
|
300
|
+
return await fetch(`${API_V0_URL}/${path}`, {
|
|
345
301
|
method: 'GET',
|
|
346
302
|
headers: {
|
|
347
303
|
Authorization: `Basic ${btoa(`${apiKey}:${apiKey}`)}`
|
|
@@ -349,15 +305,6 @@ async function queryAPI(path, apiKey) {
|
|
|
349
305
|
});
|
|
350
306
|
}
|
|
351
307
|
|
|
352
|
-
var formatIssues = {};
|
|
353
|
-
|
|
354
|
-
var objects = {};
|
|
355
|
-
|
|
356
|
-
Object.defineProperty(objects, "__esModule", {
|
|
357
|
-
value: true
|
|
358
|
-
});
|
|
359
|
-
objects.objectSome = objectSome;
|
|
360
|
-
objects.pick = pick;
|
|
361
308
|
function objectSome(obj) {
|
|
362
309
|
for (const key in obj) {
|
|
363
310
|
if (obj[key]) {
|
|
@@ -374,13 +321,6 @@ function pick(input, keys) {
|
|
|
374
321
|
return result;
|
|
375
322
|
}
|
|
376
323
|
|
|
377
|
-
Object.defineProperty(formatIssues, "__esModule", {
|
|
378
|
-
value: true
|
|
379
|
-
});
|
|
380
|
-
formatIssues.formatSeverityCount = formatSeverityCount;
|
|
381
|
-
formatIssues.getSeverityCount = getSeverityCount;
|
|
382
|
-
var _misc$2 = sdk.misc;
|
|
383
|
-
var _objects$4 = objects;
|
|
384
324
|
const SEVERITIES_BY_ORDER = ['critical', 'high', 'middle', 'low'];
|
|
385
325
|
function getDesiredSeverities(lowestToInclude) {
|
|
386
326
|
const result = [];
|
|
@@ -399,10 +339,10 @@ function formatSeverityCount(severityCount) {
|
|
|
399
339
|
summary.push(`${severityCount[severity]} ${severity}`);
|
|
400
340
|
}
|
|
401
341
|
}
|
|
402
|
-
return
|
|
342
|
+
return sdk.stringJoinWithSeparateFinalSeparator(summary);
|
|
403
343
|
}
|
|
404
344
|
function getSeverityCount(issues, lowestToInclude) {
|
|
405
|
-
const severityCount =
|
|
345
|
+
const severityCount = pick({
|
|
406
346
|
low: 0,
|
|
407
347
|
middle: 0,
|
|
408
348
|
high: 0,
|
|
@@ -420,13 +360,6 @@ function getSeverityCount(issues, lowestToInclude) {
|
|
|
420
360
|
return severityCount;
|
|
421
361
|
}
|
|
422
362
|
|
|
423
|
-
var formatting = {};
|
|
424
|
-
|
|
425
|
-
Object.defineProperty(formatting, "__esModule", {
|
|
426
|
-
value: true
|
|
427
|
-
});
|
|
428
|
-
formatting.printFlagList = printFlagList;
|
|
429
|
-
formatting.printHelpList = printHelpList;
|
|
430
363
|
function printFlagList(list, indent, {
|
|
431
364
|
keyPrefix = '--',
|
|
432
365
|
padName
|
|
@@ -452,24 +385,10 @@ function printHelpList(list, indent, {
|
|
|
452
385
|
return result.trim();
|
|
453
386
|
}
|
|
454
387
|
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
info$1.info = void 0;
|
|
460
|
-
var _yoctocolorsCjs$h = require$$1$2;
|
|
461
|
-
var _meow$p = _interopRequireDefault$q(require$$2);
|
|
462
|
-
var _yoctoSpinner$l = require$$3;
|
|
463
|
-
var _constants$6 = constants.constants;
|
|
464
|
-
var _flags$k = flags$1;
|
|
465
|
-
var _apiHelpers$i = apiHelpers;
|
|
466
|
-
var _colorOrMarkdown$3 = sdk.colorOrMarkdown;
|
|
467
|
-
var _errors$k = sdk.errors;
|
|
468
|
-
var _formatIssues$1 = formatIssues;
|
|
469
|
-
var _formatting$m = formatting;
|
|
470
|
-
var _objects$3 = objects;
|
|
471
|
-
var _sdk$j = sdk.sdk;
|
|
472
|
-
const info = info$1.info = {
|
|
388
|
+
const {
|
|
389
|
+
SOCKET_PUBLIC_API_KEY: SOCKET_PUBLIC_API_KEY$1
|
|
390
|
+
} = constants;
|
|
391
|
+
const info = {
|
|
473
392
|
description: 'Look up info regarding a package',
|
|
474
393
|
async run(argv, importMeta, {
|
|
475
394
|
parentName
|
|
@@ -478,7 +397,7 @@ const info = info$1.info = {
|
|
|
478
397
|
const commandContext = setupCommand$m(name, info.description, argv, importMeta);
|
|
479
398
|
if (commandContext) {
|
|
480
399
|
const spinnerText = commandContext.pkgVersion === 'latest' ? `Looking up data for the latest version of ${commandContext.pkgName}` : `Looking up data for version ${commandContext.pkgVersion} of ${commandContext.pkgName}`;
|
|
481
|
-
const spinner =
|
|
400
|
+
const spinner = yoctoSpinner({
|
|
482
401
|
text: spinnerText
|
|
483
402
|
}).start();
|
|
484
403
|
const packageData = await fetchPackageData(commandContext.pkgName, commandContext.pkgVersion, commandContext, spinner);
|
|
@@ -496,16 +415,16 @@ const info = info$1.info = {
|
|
|
496
415
|
|
|
497
416
|
function setupCommand$m(name, description, argv, importMeta) {
|
|
498
417
|
const flags = {
|
|
499
|
-
...
|
|
500
|
-
...
|
|
501
|
-
...
|
|
418
|
+
...commonFlags,
|
|
419
|
+
...outputFlags,
|
|
420
|
+
...validationFlags
|
|
502
421
|
};
|
|
503
|
-
const cli = (
|
|
422
|
+
const cli = meow(`
|
|
504
423
|
Usage
|
|
505
424
|
$ ${name} <name>
|
|
506
425
|
|
|
507
426
|
Options
|
|
508
|
-
${
|
|
427
|
+
${printFlagList(flags, 6)}
|
|
509
428
|
|
|
510
429
|
Examples
|
|
511
430
|
$ ${name} webtorrent
|
|
@@ -517,7 +436,7 @@ function setupCommand$m(name, description, argv, importMeta) {
|
|
|
517
436
|
flags
|
|
518
437
|
});
|
|
519
438
|
if (cli.input.length > 1) {
|
|
520
|
-
throw new
|
|
439
|
+
throw new sdk.InputError('Only one package lookup supported at once');
|
|
521
440
|
}
|
|
522
441
|
const {
|
|
523
442
|
0: rawPkgName = ''
|
|
@@ -545,16 +464,16 @@ function setupCommand$m(name, description, argv, importMeta) {
|
|
|
545
464
|
async function fetchPackageData(pkgName, pkgVersion, {
|
|
546
465
|
includeAllIssues
|
|
547
466
|
}, spinner) {
|
|
548
|
-
const socketSdk = await
|
|
549
|
-
const result = await
|
|
550
|
-
const scoreResult = await
|
|
467
|
+
const socketSdk = await sdk.setupSdk(sdk.getDefaultKey() ?? SOCKET_PUBLIC_API_KEY$1);
|
|
468
|
+
const result = await handleApiCall(socketSdk.getIssuesByNPMPackage(pkgName, pkgVersion), 'looking up package');
|
|
469
|
+
const scoreResult = await handleApiCall(socketSdk.getScoreByNPMPackage(pkgName, pkgVersion), 'looking up package score');
|
|
551
470
|
if (result.success === false) {
|
|
552
|
-
return
|
|
471
|
+
return handleUnsuccessfulApiResponse('getIssuesByNPMPackage', result, spinner);
|
|
553
472
|
}
|
|
554
473
|
if (scoreResult.success === false) {
|
|
555
|
-
return
|
|
474
|
+
return handleUnsuccessfulApiResponse('getScoreByNPMPackage', scoreResult, spinner);
|
|
556
475
|
}
|
|
557
|
-
const severityCount =
|
|
476
|
+
const severityCount = getSeverityCount(result.data, includeAllIssues ? undefined : 'high');
|
|
558
477
|
return {
|
|
559
478
|
data: result.data,
|
|
560
479
|
severityCount,
|
|
@@ -586,13 +505,13 @@ function formatPackageDataOutput({
|
|
|
586
505
|
};
|
|
587
506
|
Object.entries(scoreResult).map(score => console.log(`- ${score[0]}: ${formatScore(score[1])}`));
|
|
588
507
|
console.log('\n');
|
|
589
|
-
if (
|
|
590
|
-
spinner[strict ? 'error' : 'success'](`Package has these issues: ${
|
|
508
|
+
if (objectSome(severityCount)) {
|
|
509
|
+
spinner[strict ? 'error' : 'success'](`Package has these issues: ${formatSeverityCount(severityCount)}`);
|
|
591
510
|
formatPackageIssuesDetails(data, outputMarkdown);
|
|
592
511
|
} else {
|
|
593
512
|
spinner.success('Package has no issues');
|
|
594
513
|
}
|
|
595
|
-
const format = new
|
|
514
|
+
const format = new sdk.ColorOrMarkdown(!!outputMarkdown);
|
|
596
515
|
const url = `https://socket.dev/npm/package/${pkgName}/overview/${pkgVersion}`;
|
|
597
516
|
console.log('\n');
|
|
598
517
|
if (pkgVersion === 'latest') {
|
|
@@ -605,10 +524,10 @@ function formatPackageDataOutput({
|
|
|
605
524
|
})}`);
|
|
606
525
|
}
|
|
607
526
|
if (!outputMarkdown) {
|
|
608
|
-
console.log(
|
|
527
|
+
console.log(colors.dim(`\nOr rerun ${colors.italic(name)} using the ${colors.italic('--json')} flag to get full JSON output`));
|
|
609
528
|
}
|
|
610
529
|
}
|
|
611
|
-
if (strict &&
|
|
530
|
+
if (strict && objectSome(severityCount)) {
|
|
612
531
|
process.exit(1);
|
|
613
532
|
}
|
|
614
533
|
}
|
|
@@ -630,7 +549,7 @@ function formatPackageIssuesDetails(packageData, outputMarkdown) {
|
|
|
630
549
|
}
|
|
631
550
|
return acc;
|
|
632
551
|
}, {});
|
|
633
|
-
const format = new
|
|
552
|
+
const format = new sdk.ColorOrMarkdown(!!outputMarkdown);
|
|
634
553
|
for (const issue of Object.keys(uniqueIssues)) {
|
|
635
554
|
const issueWithLink = format.hyperlink(`${uniqueIssues[issue]?.label}`, `https://socket.dev/npm/issue/${issue}`, {
|
|
636
555
|
fallbackToUrl: true
|
|
@@ -644,32 +563,16 @@ function formatPackageIssuesDetails(packageData, outputMarkdown) {
|
|
|
644
563
|
}
|
|
645
564
|
function formatScore(score) {
|
|
646
565
|
if (score > 80) {
|
|
647
|
-
return
|
|
566
|
+
return colors.green(`${score}`);
|
|
648
567
|
} else if (score < 80 && score > 60) {
|
|
649
|
-
return
|
|
568
|
+
return colors.yellow(`${score}`);
|
|
650
569
|
}
|
|
651
|
-
return
|
|
570
|
+
return colors.red(`${score}`);
|
|
652
571
|
}
|
|
653
572
|
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
Object.defineProperty(login, "__esModule", {
|
|
658
|
-
value: true
|
|
659
|
-
});
|
|
660
|
-
login.login = void 0;
|
|
661
|
-
var _confirm = require$$1$3;
|
|
662
|
-
var _password = require$$1$4;
|
|
663
|
-
var _select$1 = require$$3$3;
|
|
664
|
-
var _isInteractive = _interopRequireDefault$p(require$$3$1);
|
|
665
|
-
var _meow$o = _interopRequireDefault$p(require$$2);
|
|
666
|
-
var _yoctoSpinner$k = require$$3;
|
|
667
|
-
var _terminalLink = _interopRequireDefault$p(require$$3$2);
|
|
668
|
-
var _constants$5 = constants.constants;
|
|
669
|
-
var _errors$j = sdk.errors;
|
|
670
|
-
var _formatting$l = formatting;
|
|
671
|
-
var _sdk$i = sdk.sdk;
|
|
672
|
-
var _settings$1 = sdk.settings;
|
|
573
|
+
const {
|
|
574
|
+
SOCKET_PUBLIC_API_KEY
|
|
575
|
+
} = constants;
|
|
673
576
|
const description$7 = 'Socket API login';
|
|
674
577
|
const flags = {
|
|
675
578
|
apiBaseUrl: {
|
|
@@ -684,20 +587,20 @@ const flags = {
|
|
|
684
587
|
function nonNullish(value) {
|
|
685
588
|
return value !== null && value !== undefined;
|
|
686
589
|
}
|
|
687
|
-
login
|
|
590
|
+
const login = {
|
|
688
591
|
description: description$7,
|
|
689
592
|
async run(argv, importMeta, {
|
|
690
593
|
parentName
|
|
691
594
|
}) {
|
|
692
595
|
const name = `${parentName} login`;
|
|
693
|
-
const cli = (
|
|
596
|
+
const cli = meow(`
|
|
694
597
|
Usage
|
|
695
598
|
$ ${name}
|
|
696
599
|
|
|
697
600
|
Logs into the Socket API by prompting for an API key
|
|
698
601
|
|
|
699
602
|
Options
|
|
700
|
-
${
|
|
603
|
+
${printFlagList({
|
|
701
604
|
'api-base-url': flags['apiBaseUrl'].description,
|
|
702
605
|
'api-proxy': flags['apiProxy'].description
|
|
703
606
|
}, 8)}
|
|
@@ -718,25 +621,25 @@ login.login = {
|
|
|
718
621
|
cli.showHelp();
|
|
719
622
|
return;
|
|
720
623
|
}
|
|
721
|
-
if (!(
|
|
722
|
-
throw new
|
|
624
|
+
if (!isInteractive()) {
|
|
625
|
+
throw new sdk.InputError('Cannot prompt for credentials in a non-interactive shell');
|
|
723
626
|
}
|
|
724
|
-
const apiKey = (await
|
|
725
|
-
message: `Enter your ${(
|
|
726
|
-
})) ||
|
|
627
|
+
const apiKey = (await prompts.password({
|
|
628
|
+
message: `Enter your ${terminalLink('Socket.dev API key', 'https://docs.socket.dev/docs/api-keys')} (leave blank for a public key)`
|
|
629
|
+
})) || SOCKET_PUBLIC_API_KEY;
|
|
727
630
|
let apiBaseUrl = cli.flags['apiBaseUrl'];
|
|
728
|
-
apiBaseUrl ??=
|
|
631
|
+
apiBaseUrl ??= sdk.getSetting('apiBaseUrl') ?? undefined;
|
|
729
632
|
let apiProxy = cli.flags['apiProxy'];
|
|
730
|
-
apiProxy ??=
|
|
731
|
-
const spinner =
|
|
633
|
+
apiProxy ??= sdk.getSetting('apiProxy') ?? undefined;
|
|
634
|
+
const spinner = yoctoSpinner({
|
|
732
635
|
text: 'Verifying API key...'
|
|
733
636
|
}).start();
|
|
734
637
|
let orgs;
|
|
735
638
|
try {
|
|
736
|
-
const sdk = await
|
|
737
|
-
const result = await sdk.getOrganizations();
|
|
639
|
+
const sdk$1 = await sdk.setupSdk(apiKey, apiBaseUrl, apiProxy);
|
|
640
|
+
const result = await sdk$1.getOrganizations();
|
|
738
641
|
if (!result.success) {
|
|
739
|
-
throw new
|
|
642
|
+
throw new sdk.AuthError();
|
|
740
643
|
}
|
|
741
644
|
orgs = result.data;
|
|
742
645
|
spinner.success('API key verified');
|
|
@@ -750,7 +653,7 @@ login.login = {
|
|
|
750
653
|
}));
|
|
751
654
|
let enforcedOrgs = [];
|
|
752
655
|
if (enforcedChoices.length > 1) {
|
|
753
|
-
const id = await
|
|
656
|
+
const id = await prompts.select({
|
|
754
657
|
message: "Which organization's policies should Socket enforce system-wide?",
|
|
755
658
|
choices: enforcedChoices.concat({
|
|
756
659
|
name: 'None',
|
|
@@ -762,7 +665,7 @@ login.login = {
|
|
|
762
665
|
enforcedOrgs = [id];
|
|
763
666
|
}
|
|
764
667
|
} else if (enforcedChoices.length) {
|
|
765
|
-
const confirmOrg = await
|
|
668
|
+
const confirmOrg = await prompts.confirm({
|
|
766
669
|
message: `Should Socket enforce ${enforcedChoices[0]?.name}'s security policies system-wide?`,
|
|
767
670
|
default: true
|
|
768
671
|
});
|
|
@@ -773,33 +676,23 @@ login.login = {
|
|
|
773
676
|
}
|
|
774
677
|
}
|
|
775
678
|
}
|
|
776
|
-
|
|
777
|
-
const oldKey =
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
679
|
+
sdk.updateSetting('enforcedOrgs', enforcedOrgs);
|
|
680
|
+
const oldKey = sdk.getSetting('apiKey');
|
|
681
|
+
sdk.updateSetting('apiKey', apiKey);
|
|
682
|
+
sdk.updateSetting('apiBaseUrl', apiBaseUrl);
|
|
683
|
+
sdk.updateSetting('apiProxy', apiProxy);
|
|
781
684
|
spinner.success(`API credentials ${oldKey ? 'updated' : 'set'}`);
|
|
782
685
|
}
|
|
783
686
|
};
|
|
784
687
|
|
|
785
|
-
var logout = {};
|
|
786
|
-
|
|
787
|
-
var _interopRequireDefault$o = vendor.interopRequireDefault.default;
|
|
788
|
-
Object.defineProperty(logout, "__esModule", {
|
|
789
|
-
value: true
|
|
790
|
-
});
|
|
791
|
-
logout.logout = void 0;
|
|
792
|
-
var _meow$n = _interopRequireDefault$o(require$$2);
|
|
793
|
-
var _yoctoSpinner$j = require$$3;
|
|
794
|
-
var _settings = sdk.settings;
|
|
795
688
|
const description$6 = 'Socket API logout';
|
|
796
|
-
logout
|
|
689
|
+
const logout = {
|
|
797
690
|
description: description$6,
|
|
798
691
|
async run(argv, importMeta, {
|
|
799
692
|
parentName
|
|
800
693
|
}) {
|
|
801
694
|
const name = `${parentName} logout`;
|
|
802
|
-
const cli = (
|
|
695
|
+
const cli = meow(`
|
|
803
696
|
Usage
|
|
804
697
|
$ ${name}
|
|
805
698
|
|
|
@@ -820,30 +713,29 @@ logout.logout = {
|
|
|
820
713
|
cli.showHelp();
|
|
821
714
|
return;
|
|
822
715
|
}
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
716
|
+
sdk.updateSetting('apiKey', null);
|
|
717
|
+
sdk.updateSetting('apiBaseUrl', null);
|
|
718
|
+
sdk.updateSetting('apiProxy', null);
|
|
719
|
+
sdk.updateSetting('enforcedOrgs', null);
|
|
720
|
+
yoctoSpinner().success('Successfully logged out');
|
|
828
721
|
}
|
|
829
722
|
};
|
|
830
723
|
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
}
|
|
836
|
-
npm.npm = void 0;
|
|
837
|
-
var _nodePath$5 = require$$1;
|
|
838
|
-
var _promiseSpawn$5 = require$$1$1;
|
|
839
|
-
var _constants$4 = constants.constants;
|
|
724
|
+
const {
|
|
725
|
+
abortSignal: abortSignal$4,
|
|
726
|
+
execPath: execPath$2,
|
|
727
|
+
rootBinPath: rootBinPath$2
|
|
728
|
+
} = constants;
|
|
840
729
|
const description$5 = 'npm wrapper functionality';
|
|
841
|
-
npm
|
|
730
|
+
const npm = {
|
|
842
731
|
description: description$5,
|
|
843
732
|
async run(argv, _importMeta, _ctx) {
|
|
844
|
-
const wrapperPath =
|
|
733
|
+
const wrapperPath = path.join(rootBinPath$2, 'npm-cli.js');
|
|
845
734
|
process.exitCode = 1;
|
|
846
|
-
const spawnPromise =
|
|
735
|
+
const spawnPromise = spawn(execPath$2, [
|
|
736
|
+
// Lazily access constants.nodeNoWarningsFlags.
|
|
737
|
+
...constants.nodeNoWarningsFlags, wrapperPath, ...argv], {
|
|
738
|
+
signal: abortSignal$4,
|
|
847
739
|
stdio: 'inherit'
|
|
848
740
|
});
|
|
849
741
|
spawnPromise.process.on('exit', (code, signal) => {
|
|
@@ -857,22 +749,21 @@ npm.npm = {
|
|
|
857
749
|
}
|
|
858
750
|
};
|
|
859
751
|
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
}
|
|
865
|
-
npx.npx = void 0;
|
|
866
|
-
var _nodePath$4 = require$$1;
|
|
867
|
-
var _promiseSpawn$4 = require$$1$1;
|
|
868
|
-
var _constants$3 = constants.constants;
|
|
752
|
+
const {
|
|
753
|
+
abortSignal: abortSignal$3,
|
|
754
|
+
execPath: execPath$1,
|
|
755
|
+
rootBinPath: rootBinPath$1
|
|
756
|
+
} = constants;
|
|
869
757
|
const description$4 = 'npx wrapper functionality';
|
|
870
|
-
npx
|
|
758
|
+
const npx = {
|
|
871
759
|
description: description$4,
|
|
872
760
|
async run(argv, _importMeta, _ctx) {
|
|
873
|
-
const wrapperPath =
|
|
761
|
+
const wrapperPath = path.join(rootBinPath$1, 'npx-cli.js');
|
|
874
762
|
process.exitCode = 1;
|
|
875
|
-
const spawnPromise =
|
|
763
|
+
const spawnPromise = spawn(execPath$1, [
|
|
764
|
+
// Lazily access constants.nodeNoWarningsFlags.
|
|
765
|
+
...constants.nodeNoWarningsFlags, wrapperPath, ...argv], {
|
|
766
|
+
abortSignal: abortSignal$3,
|
|
876
767
|
stdio: 'inherit'
|
|
877
768
|
});
|
|
878
769
|
spawnPromise.process.on('exit', (code, signal) => {
|
|
@@ -886,80 +777,49 @@ npx.npx = {
|
|
|
886
777
|
}
|
|
887
778
|
};
|
|
888
779
|
|
|
889
|
-
var optimize$1 = {};
|
|
890
|
-
|
|
891
|
-
var fs = {};
|
|
892
|
-
|
|
893
|
-
Object.defineProperty(fs, "__esModule", {
|
|
894
|
-
value: true
|
|
895
|
-
});
|
|
896
|
-
fs.existsSync = existsSync;
|
|
897
|
-
fs.findUp = findUp;
|
|
898
|
-
fs.readFileBinary = readFileBinary;
|
|
899
|
-
fs.readFileUtf8 = readFileUtf8;
|
|
900
|
-
var _nodeFs$2 = require$$0;
|
|
901
|
-
var _nodePath$3 = require$$1;
|
|
902
780
|
function existsSync(filepath) {
|
|
903
781
|
try {
|
|
904
|
-
return filepath ?
|
|
782
|
+
return filepath ? fs.existsSync(filepath) : false;
|
|
905
783
|
} catch {}
|
|
906
784
|
return false;
|
|
907
785
|
}
|
|
908
786
|
async function findUp(name, {
|
|
909
787
|
cwd = process.cwd()
|
|
910
788
|
}) {
|
|
911
|
-
let dir =
|
|
789
|
+
let dir = path.resolve(cwd);
|
|
912
790
|
const {
|
|
913
791
|
root
|
|
914
|
-
} =
|
|
792
|
+
} = path.parse(dir);
|
|
915
793
|
const names = [name].flat();
|
|
916
794
|
while (dir && dir !== root) {
|
|
917
795
|
for (const name of names) {
|
|
918
|
-
const filePath =
|
|
796
|
+
const filePath = path.join(dir, name);
|
|
919
797
|
try {
|
|
920
798
|
// eslint-disable-next-line no-await-in-loop
|
|
921
|
-
const stats = await
|
|
799
|
+
const stats = await fs.promises.stat(filePath);
|
|
922
800
|
if (stats.isFile()) {
|
|
923
801
|
return filePath;
|
|
924
802
|
}
|
|
925
803
|
} catch {}
|
|
926
804
|
}
|
|
927
|
-
dir =
|
|
805
|
+
dir = path.dirname(dir);
|
|
928
806
|
}
|
|
929
807
|
return undefined;
|
|
930
808
|
}
|
|
931
809
|
async function readFileBinary(filepath, options) {
|
|
932
|
-
return await
|
|
810
|
+
return await fs.promises.readFile(filepath, {
|
|
933
811
|
...options,
|
|
934
812
|
encoding: 'binary'
|
|
935
813
|
});
|
|
936
814
|
}
|
|
937
815
|
async function readFileUtf8(filepath, options) {
|
|
938
|
-
return await
|
|
816
|
+
return await fs.promises.readFile(filepath, {
|
|
939
817
|
...options,
|
|
940
818
|
encoding: 'utf8'
|
|
941
819
|
});
|
|
942
820
|
}
|
|
943
821
|
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
Object.defineProperty(packageManagerDetector, "__esModule", {
|
|
947
|
-
value: true
|
|
948
|
-
});
|
|
949
|
-
packageManagerDetector.AGENTS = void 0;
|
|
950
|
-
packageManagerDetector.detect = detect;
|
|
951
|
-
var _nodePath$2 = require$$1;
|
|
952
|
-
var _promiseSpawn$3 = require$$1$1;
|
|
953
|
-
var _browserslist = require$$2$1;
|
|
954
|
-
var _semver$1 = require$$4$2;
|
|
955
|
-
var _which = require$$4$4;
|
|
956
|
-
var _hyrious__bun = require$$5$1;
|
|
957
|
-
var _constants$2 = require$$3$4;
|
|
958
|
-
var _objects$2 = require$$7;
|
|
959
|
-
var _packages$1 = require$$8;
|
|
960
|
-
var _strings$1 = require$$4$3;
|
|
961
|
-
var _fs$1 = fs;
|
|
962
|
-
const AGENTS = packageManagerDetector.AGENTS = ['bun', 'npm', 'pnpm', 'yarn/berry', 'yarn/classic', 'vlt'];
|
|
822
|
+
const AGENTS = ['bun', 'npm', 'pnpm', 'yarn/berry', 'yarn/classic', 'vlt'];
|
|
963
823
|
const {
|
|
964
824
|
compare: alphanumericComparator
|
|
965
825
|
} = new Intl.Collator(undefined, {
|
|
@@ -967,16 +827,16 @@ const {
|
|
|
967
827
|
sensitivity: 'base'
|
|
968
828
|
});
|
|
969
829
|
async function getAgentExecPath(agent) {
|
|
970
|
-
return (await
|
|
830
|
+
return (await which(agent, {
|
|
971
831
|
nothrow: true
|
|
972
832
|
})) ?? agent;
|
|
973
833
|
}
|
|
974
834
|
async function getAgentVersion(agentExecPath, cwd) {
|
|
975
835
|
let result;
|
|
976
836
|
try {
|
|
977
|
-
result =
|
|
837
|
+
result = semver.coerce(
|
|
978
838
|
// All package managers support the "--version" flag.
|
|
979
|
-
(await
|
|
839
|
+
(await spawn(agentExecPath, ['--version'], {
|
|
980
840
|
cwd
|
|
981
841
|
})).stdout) ?? undefined;
|
|
982
842
|
} catch {}
|
|
@@ -1010,22 +870,22 @@ const readLockFileByAgent = (() => {
|
|
|
1010
870
|
return undefined;
|
|
1011
871
|
};
|
|
1012
872
|
}
|
|
1013
|
-
const defaultReader = wrapReader(async lockPath => await
|
|
873
|
+
const defaultReader = wrapReader(async lockPath => await readFileUtf8(lockPath));
|
|
1014
874
|
return {
|
|
1015
875
|
bun: wrapReader(async (lockPath, agentExecPath) => {
|
|
1016
876
|
let lockBuffer;
|
|
1017
877
|
try {
|
|
1018
|
-
lockBuffer = await
|
|
878
|
+
lockBuffer = await readFileBinary(lockPath);
|
|
1019
879
|
} catch {
|
|
1020
880
|
return undefined;
|
|
1021
881
|
}
|
|
1022
882
|
try {
|
|
1023
|
-
return
|
|
883
|
+
return hyrious__bun_lockb.parse(lockBuffer);
|
|
1024
884
|
} catch {}
|
|
1025
885
|
// To print a Yarn lockfile to your console without writing it to disk
|
|
1026
886
|
// use `bun bun.lockb`.
|
|
1027
887
|
// https://bun.sh/guides/install/yarnlock
|
|
1028
|
-
return (await
|
|
888
|
+
return (await spawn(agentExecPath, [lockPath])).stdout.trim();
|
|
1029
889
|
}),
|
|
1030
890
|
npm: defaultReader,
|
|
1031
891
|
pnpm: defaultReader,
|
|
@@ -1038,21 +898,21 @@ async function detect({
|
|
|
1038
898
|
cwd = process.cwd(),
|
|
1039
899
|
onUnknown
|
|
1040
900
|
} = {}) {
|
|
1041
|
-
let lockPath = await
|
|
901
|
+
let lockPath = await findUp(Object.keys(LOCKS), {
|
|
1042
902
|
cwd
|
|
1043
903
|
});
|
|
1044
904
|
const isHiddenLockFile = lockPath?.endsWith('.package-lock.json') ?? false;
|
|
1045
|
-
const pkgJsonPath = lockPath ?
|
|
905
|
+
const pkgJsonPath = lockPath ? path.resolve(lockPath, `${isHiddenLockFile ? '../' : ''}../package.json`) : await findUp('package.json', {
|
|
1046
906
|
cwd
|
|
1047
907
|
});
|
|
1048
|
-
const pkgPath =
|
|
1049
|
-
const editablePkgJson = pkgPath ? await
|
|
908
|
+
const pkgPath = existsSync(pkgJsonPath) ? path.dirname(pkgJsonPath) : undefined;
|
|
909
|
+
const editablePkgJson = pkgPath ? await packages.readPackageJson(pkgPath, {
|
|
1050
910
|
editable: true
|
|
1051
911
|
}) : undefined;
|
|
1052
912
|
const pkgJson = editablePkgJson?.content;
|
|
1053
913
|
// Read Corepack `packageManager` field in package.json:
|
|
1054
914
|
// https://nodejs.org/api/packages.html#packagemanager
|
|
1055
|
-
const pkgManager =
|
|
915
|
+
const pkgManager = strings.isNonEmptyString(pkgJson?.packageManager) ? pkgJson.packageManager : undefined;
|
|
1056
916
|
let agent;
|
|
1057
917
|
let agentVersion;
|
|
1058
918
|
if (pkgManager) {
|
|
@@ -1062,12 +922,12 @@ async function detect({
|
|
|
1062
922
|
const version = pkgManager.slice(atSignIndex + 1);
|
|
1063
923
|
if (version && AGENTS.includes(name)) {
|
|
1064
924
|
agent = name;
|
|
1065
|
-
agentVersion =
|
|
925
|
+
agentVersion = semver.coerce(version) ?? undefined;
|
|
1066
926
|
}
|
|
1067
927
|
}
|
|
1068
928
|
}
|
|
1069
929
|
if (agent === undefined && !isHiddenLockFile && typeof pkgJsonPath === 'string' && typeof lockPath === 'string') {
|
|
1070
|
-
agent = LOCKS[
|
|
930
|
+
agent = LOCKS[path.basename(lockPath)];
|
|
1071
931
|
}
|
|
1072
932
|
if (agent === undefined) {
|
|
1073
933
|
agent = 'npm';
|
|
@@ -1087,35 +947,35 @@ async function detect({
|
|
|
1087
947
|
};
|
|
1088
948
|
let lockSrc;
|
|
1089
949
|
// Lazily access constants.maintainedNodeVersions.
|
|
1090
|
-
let minimumNodeVersion =
|
|
950
|
+
let minimumNodeVersion = registryConstants.maintainedNodeVersions.previous;
|
|
1091
951
|
if (pkgJson) {
|
|
1092
952
|
const browserField = pkgJson.browser;
|
|
1093
|
-
if (
|
|
953
|
+
if (strings.isNonEmptyString(browserField) || objects.isObjectObject(browserField)) {
|
|
1094
954
|
targets.browser = true;
|
|
1095
955
|
}
|
|
1096
956
|
const nodeRange = pkgJson.engines?.['node'];
|
|
1097
|
-
if (
|
|
1098
|
-
const coerced =
|
|
1099
|
-
if (coerced &&
|
|
957
|
+
if (strings.isNonEmptyString(nodeRange)) {
|
|
958
|
+
const coerced = semver.coerce(nodeRange);
|
|
959
|
+
if (coerced && semver.lt(coerced, minimumNodeVersion)) {
|
|
1100
960
|
minimumNodeVersion = coerced.version;
|
|
1101
961
|
}
|
|
1102
962
|
}
|
|
1103
963
|
const browserslistQuery = pkgJson['browserslist'];
|
|
1104
964
|
if (Array.isArray(browserslistQuery)) {
|
|
1105
|
-
const browserslistTargets =
|
|
965
|
+
const browserslistTargets = browserslist(browserslistQuery).map(s => s.toLowerCase()).sort(alphanumericComparator);
|
|
1106
966
|
const browserslistNodeTargets = browserslistTargets.filter(v => v.startsWith('node ')).map(v => v.slice(5 /*'node '.length*/));
|
|
1107
967
|
if (!targets.browser && browserslistTargets.length) {
|
|
1108
968
|
targets.browser = browserslistTargets.length !== browserslistNodeTargets.length;
|
|
1109
969
|
}
|
|
1110
970
|
if (browserslistNodeTargets.length) {
|
|
1111
|
-
const coerced =
|
|
1112
|
-
if (coerced &&
|
|
971
|
+
const coerced = semver.coerce(browserslistNodeTargets[0]);
|
|
972
|
+
if (coerced && semver.lt(coerced, minimumNodeVersion)) {
|
|
1113
973
|
minimumNodeVersion = coerced.version;
|
|
1114
974
|
}
|
|
1115
975
|
}
|
|
1116
976
|
}
|
|
1117
977
|
// Lazily access constants.maintainedNodeVersions.
|
|
1118
|
-
targets.node =
|
|
978
|
+
targets.node = registryConstants.maintainedNodeVersions.some(v => semver.satisfies(v, `>=${minimumNodeVersion}`));
|
|
1119
979
|
lockSrc = typeof lockPath === 'string' ? await readLockFileByAgent[agent](lockPath, agentExecPath) : undefined;
|
|
1120
980
|
} else {
|
|
1121
981
|
lockPath = undefined;
|
|
@@ -1135,39 +995,19 @@ async function detect({
|
|
|
1135
995
|
};
|
|
1136
996
|
}
|
|
1137
997
|
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
var _nodePath$1 = require$$1;
|
|
1145
|
-
var _promiseSpawn$2 = require$$1$1;
|
|
1146
|
-
var _meow$m = _interopRequireDefault$n(require$$2);
|
|
1147
|
-
var _npmPackageArg = require$$5$2;
|
|
1148
|
-
var _yoctoSpinner$i = require$$3;
|
|
1149
|
-
var _semver = require$$4$2;
|
|
1150
|
-
var _tinyglobby = require$$8$1;
|
|
1151
|
-
var _yaml = require$$9;
|
|
1152
|
-
var _registry = require$$10;
|
|
1153
|
-
var _objects$1 = require$$7;
|
|
1154
|
-
var _packages = require$$8;
|
|
1155
|
-
var _promises2 = require$$13;
|
|
1156
|
-
var _regexps = require$$14;
|
|
1157
|
-
var _strings = require$$4$3;
|
|
1158
|
-
var _words = require$$5;
|
|
1159
|
-
var _constants$1 = constants.constants;
|
|
1160
|
-
var _flags$j = flags$1;
|
|
1161
|
-
var _formatting$k = formatting;
|
|
1162
|
-
var _fs = fs;
|
|
1163
|
-
var _packageManagerDetector = packageManagerDetector;
|
|
998
|
+
const {
|
|
999
|
+
UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE,
|
|
1000
|
+
abortSignal: abortSignal$2,
|
|
1001
|
+
execPath,
|
|
1002
|
+
rootBinPath
|
|
1003
|
+
} = constants;
|
|
1164
1004
|
const COMMAND_TITLE = 'Socket Optimize';
|
|
1165
1005
|
const OVERRIDES_FIELD_NAME = 'overrides';
|
|
1166
1006
|
const NPM_OVERRIDE_PR_URL = 'https://github.com/npm/cli/pull/7025';
|
|
1167
1007
|
const PNPM_FIELD_NAME = 'pnpm';
|
|
1168
1008
|
const PNPM_WORKSPACE = 'pnpm-workspace';
|
|
1169
1009
|
const RESOLUTIONS_FIELD_NAME = 'resolutions';
|
|
1170
|
-
const manifestNpmOverrides =
|
|
1010
|
+
const manifestNpmOverrides = registry.getManifestData('npm');
|
|
1171
1011
|
const getOverridesDataByAgent = {
|
|
1172
1012
|
bun(pkgJson) {
|
|
1173
1013
|
const overrides = pkgJson?.resolutions ?? {};
|
|
@@ -1222,7 +1062,7 @@ const getOverridesDataByAgent = {
|
|
|
1222
1062
|
};
|
|
1223
1063
|
const lockIncludesByAgent = (() => {
|
|
1224
1064
|
function yarnLockIncludes(lockSrc, name) {
|
|
1225
|
-
const escapedName =
|
|
1065
|
+
const escapedName = regexps.escapeRegExp(name);
|
|
1226
1066
|
return new RegExp(
|
|
1227
1067
|
// Detects the package name in the following cases:
|
|
1228
1068
|
// "name@
|
|
@@ -1239,7 +1079,7 @@ const lockIncludesByAgent = (() => {
|
|
|
1239
1079
|
return lockSrc.includes(`"${name}":`);
|
|
1240
1080
|
},
|
|
1241
1081
|
pnpm(lockSrc, name) {
|
|
1242
|
-
const escapedName =
|
|
1082
|
+
const escapedName = regexps.escapeRegExp(name);
|
|
1243
1083
|
return new RegExp(
|
|
1244
1084
|
// Detects the package name in the following cases:
|
|
1245
1085
|
// /name/
|
|
@@ -1274,18 +1114,18 @@ const updateManifestByAgent = (() => {
|
|
|
1274
1114
|
if (oldValue) {
|
|
1275
1115
|
// The field already exists so we simply update the field value.
|
|
1276
1116
|
if (field === PNPM_FIELD_NAME) {
|
|
1277
|
-
if (
|
|
1117
|
+
if (objects.hasKeys(value)) {
|
|
1278
1118
|
editablePkgJson.update({
|
|
1279
1119
|
[field]: {
|
|
1280
|
-
...(
|
|
1120
|
+
...(objects.isObject(oldValue) ? oldValue : {}),
|
|
1281
1121
|
overrides: value
|
|
1282
1122
|
}
|
|
1283
1123
|
});
|
|
1284
1124
|
} else {
|
|
1285
1125
|
// Properties with undefined values are omitted when saved as JSON.
|
|
1286
|
-
editablePkgJson.update(
|
|
1126
|
+
editablePkgJson.update(objects.hasKeys(pkgJson[field]) ? {
|
|
1287
1127
|
[field]: {
|
|
1288
|
-
...(
|
|
1128
|
+
...(objects.isObject(oldValue) ? oldValue : {}),
|
|
1289
1129
|
overrides: undefined
|
|
1290
1130
|
}
|
|
1291
1131
|
} : {
|
|
@@ -1295,7 +1135,7 @@ const updateManifestByAgent = (() => {
|
|
|
1295
1135
|
} else if (field === OVERRIDES_FIELD_NAME || field === RESOLUTIONS_FIELD_NAME) {
|
|
1296
1136
|
// Properties with undefined values are omitted when saved as JSON.
|
|
1297
1137
|
editablePkgJson.update({
|
|
1298
|
-
[field]:
|
|
1138
|
+
[field]: objects.hasKeys(value) ? value : undefined
|
|
1299
1139
|
});
|
|
1300
1140
|
} else {
|
|
1301
1141
|
editablePkgJson.update({
|
|
@@ -1304,7 +1144,7 @@ const updateManifestByAgent = (() => {
|
|
|
1304
1144
|
}
|
|
1305
1145
|
return;
|
|
1306
1146
|
}
|
|
1307
|
-
if ((field === OVERRIDES_FIELD_NAME || field === PNPM_FIELD_NAME || field === RESOLUTIONS_FIELD_NAME) && !
|
|
1147
|
+
if ((field === OVERRIDES_FIELD_NAME || field === PNPM_FIELD_NAME || field === RESOLUTIONS_FIELD_NAME) && !objects.hasKeys(value)) {
|
|
1308
1148
|
return;
|
|
1309
1149
|
}
|
|
1310
1150
|
// Since the field doesn't exist we want to insert it into the package.json
|
|
@@ -1405,7 +1245,7 @@ const lsByAgent = (() => {
|
|
|
1405
1245
|
async function npmQuery(npmExecPath, cwd) {
|
|
1406
1246
|
let stdout = '';
|
|
1407
1247
|
try {
|
|
1408
|
-
stdout = (await
|
|
1248
|
+
stdout = (await spawn(npmExecPath, ['query', ':not(.dev)'], {
|
|
1409
1249
|
cwd
|
|
1410
1250
|
})).stdout;
|
|
1411
1251
|
} catch {}
|
|
@@ -1416,7 +1256,7 @@ const lsByAgent = (() => {
|
|
|
1416
1256
|
try {
|
|
1417
1257
|
// Bun does not support filtering by production packages yet.
|
|
1418
1258
|
// https://github.com/oven-sh/bun/issues/8283
|
|
1419
|
-
return (await
|
|
1259
|
+
return (await spawn(agentExecPath, ['pm', 'ls', '--all'], {
|
|
1420
1260
|
cwd
|
|
1421
1261
|
})).stdout;
|
|
1422
1262
|
} catch {}
|
|
@@ -1440,7 +1280,7 @@ const lsByAgent = (() => {
|
|
|
1440
1280
|
}
|
|
1441
1281
|
let stdout = '';
|
|
1442
1282
|
try {
|
|
1443
|
-
stdout = (await
|
|
1283
|
+
stdout = (await spawn(agentExecPath, ['ls', '--parseable', '--prod', '--depth', 'Infinity'], {
|
|
1444
1284
|
cwd
|
|
1445
1285
|
})).stdout;
|
|
1446
1286
|
} catch {}
|
|
@@ -1449,7 +1289,7 @@ const lsByAgent = (() => {
|
|
|
1449
1289
|
async vlt(agentExecPath, cwd) {
|
|
1450
1290
|
let stdout = '';
|
|
1451
1291
|
try {
|
|
1452
|
-
stdout = (await
|
|
1292
|
+
stdout = (await spawn(agentExecPath, ['ls', '--view', 'human', ':not(.dev)'], {
|
|
1453
1293
|
cwd
|
|
1454
1294
|
})).stdout;
|
|
1455
1295
|
} catch {}
|
|
@@ -1460,7 +1300,7 @@ const lsByAgent = (() => {
|
|
|
1460
1300
|
return (
|
|
1461
1301
|
// Yarn Berry does not support filtering by production packages yet.
|
|
1462
1302
|
// https://github.com/yarnpkg/berry/issues/5117
|
|
1463
|
-
(await
|
|
1303
|
+
(await spawn(agentExecPath, ['info', '--recursive', '--name-only'], {
|
|
1464
1304
|
cwd
|
|
1465
1305
|
})).stdout.trim()
|
|
1466
1306
|
);
|
|
@@ -1473,7 +1313,7 @@ const lsByAgent = (() => {
|
|
|
1473
1313
|
// https://github.com/yarnpkg/yarn/releases/tag/v1.0.0
|
|
1474
1314
|
// > Fix: Excludes dev dependencies from the yarn list output when the
|
|
1475
1315
|
// environment is production
|
|
1476
|
-
return (await
|
|
1316
|
+
return (await spawn(agentExecPath, ['list', '--prod'], {
|
|
1477
1317
|
cwd
|
|
1478
1318
|
})).stdout.trim();
|
|
1479
1319
|
} catch {}
|
|
@@ -1498,7 +1338,7 @@ const depsIncludesByAgent = (() => {
|
|
|
1498
1338
|
};
|
|
1499
1339
|
})();
|
|
1500
1340
|
function createActionMessage(verb, overrideCount, workspaceCount) {
|
|
1501
|
-
return `${verb} ${overrideCount} Socket.dev optimized overrides${workspaceCount ? ` in ${workspaceCount} ${
|
|
1341
|
+
return `${verb} ${overrideCount} Socket.dev optimized overrides${workspaceCount ? ` in ${workspaceCount} ${words.pluralize('workspace', workspaceCount)}` : ''}`;
|
|
1502
1342
|
}
|
|
1503
1343
|
function getDependencyEntries(pkgJson) {
|
|
1504
1344
|
const {
|
|
@@ -1526,12 +1366,12 @@ function getDependencyEntries(pkgJson) {
|
|
|
1526
1366
|
async function getWorkspaceGlobs(agent, pkgPath, pkgJson) {
|
|
1527
1367
|
let workspacePatterns;
|
|
1528
1368
|
if (agent === 'pnpm') {
|
|
1529
|
-
for (const workspacePath of [
|
|
1530
|
-
if (
|
|
1369
|
+
for (const workspacePath of [path.join(pkgPath, `${PNPM_WORKSPACE}.yaml`), path.join(pkgPath, `${PNPM_WORKSPACE}.yml`)]) {
|
|
1370
|
+
if (existsSync(workspacePath)) {
|
|
1531
1371
|
try {
|
|
1532
|
-
workspacePatterns =
|
|
1372
|
+
workspacePatterns = yaml.parse(
|
|
1533
1373
|
// eslint-disable-next-line no-await-in-loop
|
|
1534
|
-
await
|
|
1374
|
+
await fs$1.readFile(workspacePath, 'utf8'))?.packages;
|
|
1535
1375
|
} catch {}
|
|
1536
1376
|
if (workspacePatterns) {
|
|
1537
1377
|
break;
|
|
@@ -1541,7 +1381,7 @@ async function getWorkspaceGlobs(agent, pkgPath, pkgJson) {
|
|
|
1541
1381
|
} else {
|
|
1542
1382
|
workspacePatterns = pkgJson['workspaces'];
|
|
1543
1383
|
}
|
|
1544
|
-
return Array.isArray(workspacePatterns) ? workspacePatterns.filter(
|
|
1384
|
+
return Array.isArray(workspacePatterns) ? workspacePatterns.filter(strings.isNonEmptyString).map(workspacePatternToGlobPattern) : undefined;
|
|
1545
1385
|
}
|
|
1546
1386
|
function workspacePatternToGlobPattern(workspace) {
|
|
1547
1387
|
const {
|
|
@@ -1585,7 +1425,7 @@ async function addOverrides({
|
|
|
1585
1425
|
rootPath
|
|
1586
1426
|
}, state = createAddOverridesState()) {
|
|
1587
1427
|
if (editablePkgJson === undefined) {
|
|
1588
|
-
editablePkgJson = await
|
|
1428
|
+
editablePkgJson = await packages.readPackageJson(pkgPath, {
|
|
1589
1429
|
editable: true
|
|
1590
1430
|
});
|
|
1591
1431
|
}
|
|
@@ -1597,7 +1437,7 @@ async function addOverrides({
|
|
|
1597
1437
|
} = editablePkgJson;
|
|
1598
1438
|
const isRoot = pkgPath === rootPath;
|
|
1599
1439
|
const isLockScanned = isRoot && !prod;
|
|
1600
|
-
const workspaceName =
|
|
1440
|
+
const workspaceName = path.relative(rootPath, pkgPath);
|
|
1601
1441
|
const workspaceGlobs = await getWorkspaceGlobs(agent, pkgPath, pkgJson);
|
|
1602
1442
|
const isWorkspace = !!workspaceGlobs;
|
|
1603
1443
|
if (isWorkspace && agent === 'pnpm' && npmExecPath === 'npm' && !state.warnedPnpmWorkspaceRequiresNpm) {
|
|
@@ -1620,7 +1460,7 @@ async function addOverrides({
|
|
|
1620
1460
|
}
|
|
1621
1461
|
const depAliasMap = new Map();
|
|
1622
1462
|
// Chunk package names to process them in parallel 3 at a time.
|
|
1623
|
-
await
|
|
1463
|
+
await promises.pEach(manifestEntries, 3, async ({
|
|
1624
1464
|
1: data
|
|
1625
1465
|
}) => {
|
|
1626
1466
|
const {
|
|
@@ -1628,7 +1468,7 @@ async function addOverrides({
|
|
|
1628
1468
|
package: origPkgName,
|
|
1629
1469
|
version
|
|
1630
1470
|
} = data;
|
|
1631
|
-
const major =
|
|
1471
|
+
const major = semver.major(version);
|
|
1632
1472
|
for (const {
|
|
1633
1473
|
1: depObj
|
|
1634
1474
|
} of depEntries) {
|
|
@@ -1638,7 +1478,7 @@ async function addOverrides({
|
|
|
1638
1478
|
// Add package aliases for direct dependencies to avoid npm EOVERRIDE errors.
|
|
1639
1479
|
// https://docs.npmjs.com/cli/v8/using-npm/package-spec#aliases
|
|
1640
1480
|
const regSpecStartsLike = `npm:${regPkgName}@`;
|
|
1641
|
-
const existingVersion = pkgSpec.startsWith(regSpecStartsLike) ?
|
|
1481
|
+
const existingVersion = pkgSpec.startsWith(regSpecStartsLike) ? semver.coerce(npa(pkgSpec).rawSpec)?.version ?? '' : '';
|
|
1642
1482
|
if (existingVersion) {
|
|
1643
1483
|
thisVersion = existingVersion;
|
|
1644
1484
|
} else {
|
|
@@ -1657,11 +1497,11 @@ async function addOverrides({
|
|
|
1657
1497
|
}
|
|
1658
1498
|
if (isRoot) {
|
|
1659
1499
|
// Chunk package names to process them in parallel 3 at a time.
|
|
1660
|
-
await
|
|
1500
|
+
await promises.pEach(overridesDataObjects, 3, async ({
|
|
1661
1501
|
overrides,
|
|
1662
1502
|
type
|
|
1663
1503
|
}) => {
|
|
1664
|
-
const overrideExists =
|
|
1504
|
+
const overrideExists = objects.hasOwn(overrides, origPkgName);
|
|
1665
1505
|
if (overrideExists || thingScanner(thingToScan, origPkgName)) {
|
|
1666
1506
|
const oldSpec = overrideExists ? overrides[origPkgName] : undefined;
|
|
1667
1507
|
const depAlias = depAliasMap.get(origPkgName);
|
|
@@ -1681,9 +1521,9 @@ async function addOverrides({
|
|
|
1681
1521
|
const thisSpec = oldSpec.startsWith('$') ? depAlias?.id ?? newSpec : oldSpec ?? newSpec;
|
|
1682
1522
|
if (thisSpec.startsWith(regSpecStartsLike)) {
|
|
1683
1523
|
if (pin) {
|
|
1684
|
-
thisVersion =
|
|
1524
|
+
thisVersion = semver.major(semver.coerce(npa(thisSpec).rawSpec)?.version ?? version) === major ? version : (await packages.fetchPackageManifest(thisSpec))?.version ?? version;
|
|
1685
1525
|
}
|
|
1686
|
-
newSpec = `${regSpecStartsLike}^${pin ? thisVersion :
|
|
1526
|
+
newSpec = `${regSpecStartsLike}^${pin ? thisVersion : semver.major(thisVersion)}`;
|
|
1687
1527
|
} else {
|
|
1688
1528
|
newSpec = oldSpec;
|
|
1689
1529
|
}
|
|
@@ -1702,13 +1542,13 @@ async function addOverrides({
|
|
|
1702
1542
|
}
|
|
1703
1543
|
});
|
|
1704
1544
|
if (workspaceGlobs) {
|
|
1705
|
-
const workspacePkgJsonPaths = await
|
|
1545
|
+
const workspacePkgJsonPaths = await tinyglobby.glob(workspaceGlobs, {
|
|
1706
1546
|
absolute: true,
|
|
1707
1547
|
cwd: pkgPath,
|
|
1708
1548
|
ignore: ['**/node_modules/**', '**/bower_components/**']
|
|
1709
1549
|
});
|
|
1710
1550
|
// Chunk package names to process them in parallel 3 at a time.
|
|
1711
|
-
await
|
|
1551
|
+
await promises.pEach(workspacePkgJsonPaths, 3, async workspacePkgJsonPath => {
|
|
1712
1552
|
const otherState = await addOverrides({
|
|
1713
1553
|
agent,
|
|
1714
1554
|
agentExecPath,
|
|
@@ -1716,7 +1556,7 @@ async function addOverrides({
|
|
|
1716
1556
|
manifestEntries,
|
|
1717
1557
|
npmExecPath,
|
|
1718
1558
|
pin,
|
|
1719
|
-
pkgPath:
|
|
1559
|
+
pkgPath: path.dirname(workspacePkgJsonPath),
|
|
1720
1560
|
prod,
|
|
1721
1561
|
rootPath
|
|
1722
1562
|
}, createAddOverridesState({
|
|
@@ -1735,13 +1575,13 @@ async function addOverrides({
|
|
|
1735
1575
|
overrides,
|
|
1736
1576
|
type
|
|
1737
1577
|
} of overridesDataObjects) {
|
|
1738
|
-
updateManifestByAgent[type](editablePkgJson,
|
|
1578
|
+
updateManifestByAgent[type](editablePkgJson, objects.toSortedObject(overrides));
|
|
1739
1579
|
}
|
|
1740
1580
|
await editablePkgJson.save();
|
|
1741
1581
|
}
|
|
1742
1582
|
return state;
|
|
1743
1583
|
}
|
|
1744
|
-
const optimize =
|
|
1584
|
+
const optimize = {
|
|
1745
1585
|
description: 'Optimize dependencies with @socketregistry overrides',
|
|
1746
1586
|
async run(argv, importMeta, {
|
|
1747
1587
|
parentName
|
|
@@ -1766,7 +1606,7 @@ const optimize = optimize$1.optimize = {
|
|
|
1766
1606
|
pkgJson,
|
|
1767
1607
|
pkgPath,
|
|
1768
1608
|
supported
|
|
1769
|
-
} = await
|
|
1609
|
+
} = await detect({
|
|
1770
1610
|
cwd,
|
|
1771
1611
|
onUnknown(pkgManager) {
|
|
1772
1612
|
console.warn(`⚠️ ${COMMAND_TITLE}: Unknown package manager${pkgManager ? ` ${pkgManager}` : ''}, defaulting to npm`);
|
|
@@ -1780,7 +1620,7 @@ const optimize = optimize$1.optimize = {
|
|
|
1780
1620
|
console.error(`✖️ ${COMMAND_TITLE}: ${agent} does not support overrides. Soon, though ⚡`);
|
|
1781
1621
|
return;
|
|
1782
1622
|
}
|
|
1783
|
-
const lockName = lockPath ?
|
|
1623
|
+
const lockName = lockPath ? path.basename(lockPath) : 'lock file';
|
|
1784
1624
|
if (lockSrc === undefined) {
|
|
1785
1625
|
console.error(`✖️ ${COMMAND_TITLE}: No ${lockName} found`);
|
|
1786
1626
|
return;
|
|
@@ -1797,10 +1637,10 @@ const optimize = optimize$1.optimize = {
|
|
|
1797
1637
|
console.error(`✖️ ${COMMAND_TITLE}: --prod not supported for ${agent}${agentVersion ? `@${agentVersion.toString()}` : ''}`);
|
|
1798
1638
|
return;
|
|
1799
1639
|
}
|
|
1800
|
-
if (lockPath &&
|
|
1640
|
+
if (lockPath && path.relative(cwd, lockPath).startsWith('.')) {
|
|
1801
1641
|
console.warn(`⚠️ ${COMMAND_TITLE}: Package ${lockName} found at ${lockPath}`);
|
|
1802
1642
|
}
|
|
1803
|
-
const spinner =
|
|
1643
|
+
const spinner = yoctoSpinner({
|
|
1804
1644
|
text: 'Socket optimizing...'
|
|
1805
1645
|
});
|
|
1806
1646
|
const state = createAddOverridesState({
|
|
@@ -1810,7 +1650,7 @@ const optimize = optimize$1.optimize = {
|
|
|
1810
1650
|
const nodeRange = `>=${minimumNodeVersion}`;
|
|
1811
1651
|
const manifestEntries = manifestNpmOverrides.filter(({
|
|
1812
1652
|
1: data
|
|
1813
|
-
}) =>
|
|
1653
|
+
}) => semver.satisfies(semver.coerce(data.engines.node), nodeRange));
|
|
1814
1654
|
await addOverrides({
|
|
1815
1655
|
agent,
|
|
1816
1656
|
agentExecPath,
|
|
@@ -1844,22 +1684,24 @@ const optimize = optimize$1.optimize = {
|
|
|
1844
1684
|
spinner.start(`Updating ${lockName}...`);
|
|
1845
1685
|
try {
|
|
1846
1686
|
if (isNpm) {
|
|
1847
|
-
const wrapperPath =
|
|
1687
|
+
const wrapperPath = path.join(rootBinPath, 'npm-cli.js');
|
|
1848
1688
|
const npmSpawnOptions = {
|
|
1689
|
+
signal: abortSignal$2,
|
|
1849
1690
|
stdio: 'ignore',
|
|
1850
1691
|
env: {
|
|
1851
1692
|
...process.env,
|
|
1852
|
-
[
|
|
1693
|
+
[UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE]: '1'
|
|
1853
1694
|
}
|
|
1854
1695
|
};
|
|
1855
|
-
await
|
|
1856
|
-
// TODO: This is a temporary workaround for
|
|
1696
|
+
await spawn(execPath, [wrapperPath, 'install', '--silent'], npmSpawnOptions);
|
|
1697
|
+
// TODO: This is a temporary workaround for a `npm ci` bug where it
|
|
1857
1698
|
// will error out after Socket Optimize generates a lock file. More
|
|
1858
1699
|
// investigation is needed.
|
|
1859
|
-
await
|
|
1700
|
+
await spawn(execPath, [wrapperPath, 'install', '--silent', '--ignore-scripts', '--package-lock-only'], npmSpawnOptions);
|
|
1860
1701
|
} else {
|
|
1861
1702
|
// All package managers support the "install" command.
|
|
1862
|
-
await
|
|
1703
|
+
await spawn(agentExecPath, ['install'], {
|
|
1704
|
+
signal: abortSignal$2,
|
|
1863
1705
|
stdio: 'ignore'
|
|
1864
1706
|
});
|
|
1865
1707
|
}
|
|
@@ -1878,7 +1720,7 @@ const optimize = optimize$1.optimize = {
|
|
|
1878
1720
|
|
|
1879
1721
|
function setupCommand$l(name, description, argv, importMeta) {
|
|
1880
1722
|
const flags = {
|
|
1881
|
-
...
|
|
1723
|
+
...commonFlags,
|
|
1882
1724
|
pin: {
|
|
1883
1725
|
type: 'boolean',
|
|
1884
1726
|
default: false,
|
|
@@ -1890,12 +1732,12 @@ function setupCommand$l(name, description, argv, importMeta) {
|
|
|
1890
1732
|
description: 'Only add overrides for production dependencies'
|
|
1891
1733
|
}
|
|
1892
1734
|
};
|
|
1893
|
-
const cli = (
|
|
1735
|
+
const cli = meow(`
|
|
1894
1736
|
Usage
|
|
1895
1737
|
$ ${name}
|
|
1896
1738
|
|
|
1897
1739
|
Options
|
|
1898
|
-
${
|
|
1740
|
+
${printFlagList(flags, 6)}
|
|
1899
1741
|
|
|
1900
1742
|
Examples
|
|
1901
1743
|
$ ${name}
|
|
@@ -1920,20 +1762,7 @@ function setupCommand$l(name, description, argv, importMeta) {
|
|
|
1920
1762
|
};
|
|
1921
1763
|
}
|
|
1922
1764
|
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
var _interopRequireDefault$m = vendor.interopRequireDefault.default;
|
|
1926
|
-
Object.defineProperty(organization, "__esModule", {
|
|
1927
|
-
value: true
|
|
1928
|
-
});
|
|
1929
|
-
organization.organizations = void 0;
|
|
1930
|
-
var _yoctocolorsCjs$g = require$$1$2;
|
|
1931
|
-
var _meow$l = _interopRequireDefault$m(require$$2);
|
|
1932
|
-
var _yoctoSpinner$h = require$$3;
|
|
1933
|
-
var _apiHelpers$h = apiHelpers;
|
|
1934
|
-
var _errors$i = sdk.errors;
|
|
1935
|
-
var _sdk$h = sdk.sdk;
|
|
1936
|
-
const organizations = organization.organizations = {
|
|
1765
|
+
const organizations = {
|
|
1937
1766
|
description: 'List organizations associated with the API key used',
|
|
1938
1767
|
async run(argv, importMeta, {
|
|
1939
1768
|
parentName
|
|
@@ -1946,7 +1775,7 @@ const organizations = organization.organizations = {
|
|
|
1946
1775
|
// Internal functions
|
|
1947
1776
|
|
|
1948
1777
|
function setupCommand$k(name, description, argv, importMeta) {
|
|
1949
|
-
(
|
|
1778
|
+
meow(`
|
|
1950
1779
|
Usage
|
|
1951
1780
|
$ ${name}
|
|
1952
1781
|
`, {
|
|
@@ -1956,20 +1785,20 @@ function setupCommand$k(name, description, argv, importMeta) {
|
|
|
1956
1785
|
});
|
|
1957
1786
|
}
|
|
1958
1787
|
async function fetchOrganizations() {
|
|
1959
|
-
const apiKey =
|
|
1788
|
+
const apiKey = sdk.getDefaultKey();
|
|
1960
1789
|
if (!apiKey) {
|
|
1961
|
-
throw new
|
|
1790
|
+
throw new sdk.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
1962
1791
|
}
|
|
1963
|
-
const spinner =
|
|
1792
|
+
const spinner = yoctoSpinner({
|
|
1964
1793
|
text: 'Fetching organizations...'
|
|
1965
1794
|
}).start();
|
|
1966
|
-
const socketSdk = await
|
|
1967
|
-
const result = await
|
|
1795
|
+
const socketSdk = await sdk.setupSdk(apiKey);
|
|
1796
|
+
const result = await handleApiCall(socketSdk.getOrganizations(), 'looking up organizations');
|
|
1968
1797
|
if (result.success === false) {
|
|
1969
|
-
|
|
1798
|
+
handleUnsuccessfulApiResponse('getOrganizations', result, spinner);
|
|
1970
1799
|
return;
|
|
1971
1800
|
}
|
|
1972
|
-
spinner.stop(`List of organizations associated with your API key: ${
|
|
1801
|
+
spinner.stop(`List of organizations associated with your API key: ${colors.italic(apiKey)}`);
|
|
1973
1802
|
const organizations = Object.values(result.data.organizations);
|
|
1974
1803
|
for (const o of organizations) {
|
|
1975
1804
|
console.log(`
|
|
@@ -1980,18 +1809,10 @@ Plan: ${o?.plan}
|
|
|
1980
1809
|
}
|
|
1981
1810
|
}
|
|
1982
1811
|
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
value: true
|
|
1988
|
-
});
|
|
1989
|
-
rawNpm$1.rawNpm = void 0;
|
|
1990
|
-
var _promiseSpawn$1 = require$$1$1;
|
|
1991
|
-
var _meow$k = _interopRequireDefault$l(require$$2);
|
|
1992
|
-
var _flags$i = flags$1;
|
|
1993
|
-
var _formatting$j = formatting;
|
|
1994
|
-
const rawNpm = rawNpm$1.rawNpm = {
|
|
1812
|
+
const {
|
|
1813
|
+
abortSignal: abortSignal$1
|
|
1814
|
+
} = constants;
|
|
1815
|
+
const rawNpm = {
|
|
1995
1816
|
description: 'Temporarily disable the Socket npm wrapper',
|
|
1996
1817
|
async run(argv, importMeta, {
|
|
1997
1818
|
parentName
|
|
@@ -2001,15 +1822,15 @@ const rawNpm = rawNpm$1.rawNpm = {
|
|
|
2001
1822
|
};
|
|
2002
1823
|
async function setupCommand$j(name, description, argv, importMeta) {
|
|
2003
1824
|
const flags = {
|
|
2004
|
-
...
|
|
2005
|
-
...
|
|
1825
|
+
...commonFlags,
|
|
1826
|
+
...validationFlags
|
|
2006
1827
|
};
|
|
2007
|
-
const cli = (
|
|
1828
|
+
const cli = meow(`
|
|
2008
1829
|
Usage
|
|
2009
1830
|
$ ${name} <npm command>
|
|
2010
1831
|
|
|
2011
1832
|
Options
|
|
2012
|
-
${
|
|
1833
|
+
${printFlagList(flags, 6)}
|
|
2013
1834
|
|
|
2014
1835
|
Examples
|
|
2015
1836
|
$ ${name} install
|
|
@@ -2027,7 +1848,8 @@ async function setupCommand$j(name, description, argv, importMeta) {
|
|
|
2027
1848
|
cli.showHelp();
|
|
2028
1849
|
return;
|
|
2029
1850
|
}
|
|
2030
|
-
const spawnPromise =
|
|
1851
|
+
const spawnPromise = spawn('npm', argv, {
|
|
1852
|
+
signal: abortSignal$1,
|
|
2031
1853
|
stdio: 'inherit'
|
|
2032
1854
|
});
|
|
2033
1855
|
spawnPromise.process.on('exit', (code, signal) => {
|
|
@@ -2040,18 +1862,10 @@ async function setupCommand$j(name, description, argv, importMeta) {
|
|
|
2040
1862
|
await spawnPromise;
|
|
2041
1863
|
}
|
|
2042
1864
|
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
value: true
|
|
2048
|
-
});
|
|
2049
|
-
rawNpx$1.rawNpx = void 0;
|
|
2050
|
-
var _promiseSpawn = require$$1$1;
|
|
2051
|
-
var _meow$j = _interopRequireDefault$k(require$$2);
|
|
2052
|
-
var _flags$h = flags$1;
|
|
2053
|
-
var _formatting$i = formatting;
|
|
2054
|
-
const rawNpx = rawNpx$1.rawNpx = {
|
|
1865
|
+
const {
|
|
1866
|
+
abortSignal
|
|
1867
|
+
} = constants;
|
|
1868
|
+
const rawNpx = {
|
|
2055
1869
|
description: 'Temporarily disable the Socket npm/npx wrapper',
|
|
2056
1870
|
async run(argv, importMeta, {
|
|
2057
1871
|
parentName
|
|
@@ -2061,15 +1875,15 @@ const rawNpx = rawNpx$1.rawNpx = {
|
|
|
2061
1875
|
};
|
|
2062
1876
|
async function setupCommand$i(name, description, argv, importMeta) {
|
|
2063
1877
|
const flags = {
|
|
2064
|
-
...
|
|
2065
|
-
...
|
|
1878
|
+
...commonFlags,
|
|
1879
|
+
...validationFlags
|
|
2066
1880
|
};
|
|
2067
|
-
const cli = (
|
|
1881
|
+
const cli = meow(`
|
|
2068
1882
|
Usage
|
|
2069
1883
|
$ ${name} <npx command>
|
|
2070
1884
|
|
|
2071
1885
|
Options
|
|
2072
|
-
${
|
|
1886
|
+
${printFlagList(flags, 6)}
|
|
2073
1887
|
|
|
2074
1888
|
Examples
|
|
2075
1889
|
$ ${name} install
|
|
@@ -2087,7 +1901,8 @@ async function setupCommand$i(name, description, argv, importMeta) {
|
|
|
2087
1901
|
cli.showHelp();
|
|
2088
1902
|
return;
|
|
2089
1903
|
}
|
|
2090
|
-
const spawnPromise =
|
|
1904
|
+
const spawnPromise = spawn('npx', [argv.join(' ')], {
|
|
1905
|
+
signal: abortSignal,
|
|
2091
1906
|
stdio: 'inherit'
|
|
2092
1907
|
});
|
|
2093
1908
|
spawnPromise.process.on('exit', (code, signal) => {
|
|
@@ -2100,37 +1915,13 @@ async function setupCommand$i(name, description, argv, importMeta) {
|
|
|
2100
1915
|
await spawnPromise;
|
|
2101
1916
|
}
|
|
2102
1917
|
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
var create$5 = {};
|
|
2106
|
-
|
|
2107
|
-
var view$3 = {};
|
|
2108
|
-
|
|
2109
|
-
var _interopRequireDefault$j = vendor.interopRequireDefault.default;
|
|
2110
|
-
Object.defineProperty(view$3, "__esModule", {
|
|
2111
|
-
value: true
|
|
2112
|
-
});
|
|
2113
|
-
view$3.fetchReportData = fetchReportData;
|
|
2114
|
-
view$3.formatReportDataOutput = formatReportDataOutput;
|
|
2115
|
-
view$3.view = void 0;
|
|
2116
|
-
var _yoctocolorsCjs$f = require$$1$2;
|
|
2117
|
-
var _meow$i = _interopRequireDefault$j(require$$2);
|
|
2118
|
-
var _yoctoSpinner$g = require$$3;
|
|
2119
|
-
var _ponyCause$3 = require$$4$1;
|
|
2120
|
-
var _flags$g = flags$1;
|
|
2121
|
-
var _apiHelpers$g = apiHelpers;
|
|
2122
|
-
var _colorOrMarkdown$2 = sdk.colorOrMarkdown;
|
|
2123
|
-
var _errors$h = sdk.errors;
|
|
2124
|
-
var _formatIssues = formatIssues;
|
|
2125
|
-
var _formatting$h = formatting;
|
|
2126
|
-
var _sdk$g = sdk.sdk;
|
|
2127
|
-
const view$2 = view$3.view = {
|
|
1918
|
+
const view$1 = {
|
|
2128
1919
|
description: 'View a project report',
|
|
2129
1920
|
async run(argv, importMeta, {
|
|
2130
1921
|
parentName
|
|
2131
1922
|
}) {
|
|
2132
1923
|
const name = `${parentName} view`;
|
|
2133
|
-
const commandContext = setupCommand$h(name, view$
|
|
1924
|
+
const commandContext = setupCommand$h(name, view$1.description, argv, importMeta);
|
|
2134
1925
|
const result = commandContext ? await fetchReportData(commandContext.reportId, commandContext) : undefined;
|
|
2135
1926
|
if (result) {
|
|
2136
1927
|
formatReportDataOutput(result, {
|
|
@@ -2145,16 +1936,16 @@ const view$2 = view$3.view = {
|
|
|
2145
1936
|
|
|
2146
1937
|
function setupCommand$h(name, description, argv, importMeta) {
|
|
2147
1938
|
const flags = {
|
|
2148
|
-
...
|
|
2149
|
-
...
|
|
2150
|
-
...
|
|
1939
|
+
...commonFlags,
|
|
1940
|
+
...outputFlags,
|
|
1941
|
+
...validationFlags
|
|
2151
1942
|
};
|
|
2152
|
-
const cli = (
|
|
1943
|
+
const cli = meow(`
|
|
2153
1944
|
Usage
|
|
2154
1945
|
$ ${name} <report-identifier>
|
|
2155
1946
|
|
|
2156
1947
|
Options
|
|
2157
|
-
${
|
|
1948
|
+
${printFlagList(flags, 6)}
|
|
2158
1949
|
|
|
2159
1950
|
Examples
|
|
2160
1951
|
$ ${name} QXU8PmK7LfH608RAwfIKdbcHgwEd_ZeWJ9QEGv05FJUQ
|
|
@@ -2176,7 +1967,7 @@ function setupCommand$h(name, description, argv, importMeta) {
|
|
|
2176
1967
|
}
|
|
2177
1968
|
// Validate the input.
|
|
2178
1969
|
if (extraInput.length) {
|
|
2179
|
-
throw new
|
|
1970
|
+
throw new sdk.InputError(`Can only handle a single report ID at a time, but got ${cli.input.length} report ID:s: ${cli.input.join(', ')}`);
|
|
2180
1971
|
}
|
|
2181
1972
|
return {
|
|
2182
1973
|
includeAllIssues: cli.flags['all'],
|
|
@@ -2192,23 +1983,23 @@ async function fetchReportData(reportId, {
|
|
|
2192
1983
|
strict
|
|
2193
1984
|
}) {
|
|
2194
1985
|
// Do the API call
|
|
2195
|
-
const socketSdk = await
|
|
2196
|
-
const spinner =
|
|
1986
|
+
const socketSdk = await sdk.setupSdk();
|
|
1987
|
+
const spinner = yoctoSpinner({
|
|
2197
1988
|
text: `Fetching report with ID ${reportId} (this could take a while)`
|
|
2198
1989
|
}).start();
|
|
2199
1990
|
let result;
|
|
2200
1991
|
for (let retry = 1; !result; ++retry) {
|
|
2201
1992
|
try {
|
|
2202
1993
|
// eslint-disable-next-line no-await-in-loop
|
|
2203
|
-
result = await
|
|
1994
|
+
result = await handleApiCall(socketSdk.getReport(reportId), 'fetching report');
|
|
2204
1995
|
} catch (err) {
|
|
2205
|
-
if (retry >= MAX_TIMEOUT_RETRY || !(err instanceof
|
|
1996
|
+
if (retry >= MAX_TIMEOUT_RETRY || !(err instanceof ponyCause.ErrorWithCause) || err.cause?.cause?.response?.statusCode !== 524) {
|
|
2206
1997
|
throw err;
|
|
2207
1998
|
}
|
|
2208
1999
|
}
|
|
2209
2000
|
}
|
|
2210
2001
|
if (result.success === false) {
|
|
2211
|
-
return
|
|
2002
|
+
return handleUnsuccessfulApiResponse('getReport', result, spinner);
|
|
2212
2003
|
}
|
|
2213
2004
|
|
|
2214
2005
|
// Conclude the status of the API call
|
|
@@ -2220,8 +2011,8 @@ async function fetchReportData(reportId, {
|
|
|
2220
2011
|
spinner.error('Report result deemed unhealthy for project');
|
|
2221
2012
|
}
|
|
2222
2013
|
} else if (result.data.healthy === false) {
|
|
2223
|
-
const severityCount =
|
|
2224
|
-
const issueSummary =
|
|
2014
|
+
const severityCount = getSeverityCount(result.data.issues, includeAllIssues ? undefined : 'high');
|
|
2015
|
+
const issueSummary = formatSeverityCount(severityCount);
|
|
2225
2016
|
spinner.success(`Report has these issues: ${issueSummary}`);
|
|
2226
2017
|
} else {
|
|
2227
2018
|
spinner.success('Report has no issues');
|
|
@@ -2238,12 +2029,12 @@ function formatReportDataOutput(data, {
|
|
|
2238
2029
|
if (outputJson) {
|
|
2239
2030
|
console.log(JSON.stringify(data, undefined, 2));
|
|
2240
2031
|
} else {
|
|
2241
|
-
const format = new
|
|
2032
|
+
const format = new sdk.ColorOrMarkdown(!!outputMarkdown);
|
|
2242
2033
|
console.log('\nDetailed info on socket.dev: ' + format.hyperlink(reportId, data.url, {
|
|
2243
2034
|
fallbackToUrl: true
|
|
2244
2035
|
}));
|
|
2245
2036
|
if (!outputMarkdown) {
|
|
2246
|
-
console.log(
|
|
2037
|
+
console.log(colors.dim(`\nOr rerun ${colors.italic(name)} using the ${colors.italic('--json')} flag to get full JSON output`));
|
|
2247
2038
|
}
|
|
2248
2039
|
}
|
|
2249
2040
|
if (strict && data.healthy === false) {
|
|
@@ -2251,33 +2042,13 @@ function formatReportDataOutput(data, {
|
|
|
2251
2042
|
}
|
|
2252
2043
|
}
|
|
2253
2044
|
|
|
2254
|
-
|
|
2255
|
-
Object.defineProperty(create$5, "__esModule", {
|
|
2256
|
-
value: true
|
|
2257
|
-
});
|
|
2258
|
-
create$5.create = void 0;
|
|
2259
|
-
var _nodePath = require$$1;
|
|
2260
|
-
var _betterAjvErrors = require$$2$2;
|
|
2261
|
-
var _meow$h = _interopRequireDefault$i(require$$2);
|
|
2262
|
-
var _yoctoSpinner$f = require$$3;
|
|
2263
|
-
var _ponyCause$2 = require$$4$1;
|
|
2264
|
-
var _config = require$$6;
|
|
2265
|
-
var _view$2 = view$3;
|
|
2266
|
-
var _flags$f = flags$1;
|
|
2267
|
-
var _apiHelpers$f = apiHelpers;
|
|
2268
|
-
var _colorOrMarkdown$1 = sdk.colorOrMarkdown;
|
|
2269
|
-
var _errors$g = sdk.errors;
|
|
2270
|
-
var _formatting$g = formatting;
|
|
2271
|
-
var _misc$1 = sdk.misc;
|
|
2272
|
-
var _pathResolve$1 = pathResolve.pathResolve;
|
|
2273
|
-
var _sdk$f = sdk.sdk;
|
|
2274
|
-
const create$4 = create$5.create = {
|
|
2045
|
+
const create$2 = {
|
|
2275
2046
|
description: 'Create a project report',
|
|
2276
2047
|
async run(argv, importMeta, {
|
|
2277
2048
|
parentName
|
|
2278
2049
|
}) {
|
|
2279
2050
|
const name = `${parentName} create`;
|
|
2280
|
-
const input = await setupCommand$g(name, create$
|
|
2051
|
+
const input = await setupCommand$g(name, create$2.description, argv, importMeta);
|
|
2281
2052
|
if (input) {
|
|
2282
2053
|
const {
|
|
2283
2054
|
config,
|
|
@@ -2299,12 +2070,12 @@ const create$4 = create$5.create = {
|
|
|
2299
2070
|
}));
|
|
2300
2071
|
if (result && view) {
|
|
2301
2072
|
const reportId = result.data.id;
|
|
2302
|
-
const reportData = input && (await
|
|
2073
|
+
const reportData = input && (await fetchReportData(reportId, {
|
|
2303
2074
|
includeAllIssues,
|
|
2304
2075
|
strict
|
|
2305
2076
|
}));
|
|
2306
2077
|
if (reportData) {
|
|
2307
|
-
|
|
2078
|
+
formatReportDataOutput(reportData, {
|
|
2308
2079
|
includeAllIssues,
|
|
2309
2080
|
name,
|
|
2310
2081
|
outputJson,
|
|
@@ -2327,9 +2098,9 @@ const create$4 = create$5.create = {
|
|
|
2327
2098
|
|
|
2328
2099
|
async function setupCommand$g(name, description, argv, importMeta) {
|
|
2329
2100
|
const flags = {
|
|
2330
|
-
...
|
|
2331
|
-
...
|
|
2332
|
-
...
|
|
2101
|
+
...commonFlags,
|
|
2102
|
+
...outputFlags,
|
|
2103
|
+
...validationFlags,
|
|
2333
2104
|
debug: {
|
|
2334
2105
|
type: 'boolean',
|
|
2335
2106
|
shortFlag: 'd',
|
|
@@ -2348,7 +2119,7 @@ async function setupCommand$g(name, description, argv, importMeta) {
|
|
|
2348
2119
|
description: 'Will wait for and return the created report'
|
|
2349
2120
|
}
|
|
2350
2121
|
};
|
|
2351
|
-
const cli = (
|
|
2122
|
+
const cli = meow(`
|
|
2352
2123
|
Usage
|
|
2353
2124
|
$ ${name} <paths-to-package-folders-and-files>
|
|
2354
2125
|
|
|
@@ -2362,7 +2133,7 @@ async function setupCommand$g(name, description, argv, importMeta) {
|
|
|
2362
2133
|
default ignores from the "ignore-by-default" module.
|
|
2363
2134
|
|
|
2364
2135
|
Options
|
|
2365
|
-
${
|
|
2136
|
+
${printFlagList({
|
|
2366
2137
|
all: 'Include all issues',
|
|
2367
2138
|
debug: 'Output debug information',
|
|
2368
2139
|
'dry-run': 'Only output what will be done without actually doing it',
|
|
@@ -2394,40 +2165,40 @@ async function setupCommand$g(name, description, argv, importMeta) {
|
|
|
2394
2165
|
const {
|
|
2395
2166
|
dryRun
|
|
2396
2167
|
} = cli.flags;
|
|
2397
|
-
const debugLog =
|
|
2168
|
+
const debugLog = sdk.createDebugLogger(!dryRun || cli.flags['debug']);
|
|
2398
2169
|
|
|
2399
2170
|
// TODO: Allow setting a custom cwd and/or configFile path?
|
|
2400
2171
|
const cwd = process.cwd();
|
|
2401
|
-
const absoluteConfigPath =
|
|
2402
|
-
const config = await
|
|
2403
|
-
if (cause && typeof cause === 'object' && cause instanceof
|
|
2172
|
+
const absoluteConfigPath = path.join(cwd, 'socket.yml');
|
|
2173
|
+
const config$1 = await config.readSocketConfig(absoluteConfigPath).catch(cause => {
|
|
2174
|
+
if (cause && typeof cause === 'object' && cause instanceof config.SocketValidationError) {
|
|
2404
2175
|
// Inspired by workbox-build:
|
|
2405
2176
|
// https://github.com/GoogleChrome/workbox/blob/95f97a207fd51efb3f8a653f6e3e58224183a778/packages/workbox-build/src/lib/validate-options.ts#L68-L71
|
|
2406
|
-
const betterErrors =
|
|
2177
|
+
const betterErrors = betterAjvErrors.betterAjvErrors({
|
|
2407
2178
|
basePath: 'config',
|
|
2408
2179
|
data: cause.data,
|
|
2409
2180
|
errors: cause.validationErrors,
|
|
2410
2181
|
schema: cause.schema
|
|
2411
2182
|
});
|
|
2412
|
-
throw new
|
|
2183
|
+
throw new sdk.InputError('The socket.yml config is not valid', betterErrors.map(err => `[${err.path}] ${err.message}.${err.suggestion ? err.suggestion : ''}`).join('\n'));
|
|
2413
2184
|
} else {
|
|
2414
|
-
throw new
|
|
2185
|
+
throw new ponyCause.ErrorWithCause('Failed to read socket.yml config', {
|
|
2415
2186
|
cause
|
|
2416
2187
|
});
|
|
2417
2188
|
}
|
|
2418
2189
|
});
|
|
2419
|
-
const socketSdk = await
|
|
2190
|
+
const socketSdk = await sdk.setupSdk();
|
|
2420
2191
|
const supportedFiles = await socketSdk.getReportSupportedFiles().then(res => {
|
|
2421
|
-
if (!res.success)
|
|
2192
|
+
if (!res.success) handleUnsuccessfulApiResponse('getReportSupportedFiles', res, yoctoSpinner());
|
|
2422
2193
|
return res.data;
|
|
2423
2194
|
}).catch(cause => {
|
|
2424
|
-
throw new
|
|
2195
|
+
throw new ponyCause.ErrorWithCause('Failed getting supported files for report', {
|
|
2425
2196
|
cause
|
|
2426
2197
|
});
|
|
2427
2198
|
});
|
|
2428
|
-
const packagePaths = await
|
|
2199
|
+
const packagePaths = await pathResolve.getPackageFiles(cwd, cli.input, config$1, supportedFiles, debugLog);
|
|
2429
2200
|
return {
|
|
2430
|
-
config,
|
|
2201
|
+
config: config$1,
|
|
2431
2202
|
cwd,
|
|
2432
2203
|
debugLog,
|
|
2433
2204
|
dryRun,
|
|
@@ -2445,21 +2216,21 @@ async function createReport(packagePaths, {
|
|
|
2445
2216
|
debugLog,
|
|
2446
2217
|
dryRun
|
|
2447
2218
|
}) {
|
|
2448
|
-
debugLog('Uploading:', packagePaths.join(`\n${
|
|
2219
|
+
debugLog('Uploading:', packagePaths.join(`\n${sdk.logSymbols.info} Uploading: `));
|
|
2449
2220
|
if (dryRun) {
|
|
2450
2221
|
return;
|
|
2451
2222
|
}
|
|
2452
|
-
const socketSdk = await
|
|
2453
|
-
const spinner =
|
|
2223
|
+
const socketSdk = await sdk.setupSdk();
|
|
2224
|
+
const spinner = yoctoSpinner({
|
|
2454
2225
|
text: `Creating report with ${packagePaths.length} package files`
|
|
2455
2226
|
}).start();
|
|
2456
2227
|
const apiCall = socketSdk.createReportFromFilePaths(packagePaths, cwd, config?.issueRules);
|
|
2457
|
-
const result = await
|
|
2228
|
+
const result = await handleApiCall(apiCall, 'creating report');
|
|
2458
2229
|
if (result.success) {
|
|
2459
2230
|
spinner.success();
|
|
2460
2231
|
return result;
|
|
2461
2232
|
}
|
|
2462
|
-
|
|
2233
|
+
handleUnsuccessfulApiResponse('createReport', result, spinner);
|
|
2463
2234
|
return undefined;
|
|
2464
2235
|
}
|
|
2465
2236
|
function formatReportCreationOutput(data, {
|
|
@@ -2470,23 +2241,12 @@ function formatReportCreationOutput(data, {
|
|
|
2470
2241
|
console.log(JSON.stringify(data, undefined, 2));
|
|
2471
2242
|
return;
|
|
2472
2243
|
}
|
|
2473
|
-
const format = new
|
|
2244
|
+
const format = new sdk.ColorOrMarkdown(!!outputMarkdown);
|
|
2474
2245
|
console.log(`New report: ${format.hyperlink(data.id, data.url, {
|
|
2475
2246
|
fallbackToUrl: true
|
|
2476
2247
|
})}`);
|
|
2477
2248
|
}
|
|
2478
2249
|
|
|
2479
|
-
var meowWithSubcommands$1 = {};
|
|
2480
|
-
|
|
2481
|
-
var _interopRequireDefault$h = vendor.interopRequireDefault.default;
|
|
2482
|
-
Object.defineProperty(meowWithSubcommands$1, "__esModule", {
|
|
2483
|
-
value: true
|
|
2484
|
-
});
|
|
2485
|
-
meowWithSubcommands$1.meowWithSubcommands = meowWithSubcommands;
|
|
2486
|
-
var _meow$g = _interopRequireDefault$h(require$$2);
|
|
2487
|
-
var _objects = require$$7;
|
|
2488
|
-
var _formatting$f = formatting;
|
|
2489
|
-
var _flags$e = flags$1;
|
|
2490
2250
|
async function meowWithSubcommands(subcommands, options) {
|
|
2491
2251
|
const {
|
|
2492
2252
|
aliases = {},
|
|
@@ -2514,22 +2274,22 @@ async function meowWithSubcommands(subcommands, options) {
|
|
|
2514
2274
|
}
|
|
2515
2275
|
}
|
|
2516
2276
|
const flags = {
|
|
2517
|
-
...
|
|
2277
|
+
...commonFlags,
|
|
2518
2278
|
...additionalOptions.flags
|
|
2519
2279
|
};
|
|
2520
2280
|
// ...else we provide basic instructions and help
|
|
2521
|
-
const cli = (
|
|
2281
|
+
const cli = meow(`
|
|
2522
2282
|
Usage
|
|
2523
2283
|
$ ${name} <command>
|
|
2524
2284
|
|
|
2525
2285
|
Commands
|
|
2526
|
-
${
|
|
2527
|
-
...
|
|
2528
|
-
...
|
|
2286
|
+
${printHelpList({
|
|
2287
|
+
...objects.toSortedObject(subcommands),
|
|
2288
|
+
...objects.toSortedObject(aliases)
|
|
2529
2289
|
}, 6)}
|
|
2530
2290
|
|
|
2531
2291
|
Options
|
|
2532
|
-
${
|
|
2292
|
+
${printFlagList(flags, 6)}
|
|
2533
2293
|
|
|
2534
2294
|
Examples
|
|
2535
2295
|
$ ${name} --help
|
|
@@ -2542,22 +2302,15 @@ async function meowWithSubcommands(subcommands, options) {
|
|
|
2542
2302
|
cli.showHelp();
|
|
2543
2303
|
}
|
|
2544
2304
|
|
|
2545
|
-
Object.defineProperty(report, "__esModule", {
|
|
2546
|
-
value: true
|
|
2547
|
-
});
|
|
2548
|
-
report.report = void 0;
|
|
2549
|
-
var _create$2 = create$5;
|
|
2550
|
-
var _view$1 = view$3;
|
|
2551
|
-
var _meowWithSubcommands$4 = meowWithSubcommands$1;
|
|
2552
2305
|
const description$3 = '[Deprecated] Project report related commands';
|
|
2553
|
-
report
|
|
2306
|
+
const report = {
|
|
2554
2307
|
description: description$3,
|
|
2555
2308
|
async run(argv, importMeta, {
|
|
2556
2309
|
parentName
|
|
2557
2310
|
}) {
|
|
2558
|
-
await
|
|
2559
|
-
create:
|
|
2560
|
-
view:
|
|
2311
|
+
await meowWithSubcommands({
|
|
2312
|
+
create: create$2,
|
|
2313
|
+
view: view$1
|
|
2561
2314
|
}, {
|
|
2562
2315
|
argv,
|
|
2563
2316
|
description: description$3,
|
|
@@ -2567,22 +2320,9 @@ report.report = {
|
|
|
2567
2320
|
}
|
|
2568
2321
|
};
|
|
2569
2322
|
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
Object.defineProperty(wrapper$1, "__esModule", {
|
|
2574
|
-
value: true
|
|
2575
|
-
});
|
|
2576
|
-
wrapper$1.wrapper = void 0;
|
|
2577
|
-
var _nodeFs$1 = require$$0;
|
|
2578
|
-
var _nodeOs = require$$2$3;
|
|
2579
|
-
var _nodeReadline = require$$3$5;
|
|
2580
|
-
var _meow$f = _interopRequireDefault$g(require$$2);
|
|
2581
|
-
var _flags$d = flags$1;
|
|
2582
|
-
var _formatting$e = formatting;
|
|
2583
|
-
const BASH_FILE = `${_nodeOs.homedir()}/.bashrc`;
|
|
2584
|
-
const ZSH_BASH_FILE = `${_nodeOs.homedir()}/.zshrc`;
|
|
2585
|
-
const wrapper = wrapper$1.wrapper = {
|
|
2323
|
+
const BASH_FILE = `${homedir.homedir()}/.bashrc`;
|
|
2324
|
+
const ZSH_BASH_FILE = `${homedir.homedir()}/.zshrc`;
|
|
2325
|
+
const wrapper = {
|
|
2586
2326
|
description: 'Enable or disable the Socket npm/npx wrapper',
|
|
2587
2327
|
async run(argv, importMeta, {
|
|
2588
2328
|
parentName
|
|
@@ -2591,13 +2331,13 @@ const wrapper = wrapper$1.wrapper = {
|
|
|
2591
2331
|
}
|
|
2592
2332
|
};
|
|
2593
2333
|
function setupCommand$f(name, description, argv, importMeta) {
|
|
2594
|
-
const flags =
|
|
2595
|
-
const cli = (
|
|
2334
|
+
const flags = commandFlags;
|
|
2335
|
+
const cli = meow(`
|
|
2596
2336
|
Usage
|
|
2597
2337
|
$ ${name} <flag>
|
|
2598
2338
|
|
|
2599
2339
|
Options
|
|
2600
|
-
${
|
|
2340
|
+
${printFlagList(flags, 6)}
|
|
2601
2341
|
|
|
2602
2342
|
Examples
|
|
2603
2343
|
$ ${name} --enable
|
|
@@ -2609,7 +2349,7 @@ function setupCommand$f(name, description, argv, importMeta) {
|
|
|
2609
2349
|
flags
|
|
2610
2350
|
});
|
|
2611
2351
|
if (argv[0] === '--postinstall') {
|
|
2612
|
-
const socketWrapperEnabled =
|
|
2352
|
+
const socketWrapperEnabled = fs.existsSync(BASH_FILE) && checkSocketWrapperAlreadySetup(BASH_FILE) || fs.existsSync(ZSH_BASH_FILE) && checkSocketWrapperAlreadySetup(ZSH_BASH_FILE);
|
|
2613
2353
|
if (!socketWrapperEnabled) {
|
|
2614
2354
|
installSafeNpm(`The Socket CLI is now successfully installed! 🎉
|
|
2615
2355
|
|
|
@@ -2632,23 +2372,23 @@ function setupCommand$f(name, description, argv, importMeta) {
|
|
|
2632
2372
|
return;
|
|
2633
2373
|
}
|
|
2634
2374
|
if (enable) {
|
|
2635
|
-
if (
|
|
2375
|
+
if (fs.existsSync(BASH_FILE)) {
|
|
2636
2376
|
const socketWrapperEnabled = checkSocketWrapperAlreadySetup(BASH_FILE);
|
|
2637
2377
|
!socketWrapperEnabled && addAlias(BASH_FILE);
|
|
2638
2378
|
}
|
|
2639
|
-
if (
|
|
2379
|
+
if (fs.existsSync(ZSH_BASH_FILE)) {
|
|
2640
2380
|
const socketWrapperEnabled = checkSocketWrapperAlreadySetup(ZSH_BASH_FILE);
|
|
2641
2381
|
!socketWrapperEnabled && addAlias(ZSH_BASH_FILE);
|
|
2642
2382
|
}
|
|
2643
2383
|
} else if (disable) {
|
|
2644
|
-
if (
|
|
2384
|
+
if (fs.existsSync(BASH_FILE)) {
|
|
2645
2385
|
removeAlias(BASH_FILE);
|
|
2646
2386
|
}
|
|
2647
|
-
if (
|
|
2387
|
+
if (fs.existsSync(ZSH_BASH_FILE)) {
|
|
2648
2388
|
removeAlias(ZSH_BASH_FILE);
|
|
2649
2389
|
}
|
|
2650
2390
|
}
|
|
2651
|
-
if (!
|
|
2391
|
+
if (!fs.existsSync(BASH_FILE) && !fs.existsSync(ZSH_BASH_FILE)) {
|
|
2652
2392
|
console.error('There was an issue setting up the alias in your bash profile');
|
|
2653
2393
|
}
|
|
2654
2394
|
}
|
|
@@ -2660,7 +2400,7 @@ const installSafeNpm = query => {
|
|
|
2660
2400
|
|_____|___|___|_,_|___|_|
|
|
2661
2401
|
|
|
2662
2402
|
`);
|
|
2663
|
-
const rl =
|
|
2403
|
+
const rl = readline.createInterface({
|
|
2664
2404
|
input: process.stdin,
|
|
2665
2405
|
output: process.stdout
|
|
2666
2406
|
});
|
|
@@ -2670,10 +2410,10 @@ const askQuestion = (rl, query) => {
|
|
|
2670
2410
|
rl.question(query, ans => {
|
|
2671
2411
|
if (ans.toLowerCase() === 'y') {
|
|
2672
2412
|
try {
|
|
2673
|
-
if (
|
|
2413
|
+
if (fs.existsSync(BASH_FILE)) {
|
|
2674
2414
|
addAlias(BASH_FILE);
|
|
2675
2415
|
}
|
|
2676
|
-
if (
|
|
2416
|
+
if (fs.existsSync(ZSH_BASH_FILE)) {
|
|
2677
2417
|
addAlias(ZSH_BASH_FILE);
|
|
2678
2418
|
}
|
|
2679
2419
|
} catch (e) {
|
|
@@ -2688,7 +2428,7 @@ const askQuestion = (rl, query) => {
|
|
|
2688
2428
|
});
|
|
2689
2429
|
};
|
|
2690
2430
|
const addAlias = file => {
|
|
2691
|
-
return
|
|
2431
|
+
return fs.appendFile(file, 'alias npm="socket npm"\nalias npx="socket npx"\n', err => {
|
|
2692
2432
|
if (err) {
|
|
2693
2433
|
return new Error(`There was an error setting up the alias: ${err}`);
|
|
2694
2434
|
}
|
|
@@ -2699,14 +2439,14 @@ If you want to disable it at any time, run \`socket wrapper --disable\`
|
|
|
2699
2439
|
});
|
|
2700
2440
|
};
|
|
2701
2441
|
const removeAlias = file => {
|
|
2702
|
-
return
|
|
2442
|
+
return fs.readFile(file, 'utf8', function (err, data) {
|
|
2703
2443
|
if (err) {
|
|
2704
2444
|
console.error(`There was an error removing the alias: ${err}`);
|
|
2705
2445
|
return;
|
|
2706
2446
|
}
|
|
2707
2447
|
const linesWithoutSocketAlias = data.split('\n').filter(l => l !== 'alias npm="socket npm"' && l !== 'alias npx="socket npx"');
|
|
2708
2448
|
const updatedFileContent = linesWithoutSocketAlias.join('\n');
|
|
2709
|
-
|
|
2449
|
+
fs.writeFile(file, updatedFileContent, function (err) {
|
|
2710
2450
|
if (err) {
|
|
2711
2451
|
console.log(err);
|
|
2712
2452
|
return;
|
|
@@ -2717,7 +2457,7 @@ const removeAlias = file => {
|
|
|
2717
2457
|
});
|
|
2718
2458
|
};
|
|
2719
2459
|
const checkSocketWrapperAlreadySetup = file => {
|
|
2720
|
-
const fileContent =
|
|
2460
|
+
const fileContent = fs.readFileSync(file, 'utf8');
|
|
2721
2461
|
const linesWithSocketAlias = fileContent.split('\n').filter(l => l === 'alias npm="socket npm"' || l === 'alias npx="socket npx"');
|
|
2722
2462
|
if (linesWithSocketAlias.length) {
|
|
2723
2463
|
console.log(`The Socket npm/npx wrapper is set up in your bash profile (${file}).`);
|
|
@@ -2726,42 +2466,20 @@ const checkSocketWrapperAlreadySetup = file => {
|
|
|
2726
2466
|
return false;
|
|
2727
2467
|
};
|
|
2728
2468
|
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
var create$3 = {};
|
|
2732
|
-
|
|
2733
|
-
var _interopRequireDefault$f = vendor.interopRequireDefault.default;
|
|
2734
|
-
Object.defineProperty(create$3, "__esModule", {
|
|
2735
|
-
value: true
|
|
2736
|
-
});
|
|
2737
|
-
create$3.create = void 0;
|
|
2738
|
-
var _nodeProcess = require$$1$6;
|
|
2739
|
-
var _promises$1 = require$$2$4;
|
|
2740
|
-
var _yoctocolorsCjs$e = require$$1$2;
|
|
2741
|
-
var _meow$e = _interopRequireDefault$f(require$$2);
|
|
2742
|
-
var _open = _interopRequireDefault$f(require$$5$3);
|
|
2743
|
-
var _yoctoSpinner$e = require$$3;
|
|
2744
|
-
var _ponyCause$1 = require$$4$1;
|
|
2745
|
-
var _apiHelpers$e = apiHelpers;
|
|
2746
|
-
var _errors$f = sdk.errors;
|
|
2747
|
-
var _formatting$d = formatting;
|
|
2748
|
-
var _misc = sdk.misc;
|
|
2749
|
-
var _pathResolve = pathResolve.pathResolve;
|
|
2750
|
-
var _sdk$e = sdk.sdk;
|
|
2751
|
-
const create$2 = create$3.create = {
|
|
2469
|
+
const create$1 = {
|
|
2752
2470
|
description: 'Create a scan',
|
|
2753
2471
|
async run(argv, importMeta, {
|
|
2754
2472
|
parentName
|
|
2755
2473
|
}) {
|
|
2756
2474
|
const name = `${parentName} create`;
|
|
2757
|
-
const input = await setupCommand$e(name, create$
|
|
2475
|
+
const input = await setupCommand$e(name, create$1.description, argv, importMeta);
|
|
2758
2476
|
if (input) {
|
|
2759
|
-
const apiKey =
|
|
2477
|
+
const apiKey = sdk.getDefaultKey();
|
|
2760
2478
|
if (!apiKey) {
|
|
2761
|
-
throw new
|
|
2479
|
+
throw new sdk.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
2762
2480
|
}
|
|
2763
2481
|
const spinnerText = 'Creating a scan... \n';
|
|
2764
|
-
const spinner =
|
|
2482
|
+
const spinner = yoctoSpinner({
|
|
2765
2483
|
text: spinnerText
|
|
2766
2484
|
}).start();
|
|
2767
2485
|
await createFullScan(input, spinner, apiKey);
|
|
@@ -2830,12 +2548,12 @@ async function setupCommand$e(name, description, argv, importMeta) {
|
|
|
2830
2548
|
const flags = {
|
|
2831
2549
|
...createFullScanFlags
|
|
2832
2550
|
};
|
|
2833
|
-
const cli = (
|
|
2551
|
+
const cli = meow(`
|
|
2834
2552
|
Usage
|
|
2835
2553
|
$ ${name} [...options]
|
|
2836
2554
|
|
|
2837
2555
|
Options
|
|
2838
|
-
${
|
|
2556
|
+
${printFlagList(flags, 6)}
|
|
2839
2557
|
|
|
2840
2558
|
Examples
|
|
2841
2559
|
$ ${name} --org=FakeOrg --repo=test-repo --branch=main ./package.json
|
|
@@ -2857,25 +2575,25 @@ async function setupCommand$e(name, description, argv, importMeta) {
|
|
|
2857
2575
|
0: orgSlug = ''
|
|
2858
2576
|
} = cli.input;
|
|
2859
2577
|
const cwd = process.cwd();
|
|
2860
|
-
const socketSdk = await
|
|
2578
|
+
const socketSdk = await sdk.setupSdk();
|
|
2861
2579
|
const supportedFiles = await socketSdk.getReportSupportedFiles().then(res => {
|
|
2862
|
-
if (!res.success)
|
|
2580
|
+
if (!res.success) handleUnsuccessfulApiResponse('getReportSupportedFiles', res, yoctoSpinner());
|
|
2863
2581
|
return res.data;
|
|
2864
2582
|
}).catch(/** @type {(cause: Error) => never} */
|
|
2865
2583
|
cause => {
|
|
2866
|
-
throw new
|
|
2584
|
+
throw new ponyCause.ErrorWithCause('Failed getting supported files for report', {
|
|
2867
2585
|
cause
|
|
2868
2586
|
});
|
|
2869
2587
|
});
|
|
2870
|
-
const debugLog =
|
|
2871
|
-
const packagePaths = await
|
|
2588
|
+
const debugLog = sdk.createDebugLogger(false);
|
|
2589
|
+
const packagePaths = await pathResolve.getPackageFilesFullScans(cwd, cli.input, supportedFiles, debugLog);
|
|
2872
2590
|
const {
|
|
2873
2591
|
branch: branchName,
|
|
2874
2592
|
repo: repoName
|
|
2875
2593
|
} = cli.flags;
|
|
2876
2594
|
if (!repoName || !branchName || !packagePaths.length) {
|
|
2877
2595
|
showHelp = true;
|
|
2878
|
-
console.error(`${
|
|
2596
|
+
console.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
2879
2597
|
- Repository name using --repo\n
|
|
2880
2598
|
- Branch name using --branch\n
|
|
2881
2599
|
- At least one file path (e.g. ./package.json)`);
|
|
@@ -2899,7 +2617,7 @@ async function setupCommand$e(name, description, argv, importMeta) {
|
|
|
2899
2617
|
};
|
|
2900
2618
|
}
|
|
2901
2619
|
async function createFullScan(input, spinner, apiKey) {
|
|
2902
|
-
const socketSdk = await
|
|
2620
|
+
const socketSdk = await sdk.setupSdk(apiKey);
|
|
2903
2621
|
const {
|
|
2904
2622
|
branchName,
|
|
2905
2623
|
commitMessage,
|
|
@@ -2910,7 +2628,7 @@ async function createFullScan(input, spinner, apiKey) {
|
|
|
2910
2628
|
repoName,
|
|
2911
2629
|
tmp
|
|
2912
2630
|
} = input;
|
|
2913
|
-
const result = await
|
|
2631
|
+
const result = await handleApiCall(socketSdk.createOrgFullScan(orgSlug, {
|
|
2914
2632
|
repo: repoName,
|
|
2915
2633
|
branch: branchName,
|
|
2916
2634
|
commit_message: commitMessage,
|
|
@@ -2919,39 +2637,24 @@ async function createFullScan(input, spinner, apiKey) {
|
|
|
2919
2637
|
tmp
|
|
2920
2638
|
}, packagePaths), 'Creating scan');
|
|
2921
2639
|
if (!result.success) {
|
|
2922
|
-
|
|
2640
|
+
handleUnsuccessfulApiResponse('CreateOrgFullScan', result, spinner);
|
|
2923
2641
|
return;
|
|
2924
2642
|
}
|
|
2925
2643
|
spinner.success('Scan created successfully');
|
|
2926
|
-
const link =
|
|
2644
|
+
const link = colors.underline(colors.cyan(`${result.data.html_report_url}`));
|
|
2927
2645
|
console.log(`Available at: ${link}`);
|
|
2928
|
-
const rl =
|
|
2929
|
-
input:
|
|
2930
|
-
output:
|
|
2646
|
+
const rl = readline$1.createInterface({
|
|
2647
|
+
input: node_process.stdin,
|
|
2648
|
+
output: node_process.stdout
|
|
2931
2649
|
});
|
|
2932
2650
|
const answer = await rl.question('Would you like to open it in your browser? (y/n)');
|
|
2933
2651
|
if (answer.toLowerCase() === 'y') {
|
|
2934
|
-
await (
|
|
2652
|
+
await open(`${result.data.html_report_url}`);
|
|
2935
2653
|
}
|
|
2936
2654
|
rl.close();
|
|
2937
2655
|
}
|
|
2938
2656
|
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
var _interopRequireDefault$e = vendor.interopRequireDefault.default;
|
|
2942
|
-
Object.defineProperty(_delete$3, "__esModule", {
|
|
2943
|
-
value: true
|
|
2944
|
-
});
|
|
2945
|
-
_delete$3.del = void 0;
|
|
2946
|
-
var _yoctocolorsCjs$d = require$$1$2;
|
|
2947
|
-
var _meow$d = _interopRequireDefault$e(require$$2);
|
|
2948
|
-
var _yoctoSpinner$d = require$$3;
|
|
2949
|
-
var _flags$c = flags$1;
|
|
2950
|
-
var _apiHelpers$d = apiHelpers;
|
|
2951
|
-
var _errors$e = sdk.errors;
|
|
2952
|
-
var _formatting$c = formatting;
|
|
2953
|
-
var _sdk$d = sdk.sdk;
|
|
2954
|
-
const del$1 = _delete$3.del = {
|
|
2657
|
+
const del$1 = {
|
|
2955
2658
|
description: 'Delete a scan',
|
|
2956
2659
|
async run(argv, importMeta, {
|
|
2957
2660
|
parentName
|
|
@@ -2959,12 +2662,12 @@ const del$1 = _delete$3.del = {
|
|
|
2959
2662
|
const name = `${parentName} del`;
|
|
2960
2663
|
const input = setupCommand$d(name, del$1.description, argv, importMeta);
|
|
2961
2664
|
if (input) {
|
|
2962
|
-
const apiKey =
|
|
2665
|
+
const apiKey = sdk.getDefaultKey();
|
|
2963
2666
|
if (!apiKey) {
|
|
2964
|
-
throw new
|
|
2667
|
+
throw new sdk.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
2965
2668
|
}
|
|
2966
2669
|
const spinnerText = 'Deleting scan...';
|
|
2967
|
-
const spinner =
|
|
2670
|
+
const spinner = yoctoSpinner({
|
|
2968
2671
|
text: spinnerText
|
|
2969
2672
|
}).start();
|
|
2970
2673
|
await deleteOrgFullScan(input.orgSlug, input.fullScanId, spinner, apiKey);
|
|
@@ -2976,15 +2679,15 @@ const del$1 = _delete$3.del = {
|
|
|
2976
2679
|
|
|
2977
2680
|
function setupCommand$d(name, description, argv, importMeta) {
|
|
2978
2681
|
const flags = {
|
|
2979
|
-
...
|
|
2980
|
-
...
|
|
2682
|
+
...commonFlags,
|
|
2683
|
+
...outputFlags
|
|
2981
2684
|
};
|
|
2982
|
-
const cli = (
|
|
2685
|
+
const cli = meow(`
|
|
2983
2686
|
Usage
|
|
2984
2687
|
$ ${name} <org slug> <scan ID>
|
|
2985
2688
|
|
|
2986
2689
|
Options
|
|
2987
|
-
${
|
|
2690
|
+
${printFlagList(flags, 6)}
|
|
2988
2691
|
|
|
2989
2692
|
Examples
|
|
2990
2693
|
$ ${name} FakeOrg 000aaaa1-0000-0a0a-00a0-00a0000000a0
|
|
@@ -2997,7 +2700,7 @@ function setupCommand$d(name, description, argv, importMeta) {
|
|
|
2997
2700
|
let showHelp = cli.flags['help'];
|
|
2998
2701
|
if (cli.input.length < 2) {
|
|
2999
2702
|
showHelp = true;
|
|
3000
|
-
console.error(`${
|
|
2703
|
+
console.error(`${colors.bgRed(colors.white('Input error'))}: Please specify an organization slug and a scan ID.`);
|
|
3001
2704
|
}
|
|
3002
2705
|
if (showHelp) {
|
|
3003
2706
|
cli.showHelp();
|
|
@@ -3015,47 +2718,29 @@ function setupCommand$d(name, description, argv, importMeta) {
|
|
|
3015
2718
|
};
|
|
3016
2719
|
}
|
|
3017
2720
|
async function deleteOrgFullScan(orgSlug, fullScanId, spinner, apiKey) {
|
|
3018
|
-
const socketSdk = await
|
|
3019
|
-
const result = await
|
|
2721
|
+
const socketSdk = await sdk.setupSdk(apiKey);
|
|
2722
|
+
const result = await handleApiCall(socketSdk.deleteOrgFullScan(orgSlug, fullScanId), 'Deleting scan');
|
|
3020
2723
|
if (result.success) {
|
|
3021
2724
|
spinner.success('Scan deleted successfully');
|
|
3022
2725
|
} else {
|
|
3023
|
-
|
|
2726
|
+
handleUnsuccessfulApiResponse('deleteOrgFullScan', result, spinner);
|
|
3024
2727
|
}
|
|
3025
2728
|
}
|
|
3026
2729
|
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
var _interopRequireDefault$d = vendor.interopRequireDefault.default;
|
|
3030
|
-
Object.defineProperty(list$3, "__esModule", {
|
|
3031
|
-
value: true
|
|
3032
|
-
});
|
|
3033
|
-
list$3.list = void 0;
|
|
3034
|
-
var _yoctocolorsCjs$c = require$$1$2;
|
|
3035
|
-
var _chalkTable$3 = require$$2$5;
|
|
3036
|
-
var _meow$c = _interopRequireDefault$d(require$$2);
|
|
3037
|
-
var _yoctoSpinner$c = require$$3;
|
|
3038
|
-
var _flags$b = flags$1;
|
|
3039
|
-
var _apiHelpers$c = apiHelpers;
|
|
3040
|
-
var _errors$d = sdk.errors;
|
|
3041
|
-
var _formatting$b = formatting;
|
|
3042
|
-
var _sdk$c = sdk.sdk;
|
|
3043
|
-
// @ts-ignore
|
|
3044
|
-
|
|
3045
|
-
const list$2 = list$3.list = {
|
|
2730
|
+
const list$1 = {
|
|
3046
2731
|
description: 'List scans for an organization',
|
|
3047
2732
|
async run(argv, importMeta, {
|
|
3048
2733
|
parentName
|
|
3049
2734
|
}) {
|
|
3050
2735
|
const name = `${parentName} list`;
|
|
3051
|
-
const input = setupCommand$c(name, list$
|
|
2736
|
+
const input = setupCommand$c(name, list$1.description, argv, importMeta);
|
|
3052
2737
|
if (input) {
|
|
3053
|
-
const apiKey =
|
|
2738
|
+
const apiKey = sdk.getDefaultKey();
|
|
3054
2739
|
if (!apiKey) {
|
|
3055
|
-
throw new
|
|
2740
|
+
throw new sdk.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
3056
2741
|
}
|
|
3057
2742
|
const spinnerText = 'Listing scans... \n';
|
|
3058
|
-
const spinner =
|
|
2743
|
+
const spinner = yoctoSpinner({
|
|
3059
2744
|
text: spinnerText
|
|
3060
2745
|
}).start();
|
|
3061
2746
|
await listOrgFullScan(input.orgSlug, input, spinner, apiKey);
|
|
@@ -3105,16 +2790,16 @@ const listFullScanFlags = {
|
|
|
3105
2790
|
|
|
3106
2791
|
function setupCommand$c(name, description, argv, importMeta) {
|
|
3107
2792
|
const flags = {
|
|
3108
|
-
...
|
|
2793
|
+
...commonFlags,
|
|
3109
2794
|
...listFullScanFlags,
|
|
3110
|
-
...
|
|
2795
|
+
...outputFlags
|
|
3111
2796
|
};
|
|
3112
|
-
const cli = (
|
|
2797
|
+
const cli = meow(`
|
|
3113
2798
|
Usage
|
|
3114
2799
|
$ ${name} <org slug>
|
|
3115
2800
|
|
|
3116
2801
|
Options
|
|
3117
|
-
${
|
|
2802
|
+
${printFlagList(flags, 6)}
|
|
3118
2803
|
|
|
3119
2804
|
Examples
|
|
3120
2805
|
$ ${name} FakeOrg
|
|
@@ -3127,7 +2812,7 @@ function setupCommand$c(name, description, argv, importMeta) {
|
|
|
3127
2812
|
let showHelp = cli.flags['help'];
|
|
3128
2813
|
if (!cli.input[0]) {
|
|
3129
2814
|
showHelp = true;
|
|
3130
|
-
console.error(`${
|
|
2815
|
+
console.error(`${colors.bgRed(colors.white('Input error'))}: Please specify an organization slug.`);
|
|
3131
2816
|
}
|
|
3132
2817
|
if (showHelp) {
|
|
3133
2818
|
cli.showHelp();
|
|
@@ -3149,31 +2834,31 @@ function setupCommand$c(name, description, argv, importMeta) {
|
|
|
3149
2834
|
};
|
|
3150
2835
|
}
|
|
3151
2836
|
async function listOrgFullScan(orgSlug, input, spinner, apiKey) {
|
|
3152
|
-
const socketSdk = await
|
|
3153
|
-
const result = await
|
|
2837
|
+
const socketSdk = await sdk.setupSdk(apiKey);
|
|
2838
|
+
const result = await handleApiCall(socketSdk.getOrgFullScanList(orgSlug, input), 'Listing scans');
|
|
3154
2839
|
if (!result.success) {
|
|
3155
|
-
|
|
2840
|
+
handleUnsuccessfulApiResponse('getOrgFullScanList', result, spinner);
|
|
3156
2841
|
return;
|
|
3157
2842
|
}
|
|
3158
2843
|
const options = {
|
|
3159
2844
|
columns: [{
|
|
3160
2845
|
field: 'id',
|
|
3161
|
-
name:
|
|
2846
|
+
name: colors.magenta('ID')
|
|
3162
2847
|
}, {
|
|
3163
2848
|
field: 'report_url',
|
|
3164
|
-
name:
|
|
2849
|
+
name: colors.magenta('Scan URL')
|
|
3165
2850
|
}, {
|
|
3166
2851
|
field: 'branch',
|
|
3167
|
-
name:
|
|
2852
|
+
name: colors.magenta('Branch')
|
|
3168
2853
|
}, {
|
|
3169
2854
|
field: 'created_at',
|
|
3170
|
-
name:
|
|
2855
|
+
name: colors.magenta('Created at')
|
|
3171
2856
|
}]
|
|
3172
2857
|
};
|
|
3173
2858
|
const formattedResults = result.data.results.map(d => {
|
|
3174
2859
|
return {
|
|
3175
2860
|
id: d.id,
|
|
3176
|
-
report_url:
|
|
2861
|
+
report_url: colors.underline(`${d.html_report_url}`),
|
|
3177
2862
|
created_at: d.created_at ? new Date(d.created_at).toLocaleDateString('en-us', {
|
|
3178
2863
|
year: 'numeric',
|
|
3179
2864
|
month: 'numeric',
|
|
@@ -3183,25 +2868,10 @@ async function listOrgFullScan(orgSlug, input, spinner, apiKey) {
|
|
|
3183
2868
|
};
|
|
3184
2869
|
});
|
|
3185
2870
|
spinner.stop(`Listing scans for: ${orgSlug}`);
|
|
3186
|
-
console.log(
|
|
2871
|
+
console.log(chalkTable(options, formattedResults));
|
|
3187
2872
|
}
|
|
3188
2873
|
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
var _interopRequireDefault$c = vendor.interopRequireDefault.default;
|
|
3192
|
-
Object.defineProperty(metadata$1, "__esModule", {
|
|
3193
|
-
value: true
|
|
3194
|
-
});
|
|
3195
|
-
metadata$1.metadata = void 0;
|
|
3196
|
-
var _yoctocolorsCjs$b = require$$1$2;
|
|
3197
|
-
var _meow$b = _interopRequireDefault$c(require$$2);
|
|
3198
|
-
var _yoctoSpinner$b = require$$3;
|
|
3199
|
-
var _flags$a = flags$1;
|
|
3200
|
-
var _apiHelpers$b = apiHelpers;
|
|
3201
|
-
var _errors$c = sdk.errors;
|
|
3202
|
-
var _formatting$a = formatting;
|
|
3203
|
-
var _sdk$b = sdk.sdk;
|
|
3204
|
-
const metadata = metadata$1.metadata = {
|
|
2874
|
+
const metadata = {
|
|
3205
2875
|
description: "Get a scan's metadata",
|
|
3206
2876
|
async run(argv, importMeta, {
|
|
3207
2877
|
parentName
|
|
@@ -3209,12 +2879,12 @@ const metadata = metadata$1.metadata = {
|
|
|
3209
2879
|
const name = `${parentName} metadata`;
|
|
3210
2880
|
const input = setupCommand$b(name, metadata.description, argv, importMeta);
|
|
3211
2881
|
if (input) {
|
|
3212
|
-
const apiKey =
|
|
2882
|
+
const apiKey = sdk.getDefaultKey();
|
|
3213
2883
|
if (!apiKey) {
|
|
3214
|
-
throw new
|
|
2884
|
+
throw new sdk.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
3215
2885
|
}
|
|
3216
2886
|
const spinnerText = "Getting scan's metadata... \n";
|
|
3217
|
-
const spinner =
|
|
2887
|
+
const spinner = yoctoSpinner({
|
|
3218
2888
|
text: spinnerText
|
|
3219
2889
|
}).start();
|
|
3220
2890
|
await getOrgScanMetadata(input.orgSlug, input.scanID, spinner, apiKey);
|
|
@@ -3226,15 +2896,15 @@ const metadata = metadata$1.metadata = {
|
|
|
3226
2896
|
|
|
3227
2897
|
function setupCommand$b(name, description, argv, importMeta) {
|
|
3228
2898
|
const flags = {
|
|
3229
|
-
...
|
|
3230
|
-
...
|
|
2899
|
+
...commonFlags,
|
|
2900
|
+
...outputFlags
|
|
3231
2901
|
};
|
|
3232
|
-
const cli = (
|
|
2902
|
+
const cli = meow(`
|
|
3233
2903
|
Usage
|
|
3234
2904
|
$ ${name} <org slug> <scan id>
|
|
3235
2905
|
|
|
3236
2906
|
Options
|
|
3237
|
-
${
|
|
2907
|
+
${printFlagList(flags, 6)}
|
|
3238
2908
|
|
|
3239
2909
|
Examples
|
|
3240
2910
|
$ ${name} FakeOrg 000aaaa1-0000-0a0a-00a0-00a0000000a0
|
|
@@ -3247,7 +2917,7 @@ function setupCommand$b(name, description, argv, importMeta) {
|
|
|
3247
2917
|
let showHelp = cli.flags['help'];
|
|
3248
2918
|
if (cli.input.length < 2) {
|
|
3249
2919
|
showHelp = true;
|
|
3250
|
-
console.error(`${
|
|
2920
|
+
console.error(`${colors.bgRed(colors.white('Input error'))}: Please specify an organization slug and a scan ID.`);
|
|
3251
2921
|
}
|
|
3252
2922
|
if (showHelp) {
|
|
3253
2923
|
cli.showHelp();
|
|
@@ -3265,32 +2935,17 @@ function setupCommand$b(name, description, argv, importMeta) {
|
|
|
3265
2935
|
};
|
|
3266
2936
|
}
|
|
3267
2937
|
async function getOrgScanMetadata(orgSlug, scanId, spinner, apiKey) {
|
|
3268
|
-
const socketSdk = await
|
|
3269
|
-
const result = await
|
|
2938
|
+
const socketSdk = await sdk.setupSdk(apiKey);
|
|
2939
|
+
const result = await handleApiCall(socketSdk.getOrgFullScanMetadata(orgSlug, scanId), 'Listing scans');
|
|
3270
2940
|
if (!result.success) {
|
|
3271
|
-
|
|
2941
|
+
handleUnsuccessfulApiResponse('getOrgFullScanMetadata', result, spinner);
|
|
3272
2942
|
return;
|
|
3273
2943
|
}
|
|
3274
2944
|
spinner.stop('Scan metadata:');
|
|
3275
2945
|
console.log(result.data);
|
|
3276
2946
|
}
|
|
3277
2947
|
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
var _interopRequireDefault$b = vendor.interopRequireDefault.default;
|
|
3281
|
-
Object.defineProperty(stream$1, "__esModule", {
|
|
3282
|
-
value: true
|
|
3283
|
-
});
|
|
3284
|
-
stream$1.stream = void 0;
|
|
3285
|
-
var _yoctocolorsCjs$a = require$$1$2;
|
|
3286
|
-
var _meow$a = _interopRequireDefault$b(require$$2);
|
|
3287
|
-
var _yoctoSpinner$a = require$$3;
|
|
3288
|
-
var _flags$9 = flags$1;
|
|
3289
|
-
var _apiHelpers$a = apiHelpers;
|
|
3290
|
-
var _errors$b = sdk.errors;
|
|
3291
|
-
var _formatting$9 = formatting;
|
|
3292
|
-
var _sdk$a = sdk.sdk;
|
|
3293
|
-
const stream = stream$1.stream = {
|
|
2948
|
+
const stream = {
|
|
3294
2949
|
description: 'Stream the output of a scan',
|
|
3295
2950
|
async run(argv, importMeta, {
|
|
3296
2951
|
parentName
|
|
@@ -3298,18 +2953,18 @@ const stream = stream$1.stream = {
|
|
|
3298
2953
|
const name = `${parentName} stream`;
|
|
3299
2954
|
const input = setupCommand$a(name, stream.description, argv, importMeta);
|
|
3300
2955
|
if (input) {
|
|
3301
|
-
const apiKey =
|
|
2956
|
+
const apiKey = sdk.getDefaultKey();
|
|
3302
2957
|
if (!apiKey) {
|
|
3303
|
-
throw new
|
|
2958
|
+
throw new sdk.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
3304
2959
|
}
|
|
3305
|
-
const spinner =
|
|
2960
|
+
const spinner = yoctoSpinner({
|
|
3306
2961
|
text: 'Streaming scan...'
|
|
3307
2962
|
}).start();
|
|
3308
2963
|
const result = await getOrgFullScan(input.orgSlug, input.fullScanId, input.file, apiKey);
|
|
3309
2964
|
if (result?.success) {
|
|
3310
2965
|
spinner.stop(input.file ? `Full scan details written to ${input.file}` : '');
|
|
3311
2966
|
} else {
|
|
3312
|
-
|
|
2967
|
+
handleUnsuccessfulApiResponse('getOrgFullScan', result, spinner);
|
|
3313
2968
|
}
|
|
3314
2969
|
}
|
|
3315
2970
|
}
|
|
@@ -3319,15 +2974,15 @@ const stream = stream$1.stream = {
|
|
|
3319
2974
|
|
|
3320
2975
|
function setupCommand$a(name, description, argv, importMeta) {
|
|
3321
2976
|
const flags = {
|
|
3322
|
-
...
|
|
3323
|
-
...
|
|
2977
|
+
...commonFlags,
|
|
2978
|
+
...outputFlags
|
|
3324
2979
|
};
|
|
3325
|
-
const cli = (
|
|
2980
|
+
const cli = meow(`
|
|
3326
2981
|
Usage
|
|
3327
2982
|
$ ${name} <org slug> <scan ID> <path to output file>
|
|
3328
2983
|
|
|
3329
2984
|
Options
|
|
3330
|
-
${
|
|
2985
|
+
${printFlagList(flags, 6)}
|
|
3331
2986
|
|
|
3332
2987
|
Examples
|
|
3333
2988
|
$ ${name} FakeOrg 000aaaa1-0000-0a0a-00a0-00a0000000a0 ./stream.txt
|
|
@@ -3340,7 +2995,7 @@ function setupCommand$a(name, description, argv, importMeta) {
|
|
|
3340
2995
|
let showHelp = cli.flags['help'];
|
|
3341
2996
|
if (cli.input.length < 2) {
|
|
3342
2997
|
showHelp = true;
|
|
3343
|
-
console.error(`${
|
|
2998
|
+
console.error(`${colors.bgRed(colors.white('Input error'))}: Please specify an organization slug and a scan ID.`);
|
|
3344
2999
|
}
|
|
3345
3000
|
if (showHelp) {
|
|
3346
3001
|
cli.showHelp();
|
|
@@ -3360,32 +3015,22 @@ function setupCommand$a(name, description, argv, importMeta) {
|
|
|
3360
3015
|
};
|
|
3361
3016
|
}
|
|
3362
3017
|
async function getOrgFullScan(orgSlug, fullScanId, file, apiKey) {
|
|
3363
|
-
const socketSdk = await
|
|
3364
|
-
return await
|
|
3018
|
+
const socketSdk = await sdk.setupSdk(apiKey);
|
|
3019
|
+
return await handleApiCall(socketSdk.getOrgFullScan(orgSlug, fullScanId, file), 'Streaming a scan');
|
|
3365
3020
|
}
|
|
3366
3021
|
|
|
3367
|
-
Object.defineProperty(scan, "__esModule", {
|
|
3368
|
-
value: true
|
|
3369
|
-
});
|
|
3370
|
-
scan.scan = void 0;
|
|
3371
|
-
var _create$1 = create$3;
|
|
3372
|
-
var _delete$2 = _delete$3;
|
|
3373
|
-
var _list$1 = list$3;
|
|
3374
|
-
var _metadata = metadata$1;
|
|
3375
|
-
var _stream = stream$1;
|
|
3376
|
-
var _meowWithSubcommands$3 = meowWithSubcommands$1;
|
|
3377
3022
|
const description$2 = 'Scans related commands';
|
|
3378
|
-
scan
|
|
3023
|
+
const scan = {
|
|
3379
3024
|
description: description$2,
|
|
3380
3025
|
async run(argv, importMeta, {
|
|
3381
3026
|
parentName
|
|
3382
3027
|
}) {
|
|
3383
|
-
await
|
|
3384
|
-
create:
|
|
3385
|
-
stream
|
|
3386
|
-
list:
|
|
3387
|
-
del:
|
|
3388
|
-
metadata
|
|
3028
|
+
await meowWithSubcommands({
|
|
3029
|
+
create: create$1,
|
|
3030
|
+
stream,
|
|
3031
|
+
list: list$1,
|
|
3032
|
+
del: del$1,
|
|
3033
|
+
metadata
|
|
3389
3034
|
}, {
|
|
3390
3035
|
argv,
|
|
3391
3036
|
description: description$2,
|
|
@@ -3395,24 +3040,7 @@ scan.scan = {
|
|
|
3395
3040
|
}
|
|
3396
3041
|
};
|
|
3397
3042
|
|
|
3398
|
-
|
|
3399
|
-
|
|
3400
|
-
var _interopRequireDefault$a = vendor.interopRequireDefault.default;
|
|
3401
|
-
var _interopRequireWildcard$1 = vendor.interopRequireWildcard.default;
|
|
3402
|
-
Object.defineProperty(auditLog$1, "__esModule", {
|
|
3403
|
-
value: true
|
|
3404
|
-
});
|
|
3405
|
-
auditLog$1.auditLog = void 0;
|
|
3406
|
-
var _select = _interopRequireWildcard$1(require$$3$3, true);
|
|
3407
|
-
var _yoctocolorsCjs$9 = require$$1$2;
|
|
3408
|
-
var _meow$9 = _interopRequireDefault$a(require$$2);
|
|
3409
|
-
var _yoctoSpinner$9 = require$$3;
|
|
3410
|
-
var _flags$8 = flags$1;
|
|
3411
|
-
var _apiHelpers$9 = apiHelpers;
|
|
3412
|
-
var _errors$a = sdk.errors;
|
|
3413
|
-
var _formatting$8 = formatting;
|
|
3414
|
-
var _sdk$9 = sdk.sdk;
|
|
3415
|
-
const auditLog = auditLog$1.auditLog = {
|
|
3043
|
+
const auditLog = {
|
|
3416
3044
|
description: 'Look up the audit log for an organization',
|
|
3417
3045
|
async run(argv, importMeta, {
|
|
3418
3046
|
parentName
|
|
@@ -3420,11 +3048,11 @@ const auditLog = auditLog$1.auditLog = {
|
|
|
3420
3048
|
const name = parentName + ' audit-log';
|
|
3421
3049
|
const input = setupCommand$9(name, auditLog.description, argv, importMeta);
|
|
3422
3050
|
if (input) {
|
|
3423
|
-
const apiKey =
|
|
3051
|
+
const apiKey = sdk.getDefaultKey();
|
|
3424
3052
|
if (!apiKey) {
|
|
3425
|
-
throw new
|
|
3053
|
+
throw new sdk.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
3426
3054
|
}
|
|
3427
|
-
const spinner =
|
|
3055
|
+
const spinner = yoctoSpinner({
|
|
3428
3056
|
text: `Looking up audit log for ${input.orgSlug}\n`
|
|
3429
3057
|
}).start();
|
|
3430
3058
|
await fetchOrgAuditLog(input.orgSlug, input, spinner, apiKey);
|
|
@@ -3457,15 +3085,15 @@ const auditLogFlags = {
|
|
|
3457
3085
|
function setupCommand$9(name, description, argv, importMeta) {
|
|
3458
3086
|
const flags = {
|
|
3459
3087
|
...auditLogFlags,
|
|
3460
|
-
...
|
|
3461
|
-
...
|
|
3088
|
+
...commonFlags,
|
|
3089
|
+
...outputFlags
|
|
3462
3090
|
};
|
|
3463
|
-
const cli = (
|
|
3091
|
+
const cli = meow(`
|
|
3464
3092
|
Usage
|
|
3465
3093
|
$ ${name} <org slug>
|
|
3466
3094
|
|
|
3467
3095
|
Options
|
|
3468
|
-
${
|
|
3096
|
+
${printFlagList(flags, 6)}
|
|
3469
3097
|
|
|
3470
3098
|
Examples
|
|
3471
3099
|
$ ${name} FakeOrg
|
|
@@ -3478,7 +3106,7 @@ function setupCommand$9(name, description, argv, importMeta) {
|
|
|
3478
3106
|
let showHelp = cli.flags['help'];
|
|
3479
3107
|
if (cli.input.length < 1) {
|
|
3480
3108
|
showHelp = true;
|
|
3481
|
-
console.error(`${
|
|
3109
|
+
console.error(`${colors.bgRed(colors.white('Input error'))}: Please provide an organization slug.`);
|
|
3482
3110
|
}
|
|
3483
3111
|
if (showHelp) {
|
|
3484
3112
|
cli.showHelp();
|
|
@@ -3504,10 +3132,10 @@ function setupCommand$9(name, description, argv, importMeta) {
|
|
|
3504
3132
|
};
|
|
3505
3133
|
}
|
|
3506
3134
|
async function fetchOrgAuditLog(orgSlug, input, spinner, apiKey) {
|
|
3507
|
-
const socketSdk = await
|
|
3508
|
-
const result = await
|
|
3135
|
+
const socketSdk = await sdk.setupSdk(apiKey);
|
|
3136
|
+
const result = await handleApiCall(socketSdk.getAuditLogEvents(orgSlug, input), `Looking up audit log for ${orgSlug}\n`);
|
|
3509
3137
|
if (!result.success) {
|
|
3510
|
-
|
|
3138
|
+
handleUnsuccessfulApiResponse('getAuditLogEvents', result, spinner);
|
|
3511
3139
|
return;
|
|
3512
3140
|
}
|
|
3513
3141
|
spinner.stop();
|
|
@@ -3525,35 +3153,18 @@ async function fetchOrgAuditLog(orgSlug, input, spinner, apiKey) {
|
|
|
3525
3153
|
})} - ${d.user_email} - ${d.type} - ${d.ip_address} - ${d.user_agent}`;
|
|
3526
3154
|
data.push({
|
|
3527
3155
|
name
|
|
3528
|
-
}, new
|
|
3156
|
+
}, new prompts.Separator());
|
|
3529
3157
|
logDetails[name] = JSON.stringify(d.payload);
|
|
3530
3158
|
}
|
|
3531
3159
|
}
|
|
3532
|
-
console.log(logDetails[await
|
|
3160
|
+
console.log(logDetails[await prompts.select({
|
|
3533
3161
|
message: input.type ? `\n Audit log for: ${orgSlug} with type: ${input.type}\n` : `\n Audit log for: ${orgSlug}\n`,
|
|
3534
3162
|
choices: data,
|
|
3535
3163
|
pageSize: 30
|
|
3536
3164
|
})]);
|
|
3537
3165
|
}
|
|
3538
3166
|
|
|
3539
|
-
|
|
3540
|
-
|
|
3541
|
-
var create$1 = {};
|
|
3542
|
-
|
|
3543
|
-
var _interopRequireDefault$9 = vendor.interopRequireDefault.default;
|
|
3544
|
-
Object.defineProperty(create$1, "__esModule", {
|
|
3545
|
-
value: true
|
|
3546
|
-
});
|
|
3547
|
-
create$1.create = void 0;
|
|
3548
|
-
var _yoctocolorsCjs$8 = require$$1$2;
|
|
3549
|
-
var _meow$8 = _interopRequireDefault$9(require$$2);
|
|
3550
|
-
var _yoctoSpinner$8 = require$$3;
|
|
3551
|
-
var _flags$7 = flags$1;
|
|
3552
|
-
var _apiHelpers$8 = apiHelpers;
|
|
3553
|
-
var _errors$9 = sdk.errors;
|
|
3554
|
-
var _formatting$7 = formatting;
|
|
3555
|
-
var _sdk$8 = sdk.sdk;
|
|
3556
|
-
const create = create$1.create = {
|
|
3167
|
+
const create = {
|
|
3557
3168
|
description: 'Create a repository in an organization',
|
|
3558
3169
|
async run(argv, importMeta, {
|
|
3559
3170
|
parentName
|
|
@@ -3561,12 +3172,12 @@ const create = create$1.create = {
|
|
|
3561
3172
|
const name = `${parentName} create`;
|
|
3562
3173
|
const input = setupCommand$8(name, create.description, argv, importMeta);
|
|
3563
3174
|
if (input) {
|
|
3564
|
-
const apiKey =
|
|
3175
|
+
const apiKey = sdk.getDefaultKey();
|
|
3565
3176
|
if (!apiKey) {
|
|
3566
|
-
throw new
|
|
3177
|
+
throw new sdk.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
3567
3178
|
}
|
|
3568
3179
|
const spinnerText = 'Creating repository... \n';
|
|
3569
|
-
const spinner =
|
|
3180
|
+
const spinner = yoctoSpinner({
|
|
3570
3181
|
text: spinnerText
|
|
3571
3182
|
}).start();
|
|
3572
3183
|
await createRepo(input.orgSlug, input, spinner, apiKey);
|
|
@@ -3610,16 +3221,16 @@ const repositoryCreationFlags = {
|
|
|
3610
3221
|
|
|
3611
3222
|
function setupCommand$8(name, description, argv, importMeta) {
|
|
3612
3223
|
const flags = {
|
|
3613
|
-
...
|
|
3614
|
-
...
|
|
3224
|
+
...commonFlags,
|
|
3225
|
+
...outputFlags,
|
|
3615
3226
|
...repositoryCreationFlags
|
|
3616
3227
|
};
|
|
3617
|
-
const cli = (
|
|
3228
|
+
const cli = meow(`
|
|
3618
3229
|
Usage
|
|
3619
3230
|
$ ${name} <org slug>
|
|
3620
3231
|
|
|
3621
3232
|
Options
|
|
3622
|
-
${
|
|
3233
|
+
${printFlagList(flags, 6)}
|
|
3623
3234
|
|
|
3624
3235
|
Examples
|
|
3625
3236
|
$ ${name} FakeOrg --repoName=test-repo
|
|
@@ -3636,10 +3247,10 @@ function setupCommand$8(name, description, argv, importMeta) {
|
|
|
3636
3247
|
let showHelp = cli.flags['help'];
|
|
3637
3248
|
if (!orgSlug) {
|
|
3638
3249
|
showHelp = true;
|
|
3639
|
-
console.error(`${
|
|
3250
|
+
console.error(`${colors.bgRed(colors.white('Input error'))}: Please provide an organization slug.`);
|
|
3640
3251
|
} else if (!repoName) {
|
|
3641
3252
|
showHelp = true;
|
|
3642
|
-
console.error(`${
|
|
3253
|
+
console.error(`${colors.bgRed(colors.white('Input error'))}: Repository name is required.`);
|
|
3643
3254
|
}
|
|
3644
3255
|
if (showHelp) {
|
|
3645
3256
|
cli.showHelp();
|
|
@@ -3657,29 +3268,16 @@ function setupCommand$8(name, description, argv, importMeta) {
|
|
|
3657
3268
|
};
|
|
3658
3269
|
}
|
|
3659
3270
|
async function createRepo(orgSlug, input, spinner, apiKey) {
|
|
3660
|
-
const socketSdk = await
|
|
3661
|
-
const result = await
|
|
3271
|
+
const socketSdk = await sdk.setupSdk(apiKey);
|
|
3272
|
+
const result = await handleApiCall(socketSdk.createOrgRepo(orgSlug, input), 'creating repository');
|
|
3662
3273
|
if (result.success) {
|
|
3663
3274
|
spinner.success('Repository created successfully');
|
|
3664
3275
|
} else {
|
|
3665
|
-
|
|
3276
|
+
handleUnsuccessfulApiResponse('createOrgRepo', result, spinner);
|
|
3666
3277
|
}
|
|
3667
3278
|
}
|
|
3668
3279
|
|
|
3669
|
-
|
|
3670
|
-
|
|
3671
|
-
var _interopRequireDefault$8 = vendor.interopRequireDefault.default;
|
|
3672
|
-
Object.defineProperty(_delete$1, "__esModule", {
|
|
3673
|
-
value: true
|
|
3674
|
-
});
|
|
3675
|
-
_delete$1.del = void 0;
|
|
3676
|
-
var _yoctocolorsCjs$7 = require$$1$2;
|
|
3677
|
-
var _meow$7 = _interopRequireDefault$8(require$$2);
|
|
3678
|
-
var _yoctoSpinner$7 = require$$3;
|
|
3679
|
-
var _apiHelpers$7 = apiHelpers;
|
|
3680
|
-
var _errors$8 = sdk.errors;
|
|
3681
|
-
var _sdk$7 = sdk.sdk;
|
|
3682
|
-
const del = _delete$1.del = {
|
|
3280
|
+
const del = {
|
|
3683
3281
|
description: 'Delete a repository in an organization',
|
|
3684
3282
|
async run(argv, importMeta, {
|
|
3685
3283
|
parentName
|
|
@@ -3687,12 +3285,12 @@ const del = _delete$1.del = {
|
|
|
3687
3285
|
const name = `${parentName} del`;
|
|
3688
3286
|
const input = setupCommand$7(name, del.description, argv, importMeta);
|
|
3689
3287
|
if (input) {
|
|
3690
|
-
const apiKey =
|
|
3288
|
+
const apiKey = sdk.getDefaultKey();
|
|
3691
3289
|
if (!apiKey) {
|
|
3692
|
-
throw new
|
|
3290
|
+
throw new sdk.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
3693
3291
|
}
|
|
3694
3292
|
const spinnerText = 'Deleting repository... \n';
|
|
3695
|
-
const spinner =
|
|
3293
|
+
const spinner = yoctoSpinner({
|
|
3696
3294
|
text: spinnerText
|
|
3697
3295
|
}).start();
|
|
3698
3296
|
await deleteRepository(input.orgSlug, input.repoName, spinner, apiKey);
|
|
@@ -3703,7 +3301,7 @@ const del = _delete$1.del = {
|
|
|
3703
3301
|
// Internal functions
|
|
3704
3302
|
|
|
3705
3303
|
function setupCommand$7(name, description, argv, importMeta) {
|
|
3706
|
-
const cli = (
|
|
3304
|
+
const cli = meow(`
|
|
3707
3305
|
Usage
|
|
3708
3306
|
$ ${name} <org slug> <repo slug>
|
|
3709
3307
|
|
|
@@ -3721,7 +3319,7 @@ function setupCommand$7(name, description, argv, importMeta) {
|
|
|
3721
3319
|
let showHelp = cli.flags['help'];
|
|
3722
3320
|
if (!orgSlug || !repoName) {
|
|
3723
3321
|
showHelp = true;
|
|
3724
|
-
console.error(`${
|
|
3322
|
+
console.error(`${colors.bgRed(colors.white('Input error'))}: Please provide an organization slug and repository slug.`);
|
|
3725
3323
|
}
|
|
3726
3324
|
if (showHelp) {
|
|
3727
3325
|
cli.showHelp();
|
|
@@ -3733,34 +3331,16 @@ function setupCommand$7(name, description, argv, importMeta) {
|
|
|
3733
3331
|
};
|
|
3734
3332
|
}
|
|
3735
3333
|
async function deleteRepository(orgSlug, repoName, spinner, apiKey) {
|
|
3736
|
-
const socketSdk = await
|
|
3737
|
-
const result = await
|
|
3334
|
+
const socketSdk = await sdk.setupSdk(apiKey);
|
|
3335
|
+
const result = await handleApiCall(socketSdk.deleteOrgRepo(orgSlug, repoName), 'deleting repository');
|
|
3738
3336
|
if (result.success) {
|
|
3739
3337
|
spinner.success('Repository deleted successfully');
|
|
3740
3338
|
} else {
|
|
3741
|
-
|
|
3339
|
+
handleUnsuccessfulApiResponse('deleteOrgRepo', result, spinner);
|
|
3742
3340
|
}
|
|
3743
3341
|
}
|
|
3744
3342
|
|
|
3745
|
-
|
|
3746
|
-
|
|
3747
|
-
var _interopRequireDefault$7 = vendor.interopRequireDefault.default;
|
|
3748
|
-
Object.defineProperty(list$1, "__esModule", {
|
|
3749
|
-
value: true
|
|
3750
|
-
});
|
|
3751
|
-
list$1.list = void 0;
|
|
3752
|
-
var _yoctocolorsCjs$6 = require$$1$2;
|
|
3753
|
-
var _chalkTable$2 = require$$2$5;
|
|
3754
|
-
var _meow$6 = _interopRequireDefault$7(require$$2);
|
|
3755
|
-
var _yoctoSpinner$6 = require$$3;
|
|
3756
|
-
var _flags$6 = flags$1;
|
|
3757
|
-
var _apiHelpers$6 = apiHelpers;
|
|
3758
|
-
var _errors$7 = sdk.errors;
|
|
3759
|
-
var _formatting$6 = formatting;
|
|
3760
|
-
var _sdk$6 = sdk.sdk;
|
|
3761
|
-
// @ts-ignore
|
|
3762
|
-
|
|
3763
|
-
const list = list$1.list = {
|
|
3343
|
+
const list = {
|
|
3764
3344
|
description: 'List repositories in an organization',
|
|
3765
3345
|
async run(argv, importMeta, {
|
|
3766
3346
|
parentName
|
|
@@ -3768,12 +3348,12 @@ const list = list$1.list = {
|
|
|
3768
3348
|
const name = `${parentName} list`;
|
|
3769
3349
|
const input = setupCommand$6(name, list.description, argv, importMeta);
|
|
3770
3350
|
if (input) {
|
|
3771
|
-
const apiKey =
|
|
3351
|
+
const apiKey = sdk.getDefaultKey();
|
|
3772
3352
|
if (!apiKey) {
|
|
3773
|
-
throw new
|
|
3353
|
+
throw new sdk.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
3774
3354
|
}
|
|
3775
3355
|
const spinnerText = 'Listing repositories... \n';
|
|
3776
|
-
const spinner =
|
|
3356
|
+
const spinner = yoctoSpinner({
|
|
3777
3357
|
text: spinnerText
|
|
3778
3358
|
}).start();
|
|
3779
3359
|
await listOrgRepos(input.orgSlug, input, spinner, apiKey);
|
|
@@ -3810,16 +3390,16 @@ const listRepoFlags = {
|
|
|
3810
3390
|
|
|
3811
3391
|
function setupCommand$6(name, description, argv, importMeta) {
|
|
3812
3392
|
const flags = {
|
|
3813
|
-
...
|
|
3393
|
+
...commonFlags,
|
|
3814
3394
|
...listRepoFlags,
|
|
3815
|
-
...
|
|
3395
|
+
...outputFlags
|
|
3816
3396
|
};
|
|
3817
|
-
const cli = (
|
|
3397
|
+
const cli = meow(`
|
|
3818
3398
|
Usage
|
|
3819
3399
|
$ ${name} <org slug>
|
|
3820
3400
|
|
|
3821
3401
|
Options
|
|
3822
|
-
${
|
|
3402
|
+
${printFlagList(flags, 6)}
|
|
3823
3403
|
|
|
3824
3404
|
Examples
|
|
3825
3405
|
$ ${name} FakeOrg
|
|
@@ -3832,7 +3412,7 @@ function setupCommand$6(name, description, argv, importMeta) {
|
|
|
3832
3412
|
let showHelp = cli.flags['help'];
|
|
3833
3413
|
if (!cli.input[0]) {
|
|
3834
3414
|
showHelp = true;
|
|
3835
|
-
console.error(`${
|
|
3415
|
+
console.error(`${colors.bgRed(colors.white('Input error'))}: Please provide an organization slug.`);
|
|
3836
3416
|
}
|
|
3837
3417
|
if (showHelp) {
|
|
3838
3418
|
cli.showHelp();
|
|
@@ -3852,49 +3432,34 @@ function setupCommand$6(name, description, argv, importMeta) {
|
|
|
3852
3432
|
};
|
|
3853
3433
|
}
|
|
3854
3434
|
async function listOrgRepos(orgSlug, input, spinner, apiKey) {
|
|
3855
|
-
const socketSdk = await
|
|
3856
|
-
const result = await
|
|
3435
|
+
const socketSdk = await sdk.setupSdk(apiKey);
|
|
3436
|
+
const result = await handleApiCall(socketSdk.getOrgRepoList(orgSlug, input), 'listing repositories');
|
|
3857
3437
|
if (!result.success) {
|
|
3858
|
-
|
|
3438
|
+
handleUnsuccessfulApiResponse('getOrgRepoList', result, spinner);
|
|
3859
3439
|
return;
|
|
3860
3440
|
}
|
|
3861
3441
|
const options = {
|
|
3862
3442
|
columns: [{
|
|
3863
3443
|
field: 'id',
|
|
3864
|
-
name:
|
|
3444
|
+
name: colors.magenta('ID')
|
|
3865
3445
|
}, {
|
|
3866
3446
|
field: 'name',
|
|
3867
|
-
name:
|
|
3447
|
+
name: colors.magenta('Name')
|
|
3868
3448
|
}, {
|
|
3869
3449
|
field: 'visibility',
|
|
3870
|
-
name:
|
|
3450
|
+
name: colors.magenta('Visibility')
|
|
3871
3451
|
}, {
|
|
3872
3452
|
field: 'default_branch',
|
|
3873
|
-
name:
|
|
3453
|
+
name: colors.magenta('Default branch')
|
|
3874
3454
|
}, {
|
|
3875
3455
|
field: 'archived',
|
|
3876
|
-
name:
|
|
3456
|
+
name: colors.magenta('Archived')
|
|
3877
3457
|
}]
|
|
3878
3458
|
};
|
|
3879
|
-
spinner.stop(
|
|
3459
|
+
spinner.stop(chalkTable(options, result.data.results));
|
|
3880
3460
|
}
|
|
3881
3461
|
|
|
3882
|
-
|
|
3883
|
-
|
|
3884
|
-
var _interopRequireDefault$6 = vendor.interopRequireDefault.default;
|
|
3885
|
-
Object.defineProperty(update$1, "__esModule", {
|
|
3886
|
-
value: true
|
|
3887
|
-
});
|
|
3888
|
-
update$1.update = void 0;
|
|
3889
|
-
var _yoctocolorsCjs$5 = require$$1$2;
|
|
3890
|
-
var _meow$5 = _interopRequireDefault$6(require$$2);
|
|
3891
|
-
var _yoctoSpinner$5 = require$$3;
|
|
3892
|
-
var _flags$5 = flags$1;
|
|
3893
|
-
var _apiHelpers$5 = apiHelpers;
|
|
3894
|
-
var _errors$6 = sdk.errors;
|
|
3895
|
-
var _formatting$5 = formatting;
|
|
3896
|
-
var _sdk$5 = sdk.sdk;
|
|
3897
|
-
const update = update$1.update = {
|
|
3462
|
+
const update = {
|
|
3898
3463
|
description: 'Update a repository in an organization',
|
|
3899
3464
|
async run(argv, importMeta, {
|
|
3900
3465
|
parentName
|
|
@@ -3902,12 +3467,12 @@ const update = update$1.update = {
|
|
|
3902
3467
|
const name = `${parentName} update`;
|
|
3903
3468
|
const input = setupCommand$5(name, update.description, argv, importMeta);
|
|
3904
3469
|
if (input) {
|
|
3905
|
-
const apiKey =
|
|
3470
|
+
const apiKey = sdk.getDefaultKey();
|
|
3906
3471
|
if (!apiKey) {
|
|
3907
|
-
throw new
|
|
3472
|
+
throw new sdk.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
3908
3473
|
}
|
|
3909
3474
|
const spinnerText = 'Updating repository... \n';
|
|
3910
|
-
const spinner =
|
|
3475
|
+
const spinner = yoctoSpinner({
|
|
3911
3476
|
text: spinnerText
|
|
3912
3477
|
}).start();
|
|
3913
3478
|
await updateRepository(input.orgSlug, input, spinner, apiKey);
|
|
@@ -3951,16 +3516,16 @@ const repositoryUpdateFlags = {
|
|
|
3951
3516
|
|
|
3952
3517
|
function setupCommand$5(name, description, argv, importMeta) {
|
|
3953
3518
|
const flags = {
|
|
3954
|
-
...
|
|
3955
|
-
...
|
|
3519
|
+
...commonFlags,
|
|
3520
|
+
...outputFlags,
|
|
3956
3521
|
...repositoryUpdateFlags
|
|
3957
3522
|
};
|
|
3958
|
-
const cli = (
|
|
3523
|
+
const cli = meow(`
|
|
3959
3524
|
Usage
|
|
3960
3525
|
$ ${name} <org slug>
|
|
3961
3526
|
|
|
3962
3527
|
Options
|
|
3963
|
-
${
|
|
3528
|
+
${printFlagList(flags, 6)}
|
|
3964
3529
|
|
|
3965
3530
|
Examples
|
|
3966
3531
|
$ ${name} FakeOrg
|
|
@@ -3977,10 +3542,10 @@ function setupCommand$5(name, description, argv, importMeta) {
|
|
|
3977
3542
|
let showHelp = cli.flags['help'];
|
|
3978
3543
|
if (!orgSlug) {
|
|
3979
3544
|
showHelp = true;
|
|
3980
|
-
console.error(`${
|
|
3545
|
+
console.error(`${colors.bgRed(colors.white('Input error'))}: Please provide an organization slug and repository name.`);
|
|
3981
3546
|
} else if (!repoName) {
|
|
3982
3547
|
showHelp = true;
|
|
3983
|
-
console.error(`${
|
|
3548
|
+
console.error(`${colors.bgRed(colors.white('Input error'))}: Repository name is required.`);
|
|
3984
3549
|
}
|
|
3985
3550
|
if (showHelp) {
|
|
3986
3551
|
cli.showHelp();
|
|
@@ -3998,34 +3563,16 @@ function setupCommand$5(name, description, argv, importMeta) {
|
|
|
3998
3563
|
};
|
|
3999
3564
|
}
|
|
4000
3565
|
async function updateRepository(orgSlug, input, spinner, apiKey) {
|
|
4001
|
-
const socketSdk = await
|
|
4002
|
-
const result = await
|
|
3566
|
+
const socketSdk = await sdk.setupSdk(apiKey);
|
|
3567
|
+
const result = await handleApiCall(socketSdk.updateOrgRepo(orgSlug, input.name, input), 'updating repository');
|
|
4003
3568
|
if (result.success) {
|
|
4004
3569
|
spinner.success('Repository updated successfully');
|
|
4005
3570
|
} else {
|
|
4006
|
-
|
|
3571
|
+
handleUnsuccessfulApiResponse('updateOrgRepo', result, spinner);
|
|
4007
3572
|
}
|
|
4008
3573
|
}
|
|
4009
3574
|
|
|
4010
|
-
|
|
4011
|
-
|
|
4012
|
-
var _interopRequireDefault$5 = vendor.interopRequireDefault.default;
|
|
4013
|
-
Object.defineProperty(view$1, "__esModule", {
|
|
4014
|
-
value: true
|
|
4015
|
-
});
|
|
4016
|
-
view$1.view = void 0;
|
|
4017
|
-
var _yoctocolorsCjs$4 = require$$1$2;
|
|
4018
|
-
var _chalkTable$1 = require$$2$5;
|
|
4019
|
-
var _meow$4 = _interopRequireDefault$5(require$$2);
|
|
4020
|
-
var _yoctoSpinner$4 = require$$3;
|
|
4021
|
-
var _flags$4 = flags$1;
|
|
4022
|
-
var _apiHelpers$4 = apiHelpers;
|
|
4023
|
-
var _errors$5 = sdk.errors;
|
|
4024
|
-
var _formatting$4 = formatting;
|
|
4025
|
-
var _sdk$4 = sdk.sdk;
|
|
4026
|
-
// @ts-ignore
|
|
4027
|
-
|
|
4028
|
-
const view = view$1.view = {
|
|
3575
|
+
const view = {
|
|
4029
3576
|
description: 'View repositories in an organization',
|
|
4030
3577
|
async run(argv, importMeta, {
|
|
4031
3578
|
parentName
|
|
@@ -4033,12 +3580,12 @@ const view = view$1.view = {
|
|
|
4033
3580
|
const name = `${parentName} view`;
|
|
4034
3581
|
const input = setupCommand$4(name, view.description, argv, importMeta);
|
|
4035
3582
|
if (input) {
|
|
4036
|
-
const apiKey =
|
|
3583
|
+
const apiKey = sdk.getDefaultKey();
|
|
4037
3584
|
if (!apiKey) {
|
|
4038
|
-
throw new
|
|
3585
|
+
throw new sdk.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
4039
3586
|
}
|
|
4040
3587
|
const spinnerText = 'Fetching repository... \n';
|
|
4041
|
-
const spinner =
|
|
3588
|
+
const spinner = yoctoSpinner({
|
|
4042
3589
|
text: spinnerText
|
|
4043
3590
|
}).start();
|
|
4044
3591
|
await viewRepository(input.orgSlug, input.repositoryName, spinner, apiKey);
|
|
@@ -4050,15 +3597,15 @@ const view = view$1.view = {
|
|
|
4050
3597
|
|
|
4051
3598
|
function setupCommand$4(name, description, argv, importMeta) {
|
|
4052
3599
|
const flags = {
|
|
4053
|
-
...
|
|
4054
|
-
...
|
|
3600
|
+
...commonFlags,
|
|
3601
|
+
...outputFlags
|
|
4055
3602
|
};
|
|
4056
|
-
const cli = (
|
|
3603
|
+
const cli = meow(`
|
|
4057
3604
|
Usage
|
|
4058
3605
|
$ ${name} <org slug>
|
|
4059
3606
|
|
|
4060
3607
|
Options
|
|
4061
|
-
${
|
|
3608
|
+
${printFlagList(flags, 6)}
|
|
4062
3609
|
|
|
4063
3610
|
Examples
|
|
4064
3611
|
$ ${name} FakeOrg
|
|
@@ -4071,7 +3618,7 @@ function setupCommand$4(name, description, argv, importMeta) {
|
|
|
4071
3618
|
let showHelp = cli.flags['help'];
|
|
4072
3619
|
if (!cli.input[0]) {
|
|
4073
3620
|
showHelp = true;
|
|
4074
|
-
console.error(`${
|
|
3621
|
+
console.error(`${colors.bgRed(colors.white('Input error'))}: Please provide an organization slug and repository name.`);
|
|
4075
3622
|
}
|
|
4076
3623
|
if (showHelp) {
|
|
4077
3624
|
cli.showHelp();
|
|
@@ -4089,61 +3636,51 @@ function setupCommand$4(name, description, argv, importMeta) {
|
|
|
4089
3636
|
};
|
|
4090
3637
|
}
|
|
4091
3638
|
async function viewRepository(orgSlug, repoName, spinner, apiKey) {
|
|
4092
|
-
const socketSdk = await
|
|
4093
|
-
const result = await
|
|
3639
|
+
const socketSdk = await sdk.setupSdk(apiKey);
|
|
3640
|
+
const result = await handleApiCall(socketSdk.getOrgRepo(orgSlug, repoName), 'fetching repository');
|
|
4094
3641
|
if (!result.success) {
|
|
4095
|
-
|
|
3642
|
+
handleUnsuccessfulApiResponse('getOrgRepo', result, spinner);
|
|
4096
3643
|
return;
|
|
4097
3644
|
}
|
|
4098
3645
|
const options = {
|
|
4099
3646
|
columns: [{
|
|
4100
3647
|
field: 'id',
|
|
4101
|
-
name:
|
|
3648
|
+
name: colors.magenta('ID')
|
|
4102
3649
|
}, {
|
|
4103
3650
|
field: 'name',
|
|
4104
|
-
name:
|
|
3651
|
+
name: colors.magenta('Name')
|
|
4105
3652
|
}, {
|
|
4106
3653
|
field: 'visibility',
|
|
4107
|
-
name:
|
|
3654
|
+
name: colors.magenta('Visibility')
|
|
4108
3655
|
}, {
|
|
4109
3656
|
field: 'default_branch',
|
|
4110
|
-
name:
|
|
3657
|
+
name: colors.magenta('Default branch')
|
|
4111
3658
|
}, {
|
|
4112
3659
|
field: 'homepage',
|
|
4113
|
-
name:
|
|
3660
|
+
name: colors.magenta('Homepage')
|
|
4114
3661
|
}, {
|
|
4115
3662
|
field: 'archived',
|
|
4116
|
-
name:
|
|
3663
|
+
name: colors.magenta('Archived')
|
|
4117
3664
|
}, {
|
|
4118
3665
|
field: 'created_at',
|
|
4119
|
-
name:
|
|
3666
|
+
name: colors.magenta('Created at')
|
|
4120
3667
|
}]
|
|
4121
3668
|
};
|
|
4122
|
-
spinner.stop(
|
|
3669
|
+
spinner.stop(chalkTable(options, [result.data]));
|
|
4123
3670
|
}
|
|
4124
3671
|
|
|
4125
|
-
Object.defineProperty(repos, "__esModule", {
|
|
4126
|
-
value: true
|
|
4127
|
-
});
|
|
4128
|
-
repos.repo = void 0;
|
|
4129
|
-
var _create = create$1;
|
|
4130
|
-
var _delete = _delete$1;
|
|
4131
|
-
var _list = list$1;
|
|
4132
|
-
var _update = update$1;
|
|
4133
|
-
var _view = view$1;
|
|
4134
|
-
var _meowWithSubcommands$2 = meowWithSubcommands$1;
|
|
4135
3672
|
const description$1 = 'Repositories related commands';
|
|
4136
|
-
|
|
3673
|
+
const repo = {
|
|
4137
3674
|
description: description$1,
|
|
4138
3675
|
run: async (argv, importMeta, {
|
|
4139
3676
|
parentName
|
|
4140
3677
|
}) => {
|
|
4141
|
-
await
|
|
4142
|
-
create
|
|
4143
|
-
view
|
|
4144
|
-
list
|
|
4145
|
-
del
|
|
4146
|
-
update
|
|
3678
|
+
await meowWithSubcommands({
|
|
3679
|
+
create,
|
|
3680
|
+
view,
|
|
3681
|
+
list,
|
|
3682
|
+
del,
|
|
3683
|
+
update
|
|
4147
3684
|
}, {
|
|
4148
3685
|
argv,
|
|
4149
3686
|
description: description$1,
|
|
@@ -4153,25 +3690,7 @@ repos.repo = {
|
|
|
4153
3690
|
}
|
|
4154
3691
|
};
|
|
4155
3692
|
|
|
4156
|
-
|
|
4157
|
-
|
|
4158
|
-
var _interopRequireDefault$4 = vendor.interopRequireDefault.default;
|
|
4159
|
-
Object.defineProperty(dependencies$1, "__esModule", {
|
|
4160
|
-
value: true
|
|
4161
|
-
});
|
|
4162
|
-
dependencies$1.dependencies = void 0;
|
|
4163
|
-
var _yoctocolorsCjs$3 = require$$1$2;
|
|
4164
|
-
var _chalkTable = require$$2$5;
|
|
4165
|
-
var _meow$3 = _interopRequireDefault$4(require$$2);
|
|
4166
|
-
var _yoctoSpinner$3 = require$$3;
|
|
4167
|
-
var _flags$3 = flags$1;
|
|
4168
|
-
var _apiHelpers$3 = apiHelpers;
|
|
4169
|
-
var _errors$4 = sdk.errors;
|
|
4170
|
-
var _formatting$3 = formatting;
|
|
4171
|
-
var _sdk$3 = sdk.sdk;
|
|
4172
|
-
// @ts-ignore
|
|
4173
|
-
|
|
4174
|
-
const dependencies = dependencies$1.dependencies = {
|
|
3693
|
+
const dependencies = {
|
|
4175
3694
|
description: 'Search for any dependency that is being used in your organization',
|
|
4176
3695
|
async run(argv, importMeta, {
|
|
4177
3696
|
parentName
|
|
@@ -4202,16 +3721,16 @@ const dependenciesFlags = {
|
|
|
4202
3721
|
|
|
4203
3722
|
function setupCommand$3(name, description, argv, importMeta) {
|
|
4204
3723
|
const flags = {
|
|
4205
|
-
...
|
|
3724
|
+
...commonFlags,
|
|
4206
3725
|
...dependenciesFlags,
|
|
4207
|
-
...
|
|
3726
|
+
...outputFlags
|
|
4208
3727
|
};
|
|
4209
|
-
const cli = (
|
|
3728
|
+
const cli = meow(`
|
|
4210
3729
|
Usage
|
|
4211
3730
|
$ ${name}
|
|
4212
3731
|
|
|
4213
3732
|
Options
|
|
4214
|
-
${
|
|
3733
|
+
${printFlagList(flags, 6)}
|
|
4215
3734
|
|
|
4216
3735
|
Examples
|
|
4217
3736
|
$ ${name}
|
|
@@ -4239,20 +3758,20 @@ async function searchDeps({
|
|
|
4239
3758
|
offset,
|
|
4240
3759
|
outputJson
|
|
4241
3760
|
}) {
|
|
4242
|
-
const apiKey =
|
|
3761
|
+
const apiKey = sdk.getDefaultKey();
|
|
4243
3762
|
if (!apiKey) {
|
|
4244
|
-
throw new
|
|
3763
|
+
throw new sdk.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
4245
3764
|
}
|
|
4246
|
-
const spinner =
|
|
3765
|
+
const spinner = yoctoSpinner({
|
|
4247
3766
|
text: 'Searching dependencies...'
|
|
4248
3767
|
}).start();
|
|
4249
|
-
const socketSdk = await
|
|
4250
|
-
const result = await
|
|
3768
|
+
const socketSdk = await sdk.setupSdk(apiKey);
|
|
3769
|
+
const result = await handleApiCall(socketSdk.searchDependencies({
|
|
4251
3770
|
limit,
|
|
4252
3771
|
offset
|
|
4253
3772
|
}), 'Searching dependencies');
|
|
4254
3773
|
if (!result.success) {
|
|
4255
|
-
|
|
3774
|
+
handleUnsuccessfulApiResponse('searchDependencies', result, spinner);
|
|
4256
3775
|
return;
|
|
4257
3776
|
}
|
|
4258
3777
|
spinner.stop('Organization dependencies:');
|
|
@@ -4263,59 +3782,31 @@ async function searchDeps({
|
|
|
4263
3782
|
const options = {
|
|
4264
3783
|
columns: [{
|
|
4265
3784
|
field: 'namespace',
|
|
4266
|
-
name:
|
|
3785
|
+
name: colors.cyan('Namespace')
|
|
4267
3786
|
}, {
|
|
4268
3787
|
field: 'name',
|
|
4269
|
-
name:
|
|
3788
|
+
name: colors.cyan('Name')
|
|
4270
3789
|
}, {
|
|
4271
3790
|
field: 'version',
|
|
4272
|
-
name:
|
|
3791
|
+
name: colors.cyan('Version')
|
|
4273
3792
|
}, {
|
|
4274
3793
|
field: 'repository',
|
|
4275
|
-
name:
|
|
3794
|
+
name: colors.cyan('Repository')
|
|
4276
3795
|
}, {
|
|
4277
3796
|
field: 'branch',
|
|
4278
|
-
name:
|
|
3797
|
+
name: colors.cyan('Branch')
|
|
4279
3798
|
}, {
|
|
4280
3799
|
field: 'type',
|
|
4281
|
-
name:
|
|
3800
|
+
name: colors.cyan('Type')
|
|
4282
3801
|
}, {
|
|
4283
3802
|
field: 'direct',
|
|
4284
|
-
name:
|
|
3803
|
+
name: colors.cyan('Direct')
|
|
4285
3804
|
}]
|
|
4286
3805
|
};
|
|
4287
|
-
console.log(
|
|
3806
|
+
console.log(chalkTable(options, result.data.rows));
|
|
4288
3807
|
}
|
|
4289
3808
|
|
|
4290
|
-
|
|
4291
|
-
|
|
4292
|
-
var _interopRequireDefault$3 = vendor.interopRequireDefault.default;
|
|
4293
|
-
Object.defineProperty(analytics$1, "__esModule", {
|
|
4294
|
-
value: true
|
|
4295
|
-
});
|
|
4296
|
-
analytics$1.analytics = void 0;
|
|
4297
|
-
var _promises = require$$1$5;
|
|
4298
|
-
var _screen$1 = require$$2$6;
|
|
4299
|
-
var _bar = require$$3$6;
|
|
4300
|
-
var _grid = require$$4$5;
|
|
4301
|
-
var _line = require$$5$4;
|
|
4302
|
-
var _meow$2 = _interopRequireDefault$3(require$$2);
|
|
4303
|
-
var _yoctocolorsCjs$2 = require$$1$2;
|
|
4304
|
-
var _yoctoSpinner$2 = require$$3;
|
|
4305
|
-
var _flags$2 = flags$1;
|
|
4306
|
-
var _apiHelpers$2 = apiHelpers;
|
|
4307
|
-
var _errors$3 = sdk.errors;
|
|
4308
|
-
var _formatting$2 = formatting;
|
|
4309
|
-
var _sdk$2 = sdk.sdk;
|
|
4310
|
-
// @ts-ignore
|
|
4311
|
-
|
|
4312
|
-
// @ts-ignore
|
|
4313
|
-
|
|
4314
|
-
// @ts-ignore
|
|
4315
|
-
|
|
4316
|
-
// @ts-ignore
|
|
4317
|
-
|
|
4318
|
-
const analytics = analytics$1.analytics = {
|
|
3809
|
+
const analytics = {
|
|
4319
3810
|
description: `Look up analytics data \n
|
|
4320
3811
|
Default parameters are set to show the organization-level analytics over the last 7 days.`,
|
|
4321
3812
|
async run(argv, importMeta, {
|
|
@@ -4324,11 +3815,11 @@ const analytics = analytics$1.analytics = {
|
|
|
4324
3815
|
const name = parentName + ' analytics';
|
|
4325
3816
|
const input = setupCommand$2(name, analytics.description, argv, importMeta);
|
|
4326
3817
|
if (input) {
|
|
4327
|
-
const apiKey =
|
|
3818
|
+
const apiKey = sdk.getDefaultKey();
|
|
4328
3819
|
if (!apiKey) {
|
|
4329
|
-
throw new
|
|
3820
|
+
throw new sdk.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
4330
3821
|
}
|
|
4331
|
-
const spinner =
|
|
3822
|
+
const spinner = yoctoSpinner({
|
|
4332
3823
|
text: 'Fetching analytics data'
|
|
4333
3824
|
}).start();
|
|
4334
3825
|
if (input.scope === 'org') {
|
|
@@ -4372,16 +3863,16 @@ const analyticsFlags = {
|
|
|
4372
3863
|
|
|
4373
3864
|
function setupCommand$2(name, description, argv, importMeta) {
|
|
4374
3865
|
const flags = {
|
|
4375
|
-
...
|
|
4376
|
-
...
|
|
3866
|
+
...commonFlags,
|
|
3867
|
+
...outputFlags,
|
|
4377
3868
|
...analyticsFlags
|
|
4378
3869
|
};
|
|
4379
|
-
const cli = (
|
|
3870
|
+
const cli = meow(`
|
|
4380
3871
|
Usage
|
|
4381
3872
|
$ ${name} --scope=<scope> --time=<time filter>
|
|
4382
3873
|
|
|
4383
3874
|
Options
|
|
4384
|
-
${
|
|
3875
|
+
${printFlagList(flags, 6)}
|
|
4385
3876
|
|
|
4386
3877
|
Examples
|
|
4387
3878
|
$ ${name} --scope=org --time=7
|
|
@@ -4399,15 +3890,15 @@ function setupCommand$2(name, description, argv, importMeta) {
|
|
|
4399
3890
|
time
|
|
4400
3891
|
} = cli.flags;
|
|
4401
3892
|
if (scope !== 'org' && scope !== 'repo') {
|
|
4402
|
-
throw new
|
|
3893
|
+
throw new sdk.InputError("The scope must either be 'org' or 'repo'");
|
|
4403
3894
|
}
|
|
4404
3895
|
if (time !== 7 && time !== 30 && time !== 90) {
|
|
4405
|
-
throw new
|
|
3896
|
+
throw new sdk.InputError('The time filter must either be 7, 30 or 90');
|
|
4406
3897
|
}
|
|
4407
3898
|
let showHelp = cli.flags['help'];
|
|
4408
3899
|
if (scope === 'repo' && !repo) {
|
|
4409
3900
|
showHelp = true;
|
|
4410
|
-
console.error(`${
|
|
3901
|
+
console.error(`${colors.bgRed(colors.white('Input error'))}: Please provide a repository name when using the repository scope.`);
|
|
4411
3902
|
}
|
|
4412
3903
|
if (showHelp) {
|
|
4413
3904
|
cli.showHelp();
|
|
@@ -4423,10 +3914,10 @@ function setupCommand$2(name, description, argv, importMeta) {
|
|
|
4423
3914
|
}
|
|
4424
3915
|
const METRICS = ['total_critical_alerts', 'total_high_alerts', 'total_medium_alerts', 'total_low_alerts', 'total_critical_added', 'total_medium_added', 'total_low_added', 'total_high_added', 'total_critical_prevented', 'total_high_prevented', 'total_medium_prevented', 'total_low_prevented'];
|
|
4425
3916
|
async function fetchOrgAnalyticsData(time, spinner, apiKey, outputJson, filePath) {
|
|
4426
|
-
const socketSdk = await
|
|
4427
|
-
const result = await
|
|
3917
|
+
const socketSdk = await sdk.setupSdk(apiKey);
|
|
3918
|
+
const result = await handleApiCall(socketSdk.getOrgAnalytics(time.toString()), 'fetching analytics data');
|
|
4428
3919
|
if (result.success === false) {
|
|
4429
|
-
return
|
|
3920
|
+
return handleUnsuccessfulApiResponse('getOrgAnalytics', result, spinner);
|
|
4430
3921
|
}
|
|
4431
3922
|
spinner.stop();
|
|
4432
3923
|
if (!result.data.length) {
|
|
@@ -4438,7 +3929,7 @@ async function fetchOrgAnalyticsData(time, spinner, apiKey, outputJson, filePath
|
|
|
4438
3929
|
}
|
|
4439
3930
|
if (filePath) {
|
|
4440
3931
|
try {
|
|
4441
|
-
await
|
|
3932
|
+
await fs$1.writeFile(filePath, JSON.stringify(result.data), 'utf8');
|
|
4442
3933
|
console.log(`Data successfully written to ${filePath}`);
|
|
4443
3934
|
} catch (e) {
|
|
4444
3935
|
console.error(e);
|
|
@@ -4536,10 +4027,10 @@ const formatData = (data, scope) => {
|
|
|
4536
4027
|
};
|
|
4537
4028
|
};
|
|
4538
4029
|
async function fetchRepoAnalyticsData(repo, time, spinner, apiKey, outputJson, filePath) {
|
|
4539
|
-
const socketSdk = await
|
|
4540
|
-
const result = await
|
|
4030
|
+
const socketSdk = await sdk.setupSdk(apiKey);
|
|
4031
|
+
const result = await handleApiCall(socketSdk.getRepoAnalytics(repo, time.toString()), 'fetching analytics data');
|
|
4541
4032
|
if (result.success === false) {
|
|
4542
|
-
return
|
|
4033
|
+
return handleUnsuccessfulApiResponse('getRepoAnalytics', result, spinner);
|
|
4543
4034
|
}
|
|
4544
4035
|
spinner.stop();
|
|
4545
4036
|
if (!result.data.length) {
|
|
@@ -4551,7 +4042,7 @@ async function fetchRepoAnalyticsData(repo, time, spinner, apiKey, outputJson, f
|
|
|
4551
4042
|
}
|
|
4552
4043
|
if (filePath) {
|
|
4553
4044
|
try {
|
|
4554
|
-
await
|
|
4045
|
+
await fs$1.writeFile(filePath, JSON.stringify(result.data), 'utf8');
|
|
4555
4046
|
console.log(`Data successfully written to ${filePath}`);
|
|
4556
4047
|
} catch (e) {
|
|
4557
4048
|
console.error(e);
|
|
@@ -4561,8 +4052,8 @@ async function fetchRepoAnalyticsData(repo, time, spinner, apiKey, outputJson, f
|
|
|
4561
4052
|
return displayAnalyticsScreen(data);
|
|
4562
4053
|
}
|
|
4563
4054
|
const displayAnalyticsScreen = data => {
|
|
4564
|
-
const screen = new
|
|
4565
|
-
const grid = new
|
|
4055
|
+
const screen = new ScreenWidget();
|
|
4056
|
+
const grid = new GridLayout({
|
|
4566
4057
|
rows: 5,
|
|
4567
4058
|
cols: 4,
|
|
4568
4059
|
screen
|
|
@@ -4575,7 +4066,7 @@ const displayAnalyticsScreen = data => {
|
|
|
4575
4066
|
renderLineCharts(grid, screen, 'Total high alerts prevented from the main branch', [2, 2, 1, 2], data['total_high_prevented']);
|
|
4576
4067
|
renderLineCharts(grid, screen, 'Total medium alerts prevented from the main branch', [3, 0, 1, 2], data['total_medium_prevented']);
|
|
4577
4068
|
renderLineCharts(grid, screen, 'Total low alerts prevented from the main branch', [3, 2, 1, 2], data['total_low_prevented']);
|
|
4578
|
-
const bar = grid.set(4, 0, 1, 2,
|
|
4069
|
+
const bar = grid.set(4, 0, 1, 2, BarChart, {
|
|
4579
4070
|
label: 'Top 5 alert types',
|
|
4580
4071
|
barWidth: 10,
|
|
4581
4072
|
barSpacing: 17,
|
|
@@ -4593,7 +4084,7 @@ const displayAnalyticsScreen = data => {
|
|
|
4593
4084
|
screen.key(['escape', 'q', 'C-c'], () => process.exit(0));
|
|
4594
4085
|
};
|
|
4595
4086
|
const renderLineCharts = (grid, screen, title, coords, data) => {
|
|
4596
|
-
const line = grid.set(...coords,
|
|
4087
|
+
const line = grid.set(...coords, LineChart, {
|
|
4597
4088
|
style: {
|
|
4598
4089
|
line: 'cyan',
|
|
4599
4090
|
text: 'cyan',
|
|
@@ -4616,26 +4107,7 @@ const renderLineCharts = (grid, screen, title, coords, data) => {
|
|
|
4616
4107
|
line.setData([lineData]);
|
|
4617
4108
|
};
|
|
4618
4109
|
|
|
4619
|
-
|
|
4620
|
-
|
|
4621
|
-
var get$1 = {};
|
|
4622
|
-
|
|
4623
|
-
var _interopRequireDefault$2 = vendor.interopRequireDefault.default;
|
|
4624
|
-
Object.defineProperty(get$1, "__esModule", {
|
|
4625
|
-
value: true
|
|
4626
|
-
});
|
|
4627
|
-
get$1.get = void 0;
|
|
4628
|
-
var _nodeFs = require$$0;
|
|
4629
|
-
var _nodeUtil = require$$2$7;
|
|
4630
|
-
var _yoctocolorsCjs$1 = require$$1$2;
|
|
4631
|
-
var _meow$1 = _interopRequireDefault$2(require$$2);
|
|
4632
|
-
var _yoctoSpinner$1 = require$$3;
|
|
4633
|
-
var _flags$1 = flags$1;
|
|
4634
|
-
var _apiHelpers$1 = apiHelpers;
|
|
4635
|
-
var _errors$2 = sdk.errors;
|
|
4636
|
-
var _formatting$1 = formatting;
|
|
4637
|
-
var _sdk$1 = sdk.sdk;
|
|
4638
|
-
const get = get$1.get = {
|
|
4110
|
+
const get = {
|
|
4639
4111
|
description: 'Get a diff scan for an organization',
|
|
4640
4112
|
async run(argv, importMeta, {
|
|
4641
4113
|
parentName
|
|
@@ -4643,12 +4115,12 @@ const get = get$1.get = {
|
|
|
4643
4115
|
const name = `${parentName} get`;
|
|
4644
4116
|
const input = setupCommand$1(name, get.description, argv, importMeta);
|
|
4645
4117
|
if (input) {
|
|
4646
|
-
const apiKey =
|
|
4118
|
+
const apiKey = sdk.getDefaultKey();
|
|
4647
4119
|
if (!apiKey) {
|
|
4648
|
-
throw new
|
|
4120
|
+
throw new sdk.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
4649
4121
|
}
|
|
4650
4122
|
const spinnerText = 'Getting diff scan... \n';
|
|
4651
|
-
const spinner =
|
|
4123
|
+
const spinner = yoctoSpinner({
|
|
4652
4124
|
text: spinnerText
|
|
4653
4125
|
}).start();
|
|
4654
4126
|
await getDiffScan(input, spinner, apiKey);
|
|
@@ -4686,16 +4158,16 @@ const getDiffScanFlags = {
|
|
|
4686
4158
|
|
|
4687
4159
|
function setupCommand$1(name, description, argv, importMeta) {
|
|
4688
4160
|
const flags = {
|
|
4689
|
-
...
|
|
4161
|
+
...commonFlags,
|
|
4690
4162
|
...getDiffScanFlags,
|
|
4691
|
-
...
|
|
4163
|
+
...outputFlags
|
|
4692
4164
|
};
|
|
4693
|
-
const cli = (
|
|
4165
|
+
const cli = meow(`
|
|
4694
4166
|
Usage
|
|
4695
4167
|
$ ${name} <org slug> --before=<before> --after=<after>
|
|
4696
4168
|
|
|
4697
4169
|
Options
|
|
4698
|
-
${
|
|
4170
|
+
${printFlagList(flags, 6)}
|
|
4699
4171
|
|
|
4700
4172
|
Examples
|
|
4701
4173
|
$ ${name} FakeCorp --before=aaa0aa0a-aaaa-0000-0a0a-0000000a00a0 --after=aaa1aa1a-aaaa-1111-1a1a-1111111a11a1
|
|
@@ -4712,10 +4184,10 @@ function setupCommand$1(name, description, argv, importMeta) {
|
|
|
4712
4184
|
let showHelp = cli.flags['help'];
|
|
4713
4185
|
if (!before || !after) {
|
|
4714
4186
|
showHelp = true;
|
|
4715
|
-
console.error(`${
|
|
4187
|
+
console.error(`${colors.bgRed(colors.white('Input error'))}: Please specify a before and after full scan ID. To get full scans IDs, you can run the command "socket scan list <your org slug>".`);
|
|
4716
4188
|
} else if (cli.input.length < 1) {
|
|
4717
4189
|
showHelp = true;
|
|
4718
|
-
console.error(`${
|
|
4190
|
+
console.error(`${colors.bgRed(colors.white('Input error'))}: Please provide an organization slug.`);
|
|
4719
4191
|
}
|
|
4720
4192
|
if (showHelp) {
|
|
4721
4193
|
cli.showHelp();
|
|
@@ -4739,50 +4211,44 @@ async function getDiffScan({
|
|
|
4739
4211
|
orgSlug,
|
|
4740
4212
|
outputJson
|
|
4741
4213
|
}, spinner, apiKey) {
|
|
4742
|
-
const response = await
|
|
4214
|
+
const response = await queryAPI(`${orgSlug}/full-scans/diff?before=${before}&after=${after}&preview`, apiKey);
|
|
4743
4215
|
const data = await response.json();
|
|
4744
4216
|
if (!response.ok) {
|
|
4745
|
-
const err = await
|
|
4746
|
-
spinner.error(`${
|
|
4217
|
+
const err = await handleAPIError(response.status);
|
|
4218
|
+
spinner.error(`${colors.bgRed(colors.white(response.statusText))}: ${err}`);
|
|
4747
4219
|
return;
|
|
4748
4220
|
}
|
|
4749
4221
|
spinner.stop();
|
|
4750
4222
|
if (file && !outputJson) {
|
|
4751
|
-
|
|
4223
|
+
fs.writeFile(file, JSON.stringify(data), err => {
|
|
4752
4224
|
err ? console.error(err) : console.log(`Data successfully written to ${file}`);
|
|
4753
4225
|
});
|
|
4754
4226
|
return;
|
|
4755
4227
|
}
|
|
4756
4228
|
if (outputJson) {
|
|
4757
4229
|
console.log(`\n Diff scan result: \n`);
|
|
4758
|
-
console.log(
|
|
4230
|
+
console.log(util.inspect(data, {
|
|
4759
4231
|
showHidden: false,
|
|
4760
4232
|
depth: null,
|
|
4761
4233
|
colors: true
|
|
4762
4234
|
}));
|
|
4763
|
-
console.log(`\n View this diff scan in the Socket dashboard: ${
|
|
4235
|
+
console.log(`\n View this diff scan in the Socket dashboard: ${colors.cyan(data?.['diff_report_url'])}`);
|
|
4764
4236
|
return;
|
|
4765
4237
|
}
|
|
4766
4238
|
console.log('Diff scan result:');
|
|
4767
4239
|
console.log(data);
|
|
4768
4240
|
console.log(`\n 📝 To display the detailed report in the terminal, use the --json flag \n`);
|
|
4769
|
-
console.log(`\n View this diff scan in the Socket dashboard: ${
|
|
4241
|
+
console.log(`\n View this diff scan in the Socket dashboard: ${colors.cyan(data?.['diff_report_url'])}`);
|
|
4770
4242
|
}
|
|
4771
4243
|
|
|
4772
|
-
Object.defineProperty(diffScan, "__esModule", {
|
|
4773
|
-
value: true
|
|
4774
|
-
});
|
|
4775
|
-
diffScan.diffScan = void 0;
|
|
4776
|
-
var _get = get$1;
|
|
4777
|
-
var _meowWithSubcommands$1 = meowWithSubcommands$1;
|
|
4778
4244
|
const description = 'Diff scans related commands';
|
|
4779
|
-
diffScan
|
|
4245
|
+
const diffScan = {
|
|
4780
4246
|
description,
|
|
4781
4247
|
run: async (argv, importMeta, {
|
|
4782
4248
|
parentName
|
|
4783
4249
|
}) => {
|
|
4784
|
-
await
|
|
4785
|
-
get
|
|
4250
|
+
await meowWithSubcommands({
|
|
4251
|
+
get
|
|
4786
4252
|
}, {
|
|
4787
4253
|
argv,
|
|
4788
4254
|
description,
|
|
@@ -4792,27 +4258,8 @@ diffScan.diffScan = {
|
|
|
4792
4258
|
}
|
|
4793
4259
|
};
|
|
4794
4260
|
|
|
4795
|
-
var threatFeed$1 = {};
|
|
4796
|
-
|
|
4797
|
-
var _interopRequireDefault$1 = vendor.interopRequireDefault.default;
|
|
4798
|
-
Object.defineProperty(threatFeed$1, "__esModule", {
|
|
4799
|
-
value: true
|
|
4800
|
-
});
|
|
4801
|
-
threatFeed$1.threatFeed = void 0;
|
|
4802
|
-
var _screen = require$$2$6;
|
|
4803
|
-
var _table = require$$2$8;
|
|
4804
|
-
var _meow = _interopRequireDefault$1(require$$2);
|
|
4805
|
-
var _yoctoSpinner = require$$3;
|
|
4806
|
-
var _flags = flags$1;
|
|
4807
|
-
var _apiHelpers = apiHelpers;
|
|
4808
|
-
var _errors$1 = sdk.errors;
|
|
4809
|
-
var _formatting = formatting;
|
|
4810
|
-
var _sdk = sdk.sdk;
|
|
4811
|
-
// @ts-ignore
|
|
4812
|
-
|
|
4813
4261
|
// @ts-ignore
|
|
4814
|
-
|
|
4815
|
-
const threatFeed = threatFeed$1.threatFeed = {
|
|
4262
|
+
const threatFeed = {
|
|
4816
4263
|
description: 'Look up the threat feed',
|
|
4817
4264
|
async run(argv, importMeta, {
|
|
4818
4265
|
parentName
|
|
@@ -4820,11 +4267,11 @@ const threatFeed = threatFeed$1.threatFeed = {
|
|
|
4820
4267
|
const name = `${parentName} threat-feed`;
|
|
4821
4268
|
const input = setupCommand(name, threatFeed.description, argv, importMeta);
|
|
4822
4269
|
if (input) {
|
|
4823
|
-
const apiKey =
|
|
4270
|
+
const apiKey = sdk.getDefaultKey();
|
|
4824
4271
|
if (!apiKey) {
|
|
4825
|
-
throw new
|
|
4272
|
+
throw new sdk.AuthError('User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.');
|
|
4826
4273
|
}
|
|
4827
|
-
const spinner =
|
|
4274
|
+
const spinner = yoctoSpinner({
|
|
4828
4275
|
text: 'Looking up the threat feed'
|
|
4829
4276
|
}).start();
|
|
4830
4277
|
await fetchThreatFeed(input, spinner, apiKey);
|
|
@@ -4862,16 +4309,16 @@ const threatFeedFlags = {
|
|
|
4862
4309
|
|
|
4863
4310
|
function setupCommand(name, description, argv, importMeta) {
|
|
4864
4311
|
const flags = {
|
|
4865
|
-
...
|
|
4866
|
-
...
|
|
4312
|
+
...commonFlags,
|
|
4313
|
+
...outputFlags,
|
|
4867
4314
|
...threatFeedFlags
|
|
4868
4315
|
};
|
|
4869
|
-
const cli = (
|
|
4316
|
+
const cli = meow(`
|
|
4870
4317
|
Usage
|
|
4871
4318
|
$ ${name}
|
|
4872
4319
|
|
|
4873
4320
|
Options
|
|
4874
|
-
${
|
|
4321
|
+
${printFlagList(flags, 6)}
|
|
4875
4322
|
|
|
4876
4323
|
Examples
|
|
4877
4324
|
$ ${name}
|
|
@@ -4912,15 +4359,15 @@ async function fetchThreatFeed({
|
|
|
4912
4359
|
direction,
|
|
4913
4360
|
filter
|
|
4914
4361
|
}).join('&');
|
|
4915
|
-
const response = await
|
|
4362
|
+
const response = await queryAPI(`threat-feed?${formattedQueryParams}`, apiKey);
|
|
4916
4363
|
const data = await response.json();
|
|
4917
4364
|
spinner.stop();
|
|
4918
4365
|
if (outputJson) {
|
|
4919
4366
|
console.log(data);
|
|
4920
4367
|
return;
|
|
4921
4368
|
}
|
|
4922
|
-
const screen = new
|
|
4923
|
-
const table = new
|
|
4369
|
+
const screen = new ScreenWidget();
|
|
4370
|
+
const table = new TableWidget({
|
|
4924
4371
|
keys: 'true',
|
|
4925
4372
|
fg: 'white',
|
|
4926
4373
|
selectedFg: 'white',
|
|
@@ -4965,233 +4412,32 @@ const formatQueryParams = params => Object.entries(params).map(entry => `${entry
|
|
|
4965
4412
|
const getHourDiff = (start, end) => Math.floor((end - start) / 3600000);
|
|
4966
4413
|
const getMinDiff = (start, end) => Math.floor((end - start) / 60000);
|
|
4967
4414
|
|
|
4968
|
-
|
|
4969
|
-
|
|
4970
|
-
|
|
4971
|
-
|
|
4972
|
-
|
|
4973
|
-
|
|
4974
|
-
|
|
4975
|
-
|
|
4976
|
-
|
|
4977
|
-
|
|
4978
|
-
|
|
4979
|
-
|
|
4980
|
-
|
|
4981
|
-
|
|
4982
|
-
|
|
4983
|
-
|
|
4984
|
-
|
|
4985
|
-
|
|
4986
|
-
|
|
4987
|
-
|
|
4988
|
-
|
|
4989
|
-
|
|
4990
|
-
|
|
4991
|
-
|
|
4992
|
-
|
|
4993
|
-
|
|
4994
|
-
});
|
|
4995
|
-
var _login = login;
|
|
4996
|
-
Object.keys(_login).forEach(function (key) {
|
|
4997
|
-
if (key === "default" || key === "__esModule") return;
|
|
4998
|
-
if (key in exports && exports[key] === _login[key]) return;
|
|
4999
|
-
Object.defineProperty(exports, key, {
|
|
5000
|
-
enumerable: true,
|
|
5001
|
-
get: function () {
|
|
5002
|
-
return _login[key];
|
|
5003
|
-
}
|
|
5004
|
-
});
|
|
5005
|
-
});
|
|
5006
|
-
var _logout = logout;
|
|
5007
|
-
Object.keys(_logout).forEach(function (key) {
|
|
5008
|
-
if (key === "default" || key === "__esModule") return;
|
|
5009
|
-
if (key in exports && exports[key] === _logout[key]) return;
|
|
5010
|
-
Object.defineProperty(exports, key, {
|
|
5011
|
-
enumerable: true,
|
|
5012
|
-
get: function () {
|
|
5013
|
-
return _logout[key];
|
|
5014
|
-
}
|
|
5015
|
-
});
|
|
5016
|
-
});
|
|
5017
|
-
var _npm = npm;
|
|
5018
|
-
Object.keys(_npm).forEach(function (key) {
|
|
5019
|
-
if (key === "default" || key === "__esModule") return;
|
|
5020
|
-
if (key in exports && exports[key] === _npm[key]) return;
|
|
5021
|
-
Object.defineProperty(exports, key, {
|
|
5022
|
-
enumerable: true,
|
|
5023
|
-
get: function () {
|
|
5024
|
-
return _npm[key];
|
|
5025
|
-
}
|
|
5026
|
-
});
|
|
5027
|
-
});
|
|
5028
|
-
var _npx = npx;
|
|
5029
|
-
Object.keys(_npx).forEach(function (key) {
|
|
5030
|
-
if (key === "default" || key === "__esModule") return;
|
|
5031
|
-
if (key in exports && exports[key] === _npx[key]) return;
|
|
5032
|
-
Object.defineProperty(exports, key, {
|
|
5033
|
-
enumerable: true,
|
|
5034
|
-
get: function () {
|
|
5035
|
-
return _npx[key];
|
|
5036
|
-
}
|
|
5037
|
-
});
|
|
5038
|
-
});
|
|
5039
|
-
var _optimize = optimize$1;
|
|
5040
|
-
Object.keys(_optimize).forEach(function (key) {
|
|
5041
|
-
if (key === "default" || key === "__esModule") return;
|
|
5042
|
-
if (key in exports && exports[key] === _optimize[key]) return;
|
|
5043
|
-
Object.defineProperty(exports, key, {
|
|
5044
|
-
enumerable: true,
|
|
5045
|
-
get: function () {
|
|
5046
|
-
return _optimize[key];
|
|
5047
|
-
}
|
|
5048
|
-
});
|
|
5049
|
-
});
|
|
5050
|
-
var _organization = organization;
|
|
5051
|
-
Object.keys(_organization).forEach(function (key) {
|
|
5052
|
-
if (key === "default" || key === "__esModule") return;
|
|
5053
|
-
if (key in exports && exports[key] === _organization[key]) return;
|
|
5054
|
-
Object.defineProperty(exports, key, {
|
|
5055
|
-
enumerable: true,
|
|
5056
|
-
get: function () {
|
|
5057
|
-
return _organization[key];
|
|
5058
|
-
}
|
|
5059
|
-
});
|
|
5060
|
-
});
|
|
5061
|
-
var _rawNpm = rawNpm$1;
|
|
5062
|
-
Object.keys(_rawNpm).forEach(function (key) {
|
|
5063
|
-
if (key === "default" || key === "__esModule") return;
|
|
5064
|
-
if (key in exports && exports[key] === _rawNpm[key]) return;
|
|
5065
|
-
Object.defineProperty(exports, key, {
|
|
5066
|
-
enumerable: true,
|
|
5067
|
-
get: function () {
|
|
5068
|
-
return _rawNpm[key];
|
|
5069
|
-
}
|
|
5070
|
-
});
|
|
5071
|
-
});
|
|
5072
|
-
var _rawNpx = rawNpx$1;
|
|
5073
|
-
Object.keys(_rawNpx).forEach(function (key) {
|
|
5074
|
-
if (key === "default" || key === "__esModule") return;
|
|
5075
|
-
if (key in exports && exports[key] === _rawNpx[key]) return;
|
|
5076
|
-
Object.defineProperty(exports, key, {
|
|
5077
|
-
enumerable: true,
|
|
5078
|
-
get: function () {
|
|
5079
|
-
return _rawNpx[key];
|
|
5080
|
-
}
|
|
5081
|
-
});
|
|
5082
|
-
});
|
|
5083
|
-
var _report = report;
|
|
5084
|
-
Object.keys(_report).forEach(function (key) {
|
|
5085
|
-
if (key === "default" || key === "__esModule") return;
|
|
5086
|
-
if (key in exports && exports[key] === _report[key]) return;
|
|
5087
|
-
Object.defineProperty(exports, key, {
|
|
5088
|
-
enumerable: true,
|
|
5089
|
-
get: function () {
|
|
5090
|
-
return _report[key];
|
|
5091
|
-
}
|
|
5092
|
-
});
|
|
5093
|
-
});
|
|
5094
|
-
var _wrapper = wrapper$1;
|
|
5095
|
-
Object.keys(_wrapper).forEach(function (key) {
|
|
5096
|
-
if (key === "default" || key === "__esModule") return;
|
|
5097
|
-
if (key in exports && exports[key] === _wrapper[key]) return;
|
|
5098
|
-
Object.defineProperty(exports, key, {
|
|
5099
|
-
enumerable: true,
|
|
5100
|
-
get: function () {
|
|
5101
|
-
return _wrapper[key];
|
|
5102
|
-
}
|
|
5103
|
-
});
|
|
5104
|
-
});
|
|
5105
|
-
var _scan = scan;
|
|
5106
|
-
Object.keys(_scan).forEach(function (key) {
|
|
5107
|
-
if (key === "default" || key === "__esModule") return;
|
|
5108
|
-
if (key in exports && exports[key] === _scan[key]) return;
|
|
5109
|
-
Object.defineProperty(exports, key, {
|
|
5110
|
-
enumerable: true,
|
|
5111
|
-
get: function () {
|
|
5112
|
-
return _scan[key];
|
|
5113
|
-
}
|
|
5114
|
-
});
|
|
5115
|
-
});
|
|
5116
|
-
var _auditLog = auditLog$1;
|
|
5117
|
-
Object.keys(_auditLog).forEach(function (key) {
|
|
5118
|
-
if (key === "default" || key === "__esModule") return;
|
|
5119
|
-
if (key in exports && exports[key] === _auditLog[key]) return;
|
|
5120
|
-
Object.defineProperty(exports, key, {
|
|
5121
|
-
enumerable: true,
|
|
5122
|
-
get: function () {
|
|
5123
|
-
return _auditLog[key];
|
|
5124
|
-
}
|
|
5125
|
-
});
|
|
5126
|
-
});
|
|
5127
|
-
var _repos = repos;
|
|
5128
|
-
Object.keys(_repos).forEach(function (key) {
|
|
5129
|
-
if (key === "default" || key === "__esModule") return;
|
|
5130
|
-
if (key in exports && exports[key] === _repos[key]) return;
|
|
5131
|
-
Object.defineProperty(exports, key, {
|
|
5132
|
-
enumerable: true,
|
|
5133
|
-
get: function () {
|
|
5134
|
-
return _repos[key];
|
|
5135
|
-
}
|
|
5136
|
-
});
|
|
5137
|
-
});
|
|
5138
|
-
var _dependencies = dependencies$1;
|
|
5139
|
-
Object.keys(_dependencies).forEach(function (key) {
|
|
5140
|
-
if (key === "default" || key === "__esModule") return;
|
|
5141
|
-
if (key in exports && exports[key] === _dependencies[key]) return;
|
|
5142
|
-
Object.defineProperty(exports, key, {
|
|
5143
|
-
enumerable: true,
|
|
5144
|
-
get: function () {
|
|
5145
|
-
return _dependencies[key];
|
|
5146
|
-
}
|
|
5147
|
-
});
|
|
5148
|
-
});
|
|
5149
|
-
var _analytics = analytics$1;
|
|
5150
|
-
Object.keys(_analytics).forEach(function (key) {
|
|
5151
|
-
if (key === "default" || key === "__esModule") return;
|
|
5152
|
-
if (key in exports && exports[key] === _analytics[key]) return;
|
|
5153
|
-
Object.defineProperty(exports, key, {
|
|
5154
|
-
enumerable: true,
|
|
5155
|
-
get: function () {
|
|
5156
|
-
return _analytics[key];
|
|
5157
|
-
}
|
|
5158
|
-
});
|
|
5159
|
-
});
|
|
5160
|
-
var _diffScan = diffScan;
|
|
5161
|
-
Object.keys(_diffScan).forEach(function (key) {
|
|
5162
|
-
if (key === "default" || key === "__esModule") return;
|
|
5163
|
-
if (key in exports && exports[key] === _diffScan[key]) return;
|
|
5164
|
-
Object.defineProperty(exports, key, {
|
|
5165
|
-
enumerable: true,
|
|
5166
|
-
get: function () {
|
|
5167
|
-
return _diffScan[key];
|
|
5168
|
-
}
|
|
5169
|
-
});
|
|
5170
|
-
});
|
|
5171
|
-
var _threatFeed = threatFeed$1;
|
|
5172
|
-
Object.keys(_threatFeed).forEach(function (key) {
|
|
5173
|
-
if (key === "default" || key === "__esModule") return;
|
|
5174
|
-
if (key in exports && exports[key] === _threatFeed[key]) return;
|
|
5175
|
-
Object.defineProperty(exports, key, {
|
|
5176
|
-
enumerable: true,
|
|
5177
|
-
get: function () {
|
|
5178
|
-
return _threatFeed[key];
|
|
5179
|
-
}
|
|
5180
|
-
});
|
|
5181
|
-
});
|
|
5182
|
-
} (commands));
|
|
5183
|
-
|
|
5184
|
-
var _interopRequireWildcard = vendor.interopRequireWildcard.default;
|
|
5185
|
-
var _interopRequireDefault = vendor.interopRequireDefault.default;
|
|
5186
|
-
var _nodeUrl = require$$2$9;
|
|
5187
|
-
var _yoctocolorsCjs = require$$1$2;
|
|
5188
|
-
var _ponyCause = require$$4$1;
|
|
5189
|
-
var _tinyUpdater = _interopRequireDefault(require$$5$5);
|
|
5190
|
-
var cliCommands = _interopRequireWildcard(commands, true);
|
|
5191
|
-
var _constants = constants.constants;
|
|
5192
|
-
var _colorOrMarkdown = sdk.colorOrMarkdown;
|
|
5193
|
-
var _errors = sdk.errors;
|
|
5194
|
-
var _meowWithSubcommands = meowWithSubcommands$1;
|
|
4415
|
+
var cliCommands = {
|
|
4416
|
+
__proto__: null,
|
|
4417
|
+
analytics: analytics,
|
|
4418
|
+
auditLog: auditLog,
|
|
4419
|
+
cdxgen: cdxgen,
|
|
4420
|
+
dependencies: dependencies,
|
|
4421
|
+
diffScan: diffScan,
|
|
4422
|
+
info: info,
|
|
4423
|
+
login: login,
|
|
4424
|
+
logout: logout,
|
|
4425
|
+
npm: npm,
|
|
4426
|
+
npx: npx,
|
|
4427
|
+
optimize: optimize,
|
|
4428
|
+
organizations: organizations,
|
|
4429
|
+
rawNpm: rawNpm,
|
|
4430
|
+
rawNpx: rawNpx,
|
|
4431
|
+
repo: repo,
|
|
4432
|
+
report: report,
|
|
4433
|
+
scan: scan,
|
|
4434
|
+
threatFeed: threatFeed,
|
|
4435
|
+
wrapper: wrapper
|
|
4436
|
+
};
|
|
4437
|
+
|
|
4438
|
+
const {
|
|
4439
|
+
rootPkgJsonPath
|
|
4440
|
+
} = constants;
|
|
5195
4441
|
const formattedCliCommands = Object.fromEntries(Object.entries(cliCommands).map(entry => {
|
|
5196
4442
|
const key = entry[0];
|
|
5197
4443
|
entry[0] = camelToHyphen(key);
|
|
@@ -5203,14 +4449,13 @@ function camelToHyphen(str) {
|
|
|
5203
4449
|
|
|
5204
4450
|
// TODO: Add autocompletion using https://socket.dev/npm/package/omelette
|
|
5205
4451
|
void (async () => {
|
|
5206
|
-
|
|
5207
|
-
|
|
5208
|
-
|
|
5209
|
-
version: rootPkgJson.version,
|
|
4452
|
+
await updateNotifier({
|
|
4453
|
+
name: 'socket',
|
|
4454
|
+
version: require(rootPkgJsonPath).version,
|
|
5210
4455
|
ttl: 86_400_000 /* 24 hours in milliseconds */
|
|
5211
4456
|
});
|
|
5212
4457
|
try {
|
|
5213
|
-
await
|
|
4458
|
+
await meowWithSubcommands(formattedCliCommands, {
|
|
5214
4459
|
aliases: {
|
|
5215
4460
|
ci: {
|
|
5216
4461
|
description: 'Alias for "report create --view --strict"',
|
|
@@ -5220,62 +4465,31 @@ void (async () => {
|
|
|
5220
4465
|
argv: process.argv.slice(2),
|
|
5221
4466
|
name: 'socket',
|
|
5222
4467
|
importMeta: {
|
|
5223
|
-
url: `${
|
|
4468
|
+
url: `${node_url.pathToFileURL(__filename)}`
|
|
5224
4469
|
}
|
|
5225
4470
|
});
|
|
5226
4471
|
} catch (err) {
|
|
5227
4472
|
let errorBody;
|
|
5228
4473
|
let errorTitle;
|
|
5229
4474
|
let errorMessage = '';
|
|
5230
|
-
if (err instanceof
|
|
4475
|
+
if (err instanceof sdk.AuthError) {
|
|
5231
4476
|
errorTitle = 'Authentication error';
|
|
5232
4477
|
errorMessage = err.message;
|
|
5233
|
-
} else if (err instanceof
|
|
4478
|
+
} else if (err instanceof sdk.InputError) {
|
|
5234
4479
|
errorTitle = 'Invalid input';
|
|
5235
4480
|
errorMessage = err.message;
|
|
5236
4481
|
errorBody = err.body;
|
|
5237
4482
|
} else if (err instanceof Error) {
|
|
5238
4483
|
errorTitle = 'Unexpected error';
|
|
5239
|
-
errorMessage =
|
|
5240
|
-
errorBody =
|
|
4484
|
+
errorMessage = ponyCause.messageWithCauses(err);
|
|
4485
|
+
errorBody = ponyCause.stackWithCauses(err);
|
|
5241
4486
|
} else {
|
|
5242
4487
|
errorTitle = 'Unexpected error with no details';
|
|
5243
4488
|
}
|
|
5244
|
-
console.error(`${
|
|
4489
|
+
console.error(`${sdk.logSymbols.error} ${colors.bgRed(colors.white(errorTitle + ':'))} ${errorMessage}`);
|
|
5245
4490
|
if (errorBody) {
|
|
5246
4491
|
console.error(`\n${errorBody}`);
|
|
5247
4492
|
}
|
|
5248
4493
|
process.exit(1);
|
|
5249
4494
|
}
|
|
5250
4495
|
})();
|
|
5251
|
-
|
|
5252
|
-
(function (exports) {
|
|
5253
|
-
|
|
5254
|
-
var _interopRequireWildcard = vendor.interopRequireWildcard.default;
|
|
5255
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5256
|
-
value: true
|
|
5257
|
-
});
|
|
5258
|
-
var _exportNames = {};
|
|
5259
|
-
Object.defineProperty(exports, "default", {
|
|
5260
|
-
enumerable: true,
|
|
5261
|
-
get: function () {
|
|
5262
|
-
return _cli.default;
|
|
5263
|
-
}
|
|
5264
|
-
});
|
|
5265
|
-
var _cli = _interopRequireWildcard(cli$1, true);
|
|
5266
|
-
Object.keys(_cli).forEach(function (key) {
|
|
5267
|
-
if (key === "default" || key === "__esModule") return;
|
|
5268
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
5269
|
-
if (key in exports && exports[key] === _cli[key]) return;
|
|
5270
|
-
Object.defineProperty(exports, key, {
|
|
5271
|
-
enumerable: true,
|
|
5272
|
-
get: function () {
|
|
5273
|
-
return _cli[key];
|
|
5274
|
-
}
|
|
5275
|
-
});
|
|
5276
|
-
});
|
|
5277
|
-
} (cli$2));
|
|
5278
|
-
|
|
5279
|
-
var cli = /*@__PURE__*/vendor.getDefaultExportFromCjs(cli$2);
|
|
5280
|
-
|
|
5281
|
-
module.exports = cli;
|