@socketsecurity/cli 0.14.34 → 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 +33 -1
- package/bin/npm-cli.js +2 -1
- package/bin/npx-cli.js +2 -1
- package/dist/constants.js +21 -30
- package/dist/module-sync/cli.js +607 -1413
- package/dist/module-sync/constants.d.ts +9 -79
- package/dist/module-sync/constants.d.ts.map +1 -0
- package/dist/module-sync/npm-injection.js +77 -396
- package/dist/module-sync/path-resolve.js +19 -37
- package/dist/module-sync/sdk.js +60 -110
- package/dist/module-sync/shadow-bin.d.ts +2 -0
- package/dist/module-sync/shadow-bin.js +109 -0
- package/dist/require/cli.js +602 -1407
- package/dist/require/constants.d.ts.map +1 -0
- package/dist/require/npm-injection.js +76 -394
- package/dist/require/path-resolve.js +19 -37
- package/dist/require/sdk.js +57 -106
- package/dist/require/shadow-bin.js +109 -0
- package/dist/require/vendor.js +8295 -8708
- package/package.json +29 -30
- 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/link.d.ts +0 -2
- package/dist/module-sync/link.js +0 -54
- package/dist/module-sync/npm-cli.d.ts +0 -2
- package/dist/module-sync/npm-cli.js +0 -101
- package/dist/module-sync/npx-cli.d.ts +0 -2
- package/dist/module-sync/npx-cli.js +0 -77
- package/dist/module-sync/vendor.js +0 -70
- package/dist/require/link.js +0 -54
- package/dist/require/npm-cli.js +0 -101
- package/dist/require/npx-cli.js +0 -77
package/dist/require/cli.js
CHANGED
|
@@ -5,78 +5,59 @@ function _socketInterop(e) {
|
|
|
5
5
|
let c = 0
|
|
6
6
|
for (const k in e ?? {}) {
|
|
7
7
|
c = c === 0 && k === 'default' ? 1 : 0
|
|
8
|
-
if (!c) break
|
|
8
|
+
if (!c && k !== '__esModule') break
|
|
9
9
|
}
|
|
10
10
|
return c ? e.default : e
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
var require$$0 = require('node:url');
|
|
14
|
+
var ponyCause = _socketInterop(require('pony-cause'));
|
|
13
15
|
var vendor = require('./vendor.js');
|
|
14
|
-
var
|
|
15
|
-
var
|
|
16
|
-
var
|
|
17
|
-
var
|
|
18
|
-
var
|
|
19
|
-
var
|
|
20
|
-
var require$$4 = require('@socketsecurity/registry/lib/npm');
|
|
21
|
-
var require$$5 = require('@socketsecurity/registry/lib/words');
|
|
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
22
|
var constants = require('./constants.js');
|
|
23
|
-
var
|
|
23
|
+
var yoctoSpinner = require('@socketregistry/yocto-spinner');
|
|
24
24
|
var sdk = require('./sdk.js');
|
|
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
|
|
25
|
+
var prompts = require('@socketsecurity/registry/lib/prompts');
|
|
26
|
+
var spawn = _socketInterop(require('@npmcli/promise-spawn'));
|
|
27
|
+
var fs$1 = require('node:fs/promises');
|
|
28
|
+
var npa = _socketInterop(require('npm-package-arg'));
|
|
29
|
+
var semver = _socketInterop(require('semver'));
|
|
30
|
+
var tinyglobby = _socketInterop(require('tinyglobby'));
|
|
31
|
+
var yaml = _socketInterop(require('yaml'));
|
|
32
|
+
var registry = require('@socketsecurity/registry');
|
|
33
|
+
var objects = require('@socketsecurity/registry/lib/objects');
|
|
34
|
+
var packages = require('@socketsecurity/registry/lib/packages');
|
|
35
|
+
var promises = require('@socketsecurity/registry/lib/promises');
|
|
36
|
+
var regexps = require('@socketsecurity/registry/lib/regexps');
|
|
37
|
+
var strings = require('@socketsecurity/registry/lib/strings');
|
|
38
|
+
var browserslist = _socketInterop(require('browserslist'));
|
|
39
|
+
var which = _socketInterop(require('which'));
|
|
40
|
+
var hyrious__bun_lockb = require('@socketregistry/hyrious__bun.lockb');
|
|
41
|
+
var registryConstants = require('@socketsecurity/registry/lib/constants');
|
|
42
|
+
var betterAjvErrors = _socketInterop(require('@apideck/better-ajv-errors'));
|
|
43
|
+
var config = require('@socketsecurity/config');
|
|
44
44
|
var pathResolve = require('./path-resolve.js');
|
|
45
|
-
var
|
|
46
|
-
var
|
|
47
|
-
var
|
|
48
|
-
var
|
|
49
|
-
var
|
|
50
|
-
var
|
|
51
|
-
var
|
|
52
|
-
var
|
|
53
|
-
var
|
|
54
|
-
var require$$0$
|
|
55
|
-
var
|
|
45
|
+
var os = require('node:os');
|
|
46
|
+
var readline = require('node:readline');
|
|
47
|
+
var process$1 = require('node:process');
|
|
48
|
+
var readline$1 = require('node:readline/promises');
|
|
49
|
+
var chalkTable = _socketInterop(require('chalk-table'));
|
|
50
|
+
var ScreenWidget = _socketInterop(require('blessed/lib/widgets/screen'));
|
|
51
|
+
var BarChart = _socketInterop(require('blessed-contrib/lib/widget/charts/bar'));
|
|
52
|
+
var GridLayout = _socketInterop(require('blessed-contrib/lib/layout/grid'));
|
|
53
|
+
var LineChart = _socketInterop(require('blessed-contrib/lib/widget/charts/line'));
|
|
54
|
+
var require$$0$1 = require('node:util');
|
|
55
|
+
var TableWidget = _socketInterop(require('blessed-contrib/lib/widget/table'));
|
|
56
56
|
|
|
57
|
-
var cli$2 = {};
|
|
58
|
-
|
|
59
|
-
var cli$1 = {};
|
|
60
|
-
|
|
61
|
-
var commands = {};
|
|
62
|
-
|
|
63
|
-
var cdxgen = {};
|
|
64
|
-
|
|
65
|
-
Object.defineProperty(cdxgen, "__esModule", {
|
|
66
|
-
value: true
|
|
67
|
-
});
|
|
68
|
-
cdxgen.cdxgen = void 0;
|
|
69
|
-
var _nodeFs$3 = require$$0;
|
|
70
|
-
var _nodePath$6 = require$$1;
|
|
71
|
-
var _yoctocolorsCjs$j = require$$1$1;
|
|
72
|
-
var _yargsParser = require$$3;
|
|
73
|
-
var _npm = require$$4;
|
|
74
|
-
var _words$1 = require$$5;
|
|
75
|
-
var _constants$8 = constants.constants;
|
|
76
57
|
const {
|
|
77
58
|
cdxgenBinPath,
|
|
78
59
|
synpBinPath
|
|
79
|
-
} =
|
|
60
|
+
} = constants;
|
|
80
61
|
const {
|
|
81
62
|
SBOM_SIGN_ALGORITHM,
|
|
82
63
|
// Algorithm. Example: RS512
|
|
@@ -179,30 +160,30 @@ function argvToArray(argv) {
|
|
|
179
160
|
}
|
|
180
161
|
return result;
|
|
181
162
|
}
|
|
182
|
-
cdxgen
|
|
163
|
+
const cdxgen = {
|
|
183
164
|
description: 'Create an SBOM with CycloneDX generator (cdxgen)',
|
|
184
165
|
async run(argv_) {
|
|
185
166
|
const yargv = {
|
|
186
|
-
...
|
|
167
|
+
...yargsParse(argv_, yargsConfig)
|
|
187
168
|
};
|
|
188
169
|
const unknown = yargv._;
|
|
189
170
|
const {
|
|
190
171
|
length: unknownLength
|
|
191
172
|
} = unknown;
|
|
192
173
|
if (unknownLength) {
|
|
193
|
-
console.error(`Unknown ${
|
|
174
|
+
console.error(`Unknown ${words.pluralize('argument', unknownLength)}: ${yargv._.join(', ')}`);
|
|
194
175
|
process.exitCode = 1;
|
|
195
176
|
return;
|
|
196
177
|
}
|
|
197
178
|
let cleanupPackageLock = false;
|
|
198
|
-
if (yargv.type !== 'yarn' && nodejsPlatformTypes.has(yargv.type) &&
|
|
199
|
-
if (
|
|
179
|
+
if (yargv.type !== 'yarn' && nodejsPlatformTypes.has(yargv.type) && fs.existsSync('./yarn.lock')) {
|
|
180
|
+
if (fs.existsSync('./package-lock.json')) {
|
|
200
181
|
yargv.type = 'npm';
|
|
201
182
|
} else {
|
|
202
183
|
// Use synp to create a package-lock.json from the yarn.lock,
|
|
203
184
|
// based on the node_modules folder, for a more accurate SBOM.
|
|
204
185
|
try {
|
|
205
|
-
await
|
|
186
|
+
await npm$1.runBin(await fs.promises.realpath(synpBinPath), ['--source-file', './yarn.lock']);
|
|
206
187
|
yargv.type = 'npm';
|
|
207
188
|
cleanupPackageLock = true;
|
|
208
189
|
} catch {}
|
|
@@ -211,7 +192,7 @@ cdxgen.cdxgen = {
|
|
|
211
192
|
if (yargv.output === undefined) {
|
|
212
193
|
yargv.output = 'socket-cdx.json';
|
|
213
194
|
}
|
|
214
|
-
await
|
|
195
|
+
await npm$1.runBin(await fs.promises.realpath(cdxgenBinPath), argvToArray(yargv), {
|
|
215
196
|
env: {
|
|
216
197
|
NODE_ENV: '',
|
|
217
198
|
SBOM_SIGN_ALGORITHM,
|
|
@@ -222,25 +203,17 @@ cdxgen.cdxgen = {
|
|
|
222
203
|
});
|
|
223
204
|
if (cleanupPackageLock) {
|
|
224
205
|
try {
|
|
225
|
-
await
|
|
206
|
+
await fs.promises.rm('./package-lock.json');
|
|
226
207
|
} catch {}
|
|
227
208
|
}
|
|
228
|
-
const fullOutputPath =
|
|
229
|
-
if (
|
|
230
|
-
console.log(
|
|
209
|
+
const fullOutputPath = path.join(process.cwd(), yargv.output);
|
|
210
|
+
if (fs.existsSync(fullOutputPath)) {
|
|
211
|
+
console.log(colors.cyanBright(`${yargv.output} created!`));
|
|
231
212
|
}
|
|
232
213
|
}
|
|
233
214
|
};
|
|
234
215
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
var flags$1 = {};
|
|
238
|
-
|
|
239
|
-
Object.defineProperty(flags$1, "__esModule", {
|
|
240
|
-
value: true
|
|
241
|
-
});
|
|
242
|
-
flags$1.validationFlags = flags$1.outputFlags = flags$1.commonFlags = flags$1.commandFlags = void 0;
|
|
243
|
-
flags$1.commonFlags = {
|
|
216
|
+
const commonFlags = {
|
|
244
217
|
help: {
|
|
245
218
|
type: 'boolean',
|
|
246
219
|
default: false,
|
|
@@ -248,7 +221,7 @@ flags$1.commonFlags = {
|
|
|
248
221
|
description: 'Print this help.'
|
|
249
222
|
}
|
|
250
223
|
};
|
|
251
|
-
|
|
224
|
+
const commandFlags = {
|
|
252
225
|
enable: {
|
|
253
226
|
type: 'boolean',
|
|
254
227
|
default: false,
|
|
@@ -260,7 +233,7 @@ flags$1.commandFlags = {
|
|
|
260
233
|
description: 'Disables the Socket npm/npx wrapper'
|
|
261
234
|
}
|
|
262
235
|
};
|
|
263
|
-
|
|
236
|
+
const outputFlags = {
|
|
264
237
|
json: {
|
|
265
238
|
type: 'boolean',
|
|
266
239
|
shortFlag: 'j',
|
|
@@ -274,7 +247,7 @@ flags$1.outputFlags = {
|
|
|
274
247
|
description: 'Output result as markdown'
|
|
275
248
|
}
|
|
276
249
|
};
|
|
277
|
-
|
|
250
|
+
const validationFlags = {
|
|
278
251
|
all: {
|
|
279
252
|
type: 'boolean',
|
|
280
253
|
default: false,
|
|
@@ -287,31 +260,18 @@ flags$1.validationFlags = {
|
|
|
287
260
|
}
|
|
288
261
|
};
|
|
289
262
|
|
|
290
|
-
var apiHelpers = {};
|
|
291
|
-
|
|
292
|
-
Object.defineProperty(apiHelpers, "__esModule", {
|
|
293
|
-
value: true
|
|
294
|
-
});
|
|
295
|
-
apiHelpers.handleAPIError = handleAPIError;
|
|
296
|
-
apiHelpers.handleApiCall = handleApiCall;
|
|
297
|
-
apiHelpers.handleUnsuccessfulApiResponse = handleUnsuccessfulApiResponse;
|
|
298
|
-
apiHelpers.queryAPI = queryAPI;
|
|
299
|
-
var _yoctocolorsCjs$i = require$$1$1;
|
|
300
|
-
var _ponyCause$4 = require$$4$1;
|
|
301
|
-
var _errors$l = sdk.errors;
|
|
302
|
-
var _constants$7 = constants.constants;
|
|
303
263
|
const {
|
|
304
264
|
API_V0_URL
|
|
305
|
-
} =
|
|
265
|
+
} = constants;
|
|
306
266
|
function handleUnsuccessfulApiResponse(_name, result, spinner) {
|
|
307
267
|
// SocketSdkErrorType['error'] is not typed.
|
|
308
268
|
const resultErrorMessage = result.error?.message;
|
|
309
269
|
const message = typeof resultErrorMessage === 'string' ? resultErrorMessage : 'No error message returned';
|
|
310
270
|
if (result.status === 401 || result.status === 403) {
|
|
311
271
|
spinner.stop();
|
|
312
|
-
throw new
|
|
272
|
+
throw new sdk.AuthError(message);
|
|
313
273
|
}
|
|
314
|
-
spinner.error(`${
|
|
274
|
+
spinner.error(`${colors.bgRed(colors.white('API returned an error:'))} ${message}`);
|
|
315
275
|
process.exit(1);
|
|
316
276
|
}
|
|
317
277
|
async function handleApiCall(value, description) {
|
|
@@ -319,7 +279,7 @@ async function handleApiCall(value, description) {
|
|
|
319
279
|
try {
|
|
320
280
|
result = await value;
|
|
321
281
|
} catch (cause) {
|
|
322
|
-
throw new
|
|
282
|
+
throw new ponyCause.ErrorWithCause(`Failed ${description}`, {
|
|
323
283
|
cause
|
|
324
284
|
});
|
|
325
285
|
}
|
|
@@ -341,15 +301,6 @@ async function queryAPI(path, apiKey) {
|
|
|
341
301
|
});
|
|
342
302
|
}
|
|
343
303
|
|
|
344
|
-
var formatIssues = {};
|
|
345
|
-
|
|
346
|
-
var objects = {};
|
|
347
|
-
|
|
348
|
-
Object.defineProperty(objects, "__esModule", {
|
|
349
|
-
value: true
|
|
350
|
-
});
|
|
351
|
-
objects.objectSome = objectSome;
|
|
352
|
-
objects.pick = pick;
|
|
353
304
|
function objectSome(obj) {
|
|
354
305
|
for (const key in obj) {
|
|
355
306
|
if (obj[key]) {
|
|
@@ -366,13 +317,6 @@ function pick(input, keys) {
|
|
|
366
317
|
return result;
|
|
367
318
|
}
|
|
368
319
|
|
|
369
|
-
Object.defineProperty(formatIssues, "__esModule", {
|
|
370
|
-
value: true
|
|
371
|
-
});
|
|
372
|
-
formatIssues.formatSeverityCount = formatSeverityCount;
|
|
373
|
-
formatIssues.getSeverityCount = getSeverityCount;
|
|
374
|
-
var _misc$2 = sdk.misc;
|
|
375
|
-
var _objects$4 = objects;
|
|
376
320
|
const SEVERITIES_BY_ORDER = ['critical', 'high', 'middle', 'low'];
|
|
377
321
|
function getDesiredSeverities(lowestToInclude) {
|
|
378
322
|
const result = [];
|
|
@@ -391,10 +335,10 @@ function formatSeverityCount(severityCount) {
|
|
|
391
335
|
summary.push(`${severityCount[severity]} ${severity}`);
|
|
392
336
|
}
|
|
393
337
|
}
|
|
394
|
-
return
|
|
338
|
+
return sdk.stringJoinWithSeparateFinalSeparator(summary);
|
|
395
339
|
}
|
|
396
340
|
function getSeverityCount(issues, lowestToInclude) {
|
|
397
|
-
const severityCount =
|
|
341
|
+
const severityCount = pick({
|
|
398
342
|
low: 0,
|
|
399
343
|
middle: 0,
|
|
400
344
|
high: 0,
|
|
@@ -412,13 +356,6 @@ function getSeverityCount(issues, lowestToInclude) {
|
|
|
412
356
|
return severityCount;
|
|
413
357
|
}
|
|
414
358
|
|
|
415
|
-
var formatting = {};
|
|
416
|
-
|
|
417
|
-
Object.defineProperty(formatting, "__esModule", {
|
|
418
|
-
value: true
|
|
419
|
-
});
|
|
420
|
-
formatting.printFlagList = printFlagList;
|
|
421
|
-
formatting.printHelpList = printHelpList;
|
|
422
359
|
function printFlagList(list, indent, {
|
|
423
360
|
keyPrefix = '--',
|
|
424
361
|
padName
|
|
@@ -444,27 +381,10 @@ function printHelpList(list, indent, {
|
|
|
444
381
|
return result.trim();
|
|
445
382
|
}
|
|
446
383
|
|
|
447
|
-
var _interopRequireDefault$q = vendor.interopRequireDefault.default;
|
|
448
|
-
Object.defineProperty(info$1, "__esModule", {
|
|
449
|
-
value: true
|
|
450
|
-
});
|
|
451
|
-
info$1.info = void 0;
|
|
452
|
-
var _yoctocolorsCjs$h = require$$1$1;
|
|
453
|
-
var _meow$p = _interopRequireDefault$q(vendor.build);
|
|
454
|
-
var _yoctoSpinner$l = require$$3$1;
|
|
455
|
-
var _constants$6 = constants.constants;
|
|
456
|
-
var _flags$k = flags$1;
|
|
457
|
-
var _apiHelpers$i = apiHelpers;
|
|
458
|
-
var _colorOrMarkdown$3 = sdk.colorOrMarkdown;
|
|
459
|
-
var _errors$k = sdk.errors;
|
|
460
|
-
var _formatIssues$1 = formatIssues;
|
|
461
|
-
var _formatting$m = formatting;
|
|
462
|
-
var _objects$3 = objects;
|
|
463
|
-
var _sdk$j = sdk.sdk;
|
|
464
384
|
const {
|
|
465
385
|
SOCKET_PUBLIC_API_KEY: SOCKET_PUBLIC_API_KEY$1
|
|
466
|
-
} =
|
|
467
|
-
const info =
|
|
386
|
+
} = constants;
|
|
387
|
+
const info = {
|
|
468
388
|
description: 'Look up info regarding a package',
|
|
469
389
|
async run(argv, importMeta, {
|
|
470
390
|
parentName
|
|
@@ -473,7 +393,7 @@ const info = info$1.info = {
|
|
|
473
393
|
const commandContext = setupCommand$m(name, info.description, argv, importMeta);
|
|
474
394
|
if (commandContext) {
|
|
475
395
|
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}`;
|
|
476
|
-
const spinner =
|
|
396
|
+
const spinner = yoctoSpinner({
|
|
477
397
|
text: spinnerText
|
|
478
398
|
}).start();
|
|
479
399
|
const packageData = await fetchPackageData(commandContext.pkgName, commandContext.pkgVersion, commandContext, spinner);
|
|
@@ -491,16 +411,16 @@ const info = info$1.info = {
|
|
|
491
411
|
|
|
492
412
|
function setupCommand$m(name, description, argv, importMeta) {
|
|
493
413
|
const flags = {
|
|
494
|
-
...
|
|
495
|
-
...
|
|
496
|
-
...
|
|
414
|
+
...commonFlags,
|
|
415
|
+
...outputFlags,
|
|
416
|
+
...validationFlags
|
|
497
417
|
};
|
|
498
|
-
const cli =
|
|
418
|
+
const cli = vendor.meow(`
|
|
499
419
|
Usage
|
|
500
420
|
$ ${name} <name>
|
|
501
421
|
|
|
502
422
|
Options
|
|
503
|
-
${
|
|
423
|
+
${printFlagList(flags, 6)}
|
|
504
424
|
|
|
505
425
|
Examples
|
|
506
426
|
$ ${name} webtorrent
|
|
@@ -512,7 +432,7 @@ function setupCommand$m(name, description, argv, importMeta) {
|
|
|
512
432
|
flags
|
|
513
433
|
});
|
|
514
434
|
if (cli.input.length > 1) {
|
|
515
|
-
throw new
|
|
435
|
+
throw new sdk.InputError('Only one package lookup supported at once');
|
|
516
436
|
}
|
|
517
437
|
const {
|
|
518
438
|
0: rawPkgName = ''
|
|
@@ -540,16 +460,16 @@ function setupCommand$m(name, description, argv, importMeta) {
|
|
|
540
460
|
async function fetchPackageData(pkgName, pkgVersion, {
|
|
541
461
|
includeAllIssues
|
|
542
462
|
}, spinner) {
|
|
543
|
-
const socketSdk = await
|
|
544
|
-
const result = await
|
|
545
|
-
const scoreResult = await
|
|
463
|
+
const socketSdk = await sdk.setupSdk(sdk.getDefaultKey() ?? SOCKET_PUBLIC_API_KEY$1);
|
|
464
|
+
const result = await handleApiCall(socketSdk.getIssuesByNPMPackage(pkgName, pkgVersion), 'looking up package');
|
|
465
|
+
const scoreResult = await handleApiCall(socketSdk.getScoreByNPMPackage(pkgName, pkgVersion), 'looking up package score');
|
|
546
466
|
if (result.success === false) {
|
|
547
|
-
return
|
|
467
|
+
return handleUnsuccessfulApiResponse('getIssuesByNPMPackage', result, spinner);
|
|
548
468
|
}
|
|
549
469
|
if (scoreResult.success === false) {
|
|
550
|
-
return
|
|
470
|
+
return handleUnsuccessfulApiResponse('getScoreByNPMPackage', scoreResult, spinner);
|
|
551
471
|
}
|
|
552
|
-
const severityCount =
|
|
472
|
+
const severityCount = getSeverityCount(result.data, includeAllIssues ? undefined : 'high');
|
|
553
473
|
return {
|
|
554
474
|
data: result.data,
|
|
555
475
|
severityCount,
|
|
@@ -581,13 +501,13 @@ function formatPackageDataOutput({
|
|
|
581
501
|
};
|
|
582
502
|
Object.entries(scoreResult).map(score => console.log(`- ${score[0]}: ${formatScore(score[1])}`));
|
|
583
503
|
console.log('\n');
|
|
584
|
-
if (
|
|
585
|
-
spinner[strict ? 'error' : 'success'](`Package has these issues: ${
|
|
504
|
+
if (objectSome(severityCount)) {
|
|
505
|
+
spinner[strict ? 'error' : 'success'](`Package has these issues: ${formatSeverityCount(severityCount)}`);
|
|
586
506
|
formatPackageIssuesDetails(data, outputMarkdown);
|
|
587
507
|
} else {
|
|
588
508
|
spinner.success('Package has no issues');
|
|
589
509
|
}
|
|
590
|
-
const format = new
|
|
510
|
+
const format = new sdk.ColorOrMarkdown(!!outputMarkdown);
|
|
591
511
|
const url = `https://socket.dev/npm/package/${pkgName}/overview/${pkgVersion}`;
|
|
592
512
|
console.log('\n');
|
|
593
513
|
if (pkgVersion === 'latest') {
|
|
@@ -600,10 +520,10 @@ function formatPackageDataOutput({
|
|
|
600
520
|
})}`);
|
|
601
521
|
}
|
|
602
522
|
if (!outputMarkdown) {
|
|
603
|
-
console.log(
|
|
523
|
+
console.log(colors.dim(`\nOr rerun ${colors.italic(name)} using the ${colors.italic('--json')} flag to get full JSON output`));
|
|
604
524
|
}
|
|
605
525
|
}
|
|
606
|
-
if (strict &&
|
|
526
|
+
if (strict && objectSome(severityCount)) {
|
|
607
527
|
process.exit(1);
|
|
608
528
|
}
|
|
609
529
|
}
|
|
@@ -625,7 +545,7 @@ function formatPackageIssuesDetails(packageData, outputMarkdown) {
|
|
|
625
545
|
}
|
|
626
546
|
return acc;
|
|
627
547
|
}, {});
|
|
628
|
-
const format = new
|
|
548
|
+
const format = new sdk.ColorOrMarkdown(!!outputMarkdown);
|
|
629
549
|
for (const issue of Object.keys(uniqueIssues)) {
|
|
630
550
|
const issueWithLink = format.hyperlink(`${uniqueIssues[issue]?.label}`, `https://socket.dev/npm/issue/${issue}`, {
|
|
631
551
|
fallbackToUrl: true
|
|
@@ -639,33 +559,16 @@ function formatPackageIssuesDetails(packageData, outputMarkdown) {
|
|
|
639
559
|
}
|
|
640
560
|
function formatScore(score) {
|
|
641
561
|
if (score > 80) {
|
|
642
|
-
return
|
|
562
|
+
return colors.green(`${score}`);
|
|
643
563
|
} else if (score < 80 && score > 60) {
|
|
644
|
-
return
|
|
564
|
+
return colors.yellow(`${score}`);
|
|
645
565
|
}
|
|
646
|
-
return
|
|
566
|
+
return colors.red(`${score}`);
|
|
647
567
|
}
|
|
648
568
|
|
|
649
|
-
var login = {};
|
|
650
|
-
|
|
651
|
-
var _interopRequireDefault$p = vendor.interopRequireDefault.default;
|
|
652
|
-
Object.defineProperty(login, "__esModule", {
|
|
653
|
-
value: true
|
|
654
|
-
});
|
|
655
|
-
login.login = void 0;
|
|
656
|
-
var _prompts$1 = require$$1$2;
|
|
657
|
-
var _isInteractive = _interopRequireDefault$p(vendor.isInteractive);
|
|
658
|
-
var _meow$o = _interopRequireDefault$p(vendor.build);
|
|
659
|
-
var _yoctoSpinner$k = require$$3$1;
|
|
660
|
-
var _terminalLink = _interopRequireDefault$p(vendor.terminalLink);
|
|
661
|
-
var _constants$5 = constants.constants;
|
|
662
|
-
var _errors$j = sdk.errors;
|
|
663
|
-
var _formatting$l = formatting;
|
|
664
|
-
var _sdk$i = sdk.sdk;
|
|
665
|
-
var _settings$1 = sdk.settings;
|
|
666
569
|
const {
|
|
667
570
|
SOCKET_PUBLIC_API_KEY
|
|
668
|
-
} =
|
|
571
|
+
} = constants;
|
|
669
572
|
const description$7 = 'Socket API login';
|
|
670
573
|
const flags = {
|
|
671
574
|
apiBaseUrl: {
|
|
@@ -680,20 +583,20 @@ const flags = {
|
|
|
680
583
|
function nonNullish(value) {
|
|
681
584
|
return value !== null && value !== undefined;
|
|
682
585
|
}
|
|
683
|
-
login
|
|
586
|
+
const login = {
|
|
684
587
|
description: description$7,
|
|
685
588
|
async run(argv, importMeta, {
|
|
686
589
|
parentName
|
|
687
590
|
}) {
|
|
688
591
|
const name = `${parentName} login`;
|
|
689
|
-
const cli =
|
|
592
|
+
const cli = vendor.meow(`
|
|
690
593
|
Usage
|
|
691
594
|
$ ${name}
|
|
692
595
|
|
|
693
596
|
Logs into the Socket API by prompting for an API key
|
|
694
597
|
|
|
695
598
|
Options
|
|
696
|
-
${
|
|
599
|
+
${printFlagList({
|
|
697
600
|
'api-base-url': flags['apiBaseUrl'].description,
|
|
698
601
|
'api-proxy': flags['apiProxy'].description
|
|
699
602
|
}, 8)}
|
|
@@ -714,25 +617,25 @@ login.login = {
|
|
|
714
617
|
cli.showHelp();
|
|
715
618
|
return;
|
|
716
619
|
}
|
|
717
|
-
if (!
|
|
718
|
-
throw new
|
|
620
|
+
if (!vendor.isInteractive()) {
|
|
621
|
+
throw new sdk.InputError('Cannot prompt for credentials in a non-interactive shell');
|
|
719
622
|
}
|
|
720
|
-
const apiKey = (await
|
|
721
|
-
message: `Enter your ${
|
|
623
|
+
const apiKey = (await prompts.password({
|
|
624
|
+
message: `Enter your ${vendor.terminalLink('Socket.dev API key', 'https://docs.socket.dev/docs/api-keys')} (leave blank for a public key)`
|
|
722
625
|
})) || SOCKET_PUBLIC_API_KEY;
|
|
723
626
|
let apiBaseUrl = cli.flags['apiBaseUrl'];
|
|
724
|
-
apiBaseUrl ??=
|
|
627
|
+
apiBaseUrl ??= sdk.getSetting('apiBaseUrl') ?? undefined;
|
|
725
628
|
let apiProxy = cli.flags['apiProxy'];
|
|
726
|
-
apiProxy ??=
|
|
727
|
-
const spinner =
|
|
629
|
+
apiProxy ??= sdk.getSetting('apiProxy') ?? undefined;
|
|
630
|
+
const spinner = yoctoSpinner({
|
|
728
631
|
text: 'Verifying API key...'
|
|
729
632
|
}).start();
|
|
730
633
|
let orgs;
|
|
731
634
|
try {
|
|
732
|
-
const sdk = await
|
|
733
|
-
const result = await sdk.getOrganizations();
|
|
635
|
+
const sdk$1 = await sdk.setupSdk(apiKey, apiBaseUrl, apiProxy);
|
|
636
|
+
const result = await sdk$1.getOrganizations();
|
|
734
637
|
if (!result.success) {
|
|
735
|
-
throw new
|
|
638
|
+
throw new sdk.AuthError();
|
|
736
639
|
}
|
|
737
640
|
orgs = result.data;
|
|
738
641
|
spinner.success('API key verified');
|
|
@@ -746,7 +649,7 @@ login.login = {
|
|
|
746
649
|
}));
|
|
747
650
|
let enforcedOrgs = [];
|
|
748
651
|
if (enforcedChoices.length > 1) {
|
|
749
|
-
const id = await
|
|
652
|
+
const id = await prompts.select({
|
|
750
653
|
message: "Which organization's policies should Socket enforce system-wide?",
|
|
751
654
|
choices: enforcedChoices.concat({
|
|
752
655
|
name: 'None',
|
|
@@ -758,7 +661,7 @@ login.login = {
|
|
|
758
661
|
enforcedOrgs = [id];
|
|
759
662
|
}
|
|
760
663
|
} else if (enforcedChoices.length) {
|
|
761
|
-
const confirmOrg = await
|
|
664
|
+
const confirmOrg = await prompts.confirm({
|
|
762
665
|
message: `Should Socket enforce ${enforcedChoices[0]?.name}'s security policies system-wide?`,
|
|
763
666
|
default: true
|
|
764
667
|
});
|
|
@@ -769,33 +672,23 @@ login.login = {
|
|
|
769
672
|
}
|
|
770
673
|
}
|
|
771
674
|
}
|
|
772
|
-
|
|
773
|
-
const oldKey =
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
675
|
+
sdk.updateSetting('enforcedOrgs', enforcedOrgs);
|
|
676
|
+
const oldKey = sdk.getSetting('apiKey');
|
|
677
|
+
sdk.updateSetting('apiKey', apiKey);
|
|
678
|
+
sdk.updateSetting('apiBaseUrl', apiBaseUrl);
|
|
679
|
+
sdk.updateSetting('apiProxy', apiProxy);
|
|
777
680
|
spinner.success(`API credentials ${oldKey ? 'updated' : 'set'}`);
|
|
778
681
|
}
|
|
779
682
|
};
|
|
780
683
|
|
|
781
|
-
var logout = {};
|
|
782
|
-
|
|
783
|
-
var _interopRequireDefault$o = vendor.interopRequireDefault.default;
|
|
784
|
-
Object.defineProperty(logout, "__esModule", {
|
|
785
|
-
value: true
|
|
786
|
-
});
|
|
787
|
-
logout.logout = void 0;
|
|
788
|
-
var _meow$n = _interopRequireDefault$o(vendor.build);
|
|
789
|
-
var _yoctoSpinner$j = require$$3$1;
|
|
790
|
-
var _settings = sdk.settings;
|
|
791
684
|
const description$6 = 'Socket API logout';
|
|
792
|
-
logout
|
|
685
|
+
const logout = {
|
|
793
686
|
description: description$6,
|
|
794
687
|
async run(argv, importMeta, {
|
|
795
688
|
parentName
|
|
796
689
|
}) {
|
|
797
690
|
const name = `${parentName} logout`;
|
|
798
|
-
const cli =
|
|
691
|
+
const cli = vendor.meow(`
|
|
799
692
|
Usage
|
|
800
693
|
$ ${name}
|
|
801
694
|
|
|
@@ -816,36 +709,29 @@ logout.logout = {
|
|
|
816
709
|
cli.showHelp();
|
|
817
710
|
return;
|
|
818
711
|
}
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
712
|
+
sdk.updateSetting('apiKey', null);
|
|
713
|
+
sdk.updateSetting('apiBaseUrl', null);
|
|
714
|
+
sdk.updateSetting('apiProxy', null);
|
|
715
|
+
sdk.updateSetting('enforcedOrgs', null);
|
|
716
|
+
yoctoSpinner().success('Successfully logged out');
|
|
824
717
|
}
|
|
825
718
|
};
|
|
826
719
|
|
|
827
|
-
var npm = {};
|
|
828
|
-
|
|
829
|
-
Object.defineProperty(npm, "__esModule", {
|
|
830
|
-
value: true
|
|
831
|
-
});
|
|
832
|
-
npm.npm = void 0;
|
|
833
|
-
var _nodePath$5 = require$$1;
|
|
834
|
-
var _promiseSpawn$5 = require$$1$3;
|
|
835
|
-
var _constants$4 = constants.constants;
|
|
836
720
|
const {
|
|
837
|
-
|
|
838
|
-
execPath: execPath$2
|
|
839
|
-
|
|
721
|
+
abortSignal: abortSignal$4,
|
|
722
|
+
execPath: execPath$2,
|
|
723
|
+
rootBinPath: rootBinPath$2
|
|
724
|
+
} = constants;
|
|
840
725
|
const description$5 = 'npm wrapper functionality';
|
|
841
|
-
npm
|
|
726
|
+
const npm = {
|
|
842
727
|
description: description$5,
|
|
843
728
|
async run(argv, _importMeta, _ctx) {
|
|
844
|
-
const wrapperPath =
|
|
729
|
+
const wrapperPath = path.join(rootBinPath$2, 'npm-cli.js');
|
|
845
730
|
process.exitCode = 1;
|
|
846
|
-
const spawnPromise =
|
|
731
|
+
const spawnPromise = spawn(execPath$2, [
|
|
847
732
|
// Lazily access constants.nodeNoWarningsFlags.
|
|
848
|
-
...
|
|
733
|
+
...constants.nodeNoWarningsFlags, wrapperPath, ...argv], {
|
|
734
|
+
signal: abortSignal$4,
|
|
849
735
|
stdio: 'inherit'
|
|
850
736
|
});
|
|
851
737
|
spawnPromise.process.on('exit', (code, signal) => {
|
|
@@ -859,28 +745,21 @@ npm.npm = {
|
|
|
859
745
|
}
|
|
860
746
|
};
|
|
861
747
|
|
|
862
|
-
var npx = {};
|
|
863
|
-
|
|
864
|
-
Object.defineProperty(npx, "__esModule", {
|
|
865
|
-
value: true
|
|
866
|
-
});
|
|
867
|
-
npx.npx = void 0;
|
|
868
|
-
var _nodePath$4 = require$$1;
|
|
869
|
-
var _promiseSpawn$4 = require$$1$3;
|
|
870
|
-
var _constants$3 = constants.constants;
|
|
871
748
|
const {
|
|
872
|
-
|
|
873
|
-
execPath: execPath$1
|
|
874
|
-
|
|
749
|
+
abortSignal: abortSignal$3,
|
|
750
|
+
execPath: execPath$1,
|
|
751
|
+
rootBinPath: rootBinPath$1
|
|
752
|
+
} = constants;
|
|
875
753
|
const description$4 = 'npx wrapper functionality';
|
|
876
|
-
npx
|
|
754
|
+
const npx = {
|
|
877
755
|
description: description$4,
|
|
878
756
|
async run(argv, _importMeta, _ctx) {
|
|
879
|
-
const wrapperPath =
|
|
757
|
+
const wrapperPath = path.join(rootBinPath$1, 'npx-cli.js');
|
|
880
758
|
process.exitCode = 1;
|
|
881
|
-
const spawnPromise =
|
|
759
|
+
const spawnPromise = spawn(execPath$1, [
|
|
882
760
|
// Lazily access constants.nodeNoWarningsFlags.
|
|
883
|
-
...
|
|
761
|
+
...constants.nodeNoWarningsFlags, wrapperPath, ...argv], {
|
|
762
|
+
abortSignal: abortSignal$3,
|
|
884
763
|
stdio: 'inherit'
|
|
885
764
|
});
|
|
886
765
|
spawnPromise.process.on('exit', (code, signal) => {
|
|
@@ -894,80 +773,49 @@ npx.npx = {
|
|
|
894
773
|
}
|
|
895
774
|
};
|
|
896
775
|
|
|
897
|
-
var optimize$1 = {};
|
|
898
|
-
|
|
899
|
-
var fs = {};
|
|
900
|
-
|
|
901
|
-
Object.defineProperty(fs, "__esModule", {
|
|
902
|
-
value: true
|
|
903
|
-
});
|
|
904
|
-
fs.existsSync = existsSync;
|
|
905
|
-
fs.findUp = findUp;
|
|
906
|
-
fs.readFileBinary = readFileBinary;
|
|
907
|
-
fs.readFileUtf8 = readFileUtf8;
|
|
908
|
-
var _nodeFs$2 = require$$0;
|
|
909
|
-
var _nodePath$3 = require$$1;
|
|
910
776
|
function existsSync(filepath) {
|
|
911
777
|
try {
|
|
912
|
-
return filepath ?
|
|
778
|
+
return filepath ? fs.existsSync(filepath) : false;
|
|
913
779
|
} catch {}
|
|
914
780
|
return false;
|
|
915
781
|
}
|
|
916
782
|
async function findUp(name, {
|
|
917
783
|
cwd = process.cwd()
|
|
918
784
|
}) {
|
|
919
|
-
let dir =
|
|
785
|
+
let dir = path.resolve(cwd);
|
|
920
786
|
const {
|
|
921
787
|
root
|
|
922
|
-
} =
|
|
788
|
+
} = path.parse(dir);
|
|
923
789
|
const names = [name].flat();
|
|
924
790
|
while (dir && dir !== root) {
|
|
925
791
|
for (const name of names) {
|
|
926
|
-
const filePath =
|
|
792
|
+
const filePath = path.join(dir, name);
|
|
927
793
|
try {
|
|
928
794
|
// eslint-disable-next-line no-await-in-loop
|
|
929
|
-
const stats = await
|
|
795
|
+
const stats = await fs.promises.stat(filePath);
|
|
930
796
|
if (stats.isFile()) {
|
|
931
797
|
return filePath;
|
|
932
798
|
}
|
|
933
799
|
} catch {}
|
|
934
800
|
}
|
|
935
|
-
dir =
|
|
801
|
+
dir = path.dirname(dir);
|
|
936
802
|
}
|
|
937
803
|
return undefined;
|
|
938
804
|
}
|
|
939
805
|
async function readFileBinary(filepath, options) {
|
|
940
|
-
return await
|
|
806
|
+
return await fs.promises.readFile(filepath, {
|
|
941
807
|
...options,
|
|
942
808
|
encoding: 'binary'
|
|
943
809
|
});
|
|
944
810
|
}
|
|
945
811
|
async function readFileUtf8(filepath, options) {
|
|
946
|
-
return await
|
|
812
|
+
return await fs.promises.readFile(filepath, {
|
|
947
813
|
...options,
|
|
948
814
|
encoding: 'utf8'
|
|
949
815
|
});
|
|
950
816
|
}
|
|
951
817
|
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
Object.defineProperty(packageManagerDetector, "__esModule", {
|
|
955
|
-
value: true
|
|
956
|
-
});
|
|
957
|
-
packageManagerDetector.AGENTS = void 0;
|
|
958
|
-
packageManagerDetector.detect = detect;
|
|
959
|
-
var _nodePath$2 = require$$1;
|
|
960
|
-
var _promiseSpawn$3 = require$$1$3;
|
|
961
|
-
var _browserslist = require$$2;
|
|
962
|
-
var _semver$1 = require$$3$2;
|
|
963
|
-
var _which = require$$4$3;
|
|
964
|
-
var _hyrious__bun = require$$5$1;
|
|
965
|
-
var _constants$2 = require$$3$3;
|
|
966
|
-
var _objects$2 = require$$7;
|
|
967
|
-
var _packages$1 = require$$8;
|
|
968
|
-
var _strings$1 = require$$4$2;
|
|
969
|
-
var _fs$1 = fs;
|
|
970
|
-
const AGENTS = packageManagerDetector.AGENTS = ['bun', 'npm', 'pnpm', 'yarn/berry', 'yarn/classic', 'vlt'];
|
|
818
|
+
const AGENTS = ['bun', 'npm', 'pnpm', 'yarn/berry', 'yarn/classic', 'vlt'];
|
|
971
819
|
const {
|
|
972
820
|
compare: alphanumericComparator
|
|
973
821
|
} = new Intl.Collator(undefined, {
|
|
@@ -975,16 +823,16 @@ const {
|
|
|
975
823
|
sensitivity: 'base'
|
|
976
824
|
});
|
|
977
825
|
async function getAgentExecPath(agent) {
|
|
978
|
-
return (await
|
|
826
|
+
return (await which(agent, {
|
|
979
827
|
nothrow: true
|
|
980
828
|
})) ?? agent;
|
|
981
829
|
}
|
|
982
830
|
async function getAgentVersion(agentExecPath, cwd) {
|
|
983
831
|
let result;
|
|
984
832
|
try {
|
|
985
|
-
result =
|
|
833
|
+
result = semver.coerce(
|
|
986
834
|
// All package managers support the "--version" flag.
|
|
987
|
-
(await
|
|
835
|
+
(await spawn(agentExecPath, ['--version'], {
|
|
988
836
|
cwd
|
|
989
837
|
})).stdout) ?? undefined;
|
|
990
838
|
} catch {}
|
|
@@ -1018,22 +866,22 @@ const readLockFileByAgent = (() => {
|
|
|
1018
866
|
return undefined;
|
|
1019
867
|
};
|
|
1020
868
|
}
|
|
1021
|
-
const defaultReader = wrapReader(async lockPath => await
|
|
869
|
+
const defaultReader = wrapReader(async lockPath => await readFileUtf8(lockPath));
|
|
1022
870
|
return {
|
|
1023
871
|
bun: wrapReader(async (lockPath, agentExecPath) => {
|
|
1024
872
|
let lockBuffer;
|
|
1025
873
|
try {
|
|
1026
|
-
lockBuffer = await
|
|
874
|
+
lockBuffer = await readFileBinary(lockPath);
|
|
1027
875
|
} catch {
|
|
1028
876
|
return undefined;
|
|
1029
877
|
}
|
|
1030
878
|
try {
|
|
1031
|
-
return
|
|
879
|
+
return hyrious__bun_lockb.parse(lockBuffer);
|
|
1032
880
|
} catch {}
|
|
1033
881
|
// To print a Yarn lockfile to your console without writing it to disk
|
|
1034
882
|
// use `bun bun.lockb`.
|
|
1035
883
|
// https://bun.sh/guides/install/yarnlock
|
|
1036
|
-
return (await
|
|
884
|
+
return (await spawn(agentExecPath, [lockPath])).stdout.trim();
|
|
1037
885
|
}),
|
|
1038
886
|
npm: defaultReader,
|
|
1039
887
|
pnpm: defaultReader,
|
|
@@ -1046,21 +894,21 @@ async function detect({
|
|
|
1046
894
|
cwd = process.cwd(),
|
|
1047
895
|
onUnknown
|
|
1048
896
|
} = {}) {
|
|
1049
|
-
let lockPath = await
|
|
897
|
+
let lockPath = await findUp(Object.keys(LOCKS), {
|
|
1050
898
|
cwd
|
|
1051
899
|
});
|
|
1052
900
|
const isHiddenLockFile = lockPath?.endsWith('.package-lock.json') ?? false;
|
|
1053
|
-
const pkgJsonPath = lockPath ?
|
|
901
|
+
const pkgJsonPath = lockPath ? path.resolve(lockPath, `${isHiddenLockFile ? '../' : ''}../package.json`) : await findUp('package.json', {
|
|
1054
902
|
cwd
|
|
1055
903
|
});
|
|
1056
|
-
const pkgPath =
|
|
1057
|
-
const editablePkgJson = pkgPath ? await
|
|
904
|
+
const pkgPath = existsSync(pkgJsonPath) ? path.dirname(pkgJsonPath) : undefined;
|
|
905
|
+
const editablePkgJson = pkgPath ? await packages.readPackageJson(pkgPath, {
|
|
1058
906
|
editable: true
|
|
1059
907
|
}) : undefined;
|
|
1060
908
|
const pkgJson = editablePkgJson?.content;
|
|
1061
909
|
// Read Corepack `packageManager` field in package.json:
|
|
1062
910
|
// https://nodejs.org/api/packages.html#packagemanager
|
|
1063
|
-
const pkgManager =
|
|
911
|
+
const pkgManager = strings.isNonEmptyString(pkgJson?.packageManager) ? pkgJson.packageManager : undefined;
|
|
1064
912
|
let agent;
|
|
1065
913
|
let agentVersion;
|
|
1066
914
|
if (pkgManager) {
|
|
@@ -1070,12 +918,12 @@ async function detect({
|
|
|
1070
918
|
const version = pkgManager.slice(atSignIndex + 1);
|
|
1071
919
|
if (version && AGENTS.includes(name)) {
|
|
1072
920
|
agent = name;
|
|
1073
|
-
agentVersion =
|
|
921
|
+
agentVersion = semver.coerce(version) ?? undefined;
|
|
1074
922
|
}
|
|
1075
923
|
}
|
|
1076
924
|
}
|
|
1077
925
|
if (agent === undefined && !isHiddenLockFile && typeof pkgJsonPath === 'string' && typeof lockPath === 'string') {
|
|
1078
|
-
agent = LOCKS[
|
|
926
|
+
agent = LOCKS[path.basename(lockPath)];
|
|
1079
927
|
}
|
|
1080
928
|
if (agent === undefined) {
|
|
1081
929
|
agent = 'npm';
|
|
@@ -1095,35 +943,35 @@ async function detect({
|
|
|
1095
943
|
};
|
|
1096
944
|
let lockSrc;
|
|
1097
945
|
// Lazily access constants.maintainedNodeVersions.
|
|
1098
|
-
let minimumNodeVersion =
|
|
946
|
+
let minimumNodeVersion = registryConstants.maintainedNodeVersions.previous;
|
|
1099
947
|
if (pkgJson) {
|
|
1100
948
|
const browserField = pkgJson.browser;
|
|
1101
|
-
if (
|
|
949
|
+
if (strings.isNonEmptyString(browserField) || objects.isObjectObject(browserField)) {
|
|
1102
950
|
targets.browser = true;
|
|
1103
951
|
}
|
|
1104
952
|
const nodeRange = pkgJson.engines?.['node'];
|
|
1105
|
-
if (
|
|
1106
|
-
const coerced =
|
|
1107
|
-
if (coerced &&
|
|
953
|
+
if (strings.isNonEmptyString(nodeRange)) {
|
|
954
|
+
const coerced = semver.coerce(nodeRange);
|
|
955
|
+
if (coerced && semver.lt(coerced, minimumNodeVersion)) {
|
|
1108
956
|
minimumNodeVersion = coerced.version;
|
|
1109
957
|
}
|
|
1110
958
|
}
|
|
1111
959
|
const browserslistQuery = pkgJson['browserslist'];
|
|
1112
960
|
if (Array.isArray(browserslistQuery)) {
|
|
1113
|
-
const browserslistTargets =
|
|
961
|
+
const browserslistTargets = browserslist(browserslistQuery).map(s => s.toLowerCase()).sort(alphanumericComparator);
|
|
1114
962
|
const browserslistNodeTargets = browserslistTargets.filter(v => v.startsWith('node ')).map(v => v.slice(5 /*'node '.length*/));
|
|
1115
963
|
if (!targets.browser && browserslistTargets.length) {
|
|
1116
964
|
targets.browser = browserslistTargets.length !== browserslistNodeTargets.length;
|
|
1117
965
|
}
|
|
1118
966
|
if (browserslistNodeTargets.length) {
|
|
1119
|
-
const coerced =
|
|
1120
|
-
if (coerced &&
|
|
967
|
+
const coerced = semver.coerce(browserslistNodeTargets[0]);
|
|
968
|
+
if (coerced && semver.lt(coerced, minimumNodeVersion)) {
|
|
1121
969
|
minimumNodeVersion = coerced.version;
|
|
1122
970
|
}
|
|
1123
971
|
}
|
|
1124
972
|
}
|
|
1125
973
|
// Lazily access constants.maintainedNodeVersions.
|
|
1126
|
-
targets.node =
|
|
974
|
+
targets.node = registryConstants.maintainedNodeVersions.some(v => semver.satisfies(v, `>=${minimumNodeVersion}`));
|
|
1127
975
|
lockSrc = typeof lockPath === 'string' ? await readLockFileByAgent[agent](lockPath, agentExecPath) : undefined;
|
|
1128
976
|
} else {
|
|
1129
977
|
lockPath = undefined;
|
|
@@ -1143,44 +991,19 @@ async function detect({
|
|
|
1143
991
|
};
|
|
1144
992
|
}
|
|
1145
993
|
|
|
1146
|
-
var _interopRequireDefault$n = vendor.interopRequireDefault.default;
|
|
1147
|
-
Object.defineProperty(optimize$1, "__esModule", {
|
|
1148
|
-
value: true
|
|
1149
|
-
});
|
|
1150
|
-
optimize$1.optimize = void 0;
|
|
1151
|
-
var _promises$2 = require$$1$4;
|
|
1152
|
-
var _nodePath$1 = require$$1;
|
|
1153
|
-
var _promiseSpawn$2 = require$$1$3;
|
|
1154
|
-
var _meow$m = _interopRequireDefault$n(vendor.build);
|
|
1155
|
-
var _npmPackageArg = require$$5$2;
|
|
1156
|
-
var _yoctoSpinner$i = require$$3$1;
|
|
1157
|
-
var _semver = require$$3$2;
|
|
1158
|
-
var _tinyglobby = require$$8$1;
|
|
1159
|
-
var _yaml = require$$9;
|
|
1160
|
-
var _registry = require$$10;
|
|
1161
|
-
var _objects$1 = require$$7;
|
|
1162
|
-
var _packages = require$$8;
|
|
1163
|
-
var _promises2 = require$$13;
|
|
1164
|
-
var _regexps = require$$14;
|
|
1165
|
-
var _strings = require$$4$2;
|
|
1166
|
-
var _words = require$$5;
|
|
1167
|
-
var _constants$1 = constants.constants;
|
|
1168
|
-
var _flags$j = flags$1;
|
|
1169
|
-
var _formatting$k = formatting;
|
|
1170
|
-
var _fs = fs;
|
|
1171
|
-
var _packageManagerDetector = packageManagerDetector;
|
|
1172
994
|
const {
|
|
1173
995
|
UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE,
|
|
1174
|
-
|
|
1175
|
-
execPath
|
|
1176
|
-
|
|
996
|
+
abortSignal: abortSignal$2,
|
|
997
|
+
execPath,
|
|
998
|
+
rootBinPath
|
|
999
|
+
} = constants;
|
|
1177
1000
|
const COMMAND_TITLE = 'Socket Optimize';
|
|
1178
1001
|
const OVERRIDES_FIELD_NAME = 'overrides';
|
|
1179
1002
|
const NPM_OVERRIDE_PR_URL = 'https://github.com/npm/cli/pull/7025';
|
|
1180
1003
|
const PNPM_FIELD_NAME = 'pnpm';
|
|
1181
1004
|
const PNPM_WORKSPACE = 'pnpm-workspace';
|
|
1182
1005
|
const RESOLUTIONS_FIELD_NAME = 'resolutions';
|
|
1183
|
-
const manifestNpmOverrides =
|
|
1006
|
+
const manifestNpmOverrides = registry.getManifestData('npm');
|
|
1184
1007
|
const getOverridesDataByAgent = {
|
|
1185
1008
|
bun(pkgJson) {
|
|
1186
1009
|
const overrides = pkgJson?.resolutions ?? {};
|
|
@@ -1235,7 +1058,7 @@ const getOverridesDataByAgent = {
|
|
|
1235
1058
|
};
|
|
1236
1059
|
const lockIncludesByAgent = (() => {
|
|
1237
1060
|
function yarnLockIncludes(lockSrc, name) {
|
|
1238
|
-
const escapedName =
|
|
1061
|
+
const escapedName = regexps.escapeRegExp(name);
|
|
1239
1062
|
return new RegExp(
|
|
1240
1063
|
// Detects the package name in the following cases:
|
|
1241
1064
|
// "name@
|
|
@@ -1252,7 +1075,7 @@ const lockIncludesByAgent = (() => {
|
|
|
1252
1075
|
return lockSrc.includes(`"${name}":`);
|
|
1253
1076
|
},
|
|
1254
1077
|
pnpm(lockSrc, name) {
|
|
1255
|
-
const escapedName =
|
|
1078
|
+
const escapedName = regexps.escapeRegExp(name);
|
|
1256
1079
|
return new RegExp(
|
|
1257
1080
|
// Detects the package name in the following cases:
|
|
1258
1081
|
// /name/
|
|
@@ -1287,18 +1110,18 @@ const updateManifestByAgent = (() => {
|
|
|
1287
1110
|
if (oldValue) {
|
|
1288
1111
|
// The field already exists so we simply update the field value.
|
|
1289
1112
|
if (field === PNPM_FIELD_NAME) {
|
|
1290
|
-
if (
|
|
1113
|
+
if (objects.hasKeys(value)) {
|
|
1291
1114
|
editablePkgJson.update({
|
|
1292
1115
|
[field]: {
|
|
1293
|
-
...(
|
|
1116
|
+
...(objects.isObject(oldValue) ? oldValue : {}),
|
|
1294
1117
|
overrides: value
|
|
1295
1118
|
}
|
|
1296
1119
|
});
|
|
1297
1120
|
} else {
|
|
1298
1121
|
// Properties with undefined values are omitted when saved as JSON.
|
|
1299
|
-
editablePkgJson.update(
|
|
1122
|
+
editablePkgJson.update(objects.hasKeys(pkgJson[field]) ? {
|
|
1300
1123
|
[field]: {
|
|
1301
|
-
...(
|
|
1124
|
+
...(objects.isObject(oldValue) ? oldValue : {}),
|
|
1302
1125
|
overrides: undefined
|
|
1303
1126
|
}
|
|
1304
1127
|
} : {
|
|
@@ -1308,7 +1131,7 @@ const updateManifestByAgent = (() => {
|
|
|
1308
1131
|
} else if (field === OVERRIDES_FIELD_NAME || field === RESOLUTIONS_FIELD_NAME) {
|
|
1309
1132
|
// Properties with undefined values are omitted when saved as JSON.
|
|
1310
1133
|
editablePkgJson.update({
|
|
1311
|
-
[field]:
|
|
1134
|
+
[field]: objects.hasKeys(value) ? value : undefined
|
|
1312
1135
|
});
|
|
1313
1136
|
} else {
|
|
1314
1137
|
editablePkgJson.update({
|
|
@@ -1317,7 +1140,7 @@ const updateManifestByAgent = (() => {
|
|
|
1317
1140
|
}
|
|
1318
1141
|
return;
|
|
1319
1142
|
}
|
|
1320
|
-
if ((field === OVERRIDES_FIELD_NAME || field === PNPM_FIELD_NAME || field === RESOLUTIONS_FIELD_NAME) && !
|
|
1143
|
+
if ((field === OVERRIDES_FIELD_NAME || field === PNPM_FIELD_NAME || field === RESOLUTIONS_FIELD_NAME) && !objects.hasKeys(value)) {
|
|
1321
1144
|
return;
|
|
1322
1145
|
}
|
|
1323
1146
|
// Since the field doesn't exist we want to insert it into the package.json
|
|
@@ -1418,7 +1241,7 @@ const lsByAgent = (() => {
|
|
|
1418
1241
|
async function npmQuery(npmExecPath, cwd) {
|
|
1419
1242
|
let stdout = '';
|
|
1420
1243
|
try {
|
|
1421
|
-
stdout = (await
|
|
1244
|
+
stdout = (await spawn(npmExecPath, ['query', ':not(.dev)'], {
|
|
1422
1245
|
cwd
|
|
1423
1246
|
})).stdout;
|
|
1424
1247
|
} catch {}
|
|
@@ -1429,7 +1252,7 @@ const lsByAgent = (() => {
|
|
|
1429
1252
|
try {
|
|
1430
1253
|
// Bun does not support filtering by production packages yet.
|
|
1431
1254
|
// https://github.com/oven-sh/bun/issues/8283
|
|
1432
|
-
return (await
|
|
1255
|
+
return (await spawn(agentExecPath, ['pm', 'ls', '--all'], {
|
|
1433
1256
|
cwd
|
|
1434
1257
|
})).stdout;
|
|
1435
1258
|
} catch {}
|
|
@@ -1453,7 +1276,7 @@ const lsByAgent = (() => {
|
|
|
1453
1276
|
}
|
|
1454
1277
|
let stdout = '';
|
|
1455
1278
|
try {
|
|
1456
|
-
stdout = (await
|
|
1279
|
+
stdout = (await spawn(agentExecPath, ['ls', '--parseable', '--prod', '--depth', 'Infinity'], {
|
|
1457
1280
|
cwd
|
|
1458
1281
|
})).stdout;
|
|
1459
1282
|
} catch {}
|
|
@@ -1462,7 +1285,7 @@ const lsByAgent = (() => {
|
|
|
1462
1285
|
async vlt(agentExecPath, cwd) {
|
|
1463
1286
|
let stdout = '';
|
|
1464
1287
|
try {
|
|
1465
|
-
stdout = (await
|
|
1288
|
+
stdout = (await spawn(agentExecPath, ['ls', '--view', 'human', ':not(.dev)'], {
|
|
1466
1289
|
cwd
|
|
1467
1290
|
})).stdout;
|
|
1468
1291
|
} catch {}
|
|
@@ -1473,7 +1296,7 @@ const lsByAgent = (() => {
|
|
|
1473
1296
|
return (
|
|
1474
1297
|
// Yarn Berry does not support filtering by production packages yet.
|
|
1475
1298
|
// https://github.com/yarnpkg/berry/issues/5117
|
|
1476
|
-
(await
|
|
1299
|
+
(await spawn(agentExecPath, ['info', '--recursive', '--name-only'], {
|
|
1477
1300
|
cwd
|
|
1478
1301
|
})).stdout.trim()
|
|
1479
1302
|
);
|
|
@@ -1486,7 +1309,7 @@ const lsByAgent = (() => {
|
|
|
1486
1309
|
// https://github.com/yarnpkg/yarn/releases/tag/v1.0.0
|
|
1487
1310
|
// > Fix: Excludes dev dependencies from the yarn list output when the
|
|
1488
1311
|
// environment is production
|
|
1489
|
-
return (await
|
|
1312
|
+
return (await spawn(agentExecPath, ['list', '--prod'], {
|
|
1490
1313
|
cwd
|
|
1491
1314
|
})).stdout.trim();
|
|
1492
1315
|
} catch {}
|
|
@@ -1511,7 +1334,7 @@ const depsIncludesByAgent = (() => {
|
|
|
1511
1334
|
};
|
|
1512
1335
|
})();
|
|
1513
1336
|
function createActionMessage(verb, overrideCount, workspaceCount) {
|
|
1514
|
-
return `${verb} ${overrideCount} Socket.dev optimized overrides${workspaceCount ? ` in ${workspaceCount} ${
|
|
1337
|
+
return `${verb} ${overrideCount} Socket.dev optimized overrides${workspaceCount ? ` in ${workspaceCount} ${words.pluralize('workspace', workspaceCount)}` : ''}`;
|
|
1515
1338
|
}
|
|
1516
1339
|
function getDependencyEntries(pkgJson) {
|
|
1517
1340
|
const {
|
|
@@ -1539,12 +1362,12 @@ function getDependencyEntries(pkgJson) {
|
|
|
1539
1362
|
async function getWorkspaceGlobs(agent, pkgPath, pkgJson) {
|
|
1540
1363
|
let workspacePatterns;
|
|
1541
1364
|
if (agent === 'pnpm') {
|
|
1542
|
-
for (const workspacePath of [
|
|
1543
|
-
if (
|
|
1365
|
+
for (const workspacePath of [path.join(pkgPath, `${PNPM_WORKSPACE}.yaml`), path.join(pkgPath, `${PNPM_WORKSPACE}.yml`)]) {
|
|
1366
|
+
if (existsSync(workspacePath)) {
|
|
1544
1367
|
try {
|
|
1545
|
-
workspacePatterns =
|
|
1368
|
+
workspacePatterns = yaml.parse(
|
|
1546
1369
|
// eslint-disable-next-line no-await-in-loop
|
|
1547
|
-
await
|
|
1370
|
+
await fs$1.readFile(workspacePath, 'utf8'))?.packages;
|
|
1548
1371
|
} catch {}
|
|
1549
1372
|
if (workspacePatterns) {
|
|
1550
1373
|
break;
|
|
@@ -1554,7 +1377,7 @@ async function getWorkspaceGlobs(agent, pkgPath, pkgJson) {
|
|
|
1554
1377
|
} else {
|
|
1555
1378
|
workspacePatterns = pkgJson['workspaces'];
|
|
1556
1379
|
}
|
|
1557
|
-
return Array.isArray(workspacePatterns) ? workspacePatterns.filter(
|
|
1380
|
+
return Array.isArray(workspacePatterns) ? workspacePatterns.filter(strings.isNonEmptyString).map(workspacePatternToGlobPattern) : undefined;
|
|
1558
1381
|
}
|
|
1559
1382
|
function workspacePatternToGlobPattern(workspace) {
|
|
1560
1383
|
const {
|
|
@@ -1598,7 +1421,7 @@ async function addOverrides({
|
|
|
1598
1421
|
rootPath
|
|
1599
1422
|
}, state = createAddOverridesState()) {
|
|
1600
1423
|
if (editablePkgJson === undefined) {
|
|
1601
|
-
editablePkgJson = await
|
|
1424
|
+
editablePkgJson = await packages.readPackageJson(pkgPath, {
|
|
1602
1425
|
editable: true
|
|
1603
1426
|
});
|
|
1604
1427
|
}
|
|
@@ -1610,7 +1433,7 @@ async function addOverrides({
|
|
|
1610
1433
|
} = editablePkgJson;
|
|
1611
1434
|
const isRoot = pkgPath === rootPath;
|
|
1612
1435
|
const isLockScanned = isRoot && !prod;
|
|
1613
|
-
const workspaceName =
|
|
1436
|
+
const workspaceName = path.relative(rootPath, pkgPath);
|
|
1614
1437
|
const workspaceGlobs = await getWorkspaceGlobs(agent, pkgPath, pkgJson);
|
|
1615
1438
|
const isWorkspace = !!workspaceGlobs;
|
|
1616
1439
|
if (isWorkspace && agent === 'pnpm' && npmExecPath === 'npm' && !state.warnedPnpmWorkspaceRequiresNpm) {
|
|
@@ -1633,7 +1456,7 @@ async function addOverrides({
|
|
|
1633
1456
|
}
|
|
1634
1457
|
const depAliasMap = new Map();
|
|
1635
1458
|
// Chunk package names to process them in parallel 3 at a time.
|
|
1636
|
-
await
|
|
1459
|
+
await promises.pEach(manifestEntries, 3, async ({
|
|
1637
1460
|
1: data
|
|
1638
1461
|
}) => {
|
|
1639
1462
|
const {
|
|
@@ -1641,7 +1464,7 @@ async function addOverrides({
|
|
|
1641
1464
|
package: origPkgName,
|
|
1642
1465
|
version
|
|
1643
1466
|
} = data;
|
|
1644
|
-
const major =
|
|
1467
|
+
const major = semver.major(version);
|
|
1645
1468
|
for (const {
|
|
1646
1469
|
1: depObj
|
|
1647
1470
|
} of depEntries) {
|
|
@@ -1651,7 +1474,7 @@ async function addOverrides({
|
|
|
1651
1474
|
// Add package aliases for direct dependencies to avoid npm EOVERRIDE errors.
|
|
1652
1475
|
// https://docs.npmjs.com/cli/v8/using-npm/package-spec#aliases
|
|
1653
1476
|
const regSpecStartsLike = `npm:${regPkgName}@`;
|
|
1654
|
-
const existingVersion = pkgSpec.startsWith(regSpecStartsLike) ?
|
|
1477
|
+
const existingVersion = pkgSpec.startsWith(regSpecStartsLike) ? semver.coerce(npa(pkgSpec).rawSpec)?.version ?? '' : '';
|
|
1655
1478
|
if (existingVersion) {
|
|
1656
1479
|
thisVersion = existingVersion;
|
|
1657
1480
|
} else {
|
|
@@ -1670,11 +1493,11 @@ async function addOverrides({
|
|
|
1670
1493
|
}
|
|
1671
1494
|
if (isRoot) {
|
|
1672
1495
|
// Chunk package names to process them in parallel 3 at a time.
|
|
1673
|
-
await
|
|
1496
|
+
await promises.pEach(overridesDataObjects, 3, async ({
|
|
1674
1497
|
overrides,
|
|
1675
1498
|
type
|
|
1676
1499
|
}) => {
|
|
1677
|
-
const overrideExists =
|
|
1500
|
+
const overrideExists = objects.hasOwn(overrides, origPkgName);
|
|
1678
1501
|
if (overrideExists || thingScanner(thingToScan, origPkgName)) {
|
|
1679
1502
|
const oldSpec = overrideExists ? overrides[origPkgName] : undefined;
|
|
1680
1503
|
const depAlias = depAliasMap.get(origPkgName);
|
|
@@ -1694,9 +1517,9 @@ async function addOverrides({
|
|
|
1694
1517
|
const thisSpec = oldSpec.startsWith('$') ? depAlias?.id ?? newSpec : oldSpec ?? newSpec;
|
|
1695
1518
|
if (thisSpec.startsWith(regSpecStartsLike)) {
|
|
1696
1519
|
if (pin) {
|
|
1697
|
-
thisVersion =
|
|
1520
|
+
thisVersion = semver.major(semver.coerce(npa(thisSpec).rawSpec)?.version ?? version) === major ? version : (await packages.fetchPackageManifest(thisSpec))?.version ?? version;
|
|
1698
1521
|
}
|
|
1699
|
-
newSpec = `${regSpecStartsLike}^${pin ? thisVersion :
|
|
1522
|
+
newSpec = `${regSpecStartsLike}^${pin ? thisVersion : semver.major(thisVersion)}`;
|
|
1700
1523
|
} else {
|
|
1701
1524
|
newSpec = oldSpec;
|
|
1702
1525
|
}
|
|
@@ -1715,13 +1538,13 @@ async function addOverrides({
|
|
|
1715
1538
|
}
|
|
1716
1539
|
});
|
|
1717
1540
|
if (workspaceGlobs) {
|
|
1718
|
-
const workspacePkgJsonPaths = await
|
|
1541
|
+
const workspacePkgJsonPaths = await tinyglobby.glob(workspaceGlobs, {
|
|
1719
1542
|
absolute: true,
|
|
1720
1543
|
cwd: pkgPath,
|
|
1721
1544
|
ignore: ['**/node_modules/**', '**/bower_components/**']
|
|
1722
1545
|
});
|
|
1723
1546
|
// Chunk package names to process them in parallel 3 at a time.
|
|
1724
|
-
await
|
|
1547
|
+
await promises.pEach(workspacePkgJsonPaths, 3, async workspacePkgJsonPath => {
|
|
1725
1548
|
const otherState = await addOverrides({
|
|
1726
1549
|
agent,
|
|
1727
1550
|
agentExecPath,
|
|
@@ -1729,7 +1552,7 @@ async function addOverrides({
|
|
|
1729
1552
|
manifestEntries,
|
|
1730
1553
|
npmExecPath,
|
|
1731
1554
|
pin,
|
|
1732
|
-
pkgPath:
|
|
1555
|
+
pkgPath: path.dirname(workspacePkgJsonPath),
|
|
1733
1556
|
prod,
|
|
1734
1557
|
rootPath
|
|
1735
1558
|
}, createAddOverridesState({
|
|
@@ -1748,13 +1571,13 @@ async function addOverrides({
|
|
|
1748
1571
|
overrides,
|
|
1749
1572
|
type
|
|
1750
1573
|
} of overridesDataObjects) {
|
|
1751
|
-
updateManifestByAgent[type](editablePkgJson,
|
|
1574
|
+
updateManifestByAgent[type](editablePkgJson, objects.toSortedObject(overrides));
|
|
1752
1575
|
}
|
|
1753
1576
|
await editablePkgJson.save();
|
|
1754
1577
|
}
|
|
1755
1578
|
return state;
|
|
1756
1579
|
}
|
|
1757
|
-
const optimize =
|
|
1580
|
+
const optimize = {
|
|
1758
1581
|
description: 'Optimize dependencies with @socketregistry overrides',
|
|
1759
1582
|
async run(argv, importMeta, {
|
|
1760
1583
|
parentName
|
|
@@ -1779,7 +1602,7 @@ const optimize = optimize$1.optimize = {
|
|
|
1779
1602
|
pkgJson,
|
|
1780
1603
|
pkgPath,
|
|
1781
1604
|
supported
|
|
1782
|
-
} = await
|
|
1605
|
+
} = await detect({
|
|
1783
1606
|
cwd,
|
|
1784
1607
|
onUnknown(pkgManager) {
|
|
1785
1608
|
console.warn(`⚠️ ${COMMAND_TITLE}: Unknown package manager${pkgManager ? ` ${pkgManager}` : ''}, defaulting to npm`);
|
|
@@ -1793,7 +1616,7 @@ const optimize = optimize$1.optimize = {
|
|
|
1793
1616
|
console.error(`✖️ ${COMMAND_TITLE}: ${agent} does not support overrides. Soon, though ⚡`);
|
|
1794
1617
|
return;
|
|
1795
1618
|
}
|
|
1796
|
-
const lockName = lockPath ?
|
|
1619
|
+
const lockName = lockPath ? path.basename(lockPath) : 'lock file';
|
|
1797
1620
|
if (lockSrc === undefined) {
|
|
1798
1621
|
console.error(`✖️ ${COMMAND_TITLE}: No ${lockName} found`);
|
|
1799
1622
|
return;
|
|
@@ -1810,10 +1633,10 @@ const optimize = optimize$1.optimize = {
|
|
|
1810
1633
|
console.error(`✖️ ${COMMAND_TITLE}: --prod not supported for ${agent}${agentVersion ? `@${agentVersion.toString()}` : ''}`);
|
|
1811
1634
|
return;
|
|
1812
1635
|
}
|
|
1813
|
-
if (lockPath &&
|
|
1636
|
+
if (lockPath && path.relative(cwd, lockPath).startsWith('.')) {
|
|
1814
1637
|
console.warn(`⚠️ ${COMMAND_TITLE}: Package ${lockName} found at ${lockPath}`);
|
|
1815
1638
|
}
|
|
1816
|
-
const spinner =
|
|
1639
|
+
const spinner = yoctoSpinner({
|
|
1817
1640
|
text: 'Socket optimizing...'
|
|
1818
1641
|
});
|
|
1819
1642
|
const state = createAddOverridesState({
|
|
@@ -1823,7 +1646,7 @@ const optimize = optimize$1.optimize = {
|
|
|
1823
1646
|
const nodeRange = `>=${minimumNodeVersion}`;
|
|
1824
1647
|
const manifestEntries = manifestNpmOverrides.filter(({
|
|
1825
1648
|
1: data
|
|
1826
|
-
}) =>
|
|
1649
|
+
}) => semver.satisfies(semver.coerce(data.engines.node), nodeRange));
|
|
1827
1650
|
await addOverrides({
|
|
1828
1651
|
agent,
|
|
1829
1652
|
agentExecPath,
|
|
@@ -1857,22 +1680,24 @@ const optimize = optimize$1.optimize = {
|
|
|
1857
1680
|
spinner.start(`Updating ${lockName}...`);
|
|
1858
1681
|
try {
|
|
1859
1682
|
if (isNpm) {
|
|
1860
|
-
const wrapperPath =
|
|
1683
|
+
const wrapperPath = path.join(rootBinPath, 'npm-cli.js');
|
|
1861
1684
|
const npmSpawnOptions = {
|
|
1685
|
+
signal: abortSignal$2,
|
|
1862
1686
|
stdio: 'ignore',
|
|
1863
1687
|
env: {
|
|
1864
1688
|
...process.env,
|
|
1865
1689
|
[UPDATE_SOCKET_OVERRIDES_IN_PACKAGE_LOCK_FILE]: '1'
|
|
1866
1690
|
}
|
|
1867
1691
|
};
|
|
1868
|
-
await
|
|
1692
|
+
await spawn(execPath, [wrapperPath, 'install', '--silent'], npmSpawnOptions);
|
|
1869
1693
|
// TODO: This is a temporary workaround for a `npm ci` bug where it
|
|
1870
1694
|
// will error out after Socket Optimize generates a lock file. More
|
|
1871
1695
|
// investigation is needed.
|
|
1872
|
-
await
|
|
1696
|
+
await spawn(execPath, [wrapperPath, 'install', '--silent', '--ignore-scripts', '--package-lock-only'], npmSpawnOptions);
|
|
1873
1697
|
} else {
|
|
1874
1698
|
// All package managers support the "install" command.
|
|
1875
|
-
await
|
|
1699
|
+
await spawn(agentExecPath, ['install'], {
|
|
1700
|
+
signal: abortSignal$2,
|
|
1876
1701
|
stdio: 'ignore'
|
|
1877
1702
|
});
|
|
1878
1703
|
}
|
|
@@ -1891,7 +1716,7 @@ const optimize = optimize$1.optimize = {
|
|
|
1891
1716
|
|
|
1892
1717
|
function setupCommand$l(name, description, argv, importMeta) {
|
|
1893
1718
|
const flags = {
|
|
1894
|
-
...
|
|
1719
|
+
...commonFlags,
|
|
1895
1720
|
pin: {
|
|
1896
1721
|
type: 'boolean',
|
|
1897
1722
|
default: false,
|
|
@@ -1903,12 +1728,12 @@ function setupCommand$l(name, description, argv, importMeta) {
|
|
|
1903
1728
|
description: 'Only add overrides for production dependencies'
|
|
1904
1729
|
}
|
|
1905
1730
|
};
|
|
1906
|
-
const cli =
|
|
1731
|
+
const cli = vendor.meow(`
|
|
1907
1732
|
Usage
|
|
1908
1733
|
$ ${name}
|
|
1909
1734
|
|
|
1910
1735
|
Options
|
|
1911
|
-
${
|
|
1736
|
+
${printFlagList(flags, 6)}
|
|
1912
1737
|
|
|
1913
1738
|
Examples
|
|
1914
1739
|
$ ${name}
|
|
@@ -1933,20 +1758,7 @@ function setupCommand$l(name, description, argv, importMeta) {
|
|
|
1933
1758
|
};
|
|
1934
1759
|
}
|
|
1935
1760
|
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
var _interopRequireDefault$m = vendor.interopRequireDefault.default;
|
|
1939
|
-
Object.defineProperty(organization, "__esModule", {
|
|
1940
|
-
value: true
|
|
1941
|
-
});
|
|
1942
|
-
organization.organizations = void 0;
|
|
1943
|
-
var _yoctocolorsCjs$g = require$$1$1;
|
|
1944
|
-
var _meow$l = _interopRequireDefault$m(vendor.build);
|
|
1945
|
-
var _yoctoSpinner$h = require$$3$1;
|
|
1946
|
-
var _apiHelpers$h = apiHelpers;
|
|
1947
|
-
var _errors$i = sdk.errors;
|
|
1948
|
-
var _sdk$h = sdk.sdk;
|
|
1949
|
-
const organizations = organization.organizations = {
|
|
1761
|
+
const organizations = {
|
|
1950
1762
|
description: 'List organizations associated with the API key used',
|
|
1951
1763
|
async run(argv, importMeta, {
|
|
1952
1764
|
parentName
|
|
@@ -1959,7 +1771,7 @@ const organizations = organization.organizations = {
|
|
|
1959
1771
|
// Internal functions
|
|
1960
1772
|
|
|
1961
1773
|
function setupCommand$k(name, description, argv, importMeta) {
|
|
1962
|
-
|
|
1774
|
+
vendor.meow(`
|
|
1963
1775
|
Usage
|
|
1964
1776
|
$ ${name}
|
|
1965
1777
|
`, {
|
|
@@ -1969,20 +1781,20 @@ function setupCommand$k(name, description, argv, importMeta) {
|
|
|
1969
1781
|
});
|
|
1970
1782
|
}
|
|
1971
1783
|
async function fetchOrganizations() {
|
|
1972
|
-
const apiKey =
|
|
1784
|
+
const apiKey = sdk.getDefaultKey();
|
|
1973
1785
|
if (!apiKey) {
|
|
1974
|
-
throw new
|
|
1786
|
+
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.');
|
|
1975
1787
|
}
|
|
1976
|
-
const spinner =
|
|
1788
|
+
const spinner = yoctoSpinner({
|
|
1977
1789
|
text: 'Fetching organizations...'
|
|
1978
1790
|
}).start();
|
|
1979
|
-
const socketSdk = await
|
|
1980
|
-
const result = await
|
|
1791
|
+
const socketSdk = await sdk.setupSdk(apiKey);
|
|
1792
|
+
const result = await handleApiCall(socketSdk.getOrganizations(), 'looking up organizations');
|
|
1981
1793
|
if (result.success === false) {
|
|
1982
|
-
|
|
1794
|
+
handleUnsuccessfulApiResponse('getOrganizations', result, spinner);
|
|
1983
1795
|
return;
|
|
1984
1796
|
}
|
|
1985
|
-
spinner.stop(`List of organizations associated with your API key: ${
|
|
1797
|
+
spinner.stop(`List of organizations associated with your API key: ${colors.italic(apiKey)}`);
|
|
1986
1798
|
const organizations = Object.values(result.data.organizations);
|
|
1987
1799
|
for (const o of organizations) {
|
|
1988
1800
|
console.log(`
|
|
@@ -1993,18 +1805,10 @@ Plan: ${o?.plan}
|
|
|
1993
1805
|
}
|
|
1994
1806
|
}
|
|
1995
1807
|
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
value: true
|
|
2001
|
-
});
|
|
2002
|
-
rawNpm$1.rawNpm = void 0;
|
|
2003
|
-
var _promiseSpawn$1 = require$$1$3;
|
|
2004
|
-
var _meow$k = _interopRequireDefault$l(vendor.build);
|
|
2005
|
-
var _flags$i = flags$1;
|
|
2006
|
-
var _formatting$j = formatting;
|
|
2007
|
-
const rawNpm = rawNpm$1.rawNpm = {
|
|
1808
|
+
const {
|
|
1809
|
+
abortSignal: abortSignal$1
|
|
1810
|
+
} = constants;
|
|
1811
|
+
const rawNpm = {
|
|
2008
1812
|
description: 'Temporarily disable the Socket npm wrapper',
|
|
2009
1813
|
async run(argv, importMeta, {
|
|
2010
1814
|
parentName
|
|
@@ -2014,15 +1818,15 @@ const rawNpm = rawNpm$1.rawNpm = {
|
|
|
2014
1818
|
};
|
|
2015
1819
|
async function setupCommand$j(name, description, argv, importMeta) {
|
|
2016
1820
|
const flags = {
|
|
2017
|
-
...
|
|
2018
|
-
...
|
|
1821
|
+
...commonFlags,
|
|
1822
|
+
...validationFlags
|
|
2019
1823
|
};
|
|
2020
|
-
const cli =
|
|
1824
|
+
const cli = vendor.meow(`
|
|
2021
1825
|
Usage
|
|
2022
1826
|
$ ${name} <npm command>
|
|
2023
1827
|
|
|
2024
1828
|
Options
|
|
2025
|
-
${
|
|
1829
|
+
${printFlagList(flags, 6)}
|
|
2026
1830
|
|
|
2027
1831
|
Examples
|
|
2028
1832
|
$ ${name} install
|
|
@@ -2040,7 +1844,8 @@ async function setupCommand$j(name, description, argv, importMeta) {
|
|
|
2040
1844
|
cli.showHelp();
|
|
2041
1845
|
return;
|
|
2042
1846
|
}
|
|
2043
|
-
const spawnPromise =
|
|
1847
|
+
const spawnPromise = spawn('npm', argv, {
|
|
1848
|
+
signal: abortSignal$1,
|
|
2044
1849
|
stdio: 'inherit'
|
|
2045
1850
|
});
|
|
2046
1851
|
spawnPromise.process.on('exit', (code, signal) => {
|
|
@@ -2053,18 +1858,10 @@ async function setupCommand$j(name, description, argv, importMeta) {
|
|
|
2053
1858
|
await spawnPromise;
|
|
2054
1859
|
}
|
|
2055
1860
|
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
value: true
|
|
2061
|
-
});
|
|
2062
|
-
rawNpx$1.rawNpx = void 0;
|
|
2063
|
-
var _promiseSpawn = require$$1$3;
|
|
2064
|
-
var _meow$j = _interopRequireDefault$k(vendor.build);
|
|
2065
|
-
var _flags$h = flags$1;
|
|
2066
|
-
var _formatting$i = formatting;
|
|
2067
|
-
const rawNpx = rawNpx$1.rawNpx = {
|
|
1861
|
+
const {
|
|
1862
|
+
abortSignal
|
|
1863
|
+
} = constants;
|
|
1864
|
+
const rawNpx = {
|
|
2068
1865
|
description: 'Temporarily disable the Socket npm/npx wrapper',
|
|
2069
1866
|
async run(argv, importMeta, {
|
|
2070
1867
|
parentName
|
|
@@ -2074,15 +1871,15 @@ const rawNpx = rawNpx$1.rawNpx = {
|
|
|
2074
1871
|
};
|
|
2075
1872
|
async function setupCommand$i(name, description, argv, importMeta) {
|
|
2076
1873
|
const flags = {
|
|
2077
|
-
...
|
|
2078
|
-
...
|
|
1874
|
+
...commonFlags,
|
|
1875
|
+
...validationFlags
|
|
2079
1876
|
};
|
|
2080
|
-
const cli =
|
|
1877
|
+
const cli = vendor.meow(`
|
|
2081
1878
|
Usage
|
|
2082
1879
|
$ ${name} <npx command>
|
|
2083
1880
|
|
|
2084
1881
|
Options
|
|
2085
|
-
${
|
|
1882
|
+
${printFlagList(flags, 6)}
|
|
2086
1883
|
|
|
2087
1884
|
Examples
|
|
2088
1885
|
$ ${name} install
|
|
@@ -2100,7 +1897,8 @@ async function setupCommand$i(name, description, argv, importMeta) {
|
|
|
2100
1897
|
cli.showHelp();
|
|
2101
1898
|
return;
|
|
2102
1899
|
}
|
|
2103
|
-
const spawnPromise =
|
|
1900
|
+
const spawnPromise = spawn('npx', [argv.join(' ')], {
|
|
1901
|
+
signal: abortSignal,
|
|
2104
1902
|
stdio: 'inherit'
|
|
2105
1903
|
});
|
|
2106
1904
|
spawnPromise.process.on('exit', (code, signal) => {
|
|
@@ -2113,37 +1911,13 @@ async function setupCommand$i(name, description, argv, importMeta) {
|
|
|
2113
1911
|
await spawnPromise;
|
|
2114
1912
|
}
|
|
2115
1913
|
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
var create$5 = {};
|
|
2119
|
-
|
|
2120
|
-
var view$3 = {};
|
|
2121
|
-
|
|
2122
|
-
var _interopRequireDefault$j = vendor.interopRequireDefault.default;
|
|
2123
|
-
Object.defineProperty(view$3, "__esModule", {
|
|
2124
|
-
value: true
|
|
2125
|
-
});
|
|
2126
|
-
view$3.fetchReportData = fetchReportData;
|
|
2127
|
-
view$3.formatReportDataOutput = formatReportDataOutput;
|
|
2128
|
-
view$3.view = void 0;
|
|
2129
|
-
var _yoctocolorsCjs$f = require$$1$1;
|
|
2130
|
-
var _meow$i = _interopRequireDefault$j(vendor.build);
|
|
2131
|
-
var _yoctoSpinner$g = require$$3$1;
|
|
2132
|
-
var _ponyCause$3 = require$$4$1;
|
|
2133
|
-
var _flags$g = flags$1;
|
|
2134
|
-
var _apiHelpers$g = apiHelpers;
|
|
2135
|
-
var _colorOrMarkdown$2 = sdk.colorOrMarkdown;
|
|
2136
|
-
var _errors$h = sdk.errors;
|
|
2137
|
-
var _formatIssues = formatIssues;
|
|
2138
|
-
var _formatting$h = formatting;
|
|
2139
|
-
var _sdk$g = sdk.sdk;
|
|
2140
|
-
const view$2 = view$3.view = {
|
|
1914
|
+
const view$1 = {
|
|
2141
1915
|
description: 'View a project report',
|
|
2142
1916
|
async run(argv, importMeta, {
|
|
2143
1917
|
parentName
|
|
2144
1918
|
}) {
|
|
2145
1919
|
const name = `${parentName} view`;
|
|
2146
|
-
const commandContext = setupCommand$h(name, view$
|
|
1920
|
+
const commandContext = setupCommand$h(name, view$1.description, argv, importMeta);
|
|
2147
1921
|
const result = commandContext ? await fetchReportData(commandContext.reportId, commandContext) : undefined;
|
|
2148
1922
|
if (result) {
|
|
2149
1923
|
formatReportDataOutput(result, {
|
|
@@ -2158,16 +1932,16 @@ const view$2 = view$3.view = {
|
|
|
2158
1932
|
|
|
2159
1933
|
function setupCommand$h(name, description, argv, importMeta) {
|
|
2160
1934
|
const flags = {
|
|
2161
|
-
...
|
|
2162
|
-
...
|
|
2163
|
-
...
|
|
1935
|
+
...commonFlags,
|
|
1936
|
+
...outputFlags,
|
|
1937
|
+
...validationFlags
|
|
2164
1938
|
};
|
|
2165
|
-
const cli =
|
|
1939
|
+
const cli = vendor.meow(`
|
|
2166
1940
|
Usage
|
|
2167
1941
|
$ ${name} <report-identifier>
|
|
2168
1942
|
|
|
2169
1943
|
Options
|
|
2170
|
-
${
|
|
1944
|
+
${printFlagList(flags, 6)}
|
|
2171
1945
|
|
|
2172
1946
|
Examples
|
|
2173
1947
|
$ ${name} QXU8PmK7LfH608RAwfIKdbcHgwEd_ZeWJ9QEGv05FJUQ
|
|
@@ -2189,7 +1963,7 @@ function setupCommand$h(name, description, argv, importMeta) {
|
|
|
2189
1963
|
}
|
|
2190
1964
|
// Validate the input.
|
|
2191
1965
|
if (extraInput.length) {
|
|
2192
|
-
throw new
|
|
1966
|
+
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(', ')}`);
|
|
2193
1967
|
}
|
|
2194
1968
|
return {
|
|
2195
1969
|
includeAllIssues: cli.flags['all'],
|
|
@@ -2205,23 +1979,23 @@ async function fetchReportData(reportId, {
|
|
|
2205
1979
|
strict
|
|
2206
1980
|
}) {
|
|
2207
1981
|
// Do the API call
|
|
2208
|
-
const socketSdk = await
|
|
2209
|
-
const spinner =
|
|
1982
|
+
const socketSdk = await sdk.setupSdk();
|
|
1983
|
+
const spinner = yoctoSpinner({
|
|
2210
1984
|
text: `Fetching report with ID ${reportId} (this could take a while)`
|
|
2211
1985
|
}).start();
|
|
2212
1986
|
let result;
|
|
2213
1987
|
for (let retry = 1; !result; ++retry) {
|
|
2214
1988
|
try {
|
|
2215
1989
|
// eslint-disable-next-line no-await-in-loop
|
|
2216
|
-
result = await
|
|
1990
|
+
result = await handleApiCall(socketSdk.getReport(reportId), 'fetching report');
|
|
2217
1991
|
} catch (err) {
|
|
2218
|
-
if (retry >= MAX_TIMEOUT_RETRY || !(err instanceof
|
|
1992
|
+
if (retry >= MAX_TIMEOUT_RETRY || !(err instanceof ponyCause.ErrorWithCause) || err.cause?.cause?.response?.statusCode !== 524) {
|
|
2219
1993
|
throw err;
|
|
2220
1994
|
}
|
|
2221
1995
|
}
|
|
2222
1996
|
}
|
|
2223
1997
|
if (result.success === false) {
|
|
2224
|
-
return
|
|
1998
|
+
return handleUnsuccessfulApiResponse('getReport', result, spinner);
|
|
2225
1999
|
}
|
|
2226
2000
|
|
|
2227
2001
|
// Conclude the status of the API call
|
|
@@ -2233,8 +2007,8 @@ async function fetchReportData(reportId, {
|
|
|
2233
2007
|
spinner.error('Report result deemed unhealthy for project');
|
|
2234
2008
|
}
|
|
2235
2009
|
} else if (result.data.healthy === false) {
|
|
2236
|
-
const severityCount =
|
|
2237
|
-
const issueSummary =
|
|
2010
|
+
const severityCount = getSeverityCount(result.data.issues, includeAllIssues ? undefined : 'high');
|
|
2011
|
+
const issueSummary = formatSeverityCount(severityCount);
|
|
2238
2012
|
spinner.success(`Report has these issues: ${issueSummary}`);
|
|
2239
2013
|
} else {
|
|
2240
2014
|
spinner.success('Report has no issues');
|
|
@@ -2251,12 +2025,12 @@ function formatReportDataOutput(data, {
|
|
|
2251
2025
|
if (outputJson) {
|
|
2252
2026
|
console.log(JSON.stringify(data, undefined, 2));
|
|
2253
2027
|
} else {
|
|
2254
|
-
const format = new
|
|
2028
|
+
const format = new sdk.ColorOrMarkdown(!!outputMarkdown);
|
|
2255
2029
|
console.log('\nDetailed info on socket.dev: ' + format.hyperlink(reportId, data.url, {
|
|
2256
2030
|
fallbackToUrl: true
|
|
2257
2031
|
}));
|
|
2258
2032
|
if (!outputMarkdown) {
|
|
2259
|
-
console.log(
|
|
2033
|
+
console.log(colors.dim(`\nOr rerun ${colors.italic(name)} using the ${colors.italic('--json')} flag to get full JSON output`));
|
|
2260
2034
|
}
|
|
2261
2035
|
}
|
|
2262
2036
|
if (strict && data.healthy === false) {
|
|
@@ -2264,33 +2038,13 @@ function formatReportDataOutput(data, {
|
|
|
2264
2038
|
}
|
|
2265
2039
|
}
|
|
2266
2040
|
|
|
2267
|
-
|
|
2268
|
-
Object.defineProperty(create$5, "__esModule", {
|
|
2269
|
-
value: true
|
|
2270
|
-
});
|
|
2271
|
-
create$5.create = void 0;
|
|
2272
|
-
var _nodePath = require$$1;
|
|
2273
|
-
var _betterAjvErrors = require$$2$1;
|
|
2274
|
-
var _meow$h = _interopRequireDefault$i(vendor.build);
|
|
2275
|
-
var _yoctoSpinner$f = require$$3$1;
|
|
2276
|
-
var _ponyCause$2 = require$$4$1;
|
|
2277
|
-
var _config = require$$6;
|
|
2278
|
-
var _view$2 = view$3;
|
|
2279
|
-
var _flags$f = flags$1;
|
|
2280
|
-
var _apiHelpers$f = apiHelpers;
|
|
2281
|
-
var _colorOrMarkdown$1 = sdk.colorOrMarkdown;
|
|
2282
|
-
var _errors$g = sdk.errors;
|
|
2283
|
-
var _formatting$g = formatting;
|
|
2284
|
-
var _misc$1 = sdk.misc;
|
|
2285
|
-
var _pathResolve$1 = pathResolve.pathResolve;
|
|
2286
|
-
var _sdk$f = sdk.sdk;
|
|
2287
|
-
const create$4 = create$5.create = {
|
|
2041
|
+
const create$2 = {
|
|
2288
2042
|
description: 'Create a project report',
|
|
2289
2043
|
async run(argv, importMeta, {
|
|
2290
2044
|
parentName
|
|
2291
2045
|
}) {
|
|
2292
2046
|
const name = `${parentName} create`;
|
|
2293
|
-
const input = await setupCommand$g(name, create$
|
|
2047
|
+
const input = await setupCommand$g(name, create$2.description, argv, importMeta);
|
|
2294
2048
|
if (input) {
|
|
2295
2049
|
const {
|
|
2296
2050
|
config,
|
|
@@ -2312,12 +2066,12 @@ const create$4 = create$5.create = {
|
|
|
2312
2066
|
}));
|
|
2313
2067
|
if (result && view) {
|
|
2314
2068
|
const reportId = result.data.id;
|
|
2315
|
-
const reportData = input && (await
|
|
2069
|
+
const reportData = input && (await fetchReportData(reportId, {
|
|
2316
2070
|
includeAllIssues,
|
|
2317
2071
|
strict
|
|
2318
2072
|
}));
|
|
2319
2073
|
if (reportData) {
|
|
2320
|
-
|
|
2074
|
+
formatReportDataOutput(reportData, {
|
|
2321
2075
|
includeAllIssues,
|
|
2322
2076
|
name,
|
|
2323
2077
|
outputJson,
|
|
@@ -2340,9 +2094,9 @@ const create$4 = create$5.create = {
|
|
|
2340
2094
|
|
|
2341
2095
|
async function setupCommand$g(name, description, argv, importMeta) {
|
|
2342
2096
|
const flags = {
|
|
2343
|
-
...
|
|
2344
|
-
...
|
|
2345
|
-
...
|
|
2097
|
+
...commonFlags,
|
|
2098
|
+
...outputFlags,
|
|
2099
|
+
...validationFlags,
|
|
2346
2100
|
debug: {
|
|
2347
2101
|
type: 'boolean',
|
|
2348
2102
|
shortFlag: 'd',
|
|
@@ -2361,7 +2115,7 @@ async function setupCommand$g(name, description, argv, importMeta) {
|
|
|
2361
2115
|
description: 'Will wait for and return the created report'
|
|
2362
2116
|
}
|
|
2363
2117
|
};
|
|
2364
|
-
const cli =
|
|
2118
|
+
const cli = vendor.meow(`
|
|
2365
2119
|
Usage
|
|
2366
2120
|
$ ${name} <paths-to-package-folders-and-files>
|
|
2367
2121
|
|
|
@@ -2375,7 +2129,7 @@ async function setupCommand$g(name, description, argv, importMeta) {
|
|
|
2375
2129
|
default ignores from the "ignore-by-default" module.
|
|
2376
2130
|
|
|
2377
2131
|
Options
|
|
2378
|
-
${
|
|
2132
|
+
${printFlagList({
|
|
2379
2133
|
all: 'Include all issues',
|
|
2380
2134
|
debug: 'Output debug information',
|
|
2381
2135
|
'dry-run': 'Only output what will be done without actually doing it',
|
|
@@ -2407,40 +2161,40 @@ async function setupCommand$g(name, description, argv, importMeta) {
|
|
|
2407
2161
|
const {
|
|
2408
2162
|
dryRun
|
|
2409
2163
|
} = cli.flags;
|
|
2410
|
-
const debugLog =
|
|
2164
|
+
const debugLog = sdk.createDebugLogger(!dryRun || cli.flags['debug']);
|
|
2411
2165
|
|
|
2412
2166
|
// TODO: Allow setting a custom cwd and/or configFile path?
|
|
2413
2167
|
const cwd = process.cwd();
|
|
2414
|
-
const absoluteConfigPath =
|
|
2415
|
-
const config = await
|
|
2416
|
-
if (cause && typeof cause === 'object' && cause instanceof
|
|
2168
|
+
const absoluteConfigPath = path.join(cwd, 'socket.yml');
|
|
2169
|
+
const config$1 = await config.readSocketConfig(absoluteConfigPath).catch(cause => {
|
|
2170
|
+
if (cause && typeof cause === 'object' && cause instanceof config.SocketValidationError) {
|
|
2417
2171
|
// Inspired by workbox-build:
|
|
2418
2172
|
// https://github.com/GoogleChrome/workbox/blob/95f97a207fd51efb3f8a653f6e3e58224183a778/packages/workbox-build/src/lib/validate-options.ts#L68-L71
|
|
2419
|
-
const betterErrors =
|
|
2173
|
+
const betterErrors = betterAjvErrors.betterAjvErrors({
|
|
2420
2174
|
basePath: 'config',
|
|
2421
2175
|
data: cause.data,
|
|
2422
2176
|
errors: cause.validationErrors,
|
|
2423
2177
|
schema: cause.schema
|
|
2424
2178
|
});
|
|
2425
|
-
throw new
|
|
2179
|
+
throw new sdk.InputError('The socket.yml config is not valid', betterErrors.map(err => `[${err.path}] ${err.message}.${err.suggestion ? err.suggestion : ''}`).join('\n'));
|
|
2426
2180
|
} else {
|
|
2427
|
-
throw new
|
|
2181
|
+
throw new ponyCause.ErrorWithCause('Failed to read socket.yml config', {
|
|
2428
2182
|
cause
|
|
2429
2183
|
});
|
|
2430
2184
|
}
|
|
2431
2185
|
});
|
|
2432
|
-
const socketSdk = await
|
|
2186
|
+
const socketSdk = await sdk.setupSdk();
|
|
2433
2187
|
const supportedFiles = await socketSdk.getReportSupportedFiles().then(res => {
|
|
2434
|
-
if (!res.success)
|
|
2188
|
+
if (!res.success) handleUnsuccessfulApiResponse('getReportSupportedFiles', res, yoctoSpinner());
|
|
2435
2189
|
return res.data;
|
|
2436
2190
|
}).catch(cause => {
|
|
2437
|
-
throw new
|
|
2191
|
+
throw new ponyCause.ErrorWithCause('Failed getting supported files for report', {
|
|
2438
2192
|
cause
|
|
2439
2193
|
});
|
|
2440
2194
|
});
|
|
2441
|
-
const packagePaths = await
|
|
2195
|
+
const packagePaths = await pathResolve.getPackageFiles(cwd, cli.input, config$1, supportedFiles, debugLog);
|
|
2442
2196
|
return {
|
|
2443
|
-
config,
|
|
2197
|
+
config: config$1,
|
|
2444
2198
|
cwd,
|
|
2445
2199
|
debugLog,
|
|
2446
2200
|
dryRun,
|
|
@@ -2458,21 +2212,21 @@ async function createReport(packagePaths, {
|
|
|
2458
2212
|
debugLog,
|
|
2459
2213
|
dryRun
|
|
2460
2214
|
}) {
|
|
2461
|
-
debugLog('Uploading:', packagePaths.join(`\n${
|
|
2215
|
+
debugLog('Uploading:', packagePaths.join(`\n${sdk.logSymbols.info} Uploading: `));
|
|
2462
2216
|
if (dryRun) {
|
|
2463
2217
|
return;
|
|
2464
2218
|
}
|
|
2465
|
-
const socketSdk = await
|
|
2466
|
-
const spinner =
|
|
2219
|
+
const socketSdk = await sdk.setupSdk();
|
|
2220
|
+
const spinner = yoctoSpinner({
|
|
2467
2221
|
text: `Creating report with ${packagePaths.length} package files`
|
|
2468
2222
|
}).start();
|
|
2469
2223
|
const apiCall = socketSdk.createReportFromFilePaths(packagePaths, cwd, config?.issueRules);
|
|
2470
|
-
const result = await
|
|
2224
|
+
const result = await handleApiCall(apiCall, 'creating report');
|
|
2471
2225
|
if (result.success) {
|
|
2472
2226
|
spinner.success();
|
|
2473
2227
|
return result;
|
|
2474
2228
|
}
|
|
2475
|
-
|
|
2229
|
+
handleUnsuccessfulApiResponse('createReport', result, spinner);
|
|
2476
2230
|
return undefined;
|
|
2477
2231
|
}
|
|
2478
2232
|
function formatReportCreationOutput(data, {
|
|
@@ -2483,23 +2237,12 @@ function formatReportCreationOutput(data, {
|
|
|
2483
2237
|
console.log(JSON.stringify(data, undefined, 2));
|
|
2484
2238
|
return;
|
|
2485
2239
|
}
|
|
2486
|
-
const format = new
|
|
2240
|
+
const format = new sdk.ColorOrMarkdown(!!outputMarkdown);
|
|
2487
2241
|
console.log(`New report: ${format.hyperlink(data.id, data.url, {
|
|
2488
2242
|
fallbackToUrl: true
|
|
2489
2243
|
})}`);
|
|
2490
2244
|
}
|
|
2491
2245
|
|
|
2492
|
-
var meowWithSubcommands$1 = {};
|
|
2493
|
-
|
|
2494
|
-
var _interopRequireDefault$h = vendor.interopRequireDefault.default;
|
|
2495
|
-
Object.defineProperty(meowWithSubcommands$1, "__esModule", {
|
|
2496
|
-
value: true
|
|
2497
|
-
});
|
|
2498
|
-
meowWithSubcommands$1.meowWithSubcommands = meowWithSubcommands;
|
|
2499
|
-
var _meow$g = _interopRequireDefault$h(vendor.build);
|
|
2500
|
-
var _objects = require$$7;
|
|
2501
|
-
var _formatting$f = formatting;
|
|
2502
|
-
var _flags$e = flags$1;
|
|
2503
2246
|
async function meowWithSubcommands(subcommands, options) {
|
|
2504
2247
|
const {
|
|
2505
2248
|
aliases = {},
|
|
@@ -2527,22 +2270,22 @@ async function meowWithSubcommands(subcommands, options) {
|
|
|
2527
2270
|
}
|
|
2528
2271
|
}
|
|
2529
2272
|
const flags = {
|
|
2530
|
-
...
|
|
2273
|
+
...commonFlags,
|
|
2531
2274
|
...additionalOptions.flags
|
|
2532
2275
|
};
|
|
2533
2276
|
// ...else we provide basic instructions and help
|
|
2534
|
-
const cli =
|
|
2277
|
+
const cli = vendor.meow(`
|
|
2535
2278
|
Usage
|
|
2536
2279
|
$ ${name} <command>
|
|
2537
2280
|
|
|
2538
2281
|
Commands
|
|
2539
|
-
${
|
|
2540
|
-
...
|
|
2541
|
-
...
|
|
2282
|
+
${printHelpList({
|
|
2283
|
+
...objects.toSortedObject(subcommands),
|
|
2284
|
+
...objects.toSortedObject(aliases)
|
|
2542
2285
|
}, 6)}
|
|
2543
2286
|
|
|
2544
2287
|
Options
|
|
2545
|
-
${
|
|
2288
|
+
${printFlagList(flags, 6)}
|
|
2546
2289
|
|
|
2547
2290
|
Examples
|
|
2548
2291
|
$ ${name} --help
|
|
@@ -2555,22 +2298,15 @@ async function meowWithSubcommands(subcommands, options) {
|
|
|
2555
2298
|
cli.showHelp();
|
|
2556
2299
|
}
|
|
2557
2300
|
|
|
2558
|
-
Object.defineProperty(report, "__esModule", {
|
|
2559
|
-
value: true
|
|
2560
|
-
});
|
|
2561
|
-
report.report = void 0;
|
|
2562
|
-
var _create$2 = create$5;
|
|
2563
|
-
var _view$1 = view$3;
|
|
2564
|
-
var _meowWithSubcommands$4 = meowWithSubcommands$1;
|
|
2565
2301
|
const description$3 = '[Deprecated] Project report related commands';
|
|
2566
|
-
report
|
|
2302
|
+
const report = {
|
|
2567
2303
|
description: description$3,
|
|
2568
2304
|
async run(argv, importMeta, {
|
|
2569
2305
|
parentName
|
|
2570
2306
|
}) {
|
|
2571
|
-
await
|
|
2572
|
-
create:
|
|
2573
|
-
view:
|
|
2307
|
+
await meowWithSubcommands({
|
|
2308
|
+
create: create$2,
|
|
2309
|
+
view: view$1
|
|
2574
2310
|
}, {
|
|
2575
2311
|
argv,
|
|
2576
2312
|
description: description$3,
|
|
@@ -2580,22 +2316,9 @@ report.report = {
|
|
|
2580
2316
|
}
|
|
2581
2317
|
};
|
|
2582
2318
|
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
Object.defineProperty(wrapper$1, "__esModule", {
|
|
2587
|
-
value: true
|
|
2588
|
-
});
|
|
2589
|
-
wrapper$1.wrapper = void 0;
|
|
2590
|
-
var _nodeFs$1 = require$$0;
|
|
2591
|
-
var _nodeOs = require$$1$5;
|
|
2592
|
-
var _nodeReadline = require$$3$4;
|
|
2593
|
-
var _meow$f = _interopRequireDefault$g(vendor.build);
|
|
2594
|
-
var _flags$d = flags$1;
|
|
2595
|
-
var _formatting$e = formatting;
|
|
2596
|
-
const BASH_FILE = `${_nodeOs.homedir()}/.bashrc`;
|
|
2597
|
-
const ZSH_BASH_FILE = `${_nodeOs.homedir()}/.zshrc`;
|
|
2598
|
-
const wrapper = wrapper$1.wrapper = {
|
|
2319
|
+
const BASH_FILE = `${os.homedir()}/.bashrc`;
|
|
2320
|
+
const ZSH_BASH_FILE = `${os.homedir()}/.zshrc`;
|
|
2321
|
+
const wrapper = {
|
|
2599
2322
|
description: 'Enable or disable the Socket npm/npx wrapper',
|
|
2600
2323
|
async run(argv, importMeta, {
|
|
2601
2324
|
parentName
|
|
@@ -2604,13 +2327,13 @@ const wrapper = wrapper$1.wrapper = {
|
|
|
2604
2327
|
}
|
|
2605
2328
|
};
|
|
2606
2329
|
function setupCommand$f(name, description, argv, importMeta) {
|
|
2607
|
-
const flags =
|
|
2608
|
-
const cli =
|
|
2330
|
+
const flags = commandFlags;
|
|
2331
|
+
const cli = vendor.meow(`
|
|
2609
2332
|
Usage
|
|
2610
2333
|
$ ${name} <flag>
|
|
2611
2334
|
|
|
2612
2335
|
Options
|
|
2613
|
-
${
|
|
2336
|
+
${printFlagList(flags, 6)}
|
|
2614
2337
|
|
|
2615
2338
|
Examples
|
|
2616
2339
|
$ ${name} --enable
|
|
@@ -2622,7 +2345,7 @@ function setupCommand$f(name, description, argv, importMeta) {
|
|
|
2622
2345
|
flags
|
|
2623
2346
|
});
|
|
2624
2347
|
if (argv[0] === '--postinstall') {
|
|
2625
|
-
const socketWrapperEnabled =
|
|
2348
|
+
const socketWrapperEnabled = fs.existsSync(BASH_FILE) && checkSocketWrapperAlreadySetup(BASH_FILE) || fs.existsSync(ZSH_BASH_FILE) && checkSocketWrapperAlreadySetup(ZSH_BASH_FILE);
|
|
2626
2349
|
if (!socketWrapperEnabled) {
|
|
2627
2350
|
installSafeNpm(`The Socket CLI is now successfully installed! 🎉
|
|
2628
2351
|
|
|
@@ -2645,23 +2368,23 @@ function setupCommand$f(name, description, argv, importMeta) {
|
|
|
2645
2368
|
return;
|
|
2646
2369
|
}
|
|
2647
2370
|
if (enable) {
|
|
2648
|
-
if (
|
|
2371
|
+
if (fs.existsSync(BASH_FILE)) {
|
|
2649
2372
|
const socketWrapperEnabled = checkSocketWrapperAlreadySetup(BASH_FILE);
|
|
2650
2373
|
!socketWrapperEnabled && addAlias(BASH_FILE);
|
|
2651
2374
|
}
|
|
2652
|
-
if (
|
|
2375
|
+
if (fs.existsSync(ZSH_BASH_FILE)) {
|
|
2653
2376
|
const socketWrapperEnabled = checkSocketWrapperAlreadySetup(ZSH_BASH_FILE);
|
|
2654
2377
|
!socketWrapperEnabled && addAlias(ZSH_BASH_FILE);
|
|
2655
2378
|
}
|
|
2656
2379
|
} else if (disable) {
|
|
2657
|
-
if (
|
|
2380
|
+
if (fs.existsSync(BASH_FILE)) {
|
|
2658
2381
|
removeAlias(BASH_FILE);
|
|
2659
2382
|
}
|
|
2660
|
-
if (
|
|
2383
|
+
if (fs.existsSync(ZSH_BASH_FILE)) {
|
|
2661
2384
|
removeAlias(ZSH_BASH_FILE);
|
|
2662
2385
|
}
|
|
2663
2386
|
}
|
|
2664
|
-
if (!
|
|
2387
|
+
if (!fs.existsSync(BASH_FILE) && !fs.existsSync(ZSH_BASH_FILE)) {
|
|
2665
2388
|
console.error('There was an issue setting up the alias in your bash profile');
|
|
2666
2389
|
}
|
|
2667
2390
|
}
|
|
@@ -2673,7 +2396,7 @@ const installSafeNpm = query => {
|
|
|
2673
2396
|
|_____|___|___|_,_|___|_|
|
|
2674
2397
|
|
|
2675
2398
|
`);
|
|
2676
|
-
const rl =
|
|
2399
|
+
const rl = readline.createInterface({
|
|
2677
2400
|
input: process.stdin,
|
|
2678
2401
|
output: process.stdout
|
|
2679
2402
|
});
|
|
@@ -2683,10 +2406,10 @@ const askQuestion = (rl, query) => {
|
|
|
2683
2406
|
rl.question(query, ans => {
|
|
2684
2407
|
if (ans.toLowerCase() === 'y') {
|
|
2685
2408
|
try {
|
|
2686
|
-
if (
|
|
2409
|
+
if (fs.existsSync(BASH_FILE)) {
|
|
2687
2410
|
addAlias(BASH_FILE);
|
|
2688
2411
|
}
|
|
2689
|
-
if (
|
|
2412
|
+
if (fs.existsSync(ZSH_BASH_FILE)) {
|
|
2690
2413
|
addAlias(ZSH_BASH_FILE);
|
|
2691
2414
|
}
|
|
2692
2415
|
} catch (e) {
|
|
@@ -2701,7 +2424,7 @@ const askQuestion = (rl, query) => {
|
|
|
2701
2424
|
});
|
|
2702
2425
|
};
|
|
2703
2426
|
const addAlias = file => {
|
|
2704
|
-
return
|
|
2427
|
+
return fs.appendFile(file, 'alias npm="socket npm"\nalias npx="socket npx"\n', err => {
|
|
2705
2428
|
if (err) {
|
|
2706
2429
|
return new Error(`There was an error setting up the alias: ${err}`);
|
|
2707
2430
|
}
|
|
@@ -2712,14 +2435,14 @@ If you want to disable it at any time, run \`socket wrapper --disable\`
|
|
|
2712
2435
|
});
|
|
2713
2436
|
};
|
|
2714
2437
|
const removeAlias = file => {
|
|
2715
|
-
return
|
|
2438
|
+
return fs.readFile(file, 'utf8', function (err, data) {
|
|
2716
2439
|
if (err) {
|
|
2717
2440
|
console.error(`There was an error removing the alias: ${err}`);
|
|
2718
2441
|
return;
|
|
2719
2442
|
}
|
|
2720
2443
|
const linesWithoutSocketAlias = data.split('\n').filter(l => l !== 'alias npm="socket npm"' && l !== 'alias npx="socket npx"');
|
|
2721
2444
|
const updatedFileContent = linesWithoutSocketAlias.join('\n');
|
|
2722
|
-
|
|
2445
|
+
fs.writeFile(file, updatedFileContent, function (err) {
|
|
2723
2446
|
if (err) {
|
|
2724
2447
|
console.log(err);
|
|
2725
2448
|
return;
|
|
@@ -2730,7 +2453,7 @@ const removeAlias = file => {
|
|
|
2730
2453
|
});
|
|
2731
2454
|
};
|
|
2732
2455
|
const checkSocketWrapperAlreadySetup = file => {
|
|
2733
|
-
const fileContent =
|
|
2456
|
+
const fileContent = fs.readFileSync(file, 'utf8');
|
|
2734
2457
|
const linesWithSocketAlias = fileContent.split('\n').filter(l => l === 'alias npm="socket npm"' || l === 'alias npx="socket npx"');
|
|
2735
2458
|
if (linesWithSocketAlias.length) {
|
|
2736
2459
|
console.log(`The Socket npm/npx wrapper is set up in your bash profile (${file}).`);
|
|
@@ -2739,42 +2462,20 @@ const checkSocketWrapperAlreadySetup = file => {
|
|
|
2739
2462
|
return false;
|
|
2740
2463
|
};
|
|
2741
2464
|
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
var create$3 = {};
|
|
2745
|
-
|
|
2746
|
-
var _interopRequireDefault$f = vendor.interopRequireDefault.default;
|
|
2747
|
-
Object.defineProperty(create$3, "__esModule", {
|
|
2748
|
-
value: true
|
|
2749
|
-
});
|
|
2750
|
-
create$3.create = void 0;
|
|
2751
|
-
var _nodeProcess = require$$0$1;
|
|
2752
|
-
var _promises$1 = require$$2$2;
|
|
2753
|
-
var _yoctocolorsCjs$e = require$$1$1;
|
|
2754
|
-
var _meow$e = _interopRequireDefault$f(vendor.build);
|
|
2755
|
-
var _open = _interopRequireDefault$f(vendor.open);
|
|
2756
|
-
var _yoctoSpinner$e = require$$3$1;
|
|
2757
|
-
var _ponyCause$1 = require$$4$1;
|
|
2758
|
-
var _apiHelpers$e = apiHelpers;
|
|
2759
|
-
var _errors$f = sdk.errors;
|
|
2760
|
-
var _formatting$d = formatting;
|
|
2761
|
-
var _misc = sdk.misc;
|
|
2762
|
-
var _pathResolve = pathResolve.pathResolve;
|
|
2763
|
-
var _sdk$e = sdk.sdk;
|
|
2764
|
-
const create$2 = create$3.create = {
|
|
2465
|
+
const create$1 = {
|
|
2765
2466
|
description: 'Create a scan',
|
|
2766
2467
|
async run(argv, importMeta, {
|
|
2767
2468
|
parentName
|
|
2768
2469
|
}) {
|
|
2769
2470
|
const name = `${parentName} create`;
|
|
2770
|
-
const input = await setupCommand$e(name, create$
|
|
2471
|
+
const input = await setupCommand$e(name, create$1.description, argv, importMeta);
|
|
2771
2472
|
if (input) {
|
|
2772
|
-
const apiKey =
|
|
2473
|
+
const apiKey = sdk.getDefaultKey();
|
|
2773
2474
|
if (!apiKey) {
|
|
2774
|
-
throw new
|
|
2475
|
+
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.');
|
|
2775
2476
|
}
|
|
2776
2477
|
const spinnerText = 'Creating a scan... \n';
|
|
2777
|
-
const spinner =
|
|
2478
|
+
const spinner = yoctoSpinner({
|
|
2778
2479
|
text: spinnerText
|
|
2779
2480
|
}).start();
|
|
2780
2481
|
await createFullScan(input, spinner, apiKey);
|
|
@@ -2843,12 +2544,12 @@ async function setupCommand$e(name, description, argv, importMeta) {
|
|
|
2843
2544
|
const flags = {
|
|
2844
2545
|
...createFullScanFlags
|
|
2845
2546
|
};
|
|
2846
|
-
const cli =
|
|
2547
|
+
const cli = vendor.meow(`
|
|
2847
2548
|
Usage
|
|
2848
2549
|
$ ${name} [...options]
|
|
2849
2550
|
|
|
2850
2551
|
Options
|
|
2851
|
-
${
|
|
2552
|
+
${printFlagList(flags, 6)}
|
|
2852
2553
|
|
|
2853
2554
|
Examples
|
|
2854
2555
|
$ ${name} --org=FakeOrg --repo=test-repo --branch=main ./package.json
|
|
@@ -2870,25 +2571,25 @@ async function setupCommand$e(name, description, argv, importMeta) {
|
|
|
2870
2571
|
0: orgSlug = ''
|
|
2871
2572
|
} = cli.input;
|
|
2872
2573
|
const cwd = process.cwd();
|
|
2873
|
-
const socketSdk = await
|
|
2574
|
+
const socketSdk = await sdk.setupSdk();
|
|
2874
2575
|
const supportedFiles = await socketSdk.getReportSupportedFiles().then(res => {
|
|
2875
|
-
if (!res.success)
|
|
2576
|
+
if (!res.success) handleUnsuccessfulApiResponse('getReportSupportedFiles', res, yoctoSpinner());
|
|
2876
2577
|
return res.data;
|
|
2877
2578
|
}).catch(/** @type {(cause: Error) => never} */
|
|
2878
2579
|
cause => {
|
|
2879
|
-
throw new
|
|
2580
|
+
throw new ponyCause.ErrorWithCause('Failed getting supported files for report', {
|
|
2880
2581
|
cause
|
|
2881
2582
|
});
|
|
2882
2583
|
});
|
|
2883
|
-
const debugLog =
|
|
2884
|
-
const packagePaths = await
|
|
2584
|
+
const debugLog = sdk.createDebugLogger(false);
|
|
2585
|
+
const packagePaths = await pathResolve.getPackageFilesFullScans(cwd, cli.input, supportedFiles, debugLog);
|
|
2885
2586
|
const {
|
|
2886
2587
|
branch: branchName,
|
|
2887
2588
|
repo: repoName
|
|
2888
2589
|
} = cli.flags;
|
|
2889
2590
|
if (!repoName || !branchName || !packagePaths.length) {
|
|
2890
2591
|
showHelp = true;
|
|
2891
|
-
console.error(`${
|
|
2592
|
+
console.error(`${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:\n
|
|
2892
2593
|
- Repository name using --repo\n
|
|
2893
2594
|
- Branch name using --branch\n
|
|
2894
2595
|
- At least one file path (e.g. ./package.json)`);
|
|
@@ -2912,7 +2613,7 @@ async function setupCommand$e(name, description, argv, importMeta) {
|
|
|
2912
2613
|
};
|
|
2913
2614
|
}
|
|
2914
2615
|
async function createFullScan(input, spinner, apiKey) {
|
|
2915
|
-
const socketSdk = await
|
|
2616
|
+
const socketSdk = await sdk.setupSdk(apiKey);
|
|
2916
2617
|
const {
|
|
2917
2618
|
branchName,
|
|
2918
2619
|
commitMessage,
|
|
@@ -2923,7 +2624,7 @@ async function createFullScan(input, spinner, apiKey) {
|
|
|
2923
2624
|
repoName,
|
|
2924
2625
|
tmp
|
|
2925
2626
|
} = input;
|
|
2926
|
-
const result = await
|
|
2627
|
+
const result = await handleApiCall(socketSdk.createOrgFullScan(orgSlug, {
|
|
2927
2628
|
repo: repoName,
|
|
2928
2629
|
branch: branchName,
|
|
2929
2630
|
commit_message: commitMessage,
|
|
@@ -2932,39 +2633,24 @@ async function createFullScan(input, spinner, apiKey) {
|
|
|
2932
2633
|
tmp
|
|
2933
2634
|
}, packagePaths), 'Creating scan');
|
|
2934
2635
|
if (!result.success) {
|
|
2935
|
-
|
|
2636
|
+
handleUnsuccessfulApiResponse('CreateOrgFullScan', result, spinner);
|
|
2936
2637
|
return;
|
|
2937
2638
|
}
|
|
2938
2639
|
spinner.success('Scan created successfully');
|
|
2939
|
-
const link =
|
|
2640
|
+
const link = colors.underline(colors.cyan(`${result.data.html_report_url}`));
|
|
2940
2641
|
console.log(`Available at: ${link}`);
|
|
2941
|
-
const rl =
|
|
2942
|
-
input:
|
|
2943
|
-
output:
|
|
2642
|
+
const rl = readline$1.createInterface({
|
|
2643
|
+
input: process$1.stdin,
|
|
2644
|
+
output: process$1.stdout
|
|
2944
2645
|
});
|
|
2945
2646
|
const answer = await rl.question('Would you like to open it in your browser? (y/n)');
|
|
2946
2647
|
if (answer.toLowerCase() === 'y') {
|
|
2947
|
-
await
|
|
2648
|
+
await vendor.open(`${result.data.html_report_url}`);
|
|
2948
2649
|
}
|
|
2949
2650
|
rl.close();
|
|
2950
2651
|
}
|
|
2951
2652
|
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
var _interopRequireDefault$e = vendor.interopRequireDefault.default;
|
|
2955
|
-
Object.defineProperty(_delete$3, "__esModule", {
|
|
2956
|
-
value: true
|
|
2957
|
-
});
|
|
2958
|
-
_delete$3.del = void 0;
|
|
2959
|
-
var _yoctocolorsCjs$d = require$$1$1;
|
|
2960
|
-
var _meow$d = _interopRequireDefault$e(vendor.build);
|
|
2961
|
-
var _yoctoSpinner$d = require$$3$1;
|
|
2962
|
-
var _flags$c = flags$1;
|
|
2963
|
-
var _apiHelpers$d = apiHelpers;
|
|
2964
|
-
var _errors$e = sdk.errors;
|
|
2965
|
-
var _formatting$c = formatting;
|
|
2966
|
-
var _sdk$d = sdk.sdk;
|
|
2967
|
-
const del$1 = _delete$3.del = {
|
|
2653
|
+
const del$1 = {
|
|
2968
2654
|
description: 'Delete a scan',
|
|
2969
2655
|
async run(argv, importMeta, {
|
|
2970
2656
|
parentName
|
|
@@ -2972,12 +2658,12 @@ const del$1 = _delete$3.del = {
|
|
|
2972
2658
|
const name = `${parentName} del`;
|
|
2973
2659
|
const input = setupCommand$d(name, del$1.description, argv, importMeta);
|
|
2974
2660
|
if (input) {
|
|
2975
|
-
const apiKey =
|
|
2661
|
+
const apiKey = sdk.getDefaultKey();
|
|
2976
2662
|
if (!apiKey) {
|
|
2977
|
-
throw new
|
|
2663
|
+
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.');
|
|
2978
2664
|
}
|
|
2979
2665
|
const spinnerText = 'Deleting scan...';
|
|
2980
|
-
const spinner =
|
|
2666
|
+
const spinner = yoctoSpinner({
|
|
2981
2667
|
text: spinnerText
|
|
2982
2668
|
}).start();
|
|
2983
2669
|
await deleteOrgFullScan(input.orgSlug, input.fullScanId, spinner, apiKey);
|
|
@@ -2989,15 +2675,15 @@ const del$1 = _delete$3.del = {
|
|
|
2989
2675
|
|
|
2990
2676
|
function setupCommand$d(name, description, argv, importMeta) {
|
|
2991
2677
|
const flags = {
|
|
2992
|
-
...
|
|
2993
|
-
...
|
|
2678
|
+
...commonFlags,
|
|
2679
|
+
...outputFlags
|
|
2994
2680
|
};
|
|
2995
|
-
const cli =
|
|
2681
|
+
const cli = vendor.meow(`
|
|
2996
2682
|
Usage
|
|
2997
2683
|
$ ${name} <org slug> <scan ID>
|
|
2998
2684
|
|
|
2999
2685
|
Options
|
|
3000
|
-
${
|
|
2686
|
+
${printFlagList(flags, 6)}
|
|
3001
2687
|
|
|
3002
2688
|
Examples
|
|
3003
2689
|
$ ${name} FakeOrg 000aaaa1-0000-0a0a-00a0-00a0000000a0
|
|
@@ -3010,7 +2696,7 @@ function setupCommand$d(name, description, argv, importMeta) {
|
|
|
3010
2696
|
let showHelp = cli.flags['help'];
|
|
3011
2697
|
if (cli.input.length < 2) {
|
|
3012
2698
|
showHelp = true;
|
|
3013
|
-
console.error(`${
|
|
2699
|
+
console.error(`${colors.bgRed(colors.white('Input error'))}: Please specify an organization slug and a scan ID.`);
|
|
3014
2700
|
}
|
|
3015
2701
|
if (showHelp) {
|
|
3016
2702
|
cli.showHelp();
|
|
@@ -3028,47 +2714,29 @@ function setupCommand$d(name, description, argv, importMeta) {
|
|
|
3028
2714
|
};
|
|
3029
2715
|
}
|
|
3030
2716
|
async function deleteOrgFullScan(orgSlug, fullScanId, spinner, apiKey) {
|
|
3031
|
-
const socketSdk = await
|
|
3032
|
-
const result = await
|
|
2717
|
+
const socketSdk = await sdk.setupSdk(apiKey);
|
|
2718
|
+
const result = await handleApiCall(socketSdk.deleteOrgFullScan(orgSlug, fullScanId), 'Deleting scan');
|
|
3033
2719
|
if (result.success) {
|
|
3034
2720
|
spinner.success('Scan deleted successfully');
|
|
3035
2721
|
} else {
|
|
3036
|
-
|
|
2722
|
+
handleUnsuccessfulApiResponse('deleteOrgFullScan', result, spinner);
|
|
3037
2723
|
}
|
|
3038
2724
|
}
|
|
3039
2725
|
|
|
3040
|
-
|
|
3041
|
-
|
|
3042
|
-
var _interopRequireDefault$d = vendor.interopRequireDefault.default;
|
|
3043
|
-
Object.defineProperty(list$3, "__esModule", {
|
|
3044
|
-
value: true
|
|
3045
|
-
});
|
|
3046
|
-
list$3.list = void 0;
|
|
3047
|
-
var _yoctocolorsCjs$c = require$$1$1;
|
|
3048
|
-
var _chalkTable$3 = require$$2$3;
|
|
3049
|
-
var _meow$c = _interopRequireDefault$d(vendor.build);
|
|
3050
|
-
var _yoctoSpinner$c = require$$3$1;
|
|
3051
|
-
var _flags$b = flags$1;
|
|
3052
|
-
var _apiHelpers$c = apiHelpers;
|
|
3053
|
-
var _errors$d = sdk.errors;
|
|
3054
|
-
var _formatting$b = formatting;
|
|
3055
|
-
var _sdk$c = sdk.sdk;
|
|
3056
|
-
// @ts-ignore
|
|
3057
|
-
|
|
3058
|
-
const list$2 = list$3.list = {
|
|
2726
|
+
const list$1 = {
|
|
3059
2727
|
description: 'List scans for an organization',
|
|
3060
2728
|
async run(argv, importMeta, {
|
|
3061
2729
|
parentName
|
|
3062
2730
|
}) {
|
|
3063
2731
|
const name = `${parentName} list`;
|
|
3064
|
-
const input = setupCommand$c(name, list$
|
|
2732
|
+
const input = setupCommand$c(name, list$1.description, argv, importMeta);
|
|
3065
2733
|
if (input) {
|
|
3066
|
-
const apiKey =
|
|
2734
|
+
const apiKey = sdk.getDefaultKey();
|
|
3067
2735
|
if (!apiKey) {
|
|
3068
|
-
throw new
|
|
2736
|
+
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.');
|
|
3069
2737
|
}
|
|
3070
2738
|
const spinnerText = 'Listing scans... \n';
|
|
3071
|
-
const spinner =
|
|
2739
|
+
const spinner = yoctoSpinner({
|
|
3072
2740
|
text: spinnerText
|
|
3073
2741
|
}).start();
|
|
3074
2742
|
await listOrgFullScan(input.orgSlug, input, spinner, apiKey);
|
|
@@ -3118,16 +2786,16 @@ const listFullScanFlags = {
|
|
|
3118
2786
|
|
|
3119
2787
|
function setupCommand$c(name, description, argv, importMeta) {
|
|
3120
2788
|
const flags = {
|
|
3121
|
-
...
|
|
2789
|
+
...commonFlags,
|
|
3122
2790
|
...listFullScanFlags,
|
|
3123
|
-
...
|
|
2791
|
+
...outputFlags
|
|
3124
2792
|
};
|
|
3125
|
-
const cli =
|
|
2793
|
+
const cli = vendor.meow(`
|
|
3126
2794
|
Usage
|
|
3127
2795
|
$ ${name} <org slug>
|
|
3128
2796
|
|
|
3129
2797
|
Options
|
|
3130
|
-
${
|
|
2798
|
+
${printFlagList(flags, 6)}
|
|
3131
2799
|
|
|
3132
2800
|
Examples
|
|
3133
2801
|
$ ${name} FakeOrg
|
|
@@ -3140,7 +2808,7 @@ function setupCommand$c(name, description, argv, importMeta) {
|
|
|
3140
2808
|
let showHelp = cli.flags['help'];
|
|
3141
2809
|
if (!cli.input[0]) {
|
|
3142
2810
|
showHelp = true;
|
|
3143
|
-
console.error(`${
|
|
2811
|
+
console.error(`${colors.bgRed(colors.white('Input error'))}: Please specify an organization slug.`);
|
|
3144
2812
|
}
|
|
3145
2813
|
if (showHelp) {
|
|
3146
2814
|
cli.showHelp();
|
|
@@ -3162,31 +2830,31 @@ function setupCommand$c(name, description, argv, importMeta) {
|
|
|
3162
2830
|
};
|
|
3163
2831
|
}
|
|
3164
2832
|
async function listOrgFullScan(orgSlug, input, spinner, apiKey) {
|
|
3165
|
-
const socketSdk = await
|
|
3166
|
-
const result = await
|
|
2833
|
+
const socketSdk = await sdk.setupSdk(apiKey);
|
|
2834
|
+
const result = await handleApiCall(socketSdk.getOrgFullScanList(orgSlug, input), 'Listing scans');
|
|
3167
2835
|
if (!result.success) {
|
|
3168
|
-
|
|
2836
|
+
handleUnsuccessfulApiResponse('getOrgFullScanList', result, spinner);
|
|
3169
2837
|
return;
|
|
3170
2838
|
}
|
|
3171
2839
|
const options = {
|
|
3172
2840
|
columns: [{
|
|
3173
2841
|
field: 'id',
|
|
3174
|
-
name:
|
|
2842
|
+
name: colors.magenta('ID')
|
|
3175
2843
|
}, {
|
|
3176
2844
|
field: 'report_url',
|
|
3177
|
-
name:
|
|
2845
|
+
name: colors.magenta('Scan URL')
|
|
3178
2846
|
}, {
|
|
3179
2847
|
field: 'branch',
|
|
3180
|
-
name:
|
|
2848
|
+
name: colors.magenta('Branch')
|
|
3181
2849
|
}, {
|
|
3182
2850
|
field: 'created_at',
|
|
3183
|
-
name:
|
|
2851
|
+
name: colors.magenta('Created at')
|
|
3184
2852
|
}]
|
|
3185
2853
|
};
|
|
3186
2854
|
const formattedResults = result.data.results.map(d => {
|
|
3187
2855
|
return {
|
|
3188
2856
|
id: d.id,
|
|
3189
|
-
report_url:
|
|
2857
|
+
report_url: colors.underline(`${d.html_report_url}`),
|
|
3190
2858
|
created_at: d.created_at ? new Date(d.created_at).toLocaleDateString('en-us', {
|
|
3191
2859
|
year: 'numeric',
|
|
3192
2860
|
month: 'numeric',
|
|
@@ -3196,25 +2864,10 @@ async function listOrgFullScan(orgSlug, input, spinner, apiKey) {
|
|
|
3196
2864
|
};
|
|
3197
2865
|
});
|
|
3198
2866
|
spinner.stop(`Listing scans for: ${orgSlug}`);
|
|
3199
|
-
console.log(
|
|
2867
|
+
console.log(chalkTable(options, formattedResults));
|
|
3200
2868
|
}
|
|
3201
2869
|
|
|
3202
|
-
|
|
3203
|
-
|
|
3204
|
-
var _interopRequireDefault$c = vendor.interopRequireDefault.default;
|
|
3205
|
-
Object.defineProperty(metadata$1, "__esModule", {
|
|
3206
|
-
value: true
|
|
3207
|
-
});
|
|
3208
|
-
metadata$1.metadata = void 0;
|
|
3209
|
-
var _yoctocolorsCjs$b = require$$1$1;
|
|
3210
|
-
var _meow$b = _interopRequireDefault$c(vendor.build);
|
|
3211
|
-
var _yoctoSpinner$b = require$$3$1;
|
|
3212
|
-
var _flags$a = flags$1;
|
|
3213
|
-
var _apiHelpers$b = apiHelpers;
|
|
3214
|
-
var _errors$c = sdk.errors;
|
|
3215
|
-
var _formatting$a = formatting;
|
|
3216
|
-
var _sdk$b = sdk.sdk;
|
|
3217
|
-
const metadata = metadata$1.metadata = {
|
|
2870
|
+
const metadata = {
|
|
3218
2871
|
description: "Get a scan's metadata",
|
|
3219
2872
|
async run(argv, importMeta, {
|
|
3220
2873
|
parentName
|
|
@@ -3222,12 +2875,12 @@ const metadata = metadata$1.metadata = {
|
|
|
3222
2875
|
const name = `${parentName} metadata`;
|
|
3223
2876
|
const input = setupCommand$b(name, metadata.description, argv, importMeta);
|
|
3224
2877
|
if (input) {
|
|
3225
|
-
const apiKey =
|
|
2878
|
+
const apiKey = sdk.getDefaultKey();
|
|
3226
2879
|
if (!apiKey) {
|
|
3227
|
-
throw new
|
|
2880
|
+
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.');
|
|
3228
2881
|
}
|
|
3229
2882
|
const spinnerText = "Getting scan's metadata... \n";
|
|
3230
|
-
const spinner =
|
|
2883
|
+
const spinner = yoctoSpinner({
|
|
3231
2884
|
text: spinnerText
|
|
3232
2885
|
}).start();
|
|
3233
2886
|
await getOrgScanMetadata(input.orgSlug, input.scanID, spinner, apiKey);
|
|
@@ -3239,15 +2892,15 @@ const metadata = metadata$1.metadata = {
|
|
|
3239
2892
|
|
|
3240
2893
|
function setupCommand$b(name, description, argv, importMeta) {
|
|
3241
2894
|
const flags = {
|
|
3242
|
-
...
|
|
3243
|
-
...
|
|
2895
|
+
...commonFlags,
|
|
2896
|
+
...outputFlags
|
|
3244
2897
|
};
|
|
3245
|
-
const cli =
|
|
2898
|
+
const cli = vendor.meow(`
|
|
3246
2899
|
Usage
|
|
3247
2900
|
$ ${name} <org slug> <scan id>
|
|
3248
2901
|
|
|
3249
2902
|
Options
|
|
3250
|
-
${
|
|
2903
|
+
${printFlagList(flags, 6)}
|
|
3251
2904
|
|
|
3252
2905
|
Examples
|
|
3253
2906
|
$ ${name} FakeOrg 000aaaa1-0000-0a0a-00a0-00a0000000a0
|
|
@@ -3260,7 +2913,7 @@ function setupCommand$b(name, description, argv, importMeta) {
|
|
|
3260
2913
|
let showHelp = cli.flags['help'];
|
|
3261
2914
|
if (cli.input.length < 2) {
|
|
3262
2915
|
showHelp = true;
|
|
3263
|
-
console.error(`${
|
|
2916
|
+
console.error(`${colors.bgRed(colors.white('Input error'))}: Please specify an organization slug and a scan ID.`);
|
|
3264
2917
|
}
|
|
3265
2918
|
if (showHelp) {
|
|
3266
2919
|
cli.showHelp();
|
|
@@ -3278,32 +2931,17 @@ function setupCommand$b(name, description, argv, importMeta) {
|
|
|
3278
2931
|
};
|
|
3279
2932
|
}
|
|
3280
2933
|
async function getOrgScanMetadata(orgSlug, scanId, spinner, apiKey) {
|
|
3281
|
-
const socketSdk = await
|
|
3282
|
-
const result = await
|
|
2934
|
+
const socketSdk = await sdk.setupSdk(apiKey);
|
|
2935
|
+
const result = await handleApiCall(socketSdk.getOrgFullScanMetadata(orgSlug, scanId), 'Listing scans');
|
|
3283
2936
|
if (!result.success) {
|
|
3284
|
-
|
|
2937
|
+
handleUnsuccessfulApiResponse('getOrgFullScanMetadata', result, spinner);
|
|
3285
2938
|
return;
|
|
3286
2939
|
}
|
|
3287
2940
|
spinner.stop('Scan metadata:');
|
|
3288
2941
|
console.log(result.data);
|
|
3289
2942
|
}
|
|
3290
2943
|
|
|
3291
|
-
|
|
3292
|
-
|
|
3293
|
-
var _interopRequireDefault$b = vendor.interopRequireDefault.default;
|
|
3294
|
-
Object.defineProperty(stream$1, "__esModule", {
|
|
3295
|
-
value: true
|
|
3296
|
-
});
|
|
3297
|
-
stream$1.stream = void 0;
|
|
3298
|
-
var _yoctocolorsCjs$a = require$$1$1;
|
|
3299
|
-
var _meow$a = _interopRequireDefault$b(vendor.build);
|
|
3300
|
-
var _yoctoSpinner$a = require$$3$1;
|
|
3301
|
-
var _flags$9 = flags$1;
|
|
3302
|
-
var _apiHelpers$a = apiHelpers;
|
|
3303
|
-
var _errors$b = sdk.errors;
|
|
3304
|
-
var _formatting$9 = formatting;
|
|
3305
|
-
var _sdk$a = sdk.sdk;
|
|
3306
|
-
const stream = stream$1.stream = {
|
|
2944
|
+
const stream = {
|
|
3307
2945
|
description: 'Stream the output of a scan',
|
|
3308
2946
|
async run(argv, importMeta, {
|
|
3309
2947
|
parentName
|
|
@@ -3311,18 +2949,18 @@ const stream = stream$1.stream = {
|
|
|
3311
2949
|
const name = `${parentName} stream`;
|
|
3312
2950
|
const input = setupCommand$a(name, stream.description, argv, importMeta);
|
|
3313
2951
|
if (input) {
|
|
3314
|
-
const apiKey =
|
|
2952
|
+
const apiKey = sdk.getDefaultKey();
|
|
3315
2953
|
if (!apiKey) {
|
|
3316
|
-
throw new
|
|
2954
|
+
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.');
|
|
3317
2955
|
}
|
|
3318
|
-
const spinner =
|
|
2956
|
+
const spinner = yoctoSpinner({
|
|
3319
2957
|
text: 'Streaming scan...'
|
|
3320
2958
|
}).start();
|
|
3321
2959
|
const result = await getOrgFullScan(input.orgSlug, input.fullScanId, input.file, apiKey);
|
|
3322
2960
|
if (result?.success) {
|
|
3323
2961
|
spinner.stop(input.file ? `Full scan details written to ${input.file}` : '');
|
|
3324
2962
|
} else {
|
|
3325
|
-
|
|
2963
|
+
handleUnsuccessfulApiResponse('getOrgFullScan', result, spinner);
|
|
3326
2964
|
}
|
|
3327
2965
|
}
|
|
3328
2966
|
}
|
|
@@ -3332,15 +2970,15 @@ const stream = stream$1.stream = {
|
|
|
3332
2970
|
|
|
3333
2971
|
function setupCommand$a(name, description, argv, importMeta) {
|
|
3334
2972
|
const flags = {
|
|
3335
|
-
...
|
|
3336
|
-
...
|
|
2973
|
+
...commonFlags,
|
|
2974
|
+
...outputFlags
|
|
3337
2975
|
};
|
|
3338
|
-
const cli =
|
|
2976
|
+
const cli = vendor.meow(`
|
|
3339
2977
|
Usage
|
|
3340
2978
|
$ ${name} <org slug> <scan ID> <path to output file>
|
|
3341
2979
|
|
|
3342
2980
|
Options
|
|
3343
|
-
${
|
|
2981
|
+
${printFlagList(flags, 6)}
|
|
3344
2982
|
|
|
3345
2983
|
Examples
|
|
3346
2984
|
$ ${name} FakeOrg 000aaaa1-0000-0a0a-00a0-00a0000000a0 ./stream.txt
|
|
@@ -3353,7 +2991,7 @@ function setupCommand$a(name, description, argv, importMeta) {
|
|
|
3353
2991
|
let showHelp = cli.flags['help'];
|
|
3354
2992
|
if (cli.input.length < 2) {
|
|
3355
2993
|
showHelp = true;
|
|
3356
|
-
console.error(`${
|
|
2994
|
+
console.error(`${colors.bgRed(colors.white('Input error'))}: Please specify an organization slug and a scan ID.`);
|
|
3357
2995
|
}
|
|
3358
2996
|
if (showHelp) {
|
|
3359
2997
|
cli.showHelp();
|
|
@@ -3373,32 +3011,22 @@ function setupCommand$a(name, description, argv, importMeta) {
|
|
|
3373
3011
|
};
|
|
3374
3012
|
}
|
|
3375
3013
|
async function getOrgFullScan(orgSlug, fullScanId, file, apiKey) {
|
|
3376
|
-
const socketSdk = await
|
|
3377
|
-
return await
|
|
3014
|
+
const socketSdk = await sdk.setupSdk(apiKey);
|
|
3015
|
+
return await handleApiCall(socketSdk.getOrgFullScan(orgSlug, fullScanId, file), 'Streaming a scan');
|
|
3378
3016
|
}
|
|
3379
3017
|
|
|
3380
|
-
Object.defineProperty(scan, "__esModule", {
|
|
3381
|
-
value: true
|
|
3382
|
-
});
|
|
3383
|
-
scan.scan = void 0;
|
|
3384
|
-
var _create$1 = create$3;
|
|
3385
|
-
var _delete$2 = _delete$3;
|
|
3386
|
-
var _list$1 = list$3;
|
|
3387
|
-
var _metadata = metadata$1;
|
|
3388
|
-
var _stream = stream$1;
|
|
3389
|
-
var _meowWithSubcommands$3 = meowWithSubcommands$1;
|
|
3390
3018
|
const description$2 = 'Scans related commands';
|
|
3391
|
-
scan
|
|
3019
|
+
const scan = {
|
|
3392
3020
|
description: description$2,
|
|
3393
3021
|
async run(argv, importMeta, {
|
|
3394
3022
|
parentName
|
|
3395
3023
|
}) {
|
|
3396
|
-
await
|
|
3397
|
-
create:
|
|
3398
|
-
stream
|
|
3399
|
-
list:
|
|
3400
|
-
del:
|
|
3401
|
-
metadata
|
|
3024
|
+
await meowWithSubcommands({
|
|
3025
|
+
create: create$1,
|
|
3026
|
+
stream,
|
|
3027
|
+
list: list$1,
|
|
3028
|
+
del: del$1,
|
|
3029
|
+
metadata
|
|
3402
3030
|
}, {
|
|
3403
3031
|
argv,
|
|
3404
3032
|
description: description$2,
|
|
@@ -3408,23 +3036,7 @@ scan.scan = {
|
|
|
3408
3036
|
}
|
|
3409
3037
|
};
|
|
3410
3038
|
|
|
3411
|
-
|
|
3412
|
-
|
|
3413
|
-
var _interopRequireDefault$a = vendor.interopRequireDefault.default;
|
|
3414
|
-
Object.defineProperty(auditLog$1, "__esModule", {
|
|
3415
|
-
value: true
|
|
3416
|
-
});
|
|
3417
|
-
auditLog$1.auditLog = void 0;
|
|
3418
|
-
var _prompts = require$$1$2;
|
|
3419
|
-
var _yoctocolorsCjs$9 = require$$1$1;
|
|
3420
|
-
var _meow$9 = _interopRequireDefault$a(vendor.build);
|
|
3421
|
-
var _yoctoSpinner$9 = require$$3$1;
|
|
3422
|
-
var _flags$8 = flags$1;
|
|
3423
|
-
var _apiHelpers$9 = apiHelpers;
|
|
3424
|
-
var _errors$a = sdk.errors;
|
|
3425
|
-
var _formatting$8 = formatting;
|
|
3426
|
-
var _sdk$9 = sdk.sdk;
|
|
3427
|
-
const auditLog = auditLog$1.auditLog = {
|
|
3039
|
+
const auditLog = {
|
|
3428
3040
|
description: 'Look up the audit log for an organization',
|
|
3429
3041
|
async run(argv, importMeta, {
|
|
3430
3042
|
parentName
|
|
@@ -3432,11 +3044,11 @@ const auditLog = auditLog$1.auditLog = {
|
|
|
3432
3044
|
const name = parentName + ' audit-log';
|
|
3433
3045
|
const input = setupCommand$9(name, auditLog.description, argv, importMeta);
|
|
3434
3046
|
if (input) {
|
|
3435
|
-
const apiKey =
|
|
3047
|
+
const apiKey = sdk.getDefaultKey();
|
|
3436
3048
|
if (!apiKey) {
|
|
3437
|
-
throw new
|
|
3049
|
+
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.');
|
|
3438
3050
|
}
|
|
3439
|
-
const spinner =
|
|
3051
|
+
const spinner = yoctoSpinner({
|
|
3440
3052
|
text: `Looking up audit log for ${input.orgSlug}\n`
|
|
3441
3053
|
}).start();
|
|
3442
3054
|
await fetchOrgAuditLog(input.orgSlug, input, spinner, apiKey);
|
|
@@ -3469,15 +3081,15 @@ const auditLogFlags = {
|
|
|
3469
3081
|
function setupCommand$9(name, description, argv, importMeta) {
|
|
3470
3082
|
const flags = {
|
|
3471
3083
|
...auditLogFlags,
|
|
3472
|
-
...
|
|
3473
|
-
...
|
|
3084
|
+
...commonFlags,
|
|
3085
|
+
...outputFlags
|
|
3474
3086
|
};
|
|
3475
|
-
const cli =
|
|
3087
|
+
const cli = vendor.meow(`
|
|
3476
3088
|
Usage
|
|
3477
3089
|
$ ${name} <org slug>
|
|
3478
3090
|
|
|
3479
3091
|
Options
|
|
3480
|
-
${
|
|
3092
|
+
${printFlagList(flags, 6)}
|
|
3481
3093
|
|
|
3482
3094
|
Examples
|
|
3483
3095
|
$ ${name} FakeOrg
|
|
@@ -3490,7 +3102,7 @@ function setupCommand$9(name, description, argv, importMeta) {
|
|
|
3490
3102
|
let showHelp = cli.flags['help'];
|
|
3491
3103
|
if (cli.input.length < 1) {
|
|
3492
3104
|
showHelp = true;
|
|
3493
|
-
console.error(`${
|
|
3105
|
+
console.error(`${colors.bgRed(colors.white('Input error'))}: Please provide an organization slug.`);
|
|
3494
3106
|
}
|
|
3495
3107
|
if (showHelp) {
|
|
3496
3108
|
cli.showHelp();
|
|
@@ -3516,10 +3128,10 @@ function setupCommand$9(name, description, argv, importMeta) {
|
|
|
3516
3128
|
};
|
|
3517
3129
|
}
|
|
3518
3130
|
async function fetchOrgAuditLog(orgSlug, input, spinner, apiKey) {
|
|
3519
|
-
const socketSdk = await
|
|
3520
|
-
const result = await
|
|
3131
|
+
const socketSdk = await sdk.setupSdk(apiKey);
|
|
3132
|
+
const result = await handleApiCall(socketSdk.getAuditLogEvents(orgSlug, input), `Looking up audit log for ${orgSlug}\n`);
|
|
3521
3133
|
if (!result.success) {
|
|
3522
|
-
|
|
3134
|
+
handleUnsuccessfulApiResponse('getAuditLogEvents', result, spinner);
|
|
3523
3135
|
return;
|
|
3524
3136
|
}
|
|
3525
3137
|
spinner.stop();
|
|
@@ -3537,35 +3149,18 @@ async function fetchOrgAuditLog(orgSlug, input, spinner, apiKey) {
|
|
|
3537
3149
|
})} - ${d.user_email} - ${d.type} - ${d.ip_address} - ${d.user_agent}`;
|
|
3538
3150
|
data.push({
|
|
3539
3151
|
name
|
|
3540
|
-
}, new
|
|
3152
|
+
}, new prompts.Separator());
|
|
3541
3153
|
logDetails[name] = JSON.stringify(d.payload);
|
|
3542
3154
|
}
|
|
3543
3155
|
}
|
|
3544
|
-
console.log(logDetails[await
|
|
3156
|
+
console.log(logDetails[await prompts.select({
|
|
3545
3157
|
message: input.type ? `\n Audit log for: ${orgSlug} with type: ${input.type}\n` : `\n Audit log for: ${orgSlug}\n`,
|
|
3546
3158
|
choices: data,
|
|
3547
3159
|
pageSize: 30
|
|
3548
3160
|
})]);
|
|
3549
3161
|
}
|
|
3550
3162
|
|
|
3551
|
-
|
|
3552
|
-
|
|
3553
|
-
var create$1 = {};
|
|
3554
|
-
|
|
3555
|
-
var _interopRequireDefault$9 = vendor.interopRequireDefault.default;
|
|
3556
|
-
Object.defineProperty(create$1, "__esModule", {
|
|
3557
|
-
value: true
|
|
3558
|
-
});
|
|
3559
|
-
create$1.create = void 0;
|
|
3560
|
-
var _yoctocolorsCjs$8 = require$$1$1;
|
|
3561
|
-
var _meow$8 = _interopRequireDefault$9(vendor.build);
|
|
3562
|
-
var _yoctoSpinner$8 = require$$3$1;
|
|
3563
|
-
var _flags$7 = flags$1;
|
|
3564
|
-
var _apiHelpers$8 = apiHelpers;
|
|
3565
|
-
var _errors$9 = sdk.errors;
|
|
3566
|
-
var _formatting$7 = formatting;
|
|
3567
|
-
var _sdk$8 = sdk.sdk;
|
|
3568
|
-
const create = create$1.create = {
|
|
3163
|
+
const create = {
|
|
3569
3164
|
description: 'Create a repository in an organization',
|
|
3570
3165
|
async run(argv, importMeta, {
|
|
3571
3166
|
parentName
|
|
@@ -3573,12 +3168,12 @@ const create = create$1.create = {
|
|
|
3573
3168
|
const name = `${parentName} create`;
|
|
3574
3169
|
const input = setupCommand$8(name, create.description, argv, importMeta);
|
|
3575
3170
|
if (input) {
|
|
3576
|
-
const apiKey =
|
|
3171
|
+
const apiKey = sdk.getDefaultKey();
|
|
3577
3172
|
if (!apiKey) {
|
|
3578
|
-
throw new
|
|
3173
|
+
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.');
|
|
3579
3174
|
}
|
|
3580
3175
|
const spinnerText = 'Creating repository... \n';
|
|
3581
|
-
const spinner =
|
|
3176
|
+
const spinner = yoctoSpinner({
|
|
3582
3177
|
text: spinnerText
|
|
3583
3178
|
}).start();
|
|
3584
3179
|
await createRepo(input.orgSlug, input, spinner, apiKey);
|
|
@@ -3622,16 +3217,16 @@ const repositoryCreationFlags = {
|
|
|
3622
3217
|
|
|
3623
3218
|
function setupCommand$8(name, description, argv, importMeta) {
|
|
3624
3219
|
const flags = {
|
|
3625
|
-
...
|
|
3626
|
-
...
|
|
3220
|
+
...commonFlags,
|
|
3221
|
+
...outputFlags,
|
|
3627
3222
|
...repositoryCreationFlags
|
|
3628
3223
|
};
|
|
3629
|
-
const cli =
|
|
3224
|
+
const cli = vendor.meow(`
|
|
3630
3225
|
Usage
|
|
3631
3226
|
$ ${name} <org slug>
|
|
3632
3227
|
|
|
3633
3228
|
Options
|
|
3634
|
-
${
|
|
3229
|
+
${printFlagList(flags, 6)}
|
|
3635
3230
|
|
|
3636
3231
|
Examples
|
|
3637
3232
|
$ ${name} FakeOrg --repoName=test-repo
|
|
@@ -3648,10 +3243,10 @@ function setupCommand$8(name, description, argv, importMeta) {
|
|
|
3648
3243
|
let showHelp = cli.flags['help'];
|
|
3649
3244
|
if (!orgSlug) {
|
|
3650
3245
|
showHelp = true;
|
|
3651
|
-
console.error(`${
|
|
3246
|
+
console.error(`${colors.bgRed(colors.white('Input error'))}: Please provide an organization slug.`);
|
|
3652
3247
|
} else if (!repoName) {
|
|
3653
3248
|
showHelp = true;
|
|
3654
|
-
console.error(`${
|
|
3249
|
+
console.error(`${colors.bgRed(colors.white('Input error'))}: Repository name is required.`);
|
|
3655
3250
|
}
|
|
3656
3251
|
if (showHelp) {
|
|
3657
3252
|
cli.showHelp();
|
|
@@ -3669,29 +3264,16 @@ function setupCommand$8(name, description, argv, importMeta) {
|
|
|
3669
3264
|
};
|
|
3670
3265
|
}
|
|
3671
3266
|
async function createRepo(orgSlug, input, spinner, apiKey) {
|
|
3672
|
-
const socketSdk = await
|
|
3673
|
-
const result = await
|
|
3267
|
+
const socketSdk = await sdk.setupSdk(apiKey);
|
|
3268
|
+
const result = await handleApiCall(socketSdk.createOrgRepo(orgSlug, input), 'creating repository');
|
|
3674
3269
|
if (result.success) {
|
|
3675
3270
|
spinner.success('Repository created successfully');
|
|
3676
3271
|
} else {
|
|
3677
|
-
|
|
3272
|
+
handleUnsuccessfulApiResponse('createOrgRepo', result, spinner);
|
|
3678
3273
|
}
|
|
3679
3274
|
}
|
|
3680
3275
|
|
|
3681
|
-
|
|
3682
|
-
|
|
3683
|
-
var _interopRequireDefault$8 = vendor.interopRequireDefault.default;
|
|
3684
|
-
Object.defineProperty(_delete$1, "__esModule", {
|
|
3685
|
-
value: true
|
|
3686
|
-
});
|
|
3687
|
-
_delete$1.del = void 0;
|
|
3688
|
-
var _yoctocolorsCjs$7 = require$$1$1;
|
|
3689
|
-
var _meow$7 = _interopRequireDefault$8(vendor.build);
|
|
3690
|
-
var _yoctoSpinner$7 = require$$3$1;
|
|
3691
|
-
var _apiHelpers$7 = apiHelpers;
|
|
3692
|
-
var _errors$8 = sdk.errors;
|
|
3693
|
-
var _sdk$7 = sdk.sdk;
|
|
3694
|
-
const del = _delete$1.del = {
|
|
3276
|
+
const del = {
|
|
3695
3277
|
description: 'Delete a repository in an organization',
|
|
3696
3278
|
async run(argv, importMeta, {
|
|
3697
3279
|
parentName
|
|
@@ -3699,12 +3281,12 @@ const del = _delete$1.del = {
|
|
|
3699
3281
|
const name = `${parentName} del`;
|
|
3700
3282
|
const input = setupCommand$7(name, del.description, argv, importMeta);
|
|
3701
3283
|
if (input) {
|
|
3702
|
-
const apiKey =
|
|
3284
|
+
const apiKey = sdk.getDefaultKey();
|
|
3703
3285
|
if (!apiKey) {
|
|
3704
|
-
throw new
|
|
3286
|
+
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.');
|
|
3705
3287
|
}
|
|
3706
3288
|
const spinnerText = 'Deleting repository... \n';
|
|
3707
|
-
const spinner =
|
|
3289
|
+
const spinner = yoctoSpinner({
|
|
3708
3290
|
text: spinnerText
|
|
3709
3291
|
}).start();
|
|
3710
3292
|
await deleteRepository(input.orgSlug, input.repoName, spinner, apiKey);
|
|
@@ -3715,7 +3297,7 @@ const del = _delete$1.del = {
|
|
|
3715
3297
|
// Internal functions
|
|
3716
3298
|
|
|
3717
3299
|
function setupCommand$7(name, description, argv, importMeta) {
|
|
3718
|
-
const cli =
|
|
3300
|
+
const cli = vendor.meow(`
|
|
3719
3301
|
Usage
|
|
3720
3302
|
$ ${name} <org slug> <repo slug>
|
|
3721
3303
|
|
|
@@ -3733,7 +3315,7 @@ function setupCommand$7(name, description, argv, importMeta) {
|
|
|
3733
3315
|
let showHelp = cli.flags['help'];
|
|
3734
3316
|
if (!orgSlug || !repoName) {
|
|
3735
3317
|
showHelp = true;
|
|
3736
|
-
console.error(`${
|
|
3318
|
+
console.error(`${colors.bgRed(colors.white('Input error'))}: Please provide an organization slug and repository slug.`);
|
|
3737
3319
|
}
|
|
3738
3320
|
if (showHelp) {
|
|
3739
3321
|
cli.showHelp();
|
|
@@ -3745,34 +3327,16 @@ function setupCommand$7(name, description, argv, importMeta) {
|
|
|
3745
3327
|
};
|
|
3746
3328
|
}
|
|
3747
3329
|
async function deleteRepository(orgSlug, repoName, spinner, apiKey) {
|
|
3748
|
-
const socketSdk = await
|
|
3749
|
-
const result = await
|
|
3330
|
+
const socketSdk = await sdk.setupSdk(apiKey);
|
|
3331
|
+
const result = await handleApiCall(socketSdk.deleteOrgRepo(orgSlug, repoName), 'deleting repository');
|
|
3750
3332
|
if (result.success) {
|
|
3751
3333
|
spinner.success('Repository deleted successfully');
|
|
3752
3334
|
} else {
|
|
3753
|
-
|
|
3335
|
+
handleUnsuccessfulApiResponse('deleteOrgRepo', result, spinner);
|
|
3754
3336
|
}
|
|
3755
3337
|
}
|
|
3756
3338
|
|
|
3757
|
-
|
|
3758
|
-
|
|
3759
|
-
var _interopRequireDefault$7 = vendor.interopRequireDefault.default;
|
|
3760
|
-
Object.defineProperty(list$1, "__esModule", {
|
|
3761
|
-
value: true
|
|
3762
|
-
});
|
|
3763
|
-
list$1.list = void 0;
|
|
3764
|
-
var _yoctocolorsCjs$6 = require$$1$1;
|
|
3765
|
-
var _chalkTable$2 = require$$2$3;
|
|
3766
|
-
var _meow$6 = _interopRequireDefault$7(vendor.build);
|
|
3767
|
-
var _yoctoSpinner$6 = require$$3$1;
|
|
3768
|
-
var _flags$6 = flags$1;
|
|
3769
|
-
var _apiHelpers$6 = apiHelpers;
|
|
3770
|
-
var _errors$7 = sdk.errors;
|
|
3771
|
-
var _formatting$6 = formatting;
|
|
3772
|
-
var _sdk$6 = sdk.sdk;
|
|
3773
|
-
// @ts-ignore
|
|
3774
|
-
|
|
3775
|
-
const list = list$1.list = {
|
|
3339
|
+
const list = {
|
|
3776
3340
|
description: 'List repositories in an organization',
|
|
3777
3341
|
async run(argv, importMeta, {
|
|
3778
3342
|
parentName
|
|
@@ -3780,12 +3344,12 @@ const list = list$1.list = {
|
|
|
3780
3344
|
const name = `${parentName} list`;
|
|
3781
3345
|
const input = setupCommand$6(name, list.description, argv, importMeta);
|
|
3782
3346
|
if (input) {
|
|
3783
|
-
const apiKey =
|
|
3347
|
+
const apiKey = sdk.getDefaultKey();
|
|
3784
3348
|
if (!apiKey) {
|
|
3785
|
-
throw new
|
|
3349
|
+
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.');
|
|
3786
3350
|
}
|
|
3787
3351
|
const spinnerText = 'Listing repositories... \n';
|
|
3788
|
-
const spinner =
|
|
3352
|
+
const spinner = yoctoSpinner({
|
|
3789
3353
|
text: spinnerText
|
|
3790
3354
|
}).start();
|
|
3791
3355
|
await listOrgRepos(input.orgSlug, input, spinner, apiKey);
|
|
@@ -3822,16 +3386,16 @@ const listRepoFlags = {
|
|
|
3822
3386
|
|
|
3823
3387
|
function setupCommand$6(name, description, argv, importMeta) {
|
|
3824
3388
|
const flags = {
|
|
3825
|
-
...
|
|
3389
|
+
...commonFlags,
|
|
3826
3390
|
...listRepoFlags,
|
|
3827
|
-
...
|
|
3391
|
+
...outputFlags
|
|
3828
3392
|
};
|
|
3829
|
-
const cli =
|
|
3393
|
+
const cli = vendor.meow(`
|
|
3830
3394
|
Usage
|
|
3831
3395
|
$ ${name} <org slug>
|
|
3832
3396
|
|
|
3833
3397
|
Options
|
|
3834
|
-
${
|
|
3398
|
+
${printFlagList(flags, 6)}
|
|
3835
3399
|
|
|
3836
3400
|
Examples
|
|
3837
3401
|
$ ${name} FakeOrg
|
|
@@ -3844,7 +3408,7 @@ function setupCommand$6(name, description, argv, importMeta) {
|
|
|
3844
3408
|
let showHelp = cli.flags['help'];
|
|
3845
3409
|
if (!cli.input[0]) {
|
|
3846
3410
|
showHelp = true;
|
|
3847
|
-
console.error(`${
|
|
3411
|
+
console.error(`${colors.bgRed(colors.white('Input error'))}: Please provide an organization slug.`);
|
|
3848
3412
|
}
|
|
3849
3413
|
if (showHelp) {
|
|
3850
3414
|
cli.showHelp();
|
|
@@ -3864,49 +3428,34 @@ function setupCommand$6(name, description, argv, importMeta) {
|
|
|
3864
3428
|
};
|
|
3865
3429
|
}
|
|
3866
3430
|
async function listOrgRepos(orgSlug, input, spinner, apiKey) {
|
|
3867
|
-
const socketSdk = await
|
|
3868
|
-
const result = await
|
|
3431
|
+
const socketSdk = await sdk.setupSdk(apiKey);
|
|
3432
|
+
const result = await handleApiCall(socketSdk.getOrgRepoList(orgSlug, input), 'listing repositories');
|
|
3869
3433
|
if (!result.success) {
|
|
3870
|
-
|
|
3434
|
+
handleUnsuccessfulApiResponse('getOrgRepoList', result, spinner);
|
|
3871
3435
|
return;
|
|
3872
3436
|
}
|
|
3873
3437
|
const options = {
|
|
3874
3438
|
columns: [{
|
|
3875
3439
|
field: 'id',
|
|
3876
|
-
name:
|
|
3440
|
+
name: colors.magenta('ID')
|
|
3877
3441
|
}, {
|
|
3878
3442
|
field: 'name',
|
|
3879
|
-
name:
|
|
3443
|
+
name: colors.magenta('Name')
|
|
3880
3444
|
}, {
|
|
3881
3445
|
field: 'visibility',
|
|
3882
|
-
name:
|
|
3446
|
+
name: colors.magenta('Visibility')
|
|
3883
3447
|
}, {
|
|
3884
3448
|
field: 'default_branch',
|
|
3885
|
-
name:
|
|
3449
|
+
name: colors.magenta('Default branch')
|
|
3886
3450
|
}, {
|
|
3887
3451
|
field: 'archived',
|
|
3888
|
-
name:
|
|
3452
|
+
name: colors.magenta('Archived')
|
|
3889
3453
|
}]
|
|
3890
3454
|
};
|
|
3891
|
-
spinner.stop(
|
|
3455
|
+
spinner.stop(chalkTable(options, result.data.results));
|
|
3892
3456
|
}
|
|
3893
3457
|
|
|
3894
|
-
|
|
3895
|
-
|
|
3896
|
-
var _interopRequireDefault$6 = vendor.interopRequireDefault.default;
|
|
3897
|
-
Object.defineProperty(update$1, "__esModule", {
|
|
3898
|
-
value: true
|
|
3899
|
-
});
|
|
3900
|
-
update$1.update = void 0;
|
|
3901
|
-
var _yoctocolorsCjs$5 = require$$1$1;
|
|
3902
|
-
var _meow$5 = _interopRequireDefault$6(vendor.build);
|
|
3903
|
-
var _yoctoSpinner$5 = require$$3$1;
|
|
3904
|
-
var _flags$5 = flags$1;
|
|
3905
|
-
var _apiHelpers$5 = apiHelpers;
|
|
3906
|
-
var _errors$6 = sdk.errors;
|
|
3907
|
-
var _formatting$5 = formatting;
|
|
3908
|
-
var _sdk$5 = sdk.sdk;
|
|
3909
|
-
const update = update$1.update = {
|
|
3458
|
+
const update = {
|
|
3910
3459
|
description: 'Update a repository in an organization',
|
|
3911
3460
|
async run(argv, importMeta, {
|
|
3912
3461
|
parentName
|
|
@@ -3914,12 +3463,12 @@ const update = update$1.update = {
|
|
|
3914
3463
|
const name = `${parentName} update`;
|
|
3915
3464
|
const input = setupCommand$5(name, update.description, argv, importMeta);
|
|
3916
3465
|
if (input) {
|
|
3917
|
-
const apiKey =
|
|
3466
|
+
const apiKey = sdk.getDefaultKey();
|
|
3918
3467
|
if (!apiKey) {
|
|
3919
|
-
throw new
|
|
3468
|
+
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.');
|
|
3920
3469
|
}
|
|
3921
3470
|
const spinnerText = 'Updating repository... \n';
|
|
3922
|
-
const spinner =
|
|
3471
|
+
const spinner = yoctoSpinner({
|
|
3923
3472
|
text: spinnerText
|
|
3924
3473
|
}).start();
|
|
3925
3474
|
await updateRepository(input.orgSlug, input, spinner, apiKey);
|
|
@@ -3963,16 +3512,16 @@ const repositoryUpdateFlags = {
|
|
|
3963
3512
|
|
|
3964
3513
|
function setupCommand$5(name, description, argv, importMeta) {
|
|
3965
3514
|
const flags = {
|
|
3966
|
-
...
|
|
3967
|
-
...
|
|
3515
|
+
...commonFlags,
|
|
3516
|
+
...outputFlags,
|
|
3968
3517
|
...repositoryUpdateFlags
|
|
3969
3518
|
};
|
|
3970
|
-
const cli =
|
|
3519
|
+
const cli = vendor.meow(`
|
|
3971
3520
|
Usage
|
|
3972
3521
|
$ ${name} <org slug>
|
|
3973
3522
|
|
|
3974
3523
|
Options
|
|
3975
|
-
${
|
|
3524
|
+
${printFlagList(flags, 6)}
|
|
3976
3525
|
|
|
3977
3526
|
Examples
|
|
3978
3527
|
$ ${name} FakeOrg
|
|
@@ -3989,10 +3538,10 @@ function setupCommand$5(name, description, argv, importMeta) {
|
|
|
3989
3538
|
let showHelp = cli.flags['help'];
|
|
3990
3539
|
if (!orgSlug) {
|
|
3991
3540
|
showHelp = true;
|
|
3992
|
-
console.error(`${
|
|
3541
|
+
console.error(`${colors.bgRed(colors.white('Input error'))}: Please provide an organization slug and repository name.`);
|
|
3993
3542
|
} else if (!repoName) {
|
|
3994
3543
|
showHelp = true;
|
|
3995
|
-
console.error(`${
|
|
3544
|
+
console.error(`${colors.bgRed(colors.white('Input error'))}: Repository name is required.`);
|
|
3996
3545
|
}
|
|
3997
3546
|
if (showHelp) {
|
|
3998
3547
|
cli.showHelp();
|
|
@@ -4010,34 +3559,16 @@ function setupCommand$5(name, description, argv, importMeta) {
|
|
|
4010
3559
|
};
|
|
4011
3560
|
}
|
|
4012
3561
|
async function updateRepository(orgSlug, input, spinner, apiKey) {
|
|
4013
|
-
const socketSdk = await
|
|
4014
|
-
const result = await
|
|
3562
|
+
const socketSdk = await sdk.setupSdk(apiKey);
|
|
3563
|
+
const result = await handleApiCall(socketSdk.updateOrgRepo(orgSlug, input.name, input), 'updating repository');
|
|
4015
3564
|
if (result.success) {
|
|
4016
3565
|
spinner.success('Repository updated successfully');
|
|
4017
3566
|
} else {
|
|
4018
|
-
|
|
3567
|
+
handleUnsuccessfulApiResponse('updateOrgRepo', result, spinner);
|
|
4019
3568
|
}
|
|
4020
3569
|
}
|
|
4021
3570
|
|
|
4022
|
-
|
|
4023
|
-
|
|
4024
|
-
var _interopRequireDefault$5 = vendor.interopRequireDefault.default;
|
|
4025
|
-
Object.defineProperty(view$1, "__esModule", {
|
|
4026
|
-
value: true
|
|
4027
|
-
});
|
|
4028
|
-
view$1.view = void 0;
|
|
4029
|
-
var _yoctocolorsCjs$4 = require$$1$1;
|
|
4030
|
-
var _chalkTable$1 = require$$2$3;
|
|
4031
|
-
var _meow$4 = _interopRequireDefault$5(vendor.build);
|
|
4032
|
-
var _yoctoSpinner$4 = require$$3$1;
|
|
4033
|
-
var _flags$4 = flags$1;
|
|
4034
|
-
var _apiHelpers$4 = apiHelpers;
|
|
4035
|
-
var _errors$5 = sdk.errors;
|
|
4036
|
-
var _formatting$4 = formatting;
|
|
4037
|
-
var _sdk$4 = sdk.sdk;
|
|
4038
|
-
// @ts-ignore
|
|
4039
|
-
|
|
4040
|
-
const view = view$1.view = {
|
|
3571
|
+
const view = {
|
|
4041
3572
|
description: 'View repositories in an organization',
|
|
4042
3573
|
async run(argv, importMeta, {
|
|
4043
3574
|
parentName
|
|
@@ -4045,12 +3576,12 @@ const view = view$1.view = {
|
|
|
4045
3576
|
const name = `${parentName} view`;
|
|
4046
3577
|
const input = setupCommand$4(name, view.description, argv, importMeta);
|
|
4047
3578
|
if (input) {
|
|
4048
|
-
const apiKey =
|
|
3579
|
+
const apiKey = sdk.getDefaultKey();
|
|
4049
3580
|
if (!apiKey) {
|
|
4050
|
-
throw new
|
|
3581
|
+
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.');
|
|
4051
3582
|
}
|
|
4052
3583
|
const spinnerText = 'Fetching repository... \n';
|
|
4053
|
-
const spinner =
|
|
3584
|
+
const spinner = yoctoSpinner({
|
|
4054
3585
|
text: spinnerText
|
|
4055
3586
|
}).start();
|
|
4056
3587
|
await viewRepository(input.orgSlug, input.repositoryName, spinner, apiKey);
|
|
@@ -4062,15 +3593,15 @@ const view = view$1.view = {
|
|
|
4062
3593
|
|
|
4063
3594
|
function setupCommand$4(name, description, argv, importMeta) {
|
|
4064
3595
|
const flags = {
|
|
4065
|
-
...
|
|
4066
|
-
...
|
|
3596
|
+
...commonFlags,
|
|
3597
|
+
...outputFlags
|
|
4067
3598
|
};
|
|
4068
|
-
const cli =
|
|
3599
|
+
const cli = vendor.meow(`
|
|
4069
3600
|
Usage
|
|
4070
3601
|
$ ${name} <org slug>
|
|
4071
3602
|
|
|
4072
3603
|
Options
|
|
4073
|
-
${
|
|
3604
|
+
${printFlagList(flags, 6)}
|
|
4074
3605
|
|
|
4075
3606
|
Examples
|
|
4076
3607
|
$ ${name} FakeOrg
|
|
@@ -4083,7 +3614,7 @@ function setupCommand$4(name, description, argv, importMeta) {
|
|
|
4083
3614
|
let showHelp = cli.flags['help'];
|
|
4084
3615
|
if (!cli.input[0]) {
|
|
4085
3616
|
showHelp = true;
|
|
4086
|
-
console.error(`${
|
|
3617
|
+
console.error(`${colors.bgRed(colors.white('Input error'))}: Please provide an organization slug and repository name.`);
|
|
4087
3618
|
}
|
|
4088
3619
|
if (showHelp) {
|
|
4089
3620
|
cli.showHelp();
|
|
@@ -4101,61 +3632,51 @@ function setupCommand$4(name, description, argv, importMeta) {
|
|
|
4101
3632
|
};
|
|
4102
3633
|
}
|
|
4103
3634
|
async function viewRepository(orgSlug, repoName, spinner, apiKey) {
|
|
4104
|
-
const socketSdk = await
|
|
4105
|
-
const result = await
|
|
3635
|
+
const socketSdk = await sdk.setupSdk(apiKey);
|
|
3636
|
+
const result = await handleApiCall(socketSdk.getOrgRepo(orgSlug, repoName), 'fetching repository');
|
|
4106
3637
|
if (!result.success) {
|
|
4107
|
-
|
|
3638
|
+
handleUnsuccessfulApiResponse('getOrgRepo', result, spinner);
|
|
4108
3639
|
return;
|
|
4109
3640
|
}
|
|
4110
3641
|
const options = {
|
|
4111
3642
|
columns: [{
|
|
4112
3643
|
field: 'id',
|
|
4113
|
-
name:
|
|
3644
|
+
name: colors.magenta('ID')
|
|
4114
3645
|
}, {
|
|
4115
3646
|
field: 'name',
|
|
4116
|
-
name:
|
|
3647
|
+
name: colors.magenta('Name')
|
|
4117
3648
|
}, {
|
|
4118
3649
|
field: 'visibility',
|
|
4119
|
-
name:
|
|
3650
|
+
name: colors.magenta('Visibility')
|
|
4120
3651
|
}, {
|
|
4121
3652
|
field: 'default_branch',
|
|
4122
|
-
name:
|
|
3653
|
+
name: colors.magenta('Default branch')
|
|
4123
3654
|
}, {
|
|
4124
3655
|
field: 'homepage',
|
|
4125
|
-
name:
|
|
3656
|
+
name: colors.magenta('Homepage')
|
|
4126
3657
|
}, {
|
|
4127
3658
|
field: 'archived',
|
|
4128
|
-
name:
|
|
3659
|
+
name: colors.magenta('Archived')
|
|
4129
3660
|
}, {
|
|
4130
3661
|
field: 'created_at',
|
|
4131
|
-
name:
|
|
3662
|
+
name: colors.magenta('Created at')
|
|
4132
3663
|
}]
|
|
4133
3664
|
};
|
|
4134
|
-
spinner.stop(
|
|
3665
|
+
spinner.stop(chalkTable(options, [result.data]));
|
|
4135
3666
|
}
|
|
4136
3667
|
|
|
4137
|
-
Object.defineProperty(repos, "__esModule", {
|
|
4138
|
-
value: true
|
|
4139
|
-
});
|
|
4140
|
-
repos.repo = void 0;
|
|
4141
|
-
var _create = create$1;
|
|
4142
|
-
var _delete = _delete$1;
|
|
4143
|
-
var _list = list$1;
|
|
4144
|
-
var _update = update$1;
|
|
4145
|
-
var _view = view$1;
|
|
4146
|
-
var _meowWithSubcommands$2 = meowWithSubcommands$1;
|
|
4147
3668
|
const description$1 = 'Repositories related commands';
|
|
4148
|
-
|
|
3669
|
+
const repo = {
|
|
4149
3670
|
description: description$1,
|
|
4150
3671
|
run: async (argv, importMeta, {
|
|
4151
3672
|
parentName
|
|
4152
3673
|
}) => {
|
|
4153
|
-
await
|
|
4154
|
-
create
|
|
4155
|
-
view
|
|
4156
|
-
list
|
|
4157
|
-
del
|
|
4158
|
-
update
|
|
3674
|
+
await meowWithSubcommands({
|
|
3675
|
+
create,
|
|
3676
|
+
view,
|
|
3677
|
+
list,
|
|
3678
|
+
del,
|
|
3679
|
+
update
|
|
4159
3680
|
}, {
|
|
4160
3681
|
argv,
|
|
4161
3682
|
description: description$1,
|
|
@@ -4165,25 +3686,7 @@ repos.repo = {
|
|
|
4165
3686
|
}
|
|
4166
3687
|
};
|
|
4167
3688
|
|
|
4168
|
-
|
|
4169
|
-
|
|
4170
|
-
var _interopRequireDefault$4 = vendor.interopRequireDefault.default;
|
|
4171
|
-
Object.defineProperty(dependencies$1, "__esModule", {
|
|
4172
|
-
value: true
|
|
4173
|
-
});
|
|
4174
|
-
dependencies$1.dependencies = void 0;
|
|
4175
|
-
var _yoctocolorsCjs$3 = require$$1$1;
|
|
4176
|
-
var _chalkTable = require$$2$3;
|
|
4177
|
-
var _meow$3 = _interopRequireDefault$4(vendor.build);
|
|
4178
|
-
var _yoctoSpinner$3 = require$$3$1;
|
|
4179
|
-
var _flags$3 = flags$1;
|
|
4180
|
-
var _apiHelpers$3 = apiHelpers;
|
|
4181
|
-
var _errors$4 = sdk.errors;
|
|
4182
|
-
var _formatting$3 = formatting;
|
|
4183
|
-
var _sdk$3 = sdk.sdk;
|
|
4184
|
-
// @ts-ignore
|
|
4185
|
-
|
|
4186
|
-
const dependencies = dependencies$1.dependencies = {
|
|
3689
|
+
const dependencies = {
|
|
4187
3690
|
description: 'Search for any dependency that is being used in your organization',
|
|
4188
3691
|
async run(argv, importMeta, {
|
|
4189
3692
|
parentName
|
|
@@ -4214,16 +3717,16 @@ const dependenciesFlags = {
|
|
|
4214
3717
|
|
|
4215
3718
|
function setupCommand$3(name, description, argv, importMeta) {
|
|
4216
3719
|
const flags = {
|
|
4217
|
-
...
|
|
3720
|
+
...commonFlags,
|
|
4218
3721
|
...dependenciesFlags,
|
|
4219
|
-
...
|
|
3722
|
+
...outputFlags
|
|
4220
3723
|
};
|
|
4221
|
-
const cli =
|
|
3724
|
+
const cli = vendor.meow(`
|
|
4222
3725
|
Usage
|
|
4223
3726
|
$ ${name}
|
|
4224
3727
|
|
|
4225
3728
|
Options
|
|
4226
|
-
${
|
|
3729
|
+
${printFlagList(flags, 6)}
|
|
4227
3730
|
|
|
4228
3731
|
Examples
|
|
4229
3732
|
$ ${name}
|
|
@@ -4251,20 +3754,20 @@ async function searchDeps({
|
|
|
4251
3754
|
offset,
|
|
4252
3755
|
outputJson
|
|
4253
3756
|
}) {
|
|
4254
|
-
const apiKey =
|
|
3757
|
+
const apiKey = sdk.getDefaultKey();
|
|
4255
3758
|
if (!apiKey) {
|
|
4256
|
-
throw new
|
|
3759
|
+
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.');
|
|
4257
3760
|
}
|
|
4258
|
-
const spinner =
|
|
3761
|
+
const spinner = yoctoSpinner({
|
|
4259
3762
|
text: 'Searching dependencies...'
|
|
4260
3763
|
}).start();
|
|
4261
|
-
const socketSdk = await
|
|
4262
|
-
const result = await
|
|
3764
|
+
const socketSdk = await sdk.setupSdk(apiKey);
|
|
3765
|
+
const result = await handleApiCall(socketSdk.searchDependencies({
|
|
4263
3766
|
limit,
|
|
4264
3767
|
offset
|
|
4265
3768
|
}), 'Searching dependencies');
|
|
4266
3769
|
if (!result.success) {
|
|
4267
|
-
|
|
3770
|
+
handleUnsuccessfulApiResponse('searchDependencies', result, spinner);
|
|
4268
3771
|
return;
|
|
4269
3772
|
}
|
|
4270
3773
|
spinner.stop('Organization dependencies:');
|
|
@@ -4275,59 +3778,31 @@ async function searchDeps({
|
|
|
4275
3778
|
const options = {
|
|
4276
3779
|
columns: [{
|
|
4277
3780
|
field: 'namespace',
|
|
4278
|
-
name:
|
|
3781
|
+
name: colors.cyan('Namespace')
|
|
4279
3782
|
}, {
|
|
4280
3783
|
field: 'name',
|
|
4281
|
-
name:
|
|
3784
|
+
name: colors.cyan('Name')
|
|
4282
3785
|
}, {
|
|
4283
3786
|
field: 'version',
|
|
4284
|
-
name:
|
|
3787
|
+
name: colors.cyan('Version')
|
|
4285
3788
|
}, {
|
|
4286
3789
|
field: 'repository',
|
|
4287
|
-
name:
|
|
3790
|
+
name: colors.cyan('Repository')
|
|
4288
3791
|
}, {
|
|
4289
3792
|
field: 'branch',
|
|
4290
|
-
name:
|
|
3793
|
+
name: colors.cyan('Branch')
|
|
4291
3794
|
}, {
|
|
4292
3795
|
field: 'type',
|
|
4293
|
-
name:
|
|
3796
|
+
name: colors.cyan('Type')
|
|
4294
3797
|
}, {
|
|
4295
3798
|
field: 'direct',
|
|
4296
|
-
name:
|
|
3799
|
+
name: colors.cyan('Direct')
|
|
4297
3800
|
}]
|
|
4298
3801
|
};
|
|
4299
|
-
console.log(
|
|
3802
|
+
console.log(chalkTable(options, result.data.rows));
|
|
4300
3803
|
}
|
|
4301
3804
|
|
|
4302
|
-
|
|
4303
|
-
|
|
4304
|
-
var _interopRequireDefault$3 = vendor.interopRequireDefault.default;
|
|
4305
|
-
Object.defineProperty(analytics$1, "__esModule", {
|
|
4306
|
-
value: true
|
|
4307
|
-
});
|
|
4308
|
-
analytics$1.analytics = void 0;
|
|
4309
|
-
var _promises = require$$1$4;
|
|
4310
|
-
var _screen$1 = require$$2$4;
|
|
4311
|
-
var _bar = require$$3$5;
|
|
4312
|
-
var _grid = require$$4$4;
|
|
4313
|
-
var _line = require$$5$3;
|
|
4314
|
-
var _meow$2 = _interopRequireDefault$3(vendor.build);
|
|
4315
|
-
var _yoctocolorsCjs$2 = require$$1$1;
|
|
4316
|
-
var _yoctoSpinner$2 = require$$3$1;
|
|
4317
|
-
var _flags$2 = flags$1;
|
|
4318
|
-
var _apiHelpers$2 = apiHelpers;
|
|
4319
|
-
var _errors$3 = sdk.errors;
|
|
4320
|
-
var _formatting$2 = formatting;
|
|
4321
|
-
var _sdk$2 = sdk.sdk;
|
|
4322
|
-
// @ts-ignore
|
|
4323
|
-
|
|
4324
|
-
// @ts-ignore
|
|
4325
|
-
|
|
4326
|
-
// @ts-ignore
|
|
4327
|
-
|
|
4328
|
-
// @ts-ignore
|
|
4329
|
-
|
|
4330
|
-
const analytics = analytics$1.analytics = {
|
|
3805
|
+
const analytics = {
|
|
4331
3806
|
description: `Look up analytics data \n
|
|
4332
3807
|
Default parameters are set to show the organization-level analytics over the last 7 days.`,
|
|
4333
3808
|
async run(argv, importMeta, {
|
|
@@ -4336,11 +3811,11 @@ const analytics = analytics$1.analytics = {
|
|
|
4336
3811
|
const name = parentName + ' analytics';
|
|
4337
3812
|
const input = setupCommand$2(name, analytics.description, argv, importMeta);
|
|
4338
3813
|
if (input) {
|
|
4339
|
-
const apiKey =
|
|
3814
|
+
const apiKey = sdk.getDefaultKey();
|
|
4340
3815
|
if (!apiKey) {
|
|
4341
|
-
throw new
|
|
3816
|
+
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.');
|
|
4342
3817
|
}
|
|
4343
|
-
const spinner =
|
|
3818
|
+
const spinner = yoctoSpinner({
|
|
4344
3819
|
text: 'Fetching analytics data'
|
|
4345
3820
|
}).start();
|
|
4346
3821
|
if (input.scope === 'org') {
|
|
@@ -4384,16 +3859,16 @@ const analyticsFlags = {
|
|
|
4384
3859
|
|
|
4385
3860
|
function setupCommand$2(name, description, argv, importMeta) {
|
|
4386
3861
|
const flags = {
|
|
4387
|
-
...
|
|
4388
|
-
...
|
|
3862
|
+
...commonFlags,
|
|
3863
|
+
...outputFlags,
|
|
4389
3864
|
...analyticsFlags
|
|
4390
3865
|
};
|
|
4391
|
-
const cli =
|
|
3866
|
+
const cli = vendor.meow(`
|
|
4392
3867
|
Usage
|
|
4393
3868
|
$ ${name} --scope=<scope> --time=<time filter>
|
|
4394
3869
|
|
|
4395
3870
|
Options
|
|
4396
|
-
${
|
|
3871
|
+
${printFlagList(flags, 6)}
|
|
4397
3872
|
|
|
4398
3873
|
Examples
|
|
4399
3874
|
$ ${name} --scope=org --time=7
|
|
@@ -4411,15 +3886,15 @@ function setupCommand$2(name, description, argv, importMeta) {
|
|
|
4411
3886
|
time
|
|
4412
3887
|
} = cli.flags;
|
|
4413
3888
|
if (scope !== 'org' && scope !== 'repo') {
|
|
4414
|
-
throw new
|
|
3889
|
+
throw new sdk.InputError("The scope must either be 'org' or 'repo'");
|
|
4415
3890
|
}
|
|
4416
3891
|
if (time !== 7 && time !== 30 && time !== 90) {
|
|
4417
|
-
throw new
|
|
3892
|
+
throw new sdk.InputError('The time filter must either be 7, 30 or 90');
|
|
4418
3893
|
}
|
|
4419
3894
|
let showHelp = cli.flags['help'];
|
|
4420
3895
|
if (scope === 'repo' && !repo) {
|
|
4421
3896
|
showHelp = true;
|
|
4422
|
-
console.error(`${
|
|
3897
|
+
console.error(`${colors.bgRed(colors.white('Input error'))}: Please provide a repository name when using the repository scope.`);
|
|
4423
3898
|
}
|
|
4424
3899
|
if (showHelp) {
|
|
4425
3900
|
cli.showHelp();
|
|
@@ -4435,10 +3910,10 @@ function setupCommand$2(name, description, argv, importMeta) {
|
|
|
4435
3910
|
}
|
|
4436
3911
|
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'];
|
|
4437
3912
|
async function fetchOrgAnalyticsData(time, spinner, apiKey, outputJson, filePath) {
|
|
4438
|
-
const socketSdk = await
|
|
4439
|
-
const result = await
|
|
3913
|
+
const socketSdk = await sdk.setupSdk(apiKey);
|
|
3914
|
+
const result = await handleApiCall(socketSdk.getOrgAnalytics(time.toString()), 'fetching analytics data');
|
|
4440
3915
|
if (result.success === false) {
|
|
4441
|
-
return
|
|
3916
|
+
return handleUnsuccessfulApiResponse('getOrgAnalytics', result, spinner);
|
|
4442
3917
|
}
|
|
4443
3918
|
spinner.stop();
|
|
4444
3919
|
if (!result.data.length) {
|
|
@@ -4450,7 +3925,7 @@ async function fetchOrgAnalyticsData(time, spinner, apiKey, outputJson, filePath
|
|
|
4450
3925
|
}
|
|
4451
3926
|
if (filePath) {
|
|
4452
3927
|
try {
|
|
4453
|
-
await
|
|
3928
|
+
await fs$1.writeFile(filePath, JSON.stringify(result.data), 'utf8');
|
|
4454
3929
|
console.log(`Data successfully written to ${filePath}`);
|
|
4455
3930
|
} catch (e) {
|
|
4456
3931
|
console.error(e);
|
|
@@ -4548,10 +4023,10 @@ const formatData = (data, scope) => {
|
|
|
4548
4023
|
};
|
|
4549
4024
|
};
|
|
4550
4025
|
async function fetchRepoAnalyticsData(repo, time, spinner, apiKey, outputJson, filePath) {
|
|
4551
|
-
const socketSdk = await
|
|
4552
|
-
const result = await
|
|
4026
|
+
const socketSdk = await sdk.setupSdk(apiKey);
|
|
4027
|
+
const result = await handleApiCall(socketSdk.getRepoAnalytics(repo, time.toString()), 'fetching analytics data');
|
|
4553
4028
|
if (result.success === false) {
|
|
4554
|
-
return
|
|
4029
|
+
return handleUnsuccessfulApiResponse('getRepoAnalytics', result, spinner);
|
|
4555
4030
|
}
|
|
4556
4031
|
spinner.stop();
|
|
4557
4032
|
if (!result.data.length) {
|
|
@@ -4563,7 +4038,7 @@ async function fetchRepoAnalyticsData(repo, time, spinner, apiKey, outputJson, f
|
|
|
4563
4038
|
}
|
|
4564
4039
|
if (filePath) {
|
|
4565
4040
|
try {
|
|
4566
|
-
await
|
|
4041
|
+
await fs$1.writeFile(filePath, JSON.stringify(result.data), 'utf8');
|
|
4567
4042
|
console.log(`Data successfully written to ${filePath}`);
|
|
4568
4043
|
} catch (e) {
|
|
4569
4044
|
console.error(e);
|
|
@@ -4573,8 +4048,8 @@ async function fetchRepoAnalyticsData(repo, time, spinner, apiKey, outputJson, f
|
|
|
4573
4048
|
return displayAnalyticsScreen(data);
|
|
4574
4049
|
}
|
|
4575
4050
|
const displayAnalyticsScreen = data => {
|
|
4576
|
-
const screen = new
|
|
4577
|
-
const grid = new
|
|
4051
|
+
const screen = new ScreenWidget();
|
|
4052
|
+
const grid = new GridLayout({
|
|
4578
4053
|
rows: 5,
|
|
4579
4054
|
cols: 4,
|
|
4580
4055
|
screen
|
|
@@ -4587,7 +4062,7 @@ const displayAnalyticsScreen = data => {
|
|
|
4587
4062
|
renderLineCharts(grid, screen, 'Total high alerts prevented from the main branch', [2, 2, 1, 2], data['total_high_prevented']);
|
|
4588
4063
|
renderLineCharts(grid, screen, 'Total medium alerts prevented from the main branch', [3, 0, 1, 2], data['total_medium_prevented']);
|
|
4589
4064
|
renderLineCharts(grid, screen, 'Total low alerts prevented from the main branch', [3, 2, 1, 2], data['total_low_prevented']);
|
|
4590
|
-
const bar = grid.set(4, 0, 1, 2,
|
|
4065
|
+
const bar = grid.set(4, 0, 1, 2, BarChart, {
|
|
4591
4066
|
label: 'Top 5 alert types',
|
|
4592
4067
|
barWidth: 10,
|
|
4593
4068
|
barSpacing: 17,
|
|
@@ -4605,7 +4080,7 @@ const displayAnalyticsScreen = data => {
|
|
|
4605
4080
|
screen.key(['escape', 'q', 'C-c'], () => process.exit(0));
|
|
4606
4081
|
};
|
|
4607
4082
|
const renderLineCharts = (grid, screen, title, coords, data) => {
|
|
4608
|
-
const line = grid.set(...coords,
|
|
4083
|
+
const line = grid.set(...coords, LineChart, {
|
|
4609
4084
|
style: {
|
|
4610
4085
|
line: 'cyan',
|
|
4611
4086
|
text: 'cyan',
|
|
@@ -4628,26 +4103,7 @@ const renderLineCharts = (grid, screen, title, coords, data) => {
|
|
|
4628
4103
|
line.setData([lineData]);
|
|
4629
4104
|
};
|
|
4630
4105
|
|
|
4631
|
-
|
|
4632
|
-
|
|
4633
|
-
var get$1 = {};
|
|
4634
|
-
|
|
4635
|
-
var _interopRequireDefault$2 = vendor.interopRequireDefault.default;
|
|
4636
|
-
Object.defineProperty(get$1, "__esModule", {
|
|
4637
|
-
value: true
|
|
4638
|
-
});
|
|
4639
|
-
get$1.get = void 0;
|
|
4640
|
-
var _nodeFs = require$$0;
|
|
4641
|
-
var _nodeUtil = require$$0$2;
|
|
4642
|
-
var _yoctocolorsCjs$1 = require$$1$1;
|
|
4643
|
-
var _meow$1 = _interopRequireDefault$2(vendor.build);
|
|
4644
|
-
var _yoctoSpinner$1 = require$$3$1;
|
|
4645
|
-
var _flags$1 = flags$1;
|
|
4646
|
-
var _apiHelpers$1 = apiHelpers;
|
|
4647
|
-
var _errors$2 = sdk.errors;
|
|
4648
|
-
var _formatting$1 = formatting;
|
|
4649
|
-
var _sdk$1 = sdk.sdk;
|
|
4650
|
-
const get = get$1.get = {
|
|
4106
|
+
const get = {
|
|
4651
4107
|
description: 'Get a diff scan for an organization',
|
|
4652
4108
|
async run(argv, importMeta, {
|
|
4653
4109
|
parentName
|
|
@@ -4655,12 +4111,12 @@ const get = get$1.get = {
|
|
|
4655
4111
|
const name = `${parentName} get`;
|
|
4656
4112
|
const input = setupCommand$1(name, get.description, argv, importMeta);
|
|
4657
4113
|
if (input) {
|
|
4658
|
-
const apiKey =
|
|
4114
|
+
const apiKey = sdk.getDefaultKey();
|
|
4659
4115
|
if (!apiKey) {
|
|
4660
|
-
throw new
|
|
4116
|
+
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.');
|
|
4661
4117
|
}
|
|
4662
4118
|
const spinnerText = 'Getting diff scan... \n';
|
|
4663
|
-
const spinner =
|
|
4119
|
+
const spinner = yoctoSpinner({
|
|
4664
4120
|
text: spinnerText
|
|
4665
4121
|
}).start();
|
|
4666
4122
|
await getDiffScan(input, spinner, apiKey);
|
|
@@ -4698,16 +4154,16 @@ const getDiffScanFlags = {
|
|
|
4698
4154
|
|
|
4699
4155
|
function setupCommand$1(name, description, argv, importMeta) {
|
|
4700
4156
|
const flags = {
|
|
4701
|
-
...
|
|
4157
|
+
...commonFlags,
|
|
4702
4158
|
...getDiffScanFlags,
|
|
4703
|
-
...
|
|
4159
|
+
...outputFlags
|
|
4704
4160
|
};
|
|
4705
|
-
const cli =
|
|
4161
|
+
const cli = vendor.meow(`
|
|
4706
4162
|
Usage
|
|
4707
4163
|
$ ${name} <org slug> --before=<before> --after=<after>
|
|
4708
4164
|
|
|
4709
4165
|
Options
|
|
4710
|
-
${
|
|
4166
|
+
${printFlagList(flags, 6)}
|
|
4711
4167
|
|
|
4712
4168
|
Examples
|
|
4713
4169
|
$ ${name} FakeCorp --before=aaa0aa0a-aaaa-0000-0a0a-0000000a00a0 --after=aaa1aa1a-aaaa-1111-1a1a-1111111a11a1
|
|
@@ -4724,10 +4180,10 @@ function setupCommand$1(name, description, argv, importMeta) {
|
|
|
4724
4180
|
let showHelp = cli.flags['help'];
|
|
4725
4181
|
if (!before || !after) {
|
|
4726
4182
|
showHelp = true;
|
|
4727
|
-
console.error(`${
|
|
4183
|
+
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>".`);
|
|
4728
4184
|
} else if (cli.input.length < 1) {
|
|
4729
4185
|
showHelp = true;
|
|
4730
|
-
console.error(`${
|
|
4186
|
+
console.error(`${colors.bgRed(colors.white('Input error'))}: Please provide an organization slug.`);
|
|
4731
4187
|
}
|
|
4732
4188
|
if (showHelp) {
|
|
4733
4189
|
cli.showHelp();
|
|
@@ -4751,50 +4207,44 @@ async function getDiffScan({
|
|
|
4751
4207
|
orgSlug,
|
|
4752
4208
|
outputJson
|
|
4753
4209
|
}, spinner, apiKey) {
|
|
4754
|
-
const response = await
|
|
4210
|
+
const response = await queryAPI(`${orgSlug}/full-scans/diff?before=${before}&after=${after}&preview`, apiKey);
|
|
4755
4211
|
const data = await response.json();
|
|
4756
4212
|
if (!response.ok) {
|
|
4757
|
-
const err = await
|
|
4758
|
-
spinner.error(`${
|
|
4213
|
+
const err = await handleAPIError(response.status);
|
|
4214
|
+
spinner.error(`${colors.bgRed(colors.white(response.statusText))}: ${err}`);
|
|
4759
4215
|
return;
|
|
4760
4216
|
}
|
|
4761
4217
|
spinner.stop();
|
|
4762
4218
|
if (file && !outputJson) {
|
|
4763
|
-
|
|
4219
|
+
fs.writeFile(file, JSON.stringify(data), err => {
|
|
4764
4220
|
err ? console.error(err) : console.log(`Data successfully written to ${file}`);
|
|
4765
4221
|
});
|
|
4766
4222
|
return;
|
|
4767
4223
|
}
|
|
4768
4224
|
if (outputJson) {
|
|
4769
4225
|
console.log(`\n Diff scan result: \n`);
|
|
4770
|
-
console.log(
|
|
4226
|
+
console.log(require$$0$1.inspect(data, {
|
|
4771
4227
|
showHidden: false,
|
|
4772
4228
|
depth: null,
|
|
4773
4229
|
colors: true
|
|
4774
4230
|
}));
|
|
4775
|
-
console.log(`\n View this diff scan in the Socket dashboard: ${
|
|
4231
|
+
console.log(`\n View this diff scan in the Socket dashboard: ${colors.cyan(data?.['diff_report_url'])}`);
|
|
4776
4232
|
return;
|
|
4777
4233
|
}
|
|
4778
4234
|
console.log('Diff scan result:');
|
|
4779
4235
|
console.log(data);
|
|
4780
4236
|
console.log(`\n 📝 To display the detailed report in the terminal, use the --json flag \n`);
|
|
4781
|
-
console.log(`\n View this diff scan in the Socket dashboard: ${
|
|
4237
|
+
console.log(`\n View this diff scan in the Socket dashboard: ${colors.cyan(data?.['diff_report_url'])}`);
|
|
4782
4238
|
}
|
|
4783
4239
|
|
|
4784
|
-
Object.defineProperty(diffScan, "__esModule", {
|
|
4785
|
-
value: true
|
|
4786
|
-
});
|
|
4787
|
-
diffScan.diffScan = void 0;
|
|
4788
|
-
var _get = get$1;
|
|
4789
|
-
var _meowWithSubcommands$1 = meowWithSubcommands$1;
|
|
4790
4240
|
const description = 'Diff scans related commands';
|
|
4791
|
-
diffScan
|
|
4241
|
+
const diffScan = {
|
|
4792
4242
|
description,
|
|
4793
4243
|
run: async (argv, importMeta, {
|
|
4794
4244
|
parentName
|
|
4795
4245
|
}) => {
|
|
4796
|
-
await
|
|
4797
|
-
get
|
|
4246
|
+
await meowWithSubcommands({
|
|
4247
|
+
get
|
|
4798
4248
|
}, {
|
|
4799
4249
|
argv,
|
|
4800
4250
|
description,
|
|
@@ -4804,27 +4254,8 @@ diffScan.diffScan = {
|
|
|
4804
4254
|
}
|
|
4805
4255
|
};
|
|
4806
4256
|
|
|
4807
|
-
var threatFeed$1 = {};
|
|
4808
|
-
|
|
4809
|
-
var _interopRequireDefault$1 = vendor.interopRequireDefault.default;
|
|
4810
|
-
Object.defineProperty(threatFeed$1, "__esModule", {
|
|
4811
|
-
value: true
|
|
4812
|
-
});
|
|
4813
|
-
threatFeed$1.threatFeed = void 0;
|
|
4814
|
-
var _screen = require$$2$4;
|
|
4815
|
-
var _table = require$$2$5;
|
|
4816
|
-
var _meow = _interopRequireDefault$1(vendor.build);
|
|
4817
|
-
var _yoctoSpinner = require$$3$1;
|
|
4818
|
-
var _flags = flags$1;
|
|
4819
|
-
var _apiHelpers = apiHelpers;
|
|
4820
|
-
var _errors$1 = sdk.errors;
|
|
4821
|
-
var _formatting = formatting;
|
|
4822
|
-
var _sdk = sdk.sdk;
|
|
4823
4257
|
// @ts-ignore
|
|
4824
|
-
|
|
4825
|
-
// @ts-ignore
|
|
4826
|
-
|
|
4827
|
-
const threatFeed = threatFeed$1.threatFeed = {
|
|
4258
|
+
const threatFeed = {
|
|
4828
4259
|
description: 'Look up the threat feed',
|
|
4829
4260
|
async run(argv, importMeta, {
|
|
4830
4261
|
parentName
|
|
@@ -4832,11 +4263,11 @@ const threatFeed = threatFeed$1.threatFeed = {
|
|
|
4832
4263
|
const name = `${parentName} threat-feed`;
|
|
4833
4264
|
const input = setupCommand(name, threatFeed.description, argv, importMeta);
|
|
4834
4265
|
if (input) {
|
|
4835
|
-
const apiKey =
|
|
4266
|
+
const apiKey = sdk.getDefaultKey();
|
|
4836
4267
|
if (!apiKey) {
|
|
4837
|
-
throw new
|
|
4268
|
+
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.');
|
|
4838
4269
|
}
|
|
4839
|
-
const spinner =
|
|
4270
|
+
const spinner = yoctoSpinner({
|
|
4840
4271
|
text: 'Looking up the threat feed'
|
|
4841
4272
|
}).start();
|
|
4842
4273
|
await fetchThreatFeed(input, spinner, apiKey);
|
|
@@ -4874,16 +4305,16 @@ const threatFeedFlags = {
|
|
|
4874
4305
|
|
|
4875
4306
|
function setupCommand(name, description, argv, importMeta) {
|
|
4876
4307
|
const flags = {
|
|
4877
|
-
...
|
|
4878
|
-
...
|
|
4308
|
+
...commonFlags,
|
|
4309
|
+
...outputFlags,
|
|
4879
4310
|
...threatFeedFlags
|
|
4880
4311
|
};
|
|
4881
|
-
const cli =
|
|
4312
|
+
const cli = vendor.meow(`
|
|
4882
4313
|
Usage
|
|
4883
4314
|
$ ${name}
|
|
4884
4315
|
|
|
4885
4316
|
Options
|
|
4886
|
-
${
|
|
4317
|
+
${printFlagList(flags, 6)}
|
|
4887
4318
|
|
|
4888
4319
|
Examples
|
|
4889
4320
|
$ ${name}
|
|
@@ -4924,15 +4355,15 @@ async function fetchThreatFeed({
|
|
|
4924
4355
|
direction,
|
|
4925
4356
|
filter
|
|
4926
4357
|
}).join('&');
|
|
4927
|
-
const response = await
|
|
4358
|
+
const response = await queryAPI(`threat-feed?${formattedQueryParams}`, apiKey);
|
|
4928
4359
|
const data = await response.json();
|
|
4929
4360
|
spinner.stop();
|
|
4930
4361
|
if (outputJson) {
|
|
4931
4362
|
console.log(data);
|
|
4932
4363
|
return;
|
|
4933
4364
|
}
|
|
4934
|
-
const screen = new
|
|
4935
|
-
const table = new
|
|
4365
|
+
const screen = new ScreenWidget();
|
|
4366
|
+
const table = new TableWidget({
|
|
4936
4367
|
keys: 'true',
|
|
4937
4368
|
fg: 'white',
|
|
4938
4369
|
selectedFg: 'white',
|
|
@@ -4977,236 +4408,32 @@ const formatQueryParams = params => Object.entries(params).map(entry => `${entry
|
|
|
4977
4408
|
const getHourDiff = (start, end) => Math.floor((end - start) / 3600000);
|
|
4978
4409
|
const getMinDiff = (start, end) => Math.floor((end - start) / 60000);
|
|
4979
4410
|
|
|
4980
|
-
|
|
4981
|
-
|
|
4982
|
-
|
|
4983
|
-
|
|
4984
|
-
|
|
4985
|
-
|
|
4986
|
-
|
|
4987
|
-
|
|
4988
|
-
|
|
4989
|
-
|
|
4990
|
-
|
|
4991
|
-
|
|
4992
|
-
|
|
4993
|
-
|
|
4994
|
-
|
|
4995
|
-
|
|
4996
|
-
|
|
4997
|
-
|
|
4998
|
-
|
|
4999
|
-
|
|
5000
|
-
|
|
5001
|
-
|
|
5002
|
-
|
|
5003
|
-
return _info[key];
|
|
5004
|
-
}
|
|
5005
|
-
});
|
|
5006
|
-
});
|
|
5007
|
-
var _login = login;
|
|
5008
|
-
Object.keys(_login).forEach(function (key) {
|
|
5009
|
-
if (key === "default" || key === "__esModule") return;
|
|
5010
|
-
if (key in exports && exports[key] === _login[key]) return;
|
|
5011
|
-
Object.defineProperty(exports, key, {
|
|
5012
|
-
enumerable: true,
|
|
5013
|
-
get: function () {
|
|
5014
|
-
return _login[key];
|
|
5015
|
-
}
|
|
5016
|
-
});
|
|
5017
|
-
});
|
|
5018
|
-
var _logout = logout;
|
|
5019
|
-
Object.keys(_logout).forEach(function (key) {
|
|
5020
|
-
if (key === "default" || key === "__esModule") return;
|
|
5021
|
-
if (key in exports && exports[key] === _logout[key]) return;
|
|
5022
|
-
Object.defineProperty(exports, key, {
|
|
5023
|
-
enumerable: true,
|
|
5024
|
-
get: function () {
|
|
5025
|
-
return _logout[key];
|
|
5026
|
-
}
|
|
5027
|
-
});
|
|
5028
|
-
});
|
|
5029
|
-
var _npm = npm;
|
|
5030
|
-
Object.keys(_npm).forEach(function (key) {
|
|
5031
|
-
if (key === "default" || key === "__esModule") return;
|
|
5032
|
-
if (key in exports && exports[key] === _npm[key]) return;
|
|
5033
|
-
Object.defineProperty(exports, key, {
|
|
5034
|
-
enumerable: true,
|
|
5035
|
-
get: function () {
|
|
5036
|
-
return _npm[key];
|
|
5037
|
-
}
|
|
5038
|
-
});
|
|
5039
|
-
});
|
|
5040
|
-
var _npx = npx;
|
|
5041
|
-
Object.keys(_npx).forEach(function (key) {
|
|
5042
|
-
if (key === "default" || key === "__esModule") return;
|
|
5043
|
-
if (key in exports && exports[key] === _npx[key]) return;
|
|
5044
|
-
Object.defineProperty(exports, key, {
|
|
5045
|
-
enumerable: true,
|
|
5046
|
-
get: function () {
|
|
5047
|
-
return _npx[key];
|
|
5048
|
-
}
|
|
5049
|
-
});
|
|
5050
|
-
});
|
|
5051
|
-
var _optimize = optimize$1;
|
|
5052
|
-
Object.keys(_optimize).forEach(function (key) {
|
|
5053
|
-
if (key === "default" || key === "__esModule") return;
|
|
5054
|
-
if (key in exports && exports[key] === _optimize[key]) return;
|
|
5055
|
-
Object.defineProperty(exports, key, {
|
|
5056
|
-
enumerable: true,
|
|
5057
|
-
get: function () {
|
|
5058
|
-
return _optimize[key];
|
|
5059
|
-
}
|
|
5060
|
-
});
|
|
5061
|
-
});
|
|
5062
|
-
var _organization = organization;
|
|
5063
|
-
Object.keys(_organization).forEach(function (key) {
|
|
5064
|
-
if (key === "default" || key === "__esModule") return;
|
|
5065
|
-
if (key in exports && exports[key] === _organization[key]) return;
|
|
5066
|
-
Object.defineProperty(exports, key, {
|
|
5067
|
-
enumerable: true,
|
|
5068
|
-
get: function () {
|
|
5069
|
-
return _organization[key];
|
|
5070
|
-
}
|
|
5071
|
-
});
|
|
5072
|
-
});
|
|
5073
|
-
var _rawNpm = rawNpm$1;
|
|
5074
|
-
Object.keys(_rawNpm).forEach(function (key) {
|
|
5075
|
-
if (key === "default" || key === "__esModule") return;
|
|
5076
|
-
if (key in exports && exports[key] === _rawNpm[key]) return;
|
|
5077
|
-
Object.defineProperty(exports, key, {
|
|
5078
|
-
enumerable: true,
|
|
5079
|
-
get: function () {
|
|
5080
|
-
return _rawNpm[key];
|
|
5081
|
-
}
|
|
5082
|
-
});
|
|
5083
|
-
});
|
|
5084
|
-
var _rawNpx = rawNpx$1;
|
|
5085
|
-
Object.keys(_rawNpx).forEach(function (key) {
|
|
5086
|
-
if (key === "default" || key === "__esModule") return;
|
|
5087
|
-
if (key in exports && exports[key] === _rawNpx[key]) return;
|
|
5088
|
-
Object.defineProperty(exports, key, {
|
|
5089
|
-
enumerable: true,
|
|
5090
|
-
get: function () {
|
|
5091
|
-
return _rawNpx[key];
|
|
5092
|
-
}
|
|
5093
|
-
});
|
|
5094
|
-
});
|
|
5095
|
-
var _report = report;
|
|
5096
|
-
Object.keys(_report).forEach(function (key) {
|
|
5097
|
-
if (key === "default" || key === "__esModule") return;
|
|
5098
|
-
if (key in exports && exports[key] === _report[key]) return;
|
|
5099
|
-
Object.defineProperty(exports, key, {
|
|
5100
|
-
enumerable: true,
|
|
5101
|
-
get: function () {
|
|
5102
|
-
return _report[key];
|
|
5103
|
-
}
|
|
5104
|
-
});
|
|
5105
|
-
});
|
|
5106
|
-
var _wrapper = wrapper$1;
|
|
5107
|
-
Object.keys(_wrapper).forEach(function (key) {
|
|
5108
|
-
if (key === "default" || key === "__esModule") return;
|
|
5109
|
-
if (key in exports && exports[key] === _wrapper[key]) return;
|
|
5110
|
-
Object.defineProperty(exports, key, {
|
|
5111
|
-
enumerable: true,
|
|
5112
|
-
get: function () {
|
|
5113
|
-
return _wrapper[key];
|
|
5114
|
-
}
|
|
5115
|
-
});
|
|
5116
|
-
});
|
|
5117
|
-
var _scan = scan;
|
|
5118
|
-
Object.keys(_scan).forEach(function (key) {
|
|
5119
|
-
if (key === "default" || key === "__esModule") return;
|
|
5120
|
-
if (key in exports && exports[key] === _scan[key]) return;
|
|
5121
|
-
Object.defineProperty(exports, key, {
|
|
5122
|
-
enumerable: true,
|
|
5123
|
-
get: function () {
|
|
5124
|
-
return _scan[key];
|
|
5125
|
-
}
|
|
5126
|
-
});
|
|
5127
|
-
});
|
|
5128
|
-
var _auditLog = auditLog$1;
|
|
5129
|
-
Object.keys(_auditLog).forEach(function (key) {
|
|
5130
|
-
if (key === "default" || key === "__esModule") return;
|
|
5131
|
-
if (key in exports && exports[key] === _auditLog[key]) return;
|
|
5132
|
-
Object.defineProperty(exports, key, {
|
|
5133
|
-
enumerable: true,
|
|
5134
|
-
get: function () {
|
|
5135
|
-
return _auditLog[key];
|
|
5136
|
-
}
|
|
5137
|
-
});
|
|
5138
|
-
});
|
|
5139
|
-
var _repos = repos;
|
|
5140
|
-
Object.keys(_repos).forEach(function (key) {
|
|
5141
|
-
if (key === "default" || key === "__esModule") return;
|
|
5142
|
-
if (key in exports && exports[key] === _repos[key]) return;
|
|
5143
|
-
Object.defineProperty(exports, key, {
|
|
5144
|
-
enumerable: true,
|
|
5145
|
-
get: function () {
|
|
5146
|
-
return _repos[key];
|
|
5147
|
-
}
|
|
5148
|
-
});
|
|
5149
|
-
});
|
|
5150
|
-
var _dependencies = dependencies$1;
|
|
5151
|
-
Object.keys(_dependencies).forEach(function (key) {
|
|
5152
|
-
if (key === "default" || key === "__esModule") return;
|
|
5153
|
-
if (key in exports && exports[key] === _dependencies[key]) return;
|
|
5154
|
-
Object.defineProperty(exports, key, {
|
|
5155
|
-
enumerable: true,
|
|
5156
|
-
get: function () {
|
|
5157
|
-
return _dependencies[key];
|
|
5158
|
-
}
|
|
5159
|
-
});
|
|
5160
|
-
});
|
|
5161
|
-
var _analytics = analytics$1;
|
|
5162
|
-
Object.keys(_analytics).forEach(function (key) {
|
|
5163
|
-
if (key === "default" || key === "__esModule") return;
|
|
5164
|
-
if (key in exports && exports[key] === _analytics[key]) return;
|
|
5165
|
-
Object.defineProperty(exports, key, {
|
|
5166
|
-
enumerable: true,
|
|
5167
|
-
get: function () {
|
|
5168
|
-
return _analytics[key];
|
|
5169
|
-
}
|
|
5170
|
-
});
|
|
5171
|
-
});
|
|
5172
|
-
var _diffScan = diffScan;
|
|
5173
|
-
Object.keys(_diffScan).forEach(function (key) {
|
|
5174
|
-
if (key === "default" || key === "__esModule") return;
|
|
5175
|
-
if (key in exports && exports[key] === _diffScan[key]) return;
|
|
5176
|
-
Object.defineProperty(exports, key, {
|
|
5177
|
-
enumerable: true,
|
|
5178
|
-
get: function () {
|
|
5179
|
-
return _diffScan[key];
|
|
5180
|
-
}
|
|
5181
|
-
});
|
|
5182
|
-
});
|
|
5183
|
-
var _threatFeed = threatFeed$1;
|
|
5184
|
-
Object.keys(_threatFeed).forEach(function (key) {
|
|
5185
|
-
if (key === "default" || key === "__esModule") return;
|
|
5186
|
-
if (key in exports && exports[key] === _threatFeed[key]) return;
|
|
5187
|
-
Object.defineProperty(exports, key, {
|
|
5188
|
-
enumerable: true,
|
|
5189
|
-
get: function () {
|
|
5190
|
-
return _threatFeed[key];
|
|
5191
|
-
}
|
|
5192
|
-
});
|
|
5193
|
-
});
|
|
5194
|
-
} (commands));
|
|
5195
|
-
|
|
5196
|
-
var _interopRequireWildcard = vendor.interopRequireWildcard.default;
|
|
5197
|
-
var _interopRequireDefault = vendor.interopRequireDefault.default;
|
|
5198
|
-
var _nodeUrl = require$$8$2;
|
|
5199
|
-
var _yoctocolorsCjs = require$$1$1;
|
|
5200
|
-
var _ponyCause = require$$4$1;
|
|
5201
|
-
var _tinyUpdater = _interopRequireDefault(vendor.dist);
|
|
5202
|
-
var cliCommands = _interopRequireWildcard(commands, true);
|
|
5203
|
-
var _constants = constants.constants;
|
|
5204
|
-
var _colorOrMarkdown = sdk.colorOrMarkdown;
|
|
5205
|
-
var _errors = sdk.errors;
|
|
5206
|
-
var _meowWithSubcommands = meowWithSubcommands$1;
|
|
4411
|
+
var cliCommands = {
|
|
4412
|
+
__proto__: null,
|
|
4413
|
+
analytics: analytics,
|
|
4414
|
+
auditLog: auditLog,
|
|
4415
|
+
cdxgen: cdxgen,
|
|
4416
|
+
dependencies: dependencies,
|
|
4417
|
+
diffScan: diffScan,
|
|
4418
|
+
info: info,
|
|
4419
|
+
login: login,
|
|
4420
|
+
logout: logout,
|
|
4421
|
+
npm: npm,
|
|
4422
|
+
npx: npx,
|
|
4423
|
+
optimize: optimize,
|
|
4424
|
+
organizations: organizations,
|
|
4425
|
+
rawNpm: rawNpm,
|
|
4426
|
+
rawNpx: rawNpx,
|
|
4427
|
+
repo: repo,
|
|
4428
|
+
report: report,
|
|
4429
|
+
scan: scan,
|
|
4430
|
+
threatFeed: threatFeed,
|
|
4431
|
+
wrapper: wrapper
|
|
4432
|
+
};
|
|
4433
|
+
|
|
5207
4434
|
const {
|
|
5208
4435
|
rootPkgJsonPath
|
|
5209
|
-
} =
|
|
4436
|
+
} = constants;
|
|
5210
4437
|
const formattedCliCommands = Object.fromEntries(Object.entries(cliCommands).map(entry => {
|
|
5211
4438
|
const key = entry[0];
|
|
5212
4439
|
entry[0] = camelToHyphen(key);
|
|
@@ -5218,14 +4445,13 @@ function camelToHyphen(str) {
|
|
|
5218
4445
|
|
|
5219
4446
|
// TODO: Add autocompletion using https://socket.dev/npm/package/omelette
|
|
5220
4447
|
void (async () => {
|
|
5221
|
-
|
|
5222
|
-
await (0, _tinyUpdater.default)({
|
|
4448
|
+
await vendor.updater({
|
|
5223
4449
|
name: 'socket',
|
|
5224
|
-
version:
|
|
4450
|
+
version: require(rootPkgJsonPath).version,
|
|
5225
4451
|
ttl: 86_400_000 /* 24 hours in milliseconds */
|
|
5226
4452
|
});
|
|
5227
4453
|
try {
|
|
5228
|
-
await
|
|
4454
|
+
await meowWithSubcommands(formattedCliCommands, {
|
|
5229
4455
|
aliases: {
|
|
5230
4456
|
ci: {
|
|
5231
4457
|
description: 'Alias for "report create --view --strict"',
|
|
@@ -5235,62 +4461,31 @@ void (async () => {
|
|
|
5235
4461
|
argv: process.argv.slice(2),
|
|
5236
4462
|
name: 'socket',
|
|
5237
4463
|
importMeta: {
|
|
5238
|
-
url: `${
|
|
4464
|
+
url: `${require$$0.pathToFileURL(__filename)}`
|
|
5239
4465
|
}
|
|
5240
4466
|
});
|
|
5241
4467
|
} catch (err) {
|
|
5242
4468
|
let errorBody;
|
|
5243
4469
|
let errorTitle;
|
|
5244
4470
|
let errorMessage = '';
|
|
5245
|
-
if (err instanceof
|
|
4471
|
+
if (err instanceof sdk.AuthError) {
|
|
5246
4472
|
errorTitle = 'Authentication error';
|
|
5247
4473
|
errorMessage = err.message;
|
|
5248
|
-
} else if (err instanceof
|
|
4474
|
+
} else if (err instanceof sdk.InputError) {
|
|
5249
4475
|
errorTitle = 'Invalid input';
|
|
5250
4476
|
errorMessage = err.message;
|
|
5251
4477
|
errorBody = err.body;
|
|
5252
4478
|
} else if (err instanceof Error) {
|
|
5253
4479
|
errorTitle = 'Unexpected error';
|
|
5254
|
-
errorMessage =
|
|
5255
|
-
errorBody =
|
|
4480
|
+
errorMessage = ponyCause.messageWithCauses(err);
|
|
4481
|
+
errorBody = ponyCause.stackWithCauses(err);
|
|
5256
4482
|
} else {
|
|
5257
4483
|
errorTitle = 'Unexpected error with no details';
|
|
5258
4484
|
}
|
|
5259
|
-
console.error(`${
|
|
4485
|
+
console.error(`${sdk.logSymbols.error} ${colors.bgRed(colors.white(errorTitle + ':'))} ${errorMessage}`);
|
|
5260
4486
|
if (errorBody) {
|
|
5261
4487
|
console.error(`\n${errorBody}`);
|
|
5262
4488
|
}
|
|
5263
4489
|
process.exit(1);
|
|
5264
4490
|
}
|
|
5265
4491
|
})();
|
|
5266
|
-
|
|
5267
|
-
(function (exports) {
|
|
5268
|
-
|
|
5269
|
-
var _interopRequireWildcard = vendor.interopRequireWildcard.default;
|
|
5270
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5271
|
-
value: true
|
|
5272
|
-
});
|
|
5273
|
-
var _exportNames = {};
|
|
5274
|
-
Object.defineProperty(exports, "default", {
|
|
5275
|
-
enumerable: true,
|
|
5276
|
-
get: function () {
|
|
5277
|
-
return _cli.default;
|
|
5278
|
-
}
|
|
5279
|
-
});
|
|
5280
|
-
var _cli = _interopRequireWildcard(cli$1, true);
|
|
5281
|
-
Object.keys(_cli).forEach(function (key) {
|
|
5282
|
-
if (key === "default" || key === "__esModule") return;
|
|
5283
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
5284
|
-
if (key in exports && exports[key] === _cli[key]) return;
|
|
5285
|
-
Object.defineProperty(exports, key, {
|
|
5286
|
-
enumerable: true,
|
|
5287
|
-
get: function () {
|
|
5288
|
-
return _cli[key];
|
|
5289
|
-
}
|
|
5290
|
-
});
|
|
5291
|
-
});
|
|
5292
|
-
} (cli$2));
|
|
5293
|
-
|
|
5294
|
-
var cli = /*@__PURE__*/vendor.getDefaultExportFromCjs(cli$2);
|
|
5295
|
-
|
|
5296
|
-
module.exports = cli;
|