@socketsecurity/cli 0.11.0 → 0.11.1

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.
Files changed (82) hide show
  1. package/README.md +22 -22
  2. package/bin/npm +2 -0
  3. package/bin/npx +2 -0
  4. package/dist/cli.d.ts +3 -0
  5. package/dist/cli.d.ts.map +1 -0
  6. package/dist/cli.js +3419 -0
  7. package/dist/errors.d.ts +7 -0
  8. package/dist/link.d.ts +2 -0
  9. package/dist/link.js +45 -0
  10. package/dist/npm-cli.d.ts +2 -0
  11. package/dist/npm-cli.js +84 -0
  12. package/dist/npm-injection.d.ts +1 -0
  13. package/dist/npm-injection.js +913 -0
  14. package/dist/npm-injection2.d.ts +25 -0
  15. package/dist/npm-injection2.js +899 -0
  16. package/dist/npx-cli.d.ts +2 -0
  17. package/dist/npx-cli.js +60 -0
  18. package/dist/path-resolve.d.ts +12 -0
  19. package/dist/path-resolve.js +139 -0
  20. package/dist/sdk.d.ts +27 -0
  21. package/dist/sdk.js +224 -0
  22. package/dist/settings.d.ts +9 -0
  23. package/dist/type-helpers.d.ts +3 -0
  24. package/dist/vendor.js +25421 -0
  25. package/package.json +105 -52
  26. package/{lib/shadow/translations.json → translations.json} +20 -20
  27. package/cli.js +0 -72
  28. package/lib/commands/audit-log/index.js +0 -162
  29. package/lib/commands/cdxgen/index.js +0 -211
  30. package/lib/commands/dependencies/index.js +0 -150
  31. package/lib/commands/index.js +0 -15
  32. package/lib/commands/info/index.js +0 -287
  33. package/lib/commands/login/index.js +0 -170
  34. package/lib/commands/logout/index.js +0 -35
  35. package/lib/commands/npm/index.js +0 -27
  36. package/lib/commands/npx/index.js +0 -22
  37. package/lib/commands/organizations/index.js +0 -81
  38. package/lib/commands/raw-npm/index.js +0 -59
  39. package/lib/commands/raw-npx/index.js +0 -59
  40. package/lib/commands/report/create.js +0 -251
  41. package/lib/commands/report/index.js +0 -24
  42. package/lib/commands/report/view.js +0 -176
  43. package/lib/commands/repos/create.js +0 -166
  44. package/lib/commands/repos/delete.js +0 -93
  45. package/lib/commands/repos/index.js +0 -30
  46. package/lib/commands/repos/list.js +0 -170
  47. package/lib/commands/repos/update.js +0 -166
  48. package/lib/commands/repos/view.js +0 -128
  49. package/lib/commands/scan/create.js +0 -245
  50. package/lib/commands/scan/delete.js +0 -112
  51. package/lib/commands/scan/index.js +0 -30
  52. package/lib/commands/scan/list.js +0 -192
  53. package/lib/commands/scan/metadata.js +0 -113
  54. package/lib/commands/scan/stream.js +0 -115
  55. package/lib/commands/wrapper/index.js +0 -199
  56. package/lib/flags/command.js +0 -14
  57. package/lib/flags/index.js +0 -3
  58. package/lib/flags/output.js +0 -16
  59. package/lib/flags/validation.js +0 -14
  60. package/lib/shadow/bin/npm +0 -2
  61. package/lib/shadow/bin/npx +0 -2
  62. package/lib/shadow/link.cjs +0 -50
  63. package/lib/shadow/npm-cli.cjs +0 -27
  64. package/lib/shadow/npm-injection.cjs +0 -649
  65. package/lib/shadow/npx-cli.cjs +0 -27
  66. package/lib/shadow/package.json +0 -3
  67. package/lib/shadow/tty-server.cjs +0 -222
  68. package/lib/shadow/update-notifier.mjs +0 -3
  69. package/lib/utils/api-helpers.js +0 -42
  70. package/lib/utils/chalk-markdown.js +0 -125
  71. package/lib/utils/errors.js +0 -14
  72. package/lib/utils/flags.js +0 -27
  73. package/lib/utils/format-issues.js +0 -99
  74. package/lib/utils/formatting.js +0 -47
  75. package/lib/utils/issue-rules.cjs +0 -180
  76. package/lib/utils/meow-with-subcommands.js +0 -87
  77. package/lib/utils/misc.js +0 -61
  78. package/lib/utils/path-resolve.js +0 -204
  79. package/lib/utils/sdk.js +0 -99
  80. package/lib/utils/settings.js +0 -69
  81. package/lib/utils/type-helpers.cjs +0 -13
  82. package/lib/utils/update-notifier.js +0 -18
