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