"Fossies" - the Fresh Open Source Software Archive

Member "cli-1.1280.1/src/lib/formatters/format-monitor-response.ts" (20 Feb 2024, 2630 Bytes) of package /linux/misc/snyk-cli-1.1280.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) TypeScript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 const assign = require('lodash.assign');
    2 import chalk from 'chalk';
    3 import * as url from 'url';
    4 
    5 import { MonitorResult } from '../types';
    6 import config from '../config';
    7 import { showMultiScanTip } from './show-multi-scan-tip';
    8 
    9 export function formatErrorMonitorOutput(
   10   packageManager,
   11   res: MonitorResult,
   12   options,
   13   projectName?: string,
   14 ): string {
   15   const humanReadableName = projectName
   16     ? `${res.path} (${projectName})`
   17     : res.path;
   18   const strOutput =
   19     chalk.bold.white('\nMonitoring ' + humanReadableName + '...\n\n') +
   20     '\n\n' +
   21     (packageManager === 'maven'
   22       ? chalk.yellow('Detected 0 dependencies (no project created)')
   23       : '');
   24   return options.json
   25     ? JSON.stringify(
   26         assign({}, res, {
   27           packageManager,
   28         }),
   29       )
   30     : strOutput;
   31 }
   32 
   33 export function formatMonitorOutput(
   34   packageManager,
   35   res: MonitorResult,
   36   options,
   37   projectName?: string,
   38   foundProjectCount?: number,
   39 ): string {
   40   const manageUrl = buildManageUrl(res.id, res.org);
   41   const multiScanTip = showMultiScanTip(
   42     packageManager,
   43     options,
   44     foundProjectCount,
   45   );
   46   const issues = res.licensesPolicy ? 'issues' : 'vulnerabilities';
   47   const humanReadableName = projectName
   48     ? `${res.path} (${projectName})`
   49     : res.path;
   50   const strOutput =
   51     chalk.bold.white('\nMonitoring ' + humanReadableName + '...\n\n') +
   52     'Explore this snapshot at ' +
   53     res.uri +
   54     '\n\n' +
   55     (multiScanTip ? `${multiScanTip}\n\n` : '') +
   56     (res.isMonitored
   57       ? 'Notifications about newly disclosed ' +
   58         issues +
   59         ' related ' +
   60         'to these dependencies will be emailed to you.\n'
   61       : chalk.bold.red(
   62           'Project is inactive, so notifications are turned ' +
   63             'off.\nActivate this project here: ' +
   64             manageUrl +
   65             '\n\n',
   66         )) +
   67     (res.trialStarted
   68       ? chalk.yellow(
   69           "You're over the free plan usage limit, \n" +
   70             'and are now on a free 14-day premium trial.\n' +
   71             'View plans here: ' +
   72             manageUrl +
   73             '\n\n',
   74         )
   75       : '');
   76 
   77   return options.json
   78     ? JSON.stringify(
   79         assign({}, res, {
   80           manageUrl,
   81           packageManager,
   82         }),
   83       )
   84     : strOutput;
   85 }
   86 
   87 function buildManageUrl(resId: string, org?: string): string {
   88   const endpoint = url.parse(config.API);
   89   let leader = '';
   90   if (org) {
   91     leader = '/org/' + org;
   92   }
   93   endpoint.pathname = leader + '/manage';
   94   const manageUrl = url.format(endpoint);
   95 
   96   // TODO: what was this meant to do?
   97   endpoint.pathname = leader + '/monitor/' + resId;
   98   return manageUrl;
   99 }