package/dist/cli.js ADDED
@@ -0,0 +1,3419 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ var vendor = require('./vendor.js');
5
+ var require$$0 = require('node:fs');
6
+ var require$$1 = require('node:path');
7
+ var require$$2$3 = require('node:url');
8
+ var require$$6 = require('pony-cause');
9
+ var require$$5 = require('yargs-parser');
10
+ var sdk = require('./sdk.js');
11
+ var require$$1$1 = require('@inquirer/prompts');
12
+ var require$$0$1 = require('node:child_process');
13
+ var require$$2 = require('@apideck/better-ajv-errors');
14
+ var require$$3 = require('@socketsecurity/config');
15
+ var pathResolve = require('./path-resolve.js');
16
+ var require$$0$2 = require('node:os');
17
+ var require$$3$1 = require('node:readline');
18
+ var require$$0$3 = require('node:process');
19
+ var require$$2$1 = require('node:readline/promises');
20
+ var require$$2$2 = require('chalk-table');
21
+
22
+ var cli$1 = {};
23
+
24
+ var cli = {};
25
+
26
+ var commands = {};
27
+
28
+ var cdxgen = {};
29
+
30
+ var _interopRequireDefault$o = vendor.interopRequireDefault.default;
31
+ Object.defineProperty(cdxgen, "__esModule", {
32
+ value: true
33
+ });
34
+ cdxgen.cdxgen = void 0;
35
+ var _nodeFs$2 = require$$0;
36
+ var _nodePath$4 = require$$1;
37
+ var _chalk$h = _interopRequireDefault$o(vendor.source);
38
+ var _execa = vendor.execa;
39
+ var _yargsParser = require$$5;
40
+ const distPath$3 = __dirname;
41
+ const rootPath$1 = _nodePath$4.resolve(distPath$3, '..');
42
+ const {
43
+ SBOM_SIGN_ALGORITHM,
44
+ // Algorithm. Example: RS512
45
+ SBOM_SIGN_PRIVATE_KEY,
46
+ // Location to the RSA private key
47
+ SBOM_SIGN_PUBLIC_KEY // Optional. Location to the RSA public key
48
+ } = process.env;
49
+ const toLower = arg => arg.toLowerCase();
50
+ const arrayToLower = arg => arg.map(toLower);
51
+ const execaConfig = {
52
+ env: {
53
+ NODE_ENV: ''
54
+ },
55
+ localDir: _nodePath$4.join(rootPath$1, 'node_modules')
56
+ };
57
+ const nodejsPlatformTypes = ['javascript', 'js', 'nodejs', 'npm', 'pnpm', 'ts', 'tsx', 'typescript'];
58
+ const yargsConfig = {
59
+ configuration: {
60
+ 'camel-case-expansion': false,
61
+ 'strip-aliased': true,
62
+ 'parse-numbers': false,
63
+ 'populate--': true,
64
+ 'unknown-options-as-args': true
65
+ },
66
+ coerce: {
67
+ author: arrayToLower,
68
+ filter: arrayToLower,
69
+ only: arrayToLower,
70
+ profile: toLower,
71
+ standard: arrayToLower,
72
+ type: toLower
73
+ },
74
+ default: {
75
+ //author: ['OWASP Foundation'],
76
+ //'auto-compositions': true,
77
+ //babel: true,
78
+ //evidence: false,
79
+ //'include-crypto': false,
80
+ //'include-formulation': false,
81
+ //'install-deps': true,
82
+ //output: 'bom.json',
83
+ //profile: 'generic',
84
+ //'project-version': '',
85
+ //recurse: true,
86
+ //'server-host': '127.0.0.1',
87
+ //'server-port': '9090',
88
+ //'spec-version': '1.5',
89
+ type: 'js'
90
+ //validate: true,
91
+ },
92
+ alias: {
93
+ help: ['h'],
94
+ output: ['o'],
95
+ print: ['p'],
96
+ recurse: ['r'],
97
+ 'resolve-class': ['c'],
98
+ type: ['t'],
99
+ version: ['v']
100
+ },
101
+ array: [{
102
+ key: 'author',
103
+ type: 'string'
104
+ }, {
105
+ key: 'exclude',
106
+ type: 'string'
107
+ }, {
108
+ key: 'filter',
109
+ type: 'string'
110
+ }, {
111
+ key: 'only',
112
+ type: 'string'
113
+ }, {
114
+ key: 'standard',
115
+ type: 'string'
116
+ }],
117
+ boolean: ['auto-compositions', 'babel', 'deep', 'evidence', 'fail-on-error', 'generate-key-and-sign', 'help', 'include-formulation', 'include-crypto', 'install-deps', 'print', 'required-only', 'server', 'validate', 'version'],
118
+ string: ['api-key', 'output', 'parent-project-id', 'profile', 'project-group', 'project-name', 'project-version', 'project-id', 'server-host', 'server-port', 'server-url', 'spec-version']
119
+ };
120
+ function argvToArray(argv) {
121
+ if (argv['help']) return ['--help'];
122
+ const result = [];
123
+ for (const {
124
+ 0: key,
125
+ 1: value
126
+ } of Object.entries(argv)) {
127
+ if (key === '_' || key === '--') continue;
128
+ if (key === 'babel' || key === 'install-deps' || key === 'validate') {
129
+ // cdxgen documents no-babel, no-install-deps, and no-validate flags so
130
+ // use them when relevant.
131
+ result.push(`--${value ? key : `no-${key}`}`);
132
+ } else if (value === true) {
133
+ result.push(`--${key}`);
134
+ } else if (typeof value === 'string') {
135
+ result.push(`--${key}=${value}`);
136
+ } else if (Array.isArray(value)) {
137
+ result.push(`--${key}`, ...value.map(String));
138
+ }
139
+ }
140
+ if (argv['--']) {
141
+ result.push('--', ...argv['--']);
142
+ }
143
+ return result;
144
+ }
145
+ cdxgen.cdxgen = {
146
+ description: 'Create an SBOM with CycloneDX generator (cdxgen)',
147
+ async run(argv_) {
148
+ const yargv = {
149
+ __proto__: null,
150
+ ..._yargsParser(argv_, yargsConfig)
151
+ };
152
+ const unknown = yargv._;
153
+ const {
154
+ length: unknownLength
155
+ } = unknown;
156
+ if (unknownLength) {
157
+ console.error(`Unknown argument${unknownLength > 1 ? 's' : ''}: ${yargv._.join(', ')}`);
158
+ process.exitCode = 1;
159
+ return;
160
+ }
161
+ let cleanupPackageLock = false;
162
+ if (yargv.type !== 'yarn' && nodejsPlatformTypes.includes(yargv.type) && (0, _nodeFs$2.existsSync)('./yarn.lock')) {
163
+ if ((0, _nodeFs$2.existsSync)('./package-lock.json')) {
164
+ yargv.type = 'npm';
165
+ } else {
166
+ // Use synp to create a package-lock.json from the yarn.lock,
167
+ // based on the node_modules folder, for a more accurate SBOM.
168
+ try {
169
+ await (0, _execa.$)(execaConfig)`synp --source-file ./yarn.lock`;
170
+ yargv.type = 'npm';
171
+ cleanupPackageLock = true;
172
+ } catch {}
173
+ }
174
+ }
175
+ if (yargv.output === undefined) {
176
+ yargv.output = 'socket-cdx.json';
177
+ }
178
+ await (0, _execa.$)({
179
+ ...execaConfig,
180
+ env: {
181
+ NODE_ENV: '',
182
+ SBOM_SIGN_ALGORITHM,
183
+ SBOM_SIGN_PRIVATE_KEY,
184
+ SBOM_SIGN_PUBLIC_KEY
185
+ },
186
+ stdout: 'inherit'
187
+ })`cdxgen ${argvToArray(yargv)}`;
188
+ if (cleanupPackageLock) {
189
+ try {
190
+ await _nodeFs$2.promises.unlink('./package-lock.json');
191
+ } catch {}
192
+ }
193
+ const fullOutputPath = _nodePath$4.join(process.cwd(), yargv.output);
194
+ if ((0, _nodeFs$2.existsSync)(fullOutputPath)) {
195
+ console.log(_chalk$h.default.cyanBright(`${yargv.output} created!`));
196
+ }
197
+ }
198
+ };
199
+
200
+ var info$1 = {};
201
+
202
+ var flags = {};
203
+
204
+ Object.defineProperty(flags, "__esModule", {
205
+ value: true
206
+ });
207
+ flags.validationFlags = flags.outputFlags = flags.commandFlags = void 0;
208
+ flags.commandFlags = {
209
+ enable: {
210
+ type: 'boolean',
211
+ default: false,
212
+ description: 'Enables the Socket npm/npx wrapper'
213
+ },
214
+ disable: {
215
+ type: 'boolean',
216
+ default: false,
217
+ description: 'Disables the Socket npm/npx wrapper'
218
+ }
219
+ };
220
+ flags.outputFlags = {
221
+ json: {
222
+ type: 'boolean',
223
+ shortFlag: 'j',
224
+ default: false,
225
+ description: 'Output result as json'
226
+ },
227
+ markdown: {
228
+ type: 'boolean',
229
+ shortFlag: 'm',
230
+ default: false,
231
+ description: 'Output result as markdown'
232
+ }
233
+ };
234
+ flags.validationFlags = {
235
+ all: {
236
+ type: 'boolean',
237
+ default: false,
238
+ description: 'Include all issues'
239
+ },
240
+ strict: {
241
+ type: 'boolean',
242
+ default: false,
243
+ description: 'Exits with an error code if any matching issues are found'
244
+ }
245
+ };
246
+
247
+ var apiHelpers = {};
248
+
249
+ var _interopRequireDefault$n = vendor.interopRequireDefault.default;
250
+ Object.defineProperty(apiHelpers, "__esModule", {
251
+ value: true
252
+ });
253
+ apiHelpers.handleApiCall = handleApiCall;
254
+ apiHelpers.handleUnsuccessfulApiResponse = handleUnsuccessfulApiResponse;
255
+ var _chalk$g = _interopRequireDefault$n(vendor.source);
256
+ var _ponyCause$4 = require$$6;
257
+ var _errors$i = sdk.errors;
258
+ function handleUnsuccessfulApiResponse(_name, result, spinner) {
259
+ const resultError = 'error' in result && result.error && typeof result.error === 'object' ? result.error : {};
260
+ const message = 'message' in resultError && typeof resultError.message === 'string' ? resultError.message : 'No error message returned';
261
+ if (result.status === 401 || result.status === 403) {
262
+ spinner.stop();
263
+ throw new _errors$i.AuthError(message);
264
+ }
265
+ spinner.fail(_chalk$g.default.white.bgRed('API returned an error:') + ' ' + message);
266
+ process.exit(1);
267
+ }
268
+ async function handleApiCall(value, description) {
269
+ let result;
270
+ try {
271
+ result = await value;
272
+ } catch (cause) {
273
+ throw new _ponyCause$4.ErrorWithCause(`Failed ${description}`, {
274
+ cause
275
+ });
276
+ }
277
+ return result;
278
+ }
279
+
280
+ var formatIssues = {};
281
+
282
+ var misc = {};
283
+
284
+ Object.defineProperty(misc, "__esModule", {
285
+ value: true
286
+ });
287
+ misc.createDebugLogger = createDebugLogger;
288
+ misc.objectSome = objectSome;
289
+ misc.pick = pick;
290
+ misc.stringJoinWithSeparateFinalSeparator = stringJoinWithSeparateFinalSeparator;
291
+ var _chalkMarkdown$4 = sdk.chalkMarkdown;
292
+ function createDebugLogger(printDebugLogs) {
293
+ return printDebugLogs ? (...params) => console.error(_chalkMarkdown$4.logSymbols.info, ...params) : () => {};
294
+ }
295
+ function stringJoinWithSeparateFinalSeparator(list, separator = ' and ') {
296
+ const values = list.filter(value => !!value);
297
+ if (values.length < 2) {
298
+ return values[0] || '';
299
+ }
300
+ const finalValue = values.pop();
301
+ return values.join(', ') + separator + finalValue;
302
+ }
303
+ function pick(input, keys) {
304
+ const result = {};
305
+ for (const key of keys) {
306
+ result[key] = input[key];
307
+ }
308
+ return result;
309
+ }
310
+ function objectSome(obj) {
311
+ for (const key in obj) {
312
+ if (obj[key]) {
313
+ return true;
314
+ }
315
+ }
316
+ return false;
317
+ }
318
+
319
+ Object.defineProperty(formatIssues, "__esModule", {
320
+ value: true
321
+ });
322
+ formatIssues.formatSeverityCount = formatSeverityCount;
323
+ formatIssues.getSeverityCount = getSeverityCount;
324
+ var _misc$3 = misc;
325
+ const SEVERITIES_BY_ORDER = ['critical', 'high', 'middle', 'low'];
326
+ function getDesiredSeverities(lowestToInclude) {
327
+ const result = [];
328
+ for (const severity of SEVERITIES_BY_ORDER) {
329
+ result.push(severity);
330
+ if (severity === lowestToInclude) {
331
+ break;
332
+ }
333
+ }
334
+ return result;
335
+ }
336
+ function getSeverityCount(issues, lowestToInclude) {
337
+ const severityCount = (0, _misc$3.pick)({
338
+ low: 0,
339
+ middle: 0,
340
+ high: 0,
341
+ critical: 0
342
+ }, getDesiredSeverities(lowestToInclude));
343
+ for (const issue of issues) {
344
+ const value = issue.value;
345
+ if (!value) {
346
+ continue;
347
+ }
348
+ if (severityCount[value.severity] !== undefined) {
349
+ severityCount[value.severity] += 1;
350
+ }
351
+ }
352
+ return severityCount;
353
+ }
354
+ function formatSeverityCount(severityCount) {
355
+ const summary = [];
356
+ for (const severity of SEVERITIES_BY_ORDER) {
357
+ if (severityCount[severity]) {
358
+ summary.push(`${severityCount[severity]} ${severity}`);
359
+ }
360
+ }
361
+ return (0, _misc$3.stringJoinWithSeparateFinalSeparator)(summary);
362
+ }
363
+
364
+ var formatting = {};
365
+
366
+ Object.defineProperty(formatting, "__esModule", {
367
+ value: true
368
+ });
369
+ formatting.printFlagList = printFlagList;
370
+ formatting.printHelpList = printHelpList;
371
+ function printHelpList(list, indent, {
372
+ keyPrefix = '',
373
+ padName = 18
374
+ } = {}) {
375
+ const names = Object.keys(list).sort();
376
+ let result = '';
377
+ for (const name of names) {
378
+ const rawDescription = list[name];
379
+ const description = (typeof rawDescription === 'object' ? rawDescription.description : rawDescription) || '';
380
+ result += ''.padEnd(indent) + (keyPrefix + name).padEnd(padName) + description + '\n';
381
+ }
382
+ return result.trim();
383
+ }
384
+ function printFlagList(list, indent, {
385
+ keyPrefix = '--',
386
+ padName
387
+ } = {}) {
388
+ return printHelpList({
389
+ help: 'Print this help and exits.',
390
+ version: 'Prints current version and exits.',
391
+ ...list
392
+ }, indent, {
393
+ keyPrefix,
394
+ padName
395
+ });
396
+ }
397
+
398
+ var _interopRequireDefault$m = vendor.interopRequireDefault.default;
399
+ Object.defineProperty(info$1, "__esModule", {
400
+ value: true
401
+ });
402
+ info$1.info = void 0;
403
+ var _chalk$f = _interopRequireDefault$m(vendor.source);
404
+ var _meow$l = _interopRequireDefault$m(vendor.build);
405
+ var _ora$h = _interopRequireDefault$m(vendor.ora);
406
+ var _flags$f = flags;
407
+ var _apiHelpers$f = apiHelpers;
408
+ var _chalkMarkdown$3 = sdk.chalkMarkdown;
409
+ var _errors$h = sdk.errors;
410
+ var _formatIssues$1 = formatIssues;
411
+ var _formatting$i = formatting;
412
+ var _misc$2 = misc;
413
+ var _sdk$g = sdk.sdk;
414
+ const info = info$1.info = {
415
+ description: 'Look up info regarding a package',
416
+ async run(argv, importMeta, {
417
+ parentName
418
+ }) {
419
+ const name = parentName + ' info';
420
+ const input = setupCommand$i(name, info.description, argv, importMeta);
421
+ if (input) {
422
+ const spinnerText = input.pkgVersion === 'latest' ? `Looking up data for the latest version of ${input.pkgName}\n` : `Looking up data for version ${input.pkgVersion} of ${input.pkgName}\n`;
423
+ const spinner = (0, _ora$h.default)(spinnerText).start();
424
+ const packageData = await fetchPackageData(input.pkgName, input.pkgVersion, input, spinner);
425
+ if (packageData) {
426
+ formatPackageDataOutput(packageData, {
427
+ name,
428
+ ...input
429
+ }, spinner);
430
+ }
431
+ }
432
+ }
433
+ };
434
+
435
+ // Internal functions
436
+
437
+ function setupCommand$i(name, description, argv, importMeta) {
438
+ const flags = {
439
+ ..._flags$f.outputFlags,
440
+ ..._flags$f.validationFlags
441
+ };
442
+ const cli = (0, _meow$l.default)(`
443
+ Usage
444
+ $ ${name} <name>
445
+
446
+ Options
447
+ ${(0, _formatting$i.printFlagList)(flags, 6)}
448
+
449
+ Examples
450
+ $ ${name} webtorrent
451
+ $ ${name} webtorrent@1.9.1
452
+ `, {
453
+ argv,
454
+ description,
455
+ importMeta,
456
+ flags
457
+ });
458
+ const {
459
+ all: includeAllIssues,
460
+ json: outputJson,
461
+ markdown: outputMarkdown,
462
+ strict
463
+ } = cli.flags;
464
+ if (cli.input.length > 1) {
465
+ throw new _errors$h.InputError('Only one package lookup supported at once');
466
+ }
467
+ const [rawPkgName = ''] = cli.input;
468
+ if (!rawPkgName) {
469
+ cli.showHelp();
470
+ return;
471
+ }
472
+ const versionSeparator = rawPkgName.lastIndexOf('@');
473
+ const pkgName = versionSeparator < 1 ? rawPkgName : rawPkgName.slice(0, versionSeparator);
474
+ const pkgVersion = versionSeparator < 1 ? 'latest' : rawPkgName.slice(versionSeparator + 1);
475
+ return {
476
+ includeAllIssues,
477
+ outputJson,
478
+ outputMarkdown,
479
+ pkgName,
480
+ pkgVersion,
481
+ strict
482
+ };
483
+ }
484
+ async function fetchPackageData(pkgName, pkgVersion, {
485
+ includeAllIssues
486
+ }, spinner) {
487
+ const socketSdk = await (0, _sdk$g.setupSdk)((0, _sdk$g.getDefaultKey)() || _sdk$g.FREE_API_KEY);
488
+ const result = await (0, _apiHelpers$f.handleApiCall)(socketSdk.getIssuesByNPMPackage(pkgName, pkgVersion), 'looking up package');
489
+ const scoreResult = await (0, _apiHelpers$f.handleApiCall)(socketSdk.getScoreByNPMPackage(pkgName, pkgVersion), 'looking up package score');
490
+ if (result.success === false) {
491
+ return (0, _apiHelpers$f.handleUnsuccessfulApiResponse)('getIssuesByNPMPackage', result, spinner);
492
+ }
493
+ if (scoreResult.success === false) {
494
+ return (0, _apiHelpers$f.handleUnsuccessfulApiResponse)('getScoreByNPMPackage', scoreResult, spinner);
495
+ }
496
+ const severityCount = (0, _formatIssues$1.getSeverityCount)(result.data, includeAllIssues ? undefined : 'high');
497
+ return {
498
+ data: result.data,
499
+ severityCount,
500
+ score: scoreResult.data
501
+ };
502
+ }
503
+ function formatPackageDataOutput({
504
+ data,
505
+ severityCount,
506
+ score
507
+ }, {
508
+ name,
509
+ outputJson,
510
+ outputMarkdown,
511
+ pkgName,
512
+ pkgVersion,
513
+ strict
514
+ }, spinner) {
515
+ if (outputJson) {
516
+ console.log(JSON.stringify(data, undefined, 2));
517
+ } else {
518
+ console.log('\nPackage report card:');
519
+ const scoreResult = {
520
+ 'Supply Chain Risk': Math.floor(score.supplyChainRisk.score * 100),
521
+ Maintenance: Math.floor(score.maintenance.score * 100),
522
+ Quality: Math.floor(score.quality.score * 100),
523
+ Vulnerabilities: Math.floor(score.vulnerability.score * 100),
524
+ License: Math.floor(score.license.score * 100)
525
+ };
526
+ Object.entries(scoreResult).map(score => console.log(`- ${score[0]}: ${formatScore(score[1])}`));
527
+ if ((0, _misc$2.objectSome)(severityCount)) {
528
+ const issueSummary = (0, _formatIssues$1.formatSeverityCount)(severityCount);
529
+ console.log('\n');
530
+ spinner[strict ? 'fail' : 'succeed'](`Package has these issues: ${issueSummary}`);
531
+ formatPackageIssuesDetails(data, outputMarkdown);
532
+ } else {
533
+ console.log('\n');
534
+ spinner.succeed('Package has no issues');
535
+ }
536
+ const format = new _chalkMarkdown$3.ChalkOrMarkdown(!!outputMarkdown);
537
+ const url = `https://socket.dev/npm/package/${pkgName}/overview/${pkgVersion}`;
538
+ if (pkgVersion === 'latest') {
539
+ console.log('\nDetailed info on socket.dev: ' + format.hyperlink(`${pkgName}`, url, {
540
+ fallbackToUrl: true
541
+ }));
542
+ } else {
543
+ console.log('\nDetailed info on socket.dev: ' + format.hyperlink(`${pkgName} v${pkgVersion}`, url, {
544
+ fallbackToUrl: true
545
+ }));
546
+ }
547
+ if (!outputMarkdown) {
548
+ console.log(_chalk$f.default.dim('\nOr rerun', _chalk$f.default.italic(name), 'using the', _chalk$f.default.italic('--json'), 'flag to get full JSON output'));
549
+ }
550
+ }
551
+ if (strict && (0, _misc$2.objectSome)(severityCount)) {
552
+ process.exit(1);
553
+ }
554
+ }
555
+ function formatPackageIssuesDetails(packageData, outputMarkdown) {
556
+ const issueDetails = packageData.filter(d => d.value?.severity === 'high' || d.value?.severity === 'critical');
557
+ const uniqueIssues = issueDetails.reduce((acc, issue) => {
558
+ const {
559
+ type
560
+ } = issue;
561
+ if (type) {
562
+ if (acc[type] === undefined) {
563
+ acc[type] = {
564
+ label: issue.value?.label,
565
+ count: 1
566
+ };
567
+ } else {
568
+ acc[type].count += 1;
569
+ }
570
+ }
571
+ return acc;
572
+ }, {});
573
+ const format = new _chalkMarkdown$3.ChalkOrMarkdown(!!outputMarkdown);
574
+ for (const issue of Object.keys(uniqueIssues)) {
575
+ const issueWithLink = format.hyperlink(`${uniqueIssues[issue]?.label}`, `https://socket.dev/npm/issue/${issue}`, {
576
+ fallbackToUrl: true
577
+ });
578
+ if (uniqueIssues[issue]?.count === 1) {
579
+ console.log(`- ${issueWithLink}`);
580
+ } else {
581
+ console.log(`- ${issueWithLink}: ${uniqueIssues[issue]?.count}`);
582
+ }
583
+ }
584
+ }
585
+ function formatScore(score) {
586
+ const error = _chalk$f.default.hex('#de7c7b');
587
+ const warning = _chalk$f.default.hex('#e59361');
588
+ const success = _chalk$f.default.hex('#a4cb9d');
589
+ if (score > 80) {
590
+ return `${success(score)}`;
591
+ } else if (score < 80 && score > 60) {
592
+ return `${warning(score)}`;
593
+ }
594
+ return `${error(score)}`;
595
+ }
596
+
597
+ var login = {};
598
+
599
+ var _interopRequireDefault$l = vendor.interopRequireDefault.default;
600
+ Object.defineProperty(login, "__esModule", {
601
+ value: true
602
+ });
603
+ login.login = void 0;
604
+ var _prompts$1 = require$$1$1;
605
+ var _isInteractive = _interopRequireDefault$l(vendor.isInteractive);
606
+ var _meow$k = _interopRequireDefault$l(vendor.build);
607
+ var _ora$g = _interopRequireDefault$l(vendor.ora);
608
+ var _terminalLink = _interopRequireDefault$l(vendor.terminalLink);
609
+ var _errors$g = sdk.errors;
610
+ var _formatting$h = formatting;
611
+ var _sdk$f = sdk.sdk;
612
+ var _settings$1 = sdk.settings;
613
+ const description$6 = 'Socket API login';
614
+ login.login = {
615
+ description: description$6,
616
+ run: async (argv, importMeta, {
617
+ parentName
618
+ }) => {
619
+ const flags = {
620
+ apiBaseUrl: {
621
+ type: 'string',
622
+ description: 'API server to connect to for login'
623
+ },
624
+ apiProxy: {
625
+ type: 'string',
626
+ description: 'Proxy to use when making connection to API server'
627
+ }
628
+ };
629
+ const name = `${parentName} login`;
630
+ const cli = (0, _meow$k.default)(`
631
+ Usage
632
+ $ ${name}
633
+
634
+ Logs into the Socket API by prompting for an API key
635
+
636
+ Options
637
+ ${(0, _formatting$h.printFlagList)({
638
+ 'api-base-url': flags['apiBaseUrl'].description,
639
+ 'api-proxy': flags['apiProxy'].description
640
+ }, 8)}
641
+
642
+ Examples
643
+ $ ${name}
644
+ `, {
645
+ argv,
646
+ description: description$6,
647
+ importMeta,
648
+ flags
649
+ });
650
+ if (cli.input.length) {
651
+ cli.showHelp();
652
+ }
653
+ if (!(0, _isInteractive.default)()) {
654
+ throw new _errors$g.InputError('Cannot prompt for credentials in a non-interactive shell');
655
+ }
656
+ const apiKey = (await (0, _prompts$1.password)({
657
+ message: `Enter your ${(0, _terminalLink.default)('Socket.dev API key', 'https://docs.socket.dev/docs/api-keys')} (leave blank for a public key)`
658
+ })) || _sdk$f.FREE_API_KEY;
659
+ let apiBaseUrl = cli.flags['apiBaseUrl'];
660
+ apiBaseUrl ??= (0, _settings$1.getSetting)('apiBaseUrl') ?? undefined;
661
+ let apiProxy = cli.flags['apiProxy'];
662
+ apiProxy ??= (0, _settings$1.getSetting)('apiProxy') ?? undefined;
663
+ const spinner = (0, _ora$g.default)('Verifying API key...').start();
664
+ let orgs;
665
+ try {
666
+ const sdk = await (0, _sdk$f.setupSdk)(apiKey, apiBaseUrl, apiProxy);
667
+ const result = await sdk.getOrganizations();
668
+ if (!result.success) {
669
+ throw new _errors$g.AuthError();
670
+ }
671
+ orgs = result.data;
672
+ spinner.succeed('API key verified\n');
673
+ } catch {
674
+ spinner.fail('Invalid API key');
675
+ return;
676
+ }
677
+ const nonNullish = value => value != null;
678
+ const enforcedChoices = Object.values(orgs.organizations).filter(nonNullish).filter(org => org.plan === 'enterprise').map(org => ({
679
+ name: org.name,
680
+ value: org.id
681
+ }));
682
+ let enforcedOrgs = [];
683
+ if (enforcedChoices.length > 1) {
684
+ const id = await (0, _prompts$1.select)({
685
+ message: "Which organization's policies should Socket enforce system-wide?",
686
+ choices: enforcedChoices.concat({
687
+ name: 'None',
688
+ value: '',
689
+ description: 'Pick "None" if this is a personal device'
690
+ })
691
+ });
692
+ if (id) {
693
+ enforcedOrgs = [id];
694
+ }
695
+ } else if (enforcedChoices.length) {
696
+ const confirmOrg = await (0, _prompts$1.confirm)({
697
+ message: `Should Socket enforce ${enforcedChoices[0]?.name}'s security policies system-wide?`,
698
+ default: true
699
+ });
700
+ if (confirmOrg) {
701
+ const existing = enforcedChoices[0];
702
+ if (existing) {
703
+ enforcedOrgs = [existing.value];
704
+ }
705
+ }
706
+ }
707
+ (0, _settings$1.updateSetting)('enforcedOrgs', enforcedOrgs);
708
+ const oldKey = (0, _settings$1.getSetting)('apiKey');
709
+ (0, _settings$1.updateSetting)('apiKey', apiKey);
710
+ (0, _settings$1.updateSetting)('apiBaseUrl', apiBaseUrl);
711
+ (0, _settings$1.updateSetting)('apiProxy', apiProxy);
712
+ spinner.succeed(`API credentials ${oldKey ? 'updated' : 'set'}`);
713
+ }
714
+ };
715
+
716
+ var logout = {};
717
+
718
+ var _interopRequireDefault$k = vendor.interopRequireDefault.default;
719
+ Object.defineProperty(logout, "__esModule", {
720
+ value: true
721
+ });
722
+ logout.logout = void 0;
723
+ var _meow$j = _interopRequireDefault$k(vendor.build);
724
+ var _ora$f = _interopRequireDefault$k(vendor.ora);
725
+ var _settings = sdk.settings;
726
+ const description$5 = 'Socket API logout';
727
+ logout.logout = {
728
+ description: description$5,
729
+ run: async (argv, importMeta, {
730
+ parentName
731
+ }) => {
732
+ const name = `${parentName} logout`;
733
+ const cli = (0, _meow$j.default)(`
734
+ Usage
735
+ $ ${name}
736
+
737
+ Logs out of the Socket API and clears all Socket credentials from disk
738
+
739
+ Examples
740
+ $ ${name}
741
+ `, {
742
+ argv,
743
+ description: description$5,
744
+ importMeta
745
+ });
746
+ if (cli.input.length) {
747
+ cli.showHelp();
748
+ }
749
+ (0, _settings.updateSetting)('apiKey', null);
750
+ (0, _settings.updateSetting)('apiBaseUrl', null);
751
+ (0, _settings.updateSetting)('apiProxy', null);
752
+ (0, _settings.updateSetting)('enforcedOrgs', null);
753
+ (0, _ora$f.default)('Successfully logged out').succeed();
754
+ }
755
+ };
756
+
757
+ var npm = {};
758
+
759
+ Object.defineProperty(npm, "__esModule", {
760
+ value: true
761
+ });
762
+ npm.npm = void 0;
763
+ var _nodeChild_process$1 = require$$0$1;
764
+ var _nodePath$3 = require$$1;
765
+ const distPath$2 = __dirname;
766
+ const description$4 = 'npm wrapper functionality';
767
+ npm.npm = {
768
+ description: description$4,
769
+ run: async (argv, _importMeta, _ctx) => {
770
+ const npmVersion = (0, _nodeChild_process$1.execSync)('npm -v').toString();
771
+ const wrapperPath = _nodePath$3.join(distPath$2, 'npm-cli.js');
772
+ process.exitCode = 1;
773
+ (0, _nodeChild_process$1.spawn)(process.execPath, [wrapperPath, ...argv], {
774
+ stdio: 'inherit',
775
+ env: {
776
+ ...process.env,
777
+ NPM_VERSION: npmVersion
778
+ }
779
+ }).on('exit', (code, signal) => {
780
+ if (signal) {
781
+ process.kill(process.pid, signal);
782
+ } else if (code !== null) {
783
+ process.exit(code);
784
+ }
785
+ });
786
+ }
787
+ };
788
+
789
+ var npx = {};
790
+
791
+ Object.defineProperty(npx, "__esModule", {
792
+ value: true
793
+ });
794
+ npx.npx = void 0;
795
+ var _child_process$1 = require$$0$1;
796
+ var _nodePath$2 = require$$1;
797
+ const distPath$1 = __dirname;
798
+ const description$3 = 'npx wrapper functionality';
799
+ npx.npx = {
800
+ description: description$3,
801
+ run: async (argv, _importMeta, _ctx) => {
802
+ const wrapperPath = _nodePath$2.join(distPath$1, 'npx-cli.js');
803
+ process.exitCode = 1;
804
+ (0, _child_process$1.spawn)(process.execPath, [wrapperPath, ...argv], {
805
+ stdio: 'inherit'
806
+ }).on('exit', (code, signal) => {
807
+ if (signal) {
808
+ process.kill(process.pid, signal);
809
+ } else if (code !== null) {
810
+ process.exit(code);
811
+ }
812
+ });
813
+ }
814
+ };
815
+
816
+ var organization = {};
817
+
818
+ var _interopRequireDefault$j = vendor.interopRequireDefault.default;
819
+ Object.defineProperty(organization, "__esModule", {
820
+ value: true
821
+ });
822
+ organization.organizations = void 0;
823
+ var _chalk$e = _interopRequireDefault$j(vendor.source);
824
+ var _meow$i = _interopRequireDefault$j(vendor.build);
825
+ var _ora$e = _interopRequireDefault$j(vendor.ora);
826
+ var _apiHelpers$e = apiHelpers;
827
+ var _sdk$e = sdk.sdk;
828
+ var _errors$f = sdk.errors;
829
+ const organizations = organization.organizations = {
830
+ description: 'List organizations associated with the API key used',
831
+ async run(argv, importMeta, {
832
+ parentName
833
+ }) {
834
+ const name = `${parentName} organizations`;
835
+ setupCommand$h(name, organizations.description, argv, importMeta);
836
+ await fetchOrganizations();
837
+ }
838
+ };
839
+
840
+ // Internal functions
841
+
842
+ function setupCommand$h(name, description, argv, importMeta) {
843
+ (0, _meow$i.default)(`
844
+ Usage
845
+ $ ${name}
846
+ `, {
847
+ argv,
848
+ description,
849
+ importMeta
850
+ });
851
+ }
852
+ async function fetchOrganizations() {
853
+ const apiKey = (0, _sdk$e.getDefaultKey)();
854
+ if (!apiKey) {
855
+ throw new _errors$f.AuthError("User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.");
856
+ }
857
+ const socketSdk = await (0, _sdk$e.setupSdk)(apiKey);
858
+ const spinner = (0, _ora$e.default)('Fetching organizations...').start();
859
+ const result = await (0, _apiHelpers$e.handleApiCall)(socketSdk.getOrganizations(), 'looking up organizations');
860
+ if (result.success === false) {
861
+ (0, _apiHelpers$e.handleUnsuccessfulApiResponse)('getOrganizations', result, spinner);
862
+ return;
863
+ }
864
+ spinner.stop();
865
+ const organizations = Object.values(result.data.organizations);
866
+ console.log(`List of organizations associated with your API key: ${_chalk$e.default.italic(apiKey)}`);
867
+ for (const o of organizations) {
868
+ console.log(`
869
+ Name: ${o?.name}
870
+ ID: ${o?.id}
871
+ Plan: ${o?.plan}
872
+ `);
873
+ }
874
+ }
875
+
876
+ var rawNpm$1 = {};
877
+
878
+ var _interopRequireDefault$i = vendor.interopRequireDefault.default;
879
+ Object.defineProperty(rawNpm$1, "__esModule", {
880
+ value: true
881
+ });
882
+ rawNpm$1.rawNpm = void 0;
883
+ var _nodeChild_process = require$$0$1;
884
+ var _meow$h = _interopRequireDefault$i(vendor.build);
885
+ var _flags$e = flags;
886
+ var _formatting$g = formatting;
887
+ const rawNpm = rawNpm$1.rawNpm = {
888
+ description: 'Temporarily disable the Socket npm wrapper',
889
+ async run(argv, importMeta, {
890
+ parentName
891
+ }) {
892
+ const name = `${parentName} raw-npm`;
893
+ setupCommand$g(name, rawNpm.description, argv, importMeta);
894
+ }
895
+ };
896
+ function setupCommand$g(name, description, argv, importMeta) {
897
+ const flags = _flags$e.validationFlags;
898
+ const cli = (0, _meow$h.default)(`
899
+ Usage
900
+ $ ${name} <npm command>
901
+
902
+ Options
903
+ ${(0, _formatting$g.printFlagList)(flags, 6)}
904
+
905
+ Examples
906
+ $ ${name} install
907
+ `, {
908
+ argv,
909
+ description,
910
+ importMeta,
911
+ flags
912
+ });
913
+ if (!argv[0]) {
914
+ cli.showHelp();
915
+ return;
916
+ }
917
+ (0, _nodeChild_process.spawn)('npm', [argv.join(' ')], {
918
+ stdio: 'inherit',
919
+ shell: true
920
+ }).on('exit', (code, signal) => {
921
+ if (signal) {
922
+ process.kill(process.pid, signal);
923
+ } else if (code !== null) {
924
+ process.exit(code);
925
+ }
926
+ });
927
+ }
928
+
929
+ var rawNpx$1 = {};
930
+
931
+ var _interopRequireDefault$h = vendor.interopRequireDefault.default;
932
+ Object.defineProperty(rawNpx$1, "__esModule", {
933
+ value: true
934
+ });
935
+ rawNpx$1.rawNpx = void 0;
936
+ var _child_process = require$$0$1;
937
+ var _meow$g = _interopRequireDefault$h(vendor.build);
938
+ var _flags$d = flags;
939
+ var _formatting$f = formatting;
940
+ const rawNpx = rawNpx$1.rawNpx = {
941
+ description: 'Temporarily disable the Socket npm/npx wrapper',
942
+ async run(argv, importMeta, {
943
+ parentName
944
+ }) {
945
+ const name = `${parentName} raw-npx`;
946
+ setupCommand$f(name, rawNpx.description, argv, importMeta);
947
+ }
948
+ };
949
+ function setupCommand$f(name, description, argv, importMeta) {
950
+ const flags = _flags$d.validationFlags;
951
+ const cli = (0, _meow$g.default)(`
952
+ Usage
953
+ $ ${name} <npx command>
954
+
955
+ Options
956
+ ${(0, _formatting$f.printFlagList)(flags, 6)}
957
+
958
+ Examples
959
+ $ ${name} install
960
+ `, {
961
+ argv,
962
+ description,
963
+ importMeta,
964
+ flags
965
+ });
966
+ if (!argv[0]) {
967
+ cli.showHelp();
968
+ return;
969
+ }
970
+ (0, _child_process.spawn)('npx', [argv.join(' ')], {
971
+ stdio: 'inherit',
972
+ shell: true
973
+ }).on('exit', (code, signal) => {
974
+ if (signal) {
975
+ process.kill(process.pid, signal);
976
+ } else if (code !== null) {
977
+ process.exit(code);
978
+ }
979
+ });
980
+ }
981
+
982
+ var report = {};
983
+
984
+ var create$5 = {};
985
+
986
+ var view$3 = {};
987
+
988
+ var _interopRequireDefault$g = vendor.interopRequireDefault.default;
989
+ Object.defineProperty(view$3, "__esModule", {
990
+ value: true
991
+ });
992
+ view$3.fetchReportData = fetchReportData;
993
+ view$3.formatReportDataOutput = formatReportDataOutput;
994
+ view$3.view = void 0;
995
+ var _chalk$d = _interopRequireDefault$g(vendor.source);
996
+ var _meow$f = _interopRequireDefault$g(vendor.build);
997
+ var _ora$d = _interopRequireDefault$g(vendor.ora);
998
+ var _ponyCause$3 = require$$6;
999
+ var _flags$c = flags;
1000
+ var _apiHelpers$d = apiHelpers;
1001
+ var _chalkMarkdown$2 = sdk.chalkMarkdown;
1002
+ var _errors$e = sdk.errors;
1003
+ var _formatIssues = formatIssues;
1004
+ var _formatting$e = formatting;
1005
+ var _sdk$d = sdk.sdk;
1006
+ const view$2 = view$3.view = {
1007
+ description: 'View a project report',
1008
+ async run(argv, importMeta, {
1009
+ parentName
1010
+ }) {
1011
+ const name = `${parentName} view`;
1012
+ const input = setupCommand$e(name, view$2.description, argv, importMeta);
1013
+ const result = input ? await fetchReportData(input.reportId, input) : undefined;
1014
+ if (result) {
1015
+ formatReportDataOutput(result, {
1016
+ name,
1017
+ ...input
1018
+ });
1019
+ }
1020
+ }
1021
+ };
1022
+
1023
+ // Internal functions
1024
+
1025
+ function setupCommand$e(name, description, argv, importMeta) {
1026
+ const flags = {
1027
+ ..._flags$c.outputFlags,
1028
+ ..._flags$c.validationFlags
1029
+ };
1030
+ const cli = (0, _meow$f.default)(`
1031
+ Usage
1032
+ $ ${name} <report-identifier>
1033
+
1034
+ Options
1035
+ ${(0, _formatting$e.printFlagList)(flags, 6)}
1036
+
1037
+ Examples
1038
+ $ ${name} QXU8PmK7LfH608RAwfIKdbcHgwEd_ZeWJ9QEGv05FJUQ
1039
+ `, {
1040
+ argv,
1041
+ description,
1042
+ importMeta,
1043
+ flags
1044
+ });
1045
+
1046
+ // Extract the input
1047
+
1048
+ const {
1049
+ all: includeAllIssues,
1050
+ json: outputJson,
1051
+ markdown: outputMarkdown,
1052
+ strict
1053
+ } = cli.flags;
1054
+ const [reportId, ...extraInput] = cli.input;
1055
+ if (!reportId) {
1056
+ cli.showHelp();
1057
+ return;
1058
+ }
1059
+
1060
+ // Validate the input
1061
+
1062
+ if (extraInput.length) {
1063
+ throw new _errors$e.InputError(`Can only handle a single report ID at a time, but got ${cli.input.length} report ID:s: ${cli.input.join(', ')}`);
1064
+ }
1065
+ return {
1066
+ includeAllIssues,
1067
+ outputJson,
1068
+ outputMarkdown,
1069
+ reportId,
1070
+ strict
1071
+ };
1072
+ }
1073
+ const MAX_TIMEOUT_RETRY = 5;
1074
+ async function fetchReportData(reportId, {
1075
+ includeAllIssues,
1076
+ strict
1077
+ }) {
1078
+ // Do the API call
1079
+
1080
+ const socketSdk = await (0, _sdk$d.setupSdk)();
1081
+ const spinner = (0, _ora$d.default)(`Fetching report with ID ${reportId} (this could take a while)`).start();
1082
+ let result;
1083
+ for (let retry = 1; !result; ++retry) {
1084
+ try {
1085
+ result = await (0, _apiHelpers$d.handleApiCall)(socketSdk.getReport(reportId), 'fetching report');
1086
+ } catch (err) {
1087
+ if (retry >= MAX_TIMEOUT_RETRY || !(err instanceof _ponyCause$3.ErrorWithCause) || err.cause?.cause?.response?.statusCode !== 524) {
1088
+ throw err;
1089
+ }
1090
+ }
1091
+ }
1092
+ if (result.success === false) {
1093
+ return (0, _apiHelpers$d.handleUnsuccessfulApiResponse)('getReport', result, spinner);
1094
+ }
1095
+
1096
+ // Conclude the status of the API call
1097
+
1098
+ if (strict) {
1099
+ if (result.data.healthy) {
1100
+ spinner.succeed('Report result is healthy and great!');
1101
+ } else {
1102
+ spinner.fail('Report result deemed unhealthy for project');
1103
+ }
1104
+ } else if (result.data.healthy === false) {
1105
+ const severityCount = (0, _formatIssues.getSeverityCount)(result.data.issues, includeAllIssues ? undefined : 'high');
1106
+ const issueSummary = (0, _formatIssues.formatSeverityCount)(severityCount);
1107
+ spinner.succeed(`Report has these issues: ${issueSummary}`);
1108
+ } else {
1109
+ spinner.succeed('Report has no issues');
1110
+ }
1111
+ return result.data;
1112
+ }
1113
+ function formatReportDataOutput(data, {
1114
+ name,
1115
+ outputJson,
1116
+ outputMarkdown,
1117
+ reportId,
1118
+ strict
1119
+ }) {
1120
+ if (outputJson) {
1121
+ console.log(JSON.stringify(data, undefined, 2));
1122
+ } else {
1123
+ const format = new _chalkMarkdown$2.ChalkOrMarkdown(!!outputMarkdown);
1124
+ console.log('\nDetailed info on socket.dev: ' + format.hyperlink(reportId, data.url, {
1125
+ fallbackToUrl: true
1126
+ }));
1127
+ if (!outputMarkdown) {
1128
+ console.log(_chalk$d.default.dim('\nOr rerun', _chalk$d.default.italic(name), 'using the', _chalk$d.default.italic('--json'), 'flag to get full JSON output'));
1129
+ }
1130
+ }
1131
+ if (strict && data.healthy === false) {
1132
+ process.exit(1);
1133
+ }
1134
+ }
1135
+
1136
+ var _interopRequireDefault$f = vendor.interopRequireDefault.default;
1137
+ Object.defineProperty(create$5, "__esModule", {
1138
+ value: true
1139
+ });
1140
+ create$5.create = void 0;
1141
+ var _nodePath$1 = require$$1;
1142
+ var _betterAjvErrors = require$$2;
1143
+ var _config = require$$3;
1144
+ var _meow$e = _interopRequireDefault$f(vendor.build);
1145
+ var _ora$c = _interopRequireDefault$f(vendor.ora);
1146
+ var _ponyCause$2 = require$$6;
1147
+ var _view$2 = view$3;
1148
+ var _flags$b = flags;
1149
+ var _apiHelpers$c = apiHelpers;
1150
+ var _chalkMarkdown$1 = sdk.chalkMarkdown;
1151
+ var _errors$d = sdk.errors;
1152
+ var _formatting$d = formatting;
1153
+ var _misc$1 = misc;
1154
+ var _pathResolve$1 = pathResolve.pathResolve;
1155
+ var _sdk$c = sdk.sdk;
1156
+ const create$4 = create$5.create = {
1157
+ description: 'Create a project report',
1158
+ async run(argv, importMeta, {
1159
+ parentName
1160
+ }) {
1161
+ const name = `${parentName} create`;
1162
+ const input = await setupCommand$d(name, create$4.description, argv, importMeta);
1163
+ if (input) {
1164
+ const {
1165
+ config,
1166
+ cwd,
1167
+ debugLog,
1168
+ dryRun,
1169
+ includeAllIssues,
1170
+ outputJson,
1171
+ outputMarkdown,
1172
+ packagePaths,
1173
+ strict,
1174
+ view
1175
+ } = input;
1176
+ const result = input && (await createReport(packagePaths, {
1177
+ config,
1178
+ cwd,
1179
+ debugLog,
1180
+ dryRun
1181
+ }));
1182
+ if (result && view) {
1183
+ const reportId = result.data.id;
1184
+ const reportData = input && (await (0, _view$2.fetchReportData)(reportId, {
1185
+ includeAllIssues,
1186
+ strict
1187
+ }));
1188
+ if (reportData) {
1189
+ (0, _view$2.formatReportDataOutput)(reportData, {
1190
+ includeAllIssues,
1191
+ name,
1192
+ outputJson,
1193
+ outputMarkdown,
1194
+ reportId,
1195
+ strict
1196
+ });
1197
+ }
1198
+ } else if (result) {
1199
+ formatReportCreationOutput(result.data, {
1200
+ outputJson,
1201
+ outputMarkdown
1202
+ });
1203
+ }
1204
+ }
1205
+ }
1206
+ };
1207
+
1208
+ // Internal functions
1209
+
1210
+ async function setupCommand$d(name, description, argv, importMeta) {
1211
+ const flags = {
1212
+ ..._flags$b.outputFlags,
1213
+ ..._flags$b.validationFlags,
1214
+ debug: {
1215
+ type: 'boolean',
1216
+ shortFlag: 'd',
1217
+ default: false,
1218
+ description: 'Output debug information'
1219
+ },
1220
+ dryRun: {
1221
+ type: 'boolean',
1222
+ default: false,
1223
+ description: 'Only output what will be done without actually doing it'
1224
+ },
1225
+ view: {
1226
+ type: 'boolean',
1227
+ shortFlag: 'v',
1228
+ default: false,
1229
+ description: 'Will wait for and return the created report'
1230
+ }
1231
+ };
1232
+ const cli = (0, _meow$e.default)(`
1233
+ Usage
1234
+ $ ${name} <paths-to-package-folders-and-files>
1235
+
1236
+ Uploads the specified "package.json" and lock files for JavaScript, Python, and Go dependency manifests.
1237
+ If any folder is specified, the ones found in there recursively are uploaded.
1238
+
1239
+ Supports globbing such as "**/package.json", "**/requirements.txt", "**/pyproject.toml", and "**/go.mod".
1240
+
1241
+ Ignores any file specified in your project's ".gitignore", your project's
1242
+ "socket.yml" file's "projectIgnorePaths" and also has a sensible set of
1243
+ default ignores from the "ignore-by-default" module.
1244
+
1245
+ Options
1246
+ ${(0, _formatting$d.printFlagList)({
1247
+ all: 'Include all issues',
1248
+ debug: 'Output debug information',
1249
+ 'dry-run': 'Only output what will be done without actually doing it',
1250
+ json: 'Output result as json',
1251
+ markdown: 'Output result as markdown',
1252
+ strict: 'Exits with an error code if any matching issues are found',
1253
+ view: 'Will wait for and return the created report'
1254
+ }, 6)}
1255
+
1256
+ Examples
1257
+ $ ${name} .
1258
+ $ ${name} '**/package.json'
1259
+ $ ${name} /path/to/a/package.json /path/to/another/package.json
1260
+ $ ${name} . --view --json
1261
+ `, {
1262
+ argv,
1263
+ description,
1264
+ importMeta,
1265
+ flags
1266
+ });
1267
+ const {
1268
+ all: includeAllIssues,
1269
+ dryRun,
1270
+ json: outputJson,
1271
+ markdown: outputMarkdown,
1272
+ strict,
1273
+ view
1274
+ } = cli.flags;
1275
+ if (!cli.input[0]) {
1276
+ cli.showHelp();
1277
+ return;
1278
+ }
1279
+ const debugLog = (0, _misc$1.createDebugLogger)(!dryRun || cli.flags['debug']);
1280
+
1281
+ // TODO: Allow setting a custom cwd and/or configFile path?
1282
+ const cwd = process.cwd();
1283
+ const absoluteConfigPath = _nodePath$1.join(cwd, 'socket.yml');
1284
+ const config = await (0, _config.readSocketConfig)(absoluteConfigPath).catch(cause => {
1285
+ if (cause && typeof cause === 'object' && cause instanceof _config.SocketValidationError) {
1286
+ // Inspired by workbox-build: https://github.com/GoogleChrome/workbox/blob/95f97a207fd51efb3f8a653f6e3e58224183a778/packages/workbox-build/src/lib/validate-options.ts#L68-L71
1287
+ const betterErrors = (0, _betterAjvErrors.betterAjvErrors)({
1288
+ basePath: 'config',
1289
+ data: cause.data,
1290
+ errors: cause.validationErrors,
1291
+ schema: cause.schema
1292
+ });
1293
+ throw new _errors$d.InputError('The socket.yml config is not valid', betterErrors.map(err => `[${err.path}] ${err.message}.${err.suggestion ? err.suggestion : ''}`).join('\n'));
1294
+ } else {
1295
+ throw new _ponyCause$2.ErrorWithCause('Failed to read socket.yml config', {
1296
+ cause
1297
+ });
1298
+ }
1299
+ });
1300
+ const socketSdk = await (0, _sdk$c.setupSdk)();
1301
+ const supportedFiles = await socketSdk.getReportSupportedFiles().then(res => {
1302
+ if (!res.success) (0, _apiHelpers$c.handleUnsuccessfulApiResponse)('getReportSupportedFiles', res, (0, _ora$c.default)());
1303
+ return res.data;
1304
+ }).catch(cause => {
1305
+ throw new _ponyCause$2.ErrorWithCause('Failed getting supported files for report', {
1306
+ cause
1307
+ });
1308
+ });
1309
+ const packagePaths = await (0, _pathResolve$1.getPackageFiles)(cwd, cli.input, config, supportedFiles, debugLog);
1310
+ return {
1311
+ config,
1312
+ cwd,
1313
+ debugLog,
1314
+ dryRun,
1315
+ includeAllIssues,
1316
+ outputJson,
1317
+ outputMarkdown,
1318
+ packagePaths,
1319
+ strict,
1320
+ view
1321
+ };
1322
+ }
1323
+ async function createReport(packagePaths, {
1324
+ config,
1325
+ cwd,
1326
+ debugLog,
1327
+ dryRun
1328
+ }) {
1329
+ debugLog('Uploading:', packagePaths.join(`\n${_chalkMarkdown$1.logSymbols.info} Uploading: `));
1330
+ if (dryRun) {
1331
+ return;
1332
+ }
1333
+ const socketSdk = await (0, _sdk$c.setupSdk)();
1334
+ const spinner = (0, _ora$c.default)(`Creating report with ${packagePaths.length} package files`).start();
1335
+ const apiCall = socketSdk.createReportFromFilePaths(packagePaths, cwd, config?.issueRules);
1336
+ const result = await (0, _apiHelpers$c.handleApiCall)(apiCall, 'creating report');
1337
+ if (result.success === false) {
1338
+ return (0, _apiHelpers$c.handleUnsuccessfulApiResponse)('createReport', result, spinner);
1339
+ }
1340
+
1341
+ // Conclude the status of the API call
1342
+
1343
+ spinner.succeed();
1344
+ return result;
1345
+ }
1346
+ function formatReportCreationOutput(data, {
1347
+ outputJson,
1348
+ outputMarkdown
1349
+ }) {
1350
+ if (outputJson) {
1351
+ console.log(JSON.stringify(data, undefined, 2));
1352
+ return;
1353
+ }
1354
+ const format = new _chalkMarkdown$1.ChalkOrMarkdown(!!outputMarkdown);
1355
+ console.log('\nNew report: ' + format.hyperlink(data.id, data.url, {
1356
+ fallbackToUrl: true
1357
+ }));
1358
+ }
1359
+
1360
+ var meowWithSubcommands$1 = {};
1361
+
1362
+ var _interopRequireDefault$e = vendor.interopRequireDefault.default;
1363
+ Object.defineProperty(meowWithSubcommands$1, "__esModule", {
1364
+ value: true
1365
+ });
1366
+ meowWithSubcommands$1.meowWithSubcommands = meowWithSubcommands;
1367
+ var _meow$d = _interopRequireDefault$e(vendor.build);
1368
+ var _formatting$c = formatting;
1369
+ function sortKeys(object) {
1370
+ return Object.fromEntries(Object.keys(object).sort().map(k => [k, object[k]]));
1371
+ }
1372
+ async function meowWithSubcommands(subcommands, options) {
1373
+ const {
1374
+ aliases = {},
1375
+ argv,
1376
+ name,
1377
+ importMeta,
1378
+ ...additionalOptions
1379
+ } = options;
1380
+ const [commandOrAliasName, ...rawCommandArgv] = argv;
1381
+
1382
+ // If we got at least some args, then lets find out if we can find a command
1383
+ if (commandOrAliasName) {
1384
+ const alias = aliases[commandOrAliasName];
1385
+
1386
+ // First: Resolve argv data from alias if its an alias that's been given
1387
+ const [commandName, ...commandArgv] = alias ? [...alias.argv, ...rawCommandArgv] : [commandOrAliasName, ...rawCommandArgv];
1388
+
1389
+ // Second: Find a command definition using that data
1390
+ const commandDefinition = commandName ? subcommands[commandName] : undefined;
1391
+
1392
+ // Third: If a valid command has been found, then we run it...
1393
+ if (commandDefinition) {
1394
+ return await commandDefinition.run(commandArgv, importMeta, {
1395
+ parentName: name
1396
+ });
1397
+ }
1398
+ }
1399
+
1400
+ // ...else we provide basic instructions and help
1401
+ const cli = (0, _meow$d.default)(`
1402
+ Usage
1403
+ $ ${name} <command>
1404
+
1405
+ Commands
1406
+ ${(0, _formatting$c.printHelpList)({
1407
+ ...sortKeys(subcommands),
1408
+ ...sortKeys(aliases)
1409
+ }, 6)}
1410
+
1411
+ Options
1412
+ ${(0, _formatting$c.printFlagList)({}, 6)}
1413
+
1414
+ Examples
1415
+ $ ${name} --help
1416
+ `, {
1417
+ argv,
1418
+ importMeta,
1419
+ ...additionalOptions
1420
+ });
1421
+ cli.showHelp();
1422
+ }
1423
+
1424
+ Object.defineProperty(report, "__esModule", {
1425
+ value: true
1426
+ });
1427
+ report.report = void 0;
1428
+ var _create$2 = create$5;
1429
+ var _view$1 = view$3;
1430
+ var _meowWithSubcommands$3 = meowWithSubcommands$1;
1431
+ const description$2 = '[Deprecated] Project report related commands';
1432
+ report.report = {
1433
+ description: description$2,
1434
+ run: async (argv, importMeta, {
1435
+ parentName
1436
+ }) => {
1437
+ await (0, _meowWithSubcommands$3.meowWithSubcommands)({
1438
+ create: _create$2.create,
1439
+ view: _view$1.view
1440
+ }, {
1441
+ argv,
1442
+ description: description$2,
1443
+ importMeta,
1444
+ name: parentName + ' report'
1445
+ });
1446
+ }
1447
+ };
1448
+
1449
+ var wrapper$1 = {};
1450
+
1451
+ var _interopRequireDefault$d = vendor.interopRequireDefault.default;
1452
+ Object.defineProperty(wrapper$1, "__esModule", {
1453
+ value: true
1454
+ });
1455
+ wrapper$1.wrapper = void 0;
1456
+ var _nodeFs$1 = require$$0;
1457
+ var _nodeOs = require$$0$2;
1458
+ var _nodeReadline = require$$3$1;
1459
+ var _meow$c = _interopRequireDefault$d(vendor.build);
1460
+ var _flags$a = flags;
1461
+ var _formatting$b = formatting;
1462
+ const BASH_FILE = `${_nodeOs.homedir()}/.bashrc`;
1463
+ const ZSH_BASH_FILE = `${_nodeOs.homedir()}/.zshrc`;
1464
+ const wrapper = wrapper$1.wrapper = {
1465
+ description: 'Enable or disable the Socket npm/npx wrapper',
1466
+ async run(argv, importMeta, {
1467
+ parentName
1468
+ }) {
1469
+ const name = `${parentName} wrapper`;
1470
+ setupCommand$c(name, wrapper.description, argv, importMeta);
1471
+ }
1472
+ };
1473
+ function setupCommand$c(name, description, argv, importMeta) {
1474
+ const flags = _flags$a.commandFlags;
1475
+ const cli = (0, _meow$c.default)(`
1476
+ Usage
1477
+ $ ${name} <flag>
1478
+
1479
+ Options
1480
+ ${(0, _formatting$b.printFlagList)(flags, 6)}
1481
+
1482
+ Examples
1483
+ $ ${name} --enable
1484
+ $ ${name} --disable
1485
+ `, {
1486
+ argv,
1487
+ description,
1488
+ importMeta,
1489
+ flags
1490
+ });
1491
+ const {
1492
+ enable,
1493
+ disable
1494
+ } = cli.flags;
1495
+ if (argv[0] === '--postinstall') {
1496
+ const socketWrapperEnabled = _nodeFs$1.existsSync(BASH_FILE) && checkSocketWrapperAlreadySetup(BASH_FILE) || _nodeFs$1.existsSync(ZSH_BASH_FILE) && checkSocketWrapperAlreadySetup(ZSH_BASH_FILE);
1497
+ if (!socketWrapperEnabled) {
1498
+ installSafeNpm(`The Socket CLI is now successfully installed! 🎉
1499
+
1500
+ To better protect yourself against supply-chain attacks, our "safe npm" wrapper can warn you about malicious packages whenever you run 'npm install'.
1501
+
1502
+ Do you want to install "safe npm" (this will create an alias to the socket-npm command)? (y/n)`);
1503
+ }
1504
+ return;
1505
+ }
1506
+ if (!enable && !disable) {
1507
+ cli.showHelp();
1508
+ return;
1509
+ }
1510
+ if (enable) {
1511
+ if (_nodeFs$1.existsSync(BASH_FILE)) {
1512
+ const socketWrapperEnabled = checkSocketWrapperAlreadySetup(BASH_FILE);
1513
+ !socketWrapperEnabled && addAlias(BASH_FILE);
1514
+ }
1515
+ if (_nodeFs$1.existsSync(ZSH_BASH_FILE)) {
1516
+ const socketWrapperEnabled = checkSocketWrapperAlreadySetup(ZSH_BASH_FILE);
1517
+ !socketWrapperEnabled && addAlias(ZSH_BASH_FILE);
1518
+ }
1519
+ } else if (disable) {
1520
+ if (_nodeFs$1.existsSync(BASH_FILE)) {
1521
+ removeAlias(BASH_FILE);
1522
+ }
1523
+ if (_nodeFs$1.existsSync(ZSH_BASH_FILE)) {
1524
+ removeAlias(ZSH_BASH_FILE);
1525
+ }
1526
+ }
1527
+ if (!_nodeFs$1.existsSync(BASH_FILE) && !_nodeFs$1.existsSync(ZSH_BASH_FILE)) {
1528
+ console.error('There was an issue setting up the alias in your bash profile');
1529
+ }
1530
+ return;
1531
+ }
1532
+ const installSafeNpm = query => {
1533
+ console.log(`
1534
+ _____ _ _
1535
+ | __|___ ___| |_ ___| |_
1536
+ |__ | . | _| '_| -_| _|
1537
+ |_____|___|___|_,_|___|_|
1538
+
1539
+ `);
1540
+ const rl = _nodeReadline.createInterface({
1541
+ input: process.stdin,
1542
+ output: process.stdout
1543
+ });
1544
+ return askQuestion(rl, query);
1545
+ };
1546
+ const askQuestion = (rl, query) => {
1547
+ rl.question(query, ans => {
1548
+ if (ans.toLowerCase() === 'y') {
1549
+ try {
1550
+ if (_nodeFs$1.existsSync(BASH_FILE)) {
1551
+ addAlias(BASH_FILE);
1552
+ }
1553
+ if (_nodeFs$1.existsSync(ZSH_BASH_FILE)) {
1554
+ addAlias(ZSH_BASH_FILE);
1555
+ }
1556
+ } catch (e) {
1557
+ throw new Error(`There was an issue setting up the alias: ${e}`);
1558
+ }
1559
+ rl.close();
1560
+ } else if (ans.toLowerCase() !== 'n') {
1561
+ askQuestion(rl, 'Incorrect input: please enter either y (yes) or n (no): ');
1562
+ } else {
1563
+ rl.close();
1564
+ }
1565
+ });
1566
+ };
1567
+ const addAlias = file => {
1568
+ return _nodeFs$1.appendFile(file, 'alias npm="socket npm"\nalias npx="socket npx"\n', err => {
1569
+ if (err) {
1570
+ return new Error(`There was an error setting up the alias: ${err}`);
1571
+ }
1572
+ console.log(`
1573
+ The alias was added to ${file}. Running 'npm install' will now be wrapped in Socket's "safe npm" 🎉
1574
+ If you want to disable it at any time, run \`socket wrapper --disable\`
1575
+ `);
1576
+ });
1577
+ };
1578
+ const removeAlias = file => {
1579
+ return _nodeFs$1.readFile(file, 'utf8', function (err, data) {
1580
+ if (err) {
1581
+ console.error(`There was an error removing the alias: ${err}`);
1582
+ return;
1583
+ }
1584
+ const linesWithoutSocketAlias = data.split('\n').filter(l => l !== 'alias npm="socket npm"' && l !== 'alias npx="socket npx"');
1585
+ const updatedFileContent = linesWithoutSocketAlias.join('\n');
1586
+ _nodeFs$1.writeFile(file, updatedFileContent, function (err) {
1587
+ if (err) {
1588
+ console.log(err);
1589
+ return;
1590
+ } else {
1591
+ console.log(`\nThe alias was removed from ${file}. Running 'npm install' will now run the standard npm command.\n`);
1592
+ }
1593
+ });
1594
+ });
1595
+ };
1596
+ const checkSocketWrapperAlreadySetup = file => {
1597
+ const fileContent = _nodeFs$1.readFileSync(file, 'utf-8');
1598
+ const linesWithSocketAlias = fileContent.split('\n').filter(l => l === 'alias npm="socket npm"' || l === 'alias npx="socket npx"');
1599
+ if (linesWithSocketAlias.length) {
1600
+ console.log(`The Socket npm/npx wrapper is set up in your bash profile (${file}).`);
1601
+ return true;
1602
+ }
1603
+ return false;
1604
+ };
1605
+
1606
+ var scan = {};
1607
+
1608
+ var create$3 = {};
1609
+
1610
+ var _interopRequireDefault$c = vendor.interopRequireDefault.default;
1611
+ Object.defineProperty(create$3, "__esModule", {
1612
+ value: true
1613
+ });
1614
+ create$3.create = void 0;
1615
+ var _nodeProcess = require$$0$3;
1616
+ var _promises = require$$2$1;
1617
+ var _chalk$c = _interopRequireDefault$c(vendor.source);
1618
+ var _meow$b = _interopRequireDefault$c(vendor.build);
1619
+ var _open = _interopRequireDefault$c(vendor.open);
1620
+ var _ora$b = _interopRequireDefault$c(vendor.ora);
1621
+ var _ponyCause$1 = require$$6;
1622
+ var _apiHelpers$b = apiHelpers;
1623
+ var _formatting$a = formatting;
1624
+ var _misc = misc;
1625
+ var _pathResolve = pathResolve.pathResolve;
1626
+ var _sdk$b = sdk.sdk;
1627
+ var _errors$c = sdk.errors;
1628
+ const create$2 = create$3.create = {
1629
+ description: 'Create a scan',
1630
+ async run(argv, importMeta, {
1631
+ parentName
1632
+ }) {
1633
+ const name = `${parentName} create`;
1634
+ const input = await setupCommand$b(name, create$2.description, argv, importMeta);
1635
+ if (input) {
1636
+ const apiKey = (0, _sdk$b.getDefaultKey)();
1637
+ if (!apiKey) {
1638
+ throw new _errors$c.AuthError("User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.");
1639
+ }
1640
+ const spinnerText = 'Creating a scan... \n';
1641
+ const spinner = (0, _ora$b.default)(spinnerText).start();
1642
+ await createFullScan(input, spinner, apiKey);
1643
+ }
1644
+ }
1645
+ };
1646
+ const createFullScanFlags = {
1647
+ repo: {
1648
+ type: 'string',
1649
+ shortFlag: 'r',
1650
+ default: '',
1651
+ description: 'Repository name'
1652
+ },
1653
+ branch: {
1654
+ type: 'string',
1655
+ shortFlag: 'b',
1656
+ default: '',
1657
+ description: 'Branch name'
1658
+ },
1659
+ commitMessage: {
1660
+ type: 'string',
1661
+ shortFlag: 'm',
1662
+ default: '',
1663
+ description: 'Commit message'
1664
+ },
1665
+ commitHash: {
1666
+ type: 'string',
1667
+ shortFlag: 'ch',
1668
+ default: '',
1669
+ description: 'Commit hash'
1670
+ },
1671
+ pullRequest: {
1672
+ type: 'number',
1673
+ shortFlag: 'pr',
1674
+ description: 'Commit hash'
1675
+ },
1676
+ committers: {
1677
+ type: 'string',
1678
+ shortFlag: 'c',
1679
+ default: '',
1680
+ description: 'Committers'
1681
+ },
1682
+ defaultBranch: {
1683
+ type: 'boolean',
1684
+ shortFlag: 'db',
1685
+ default: false,
1686
+ description: 'Make default branch'
1687
+ },
1688
+ pendingHead: {
1689
+ type: 'boolean',
1690
+ shortFlag: 'ph',
1691
+ default: false,
1692
+ description: 'Set as pending head'
1693
+ },
1694
+ tmp: {
1695
+ type: 'boolean',
1696
+ shortFlag: 't',
1697
+ default: false,
1698
+ description: 'Set the visibility (true/false) of the scan in your dashboard'
1699
+ }
1700
+ };
1701
+
1702
+ // Internal functions
1703
+
1704
+ async function setupCommand$b(name, description, argv, importMeta) {
1705
+ const flags = {
1706
+ ...createFullScanFlags
1707
+ };
1708
+ const cli = (0, _meow$b.default)(`
1709
+ Usage
1710
+ $ ${name} [...options]
1711
+
1712
+ Options
1713
+ ${(0, _formatting$a.printFlagList)(flags, 6)}
1714
+
1715
+ Examples
1716
+ $ ${name} --org=FakeOrg --repo=test-repo --branch=main ./package.json
1717
+ `, {
1718
+ argv,
1719
+ description,
1720
+ importMeta,
1721
+ flags
1722
+ });
1723
+ const {
1724
+ repo: repoName,
1725
+ branch: branchName,
1726
+ commitMessage,
1727
+ defaultBranch,
1728
+ pendingHead,
1729
+ tmp,
1730
+ committers,
1731
+ commitHash,
1732
+ pullRequest
1733
+ } = cli.flags;
1734
+ if (!cli.input[0]) {
1735
+ cli.showHelp();
1736
+ return;
1737
+ }
1738
+ const {
1739
+ 0: orgSlug = ''
1740
+ } = cli.input;
1741
+ const cwd = process.cwd();
1742
+ const socketSdk = await (0, _sdk$b.setupSdk)();
1743
+ const supportedFiles = await socketSdk.getReportSupportedFiles().then(res => {
1744
+ if (!res.success) (0, _apiHelpers$b.handleUnsuccessfulApiResponse)('getReportSupportedFiles', res, (0, _ora$b.default)());
1745
+ return res.data;
1746
+ }).catch( /** @type {(cause: Error) => never} */
1747
+ cause => {
1748
+ throw new _ponyCause$1.ErrorWithCause('Failed getting supported files for report', {
1749
+ cause
1750
+ });
1751
+ });
1752
+ const debugLog = (0, _misc.createDebugLogger)(false);
1753
+ const packagePaths = await (0, _pathResolve.getPackageFilesFullScans)(cwd, cli.input, supportedFiles, debugLog);
1754
+ if (!repoName || !branchName || !packagePaths.length) {
1755
+ console.error(`${_chalk$c.default.bgRed('Input error')}: Please provide the required fields:\n
1756
+ - Repository name using --repo,\n
1757
+ - Branch name using --branch\n
1758
+ - At least one file path (e.g. ./package.json).\n`);
1759
+ cli.showHelp();
1760
+ return;
1761
+ }
1762
+ return {
1763
+ orgSlug,
1764
+ repoName,
1765
+ branchName,
1766
+ commitMessage,
1767
+ defaultBranch,
1768
+ pendingHead,
1769
+ tmp,
1770
+ packagePaths,
1771
+ commitHash,
1772
+ committers,
1773
+ pullRequest
1774
+ };
1775
+ }
1776
+ async function createFullScan(input, spinner, apiKey) {
1777
+ const socketSdk = await (0, _sdk$b.setupSdk)(apiKey);
1778
+ const {
1779
+ orgSlug,
1780
+ repoName,
1781
+ branchName,
1782
+ commitMessage,
1783
+ defaultBranch,
1784
+ pendingHead,
1785
+ tmp,
1786
+ packagePaths
1787
+ } = input;
1788
+ const result = await (0, _apiHelpers$b.handleApiCall)(socketSdk.createOrgFullScan(orgSlug, {
1789
+ repo: repoName,
1790
+ branch: branchName,
1791
+ commit_message: commitMessage,
1792
+ make_default_branch: defaultBranch,
1793
+ set_as_pending_head: pendingHead,
1794
+ tmp
1795
+ }, packagePaths), 'Creating scan');
1796
+ if (!result.success) {
1797
+ (0, _apiHelpers$b.handleUnsuccessfulApiResponse)('CreateOrgFullScan', result, spinner);
1798
+ return;
1799
+ }
1800
+ spinner.stop();
1801
+ console.log('\n✅ Scan created successfully\n');
1802
+ const link = _chalk$c.default.hex('#00FFFF').underline(`${result.data.html_report_url}`);
1803
+ console.log(`Available at: ${link}\n`);
1804
+ const rl = _promises.createInterface({
1805
+ input: _nodeProcess.stdin,
1806
+ output: _nodeProcess.stdout
1807
+ });
1808
+ const answer = await rl.question('Would you like to open it in your browser? (y/n)');
1809
+ if (answer.toLowerCase() === 'y') {
1810
+ await (0, _open.default)(`${result.data.html_report_url}`);
1811
+ }
1812
+ rl.close();
1813
+ }
1814
+
1815
+ var _delete$3 = {};
1816
+
1817
+ var _interopRequireDefault$b = vendor.interopRequireDefault.default;
1818
+ Object.defineProperty(_delete$3, "__esModule", {
1819
+ value: true
1820
+ });
1821
+ _delete$3.del = void 0;
1822
+ var _chalk$b = _interopRequireDefault$b(vendor.source);
1823
+ var _meow$a = _interopRequireDefault$b(vendor.build);
1824
+ var _ora$a = _interopRequireDefault$b(vendor.ora);
1825
+ var _flags$9 = flags;
1826
+ var _apiHelpers$a = apiHelpers;
1827
+ var _formatting$9 = formatting;
1828
+ var _sdk$a = sdk.sdk;
1829
+ var _errors$b = sdk.errors;
1830
+ const del$1 = _delete$3.del = {
1831
+ description: 'Delete a scan',
1832
+ async run(argv, importMeta, {
1833
+ parentName
1834
+ }) {
1835
+ const name = `${parentName} del`;
1836
+ const input = setupCommand$a(name, del$1.description, argv, importMeta);
1837
+ if (input) {
1838
+ const apiKey = (0, _sdk$a.getDefaultKey)();
1839
+ if (!apiKey) {
1840
+ throw new _errors$b.AuthError("User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.");
1841
+ }
1842
+ const spinnerText = 'Deleting scan...';
1843
+ const spinner = (0, _ora$a.default)(spinnerText).start();
1844
+ await deleteOrgFullScan(input.orgSlug, input.fullScanId, spinner, apiKey);
1845
+ }
1846
+ }
1847
+ };
1848
+
1849
+ // Internal functions
1850
+
1851
+ function setupCommand$a(name, description, argv, importMeta) {
1852
+ const flags = {
1853
+ ..._flags$9.outputFlags
1854
+ };
1855
+ const cli = (0, _meow$a.default)(`
1856
+ Usage
1857
+ $ ${name} <org slug> <scan ID>
1858
+
1859
+ Options
1860
+ ${(0, _formatting$9.printFlagList)(flags, 6)}
1861
+
1862
+ Examples
1863
+ $ ${name} FakeOrg 000aaaa1-0000-0a0a-00a0-00a0000000a0
1864
+ `, {
1865
+ argv,
1866
+ description,
1867
+ importMeta,
1868
+ flags
1869
+ });
1870
+ const {
1871
+ json: outputJson,
1872
+ markdown: outputMarkdown
1873
+ } = cli.flags;
1874
+ if (cli.input.length < 2) {
1875
+ console.error(`${_chalk$b.default.bgRed('Input error')}: Please specify an organization slug and a scan ID.\n`);
1876
+ cli.showHelp();
1877
+ return;
1878
+ }
1879
+ const {
1880
+ 0: orgSlug = '',
1881
+ 1: fullScanId = ''
1882
+ } = cli.input;
1883
+ return {
1884
+ outputJson,
1885
+ outputMarkdown,
1886
+ orgSlug,
1887
+ fullScanId
1888
+ };
1889
+ }
1890
+ async function deleteOrgFullScan(orgSlug, fullScanId, spinner, apiKey) {
1891
+ const socketSdk = await (0, _sdk$a.setupSdk)(apiKey);
1892
+ const result = await (0, _apiHelpers$a.handleApiCall)(socketSdk.deleteOrgFullScan(orgSlug, fullScanId), 'Deleting scan');
1893
+ if (!result.success) {
1894
+ (0, _apiHelpers$a.handleUnsuccessfulApiResponse)('deleteOrgFullScan', result, spinner);
1895
+ return;
1896
+ }
1897
+ spinner.stop();
1898
+ console.log('\n ✅ Scan deleted successfully\n');
1899
+ }
1900
+
1901
+ var list$3 = {};
1902
+
1903
+ var _interopRequireDefault$a = vendor.interopRequireDefault.default;
1904
+ Object.defineProperty(list$3, "__esModule", {
1905
+ value: true
1906
+ });
1907
+ list$3.list = void 0;
1908
+ var _chalk$a = _interopRequireDefault$a(vendor.source);
1909
+ var _chalkTable$3 = require$$2$2;
1910
+ var _meow$9 = _interopRequireDefault$a(vendor.build);
1911
+ var _ora$9 = _interopRequireDefault$a(vendor.ora);
1912
+ var _flags$8 = flags;
1913
+ var _apiHelpers$9 = apiHelpers;
1914
+ var _formatting$8 = formatting;
1915
+ var _sdk$9 = sdk.sdk;
1916
+ var _errors$a = sdk.errors;
1917
+ // @ts-ignore
1918
+
1919
+ const list$2 = list$3.list = {
1920
+ description: 'List scans for an organization',
1921
+ async run(argv, importMeta, {
1922
+ parentName
1923
+ }) {
1924
+ const name = `${parentName} list`;
1925
+ const input = setupCommand$9(name, list$2.description, argv, importMeta);
1926
+ if (input) {
1927
+ const apiKey = (0, _sdk$9.getDefaultKey)();
1928
+ if (!apiKey) {
1929
+ throw new _errors$a.AuthError("User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.");
1930
+ }
1931
+ const spinnerText = 'Listing scans... \n';
1932
+ const spinner = (0, _ora$9.default)(spinnerText).start();
1933
+ await listOrgFullScan(input.orgSlug, input, spinner, apiKey);
1934
+ }
1935
+ }
1936
+ };
1937
+ const listFullScanFlags = {
1938
+ sort: {
1939
+ type: 'string',
1940
+ shortFlag: 's',
1941
+ default: 'created_at',
1942
+ description: 'Sorting option (`name` or `created_at`) - default is `created_at`'
1943
+ },
1944
+ direction: {
1945
+ type: 'string',
1946
+ shortFlag: 'd',
1947
+ default: 'desc',
1948
+ description: 'Direction option (`desc` or `asc`) - Default is `desc`'
1949
+ },
1950
+ perPage: {
1951
+ type: 'number',
1952
+ shortFlag: 'pp',
1953
+ default: 30,
1954
+ description: 'Results per page - Default is 30'
1955
+ },
1956
+ page: {
1957
+ type: 'number',
1958
+ shortFlag: 'p',
1959
+ default: 1,
1960
+ description: 'Page number - Default is 1'
1961
+ },
1962
+ fromTime: {
1963
+ type: 'string',
1964
+ shortFlag: 'f',
1965
+ default: '',
1966
+ description: 'From time - as a unix timestamp'
1967
+ },
1968
+ untilTime: {
1969
+ type: 'string',
1970
+ shortFlag: 'u',
1971
+ default: '',
1972
+ description: 'Until time - as a unix timestamp'
1973
+ }
1974
+ };
1975
+
1976
+ // Internal functions
1977
+
1978
+ function setupCommand$9(name, description, argv, importMeta) {
1979
+ const flags = {
1980
+ ..._flags$8.outputFlags,
1981
+ ...listFullScanFlags
1982
+ };
1983
+ const cli = (0, _meow$9.default)(`
1984
+ Usage
1985
+ $ ${name} <org slug>
1986
+
1987
+ Options
1988
+ ${(0, _formatting$8.printFlagList)(flags, 6)}
1989
+
1990
+ Examples
1991
+ $ ${name} FakeOrg
1992
+ `, {
1993
+ argv,
1994
+ description,
1995
+ importMeta,
1996
+ flags
1997
+ });
1998
+ const {
1999
+ json: outputJson,
2000
+ markdown: outputMarkdown,
2001
+ sort,
2002
+ direction,
2003
+ perPage,
2004
+ page,
2005
+ fromTime,
2006
+ untilTime
2007
+ } = cli.flags;
2008
+ if (!cli.input[0]) {
2009
+ console.error(`${_chalk$a.default.bgRed('Input error')}: Please specify an organization slug.\n`);
2010
+ cli.showHelp();
2011
+ return;
2012
+ }
2013
+ const {
2014
+ 0: orgSlug = ''
2015
+ } = cli.input;
2016
+ return {
2017
+ outputJson,
2018
+ outputMarkdown,
2019
+ orgSlug,
2020
+ sort,
2021
+ direction,
2022
+ per_page: perPage,
2023
+ page,
2024
+ from_time: fromTime,
2025
+ until_time: untilTime
2026
+ };
2027
+ }
2028
+ async function listOrgFullScan(orgSlug, input, spinner, apiKey) {
2029
+ const socketSdk = await (0, _sdk$9.setupSdk)(apiKey);
2030
+ const result = await (0, _apiHelpers$9.handleApiCall)(socketSdk.getOrgFullScanList(orgSlug, input), 'Listing scans');
2031
+ if (!result.success) {
2032
+ (0, _apiHelpers$9.handleUnsuccessfulApiResponse)('getOrgFullScanList', result, spinner);
2033
+ return;
2034
+ }
2035
+ spinner.stop();
2036
+ console.log(`\n Listing scans for: ${orgSlug}\n`);
2037
+ const options = {
2038
+ columns: [{
2039
+ field: 'id',
2040
+ name: _chalk$a.default.magenta('ID')
2041
+ }, {
2042
+ field: 'report_url',
2043
+ name: _chalk$a.default.magenta('Scan URL')
2044
+ }, {
2045
+ field: 'branch',
2046
+ name: _chalk$a.default.magenta('Branch')
2047
+ }, {
2048
+ field: 'created_at',
2049
+ name: _chalk$a.default.magenta('Created at')
2050
+ }]
2051
+ };
2052
+ const formattedResults = result.data.results.map(d => {
2053
+ return {
2054
+ id: d.id,
2055
+ report_url: _chalk$a.default.underline(`${d.html_report_url}`),
2056
+ created_at: d.created_at ? new Date(d.created_at).toLocaleDateString('en-us', {
2057
+ year: 'numeric',
2058
+ month: 'numeric',
2059
+ day: 'numeric'
2060
+ }) : '',
2061
+ branch: d.branch
2062
+ };
2063
+ });
2064
+ console.log(`${_chalkTable$3(options, formattedResults)}\n`);
2065
+ }
2066
+
2067
+ var metadata$1 = {};
2068
+
2069
+ var _interopRequireDefault$9 = vendor.interopRequireDefault.default;
2070
+ Object.defineProperty(metadata$1, "__esModule", {
2071
+ value: true
2072
+ });
2073
+ metadata$1.metadata = void 0;
2074
+ var _chalk$9 = _interopRequireDefault$9(vendor.source);
2075
+ var _meow$8 = _interopRequireDefault$9(vendor.build);
2076
+ var _ora$8 = _interopRequireDefault$9(vendor.ora);
2077
+ var _flags$7 = flags;
2078
+ var _apiHelpers$8 = apiHelpers;
2079
+ var _formatting$7 = formatting;
2080
+ var _sdk$8 = sdk.sdk;
2081
+ var _errors$9 = sdk.errors;
2082
+ const metadata = metadata$1.metadata = {
2083
+ description: "Get a scan's metadata",
2084
+ async run(argv, importMeta, {
2085
+ parentName
2086
+ }) {
2087
+ const name = `${parentName} metadata`;
2088
+ const input = setupCommand$8(name, metadata.description, argv, importMeta);
2089
+ if (input) {
2090
+ const apiKey = (0, _sdk$8.getDefaultKey)();
2091
+ if (!apiKey) {
2092
+ throw new _errors$9.AuthError("User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.");
2093
+ }
2094
+ const spinnerText = "Getting scan's metadata... \n";
2095
+ const spinner = (0, _ora$8.default)(spinnerText).start();
2096
+ await getOrgScanMetadata(input.orgSlug, input.scanID, spinner, apiKey);
2097
+ }
2098
+ }
2099
+ };
2100
+
2101
+ // Internal functions
2102
+
2103
+ function setupCommand$8(name, description, argv, importMeta) {
2104
+ const flags = {
2105
+ ..._flags$7.outputFlags
2106
+ };
2107
+ const cli = (0, _meow$8.default)(`
2108
+ Usage
2109
+ $ ${name} <org slug> <scan id>
2110
+
2111
+ Options
2112
+ ${(0, _formatting$7.printFlagList)(flags, 6)}
2113
+
2114
+ Examples
2115
+ $ ${name} FakeOrg 000aaaa1-0000-0a0a-00a0-00a0000000a0
2116
+ `, {
2117
+ argv,
2118
+ description,
2119
+ importMeta,
2120
+ flags
2121
+ });
2122
+ const {
2123
+ json: outputJson,
2124
+ markdown: outputMarkdown
2125
+ } = cli.flags;
2126
+ if (cli.input.length < 2) {
2127
+ console.error(`${_chalk$9.default.bgRed('Input error')}: Please specify an organization slug and a scan ID.\n`);
2128
+ cli.showHelp();
2129
+ return;
2130
+ }
2131
+ const {
2132
+ 0: orgSlug = '',
2133
+ 1: scanID = ''
2134
+ } = cli.input;
2135
+ return {
2136
+ outputJson,
2137
+ outputMarkdown,
2138
+ orgSlug,
2139
+ scanID
2140
+ };
2141
+ }
2142
+ async function getOrgScanMetadata(orgSlug, scanId, spinner, apiKey) {
2143
+ const socketSdk = await (0, _sdk$8.setupSdk)(apiKey);
2144
+ const result = await (0, _apiHelpers$8.handleApiCall)(socketSdk.getOrgFullScanMetadata(orgSlug, scanId), 'Listing scans');
2145
+ if (!result.success) {
2146
+ (0, _apiHelpers$8.handleUnsuccessfulApiResponse)('getOrgFullScanMetadata', result, spinner);
2147
+ return;
2148
+ }
2149
+ spinner.stop();
2150
+ console.log('\nScan metadata:\n');
2151
+ console.log(result.data);
2152
+ }
2153
+
2154
+ var stream$1 = {};
2155
+
2156
+ var _interopRequireDefault$8 = vendor.interopRequireDefault.default;
2157
+ Object.defineProperty(stream$1, "__esModule", {
2158
+ value: true
2159
+ });
2160
+ stream$1.stream = void 0;
2161
+ var _chalk$8 = _interopRequireDefault$8(vendor.source);
2162
+ var _meow$7 = _interopRequireDefault$8(vendor.build);
2163
+ var _ora$7 = _interopRequireDefault$8(vendor.ora);
2164
+ var _flags$6 = flags;
2165
+ var _apiHelpers$7 = apiHelpers;
2166
+ var _formatting$6 = formatting;
2167
+ var _sdk$7 = sdk.sdk;
2168
+ var _errors$8 = sdk.errors;
2169
+ const stream = stream$1.stream = {
2170
+ description: 'Stream the output of a scan',
2171
+ async run(argv, importMeta, {
2172
+ parentName
2173
+ }) {
2174
+ const name = `${parentName} stream`;
2175
+ const input = setupCommand$7(name, stream.description, argv, importMeta);
2176
+ if (input) {
2177
+ const apiKey = (0, _sdk$7.getDefaultKey)();
2178
+ if (!apiKey) {
2179
+ throw new _errors$8.AuthError("User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.");
2180
+ }
2181
+ const spinnerText = 'Streaming scan...\n';
2182
+ const spinner = (0, _ora$7.default)(spinnerText).start();
2183
+ await getOrgFullScan(input.orgSlug, input.fullScanId, input.file, spinner, apiKey);
2184
+ }
2185
+ }
2186
+ };
2187
+
2188
+ // Internal functions
2189
+
2190
+ function setupCommand$7(name, description, argv, importMeta) {
2191
+ const flags = {
2192
+ ..._flags$6.outputFlags
2193
+ };
2194
+ const cli = (0, _meow$7.default)(`
2195
+ Usage
2196
+ $ ${name} <org slug> <scan ID> <path to output file>
2197
+
2198
+ Options
2199
+ ${(0, _formatting$6.printFlagList)(flags, 6)}
2200
+
2201
+ Examples
2202
+ $ ${name} FakeOrg 000aaaa1-0000-0a0a-00a0-00a0000000a0 ./stream.txt
2203
+ `, {
2204
+ argv,
2205
+ description,
2206
+ importMeta,
2207
+ flags
2208
+ });
2209
+ const {
2210
+ json: outputJson,
2211
+ markdown: outputMarkdown
2212
+ } = cli.flags;
2213
+ if (cli.input.length < 2) {
2214
+ console.error(`${_chalk$8.default.bgRed('Input error')}: Please specify an organization slug and a scan ID.\n`);
2215
+ cli.showHelp();
2216
+ return;
2217
+ }
2218
+ const {
2219
+ 0: orgSlug = '',
2220
+ 1: fullScanId = '',
2221
+ 2: file
2222
+ } = cli.input;
2223
+ return {
2224
+ outputJson,
2225
+ outputMarkdown,
2226
+ orgSlug,
2227
+ fullScanId,
2228
+ file
2229
+ };
2230
+ }
2231
+ async function getOrgFullScan(orgSlug, fullScanId, file, spinner, apiKey) {
2232
+ const socketSdk = await (0, _sdk$7.setupSdk)(apiKey);
2233
+ const result = await (0, _apiHelpers$7.handleApiCall)(socketSdk.getOrgFullScan(orgSlug, fullScanId, file), 'Streaming a scan');
2234
+ if (!result?.success) {
2235
+ (0, _apiHelpers$7.handleUnsuccessfulApiResponse)('getOrgFullScan', result, spinner);
2236
+ return;
2237
+ }
2238
+ spinner.stop();
2239
+ console.log(file ? `\nFull scan details written to ${file}\n` : '\nFull scan details:\n');
2240
+ }
2241
+
2242
+ Object.defineProperty(scan, "__esModule", {
2243
+ value: true
2244
+ });
2245
+ scan.scan = void 0;
2246
+ var _create$1 = create$3;
2247
+ var _delete$2 = _delete$3;
2248
+ var _list$1 = list$3;
2249
+ var _metadata = metadata$1;
2250
+ var _stream = stream$1;
2251
+ var _meowWithSubcommands$2 = meowWithSubcommands$1;
2252
+ const description$1 = 'Scans related commands';
2253
+ scan.scan = {
2254
+ description: description$1,
2255
+ run: async (argv, importMeta, {
2256
+ parentName
2257
+ }) => {
2258
+ await (0, _meowWithSubcommands$2.meowWithSubcommands)({
2259
+ create: _create$1.create,
2260
+ stream: _stream.stream,
2261
+ list: _list$1.list,
2262
+ del: _delete$2.del,
2263
+ metadata: _metadata.metadata
2264
+ }, {
2265
+ argv,
2266
+ description: description$1,
2267
+ importMeta,
2268
+ name: parentName + ' scan'
2269
+ });
2270
+ }
2271
+ };
2272
+
2273
+ var auditLog$1 = {};
2274
+
2275
+ var _interopRequireDefault$7 = vendor.interopRequireDefault.default;
2276
+ Object.defineProperty(auditLog$1, "__esModule", {
2277
+ value: true
2278
+ });
2279
+ auditLog$1.auditLog = void 0;
2280
+ var _prompts = require$$1$1;
2281
+ var _chalk$7 = _interopRequireDefault$7(vendor.source);
2282
+ var _meow$6 = _interopRequireDefault$7(vendor.build);
2283
+ var _ora$6 = _interopRequireDefault$7(vendor.ora);
2284
+ var _flags$5 = flags;
2285
+ var _apiHelpers$6 = apiHelpers;
2286
+ var _formatting$5 = formatting;
2287
+ var _sdk$6 = sdk.sdk;
2288
+ var _errors$7 = sdk.errors;
2289
+ const auditLog = auditLog$1.auditLog = {
2290
+ description: 'Look up the audit log for an organization',
2291
+ async run(argv, importMeta, {
2292
+ parentName
2293
+ }) {
2294
+ const name = parentName + ' audit-log';
2295
+ const input = setupCommand$6(name, auditLog.description, argv, importMeta);
2296
+ if (input) {
2297
+ const apiKey = (0, _sdk$6.getDefaultKey)();
2298
+ if (!apiKey) {
2299
+ throw new _errors$7.AuthError("User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.");
2300
+ }
2301
+ const spinner = (0, _ora$6.default)(`Looking up audit log for ${input.orgSlug}\n`).start();
2302
+ await fetchOrgAuditLog(input.orgSlug, input, spinner, apiKey);
2303
+ }
2304
+ }
2305
+ };
2306
+ const auditLogFlags = {
2307
+ type: {
2308
+ type: 'string',
2309
+ shortFlag: 't',
2310
+ default: '',
2311
+ description: 'Type of log event'
2312
+ },
2313
+ perPage: {
2314
+ type: 'number',
2315
+ shortFlag: 'pp',
2316
+ default: 30,
2317
+ description: 'Results per page - default is 30'
2318
+ },
2319
+ page: {
2320
+ type: 'number',
2321
+ shortFlag: 'p',
2322
+ default: 1,
2323
+ description: 'Page number - default is 1'
2324
+ }
2325
+ };
2326
+
2327
+ // Internal functions
2328
+
2329
+ function setupCommand$6(name, description, argv, importMeta) {
2330
+ const flags = {
2331
+ ...auditLogFlags,
2332
+ ..._flags$5.outputFlags
2333
+ };
2334
+ const cli = (0, _meow$6.default)(`
2335
+ Usage
2336
+ $ ${name} <org slug>
2337
+
2338
+ Options
2339
+ ${(0, _formatting$5.printFlagList)(flags, 6)}
2340
+
2341
+ Examples
2342
+ $ ${name} FakeOrg
2343
+ `, {
2344
+ argv,
2345
+ description,
2346
+ importMeta,
2347
+ flags
2348
+ });
2349
+ const {
2350
+ json: outputJson,
2351
+ markdown: outputMarkdown,
2352
+ page,
2353
+ perPage
2354
+ } = cli.flags;
2355
+ const type = cli.flags['type'];
2356
+ if (cli.input.length < 1) {
2357
+ console.error(`${_chalk$7.default.bgRed('Input error')}: Please provide an organization slug \n`);
2358
+ cli.showHelp();
2359
+ return;
2360
+ }
2361
+ const [orgSlug = ''] = cli.input;
2362
+ return {
2363
+ outputJson,
2364
+ outputMarkdown,
2365
+ orgSlug,
2366
+ type: type && type.charAt(0).toUpperCase() + type.slice(1),
2367
+ page,
2368
+ per_page: perPage
2369
+ };
2370
+ }
2371
+ async function fetchOrgAuditLog(orgSlug, input, spinner, apiKey) {
2372
+ const socketSdk = await (0, _sdk$6.setupSdk)(apiKey);
2373
+ const result = await (0, _apiHelpers$6.handleApiCall)(socketSdk.getAuditLogEvents(orgSlug, input), `Looking up audit log for ${orgSlug}\n`);
2374
+ if (!result.success) {
2375
+ (0, _apiHelpers$6.handleUnsuccessfulApiResponse)('getAuditLogEvents', result, spinner);
2376
+ return;
2377
+ }
2378
+ spinner.stop();
2379
+ const data = [];
2380
+ const logDetails = {};
2381
+ for (const d of result.data.results) {
2382
+ const {
2383
+ created_at
2384
+ } = d;
2385
+ if (created_at) {
2386
+ const name = `${new Date(created_at).toLocaleDateString('en-us', {
2387
+ year: 'numeric',
2388
+ month: 'numeric',
2389
+ day: 'numeric'
2390
+ })} - ${d.user_email} - ${d.type} - ${d.ip_address} - ${d.user_agent}`;
2391
+ data.push({
2392
+ name
2393
+ }, new _prompts.Separator());
2394
+ logDetails[name] = JSON.stringify(d.payload);
2395
+ }
2396
+ }
2397
+ console.log(logDetails[await (0, _prompts.select)({
2398
+ message: input.type ? `\n Audit log for: ${orgSlug} with type: ${input.type} \n` : `\n Audit log for: ${orgSlug} \n`,
2399
+ choices: data,
2400
+ pageSize: 30
2401
+ })]);
2402
+ }
2403
+
2404
+ var repos = {};
2405
+
2406
+ var create$1 = {};
2407
+
2408
+ var _interopRequireDefault$6 = vendor.interopRequireDefault.default;
2409
+ Object.defineProperty(create$1, "__esModule", {
2410
+ value: true
2411
+ });
2412
+ create$1.create = void 0;
2413
+ var _chalk$6 = _interopRequireDefault$6(vendor.source);
2414
+ var _meow$5 = _interopRequireDefault$6(vendor.build);
2415
+ var _ora$5 = _interopRequireDefault$6(vendor.ora);
2416
+ var _flags$4 = flags;
2417
+ var _apiHelpers$5 = apiHelpers;
2418
+ var _formatting$4 = formatting;
2419
+ var _sdk$5 = sdk.sdk;
2420
+ var _errors$6 = sdk.errors;
2421
+ const create = create$1.create = {
2422
+ description: 'Create a repository in an organization',
2423
+ async run(argv, importMeta, {
2424
+ parentName
2425
+ }) {
2426
+ const name = `${parentName} create`;
2427
+ const input = setupCommand$5(name, create.description, argv, importMeta);
2428
+ if (input) {
2429
+ const apiKey = (0, _sdk$5.getDefaultKey)();
2430
+ if (!apiKey) {
2431
+ throw new _errors$6.AuthError("User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.");
2432
+ }
2433
+ const spinnerText = 'Creating repository... \n';
2434
+ const spinner = (0, _ora$5.default)(spinnerText).start();
2435
+ await createRepo(input.orgSlug, input, spinner, apiKey);
2436
+ }
2437
+ }
2438
+ };
2439
+ const repositoryCreationFlags = {
2440
+ repoName: {
2441
+ type: 'string',
2442
+ shortFlag: 'n',
2443
+ default: '',
2444
+ description: 'Repository name'
2445
+ },
2446
+ repoDescription: {
2447
+ type: 'string',
2448
+ shortFlag: 'd',
2449
+ default: '',
2450
+ description: 'Repository description'
2451
+ },
2452
+ homepage: {
2453
+ type: 'string',
2454
+ shortFlag: 'h',
2455
+ default: '',
2456
+ description: 'Repository url'
2457
+ },
2458
+ defaultBranch: {
2459
+ type: 'string',
2460
+ shortFlag: 'b',
2461
+ default: 'main',
2462
+ description: 'Repository default branch'
2463
+ },
2464
+ visibility: {
2465
+ type: 'string',
2466
+ shortFlag: 'v',
2467
+ default: 'private',
2468
+ description: 'Repository visibility (Default Private)'
2469
+ }
2470
+ };
2471
+
2472
+ // Internal functions
2473
+
2474
+ function setupCommand$5(name, description, argv, importMeta) {
2475
+ const flags = {
2476
+ ..._flags$4.outputFlags,
2477
+ ...repositoryCreationFlags
2478
+ };
2479
+ const cli = (0, _meow$5.default)(`
2480
+ Usage
2481
+ $ ${name} <org slug>
2482
+
2483
+ Options
2484
+ ${(0, _formatting$4.printFlagList)(flags, 6)}
2485
+
2486
+ Examples
2487
+ $ ${name} FakeOrg --repoName=test-repo
2488
+ `, {
2489
+ argv,
2490
+ description,
2491
+ importMeta,
2492
+ flags
2493
+ });
2494
+ const {
2495
+ json: outputJson,
2496
+ markdown: outputMarkdown,
2497
+ repoName,
2498
+ repoDescription,
2499
+ homepage,
2500
+ defaultBranch,
2501
+ visibility
2502
+ } = cli.flags;
2503
+ const [orgSlug = ''] = cli.input;
2504
+ if (!orgSlug) {
2505
+ console.error(`${_chalk$6.default.bgRed('Input error')}: Please provide an organization slug \n`);
2506
+ cli.showHelp();
2507
+ return;
2508
+ }
2509
+ if (!repoName) {
2510
+ console.error(`${_chalk$6.default.bgRed('Input error')}: Repository name is required. \n`);
2511
+ cli.showHelp();
2512
+ return;
2513
+ }
2514
+ return {
2515
+ outputJson,
2516
+ outputMarkdown,
2517
+ orgSlug,
2518
+ name: repoName,
2519
+ description: repoDescription,
2520
+ homepage,
2521
+ default_branch: defaultBranch,
2522
+ visibility
2523
+ };
2524
+ }
2525
+ async function createRepo(orgSlug, input, spinner, apiKey) {
2526
+ const socketSdk = await (0, _sdk$5.setupSdk)(apiKey);
2527
+ const result = await (0, _apiHelpers$5.handleApiCall)(socketSdk.createOrgRepo(orgSlug, input), 'creating repository');
2528
+ if (!result.success) {
2529
+ (0, _apiHelpers$5.handleUnsuccessfulApiResponse)('createOrgRepo', result, spinner);
2530
+ return;
2531
+ }
2532
+ spinner.stop();
2533
+ console.log('\n✅ Repository created successfully\n');
2534
+ }
2535
+
2536
+ var _delete$1 = {};
2537
+
2538
+ var _interopRequireDefault$5 = vendor.interopRequireDefault.default;
2539
+ Object.defineProperty(_delete$1, "__esModule", {
2540
+ value: true
2541
+ });
2542
+ _delete$1.del = void 0;
2543
+ var _chalk$5 = _interopRequireDefault$5(vendor.source);
2544
+ var _meow$4 = _interopRequireDefault$5(vendor.build);
2545
+ var _ora$4 = _interopRequireDefault$5(vendor.ora);
2546
+ var _apiHelpers$4 = apiHelpers;
2547
+ var _sdk$4 = sdk.sdk;
2548
+ var _errors$5 = sdk.errors;
2549
+ const del = _delete$1.del = {
2550
+ description: 'Delete a repository in an organization',
2551
+ async run(argv, importMeta, {
2552
+ parentName
2553
+ }) {
2554
+ const name = `${parentName} del`;
2555
+ const input = setupCommand$4(name, del.description, argv, importMeta);
2556
+ if (input) {
2557
+ const apiKey = (0, _sdk$4.getDefaultKey)();
2558
+ if (!apiKey) {
2559
+ throw new _errors$5.AuthError("User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.");
2560
+ }
2561
+ const spinnerText = 'Deleting repository... \n';
2562
+ const spinner = (0, _ora$4.default)(spinnerText).start();
2563
+ await deleteRepository(input.orgSlug, input.repoName, spinner, apiKey);
2564
+ }
2565
+ }
2566
+ };
2567
+
2568
+ // Internal functions
2569
+
2570
+ function setupCommand$4(name, description, argv, importMeta) {
2571
+ const cli = (0, _meow$4.default)(`
2572
+ Usage
2573
+ $ ${name} <org slug> <repo slug>
2574
+
2575
+ Examples
2576
+ $ ${name} FakeOrg test-repo
2577
+ `, {
2578
+ argv,
2579
+ description,
2580
+ importMeta
2581
+ });
2582
+ const {
2583
+ 0: orgSlug = '',
2584
+ 1: repoName = ''
2585
+ } = cli.input;
2586
+ if (!orgSlug || !repoName) {
2587
+ console.error(`${_chalk$5.default.bgRed('Input error')}: Please provide an organization slug and repository slug \n`);
2588
+ cli.showHelp();
2589
+ return;
2590
+ }
2591
+ return {
2592
+ orgSlug,
2593
+ repoName
2594
+ };
2595
+ }
2596
+ async function deleteRepository(orgSlug, repoName, spinner, apiKey) {
2597
+ const socketSdk = await (0, _sdk$4.setupSdk)(apiKey);
2598
+ const result = await (0, _apiHelpers$4.handleApiCall)(socketSdk.deleteOrgRepo(orgSlug, repoName), 'deleting repository');
2599
+ if (!result.success) {
2600
+ (0, _apiHelpers$4.handleUnsuccessfulApiResponse)('deleteOrgRepo', result, spinner);
2601
+ return;
2602
+ }
2603
+ spinner.stop();
2604
+ console.log('\n✅ Repository deleted successfully\n');
2605
+ }
2606
+
2607
+ var list$1 = {};
2608
+
2609
+ var _interopRequireDefault$4 = vendor.interopRequireDefault.default;
2610
+ Object.defineProperty(list$1, "__esModule", {
2611
+ value: true
2612
+ });
2613
+ list$1.list = void 0;
2614
+ var _chalk$4 = _interopRequireDefault$4(vendor.source);
2615
+ var _chalkTable$2 = require$$2$2;
2616
+ var _meow$3 = _interopRequireDefault$4(vendor.build);
2617
+ var _ora$3 = _interopRequireDefault$4(vendor.ora);
2618
+ var _flags$3 = flags;
2619
+ var _apiHelpers$3 = apiHelpers;
2620
+ var _formatting$3 = formatting;
2621
+ var _sdk$3 = sdk.sdk;
2622
+ var _errors$4 = sdk.errors;
2623
+ // @ts-ignore
2624
+
2625
+ const list = list$1.list = {
2626
+ description: 'List repositories in an organization',
2627
+ async run(argv, importMeta, {
2628
+ parentName
2629
+ }) {
2630
+ const name = `${parentName} list`;
2631
+ const input = setupCommand$3(name, list.description, argv, importMeta);
2632
+ if (input) {
2633
+ const apiKey = (0, _sdk$3.getDefaultKey)();
2634
+ if (!apiKey) {
2635
+ throw new _errors$4.AuthError("User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.");
2636
+ }
2637
+ const spinnerText = 'Listing repositories... \n';
2638
+ const spinner = (0, _ora$3.default)(spinnerText).start();
2639
+ await listOrgRepos(input.orgSlug, input, spinner, apiKey);
2640
+ }
2641
+ }
2642
+ };
2643
+ const listRepoFlags = {
2644
+ sort: {
2645
+ type: 'string',
2646
+ shortFlag: 's',
2647
+ default: 'created_at',
2648
+ description: 'Sorting option'
2649
+ },
2650
+ direction: {
2651
+ type: 'string',
2652
+ default: 'desc',
2653
+ description: 'Direction option'
2654
+ },
2655
+ perPage: {
2656
+ type: 'number',
2657
+ shortFlag: 'pp',
2658
+ default: 30,
2659
+ description: 'Number of results per page'
2660
+ },
2661
+ page: {
2662
+ type: 'number',
2663
+ shortFlag: 'p',
2664
+ default: 1,
2665
+ description: 'Page number'
2666
+ }
2667
+ };
2668
+
2669
+ // Internal functions
2670
+
2671
+ function setupCommand$3(name, description, argv, importMeta) {
2672
+ const flags = {
2673
+ ..._flags$3.outputFlags,
2674
+ ...listRepoFlags
2675
+ };
2676
+ const cli = (0, _meow$3.default)(`
2677
+ Usage
2678
+ $ ${name} <org slug>
2679
+
2680
+ Options
2681
+ ${(0, _formatting$3.printFlagList)(flags, 6)}
2682
+
2683
+ Examples
2684
+ $ ${name} FakeOrg
2685
+ `, {
2686
+ argv,
2687
+ description,
2688
+ importMeta,
2689
+ flags
2690
+ });
2691
+ const {
2692
+ json: outputJson,
2693
+ markdown: outputMarkdown,
2694
+ perPage,
2695
+ sort,
2696
+ direction,
2697
+ page
2698
+ } = cli.flags;
2699
+ if (!cli.input[0]) {
2700
+ console.error(`${_chalk$4.default.bgRed('Input error')}: Please provide an organization slug \n`);
2701
+ cli.showHelp();
2702
+ return;
2703
+ }
2704
+ const {
2705
+ 0: orgSlug = ''
2706
+ } = cli.input;
2707
+ return {
2708
+ outputJson,
2709
+ outputMarkdown,
2710
+ orgSlug,
2711
+ sort,
2712
+ direction,
2713
+ page,
2714
+ per_page: perPage
2715
+ };
2716
+ }
2717
+ async function listOrgRepos(orgSlug, input, spinner, apiKey) {
2718
+ const socketSdk = await (0, _sdk$3.setupSdk)(apiKey);
2719
+ const result = await (0, _apiHelpers$3.handleApiCall)(socketSdk.getOrgRepoList(orgSlug, input), 'listing repositories');
2720
+ if (!result.success) {
2721
+ (0, _apiHelpers$3.handleUnsuccessfulApiResponse)('getOrgRepoList', result, spinner);
2722
+ return;
2723
+ }
2724
+ spinner.stop();
2725
+ const options = {
2726
+ columns: [{
2727
+ field: 'id',
2728
+ name: _chalk$4.default.magenta('ID')
2729
+ }, {
2730
+ field: 'name',
2731
+ name: _chalk$4.default.magenta('Name')
2732
+ }, {
2733
+ field: 'visibility',
2734
+ name: _chalk$4.default.magenta('Visibility')
2735
+ }, {
2736
+ field: 'default_branch',
2737
+ name: _chalk$4.default.magenta('Default branch')
2738
+ }, {
2739
+ field: 'archived',
2740
+ name: _chalk$4.default.magenta('Archived')
2741
+ }]
2742
+ };
2743
+ console.log(`${_chalkTable$2(options, result.data.results)}\n`);
2744
+ }
2745
+
2746
+ var update$1 = {};
2747
+
2748
+ var _interopRequireDefault$3 = vendor.interopRequireDefault.default;
2749
+ Object.defineProperty(update$1, "__esModule", {
2750
+ value: true
2751
+ });
2752
+ update$1.update = void 0;
2753
+ var _chalk$3 = _interopRequireDefault$3(vendor.source);
2754
+ var _meow$2 = _interopRequireDefault$3(vendor.build);
2755
+ var _ora$2 = _interopRequireDefault$3(vendor.ora);
2756
+ var _flags$2 = flags;
2757
+ var _apiHelpers$2 = apiHelpers;
2758
+ var _formatting$2 = formatting;
2759
+ var _sdk$2 = sdk.sdk;
2760
+ var _errors$3 = sdk.errors;
2761
+ const update = update$1.update = {
2762
+ description: 'Update a repository in an organization',
2763
+ async run(argv, importMeta, {
2764
+ parentName
2765
+ }) {
2766
+ const name = `${parentName} update`;
2767
+ const input = setupCommand$2(name, update.description, argv, importMeta);
2768
+ if (input) {
2769
+ const apiKey = (0, _sdk$2.getDefaultKey)();
2770
+ if (!apiKey) {
2771
+ throw new _errors$3.AuthError("User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.");
2772
+ }
2773
+ const spinnerText = 'Updating repository... \n';
2774
+ const spinner = (0, _ora$2.default)(spinnerText).start();
2775
+ await updateRepository(input.orgSlug, input, spinner, apiKey);
2776
+ }
2777
+ }
2778
+ };
2779
+ const repositoryUpdateFlags = {
2780
+ repoName: {
2781
+ type: 'string',
2782
+ shortFlag: 'n',
2783
+ default: '',
2784
+ description: 'Repository name'
2785
+ },
2786
+ repoDescription: {
2787
+ type: 'string',
2788
+ shortFlag: 'd',
2789
+ default: '',
2790
+ description: 'Repository description'
2791
+ },
2792
+ homepage: {
2793
+ type: 'string',
2794
+ shortFlag: 'h',
2795
+ default: '',
2796
+ description: 'Repository url'
2797
+ },
2798
+ defaultBranch: {
2799
+ type: 'string',
2800
+ shortFlag: 'b',
2801
+ default: 'main',
2802
+ description: 'Repository default branch'
2803
+ },
2804
+ visibility: {
2805
+ type: 'string',
2806
+ shortFlag: 'v',
2807
+ default: 'private',
2808
+ description: 'Repository visibility (Default Private)'
2809
+ }
2810
+ };
2811
+
2812
+ // Internal functions
2813
+
2814
+ function setupCommand$2(name, description, argv, importMeta) {
2815
+ const flags = {
2816
+ ..._flags$2.outputFlags,
2817
+ ...repositoryUpdateFlags
2818
+ };
2819
+ const cli = (0, _meow$2.default)(`
2820
+ Usage
2821
+ $ ${name} <org slug>
2822
+
2823
+ Options
2824
+ ${(0, _formatting$2.printFlagList)(flags, 6)}
2825
+
2826
+ Examples
2827
+ $ ${name} FakeOrg
2828
+ `, {
2829
+ argv,
2830
+ description,
2831
+ importMeta,
2832
+ flags
2833
+ });
2834
+ const {
2835
+ json: outputJson,
2836
+ markdown: outputMarkdown,
2837
+ repoName,
2838
+ repoDescription,
2839
+ homepage,
2840
+ defaultBranch,
2841
+ visibility
2842
+ } = cli.flags;
2843
+ const [orgSlug = ''] = cli.input;
2844
+ if (!orgSlug) {
2845
+ console.error(`${_chalk$3.default.bgRed('Input error')}: Please provide an organization slug and repository name \n`);
2846
+ cli.showHelp();
2847
+ return;
2848
+ }
2849
+ if (!repoName) {
2850
+ console.error(`${_chalk$3.default.bgRed('Input error')}: Repository name is required. \n`);
2851
+ cli.showHelp();
2852
+ return;
2853
+ }
2854
+ return {
2855
+ outputJson,
2856
+ outputMarkdown,
2857
+ orgSlug,
2858
+ name: repoName,
2859
+ description: repoDescription,
2860
+ homepage,
2861
+ default_branch: defaultBranch,
2862
+ visibility
2863
+ };
2864
+ }
2865
+ async function updateRepository(orgSlug, input, spinner, apiKey) {
2866
+ const socketSdk = await (0, _sdk$2.setupSdk)(apiKey);
2867
+ const result = await (0, _apiHelpers$2.handleApiCall)(socketSdk.updateOrgRepo(orgSlug, input.name, input), 'updating repository');
2868
+ if (!result.success) {
2869
+ (0, _apiHelpers$2.handleUnsuccessfulApiResponse)('updateOrgRepo', result, spinner);
2870
+ return;
2871
+ }
2872
+ spinner.stop();
2873
+ console.log('\n✅ Repository updated successfully\n');
2874
+ }
2875
+
2876
+ var view$1 = {};
2877
+
2878
+ var _interopRequireDefault$2 = vendor.interopRequireDefault.default;
2879
+ Object.defineProperty(view$1, "__esModule", {
2880
+ value: true
2881
+ });
2882
+ view$1.view = void 0;
2883
+ var _chalk$2 = _interopRequireDefault$2(vendor.source);
2884
+ var _chalkTable$1 = require$$2$2;
2885
+ var _meow$1 = _interopRequireDefault$2(vendor.build);
2886
+ var _ora$1 = _interopRequireDefault$2(vendor.ora);
2887
+ var _flags$1 = flags;
2888
+ var _apiHelpers$1 = apiHelpers;
2889
+ var _formatting$1 = formatting;
2890
+ var _sdk$1 = sdk.sdk;
2891
+ var _errors$2 = sdk.errors;
2892
+ // @ts-ignore
2893
+
2894
+ const view = view$1.view = {
2895
+ description: 'View repositories in an organization',
2896
+ async run(argv, importMeta, {
2897
+ parentName
2898
+ }) {
2899
+ const name = `${parentName} view`;
2900
+ const input = setupCommand$1(name, view.description, argv, importMeta);
2901
+ if (input) {
2902
+ const apiKey = (0, _sdk$1.getDefaultKey)();
2903
+ if (!apiKey) {
2904
+ throw new _errors$2.AuthError("User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.");
2905
+ }
2906
+ const spinnerText = 'Fetching repository... \n';
2907
+ const spinner = (0, _ora$1.default)(spinnerText).start();
2908
+ await viewRepository(input.orgSlug, input.repositoryName, spinner, apiKey);
2909
+ }
2910
+ }
2911
+ };
2912
+
2913
+ // Internal functions
2914
+
2915
+ function setupCommand$1(name, description, argv, importMeta) {
2916
+ const flags = {
2917
+ ..._flags$1.outputFlags
2918
+ };
2919
+ const cli = (0, _meow$1.default)(`
2920
+ Usage
2921
+ $ ${name} <org slug>
2922
+
2923
+ Options
2924
+ ${(0, _formatting$1.printFlagList)(flags, 6)}
2925
+
2926
+ Examples
2927
+ $ ${name} FakeOrg
2928
+ `, {
2929
+ argv,
2930
+ description,
2931
+ importMeta,
2932
+ flags
2933
+ });
2934
+ const {
2935
+ json: outputJson,
2936
+ markdown: outputMarkdown
2937
+ } = cli.flags;
2938
+ if (!cli.input[0]) {
2939
+ console.error(`${_chalk$2.default.bgRed('Input error')}: Please provide an organization slug and repository name \n`);
2940
+ cli.showHelp();
2941
+ return;
2942
+ }
2943
+ const {
2944
+ 0: orgSlug = '',
2945
+ 1: repositoryName = ''
2946
+ } = cli.input;
2947
+ return {
2948
+ outputJson,
2949
+ outputMarkdown,
2950
+ orgSlug,
2951
+ repositoryName
2952
+ };
2953
+ }
2954
+ async function viewRepository(orgSlug, repoName, spinner, apiKey) {
2955
+ const socketSdk = await (0, _sdk$1.setupSdk)(apiKey);
2956
+ const result = await (0, _apiHelpers$1.handleApiCall)(socketSdk.getOrgRepo(orgSlug, repoName), 'fetching repository');
2957
+ if (!result.success) {
2958
+ (0, _apiHelpers$1.handleUnsuccessfulApiResponse)('getOrgRepo', result, spinner);
2959
+ return;
2960
+ }
2961
+ spinner.stop();
2962
+ const options = {
2963
+ columns: [{
2964
+ field: 'id',
2965
+ name: _chalk$2.default.magenta('ID')
2966
+ }, {
2967
+ field: 'name',
2968
+ name: _chalk$2.default.magenta('Name')
2969
+ }, {
2970
+ field: 'visibility',
2971
+ name: _chalk$2.default.magenta('Visibility')
2972
+ }, {
2973
+ field: 'default_branch',
2974
+ name: _chalk$2.default.magenta('Default branch')
2975
+ }, {
2976
+ field: 'homepage',
2977
+ name: _chalk$2.default.magenta('Homepage')
2978
+ }, {
2979
+ field: 'archived',
2980
+ name: _chalk$2.default.magenta('Archived')
2981
+ }, {
2982
+ field: 'created_at',
2983
+ name: _chalk$2.default.magenta('Created at')
2984
+ }]
2985
+ };
2986
+ console.log(`${_chalkTable$1(options, [result.data])}\n`);
2987
+ }
2988
+
2989
+ Object.defineProperty(repos, "__esModule", {
2990
+ value: true
2991
+ });
2992
+ repos.repo = void 0;
2993
+ var _create = create$1;
2994
+ var _delete = _delete$1;
2995
+ var _list = list$1;
2996
+ var _update = update$1;
2997
+ var _view = view$1;
2998
+ var _meowWithSubcommands$1 = meowWithSubcommands$1;
2999
+ const description = 'Repositories related commands';
3000
+ repos.repo = {
3001
+ description,
3002
+ run: async (argv, importMeta, {
3003
+ parentName
3004
+ }) => {
3005
+ await (0, _meowWithSubcommands$1.meowWithSubcommands)({
3006
+ create: _create.create,
3007
+ view: _view.view,
3008
+ list: _list.list,
3009
+ del: _delete.del,
3010
+ update: _update.update
3011
+ }, {
3012
+ argv,
3013
+ description,
3014
+ importMeta,
3015
+ name: `${parentName} repo`
3016
+ });
3017
+ }
3018
+ };
3019
+
3020
+ var dependencies$1 = {};
3021
+
3022
+ var _interopRequireDefault$1 = vendor.interopRequireDefault.default;
3023
+ Object.defineProperty(dependencies$1, "__esModule", {
3024
+ value: true
3025
+ });
3026
+ dependencies$1.dependencies = void 0;
3027
+ var _chalk$1 = _interopRequireDefault$1(vendor.source);
3028
+ var _chalkTable = require$$2$2;
3029
+ var _meow = _interopRequireDefault$1(vendor.build);
3030
+ var _ora = _interopRequireDefault$1(vendor.ora);
3031
+ var _flags = flags;
3032
+ var _apiHelpers = apiHelpers;
3033
+ var _formatting = formatting;
3034
+ var _sdk = sdk.sdk;
3035
+ var _errors$1 = sdk.errors;
3036
+ // @ts-ignore
3037
+
3038
+ const dependencies = dependencies$1.dependencies = {
3039
+ description: 'Search for any dependency that is being used in your organization',
3040
+ async run(argv, importMeta, {
3041
+ parentName
3042
+ }) {
3043
+ const name = parentName + ' dependencies';
3044
+ const input = setupCommand(name, dependencies.description, argv, importMeta);
3045
+ if (input) {
3046
+ await searchDeps(input);
3047
+ }
3048
+ }
3049
+ };
3050
+ const dependenciesFlags = {
3051
+ limit: {
3052
+ type: 'number',
3053
+ shortFlag: 'l',
3054
+ default: 50,
3055
+ description: 'Maximum number of dependencies returned'
3056
+ },
3057
+ offset: {
3058
+ type: 'number',
3059
+ shortFlag: 'o',
3060
+ default: 0,
3061
+ description: 'Page number'
3062
+ }
3063
+ };
3064
+
3065
+ // Internal functions
3066
+
3067
+ function setupCommand(name, description, argv, importMeta) {
3068
+ const flags = {
3069
+ ..._flags.outputFlags,
3070
+ ...dependenciesFlags
3071
+ };
3072
+ const cli = (0, _meow.default)(`
3073
+ Usage
3074
+ $ ${name}
3075
+
3076
+ Options
3077
+ ${(0, _formatting.printFlagList)(flags, 6)}
3078
+
3079
+ Examples
3080
+ $ ${name}
3081
+ `, {
3082
+ argv,
3083
+ description,
3084
+ importMeta,
3085
+ flags
3086
+ });
3087
+ const {
3088
+ json: outputJson,
3089
+ markdown: outputMarkdown,
3090
+ limit,
3091
+ offset
3092
+ } = cli.flags;
3093
+ return {
3094
+ outputJson,
3095
+ outputMarkdown,
3096
+ limit,
3097
+ offset
3098
+ };
3099
+ }
3100
+ async function searchDeps({
3101
+ limit,
3102
+ offset,
3103
+ outputJson
3104
+ }) {
3105
+ const apiKey = (0, _sdk.getDefaultKey)();
3106
+ if (!apiKey) {
3107
+ throw new _errors$1.AuthError("User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.");
3108
+ }
3109
+ const spinnerText = 'Searching dependencies...';
3110
+ const spinner = (0, _ora.default)(spinnerText).start();
3111
+ const socketSdk = await (0, _sdk.setupSdk)(apiKey);
3112
+ const result = await (0, _apiHelpers.handleApiCall)(socketSdk.searchDependencies({
3113
+ limit,
3114
+ offset
3115
+ }), 'Searching dependencies');
3116
+ if (!result.success) {
3117
+ (0, _apiHelpers.handleUnsuccessfulApiResponse)('searchDependencies', result, spinner);
3118
+ return;
3119
+ }
3120
+ spinner.stop();
3121
+ console.log('Organization dependencies:\n');
3122
+ if (outputJson) {
3123
+ console.log(result.data);
3124
+ return;
3125
+ }
3126
+ const options = {
3127
+ columns: [{
3128
+ field: 'namespace',
3129
+ name: _chalk$1.default.cyan('Namespace')
3130
+ }, {
3131
+ field: 'name',
3132
+ name: _chalk$1.default.cyan('Name')
3133
+ }, {
3134
+ field: 'version',
3135
+ name: _chalk$1.default.cyan('Version')
3136
+ }, {
3137
+ field: 'repository',
3138
+ name: _chalk$1.default.cyan('Repository')
3139
+ }, {
3140
+ field: 'branch',
3141
+ name: _chalk$1.default.cyan('Branch')
3142
+ }, {
3143
+ field: 'type',
3144
+ name: _chalk$1.default.cyan('Type')
3145
+ }, {
3146
+ field: 'direct',
3147
+ name: _chalk$1.default.cyan('Direct')
3148
+ }]
3149
+ };
3150
+ console.log(`${_chalkTable(options, result.data.rows)}\n`);
3151
+ }
3152
+
3153
+ (function (exports) {
3154
+
3155
+ Object.defineProperty(exports, "__esModule", {
3156
+ value: true
3157
+ });
3158
+ var _cdxgen = cdxgen;
3159
+ Object.keys(_cdxgen).forEach(function (key) {
3160
+ if (key === "default" || key === "__esModule") return;
3161
+ if (key in exports && exports[key] === _cdxgen[key]) return;
3162
+ Object.defineProperty(exports, key, {
3163
+ enumerable: true,
3164
+ get: function () {
3165
+ return _cdxgen[key];
3166
+ }
3167
+ });
3168
+ });
3169
+ var _info = info$1;
3170
+ Object.keys(_info).forEach(function (key) {
3171
+ if (key === "default" || key === "__esModule") return;
3172
+ if (key in exports && exports[key] === _info[key]) return;
3173
+ Object.defineProperty(exports, key, {
3174
+ enumerable: true,
3175
+ get: function () {
3176
+ return _info[key];
3177
+ }
3178
+ });
3179
+ });
3180
+ var _login = login;
3181
+ Object.keys(_login).forEach(function (key) {
3182
+ if (key === "default" || key === "__esModule") return;
3183
+ if (key in exports && exports[key] === _login[key]) return;
3184
+ Object.defineProperty(exports, key, {
3185
+ enumerable: true,
3186
+ get: function () {
3187
+ return _login[key];
3188
+ }
3189
+ });
3190
+ });
3191
+ var _logout = logout;
3192
+ Object.keys(_logout).forEach(function (key) {
3193
+ if (key === "default" || key === "__esModule") return;
3194
+ if (key in exports && exports[key] === _logout[key]) return;
3195
+ Object.defineProperty(exports, key, {
3196
+ enumerable: true,
3197
+ get: function () {
3198
+ return _logout[key];
3199
+ }
3200
+ });
3201
+ });
3202
+ var _npm = npm;
3203
+ Object.keys(_npm).forEach(function (key) {
3204
+ if (key === "default" || key === "__esModule") return;
3205
+ if (key in exports && exports[key] === _npm[key]) return;
3206
+ Object.defineProperty(exports, key, {
3207
+ enumerable: true,
3208
+ get: function () {
3209
+ return _npm[key];
3210
+ }
3211
+ });
3212
+ });
3213
+ var _npx = npx;
3214
+ Object.keys(_npx).forEach(function (key) {
3215
+ if (key === "default" || key === "__esModule") return;
3216
+ if (key in exports && exports[key] === _npx[key]) return;
3217
+ Object.defineProperty(exports, key, {
3218
+ enumerable: true,
3219
+ get: function () {
3220
+ return _npx[key];
3221
+ }
3222
+ });
3223
+ });
3224
+ var _organization = organization;
3225
+ Object.keys(_organization).forEach(function (key) {
3226
+ if (key === "default" || key === "__esModule") return;
3227
+ if (key in exports && exports[key] === _organization[key]) return;
3228
+ Object.defineProperty(exports, key, {
3229
+ enumerable: true,
3230
+ get: function () {
3231
+ return _organization[key];
3232
+ }
3233
+ });
3234
+ });
3235
+ var _rawNpm = rawNpm$1;
3236
+ Object.keys(_rawNpm).forEach(function (key) {
3237
+ if (key === "default" || key === "__esModule") return;
3238
+ if (key in exports && exports[key] === _rawNpm[key]) return;
3239
+ Object.defineProperty(exports, key, {
3240
+ enumerable: true,
3241
+ get: function () {
3242
+ return _rawNpm[key];
3243
+ }
3244
+ });
3245
+ });
3246
+ var _rawNpx = rawNpx$1;
3247
+ Object.keys(_rawNpx).forEach(function (key) {
3248
+ if (key === "default" || key === "__esModule") return;
3249
+ if (key in exports && exports[key] === _rawNpx[key]) return;
3250
+ Object.defineProperty(exports, key, {
3251
+ enumerable: true,
3252
+ get: function () {
3253
+ return _rawNpx[key];
3254
+ }
3255
+ });
3256
+ });
3257
+ var _report = report;
3258
+ Object.keys(_report).forEach(function (key) {
3259
+ if (key === "default" || key === "__esModule") return;
3260
+ if (key in exports && exports[key] === _report[key]) return;
3261
+ Object.defineProperty(exports, key, {
3262
+ enumerable: true,
3263
+ get: function () {
3264
+ return _report[key];
3265
+ }
3266
+ });
3267
+ });
3268
+ var _wrapper = wrapper$1;
3269
+ Object.keys(_wrapper).forEach(function (key) {
3270
+ if (key === "default" || key === "__esModule") return;
3271
+ if (key in exports && exports[key] === _wrapper[key]) return;
3272
+ Object.defineProperty(exports, key, {
3273
+ enumerable: true,
3274
+ get: function () {
3275
+ return _wrapper[key];
3276
+ }
3277
+ });
3278
+ });
3279
+ var _scan = scan;
3280
+ Object.keys(_scan).forEach(function (key) {
3281
+ if (key === "default" || key === "__esModule") return;
3282
+ if (key in exports && exports[key] === _scan[key]) return;
3283
+ Object.defineProperty(exports, key, {
3284
+ enumerable: true,
3285
+ get: function () {
3286
+ return _scan[key];
3287
+ }
3288
+ });
3289
+ });
3290
+ var _auditLog = auditLog$1;
3291
+ Object.keys(_auditLog).forEach(function (key) {
3292
+ if (key === "default" || key === "__esModule") return;
3293
+ if (key in exports && exports[key] === _auditLog[key]) return;
3294
+ Object.defineProperty(exports, key, {
3295
+ enumerable: true,
3296
+ get: function () {
3297
+ return _auditLog[key];
3298
+ }
3299
+ });
3300
+ });
3301
+ var _repos = repos;
3302
+ Object.keys(_repos).forEach(function (key) {
3303
+ if (key === "default" || key === "__esModule") return;
3304
+ if (key in exports && exports[key] === _repos[key]) return;
3305
+ Object.defineProperty(exports, key, {
3306
+ enumerable: true,
3307
+ get: function () {
3308
+ return _repos[key];
3309
+ }
3310
+ });
3311
+ });
3312
+ var _dependencies = dependencies$1;
3313
+ Object.keys(_dependencies).forEach(function (key) {
3314
+ if (key === "default" || key === "__esModule") return;
3315
+ if (key in exports && exports[key] === _dependencies[key]) return;
3316
+ Object.defineProperty(exports, key, {
3317
+ enumerable: true,
3318
+ get: function () {
3319
+ return _dependencies[key];
3320
+ }
3321
+ });
3322
+ });
3323
+ } (commands));
3324
+
3325
+ var _interopRequireWildcard = vendor.interopRequireWildcard.default;
3326
+ var _interopRequireDefault = vendor.interopRequireDefault.default;
3327
+ var _nodeFs = require$$0;
3328
+ var _nodePath = require$$1;
3329
+ var _nodeUrl = require$$2$3;
3330
+ var _chalk = _interopRequireDefault(vendor.source);
3331
+ var _ponyCause = require$$6;
3332
+ var _updateNotifier = _interopRequireDefault(vendor.updateNotifier);
3333
+ var cliCommands = _interopRequireWildcard(commands, true);
3334
+ var _chalkMarkdown = sdk.chalkMarkdown;
3335
+ var _errors = sdk.errors;
3336
+ var _meowWithSubcommands = meowWithSubcommands$1;
3337
+ const distPath = __dirname;
3338
+ const rootPath = _nodePath.resolve(distPath, '..');
3339
+ const formattedCliCommands = Object.fromEntries(Object.entries(cliCommands).map(entry => {
3340
+ entry[0] = camelToHyphen(entry[0]);
3341
+ return entry;
3342
+ }));
3343
+ function camelToHyphen(str) {
3344
+ return str.replace(/[A-Z]+/g, '-$&').toLowerCase();
3345
+ }
3346
+ (async () => {
3347
+ try {
3348
+ (0, _updateNotifier.default)({
3349
+ pkg: JSON.parse((0, _nodeFs.readFileSync)(_nodePath.join(rootPath, 'package.json'), 'utf8'))
3350
+ }).notify();
3351
+ } catch {}
3352
+ try {
3353
+ await (0, _meowWithSubcommands.meowWithSubcommands)(formattedCliCommands, {
3354
+ aliases: {
3355
+ ci: {
3356
+ description: 'Alias for "report create --view --strict"',
3357
+ argv: ['report', 'create', '--view', '--strict']
3358
+ }
3359
+ },
3360
+ argv: process.argv.slice(2),
3361
+ name: 'socket',
3362
+ importMeta: {
3363
+ url: `${(0, _nodeUrl.pathToFileURL)(__filename)}`
3364
+ }
3365
+ });
3366
+ } catch (err) {
3367
+ let errorTitle;
3368
+ let errorMessage = '';
3369
+ let errorBody;
3370
+ if (err instanceof _errors.AuthError) {
3371
+ errorTitle = 'Authentication error';
3372
+ errorMessage = err.message;
3373
+ } else if (err instanceof _errors.InputError) {
3374
+ errorTitle = 'Invalid input';
3375
+ errorMessage = err.message;
3376
+ errorBody = err.body;
3377
+ } else if (err instanceof Error) {
3378
+ errorTitle = 'Unexpected error';
3379
+ errorMessage = (0, _ponyCause.messageWithCauses)(err);
3380
+ errorBody = (0, _ponyCause.stackWithCauses)(err);
3381
+ } else {
3382
+ errorTitle = 'Unexpected error with no details';
3383
+ }
3384
+ console.error(`${_chalkMarkdown.logSymbols.error} ${_chalk.default.white.bgRed(errorTitle + ':')} ${errorMessage}`);
3385
+ if (errorBody) {
3386
+ console.error(`\n${errorBody}`);
3387
+ }
3388
+ process.exit(1);
3389
+ }
3390
+ })();
3391
+
3392
+ (function (exports) {
3393
+
3394
+ var _interopRequireWildcard = vendor.interopRequireWildcard.default;
3395
+ Object.defineProperty(exports, "__esModule", {
3396
+ value: true
3397
+ });
3398
+ var _exportNames = {};
3399
+ Object.defineProperty(exports, "default", {
3400
+ enumerable: true,
3401
+ get: function () {
3402
+ return _cli.default;
3403
+ }
3404
+ });
3405
+ var _cli = _interopRequireWildcard(cli, true);
3406
+ Object.keys(_cli).forEach(function (key) {
3407
+ if (key === "default" || key === "__esModule") return;
3408
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
3409
+ if (key in exports && exports[key] === _cli[key]) return;
3410
+ Object.defineProperty(exports, key, {
3411
+ enumerable: true,
3412
+ get: function () {
3413
+ return _cli[key];
3414
+ }
3415
+ });
3416
+ });
3417
+ } (cli$1));
3418
+
3419
+ module.exports = cli$1;