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