UNPKG

@digital-ai/plugin-dai-deploy-backend

Version:

Backend functionalities for the dai-deploy backstage plugin

74 lines (70 loc) 2.31 kB
'use strict'; var apiConfig = require('./apiConfig.cjs.js'); var responseUtil = require('./responseUtil.cjs.js'); class DeploymentHistoryStatusApi { logger; config; constructor(logger, config) { this.logger = logger; this.config = config; } static fromConfig(config, logger) { return new DeploymentHistoryStatusApi(logger, config); } async getDeploymentHistoryStatus(appName, beginDate, endDate, order, pageNumber, resultsPerPage, taskId) { this.logger?.debug( `Calling Deployment History status api, start from: ${beginDate} to: ${endDate}, in order of ${order}` ); const authCredentials = apiConfig.getCredentials(this.config); const apiUrl = apiConfig.getDeployApiHost(this.config); const requestBody = [ { type: "udm.Application", id: appName } ]; const response = await fetch( `${apiUrl}${apiConfig.DEPLOYMENT_HISTORY_STATUS_API_PATH}?begin=${beginDate}&end=${endDate} &order=${order}&page=${pageNumber}&resultsPerPage=${resultsPerPage}&taskId=${taskId}`, { method: "POST", headers: { Authorization: `Basic ${authCredentials}`, "Content-Type": "application/json", Accept: "application/json" }, body: JSON.stringify(requestBody) } ); if (!response.ok) { await responseUtil.parseErrorResponse(this.logger, response); } const data = await response.json(); const deploymentArchiveData = []; data.forEach( (d) => deploymentArchiveData.push({ package: d.package, environment: d.environmentIdWithoutRoot, type: d.type, owner: d.user, state: d.status, startDate: d.startDate, completionDate: d.completionDate, detailsRedirectUri: apiConfig.getDeploymentHistoryRedirectUri( this.config, d.taskId ), environmentRedirectUri: apiConfig.getEnvironmentRedirectUri( this.config, d.environmentId ) }) ); return { deploymentStatus: deploymentArchiveData, totalCount: Number(response.headers.get("X-Total-Count")) }; } } exports.DeploymentHistoryStatusApi = DeploymentHistoryStatusApi; //# sourceMappingURL=DeploymentHistoryStatusApi.cjs.js.map