snyk 1.1245.0 → 1.1246.0

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.
@@ -11391,7 +11391,7 @@ exports.readJSON = readJSON;
11391
11391
  "use strict";
11392
11392
 
11393
11393
  Object.defineProperty(exports, "__esModule", ({ value: true }));
11394
- exports.DEFAULT_ERROR_MESSAGES = exports.NETWORK_ERRORS = exports.ErrorCodes = exports.DCIGNORE_DRAFTS = exports.IGNORE_FILES_NAMES = exports.IGNORES_DEFAULT = exports.REQUEST_RETRY_DELAY = exports.MAX_RETRY_ATTEMPTS = exports.POLLING_INTERVAL = exports.UPLOAD_CONCURRENCY = exports.MAX_UPLOAD_ATTEMPTS = exports.CACHE_KEY = exports.EXCLUDED_NAMES = exports.DOTSNYK_FILENAME = exports.DCIGNORE_FILENAME = exports.GITIGNORE_FILENAME = exports.GIT_FILENAME = exports.ENCODE_TYPE = exports.HASH_ALGORITHM = exports.MAX_FILE_SIZE = exports.MAX_PAYLOAD = void 0;
11394
+ exports.DEFAULT_ERROR_MESSAGES = exports.NETWORK_ERRORS = exports.ErrorCodes = exports.DCIGNORE_DRAFTS = exports.IGNORE_FILES_NAMES = exports.IGNORES_DEFAULT = exports.ORG_ID_REGEXP = exports.REQUEST_RETRY_DELAY = exports.MAX_RETRY_ATTEMPTS = exports.POLLING_INTERVAL = exports.UPLOAD_CONCURRENCY = exports.MAX_UPLOAD_ATTEMPTS = exports.CACHE_KEY = exports.EXCLUDED_NAMES = exports.DOTSNYK_FILENAME = exports.DCIGNORE_FILENAME = exports.GITIGNORE_FILENAME = exports.GIT_FILENAME = exports.ENCODE_TYPE = exports.HASH_ALGORITHM = exports.MAX_FILE_SIZE = exports.MAX_PAYLOAD = void 0;
11395
11395
  const dcignore_1 = __webpack_require__(55086);
11396
11396
  exports.MAX_PAYLOAD = 4 * 1024 * 1024;
11397
11397
  exports.MAX_FILE_SIZE = 1024 * 1024;
@@ -11408,6 +11408,7 @@ exports.UPLOAD_CONCURRENCY = 2;
11408
11408
  exports.POLLING_INTERVAL = 500;
11409
11409
  exports.MAX_RETRY_ATTEMPTS = 10; // Request retries on network errors
11410
11410
  exports.REQUEST_RETRY_DELAY = 5 * 1000; // delay between retries in milliseconds
11411
+ exports.ORG_ID_REGEXP = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
11411
11412
  exports.IGNORES_DEFAULT = [`**/${exports.GIT_FILENAME}/**`];
11412
11413
  exports.IGNORE_FILES_NAMES = [exports.GITIGNORE_FILENAME, exports.DCIGNORE_FILENAME, exports.DOTSNYK_FILENAME];
