alwaysai
Version:
The alwaysAI command-line interface (CLI)
60 lines • 3.02 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.appReleasePullComponent = exports.fetchAppReleaseHistoryComponent = void 0;
const fs_1 = require("fs");
const path_1 = require("path");
const alwayscli_1 = require("@alwaysai/alwayscli");
const user_1 = require("../user");
const get_release_versions_1 = require("../../core/release/get-release-versions");
const util_1 = require("../../util");
const infrastructure_1 = require("../../infrastructure");
const project_1 = require("../../core/project");
const constants_1 = require("../../constants");
async function fetchAppReleaseHistoryComponent(props) {
const { yes, project } = props;
await (0, user_1.checkUserIsLoggedInComponent)({ yes });
await (0, project_1.validateIsUserProject)({ project });
return await (0, infrastructure_1.fetchAppReleaseHistory)(project);
}
exports.fetchAppReleaseHistoryComponent = fetchAppReleaseHistoryComponent;
async function appReleasePullComponent(props) {
const { yes, project, releaseHash } = props;
await (0, user_1.checkUserIsLoggedInComponent)({ yes });
await (0, project_1.validateIsUserProject)({ project });
// verify the project has been published (also verifies project ownership)
const releaseHistory = await (0, infrastructure_1.fetchAppReleaseHistory)(project);
if (releaseHistory.length === 0) {
throw new alwayscli_1.CliTerseError('This project has not been published!');
}
// verify valid release hash, if provided
if (releaseHash !== undefined) {
const releases = await (0, get_release_versions_1.getProjectReleases)({ releaseHistory });
if (!releases.includes(releaseHash)) {
throw new alwayscli_1.CliTerseError(`The release hash you specified ${releaseHash} is invalid for this project! To get a list of valid hashes, run \`${constants_1.ALWAYSAI_CLI_EXECUTABLE_NAME} release list --project ${project}\`
`);
}
}
await (0, util_1.runWithSpinner)(async () => {
let key;
let presignedAppUrl;
try {
const results = await (0, infrastructure_1.getReleaseURL)(project, releaseHash);
key = results.key;
presignedAppUrl = results.presignedAppUrl;
}
catch (error) {
util_1.logger.error((0, util_1.stringifyError)(error));
throw new alwayscli_1.CliTerseError('An error occurred retrieving project.');
}
const response = await (0, util_1.fetchFilestream)(presignedAppUrl);
const localDest = (0, path_1.join)(process.cwd(), `${(0, path_1.basename)(key)}`);
const stream = response.pipe((0, fs_1.createWriteStream)(localDest));
await new Promise((resolve, reject) => {
stream.on('finish', resolve);
stream.on('error', reject);
});
}, [], 'Retrieving application package');
return releaseHash;
}
exports.appReleasePullComponent = appReleasePullComponent;
//# sourceMappingURL=release-component.js.map