Socket
Socket
Sign inDemoInstall

@snyk/code-client

Package Overview
Dependencies
Maintainers
1
Versions
102
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@snyk/code-client - npm Package Compare versions

Comparing version 4.22.5 to 4.23.0

dist/interfaces/json-api.d.ts

5

dist/http.d.ts

@@ -5,3 +5,3 @@ /// <reference types="node" />

import { AnalysisResult, ReportResult } from './interfaces/analysis-result.interface';
import { AnalysisOptions, AnalysisContext, ReportOptions, ScmReportOptions } from './interfaces/analysis-options.interface';
import { AnalysisContext, AnalysisOptions, ReportOptions, ScmReportOptions } from './interfaces/analysis-options.interface';
declare type ResultSuccess<T> = {

@@ -11,3 +11,3 @@ type: 'success';

};
declare type ResultError<E> = {
export declare type ResultError<E> = {
type: 'error';

@@ -18,2 +18,3 @@ error: {

apiName: string;
detail?: string | undefined;
};

@@ -20,0 +21,0 @@ };

38

dist/http.js

@@ -17,13 +17,13 @@ "use strict";

function isSubsetErrorCode(code, messages) {
if (code in messages) {
return true;
return code in messages;
}
function generateError(errorCode, messages, apiName, errorMessage, jsonApiError) {
if (jsonApiError) {
return httpUtils_1.generateErrorWithDetail(jsonApiError, errorCode, apiName);
}
return false;
}
function generateError(errorCode, messages, apiName, error) {
if (!isSubsetErrorCode(errorCode, messages)) {
throw { errorCode, messages, apiName };
throw { statusCode: errorCode, statusText: errorMessage || 'unknown error occurred', apiName };
}
const statusCode = errorCode;
const statusText = error !== null && error !== void 0 ? error : messages[errorCode];
const statusText = errorMessage !== null && errorMessage !== void 0 ? errorMessage : messages[errorCode];
return {

@@ -49,4 +49,3 @@ type: 'error',

const deflate = util_1.promisify(zlib_1.gzip);
const compressedPayload = await deflate(Buffer.from(JSON.stringify(payload)).toString('base64'));
return compressedPayload;
return await deflate(Buffer.from(JSON.stringify(payload)).toString('base64'));
}

@@ -128,3 +127,3 @@ exports.compressAndEncode = compressAndEncode;

}
return generateError(res.errorCode, GENERIC_ERROR_MESSAGES, apiName);
return generateError(res.errorCode, GENERIC_ERROR_MESSAGES, apiName, undefined, res.jsonApiError);
}

@@ -173,3 +172,3 @@ exports.getFilters = getFilters;

}
return generateError(res.errorCode, CREATE_BUNDLE_ERROR_MESSAGES, 'createBundle');
return generateError(res.errorCode, CREATE_BUNDLE_ERROR_MESSAGES, 'createBundle', undefined, res.jsonApiError);
}

@@ -200,3 +199,3 @@ exports.createBundle = createBundle;

return { type: 'success', value: res.body };
return generateError(res.errorCode, CHECK_BUNDLE_ERROR_MESSAGES, 'checkBundle');
return generateError(res.errorCode, CHECK_BUNDLE_ERROR_MESSAGES, 'checkBundle', undefined, res.jsonApiError);
}

@@ -234,3 +233,3 @@ exports.checkBundle = checkBundle;

return { type: 'success', value: res.body };
return generateError(res.errorCode, EXTEND_BUNDLE_ERROR_MESSAGES, 'extendBundle');
return generateError(res.errorCode, EXTEND_BUNDLE_ERROR_MESSAGES, 'extendBundle', undefined, res.jsonApiError);
}

@@ -281,5 +280,6 @@ exports.extendBundle = extendBundle;

const res = await needle_1.makeRequest(config);
if (res.success)
if (res.success) {
return { type: 'success', value: res.body };
return generateError(res.errorCode, GET_ANALYSIS_ERROR_MESSAGES, 'getAnalysis');
}
return generateError(res.errorCode, GET_ANALYSIS_ERROR_MESSAGES, 'getAnalysis', undefined, res.jsonApiError);
}

@@ -331,3 +331,3 @@ exports.getAnalysis = getAnalysis;

return { type: 'success', value: res.body.reportId };
return generateError(res.errorCode, REPORT_ERROR_MESSAGES, 'initReport');
return generateError(res.errorCode, REPORT_ERROR_MESSAGES, 'initReport', undefined, res.jsonApiError);
}

@@ -357,3 +357,3 @@ exports.initReport = initReport;