11413
11414
  exports.DCIGNORE_DRAFTS = {
@@ -12014,17 +12015,17 @@ const httpUtils_1 = __webpack_require__(11294);
12014
12015
  // The trick to typecast union type alias
12015
12016
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
12016
12017
  function isSubsetErrorCode(code, messages) {
12017
- if (code in messages) {
12018
- return true;
12019
- }
12020
- return false;
12018
+ return code in messages;
12021
12019
  }
12022
- function generateError(errorCode, messages, apiName, error) {
12020
+ function generateError(errorCode, messages, apiName, errorMessage, jsonApiError) {
12021
+ if (jsonApiError) {
12022
+ return httpUtils_1.generateErrorWithDetail(jsonApiError, errorCode, apiName);
12023
+ }
12023
12024
  if (!isSubsetErrorCode(errorCode, messages)) {
12024
- throw { errorCode, messages, apiName };
12025
+ throw { statusCode: errorCode, statusText: errorMessage || 'unknown error occurred', apiName };
12025
12026
  }
12026
12027
  const statusCode = errorCode;
12027
- const statusText = error !== null && error !== void 0 ? error : messages[errorCode];
12028
+ const statusText = errorMessage !== null && errorMessage !== void 0 ? errorMessage : messages[errorCode];
12028
12029
  return {
12029
12030
  type: 'error',
12030
12031
  error: {
@@ -12045,8 +12046,7 @@ const GENERIC_ERROR_MESSAGES = {
12045
12046
  async function compressAndEncode(payload) {
12046
12047
  // encode payload and compress;
12047
12048
  const deflate = util_1.promisify(zlib_1.gzip);
12048
- const compressedPayload = await deflate(Buffer.from(JSON.stringify(payload)).toString('base64'));
12049
- return compressedPayload;
12049
+ return await deflate(Buffer.from(JSON.stringify(payload)).toString('base64'));
12050
12050
  }
12051
12051
  exports.compressAndEncode = compressAndEncode;
12052
12052
  function startSession(options) {
@@ -12123,7 +12123,7 @@ async function getFilters(baseURL, source, attempts = constants_1.MAX_RETRY_ATTE
12123
12123
  if (res.success) {
12124
12124
  return { type: 'success', value: res.body };
12125
12125
  }
12126
- return generateError(res.errorCode, GENERIC_ERROR_MESSAGES, apiName);
12126
+ return generateError(res.errorCode, GENERIC_ERROR_MESSAGES, apiName, undefined, res.jsonApiError);
12127
12127
  }
12128
12128
  exports.getFilters = getFilters;
12129
12129
  function commonHttpHeaders(options) {
@@ -12167,7 +12167,7 @@ async function createBundle(options) {
12167
12167
  if (res.success) {
12168
12168
  return { type: 'success', value: res.body };
12169
12169
  }
12170
- return generateError(res.errorCode, CREATE_BUNDLE_ERROR_MESSAGES, 'createBundle');
12170
+ return generateError(res.errorCode, CREATE_BUNDLE_ERROR_MESSAGES, 'createBundle', undefined, res.jsonApiError);
12171
12171
  }
12172
12172
  exports.createBundle = createBundle;
12173
12173
  const CHECK_BUNDLE_ERROR_MESSAGES = {
@@ -12193,7 +12193,7 @@ async function checkBundle(options) {
12193
12193
  });
12194
12194
  if (res.success)
12195
12195
  return { type: 'success', value: res.body };
12196
- return generateError(res.errorCode, CHECK_BUNDLE_ERROR_MESSAGES, 'checkBundle');
12196
+ return generateError(res.errorCode, CHECK_BUNDLE_ERROR_MESSAGES, 'checkBundle', undefined, res.jsonApiError);
12197
12197
  }
12198
12198
  exports.checkBundle = checkBundle;
12199
12199
  const EXTEND_BUNDLE_ERROR_MESSAGES = {
@@ -12226,7 +12226,7 @@ async function extendBundle(options) {
12226
12226
  });
12227
12227
  if (res.success)
12228
12228
  return { type: 'success', value: res.body };
12229
- return generateError(res.errorCode, EXTEND_BUNDLE_ERROR_MESSAGES, 'extendBundle');
12229
+ return generateError(res.errorCode, EXTEND_BUNDLE_ERROR_MESSAGES, 'extendBundle', undefined, res.jsonApiError);
12230
12230
  }
12231
12231
  exports.extendBundle = extendBundle;
12232
12232
  // eslint-disable-next-line no-shadow
@@ -12272,9 +12272,10 @@ async function getAnalysis(options) {
12272
12272
  },
12273
12273
  };
12274
12274
  const res = await needle_1.makeRequest(config);
12275
- if (res.success)
12275
+ if (res.success) {
12276
12276
  return { type: 'success', value: res.body };
12277
- return generateError(res.errorCode, GET_ANALYSIS_ERROR_MESSAGES, 'getAnalysis');
12277
+ }
12278
+ return generateError(res.errorCode, GET_ANALYSIS_ERROR_MESSAGES, 'getAnalysis', undefined, res.jsonApiError);
12278
12279
  }
12279
12280
  exports.getAnalysis = getAnalysis;
12280
12281
  const REPORT_ERROR_MESSAGES = {
@@ -12321,7 +12322,7 @@ async function initReport(options) {
12321
12322
  const res = await needle_1.makeRequest(config);
12322
12323
  if (res.success)
12323
12324
  return { type: 'success', value: res.body.reportId };
12324
- return generateError(res.errorCode, REPORT_ERROR_MESSAGES, 'initReport');
12325
+ return generateError(res.errorCode, REPORT_ERROR_MESSAGES, 'initReport', undefined, res.jsonApiError);
12325
12326
  }
12326
12327
  exports.initReport = initReport;
12327
12328
  /**
@@ -12346,7 +12347,7 @@ async function getReport(options) {
12346
12347
  const res = await needle_1.makeRequest(config);
12347
12348
  if (res.success)
12348
12349
  return { type: 'success', value: res.body };
12349
- return generateError(res.errorCode, REPORT_ERROR_MESSAGES, 'getReport', (_a = res.error) === null || _a === void 0 ? void 0 : _a.message);
12350
+ return generateError(res.errorCode, REPORT_ERROR_MESSAGES, 'getReport', (_a = res.error) === null || _a === void 0 ? void 0 : _a.message, res.jsonApiError);
12350
12351
  }
12351
12352
  exports.getReport = getReport;
12352
12353
  /**
@@ -12377,7 +12378,7 @@ async function initScmReport(options) {
12377
12378
  const res = await needle_1.makeRequest(config);
12378
12379
  if (res.success)
12379
12380
  return { type: 'success', value: res.body.testId };
12380
- return generateError(res.errorCode, REPORT_ERROR_MESSAGES, 'initReport');
12381
+ return generateError(res.errorCode, REPORT_ERROR_MESSAGES, 'initReport', undefined, res.jsonApiError);
12381
12382
  }
12382
12383
  exports.initScmReport = initScmReport;
12383
12384
  /**
@@ -12402,7 +12403,7 @@ async function getScmReport(options) {
12402
12403
  const res = await needle_1.makeRequest(config);
12403
12404
  if (res.success)
12404
12405
  return { type: 'success', value: res.body };
12405
- return generateError(res.errorCode, REPORT_ERROR_MESSAGES, 'getReport', (_a = res.error) === null || _a === void 0 ? void 0 : _a.message);
12406
+ return generateError(res.errorCode, REPORT_ERROR_MESSAGES, 'getReport', (_a = res.error) === null || _a === void 0 ? void 0 : _a.message, res.jsonApiError);
12406
12407
  }
12407
12408
  exports.getScmReport = getScmReport;
12408
12409
  //# sourceMappingURL=http.js.map
@@ -12517,6 +12518,7 @@ const https_1 = __importDefault(__webpack_require__(95687));
12517
12518
  const url_1 = __webpack_require__(57310);
12518
12519
  const emitter_1 = __webpack_require__(37544);
12519
12520
  const constants_1 = __webpack_require__(65765);
12521
+ const httpUtils_1 = __webpack_require__(11294);
12520
12522
  const sleep = (duration) => new Promise(resolve => setTimeout(resolve, duration));
12521
12523
  const TIMEOUT_DEFAULT = 600000;
12522
12524
  const agentOptions = {
@@ -12529,7 +12531,7 @@ const agentOptions = {
12529
12531
  rejectUnauthorized: !global.ignoreUnknownCA,
12530
12532
  };
12531
12533
  async function makeRequest(payload, attempts = constants_1.MAX_RETRY_ATTEMPTS) {
12532
- var _a;
12534
+ var _a, _b;
12533
12535
  let data;
12534
12536
  if (!payload.isJson && payload.body) {
12535
12537
  data = payload.body;
@@ -12564,6 +12566,7 @@ async function makeRequest(payload, attempts = constants_1.MAX_RETRY_ATTEMPTS) {
12564
12566
  do {
12565
12567
  let errorCode;
12566
12568
  let error;
12569
+ let jsonApiError;
12567
12570
  let response;
12568
12571
  try {
12569
12572
  response = await needle_1.default(method, url, data, options);
@@ -12580,6 +12583,11 @@ async function makeRequest(payload, attempts = constants_1.MAX_RETRY_ATTEMPTS) {
12580
12583
  }
12581
12584
  // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
12582
12585
  const errorMessage = (_a = response === null || response === void 0 ? void 0 : response.body) === null || _a === void 0 ? void 0 : _a.error;
12586
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access
12587
+ const errors = (_b = response === null || response === void 0 ? void 0 : response.body) === null || _b === void 0 ? void 0 : _b.errors;
12588
+ if (httpUtils_1.isJsonApiErrors(errors)) {
12589
+ jsonApiError = errors[0];
12590
+ }
12583
12591
  if (errorMessage) {
12584
12592
  error = error !== null && error !== void 0 ? error : new Error(errorMessage);
12585
12593
  }
@@ -12599,7 +12607,7 @@ async function makeRequest(payload, attempts = constants_1.MAX_RETRY_ATTEMPTS) {
12599
12607
  }
12600
12608
  else {
12601
12609
  attempts = 0;
12602
- return { success: false, errorCode, error };
12610
+ return { success: false, errorCode, error, jsonApiError };
12603
12611
  }
12604
12612
  } while (attempts > 0);
12605
12613
  return { success: false, errorCode: constants_1.ErrorCodes.serviceUnavailable, error: undefined };
@@ -12737,16 +12745,17 @@ exports.reportScm = reportScm;
12737
12745
  /***/ }),
12738
12746
 
12739
12747
  /***/ 11294:
12740
- /***/ ((__unused_webpack_module, exports) => {
12748
+ /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
12741
12749
 
12742
12750
  "use strict";
12743
12751
 
12744
12752
  Object.defineProperty(exports, "__esModule", ({ value: true }));
12745
- exports.getURL = void 0;
12753
+ exports.generateErrorWithDetail = exports.isJsonApiErrors = exports.getURL = void 0;
12754
+ const constants_1 = __webpack_require__(65765);
12746
12755
  function getURL(baseURL, path, orgId) {
12747
12756
  if (routeToGateway(baseURL)) {
12748
- if (!orgId) {
12749
- throw new Error('Org is required for this operation');
12757
+ if (!isValidOrg(orgId)) {
12758
+ throw new Error('A valid Org id is required for this operation');
12750
12759
  }
12751
12760
  return `${baseURL}/hidden/orgs/${orgId}/code${path}`;
12752
12761
  }
@@ -12756,6 +12765,41 @@ exports.getURL = getURL;
12756
12765
  function routeToGateway(baseURL) {
12757
12766
  return baseURL.includes('snykgov.io');
12758
12767
  }
12768
+ function isValidOrg(orgId) {
12769
+ return orgId !== undefined && constants_1.ORG_ID_REGEXP.test(orgId);
12770
+ }
12771
+ function isJsonApiErrors(input) {
12772
+ if (!Array.isArray(input) || input.length < 1) {
12773
+ return false;
12774
+ }
12775
+ for (const element of input) {
12776
+ if (typeof element !== 'object' ||
12777
+ !('status' in element) ||
12778
+ !('code' in element) ||
12779
+ !('title' in element) ||
12780
+ !('detail' in element)) {
12781
+ return false;
12782
+ }
12783
+ }
12784
+ return true;
12785
+ }
12786
+ exports.isJsonApiErrors = isJsonApiErrors;
12787
+ function generateErrorWithDetail(error, statusCode, apiName) {
12788
+ var _a;
12789
+ const errorLink = (_a = error.links) === null || _a === void 0 ? void 0 : _a.about;
12790
+ const detail = `${error.title}${error.detail ? `: ${error.detail}` : ''}${errorLink ? ` (more info: ${errorLink})` : ``}`;
12791
+ const statusText = error.title;
12792
+ return {
12793
+ type: 'error',
12794
+ error: {
12795
+ apiName,
12796
+ statusCode: statusCode,
12797
+ statusText,
12798
+ detail,
12799
+ },
12800
+ };
12801
+ }
12802
+ exports.generateErrorWithDetail = generateErrorWithDetail;
12759
12803
  //# sourceMappingURL=httpUtils.js.map
12760
12804
 
12761
12805
  /***/ }),