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