"Fossies" - the Fresh Open Source Software Archive

Member "cli-1.1260.0/packages/snyk-fix/src/types.ts" (4 Dec 2023, 5270 Bytes) of package /linux/misc/snyk-cli-1.1260.0.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 import { DepGraphData } from '@snyk/dep-graph';
    2 import { CustomError } from './lib/errors/custom-error';
    3 
    4 /* Scan Result
    5  * this data is returned by the CLI plugins to identify
    6  * what should be scanned for issues
    7  */
    8 export interface GitTarget {
    9   remoteUrl?: string;
   10   branch?: string;
   11 }
   12 export interface ContainerTarget {
   13   image: string;
   14 }
   15 
   16 interface UnknownTarget {
   17   name: string; // Should be equal to the project name
   18 }
   19 
   20 export interface ScanResult {
   21   readonly identity: Identity;
   22   readonly facts: Facts[];
   23   readonly name?: string;
   24   readonly policy?: string;
   25   readonly target?: GitTarget | ContainerTarget | UnknownTarget;
   26 }
   27 
   28 export interface Identity {
   29   type: string;
   30   targetFile?: string;
   31   // options used to scan should be here
   32   args?: { [key: string]: string };
   33 }
   34 
   35 export interface Facts {
   36   type: string;
   37   data: any;
   38 }
   39 
   40 /* Test Result
   41  * this data is returned on a `snyk test` for supported project types
   42  * after the relevant plugin extracts dependencies
   43  */
   44 export interface TestResult {
   45   readonly issues: Issue[];
   46   readonly issuesData: IssuesData;
   47   readonly depGraphData: DepGraphData;
   48   readonly remediation?: RemediationChanges; // TODO: not yet in the CLI TestResults type
   49 }
   50 
   51 export interface Issue {
   52   pkgName: string;
   53   pkgVersion?: string;
   54   issueId: string;
   55   fixInfo: FixInfo;
   56 }
   57 
   58 interface UpgradePath {
   59   path: UpgradePathItem[];
   60 }
   61 
   62 export interface FixInfo {
   63   upgradePaths?: UpgradePath[];
   64   isPatchable?: boolean;
   65   nearestFixedInVersion?: string;
   66 }
   67 
   68 interface UpgradePathItem {
   69   name: string;
   70   version: string;
   71   newVersion?: string;
   72   isDropped?: boolean;
   73 }
   74 export interface IssuesData {
   75   [issueId: string]: {
   76     id: string;
   77     severity: SEVERITY;
   78     title: string;
   79   };
   80 }
   81 
   82 /* Remediation Data
   83  * this data is returned on a `snyk test` for supported project types
   84  */
   85 export interface Upgrade {
   86   upgradeTo: string; // name@version
   87 }
   88 
   89 export interface UpgradeVulns extends Upgrade {
   90   vulns: string[];
   91 }
   92 export interface UpgradeRemediation extends UpgradeVulns {
   93   upgrades: string[];
   94 }
   95 
   96 export interface PatchRemediation {
   97   paths: PatchObject[];
   98 }
   99 
  100 export interface DependencyUpdates {
  101   [from: string]: UpgradeRemediation;
  102 }
  103 
  104 export interface PinRemediation extends UpgradeVulns {
  105   isTransitive: boolean;
  106 }
  107 
  108 export interface DependencyPins {
  109   [name: string]: PinRemediation;
  110 }
  111 
  112 // Remediation changes to be applied to the project,
  113 // including information on all and unresolved issues.
  114 export interface RemediationChanges {
  115   unresolved: IssueData[];
  116   upgrade: DependencyUpdates;
  117   patch: {
  118     [name: string]: PatchRemediation;
  119   };
  120   ignore: unknown;
  121   pin: DependencyPins;
  122 }
  123 
  124 export interface IssueData {
  125   id: string;
  126   packageName: string;
  127   version: string;
  128   moduleName?: string;
  129   below: string; // Vulnerable below version
  130   semver: {
  131     vulnerable: string | string[];
  132     vulnerableHashes?: string[];
  133     vulnerableByDistro?: {
  134       [distroNameAndVersion: string]: string[];
  135     };
  136   };
  137   patches: Patch[];
  138   isNew: boolean;
  139   description: string;
  140   title: string;
  141   severity: SEVERITY;
  142   fixedIn: string[];
  143   legalInstructions?: string;
  144 }
  145 
  146 interface Patch {
  147   version: string;
  148   id: string;
  149   urls: string[];
  150   modificationTime: string;
  151 }
  152 
  153 export interface PatchObject {
  154   [name: string]: {
  155     patched: string;
  156   };
  157 }
  158 
  159 export enum SEVERITY {
  160   LOW = 'low',
  161   MEDIUM = 'medium',
  162   HIGH = 'high',
  163   CRITICAL = 'critical',
  164 }
  165 
  166 /* End Remediation Data
  167  */
  168 
  169 /* Snyk fix types
  170  * Types for concepts introduced as part of this lib
  171  */
  172 
  173 export type SupportedScanTypes = 'pip';
  174 
  175 export interface Workspace {
  176   path: string;
  177   readFile: (path: string) => Promise<string>;
  178   writeFile: (path: string, content: string) => Promise<void>;
  179 }
  180 export interface EntityToFix {
  181   readonly workspace: Workspace;
  182   readonly scanResult: ScanResult;
  183   readonly testResult: TestResult;
  184   readonly options: CliTestOptions;
  185 }
  186 
  187 // Partial CLI test options interface
  188 // defining only what is used by @snyk/fix
  189 // add more as needed
  190 interface BaseTestOptions {
  191   packageManager?: string;
  192 }
  193 export interface PythonTestOptions extends BaseTestOptions {
  194   command?: string; // python interpreter to use for python tests
  195   dev?: boolean;
  196 }
  197 export type CliTestOptions = PythonTestOptions;
  198 export interface WithError<Original> {
  199   original: Original;
  200   error: CustomError;
  201   tip?: string;
  202 }
  203 
  204 export interface WithAttemptedFixChanges<Original> {
  205   original: Original;
  206   changes: FixChangesSummary[];
  207 }
  208 
  209 export interface WithUserMessage<Original> {
  210   original: Original;
  211   userMessage: string;
  212 }
  213 
  214 export type FixChangesSummary = FixChangesSuccess | FixChangesError;
  215 
  216 export interface FixChangesSuccess {
  217   success: true;
  218   userMessage: string;
  219   issueIds: string[];
  220   from?: string;
  221   to?: string;
  222 }
  223 
  224 export interface FixChangesError {
  225   success: false;
  226   userMessage: string;
  227   reason: string;
  228   tip?: string;
  229   issueIds: string[];
  230   from?: string;
  231   to?: string;
  232 }
  233 
  234 export interface ErrorsByEcoSystem {
  235   [ecosystem: string]: { originals: EntityToFix[]; userMessage: string };
  236 }
  237 export interface FixOptions {
  238   dryRun?: boolean;
  239   quiet?: boolean;
  240   stripAnsi?: boolean;
  241   sequentialFix?: boolean;
  242 }
  243 
  244 export interface FixedMeta {
  245   fixed: number;
  246   failed: number;
  247   fixableIssues: number;
  248   fixedIssues: number;
  249   totalIssues: number;
  250 }