Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@soos-io/api-client

Package Overview
Dependencies
Maintainers
1
Versions
207
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@soos-io/api-client - npm Package Compare versions

Comparing version 0.2.49-pre.2 to 0.2.49-pre.3

testassets/elasticsearch-grok-8.9.1.jar

23

dist/api/SOOSAnalysisApiClient.d.ts
import FormData from "form-data";
import { IntegrationName, IntegrationType, ManifestStatus, OutputFormat, PackageManagerType, ScanStatus, ScanType } from "../enums";
import { HashAlgorithmEnum, HashEncodingEnum, IntegrationName, IntegrationType, ManifestStatus, OutputFormat, PackageManagerType, ScanStatus, ScanType } from "../enums";
import { ICodedMessageModel } from "../models";

@@ -38,13 +38,22 @@ interface ICreateScanRequestContributingDeveloperAudit {

}
interface IGetSupportedManifestsRequest {
interface IGetSupportedScanFileFormatsRequest {
clientId: string;
}
interface IGetSupportedManifestsResponsePackageManagerManifestPatterns {
interface IGetSupportedScanFileFormatsResponsePackageManagerManifestAndHashableFiles {
packageManager: PackageManagerType;
manifests: Array<{
supportedManifests: Array<{
pattern: string;
isLockFile: boolean;
}>;
hashableFiles: Array<{
hashAlgorithms: Array<{
hashAlgorithm: HashAlgorithmEnum;
bufferEncoding: HashEncodingEnum;
digestEncoding: HashEncodingEnum;
}>;
archiveFileExtensions: Array<string> | null;
archiveContentFileExtensions: Array<string> | null;
}> | null;
}
type IGetSupportedManifestsResponse = Array<IGetSupportedManifestsResponsePackageManagerManifestPatterns>;
type IGetSupportedScanFileFormatsResponse = Array<IGetSupportedScanFileFormatsResponsePackageManagerManifestAndHashableFiles>;
interface IScanStatusRequest {

@@ -158,3 +167,3 @@ scanStatusUrl: string;

createScan({ clientId, projectName, commitHash, branch, buildVersion, buildUri, branchUri, integrationType, operatingEnvironment, integrationName, scanType, appVersion, scriptVersion, contributingDeveloperAudit, toolName, toolVersion, }: ICreateScanRequest): Promise<ICreateScanResponse>;
getSupportedManifests({ clientId, }: IGetSupportedManifestsRequest): Promise<IGetSupportedManifestsResponse>;
getSupportedScanFileFormats({ clientId, }: IGetSupportedScanFileFormatsRequest): Promise<IGetSupportedScanFileFormatsResponse>;
uploadManifestFiles({ clientId, projectHash, analysisId, manifestFiles, hasMoreThanMaximumManifests, }: IUploadManifestFilesRequest): Promise<IUploadManifestFilesResponse>;

@@ -167,3 +176,3 @@ startScan({ clientId, projectHash, analysisId }: IStartScanRequest): Promise<void>;

}
export { ICreateScanRequestContributingDeveloperAudit, ICreateScanRequest, ICreateScanResponse, IGetSupportedManifestsRequest, IGetSupportedManifestsResponsePackageManagerManifestPatterns, IGetSupportedManifestsResponse, IScanStatusRequest, IScanStatusResponse, IStartScanRequest, IUpdateScanStatusRequest, IUploadManifestFilesRequest, IUploadManifestFilesResponseManifestStatus, IUploadManifestFilesResponse, IGetFormattedScanRequest as IFormattedScanRequest, IUploadScanToolResultRequest, IIssuesModel, };
export { ICreateScanRequestContributingDeveloperAudit, ICreateScanRequest, ICreateScanResponse, IGetSupportedScanFileFormatsRequest, IGetSupportedScanFileFormatsResponsePackageManagerManifestAndHashableFiles, IGetSupportedScanFileFormatsResponse, IScanStatusRequest, IScanStatusResponse, IStartScanRequest, IUpdateScanStatusRequest, IUploadManifestFilesRequest, IUploadManifestFilesResponseManifestStatus, IUploadManifestFilesResponse, IGetFormattedScanRequest as IFormattedScanRequest, IUploadScanToolResultRequest, IIssuesModel, };
export default SOOSAnalysisApiClient;

@@ -42,4 +42,4 @@ "use strict";

}
async getSupportedManifests({ clientId, }) {
const response = await this.client.get(`clients/${clientId}/manifests`);
async getSupportedScanFileFormats({ clientId, }) {
const response = await this.client.get(`clients/${clientId}/scan-file-formats`);
return response.data;

@@ -46,0 +46,0 @@ }

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

SoosPackageDirToExclude: string;
SoosFileHashesManifest: string;
};

@@ -32,0 +33,0 @@ Status: {

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

SoosPackageDirToExclude: "**/soos/**",
SoosFileHashesManifest: "_soos_hashes.json",
},

@@ -34,0 +35,0 @@ Status: {

@@ -120,1 +120,19 @@ export declare enum ContributingDeveloperSource {

}
export declare enum HashAlgorithmEnum {
Unknown = "Unknown",
Md5 = "Md5",
Sha1 = "Sha1",
Sha256 = "Sha256",
Sha512 = "Sha512"
}
export declare enum HashEncodingEnum {
Utf8 = "Utf8",
Base64 = "Base64",
Binary = "Binary",
Hex = "Hex"
}
export declare enum FileMatchTypeEnum {
Manifest = "Manifest",
FileHash = "FileHash",
ManifestAndFileHash = "ManifestAndFileHash"
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.OnFailure = exports.OutputFormat = exports.LogLevel = exports.SeverityEnum = exports.ScmType = exports.ScmResultsFormat = exports.ScanType = exports.ScanStatus = exports.ManifestStatus = exports.PackageManagerType = exports.IntegrationType = exports.IntegrationName = exports.ContributingDeveloperSource = void 0;
exports.FileMatchTypeEnum = exports.HashEncodingEnum = exports.HashAlgorithmEnum = exports.OnFailure = exports.OutputFormat = exports.LogLevel = exports.SeverityEnum = exports.ScmType = exports.ScmResultsFormat = exports.ScanType = exports.ScanStatus = exports.ManifestStatus = exports.PackageManagerType = exports.IntegrationType = exports.IntegrationName = exports.ContributingDeveloperSource = void 0;
var ContributingDeveloperSource;

@@ -136,1 +136,22 @@ (function (ContributingDeveloperSource) {

})(OnFailure || (exports.OnFailure = OnFailure = {}));
var HashAlgorithmEnum;
(function (HashAlgorithmEnum) {
HashAlgorithmEnum["Unknown"] = "Unknown";
HashAlgorithmEnum["Md5"] = "Md5";
HashAlgorithmEnum["Sha1"] = "Sha1";
HashAlgorithmEnum["Sha256"] = "Sha256";
HashAlgorithmEnum["Sha512"] = "Sha512";
})(HashAlgorithmEnum || (exports.HashAlgorithmEnum = HashAlgorithmEnum = {}));
var HashEncodingEnum;
(function (HashEncodingEnum) {
HashEncodingEnum["Utf8"] = "Utf8";
HashEncodingEnum["Base64"] = "Base64";
HashEncodingEnum["Binary"] = "Binary";
HashEncodingEnum["Hex"] = "Hex";
})(HashEncodingEnum || (exports.HashEncodingEnum = HashEncodingEnum = {}));
var FileMatchTypeEnum;
(function (FileMatchTypeEnum) {
FileMatchTypeEnum["Manifest"] = "Manifest";
FileMatchTypeEnum["FileHash"] = "FileHash";
FileMatchTypeEnum["ManifestAndFileHash"] = "ManifestAndFileHash";
})(FileMatchTypeEnum || (exports.FileMatchTypeEnum = FileMatchTypeEnum = {}));

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

import { FileMatchTypeEnum, HashAlgorithmEnum } from "./../enums";
import SOOSAnalysisApiClient, { ICreateScanRequestContributingDeveloperAudit, ICreateScanResponse } from "../api/SOOSAnalysisApiClient";
import SOOSProjectsApiClient from "../api/SOOSProjectsApiClient";
import SOOSUserApiClient from "../api/SOOSUserApiClient";
import { IntegrationName, IntegrationType, OutputFormat, PackageManagerType, ScanStatus, ScanType } from "../enums";
import { IntegrationName, IntegrationType, OutputFormat, ScanStatus, ScanType } from "../enums";
import FormData from "form-data";

@@ -18,6 +19,19 @@ import SOOSHooksApiClient from "../api/SOOSHooksApiClient";

interface IManifestFile {
packageManager: PackageManagerType;
packageManager: string;
name: string;
path: string;
}
interface ISoosFileHash {
filename: string;
path: string;
digests: Array<ISoosDigest>;
}
interface ISoosDigest {
hashAlgorithm: HashAlgorithmEnum;
digest: string;
}
interface ISoosHashesManifest {
packageManager: string;
fileHashes: Array<ISoosFileHash>;
}
interface IStartScanParams {

@@ -82,15 +96,17 @@ clientId: string;

}>;
findManifestFiles({ clientId, projectHash, branchHash, scanType, analysisId, scanStatusUrl, filesToExclude, directoriesToExclude, sourceCodePath, packageManagers, }: {
findManifestsAndHashableFiles({ clientId, projectHash, filesToExclude, directoriesToExclude, sourceCodePath, workingDirectory, packageManagers, fileMatchType, }: {
clientId: string;
projectHash: string;
branchHash: string;
scanType: ScanType;
analysisId: string;
scanStatusUrl: string;
filesToExclude: string[];
directoriesToExclude: string[];
sourceCodePath: string;
workingDirectory: string;
packageManagers: string[];
}): Promise<IManifestFile[]>;
fileMatchType: FileMatchTypeEnum;
}): Promise<{
manifestFiles: IManifestFile[] | null;
hashManifests: ISoosHashesManifest[] | null;
}>;
private searchForManifestFiles;
private searchForHashableFiles;
getAnalysisFilesAsFormData(analysisFilePaths: string[], workingDirectory: string): Promise<FormData>;

@@ -97,0 +113,0 @@ addManifestFilesToScan({ clientId, projectHash, branchHash, analysisId, scanType, scanStatusUrl, manifestFiles, }: {

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

const tslib_1 = require("tslib");
const enums_1 = require("./../enums");
const SOOSAnalysisApiClient_1 = tslib_1.__importDefault(require("../api/SOOSAnalysisApiClient"));

@@ -10,3 +11,3 @@ const SOOSProjectsApiClient_1 = tslib_1.__importDefault(require("../api/SOOSProjectsApiClient"));

const constants_1 = require("../constants");
const enums_1 = require("../enums");
const enums_2 = require("../enums");
const logging_1 = require("../logging");

@@ -20,22 +21,22 @@ const utilities_1 = require("../utilities");

const integrationNameToEnvVariable = {
[enums_1.IntegrationName.AzureDevOps]: "Build.RequestedFor",
[enums_1.IntegrationName.AWSCodeBuild]: "CODEBUILD_BUILD_INITIATOR",
[enums_1.IntegrationName.Bamboo]: "bamboo_planRepository_1_username",
[enums_1.IntegrationName.BitBucket]: "BITBUCKET_STEP_TRIGGERER_UUID",
[enums_1.IntegrationName.CircleCI]: "CIRCLE_USERNAME",
[enums_1.IntegrationName.CodeShip]: "CI_COMMITTER_USERNAME",
[enums_1.IntegrationName.GithubActions]: "GITHUB_ACTOR",
[enums_1.IntegrationName.GitLab]: "GITLAB_USER_LOGIN",
[enums_1.IntegrationName.Jenkins]: "CHANGE_AUTHOR",
[enums_1.IntegrationName.SoosCsa]: "SOOS_CONTRIBUTING_DEVELOPER",
[enums_1.IntegrationName.SoosDast]: "SOOS_CONTRIBUTING_DEVELOPER",
[enums_1.IntegrationName.SoosSast]: "SOOS_CONTRIBUTING_DEVELOPER",
[enums_1.IntegrationName.SoosSca]: "SOOS_CONTRIBUTING_DEVELOPER",
[enums_1.IntegrationName.SoosSbom]: "SOOS_CONTRIBUTING_DEVELOPER",
[enums_1.IntegrationName.TeamCity]: "TEAMCITY_BUILD_TRIGGEREDBY_USERNAME",
[enums_1.IntegrationName.TravisCI]: "TRAVIS_COMMIT",
[enums_1.IntegrationName.VisualStudio]: "SOOS_CONTRIBUTING_DEVELOPER",
[enums_1.IntegrationName.VisualStudioCode]: "SOOS_CONTRIBUTING_DEVELOPER",
[enums_2.IntegrationName.AzureDevOps]: "Build.RequestedFor",
[enums_2.IntegrationName.AWSCodeBuild]: "CODEBUILD_BUILD_INITIATOR",
[enums_2.IntegrationName.Bamboo]: "bamboo_planRepository_1_username",
[enums_2.IntegrationName.BitBucket]: "BITBUCKET_STEP_TRIGGERER_UUID",
[enums_2.IntegrationName.CircleCI]: "CIRCLE_USERNAME",
[enums_2.IntegrationName.CodeShip]: "CI_COMMITTER_USERNAME",
[enums_2.IntegrationName.GithubActions]: "GITHUB_ACTOR",
[enums_2.IntegrationName.GitLab]: "GITLAB_USER_LOGIN",
[enums_2.IntegrationName.Jenkins]: "CHANGE_AUTHOR",
[enums_2.IntegrationName.SoosCsa]: "SOOS_CONTRIBUTING_DEVELOPER",
[enums_2.IntegrationName.SoosDast]: "SOOS_CONTRIBUTING_DEVELOPER",
[enums_2.IntegrationName.SoosSast]: "SOOS_CONTRIBUTING_DEVELOPER",
[enums_2.IntegrationName.SoosSca]: "SOOS_CONTRIBUTING_DEVELOPER",
[enums_2.IntegrationName.SoosSbom]: "SOOS_CONTRIBUTING_DEVELOPER",
[enums_2.IntegrationName.TeamCity]: "TEAMCITY_BUILD_TRIGGEREDBY_USERNAME",
[enums_2.IntegrationName.TravisCI]: "TRAVIS_COMMIT",
[enums_2.IntegrationName.VisualStudio]: "SOOS_CONTRIBUTING_DEVELOPER",
[enums_2.IntegrationName.VisualStudioCode]: "SOOS_CONTRIBUTING_DEVELOPER",
};
const GeneratedScanTypes = [enums_1.ScanType.CSA, enums_1.ScanType.SBOM, enums_1.ScanType.SCA];
const GeneratedScanTypes = [enums_2.ScanType.CSA, enums_2.ScanType.SBOM, enums_2.ScanType.SCA];
exports.GeneratedScanTypes = GeneratedScanTypes;

@@ -59,13 +60,13 @@ class AnalysisService {

switch (message.severity) {
case enums_1.SeverityEnum.Unknown:
case enums_1.SeverityEnum.None:
case enums_1.SeverityEnum.Info:
case enums_1.SeverityEnum.Low:
case enums_2.SeverityEnum.Unknown:
case enums_2.SeverityEnum.None:
case enums_2.SeverityEnum.Info:
case enums_2.SeverityEnum.Low:
logging_1.soosLogger.info(message.message);
break;
case enums_1.SeverityEnum.Medium:
case enums_1.SeverityEnum.High:
case enums_2.SeverityEnum.Medium:
case enums_2.SeverityEnum.High:
logging_1.soosLogger.warn(message.message);
break;
case enums_1.SeverityEnum.Critical:
case enums_2.SeverityEnum.Critical:
logging_1.soosLogger.error(message.message);

@@ -96,3 +97,3 @@ break;

contributingDeveloperAudit.push({
source: enums_1.ContributingDeveloperSource.EnvironmentVariable,
source: enums_2.ContributingDeveloperSource.EnvironmentVariable,
sourceName: envVariableName,

@@ -164,6 +165,6 @@ contributingDeveloperId: contributingDeveloper,

: "";
const codeIssues = scanType === enums_1.ScanType.SAST
const codeIssues = scanType === enums_2.ScanType.SAST
? `(${utilities_1.StringUtilities.pluralizeTemplate(scanStatus.issues?.Sast?.count ?? 0, "code issue")}) `
: "";
const webVulnerabilities = scanType === enums_1.ScanType.DAST
const webVulnerabilities = scanType === enums_2.ScanType.DAST
? `(${utilities_1.StringUtilities.pluralizeTemplate(scanStatus.issues?.Dast?.count ?? 0, "web vulnerability", "web vulnerabilities")}) `

@@ -224,3 +225,3 @@ : "";

});
if (status === enums_1.ScanStatus.Incomplete || status === enums_1.ScanStatus.Error)
if (status === enums_2.ScanStatus.Incomplete || status === enums_2.ScanStatus.Error)
logging_1.soosLogger.error(message);

@@ -260,9 +261,13 @@ }

}
async findManifestFiles({ clientId, projectHash, branchHash, scanType, analysisId, scanStatusUrl, filesToExclude, directoriesToExclude, sourceCodePath, packageManagers, }) {
const supportedManifestsResponse = await this.analysisApiClient.getSupportedManifests({
async findManifestsAndHashableFiles({ clientId, projectHash, filesToExclude, directoriesToExclude, sourceCodePath, workingDirectory, packageManagers, fileMatchType, }) {
const supportedScanFileFormats = await this.analysisApiClient.getSupportedScanFileFormats({
clientId: clientId,
});
const runFileHashing = fileMatchType === enums_1.FileMatchTypeEnum.FileHash ||
fileMatchType === enums_1.FileMatchTypeEnum.ManifestAndFileHash;
const runManifestMatching = fileMatchType === enums_1.FileMatchTypeEnum.Manifest ||
fileMatchType === enums_1.FileMatchTypeEnum.ManifestAndFileHash;
const filteredPackageManagers = (0, utilities_1.isNil)(packageManagers) || packageManagers.length === 0
? supportedManifestsResponse
: supportedManifestsResponse.filter((packageManagerManifests) => packageManagers.some((pm) => utilities_1.StringUtilities.areEqual(pm, packageManagerManifests.packageManager, {
? supportedScanFileFormats
: supportedScanFileFormats.filter((packageManagerScanFileFormats) => packageManagers.some((pm) => utilities_1.StringUtilities.areEqual(pm, packageManagerScanFileFormats.packageManager, {
sensitivity: "base",

@@ -274,18 +279,77 @@ })));

});
const manifestFiles = this.searchForManifestFiles({
clientId,
projectHash,
branchHash,
scanType,
analysisId,
scanStatusUrl,
packageManagerManifests: filteredPackageManagers,
useLockFile: settings.useLockFile ?? false,
filesToExclude,
directoriesToExclude,
sourceCodePath,
});
return manifestFiles;
var manifestFormats = !runManifestMatching
? []
: filteredPackageManagers.flatMap((fpm) => {
return {
packageManager: fpm.packageManager,
manifests: fpm.supportedManifests?.map((sm) => {
return {
isLockFile: sm.isLockFile,
pattern: sm.pattern,
};
}) ?? [],
};
});
const manifestFiles = !runManifestMatching
? null
: this.searchForManifestFiles({
packageManagerManifests: manifestFormats,
useLockFile: settings.useLockFile ?? false,
filesToExclude,
directoriesToExclude,
sourceCodePath,
});
var archiveHashFormats = !runFileHashing
? []
: filteredPackageManagers.flatMap((fpm) => {
return {
packageManager: fpm.packageManager,
fileFormats: fpm.hashableFiles?.map((hf) => {
return {
hashAlgorithms: hf.hashAlgorithms,
patterns: hf.archiveFileExtensions?.filter((afe) => !(0, utilities_1.isNil)(afe)) ?? [],
};
}) ?? [],
};
});
const archiveFileHashManifests = !runFileHashing
? null
: this.searchForHashableFiles({
hashableFileFormats: archiveHashFormats,
sourceCodePath,
filesToExclude,
directoriesToExclude,
});
var contentHashFormats = !runFileHashing
? []
: filteredPackageManagers.flatMap((fpm) => {
return {
packageManager: fpm.packageManager,
fileFormats: fpm.hashableFiles?.map((hf) => {
return {
hashAlgorithms: hf.hashAlgorithms,
patterns: hf.archiveContentFileExtensions?.filter((afe) => !(0, utilities_1.isNil)(afe)) ?? [],
};
}) ?? [],
};
});
const contentFileHashManifests = !runFileHashing
? null
: this.searchForHashableFiles({
hashableFileFormats: contentHashFormats,
sourceCodePath,
filesToExclude,
directoriesToExclude,
});
const hashManifests = (archiveFileHashManifests ?? []).concat(contentFileHashManifests ?? []);
if (runFileHashing && hashManifests) {
for (const soosHashesManifest of hashManifests) {
const manifestPath = Path.join(workingDirectory, `${soosHashesManifest.packageManager}${constants_1.SOOS_CONSTANTS.SCA.SoosFileHashesManifest}`);
logging_1.soosLogger.info(`Generating SOOS hashes manifest: ${manifestPath}`);
FileSystem.writeFileSync(manifestPath, JSON.stringify(soosHashesManifest, null, 2));
}
}
return { manifestFiles, hashManifests };
}
async searchForManifestFiles({ clientId, projectHash, branchHash, scanType, analysisId, scanStatusUrl, packageManagerManifests, useLockFile, filesToExclude, directoriesToExclude, sourceCodePath, }) {
searchForManifestFiles({ packageManagerManifests, useLockFile, filesToExclude, directoriesToExclude, sourceCodePath, }) {
const currentDirectory = process.cwd();

@@ -336,18 +400,64 @@ logging_1.soosLogger.info(`Setting current working directory to project path '${sourceCodePath}'.`);

logging_1.soosLogger.info(`${manifestFiles.length} manifest files found.`);
if (manifestFiles.length === 0) {
const errorMessage = "No valid manifests found, cannot continue. For more help, please visit https://kb.soos.io/help/error-no-valid-manifests-found";
await this.updateScanStatus({
clientId: clientId,
projectHash,
branchHash,
scanType,
analysisId: analysisId,
status: enums_1.ScanStatus.Incomplete,
message: errorMessage,
scanStatusUrl,
});
throw new Error(errorMessage);
}
return manifestFiles;
}
searchForHashableFiles({ hashableFileFormats, sourceCodePath, filesToExclude, directoriesToExclude, }) {
const currentDirectory = process.cwd();
logging_1.soosLogger.info(`Setting current working directory to project path '${sourceCodePath}'.`);
process.chdir(sourceCodePath);
const fileHashes = hashableFileFormats.reduce((accumulator, fileFormatToHash) => {
const matches = fileFormatToHash.fileFormats.flatMap((fileFormat) => {
return fileFormat.patterns.flatMap((matchPattern) => {
const manifestGlobPattern = matchPattern.startsWith(".")
? `*${matchPattern}`
: matchPattern;
const pattern = `**/${manifestGlobPattern}`;
const files = Glob.sync(pattern, {
ignore: [
...(filesToExclude || []),
...directoriesToExclude,
constants_1.SOOS_CONSTANTS.SCA.SoosPackageDirToExclude,
],
nocase: true,
});
const absolutePathFiles = files.map((x) => Path.resolve(x));
const matchingFilesMessage = `${absolutePathFiles.length} files found matching pattern '${matchPattern}'.`;
if (absolutePathFiles.length > 0) {
logging_1.soosLogger.info(matchingFilesMessage);
}
else {
logging_1.soosLogger.verboseInfo(matchingFilesMessage);
}
return absolutePathFiles.flat().map((filePath) => {
const filename = Path.basename(filePath);
var fileDigests = fileFormat.hashAlgorithms.map((ha) => {
const digest = (0, utilities_1.generateFileHash)(ha.hashAlgorithm, ha.bufferEncoding, ha.digestEncoding, filePath);
logging_1.soosLogger.debug(`Found '${filePath}' (${digest})`);
return {
digest: digest,
hashAlgorithm: ha.hashAlgorithm,
};
});
return {
digests: fileDigests.map((d) => {
return {
hashAlgorithm: d.hashAlgorithm,
digest: d.digest,
};
}),
filename: filename,
path: filePath,
};
});
});
});
return accumulator.concat({
packageManager: fileFormatToHash.packageManager,
fileHashes: matches,
});
}, []);
process.chdir(currentDirectory);
logging_1.soosLogger.info(`Setting current working directory back to '${currentDirectory}'.\n`);
logging_1.soosLogger.info(`Generated ${fileHashes.length} file hashes.`);
return fileHashes;
}
async getAnalysisFilesAsFormData(analysisFilePaths, workingDirectory) {

@@ -416,3 +526,3 @@ const analysisFiles = analysisFilePaths.map((filePath) => {

analysisId: analysisId,
status: enums_1.ScanStatus.Incomplete,
status: enums_2.ScanStatus.Incomplete,
message: `Error uploading manifests.`,

@@ -419,0 +529,0 @@ scanStatusUrl,

@@ -1,2 +0,2 @@

import { IntegrationName, OnFailure, ScanStatus } from "./enums";
import { HashEncodingEnum, IntegrationName, OnFailure, ScanStatus } from "./enums";
declare const isNil: (value: unknown) => value is null | undefined;

@@ -12,2 +12,3 @@ declare const ensureValue: <T>(value: T | null | undefined, propertyName: string) => T;

declare const formatBytes: (bytes: number, decimals?: number) => string;
declare const generateFileHash: (hashAlgorithm: string, encoding: HashEncodingEnum, digestEncoding: HashEncodingEnum, filePath: string) => string;
declare const getAnalysisExitCodeWithMessage: (scanStatus: ScanStatus, integrationName: IntegrationName, onFailure: OnFailure) => {

@@ -31,2 +32,2 @@ exitCode: number;

};
export { isNil, ensureValue, ensureEnumValue, ensureNonEmptyValue, sleep, isUrlAvailable, obfuscateProperties, convertStringToBase64, getEnvVariable, formatBytes, getAnalysisExitCodeWithMessage, DateUtilities, StringUtilities, };
export { isNil, ensureValue, ensureEnumValue, ensureNonEmptyValue, sleep, isUrlAvailable, obfuscateProperties, convertStringToBase64, getEnvVariable, formatBytes, generateFileHash, getAnalysisExitCodeWithMessage, DateUtilities, StringUtilities, };
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.StringUtilities = exports.DateUtilities = exports.getAnalysisExitCodeWithMessage = exports.formatBytes = exports.getEnvVariable = exports.convertStringToBase64 = exports.obfuscateProperties = exports.isUrlAvailable = exports.sleep = exports.ensureNonEmptyValue = exports.ensureEnumValue = exports.ensureValue = exports.isNil = void 0;
exports.StringUtilities = exports.DateUtilities = exports.getAnalysisExitCodeWithMessage = exports.generateFileHash = exports.formatBytes = exports.getEnvVariable = exports.convertStringToBase64 = exports.obfuscateProperties = exports.isUrlAvailable = exports.sleep = exports.ensureNonEmptyValue = exports.ensureEnumValue = exports.ensureValue = exports.isNil = void 0;
const tslib_1 = require("tslib");

@@ -8,2 +8,4 @@ const axios_1 = tslib_1.__importStar(require("axios"));

const enums_1 = require("./enums");
const fs_1 = tslib_1.__importDefault(require("fs"));
const node_crypto_1 = tslib_1.__importDefault(require("node:crypto"));
const isNil = (value) => value === null || value === undefined;

@@ -102,2 +104,12 @@ exports.isNil = isNil;

exports.formatBytes = formatBytes;
const generateFileHash = (hashAlgorithm, encoding, digestEncoding, filePath) => {
const bufferEncoding = encoding.toLowerCase();
const binaryToTextEncoding = digestEncoding.toLowerCase();
const fileContent = fs_1.default.readFileSync(filePath, bufferEncoding);
return node_crypto_1.default
.createHash(hashAlgorithm)
.update(fileContent, bufferEncoding)
.digest(binaryToTextEncoding);
};
exports.generateFileHash = generateFileHash;
const getAnalysisExitCodeWithMessage = (scanStatus, integrationName, onFailure) => {

@@ -104,0 +116,0 @@ if (scanStatus === enums_1.ScanStatus.FailedWithIssues) {

@@ -164,1 +164,15 @@ "use strict";

});
describe("generateFileDigest", () => {
test("should generate expected sha1 hash using binary file encoding and hex digest conversion", () => {
expect((0, utilities_1.generateFileHash)("sha1", enums_1.HashEncodingEnum.Binary, enums_1.HashEncodingEnum.Hex, "./testassets/elasticsearch-grok-8.9.1.jar")).toBe("499f313de5e097fe4db1b623cfb954f18776a88b");
});
test("should generate expected sha1 hash using hex file encoding and hex digest conversion", () => {
expect((0, utilities_1.generateFileHash)("sha1", enums_1.HashEncodingEnum.Hex, enums_1.HashEncodingEnum.Hex, "./testassets/elasticsearch-grok-8.9.1.jar")).toBe("499f313de5e097fe4db1b623cfb954f18776a88b");
});
test("should generate expected sha512 hash using binary file encoding and base64 digest conversion", () => {
expect((0, utilities_1.generateFileHash)("sha512", enums_1.HashEncodingEnum.Binary, enums_1.HashEncodingEnum.Base64, "./testassets/jquery.1.4.2.nupkg")).toBe("FEk/h76zlaEGtK2MPOgA4jfXGOG4DAMc6CI2OtgcL3F3Cp37Ds2VIlXnJXIQZSyURAS+4bVpvrx9r0d2FZCdQQ==");
});
test("should generate expected sha512 hash using base64 file encoding and base64 digest conversion", () => {
expect((0, utilities_1.generateFileHash)("sha512", enums_1.HashEncodingEnum.Base64, enums_1.HashEncodingEnum.Base64, "./testassets/jquery.1.4.2.nupkg")).toBe("FEk/h76zlaEGtK2MPOgA4jfXGOG4DAMc6CI2OtgcL3F3Cp37Ds2VIlXnJXIQZSyURAS+4bVpvrx9r0d2FZCdQQ==");
});
});
{
"name": "@soos-io/api-client",
"version": "0.2.49-pre.2",
"version": "0.2.49-pre.3",
"description": "This is the SOOS API Client for registered clients leveraging the various integrations to the SOOS platform.",

@@ -58,3 +58,3 @@ "main": "dist/index.js",

"glob": "^10.4.1",
"tslib": "^2.6.2"
"tslib": "^2.6.3"
},

@@ -67,5 +67,5 @@ "overrides": {

"@types/jest": "^29.5.12",
"@types/node": "^20.12.13",
"@types/node": "^20.14.2",
"jest": "^29.1.2",
"prettier": "^3.2.5",
"prettier": "^3.3.2",
"ts-jest": "^29.1.4",

@@ -72,0 +72,0 @@ "ts-node": "^10.9.2",

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