@nitin15j/plugin-dora-frontend
Version:
Welcome to the dora-frontend plugin!
83 lines (80 loc) • 3.2 kB
JavaScript
import { createApiRef } from '@backstage/core-plugin-api';
const API_PATHS = {
PERMISSION: "/permission/"};
const doraBackendApiRef = createApiRef({
id: "plugin.dora.backend.service"
});
class DORABackendClientImpl {
configApi;
identityApi;
discoveryApi;
baseUrl;
constructor(options) {
this.configApi = options.configApi;
this.identityApi = options.identityApi;
this.discoveryApi = options.discoveryApi;
this.baseUrl = this.configApi.getString("backend.baseUrl");
}
async fetchWithAuth(url, options = {}) {
const { token: idToken } = await this.identityApi.getCredentials();
const response = await fetch(url, {
...options,
headers: {
...options.headers,
...idToken && { Authorization: `Bearer ${idToken}` }
}
});
if (!response.ok) {
const error = await response.json();
throw new Error(error.error || "Request failed");
}
return response.json();
}
async getUserAuthorization() {
return this.fetchWithAuth(`${this.baseUrl}${API_PATHS.PERMISSION}`);
}
async getProjectDORAMetrics(projectSlug, environment, deployment, timeRange) {
const baseUrl = await this.discoveryApi.getBaseUrl("dora-backend");
const url = `${baseUrl}/metrics/${projectSlug}?environment=${environment}&deploymentId=${deployment}&timeRange=${timeRange}`;
return this.fetchWithAuth(url);
}
async getProjectDORAMetricsInsights(projectId, environment, deployment, timeRange) {
const baseUrl = await this.discoveryApi.getBaseUrl("dora-backend");
const url = `${baseUrl}/metrics-insights/${projectId}?environment=${environment}&deploymentId=${deployment}&timeRange=${timeRange}`;
return this.fetchWithAuth(url);
}
async getOrganizationTrendMetrics(timeRange) {
const baseUrl = await this.discoveryApi.getBaseUrl("dora-backend");
const url = `${baseUrl}/org-trend-metrics?timeRange=${timeRange}`;
return this.fetchWithAuth(url);
}
async getTeamDORAMetrics(teamSlug, environment, deployment, timeRange) {
const baseUrl = await this.discoveryApi.getBaseUrl("dora-backend");
const url = `${baseUrl}/team-metrics/${teamSlug}?environment=${environment}&deploymentId=${deployment}&timeRange=${timeRange}`;
return this.fetchWithAuth(url);
}
async getTeamDORAMetricsInsights(teamSlug, environment, deployment, timeRange) {
const baseUrl = await this.discoveryApi.getBaseUrl("dora-backend");
const url = `${baseUrl}/team-metrics-insights/${teamSlug}?environment=${environment}&deploymentId=${deployment}&timeRange=${timeRange}`;
return this.fetchWithAuth(url);
}
async getBatchTeamDORAMetrics(teamSlugs, environment, deployment, timeRange) {
const baseUrl = await this.discoveryApi.getBaseUrl("dora-backend");
const url = `${baseUrl}/batch-team-metrics`;
const body = {
teamSlugs,
environment,
deploymentId: deployment,
timeRange
};
return this.fetchWithAuth(url, {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(body)
});
}
}
export { DORABackendClientImpl, doraBackendApiRef };
//# sourceMappingURL=DORABackendClient.esm.js.map