"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getCloudAsset = void 0;
const testim_services_api_1 = require("../testim-services-api");
const testim_credentials_manager_1 = require("../testim-credentials-manager");
async function authenticateIfNeeded() {
    const testimAuthInfo = await testim_credentials_manager_1.getTestimCredentials();
    if (testimAuthInfo.projectId && testimAuthInfo.ciToken) {
        const testim = new testim_services_api_1.TestimApi();
        await testim.authenticate(testimAuthInfo.projectId, testimAuthInfo.ciToken);
        return testim;
    }
    return null;
}
const testimBackendPromise = authenticateIfNeeded().catch(() => { });
async function getCloudAsset(path) {
    const testim = await testimBackendPromise;
    if (!testim || !testim.projectId) {
        throw new Error('Unauthenticated');
    }
    const response = await testim.assets.getAsset({
        projectId: testim.projectId,
        pathInsideBucket: `.root-cause/${path}`,
    });
    return response;
}
exports.getCloudAsset = getCloudAsset;