return { type: 'success', value: res.body };
return generateError(res.errorCode, REPORT_ERROR_MESSAGES, 'getReport', (_a = res.error) === null || _a === void 0 ? void 0 : _a.message);
return generateError(res.errorCode, REPORT_ERROR_MESSAGES, 'getReport', (_a = res.error) === null || _a === void 0 ? void 0 : _a.message, res.jsonApiError);
}

@@ -389,3 +389,3 @@ exports.getReport = getReport;

return { type: 'success', value: res.body.testId };
return generateError(res.errorCode, REPORT_ERROR_MESSAGES, 'initReport');
return generateError(res.errorCode, REPORT_ERROR_MESSAGES, 'initReport', undefined, res.jsonApiError);
}

@@ -415,5 +415,5 @@ exports.initScmReport = initScmReport;

return { type: 'success', value: res.body };
return generateError(res.errorCode, REPORT_ERROR_MESSAGES, 'getReport', (_a = res.error) === null || _a === void 0 ? void 0 : _a.message);
return generateError(res.errorCode, REPORT_ERROR_MESSAGES, 'getReport', (_a = res.error) === null || _a === void 0 ? void 0 : _a.message, res.jsonApiError);
}
exports.getScmReport = getScmReport;
//# sourceMappingURL=http.js.map

@@ -5,2 +5,3 @@ /// <reference types="node" />

import * as querystring from 'querystring';
import { JsonApiError } from './interfaces/json-api';
export declare interface Global extends NodeJS.Global {

@@ -27,4 +28,5 @@ ignoreUnknownCA: boolean;

error: Error | undefined;
jsonApiError?: JsonApiError | undefined;
};
export declare function makeRequest<T = void>(payload: Payload, attempts?: number): Promise<SuccessResponse<T> | FailedResponse>;
export {};

@@ -34,2 +34,3 @@ "use strict";

const constants_1 = require("./constants");
const httpUtils_1 = require("./utils/httpUtils");
const sleep = (duration) => new Promise(resolve => setTimeout(resolve, duration));

@@ -47,3 +48,3 @@ const TIMEOUT_DEFAULT = 600000;

async function makeRequest(payload, attempts = constants_1.MAX_RETRY_ATTEMPTS) {
var _a;
var _a, _b;
let data;

@@ -83,2 +84,3 @@ if (!payload.isJson && payload.body) {

let error;
let jsonApiError;
let response;

@@ -100,2 +102,7 @@ try {

const errorMessage = (_a = response === null || response === void 0 ? void 0 : response.body) === null || _a === void 0 ? void 0 : _a.error;
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access
const errors = (_b = response === null || response === void 0 ? void 0 : response.body) === null || _b === void 0 ? void 0 : _b.errors;
if (httpUtils_1.isJsonApiErrors(errors)) {
jsonApiError = errors[0];
}
if (errorMessage) {

@@ -120,3 +127,3 @@ error = error !== null && error !== void 0 ? error : new Error(errorMessage);

attempts = 0;
return { success: false, errorCode, error };
return { success: false, errorCode, error, jsonApiError };
}

@@ -123,0 +130,0 @@ } while (attempts > 0);

@@ -0,1 +1,5 @@

import { JsonApiError } from '../interfaces/json-api';
import { ResultError } from '../http';
export declare function getURL(baseURL: string, path: string, orgId?: string): string;
export declare function isJsonApiErrors(input: unknown): input is JsonApiError[];
export declare function generateErrorWithDetail<E>(error: JsonApiError, statusCode: number, apiName: string): ResultError<E>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getURL = void 0;
exports.generateErrorWithDetail = exports.isJsonApiErrors = exports.getURL = void 0;
const constants_1 = require("../constants");

@@ -21,2 +21,34 @@ function getURL(baseURL, path, orgId) {

}
function isJsonApiErrors(input) {
if (!Array.isArray(input) || input.length < 1) {
return false;
}
for (const element of input) {
if (typeof element !== 'object' ||
!('status' in element) ||
!('code' in element) ||
!('title' in element) ||
!('detail' in element)) {
return false;
}
}
return true;
}
exports.isJsonApiErrors = isJsonApiErrors;
function generateErrorWithDetail(error, statusCode, apiName) {
var _a;
const errorLink = (_a = error.links) === null || _a === void 0 ? void 0 : _a.about;
const detail = `${error.title}${error.detail ? `: ${error.detail}` : ''}${errorLink ? ` (more info: ${errorLink})` : ``}`;
const statusText = error.title;
return {
type: 'error',
error: {
apiName,
statusCode: statusCode,
statusText,
detail,
},
};
}
exports.generateErrorWithDetail = generateErrorWithDetail;
//# sourceMappingURL=httpUtils.js.map

@@ -94,3 +94,3 @@ {

},
"version": "4.22.5"
"version": "4.23.0"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc