@snyk/code-client
Advanced tools
Comparing version 4.13.0 to 4.14.0
@@ -22,3 +22,3 @@ "use strict"; | ||
const apiParams = { | ||
...(0, lodash_pick_1.default)(options, ['baseURL', 'sessionToken', 'source', 'removedFiles', 'requestId', 'base64Encoding', 'org']), | ||
...(0, lodash_pick_1.default)(options, ['baseURL', 'sessionToken', 'source', 'removedFiles', 'requestId', 'org']), | ||
files: chunkedFiles.reduce((d, f) => { | ||
@@ -58,11 +58,3 @@ // deepcode ignore PrototypePollution: FP this is an internal code | ||
emitter_1.emitter.uploadBundleProgress(0, options.files.length); | ||
const apiParams = (0, lodash_pick_1.default)(options, [ | ||
'baseURL', | ||
'sessionToken', | ||
'source', | ||
'bundleHash', | ||
'requestId', | ||
'base64Encoding', | ||
'org', | ||
]); | ||
const apiParams = (0, lodash_pick_1.default)(options, ['baseURL', 'sessionToken', 'source', 'bundleHash', 'requestId', 'org']); | ||
const uploadFileChunks = async (bucketFiles) => { | ||
@@ -96,3 +88,3 @@ // Note: we specifically create __new__ isolated bundles here to faster files upload | ||
let { remoteBundle } = options; | ||
const connectionOptions = (0, lodash_pick_1.default)(options, ['baseURL', 'sessionToken', 'source', 'requestId', 'base64Encoding', 'org']); | ||
const connectionOptions = (0, lodash_pick_1.default)(options, ['baseURL', 'sessionToken', 'source', 'requestId', 'org']); | ||
while (remoteBundle.missingFiles.length && attempts < (options.maxAttempts || constants_1.MAX_UPLOAD_ATTEMPTS)) { | ||
@@ -117,11 +109,3 @@ const missingFiles = await (0, files_1.resolveBundleFiles)(options.baseDir, remoteBundle.missingFiles); | ||
let remoteBundle = null; | ||
const baseOptions = (0, lodash_pick_1.default)(options, [ | ||
'baseURL', | ||
'sessionToken', | ||
'source', | ||
'baseDir', | ||
'requestId', | ||
'base64Encoding', | ||
'org', | ||
]); | ||
const baseOptions = (0, lodash_pick_1.default)(options, ['baseURL', 'sessionToken', 'source', 'baseDir', 'requestId', 'org']); | ||
const bundleFactory = prepareRemoteBundle((0, lodash_omit_1.default)(options, ['baseDir'])); | ||
@@ -198,3 +182,3 @@ for await (const response of bundleFactory) { | ||
const bundleOptions = { | ||
...(0, lodash_pick_1.default)(options, ['baseURL', 'sessionToken', 'source', 'requestId', 'base64Encoding']), | ||
...(0, lodash_pick_1.default)(options, ['baseURL', 'sessionToken', 'source', 'requestId']), | ||
baseDir, | ||
@@ -201,0 +185,0 @@ files: bundleFiles, |
@@ -46,2 +46,2 @@ export declare const MAX_PAYLOAD: number; | ||
}; | ||
export declare type GenericErrorTypes = ErrorCodes.serverError | ErrorCodes.badGateway | ErrorCodes.serviceUnavailable | ErrorCodes.timeout | ErrorCodes.connectionRefused | ErrorCodes.dnsNotFound; | ||
export type GenericErrorTypes = ErrorCodes.serverError | ErrorCodes.badGateway | ErrorCodes.serviceUnavailable | ErrorCodes.timeout | ErrorCodes.connectionRefused | ErrorCodes.dnsNotFound; |
@@ -6,7 +6,7 @@ /// <reference types="node" /> | ||
import { AnalysisOptions, AnalysisContext } from './interfaces/analysis-options.interface'; | ||
declare type ResultSuccess<T> = { | ||
type ResultSuccess<T> = { | ||
type: 'success'; | ||
value: T; | ||
}; | ||
declare type ResultError<E> = { | ||
type ResultError<E> = { | ||
type: 'error'; | ||
@@ -19,3 +19,3 @@ error: { | ||
}; | ||
export declare type Result<T, E> = ResultSuccess<T> | ResultError<E>; | ||
export type Result<T, E> = ResultSuccess<T> | ResultError<E>; | ||
export interface ConnectionOptions { | ||
@@ -26,6 +26,5 @@ baseURL: string; | ||
requestId?: string; | ||
base64Encoding: boolean; | ||
org?: string; | ||
} | ||
declare type StartSessionResponseDto = { | ||
type StartSessionResponseDto = { | ||
readonly draftToken: string; | ||
@@ -38,6 +37,5 @@ readonly loginURL: string; | ||
} | ||
export declare function setBase64Encoding(options: ConnectionOptions): boolean; | ||
export declare function compressAndEncode(payload: any): Promise<Buffer>; | ||
export declare function compressAndEncode(payload: unknown): Promise<Buffer>; | ||
export declare function startSession(options: StartSessionOptions): StartSessionResponseDto; | ||
export declare type IpFamily = 6 | undefined; | ||
export type IpFamily = 6 | undefined; | ||
/** | ||
@@ -49,3 +47,3 @@ * Dispatches a FORCED IPv6 request to test client's ISP and network capability. | ||
export declare function getIpFamily(authHost: string): Promise<IpFamily>; | ||
declare type CheckSessionErrorCodes = GenericErrorTypes | ErrorCodes.unauthorizedUser | ErrorCodes.loginInProgress; | ||
type CheckSessionErrorCodes = GenericErrorTypes | ErrorCodes.unauthorizedUser | ErrorCodes.loginInProgress; | ||
interface CheckSessionOptions { | ||
@@ -58,7 +56,7 @@ readonly authHost: string; | ||
export declare function getFilters(baseURL: string, source: string, attempts?: number, requestId?: string): Promise<Result<SupportedFiles, GenericErrorTypes>>; | ||
export declare type RemoteBundle = { | ||
export type RemoteBundle = { | ||
readonly bundleHash: string; | ||
readonly missingFiles: string[]; | ||
}; | ||
export declare type CreateBundleErrorCodes = GenericErrorTypes | ErrorCodes.unauthorizedUser | ErrorCodes.unauthorizedBundleAccess | ErrorCodes.bigPayload | ErrorCodes.badRequest | ErrorCodes.notFound; | ||
export type CreateBundleErrorCodes = GenericErrorTypes | ErrorCodes.unauthorizedUser | ErrorCodes.unauthorizedBundleAccess | ErrorCodes.bigPayload | ErrorCodes.badRequest | ErrorCodes.notFound; | ||
interface CreateBundleOptions extends ConnectionOptions { | ||
@@ -68,3 +66,3 @@ files: BundleFiles; | ||
export declare function createBundle(options: CreateBundleOptions): Promise<Result<RemoteBundle, CreateBundleErrorCodes>>; | ||
export declare type CheckBundleErrorCodes = GenericErrorTypes | ErrorCodes.unauthorizedUser | ErrorCodes.unauthorizedBundleAccess | ErrorCodes.notFound; | ||
export type CheckBundleErrorCodes = GenericErrorTypes | ErrorCodes.unauthorizedUser | ErrorCodes.unauthorizedBundleAccess | ErrorCodes.notFound; | ||
interface CheckBundleOptions extends ConnectionOptions { | ||
@@ -74,3 +72,3 @@ bundleHash: string; | ||
export declare function checkBundle(options: CheckBundleOptions): Promise<Result<RemoteBundle, CheckBundleErrorCodes>>; | ||
export declare type ExtendBundleErrorCodes = GenericErrorTypes | ErrorCodes.unauthorizedUser | ErrorCodes.badRequest | ErrorCodes.unauthorizedBundleAccess | ErrorCodes.bigPayload | ErrorCodes.notFound; | ||
export type ExtendBundleErrorCodes = GenericErrorTypes | ErrorCodes.unauthorizedUser | ErrorCodes.badRequest | ErrorCodes.unauthorizedBundleAccess | ErrorCodes.bigPayload | ErrorCodes.notFound; | ||
interface ExtendBundleOptions extends ConnectionOptions { | ||
@@ -90,11 +88,11 @@ readonly bundleHash: string; | ||
} | ||
export declare type AnalysisResponseProgress = { | ||
export type AnalysisResponseProgress = { | ||
readonly status: AnalysisStatus.waiting | AnalysisStatus.fetching | AnalysisStatus.analyzing | AnalysisStatus.done; | ||
readonly progress: number; | ||
}; | ||
export declare type AnalysisFailedResponse = { | ||
export type AnalysisFailedResponse = { | ||
readonly status: AnalysisStatus.failed; | ||
}; | ||
export declare type GetAnalysisResponseDto = AnalysisResult | AnalysisFailedResponse | AnalysisResponseProgress; | ||
export declare type GetAnalysisErrorCodes = GenericErrorTypes | ErrorCodes.unauthorizedUser | ErrorCodes.unauthorizedBundleAccess | ErrorCodes.badRequest | ErrorCodes.notFound; | ||
export type GetAnalysisResponseDto = AnalysisResult | AnalysisFailedResponse | AnalysisResponseProgress; | ||
export type GetAnalysisErrorCodes = GenericErrorTypes | ErrorCodes.unauthorizedUser | ErrorCodes.unauthorizedBundleAccess | ErrorCodes.badRequest | ErrorCodes.notFound; | ||
export interface GetAnalysisOptions extends ConnectionOptions, AnalysisOptions, AnalysisContext { | ||
@@ -101,0 +99,0 @@ bundleHash: string; |
@@ -6,3 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getVerifyCallbackUrl = exports.getAnalysis = exports.AnalysisStatus = exports.extendBundle = exports.checkBundle = exports.createBundle = exports.getFilters = exports.checkSession = exports.getIpFamily = exports.startSession = exports.compressAndEncode = exports.setBase64Encoding = void 0; | ||
exports.getVerifyCallbackUrl = exports.getAnalysis = exports.AnalysisStatus = exports.extendBundle = exports.checkBundle = exports.createBundle = exports.getFilters = exports.checkSession = exports.getIpFamily = exports.startSession = exports.compressAndEncode = void 0; | ||
const uuid_1 = require("uuid"); | ||
@@ -14,3 +14,2 @@ const lodash_pick_1 = __importDefault(require("lodash.pick")); | ||
const needle_1 = require("./needle"); | ||
const url_1 = require("url"); | ||
// The trick to typecast union type alias | ||
@@ -46,18 +45,2 @@ function isSubsetErrorCode(code, messages) { | ||
}; | ||
function setBase64Encoding(options) { | ||
if (!options.base64Encoding) { | ||
const { hostname } = new url_1.URL(options.baseURL); | ||
const rg = new RegExp('^(|dev.)snyk.io'); | ||
if (rg.test(hostname.slice(hostname.indexOf('.') + 1))) { | ||
return options.base64Encoding; | ||
} | ||
else { | ||
return true; | ||
} | ||
} | ||
else { | ||
return options.base64Encoding; | ||
} | ||
} | ||
exports.setBase64Encoding = setBase64Encoding; | ||
async function compressAndEncode(payload) { | ||
@@ -152,10 +135,3 @@ // encode payload and compress; | ||
async function createBundle(options) { | ||
const base64Encoding = setBase64Encoding(options); | ||
let payloadBody; | ||
if (base64Encoding) { | ||
payloadBody = await compressAndEncode(options.files); | ||
} | ||
else { | ||
payloadBody = options.files; | ||
} | ||
const payloadBody = await compressAndEncode(options.files); | ||
const payload = { | ||
@@ -166,3 +142,3 @@ headers: { | ||
...(options.requestId && { 'snyk-request-id': options.requestId }), | ||
...(base64Encoding ? { 'content-type': 'application/octet-stream', 'content-encoding': 'gzip' } : null), | ||
...{ 'content-type': 'application/octet-stream', 'content-encoding': 'gzip' }, | ||
...(options.org && { 'snyk-org-name': options.org }), | ||
@@ -173,3 +149,3 @@ }, | ||
body: payloadBody, | ||
isJson: base64Encoding ? false : true, | ||
isJson: false, | ||
}; | ||
@@ -214,10 +190,3 @@ const res = await (0, needle_1.makeRequest)(payload); | ||
async function extendBundle(options) { | ||
const base64Encoding = setBase64Encoding(options); | ||
let payloadBody; | ||
if (base64Encoding) { | ||
payloadBody = await compressAndEncode((0, lodash_pick_1.default)(options, ['files', 'removedFiles'])); | ||
} | ||
else { | ||
payloadBody = (0, lodash_pick_1.default)(options, ['files', 'removedFiles']); | ||
} | ||
const payloadBody = await compressAndEncode((0, lodash_pick_1.default)(options, ['files', 'removedFiles'])); | ||
const res = await (0, needle_1.makeRequest)({ | ||
@@ -228,3 +197,3 @@ headers: { | ||
...(options.requestId && { 'snyk-request-id': options.requestId }), | ||
...(base64Encoding ? { 'content-type': 'application/octet-stream', 'content-encoding': 'gzip' } : null), | ||
...{ 'content-type': 'application/octet-stream', 'content-encoding': 'gzip' }, | ||
...(options.org && { 'snyk-org-name': options.org }), | ||
@@ -235,3 +204,3 @@ }, | ||
body: payloadBody, | ||
isJson: base64Encoding ? false : true, | ||
isJson: false, | ||
}); | ||
@@ -238,0 +207,0 @@ if (res.success) |
@@ -28,3 +28,3 @@ import { Log } from 'sarif'; | ||
} | ||
export declare type Point = [number, number]; | ||
export type Point = [number, number]; | ||
export interface Marker { | ||
@@ -75,3 +75,3 @@ msg: Point; | ||
} | ||
export declare type AnalysisResult = AnalysisResultSarif | AnalysisResultLegacy; | ||
export type AnalysisResult = AnalysisResultSarif | AnalysisResultLegacy; | ||
export {}; |
@@ -8,3 +8,3 @@ import { AnalysisResult } from '..'; | ||
} | ||
export declare type BundleFiles = { | ||
export type BundleFiles = { | ||
[filePath: string]: string | File; | ||
@@ -19,3 +19,3 @@ }; | ||
} | ||
export declare type SupportedFiles = { | ||
export type SupportedFiles = { | ||
configFiles: string[]; | ||
@@ -22,0 +22,0 @@ extensions: string[]; |
@@ -26,3 +26,3 @@ /// <reference types="node" /> | ||
} | ||
export declare type FailedResponse = { | ||
export type FailedResponse = { | ||
success: false; | ||
@@ -29,0 +29,0 @@ errorCode: number; |
@@ -86,3 +86,3 @@ { | ||
}, | ||
"version": "4.13.0" | ||
"version": "4.14.0" | ||
} |
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
136970
1893