UNPKG

@soos-io/api-client

Version:

This is the SOOS API Client for registered clients leveraging the various integrations to the SOOS platform. Register for a free trial today at https://app.soos.io/register

96 lines (95 loc) 4.24 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const constants_1 = require("../constants"); const enums_1 = require("../enums"); const SOOSApiClient_1 = tslib_1.__importDefault(require("./SOOSApiClient")); const CompletedScanStatuses = [ enums_1.ScanStatus.Error, enums_1.ScanStatus.Incomplete, enums_1.ScanStatus.FailedWithIssues, enums_1.ScanStatus.Finished, ]; class SOOSAnalysisApiClient { baseUri; apiKey; client; createApiClient = (skipDebugRequestLogging) => SOOSApiClient_1.default.create({ baseUri: this.baseUri, apiKey: this.apiKey, apiClientName: "Analysis API", skipDebugRequestLogging, }); constructor(apiKey, baseUri = constants_1.SOOS_CONSTANTS.Urls.API.Analysis) { this.apiKey = apiKey; this.baseUri = baseUri; this.client = this.createApiClient(false); } async createScan({ clientId, projectName, commitHash, branch, buildVersion, buildUri, branchUri, integrationType, operatingEnvironment, integrationName, scanType, appVersion, scriptVersion, contributingDeveloperAudit, toolName, toolVersion, commandLine, scanMode, }) { const response = await this.client.post(`clients/${clientId}/scan-types/${scanType}/scans`, { projectName: projectName, commitHash: commitHash, branch: branch, buildVersion: buildVersion, buildUri: buildUri, branchUri: branchUri, integrationType: integrationType, operatingEnvironment: operatingEnvironment, integrationName: integrationName, scriptVersion: scriptVersion, appVersion: appVersion, contributingDeveloperAudit: contributingDeveloperAudit, toolName: toolName, toolVersion: toolVersion, commandLine: commandLine, scanMode: scanMode, }); return response.data; } async getSupportedScanFileFormats({ clientId, }) { const response = await this.client.get(`clients/${clientId}/scan-file-formats`); return response.data; } async uploadManifestFiles({ clientId, projectHash, analysisId, manifestFiles, hasMoreThanMaximumManifests, }) { const response = await this.client.post(`clients/${clientId}/projects/${projectHash}/analysis/${analysisId}/manifests`, manifestFiles, { headers: { "Content-Type": "multipart/form-data", }, params: { hasMoreThanMaximumManifests: hasMoreThanMaximumManifests ? "true" : "false", }, }); return response.data; } async startScan({ clientId, projectHash, analysisId }) { await this.client.put(`clients/${clientId}/projects/${projectHash}/analysis/${analysisId}`); } async updateScanStatus({ clientId, projectHash, branchHash, scanType, scanId, status, message, }) { await this.client.patch(`clients/${clientId}/projects/${projectHash}/branches/${branchHash}/scan-types/${scanType}/scans/${scanId}`, { status: status, message: message, }); } async getScanStatus({ scanStatusUrl }) { const response = await this.client.get(scanStatusUrl); return { status: response.data.status, isComplete: CompletedScanStatuses.includes(response.data.status), isSuccess: response.data.status === enums_1.ScanStatus.Finished, issues: response.data.issues, errors: response.data.errors ?? [], }; } async uploadScanToolResult({ clientId, projectHash, branchHash, scanType, scanId, resultFile, hasMoreThanMaximumFiles, }) { const client = this.createApiClient(true); await client.put(`clients/${clientId}/projects/${projectHash}/branches/${branchHash}/scan-types/${scanType}/scans/${scanId}`, resultFile, { headers: { "Content-Type": "multipart/form-data", }, params: { hasMoreThanMaximumFiles: hasMoreThanMaximumFiles ? "true" : "false", }, }); } } exports.default = SOOSAnalysisApiClient;