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