663.index.js
30.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
"use strict";
exports.id = 663;
exports.ids = [663,85];
exports.modules = {
/***/ 29430:
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.createApp = void 0;
const Debug = __webpack_require__(15158);
const apps_1 = __webpack_require__(14589);
const promise_1 = __webpack_require__(90430);
const spinner_1 = __webpack_require__(86766);
const debug = Debug(apps_1.SNYK_APP_DEBUG);
/**
* Function to process the app creation request and
* handle any errors that are request error and print
* in a formatted string. It throws is error is unknown
* or cannot be handled.
* @param {ICreateAppRequest} data to create the app
* @returns {String} response formatted string
*/
async function createApp(data) {
debug('App data', data);
const { orgId, snykAppName: name, snykAppRedirectUris: redirectUris, snykAppScopes: scopes, } = data;
const payload = {
method: 'POST',
url: apps_1.getAppsURL(apps_1.EAppsURL.CREATE_APP, { orgId }),
body: {
name,
redirectUris,
scopes,
},
qs: {
version: '2021-08-11~experimental',
},
};
try {
await spinner_1.spinner('Creating your Snyk App');
const response = await promise_1.makeRequestV3(payload);
debug(response);
spinner_1.spinner.clearAll();
return apps_1.handleCreateAppRes(response);
}
catch (error) {
spinner_1.spinner.clearAll();
apps_1.handleV3Error(error);
}
}
exports.createApp = createApp;
/***/ }),
/***/ 68458:
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
Object.defineProperty(exports, "__esModule", ({ value: true }));
const Debug = __webpack_require__(15158);
const process_command_args_1 = __webpack_require__(52369);
const apps_1 = __webpack_require__(14589);
const create_app_1 = __webpack_require__(29430);
// import * as path from 'path';
const create_app_2 = __webpack_require__(38276);
const help_1 = __webpack_require__(21085);
const debug = Debug(apps_1.SNYK_APP_DEBUG);
async function apps(...args0) {
debug('Snyk apps CLI called');
const { options, paths } = process_command_args_1.processCommandArgs(...args0);
debug(options, paths);
const commandVerb1 = paths[0];
const validCommandVerb = commandVerb1 && apps_1.validAppsSubCommands.includes(commandVerb1);
if (!validCommandVerb) {
// Display help md for apps
debug(`Unknown subcommand: ${commandVerb1}`);
return help_1.default('apps');
}
// Check if experimental flag is being used
if (!options.experimental)
throw new Error(apps_1.AppsErrorMessages.useExperimental);
if (commandVerb1 === apps_1.EValidSubCommands.CREATE) {
const createAppData = options.interactive
? await create_app_2.createAppDataInteractive()
: create_app_2.createAppDataScriptable(options);
return await create_app_1.createApp(createAppData);
}
}
exports.default = apps;
/***/ }),
/***/ 21085:
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.findHelpFile = void 0;
const fs = __webpack_require__(35747);
const path = __webpack_require__(85622);
const markdown_renderer_1 = __webpack_require__(99387);
function findHelpFile(helpArgs, helpFolderPath = '../../help/cli-commands') {
while (helpArgs.length > 0) {
// cleanse the filename to only contain letters
// aka: /\W/g but figured this was easier to read
const file = `${helpArgs.join('-').replace(/[^a-z0-9-]/gi, '')}.md`;
const testHelpAbsolutePath = path.resolve(__dirname, helpFolderPath, file);
if (fs.existsSync(testHelpAbsolutePath)) {
return testHelpAbsolutePath;
}
helpArgs = helpArgs.slice(0, -1);
}
return path.resolve(__dirname, helpFolderPath, `README.md`); // Default help file
}
exports.findHelpFile = findHelpFile;
async function help(...args) {
const helpArgs = args.filter((arg) => typeof arg === 'string');
const helpFileAbsolutePath = findHelpFile(helpArgs);
return markdown_renderer_1.renderMarkdown(fs.readFileSync(helpFileAbsolutePath, 'utf8'));
}
exports.default = help;
/***/ }),
/***/ 99387:
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.renderMarkdown = void 0;
const marked_1 = __webpack_require__(30970);
const chalk_1 = __webpack_require__(32589);
const reflow_text_1 = __webpack_require__(67211);
// stateful variable to control left-padding by header level
let currentHeader = 1;
const listItemSeparator = 'LISTITEMSEPARATOR'; // Helper string for rendering ListItems
/**
* @description get padding spaces depending on the last header level used
* @returns string
*/
function getLeftTextPadding() {
return ' '.repeat(currentHeader === 1 || currentHeader === 2 ? 1 : currentHeader - 1);
}
/**
* @description Reads current terminal width if available to limit column width for text-reflowing
* @returns {number}
*/
const defaultMaximumLineWidth = 100;
function getIdealTextWidth(maximumLineWidth = defaultMaximumLineWidth) {
if (typeof process.stdout.columns === 'number') {
if (process.stdout.columns < maximumLineWidth) {
return process.stdout.columns - getLeftTextPadding().length - 5;
}
}
return maximumLineWidth - getLeftTextPadding().length;
}
// Marked custom renderer class
const renderer = {
em(text) {
return chalk_1.default.italic(text);
},
strong(text) {
return chalk_1.default.bold(text);
},
link(href, title, text) {
// Don't render links to relative paths (like local files)
if (href.startsWith('./') || !href.includes('://')) {
return text;
}
const renderedLink = chalk_1.default.bold.blueBright(href);
if (text && text !== href) {
return `${text} ${renderedLink}`;
}
return renderedLink;
},
blockquote(quote) {
return quote;
},
list(body, ordered, start) {
return (body
.split(listItemSeparator)
.map((listItem, listItemIndex) => {
const bulletPoint = ordered ? `${listItemIndex + start}. ` : '- ';
return reflow_text_1.reflowText(listItem, getIdealTextWidth())
.split('\n')
.map((listItemLine, listItemLineIndex) => {
if (!listItemLine) {
return '';
}
return `${getLeftTextPadding()}${listItemLineIndex === 0 ? bulletPoint : ' '}${listItemLine}`;
})
.join('\n');
})
.join('\n') + '\n');
},
listitem(text) {
return text + listItemSeparator;
},
paragraph(text) {
return (reflow_text_1.reflowText(text, getIdealTextWidth())
.split('\n')
.map((s) => getLeftTextPadding() + chalk_1.default.reset() + s)
.join('\n') + '\n\n');
},
codespan(text) {
return chalk_1.default.italic.blueBright(`${text}`);
},
code(code) {
return code + '\n';
},
heading(text, level) {
currentHeader = level;
let coloring;
switch (level) {
case 1:
coloring = chalk_1.default.bold.underline;
break;
case 3:
case 4:
coloring = chalk_1.default;
break;
default:
coloring = chalk_1.default.bold;
break;
}
return `${' '.repeat(level === 1 ? 0 : currentHeader - 2)}${coloring(text)}\n`;
},
};
marked_1.marked.use({ renderer });
marked_1.marked.setOptions({
mangle: false,
});
const htmlUnescapes = {
'&': '&',
'<': '<',
'>': '>',
'"': '"',
''': "'",
'`': '`',
' ': '',
};
/**
* @description Replace HTML entities with their non-encoded variant
* @param {string} text
* @returns {string}
*/
function unescape(text) {
Object.entries(htmlUnescapes).forEach(([escapedChar, unescapedChar]) => {
const escapedCharRegExp = new RegExp(escapedChar, 'g');
text = text.replace(escapedCharRegExp, unescapedChar);
});
return text;
}
function renderMarkdown(markdown) {
return unescape(marked_1.marked.parse(markdown));
}
exports.renderMarkdown = renderMarkdown;
/***/ }),
/***/ 67211:
/***/ ((__unused_webpack_module, exports) => {
/**
Code in this file is adapted from mikaelbr/marked-terminal
https://github.com/mikaelbr/marked-terminal/blob/7501b8bb24a5ed52ec7d9114d4aeefa14f1bf5e6/index.js#L234-L330
MIT License
Copyright (c) 2017 Mikael Brevik
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.reflowText = void 0;
// Compute length of str not including ANSI escape codes.
// See http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
function textLength(str) {
// eslint-disable-next-line no-control-regex
return str.replace(/\u001b\[(?:\d{1,3})(?:;\d{1,3})*m/g, '').length;
}
// Munge \n's and spaces in "text" so that the number of
// characters between \n's is less than or equal to "width".
function reflowText(text, width) {
const HARD_RETURN = '\r|\n';
const HARD_RETURN_GFM_RE = new RegExp(HARD_RETURN + '|<br ?/?>');
const splitRe = HARD_RETURN_GFM_RE;
const sections = text.split(splitRe);
const reflowed = [];
sections.forEach((section) => {
// Split the section by escape codes so that we can
// deal with them separately.
// eslint-disable-next-line no-control-regex
const fragments = section.split(/(\u001b\[(?:\d{1,3})(?:;\d{1,3})*m)/g);
let column = 0;
let currentLine = '';
let lastWasEscapeChar = false;
while (fragments.length) {
const fragment = fragments[0];
if (fragment === '') {
fragments.splice(0, 1);
lastWasEscapeChar = false;
continue;
}
// This is an escape code - leave it whole and
// move to the next fragment.
if (!textLength(fragment)) {
currentLine += fragment;
fragments.splice(0, 1);
lastWasEscapeChar = true;
continue;
}
const words = fragment.split(/[ \t\n]+/);
for (let i = 0; i < words.length; i++) {
let word = words[i];
let addSpace = column != 0;
if (lastWasEscapeChar)
addSpace = false;
// If adding the new word overflows the required width
if (column + word.length > width) {
if (word.length <= width) {
// If the new word is smaller than the required width
// just add it at the beginning of a new line
reflowed.push(currentLine);
currentLine = word;
column = word.length;
}
else {
// If the new word is longer than the required width
// split this word into smaller parts.
const w = word.substr(0, width - column);
if (addSpace)
currentLine += ' ';
currentLine += w;
reflowed.push(currentLine);
currentLine = '';
column = 0;
word = word.substr(w.length);
while (word.length) {
const w = word.substr(0, width);
if (!w.length)
break;
if (w.length < width) {
currentLine = w;
column = w.length;
break;
}
else {
reflowed.push(w);
word = word.substr(width);
}
}
}
}
else {
if (addSpace) {
currentLine += ' ';
column++;
}
currentLine += word;
column += word.length;
}
lastWasEscapeChar = false;
}
fragments.splice(0, 1);
}
if (textLength(currentLine))
reflowed.push(currentLine);
});
return reflowed.join('\n');
}
exports.reflowText = reflowText;
/***/ }),
/***/ 52369:
/***/ ((__unused_webpack_module, exports) => {
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.processCommandArgs = void 0;
function processCommandArgs(...args) {
let options = {};
if (typeof args[args.length - 1] === 'object') {
options = args.pop();
}
args = args.filter(Boolean);
// For repository scanning, populate with default path (cwd) if no path given
if (args.length === 0 && !options.docker) {
args.unshift(process.cwd());
}
return { options, paths: args };
}
exports.processCommandArgs = processCommandArgs;
/***/ }),
/***/ 89019:
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.CreateAppPromptData = exports.AppsErrorMessages = exports.validAppsSubCommands = exports.EAppsURL = exports.EValidSubCommands = exports.SNYK_APP_DEBUG = exports.SNYK_APP_ORG_ID = exports.SNYK_APP_CLIENT_ID = exports.SNYK_APP_SCOPES = exports.SNYK_APP_REDIRECT_URIS = exports.SNYK_APP_NAME = void 0;
const chalk_1 = __webpack_require__(32589);
exports.SNYK_APP_NAME = 'snykAppName';
exports.SNYK_APP_REDIRECT_URIS = 'snykAppRedirectUris';
exports.SNYK_APP_SCOPES = 'snykAppScopes';
exports.SNYK_APP_CLIENT_ID = 'snykAppClientId';
exports.SNYK_APP_ORG_ID = 'snykAppOrgId';
exports.SNYK_APP_DEBUG = 'snyk:apps';
var EValidSubCommands;
(function (EValidSubCommands) {
EValidSubCommands["CREATE"] = "create";
})(EValidSubCommands = exports.EValidSubCommands || (exports.EValidSubCommands = {}));
var EAppsURL;
(function (EAppsURL) {
EAppsURL[EAppsURL["CREATE_APP"] = 0] = "CREATE_APP";
})(EAppsURL = exports.EAppsURL || (exports.EAppsURL = {}));
exports.validAppsSubCommands = Object.values(EValidSubCommands);
exports.AppsErrorMessages = {
orgRequired: `Option '--org' is required! For interactive mode, please use '--interactive' or '-i' flag. For more information please run the help command 'snyk apps --help' or 'snyk apps -h'.`,
nameRequired: `Option '--name' is required! For interactive mode, please use '--interactive' or '-i' flag. For more information please run the help command 'snyk apps --help' or 'snyk apps -h'.`,
redirectUrisRequired: `Option '--redirect-uris' is required! For interactive mode, please use '--interactive' or '-i' flag. For more information please run the help command 'snyk apps --help' or 'snyk apps -h'.`,
scopesRequired: `Option '--scopes' is required! For interactive mode, please use '--interactive' or '-i' flag. For more information please run the help command 'snyk apps --help' or 'snyk apps -h'.`,
useExperimental: `\n${chalk_1.default.redBright("All 'apps' commands are only accessible behind the '--experimental' flag.")}\n
The behaviour can change at any time, without prior notice.
You are kindly advised to use all the commands with caution.
${chalk_1.default.bold('Usage')}
${chalk_1.default.italic('snyk apps <COMMAND> --experimental')}\n`,
};
exports.CreateAppPromptData = {
SNYK_APP_NAME: {
name: exports.SNYK_APP_NAME,
message: `Name of the Snyk App (visible to users when they install the Snyk App)?`,
},
SNYK_APP_REDIRECT_URIS: {
name: exports.SNYK_APP_REDIRECT_URIS,
message: `Your Snyk App's redirect URIs (comma seprated list. ${chalk_1.default.yellowBright(' Ex: https://example1.com,https://example2.com')})?: `,
},
SNYK_APP_SCOPES: {
name: exports.SNYK_APP_SCOPES,
message: `Your Snyk App's permission scopes (comma separated list. ${chalk_1.default.yellowBright(' Ex: apps:beta')})?: `,
},
SNYK_APP_ORG_ID: {
name: exports.SNYK_APP_ORG_ID,
message: 'Please provide the org id under which you want to create your Snyk App: ',
},
};
/***/ }),
/***/ 38276:
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.createAppDataInteractive = exports.createAppDataScriptable = void 0;
const __1 = __webpack_require__(14589);
const inquirer = __webpack_require__(32139);
const errors_1 = __webpack_require__(55191);
/**
* Validates and parsed the data required to create app.
* Throws error if option is not provided or is invalid
* @param {ICreateAppOptions} options required to create an app
* @returns {ICreateAppRequest} data that is used to make the request
*/
function createAppDataScriptable(options) {
if (!options.org) {
throw new errors_1.ValidationError(__1.AppsErrorMessages.orgRequired);
}
else if (typeof __1.validateUUID(options.org) === 'string') {
// Combines to form "Invalid UUID provided for org id"
throw new errors_1.ValidationError(`${__1.validateUUID(options.org)} for org id`);
}
else if (!options.name) {
throw new errors_1.ValidationError(__1.AppsErrorMessages.nameRequired);
}
else if (!options['redirect-uris']) {
throw new errors_1.ValidationError(__1.AppsErrorMessages.redirectUrisRequired);
}
else if (typeof __1.validateAllURL(options['redirect-uris']) === 'string') {
throw new errors_1.ValidationError(__1.validateAllURL(options['redirect-uris']));
}
else if (!options.scopes) {
throw new errors_1.ValidationError(__1.AppsErrorMessages.scopesRequired);
}
else {
return {
orgId: options.org,
snykAppName: options.name,
snykAppRedirectUris: options['redirect-uris']
.replace(/\s+/g, '')
.split(','),
snykAppScopes: options.scopes.replace(/\s+/g, '').split(','),
};
}
}
exports.createAppDataScriptable = createAppDataScriptable;
// Interactive format
async function createAppDataInteractive() {
// Proceed with interactive
const answers = await inquirer.prompt(__1.createAppPrompts);
// Process answers
const snykAppName = answers[__1.SNYK_APP_NAME].trim();
const snykAppRedirectUris = answers[__1.SNYK_APP_REDIRECT_URIS].replace(/\s+/g, '').split(',');
const snykAppScopes = answers[__1.SNYK_APP_SCOPES].replace(/\s+/g, '').split(',');
const orgId = answers[__1.SNYK_APP_ORG_ID].trim();
// POST: to create an app
return {
orgId,
snykAppName,
snykAppRedirectUris,
snykAppScopes,
};
}
exports.createAppDataInteractive = createAppDataInteractive;
/***/ }),
/***/ 14589:
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
__exportStar(__webpack_require__(89019), exports);
__exportStar(__webpack_require__(86950), exports);
__exportStar(__webpack_require__(31940), exports);
__exportStar(__webpack_require__(91596), exports);
__exportStar(__webpack_require__(46693), exports);
__exportStar(__webpack_require__(8864), exports);
/***/ }),
/***/ 8864:
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.validInput = exports.validateUUID = exports.validURL = exports.validateAllURL = void 0;
const uuid = __webpack_require__(42277);
/**
*
* @param {String} input of space separated URL/URI passed by
* user for redirect URIs
* @returns { String | Boolean } complying with inquirer return values, the function
* separates the string on space and validates each to see
* if a valid URL/URI. Return a string if invalid and
* boolean true if valid
*/
function validateAllURL(input) {
const trimmedInput = input.trim();
let errMessage = '';
for (const i of trimmedInput.split(',')) {
if (typeof validURL(i) == 'string')
errMessage = errMessage + `\n${validURL(i)}`;
}
if (errMessage)
return errMessage;
return true;
}
exports.validateAllURL = validateAllURL;
/**
* Custom validation logic which takes in consideration
* creation of Snyk Apps and thus allows localhost.com
* as a valid URL.
* @param {String} input of URI/URL value to validate using
* regex
* @returns {String | Boolean } string message is not valid
* and boolean true if valid
*/
function validURL(input) {
try {
new URL(input);
return true;
}
catch (error) {
return `${input} is not a valid URL`;
}
}
exports.validURL = validURL;
/**
* Function validates if a valid UUID (version of UUID not tacken into account)
* @param {String} input UUID to be validated
* @returns {String | Boolean } string message is not valid
* and boolean true if valid
*/
function validateUUID(input) {
return uuid.validate(input) ? true : 'Invalid UUID provided';
}
exports.validateUUID = validateUUID;
/**
* @param {String} input
* @returns {String | Boolean } string message is not valid
* and boolean true if valid
*/
function validInput(input) {
if (!input)
return 'Please enter something';
return true;
}
exports.validInput = validInput;
/***/ }),
/***/ 86950:
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.createAppPrompts = void 0;
const constants_1 = __webpack_require__(89019);
const input_validator_1 = __webpack_require__(8864);
/**
* Prompts for $snyk apps create command
*/
exports.createAppPrompts = [
{
name: constants_1.CreateAppPromptData.SNYK_APP_NAME.name,
message: constants_1.CreateAppPromptData.SNYK_APP_NAME.message,
validate: input_validator_1.validInput,
},
{
name: constants_1.CreateAppPromptData.SNYK_APP_REDIRECT_URIS.name,
message: constants_1.CreateAppPromptData.SNYK_APP_REDIRECT_URIS.message,
validate: input_validator_1.validateAllURL,
},
{
name: constants_1.CreateAppPromptData.SNYK_APP_SCOPES.name,
message: constants_1.CreateAppPromptData.SNYK_APP_SCOPES.message,
validate: input_validator_1.validInput,
},
{
name: constants_1.CreateAppPromptData.SNYK_APP_ORG_ID.name,
message: constants_1.CreateAppPromptData.SNYK_APP_ORG_ID.message,
validate: input_validator_1.validateUUID,
},
];
/***/ }),
/***/ 31940:
/***/ ((__unused_webpack_module, exports) => {
Object.defineProperty(exports, "__esModule", ({ value: true }));
/***/ }),
/***/ 46693:
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.readAppsHelpMarkdown = void 0;
const fs = __webpack_require__(35747);
const markdown_renderer_1 = __webpack_require__(99387);
function readAppsHelpMarkdown(filename) {
const file = fs.readFileSync(filename, 'utf8');
return markdown_renderer_1.renderMarkdown(file);
}
exports.readAppsHelpMarkdown = readAppsHelpMarkdown;
/***/ }),
/***/ 91596:
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.handleCreateAppRes = exports.handleV3Error = exports.getAppsURL = void 0;
/**
* Collection of utility function for the
* $snyk apps commands
*/
const _1 = __webpack_require__(14589);
const chalk_1 = __webpack_require__(32589);
const errors_1 = __webpack_require__(55191);
const Debug = __webpack_require__(15158);
const config_1 = __webpack_require__(22541);
const debug = Debug(_1.SNYK_APP_DEBUG);
function getAppsURL(selection, opts = {}) {
// Get the V3 URL from user config
// Environment variable takes precendence over config
const baseURL = config_1.default.API_V3_URL;
debug(`API v3 base URL => ${baseURL}`);
switch (selection) {
case _1.EAppsURL.CREATE_APP:
return `${baseURL}/orgs/${opts.orgId}/apps`;
default:
throw new Error('Invalid selection for URL');
}
}
exports.getAppsURL = getAppsURL;
function handleV3Error(error) {
if (error.code) {
if (error.code === 400) {
// Bad request
const responseJSON = error.body;
const errString = errorsToDisplayString(responseJSON);
throw new Error(errString);
}
else if (error.code === 401) {
// Unauthorized
throw errors_1.AuthFailedError();
}
else if (error.code === 403) {
throw new Error('Forbidden! the authentication token does not have access to the resource.');
}
else if (error.code === 404) {
const responseJSON = error.body;
const errString = errorsToDisplayString(responseJSON);
throw new Error(errString);
}
else if (error.code === 500) {
throw new errors_1.InternalServerError('Internal server error');
}
else {
throw new Error(error.message);
}
}
else {
throw error;
}
}
exports.handleV3Error = handleV3Error;
/**
* @param errRes V3Error response
* @returns {String} Iterates over error and
* converts them into a readible string
*/
function errorsToDisplayString(errRes) {
const resString = `Uh oh! an error occurred while trying to create the Snyk App.
Please run the command with '--debug' or '-d' to get more information`;
if (!errRes.errors)
return resString;
errRes.errors.forEach((e) => {
let metaString = '', sourceString = '';
if (e.meta) {
for (const [key, value] of Object.entries(e.meta)) {
metaString += `${key}: ${value}\n`;
}
}
if (e.source) {
for (const [key, value] of Object.entries(e.source)) {
sourceString += `${key}: ${value}\n`;
}
}
const meta = metaString || '-';
const source = sourceString || '-';
return `Uh oh! an error occured while trying to create the Snyk App.
Error Description:\t${e.detail}
Request Status:\t${e.status}
Source:\t${source}
Meta:\t${meta}`;
});
return resString;
}
function handleCreateAppRes(res) {
const { name, clientId, redirectUris, scopes, isPublic, clientSecret, } = res.data.attributes;
return `Snyk App created successfully!
Please ensure you save the following details:
App Name:\t${name}
Client ID:\t${clientId}
Redirect URIs:\t${redirectUris}
Scopes:\t${scopes}
Is App Public:\t${isPublic}
Client Secret (${chalk_1.default.redBright('keep it safe and protected')}):\t${clientSecret}`;
}
exports.handleCreateAppRes = handleCreateAppRes;
/***/ }),
/***/ 90430:
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.makeRequestV3 = exports.makeRequest = void 0;
const api_token_1 = __webpack_require__(95181);
const request = __webpack_require__(52050);
async function makeRequest(payload) {
return new Promise((resolve, reject) => {
request.makeRequest(payload, (error, res, body) => {
if (error) {
return reject(error);
}
if (res.statusCode !== 200) {
return reject({
code: res.statusCode,
message: body === null || body === void 0 ? void 0 : body.message,
});
}
resolve(body);
});
});
}
exports.makeRequest = makeRequest;
/**
* All v3 request will essentially be the same and are JSON by default
* Thus if no headers provided default headers are used
* @param {any} payload for the request
* @returns
*/
async function makeRequestV3(payload) {
return new Promise((resolve, reject) => {
var _a;
payload.headers = (_a = payload.headers) !== null && _a !== void 0 ? _a : {
'Content-Type': 'application/vnd.api+json',
authorization: api_token_1.getAuthHeader(),
};
payload.json = true;
request.makeRequest(payload, (error, res, body) => {
if (error) {
return reject(error);
}
if (res.statusCode >= 400) {
return reject({
code: res.statusCode,
body: JSON.parse(body),
});
}
resolve(JSON.parse(body));
});
});
}
exports.makeRequestV3 = makeRequestV3;
/***/ })
};
;
//# sourceMappingURL=663.index.js.map