@snyk/code-client
Advanced tools
Comparing version 3.9.0 to 3.10.0
@@ -6,6 +6,5 @@ import { RemoteBundle } from './http'; | ||
import { ISupportedFiles } from './interfaces/files.interface'; | ||
export declare function analyzeBundle({ baseURL, sessionToken, includeLint, severity, bundleId, oAuthToken, username, limitToFiles, source, reachability, }: { | ||
export declare function analyzeBundle({ baseURL, sessionToken, severity, bundleId, oAuthToken, username, limitToFiles, source, reachability, }: { | ||
baseURL: string; | ||
sessionToken: string; | ||
includeLint: boolean; | ||
severity: AnalysisSeverity; | ||
@@ -12,0 +11,0 @@ bundleId: string; |
@@ -21,3 +21,2 @@ "use strict"; | ||
sessionToken: '', | ||
includeLint: false, | ||
reachability: false, | ||
@@ -31,3 +30,3 @@ severity: analysis_result_interface_1.AnalysisSeverity.info, | ||
}; | ||
async function pollAnalysis({ baseURL, sessionToken, includeLint, severity, bundleId, oAuthToken, username, limitToFiles, source, reachability, }, requestOptions) { | ||
async function pollAnalysis({ baseURL, sessionToken, severity, bundleId, oAuthToken, username, limitToFiles, source, reachability, }, requestOptions) { | ||
let analysisResponse; | ||
@@ -48,3 +47,2 @@ let analysisData; | ||
bundleId, | ||
includeLint, | ||
severity, | ||
@@ -78,3 +76,3 @@ limitToFiles, | ||
} | ||
async function analyzeBundle({ baseURL = constants_1.defaultBaseURL, sessionToken = '', includeLint = false, severity = analysis_result_interface_1.AnalysisSeverity.info, bundleId, oAuthToken, username, limitToFiles, source, reachability = false, }, requestOptions) { | ||
async function analyzeBundle({ baseURL = constants_1.defaultBaseURL, sessionToken = '', severity = analysis_result_interface_1.AnalysisSeverity.info, bundleId, oAuthToken, username, limitToFiles, source, reachability = false, }, requestOptions) { | ||
// Call remote bundle for analysis results and emit intermediate progress | ||
@@ -87,3 +85,2 @@ const analysisData = await pollAnalysis({ | ||
bundleId, | ||
includeLint, | ||
severity, | ||
@@ -105,3 +102,2 @@ limitToFiles, | ||
analysisResults, | ||
analysisURL: analysisData.value.analysisURL, | ||
}; | ||
@@ -151,3 +147,3 @@ } | ||
const analysisOptions = { ...ANALYSIS_OPTIONS_DEFAULTS, ...options }; | ||
const { baseURL, sessionToken, includeLint, reachability, severity, paths, symlinksEnabled, sarif, defaultFileIgnores, source, } = analysisOptions; | ||
const { baseURL, sessionToken, reachability, severity, paths, symlinksEnabled, sarif, defaultFileIgnores, source, } = analysisOptions; | ||
const supportedFiles = await getSupportedFiles(baseURL, source); | ||
@@ -173,3 +169,2 @@ // Scan directories and find all suitable files | ||
}, | ||
analysisURL: '', | ||
bundleId: '', | ||
@@ -182,3 +177,2 @@ }; | ||
sessionToken, | ||
includeLint, | ||
reachability, | ||
@@ -194,3 +188,2 @@ severity, | ||
sessionToken, | ||
includeLint, | ||
reachability, | ||
@@ -226,3 +219,2 @@ severity, | ||
sessionToken: bundle.sessionToken, | ||
includeLint: bundle.includeLint, | ||
severity: bundle.severity, | ||
@@ -241,3 +233,3 @@ bundleId: remoteBundle.bundleId, | ||
const analysisOptions = { ...ANALYSIS_OPTIONS_DEFAULTS, ...options }; | ||
const { baseURL, sessionToken, oAuthToken, username, includeLint, reachability, severity, gitUri, sarif, source } = analysisOptions; | ||
const { baseURL, sessionToken, oAuthToken, username, reachability, severity, gitUri, sarif, source } = analysisOptions; | ||
const bundleResponse = await http_1.createGitBundle({ | ||
@@ -260,3 +252,2 @@ baseURL, | ||
username, | ||
includeLint, | ||
reachability, | ||
@@ -271,3 +262,2 @@ severity, | ||
oAuthToken, | ||
includeLint, | ||
reachability, | ||
@@ -274,0 +264,0 @@ severity, |
@@ -1,5 +0,4 @@ | ||
import { AxiosError } from 'axios'; | ||
import { ErrorCodes, GenericErrorTypes } from './constants'; | ||
import { IFiles, IFileContent, ISupportedFiles } from './interfaces/files.interface'; | ||
import { IAnalysisResult } from './interfaces/analysis-result.interface'; | ||
import { IFileContent, IFiles, ISupportedFiles } from './interfaces/files.interface'; | ||
import { RequestOptions } from './interfaces/http-options.interface'; | ||
@@ -19,3 +18,3 @@ declare type ResultSuccess<T> = { | ||
export declare type IResult<T, E> = ResultSuccess<T> | ResultError<E>; | ||
export declare function determineErrorCode(error: AxiosError | any): ErrorCodes; | ||
export declare function determineErrorCode(error: any): ErrorCodes; | ||
declare type StartSessionResponseDto = { | ||
@@ -29,2 +28,9 @@ readonly draftToken: string; | ||
}): StartSessionResponseDto; | ||
export declare type IpFamily = 6 | undefined; | ||
/** | ||
* Dispatches a FORCED IPv6 request to test client's ISP and network capability. | ||
* | ||
* @return {number} IP family number used by the client. | ||
*/ | ||
export declare function getIpFamily(authHost: string): Promise<IpFamily>; | ||
declare type CheckSessionErrorCodes = GenericErrorTypes | ErrorCodes.unauthorizedUser | ErrorCodes.loginInProgress; | ||
@@ -34,2 +40,3 @@ export declare function checkSession(options: { | ||
readonly draftToken: string; | ||
readonly ipFamily?: IpFamily; | ||
}): Promise<IResult<string, CheckSessionErrorCodes>>; | ||
@@ -40,3 +47,2 @@ export declare function getFilters(baseURL: string, source: string): Promise<IResult<ISupportedFiles, GenericErrorTypes>>; | ||
readonly missingFiles: string[]; | ||
readonly uploadURL?: string; | ||
}; | ||
@@ -97,3 +103,2 @@ export declare type CreateBundleErrorCodes = GenericErrorTypes | ErrorCodes.unauthorizedUser | ErrorCodes.unauthorizedBundleAccess | ErrorCodes.bigPayload | ErrorCodes.unauthorizedContent | ErrorCodes.notFound; | ||
readonly status: AnalysisStatus.done; | ||
readonly analysisURL: string; | ||
readonly analysisResults: IAnalysisResult; | ||
@@ -107,3 +112,2 @@ }; | ||
readonly bundleId: string; | ||
readonly includeLint?: boolean; | ||
readonly severity: number; | ||
@@ -110,0 +114,0 @@ readonly limitToFiles?: string[]; |
207
dist/http.js
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.reportEvent = exports.reportError = exports.getAnalysis = exports.AnalysisStatus = exports.uploadFiles = exports.createGitBundle = exports.extendBundle = exports.checkBundle = exports.createBundle = exports.getFilters = exports.checkSession = exports.startSession = exports.determineErrorCode = void 0; | ||
exports.reportEvent = exports.reportError = exports.getAnalysis = exports.AnalysisStatus = exports.uploadFiles = exports.createGitBundle = exports.extendBundle = exports.checkBundle = exports.createBundle = exports.getFilters = exports.checkSession = exports.getIpFamily = exports.startSession = exports.determineErrorCode = void 0; | ||
const uuid_1 = require("uuid"); | ||
const constants_1 = require("./constants"); | ||
const axios_1 = __importDefault(require("./axios")); | ||
const needle_1 = require("./needle"); | ||
function determineErrorCode(error) { | ||
@@ -14,3 +11,3 @@ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment | ||
if (response) { | ||
return response.status; | ||
return response.statusCode; | ||
} | ||
@@ -74,2 +71,23 @@ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment | ||
exports.startSession = startSession; | ||
/** | ||
* Dispatches a FORCED IPv6 request to test client's ISP and network capability. | ||
* | ||
* @return {number} IP family number used by the client. | ||
*/ | ||
async function getIpFamily(authHost) { | ||
const family = 6; | ||
try { | ||
// Dispatch a FORCED IPv6 request to test client's ISP and network capability | ||
await needle_1.makeRequest({ | ||
url: `${authHost}/verify/callback`, | ||
method: 'post', | ||
family, // family param forces the handler to dispatch a request using IP at "family" version | ||
}); | ||
return family; | ||
} | ||
catch (e) { | ||
return undefined; | ||
} | ||
} | ||
exports.getIpFamily = getIpFamily; | ||
const CHECK_SESSION_ERROR_MESSAGES = { | ||
@@ -82,17 +100,20 @@ ...GENERIC_ERROR_MESSAGES, | ||
var _a; | ||
const { draftToken, authHost } = options; | ||
const config = { | ||
url: `${authHost}/api/v1/verify/callback`, | ||
method: 'POST', | ||
data: { | ||
token: draftToken, | ||
}, | ||
const defaultValue = { | ||
type: 'success', | ||
value: '', | ||
}; | ||
try { | ||
const response = await axios_1.default.request(config); | ||
return { | ||
type: 'success', | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access | ||
value: (response.status === 200 && response.data.ok && response.data.api) || '', | ||
}; | ||
const { success, response } = await needle_1.makeRequest({ | ||
url: `${options.authHost}/api/v1/verify/callback`, | ||
body: { | ||
token: options.draftToken, | ||
}, | ||
family: options.ipFamily, | ||
method: 'post', | ||
}); | ||
if (success) { | ||
const responseBody = response.body; | ||
defaultValue.value = (responseBody.ok && responseBody.api) || ''; | ||
} | ||
return defaultValue; | ||
} | ||
@@ -103,3 +124,3 @@ catch (err) { | ||
(_a = err.response) === null || _a === void 0 ? void 0 : _a.status)) { | ||
return { type: 'success', value: '' }; | ||
return defaultValue; | ||
} | ||
@@ -112,10 +133,13 @@ return generateError(err, CHECK_SESSION_ERROR_MESSAGES, 'checkSession'); | ||
const apiName = 'filters'; | ||
const config = { | ||
headers: { source }, | ||
url: `${baseURL}${constants_1.apiPath}/${apiName}`, | ||
method: 'GET', | ||
}; | ||
try { | ||
const response = await axios_1.default.request(config); | ||
return { type: 'success', value: response.data }; | ||
const { success, response } = await needle_1.makeRequest({ | ||
headers: { source }, | ||
url: `${baseURL}${constants_1.apiPath}/${apiName}`, | ||
method: 'get', | ||
}); | ||
if (success) { | ||
const responseBody = response.body; | ||
return { type: 'success', value: responseBody }; | ||
} | ||
return generateError({ response }, GENERIC_ERROR_MESSAGES, apiName); | ||
} | ||
@@ -137,13 +161,16 @@ catch (error) { | ||
const { baseURL, sessionToken, files, source } = options; | ||
const config = { | ||
headers: { 'Session-Token': sessionToken, source }, | ||
url: `${baseURL}${constants_1.apiPath}/bundle`, | ||
method: 'POST', | ||
data: { | ||
files, | ||
}, | ||
}; | ||
try { | ||
const response = await axios_1.default.request(config); | ||
return { type: 'success', value: response.data }; | ||
const payload = { | ||
headers: { 'Session-Token': sessionToken, source }, | ||
url: `${baseURL}${constants_1.apiPath}/bundle`, | ||
method: 'post', | ||
body: { | ||
files, | ||
}, | ||
}; | ||
const { response, success } = await needle_1.makeRequest(payload); | ||
if (success) { | ||
return { type: 'success', value: response.body }; | ||
} | ||
return generateError({ response }, CREATE_BUNDLE_ERROR_MESSAGES, 'createBundle'); | ||
} | ||
@@ -163,10 +190,11 @@ catch (error) { | ||
const { baseURL, sessionToken, bundleId } = options; | ||
const config = { | ||
headers: { 'Session-Token': sessionToken }, | ||
url: `${baseURL}${constants_1.apiPath}/bundle/${bundleId}`, | ||
method: 'GET', | ||
}; | ||
try { | ||
const response = await axios_1.default.request(config); | ||
return { type: 'success', value: response.data }; | ||
const { response, success } = await needle_1.makeRequest({ | ||
headers: { 'Session-Token': sessionToken }, | ||
url: `${baseURL}${constants_1.apiPath}/bundle/${bundleId}`, | ||
method: 'get', | ||
}); | ||
if (success) | ||
return { type: 'success', value: response.body }; | ||
return generateError({ response }, CHECK_BUNDLE_ERROR_MESSAGES, 'checkBundle'); | ||
} | ||
@@ -188,14 +216,15 @@ catch (error) { | ||
const { baseURL, sessionToken, bundleId, files, removedFiles = [] } = options; | ||
const config = { | ||
headers: { 'Session-Token': sessionToken }, | ||
url: `${baseURL}${constants_1.apiPath}/bundle/${bundleId}`, | ||
method: 'PUT', | ||
data: { | ||
files, | ||
removedFiles, | ||
}, | ||
}; | ||
try { | ||
const response = await axios_1.default.request(config); | ||
return { type: 'success', value: response.data }; | ||
const { response, success } = await needle_1.makeRequest({ | ||
headers: { 'Session-Token': sessionToken }, | ||
url: `${baseURL}${constants_1.apiPath}/bundle/${bundleId}`, | ||
method: 'put', | ||
body: { | ||
files, | ||
removedFiles, | ||
}, | ||
}); | ||
if (success) | ||
return { type: 'success', value: response.body }; | ||
return generateError({ response }, EXTEND_BUNDLE_ERROR_MESSAGES, 'extendBundle'); | ||
} | ||
@@ -222,11 +251,12 @@ catch (error) { | ||
} | ||
const config = { | ||
headers, | ||
url: `${baseURL}${constants_1.apiPath}/bundle`, | ||
method: 'POST', | ||
data: { gitURI: gitUri }, | ||
}; | ||
try { | ||
const response = await axios_1.default.request(config); | ||
return { type: 'success', value: response.data }; | ||
const { response, success } = await needle_1.makeRequest({ | ||
headers, | ||
url: `${baseURL}${constants_1.apiPath}/bundle`, | ||
method: 'post', | ||
body: { gitURI: gitUri }, | ||
}); | ||
if (success) | ||
return { type: 'success', value: response.body }; | ||
return generateError({ response }, CREATE_GIT_BUNDLE_ERROR_MESSAGES, 'createBundle'); | ||
} | ||
@@ -248,11 +278,12 @@ catch (error) { | ||
const { baseURL, sessionToken, bundleId, content } = options; | ||
const config = { | ||
headers: { 'Session-Token': sessionToken }, | ||
url: `${baseURL}${constants_1.apiPath}/file/${bundleId}`, | ||
method: 'POST', | ||
data: content, | ||
}; | ||
try { | ||
await axios_1.default.request(config); | ||
return { type: 'success', value: true }; | ||
const { response, success } = await needle_1.makeRequest({ | ||
headers: { 'Session-Token': sessionToken }, | ||
url: `${baseURL}${constants_1.apiPath}/file/${bundleId}`, | ||
method: 'post', | ||
body: content, | ||
}); | ||
if (success) | ||
return { type: 'success', value: true }; | ||
return generateError({ response }, UPLOAD_BUNDLE_ERROR_MESSAGES, 'uploadFiles'); | ||
} | ||
@@ -282,6 +313,8 @@ catch (error) { | ||
async function getAnalysis(options, requestOptions) { | ||
const { baseURL, sessionToken, oAuthToken, username, bundleId, includeLint, severity, limitToFiles, source, reachability, } = options; | ||
// ?linters=false is still a truthy query value, if(includeLint === false) we have to avoid sending the value altogether | ||
const { baseURL, sessionToken, oAuthToken, username, bundleId, severity, limitToFiles, source, reachability } = options; | ||
// the same applies for reachability | ||
const params = { severity, linters: includeLint || undefined, reachability: reachability || undefined }; | ||
const params = { severity }; | ||
if (reachability) { | ||
params.reachability = true; | ||
} | ||
const headers = { ...requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.headers, 'Session-Token': sessionToken, source }; | ||
@@ -296,13 +329,15 @@ if (oAuthToken) { | ||
headers, | ||
params, | ||
qs: params, | ||
url: `${baseURL}${constants_1.apiPath}/analysis/${bundleId}`, | ||
method: 'GET', | ||
method: 'get', | ||
}; | ||
if (limitToFiles && limitToFiles.length) { | ||
config.data = { files: limitToFiles }; | ||
config.method = 'POST'; | ||
config.body = { files: limitToFiles }; | ||
config.method = 'post'; | ||
} | ||
try { | ||
const response = await axios_1.default.request(config); | ||
return { type: 'success', value: response.data }; | ||
const { response, success } = await needle_1.makeRequest(config); | ||
if (success) | ||
return { type: 'success', value: response.body }; | ||
return generateError({ response }, GET_ANALYSIS_ERROR_MESSAGES, 'getAnalysis'); | ||
} | ||
@@ -318,4 +353,4 @@ catch (error) { | ||
url: `${baseURL}${constants_1.apiPath}/error`, | ||
method: 'POST', | ||
data: { | ||
method: 'post', | ||
body: { | ||
sessionToken, | ||
@@ -333,3 +368,3 @@ source, | ||
try { | ||
await axios_1.default.request(config); | ||
await needle_1.makeRequest(config); | ||
return { type: 'success', value: undefined }; | ||
@@ -346,4 +381,4 @@ } | ||
url: `${baseURL}${constants_1.apiPath}/track`, | ||
method: 'POST', | ||
data: { | ||
method: 'post', | ||
body: { | ||
sessionToken, | ||
@@ -361,3 +396,3 @@ source, | ||
try { | ||
await axios_1.default.request(config); | ||
await needle_1.makeRequest(config); | ||
return { type: 'success', value: undefined }; | ||
@@ -364,0 +399,0 @@ } |
@@ -5,3 +5,2 @@ import { AnalysisSeverity } from './analysis-result.interface'; | ||
sessionToken: string; | ||
includeLint: boolean; | ||
reachability: boolean; | ||
@@ -26,3 +25,2 @@ severity: AnalysisSeverity; | ||
sessionToken: string; | ||
includeLint?: boolean; | ||
reachability?: boolean; | ||
@@ -29,0 +27,0 @@ severity?: AnalysisSeverity; |
@@ -83,3 +83,2 @@ import { Log } from 'sarif'; | ||
readonly oAuthToken?: string; | ||
readonly includeLint: boolean; | ||
readonly severity: AnalysisSeverity; | ||
@@ -91,3 +90,2 @@ } | ||
readonly sarifResults?: Log; | ||
readonly analysisURL: string; | ||
} | ||
@@ -94,0 +92,0 @@ interface IBundleBase extends IBundleArgs, IBundleResult { |
@@ -15,3 +15,2 @@ // import { IAnalysisResult } from './analysis-result.interface'; | ||
// bundleId: string; | ||
// useLinter?: boolean; | ||
// } | ||
@@ -21,4 +20,3 @@ // export interface IQueueAnalysisCheckResult { | ||
// progress: number; | ||
// analysisURL: string; | ||
// } | ||
//# sourceMappingURL=queue.interface.js.map |
@@ -16,3 +16,3 @@ { | ||
"watch": "tsc -watch -p ./", | ||
"test": "jest --coverage --runInBand --detectOpenHandles" | ||
"test": "jest --verbose --coverage --runInBand --detectOpenHandles" | ||
}, | ||
@@ -43,2 +43,3 @@ "repository": { | ||
"@typescript-eslint/parser": "^4.0.1", | ||
"@types/needle": "^2.5.2", | ||
"eslint": "^7.8.1", | ||
@@ -66,3 +67,2 @@ "eslint-config-airbnb-base": "^14.2.0", | ||
"@types/uuid": "^8.3.0", | ||
"axios": "^0.21.1", | ||
"ignore": "^5.1.8", | ||
@@ -73,6 +73,7 @@ "lodash.chunk": "^4.2.0", | ||
"multimatch": "^5.0.0", | ||
"needle": "^2.8.0", | ||
"queue": "^6.0.1", | ||
"uuid": "^8.3.2" | ||
}, | ||
"version": "3.9.0" | ||
"version": "3.10.0" | ||
} |
@@ -92,3 +92,2 @@ # code-client | ||
sessionToken, | ||
includeLint: false, | ||
severity: 1, | ||
@@ -103,7 +102,5 @@ paths: ['/home/user/repo'], | ||
// readonly sessionToken: string; | ||
// readonly includeLint: boolean; | ||
// readonly severity: AnalysisSeverity; | ||
// readonly bundleId: string; | ||
// readonly analysisResults: IAnalysisResult; | ||
// readonly analysisURL: string; | ||
// readonly baseDir: string; | ||
@@ -126,3 +123,3 @@ // readonly paths: string[]; | ||
}); | ||
const { bundleId, missingFiles, uploadURL } = result; | ||
const { bundleId, missingFiles } = result; | ||
``` | ||
@@ -136,3 +133,2 @@ | ||
sessionToken, | ||
includeLint: false, | ||
severity: 1, | ||
@@ -148,7 +144,5 @@ gitUri: 'git@github.com:DeepCodeAI/cli.git@320d98a6896f5376efe6cefefb6e70b46b97d566', | ||
// readonly oAuthToken?: string; | ||
// readonly includeLint: boolean; | ||
// readonly severity: AnalysisSeverity; | ||
// readonly bundleId: string; | ||
// readonly analysisResults: IAnalysisResult; | ||
// readonly analysisURL: string; | ||
// readonly sarifResults?: Log; | ||
@@ -155,0 +149,0 @@ // readonly gitUri: string; |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
152667
2244
18
51
154
+ Addedneedle@^2.8.0
+ Addeddebug@3.2.7(transitive)
+ Addediconv-lite@0.4.24(transitive)
+ Addedms@2.1.3(transitive)
+ Addedneedle@2.9.1(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedsax@1.4.1(transitive)
- Removedaxios@^0.21.1
- Removedaxios@0.21.4(transitive)
- Removedfollow-redirects@1.15.9(transitive)